@posthog/agent 1.25.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/_virtual/_tslib.js +74 -0
  2. package/dist/_virtual/_tslib.js.map +1 -0
  3. package/dist/_virtual/index.js +2 -2
  4. package/dist/_virtual/index2.js +2 -2
  5. package/dist/_virtual/index8.js +2 -2
  6. package/dist/_virtual/index9.js +2 -2
  7. package/dist/node_modules/@agentclientprotocol/sdk/dist/acp.js +284 -3
  8. package/dist/node_modules/@agentclientprotocol/sdk/dist/acp.js.map +1 -1
  9. package/dist/node_modules/@agentclientprotocol/sdk/dist/schema.js +2 -1
  10. package/dist/node_modules/@agentclientprotocol/sdk/dist/schema.js.map +1 -1
  11. package/dist/node_modules/ajv/dist/ajv.js +1 -1
  12. package/dist/node_modules/ajv/dist/compile/codegen/index.js +1 -1
  13. package/dist/node_modules/ajv/dist/compile/validate/index.js +1 -1
  14. package/dist/node_modules/ajv/dist/vocabularies/discriminator/index.js +1 -1
  15. package/dist/node_modules/ajv-formats/dist/index.js +1 -1
  16. package/dist/package.json.js +1 -1
  17. package/dist/src/adapters/claude/claude.d.ts.map +1 -1
  18. package/dist/src/adapters/claude/claude.js +21 -5
  19. package/dist/src/adapters/claude/claude.js.map +1 -1
  20. package/dist/src/adapters/claude/mcp-server.js +105 -92
  21. package/dist/src/adapters/claude/mcp-server.js.map +1 -1
  22. package/dist/src/adapters/claude/tools.d.ts.map +1 -1
  23. package/dist/src/adapters/claude/tools.js +8 -1
  24. package/dist/src/adapters/claude/tools.js.map +1 -1
  25. package/dist/src/agent.d.ts +7 -1
  26. package/dist/src/agent.d.ts.map +1 -1
  27. package/dist/src/agent.js +151 -0
  28. package/dist/src/agent.js.map +1 -1
  29. package/dist/src/session-store.d.ts +7 -2
  30. package/dist/src/session-store.d.ts.map +1 -1
  31. package/dist/src/session-store.js +11 -0
  32. package/dist/src/session-store.js.map +1 -1
  33. package/dist/src/worktree-manager.d.ts.map +1 -1
  34. package/dist/src/worktree-manager.js +3 -5
  35. package/dist/src/worktree-manager.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/adapters/claude/claude.ts +21 -5
  38. package/src/adapters/claude/tools.ts +8 -1
  39. package/src/agent.ts +213 -1
  40. package/src/session-store.ts +18 -3
  41. package/src/worktree-manager.ts +4 -7
@@ -1,3 +1,4 @@
1
+ import { __addDisposableResource, __disposeResources } from '../../../_virtual/_tslib.js';
1
2
  import { randomBytes } from 'node:crypto';
2
3
  import { McpServer } from '../../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js';
3
4
  import { createPatch } from '../../../node_modules/diff/libesm/patch/create.js';
@@ -313,108 +314,120 @@ Output: Create directory 'foo'`),
313
314
  .describe(`Set to true to run this command in the background. The tool returns an \`id\` that can be used with the \`${toolNames.bashOutput}\` tool to retrieve the current output, or the \`${toolNames.killShell}\` tool to stop it early.`),
314
315
  },
