iosm-cli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +58 -47
  2. package/dist/core/agent-teams.d.ts.map +1 -1
  3. package/dist/core/agent-teams.js +38 -11
  4. package/dist/core/agent-teams.js.map +1 -1
  5. package/dist/core/failure-retrospective.d.ts +12 -0
  6. package/dist/core/failure-retrospective.d.ts.map +1 -0
  7. package/dist/core/failure-retrospective.js +115 -0
  8. package/dist/core/failure-retrospective.js.map +1 -0
  9. package/dist/core/project-index/index.d.ts +17 -0
  10. package/dist/core/project-index/index.d.ts.map +1 -0
  11. package/dist/core/project-index/index.js +323 -0
  12. package/dist/core/project-index/index.js.map +1 -0
  13. package/dist/core/project-index/types.d.ts +34 -0
  14. package/dist/core/project-index/types.d.ts.map +1 -0
  15. package/dist/core/project-index/types.js +2 -0
  16. package/dist/core/project-index/types.js.map +1 -0
  17. package/dist/core/sdk.d.ts.map +1 -1
  18. package/dist/core/sdk.js +8 -0
  19. package/dist/core/sdk.js.map +1 -1
  20. package/dist/core/shared-memory.d.ts +46 -0
  21. package/dist/core/shared-memory.d.ts.map +1 -0
  22. package/dist/core/shared-memory.js +253 -0
  23. package/dist/core/shared-memory.js.map +1 -0
  24. package/dist/core/slash-commands.d.ts.map +1 -1
  25. package/dist/core/slash-commands.js +5 -1
  26. package/dist/core/slash-commands.js.map +1 -1
  27. package/dist/core/subagents.js +1 -1
  28. package/dist/core/subagents.js.map +1 -1
  29. package/dist/core/swarm/gates.d.ts +9 -0
  30. package/dist/core/swarm/gates.d.ts.map +1 -0
  31. package/dist/core/swarm/gates.js +65 -0
  32. package/dist/core/swarm/gates.js.map +1 -0
  33. package/dist/core/swarm/index.d.ts +9 -0
  34. package/dist/core/swarm/index.d.ts.map +1 -0
  35. package/dist/core/swarm/index.js +9 -0
  36. package/dist/core/swarm/index.js.map +1 -0
  37. package/dist/core/swarm/locks.d.ts +21 -0
  38. package/dist/core/swarm/locks.d.ts.map +1 -0
  39. package/dist/core/swarm/locks.js +93 -0
  40. package/dist/core/swarm/locks.js.map +1 -0
  41. package/dist/core/swarm/planner.d.ts +16 -0
  42. package/dist/core/swarm/planner.d.ts.map +1 -0
  43. package/dist/core/swarm/planner.js +137 -0
  44. package/dist/core/swarm/planner.js.map +1 -0
  45. package/dist/core/swarm/retry.d.ts +16 -0
  46. package/dist/core/swarm/retry.d.ts.map +1 -0
  47. package/dist/core/swarm/retry.js +32 -0
  48. package/dist/core/swarm/retry.js.map +1 -0
  49. package/dist/core/swarm/scheduler.d.ts +48 -0
  50. package/dist/core/swarm/scheduler.d.ts.map +1 -0
  51. package/dist/core/swarm/scheduler.js +554 -0
  52. package/dist/core/swarm/scheduler.js.map +1 -0
  53. package/dist/core/swarm/spawn.d.ts +16 -0
  54. package/dist/core/swarm/spawn.d.ts.map +1 -0
  55. package/dist/core/swarm/spawn.js +42 -0
  56. package/dist/core/swarm/spawn.js.map +1 -0
  57. package/dist/core/swarm/state-store.d.ts +35 -0
  58. package/dist/core/swarm/state-store.d.ts.map +1 -0
  59. package/dist/core/swarm/state-store.js +106 -0
  60. package/dist/core/swarm/state-store.js.map +1 -0
  61. package/dist/core/swarm/types.d.ts +116 -0
  62. package/dist/core/swarm/types.d.ts.map +1 -0
  63. package/dist/core/swarm/types.js +2 -0
  64. package/dist/core/swarm/types.js.map +1 -0
  65. package/dist/core/system-prompt.d.ts.map +1 -1
  66. package/dist/core/system-prompt.js +3 -2
  67. package/dist/core/system-prompt.js.map +1 -1
  68. package/dist/core/tools/shared-memory.d.ts +23 -0
  69. package/dist/core/tools/shared-memory.d.ts.map +1 -0
  70. package/dist/core/tools/shared-memory.js +134 -0
  71. package/dist/core/tools/shared-memory.js.map +1 -0
  72. package/dist/core/tools/task.d.ts +8 -1
  73. package/dist/core/tools/task.d.ts.map +1 -1
  74. package/dist/core/tools/task.js +664 -123
  75. package/dist/core/tools/task.js.map +1 -1
  76. package/dist/modes/interactive/components/login-dialog.d.ts +1 -0
  77. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  78. package/dist/modes/interactive/components/login-dialog.js +27 -4
  79. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  80. package/dist/modes/interactive/components/subagent-message.d.ts.map +1 -1
  81. package/dist/modes/interactive/components/subagent-message.js +14 -0
  82. package/dist/modes/interactive/components/subagent-message.js.map +1 -1
  83. package/dist/modes/interactive/interactive-mode.d.ts +38 -0
  84. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  85. package/dist/modes/interactive/interactive-mode.js +1362 -31
  86. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  87. package/docs/cli-reference.md +11 -1
  88. package/docs/interactive-mode.md +42 -3
  89. package/docs/orchestration-and-subagents.md +96 -169
  90. package/package.json +4 -3
