@astralyn/pi 0.82.3 → 0.82.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/cli/config-selector.d.ts.map +1 -1
  3. package/dist/cli/config-selector.js +3 -2
  4. package/dist/cli/config-selector.js.map +1 -1
  5. package/dist/cli/startup-ui.d.ts.map +1 -1
  6. package/dist/cli/startup-ui.js +3 -2
  7. package/dist/cli/startup-ui.js.map +1 -1
  8. package/dist/core/agent-session.d.ts +2 -0
  9. package/dist/core/agent-session.d.ts.map +1 -1
  10. package/dist/core/agent-session.js +33 -14
  11. package/dist/core/agent-session.js.map +1 -1
  12. package/dist/core/extensions/index.d.ts +2 -2
  13. package/dist/core/extensions/index.d.ts.map +1 -1
  14. package/dist/core/extensions/index.js +1 -1
  15. package/dist/core/extensions/index.js.map +1 -1
  16. package/dist/core/extensions/loader.d.ts +1 -1
  17. package/dist/core/extensions/loader.d.ts.map +1 -1
  18. package/dist/core/extensions/loader.js +2 -3
  19. package/dist/core/extensions/loader.js.map +1 -1
  20. package/dist/core/extensions/types.d.ts +18 -0
  21. package/dist/core/extensions/types.d.ts.map +1 -1
  22. package/dist/core/extensions/types.js +11 -0
  23. package/dist/core/extensions/types.js.map +1 -1
  24. package/dist/extensions/index.d.ts.map +1 -1
  25. package/dist/extensions/index.js +2 -0
  26. package/dist/extensions/index.js.map +1 -1
  27. package/dist/extensions/plan/constants.d.ts +31 -0
  28. package/dist/extensions/plan/constants.d.ts.map +1 -0
  29. package/dist/extensions/plan/constants.js +57 -0
  30. package/dist/extensions/plan/constants.js.map +1 -0
  31. package/dist/extensions/plan/index.d.ts +21 -0
  32. package/dist/extensions/plan/index.d.ts.map +1 -0
  33. package/dist/extensions/plan/index.js +291 -0
  34. package/dist/extensions/plan/index.js.map +1 -0
  35. package/dist/extensions/plan/schema.d.ts +15 -0
  36. package/dist/extensions/plan/schema.d.ts.map +1 -0
  37. package/dist/extensions/plan/schema.js +13 -0
  38. package/dist/extensions/plan/schema.js.map +1 -0
  39. package/dist/extensions/plan/state.d.ts +29 -0
  40. package/dist/extensions/plan/state.d.ts.map +1 -0
  41. package/dist/extensions/plan/state.js +74 -0
  42. package/dist/extensions/plan/state.js.map +1 -0
  43. package/dist/extensions/plan/storage.d.ts +18 -0
  44. package/dist/extensions/plan/storage.d.ts.map +1 -0
  45. package/dist/extensions/plan/storage.js +58 -0
  46. package/dist/extensions/plan/storage.js.map +1 -0
  47. package/dist/extensions/question/dialog.d.ts +3 -1
  48. package/dist/extensions/question/dialog.d.ts.map +1 -1
  49. package/dist/extensions/question/dialog.js +106 -52
  50. package/dist/extensions/question/dialog.js.map +1 -1
  51. package/dist/extensions/question/index.d.ts.map +1 -1
  52. package/dist/extensions/question/index.js +2 -2
  53. package/dist/extensions/question/index.js.map +1 -1
  54. package/dist/extensions/question/render-cache.d.ts +9 -0
  55. package/dist/extensions/question/render-cache.d.ts.map +1 -1
  56. package/dist/extensions/question/render-cache.js +22 -0
  57. package/dist/extensions/question/render-cache.js.map +1 -1
  58. package/dist/extensions/question/results.d.ts.map +1 -1
  59. package/dist/extensions/question/results.js +6 -1
  60. package/dist/extensions/question/results.js.map +1 -1
  61. package/dist/extensions/question/schema.d.ts +4 -0
  62. package/dist/extensions/question/schema.d.ts.map +1 -1
  63. package/dist/extensions/question/schema.js +19 -28
  64. package/dist/extensions/question/schema.js.map +1 -1
  65. package/dist/extensions/question/types.d.ts +1 -1
  66. package/dist/extensions/question/types.d.ts.map +1 -1
  67. package/dist/extensions/question/types.js.map +1 -1
  68. package/dist/extensions/rewind/anchor.d.ts +29 -0
  69. package/dist/extensions/rewind/anchor.d.ts.map +1 -0
  70. package/dist/extensions/rewind/anchor.js +35 -0
  71. package/dist/extensions/rewind/anchor.js.map +1 -0
  72. package/dist/extensions/rewind/engine.d.ts +2 -6
  73. package/dist/extensions/rewind/engine.d.ts.map +1 -1
  74. package/dist/extensions/rewind/engine.js +41 -10
  75. package/dist/extensions/rewind/engine.js.map +1 -1
  76. package/dist/extensions/rewind/index.d.ts.map +1 -1
  77. package/dist/extensions/rewind/index.js +55 -21
  78. package/dist/extensions/rewind/index.js.map +1 -1
  79. package/dist/extensions/rewind/menu.d.ts.map +1 -1
  80. package/dist/extensions/rewind/menu.js +7 -2
  81. package/dist/extensions/rewind/menu.js.map +1 -1
  82. package/dist/extensions/rewind/restore.d.ts +26 -9
  83. package/dist/extensions/rewind/restore.d.ts.map +1 -1
  84. package/dist/extensions/rewind/restore.js +58 -16
  85. package/dist/extensions/rewind/restore.js.map +1 -1
  86. package/dist/extensions/subagent/activity.d.ts +1 -0
  87. package/dist/extensions/subagent/activity.d.ts.map +1 -1
  88. package/dist/extensions/subagent/activity.js +20 -4
  89. package/dist/extensions/subagent/activity.js.map +1 -1
  90. package/dist/extensions/subagent/agents.d.ts.map +1 -1
  91. package/dist/extensions/subagent/agents.js +13 -18
  92. package/dist/extensions/subagent/agents.js.map +1 -1
  93. package/dist/extensions/subagent/constants.d.ts +5 -4
  94. package/dist/extensions/subagent/constants.d.ts.map +1 -1
  95. package/dist/extensions/subagent/constants.js +12 -5
  96. package/dist/extensions/subagent/constants.js.map +1 -1
  97. package/dist/extensions/subagent/index.d.ts.map +1 -1
  98. package/dist/extensions/subagent/index.js +12 -5
  99. package/dist/extensions/subagent/index.js.map +1 -1
  100. package/dist/extensions/subagent/render.d.ts.map +1 -1
  101. package/dist/extensions/subagent/render.js +166 -41
  102. package/dist/extensions/subagent/render.js.map +1 -1
  103. package/dist/extensions/subagent/resolve.d.ts +2 -5
  104. package/dist/extensions/subagent/resolve.d.ts.map +1 -1
  105. package/dist/extensions/subagent/resolve.js +8 -13
  106. package/dist/extensions/subagent/resolve.js.map +1 -1
  107. package/dist/extensions/subagent/runner.d.ts +3 -1
  108. package/dist/extensions/subagent/runner.d.ts.map +1 -1
  109. package/dist/extensions/subagent/runner.js +115 -66
  110. package/dist/extensions/subagent/runner.js.map +1 -1
  111. package/dist/extensions/subagent/schema.d.ts +0 -6
  112. package/dist/extensions/subagent/schema.d.ts.map +1 -1
  113. package/dist/extensions/subagent/schema.js +3 -4
  114. package/dist/extensions/subagent/schema.js.map +1 -1
  115. package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
  116. package/dist/extensions/subagent/sdk-runner.js +37 -16
  117. package/dist/extensions/subagent/sdk-runner.js.map +1 -1
  118. package/dist/extensions/subagent/types.d.ts +10 -2
  119. package/dist/extensions/subagent/types.d.ts.map +1 -1
  120. package/dist/extensions/subagent/types.js.map +1 -1
  121. package/dist/extensions/todo/constants.d.ts +1 -1
  122. package/dist/extensions/todo/constants.d.ts.map +1 -1
  123. package/dist/extensions/todo/constants.js +29 -4
  124. package/dist/extensions/todo/constants.js.map +1 -1
  125. package/dist/extensions/todo/index.d.ts +1 -1
  126. package/dist/extensions/todo/index.d.ts.map +1 -1
  127. package/dist/extensions/todo/index.js +22 -3
  128. package/dist/extensions/todo/index.js.map +1 -1
  129. package/dist/extensions/todo/schema.d.ts +6 -5
  130. package/dist/extensions/todo/schema.d.ts.map +1 -1
  131. package/dist/extensions/todo/schema.js +20 -9
  132. package/dist/extensions/todo/schema.js.map +1 -1
  133. package/dist/extensions/todo/state.d.ts +5 -1
  134. package/dist/extensions/todo/state.d.ts.map +1 -1
  135. package/dist/extensions/todo/state.js +184 -38
  136. package/dist/extensions/todo/state.js.map +1 -1
  137. package/dist/extensions/todo/view.d.ts.map +1 -1
  138. package/dist/extensions/todo/view.js +10 -6
  139. package/dist/extensions/todo/view.js.map +1 -1
  140. package/dist/modes/interactive/interactive-mode.d.ts +2 -0
  141. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  142. package/dist/modes/interactive/interactive-mode.js +36 -2
  143. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  144. package/dist/utils/coalescing-terminal.d.ts +116 -0
  145. package/dist/utils/coalescing-terminal.d.ts.map +1 -0
  146. package/dist/utils/coalescing-terminal.js +256 -0
  147. package/dist/utils/coalescing-terminal.js.map +1 -0
  148. package/docs/bundled/extensions/README.md +1 -0
  149. package/docs/bundled/extensions/plan.md +31 -0
  150. package/docs/bundled/extensions/question.md +9 -7
  151. package/docs/bundled/extensions/rewind.md +19 -8
  152. package/docs/bundled/extensions/subagent.md +16 -16
  153. package/docs/bundled/extensions/todo.md +5 -3
  154. package/docs/compaction.md +6 -2
  155. package/docs/docs.json +4 -0
  156. package/docs/extensions.md +4 -2
  157. package/npm-shrinkwrap.json +2 -2
  158. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/agents.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAoC,oBAAoB,EAAe,MAAM,YAAY,CAAC;AAoJtG,wBAAgB,cAAc,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD,oBAAoB,CAiBtB;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,CAkD/E","sourcesContent":["import { type Dirent, existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../config.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS } from \"./constants.ts\";\nimport type { AgentDefinition, AgentDiagnostic, AgentDiscoveryResult, AgentSource } from \"./types.ts\";\n\nconst AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,79}$/u;\nconst BUILTIN_TOOL_SET = new Set<string>(BUILTIN_TOOL_NAMES);\nconst TOOL_DESCRIPTION_AGENT_LIST_LIMIT = 8_000;\nconst TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT = 480;\n\nfunction utf8Prefix(text: string, maxBytes: number): string {\n\tlet output = \"\";\n\tlet bytes = 0;\n\tfor (const character of text) {\n\t\tconst characterBytes = Buffer.byteLength(character, \"utf8\");\n\t\tif (bytes + characterBytes > maxBytes) break;\n\t\toutput += character;\n\t\tbytes += characterBytes;\n\t}\n\treturn output;\n}\n\nconst BUILTIN_AGENTS: AgentDefinition[] = [\n\t{\n\t\tname: \"general\",\n\t\tdescription: \"General-purpose implementation agent with coding tools\",\n\t\ttools: [...DEFAULT_AGENT_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"Work independently on the delegated task from start to finish.\",\n\t\t\t\"Inspect relevant repository instructions before changing files.\",\n\t\t\t\"Prefer editing existing files; never create documentation files unless the task explicitly asks for them.\",\n\t\t\t\"Keep changes focused, run appropriate verification, and report exact paths, checks, blockers, and remaining risks.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:general>\",\n\t\tbackend: \"sdk\",\n\t},\n\t{\n\t\tname: \"explorer\",\n\t\tdescription:\n\t\t\t'Fast read-only agent for finding files, searching code, and answering codebase questions. State thoroughness in the prompt: \"quick\" for a targeted lookup, \"medium\" for checking likely related locations, or \"very thorough\" for exhaustive sweeps across locations and naming conventions',\n\t\ttools: [...EXPLORER_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"You are a fast read-only exploration agent; return findings as quickly as possible.\",\n\t\t\t\"Explore the delegated question without modifying files.\",\n\t\t\t\"Use read and search tools to gather exact evidence, batching independent searches and reads instead of running them one at a time.\",\n\t\t\t\"Match the depth the caller requested: quick targets the direct question, medium checks likely related locations, and very thorough sweeps multiple locations and naming conventions.\",\n\t\t\t\"Return concise findings with precise paths, symbols, relationships, and unresolved uncertainties.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:explorer>\",\n\t\tbackend: \"sdk\",\n\t},\n];\n\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findNearestProjectAgentsDir(cwd: string): string | undefined {\n\tlet current = cwd;\n\twhile (true) {\n\t\tconst candidate = join(current, CONFIG_DIR_NAME, \"agents\");\n\t\tif (isDirectory(candidate)) return candidate;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\nfunction parseTools(raw: string | undefined, filePath: string): string[] {\n\tif (!raw?.trim()) return [...DEFAULT_AGENT_TOOLS];\n\tconst tools = [\n\t\t...new Set(\n\t\t\traw\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((tool) => tool.trim())\n\t\t\t\t.filter(Boolean),\n\t\t),\n\t];\n\tconst unsupported = tools.filter((tool) => !BUILTIN_TOOL_SET.has(tool));\n\tif (unsupported.length > 0) {\n\t\tthrow new Error(`Unsupported tool(s) ${unsupported.join(\", \")} in ${filePath}.`);\n\t}\n\treturn tools;\n}\n\n// Frontmatter model/thinking keys are intentionally ignored: agent files\n// travel across machines (project repos), so a pinned model rarely exists\n// in the reader's environment. Model and thinking come from /agents\n// overrides or default to the parent session.\nfunction parseAgentFile(filePath: string, source: Exclude<AgentSource, \"builtin\">): AgentDefinition {\n\tconst content = readFileSync(filePath, \"utf8\");\n\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(content);\n\tconst name = frontmatter.name?.trim() ?? \"\";\n\tconst description = frontmatter.description?.trim() ?? \"\";\n\tif (!name) throw new Error(\"Missing required frontmatter field: name.\");\n\tif (!AGENT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(`Agent name \"${name}\" must use lowercase letters, digits, hyphens, or underscores.`);\n\t}\n\tif (!description) throw new Error(\"Missing required frontmatter field: description.\");\n\tif (!body.trim()) throw new Error(\"Agent prompt body must not be empty.\");\n\tconst backend = frontmatter.backend?.trim();\n\tif (backend && backend !== \"sdk\") throw new Error(`Backend \"${backend}\" is not implemented; use \"sdk\".`);\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\ttools: parseTools(frontmatter.tools, filePath),\n\t\tsystemPrompt: body.trim(),\n\t\tsource,\n\t\tfilePath,\n\t\tbackend: \"sdk\",\n\t};\n}\n\nfunction loadAgentDirectory(\n\tdir: string,\n\tsource: Exclude<AgentSource, \"builtin\">,\n): { agents: AgentDefinition[]; diagnostics: AgentDiagnostic[] } {\n\tif (!existsSync(dir)) return { agents: [], diagnostics: [] };\n\tlet entries: Dirent[];\n\ttry {\n\t\tentries = readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));\n\t} catch (error) {\n\t\treturn {\n\t\t\tagents: [],\n\t\t\tdiagnostics: [{ path: dir, source, message: error instanceof Error ? error.message : String(error) }],\n\t\t};\n\t}\n\tconst agents: AgentDefinition[] = [];\n\tconst diagnostics: AgentDiagnostic[] = [];\n\tfor (const entry of entries) {\n\t\tif (!entry.name.endsWith(\".md\") || (!entry.isFile() && !entry.isSymbolicLink())) continue;\n\t\tconst filePath = join(dir, entry.name);\n\t\ttry {\n\t\t\tagents.push(parseAgentFile(filePath, source));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpath: filePath,\n\t\t\t\tsource,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t}\n\t}\n\treturn { agents, diagnostics };\n}\n\nexport function discoverAgents(\n\tcwd: string,\n\toptions: { projectTrusted: boolean; agentDir?: string },\n): AgentDiscoveryResult {\n\tconst userDir = join(options.agentDir ?? getAgentDir(), \"agents\");\n\tconst projectAgentsDir = findNearestProjectAgentsDir(cwd);\n\tconst user = loadAgentDirectory(userDir, \"user\");\n\tconst project =\n\t\toptions.projectTrusted && projectAgentsDir\n\t\t\t? loadAgentDirectory(projectAgentsDir, \"project\")\n\t\t\t: { agents: [], diagnostics: [] };\n\tconst agents = new Map(BUILTIN_AGENTS.map((agent) => [agent.name, { ...agent, tools: [...agent.tools] }]));\n\tfor (const agent of user.agents) agents.set(agent.name, agent);\n\tfor (const agent of project.agents) agents.set(agent.name, agent);\n\treturn {\n\t\tagents: [...agents.values()],\n\t\tdiagnostics: [...user.diagnostics, ...project.diagnostics],\n\t\tprojectAgentsDir,\n\t\tprojectAgentsTrusted: options.projectTrusted,\n\t};\n}\n\nexport function subagentToolDescription(discovery: AgentDiscoveryResult): string {\n\tconst agentLines: string[] = [];\n\tlet agentListLength = 0;\n\tfor (const [index, agent] of discovery.agents.entries()) {\n\t\tconst normalizedDescription = agent.description.replace(/\\s+/gu, \" \").trim();\n\t\tconst description =\n\t\t\tBuffer.byteLength(normalizedDescription, \"utf8\") <= TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT\n\t\t\t\t? normalizedDescription\n\t\t\t\t: `${utf8Prefix(normalizedDescription, TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT - Buffer.byteLength(\"…\", \"utf8\"))}…`;\n\t\tconst defaultLabel = agent.name === \"general\" ? \" (default)\" : \"\";\n\t\tconst tools = agent.tools.length > 0 ? agent.tools.join(\", \") : \"none\";\n\t\tconst line = `- ${agent.name}${defaultLabel}: ${description} (Tools: ${tools})`;\n\t\tconst lineLength = Buffer.byteLength(line, \"utf8\") + 1;\n\t\tif (agentListLength + lineLength > TOOL_DESCRIPTION_AGENT_LIST_LIMIT) {\n\t\t\tlet omitted = discovery.agents.length - index;\n\t\t\tlet notice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\twhile (\n\t\t\t\tagentLines.length > 0 &&\n\t\t\t\tagentListLength + Buffer.byteLength(notice, \"utf8\") + 1 > TOOL_DESCRIPTION_AGENT_LIST_LIMIT\n\t\t\t) {\n\t\t\t\tconst removed = agentLines.pop();\n\t\t\t\tif (!removed) break;\n\t\t\t\tagentListLength -= Buffer.byteLength(removed, \"utf8\") + 1;\n\t\t\t\tomitted++;\n\t\t\t\tnotice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\t}\n\t\t\tagentLines.push(notice);\n\t\t\tbreak;\n\t\t}\n\t\tagentLines.push(line);\n\t\tagentListLength += lineLength;\n\t}\n\n\treturn [\n\t\t\"Delegate bounded work to isolated one-shot subagents. Choose exactly one mode: prompt for one task, tasks for independent parallel work, or chain for sequential work whose later prompts may include {previous}.\",\n\t\t\"\",\n\t\t\"Available agent profiles:\",\n\t\t...agentLines,\n\t\t\"\",\n\t\t\"When not to delegate:\",\n\t\t\"- Read a known file directly with read, or search for a known symbol directly with grep.\",\n\t\t\"- Do not delegate a trivial task when the coordination overhead exceeds the work.\",\n\t\t\"\",\n\t\t\"Writing the briefing:\",\n\t\t\"- Brief the worker like a capable colleague entering the project now: include the objective, relevant context, exact paths or symbols already known, constraints, and expected output.\",\n\t\t\"- Never delegate understanding with vague instructions such as 'fix this based on your findings'; state what must be investigated or changed and whether the worker should research, implement, or review.\",\n\t\t\"- Ask for a concise report when only findings are needed. Workers cannot see the parent conversation or ask the end user questions.\",\n\t\t\"\",\n\t\t\"Subagent results are reports for you to interpret and relay. Surface the important findings, changes, verification, and unresolved risks to the user.\",\n\t].join(\"\\n\");\n}\n"]}
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/agents.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAoC,oBAAoB,EAAe,MAAM,YAAY,CAAC;AA4ItG,wBAAgB,cAAc,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD,oBAAoB,CAiBtB;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,CAqD/E","sourcesContent":["import { type Dirent, existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../config.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { utf8Prefix } from \"./activity.ts\";\nimport { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS, MAX_CONCURRENCY, MAX_TASKS } from \"./constants.ts\";\nimport type { AgentDefinition, AgentDiagnostic, AgentDiscoveryResult, AgentSource } from \"./types.ts\";\n\nconst AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,79}$/u;\nconst BUILTIN_TOOL_SET = new Set<string>(BUILTIN_TOOL_NAMES);\nconst TOOL_DESCRIPTION_AGENT_LIST_LIMIT = 8_000;\nconst TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT = 480;\n\nconst BUILTIN_AGENTS: AgentDefinition[] = [\n\t{\n\t\tname: \"general\",\n\t\tdescription:\n\t\t\t\"Implementation agent for bounded coding tasks: edits, fixes, refactors, and verification in a scoped area. Use when the task changes files; use explorer for read-only questions\",\n\t\ttools: [...DEFAULT_AGENT_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"Work independently on the delegated task from start to finish.\",\n\t\t\t\"Inspect relevant repository instructions before changing files.\",\n\t\t\t\"Prefer editing existing files; never create documentation files unless the task explicitly asks for them.\",\n\t\t\t\"Keep changes focused, run appropriate verification, and report exact paths, checks, blockers, and remaining risks.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:general>\",\n\t\tbackend: \"sdk\",\n\t},\n\t{\n\t\tname: \"explorer\",\n\t\tdescription:\n\t\t\t'Fast read-only agent for finding files, searching code, and answering codebase questions. Can inspect git history (log, blame, diff) via read-only bash. State thoroughness in the prompt: \"quick\" for a targeted lookup, \"medium\" for checking likely related locations, or \"very thorough\" for exhaustive sweeps across locations and naming conventions',\n\t\ttools: [...EXPLORER_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"You are a fast read-only exploration agent; return findings as quickly as possible.\",\n\t\t\t\"Explore the delegated question without modifying files.\",\n\t\t\t\"Use read and search tools to gather exact evidence, batching independent searches and reads instead of running them one at a time.\",\n\t\t\t\"bash is for read-only inspection only: git log/diff/blame/show/status, ls, wc, head, tail, cat, and similar.\",\n\t\t\t\"Never run anything that modifies state: no file creation or deletion, no redirect (>, >>) or heredoc writes, no temp files, no git commands that write (add, commit, checkout, restore, stash, clean), no installs, no network access.\",\n\t\t\t\"Match the depth the caller requested: quick targets the direct question, medium checks likely related locations, and very thorough sweeps multiple locations and naming conventions.\",\n\t\t\t\"Return concise findings with precise paths, symbols, relationships, and unresolved uncertainties.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:explorer>\",\n\t\tbackend: \"sdk\",\n\t\tomitContextFiles: true,\n\t},\n];\n\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findNearestProjectAgentsDir(cwd: string): string | undefined {\n\tlet current = cwd;\n\twhile (true) {\n\t\tconst candidate = join(current, CONFIG_DIR_NAME, \"agents\");\n\t\tif (isDirectory(candidate)) return candidate;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\nfunction parseTools(raw: string | undefined, filePath: string): string[] {\n\tif (!raw?.trim()) return [...DEFAULT_AGENT_TOOLS];\n\tconst tools = [\n\t\t...new Set(\n\t\t\traw\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((tool) => tool.trim())\n\t\t\t\t.filter(Boolean),\n\t\t),\n\t];\n\tconst unsupported = tools.filter((tool) => !BUILTIN_TOOL_SET.has(tool));\n\tif (unsupported.length > 0) {\n\t\tthrow new Error(`Unsupported tool(s) ${unsupported.join(\", \")} in ${filePath}.`);\n\t}\n\treturn tools;\n}\n\n// Frontmatter model/thinking keys are intentionally ignored: agent files\n// travel across machines (project repos), so a pinned model rarely exists\n// in the reader's environment. Model and thinking come from /agents\n// overrides or default to the parent session.\nfunction parseAgentFile(filePath: string, source: Exclude<AgentSource, \"builtin\">): AgentDefinition {\n\tconst content = readFileSync(filePath, \"utf8\");\n\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(content);\n\tconst name = frontmatter.name?.trim() ?? \"\";\n\tconst description = frontmatter.description?.trim() ?? \"\";\n\tif (!name) throw new Error(\"Missing required frontmatter field: name.\");\n\tif (!AGENT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(`Agent name \"${name}\" must use lowercase letters, digits, hyphens, or underscores.`);\n\t}\n\tif (!description) throw new Error(\"Missing required frontmatter field: description.\");\n\tif (!body.trim()) throw new Error(\"Agent prompt body must not be empty.\");\n\tconst backend = frontmatter.backend?.trim();\n\tif (backend && backend !== \"sdk\") throw new Error(`Backend \"${backend}\" is not implemented; use \"sdk\".`);\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\ttools: parseTools(frontmatter.tools, filePath),\n\t\tsystemPrompt: body.trim(),\n\t\tsource,\n\t\tfilePath,\n\t\tbackend: \"sdk\",\n\t};\n}\n\nfunction loadAgentDirectory(\n\tdir: string,\n\tsource: Exclude<AgentSource, \"builtin\">,\n): { agents: AgentDefinition[]; diagnostics: AgentDiagnostic[] } {\n\tif (!existsSync(dir)) return { agents: [], diagnostics: [] };\n\tlet entries: Dirent[];\n\ttry {\n\t\tentries = readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));\n\t} catch (error) {\n\t\treturn {\n\t\t\tagents: [],\n\t\t\tdiagnostics: [{ path: dir, source, message: error instanceof Error ? error.message : String(error) }],\n\t\t};\n\t}\n\tconst agents: AgentDefinition[] = [];\n\tconst diagnostics: AgentDiagnostic[] = [];\n\tfor (const entry of entries) {\n\t\tif (!entry.name.endsWith(\".md\") || (!entry.isFile() && !entry.isSymbolicLink())) continue;\n\t\tconst filePath = join(dir, entry.name);\n\t\ttry {\n\t\t\tagents.push(parseAgentFile(filePath, source));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpath: filePath,\n\t\t\t\tsource,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t}\n\t}\n\treturn { agents, diagnostics };\n}\n\nexport function discoverAgents(\n\tcwd: string,\n\toptions: { projectTrusted: boolean; agentDir?: string },\n): AgentDiscoveryResult {\n\tconst userDir = join(options.agentDir ?? getAgentDir(), \"agents\");\n\tconst projectAgentsDir = findNearestProjectAgentsDir(cwd);\n\tconst user = loadAgentDirectory(userDir, \"user\");\n\tconst project =\n\t\toptions.projectTrusted && projectAgentsDir\n\t\t\t? loadAgentDirectory(projectAgentsDir, \"project\")\n\t\t\t: { agents: [], diagnostics: [] };\n\tconst agents = new Map(BUILTIN_AGENTS.map((agent) => [agent.name, { ...agent, tools: [...agent.tools] }]));\n\tfor (const agent of user.agents) agents.set(agent.name, agent);\n\tfor (const agent of project.agents) agents.set(agent.name, agent);\n\treturn {\n\t\tagents: [...agents.values()],\n\t\tdiagnostics: [...user.diagnostics, ...project.diagnostics],\n\t\tprojectAgentsDir,\n\t\tprojectAgentsTrusted: options.projectTrusted,\n\t};\n}\n\nexport function subagentToolDescription(discovery: AgentDiscoveryResult): string {\n\tconst agentLines: string[] = [];\n\tlet agentListLength = 0;\n\tfor (const [index, agent] of discovery.agents.entries()) {\n\t\tconst normalizedDescription = agent.description.replace(/\\s+/gu, \" \").trim();\n\t\tconst description =\n\t\t\tBuffer.byteLength(normalizedDescription, \"utf8\") <= TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT\n\t\t\t\t? normalizedDescription\n\t\t\t\t: `${utf8Prefix(normalizedDescription, TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT - Buffer.byteLength(\"…\", \"utf8\"))}…`;\n\t\tconst defaultLabel = agent.name === \"general\" ? \" (default)\" : \"\";\n\t\tconst tools = agent.tools.length > 0 ? agent.tools.join(\", \") : \"none\";\n\t\tconst line = `- ${agent.name}${defaultLabel}: ${description} (Tools: ${tools})`;\n\t\tconst lineLength = Buffer.byteLength(line, \"utf8\") + 1;\n\t\tif (agentListLength + lineLength > TOOL_DESCRIPTION_AGENT_LIST_LIMIT) {\n\t\t\tlet omitted = discovery.agents.length - index;\n\t\t\tlet notice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\twhile (\n\t\t\t\tagentLines.length > 0 &&\n\t\t\t\tagentListLength + Buffer.byteLength(notice, \"utf8\") + 1 > TOOL_DESCRIPTION_AGENT_LIST_LIMIT\n\t\t\t) {\n\t\t\t\tconst removed = agentLines.pop();\n\t\t\t\tif (!removed) break;\n\t\t\t\tagentListLength -= Buffer.byteLength(removed, \"utf8\") + 1;\n\t\t\t\tomitted++;\n\t\t\t\tnotice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\t}\n\t\t\tagentLines.push(notice);\n\t\t\tbreak;\n\t\t}\n\t\tagentLines.push(line);\n\t\tagentListLength += lineLength;\n\t}\n\n\treturn [\n\t\t`Delegate bounded work to isolated one-shot subagents. Delegation keeps intermediate tool output (file dumps, search results) out of your context: you receive only the final report. Choose exactly one mode: prompt for one task, or tasks for independent parallel work (up to ${MAX_TASKS} per call; ${MAX_CONCURRENCY} run concurrently, the rest queue). For sequential work, call this tool again with the previous result folded into the next briefing.`,\n\t\t\"\",\n\t\t\"Available agent profiles:\",\n\t\t...agentLines,\n\t\t\"\",\n\t\t\"When not to delegate:\",\n\t\t\"- Read a known file directly with read, or search for a known symbol directly with grep.\",\n\t\t\"- Prefer direct tools when a directed lookup answers the question; delegate when the investigation will clearly take more than ~3 searches or would flood your context with intermediate output.\",\n\t\t\"- Do not delegate a trivial task when the coordination overhead exceeds the work.\",\n\t\t\"\",\n\t\t\"Writing the briefing:\",\n\t\t\"- Brief the worker like a capable colleague entering the project now: include the objective, relevant context, exact paths or symbols already known, constraints, and expected output.\",\n\t\t\"- Never delegate understanding with vague instructions such as 'fix this based on your findings'; state what must be investigated or changed and whether the worker should research, implement, or review.\",\n\t\t\"- Lookups: hand over the exact command or file. Investigations: hand over the question — prescribed steps become dead weight when the premise is wrong.\",\n\t\t'- If you need a short answer, say so (e.g. \"report in under 200 words\"). Workers cannot see the parent conversation or ask the end user questions.',\n\t\t'- Example briefing (explorer): \"Quick: which commit introduced the retry loop in src/net/client.ts? Use git log/blame; report the hash and a one-line summary.\"',\n\t\t\"\",\n\t\t\"The subagent's report is not shown to the user. Interpret it and relay the important findings, changes, verification, and unresolved risks in your own reply.\",\n\t].join(\"\\n\");\n}\n"]}
@@ -2,27 +2,16 @@ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { CONFIG_DIR_NAME, getAgentDir } from "../../config.js";
4
4
  import { parseFrontmatter } from "../../utils/frontmatter.js";