315
316
  }, async (input, extra) => {
316
- const session = agent.sessions[sessionId];
317
- if (!session) {
318
- return {
319
- content: [
320
- {
321
- type: "text",
322
- text: "The user has left the building",
323
- },
324
- ],
325
- };
326
- }
327
- const toolCallId = extra._meta?.["claudecode/toolUseId"];
328
- if (typeof toolCallId !== "string") {
329
- throw new Error("No tool call ID found");
330
- }
331
- if (!agent.clientCapabilities?.terminal ||
332
- !agent.client.createTerminal) {
333
- throw new Error("unreachable");
334
- }
335
- const handle = await agent.client.createTerminal({
336
- command: input.command,
337
- env: [{ name: "CLAUDECODE", value: "1" }],
338
- sessionId,
339
- outputByteLimit: 32_000,
340
- });
341
- await agent.client.sessionUpdate({
342
- sessionId,
343
- update: {
344
- sessionUpdate: "tool_call_update",
345
- toolCallId,
346
- status: "in_progress",
347
- title: input.description,
348
- content: [{ type: "terminal", terminalId: handle.id }],
349
- },
350
- });
351
- const abortPromise = new Promise((resolve) => {
352
- if (extra.signal.aborted) {
353
- resolve(null);
317
+ const env_1 = { stack: [], error: void 0, hasError: false };
318
+ try {
319
+ const session = agent.sessions[sessionId];
320
+ if (!session) {
321
+ return {
322
+ content: [
323
+ {
324
+ type: "text",
325
+ text: "The user has left the building",
326
+ },
327
+ ],
328
+ };
354
329
  }
355
- else {
356
- extra.signal.addEventListener("abort", () => {
357
- resolve(null);
358
- });
330
+ const toolCallId = extra._meta?.["claudecode/toolUseId"];
331
+ if (typeof toolCallId !== "string") {
332
+ throw new Error("No tool call ID found");
359
333
  }
360
- });
361
- const statusPromise = Promise.race([
362
- handle
363
- .waitForExit()
364
- .then((exitStatus) => ({ status: "exited", exitStatus })),
365
- abortPromise.then(() => ({
366
- status: "aborted",
367
- exitStatus: null,
368
- })),
369
- sleep(input.timeout).then(async () => {
370
- if (agent.backgroundTerminals[handle.id]?.status === "started") {
371
- await handle.kill();
334
+ if (!agent.clientCapabilities?.terminal ||
335
+ !agent.client.createTerminal) {
336
+ throw new Error("unreachable");
337
+ }
338
+ const handle = await agent.client.createTerminal({
339
+ command: input.command,
340
+ env: [{ name: "CLAUDECODE", value: "1" }],
341
+ sessionId,
342
+ outputByteLimit: 32_000,
343
+ });
344
+ await agent.client.sessionUpdate({
345
+ sessionId,
346
+ update: {
347
+ sessionUpdate: "tool_call_update",
348
+ toolCallId,
349
+ status: "in_progress",
350
+ title: input.description,
351
+ content: [{ type: "terminal", terminalId: handle.id }],
352
+ },
353
+ });
354
+ const abortPromise = new Promise((resolve) => {
355
+ if (extra.signal.aborted) {
356
+ resolve(null);
372
357
  }
373
- return { status: "timedOut", exitStatus: null };
374
- }),
375
- ]);
376
- if (input.run_in_background) {
377
- agent.backgroundTerminals[handle.id] = {
378
- handle,
379
- lastOutput: null,
380
- status: "started",
381
- };
382
- statusPromise.then(async ({ status, exitStatus }) => {
383
- const bgTerm = agent.backgroundTerminals[handle.id];
384
- if (bgTerm.status !== "started") {
385
- return;
358
+ else {
359
+ extra.signal.addEventListener("abort", () => {
360
+ resolve(null);
361
+ });
386
362
  }
387
- const currentOutput = await handle.currentOutput();
363
+ });
364
+ const statusPromise = Promise.race([
365
+ handle
366
+ .waitForExit()
367
+ .then((exitStatus) => ({ status: "exited", exitStatus })),
368
+ abortPromise.then(() => ({
369
+ status: "aborted",
370
+ exitStatus: null,
371
+ })),
372
+ sleep(input.timeout).then(async () => {
373
+ if (agent.backgroundTerminals[handle.id]?.status === "started") {
374
+ await handle.kill();
375
+ }
376
+ return { status: "timedOut", exitStatus: null };
377
+ }),
378
+ ]);
379
+ if (input.run_in_background) {
388
380
  agent.backgroundTerminals[handle.id] = {
389
- status,
390
- pendingOutput: {
391
- ...currentOutput,
392
- output: stripCommonPrefix(bgTerm.lastOutput?.output ?? "", currentOutput.output),
393
- exitStatus: exitStatus ?? currentOutput.exitStatus,
394
- },
381
+ handle,
382
+ lastOutput: null,
383
+ status: "started",
395
384
  };
396
- return handle.release();
397
- });
385
+ statusPromise.then(async ({ status, exitStatus }) => {
386
+ const bgTerm = agent.backgroundTerminals[handle.id];
387
+ if (bgTerm.status !== "started") {
388
+ return;
389
+ }
390
+ const currentOutput = await handle.currentOutput();
391
+ agent.backgroundTerminals[handle.id] = {
392
+ status,
393
+ pendingOutput: {
394
+ ...currentOutput,
395
+ output: stripCommonPrefix(bgTerm.lastOutput?.output ?? "", currentOutput.output),
396
+ exitStatus: exitStatus ?? currentOutput.exitStatus,
397
+ },
398
+ };
399
+ return handle.release();
400
+ });
401
+ return {
402
+ content: [
403
+ {
404
+ type: "text",
405
+ text: `Command started in background with id: ${handle.id}`,
406
+ },
407
+ ],
408
+ };
409
+ }
410
+ const terminal = __addDisposableResource(env_1, handle, true);
411
+ const { status } = await statusPromise;
412
+ if (status === "aborted") {
413
+ return {
414
+ content: [{ type: "text", text: "Tool cancelled by user" }],
415
+ };
416
+ }
417
+ const output = await terminal.currentOutput();
398
418
  return {
399
- content: [
400
- {
401
- type: "text",
402
- text: `Command started in background with id: ${handle.id}`,
403
- },
404
- ],
419
+ content: [{ type: "text", text: toolCommandOutput(status, output) }],
405
420
  };
406
421
  }
407
- await using terminal = handle;
408
- const { status } = await statusPromise;
409
- if (status === "aborted") {
410
- return {
411
- content: [{ type: "text", text: "Tool cancelled by user" }],
412
- };
422
+ catch (e_1) {
423
+ env_1.error = e_1;
424
+ env_1.hasError = true;
425
+ }
426
+ finally {
427
+ const result_1 = __disposeResources(env_1);
428
+ if (result_1)
429
+ await result_1;
413
430
  }
414
- const output = await terminal.currentOutput();
415
- return {
416
- content: [{ type: "text", text: toolCommandOutput(status, output) }],
417
- };
418
431
  });
419
432
  server.registerTool(unqualifiedToolNames.bashOutput, {
420
433
  title: unqualifiedToolNames.bashOutput,
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-server.js","sources":["../../../../src/adapters/claude/mcp-server.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport type {\n ClientCapabilities,\n TerminalOutputResponse,\n} from \"@agentclientprotocol/sdk\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport * as diff from \"diff\";\nimport { z } from \"zod\";\nimport { Logger } from \"@/utils/logger.js\";\nimport type { ClaudeAcpAgent } from \"./claude.js\";\nimport { extractLinesWithByteLimit, sleep, unreachable } from \"./utils.js\";\n\nexport const SYSTEM_REMINDER = `\n\n<system-reminder>\nWhenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.\n</system-reminder>`;\n\nconst defaults = { maxFileSize: 50000, linesToRead: 2000 };\n\nconst unqualifiedToolNames = {\n read: \"Read\",\n edit: \"Edit\",\n write: \"Write\",\n bash: \"Bash\",\n killShell: \"KillShell\",\n bashOutput: \"BashOutput\",\n};\n\nconst SERVER_PREFIX = \"mcp__acp__\";\nexport const toolNames = {\n read: SERVER_PREFIX + unqualifiedToolNames.read,\n edit: SERVER_PREFIX + unqualifiedToolNames.edit,\n write: SERVER_PREFIX + unqualifiedToolNames.write,\n bash: SERVER_PREFIX + unqualifiedToolNames.bash,\n killShell: SERVER_PREFIX + unqualifiedToolNames.killShell,\n bashOutput: SERVER_PREFIX + unqualifiedToolNames.bashOutput,\n};\n\nexport const EDIT_TOOL_NAMES = [toolNames.edit, toolNames.write];\n\nexport function createMcpServer(\n agent: ClaudeAcpAgent,\n sessionId: string,\n clientCapabilities: ClientCapabilities | undefined,\n): McpServer {\n // Create MCP server\n const server = new McpServer(\n { name: \"acp\", version: \"1.0.0\" },\n { capabilities: { tools: {} } },\n );\n\n if (clientCapabilities?.fs?.readTextFile) {\n server.registerTool(\n unqualifiedToolNames.read,\n {\n title: unqualifiedToolNames.read,\n description: `Reads the content of the given file in the project.\n\nIn sessions with ${toolNames.read} always use it instead of Read as it contains the most up-to-date contents.\n\nReads a file from the local filesystem. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.\n\nUsage:\n- The file_path parameter must be an absolute path, not a relative path\n- By default, it reads up to ${defaults.linesToRead} lines starting from the beginning of the file\n- You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters\n- Any files larger than ${defaults.maxFileSize} bytes will be truncated\n- This tool allows Claude Code to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Claude Code is a multimodal LLM.\n- This tool can only read files, not directories. To read a directory, use an ls command via the ${toolNames.bash} tool.\n- You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.`,\n inputSchema: {\n file_path: z\n .string()\n .describe(\"The absolute path to the file to read\"),\n offset: z\n .number()\n .optional()\n .default(1)\n .describe(\n \"The line number to start reading from. Only provide if the file is too large to read at once\",\n ),\n limit: z\n .number()\n .optional()\n .default(defaults.linesToRead)\n .describe(\n `The number of lines to read. Only provide if the file is too large to read at once.`,\n ),\n },\n annotations: {\n title: \"Read file\",\n readOnlyHint: true,\n destructiveHint: false,\n openWorldHint: false,\n idempotentHint: false,\n },\n },\n async (input) => {\n try {\n const session = agent.sessions[sessionId];\n if (!session) {\n return {\n content: [\n {\n type: \"text\",\n text: \"The user has left the building\",\n },\n ],\n };\n }\n\n const readResponse = await agent.readTextFile({\n sessionId,\n path: input.file_path,\n line: input.offset,\n limit: input.limit,\n });\n\n if (typeof readResponse?.content !== \"string\") {\n throw new Error(`No file contents for ${input.file_path}.`);\n }\n\n // Extract lines with byte limit enforcement\n const result = extractLinesWithByteLimit(\n readResponse.content,\n defaults.maxFileSize,\n );\n\n // Construct informative message about what was read\n let readInfo = \"\";\n if (input.offset > 1 || result.wasLimited) {\n readInfo = \"\\n\\n<file-read-info>\";\n\n if (result.wasLimited) {\n readInfo += `Read ${result.linesRead} lines (hit 50KB limit). `;\n } else {\n readInfo += `Read lines ${input.offset}-${result.linesRead}. `;\n }\n\n if (result.wasLimited) {\n readInfo += `Continue with offset=${result.linesRead}.`;\n }\n\n readInfo += \"</file-read-info>\";\n }\n\n return {\n content: [\n {\n type: \"text\",\n text: result.content + readInfo + SYSTEM_REMINDER,\n },\n ],\n };\n } catch (error: any) {\n return {\n content: [\n {\n type: \"text\",\n text: `Reading file failed: ${error.message}`,\n },\n ],\n };\n }\n },\n );\n }\n\n if (clientCapabilities?.fs?.writeTextFile) {\n server.registerTool(\n unqualifiedToolNames.write,\n {\n title: unqualifiedToolNames.write,\n description: `Writes a file to the local filesystem..\n\nIn sessions with ${toolNames.write} always use it instead of Write as it will\nallow the user to conveniently review changes.\n\nUsage:\n- This tool will overwrite the existing file if there is one at the provided path.\n- If this is an existing file, you MUST use the ${toolNames.read} tool first to read the file's contents. This tool will fail if you did not read the file first.\n- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.\n- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.\n- Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.`,\n inputSchema: {\n file_path: z\n .string()\n .describe(\n \"The absolute path to the file to write (must be absolute, not relative)\",\n ),\n content: z.string().describe(\"The content to write to the file\"),\n },\n annotations: {\n title: \"Write file\",\n readOnlyHint: false,\n destructiveHint: false,\n openWorldHint: false,\n idempotentHint: false,\n },\n },\n async (input) => {\n try {\n const session = agent.sessions[sessionId];\n if (!session) {\n return {\n content: [\n {\n type: \"text\",\n text: \"The user has left the building\",\n },\n ],\n };\n }\n await agent.writeTextFile({\n sessionId,\n path: input.file_path,\n content: input.content,\n });\n\n return {\n content: [],\n };\n } catch (error: any) {\n return {\n content: [\n {\n type: \"text\",\n text: `Writing file failed: ${error.message}`,\n },\n ],\n };\n }\n },\n );\n\n server.registerTool(\n unqualifiedToolNames.edit,\n {\n title: unqualifiedToolNames.edit,\n description: `Performs exact string replacements in files.\n\nIn sessions with ${toolNames.edit} always use it instead of Edit as it will\nallow the user to conveniently review changes.\n\nUsage:\n- You must use your \\`${toolNames.read}\\` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.\n- When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears.\n- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.\n- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.\n- The edit will FAIL if \\`old_string\\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \\`replace_all\\` to change every instance of \\`old_string\\`.\n- Use \\`replace_all\\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.`,\n inputSchema: {\n file_path: z\n .string()\n .describe(\"The absolute path to the file to modify\"),\n old_string: z.string().describe(\"The text to replace\"),\n new_string: z\n .string()\n .describe(\n \"The text to replace it with (must be different from old_string)\",\n ),\n replace_all: z\n .boolean()\n .default(false)\n .optional()\n .describe(\"Replace all occurences of old_string (default false)\"),\n },\n annotations: {\n title: \"Edit file\",\n readOnlyHint: false,\n destructiveHint: false,\n openWorldHint: false,\n idempotentHint: false,\n },\n },\n async (input) => {\n try {\n const session = agent.sessions[sessionId];\n if (!session) {\n return {\n content: [\n {\n type: \"text\",\n text: \"The user has left the building\",\n },\n ],\n };\n }\n\n const readResponse = await agent.readTextFile({\n sessionId,\n path: input.file_path,\n });\n\n if (typeof readResponse?.content !== \"string\") {\n throw new Error(`No file contents for ${input.file_path}.`);\n }\n\n const { newContent } = replaceAndCalculateLocation(\n readResponse.content,\n [\n {\n oldText: input.old_string,\n newText: input.new_string,\n replaceAll: input.replace_all,\n },\n ],\n );\n\n const patch = diff.createPatch(\n input.file_path,\n readResponse.content,\n newContent,\n );\n\n await agent.writeTextFile({\n sessionId,\n path: input.file_path,\n content: newContent,\n });\n\n return {\n content: [\n {\n type: \"text\",\n text: patch,\n },\n ],\n };\n } catch (error: any) {\n return {\n content: [\n {\n type: \"text\",\n text: `Editing file failed: ${error?.message ?? String(error)}`,\n },\n ],\n };\n }\n },\n );\n }\n\n if (agent.clientCapabilities?.terminal) {\n server.registerTool(\n unqualifiedToolNames.bash,\n {\n title: unqualifiedToolNames.bash,\n description: `Executes a bash command\n\nIn sessions with ${toolNames.bash} always use it instead of Bash`,\n inputSchema: {\n command: z.string().describe(\"The command to execute\"),\n timeout: z\n .number()\n .default(2 * 60 * 1000)\n .describe(\n `Optional timeout in milliseconds (max ${2 * 60 * 1000})`,\n ),\n description: z\n .string()\n .optional()\n .describe(`Clear, concise description of what this command does in 5-10 words, in active voice. Examples:\nInput: ls\nOutput: List files in current directory\n\nInput: git status\nOutput: Show working tree status\n\nInput: npm install\nOutput: Install package dependencies\n\nInput: mkdir foo\nOutput: Create directory 'foo'`),\n run_in_background: z\n .boolean()\n .default(false)\n .describe(\n `Set to true to run this command in the background. The tool returns an \\`id\\` that can be used with the \\`${toolNames.bashOutput}\\` tool to retrieve the current output, or the \\`${toolNames.killShell}\\` tool to stop it early.`,\n ),\n },\n },\n async (input, extra) => {\n const session = agent.sessions[sessionId];\n if (!session) {\n return {\n content: [\n {\n type: \"text\",\n text: \"The user has left the building\",\n },\n ],\n };\n }\n\n const toolCallId = extra._meta?.[\"claudecode/toolUseId\"];\n\n if (typeof toolCallId !== \"string\") {\n throw new Error(\"No tool call ID found\");\n }\n\n if (\n !agent.clientCapabilities?.terminal ||\n !agent.client.createTerminal\n ) {\n throw new Error(\"unreachable\");\n }\n\n const handle = await agent.client.createTerminal({\n command: input.command,\n env: [{ name: \"CLAUDECODE\", value: \"1\" }],\n sessionId,\n outputByteLimit: 32_000,\n });\n\n await agent.client.sessionUpdate({\n sessionId,\n update: {\n sessionUpdate: \"tool_call_update\",\n toolCallId,\n status: \"in_progress\",\n title: input.description,\n content: [{ type: \"terminal\", terminalId: handle.id }],\n },\n });\n\n const abortPromise = new Promise((resolve) => {\n if (extra.signal.aborted) {\n resolve(null);\n } else {\n extra.signal.addEventListener(\"abort\", () => {\n resolve(null);\n });\n }\n });\n\n const statusPromise = Promise.race([\n handle\n .waitForExit()\n .then((exitStatus) => ({ status: \"exited\" as const, exitStatus })),\n abortPromise.then(() => ({\n status: \"aborted\" as const,\n exitStatus: null,\n })),\n sleep(input.timeout).then(async () => {\n if (agent.backgroundTerminals[handle.id]?.status === \"started\") {\n await handle.kill();\n }\n return { status: \"timedOut\" as const, exitStatus: null };\n }),\n ]);\n\n if (input.run_in_background) {\n agent.backgroundTerminals[handle.id] = {\n handle,\n lastOutput: null,\n status: \"started\",\n };\n\n statusPromise.then(async ({ status, exitStatus }) => {\n const bgTerm = agent.backgroundTerminals[handle.id];\n\n if (bgTerm.status !== \"started\") {\n return;\n }\n\n const currentOutput = await handle.currentOutput();\n\n agent.backgroundTerminals[handle.id] = {\n status,\n pendingOutput: {\n ...currentOutput,\n output: stripCommonPrefix(\n bgTerm.lastOutput?.output ?? \"\",\n currentOutput.output,\n ),\n exitStatus: exitStatus ?? currentOutput.exitStatus,\n },\n };\n\n return handle.release();\n });\n\n return {\n content: [\n {\n type: \"text\",\n text: `Command started in background with id: ${handle.id}`,\n },\n ],\n };\n }\n\n await using terminal = handle;\n\n const { status } = await statusPromise;\n\n if (status === \"aborted\") {\n return {\n content: [{ type: \"text\", text: \"Tool cancelled by user\" }],\n };\n }\n\n const output = await terminal.currentOutput();\n\n return {\n content: [{ type: \"text\", text: toolCommandOutput(status, output) }],\n };\n },\n );\n\n server.registerTool(\n unqualifiedToolNames.bashOutput,\n {\n title: unqualifiedToolNames.bashOutput,\n description: `- Retrieves output from a running or completed background bash shell\n- Takes a shell_id parameter identifying the shell\n- Always returns only new output since the last check\n- Returns stdout and stderr output along with shell status\n- Use this tool when you need to monitor or check the output of a long-running shell\n\nIn sessions with ${toolNames.bashOutput} always use it instead of BashOutput.`,\n inputSchema: {\n shell_id: z\n .string()\n .describe(\n `The id of the background bash command as returned by \\`${toolNames.bash}\\``,\n ),\n },\n },\n async (input) => {\n const bgTerm = agent.backgroundTerminals[input.shell_id];\n\n if (!bgTerm) {\n throw new Error(`Unknown shell ${input.shell_id}`);\n }\n\n if (bgTerm.status === \"started\") {\n const newOutput = await bgTerm.handle.currentOutput();\n const strippedOutput = stripCommonPrefix(\n bgTerm.lastOutput?.output ?? \"\",\n newOutput.output,\n );\n bgTerm.lastOutput = newOutput;\n\n return {\n content: [\n {\n type: \"text\",\n text: toolCommandOutput(bgTerm.status, {\n ...newOutput,\n output: strippedOutput,\n }),\n },\n ],\n };\n } else {\n return {\n content: [\n {\n type: \"text\",\n text: toolCommandOutput(bgTerm.status, bgTerm.pendingOutput),\n },\n ],\n };\n }\n },\n );\n\n server.registerTool(\n unqualifiedToolNames.killShell,\n {\n title: unqualifiedToolNames.killShell,\n description: `- Kills a running background bash shell by its ID\n- Takes a shell_id parameter identifying the shell to kill\n- Returns a success or failure status\n- Use this tool when you need to terminate a long-running shell\n\nIn sessions with ${toolNames.killShell} always use it instead of KillShell.`,\n inputSchema: {\n shell_id: z\n .string()\n .describe(\n `The id of the background bash command as returned by \\`${toolNames.bash}\\``,\n ),\n },\n },\n async (input) => {\n const bgTerm = agent.backgroundTerminals[input.shell_id];\n\n if (!bgTerm) {\n throw new Error(`Unknown shell ${input.shell_id}`);\n }\n\n switch (bgTerm.status) {\n case \"started\": {\n await bgTerm.handle.kill();\n const currentOutput = await bgTerm.handle.currentOutput();\n agent.backgroundTerminals[bgTerm.handle.id] = {\n status: \"killed\",\n pendingOutput: {\n ...currentOutput,\n output: stripCommonPrefix(\n bgTerm.lastOutput?.output ?? \"\",\n currentOutput.output,\n ),\n },\n };\n await bgTerm.handle.release();\n\n return {\n content: [{ type: \"text\", text: \"Command killed successfully.\" }],\n };\n }\n case \"aborted\":\n return {\n content: [{ type: \"text\", text: \"Command aborted by user.\" }],\n };\n case \"exited\":\n return {\n content: [{ type: \"text\", text: \"Command had already exited.\" }],\n };\n case \"killed\":\n return {\n content: [{ type: \"text\", text: \"Command was already killed.\" }],\n };\n case \"timedOut\":\n return {\n content: [{ type: \"text\", text: \"Command killed by timeout.\" }],\n };\n default: {\n unreachable(bgTerm, new Logger({ prefix: \"[McpServer]\" }));\n throw new Error(\"Unexpected background terminal status\");\n }\n }\n },\n );\n }\n\n return server;\n}\n\nfunction stripCommonPrefix(a: string, b: string): string {\n let i = 0;\n while (i < a.length && i < b.length && a[i] === b[i]) {\n i++;\n }\n return b.slice(i);\n}\n\nfunction toolCommandOutput(\n status: \"started\" | \"aborted\" | \"exited\" | \"killed\" | \"timedOut\",\n output: TerminalOutputResponse,\n): string {\n const { exitStatus, output: commandOutput, truncated } = output;\n\n let toolOutput = \"\";\n\n switch (status) {\n case \"started\":\n case \"exited\": {\n if (exitStatus && (exitStatus.exitCode ?? null) === null) {\n toolOutput += `Interrupted by the user. `;\n }\n break;\n }\n case \"killed\":\n toolOutput += `Killed. `;\n break;\n case \"timedOut\":\n toolOutput += `Timed out. `;\n break;\n case \"aborted\":\n break;\n default: {\n const unreachable: never = status;\n return unreachable;\n }\n }\n\n if (exitStatus) {\n if (typeof exitStatus.exitCode === \"number\") {\n toolOutput += `Exited with code ${exitStatus.exitCode}.`;\n }\n\n if (typeof exitStatus.signal === \"string\") {\n toolOutput += `Signal \\`${exitStatus.signal}\\`. `;\n }\n\n toolOutput += \"Final output:\\n\\n\";\n } else {\n toolOutput += \"New output:\\n\\n\";\n }\n\n toolOutput += commandOutput;\n\n if (truncated) {\n toolOutput += `\\n\\nCommand output was too long, so it was truncated to ${commandOutput.length} bytes.`;\n }\n\n return toolOutput;\n}\n\n/**\n * Replace text in a file and calculate the line numbers where the edits occurred.\n *\n * @param fileContent - The full file content\n * @param edits - Array of edit operations to apply sequentially\n * @returns the new content and the line numbers where replacements occurred in the final content\n */\nexport function replaceAndCalculateLocation(\n fileContent: string,\n edits: Array<{\n oldText: string;\n newText: string;\n replaceAll?: boolean;\n }>,\n): { newContent: string; lineNumbers: number[] } {\n let currentContent = fileContent;\n\n // Use unique markers to track where replacements happen\n const markerPrefix = `__REPLACE_MARKER_${randomBytes(5).toString(\"hex\")}_`;\n let markerCounter = 0;\n const markers: string[] = [];\n\n // Apply edits sequentially, inserting markers at replacement positions\n for (const edit of edits) {\n // Skip empty oldText\n if (edit.oldText === \"\") {\n throw new Error(\n `The provided \\`old_string\\` is empty.\\n\\nNo edits were applied.`,\n );\n }\n\n if (edit.replaceAll) {\n // Replace all occurrences with marker + newText\n const parts: string[] = [];\n let lastIndex = 0;\n let searchIndex = 0;\n\n while (true) {\n const index = currentContent.indexOf(edit.oldText, searchIndex);\n if (index === -1) {\n if (searchIndex === 0) {\n throw new Error(\n `The provided \\`old_string\\` does not appear in the file: \"${edit.oldText}\".\\n\\nNo edits were applied.`,\n );\n }\n break;\n }\n\n // Add content before the match\n parts.push(currentContent.substring(lastIndex, index));\n\n // Add marker and replacement\n const marker = `${markerPrefix}${markerCounter++}__`;\n markers.push(marker);\n parts.push(marker + edit.newText);\n\n lastIndex = index + edit.oldText.length;\n searchIndex = lastIndex;\n }\n\n // Add remaining content\n parts.push(currentContent.substring(lastIndex));\n currentContent = parts.join(\"\");\n } else {\n // Replace first occurrence only\n const index = currentContent.indexOf(edit.oldText);\n if (index === -1) {\n throw new Error(\n `The provided \\`old_string\\` does not appear in the file: \"${edit.oldText}\".\\n\\nNo edits were applied.`,\n );\n } else {\n const marker = `${markerPrefix}${markerCounter++}__`;\n markers.push(marker);\n currentContent =\n currentContent.substring(0, index) +\n marker +\n edit.newText +\n currentContent.substring(index + edit.oldText.length);\n }\n }\n }\n\n // Find line numbers where markers appear in the content\n const lineNumbers: number[] = [];\n for (const marker of markers) {\n const index = currentContent.indexOf(marker);\n if (index !== -1) {\n const lineNumber = Math.max(\n 0,\n currentContent.substring(0, index).split(/\\r\\n|\\r|\\n/).length - 1,\n );\n lineNumbers.push(lineNumber);\n }\n }\n\n // Remove all markers from the final content\n let finalContent = currentContent;\n for (const marker of markers) {\n finalContent = finalContent.replace(marker, \"\");\n }\n\n // Dedupe and sort line numbers\n const uniqueLineNumbers = [...new Set(lineNumbers)].sort();\n\n return { newContent: finalContent, lineNumbers: uniqueLineNumbers };\n}\n"],"names":["diff.createPatch"],"mappings":";;;;;;;AAYO,MAAM,eAAe,GAAG;;;;;AAM/B,MAAM,QAAQ,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE;AAE1D,MAAM,oBAAoB,GAAG;AAC3B,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,UAAU,EAAE,YAAY;CACzB;AAED,MAAM,aAAa,GAAG,YAAY;AAC3B,MAAM,SAAS,GAAG;AACvB,IAAA,IAAI,EAAE,aAAa,GAAG,oBAAoB,CAAC,IAAI;AAC/C,IAAA,IAAI,EAAE,aAAa,GAAG,oBAAoB,CAAC,IAAI;AAC/C,IAAA,KAAK,EAAE,aAAa,GAAG,oBAAoB,CAAC,KAAK;AACjD,IAAA,IAAI,EAAE,aAAa,GAAG,oBAAoB,CAAC,IAAI;AAC/C,IAAA,SAAS,EAAE,aAAa,GAAG,oBAAoB,CAAC,SAAS;AACzD,IAAA,UAAU,EAAE,aAAa,GAAG,oBAAoB,CAAC,UAAU;;AAGtD,MAAM,eAAe,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK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EAAE,iBAAiB,EAAE;AACrE;;;;"}
1
+ {"version":3,"file":"mcp-server.js","sources":["../../../../src/adapters/claude/mcp-server.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport type {\n ClientCapabilities,\n TerminalOutputResponse,\n} from \"@agentclientprotocol/sdk\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport * as diff from \"diff\";\nimport { z } from \"zod\";\nimport { Logger } from \"@/utils/logger.js\";\nimport type { ClaudeAcpAgent } from \"./claude.js\";\nimport { extractLinesWithByteLimit, sleep, unreachable } from \"./utils.js\";\n\nexport const SYSTEM_REMINDER = `\n\n<system-reminder>\nWhenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.\n</system-reminder>`;\n\nconst defaults = { maxFileSize: 50000, linesToRead: 2000 };\n\nconst unqualifiedToolNames = {\n read: \"Read\",\n edit: \"Edit\",\n write: \"Write\",\n bash: \"Bash\",\n killShell: \"KillShell\",\n bashOutput: \"BashOutput\",\n};\n\nconst SERVER_PREFIX = \"mcp__acp__\";\nexport const toolNames = {\n read: SERVER_PREFIX + unqualifiedToolNames.read,\n edit: SERVER_PREFIX + unqualifiedToolNames.edit,\n write: SERVER_PREFIX + unqualifiedToolNames.write,\n bash: SERVER_PREFIX + unqualifiedToolNames.bash,\n killShell: SERVER_PREFIX + unqualifiedToolNames.killShell,\n bashOutput: SERVER_PREFIX + unqualifiedToolNames.bashOutput,\n};\n\nexport const EDIT_TOOL_NAMES = [toolNames.edit, toolNames.write];\n\nexport function createMcpServer(\n agent: ClaudeAcpAgent,\n sessionId: string,\n clientCapabilities: ClientCapabilities | undefined,\n): McpServer {\n // Create MCP server\n const server = new McpServer(\n { name: \"acp\", version: \"1.0.0\" },\n { capabilities: { tools: {} } },\n );\n\n if (clientCapabilities?.fs?.readTextFile) {\n server.registerTool(\n unqualifiedToolNames.read,\n {\n title: unqualifiedToolNames.read,\n description: `Reads the content of the given file in the project.\n\nIn sessions with ${toolNames.read} always use it instead of Read as it contains the most up-to-date contents.\n\nReads a file from the local filesystem. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.\n\nUsage:\n- The file_path parameter must be an absolute path, not a relative path\n- By default, it reads up to ${defaults.linesToRead} lines starting from the beginning of the file\n- You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters\n- Any files larger than ${defaults.maxFileSize} bytes will be truncated\n- This tool allows Claude Code to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Claude Code is a multimodal LLM.\n- This tool can only read files, not directories. To read a directory, use an ls command via the ${toolNames.bash} tool.\n- You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.`,\n inputSchema: {\n file_path: z\n .string()\n .describe(\"The absolute path to the file to read\"),\n offset: z\n .number()\n .optional()\n .default(1)\n .describe(\n \"The line number to start reading from. Only provide if the file is too large to read at once\",\n ),\n limit: z\n .number()\n .optional()\n .default(defaults.linesToRead)\n .describe(\n `The number of lines to read. Only provide if the file is too large to read at once.`,\n ),\n },\n annotations: {\n title: \"Read file\",\n readOnlyHint: true,\n destructiveHint: false,\n openWorldHint: false,\n idempotentHint: false,\n },\n },\n async (input) => {\n try {\n const session = agent.sessions[sessionId];\n if (!session) {\n return {\n content: [\n {\n type: \"text\",\n text: \"The user has left the building\",\n },\n ],\n };\n }\n\n const readResponse = await agent.readTextFile({\n sessionId,\n path: input.file_path,\n line: input.offset,\n limit: input.limit,\n });\n\n if (typeof readResponse?.content !== \"string\") {\n throw new Error(`No file contents for ${input.file_path}.`);\n }\n\n // Extract lines with byte limit enforcement\n const result = extractLinesWithByteLimit(\n readResponse.content,\n defaults.maxFileSize,\n );\n\n // Construct informative message about what was read\n let readInfo = \"\";\n if (input.offset > 1 || result.wasLimited) {\n readInfo = \"\\n\\n<file-read-info>\";\n\n if (result.wasLimited) {\n readInfo += `Read ${result.linesRead} lines (hit 50KB limit). `;\n } else {\n readInfo += `Read lines ${input.offset}-${result.linesRead}. `;\n }\n\n if (result.wasLimited) {\n readInfo += `Continue with offset=${result.linesRead}.`;\n }\n\n readInfo += \"</file-read-info>\";\n }\n\n return {\n content: [\n {\n type: \"text\",\n text: result.content + readInfo + SYSTEM_REMINDER,\n },\n ],\n };\n } catch (error: any) {\n return {\n content: [\n {\n type: \"text\",\n text: `Reading file failed: ${error.message}`,\n },\n ],\n };\n }\n },\n );\n }\n\n if (clientCapabilities?.fs?.writeTextFile) {\n server.registerTool(\n unqualifiedToolNames.write,\n {\n title: unqualifiedToolNames.write,\n description: `Writes a file to the local filesystem..\n\nIn sessions with ${toolNames.write} always use it instead of Write as it will\nallow the user to conveniently review changes.\n\nUsage:\n- This tool will overwrite the existing file if there is one at the provided path.\n- If this is an existing file, you MUST use the ${toolNames.read} tool first to read the file's contents. This tool will fail if you did not read the file first.\n- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.\n- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.\n- Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.`,\n inputSchema: {\n file_path: z\n .string()\n .describe(\n \"The absolute path to the file to write (must be absolute, not relative)\",\n ),\n content: z.string().describe(\"The content to write to the file\"),\n },\n annotations: {\n title: \"Write file\",\n readOnlyHint: false,\n destructiveHint: false,\n openWorldHint: false,\n idempotentHint: false,\n },\n },\n async (input) => {\n try {\n const session = agent.sessions[sessionId];\n if (!session) {\n return {\n content: [\n {\n type: \"text\",\n text: \"The user has left the building\",\n },\n ],\n };\n }\n await agent.writeTextFile({\n sessionId,\n path: input.file_path,\n content: input.content,\n });\n\n return {\n content: [],\n };\n } catch (error: any) {\n return {\n content: [\n {\n type: \"text\",\n text: `Writing file failed: ${error.message}`,\n },\n ],\n };\n }\n },\n );\n\n server.registerTool(\n unqualifiedToolNames.edit,\n {\n title: unqualifiedToolNames.edit,\n description: `Performs exact string replacements in files.\n\nIn sessions with ${toolNames.edit} always use it instead of Edit as it will\nallow the user to conveniently review changes.\n\nUsage:\n- You must use your \\`${toolNames.read}\\` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.\n- When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears.\n- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.\n- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.\n- The edit will FAIL if \\`old_string\\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \\`replace_all\\` to change every instance of \\`old_string\\`.\n- Use \\`replace_all\\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.`,\n inputSchema: {\n file_path: z\n .string()\n .describe(\"The absolute path to the file to modify\"),\n old_string: z.string().describe(\"The text to replace\"),\n new_string: z\n .string()\n .describe(\n \"The text to replace it with (must be different from old_string)\",\n ),\n replace_all: z\n .boolean()\n .default(false)\n .optional()\n .describe(\"Replace all occurences of old_string (default false)\"),\n },\n annotations: {\n title: \"Edit file\",\n readOnlyHint: false,\n destructiveHint: false,\n openWorldHint: false,\n idempotentHint: false,\n },\n },\n async (input) => {\n try {\n const session = agent.sessions[sessionId];\n if (!session) {\n return {\n content: [\n {\n type: \"text\",\n text: \"The user has left the building\",\n },\n ],\n };\n }\n\n const readResponse = await agent.readTextFile({\n sessionId,\n path: input.file_path,\n });\n\n if (typeof readResponse?.content !== \"string\") {\n throw new Error(`No file contents for ${input.file_path}.`);\n }\n\n const { newContent } = replaceAndCalculateLocation(\n readResponse.content,\n [\n {\n oldText: input.old_string,\n newText: input.new_string,\n replaceAll: input.replace_all,\n },\n ],\n );\n\n const patch = diff.createPatch(\n input.file_path,\n readResponse.content,\n newContent,\n );\n\n await agent.writeTextFile({\n sessionId,\n path: input.file_path,\n content: newContent,\n });\n\n return {\n content: [\n {\n type: \"text\",\n text: patch,\n },\n ],\n };\n } catch (error: any) {\n return {\n content: [\n {\n type: \"text\",\n text: `Editing file failed: ${error?.message ?? String(error)}`,\n },\n ],\n };\n }\n },\n );\n }\n\n if (agent.clientCapabilities?.terminal) {\n server.registerTool(\n unqualifiedToolNames.bash,\n {\n title: unqualifiedToolNames.bash,\n description: `Executes a bash command\n\nIn sessions with ${toolNames.bash} always use it instead of Bash`,\n inputSchema: {\n command: z.string().describe(\"The command to execute\"),\n timeout: z\n .number()\n .default(2 * 60 * 1000)\n .describe(\n `Optional timeout in milliseconds (max ${2 * 60 * 1000})`,\n ),\n description: z\n .string()\n .optional()\n .describe(`Clear, concise description of what this command does in 5-10 words, in active voice. Examples:\nInput: ls\nOutput: List files in current directory\n\nInput: git status\nOutput: Show working tree status\n\nInput: npm install\nOutput: Install package dependencies\n\nInput: mkdir foo\nOutput: Create directory 'foo'`),\n run_in_background: z\n .boolean()\n .default(false)\n .describe(\n `Set to true to run this command in the background. The tool returns an \\`id\\` that can be used with the \\`${toolNames.bashOutput}\\` tool to retrieve the current output, or the \\`${toolNames.killShell}\\` tool to stop it early.`,\n ),\n },\n },\n async (input, extra) => {\n const session = agent.sessions[sessionId];\n if (!session) {\n return {\n content: [\n {\n type: \"text\",\n text: \"The user has left the building\",\n },\n ],\n };\n }\n\n const toolCallId = extra._meta?.[\"claudecode/toolUseId\"];\n\n if (typeof toolCallId !== \"string\") {\n throw new Error(\"No tool call ID found\");\n }\n\n if (\n !agent.clientCapabilities?.terminal ||\n !agent.client.createTerminal\n ) {\n throw new Error(\"unreachable\");\n }\n\n const handle = await agent.client.createTerminal({\n command: input.command,\n env: [{ name: \"CLAUDECODE\", value: \"1\" }],\n sessionId,\n outputByteLimit: 32_000,\n });\n\n await agent.client.sessionUpdate({\n sessionId,\n update: {\n sessionUpdate: \"tool_call_update\",\n toolCallId,\n status: \"in_progress\",\n title: input.description,\n content: [{ type: \"terminal\", terminalId: handle.id }],\n },\n });\n\n const abortPromise = new Promise((resolve) => {\n if (extra.signal.aborted) {\n resolve(null);\n } else {\n extra.signal.addEventListener(\"abort\", () => {\n resolve(null);\n });\n }\n });\n\n const statusPromise = Promise.race([\n handle\n .waitForExit()\n .then((exitStatus) => ({ status: \"exited\" as const, exitStatus })),\n abortPromise.then(() => ({\n status: \"aborted\" as const,\n exitStatus: null,\n })),\n sleep(input.timeout).then(async () => {\n if (agent.backgroundTerminals[handle.id]?.status === \"started\") {\n await handle.kill();\n }\n return { status: \"timedOut\" as const, exitStatus: null };\n }),\n ]);\n\n if (input.run_in_background) {\n agent.backgroundTerminals[handle.id] = {\n handle,\n lastOutput: null,\n status: \"started\",\n };\n\n statusPromise.then(async ({ status, exitStatus }) => {\n const bgTerm = agent.backgroundTerminals[handle.id];\n\n if (bgTerm.status !== \"started\") {\n return;\n }\n\n const currentOutput = await handle.currentOutput();\n\n agent.backgroundTerminals[handle.id] = {\n status,\n pendingOutput: {\n ...currentOutput,\n output: stripCommonPrefix(\n bgTerm.lastOutput?.output ?? \"\",\n currentOutput.output,\n ),\n exitStatus: exitStatus ?? currentOutput.exitStatus,\n },\n };\n\n return handle.release();\n });\n\n return {\n content: [\n {\n type: \"text\",\n text: `Command started in background with id: ${handle.id}`,\n },\n ],\n };\n }\n\n await using terminal = handle;\n\n const { status } = await statusPromise;\n\n if (status === \"aborted\") {\n return {\n content: [{ type: \"text\", text: \"Tool cancelled by user\" }],\n };\n }\n\n const output = await terminal.currentOutput();\n\n return {\n content: [{ type: \"text\", text: toolCommandOutput(status, output) }],\n };\n },\n );\n\n server.registerTool(\n unqualifiedToolNames.bashOutput,\n {\n title: unqualifiedToolNames.bashOutput,\n description: `- Retrieves output from a running or completed background bash shell\n- Takes a shell_id parameter identifying the shell\n- Always returns only new output since the last check\n- Returns stdout and stderr output along with shell status\n- Use this tool when you need to monitor or check the output of a long-running shell\n\nIn sessions with ${toolNames.bashOutput} always use it instead of BashOutput.`,\n inputSchema: {\n shell_id: z\n .string()\n .describe(\n `The id of the background bash command as returned by \\`${toolNames.bash}\\``,\n ),\n },\n },\n async (input) => {\n const bgTerm = agent.backgroundTerminals[input.shell_id];\n\n if (!bgTerm) {\n throw new Error(`Unknown shell ${input.shell_id}`);\n }\n\n if (bgTerm.status === \"started\") {\n const newOutput = await bgTerm.handle.currentOutput();\n const strippedOutput = stripCommonPrefix(\n bgTerm.lastOutput?.output ?? \"\",\n newOutput.output,\n );\n bgTerm.lastOutput = newOutput;\n\n return {\n content: [\n {\n type: \"text\",\n text: toolCommandOutput(bgTerm.status, {\n ...newOutput,\n output: strippedOutput,\n }),\n },\n ],\n };\n } else {\n return {\n content: [\n {\n type: \"text\",\n text: toolCommandOutput(bgTerm.status, bgTerm.pendingOutput),\n },\n ],\n };\n }\n },\n );\n\n server.registerTool(\n unqualifiedToolNames.killShell,\n {\n title: unqualifiedToolNames.killShell,\n description: `- Kills a running background bash shell by its ID\n- Takes a shell_id parameter identifying the shell to kill\n- Returns a success or failure status\n- Use this tool when you need to terminate a long-running shell\n\nIn sessions with ${toolNames.killShell} always use it instead of KillShell.`,\n inputSchema: {\n shell_id: z\n .string()\n .describe(\n `The id of the background bash command as returned by \\`${toolNames.bash}\\``,\n ),\n },\n },\n async (input) => {\n const bgTerm = agent.backgroundTerminals[input.shell_id];\n\n if (!bgTerm) {\n throw new Error(`Unknown shell ${input.shell_id}`);\n }\n\n switch (bgTerm.status) {\n case \"started\": {\n await bgTerm.handle.kill();\n const currentOutput = await bgTerm.handle.currentOutput();\n agent.backgroundTerminals[bgTerm.handle.id] = {\n status: \"killed\",\n pendingOutput: {\n ...currentOutput,\n output: stripCommonPrefix(\n bgTerm.lastOutput?.output ?? \"\",\n currentOutput.output,\n ),\n },\n };\n await bgTerm.handle.release();\n\n return {\n content: [{ type: \"text\", text: \"Command killed successfully.\" }],\n };\n }\n case \"aborted\":\n return {\n content: [{ type: \"text\", text: \"Command aborted by user.\" }],\n };\n case \"exited\":\n return {\n content: [{ type: \"text\", text: \"Command had already exited.\" }],\n };\n case \"killed\":\n return {\n content: [{ type: \"text\", text: \"Command was already killed.\" }],\n };\n case \"timedOut\":\n return {\n content: [{ type: \"text\", text: \"Command killed by timeout.\" }],\n };\n default: {\n unreachable(bgTerm, new Logger({ prefix: \"[McpServer]\" }));\n throw new Error(\"Unexpected background terminal status\");\n }\n }\n },\n );\n }\n\n return server;\n}\n\nfunction stripCommonPrefix(a: string, b: string): string {\n let i = 0;\n while (i < a.length && i < b.length && a[i] === b[i]) {\n i++;\n }\n return b.slice(i);\n}\n\nfunction toolCommandOutput(\n status: \"started\" | \"aborted\" | \"exited\" | \"killed\" | \"timedOut\",\n output: TerminalOutputResponse,\n): string {\n const { exitStatus, output: commandOutput, truncated } = output;\n\n let toolOutput = \"\";\n\n switch (status) {\n case \"started\":\n case \"exited\": {\n if (exitStatus && (exitStatus.exitCode ?? null) === null) {\n toolOutput += `Interrupted by the user. `;\n }\n break;\n }\n case \"killed\":\n toolOutput += `Killed. `;\n break;\n case \"timedOut\":\n toolOutput += `Timed out. `;\n break;\n case \"aborted\":\n break;\n default: {\n const unreachable: never = status;\n return unreachable;\n }\n }\n\n if (exitStatus) {\n if (typeof exitStatus.exitCode === \"number\") {\n toolOutput += `Exited with code ${exitStatus.exitCode}.`;\n }\n\n if (typeof exitStatus.signal === \"string\") {\n toolOutput += `Signal \\`${exitStatus.signal}\\`. `;\n }\n\n toolOutput += \"Final output:\\n\\n\";\n } else {\n toolOutput += \"New output:\\n\\n\";\n }\n\n toolOutput += commandOutput;\n\n if (truncated) {\n toolOutput += `\\n\\nCommand output was too long, so it was truncated to ${commandOutput.length} bytes.`;\n }\n\n return toolOutput;\n}\n\n/**\n * Replace text in a file and calculate the line numbers where the edits occurred.\n *\n * @param fileContent - The full file content\n * @param edits - Array of edit operations to apply sequentially\n * @returns the new content and the line numbers where replacements occurred in the final content\n */\nexport function replaceAndCalculateLocation(\n fileContent: string,\n edits: Array<{\n oldText: string;\n newText: string;\n replaceAll?: boolean;\n }>,\n): { newContent: string; lineNumbers: number[] } {\n let currentContent = fileContent;\n\n // Use unique markers to track where replacements happen\n const markerPrefix = `__REPLACE_MARKER_${randomBytes(5).toString(\"hex\")}_`;\n let markerCounter = 0;\n const markers: string[] = [];\n\n // Apply edits sequentially, inserting markers at replacement positions\n for (const edit of edits) {\n // Skip empty oldText\n if (edit.oldText === \"\") {\n throw new Error(\n `The provided \\`old_string\\` is empty.\\n\\nNo edits were applied.`,\n );\n }\n\n if (edit.replaceAll) {\n // Replace all occurrences with marker + newText\n const parts: string[] = [];\n let lastIndex = 0;\n let searchIndex = 0;\n\n while (true) {\n const index = currentContent.indexOf(edit.oldText, searchIndex);\n if (index === -1) {\n if (searchIndex === 0) {\n throw new Error(\n `The provided \\`old_string\\` does not appear in the file: \"${edit.oldText}\".\\n\\nNo edits were applied.`,\n );\n }\n break;\n }\n\n // Add content before the match\n parts.push(currentContent.substring(lastIndex, index));\n\n // Add marker and replacement\n const marker = `${markerPrefix}${markerCounter++}__`;\n markers.push(marker);\n parts.push(marker + edit.newText);\n\n lastIndex = index + edit.oldText.length;\n searchIndex = lastIndex;\n }\n\n // Add remaining content\n parts.push(currentContent.substring(lastIndex));\n currentContent = parts.join(\"\");\n } else {\n // Replace first occurrence only\n const index = currentContent.indexOf(edit.oldText);\n if (index === -1) {\n throw new Error(\n `The provided \\`old_string\\` does not appear in the file: \"${edit.oldText}\".\\n\\nNo edits were applied.`,\n );\n } else {\n const marker = `${markerPrefix}${markerCounter++}__`;\n markers.push(marker);\n currentContent =\n currentContent.substring(0, index) +\n marker +\n edit.newText +\n currentContent.substring(index + edit.oldText.length);\n }\n }\n }\n\n // Find line numbers where markers appear in the content\n const lineNumbers: number[] = [];\n for (const marker of markers) {\n const index = currentContent.indexOf(marker);\n if (index !== -1) {\n const lineNumber = Math.max(\n 0,\n currentContent.substring(0, index).split(/\\r\\n|\\r|\\n/).length - 1,\n );\n lineNumbers.push(lineNumber);\n }\n }\n\n // Remove all markers from the final content\n let finalContent = currentContent;\n for (const marker of markers) {\n finalContent = finalContent.replace(marker, \"\");\n }\n\n // Dedupe and sort line numbers\n const uniqueLineNumbers = [...new Set(lineNumbers)].sort();\n\n return {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AE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAC5C,MAAM,GAAE,MAA8D,GACrE,QAAQ,CAwXV;AAED,wBAAgB,wBAAwB,CACtC,UAAU,EACN,oBAAoB,GACpB,iCAAiC,GACjC,gCAAgC,GAChC,6BAA6B,GAC7B,qCAAqC,GACrC,yCAAyC,GACzC,+CAA+C,GAC/C,kCAAkC,GAClC,kCAAkC,EACtC,OAAO,EAAE,GAAG,GAAG,SAAS,GACvB,UAAU,CAmEZ;AAmCD,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,GAAG,aAAa,GAAG,WAAW,CAAC;IAChD,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,eAAe,EAAE,CAAA;CAAE,GAAG,SAAS,EAAE,CAM5E;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQnD;AAcD,eAAO,MAAM,oBAAoB,GAC/B,WAAW,MAAM,EACjB,wBAEG;IACD,iBAAiB,CAAC,EAAE,CAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,OAAO,EAClB,YAAY,EAAE,OAAO,KAClB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,SAKF,CAAC;AAGF,eAAO,MAAM,qBAAqB,GAE9B,SAAQ,MAA0D,KACjE,YAsBF,CAAC"}
@@ -105,7 +105,14 @@ function toolInfoFromToolUse(toolUse, cachedFileContent, logger = new Logger({ d
105
105
  title: "Read File",
106
106
  kind: "read",
107
107
  content: [],
108
- locations: [{ path: input.file_path, line: input.offset ?? 0 }],
108
+ locations: input.file_path
109
+ ? [
110
+ {
111
+ path: input.file_path,
112
+ line: input.offset ?? 0,
113
+ },
114
+ ]
115
+ : [],
109
116
  };
110
117
  case "LS":
111
118
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","sources":["../../../../src/adapters/claude/tools.ts"],"sourcesContent":["import type {\n PlanEntry,\n ToolCallContent,\n ToolCallLocation,\n ToolKind,\n} from \"@agentclientprotocol/sdk\";\nimport type { HookCallback, HookInput } from \"@anthropic-ai/claude-agent-sdk\";\nimport type {\n ToolResultBlockParam,\n WebSearchToolResultBlockParam,\n} from \"@anthropic-ai/sdk/resources\";\nimport type {\n BetaBashCodeExecutionToolResultBlockParam,\n BetaCodeExecutionToolResultBlockParam,\n BetaRequestMCPToolResultBlockParam,\n BetaTextEditorCodeExecutionToolResultBlockParam,\n BetaToolSearchToolResultBlockParam,\n BetaWebFetchToolResultBlockParam,\n BetaWebSearchToolResultBlockParam,\n} from \"@anthropic-ai/sdk/resources/beta.mjs\";\nimport { Logger } from \"@/utils/logger.js\";\nimport {\n replaceAndCalculateLocation,\n SYSTEM_REMINDER,\n toolNames,\n} from \"./mcp-server.js\";\n\ninterface ToolInfo {\n title: string;\n kind: ToolKind;\n content: ToolCallContent[];\n locations?: ToolCallLocation[];\n}\n\ninterface ToolUpdate {\n title?: string;\n content?: ToolCallContent[];\n locations?: ToolCallLocation[];\n}\n\nexport function toolInfoFromToolUse(\n toolUse: any,\n cachedFileContent: { [key: string]: string },\n logger: Logger = new Logger({ debug: false, prefix: \"[ClaudeTools]\" }),\n): ToolInfo {\n const name = toolUse.name;\n const input = toolUse.input;\n\n switch (name) {\n case \"Task\":\n return {\n title: input?.description ? input.description : \"Task\",\n kind: \"think\",\n content: input?.prompt\n ? [\n {\n type: \"content\",\n content: { type: \"text\", text: input.prompt },\n },\n ]\n : [],\n };\n\n case \"NotebookRead\":\n return {\n title: input?.notebook_path\n ? `Read Notebook ${input.notebook_path}`\n : \"Read Notebook\",\n kind: \"read\",\n content: [],\n locations: input?.notebook_path ? [{ path: input.notebook_path }] : [],\n };\n\n case \"NotebookEdit\":\n return {\n title: input?.notebook_path\n ? `Edit Notebook ${input.notebook_path}`\n : \"Edit Notebook\",\n kind: \"edit\",\n content: input?.new_source\n ? [\n {\n type: \"content\",\n content: { type: \"text\", text: input.new_source },\n },\n ]\n : [],\n locations: input?.notebook_path ? [{ path: input.notebook_path }] : [],\n };\n\n case \"Bash\":\n case toolNames.bash:\n return {\n title: input?.command\n ? `\\`${input.command.replaceAll(\"`\", \"\\\\`\")}\\``\n : \"Terminal\",\n kind: \"execute\",\n content: input?.description\n ? [\n {\n type: \"content\",\n content: { type: \"text\", text: input.description },\n },\n ]\n : [],\n };\n\n case \"BashOutput\":\n case toolNames.bashOutput:\n return {\n title: \"Tail Logs\",\n kind: \"execute\",\n content: [],\n };\n\n case \"KillShell\":\n case toolNames.killShell:\n return {\n title: \"Kill Process\",\n kind: \"execute\",\n content: [],\n };\n\n case toolNames.read: {\n let limit = \"\";\n if (input.limit) {\n limit =\n \" (\" +\n ((input.offset ?? 0) + 1) +\n \" - \" +\n ((input.offset ?? 0) + input.limit) +\n \")\";\n } else if (input.offset) {\n limit = ` (from line ${input.offset + 1})`;\n }\n return {\n title: `Read ${input.file_path ?? \"File\"}${limit}`,\n kind: \"read\",\n locations: input.file_path\n ? [\n {\n path: input.file_path,\n line: input.offset ?? 0,\n },\n ]\n : [],\n content: [],\n };\n }\n\n case \"Read\":\n return {\n title: \"Read File\",\n kind: \"read\",\n content: [],\n locations: [{ path: input.file_path, line: input.offset ?? 0 }],\n };\n\n case \"LS\":\n return {\n title: `List the ${input?.path ? `\\`${input.path}\\`` : \"current\"} directory's contents`,\n kind: \"search\",\n content: [],\n locations: [],\n };\n\n case toolNames.edit:\n case \"Edit\": {\n const path = input?.file_path ?? input?.file_path;\n let oldText = input.old_string ?? null;\n let newText = input.new_string ?? \"\";\n let affectedLines: number[] = [];\n\n if (path && oldText) {\n try {\n const oldContent = cachedFileContent[path] || \"\";\n const newContent = replaceAndCalculateLocation(oldContent, [\n {\n oldText,\n newText,\n replaceAll: false,\n },\n ]);\n oldText = oldContent;\n newText = newContent.newContent;\n affectedLines = newContent.lineNumbers;\n } catch (e) {\n logger.error(\"Failed to edit file\", e);\n }\n }\n return {\n title: path ? `Edit \\`${path}\\`` : \"Edit\",\n kind: \"edit\",\n content:\n input && path\n ? [\n {\n type: \"diff\",\n path,\n oldText,\n newText,\n },\n ]\n : [],\n locations: path\n ? affectedLines.length > 0\n ? affectedLines.map((line) => ({ line, path }))\n : [{ path }]\n : [],\n };\n }\n\n case toolNames.write: {\n let content: ToolCallContent[] = [];\n if (input?.file_path) {\n content = [\n {\n type: \"diff\",\n path: input.file_path,\n oldText: null,\n newText: input.content,\n },\n ];\n } else if (input?.content) {\n content = [\n {\n type: \"content\",\n content: { type: \"text\", text: input.content },\n },\n ];\n }\n return {\n title: input?.file_path ? `Write ${input.file_path}` : \"Write\",\n kind: \"edit\",\n content,\n locations: input?.file_path ? [{ path: input.file_path }] : [],\n };\n }\n\n case \"Write\":\n return {\n title: input?.file_path ? `Write ${input.file_path}` : \"Write\",\n kind: \"edit\",\n content: input?.file_path\n ? [\n {\n type: \"diff\",\n path: input.file_path,\n oldText: null,\n newText: input.content,\n },\n ]\n : [],\n locations: input?.file_path ? [{ path: input.file_path }] : [],\n };\n\n case \"Glob\": {\n let label = \"Find\";\n if (input.path) {\n label += ` \\`${input.path}\\``;\n }\n if (input.pattern) {\n label += ` \\`${input.pattern}\\``;\n }\n return {\n title: label,\n kind: \"search\",\n content: [],\n locations: input.path ? [{ path: input.path }] : [],\n };\n }\n\n case \"Grep\": {\n let label = \"grep\";\n\n if (input[\"-i\"]) {\n label += \" -i\";\n }\n if (input[\"-n\"]) {\n label += \" -n\";\n }\n\n if (input[\"-A\"] !== undefined) {\n label += ` -A ${input[\"-A\"]}`;\n }\n if (input[\"-B\"] !== undefined) {\n label += ` -B ${input[\"-B\"]}`;\n }\n if (input[\"-C\"] !== undefined) {\n label += ` -C ${input[\"-C\"]}`;\n }\n\n if (input.output_mode) {\n switch (input.output_mode) {\n case \"FilesWithMatches\":\n label += \" -l\";\n break;\n case \"Count\":\n label += \" -c\";\n break;\n default:\n break;\n }\n }\n\n if (input.head_limit !== undefined) {\n label += ` | head -${input.head_limit}`;\n }\n\n if (input.glob) {\n label += ` --include=\"${input.glob}\"`;\n }\n\n if (input.type) {\n label += ` --type=${input.type}`;\n }\n\n if (input.multiline) {\n label += \" -P\";\n }\n\n label += ` \"${input.pattern}\"`;\n\n if (input.path) {\n label += ` ${input.path}`;\n }\n\n return {\n title: label,\n kind: \"search\",\n content: [],\n };\n }\n\n case \"WebFetch\":\n return {\n title: input?.url ? `Fetch ${input.url}` : \"Fetch\",\n kind: \"fetch\",\n content: input?.prompt\n ? [\n {\n type: \"content\",\n content: { type: \"text\", text: input.prompt },\n },\n ]\n : [],\n };\n\n case \"WebSearch\": {\n let label = `\"${input.query}\"`;\n\n if (input.allowed_domains && input.allowed_domains.length > 0) {\n label += ` (allowed: ${input.allowed_domains.join(\", \")})`;\n }\n\n if (input.blocked_domains && input.blocked_domains.length > 0) {\n label += ` (blocked: ${input.blocked_domains.join(\", \")})`;\n }\n\n return {\n title: label,\n kind: \"fetch\",\n content: [],\n };\n }\n\n case \"TodoWrite\":\n return {\n title: Array.isArray(input?.todos)\n ? `Update TODOs: ${input.todos.map((todo: any) => todo.content).join(\", \")}`\n : \"Update TODOs\",\n kind: \"think\",\n content: [],\n };\n\n case \"ExitPlanMode\":\n return {\n title: \"Ready to code?\",\n kind: \"switch_mode\",\n content: input?.plan\n ? [{ type: \"content\", content: { type: \"text\", text: input.plan } }]\n : [],\n };\n\n case \"Other\": {\n let output: string;\n try {\n output = JSON.stringify(input, null, 2);\n } catch {\n output = typeof input === \"string\" ? input : \"{}\";\n }\n return {\n title: name || \"Unknown Tool\",\n kind: \"other\",\n content: [\n {\n type: \"content\",\n content: {\n type: \"text\",\n text: `\\`\\`\\`json\\n${output}\\`\\`\\``,\n },\n },\n ],\n };\n }\n\n default:\n return {\n title: name || \"Unknown Tool\",\n kind: \"other\",\n content: [],\n };\n }\n}\n\nexport function toolUpdateFromToolResult(\n toolResult:\n | ToolResultBlockParam\n | BetaWebSearchToolResultBlockParam\n | BetaWebFetchToolResultBlockParam\n | WebSearchToolResultBlockParam\n | BetaCodeExecutionToolResultBlockParam\n | BetaBashCodeExecutionToolResultBlockParam\n | BetaTextEditorCodeExecutionToolResultBlockParam\n | BetaRequestMCPToolResultBlockParam\n | BetaToolSearchToolResultBlockParam,\n toolUse: any | undefined,\n): ToolUpdate {\n switch (toolUse?.name) {\n case \"Read\":\n case toolNames.read:\n if (Array.isArray(toolResult.content) && toolResult.content.length > 0) {\n return {\n content: toolResult.content.map((content: any) => ({\n type: \"content\",\n content:\n content.type === \"text\"\n ? {\n type: \"text\",\n text: markdownEscape(\n content.text.replace(SYSTEM_REMINDER, \"\"),\n ),\n }\n : content,\n })),\n };\n } else if (\n typeof toolResult.content === \"string\" &&\n toolResult.content.length > 0\n ) {\n return {\n content: [\n {\n type: \"content\",\n content: {\n type: \"text\",\n text: markdownEscape(\n toolResult.content.replace(SYSTEM_REMINDER, \"\"),\n ),\n },\n },\n ],\n };\n }\n return {};\n\n case toolNames.bash:\n case \"edit\":\n case \"Edit\":\n case toolNames.edit:\n case toolNames.write:\n case \"Write\": {\n if (\n \"is_error\" in toolResult &&\n toolResult.is_error &&\n toolResult.content &&\n toolResult.content.length > 0\n ) {\n // Only return errors\n return toAcpContentUpdate(toolResult.content, true);\n }\n return {};\n }\n\n case \"ExitPlanMode\": {\n return { title: \"Exited Plan Mode\" };\n }\n default: {\n return toAcpContentUpdate(\n toolResult.content,\n \"is_error\" in toolResult ? toolResult.is_error : false,\n );\n }\n }\n}\n\nfunction toAcpContentUpdate(\n content: any,\n isError: boolean = false,\n): { content?: ToolCallContent[] } {\n if (Array.isArray(content) && content.length > 0) {\n return {\n content: content.map((content: any) => ({\n type: \"content\",\n content:\n isError && content.type === \"text\"\n ? {\n ...content,\n text: `\\`\\`\\`\\n${content.text}\\n\\`\\`\\``,\n }\n : content,\n })),\n };\n } else if (typeof content === \"string\" && content.length > 0) {\n return {\n content: [\n {\n type: \"content\",\n content: {\n type: \"text\",\n text: isError ? `\\`\\`\\`\\n${content}\\n\\`\\`\\`` : content,\n },\n },\n ],\n };\n }\n return {};\n}\n\nexport type ClaudePlanEntry = {\n content: string;\n status: \"pending\" | \"in_progress\" | \"completed\";\n activeForm: string;\n};\n\nexport function planEntries(input: { todos: ClaudePlanEntry[] }): PlanEntry[] {\n return input.todos.map((input) => ({\n content: input.content,\n status: input.status,\n priority: \"medium\",\n }));\n}\n\nexport function markdownEscape(text: string): string {\n let escapedText = \"```\";\n for (const [m] of text.matchAll(/^```+/gm)) {\n while (m.length >= escapedText.length) {\n escapedText += \"`\";\n }\n }\n return `${escapedText}\\n${text}${text.endsWith(\"\\n\") ? \"\" : \"\\n\"}${escapedText}`;\n}\n\n/* A global variable to store callbacks that should be executed when receiving hooks from Claude Code */\nconst toolUseCallbacks: {\n [toolUseId: string]: {\n onPostToolUseHook?: (\n toolUseID: string,\n toolInput: unknown,\n toolResponse: unknown,\n ) => Promise<void>;\n };\n} = {};\n\n/* Setup callbacks that will be called when receiving hooks from Claude Code */\nexport const registerHookCallback = (\n toolUseID: string,\n {\n onPostToolUseHook,\n }: {\n onPostToolUseHook?: (\n toolUseID: string,\n toolInput: unknown,\n toolResponse: unknown,\n ) => Promise<void>;\n },\n) => {\n toolUseCallbacks[toolUseID] = {\n onPostToolUseHook,\n };\n};\n\n/* A callback for Claude Code that is called when receiving a PostToolUse hook */\nexport const createPostToolUseHook =\n (\n logger: Logger = new Logger({ prefix: \"[createPostToolUseHook]\" }),\n ): HookCallback =>\n async (\n input: HookInput,\n toolUseID: string | undefined,\n ): Promise<{ continue: boolean }> => {\n if (input.hook_event_name === \"PostToolUse\" && toolUseID) {\n const onPostToolUseHook = toolUseCallbacks[toolUseID]?.onPostToolUseHook;\n if (onPostToolUseHook) {\n await onPostToolUseHook(\n toolUseID,\n input.tool_input,\n input.tool_response,\n );\n delete toolUseCallbacks[toolUseID]; // Cleanup after execution\n } else {\n logger.error(\n `No onPostToolUseHook found for tool use ID: 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AC1C,OAAO,CAAC,CAAC,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE;YACrC,WAAW,IAAI,GAAG;QACpB;IACF;IACA,OAAO,CAAA,EAAG,WAAW,CAAA,EAAA,EAAK,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,EAAG,WAAW,CAAA,CAAE;AAClF;AAEA;AACA,MAAM,gBAAgB,GAQlB,EAAE;AAEN;AACO,MAAM,oBAAoB,GAAG,CAClC,SAAiB,EACjB,EACE,iBAAiB,GAOlB,KACC;IACF,gBAAgB,CAAC,SAAS,CAAC,GAAG;QAC5B,iBAAiB;KAClB;AACH;AAEA;AACO,MAAM,qBAAqB,GAChC,CACE,SAAiB,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC,KAEpE,OACE,KAAgB,EAChB,SAA6B,KACK;IAClC,IAAI,KAAK,CAAC,eAAe,KAAK,aAAa,IAAI,SAAS,EAAE;QACxD,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,SAAS,CAAC,EAAE,iBAAiB;QACxE,IAAI,iBAAiB,EAAE;AACrB,YAAA,MAAM,iBAAiB,CACrB,SAAS,EACT,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,aAAa,CACpB;AACD,YAAA,OAAO,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACrC;aAAO;AACL,YAAA,MAAM,CAAC,KAAK,CACV,+CAA+C,SAAS,CAAA,CAAE,CAC3D;AACD,YAAA,OAAO,gBAAgB,CAAC,SAAS,CAAC;QACpC;IACF;AACA,IAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;AAC3B;;;;"}
1
+ {"version":3,"file":"tools.js","sources":["../../../../src/adapters/claude/tools.ts"],"sourcesContent":["import type {\n PlanEntry,\n ToolCallContent,\n ToolCallLocation,\n ToolKind,\n} from \"@agentclientprotocol/sdk\";\nimport type { HookCallback, HookInput } from \"@anthropic-ai/claude-agent-sdk\";\nimport type {\n ToolResultBlockParam,\n WebSearchToolResultBlockParam,\n} from \"@anthropic-ai/sdk/resources\";\nimport type {\n BetaBashCodeExecutionToolResultBlockParam,\n BetaCodeExecutionToolResultBlockParam,\n BetaRequestMCPToolResultBlockParam,\n BetaTextEditorCodeExecutionToolResultBlockParam,\n BetaToolSearchToolResultBlockParam,\n BetaWebFetchToolResultBlockParam,\n BetaWebSearchToolResultBlockParam,\n} from \"@anthropic-ai/sdk/resources/beta.mjs\";\nimport { Logger } from \"@/utils/logger.js\";\nimport {\n replaceAndCalculateLocation,\n SYSTEM_REMINDER,\n toolNames,\n} from \"./mcp-server.js\";\n\ninterface ToolInfo {\n title: string;\n kind: ToolKind;\n content: ToolCallContent[];\n locations?: ToolCallLocation[];\n}\n\ninterface ToolUpdate {\n title?: string;\n content?: ToolCallContent[];\n locations?: ToolCallLocation[];\n}\n\nexport function toolInfoFromToolUse(\n toolUse: any,\n cachedFileContent: { [key: string]: string },\n logger: Logger = new Logger({ debug: false, prefix: \"[ClaudeTools]\" }),\n): ToolInfo {\n const name = toolUse.name;\n const input = toolUse.input;\n\n switch (name) {\n case \"Task\":\n return {\n title: input?.description ? input.description : \"Task\",\n kind: \"think\",\n content: input?.prompt\n ? [\n {\n type: \"content\",\n content: { type: \"text\", text: input.prompt },\n },\n ]\n : [],\n };\n\n case \"NotebookRead\":\n return {\n title: input?.notebook_path\n ? `Read Notebook ${input.notebook_path}`\n : \"Read Notebook\",\n kind: \"read\",\n content: [],\n locations: input?.notebook_path ? [{ path: input.notebook_path }] : [],\n };\n\n case \"NotebookEdit\":\n return {\n title: input?.notebook_path\n ? `Edit Notebook ${input.notebook_path}`\n : \"Edit Notebook\",\n kind: \"edit\",\n content: input?.new_source\n ? [\n {\n type: \"content\",\n content: { type: \"text\", text: input.new_source },\n },\n ]\n : [],\n locations: input?.notebook_path ? [{ path: input.notebook_path }] : [],\n };\n\n case \"Bash\":\n case toolNames.bash:\n return {\n title: input?.command\n ? `\\`${input.command.replaceAll(\"`\", \"\\\\`\")}\\``\n : \"Terminal\",\n kind: \"execute\",\n content: input?.description\n ? [\n {\n type: \"content\",\n content: { type: \"text\", text: input.description },\n },\n ]\n : [],\n };\n\n case \"BashOutput\":\n case toolNames.bashOutput:\n return {\n title: \"Tail Logs\",\n kind: \"execute\",\n content: [],\n };\n\n case \"KillShell\":\n case toolNames.killShell:\n return {\n title: \"Kill Process\",\n kind: \"execute\",\n content: [],\n };\n\n case toolNames.read: {\n let limit = \"\";\n if (input.limit) {\n limit =\n \" (\" +\n ((input.offset ?? 0) + 1) +\n \" - \" +\n ((input.offset ?? 0) + input.limit) +\n \")\";\n } else if (input.offset) {\n limit = ` (from line ${input.offset + 1})`;\n }\n return {\n title: `Read ${input.file_path ?? \"File\"}${limit}`,\n kind: \"read\",\n locations: input.file_path\n ? [\n {\n path: input.file_path,\n line: input.offset ?? 0,\n },\n ]\n : [],\n content: [],\n };\n }\n\n case \"Read\":\n return {\n title: \"Read File\",\n kind: \"read\",\n content: [],\n locations: input.file_path\n ? [\n {\n path: input.file_path,\n line: input.offset ?? 0,\n },\n ]\n : [],\n };\n\n case \"LS\":\n return {\n title: `List the ${input?.path ? `\\`${input.path}\\`` : \"current\"} directory's contents`,\n kind: \"search\",\n content: [],\n locations: [],\n };\n\n case toolNames.edit:\n case \"Edit\": {\n const path = input?.file_path ?? input?.file_path;\n let oldText = input.old_string ?? null;\n let newText = input.new_string ?? \"\";\n let affectedLines: number[] = [];\n\n if (path && oldText) {\n try {\n const oldContent = cachedFileContent[path] || \"\";\n const newContent = replaceAndCalculateLocation(oldContent, [\n {\n oldText,\n newText,\n replaceAll: false,\n },\n ]);\n oldText = oldContent;\n newText = newContent.newContent;\n affectedLines = newContent.lineNumbers;\n } catch (e) {\n logger.error(\"Failed to edit file\", e);\n }\n }\n return {\n title: path ? `Edit \\`${path}\\`` : \"Edit\",\n kind: \"edit\",\n content:\n input && path\n ? [\n {\n type: \"diff\",\n path,\n oldText,\n newText,\n },\n ]\n : [],\n locations: path\n ? affectedLines.length > 0\n ? affectedLines.map((line) => ({ line, path }))\n : [{ path }]\n : [],\n };\n }\n\n case toolNames.write: {\n let content: ToolCallContent[] = [];\n if (input?.file_path) {\n content = [\n {\n type: \"diff\",\n path: input.file_path,\n oldText: null,\n newText: input.content,\n },\n ];\n } else if (input?.content) {\n content = [\n {\n type: \"content\",\n content: { type: \"text\", text: input.content },\n },\n ];\n }\n return {\n title: input?.file_path ? `Write ${input.file_path}` : \"Write\",\n kind: \"edit\",\n content,\n locations: input?.file_path ? [{ path: input.file_path }] : [],\n };\n }\n\n case \"Write\":\n return {\n title: input?.file_path ? `Write ${input.file_path}` : \"Write\",\n kind: \"edit\",\n content: input?.file_path\n ? [\n {\n type: \"diff\",\n path: input.file_path,\n oldText: null,\n newText: input.content,\n },\n ]\n : [],\n locations: input?.file_path ? [{ path: input.file_path }] : [],\n };\n\n case \"Glob\": {\n let label = \"Find\";\n if (input.path) {\n label += ` \\`${input.path}\\``;\n }\n if (input.pattern) {\n label += ` \\`${input.pattern}\\``;\n }\n return {\n title: label,\n kind: \"search\",\n content: [],\n locations: input.path ? [{ path: input.path }] : [],\n };\n }\n\n case \"Grep\": {\n let label = \"grep\";\n\n if (input[\"-i\"]) {\n label += \" -i\";\n }\n if (input[\"-n\"]) {\n label += \" -n\";\n }\n\n if (input[\"-A\"] !== undefined) {\n label += ` -A ${input[\"-A\"]}`;\n }\n if (input[\"-B\"] !== undefined) {\n label += ` -B ${input[\"-B\"]}`;\n }\n if (input[\"-C\"] !== undefined) {\n label += ` -C ${input[\"-C\"]}`;\n }\n\n if (input.output_mode) {\n switch (input.output_mode) {\n case \"FilesWithMatches\":\n label += \" -l\";\n break;\n case \"Count\":\n label += \" -c\";\n break;\n default:\n break;\n }\n }\n\n if (input.head_limit !== undefined) {\n label += ` | head -${input.head_limit}`;\n }\n\n if (input.glob) {\n label += ` --include=\"${input.glob}\"`;\n }\n\n if (input.type) {\n label += ` --type=${input.type}`;\n }\n\n if (input.multiline) {\n label += \" -P\";\n }\n\n label += ` \"${input.pattern}\"`;\n\n if (input.path) {\n label += ` ${input.path}`;\n }\n\n return {\n title: label,\n kind: \"search\",\n content: [],\n };\n }\n\n case \"WebFetch\":\n return {\n title: input?.url ? `Fetch ${input.url}` : \"Fetch\",\n kind: \"fetch\",\n content: input?.prompt\n ? [\n {\n type: \"content\",\n content: { type: \"text\", text: input.prompt },\n },\n ]\n : [],\n };\n\n case \"WebSearch\": {\n let label = `\"${input.query}\"`;\n\n if (input.allowed_domains && input.allowed_domains.length > 0) {\n label += ` (allowed: ${input.allowed_domains.join(\", \")})`;\n }\n\n if (input.blocked_domains && input.blocked_domains.length > 0) {\n label += ` (blocked: ${input.blocked_domains.join(\", \")})`;\n }\n\n return {\n title: label,\n kind: \"fetch\",\n content: [],\n };\n }\n\n case \"TodoWrite\":\n return {\n title: Array.isArray(input?.todos)\n ? `Update TODOs: ${input.todos.map((todo: any) => todo.content).join(\", \")}`\n : \"Update TODOs\",\n kind: \"think\",\n content: [],\n };\n\n case \"ExitPlanMode\":\n return {\n title: \"Ready to code?\",\n kind: \"switch_mode\",\n content: input?.plan\n ? [{ type: \"content\", content: { type: \"text\", text: input.plan } }]\n : [],\n };\n\n case \"Other\": {\n let output: string;\n try {\n output = JSON.stringify(input, null, 2);\n } catch {\n output = typeof input === \"string\" ? input : \"{}\";\n }\n return {\n title: name || \"Unknown Tool\",\n kind: \"other\",\n content: [\n {\n type: \"content\",\n content: {\n type: \"text\",\n text: `\\`\\`\\`json\\n${output}\\`\\`\\``,\n },\n },\n ],\n };\n }\n\n default:\n return {\n title: name || \"Unknown Tool\",\n kind: \"other\",\n content: [],\n };\n }\n}\n\nexport function toolUpdateFromToolResult(\n toolResult:\n | ToolResultBlockParam\n | BetaWebSearchToolResultBlockParam\n | BetaWebFetchToolResultBlockParam\n | WebSearchToolResultBlockParam\n | BetaCodeExecutionToolResultBlockParam\n | BetaBashCodeExecutionToolResultBlockParam\n | BetaTextEditorCodeExecutionToolResultBlockParam\n | BetaRequestMCPToolResultBlockParam\n | BetaToolSearchToolResultBlockParam,\n toolUse: any | undefined,\n): ToolUpdate {\n switch (toolUse?.name) {\n case \"Read\":\n case toolNames.read:\n if (Array.isArray(toolResult.content) && toolResult.content.length > 0) {\n return {\n content: toolResult.content.map((content: any) => ({\n type: \"content\",\n content:\n content.type === \"text\"\n ? {\n type: \"text\",\n text: markdownEscape(\n content.text.replace(SYSTEM_REMINDER, \"\"),\n ),\n }\n : content,\n })),\n };\n } else if (\n typeof toolResult.content === \"string\" &&\n toolResult.content.length > 0\n ) {\n return {\n content: [\n {\n type: \"content\",\n content: {\n type: \"text\",\n text: markdownEscape(\n toolResult.content.replace(SYSTEM_REMINDER, \"\"),\n ),\n },\n },\n ],\n };\n }\n return {};\n\n case toolNames.bash:\n case \"edit\":\n case \"Edit\":\n case toolNames.edit:\n case toolNames.write:\n case \"Write\": {\n if (\n \"is_error\" in toolResult &&\n toolResult.is_error &&\n toolResult.content &&\n toolResult.content.length > 0\n ) {\n // Only return errors\n return toAcpContentUpdate(toolResult.content, true);\n }\n return {};\n }\n\n case \"ExitPlanMode\": {\n return { title: \"Exited Plan Mode\" };\n }\n default: {\n return toAcpContentUpdate(\n toolResult.content,\n \"is_error\" in toolResult ? toolResult.is_error : false,\n );\n }\n }\n}\n\nfunction toAcpContentUpdate(\n content: any,\n isError: boolean = false,\n): { content?: ToolCallContent[] } {\n if (Array.isArray(content) && content.length > 0) {\n return {\n content: content.map((content: any) => ({\n type: \"content\",\n content:\n isError && content.type === \"text\"\n ? {\n ...content,\n text: `\\`\\`\\`\\n${content.text}\\n\\`\\`\\``,\n }\n : content,\n })),\n };\n } else if (typeof content === \"string\" && content.length > 0) {\n return {\n content: [\n {\n type: \"content\",\n content: {\n type: \"text\",\n text: isError ? `\\`\\`\\`\\n${content}\\n\\`\\`\\`` : content,\n },\n },\n ],\n };\n }\n return {};\n}\n\nexport type ClaudePlanEntry = {\n content: string;\n status: \"pending\" | \"in_progress\" | \"completed\";\n activeForm: string;\n};\n\nexport function planEntries(input: { todos: ClaudePlanEntry[] }): PlanEntry[] {\n return input.todos.map((input) => ({\n content: input.content,\n status: input.status,\n priority: \"medium\",\n }));\n}\n\nexport function markdownEscape(text: string): string {\n let escapedText = \"```\";\n for (const [m] of text.matchAll(/^```+/gm)) {\n while (m.length >= escapedText.length) {\n escapedText += \"`\";\n }\n }\n return `${escapedText}\\n${text}${text.endsWith(\"\\n\") ? \"\" : \"\\n\"}${escapedText}`;\n}\n\n/* A global variable to store callbacks that should be executed when receiving hooks from Claude Code */\nconst toolUseCallbacks: {\n [toolUseId: string]: {\n onPostToolUseHook?: (\n toolUseID: string,\n toolInput: unknown,\n toolResponse: unknown,\n ) => Promise<void>;\n };\n} = {};\n\n/* Setup callbacks that will be called when receiving hooks from Claude Code */\nexport const registerHookCallback = (\n toolUseID: string,\n {\n onPostToolUseHook,\n }: {\n onPostToolUseHook?: (\n toolUseID: string,\n toolInput: unknown,\n toolResponse: unknown,\n ) => Promise<void>;\n },\n) => {\n toolUseCallbacks[toolUseID] = {\n onPostToolUseHook,\n };\n};\n\n/* A callback for Claude Code that is called when receiving a PostToolUse hook */\nexport const createPostToolUseHook =\n (\n logger: Logger = new Logger({ prefix: \"[createPostToolUseHook]\" }),\n ): HookCallback =>\n async (\n input: HookInput,\n toolUseID: string | undefined,\n ): Promise<{ continue: boolean }> => {\n if (input.hook_event_name === \"PostToolUse\" && toolUseID) {\n const onPostToolUseHook = toolUseCallbacks[toolUseID]?.onPostToolUseHook;\n if (onPostToolUseHook) {\n await onPostToolUseHook(\n toolUseID,\n input.tool_input,\n input.tool_response,\n );\n delete toolUseCallbacks[toolUseID]; // Cleanup after execution\n } else {\n logger.error(\n `No onPostToolUseHook found for tool use ID: ${toolUseID}`,\n );\n delete toolUseCallbacks[toolUseID];\n }\n }\n return { continue: true };\n };\n"],"names":[],"mappings":";;;AAwCM,SAAU,mBAAmB,CACjC,OAAY,EACZ,iBA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