kimi-code/packages/agent-core/test/tools
Kai 743f66e547
refactor: move tool-result metadata into a structured note side channel (#1437)
* fix: stop rendering <system> notes from tool results in the terminal and web UIs

Tool results carry <system> blocks as side-channel notes for the model (ReadMediaFile summaries, Read status, MCP image captions, error/empty sentinels). Keep them in history for the model, but strip them at every core-to-UI boundary so they no longer render as plain text. vis is intentionally left untouched to preserve the model's-eye view for debugging.

* fix: keep error/empty status text visible when stripping tool-result <system> tags

Unwrap the tool error/empty sentinels (<system>ERROR: ...</system>, <system>Tool output is empty.</system>) instead of deleting them: keep the human-readable text and drop only the tags. Otherwise a failed or empty tool result rendered as a blank output, indistinguishable from a rendering bug. The model still reads the wrapped form in history.

* refactor: move tool-result metadata into a structured note side channel

Tool-produced model-facing metadata (ReadMediaFile summaries, Read status
lines, MCP image-compression captions) was baked into tool output as
<system> text, so every UI had to strip it back out and three copies of
the model-view normalization had silently drifted apart.

- ExecutableToolResult gains `note`: content rendered to the model but
  never to UIs; records and history now store the raw output plus the
  structured isError/note fields
- the model view is rendered exactly once at the LLM projection boundary
  by renderToolResultForModel; the transcript and vis hand-copies are
  deleted (vis now calls the same function for its model view, fixing
  their drifted empty-output checks)
- ReadMediaFile / Read / MCP captions write `note`; tool outputs stay
  pure data, and text-only results keep a single text part (note joined
  with a newline) so provider tool content stays a plain string
- all UI-side <system> stripping is removed; failed tools show their own
  error text with the structured isError flag
- wire protocol 1.4 -> 1.5 migrates existing records' tool-produced
  <system> blocks into `note` on resume

* fix: provider-neutral wording, no wire migration, direct optional fields

- "The attached image was downsampled" replaces directional wording that
  depended on provider serialization order (inline media vs flatten-and-
  re-attach)
- drop the 1.4 -> 1.5 wire migration: legacy records replay verbatim, so
  the model view of old sessions stays byte-identical to what the model
  originally saw and UIs show the legacy <system> text as-is; this also
  removes the risk of the migration misclassifying user data that quotes
  tool metadata, and the additive note field needs no version bump
- pass optional result fields as undefined instead of conditional spreads
  (repo convention)

* fix: enforce the note contract at the trust boundary; narrow the TUI system-tag guard

- normalizeToolResult now keeps a note only when it is a non-empty string:
  tools and finalize hooks are arbitrary JS, and a malformed note (null,
  number, object) would previously persist into the record and crash every
  subsequent LLM projection of the session. Everything downstream now
  trusts note to be string | undefined.
- the TUI tool body suppression matches the full <system-reminder> tag
  instead of any <system prefix: reminder piggy-backing stays hidden,
  while real output that merely starts with a literal <system> tag (file
  contents, MCP text) stays visible, covered through the real
  ToolCallComponent path.

* fix: return MCP compression captions as data instead of extracting them from text

compressImageContentParts now returns { parts, captions } — captions come
back from the compressor as structured data and are never inserted into
the parts, so the MCP pipeline no longer pattern-matches text to move
them into the note side channel. Tool output that merely quotes a
caption (a doc, a log, a test fixture) stays verbatim in the output.
Also corrects the stale claim that prompt ingestion uses this helper
(it compresses per image while constructing the part).

* docs: correct the image-compression re-export comment; export CompressedContentParts

The package-root comment still described compressImageContentParts as the
input-stage helper every ingestion site calls; prompt ingestion compresses
per image with compressBase64ForModel / compressImageForModel, and the MCP
pipeline is the walker's only caller. Also export the walker's
CompressedContentParts return type so public-API consumers can name it.

* feat: wrap tool status sentinels in <system> so the model can tell harness verdicts from tool output

The error/empty status text is model-only after the note refactor (UIs
render the raw output and style failures via the structured isError
flag), so the earlier plain-text wording served no remaining audience.
Wrapping the statuses in <system> gives every piece of system-generated
text inside a tool result the same marker:

- failed calls get '<system>ERROR: Tool execution failed.</system>'
  unconditionally — the ERROR:-prefix guard is removed, so the harness
  verdict can no longer be confused with tool output that happens to
  start with error-like text
- empty outputs render as '<system>Tool output is empty.</system>'; the
  plain placeholder the loop layer bakes into records is still
  recognized and upgraded at projection time

* style: collapse an internal helper docstring per the services subtree convention
2026-07-07 11:40:27 +08:00
..
background feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
cron feat(agent-core): rework compaction to keep only user prompts and summary (#1214) 2026-07-01 01:17:30 +08:00
fixtures fix: propagate kaos env overlays (#654) 2026-06-11 17:21:32 +08:00
planning fix: require AgentSwarm to run alone (#643) 2026-06-11 13:58:35 +08:00
policies feat: rework permission decision policies (#26) 2026-05-27 20:07:24 +08:00
providers Kimi For Coding 2026-05-22 15:54:50 +08:00
agent.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
ask-user.test.ts feat(agent-core): feed AskUserQuestion answers back as question text and option labels (#1414) 2026-07-06 16:37:54 +08:00
bash-env.test.ts feat: detach foreground tasks to background (#821) 2026-06-20 21:24:22 +08:00
bash-windows-kill.test.ts Kimi For Coding 2026-05-22 15:54:50 +08:00
bash.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
builtin-current.test.ts refactor: move tool-result metadata into a structured note side channel (#1437) 2026-07-07 11:40:27 +08:00
edit.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
enter-plan-mode.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
exit-plan-mode-options.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
exit-plan-mode.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
fetch-url.test.ts feat(agent-core): slim WebSearch to query-only; fetch page content via FetchURL (#1260) 2026-07-01 18:46:15 +08:00
file-type.test.ts refactor(agent-core): unify image extension sniff-failed detection (#974) 2026-06-22 19:31:48 +08:00
glob.test.ts chore(telemetry): add ripgrep fallback telemetry (#1203) 2026-06-29 18:30:09 +08:00
goal.test.ts feat(agent-core): rework compaction to keep only user prompts and summary (#1214) 2026-07-01 01:17:30 +08:00
grep.test.ts chore(telemetry): add ripgrep fallback telemetry (#1203) 2026-06-29 18:30:09 +08:00
image-compress.test.ts refactor: move tool-result metadata into a structured note side channel (#1437) 2026-07-07 11:40:27 +08:00
image-originals.test.ts feat(agent-core): announce image compression and keep originals readable (#1304) 2026-07-02 19:07:56 +08:00
input-schema-io.test.ts feat(agent-core): feed AskUserQuestion answers back as question text and option labels (#1414) 2026-07-06 16:37:54 +08:00
list-directory.test.ts feat(agent-core): refine system prompt context (#777) 2026-06-15 18:38:42 +08:00
path-guard.test.ts feat: add workspace add-dir support (#812) 2026-06-22 19:42:13 +08:00
plan-mode-hard-block.test.ts fix: require AgentSwarm to run alone (#643) 2026-06-11 13:58:35 +08:00
read-file.test.ts refactor: move tool-result metadata into a structured note side channel (#1437) 2026-07-07 11:40:27 +08:00
read-media-desc.test.ts Kimi For Coding 2026-05-22 15:54:50 +08:00
read-media.test.ts refactor: move tool-result metadata into a structured note side channel (#1437) 2026-07-07 11:40:27 +08:00
read.test.ts refactor: move tool-result metadata into a structured note side channel (#1437) 2026-07-07 11:40:27 +08:00
result-builder.test.ts Kimi For Coding 2026-05-22 15:54:50 +08:00
rg-locator.test.ts refactor: unify path normalization with pathe (#84) 2026-05-27 11:53:24 +08:00
shell-cancel.test.ts feat: detach foreground tasks to background (#821) 2026-06-20 21:24:22 +08:00
shell-quoting.test.ts feat: detach foreground tasks to background (#821) 2026-06-20 21:24:22 +08:00
skill-tool-dispatch.test.ts refactor: decouple agent skill registry (#784) 2026-06-15 20:39:29 +08:00
skill-tool.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
todo-list.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00
web-search.test.ts feat(agent-core): slim WebSearch to query-only; fetch page content via FetchURL (#1260) 2026-07-01 18:46:15 +08:00
write.test.ts feat: Harden the default system prompt and built-in tool descriptions (#1102) 2026-06-26 16:56:40 +08:00