Skip to content

Enable displaying tasks as JSON - #165

Merged
joerdav merged 4 commits into
joerdav:mainfrom
ryanprior:ryanprior/json-output
Jul 17, 2026
Merged

joerdav merged 4 commits into
joerdav:mainfrom
ryanprior:ryanprior/json-output

Conversation

@ryanprior

Copy link
Copy Markdown
Contributor

Fixes #149

Context

In my Emacs integration for xc, I would like to prompt the user for task inputs when they're required, but it's not as straightforward to enumerate the task inputs as I'd like. This PR adds a facility to display the JSON representation for the parsed task data structure, which is ideal for tool integrations like this.

In this PR

  • new method Task.DisplayJSON in models package
  • new flag -output, defaulting to "markdown" but also accepting "json", for the user to control how to display a task (with -display)
  • updated documentation and tests

Next steps

Now that this is ready for review, I'll start work to use this data in the Emacs integration to enumerate task inputs and prompt for them interactively.

Special thanks

Appreciation to @jgarte for pair programming with me on this enhancement. Thank you Jorge!

@ryanprior
ryanprior requested a review from joerdav as a code owner February 6, 2026 21:17
@ryanprior
ryanprior force-pushed the ryanprior/json-output branch 2 times, most recently from c949995 to 874bdfd Compare February 6, 2026 21:49
@ryanprior

Copy link
Copy Markdown
Contributor Author

Interesting wrinkle: the error case for the JSON display function wasn't covered in testing, which caused test coverage overall to drop and held up the PR. I dug into the JSON docs in golang to find a value that would trigger the error case so I could account for that in testing, and found that none of the types in the Task struct can accept un-marshalable values. (I tried typecasting and that just resulted in weird, but valid, values.) So I removed the error handling code and left a comment in its place 🙃

Here's the code coverage report that helped me understand that was what was causing code coverage to drop: https://coveralls.io/builds/77696075/source?filename=models%2Fmodels.go#L63

@jgarte

jgarte commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Hi @joerdav

Just checking in when you have a moment. Would appreciate any initial feedback when convenient. All best.

@joerdav joerdav left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending 2 changes. Apologies for the delayed response.

Comment thread models/models.go Outdated
Comment thread models/models.go Outdated
ryanprior and others added 3 commits July 15, 2026 18:36
Uses encoding/json package to write a task to the target writer as JSON.

Co-authored-by: jgart <jgart@dismail.de>
Co-authored-by: jgart <jgart@dismail.de>
@ryanprior
ryanprior force-pushed the ryanprior/json-output branch from 874bdfd to 35d06ef Compare July 15, 2026 22:58
@ryanprior

Copy link
Copy Markdown
Contributor Author

@joerdav I resolved both concerns, ready for re-review.

@ryanprior
ryanprior force-pushed the ryanprior/json-output branch from 35d06ef to 6a816d9 Compare July 15, 2026 23:00
@joerdav
joerdav merged commit 5dc73db into joerdav:main Jul 17, 2026
3 checks passed
@ryanprior
ryanprior deleted the ryanprior/json-output branch July 17, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command to provide machine-readable information about task inputs

3 participants