Skip to content

fix(auto-capture): read tool names from v2-shaped tool parts - #431

Open
Phototonic wants to merge 1 commit into
tickernelz:mainfrom
Phototonic:fix/auto-capture-v2-tool-name
Open

Phototonic wants to merge 1 commit into
tickernelz:mainfrom
Phototonic:fix/auto-capture-v2-tool-name

Conversation

@Phototonic

Copy link
Copy Markdown
Contributor

Summary

On OpenCode v2 hosts, the auto-capture summarization prompt always listed tool calls as unknown(...) in the ## Tools Used section, degrading memory summaries and tags (#428).

Root cause: extractAIContent read the v1 wire-format field tool.tool. On v2 hosts the plugin's legacy adapter (src/v2/legacy-client.ts) passes v2 content parts through verbatim (...part), where the tool name lives at part.name (v2 SessionMessageAssistantTool shape; confirmed against @opencode-ai/sdk v2 gen types and a v2.1.x host's session storage). Tool inputs (state.input) have the same field in both formats, which is why only the name degraded.

Fix: read tool.name first, keeping tool.tool as a fallback for v1-wire-format hosts:

const name = tool.name || tool.tool || "unknown";

Also exports extractAIContent for direct testing and adds regression tests covering v2-shaped parts, v1-shaped parts, and the unknown fallback.

Fixes #428

Test plan

  • Exercised the change locally (or N/A for docs/meta-only)
    • New regression tests in tests/auto-capture-context.test.ts: v2 part {type:"tool", name:"bash", state:{input:{command:"ls"}}} extracts bash(command: "ls"); v1 part with tool:"read" still extracts read; a part with neither field falls back to unknown (focused run: 9 pass / 0 fail)
    • bun run typecheck, bun run check, and bun run build pass
    • Full bun test: 831 pass / 4 skip / 3 fail — all 3 failures also reproduce on pristine main (1ddfdad) and are unrelated to this change (plugin bundle-boundary dist state, user-profile-learning interval crossing, config defaults)
  • Noted any follow-up or known limitations
    • The legacy adapter stays pass-through by design; if a future consumer needs a normalized v1 field layout, prefer normalizing in legacyMessage rather than widening this fallback

Checklist

  • Branch is based on main (do not open PRs from commits already on main)
  • bun test passes (or N/A) — remaining failures pre-exist on main, see Test plan
  • bun run typecheck passes (or N/A)
  • bun run check passes (format + lint + typecheck; or N/A)
  • Docs / README updated when behavior or contribution process changes (N/A — internal prompt-building fix, no documented behavior or config change)

On OpenCode v2 hosts, session tool parts carry the tool name at
part.name (v1 wire format used part.tool). extractAIContent only read
tool.tool, so the auto-capture prompt's Tools Used section always
listed unknown(). Read name first with the v1 field kept as a
fallback, and cover both part shapes with extraction regression tests.
@Phototonic

Copy link
Copy Markdown
Contributor Author

An independent pre-creation review round ran over the full diff (correctness, contract fidelity vs both SDK tool-part shapes, test coverage, export surface, input budget/truncation). Verdict: APPROVE — no blockers or majors. Only note: a truthy non-string name on out-of-contract input is not validated; left as-is since it is not a demonstrated host scenario.

@Phototonic
Phototonic marked this pull request as ready for review October 23, 2026 10:54
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.

Auto-capture prompt for tool used section always list unknown tool call

1 participant