@within-7/minto 0.1.6 → 0.1.7

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/tools/NotebookReadTool/NotebookReadTool.tsx"],
4
- "sourcesContent": ["import type {\n ImageBlockParam,\n TextBlockParam,\n} from '@anthropic-ai/sdk/resources/index.mjs'\n\nimport { existsSync, readFileSync } from 'fs'\nimport { Text } from 'ink'\nimport { extname, isAbsolute, relative, resolve } from 'path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool } from '@tool'\nimport {\n NotebookCellSource,\n NotebookContent,\n NotebookCell,\n NotebookOutputImage,\n NotebookCellSourceOutput,\n NotebookCellOutput,\n NotebookCellType,\n} from '@minto-types/notebook'\nimport { formatOutput } from '@tools/BashTool/utils'\nimport { getCwd } from '@utils/state'\nimport { findSimilarFile } from '@utils/file'\nimport { DESCRIPTION, PROMPT } from './prompt'\nimport { hasReadPermission } from '@utils/permissions/filesystem'\n\nconst inputSchema = z.strictObject({\n notebook_path: z\n .string()\n .describe(\n 'The absolute path to the Jupyter notebook file to read (must be absolute, not relative)',\n ),\n})\n\ntype In = typeof inputSchema\ntype Out = NotebookCellSource[]\n\nexport const NotebookReadTool = {\n name: 'ReadNotebook',\n async description() {\n return DESCRIPTION\n },\n async prompt() {\n return PROMPT\n },\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true // NotebookReadTool is read-only, safe for concurrent execution\n },\n inputSchema,\n userFacingName() {\n return 'Read Notebook'\n },\n async isEnabled() {\n return true\n },\n needsPermissions({ notebook_path }) {\n return !hasReadPermission(notebook_path)\n },\n async validateInput({ notebook_path }) {\n const fullFilePath = isAbsolute(notebook_path)\n ? notebook_path\n : resolve(getCwd(), notebook_path)\n\n if (!existsSync(fullFilePath)) {\n // Try to find a similar file with a different extension\n const similarFilename = findSimilarFile(fullFilePath)\n let message = 'File does not exist.'\n\n // If we found a similar file, suggest it to the assistant\n if (similarFilename) {\n message += ` Did you mean ${similarFilename}?`\n }\n\n return {\n result: false,\n message,\n }\n }\n\n if (extname(fullFilePath) !== '.ipynb') {\n return {\n result: false,\n message: 'File must be a Jupyter notebook (.ipynb file).',\n }\n }\n\n return { result: true }\n },\n renderToolUseMessage(input, { verbose }) {\n return `notebook_path: ${verbose ? input.notebook_path : relative(getCwd(), input.notebook_path)}`\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n\n renderToolResultMessage(content) {\n if (!content) {\n return <Text>No cells found in notebook</Text>\n }\n if (content.length < 1 || !content[0]) {\n return <Text>No cells found in notebook</Text>\n }\n return <Text>Read {content.length} cells</Text>\n },\n async *call({ notebook_path }) {\n const fullPath = isAbsolute(notebook_path)\n ? notebook_path\n : resolve(getCwd(), notebook_path)\n\n const content = readFileSync(fullPath, 'utf-8')\n const notebook = JSON.parse(content) as NotebookContent\n const language = notebook.metadata.language_info?.name ?? 'python'\n const cells = notebook.cells.map((cell, index) =>\n processCell(cell, index, language),\n )\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(cells),\n data: cells,\n }\n },\n renderResultForAssistant(data: NotebookCellSource[]) {\n // Convert the complex structure to a string representation for the assistant\n return data\n .map((cell, index) => {\n let content = `Cell ${index + 1} (${cell.cellType}):\\n${cell.source}`\n if (cell.outputs && cell.outputs.length > 0) {\n const outputText = cell.outputs\n .map(output => output.text)\n .filter(Boolean)\n .join('\\n')\n if (outputText) {\n content += `\\nOutput:\\n${outputText}`\n }\n }\n return content\n })\n .join('\\n\\n')\n },\n} satisfies Tool<In, Out>\n\nfunction processOutputText(text: string | string[] | undefined): string {\n if (!text) return ''\n const rawText = Array.isArray(text) ? text.join('') : text\n const { truncatedContent } = formatOutput(rawText)\n return truncatedContent\n}\n\nfunction extractImage(\n data: Record<string, unknown>,\n): NotebookOutputImage | undefined {\n if (typeof data['image/png'] === 'string') {\n return {\n image_data: data['image/png'] as string,\n media_type: 'image/png',\n }\n }\n if (typeof data['image/jpeg'] === 'string') {\n return {\n image_data: data['image/jpeg'] as string,\n media_type: 'image/jpeg',\n }\n }\n return undefined\n}\n\nfunction processOutput(output: NotebookCellOutput) {\n switch (output.output_type) {\n case 'stream':\n return {\n output_type: output.output_type,\n text: processOutputText(output.text),\n }\n case 'execute_result':\n case 'display_data':\n return {\n output_type: output.output_type,\n text: processOutputText(\n output.data?.['text/plain'] as string | string[] | undefined,\n ),\n image: output.data && extractImage(output.data),\n }\n case 'error':\n return {\n output_type: output.output_type,\n text: processOutputText(\n `${output.ename}: ${output.evalue}\\n${output.traceback.join('\\n')}`,\n ),\n }\n }\n}\n\nfunction processCell(\n cell: NotebookCell,\n index: number,\n language: string,\n): NotebookCellSource {\n const cellData: NotebookCellSource = {\n cell: index,\n cellType: cell.cell_type,\n source: Array.isArray(cell.source) ? cell.source.join('') : cell.source,\n language,\n execution_count: cell.execution_count,\n }\n\n if (cell.outputs?.length) {\n cellData.outputs = cell.outputs.map(processOutput)\n }\n\n return cellData\n}\n\nfunction cellContentToToolResult(cell: NotebookCellSource): TextBlockParam {\n const metadata = []\n if (cell.cellType !== 'code') {\n metadata.push(`<cell_type>${cell.cellType}</cell_type>`)\n }\n if (cell.language !== 'python' && cell.cellType === 'code') {\n metadata.push(`<language>${cell.language}</language>`)\n }\n const cellContent = `<cell ${cell.cell}>${metadata.join('')}${cell.source}</cell ${cell.cell}>`\n return {\n text: cellContent,\n type: 'text',\n }\n}\n\nfunction cellOutputToToolResult(output: NotebookCellSourceOutput) {\n const outputs: (TextBlockParam | ImageBlockParam)[] = []\n if (output.text) {\n outputs.push({\n text: `\\n${output.text}`,\n type: 'text',\n })\n }\n if (output.image) {\n outputs.push({\n type: 'image',\n source: {\n data: output.image.image_data,\n media_type: output.image.media_type,\n type: 'base64',\n },\n })\n }\n return outputs\n}\n\nfunction getToolResultFromCell(cell: NotebookCellSource) {\n const contentResult = cellContentToToolResult(cell)\n const outputResults = cell.outputs?.flatMap(cellOutputToToolResult)\n return [contentResult, ...(outputResults ?? [])]\n}\n\nexport function isNotebookCellType(\n value: string | null,\n): value is NotebookCellType {\n return value === 'code' || value === 'markdown'\n}\n"],
5
- "mappings": "AAKA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AACrB,SAAS,SAAS,YAAY,UAAU,eAAe;AACvD,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAW/C,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAChC,SAAS,aAAa,cAAc;AACpC,SAAS,yBAAyB;AAElC,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,eAAe,EACZ,OAAO,EACP;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAKM,MAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,MAAM,SAAS;AACb,WAAO;AAAA,EACT;AAAA,EACA,aAAa;AACX,WAAO;AAAA,EACT;AAAA,EACA,oBAAoB;AAClB,WAAO;AAAA,EACT;AAAA,EACA;AAAA,EACA,iBAAiB;AACf,WAAO;AAAA,EACT;AAAA,EACA,MAAM,YAAY;AAChB,WAAO;AAAA,EACT;AAAA,EACA,iBAAiB,EAAE,cAAc,GAAG;AAClC,WAAO,CAAC,kBAAkB,aAAa;AAAA,EACzC;AAAA,EACA,MAAM,cAAc,EAAE,cAAc,GAAG;AACrC,UAAM,eAAe,WAAW,aAAa,IACzC,gBACA,QAAQ,OAAO,GAAG,aAAa;AAEnC,QAAI,CAAC,WAAW,YAAY,GAAG;AAE7B,YAAM,kBAAkB,gBAAgB,YAAY;AACpD,UAAI,UAAU;AAGd,UAAI,iBAAiB;AACnB,mBAAW,iBAAiB,eAAe;AAAA,MAC7C;AAEA,aAAO;AAAA,QACL,QAAQ;AAAA,QAC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AI;AAClD,QAAM,gBAAgB,KAAK,SAAS,QAAQ,sBAAsB;AAClE,SAAO,CAAC,eAAe,GAAI,iBAAiB,CAAC,CAAE;AACjD;AAEO,SAAS,mBACd,OAC2B;AAC3B,SAAO,UAAU,UAAU,UAAU;AACvC;",
4
+ "sourcesContent": ["import type {\n ImageBlockParam,\n TextBlockParam,\n} from '@anthropic-ai/sdk/resources/index.mjs'\n\nimport { existsSync, readFileSync } from 'fs'\nimport { Text } from 'ink'\nimport { extname, isAbsolute, relative, resolve } from 'path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool } from '@tool'\nimport {\n NotebookCellSource,\n NotebookContent,\n NotebookCell,\n NotebookOutputImage,\n NotebookCellSourceOutput,\n NotebookCellOutput,\n NotebookCellType,\n} from '@minto-types/notebook'\nimport { formatOutput } from '@tools/BashTool/utils'\nimport { getCwd } from '@utils/state'\nimport { findSimilarFile } from '@utils/file'\nimport { DESCRIPTION, PROMPT } from './prompt'\nimport { hasReadPermission } from '@utils/permissions/filesystem'\n\nconst inputSchema = z.strictObject({\n notebook_path: z\n .string()\n .describe(\n 'The absolute path to the Jupyter notebook file to read (must be absolute, not relative)',\n ),\n})\n\ntype In = typeof inputSchema\ntype Out = NotebookCellSource[]\n\nexport const NotebookReadTool = {\n name: 'ReadNotebook',\n async description() {\n return DESCRIPTION\n },\n async prompt() {\n return PROMPT\n },\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true // NotebookReadTool is read-only, safe for concurrent execution\n },\n inputSchema,\n userFacingName() {\n return 'Read Notebook'\n },\n async isEnabled() {\n return true\n },\n needsPermissions({ notebook_path }) {\n return !hasReadPermission(notebook_path)\n },\n async validateInput({ notebook_path }) {\n const fullFilePath = isAbsolute(notebook_path)\n ? notebook_path\n : resolve(getCwd(), notebook_path)\n\n if (!existsSync(fullFilePath)) {\n // Try to find a similar file with a different extension\n const similarFilename = findSimilarFile(fullFilePath)\n let message = 'File does not exist.'\n\n // If we found a similar file, suggest it to the assistant\n if (similarFilename) {\n message += ` Did you mean ${similarFilename}?`\n }\n\n return {\n result: false,\n message,\n }\n }\n\n if (extname(fullFilePath) !== '.ipynb') {\n return {\n result: false,\n message: 'File must be a Jupyter notebook (.ipynb file).',\n }\n }\n\n return { result: true }\n },\n renderToolUseMessage(input, { verbose }) {\n return `notebook_path: ${verbose ? input.notebook_path : relative(getCwd(), input.notebook_path)}`\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n\n renderToolResultMessage(content) {\n if (!content) {\n return <Text>No cells found in notebook</Text>\n }\n if (content.length < 1 || !content[0]) {\n return <Text>No cells found in notebook</Text>\n }\n return <Text>Read {content.length} cells</Text>\n },\n async *call({ notebook_path }) {\n const fullPath = isAbsolute(notebook_path)\n ? notebook_path\n : resolve(getCwd(), notebook_path)\n\n const content = readFileSync(fullPath, 'utf-8')\n const notebook = JSON.parse(content) as NotebookContent\n const language = notebook.metadata.language_info?.name ?? 'python'\n const cells = notebook.cells.map((cell, index) =>\n processCell(cell, index, language),\n )\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(cells),\n data: cells,\n }\n },\n renderResultForAssistant(data: NotebookCellSource[]) {\n // Guard against undefined or null data\n if (!data || !Array.isArray(data)) {\n return 'No cells found in notebook'\n }\n\n // Convert the complex structure to a string representation for the assistant\n return data\n .map((cell, index) => {\n if (!cell) return `Cell ${index + 1}: (empty)`\n let content = `Cell ${index + 1} (${cell.cellType || 'unknown'}):\\n${cell.source || ''}`\n if (cell.outputs && Array.isArray(cell.outputs) && cell.outputs.length > 0) {\n const outputText = cell.outputs\n .filter(output => output != null)\n .map(output => output.text || '')\n .filter(Boolean)\n .join('\\n')\n if (outputText) {\n content += `\\nOutput:\\n${outputText}`\n }\n }\n return content\n })\n .join('\\n\\n')\n },\n} satisfies Tool<In, Out>\n\nfunction processOutputText(text: string | string[] | undefined): string {\n if (!text) return ''\n const rawText = Array.isArray(text) ? text.join('') : text\n const { truncatedContent } = formatOutput(rawText)\n return truncatedContent\n}\n\nfunction extractImage(\n data: Record<string, unknown>,\n): NotebookOutputImage | undefined {\n if (typeof data['image/png'] === 'string') {\n return {\n image_data: data['image/png'] as string,\n media_type: 'image/png',\n }\n }\n if (typeof data['image/jpeg'] === 'string') {\n return {\n image_data: data['image/jpeg'] as string,\n media_type: 'image/jpeg',\n }\n }\n return undefined\n}\n\nfunction processOutput(output: NotebookCellOutput) {\n switch (output.output_type) {\n case 'stream':\n return {\n output_type: output.output_type,\n text: processOutputText(output.text),\n }\n case 'execute_result':\n case 'display_data':\n return {\n output_type: output.output_type,\n text: processOutputText(\n output.data?.['text/plain'] as string | string[] | undefined,\n ),\n image: output.data && extractImage(output.data),\n }\n case 'error':\n return {\n output_type: output.output_type,\n text: processOutputText(\n `${output.ename}: ${output.evalue}\\n${output.traceback.join('\\n')}`,\n ),\n }\n }\n}\n\nfunction processCell(\n cell: NotebookCell,\n index: number,\n language: string,\n): NotebookCellSource {\n const cellData: NotebookCellSource = {\n cell: index,\n cellType: cell.cell_type,\n source: Array.isArray(cell.source) ? cell.source.join('') : cell.source,\n language,\n execution_count: cell.execution_count,\n }\n\n if (cell.outputs?.length) {\n cellData.outputs = cell.outputs.map(processOutput)\n }\n\n return cellData\n}\n\nfunction cellContentToToolResult(cell: NotebookCellSource): TextBlockParam {\n const metadata = []\n if (cell.cellType !== 'code') {\n metadata.push(`<cell_type>${cell.cellType}</cell_type>`)\n }\n if (cell.language !== 'python' && cell.cellType === 'code') {\n metadata.push(`<language>${cell.language}</language>`)\n }\n const cellContent = `<cell ${cell.cell}>${metadata.join('')}${cell.source}</cell ${cell.cell}>`\n return {\n text: cellContent,\n type: 'text',\n }\n}\n\nfunction cellOutputToToolResult(output: NotebookCellSourceOutput) {\n const outputs: (TextBlockParam | ImageBlockParam)[] = []\n if (output.text) {\n outputs.push({\n text: `\\n${output.text}`,\n type: 'text',\n })\n }\n if (output.image) {\n outputs.push({\n type: 'image',\n source: {\n data: output.image.image_data,\n media_type: output.image.media_type,\n type: 'base64',\n },\n })\n }\n return outputs\n}\n\nfunction getToolResultFromCell(cell: NotebookCellSource) {\n const contentResult = cellContentToToolResult(cell)\n const outputResults = cell.outputs?.flatMap(cellOutputToToolResult)\n return [contentResult, ...(outputResults ?? [])]\n}\n\nexport function isNotebookCellType(\n value: string | null,\n): value is NotebookCellType {\n return value === 'code' || value === 'markdown'\n}\n"],
5
+ "mappings": "AAKA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AACrB,SAAS,SAAS,YAAY,UAAU,eAAe;AACvD,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAW/C,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAChC,SAAS,aAAa,cAAc;AACpC,SAAS,yBAAyB;AAElC,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,eAAe,EACZ,OAAO,EACP;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAKM,MAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,MAAM,SAAS;AACb,WAAO;AAAA,EACT;AAAA,EACA,aAAa;AACX,WAAO;AAAA,EACT;AAAA,EACA,oBAAoB;AAClB,WAAO;AAAA,EACT;AAAA,EACA;AAAA,EACA,iBAAiB;AACf,WAAO;AAAA,EACT;AAAA,EACA,MAAM,YAAY;AAChB,WAAO;AAAA,EACT;AAAA,EACA,iBAAiB,EAAE,cAAc,GAAG;AAClC,WAAO,CAAC,kBAAkB,aAAa;AAAA,EACzC;AAAA,EACA,MAAM,cAAc,EAAE,cAAc,GAAG;AACrC,UAAM,eAAe,WAAW,aAAa,IACzC,gBACA,QAAQ,OAAO,GAAG,aAAa;AAEnC,QAAI,CAAC,WAAW,YAAY,GAAG;AAE7B,YAAM,kBAAkB,gBAAgB,YAAY;AACpD,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AAO,IAAI;AAAA,MACtB,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AACA,MAAI,OAAO,OAAO;AAChB,YAAQ,KAAK;AAAA,MACX,MAAM;AAAA,MACN,QAAQ;AAAA,QACN,MAAM,OAAO,MAAM;AAAA,QACnB,YAAY,OAAO,MAAM;AAAA,QACzB,MAAM;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEA,SAAS,sBAAsB,MAA0B;AACvD,QAAM,gBAAgB,wBAAwB,IAAI;AAClD,QAAM,gBAAgB,KAAK,SAAS,QAAQ,sBAAsB;AAClE,SAAO,CAAC,eAAe,GAAI,iBAAiB,CAAC,CAAE;AACjD;AAEO,SAAS,mBACd,OAC2B;AAC3B,SAAO,UAAU,UAAU,UAAU;AACvC;",
6
6
  "names": []
