Skip to content

feat(cli)!: add agent-first chat / session ask output modes#1741

Open
coconut-yc wants to merge 2 commits into
Tencent:mainfrom
coconut-yc:contrib/feat-agent-output
Open

feat(cli)!: add agent-first chat / session ask output modes#1741
coconut-yc wants to merge 2 commits into
Tencent:mainfrom
coconut-yc:contrib/feat-agent-output

Conversation

@coconut-yc

@coconut-yc coconut-yc commented Jun 20, 2026

Copy link
Copy Markdown

Description

Implements #1739. This PR gives JSON, text, and NDJSON distinct contracts for
chat and session ask, with a lean default for AI-agent consumers and an
explicit raw mode for protocol consumers. The behavior comparison below uses
the PR's main base, ae9038732ad2 (CLI v0.9.0), not an earlier version of this
feature branch.

This PR is stacked on #1740, which fixes the prerequisite streaming defects
from #1738. After #1740 merges, this branch should be rebased onto main so
only the feature commit remains.

Behavior change from main

Surface main This PR
CLI --format json same NDJSON stream as --format ndjson one {ok,data:{events}} JSON envelope
CLI --format text separate TTY/pipe behavior plus trailing reference/tool sections live renderer over the same selected events as JSON
CLI --format ndjson init + verbatim SDK events unchanged
MCP chat categorized answer/thinking/full references event projection with reference / verbose inputs
MCP session_ask categorized answer/thinking/tool events/full references event projection with reference / verbose inputs

1. Bounded JSON default

Default --format json buffers the run into one success envelope containing
answer events and session/request metadata:

{"ok":true,"data":{"events":[{"response_type":"answer","content":"...","done":false}],"session_id":"..."}}

Thinking, reflection, tools, and references are excluded by default instead of
being placed into the agent's context automatically.

2. Independent detail controls

--reference adds bounded reference events without exposing the execution
trace. --verbose adds reasoning, tool, metadata, and lifecycle events without
implicitly adding references. Combine both flags for both kinds of detail.

MCP chat and session_ask expose the same controls through reference:true
and verbose:true.

Selection JSON / text / MCP events
default answer
reference only answer + indexed references
verbose only answer + reasoning/tool/lifecycle detail
both all projected detail; references remain index-only

Text renders selected events immediately for terminals and pipes. TTY detection
no longer changes which content is emitted.

3. Indexed references

Projected reference payloads contain lookup keys only:

{"kb_id":"...","chunk_id":"...","parent_chunk_id":"..."}

The projector does not mutate SDK events. NDJSON therefore retains full
reference content, while JSON/text/MCP consumers fetch passages on demand with
chunk view. session ask answer events also carry inline chunk indexes for
follow-up retrieval.

4. Raw NDJSON remains available

--format ndjson emits the CLI init event and then passes every SDK frame
through verbatim. Presentation flags do not alter it.

5. Shared projection and recovery metadata

JSON, text, and MCP use one projector, preventing their selection policies from
drifting. Buffered CLI JSON errors retain session_id; chat also retains
assistant_message_id when supplied by the stream.

Type of Change

  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🧪 Test
  • 🐛 Bug fix (provided by the prerequisite PR)

Related Issue

Fixes #1739

Testing

Regression coverage verifies:

  • default JSON emits one envelope containing answer events only;
  • --reference includes indexed references without reasoning/tool events;
  • --verbose includes reasoning/tool/lifecycle events without references;
  • combining both flags includes both detail classes;
  • reference projection does not mutate the raw SDK event;
  • text uses the same selection controls for TTY and non-TTY output;
  • MCP chat / session_ask expose the same default, reference, and verbose
    projections;
  • NDJSON keeps its init + verbatim SDK-frame contract;
  • --jq can extract or join answer fragments;
  • buffered CLI JSON stream errors retain the active session id.

Validated locally:

(cd cli && go test ./... && go vet ./...)
(cd client && go test ./... && go vet ./...)
git diff --check

Checklist

  • Relevant Go files are formatted and git diff --check passes
  • CLI/client tests and vet pass locally
  • Self-reviewed the code
  • Added/updated tests for the new contract
  • Updated cli/CHANGELOG.md, cli/README.md, cli/AGENTS.md, and bundled skills
  • Breaking changes and migration paths are documented below

⚠️ Breaking changes

  1. Default chat / session ask --format json now emits one envelope with
    data.events rather than raw JSON lines.
  2. MCP chat / session_ask now return events rather than categorized
    answer/thinking/tool/reference fields.
  3. Default JSON/text/MCP output excludes reasoning, tools, and references. Add
    --reference for indexed references and --verbose for execution detail
    (or the corresponding MCP booleans).
  4. Projected references are lookup indexes rather than full SearchResult
    objects. NDJSON SDK frames remain lossless.
  5. Text streams selected content for both terminals and pipes; optional
    tool/reference events are no longer deferred to trailing summary sections.

Migration examples:

# Extract the default answer fragments
weknora chat "What is RRF?" --kb <kb-id> \
  --jq '[.data.events[].content] | join("")'

# Include reference indexes only
weknora chat "What is RRF?" --kb <kb-id> --reference

# Include reasoning, tool activity, and reference indexes
weknora session ask "Investigate" --agent ag_x --verbose --reference

# Previous raw incremental contract
weknora chat "What is RRF?" --kb <kb-id> --format ndjson

Screenshots / Recordings

N/A — CLI / MCP output only.

@coconut-yc coconut-yc changed the title feat(cli)!: add an agent-first chat / session ask output contract feat(cli)!: add agent-first chat / session ask output modes Jun 22, 2026
@coconut-yc coconut-yc force-pushed the contrib/feat-agent-output branch from 57e8e5b to e40641c Compare June 22, 2026 01:06
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.

[Feature]: agent-first output modes for chat / session ask

1 participant