opencode-agent-orchestration-kit 1.0.27

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 (236) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.yml +65 -0
  3. package/.github/ISSUE_TEMPLATE/config.yml +11 -0
  4. package/.github/ISSUE_TEMPLATE/documentation.yml +22 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.yml +43 -0
  6. package/.github/PULL_REQUEST_TEMPLATE.md +25 -0
  7. package/.github/workflows/check.yml +47 -0
  8. package/CODE_OF_CONDUCT.md +24 -0
  9. package/CONTRIBUTING.md +52 -0
  10. package/LICENSE +201 -0
  11. package/NOTICE.md +23 -0
  12. package/README.md +806 -0
  13. package/SECURITY.md +17 -0
  14. package/docker/open-design/.env.example +6 -0
  15. package/docker/open-design/Dockerfile +50 -0
  16. package/docker/open-design/docker-compose.yml +18 -0
  17. package/docker/open-design/opencode-od/agents/od-worker.md +22 -0
  18. package/docker/open-design/opencode-od/opencode.json +24 -0
  19. package/docs/agents.md +21 -0
  20. package/docs/commands.md +16 -0
  21. package/docs/configuration.md +30 -0
  22. package/docs/docker-open-design.md +42 -0
  23. package/docs/impeccable.md +18 -0
  24. package/docs/installation.md +176 -0
  25. package/docs/models.md +17 -0
  26. package/docs/open-design.md +25 -0
  27. package/docs/quickstart.md +74 -0
  28. package/docs/releases/v1.0.10.md +46 -0
  29. package/docs/releases/v1.0.14.md +39 -0
  30. package/docs/releases/v1.0.27.md +66 -0
  31. package/docs/security.md +8 -0
  32. package/docs/superpowers/plans/2026-07-20-safe-installation-lifecycle.md +779 -0
  33. package/docs/superpowers/plans/2026-07-20-version-identity-and-releases.md +590 -0
  34. package/docs/superpowers/specs/2026-07-20-safe-installation-lifecycle-design.md +1350 -0
  35. package/docs/superpowers/specs/2026-07-20-version-identity-and-releases-design.md +557 -0
  36. package/docs/superpowers.md +34 -0
  37. package/docs/synology.md +30 -0
  38. package/docs/troubleshooting.md +54 -0
  39. package/docs/workflows.md +44 -0
  40. package/doctor.sh +5 -0
  41. package/env.example +15 -0
  42. package/install.sh +5 -0
  43. package/opencode/AGENTS.md +104 -0
  44. package/opencode/agents/debugger.md +41 -0
  45. package/opencode/agents/designer.md +93 -0
  46. package/opencode/agents/developer.md +180 -0
  47. package/opencode/agents/evaluator.md +35 -0
  48. package/opencode/agents/evolver.md +31 -0
  49. package/opencode/agents/lead.md +251 -0
  50. package/opencode/agents/researcher.md +76 -0
  51. package/opencode/agents/review_api.md +34 -0
  52. package/opencode/agents/review_coordinator.md +111 -0
  53. package/opencode/agents/review_quality.md +35 -0
  54. package/opencode/agents/review_security.md +35 -0
  55. package/opencode/agents/review_tests.md +37 -0
  56. package/opencode/agents/reviewer.md +116 -0
  57. package/opencode/agents/scoper.md +75 -0
  58. package/opencode/agents/specifier.md +116 -0
  59. package/opencode/commands/code-simplify.md +36 -0
  60. package/opencode/commands/design.md +27 -0
  61. package/opencode/commands/evolve.md +165 -0
  62. package/opencode/commands/feature.md +67 -0
  63. package/opencode/commands/implement.md +11 -0
  64. package/opencode/commands/init.md +34 -0
  65. package/opencode/commands/loop.md +145 -0
  66. package/opencode/commands/mvp-spec.md +20 -0
  67. package/opencode/commands/plan.md +74 -0
  68. package/opencode/commands/research.md +12 -0
  69. package/opencode/commands/review-orchestrated.md +47 -0
  70. package/opencode/commands/review-preflight.md +26 -0
  71. package/opencode/commands/review.md +18 -0
  72. package/opencode/commands/scope.md +36 -0
  73. package/opencode/commands/spec.md +12 -0
  74. package/opencode/commands/test.md +40 -0
  75. package/opencode/docs/ai/evolution/README.md +135 -0
  76. package/opencode/docs/ai/evolution/benchmarks/manual-scenarios.md +123 -0
  77. package/opencode/docs/ai/evolution/benchmarks/router-scenarios.jsonl +8 -0
  78. package/opencode/docs/ai/evolution/evolution_history.md +83 -0
  79. package/opencode/docs/ai/evolution/mechanisms.jsonl +7 -0
  80. package/opencode/docs/ai/evolution/rejected_mechanisms.jsonl +2 -0
  81. package/opencode/docs/ai/evolution/runs/README.md +15 -0
  82. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/analysis/overview.md +12 -0
  83. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_evaluation.json +108 -0
  84. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_manifest.json +52 -0
  85. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/evaluation.md +19 -0
  86. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/post_evaluation.md +12 -0
  87. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/analysis/overview.md +7 -0
  88. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/change_evaluation.json +31 -0
  89. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/evaluation.md +19 -0
  90. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/analysis/overview.md +13 -0
  91. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_evaluation.json +66 -0
  92. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_manifest.json +82 -0
  93. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/evaluation.md +20 -0
  94. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/ahe-run-lifecycle-validator.md +40 -0
  95. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/evolve-evaluation-only-contract.md +15 -0
  96. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/open-design-tool-contract.md +14 -0
  97. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/slash-command-contract-coverage.md +40 -0
  98. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/overview.md +17 -0
  99. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/pre_apply_approval.md +15 -0
  100. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_evaluation.json +252 -0
  101. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_manifest.json +210 -0
  102. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/evaluation.md +25 -0
  103. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_apply_evaluation.md +15 -0
  104. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_manifest_evaluation.md +14 -0
  105. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/pre_apply_evaluation.md +15 -0
  106. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/analysis/overview.md +13 -0
  107. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_evaluation.json +14 -0
  108. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_manifest.json +30 -0
  109. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/evaluation.md +25 -0
  110. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/analysis/overview.md +13 -0
  111. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_evaluation.json +14 -0
  112. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_manifest.json +29 -0
  113. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/evaluation.md +18 -0
  114. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/analysis/overview.md +13 -0
  115. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_evaluation.json +14 -0
  116. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_manifest.json +34 -0
  117. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/evaluation.md +17 -0
  118. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/analysis/overview.md +13 -0
  119. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_evaluation.json +12 -0
  120. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_manifest.json +28 -0
  121. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/evaluation.md +17 -0
  122. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/analysis/overview.md +9 -0
  123. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_evaluation.json +14 -0
  124. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_manifest.json +31 -0
  125. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/evaluation.md +18 -0
  126. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/analysis/overview.md +12 -0
  127. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_evaluation.json +14 -0
  128. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_manifest.json +31 -0
  129. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/evaluation.md +17 -0
  130. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/analysis/overview.md +10 -0
  131. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_evaluation.json +14 -0
  132. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_manifest.json +30 -0
  133. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/evaluation.md +17 -0
  134. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/analysis/overview.md +25 -0
  135. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_evaluation.json +28 -0
  136. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_manifest.json +31 -0
  137. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/evaluation.md +22 -0
  138. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/analysis/overview.md +27 -0
  139. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_evaluation.json +32 -0
  140. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_manifest.json +49 -0
  141. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/evaluation.md +92 -0
  142. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/detail/token-vs-semantic.md +31 -0
  143. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/overview.md +14 -0
  144. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/evaluation.md +36 -0
  145. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/analysis/overview.md +13 -0
  146. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_evaluation.json +31 -0
  147. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_manifest.json +47 -0
  148. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/evaluation.md +27 -0
  149. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/analysis/overview.md +32 -0
  150. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_evaluation.json +31 -0
  151. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_manifest.json +35 -0
  152. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/evaluation.md +31 -0
  153. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-1-feature-sidecar-false-positive.md +51 -0
  154. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-2-checker-time-budget.md +52 -0
  155. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/overview.md +99 -0
  156. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_evaluation.json +61 -0
  157. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_manifest.json +61 -0
  158. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/evaluation.md +448 -0
  159. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/detail/intake-gray-zone.md +65 -0
  160. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/overview.md +172 -0
  161. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/evaluation.md +226 -0
  162. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/detail/plan-only-gray-zone.md +62 -0
  163. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/overview.md +167 -0
  164. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/evaluation.md +163 -0
  165. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/analysis/overview.md +42 -0
  166. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_evaluation.json +46 -0
  167. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_manifest.json +57 -0
  168. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/evaluation.md +48 -0
  169. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/contract-vs-runtime-gap.md +163 -0
  170. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/evidence-collection-blocker.md +134 -0
  171. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/overview.md +111 -0
  172. package/opencode/docs/ai/evolution/runs/iteration-021/change_evaluation.json +52 -0
  173. package/opencode/docs/ai/evolution/runs/iteration-021/change_manifest.json +50 -0
  174. package/opencode/docs/ai/evolution/runs/iteration-021/evaluation.md +46 -0
  175. package/opencode/docs/ai/evolution/runs/iteration-021/manifest-justification.md +48 -0
  176. package/opencode/docs/ai/evolution/session-sources.md +91 -0
  177. package/opencode/docs/ai/harness/README.md +32 -0
  178. package/opencode/docs/ai/harness/agents.md +148 -0
  179. package/opencode/docs/ai/harness/checks.md +119 -0
  180. package/opencode/docs/ai/harness/commands.md +391 -0
  181. package/opencode/docs/ai/harness/evidence.md +85 -0
  182. package/opencode/docs/ai/harness/init-detection-rules.md +160 -0
  183. package/opencode/docs/ai/harness/orchestrated-review.md +131 -0
  184. package/opencode/docs/ai/harness/skill-metadata-schema.md +198 -0
  185. package/opencode/docs/ai/harness/skill-resolution.md +202 -0
  186. package/opencode/docs/ai/harness/skill_registry.json +443 -0
  187. package/opencode/docs/ai/harness/skill_registry.md +43 -0
  188. package/opencode/docs/ai/project-context-template.md +53 -0
  189. package/opencode/opencode.json +38 -0
  190. package/opencode/package-lock.json +1717 -0
  191. package/opencode/package.json +11 -0
  192. package/opencode/plugins/token-tree-usage.tsx +206 -0
  193. package/opencode/references/performance-checklist.md +153 -0
  194. package/opencode/references/security-checklist.md +134 -0
  195. package/opencode/references/testing-patterns.md +236 -0
  196. package/opencode/scripts/check-harness.mjs +1572 -0
  197. package/opencode/scripts/check-harness.test.mjs +820 -0
  198. package/opencode/scripts/collect-session-evidence.mjs +612 -0
  199. package/opencode/scripts/collect-session-evidence.test.mjs +443 -0
  200. package/opencode/scripts/preflight-audit.mjs +497 -0
  201. package/opencode/scripts/preflight-audit.test.mjs +363 -0
  202. package/opencode/scripts/project-capability-snapshot.mjs +407 -0
  203. package/opencode/scripts/project-capability-snapshot.test.mjs +382 -0
  204. package/opencode/scripts/review-orchestrated-prepare.mjs +547 -0
  205. package/opencode/scripts/review-orchestrated-prepare.test.mjs +516 -0
  206. package/opencode/scripts/skill-resolver.mjs +585 -0
  207. package/opencode/scripts/skill-resolver.test.mjs +781 -0
  208. package/opencode/scripts/update-skill-registry.mjs +380 -0
  209. package/opencode/skills/api-and-interface-design/SKILL.md +315 -0
  210. package/opencode/skills/autonomous-loops/SKILL.md +312 -0
  211. package/opencode/skills/code-review-and-quality/SKILL.md +365 -0
  212. package/opencode/skills/code-simplification/SKILL.md +345 -0
  213. package/opencode/skills/context-engineering/SKILL.md +252 -0
  214. package/opencode/skills/debugging-and-error-recovery/SKILL.md +316 -0
  215. package/opencode/skills/documentation-and-adrs/SKILL.md +298 -0
  216. package/opencode/skills/doubt-driven-development/SKILL.md +168 -0
  217. package/opencode/skills/iterative-retrieval/SKILL.md +232 -0
  218. package/opencode/skills/open-design/SKILL.md +123 -0
  219. package/opencode/skills/performance-optimization/SKILL.md +365 -0
  220. package/opencode/skills/security-and-hardening/SKILL.md +369 -0
  221. package/opencode/skills/source-driven-development/SKILL.md +210 -0
  222. package/opencode/skills/test-driven-development/SKILL.md +406 -0
  223. package/opencode/skills/using-agent-skills/SKILL.md +194 -0
  224. package/opencode/skills/verification-loop/SKILL.md +162 -0
  225. package/opencode/tools/open_design.ts +361 -0
  226. package/opencode/tui.json +5 -0
  227. package/package.json +20 -0
  228. package/rollback.sh +5 -0
  229. package/scripts/check.sh +184 -0
  230. package/scripts/install-smoke.sh +111 -0
  231. package/scripts/manage-installation.mjs +1498 -0
  232. package/scripts/manage-installation.test.mjs +1936 -0
  233. package/scripts/version.mjs +197 -0
  234. package/scripts/version.test.mjs +195 -0
  235. package/uninstall.sh +5 -0
  236. package/upgrade.sh +5 -0
