Skip to content

feat(cli): add per-tool result formatters for MCP tools - #3

Merged
ace331 merged 1 commit into
mainfrom
feat/cli-format-mcp-tool-results
Jul 14, 2026
Merged

ace331 merged 1 commit into
mainfrom
feat/cli-format-mcp-tool-results

Conversation

@ace331

@ace331 ace331 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replace raw MCP JSON output with clean, LLM-agent-friendly formatted output for all 8 MCP tools. Image tools now save base64 content to disk and output absolute paths instead of embedding raw base64 in stdout.

Add --raw flag to preserve the original JSON/text output behavior.

Per-tool changes

Tool Before After
search_paper Raw JSON dump Markdown paper list (title, authors, journal, DOI, AI summary)
get_paper Raw JSON dump # Title + metadata header + body text
web_search Raw JSON dump Numbered results (title, link, snippet)
fetch_url Raw JSON dump # Title + URL + content
read_image JSON with usage metadata Just the answer text
parse_doc JSON with truncated preview Full markdown content
image_gen / image_edit Raw base64 in stdout Writes to ~/.future/agent/images/ (or --output), prints absolute path

Verification

  • TypeScript type check passes (tsc --noEmit)
  • All 20 existing unit tests pass

🤖 Generated with Claude Code

Replace raw MCP JSON output with clean, LLM-agent-friendly formatted
output for all 8 MCP tools (search_paper, get_paper, web_search,
fetch_url, read_image, parse_doc, image_gen, image_edit). Image tools
now save base64 content to disk and output absolute paths instead of
embedding raw base64 in stdout.

Add --raw flag to preserve the original JSON/text output behavior.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ace331
ace331 marked this pull request as ready for review July 14, 2026 10:40
@ace331
ace331 merged commit e2cebab into main Jul 14, 2026
@ace331
ace331 deleted the feat/cli-format-mcp-tool-results branch July 14, 2026 10:40
huichen pushed a commit that referenced this pull request Jul 16, 2026
…handling, and more

