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,363 @@
1
+ import assert from "node:assert/strict";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { spawnSync } from "node:child_process";
6
+ import test from "node:test";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
10
+ const root = path.dirname(scriptDir);
11
+ const script = path.join(scriptDir, "preflight-audit.mjs");
12
+
13
+ function makeFixture() {
14
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-preflight-"));
15
+ fs.cpSync(root, tmp, {
16
+ recursive: true,
17
+ filter: (source) => {
18
+ const rel = path.relative(root, source);
19
+ return rel !== ".git" && !rel.startsWith(`.git${path.sep}`);
20
+ },
21
+ });
22
+ return tmp;
23
+ }
24
+
25
+ function runPreflight(cwd, args = []) {
26
+ return spawnSync(process.execPath, [script, ...args], {
27
+ cwd,
28
+ encoding: "utf8",
29
+ });
30
+ }
31
+
32
+ function readArtifact(cwd, iteration) {
33
+ const p = path.join(cwd, "docs/ai/evolution/runs", iteration, "preflight-audit.json");
34
+ return JSON.parse(fs.readFileSync(p, "utf8"));
35
+ }
36
+
37
+ function readArtifactFromDir(dir) {
38
+ const p = path.join(dir, "preflight-audit.json");
39
+ return JSON.parse(fs.readFileSync(p, "utf8"));
40
+ }
41
+
42
+ function write(rel, content, cwd) {
43
+ fs.writeFileSync(path.join(cwd, rel), content);
44
+ }
45
+
46
+ test("preflight-audit generates valid artifact with required fields", () => {
47
+ const cwd = makeFixture();
48
+ try {
49
+ const result = runPreflight(cwd, ["--iteration", "iteration-test-001"]);
50
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
51
+ const artifact = readArtifact(cwd, "iteration-test-001");
52
+
53
+ // Required top-level fields
54
+ for (const field of ["iteration", "timestamp", "scores", "doc_runtime_matrix", "drifts", "recommendations", "coverage", "confidence"]) {
55
+ assert.ok(field in artifact, `missing top-level field: ${field}`);
56
+ }
57
+
58
+ // Required score fields
59
+ for (const field of ["contract_coverage", "runtime_evidence_coverage", "doc_runtime_alignment", "drift_severity"]) {
60
+ assert.ok(field in artifact.scores, `missing score field: ${field}`);
61
+ }
62
+
63
+ // Scores are numbers between 0 and 1 (except drift_severity)
64
+ assert.ok(typeof artifact.scores.contract_coverage === "number", "contract_coverage must be a number");
65
+ assert.ok(artifact.scores.contract_coverage >= 0 && artifact.scores.contract_coverage <= 1, "contract_coverage out of range");
66
+ assert.ok(typeof artifact.scores.runtime_evidence_coverage === "number", "runtime_evidence_coverage must be a number");
67
+ assert.ok(typeof artifact.scores.doc_runtime_alignment === "number", "doc_runtime_alignment must be a number");
68
+ assert.ok(["none", "low", "medium", "high"].includes(artifact.scores.drift_severity), "invalid drift_severity");
69
+
70
+ // doc_runtime_matrix is an array
71
+ assert.ok(Array.isArray(artifact.doc_runtime_matrix), "doc_runtime_matrix must be an array");
72
+
73
+ // drifts is an array
74
+ assert.ok(Array.isArray(artifact.drifts), "drifts must be an array");
75
+
76
+ // recommendations is an array
77
+ assert.ok(Array.isArray(artifact.recommendations), "recommendations must be an array");
78
+
79
+ // iteration matches
80
+ assert.equal(artifact.iteration, "iteration-test-001");
81
+ } finally {
82
+ fs.rmSync(cwd, { recursive: true, force: true });
83
+ }
84
+ });
85
+
86
+ test("preflight-audit detects missing runtime evidence for documented agent", () => {
87
+ const cwd = makeFixture();
88
+ try {
89
+ // Create iteration directory with no staged artifacts
90
+ fs.mkdirSync(path.join(cwd, "docs/ai/evolution/runs/iteration-drift-001/raw"), { recursive: true });
91
+
92
+ const result = runPreflight(cwd, ["--iteration", "iteration-drift-001"]);
93
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
94
+ const artifact = readArtifact(cwd, "iteration-drift-001");
95
+
96
+ // Should detect drifts
97
+ assert.ok(artifact.drifts.length > 0, "expected drifts for missing runtime evidence");
98
+ // At least one drift should be about missing evidence
99
+ const hasMissingEvidence = artifact.drifts.some(
100
+ (d) => d.type === "missing_evidence" || d.description.toLowerCase().includes("evidence")
101
+ );
102
+ assert.ok(hasMissingEvidence, "expected a drift about missing evidence");
103
+ } finally {
104
+ fs.rmSync(cwd, { recursive: true, force: true });
105
+ }
106
+ });
107
+
108
+ test("preflight-audit produces recommendations sorted by priority", () => {
109
+ const cwd = makeFixture();
110
+ try {
111
+ fs.mkdirSync(path.join(cwd, "docs/ai/evolution/runs/iteration-recs-001/raw"), { recursive: true });
112
+
113
+ const result = runPreflight(cwd, ["--iteration", "iteration-recs-001"]);
114
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
115
+ const artifact = readArtifact(cwd, "iteration-recs-001");
116
+
117
+ assert.ok(artifact.recommendations.length > 0, "expected at least one recommendation");
118
+
119
+ // Each recommendation has required fields
120
+ for (const rec of artifact.recommendations) {
121
+ assert.ok(["high", "medium", "low"].includes(rec.priority), `invalid priority: ${rec.priority}`);
122
+ assert.ok(typeof rec.description === "string" && rec.description.length > 0, "recommendation must have description");
123
+ }
124
+
125
+ // Recommendations should be sorted: high first, then medium, then low
126
+ const priorityOrder = { high: 0, medium: 1, low: 2 };
127
+ for (let i = 1; i < artifact.recommendations.length; i++) {
128
+ assert.ok(
129
+ priorityOrder[artifact.recommendations[i].priority] >= priorityOrder[artifact.recommendations[i - 1].priority],
130
+ "recommendations not sorted by priority"
131
+ );
132
+ }
133
+ } finally {
134
+ fs.rmSync(cwd, { recursive: true, force: true });
135
+ }
136
+ });
137
+
138
+ test("preflight-audit handles missing iteration directory gracefully", () => {
139
+ const cwd = makeFixture();
140
+ try {
141
+ const result = runPreflight(cwd, ["--iteration", "iteration-nonexistent-999"]);
142
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
143
+ const artifact = readArtifact(cwd, "iteration-nonexistent-999");
144
+
145
+ // Should still produce a valid artifact with doc-only signals
146
+ assert.ok("scores" in artifact, "artifact must have scores even without iteration dir");
147
+ assert.ok("confidence" in artifact, "artifact must have confidence");
148
+ assert.equal(artifact.confidence, "low", "confidence should be low when no iteration exists");
149
+ } finally {
150
+ fs.rmSync(cwd, { recursive: true, force: true });
151
+ }
152
+ });
153
+
154
+ test("preflight-audit doc_runtime_matrix covers agents and commands", () => {
155
+ const cwd = makeFixture();
156
+ try {
157
+ const result = runPreflight(cwd, ["--iteration", "iteration-matrix-001"]);
158
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
159
+ const artifact = readArtifact(cwd, "iteration-matrix-001");
160
+
161
+ // Matrix should cover agents
162
+ const agentEntries = artifact.doc_runtime_matrix.filter((m) => m.type === "agent");
163
+ assert.ok(agentEntries.length >= 3, `expected at least 3 agent entries, got ${agentEntries.length}`);
164
+
165
+ // Matrix should cover commands
166
+ const commandEntries = artifact.doc_runtime_matrix.filter((m) => m.type === "command");
167
+ assert.ok(commandEntries.length >= 3, `expected at least 3 command entries, got ${commandEntries.length}`);
168
+
169
+ // Each entry has required fields
170
+ for (const entry of artifact.doc_runtime_matrix) {
171
+ assert.ok(["agent", "command", "workflow", "evidence"].includes(entry.type), `invalid matrix type: ${entry.type}`);
172
+ assert.ok(typeof entry.name === "string", "matrix entry must have name");
173
+ assert.ok(typeof entry.doc_exists === "boolean", "matrix entry must have doc_exists");
174
+ assert.ok(typeof entry.aligned === "boolean", "matrix entry must have aligned");
175
+ }
176
+ } finally {
177
+ fs.rmSync(cwd, { recursive: true, force: true });
178
+ }
179
+ });
180
+
181
+ test("preflight-audit fails without --iteration argument", () => {
182
+ const cwd = makeFixture();
183
+ try {
184
+ const result = runPreflight(cwd, []);
185
+ assert.notEqual(result.status, 0, "script should fail without --iteration");
186
+ } finally {
187
+ fs.rmSync(cwd, { recursive: true, force: true });
188
+ }
189
+ });
190
+
191
+ test("preflight-audit with staged execution-trees produces higher evidence coverage", () => {
192
+ const cwd = makeFixture();
193
+ try {
194
+ const iterationDir = path.join(cwd, "docs/ai/evolution/runs/iteration-evidence-001/raw");
195
+ fs.mkdirSync(iterationDir, { recursive: true });
196
+
197
+ // Write minimal staged artifacts with agent references
198
+ write(
199
+ "docs/ai/evolution/runs/iteration-evidence-001/raw/execution-trees.jsonl",
200
+ '{"root_session_id":"s1","agent":"lead","children":[{"agent":"developer"},{"agent":"evaluator"}]}',
201
+ cwd
202
+ );
203
+ write(
204
+ "docs/ai/evolution/runs/iteration-evidence-001/raw/session-sources.summary.json",
205
+ '{"discovered":1,"accepted":1,"skipped":0,"skip_reasons":[]}',
206
+ cwd
207
+ );
208
+ write(
209
+ "docs/ai/evolution/runs/iteration-evidence-001/raw/cursor.json",
210
+ '{"tree_time_updated_max":"2024-01-01T00:00:00Z","root_session_id":"s1"}',
211
+ cwd
212
+ );
213
+
214
+ const result = runPreflight(cwd, ["--iteration", "iteration-evidence-001"]);
215
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
216
+ const artifact = readArtifact(cwd, "iteration-evidence-001");
217
+
218
+ // With staged artifacts, evidence coverage should be higher than without
219
+ assert.ok(artifact.scores.runtime_evidence_coverage > 0, "evidence coverage should be > 0 with staged artifacts");
220
+ } finally {
221
+ fs.rmSync(cwd, { recursive: true, force: true });
222
+ }
223
+ });
224
+
225
+ test("preflight-audit drift detection severity follows priority rules", () => {
226
+ const cwd = makeFixture();
227
+ try {
228
+ // Create a scenario where a critical contract exists but has no evidence
229
+ const iterationDir = path.join(cwd, "docs/ai/evolution/runs/iteration-severity-001/raw");
230
+ fs.mkdirSync(iterationDir, { recursive: true });
231
+
232
+ const result = runPreflight(cwd, ["--iteration", "iteration-severity-001"]);
233
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
234
+ const artifact = readArtifact(cwd, "iteration-severity-001");
235
+
236
+ // Check that drifts have valid severity levels
237
+ for (const drift of artifact.drifts) {
238
+ assert.ok(["high", "medium", "low"].includes(drift.severity), `invalid drift severity: ${drift.severity}`);
239
+ assert.ok(typeof drift.surface === "string", "drift must have surface");
240
+ assert.ok(typeof drift.description === "string" && drift.description.length > 0, "drift must have description");
241
+ }
242
+ } finally {
243
+ fs.rmSync(cwd, { recursive: true, force: true });
244
+ }
245
+ });
246
+
247
+ test("preflight-audit confidence is high when all docs exist and no drifts", () => {
248
+ const cwd = makeFixture();
249
+ try {
250
+ // All docs exist in the fixture (they come from the real repo)
251
+ // But staged artifacts are missing, so confidence depends on doc coverage
252
+ const result = runPreflight(cwd, ["--iteration", "iteration-conf-001"]);
253
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
254
+ const artifact = readArtifact(cwd, "iteration-conf-001");
255
+
256
+ // Confidence should be a valid level
257
+ assert.ok(["high", "medium", "low"].includes(artifact.confidence), `invalid confidence: ${artifact.confidence}`);
258
+
259
+ // If no drifts, confidence should be at least medium
260
+ if (artifact.drifts.length === 0) {
261
+ assert.ok(["high", "medium"].includes(artifact.confidence), "confidence should be medium or high with no drifts");
262
+ }
263
+ } finally {
264
+ fs.rmSync(cwd, { recursive: true, force: true });
265
+ }
266
+ });
267
+
268
+ test("preflight-audit --output-dir overrides default output location", () => {
269
+ const cwd = makeFixture();
270
+ try {
271
+ const customOutDir = path.join(cwd, "custom-output");
272
+ fs.mkdirSync(customOutDir, { recursive: true });
273
+
274
+ const result = runPreflight(cwd, [
275
+ "--iteration", "iteration-outdir-001",
276
+ "--output-dir", customOutDir,
277
+ ]);
278
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
279
+
280
+ // Artifact should be in the custom dir, not the default location
281
+ const artifact = readArtifactFromDir(customOutDir);
282
+ assert.equal(artifact.iteration, "iteration-outdir-001");
283
+
284
+ // Default location should NOT exist
285
+ const defaultPath = path.join(cwd, "docs/ai/evolution/runs/iteration-outdir-001/preflight-audit.json");
286
+ assert.ok(!fs.existsSync(defaultPath), "artifact should not be in default location when --output-dir is used");
287
+ } finally {
288
+ fs.rmSync(cwd, { recursive: true, force: true });
289
+ }
290
+ });
291
+
292
+ test("preflight-audit structured evidence detects agent from JSONL fields", () => {
293
+ const cwd = makeFixture();
294
+ try {
295
+ const iterationDir = path.join(cwd, "docs/ai/evolution/runs/iteration-struct-001/raw");
296
+ fs.mkdirSync(iterationDir, { recursive: true });
297
+
298
+ // Write JSONL with structured agent field (not just substring match)
299
+ // The agent "lead" appears in the "agent" field of a nested child
300
+ write(
301
+ "docs/ai/evolution/runs/iteration-struct-001/raw/execution-trees.jsonl",
302
+ JSON.stringify({
303
+ root_session_id: "s1",
304
+ children: [
305
+ { agent: "lead", type: "orchestration" },
306
+ { agent: "developer", type: "implementation" },
307
+ ],
308
+ }),
309
+ cwd
310
+ );
311
+
312
+ const result = runPreflight(cwd, ["--iteration", "iteration-struct-001"]);
313
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
314
+ const artifact = readArtifact(cwd, "iteration-struct-001");
315
+
316
+ // "lead" and "developer" should have runtime evidence from structured fields
317
+ const leadEntry = artifact.doc_runtime_matrix.find(
318
+ (m) => m.type === "agent" && m.name === "lead"
319
+ );
320
+ const devEntry = artifact.doc_runtime_matrix.find(
321
+ (m) => m.type === "agent" && m.name === "developer"
322
+ );
323
+ assert.ok(leadEntry, "lead entry should exist in matrix");
324
+ assert.ok(devEntry, "developer entry should exist in matrix");
325
+ assert.ok(leadEntry.runtime_evidence_exists, "lead should have runtime evidence from structured JSONL");
326
+ assert.ok(devEntry.runtime_evidence_exists, "developer should have runtime evidence from structured JSONL");
327
+ } finally {
328
+ fs.rmSync(cwd, { recursive: true, force: true });
329
+ }
330
+ });
331
+
332
+ test("preflight-audit structured evidence does not false-positive on partial substring", () => {
333
+ const cwd = makeFixture();
334
+ try {
335
+ const iterationDir = path.join(cwd, "docs/ai/evolution/runs/iteration-fp-001/raw");
336
+ fs.mkdirSync(iterationDir, { recursive: true });
337
+
338
+ // Write JSONL where "lead" appears only as part of a longer string value
339
+ // in a non-evidence field, which should NOT count as structured evidence
340
+ write(
341
+ "docs/ai/evolution/runs/iteration-fp-001/raw/execution-trees.jsonl",
342
+ JSON.stringify({
343
+ root_session_id: "s1",
344
+ type: "leaderboard_snapshot",
345
+ summary: "This is a leading indicator report",
346
+ }),
347
+ cwd
348
+ );
349
+
350
+ const result = runPreflight(cwd, ["--iteration", "iteration-fp-001"]);
351
+ assert.equal(result.status, 0, `script failed: ${result.stderr}`);
352
+ const artifact = readArtifact(cwd, "iteration-fp-001");
353
+
354
+ // "lead" should NOT have runtime evidence from a false-positive substring
355
+ const leadEntry = artifact.doc_runtime_matrix.find(
356
+ (m) => m.type === "agent" && m.name === "lead"
357
+ );
358
+ assert.ok(leadEntry, "lead entry should exist in matrix");
359
+ assert.ok(!leadEntry.runtime_evidence_exists, "lead should NOT have runtime evidence from false-positive substring");
360
+ } finally {
361
+ fs.rmSync(cwd, { recursive: true, force: true });
362
+ }
363
+ });