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,443 @@
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
+ // collect-session-evidence.mjs exposes only async streamSqliteJson; sync runSqliteJson was removed.
10
+
11
+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
12
+ const root = path.dirname(scriptDir);
13
+
14
+ function run(command, args, options = {}) {
15
+ const result = spawnSync(command, args, { encoding: "utf8", ...options });
16
+ if (result.status !== 0) {
17
+ throw new Error(`Command failed: ${command} ${args.join(" ")}\n${result.stderr}`);
18
+ }
19
+ return result;
20
+ }
21
+
22
+ function makeTempDir() {
23
+ return fs.mkdtempSync(path.join(os.tmpdir(), "collect-session-evidence-"));
24
+ }
25
+
26
+ function writeJson(file, value) {
27
+ fs.writeFileSync(file, JSON.stringify(value), "utf8");
28
+ }
29
+
30
+ function createFixtureDb(dbPath) {
31
+ run("sqlite3", [
32
+ dbPath,
33
+ `
34
+ create table session (
35
+ id text primary key,
36
+ project_id text not null,
37
+ parent_id text,
38
+ slug text not null,
39
+ directory text not null,
40
+ title text not null,
41
+ version text not null,
42
+ share_url text,
43
+ summary_additions integer,
44
+ summary_deletions integer,
45
+ summary_files integer,
46
+ summary_diffs text,
47
+ revert text,
48
+ permission text,
49
+ time_created integer not null,
50
+ time_updated integer not null,
51
+ time_compacting integer,
52
+ time_archived integer,
53
+ workspace_id text,
54
+ path text,
55
+ agent text,
56
+ model text,
57
+ cost real default 0 not null,
58
+ tokens_input integer default 0 not null,
59
+ tokens_output integer default 0 not null,
60
+ tokens_reasoning integer default 0 not null,
61
+ tokens_cache_read integer default 0 not null,
62
+ tokens_cache_write integer default 0 not null
63
+ );
64
+ create table message (
65
+ id text primary key,
66
+ session_id text not null,
67
+ time_created integer not null,
68
+ time_updated integer not null,
69
+ data text not null
70
+ );
71
+ create table part (
72
+ id text primary key,
73
+ message_id text not null,
74
+ session_id text not null,
75
+ time_created integer not null,
76
+ time_updated integer not null,
77
+ data text not null
78
+ );
79
+
80
+ insert into session (
81
+ id, project_id, parent_id, slug, directory, title, version, time_created, time_updated, path, agent, model, cost, tokens_input, tokens_output, tokens_reasoning, tokens_cache_read, tokens_cache_write
82
+ ) values
83
+ ('ses_root_1', 'proj_1', null, 'steady-otter', '/tmp/repo', 'Investigate harness issue', '1.15.12', 1000, 2000, '', 'lead', '{"id":"gpt-5.4","providerID":"openai","variant":"medium"}', 1.5, 120, 45, 3, 10, 0),
84
+ ('ses_child_1', 'proj_1', 'ses_root_1', 'curious-otter', '/tmp/repo', 'Research harness issue (@researcher subagent)', '1.15.12', 1100, 2100, '', 'researcher', '{"id":"gpt-5.4","providerID":"openai","variant":"medium"}', 0.5, 50, 10, 1, 0, 0),
85
+ ('ses_grandchild_1', 'proj_1', 'ses_child_1', 'quiet-otter', '/tmp/repo', 'Review harness issue (@reviewer subagent)', '1.15.12', 1150, 2200, '', 'reviewer', '{"id":"gpt-5.4","providerID":"openai","variant":"medium"}', 0.25, 25, 15, 2, 0, 0),
86
+ ('ses_root_2', 'proj_1', null, 'brisk-otter', '/tmp/repo', 'Independent direct session', '1.15.12', 3000, 3000, '', 'developer', '{"id":"gpt-5.4","providerID":"openai","variant":"medium"}', 0.75, 90, 20, 0, 0, 0);
87
+
88
+ insert into message (id, session_id, time_created, time_updated, data) values
89
+ ('msg_user_root_1', 'ses_root_1', 1000, 1000, '{"role":"user","time":{"created":1000}}'),
90
+ ('msg_assistant_root_1', 'ses_root_1', 1200, 1300, '{"role":"assistant","time":{"created":1200,"completed":1300},"finish":"stop"}'),
91
+ ('msg_user_child_1', 'ses_child_1', 1100, 1100, '{"role":"user","time":{"created":1100}}'),
92
+ ('msg_assistant_child_1', 'ses_child_1', 1400, 1500, '{"role":"assistant","time":{"created":1400,"completed":1500},"finish":"stop"}'),
93
+ ('msg_user_grandchild_1', 'ses_grandchild_1', 1150, 1150, '{"role":"user","time":{"created":1150}}'),
94
+ ('msg_assistant_grandchild_1', 'ses_grandchild_1', 1500, 1600, '{"role":"assistant","time":{"created":1500,"completed":1600},"finish":"stop"}'),
95
+ ('msg_user_root_2', 'ses_root_2', 3000, 3000, '{"role":"user","time":{"created":3000}}'),
96
+ ('msg_assistant_root_2', 'ses_root_2', 3200, 3300, '{"role":"assistant","time":{"created":3200,"completed":3300},"finish":"stop"}');
97
+
98
+ insert into part (id, message_id, session_id, time_created, time_updated, data) values
99
+ ('prt_user_root_1', 'msg_user_root_1', 'ses_root_1', 1000, 1000, '{"type":"text","text":"Investigate the harness issue carefully."}'),
100
+ ('prt_assistant_root_1', 'msg_assistant_root_1', 'ses_root_1', 1200, 1300, '{"type":"text","text":"Lead summary for the harness issue."}'),
101
+ ('prt_user_child_1', 'msg_user_child_1', 'ses_child_1', 1100, 1100, '{"type":"text","text":"Research the harness issue in depth."}'),
102
+ ('prt_assistant_child_1', 'msg_assistant_child_1', 'ses_child_1', 1400, 1500, '{"type":"text","text":"Research findings for the harness issue."}'),
103
+ ('prt_user_grandchild_1', 'msg_user_grandchild_1', 'ses_grandchild_1', 1150, 1150, '{"type":"text","text":"Review the harness issue findings."}'),
104
+ ('prt_assistant_grandchild_1', 'msg_assistant_grandchild_1', 'ses_grandchild_1', 1500, 1600, '{"type":"text","text":"Reviewer findings for the harness issue."}'),
105
+ ('prt_user_root_2', 'msg_user_root_2', 'ses_root_2', 3000, 3000, '{"type":"text","text":"Implement a direct fix."}'),
106
+ ('prt_assistant_root_2', 'msg_assistant_root_2', 'ses_root_2', 3200, 3300, '{"type":"text","text":"Direct fix implemented."}');
107
+ `,
108
+ ]);
109
+ }
110
+
111
+ function createLargeFixtureDb(dbPath, repeatCount = 400000) {
112
+ const chunk = "Evidence payload ";
113
+ const targetLength = chunk.length * repeatCount;
114
+ run("sqlite3", [
115
+ dbPath,
116
+ `
117
+ create table session (
118
+ id text primary key,
119
+ project_id text not null,
120
+ parent_id text,
121
+ slug text not null,
122
+ directory text not null,
123
+ title text not null,
124
+ version text not null,
125
+ share_url text,
126
+ summary_additions integer,
127
+ summary_deletions integer,
128
+ summary_files integer,
129
+ summary_diffs text,
130
+ revert text,
131
+ permission text,
132
+ time_created integer not null,
133
+ time_updated integer not null,
134
+ time_compacting integer,
135
+ time_archived integer,
136
+ workspace_id text,
137
+ path text,
138
+ agent text,
139
+ model text,
140
+ cost real default 0 not null,
141
+ tokens_input integer default 0 not null,
142
+ tokens_output integer default 0 not null,
143
+ tokens_reasoning integer default 0 not null,
144
+ tokens_cache_read integer default 0 not null,
145
+ tokens_cache_write integer default 0 not null
146
+ );
147
+ create table message (
148
+ id text primary key,
149
+ session_id text not null,
150
+ time_created integer not null,
151
+ time_updated integer not null,
152
+ data text not null
153
+ );
154
+ create table part (
155
+ id text primary key,
156
+ message_id text not null,
157
+ session_id text not null,
158
+ time_created integer not null,
159
+ time_updated integer not null,
160
+ data text not null
161
+ );
162
+ insert into session (
163
+ id, project_id, parent_id, slug, directory, title, version, time_created, time_updated, path, agent, model, cost, tokens_input, tokens_output, tokens_reasoning, tokens_cache_read, tokens_cache_write
164
+ ) values (
165
+ 'ses_large_1', 'proj_1', null, 'steady-otter', '/tmp/repo', 'Large evidence session', '1.15.12', 1000, 2000, '', 'developer',
166
+ '{"id":"gpt-5.4","providerID":"openai","variant":"medium"}', 0, 120, 45, 3, 10, 0
167
+ );
168
+ insert into message (id, session_id, time_created, time_updated, data) values
169
+ ('msg_user_large_1', 'ses_large_1', 1100, 1100, '{"role":"user","time":{"created":1100}}'),
170
+ ('msg_assistant_large_1', 'ses_large_1', 1200, 1300, '{"role":"assistant","time":{"created":1200,"completed":1300},"finish":"stop"}');
171
+ with large_text(value) as (
172
+ select substr(replace(hex(zeroblob(${repeatCount})), '00', '${chunk}'), 1, ${targetLength})
173
+ )
174
+ insert into part (id, message_id, session_id, time_created, time_updated, data) values
175
+ ('prt_user_large_1', 'msg_user_large_1', 'ses_large_1', 1100, 1100, json_object('type', 'text', 'text', (select value from large_text))),
176
+ ('prt_assistant_large_1', 'msg_assistant_large_1', 'ses_large_1', 1200, 1300, json_object('type', 'text', 'text', (select value from large_text)));
177
+ `,
178
+ ]);
179
+ }
180
+
181
+ function readJson(file) {
182
+ return JSON.parse(fs.readFileSync(file, "utf8"));
183
+ }
184
+
185
+ function readJsonl(file) {
186
+ const text = fs.readFileSync(file, "utf8").trim();
187
+ if (!text) return [];
188
+ return text.split("\n").map((line) => JSON.parse(line));
189
+ }
190
+
191
+ test("collector stages execution trees, per-session detail, and cursor artifacts", () => {
192
+ const tmp = makeTempDir();
193
+ const dbPath = path.join(tmp, "opencode.db");
194
+ const rawDir = path.join(tmp, "raw");
195
+ const outDir = path.join(tmp, "out");
196
+ fs.mkdirSync(rawDir, { recursive: true });
197
+ fs.mkdirSync(outDir, { recursive: true });
198
+
199
+ createFixtureDb(dbPath);
200
+ writeJson(path.join(rawDir, "ses_root_1.json"), [
201
+ {
202
+ file: "lib/example.dart",
203
+ patch: "Index: lib/example.dart",
204
+ },
205
+ ]);
206
+ fs.writeFileSync(path.join(rawDir, "ses_noise.json"), "[]", "utf8");
207
+
208
+ const result = spawnSync(
209
+ process.execPath,
210
+ [
211
+ "scripts/collect-session-evidence.mjs",
212
+ "--output-dir",
213
+ outDir,
214
+ "--source",
215
+ dbPath,
216
+ "--source",
217
+ rawDir,
218
+ ],
219
+ {
220
+ cwd: root,
221
+ encoding: "utf8",
222
+ },
223
+ );
224
+
225
+ assert.equal(result.status, 0, result.stderr);
226
+
227
+ const summary = readJson(path.join(outDir, "session-sources.summary.json"));
228
+ const sessions = readJsonl(path.join(outDir, "normalized-sessions.jsonl"));
229
+ const trees = readJsonl(path.join(outDir, "execution-trees.jsonl"));
230
+ const cursor = readJson(path.join(outDir, "cursor.json"));
231
+
232
+ assert.equal(summary.sources.length, 2);
233
+ assert.equal(summary.sources[0].format, "opencode-sqlite");
234
+ assert.equal(summary.sources[0].accepted, 4);
235
+ assert.equal(summary.sources[1].format, "opencode-raw-json");
236
+ assert.equal(summary.sources[1].accepted, 1);
237
+ assert.equal(summary.sources[1].skipped, 1);
238
+ assert.equal(summary.sources[1].skip_reasons.empty_array, 1);
239
+
240
+ assert.equal(sessions.length, 4);
241
+ assert.deepEqual(
242
+ sessions.map((row) => row.session_id).sort(),
243
+ ["ses_child_1", "ses_grandchild_1", "ses_root_1", "ses_root_2"],
244
+ );
245
+
246
+ assert.equal(trees.length, 2);
247
+ const treeOne = trees.find((row) => row.execution_tree_id === "ses_root_1");
248
+ const treeTwo = trees.find((row) => row.execution_tree_id === "ses_root_2");
249
+ assert.ok(treeOne);
250
+ assert.ok(treeTwo);
251
+
252
+ assert.equal(treeOne.session_count, 3);
253
+ assert.deepEqual(treeOne.participating_agents, ["lead", "researcher", "reviewer"]);
254
+ assert.equal(treeOne.tree_time_created_min, 1000);
255
+ assert.equal(treeOne.tree_time_updated_max, 2200);
256
+ assert.equal(treeOne.aggregate_cost, 2.25);
257
+ assert.equal(treeOne.aggregate_tokens.input, 195);
258
+ assert.equal(treeOne.aggregate_tokens.output, 70);
259
+ assert.equal(treeOne.root_session.session_id, "ses_root_1");
260
+ assert.equal(treeOne.child_sessions.length, 2);
261
+ assert.deepEqual(
262
+ treeOne.child_sessions.map((row) => row.session_id),
263
+ ["ses_child_1", "ses_grandchild_1"],
264
+ );
265
+ assert.equal(treeOne.representative_user_prompt, "Investigate the harness issue carefully.");
266
+ assert.equal(treeOne.representative_assistant_summary, "Reviewer findings for the harness issue.");
267
+ assert.deepEqual(treeOne.supplemental_raw_session_ids, ["ses_root_1"]);
268
+
269
+ assert.equal(treeTwo.session_count, 1);
270
+ assert.deepEqual(treeTwo.participating_agents, ["developer"]);
271
+ assert.equal(treeTwo.tree_time_updated_max, 3000);
272
+ assert.deepEqual(treeTwo.supplemental_raw_session_ids, []);
273
+
274
+ assert.equal(cursor.cursor_mode, "execution_tree_incremental");
275
+ assert.equal(cursor.cursor_start, null);
276
+ assert.equal(cursor.cursor_end_time_updated_max, 3000);
277
+ assert.equal(cursor.cursor_end_root_session_id, "ses_root_2");
278
+ assert.equal(cursor.trees_discovered, 2);
279
+ assert.equal(cursor.trees_accepted, 2);
280
+ assert.equal(cursor.trees_skipped, 0);
281
+ assert.equal(cursor.supplemental_raw_summary.accepted, 1);
282
+ assert.equal(cursor.supplemental_raw_summary.unmatched, 0);
283
+ });
284
+
285
+ test("collector uses prior iteration cursor to ingest only updated execution trees", () => {
286
+ const tmp = makeTempDir();
287
+ const dbPath = path.join(tmp, "opencode.db");
288
+ const runsDir = path.join(tmp, "docs", "ai", "evolution", "runs");
289
+ const iterationOne = path.join(runsDir, "iteration-001", "raw");
290
+ const iterationTwo = path.join(runsDir, "iteration-002", "raw");
291
+ fs.mkdirSync(iterationOne, { recursive: true });
292
+ fs.mkdirSync(iterationTwo, { recursive: true });
293
+
294
+ createFixtureDb(dbPath);
295
+
296
+ const firstRun = spawnSync(
297
+ process.execPath,
298
+ [
299
+ path.join(root, "scripts", "collect-session-evidence.mjs"),
300
+ "--iteration",
301
+ "iteration-001",
302
+ "--source",
303
+ dbPath,
304
+ ],
305
+ {
306
+ cwd: tmp,
307
+ encoding: "utf8",
308
+ },
309
+ );
310
+ assert.equal(firstRun.status, 0, firstRun.stderr);
311
+
312
+ run("sqlite3", [
313
+ dbPath,
314
+ `
315
+ update session set time_updated = 3400 where id = 'ses_child_1';
316
+ insert into session (
317
+ id, project_id, parent_id, slug, directory, title, version, time_created, time_updated, path, agent, model, cost, tokens_input, tokens_output, tokens_reasoning, tokens_cache_read, tokens_cache_write
318
+ ) values (
319
+ 'ses_root_3', 'proj_1', null, 'fresh-otter', '/tmp/repo', 'Brand new orchestration', '1.15.12', 4000, 4000, '', 'lead',
320
+ '{"id":"gpt-5.4","providerID":"openai","variant":"medium"}', 1.0, 30, 5, 0, 0, 0
321
+ );
322
+ insert into message (id, session_id, time_created, time_updated, data) values
323
+ ('msg_user_root_3', 'ses_root_3', 4000, 4000, '{"role":"user","time":{"created":4000}}'),
324
+ ('msg_assistant_root_3', 'ses_root_3', 4100, 4200, '{"role":"assistant","time":{"created":4100,"completed":4200},"finish":"stop"}');
325
+ insert into part (id, message_id, session_id, time_created, time_updated, data) values
326
+ ('prt_user_root_3', 'msg_user_root_3', 'ses_root_3', 4000, 4000, '{"type":"text","text":"Investigate the newest run."}'),
327
+ ('prt_assistant_root_3', 'msg_assistant_root_3', 'ses_root_3', 4100, 4200, '{"type":"text","text":"Newest run summarized."}');
328
+ `,
329
+ ]);
330
+
331
+ const secondRun = spawnSync(
332
+ process.execPath,
333
+ [
334
+ path.join(root, "scripts", "collect-session-evidence.mjs"),
335
+ "--iteration",
336
+ "iteration-002",
337
+ "--source",
338
+ dbPath,
339
+ ],
340
+ {
341
+ cwd: tmp,
342
+ encoding: "utf8",
343
+ },
344
+ );
345
+ assert.equal(secondRun.status, 0, secondRun.stderr);
346
+
347
+ const trees = readJsonl(path.join(iterationTwo, "execution-trees.jsonl"));
348
+ const cursor = readJson(path.join(iterationTwo, "cursor.json"));
349
+
350
+ assert.equal(trees.length, 2);
351
+ assert.deepEqual(
352
+ trees.map((row) => row.execution_tree_id).sort(),
353
+ ["ses_root_1", "ses_root_3"],
354
+ );
355
+
356
+ const updatedTree = trees.find((row) => row.execution_tree_id === "ses_root_1");
357
+ assert.equal(updatedTree.tree_time_updated_max, 3400);
358
+ assert.deepEqual(
359
+ updatedTree.child_sessions.map((row) => row.session_id),
360
+ ["ses_child_1", "ses_grandchild_1"],
361
+ );
362
+
363
+ // M1 guard: a re-activated tree whose sessions were created before the cursor
364
+ // has its messages/parts dropped by the SQL cutoff filter. The collector must
365
+ // mark this explicitly so consumers don't trust incomplete content:
366
+ // - message_count is null (not 0) for filtered sessions
367
+ // - content_filtered: true on the row and the tree
368
+ // - representative prompts stay null
369
+ // Without this guard, message_count: 0 reads as "no messages" instead of
370
+ // "filtered by cutoff", silently degrading evidence.
371
+ const sessions = readJsonl(path.join(iterationTwo, "normalized-sessions.jsonl"));
372
+ const reactivatedSessionIds = ["ses_root_1", "ses_child_1", "ses_grandchild_1"];
373
+ const reactivatedRows = sessions.filter((row) => reactivatedSessionIds.includes(row.session_id));
374
+ assert.equal(reactivatedRows.length, 3);
375
+ for (const row of reactivatedRows) {
376
+ assert.equal(row.content_filtered, true, `${row.session_id} should be content_filtered`);
377
+ assert.equal(row.message_count, null, `${row.session_id} message_count should be null, not 0`);
378
+ assert.equal(row.user_prompt, null);
379
+ assert.equal(row.assistant_summary, null);
380
+ }
381
+ assert.equal(updatedTree.content_filtered, true);
382
+ assert.equal(updatedTree.representative_user_prompt, null);
383
+ assert.equal(updatedTree.representative_assistant_summary, null);
384
+
385
+ // ses_root_3 was created after the cursor: content is complete, not filtered.
386
+ const freshTree = trees.find((row) => row.execution_tree_id === "ses_root_3");
387
+ assert.ok(freshTree);
388
+ assert.equal(freshTree.content_filtered, false);
389
+ assert.equal(freshTree.representative_user_prompt, "Investigate the newest run.");
390
+ const freshSession = sessions.find((row) => row.session_id === "ses_root_3");
391
+ assert.equal(freshSession.content_filtered, false);
392
+ assert.equal(freshSession.message_count, 2);
393
+
394
+ assert.deepEqual(cursor.cursor_start, {
395
+ time_updated_max: 3000,
396
+ root_session_id: "ses_root_2",
397
+ });
398
+ assert.equal(cursor.cursor_end_time_updated_max, 4000);
399
+ assert.equal(cursor.cursor_end_root_session_id, "ses_root_3");
400
+ assert.equal(cursor.trees_discovered, 3);
401
+ assert.equal(cursor.trees_accepted, 2);
402
+ assert.equal(cursor.trees_skipped, 1);
403
+ assert.equal(cursor.tree_skip_reasons.before_cursor, 1);
404
+ });
405
+
406
+ test("collector handles larger sqlite JSON payloads without buffer failure", () => {
407
+ const tmp = makeTempDir();
408
+ const dbPath = path.join(tmp, "opencode.db");
409
+ const outDir = path.join(tmp, "out");
410
+ fs.mkdirSync(outDir, { recursive: true });
411
+
412
+ createLargeFixtureDb(dbPath);
413
+
414
+ const result = spawnSync(process.execPath, ["scripts/collect-session-evidence.mjs", "--output-dir", outDir, "--source", dbPath], {
415
+ cwd: root,
416
+ encoding: "utf8",
417
+ });
418
+
419
+ assert.equal(result.status, 0, result.stderr);
420
+ const trees = readJsonl(path.join(outDir, "execution-trees.jsonl"));
421
+ assert.equal(trees.length, 1);
422
+ assert.equal(trees[0].execution_tree_id, "ses_large_1");
423
+ assert.match(trees[0].representative_user_prompt, /^Evidence payload /);
424
+ });
425
+
426
+ test("streamSqliteJson rejects on sqlite3 runtime error (non-zero exit)", async () => {
427
+ // Invoke the collector with a DB that has no session table — sqlite3 will exit 1.
428
+ const tmp = makeTempDir();
429
+ const dbPath = path.join(tmp, "empty.db");
430
+ run("sqlite3", [dbPath, "create table dummy(id text);"]);
431
+ const outDir = path.join(tmp, "out");
432
+ fs.mkdirSync(outDir, { recursive: true });
433
+
434
+ const result = spawnSync(
435
+ process.execPath,
436
+ ["scripts/collect-session-evidence.mjs", "--output-dir", outDir, "--source", dbPath],
437
+ { cwd: root, encoding: "utf8" },
438
+ );
439
+
440
+ // The script should exit non-zero because the session table is missing.
441
+ assert.notEqual(result.status, 0);
442
+ assert.match(result.stderr, /sqlite3 runtime error|session/);
443
+ });