The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(cli): amp translates its own tool arguments
0xken150e671abf6b8b
diff --git a/cli/src/engines/amp/normalizer.spec.ts b/cli/src/engines/amp/normalizer.spec.tsindex f7c790511..54a652a89 100644--- a/cli/src/engines/amp/normalizer.spec.ts+++ b/cli/src/engines/amp/normalizer.spec.ts@@ -127,6 +127,30 @@ describe('amp tool names', () => {})})+describe('amp tool arguments', () => {+ it('gives WebSearch a `query`, which is the field the cards read', () => {+ // Amp sends {objective, search_queries}; web renders from `query` (or cursor's `search_term`), so+ // without this a real search drew as Web Search(""). Adapting belongs in the engine, not the surface.+ const n = new AmpNormalizer()+ const events = n.ingest(JSON.stringify({+ t: 'tool_call', id: 'TU-1', tool: 'web_search',+ input: { objective: 'Find the current BTC price', search_queries: ['btc price'] },+ }))+ // events[0] is the turn the backstop opened — a tool arriving with no turn_start still has to render.+ expect(events.find((e) => e.type === 'tool_start'))+ .toMatchObject({ payload: { tool: 'WebSearch', input: { query: 'Find the current BTC price' } } })+ })++ it('leaves a tool that already speaks the shared shape alone', () => {+ const n = new AmpNormalizer()+ const events = n.ingest(JSON.stringify({+ t: 'tool_call', id: 'TU-2', tool: 'shell_command', input: { command: 'ls', workdir: '/tmp' },+ }))+ expect(events.find((e) => e.type === 'tool_start'))+ .toMatchObject({ payload: { tool: 'Bash', input: { command: 'ls', workdir: '/tmp' } } })+ })+})+describe('amp tool output', () => {it('unwraps the shapes Amp returns', () => {expect(ampToolOutput({ output: 'hello\n', exitCode: 0 })).toBe('hello\n')diff --git a/cli/src/engines/amp/normalizer.ts b/cli/src/engines/amp/normalizer.tsindex 851c16d87..93bc4c1d1 100644--- a/cli/src/engines/amp/normalizer.ts+++ b/cli/src/engines/amp/normalizer.ts@@ -79,6 +79,30 @@ const TOOL_NAMES: Record<string, string> = {todo_read: 'TodoRead',}+/**+ * Amp's tool arguments → the field names the shared cards already read.+ *+ * The consumers are not the place to learn an engine's spelling. Web renders `WebSearch` from `query`+ * (or cursor's `search_term`) and Amp sends neither — it sends `{objective, search_queries}` — so a real+ * search drew as `Web Search("")`, a card admitting a search happened and refusing to say what for. The+ * fix belongs HERE, exactly as muse's `TodoWrite` is reshaped so `input.todos[].content` matches: one+ * engine adapts once, instead of every surface learning every engine.+ *+ * The original keys are kept alongside, so the expanded card still shows what Amp was actually given.+ */+export function ampToolInput(tool: string, input: unknown): unknown {+ const args = obj(input)+ if (!args) return input ?? {}+ if (tool === 'WebSearch' && !str(args.query)) {+ const queries = Array.isArray(args.search_queries)+ ? args.search_queries.filter((q): q is string => typeof q === 'string').join(', ')+ : ''+ const query = str(args.objective).trim() || queries+ if (query) return { ...args, query }+ }+ return args+}+export function ampToolName(name: string): string {return TOOL_NAMES[name] ?? (name ? name.charAt(0).toUpperCase() + name.slice(1) : 'Tool')}@@ -241,7 +265,7 @@ export function ampRecordToEvents(record: JsonObject, state: AmpTurnState, mode:const tool = ampToolName(str(record.tool))state.toolNames.set(id, tool)state.pendingTools.add(id)- events.push({ type: 'tool_start', payload: { id, tool, input: record.input ?? {} } })+ events.push({ type: 'tool_start', payload: { id, tool, input: ampToolInput(tool, record.input) } })return events}diff --git a/cli/src/engines/amp/threadExport.spec.ts b/cli/src/engines/amp/threadExport.spec.tsindex 95ea3eb84..fe5b896e2 100644--- a/cli/src/engines/amp/threadExport.spec.ts+++ b/cli/src/engines/amp/threadExport.spec.ts@@ -68,6 +68,27 @@ describe('amp thread export → history', () => {expect(events.find((e) => e.type === 'tool_end')).toMatchObject({ payload: { tool: 'Bash' } })})+ /**+ * The consumers already render `WebSearch` from `query`; teaching each of them Amp's spelling would be+ * the wrong layer. The adapter adapts — same rule muse's `TodoWrite` reshape follows.+ */+ it("hands the search card a `query`, because that is what the surfaces read", () => {+ const start = ampThreadToEvents(messages()).find((e) => e.type === 'tool_start')+ const input = (start as { payload: { input: Record<string, unknown> } }).payload.input+ expect(input.query).toBe(input.objective)+ // The original keys survive, so the expanded card still shows what Amp was actually given.+ expect(input.objective).toBeTruthy()+ })++ it('falls back to the queries when there is no objective', () => {+ const noObjective = [{+ role: 'assistant',+ content: [{ type: 'tool_use', id: 'TU-1', name: 'web_search', input: { search_queries: ['btc price', 'eth price'] } }],+ }]+ const start = ampThreadToEvents(noObjective).find((e) => e.type === 'tool_start')+ expect((start as { payload: { input: Record<string, unknown> } }).payload.input.query).toBe('btc price, eth price')+ })+it('survives a thread with nothing in it', () => {expect(ampThreadToEvents([])).toEqual([{ type: 'done', payload: { result: 'success' } }])})diff --git a/cli/src/engines/amp/threadExport.ts b/cli/src/engines/amp/threadExport.tsindex b9aba2cbd..ba2a3dd53 100644--- a/cli/src/engines/amp/threadExport.ts+++ b/cli/src/engines/amp/threadExport.ts@@ -19,7 +19,7 @@ import { execFile } from 'child_process'import { promisify } from 'util'import { env } from '../../config/env.js'import type { SessionEvent } from '../../lib/normalize.js'-import { ampToolName, ampToolOutput, clip } from './normalizer.js'+import { ampToolInput, ampToolName, ampToolOutput, clip } from './normalizer.js'const execFileAsync = promisify(execFile)@@ -115,7 +115,7 @@ export function ampThreadToEvents(messages: JsonObject[]): SessionEvent[] {if (!id) continueconst tool = ampToolName(str(block.name))toolNames.set(id, tool)- events.push({ type: 'tool_start', payload: { id, tool, input: block.input ?? {} } })+ events.push({ type: 'tool_start', payload: { id, tool, input: ampToolInput(tool, block.input) } })} else if (type === 'tool_result') {const id = str(block.toolUseID) || str(block.tool_use_id)if (!id) continue