feat: add elastic docs commands (search, ask, chat, read)#147
Merged
Conversation
0e349a9 to
1bb4b0f
Compare
JoshMock
reviewed
Apr 14, 2026
Member
JoshMock
left a comment
There was a problem hiding this comment.
Some thoughts before we merge this. Just want to make sure we're sticking to the agent-first philosophy as much as possible.
Add four subcommands under `elastic docs` for interacting with the Elastic documentation directly from the CLI. No Elasticsearch context or API key required — these commands use the public elastic.co docs APIs. Also extends `defineCommand` in the factory with an optional `positionalArg` field so commands can accept a single positional argument (e.g. `elastic docs search "ingest pipelines"`) in addition to named flags. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- docs read: return { markdown } under --json instead of writing to stdout
and returning null (which produced invalid output for agents)
- docs ask/chat: disable spinner when stderr is not a TTY or --json is set,
so agents and piped output never receive ANSI escape sequences
- docs chat: skip the interactive follow-up loop when non-interactive or
--json, behaving like 'ask' for single-shot agent use
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
c07f6f5 to
7ec44a5
Compare
✅MegaLinter analysis: Success
See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reimplementation of #1
Add four subcommands under
elastic docsfor interacting with theElastic documentation directly from the CLI. No Elasticsearch context or
API key is required — these commands use the public elastic.co docs APIs.
elastic docs search <query>Search results rendered as styled markdown — title, product, URL, and
AI summary. Defaults to 5 results.
elastic docs ask <question>Single-shot AI answer with live spinner phases (Thinking → Searching → Generating).
Paragraphs are rendered incrementally as they complete via paragraph-aware buffering.
elastic docs chat <question>Same as
askbut loops for follow-up questions; shares aconversationIdso the AI retains context across the conversation.
elastic docs read <path|url|query>Fetch any Elastic docs page rendered with colours and formatting.
Accepts a docs path, a full elastic.co URL, or a free-text query
(searches and reads the first result). Use
--rawfor unrendered markdown.Implementation details
src/docs/client.ts—fetch-based client for the search, read, andask-ai SSE endpoints. SSE parsing uses a line buffer that persists across
HTTP body chunks so split
data:lines never produce malformed JSON andsilently drop content.
src/docs/stream.ts— paragraph-buffering streamer: accumulates chunks,only flushes at
`-fence-aware\n\nboundaries, strips<!--REFERENCES-->silently, surfaces real API phases (Searching / Generating answer) via the spinner.
marked+marked-terminalfor terminal markdown rendering. A blankcli-highlighttheme prevents per-token syntax colours from conflictingwith terminal themes.
src/factory.ts— adds optionalpositionalArgtoCommandConfig/ParsedResultso commands can declare a single positional argument.All four
docscommands use this (elastic docs search <query>, etc.).preActionfordocssubcommands — noElasticsearch credentials needed.