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.
- package/.github/CODEOWNERS +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +65 -0
- package/.github/ISSUE_TEMPLATE/config.yml +11 -0
- package/.github/ISSUE_TEMPLATE/documentation.yml +22 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +43 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +25 -0
- package/.github/workflows/check.yml +47 -0
- package/CODE_OF_CONDUCT.md +24 -0
- package/CONTRIBUTING.md +52 -0
- package/LICENSE +201 -0
- package/NOTICE.md +23 -0
- package/README.md +806 -0
- package/SECURITY.md +17 -0
- package/docker/open-design/.env.example +6 -0
- package/docker/open-design/Dockerfile +50 -0
- package/docker/open-design/docker-compose.yml +18 -0
- package/docker/open-design/opencode-od/agents/od-worker.md +22 -0
- package/docker/open-design/opencode-od/opencode.json +24 -0
- package/docs/agents.md +21 -0
- package/docs/commands.md +16 -0
- package/docs/configuration.md +30 -0
- package/docs/docker-open-design.md +42 -0
- package/docs/impeccable.md +18 -0
- package/docs/installation.md +176 -0
- package/docs/models.md +17 -0
- package/docs/open-design.md +25 -0
- package/docs/quickstart.md +74 -0
- package/docs/releases/v1.0.10.md +46 -0
- package/docs/releases/v1.0.14.md +39 -0
- package/docs/releases/v1.0.27.md +66 -0
- package/docs/security.md +8 -0
- package/docs/superpowers/plans/2026-07-20-safe-installation-lifecycle.md +779 -0
- package/docs/superpowers/plans/2026-07-20-version-identity-and-releases.md +590 -0
- package/docs/superpowers/specs/2026-07-20-safe-installation-lifecycle-design.md +1350 -0
- package/docs/superpowers/specs/2026-07-20-version-identity-and-releases-design.md +557 -0
- package/docs/superpowers.md +34 -0
- package/docs/synology.md +30 -0
- package/docs/troubleshooting.md +54 -0
- package/docs/workflows.md +44 -0
- package/doctor.sh +5 -0
- package/env.example +15 -0
- package/install.sh +5 -0
- package/opencode/AGENTS.md +104 -0
- package/opencode/agents/debugger.md +41 -0
- package/opencode/agents/designer.md +93 -0
- package/opencode/agents/developer.md +180 -0
- package/opencode/agents/evaluator.md +35 -0
- package/opencode/agents/evolver.md +31 -0
- package/opencode/agents/lead.md +251 -0
- package/opencode/agents/researcher.md +76 -0
- package/opencode/agents/review_api.md +34 -0
- package/opencode/agents/review_coordinator.md +111 -0
- package/opencode/agents/review_quality.md +35 -0
- package/opencode/agents/review_security.md +35 -0
- package/opencode/agents/review_tests.md +37 -0
- package/opencode/agents/reviewer.md +116 -0
- package/opencode/agents/scoper.md +75 -0
- package/opencode/agents/specifier.md +116 -0
- package/opencode/commands/code-simplify.md +36 -0
- package/opencode/commands/design.md +27 -0
- package/opencode/commands/evolve.md +165 -0
- package/opencode/commands/feature.md +67 -0
- package/opencode/commands/implement.md +11 -0
- package/opencode/commands/init.md +34 -0
- package/opencode/commands/loop.md +145 -0
- package/opencode/commands/mvp-spec.md +20 -0
- package/opencode/commands/plan.md +74 -0
- package/opencode/commands/research.md +12 -0
- package/opencode/commands/review-orchestrated.md +47 -0
- package/opencode/commands/review-preflight.md +26 -0
- package/opencode/commands/review.md +18 -0
- package/opencode/commands/scope.md +36 -0
- package/opencode/commands/spec.md +12 -0
- package/opencode/commands/test.md +40 -0
- package/opencode/docs/ai/evolution/README.md +135 -0
- package/opencode/docs/ai/evolution/benchmarks/manual-scenarios.md +123 -0
- package/opencode/docs/ai/evolution/benchmarks/router-scenarios.jsonl +8 -0
- package/opencode/docs/ai/evolution/evolution_history.md +83 -0
- package/opencode/docs/ai/evolution/mechanisms.jsonl +7 -0
- package/opencode/docs/ai/evolution/rejected_mechanisms.jsonl +2 -0
- package/opencode/docs/ai/evolution/runs/README.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/analysis/overview.md +12 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_evaluation.json +108 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_manifest.json +52 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/evaluation.md +19 -0
- package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/post_evaluation.md +12 -0
- package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/analysis/overview.md +7 -0
- package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/change_evaluation.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/evaluation.md +19 -0
- package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_evaluation.json +66 -0
- package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_manifest.json +82 -0
- package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/evaluation.md +20 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/ahe-run-lifecycle-validator.md +40 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/evolve-evaluation-only-contract.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/open-design-tool-contract.md +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/slash-command-contract-coverage.md +40 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/overview.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/pre_apply_approval.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_evaluation.json +252 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_manifest.json +210 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/evaluation.md +25 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_apply_evaluation.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_manifest_evaluation.md +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/pre_apply_evaluation.md +15 -0
- package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_manifest.json +30 -0
- package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/evaluation.md +25 -0
- package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_manifest.json +29 -0
- package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/evaluation.md +18 -0
- package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_manifest.json +34 -0
- package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/evaluation.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_evaluation.json +12 -0
- package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_manifest.json +28 -0
- package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/evaluation.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/analysis/overview.md +9 -0
- package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_manifest.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/evaluation.md +18 -0
- package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/analysis/overview.md +12 -0
- package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_manifest.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/evaluation.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/analysis/overview.md +10 -0
- package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_evaluation.json +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_manifest.json +30 -0
- package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/evaluation.md +17 -0
- package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/analysis/overview.md +25 -0
- package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_evaluation.json +28 -0
- package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_manifest.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/evaluation.md +22 -0
- package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/analysis/overview.md +27 -0
- package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_evaluation.json +32 -0
- package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_manifest.json +49 -0
- package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/evaluation.md +92 -0
- package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/detail/token-vs-semantic.md +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/overview.md +14 -0
- package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/evaluation.md +36 -0
- package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/analysis/overview.md +13 -0
- package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_evaluation.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_manifest.json +47 -0
- package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/evaluation.md +27 -0
- package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/analysis/overview.md +32 -0
- package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_evaluation.json +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_manifest.json +35 -0
- package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/evaluation.md +31 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-1-feature-sidecar-false-positive.md +51 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-2-checker-time-budget.md +52 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/overview.md +99 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_evaluation.json +61 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_manifest.json +61 -0
- package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/evaluation.md +448 -0
- package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/detail/intake-gray-zone.md +65 -0
- package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/overview.md +172 -0
- package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/evaluation.md +226 -0
- package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/detail/plan-only-gray-zone.md +62 -0
- package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/overview.md +167 -0
- package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/evaluation.md +163 -0
- package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/analysis/overview.md +42 -0
- package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_evaluation.json +46 -0
- package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_manifest.json +57 -0
- package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/evaluation.md +48 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/contract-vs-runtime-gap.md +163 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/evidence-collection-blocker.md +134 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/analysis/overview.md +111 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/change_evaluation.json +52 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/change_manifest.json +50 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/evaluation.md +46 -0
- package/opencode/docs/ai/evolution/runs/iteration-021/manifest-justification.md +48 -0
- package/opencode/docs/ai/evolution/session-sources.md +91 -0
- package/opencode/docs/ai/harness/README.md +32 -0
- package/opencode/docs/ai/harness/agents.md +148 -0
- package/opencode/docs/ai/harness/checks.md +119 -0
- package/opencode/docs/ai/harness/commands.md +391 -0
- package/opencode/docs/ai/harness/evidence.md +85 -0
- package/opencode/docs/ai/harness/init-detection-rules.md +160 -0
- package/opencode/docs/ai/harness/orchestrated-review.md +131 -0
- package/opencode/docs/ai/harness/skill-metadata-schema.md +198 -0
- package/opencode/docs/ai/harness/skill-resolution.md +202 -0
- package/opencode/docs/ai/harness/skill_registry.json +443 -0
- package/opencode/docs/ai/harness/skill_registry.md +43 -0
- package/opencode/docs/ai/project-context-template.md +53 -0
- package/opencode/opencode.json +38 -0
- package/opencode/package-lock.json +1717 -0
- package/opencode/package.json +11 -0
- package/opencode/plugins/token-tree-usage.tsx +206 -0
- package/opencode/references/performance-checklist.md +153 -0
- package/opencode/references/security-checklist.md +134 -0
- package/opencode/references/testing-patterns.md +236 -0
- package/opencode/scripts/check-harness.mjs +1572 -0
- package/opencode/scripts/check-harness.test.mjs +820 -0
- package/opencode/scripts/collect-session-evidence.mjs +612 -0
- package/opencode/scripts/collect-session-evidence.test.mjs +443 -0
- package/opencode/scripts/preflight-audit.mjs +497 -0
- package/opencode/scripts/preflight-audit.test.mjs +363 -0
- package/opencode/scripts/project-capability-snapshot.mjs +407 -0
- package/opencode/scripts/project-capability-snapshot.test.mjs +382 -0
- package/opencode/scripts/review-orchestrated-prepare.mjs +547 -0
- package/opencode/scripts/review-orchestrated-prepare.test.mjs +516 -0
- package/opencode/scripts/skill-resolver.mjs +585 -0
- package/opencode/scripts/skill-resolver.test.mjs +781 -0
- package/opencode/scripts/update-skill-registry.mjs +380 -0
- package/opencode/skills/api-and-interface-design/SKILL.md +315 -0
- package/opencode/skills/autonomous-loops/SKILL.md +312 -0
- package/opencode/skills/code-review-and-quality/SKILL.md +365 -0
- package/opencode/skills/code-simplification/SKILL.md +345 -0
- package/opencode/skills/context-engineering/SKILL.md +252 -0
- package/opencode/skills/debugging-and-error-recovery/SKILL.md +316 -0
- package/opencode/skills/documentation-and-adrs/SKILL.md +298 -0
- package/opencode/skills/doubt-driven-development/SKILL.md +168 -0
- package/opencode/skills/iterative-retrieval/SKILL.md +232 -0
- package/opencode/skills/open-design/SKILL.md +123 -0
- package/opencode/skills/performance-optimization/SKILL.md +365 -0
- package/opencode/skills/security-and-hardening/SKILL.md +369 -0
- package/opencode/skills/source-driven-development/SKILL.md +210 -0
- package/opencode/skills/test-driven-development/SKILL.md +406 -0
- package/opencode/skills/using-agent-skills/SKILL.md +194 -0
- package/opencode/skills/verification-loop/SKILL.md +162 -0
- package/opencode/tools/open_design.ts +361 -0
- package/opencode/tui.json +5 -0
- package/package.json +20 -0
- package/rollback.sh +5 -0
- package/scripts/check.sh +184 -0
- package/scripts/install-smoke.sh +111 -0
- package/scripts/manage-installation.mjs +1498 -0
- package/scripts/manage-installation.test.mjs +1936 -0
- package/scripts/version.mjs +197 -0
- package/scripts/version.test.mjs +195 -0
- package/uninstall.sh +5 -0
- package/upgrade.sh +5 -0
|
@@ -0,0 +1,1572 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
const root = process.cwd();
|
|
7
|
+
const errors = [];
|
|
8
|
+
|
|
9
|
+
function read(rel) {
|
|
10
|
+
return fs.readFileSync(path.join(root, rel), "utf8");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function exists(rel) {
|
|
14
|
+
return fs.existsSync(path.join(root, rel));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function listMarkdown(dir) {
|
|
18
|
+
return fs
|
|
19
|
+
.readdirSync(path.join(root, dir))
|
|
20
|
+
.filter((file) => file.endsWith(".md"))
|
|
21
|
+
.map((file) => path.join(dir, file));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function stripMarkdownExtension(rel) {
|
|
25
|
+
return path.basename(rel, ".md");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function fail(message) {
|
|
29
|
+
errors.push(message);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseJson(rel) {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(read(rel));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
fail(`${rel}: invalid JSON (${error.message})`);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseFrontmatter(rel) {
|
|
42
|
+
const text = read(rel);
|
|
43
|
+
if (!text.startsWith("---\n")) {
|
|
44
|
+
fail(`${rel}: missing frontmatter`);
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const end = text.indexOf("\n---", 4);
|
|
49
|
+
if (end === -1) {
|
|
50
|
+
fail(`${rel}: unclosed frontmatter`);
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const data = {};
|
|
55
|
+
const block = text.slice(4, end).split("\n");
|
|
56
|
+
for (const line of block) {
|
|
57
|
+
if (!line.trim()) continue;
|
|
58
|
+
if (/^\s/.test(line)) continue;
|
|
59
|
+
const match = line.match(/^([A-Za-z_][A-Za-z0-9_-]*):\s*(.*)$/);
|
|
60
|
+
if (!match) {
|
|
61
|
+
fail(`${rel}: malformed frontmatter line "${line}"`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
data[match[1]] = match[2].replace(/^"(.*)"$/, "$1");
|
|
65
|
+
}
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function frontmatterBlock(rel) {
|
|
70
|
+
const text = read(rel);
|
|
71
|
+
if (!text.startsWith("---\n")) return "";
|
|
72
|
+
const end = text.indexOf("\n---", 4);
|
|
73
|
+
if (end === -1) return "";
|
|
74
|
+
return text.slice(4, end);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function requireFields(rel, object, fields) {
|
|
78
|
+
for (const field of fields) {
|
|
79
|
+
if (!object[field]) fail(`${rel}: missing ${field}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function checkAgentsIndex() {
|
|
84
|
+
const text = read("AGENTS.md");
|
|
85
|
+
const nonBlankLines = text.split("\n").filter((line) => line.trim()).length;
|
|
86
|
+
const maxNonBlankLines = 120;
|
|
87
|
+
|
|
88
|
+
if (nonBlankLines > maxNonBlankLines) {
|
|
89
|
+
fail(`AGENTS.md: must stay a short index (${nonBlankLines}/${maxNonBlankLines} non-blank lines)`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (const token of ["docs/ai/harness/", "docs/ai/evolution/"]) {
|
|
93
|
+
if (!text.includes(token)) fail(`AGENTS.md: missing index reference ${token}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function checkAgentDocsCoverage() {
|
|
98
|
+
const docs = read("docs/ai/harness/agents.md");
|
|
99
|
+
for (const rel of listMarkdown("agents")) {
|
|
100
|
+
const agent = stripMarkdownExtension(rel);
|
|
101
|
+
if (!docs.includes(`\`${agent}\``)) {
|
|
102
|
+
fail(`docs/ai/harness/agents.md: missing documented agent \`${agent}\``);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function checkCommandDocsCoverage() {
|
|
108
|
+
const docs = read("docs/ai/harness/commands.md");
|
|
109
|
+
for (const rel of listMarkdown("commands")) {
|
|
110
|
+
const command = stripMarkdownExtension(rel);
|
|
111
|
+
if (!docs.includes(`/${command}`)) {
|
|
112
|
+
fail(`docs/ai/harness/commands.md: missing documented command /${command}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function checkLoopContract() {
|
|
118
|
+
const rel = "commands/loop.md";
|
|
119
|
+
if (!exists(rel)) {
|
|
120
|
+
fail(`${rel}: missing command`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const text = read(rel);
|
|
125
|
+
const required = [
|
|
126
|
+
"approval_gate: explicit_before_writes",
|
|
127
|
+
"max_iterations_per_invocation: 3",
|
|
128
|
+
"completion_authority: reviewer_only",
|
|
129
|
+
"state_path: .opencode/loops/<slug>.md",
|
|
130
|
+
"worktree_mode: explicit_opt_in",
|
|
131
|
+
"developer -> reviewer -> developer (state sync)",
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
for (const token of required) {
|
|
135
|
+
if (!text.includes(token)) fail(`${rel}: missing ${token}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function checkFrontmatter() {
|
|
140
|
+
for (const rel of listMarkdown("agents")) {
|
|
141
|
+
requireFields(rel, parseFrontmatter(rel), ["description", "mode"]);
|
|
142
|
+
}
|
|
143
|
+
for (const rel of listMarkdown("commands")) {
|
|
144
|
+
requireFields(rel, parseFrontmatter(rel), ["description", "agent"]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function checkOrchestratedReviewContract() {
|
|
149
|
+
const preflightCommandRel = "commands/review-preflight.md";
|
|
150
|
+
const commandRel = "commands/review-orchestrated.md";
|
|
151
|
+
const docRel = "docs/ai/harness/orchestrated-review.md";
|
|
152
|
+
const prepareRel = "scripts/review-orchestrated-prepare.mjs";
|
|
153
|
+
const prepareTestRel = "scripts/review-orchestrated-prepare.test.mjs";
|
|
154
|
+
|
|
155
|
+
for (const rel of [preflightCommandRel, commandRel, docRel, prepareRel, prepareTestRel]) {
|
|
156
|
+
if (!exists(rel)) fail(`${rel}: missing orchestrated review surface`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (exists("commands/review.md")) {
|
|
160
|
+
const review = read("commands/review.md");
|
|
161
|
+
for (const token of ["agent: reviewer", "Review the current diff", "git diff"]) {
|
|
162
|
+
if (!review.includes(token)) fail(`commands/review.md: existing /review contract changed or missing ${token}`);
|
|
163
|
+
}
|
|
164
|
+
if (review.includes("review_coordinator") || review.includes("review-orchestrated")) {
|
|
165
|
+
fail("commands/review.md: /review must not invoke orchestrated review");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (exists(preflightCommandRel)) {
|
|
170
|
+
const command = read(preflightCommandRel);
|
|
171
|
+
for (const token of [
|
|
172
|
+
"agent: lead",
|
|
173
|
+
"recommended daily path",
|
|
174
|
+
"rtk node scripts/review-orchestrated-prepare.mjs --dry-run",
|
|
175
|
+
"manifest.json",
|
|
176
|
+
"shared-review-context.md",
|
|
177
|
+
"patches/",
|
|
178
|
+
"findings/",
|
|
179
|
+
"Do not invoke reviewers",
|
|
180
|
+
"Do not claim an AI review was performed",
|
|
181
|
+
"Do not ask follow-up questions",
|
|
182
|
+
]) {
|
|
183
|
+
if (!command.includes(token)) fail(`${preflightCommandRel}: missing ${token}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (exists(commandRel)) {
|
|
188
|
+
const command = read(commandRel);
|
|
189
|
+
for (const token of [
|
|
190
|
+
"agent: review_coordinator",
|
|
191
|
+
"node scripts/review-orchestrated-prepare.mjs $ARGUMENTS",
|
|
192
|
+
"manifest.json",
|
|
193
|
+
"shared-review-context.md",
|
|
194
|
+
"patches/",
|
|
195
|
+
"findings/",
|
|
196
|
+
"untrusted data",
|
|
197
|
+
"--dry-run",
|
|
198
|
+
"--agents",
|
|
199
|
+
"--full-agents",
|
|
200
|
+
"Do not invoke `task`",
|
|
201
|
+
"do not write or list `findings/`",
|
|
202
|
+
"at most one finding",
|
|
203
|
+
"Do not use `git diff`",
|
|
204
|
+
"--reviewer-timeout-ms",
|
|
205
|
+
"--retain",
|
|
206
|
+
"Do not claim an AI review was performed",
|
|
207
|
+
"preflight_only",
|
|
208
|
+
"Do not ask follow-up questions",
|
|
209
|
+
"Always enumerate `review_quality`",
|
|
210
|
+
"skipped",
|
|
211
|
+
"lite",
|
|
212
|
+
]) {
|
|
213
|
+
if (!command.includes(token)) fail(`${commandRel}: missing ${token}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const agentRels = [
|
|
218
|
+
"agents/review_coordinator.md",
|
|
219
|
+
"agents/review_quality.md",
|
|
220
|
+
"agents/review_security.md",
|
|
221
|
+
"agents/review_tests.md",
|
|
222
|
+
"agents/review_api.md",
|
|
223
|
+
];
|
|
224
|
+
for (const rel of agentRels) {
|
|
225
|
+
if (!exists(rel)) {
|
|
226
|
+
fail(`${rel}: missing orchestrated review agent`);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const text = read(rel);
|
|
230
|
+
const frontmatter = frontmatterBlock(rel);
|
|
231
|
+
if (!/^\s*edit:\s*deny\s*$/m.test(frontmatter)) {
|
|
232
|
+
fail(`${rel}: review agents must be read-only`);
|
|
233
|
+
}
|
|
234
|
+
for (const token of ["manifest.json", "shared-review-context.md", "patches/", "findings/"]) {
|
|
235
|
+
if (!text.includes(token)) fail(`${rel}: missing workspace token ${token}`);
|
|
236
|
+
}
|
|
237
|
+
for (const token of ["untrusted data", "instructions", "diff"]) {
|
|
238
|
+
if (!text.toLowerCase().includes(token)) fail(`${rel}: missing anti-injection token ${token}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (exists("agents/review_coordinator.md")) {
|
|
243
|
+
const coordinator = read("agents/review_coordinator.md");
|
|
244
|
+
const coordinatorFrontmatter = frontmatterBlock("agents/review_coordinator.md");
|
|
245
|
+
if (!/^\s*mode:\s*primary\s*$/m.test(coordinatorFrontmatter)) {
|
|
246
|
+
fail("agents/review_coordinator.md: --agents must run in the primary coordinator session without a wrapper task");
|
|
247
|
+
}
|
|
248
|
+
if (!/^\s*"ls\*":\s*allow\s*$/m.test(coordinatorFrontmatter)) {
|
|
249
|
+
fail("agents/review_coordinator.md: harmless preparer existence checks must not abort --agents");
|
|
250
|
+
}
|
|
251
|
+
for (const token of [
|
|
252
|
+
"node scripts/review-orchestrated-prepare.mjs*",
|
|
253
|
+
"node ./scripts/review-orchestrated-prepare.mjs*",
|
|
254
|
+
"node *scripts/review-orchestrated-prepare.mjs*",
|
|
255
|
+
"Use a relative path",
|
|
256
|
+
"Call the preparer exactly once",
|
|
257
|
+
"execution_plan.mode",
|
|
258
|
+
"preflight_only",
|
|
259
|
+
"--agents",
|
|
260
|
+
"--full-agents",
|
|
261
|
+
"Do not invoke `task`",
|
|
262
|
+
"do not write or list `findings/`",
|
|
263
|
+
"at most one finding",
|
|
264
|
+
"Do not run `git diff`",
|
|
265
|
+
"timed_out",
|
|
266
|
+
"always enumerate all four reviewers",
|
|
267
|
+
]) {
|
|
268
|
+
if (!coordinator.includes(token)) fail(`agents/review_coordinator.md: missing preparer permission/routing token ${token}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (exists(docRel)) {
|
|
273
|
+
const doc = read(docRel);
|
|
274
|
+
for (const token of [
|
|
275
|
+
"manifest.json",
|
|
276
|
+
"shared-review-context.md",
|
|
277
|
+
"patches/",
|
|
278
|
+
"findings/",
|
|
279
|
+
"/review-preflight",
|
|
280
|
+
"BEGIN_UNTRUSTED_PATCH_DATA",
|
|
281
|
+
"END_UNTRUSTED_PATCH_DATA",
|
|
282
|
+
"--base",
|
|
283
|
+
"--staged",
|
|
284
|
+
"--include-untracked",
|
|
285
|
+
"--dry-run",
|
|
286
|
+
"--agents",
|
|
287
|
+
"--full-agents",
|
|
288
|
+
"--reviewer-timeout-ms",
|
|
289
|
+
"--retain",
|
|
290
|
+
"staged + unstaged",
|
|
291
|
+
"untracked",
|
|
292
|
+
"lockfiles",
|
|
293
|
+
"does not open filtered files or run an alternate diff",
|
|
294
|
+
"sourcemaps",
|
|
295
|
+
"minified",
|
|
296
|
+
"Database migrations are not automatically excluded",
|
|
297
|
+
"max_reviewers",
|
|
298
|
+
"max_patch_bytes_per_reviewer",
|
|
299
|
+
"max_total_patch_bytes",
|
|
300
|
+
"reviewer_patch_sets",
|
|
301
|
+
"dropped_patches",
|
|
302
|
+
"execution_plan",
|
|
303
|
+
"reviewer_timeout_ms",
|
|
304
|
+
"preflight_only",
|
|
305
|
+
"skipped",
|
|
306
|
+
"trivial",
|
|
307
|
+
"lite",
|
|
308
|
+
"full",
|
|
309
|
+
"no automatic provider failover",
|
|
310
|
+
"There is no remote control plane",
|
|
311
|
+
"Real concurrency is deferred",
|
|
312
|
+
"timed_out",
|
|
313
|
+
"workspace is cleaned by default",
|
|
314
|
+
"requires_human_verification",
|
|
315
|
+
]) {
|
|
316
|
+
if (!doc.includes(token)) fail(`${docRel}: missing ${token}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (exists(prepareRel)) {
|
|
321
|
+
const prepare = read(prepareRel);
|
|
322
|
+
for (const token of [
|
|
323
|
+
"manifest.json",
|
|
324
|
+
"shared-review-context.md",
|
|
325
|
+
"patches",
|
|
326
|
+
"findings",
|
|
327
|
+
"BEGIN_UNTRUSTED_PATCH_DATA",
|
|
328
|
+
"END_UNTRUSTED_PATCH_DATA",
|
|
329
|
+
"max_reviewers",
|
|
330
|
+
"max_patch_bytes_per_reviewer",
|
|
331
|
+
"max_total_patch_bytes",
|
|
332
|
+
"reviewer_timeout_ms",
|
|
333
|
+
"workspace_retention",
|
|
334
|
+
".opencode-review-",
|
|
335
|
+
"reviewer_patch_sets",
|
|
336
|
+
"dropped_patches",
|
|
337
|
+
"execution_plan",
|
|
338
|
+
"recommended_reviewers",
|
|
339
|
+
"timed_out_reviewers",
|
|
340
|
+
"include_untracked",
|
|
341
|
+
"untracked_files",
|
|
342
|
+
"filtered_files",
|
|
343
|
+
"generated_files",
|
|
344
|
+
"skipped_reason",
|
|
345
|
+
"hasHighRisk",
|
|
346
|
+
]) {
|
|
347
|
+
if (!prepare.includes(token)) fail(`${prepareRel}: missing ${token}`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (exists(prepareTestRel)) {
|
|
352
|
+
const tests = read(prepareTestRel);
|
|
353
|
+
for (const token of [
|
|
354
|
+
"doc-only",
|
|
355
|
+
"security and api",
|
|
356
|
+
"lockfiles and generated files",
|
|
357
|
+
"database migrations",
|
|
358
|
+
"untracked files",
|
|
359
|
+
"tests-only risk stays lite",
|
|
360
|
+
"auth permission changes plan the security reviewer",
|
|
361
|
+
"dependency manifests select security while lockfiles stay filtered",
|
|
362
|
+
"deleted regression tests plan the tests reviewer",
|
|
363
|
+
"default workspace is created inside the repo",
|
|
364
|
+
"per-reviewer patch budget",
|
|
365
|
+
"dry-run is a preflight-compatible alias",
|
|
366
|
+
"--agents mode plans at most one focused reviewer",
|
|
367
|
+
"--full-agents mode caps planned specialized reviewers at four",
|
|
368
|
+
"reviewer timeout and failure statuses",
|
|
369
|
+
"parseArgs rejects invalid invocation shapes",
|
|
370
|
+
"budget overflow",
|
|
371
|
+
"cleanup removes workspace",
|
|
372
|
+
]) {
|
|
373
|
+
if (!tests.includes(token)) fail(`${prepareTestRel}: missing scenario ${token}`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function checkConfig() {
|
|
379
|
+
const config = parseJson("opencode.json");
|
|
380
|
+
if (!config) return;
|
|
381
|
+
if (config.default_agent !== "lead") {
|
|
382
|
+
fail("opencode.json: default_agent must remain lead");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Verify that all given regex patterns match the text.
|
|
388
|
+
* Each pattern is either a RegExp, a string treated as literal, or an object
|
|
389
|
+
* with a regex and optional literal fallbacks.
|
|
390
|
+
*/
|
|
391
|
+
function checkSemantic(text, patterns, label) {
|
|
392
|
+
for (let i = 0; i < patterns.length; i++) {
|
|
393
|
+
const p = patterns[i];
|
|
394
|
+
const re =
|
|
395
|
+
p instanceof RegExp
|
|
396
|
+
? p
|
|
397
|
+
: p.regex instanceof RegExp
|
|
398
|
+
? p.regex
|
|
399
|
+
: new RegExp("\\b" + p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b", "i");
|
|
400
|
+
const fallbackLiterals = p.fallbackLiterals ?? [];
|
|
401
|
+
if (!re.test(text) && !fallbackLiterals.some((token) => text.includes(token))) {
|
|
402
|
+
const desc = p instanceof RegExp ? p.source : p.description ?? p.regex?.source ?? p;
|
|
403
|
+
fail(`${label}[${i}]: no match for /${desc}/`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function checkLeadRouterContract() {
|
|
409
|
+
const text = read("agents/lead.md");
|
|
410
|
+
const frontmatter = frontmatterBlock("agents/lead.md");
|
|
411
|
+
|
|
412
|
+
if (!/^\s*edit:\s*deny\s*$/m.test(frontmatter)) {
|
|
413
|
+
fail("agents/lead.md: lead edit permission must remain deny");
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
for (const command of [
|
|
417
|
+
'"cd": allow',
|
|
418
|
+
'"cd *": allow',
|
|
419
|
+
'"which": allow',
|
|
420
|
+
'"which *": allow',
|
|
421
|
+
]) {
|
|
422
|
+
if (!frontmatter.includes(command)) {
|
|
423
|
+
fail(`agents/lead.md: missing bash allow ${command}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// --- Structural tokens (exact literals, agent identifiers) ---
|
|
428
|
+
for (const token of [
|
|
429
|
+
"developer",
|
|
430
|
+
"researcher",
|
|
431
|
+
"designer",
|
|
432
|
+
"specifier",
|
|
433
|
+
"`researcher`",
|
|
434
|
+
"`reviewer`",
|
|
435
|
+
]) {
|
|
436
|
+
if (!text.includes(token)) fail(`agents/lead.md: missing ${token}`);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// --- Semantic tokens (flexible regex, 15 patterns) ---
|
|
440
|
+
checkSemantic(text, [
|
|
441
|
+
// C1: fast router
|
|
442
|
+
/\b(fast|quick|rapid|agile|lightweight)\s+router\b/i,
|
|
443
|
+
// B11: ask the user
|
|
444
|
+
/\b(ask|consult)\s+the\s+user\b/i,
|
|
445
|
+
// C2: real ambiguity
|
|
446
|
+
/\b(real|genuine|material|meaningful)\s+ambiguity\b/i,
|
|
447
|
+
// B1: Do not edit code
|
|
448
|
+
{
|
|
449
|
+
regex: /\bdo\s+not\s+(edit|modify|change|alter)\s+code\b/i,
|
|
450
|
+
fallbackLiterals: ["Do not edit code"],
|
|
451
|
+
},
|
|
452
|
+
// B9: ownership during the whole loop
|
|
453
|
+
/\b(whole|entire)\s+(loop|cycle)\s+of\s+the\s+same\s+free-form\s+request\b/i,
|
|
454
|
+
// B8: send a bounded task back to `developer`
|
|
455
|
+
/\b(send|return|route|pass)\s+a\s+bounded\s+(task|correction)\s+back\s+to\s+\`developer\`/i,
|
|
456
|
+
// B7: implementation correction goes back to `developer`
|
|
457
|
+
/\b(implementation\s+)?(correction|fix|adjustment|change)\s+goes\s+back\s+to\s+\`developer\`/i,
|
|
458
|
+
// B2: does not develop
|
|
459
|
+
{
|
|
460
|
+
regex: /\bdoes\s+not\s+(develop|code|implement|program)\b/i,
|
|
461
|
+
fallbackLiterals: ["does not develop"],
|
|
462
|
+
},
|
|
463
|
+
// B3: does not investigate code
|
|
464
|
+
{
|
|
465
|
+
regex: /\bdoes\s+not\s+(deeply\s+)?(investigate|inspect|analyze|analyse)\s+code\b/i,
|
|
466
|
+
fallbackLiterals: ["does not deeply"],
|
|
467
|
+
},
|
|
468
|
+
// C3: minimum context needed to
|
|
469
|
+
/\bminimum\s+context\s+needed\s+to\b/i,
|
|
470
|
+
// B4: delegate to `researcher`
|
|
471
|
+
/\bdelegate\s+to\s+\`researcher\`/i,
|
|
472
|
+
// B10: Do not mentally implement before delegating
|
|
473
|
+
/\bdo\s+not\s+(mentally\s+)?(implement|design|solve|build)\s+the\s+(solution|problem)\s+before\s+delegating\b/i,
|
|
474
|
+
// C4: handoff to another
|
|
475
|
+
/\bhandoff\s+to\s+another\b/i,
|
|
476
|
+
// B5: must be self-contained
|
|
477
|
+
/\bmust\s+be\s+self-contained\b/i,
|
|
478
|
+
// B6: Do not review a diff yourself
|
|
479
|
+
/\bdo\s+not\s+(review|inspect)\s+a\s+diff\s+yourself\b/i,
|
|
480
|
+
], "agents/lead.md semantic invariant");
|
|
481
|
+
|
|
482
|
+
const docs = read("docs/ai/harness/agents.md");
|
|
483
|
+
|
|
484
|
+
// --- Structural token in agents.md ---
|
|
485
|
+
if (!docs.includes("belongs to `reviewer`")) {
|
|
486
|
+
fail("docs/ai/harness/agents.md: missing belongs to `reviewer`");
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// --- Semantic tokens in agents.md (4 patterns) ---
|
|
490
|
+
checkSemantic(docs, [
|
|
491
|
+
/\`lead\`\s+does\s+not\s+(edit|modify|change|alter)\s+files\b/i,
|
|
492
|
+
/\b(later|subsequent)\s+(adjustments|corrections|fixes|changes)\s+for\s+that\s+same\s+free-form\s+request\s+go\s+back\s+to\s+\`developer\`/i,
|
|
493
|
+
/\`lead\`\s+does\s+not\s+(develop|code|implement|program)\b/i,
|
|
494
|
+
/\bdelegates\s+(substantive|meaningful|deep)\s+discovery\s+to\s+\`researcher\`/i,
|
|
495
|
+
/\bevery\s+\`lead\`\s+handoff\s+to\s+another\s+agent\s+must\s+be\s+self-contained\b/i,
|
|
496
|
+
], "docs/ai/harness/agents.md semantic invariant");
|
|
497
|
+
|
|
498
|
+
const commandDocs = read("docs/ai/harness/commands.md");
|
|
499
|
+
|
|
500
|
+
// --- Semantic tokens in commands.md (3 patterns) ---
|
|
501
|
+
checkSemantic(commandDocs, [
|
|
502
|
+
/\bunderstand\s+(code\s+behavior|how\s+the\s+code\s+works|the\s+code)\b/i,
|
|
503
|
+
/\bdelegates\s+to\s+\`researcher\`/i,
|
|
504
|
+
/\bdelegate\s+review\s+to\s+\`reviewer\`/i,
|
|
505
|
+
/\`lead\`\s+does\s+not\s+replace\s+\`reviewer\`/i,
|
|
506
|
+
], "docs/ai/harness/commands.md semantic invariant");
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function checkFeatureContract() {
|
|
510
|
+
const text = read("commands/feature.md");
|
|
511
|
+
const requiredFlow =
|
|
512
|
+
"lead -> designer if applicable -> researcher -> specifier -> developer -> reviewer";
|
|
513
|
+
if (!text.includes(requiredFlow)) {
|
|
514
|
+
fail("commands/feature.md: missing exact base feature flow");
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const flowSection = text.split("## Mandatory flow")[1]?.split("AHE sidecars")[0] || "";
|
|
518
|
+
if (/\b(evaluator|debugger|evolver)\b/.test(flowSection)) {
|
|
519
|
+
fail("commands/feature.md: sidecar appears in mandatory feature flow");
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function checkPlanContract() {
|
|
524
|
+
const rel = "commands/plan.md";
|
|
525
|
+
if (!exists(rel)) {
|
|
526
|
+
fail(`${rel}: missing plan command`);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const text = read(rel);
|
|
531
|
+
for (const token of [
|
|
532
|
+
"lead -> researcher -> specifier -> reviewer",
|
|
533
|
+
"Do not invoke developer",
|
|
534
|
+
"1 correction pass",
|
|
535
|
+
]) {
|
|
536
|
+
if (!text.includes(token)) fail(`${rel}: missing ${token}`);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function checkHarnessDocs() {
|
|
541
|
+
const required = [
|
|
542
|
+
"docs/ai/harness/README.md",
|
|
543
|
+
"docs/ai/harness/agents.md",
|
|
544
|
+
"docs/ai/harness/commands.md",
|
|
545
|
+
"docs/ai/harness/evidence.md",
|
|
546
|
+
"docs/ai/harness/checks.md",
|
|
547
|
+
"docs/ai/evolution/README.md",
|
|
548
|
+
"docs/ai/evolution/evolution_history.md",
|
|
549
|
+
"docs/ai/evolution/benchmarks/manual-scenarios.md",
|
|
550
|
+
];
|
|
551
|
+
for (const rel of required) {
|
|
552
|
+
if (!exists(rel)) fail(`${rel}: missing harness doc`);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (exists("docs/ai/evolution/benchmarks/manual-scenarios.md")) {
|
|
556
|
+
const text = read("docs/ai/evolution/benchmarks/manual-scenarios.md");
|
|
557
|
+
for (const token of ["opencode run --format json --thinking", "static_contract", "transcript_replay", "live_smoke", "manual_oracle"]) {
|
|
558
|
+
if (!text.includes(token)) {
|
|
559
|
+
fail(`docs/ai/evolution/benchmarks/manual-scenarios.md: missing ${token}`);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function collectReferencedPathStrings(value, strings = [], key = "") {
|
|
566
|
+
if (typeof value === "string") {
|
|
567
|
+
if (key === "files" || key === "evidence") strings.push(value);
|
|
568
|
+
} else if (Array.isArray(value)) {
|
|
569
|
+
for (const item of value) collectReferencedPathStrings(item, strings, key);
|
|
570
|
+
} else if (value && typeof value === "object") {
|
|
571
|
+
for (const [childKey, item] of Object.entries(value)) {
|
|
572
|
+
collectReferencedPathStrings(item, strings, childKey);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return strings;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function localPathFromString(value) {
|
|
579
|
+
const trimmed = value.trim();
|
|
580
|
+
const match = trimmed.match(/^((?:\.{1,2}\/)?[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*\.(?:md|json|mjs|js|ts|tsx|txt))(?:[:#].*)?$/);
|
|
581
|
+
if (!match) return null;
|
|
582
|
+
|
|
583
|
+
const rel = match[1];
|
|
584
|
+
if (rel.startsWith("http://") || rel.startsWith("https://")) return null;
|
|
585
|
+
if (rel.startsWith("/")) return null;
|
|
586
|
+
return rel;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function checkReferencedJsonPaths(rel, json) {
|
|
590
|
+
if (!json) return;
|
|
591
|
+
const runRel = path.dirname(rel);
|
|
592
|
+
|
|
593
|
+
for (const value of collectReferencedPathStrings(json)) {
|
|
594
|
+
const localPath = localPathFromString(value);
|
|
595
|
+
if (!localPath) continue;
|
|
596
|
+
|
|
597
|
+
const candidates = localPath.startsWith("docs/")
|
|
598
|
+
? [localPath]
|
|
599
|
+
: [path.join(runRel, localPath), localPath];
|
|
600
|
+
if (!candidates.some((candidate) => exists(candidate))) {
|
|
601
|
+
fail(`${rel}: referenced local path does not exist: ${localPath}`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function validateManifest(rel) {
|
|
607
|
+
const manifest = parseJson(rel);
|
|
608
|
+
if (!manifest) return;
|
|
609
|
+
if (!Array.isArray(manifest.changes) || manifest.changes.length === 0) {
|
|
610
|
+
fail(`${rel}: changes must be a non-empty array`);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
for (const [index, change] of manifest.changes.entries()) {
|
|
614
|
+
const prefix = `${rel}: changes[${index}]`;
|
|
615
|
+
for (const field of [
|
|
616
|
+
"id",
|
|
617
|
+
"type",
|
|
618
|
+
"description",
|
|
619
|
+
"files",
|
|
620
|
+
"failure_pattern",
|
|
621
|
+
"evidence",
|
|
622
|
+
"predicted_fixes",
|
|
623
|
+
"risk_tasks",
|
|
624
|
+
"constraint_level",
|
|
625
|
+
"why_this_component",
|
|
626
|
+
]) {
|
|
627
|
+
if (change[field] === undefined) fail(`${prefix}: missing ${field}`);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
checkReferencedJsonPaths(rel, manifest);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function checkEvolutionRuns() {
|
|
634
|
+
const runsDir = path.join(root, "docs/ai/evolution/runs");
|
|
635
|
+
if (!fs.existsSync(runsDir)) return;
|
|
636
|
+
|
|
637
|
+
for (const name of fs.readdirSync(runsDir)) {
|
|
638
|
+
const runPath = path.join(runsDir, name);
|
|
639
|
+
if (!fs.statSync(runPath).isDirectory()) continue;
|
|
640
|
+
const rel = `docs/ai/evolution/runs/${name}`;
|
|
641
|
+
const hasEvaluation = exists(`${rel}/evaluation.md`);
|
|
642
|
+
const hasAnalysis = exists(`${rel}/analysis/overview.md`);
|
|
643
|
+
const hasManifest = exists(`${rel}/change_manifest.json`);
|
|
644
|
+
|
|
645
|
+
if (!hasEvaluation) fail(`${rel}: missing evaluation.md`);
|
|
646
|
+
if (hasManifest && !hasAnalysis) fail(`${rel}: missing analysis/overview.md`);
|
|
647
|
+
if (hasManifest) validateManifest(`${rel}/change_manifest.json`);
|
|
648
|
+
if (hasManifest && !exists(`${rel}/change_evaluation.json`)) {
|
|
649
|
+
fail(`${rel}: manifest exists without change_evaluation.json`);
|
|
650
|
+
}
|
|
651
|
+
if (exists(`${rel}/change_evaluation.json`)) {
|
|
652
|
+
checkReferencedJsonPaths(`${rel}/change_evaluation.json`, parseJson(`${rel}/change_evaluation.json`));
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function parseJsonl(rel) {
|
|
658
|
+
if (!exists(rel)) {
|
|
659
|
+
fail(`${rel}: missing`);
|
|
660
|
+
return [];
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const records = [];
|
|
664
|
+
const lines = read(rel).split("\n");
|
|
665
|
+
for (let index = 0; index < lines.length; index++) {
|
|
666
|
+
const line = lines[index].trim();
|
|
667
|
+
if (!line) continue;
|
|
668
|
+
try {
|
|
669
|
+
records.push({ line: index + 1, value: JSON.parse(line) });
|
|
670
|
+
} catch (error) {
|
|
671
|
+
fail(`${rel}: line ${index + 1} invalid JSON (${error.message})`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return records;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function requireJsonlFields(rel, line, object, fields) {
|
|
678
|
+
for (const field of fields) {
|
|
679
|
+
if (object[field] === undefined) fail(`${rel}: line ${line} missing ${field}`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
function checkStringArray(rel, line, object, field) {
|
|
684
|
+
if (!Array.isArray(object[field])) {
|
|
685
|
+
fail(`${rel}: line ${line} ${field} must be an array`);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
for (const [index, value] of object[field].entries()) {
|
|
689
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
690
|
+
fail(`${rel}: line ${line} ${field}[${index}] must be a non-empty string`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function checkTaskContractSurface() {
|
|
696
|
+
const taskContractFiles = [
|
|
697
|
+
"agents/specifier.md",
|
|
698
|
+
"agents/developer.md",
|
|
699
|
+
"agents/reviewer.md",
|
|
700
|
+
];
|
|
701
|
+
const requiredFields = [
|
|
702
|
+
"objective",
|
|
703
|
+
"success_criteria",
|
|
704
|
+
"non_goals",
|
|
705
|
+
"assumptions",
|
|
706
|
+
"open_questions",
|
|
707
|
+
"accepted_tradeoffs",
|
|
708
|
+
"validation",
|
|
709
|
+
"ask_abort_triggers",
|
|
710
|
+
];
|
|
711
|
+
|
|
712
|
+
for (const rel of taskContractFiles) {
|
|
713
|
+
const text = read(rel);
|
|
714
|
+
if (!text.includes("Task Contract")) {
|
|
715
|
+
fail(`${rel}: missing Task Contract`);
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
for (const field of requiredFields) {
|
|
719
|
+
if (!text.includes(field)) fail(`${rel}: Task Contract missing ${field}`);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const docs = read("docs/ai/harness/agents.md");
|
|
724
|
+
for (const token of ["Task Contract", "handoff_packet", "ask_abort_triggers"]) {
|
|
725
|
+
if (!docs.includes(token)) fail(`docs/ai/harness/agents.md: missing ${token}`);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
const planText = read("commands/plan.md");
|
|
729
|
+
for (const token of ["Clarifications", "Acceptance Checklist"]) {
|
|
730
|
+
if (!planText.includes(token)) fail(`commands/plan.md: missing ${token}`);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
function checkResultContractSurface() {
|
|
735
|
+
const resultContractFiles = [
|
|
736
|
+
"agents/specifier.md",
|
|
737
|
+
"agents/developer.md",
|
|
738
|
+
"agents/reviewer.md",
|
|
739
|
+
];
|
|
740
|
+
const resultFields = [
|
|
741
|
+
"status",
|
|
742
|
+
"summary",
|
|
743
|
+
"artifacts",
|
|
744
|
+
"next_recommended",
|
|
745
|
+
"risks",
|
|
746
|
+
"skill_resolution",
|
|
747
|
+
];
|
|
748
|
+
|
|
749
|
+
const docs = read("docs/ai/harness/agents.md");
|
|
750
|
+
for (const token of ["Result Contract", "Verification Envelope", ...resultFields]) {
|
|
751
|
+
if (!docs.includes(token)) fail(`docs/ai/harness/agents.md: missing ${token}`);
|
|
752
|
+
}
|
|
753
|
+
for (const token of ["commands_run", "results", "not_run", "evidence"]) {
|
|
754
|
+
if (!docs.includes(token)) fail(`docs/ai/harness/agents.md: missing ${token}`);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
for (const rel of resultContractFiles) {
|
|
758
|
+
const text = read(rel);
|
|
759
|
+
if (!text.includes("Result Contract")) {
|
|
760
|
+
fail(`${rel}: missing Result Contract`);
|
|
761
|
+
continue;
|
|
762
|
+
}
|
|
763
|
+
for (const field of resultFields) {
|
|
764
|
+
if (!text.includes(field)) fail(`${rel}: Result Contract missing ${field}`);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const developer = read("agents/developer.md");
|
|
769
|
+
if (!developer.includes("Verification Envelope")) {
|
|
770
|
+
fail("agents/developer.md: missing Verification Envelope");
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
for (const field of ["commands_run", "results", "not_run", "evidence"]) {
|
|
774
|
+
if (!developer.includes(field)) fail(`agents/developer.md: Verification Envelope missing ${field}`);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
function checkInitContextPolicy() {
|
|
779
|
+
for (const rel of ["commands/feature.md", "commands/plan.md", "commands/scope.md", "commands/evolve.md"]) {
|
|
780
|
+
const text = read(rel);
|
|
781
|
+
for (const token of ["Init/context policy", "cwd", "AGENTS.md", "git state", "validation commands", "repo docs"]) {
|
|
782
|
+
if (!text.includes(token)) fail(`${rel}: missing init/context token ${token}`);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function checkMechanismRegistries() {
|
|
788
|
+
const acceptedRel = "docs/ai/evolution/mechanisms.jsonl";
|
|
789
|
+
const rejectedRel = "docs/ai/evolution/rejected_mechanisms.jsonl";
|
|
790
|
+
const mechanismIdPattern = /^mech-[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
791
|
+
const allowedSurfaces = new Set(["agent", "command", "skill", "tool", "workflow", "memory", "evaluation"]);
|
|
792
|
+
const behaviorKeys = new Map();
|
|
793
|
+
|
|
794
|
+
for (const { line, value } of parseJsonl(acceptedRel)) {
|
|
795
|
+
requireJsonlFields(acceptedRel, line, value, [
|
|
796
|
+
"mechanism_id",
|
|
797
|
+
"status",
|
|
798
|
+
"owning_surface",
|
|
799
|
+
"activation",
|
|
800
|
+
"behavior_key",
|
|
801
|
+
"behavior_change",
|
|
802
|
+
"evidence",
|
|
803
|
+
"failure_modes",
|
|
804
|
+
]);
|
|
805
|
+
if (typeof value.mechanism_id !== "string" || !mechanismIdPattern.test(value.mechanism_id)) {
|
|
806
|
+
fail(`${acceptedRel}: line ${line} invalid mechanism_id`);
|
|
807
|
+
}
|
|
808
|
+
if (value.status !== "accepted") fail(`${acceptedRel}: line ${line} status must be accepted`);
|
|
809
|
+
if (!allowedSurfaces.has(value.owning_surface)) {
|
|
810
|
+
fail(`${acceptedRel}: line ${line} invalid owning_surface`);
|
|
811
|
+
}
|
|
812
|
+
checkStringArray(acceptedRel, line, value, "evidence");
|
|
813
|
+
checkStringArray(acceptedRel, line, value, "failure_modes");
|
|
814
|
+
|
|
815
|
+
if (typeof value.behavior_key === "string") {
|
|
816
|
+
const records = behaviorKeys.get(value.behavior_key) ?? [];
|
|
817
|
+
records.push({ line, value });
|
|
818
|
+
behaviorKeys.set(value.behavior_key, records);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
for (const [behaviorKey, records] of behaviorKeys.entries()) {
|
|
823
|
+
if (records.length <= 1) continue;
|
|
824
|
+
if (!records.some((record) => typeof record.value.pruning_decision === "string" && record.value.pruning_decision.length > 0)) {
|
|
825
|
+
fail(`${acceptedRel}: duplicate behavior_key ${behaviorKey} requires pruning_decision`);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
for (const { line, value } of parseJsonl(rejectedRel)) {
|
|
830
|
+
requireJsonlFields(rejectedRel, line, value, [
|
|
831
|
+
"mechanism_id",
|
|
832
|
+
"status",
|
|
833
|
+
"reason",
|
|
834
|
+
"evidence",
|
|
835
|
+
"failure_modes",
|
|
836
|
+
]);
|
|
837
|
+
if (typeof value.mechanism_id !== "string" || !mechanismIdPattern.test(value.mechanism_id)) {
|
|
838
|
+
fail(`${rejectedRel}: line ${line} invalid mechanism_id`);
|
|
839
|
+
}
|
|
840
|
+
if (value.status !== "rejected") fail(`${rejectedRel}: line ${line} status must be rejected`);
|
|
841
|
+
checkStringArray(rejectedRel, line, value, "evidence");
|
|
842
|
+
checkStringArray(rejectedRel, line, value, "failure_modes");
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function checkRouterScenarios() {
|
|
847
|
+
const rel = "docs/ai/evolution/benchmarks/router-scenarios.jsonl";
|
|
848
|
+
const allowedAgents = new Set([
|
|
849
|
+
"lead",
|
|
850
|
+
"developer",
|
|
851
|
+
"researcher",
|
|
852
|
+
"designer",
|
|
853
|
+
"specifier",
|
|
854
|
+
"reviewer",
|
|
855
|
+
"scoper",
|
|
856
|
+
"evaluator",
|
|
857
|
+
"debugger",
|
|
858
|
+
"evolver",
|
|
859
|
+
]);
|
|
860
|
+
const allowedEvidence = new Set(["static_contract", "transcript_replay", "live_smoke", "manual_oracle"]);
|
|
861
|
+
|
|
862
|
+
for (const { line, value } of parseJsonl(rel)) {
|
|
863
|
+
requireJsonlFields(rel, line, value, [
|
|
864
|
+
"id",
|
|
865
|
+
"prompt",
|
|
866
|
+
"expected_agent",
|
|
867
|
+
"command_path",
|
|
868
|
+
"allowed_skills",
|
|
869
|
+
"forbidden_sidecars",
|
|
870
|
+
"required_evidence",
|
|
871
|
+
]);
|
|
872
|
+
if (typeof value.id !== "string" || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value.id)) {
|
|
873
|
+
fail(`${rel}: line ${line} invalid id`);
|
|
874
|
+
}
|
|
875
|
+
if (!allowedAgents.has(value.expected_agent)) {
|
|
876
|
+
fail(`${rel}: line ${line} invalid expected_agent`);
|
|
877
|
+
}
|
|
878
|
+
if (value.command_path !== "freeform" && !/^\/[a-z-]+$/.test(value.command_path ?? "")) {
|
|
879
|
+
fail(`${rel}: line ${line} invalid command_path`);
|
|
880
|
+
}
|
|
881
|
+
for (const field of ["allowed_skills", "forbidden_sidecars", "required_evidence"]) {
|
|
882
|
+
checkStringArray(rel, line, value, field);
|
|
883
|
+
}
|
|
884
|
+
if (Array.isArray(value.required_evidence)) {
|
|
885
|
+
for (const evidence of value.required_evidence) {
|
|
886
|
+
if (!allowedEvidence.has(evidence)) fail(`${rel}: line ${line} invalid required_evidence ${evidence}`);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Validate that commands/evolve.md contains the AHE flow
|
|
894
|
+
* evaluator -> debugger -> evolver with flexible regex matching.
|
|
895
|
+
*/
|
|
896
|
+
function checkEvolveContract() {
|
|
897
|
+
const text = read("commands/evolve.md");
|
|
898
|
+
|
|
899
|
+
// Structural tokens: agent identifiers that must appear
|
|
900
|
+
for (const token of ["evaluator", "debugger", "evolver"]) {
|
|
901
|
+
if (!text.includes(token)) {
|
|
902
|
+
fail(`commands/evolve.md: missing agent token ${token}`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
for (const token of ["session_sources", "opencode.db", "collect-session-evidence.mjs", "session-sources.md", "execution-trees.jsonl", "cursor.json", "parent_id", "full-rescan"]) {
|
|
906
|
+
if (!text.includes(token)) fail(`commands/evolve.md: missing evolve session-source token ${token}`);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// Semantic: the AHE flow sequence evaluator -> debugger -> evolver
|
|
910
|
+
// Must appear in this order with any intervening text.
|
|
911
|
+
checkSemantic(text, [
|
|
912
|
+
// The core AHE flow: evaluator -> debugger -> evolver (flexible arrow + ordering)
|
|
913
|
+
{
|
|
914
|
+
regex: /\bevaluator\b[\s\S]*?\bdebugger\b[\s\S]*?\bevolver\b/i,
|
|
915
|
+
},
|
|
916
|
+
// Flow section must exist
|
|
917
|
+
{
|
|
918
|
+
regex: /\bflow\b/i,
|
|
919
|
+
fallbackLiterals: ["## Flow"],
|
|
920
|
+
},
|
|
921
|
+
// Invoke evaluator pattern
|
|
922
|
+
{
|
|
923
|
+
regex: /\b(invoke|run|call)\s+\`?evaluator\`?/i,
|
|
924
|
+
fallbackLiterals: ["Invoke `evaluator`"],
|
|
925
|
+
},
|
|
926
|
+
// Invoke debugger pattern
|
|
927
|
+
{
|
|
928
|
+
regex: /\b(invoke|run|call)\s+\`?debugger\`?/i,
|
|
929
|
+
fallbackLiterals: ["Invoke `debugger`"],
|
|
930
|
+
},
|
|
931
|
+
// Invoke evolver pattern
|
|
932
|
+
{
|
|
933
|
+
regex: /\b(invoke|run|call)\s+\`?evolver\`?/i,
|
|
934
|
+
fallbackLiterals: ["Invoke `evolver`"],
|
|
935
|
+
},
|
|
936
|
+
// AHE reference
|
|
937
|
+
{
|
|
938
|
+
regex: /\ba\.h\.e\.|ahe|harness\s+(iteration|evolution)|evolve\s+the\s+harness/i,
|
|
939
|
+
fallbackLiterals: ["/evolve", "Evolve the OpenCode harness"],
|
|
940
|
+
},
|
|
941
|
+
], "commands/evolve.md AHE flow");
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
function checkSessionSourceDocs() {
|
|
945
|
+
const docs = read("docs/ai/evolution/session-sources.md");
|
|
946
|
+
for (const token of [
|
|
947
|
+
"opencode.db",
|
|
948
|
+
"RAW_SESSIONS_DIR",
|
|
949
|
+
"/raw-sessions",
|
|
950
|
+
"collect-session-evidence.mjs",
|
|
951
|
+
"normalized-sessions.jsonl",
|
|
952
|
+
"session-sources.summary.json",
|
|
953
|
+
"execution-trees.jsonl",
|
|
954
|
+
"cursor.json",
|
|
955
|
+
"parent_id",
|
|
956
|
+
"tree_time_updated_max",
|
|
957
|
+
"root_session_id",
|
|
958
|
+
"full-rescan",
|
|
959
|
+
"discovered",
|
|
960
|
+
"accepted",
|
|
961
|
+
"skipped",
|
|
962
|
+
"skip_reasons",
|
|
963
|
+
]) {
|
|
964
|
+
if (!docs.includes(token)) fail(`docs/ai/evolution/session-sources.md: missing ${token}`);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const evidence = read("docs/ai/harness/evidence.md");
|
|
968
|
+
for (const token of ["opencode.db", "collect-session-evidence.mjs", "execution-trees.jsonl", "cursor.json", "tree_time_updated_max", "root_session_id", "discovered", "accepted", "skipped", "skip_reasons"]) {
|
|
969
|
+
if (!evidence.includes(token)) fail(`docs/ai/harness/evidence.md: missing session evidence token ${token}`);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const readme = read("docs/ai/evolution/README.md");
|
|
973
|
+
for (const token of ["session-sources.md", "opencode.db", "collect-session-evidence.mjs", "execution-trees.jsonl", "cursor.json", "parent_id"]) {
|
|
974
|
+
if (!readme.includes(token)) fail(`docs/ai/evolution/README.md: missing session-source token ${token}`);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Verify that each semantic invariant documented in
|
|
980
|
+
* docs/ai/harness/agents.md has a semantically equivalent phrase
|
|
981
|
+
* in the corresponding agent prompt (agents/<name>.md).
|
|
982
|
+
*/
|
|
983
|
+
function checkCrossAgentContract() {
|
|
984
|
+
const docs = read("docs/ai/harness/agents.md");
|
|
985
|
+
|
|
986
|
+
// Define invariant patterns per agent. Each entry maps an agent to
|
|
987
|
+
// the semantic invariants that agents.md declares about them, and
|
|
988
|
+
// the regex/literals used to find equivalent phrases in the agent's
|
|
989
|
+
// prompt file.
|
|
990
|
+
const agentInvariants = [
|
|
991
|
+
{
|
|
992
|
+
agent: "lead",
|
|
993
|
+
// Invariants from agents.md:
|
|
994
|
+
// - `lead` is the harness default_agent and bounded router.
|
|
995
|
+
// - `lead` does not edit files; it delegates to `developer`.
|
|
996
|
+
// - `lead` does not develop or deeply inspect code.
|
|
997
|
+
// - Every `lead` handoff must be self-contained.
|
|
998
|
+
patterns: [
|
|
999
|
+
{
|
|
1000
|
+
regex: /\b(fast|bounded|quick|lightweight)\s+router\b/i,
|
|
1001
|
+
fallbackLiterals: ["bounded router", "fast router"],
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
regex: /\bdo\s+not\s+(edit|modify|change|alter)\s+(files|code)\b/i,
|
|
1005
|
+
fallbackLiterals: ["Do not edit code"],
|
|
1006
|
+
},
|
|
1007
|
+
{
|
|
1008
|
+
regex: /\bdoes\s+not\s+(develop|code|implement|program)\b/i,
|
|
1009
|
+
fallbackLiterals: ["does not develop"],
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
regex: /\bdoes\s+not\s+(deeply\s+)?(investigate|inspect|analyze|analyse)\s+code\b/i,
|
|
1013
|
+
fallbackLiterals: ["does not deeply"],
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
regex: /\bself-contained\b/i,
|
|
1017
|
+
fallbackLiterals: ["self-contained"],
|
|
1018
|
+
},
|
|
1019
|
+
],
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
agent: "developer",
|
|
1023
|
+
// Invariants from agents.md:
|
|
1024
|
+
// - `developer` runs direct mode when `lead` delegates.
|
|
1025
|
+
// - Later adjustments go back to `developer`.
|
|
1026
|
+
patterns: [
|
|
1027
|
+
{
|
|
1028
|
+
regex: /\bdirect\s+mode\b/i,
|
|
1029
|
+
fallbackLiterals: ["Direct mode"],
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
regex: /\bdelegat\w*[\s\S]*?(small|clear|bounded|verifiable)\s+(task|change)/i,
|
|
1033
|
+
fallbackLiterals: ["delegates a small"],
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
regex: /\b(later|subsequent)\s+(adjustments|corrections|fixes|changes)[\s\S]*?\b(go|goes|return|returns)\s+back\s+to\s+\`?developer\`?/i,
|
|
1037
|
+
fallbackLiterals: ["go back to `developer`"],
|
|
1038
|
+
},
|
|
1039
|
+
],
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
agent: "designer",
|
|
1043
|
+
// Invariants from agents.md:
|
|
1044
|
+
// - UX/UI, brand, layout, interaction, or Open Design.
|
|
1045
|
+
patterns: [
|
|
1046
|
+
{
|
|
1047
|
+
regex: /\b(UX|UI|interface|design|brand|layout|interaction)\b/i,
|
|
1048
|
+
fallbackLiterals: ["UX/UI"],
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
regex: /\bopen\s*design/i,
|
|
1052
|
+
fallbackLiterals: ["Open Design"],
|
|
1053
|
+
},
|
|
1054
|
+
],
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
agent: "researcher",
|
|
1058
|
+
// Invariants from agents.md:
|
|
1059
|
+
// - Technical/product uncertainty, APIs, libraries, and risks.
|
|
1060
|
+
patterns: [
|
|
1061
|
+
{
|
|
1062
|
+
regex: /\b((technical|product)\s+uncertainty|uncertainty|unknowns?|APIs?|libraries|risks?)\b/i,
|
|
1063
|
+
fallbackLiterals: ["technical/product uncertainty"],
|
|
1064
|
+
},
|
|
1065
|
+
{
|
|
1066
|
+
regex: /\b(API|library|libraries|framework|dependency|dependencies)\b/i,
|
|
1067
|
+
fallbackLiterals: ["APIs"],
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
regex: /\b(risk|risks|threat|hazard)\b/i,
|
|
1071
|
+
fallbackLiterals: ["riesgos"],
|
|
1072
|
+
},
|
|
1073
|
+
],
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
agent: "specifier",
|
|
1077
|
+
// Invariants from agents.md:
|
|
1078
|
+
// - Enough context exists to turn the goal into tasks.
|
|
1079
|
+
patterns: [
|
|
1080
|
+
{
|
|
1081
|
+
regex: /\b(acceptance\s+criteria|criterion|criteria)\b/i,
|
|
1082
|
+
fallbackLiterals: ["Acceptance criteria"],
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
regex: /\b(validation\s+plan|test\s+plan)\b/i,
|
|
1086
|
+
fallbackLiterals: ["validation plan"],
|
|
1087
|
+
},
|
|
1088
|
+
{
|
|
1089
|
+
regex: /\b(atomic|ordered|small)\s+tasks?\b/i,
|
|
1090
|
+
fallbackLiterals: ["ordered tasks"],
|
|
1091
|
+
},
|
|
1092
|
+
],
|
|
1093
|
+
},
|
|
1094
|
+
{
|
|
1095
|
+
agent: "reviewer",
|
|
1096
|
+
// Invariants from agents.md:
|
|
1097
|
+
// - A diff, implementation, or planning artifact is reviewable.
|
|
1098
|
+
patterns: [
|
|
1099
|
+
{
|
|
1100
|
+
regex: /\b((diff|implementation|code|artifact)\s+(reviewable|review|audit|reviewed)|reviewable\s+diff)\b/i,
|
|
1101
|
+
fallbackLiterals: ["reviewable diff"],
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
regex: /\b(security|bugs?|regression|maintainability|compliance)\b/i,
|
|
1105
|
+
fallbackLiterals: ["seguridad"],
|
|
1106
|
+
},
|
|
1107
|
+
],
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
agent: "scoper",
|
|
1111
|
+
// Invariants from agents.md:
|
|
1112
|
+
// - The user wants research -> spec without implementation.
|
|
1113
|
+
patterns: [
|
|
1114
|
+
{
|
|
1115
|
+
regex: /\b(research\s*->\s*spec|research-and-spec|research\s+and\s+specification|research[\s\S]*?scoped\s+specs?)\b/i,
|
|
1116
|
+
fallbackLiterals: ["research -> spec"],
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
regex: /\b(no\s+(design|implementation|code|developer)|do\s+not\s+(design|implement|modify|review)\s+code|do\s+not\s+design)\b/i,
|
|
1120
|
+
fallbackLiterals: ["Do not implement code"],
|
|
1121
|
+
},
|
|
1122
|
+
],
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
agent: "evaluator",
|
|
1126
|
+
// Invariants from agents.md:
|
|
1127
|
+
// - Benchmark/smoke evidence or /evolve is needed.
|
|
1128
|
+
patterns: [
|
|
1129
|
+
{
|
|
1130
|
+
regex: /\b(benchmark|smoke|evidencia)\b/i,
|
|
1131
|
+
fallbackLiterals: ["evidencia"],
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
regex: /\b(pass|fail|not_run)\b/i,
|
|
1135
|
+
fallbackLiterals: ["pass/fail"],
|
|
1136
|
+
},
|
|
1137
|
+
],
|
|
1138
|
+
},
|
|
1139
|
+
{
|
|
1140
|
+
agent: "debugger",
|
|
1141
|
+
// Invariants from agents.md:
|
|
1142
|
+
// - Failures, traces, results, or attribution need analysis.
|
|
1143
|
+
patterns: [
|
|
1144
|
+
{
|
|
1145
|
+
regex: /\b(failure|fail|trace|root\s+cause|attribution)\b/i,
|
|
1146
|
+
fallbackLiterals: ["root cause"],
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
regex: /\b(analyze|analyse|interpret|debug|transform)\b/i,
|
|
1150
|
+
fallbackLiterals: ["analizar"],
|
|
1151
|
+
},
|
|
1152
|
+
],
|
|
1153
|
+
},
|
|
1154
|
+
{
|
|
1155
|
+
agent: "evolver",
|
|
1156
|
+
// Invariants from agents.md:
|
|
1157
|
+
// - The harness is improved with AHE evidence.
|
|
1158
|
+
// - `evolver` only works on the OpenCode harness.
|
|
1159
|
+
patterns: [
|
|
1160
|
+
{
|
|
1161
|
+
regex: /\b(harness|OpenCode)\b/i,
|
|
1162
|
+
fallbackLiterals: ["harness"],
|
|
1163
|
+
},
|
|
1164
|
+
{
|
|
1165
|
+
regex: /\b(evidencia|manifest|predicted\s+fixes|risk\s+tasks)\b/i,
|
|
1166
|
+
fallbackLiterals: ["evidencia"],
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
regex: /\b(iteration|keep|improve|rollback|pivot)\b/i,
|
|
1170
|
+
fallbackLiterals: ["keep"],
|
|
1171
|
+
},
|
|
1172
|
+
],
|
|
1173
|
+
},
|
|
1174
|
+
];
|
|
1175
|
+
|
|
1176
|
+
for (const { agent, patterns } of agentInvariants) {
|
|
1177
|
+
const agentFile = `agents/${agent}.md`;
|
|
1178
|
+
if (!exists(agentFile)) {
|
|
1179
|
+
fail(`agents/${agent}.md: file does not exist`);
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
const agentText = read(agentFile);
|
|
1184
|
+
|
|
1185
|
+
for (const [index, pattern] of patterns.entries()) {
|
|
1186
|
+
const re =
|
|
1187
|
+
pattern.regex instanceof RegExp
|
|
1188
|
+
? pattern.regex
|
|
1189
|
+
: new RegExp("\\b" + pattern.regex.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b", "i");
|
|
1190
|
+
const hasMatch = re.test(agentText) ||
|
|
1191
|
+
(pattern.fallbackLiterals ?? []).some((token) => agentText.includes(token));
|
|
1192
|
+
if (!hasMatch) {
|
|
1193
|
+
fail(`agents/${agent}.md: missing semantic invariant[${index}] from agents.md`);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Validate that commands/scope.md and commands/design.md contain
|
|
1201
|
+
* their documented base flows with flexible regex matching.
|
|
1202
|
+
*/
|
|
1203
|
+
function checkCommandContracts() {
|
|
1204
|
+
// --- scope.md: must contain scoper -> researcher -> specifier flow ---
|
|
1205
|
+
const scopeText = read("commands/scope.md");
|
|
1206
|
+
|
|
1207
|
+
checkSemantic(scopeText, [
|
|
1208
|
+
// researcher invocation
|
|
1209
|
+
{
|
|
1210
|
+
regex: /\b(invoke|run|call)\s+\`?researcher\`?/i,
|
|
1211
|
+
fallbackLiterals: ["Invoke researcher first"],
|
|
1212
|
+
},
|
|
1213
|
+
// specifier invocation
|
|
1214
|
+
{
|
|
1215
|
+
regex: /\b(invoke|run|call)\s+\`?specifier\`?/i,
|
|
1216
|
+
fallbackLiterals: ["Invoke specifier"],
|
|
1217
|
+
},
|
|
1218
|
+
// researcher -> specifier ordering (with arrows or sequential steps)
|
|
1219
|
+
{
|
|
1220
|
+
regex: /\bresearcher\b[\s\S]*?\bspecifier\b/i,
|
|
1221
|
+
},
|
|
1222
|
+
// scoper self-reference (this is the scoper command)
|
|
1223
|
+
{
|
|
1224
|
+
regex: /\bscoper\b/i,
|
|
1225
|
+
fallbackLiterals: ["scoper"],
|
|
1226
|
+
},
|
|
1227
|
+
// no implementation
|
|
1228
|
+
{
|
|
1229
|
+
regex: /\b(no\s+(design|implementation|diff\s+review)|do\s+not\s+(implement|use\s+developer))\b/i,
|
|
1230
|
+
fallbackLiterals: ["Do not implement code"],
|
|
1231
|
+
},
|
|
1232
|
+
], "commands/scope.md flow");
|
|
1233
|
+
|
|
1234
|
+
// --- design.md: must contain designer -> open design flow ---
|
|
1235
|
+
const designText = read("commands/design.md");
|
|
1236
|
+
|
|
1237
|
+
checkSemantic(designText, [
|
|
1238
|
+
// open-design skill/tool references
|
|
1239
|
+
{
|
|
1240
|
+
regex: /\bopen[-_]?design\b/i,
|
|
1241
|
+
fallbackLiterals: ["open_design"],
|
|
1242
|
+
},
|
|
1243
|
+
// PRODUCT.md / DESIGN.md references
|
|
1244
|
+
{
|
|
1245
|
+
regex: /\b(PRODUCT\.md|DESIGN\.md)\b/i,
|
|
1246
|
+
fallbackLiterals: ["PRODUCT.md"],
|
|
1247
|
+
},
|
|
1248
|
+
// open_design_health / open_design_list_agents / open_design_run_design
|
|
1249
|
+
{
|
|
1250
|
+
regex: /\b(open_design_(health|list_agents|list_skills|list_design_systems|create_project|run_design))\b/i,
|
|
1251
|
+
fallbackLiterals: ["open_design_health"],
|
|
1252
|
+
},
|
|
1253
|
+
// baseUrl handling
|
|
1254
|
+
{
|
|
1255
|
+
regex: /\b(baseUrl|base\s*url|url\s+(de|del|base))\b/i,
|
|
1256
|
+
fallbackLiterals: ["baseUrl"],
|
|
1257
|
+
},
|
|
1258
|
+
// design flow with numbered steps
|
|
1259
|
+
{
|
|
1260
|
+
regex: /\b(Flow|Step\s+\d|^\d+\.\s)/m,
|
|
1261
|
+
fallbackLiterals: ["Flow"],
|
|
1262
|
+
},
|
|
1263
|
+
], "commands/design.md flow");
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function checkSkillRegistryPresence() {
|
|
1267
|
+
const rel = "docs/ai/harness/skill_registry.md";
|
|
1268
|
+
if (!exists(rel)) {
|
|
1269
|
+
console.warn(`Warning: ${rel} missing (soft check)`);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
function checkLeadSkillResolution() {
|
|
1274
|
+
const text = read("agents/lead.md");
|
|
1275
|
+
if (!text.includes("Skill Resolution") && !text.includes("registry")) {
|
|
1276
|
+
fail("agents/lead.md: missing Skill Resolution or registry reference");
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
function checkAgentSkillLoading() {
|
|
1281
|
+
const requiredAgents = ["developer", "researcher", "specifier", "reviewer", "designer", "scoper"];
|
|
1282
|
+
for (const agent of requiredAgents) {
|
|
1283
|
+
const rel = `agents/${agent}.md`;
|
|
1284
|
+
const text = read(rel);
|
|
1285
|
+
if (!text.includes("Skill Resolution") && !text.includes("selected_skills")) {
|
|
1286
|
+
fail(`${rel}: missing Skill Resolution or selected_skills behavior`);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
function checkSkillRegistryGenerator() {
|
|
1292
|
+
const generatorRel = "scripts/update-skill-registry.mjs";
|
|
1293
|
+
if (!exists(generatorRel)) return;
|
|
1294
|
+
try {
|
|
1295
|
+
execSync(`node ${generatorRel} --check`, { cwd: root, stdio: "pipe" });
|
|
1296
|
+
} catch (error) {
|
|
1297
|
+
fail(`Skill registry generator --check failed: ${error.message}`);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
function checkInitCommand() {
|
|
1302
|
+
if (!exists("commands/init.md")) {
|
|
1303
|
+
console.warn("Warning: commands/init.md missing (soft check)");
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
const commandDocs = read("docs/ai/harness/commands.md");
|
|
1307
|
+
if (!commandDocs.includes("/init")) {
|
|
1308
|
+
fail("docs/ai/harness/commands.md: missing /init documentation");
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
if (!exists("docs/ai/harness/init-detection-rules.md")) {
|
|
1312
|
+
console.warn("Warning: docs/ai/harness/init-detection-rules.md missing (soft check)");
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
function checkAutoForecastContract() {
|
|
1317
|
+
const specifier = read("agents/specifier.md");
|
|
1318
|
+
for (const token of ["estimated_scope", "affected_files", "suggested_phases"]) {
|
|
1319
|
+
if (!specifier.includes(token)) fail(`agents/specifier.md: missing auto-forecast token ${token}`);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
const lead = read("agents/lead.md");
|
|
1323
|
+
for (const token of ["Auto-Forecast", "estimated_scope", "large", "developer"]) {
|
|
1324
|
+
if (!lead.includes(token)) fail(`agents/lead.md: missing auto-forecast token ${token}`);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
function checkStrictTddContract() {
|
|
1329
|
+
const lead = read("agents/lead.md");
|
|
1330
|
+
for (const token of ["Strict TDD", "strict_tdd_recommended", "advisory_active"]) {
|
|
1331
|
+
if (!lead.includes(token)) fail(`agents/lead.md: missing strict TDD token ${token}`);
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
const developer = read("agents/developer.md");
|
|
1335
|
+
for (const token of ["Strict TDD", "advisory_active", "Verification Envelope.not_run"]) {
|
|
1336
|
+
if (!developer.includes(token)) fail(`agents/developer.md: missing strict TDD token ${token}`);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
function checkContextQuarantineContract() {
|
|
1341
|
+
const lead = read("agents/lead.md");
|
|
1342
|
+
for (const token of ["minimum handoff", "compact output"]) {
|
|
1343
|
+
if (!lead.includes(token)) fail(`agents/lead.md: missing context quarantine token ${token}`);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
function checkPreflightAuditContract() {
|
|
1348
|
+
const evolve = read("commands/evolve.md");
|
|
1349
|
+
for (const token of [
|
|
1350
|
+
"preflight audit",
|
|
1351
|
+
"preflight-audit.mjs",
|
|
1352
|
+
"preflight-audit.json",
|
|
1353
|
+
"audit-only",
|
|
1354
|
+
]) {
|
|
1355
|
+
if (!evolve.includes(token)) fail(`commands/evolve.md: missing preflight audit token ${token}`);
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
const commandDocs = read("docs/ai/harness/commands.md");
|
|
1359
|
+
const evolveSection = commandDocs.split("## `/evolve`")[1]?.split("## `/review`")[0] || "";
|
|
1360
|
+
for (const token of ["preflight audit", "preflight-audit.json"]) {
|
|
1361
|
+
if (!evolveSection.includes(token)) fail(`docs/ai/harness/commands.md /evolve: missing preflight token ${token}`);
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
const readme = read("docs/ai/evolution/README.md");
|
|
1365
|
+
for (const token of ["preflight-audit.json", "preflight audit"]) {
|
|
1366
|
+
if (!readme.includes(token)) fail(`docs/ai/evolution/README.md: missing preflight token ${token}`);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
const evaluator = read("agents/evaluator.md");
|
|
1370
|
+
if (!evaluator.includes("preflight-audit.json")) {
|
|
1371
|
+
fail("agents/evaluator.md: missing preflight-audit.json reference");
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
const debuggerDoc = read("agents/debugger.md");
|
|
1375
|
+
if (!debuggerDoc.includes("preflight-audit.json")) {
|
|
1376
|
+
fail("agents/debugger.md: missing preflight-audit.json reference");
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
const evolver = read("agents/evolver.md");
|
|
1380
|
+
if (!evolver.includes("preflight audit") && !evolver.includes("Preflight audit")) {
|
|
1381
|
+
fail("agents/evolver.md: missing preflight reference");
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
function checkMemoryAsHintContract() {
|
|
1386
|
+
const surfaces = [
|
|
1387
|
+
{ rel: "AGENTS.md", label: "AGENTS.md" },
|
|
1388
|
+
{ rel: "docs/ai/harness/agents.md", label: "docs/ai/harness/agents.md" },
|
|
1389
|
+
{ rel: "agents/lead.md", label: "agents/lead.md" },
|
|
1390
|
+
{ rel: "agents/developer.md", label: "agents/developer.md" },
|
|
1391
|
+
{ rel: "agents/researcher.md", label: "agents/researcher.md" },
|
|
1392
|
+
];
|
|
1393
|
+
|
|
1394
|
+
for (const { rel, label } of surfaces) {
|
|
1395
|
+
const text = read(rel);
|
|
1396
|
+
if (!text.includes("memory-as-hint")) {
|
|
1397
|
+
fail(`${label}: missing memory-as-hint contract`);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
for (const rel of ["agents/lead.md", "agents/developer.md"]) {
|
|
1402
|
+
const text = read(rel);
|
|
1403
|
+
if (!/verify against/i.test(text)) {
|
|
1404
|
+
fail(`${rel}: memory-as-hint must mention verification`);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Validate the HITL durable `handoff_packet` contract (ADK pattern 1).
|
|
1412
|
+
* Ensures the durable handoff surface is formalized in agents.md, referenced
|
|
1413
|
+
* from commands.md (/loop and /feature), visible in commands/loop.md during
|
|
1414
|
+
* execution, and mentioned in the root AGENTS.md index.
|
|
1415
|
+
*/
|
|
1416
|
+
function checkHitlDurableContract() {
|
|
1417
|
+
// `handoff_packet` is a code identifier; the repo writes it with backticks.
|
|
1418
|
+
// Whitespace is normalized so line-wrapping in markdown doesn't break matches.
|
|
1419
|
+
const includesPhrase = (text, phrase) =>
|
|
1420
|
+
text.replace(/\s+/g, " ").includes(phrase.replace(/\s+/g, " "));
|
|
1421
|
+
const handoffDurable = "durable `handoff_packet`";
|
|
1422
|
+
|
|
1423
|
+
const agentsDocs = read("docs/ai/harness/agents.md");
|
|
1424
|
+
for (const token of [
|
|
1425
|
+
handoffDurable,
|
|
1426
|
+
"approval_status",
|
|
1427
|
+
".opencode/handoffs/",
|
|
1428
|
+
"resumable",
|
|
1429
|
+
]) {
|
|
1430
|
+
if (!includesPhrase(agentsDocs, token)) {
|
|
1431
|
+
fail(`docs/ai/harness/agents.md: missing HITL durable token ${token}`);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
const commandDocs = read("docs/ai/harness/commands.md");
|
|
1436
|
+
const loopSection = commandDocs.split("## `/loop`")[1]?.split(/\n## (?![#])/)[0] || "";
|
|
1437
|
+
if (!includesPhrase(loopSection, handoffDurable)) {
|
|
1438
|
+
fail(`docs/ai/harness/commands.md: missing HITL durable token ${handoffDurable} in /loop`);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
const featureSection = commandDocs.split("## `/feature`")[1]?.split(/\n## (?![#])/)[0] || "";
|
|
1442
|
+
if (!includesPhrase(featureSection, handoffDurable)) {
|
|
1443
|
+
fail(`docs/ai/harness/commands.md: missing HITL durable token ${handoffDurable} in /feature`);
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
const loopCommand = read("commands/loop.md");
|
|
1447
|
+
for (const token of [handoffDurable, ".opencode/handoffs/"]) {
|
|
1448
|
+
if (!includesPhrase(loopCommand, token)) {
|
|
1449
|
+
fail(`commands/loop.md: missing HITL durable token ${token}`);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
const agentsIndex = read("AGENTS.md");
|
|
1454
|
+
if (!includesPhrase(agentsIndex, handoffDurable)) {
|
|
1455
|
+
fail(`AGENTS.md: missing HITL durable token ${handoffDurable}`);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* Validate the declarative routing table contract (ADK pattern 2).
|
|
1461
|
+
* Ensures commands.md "Free-form Message" contains a declarative routing table
|
|
1462
|
+
* with the expected agent targets and a fallback adaptive note, and that
|
|
1463
|
+
* commands/feature.md references the table so the contract is visible during
|
|
1464
|
+
* /feature execution.
|
|
1465
|
+
*/
|
|
1466
|
+
function checkRoutingDeclarativoContract() {
|
|
1467
|
+
const commandDocs = read("docs/ai/harness/commands.md");
|
|
1468
|
+
// Split on top-level "## " headers (not "### " sub-headers) to capture the
|
|
1469
|
+
// full Free-form Message section including its "### Declarative routing" subsection.
|
|
1470
|
+
const freeSection = commandDocs.split("## Free-form Message")[1]?.split(/\n## (?![#])/)[0] || "";
|
|
1471
|
+
|
|
1472
|
+
if (!freeSection.includes("Declarative routing")) {
|
|
1473
|
+
fail("docs/ai/harness/commands.md: missing declarative routing token Declarative routing");
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
for (const token of [
|
|
1477
|
+
"`researcher`",
|
|
1478
|
+
"`reviewer`",
|
|
1479
|
+
"`designer`",
|
|
1480
|
+
"`specifier`",
|
|
1481
|
+
"`developer`",
|
|
1482
|
+
"ask the user",
|
|
1483
|
+
]) {
|
|
1484
|
+
if (!freeSection.includes(token)) {
|
|
1485
|
+
fail(`docs/ai/harness/commands.md: missing declarative routing token ${token}`);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
if (!/adaptive fallback/i.test(freeSection)) {
|
|
1490
|
+
fail("docs/ai/harness/commands.md: missing declarative routing token adaptive fallback");
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
const featureCommand = read("commands/feature.md");
|
|
1494
|
+
if (!featureCommand.includes("Declarative routing")) {
|
|
1495
|
+
fail("commands/feature.md: missing declarative routing token Declarative routing");
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
/**
|
|
1500
|
+
* Validate the retry policies contract (ADK pattern 3).
|
|
1501
|
+
* Ensures commands.md contains a "Retry Policies" section with explicit
|
|
1502
|
+
* limits for developer (max 2 attempts), reviewer (max 2 rounds), /loop
|
|
1503
|
+
* (max 3 iterations) and a conceptual backoff note. Also ensures agents.md
|
|
1504
|
+
* declares the retry invariant.
|
|
1505
|
+
*/
|
|
1506
|
+
function checkRetryPoliciesContract() {
|
|
1507
|
+
const commandDocs = read("docs/ai/harness/commands.md");
|
|
1508
|
+
const retrySection = commandDocs.split("## Retry Policies")[1]?.split(/\n## (?![#])/)[0] || "";
|
|
1509
|
+
|
|
1510
|
+
if (!retrySection) {
|
|
1511
|
+
fail("docs/ai/harness/commands.md: missing retry policy token Retry Policies");
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
for (const token of [
|
|
1515
|
+
"maximum 2 attempts",
|
|
1516
|
+
"maximum 2 rounds",
|
|
1517
|
+
"maximum 3 iterations",
|
|
1518
|
+
"backoff",
|
|
1519
|
+
]) {
|
|
1520
|
+
if (!retrySection.includes(token)) {
|
|
1521
|
+
fail(`docs/ai/harness/commands.md: missing retry policy token ${token}`);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
const agentsDocs = read("docs/ai/harness/agents.md");
|
|
1526
|
+
if (!/retry limits/i.test(agentsDocs) || !/do not retry indefinitely/i.test(agentsDocs)) {
|
|
1527
|
+
fail("docs/ai/harness/agents.md: missing retry policy token retry invariant");
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
checkConfig();
|
|
1532
|
+
checkAgentsIndex();
|
|
1533
|
+
checkFrontmatter();
|
|
1534
|
+
checkAgentDocsCoverage();
|
|
1535
|
+
checkCommandDocsCoverage();
|
|
1536
|
+
checkLoopContract();
|
|
1537
|
+
checkLeadRouterContract();
|
|
1538
|
+
checkFeatureContract();
|
|
1539
|
+
checkPlanContract();
|
|
1540
|
+
checkHarnessDocs();
|
|
1541
|
+
checkEvolutionRuns();
|
|
1542
|
+
checkTaskContractSurface();
|
|
1543
|
+
checkResultContractSurface();
|
|
1544
|
+
checkInitContextPolicy();
|
|
1545
|
+
checkMechanismRegistries();
|
|
1546
|
+
checkRouterScenarios();
|
|
1547
|
+
checkEvolveContract();
|
|
1548
|
+
checkSessionSourceDocs();
|
|
1549
|
+
checkCrossAgentContract();
|
|
1550
|
+
checkCommandContracts();
|
|
1551
|
+
checkSkillRegistryPresence();
|
|
1552
|
+
checkLeadSkillResolution();
|
|
1553
|
+
checkAgentSkillLoading();
|
|
1554
|
+
checkSkillRegistryGenerator();
|
|
1555
|
+
checkInitCommand();
|
|
1556
|
+
checkAutoForecastContract();
|
|
1557
|
+
checkStrictTddContract();
|
|
1558
|
+
checkContextQuarantineContract();
|
|
1559
|
+
checkMemoryAsHintContract();
|
|
1560
|
+
checkPreflightAuditContract();
|
|
1561
|
+
checkOrchestratedReviewContract();
|
|
1562
|
+
checkHitlDurableContract();
|
|
1563
|
+
checkRoutingDeclarativoContract();
|
|
1564
|
+
checkRetryPoliciesContract();
|
|
1565
|
+
|
|
1566
|
+
if (errors.length > 0) {
|
|
1567
|
+
console.error("Harness check failed:");
|
|
1568
|
+
for (const error of errors) console.error(`- ${error}`);
|
|
1569
|
+
process.exit(1);
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
console.log("Harness check passed.");
|