@kolisachint/hoocode-agent 0.4.9 → 0.4.11
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.
- package/CHANGELOG.md +12 -0
- package/dist/core/dispatch-evaluator.d.ts +31 -0
- package/dist/core/dispatch-evaluator.d.ts.map +1 -0
- package/dist/core/dispatch-evaluator.js +300 -0
- package/dist/core/dispatch-evaluator.js.map +1 -0
- package/dist/core/lifeguard.d.ts +1 -0
- package/dist/core/lifeguard.d.ts.map +1 -1
- package/dist/core/lifeguard.js +6 -0
- package/dist/core/lifeguard.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/subagent-pool.d.ts +35 -0
- package/dist/core/subagent-pool.d.ts.map +1 -1
- package/dist/core/subagent-pool.js +152 -11
- package/dist/core/subagent-pool.js.map +1 -1
- package/dist/core/subagent.d.ts +9 -1
- package/dist/core/subagent.d.ts.map +1 -1
- package/dist/core/subagent.js +23 -2
- package/dist/core/subagent.js.map +1 -1
- package/dist/core/task-store.d.ts +12 -3
- package/dist/core/task-store.d.ts.map +1 -1
- package/dist/core/task-store.js +5 -2
- package/dist/core/task-store.js.map +1 -1
- package/dist/core/tools/subagent.d.ts +5 -1
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +64 -13
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/init-templates.generated.d.ts +1 -0
- package/dist/init-templates.generated.d.ts.map +1 -1
- package/dist/init-templates.generated.js +8 -0
- package/dist/init-templates.generated.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +2 -2
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +9 -14
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +1 -6
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +1 -5
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/task-panel.d.ts +5 -2
- package/dist/modes/interactive/components/task-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-panel.js +103 -9
- package/dist/modes/interactive/components/task-panel.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +12 -10
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +64 -3
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +5 -5
- package/dist/modes/interactive/theme/light.json +5 -5
- package/docs/routing.md +57 -0
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
- package/templates/agents/doc.md +35 -0
- package/templates/agents/edit.md +37 -0
- package/templates/agents/explore.md +35 -0
- package/templates/agents/review.md +36 -0
- package/templates/agents/test.md +35 -0
- package/templates/subagent/doc.md +16 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../src/core/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKzD,MAAM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F;AAED,mEAAmE;AACnE,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAMlE;AA+DD;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAgFtF","sourcesContent":["/**\n * Subagent core: spawn a fresh, isolated agent loop for one delegated task.\n *\n * Each invocation creates a brand-new in-process AgentSession with:\n * - a clean, minimal system prompt (the mode template, no parent history),\n * - an in-memory session (nothing persisted to disk),\n * - a tool allowlist scoped to the mode.\n *\n * The subagent runs to completion and returns ONLY its final answer string;\n * intermediate reasoning, tool calls, and tool output are discarded.\n */\n\nimport type { AssistantMessage, Model } from \"@kolisachint/hoocode-ai\";\nimport { EMBEDDED_SUBAGENT_PROMPTS } from \"../init-templates.generated.js\";\nimport { createExtensionRuntime, type LoadExtensionsResult } from \"./extensions/index.js\";\nimport type { ModelRegistry } from \"./model-registry.js\";\nimport type { ResourceExtensionPaths, ResourceLoader } from \"./resource-loader.js\";\nimport { createAgentSession } from \"./sdk.js\";\nimport { SessionManager } from \"./session-manager.js\";\n\nexport type SubagentMode = \"explore\" | \"edit\" | \"test\" | \"fix\" | \"review\" | \"doc\";\n\nexport const SUBAGENT_MODES: readonly SubagentMode[] = [\"explore\", \"edit\", \"test\", \"fix\", \"review\", \"doc\"];\n\n/** Tool allowlist per mode. Read-only modes deliberately omit edit/write. */\nconst MODE_TOOLS: Record<SubagentMode, string[]> = {\n\texplore: [\"read\", \"grep\", \"find\", \"ls\", \"bash\"],\n\tedit: [\"read\", \"edit\", \"write\", \"grep\", \"find\", \"ls\", \"bash\"],\n\ttest: [\"read\", \"bash\", \"grep\", \"find\", \"ls\"],\n\tfix: [\"read\", \"edit\", \"write\", \"bash\", \"grep\", \"find\", \"ls\"],\n\treview: [\"read\", \"grep\", \"find\", \"ls\", \"bash\"],\n\tdoc: [\"read\", \"write\", \"edit\", \"grep\", \"find\", \"ls\", \"bash\"],\n};\n\nexport interface RunSubagentOptions {\n\t/** The task to delegate. */\n\ttask: string;\n\t/** Optional context distilled from the parent conversation. */\n\tcontext?: string;\n\t/** Which subagent mode to run. */\n\tmode: SubagentMode;\n\t/** Working directory for the subagent. */\n\tcwd: string;\n\t/** Model to use. When omitted the subagent picks the configured default. */\n\tmodel?: Model<any>;\n\t/** Model registry to reuse (shares the parent's auth). */\n\tmodelRegistry?: ModelRegistry;\n\t/** Abort signal from the parent; aborts the subagent loop. */\n\tsignal?: AbortSignal;\n}\n\nexport interface SubagentResult {\n\tmode: SubagentMode;\n\t/** The subagent's final answer (its last assistant text), or \"\" on failure. */\n\tanswer: string;\n\tok: boolean;\n\t/** Populated when ok is false. */\n\terror?: string;\n\t/** Token and cost usage from the subagent session, if available. */\n\tusage?: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\tcost: number;\n\t};\n}\n\n/** Return the clean, minimal system prompt for a subagent mode. */\nexport function getSubagentSystemPrompt(mode: SubagentMode): string {\n\tconst prompt = EMBEDDED_SUBAGENT_PROMPTS[mode];\n\tif (!prompt) {\n\t\tthrow new Error(`No system prompt template for subagent mode \"${mode}\"`);\n\t}\n\treturn prompt;\n}\n\n/**\n * Resource loader that gives the subagent a clean context: just the mode's\n * system prompt, with no project context files, skills, prompts, or extensions.\n */\nclass MinimalResourceLoader implements ResourceLoader {\n\tprivate readonly extensionsResult: LoadExtensionsResult;\n\n\tconstructor(private readonly systemPrompt: string) {\n\t\tthis.extensionsResult = { extensions: [], errors: [], runtime: createExtensionRuntime() };\n\t}\n\n\tgetExtensions(): LoadExtensionsResult {\n\t\treturn this.extensionsResult;\n\t}\n\n\tgetSkills() {\n\t\treturn { skills: [], diagnostics: [] };\n\t}\n\n\tgetPrompts() {\n\t\treturn { prompts: [], diagnostics: [] };\n\t}\n\n\tgetThemes() {\n\t\treturn { themes: [], diagnostics: [] };\n\t}\n\n\tgetAgentsFiles() {\n\t\treturn { agentsFiles: [], warnings: [] };\n\t}\n\n\tgetSystemPrompt(): string | undefined {\n\t\treturn this.systemPrompt;\n\t}\n\n\tgetAppendSystemPrompt(): string[] {\n\t\treturn [];\n\t}\n\n\taddAppendSystemPrompt(_text: string): void {\n\t\t// Subagents do not accept dynamic prompt appendages.\n\t}\n\n\textendResources(_paths: ResourceExtensionPaths): void {\n\t\t// Subagents do not accept additional resource paths.\n\t}\n\n\tasync reload(): Promise<void> {\n\t\t// Nothing to reload: the context is fixed at construction.\n\t}\n}\n\nfunction composePrompt(task: string, context: string | undefined): string {\n\tconst trimmedContext = context?.trim();\n\tconst trimmedTask = task.trim();\n\tif (trimmedContext) {\n\t\treturn `Context from the calling agent:\\n\\n${trimmedContext}\\n\\nTask: ${trimmedTask}`;\n\t}\n\treturn `Task: ${trimmedTask}`;\n}\n\n/**\n * Run one subagent task to completion and return only its final answer.\n */\nexport async function runSubagent(options: RunSubagentOptions): Promise<SubagentResult> {\n\tconst { task, context, mode, cwd, model, modelRegistry, signal } = options;\n\n\tif (signal?.aborted) {\n\t\treturn { mode, answer: \"\", ok: false, error: \"Subagent aborted before starting.\" };\n\t}\n\n\tconst systemPrompt = getSubagentSystemPrompt(mode);\n\tconst { session } = await createAgentSession({\n\t\tcwd,\n\t\tmodel,\n\t\tmodelRegistry,\n\t\ttools: MODE_TOOLS[mode],\n\t\tresourceLoader: new MinimalResourceLoader(systemPrompt),\n\t\tsessionManager: SessionManager.inMemory(cwd),\n\t});\n\n\tconst onAbort = () => {\n\t\tvoid session.abort();\n\t};\n\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\ttry {\n\t\tif (!session.model) {\n\t\t\treturn { mode, answer: \"\", ok: false, error: \"No model available for the subagent.\" };\n\t\t}\n\n\t\tawait session.bindExtensions({ onError: () => {} });\n\t\tawait session.prompt(composePrompt(task, context), {\n\t\t\texpandPromptTemplates: false,\n\t\t\tsource: \"extension\",\n\t\t});\n\n\t\tconst messages = session.messages;\n\t\tconst last = messages[messages.length - 1];\n\t\tif (last?.role === \"assistant\") {\n\t\t\tconst assistant = last as AssistantMessage;\n\t\t\tif (assistant.stopReason === \"error\" || assistant.stopReason === \"aborted\") {\n\t\t\t\treturn {\n\t\t\t\t\tmode,\n\t\t\t\t\tanswer: \"\",\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: assistant.errorMessage || `Subagent ${assistant.stopReason}.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tconst answer = session.getLastAssistantText() ?? \"\";\n\t\tconst stats = session.getSessionStats();\n\t\treturn {\n\t\t\tmode,\n\t\t\tanswer,\n\t\t\tok: true,\n\t\t\tusage: {\n\t\t\t\tinput: stats.tokens.input,\n\t\t\t\toutput: stats.tokens.output,\n\t\t\t\tcacheRead: stats.tokens.cacheRead,\n\t\t\t\tcacheWrite: stats.tokens.cacheWrite,\n\t\t\t\tcost: stats.cost,\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\tconst stats = session.getSessionStats();\n\t\treturn {\n\t\t\tmode,\n\t\t\tanswer: \"\",\n\t\t\tok: false,\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tusage: {\n\t\t\t\tinput: stats.tokens.input,\n\t\t\t\toutput: stats.tokens.output,\n\t\t\t\tcacheRead: stats.tokens.cacheRead,\n\t\t\t\tcacheWrite: stats.tokens.cacheWrite,\n\t\t\t\tcost: stats.cost,\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\tsession.dispose();\n\t}\n}\n"]}
|
package/dist/core/subagent.js
CHANGED
|
@@ -13,7 +13,7 @@ import { EMBEDDED_SUBAGENT_PROMPTS } from "../init-templates.generated.js";
|
|
|
13
13
|
import { createExtensionRuntime } from "./extensions/index.js";
|
|
14
14
|
import { createAgentSession } from "./sdk.js";
|
|
15
15
|
import { SessionManager } from "./session-manager.js";
|
|
16
|
-
export const SUBAGENT_MODES = ["explore", "edit", "test", "fix", "review"];
|
|
16
|
+
export const SUBAGENT_MODES = ["explore", "edit", "test", "fix", "review", "doc"];
|
|
17
17
|
/** Tool allowlist per mode. Read-only modes deliberately omit edit/write. */
|
|
18
18
|
const MODE_TOOLS = {
|
|
19
19
|
explore: ["read", "grep", "find", "ls", "bash"],
|
|
@@ -21,6 +21,7 @@ const MODE_TOOLS = {
|
|
|
21
21
|
test: ["read", "bash", "grep", "find", "ls"],
|
|
22
22
|
fix: ["read", "edit", "write", "bash", "grep", "find", "ls"],
|
|
23
23
|
review: ["read", "grep", "find", "ls", "bash"],
|
|
24
|
+
doc: ["read", "write", "edit", "grep", "find", "ls", "bash"],
|
|
24
25
|
};
|
|
25
26
|
/** Return the clean, minimal system prompt for a subagent mode. */
|
|
26
27
|
export function getSubagentSystemPrompt(mode) {
|
|
@@ -124,14 +125,34 @@ export async function runSubagent(options) {
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
const answer = session.getLastAssistantText() ?? "";
|
|
127
|
-
|
|
128
|
+
const stats = session.getSessionStats();
|
|
129
|
+
return {
|
|
130
|
+
mode,
|
|
131
|
+
answer,
|
|
132
|
+
ok: true,
|
|
133
|
+
usage: {
|
|
134
|
+
input: stats.tokens.input,
|
|
135
|
+
output: stats.tokens.output,
|
|
136
|
+
cacheRead: stats.tokens.cacheRead,
|
|
137
|
+
cacheWrite: stats.tokens.cacheWrite,
|
|
138
|
+
cost: stats.cost,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
128
141
|
}
|
|
129
142
|
catch (error) {
|
|
143
|
+
const stats = session.getSessionStats();
|
|
130
144
|
return {
|
|
131
145
|
mode,
|
|
132
146
|
answer: "",
|
|
133
147
|
ok: false,
|
|
134
148
|
error: error instanceof Error ? error.message : String(error),
|
|
149
|
+
usage: {
|
|
150
|
+
input: stats.tokens.input,
|
|
151
|
+
output: stats.tokens.output,
|
|
152
|
+
cacheRead: stats.tokens.cacheRead,
|
|
153
|
+
cacheWrite: stats.tokens.cacheWrite,
|
|
154
|
+
cost: stats.cost,
|
|
155
|
+
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D","sourcesContent":["/**\n * Subagent core: spawn a fresh, isolated agent loop for one delegated task.\n *\n * Each invocation creates a brand-new in-process AgentSession with:\n * - a clean, minimal system prompt (the mode template, no parent history),\n * - an in-memory session (nothing persisted to disk),\n * - a tool allowlist scoped to the mode.\n *\n * The subagent runs to completion and returns ONLY its final answer string;\n * intermediate reasoning, tool calls, and tool output are discarded.\n */\n\nimport type { AssistantMessage, Model } from \"@kolisachint/hoocode-ai\";\nimport { EMBEDDED_SUBAGENT_PROMPTS } from \"../init-templates.generated.js\";\nimport { createExtensionRuntime, type LoadExtensionsResult } from \"./extensions/index.js\";\nimport type { ModelRegistry } from \"./model-registry.js\";\nimport type { ResourceExtensionPaths, ResourceLoader } from \"./resource-loader.js\";\nimport { createAgentSession } from \"./sdk.js\";\nimport { SessionManager } from \"./session-manager.js\";\n\nexport type SubagentMode = \"explore\" | \"edit\" | \"test\" | \"fix\" | \"review\";\n\nexport const SUBAGENT_MODES: readonly SubagentMode[] = [\"explore\", \"edit\", \"test\", \"fix\", \"review\"];\n\n/** Tool allowlist per mode. Read-only modes deliberately omit edit/write. */\nconst MODE_TOOLS: Record<SubagentMode, string[]> = {\n\texplore: [\"read\", \"grep\", \"find\", \"ls\", \"bash\"],\n\tedit: [\"read\", \"edit\", \"write\", \"grep\", \"find\", \"ls\", \"bash\"],\n\ttest: [\"read\", \"bash\", \"grep\", \"find\", \"ls\"],\n\tfix: [\"read\", \"edit\", \"write\", \"bash\", \"grep\", \"find\", \"ls\"],\n\treview: [\"read\", \"grep\", \"find\", \"ls\", \"bash\"],\n};\n\nexport interface RunSubagentOptions {\n\t/** The task to delegate. */\n\ttask: string;\n\t/** Optional context distilled from the parent conversation. */\n\tcontext?: string;\n\t/** Which subagent mode to run. */\n\tmode: SubagentMode;\n\t/** Working directory for the subagent. */\n\tcwd: string;\n\t/** Model to use. When omitted the subagent picks the configured default. */\n\tmodel?: Model<any>;\n\t/** Model registry to reuse (shares the parent's auth). */\n\tmodelRegistry?: ModelRegistry;\n\t/** Abort signal from the parent; aborts the subagent loop. */\n\tsignal?: AbortSignal;\n}\n\nexport interface SubagentResult {\n\tmode: SubagentMode;\n\t/** The subagent's final answer (its last assistant text), or \"\" on failure. */\n\tanswer: string;\n\tok: boolean;\n\t/** Populated when ok is false. */\n\terror?: string;\n}\n\n/** Return the clean, minimal system prompt for a subagent mode. */\nexport function getSubagentSystemPrompt(mode: SubagentMode): string {\n\tconst prompt = EMBEDDED_SUBAGENT_PROMPTS[mode];\n\tif (!prompt) {\n\t\tthrow new Error(`No system prompt template for subagent mode \"${mode}\"`);\n\t}\n\treturn prompt;\n}\n\n/**\n * Resource loader that gives the subagent a clean context: just the mode's\n * system prompt, with no project context files, skills, prompts, or extensions.\n */\nclass MinimalResourceLoader implements ResourceLoader {\n\tprivate readonly extensionsResult: LoadExtensionsResult;\n\n\tconstructor(private readonly systemPrompt: string) {\n\t\tthis.extensionsResult = { extensions: [], errors: [], runtime: createExtensionRuntime() };\n\t}\n\n\tgetExtensions(): LoadExtensionsResult {\n\t\treturn this.extensionsResult;\n\t}\n\n\tgetSkills() {\n\t\treturn { skills: [], diagnostics: [] };\n\t}\n\n\tgetPrompts() {\n\t\treturn { prompts: [], diagnostics: [] };\n\t}\n\n\tgetThemes() {\n\t\treturn { themes: [], diagnostics: [] };\n\t}\n\n\tgetAgentsFiles() {\n\t\treturn { agentsFiles: [], warnings: [] };\n\t}\n\n\tgetSystemPrompt(): string | undefined {\n\t\treturn this.systemPrompt;\n\t}\n\n\tgetAppendSystemPrompt(): string[] {\n\t\treturn [];\n\t}\n\n\taddAppendSystemPrompt(_text: string): void {\n\t\t// Subagents do not accept dynamic prompt appendages.\n\t}\n\n\textendResources(_paths: ResourceExtensionPaths): void {\n\t\t// Subagents do not accept additional resource paths.\n\t}\n\n\tasync reload(): Promise<void> {\n\t\t// Nothing to reload: the context is fixed at construction.\n\t}\n}\n\nfunction composePrompt(task: string, context: string | undefined): string {\n\tconst trimmedContext = context?.trim();\n\tconst trimmedTask = task.trim();\n\tif (trimmedContext) {\n\t\treturn `Context from the calling agent:\\n\\n${trimmedContext}\\n\\nTask: ${trimmedTask}`;\n\t}\n\treturn `Task: ${trimmedTask}`;\n}\n\n/**\n * Run one subagent task to completion and return only its final answer.\n */\nexport async function runSubagent(options: RunSubagentOptions): Promise<SubagentResult> {\n\tconst { task, context, mode, cwd, model, modelRegistry, signal } = options;\n\n\tif (signal?.aborted) {\n\t\treturn { mode, answer: \"\", ok: false, error: \"Subagent aborted before starting.\" };\n\t}\n\n\tconst systemPrompt = getSubagentSystemPrompt(mode);\n\tconst { session } = await createAgentSession({\n\t\tcwd,\n\t\tmodel,\n\t\tmodelRegistry,\n\t\ttools: MODE_TOOLS[mode],\n\t\tresourceLoader: new MinimalResourceLoader(systemPrompt),\n\t\tsessionManager: SessionManager.inMemory(cwd),\n\t});\n\n\tconst onAbort = () => {\n\t\tvoid session.abort();\n\t};\n\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\ttry {\n\t\tif (!session.model) {\n\t\t\treturn { mode, answer: \"\", ok: false, error: \"No model available for the subagent.\" };\n\t\t}\n\n\t\tawait session.bindExtensions({ onError: () => {} });\n\t\tawait session.prompt(composePrompt(task, context), {\n\t\t\texpandPromptTemplates: false,\n\t\t\tsource: \"extension\",\n\t\t});\n\n\t\tconst messages = session.messages;\n\t\tconst last = messages[messages.length - 1];\n\t\tif (last?.role === \"assistant\") {\n\t\t\tconst assistant = last as AssistantMessage;\n\t\t\tif (assistant.stopReason === \"error\" || assistant.stopReason === \"aborted\") {\n\t\t\t\treturn {\n\t\t\t\t\tmode,\n\t\t\t\t\tanswer: \"\",\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: assistant.errorMessage || `Subagent ${assistant.stopReason}.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tconst answer = session.getLastAssistantText() ?? \"\";\n\t\treturn { mode, answer, ok: true };\n\t} catch (error) {\n\t\treturn {\n\t\t\tmode,\n\t\t\tanswer: \"\",\n\t\t\tok: false,\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t};\n\t} finally {\n\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\tsession.dispose();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"subagent.js","sourceRoot":"","sources":["../../src/core/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAA6B,MAAM,uBAAuB,CAAC;AAG1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,MAAM,CAAC,MAAM,cAAc,GAA4B,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAE3G,6EAA6E;AAC7E,MAAM,UAAU,GAAmC;IAClD,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC;IAC/C,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC;IAC7D,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC;IAC5C,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC;IAC5D,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC;IAC9C,GAAG,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC;CAC5D,CAAC;AAoCF,mEAAmE;AACnE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M,CAAC,SAAS;gBACjC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU;gBACnC,IAAI,EAAE,KAAK,CAAC,IAAI;aAChB;SACD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,KAAK,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;QACxC,OAAO;YACN,IAAI;YACJ,MAAM,EAAE,EAAE;YACV,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,KAAK,EAAE;gBACN,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK;gBACzB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM;gBAC3B,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;gBACjC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU;gBACnC,IAAI,EAAE,KAAK,CAAC,IAAI;aAChB;SACD,CAAC;IACH,CAAC;YAAS,CAAC;QACV,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;AAAA,CACD","sourcesContent":["/**\n * Subagent core: spawn a fresh, isolated agent loop for one delegated task.\n *\n * Each invocation creates a brand-new in-process AgentSession with:\n * - a clean, minimal system prompt (the mode template, no parent history),\n * - an in-memory session (nothing persisted to disk),\n * - a tool allowlist scoped to the mode.\n *\n * The subagent runs to completion and returns ONLY its final answer string;\n * intermediate reasoning, tool calls, and tool output are discarded.\n */\n\nimport type { AssistantMessage, Model } from \"@kolisachint/hoocode-ai\";\nimport { EMBEDDED_SUBAGENT_PROMPTS } from \"../init-templates.generated.js\";\nimport { createExtensionRuntime, type LoadExtensionsResult } from \"./extensions/index.js\";\nimport type { ModelRegistry } from \"./model-registry.js\";\nimport type { ResourceExtensionPaths, ResourceLoader } from \"./resource-loader.js\";\nimport { createAgentSession } from \"./sdk.js\";\nimport { SessionManager } from \"./session-manager.js\";\n\nexport type SubagentMode = \"explore\" | \"edit\" | \"test\" | \"fix\" | \"review\" | \"doc\";\n\nexport const SUBAGENT_MODES: readonly SubagentMode[] = [\"explore\", \"edit\", \"test\", \"fix\", \"review\", \"doc\"];\n\n/** Tool allowlist per mode. Read-only modes deliberately omit edit/write. */\nconst MODE_TOOLS: Record<SubagentMode, string[]> = {\n\texplore: [\"read\", \"grep\", \"find\", \"ls\", \"bash\"],\n\tedit: [\"read\", \"edit\", \"write\", \"grep\", \"find\", \"ls\", \"bash\"],\n\ttest: [\"read\", \"bash\", \"grep\", \"find\", \"ls\"],\n\tfix: [\"read\", \"edit\", \"write\", \"bash\", \"grep\", \"find\", \"ls\"],\n\treview: [\"read\", \"grep\", \"find\", \"ls\", \"bash\"],\n\tdoc: [\"read\", \"write\", \"edit\", \"grep\", \"find\", \"ls\", \"bash\"],\n};\n\nexport interface RunSubagentOptions {\n\t/** The task to delegate. */\n\ttask: string;\n\t/** Optional context distilled from the parent conversation. */\n\tcontext?: string;\n\t/** Which subagent mode to run. */\n\tmode: SubagentMode;\n\t/** Working directory for the subagent. */\n\tcwd: string;\n\t/** Model to use. When omitted the subagent picks the configured default. */\n\tmodel?: Model<any>;\n\t/** Model registry to reuse (shares the parent's auth). */\n\tmodelRegistry?: ModelRegistry;\n\t/** Abort signal from the parent; aborts the subagent loop. */\n\tsignal?: AbortSignal;\n}\n\nexport interface SubagentResult {\n\tmode: SubagentMode;\n\t/** The subagent's final answer (its last assistant text), or \"\" on failure. */\n\tanswer: string;\n\tok: boolean;\n\t/** Populated when ok is false. */\n\terror?: string;\n\t/** Token and cost usage from the subagent session, if available. */\n\tusage?: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\tcost: number;\n\t};\n}\n\n/** Return the clean, minimal system prompt for a subagent mode. */\nexport function getSubagentSystemPrompt(mode: SubagentMode): string {\n\tconst prompt = EMBEDDED_SUBAGENT_PROMPTS[mode];\n\tif (!prompt) {\n\t\tthrow new Error(`No system prompt template for subagent mode \"${mode}\"`);\n\t}\n\treturn prompt;\n}\n\n/**\n * Resource loader that gives the subagent a clean context: just the mode's\n * system prompt, with no project context files, skills, prompts, or extensions.\n */\nclass MinimalResourceLoader implements ResourceLoader {\n\tprivate readonly extensionsResult: LoadExtensionsResult;\n\n\tconstructor(private readonly systemPrompt: string) {\n\t\tthis.extensionsResult = { extensions: [], errors: [], runtime: createExtensionRuntime() };\n\t}\n\n\tgetExtensions(): LoadExtensionsResult {\n\t\treturn this.extensionsResult;\n\t}\n\n\tgetSkills() {\n\t\treturn { skills: [], diagnostics: [] };\n\t}\n\n\tgetPrompts() {\n\t\treturn { prompts: [], diagnostics: [] };\n\t}\n\n\tgetThemes() {\n\t\treturn { themes: [], diagnostics: [] };\n\t}\n\n\tgetAgentsFiles() {\n\t\treturn { agentsFiles: [], warnings: [] };\n\t}\n\n\tgetSystemPrompt(): string | undefined {\n\t\treturn this.systemPrompt;\n\t}\n\n\tgetAppendSystemPrompt(): string[] {\n\t\treturn [];\n\t}\n\n\taddAppendSystemPrompt(_text: string): void {\n\t\t// Subagents do not accept dynamic prompt appendages.\n\t}\n\n\textendResources(_paths: ResourceExtensionPaths): void {\n\t\t// Subagents do not accept additional resource paths.\n\t}\n\n\tasync reload(): Promise<void> {\n\t\t// Nothing to reload: the context is fixed at construction.\n\t}\n}\n\nfunction composePrompt(task: string, context: string | undefined): string {\n\tconst trimmedContext = context?.trim();\n\tconst trimmedTask = task.trim();\n\tif (trimmedContext) {\n\t\treturn `Context from the calling agent:\\n\\n${trimmedContext}\\n\\nTask: ${trimmedTask}`;\n\t}\n\treturn `Task: ${trimmedTask}`;\n}\n\n/**\n * Run one subagent task to completion and return only its final answer.\n */\nexport async function runSubagent(options: RunSubagentOptions): Promise<SubagentResult> {\n\tconst { task, context, mode, cwd, model, modelRegistry, signal } = options;\n\n\tif (signal?.aborted) {\n\t\treturn { mode, answer: \"\", ok: false, error: \"Subagent aborted before starting.\" };\n\t}\n\n\tconst systemPrompt = getSubagentSystemPrompt(mode);\n\tconst { session } = await createAgentSession({\n\t\tcwd,\n\t\tmodel,\n\t\tmodelRegistry,\n\t\ttools: MODE_TOOLS[mode],\n\t\tresourceLoader: new MinimalResourceLoader(systemPrompt),\n\t\tsessionManager: SessionManager.inMemory(cwd),\n\t});\n\n\tconst onAbort = () => {\n\t\tvoid session.abort();\n\t};\n\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\ttry {\n\t\tif (!session.model) {\n\t\t\treturn { mode, answer: \"\", ok: false, error: \"No model available for the subagent.\" };\n\t\t}\n\n\t\tawait session.bindExtensions({ onError: () => {} });\n\t\tawait session.prompt(composePrompt(task, context), {\n\t\t\texpandPromptTemplates: false,\n\t\t\tsource: \"extension\",\n\t\t});\n\n\t\tconst messages = session.messages;\n\t\tconst last = messages[messages.length - 1];\n\t\tif (last?.role === \"assistant\") {\n\t\t\tconst assistant = last as AssistantMessage;\n\t\t\tif (assistant.stopReason === \"error\" || assistant.stopReason === \"aborted\") {\n\t\t\t\treturn {\n\t\t\t\t\tmode,\n\t\t\t\t\tanswer: \"\",\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: assistant.errorMessage || `Subagent ${assistant.stopReason}.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tconst answer = session.getLastAssistantText() ?? \"\";\n\t\tconst stats = session.getSessionStats();\n\t\treturn {\n\t\t\tmode,\n\t\t\tanswer,\n\t\t\tok: true,\n\t\t\tusage: {\n\t\t\t\tinput: stats.tokens.input,\n\t\t\t\toutput: stats.tokens.output,\n\t\t\t\tcacheRead: stats.tokens.cacheRead,\n\t\t\t\tcacheWrite: stats.tokens.cacheWrite,\n\t\t\t\tcost: stats.cost,\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\tconst stats = session.getSessionStats();\n\t\treturn {\n\t\t\tmode,\n\t\t\tanswer: \"\",\n\t\t\tok: false,\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tusage: {\n\t\t\t\tinput: stats.tokens.input,\n\t\t\t\toutput: stats.tokens.output,\n\t\t\t\tcacheRead: stats.tokens.cacheRead,\n\t\t\t\tcacheWrite: stats.tokens.cacheWrite,\n\t\t\t\tcost: stats.cost,\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\tsession.dispose();\n\t}\n}\n"]}
|
|
@@ -15,11 +15,19 @@ export interface Task {
|
|
|
15
15
|
subagentMode?: string;
|
|
16
16
|
readonly createdAt: number;
|
|
17
17
|
updatedAt: number;
|
|
18
|
+
/** Token and cost usage attributed to this task (e.g. from a subagent session). */
|
|
19
|
+
usage?: {
|
|
20
|
+
input: number;
|
|
21
|
+
output: number;
|
|
22
|
+
cacheRead: number;
|
|
23
|
+
cacheWrite: number;
|
|
24
|
+
cost: number;
|
|
25
|
+
};
|
|
18
26
|
}
|
|
19
27
|
export interface CreateTaskOptions {
|
|
20
28
|
subagentMode?: string;
|
|
21
29
|
}
|
|
22
|
-
export type TaskPatch = Partial<Pick<Task, "title" | "status" | "subagentMode">>;
|
|
30
|
+
export type TaskPatch = Partial<Pick<Task, "title" | "status" | "subagentMode" | "usage">>;
|
|
23
31
|
type Listener = () => void;
|
|
24
32
|
declare class TaskStore {
|
|
25
33
|
private tasks;
|
|
@@ -31,8 +39,9 @@ declare class TaskStore {
|
|
|
31
39
|
/**
|
|
32
40
|
* Remove all finished tasks (done or failed), keeping pending/in_progress ones.
|
|
33
41
|
*
|
|
34
|
-
* Called when
|
|
35
|
-
*
|
|
42
|
+
* Called when a new user message arrives: finished subagent tasks stay visible
|
|
43
|
+
* (with their final status) for the whole turn and only retire when the user
|
|
44
|
+
* starts the next turn, so their outcome remains glanceable until then.
|
|
36
45
|
*/
|
|
37
46
|
retireFinished(): void;
|
|
38
47
|
list(): readonly Task[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-store.d.ts","sourceRoot":"","sources":["../../src/core/task-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEvE,MAAM,WAAW,IAAI;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,CAAC;IACnB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"task-store.d.ts","sourceRoot":"","sources":["../../src/core/task-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEvE,MAAM,WAAW,IAAI;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,CAAC;IACnB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,KAAK,CAAC,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;KACb,CAAC;CACF;AAED,MAAM,WAAW,iBAAiB;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;AAE3F,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAE3B,cAAM,SAAS;IACd,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuB;IAEjD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAa3D;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CASzC;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAKvB;IAED;;;;;;OAMG;IACH,cAAc,IAAI,IAAI,CAIrB;IAED,IAAI,IAAI,SAAS,IAAI,EAAE,CAEtB;IAED,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAKxC;IAED,yDAAyD;IACzD,KAAK,IAAI,IAAI,CAIZ;IAED,OAAO,CAAC,IAAI;CAKZ;AAED,uCAAuC;AACvC,eAAO,MAAM,SAAS,WAAkB,CAAC","sourcesContent":["/**\n * Minimal in-process task store.\n *\n * Tracks short-lived tasks (e.g. subagent delegations) so the TUI task panel can\n * display active work. It is a process-level singleton because the tool that\n * creates tasks and the footer that renders them live in the same process and\n * there is no cross-process boundary to cross.\n */\n\nexport type TaskStatus = \"pending\" | \"in_progress\" | \"done\" | \"failed\";\n\nexport interface Task {\n\treadonly id: number;\n\ttitle: string;\n\tstatus: TaskStatus;\n\t/** Subagent mode when this task is owned by a subagent (e.g. \"explore\"). */\n\tsubagentMode?: string;\n\treadonly createdAt: number;\n\tupdatedAt: number;\n\t/** Token and cost usage attributed to this task (e.g. from a subagent session). */\n\tusage?: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\tcost: number;\n\t};\n}\n\nexport interface CreateTaskOptions {\n\tsubagentMode?: string;\n}\n\nexport type TaskPatch = Partial<Pick<Task, \"title\" | \"status\" | \"subagentMode\" | \"usage\">>;\n\ntype Listener = () => void;\n\nclass TaskStore {\n\tprivate tasks: Task[] = [];\n\tprivate nextId = 1;\n\tprivate readonly listeners = new Set<Listener>();\n\n\tcreate(title: string, options: CreateTaskOptions = {}): Task {\n\t\tconst now = Date.now();\n\t\tconst task: Task = {\n\t\t\tid: this.nextId++,\n\t\t\ttitle: title.trim() || \"(untitled task)\",\n\t\t\tstatus: \"pending\",\n\t\t\tsubagentMode: options.subagentMode,\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t};\n\t\tthis.tasks.push(task);\n\t\tthis.emit();\n\t\treturn task;\n\t}\n\n\tupdate(id: number, patch: TaskPatch): void {\n\t\tconst task = this.tasks.find((t) => t.id === id);\n\t\tif (!task) return;\n\t\tif (patch.title !== undefined) task.title = patch.title;\n\t\tif (patch.status !== undefined) task.status = patch.status;\n\t\tif (patch.subagentMode !== undefined) task.subagentMode = patch.subagentMode;\n\t\tif (patch.usage !== undefined) task.usage = patch.usage;\n\t\ttask.updatedAt = Date.now();\n\t\tthis.emit();\n\t}\n\n\tremove(id: number): void {\n\t\tconst idx = this.tasks.findIndex((t) => t.id === id);\n\t\tif (idx === -1) return;\n\t\tthis.tasks.splice(idx, 1);\n\t\tthis.emit();\n\t}\n\n\t/**\n\t * Remove all finished tasks (done or failed), keeping pending/in_progress ones.\n\t *\n\t * Called when a new user message arrives: finished subagent tasks stay visible\n\t * (with their final status) for the whole turn and only retire when the user\n\t * starts the next turn, so their outcome remains glanceable until then.\n\t */\n\tretireFinished(): void {\n\t\tconst before = this.tasks.length;\n\t\tthis.tasks = this.tasks.filter((t) => t.status !== \"done\" && t.status !== \"failed\");\n\t\tif (this.tasks.length !== before) this.emit();\n\t}\n\n\tlist(): readonly Task[] {\n\t\treturn this.tasks;\n\t}\n\n\tsubscribe(listener: Listener): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\t/** Clear all tasks. Intended for test isolation only. */\n\tclear(): void {\n\t\tthis.tasks = [];\n\t\tthis.nextId = 1;\n\t\tthis.emit();\n\t}\n\n\tprivate emit(): void {\n\t\tfor (const listener of this.listeners) {\n\t\t\tlistener();\n\t\t}\n\t}\n}\n\n/** Shared, process-wide task store. */\nexport const taskStore = new TaskStore();\n"]}
|
package/dist/core/task-store.js
CHANGED
|
@@ -34,6 +34,8 @@ class TaskStore {
|
|
|
34
34
|
task.status = patch.status;
|
|
35
35
|
if (patch.subagentMode !== undefined)
|
|
36
36
|
task.subagentMode = patch.subagentMode;
|
|
37
|
+
if (patch.usage !== undefined)
|
|
38
|
+
task.usage = patch.usage;
|
|
37
39
|
task.updatedAt = Date.now();
|
|
38
40
|
this.emit();
|
|
39
41
|
}
|
|
@@ -47,8 +49,9 @@ class TaskStore {
|
|
|
47
49
|
/**
|
|
48
50
|
* Remove all finished tasks (done or failed), keeping pending/in_progress ones.
|
|
49
51
|
*
|
|
50
|
-
* Called when
|
|
51
|
-
*
|
|
52
|
+
* Called when a new user message arrives: finished subagent tasks stay visible
|
|
53
|
+
* (with their final status) for the whole turn and only retire when the user
|
|
54
|
+
* starts the next turn, so their outcome remains glanceable until then.
|
|
52
55
|
*/
|
|
53
56
|
retireFinished() {
|
|
54
57
|
const before = this.tasks.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-store.js","sourceRoot":"","sources":["../../src/core/task-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"task-store.js","sourceRoot":"","sources":["../../src/core/task-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA8BH,MAAM,SAAS;IACN,KAAK,GAAW,EAAE,CAAC;IACnB,MAAM,GAAG,CAAC,CAAC;IACF,SAAS,GAAG,IAAI,GAAG,EAAY,CAAC;IAEjD,MAAM,CAAC,KAAa,EAAE,O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M,CAAC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC","sourcesContent":["/**\n * Minimal in-process task store.\n *\n * Tracks short-lived tasks (e.g. subagent delegations) so the TUI task panel can\n * display active work. It is a process-level singleton because the tool that\n * creates tasks and the footer that renders them live in the same process and\n * there is no cross-process boundary to cross.\n */\n\nexport type TaskStatus = \"pending\" | \"in_progress\" | \"done\" | \"failed\";\n\nexport interface Task {\n\treadonly id: number;\n\ttitle: string;\n\tstatus: TaskStatus;\n\t/** Subagent mode when this task is owned by a subagent (e.g. \"explore\"). */\n\tsubagentMode?: string;\n\treadonly createdAt: number;\n\tupdatedAt: number;\n\t/** Token and cost usage attributed to this task (e.g. from a subagent session). */\n\tusage?: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\tcost: number;\n\t};\n}\n\nexport interface CreateTaskOptions {\n\tsubagentMode?: string;\n}\n\nexport type TaskPatch = Partial<Pick<Task, \"title\" | \"status\" | \"subagentMode\" | \"usage\">>;\n\ntype Listener = () => void;\n\nclass TaskStore {\n\tprivate tasks: Task[] = [];\n\tprivate nextId = 1;\n\tprivate readonly listeners = new Set<Listener>();\n\n\tcreate(title: string, options: CreateTaskOptions = {}): Task {\n\t\tconst now = Date.now();\n\t\tconst task: Task = {\n\t\t\tid: this.nextId++,\n\t\t\ttitle: title.trim() || \"(untitled task)\",\n\t\t\tstatus: \"pending\",\n\t\t\tsubagentMode: options.subagentMode,\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t};\n\t\tthis.tasks.push(task);\n\t\tthis.emit();\n\t\treturn task;\n\t}\n\n\tupdate(id: number, patch: TaskPatch): void {\n\t\tconst task = this.tasks.find((t) => t.id === id);\n\t\tif (!task) return;\n\t\tif (patch.title !== undefined) task.title = patch.title;\n\t\tif (patch.status !== undefined) task.status = patch.status;\n\t\tif (patch.subagentMode !== undefined) task.subagentMode = patch.subagentMode;\n\t\tif (patch.usage !== undefined) task.usage = patch.usage;\n\t\ttask.updatedAt = Date.now();\n\t\tthis.emit();\n\t}\n\n\tremove(id: number): void {\n\t\tconst idx = this.tasks.findIndex((t) => t.id === id);\n\t\tif (idx === -1) return;\n\t\tthis.tasks.splice(idx, 1);\n\t\tthis.emit();\n\t}\n\n\t/**\n\t * Remove all finished tasks (done or failed), keeping pending/in_progress ones.\n\t *\n\t * Called when a new user message arrives: finished subagent tasks stay visible\n\t * (with their final status) for the whole turn and only retire when the user\n\t * starts the next turn, so their outcome remains glanceable until then.\n\t */\n\tretireFinished(): void {\n\t\tconst before = this.tasks.length;\n\t\tthis.tasks = this.tasks.filter((t) => t.status !== \"done\" && t.status !== \"failed\");\n\t\tif (this.tasks.length !== before) this.emit();\n\t}\n\n\tlist(): readonly Task[] {\n\t\treturn this.tasks;\n\t}\n\n\tsubscribe(listener: Listener): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\t/** Clear all tasks. Intended for test isolation only. */\n\tclear(): void {\n\t\tthis.tasks = [];\n\t\tthis.nextId = 1;\n\t\tthis.emit();\n\t}\n\n\tprivate emit(): void {\n\t\tfor (const listener of this.listeners) {\n\t\t\tlistener();\n\t\t}\n\t}\n}\n\n/** Shared, process-wide task store. */\nexport const taskStore = new TaskStore();\n"]}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/** System prompt appendix for the main session when subagent tooling is enabled.
|
|
10
10
|
* Instructs the parent agent on when and how to delegate effectively. */
|
|
11
|
-
export declare const SUBAGENT_MAIN_PROMPT = "You have access to the **subagent** tool. Use it to delegate self-contained tasks to isolated subagent loops that run with their own context and return only their final answer.\n\nAvailable subagent modes:\n- explore: read-only investigation (read, grep, find, ls, bash).\n- edit: make a focused code change (read, edit, write, grep, find, ls, bash).\n- test: run tests and report (read, bash, grep, find, ls).\n- fix: diagnose and fix a failure (read, edit, write, bash, grep, find, ls).\n- review: read-only code review (read, grep, find, ls, bash).\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- Make every task specific and self-contained. The subagent cannot see this conversation.\n- Pass all necessary context (files, constraints, prior findings) via the `context` parameter.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning.\n- Do NOT delegate edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Intermediate reasoning, tool calls, and output are hidden from you.";
|
|
11
|
+
export declare const SUBAGENT_MAIN_PROMPT = "You have access to the **subagent** tool. Use it to delegate self-contained tasks to isolated subagent loops that run with their own context and return only their final answer.\n\nAvailable subagent modes:\n- explore: read-only investigation (read, grep, find, ls, bash).\n- edit: make a focused code change (read, edit, write, grep, find, ls, bash).\n- test: run tests and report (read, bash, grep, find, ls).\n- fix: diagnose and fix a failure (read, edit, write, bash, grep, find, ls).\n- review: read-only code review (read, grep, find, ls, bash).\n- doc: write documentation, README, or comments (read, write, edit, grep, find, ls, bash).\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- Make every task specific and self-contained. The subagent cannot see this conversation.\n- Pass all necessary context (files, constraints, prior findings) via the `context` parameter.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning.\n- Do NOT delegate edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Intermediate reasoning, tool calls, and output are hidden from you.\n\nDispatch evaluator:\n- The dispatch evaluator determines if a subagent is needed. Do not spawn subagents directly unless the user explicitly requests it.\n- For simple single-file changes (<50 lines, read-only or trivial edit), handle them inline.\n- Use force=true to bypass evaluation when you are certain a subagent is required.";
|
|
12
12
|
import type { ToolDefinition } from "../extensions/types.js";
|
|
13
13
|
import { type SubagentMode } from "../subagent.js";
|
|
14
14
|
export interface SubagentToolDetails {
|
|
@@ -16,7 +16,11 @@ export interface SubagentToolDetails {
|
|
|
16
16
|
ok: boolean;
|
|
17
17
|
error?: string;
|
|
18
18
|
taskId: number;
|
|
19
|
+
/** True when the evaluator handled the task inline instead of delegating. */
|
|
20
|
+
inline?: boolean;
|
|
19
21
|
}
|
|
22
|
+
/** Quick check: should this task go to a subagent? */
|
|
23
|
+
export declare function isSubagentRecommended(task: string): boolean;
|
|
20
24
|
/** Create the subagent tool definition. Registered as a customTool when enabled. */
|
|
21
25
|
export declare function createSubagentToolDefinition(): ToolDefinition;
|
|
22
26
|
//# sourceMappingURL=subagent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../../src/core/tools/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;0EAC0E;AAC1E,eAAO,MAAM,oBAAoB,m8CAoBiF,CAAC;AAInH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA6BhE,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,YAAY,CAAC;IACnB,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf;AAQD,oFAAoF;AACpF,wBAAgB,4BAA4B,IAAI,cAAc,CAiE7D","sourcesContent":["/**\n * Subagent tool: delegate a focused task to a fresh, isolated agent loop.\n *\n * The tool registers a task in the shared task store (visible in the task panel),\n * runs the subagent to completion, and returns ONLY the subagent's final\n * answer. It is an optional, opt-in tool (enabled via --subagent or the\n * `enableSubagent` setting); see buildSessionOptions in main.ts.\n */\n\n/** System prompt appendix for the main session when subagent tooling is enabled.\n * Instructs the parent agent on when and how to delegate effectively. */\nexport const SUBAGENT_MAIN_PROMPT = `You have access to the **subagent** tool. Use it to delegate self-contained tasks to isolated subagent loops that run with their own context and return only their final answer.\n\nAvailable subagent modes:\n- explore: read-only investigation (read, grep, find, ls, bash).\n- edit: make a focused code change (read, edit, write, grep, find, ls, bash).\n- test: run tests and report (read, bash, grep, find, ls).\n- fix: diagnose and fix a failure (read, edit, write, bash, grep, find, ls).\n- review: read-only code review (read, grep, find, ls, bash).\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- Make every task specific and self-contained. The subagent cannot see this conversation.\n- Pass all necessary context (files, constraints, prior findings) via the \\`context\\` parameter.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning.\n- Do NOT delegate edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Intermediate reasoning, tool calls, and output are hidden from you.`;\n\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type Static, Type } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { defineTool } from \"../extensions/types.js\";\nimport { runSubagent, type SubagentMode } from \"../subagent.js\";\nimport { taskStore } from \"../task-store.js\";\n\nconst subagentParams = Type.Object({\n\ttask: Type.String({\n\t\tdescription:\n\t\t\t\"The task to delegate. Make it specific and self-contained; the subagent cannot see this conversation.\",\n\t}),\n\tcontext: Type.String({\n\t\tdescription:\n\t\t\t'Context distilled from the conversation the subagent needs (files, constraints, prior findings). Pass \"\" if none.',\n\t}),\n\tmode: Type.Union(\n\t\t[\n\t\t\tType.Literal(\"explore\"),\n\t\t\tType.Literal(\"edit\"),\n\t\t\tType.Literal(\"test\"),\n\t\t\tType.Literal(\"fix\"),\n\t\t\tType.Literal(\"review\"),\n\t\t],\n\t\t{\n\t\t\tdescription:\n\t\t\t\t\"explore: read-only investigation. edit: make a focused code change. test: run tests and report. fix: diagnose and fix a failure. review: read-only code review.\",\n\t\t},\n\t),\n});\n\ntype SubagentParams = Static<typeof subagentParams>;\n\nexport interface SubagentToolDetails {\n\tmode: SubagentMode;\n\tok: boolean;\n\terror?: string;\n\ttaskId: number;\n}\n\n/** First line of the task, trimmed to a short summary for the task list/footer. */\nfunction summarize(task: string): string {\n\tconst firstLine = task.trim().split(\"\\n\")[0] ?? \"\";\n\treturn firstLine.length > 60 ? `${firstLine.slice(0, 57)}...` : firstLine || \"(task)\";\n}\n\n/** Create the subagent tool definition. Registered as a customTool when enabled. */\nexport function createSubagentToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof subagentParams, SubagentToolDetails>({\n\t\tname: \"subagent\",\n\t\tlabel: \"Subagent\",\n\t\tdescription: [\n\t\t\t\"Delegate a focused task to a subagent that runs in a fresh, isolated context (it cannot see this conversation).\",\n\t\t\t\"Pass everything it needs via `context`. The subagent returns only its final answer.\",\n\t\t\t\"Modes: explore, edit, test, fix, review.\",\n\t\t\t\"WHEN TO USE: (1) The work is self-contained and you do not need to see intermediate steps — only the final result.\",\n\t\t\t\"(2) You want to investigate or edit something in parallel without losing your current context or reasoning chain.\",\n\t\t\t\"(3) The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug).\",\n\t\t\t\"(4) You need to run a long command or test suite and wait for its output without blocking your own reasoning.\",\n\t\t\t\"Do NOT use for tasks that require tight back-and-forth with your current reasoning or that change files you are actively reasoning about.\",\n\t\t].join(\" \"),\n\t\tpromptSnippet: \"delegate a self-contained task to an isolated subagent (modes: explore/edit/test/fix/review)\",\n\t\tparameters: subagentParams,\n\n\t\tasync execute(_toolCallId, params: SubagentParams, signal, _onUpdate, ctx) {\n\t\t\tconst mode = params.mode as SubagentMode;\n\t\t\tconst summary = summarize(params.task);\n\n\t\t\tconst task = taskStore.create(summary, { subagentMode: mode });\n\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\ttry {\n\t\t\t\tconst result = await runSubagent({\n\t\t\t\t\ttask: params.task,\n\t\t\t\t\tcontext: params.context,\n\t\t\t\t\tmode,\n\t\t\t\t\tcwd: ctx.cwd,\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\tsignal: signal ?? ctx.signal,\n\t\t\t\t});\n\n\t\t\t\tif (!result.ok) {\n\t\t\t\t\t// Signal failure by throwing: the agent loop derives a tool's error\n\t\t\t\t\t// state from a thrown error, not from a returned flag.\n\t\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\t\tthrow new Error(`Subagent (${mode}) failed: ${result.error ?? \"unknown error\"}`);\n\t\t\t\t}\n\n\t\t\t\t// Leave the task in the store with its final status. It stays visible in\n\t\t\t\t// the task panel until the main agent moves on (retireFinished is called\n\t\t\t\t// when the main agent starts its next turn).\n\t\t\t\ttaskStore.update(task.id, { status: \"done\" });\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: result.answer || \"(subagent returned no output)\" }],\n\t\t\t\t\tdetails: { mode, ok: true, taskId: task.id },\n\t\t\t\t};\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 mode = args.mode ?? \"explore\";\n\t\t\tconst preview = summarize(args.task ?? \"\");\n\t\t\tconst text =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"subagent \")) +\n\t\t\t\ttheme.fg(\"accent\", `[${mode}]`) +\n\t\t\t\ttheme.fg(\"dim\", ` ${preview}`);\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;;;;;;;GAOG;AAEH;0EAC0E;AAC1E,eAAO,MAAM,oBAAoB,82DA0BkD,CAAC;AAKpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAmChE,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,YAAY,CAAC;IACnB,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAgBD,sDAAsD;AACtD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG3D;AAOD,oFAAoF;AACpF,wBAAgB,4BAA4B,IAAI,cAAc,CAuF7D","sourcesContent":["/**\n * Subagent tool: delegate a focused task to a fresh, isolated agent loop.\n *\n * The tool registers a task in the shared task store (visible in the task panel),\n * runs the subagent to completion, and returns ONLY the subagent's final\n * answer. It is an optional, opt-in tool (enabled via --subagent or the\n * `enableSubagent` setting); see buildSessionOptions in main.ts.\n */\n\n/** System prompt appendix for the main session when subagent tooling is enabled.\n * Instructs the parent agent on when and how to delegate effectively. */\nexport const SUBAGENT_MAIN_PROMPT = `You have access to the **subagent** tool. Use it to delegate self-contained tasks to isolated subagent loops that run with their own context and return only their final answer.\n\nAvailable subagent modes:\n- explore: read-only investigation (read, grep, find, ls, bash).\n- edit: make a focused code change (read, edit, write, grep, find, ls, bash).\n- test: run tests and report (read, bash, grep, find, ls).\n- fix: diagnose and fix a failure (read, edit, write, bash, grep, find, ls).\n- review: read-only code review (read, grep, find, ls, bash).\n- doc: write documentation, README, or comments (read, write, edit, grep, find, ls, bash).\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- Make every task specific and self-contained. The subagent cannot see this conversation.\n- Pass all necessary context (files, constraints, prior findings) via the \\`context\\` parameter.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning.\n- Do NOT delegate edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Intermediate reasoning, tool calls, and output are hidden from you.\n\nDispatch evaluator:\n- The dispatch evaluator determines if a subagent is needed. Do not spawn subagents directly unless the user explicitly requests it.\n- For simple single-file changes (<50 lines, read-only or trivial edit), handle them inline.\n- Use force=true to bypass evaluation when you are certain a subagent is required.`;\n\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { type AgentType, DispatchEvaluator } from \"../dispatch-evaluator.js\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { defineTool } from \"../extensions/types.js\";\nimport { runSubagent, type SubagentMode } from \"../subagent.js\";\nimport { taskStore } from \"../task-store.js\";\n\nconst subagentParams = Type.Object({\n\ttask: Type.String({\n\t\tdescription:\n\t\t\t\"The task to delegate. Make it specific and self-contained; the subagent cannot see this conversation.\",\n\t}),\n\tcontext: Type.String({\n\t\tdescription:\n\t\t\t'Context distilled from the conversation the subagent needs (files, constraints, prior findings). Pass \"\" if none.',\n\t}),\n\tmode: Type.Union(\n\t\t[\n\t\t\tType.Literal(\"explore\"),\n\t\t\tType.Literal(\"edit\"),\n\t\t\tType.Literal(\"test\"),\n\t\t\tType.Literal(\"fix\"),\n\t\t\tType.Literal(\"review\"),\n\t\t\tType.Literal(\"doc\"),\n\t\t],\n\t\t{\n\t\t\tdescription:\n\t\t\t\t\"explore: read-only investigation. edit: make a focused code change. test: run tests and report. fix: diagnose and fix a failure. review: read-only code review. doc: write documentation.\",\n\t\t},\n\t),\n\tforce: Type.Boolean({\n\t\tdescription:\n\t\t\t\"Bypass dispatch evaluation and spawn the subagent directly. Use when you are certain a subagent is required.\",\n\t\tdefault: false,\n\t}),\n});\n\ntype SubagentParams = Static<typeof subagentParams>;\n\nexport interface SubagentToolDetails {\n\tmode: SubagentMode;\n\tok: boolean;\n\terror?: string;\n\ttaskId: number;\n\t/** True when the evaluator handled the task inline instead of delegating. */\n\tinline?: boolean;\n}\n\n/**\n * A short, human-readable task name for the task panel: the first line of the\n * task limited to ~4–8 words so it stays glanceable in the pane. A character cap\n * guards against a single very 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 check: should this task go to a subagent? */\nexport function isSubagentRecommended(task: string): boolean {\n\tconst evaluator = new DispatchEvaluator();\n\treturn evaluator.evaluate(task).should_delegate;\n}\n\n/** Map evaluator AgentType to SubagentMode (they are compatible strings). */\nfunction toSubagentMode(agentType: AgentType | null): SubagentMode {\n\treturn (agentType as SubagentMode) ?? \"explore\";\n}\n\n/** Create the subagent tool definition. Registered as a customTool when enabled. */\nexport function createSubagentToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof subagentParams, SubagentToolDetails>({\n\t\tname: \"subagent\",\n\t\tlabel: \"Subagent\",\n\t\tdescription: [\n\t\t\t\"Delegate a focused task to a subagent that runs in a fresh, isolated context (it cannot see this conversation).\",\n\t\t\t\"Pass everything it needs via `context`. The subagent returns only its final answer.\",\n\t\t\t\"Modes: explore, edit, test, fix, review, doc.\",\n\t\t\t\"WHEN TO USE: (1) The work is self-contained and you do not need to see intermediate steps — only the final result.\",\n\t\t\t\"(2) You want to investigate or edit something in parallel without losing your current context or reasoning chain.\",\n\t\t\t\"(3) The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug, write docs).\",\n\t\t\t\"(4) You need to run a long command or test suite and wait for its output without blocking your own reasoning.\",\n\t\t\t\"Do NOT use for tasks that require tight back-and-forth with your current reasoning or that change files you are actively reasoning about.\",\n\t\t\t\"Use force=true to bypass dispatch evaluation when you are certain a subagent is required.\",\n\t\t].join(\" \"),\n\t\tpromptSnippet: \"delegate a self-contained task to an isolated subagent (modes: explore/edit/test/fix/review/doc)\",\n\t\tparameters: subagentParams,\n\n\t\tasync execute(_toolCallId, params: SubagentParams, signal, _onUpdate, ctx) {\n\t\t\tconst forcedMode = params.mode as SubagentMode;\n\n\t\t\t// Dispatch evaluation\n\t\t\tif (!params.force) {\n\t\t\t\tconst evaluator = new DispatchEvaluator();\n\t\t\t\tconst analysis = evaluator.evaluate(params.task);\n\t\t\t\tif (!analysis.should_delegate) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: `Task is simple enough for inline handling. Reason: ${analysis.reason}. Use force=true for subagent override.`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { mode: forcedMode, ok: true, taskId: 0, inline: true },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst mode = params.force\n\t\t\t\t? forcedMode\n\t\t\t\t: toSubagentMode(new DispatchEvaluator().evaluate(params.task).agent_type);\n\t\t\tconst summary = summarize(params.task);\n\n\t\t\tconst task = taskStore.create(summary, { subagentMode: mode });\n\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\ttry {\n\t\t\t\tconst result = await runSubagent({\n\t\t\t\t\ttask: params.task,\n\t\t\t\t\tcontext: params.context,\n\t\t\t\t\tmode,\n\t\t\t\t\tcwd: ctx.cwd,\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\tsignal: signal ?? ctx.signal,\n\t\t\t\t});\n\n\t\t\t\tif (!result.ok) {\n\t\t\t\t\t// Signal failure by throwing: the agent loop derives a tool's error\n\t\t\t\t\t// state from a thrown error, not from a returned flag.\n\t\t\t\t\ttaskStore.update(task.id, { status: \"failed\", usage: result.usage });\n\t\t\t\t\tthrow new Error(`Subagent (${mode}) failed: ${result.error ?? \"unknown error\"}`);\n\t\t\t\t}\n\n\t\t\t\t// Leave the task in the store with its final status. It stays visible in\n\t\t\t\t// the task panel until the next user message arrives (retireFinished is\n\t\t\t\t// called when the user starts the next turn).\n\t\t\t\ttaskStore.update(task.id, { status: \"done\", usage: result.usage });\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: result.answer || \"(subagent returned no output)\" }],\n\t\t\t\t\tdetails: { mode, ok: true, taskId: task.id },\n\t\t\t\t};\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 mode = args.mode ?? \"explore\";\n\t\t\tconst preview = summarize(args.task ?? \"\");\n\t\t\tconst text =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"subagent \")) +\n\t\t\t\ttheme.fg(\"accent\", `[${mode}]`) +\n\t\t\t\ttheme.fg(\"dim\", ` ${preview}`);\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n"]}
|
|
@@ -16,6 +16,7 @@ Available subagent modes:
|
|
|
16
16
|
- test: run tests and report (read, bash, grep, find, ls).
|
|
17
17
|
- fix: diagnose and fix a failure (read, edit, write, bash, grep, find, ls).
|
|
18
18
|
- review: read-only code review (read, grep, find, ls, bash).
|
|
19
|
+
- doc: write documentation, README, or comments (read, write, edit, grep, find, ls, bash).
|
|
19
20
|
|
|
20
21
|
When to delegate:
|
|
21
22
|
1. The work is self-contained and you only need the final result, not intermediate steps.
|
|
@@ -28,9 +29,15 @@ Guidelines:
|
|
|
28
29
|
- Pass all necessary context (files, constraints, prior findings) via the \`context\` parameter.
|
|
29
30
|
- Do NOT delegate tasks that require tight back-and-forth with your current reasoning.
|
|
30
31
|
- Do NOT delegate edits to files you are actively reasoning about.
|
|
31
|
-
- The subagent returns ONLY its final answer. Intermediate reasoning, tool calls, and output are hidden from you
|
|
32
|
+
- The subagent returns ONLY its final answer. Intermediate reasoning, tool calls, and output are hidden from you.
|
|
33
|
+
|
|
34
|
+
Dispatch evaluator:
|
|
35
|
+
- The dispatch evaluator determines if a subagent is needed. Do not spawn subagents directly unless the user explicitly requests it.
|
|
36
|
+
- For simple single-file changes (<50 lines, read-only or trivial edit), handle them inline.
|
|
37
|
+
- Use force=true to bypass evaluation when you are certain a subagent is required.`;
|
|
32
38
|
import { Text } from "@kolisachint/hoocode-tui";
|
|
33
39
|
import { Type } from "typebox";
|
|
40
|
+
import { DispatchEvaluator } from "../dispatch-evaluator.js";
|
|
34
41
|
import { defineTool } from "../extensions/types.js";
|
|
35
42
|
import { runSubagent } from "../subagent.js";
|
|
36
43
|
import { taskStore } from "../task-store.js";
|
|
@@ -47,14 +54,38 @@ const subagentParams = Type.Object({
|
|
|
47
54
|
Type.Literal("test"),
|
|
48
55
|
Type.Literal("fix"),
|
|
49
56
|
Type.Literal("review"),
|
|
57
|
+
Type.Literal("doc"),
|
|
50
58
|
], {
|
|
51
|
-
description: "explore: read-only investigation. edit: make a focused code change. test: run tests and report. fix: diagnose and fix a failure. review: read-only code review.",
|
|
59
|
+
description: "explore: read-only investigation. edit: make a focused code change. test: run tests and report. fix: diagnose and fix a failure. review: read-only code review. doc: write documentation.",
|
|
60
|
+
}),
|
|
61
|
+
force: Type.Boolean({
|
|
62
|
+
description: "Bypass dispatch evaluation and spawn the subagent directly. Use when you are certain a subagent is required.",
|
|
63
|
+
default: false,
|
|
52
64
|
}),
|
|
53
65
|
});
|
|
54
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* A short, human-readable task name for the task panel: the first line of the
|
|
68
|
+
* task limited to ~4–8 words so it stays glanceable in the pane. A character cap
|
|
69
|
+
* guards against a single very long word.
|
|
70
|
+
*/
|
|
55
71
|
function summarize(task) {
|
|
56
|
-
const firstLine = task.trim().split("\n")[0] ?? "";
|
|
57
|
-
|
|
72
|
+
const firstLine = (task.trim().split("\n")[0] ?? "").trim();
|
|
73
|
+
if (!firstLine)
|
|
74
|
+
return "(task)";
|
|
75
|
+
const words = firstLine.split(/\s+/);
|
|
76
|
+
let name = words.length > 8 ? `${words.slice(0, 8).join(" ")}…` : firstLine;
|
|
77
|
+
if (name.length > 60)
|
|
78
|
+
name = `${name.slice(0, 59)}…`;
|
|
79
|
+
return name;
|
|
80
|
+
}
|
|
81
|
+
/** Quick check: should this task go to a subagent? */
|
|
82
|
+
export function isSubagentRecommended(task) {
|
|
83
|
+
const evaluator = new DispatchEvaluator();
|
|
84
|
+
return evaluator.evaluate(task).should_delegate;
|
|
85
|
+
}
|
|
86
|
+
/** Map evaluator AgentType to SubagentMode (they are compatible strings). */
|
|
87
|
+
function toSubagentMode(agentType) {
|
|
88
|
+
return agentType ?? "explore";
|
|
58
89
|
}
|
|
59
90
|
/** Create the subagent tool definition. Registered as a customTool when enabled. */
|
|
60
91
|
export function createSubagentToolDefinition() {
|
|
@@ -64,17 +95,37 @@ export function createSubagentToolDefinition() {
|
|
|
64
95
|
description: [
|
|
65
96
|
"Delegate a focused task to a subagent that runs in a fresh, isolated context (it cannot see this conversation).",
|
|
66
97
|
"Pass everything it needs via `context`. The subagent returns only its final answer.",
|
|
67
|
-
"Modes: explore, edit, test, fix, review.",
|
|
98
|
+
"Modes: explore, edit, test, fix, review, doc.",
|
|
68
99
|
"WHEN TO USE: (1) The work is self-contained and you do not need to see intermediate steps — only the final result.",
|
|
69
100
|
"(2) You want to investigate or edit something in parallel without losing your current context or reasoning chain.",
|
|
70
|
-
"(3) The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug).",
|
|
101
|
+
"(3) The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug, write docs).",
|
|
71
102
|
"(4) You need to run a long command or test suite and wait for its output without blocking your own reasoning.",
|
|
72
103
|
"Do NOT use for tasks that require tight back-and-forth with your current reasoning or that change files you are actively reasoning about.",
|
|
104
|
+
"Use force=true to bypass dispatch evaluation when you are certain a subagent is required.",
|
|
73
105
|
].join(" "),
|
|
74
|
-
promptSnippet: "delegate a self-contained task to an isolated subagent (modes: explore/edit/test/fix/review)",
|
|
106
|
+
promptSnippet: "delegate a self-contained task to an isolated subagent (modes: explore/edit/test/fix/review/doc)",
|
|
75
107
|
parameters: subagentParams,
|
|
76
108
|
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
77
|
-
const
|
|
109
|
+
const forcedMode = params.mode;
|
|
110
|
+
// Dispatch evaluation
|
|
111
|
+
if (!params.force) {
|
|
112
|
+
const evaluator = new DispatchEvaluator();
|
|
113
|
+
const analysis = evaluator.evaluate(params.task);
|
|
114
|
+
if (!analysis.should_delegate) {
|
|
115
|
+
return {
|
|
116
|
+
content: [
|
|
117
|
+
{
|
|
118
|
+
type: "text",
|
|
119
|
+
text: `Task is simple enough for inline handling. Reason: ${analysis.reason}. Use force=true for subagent override.`,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
details: { mode: forcedMode, ok: true, taskId: 0, inline: true },
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const mode = params.force
|
|
127
|
+
? forcedMode
|
|
128
|
+
: toSubagentMode(new DispatchEvaluator().evaluate(params.task).agent_type);
|
|
78
129
|
const summary = summarize(params.task);
|
|
79
130
|
const task = taskStore.create(summary, { subagentMode: mode });
|
|
80
131
|
taskStore.update(task.id, { status: "in_progress" });
|
|
@@ -91,13 +142,13 @@ export function createSubagentToolDefinition() {
|
|
|
91
142
|
if (!result.ok) {
|
|
92
143
|
// Signal failure by throwing: the agent loop derives a tool's error
|
|
93
144
|
// state from a thrown error, not from a returned flag.
|
|
94
|
-
taskStore.update(task.id, { status: "failed" });
|
|
145
|
+
taskStore.update(task.id, { status: "failed", usage: result.usage });
|
|
95
146
|
throw new Error(`Subagent (${mode}) failed: ${result.error ?? "unknown error"}`);
|
|
96
147
|
}
|
|
97
148
|
// Leave the task in the store with its final status. It stays visible in
|
|
98
|
-
// the task panel until the
|
|
99
|
-
// when the
|
|
100
|
-
taskStore.update(task.id, { status: "done" });
|
|
149
|
+
// the task panel until the next user message arrives (retireFinished is
|
|
150
|
+
// called when the user starts the next turn).
|
|
151
|
+
taskStore.update(task.id, { status: "done", usage: result.usage });
|
|
101
152
|
return {
|
|
102
153
|
content: [{ type: "text", text: result.answer || "(subagent returned no output)" }],
|
|
103
154
|
details: { mode, ok: true, taskId: task.id },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent.js","sourceRoot":"","sources":["../../../src/core/tools/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;0EAC0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;kHAoB8E,CAAC;AAEnH,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAqB,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,WAAW,EACV,uGAAuG;KACxG,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;QACpB,WAAW,EACV,mHAAmH;KACpH,CAAC;IACF,IAAI,EAAE,IAAI,CAAC,KAAK,CACf;QACC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,OA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AM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC;YACpC,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YAC3C,MAAM,IAAI,GACT,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC9C,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,CAAC;gBAC/B,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC;YAChC,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAAA,CAC5B;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * Subagent tool: delegate a focused task to a fresh, isolated agent loop.\n *\n * The tool registers a task in the shared task store (visible in the task panel),\n * runs the subagent to completion, and returns ONLY the subagent's final\n * answer. It is an optional, opt-in tool (enabled via --subagent or the\n * `enableSubagent` setting); see buildSessionOptions in main.ts.\n */\n\n/** System prompt appendix for the main session when subagent tooling is enabled.\n * Instructs the parent agent on when and how to delegate effectively. */\nexport const SUBAGENT_MAIN_PROMPT = `You have access to the **subagent** tool. Use it to delegate self-contained tasks to isolated subagent loops that run with their own context and return only their final answer.\n\nAvailable subagent modes:\n- explore: read-only investigation (read, grep, find, ls, bash).\n- edit: make a focused code change (read, edit, write, grep, find, ls, bash).\n- test: run tests and report (read, bash, grep, find, ls).\n- fix: diagnose and fix a failure (read, edit, write, bash, grep, find, ls).\n- review: read-only code review (read, grep, find, ls, bash).\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- Make every task specific and self-contained. The subagent cannot see this conversation.\n- Pass all necessary context (files, constraints, prior findings) via the \\`context\\` parameter.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning.\n- Do NOT delegate edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Intermediate reasoning, tool calls, and output are hidden from you.`;\n\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type Static, Type } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { defineTool } from \"../extensions/types.js\";\nimport { runSubagent, type SubagentMode } from \"../subagent.js\";\nimport { taskStore } from \"../task-store.js\";\n\nconst subagentParams = Type.Object({\n\ttask: Type.String({\n\t\tdescription:\n\t\t\t\"The task to delegate. Make it specific and self-contained; the subagent cannot see this conversation.\",\n\t}),\n\tcontext: Type.String({\n\t\tdescription:\n\t\t\t'Context distilled from the conversation the subagent needs (files, constraints, prior findings). Pass \"\" if none.',\n\t}),\n\tmode: Type.Union(\n\t\t[\n\t\t\tType.Literal(\"explore\"),\n\t\t\tType.Literal(\"edit\"),\n\t\t\tType.Literal(\"test\"),\n\t\t\tType.Literal(\"fix\"),\n\t\t\tType.Literal(\"review\"),\n\t\t],\n\t\t{\n\t\t\tdescription:\n\t\t\t\t\"explore: read-only investigation. edit: make a focused code change. test: run tests and report. fix: diagnose and fix a failure. review: read-only code review.\",\n\t\t},\n\t),\n});\n\ntype SubagentParams = Static<typeof subagentParams>;\n\nexport interface SubagentToolDetails {\n\tmode: SubagentMode;\n\tok: boolean;\n\terror?: string;\n\ttaskId: number;\n}\n\n/** First line of the task, trimmed to a short summary for the task list/footer. */\nfunction summarize(task: string): string {\n\tconst firstLine = task.trim().split(\"\\n\")[0] ?? \"\";\n\treturn firstLine.length > 60 ? `${firstLine.slice(0, 57)}...` : firstLine || \"(task)\";\n}\n\n/** Create the subagent tool definition. Registered as a customTool when enabled. */\nexport function createSubagentToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof subagentParams, SubagentToolDetails>({\n\t\tname: \"subagent\",\n\t\tlabel: \"Subagent\",\n\t\tdescription: [\n\t\t\t\"Delegate a focused task to a subagent that runs in a fresh, isolated context (it cannot see this conversation).\",\n\t\t\t\"Pass everything it needs via `context`. The subagent returns only its final answer.\",\n\t\t\t\"Modes: explore, edit, test, fix, review.\",\n\t\t\t\"WHEN TO USE: (1) The work is self-contained and you do not need to see intermediate steps — only the final result.\",\n\t\t\t\"(2) You want to investigate or edit something in parallel without losing your current context or reasoning chain.\",\n\t\t\t\"(3) The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug).\",\n\t\t\t\"(4) You need to run a long command or test suite and wait for its output without blocking your own reasoning.\",\n\t\t\t\"Do NOT use for tasks that require tight back-and-forth with your current reasoning or that change files you are actively reasoning about.\",\n\t\t].join(\" \"),\n\t\tpromptSnippet: \"delegate a self-contained task to an isolated subagent (modes: explore/edit/test/fix/review)\",\n\t\tparameters: subagentParams,\n\n\t\tasync execute(_toolCallId, params: SubagentParams, signal, _onUpdate, ctx) {\n\t\t\tconst mode = params.mode as SubagentMode;\n\t\t\tconst summary = summarize(params.task);\n\n\t\t\tconst task = taskStore.create(summary, { subagentMode: mode });\n\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\ttry {\n\t\t\t\tconst result = await runSubagent({\n\t\t\t\t\ttask: params.task,\n\t\t\t\t\tcontext: params.context,\n\t\t\t\t\tmode,\n\t\t\t\t\tcwd: ctx.cwd,\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\tsignal: signal ?? ctx.signal,\n\t\t\t\t});\n\n\t\t\t\tif (!result.ok) {\n\t\t\t\t\t// Signal failure by throwing: the agent loop derives a tool's error\n\t\t\t\t\t// state from a thrown error, not from a returned flag.\n\t\t\t\t\ttaskStore.update(task.id, { status: \"failed\" });\n\t\t\t\t\tthrow new Error(`Subagent (${mode}) failed: ${result.error ?? \"unknown error\"}`);\n\t\t\t\t}\n\n\t\t\t\t// Leave the task in the store with its final status. It stays visible in\n\t\t\t\t// the task panel until the main agent moves on (retireFinished is called\n\t\t\t\t// when the main agent starts its next turn).\n\t\t\t\ttaskStore.update(task.id, { status: \"done\" });\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: result.answer || \"(subagent returned no output)\" }],\n\t\t\t\t\tdetails: { mode, ok: true, taskId: task.id },\n\t\t\t\t};\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 mode = args.mode ?? \"explore\";\n\t\t\tconst preview = summarize(args.task ?? \"\");\n\t\t\tconst text =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"subagent \")) +\n\t\t\t\ttheme.fg(\"accent\", `[${mode}]`) +\n\t\t\t\ttheme.fg(\"dim\", ` ${preview}`);\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;;;;;;;GAOG;AAEH;0EAC0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;mFA0B+C,CAAC;AAEpF,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAkB,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7E,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAqB,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,WAAW,EACV,uGAAuG;KACxG,C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A8C;gBAC9C,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;gBACnE,OAAO;oBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,IAAI,+BAA+B,EAAE,CAAC;oBACnF,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;iBAC5C,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAChD,MAAM,KAAK,CAAC;YACb,CAAC;QAAA,CACD;QAED,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE;YACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC;YACpC,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YAC3C,MAAM,IAAI,GACT,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC9C,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,CAAC;gBAC/B,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC;YAChC,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAAA,CAC5B;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * Subagent tool: delegate a focused task to a fresh, isolated agent loop.\n *\n * The tool registers a task in the shared task store (visible in the task panel),\n * runs the subagent to completion, and returns ONLY the subagent's final\n * answer. It is an optional, opt-in tool (enabled via --subagent or the\n * `enableSubagent` setting); see buildSessionOptions in main.ts.\n */\n\n/** System prompt appendix for the main session when subagent tooling is enabled.\n * Instructs the parent agent on when and how to delegate effectively. */\nexport const SUBAGENT_MAIN_PROMPT = `You have access to the **subagent** tool. Use it to delegate self-contained tasks to isolated subagent loops that run with their own context and return only their final answer.\n\nAvailable subagent modes:\n- explore: read-only investigation (read, grep, find, ls, bash).\n- edit: make a focused code change (read, edit, write, grep, find, ls, bash).\n- test: run tests and report (read, bash, grep, find, ls).\n- fix: diagnose and fix a failure (read, edit, write, bash, grep, find, ls).\n- review: read-only code review (read, grep, find, ls, bash).\n- doc: write documentation, README, or comments (read, write, edit, grep, find, ls, bash).\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- Make every task specific and self-contained. The subagent cannot see this conversation.\n- Pass all necessary context (files, constraints, prior findings) via the \\`context\\` parameter.\n- Do NOT delegate tasks that require tight back-and-forth with your current reasoning.\n- Do NOT delegate edits to files you are actively reasoning about.\n- The subagent returns ONLY its final answer. Intermediate reasoning, tool calls, and output are hidden from you.\n\nDispatch evaluator:\n- The dispatch evaluator determines if a subagent is needed. Do not spawn subagents directly unless the user explicitly requests it.\n- For simple single-file changes (<50 lines, read-only or trivial edit), handle them inline.\n- Use force=true to bypass evaluation when you are certain a subagent is required.`;\n\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { type AgentType, DispatchEvaluator } from \"../dispatch-evaluator.js\";\nimport type { ToolDefinition } from \"../extensions/types.js\";\nimport { defineTool } from \"../extensions/types.js\";\nimport { runSubagent, type SubagentMode } from \"../subagent.js\";\nimport { taskStore } from \"../task-store.js\";\n\nconst subagentParams = Type.Object({\n\ttask: Type.String({\n\t\tdescription:\n\t\t\t\"The task to delegate. Make it specific and self-contained; the subagent cannot see this conversation.\",\n\t}),\n\tcontext: Type.String({\n\t\tdescription:\n\t\t\t'Context distilled from the conversation the subagent needs (files, constraints, prior findings). Pass \"\" if none.',\n\t}),\n\tmode: Type.Union(\n\t\t[\n\t\t\tType.Literal(\"explore\"),\n\t\t\tType.Literal(\"edit\"),\n\t\t\tType.Literal(\"test\"),\n\t\t\tType.Literal(\"fix\"),\n\t\t\tType.Literal(\"review\"),\n\t\t\tType.Literal(\"doc\"),\n\t\t],\n\t\t{\n\t\t\tdescription:\n\t\t\t\t\"explore: read-only investigation. edit: make a focused code change. test: run tests and report. fix: diagnose and fix a failure. review: read-only code review. doc: write documentation.\",\n\t\t},\n\t),\n\tforce: Type.Boolean({\n\t\tdescription:\n\t\t\t\"Bypass dispatch evaluation and spawn the subagent directly. Use when you are certain a subagent is required.\",\n\t\tdefault: false,\n\t}),\n});\n\ntype SubagentParams = Static<typeof subagentParams>;\n\nexport interface SubagentToolDetails {\n\tmode: SubagentMode;\n\tok: boolean;\n\terror?: string;\n\ttaskId: number;\n\t/** True when the evaluator handled the task inline instead of delegating. */\n\tinline?: boolean;\n}\n\n/**\n * A short, human-readable task name for the task panel: the first line of the\n * task limited to ~4–8 words so it stays glanceable in the pane. A character cap\n * guards against a single very 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 check: should this task go to a subagent? */\nexport function isSubagentRecommended(task: string): boolean {\n\tconst evaluator = new DispatchEvaluator();\n\treturn evaluator.evaluate(task).should_delegate;\n}\n\n/** Map evaluator AgentType to SubagentMode (they are compatible strings). */\nfunction toSubagentMode(agentType: AgentType | null): SubagentMode {\n\treturn (agentType as SubagentMode) ?? \"explore\";\n}\n\n/** Create the subagent tool definition. Registered as a customTool when enabled. */\nexport function createSubagentToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof subagentParams, SubagentToolDetails>({\n\t\tname: \"subagent\",\n\t\tlabel: \"Subagent\",\n\t\tdescription: [\n\t\t\t\"Delegate a focused task to a subagent that runs in a fresh, isolated context (it cannot see this conversation).\",\n\t\t\t\"Pass everything it needs via `context`. The subagent returns only its final answer.\",\n\t\t\t\"Modes: explore, edit, test, fix, review, doc.\",\n\t\t\t\"WHEN TO USE: (1) The work is self-contained and you do not need to see intermediate steps — only the final result.\",\n\t\t\t\"(2) You want to investigate or edit something in parallel without losing your current context or reasoning chain.\",\n\t\t\t\"(3) The task is a discrete unit (explore one module, run one test file, review one PR, fix one isolated bug, write docs).\",\n\t\t\t\"(4) You need to run a long command or test suite and wait for its output without blocking your own reasoning.\",\n\t\t\t\"Do NOT use for tasks that require tight back-and-forth with your current reasoning or that change files you are actively reasoning about.\",\n\t\t\t\"Use force=true to bypass dispatch evaluation when you are certain a subagent is required.\",\n\t\t].join(\" \"),\n\t\tpromptSnippet: \"delegate a self-contained task to an isolated subagent (modes: explore/edit/test/fix/review/doc)\",\n\t\tparameters: subagentParams,\n\n\t\tasync execute(_toolCallId, params: SubagentParams, signal, _onUpdate, ctx) {\n\t\t\tconst forcedMode = params.mode as SubagentMode;\n\n\t\t\t// Dispatch evaluation\n\t\t\tif (!params.force) {\n\t\t\t\tconst evaluator = new DispatchEvaluator();\n\t\t\t\tconst analysis = evaluator.evaluate(params.task);\n\t\t\t\tif (!analysis.should_delegate) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: `Task is simple enough for inline handling. Reason: ${analysis.reason}. Use force=true for subagent override.`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: { mode: forcedMode, ok: true, taskId: 0, inline: true },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst mode = params.force\n\t\t\t\t? forcedMode\n\t\t\t\t: toSubagentMode(new DispatchEvaluator().evaluate(params.task).agent_type);\n\t\t\tconst summary = summarize(params.task);\n\n\t\t\tconst task = taskStore.create(summary, { subagentMode: mode });\n\t\t\ttaskStore.update(task.id, { status: \"in_progress\" });\n\t\t\ttry {\n\t\t\t\tconst result = await runSubagent({\n\t\t\t\t\ttask: params.task,\n\t\t\t\t\tcontext: params.context,\n\t\t\t\t\tmode,\n\t\t\t\t\tcwd: ctx.cwd,\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\tsignal: signal ?? ctx.signal,\n\t\t\t\t});\n\n\t\t\t\tif (!result.ok) {\n\t\t\t\t\t// Signal failure by throwing: the agent loop derives a tool's error\n\t\t\t\t\t// state from a thrown error, not from a returned flag.\n\t\t\t\t\ttaskStore.update(task.id, { status: \"failed\", usage: result.usage });\n\t\t\t\t\tthrow new Error(`Subagent (${mode}) failed: ${result.error ?? \"unknown error\"}`);\n\t\t\t\t}\n\n\t\t\t\t// Leave the task in the store with its final status. It stays visible in\n\t\t\t\t// the task panel until the next user message arrives (retireFinished is\n\t\t\t\t// called when the user starts the next turn).\n\t\t\t\ttaskStore.update(task.id, { status: \"done\", usage: result.usage });\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: result.answer || \"(subagent returned no output)\" }],\n\t\t\t\t\tdetails: { mode, ok: true, taskId: task.id },\n\t\t\t\t};\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 mode = args.mode ?? \"explore\";\n\t\t\tconst preview = summarize(args.task ?? \"\");\n\t\t\tconst text =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"subagent \")) +\n\t\t\t\ttheme.fg(\"accent\", `[${mode}]`) +\n\t\t\t\ttheme.fg(\"dim\", ` ${preview}`);\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t});\n}\n"]}
|
|
@@ -2,4 +2,5 @@ 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
4
|
export declare const EMBEDDED_SUBAGENT_PROMPTS: Record<string, string>;
|
|
5
|
+
export declare const EMBEDDED_AGENT_PROMPTS: Record<string, string>;
|
|
5
6
|
//# sourceMappingURL=init-templates.generated.d.ts.map
|