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,407 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Project Capability Snapshot
4
+ *
5
+ * Detects stacks, domains, and work surfaces from repo structure.
6
+ * Used by the lead agent's skill resolution prefilter.
7
+ *
8
+ * Usage:
9
+ * node scripts/project-capability-snapshot.mjs [--dir /path] [--output path]
10
+ *
11
+ * If --dir is omitted, uses current working directory.
12
+ * If --output is omitted, prints JSON to stdout.
13
+ */
14
+
15
+ import fs from "node:fs";
16
+ import path from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+
19
+ // ── Directories to always skip ──────────────────────────────────────────
20
+
21
+ const SKIP_DIRS = new Set([
22
+ "node_modules",
23
+ ".git",
24
+ ".next",
25
+ ".nuxt",
26
+ "dist",
27
+ "build",
28
+ ".cache",
29
+ "__pycache__",
30
+ ".venv",
31
+ "coverage",
32
+ ".turbo",
33
+ ".vercel",
34
+ ]);
35
+
36
+ // ── Stack detection rules ───────────────────────────────────────────────
37
+
38
+ const STACK_RULES = [
39
+ { file: "package.json", id: "node", confidence: "high" },
40
+ { file: "tsconfig.json", id: "typescript", confidence: "high" },
41
+ { file: "next.config.mjs", id: "nextjs", confidence: "high" },
42
+ { file: "next.config.js", id: "nextjs", confidence: "high" },
43
+ { file: "next.config.ts", id: "nextjs", confidence: "high" },
44
+ { file: "vite.config.mjs", id: "node", confidence: "medium" },
45
+ { file: "vite.config.js", id: "node", confidence: "medium" },
46
+ { file: "vite.config.ts", id: "typescript", confidence: "medium" },
47
+ { file: "pubspec.yaml", id: "flutter", confidence: "high" },
48
+ { file: "go.mod", id: "go", confidence: "high" },
49
+ { file: "Cargo.toml", id: "rust", confidence: "high" },
50
+ { file: "pyproject.toml", id: "python", confidence: "high" },
51
+ { file: "requirements.txt", id: "python", confidence: "medium" },
52
+ { file: "poetry.lock", id: "python", confidence: "high" },
53
+ { file: "manage.py", id: "python", confidence: "medium" },
54
+ { file: "Gemfile", id: "ruby", confidence: "high" },
55
+ { file: "composer.json", id: "php", confidence: "high" },
56
+ { file: "pom.xml", id: "java", confidence: "high" },
57
+ { file: "Dockerfile", id: "infra", confidence: "medium" },
58
+ ];
59
+
60
+ // ── Domain detection rules (directory/file patterns) ────────────────────
61
+
62
+ const DOMAIN_RULES = [
63
+ {
64
+ id: "orchestration",
65
+ confidence: "high",
66
+ globs: ["agents/*.md", "docs/ai/harness/**", "skills/**/SKILL.md"],
67
+ },
68
+ {
69
+ id: "documentation",
70
+ confidence: "high",
71
+ globs: ["docs/**/*.md", "docs/decisions/**", "docs/adr/**", "ADR*.md"],
72
+ },
73
+ {
74
+ id: "testing",
75
+ confidence: "high",
76
+ globs: ["**/*.test.*", "**/*.spec.*", "**/__tests__/**"],
77
+ },
78
+ {
79
+ id: "specification",
80
+ confidence: "high",
81
+ globs: ["docs/ai/specs/**"],
82
+ },
83
+ {
84
+ id: "security",
85
+ confidence: "medium",
86
+ globs: ["**/*security*", "**/*security*/**/*", "**/*auth*", "**/*auth*/**/*"],
87
+ },
88
+ {
89
+ id: "api-design",
90
+ confidence: "medium",
91
+ globs: ["**/routes/**", "**/api/**", "**/endpoints/**", "**/controllers/**"],
92
+ },
93
+ {
94
+ id: "ui-ux",
95
+ confidence: "medium",
96
+ globs: ["**/components/**", "**/pages/**", "**/views/**", "**/ui/**"],
97
+ },
98
+ {
99
+ id: "evolution",
100
+ confidence: "high",
101
+ globs: ["docs/ai/evolution/**"],
102
+ },
103
+ {
104
+ id: "debugging",
105
+ confidence: "medium",
106
+ globs: ["**/*debug*", "**/*debug*/**/*", "**/diagnostics/**"],
107
+ },
108
+ {
109
+ id: "release",
110
+ confidence: "medium",
111
+ globs: [".github/workflows/**", "**/releases/**", "**/changelog*"],
112
+ },
113
+ ];
114
+
115
+ // ── Surface detection rules ─────────────────────────────────────────────
116
+
117
+ const SURFACE_RULES = [
118
+ {
119
+ id: "harness",
120
+ confidence: "high",
121
+ globs: ["AGENTS.md", "docs/ai/harness/**", "scripts/check-harness*"],
122
+ },
123
+ {
124
+ id: "skills-catalog",
125
+ confidence: "high",
126
+ globs: ["skills/**/SKILL.md", "scripts/update-skill-registry*"],
127
+ },
128
+ {
129
+ id: "automation",
130
+ confidence: "medium",
131
+ globs: ["scripts/**"],
132
+ },
133
+ {
134
+ id: "monorepo",
135
+ confidence: "medium",
136
+ globs: ["apps/**", "packages/**"],
137
+ },
138
+ ];
139
+
140
+ // ── Helpers ─────────────────────────────────────────────────────────────
141
+
142
+ /**
143
+ * Recursively walk a directory, respecting skip rules and depth limit.
144
+ * Returns relative paths of all files found.
145
+ */
146
+ function walkDir(root, relDir, maxDepth = 6, currentDepth = 0) {
147
+ if (currentDepth > maxDepth) return [];
148
+
149
+ const absDir = path.join(root, relDir);
150
+ let entries;
151
+ try {
152
+ entries = fs.readdirSync(absDir, { withFileTypes: true });
153
+ } catch {
154
+ return [];
155
+ }
156
+
157
+ const files = [];
158
+ for (const entry of entries) {
159
+ if (entry.isDirectory()) {
160
+ if (SKIP_DIRS.has(entry.name)) continue;
161
+ const childRel = relDir ? `${relDir}/${entry.name}` : entry.name;
162
+ files.push(...walkDir(root, childRel, maxDepth, currentDepth + 1));
163
+ } else {
164
+ const rel = relDir ? `${relDir}/${entry.name}` : entry.name;
165
+ files.push(rel);
166
+ }
167
+ }
168
+ return files;
169
+ }
170
+
171
+ /**
172
+ * Simple glob-to-regex converter for the limited patterns we use.
173
+ * Supports: **, *, ?, and literal paths.
174
+ */
175
+ function globToRegex(glob) {
176
+ let re = "";
177
+ let i = 0;
178
+
179
+ while (i < glob.length) {
180
+ if (glob[i] === "*" && glob[i + 1] === "*") {
181
+ // ** matches any number of path segments
182
+ if (glob[i + 2] === "/") {
183
+ // **/ matches zero or more segments followed by /
184
+ re += "(?:[^/]+/)*";
185
+ i += 3;
186
+ } else if (i + 2 >= glob.length) {
187
+ // ** at end matches everything
188
+ re += ".*";
189
+ i += 2;
190
+ } else {
191
+ // ** between chars (rare) — match anything
192
+ re += ".*";
193
+ i += 2;
194
+ }
195
+ } else if (glob[i] === "*") {
196
+ // * matches within a single segment
197
+ re += "[^/]*";
198
+ i += 1;
199
+ } else if (glob[i] === "?") {
200
+ re += "[^/]";
201
+ i += 1;
202
+ } else if (glob[i] === ".") {
203
+ re += "\\.";
204
+ i += 1;
205
+ } else if ("+^${}()|[\\".includes(glob[i])) {
206
+ re += "\\" + glob[i];
207
+ i += 1;
208
+ } else {
209
+ re += glob[i];
210
+ i += 1;
211
+ }
212
+ }
213
+
214
+ return new RegExp("^" + re + "$");
215
+ }
216
+
217
+ /**
218
+ * Check if any file in the repo matches any of the given glob patterns.
219
+ * Returns matched file paths (relative to repo root).
220
+ */
221
+ function matchGlobs(files, globs) {
222
+ const matched = [];
223
+ const regexes = globs.map((g) => ({ glob: g, re: globToRegex(g) }));
224
+
225
+ for (const file of files) {
226
+ for (const { glob, re } of regexes) {
227
+ if (re.test(file)) {
228
+ matched.push(file);
229
+ break;
230
+ }
231
+ }
232
+ }
233
+ return matched;
234
+ }
235
+
236
+ // ── Detection functions ─────────────────────────────────────────────────
237
+
238
+ export function detectStacks(repoRoot) {
239
+ const files = walkDir(repoRoot, "");
240
+ const detected = [];
241
+ const seen = new Map();
242
+
243
+ for (const rule of STACK_RULES) {
244
+ const matches = matchGlobs(files, [rule.file]);
245
+ if (matches.length > 0) {
246
+ const existing = seen.get(rule.id);
247
+ if (!existing) {
248
+ const entry = {
249
+ id: rule.id,
250
+ confidence: rule.confidence,
251
+ evidence: matches,
252
+ };
253
+ detected.push(entry);
254
+ seen.set(rule.id, entry);
255
+ } else {
256
+ // Merge evidence and keep highest confidence
257
+ existing.evidence.push(...matches);
258
+ existing.evidence = [...new Set(existing.evidence)];
259
+ if (rule.confidence === "high" && existing.confidence !== "high") {
260
+ existing.confidence = "high";
261
+ }
262
+ }
263
+ }
264
+ }
265
+
266
+ return detected;
267
+ }
268
+
269
+ export function detectDomains(repoRoot) {
270
+ const files = walkDir(repoRoot, "");
271
+ const byDomain = new Map();
272
+
273
+ for (const rule of DOMAIN_RULES) {
274
+ const matches = matchGlobs(files, rule.globs);
275
+ if (matches.length > 0) {
276
+ const existing = byDomain.get(rule.id);
277
+ if (!existing) {
278
+ byDomain.set(rule.id, {
279
+ id: rule.id,
280
+ confidence: rule.confidence,
281
+ evidence: matches,
282
+ });
283
+ } else {
284
+ // Merge evidence and keep highest confidence
285
+ existing.evidence.push(...matches);
286
+ // Deduplicate evidence
287
+ existing.evidence = [...new Set(existing.evidence)];
288
+ // Upgrade confidence if needed
289
+ if (rule.confidence === "high" && existing.confidence !== "high") {
290
+ existing.confidence = "high";
291
+ }
292
+ }
293
+ }
294
+ }
295
+
296
+ return [...byDomain.values()];
297
+ }
298
+
299
+ export function detectSurfaces(repoRoot) {
300
+ const files = walkDir(repoRoot, "");
301
+ const bySurface = new Map();
302
+
303
+ for (const rule of SURFACE_RULES) {
304
+ const matches = matchGlobs(files, rule.globs);
305
+ if (matches.length > 0) {
306
+ const existing = bySurface.get(rule.id);
307
+ if (!existing) {
308
+ bySurface.set(rule.id, {
309
+ id: rule.id,
310
+ confidence: rule.confidence,
311
+ evidence: matches,
312
+ });
313
+ } else {
314
+ existing.evidence.push(...matches);
315
+ existing.evidence = [...new Set(existing.evidence)];
316
+ if (rule.confidence === "high" && existing.confidence !== "high") {
317
+ existing.confidence = "high";
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ return [...bySurface.values()];
324
+ }
325
+
326
+ export function generateSnapshot(repoRoot) {
327
+ const absRoot = path.resolve(repoRoot);
328
+
329
+ const stacks = detectStacks(absRoot);
330
+ const domains = detectDomains(absRoot);
331
+ const surfaces = detectSurfaces(absRoot);
332
+
333
+ // Determine unknowns: if all arrays are empty, note it
334
+ const unknowns = [];
335
+ if (stacks.length === 0) unknowns.push("no_stacks_detected");
336
+ if (domains.length === 0) unknowns.push("no_domains_detected");
337
+ if (surfaces.length === 0) unknowns.push("no_surfaces_detected");
338
+
339
+ return {
340
+ schema_version: 1,
341
+ repo_root: absRoot,
342
+ stacks_detected: stacks,
343
+ domains_detected: domains,
344
+ surfaces_detected: surfaces,
345
+ unknowns,
346
+ generated_by: "lead prefilter",
347
+ generated_at: new Date().toISOString(),
348
+ };
349
+ }
350
+
351
+ // ── CLI ─────────────────────────────────────────────────────────────────
352
+
353
+ function parseArgs(argv) {
354
+ const args = argv.slice(2);
355
+ let dir = process.cwd();
356
+ let output = null;
357
+
358
+ for (let i = 0; i < args.length; i++) {
359
+ if (args[i] === "--dir" && args[i + 1]) {
360
+ dir = path.resolve(args[++i]);
361
+ } else if (args[i] === "--output" && args[i + 1]) {
362
+ output = args[++i];
363
+ } else if (args[i] === "--help" || args[i] === "-h") {
364
+ console.log(
365
+ "Usage: node project-capability-snapshot.mjs [--dir /path] [--output path]\n\n" +
366
+ "Options:\n" +
367
+ " --dir <path> Repository root to analyze (default: cwd)\n" +
368
+ " --output <path> Write JSON to file instead of stdout\n" +
369
+ " -h, --help Show this help",
370
+ );
371
+ process.exit(0);
372
+ }
373
+ }
374
+
375
+ return { dir, output };
376
+ }
377
+
378
+ function main() {
379
+ const { dir, output } = parseArgs(process.argv);
380
+
381
+ if (!fs.existsSync(dir)) {
382
+ console.error(`Error: directory does not exist: ${dir}`);
383
+ process.exit(1);
384
+ }
385
+
386
+ const snapshot = generateSnapshot(dir);
387
+ const json = JSON.stringify(snapshot, null, 2);
388
+
389
+ if (output) {
390
+ const outDir = path.dirname(output);
391
+ if (!fs.existsSync(outDir)) {
392
+ fs.mkdirSync(outDir, { recursive: true });
393
+ }
394
+ fs.writeFileSync(output, json + "\n");
395
+ } else {
396
+ console.log(json);
397
+ }
398
+ }
399
+
400
+ // Run CLI when invoked directly (not imported as module)
401
+ const isMainModule =
402
+ process.argv[1] &&
403
+ path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
404
+
405
+ if (isMainModule) {
406
+ main();
407
+ }