iosm-cli 0.2.16 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +10 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +3 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +26 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings.schema.json +92 -0
- package/dist/core/subagents.d.ts.map +1 -1
- package/dist/core/subagents.js +4 -0
- package/dist/core/subagents.js.map +1 -1
- package/dist/core/tools/task.d.ts.map +1 -1
- package/dist/core/tools/task.js +48 -26
- package/dist/core/tools/task.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +7 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +77 -5
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +7 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +95 -10
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +2 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +49 -32
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/message-frame-border.d.ts +22 -0
- package/dist/modes/interactive/components/message-frame-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/message-frame-border.js +51 -0
- package/dist/modes/interactive/components/message-frame-border.js.map +1 -0
- package/dist/modes/interactive/components/message-window.d.ts +25 -0
- package/dist/modes/interactive/components/message-window.d.ts.map +1 -0
- package/dist/modes/interactive/components/message-window.js +66 -0
- package/dist/modes/interactive/components/message-window.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +12 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/subagent-message.d.ts +12 -9
- package/dist/modes/interactive/components/subagent-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/subagent-message.js +138 -136
- package/dist/modes/interactive/components/subagent-message.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +2 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +33 -28
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +10 -3
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +11 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +509 -155
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagents.d.ts","sourceRoot":"","sources":["../../src/core/subagents.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsC,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEhG,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,WAAW,wBAAwB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MA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C7C,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,GAC1E,MAAM,GAAG,SAAS,CAuCpB;AAgJD,MAAM,WAAW,0BAA0B;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,yBAAyB,CA+FlG"}
|
package/dist/core/subagents.js
CHANGED
|
@@ -192,6 +192,9 @@ const BUILTIN_SUBAGENTS = [
|
|
|
192
192
|
"- Decide number of delegates based on task complexity (usually 1-10), and prefer higher fan-out when the work naturally splits.",
|
|
193
193
|
"- For medium/complex work, target aggressive safe parallel fan-out (commonly >=3 delegates) when independent slices exist.",
|
|
194
194
|
"- If the user asked for N parallel agents, match that fan-out when feasible or explain the exact blocker.",
|
|
195
|
+
"- Delegates are child task calls only; do not count plain tool invocations (read/bash/grep/etc.) as delegated agents.",
|
|
196
|
+
"- Assign explicit ownership domains per delegate before execution to reduce duplicate findings and overlap.",
|
|
197
|
+
"- If overlap is unavoidable, declare a primary owner and a secondary verifier for that overlap zone.",
|
|
195
198
|
"- If a delegate owns a task that still contains multiple independent slices, that delegate should split again with nested delegates instead of executing everything alone.",
|
|
196
199
|
"- Run independent read-heavy work in parallel by emitting multiple delegate blocks.",
|
|
197
200
|
"- For write-capable delegates touching overlapping areas, provide lock_key to avoid edit collisions.",
|
|
@@ -218,6 +221,7 @@ const BUILTIN_SUBAGENTS = [
|
|
|
218
221
|
"- concise execution summary",
|
|
219
222
|
"- delegated work breakdown",
|
|
220
223
|
"- verification status",
|
|
224
|
+
"- observed-vs-estimated metrics (mark unknown when evidence is missing)",
|
|
221
225
|
"- residual risks/assumptions",
|
|
222
226
|
].join("\n"),
|
|
223
227
|
},
|
|
@@ -1 +1 @@
|
|
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AM,KAAK,GAAwB;gBAClC,GAAG,MAAM,CAAC,KAAK;gBACf,WAAW,EAAE,IAAI,CAAC,KAAK;gBACvB,cAAc,EAAE,IAAI,CAAC,QAAQ;gBAC7B,SAAS,EAAE,KAAK;aAChB,CAAC;YACF,aAAa,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACF,CAAC;IAED,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACtG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxD,IAAI,WAAW,KAAK,CAAC;YAAE,OAAO,WAAW,CAAC;QAC1C,OAAO,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;IACnD,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AACtD,CAAC","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { basename, join, resolve } from \"node:path\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport { AGENT_PROFILES, isValidProfileName, type AgentProfileName } from \"./agent-profiles.js\";\n\nexport type CustomSubagentSourceScope = \"builtin\" | \"global\" | \"project\";\n\nexport interface CustomSubagentDefinition {\n\tname: string;\n\tdescription: string;\n\tsourcePath: string;\n\tprofile?: AgentProfileName;\n\ttools?: string[];\n\tdisallowedTools?: string[];\n\tsystemPrompt?: string;\n\tinstructions: string;\n\tcwd?: string;\n\tmodel?: string;\n\tbackground?: boolean;\n}\n\nexport interface CustomSubagentEntry extends CustomSubagentDefinition {\n\tsourceScope: CustomSubagentSourceScope;\n\tsourcePriority: number;\n\teffective: boolean;\n\toverriddenByPath?: string;\n}\n\nexport interface SubagentOverrideInfo {\n\tname: string;\n\twinnerPath: string;\n\twinnerScope: CustomSubagentSourceScope;\n\toverriddenPath: string;\n\toverriddenScope: CustomSubagentSourceScope;\n}\n\nexport interface SubagentDiagnostic {\n\tpath: string;\n\tmessage: string;\n}\n\nexport interface LoadCustomSubagentsResult {\n\tagents: CustomSubagentEntry[];\n\tallAgents: CustomSubagentEntry[];\n\toverrides: SubagentOverrideInfo[];\n\tdiagnostics: SubagentDiagnostic[];\n}\n\nconst BUILTIN_SUBAGENT_PRIORITY = -1;\n\nconst BUILTIN_SUBAGENTS: CustomSubagentDefinition[] = [\n\t{\n\t\tname: \"codebase_auditor\",\n\t\tdescription: \"Structured codebase audit for architecture, reliability, security, and test gaps.\",\n\t\tsourcePath: \"builtin://codebase_auditor.md\",\n\t\tprofile: \"explore\",\n\t\tinstructions: [\n\t\t\t\"You are a codebase auditor.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Produce an evidence-based audit of architecture, defect risks, and maintainability hotspots.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Read-only operation. Never edit files.\",\n\t\t\t\"- Make claims only with direct repository evidence.\",\n\t\t\t\"- Prioritize by user impact and likelihood (P0..P3).\",\n\t\t\t\"- If the assigned audit still spans multiple independent subsystems and delegation protocol is available, split it with nested delegates instead of producing one monolithic audit.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Findings (ordered by severity)\",\n\t\t\t\"2) Open questions/unknowns\",\n\t\t\t\"3) Recommended next actions\",\n\t\t\t\"\",\n\t\t\t\"For each finding include:\",\n\t\t\t\"- file path + line reference (when available)\",\n\t\t\t\"- risk/impact\",\n\t\t\t\"- concrete fix direction\",\n\t\t\t\"\",\n\t\t\t\"If no issues are found, explicitly state 'No findings' and list residual risks/testing gaps.\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"system_error_analyst\",\n\t\tdescription: \"Diagnoses system/runtime failures and produces root-cause + fix plan.\",\n\t\tsourcePath: \"builtin://system_error_analyst.md\",\n\t\tprofile: \"plan\",\n\t\tinstructions: [\n\t\t\t\"You are a system error analyst.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Triage failures, identify probable root cause, and propose a minimal, testable fix plan.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Do not modify files.\",\n\t\t\t\"- Use deterministic evidence (logs, stack traces, tests, configs).\",\n\t\t\t\"- Distinguish facts vs hypotheses explicitly.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Incident summary\",\n\t\t\t\"2) Root-cause analysis (ranked hypotheses with evidence)\",\n\t\t\t\"3) Minimal patch plan\",\n\t\t\t\"4) Verification plan (commands + expected signals)\",\n\t\t\t\"5) Regression risks\",\n\t\t\t\"\",\n\t\t\t\"Escalation guidance:\",\n\t\t\t\"- If data is insufficient, request the minimum missing evidence instead of guessing.\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"iosm_change_executor\",\n\t\tdescription: \"Implements repository changes under IOSM methodology and keeps artifacts aligned.\",\n\t\tsourcePath: \"builtin://iosm_change_executor.md\",\n\t\tprofile: \"iosm\",\n\t\tinstructions: [\n\t\t\t\"You are an IOSM change executor.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Analyze, implement, and verify changes while preserving IOSM methodology and artifact consistency.\",\n\t\t\t\"\",\n\t\t\t\"Execution policy:\",\n\t\t\t\"- Inspect relevant code and .iosm artifacts before edits.\",\n\t\t\t\"- Make minimal, targeted changes with clear rationale.\",\n\t\t\t\"- Run focused verification after each meaningful change.\",\n\t\t\t\"- Keep IOSM artifacts in sync when behavior/metrics assumptions change.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) What changed and why\",\n\t\t\t\"2) Files changed\",\n\t\t\t\"3) Verification executed and results\",\n\t\t\t\"4) Remaining risks/assumptions\",\n\t\t\t\"\",\n\t\t\t\"Safety rules:\",\n\t\t\t\"- Do not introduce speculative changes.\",\n\t\t\t\"- If requirements are ambiguous, ask a concise clarification before risky edits.\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"iosm_postchange_verifier\",\n\t\tdescription: \"Post-change IOSM verifier for metric/artifact integrity and regression checks.\",\n\t\tsourcePath: \"builtin://iosm_postchange_verifier.md\",\n\t\tprofile: \"iosm_verifier\",\n\t\tinstructions: [\n\t\t\t\"You are an IOSM post-change verifier.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Validate that implemented changes are correctly reflected in IOSM metrics/artifacts.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Restrict edits to .iosm artifacts unless explicitly instructed otherwise.\",\n\t\t\t\"- Prefer deterministic checks and reproducible commands.\",\n\t\t\t\"- Report mismatches and exact remediation steps.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Checks performed\",\n\t\t\t\"2) Pass/fail per check\",\n\t\t\t\"3) Artifact updates applied (if any)\",\n\t\t\t\"4) Remaining discrepancies and follow-ups\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"qa_test_engineer\",\n\t\tdescription: \"Writes tests, runs verification, and fixes regressions with evidence-driven workflow.\",\n\t\tsourcePath: \"builtin://qa_test_engineer.md\",\n\t\tprofile: \"full\",\n\t\tinstructions: [\n\t\t\t\"You are a QA test engineer and regression fixer.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Increase confidence by adding/updating tests, reproducing failures, and fixing root causes.\",\n\t\t\t\"\",\n\t\t\t\"Workflow:\",\n\t\t\t\"1) Reproduce failure (or define expected behavior if bug is not reproducible yet).\",\n\t\t\t\"2) Add/update focused tests that capture expected behavior.\",\n\t\t\t\"3) Run targeted tests first, then broader suite if needed.\",\n\t\t\t\"4) Implement minimal fix in production code.\",\n\t\t\t\"5) Re-run tests and report outcomes.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Never hide failures by removing assertions or disabling tests unless explicitly requested.\",\n\t\t\t\"- Prefer deterministic tests; avoid flaky timing assumptions.\",\n\t\t\t\"- Keep patch size minimal and localized.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Root cause summary\",\n\t\t\t\"2) Tests added/updated\",\n\t\t\t\"3) Code fixes applied\",\n\t\t\t\"4) Commands executed + pass/fail results\",\n\t\t\t\"5) Residual risk\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"test_failure_triager\",\n\t\tdescription: \"Analyzes failing/flaky tests and proposes a ranked remediation plan.\",\n\t\tsourcePath: \"builtin://test_failure_triager.md\",\n\t\tprofile: \"plan\",\n\t\tinstructions: [\n\t\t\t\"You are a test-failure triage specialist.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Analyze failures quickly and produce a ranked, actionable remediation plan.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Read/analyze only; do not edit files.\",\n\t\t\t\"- Separate infra/environment issues from product-code defects.\",\n\t\t\t\"- Label confidence for each hypothesis.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Failure classification (deterministic, flaky, environment, unknown)\",\n\t\t\t\"2) Ranked hypotheses with evidence\",\n\t\t\t\"3) Minimal next steps to verify each hypothesis\",\n\t\t\t\"4) Recommended owner/agent to execute fixes\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"meta_orchestrator\",\n\t\tdescription: \"Autonomous orchestration lead: audits, plans, and delegates parallel specialists safely.\",\n\t\tsourcePath: \"builtin://meta_orchestrator.md\",\n\t\tprofile: \"meta\",\n\t\t\tinstructions: [\n\t\t\t\t\"You are the main orchestration agent for complex engineering tasks.\",\n\t\t\t\t\"\",\n\t\t\t\t\"Goal:\",\n\t\t\t\t\"- Drive tasks end-to-end with dynamic delegation: audit -> plan -> execution -> verification.\",\n\t\t\t\t\"- Act as the lead orchestrator, not as a substitute for the parent session runtime.\",\n\t\t\t\t\"\",\n\t\t\t\t\"Required operating phases:\",\n\t\t\t\t\"1) Recon: do bounded read-only inspection to identify repository context, constraints, and relevant files.\",\n\t\t\t\t\"2) Plan: split work into an explicit execution graph of tasks/delegates, including dependencies and lock domains where needed.\",\n\t\t\t\t\"3) Execute adaptively: trivial tasks may stay single-agent; medium/complex tasks should maximize safe parallelism via <delegate_task> and multiple focused workstreams.\",\n\t\t\t\t\"4) Verify: for any code or test changes, add/update tests and run targeted verification before closure.\",\n\t\t\t\t\"5) Synthesize: provide integrated results, unresolved risks, and next actions only after all launched delegates are resolved.\",\n\t\t\t\t\"\",\n\t\t\t\t\"Delegation policy:\",\n\t\t\t\t\"- Main emphasis in META orchestration is parallelism: use as many focused agents and delegates as the task can support safely, rather than defaulting to one broad worker.\",\n\t\t\t\t\"- Recon is only preparation; once you can name the workstreams, stop exploring and delegate.\",\n\t\t\t\t\"- For non-trivial work, assume multi-agent parallel fan-out is required unless you can justify why it is not useful.\",\n\t\t\t\t\"- Decide number of delegates based on task complexity (usually 1-10), and prefer higher fan-out when the work naturally splits.\",\n\t\t\t\t\"- For medium/complex work, target aggressive safe parallel fan-out (commonly >=3 delegates) when independent slices exist.\",\n\t\t\t\t\"- If the user asked for N parallel agents, match that fan-out when feasible or explain the exact blocker.\",\n\t\t\t\t\"- If a delegate owns a task that still contains multiple independent slices, that delegate should split again with nested delegates instead of executing everything alone.\",\n\t\t\t\t\"- Run independent read-heavy work in parallel by emitting multiple delegate blocks.\",\n\t\t\t\t\"- For write-capable delegates touching overlapping areas, provide lock_key to avoid edit collisions.\",\n\t\t\t\t\"- Use depends_on to enforce ordering for dependent steps (for example verification after implementation).\",\n\t\t\t\t\"- Use clear description values and focused prompts per delegate.\",\n\t\t\t\t\"- Do not keep doing direct implementation in the orchestrator after recon for non-trivial work; delegate first.\",\n\t\t\t\t\"- Do not collapse the whole implementation into one specialist delegate when multiple independent workstreams exist.\",\n\t\t\t\t\"- If you keep any non-trivial work single-agent or undelegated, include one line: DELEGATION_IMPOSSIBLE: <reason>.\",\n\t\t\t\"\",\n\t\t\t\"Suggested specialist mapping:\",\n\t\t\t\"- architecture/recon -> profile=explore or plan\",\n\t\t\t\"- implementation -> profile=meta or full or iosm\",\n\t\t\t\"- iosm artifact validation -> profile=iosm_verifier\",\n\t\t\t\"- test creation/fixes -> profile=full (or qa_test_engineer when referenced)\",\n\t\t\t\"\",\n\t\t\t\"Safety rules:\",\n\t\t\t\"- Avoid broad overlapping writes without lock separation.\",\n\t\t\t\"- If requirements are ambiguous and risky, ask for minimal clarification before destructive changes.\",\n\t\t\t\"- Keep all delegated prompts concrete and scoped to specific files/behaviors.\",\n\t\t\t\"- Do not claim completion while any launched delegate remains pending/running.\",\n\t\t\t\"- If no code changed and tests were skipped, include an explicit safety justification.\",\n\t\t\t\"\",\n\t\t\t\"Output requirements:\",\n\t\t\t\"- concise execution summary\",\n\t\t\t\"- delegated work breakdown\",\n\t\t\t\"- verification status\",\n\t\t\t\"- residual risks/assumptions\",\n\t\t].join(\"\\n\"),\n\t},\n];\n\nconst EXTRA_KNOWN_TOOLS = [\"task\", \"todo_write\", \"todo_read\", \"ask_user\", \"git_read\"];\n\nexport function normalizeToolName(value: string): string {\n\treturn value.trim().toLowerCase().replace(/-/g, \"_\");\n}\n\nexport function getDefaultKnownToolNames(): string[] {\n\tconst fromProfiles = Object.values(AGENT_PROFILES).flatMap((profile) => profile.tools);\n\treturn Array.from(\n\t\tnew Set([...fromProfiles, ...EXTRA_KNOWN_TOOLS].map((name) => normalizeToolName(name)).filter(Boolean)),\n\t).sort((left, right) => left.localeCompare(right));\n}\n\nexport function normalizeAndFilterToolNames(\n\tvalues: readonly string[] | undefined,\n\tknownToolNames?: ReadonlySet<string>,\n): { normalized: string[]; unknown: string[] } {\n\tif (!values || values.length === 0) {\n\t\treturn { normalized: [], unknown: [] };\n\t}\n\n\tconst seen = new Set<string>();\n\tconst normalized: string[] = [];\n\tconst unknown: string[] = [];\n\tfor (const value of values) {\n\t\tconst next = normalizeToolName(value);\n\t\tif (!next || seen.has(next)) continue;\n\t\tseen.add(next);\n\t\tif (knownToolNames && knownToolNames.size > 0 && !knownToolNames.has(next)) {\n\t\t\tunknown.push(next);\n\t\t\tcontinue;\n\t\t}\n\t\tnormalized.push(next);\n\t}\n\treturn { normalized, unknown };\n}\n\nfunction trimWrappingChars(value: string): string {\n\tlet next = value.trim();\n\tnext = next.replace(/^@+/, \"\");\n\tnext = next.replace(/^[`\"'“”‘’]+/, \"\");\n\tnext = next.replace(/[`\"'“”‘’]+$/, \"\");\n\tnext = next.replace(/[),;:!?]+$/, \"\");\n\treturn next.trim();\n}\n\nfunction pushCandidate(set: Set<string>, value: string): void {\n\tconst trimmed = value.trim();\n\tif (!trimmed) return;\n\tset.add(trimmed);\n}\n\nexport function getSubagentLookupCandidates(reference: string): string[] {\n\tconst cleaned = trimWrappingChars(reference);\n\tif (!cleaned) return [];\n\tconst normalized = cleaned.replace(/\\\\/g, \"/\");\n\tconst lowerNormalized = normalized.toLowerCase();\n\tconst candidates = new Set<string>();\n\n\tpushCandidate(candidates, cleaned);\n\tpushCandidate(candidates, cleaned.replace(/\\.md$/i, \"\"));\n\tpushCandidate(candidates, normalized);\n\tpushCandidate(candidates, normalized.replace(/\\.md$/i, \"\"));\n\n\tconst pathMarkers = [\"/.iosm/agents/\", \".iosm/agents/\", \"/agents/\", \"agents/\"];\n\tfor (const marker of pathMarkers) {\n\t\tconst markerIndex = lowerNormalized.lastIndexOf(marker.toLowerCase());\n\t\tif (markerIndex === -1) continue;\n\t\tconst suffix = normalized.slice(markerIndex + marker.length);\n\t\tpushCandidate(candidates, suffix);\n\t\tpushCandidate(candidates, suffix.replace(/\\.md$/i, \"\"));\n\t}\n\n\tconst baseFromNormalized = normalized.split(\"/\").filter(Boolean).pop() ?? \"\";\n\tconst baseFromPath = basename(cleaned);\n\tpushCandidate(candidates, baseFromNormalized);\n\tpushCandidate(candidates, baseFromNormalized.replace(/\\.md$/i, \"\"));\n\tpushCandidate(candidates, baseFromPath);\n\tpushCandidate(candidates, baseFromPath.replace(/\\.md$/i, \"\"));\n\n\treturn Array.from(candidates);\n}\n\nexport function resolveCustomSubagentReference(\n\treference: string,\n\tagents: ReadonlyArray<Pick<CustomSubagentDefinition, \"name\" | \"sourcePath\">>,\n): string | undefined {\n\tif (agents.length === 0) return undefined;\n\tconst byName = new Map<string, string>();\n\tconst byNameLower = new Map<string, string>();\n\tconst bySourceBaseLower = new Map<string, string>();\n\n\tfor (const agent of agents) {\n\t\tbyName.set(agent.name, agent.name);\n\t\tbyNameLower.set(agent.name.toLowerCase(), agent.name);\n\n\t\tconst sourceBase = basename(agent.sourcePath);\n\t\tif (sourceBase) {\n\t\t\tconst sourceBaseLower = sourceBase.toLowerCase();\n\t\t\tif (!bySourceBaseLower.has(sourceBaseLower)) {\n\t\t\t\tbySourceBaseLower.set(sourceBaseLower, agent.name);\n\t\t\t}\n\t\t\tconst sourceBaseNoMdLower = sourceBase.replace(/\\.md$/i, \"\").toLowerCase();\n\t\t\tif (!bySourceBaseLower.has(sourceBaseNoMdLower)) {\n\t\t\t\tbySourceBaseLower.set(sourceBaseNoMdLower, agent.name);\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const candidate of getSubagentLookupCandidates(reference)) {\n\t\tconst exact = byName.get(candidate);\n\t\tif (exact) return exact;\n\n\t\tconst lower = candidate.toLowerCase();\n\t\tconst byLower = byNameLower.get(lower);\n\t\tif (byLower) return byLower;\n\t\tconst withoutMd = lower.replace(/\\.md$/i, \"\");\n\t\tconst byWithoutMd = byNameLower.get(withoutMd);\n\t\tif (byWithoutMd) return byWithoutMd;\n\n\t\tconst byBase = bySourceBaseLower.get(lower) ?? bySourceBaseLower.get(withoutMd);\n\t\tif (byBase) return byBase;\n\t}\n\n\treturn undefined;\n}\n\ntype ParsedFrontmatter = {\n\tname?: unknown;\n\tdescription?: unknown;\n\tprofile?: unknown;\n\ttools?: unknown;\n\tdisallowed_tools?: unknown;\n\tsystem_prompt?: unknown;\n\tcwd?: unknown;\n\tmodel?: unknown;\n\tbackground?: unknown;\n};\n\nfunction readMarkdownFilesRecursive(root: string): string[] {\n\tif (!existsSync(root)) return [];\n\tconst files: string[] = [];\n\tconst walk = (dir: string): void => {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true }).sort((left, right) =>\n\t\t\tleft.name.localeCompare(right.name),\n\t\t);\n\t\tfor (const entry of entries) {\n\t\t\tconst full = join(dir, entry.name);\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\twalk(full);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (entry.isFile() && entry.name.toLowerCase().endsWith(\".md\")) {\n\t\t\t\tfiles.push(full);\n\t\t\t}\n\t\t}\n\t};\n\twalk(root);\n\treturn files;\n}\n\nfunction asStringArray(value: unknown): string[] | undefined {\n\tif (Array.isArray(value)) {\n\t\tconst normalized = value.map((item) => String(item).trim()).filter(Boolean);\n\t\treturn normalized.length > 0 ? normalized : undefined;\n\t}\n\tif (typeof value === \"string\") {\n\t\tconst normalized = value\n\t\t\t.split(\",\")\n\t\t\t.map((item) => item.trim())\n\t\t\t.filter(Boolean);\n\t\treturn normalized.length > 0 ? normalized : undefined;\n\t}\n\treturn undefined;\n}\n\nfunction parseSubagentFile(\n\tfilePath: string,\n\tcwd: string,\n\tknownToolNames: ReadonlySet<string>,\n): { agent?: CustomSubagentDefinition; diagnostics: SubagentDiagnostic[] } {\n\tconst diagnostics: SubagentDiagnostic[] = [];\n\tlet content: string;\n\ttry {\n\t\tcontent = readFileSync(filePath, \"utf8\");\n\t} catch (error) {\n\t\treturn {\n\t\t\tdiagnostics: [\n\t\t\t\t{ path: filePath, message: `Failed to read file: ${error instanceof Error ? error.message : String(error)}` },\n\t\t\t],\n\t\t};\n\t}\n\n\tconst { frontmatter, body } = parseFrontmatter<ParsedFrontmatter>(content);\n\tconst nameRaw = typeof frontmatter.name === \"string\" ? frontmatter.name.trim() : \"\";\n\tconst defaultName = filePath.split(\"/\").pop()?.replace(/\\.md$/i, \"\") ?? \"subagent\";\n\tconst name = (nameRaw || defaultName).trim();\n\tconst description = typeof frontmatter.description === \"string\" ? frontmatter.description.trim() : \"\";\n\tconst profileRaw = typeof frontmatter.profile === \"string\" ? frontmatter.profile.trim() : \"\";\n\tif (profileRaw.length > 0 && !isValidProfileName(profileRaw.toLowerCase())) {\n\t\treturn {\n\t\t\tdiagnostics: [\n\t\t\t\t{\n\t\t\t\t\tpath: filePath,\n\t\t\t\t\tmessage: `Invalid profile \"${profileRaw}\". Valid profiles: explore, plan, iosm, iosm_analyst, iosm_verifier, cycle_planner, meta, full.`,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\tconst profile =\n\t\tprofileRaw.length > 0 ? (profileRaw.toLowerCase() as AgentProfileName) : undefined;\n\tconst parsedTools = normalizeAndFilterToolNames(asStringArray(frontmatter.tools), knownToolNames);\n\tconst parsedDisallowedTools = normalizeAndFilterToolNames(asStringArray(frontmatter.disallowed_tools), knownToolNames);\n\tif (parsedTools.unknown.length > 0) {\n\t\tdiagnostics.push({\n\t\t\tpath: filePath,\n\t\t\tmessage: `Unknown tools were removed from \"tools\": ${parsedTools.unknown.join(\", \")}.`,\n\t\t});\n\t}\n\tif (parsedDisallowedTools.unknown.length > 0) {\n\t\tdiagnostics.push({\n\t\t\tpath: filePath,\n\t\t\tmessage: `Unknown tools were removed from \"disallowed_tools\": ${parsedDisallowedTools.unknown.join(\", \")}.`,\n\t\t});\n\t}\n\tconst tools = parsedTools.normalized.length > 0 ? parsedTools.normalized : undefined;\n\tconst disallowedTools = parsedDisallowedTools.normalized.length > 0 ? parsedDisallowedTools.normalized : undefined;\n\tconst systemPrompt =\n\t\ttypeof frontmatter.system_prompt === \"string\" && frontmatter.system_prompt.trim().length > 0\n\t\t\t? frontmatter.system_prompt.trim()\n\t\t\t: undefined;\n\tconst configuredCwd =\n\t\ttypeof frontmatter.cwd === \"string\" && frontmatter.cwd.trim().length > 0\n\t\t\t? resolve(cwd, frontmatter.cwd.trim())\n\t\t\t: undefined;\n\n\tif (configuredCwd) {\n\t\ttry {\n\t\t\tif (!existsSync(configuredCwd) || !statSync(configuredCwd).isDirectory()) {\n\t\t\t\treturn { diagnostics: [{ path: filePath, message: `Configured cwd is invalid: ${configuredCwd}` }] };\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { diagnostics: [{ path: filePath, message: `Configured cwd is invalid: ${configuredCwd}` }] };\n\t\t}\n\t}\n\n\tconst instructions = body.trim();\n\tif (!instructions) {\n\t\treturn { diagnostics: [{ path: filePath, message: \"Subagent instructions are empty.\" }] };\n\t}\n\n\treturn {\n\t\tdiagnostics,\n\t\tagent: {\n\t\t\tname,\n\t\t\tdescription: description || `Custom subagent ${name}`,\n\t\t\tsourcePath: filePath,\n\t\t\tprofile,\n\t\t\ttools,\n\t\t\tdisallowedTools,\n\t\t\tsystemPrompt,\n\t\t\tinstructions,\n\t\t\tcwd: configuredCwd,\n\t\t\tmodel: typeof frontmatter.model === \"string\" ? frontmatter.model.trim() : undefined,\n\t\t\tbackground: frontmatter.background === true,\n\t\t},\n\t};\n}\n\nexport interface LoadCustomSubagentsOptions {\n\tcwd: string;\n\tagentDir: string;\n\tknownToolNames?: string[];\n}\n\nexport function loadCustomSubagents(options: LoadCustomSubagentsOptions): LoadCustomSubagentsResult {\n\tconst roots: Array<{ path: string; scope: CustomSubagentSourceScope; priority: number }> = [\n\t\t{ path: join(options.agentDir, \"agents\"), scope: \"global\", priority: 0 },\n\t\t{ path: join(options.cwd, \".iosm\", \"agents\"), scope: \"project\", priority: 1 },\n\t];\n\tconst normalizedKnownToolNames = new Set(\n\t\t(options.knownToolNames && options.knownToolNames.length > 0 ? options.knownToolNames : getDefaultKnownToolNames())\n\t\t\t.map((name) => normalizeToolName(name))\n\t\t\t.filter(Boolean),\n\t);\n\tconst diagnostics: SubagentDiagnostic[] = [];\n\tconst overrides: SubagentOverrideInfo[] = [];\n\tconst allAgents: CustomSubagentEntry[] = [];\n\tconst byName = new Map<string, CustomSubagentEntry>();\n\n\tconst registerEntry = (entry: CustomSubagentEntry): void => {\n\t\tconst existing = byName.get(entry.name);\n\t\tif (!existing) {\n\t\t\tentry.effective = true;\n\t\t\tbyName.set(entry.name, entry);\n\t\t\tallAgents.push(entry);\n\t\t\treturn;\n\t\t}\n\n\t\tconst shouldReplace =\n\t\t\tentry.sourcePriority > existing.sourcePriority ||\n\t\t\t(entry.sourcePriority === existing.sourcePriority &&\n\t\t\t\tentry.sourcePath.localeCompare(existing.sourcePath) > 0);\n\n\t\tif (entry.sourcePriority === existing.sourcePriority) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpath: entry.sourcePath,\n\t\t\t\tmessage: `Duplicate agent \"${entry.name}\" in ${entry.sourceScope} scope; ${\n\t\t\t\t\tshouldReplace ? \"this file takes precedence\" : \"existing file keeps precedence\"\n\t\t\t\t}.`,\n\t\t\t});\n\t\t}\n\n\t\tif (shouldReplace) {\n\t\t\texisting.effective = false;\n\t\t\texisting.overriddenByPath = entry.sourcePath;\n\t\t\tentry.effective = true;\n\t\t\tbyName.set(entry.name, entry);\n\t\t\toverrides.push({\n\t\t\t\tname: entry.name,\n\t\t\t\twinnerPath: entry.sourcePath,\n\t\t\t\twinnerScope: entry.sourceScope,\n\t\t\t\toverriddenPath: existing.sourcePath,\n\t\t\t\toverriddenScope: existing.sourceScope,\n\t\t\t});\n\t\t} else {\n\t\t\tentry.overriddenByPath = existing.sourcePath;\n\t\t\toverrides.push({\n\t\t\t\tname: entry.name,\n\t\t\t\twinnerPath: existing.sourcePath,\n\t\t\t\twinnerScope: existing.sourceScope,\n\t\t\t\toverriddenPath: entry.sourcePath,\n\t\t\t\toverriddenScope: entry.sourceScope,\n\t\t\t});\n\t\t}\n\n\t\tallAgents.push(entry);\n\t};\n\n\tfor (const builtin of BUILTIN_SUBAGENTS) {\n\t\tregisterEntry({\n\t\t\t...builtin,\n\t\t\tsourceScope: \"builtin\",\n\t\t\tsourcePriority: BUILTIN_SUBAGENT_PRIORITY,\n\t\t\teffective: false,\n\t\t});\n\t}\n\n\tfor (const root of roots) {\n\t\tfor (const file of readMarkdownFilesRecursive(root.path)) {\n\t\t\tconst parsed = parseSubagentFile(file, options.cwd, normalizedKnownToolNames);\n\t\t\tif (parsed.diagnostics.length > 0) diagnostics.push(...parsed.diagnostics);\n\t\t\tif (!parsed.agent) continue;\n\t\t\tconst entry: CustomSubagentEntry = {\n\t\t\t\t...parsed.agent,\n\t\t\t\tsourceScope: root.scope,\n\t\t\t\tsourcePriority: root.priority,\n\t\t\t\teffective: false,\n\t\t\t};\n\t\t\tregisterEntry(entry);\n\t\t}\n\t}\n\n\tconst agents = Array.from(byName.values()).sort((left, right) => left.name.localeCompare(right.name));\n\tallAgents.sort((left, right) => {\n\t\tconst nameCompare = left.name.localeCompare(right.name);\n\t\tif (nameCompare !== 0) return nameCompare;\n\t\treturn right.sourcePriority - left.sourcePriority;\n\t});\n\treturn { agents, allAgents, overrides, diagnostics };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"subagents.js","sourceRoot":"","sources":["../../src/core/subagents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAyB,MAAM,qBAAqB,CAAC;AA6ChG,MAAM,yBAAyB,GAAG,CAAC,CAAC,CAAC;AAErC,MAAM,iBAAiB,GAA+B;IACrD;QACC,IAAI,EAAE,kB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K,CAAC,IAAI,CAAC,CAAC,CAAC;IACtG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxD,IAAI,WAAW,KAAK,CAAC;YAAE,OAAO,WAAW,CAAC;QAC1C,OAAO,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;IACnD,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AACtD,CAAC","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { basename, join, resolve } from \"node:path\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport { AGENT_PROFILES, isValidProfileName, type AgentProfileName } from \"./agent-profiles.js\";\n\nexport type CustomSubagentSourceScope = \"builtin\" | \"global\" | \"project\";\n\nexport interface CustomSubagentDefinition {\n\tname: string;\n\tdescription: string;\n\tsourcePath: string;\n\tprofile?: AgentProfileName;\n\ttools?: string[];\n\tdisallowedTools?: string[];\n\tsystemPrompt?: string;\n\tinstructions: string;\n\tcwd?: string;\n\tmodel?: string;\n\tbackground?: boolean;\n}\n\nexport interface CustomSubagentEntry extends CustomSubagentDefinition {\n\tsourceScope: CustomSubagentSourceScope;\n\tsourcePriority: number;\n\teffective: boolean;\n\toverriddenByPath?: string;\n}\n\nexport interface SubagentOverrideInfo {\n\tname: string;\n\twinnerPath: string;\n\twinnerScope: CustomSubagentSourceScope;\n\toverriddenPath: string;\n\toverriddenScope: CustomSubagentSourceScope;\n}\n\nexport interface SubagentDiagnostic {\n\tpath: string;\n\tmessage: string;\n}\n\nexport interface LoadCustomSubagentsResult {\n\tagents: CustomSubagentEntry[];\n\tallAgents: CustomSubagentEntry[];\n\toverrides: SubagentOverrideInfo[];\n\tdiagnostics: SubagentDiagnostic[];\n}\n\nconst BUILTIN_SUBAGENT_PRIORITY = -1;\n\nconst BUILTIN_SUBAGENTS: CustomSubagentDefinition[] = [\n\t{\n\t\tname: \"codebase_auditor\",\n\t\tdescription: \"Structured codebase audit for architecture, reliability, security, and test gaps.\",\n\t\tsourcePath: \"builtin://codebase_auditor.md\",\n\t\tprofile: \"explore\",\n\t\tinstructions: [\n\t\t\t\"You are a codebase auditor.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Produce an evidence-based audit of architecture, defect risks, and maintainability hotspots.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Read-only operation. Never edit files.\",\n\t\t\t\"- Make claims only with direct repository evidence.\",\n\t\t\t\"- Prioritize by user impact and likelihood (P0..P3).\",\n\t\t\t\"- If the assigned audit still spans multiple independent subsystems and delegation protocol is available, split it with nested delegates instead of producing one monolithic audit.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Findings (ordered by severity)\",\n\t\t\t\"2) Open questions/unknowns\",\n\t\t\t\"3) Recommended next actions\",\n\t\t\t\"\",\n\t\t\t\"For each finding include:\",\n\t\t\t\"- file path + line reference (when available)\",\n\t\t\t\"- risk/impact\",\n\t\t\t\"- concrete fix direction\",\n\t\t\t\"\",\n\t\t\t\"If no issues are found, explicitly state 'No findings' and list residual risks/testing gaps.\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"system_error_analyst\",\n\t\tdescription: \"Diagnoses system/runtime failures and produces root-cause + fix plan.\",\n\t\tsourcePath: \"builtin://system_error_analyst.md\",\n\t\tprofile: \"plan\",\n\t\tinstructions: [\n\t\t\t\"You are a system error analyst.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Triage failures, identify probable root cause, and propose a minimal, testable fix plan.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Do not modify files.\",\n\t\t\t\"- Use deterministic evidence (logs, stack traces, tests, configs).\",\n\t\t\t\"- Distinguish facts vs hypotheses explicitly.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Incident summary\",\n\t\t\t\"2) Root-cause analysis (ranked hypotheses with evidence)\",\n\t\t\t\"3) Minimal patch plan\",\n\t\t\t\"4) Verification plan (commands + expected signals)\",\n\t\t\t\"5) Regression risks\",\n\t\t\t\"\",\n\t\t\t\"Escalation guidance:\",\n\t\t\t\"- If data is insufficient, request the minimum missing evidence instead of guessing.\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"iosm_change_executor\",\n\t\tdescription: \"Implements repository changes under IOSM methodology and keeps artifacts aligned.\",\n\t\tsourcePath: \"builtin://iosm_change_executor.md\",\n\t\tprofile: \"iosm\",\n\t\tinstructions: [\n\t\t\t\"You are an IOSM change executor.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Analyze, implement, and verify changes while preserving IOSM methodology and artifact consistency.\",\n\t\t\t\"\",\n\t\t\t\"Execution policy:\",\n\t\t\t\"- Inspect relevant code and .iosm artifacts before edits.\",\n\t\t\t\"- Make minimal, targeted changes with clear rationale.\",\n\t\t\t\"- Run focused verification after each meaningful change.\",\n\t\t\t\"- Keep IOSM artifacts in sync when behavior/metrics assumptions change.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) What changed and why\",\n\t\t\t\"2) Files changed\",\n\t\t\t\"3) Verification executed and results\",\n\t\t\t\"4) Remaining risks/assumptions\",\n\t\t\t\"\",\n\t\t\t\"Safety rules:\",\n\t\t\t\"- Do not introduce speculative changes.\",\n\t\t\t\"- If requirements are ambiguous, ask a concise clarification before risky edits.\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"iosm_postchange_verifier\",\n\t\tdescription: \"Post-change IOSM verifier for metric/artifact integrity and regression checks.\",\n\t\tsourcePath: \"builtin://iosm_postchange_verifier.md\",\n\t\tprofile: \"iosm_verifier\",\n\t\tinstructions: [\n\t\t\t\"You are an IOSM post-change verifier.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Validate that implemented changes are correctly reflected in IOSM metrics/artifacts.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Restrict edits to .iosm artifacts unless explicitly instructed otherwise.\",\n\t\t\t\"- Prefer deterministic checks and reproducible commands.\",\n\t\t\t\"- Report mismatches and exact remediation steps.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Checks performed\",\n\t\t\t\"2) Pass/fail per check\",\n\t\t\t\"3) Artifact updates applied (if any)\",\n\t\t\t\"4) Remaining discrepancies and follow-ups\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"qa_test_engineer\",\n\t\tdescription: \"Writes tests, runs verification, and fixes regressions with evidence-driven workflow.\",\n\t\tsourcePath: \"builtin://qa_test_engineer.md\",\n\t\tprofile: \"full\",\n\t\tinstructions: [\n\t\t\t\"You are a QA test engineer and regression fixer.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Increase confidence by adding/updating tests, reproducing failures, and fixing root causes.\",\n\t\t\t\"\",\n\t\t\t\"Workflow:\",\n\t\t\t\"1) Reproduce failure (or define expected behavior if bug is not reproducible yet).\",\n\t\t\t\"2) Add/update focused tests that capture expected behavior.\",\n\t\t\t\"3) Run targeted tests first, then broader suite if needed.\",\n\t\t\t\"4) Implement minimal fix in production code.\",\n\t\t\t\"5) Re-run tests and report outcomes.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Never hide failures by removing assertions or disabling tests unless explicitly requested.\",\n\t\t\t\"- Prefer deterministic tests; avoid flaky timing assumptions.\",\n\t\t\t\"- Keep patch size minimal and localized.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Root cause summary\",\n\t\t\t\"2) Tests added/updated\",\n\t\t\t\"3) Code fixes applied\",\n\t\t\t\"4) Commands executed + pass/fail results\",\n\t\t\t\"5) Residual risk\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"test_failure_triager\",\n\t\tdescription: \"Analyzes failing/flaky tests and proposes a ranked remediation plan.\",\n\t\tsourcePath: \"builtin://test_failure_triager.md\",\n\t\tprofile: \"plan\",\n\t\tinstructions: [\n\t\t\t\"You are a test-failure triage specialist.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Analyze failures quickly and produce a ranked, actionable remediation plan.\",\n\t\t\t\"\",\n\t\t\t\"Rules:\",\n\t\t\t\"- Read/analyze only; do not edit files.\",\n\t\t\t\"- Separate infra/environment issues from product-code defects.\",\n\t\t\t\"- Label confidence for each hypothesis.\",\n\t\t\t\"\",\n\t\t\t\"Required output:\",\n\t\t\t\"1) Failure classification (deterministic, flaky, environment, unknown)\",\n\t\t\t\"2) Ranked hypotheses with evidence\",\n\t\t\t\"3) Minimal next steps to verify each hypothesis\",\n\t\t\t\"4) Recommended owner/agent to execute fixes\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tname: \"meta_orchestrator\",\n\t\tdescription: \"Autonomous orchestration lead: audits, plans, and delegates parallel specialists safely.\",\n\t\tsourcePath: \"builtin://meta_orchestrator.md\",\n\t\tprofile: \"meta\",\n\t\t\tinstructions: [\n\t\t\t\t\"You are the main orchestration agent for complex engineering tasks.\",\n\t\t\t\t\"\",\n\t\t\t\t\"Goal:\",\n\t\t\t\t\"- Drive tasks end-to-end with dynamic delegation: audit -> plan -> execution -> verification.\",\n\t\t\t\t\"- Act as the lead orchestrator, not as a substitute for the parent session runtime.\",\n\t\t\t\t\"\",\n\t\t\t\t\"Required operating phases:\",\n\t\t\t\t\"1) Recon: do bounded read-only inspection to identify repository context, constraints, and relevant files.\",\n\t\t\t\t\"2) Plan: split work into an explicit execution graph of tasks/delegates, including dependencies and lock domains where needed.\",\n\t\t\t\t\"3) Execute adaptively: trivial tasks may stay single-agent; medium/complex tasks should maximize safe parallelism via <delegate_task> and multiple focused workstreams.\",\n\t\t\t\t\"4) Verify: for any code or test changes, add/update tests and run targeted verification before closure.\",\n\t\t\t\t\"5) Synthesize: provide integrated results, unresolved risks, and next actions only after all launched delegates are resolved.\",\n\t\t\t\t\"\",\n\t\t\t\t\"Delegation policy:\",\n\t\t\t\t\"- Main emphasis in META orchestration is parallelism: use as many focused agents and delegates as the task can support safely, rather than defaulting to one broad worker.\",\n\t\t\t\t\"- Recon is only preparation; once you can name the workstreams, stop exploring and delegate.\",\n\t\t\t\t\"- For non-trivial work, assume multi-agent parallel fan-out is required unless you can justify why it is not useful.\",\n\t\t\t\t\"- Decide number of delegates based on task complexity (usually 1-10), and prefer higher fan-out when the work naturally splits.\",\n\t\t\t\t\"- For medium/complex work, target aggressive safe parallel fan-out (commonly >=3 delegates) when independent slices exist.\",\n\t\t\t\t\"- If the user asked for N parallel agents, match that fan-out when feasible or explain the exact blocker.\",\n\t\t\t\t\"- Delegates are child task calls only; do not count plain tool invocations (read/bash/grep/etc.) as delegated agents.\",\n\t\t\t\t\"- Assign explicit ownership domains per delegate before execution to reduce duplicate findings and overlap.\",\n\t\t\t\t\"- If overlap is unavoidable, declare a primary owner and a secondary verifier for that overlap zone.\",\n\t\t\t\t\"- If a delegate owns a task that still contains multiple independent slices, that delegate should split again with nested delegates instead of executing everything alone.\",\n\t\t\t\t\"- Run independent read-heavy work in parallel by emitting multiple delegate blocks.\",\n\t\t\t\t\"- For write-capable delegates touching overlapping areas, provide lock_key to avoid edit collisions.\",\n\t\t\t\t\"- Use depends_on to enforce ordering for dependent steps (for example verification after implementation).\",\n\t\t\t\t\"- Use clear description values and focused prompts per delegate.\",\n\t\t\t\t\"- Do not keep doing direct implementation in the orchestrator after recon for non-trivial work; delegate first.\",\n\t\t\t\t\"- Do not collapse the whole implementation into one specialist delegate when multiple independent workstreams exist.\",\n\t\t\t\t\"- If you keep any non-trivial work single-agent or undelegated, include one line: DELEGATION_IMPOSSIBLE: <reason>.\",\n\t\t\t\"\",\n\t\t\t\"Suggested specialist mapping:\",\n\t\t\t\"- architecture/recon -> profile=explore or plan\",\n\t\t\t\"- implementation -> profile=meta or full or iosm\",\n\t\t\t\"- iosm artifact validation -> profile=iosm_verifier\",\n\t\t\t\"- test creation/fixes -> profile=full (or qa_test_engineer when referenced)\",\n\t\t\t\"\",\n\t\t\t\"Safety rules:\",\n\t\t\t\"- Avoid broad overlapping writes without lock separation.\",\n\t\t\t\"- If requirements are ambiguous and risky, ask for minimal clarification before destructive changes.\",\n\t\t\t\"- Keep all delegated prompts concrete and scoped to specific files/behaviors.\",\n\t\t\t\"- Do not claim completion while any launched delegate remains pending/running.\",\n\t\t\t\"- If no code changed and tests were skipped, include an explicit safety justification.\",\n\t\t\t\"\",\n\t\t\t\"Output requirements:\",\n\t\t\t\"- concise execution summary\",\n\t\t\t\"- delegated work breakdown\",\n\t\t\t\"- verification status\",\n\t\t\t\"- observed-vs-estimated metrics (mark unknown when evidence is missing)\",\n\t\t\t\"- residual risks/assumptions\",\n\t\t].join(\"\\n\"),\n\t},\n];\n\nconst EXTRA_KNOWN_TOOLS = [\"task\", \"todo_write\", \"todo_read\", \"ask_user\", \"git_read\"];\n\nexport function normalizeToolName(value: string): string {\n\treturn value.trim().toLowerCase().replace(/-/g, \"_\");\n}\n\nexport function getDefaultKnownToolNames(): string[] {\n\tconst fromProfiles = Object.values(AGENT_PROFILES).flatMap((profile) => profile.tools);\n\treturn Array.from(\n\t\tnew Set([...fromProfiles, ...EXTRA_KNOWN_TOOLS].map((name) => normalizeToolName(name)).filter(Boolean)),\n\t).sort((left, right) => left.localeCompare(right));\n}\n\nexport function normalizeAndFilterToolNames(\n\tvalues: readonly string[] | undefined,\n\tknownToolNames?: ReadonlySet<string>,\n): { normalized: string[]; unknown: string[] } {\n\tif (!values || values.length === 0) {\n\t\treturn { normalized: [], unknown: [] };\n\t}\n\n\tconst seen = new Set<string>();\n\tconst normalized: string[] = [];\n\tconst unknown: string[] = [];\n\tfor (const value of values) {\n\t\tconst next = normalizeToolName(value);\n\t\tif (!next || seen.has(next)) continue;\n\t\tseen.add(next);\n\t\tif (knownToolNames && knownToolNames.size > 0 && !knownToolNames.has(next)) {\n\t\t\tunknown.push(next);\n\t\t\tcontinue;\n\t\t}\n\t\tnormalized.push(next);\n\t}\n\treturn { normalized, unknown };\n}\n\nfunction trimWrappingChars(value: string): string {\n\tlet next = value.trim();\n\tnext = next.replace(/^@+/, \"\");\n\tnext = next.replace(/^[`\"'“”‘’]+/, \"\");\n\tnext = next.replace(/[`\"'“”‘’]+$/, \"\");\n\tnext = next.replace(/[),;:!?]+$/, \"\");\n\treturn next.trim();\n}\n\nfunction pushCandidate(set: Set<string>, value: string): void {\n\tconst trimmed = value.trim();\n\tif (!trimmed) return;\n\tset.add(trimmed);\n}\n\nexport function getSubagentLookupCandidates(reference: string): string[] {\n\tconst cleaned = trimWrappingChars(reference);\n\tif (!cleaned) return [];\n\tconst normalized = cleaned.replace(/\\\\/g, \"/\");\n\tconst lowerNormalized = normalized.toLowerCase();\n\tconst candidates = new Set<string>();\n\n\tpushCandidate(candidates, cleaned);\n\tpushCandidate(candidates, cleaned.replace(/\\.md$/i, \"\"));\n\tpushCandidate(candidates, normalized);\n\tpushCandidate(candidates, normalized.replace(/\\.md$/i, \"\"));\n\n\tconst pathMarkers = [\"/.iosm/agents/\", \".iosm/agents/\", \"/agents/\", \"agents/\"];\n\tfor (const marker of pathMarkers) {\n\t\tconst markerIndex = lowerNormalized.lastIndexOf(marker.toLowerCase());\n\t\tif (markerIndex === -1) continue;\n\t\tconst suffix = normalized.slice(markerIndex + marker.length);\n\t\tpushCandidate(candidates, suffix);\n\t\tpushCandidate(candidates, suffix.replace(/\\.md$/i, \"\"));\n\t}\n\n\tconst baseFromNormalized = normalized.split(\"/\").filter(Boolean).pop() ?? \"\";\n\tconst baseFromPath = basename(cleaned);\n\tpushCandidate(candidates, baseFromNormalized);\n\tpushCandidate(candidates, baseFromNormalized.replace(/\\.md$/i, \"\"));\n\tpushCandidate(candidates, baseFromPath);\n\tpushCandidate(candidates, baseFromPath.replace(/\\.md$/i, \"\"));\n\n\treturn Array.from(candidates);\n}\n\nexport function resolveCustomSubagentReference(\n\treference: string,\n\tagents: ReadonlyArray<Pick<CustomSubagentDefinition, \"name\" | \"sourcePath\">>,\n): string | undefined {\n\tif (agents.length === 0) return undefined;\n\tconst byName = new Map<string, string>();\n\tconst byNameLower = new Map<string, string>();\n\tconst bySourceBaseLower = new Map<string, string>();\n\n\tfor (const agent of agents) {\n\t\tbyName.set(agent.name, agent.name);\n\t\tbyNameLower.set(agent.name.toLowerCase(), agent.name);\n\n\t\tconst sourceBase = basename(agent.sourcePath);\n\t\tif (sourceBase) {\n\t\t\tconst sourceBaseLower = sourceBase.toLowerCase();\n\t\t\tif (!bySourceBaseLower.has(sourceBaseLower)) {\n\t\t\t\tbySourceBaseLower.set(sourceBaseLower, agent.name);\n\t\t\t}\n\t\t\tconst sourceBaseNoMdLower = sourceBase.replace(/\\.md$/i, \"\").toLowerCase();\n\t\t\tif (!bySourceBaseLower.has(sourceBaseNoMdLower)) {\n\t\t\t\tbySourceBaseLower.set(sourceBaseNoMdLower, agent.name);\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const candidate of getSubagentLookupCandidates(reference)) {\n\t\tconst exact = byName.get(candidate);\n\t\tif (exact) return exact;\n\n\t\tconst lower = candidate.toLowerCase();\n\t\tconst byLower = byNameLower.get(lower);\n\t\tif (byLower) return byLower;\n\t\tconst withoutMd = lower.replace(/\\.md$/i, \"\");\n\t\tconst byWithoutMd = byNameLower.get(withoutMd);\n\t\tif (byWithoutMd) return byWithoutMd;\n\n\t\tconst byBase = bySourceBaseLower.get(lower) ?? bySourceBaseLower.get(withoutMd);\n\t\tif (byBase) return byBase;\n\t}\n\n\treturn undefined;\n}\n\ntype ParsedFrontmatter = {\n\tname?: unknown;\n\tdescription?: unknown;\n\tprofile?: unknown;\n\ttools?: unknown;\n\tdisallowed_tools?: unknown;\n\tsystem_prompt?: unknown;\n\tcwd?: unknown;\n\tmodel?: unknown;\n\tbackground?: unknown;\n};\n\nfunction readMarkdownFilesRecursive(root: string): string[] {\n\tif (!existsSync(root)) return [];\n\tconst files: string[] = [];\n\tconst walk = (dir: string): void => {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true }).sort((left, right) =>\n\t\t\tleft.name.localeCompare(right.name),\n\t\t);\n\t\tfor (const entry of entries) {\n\t\t\tconst full = join(dir, entry.name);\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\twalk(full);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (entry.isFile() && entry.name.toLowerCase().endsWith(\".md\")) {\n\t\t\t\tfiles.push(full);\n\t\t\t}\n\t\t}\n\t};\n\twalk(root);\n\treturn files;\n}\n\nfunction asStringArray(value: unknown): string[] | undefined {\n\tif (Array.isArray(value)) {\n\t\tconst normalized = value.map((item) => String(item).trim()).filter(Boolean);\n\t\treturn normalized.length > 0 ? normalized : undefined;\n\t}\n\tif (typeof value === \"string\") {\n\t\tconst normalized = value\n\t\t\t.split(\",\")\n\t\t\t.map((item) => item.trim())\n\t\t\t.filter(Boolean);\n\t\treturn normalized.length > 0 ? normalized : undefined;\n\t}\n\treturn undefined;\n}\n\nfunction parseSubagentFile(\n\tfilePath: string,\n\tcwd: string,\n\tknownToolNames: ReadonlySet<string>,\n): { agent?: CustomSubagentDefinition; diagnostics: SubagentDiagnostic[] } {\n\tconst diagnostics: SubagentDiagnostic[] = [];\n\tlet content: string;\n\ttry {\n\t\tcontent = readFileSync(filePath, \"utf8\");\n\t} catch (error) {\n\t\treturn {\n\t\t\tdiagnostics: [\n\t\t\t\t{ path: filePath, message: `Failed to read file: ${error instanceof Error ? error.message : String(error)}` },\n\t\t\t],\n\t\t};\n\t}\n\n\tconst { frontmatter, body } = parseFrontmatter<ParsedFrontmatter>(content);\n\tconst nameRaw = typeof frontmatter.name === \"string\" ? frontmatter.name.trim() : \"\";\n\tconst defaultName = filePath.split(\"/\").pop()?.replace(/\\.md$/i, \"\") ?? \"subagent\";\n\tconst name = (nameRaw || defaultName).trim();\n\tconst description = typeof frontmatter.description === \"string\" ? frontmatter.description.trim() : \"\";\n\tconst profileRaw = typeof frontmatter.profile === \"string\" ? frontmatter.profile.trim() : \"\";\n\tif (profileRaw.length > 0 && !isValidProfileName(profileRaw.toLowerCase())) {\n\t\treturn {\n\t\t\tdiagnostics: [\n\t\t\t\t{\n\t\t\t\t\tpath: filePath,\n\t\t\t\t\tmessage: `Invalid profile \"${profileRaw}\". Valid profiles: explore, plan, iosm, iosm_analyst, iosm_verifier, cycle_planner, meta, full.`,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\tconst profile =\n\t\tprofileRaw.length > 0 ? (profileRaw.toLowerCase() as AgentProfileName) : undefined;\n\tconst parsedTools = normalizeAndFilterToolNames(asStringArray(frontmatter.tools), knownToolNames);\n\tconst parsedDisallowedTools = normalizeAndFilterToolNames(asStringArray(frontmatter.disallowed_tools), knownToolNames);\n\tif (parsedTools.unknown.length > 0) {\n\t\tdiagnostics.push({\n\t\t\tpath: filePath,\n\t\t\tmessage: `Unknown tools were removed from \"tools\": ${parsedTools.unknown.join(\", \")}.`,\n\t\t});\n\t}\n\tif (parsedDisallowedTools.unknown.length > 0) {\n\t\tdiagnostics.push({\n\t\t\tpath: filePath,\n\t\t\tmessage: `Unknown tools were removed from \"disallowed_tools\": ${parsedDisallowedTools.unknown.join(\", \")}.`,\n\t\t});\n\t}\n\tconst tools = parsedTools.normalized.length > 0 ? parsedTools.normalized : undefined;\n\tconst disallowedTools = parsedDisallowedTools.normalized.length > 0 ? parsedDisallowedTools.normalized : undefined;\n\tconst systemPrompt =\n\t\ttypeof frontmatter.system_prompt === \"string\" && frontmatter.system_prompt.trim().length > 0\n\t\t\t? frontmatter.system_prompt.trim()\n\t\t\t: undefined;\n\tconst configuredCwd =\n\t\ttypeof frontmatter.cwd === \"string\" && frontmatter.cwd.trim().length > 0\n\t\t\t? resolve(cwd, frontmatter.cwd.trim())\n\t\t\t: undefined;\n\n\tif (configuredCwd) {\n\t\ttry {\n\t\t\tif (!existsSync(configuredCwd) || !statSync(configuredCwd).isDirectory()) {\n\t\t\t\treturn { diagnostics: [{ path: filePath, message: `Configured cwd is invalid: ${configuredCwd}` }] };\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { diagnostics: [{ path: filePath, message: `Configured cwd is invalid: ${configuredCwd}` }] };\n\t\t}\n\t}\n\n\tconst instructions = body.trim();\n\tif (!instructions) {\n\t\treturn { diagnostics: [{ path: filePath, message: \"Subagent instructions are empty.\" }] };\n\t}\n\n\treturn {\n\t\tdiagnostics,\n\t\tagent: {\n\t\t\tname,\n\t\t\tdescription: description || `Custom subagent ${name}`,\n\t\t\tsourcePath: filePath,\n\t\t\tprofile,\n\t\t\ttools,\n\t\t\tdisallowedTools,\n\t\t\tsystemPrompt,\n\t\t\tinstructions,\n\t\t\tcwd: configuredCwd,\n\t\t\tmodel: typeof frontmatter.model === \"string\" ? frontmatter.model.trim() : undefined,\n\t\t\tbackground: frontmatter.background === true,\n\t\t},\n\t};\n}\n\nexport interface LoadCustomSubagentsOptions {\n\tcwd: string;\n\tagentDir: string;\n\tknownToolNames?: string[];\n}\n\nexport function loadCustomSubagents(options: LoadCustomSubagentsOptions): LoadCustomSubagentsResult {\n\tconst roots: Array<{ path: string; scope: CustomSubagentSourceScope; priority: number }> = [\n\t\t{ path: join(options.agentDir, \"agents\"), scope: \"global\", priority: 0 },\n\t\t{ path: join(options.cwd, \".iosm\", \"agents\"), scope: \"project\", priority: 1 },\n\t];\n\tconst normalizedKnownToolNames = new Set(\n\t\t(options.knownToolNames && options.knownToolNames.length > 0 ? options.knownToolNames : getDefaultKnownToolNames())\n\t\t\t.map((name) => normalizeToolName(name))\n\t\t\t.filter(Boolean),\n\t);\n\tconst diagnostics: SubagentDiagnostic[] = [];\n\tconst overrides: SubagentOverrideInfo[] = [];\n\tconst allAgents: CustomSubagentEntry[] = [];\n\tconst byName = new Map<string, CustomSubagentEntry>();\n\n\tconst registerEntry = (entry: CustomSubagentEntry): void => {\n\t\tconst existing = byName.get(entry.name);\n\t\tif (!existing) {\n\t\t\tentry.effective = true;\n\t\t\tbyName.set(entry.name, entry);\n\t\t\tallAgents.push(entry);\n\t\t\treturn;\n\t\t}\n\n\t\tconst shouldReplace =\n\t\t\tentry.sourcePriority > existing.sourcePriority ||\n\t\t\t(entry.sourcePriority === existing.sourcePriority &&\n\t\t\t\tentry.sourcePath.localeCompare(existing.sourcePath) > 0);\n\n\t\tif (entry.sourcePriority === existing.sourcePriority) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpath: entry.sourcePath,\n\t\t\t\tmessage: `Duplicate agent \"${entry.name}\" in ${entry.sourceScope} scope; ${\n\t\t\t\t\tshouldReplace ? \"this file takes precedence\" : \"existing file keeps precedence\"\n\t\t\t\t}.`,\n\t\t\t});\n\t\t}\n\n\t\tif (shouldReplace) {\n\t\t\texisting.effective = false;\n\t\t\texisting.overriddenByPath = entry.sourcePath;\n\t\t\tentry.effective = true;\n\t\t\tbyName.set(entry.name, entry);\n\t\t\toverrides.push({\n\t\t\t\tname: entry.name,\n\t\t\t\twinnerPath: entry.sourcePath,\n\t\t\t\twinnerScope: entry.sourceScope,\n\t\t\t\toverriddenPath: existing.sourcePath,\n\t\t\t\toverriddenScope: existing.sourceScope,\n\t\t\t});\n\t\t} else {\n\t\t\tentry.overriddenByPath = existing.sourcePath;\n\t\t\toverrides.push({\n\t\t\t\tname: entry.name,\n\t\t\t\twinnerPath: existing.sourcePath,\n\t\t\t\twinnerScope: existing.sourceScope,\n\t\t\t\toverriddenPath: entry.sourcePath,\n\t\t\t\toverriddenScope: entry.sourceScope,\n\t\t\t});\n\t\t}\n\n\t\tallAgents.push(entry);\n\t};\n\n\tfor (const builtin of BUILTIN_SUBAGENTS) {\n\t\tregisterEntry({\n\t\t\t...builtin,\n\t\t\tsourceScope: \"builtin\",\n\t\t\tsourcePriority: BUILTIN_SUBAGENT_PRIORITY,\n\t\t\teffective: false,\n\t\t});\n\t}\n\n\tfor (const root of roots) {\n\t\tfor (const file of readMarkdownFilesRecursive(root.path)) {\n\t\t\tconst parsed = parseSubagentFile(file, options.cwd, normalizedKnownToolNames);\n\t\t\tif (parsed.diagnostics.length > 0) diagnostics.push(...parsed.diagnostics);\n\t\t\tif (!parsed.agent) continue;\n\t\t\tconst entry: CustomSubagentEntry = {\n\t\t\t\t...parsed.agent,\n\t\t\t\tsourceScope: root.scope,\n\t\t\t\tsourcePriority: root.priority,\n\t\t\t\teffective: false,\n\t\t\t};\n\t\t\tregisterEntry(entry);\n\t\t}\n\t}\n\n\tconst agents = Array.from(byName.values()).sort((left, right) => left.name.localeCompare(right.name));\n\tallAgents.sort((left, right) => {\n\t\tconst nameCompare = left.name.localeCompare(right.name);\n\t\tif (nameCompare !== 0) return nameCompare;\n\t\treturn right.sourcePriority - left.sourcePriority;\n\t});\n\treturn { agents, allAgents, overrides, diagnostics };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../../src/core/tools/task.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../../src/core/tools/task.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAKN,KAAK,YAAY,EACjB,MAAM,6BAA6B,CAAC;AAOrC,OAAO,EAEN,KAAK,mBAAmB,EAGxB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,EAAkD,KAAK,wBA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AAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,eAAe,GACvB,SAAS,CAAC,OAAO,UAAU,CAAC,CA0sE9B"}
|
package/dist/core/tools/task.js
CHANGED
|
@@ -4,7 +4,6 @@ import { spawnSync } from "node:child_process";
|
|
|
4
4
|
import { Type } from "@sinclair/typebox";
|
|
5
5
|
import { getTeamRun, updateTeamTaskStatus } from "../agent-teams.js";
|
|
6
6
|
import { buildRetrospectiveDirective, classifyFailureCause, formatFailureCauseCounts, isRetrospectiveRetryable, } from "../failure-retrospective.js";
|
|
7
|
-
import { MAX_ORCHESTRATION_AGENTS, MAX_ORCHESTRATION_PARALLEL, MAX_SUBAGENT_DELEGATE_PARALLEL, MAX_SUBAGENT_DELEGATION_DEPTH, MAX_SUBAGENT_DELEGATIONS_PER_TASK, } from "../orchestration-limits.js";
|
|
8
7
|
import { AGENT_PROFILES, isReadOnlyProfileName, isValidProfileName, } from "../agent-profiles.js";
|
|
9
8
|
import { readSharedMemory, summarizeSharedMemoryUsage, writeSharedMemory, } from "../shared-memory.js";
|
|
10
9
|
import { appendSubagentBackgroundRunLog, registerSubagentBackgroundRunController, unregisterSubagentBackgroundRunController, writeSubagentBackgroundRunStatus, } from "../subagent-background-runs.js";
|
|
@@ -51,7 +50,6 @@ const taskSchema = Type.Object({
|
|
|
51
50
|
})),
|
|
52
51
|
delegate_parallel_hint: Type.Optional(Type.Integer({
|
|
53
52
|
minimum: 1,
|
|
54
|
-
maximum: MAX_SUBAGENT_DELEGATE_PARALLEL,
|
|
55
53
|
description: "Optional hint for intra-task delegation fan-out. Higher value allows more delegated subtasks to run in parallel inside a single task execution.",
|
|
56
54
|
})),
|
|
57
55
|
});
|
|
@@ -65,7 +63,7 @@ const systemPromptByProfile = {
|
|
|
65
63
|
explore: "You are a fast read-only codebase explorer. Answer concisely. Never write or edit files.",
|
|
66
64
|
plan: "You are a technical architect. Analyze the codebase and produce a clear implementation plan. Do not write or edit files.",
|
|
67
65
|
iosm: "You are an IOSM execution agent. Use IOSM methodology and keep IOSM artifacts synchronized with implementation.",
|
|
68
|
-
meta: "You are a meta orchestration agent. Your main job is to maximize safe parallel execution through delegates, not to personally do most of the implementation. Start with bounded read-only recon, then form a concrete execution graph: subtasks, delegate subtasks, dependencies, lock domains, and verification steps. The parent agent remains responsible for orchestration and synthesis, so decompose work aggressively instead of collapsing complex work into one worker. For any non-trivial task, orchestration is required: after recon, launch multiple focused delegates instead of continuing manual implementation in the parent agent, avoid direct write/edit work in the parent agent before delegation unless the task is clearly trivial, and do not hand the whole task to one specialist child when independent workstreams exist. If a delegated workstream still contains multiple independent slices, split it again with nested <delegate_task> blocks. Default to aggressive safe parallelism. If the user requested a specific degree of parallelism, honor it when feasible or explain the exact blocker. Use shared_memory as the default coordination channel between delegates: use stable namespaced keys, prefer read-before-write, and use CAS (if_version) for contested updates; reserve append mode for timeline/log keys. When delegation is not used for non-trivial work, explain why in one line and include DELEGATION_IMPOSSIBLE. Enforce test verification for code changes, complete only after all delegated branches are resolved, and explicitly justify any no-code path where tests are skipped. For any metrics (speedup, compliance, conflict counts, quality scores), report only values backed by observed runtime evidence; if evidence is missing, mark the metric as unknown. Do not claim report files/artifacts unless they were produced in this run or verified on disk.",
|
|
66
|
+
meta: "You are a meta orchestration agent. Your main job is to maximize safe parallel execution through delegates, not to personally do most of the implementation. Start with bounded read-only recon, then form a concrete execution graph: subtasks, delegate subtasks, dependencies, lock domains, and verification steps. The parent agent remains responsible for orchestration and synthesis, so decompose work aggressively instead of collapsing complex work into one worker. For any non-trivial task, orchestration is required: after recon, launch multiple focused delegates instead of continuing manual implementation in the parent agent, avoid direct write/edit work in the parent agent before delegation unless the task is clearly trivial, and do not hand the whole task to one specialist child when independent workstreams exist. If a delegated workstream still contains multiple independent slices, split it again with nested <delegate_task> blocks. Default to aggressive safe parallelism. If the user requested a specific degree of parallelism, honor it when feasible or explain the exact blocker. Delegates are child task calls only; do not treat plain tool invocations (read/bash/grep/etc.) as delegated agents. Assign explicit ownership domains per delegate to minimize overlap; if overlap is unavoidable, declare a primary owner and a secondary verifier. Use shared_memory as the default coordination channel between delegates: use stable namespaced keys, prefer read-before-write, and use CAS (if_version) for contested updates; reserve append mode for timeline/log keys. When delegation is not used for non-trivial work, explain why in one line and include DELEGATION_IMPOSSIBLE. Enforce test verification for code changes, complete only after all delegated branches are resolved, and explicitly justify any no-code path where tests are skipped. For any metrics (speedup, compliance, conflict counts, quality scores), report only values backed by observed runtime evidence; if evidence is missing, mark the metric as unknown. Do not claim report files/artifacts unless they were produced in this run or verified on disk.",
|
|
69
67
|
iosm_analyst: "You are an IOSM metrics analyst. Analyze .iosm/ artifacts and codebase metrics. Be precise and evidence-based.",
|
|
70
68
|
iosm_verifier: "You are an IOSM verifier. Validate checks and update only required IOSM artifacts with deterministic reasoning.",
|
|
71
69
|
cycle_planner: "You are an IOSM cycle planner. Propose and align cycle goals with measurable outcomes and concrete risks.",
|
|
@@ -195,11 +193,11 @@ class Mutex {
|
|
|
195
193
|
return !this.locked && this.waiters.length === 0;
|
|
196
194
|
}
|
|
197
195
|
}
|
|
198
|
-
const maxParallelFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_MAX_PARALLEL,
|
|
196
|
+
const maxParallelFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_MAX_PARALLEL, Number.MAX_SAFE_INTEGER, 1, Number.MAX_SAFE_INTEGER);
|
|
199
197
|
const subagentSemaphore = new Semaphore(maxParallelFromEnv);
|
|
200
|
-
const maxDelegationDepthFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_MAX_DELEGATION_DEPTH,
|
|
201
|
-
const maxDelegationsPerTaskFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_MAX_DELEGATIONS_PER_TASK,
|
|
202
|
-
const maxDelegatedParallelFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_MAX_DELEGATE_PARALLEL,
|
|
198
|
+
const maxDelegationDepthFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_MAX_DELEGATION_DEPTH, Number.MAX_SAFE_INTEGER, 0, Number.MAX_SAFE_INTEGER);
|
|
199
|
+
const maxDelegationsPerTaskFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_MAX_DELEGATIONS_PER_TASK, Number.MAX_SAFE_INTEGER, 0, Number.MAX_SAFE_INTEGER);
|
|
200
|
+
const maxDelegatedParallelFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_MAX_DELEGATE_PARALLEL, Number.MAX_SAFE_INTEGER, 1, Number.MAX_SAFE_INTEGER);
|
|
203
201
|
const emptyOutputRetriesFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_EMPTY_OUTPUT_RETRIES, 1, 0, 2);
|
|
204
202
|
const retrospectiveRetriesFromEnv = parseBoundedInt(process.env.IOSM_SUBAGENT_RETRO_RETRIES, 1, 0, 1);
|
|
205
203
|
const orchestrationDependencyWaitTimeoutMsFromEnv = parseBoundedInt(process.env.IOSM_ORCHESTRATION_DEPENDENCY_WAIT_TIMEOUT_MS, 120_000, 5_000, 900_000);
|
|
@@ -244,8 +242,6 @@ function deriveAutoDelegateParallelHint(profile, agentName, hostProfile, descrip
|
|
|
244
242
|
const fileLikeMatches = normalized.match(/\b[A-Za-z0-9_.-]+\.[A-Za-z0-9]{1,8}\b/g) ?? [];
|
|
245
243
|
const listMarkers = text.match(/(?:^|\n)\s*(?:[-*]|\d+[.)])\s+/g)?.length ?? 0;
|
|
246
244
|
const hasCodeBlock = text.includes("```");
|
|
247
|
-
const actionTokenMatches = normalized.match(/\b(?:audit|security|auth|rbac|sqli|sql|injection|fix|implement|refactor|migrat|harden|verify|test|scan|orchestrate|parallel|delegate|bug|vulnerab)\w*/gi) ?? [];
|
|
248
|
-
const strongActionSignal = new Set(actionTokenMatches.map((token) => token.toLowerCase())).size >= 2;
|
|
249
245
|
const metaOrchestratorContext = isMetaProfile || isMetaHost;
|
|
250
246
|
let score = 0;
|
|
251
247
|
if (words >= 40) {
|
|
@@ -268,8 +264,7 @@ function deriveAutoDelegateParallelHint(profile, agentName, hostProfile, descrip
|
|
|
268
264
|
clauses >= 3 ||
|
|
269
265
|
listMarkers >= 1 ||
|
|
270
266
|
referenceCount >= 1 ||
|
|
271
|
-
hasCodeBlock
|
|
272
|
-
(strongActionSignal && words >= 4);
|
|
267
|
+
hasCodeBlock;
|
|
273
268
|
if (referenceCount >= 3 || (referenceCount >= 1 && words >= 20)) {
|
|
274
269
|
score += 1;
|
|
275
270
|
}
|
|
@@ -277,13 +272,9 @@ function deriveAutoDelegateParallelHint(profile, agentName, hostProfile, descrip
|
|
|
277
272
|
score += 1;
|
|
278
273
|
}
|
|
279
274
|
if (metaOrchestratorContext) {
|
|
280
|
-
// In meta orchestration, require delegation pressure for non-trivial prompts
|
|
281
|
-
// even when lexical scoring is still low.
|
|
275
|
+
// In meta orchestration, require delegation pressure for structurally non-trivial prompts.
|
|
282
276
|
if (score === 0) {
|
|
283
|
-
if (
|
|
284
|
-
score = 1;
|
|
285
|
-
}
|
|
286
|
-
else if (metaNonTrivialSignal) {
|
|
277
|
+
if (metaNonTrivialSignal) {
|
|
287
278
|
score = 2;
|
|
288
279
|
}
|
|
289
280
|
}
|
|
@@ -305,6 +296,23 @@ function deriveAutoDelegateParallelHint(profile, agentName, hostProfile, descrip
|
|
|
305
296
|
return 2;
|
|
306
297
|
return 1;
|
|
307
298
|
}
|
|
299
|
+
function deriveExplicitDelegateParallelHint(description, prompt) {
|
|
300
|
+
const text = `${description}\n${prompt}`.trim();
|
|
301
|
+
if (!text)
|
|
302
|
+
return undefined;
|
|
303
|
+
const structuredPatterns = [
|
|
304
|
+
/\bdelegate_parallel_hint\s*[:=]\s*["']?(\d{1,4})\b/i,
|
|
305
|
+
/"delegate_parallel_hint"\s*:\s*(\d{1,4})/i,
|
|
306
|
+
];
|
|
307
|
+
for (const pattern of structuredPatterns) {
|
|
308
|
+
const match = text.match(pattern);
|
|
309
|
+
const parsed = match?.[1] ? Number.parseInt(match[1], 10) : Number.NaN;
|
|
310
|
+
if (Number.isInteger(parsed) && parsed >= 1) {
|
|
311
|
+
return parsed;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
308
316
|
function normalizeSpacing(text) {
|
|
309
317
|
return text.replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
310
318
|
}
|
|
@@ -862,9 +870,9 @@ function getRunParallelLimit(cwd, runId) {
|
|
|
862
870
|
return 1;
|
|
863
871
|
const maxParallel = teamRun.maxParallel;
|
|
864
872
|
if (!Number.isInteger(maxParallel) || !maxParallel || maxParallel < 1) {
|
|
865
|
-
return Math.max(1,
|
|
873
|
+
return Math.max(1, teamRun.agents);
|
|
866
874
|
}
|
|
867
|
-
return Math.max(1,
|
|
875
|
+
return Math.max(1, maxParallel);
|
|
868
876
|
}
|
|
869
877
|
function getOrCreateOrchestrationSemaphore(cwd, runId) {
|
|
870
878
|
const limit = getRunParallelLimit(cwd, runId);
|
|
@@ -1159,22 +1167,32 @@ export function createTaskTool(cwd, runner, options) {
|
|
|
1159
1167
|
}
|
|
1160
1168
|
const delegationDepth = maxDelegationDepthFromEnv;
|
|
1161
1169
|
const requestedDelegateParallelHint = typeof delegateParallelHint === "number" && Number.isInteger(delegateParallelHint)
|
|
1162
|
-
? Math.max(1,
|
|
1170
|
+
? Math.max(1, delegateParallelHint)
|
|
1163
1171
|
: undefined;
|
|
1164
|
-
const
|
|
1172
|
+
const explicitDelegateParallelHint = requestedDelegateParallelHint === undefined
|
|
1173
|
+
? deriveExplicitDelegateParallelHint(description, prompt)
|
|
1174
|
+
: undefined;
|
|
1175
|
+
const autoDelegateParallelHint = requestedDelegateParallelHint === undefined && explicitDelegateParallelHint === undefined
|
|
1165
1176
|
? deriveAutoDelegateParallelHint(effectiveProfile, normalizedAgentName, normalizedHostProfile, description, prompt)
|
|
1166
1177
|
: undefined;
|
|
1167
|
-
|
|
1178
|
+
const effectiveDelegateParallelHint = requestedDelegateParallelHint ?? explicitDelegateParallelHint ?? autoDelegateParallelHint;
|
|
1168
1179
|
const effectiveDelegationDepth = effectiveProfile === "meta" || normalizedHostProfile === "meta" || normalizedAgentName?.toLowerCase().includes("orchestrator")
|
|
1169
1180
|
? Math.max(delegationDepth, 2)
|
|
1170
1181
|
: delegationDepth;
|
|
1171
1182
|
const orchestratedRunContext = !!(orchestrationRunId && orchestrationTaskId);
|
|
1183
|
+
const explicitDelegationContract = explicitDelegateParallelHint !== undefined && explicitDelegateParallelHint >= 1;
|
|
1172
1184
|
const strictDelegationContract = effectiveProfile === "meta" ||
|
|
1173
1185
|
normalizedHostProfile === "meta" ||
|
|
1174
1186
|
normalizedAgentName?.toLowerCase().includes("orchestrator") ||
|
|
1175
|
-
(orchestratedRunContext && (effectiveDelegateParallelHint ?? 0) >= 2)
|
|
1187
|
+
(orchestratedRunContext && (effectiveDelegateParallelHint ?? 0) >= 2) ||
|
|
1188
|
+
explicitDelegationContract;
|
|
1176
1189
|
let effectiveMaxDelegations = Math.max(0, Math.min(maxDelegationsPerTaskFromEnv, effectiveDelegateParallelHint ?? maxDelegationsPerTaskFromEnv));
|
|
1177
1190
|
let effectiveMaxDelegateParallel = Math.max(1, Math.min(maxDelegatedParallelFromEnv, effectiveDelegateParallelHint ?? maxDelegatedParallelFromEnv));
|
|
1191
|
+
if (explicitDelegationContract) {
|
|
1192
|
+
const explicitTarget = Math.max(1, explicitDelegateParallelHint ?? 1);
|
|
1193
|
+
effectiveMaxDelegations = Math.max(effectiveMaxDelegations, Math.min(maxDelegationsPerTaskFromEnv, explicitTarget));
|
|
1194
|
+
effectiveMaxDelegateParallel = Math.max(effectiveMaxDelegateParallel, Math.min(maxDelegatedParallelFromEnv, explicitTarget));
|
|
1195
|
+
}
|
|
1178
1196
|
const isMetaDelegationContext = effectiveProfile === "meta" || normalizedHostProfile === "meta";
|
|
1179
1197
|
const preferredDelegationFloorBase = isMetaDelegationContext ? 3 : 2;
|
|
1180
1198
|
const preferredDelegationFloorMin = isMetaDelegationContext ? 2 : 1;
|
|
@@ -1186,9 +1204,13 @@ export function createTaskTool(cwd, runner, options) {
|
|
|
1186
1204
|
effectiveMaxDelegations = Math.max(effectiveMaxDelegations, Math.min(maxDelegationsPerTaskFromEnv, metaDelegationCapacityFloor));
|
|
1187
1205
|
effectiveMaxDelegateParallel = Math.max(effectiveMaxDelegateParallel, Math.min(maxDelegatedParallelFromEnv, preferredDelegationFloor));
|
|
1188
1206
|
}
|
|
1189
|
-
const minDelegationsPreferred =
|
|
1190
|
-
?
|
|
1191
|
-
|
|
1207
|
+
const minDelegationsPreferred = explicitDelegationContract
|
|
1208
|
+
? effectiveMaxDelegations > 0
|
|
1209
|
+
? Math.min(Math.max(1, explicitDelegateParallelHint ?? 1), effectiveMaxDelegations)
|
|
1210
|
+
: 0
|
|
1211
|
+
: (effectiveDelegateParallelHint ?? 0) >= 2 && effectiveMaxDelegations >= 2
|
|
1212
|
+
? Math.min(preferredDelegationFloor, effectiveMaxDelegations, effectiveDelegateParallelHint ?? preferredDelegationFloor)
|
|
1213
|
+
: 0;
|
|
1192
1214
|
const runtimeCapabilityHints = "Runtime capability: for long-running shell commands that should not block the turn (especially start/run-project or dev-server/watch commands), use bash with run_in_background=true and report backgroundTaskId for follow-up monitoring/stop actions; keep foreground mode only when immediate command output is required.";
|
|
1193
1215
|
const baseSystemPrompt = withSubagentInstructions(`${customSubagent?.systemPrompt ??
|
|
1194
1216
|
systemPromptByProfile[effectiveProfile] ??
|