7
7
  }
@@ -101,14 +101,20 @@ ${skill.content}
101
101
  return /* @__PURE__ */ React.createElement(FallbackToolUseRejectedMessage, null);
102
102
  },
103
103
  renderToolResultMessage(output) {
104
+ if (!output || !output.type) {
105
+ return /* @__PURE__ */ React.createElement(Box, { paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, null, "Skill operation completed"));
106
+ }
104
107
  if (output.type === "list") {
105
- return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { color: "green" }, "\u2713 Found ", output.skills.length, " skill", output.skills.length !== 1 ? "s" : ""), output.skills.slice(0, 10).map((skill, i) => /* @__PURE__ */ React.createElement(Box, { key: i, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, skill.name), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " (", skill.plugin, ")")), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ", skill.description))), output.skills.length > 10 && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ... and ", output.skills.length - 10, " more"));
108
+ const skills = output.skills || [];
109
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { color: "green" }, "\u2713 Found ", skills.length, " skill", skills.length !== 1 ? "s" : ""), skills.slice(0, 10).map((skill, i) => /* @__PURE__ */ React.createElement(Box, { key: i, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, skill?.name || "Unknown"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " (", skill?.plugin || "Unknown", ")")), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ", skill?.description || ""))), skills.length > 10 && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ... and ", skills.length - 10, " more"));
106
110
  }
107
111
  if (output.type === "search") {
108
- return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { color: "green" }, "\u2713 Found ", output.skills.length, " skill", output.skills.length !== 1 ? "s" : "", ' matching "', output.query, '"'), output.skills.slice(0, 10).map((skill, i) => /* @__PURE__ */ React.createElement(Box, { key: i, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, skill.name), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " (", skill.plugin, ")")), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ", skill.description))), output.skills.length > 10 && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ... and ", output.skills.length - 10, " more"));
112
+ const skills = output.skills || [];
113
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { color: "green" }, "\u2713 Found ", skills.length, " skill", skills.length !== 1 ? "s" : "", ' matching "', output.query || "", '"'), skills.slice(0, 10).map((skill, i) => /* @__PURE__ */ React.createElement(Box, { key: i, flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, null, /* @__PURE__ */ React.createElement(Text, { bold: true }, skill?.name || "Unknown"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " (", skill?.plugin || "Unknown", ")")), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ", skill?.description || ""))), skills.length > 10 && /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ... and ", skills.length - 10, " more"));
109
114
  }
110
115
  if (output.type === "load") {
111
- return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { color: "green" }, "\u2713 Loaded skill: ", output.skill.name), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " Plugin: ", output.skill.plugin), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ", "Content: ", output.skill.content.length, " characters"));
116
+ const skill = output.skill || { name: "", description: "", plugin: "", content: "" };
117
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { color: "green" }, "\u2713 Loaded skill: ", skill.name || "Unknown"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " Plugin: ", skill.plugin || "Unknown"), /* @__PURE__ */ React.createElement(Text, { dimColor: true }, " ", "Content: ", (skill.content || "").length, " characters"));
112
118
  }
113
119
  return /* @__PURE__ */ React.createElement(Box, { paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, null, "Skill operation completed"));