5
- import { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS } from "./constants.js";
5
+ import { utf8Prefix } from "./activity.js";
6
+ import { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS, MAX_CONCURRENCY, MAX_TASKS } from "./constants.js";
6
7
  const AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,79}$/u;
7
8
  const BUILTIN_TOOL_SET = new Set(BUILTIN_TOOL_NAMES);
8
9
  const TOOL_DESCRIPTION_AGENT_LIST_LIMIT = 8_000;
9
10
  const TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT = 480;
10
- function utf8Prefix(text, maxBytes) {
11
- let output = "";
12
- let bytes = 0;
13
- for (const character of text) {
14
- const characterBytes = Buffer.byteLength(character, "utf8");
15
- if (bytes + characterBytes > maxBytes)
16
- break;
17
- output += character;
18
- bytes += characterBytes;
19
- }
20
- return output;
21
- }
22
11
  const BUILTIN_AGENTS = [
23
12
  {
24
13
  name: "general",
25
- description: "General-purpose implementation agent with coding tools",
14
+ description: "Implementation agent for bounded coding tasks: edits, fixes, refactors, and verification in a scoped area. Use when the task changes files; use explorer for read-only questions",
26
15
  tools: [...DEFAULT_AGENT_TOOLS],
27
16
  systemPrompt: [
28
17
  "Work independently on the delegated task from start to finish.",
@@ -36,18 +25,21 @@ const BUILTIN_AGENTS = [
36
25
  },
37
26
  {
38
27
  name: "explorer",
39
- description: 'Fast read-only agent for finding files, searching code, and answering codebase questions. State thoroughness in the prompt: "quick" for a targeted lookup, "medium" for checking likely related locations, or "very thorough" for exhaustive sweeps across locations and naming conventions',
28
+ description: 'Fast read-only agent for finding files, searching code, and answering codebase questions. Can inspect git history (log, blame, diff) via read-only bash. State thoroughness in the prompt: "quick" for a targeted lookup, "medium" for checking likely related locations, or "very thorough" for exhaustive sweeps across locations and naming conventions',
40
29
  tools: [...EXPLORER_TOOLS],
41
30
  systemPrompt: [
42
31
  "You are a fast read-only exploration agent; return findings as quickly as possible.",
43
32
  "Explore the delegated question without modifying files.",
44
33
  "Use read and search tools to gather exact evidence, batching independent searches and reads instead of running them one at a time.",
34
+ "bash is for read-only inspection only: git log/diff/blame/show/status, ls, wc, head, tail, cat, and similar.",
35
+ "Never run anything that modifies state: no file creation or deletion, no redirect (>, >>) or heredoc writes, no temp files, no git commands that write (add, commit, checkout, restore, stash, clean), no installs, no network access.",
45
36
  "Match the depth the caller requested: quick targets the direct question, medium checks likely related locations, and very thorough sweeps multiple locations and naming conventions.",
46
37
  "Return concise findings with precise paths, symbols, relationships, and unresolved uncertainties.",
47
38
  ].join("\n"),
48
39
  source: "builtin",
49
40
  filePath: "<builtin:explorer>",
50
41
  backend: "sdk",
42
+ omitContextFiles: true,
51
43
  },
52
44
  ];
53
45
  function isDirectory(path) {
@@ -198,21 +190,24 @@ export function subagentToolDescription(discovery) {
198
190
  agentListLength += lineLength;
199
191
  }
200
192
  return [
201
- "Delegate bounded work to isolated one-shot subagents. Choose exactly one mode: prompt for one task, tasks for independent parallel work, or chain for sequential work whose later prompts may include {previous}.",
193
+ `Delegate bounded work to isolated one-shot subagents. Delegation keeps intermediate tool output (file dumps, search results) out of your context: you receive only the final report. Choose exactly one mode: prompt for one task, or tasks for independent parallel work (up to ${MAX_TASKS} per call; ${MAX_CONCURRENCY} run concurrently, the rest queue). For sequential work, call this tool again with the previous result folded into the next briefing.`,
202
194
  "",
203
195
  "Available agent profiles:",
204
196
  ...agentLines,
205
197
  "",
206
198
  "When not to delegate:",
207
199
  "- Read a known file directly with read, or search for a known symbol directly with grep.",
200
+ "- Prefer direct tools when a directed lookup answers the question; delegate when the investigation will clearly take more than ~3 searches or would flood your context with intermediate output.",
208
201
  "- Do not delegate a trivial task when the coordination overhead exceeds the work.",
209
202
  "",
210
203
  "Writing the briefing:",
211
204
  "- Brief the worker like a capable colleague entering the project now: include the objective, relevant context, exact paths or symbols already known, constraints, and expected output.",
212
205
  "- Never delegate understanding with vague instructions such as 'fix this based on your findings'; state what must be investigated or changed and whether the worker should research, implement, or review.",
213
- "- Ask for a concise report when only findings are needed. Workers cannot see the parent conversation or ask the end user questions.",
206
+ "- Lookups: hand over the exact command or file. Investigations: hand over the question — prescribed steps become dead weight when the premise is wrong.",
207
+ '- If you need a short answer, say so (e.g. "report in under 200 words"). Workers cannot see the parent conversation or ask the end user questions.',
208
+ '- Example briefing (explorer): "Quick: which commit introduced the retry loop in src/net/client.ts? Use git log/blame; report the hash and a one-line summary."',
214
209
  "",
215
- "Subagent results are reports for you to interpret and relay. Surface the important findings, changes, verification, and unresolved risks to the user.",
210
+ "The subagent's report is not shown to the user. Interpret it and relay the important findings, changes, verification, and unresolved risks in your own reply.",
216
211
  ].join("\n");
217
212
  }
218
213
  //# sourceMappingURL=agents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agents.js","sourceRoot":"","sources":["../../../src/extensions/subagent/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,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AC1F,mFAAmF;QACnF,EAAE;QACF,uBAAuB;QACvB,wLAAwL;QACxL,4MAA4M;QAC5M,qIAAqI;QACrI,EAAE;QACF,uJAAuJ;KACvJ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACb","sourcesContent":["import { type Dirent, existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../config.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS } from \"./constants.ts\";\nimport type { AgentDefinition, AgentDiagnostic, AgentDiscoveryResult, AgentSource } from \"./types.ts\";\n\nconst AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,79}$/u;\nconst BUILTIN_TOOL_SET = new Set<string>(BUILTIN_TOOL_NAMES);\nconst TOOL_DESCRIPTION_AGENT_LIST_LIMIT = 8_000;\nconst TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT = 480;\n\nfunction utf8Prefix(text: string, maxBytes: number): string {\n\tlet output = \"\";\n\tlet bytes = 0;\n\tfor (const character of text) {\n\t\tconst characterBytes = Buffer.byteLength(character, \"utf8\");\n\t\tif (bytes + characterBytes > maxBytes) break;\n\t\toutput += character;\n\t\tbytes += characterBytes;\n\t}\n\treturn output;\n}\n\nconst BUILTIN_AGENTS: AgentDefinition[] = [\n\t{\n\t\tname: \"general\",\n\t\tdescription: \"General-purpose implementation agent with coding tools\",\n\t\ttools: [...DEFAULT_AGENT_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"Work independently on the delegated task from start to finish.\",\n\t\t\t\"Inspect relevant repository instructions before changing files.\",\n\t\t\t\"Prefer editing existing files; never create documentation files unless the task explicitly asks for them.\",\n\t\t\t\"Keep changes focused, run appropriate verification, and report exact paths, checks, blockers, and remaining risks.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:general>\",\n\t\tbackend: \"sdk\",\n\t},\n\t{\n\t\tname: \"explorer\",\n\t\tdescription:\n\t\t\t'Fast read-only agent for finding files, searching code, and answering codebase questions. State thoroughness in the prompt: \"quick\" for a targeted lookup, \"medium\" for checking likely related locations, or \"very thorough\" for exhaustive sweeps across locations and naming conventions',\n\t\ttools: [...EXPLORER_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"You are a fast read-only exploration agent; return findings as quickly as possible.\",\n\t\t\t\"Explore the delegated question without modifying files.\",\n\t\t\t\"Use read and search tools to gather exact evidence, batching independent searches and reads instead of running them one at a time.\",\n\t\t\t\"Match the depth the caller requested: quick targets the direct question, medium checks likely related locations, and very thorough sweeps multiple locations and naming conventions.\",\n\t\t\t\"Return concise findings with precise paths, symbols, relationships, and unresolved uncertainties.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:explorer>\",\n\t\tbackend: \"sdk\",\n\t},\n];\n\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findNearestProjectAgentsDir(cwd: string): string | undefined {\n\tlet current = cwd;\n\twhile (true) {\n\t\tconst candidate = join(current, CONFIG_DIR_NAME, \"agents\");\n\t\tif (isDirectory(candidate)) return candidate;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\nfunction parseTools(raw: string | undefined, filePath: string): string[] {\n\tif (!raw?.trim()) return [...DEFAULT_AGENT_TOOLS];\n\tconst tools = [\n\t\t...new Set(\n\t\t\traw\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((tool) => tool.trim())\n\t\t\t\t.filter(Boolean),\n\t\t),\n\t];\n\tconst unsupported = tools.filter((tool) => !BUILTIN_TOOL_SET.has(tool));\n\tif (unsupported.length > 0) {\n\t\tthrow new Error(`Unsupported tool(s) ${unsupported.join(\", \")} in ${filePath}.`);\n\t}\n\treturn tools;\n}\n\n// Frontmatter model/thinking keys are intentionally ignored: agent files\n// travel across machines (project repos), so a pinned model rarely exists\n// in the reader's environment. Model and thinking come from /agents\n// overrides or default to the parent session.\nfunction parseAgentFile(filePath: string, source: Exclude<AgentSource, \"builtin\">): AgentDefinition {\n\tconst content = readFileSync(filePath, \"utf8\");\n\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(content);\n\tconst name = frontmatter.name?.trim() ?? \"\";\n\tconst description = frontmatter.description?.trim() ?? \"\";\n\tif (!name) throw new Error(\"Missing required frontmatter field: name.\");\n\tif (!AGENT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(`Agent name \"${name}\" must use lowercase letters, digits, hyphens, or underscores.`);\n\t}\n\tif (!description) throw new Error(\"Missing required frontmatter field: description.\");\n\tif (!body.trim()) throw new Error(\"Agent prompt body must not be empty.\");\n\tconst backend = frontmatter.backend?.trim();\n\tif (backend && backend !== \"sdk\") throw new Error(`Backend \"${backend}\" is not implemented; use \"sdk\".`);\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\ttools: parseTools(frontmatter.tools, filePath),\n\t\tsystemPrompt: body.trim(),\n\t\tsource,\n\t\tfilePath,\n\t\tbackend: \"sdk\",\n\t};\n}\n\nfunction loadAgentDirectory(\n\tdir: string,\n\tsource: Exclude<AgentSource, \"builtin\">,\n): { agents: AgentDefinition[]; diagnostics: AgentDiagnostic[] } {\n\tif (!existsSync(dir)) return { agents: [], diagnostics: [] };\n\tlet entries: Dirent[];\n\ttry {\n\t\tentries = readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));\n\t} catch (error) {\n\t\treturn {\n\t\t\tagents: [],\n\t\t\tdiagnostics: [{ path: dir, source, message: error instanceof Error ? error.message : String(error) }],\n\t\t};\n\t}\n\tconst agents: AgentDefinition[] = [];\n\tconst diagnostics: AgentDiagnostic[] = [];\n\tfor (const entry of entries) {\n\t\tif (!entry.name.endsWith(\".md\") || (!entry.isFile() && !entry.isSymbolicLink())) continue;\n\t\tconst filePath = join(dir, entry.name);\n\t\ttry {\n\t\t\tagents.push(parseAgentFile(filePath, source));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpath: filePath,\n\t\t\t\tsource,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t}\n\t}\n\treturn { agents, diagnostics };\n}\n\nexport function discoverAgents(\n\tcwd: string,\n\toptions: { projectTrusted: boolean; agentDir?: string },\n): AgentDiscoveryResult {\n\tconst userDir = join(options.agentDir ?? getAgentDir(), \"agents\");\n\tconst projectAgentsDir = findNearestProjectAgentsDir(cwd);\n\tconst user = loadAgentDirectory(userDir, \"user\");\n\tconst project =\n\t\toptions.projectTrusted && projectAgentsDir\n\t\t\t? loadAgentDirectory(projectAgentsDir, \"project\")\n\t\t\t: { agents: [], diagnostics: [] };\n\tconst agents = new Map(BUILTIN_AGENTS.map((agent) => [agent.name, { ...agent, tools: [...agent.tools] }]));\n\tfor (const agent of user.agents) agents.set(agent.name, agent);\n\tfor (const agent of project.agents) agents.set(agent.name, agent);\n\treturn {\n\t\tagents: [...agents.values()],\n\t\tdiagnostics: [...user.diagnostics, ...project.diagnostics],\n\t\tprojectAgentsDir,\n\t\tprojectAgentsTrusted: options.projectTrusted,\n\t};\n}\n\nexport function subagentToolDescription(discovery: AgentDiscoveryResult): string {\n\tconst agentLines: string[] = [];\n\tlet agentListLength = 0;\n\tfor (const [index, agent] of discovery.agents.entries()) {\n\t\tconst normalizedDescription = agent.description.replace(/\\s+/gu, \" \").trim();\n\t\tconst description =\n\t\t\tBuffer.byteLength(normalizedDescription, \"utf8\") <= TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT\n\t\t\t\t? normalizedDescription\n\t\t\t\t: `${utf8Prefix(normalizedDescription, TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT - Buffer.byteLength(\"…\", \"utf8\"))}…`;\n\t\tconst defaultLabel = agent.name === \"general\" ? \" (default)\" : \"\";\n\t\tconst tools = agent.tools.length > 0 ? agent.tools.join(\", \") : \"none\";\n\t\tconst line = `- ${agent.name}${defaultLabel}: ${description} (Tools: ${tools})`;\n\t\tconst lineLength = Buffer.byteLength(line, \"utf8\") + 1;\n\t\tif (agentListLength + lineLength > TOOL_DESCRIPTION_AGENT_LIST_LIMIT) {\n\t\t\tlet omitted = discovery.agents.length - index;\n\t\t\tlet notice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\twhile (\n\t\t\t\tagentLines.length > 0 &&\n\t\t\t\tagentListLength + Buffer.byteLength(notice, \"utf8\") + 1 > TOOL_DESCRIPTION_AGENT_LIST_LIMIT\n\t\t\t) {\n\t\t\t\tconst removed = agentLines.pop();\n\t\t\t\tif (!removed) break;\n\t\t\t\tagentListLength -= Buffer.byteLength(removed, \"utf8\") + 1;\n\t\t\t\tomitted++;\n\t\t\t\tnotice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\t}\n\t\t\tagentLines.push(notice);\n\t\t\tbreak;\n\t\t}\n\t\tagentLines.push(line);\n\t\tagentListLength += lineLength;\n\t}\n\n\treturn [\n\t\t\"Delegate bounded work to isolated one-shot subagents. Choose exactly one mode: prompt for one task, tasks for independent parallel work, or chain for sequential work whose later prompts may include {previous}.\",\n\t\t\"\",\n\t\t\"Available agent profiles:\",\n\t\t...agentLines,\n\t\t\"\",\n\t\t\"When not to delegate:\",\n\t\t\"- Read a known file directly with read, or search for a known symbol directly with grep.\",\n\t\t\"- Do not delegate a trivial task when the coordination overhead exceeds the work.\",\n\t\t\"\",\n\t\t\"Writing the briefing:\",\n\t\t\"- Brief the worker like a capable colleague entering the project now: include the objective, relevant context, exact paths or symbols already known, constraints, and expected output.\",\n\t\t\"- Never delegate understanding with vague instructions such as 'fix this based on your findings'; state what must be investigated or changed and whether the worker should research, implement, or review.\",\n\t\t\"- Ask for a concise report when only findings are needed. Workers cannot see the parent conversation or ask the end user questions.\",\n\t\t\"\",\n\t\t\"Subagent results are reports for you to interpret and relay. Surface the important findings, changes, verification, and unresolved risks to the user.\",\n\t].join(\"\\n\");\n}\n"]}
1
+ {"version":3,"file":"agents.js","sourceRoot":"","sources":["../../../src/extensions/subagent/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGrH,MAAM,kBAAkB,GAAG,6BAA6B,CAAC;AACzD,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAS,kBAAkB,CAAC,CAAC;AAC7D,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,oCAAoC,GAAG,GAAG,CAAC;AAEjD,MAAM,cAAc,GAAsB;IACzC;QACC,IAAI,EAAE,SAAS;QACf,WAAW,EACV,kLAAkL;QACnL,KAAK,EAAE,CAAC,GAAG,mBAAmB,CAAC;QAC/B,YAAY,EAAE;YACb,gEAAgE;YAChE,iEAAiE;YACjE,2GAA2G;YAC3G,oHAAoH;SACpH,CAAC,IAAI,CAAC,IAAI,CAAC;QACZ,MAAM,EAAE,SAAS;QACjB,QAAQ,EAAE,mBAAmB;QAC7B,OAAO,EAAE,KAAK;KACd;IACD;QACC,IAAI,EAAE,UAAU;QAChB,WAAW,EACV,4VAA4V;QAC7V,KAAK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,CAAC;IAED,OAAO;QACN,oRAAoR,SAAS,cAAc,eAAe,uIAAuI;QACjc,EAAE;QACF,2BAA2B;QAC3B,GAAG,UAAU;QACb,EAAE;QACF,uBAAuB;QACvB,0FAA0F;QAC1F,kMAAkM;QAClM,mFAAmF;QACnF,EAAE;QACF,uBAAuB;QACvB,wLAAwL;QACxL,4MAA4M;QAC5M,2JAAyJ;QACzJ,oJAAoJ;QACpJ,iKAAiK;QACjK,EAAE;QACF,+JAA+J;KAC/J,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACb","sourcesContent":["import { type Dirent, existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../config.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { utf8Prefix } from \"./activity.ts\";\nimport { BUILTIN_TOOL_NAMES, DEFAULT_AGENT_TOOLS, EXPLORER_TOOLS, MAX_CONCURRENCY, MAX_TASKS } from \"./constants.ts\";\nimport type { AgentDefinition, AgentDiagnostic, AgentDiscoveryResult, AgentSource } from \"./types.ts\";\n\nconst AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,79}$/u;\nconst BUILTIN_TOOL_SET = new Set<string>(BUILTIN_TOOL_NAMES);\nconst TOOL_DESCRIPTION_AGENT_LIST_LIMIT = 8_000;\nconst TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT = 480;\n\nconst BUILTIN_AGENTS: AgentDefinition[] = [\n\t{\n\t\tname: \"general\",\n\t\tdescription:\n\t\t\t\"Implementation agent for bounded coding tasks: edits, fixes, refactors, and verification in a scoped area. Use when the task changes files; use explorer for read-only questions\",\n\t\ttools: [...DEFAULT_AGENT_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"Work independently on the delegated task from start to finish.\",\n\t\t\t\"Inspect relevant repository instructions before changing files.\",\n\t\t\t\"Prefer editing existing files; never create documentation files unless the task explicitly asks for them.\",\n\t\t\t\"Keep changes focused, run appropriate verification, and report exact paths, checks, blockers, and remaining risks.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:general>\",\n\t\tbackend: \"sdk\",\n\t},\n\t{\n\t\tname: \"explorer\",\n\t\tdescription:\n\t\t\t'Fast read-only agent for finding files, searching code, and answering codebase questions. Can inspect git history (log, blame, diff) via read-only bash. State thoroughness in the prompt: \"quick\" for a targeted lookup, \"medium\" for checking likely related locations, or \"very thorough\" for exhaustive sweeps across locations and naming conventions',\n\t\ttools: [...EXPLORER_TOOLS],\n\t\tsystemPrompt: [\n\t\t\t\"You are a fast read-only exploration agent; return findings as quickly as possible.\",\n\t\t\t\"Explore the delegated question without modifying files.\",\n\t\t\t\"Use read and search tools to gather exact evidence, batching independent searches and reads instead of running them one at a time.\",\n\t\t\t\"bash is for read-only inspection only: git log/diff/blame/show/status, ls, wc, head, tail, cat, and similar.\",\n\t\t\t\"Never run anything that modifies state: no file creation or deletion, no redirect (>, >>) or heredoc writes, no temp files, no git commands that write (add, commit, checkout, restore, stash, clean), no installs, no network access.\",\n\t\t\t\"Match the depth the caller requested: quick targets the direct question, medium checks likely related locations, and very thorough sweeps multiple locations and naming conventions.\",\n\t\t\t\"Return concise findings with precise paths, symbols, relationships, and unresolved uncertainties.\",\n\t\t].join(\"\\n\"),\n\t\tsource: \"builtin\",\n\t\tfilePath: \"<builtin:explorer>\",\n\t\tbackend: \"sdk\",\n\t\tomitContextFiles: true,\n\t},\n];\n\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findNearestProjectAgentsDir(cwd: string): string | undefined {\n\tlet current = cwd;\n\twhile (true) {\n\t\tconst candidate = join(current, CONFIG_DIR_NAME, \"agents\");\n\t\tif (isDirectory(candidate)) return candidate;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\nfunction parseTools(raw: string | undefined, filePath: string): string[] {\n\tif (!raw?.trim()) return [...DEFAULT_AGENT_TOOLS];\n\tconst tools = [\n\t\t...new Set(\n\t\t\traw\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((tool) => tool.trim())\n\t\t\t\t.filter(Boolean),\n\t\t),\n\t];\n\tconst unsupported = tools.filter((tool) => !BUILTIN_TOOL_SET.has(tool));\n\tif (unsupported.length > 0) {\n\t\tthrow new Error(`Unsupported tool(s) ${unsupported.join(\", \")} in ${filePath}.`);\n\t}\n\treturn tools;\n}\n\n// Frontmatter model/thinking keys are intentionally ignored: agent files\n// travel across machines (project repos), so a pinned model rarely exists\n// in the reader's environment. Model and thinking come from /agents\n// overrides or default to the parent session.\nfunction parseAgentFile(filePath: string, source: Exclude<AgentSource, \"builtin\">): AgentDefinition {\n\tconst content = readFileSync(filePath, \"utf8\");\n\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(content);\n\tconst name = frontmatter.name?.trim() ?? \"\";\n\tconst description = frontmatter.description?.trim() ?? \"\";\n\tif (!name) throw new Error(\"Missing required frontmatter field: name.\");\n\tif (!AGENT_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(`Agent name \"${name}\" must use lowercase letters, digits, hyphens, or underscores.`);\n\t}\n\tif (!description) throw new Error(\"Missing required frontmatter field: description.\");\n\tif (!body.trim()) throw new Error(\"Agent prompt body must not be empty.\");\n\tconst backend = frontmatter.backend?.trim();\n\tif (backend && backend !== \"sdk\") throw new Error(`Backend \"${backend}\" is not implemented; use \"sdk\".`);\n\treturn {\n\t\tname,\n\t\tdescription,\n\t\ttools: parseTools(frontmatter.tools, filePath),\n\t\tsystemPrompt: body.trim(),\n\t\tsource,\n\t\tfilePath,\n\t\tbackend: \"sdk\",\n\t};\n}\n\nfunction loadAgentDirectory(\n\tdir: string,\n\tsource: Exclude<AgentSource, \"builtin\">,\n): { agents: AgentDefinition[]; diagnostics: AgentDiagnostic[] } {\n\tif (!existsSync(dir)) return { agents: [], diagnostics: [] };\n\tlet entries: Dirent[];\n\ttry {\n\t\tentries = readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));\n\t} catch (error) {\n\t\treturn {\n\t\t\tagents: [],\n\t\t\tdiagnostics: [{ path: dir, source, message: error instanceof Error ? error.message : String(error) }],\n\t\t};\n\t}\n\tconst agents: AgentDefinition[] = [];\n\tconst diagnostics: AgentDiagnostic[] = [];\n\tfor (const entry of entries) {\n\t\tif (!entry.name.endsWith(\".md\") || (!entry.isFile() && !entry.isSymbolicLink())) continue;\n\t\tconst filePath = join(dir, entry.name);\n\t\ttry {\n\t\t\tagents.push(parseAgentFile(filePath, source));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpath: filePath,\n\t\t\t\tsource,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t}\n\t}\n\treturn { agents, diagnostics };\n}\n\nexport function discoverAgents(\n\tcwd: string,\n\toptions: { projectTrusted: boolean; agentDir?: string },\n): AgentDiscoveryResult {\n\tconst userDir = join(options.agentDir ?? getAgentDir(), \"agents\");\n\tconst projectAgentsDir = findNearestProjectAgentsDir(cwd);\n\tconst user = loadAgentDirectory(userDir, \"user\");\n\tconst project =\n\t\toptions.projectTrusted && projectAgentsDir\n\t\t\t? loadAgentDirectory(projectAgentsDir, \"project\")\n\t\t\t: { agents: [], diagnostics: [] };\n\tconst agents = new Map(BUILTIN_AGENTS.map((agent) => [agent.name, { ...agent, tools: [...agent.tools] }]));\n\tfor (const agent of user.agents) agents.set(agent.name, agent);\n\tfor (const agent of project.agents) agents.set(agent.name, agent);\n\treturn {\n\t\tagents: [...agents.values()],\n\t\tdiagnostics: [...user.diagnostics, ...project.diagnostics],\n\t\tprojectAgentsDir,\n\t\tprojectAgentsTrusted: options.projectTrusted,\n\t};\n}\n\nexport function subagentToolDescription(discovery: AgentDiscoveryResult): string {\n\tconst agentLines: string[] = [];\n\tlet agentListLength = 0;\n\tfor (const [index, agent] of discovery.agents.entries()) {\n\t\tconst normalizedDescription = agent.description.replace(/\\s+/gu, \" \").trim();\n\t\tconst description =\n\t\t\tBuffer.byteLength(normalizedDescription, \"utf8\") <= TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT\n\t\t\t\t? normalizedDescription\n\t\t\t\t: `${utf8Prefix(normalizedDescription, TOOL_DESCRIPTION_AGENT_SUMMARY_LIMIT - Buffer.byteLength(\"…\", \"utf8\"))}…`;\n\t\tconst defaultLabel = agent.name === \"general\" ? \" (default)\" : \"\";\n\t\tconst tools = agent.tools.length > 0 ? agent.tools.join(\", \") : \"none\";\n\t\tconst line = `- ${agent.name}${defaultLabel}: ${description} (Tools: ${tools})`;\n\t\tconst lineLength = Buffer.byteLength(line, \"utf8\") + 1;\n\t\tif (agentListLength + lineLength > TOOL_DESCRIPTION_AGENT_LIST_LIMIT) {\n\t\t\tlet omitted = discovery.agents.length - index;\n\t\t\tlet notice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\twhile (\n\t\t\t\tagentLines.length > 0 &&\n\t\t\t\tagentListLength + Buffer.byteLength(notice, \"utf8\") + 1 > TOOL_DESCRIPTION_AGENT_LIST_LIMIT\n\t\t\t) {\n\t\t\t\tconst removed = agentLines.pop();\n\t\t\t\tif (!removed) break;\n\t\t\t\tagentListLength -= Buffer.byteLength(removed, \"utf8\") + 1;\n\t\t\t\tomitted++;\n\t\t\t\tnotice = `- ${omitted} additional profile${omitted === 1 ? \"\" : \"s\"} omitted from this bounded description; /agents lists every profile.`;\n\t\t\t}\n\t\t\tagentLines.push(notice);\n\t\t\tbreak;\n\t\t}\n\t\tagentLines.push(line);\n\t\tagentListLength += lineLength;\n\t}\n\n\treturn [\n\t\t`Delegate bounded work to isolated one-shot subagents. Delegation keeps intermediate tool output (file dumps, search results) out of your context: you receive only the final report. Choose exactly one mode: prompt for one task, or tasks for independent parallel work (up to ${MAX_TASKS} per call; ${MAX_CONCURRENCY} run concurrently, the rest queue). For sequential work, call this tool again with the previous result folded into the next briefing.`,\n\t\t\"\",\n\t\t\"Available agent profiles:\",\n\t\t...agentLines,\n\t\t\"\",\n\t\t\"When not to delegate:\",\n\t\t\"- Read a known file directly with read, or search for a known symbol directly with grep.\",\n\t\t\"- Prefer direct tools when a directed lookup answers the question; delegate when the investigation will clearly take more than ~3 searches or would flood your context with intermediate output.\",\n\t\t\"- Do not delegate a trivial task when the coordination overhead exceeds the work.\",\n\t\t\"\",\n\t\t\"Writing the briefing:\",\n\t\t\"- Brief the worker like a capable colleague entering the project now: include the objective, relevant context, exact paths or symbols already known, constraints, and expected output.\",\n\t\t\"- Never delegate understanding with vague instructions such as 'fix this based on your findings'; state what must be investigated or changed and whether the worker should research, implement, or review.\",\n\t\t\"- Lookups: hand over the exact command or file. Investigations: hand over the question — prescribed steps become dead weight when the premise is wrong.\",\n\t\t'- If you need a short answer, say so (e.g. \"report in under 200 words\"). Workers cannot see the parent conversation or ask the end user questions.',\n\t\t'- Example briefing (explorer): \"Quick: which commit introduced the retry loop in src/net/client.ts? Use git log/blame; report the hash and a one-line summary.\"',\n\t\t\"\",\n\t\t\"The subagent's report is not shown to the user. Interpret it and relay the important findings, changes, verification, and unresolved risks in your own reply.\",\n\t].join(\"\\n\");\n}\n"]}
@@ -4,10 +4,12 @@ export declare const SUBAGENT_COMMAND_NAME = "agents";
4
4
  export declare const SUBAGENT_CONFIG_VERSION = 1;
5
5
  export declare const SUBAGENT_CONFIG_FILE = "subagent.json";
6
6
  export declare const MAX_TASKS = 8;
7
- export declare const MAX_CONCURRENCY = 3;
7
+ export declare const MAX_CONCURRENCY = 5;
8
+ export declare const TASK_RETRY_LIMIT = 2;
9
+ export declare const TASK_RETRY_BASE_DELAY_MS = 1000;
8
10
  export declare const BUILTIN_TOOL_NAMES: readonly ["read", "bash", "edit", "write", "grep", "find", "ls"];
9
11
  export declare const DEFAULT_AGENT_TOOLS: readonly ["read", "bash", "edit", "write"];
10
- export declare const EXPLORER_TOOLS: readonly ["read", "grep", "find", "ls"];
12
+ export declare const EXPLORER_TOOLS: readonly ["read", "grep", "find", "ls", "bash"];
11
13
  export declare const THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
12
14
  export declare const LIVE_TEXT_LIMIT: number;
13
15
  export declare const ACTIVITY_LIMIT = 80;
@@ -15,8 +17,7 @@ export declare const ACTIVITY_TEXT_LIMIT: number;
15
17
  export declare const SINGLE_OUTPUT_LIMIT: number;
16
18
  export declare const PARALLEL_TASK_OUTPUT_LIMIT: number;
17
19
  export declare const PARALLEL_OUTPUT_LIMIT: number;
18
- export declare const CHAIN_HANDOFF_LIMIT: number;
19
20
  export declare const ERROR_TEXT_LIMIT: number;
20
21
  export declare const DETAILS_OUTPUT_LIMIT: number;
21
- export declare const DETAILS_ACTIVITY_LIMIT = 4;
22
+ export declare const DETAILS_ACTIVITY_LIMIT = 12;
22
23
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAC7C,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AAEpD,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,eAAO,MAAM,kBAAkB,kEAAmE,CAAC;AAEnG,eAAO,MAAM,mBAAmB,4CAA6C,CAAC;AAE9E,eAAO,MAAM,cAAc,yCAA0C,CAAC;AAEtE,eAAO,MAAM,eAAe,sEAQiB,CAAC;AAE9C,eAAO,MAAM,eAAe,QAAW,CAAC;AACxC,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,0BAA0B,QAAY,CAAC;AACpD,eAAO,MAAM,qBAAqB,QAAY,CAAC;AAC/C,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,gBAAgB,QAAW,CAAC;AACzC,eAAO,MAAM,oBAAoB,QAAa,CAAC;AAC/C,eAAO,MAAM,sBAAsB,IAAI,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport const SUBAGENT_TOOL_NAME = \"subagent\";\nexport const SUBAGENT_TOOL_LABEL = \"Subagent\";\nexport const SUBAGENT_COMMAND_NAME = \"agents\";\nexport const SUBAGENT_CONFIG_VERSION = 1;\nexport const SUBAGENT_CONFIG_FILE = \"subagent.json\";\n\nexport const MAX_TASKS = 8;\nexport const MAX_CONCURRENCY = 3;\n\nexport const BUILTIN_TOOL_NAMES = [\"read\", \"bash\", \"edit\", \"write\", \"grep\", \"find\", \"ls\"] as const;\n// Matches the parent session's default toolset; bash covers search needs.\nexport const DEFAULT_AGENT_TOOLS = [\"read\", \"bash\", \"edit\", \"write\"] as const;\n// Read-only agents get the standalone search tools instead of bash.\nexport const EXPLORER_TOOLS = [\"read\", \"grep\", \"find\", \"ls\"] as const;\n\nexport const THINKING_LEVELS = [\n\t\"off\",\n\t\"minimal\",\n\t\"low\",\n\t\"medium\",\n\t\"high\",\n\t\"xhigh\",\n\t\"max\",\n] as const satisfies readonly ThinkingLevel[];\n\nexport const LIVE_TEXT_LIMIT = 8 * 1024;\nexport const ACTIVITY_LIMIT = 80;\nexport const ACTIVITY_TEXT_LIMIT = 24 * 1024;\nexport const SINGLE_OUTPUT_LIMIT = 32 * 1024;\nexport const PARALLEL_TASK_OUTPUT_LIMIT = 12 * 1024;\nexport const PARALLEL_OUTPUT_LIMIT = 48 * 1024;\nexport const CHAIN_HANDOFF_LIMIT = 16 * 1024;\nexport const ERROR_TEXT_LIMIT = 8 * 1024;\nexport const DETAILS_OUTPUT_LIMIT = 120 * 1024;\nexport const DETAILS_ACTIVITY_LIMIT = 4;\n"]}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAC7C,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AAEpD,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,eAAO,MAAM,eAAe,IAAI,CAAC;AAKjC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,wBAAwB,OAAQ,CAAC;AAE9C,eAAO,MAAM,kBAAkB,kEAAmE,CAAC;AAEnG,eAAO,MAAM,mBAAmB,4CAA6C,CAAC;AAG9E,eAAO,MAAM,cAAc,iDAAkD,CAAC;AAE9E,eAAO,MAAM,eAAe,sEAQiB,CAAC;AAE9C,eAAO,MAAM,eAAe,QAAW,CAAC;AACxC,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,0BAA0B,QAAY,CAAC;AACpD,eAAO,MAAM,qBAAqB,QAAY,CAAC;AAC/C,eAAO,MAAM,gBAAgB,QAAW,CAAC;AACzC,eAAO,MAAM,oBAAoB,QAAa,CAAC;AAG/C,eAAO,MAAM,sBAAsB,KAAK,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport const SUBAGENT_TOOL_NAME = \"subagent\";\nexport const SUBAGENT_TOOL_LABEL = \"Subagent\";\nexport const SUBAGENT_COMMAND_NAME = \"agents\";\nexport const SUBAGENT_CONFIG_VERSION = 1;\nexport const SUBAGENT_CONFIG_FILE = \"subagent.json\";\n\nexport const MAX_TASKS = 8;\nexport const MAX_CONCURRENCY = 5;\n\n// Task-level retry for failures that bypass the session's own auto-retry\n// (preflight throws such as auth checks). Only runs that produced nothing\n// are retried, so a retry never discards partial work.\nexport const TASK_RETRY_LIMIT = 2;\nexport const TASK_RETRY_BASE_DELAY_MS = 1_000;\n\nexport const BUILTIN_TOOL_NAMES = [\"read\", \"bash\", \"edit\", \"write\", \"grep\", \"find\", \"ls\"] as const;\n// Matches the parent session's default toolset; bash covers search needs.\nexport const DEFAULT_AGENT_TOOLS = [\"read\", \"bash\", \"edit\", \"write\"] as const;\n// Read-only agents get the standalone search tools plus bash for read-only\n// inspection (git history, counting); the system prompt constrains bash.\nexport const EXPLORER_TOOLS = [\"read\", \"grep\", \"find\", \"ls\", \"bash\"] as const;\n\nexport const THINKING_LEVELS = [\n\t\"off\",\n\t\"minimal\",\n\t\"low\",\n\t\"medium\",\n\t\"high\",\n\t\"xhigh\",\n\t\"max\",\n] as const satisfies readonly ThinkingLevel[];\n\nexport const LIVE_TEXT_LIMIT = 8 * 1024;\nexport const ACTIVITY_LIMIT = 80;\nexport const ACTIVITY_TEXT_LIMIT = 24 * 1024;\nexport const SINGLE_OUTPUT_LIMIT = 32 * 1024;\nexport const PARALLEL_TASK_OUTPUT_LIMIT = 12 * 1024;\nexport const PARALLEL_OUTPUT_LIMIT = 48 * 1024;\nexport const ERROR_TEXT_LIMIT = 8 * 1024;\nexport const DETAILS_OUTPUT_LIMIT = 120 * 1024;\n// Bounded per run inside DETAILS_OUTPUT_LIMIT; each activity costs up to\n// ~600 bytes, so 12 keeps an 8-run parallel batch from starving outputs.\nexport const DETAILS_ACTIVITY_LIMIT = 12;\n"]}
@@ -4,12 +4,18 @@ export const SUBAGENT_COMMAND_NAME = "agents";
4
4
  export const SUBAGENT_CONFIG_VERSION = 1;
