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,380 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const root = path.resolve(__dirname, "..");
8
+
9
+ // Paths
10
+ const registryMdRel = "docs/ai/harness/skill_registry.md";
11
+ const registryJsonRel = "docs/ai/harness/skill_registry.json";
12
+ const builtInSkillsDir = path.join(root, "skills");
13
+ const userSkillsDir = path.join(process.env.HOME, ".agents", "skills");
14
+
15
+ const SCHEMA_VERSION = 2;
16
+
17
+ // Header to preserve (everything before the first table)
18
+ const header = `# Skill Registry
19
+
20
+ > Generated by \`node scripts/update-skill-registry.mjs --check\`.
21
+ > Do not edit manually. Re-run the generator after adding/removing skills.
22
+
23
+ ## Purpose
24
+
25
+ The \`lead\` agent consults this registry before delegating non-trivial work. It selects 0-3 relevant skills per handoff and includes them in the \`Skill Resolution\` block. This reduces noise and saves tokens compared to injecting all skills.
26
+
27
+ ## Public package boundary
28
+
29
+ This public registry includes project skills only. User-installed skills from
30
+ \`~/.agents/skills\` are intentionally omitted from committed public artifacts.
31
+
32
+ ## Fallback
33
+
34
+ If this file is missing, \`lead\` continues using the global \`<available_skills>\` block as before. No agent should fail solely because this registry is absent.
35
+
36
+ `;
37
+
38
+ const allAgentTypes = [
39
+ "developer",
40
+ "researcher",
41
+ "designer",
42
+ "specifier",
43
+ "reviewer",
44
+ "scoper",
45
+ "lead",
46
+ ];
47
+
48
+ // ---------------------------------------------------------------------------
49
+ // Frontmatter parser — enhanced to handle YAML arrays
50
+ // ---------------------------------------------------------------------------
51
+
52
+ function parseFrontmatter(content) {
53
+ if (!content.startsWith("---\n")) return {};
54
+ const end = content.indexOf("\n---", 4);
55
+ if (end === -1) return {};
56
+ const lines = content.slice(4, end).split("\n");
57
+ const data = {};
58
+ let i = 0;
59
+ while (i < lines.length) {
60
+ const line = lines[i];
61
+ if (!line.trim() || /^\s/.test(line)) {
62
+ i++;
63
+ continue;
64
+ }
65
+ const match = line.match(/^([A-Za-z_][A-Za-z0-9_-]*):\s*(.*)$/);
66
+ if (!match) {
67
+ i++;
68
+ continue;
69
+ }
70
+ const key = match[1];
71
+ let value = match[2].replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1");
72
+
73
+ // Inline array: [item1, item2, item3]
74
+ const inlineArrayMatch = value.match(/^\[(.*)\]$/);
75
+ if (inlineArrayMatch) {
76
+ const inner = inlineArrayMatch[1].trim();
77
+ if (inner === "") {
78
+ data[key] = [];
79
+ } else {
80
+ data[key] = inner.split(/\s*,\s*/).map((s) =>
81
+ s.replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1").trim()
82
+ );
83
+ }
84
+ i++;
85
+ continue;
86
+ }
87
+
88
+ // Block-style array or multiline: value is empty / indicator, followed by indented lines
89
+ if (
90
+ value === "" ||
91
+ value === ">-" ||
92
+ value === ">" ||
93
+ value === "|" ||
94
+ value === "|-"
95
+ ) {
96
+ const parts = [];
97
+ // Check if next lines are block-array items (start with `- `)
98
+ const arrayItems = [];
99
+ let j = i + 1;
100
+ while (j < lines.length && /^\s+/.test(lines[j])) {
101
+ const trimmed = lines[j].trim();
102
+ if (trimmed.startsWith("- ")) {
103
+ arrayItems.push(
104
+ trimmed.slice(2).replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1").trim()
105
+ );
106
+ } else if (trimmed.startsWith("-")) {
107
+ // bare dash with no space (e.g., "-item")
108
+ arrayItems.push(
109
+ trimmed.slice(1).replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1").trim()
110
+ );
111
+ } else {
112
+ parts.push(trimmed);
113
+ }
114
+ j++;
115
+ }
116
+
117
+ if (arrayItems.length > 0) {
118
+ data[key] = arrayItems;
119
+ } else {
120
+ data[key] = parts.join(" ").trim();
121
+ }
122
+ i = j;
123
+ continue;
124
+ }
125
+
126
+ data[key] = value;
127
+ i++;
128
+ }
129
+ return data;
130
+ }
131
+
132
+ // ---------------------------------------------------------------------------
133
+ // Skill enrichment — apply fallbacks for missing fields
134
+ // ---------------------------------------------------------------------------
135
+
136
+ function coerceNull(val) {
137
+ if (val === "null" || val === "Null" || val === "NULL") return null;
138
+ return val;
139
+ }
140
+
141
+ function enrichSkill(raw, source, skillFile) {
142
+ const allowed = Array.isArray(raw.allowed_agents)
143
+ ? raw.allowed_agents
144
+ : allAgentTypes;
145
+
146
+ return {
147
+ name: raw.name || "",
148
+ description: (raw.description || "").replace(/\s+/g, " ").trim(),
149
+ source,
150
+ phase: raw.phase || "unknown",
151
+ domains: Array.isArray(raw.domains) ? raw.domains : [],
152
+ stacks: Array.isArray(raw.stacks) ? raw.stacks : ["any"],
153
+ allowed_agents: allowed,
154
+ surfaces: Array.isArray(raw.surfaces) ? raw.surfaces : [],
155
+ status: raw.status || "active",
156
+ skill_source: raw.skill_source || source,
157
+ origin: coerceNull(raw.origin) || null,
158
+ loadPath: displayPath(skillFile, source),
159
+ };
160
+ }
161
+
162
+ function displayPath(skillFile, source) {
163
+ if (source === "built-in") {
164
+ return path.relative(root, skillFile).split(path.sep).join("/");
165
+ }
166
+
167
+ const home = process.env.HOME;
168
+ if (home && skillFile.startsWith(`${home}${path.sep}`)) {
169
+ return `~/${path.relative(home, skillFile).split(path.sep).join("/")}`;
170
+ }
171
+
172
+ return skillFile.split(path.sep).join("/");
173
+ }
174
+
175
+ // ---------------------------------------------------------------------------
176
+ // Scanner
177
+ // ---------------------------------------------------------------------------
178
+
179
+ function scanSkills(dir, source) {
180
+ if (!fs.existsSync(dir)) return [];
181
+ const skills = [];
182
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
183
+ for (const entry of entries) {
184
+ if (!entry.isDirectory()) continue;
185
+ const skillFile = path.join(dir, entry.name, "SKILL.md");
186
+ if (!fs.existsSync(skillFile)) continue;
187
+ const content = fs.readFileSync(skillFile, "utf8");
188
+ const raw = parseFrontmatter(content);
189
+ if (!raw.name) continue;
190
+ skills.push(enrichSkill(raw, source, skillFile));
191
+ }
192
+ return skills.sort((left, right) => left.name.localeCompare(right.name));
193
+ }
194
+
195
+ // ---------------------------------------------------------------------------
196
+ // Markdown table generation — enriched columns
197
+ // ---------------------------------------------------------------------------
198
+
199
+ function truncate(str, maxLen) {
200
+ if (str.length <= maxLen) return str;
201
+ return str.slice(0, maxLen - 1) + "\u2026";
202
+ }
203
+
204
+ function escapeCell(str) {
205
+ return str.replace(/\|/g, "\\|").replace(/\n/g, " ");
206
+ }
207
+
208
+ function generateTable(skills) {
209
+ const headerRow =
210
+ "| Skill | Source | Phase | Domains | Stacks | Allowed Agents | Status | Trigger Summary | Load Path |";
211
+ const separatorRow =
212
+ "| --- | --- | --- | --- | --- | --- | --- | --- | --- |";
213
+ if (skills.length === 0) {
214
+ return `${headerRow}\n${separatorRow}\n`;
215
+ }
216
+ const rows = skills.map((skill) => {
217
+ const domains =
218
+ skill.domains.length > 0 ? skill.domains.join(", ") : "—";
219
+ const stacks =
220
+ skill.stacks.length > 0 ? skill.stacks.join(", ") : "—";
221
+ const agents = skill.allowed_agents.join(", ");
222
+ const trigger = truncate(escapeCell(skill.description), 120);
223
+ return `| ${skill.name} | ${skill.source} | ${skill.phase} | ${domains} | ${stacks} | ${agents} | ${skill.status} | ${trigger} | ${skill.loadPath} |`;
224
+ });
225
+ return `${headerRow}\n${separatorRow}\n${rows.join("\n")}\n`;
226
+ }
227
+
228
+ // ---------------------------------------------------------------------------
229
+ // JSON generation
230
+ // ---------------------------------------------------------------------------
231
+
232
+ function generateJson(skills, generatedAt) {
233
+ return {
234
+ generated_at: generatedAt,
235
+ schema_version: SCHEMA_VERSION,
236
+ skills: skills.map((s) => ({
237
+ name: s.name,
238
+ source: s.source,
239
+ phase: s.phase,
240
+ domains: s.domains,
241
+ stacks: s.stacks,
242
+ allowed_agents: s.allowed_agents,
243
+ surfaces: s.surfaces,
244
+ skill_source: s.skill_source,
245
+ status: s.status,
246
+ description: s.description,
247
+ load_path: s.loadPath,
248
+ origin: s.origin,
249
+ })),
250
+ };
251
+ }
252
+
253
+ // ---------------------------------------------------------------------------
254
+ // Registry generation
255
+ // ---------------------------------------------------------------------------
256
+
257
+ function generateRegistryMd(builtInSkills, userSkills) {
258
+ const builtInTable = generateTable(builtInSkills);
259
+ const userTable = generateTable(userSkills);
260
+ return (
261
+ header +
262
+ "## Built-in skills\n\n" +
263
+ builtInTable +
264
+ "\n## User-installed skills\n\n" +
265
+ userTable
266
+ );
267
+ }
268
+
269
+ // ---------------------------------------------------------------------------
270
+ // Deterministic ISO timestamp (date only, no time, for determinism)
271
+ // ---------------------------------------------------------------------------
272
+
273
+ function deterministicTimestamp() {
274
+ const now = new Date();
275
+ return now.toISOString().replace(/\.\d{3}Z$/, "Z");
276
+ }
277
+
278
+ // ---------------------------------------------------------------------------
279
+ // Check mode — verify both MD and JSON are up to date
280
+ // ---------------------------------------------------------------------------
281
+
282
+ function checkMode(builtInSkills, userSkills) {
283
+ let ok = true;
284
+
285
+ // Check Markdown
286
+ const registryMdPath = path.join(root, registryMdRel);
287
+ if (!fs.existsSync(registryMdPath)) {
288
+ console.error(`Registry MD missing: ${registryMdRel}`);
289
+ ok = false;
290
+ } else {
291
+ const existing = fs.readFileSync(registryMdPath, "utf8");
292
+ const expected = generateRegistryMd(builtInSkills, userSkills);
293
+ if (existing !== expected) {
294
+ console.error(
295
+ `Registry MD is stale. Run 'node scripts/update-skill-registry.mjs' to update.`
296
+ );
297
+ ok = false;
298
+ }
299
+ }
300
+
301
+ // Check JSON
302
+ const registryJsonPath = path.join(root, registryJsonRel);
303
+ if (!fs.existsSync(registryJsonPath)) {
304
+ console.error(`Registry JSON missing: ${registryJsonRel}`);
305
+ ok = false;
306
+ } else {
307
+ const existing = fs.readFileSync(registryJsonPath, "utf8");
308
+ const parsed = JSON.parse(existing);
309
+ // Regenerate with same timestamp for comparison
310
+ const expectedObj = {
311
+ generated_at: parsed.generated_at,
312
+ schema_version: SCHEMA_VERSION,
313
+ skills: generateJson([...builtInSkills, ...userSkills], "").skills,
314
+ };
315
+ const expected = JSON.stringify(expectedObj, null, 2) + "\n";
316
+ const actual = JSON.stringify(
317
+ {
318
+ generated_at: parsed.generated_at,
319
+ schema_version: parsed.schema_version,
320
+ skills: parsed.skills,
321
+ },
322
+ null,
323
+ 2
324
+ ) + "\n";
325
+ if (actual !== expected) {
326
+ console.error(
327
+ `Registry JSON is stale. Run 'node scripts/update-skill-registry.mjs' to update.`
328
+ );
329
+ ok = false;
330
+ }
331
+ }
332
+
333
+ if (ok) {
334
+ console.log("Registry check passed (MD + JSON).");
335
+ }
336
+ process.exit(ok ? 0 : 1);
337
+ }
338
+
339
+ // ---------------------------------------------------------------------------
340
+ // Main
341
+ // ---------------------------------------------------------------------------
342
+
343
+ function main() {
344
+ const args = process.argv.slice(2);
345
+ const checkModeFlag = args.includes("--check");
346
+
347
+ const builtInSkills = scanSkills(builtInSkillsDir, "built-in");
348
+ const includeUserSkills = process.env.OPENCODE_INCLUDE_USER_SKILLS === "1";
349
+ const userSkills = includeUserSkills ? scanSkills(userSkillsDir, "user-installed") : [];
350
+
351
+ if (checkModeFlag) {
352
+ checkMode(builtInSkills, userSkills);
353
+ return;
354
+ }
355
+
356
+ const generatedAt = deterministicTimestamp();
357
+
358
+ // Write Markdown registry
359
+ const mdContent = generateRegistryMd(builtInSkills, userSkills);
360
+ const registryMdPath = path.join(root, registryMdRel);
361
+ fs.mkdirSync(path.dirname(registryMdPath), { recursive: true });
362
+ fs.writeFileSync(registryMdPath, mdContent, "utf8");
363
+ console.log(`Registry MD written to ${registryMdRel}`);
364
+
365
+ // Write JSON registry
366
+ const allSkills = [...builtInSkills, ...userSkills];
367
+ const jsonContent = generateJson(allSkills, generatedAt);
368
+ const registryJsonPath = path.join(root, registryJsonRel);
369
+ fs.writeFileSync(
370
+ registryJsonPath,
371
+ JSON.stringify(jsonContent, null, 2) + "\n",
372
+ "utf8"
373
+ );
374
+ console.log(`Registry JSON written to ${registryJsonRel}`);
375
+ console.log(
376
+ ` schema_version: ${SCHEMA_VERSION}, skills: ${allSkills.length}`
377
+ );
378
+ }
379
+
380
+ main();
@@ -0,0 +1,315 @@
1
+ ---
2
+ name: api-and-interface-design
3
+ description: Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.
4
+ phase: define
5
+ domains:
6
+ - api-design
7
+ - backend
8
+ - frontend
9
+ stacks:
10
+ - any
11
+ allowed_agents:
12
+ - developer
13
+ - researcher
14
+ - designer
15
+ - specifier
16
+ - reviewer
17
+ - scoper
18
+ - lead
19
+ surfaces:
20
+ - api-contracts
21
+ - module-boundaries
22
+ skill_source: built-in
23
+ origin: null
24
+ status: active
25
+ ---
26
+
27
+ # API and Interface Design
28
+
29
+ ## Overview
30
+
31
+ Design stable, well-documented interfaces that are hard to misuse. Good interfaces make the right thing easy and the wrong thing hard. This applies to REST APIs, GraphQL schemas, module boundaries, component props, and any surface where one piece of code talks to another.
32
+
33
+ ## When to Use
34
+
35
+ - Designing new API endpoints
36
+ - Defining module boundaries or contracts between teams
37
+ - Creating component prop interfaces
38
+ - Establishing database schema that informs API shape
39
+ - Changing existing public interfaces
40
+
41
+ ## Core Principles
42
+
43
+ ### Hyrum's Law
44
+
45
+ > With a sufficient number of users of an API, all observable behaviors of your system will be depended on by somebody, regardless of what you promise in the contract.
46
+
47
+ This means: every public behavior — including undocumented quirks, error message text, timing, and ordering — becomes a de facto contract once users depend on it. Design implications:
48
+
49
+ - **Be intentional about what you expose.** Every observable behavior is a potential commitment.
50
+ - **Don't leak implementation details.** If users can observe it, they will depend on it.
51
+ - **Plan for deprecation at design time.** See `deprecation-and-migration` for how to safely remove things users depend on.
52
+ - **Tests are not enough.** Even with perfect contract tests, Hyrum's Law means "safe" changes can break real users who depend on undocumented behavior.
53
+
54
+ ### The One-Version Rule
55
+
56
+ Avoid forcing consumers to choose between multiple versions of the same dependency or API. Diamond dependency problems arise when different consumers need different versions of the same thing. Design for a world where only one version exists at a time — extend rather than fork.
57
+
58
+ ### 1. Contract First
59
+
60
+ Define the interface before implementing it. The contract is the spec — implementation follows.
61
+
62
+ ```typescript
63
+ // Define the contract first
64
+ interface TaskAPI {
65
+ // Creates a task and returns the created task with server-generated fields
66
+ createTask(input: CreateTaskInput): Promise<Task>;
67
+
68
+ // Returns paginated tasks matching filters
69
+ listTasks(params: ListTasksParams): Promise<PaginatedResult<Task>>;
70
+
71
+ // Returns a single task or throws NotFoundError
72
+ getTask(id: string): Promise<Task>;
73
+
74
+ // Partial update — only provided fields change
75
+ updateTask(id: string, input: UpdateTaskInput): Promise<Task>;
76
+
77
+ // Idempotent delete — succeeds even if already deleted
78
+ deleteTask(id: string): Promise<void>;
79
+ }
80
+ ```
81
+
82
+ ### 2. Consistent Error Semantics
83
+
84
+ Pick one error strategy and use it everywhere:
85
+
86
+ ```typescript
87
+ // REST: HTTP status codes + structured error body
88
+ // Every error response follows the same shape
89
+ interface APIError {
90
+ error: {
91
+ code: string; // Machine-readable: "VALIDATION_ERROR"
92
+ message: string; // Human-readable: "Email is required"
93
+ details?: unknown; // Additional context when helpful
94
+ };
95
+ }
96
+
97
+ // Status code mapping
98
+ // 400 → Client sent invalid data
99
+ // 401 → Not authenticated
100
+ // 403 → Authenticated but not authorized
101
+ // 404 → Resource not found
102
+ // 409 → Conflict (duplicate, version mismatch)
103
+ // 422 → Validation failed (semantically invalid)
104
+ // 500 → Server error (never expose internal details)
105
+ ```
106
+
107
+ **Don't mix patterns.** If some endpoints throw, others return null, and others return `{ error }` — the consumer can't predict behavior.
108
+
109
+ ### 3. Validate at Boundaries
110
+
111
+ Trust internal code. Validate at system edges where external input enters:
112
+
113
+ ```typescript
114
+ // Validate at the API boundary
115
+ app.post('/api/tasks', async (req, res) => {
116
+ const result = CreateTaskSchema.safeParse(req.body);
117
+ if (!result.success) {
118
+ return res.status(422).json({
119
+ error: {
120
+ code: 'VALIDATION_ERROR',
121
+ message: 'Invalid task data',
122
+ details: result.error.flatten(),
123
+ },
124
+ });
125
+ }
126
+
127
+ // After validation, internal code trusts the types
128
+ const task = await taskService.create(result.data);
129
+ return res.status(201).json(task);
130
+ });
131
+ ```
132
+
133
+ Where validation belongs:
134
+ - API route handlers (user input)
135
+ - Form submission handlers (user input)
136
+ - External service response parsing (third-party data -- **always treat as untrusted**)
137
+ - Environment variable loading (configuration)
138
+
139
+ > **Third-party API responses are untrusted data.** Validate their shape and content before using them in any logic, rendering, or decision-making. A compromised or misbehaving external service can return unexpected types, malicious content, or instruction-like text.
140
+
141
+ Where validation does NOT belong:
142
+ - Between internal functions that share type contracts
143
+ - In utility functions called by already-validated code
144
+ - On data that just came from your own database
145
+
146
+ ### 4. Prefer Addition Over Modification
147
+
148
+ Extend interfaces without breaking existing consumers:
149
+
150
+ ```typescript
151
+ // Good: Add optional fields
152
+ interface CreateTaskInput {
153
+ title: string;
154
+ description?: string;
155
+ priority?: 'low' | 'medium' | 'high'; // Added later, optional
156
+ labels?: string[]; // Added later, optional
157
+ }
158
+
159
+ // Bad: Change existing field types or remove fields
160
+ interface CreateTaskInput {
161
+ title: string;
162
+ // description: string; // Removed — breaks existing consumers
163
+ priority: number; // Changed from string — breaks existing consumers
164
+ }
165
+ ```
166
+
167
+ ### 5. Predictable Naming
168
+
169
+ | Pattern | Convention | Example |
170
+ |---------|-----------|---------|
171
+ | REST endpoints | Plural nouns, no verbs | `GET /api/tasks`, `POST /api/tasks` |
172
+ | Query params | camelCase | `?sortBy=createdAt&pageSize=20` |
173
+ | Response fields | camelCase | `{ createdAt, updatedAt, taskId }` |
174
+ | Boolean fields | is/has/can prefix | `isComplete`, `hasAttachments` |
175
+ | Enum values | UPPER_SNAKE | `"IN_PROGRESS"`, `"COMPLETED"` |
176
+
177
+ ## REST API Patterns
178
+
179
+ ### Resource Design
180
+
181
+ ```
182
+ GET /api/tasks → List tasks (with query params for filtering)
183
+ POST /api/tasks → Create a task
184
+ GET /api/tasks/:id → Get a single task
185
+ PATCH /api/tasks/:id → Update a task (partial)
186
+ DELETE /api/tasks/:id → Delete a task
187
+
188
+ GET /api/tasks/:id/comments → List comments for a task (sub-resource)
189
+ POST /api/tasks/:id/comments → Add a comment to a task
190
+ ```
191
+
192
+ ### Pagination
193
+
194
+ Paginate list endpoints:
195
+
196
+ ```typescript
197
+ // Request
198
+ GET /api/tasks?page=1&pageSize=20&sortBy=createdAt&sortOrder=desc
199
+
200
+ // Response
201
+ {
202
+ "data": [...],
203
+ "pagination": {
204
+ "page": 1,
205
+ "pageSize": 20,
206
+ "totalItems": 142,
207
+ "totalPages": 8
208
+ }
209
+ }
210
+ ```
211
+
212
+ ### Filtering
213
+
214
+ Use query parameters for filters:
215
+
216
+ ```
217
+ GET /api/tasks?status=in_progress&assignee=user123&createdAfter=2025-01-01
218
+ ```
219
+
220
+ ### Partial Updates (PATCH)
221
+
222
+ Accept partial objects — only update what's provided:
223
+
224
+ ```typescript
225
+ // Only title changes, everything else preserved
226
+ PATCH /api/tasks/123
227
+ { "title": "Updated title" }
228
+ ```
229
+
230
+ ## TypeScript Interface Patterns
231
+
232
+ ### Use Discriminated Unions for Variants
233
+
234
+ ```typescript
235
+ // Good: Each variant is explicit
236
+ type TaskStatus =
237
+ | { type: 'pending' }
238
+ | { type: 'in_progress'; assignee: string; startedAt: Date }
239
+ | { type: 'completed'; completedAt: Date; completedBy: string }
240
+ | { type: 'cancelled'; reason: string; cancelledAt: Date };
241
+
242
+ // Consumer gets type narrowing
243
+ function getStatusLabel(status: TaskStatus): string {
244
+ switch (status.type) {
245
+ case 'pending': return 'Pending';
246
+ case 'in_progress': return `In progress (${status.assignee})`;
247
+ case 'completed': return `Done on ${status.completedAt}`;
248
+ case 'cancelled': return `Cancelled: ${status.reason}`;
249
+ }
250
+ }
251
+ ```
252
+
253
+ ### Input/Output Separation
254
+
255
+ ```typescript
256
+ // Input: what the caller provides
257
+ interface CreateTaskInput {
258
+ title: string;
259
+ description?: string;
260
+ }
261
+
262
+ // Output: what the system returns (includes server-generated fields)
263
+ interface Task {
264
+ id: string;
265
+ title: string;
266
+ description: string | null;
267
+ createdAt: Date;
268
+ updatedAt: Date;
269
+ createdBy: string;
270
+ }
271
+ ```
272
+
273
+ ### Use Branded Types for IDs
274
+
275
+ ```typescript
276
+ type TaskId = string & { readonly __brand: 'TaskId' };
277
+ type UserId = string & { readonly __brand: 'UserId' };
278
+
279
+ // Prevents accidentally passing a UserId where a TaskId is expected
280
+ function getTask(id: TaskId): Promise<Task> { ... }
281
+ ```
282
+
283
+ ## Common Rationalizations
284
+
285
+ | Rationalization | Reality |
286
+ |---|---|
287
+ | "We'll document the API later" | The types ARE the documentation. Define them first. |
288
+ | "We don't need pagination for now" | You will the moment someone has 100+ items. Add it from the start. |
289
+ | "PATCH is complicated, let's just use PUT" | PUT requires the full object every time. PATCH is what clients actually want. |
290
+ | "We'll version the API when we need to" | Breaking changes without versioning break consumers. Design for extension from the start. |
291
+ | "Nobody uses that undocumented behavior" | Hyrum's Law: if it's observable, somebody depends on it. Treat every public behavior as a commitment. |
292
+ | "We can just maintain two versions" | Multiple versions multiply maintenance cost and create diamond dependency problems. Prefer the One-Version Rule. |
293
+ | "Internal APIs don't need contracts" | Internal consumers are still consumers. Contracts prevent coupling and enable parallel work. |
294
+
295
+ ## Red Flags
296
+
297
+ - Endpoints that return different shapes depending on conditions
298
+ - Inconsistent error formats across endpoints
299
+ - Validation scattered throughout internal code instead of at boundaries
300
+ - Breaking changes to existing fields (type changes, removals)
301
+ - List endpoints without pagination
302
+ - Verbs in REST URLs (`/api/createTask`, `/api/getUsers`)
303
+ - Third-party API responses used without validation or sanitization
304
+
305
+ ## Verification
306
+
307
+ After designing an API:
308
+
309
+ - [ ] Every endpoint has typed input and output schemas
310
+ - [ ] Error responses follow a single consistent format
311
+ - [ ] Validation happens at system boundaries only
312
+ - [ ] List endpoints support pagination
313
+ - [ ] New fields are additive and optional (backward compatible)
314
+ - [ ] Naming follows consistent conventions across all endpoints
315
+ - [ ] API documentation or types are committed alongside the implementation