Skip to content

fix: return structured JSON from docs ask/chat when --json is active#202

Merged
ssh-esh merged 5 commits into
mainfrom
fix/docs-json-output-v2
Apr 17, 2026
Merged

fix: return structured JSON from docs ask/chat when --json is active#202
ssh-esh merged 5 commits into
mainfrom
fix/docs-json-output-v2

Conversation

@ssh-esh
Copy link
Copy Markdown
Contributor

@ssh-esh ssh-esh commented Apr 17, 2026

Closes #160

When --json is passed, docs ask and docs chat now buffer all streamed chunks
and return { "answer": "..." } instead of streaming markdown to stdout and
appending null.

@ssh-esh ssh-esh changed the title Fix/docs json output v2 fix: return structured JSON from docs ask/chat when --json is active Apr 17, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 17, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 2.77s
✅ REPOSITORY gitleaks yes no no 8.25s
✅ REPOSITORY git_diff yes no no 0.03s
✅ REPOSITORY secretlint yes no no 2.1s
✅ REPOSITORY trivy yes no no 13.88s
✅ TYPESCRIPT eslint 4 0 0 2.51s

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@ssh-esh ssh-esh marked this pull request as ready for review April 17, 2026 17:11
Comment thread src/docs/ask.ts
}
return { answer: chunks.join('') }
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A good approach for now.

If there was a way to separate the input stream into chunks by sentence, paragraph or section, each chunk could be streamed to stdout as one JSON object per line. That way an agent could choose to kill the NDJSON stream early once it has its answer, rather than wasting tokens on content it doesn't need. That's likely a much more complex solution, though, so this works. 👍

Copy link
Copy Markdown
Contributor

@MattDevy MattDevy left a comment

Choose a reason for hiding this comment

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

LGTM

@ssh-esh ssh-esh merged commit 3a5ac96 into main Apr 17, 2026
16 of 17 checks passed
@ssh-esh ssh-esh deleted the fix/docs-json-output-v2 branch April 17, 2026 17:38
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.

bug: docs ask and docs chat with --json produce mixed text and JSON output

3 participants