114
120
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/tools/SkillTool/SkillTool.tsx"],
4
- "sourcesContent": ["import { Box, Text } from 'ink'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool } from '@tool'\nimport {\n loadAllSkills,\n getSkill,\n loadSkillContent,\n searchSkills,\n getSkillCount,\n} from '@utils/skillLoader'\nimport { DESCRIPTION, PROMPT } from './prompt'\n\nconst inputSchema = z.strictObject({\n action: z\n .enum(['list', 'load', 'search'])\n .describe(\n 'Action to perform: list all skills, load a specific skill, or search skills',\n ),\n name: z\n .string()\n .optional()\n .describe('Name of skill to load (required for \"load\" action)'),\n query: z\n .string()\n .optional()\n .describe('Search query (required for \"search\" action)'),\n})\n\ntype SkillToolOutput =\n | {\n type: 'list'\n skills: Array<{ name: string; description: string; plugin: string }>\n }\n | {\n type: 'load'\n skill: {\n name: string\n description: string\n plugin: string\n content: string\n }\n }\n | {\n type: 'search'\n skills: Array<{ name: string; description: string; plugin: string }>\n query: string\n }\n\nexport const SkillTool = {\n name: 'Skill',\n async description() {\n return DESCRIPTION\n },\n async prompt() {\n return PROMPT\n },\n inputSchema,\n userFacingName() {\n return 'Skill'\n },\n async isEnabled() {\n // Enable if there are any skills available\n return getSkillCount() > 0\n },\n isReadOnly() {\n return true // Skills are read-only resources\n },\n isConcurrencySafe() {\n return true // Reading skills is safe for concurrent execution\n },\n needsPermissions() {\n return false // No permissions needed for reading skills\n },\n renderResultForAssistant(output: SkillToolOutput) {\n if (output.type === 'list') {\n if (output.skills.length === 0) {\n return 'No skills available. Install plugins with skills to use this feature.'\n }\n\n const skillsList = output.skills\n .map(\n skill =>\n `- **${skill.name}** (${skill.plugin}): ${skill.description}`,\n )\n .join('\\n')\n\n return `Available skills (${output.skills.length}):\\n\\n${skillsList}\\n\\nUse the \"load\" action to get full skill content.`\n }\n\n if (output.type === 'search') {\n if (output.skills.length === 0) {\n return `No skills found matching \"${output.query}\".`\n }\n\n const skillsList = output.skills\n .map(\n skill =>\n `- **${skill.name}** (${skill.plugin}): ${skill.description}`,\n )\n .join('\\n')\n\n return `Skills matching \"${output.query}\" (${output.skills.length}):\\n\\n${skillsList}\\n\\nUse the \"load\" action to get full skill content.`\n }\n\n if (output.type === 'load') {\n const { skill } = output\n return `# Skill: ${skill.name}\n\n**Plugin**: ${skill.plugin}\n**Description**: ${skill.description}\n\n---\n\n${skill.content}\n\n---\n\n*End of skill content. Apply these instructions to complete your task.*`\n }\n\n return 'Unknown skill operation'\n },\n renderToolUseMessage(input, { verbose }) {\n if (input.action === 'list') {\n return 'Listing all available skills'\n }\n if (input.action === 'load' && input.name) {\n return `Loading skill: ${input.name}`\n }\n if (input.action === 'search' && input.query) {\n return `Searching skills for: ${input.query}`\n }\n return Object.entries(input)\n .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)\n .join(', ')\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(output: SkillToolOutput) {\n if (output.type === 'list') {\n return (\n <Box flexDirection=\"column\" paddingLeft={2}>\n <Text color=\"green\">\n \u2713 Found {output.skills.length} skill\n {output.skills.length !== 1 ? 's' : ''}\n </Text>\n {output.skills.slice(0, 10).map((skill, i) => (\n <Box key={i} flexDirection=\"column\">\n <Text>\n <Text bold>{skill.name}</Text>\n <Text dimColor> ({skill.plugin})</Text>\n </Text>\n <Text dimColor> {skill.description}</Text>\n </Box>\n ))}\n {output.skills.length > 10 && (\n <Text dimColor> ... and {output.skills.length - 10} more</Text>\n )}\n </Box>\n )\n }\n\n if (output.type === 'search') {\n return (\n <Box flexDirection=\"column\" paddingLeft={2}>\n <Text color=\"green\">\n \u2713 Found {output.skills.length} skill\n {output.skills.length !== 1 ? 's' : ''} matching &quot;\n {output.query}&quot;\n </Text>\n {output.skills.slice(0, 10).map((skill, i) => (\n <Box key={i} flexDirection=\"column\">\n <Text>\n <Text bold>{skill.name}</Text>\n <Text dimColor> ({skill.plugin})</Text>\n </Text>\n <Text dimColor> {skill.description}</Text>\n </Box>\n ))}\n {output.skills.length > 10 && (\n <Text dimColor> ... and {output.skills.length - 10} more</Text>\n )}\n </Box>\n )\n }\n\n if (output.type === 'load') {\n return (\n <Box flexDirection=\"column\" paddingLeft={2}>\n <Text color=\"green\">\u2713 Loaded skill: {output.skill.name}</Text>\n <Text dimColor> Plugin: {output.skill.plugin}</Text>\n <Text dimColor>\n {' '}\n Content: {output.skill.content.length} characters\n </Text>\n </Box>\n )\n }\n\n return (\n <Box paddingLeft={2}>\n <Text>Skill operation completed</Text>\n </Box>\n )\n },\n async validateInput(input) {\n if (input.action === 'load') {\n if (!input.name) {\n return {\n result: false,\n message: 'Skill name is required for \"load\" action',\n }\n }\n\n const skill = getSkill(input.name)\n if (!skill) {\n const allSkills = loadAllSkills()\n const availableNames = allSkills.map(s => s.name).join(', ')\n return {\n result: false,\n message: `Skill \"${input.name}\" not found. Available skills: ${availableNames}`,\n }\n }\n }\n\n if (input.action === 'search') {\n if (!input.query) {\n return {\n result: false,\n message: 'Query is required for \"search\" action',\n }\n }\n }\n\n return { result: true }\n },\n async *call(input) {\n try {\n // List all skills\n if (input.action === 'list') {\n const skills = loadAllSkills()\n const skillsList = skills.map(skill => ({\n name: skill.name,\n description: skill.config.description,\n plugin: skill.pluginName,\n }))\n\n const output: SkillToolOutput = {\n type: 'list',\n skills: skillsList,\n }\n\n yield {\n type: 'result',\n data: output,\n resultForAssistant: this.renderResultForAssistant(output),\n }\n return\n }\n\n // Load specific skill\n if (input.action === 'load' && input.name) {\n const skill = getSkill(input.name)\n if (!skill) {\n throw new Error(`Skill \"${input.name}\" not found`)\n }\n\n // Load full content\n const content = await loadSkillContent(skill)\n\n const output: SkillToolOutput = {\n type: 'load',\n skill: {\n name: skill.name,\n description: skill.config.description,\n plugin: skill.pluginName,\n content,\n },\n }\n\n yield {\n type: 'result',\n data: output,\n resultForAssistant: this.renderResultForAssistant(output),\n }\n return\n }\n\n // Search skills\n if (input.action === 'search' && input.query) {\n const skills = searchSkills(input.query)\n const skillsList = skills.map(skill => ({\n name: skill.name,\n description: skill.config.description,\n plugin: skill.pluginName,\n }))\n\n const output: SkillToolOutput = {\n type: 'search',\n skills: skillsList,\n query: input.query,\n }\n\n yield {\n type: 'result',\n data: output,\n resultForAssistant: this.renderResultForAssistant(output),\n }\n return\n }\n\n throw new Error('Invalid skill action or missing required parameters')\n } catch (error) {\n throw new Error(\n `Skill operation failed: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n },\n} satisfies Tool<typeof inputS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M,UAAU,MAAM,IAAI,aAAa;AAAA,QACnD;AAGA,cAAM,UAAU,MAAM,iBAAiB,KAAK;AAE5C,cAAM,SAA0B;AAAA,UAC9B,MAAM;AAAA,UACN,OAAO;AAAA,YACL,MAAM,MAAM;AAAA,YACZ,aAAa,MAAM,OAAO;AAAA,YAC1B,QAAQ,MAAM;AAAA,YACd;AAAA,UACF;AAAA,QACF;AAEA,cAAM;AAAA,UACJ,MAAM;AAAA,UACN,MAAM;AAAA,UACN,oBAAoB,KAAK,yBAAyB,MAAM;AAAA,QAC1D;AACA;AAAA,MACF;AAGA,UAAI,MAAM,WAAW,YAAY,MAAM,OAAO;AAC5C,cAAM,SAAS,aAAa,MAAM,KAAK;AACvC,cAAM,aAAa,OAAO,IAAI,YAAU;AAAA,UACtC,MAAM,MAAM;AAAA,UACZ,aAAa,MAAM,OAAO;AAAA,UAC1B,QAAQ,MAAM;AAAA,QAChB,EAAE;AAEF,cAAM,SAA0B;AAAA,UAC9B,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,OAAO,MAAM;AAAA,QACf;AAEA,cAAM;AAAA,UACJ,MAAM;AAAA,UACN,MAAM;AAAA,UACN,oBAAoB,KAAK,yBAAyB,MAAM;AAAA,QAC1D;AACA;AAAA,MACF;AAEA,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE,SAAS,OAAO;AACd,YAAM,IAAI;AAAA,QACR,2BAA2B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,MACnF;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { Box, Text } from 'ink'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool } from '@tool'\nimport {\n loadAllSkills,\n getSkill,\n loadSkillContent,\n searchSkills,\n getSkillCount,\n} from '@utils/skillLoader'\nimport { DESCRIPTION, PROMPT } from './prompt'\n\nconst inputSchema = z.strictObject({\n action: z\n .enum(['list', 'load', 'search'])\n .describe(\n 'Action to perform: list all skills, load a specific skill, or search skills',\n ),\n name: z\n .string()\n .optional()\n .describe('Name of skill to load (required for \"load\" action)'),\n query: z\n .string()\n .optional()\n .describe('Search query (required for \"search\" action)'),\n})\n\ntype SkillToolOutput =\n | {\n type: 'list'\n skills: Array<{ name: string; description: string; plugin: string }>\n }\n | {\n type: 'load'\n skill: {\n name: string\n description: string\n plugin: string\n content: string\n }\n }\n | {\n type: 'search'\n skills: Array<{ name: string; description: string; plugin: string }>\n query: string\n }\n\nexport const SkillTool = {\n name: 'Skill',\n async description() {\n return DESCRIPTION\n },\n async prompt() {\n return PROMPT\n },\n inputSchema,\n userFacingName() {\n return 'Skill'\n },\n async isEnabled() {\n // Enable if there are any skills available\n return getSkillCount() > 0\n },\n isReadOnly() {\n return true // Skills are read-only resources\n },\n isConcurrencySafe() {\n return true // Reading skills is safe for concurrent execution\n },\n needsPermissions() {\n return false // No permissions needed for reading skills\n },\n renderResultForAssistant(output: SkillToolOutput) {\n if (output.type === 'list') {\n if (output.skills.length === 0) {\n return 'No skills available. Install plugins with skills to use this feature.'\n }\n\n const skillsList = output.skills\n .map(\n skill =>\n `- **${skill.name}** (${skill.plugin}): ${skill.description}`,\n )\n .join('\\n')\n\n return `Available skills (${output.skills.length}):\\n\\n${skillsList}\\n\\nUse the \"load\" action to get full skill content.`\n }\n\n if (output.type === 'search') {\n if (output.skills.length === 0) {\n return `No skills found matching \"${output.query}\".`\n }\n\n const skillsList = output.skills\n .map(\n skill =>\n `- **${skill.name}** (${skill.plugin}): ${skill.description}`,\n )\n .join('\\n')\n\n return `Skills matching \"${output.query}\" (${output.skills.length}):\\n\\n${skillsList}\\n\\nUse the \"load\" action to get full skill content.`\n }\n\n if (output.type === 'load') {\n const { skill } = output\n return `# Skill: ${skill.name}\n\n**Plugin**: ${skill.plugin}\n**Description**: ${skill.description}\n\n---\n\n${skill.content}\n\n---\n\n*End of skill content. Apply these instructions to complete your task.*`\n }\n\n return 'Unknown skill operation'\n },\n renderToolUseMessage(input, { verbose }) {\n if (input.action === 'list') {\n return 'Listing all available skills'\n }\n if (input.action === 'load' && input.name) {\n return `Loading skill: ${input.name}`\n }\n if (input.action === 'search' && input.query) {\n return `Searching skills for: ${input.query}`\n }\n return Object.entries(input)\n .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)\n .join(', ')\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(output: SkillToolOutput) {\n // Guard against undefined or null output\n if (!output || !output.type) {\n return (\n <Box paddingLeft={2}>\n <Text>Skill operation completed</Text>\n </Box>\n )\n }\n\n if (output.type === 'list') {\n const skills = output.skills || []\n return (\n <Box flexDirection=\"column\" paddingLeft={2}>\n <Text color=\"green\">\n \u2713 Found {skills.length} skill\n {skills.length !== 1 ? 's' : ''}\n </Text>\n {skills.slice(0, 10).map((skill, i) => (\n <Box key={i} flexDirection=\"column\">\n <Text>\n <Text bold>{skill?.name || 'Unknown'}</Text>\n <Text dimColor> ({skill?.plugin || 'Unknown'})</Text>\n </Text>\n <Text dimColor> {skill?.description || ''}</Text>\n </Box>\n ))}\n {skills.length > 10 && (\n <Text dimColor> ... and {skills.length - 10} more</Text>\n )}\n </Box>\n )\n }\n\n if (output.type === 'search') {\n const skills = output.skills || []\n return (\n <Box flexDirection=\"column\" paddingLeft={2}>\n <Text color=\"green\">\n \u2713 Found {skills.length} skill\n {skills.length !== 1 ? 's' : ''} matching &quot;\n {output.query || ''}&quot;\n </Text>\n {skills.slice(0, 10).map((skill, i) => (\n <Box key={i} flexDirection=\"column\">\n <Text>\n <Text bold>{skill?.name || 'Unknown'}</Text>\n <Text dimColor> ({skill?.plugin || 'Unknown'})</Text>\n </Text>\n <Text dimColor> {skill?.description || ''}</Text>\n </Box>\n ))}\n {skills.length > 10 && (\n <Text dimColor> ... and {skills.length - 10} more</Text>\n )}\n </Box>\n )\n }\n\n if (output.type === 'load') {\n const skill = output.skill || { name: '', description: '', plugin: '', content: '' }\n return (\n <Box flexDirection=\"column\" paddingLeft={2}>\n <Text color=\"green\">\u2713 Loaded skill: {skill.name || 'Unknown'}</Text>\n <Text dimColor> Plugin: {skill.plugin || 'Unknown'}</Text>\n <Text dimColor>\n {' '}\n Content: {(skill.content || '').length} characters\n </Text>\n </Box>\n )\n }\n\n return (\n <Box paddingLeft={2}>\n <Text>Skill operation completed</Text>\n </Box>\n )\n },\n async validateInput(input) {\n if (input.action === 'load') {\n if (!input.name) {\n return {\n result: false,\n message: 'Skill name is required for \"load\" action',\n }\n }\n\n const skill = getSkill(input.name)\n if (!skill) {\n const allSkills = loadAllSkills()\n const availableNames = allSkills.map(s => s.name).join(', ')\n return {\n result: false,\n message: `Skill \"${input.name}\" not found. Available skills: ${availableNames}`,\n }\n }\n }\n\n if (input.action === 'search') {\n if (!input.query) {\n return {\n result: false,\n message: 'Query is required for \"search\" action',\n }\n }\n }\n\n return { result: true }\n },\n async *call(input) {\n try {\n // List all skills\n if (input.action === 'list') {\n const skills = loadAllSkills()\n const skillsList = skills.map(skill => ({\n name: skill.name,\n description: skill.config.description,\n plugin: skill.pluginName,\n }))\n\n const output: SkillToolOutput = {\n type: 'list',\n skills: skillsList,\n }\n\n yield {\n type: 'result',\n data: output,\n resultForAssistant: this.renderResultForAssistant(output),\n }\n return\n }\n\n // Load specific skill\n if (input.action === 'load' && input.name) {\n const skill = getSkill(input.name)\n if (!skill) {\n throw new Error(`Skill \"${input.name}\" not found`)\n }\n\n // Load full content\n const content = await loadSkillContent(skill)\n\n const output: SkillToolOutput = {\n type: 'load',\n skill: {\n name: skill.name,\n description: skill.config.description,\n plugin: skill.pluginName,\n content,\n },\n }\n\n yield {\n type: 'result',\n data: output,\n resultForAssistant: this.renderResultForAssistant(output),\n }\n return\n }\n\n // Search skills\n if (input.action === 'search' && input.query) {\n const skills = searchSkills(input.query)\n const skillsList = skills.map(skill => ({\n name: skill.name,\n description: skill.config.description,\n plugin: skill.pluginName,\n }))\n\n const output: SkillToolOutput = {\n type: 'search',\n skills: skillsList,\n query: input.query,\n }\n\n yield {\n type: 'result',\n data: output,\n resultForAssistant: this.renderResultForAssistant(output),\n }\n return\n }\n\n throw new Error('Invalid skill action or missing required parameters')\n } catch (error) {\n throw new Error(\n `Skill operation failed: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n },\n} satisfies Tool<typeof inputSchema, SkillToolOutput>\n"],
5
+ "mappings": "AAAA,SAAS,KAAK,YAAY;AAC1B,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAE/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,cAAc;AAEpC,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,QAAQ,EACL,KAAK,CAAC,QAAQ,QAAQ,QAAQ,CAAC,EAC/B;AAAA,IACC;AAAA,EACF;AAAA,EACF,MAAM,EACH,OAAO,EACP,SAAS,EACT,SAAS,oDAAoD;AAAA,EAChE,OAAO,EACJ,OAAO,EACP,SAAS,EACT,SAAS,6CAA6C;AAC3D,CAAC;AAsBM,MAAM,YAAY;AAAA,EACvB,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,MAAM,SAAS;AACb,WAAO;AAAA,EACT;AAAA,EACA;AAAA,EACA,iBAAiB;AACf,WAAO;AAAA,EACT;AAAA,EACA,MAAM,YAAY;AAEhB,WAAO,cAAc,IAAI;AAAA,EAC3B;AAAA,EACA,aAAa;AACX,WAAO;AAAA,EACT;AAAA,EACA,oBAAoB;AAClB,WAAO;AAAA,EACT;AAAA,EACA,mBAAmB;AACjB,WAAO;AAAA,EACT;AAAA,EACA,yBAAyB,QAAyB;AAChD,QAAI,OAAO,SAAS,QAAQ;AAC1B,UAAI,OAAO,OAAO,WAAW,GAAG;AAC9B,eAAO;AAAA,MACT;AAEA,YAAM,aAAa,OAAO,OACvB;AAAA,QACC,WACE,OAAO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AAK,yBAAyB,MAAM;AAAA,QAC1D;AACA;AAAA,MACF;AAEA,YAAM,IAAI,MAAM,qDAAqD;AAAA,IACvE,SAAS,OAAO;AACd,YAAM,IAAI;AAAA,QACR,2BAA2B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,MACnF;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -336,53 +336,30 @@ IMPORTANT: You are currently running as ${modelToUse}. You do not need to consul
336
336
  },
337
337
  renderToolUseRejectedMessage() {
338
338
  return /* @__PURE__ */ React.createElement(FallbackToolUseRejectedMessage, null);
339
+ },
340
+ renderToolResultMessage(content) {
341
+ const theme = getTheme();
342
+ if (!content) {
343
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "Task completed"));
344
+ }
345
+ if (Array.isArray(content)) {
346
+ const textBlocks = content.filter(
347
+ (block) => block && block.type === "text"
348
+ );
349
+ const totalLength = textBlocks.reduce(
350
+ (sum, block) => sum + (block.text?.length || 0),
351
+ 0
352
+ );
353
+ const isInterrupted = content.some(
354
+ (block) => block && block.type === "text" && block.text === INTERRUPT_MESSAGE
355
+ );
356
+ if (isInterrupted) {
357
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React.createElement(Text, { color: theme.error }, "Interrupted by user"));
358
+ }
359
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Box, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React.createElement(Text, null, "Task completed"), textBlocks.length > 0 && /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, " ", "(", totalLength, " characters)"))));
360
+ }
361
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, "Task completed"));
339
362
  }
340
- // renderToolResultMessage(content) {
341
- // const theme = getTheme()
342
- // if (Array.isArray(content)) {
343
- // const textBlocks = content.filter(block => block.type === 'text')
344
- // const totalLength = textBlocks.reduce(
345
- // (sum, block) => sum + block.text.length,
346
- // 0,
347
- // )
348
- // // 🔧 CRITICAL FIX: Use exact match for interrupt detection, not .includes()
349
- // const isInterrupted = content.some(
350
- // block =>
351
- // block.type === 'text' && block.text === INTERRUPT_MESSAGE,
352
- // )
353
- // if (isInterrupted) {
354
- // // 🔧 CRITICAL FIX: Match original system interrupt rendering exactly
355
- // return (
356
- // <Box flexDirection="row">
357
- // <Text>&nbsp;&nbsp;⎿ &nbsp;</Text>
358
- // <Text color={theme.error}>Interrupted by user</Text>
359
- // </Box>
360
- // )
361
- // }
362
- // return (
363
- // <Box flexDirection="column">
364
- // <Box justifyContent="space-between" width="100%">
365
- // <Box flexDirection="row">
366
- // <Text>&nbsp;&nbsp;⎿ &nbsp;</Text>
367
- // <Text>Task completed</Text>
368
- // {textBlocks.length > 0 && (
369
- // <Text color={theme.secondaryText}>
370
- // {' '}
371
- // ({totalLength} characters)
372
- // </Text>
373
- // )}
374
- // </Box>
375
- // </Box>
376
- // </Box>
377
- // )
378
- // }
379
- // return (
380
- // <Box flexDirection="row">
381
- // <Text>&nbsp;&nbsp;⎿ &nbsp;</Text>
382
- // <Text color={theme.secondaryText}>Task completed</Text>
383
- // </Box>
384
- // )
385
- // },
386
363
  };
