Skip to content

feat: add elastic docs commands (search, ask, chat, read)#147

Merged
JoshMock merged 2 commits into
elastic:mainfrom
Mpdreamz:feature/docs-2
Apr 15, 2026
Merged

feat: add elastic docs commands (search, ask, chat, read)#147
JoshMock merged 2 commits into
elastic:mainfrom
Mpdreamz:feature/docs-2

Conversation

@Mpdreamz
Copy link
Copy Markdown
Member

@Mpdreamz Mpdreamz commented Apr 14, 2026

Reimplementation of #1

Add four subcommands under elastic docs for interacting with the
Elastic documentation directly from the CLI. No Elasticsearch context or
API key is required — these commands use the public elastic.co docs APIs.

elastic docs [command]

Available Commands:
  search   Search Elastic documentation
  ask      Ask a question about Elastic documentation using AI
  chat     Ask with interactive follow-up conversation
  read     Read an Elastic documentation page

elastic docs search <query>

Search results rendered as styled markdown — title, product, URL, and
AI summary. Defaults to 5 results.

elastic docs search "ingest pipelines"
elastic docs search "machine learning" --size 10
elastic docs search "ingest pipelines" --json

docs-search

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 ask "What is Elasticsearch?"

docs-ask

elastic docs chat <question>

Same as ask but loops for follow-up questions; shares a conversationId
so the AI retains context across the conversation.

elastic docs chat "How do ingest pipelines work?"

docs-chat

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 --raw for unrendered markdown.

elastic docs read /reference/elasticsearch
elastic docs read "ingest pipelines"
elastic docs read https://www.elastic.co/docs/reference/elasticsearch --raw

docs-read

Implementation details

  • src/docs/client.tsfetch-based client for the search, read, and
    ask-ai SSE endpoints. SSE parsing uses a line buffer that persists across
    HTTP body chunks so split data: lines never produce malformed JSON and
    silently drop content.
  • src/docs/stream.ts — paragraph-buffering streamer: accumulates chunks,
    only flushes at `-fence-aware \n\n boundaries, strips <!--REFERENCES-->
    silently, surfaces real API phases (Searching / Generating answer) via the spinner.
  • marked + marked-terminal for terminal markdown rendering. A blank
    cli-highlight theme prevents per-token syntax colours from conflicting
    with terminal themes.
  • src/factory.ts — adds optional positionalArg to CommandConfig /
    ParsedResult so commands can declare a single positional argument.
    All four docs commands use this (elastic docs search <query>, etc.).
  • Config loading is skipped in preAction for docs subcommands — no
    Elasticsearch credentials needed.

Copy link
Copy Markdown
Member

@JoshMock JoshMock left a comment

Choose a reason for hiding this comment

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

Some thoughts before we merge this. Just want to make sure we're sticking to the agent-first philosophy as much as possible.

Comment thread package.json
Comment thread src/docs/read.ts Outdated
Comment thread src/docs/ask.ts Outdated
Comment thread src/docs/chat.ts Outdated
Mpdreamz and others added 2 commits April 15, 2026 10:54
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>
@Mpdreamz Mpdreamz requested a review from JoshMock April 15, 2026 08:55
@github-actions
Copy link
Copy Markdown

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 3.2s
✅ REPOSITORY gitleaks yes no no 8.09s
✅ REPOSITORY git_diff yes no no 0.02s
✅ REPOSITORY secretlint yes no no 1.88s
✅ REPOSITORY trivy yes no no 11.22s

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

Copy link
Copy Markdown
Member

@JoshMock JoshMock left a comment

Choose a reason for hiding this comment

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

👏

@JoshMock JoshMock merged commit fd447b1 into elastic:main Apr 15, 2026
19 checks passed
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.

2 participants