@@ -0,0 +1,585 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Skill Resolver — Two-stage deterministic prefilter + ranking
4
+ *
5
+ * Given a target agent, task phase, task domains, registry and project
6
+ * capability snapshot, produces a ranked shortlist of 3-8 skills with
7
+ * explanations.
8
+ *
9
+ * Usage:
10
+ * node scripts/skill-resolver.mjs --agent developer --phase build --domains testing,security
11
+ *
12
+ * Options:
13
+ * --agent <name> Target agent (required)
14
+ * --phase <phase> Task phase (default: unknown)
15
+ * --domains <list> Comma-separated domain hints (optional)
16
+ * --registry <path> Path to skill_registry.json (default: docs/ai/harness/skill_registry.json)
17
+ * --snapshot <path> Path to snapshot JSON (auto-detected if omitted)
18
+ * -h, --help Show this help
19
+ *
20
+ * Can be imported as a module:
21
+ * import { generateShortlist, formatShortlist } from './skill-resolver.mjs';
22
+ */
23
+
24
+ import fs from "node:fs";
25
+ import path from "node:path";
26
+ import { fileURLToPath } from "node:url";
27
+
28
+ // ── Constants ────────────────────────────────────────────────────────────
29
+
30
+ const MAX_CANDIDATES = 8;
31
+ const SUGGESTED_FINAL_SELECTION = 3;
32
+
33
+ const PASS_PHASES = new Set(["meta", "operate"]);
34
+
35
+ // ── Data loading ─────────────────────────────────────────────────────────
36
+
37
+ /**
38
+ * Load the skill registry from a JSON file.
39
+ * @param {string} registryPath
40
+ * @returns {{ skills: Array }}
41
+ */
42
+ export function loadRegistry(registryPath) {
43
+ const raw = fs.readFileSync(registryPath, "utf-8");
44
+ return JSON.parse(raw);
45
+ }
46
+
47
+ /**
48
+ * Load the project capability snapshot from a JSON file.
49
+ * @param {string} snapshotPath
50
+ * @returns {object|null}
51
+ */
52
+ export function loadSnapshot(snapshotPath) {
53
+ if (!snapshotPath || !fs.existsSync(snapshotPath)) return null;
54
+ const raw = fs.readFileSync(snapshotPath, "utf-8");
55
+ return JSON.parse(raw);
56
+ }
57
+
58
+ /**
59
+ * Auto-detect snapshot path by checking common locations.
60
+ * @param {string} repoRoot
61
+ * @returns {string|null}
62
+ */
63
+ function detectSnapshotPath(repoRoot) {
64
+ const candidates = [
65
+ path.join(repoRoot, "docs/ai/harness/project_capability_snapshot.json"),
66
+ path.join(repoRoot, "project_capability_snapshot.json"),
67
+ ];
68
+ for (const p of candidates) {
69
+ if (fs.existsSync(p)) return p;
70
+ }
71
+ return null;
72
+ }
73
+
74
+ // ── Filtering functions ──────────────────────────────────────────────────
75
+
76
+ /**
77
+ * Filter skills by allowed_agents.
78
+ * If skill.allowed_agents is empty/missing → include (fallback to all agents).
79
+ * @param {Array} skills
80
+ * @param {string} targetAgent
81
+ * @returns {{ passed: Array, filteredCount: number }}
82
+ */
83
+ export function filterByAgent(skills, targetAgent) {
84
+ const passed = [];
85
+ let filteredCount = 0;
86
+
87
+ for (const skill of skills) {
88
+ // Skip deprecated
89
+ if (skill.status === "deprecated") {
90
+ filteredCount++;
91
+ continue;
92
+ }
93
+
94
+ const agents = skill.allowed_agents;
95
+ if (!agents) {
96
+ // Missing allowed_agents → fallback: include for all agents
97
+ passed.push(skill);
98
+ } else if (agents.length === 0) {
99
+ // Empty array → no agents allowed → exclude
100
+ filteredCount++;
101
+ } else if (agents.includes(targetAgent)) {
102
+ passed.push(skill);
103
+ } else {
104
+ filteredCount++;
105
+ }
106
+ }
107
+
108
+ return { passed, filteredCount };
109
+ }
110
+
111
+ /**
112
+ * Filter skills by phase.
113
+ * Phase match: skill.phase === taskPhase OR skill.phase is meta/operate.
114
+ * If taskPhase is "unknown" → no filtering.
115
+ * If skill.phase is missing/unknown → don't exclude.
116
+ * @param {Array} skills
117
+ * @param {string} taskPhase
118
+ * @returns {{ passed: Array, filteredCount: number }}
119
+ */
120
+ export function filterByPhase(skills, taskPhase) {
121
+ if (taskPhase === "unknown") {
122
+ return { passed: [...skills], filteredCount: 0 };
123
+ }
124
+
125
+ const passed = [];
126
+ let filteredCount = 0;
127
+
128
+ for (const skill of skills) {
129
+ const skillPhase = skill.phase;
130
+
131
+ // No phase info → don't exclude
132
+ if (!skillPhase || skillPhase === "unknown") {
133
+ passed.push(skill);
134
+ continue;
135
+ }
136
+
137
+ // Exact match or meta/operate pass-through
138
+ if (skillPhase === taskPhase || PASS_PHASES.has(skillPhase)) {
139
+ passed.push(skill);
140
+ } else {
141
+ filteredCount++;
142
+ }
143
+ }
144
+
145
+ return { passed, filteredCount };
146
+ }
147
+
148
+ /**
149
+ * Filter skills by domains.
150
+ * Match if any of:
151
+ * - skill.domains ∩ taskDomains
152
+ * - skill.domains ∩ snapshotDomains
153
+ * - keyword match in skill.description vs taskDomains
154
+ * If no domains info available → don't filter.
155
+ * @param {Array} skills
156
+ * @param {string[]} taskDomains
157
+ * @param {string[]} snapshotDomains
158
+ * @returns {{ passed: Array, filteredCount: number }}
159
+ */
160
+ export function filterByDomains(skills, taskDomains, snapshotDomains) {
161
+ const allTaskDomains = [
162
+ ...new Set([...(taskDomains || []), ...(snapshotDomains || [])]),
163
+ ];
164
+
165
+ // If no domain signals at all, don't filter
166
+ if (allTaskDomains.length === 0) {
167
+ return { passed: [...skills], filteredCount: 0 };
168
+ }
169
+
170
+ const passed = [];
171
+ let filteredCount = 0;
172
+
173
+ for (const skill of skills) {
174
+ const skillDomains = skill.domains || [];
175
+
176
+ // No domain info on skill → fallback to description keyword match
177
+ if (skillDomains.length === 0) {
178
+ const desc = (skill.description || "").toLowerCase();
179
+ const matched = allTaskDomains.some(
180
+ (d) => desc.includes(d.toLowerCase()) || desc.includes(d.replace(/-/g, " ")),
181
+ );
182
+ if (matched) {
183
+ passed.push(skill);
184
+ } else {
185
+ filteredCount++;
186
+ }
187
+ continue;
188
+ }
189
+
190
+ // Check intersection
191
+ const hasMatch = skillDomains.some((sd) => allTaskDomains.includes(sd));
192
+ if (hasMatch) {
193
+ passed.push(skill);
194
+ } else {
195
+ filteredCount++;
196
+ }
197
+ }
198
+
199
+ return { passed, filteredCount };
200
+ }
201
+
202
+ /**
203
+ * Filter skills by stacks.
204
+ * Match if skill.stacks contains "any" OR intersects with snapshotStacks.
205
+ * If no stack info → don't filter.
206
+ * @param {Array} skills
207
+ * @param {string[]} snapshotStacks
208
+ * @returns {{ passed: Array, filteredCount: number }}
209
+ */
210
+ export function filterByStacks(skills, snapshotStacks) {
211
+ const stacks = snapshotStacks || [];
212
+
213
+ // If no snapshot stacks, don't filter
214
+ if (stacks.length === 0) {
215
+ return { passed: [...skills], filteredCount: 0 };
216
+ }
217
+
218
+ const passed = [];
219
+ let filteredCount = 0;
220
+
221
+ for (const skill of skills) {
222
+ const skillStacks = skill.stacks || [];
223
+
224
+ // No stack info → don't exclude
225
+ if (skillStacks.length === 0) {
226
+ passed.push(skill);
227
+ continue;
228
+ }
229
+
230
+ // "any" matches everything
231
+ if (skillStacks.includes("any")) {
232
+ passed.push(skill);
233
+ continue;
234
+ }
235
+
236
+ // Check intersection
237
+ const hasMatch = skillStacks.some((ss) => stacks.includes(ss));
238
+ if (hasMatch) {
239
+ passed.push(skill);
240
+ } else {
241
+ filteredCount++;
242
+ }
243
+ }
244
+
245
+ return { passed, filteredCount };
246
+ }
247
+
248
+ // ── Ranking ──────────────────────────────────────────────────────────────
249
+
250
+ /**
251
+ * Rank candidates with explainable scoring.
252
+ *
253
+ * Score breakdown:
254
+ * +3 phase match exact
255
+ * +2 per domain match (max +6)
256
+ * +1 stacks match
257
+ * +1 status === "active"
258
+ * -1 status === "experimental"
259
+ *
260
+ * @param {Array} candidates - skills that passed all filters
261
+ * @param {string} targetAgent
262
+ * @param {string} taskPhase
263
+ * @param {string[]} taskDomains
264
+ * @param {string[]} snapshotDomains
265
+ * @param {string[]} snapshotStacks
266
+ * @returns {Array} candidates with score, reasons, confidence
267
+ */
268
+ export function rankCandidates(
269
+ candidates,
270
+ targetAgent,
271
+ taskPhase,
272
+ taskDomains,
273
+ snapshotDomains,
274
+ snapshotStacks,
275
+ ) {
276
+ const allDomains = [...new Set([...(taskDomains || []), ...(snapshotDomains || [])])];
277
+
278
+ const ranked = candidates.map((skill) => {
279
+ let score = 0;
280
+ const reasons = [];
281
+
282
+ // Agent match (always true at this point, but record it)
283
+ reasons.push(`matches target_agent=${targetAgent}`);
284
+
285
+ // Phase match
286
+ const skillPhase = skill.phase;
287
+ if (skillPhase === taskPhase) {
288
+ score += 3;
289
+ reasons.push(`matches phase=${taskPhase}`);
290
+ } else if (PASS_PHASES.has(skillPhase)) {
291
+ reasons.push(`phase pass-through: ${skillPhase}`);
292
+ }
293
+
294
+ // Domain matches
295
+ const skillDomains = skill.domains || [];
296
+ const matchedDomains = skillDomains.filter((sd) => allDomains.includes(sd));
297
+ if (matchedDomains.length > 0) {
298
+ const domainScore = Math.min(matchedDomains.length * 2, 6);
299
+ score += domainScore;
300
+ reasons.push(`matches domains=${matchedDomains.join(", ")}`);
301
+ }
302
+
303
+ // Stack match
304
+ const skillStacks = skill.stacks || [];
305
+ const snapshotStackIds = (snapshotStacks || []).map((s) =>
306
+ typeof s === "string" ? s : s.id,
307
+ );
308
+ if (skillStacks.includes("any") || skillStacks.some((ss) => snapshotStackIds.includes(ss))) {
309
+ score += 1;
310
+ const matchedStack = skillStacks.includes("any")
311
+ ? "any"
312
+ : skillStacks.find((ss) => snapshotStackIds.includes(ss));
313
+ reasons.push(`stack compatible: ${matchedStack}`);
314
+ }
315
+
316
+ // Status bonus
317
+ if (skill.status === "active") {
318
+ score += 1;
319
+ reasons.push("status: active");
320
+ } else if (skill.status === "experimental") {
321
+ score -= 1;
322
+ reasons.push("status: experimental");
323
+ }
324
+
325
+ // Confidence derived from score
326
+ let confidence;
327
+ if (score >= 6) {
328
+ confidence = "high";
329
+ } else if (score >= 3) {
330
+ confidence = "medium";
331
+ } else {
332
+ confidence = "low";
333
+ }
334
+
335
+ return {
336
+ name: skill.name,
337
+ load_path: skill.load_path,
338
+ score,
339
+ reasons,
340
+ confidence,
341
+ };
342
+ });
343
+
344
+ // Sort by score desc, then alphabetically
345
+ ranked.sort((a, b) => {
346
+ if (b.score !== a.score) return b.score - a.score;
347
+ return a.name.localeCompare(b.name);
348
+ });
349
+
350
+ return ranked;
351
+ }
352
+
353
+ // ── Shortlist generation ─────────────────────────────────────────────────
354
+
355
+ /**
356
+ * Generate the full shortlist output.
357
+ * @param {object} input
358
+ * @param {string} input.targetAgent
359
+ * @param {string} input.taskPhase
360
+ * @param {string[]} input.taskDomains
361
+ * @param {object} input.registry - { skills: [...] }
362
+ * @param {object|null} input.snapshot - project capability snapshot
363
+ * @returns {object} shortlist output
364
+ */
365
+ export function generateShortlist({
366
+ targetAgent,
367
+ taskPhase = "unknown",
368
+ taskDomains = [],
369
+ registry,
370
+ snapshot = null,
371
+ }) {
372
+ const skills = registry.skills || [];
373
+
374
+ // Extract snapshot data
375
+ const snapshotStacks = snapshot
376
+ ? (snapshot.stacks_detected || []).map((s) => s.id)
377
+ : [];
378
+ const snapshotDomains = snapshot
379
+ ? (snapshot.domains_detected || []).map((s) => s.id)
380
+ : [];
381
+
382
+ // Stage A: Prefilter (in order)
383
+ const agentResult = filterByAgent(skills, targetAgent);
384
+ const phaseResult = filterByPhase(agentResult.passed, taskPhase);
385
+ const domainResult = filterByDomains(phaseResult.passed, taskDomains, snapshotDomains);
386
+ const stackResult = filterByStacks(domainResult.passed, snapshotStacks);
387
+
388
+ // Stage B: Rank
389
+ const ranked = rankCandidates(
390
+ stackResult.passed,
391
+ targetAgent,
392
+ taskPhase,
393
+ taskDomains,
394
+ snapshotDomains,
395
+ snapshotStacks,
396
+ );
397
+
398
+ // Apply max candidates limit
399
+ const candidates = ranked.slice(0, MAX_CANDIDATES);
400
+
401
+ // Build omitted summary
402
+ const totalFiltered =
403
+ agentResult.filteredCount +
404
+ phaseResult.filteredCount +
405
+ domainResult.filteredCount +
406
+ stackResult.filteredCount;
407
+
408
+ // Build recommendation guidance
409
+ let guidance;
410
+ if (candidates.length === 0) {
411
+ guidance =
412
+ "No strong matches found. Review task description and consider manual skill selection or fallback to <available_skills>.";
413
+ } else if (candidates.length <= 3) {
414
+ guidance = `Select all ${candidates.length} candidate(s) or fewer based on task priority.`;
415
+ } else {
416
+ guidance = `Select top ${SUGGESTED_FINAL_SELECTION} from ${candidates.length} candidates. Prioritize high-confidence matches.`;
417
+ }
418
+
419
+ return {
420
+ target_agent: targetAgent,
421
+ task_phase: taskPhase,
422
+ snapshot_ref: snapshot
423
+ ? snapshot.repo_root
424
+ ? `${snapshot.repo_root}/project_capability_snapshot.json`
425
+ : "auto-detected"
426
+ : "none",
427
+ candidates,
428
+ omitted_summary: {
429
+ filtered_by_agent: agentResult.filteredCount,
430
+ filtered_by_phase: phaseResult.filteredCount,
431
+ filtered_by_domain: domainResult.filteredCount,
432
+ filtered_by_stack: stackResult.filteredCount,
433
+ },
434
+ recommendation: {
435
+ suggested_final_selection: SUGGESTED_FINAL_SELECTION,
436
+ guidance,
437
+ },
438
+ };
439
+ }
440
+
441
+ // ── Formatting ───────────────────────────────────────────────────────────
442
+
443
+ /**
444
+ * Format the shortlist output as human-readable text.
445
+ * @param {object} shortlist
446
+ * @returns {string}
447
+ */
448
+ export function formatShortlist(shortlist) {
449
+ const lines = [];
450
+
451
+ lines.push("=== Skill Shortlist ===");
452
+ lines.push(`Target Agent: ${shortlist.target_agent}`);
453
+ lines.push(`Task Phase: ${shortlist.task_phase}`);
454
+ lines.push(`Snapshot: ${shortlist.snapshot_ref}`);
455
+ lines.push("");
456
+
457
+ // Candidates
458
+ lines.push(`--- Candidates (${shortlist.candidates.length}) ---`);
459
+ lines.push("");
460
+
461
+ if (shortlist.candidates.length === 0) {
462
+ lines.push(" No candidates found.");
463
+ lines.push("");
464
+ } else {
465
+ for (let i = 0; i < shortlist.candidates.length; i++) {
466
+ const c = shortlist.candidates[i];
467
+ lines.push(`${i + 1}. ${c.name} (confidence: ${c.confidence})`);
468
+ lines.push(` Load: ${c.load_path}`);
469
+ lines.push(" Reasons:");
470
+ for (const reason of c.reasons) {
471
+ lines.push(` - "${reason}"`);
472
+ }
473
+ lines.push("");
474
+ }
475
+ }
476
+
477
+ // Omitted summary
478
+ lines.push("--- Omitted Summary ---");
479
+ const om = shortlist.omitted_summary;
480
+ lines.push(` filtered_by_agent: ${om.filtered_by_agent}`);
481
+ lines.push(` filtered_by_phase: ${om.filtered_by_phase}`);
482
+ lines.push(` filtered_by_domain: ${om.filtered_by_domain}`);
483
+ lines.push(` filtered_by_stack: ${om.filtered_by_stack}`);
484
+ lines.push("");
485
+
486
+ // Recommendation
487
+ lines.push("--- Recommendation ---");
488
+ lines.push(` suggested_final_selection: ${shortlist.recommendation.suggested_final_selection}`);
489
+ lines.push(` guidance: "${shortlist.recommendation.guidance}"`);
490
+
491
+ return lines.join("\n");
492
+ }
493
+
494
+ // ── CLI ──────────────────────────────────────────────────────────────────
495
+
496
+ function parseArgs(argv) {
497
+ const args = argv.slice(2);
498
+ const parsed = {
499
+ agent: null,
500
+ phase: "unknown",
501
+ domains: [],
502
+ registry: null,
503
+ snapshot: null,
504
+ };
505
+
506
+ for (let i = 0; i < args.length; i++) {
507
+ if (args[i] === "--agent" && args[i + 1]) {
508
+ parsed.agent = args[++i];
509
+ } else if (args[i] === "--phase" && args[i + 1]) {
510
+ parsed.phase = args[++i];
511
+ } else if (args[i] === "--domains" && args[i + 1]) {
512
+ parsed.domains = args[++i].split(",").map((d) => d.trim());
513
+ } else if (args[i] === "--registry" && args[i + 1]) {
514
+ parsed.registry = args[++i];
515
+ } else if (args[i] === "--snapshot" && args[i + 1]) {
516
+ parsed.snapshot = args[++i];
517
+ } else if (args[i] === "--help" || args[i] === "-h") {
518
+ console.log(
519
+ "Usage: node skill-resolver.mjs --agent <name> [--phase <phase>] [--domains <list>] [--registry <path>] [--snapshot <path>]\n\n" +
520
+ "Options:\n" +
521
+ " --agent <name> Target agent (required)\n" +
522
+ " --phase <phase> Task phase: meta|define|plan|build|verify|review|ship|operate|unknown (default: unknown)\n" +
523
+ " --domains <list> Comma-separated domain hints (optional)\n" +
524
+ " --registry <path> Path to skill_registry.json (default: docs/ai/harness/skill_registry.json)\n" +
525
+ " --snapshot <path> Path to capability snapshot JSON (auto-detected if omitted)\n" +
526
+ " -h, --help Show this help",
527
+ );
528
+ process.exit(0);
529
+ }
530
+ }
531
+
532
+ return parsed;
533
+ }
534
+
535
+ function main() {
536
+ const parsed = parseArgs(process.argv);
537
+
538
+ if (!parsed.agent) {
539
+ console.error("Error: --agent is required. Use --help for usage.");
540
+ process.exit(1);
541
+ }
542
+
543
+ // Resolve paths
544
+ const __filename = fileURLToPath(import.meta.url);
545
+ const __dirname = path.dirname(__filename);
546
+ const repoRoot = path.resolve(__dirname, "..");
547
+
548
+ const registryPath = parsed.registry
549
+ ? path.resolve(parsed.registry)
550
+ : path.join(repoRoot, "docs/ai/harness/skill_registry.json");
551
+
552
+ const snapshotPath = parsed.snapshot
553
+ ? path.resolve(parsed.snapshot)
554
+ : detectSnapshotPath(repoRoot);
555
+
556
+ // Load data
557
+ if (!fs.existsSync(registryPath)) {
558
+ console.error(`Error: registry not found: ${registryPath}`);
559
+ process.exit(1);
560
+ }
561
+
562
+ const registry = loadRegistry(registryPath);
563
+ const snapshot = snapshotPath ? loadSnapshot(snapshotPath) : null;
564
+
565
+ // Generate shortlist
566
+ const shortlist = generateShortlist({
567
+ targetAgent: parsed.agent,
568
+ taskPhase: parsed.phase,
569
+ taskDomains: parsed.domains,
570
+ registry,
571
+ snapshot,
572
+ });
573
+
574
+ // Output
575
+ console.log(formatShortlist(shortlist));
576
+ }
577
+
578
+ // Run CLI when invoked directly
579
+ const isMainModule =
580
+ process.argv[1] &&
581
+ path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
582
+
583
+ if (isMainModule) {
584
+ main();
585
+ }