387
364
  export {
388
365
  TaskTool
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/tools/TaskTool/TaskTool.tsx"],
4
- "sourcesContent": ["import { TextBlock } from '@anthropic-ai/sdk/resources/index.mjs'\nimport chalk from 'chalk'\nimport { last, memoize } from 'lodash-es'\nimport { EOL } from 'os'\nimport React, { useState, useEffect } from 'react'\nimport { Box, Text } from 'ink'\nimport { z } from 'zod'\nimport { Tool, ValidationResult } from '@tool'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { getAgentPrompt } from '@constants/prompts'\nimport { getContext } from '@context'\nimport { hasPermissionsToUseTool } from '@permissions'\nimport { AssistantMessage, Message as MessageType, query } from '@query'\nimport { formatDuration, formatNumber } from '@utils/format'\nimport {\n getMessagesPath,\n getNextAvailableLogSidechainNumber,\n overwriteLog,\n} from '@utils/log'\nimport { applyMarkdown } from '@utils/markdown'\nimport {\n createAssistantMessage,\n createUserMessage,\n getLastAssistantMessageId,\n INTERRUPT_MESSAGE,\n normalizeMessages,\n} from '@utils/messages'\nimport { getModelManager } from '@utils/model'\nimport { getMaxThinkingTokens } from '@utils/thinking'\nimport { getTheme } from '@utils/theme'\nimport { generateAgentId } from '@utils/agentStorage'\nimport { debug as debugLogger } from '@utils/debugLogger'\nimport { getTaskTools, getPrompt } from './prompt'\nimport { TOOL_NAME } from './constants'\nimport {\n getActiveAgents,\n getAgentByType,\n getAvailableAgentTypes,\n} from '@utils/agentLoader'\n\nconst inputSchema = z.object({\n description: z\n .string()\n .describe('A short (3-5 word) description of the task'),\n prompt: z.string().describe('The task for the agent to perform'),\n model_name: z\n .string()\n .optional()\n .describe(\n 'Optional: Specific model name to use for this task. If not provided, uses the default task model pointer.',\n ),\n subagent_type: z\n .string()\n .optional()\n .describe(\n 'The specialized agent type (MUST use hyphens, e.g., \"strategic-market-analyzer\"). For research/analysis use \"strategic-market-analyzer\" or \"business-analyst\", for data use \"data-scientist\", for general use \"general-purpose\". NEVER use underscores or invent names like \"researcher\".',\n ),\n})\n\nexport const TaskTool = {\n async prompt({ safeMode }) {\n // Ensure agent prompts remain compatible with Claude Code `.claude` agent packs\n return await getPrompt(safeMode)\n },\n name: TOOL_NAME,\n async description() {\n // Ensure metadata stays compatible with Claude Code `.claude` agent packs\n const availableTypes = await getAvailableAgentTypes()\n const typesList =\n availableTypes.slice(0, 10).join(', ') +\n (availableTypes.length > 10 ? '...' : '')\n return `Launch a specialized agent to handle tasks autonomously. CRITICAL: Use exact agent type names with hyphens (e.g., \"strategic-market-analyzer\", NOT \"researcher\" or \"market_analyzer\"). Available: ${typesList}`\n },\n inputSchema,\n\n async *call(\n { description, prompt, model_name, subagent_type },\n {\n abortController,\n options: { safeMode = false, forkNumber, messageLogName, verbose },\n readFileTimestamps,\n },\n ): AsyncGenerator<\n | { type: 'result'; data: TextBlock[]; resultForAssistant?: string }\n | {\n type: 'progress'\n content: any\n normalizedMessages?: any[]\n tools?: any[]\n },\n void,\n unknown\n > {\n const startTime = Date.now()\n\n // Default to general-purpose if no subagent_type specified\n const agentType = subagent_type || 'general-purpose'\n\n // Apply subagent configuration\n let effectivePrompt = prompt\n let effectiveModel = model_name || 'task'\n let toolFilter = null\n let temperature = undefined\n\n // Load agent configuration dynamically\n if (agentType) {\n const agentConfig = await getAgentByType(agentType)\n\n if (!agentConfig) {\n // If agent type not found, return helpful message instead of throwing\n const availableTypes = await getAvailableAgentTypes()\n const helpMessage = `Agent type '${agentType}' not found.\\n\\nAvailable agents:\\n${availableTypes.map(t => ` \u2022 ${t}`).join('\\n')}\\n\\nUse /agents command to manage agent configurations.`\n\n yield {\n type: 'result',\n data: [{ type: 'text', text: helpMessage }] as TextBlock[],\n resultForAssistant: helpMessage,\n }\n return\n }\n\n // Apply system prompt if configured\n if (agentConfig.systemPrompt) {\n effectivePrompt = `${agentConfig.systemPrompt}\\n\\n${prompt}`\n }\n\n // Apply model if not overridden by model_name parameter\n if (!model_name && agentConfig.model_name) {\n // Support inherit: keep pointer-based default\n if (agentConfig.model_name !== 'inherit') {\n effectiveModel = agentConfig.model_name as string\n }\n }\n\n // Store tool filter for later application\n toolFilter = agentConfig.tools\n\n // Note: temperature is not currently in our agent configs\n // but could be added in the future\n }\n\n const messages: MessageType[] = [createUserMessage(effectivePrompt)]\n let tools = await getTaskTools(safeMode)\n\n // Apply tool filtering if specified by subagent config\n if (toolFilter) {\n // Back-compat: ['*'] means all tools\n const isAllArray =\n Array.isArray(toolFilter) &&\n toolFilter.length === 1 &&\n toolFilter[0] === '*'\n if (toolFilter === '*' || isAllArray) {\n // no-op, keep all tools\n } else if (Array.isArray(toolFilter)) {\n tools = tools.filter(tool => toolFilter.includes(tool.name))\n }\n }\n\n // Model already resolved in effectiveModel variable above\n const modelToUse = effectiveModel\n\n // Display initial task information with separate progress lines\n yield {\n type: 'progress',\n content: createAssistantMessage(`Starting agent: ${agentType}`),\n normalizedMessages: normalizeMessages(messages),\n tools,\n }\n\n yield {\n type: 'progress',\n content: createAssistantMessage(`Using model: ${modelToUse}`),\n normalizedMessages: normalizeMessages(messages),\n tools,\n }\n\n yield {\n type: 'progress',\n content: createAssistantMessage(`Task: ${description}`),\n normalizedMessages: normalizeMessages(messages),\n tools,\n }\n\n yield {\n type: 'progress',\n content: createAssistantMessage(\n `Prompt: ${prompt.length > 150 ? prompt.substring(0, 150) + '...' : prompt}`,\n ),\n normalizedMessages: normalizeMessages(messages),\n tools,\n }\n\n const [taskPrompt, context, maxThinkingTokens] = await Promise.all([\n getAgentPrompt(),\n getContext(),\n getMaxThinkingTokens(messages),\n ])\n\n // Inject model context to prevent self-referential expert consultations\n taskPrompt.push(\n `\\nIMPORTANT: You are currently running as ${modelToUse}. You do not need to consult ${modelToUse} via AskExpertModel since you ARE ${modelToUse}. Complete tasks directly using your capabilities.`,\n )\n\n let toolUseCount = 0\n\n const getSidechainNumber = memoize(() =>\n getNextAvailableLogSidechainNumber(messageLogName, forkNumber),\n )\n\n // Generate unique Task ID for this task execution\n const taskId = generateAgentId()\n\n // \uD83D\uDD27 ULTRA SIMPLIFIED: Exact original AgentTool pattern\n // Build query options, adding temperature if specified\n const queryOptions = {\n safeMode,\n forkNumber,\n messageLogName,\n tools,\n commands: [],\n verbose,\n maxThinkingTokens,\n model: modelToUse,\n }\n\n // Add temperature if specified by subagent config\n if (temperature !== undefined) {\n queryOptions['temperature'] = temperature\n }\n\n for await (const message of query(\n messages,\n taskPrompt,\n context,\n hasPermissionsToUseTool,\n {\n abortController,\n options: queryOptions,\n messageId: getLastAssistantMessageId(messages),\n agentId: taskId,\n readFileTimestamps,\n setToolJSX: () => {}, // No-op implementation for TaskTool\n },\n )) {\n messages.push(message)\n\n overwriteLog(\n getMessagesPath(messageLogName, forkNumber, getSidechainNumber()),\n messages.filter(_ => _.type !== 'progress'),\n )\n\n if (message.type !== 'assistant') {\n continue\n }\n\n const normalizedMessages = normalizeMessages(messages)\n\n // Process tool uses and text content for better visibility\n for (const content of message.message.content) {\n if (\n content.type === 'text' &&\n content.text &&\n content.text !== INTERRUPT_MESSAGE\n ) {\n // Show agent's reasoning/responses\n const preview =\n content.text.length > 200\n ? content.text.substring(0, 200) + '...'\n : content.text\n yield {\n type: 'progress',\n content: createAssistantMessage(`${preview}`),\n normalizedMessages,\n tools,\n }\n } else if (content.type === 'tool_use') {\n toolUseCount++\n\n // Show which tool is being used with agent context\n const toolMessage = normalizedMessages.find(\n _ =>\n _.type === 'assistant' &&\n _.message.content[0]?.type === 'tool_use' &&\n _.message.content[0].id === content.id,\n ) as AssistantMessage\n\n if (toolMessage) {\n // Clone and modify the message to show agent context\n const modifiedMessage = {\n ...toolMessage,\n message: {\n ...toolMessage.message,\n content: toolMessage.message.content.map(c => {\n if (c.type === 'tool_use' && c.id === content.id) {\n // Add agent context to tool name display\n return {\n ...c,\n name: c.name, // Keep original name, UI will handle display\n }\n }\n return c\n }),\n },\n }\n\n yield {\n type: 'progress',\n content: modifiedMessage,\n normalizedMessages,\n tools,\n }\n }\n }\n }\n }\n\n const normalizedMessages = normalizeMessages(messages)\n const lastMessage = last(messages)\n if (lastMessage?.type !== 'assistant') {\n throw new Error('Last message was not an assistant message')\n }\n\n // \uD83D\uDD27 CRITICAL FIX: Match original AgentTool interrupt handling pattern exactly\n if (\n lastMessage.message.content.some(\n _ => _.type === 'text' && _.text === INTERRUPT_MESSAGE,\n )\n ) {\n // Skip progress yield - only yield final result\n } else {\n const result = [\n toolUseCount === 1 ? '1 tool use' : `${toolUseCount} tool uses`,\n formatNumber(\n (lastMessage.message.usage.cache_creation_input_tokens ?? 0) +\n (lastMessage.message.usage.cache_read_input_tokens ?? 0) +\n lastMessage.message.usage.input_tokens +\n lastMessage.message.usage.output_tokens,\n ) + ' tokens',\n formatDuration(Date.now() - startTime),\n ]\n yield {\n type: 'progress',\n content: createAssistantMessage(\n `Task completed (${result.join(' \u00B7 ')})`,\n ),\n normalizedMessages,\n tools,\n }\n }\n\n // Output is an AssistantMessage, but since TaskTool is a tool, it needs\n // to serialize its response to UserMessage-compatible content.\n const data = lastMessage.message.content.filter(_ => _.type === 'text')\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n },\n\n isReadOnly() {\n return true // for now...\n },\n isConcurrencySafe() {\n return true // Task tool supports concurrent execution in official implementation\n },\n async validateInput(input, context) {\n if (!input.description || typeof input.description !== 'string') {\n return {\n result: false,\n message: 'Description is required and must be a string',\n }\n }\n if (!input.prompt || typeof input.prompt !== 'string') {\n return {\n result: false,\n message: 'Prompt is required and must be a string',\n }\n }\n\n // Model validation - similar to Edit tool error handling\n if (input.model_name) {\n const modelManager = getModelManager()\n const availableModels = modelManager.getAllAvailableModelNames()\n\n if (!availableModels.includes(input.model_name)) {\n return {\n result: false,\n message: `Model '${input.model_name}' does not exist. Available models: ${availableModels.join(', ')}`,\n meta: {\n model_name: input.model_name,\n availableModels,\n },\n }\n }\n }\n\n // Validate subagent_type if provided\n if (input.subagent_type) {\n const availableTypes = await getAvailableAgentTypes()\n if (!availableTypes.includes(input.subagent_type)) {\n return {\n result: false,\n message: `Agent type '${input.subagent_type}' does not exist. Available types: ${availableTypes.join(', ')}`,\n meta: {\n subagent_type: input.subagent_type,\n availableTypes,\n },\n }\n }\n }\n\n return { result: true }\n },\n async isEnabled() {\n return true\n },\n userFacingName(input?: any) {\n // Return agent name with proper prefix\n const agentType = input?.subagent_type || 'general-purpose'\n return `agent-${agentType}`\n },\n needsPermissions() {\n return false\n },\n renderResultForAssistant(data: TextBlock[]) {\n return data\n .map(block => (block.type === 'text' ? block.text : ''))\n .join('\\n')\n },\n renderToolUseMessage(\n { description, prompt, model_name, subagent_type },\n { verbose },\n ) {\n if (!description || !prompt) return null\n\n const modelManager = getModelManager()\n const defaultTaskModel = modelManager.getModelName('task')\n const actualModel = model_name || defaultTaskModel\n const agentType = subagent_type || 'general-purpose'\n const promptPreview =\n prompt.length > 80 ? prompt.substring(0, 80) + '...' : prompt\n\n const theme = getTheme()\n\n if (verbose) {\n return (\n <Box flexDirection=\"column\">\n <Text>\n [{agentType}] {actualModel}: {description}\n </Text>\n <Box\n paddingLeft={2}\n borderLeftStyle=\"single\"\n borderLeftColor={theme.secondaryBorder}\n >\n <Text color={theme.secondaryText}>{promptPreview}</Text>\n </Box>\n </Box>\n )\n }\n\n // Simple display: agent type, model and description\n return `[${agentType}] ${actualModel}: ${description}`\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n // renderToolResultMessage(content) {\n // const theme = getTheme()\n\n // if (Array.isArray(content)) {\n // const textBlocks = content.filter(block => block.type === 'text')\n // const totalLength = textBlocks.reduce(\n // (sum, block) => sum + block.text.length,\n // 0,\n // )\n // // \uD83D\uDD27 CRITICAL FIX: Use exact match for interrupt detection, not .includes()\n // const isInterrupted = content.some(\n // block =>\n // block.type === 'text' && block.text === INTERRUPT_MESSAGE,\n // )\n\n // if (isInterrupted) {\n // // \uD83D\uDD27 CRITICAL FIX: Match original system interrupt rendering exactly\n // return (\n // <Box flexDirection=\"row\">\n // <Text>&nbsp;&nbsp;\u23BF &nbsp;</Text>\n // <Text color={theme.error}>Interrupted by user</Text>\n // </Box>\n // )\n // }\n\n // return (\n // <Box flexDirection=\"column\">\n // <Box justifyContent=\"space-between\" width=\"100%\">\n // <Box flexDirection=\"row\">\n // <Text>&nbsp;&nbsp;\u23BF &nbsp;</Text>\n // <Text>Task completed</Text>\n // {textBlocks.length > 0 && (\n // <Text color={theme.secondaryText}>\n // {' '}\n // ({totalLength} characters)\n // </Text>\n // )}\n // </Box>\n // </Box>\n // </Box>\n // )\n // }\n\n // return (\n // <Box flexDirection=\"row\">\n // <Text>&nbsp;&nbsp;\u23BF &nbsp;</Text>\n // <Text color={theme.secondaryText}>Task completed</Text>\n // </Box>\n // )\n // },\n} satisfies Tool<typeof inputSchema, TextBlock[]>\n"],
5
- "mappings": "AAEA,SAAS,MAAM,eAAe;AAE9B,OAAO,WAAoC;AAC3C,SAAS,KAAK,YAAY;AAC1B,SAAS,SAAS;AAElB,SAAS,sCAAsC;AAC/C,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,+BAA+B;AACxC,SAAmD,aAAa;AAChE,SAAS,gBAAgB,oBAAoB;AAC7C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAEhC,SAAS,cAAc,iBAAiB;AACxC,SAAS,iBAAiB;AAC1B;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,cAAc,EAAE,OAAO;AAAA,EAC3B,aAAa,EACV,OAAO,EACP,SAAS,4CAA4C;AAAA,EACxD,QAAQ,EAAE,OAAO,EAAE,SAAS,mCAAmC;AAAA,EAC/D,YAAY,EACT,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AAAA,EACF,eAAe,EACZ,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAEM,MAAM,WAAW;AAAA,EACtB,MAAM,OAAO,EAAE,SA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sourcesContent": ["import { TextBlock } from '@anthropic-ai/sdk/resources/index.mjs'\nimport chalk from 'chalk'\nimport { last, memoize } from 'lodash-es'\nimport { EOL } from 'os'\nimport React, { useState, useEffect } from 'react'\nimport { Box, Text } from 'ink'\nimport { z } from 'zod'\nimport { Tool, ValidationResult } from '@tool'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { getAgentPrompt } from '@constants/prompts'\nimport { getContext } from '@context'\nimport { hasPermissionsToUseTool } from '@permissions'\nimport { AssistantMessage, Message as MessageType, query } from '@query'\nimport { formatDuration, formatNumber } from '@utils/format'\nimport {\n getMessagesPath,\n getNextAvailableLogSidechainNumber,\n overwriteLog,\n} from '@utils/log'\nimport { applyMarkdown } from '@utils/markdown'\nimport {\n createAssistantMessage,\n createUserMessage,\n getLastAssistantMessageId,\n INTERRUPT_MESSAGE,\n normalizeMessages,\n} from '@utils/messages'\nimport { getModelManager } from '@utils/model'\nimport { getMaxThinkingTokens } from '@utils/thinking'\nimport { getTheme } from '@utils/theme'\nimport { generateAgentId } from '@utils/agentStorage'\nimport { debug as debugLogger } from '@utils/debugLogger'\nimport { getTaskTools, getPrompt } from './prompt'\nimport { TOOL_NAME } from './constants'\nimport {\n getActiveAgents,\n getAgentByType,\n getAvailableAgentTypes,\n} from '@utils/agentLoader'\n\nconst inputSchema = z.object({\n description: z\n .string()\n .describe('A short (3-5 word) description of the task'),\n prompt: z.string().describe('The task for the agent to perform'),\n model_name: z\n .string()\n .optional()\n .describe(\n 'Optional: Specific model name to use for this task. If not provided, uses the default task model pointer.',\n ),\n subagent_type: z\n .string()\n .optional()\n .describe(\n 'The specialized agent type (MUST use hyphens, e.g., \"strategic-market-analyzer\"). For research/analysis use \"strategic-market-analyzer\" or \"business-analyst\", for data use \"data-scientist\", for general use \"general-purpose\". NEVER use underscores or invent names like \"researcher\".',\n ),\n})\n\nexport const TaskTool = {\n async prompt({ safeMode }) {\n // Ensure agent prompts remain compatible with Claude Code `.claude` agent packs\n return await getPrompt(safeMode)\n },\n name: TOOL_NAME,\n async description() {\n // Ensure metadata stays compatible with Claude Code `.claude` agent packs\n const availableTypes = await getAvailableAgentTypes()\n const typesList =\n availableTypes.slice(0, 10).join(', ') +\n (availableTypes.length > 10 ? '...' : '')\n return `Launch a specialized agent to handle tasks autonomously. CRITICAL: Use exact agent type names with hyphens (e.g., \"strategic-market-analyzer\", NOT \"researcher\" or \"market_analyzer\"). Available: ${typesList}`\n },\n inputSchema,\n\n async *call(\n { description, prompt, model_name, subagent_type },\n {\n abortController,\n options: { safeMode = false, forkNumber, messageLogName, verbose },\n readFileTimestamps,\n },\n ): AsyncGenerator<\n | { type: 'result'; data: TextBlock[]; resultForAssistant?: string }\n | {\n type: 'progress'\n content: any\n normalizedMessages?: any[]\n tools?: any[]\n },\n void,\n unknown\n > {\n const startTime = Date.now()\n\n // Default to general-purpose if no subagent_type specified\n const agentType = subagent_type || 'general-purpose'\n\n // Apply subagent configuration\n let effectivePrompt = prompt\n let effectiveModel = model_name || 'task'\n let toolFilter = null\n let temperature = undefined\n\n // Load agent configuration dynamically\n if (agentType) {\n const agentConfig = await getAgentByType(agentType)\n\n if (!agentConfig) {\n // If agent type not found, return helpful message instead of throwing\n const availableTypes = await getAvailableAgentTypes()\n const helpMessage = `Agent type '${agentType}' not found.\\n\\nAvailable agents:\\n${availableTypes.map(t => ` \u2022 ${t}`).join('\\n')}\\n\\nUse /agents command to manage agent configurations.`\n\n yield {\n type: 'result',\n data: [{ type: 'text', text: helpMessage }] as TextBlock[],\n resultForAssistant: helpMessage,\n }\n return\n }\n\n // Apply system prompt if configured\n if (agentConfig.systemPrompt) {\n effectivePrompt = `${agentConfig.systemPrompt}\\n\\n${prompt}`\n }\n\n // Apply model if not overridden by model_name parameter\n if (!model_name && agentConfig.model_name) {\n // Support inherit: keep pointer-based default\n if (agentConfig.model_name !== 'inherit') {\n effectiveModel = agentConfig.model_name as string\n }\n }\n\n // Store tool filter for later application\n toolFilter = agentConfig.tools\n\n // Note: temperature is not currently in our agent configs\n // but could be added in the future\n }\n\n const messages: MessageType[] = [createUserMessage(effectivePrompt)]\n let tools = await getTaskTools(safeMode)\n\n // Apply tool filtering if specified by subagent config\n if (toolFilter) {\n // Back-compat: ['*'] means all tools\n const isAllArray =\n Array.isArray(toolFilter) &&\n toolFilter.length === 1 &&\n toolFilter[0] === '*'\n if (toolFilter === '*' || isAllArray) {\n // no-op, keep all tools\n } else if (Array.isArray(toolFilter)) {\n tools = tools.filter(tool => toolFilter.includes(tool.name))\n }\n }\n\n // Model already resolved in effectiveModel variable above\n const modelToUse = effectiveModel\n\n // Display initial task information with separate progress lines\n yield {\n type: 'progress',\n content: createAssistantMessage(`Starting agent: ${agentType}`),\n normalizedMessages: normalizeMessages(messages),\n tools,\n }\n\n yield {\n type: 'progress',\n content: createAssistantMessage(`Using model: ${modelToUse}`),\n normalizedMessages: normalizeMessages(messages),\n tools,\n }\n\n yield {\n type: 'progress',\n content: createAssistantMessage(`Task: ${description}`),\n normalizedMessages: normalizeMessages(messages),\n tools,\n }\n\n yield {\n type: 'progress',\n content: createAssistantMessage(\n `Prompt: ${prompt.length > 150 ? prompt.substring(0, 150) + '...' : prompt}`,\n ),\n normalizedMessages: normalizeMessages(messages),\n tools,\n }\n\n const [taskPrompt, context, maxThinkingTokens] = await Promise.all([\n getAgentPrompt(),\n getContext(),\n getMaxThinkingTokens(messages),\n ])\n\n // Inject model context to prevent self-referential expert consultations\n taskPrompt.push(\n `\\nIMPORTANT: You are currently running as ${modelToUse}. You do not need to consult ${modelToUse} via AskExpertModel since you ARE ${modelToUse}. Complete tasks directly using your capabilities.`,\n )\n\n let toolUseCount = 0\n\n const getSidechainNumber = memoize(() =>\n getNextAvailableLogSidechainNumber(messageLogName, forkNumber),\n )\n\n // Generate unique Task ID for this task execution\n const taskId = generateAgentId()\n\n // \uD83D\uDD27 ULTRA SIMPLIFIED: Exact original AgentTool pattern\n // Build query options, adding temperature if specified\n const queryOptions = {\n safeMode,\n forkNumber,\n messageLogName,\n tools,\n commands: [],\n verbose,\n maxThinkingTokens,\n model: modelToUse,\n }\n\n // Add temperature if specified by subagent config\n if (temperature !== undefined) {\n queryOptions['temperature'] = temperature\n }\n\n for await (const message of query(\n messages,\n taskPrompt,\n context,\n hasPermissionsToUseTool,\n {\n abortController,\n options: queryOptions,\n messageId: getLastAssistantMessageId(messages),\n agentId: taskId,\n readFileTimestamps,\n setToolJSX: () => {}, // No-op implementation for TaskTool\n },\n )) {\n messages.push(message)\n\n overwriteLog(\n getMessagesPath(messageLogName, forkNumber, getSidechainNumber()),\n messages.filter(_ => _.type !== 'progress'),\n )\n\n if (message.type !== 'assistant') {\n continue\n }\n\n const normalizedMessages = normalizeMessages(messages)\n\n // Process tool uses and text content for better visibility\n for (const content of message.message.content) {\n if (\n content.type === 'text' &&\n content.text &&\n content.text !== INTERRUPT_MESSAGE\n ) {\n // Show agent's reasoning/responses\n const preview =\n content.text.length > 200\n ? content.text.substring(0, 200) + '...'\n : content.text\n yield {\n type: 'progress',\n content: createAssistantMessage(`${preview}`),\n normalizedMessages,\n tools,\n }\n } else if (content.type === 'tool_use') {\n toolUseCount++\n\n // Show which tool is being used with agent context\n const toolMessage = normalizedMessages.find(\n _ =>\n _.type === 'assistant' &&\n _.message.content[0]?.type === 'tool_use' &&\n _.message.content[0].id === content.id,\n ) as AssistantMessage\n\n if (toolMessage) {\n // Clone and modify the message to show agent context\n const modifiedMessage = {\n ...toolMessage,\n message: {\n ...toolMessage.message,\n content: toolMessage.message.content.map(c => {\n if (c.type === 'tool_use' && c.id === content.id) {\n // Add agent context to tool name display\n return {\n ...c,\n name: c.name, // Keep original name, UI will handle display\n }\n }\n return c\n }),\n },\n }\n\n yield {\n type: 'progress',\n content: modifiedMessage,\n normalizedMessages,\n tools,\n }\n }\n }\n }\n }\n\n const normalizedMessages = normalizeMessages(messages)\n const lastMessage = last(messages)\n if (lastMessage?.type !== 'assistant') {\n throw new Error('Last message was not an assistant message')\n }\n\n // \uD83D\uDD27 CRITICAL FIX: Match original AgentTool interrupt handling pattern exactly\n if (\n lastMessage.message.content.some(\n _ => _.type === 'text' && _.text === INTERRUPT_MESSAGE,\n )\n ) {\n // Skip progress yield - only yield final result\n } else {\n const result = [\n toolUseCount === 1 ? '1 tool use' : `${toolUseCount} tool uses`,\n formatNumber(\n (lastMessage.message.usage.cache_creation_input_tokens ?? 0) +\n (lastMessage.message.usage.cache_read_input_tokens ?? 0) +\n lastMessage.message.usage.input_tokens +\n lastMessage.message.usage.output_tokens,\n ) + ' tokens',\n formatDuration(Date.now() - startTime),\n ]\n yield {\n type: 'progress',\n content: createAssistantMessage(\n `Task completed (${result.join(' \u00B7 ')})`,\n ),\n normalizedMessages,\n tools,\n }\n }\n\n // Output is an AssistantMessage, but since TaskTool is a tool, it needs\n // to serialize its response to UserMessage-compatible content.\n const data = lastMessage.message.content.filter(_ => _.type === 'text')\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n },\n\n isReadOnly() {\n return true // for now...\n },\n isConcurrencySafe() {\n return true // Task tool supports concurrent execution in official implementation\n },\n async validateInput(input, context) {\n if (!input.description || typeof input.description !== 'string') {\n return {\n result: false,\n message: 'Description is required and must be a string',\n }\n }\n if (!input.prompt || typeof input.prompt !== 'string') {\n return {\n result: false,\n message: 'Prompt is required and must be a string',\n }\n }\n\n // Model validation - similar to Edit tool error handling\n if (input.model_name) {\n const modelManager = getModelManager()\n const availableModels = modelManager.getAllAvailableModelNames()\n\n if (!availableModels.includes(input.model_name)) {\n return {\n result: false,\n message: `Model '${input.model_name}' does not exist. Available models: ${availableModels.join(', ')}`,\n meta: {\n model_name: input.model_name,\n availableModels,\n },\n }\n }\n }\n\n // Validate subagent_type if provided\n if (input.subagent_type) {\n const availableTypes = await getAvailableAgentTypes()\n if (!availableTypes.includes(input.subagent_type)) {\n return {\n result: false,\n message: `Agent type '${input.subagent_type}' does not exist. Available types: ${availableTypes.join(', ')}`,\n meta: {\n subagent_type: input.subagent_type,\n availableTypes,\n },\n }\n }\n }\n\n return { result: true }\n },\n async isEnabled() {\n return true\n },\n userFacingName(input?: any) {\n // Return agent name with proper prefix\n const agentType = input?.subagent_type || 'general-purpose'\n return `agent-${agentType}`\n },\n needsPermissions() {\n return false\n },\n renderResultForAssistant(data: TextBlock[]) {\n return data\n .map(block => (block.type === 'text' ? block.text : ''))\n .join('\\n')\n },\n renderToolUseMessage(\n { description, prompt, model_name, subagent_type },\n { verbose },\n ) {\n if (!description || !prompt) return null\n\n const modelManager = getModelManager()\n const defaultTaskModel = modelManager.getModelName('task')\n const actualModel = model_name || defaultTaskModel\n const agentType = subagent_type || 'general-purpose'\n const promptPreview =\n prompt.length > 80 ? prompt.substring(0, 80) + '...' : prompt\n\n const theme = getTheme()\n\n if (verbose) {\n return (\n <Box flexDirection=\"column\">\n <Text>\n [{agentType}] {actualModel}: {description}\n </Text>\n <Box\n paddingLeft={2}\n borderLeftStyle=\"single\"\n borderLeftColor={theme.secondaryBorder}\n >\n <Text color={theme.secondaryText}>{promptPreview}</Text>\n </Box>\n </Box>\n )\n }\n\n // Simple display: agent type, model and description\n return `[${agentType}] ${actualModel}: ${description}`\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(content) {\n const theme = getTheme()\n\n // Guard against undefined or null content\n if (!content) {\n return (\n <Box flexDirection=\"row\">\n <Text>&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Text color={theme.secondaryText}>Task completed</Text>\n </Box>\n )\n }\n\n if (Array.isArray(content)) {\n const textBlocks = content.filter(\n (block): block is { type: 'text'; text: string } =>\n block && block.type === 'text',\n )\n const totalLength = textBlocks.reduce(\n (sum, block) => sum + (block.text?.length || 0),\n 0,\n )\n // Use exact match for interrupt detection\n const isInterrupted = content.some(\n block =>\n block &&\n block.type === 'text' &&\n block.text === INTERRUPT_MESSAGE,\n )\n\n if (isInterrupted) {\n return (\n <Box flexDirection=\"row\">\n <Text>&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Text color={theme.error}>Interrupted by user</Text>\n </Box>\n )\n }\n\n return (\n <Box flexDirection=\"column\">\n <Box justifyContent=\"space-between\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text>&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Text>Task completed</Text>\n {textBlocks.length > 0 && (\n <Text color={theme.secondaryText}>\n {' '}\n ({totalLength} characters)\n </Text>\n )}\n </Box>\n </Box>\n </Box>\n )\n }\n\n return (\n <Box flexDirection=\"row\">\n <Text>&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Text color={theme.secondaryText}>Task completed</Text>\n </Box>\n )\n },\n} satisfies Tool<typeof inputSchema, TextBlock[]>\n"],
5
+ "mappings": "AAEA,SAAS,MAAM,eAAe;AAE9B,OAAO,WAAoC;AAC3C,SAAS,KAAK,YAAY;AAC1B,SAAS,SAAS;AAElB,SAAS,sCAAsC;AAC/C,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,+BAA+B;AACxC,SAAmD,aAAa;AAChE,SAAS,gBAAgB,oBAAoB;AAC7C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAEhC,SAAS,cAAc,iBAAiB;AACxC,SAAS,iBAAiB;AAC1B;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,cAAc,EAAE,OAAO;AAAA,EAC3B,aAAa,EACV,OAAO,EACP,SAAS,4CAA4C;AAAA,EACxD,QAAQ,EAAE,OAAO,EAAE,SAAS,mCAAmC;AAAA,EAC/D,YAAY,EACT,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AAAA,EACF,eAAe,EACZ,OAAO,EACP,SAAS,EACT;AAAA,IAC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M,QAAQ,OAAO,GAAG;AAC1B,YAAM,aAAa,QAAQ;AAAA,QACzB,CAAC,UACC,SAAS,MAAM,SAAS;AAAA,MAC5B;AACA,YAAM,cAAc,WAAW;AAAA,QAC7B,CAAC,KAAK,UAAU,OAAO,MAAM,MAAM,UAAU;AAAA,QAC7C;AAAA,MACF;AAEA,YAAM,gBAAgB,QAAQ;AAAA,QAC5B,WACE,SACA,MAAM,SAAS,UACf,MAAM,SAAS;AAAA,MACnB;AAEA,UAAI,eAAe;AACjB,eACE,oCAAC,OAAI,eAAc,SACjB,oCAAC,YAAK,qBAAoB,GAC1B,oCAAC,QAAK,OAAO,MAAM,SAAO,qBAAmB,CAC/C;AAAA,MAEJ;AAEA,aACE,oCAAC,OAAI,eAAc,YACjB,oCAAC,OAAI,gBAAe,iBAAgB,OAAM,UACxC,oCAAC,OAAI,eAAc,SACjB,oCAAC,YAAK,qBAAoB,GAC1B,oCAAC,YAAK,gBAAc,GACnB,WAAW,SAAS,KACnB,oCAAC,QAAK,OAAO,MAAM,iBAChB,KAAI,KACH,aAAY,cAChB,CAEJ,CACF,CACF;AAAA,IAEJ;AAEA,WACE,oCAAC,OAAI,eAAc,SACjB,oCAAC,YAAK,qBAAoB,GAC1B,oCAAC,QAAK,OAAO,MAAM,iBAAe,gBAAc,CAClD;AAAA,EAEJ;AACF;",
6
6
  "names": ["normalizedMessages"]
7
7
  }