@@ -182,7 +182,7 @@ const BUILTIN_SUBAGENTS = [
182
182
  "4) Synthesize: provide integrated results, unresolved risks, and next actions.",
183
183
  "",
184
184
  "Delegation policy:",
185
- "- Decide number of delegates based on task complexity (usually 1-6).",
185
+ "- Decide number of delegates based on task complexity (usually 1-10).",
186
186
  "- Run independent read-heavy work in parallel by emitting multiple delegate blocks.",
187
187
  "- For write-capable delegates touching overlapping areas, provide lock_key to avoid edit collisions.",
188
188
  "- Use depends_on to enforce ordering for dependent steps (for example verification after implementation).",
@@ -1 +1 @@
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;AA8C3D,MAAM,yBAAyB,GAAG,CAAC,CAAC,CAAC;AAErC,MAAM,iBAAiB,GAA+B;IACrD;QACC,IA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,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 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\"\",\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: \"full\",\n\t\tinstructions: [\n\t\t\t\"You are the main orchestration agent for complex engineering tasks.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Drive tasks end-to-end with dynamic delegation: audit -> plan -> execution -> verification.\",\n\t\t\t\"\",\n\t\t\t\"Required operating phases:\",\n\t\t\t\"1) Recon: inspect repository context and constraints.\",\n\t\t\t\"2) Plan: split work into independent chunks and dependency chains.\",\n\t\t\t\"3) Delegate: emit specialist <delegate_task> blocks for chunks that benefit from parallel execution.\",\n\t\t\t\"4) Synthesize: provide integrated results, unresolved risks, and next actions.\",\n\t\t\t\"\",\n\t\t\t\"Delegation policy:\",\n\t\t\t\"- Decide number of delegates based on task complexity (usually 1-6).\",\n\t\t\t\"- Run independent read-heavy work in parallel by emitting multiple delegate blocks.\",\n\t\t\t\"- For write-capable delegates touching overlapping areas, provide lock_key to avoid edit collisions.\",\n\t\t\t\"- Use depends_on to enforce ordering for dependent steps (for example verification after implementation).\",\n\t\t\t\"- Use clear description values and focused prompts per delegate.\",\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=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\"\",\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\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(filePath: string, cwd: string): { agent?: CustomSubagentDefinition; diagnostic?: SubagentDiagnostic } {\n\tlet content: string;\n\ttry {\n\t\tcontent = readFileSync(filePath, \"utf8\");\n\t} catch (error) {\n\t\treturn {\n\t\t\tdiagnostic: { path: filePath, message: `Failed to read file: ${error instanceof Error ? error.message : String(error)}` },\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 profile =\n\t\ttypeof frontmatter.profile === \"string\" && frontmatter.profile.trim().length > 0\n\t\t\t? (frontmatter.profile.trim() as AgentProfileName)\n\t\t\t: undefined;\n\tconst tools = asStringArray(frontmatter.tools);\n\tconst disallowedTools = asStringArray(frontmatter.disallowed_tools);\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 { diagnostic: { path: filePath, message: `Configured cwd is invalid: ${configuredCwd}` } };\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { diagnostic: { 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 { diagnostic: { path: filePath, message: \"Subagent instructions are empty.\" } };\n\t}\n\n\treturn {\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 function loadCustomSubagents(options: { cwd: string; agentDir: string }): 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 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);\n\t\t\tif (parsed.diagnostic) {\n\t\t\t\tdiagnostics.push(parsed.diagnostic);\n\t\t\t\tcontinue;\n\t\t\t}\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;AA8C3D,MAAM,yBAAyB,GAAG,CAAC,CAAC,CAAC;AAErC,MAAM,iBAAiB,GAA+B;IACrD;QACC,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,mFAAmF;QAChG,UAAU,EAAE,+BAA+B;QAC3C,OAAO,EAAE,SAAS;QAClB,YAAY,EAAE;YACb,6BAA6B;YAC7B,EAAE;YACF,OAAO;YACP,gGAAgG;YAChG,EAAE;YACF,QAAQ;YACR,0CAA0C;YAC1C,qDAAqD;YACrD,sDAAsD;YACtD,EAAE;YACF,kBAAkB;YAClB,mCAAmC;YACnC,4BAA4B;YAC5B,6BAA6B;YAC7B,EAAE;YACF,2BAA2B;YAC3B,+CAA+C;YAC/C,eAAe;YACf,0BAA0B;YAC1B,EAAE;YACF,8FAA8F;SAC9F,CAAC,IAAI,CAAC,IAAI,CAAC;KACZ;IACD;QACC,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,uEAAuE;QACpF,UAAU,EAAE,mCAAmC;QAC/C,OAAO,EAAE,MAAM;QACf,YAAY,EAAE;YACb,iCAAiC;YACjC,EAAE;YACF,OAAO;YACP,4FAA4F;YAC5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AE,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 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\"\",\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: \"full\",\n\t\tinstructions: [\n\t\t\t\"You are the main orchestration agent for complex engineering tasks.\",\n\t\t\t\"\",\n\t\t\t\"Goal:\",\n\t\t\t\"- Drive tasks end-to-end with dynamic delegation: audit -> plan -> execution -> verification.\",\n\t\t\t\"\",\n\t\t\t\"Required operating phases:\",\n\t\t\t\"1) Recon: inspect repository context and constraints.\",\n\t\t\t\"2) Plan: split work into independent chunks and dependency chains.\",\n\t\t\t\"3) Delegate: emit specialist <delegate_task> blocks for chunks that benefit from parallel execution.\",\n\t\t\t\"4) Synthesize: provide integrated results, unresolved risks, and next actions.\",\n\t\t\t\"\",\n\t\t\t\"Delegation policy:\",\n\t\t\t\"- Decide number of delegates based on task complexity (usually 1-10).\",\n\t\t\t\"- Run independent read-heavy work in parallel by emitting multiple delegate blocks.\",\n\t\t\t\"- For write-capable delegates touching overlapping areas, provide lock_key to avoid edit collisions.\",\n\t\t\t\"- Use depends_on to enforce ordering for dependent steps (for example verification after implementation).\",\n\t\t\t\"- Use clear description values and focused prompts per delegate.\",\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=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\"\",\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\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(filePath: string, cwd: string): { agent?: CustomSubagentDefinition; diagnostic?: SubagentDiagnostic } {\n\tlet content: string;\n\ttry {\n\t\tcontent = readFileSync(filePath, \"utf8\");\n\t} catch (error) {\n\t\treturn {\n\t\t\tdiagnostic: { path: filePath, message: `Failed to read file: ${error instanceof Error ? error.message : String(error)}` },\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 profile =\n\t\ttypeof frontmatter.profile === \"string\" && frontmatter.profile.trim().length > 0\n\t\t\t? (frontmatter.profile.trim() as AgentProfileName)\n\t\t\t: undefined;\n\tconst tools = asStringArray(frontmatter.tools);\n\tconst disallowedTools = asStringArray(frontmatter.disallowed_tools);\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 { diagnostic: { path: filePath, message: `Configured cwd is invalid: ${configuredCwd}` } };\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { diagnostic: { 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 { diagnostic: { path: filePath, message: \"Subagent instructions are empty.\" } };\n\t}\n\n\treturn {\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 function loadCustomSubagents(options: { cwd: string; agentDir: string }): 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 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);\n\t\t\tif (parsed.diagnostic) {\n\t\t\t\tdiagnostics.push(parsed.diagnostic);\n\t\t\t\tcontinue;\n\t\t\t}\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"]}
@@ -0,0 +1,9 @@
1
+ import type { EngineeringContract } from "../contract.js";
2
+ import type { SwarmGateResult, SwarmRunGateResult, SwarmTaskPlan, SwarmTaskRuntimeState } from "./types.js";
3
+ export declare function evaluateTaskGates(task: SwarmTaskPlan, contract: EngineeringContract): SwarmGateResult;
4
+ export declare function evaluateRunGates(input: {
5
+ taskStates: Record<string, SwarmTaskRuntimeState>;
6
+ taskGateResults: SwarmGateResult[];
7
+ contract: EngineeringContract;
8
+ }): SwarmRunGateResult;
9
+ //# sourceMappingURL=gates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gates.d.ts","sourceRoot":"","sources":["../../../src/core/swarm/gates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE5G,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,mBAAmB,GAAG,eAAe,CA4CrG;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACvC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAClD,eAAe,EAAE,eAAe,EAAE,CAAC;IACnC,QAAQ,EAAE,mBAAmB,CAAC;CAC9B,GAAG,kBAAkB,CA2BrB"}
@@ -0,0 +1,65 @@
1
+ import { isTouchInScope } from "./locks.js";
2
+ export function evaluateTaskGates(task, contract) {
3
+ const warnings = [];
4
+ const failures = [];
5
+ const checks = [];
6
+ const scopeExclude = contract.scope_exclude ?? [];
7
+ const scopeInclude = contract.scope_include ?? [];
8
+ if (scopeExclude.length > 0) {
9
+ checks.push(`scope_exclude=${scopeExclude.length}`);
10
+ for (const touch of task.touches) {
11
+ if (scopeExclude.some((scope) => isTouchInScope(touch, scope))) {
12
+ failures.push(`Touch "${touch}" is excluded by contract scope_exclude.`);
13
+ }
14
+ }
15
+ }
16
+ if (scopeInclude.length > 0) {
17
+ checks.push(`scope_include=${scopeInclude.length}`);
18
+ const allOutside = task.touches.length > 0 &&
19
+ task.touches.every((touch) => !scopeInclude.some((scope) => isTouchInScope(touch, scope)));
20
+ if (allOutside) {
21
+ warnings.push("All touches are outside scope_include. Verify contract boundaries.");
22
+ }
23
+ }
24
+ if ((contract.constraints ?? []).length > 0) {
25
+ checks.push(`constraints=${contract.constraints?.length ?? 0}`);
26
+ }
27
+ if ((contract.quality_gates ?? []).length > 0) {
28
+ checks.push(`quality_gates=${contract.quality_gates?.length ?? 0}`);
29
+ }
30
+ if ((contract.definition_of_done ?? []).length > 0) {
31
+ checks.push(`definition_of_done=${contract.definition_of_done?.length ?? 0}`);
32
+ }
33
+ return {
34
+ taskId: task.id,
35
+ pass: failures.length === 0,
36
+ warnings,
37
+ failures,
38
+ checks,
39
+ };
40
+ }
41
+ export function evaluateRunGates(input) {
42
+ const warnings = [];
43
+ const failures = [];
44
+ const tasks = Object.values(input.taskStates);
45
+ const nonDone = tasks.filter((task) => task.status !== "done");
46
+ if (nonDone.length > 0) {
47
+ failures.push(`${nonDone.length} task(s) are not done.`);
48
+ }
49
+ const failedTaskGates = input.taskGateResults.filter((result) => !result.pass);
50
+ if (failedTaskGates.length > 0) {
51
+ failures.push(`${failedTaskGates.length} task gate(s) failed.`);
52
+ }
53
+ if ((input.contract.quality_gates ?? []).length > 0) {
54
+ warnings.push("Run-gates rely on task-level checks and manual contract quality_gates confirmation.");
55
+ }
56
+ if ((input.contract.definition_of_done ?? []).length > 0) {
57
+ warnings.push("Definition of Done items should be reviewed in final integration report.");
58
+ }
59
+ return {
60
+ pass: failures.length === 0,
61
+ warnings,
62
+ failures,
63
+ };
64
+ }
65
+ //# sourceMappingURL=gates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gates.js","sourceRoot":"","sources":["../../../src/core/swarm/gates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,UAAU,iBAAiB,CAAC,IAAmB,EAAE,QAA6B;IACnF,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,IAAI,EAAE,CAAC;IAClD,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,IAAI,EAAE,CAAC;IAElD,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,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AqF,CAAC,CAAC;IACtG,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1D,QAAQ,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO;QACN,IAAI,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC;QAC3B,QAAQ;QACR,QAAQ;KACR,CAAC;AACH,CAAC","sourcesContent":["import type { EngineeringContract } from \"../contract.js\";\nimport { isTouchInScope } from \"./locks.js\";\nimport type { SwarmGateResult, SwarmRunGateResult, SwarmTaskPlan, SwarmTaskRuntimeState } from \"./types.js\";\n\nexport function evaluateTaskGates(task: SwarmTaskPlan, contract: EngineeringContract): SwarmGateResult {\n\tconst warnings: string[] = [];\n\tconst failures: string[] = [];\n\tconst checks: string[] = [];\n\n\tconst scopeExclude = contract.scope_exclude ?? [];\n\tconst scopeInclude = contract.scope_include ?? [];\n\n\tif (scopeExclude.length > 0) {\n\t\tchecks.push(`scope_exclude=${scopeExclude.length}`);\n\t\tfor (const touch of task.touches) {\n\t\t\tif (scopeExclude.some((scope) => isTouchInScope(touch, scope))) {\n\t\t\t\tfailures.push(`Touch \"${touch}\" is excluded by contract scope_exclude.`);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (scopeInclude.length > 0) {\n\t\tchecks.push(`scope_include=${scopeInclude.length}`);\n\t\tconst allOutside =\n\t\t\ttask.touches.length > 0 &&\n\t\t\ttask.touches.every((touch) => !scopeInclude.some((scope) => isTouchInScope(touch, scope)));\n\t\tif (allOutside) {\n\t\t\twarnings.push(\"All touches are outside scope_include. Verify contract boundaries.\");\n\t\t}\n\t}\n\n\tif ((contract.constraints ?? []).length > 0) {\n\t\tchecks.push(`constraints=${contract.constraints?.length ?? 0}`);\n\t}\n\tif ((contract.quality_gates ?? []).length > 0) {\n\t\tchecks.push(`quality_gates=${contract.quality_gates?.length ?? 0}`);\n\t}\n\tif ((contract.definition_of_done ?? []).length > 0) {\n\t\tchecks.push(`definition_of_done=${contract.definition_of_done?.length ?? 0}`);\n\t}\n\n\treturn {\n\t\ttaskId: task.id,\n\t\tpass: failures.length === 0,\n\t\twarnings,\n\t\tfailures,\n\t\tchecks,\n\t};\n}\n\nexport function evaluateRunGates(input: {\n\ttaskStates: Record<string, SwarmTaskRuntimeState>;\n\ttaskGateResults: SwarmGateResult[];\n\tcontract: EngineeringContract;\n}): SwarmRunGateResult {\n\tconst warnings: string[] = [];\n\tconst failures: string[] = [];\n\n\tconst tasks = Object.values(input.taskStates);\n\tconst nonDone = tasks.filter((task) => task.status !== \"done\");\n\tif (nonDone.length > 0) {\n\t\tfailures.push(`${nonDone.length} task(s) are not done.`);\n\t}\n\n\tconst failedTaskGates = input.taskGateResults.filter((result) => !result.pass);\n\tif (failedTaskGates.length > 0) {\n\t\tfailures.push(`${failedTaskGates.length} task gate(s) failed.`);\n\t}\n\n\tif ((input.contract.quality_gates ?? []).length > 0) {\n\t\twarnings.push(\"Run-gates rely on task-level checks and manual contract quality_gates confirmation.\");\n\t}\n\tif ((input.contract.definition_of_done ?? []).length > 0) {\n\t\twarnings.push(\"Definition of Done items should be reviewed in final integration report.\");\n\t}\n\n\treturn {\n\t\tpass: failures.length === 0,\n\t\twarnings,\n\t\tfailures,\n\t};\n}\n"]}
@@ -0,0 +1,9 @@
1
+ export * from "./types.js";
2
+ export * from "./locks.js";
3
+ export * from "./gates.js";
4
+ export * from "./spawn.js";
5
+ export * from "./retry.js";
6
+ export * from "./planner.js";
7
+ export * from "./scheduler.js";
8
+ export * from "./state-store.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/swarm/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from "./types.js";
2
+ export * from "./locks.js";
3
+ export * from "./gates.js";
4
+ export * from "./spawn.js";
5
+ export * from "./retry.js";
6
+ export * from "./planner.js";
7
+ export * from "./scheduler.js";
8
+ export * from "./state-store.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/swarm/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from \"./types.js\";\nexport * from \"./locks.js\";\nexport * from \"./gates.js\";\nexport * from \"./spawn.js\";\nexport * from \"./retry.js\";\nexport * from \"./planner.js\";\nexport * from \"./scheduler.js\";\nexport * from \"./state-store.js\";\n"]}
@@ -0,0 +1,21 @@
1
+ export interface LockConflict {
2
+ taskId: string;
3
+ conflictsWithTaskId: string;
4
+ touch: string;
5
+ conflictingTouch: string;
6
+ }
7
+ export declare class HierarchicalLockManager {
8
+ private readonly locksByTask;
9
+ canAcquire(taskId: string, touches: string[]): {
10
+ ok: boolean;
11
+ conflicts: LockConflict[];
12
+ };
13
+ acquire(taskId: string, touches: string[]): void;
14
+ release(taskId: string): void;
15
+ downgrade(taskId: string, touches: string[]): void;
16
+ has(taskId: string): boolean;
17
+ snapshot(): Record<string, string[]>;
18
+ }
19
+ export declare function isTouchInScope(touch: string, scope: string): boolean;
20
+ export declare function touchesConflict(a: string[], b: string[]): boolean;
21
+ //# sourceMappingURL=locks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../../src/core/swarm/locks.ts"],"names":[],"mappings":"AAyBA,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,uBAAuB;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+B;IAE3D,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,YAAY,EAAE,CAAA;KAAE;IAoBzF,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAKhD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI7B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAKlD,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5B,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;CAOpC;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAKpE;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAOjE"}
@@ -0,0 +1,93 @@
1
+ function normalizeTouch(value) {
2
+ const trimmed = value.trim().replace(/\\/g, "/").replace(/^\.\//, "");
3
+ if (!trimmed)
4
+ return "";
5
+ return trimmed.replace(/\/+/g, "/").replace(/\/$/, "");
6
+ }
7
+ function normalizePrefix(value) {
8
+ const normalized = normalizeTouch(value);
9
+ if (!normalized)
10
+ return "";
11
+ if (normalized.endsWith("/**") || normalized.endsWith("/*")) {
12
+ return normalized.replace(/\/\*\*?$/, "");
13
+ }
14
+ return normalized;
15
+ }
16
+ function overlaps(a, b) {
17
+ if (!a || !b)
18
+ return false;
19
+ const na = normalizePrefix(a);
20
+ const nb = normalizePrefix(b);
21
+ if (!na || !nb)
22
+ return false;
23
+ if (na === nb)
24
+ return true;
25
+ if (na.startsWith(`${nb}/`) || nb.startsWith(`${na}/`))
26
+ return true;
27
+ return false;
28
+ }
29
+ export class HierarchicalLockManager {
30
+ constructor() {
31
+ this.locksByTask = new Map();
32
+ }
33
+ canAcquire(taskId, touches) {
34
+ const normalizedTouches = touches.map((touch) => normalizeTouch(touch)).filter((touch) => touch.length > 0);
35
+ const conflicts = [];
36
+ for (const [existingTaskId, existingTouches] of this.locksByTask.entries()) {
37
+ if (existingTaskId === taskId)
38
+ continue;
39
+ for (const touch of normalizedTouches) {
40
+ for (const existingTouch of existingTouches) {
41
+ if (!overlaps(touch, existingTouch))
42
+ continue;
43
+ conflicts.push({
44
+ taskId,
45
+ conflictsWithTaskId: existingTaskId,
46
+ touch,
47
+ conflictingTouch: existingTouch,
48
+ });
49
+ }
50
+ }
51
+ }
52
+ return { ok: conflicts.length === 0, conflicts };
53
+ }
54
+ acquire(taskId, touches) {
55
+ const normalized = touches.map((touch) => normalizeTouch(touch)).filter((touch) => touch.length > 0);
56
+ this.locksByTask.set(taskId, normalized);
57
+ }
58
+ release(taskId) {
59
+ this.locksByTask.delete(taskId);
60
+ }
61
+ downgrade(taskId, touches) {
62
+ if (!this.locksByTask.has(taskId))
63
+ return;
64
+ this.acquire(taskId, touches);
65
+ }
66
+ has(taskId) {
67
+ return this.locksByTask.has(taskId);
68
+ }
69
+ snapshot() {
70
+ const result = {};
71
+ for (const [taskId, touches] of this.locksByTask.entries()) {
72
+ result[taskId] = [...touches];
73
+ }
74
+ return result;
75
+ }
76
+ }
77
+ export function isTouchInScope(touch, scope) {
78
+ const normalizedTouch = normalizePrefix(touch);
79
+ const normalizedScope = normalizePrefix(scope);
80
+ if (!normalizedTouch || !normalizedScope)
81
+ return false;
82
+ return normalizedTouch === normalizedScope || normalizedTouch.startsWith(`${normalizedScope}/`);
83
+ }
84
+ export function touchesConflict(a, b) {
85
+ for (const ta of a) {
86
+ for (const tb of b) {
87
+ if (overlaps(ta, tb))
88
+ return true;
89
+ }
90
+ }
91
+ return false;
92
+ }
93
+ //# sourceMappingURL=locks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locks.js","sourceRoot":"","sources":["../../../src/core/swarm/locks.ts"],"names":[],"mappings":"AAAA,SAAS,cAAc,CAAC,KAAa;IACpC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACtE,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACrC,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACzC,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,CAAC;IAC3B,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7D,OAAO,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,UAAU,CAAC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IACrC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3B,MAAM,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC,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,eAAe,KAAK,eAAe,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,eAAe,GAAG,CAAC,CAAC;AACjG,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,CAAW,EAAE,CAAW;IACvD,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;QACpB,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;YACpB,IAAI,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;gBAAE,OAAO,IAAI,CAAC;QACnC,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["function normalizeTouch(value: string): string {\n\tconst trimmed = value.trim().replace(/\\\\/g, \"/\").replace(/^\\.\\//, \"\");\n\tif (!trimmed) return \"\";\n\treturn trimmed.replace(/\\/+/g, \"/\").replace(/\\/$/, \"\");\n}\n\nfunction normalizePrefix(value: string): string {\n\tconst normalized = normalizeTouch(value);\n\tif (!normalized) return \"\";\n\tif (normalized.endsWith(\"/**\") || normalized.endsWith(\"/*\")) {\n\t\treturn normalized.replace(/\\/\\*\\*?$/, \"\");\n\t}\n\treturn normalized;\n}\n\nfunction overlaps(a: string, b: string): boolean {\n\tif (!a || !b) return false;\n\tconst na = normalizePrefix(a);\n\tconst nb = normalizePrefix(b);\n\tif (!na || !nb) return false;\n\tif (na === nb) return true;\n\tif (na.startsWith(`${nb}/`) || nb.startsWith(`${na}/`)) return true;\n\treturn false;\n}\n\nexport interface LockConflict {\n\ttaskId: string;\n\tconflictsWithTaskId: string;\n\ttouch: string;\n\tconflictingTouch: string;\n}\n\nexport class HierarchicalLockManager {\n\tprivate readonly locksByTask = new Map<string, string[]>();\n\n\tcanAcquire(taskId: string, touches: string[]): { ok: boolean; conflicts: LockConflict[] } {\n\t\tconst normalizedTouches = touches.map((touch) => normalizeTouch(touch)).filter((touch) => touch.length > 0);\n\t\tconst conflicts: LockConflict[] = [];\n\t\tfor (const [existingTaskId, existingTouches] of this.locksByTask.entries()) {\n\t\t\tif (existingTaskId === taskId) continue;\n\t\t\tfor (const touch of normalizedTouches) {\n\t\t\t\tfor (const existingTouch of existingTouches) {\n\t\t\t\t\tif (!overlaps(touch, existingTouch)) continue;\n\t\t\t\t\tconflicts.push({\n\t\t\t\t\t\ttaskId,\n\t\t\t\t\t\tconflictsWithTaskId: existingTaskId,\n\t\t\t\t\t\ttouch,\n\t\t\t\t\t\tconflictingTouch: existingTouch,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn { ok: conflicts.length === 0, conflicts };\n\t}\n\n\tacquire(taskId: string, touches: string[]): void {\n\t\tconst normalized = touches.map((touch) => normalizeTouch(touch)).filter((touch) => touch.length > 0);\n\t\tthis.locksByTask.set(taskId, normalized);\n\t}\n\n\trelease(taskId: string): void {\n\t\tthis.locksByTask.delete(taskId);\n\t}\n\n\tdowngrade(taskId: string, touches: string[]): void {\n\t\tif (!this.locksByTask.has(taskId)) return;\n\t\tthis.acquire(taskId, touches);\n\t}\n\n\thas(taskId: string): boolean {\n\t\treturn this.locksByTask.has(taskId);\n\t}\n\n\tsnapshot(): Record<string, string[]> {\n\t\tconst result: Record<string, string[]> = {};\n\t\tfor (const [taskId, touches] of this.locksByTask.entries()) {\n\t\t\tresult[taskId] = [...touches];\n\t\t}\n\t\treturn result;\n\t}\n}\n\nexport function isTouchInScope(touch: string, scope: string): boolean {\n\tconst normalizedTouch = normalizePrefix(touch);\n\tconst normalizedScope = normalizePrefix(scope);\n\tif (!normalizedTouch || !normalizedScope) return false;\n\treturn normalizedTouch === normalizedScope || normalizedTouch.startsWith(`${normalizedScope}/`);\n}\n\nexport function touchesConflict(a: string[], b: string[]): boolean {\n\tfor (const ta of a) {\n\t\tfor (const tb of b) {\n\t\t\tif (overlaps(ta, tb)) return true;\n\t\t}\n\t}\n\treturn false;\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import type { EngineeringContract } from "../contract.js";
2
+ import type { SingularAnalysisResult, SingularOption } from "../singular.js";
3
+ import type { ProjectIndex } from "../project-index/types.js";
4
+ import type { SwarmPlan } from "./types.js";
5
+ export declare function buildSwarmPlanFromTask(input: {
6
+ request: string;
7
+ contract: EngineeringContract;
8
+ index: ProjectIndex;
9
+ }): SwarmPlan;
10
+ export declare function buildSwarmPlanFromSingular(input: {
11
+ analysis: SingularAnalysisResult;
12
+ option: SingularOption;
13
+ contract: EngineeringContract;
14
+ index: ProjectIndex;
15
+ }): SwarmPlan;
16
+ //# sourceMappingURL=planner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../../../src/core/swarm/planner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,YAAY,CAAC;AA8E3D,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,KAAK,EAAE,YAAY,CAAC;CACpB,GAAG,SAAS,CAwCZ;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IACjD,QAAQ,EAAE,sBAAsB,CAAC;IACjC,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,KAAK,EAAE,YAAY,CAAC;CACpB,GAAG,SAAS,CAkEZ"}
@@ -0,0 +1,137 @@
1
+ import { queryProjectIndex } from "../project-index/index.js";
2
+ function toTaskId(index) {
3
+ return `task_${index + 1}`;
4
+ }
5
+ function compact(values) {
6
+ return [...new Set(values.map((value) => value.trim()).filter((value) => value.length > 0))];
7
+ }
8
+ function inferConcurrencyClass(brief, touches) {
9
+ const lower = `${brief} ${touches.join(" ")}`.toLowerCase();
10
+ if (/(test|spec|verification|verify|qa)/.test(lower))
11
+ return "verification";
12
+ if (/(doc|readme|changelog)/.test(lower))
13
+ return "docs";
14
+ if (/(analysis|audit|map|scope)/.test(lower))
15
+ return "analysis";
16
+ if (/(implement|refactor|patch|change|rewrite)/.test(lower))
17
+ return "implementation";
18
+ return "default";
19
+ }
20
+ function deriveScopes(contract, touches) {
21
+ if ((contract.scope_include ?? []).length > 0) {
22
+ return compact(contract.scope_include ?? []);
23
+ }
24
+ const scopes = touches
25
+ .map((touch) => touch.replace(/^\.\//, "").split("/").slice(0, 2).join("/"))
26
+ .filter((value) => value.length > 0)
27
+ .map((value) => `${value}/**`);
28
+ return compact(scopes).slice(0, 8);
29
+ }
30
+ function spreadTouches(touches, index) {
31
+ if (touches.length === 0)
32
+ return [];
33
+ const start = index % touches.length;
34
+ const result = [];
35
+ for (let offset = 0; offset < Math.min(3, touches.length); offset += 1) {
36
+ result.push(touches[(start + offset) % touches.length] ?? touches[0]);
37
+ }
38
+ return compact(result);
39
+ }
40
+ function deriveDiffPredictionTouches(index, querySeeds, limit = 12) {
41
+ const touches = [];
42
+ for (const seed of querySeeds) {
43
+ if (!seed || seed.trim().length === 0)
44
+ continue;
45
+ const matches = queryProjectIndex(index, seed, Math.max(4, Math.floor(limit / 2))).matches;
46
+ for (const entry of matches) {
47
+ touches.push(entry.path);
48
+ if (touches.length >= limit) {
49
+ return compact(touches).slice(0, limit);
50
+ }
51
+ }
52
+ }
53
+ return compact(touches).slice(0, limit);
54
+ }
55
+ function buildTask(index, brief, touches, scopes, dependsOn, severity = "medium") {
56
+ const taskTouches = compact(touches).slice(0, 8);
57
+ return {
58
+ id: toTaskId(index),
59
+ brief,
60
+ depends_on: compact(dependsOn),
61
+ scopes: compact(scopes),
62
+ touches: taskTouches,
63
+ concurrency_class: inferConcurrencyClass(brief, taskTouches),
64
+ severity,
65
+ needs_user_input: false,
66
+ model_hint: "default",
67
+ spawn_policy: severity === "high" ? "manual_high_risk" : "allow",
68
+ };
69
+ }
70
+ export function buildSwarmPlanFromTask(input) {
71
+ const matches = queryProjectIndex(input.index, input.request, 12).matches;
72
+ const diffPredictionTouches = deriveDiffPredictionTouches(input.index, [
73
+ input.request,
74
+ `implement ${input.request}`,
75
+ `refactor ${input.request}`,
76
+ `verify ${input.request}`,
77
+ ]);
78
+ const touches = compact([...matches.map((entry) => entry.path), ...diffPredictionTouches]).slice(0, 12);
79
+ const scopes = deriveScopes(input.contract, touches.length > 0 ? touches : ["src/**", "test/**"]);
80
+ const tasks = [
81
+ buildTask(0, `Map scope and baseline risks for: ${input.request}`, spreadTouches(touches, 0), scopes, [], "low"),
82
+ buildTask(1, `Implement change for: ${input.request}`, spreadTouches(touches, 1), scopes, [toTaskId(0)], "high"),
83
+ buildTask(2, `Verify behavior and quality gates for: ${input.request}`, spreadTouches(touches, 2), scopes, [toTaskId(1)], "medium"),
84
+ ];
85
+ if ((input.contract.definition_of_done ?? []).length > 0 || (input.contract.quality_gates ?? []).length > 0) {
86
+ tasks.push(buildTask(3, "Finalize integration report and contract gate checklist.", spreadTouches(touches, 3), scopes, [toTaskId(2)], "medium"));
87
+ }
88
+ return {
89
+ source: "plain",
90
+ request: input.request,
91
+ tasks,
92
+ notes: [
93
+ "Plan built from plain-language task and Project Index signals.",
94
+ `candidate_files=${touches.length}`,
95
+ `diff_prediction_candidates=${diffPredictionTouches.length}`,
96
+ ],
97
+ };
98
+ }
99
+ export function buildSwarmPlanFromSingular(input) {
100
+ const optionTouches = compact(input.option.suggested_files);
101
+ const fallbackTouches = queryProjectIndex(input.index, `${input.analysis.request} ${input.option.title}`, 12).matches.map((entry) => entry.path);
102
+ const diffPredictionTouches = deriveDiffPredictionTouches(input.index, [
103
+ input.analysis.request,
104
+ input.option.title,
105
+ input.option.summary,
106
+ ...input.option.plan.slice(0, 6),
107
+ ...input.option.pros.slice(0, 3),
108
+ ...input.option.cons.slice(0, 3),
109
+ ], 14);
110
+ const touches = compact([
111
+ ...(optionTouches.length > 0 ? optionTouches : fallbackTouches),
112
+ ...diffPredictionTouches,
113
+ ]).slice(0, 14);
114
+ const scopes = deriveScopes(input.contract, touches.length > 0 ? touches : ["src/**", "test/**"]);
115
+ const steps = input.option.plan.length > 0
116
+ ? input.option.plan
117
+ : [`Implement option ${input.option.id}: ${input.option.title}`];
118
+ const tasks = steps.map((step, index) => buildTask(index, step, spreadTouches(touches, index), scopes, index === 0 ? [] : [toTaskId(index - 1)], index === 0 ? "medium" : index === steps.length - 1 ? "medium" : "high"));
119
+ if (tasks.length === 0) {
120
+ tasks.push(buildTask(0, `Execute selected singular option: ${input.option.title}`, touches, scopes, [], "high"));
121
+ }
122
+ const finalTaskId = toTaskId(tasks.length);
123
+ tasks.push(buildTask(tasks.length, "Run final task gates and prepare integration handoff artifact.", spreadTouches(touches, tasks.length), scopes, [tasks[tasks.length - 1].id], "medium"));
124
+ return {
125
+ source: "singular",
126
+ request: input.analysis.request,
127
+ tasks,
128
+ notes: [
129
+ `singular_run_id=${input.analysis.runId}`,
130
+ `option=${input.option.id}`,
131
+ `option_title=${input.option.title}`,
132
+ `final_task_id=${finalTaskId}`,
133
+ `diff_prediction_candidates=${diffPredictionTouches.length}`,
134
+ ],
135
+ };
136
+ }
137
+ //# sourceMappingURL=planner.js.map