@kolisachint/hoocode-agent 0.4.16 → 0.4.18

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 (42) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/core/dispatch-evaluator.d.ts +9 -36
  3. package/dist/core/dispatch-evaluator.d.ts.map +1 -1
  4. package/dist/core/dispatch-evaluator.js +11 -302
  5. package/dist/core/dispatch-evaluator.js.map +1 -1
  6. package/dist/core/subagent-pool.d.ts +7 -13
  7. package/dist/core/subagent-pool.d.ts.map +1 -1
  8. package/dist/core/subagent-pool.js +35 -44
  9. package/dist/core/subagent-pool.js.map +1 -1
  10. package/dist/core/token-budget.d.ts +4 -0
  11. package/dist/core/token-budget.d.ts.map +1 -1
  12. package/dist/core/token-budget.js +4 -2
  13. package/dist/core/token-budget.js.map +1 -1
  14. package/dist/core/tools/subagent.d.ts +0 -3
  15. package/dist/core/tools/subagent.d.ts.map +1 -1
  16. package/dist/core/tools/subagent.js +0 -6
  17. package/dist/core/tools/subagent.js.map +1 -1
  18. package/dist/init-templates.generated.d.ts +0 -1
  19. package/dist/init-templates.generated.d.ts.map +1 -1
  20. package/dist/init-templates.generated.js +5 -13
  21. package/dist/init-templates.generated.js.map +1 -1
  22. package/docs/routing.md +48 -36
  23. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  24. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  25. package/examples/extensions/sandbox/package.json +1 -1
  26. package/examples/extensions/with-deps/package.json +1 -1
  27. package/package.json +4 -4
  28. package/templates/agents/doc.md +1 -0
  29. package/templates/agents/edit.md +1 -0
  30. package/templates/agents/explore.md +1 -0
  31. package/templates/agents/review.md +1 -0
  32. package/templates/agents/test.md +1 -0
  33. package/dist/core/subagent.d.ts +0 -14
  34. package/dist/core/subagent.d.ts.map +0 -1
  35. package/dist/core/subagent.js +0 -27
  36. package/dist/core/subagent.js.map +0 -1
  37. package/templates/subagent/doc.md +0 -16
  38. package/templates/subagent/edit.md +0 -22
  39. package/templates/subagent/explore.md +0 -21
  40. package/templates/subagent/fix.md +0 -22
  41. package/templates/subagent/review.md +0 -21
  42. package/templates/subagent/test.md +0 -20
@@ -8,7 +8,6 @@ import { getDispatchTaskDir } from "../config.js";
8
8
  * - explore: 35 000 (read-only scanning, tracing deps)
9
9
  * - edit: 60 000 (reads, plans, writes, iterates — heaviest)
10
10
  * - test: 45 000 (writes tests, runs, debugs failures)
11
- * - fix: 45 000 (reads, edits, re-runs to verify the fix)
12
11
  * - review: 35 000 (read-only audit, security analysis)
13
12
  * - doc: 30 000 (reads code, writes docs/comments)
14
13
  */
@@ -16,7 +15,6 @@ const DEFAULT_BUDGETS = {
16
15
  explore: 35000,
17
16
  edit: 60000,
18
17
  test: 45000,
19
- fix: 45000,
20
18
  review: 35000,
21
19
  doc: 30000,
22
20
  };