@@ -140,15 +140,19 @@ const TodoWriteTool = {
140
140
  return /* @__PURE__ */ React.createElement(FallbackToolUseRejectedMessage, null);
141
141
  },
142
142
  renderToolResultMessage(output) {
143
+ if (output === void 0 || output === null) {
144
+ return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", width: "100%" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, { color: "#6B7280" }, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React.createElement(Text, { color: "#9CA3AF" }, "Todo operation completed")));
145
+ }
143
146
  const isError = typeof output === "string" && output.startsWith("Error");
144
147
  if (!isError && typeof output === "string") {
145
- const currentTodos = getTodos();
148
+ const currentTodos = getTodos() || [];
146
149
  if (currentTodos.length === 0) {
147
150
  return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", width: "100%" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, { color: "#6B7280" }, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React.createElement(Text, { color: "#9CA3AF" }, "No todos currently")));
148
151
  }
149
152
  const sortedTodos = [...currentTodos].sort((a, b) => {
153
+ if (!a || !b) return 0;
150
154
  const order = ["completed", "in_progress", "pending"];
151
- return order.indexOf(a.status) - order.indexOf(b.status) || a.content.localeCompare(b.content);
155
+ return order.indexOf(a.status || "pending") - order.indexOf(b.status || "pending") || (a.content || "").localeCompare(b.content || "");
152
156
  });
153
157
  const nextPendingIndex = sortedTodos.findIndex(
154
158
  (todo) => todo.status === "pending"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/tools/TodoWriteTool/TodoWriteTool.tsx"],
4
- "sourcesContent": ["import { Box, Text } from 'ink'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { TodoItem as TodoItemComponent } from '@components/TodoItem'\nimport { Tool, ValidationResult } from '@tool'\nimport { setTodos, getTodos, TodoItem } from '@utils/todoStorage'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport { startWatchingTodoFile } from '@services/fileFreshness'\nimport { DESCRIPTION, PROMPT } from './prompt'\nimport { getTheme } from '@utils/theme'\n\nconst TodoItemSchema = z.object({\n content: z.string().min(1).describe('The task description or content'),\n activeForm: z\n .string()\n .min(1)\n .optional()\n .describe(\n 'The present continuous form of the task (e.g., \"Running tests\" for \"Run tests\"). If not provided, will be auto-generated from content.',\n ),\n status: z\n .enum(['pending', 'in_progress', 'completed'])\n .describe('Current status of the task'),\n priority: z\n .enum(['high', 'medium', 'low'])\n .describe('Priority level of the task'),\n id: z.string().min(1).describe('Unique identifier for the task'),\n})\n\nconst inputSchema = z.strictObject({\n todos: z.array(TodoItemSchema).describe('The updated todo list'),\n})\n\n/**\n * Auto-generates activeForm from content if not provided\n * Converts imperative form to present continuous\n * Examples: \"Run tests\" -> \"Running tests\", \"Fix bug\" -> \"Fixing bug\"\n */\nfunction generateActiveForm(content: string): string {\n const trimmed = content.trim()\n\n // Common verb patterns for imperative -> present continuous\n const patterns = [\n { regex: /^(Run|run)\\s+(.+)$/i, replacement: 'Running $2' },\n { regex: /^(Build|build)\\s+(.+)$/i, replacement: 'Building $2' },\n { regex: /^(Fix|fix)\\s+(.+)$/i, replacement: 'Fixing $2' },\n { regex: /^(Add|add)\\s+(.+)$/i, replacement: 'Adding $2' },\n { regex: /^(Create|create)\\s+(.+)$/i, replacement: 'Creating $2' },\n { regex: /^(Update|update)\\s+(.+)$/i, replacement: 'Updating $2' },\n { regex: /^(Delete|delete)\\s+(.+)$/i, replacement: 'Deleting $2' },\n { regex: /^(Test|test)\\s+(.+)$/i, replacement: 'Testing $2' },\n { regex: /^(Deploy|deploy)\\s+(.+)$/i, replacement: 'Deploying $2' },\n { regex: /^(Analyze|analyze)\\s+(.+)$/i, replacement: 'Analyzing $2' },\n { regex: /^(Review|review)\\s+(.+)$/i, replacement: 'Reviewing $2' },\n { regex: /^(Write|write)\\s+(.+)$/i, replacement: 'Writing $2' },\n ]\n\n for (const { regex, replacement } of patterns) {\n if (regex.test(trimmed)) {\n return trimmed.replace(regex, replacement)\n }\n }\n\n // Fallback: add \"Working on\" prefix\n return `Working on: ${trimmed}`\n}\n\nfunction validateTodos(todos: TodoItem[]): ValidationResult {\n // Check for duplicate IDs\n const ids = todos.map(todo => todo.id)\n const uniqueIds = new Set(ids)\n if (ids.length !== uniqueIds.size) {\n return {\n result: false,\n errorCode: 1,\n message: 'Duplicate todo IDs found',\n meta: {\n duplicateIds: ids.filter((id, index) => ids.indexOf(id) !== index),\n },\n }\n }\n\n // Check for multiple in_progress tasks\n const inProgressTasks = todos.filter(todo => todo.status === 'in_progress')\n if (inProgressTasks.length > 1) {\n return {\n result: false,\n errorCode: 2,\n message: 'Only one task can be in_progress at a time',\n meta: { inProgressTaskIds: inProgressTasks.map(t => t.id) },\n }\n }\n\n // Validate each todo\n for (const todo of todos) {\n if (!todo.content?.trim()) {\n return {\n result: false,\n errorCode: 3,\n message: `Todo with ID \"${todo.id}\" has empty content`,\n meta: { todoId: todo.id },\n }\n }\n if (!['pending', 'in_progress', 'completed'].includes(todo.status)) {\n return {\n result: false,\n errorCode: 4,\n message: `Invalid status \"${todo.status}\" for todo \"${todo.id}\"`,\n meta: { todoId: todo.id, invalidStatus: todo.status },\n }\n }\n if (!['high', 'medium', 'low'].includes(todo.priority)) {\n return {\n result: false,\n errorCode: 5,\n message: `Invalid priority \"${todo.priority}\" for todo \"${todo.id}\"`,\n meta: { todoId: todo.id, invalidPriority: todo.priority },\n }\n }\n }\n\n return { result: true }\n}\n\nfunction generateTodoSummary(todos: TodoItem[]): string {\n const stats = {\n total: todos.length,\n pending: todos.filter(t => t.status === 'pending').length,\n inProgress: todos.filter(t => t.status === 'in_progress').length,\n completed: todos.filter(t => t.status === 'completed').length,\n }\n\n // Enhanced summary with statistics\n let summary = `Updated ${stats.total} todo(s)`\n if (stats.total > 0) {\n summary += ` (${stats.pending} pending, ${stats.inProgress} in progress, ${stats.completed} completed)`\n }\n summary += '. Continue tracking your progress with the todo list.'\n\n return summary\n}\n\nexport const TodoWriteTool = {\n name: 'TodoWrite',\n async description() {\n return DESCRIPTION\n },\n async prompt() {\n return PROMPT\n },\n inputSchema,\n userFacingName() {\n return 'Update Todos'\n },\n async isEnabled() {\n return true\n },\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false // TodoWrite modifies state, not safe for concurrent execution\n },\n needsPermissions() {\n return false\n },\n renderResultForAssistant(result) {\n // Match official implementation - return static confirmation message\n return 'Todos have been modified successfully. Ensure that you continue to use the todo list to track your progress. Please proceed with the current tasks if applicable'\n },\n renderToolUseMessage(input, { verbose }) {\n // Show a simple confirmation message when the tool is being used\n return '{ params.todo }'\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(output) {\n const isError = typeof output === 'string' && output.startsWith('Error')\n\n // For non-error output, get current todos from storage and render them\n if (!isError && typeof output === 'string') {\n const currentTodos = getTodos()\n\n if (currentTodos.length === 0) {\n return (\n <Box flexDirection=\"column\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text color=\"#6B7280\">&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Text color=\"#9CA3AF\">No todos currently</Text>\n </Box>\n </Box>\n )\n }\n\n // Sort: [completed, in_progress, pending]\n const sortedTodos = [...currentTodos].sort((a, b) => {\n const order = ['completed', 'in_progress', 'pending']\n return (\n order.indexOf(a.status) - order.indexOf(b.status) ||\n a.content.localeCompare(b.content)\n )\n })\n\n // Find the next pending task (first pending task after sorting)\n const nextPendingIndex = sortedTodos.findIndex(\n todo => todo.status === 'pending',\n )\n\n return (\n <Box flexDirection=\"column\" width=\"100%\">\n {sortedTodos.map((todo: TodoItem, index: number) => {\n // Determine checkbox symbol and colors\n let checkbox: string\n let textColor: string\n let isBold = false\n let isStrikethrough = false\n\n if (todo.status === 'completed') {\n checkbox = '\u2612'\n textColor = '#6B7280' // Professional gray for completed\n isStrikethrough = true\n } else if (todo.status === 'in_progress') {\n checkbox = '\u2610'\n textColor = '#10B981' // Professional green for in progress\n isBold = true\n } else if (todo.status === 'pending') {\n checkbox = '\u2610'\n // Only the FIRST pending task gets purple highlight\n if (index === nextPendingIndex) {\n textColor = '#8B5CF6' // Professional purple for next pending\n isBold = true\n } else {\n textColor = '#9CA3AF' // Muted gray for other pending\n }\n }\n\n return (\n <Box key={todo.id || index} flexDirection=\"row\" marginBottom={0}>\n <Text color=\"#6B7280\">&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Box flexDirection=\"row\" flexGrow={1}>\n <Text\n color={textColor}\n bold={isBold}\n strikethrough={isStrikethrough}\n >\n {checkbox}\n </Text>\n <Text> </Text>\n <Text\n color={textColor}\n bold={isBold}\n strikethrough={isStrikethrough}\n >\n {todo.content}\n </Text>\n </Box>\n </Box>\n )\n })}\n </Box>\n )\n }\n\n // Fallback to simple text rendering for errors or string output\n return (\n <Box justifyContent=\"space-between\" overflowX=\"hidden\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text color={isError ? getTheme().error : getTheme().success}>\n &nbsp;&nbsp;\u23BF &nbsp;\n {typeof output === 'string' ? output : JSON.stringify(output)}\n </Text>\n </Box>\n </Box>\n )\n },\n async validateInput({ todos }: z.infer<typeof inputSchema>) {\n // Type assertion to ensure todos match TodoItem[] interface\n const todoItems = todos as TodoItem[]\n const validation = validateTodos(todoItems)\n if (!validation.result) {\n return validation\n }\n return { result: true }\n },\n async *call({ todos }: z.infer<typeof inputSchema>, context) {\n try {\n // Get agent ID from context\n const agentId = context?.agentId\n\n // Start watching todo file for this agent if not already watching\n if (agentId) {\n startWatchingTodoFile(agentId)\n }\n\n // Store previous todos for comparison (agent-scoped)\n const previousTodos = getTodos(agentId)\n\n // Type assertion to ensure todos match TodoItem[] interface\n // Auto-generate activeForm for todos that don't have it\n const todoItems = todos.map(todo => ({\n ...todo,\n activeForm: todo.activeForm || generateActiveForm(todo.content),\n })) as TodoItem[]\n\n // Note: Validation already done in validateInput, no need for duplicate validation\n // This eliminates the double validation issue\n\n // Update the todos in storage (agent-scoped)\n setTodos(todoItems, agentId)\n\n // Emit todo change event for system reminders (optimized - only if todos actually changed)\n const hasChanged =\n JSON.stringify(previousTodos) !== JSON.stringify(todoItems)\n if (hasChanged) {\n emitReminderEvent('todo:changed', {\n previousTodos,\n newTodos: todoItems,\n timestamp: Date.now(),\n agentId: agentId || 'default',\n changeType:\n todoItems.length > previousTodos.length\n ? 'added'\n : todoItems.length < previousTodos.length\n ? 'removed'\n : 'modified',\n })\n }\n\n // Generate enhanced summary\n const summary = generateTodoSummary(todoItems)\n\n // Enhanced result data for rendering\n const resultData = {\n oldTodos: previousTodos,\n newTodos: todoItems,\n summary,\n }\n\n yield {\n type: 'result',\n data: summary, // Return string to satisfy interface\n resultForAssistant: summary,\n // Store todo data in a way accessible to the renderer\n // We'll modify the renderToolResultMessage to get todos from storage\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error occurred'\n const errorResult = `Error updating todos: ${errorMessage}`\n\n // Emit error event for system monitoring\n emitReminderEvent('todo:error', {\n error: errorMessage,\n timestamp: Date.now(),\n agentId: context?.agentId || 'default',\n context: 'TodoWriteTool.call',\n })\n\n yield {\n type: 'result',\n data: errorResult,\n resultForAssistant: errorResult,\n }\n }\n },\n} satisfies Tool<typeof inputSchema, string>\n"],
5
- "mappings": "AAAA,SAAS,KAAK,YAAY;AAC1B,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAG/C,SAAS,UAAU,gBAA0B;AAC7C,SAAS,yBAAyB;AAClC,SAAS,6BAA6B;AACtC,SAAS,aAAa,cAAc;AACpC,SAAS,gBAAgB;AAEzB,MAAM,iBAAiB,EAAE,OAAO;AAAA,EAC9B,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,iCAAiC;AAAA,EACrE,YAAY,EACT,OAAO,EACP,IAAI,CAAC,EACL,SAAS,EACT;AAAA,IACC;AAAA,EACF;AAAA,EACF,QAAQ,EACL,KAAK,CAAC,WAAW,eAAe,WAAW,CAAC,EAC5C,SAAS,4BAA4B;AAAA,EACxC,UAAU,EACP,KAAK,CAAC,QAAQ,UAAU,KAAK,CAAC,EAC9B,SAAS,4BAA4B;AAAA,EACxC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,gCAAgC;AACjE,CAAC;AAED,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,OAAO,EAAE,MAAM,cAAc,EAAE,SAAS,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A,MACX,CAAC;AAED,YAAM;AAAA,QACJ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { Box, Text } from 'ink'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { TodoItem as TodoItemComponent } from '@components/TodoItem'\nimport { Tool, ValidationResult } from '@tool'\nimport { setTodos, getTodos, TodoItem } from '@utils/todoStorage'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport { startWatchingTodoFile } from '@services/fileFreshness'\nimport { DESCRIPTION, PROMPT } from './prompt'\nimport { getTheme } from '@utils/theme'\n\nconst TodoItemSchema = z.object({\n content: z.string().min(1).describe('The task description or content'),\n activeForm: z\n .string()\n .min(1)\n .optional()\n .describe(\n 'The present continuous form of the task (e.g., \"Running tests\" for \"Run tests\"). If not provided, will be auto-generated from content.',\n ),\n status: z\n .enum(['pending', 'in_progress', 'completed'])\n .describe('Current status of the task'),\n priority: z\n .enum(['high', 'medium', 'low'])\n .describe('Priority level of the task'),\n id: z.string().min(1).describe('Unique identifier for the task'),\n})\n\nconst inputSchema = z.strictObject({\n todos: z.array(TodoItemSchema).describe('The updated todo list'),\n})\n\n/**\n * Auto-generates activeForm from content if not provided\n * Converts imperative form to present continuous\n * Examples: \"Run tests\" -> \"Running tests\", \"Fix bug\" -> \"Fixing bug\"\n */\nfunction generateActiveForm(content: string): string {\n const trimmed = content.trim()\n\n // Common verb patterns for imperative -> present continuous\n const patterns = [\n { regex: /^(Run|run)\\s+(.+)$/i, replacement: 'Running $2' },\n { regex: /^(Build|build)\\s+(.+)$/i, replacement: 'Building $2' },\n { regex: /^(Fix|fix)\\s+(.+)$/i, replacement: 'Fixing $2' },\n { regex: /^(Add|add)\\s+(.+)$/i, replacement: 'Adding $2' },\n { regex: /^(Create|create)\\s+(.+)$/i, replacement: 'Creating $2' },\n { regex: /^(Update|update)\\s+(.+)$/i, replacement: 'Updating $2' },\n { regex: /^(Delete|delete)\\s+(.+)$/i, replacement: 'Deleting $2' },\n { regex: /^(Test|test)\\s+(.+)$/i, replacement: 'Testing $2' },\n { regex: /^(Deploy|deploy)\\s+(.+)$/i, replacement: 'Deploying $2' },\n { regex: /^(Analyze|analyze)\\s+(.+)$/i, replacement: 'Analyzing $2' },\n { regex: /^(Review|review)\\s+(.+)$/i, replacement: 'Reviewing $2' },\n { regex: /^(Write|write)\\s+(.+)$/i, replacement: 'Writing $2' },\n ]\n\n for (const { regex, replacement } of patterns) {\n if (regex.test(trimmed)) {\n return trimmed.replace(regex, replacement)\n }\n }\n\n // Fallback: add \"Working on\" prefix\n return `Working on: ${trimmed}`\n}\n\nfunction validateTodos(todos: TodoItem[]): ValidationResult {\n // Check for duplicate IDs\n const ids = todos.map(todo => todo.id)\n const uniqueIds = new Set(ids)\n if (ids.length !== uniqueIds.size) {\n return {\n result: false,\n errorCode: 1,\n message: 'Duplicate todo IDs found',\n meta: {\n duplicateIds: ids.filter((id, index) => ids.indexOf(id) !== index),\n },\n }\n }\n\n // Check for multiple in_progress tasks\n const inProgressTasks = todos.filter(todo => todo.status === 'in_progress')\n if (inProgressTasks.length > 1) {\n return {\n result: false,\n errorCode: 2,\n message: 'Only one task can be in_progress at a time',\n meta: { inProgressTaskIds: inProgressTasks.map(t => t.id) },\n }\n }\n\n // Validate each todo\n for (const todo of todos) {\n if (!todo.content?.trim()) {\n return {\n result: false,\n errorCode: 3,\n message: `Todo with ID \"${todo.id}\" has empty content`,\n meta: { todoId: todo.id },\n }\n }\n if (!['pending', 'in_progress', 'completed'].includes(todo.status)) {\n return {\n result: false,\n errorCode: 4,\n message: `Invalid status \"${todo.status}\" for todo \"${todo.id}\"`,\n meta: { todoId: todo.id, invalidStatus: todo.status },\n }\n }\n if (!['high', 'medium', 'low'].includes(todo.priority)) {\n return {\n result: false,\n errorCode: 5,\n message: `Invalid priority \"${todo.priority}\" for todo \"${todo.id}\"`,\n meta: { todoId: todo.id, invalidPriority: todo.priority },\n }\n }\n }\n\n return { result: true }\n}\n\nfunction generateTodoSummary(todos: TodoItem[]): string {\n const stats = {\n total: todos.length,\n pending: todos.filter(t => t.status === 'pending').length,\n inProgress: todos.filter(t => t.status === 'in_progress').length,\n completed: todos.filter(t => t.status === 'completed').length,\n }\n\n // Enhanced summary with statistics\n let summary = `Updated ${stats.total} todo(s)`\n if (stats.total > 0) {\n summary += ` (${stats.pending} pending, ${stats.inProgress} in progress, ${stats.completed} completed)`\n }\n summary += '. Continue tracking your progress with the todo list.'\n\n return summary\n}\n\nexport const TodoWriteTool = {\n name: 'TodoWrite',\n async description() {\n return DESCRIPTION\n },\n async prompt() {\n return PROMPT\n },\n inputSchema,\n userFacingName() {\n return 'Update Todos'\n },\n async isEnabled() {\n return true\n },\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false // TodoWrite modifies state, not safe for concurrent execution\n },\n needsPermissions() {\n return false\n },\n renderResultForAssistant(result) {\n // Match official implementation - return static confirmation message\n return 'Todos have been modified successfully. Ensure that you continue to use the todo list to track your progress. Please proceed with the current tasks if applicable'\n },\n renderToolUseMessage(input, { verbose }) {\n // Show a simple confirmation message when the tool is being used\n return '{ params.todo }'\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(output) {\n // Guard against undefined or null output\n if (output === undefined || output === null) {\n return (\n <Box flexDirection=\"column\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text color=\"#6B7280\">&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Text color=\"#9CA3AF\">Todo operation completed</Text>\n </Box>\n </Box>\n )\n }\n\n const isError = typeof output === 'string' && output.startsWith('Error')\n\n // For non-error output, get current todos from storage and render them\n if (!isError && typeof output === 'string') {\n const currentTodos = getTodos() || []\n\n if (currentTodos.length === 0) {\n return (\n <Box flexDirection=\"column\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text color=\"#6B7280\">&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Text color=\"#9CA3AF\">No todos currently</Text>\n </Box>\n </Box>\n )\n }\n\n // Sort: [completed, in_progress, pending]\n const sortedTodos = [...currentTodos].sort((a, b) => {\n if (!a || !b) return 0\n const order = ['completed', 'in_progress', 'pending']\n return (\n order.indexOf(a.status || 'pending') -\n order.indexOf(b.status || 'pending') ||\n (a.content || '').localeCompare(b.content || '')\n )\n })\n\n // Find the next pending task (first pending task after sorting)\n const nextPendingIndex = sortedTodos.findIndex(\n todo => todo.status === 'pending',\n )\n\n return (\n <Box flexDirection=\"column\" width=\"100%\">\n {sortedTodos.map((todo: TodoItem, index: number) => {\n // Determine checkbox symbol and colors\n let checkbox: string\n let textColor: string\n let isBold = false\n let isStrikethrough = false\n\n if (todo.status === 'completed') {\n checkbox = '\u2612'\n textColor = '#6B7280' // Professional gray for completed\n isStrikethrough = true\n } else if (todo.status === 'in_progress') {\n checkbox = '\u2610'\n textColor = '#10B981' // Professional green for in progress\n isBold = true\n } else if (todo.status === 'pending') {\n checkbox = '\u2610'\n // Only the FIRST pending task gets purple highlight\n if (index === nextPendingIndex) {\n textColor = '#8B5CF6' // Professional purple for next pending\n isBold = true\n } else {\n textColor = '#9CA3AF' // Muted gray for other pending\n }\n }\n\n return (\n <Box key={todo.id || index} flexDirection=\"row\" marginBottom={0}>\n <Text color=\"#6B7280\">&nbsp;&nbsp;\u23BF &nbsp;</Text>\n <Box flexDirection=\"row\" flexGrow={1}>\n <Text\n color={textColor}\n bold={isBold}\n strikethrough={isStrikethrough}\n >\n {checkbox}\n </Text>\n <Text> </Text>\n <Text\n color={textColor}\n bold={isBold}\n strikethrough={isStrikethrough}\n >\n {todo.content}\n </Text>\n </Box>\n </Box>\n )\n })}\n </Box>\n )\n }\n\n // Fallback to simple text rendering for errors or string output\n return (\n <Box justifyContent=\"space-between\" overflowX=\"hidden\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text color={isError ? getTheme().error : getTheme().success}>\n &nbsp;&nbsp;\u23BF &nbsp;\n {typeof output === 'string' ? output : JSON.stringify(output)}\n </Text>\n </Box>\n </Box>\n )\n },\n async validateInput({ todos }: z.infer<typeof inputSchema>) {\n // Type assertion to ensure todos match TodoItem[] interface\n const todoItems = todos as TodoItem[]\n const validation = validateTodos(todoItems)\n if (!validation.result) {\n return validation\n }\n return { result: true }\n },\n async *call({ todos }: z.infer<typeof inputSchema>, context) {\n try {\n // Get agent ID from context\n const agentId = context?.agentId\n\n // Start watching todo file for this agent if not already watching\n if (agentId) {\n startWatchingTodoFile(agentId)\n }\n\n // Store previous todos for comparison (agent-scoped)\n const previousTodos = getTodos(agentId)\n\n // Type assertion to ensure todos match TodoItem[] interface\n // Auto-generate activeForm for todos that don't have it\n const todoItems = todos.map(todo => ({\n ...todo,\n activeForm: todo.activeForm || generateActiveForm(todo.content),\n })) as TodoItem[]\n\n // Note: Validation already done in validateInput, no need for duplicate validation\n // This eliminates the double validation issue\n\n // Update the todos in storage (agent-scoped)\n setTodos(todoItems, agentId)\n\n // Emit todo change event for system reminders (optimized - only if todos actually changed)\n const hasChanged =\n JSON.stringify(previousTodos) !== JSON.stringify(todoItems)\n if (hasChanged) {\n emitReminderEvent('todo:changed', {\n previousTodos,\n newTodos: todoItems,\n timestamp: Date.now(),\n agentId: agentId || 'default',\n changeType:\n todoItems.length > previousTodos.length\n ? 'added'\n : todoItems.length < previousTodos.length\n ? 'removed'\n : 'modified',\n })\n }\n\n // Generate enhanced summary\n const summary = generateTodoSummary(todoItems)\n\n // Enhanced result data for rendering\n const resultData = {\n oldTodos: previousTodos,\n newTodos: todoItems,\n summary,\n }\n\n yield {\n type: 'result',\n data: summary, // Return string to satisfy interface\n resultForAssistant: summary,\n // Store todo data in a way accessible to the renderer\n // We'll modify the renderToolResultMessage to get todos from storage\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'Unknown error occurred'\n const errorResult = `Error updating todos: ${errorMessage}`\n\n // Emit error event for system monitoring\n emitReminderEvent('todo:error', {\n error: errorMessage,\n timestamp: Date.now(),\n agentId: context?.agentId || 'default',\n context: 'TodoWriteTool.call',\n })\n\n yield {\n type: 'result',\n data: errorResult,\n resultForAssistant: errorResult,\n }\n }\n },\n} satisfies Tool<typeof inputSchema, string>\n"],
5
+ "mappings": "AAAA,SAAS,KAAK,YAAY;AAC1B,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAG/C,SAAS,UAAU,gBAA0B;AAC7C,SAAS,yBAAyB;AAClC,SAAS,6BAA6B;AACtC,SAAS,aAAa,cAAc;AACpC,SAAS,gBAAgB;AAEzB,MAAM,iBAAiB,EAAE,OAAO;AAAA,EAC9B,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,iCAAiC;AAAA,EACrE,YAAY,EACT,OAAO,EACP,IAAI,CAAC,EACL,SAAS,EACT;AAAA,IACC;AAAA,EACF;AAAA,EACF,QAAQ,EACL,KAAK,CAAC,WAAW,eAAe,WAAW,CAAC,EAC5C,SAAS,4BAA4B;AAAA,EACxC,UAAU,EACP,KAAK,CAAC,QAAQ,UAAU,KAAK,CAAC,EAC9B,SAAS,4BAA4B;AAAA,EACxC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,gCAAgC;AACjE,CAAC;AAED,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,OAAO,EAAE,MAAM,cAAc,EAAE,SAAS,uBAAuB;AACjE,CAAC;AAOD,SAAS,mBAAmB,SAAyB;AACnD,QAAM,UAAU,QAAQ,KAAK;AAG7B,QAAM,WAAW;AAAA,IACf,EAAE,OAAO,uBAAuB,aAAa,aAAa;AAAA,IAC1D,EAAE,OAAO,2BAA2B,aAAa,cAAc;AAAA,IAC/D,EAAE,OAAO,uBAAuB,aAAa,YAAY;AAAA,IACzD,EAAE,OAAO,uBAAuB,aAAa,YAAY;AAAA,IACzD,EAAE,OAAO,6BAA6B,aAAa,cAAc;AAAA,IACjE,EA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ACN,MAAM;AAAA,QACN,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -43,6 +43,9 @@ const URLFetcherTool = {
43
43
  return /* @__PURE__ */ React.createElement(FallbackToolUseRejectedMessage, null);
44
44
  },
45
45
  renderToolResultMessage(output) {
46
+ if (!output) {
47
+ return /* @__PURE__ */ React.createElement(Box, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\u23BF \xA0URL fetch completed")));
48
+ }
46
49
  const statusText = output.fromCache ? "from cache" : "fetched";
47
50
  return /* @__PURE__ */ React.createElement(Box, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\u23BF \xA0Content "), /* @__PURE__ */ React.createElement(Text, { bold: true }, statusText, " "), /* @__PURE__ */ React.createElement(Text, null, "and analyzed")), /* @__PURE__ */ React.createElement(Cost, { costUSD: 0, durationMs: 0, debug: false }));
48
51
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/tools/URLFetcherTool/URLFetcherTool.tsx"],
4
- "sourcesContent": ["import { Box, Text } from 'ink'\nimport React from 'react'\nimport { z } from 'zod'\nimport fetch from 'node-fetch'\nimport { Cost } from '@components/Cost'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool, ToolUseContext } from '@tool'\nimport { DESCRIPTION, TOOL_NAME_FOR_PROMPT } from './prompt'\nimport { convertHtmlToMarkdown } from './htmlToMarkdown'\nimport { urlCache } from './cache'\nimport { queryQuick } from '@services/claude'\n\nconst inputSchema = z.strictObject({\n url: z.string().url().describe('The URL to fetch content from'),\n prompt: z.string().describe('The prompt to run on the fetched content'),\n})\n\ntype Input = z.infer<typeof inputSchema>\ntype Output = {\n url: string\n fromCache: boolean\n aiAnalysis: string\n}\n\nfunction normalizeUrl(url: string): string {\n // Auto-upgrade HTTP to HTTPS\n if (url.startsWith('http://')) {\n return url.replace('http://', 'https://')\n }\n return url\n}\n\nexport const URLFetcherTool = {\n name: TOOL_NAME_FOR_PROMPT,\n async description() {\n return DESCRIPTION\n },\n userFacingName: () => 'URL Fetcher',\n inputSchema,\n isReadOnly: () => true,\n isConcurrencySafe: () => true,\n async isEnabled() {\n return true\n },\n needsPermissions() {\n return false\n },\n async prompt() {\n return DESCRIPTION\n },\n renderToolUseMessage({ url, prompt }: Input) {\n return `Fetching content from ${url} and analyzing with prompt: \"${prompt}\"`\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(output: Output) {\n const statusText = output.fromCache ? 'from cache' : 'fetched'\n\n return (\n <Box justifyContent=\"space-between\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text>&nbsp;&nbsp;\u23BF &nbsp;Content </Text>\n <Text bold>{statusText} </Text>\n <Text>and analyzed</Text>\n </Box>\n <Cost costUSD={0} durationMs={0} debug={false} />\n </Box>\n )\n },\n renderResultForAssistant(output: Output) {\n if (!output.aiAnalysis.trim()) {\n return `No content could be analyzed from URL: ${output.url}`\n }\n\n return output.aiAnalysis\n },\n async *call({ url, prompt }: Input, {}: ToolUseContext) {\n const normalizedUrl = normalizeUrl(url)\n\n try {\n let content: string\n let fromCache = false\n\n // Check cache first\n const cachedContent = urlCache.get(normalizedUrl)\n if (cachedContent) {\n content = cachedContent\n fromCache = true\n } else {\n // Fetch from URL with AbortController for timeout\n const abortController = new AbortController()\n const timeout = setTimeout(() => abortController.abort(), 30000)\n\n const response = await fetch(normalizedUrl, {\n method: 'GET',\n headers: {\n 'User-Agent': 'Mozilla/5.0 (compatible; URLFetcher/1.0)',\n Accept:\n 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'Accept-Language': 'en-US,en;q=0.5',\n 'Accept-Encoding': 'gzip, deflate',\n Connection: 'keep-alive',\n 'Upgrade-Insecure-Requests': '1',\n },\n signal: abortController.signal,\n redirect: 'follow',\n })\n\n clearTimeout(timeout)\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`)\n }\n\n const contentType = response.headers.get('content-type') || ''\n if (\n !contentType.includes('text/') &&\n !contentType.includes('application/')\n ) {\n throw new Error(`Unsupported content type: ${contentType}`)\n }\n\n const html = await response.text()\n content = convertHtmlToMarkdown(html)\n\n // Cache the result\n urlCache.set(normalizedUrl, content)\n fromCache = false\n }\n\n // Truncate content if too large (keep within reasonable token limits)\n const maxContentLength = 50000 // ~15k tokens approximately\n const truncatedContent =\n content.length > maxContentLength\n ? content.substring(0, maxContentLength) +\n '\\n\\n[Content truncated due to length]'\n : content\n\n // AI Analysis - always performed fresh, even with cached content\n const systemPrompt = [\n \"You are analyzing web content based on a user's specific request.\",\n 'The content has been extracted from a webpage and converted to markdown.',\n \"Provide a focused response that directly addresses the user's prompt.\",\n ]\n\n const userPrompt = `Here is the content from ${normalizedUrl}:\n\n${truncatedContent}\n\nUser request: ${prompt}`\n\n const aiResponse = await queryQuick({\n systemPrompt,\n userPrompt,\n enablePromptCaching: false,\n })\n\n const output: Output = {\n url: normalizedUrl,\n fromCache,\n aiAnalysis:\n aiResponse.message.content[0]?.text || 'Unable to analyze content',\n }\n\n yield {\n type: 'result' as const,\n resultForAssistant: this.renderResultForAssistant(output),\n data: output,\n }\n } catch (error: any) {\n const output: Output = {\n url: normalizedUrl,\n fromCache: false,\n aiAnalysis: '',\n }\n\n yield {\n type: 'result' as const,\n resultForAssistant: `Error processing URL ${normalizedUrl}: ${error.message}`,\n data: output,\n }\n }\n },\n} satisfies Tool<typeof inputSchema, Output>\n"],
5
- "mappings": "AAAA,SAAS,KAAK,YAAY;AAC1B,OAAO,WAAW;AAClB,SAAS,SAAS;AAClB,OAAO,WAAW;AAClB,SAAS,YAAY;AACrB,SAAS,sCAAsC;AAE/C,SAAS,aAA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,YAAM,aAAa,4BAA4B,aAAa;AAAA;AAAA,EAEhE,gBAAgB;AAAA;AAAA,gBAEF,MAAM;AAEhB,YAAM,aAAa,MAAM,WAAW;AAAA,QAClC;AAAA,QACA;AAAA,QACA,qBAAqB;AAAA,MACvB,CAAC;AAED,YAAM,SAAiB;AAAA,QACrB,KAAK;AAAA,QACL;AAAA,QACA,YACE,WAAW,QAAQ,QAAQ,CAAC,GAAG,QAAQ;AAAA,MAC3C;AAEA,YAAM;AAAA,QACJ,MAAM;AAAA,QACN,oBAAoB,KAAK,yBAAyB,MAAM;AAAA,QACxD,MAAM;AAAA,MACR;AAAA,IACF,SAAS,OAAY;AACnB,YAAM,SAAiB;AAAA,QACrB,KAAK;AAAA,QACL,WAAW;AAAA,QACX,YAAY;AAAA,MACd;AAEA,YAAM;AAAA,QACJ,MAAM;AAAA,QACN,oBAAoB,wBAAwB,aAAa,KAAK,MAAM,OAAO;AAAA,QAC3E,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { Box, Text } from 'ink'\nimport React from 'react'\nimport { z } from 'zod'\nimport fetch from 'node-fetch'\nimport { Cost } from '@components/Cost'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool, ToolUseContext } from '@tool'\nimport { DESCRIPTION, TOOL_NAME_FOR_PROMPT } from './prompt'\nimport { convertHtmlToMarkdown } from './htmlToMarkdown'\nimport { urlCache } from './cache'\nimport { queryQuick } from '@services/claude'\n\nconst inputSchema = z.strictObject({\n url: z.string().url().describe('The URL to fetch content from'),\n prompt: z.string().describe('The prompt to run on the fetched content'),\n})\n\ntype Input = z.infer<typeof inputSchema>\ntype Output = {\n url: string\n fromCache: boolean\n aiAnalysis: string\n}\n\nfunction normalizeUrl(url: string): string {\n // Auto-upgrade HTTP to HTTPS\n if (url.startsWith('http://')) {\n return url.replace('http://', 'https://')\n }\n return url\n}\n\nexport const URLFetcherTool = {\n name: TOOL_NAME_FOR_PROMPT,\n async description() {\n return DESCRIPTION\n },\n userFacingName: () => 'URL Fetcher',\n inputSchema,\n isReadOnly: () => true,\n isConcurrencySafe: () => true,\n async isEnabled() {\n return true\n },\n needsPermissions() {\n return false\n },\n async prompt() {\n return DESCRIPTION\n },\n renderToolUseMessage({ url, prompt }: Input) {\n return `Fetching content from ${url} and analyzing with prompt: \"${prompt}\"`\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(output: Output) {\n // Guard against undefined or null output\n if (!output) {\n return (\n <Box justifyContent=\"space-between\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text>&nbsp;&nbsp;\u23BF &nbsp;URL fetch completed</Text>\n </Box>\n </Box>\n )\n }\n\n const statusText = output.fromCache ? 'from cache' : 'fetched'\n\n return (\n <Box justifyContent=\"space-between\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text>&nbsp;&nbsp;\u23BF &nbsp;Content </Text>\n <Text bold>{statusText} </Text>\n <Text>and analyzed</Text>\n </Box>\n <Cost costUSD={0} durationMs={0} debug={false} />\n </Box>\n )\n },\n renderResultForAssistant(output: Output) {\n if (!output.aiAnalysis.trim()) {\n return `No content could be analyzed from URL: ${output.url}`\n }\n\n return output.aiAnalysis\n },\n async *call({ url, prompt }: Input, {}: ToolUseContext) {\n const normalizedUrl = normalizeUrl(url)\n\n try {\n let content: string\n let fromCache = false\n\n // Check cache first\n const cachedContent = urlCache.get(normalizedUrl)\n if (cachedContent) {\n content = cachedContent\n fromCache = true\n } else {\n // Fetch from URL with AbortController for timeout\n const abortController = new AbortController()\n const timeout = setTimeout(() => abortController.abort(), 30000)\n\n const response = await fetch(normalizedUrl, {\n method: 'GET',\n headers: {\n 'User-Agent': 'Mozilla/5.0 (compatible; URLFetcher/1.0)',\n Accept:\n 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'Accept-Language': 'en-US,en;q=0.5',\n 'Accept-Encoding': 'gzip, deflate',\n Connection: 'keep-alive',\n 'Upgrade-Insecure-Requests': '1',\n },\n signal: abortController.signal,\n redirect: 'follow',\n })\n\n clearTimeout(timeout)\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`)\n }\n\n const contentType = response.headers.get('content-type') || ''\n if (\n !contentType.includes('text/') &&\n !contentType.includes('application/')\n ) {\n throw new Error(`Unsupported content type: ${contentType}`)\n }\n\n const html = await response.text()\n content = convertHtmlToMarkdown(html)\n\n // Cache the result\n urlCache.set(normalizedUrl, content)\n fromCache = false\n }\n\n // Truncate content if too large (keep within reasonable token limits)\n const maxContentLength = 50000 // ~15k tokens approximately\n const truncatedContent =\n content.length > maxContentLength\n ? content.substring(0, maxContentLength) +\n '\\n\\n[Content truncated due to length]'\n : content\n\n // AI Analysis - always performed fresh, even with cached content\n const systemPrompt = [\n \"You are analyzing web content based on a user's specific request.\",\n 'The content has been extracted from a webpage and converted to markdown.',\n \"Provide a focused response that directly addresses the user's prompt.\",\n ]\n\n const userPrompt = `Here is the content from ${normalizedUrl}:\n\n${truncatedContent}\n\nUser request: ${prompt}`\n\n const aiResponse = await queryQuick({\n systemPrompt,\n userPrompt,\n enablePromptCaching: false,\n })\n\n const output: Output = {\n url: normalizedUrl,\n fromCache,\n aiAnalysis:\n aiResponse.message.content[0]?.text || 'Unable to analyze content',\n }\n\n yield {\n type: 'result' as const,\n resultForAssistant: this.renderResultForAssistant(output),\n data: output,\n }\n } catch (error: any) {\n const output: Output = {\n url: normalizedUrl,\n fromCache: false,\n aiAnalysis: '',\n }\n\n yield {\n type: 'result' as const,\n resultForAssistant: `Error processing URL ${normalizedUrl}: ${error.message}`,\n data: output,\n }\n }\n },\n} satisfies Tool<typeof inputSchema, Output>\n"],
5
+ "mappings": "AAAA,SAAS,KAAK,YAAY;AAC1B,OAAO,WAAW;AAClB,SAAS,SAAS;AAClB,OAAO,WAAW;AAClB,SAAS,YAAY;AACrB,SAAS,sCAAsC;AAE/C,SAAS,aAAa,4BAA4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