Bug fixes:
- Navigation observer: poll 500ms instead of 15s for non-navigating actions.
  One fix resolves click file:// timeout, selector click timeout, and press
  15s delay (bugs #1, #2, #3).
- Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label,
  span, div, pre, code, blockquote (bug #4).
- CdpError: changed from plain object to class extends Error so it serialises
  as a readable message instead of '[object Object]' (bug #8).

Improvements:
- Snapshot: textarea/input name priority aria-label > placeholder > associated
  label > name > value[:30] (bug #10).
- Tabs: all actions now return { tabs: [...], tabCount: N } for consistent
  output (bug #6).
- Start: when endpoint already reachable, returns already_running with note
  instead of silently switching (bug #7).
- Type: returns both ref (typed) and resolved selector (bug #9).
- Scroll: new scroll command with direction/amount/ref arguments (bug #11).

Defense in depth:
- tools.ts catch block: extract .message from non-Error objects as fallback.
huichen pushed a commit that referenced this pull request Jul 16, 2026
…handling, and more

Bug fixes:
- Navigation observer: poll 500ms instead of 15s for non-navigating actions.
  One fix resolves click file:// timeout, selector click timeout, and press
  15s delay (bugs #1, #2, #3).
- Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label,
  span, div, pre, code, blockquote (bug #4).
- CdpError: changed from plain object to class extends Error so it serialises
  as a readable message instead of '[object Object]' (bug #8).

Improvements:
- Snapshot: textarea/input name priority aria-label > placeholder > associated
  label > name > value[:30] (bug #10).
- Tabs: all actions now return { tabs: [...], tabCount: N } for consistent
  output (bug #6).
- Start: when endpoint already reachable, returns already_running with note
  instead of silently switching (bug #7).
- Type: returns both ref (typed) and resolved selector (bug #9).
- Scroll: new scroll command with direction/amount/ref arguments (bug #11).

Defense in depth:
- tools.ts catch block: extract .message from non-Error objects as fallback.
huichen pushed a commit that referenced this pull request Jul 16, 2026
…handling, and more

Bug fixes:
- Navigation observer: poll 500ms instead of 15s for non-navigating actions.
  One fix resolves click file:// timeout, selector click timeout, and press
  15s delay (bugs #1, #2, #3).
- Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label,
  span, div, pre, code, blockquote (bug #4).
- CdpError: changed from plain object to class extends Error so it serialises
  as a readable message instead of '[object Object]' (bug #8).

Improvements:
- Snapshot: textarea/input name priority aria-label > placeholder > associated
  label > name > value[:30] (bug #10).
- Tabs: all actions now return { tabs: [...], tabCount: N } for consistent
  output (bug #6).
- Start: when endpoint already reachable, returns already_running with note
  instead of silently switching (bug #7).
- Type: returns both ref (typed) and resolved selector (bug #9).
- Scroll: new scroll command with direction/amount/ref arguments (bug #11).

Defense in depth:
- tools.ts catch block: extract .message from non-Error objects as fallback.
huichen pushed a commit that referenced this pull request Jul 16, 2026
…handling, and more

Bug fixes:
- Navigation observer: poll 500ms instead of 15s for non-navigating actions.
  One fix resolves click file:// timeout, selector click timeout, and press
  15s delay (bugs #1, #2, #3).
- Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label,
  span, div, pre, code, blockquote (bug #4).
- CdpError: changed from plain object to class extends Error so it serialises
  as a readable message instead of '[object Object]' (bug #8).

Improvements:
- Snapshot: textarea/input name priority aria-label > placeholder > associated
  label > name > value[:30] (bug #10).
- Tabs: all actions now return { tabs: [...], tabCount: N } for consistent
  output (bug #6).
- Start: when endpoint already reachable, returns already_running with note
  instead of silently switching (bug #7).
- Type: returns both ref (typed) and resolved selector (bug #9).
- Scroll: new scroll command with direction/amount/ref arguments (bug #11).

Defense in depth:
- tools.ts catch block: extract .message from non-Error objects as fallback.
huichen pushed a commit that referenced this pull request Jul 16, 2026
…handling, and more

Bug fixes:
- Navigation observer: poll 500ms instead of 15s for non-navigating actions.
  One fix resolves click file:// timeout, selector click timeout, and press
  15s delay (bugs #1, #2, #3).
- Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label,
  span, div, pre, code, blockquote (bug #4).
- CdpError: changed from plain object to class extends Error so it serialises
  as a readable message instead of '[object Object]' (bug #8).

Improvements:
- Snapshot: textarea/input name priority aria-label > placeholder > associated
  label > name > value[:30] (bug #10).
- Tabs: all actions now return { tabs: [...], tabCount: N } for consistent
  output (bug #6).
- Start: when endpoint already reachable, returns already_running with note
  instead of silently switching (bug #7).
- Type: returns both ref (typed) and resolved selector (bug #9).
- Scroll: new scroll command with direction/amount/ref arguments (bug #11).

Defense in depth:
- tools.ts catch block: extract .message from non-Error objects as fallback.
huichen added a commit that referenced this pull request Sep 22, 2026
)

* feat(tui): bring the terminal UI up to the desktop feature surface

The TUI had fallen behind the desktop app: no provider or model editing, no
skills browser or install path, no sandbox or permission controls, and menus
that could only list a flat set of choices. This lands the interaction surface
the desktop already had, plus the defects that surfaced while verifying it.

Interaction surfaces
- A popup-menu framework (incremental search, groups, multi-select, reload) now
  backs /providers, /models, /tools, /sessions, /tree and the scoped-model
  picker, replacing the flat lists.
- Provider and model configuration: add and edit providers, keys, endpoints and
  models from the panel. /provider-key captures a key and does what its prompt
  promises — empty input clears the stored key.
- Skills: a browser that merges the agent's own skills with the installable
  catalogue, with search, groups, a detail preview and use. Install, uninstall
  (a two-press confirmation that any other key disarms) and upgrade run through
  the `future` binary, then refresh the panel so it shows the new state.
- Sandbox and permission: /sandbox shows the tier, its reason and how platforms
  differ, and surfaces the agent's silent sandbox-to-manual fallback instead of
  hiding it; /permission persists the level.
- Diff rendering for edit, write and patch output, with per-file stats,
  collapsing and syntax colouring.
- A full-screen pager (/transcript) with search, copy and a status row, whose
  live search claims the first escape.
- Clipboard (/copy) with a tmux, native, OSC 52 ladder and an honest notice when
  a write cannot be confirmed.
- Desktop notifications and the terminal title (OSC 9 and OSC 0), respecting the
  terminal's own settings.
- External editor drafts for /editor, and a theme catalog behind /theme that
  repaints every chrome widget.
- /worktree picks or creates a git worktree and moves the session into it,
  reusing the existing set_cwd RPC; destructive git subcommands are refused.
- /keymap lists every binding by group and rebinds one, with conflict detection
  and persistence to `~/.future/tui/keybindings.json`.
- Finished transcript rows are inserted into the terminal's own scrollback, so a
  conversation can be scrolled back to and selected with the terminal's copy
  mode after the TUI exits. Rows are handed over once (a watermark), re-wrapped
  at the terminal width, and sanitised so a tool result cannot replay an escape
  into the terminal a second time.
- /history results now show why each hit matched and when it was said: the query
  is highlighted inside the snippet (display-width aware, so CJK and emoji are
  not cut), the timestamp is printed, and the opaque entry id is demoted.
- Long pastes fold. A paste longer than 200 characters never enters the box as
  text: it is kept aside and replaced by a `[Pasted Content N chars]` marker
  (numbered `#2`, `#3` … for repeats, reusing a number a deleted marker frees),
  and expanded back to the pasted bytes on submit. The threshold is the box's own
  height in characters — three lines at 80 columns, so roughly 240 characters are
  visible — because a paste that overflows the box while still being shown as
  text is what the marker exists to prevent. The count is characters, not bytes,
  so CJK is not three times as long as it looks.
- Pasting an image *path* attaches the file instead of inserting the text: an
  `[Image #N]` marker in the box, the number of waiting images beside it, and the
  path on the wire as an attachment. Dragging a file into the terminal pastes its
  path, so this is how that gesture becomes an attachment. The path is normalised
  (quotes, `file://`, backslash-escaped spaces) and the file is checked by its
  magic bytes — a text file named `notes.png` is not an image, so it stays text.
- Ctrl+V takes an image off the system clipboard (a screenshot), or its text when
  it holds no image. `super+v` is bound to the same path: upstream of a
  Kitty-protocol terminal a Command press is reported that way, and where the
  terminal keeps Command for its own Paste menu the key never arrives at all —
  which is why Ctrl+V remains what that case sends. Deleting a marker drops its
  attachment and the survivors are renumbered, so what is shown is what is sent.
- A paste burst is detected when the terminal does not send bracketed paste (some
  Windows hosts): characters that arrive faster than typing are buffered as one
  paste, so an `Enter` inside it is a newline rather than a submit and a `?` in it
  does not toggle anything. Only the bracketed-paste-less path uses it, so the
  recorded screens are unchanged.

Slash commands added to the dispatch surface
/shell /delete /title /metrics /snapshot /context /export (now a real
implementation rather than a stub) /agent /history /tool-output /autocompact
/autoretry /scoped-models /fork /keymap /worktree and /theme <id>.

Shortcuts
ctrl+v pastes the clipboard (image or text) and is listed in `/help` with the
other keys — pasting an image has no slash command to be discovered through.
ctrl+x copies the last answer, as before.

Commands removed
- /append-prompt and /system-prompt were silent no-ops: the agent composes a
  run's system prompt from project context, skills, workspace memory and the
  tool list and never reads the list field those commands wrote, so the value was
  overwritten at every run boundary. Their RPCs stay (the CLI builds them
  directly for its own flags) but nothing here sends them any more.
- /ephemeral, /rule, /quit-agent and /stats were removed by choice. /stats was
  not dropped: its counters are now the tail of /status, so the session report
  and the usage ledger have one home instead of two panels printing the same
  numbers.
- Unknown slash commands still fall through to a prompt, so one typed from
  muscle memory is sent as text rather than rejected. That is the existing,
  test-pinned behaviour that also lets `/usr/bin/foo` be sent as a message.

Fixes
- The skills child's pipes are drained while it waits, so a catalogue larger
  than the 64 KiB pipe buffer no longer deadlocks into a timeout.
- An overlay owns its whole row instead of splicing over the rows beneath it, so
  chat text can no longer bleed into a panel's leading columns.
- /help scrolls (the commands above were unreachable at 80x36), /permission
  opens focused on the permission half of its shared card, and truncated hints
  end in an ellipsis.
- A panel's live search claims escape before the overlay closes, matching what
  the components already did when tested in isolation.
- The pager accepts the key ids a real terminal sends (pageDown, not pagedown).
- The mock agent carries `state` on agent_end, without which the completion
  notification path was unreachable in the harness.
- A test restores the panic hook it installed instead of removing it, so a
  leaked hook can no longer swallow another test's panic or append to the
  developer's real crash log.
- Cumulative token totals are labelled as resent-per-call and joined by an
  average per query, so they cannot be read as the current context size.
- markdown follows the active palette: under the light theme, headings, links
  and code were painted with the dark constants' xterm indices (1.4-2.3:1 on
  white) while the palette's own md_* roles went unread.
- /history snippets were byte slices of concatenated UTF-8, so a window edge
  could land inside a multi-byte character and lossy decoding rendered the half
  as U+FFFD — the box users saw with CJK text. The partial character is dropped
  on each edge instead of substituted for; the SQL and `byteOffset` are
  unchanged.

Verification
- 2020 TUI unit tests, 8 CLI smoke tests and 5 bug-hunt regressions pass, plus
  1822 agent tests; rustfmt and clippy are clean at the pinned 1.97.0 toolchain.
- A tmux harness drives the real TUI against a deterministic mock agent and
  compares recorded screens byte for byte, waiting on content instead of fixed
  sleeps. It covers every panel listed above plus the applied state (tier set,
  permission applied, theme switched, tool expanded, search, paging) and the
  paste surfaces (folding, an image path, attachment numbering, renumbering
  after a delete): 51 checks pass, 0 warnings.
- Pasting was checked end to end on a real pane, not through doubles. A 250
  character paste folds, and the whole text still reaches the agent while the
  marker never does (the mock echoes the prompt, so the pane is the wire). A
  pasted image path and a Ctrl+V from the clipboard both attach, and the
  attachment's path, kind and name arrive on the prompt.
- The clipboard probe was run on macOS both ways: with a real PNG on the
  clipboard it writes the file, and with text on it the tool fails without
  leaving a partial file behind — which is the fallback to a text paste.
- The scrollback path was checked against a real pane, not a double: the exit
  status and the conversation are readable through `capture-pane -S` after the
  TUI leaves, the oldest rows sit above the viewport (so scrolling is required to
  reach them), and one exchange produces exactly one copy of each row.
- New-on-branch coverage is complete: three independent oracles (two blame-based,
  one difflib) agree on zero uncovered lines, sanity-checked against a report
  with 57059 records of which 96.9% are covered.

Not verified here
- Windows and Linux are covered by CI only; this machine cannot cross-compile
  the agent's `ring` dependency. The clipboard probe's PowerShell and Wayland /
  X11 command lines are held by unit tests, not by a real clipboard on a host
  that has them.
- Command+V cannot be shown to work on a terminal that does not speak the Kitty
  keyboard protocol (Terminal.app, for one): the key never arrives there. That is
  a property of the terminal, not something the TUI can fix — Ctrl+V is what that
  case sends, and both spellings are bound.
- The keymap panel's capture/rebind flow was driven by unit tests and the
  keybindings.json round trip, not end to end in a real pane.
- ctrl+p (cycle model) cannot be exercised in the harness: the real agent
  implements `cycle_model`, the mock does not.

* fix(tui): make the clipboard, skills and sandbox tests host-independent

Twelve tests passed on macOS and failed on Linux CI, each for the same shape of
reason: a test asserted one host's behaviour while the code under test read the
host it happened to be running on.

- Clipboard paste: four tests drove `ctrl+v`/`super+v` and asserted the macOS
  probe names (`osascript`/`pbpaste`), while `paste_clipboard` read
  `std::env::consts::OS` — on Linux the probes are `wl-paste`/`xclip`. The OS is
  now a parameter (`paste_clipboard_for_os`), as the sandbox panel already does
  for its platform, and the tests pin macOS.
- Sandbox/permission panels: three tests asserted `current: Sandboxed` and the
  marked tier row, which is the macOS platform default; on Linux the default is
  `Manual` and Bubblewrap adds its own caveat. The app now reads one
  `host_sandbox_platform()`, pinned to macOS in the test build, so the whole
  panel lifecycle (open, probe, policy answer) agrees.
- Copy: `recording_clipboard` inherited the host's resolved candidate list. On
  macOS `pbcopy` was found and the recording runner was reached; a Linux runner
  without X11/Wayland resolved to no candidates, so `copy()` took the OSC 52
  fallback and recorded nothing. The helper now carries one synthetic candidate,
  the same on every host — `copy()` keeps using the clipboard's own list, so
  only the fixture changes, and the real OSC 52 fallback keeps its own test.
- Skills: `skills_cli_for_host` returned `None` when no `future` binary was
  resolvable, so on a CI runner (none next to the test executable, none on
  `PATH`) the panel showed the no-binary notice and two tests waited for
  behaviour that needs an installer. The test build now always offers the
  refusing installer; a test that wants the missing-binary state sets
  `skills_cli = None`, as one already did.

Verified: 2020 tui unit tests pass, rustfmt clean, clippy clean at the pinned
1.97.0 toolchain. Each of the twelve is host-independent by construction rather
than by a host check — the test build cannot read the host for the platform, the
OS arrives as an argument, and the candidate list is synthetic — so the run on
this Mac is the run CI will do, not a second behaviour to be reconciled later.
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.

1 participant