@@ -28,6 +26,10 @@ export function getDefaultBudget(agent_type) {
28
26
  * Tracks cumulative token usage for a single subagent task by parsing
29
27
  * newline-delimited JSON events from the subagent's stdout stream.
30
28
  *
29
+ * Advisory only: this never stops or penalizes a subagent. The guaranteed hard
30
+ * stop is the per-subagent turn cap (--max-turns); these events exist purely for
31
+ * telemetry and for callers that want to surface usage.
32
+ *
31
33
  * Emits:
32
34
  * - "budget_warning" when 80% of the budget is consumed
33
35
  * - "budget_exceeded" when 100% of the budget is consumed
@@ -1 +1 @@
1
- {"version":3,"file":"token-budget.js","sourceRoot":"","sources":["../../src/core/token-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAiBlD;;;;;;;;;GASG;AACH,MAAM,eAAe,GAA2B;IAC/C,OAAO,EAAE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AAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1F,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,IAAI,CAAC;YAAE,OAAO;QAE1D,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC;QAEzB,mBAAmB;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,OAAO,EAAE,gEAAgE;gBACzE,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;aACjB,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3D,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;gBAC5B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;aACjB,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;IAAA,CACf;CACD","sourcesContent":["import { EventEmitter } from \"node:events\";\nimport { mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { getDispatchTaskDir } from \"../config.js\";\n\nexport interface TokenBudgetConfig {\n\t/** Budget limit in tokens. */\n\tlimit: number;\n}\n\nexport interface TokenBudgetState {\n\ttask_id: string;\n\tagent_type: string;\n\tbudget: number;\n\tused: number;\n\twarned: boolean;\n\texceeded: boolean;\n\tlast_updated: number;\n}\n\n/**\n * Default token budgets per agent type (in tokens). Raised from the previous\n * 8k–16k range, which was too low and hard-stopped subagents mid-task.\n * - explore: 35 000 (read-only scanning, tracing deps)\n * - edit: 60 000 (reads, plans, writes, iterates — heaviest)\n * - test: 45 000 (writes tests, runs, debugs failures)\n * - fix: 45 000 (reads, edits, re-runs to verify the fix)\n * - review: 35 000 (read-only audit, security analysis)\n * - doc: 30 000 (reads code, writes docs/comments)\n */\nconst DEFAULT_BUDGETS: Record<string, number> = {\n\texplore: 35000,\n\tedit: 60000,\n\ttest: 45000,\n\tfix: 45000,\n\treview: 35000,\n\tdoc: 30000,\n};\n\n/** Get the default budget for an agent type. */\nexport function getDefaultBudget(agent_type: string): number {\n\treturn DEFAULT_BUDGETS[agent_type] ?? 35000;\n}\n\n/**\n * Tracks cumulative token usage for a single subagent task by parsing\n * newline-delimited JSON events from the subagent's stdout stream.\n *\n * Emits:\n * - \"budget_warning\" when 80% of the budget is consumed\n * - \"budget_exceeded\" when 100% of the budget is consumed\n */\nexport class TokenBudget extends EventEmitter {\n\tprivate readonly task_id: string;\n\tprivate readonly agent_type: string;\n\tprivate readonly limit: number;\n\tprivate readonly cwd: string;\n\n\tprivate used = 0;\n\tprivate warned = false;\n\tprivate exceeded = false;\n\tprivate stdoutBuffer = \"\";\n\n\t/** Warning threshold (80%). */\n\tprivate readonly warningThreshold: number;\n\t/** Hard-stop threshold (100%). */\n\tprivate readonly exceededThreshold: number;\n\n\tconstructor(task_id: string, agent_type: string, options: { limit?: number; cwd?: string } = {}) {\n\t\tsuper();\n\t\tthis.task_id = task_id;\n\t\tthis.agent_type = agent_type;\n\t\tthis.limit = options.limit ?? getDefaultBudget(agent_type);\n\t\tthis.cwd = options.cwd ?? process.cwd();\n\t\tthis.warningThreshold = Math.floor(this.limit * 0.8);\n\t\tthis.exceededThreshold = this.limit;\n\t}\n\n\t/** Process a chunk of stdout data from the subagent. */\n\tprocessStdout(chunk: string): void {\n\t\tthis.stdoutBuffer += chunk;\n\n\t\twhile (true) {\n\t\t\tconst lineEnd = this.stdoutBuffer.indexOf(\"\\n\");\n\t\t\tif (lineEnd === -1) break;\n\t\t\tconst line = this.stdoutBuffer.slice(0, lineEnd).trimEnd();\n\t\t\tthis.stdoutBuffer = this.stdoutBuffer.slice(lineEnd + 1);\n\t\t\tif (line) {\n\t\t\t\tthis.parseLine(line);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Flush any remaining buffered stdout. Call when the stream ends. */\n\tflush(): void {\n\t\tif (this.stdoutBuffer.trim()) {\n\t\t\tthis.parseLine(this.stdoutBuffer.trim());\n\t\t\tthis.stdoutBuffer = \"\";\n\t\t}\n\t}\n\n\t/** Current cumulative token usage. */\n\tgetUsed(): number {\n\t\treturn this.used;\n\t}\n\n\t/** Configured token budget limit. */\n\tgetLimit(): number {\n\t\treturn this.limit;\n\t}\n\n\t/** Whether the budget warning has been triggered. */\n\tisWarned(): boolean {\n\t\treturn this.warned;\n\t}\n\n\t/** Whether the budget has been exceeded. */\n\tisExceeded(): boolean {\n\t\treturn this.exceeded;\n\t}\n\n\t/** Persist current budget state to disk. */\n\tpersist(): void {\n\t\tconst state: TokenBudgetState = {\n\t\t\ttask_id: this.task_id,\n\t\t\tagent_type: this.agent_type,\n\t\t\tbudget: this.limit,\n\t\t\tused: this.used,\n\t\t\twarned: this.warned,\n\t\t\texceeded: this.exceeded,\n\t\t\tlast_updated: Date.now(),\n\t\t};\n\n\t\tconst path = this.budgetPath();\n\t\ttry {\n\t\t\tmkdirSync(dirname(path), { recursive: true });\n\t\t\twriteFileSync(path, JSON.stringify(state, null, 2));\n\t\t} catch {\n\t\t\t// Persistence is best-effort; silently ignore write failures\n\t\t}\n\t}\n\n\tprivate budgetPath(): string {\n\t\treturn join(getDispatchTaskDir(this.cwd, this.task_id), \"budget.json\");\n\t}\n\n\tprivate parseLine(line: string): void {\n\t\tlet event: unknown;\n\t\ttry {\n\t\t\tevent = JSON.parse(line);\n\t\t} catch {\n\t\t\treturn; // Not valid JSON, ignore\n\t\t}\n\n\t\tif (!event || typeof event !== \"object\") return;\n\n\t\t// Look for message_end events with assistant messages that have usage\n\t\tconst typedEvent = event as Record<string, unknown>;\n\t\tif (typedEvent.type !== \"message_end\") return;\n\n\t\tconst message = typedEvent.message as Record<string, unknown> | undefined;\n\t\tif (!message) return;\n\t\tif (message.role !== \"assistant\") return;\n\n\t\tconst usage = message.usage as Record<string, unknown> | undefined;\n\t\tif (!usage) return;\n\n\t\tconst totalTokens = typeof usage.totalTokens === \"number\" ? usage.totalTokens : undefined;\n\t\tif (totalTokens === undefined || totalTokens <= 0) return;\n\n\t\tthis.used += totalTokens;\n\n\t\t// Check thresholds\n\t\tif (!this.warned && this.used >= this.warningThreshold) {\n\t\t\tthis.warned = true;\n\t\t\tthis.emit(\"budget_warning\", {\n\t\t\t\ttask_id: this.task_id,\n\t\t\t\tmessage: \"You are near token limit. Summarize and write result.json now.\",\n\t\t\t\tused: this.used,\n\t\t\t\tlimit: this.limit,\n\t\t\t});\n\t\t}\n\n\t\tif (!this.exceeded && this.used >= this.exceededThreshold) {\n\t\t\tthis.exceeded = true;\n\t\t\tthis.emit(\"budget_exceeded\", {\n\t\t\t\ttask_id: this.task_id,\n\t\t\t\tused: this.used,\n\t\t\t\tlimit: this.limit,\n\t\t\t});\n\t\t}\n\n\t\tthis.persist();\n\t}\n}\n"]}
1
+ {"version":3,"file":"token-budget.js","sourceRoot":"","sources":["../../src/core/token-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAiBlD;;;;;;;;GAQG;AACH,MAAM,eAAe,GAA2B;IAC/C,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,MAA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AAS,IAAI,WAAW,IAAI,CAAC;YAAE,OAAO;QAE1D,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC;QAEzB,mBAAmB;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,OAAO,EAAE,gEAAgE;gBACzE,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;aACjB,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3D,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;gBAC5B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;aACjB,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;IAAA,CACf;CACD","sourcesContent":["import { EventEmitter } from \"node:events\";\nimport { mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { getDispatchTaskDir } from \"../config.js\";\n\nexport interface TokenBudgetConfig {\n\t/** Budget limit in tokens. */\n\tlimit: number;\n}\n\nexport interface TokenBudgetState {\n\ttask_id: string;\n\tagent_type: string;\n\tbudget: number;\n\tused: number;\n\twarned: boolean;\n\texceeded: boolean;\n\tlast_updated: number;\n}\n\n/**\n * Default token budgets per agent type (in tokens). Raised from the previous\n * 8k–16k range, which was too low and hard-stopped subagents mid-task.\n * - explore: 35 000 (read-only scanning, tracing deps)\n * - edit: 60 000 (reads, plans, writes, iterates — heaviest)\n * - test: 45 000 (writes tests, runs, debugs failures)\n * - review: 35 000 (read-only audit, security analysis)\n * - doc: 30 000 (reads code, writes docs/comments)\n */\nconst DEFAULT_BUDGETS: Record<string, number> = {\n\texplore: 35000,\n\tedit: 60000,\n\ttest: 45000,\n\treview: 35000,\n\tdoc: 30000,\n};\n\n/** Get the default budget for an agent type. */\nexport function getDefaultBudget(agent_type: string): number {\n\treturn DEFAULT_BUDGETS[agent_type] ?? 35000;\n}\n\n/**\n * Tracks cumulative token usage for a single subagent task by parsing\n * newline-delimited JSON events from the subagent's stdout stream.\n *\n * Advisory only: this never stops or penalizes a subagent. The guaranteed hard\n * stop is the per-subagent turn cap (--max-turns); these events exist purely for\n * telemetry and for callers that want to surface usage.\n *\n * Emits:\n * - \"budget_warning\" when 80% of the budget is consumed\n * - \"budget_exceeded\" when 100% of the budget is consumed\n */\nexport class TokenBudget extends EventEmitter {\n\tprivate readonly task_id: string;\n\tprivate readonly agent_type: string;\n\tprivate readonly limit: number;\n\tprivate readonly cwd: string;\n\n\tprivate used = 0;\n\tprivate warned = false;\n\tprivate exceeded = false;\n\tprivate stdoutBuffer = \"\";\n\n\t/** Warning threshold (80%). */\n\tprivate readonly warningThreshold: number;\n\t/** Hard-stop threshold (100%). */\n\tprivate readonly exceededThreshold: number;\n\n\tconstructor(task_id: string, agent_type: string, options: { limit?: number; cwd?: string } = {}) {\n\t\tsuper();\n\t\tthis.task_id = task_id;\n\t\tthis.agent_type = agent_type;\n\t\tthis.limit = options.limit ?? getDefaultBudget(agent_type);\n\t\tthis.cwd = options.cwd ?? process.cwd();\n\t\tthis.warningThreshold = Math.floor(this.limit * 0.8);\n\t\tthis.exceededThreshold = this.limit;\n\t}\n\n\t/** Process a chunk of stdout data from the subagent. */\n\tprocessStdout(chunk: string): void {\n\t\tthis.stdoutBuffer += chunk;\n\n\t\twhile (true) {\n\t\t\tconst lineEnd = this.stdoutBuffer.indexOf(\"\\n\");\n\t\t\tif (lineEnd === -1) break;\n\t\t\tconst line = this.stdoutBuffer.slice(0, lineEnd).trimEnd();\n\t\t\tthis.stdoutBuffer = this.stdoutBuffer.slice(lineEnd + 1);\n\t\t\tif (line) {\n\t\t\t\tthis.parseLine(line);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Flush any remaining buffered stdout. Call when the stream ends. */\n\tflush(): void {\n\t\tif (this.stdoutBuffer.trim()) {\n\t\t\tthis.parseLine(this.stdoutBuffer.trim());\n\t\t\tthis.stdoutBuffer = \"\";\n\t\t}\n\t}\n\n\t/** Current cumulative token usage. */\n\tgetUsed(): number {\n\t\treturn this.used;\n\t}\n\n\t/** Configured token budget limit. */\n\tgetLimit(): number {\n\t\treturn this.limit;\n\t}\n\n\t/** Whether the budget warning has been triggered. */\n\tisWarned(): boolean {\n\t\treturn this.warned;\n\t}\n\n\t/** Whether the budget has been exceeded. */\n\tisExceeded(): boolean {\n\t\treturn this.exceeded;\n\t}\n\n\t/** Persist current budget state to disk. */\n\tpersist(): void {\n\t\tconst state: TokenBudgetState = {\n\t\t\ttask_id: this.task_id,\n\t\t\tagent_type: this.agent_type,\n\t\t\tbudget: this.limit,\n\t\t\tused: this.used,\n\t\t\twarned: this.warned,\n\t\t\texceeded: this.exceeded,\n\t\t\tlast_updated: Date.now(),\n\t\t};\n\n\t\tconst path = this.budgetPath();\n\t\ttry {\n\t\t\tmkdirSync(dirname(path), { recursive: true });\n\t\t\twriteFileSync(path, JSON.stringify(state, null, 2));\n\t\t} catch {\n\t\t\t// Persistence is best-effort; silently ignore write failures\n\t\t}\n\t}\n\n\tprivate budgetPath(): string {\n\t\treturn join(getDispatchTaskDir(this.cwd, this.task_id), \"budget.json\");\n\t}\n\n\tprivate parseLine(line: string): void {\n\t\tlet event: unknown;\n\t\ttry {\n\t\t\tevent = JSON.parse(line);\n\t\t} catch {\n\t\t\treturn; // Not valid JSON, ignore\n\t\t}\n\n\t\tif (!event || typeof event !== \"object\") return;\n\n\t\t// Look for message_end events with assistant messages that have usage\n\t\tconst typedEvent = event as Record<string, unknown>;\n\t\tif (typedEvent.type !== \"message_end\") return;\n\n\t\tconst message = typedEvent.message as Record<string, unknown> | undefined;\n\t\tif (!message) return;\n\t\tif (message.role !== \"assistant\") return;\n\n\t\tconst usage = message.usage as Record<string, unknown> | undefined;\n\t\tif (!usage) return;\n\n\t\tconst totalTokens = typeof usage.totalTokens === \"number\" ? usage.totalTokens : undefined;\n\t\tif (totalTokens === undefined || totalTokens <= 0) return;\n\n\t\tthis.used += totalTokens;\n\n\t\t// Check thresholds\n\t\tif (!this.warned && this.used >= this.warningThreshold) {\n\t\t\tthis.warned = true;\n\t\t\tthis.emit(\"budget_warning\", {\n\t\t\t\ttask_id: this.task_id,\n\t\t\t\tmessage: \"You are near token limit. Summarize and write result.json now.\",\n\t\t\t\tused: this.used,\n\t\t\t\tlimit: this.limit,\n\t\t\t});\n\t\t}\n\n\t\tif (!this.exceeded && this.used >= this.exceededThreshold) {\n\t\t\tthis.exceeded = true;\n\t\t\tthis.emit(\"budget_exceeded\", {\n\t\t\t\ttask_id: this.task_id,\n\t\t\t\tused: this.used,\n\t\t\t\tlimit: this.limit,\n\t\t\t});\n\t\t}\n\n\t\tthis.persist();\n\t}\n}\n"]}
@@ -40,9 +40,6 @@ export interface TaskOutputDetails {
40
40
  status: string;
41
41
  ok: boolean;
42
42
  }
43
- /** Quick advisory check: would the dispatch evaluator delegate this task?
44
- * The evaluator is non-blocking; this is exposed for diagnostics/tools only. */
45
- export declare function isSubagentRecommended(task: string): boolean;
46
43
  /** Create the Task tool definition. Registered as a customTool when enabled. */
47
44
  export declare function createTaskToolDefinition(cwd?: string): ToolDefinition;
48
45
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../../src/core/tools/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAO7D;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAwBrE;AASD;0EAC0E;AAC1E,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,CAoBvE;AAuBD,MAAM,WAAW,eAAe;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;CACZ;AAeD;iFACiF;AACjF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED,gFAAgF;AAChF,wBAAgB,wBAAwB,CAAC,GAAG,GAAE,MAAsB,GAAG,cAAc,CAkHpF;AAmED;;;;GAIG;AACH,wBAAgB,8BAA8B,IAAI,cAAc,CAiD/D","sourcesContent":["/**\n * Task tool: delegate a focused task to a specialized subagent.\n *\n * Mirrors the Claude Code `Task` tool. The parent agent decides *when* to\n * delegate based on each agent's `description` (there is no deterministic gate)\n * and selects *which* agent via `subagent_type`. The chosen agent runs in a\n * fresh, isolated child process (SubagentPool) and only its final answer is\n * returned to the parent.\n *\n * It is an optional, opt-in tool (enabled via --subagent or the\n * `enableSubagent` setting); see buildSessionOptions in main.ts.\n */\n\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { loadAgentRegistry } from \"../agent-registry.js\";\nimport { DispatchEvaluator } from \"../dispatch-evaluator.js\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { defineTool } from \"../extensions/types.js\";\nimport type { SubagentPool, TaskResult } from \"../subagent-pool.js\";\nimport { getSubagentPool } from \"../subagent-pool-instance.js\";\nimport type { SubagentResultFile } from \"../subagent-result.js\";\nimport { taskStore } from \"../task-store.js\";\n\n/**\n * Condense a (possibly multi-line, bulleted) agent description into a single\n * useful one-liner for the agent picker list.\n *\n * Built-in agent descriptions open with a boilerplate header (\"Use this\n * subagent ONLY when:\") followed by \"when to use\" bullets and a \"DO NOT use\"\n * section. Taking the first line alone yields that identical header for every\n * agent, so instead surface the first meaningful bullets (or the first prose\n * line) from the positive \"when to use\" region.\n */\nexport function summarizeAgentDescription(description: string): string {\n\tconst lines = description\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0);\n\tif (lines.length === 0) return \"\";\n\n\t// Keep only the positive region: everything before a \"DO NOT use\" section.\n\tconst stop = lines.findIndex((line) => /^(do\\s*not|don'?t|avoid)\\b/i.test(line));\n\tconst region = stop === -1 ? lines : lines.slice(0, stop);\n\n\t// Drop a leading header line (e.g. \"Use this subagent ONLY when:\").\n\tconst body = region.length > 1 && region[0]!.endsWith(\":\") ? region.slice(1) : region;\n\n\tconst stripBullet = (line: string) => line.replace(/^[-*\\u2022]\\s+/, \"\").trim();\n\tconst bullets = body\n\t\t.filter((line) => /^[-*\\u2022]\\s+/.test(line))\n\t\t.map(stripBullet)\n\t\t.filter((line) => line.length > 0);\n\n\tconst summary = bullets.length > 0 ? bullets.slice(0, 3).join(\"; \") : (body[0] ?? lines[0] ?? \"\").replace(/:$/, \"\");\n\n\tconst MAX = 200;\n\treturn summary.length > MAX ? `${summary.slice(0, MAX - 1).trimEnd()}\\u2026` : summary;\n}\n\n/** Render the available agents as a \"- name: description\" list for prompts. */\nfunction describeAvailableAgents(cwd: string): string {\n\tconst agents = loadAgentRegistry({ cwd }).list();\n\tif (agents.length === 0) return \"(no agents available)\";\n\treturn agents.map((a) => `- ${a.name}: ${summarizeAgentDescription(a.description)}`).join(\"\\n\");\n}\n\n/** System prompt appendix for the main session when the Task tool is enabled.\n * Instructs the parent agent on when and how to delegate effectively. */\nexport function buildTaskMainPrompt(cwd: string = process.cwd()): string {\n\treturn `You have access to the **Task** tool. Use it to delegate self-contained tasks to specialized subagents that run in their own isolated context and return only their final answer.\n\nAvailable agents (choose one via \\`subagent_type\\`):\n${describeAvailableAgents(cwd)}\n\nWhen to delegate:\n1. The work is self-contained and you only need the final result, not intermediate steps.\n2. You want to investigate or edit something in parallel without losing your current context or reasoning chain.\n3. The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug).\n4. You need to run a long command or test suite and wait for its output without blocking your own reasoning.\n\nGuidelines:\n- Choose the agent whose description best matches the task.\n- Make every task specific and self-contained. The subagent cannot see this conversation; pass all necessary context (files, constraints, prior findings) in \\`prompt\\`.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Its intermediate reasoning, tool calls, and output are hidden from you.\n- Default to handling small, quick, or single-file work inline; delegate only self-contained units.\n- Some agents are configured to run in the background (non-blocking). For those, Task returns immediately with a task_id; use the **TaskOutput** tool with that task_id to check status and collect the final answer.\n- To continue a previous subagent (for example one that returned partial results), call Task again with \\`resume_task_id\\` set to its task_id; it resumes with its full prior transcript and \\`prompt\\` is your follow-up.`;\n}\n\nconst taskParams = Type.Object({\n\tdescription: Type.String({\n\t\tdescription: \"A short (3-5 word) description of the task, shown in the task panel.\",\n\t}),\n\tprompt: Type.String({\n\t\tdescription:\n\t\t\t\"The full, self-contained task for the subagent. It cannot see this conversation, so include all needed context, files, and constraints.\",\n\t}),\n\tsubagent_type: Type.String({\n\t\tdescription: \"The name of the specialized agent to delegate to. Must be one of the available agents.\",\n\t}),\n\tresume_task_id: Type.Optional(\n\t\tType.String({\n\t\t\tdescription:\n\t\t\t\t\"Optional. To continue a previous subagent run, pass its task_id (returned by an earlier Task or TaskOutput call). The subagent resumes with its full prior transcript and `prompt` is your follow-up instruction.\",\n\t\t}),\n\t),\n});\n\ntype TaskParams = Static<typeof taskParams>;\n\nexport interface TaskToolDetails {\n\tsubagent_type: string;\n\tok: boolean;\n\terror?: string;\n\ttaskId: number;\n\t/** Pool-level task id usable for resume/polling. */\n\tpoolTaskId?: string;\n\t/** True when dispatched as a non-blocking background task. */\n\tbackground?: boolean;\n}\n\nexport interface TaskOutputDetails {\n\ttask_id: string;\n\tstatus: string;\n\tok: boolean;\n}\n\n/**\n * A short, human-readable task name for the task panel: the first line limited\n * to ~8 words so it stays glanceable. A character cap guards a single long word.\n */\nfunction summarize(task: string): string {\n\tconst firstLine = (task.trim().split(\"\\n\")[0] ?? \"\").trim();\n\tif (!firstLine) return \"(task)\";\n\tconst words = firstLine.split(/\\s+/);\n\tlet name = words.length > 8 ? `${words.slice(0, 8).join(\" \")}…` : firstLine;\n\tif (name.length > 60) name = `${name.slice(0, 59)}…`;\n\treturn name;\n}\n\n/** Quick advisory check: would the dispatch evaluator delegate this task?\n * The evaluator is non-blocking; this is exposed for diagnostics/tools only. */\nexport function isSubagentRecommended(task: string): boolean {\n\treturn new DispatchEvaluator().evaluate(task).should_delegate;\n}\n\n/** Create the Task tool definition. Registered as a customTool when enabled. */\nexport function createTaskToolDefinition(cwd: string = process.cwd()): ToolDefinition {\n\tconst agentList = describeAvailableAgents(cwd);\n\treturn defineTool<typeof taskParams, TaskToolDetails>({\n\t\tname: \"Task\",\n\t\tlabel: \"Task\",\n\t\tdescription: [\n\t\t\t\"Delegate a focused task to a specialized subagent that runs in a fresh, isolated context (it cannot see this conversation).\",\n\t\t\t\"Select the agent via `subagent_type`; pass everything it needs via `prompt`. The subagent returns only its final answer.\",\n\t\t\t\"Available agents:\",\n\t\t\tagentList,\n\t\t\t\"WHEN TO USE: (1) self-contained work where you only need the final result;\",\n\t\t\t\"(2) parallel investigation/edits without losing your reasoning chain;\",\n\t\t\t\"(3) a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug, write docs);\",\n\t\t\t\"(4) a long command or test suite you want to run without blocking your reasoning.\",\n\t\t\t\"Do NOT use for tasks needing tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\",\n\t\t\t\"Prefer handling small, quick, or single-file tasks yourself; delegate only self-contained units of work.\",\n\t\t].join(\"\\n\"),\n\t\tpromptSnippet: \"delegate a self-contained task to a specialized subagent (choose via subagent_type)\",\n\t\tparameters: taskParams,\n\n\t\tasync execute(_toolCallId, params: TaskParams, _signal, _onUpdate, ctx) {\n\t\t\tconst pool = getSubagentPool(ctx.cwd);\n\n\t\t\t// Resume path: continue a previously dispatched subagent with a follow-up\n\t\t\t// prompt, reusing its persisted session (full prior transcript).\n\t\t\tconst resumeId = params.resume_task_id?.trim();\n\t\t\tif (resumeId) {\n\t\t\t\tconst summary = params.description?.trim() || summarize(params.prompt);\n\t\t\t\tconst task = taskStore.create(summary, { subagentMode: params.subagent_type });\n\t\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\t\ttry {\n\t\t\t\t\tconst dispatchResult = await pool.resume(resumeId, params.prompt, {\n\t\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t\t});\n\t\t\t\t\t// The session lives under the original task id; keep it as the resume handle.\n\t\t\t\t\treturn finalizeForegroundResult(dispatchResult, params.subagent_type, task.id, resumeId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The model has already decided to delegate and which agent to use; honor\n\t\t\t// it. Validate the requested agent against the registry (no routing gate).\n\t\t\tconst registry = loadAgentRegistry({ cwd: ctx.cwd });\n\t\t\tconst def = registry.get(params.subagent_type);\n\t\t\tif (!def) {\n\t\t\t\tconst available = registry\n\t\t\t\t\t.list()\n\t\t\t\t\t.map((a) => a.name)\n\t\t\t\t\t.join(\", \");\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unknown subagent_type: \"${params.subagent_type}\". Available agents: ${available || \"(none)\"}.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst summary = params.description?.trim() || summarize(params.prompt);\n\t\t\tconst task = taskStore.create(summary, { subagentMode: params.subagent_type });\n\n\t\t\t// Background agents: dispatch detached and return a handle immediately so\n\t\t\t// the parent keeps reasoning. The parent polls via the TaskOutput tool.\n\t\t\tif (def.background) {\n\t\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\t\tconst dispatched = pool.dispatchDetached(params.prompt, {\n\t\t\t\t\tforceAgent: params.subagent_type,\n\t\t\t\t\tcontext: \"\",\n\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t});\n\t\t\t\tconst poolTaskId = dispatched.task_id;\n\t\t\t\tif (poolTaskId) trackBackgroundTask(pool, poolTaskId, task.id);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Background subagent (${params.subagent_type}) started with task_id \"${poolTaskId}\". It runs without blocking you. Call the TaskOutput tool with this task_id to check its status and collect the final answer.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tsubagent_type: params.subagent_type,\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\tpoolTaskId,\n\t\t\t\t\t\tbackground: true,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\ttry {\n\t\t\t\tconst dispatchResult = await pool.dispatch(params.prompt, {\n\t\t\t\t\tforceAgent: params.subagent_type,\n\t\t\t\t\tcontext: \"\",\n\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t});\n\t\t\t\treturn finalizeForegroundResult(dispatchResult, params.subagent_type, task.id, dispatchResult.task_id);\n\t\t\t} catch (error) {\n\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst type = args.subagent_type ?? \"agent\";\n\t\t\tconst preview = summarize(args.description ?? args.prompt ?? \"\");\n\t\t\tconst text =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"Task \")) +\n\t\t\t\ttheme.fg(\"accent\", `[${type}]`) +\n\t\t\t\ttheme.fg(\"dim\", ` ${preview}`);\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n\n/** Extract the final answer from a finished dispatch, updating the task panel. */\nfunction finalizeForegroundResult(\n\tdispatchResult: TaskResult,\n\tsubagentType: string,\n\ttaskStoreId: number,\n\tresumeHandle: string | undefined,\n): { content: Array<{ type: \"text\"; text: string }>; details: TaskToolDetails } {\n\tconst result = dispatchResult.result;\n\tconst resultData = result?.result_data as SubagentResultFile | undefined;\n\tconst usage = resultData?.usage;\n\n\tif (!result || !result.ok) {\n\t\t// Signal failure by throwing: the agent loop derives a tool's error state\n\t\t// from a thrown error, not from a returned flag.\n\t\ttaskStore.update(taskStoreId, { status: \"failed\", usage });\n\t\tconst reason = result?.error ?? (result?.status ? `subagent ${result.status}` : \"unknown error\");\n\t\tthrow new Error(`Subagent (${subagentType}) failed: ${reason}`);\n\t}\n\n\t// Leave the task in the store with its final status; it stays visible in the\n\t// task panel until the next user message arrives.\n\ttaskStore.update(taskStoreId, { status: \"done\", usage });\n\tlet answer = resultData?.summary || \"(subagent returned no output)\";\n\t// Partial results are resumable; surface the handle so the parent can continue.\n\tif (result.status === \"partial\" && resumeHandle) {\n\t\tanswer += `\\n\\n[Partial result. To continue this subagent, call Task again with resume_task_id=\"${resumeHandle}\".]`;\n\t}\n\treturn {\n\t\tcontent: [{ type: \"text\", text: answer }],\n\t\tdetails: { subagent_type: subagentType, ok: true, taskId: taskStoreId, poolTaskId: resumeHandle },\n\t};\n}\n\n/**\n * Keep the task panel in sync for a detached background subagent: when the pool\n * reports the task finished, update the stored task's status and detach.\n */\nfunction trackBackgroundTask(pool: SubagentPool, poolTaskId: string, taskStoreId: number): void {\n\tfunction finish(status: \"done\" | \"failed\"): void {\n\t\ttaskStore.update(taskStoreId, { status });\n\t\tpool.off(\"task_done\", onDone);\n\t\tpool.off(\"task_failed\", onFail);\n\t\tpool.off(\"task_stalled\", onFail);\n\t\tpool.off(\"task_timeout\", onFail);\n\t}\n\tfunction onDone(data: { task_id?: string }): void {\n\t\tif (data?.task_id === poolTaskId) finish(\"done\");\n\t}\n\tfunction onFail(data: { task_id?: string }): void {\n\t\tif (data?.task_id === poolTaskId) finish(\"failed\");\n\t}\n\tpool.on(\"task_done\", onDone);\n\tpool.on(\"task_failed\", onFail);\n\tpool.on(\"task_stalled\", onFail);\n\tpool.on(\"task_timeout\", onFail);\n}\n\nconst taskOutputParams = Type.Object({\n\ttask_id: Type.String({\n\t\tdescription: \"The task_id of a background (or previously dispatched) subagent, as returned by the Task tool.\",\n\t}),\n});\n\ntype TaskOutputParams = Static<typeof taskOutputParams>;\n\n/**\n * TaskOutput tool: poll a background subagent and collect its final answer.\n * Returns the current status while running, or the subagent's final answer once\n * complete. Registered alongside the Task tool when subagents are enabled.\n */\nexport function createTaskOutputToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof taskOutputParams, TaskOutputDetails>({\n\t\tname: \"TaskOutput\",\n\t\tlabel: \"TaskOutput\",\n\t\tdescription: [\n\t\t\t\"Check the status of a background subagent and collect its final answer once it finishes.\",\n\t\t\t\"Pass the task_id returned by a background Task call. While the subagent runs this reports its status; once complete it returns only the subagent's final answer.\",\n\t\t].join(\"\\n\"),\n\t\tpromptSnippet: \"check status / collect the result of a background subagent\",\n\t\tparameters: taskOutputParams,\n\n\t\tasync execute(_toolCallId, params: TaskOutputParams, _signal, _onUpdate, ctx) {\n\t\t\tconst pool = getSubagentPool(ctx.cwd);\n\t\t\tconst status = pool.get_status(params.task_id);\n\t\t\tif (status === \"running\" || status === \"queued\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Subagent task \"${params.task_id}\" is ${status}. Call TaskOutput again later to collect its result.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { task_id: params.task_id, status, ok: true },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst result = pool.collect(params.task_id);\n\t\t\tif (!result) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No result available for task \"${params.task_id}\" (status: ${status}). It may not exist or its result was already collected.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!result.ok) {\n\t\t\t\tconst reason = result.error ?? (result.status ? `subagent ${result.status}` : status);\n\t\t\t\tthrow new Error(`Background subagent \"${params.task_id}\" failed: ${reason}`);\n\t\t\t}\n\t\t\tconst resultData = result.result_data as SubagentResultFile | undefined;\n\t\t\tconst answer = resultData?.summary || \"(subagent returned no output)\";\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: answer }],\n\t\t\t\tdetails: { task_id: params.task_id, status: result.status ?? \"complete\", ok: true },\n\t\t\t};\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst text = theme.fg(\"toolTitle\", theme.bold(\"TaskOutput \")) + theme.fg(\"dim\", String(args.task_id ?? \"\"));\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n"]}
1
+ {"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../../src/core/tools/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAO7D;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAwBrE;AASD;0EAC0E;AAC1E,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,CAoBvE;AAuBD,MAAM,WAAW,eAAe;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;CACZ;AAeD,gFAAgF;AAChF,wBAAgB,wBAAwB,CAAC,GAAG,GAAE,MAAsB,GAAG,cAAc,CAkHpF;AAmED;;;;GAIG;AACH,wBAAgB,8BAA8B,IAAI,cAAc,CAiD/D","sourcesContent":["/**\n * Task tool: delegate a focused task to a specialized subagent.\n *\n * Mirrors the Claude Code `Task` tool. The parent agent decides *when* to\n * delegate based on each agent's `description` (there is no deterministic gate)\n * and selects *which* agent via `subagent_type`. The chosen agent runs in a\n * fresh, isolated child process (SubagentPool) and only its final answer is\n * returned to the parent.\n *\n * It is an optional, opt-in tool (enabled via --subagent or the\n * `enableSubagent` setting); see buildSessionOptions in main.ts.\n */\n\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { loadAgentRegistry } from \"../agent-registry.js\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { defineTool } from \"../extensions/types.js\";\nimport type { SubagentPool, TaskResult } from \"../subagent-pool.js\";\nimport { getSubagentPool } from \"../subagent-pool-instance.js\";\nimport type { SubagentResultFile } from \"../subagent-result.js\";\nimport { taskStore } from \"../task-store.js\";\n\n/**\n * Condense a (possibly multi-line, bulleted) agent description into a single\n * useful one-liner for the agent picker list.\n *\n * Built-in agent descriptions open with a boilerplate header (\"Use this\n * subagent ONLY when:\") followed by \"when to use\" bullets and a \"DO NOT use\"\n * section. Taking the first line alone yields that identical header for every\n * agent, so instead surface the first meaningful bullets (or the first prose\n * line) from the positive \"when to use\" region.\n */\nexport function summarizeAgentDescription(description: string): string {\n\tconst lines = description\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0);\n\tif (lines.length === 0) return \"\";\n\n\t// Keep only the positive region: everything before a \"DO NOT use\" section.\n\tconst stop = lines.findIndex((line) => /^(do\\s*not|don'?t|avoid)\\b/i.test(line));\n\tconst region = stop === -1 ? lines : lines.slice(0, stop);\n\n\t// Drop a leading header line (e.g. \"Use this subagent ONLY when:\").\n\tconst body = region.length > 1 && region[0]!.endsWith(\":\") ? region.slice(1) : region;\n\n\tconst stripBullet = (line: string) => line.replace(/^[-*\\u2022]\\s+/, \"\").trim();\n\tconst bullets = body\n\t\t.filter((line) => /^[-*\\u2022]\\s+/.test(line))\n\t\t.map(stripBullet)\n\t\t.filter((line) => line.length > 0);\n\n\tconst summary = bullets.length > 0 ? bullets.slice(0, 3).join(\"; \") : (body[0] ?? lines[0] ?? \"\").replace(/:$/, \"\");\n\n\tconst MAX = 200;\n\treturn summary.length > MAX ? `${summary.slice(0, MAX - 1).trimEnd()}\\u2026` : summary;\n}\n\n/** Render the available agents as a \"- name: description\" list for prompts. */\nfunction describeAvailableAgents(cwd: string): string {\n\tconst agents = loadAgentRegistry({ cwd }).list();\n\tif (agents.length === 0) return \"(no agents available)\";\n\treturn agents.map((a) => `- ${a.name}: ${summarizeAgentDescription(a.description)}`).join(\"\\n\");\n}\n\n/** System prompt appendix for the main session when the Task tool is enabled.\n * Instructs the parent agent on when and how to delegate effectively. */\nexport function buildTaskMainPrompt(cwd: string = process.cwd()): string {\n\treturn `You have access to the **Task** tool. Use it to delegate self-contained tasks to specialized subagents that run in their own isolated context and return only their final answer.\n\nAvailable agents (choose one via \\`subagent_type\\`):\n${describeAvailableAgents(cwd)}\n\nWhen to delegate:\n1. The work is self-contained and you only need the final result, not intermediate steps.\n2. You want to investigate or edit something in parallel without losing your current context or reasoning chain.\n3. The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug).\n4. You need to run a long command or test suite and wait for its output without blocking your own reasoning.\n\nGuidelines:\n- Choose the agent whose description best matches the task.\n- Make every task specific and self-contained. The subagent cannot see this conversation; pass all necessary context (files, constraints, prior findings) in \\`prompt\\`.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Its intermediate reasoning, tool calls, and output are hidden from you.\n- Default to handling small, quick, or single-file work inline; delegate only self-contained units.\n- Some agents are configured to run in the background (non-blocking). For those, Task returns immediately with a task_id; use the **TaskOutput** tool with that task_id to check status and collect the final answer.\n- To continue a previous subagent (for example one that returned partial results), call Task again with \\`resume_task_id\\` set to its task_id; it resumes with its full prior transcript and \\`prompt\\` is your follow-up.`;\n}\n\nconst taskParams = Type.Object({\n\tdescription: Type.String({\n\t\tdescription: \"A short (3-5 word) description of the task, shown in the task panel.\",\n\t}),\n\tprompt: Type.String({\n\t\tdescription:\n\t\t\t\"The full, self-contained task for the subagent. It cannot see this conversation, so include all needed context, files, and constraints.\",\n\t}),\n\tsubagent_type: Type.String({\n\t\tdescription: \"The name of the specialized agent to delegate to. Must be one of the available agents.\",\n\t}),\n\tresume_task_id: Type.Optional(\n\t\tType.String({\n\t\t\tdescription:\n\t\t\t\t\"Optional. To continue a previous subagent run, pass its task_id (returned by an earlier Task or TaskOutput call). The subagent resumes with its full prior transcript and `prompt` is your follow-up instruction.\",\n\t\t}),\n\t),\n});\n\ntype TaskParams = Static<typeof taskParams>;\n\nexport interface TaskToolDetails {\n\tsubagent_type: string;\n\tok: boolean;\n\terror?: string;\n\ttaskId: number;\n\t/** Pool-level task id usable for resume/polling. */\n\tpoolTaskId?: string;\n\t/** True when dispatched as a non-blocking background task. */\n\tbackground?: boolean;\n}\n\nexport interface TaskOutputDetails {\n\ttask_id: string;\n\tstatus: string;\n\tok: boolean;\n}\n\n/**\n * A short, human-readable task name for the task panel: the first line limited\n * to ~8 words so it stays glanceable. A character cap guards a single long word.\n */\nfunction summarize(task: string): string {\n\tconst firstLine = (task.trim().split(\"\\n\")[0] ?? \"\").trim();\n\tif (!firstLine) return \"(task)\";\n\tconst words = firstLine.split(/\\s+/);\n\tlet name = words.length > 8 ? `${words.slice(0, 8).join(\" \")}…` : firstLine;\n\tif (name.length > 60) name = `${name.slice(0, 59)}…`;\n\treturn name;\n}\n\n/** Create the Task tool definition. Registered as a customTool when enabled. */\nexport function createTaskToolDefinition(cwd: string = process.cwd()): ToolDefinition {\n\tconst agentList = describeAvailableAgents(cwd);\n\treturn defineTool<typeof taskParams, TaskToolDetails>({\n\t\tname: \"Task\",\n\t\tlabel: \"Task\",\n\t\tdescription: [\n\t\t\t\"Delegate a focused task to a specialized subagent that runs in a fresh, isolated context (it cannot see this conversation).\",\n\t\t\t\"Select the agent via `subagent_type`; pass everything it needs via `prompt`. The subagent returns only its final answer.\",\n\t\t\t\"Available agents:\",\n\t\t\tagentList,\n\t\t\t\"WHEN TO USE: (1) self-contained work where you only need the final result;\",\n\t\t\t\"(2) parallel investigation/edits without losing your reasoning chain;\",\n\t\t\t\"(3) a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug, write docs);\",\n\t\t\t\"(4) a long command or test suite you want to run without blocking your reasoning.\",\n\t\t\t\"Do NOT use for tasks needing tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\",\n\t\t\t\"Prefer handling small, quick, or single-file tasks yourself; delegate only self-contained units of work.\",\n\t\t].join(\"\\n\"),\n\t\tpromptSnippet: \"delegate a self-contained task to a specialized subagent (choose via subagent_type)\",\n\t\tparameters: taskParams,\n\n\t\tasync execute(_toolCallId, params: TaskParams, _signal, _onUpdate, ctx) {\n\t\t\tconst pool = getSubagentPool(ctx.cwd);\n\n\t\t\t// Resume path: continue a previously dispatched subagent with a follow-up\n\t\t\t// prompt, reusing its persisted session (full prior transcript).\n\t\t\tconst resumeId = params.resume_task_id?.trim();\n\t\t\tif (resumeId) {\n\t\t\t\tconst summary = params.description?.trim() || summarize(params.prompt);\n\t\t\t\tconst task = taskStore.create(summary, { subagentMode: params.subagent_type });\n\t\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\t\ttry {\n\t\t\t\t\tconst dispatchResult = await pool.resume(resumeId, params.prompt, {\n\t\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t\t});\n\t\t\t\t\t// The session lives under the original task id; keep it as the resume handle.\n\t\t\t\t\treturn finalizeForegroundResult(dispatchResult, params.subagent_type, task.id, resumeId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The model has already decided to delegate and which agent to use; honor\n\t\t\t// it. Validate the requested agent against the registry (no routing gate).\n\t\t\tconst registry = loadAgentRegistry({ cwd: ctx.cwd });\n\t\t\tconst def = registry.get(params.subagent_type);\n\t\t\tif (!def) {\n\t\t\t\tconst available = registry\n\t\t\t\t\t.list()\n\t\t\t\t\t.map((a) => a.name)\n\t\t\t\t\t.join(\", \");\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unknown subagent_type: \"${params.subagent_type}\". Available agents: ${available || \"(none)\"}.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst summary = params.description?.trim() || summarize(params.prompt);\n\t\t\tconst task = taskStore.create(summary, { subagentMode: params.subagent_type });\n\n\t\t\t// Background agents: dispatch detached and return a handle immediately so\n\t\t\t// the parent keeps reasoning. The parent polls via the TaskOutput tool.\n\t\t\tif (def.background) {\n\t\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\t\tconst dispatched = pool.dispatchDetached(params.prompt, {\n\t\t\t\t\tforceAgent: params.subagent_type,\n\t\t\t\t\tcontext: \"\",\n\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t});\n\t\t\t\tconst poolTaskId = dispatched.task_id;\n\t\t\t\tif (poolTaskId) trackBackgroundTask(pool, poolTaskId, task.id);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Background subagent (${params.subagent_type}) started with task_id \"${poolTaskId}\". It runs without blocking you. Call the TaskOutput tool with this task_id to check its status and collect the final answer.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tsubagent_type: params.subagent_type,\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\tpoolTaskId,\n\t\t\t\t\t\tbackground: true,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\ttry {\n\t\t\t\tconst dispatchResult = await pool.dispatch(params.prompt, {\n\t\t\t\t\tforceAgent: params.subagent_type,\n\t\t\t\t\tcontext: \"\",\n\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t});\n\t\t\t\treturn finalizeForegroundResult(dispatchResult, params.subagent_type, task.id, dispatchResult.task_id);\n\t\t\t} catch (error) {\n\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst type = args.subagent_type ?? \"agent\";\n\t\t\tconst preview = summarize(args.description ?? args.prompt ?? \"\");\n\t\t\tconst text =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"Task \")) +\n\t\t\t\ttheme.fg(\"accent\", `[${type}]`) +\n\t\t\t\ttheme.fg(\"dim\", ` ${preview}`);\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n\n/** Extract the final answer from a finished dispatch, updating the task panel. */\nfunction finalizeForegroundResult(\n\tdispatchResult: TaskResult,\n\tsubagentType: string,\n\ttaskStoreId: number,\n\tresumeHandle: string | undefined,\n): { content: Array<{ type: \"text\"; text: string }>; details: TaskToolDetails } {\n\tconst result = dispatchResult.result;\n\tconst resultData = result?.result_data as SubagentResultFile | undefined;\n\tconst usage = resultData?.usage;\n\n\tif (!result || !result.ok) {\n\t\t// Signal failure by throwing: the agent loop derives a tool's error state\n\t\t// from a thrown error, not from a returned flag.\n\t\ttaskStore.update(taskStoreId, { status: \"failed\", usage });\n\t\tconst reason = result?.error ?? (result?.status ? `subagent ${result.status}` : \"unknown error\");\n\t\tthrow new Error(`Subagent (${subagentType}) failed: ${reason}`);\n\t}\n\n\t// Leave the task in the store with its final status; it stays visible in the\n\t// task panel until the next user message arrives.\n\ttaskStore.update(taskStoreId, { status: \"done\", usage });\n\tlet answer = resultData?.summary || \"(subagent returned no output)\";\n\t// Partial results are resumable; surface the handle so the parent can continue.\n\tif (result.status === \"partial\" && resumeHandle) {\n\t\tanswer += `\\n\\n[Partial result. To continue this subagent, call Task again with resume_task_id=\"${resumeHandle}\".]`;\n\t}\n\treturn {\n\t\tcontent: [{ type: \"text\", text: answer }],\n\t\tdetails: { subagent_type: subagentType, ok: true, taskId: taskStoreId, poolTaskId: resumeHandle },\n\t};\n}\n\n/**\n * Keep the task panel in sync for a detached background subagent: when the pool\n * reports the task finished, update the stored task's status and detach.\n */\nfunction trackBackgroundTask(pool: SubagentPool, poolTaskId: string, taskStoreId: number): void {\n\tfunction finish(status: \"done\" | \"failed\"): void {\n\t\ttaskStore.update(taskStoreId, { status });\n\t\tpool.off(\"task_done\", onDone);\n\t\tpool.off(\"task_failed\", onFail);\n\t\tpool.off(\"task_stalled\", onFail);\n\t\tpool.off(\"task_timeout\", onFail);\n\t}\n\tfunction onDone(data: { task_id?: string }): void {\n\t\tif (data?.task_id === poolTaskId) finish(\"done\");\n\t}\n\tfunction onFail(data: { task_id?: string }): void {\n\t\tif (data?.task_id === poolTaskId) finish(\"failed\");\n\t}\n\tpool.on(\"task_done\", onDone);\n\tpool.on(\"task_failed\", onFail);\n\tpool.on(\"task_stalled\", onFail);\n\tpool.on(\"task_timeout\", onFail);\n}\n\nconst taskOutputParams = Type.Object({\n\ttask_id: Type.String({\n\t\tdescription: \"The task_id of a background (or previously dispatched) subagent, as returned by the Task tool.\",\n\t}),\n});\n\ntype TaskOutputParams = Static<typeof taskOutputParams>;\n\n/**\n * TaskOutput tool: poll a background subagent and collect its final answer.\n * Returns the current status while running, or the subagent's final answer once\n * complete. Registered alongside the Task tool when subagents are enabled.\n */\nexport function createTaskOutputToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof taskOutputParams, TaskOutputDetails>({\n\t\tname: \"TaskOutput\",\n\t\tlabel: \"TaskOutput\",\n\t\tdescription: [\n\t\t\t\"Check the status of a background subagent and collect its final answer once it finishes.\",\n\t\t\t\"Pass the task_id returned by a background Task call. While the subagent runs this reports its status; once complete it returns only the subagent's final answer.\",\n\t\t].join(\"\\n\"),\n\t\tpromptSnippet: \"check status / collect the result of a background subagent\",\n\t\tparameters: taskOutputParams,\n\n\t\tasync execute(_toolCallId, params: TaskOutputParams, _signal, _onUpdate, ctx) {\n\t\t\tconst pool = getSubagentPool(ctx.cwd);\n\t\t\tconst status = pool.get_status(params.task_id);\n\t\t\tif (status === \"running\" || status === \"queued\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Subagent task \"${params.task_id}\" is ${status}. Call TaskOutput again later to collect its result.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { task_id: params.task_id, status, ok: true },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst result = pool.collect(params.task_id);\n\t\t\tif (!result) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No result available for task \"${params.task_id}\" (status: ${status}). It may not exist or its result was already collected.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!result.ok) {\n\t\t\t\tconst reason = result.error ?? (result.status ? `subagent ${result.status}` : status);\n\t\t\t\tthrow new Error(`Background subagent \"${params.task_id}\" failed: ${reason}`);\n\t\t\t}\n\t\t\tconst resultData = result.result_data as SubagentResultFile | undefined;\n\t\t\tconst answer = resultData?.summary || \"(subagent returned no output)\";\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: answer }],\n\t\t\t\tdetails: { task_id: params.task_id, status: result.status ?? \"complete\", ok: true },\n\t\t\t};\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst text = theme.fg(\"toolTitle\", theme.bold(\"TaskOutput \")) + theme.fg(\"dim\", String(args.task_id ?? \"\"));\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n"]}
@@ -13,7 +13,6 @@
13
13
  import { Text } from "@kolisachint/hoocode-tui";
14
14
  import { Type } from "typebox";
15
15
  import { loadAgentRegistry } from "../agent-registry.js";
16
- import { DispatchEvaluator } from "../dispatch-evaluator.js";
17
16
  import { defineTool } from "../extensions/types.js";
18
17
  import { getSubagentPool } from "../subagent-pool-instance.js";
19
18
  import { taskStore } from "../task-store.js";
@@ -106,11 +105,6 @@ function summarize(task) {
106
105
  name = `${name.slice(0, 59)}…`;
107
106
  return name;
108
107
  }
109
- /** Quick advisory check: would the dispatch evaluator delegate this task?
110
- * The evaluator is non-blocking; this is exposed for diagnostics/tools only. */
111
- export function isSubagentRecommended(task) {
112
- return new DispatchEvaluator().evaluate(task).should_delegate;
113
- }
114
108
  /** Create the Task tool definition. Registered as a customTool when enabled. */
115
109
  export function createTaskToolDefinition(cwd = process.cwd()) {
116
110
  const agentList = describeAvailableAgents(cwd);
@@ -1 +1 @@
1
- {"version":3,"file":"subagent.js","sourceRoot":"","sources":["../../../src/core/tools/subagent.ts"],"names":[],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AE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gBAClD,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE;aACnF,CAAC;QAAA,CACF;QAED,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE;YACvB,MAAM,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;YAC5G,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAAA,CAC5B;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * Task tool: delegate a focused task to a specialized subagent.\n *\n * Mirrors the Claude Code `Task` tool. The parent agent decides *when* to\n * delegate based on each agent's `description` (there is no deterministic gate)\n * and selects *which* agent via `subagent_type`. The chosen agent runs in a\n * fresh, isolated child process (SubagentPool) and only its final answer is\n * returned to the parent.\n *\n * It is an optional, opt-in tool (enabled via --subagent or the\n * `enableSubagent` setting); see buildSessionOptions in main.ts.\n */\n\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { loadAgentRegistry } from \"../agent-registry.js\";\nimport { DispatchEvaluator } from \"../dispatch-evaluator.js\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { defineTool } from \"../extensions/types.js\";\nimport type { SubagentPool, TaskResult } from \"../subagent-pool.js\";\nimport { getSubagentPool } from \"../subagent-pool-instance.js\";\nimport type { SubagentResultFile } from \"../subagent-result.js\";\nimport { taskStore } from \"../task-store.js\";\n\n/**\n * Condense a (possibly multi-line, bulleted) agent description into a single\n * useful one-liner for the agent picker list.\n *\n * Built-in agent descriptions open with a boilerplate header (\"Use this\n * subagent ONLY when:\") followed by \"when to use\" bullets and a \"DO NOT use\"\n * section. Taking the first line alone yields that identical header for every\n * agent, so instead surface the first meaningful bullets (or the first prose\n * line) from the positive \"when to use\" region.\n */\nexport function summarizeAgentDescription(description: string): string {\n\tconst lines = description\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0);\n\tif (lines.length === 0) return \"\";\n\n\t// Keep only the positive region: everything before a \"DO NOT use\" section.\n\tconst stop = lines.findIndex((line) => /^(do\\s*not|don'?t|avoid)\\b/i.test(line));\n\tconst region = stop === -1 ? lines : lines.slice(0, stop);\n\n\t// Drop a leading header line (e.g. \"Use this subagent ONLY when:\").\n\tconst body = region.length > 1 && region[0]!.endsWith(\":\") ? region.slice(1) : region;\n\n\tconst stripBullet = (line: string) => line.replace(/^[-*\\u2022]\\s+/, \"\").trim();\n\tconst bullets = body\n\t\t.filter((line) => /^[-*\\u2022]\\s+/.test(line))\n\t\t.map(stripBullet)\n\t\t.filter((line) => line.length > 0);\n\n\tconst summary = bullets.length > 0 ? bullets.slice(0, 3).join(\"; \") : (body[0] ?? lines[0] ?? \"\").replace(/:$/, \"\");\n\n\tconst MAX = 200;\n\treturn summary.length > MAX ? `${summary.slice(0, MAX - 1).trimEnd()}\\u2026` : summary;\n}\n\n/** Render the available agents as a \"- name: description\" list for prompts. */\nfunction describeAvailableAgents(cwd: string): string {\n\tconst agents = loadAgentRegistry({ cwd }).list();\n\tif (agents.length === 0) return \"(no agents available)\";\n\treturn agents.map((a) => `- ${a.name}: ${summarizeAgentDescription(a.description)}`).join(\"\\n\");\n}\n\n/** System prompt appendix for the main session when the Task tool is enabled.\n * Instructs the parent agent on when and how to delegate effectively. */\nexport function buildTaskMainPrompt(cwd: string = process.cwd()): string {\n\treturn `You have access to the **Task** tool. Use it to delegate self-contained tasks to specialized subagents that run in their own isolated context and return only their final answer.\n\nAvailable agents (choose one via \\`subagent_type\\`):\n${describeAvailableAgents(cwd)}\n\nWhen to delegate:\n1. The work is self-contained and you only need the final result, not intermediate steps.\n2. You want to investigate or edit something in parallel without losing your current context or reasoning chain.\n3. The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug).\n4. You need to run a long command or test suite and wait for its output without blocking your own reasoning.\n\nGuidelines:\n- Choose the agent whose description best matches the task.\n- Make every task specific and self-contained. The subagent cannot see this conversation; pass all necessary context (files, constraints, prior findings) in \\`prompt\\`.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Its intermediate reasoning, tool calls, and output are hidden from you.\n- Default to handling small, quick, or single-file work inline; delegate only self-contained units.\n- Some agents are configured to run in the background (non-blocking). For those, Task returns immediately with a task_id; use the **TaskOutput** tool with that task_id to check status and collect the final answer.\n- To continue a previous subagent (for example one that returned partial results), call Task again with \\`resume_task_id\\` set to its task_id; it resumes with its full prior transcript and \\`prompt\\` is your follow-up.`;\n}\n\nconst taskParams = Type.Object({\n\tdescription: Type.String({\n\t\tdescription: \"A short (3-5 word) description of the task, shown in the task panel.\",\n\t}),\n\tprompt: Type.String({\n\t\tdescription:\n\t\t\t\"The full, self-contained task for the subagent. It cannot see this conversation, so include all needed context, files, and constraints.\",\n\t}),\n\tsubagent_type: Type.String({\n\t\tdescription: \"The name of the specialized agent to delegate to. Must be one of the available agents.\",\n\t}),\n\tresume_task_id: Type.Optional(\n\t\tType.String({\n\t\t\tdescription:\n\t\t\t\t\"Optional. To continue a previous subagent run, pass its task_id (returned by an earlier Task or TaskOutput call). The subagent resumes with its full prior transcript and `prompt` is your follow-up instruction.\",\n\t\t}),\n\t),\n});\n\ntype TaskParams = Static<typeof taskParams>;\n\nexport interface TaskToolDetails {\n\tsubagent_type: string;\n\tok: boolean;\n\terror?: string;\n\ttaskId: number;\n\t/** Pool-level task id usable for resume/polling. */\n\tpoolTaskId?: string;\n\t/** True when dispatched as a non-blocking background task. */\n\tbackground?: boolean;\n}\n\nexport interface TaskOutputDetails {\n\ttask_id: string;\n\tstatus: string;\n\tok: boolean;\n}\n\n/**\n * A short, human-readable task name for the task panel: the first line limited\n * to ~8 words so it stays glanceable. A character cap guards a single long word.\n */\nfunction summarize(task: string): string {\n\tconst firstLine = (task.trim().split(\"\\n\")[0] ?? \"\").trim();\n\tif (!firstLine) return \"(task)\";\n\tconst words = firstLine.split(/\\s+/);\n\tlet name = words.length > 8 ? `${words.slice(0, 8).join(\" \")}…` : firstLine;\n\tif (name.length > 60) name = `${name.slice(0, 59)}…`;\n\treturn name;\n}\n\n/** Quick advisory check: would the dispatch evaluator delegate this task?\n * The evaluator is non-blocking; this is exposed for diagnostics/tools only. */\nexport function isSubagentRecommended(task: string): boolean {\n\treturn new DispatchEvaluator().evaluate(task).should_delegate;\n}\n\n/** Create the Task tool definition. Registered as a customTool when enabled. */\nexport function createTaskToolDefinition(cwd: string = process.cwd()): ToolDefinition {\n\tconst agentList = describeAvailableAgents(cwd);\n\treturn defineTool<typeof taskParams, TaskToolDetails>({\n\t\tname: \"Task\",\n\t\tlabel: \"Task\",\n\t\tdescription: [\n\t\t\t\"Delegate a focused task to a specialized subagent that runs in a fresh, isolated context (it cannot see this conversation).\",\n\t\t\t\"Select the agent via `subagent_type`; pass everything it needs via `prompt`. The subagent returns only its final answer.\",\n\t\t\t\"Available agents:\",\n\t\t\tagentList,\n\t\t\t\"WHEN TO USE: (1) self-contained work where you only need the final result;\",\n\t\t\t\"(2) parallel investigation/edits without losing your reasoning chain;\",\n\t\t\t\"(3) a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug, write docs);\",\n\t\t\t\"(4) a long command or test suite you want to run without blocking your reasoning.\",\n\t\t\t\"Do NOT use for tasks needing tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\",\n\t\t\t\"Prefer handling small, quick, or single-file tasks yourself; delegate only self-contained units of work.\",\n\t\t].join(\"\\n\"),\n\t\tpromptSnippet: \"delegate a self-contained task to a specialized subagent (choose via subagent_type)\",\n\t\tparameters: taskParams,\n\n\t\tasync execute(_toolCallId, params: TaskParams, _signal, _onUpdate, ctx) {\n\t\t\tconst pool = getSubagentPool(ctx.cwd);\n\n\t\t\t// Resume path: continue a previously dispatched subagent with a follow-up\n\t\t\t// prompt, reusing its persisted session (full prior transcript).\n\t\t\tconst resumeId = params.resume_task_id?.trim();\n\t\t\tif (resumeId) {\n\t\t\t\tconst summary = params.description?.trim() || summarize(params.prompt);\n\t\t\t\tconst task = taskStore.create(summary, { subagentMode: params.subagent_type });\n\t\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\t\ttry {\n\t\t\t\t\tconst dispatchResult = await pool.resume(resumeId, params.prompt, {\n\t\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t\t});\n\t\t\t\t\t// The session lives under the original task id; keep it as the resume handle.\n\t\t\t\t\treturn finalizeForegroundResult(dispatchResult, params.subagent_type, task.id, resumeId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The model has already decided to delegate and which agent to use; honor\n\t\t\t// it. Validate the requested agent against the registry (no routing gate).\n\t\t\tconst registry = loadAgentRegistry({ cwd: ctx.cwd });\n\t\t\tconst def = registry.get(params.subagent_type);\n\t\t\tif (!def) {\n\t\t\t\tconst available = registry\n\t\t\t\t\t.list()\n\t\t\t\t\t.map((a) => a.name)\n\t\t\t\t\t.join(\", \");\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unknown subagent_type: \"${params.subagent_type}\". Available agents: ${available || \"(none)\"}.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst summary = params.description?.trim() || summarize(params.prompt);\n\t\t\tconst task = taskStore.create(summary, { subagentMode: params.subagent_type });\n\n\t\t\t// Background agents: dispatch detached and return a handle immediately so\n\t\t\t// the parent keeps reasoning. The parent polls via the TaskOutput tool.\n\t\t\tif (def.background) {\n\t\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\t\tconst dispatched = pool.dispatchDetached(params.prompt, {\n\t\t\t\t\tforceAgent: params.subagent_type,\n\t\t\t\t\tcontext: \"\",\n\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t});\n\t\t\t\tconst poolTaskId = dispatched.task_id;\n\t\t\t\tif (poolTaskId) trackBackgroundTask(pool, poolTaskId, task.id);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Background subagent (${params.subagent_type}) started with task_id \"${poolTaskId}\". It runs without blocking you. Call the TaskOutput tool with this task_id to check its status and collect the final answer.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tsubagent_type: params.subagent_type,\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\tpoolTaskId,\n\t\t\t\t\t\tbackground: true,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\ttry {\n\t\t\t\tconst dispatchResult = await pool.dispatch(params.prompt, {\n\t\t\t\t\tforceAgent: params.subagent_type,\n\t\t\t\t\tcontext: \"\",\n\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t});\n\t\t\t\treturn finalizeForegroundResult(dispatchResult, params.subagent_type, task.id, dispatchResult.task_id);\n\t\t\t} catch (error) {\n\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst type = args.subagent_type ?? \"agent\";\n\t\t\tconst preview = summarize(args.description ?? args.prompt ?? \"\");\n\t\t\tconst text =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"Task \")) +\n\t\t\t\ttheme.fg(\"accent\", `[${type}]`) +\n\t\t\t\ttheme.fg(\"dim\", ` ${preview}`);\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n\n/** Extract the final answer from a finished dispatch, updating the task panel. */\nfunction finalizeForegroundResult(\n\tdispatchResult: TaskResult,\n\tsubagentType: string,\n\ttaskStoreId: number,\n\tresumeHandle: string | undefined,\n): { content: Array<{ type: \"text\"; text: string }>; details: TaskToolDetails } {\n\tconst result = dispatchResult.result;\n\tconst resultData = result?.result_data as SubagentResultFile | undefined;\n\tconst usage = resultData?.usage;\n\n\tif (!result || !result.ok) {\n\t\t// Signal failure by throwing: the agent loop derives a tool's error state\n\t\t// from a thrown error, not from a returned flag.\n\t\ttaskStore.update(taskStoreId, { status: \"failed\", usage });\n\t\tconst reason = result?.error ?? (result?.status ? `subagent ${result.status}` : \"unknown error\");\n\t\tthrow new Error(`Subagent (${subagentType}) failed: ${reason}`);\n\t}\n\n\t// Leave the task in the store with its final status; it stays visible in the\n\t// task panel until the next user message arrives.\n\ttaskStore.update(taskStoreId, { status: \"done\", usage });\n\tlet answer = resultData?.summary || \"(subagent returned no output)\";\n\t// Partial results are resumable; surface the handle so the parent can continue.\n\tif (result.status === \"partial\" && resumeHandle) {\n\t\tanswer += `\\n\\n[Partial result. To continue this subagent, call Task again with resume_task_id=\"${resumeHandle}\".]`;\n\t}\n\treturn {\n\t\tcontent: [{ type: \"text\", text: answer }],\n\t\tdetails: { subagent_type: subagentType, ok: true, taskId: taskStoreId, poolTaskId: resumeHandle },\n\t};\n}\n\n/**\n * Keep the task panel in sync for a detached background subagent: when the pool\n * reports the task finished, update the stored task's status and detach.\n */\nfunction trackBackgroundTask(pool: SubagentPool, poolTaskId: string, taskStoreId: number): void {\n\tfunction finish(status: \"done\" | \"failed\"): void {\n\t\ttaskStore.update(taskStoreId, { status });\n\t\tpool.off(\"task_done\", onDone);\n\t\tpool.off(\"task_failed\", onFail);\n\t\tpool.off(\"task_stalled\", onFail);\n\t\tpool.off(\"task_timeout\", onFail);\n\t}\n\tfunction onDone(data: { task_id?: string }): void {\n\t\tif (data?.task_id === poolTaskId) finish(\"done\");\n\t}\n\tfunction onFail(data: { task_id?: string }): void {\n\t\tif (data?.task_id === poolTaskId) finish(\"failed\");\n\t}\n\tpool.on(\"task_done\", onDone);\n\tpool.on(\"task_failed\", onFail);\n\tpool.on(\"task_stalled\", onFail);\n\tpool.on(\"task_timeout\", onFail);\n}\n\nconst taskOutputParams = Type.Object({\n\ttask_id: Type.String({\n\t\tdescription: \"The task_id of a background (or previously dispatched) subagent, as returned by the Task tool.\",\n\t}),\n});\n\ntype TaskOutputParams = Static<typeof taskOutputParams>;\n\n/**\n * TaskOutput tool: poll a background subagent and collect its final answer.\n * Returns the current status while running, or the subagent's final answer once\n * complete. Registered alongside the Task tool when subagents are enabled.\n */\nexport function createTaskOutputToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof taskOutputParams, TaskOutputDetails>({\n\t\tname: \"TaskOutput\",\n\t\tlabel: \"TaskOutput\",\n\t\tdescription: [\n\t\t\t\"Check the status of a background subagent and collect its final answer once it finishes.\",\n\t\t\t\"Pass the task_id returned by a background Task call. While the subagent runs this reports its status; once complete it returns only the subagent's final answer.\",\n\t\t].join(\"\\n\"),\n\t\tpromptSnippet: \"check status / collect the result of a background subagent\",\n\t\tparameters: taskOutputParams,\n\n\t\tasync execute(_toolCallId, params: TaskOutputParams, _signal, _onUpdate, ctx) {\n\t\t\tconst pool = getSubagentPool(ctx.cwd);\n\t\t\tconst status = pool.get_status(params.task_id);\n\t\t\tif (status === \"running\" || status === \"queued\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Subagent task \"${params.task_id}\" is ${status}. Call TaskOutput again later to collect its result.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { task_id: params.task_id, status, ok: true },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst result = pool.collect(params.task_id);\n\t\t\tif (!result) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No result available for task \"${params.task_id}\" (status: ${status}). It may not exist or its result was already collected.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!result.ok) {\n\t\t\t\tconst reason = result.error ?? (result.status ? `subagent ${result.status}` : status);\n\t\t\t\tthrow new Error(`Background subagent \"${params.task_id}\" failed: ${reason}`);\n\t\t\t}\n\t\t\tconst resultData = result.result_data as SubagentResultFile | undefined;\n\t\t\tconst answer = resultData?.summary || \"(subagent returned no output)\";\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: answer }],\n\t\t\t\tdetails: { task_id: params.task_id, status: result.status ?? \"complete\", ok: true },\n\t\t\t};\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst text = theme.fg(\"toolTitle\", theme.bold(\"TaskOutput \")) + theme.fg(\"dim\", String(args.task_id ?? \"\"));\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n"]}
1
+ {"version":3,"file":"subagent.js","sourceRoot":"","sources":["../../../src/core/tools/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB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Content":["/**\n * Task tool: delegate a focused task to a specialized subagent.\n *\n * Mirrors the Claude Code `Task` tool. The parent agent decides *when* to\n * delegate based on each agent's `description` (there is no deterministic gate)\n * and selects *which* agent via `subagent_type`. The chosen agent runs in a\n * fresh, isolated child process (SubagentPool) and only its final answer is\n * returned to the parent.\n *\n * It is an optional, opt-in tool (enabled via --subagent or the\n * `enableSubagent` setting); see buildSessionOptions in main.ts.\n */\n\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { loadAgentRegistry } from \"../agent-registry.js\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { defineTool } from \"../extensions/types.js\";\nimport type { SubagentPool, TaskResult } from \"../subagent-pool.js\";\nimport { getSubagentPool } from \"../subagent-pool-instance.js\";\nimport type { SubagentResultFile } from \"../subagent-result.js\";\nimport { taskStore } from \"../task-store.js\";\n\n/**\n * Condense a (possibly multi-line, bulleted) agent description into a single\n * useful one-liner for the agent picker list.\n *\n * Built-in agent descriptions open with a boilerplate header (\"Use this\n * subagent ONLY when:\") followed by \"when to use\" bullets and a \"DO NOT use\"\n * section. Taking the first line alone yields that identical header for every\n * agent, so instead surface the first meaningful bullets (or the first prose\n * line) from the positive \"when to use\" region.\n */\nexport function summarizeAgentDescription(description: string): string {\n\tconst lines = description\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0);\n\tif (lines.length === 0) return \"\";\n\n\t// Keep only the positive region: everything before a \"DO NOT use\" section.\n\tconst stop = lines.findIndex((line) => /^(do\\s*not|don'?t|avoid)\\b/i.test(line));\n\tconst region = stop === -1 ? lines : lines.slice(0, stop);\n\n\t// Drop a leading header line (e.g. \"Use this subagent ONLY when:\").\n\tconst body = region.length > 1 && region[0]!.endsWith(\":\") ? region.slice(1) : region;\n\n\tconst stripBullet = (line: string) => line.replace(/^[-*\\u2022]\\s+/, \"\").trim();\n\tconst bullets = body\n\t\t.filter((line) => /^[-*\\u2022]\\s+/.test(line))\n\t\t.map(stripBullet)\n\t\t.filter((line) => line.length > 0);\n\n\tconst summary = bullets.length > 0 ? bullets.slice(0, 3).join(\"; \") : (body[0] ?? lines[0] ?? \"\").replace(/:$/, \"\");\n\n\tconst MAX = 200;\n\treturn summary.length > MAX ? `${summary.slice(0, MAX - 1).trimEnd()}\\u2026` : summary;\n}\n\n/** Render the available agents as a \"- name: description\" list for prompts. */\nfunction describeAvailableAgents(cwd: string): string {\n\tconst agents = loadAgentRegistry({ cwd }).list();\n\tif (agents.length === 0) return \"(no agents available)\";\n\treturn agents.map((a) => `- ${a.name}: ${summarizeAgentDescription(a.description)}`).join(\"\\n\");\n}\n\n/** System prompt appendix for the main session when the Task tool is enabled.\n * Instructs the parent agent on when and how to delegate effectively. */\nexport function buildTaskMainPrompt(cwd: string = process.cwd()): string {\n\treturn `You have access to the **Task** tool. Use it to delegate self-contained tasks to specialized subagents that run in their own isolated context and return only their final answer.\n\nAvailable agents (choose one via \\`subagent_type\\`):\n${describeAvailableAgents(cwd)}\n\nWhen to delegate:\n1. The work is self-contained and you only need the final result, not intermediate steps.\n2. You want to investigate or edit something in parallel without losing your current context or reasoning chain.\n3. The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug).\n4. You need to run a long command or test suite and wait for its output without blocking your own reasoning.\n\nGuidelines:\n- Choose the agent whose description best matches the task.\n- Make every task specific and self-contained. The subagent cannot see this conversation; pass all necessary context (files, constraints, prior findings) in \\`prompt\\`.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Its intermediate reasoning, tool calls, and output are hidden from you.\n- Default to handling small, quick, or single-file work inline; delegate only self-contained units.\n- Some agents are configured to run in the background (non-blocking). For those, Task returns immediately with a task_id; use the **TaskOutput** tool with that task_id to check status and collect the final answer.\n- To continue a previous subagent (for example one that returned partial results), call Task again with \\`resume_task_id\\` set to its task_id; it resumes with its full prior transcript and \\`prompt\\` is your follow-up.`;\n}\n\nconst taskParams = Type.Object({\n\tdescription: Type.String({\n\t\tdescription: \"A short (3-5 word) description of the task, shown in the task panel.\",\n\t}),\n\tprompt: Type.String({\n\t\tdescription:\n\t\t\t\"The full, self-contained task for the subagent. It cannot see this conversation, so include all needed context, files, and constraints.\",\n\t}),\n\tsubagent_type: Type.String({\n\t\tdescription: \"The name of the specialized agent to delegate to. Must be one of the available agents.\",\n\t}),\n\tresume_task_id: Type.Optional(\n\t\tType.String({\n\t\t\tdescription:\n\t\t\t\t\"Optional. To continue a previous subagent run, pass its task_id (returned by an earlier Task or TaskOutput call). The subagent resumes with its full prior transcript and `prompt` is your follow-up instruction.\",\n\t\t}),\n\t),\n});\n\ntype TaskParams = Static<typeof taskParams>;\n\nexport interface TaskToolDetails {\n\tsubagent_type: string;\n\tok: boolean;\n\terror?: string;\n\ttaskId: number;\n\t/** Pool-level task id usable for resume/polling. */\n\tpoolTaskId?: string;\n\t/** True when dispatched as a non-blocking background task. */\n\tbackground?: boolean;\n}\n\nexport interface TaskOutputDetails {\n\ttask_id: string;\n\tstatus: string;\n\tok: boolean;\n}\n\n/**\n * A short, human-readable task name for the task panel: the first line limited\n * to ~8 words so it stays glanceable. A character cap guards a single long word.\n */\nfunction summarize(task: string): string {\n\tconst firstLine = (task.trim().split(\"\\n\")[0] ?? \"\").trim();\n\tif (!firstLine) return \"(task)\";\n\tconst words = firstLine.split(/\\s+/);\n\tlet name = words.length > 8 ? `${words.slice(0, 8).join(\" \")}…` : firstLine;\n\tif (name.length > 60) name = `${name.slice(0, 59)}…`;\n\treturn name;\n}\n\n/** Create the Task tool definition. Registered as a customTool when enabled. */\nexport function createTaskToolDefinition(cwd: string = process.cwd()): ToolDefinition {\n\tconst agentList = describeAvailableAgents(cwd);\n\treturn defineTool<typeof taskParams, TaskToolDetails>({\n\t\tname: \"Task\",\n\t\tlabel: \"Task\",\n\t\tdescription: [\n\t\t\t\"Delegate a focused task to a specialized subagent that runs in a fresh, isolated context (it cannot see this conversation).\",\n\t\t\t\"Select the agent via `subagent_type`; pass everything it needs via `prompt`. The subagent returns only its final answer.\",\n\t\t\t\"Available agents:\",\n\t\t\tagentList,\n\t\t\t\"WHEN TO USE: (1) self-contained work where you only need the final result;\",\n\t\t\t\"(2) parallel investigation/edits without losing your reasoning chain;\",\n\t\t\t\"(3) a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug, write docs);\",\n\t\t\t\"(4) a long command or test suite you want to run without blocking your reasoning.\",\n\t\t\t\"Do NOT use for tasks needing tight back-and-forth with your current reasoning, or edits to files you are actively reasoning about.\",\n\t\t\t\"Prefer handling small, quick, or single-file tasks yourself; delegate only self-contained units of work.\",\n\t\t].join(\"\\n\"),\n\t\tpromptSnippet: \"delegate a self-contained task to a specialized subagent (choose via subagent_type)\",\n\t\tparameters: taskParams,\n\n\t\tasync execute(_toolCallId, params: TaskParams, _signal, _onUpdate, ctx) {\n\t\t\tconst pool = getSubagentPool(ctx.cwd);\n\n\t\t\t// Resume path: continue a previously dispatched subagent with a follow-up\n\t\t\t// prompt, reusing its persisted session (full prior transcript).\n\t\t\tconst resumeId = params.resume_task_id?.trim();\n\t\t\tif (resumeId) {\n\t\t\t\tconst summary = params.description?.trim() || summarize(params.prompt);\n\t\t\t\tconst task = taskStore.create(summary, { subagentMode: params.subagent_type });\n\t\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\t\ttry {\n\t\t\t\t\tconst dispatchResult = await pool.resume(resumeId, params.prompt, {\n\t\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t\t});\n\t\t\t\t\t// The session lives under the original task id; keep it as the resume handle.\n\t\t\t\t\treturn finalizeForegroundResult(dispatchResult, params.subagent_type, task.id, resumeId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The model has already decided to delegate and which agent to use; honor\n\t\t\t// it. Validate the requested agent against the registry (no routing gate).\n\t\t\tconst registry = loadAgentRegistry({ cwd: ctx.cwd });\n\t\t\tconst def = registry.get(params.subagent_type);\n\t\t\tif (!def) {\n\t\t\t\tconst available = registry\n\t\t\t\t\t.list()\n\t\t\t\t\t.map((a) => a.name)\n\t\t\t\t\t.join(\", \");\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unknown subagent_type: \"${params.subagent_type}\". Available agents: ${available || \"(none)\"}.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst summary = params.description?.trim() || summarize(params.prompt);\n\t\t\tconst task = taskStore.create(summary, { subagentMode: params.subagent_type });\n\n\t\t\t// Background agents: dispatch detached and return a handle immediately so\n\t\t\t// the parent keeps reasoning. The parent polls via the TaskOutput tool.\n\t\t\tif (def.background) {\n\t\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\t\tconst dispatched = pool.dispatchDetached(params.prompt, {\n\t\t\t\t\tforceAgent: params.subagent_type,\n\t\t\t\t\tcontext: \"\",\n\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t});\n\t\t\t\tconst poolTaskId = dispatched.task_id;\n\t\t\t\tif (poolTaskId) trackBackgroundTask(pool, poolTaskId, task.id);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Background subagent (${params.subagent_type}) started with task_id \"${poolTaskId}\". It runs without blocking you. Call the TaskOutput tool with this task_id to check its status and collect the final answer.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tsubagent_type: params.subagent_type,\n\t\t\t\t\t\tok: true,\n\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\tpoolTaskId,\n\t\t\t\t\t\tbackground: true,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\ttry {\n\t\t\t\tconst dispatchResult = await pool.dispatch(params.prompt, {\n\t\t\t\t\tforceAgent: params.subagent_type,\n\t\t\t\t\tcontext: \"\",\n\t\t\t\t\tmodel: ctx.model?.id,\n\t\t\t\t\tprovider: ctx.model?.provider,\n\t\t\t\t});\n\t\t\t\treturn finalizeForegroundResult(dispatchResult, params.subagent_type, task.id, dispatchResult.task_id);\n\t\t\t} catch (error) {\n\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst type = args.subagent_type ?? \"agent\";\n\t\t\tconst preview = summarize(args.description ?? args.prompt ?? \"\");\n\t\t\tconst text =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"Task \")) +\n\t\t\t\ttheme.fg(\"accent\", `[${type}]`) +\n\t\t\t\ttheme.fg(\"dim\", ` ${preview}`);\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n\n/** Extract the final answer from a finished dispatch, updating the task panel. */\nfunction finalizeForegroundResult(\n\tdispatchResult: TaskResult,\n\tsubagentType: string,\n\ttaskStoreId: number,\n\tresumeHandle: string | undefined,\n): { content: Array<{ type: \"text\"; text: string }>; details: TaskToolDetails } {\n\tconst result = dispatchResult.result;\n\tconst resultData = result?.result_data as SubagentResultFile | undefined;\n\tconst usage = resultData?.usage;\n\n\tif (!result || !result.ok) {\n\t\t// Signal failure by throwing: the agent loop derives a tool's error state\n\t\t// from a thrown error, not from a returned flag.\n\t\ttaskStore.update(taskStoreId, { status: \"failed\", usage });\n\t\tconst reason = result?.error ?? (result?.status ? `subagent ${result.status}` : \"unknown error\");\n\t\tthrow new Error(`Subagent (${subagentType}) failed: ${reason}`);\n\t}\n\n\t// Leave the task in the store with its final status; it stays visible in the\n\t// task panel until the next user message arrives.\n\ttaskStore.update(taskStoreId, { status: \"done\", usage });\n\tlet answer = resultData?.summary || \"(subagent returned no output)\";\n\t// Partial results are resumable; surface the handle so the parent can continue.\n\tif (result.status === \"partial\" && resumeHandle) {\n\t\tanswer += `\\n\\n[Partial result. To continue this subagent, call Task again with resume_task_id=\"${resumeHandle}\".]`;\n\t}\n\treturn {\n\t\tcontent: [{ type: \"text\", text: answer }],\n\t\tdetails: { subagent_type: subagentType, ok: true, taskId: taskStoreId, poolTaskId: resumeHandle },\n\t};\n}\n\n/**\n * Keep the task panel in sync for a detached background subagent: when the pool\n * reports the task finished, update the stored task's status and detach.\n */\nfunction trackBackgroundTask(pool: SubagentPool, poolTaskId: string, taskStoreId: number): void {\n\tfunction finish(status: \"done\" | \"failed\"): void {\n\t\ttaskStore.update(taskStoreId, { status });\n\t\tpool.off(\"task_done\", onDone);\n\t\tpool.off(\"task_failed\", onFail);\n\t\tpool.off(\"task_stalled\", onFail);\n\t\tpool.off(\"task_timeout\", onFail);\n\t}\n\tfunction onDone(data: { task_id?: string }): void {\n\t\tif (data?.task_id === poolTaskId) finish(\"done\");\n\t}\n\tfunction onFail(data: { task_id?: string }): void {\n\t\tif (data?.task_id === poolTaskId) finish(\"failed\");\n\t}\n\tpool.on(\"task_done\", onDone);\n\tpool.on(\"task_failed\", onFail);\n\tpool.on(\"task_stalled\", onFail);\n\tpool.on(\"task_timeout\", onFail);\n}\n\nconst taskOutputParams = Type.Object({\n\ttask_id: Type.String({\n\t\tdescription: \"The task_id of a background (or previously dispatched) subagent, as returned by the Task tool.\",\n\t}),\n});\n\ntype TaskOutputParams = Static<typeof taskOutputParams>;\n\n/**\n * TaskOutput tool: poll a background subagent and collect its final answer.\n * Returns the current status while running, or the subagent's final answer once\n * complete. Registered alongside the Task tool when subagents are enabled.\n */\nexport function createTaskOutputToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof taskOutputParams, TaskOutputDetails>({\n\t\tname: \"TaskOutput\",\n\t\tlabel: \"TaskOutput\",\n\t\tdescription: [\n\t\t\t\"Check the status of a background subagent and collect its final answer once it finishes.\",\n\t\t\t\"Pass the task_id returned by a background Task call. While the subagent runs this reports its status; once complete it returns only the subagent's final answer.\",\n\t\t].join(\"\\n\"),\n\t\tpromptSnippet: \"check status / collect the result of a background subagent\",\n\t\tparameters: taskOutputParams,\n\n\t\tasync execute(_toolCallId, params: TaskOutputParams, _signal, _onUpdate, ctx) {\n\t\t\tconst pool = getSubagentPool(ctx.cwd);\n\t\t\tconst status = pool.get_status(params.task_id);\n\t\t\tif (status === \"running\" || status === \"queued\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Subagent task \"${params.task_id}\" is ${status}. Call TaskOutput again later to collect its result.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { task_id: params.task_id, status, ok: true },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst result = pool.collect(params.task_id);\n\t\t\tif (!result) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No result available for task \"${params.task_id}\" (status: ${status}). It may not exist or its result was already collected.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!result.ok) {\n\t\t\t\tconst reason = result.error ?? (result.status ? `subagent ${result.status}` : status);\n\t\t\t\tthrow new Error(`Background subagent \"${params.task_id}\" failed: ${reason}`);\n\t\t\t}\n\t\t\tconst resultData = result.result_data as SubagentResultFile | undefined;\n\t\t\tconst answer = resultData?.summary || \"(subagent returned no output)\";\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: answer }],\n\t\t\t\tdetails: { task_id: params.task_id, status: result.status ?? \"complete\", ok: true },\n\t\t\t};\n\t\t},\n\n\t\trenderCall(args, theme) {\n\t\t\tconst text = theme.fg(\"toolTitle\", theme.bold(\"TaskOutput \")) + theme.fg(\"dim\", String(args.task_id ?? \"\"));\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  export declare const EMBEDDED_DEFAULT_CONFIG: string;
2
2
  export declare const EMBEDDED_MODES: Record<string, string>;
3
3
  export declare const EMBEDDED_PROFILES: Record<string, string>;
4
- export declare const EMBEDDED_SUBAGENT_PROMPTS: Record<string, string>;
5
4
  export declare const EMBEDDED_AGENT_PROMPTS: Record<string, string>;
6
5
  //# sourceMappingURL=init-templates.generated.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init-templates.generated.d.ts","sourceRoot":"","sources":["../src/init-templates.generated.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,EAAE,MAC+Z,CAAC;AAEtc,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKjD,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,CAAC;AAE5D,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAS5D,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQzD,CAAC","sourcesContent":["// AUTO-GENERATED by scripts/embed-templates.mjs — do not edit.\n// Source of truth: packages/coding-agent/templates/**\n// Regenerated on every `npm run build`.\n\nexport const EMBEDDED_DEFAULT_CONFIG: string =\n\t'{\\n \"version\": \"1.0\",\\n \"active_mode\": \"build\",\\n \"llm\": {\\n \"default_provider\": \"anthropic\",\\n \"providers\": {\\n \"anthropic\": { \"api_key_env\": \"ANTHROPIC_API_KEY\" },\\n \"openai\": { \"api_key_env\": \"OPENAI_API_KEY\" }\\n }\\n },\\n \"modes\": {\\n \"ask\": { \"auto_allow\": [\"read\"] },\\n \"plan\": { \"auto_allow\": [\"read\", \"write\"] },\\n \"build\": { \"auto_allow\": [\"read\"] },\\n \"debug\": { \"auto_allow\": [\"read\", \"bash\"] }\\n }\\n}\\n';\n\nexport const EMBEDDED_MODES: Record<string, string> = {\n\task: \"You are in **ask mode** — read-only Q&A.\\n\\nPermitted: read files, run grep/find, explain code, trace logic, compare approaches, debug conceptually.\\nForbidden: edit files, write files, run commands that modify state.\\n\\nWhen answering:\\n- Cite file paths and line numbers.\\n- Prefer precise over verbose.\\n- If a question requires a code change to answer properly, describe the change; do not apply it.\\n- If the user asks you to edit something, decline and suggest switching to build mode with `/mode build`.\\n\",\n\tbuild: \"You are in **build mode** — implement carefully, one step at a time.\\n\\nRules:\\n- **One tool per turn.** Plan the action, call the tool, wait for the result before proceeding.\\n- **Read before editing.** Never write to a file you have not read in this session.\\n- **Show diffs** before applying non-trivial edits; wait for implicit acceptance.\\n- **Dangerous ops** (delete, force-push, drop table, rm -rf): state what you are about to do and wait for explicit confirmation.\\n- **Match existing style** — indentation, naming, import order.\\n- **Run tests** after every logical unit of change. Fix failures before continuing.\\n\",\n\tdebug: \"You are in **debug mode** — root-cause analysis only, no file modifications.\\n\\nProcess:\\n1. **Gather evidence** — read logs, error traces, and relevant source. Run safe diagnostic commands (grep, find, read, non-mutating shell commands).\\n2. **Reproduce** — identify the minimal condition that triggers the bug.\\n3. **Trace** — follow the full call path from entry point to failure site, citing file and line at each step.\\n4. **State the root cause** in one clear sentence.\\n5. **Describe the fix** — files, lines, and what to change — but do not apply it.\\n\\nForbidden: edit or write any file. To apply a fix, switch to build mode with `/mode build`.\\n\",\n\tplan: 'You are in **plan mode** — explore and design, no source edits.\\n\\nYour job: produce a complete, actionable implementation plan.\\n\\nSteps:\\n1. Read relevant files and ask clarifying questions before drafting.\\n2. Write the finished plan to `{{PLAN_PATH}}` with these sections:\\n - **Goal** — one sentence.\\n - **Files to modify** — path, line range, what changes.\\n - **New files** — path, purpose.\\n - **Tests** — what to add or update.\\n - **Verification** — commands to confirm correctness.\\n3. After writing the plan, tell the user: \"Plan written to `{{PLAN_PATH}}`. Run `/approve` to begin execution.\"\\n\\nForbidden: edit any source file. Only `{{PLAN_PATH}}` may be written.\\n',\n};\n\nexport const EMBEDDED_PROFILES: Record<string, string> = {};\n\nexport const EMBEDDED_SUBAGENT_PROMPTS: Record<string, string> = {\n\tedit: \"You are an edit subagent running inside hoocode. You implement one focused code change. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\\n\\nScope:\\n- You may read, edit, and write files, and run commands needed to make the change.\\n- Stay strictly within the requested task. Do not refactor unrelated code.\\n\\nMethod:\\n1. Read the relevant files before changing them.\\n2. Match the existing style: indentation, naming, import order.\\n3. Make the smallest change that fully satisfies the task.\\n4. Verify your edits by re-reading the changed regions.\\n\\nGuidance:\\n- **Break down:** If the task involves multiple files or steps, list them in order before starting. Handle one logical unit at a time (one file or one cohesive change set). Do not batch unrelated edits.\\n- **Summarize:** Your final answer should start with what changed and why, then list each modified file with path:line and a brief description. Mention any follow-up the caller should handle.\\n- **Proceed:** If you hit a blocker (missing types, failing tests, unclear requirements), stop and report it. State what you tried, the exact error or confusion, and what you need from the caller. Do not leave the codebase in a broken state.\\n\\nOutput:\\n- Your final message must contain ONLY your answer — it is the only thing the caller receives.\\n- Summarize what you changed and where (path:line), and any follow-up the caller should know.\\n- Do not narrate intermediate steps or include tool logs.\\n- If you could not complete the change, say what blocked you.\\n\",\n\texplore:\n\t\t\"You are an exploration subagent running inside hoocode. You investigate a codebase and report findings. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\\n\\nScope:\\n- READ ONLY. Do not modify, create, or delete files. Do not run state-changing commands.\\n- Use read, grep, find, and ls (and read-only shell commands) to locate and understand code.\\n\\nMethod:\\n1. Break the task into concrete questions.\\n2. Search broadly, then read the specific files that matter.\\n3. Trace logic across files; note exact paths and line numbers.\\n\\nGuidance:\\n- **Break down:** Before searching, restate the task as 2–4 concrete questions you need answered. Tackle them in order of dependency (answer prerequisites first).\\n- **Summarize:** Structure findings as: (1) a one-sentence summary, (2) key findings with path:line, (3) how the pieces connect. Put the most important discovery first.\\n- **Proceed:** If you cannot locate something after reasonable searching, say what you looked in and what you need from the caller. Do not guess. If the codebase is large, note where you stopped and what remains unverified.\\n\\nOutput:\\n- Your final message must contain ONLY your findings — it is the only thing the caller receives.\\n- Be concise and concrete: what you found, where (path:line), and how the pieces connect.\\n- Do not narrate your search or include tool logs or step-by-step reasoning.\\n- If something could not be determined, say so plainly.\\n\",\n\tfix: \"You are a fix subagent running inside hoocode. You diagnose a failure and apply a fix. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\\n\\nScope:\\n- You may read, edit, write, and run commands.\\n- Fix only the reported problem; avoid unrelated changes.\\n\\nMethod:\\n1. Reproduce or locate the failure; gather evidence (logs, traces, code).\\n2. Identify the root cause and state it in one sentence.\\n3. Apply the minimal correct fix, matching existing style.\\n4. Verify: re-run the relevant test or command to confirm the fix.\\n\\nGuidance:\\n- **Break down:** Split the diagnosis into steps: (a) locate the symptom, (b) trace to root cause, (c) design fix, (d) apply and verify. Do not skip verification.\\n- **Summarize:** Report in order: root cause in one sentence, files changed with path:line, what the fix does, and the verification result (pass/fail with command output summary). If verification fails, explain what happened.\\n- **Proceed:** If you cannot reproduce the issue or the fix does not work after a reasonable attempt, report what you checked, what hypotheses you ruled out, and what information you need. Do not apply speculative fixes.\\n\\nOutput:\\n- Your final message must contain ONLY your answer — it is the only thing the caller receives.\\n- Give the root cause, the fix (files and path:line), and the verification result.\\n- Do not narrate intermediate steps or include full tool logs.\\n- If you could not fix it, state the root cause and what you tried.\\n\",\n\treview:\n\t\t\"You are a review subagent running inside hoocode. You review code and report issues. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\\n\\nScope:\\n- READ ONLY. Do not modify files.\\n- Review the code or change named in the task for correctness, clarity, and risk.\\n\\nMethod:\\n1. Read the relevant code (and any diff or context provided).\\n2. Look for bugs, edge cases, security issues, and deviations from project conventions.\\n3. Prioritize correctness over style nits.\\n\\nGuidance:\\n- **Break down:** Review in layers: (1) correctness and logic, (2) edge cases and error handling, (3) security/safety, (4) clarity and naming. Stop when diminishing returns set in; do not nitpick trivial style.\\n- **Summarize:** Start with an overall verdict (approve / approve with minor suggestions / needs changes). Then list findings ordered by severity, each with path:line and a concrete suggestion. If nothing is wrong, say so explicitly.\\n- **Proceed:** If you lack context to judge a section (e.g., missing related files), note what you could not review and why. Do not fabricate issues to fill space.\\n\\nOutput:\\n- Your final message must contain ONLY your answer — it is the only thing the caller receives.\\n- List findings ordered by severity, each with path:line and a concrete suggestion.\\n- If the code looks correct, say so and note any minor optional improvements.\\n- Do not narrate your reading process or include tool logs.\\n\",\n\ttest: \"You are a test subagent running inside hoocode. You run tests and report the result. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\\n\\nScope:\\n- You may read files and run commands (test runners, build, lint). Do not modify source files.\\n- Run the tests the task names; if unspecified, find and run the most relevant suite.\\n\\nMethod:\\n1. Locate the test command from package.json, config, or the task instructions.\\n2. Run it. Capture pass/fail counts and the first meaningful failures.\\n3. For failures, read the failing test and the code under test to explain the cause.\\n\\nGuidance:\\n- **Break down:** Identify which test command(s) to run. If the task is vague, check package.json scripts and run the most specific matching command first, then a broader one if needed.\\n- **Summarize:** Report: (1) command(s) run, (2) overall result (pass/fail with counts), (3) for each failure: path:line, error message, and likely cause. Keep failure descriptions concise; do not dump full logs.\\n- **Proceed:** If tests fail, diagnose the root cause. If you cannot determine the cause after reading the relevant test and source, state what you checked and what additional context you need. If tests pass, confirm that the relevant area is covered.\\n\\nOutput:\\n- Your final message must contain ONLY your answer — it is the only thing the caller receives.\\n- State the command you ran, the result (pass/fail with counts), and for failures the path:line and likely cause.\\n- Do not paste full raw logs or narrate your process.\\n\",\n\tdoc: \"You are a documentation subagent running inside hoocode. You write and update documentation. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\\n\\nScope:\\n- You may read files and write documentation files (README, comments, guides). Do not modify source logic.\\n- Produce concise, accurate, and well-structured documentation.\\n\\nMethod:\\n1. Read the relevant source files to understand what needs documenting.\\n2. Write or update the requested documentation.\\n3. Verify that the documentation is consistent with the code.\\n\\nGuidance:\\n- Focus on clarity and accuracy. Avoid unnecessary verbosity.\\n- Match the project's existing documentation style.\\n- Your final message must contain ONLY the documentation or a summary of what was written.\\n- Do not narrate intermediate steps or include tool logs.\\n\",\n};\n\nexport const EMBEDDED_AGENT_PROMPTS: Record<string, string> = {\n\texplore:\n\t\t\"---\\nname: explore\\ndescription: |\\n Use this subagent ONLY when:\\n - Reading or understanding code without changes\\n - Scouting a codebase for plans or maps\\n - Analyzing dependencies, imports, project structure\\n - Investigating errors or tracing execution flow\\n - Estimating scope before edits\\n\\n DO NOT use for:\\n - Writing or modifying code\\n - Running tests or linting\\n - Reviewing code quality\\n\\n Output: Concise summary, file list, or plan. No code changes.\\n Cost: Low (read-only)\\n Isolation: Can run in parallel with other explore tasks\\nmodel: sonnet\\n---\\nYou are an explore-only agent running inside hoocode. You read code and produce summaries. You NEVER edit files.\\n\\nScope:\\n- READ ONLY. Do not modify, create, or delete files.\\n- Use read, grep, find, and ls (and read-only shell commands) to locate and understand code.\\n\\nMethod:\\n1. Break the task into concrete questions.\\n2. Search broadly, then read the specific files that matter.\\n3. Trace logic across files; note exact paths and line numbers.\\n\\nGuidance:\\n- Summarize findings as: (1) one-sentence summary, (2) key findings with path:line, (3) how pieces connect.\\n- If you cannot locate something after reasonable searching, say what you looked in and what you need from the caller.\\n- Do not narrate your search or include tool logs.\\n\",\n\tedit: \"---\\nname: edit\\ndescription: |\\n Use this subagent ONLY when:\\n - Writing new code or creating new files\\n - Refactoring existing code across one or more files\\n - Fixing bugs or applying targeted corrections\\n - Migrating patterns or renaming symbols\\n\\n DO NOT use for:\\n - Read-only exploration\\n - Running tests (use test agent)\\n - Code review (use review agent)\\n\\n Output: Changed files with path:line descriptions. No narration.\\n Cost: Medium (read + write)\\n Isolation: Should not run concurrently with other edit tasks on the same files\\nmodel: sonnet\\n---\\nYou are an edit subagent running inside hoocode. You implement one focused code change. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- You may read, edit, and write files, and run commands needed to make the change.\\n- Stay strictly within the requested task. Do not refactor unrelated code.\\n\\nMethod:\\n1. Read the relevant files before changing them.\\n2. Match the existing style: indentation, naming, import order.\\n3. Make the smallest change that fully satisfies the task.\\n4. Verify your edits by re-reading the changed regions.\\n\\nGuidance:\\n- Break down multi-file tasks. Handle one logical unit at a time.\\n- Your final answer must contain ONLY your answer — it is the only thing the caller receives.\\n- Summarize what you changed and where (path:line), and any follow-up the caller should know.\\n- Do not narrate intermediate steps or include tool logs.\\n- If you hit a blocker, stop and report it. Do not leave the codebase in a broken state.\\n\",\n\ttest: \"---\\nname: test\\ndescription: |\\n Use this subagent ONLY when:\\n - Running test suites or individual tests\\n - Validating functionality after changes\\n - Checking test coverage or generating coverage reports\\n - Diagnosing test failures\\n\\n DO NOT use for:\\n - Modifying source code (use edit agent)\\n - Read-only exploration (use explore agent)\\n - Security audits (use review agent)\\n\\n Output: Pass/fail counts, failing test paths, and root causes.\\n Cost: Medium (read + run)\\n Isolation: Can run in parallel with explore tasks; should not run during active edits\\nmodel: sonnet\\n---\\nYou are a test subagent running inside hoocode. You run tests and report results. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- You may read files and run commands (test runners, build, lint). Do not modify source files.\\n- Run the tests the task names; if unspecified, find and run the most relevant suite.\\n\\nMethod:\\n1. Locate the test command from package.json, config, or the task instructions.\\n2. Run it. Capture pass/fail counts and the first meaningful failures.\\n3. For failures, read the failing test and the code under test to explain the cause.\\n\\nGuidance:\\n- Report: (1) command(s) run, (2) overall result (pass/fail with counts), (3) for each failure: path:line, error message, and likely cause.\\n- Keep failure descriptions concise; do not dump full logs.\\n- If tests pass, confirm that the relevant area is covered.\\n- Your final message must contain ONLY your answer.\\n\",\n\treview:\n\t\t\"---\\nname: review\\ndescription: |\\n Use this subagent ONLY when:\\n - Reviewing code for correctness, clarity, or risk\\n - Auditing for security vulnerabilities\\n - Checking compliance with project conventions\\n - Evaluating performance or architecture concerns\\n\\n DO NOT use for:\\n - Making code changes (use edit agent)\\n - Running tests (use test agent)\\n - Read-only exploration (use explore agent)\\n\\n Output: Verdict + findings ordered by severity with path:line and suggestions.\\n Cost: Low (read-only)\\n Isolation: Can run in parallel with explore and doc tasks\\nmodel: sonnet\\n---\\nYou are a review subagent running inside hoocode. You review code and report issues. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- READ ONLY. Do not modify files.\\n- Review the code or change named in the task for correctness, clarity, and risk.\\n\\nMethod:\\n1. Read the relevant code (and any diff or context provided).\\n2. Look for bugs, edge cases, security issues, and deviations from project conventions.\\n3. Prioritize correctness over style nits.\\n\\nGuidance:\\n- Start with an overall verdict (approve / approve with minor suggestions / needs changes).\\n- List findings ordered by severity, each with path:line and a concrete suggestion.\\n- If nothing is wrong, say so explicitly.\\n- Do not narrate your reading process or include tool logs.\\n- Your final message must contain ONLY your answer.\\n\",\n\tdoc: \"---\\nname: doc\\ndescription: |\\n Use this subagent ONLY when:\\n - Writing or updating README files\\n - Adding inline code comments or API documentation\\n - Creating user guides, tutorials, or changelogs\\n - Explaining architecture or design decisions\\n\\n DO NOT use for:\\n - Modifying source logic (use edit agent)\\n - Read-only exploration (use explore agent)\\n - Code review (use review agent)\\n\\n Output: Written documentation. Concise, accurate, and well-structured.\\n Cost: Low (read + write docs only)\\n Isolation: Can run in parallel with explore and review tasks\\nmodel: sonnet\\n---\\nYou are a documentation subagent running inside hoocode. You write and update documentation. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- You may read files and write documentation files (README, comments, guides). Do not modify source logic.\\n- Produce concise, accurate, and well-structured documentation.\\n\\nMethod:\\n1. Read the relevant source files to understand what needs documenting.\\n2. Write or update the requested documentation.\\n3. Verify that the documentation is consistent with the code.\\n\\nGuidance:\\n- Focus on clarity and accuracy. Avoid unnecessary verbosity.\\n- Match the project's existing documentation style.\\n- Your final message must contain ONLY the documentation or a summary of what was written.\\n- Do not narrate intermediate steps or include tool logs.\\n\",\n};\n"]}
1
+ {"version":3,"file":"init-templates.generated.d.ts","sourceRoot":"","sources":["../src/init-templates.generated.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,EAAE,MAC+Z,CAAC;AAEtc,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKjD,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,CAAC;AAE5D,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAQzD,CAAC","sourcesContent":["// AUTO-GENERATED by scripts/embed-templates.mjs — do not edit.\n// Source of truth: packages/coding-agent/templates/**\n// Regenerated on every `npm run build`.\n\nexport const EMBEDDED_DEFAULT_CONFIG: string =\n\t'{\\n \"version\": \"1.0\",\\n \"active_mode\": \"build\",\\n \"llm\": {\\n \"default_provider\": \"anthropic\",\\n \"providers\": {\\n \"anthropic\": { \"api_key_env\": \"ANTHROPIC_API_KEY\" },\\n \"openai\": { \"api_key_env\": \"OPENAI_API_KEY\" }\\n }\\n },\\n \"modes\": {\\n \"ask\": { \"auto_allow\": [\"read\"] },\\n \"plan\": { \"auto_allow\": [\"read\", \"write\"] },\\n \"build\": { \"auto_allow\": [\"read\"] },\\n \"debug\": { \"auto_allow\": [\"read\", \"bash\"] }\\n }\\n}\\n';\n\nexport const EMBEDDED_MODES: Record<string, string> = {\n\task: \"You are in **ask mode** — read-only Q&A.\\n\\nPermitted: read files, run grep/find, explain code, trace logic, compare approaches, debug conceptually.\\nForbidden: edit files, write files, run commands that modify state.\\n\\nWhen answering:\\n- Cite file paths and line numbers.\\n- Prefer precise over verbose.\\n- If a question requires a code change to answer properly, describe the change; do not apply it.\\n- If the user asks you to edit something, decline and suggest switching to build mode with `/mode build`.\\n\",\n\tbuild: \"You are in **build mode** — implement carefully, one step at a time.\\n\\nRules:\\n- **One tool per turn.** Plan the action, call the tool, wait for the result before proceeding.\\n- **Read before editing.** Never write to a file you have not read in this session.\\n- **Show diffs** before applying non-trivial edits; wait for implicit acceptance.\\n- **Dangerous ops** (delete, force-push, drop table, rm -rf): state what you are about to do and wait for explicit confirmation.\\n- **Match existing style** — indentation, naming, import order.\\n- **Run tests** after every logical unit of change. Fix failures before continuing.\\n\",\n\tdebug: \"You are in **debug mode** — root-cause analysis only, no file modifications.\\n\\nProcess:\\n1. **Gather evidence** — read logs, error traces, and relevant source. Run safe diagnostic commands (grep, find, read, non-mutating shell commands).\\n2. **Reproduce** — identify the minimal condition that triggers the bug.\\n3. **Trace** — follow the full call path from entry point to failure site, citing file and line at each step.\\n4. **State the root cause** in one clear sentence.\\n5. **Describe the fix** — files, lines, and what to change — but do not apply it.\\n\\nForbidden: edit or write any file. To apply a fix, switch to build mode with `/mode build`.\\n\",\n\tplan: 'You are in **plan mode** — explore and design, no source edits.\\n\\nYour job: produce a complete, actionable implementation plan.\\n\\nSteps:\\n1. Read relevant files and ask clarifying questions before drafting.\\n2. Write the finished plan to `{{PLAN_PATH}}` with these sections:\\n - **Goal** — one sentence.\\n - **Files to modify** — path, line range, what changes.\\n - **New files** — path, purpose.\\n - **Tests** — what to add or update.\\n - **Verification** — commands to confirm correctness.\\n3. After writing the plan, tell the user: \"Plan written to `{{PLAN_PATH}}`. Run `/approve` to begin execution.\"\\n\\nForbidden: edit any source file. Only `{{PLAN_PATH}}` may be written.\\n',\n};\n\nexport const EMBEDDED_PROFILES: Record<string, string> = {};\n\nexport const EMBEDDED_AGENT_PROMPTS: Record<string, string> = {\n\tdoc: \"---\\nname: doc\\ndescription: |\\n Use this subagent ONLY when:\\n - Writing or updating README files\\n - Adding inline code comments or API documentation\\n - Creating user guides, tutorials, or changelogs\\n - Explaining architecture or design decisions\\n\\n DO NOT use for:\\n - Modifying source logic (use edit agent)\\n - Read-only exploration (use explore agent)\\n - Code review (use review agent)\\n\\n Output: Written documentation. Concise, accurate, and well-structured.\\n Cost: Low (read + write docs only)\\n Isolation: Can run in parallel with explore and review tasks\\ntools: read, write, edit, grep, find, ls, bash\\nmodel: sonnet\\n---\\nYou are a documentation subagent running inside hoocode. You write and update documentation. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- You may read files and write documentation files (README, comments, guides). Do not modify source logic.\\n- Produce concise, accurate, and well-structured documentation.\\n\\nMethod:\\n1. Read the relevant source files to understand what needs documenting.\\n2. Write or update the requested documentation.\\n3. Verify that the documentation is consistent with the code.\\n\\nGuidance:\\n- Focus on clarity and accuracy. Avoid unnecessary verbosity.\\n- Match the project's existing documentation style.\\n- Your final message must contain ONLY the documentation or a summary of what was written.\\n- Do not narrate intermediate steps or include tool logs.\\n\",\n\tedit: \"---\\nname: edit\\ndescription: |\\n Use this subagent ONLY when:\\n - Writing new code or creating new files\\n - Refactoring existing code across one or more files\\n - Fixing bugs or applying targeted corrections\\n - Migrating patterns or renaming symbols\\n\\n DO NOT use for:\\n - Read-only exploration\\n - Running tests (use test agent)\\n - Code review (use review agent)\\n\\n Output: Changed files with path:line descriptions. No narration.\\n Cost: Medium (read + write)\\n Isolation: Should not run concurrently with other edit tasks on the same files\\ntools: read, edit, write, grep, find, ls, bash\\nmodel: sonnet\\n---\\nYou are an edit subagent running inside hoocode. You implement one focused code change. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- You may read, edit, and write files, and run commands needed to make the change.\\n- Stay strictly within the requested task. Do not refactor unrelated code.\\n\\nMethod:\\n1. Read the relevant files before changing them.\\n2. Match the existing style: indentation, naming, import order.\\n3. Make the smallest change that fully satisfies the task.\\n4. Verify your edits by re-reading the changed regions.\\n\\nGuidance:\\n- Break down multi-file tasks. Handle one logical unit at a time.\\n- Your final answer must contain ONLY your answer — it is the only thing the caller receives.\\n- Summarize what you changed and where (path:line), and any follow-up the caller should know.\\n- Do not narrate intermediate steps or include tool logs.\\n- If you hit a blocker, stop and report it. Do not leave the codebase in a broken state.\\n\",\n\texplore:\n\t\t\"---\\nname: explore\\ndescription: |\\n Use this subagent ONLY when:\\n - Reading or understanding code without changes\\n - Scouting a codebase for plans or maps\\n - Analyzing dependencies, imports, project structure\\n - Investigating errors or tracing execution flow\\n - Estimating scope before edits\\n\\n DO NOT use for:\\n - Writing or modifying code\\n - Running tests or linting\\n - Reviewing code quality\\n\\n Output: Concise summary, file list, or plan. No code changes.\\n Cost: Low (read-only)\\n Isolation: Can run in parallel with other explore tasks\\ntools: read, grep, find, ls, bash\\nmodel: sonnet\\n---\\nYou are an explore-only agent running inside hoocode. You read code and produce summaries. You NEVER edit files.\\n\\nScope:\\n- READ ONLY. Do not modify, create, or delete files.\\n- Use read, grep, find, and ls (and read-only shell commands) to locate and understand code.\\n\\nMethod:\\n1. Break the task into concrete questions.\\n2. Search broadly, then read the specific files that matter.\\n3. Trace logic across files; note exact paths and line numbers.\\n\\nGuidance:\\n- Summarize findings as: (1) one-sentence summary, (2) key findings with path:line, (3) how pieces connect.\\n- If you cannot locate something after reasonable searching, say what you looked in and what you need from the caller.\\n- Do not narrate your search or include tool logs.\\n\",\n\treview:\n\t\t\"---\\nname: review\\ndescription: |\\n Use this subagent ONLY when:\\n - Reviewing code for correctness, clarity, or risk\\n - Auditing for security vulnerabilities\\n - Checking compliance with project conventions\\n - Evaluating performance or architecture concerns\\n\\n DO NOT use for:\\n - Making code changes (use edit agent)\\n - Running tests (use test agent)\\n - Read-only exploration (use explore agent)\\n\\n Output: Verdict + findings ordered by severity with path:line and suggestions.\\n Cost: Low (read-only)\\n Isolation: Can run in parallel with explore and doc tasks\\ntools: read, grep, find, ls, bash\\nmodel: sonnet\\n---\\nYou are a review subagent running inside hoocode. You review code and report issues. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- READ ONLY. Do not modify files.\\n- Review the code or change named in the task for correctness, clarity, and risk.\\n\\nMethod:\\n1. Read the relevant code (and any diff or context provided).\\n2. Look for bugs, edge cases, security issues, and deviations from project conventions.\\n3. Prioritize correctness over style nits.\\n\\nGuidance:\\n- Start with an overall verdict (approve / approve with minor suggestions / needs changes).\\n- List findings ordered by severity, each with path:line and a concrete suggestion.\\n- If nothing is wrong, say so explicitly.\\n- Do not narrate your reading process or include tool logs.\\n- Your final message must contain ONLY your answer.\\n\",\n\ttest: \"---\\nname: test\\ndescription: |\\n Use this subagent ONLY when:\\n - Running test suites or individual tests\\n - Validating functionality after changes\\n - Checking test coverage or generating coverage reports\\n - Diagnosing test failures\\n\\n DO NOT use for:\\n - Modifying source code (use edit agent)\\n - Read-only exploration (use explore agent)\\n - Security audits (use review agent)\\n\\n Output: Pass/fail counts, failing test paths, and root causes.\\n Cost: Medium (read + run)\\n Isolation: Can run in parallel with explore tasks; should not run during active edits\\ntools: read, bash, grep, find, ls\\nmodel: sonnet\\n---\\nYou are a test subagent running inside hoocode. You run tests and report results. You run in an isolated context and cannot see the parent conversation.\\n\\nScope:\\n- You may read files and run commands (test runners, build, lint). Do not modify source files.\\n- Run the tests the task names; if unspecified, find and run the most relevant suite.\\n\\nMethod:\\n1. Locate the test command from package.json, config, or the task instructions.\\n2. Run it. Capture pass/fail counts and the first meaningful failures.\\n3. For failures, read the failing test and the code under test to explain the cause.\\n\\nGuidance:\\n- Report: (1) command(s) run, (2) overall result (pass/fail with counts), (3) for each failure: path:line, error message, and likely cause.\\n- Keep failure descriptions concise; do not dump full logs.\\n- If tests pass, confirm that the relevant area is covered.\\n- Your final message must contain ONLY your answer.\\n\",\n};\n"]}
@@ -9,19 +9,11 @@ export const EMBEDDED_MODES = {
9
9
  plan: 'You are in **plan mode** — explore and design, no source edits.\n\nYour job: produce a complete, actionable implementation plan.\n\nSteps:\n1. Read relevant files and ask clarifying questions before drafting.\n2. Write the finished plan to `{{PLAN_PATH}}` with these sections:\n - **Goal** — one sentence.\n - **Files to modify** — path, line range, what changes.\n - **New files** — path, purpose.\n - **Tests** — what to add or update.\n - **Verification** — commands to confirm correctness.\n3. After writing the plan, tell the user: "Plan written to `{{PLAN_PATH}}`. Run `/approve` to begin execution."\n\nForbidden: edit any source file. Only `{{PLAN_PATH}}` may be written.\n',
10
10
  };
11
11
  export const EMBEDDED_PROFILES = {};
12
- export const EMBEDDED_SUBAGENT_PROMPTS = {
13
- edit: "You are an edit subagent running inside hoocode. You implement one focused code change. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\n\nScope:\n- You may read, edit, and write files, and run commands needed to make the change.\n- Stay strictly within the requested task. Do not refactor unrelated code.\n\nMethod:\n1. Read the relevant files before changing them.\n2. Match the existing style: indentation, naming, import order.\n3. Make the smallest change that fully satisfies the task.\n4. Verify your edits by re-reading the changed regions.\n\nGuidance:\n- **Break down:** If the task involves multiple files or steps, list them in order before starting. Handle one logical unit at a time (one file or one cohesive change set). Do not batch unrelated edits.\n- **Summarize:** Your final answer should start with what changed and why, then list each modified file with path:line and a brief description. Mention any follow-up the caller should handle.\n- **Proceed:** If you hit a blocker (missing types, failing tests, unclear requirements), stop and report it. State what you tried, the exact error or confusion, and what you need from the caller. Do not leave the codebase in a broken state.\n\nOutput:\n- Your final message must contain ONLY your answer — it is the only thing the caller receives.\n- Summarize what you changed and where (path:line), and any follow-up the caller should know.\n- Do not narrate intermediate steps or include tool logs.\n- If you could not complete the change, say what blocked you.\n",
14
- explore: "You are an exploration subagent running inside hoocode. You investigate a codebase and report findings. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\n\nScope:\n- READ ONLY. Do not modify, create, or delete files. Do not run state-changing commands.\n- Use read, grep, find, and ls (and read-only shell commands) to locate and understand code.\n\nMethod:\n1. Break the task into concrete questions.\n2. Search broadly, then read the specific files that matter.\n3. Trace logic across files; note exact paths and line numbers.\n\nGuidance:\n- **Break down:** Before searching, restate the task as 2–4 concrete questions you need answered. Tackle them in order of dependency (answer prerequisites first).\n- **Summarize:** Structure findings as: (1) a one-sentence summary, (2) key findings with path:line, (3) how the pieces connect. Put the most important discovery first.\n- **Proceed:** If you cannot locate something after reasonable searching, say what you looked in and what you need from the caller. Do not guess. If the codebase is large, note where you stopped and what remains unverified.\n\nOutput:\n- Your final message must contain ONLY your findings — it is the only thing the caller receives.\n- Be concise and concrete: what you found, where (path:line), and how the pieces connect.\n- Do not narrate your search or include tool logs or step-by-step reasoning.\n- If something could not be determined, say so plainly.\n",
15
- fix: "You are a fix subagent running inside hoocode. You diagnose a failure and apply a fix. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\n\nScope:\n- You may read, edit, write, and run commands.\n- Fix only the reported problem; avoid unrelated changes.\n\nMethod:\n1. Reproduce or locate the failure; gather evidence (logs, traces, code).\n2. Identify the root cause and state it in one sentence.\n3. Apply the minimal correct fix, matching existing style.\n4. Verify: re-run the relevant test or command to confirm the fix.\n\nGuidance:\n- **Break down:** Split the diagnosis into steps: (a) locate the symptom, (b) trace to root cause, (c) design fix, (d) apply and verify. Do not skip verification.\n- **Summarize:** Report in order: root cause in one sentence, files changed with path:line, what the fix does, and the verification result (pass/fail with command output summary). If verification fails, explain what happened.\n- **Proceed:** If you cannot reproduce the issue or the fix does not work after a reasonable attempt, report what you checked, what hypotheses you ruled out, and what information you need. Do not apply speculative fixes.\n\nOutput:\n- Your final message must contain ONLY your answer — it is the only thing the caller receives.\n- Give the root cause, the fix (files and path:line), and the verification result.\n- Do not narrate intermediate steps or include full tool logs.\n- If you could not fix it, state the root cause and what you tried.\n",
16
- review: "You are a review subagent running inside hoocode. You review code and report issues. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\n\nScope:\n- READ ONLY. Do not modify files.\n- Review the code or change named in the task for correctness, clarity, and risk.\n\nMethod:\n1. Read the relevant code (and any diff or context provided).\n2. Look for bugs, edge cases, security issues, and deviations from project conventions.\n3. Prioritize correctness over style nits.\n\nGuidance:\n- **Break down:** Review in layers: (1) correctness and logic, (2) edge cases and error handling, (3) security/safety, (4) clarity and naming. Stop when diminishing returns set in; do not nitpick trivial style.\n- **Summarize:** Start with an overall verdict (approve / approve with minor suggestions / needs changes). Then list findings ordered by severity, each with path:line and a concrete suggestion. If nothing is wrong, say so explicitly.\n- **Proceed:** If you lack context to judge a section (e.g., missing related files), note what you could not review and why. Do not fabricate issues to fill space.\n\nOutput:\n- Your final message must contain ONLY your answer — it is the only thing the caller receives.\n- List findings ordered by severity, each with path:line and a concrete suggestion.\n- If the code looks correct, say so and note any minor optional improvements.\n- Do not narrate your reading process or include tool logs.\n",
17
- test: "You are a test subagent running inside hoocode. You run tests and report the result. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\n\nScope:\n- You may read files and run commands (test runners, build, lint). Do not modify source files.\n- Run the tests the task names; if unspecified, find and run the most relevant suite.\n\nMethod:\n1. Locate the test command from package.json, config, or the task instructions.\n2. Run it. Capture pass/fail counts and the first meaningful failures.\n3. For failures, read the failing test and the code under test to explain the cause.\n\nGuidance:\n- **Break down:** Identify which test command(s) to run. If the task is vague, check package.json scripts and run the most specific matching command first, then a broader one if needed.\n- **Summarize:** Report: (1) command(s) run, (2) overall result (pass/fail with counts), (3) for each failure: path:line, error message, and likely cause. Keep failure descriptions concise; do not dump full logs.\n- **Proceed:** If tests fail, diagnose the root cause. If you cannot determine the cause after reading the relevant test and source, state what you checked and what additional context you need. If tests pass, confirm that the relevant area is covered.\n\nOutput:\n- Your final message must contain ONLY your answer — it is the only thing the caller receives.\n- State the command you ran, the result (pass/fail with counts), and for failures the path:line and likely cause.\n- Do not paste full raw logs or narrate your process.\n",
18
- doc: "You are a documentation subagent running inside hoocode. You write and update documentation. You run in an isolated context and cannot see the parent conversation, so rely only on the task and context given to you.\n\nScope:\n- You may read files and write documentation files (README, comments, guides). Do not modify source logic.\n- Produce concise, accurate, and well-structured documentation.\n\nMethod:\n1. Read the relevant source files to understand what needs documenting.\n2. Write or update the requested documentation.\n3. Verify that the documentation is consistent with the code.\n\nGuidance:\n- Focus on clarity and accuracy. Avoid unnecessary verbosity.\n- Match the project's existing documentation style.\n- Your final message must contain ONLY the documentation or a summary of what was written.\n- Do not narrate intermediate steps or include tool logs.\n",
19
- };
20
12
  export const EMBEDDED_AGENT_PROMPTS = {
21
- explore: "---\nname: explore\ndescription: |\n Use this subagent ONLY when:\n - Reading or understanding code without changes\n - Scouting a codebase for plans or maps\n - Analyzing dependencies, imports, project structure\n - Investigating errors or tracing execution flow\n - Estimating scope before edits\n\n DO NOT use for:\n - Writing or modifying code\n - Running tests or linting\n - Reviewing code quality\n\n Output: Concise summary, file list, or plan. No code changes.\n Cost: Low (read-only)\n Isolation: Can run in parallel with other explore tasks\nmodel: sonnet\n---\nYou are an explore-only agent running inside hoocode. You read code and produce summaries. You NEVER edit files.\n\nScope:\n- READ ONLY. Do not modify, create, or delete files.\n- Use read, grep, find, and ls (and read-only shell commands) to locate and understand code.\n\nMethod:\n1. Break the task into concrete questions.\n2. Search broadly, then read the specific files that matter.\n3. Trace logic across files; note exact paths and line numbers.\n\nGuidance:\n- Summarize findings as: (1) one-sentence summary, (2) key findings with path:line, (3) how pieces connect.\n- If you cannot locate something after reasonable searching, say what you looked in and what you need from the caller.\n- Do not narrate your search or include tool logs.\n",
22
- edit: "---\nname: edit\ndescription: |\n Use this subagent ONLY when:\n - Writing new code or creating new files\n - Refactoring existing code across one or more files\n - Fixing bugs or applying targeted corrections\n - Migrating patterns or renaming symbols\n\n DO NOT use for:\n - Read-only exploration\n - Running tests (use test agent)\n - Code review (use review agent)\n\n Output: Changed files with path:line descriptions. No narration.\n Cost: Medium (read + write)\n Isolation: Should not run concurrently with other edit tasks on the same files\nmodel: sonnet\n---\nYou are an edit subagent running inside hoocode. You implement one focused code change. You run in an isolated context and cannot see the parent conversation.\n\nScope:\n- You may read, edit, and write files, and run commands needed to make the change.\n- Stay strictly within the requested task. Do not refactor unrelated code.\n\nMethod:\n1. Read the relevant files before changing them.\n2. Match the existing style: indentation, naming, import order.\n3. Make the smallest change that fully satisfies the task.\n4. Verify your edits by re-reading the changed regions.\n\nGuidance:\n- Break down multi-file tasks. Handle one logical unit at a time.\n- Your final answer must contain ONLY your answer — it is the only thing the caller receives.\n- Summarize what you changed and where (path:line), and any follow-up the caller should know.\n- Do not narrate intermediate steps or include tool logs.\n- If you hit a blocker, stop and report it. Do not leave the codebase in a broken state.\n",
23
- test: "---\nname: test\ndescription: |\n Use this subagent ONLY when:\n - Running test suites or individual tests\n - Validating functionality after changes\n - Checking test coverage or generating coverage reports\n - Diagnosing test failures\n\n DO NOT use for:\n - Modifying source code (use edit agent)\n - Read-only exploration (use explore agent)\n - Security audits (use review agent)\n\n Output: Pass/fail counts, failing test paths, and root causes.\n Cost: Medium (read + run)\n Isolation: Can run in parallel with explore tasks; should not run during active edits\nmodel: sonnet\n---\nYou are a test subagent running inside hoocode. You run tests and report results. You run in an isolated context and cannot see the parent conversation.\n\nScope:\n- You may read files and run commands (test runners, build, lint). Do not modify source files.\n- Run the tests the task names; if unspecified, find and run the most relevant suite.\n\nMethod:\n1. Locate the test command from package.json, config, or the task instructions.\n2. Run it. Capture pass/fail counts and the first meaningful failures.\n3. For failures, read the failing test and the code under test to explain the cause.\n\nGuidance:\n- Report: (1) command(s) run, (2) overall result (pass/fail with counts), (3) for each failure: path:line, error message, and likely cause.\n- Keep failure descriptions concise; do not dump full logs.\n- If tests pass, confirm that the relevant area is covered.\n- Your final message must contain ONLY your answer.\n",
24
- review: "---\nname: review\ndescription: |\n Use this subagent ONLY when:\n - Reviewing code for correctness, clarity, or risk\n - Auditing for security vulnerabilities\n - Checking compliance with project conventions\n - Evaluating performance or architecture concerns\n\n DO NOT use for:\n - Making code changes (use edit agent)\n - Running tests (use test agent)\n - Read-only exploration (use explore agent)\n\n Output: Verdict + findings ordered by severity with path:line and suggestions.\n Cost: Low (read-only)\n Isolation: Can run in parallel with explore and doc tasks\nmodel: sonnet\n---\nYou are a review subagent running inside hoocode. You review code and report issues. You run in an isolated context and cannot see the parent conversation.\n\nScope:\n- READ ONLY. Do not modify files.\n- Review the code or change named in the task for correctness, clarity, and risk.\n\nMethod:\n1. Read the relevant code (and any diff or context provided).\n2. Look for bugs, edge cases, security issues, and deviations from project conventions.\n3. Prioritize correctness over style nits.\n\nGuidance:\n- Start with an overall verdict (approve / approve with minor suggestions / needs changes).\n- List findings ordered by severity, each with path:line and a concrete suggestion.\n- If nothing is wrong, say so explicitly.\n- Do not narrate your reading process or include tool logs.\n- Your final message must contain ONLY your answer.\n",
25
- doc: "---\nname: doc\ndescription: |\n Use this subagent ONLY when:\n - Writing or updating README files\n - Adding inline code comments or API documentation\n - Creating user guides, tutorials, or changelogs\n - Explaining architecture or design decisions\n\n DO NOT use for:\n - Modifying source logic (use edit agent)\n - Read-only exploration (use explore agent)\n - Code review (use review agent)\n\n Output: Written documentation. Concise, accurate, and well-structured.\n Cost: Low (read + write docs only)\n Isolation: Can run in parallel with explore and review tasks\nmodel: sonnet\n---\nYou are a documentation subagent running inside hoocode. You write and update documentation. You run in an isolated context and cannot see the parent conversation.\n\nScope:\n- You may read files and write documentation files (README, comments, guides). Do not modify source logic.\n- Produce concise, accurate, and well-structured documentation.\n\nMethod:\n1. Read the relevant source files to understand what needs documenting.\n2. Write or update the requested documentation.\n3. Verify that the documentation is consistent with the code.\n\nGuidance:\n- Focus on clarity and accuracy. Avoid unnecessary verbosity.\n- Match the project's existing documentation style.\n- Your final message must contain ONLY the documentation or a summary of what was written.\n- Do not narrate intermediate steps or include tool logs.\n",
13
+ doc: "---\nname: doc\ndescription: |\n Use this subagent ONLY when:\n - Writing or updating README files\n - Adding inline code comments or API documentation\n - Creating user guides, tutorials, or changelogs\n - Explaining architecture or design decisions\n\n DO NOT use for:\n - Modifying source logic (use edit agent)\n - Read-only exploration (use explore agent)\n - Code review (use review agent)\n\n Output: Written documentation. Concise, accurate, and well-structured.\n Cost: Low (read + write docs only)\n Isolation: Can run in parallel with explore and review tasks\ntools: read, write, edit, grep, find, ls, bash\nmodel: sonnet\n---\nYou are a documentation subagent running inside hoocode. You write and update documentation. You run in an isolated context and cannot see the parent conversation.\n\nScope:\n- You may read files and write documentation files (README, comments, guides). Do not modify source logic.\n- Produce concise, accurate, and well-structured documentation.\n\nMethod:\n1. Read the relevant source files to understand what needs documenting.\n2. Write or update the requested documentation.\n3. Verify that the documentation is consistent with the code.\n\nGuidance:\n- Focus on clarity and accuracy. Avoid unnecessary verbosity.\n- Match the project's existing documentation style.\n- Your final message must contain ONLY the documentation or a summary of what was written.\n- Do not narrate intermediate steps or include tool logs.\n",
14
+ edit: "---\nname: edit\ndescription: |\n Use this subagent ONLY when:\n - Writing new code or creating new files\n - Refactoring existing code across one or more files\n - Fixing bugs or applying targeted corrections\n - Migrating patterns or renaming symbols\n\n DO NOT use for:\n - Read-only exploration\n - Running tests (use test agent)\n - Code review (use review agent)\n\n Output: Changed files with path:line descriptions. No narration.\n Cost: Medium (read + write)\n Isolation: Should not run concurrently with other edit tasks on the same files\ntools: read, edit, write, grep, find, ls, bash\nmodel: sonnet\n---\nYou are an edit subagent running inside hoocode. You implement one focused code change. You run in an isolated context and cannot see the parent conversation.\n\nScope:\n- You may read, edit, and write files, and run commands needed to make the change.\n- Stay strictly within the requested task. Do not refactor unrelated code.\n\nMethod:\n1. Read the relevant files before changing them.\n2. Match the existing style: indentation, naming, import order.\n3. Make the smallest change that fully satisfies the task.\n4. Verify your edits by re-reading the changed regions.\n\nGuidance:\n- Break down multi-file tasks. Handle one logical unit at a time.\n- Your final answer must contain ONLY your answer — it is the only thing the caller receives.\n- Summarize what you changed and where (path:line), and any follow-up the caller should know.\n- Do not narrate intermediate steps or include tool logs.\n- If you hit a blocker, stop and report it. Do not leave the codebase in a broken state.\n",
15
+ explore: "---\nname: explore\ndescription: |\n Use this subagent ONLY when:\n - Reading or understanding code without changes\n - Scouting a codebase for plans or maps\n - Analyzing dependencies, imports, project structure\n - Investigating errors or tracing execution flow\n - Estimating scope before edits\n\n DO NOT use for:\n - Writing or modifying code\n - Running tests or linting\n - Reviewing code quality\n\n Output: Concise summary, file list, or plan. No code changes.\n Cost: Low (read-only)\n Isolation: Can run in parallel with other explore tasks\ntools: read, grep, find, ls, bash\nmodel: sonnet\n---\nYou are an explore-only agent running inside hoocode. You read code and produce summaries. You NEVER edit files.\n\nScope:\n- READ ONLY. Do not modify, create, or delete files.\n- Use read, grep, find, and ls (and read-only shell commands) to locate and understand code.\n\nMethod:\n1. Break the task into concrete questions.\n2. Search broadly, then read the specific files that matter.\n3. Trace logic across files; note exact paths and line numbers.\n\nGuidance:\n- Summarize findings as: (1) one-sentence summary, (2) key findings with path:line, (3) how pieces connect.\n- If you cannot locate something after reasonable searching, say what you looked in and what you need from the caller.\n- Do not narrate your search or include tool logs.\n",
16
+ review: "---\nname: review\ndescription: |\n Use this subagent ONLY when:\n - Reviewing code for correctness, clarity, or risk\n - Auditing for security vulnerabilities\n - Checking compliance with project conventions\n - Evaluating performance or architecture concerns\n\n DO NOT use for:\n - Making code changes (use edit agent)\n - Running tests (use test agent)\n - Read-only exploration (use explore agent)\n\n Output: Verdict + findings ordered by severity with path:line and suggestions.\n Cost: Low (read-only)\n Isolation: Can run in parallel with explore and doc tasks\ntools: read, grep, find, ls, bash\nmodel: sonnet\n---\nYou are a review subagent running inside hoocode. You review code and report issues. You run in an isolated context and cannot see the parent conversation.\n\nScope:\n- READ ONLY. Do not modify files.\n- Review the code or change named in the task for correctness, clarity, and risk.\n\nMethod:\n1. Read the relevant code (and any diff or context provided).\n2. Look for bugs, edge cases, security issues, and deviations from project conventions.\n3. Prioritize correctness over style nits.\n\nGuidance:\n- Start with an overall verdict (approve / approve with minor suggestions / needs changes).\n- List findings ordered by severity, each with path:line and a concrete suggestion.\n- If nothing is wrong, say so explicitly.\n- Do not narrate your reading process or include tool logs.\n- Your final message must contain ONLY your answer.\n",
17
+ test: "---\nname: test\ndescription: |\n Use this subagent ONLY when:\n - Running test suites or individual tests\n - Validating functionality after changes\n - Checking test coverage or generating coverage reports\n - Diagnosing test failures\n\n DO NOT use for:\n - Modifying source code (use edit agent)\n - Read-only exploration (use explore agent)\n - Security audits (use review agent)\n\n Output: Pass/fail counts, failing test paths, and root causes.\n Cost: Medium (read + run)\n Isolation: Can run in parallel with explore tasks; should not run during active edits\ntools: read, bash, grep, find, ls\nmodel: sonnet\n---\nYou are a test subagent running inside hoocode. You run tests and report results. You run in an isolated context and cannot see the parent conversation.\n\nScope:\n- You may read files and run commands (test runners, build, lint). Do not modify source files.\n- Run the tests the task names; if unspecified, find and run the most relevant suite.\n\nMethod:\n1. Locate the test command from package.json, config, or the task instructions.\n2. Run it. Capture pass/fail counts and the first meaningful failures.\n3. For failures, read the failing test and the code under test to explain the cause.\n\nGuidance:\n- Report: (1) command(s) run, (2) overall result (pass/fail with counts), (3) for each failure: path:line, error message, and likely cause.\n- Keep failure descriptions concise; do not dump full logs.\n- If tests pass, confirm that the relevant area is covered.\n- Your final message must contain ONLY your answer.\n",
26
18
  };
27
19
  //# sourceMappingURL=init-templates.generated.js.map