5
5
  export const SUBAGENT_CONFIG_FILE = "subagent.json";
6
6
  export const MAX_TASKS = 8;
7
- export const MAX_CONCURRENCY = 3;
7
+ export const MAX_CONCURRENCY = 5;
8
+ // Task-level retry for failures that bypass the session's own auto-retry
9
+ // (preflight throws such as auth checks). Only runs that produced nothing
10
+ // are retried, so a retry never discards partial work.
11
+ export const TASK_RETRY_LIMIT = 2;
12
+ export const TASK_RETRY_BASE_DELAY_MS = 1_000;
8
13
  export const BUILTIN_TOOL_NAMES = ["read", "bash", "edit", "write", "grep", "find", "ls"];
9
14
  // Matches the parent session's default toolset; bash covers search needs.
10
15
  export const DEFAULT_AGENT_TOOLS = ["read", "bash", "edit", "write"];
11
- // Read-only agents get the standalone search tools instead of bash.
12
- export const EXPLORER_TOOLS = ["read", "grep", "find", "ls"];
16
+ // Read-only agents get the standalone search tools plus bash for read-only
17
+ // inspection (git history, counting); the system prompt constrains bash.
18
+ export const EXPLORER_TOOLS = ["read", "grep", "find", "ls", "bash"];
13
19
  export const THINKING_LEVELS = [
14
20
  "off",
15
21
  "minimal",
@@ -25,8 +31,9 @@ export const ACTIVITY_TEXT_LIMIT = 24 * 1024;
25
31
  export const SINGLE_OUTPUT_LIMIT = 32 * 1024;
26
32
  export const PARALLEL_TASK_OUTPUT_LIMIT = 12 * 1024;
27
33
  export const PARALLEL_OUTPUT_LIMIT = 48 * 1024;
28
- export const CHAIN_HANDOFF_LIMIT = 16 * 1024;
29
34
  export const ERROR_TEXT_LIMIT = 8 * 1024;
30
35
  export const DETAILS_OUTPUT_LIMIT = 120 * 1024;
31
- export const DETAILS_ACTIVITY_LIMIT = 4;
36
+ // Bounded per run inside DETAILS_OUTPUT_LIMIT; each activity costs up to
37
+ // ~600 bytes, so 12 keeps an 8-run parallel batch from starving outputs.
38
+ export const DETAILS_ACTIVITY_LIMIT = 12;
32
39
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/extensions/subagent/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC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EAAE,GAAG,IAAI,CAAC;AAC7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAG,IAAI,CAAC;AACzC,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC/C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport const SUBAGENT_TOOL_NAME = \"subagent\";\nexport const SUBAGENT_TOOL_LABEL = \"Subagent\";\nexport const SUBAGENT_COMMAND_NAME = \"agents\";\nexport const SUBAGENT_CONFIG_VERSION = 1;\nexport const SUBAGENT_CONFIG_FILE = \"subagent.json\";\n\nexport const MAX_TASKS = 8;\nexport const MAX_CONCURRENCY = 3;\n\nexport const BUILTIN_TOOL_NAMES = [\"read\", \"bash\", \"edit\", \"write\", \"grep\", \"find\", \"ls\"] as const;\n// Matches the parent session's default toolset; bash covers search needs.\nexport const DEFAULT_AGENT_TOOLS = [\"read\", \"bash\", \"edit\", \"write\"] as const;\n// Read-only agents get the standalone search tools instead of bash.\nexport const EXPLORER_TOOLS = [\"read\", \"grep\", \"find\", \"ls\"] as const;\n\nexport const THINKING_LEVELS = [\n\t\"off\",\n\t\"minimal\",\n\t\"low\",\n\t\"medium\",\n\t\"high\",\n\t\"xhigh\",\n\t\"max\",\n] as const satisfies readonly ThinkingLevel[];\n\nexport const LIVE_TEXT_LIMIT = 8 * 1024;\nexport const ACTIVITY_LIMIT = 80;\nexport const ACTIVITY_TEXT_LIMIT = 24 * 1024;\nexport const SINGLE_OUTPUT_LIMIT = 32 * 1024;\nexport const PARALLEL_TASK_OUTPUT_LIMIT = 12 * 1024;\nexport const PARALLEL_OUTPUT_LIMIT = 48 * 1024;\nexport const CHAIN_HANDOFF_LIMIT = 16 * 1024;\nexport const ERROR_TEXT_LIMIT = 8 * 1024;\nexport const DETAILS_OUTPUT_LIMIT = 120 * 1024;\nexport const DETAILS_ACTIVITY_LIMIT = 4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,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7C,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC;AACpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAG,IAAI,CAAC;AACzC,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC/C,yEAAyE;AACzE,yEAAyE;AACzE,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport const SUBAGENT_TOOL_NAME = \"subagent\";\nexport const SUBAGENT_TOOL_LABEL = \"Subagent\";\nexport const SUBAGENT_COMMAND_NAME = \"agents\";\nexport const SUBAGENT_CONFIG_VERSION = 1;\nexport const SUBAGENT_CONFIG_FILE = \"subagent.json\";\n\nexport const MAX_TASKS = 8;\nexport const MAX_CONCURRENCY = 5;\n\n// Task-level retry for failures that bypass the session's own auto-retry\n// (preflight throws such as auth checks). Only runs that produced nothing\n// are retried, so a retry never discards partial work.\nexport const TASK_RETRY_LIMIT = 2;\nexport const TASK_RETRY_BASE_DELAY_MS = 1_000;\n\nexport const BUILTIN_TOOL_NAMES = [\"read\", \"bash\", \"edit\", \"write\", \"grep\", \"find\", \"ls\"] as const;\n// Matches the parent session's default toolset; bash covers search needs.\nexport const DEFAULT_AGENT_TOOLS = [\"read\", \"bash\", \"edit\", \"write\"] as const;\n// Read-only agents get the standalone search tools plus bash for read-only\n// inspection (git history, counting); the system prompt constrains bash.\nexport const EXPLORER_TOOLS = [\"read\", \"grep\", \"find\", \"ls\", \"bash\"] as const;\n\nexport const THINKING_LEVELS = [\n\t\"off\",\n\t\"minimal\",\n\t\"low\",\n\t\"medium\",\n\t\"high\",\n\t\"xhigh\",\n\t\"max\",\n] as const satisfies readonly ThinkingLevel[];\n\nexport const LIVE_TEXT_LIMIT = 8 * 1024;\nexport const ACTIVITY_LIMIT = 80;\nexport const ACTIVITY_TEXT_LIMIT = 24 * 1024;\nexport const SINGLE_OUTPUT_LIMIT = 32 * 1024;\nexport const PARALLEL_TASK_OUTPUT_LIMIT = 12 * 1024;\nexport const PARALLEL_OUTPUT_LIMIT = 48 * 1024;\nexport const ERROR_TEXT_LIMIT = 8 * 1024;\nexport const DETAILS_OUTPUT_LIMIT = 120 * 1024;\n// Bounded per run inside DETAILS_OUTPUT_LIMIT; each activity costs up to\n// ~600 bytes, so 12 keeps an 8-run parallel batch from starving outputs.\nexport const DETAILS_ACTIVITY_LIMIT = 12;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEX,YAAY,EAGZ,MAAM,gCAAgC,CAAC;AA8LxC,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAgGvD","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getSupportedThinkingLevels } from \"@earendil-works/pi-ai/compat\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { discoverAgents, subagentToolDescription } from \"./agents.ts\";\nimport { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from \"./constants.ts\";\nimport { type PickerItem, SearchPickerComponent } from \"./picker.ts\";\nimport { renderSubagentCall, renderSubagentResult } from \"./render.ts\";\nimport type { ParentModelContext } from \"./resolve.ts\";\nimport { ConcurrencyGate, runSubagentInvocation, statusSummary } from \"./runner.ts\";\nimport { SubagentParamsSchema } from \"./schema.ts\";\nimport { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from \"./settings.ts\";\nimport type { AgentDefinition, AgentDiscoveryResult, SubagentDetails, SubagentProfileOverride } from \"./types.ts\";\n\nfunction formatParentModel(model: { provider: string; id: string } | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"none\";\n}\n\n// Settings resolve in two layers: a saved override wins, otherwise the\n// profile inherits the parent session. Inherited rows show the value\n// currently in effect so the menu doubles as a status view.\nfunction effectiveSettings(\n\toverride: SubagentProfileOverride | undefined,\n\tctx: ExtensionCommandContext,\n\tparentThinking: string,\n): { model: string; thinking: string } {\n\treturn {\n\t\tmodel: override?.model ?? `inherit (${formatParentModel(ctx.model)})`,\n\t\tthinking: override?.thinking ?? `inherit (${parentThinking})`,\n\t};\n}\n\n// The thinking picker lists what the effective model actually supports;\n// if the saved override names a model that is unavailable right now,\n// every level shows and the runtime clamp decides.\nfunction effectiveModelFor(\n\tctx: ExtensionCommandContext,\n\toverride: SubagentProfileOverride | undefined,\n): Model<Api> | undefined {\n\tif (override?.model) {\n\t\tconst separator = override.model.indexOf(\"/\");\n\t\tif (separator <= 0) return undefined;\n\t\treturn ctx.modelRegistry.find(override.model.slice(0, separator), override.model.slice(separator + 1));\n\t}\n\treturn ctx.model;\n}\n\nasync function pickModel(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n): Promise<void> {\n\tconst items: PickerItem<string | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${formatParentModel(ctx.model)})`,\n\t\t\tcurrent: !override?.model,\n\t\t},\n\t\t...ctx.modelRegistry.getAvailable().map((model) => ({\n\t\t\tvalue: `${model.provider}/${model.id}`,\n\t\t\tlabel: `${model.provider}/${model.id}`,\n\t\t\tdetail: model.name && model.name !== model.id ? model.name : undefined,\n\t\t\tcurrent: override?.model === `${model.provider}/${model.id}`,\n\t\t})),\n\t];\n\tconst selected = await ctx.ui.custom<string | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Model for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { model: selected ?? undefined }, getAgentDir());\n}\n\nasync function pickThinking(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n\tparentThinking: string,\n): Promise<void> {\n\tconst model = effectiveModelFor(ctx, override);\n\tconst levels = model ? (getSupportedThinkingLevels(model) as ThinkingLevel[]) : [...THINKING_LEVELS];\n\tconst items: PickerItem<ThinkingLevel | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${parentThinking})`,\n\t\t\tcurrent: !override?.thinking,\n\t\t},\n\t\t...levels.map((level) => ({ value: level, label: level, current: override?.thinking === level })),\n\t];\n\tconst selected = await ctx.ui.custom<ThinkingLevel | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Thinking for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { thinking: selected ?? undefined }, getAgentDir());\n}\n\nasync function configureProfile(\n\tctx: ExtensionCommandContext,\n\tagent: AgentDefinition,\n\tparentThinking: string,\n): Promise<void> {\n\tconst agentDir = getAgentDir();\n\twhile (true) {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst override = config.profiles[agent.name];\n\t\tconst effective = effectiveSettings(override, ctx, parentThinking);\n\t\tconst action = await ctx.ui.select(`${agent.name} — ${agent.description}`, [\n\t\t\t`Model: ${effective.model}`,\n\t\t\t`Thinking: ${effective.thinking}`,\n\t\t\t\"Back\",\n\t\t]);\n\t\tif (!action || action === \"Back\") return;\n\t\tif (action.startsWith(\"Model:\")) {\n\t\t\tawait pickModel(ctx, agent.name, override);\n\t\t\tcontinue;\n\t\t}\n\t\tawait pickThinking(ctx, agent.name, override, parentThinking);\n\t}\n}\n\nasync function syncParentProviders(\n\truntime: ModelRuntime,\n\tregistry: ModelRegistry,\n\tsyncedIds: Set<string>,\n): Promise<void> {\n\tconst nextIds = new Set(registry.getRegisteredProviderIds());\n\tfor (const id of syncedIds) {\n\t\tif (!nextIds.has(id)) runtime.unregisterProvider(id);\n\t}\n\tfor (const id of nextIds) {\n\t\tconst native = registry.getRegisteredNativeProvider(id);\n\t\tif (native) runtime.registerNativeProvider(native);\n\t\telse {\n\t\t\tconst config = registry.getRegisteredProviderConfig(id);\n\t\t\tif (config) runtime.registerProvider(id, config);\n\t\t}\n\t\tconst auth = await registry.getProviderAuth(id);\n\t\tif (auth?.auth.apiKey) await runtime.setRuntimeApiKey(id, auth.auth.apiKey, { allowNetwork: false });\n\t}\n\tsyncedIds.clear();\n\tfor (const id of nextIds) syncedIds.add(id);\n}\n\nasync function showAgentsCommand(ctx: ExtensionCommandContext, parentThinking: string): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/agents requires an interactive UI.\", \"warning\");\n\t\treturn;\n\t}\n\tconst agentDir = getAgentDir();\n\tconst reset = \"Reset all overrides\";\n\tconst done = \"Done\";\n\twhile (true) {\n\t\tconst discovery = discoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir });\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst rows = discovery.agents.map((agent) => {\n\t\t\tconst effective = effectiveSettings(config.profiles[agent.name], ctx, parentThinking);\n\t\t\treturn `${agent.name} — model: ${effective.model} · thinking: ${effective.thinking}`;\n\t\t});\n\t\tconst issueCount = discovery.diagnostics.length;\n\t\tconst issues = issueCount ? [`Show ${issueCount} agent file issue${issueCount === 1 ? \"\" : \"s\"}`] : [];\n\t\tconst action = await ctx.ui.select(\"Subagent profiles — select one to configure\", [\n\t\t\t...rows,\n\t\t\t...issues,\n\t\t\treset,\n\t\t\tdone,\n\t\t]);\n\t\tif (!action || action === done) return;\n\t\tif (action === reset) {\n\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\"Reset profile overrides?\",\n\t\t\t\t\"Clear every saved Subagent model and thinking override?\",\n\t\t\t);\n\t\t\tif (confirmed) {\n\t\t\t\tawait resetProfileOverrides(agentDir);\n\t\t\t\tctx.ui.notify(\"All profiles now inherit the parent session.\", \"info\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (issues.length > 0 && action === issues[0]) {\n\t\t\tctx.ui.notify(\n\t\t\t\tdiscovery.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`).join(\"\\n\"),\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst agent = discovery.agents.find((candidate) => action.startsWith(`${candidate.name} — `));\n\t\tif (agent) await configureProfile(ctx, agent, parentThinking);\n\t}\n}\n\nexport default function subagent(pi: ExtensionAPI): void {\n\tconst gate = new ConcurrencyGate();\n\tconst activeAborters = new Set<() => Promise<void>>();\n\tconst syncedProviderIds = new Set<string>();\n\tlet modelRuntimePromise: Promise<ModelRuntime> | undefined;\n\n\tconst getModelRuntime = async (ctx: ExtensionContext): Promise<ModelRuntime> => {\n\t\tif (!modelRuntimePromise) {\n\t\t\tconst agentDir = getAgentDir();\n\t\t\tmodelRuntimePromise = ModelRuntime.create({\n\t\t\t\tauthPath: join(agentDir, \"auth.json\"),\n\t\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\t});\n\t\t}\n\t\tconst runtime = await modelRuntimePromise;\n\t\tawait syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);\n\t\treturn runtime;\n\t};\n\n\tconst registerSubagentTool = (discovery: AgentDiscoveryResult): void => {\n\t\tpi.registerTool<typeof SubagentParamsSchema, SubagentDetails>({\n\t\t\tname: SUBAGENT_TOOL_NAME,\n\t\t\tlabel: SUBAGENT_TOOL_LABEL,\n\t\t\tdescription: subagentToolDescription(discovery),\n\t\t\tpromptSnippet: \"Delegate focused research, review, or implementation tasks to isolated subagents\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use subagent when a bounded task benefits from isolated context, parallel investigation, or a sequential specialist handoff; choose a profile and write its briefing using the tool description.\",\n\t\t\t],\n\t\t\tparameters: SubagentParamsSchema,\n\t\t\tasync execute(_toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<SubagentDetails>> {\n\t\t\t\tconst discovery = discoverAgents(ctx.cwd, {\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t});\n\t\t\t\tconst runtime = await getModelRuntime(ctx);\n\t\t\t\tconst parent: ParentModelContext = {\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tthinking: pi.getThinkingLevel(),\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t};\n\t\t\t\tconst execution = await runSubagentInvocation({\n\t\t\t\t\tparams,\n\t\t\t\t\tparentCwd: ctx.cwd,\n\t\t\t\t\tagents: discovery.agents,\n\t\t\t\t\tparent,\n\t\t\t\t\tmodelRuntime: runtime,\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t\tconfigAgentDir: getAgentDir(),\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tsignal,\n\t\t\t\t\tgate,\n\t\t\t\t\tonUpdate: (details) => {\n\t\t\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: statusSummary(details) }], details });\n\t\t\t\t\t},\n\t\t\t\t\tregisterAbort: (abort) => {\n\t\t\t\t\t\tactiveAborters.add(abort);\n\t\t\t\t\t\treturn () => activeAborters.delete(abort);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: execution.content }],\n\t\t\t\t\tdetails: execution.details,\n\t\t\t\t\tusage: execution.usage,\n\t\t\t\t};\n\t\t\t},\n\t\t\trenderCall(args, theme) {\n\t\t\t\treturn renderSubagentCall(args, theme);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderSubagentResult(result, options, theme, context.isError);\n\t\t\t},\n\t\t});\n\t};\n\n\tregisterSubagentTool(discoverAgents(process.cwd(), { projectTrusted: false, agentDir: getAgentDir() }));\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\tregisterSubagentTool(\n\t\t\tdiscoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir: getAgentDir() }),\n\t\t);\n\t});\n\n\tpi.registerCommand(SUBAGENT_COMMAND_NAME, {\n\t\tdescription: \"Configure Subagent profiles, models, and thinking levels\",\n\t\thandler: async (_args, ctx) => showAgentsCommand(ctx, pi.getThinkingLevel()),\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== SUBAGENT_TOOL_NAME) return;\n\t\tconst details = event.details as SubagentDetails | undefined;\n\t\tif (details?.status === \"failed\" || details?.status === \"aborted\") return { isError: true };\n\t});\n\n\tpi.on(\"session_shutdown\", async () => {\n\t\tawait Promise.allSettled([...activeAborters].map((abort) => abort()));\n\t\tactiveAborters.clear();\n\t});\n}\n"]}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEX,YAAY,EAGZ,MAAM,gCAAgC,CAAC;AA8LxC,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAsGvD","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getSupportedThinkingLevels } from \"@earendil-works/pi-ai/compat\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { discoverAgents, subagentToolDescription } from \"./agents.ts\";\nimport { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from \"./constants.ts\";\nimport { type PickerItem, SearchPickerComponent } from \"./picker.ts\";\nimport { renderSubagentCall, renderSubagentResult } from \"./render.ts\";\nimport type { ParentModelContext } from \"./resolve.ts\";\nimport { ConcurrencyGate, isSubagentError, runSubagentInvocation, statusSummary } from \"./runner.ts\";\nimport { SubagentParamsSchema } from \"./schema.ts\";\nimport { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from \"./settings.ts\";\nimport type { AgentDefinition, AgentDiscoveryResult, SubagentDetails, SubagentProfileOverride } from \"./types.ts\";\n\nfunction formatParentModel(model: { provider: string; id: string } | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"none\";\n}\n\n// Settings resolve in two layers: a saved override wins, otherwise the\n// profile inherits the parent session. Inherited rows show the value\n// currently in effect so the menu doubles as a status view.\nfunction effectiveSettings(\n\toverride: SubagentProfileOverride | undefined,\n\tctx: ExtensionCommandContext,\n\tparentThinking: string,\n): { model: string; thinking: string } {\n\treturn {\n\t\tmodel: override?.model ?? `inherit (${formatParentModel(ctx.model)})`,\n\t\tthinking: override?.thinking ?? `inherit (${parentThinking})`,\n\t};\n}\n\n// The thinking picker lists what the effective model actually supports;\n// if the saved override names a model that is unavailable right now,\n// every level shows and the runtime clamp decides.\nfunction effectiveModelFor(\n\tctx: ExtensionCommandContext,\n\toverride: SubagentProfileOverride | undefined,\n): Model<Api> | undefined {\n\tif (override?.model) {\n\t\tconst separator = override.model.indexOf(\"/\");\n\t\tif (separator <= 0) return undefined;\n\t\treturn ctx.modelRegistry.find(override.model.slice(0, separator), override.model.slice(separator + 1));\n\t}\n\treturn ctx.model;\n}\n\nasync function pickModel(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n): Promise<void> {\n\tconst items: PickerItem<string | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${formatParentModel(ctx.model)})`,\n\t\t\tcurrent: !override?.model,\n\t\t},\n\t\t...ctx.modelRegistry.getAvailable().map((model) => ({\n\t\t\tvalue: `${model.provider}/${model.id}`,\n\t\t\tlabel: `${model.provider}/${model.id}`,\n\t\t\tdetail: model.name && model.name !== model.id ? model.name : undefined,\n\t\t\tcurrent: override?.model === `${model.provider}/${model.id}`,\n\t\t})),\n\t];\n\tconst selected = await ctx.ui.custom<string | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Model for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { model: selected ?? undefined }, getAgentDir());\n}\n\nasync function pickThinking(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n\tparentThinking: string,\n): Promise<void> {\n\tconst model = effectiveModelFor(ctx, override);\n\tconst levels = model ? (getSupportedThinkingLevels(model) as ThinkingLevel[]) : [...THINKING_LEVELS];\n\tconst items: PickerItem<ThinkingLevel | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${parentThinking})`,\n\t\t\tcurrent: !override?.thinking,\n\t\t},\n\t\t...levels.map((level) => ({ value: level, label: level, current: override?.thinking === level })),\n\t];\n\tconst selected = await ctx.ui.custom<ThinkingLevel | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Thinking for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { thinking: selected ?? undefined }, getAgentDir());\n}\n\nasync function configureProfile(\n\tctx: ExtensionCommandContext,\n\tagent: AgentDefinition,\n\tparentThinking: string,\n): Promise<void> {\n\tconst agentDir = getAgentDir();\n\twhile (true) {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst override = config.profiles[agent.name];\n\t\tconst effective = effectiveSettings(override, ctx, parentThinking);\n\t\tconst action = await ctx.ui.select(`${agent.name} — ${agent.description}`, [\n\t\t\t`Model: ${effective.model}`,\n\t\t\t`Thinking: ${effective.thinking}`,\n\t\t\t\"Back\",\n\t\t]);\n\t\tif (!action || action === \"Back\") return;\n\t\tif (action.startsWith(\"Model:\")) {\n\t\t\tawait pickModel(ctx, agent.name, override);\n\t\t\tcontinue;\n\t\t}\n\t\tawait pickThinking(ctx, agent.name, override, parentThinking);\n\t}\n}\n\nasync function syncParentProviders(\n\truntime: ModelRuntime,\n\tregistry: ModelRegistry,\n\tsyncedIds: Set<string>,\n): Promise<void> {\n\tconst nextIds = new Set(registry.getRegisteredProviderIds());\n\tfor (const id of syncedIds) {\n\t\tif (!nextIds.has(id)) runtime.unregisterProvider(id);\n\t}\n\tfor (const id of nextIds) {\n\t\tconst native = registry.getRegisteredNativeProvider(id);\n\t\tif (native) runtime.registerNativeProvider(native);\n\t\telse {\n\t\t\tconst config = registry.getRegisteredProviderConfig(id);\n\t\t\tif (config) runtime.registerProvider(id, config);\n\t\t}\n\t\tconst auth = await registry.getProviderAuth(id);\n\t\tif (auth?.auth.apiKey) await runtime.setRuntimeApiKey(id, auth.auth.apiKey, { allowNetwork: false });\n\t}\n\tsyncedIds.clear();\n\tfor (const id of nextIds) syncedIds.add(id);\n}\n\nasync function showAgentsCommand(ctx: ExtensionCommandContext, parentThinking: string): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/agents requires an interactive UI.\", \"warning\");\n\t\treturn;\n\t}\n\tconst agentDir = getAgentDir();\n\tconst reset = \"Reset all overrides\";\n\tconst done = \"Done\";\n\twhile (true) {\n\t\tconst discovery = discoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir });\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst rows = discovery.agents.map((agent) => {\n\t\t\tconst effective = effectiveSettings(config.profiles[agent.name], ctx, parentThinking);\n\t\t\treturn `${agent.name} — model: ${effective.model} · thinking: ${effective.thinking}`;\n\t\t});\n\t\tconst issueCount = discovery.diagnostics.length;\n\t\tconst issues = issueCount ? [`Show ${issueCount} agent file issue${issueCount === 1 ? \"\" : \"s\"}`] : [];\n\t\tconst action = await ctx.ui.select(\"Subagent profiles — select one to configure\", [\n\t\t\t...rows,\n\t\t\t...issues,\n\t\t\treset,\n\t\t\tdone,\n\t\t]);\n\t\tif (!action || action === done) return;\n\t\tif (action === reset) {\n\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\"Reset profile overrides?\",\n\t\t\t\t\"Clear every saved Subagent model and thinking override?\",\n\t\t\t);\n\t\t\tif (confirmed) {\n\t\t\t\tawait resetProfileOverrides(agentDir);\n\t\t\t\tctx.ui.notify(\"All profiles now inherit the parent session.\", \"info\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (issues.length > 0 && action === issues[0]) {\n\t\t\tctx.ui.notify(\n\t\t\t\tdiscovery.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`).join(\"\\n\"),\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst agent = discovery.agents.find((candidate) => action.startsWith(`${candidate.name} — `));\n\t\tif (agent) await configureProfile(ctx, agent, parentThinking);\n\t}\n}\n\nexport default function subagent(pi: ExtensionAPI): void {\n\tconst gate = new ConcurrencyGate();\n\tconst activeAborters = new Set<() => Promise<void>>();\n\tconst syncedProviderIds = new Set<string>();\n\tlet modelRuntimePromise: Promise<ModelRuntime> | undefined;\n\n\tconst getModelRuntime = async (ctx: ExtensionContext): Promise<ModelRuntime> => {\n\t\tif (!modelRuntimePromise) {\n\t\t\tconst agentDir = getAgentDir();\n\t\t\tconst created = ModelRuntime.create({\n\t\t\t\tauthPath: join(agentDir, \"auth.json\"),\n\t\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\t});\n\t\t\t// A transient failure (network, filesystem) must not brick the tool\n\t\t\t// for the rest of the session: drop the rejected promise so the\n\t\t\t// next invocation retries creation.\n\t\t\tcreated.catch(() => {\n\t\t\t\tif (modelRuntimePromise === created) modelRuntimePromise = undefined;\n\t\t\t});\n\t\t\tmodelRuntimePromise = created;\n\t\t}\n\t\tconst runtime = await modelRuntimePromise;\n\t\tawait syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);\n\t\treturn runtime;\n\t};\n\n\tconst registerSubagentTool = (discovery: AgentDiscoveryResult): void => {\n\t\tpi.registerTool<typeof SubagentParamsSchema, SubagentDetails>({\n\t\t\tname: SUBAGENT_TOOL_NAME,\n\t\t\tlabel: SUBAGENT_TOOL_LABEL,\n\t\t\tdescription: subagentToolDescription(discovery),\n\t\t\tpromptSnippet: \"Delegate focused research, review, or implementation tasks to isolated subagents\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use subagent when a bounded task benefits from isolated context or parallel investigation; choose a profile and write its briefing using the tool description.\",\n\t\t\t],\n\t\t\tparameters: SubagentParamsSchema,\n\t\t\tasync execute(_toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<SubagentDetails>> {\n\t\t\t\tconst discovery = discoverAgents(ctx.cwd, {\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t});\n\t\t\t\tconst runtime = await getModelRuntime(ctx);\n\t\t\t\tconst parent: ParentModelContext = {\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tthinking: pi.getThinkingLevel(),\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t};\n\t\t\t\tconst execution = await runSubagentInvocation({\n\t\t\t\t\tparams,\n\t\t\t\t\tparentCwd: ctx.cwd,\n\t\t\t\t\tagents: discovery.agents,\n\t\t\t\t\tparent,\n\t\t\t\t\tmodelRuntime: runtime,\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tsignal,\n\t\t\t\t\tgate,\n\t\t\t\t\tonUpdate: (details) => {\n\t\t\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: statusSummary(details) }], details });\n\t\t\t\t\t},\n\t\t\t\t\tregisterAbort: (abort) => {\n\t\t\t\t\t\tactiveAborters.add(abort);\n\t\t\t\t\t\treturn () => activeAborters.delete(abort);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: execution.content }],\n\t\t\t\t\tdetails: execution.details,\n\t\t\t\t\tusage: execution.usage,\n\t\t\t\t};\n\t\t\t},\n\t\t\trenderCall(args, theme) {\n\t\t\t\treturn renderSubagentCall(args, theme);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderSubagentResult(result, options, theme, context.isError);\n\t\t\t},\n\t\t});\n\t};\n\n\tregisterSubagentTool(discoverAgents(process.cwd(), { projectTrusted: false, agentDir: getAgentDir() }));\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\tregisterSubagentTool(\n\t\t\tdiscoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir: getAgentDir() }),\n\t\t);\n\t});\n\n\tpi.registerCommand(SUBAGENT_COMMAND_NAME, {\n\t\tdescription: \"Configure Subagent profiles, models, and thinking levels\",\n\t\thandler: async (_args, ctx) => showAgentsCommand(ctx, pi.getThinkingLevel()),\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== SUBAGENT_TOOL_NAME) return;\n\t\tconst details = event.details as SubagentDetails | undefined;\n\t\tif (details && isSubagentError(details)) return { isError: true };\n\t});\n\n\tpi.on(\"session_shutdown\", async () => {\n\t\tawait Promise.allSettled([...activeAborters].map((abort) => abort()));\n\t\tactiveAborters.clear();\n\t});\n}\n"]}
@@ -6,7 +6,7 @@ import { discoverAgents, subagentToolDescription } from "./agents.js";
6
6
  import { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from "./constants.js";
7
7
  import { SearchPickerComponent } from "./picker.js";
8
8
  import { renderSubagentCall, renderSubagentResult } from "./render.js";
9
- import { ConcurrencyGate, runSubagentInvocation, statusSummary } from "./runner.js";
9
+ import { ConcurrencyGate, isSubagentError, runSubagentInvocation, statusSummary } from "./runner.js";
10
10
  import { SubagentParamsSchema } from "./schema.js";
11
11
  import { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from "./settings.js";
12
12
  function formatParentModel(model) {
@@ -163,10 +163,18 @@ export default function subagent(pi) {
163
163
  const getModelRuntime = async (ctx) => {
164
164
  if (!modelRuntimePromise) {
165
165
  const agentDir = getAgentDir();
166
- modelRuntimePromise = ModelRuntime.create({
166
+ const created = ModelRuntime.create({
167
167
  authPath: join(agentDir, "auth.json"),
168
168
  modelsPath: join(agentDir, "models.json"),
169
169
  });
170
+ // A transient failure (network, filesystem) must not brick the tool
171
+ // for the rest of the session: drop the rejected promise so the
172
+ // next invocation retries creation.
173
+ created.catch(() => {
174
+ if (modelRuntimePromise === created)
175
+ modelRuntimePromise = undefined;
176
+ });
177
+ modelRuntimePromise = created;
170
178
  }
171
179
  const runtime = await modelRuntimePromise;
172
180
  await syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);
@@ -179,7 +187,7 @@ export default function subagent(pi) {
179
187
  description: subagentToolDescription(discovery),
180
188
  promptSnippet: "Delegate focused research, review, or implementation tasks to isolated subagents",
181
189
  promptGuidelines: [
182
- "Use subagent when a bounded task benefits from isolated context, parallel investigation, or a sequential specialist handoff; choose a profile and write its briefing using the tool description.",
190
+ "Use subagent when a bounded task benefits from isolated context or parallel investigation; choose a profile and write its briefing using the tool description.",
183
191
  ],
184
192
  parameters: SubagentParamsSchema,
185
193
  async execute(_toolCallId, params, signal, onUpdate, ctx) {
@@ -200,7 +208,6 @@ export default function subagent(pi) {
200
208
  parent,
201
209
  modelRuntime: runtime,
202
210
  agentDir: getAgentDir(),
203
- configAgentDir: getAgentDir(),
204
211
  projectTrusted: ctx.isProjectTrusted(),
205
212
  signal,
206
213
  gate,
@@ -238,7 +245,7 @@ export default function subagent(pi) {
238
245
  if (event.toolName !== SUBAGENT_TOOL_NAME)
239
246
  return;
240
247
  const details = event.details;
241
- if (details?.status === "failed" || details?.status === "aborted")
248
+ if (details && isSubagentError(details))
242
249
  return { isError: true };
243
250
  });
244
251
  pi.on("session_shutdown", async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/subagent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQ9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjH,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,qBAA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MAAM,OAAO,GAAG,KAAK,CAAC,OAAsC,CAAC;QAC7D,IAAI,OAAO,EAAE,MAAM,KAAK,QAAQ,IAAI,OAAO,EAAE,MAAM,KAAK,SAAS;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAAA,CAC5F,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE,CAAC;QACrC,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACtE,cAAc,CAAC,KAAK,EAAE,CAAC;IAAA,CACvB,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getSupportedThinkingLevels } from \"@earendil-works/pi-ai/compat\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { discoverAgents, subagentToolDescription } from \"./agents.ts\";\nimport { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from \"./constants.ts\";\nimport { type PickerItem, SearchPickerComponent } from \"./picker.ts\";\nimport { renderSubagentCall, renderSubagentResult } from \"./render.ts\";\nimport type { ParentModelContext } from \"./resolve.ts\";\nimport { ConcurrencyGate, runSubagentInvocation, statusSummary } from \"./runner.ts\";\nimport { SubagentParamsSchema } from \"./schema.ts\";\nimport { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from \"./settings.ts\";\nimport type { AgentDefinition, AgentDiscoveryResult, SubagentDetails, SubagentProfileOverride } from \"./types.ts\";\n\nfunction formatParentModel(model: { provider: string; id: string } | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"none\";\n}\n\n// Settings resolve in two layers: a saved override wins, otherwise the\n// profile inherits the parent session. Inherited rows show the value\n// currently in effect so the menu doubles as a status view.\nfunction effectiveSettings(\n\toverride: SubagentProfileOverride | undefined,\n\tctx: ExtensionCommandContext,\n\tparentThinking: string,\n): { model: string; thinking: string } {\n\treturn {\n\t\tmodel: override?.model ?? `inherit (${formatParentModel(ctx.model)})`,\n\t\tthinking: override?.thinking ?? `inherit (${parentThinking})`,\n\t};\n}\n\n// The thinking picker lists what the effective model actually supports;\n// if the saved override names a model that is unavailable right now,\n// every level shows and the runtime clamp decides.\nfunction effectiveModelFor(\n\tctx: ExtensionCommandContext,\n\toverride: SubagentProfileOverride | undefined,\n): Model<Api> | undefined {\n\tif (override?.model) {\n\t\tconst separator = override.model.indexOf(\"/\");\n\t\tif (separator <= 0) return undefined;\n\t\treturn ctx.modelRegistry.find(override.model.slice(0, separator), override.model.slice(separator + 1));\n\t}\n\treturn ctx.model;\n}\n\nasync function pickModel(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n): Promise<void> {\n\tconst items: PickerItem<string | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${formatParentModel(ctx.model)})`,\n\t\t\tcurrent: !override?.model,\n\t\t},\n\t\t...ctx.modelRegistry.getAvailable().map((model) => ({\n\t\t\tvalue: `${model.provider}/${model.id}`,\n\t\t\tlabel: `${model.provider}/${model.id}`,\n\t\t\tdetail: model.name && model.name !== model.id ? model.name : undefined,\n\t\t\tcurrent: override?.model === `${model.provider}/${model.id}`,\n\t\t})),\n\t];\n\tconst selected = await ctx.ui.custom<string | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Model for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { model: selected ?? undefined }, getAgentDir());\n}\n\nasync function pickThinking(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n\tparentThinking: string,\n): Promise<void> {\n\tconst model = effectiveModelFor(ctx, override);\n\tconst levels = model ? (getSupportedThinkingLevels(model) as ThinkingLevel[]) : [...THINKING_LEVELS];\n\tconst items: PickerItem<ThinkingLevel | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${parentThinking})`,\n\t\t\tcurrent: !override?.thinking,\n\t\t},\n\t\t...levels.map((level) => ({ value: level, label: level, current: override?.thinking === level })),\n\t];\n\tconst selected = await ctx.ui.custom<ThinkingLevel | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Thinking for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { thinking: selected ?? undefined }, getAgentDir());\n}\n\nasync function configureProfile(\n\tctx: ExtensionCommandContext,\n\tagent: AgentDefinition,\n\tparentThinking: string,\n): Promise<void> {\n\tconst agentDir = getAgentDir();\n\twhile (true) {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst override = config.profiles[agent.name];\n\t\tconst effective = effectiveSettings(override, ctx, parentThinking);\n\t\tconst action = await ctx.ui.select(`${agent.name} — ${agent.description}`, [\n\t\t\t`Model: ${effective.model}`,\n\t\t\t`Thinking: ${effective.thinking}`,\n\t\t\t\"Back\",\n\t\t]);\n\t\tif (!action || action === \"Back\") return;\n\t\tif (action.startsWith(\"Model:\")) {\n\t\t\tawait pickModel(ctx, agent.name, override);\n\t\t\tcontinue;\n\t\t}\n\t\tawait pickThinking(ctx, agent.name, override, parentThinking);\n\t}\n}\n\nasync function syncParentProviders(\n\truntime: ModelRuntime,\n\tregistry: ModelRegistry,\n\tsyncedIds: Set<string>,\n): Promise<void> {\n\tconst nextIds = new Set(registry.getRegisteredProviderIds());\n\tfor (const id of syncedIds) {\n\t\tif (!nextIds.has(id)) runtime.unregisterProvider(id);\n\t}\n\tfor (const id of nextIds) {\n\t\tconst native = registry.getRegisteredNativeProvider(id);\n\t\tif (native) runtime.registerNativeProvider(native);\n\t\telse {\n\t\t\tconst config = registry.getRegisteredProviderConfig(id);\n\t\t\tif (config) runtime.registerProvider(id, config);\n\t\t}\n\t\tconst auth = await registry.getProviderAuth(id);\n\t\tif (auth?.auth.apiKey) await runtime.setRuntimeApiKey(id, auth.auth.apiKey, { allowNetwork: false });\n\t}\n\tsyncedIds.clear();\n\tfor (const id of nextIds) syncedIds.add(id);\n}\n\nasync function showAgentsCommand(ctx: ExtensionCommandContext, parentThinking: string): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/agents requires an interactive UI.\", \"warning\");\n\t\treturn;\n\t}\n\tconst agentDir = getAgentDir();\n\tconst reset = \"Reset all overrides\";\n\tconst done = \"Done\";\n\twhile (true) {\n\t\tconst discovery = discoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir });\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst rows = discovery.agents.map((agent) => {\n\t\t\tconst effective = effectiveSettings(config.profiles[agent.name], ctx, parentThinking);\n\t\t\treturn `${agent.name} — model: ${effective.model} · thinking: ${effective.thinking}`;\n\t\t});\n\t\tconst issueCount = discovery.diagnostics.length;\n\t\tconst issues = issueCount ? [`Show ${issueCount} agent file issue${issueCount === 1 ? \"\" : \"s\"}`] : [];\n\t\tconst action = await ctx.ui.select(\"Subagent profiles — select one to configure\", [\n\t\t\t...rows,\n\t\t\t...issues,\n\t\t\treset,\n\t\t\tdone,\n\t\t]);\n\t\tif (!action || action === done) return;\n\t\tif (action === reset) {\n\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\"Reset profile overrides?\",\n\t\t\t\t\"Clear every saved Subagent model and thinking override?\",\n\t\t\t);\n\t\t\tif (confirmed) {\n\t\t\t\tawait resetProfileOverrides(agentDir);\n\t\t\t\tctx.ui.notify(\"All profiles now inherit the parent session.\", \"info\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (issues.length > 0 && action === issues[0]) {\n\t\t\tctx.ui.notify(\n\t\t\t\tdiscovery.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`).join(\"\\n\"),\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst agent = discovery.agents.find((candidate) => action.startsWith(`${candidate.name} — `));\n\t\tif (agent) await configureProfile(ctx, agent, parentThinking);\n\t}\n}\n\nexport default function subagent(pi: ExtensionAPI): void {\n\tconst gate = new ConcurrencyGate();\n\tconst activeAborters = new Set<() => Promise<void>>();\n\tconst syncedProviderIds = new Set<string>();\n\tlet modelRuntimePromise: Promise<ModelRuntime> | undefined;\n\n\tconst getModelRuntime = async (ctx: ExtensionContext): Promise<ModelRuntime> => {\n\t\tif (!modelRuntimePromise) {\n\t\t\tconst agentDir = getAgentDir();\n\t\t\tmodelRuntimePromise = ModelRuntime.create({\n\t\t\t\tauthPath: join(agentDir, \"auth.json\"),\n\t\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\t});\n\t\t}\n\t\tconst runtime = await modelRuntimePromise;\n\t\tawait syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);\n\t\treturn runtime;\n\t};\n\n\tconst registerSubagentTool = (discovery: AgentDiscoveryResult): void => {\n\t\tpi.registerTool<typeof SubagentParamsSchema, SubagentDetails>({\n\t\t\tname: SUBAGENT_TOOL_NAME,\n\t\t\tlabel: SUBAGENT_TOOL_LABEL,\n\t\t\tdescription: subagentToolDescription(discovery),\n\t\t\tpromptSnippet: \"Delegate focused research, review, or implementation tasks to isolated subagents\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use subagent when a bounded task benefits from isolated context, parallel investigation, or a sequential specialist handoff; choose a profile and write its briefing using the tool description.\",\n\t\t\t],\n\t\t\tparameters: SubagentParamsSchema,\n\t\t\tasync execute(_toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<SubagentDetails>> {\n\t\t\t\tconst discovery = discoverAgents(ctx.cwd, {\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t});\n\t\t\t\tconst runtime = await getModelRuntime(ctx);\n\t\t\t\tconst parent: ParentModelContext = {\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tthinking: pi.getThinkingLevel(),\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t};\n\t\t\t\tconst execution = await runSubagentInvocation({\n\t\t\t\t\tparams,\n\t\t\t\t\tparentCwd: ctx.cwd,\n\t\t\t\t\tagents: discovery.agents,\n\t\t\t\t\tparent,\n\t\t\t\t\tmodelRuntime: runtime,\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t\tconfigAgentDir: getAgentDir(),\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tsignal,\n\t\t\t\t\tgate,\n\t\t\t\t\tonUpdate: (details) => {\n\t\t\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: statusSummary(details) }], details });\n\t\t\t\t\t},\n\t\t\t\t\tregisterAbort: (abort) => {\n\t\t\t\t\t\tactiveAborters.add(abort);\n\t\t\t\t\t\treturn () => activeAborters.delete(abort);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: execution.content }],\n\t\t\t\t\tdetails: execution.details,\n\t\t\t\t\tusage: execution.usage,\n\t\t\t\t};\n\t\t\t},\n\t\t\trenderCall(args, theme) {\n\t\t\t\treturn renderSubagentCall(args, theme);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderSubagentResult(result, options, theme, context.isError);\n\t\t\t},\n\t\t});\n\t};\n\n\tregisterSubagentTool(discoverAgents(process.cwd(), { projectTrusted: false, agentDir: getAgentDir() }));\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\tregisterSubagentTool(\n\t\t\tdiscoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir: getAgentDir() }),\n\t\t);\n\t});\n\n\tpi.registerCommand(SUBAGENT_COMMAND_NAME, {\n\t\tdescription: \"Configure Subagent profiles, models, and thinking levels\",\n\t\thandler: async (_args, ctx) => showAgentsCommand(ctx, pi.getThinkingLevel()),\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== SUBAGENT_TOOL_NAME) return;\n\t\tconst details = event.details as SubagentDetails | undefined;\n\t\tif (details?.status === \"failed\" || details?.status === \"aborted\") return { isError: true };\n\t});\n\n\tpi.on(\"session_shutdown\", async () => {\n\t\tawait Promise.allSettled([...activeAborters].map((abort) => abort()));\n\t\tactiveAborters.clear();\n\t});\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/subagent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQ9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjH,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,qBAAqB,EAAE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AW,EAAE,0DAA0D;QACvE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,iBAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC;KAC5E,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;QACrC,IAAI,KAAK,CAAC,QAAQ,KAAK,kBAAkB;YAAE,OAAO;QAClD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAsC,CAAC;QAC7D,IAAI,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAAA,CAClE,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE,CAAC;QACrC,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACtE,cAAc,CAAC,KAAK,EAAE,CAAC;IAAA,CACvB,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getSupportedThinkingLevels } from \"@earendil-works/pi-ai/compat\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { discoverAgents, subagentToolDescription } from \"./agents.ts\";\nimport { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from \"./constants.ts\";\nimport { type PickerItem, SearchPickerComponent } from \"./picker.ts\";\nimport { renderSubagentCall, renderSubagentResult } from \"./render.ts\";\nimport type { ParentModelContext } from \"./resolve.ts\";\nimport { ConcurrencyGate, isSubagentError, runSubagentInvocation, statusSummary } from \"./runner.ts\";\nimport { SubagentParamsSchema } from \"./schema.ts\";\nimport { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from \"./settings.ts\";\nimport type { AgentDefinition, AgentDiscoveryResult, SubagentDetails, SubagentProfileOverride } from \"./types.ts\";\n\nfunction formatParentModel(model: { provider: string; id: string } | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"none\";\n}\n\n// Settings resolve in two layers: a saved override wins, otherwise the\n// profile inherits the parent session. Inherited rows show the value\n// currently in effect so the menu doubles as a status view.\nfunction effectiveSettings(\n\toverride: SubagentProfileOverride | undefined,\n\tctx: ExtensionCommandContext,\n\tparentThinking: string,\n): { model: string; thinking: string } {\n\treturn {\n\t\tmodel: override?.model ?? `inherit (${formatParentModel(ctx.model)})`,\n\t\tthinking: override?.thinking ?? `inherit (${parentThinking})`,\n\t};\n}\n\n// The thinking picker lists what the effective model actually supports;\n// if the saved override names a model that is unavailable right now,\n// every level shows and the runtime clamp decides.\nfunction effectiveModelFor(\n\tctx: ExtensionCommandContext,\n\toverride: SubagentProfileOverride | undefined,\n): Model<Api> | undefined {\n\tif (override?.model) {\n\t\tconst separator = override.model.indexOf(\"/\");\n\t\tif (separator <= 0) return undefined;\n\t\treturn ctx.modelRegistry.find(override.model.slice(0, separator), override.model.slice(separator + 1));\n\t}\n\treturn ctx.model;\n}\n\nasync function pickModel(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n): Promise<void> {\n\tconst items: PickerItem<string | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${formatParentModel(ctx.model)})`,\n\t\t\tcurrent: !override?.model,\n\t\t},\n\t\t...ctx.modelRegistry.getAvailable().map((model) => ({\n\t\t\tvalue: `${model.provider}/${model.id}`,\n\t\t\tlabel: `${model.provider}/${model.id}`,\n\t\t\tdetail: model.name && model.name !== model.id ? model.name : undefined,\n\t\t\tcurrent: override?.model === `${model.provider}/${model.id}`,\n\t\t})),\n\t];\n\tconst selected = await ctx.ui.custom<string | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Model for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { model: selected ?? undefined }, getAgentDir());\n}\n\nasync function pickThinking(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n\tparentThinking: string,\n): Promise<void> {\n\tconst model = effectiveModelFor(ctx, override);\n\tconst levels = model ? (getSupportedThinkingLevels(model) as ThinkingLevel[]) : [...THINKING_LEVELS];\n\tconst items: PickerItem<ThinkingLevel | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${parentThinking})`,\n\t\t\tcurrent: !override?.thinking,\n\t\t},\n\t\t...levels.map((level) => ({ value: level, label: level, current: override?.thinking === level })),\n\t];\n\tconst selected = await ctx.ui.custom<ThinkingLevel | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Thinking for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { thinking: selected ?? undefined }, getAgentDir());\n}\n\nasync function configureProfile(\n\tctx: ExtensionCommandContext,\n\tagent: AgentDefinition,\n\tparentThinking: string,\n): Promise<void> {\n\tconst agentDir = getAgentDir();\n\twhile (true) {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst override = config.profiles[agent.name];\n\t\tconst effective = effectiveSettings(override, ctx, parentThinking);\n\t\tconst action = await ctx.ui.select(`${agent.name} — ${agent.description}`, [\n\t\t\t`Model: ${effective.model}`,\n\t\t\t`Thinking: ${effective.thinking}`,\n\t\t\t\"Back\",\n\t\t]);\n\t\tif (!action || action === \"Back\") return;\n\t\tif (action.startsWith(\"Model:\")) {\n\t\t\tawait pickModel(ctx, agent.name, override);\n\t\t\tcontinue;\n\t\t}\n\t\tawait pickThinking(ctx, agent.name, override, parentThinking);\n\t}\n}\n\nasync function syncParentProviders(\n\truntime: ModelRuntime,\n\tregistry: ModelRegistry,\n\tsyncedIds: Set<string>,\n): Promise<void> {\n\tconst nextIds = new Set(registry.getRegisteredProviderIds());\n\tfor (const id of syncedIds) {\n\t\tif (!nextIds.has(id)) runtime.unregisterProvider(id);\n\t}\n\tfor (const id of nextIds) {\n\t\tconst native = registry.getRegisteredNativeProvider(id);\n\t\tif (native) runtime.registerNativeProvider(native);\n\t\telse {\n\t\t\tconst config = registry.getRegisteredProviderConfig(id);\n\t\t\tif (config) runtime.registerProvider(id, config);\n\t\t}\n\t\tconst auth = await registry.getProviderAuth(id);\n\t\tif (auth?.auth.apiKey) await runtime.setRuntimeApiKey(id, auth.auth.apiKey, { allowNetwork: false });\n\t}\n\tsyncedIds.clear();\n\tfor (const id of nextIds) syncedIds.add(id);\n}\n\nasync function showAgentsCommand(ctx: ExtensionCommandContext, parentThinking: string): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/agents requires an interactive UI.\", \"warning\");\n\t\treturn;\n\t}\n\tconst agentDir = getAgentDir();\n\tconst reset = \"Reset all overrides\";\n\tconst done = \"Done\";\n\twhile (true) {\n\t\tconst discovery = discoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir });\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst rows = discovery.agents.map((agent) => {\n\t\t\tconst effective = effectiveSettings(config.profiles[agent.name], ctx, parentThinking);\n\t\t\treturn `${agent.name} — model: ${effective.model} · thinking: ${effective.thinking}`;\n\t\t});\n\t\tconst issueCount = discovery.diagnostics.length;\n\t\tconst issues = issueCount ? [`Show ${issueCount} agent file issue${issueCount === 1 ? \"\" : \"s\"}`] : [];\n\t\tconst action = await ctx.ui.select(\"Subagent profiles — select one to configure\", [\n\t\t\t...rows,\n\t\t\t...issues,\n\t\t\treset,\n\t\t\tdone,\n\t\t]);\n\t\tif (!action || action === done) return;\n\t\tif (action === reset) {\n\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\"Reset profile overrides?\",\n\t\t\t\t\"Clear every saved Subagent model and thinking override?\",\n\t\t\t);\n\t\t\tif (confirmed) {\n\t\t\t\tawait resetProfileOverrides(agentDir);\n\t\t\t\tctx.ui.notify(\"All profiles now inherit the parent session.\", \"info\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (issues.length > 0 && action === issues[0]) {\n\t\t\tctx.ui.notify(\n\t\t\t\tdiscovery.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`).join(\"\\n\"),\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst agent = discovery.agents.find((candidate) => action.startsWith(`${candidate.name} — `));\n\t\tif (agent) await configureProfile(ctx, agent, parentThinking);\n\t}\n}\n\nexport default function subagent(pi: ExtensionAPI): void {\n\tconst gate = new ConcurrencyGate();\n\tconst activeAborters = new Set<() => Promise<void>>();\n\tconst syncedProviderIds = new Set<string>();\n\tlet modelRuntimePromise: Promise<ModelRuntime> | undefined;\n\n\tconst getModelRuntime = async (ctx: ExtensionContext): Promise<ModelRuntime> => {\n\t\tif (!modelRuntimePromise) {\n\t\t\tconst agentDir = getAgentDir();\n\t\t\tconst created = ModelRuntime.create({\n\t\t\t\tauthPath: join(agentDir, \"auth.json\"),\n\t\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\t});\n\t\t\t// A transient failure (network, filesystem) must not brick the tool\n\t\t\t// for the rest of the session: drop the rejected promise so the\n\t\t\t// next invocation retries creation.\n\t\t\tcreated.catch(() => {\n\t\t\t\tif (modelRuntimePromise === created) modelRuntimePromise = undefined;\n\t\t\t});\n\t\t\tmodelRuntimePromise = created;\n\t\t}\n\t\tconst runtime = await modelRuntimePromise;\n\t\tawait syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);\n\t\treturn runtime;\n\t};\n\n\tconst registerSubagentTool = (discovery: AgentDiscoveryResult): void => {\n\t\tpi.registerTool<typeof SubagentParamsSchema, SubagentDetails>({\n\t\t\tname: SUBAGENT_TOOL_NAME,\n\t\t\tlabel: SUBAGENT_TOOL_LABEL,\n\t\t\tdescription: subagentToolDescription(discovery),\n\t\t\tpromptSnippet: \"Delegate focused research, review, or implementation tasks to isolated subagents\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use subagent when a bounded task benefits from isolated context or parallel investigation; choose a profile and write its briefing using the tool description.\",\n\t\t\t],\n\t\t\tparameters: SubagentParamsSchema,\n\t\t\tasync execute(_toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<SubagentDetails>> {\n\t\t\t\tconst discovery = discoverAgents(ctx.cwd, {\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t});\n\t\t\t\tconst runtime = await getModelRuntime(ctx);\n\t\t\t\tconst parent: ParentModelContext = {\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tthinking: pi.getThinkingLevel(),\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t};\n\t\t\t\tconst execution = await runSubagentInvocation({\n\t\t\t\t\tparams,\n\t\t\t\t\tparentCwd: ctx.cwd,\n\t\t\t\t\tagents: discovery.agents,\n\t\t\t\t\tparent,\n\t\t\t\t\tmodelRuntime: runtime,\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tsignal,\n\t\t\t\t\tgate,\n\t\t\t\t\tonUpdate: (details) => {\n\t\t\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: statusSummary(details) }], details });\n\t\t\t\t\t},\n\t\t\t\t\tregisterAbort: (abort) => {\n\t\t\t\t\t\tactiveAborters.add(abort);\n\t\t\t\t\t\treturn () => activeAborters.delete(abort);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: execution.content }],\n\t\t\t\t\tdetails: execution.details,\n\t\t\t\t\tusage: execution.usage,\n\t\t\t\t};\n\t\t\t},\n\t\t\trenderCall(args, theme) {\n\t\t\t\treturn renderSubagentCall(args, theme);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderSubagentResult(result, options, theme, context.isError);\n\t\t\t},\n\t\t});\n\t};\n\n\tregisterSubagentTool(discoverAgents(process.cwd(), { projectTrusted: false, agentDir: getAgentDir() }));\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\tregisterSubagentTool(\n\t\t\tdiscoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir: getAgentDir() }),\n\t\t);\n\t});\n\n\tpi.registerCommand(SUBAGENT_COMMAND_NAME, {\n\t\tdescription: \"Configure Subagent profiles, models, and thinking levels\",\n\t\thandler: async (_args, ctx) => showAgentsCommand(ctx, pi.getThinkingLevel()),\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== SUBAGENT_TOOL_NAME) return;\n\t\tconst details = event.details as SubagentDetails | undefined;\n\t\tif (details && isSubagentError(details)) return { isError: true };\n\t});\n\n\tpi.on(\"session_shutdown\", async () => {\n\t\tawait Promise.allSettled([...activeAborters].map((abort) => abort()));\n\t\tactiveAborters.clear();\n\t});\n}\n"]}