opencode-agent-orchestration-kit 1.0.32 → 1.0.37

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 (88) hide show
  1. package/README.md +73 -4
  2. package/SECURITY.md +7 -0
  3. package/docs/cli.md +100 -0
  4. package/docs/installation.md +25 -5
  5. package/docs/quickstart.md +1 -1
  6. package/docs/releases/v1.0.33.md +72 -0
  7. package/docs/releases/v1.0.34.md +59 -0
  8. package/docs/releases/v1.0.35.md +62 -0
  9. package/docs/releases/v1.0.36.md +58 -0
  10. package/docs/releases/v1.0.37.md +53 -0
  11. package/docs/security.md +4 -0
  12. package/docs/supply-chain.md +9 -5
  13. package/docs/threat-model.md +244 -0
  14. package/docs/use-cases/README.md +31 -0
  15. package/docs/use-cases/direct-label-change/README.md +76 -0
  16. package/docs/use-cases/direct-label-change/before/package.json +8 -0
  17. package/docs/use-cases/direct-label-change/before/src/settings-label.mjs +1 -0
  18. package/docs/use-cases/direct-label-change/before/test/settings-label.test.mjs +8 -0
  19. package/docs/use-cases/direct-label-change/case.json +118 -0
  20. package/docs/use-cases/direct-label-change/expected/package.json +8 -0
  21. package/docs/use-cases/direct-label-change/expected/src/settings-label.mjs +1 -0
  22. package/docs/use-cases/direct-label-change/expected/test/settings-label.test.mjs +8 -0
  23. package/docs/use-cases/feature-tag-normalizer/README.md +78 -0
  24. package/docs/use-cases/feature-tag-normalizer/before/package.json +8 -0
  25. package/docs/use-cases/feature-tag-normalizer/before/src/normalize-tags.mjs +3 -0
  26. package/docs/use-cases/feature-tag-normalizer/before/test/normalize-tags.test.mjs +13 -0
  27. package/docs/use-cases/feature-tag-normalizer/case.json +119 -0
  28. package/docs/use-cases/feature-tag-normalizer/expected/package.json +8 -0
  29. package/docs/use-cases/feature-tag-normalizer/expected/src/normalize-tags.mjs +14 -0
  30. package/docs/use-cases/feature-tag-normalizer/expected/test/normalize-tags.test.mjs +18 -0
  31. package/docs/workflows.md +6 -0
  32. package/opencode/agents/lead.md +11 -2
  33. package/opencode/agents/review_api.md +26 -9
  34. package/opencode/agents/review_coordinator.md +60 -68
  35. package/opencode/agents/review_quality.md +27 -11
  36. package/opencode/agents/review_security.md +26 -10
  37. package/opencode/agents/review_tests.md +26 -9
  38. package/opencode/agents/reviewer.md +95 -80
  39. package/opencode/commands/autonomous.md +75 -0
  40. package/opencode/commands/evolve.md +3 -1
  41. package/opencode/commands/feature.md +6 -2
  42. package/opencode/commands/loop.md +12 -8
  43. package/opencode/commands/review-orchestrated.md +26 -24
  44. package/opencode/commands/review-preflight.md +8 -7
  45. package/opencode/commands/review.md +27 -10
  46. package/opencode/docs/ai/harness/README.md +5 -0
  47. package/opencode/docs/ai/harness/agents.md +27 -3
  48. package/opencode/docs/ai/harness/checks.md +18 -0
  49. package/opencode/docs/ai/harness/commands.md +44 -0
  50. package/opencode/docs/ai/harness/orchestrated-review.md +8 -1
  51. package/opencode/docs/ai/harness/orchestration-contracts.json +924 -0
  52. package/opencode/package-lock.json +14 -8
  53. package/opencode/package.json +1 -0
  54. package/opencode/plugins/shell-export-guard.ts +23 -0
  55. package/opencode/scripts/adversarial-harness.test.mjs +5 -2
  56. package/opencode/scripts/check-harness.mjs +873 -18
  57. package/opencode/scripts/check-harness.test.mjs +562 -0
  58. package/opencode/scripts/loop-state.mjs +88 -14
  59. package/opencode/scripts/loop-state.test.mjs +82 -5
  60. package/opencode/scripts/review-orchestrated-prepare.mjs +18 -1
  61. package/opencode/scripts/review-orchestrated-prepare.test.mjs +49 -0
  62. package/opencode/scripts/shell-export-policy.d.mts +4 -0
  63. package/opencode/scripts/shell-export-policy.mjs +272 -0
  64. package/opencode/scripts/shell-export-policy.test.mjs +96 -0
  65. package/opencode/skills/code-review-and-quality/SKILL.md +63 -321
  66. package/opencode/skills/code-review-and-quality/references/profiles/backend-clean-ddd-cqrs.md +60 -0
  67. package/opencode/skills/code-review-and-quality/references/profiles/backend.md +54 -0
  68. package/opencode/skills/code-review-and-quality/references/profiles/frontend-clean-layered.md +60 -0
  69. package/opencode/skills/code-review-and-quality/references/profiles/frontend.md +62 -0
  70. package/opencode/skills/code-review-and-quality/references/review-policy.md +258 -0
  71. package/package.json +5 -2
  72. package/scripts/check-supply-chain.mjs +16 -2
  73. package/scripts/check-supply-chain.test.mjs +52 -1
  74. package/scripts/check-threat-model.mjs +421 -0
  75. package/scripts/check-threat-model.test.mjs +304 -0
  76. package/scripts/check-use-cases.mjs +501 -0
  77. package/scripts/check-use-cases.test.mjs +225 -0
  78. package/scripts/check.sh +55 -1
  79. package/scripts/install-smoke.sh +24 -1
  80. package/scripts/manage-installation.mjs +567 -25
  81. package/scripts/manage-installation.test.mjs +418 -0
  82. package/scripts/oak.mjs +246 -0
  83. package/scripts/oak.test.mjs +329 -0
  84. package/scripts/package-smoke.mjs +57 -0
  85. package/scripts/package-smoke.test.mjs +75 -2
  86. package/scripts/version.mjs +1 -0
  87. package/scripts/version.test.mjs +3 -2
  88. package/supply-chain.json +1 -0
@@ -5,6 +5,7 @@ import { execSync } from "node:child_process";
5
5
 
6
6
  const root = process.cwd();
7
7
  const errors = [];
8
+ let orchestrationCatalog = null;
8
9
 
9
10
  function read(rel) {
10
11
  return fs.readFileSync(path.join(root, rel), "utf8");
@@ -79,6 +80,630 @@ function parseJson(rel) {
79
80
  }
80
81
  }
81
82
 
83
+ const orchestrationContractRel =
84
+ "docs/ai/harness/orchestration-contracts.json";
85
+
86
+ function readOrchestrationContract() {
87
+ if (!exists(orchestrationContractRel)) {
88
+ fail(`${orchestrationContractRel}: missing orchestration contract`);
89
+ return null;
90
+ }
91
+ const stat = fs.lstatSync(path.join(root, orchestrationContractRel));
92
+ if (stat.isSymbolicLink() || !stat.isFile()) {
93
+ fail(`${orchestrationContractRel}: must be a regular non-symlink file`);
94
+ return null;
95
+ }
96
+ return parseJson(orchestrationContractRel);
97
+ }
98
+
99
+ function checkOrchestrationContracts() {
100
+ const contract = readOrchestrationContract();
101
+ if (!contract) return;
102
+ checkExactKeys("contract", contract, [
103
+ "schema_version",
104
+ "contract_id",
105
+ "evidence_types",
106
+ "agents",
107
+ "commands",
108
+ "routing_rules",
109
+ "retry_policies",
110
+ "workflows",
111
+ "profiles",
112
+ ]);
113
+ if (contract.schema_version !== 1) {
114
+ fail(`${orchestrationContractRel}: schema_version must be 1`);
115
+ }
116
+ if (contract.contract_id !== "oak-orchestration") {
117
+ fail(`${orchestrationContractRel}: contract_id must be oak-orchestration`);
118
+ }
119
+ const canonicalEvidence = [
120
+ "live_smoke",
121
+ "manual_oracle",
122
+ "static_contract",
123
+ "transcript_replay",
124
+ ];
125
+ if (JSON.stringify(contract.evidence_types) !== JSON.stringify(canonicalEvidence)) {
126
+ fail(
127
+ `${orchestrationContractRel}: evidence_types must match the canonical catalog`,
128
+ );
129
+ }
130
+ const expectedAgentIds = listMarkdown("agents")
131
+ .map(stripMarkdownExtension)
132
+ .sort();
133
+ const declaredAgentIds = Array.isArray(contract.agents)
134
+ ? contract.agents.map((agent) => agent?.id).sort()
135
+ : [];
136
+ if (JSON.stringify(declaredAgentIds) !== JSON.stringify(expectedAgentIds)) {
137
+ fail(`${orchestrationContractRel}: agent catalog must match harness agents`);
138
+ }
139
+ const actualAgentDelegations = new Map();
140
+ if (Array.isArray(contract.agents)) {
141
+ for (const agent of contract.agents) {
142
+ const label = `agent ${agent?.id ?? "<unknown>"}`;
143
+ if (!checkExactKeys(label, agent, [
144
+ "id",
145
+ "mode",
146
+ "permission_invariants",
147
+ "delegates_to",
148
+ ])) {
149
+ continue;
150
+ }
151
+ if (!/^[a-z][a-z0-9_]*$/.test(agent.id)) {
152
+ fail(`${orchestrationContractRel}: ${label} id must be canonical`);
153
+ continue;
154
+ }
155
+ if (!["primary", "subagent", "all"].includes(agent.mode)) {
156
+ fail(`${orchestrationContractRel}: ${label} mode is invalid`);
157
+ }
158
+ if (!checkExactKeys(`${label} permission_invariants`, agent.permission_invariants, [
159
+ "repository_write",
160
+ "task_default",
161
+ ])) {
162
+ continue;
163
+ }
164
+ for (const key of ["repository_write", "task_default"]) {
165
+ if (!["allow", "ask", "deny", "unspecified"].includes(agent.permission_invariants[key])) {
166
+ fail(`${orchestrationContractRel}: ${label} ${key} is invalid`);
167
+ }
168
+ }
169
+ checkSortedUniqueStrings(`${label} delegates_to`, agent.delegates_to);
170
+
171
+ const rel = `agents/${agent.id}.md`;
172
+ if (!exists(rel)) continue;
173
+ const frontmatter = parseFrontmatter(rel);
174
+ const permissions = parsePortableAgentPermissions(rel);
175
+ if (agent.mode !== frontmatter.mode) {
176
+ fail(`${orchestrationContractRel}: ${label} mode must match frontmatter`);
177
+ }
178
+ if (agent.permission_invariants.repository_write !== permissions.repositoryWrite) {
179
+ fail(`${orchestrationContractRel}: ${label} repository_write must match frontmatter`);
180
+ }
181
+ if (agent.permission_invariants.task_default !== permissions.taskDefault) {
182
+ fail(`${orchestrationContractRel}: ${label} task_default must match frontmatter`);
183
+ }
184
+ actualAgentDelegations.set(agent.id, permissions.taskAllows);
185
+ }
186
+ }
187
+
188
+ const declaredCommandIds = Array.isArray(contract.commands)
189
+ ? contract.commands.map((command) => command?.id)
190
+ : [];
191
+ checkSortedUniqueStrings("command ids", declaredCommandIds);
192
+ if (Array.isArray(contract.commands)) {
193
+ for (const command of contract.commands) {
194
+ const label = `command ${command?.id ?? "<unknown>"}`;
195
+ if (!checkExactKeys(label, command, [
196
+ "id",
197
+ "root_agent",
198
+ "subtask",
199
+ "workflow",
200
+ ])) {
201
+ continue;
202
+ }
203
+ if (!/^[a-z][a-z0-9-]*$/.test(command.id)) {
204
+ fail(`${orchestrationContractRel}: ${label} id must be canonical`);
205
+ continue;
206
+ }
207
+ if (!expectedAgentIds.includes(command.root_agent)) {
208
+ fail(`${orchestrationContractRel}: ${label} root_agent must reference an agent`);
209
+ }
210
+ if (typeof command.subtask !== "boolean") {
211
+ fail(`${orchestrationContractRel}: ${label} subtask must be boolean`);
212
+ }
213
+ if (!/^[a-z][a-z0-9-]*$/.test(command.workflow)) {
214
+ fail(`${orchestrationContractRel}: ${label} workflow must be canonical`);
215
+ }
216
+
217
+ const rel = `commands/${command.id}.md`;
218
+ if (!exists(rel)) continue;
219
+ const frontmatter = parseFrontmatter(rel);
220
+ const actualSubtask = frontmatter.subtask === "true";
221
+ if (command.root_agent !== frontmatter.agent) {
222
+ fail(`${orchestrationContractRel}: ${label} root_agent must match frontmatter`);
223
+ }
224
+ if (command.subtask !== actualSubtask) {
225
+ fail(`${orchestrationContractRel}: ${label} subtask must match frontmatter`);
226
+ }
227
+ }
228
+ }
229
+
230
+ const workflowIds = Array.isArray(contract.workflows)
231
+ ? contract.workflows.map((workflow) => workflow?.id)
232
+ : [];
233
+ checkSortedUniqueStrings("workflow ids", workflowIds);
234
+ const canonicalWorkflowIds = [
235
+ "autonomous",
236
+ "design",
237
+ "direct-development",
238
+ "direct-research",
239
+ "direct-review",
240
+ "direct-spec",
241
+ "evolve",
242
+ "feature",
243
+ "freeform",
244
+ "init",
245
+ "loop",
246
+ "plan",
247
+ "review-orchestrated",
248
+ "review-preflight",
249
+ "scope",
250
+ ];
251
+ if (JSON.stringify(workflowIds) !== JSON.stringify(canonicalWorkflowIds)) {
252
+ fail(`${orchestrationContractRel}: workflow catalog must match the approved catalog`);
253
+ }
254
+ const workflowIdSet = new Set(workflowIds);
255
+ const retryIds = Array.isArray(contract.retry_policies)
256
+ ? contract.retry_policies.map((policy) => policy?.id)
257
+ : [];
258
+ checkSortedUniqueStrings("retry ids", retryIds);
259
+ const retryIdSet = new Set(retryIds);
260
+
261
+ const retryScopes = new Set();
262
+ if (Array.isArray(contract.retry_policies)) {
263
+ const approvedRetries = {
264
+ "autonomous-iterations": ["autonomous", 6, true, "block"],
265
+ "developer-default": ["developer", 2, true, "escalate-review"],
266
+ "loop-iterations": ["loop", 3, true, "ask-user"],
267
+ "reviewer-default": ["reviewer", 2, true, "block"],
268
+ };
269
+ for (const policy of contract.retry_policies) {
270
+ const label = `retry ${policy?.id ?? "<unknown>"}`;
271
+ if (!checkExactKeys(label, policy, [
272
+ "id",
273
+ "scope",
274
+ "max_attempts",
275
+ "requires_new_evidence",
276
+ "on_exhaustion",
277
+ ])) {
278
+ continue;
279
+ }
280
+ if (!/^[a-z][a-z0-9-]*$/.test(policy.id)) {
281
+ fail(`${orchestrationContractRel}: ${label} id must be canonical`);
282
+ }
283
+ if (!expectedAgentIds.includes(policy.scope) && !workflowIdSet.has(policy.scope)) {
284
+ fail(`${orchestrationContractRel}: ${label} scope must reference an agent or workflow`);
285
+ }
286
+ if (retryScopes.has(policy.scope)) {
287
+ fail(`${orchestrationContractRel}: retry scope ${policy.scope} must be unique`);
288
+ }
289
+ retryScopes.add(policy.scope);
290
+ if (!Number.isInteger(policy.max_attempts) || policy.max_attempts < 1 || policy.max_attempts > 6) {
291
+ fail(`${orchestrationContractRel}: ${label} max_attempts must be between 1 and 6`);
292
+ }
293
+ if (typeof policy.requires_new_evidence !== "boolean") {
294
+ fail(`${orchestrationContractRel}: ${label} requires_new_evidence must be boolean`);
295
+ }
296
+ if (!["ask-user", "block", "escalate-review"].includes(policy.on_exhaustion)) {
297
+ fail(`${orchestrationContractRel}: ${label} on_exhaustion is invalid`);
298
+ }
299
+ const observed = [
300
+ policy.scope,
301
+ policy.max_attempts,
302
+ policy.requires_new_evidence,
303
+ policy.on_exhaustion,
304
+ ];
305
+ if (JSON.stringify(observed) !== JSON.stringify(approvedRetries[policy.id])) {
306
+ fail(`${orchestrationContractRel}: ${label} must match the approved policy`);
307
+ }
308
+ }
309
+ }
310
+
311
+ const usedEntrypoints = new Set();
312
+ const entrypointWorkflows = new Map();
313
+ const approvedStageSequences = {
314
+ autonomous: [
315
+ "lead:required",
316
+ "developer:required",
317
+ "reviewer:required",
318
+ "developer:state-sync",
319
+ ],
320
+ design: ["designer:required"],
321
+ "direct-development": ["developer:required"],
322
+ "direct-research": ["researcher:required"],
323
+ "direct-review": ["reviewer:required"],
324
+ "direct-spec": ["specifier:required"],
325
+ evolve: [
326
+ "lead:required",
327
+ "evaluator:required",
328
+ "debugger:required",
329
+ "evolver:required",
330
+ "developer:conditional",
331
+ "evaluator:required",
332
+ "debugger:required",
333
+ "reviewer:required",
334
+ ],
335
+ feature: [
336
+ "lead:required",
337
+ "designer:conditional",
338
+ "researcher:conditional",
339
+ "specifier:required",
340
+ "developer:required",
341
+ "reviewer:required",
342
+ ],
343
+ freeform: [
344
+ "lead:required",
345
+ "designer:conditional",
346
+ "researcher:conditional",
347
+ "specifier:conditional",
348
+ "developer:conditional",
349
+ "reviewer:conditional",
350
+ ],
351
+ init: ["lead:required"],
352
+ loop: [
353
+ "lead:required",
354
+ "developer:required",
355
+ "reviewer:required",
356
+ "developer:state-sync",
357
+ ],
358
+ plan: [
359
+ "lead:required",
360
+ "researcher:required",
361
+ "specifier:required",
362
+ "reviewer:required",
363
+ ],
364
+ "review-orchestrated": [
365
+ "review_coordinator:required",
366
+ "review_api:conditional",
367
+ "review_quality:conditional",
368
+ "review_security:conditional",
369
+ "review_tests:conditional",
370
+ "review_coordinator:state-sync",
371
+ ],
372
+ "review-preflight": ["lead:required"],
373
+ scope: ["scoper:required", "researcher:required", "specifier:required"],
374
+ };
375
+ const approvedCompletionAuthorities = {
376
+ autonomous: ["agent", "reviewer"],
377
+ design: ["agent", "designer"],
378
+ "direct-development": ["result-contract", null],
379
+ "direct-research": ["agent", "researcher"],
380
+ "direct-review": ["agent", "reviewer"],
381
+ "direct-spec": ["agent", "specifier"],
382
+ evolve: ["agent", "reviewer"],
383
+ feature: ["agent", "lead"],
384
+ freeform: ["agent", "lead"],
385
+ init: ["agent", "lead"],
386
+ loop: ["agent", "reviewer"],
387
+ plan: ["agent", "reviewer"],
388
+ "review-orchestrated": ["agent", "review_coordinator"],
389
+ "review-preflight": ["result-contract", null],
390
+ scope: ["result-contract", null],
391
+ };
392
+ const barrierConditions = new Set([
393
+ "acceptance-criteria-ready",
394
+ "approval-explicit",
395
+ "diff-reviewable",
396
+ "research-ready",
397
+ "review-approved",
398
+ "visual-criteria-ready",
399
+ ]);
400
+ if (Array.isArray(contract.workflows)) {
401
+ for (const workflow of contract.workflows) {
402
+ const label = `workflow ${workflow?.id ?? "<unknown>"}`;
403
+ if (!checkExactKeys(label, workflow, [
404
+ "id",
405
+ "entrypoints",
406
+ "stages",
407
+ "barriers",
408
+ "retry_policy",
409
+ "completion_authority",
410
+ "required_evidence",
411
+ "adaptive",
412
+ ])) {
413
+ continue;
414
+ }
415
+ checkSortedUniqueStrings(`${label} entrypoints`, workflow.entrypoints, { nonEmpty: true });
416
+ for (const entrypoint of Array.isArray(workflow.entrypoints) ? workflow.entrypoints : []) {
417
+ if (entrypoint !== "freeform" && !declaredCommandIds.includes(entrypoint)) {
418
+ fail(`${orchestrationContractRel}: ${label} entrypoint must reference a command`);
419
+ }
420
+ if (usedEntrypoints.has(entrypoint)) {
421
+ fail(`${orchestrationContractRel}: entrypoint ${entrypoint} must be unique`);
422
+ }
423
+ usedEntrypoints.add(entrypoint);
424
+ entrypointWorkflows.set(entrypoint, workflow.id);
425
+ }
426
+ if (!Array.isArray(workflow.stages) || workflow.stages.length === 0) {
427
+ fail(`${orchestrationContractRel}: ${label} stages must be non-empty`);
428
+ } else {
429
+ const seenAgents = new Set();
430
+ for (const [index, stage] of workflow.stages.entries()) {
431
+ const stageLabel = `${label} stage ${index}`;
432
+ if (!checkExactKeys(stageLabel, stage, ["agent", "requirement"])) continue;
433
+ if (!expectedAgentIds.includes(stage.agent)) {
434
+ fail(`${orchestrationContractRel}: ${label} stage agent must reference an agent`);
435
+ }
436
+ if (!["required", "conditional", "state-sync"].includes(stage.requirement)) {
437
+ fail(`${orchestrationContractRel}: ${stageLabel} requirement is invalid`);
438
+ }
439
+ const evolvePostChange =
440
+ workflow.id === "evolve"
441
+ && ["evaluator", "debugger"].includes(stage.agent)
442
+ && index >= 5;
443
+ if (seenAgents.has(stage.agent) && stage.requirement !== "state-sync" && !evolvePostChange) {
444
+ fail(`${orchestrationContractRel}: ${label} repeats ${stage.agent} without a recognized role`);
445
+ }
446
+ seenAgents.add(stage.agent);
447
+ }
448
+ const observedSequence = workflow.stages.map(
449
+ (stage) => `${stage.agent}:${stage.requirement}`,
450
+ );
451
+ if (JSON.stringify(observedSequence) !== JSON.stringify(approvedStageSequences[workflow.id])) {
452
+ fail(`${orchestrationContractRel}: ${label} stages must match the approved sequence`);
453
+ }
454
+ }
455
+ if (!Array.isArray(workflow.barriers)) {
456
+ fail(`${orchestrationContractRel}: ${label} barriers must be an array`);
457
+ } else {
458
+ checkSortedUniqueStrings(
459
+ `${label} barrier ids`,
460
+ workflow.barriers.map((barrier) => barrier?.id),
461
+ );
462
+ for (const barrier of workflow.barriers) {
463
+ const barrierLabel = `${label} barrier ${barrier?.id ?? "<unknown>"}`;
464
+ if (!checkExactKeys(barrierLabel, barrier, [
465
+ "id",
466
+ "before_stage",
467
+ "authority",
468
+ "condition",
469
+ ])) {
470
+ continue;
471
+ }
472
+ if (!Number.isInteger(barrier.before_stage)
473
+ || barrier.before_stage < 0
474
+ || barrier.before_stage >= workflow.stages.length) {
475
+ fail(`${orchestrationContractRel}: ${barrierLabel} before_stage is invalid`);
476
+ }
477
+ if (!["human", "none", ...expectedAgentIds].includes(barrier.authority)) {
478
+ fail(`${orchestrationContractRel}: ${barrierLabel} authority is invalid`);
479
+ }
480
+ if (!barrierConditions.has(barrier.condition)) {
481
+ fail(`${orchestrationContractRel}: ${barrierLabel} condition is invalid`);
482
+ }
483
+ if (barrier.condition === "approval-explicit" && barrier.authority !== "human") {
484
+ fail(`${orchestrationContractRel}: ${barrierLabel} approval-explicit requires human authority`);
485
+ }
486
+ }
487
+ }
488
+ if (workflow.retry_policy !== null && !retryIdSet.has(workflow.retry_policy)) {
489
+ fail(`${orchestrationContractRel}: ${label} retry_policy must reference a retry`);
490
+ }
491
+ if (checkExactKeys(`${label} completion_authority`, workflow.completion_authority, [
492
+ "kind",
493
+ "agent",
494
+ ])) {
495
+ const completion = workflow.completion_authority;
496
+ if (!["agent", "human", "result-contract"].includes(completion.kind)) {
497
+ fail(`${orchestrationContractRel}: ${label} completion kind is invalid`);
498
+ } else if (completion.kind === "agent" && !expectedAgentIds.includes(completion.agent)) {
499
+ fail(`${orchestrationContractRel}: ${label} completion agent must reference an agent`);
500
+ } else if (completion.kind !== "agent" && completion.agent !== null) {
501
+ fail(`${orchestrationContractRel}: ${label} completion agent must be null`);
502
+ }
503
+ if (JSON.stringify([completion.kind, completion.agent])
504
+ !== JSON.stringify(approvedCompletionAuthorities[workflow.id])) {
505
+ fail(`${orchestrationContractRel}: ${label} completion authority must match the approved authority`);
506
+ }
507
+ }
508
+ if (checkSortedUniqueStrings(
509
+ `${label} required_evidence`,
510
+ workflow.required_evidence,
511
+ { nonEmpty: true },
512
+ )) {
513
+ for (const evidence of workflow.required_evidence) {
514
+ if (!canonicalEvidence.includes(evidence)) {
515
+ fail(`${orchestrationContractRel}: ${label} required_evidence is invalid`);
516
+ }
517
+ }
518
+ }
519
+ if (typeof workflow.adaptive !== "boolean") {
520
+ fail(`${orchestrationContractRel}: ${label} adaptive must be boolean`);
521
+ } else if (workflow.adaptive !== (workflow.id === "freeform")) {
522
+ fail(`${orchestrationContractRel}: ${label} adaptive must match the approved policy`);
523
+ }
524
+ }
525
+ }
526
+ for (const command of Array.isArray(contract.commands) ? contract.commands : []) {
527
+ if (entrypointWorkflows.get(command.id) !== command.workflow) {
528
+ fail(`${orchestrationContractRel}: command ${command.id} workflow must match its entrypoint`);
529
+ }
530
+ }
531
+
532
+ const routingPrecedence = new Set();
533
+ let hasAskUserFallback = false;
534
+ if (Array.isArray(contract.routing_rules)) {
535
+ const approvedRouting = {
536
+ "technical-uncertainty": ["researcher", 1],
537
+ "reviewable-change": ["reviewer", 2],
538
+ "visual-impact": ["designer", 3],
539
+ "specification-gap": ["specifier", 4],
540
+ "small-clear-change": ["developer", 5],
541
+ "routing-ambiguity": ["ask-user", 6],
542
+ };
543
+ if (JSON.stringify(contract.routing_rules.map((rule) => rule?.id))
544
+ !== JSON.stringify(Object.keys(approvedRouting))) {
545
+ fail(`${orchestrationContractRel}: routing rule catalog must match the approved catalog`);
546
+ }
547
+ for (const rule of contract.routing_rules) {
548
+ const label = `routing rule ${rule?.id ?? "<unknown>"}`;
549
+ if (!checkExactKeys(label, rule, ["id", "target", "precedence"])) continue;
550
+ if (!expectedAgentIds.includes(rule.target) && rule.target !== "ask-user") {
551
+ fail(`${orchestrationContractRel}: ${label} target must reference an agent or ask-user`);
552
+ }
553
+ if (!Number.isInteger(rule.precedence) || rule.precedence < 1) {
554
+ fail(`${orchestrationContractRel}: ${label} precedence must be a positive integer`);
555
+ }
556
+ if (routingPrecedence.has(rule.precedence)) {
557
+ fail(`${orchestrationContractRel}: routing precedence ${rule.precedence} must be unique`);
558
+ }
559
+ routingPrecedence.add(rule.precedence);
560
+ if (rule.target === "ask-user") hasAskUserFallback = true;
561
+ if (JSON.stringify([rule.target, rule.precedence]) !== JSON.stringify(approvedRouting[rule.id])) {
562
+ fail(`${orchestrationContractRel}: ${label} must match the approved rule`);
563
+ }
564
+ }
565
+ }
566
+ if (Array.isArray(contract.routing_rules) && contract.routing_rules.length > 0 && !hasAskUserFallback) {
567
+ fail(`${orchestrationContractRel}: routing rules must include ask-user fallback`);
568
+ }
569
+
570
+ checkExactKeys("profiles", contract.profiles, ["private", "public"]);
571
+ const actualCommandIds = listMarkdown("commands")
572
+ .map(stripMarkdownExtension)
573
+ .sort();
574
+ let matchingProfiles = 0;
575
+ let selectedProfile = null;
576
+ for (const [profileId, profile] of Object.entries(
577
+ isPlainObject(contract.profiles) ? contract.profiles : {},
578
+ )) {
579
+ const label = `profile ${profileId}`;
580
+ if (!checkExactKeys(label, profile, [
581
+ "agent_ids",
582
+ "command_ids",
583
+ "delegation_extensions",
584
+ ])) {
585
+ continue;
586
+ }
587
+ checkSortedUniqueStrings(`${label} agent_ids`, profile.agent_ids);
588
+ checkSortedUniqueStrings(`${label} command_ids`, profile.command_ids);
589
+ if (!isPlainObject(profile.delegation_extensions)) {
590
+ fail(`${orchestrationContractRel}: ${label} delegation_extensions must be an object`);
591
+ } else {
592
+ for (const [agentId, delegates] of Object.entries(profile.delegation_extensions)) {
593
+ if (!expectedAgentIds.includes(agentId)) {
594
+ fail(`${orchestrationContractRel}: ${label} delegation extension agent is unknown`);
595
+ }
596
+ checkSortedUniqueStrings(`${label} ${agentId} delegation_extensions`, delegates, {
597
+ nonEmpty: true,
598
+ });
599
+ for (const delegate of Array.isArray(delegates) ? delegates : []) {
600
+ if (!expectedAgentIds.includes(delegate)) {
601
+ fail(`${orchestrationContractRel}: ${label} delegation extension target is unknown`);
602
+ }
603
+ }
604
+ }
605
+ }
606
+ if (
607
+ JSON.stringify(profile.agent_ids) === JSON.stringify(expectedAgentIds)
608
+ && JSON.stringify(profile.command_ids) === JSON.stringify(actualCommandIds)
609
+ ) {
610
+ matchingProfiles += 1;
611
+ selectedProfile = profile;
612
+ }
613
+ }
614
+ const profiledCommandIds = [
615
+ ...new Set(
616
+ Object.values(isPlainObject(contract.profiles) ? contract.profiles : {})
617
+ .flatMap((profile) => Array.isArray(profile?.command_ids) ? profile.command_ids : []),
618
+ ),
619
+ ].sort();
620
+ if (JSON.stringify(declaredCommandIds) !== JSON.stringify(profiledCommandIds)) {
621
+ fail(`${orchestrationContractRel}: command catalog must match inventory profiles`);
622
+ }
623
+ if (matchingProfiles !== 1) {
624
+ fail(`${orchestrationContractRel}: must select exactly one inventory profile`);
625
+ } else {
626
+ const agentsById = new Map(contract.agents.map((agent) => [agent.id, agent]));
627
+ for (const agentId of expectedAgentIds) {
628
+ const base = agentsById.get(agentId)?.delegates_to ?? [];
629
+ const extension = selectedProfile.delegation_extensions[agentId] ?? [];
630
+ const effective = [...new Set([...base, ...extension])].sort();
631
+ if (JSON.stringify(effective) !== JSON.stringify(actualAgentDelegations.get(agentId))) {
632
+ fail(`${orchestrationContractRel}: agent ${agentId} delegates_to must match selected profile`);
633
+ }
634
+ }
635
+ orchestrationCatalog = {
636
+ agentIds: new Set(expectedAgentIds),
637
+ commandIds: new Set(selectedProfile.command_ids),
638
+ evidenceTypes: new Set(canonicalEvidence),
639
+ routingTargets: contract.routing_rules.map((rule) => rule.target),
640
+ };
641
+ }
642
+ }
643
+
644
+ function isPlainObject(value) {
645
+ return value !== null && typeof value === "object" && !Array.isArray(value);
646
+ }
647
+
648
+ function checkExactKeys(label, value, expected) {
649
+ if (!isPlainObject(value)) {
650
+ fail(`${orchestrationContractRel}: ${label} must be an object`);
651
+ return false;
652
+ }
653
+ const actual = Object.keys(value).sort();
654
+ const wanted = [...expected].sort();
655
+ if (JSON.stringify(actual) !== JSON.stringify(wanted)) {
656
+ fail(
657
+ `${orchestrationContractRel}: ${label} must contain exactly ${wanted.join(", ")}`,
658
+ );
659
+ return false;
660
+ }
661
+ return true;
662
+ }
663
+
664
+ function checkSortedUniqueStrings(label, value, { nonEmpty = false } = {}) {
665
+ if (
666
+ !Array.isArray(value)
667
+ || (nonEmpty && value.length === 0)
668
+ || value.some((item) => typeof item !== "string" || item.trim() !== item)
669
+ || new Set(value).size !== value.length
670
+ || JSON.stringify(value) !== JSON.stringify([...value].sort())
671
+ ) {
672
+ fail(`${orchestrationContractRel}: ${label} must be a sorted unique string array`);
673
+ return false;
674
+ }
675
+ return true;
676
+ }
677
+
678
+ function parsePortableAgentPermissions(rel) {
679
+ let repositoryWrite = "unspecified";
680
+ let taskDefault = "unspecified";
681
+ const taskAllows = [];
682
+ let section = "";
683
+
684
+ for (const line of frontmatterBlock(rel).split("\n")) {
685
+ const sectionMatch = line.match(/^ ([A-Za-z_][A-Za-z0-9_-]*):(?:\s*(\S+))?$/);
686
+ if (sectionMatch) {
687
+ section = sectionMatch[1];
688
+ if (section === "edit" && sectionMatch[2]) {
689
+ repositoryWrite = sectionMatch[2];
690
+ }
691
+ continue;
692
+ }
693
+ if (section !== "task") continue;
694
+ const taskMatch = line.match(/^ "?([A-Za-z_*][A-Za-z0-9_*-]*)"?:\s*(allow|ask|deny)$/);
695
+ if (!taskMatch) continue;
696
+ if (taskMatch[1] === "*") taskDefault = taskMatch[2];
697
+ else if (taskMatch[2] === "allow") taskAllows.push(taskMatch[1]);
698
+ }
699
+
700
+ return {
701
+ repositoryWrite,
702
+ taskDefault,
703
+ taskAllows: taskAllows.sort(),
704
+ };
705
+ }
706
+
82
707
  function parseFrontmatter(rel) {
83
708
  const text = read(rel);
84
709
  if (!text.startsWith("---\n")) {
@@ -155,6 +780,46 @@ function checkCommandDocsCoverage() {
155
780
  }
156
781
  }
157
782
 
783
+ function checkAutonomousContract() {
784
+ const rel = "commands/autonomous.md";
785
+ if (!exists(rel)) {
786
+ fail(`${rel}: missing command`);
787
+ return;
788
+ }
789
+ const text = contractText(read(rel));
790
+ for (const token of [
791
+ "authorization: explicit_command_invocation",
792
+ "execution_scope: local_checkout_only",
793
+ "max_iterations_per_invocation: 6",
794
+ "planned_iteration_budget: task_specific_1_to_6",
795
+ "hard_safety_ceiling: 6",
796
+ "completion_authority: reviewer_only",
797
+ "validation_gate: deterministic_per_iteration",
798
+ "canonical_state_path: .opencode/loops/<slug>.json",
799
+ "history_path: .opencode/loops/<slug>.history.jsonl",
800
+ "lock_path: .opencode/loops/<slug>.lock",
801
+ "human_view_path: .opencode/loops/<slug>.md",
802
+ "worktree_mode: prohibited",
803
+ "scheduling: prohibited",
804
+ "parallelism: prohibited",
805
+ "external_writes: prohibited",
806
+ "auto_commit_push_merge_deploy: prohibited",
807
+ "reviewer_execution: task_subagent_only",
808
+ "reviewer_evidence: required_subagent_attestation",
809
+ "oak state init --root .",
810
+ "task reviewer",
811
+ "oak state attest-review --root .",
812
+ "developer -> reviewer -> developer (state sync)",
813
+ "Do not create worktrees, schedule runs, execute parallel branches, use network",
814
+ "two iterations without observable progress",
815
+ "repeated failure",
816
+ "Final reviewer approval stops the cycle immediately.",
817
+ "An explicit schema migration requires renewed human approval before `oak state resume`",
818
+ ]) {
819
+ if (!text.includes(token)) fail(`${rel}: missing ${token}`);
820
+ }
821
+ }
822
+
158
823
  function checkLoopContract() {
159
824
  const rel = "commands/loop.md";
160
825
  if (!exists(rel)) {
@@ -247,6 +912,107 @@ function checkFrontmatter() {
247
912
  }
248
913
  }
249
914
 
915
+ function checkCanonicalReviewPolicy() {
916
+ const policyRel = "skills/code-review-and-quality/references/review-policy.md";
917
+ const skillRel = "skills/code-review-and-quality/SKILL.md";
918
+ const profiles = [
919
+ ["backend", "skills/code-review-and-quality/references/profiles/backend.md"],
920
+ ["backend-clean-ddd-cqrs", "skills/code-review-and-quality/references/profiles/backend-clean-ddd-cqrs.md"],
921
+ ["frontend", "skills/code-review-and-quality/references/profiles/frontend.md"],
922
+ ["frontend-clean-layered", "skills/code-review-and-quality/references/profiles/frontend-clean-layered.md"],
923
+ ];
924
+
925
+ for (const rel of [policyRel, ...profiles.map(([, rel]) => rel)]) {
926
+ if (!exists(rel)) {
927
+ fail(`${rel}: missing canonical review surface`);
928
+ continue;
929
+ }
930
+ const stat = fs.lstatSync(path.join(root, rel));
931
+ if (stat.isSymbolicLink() || !stat.isFile()) {
932
+ fail(`${rel}: must be a regular non-symlink file`);
933
+ }
934
+ }
935
+
936
+ if (exists(policyRel)) {
937
+ const policy = read(policyRel);
938
+ for (const heading of [
939
+ "## Seven Review Gates",
940
+ "## Independent Verification",
941
+ "## Causality",
942
+ "## Findings Contract",
943
+ "## Review Stage And Verdict",
944
+ "## Blocking Rules",
945
+ "## Pre-existing Debt",
946
+ "## Specialist And Coordinator Limits",
947
+ "## Final Review Output",
948
+ ]) {
949
+ if (!policy.includes(heading)) fail(`${policyRel}: missing heading ${heading}`);
950
+ }
951
+ const normalized = contractText(policy);
952
+ for (const token of [
953
+ "introduced | worsened | pre_existing | unknown",
954
+ "blocking | non_blocking | pre_existing | needs_human_verification",
955
+ "review_stage: preflight | partial | final",
956
+ "verdict: not_run | pass | pass_with_observations | needs_changes | blocked",
957
+ "Never block solely because hypothetical external callers may exist",
958
+ "Only the general reviewer can consolidate evidence",
959
+ ]) {
960
+ if (!normalized.includes(token)) fail(`${policyRel}: missing canonical token ${token}`);
961
+ }
962
+ }
963
+
964
+ const skill = exists(skillRel) ? read(skillRel) : "";
965
+ for (const [profile] of profiles) {
966
+ if (!skill.includes(`references/profiles/${profile}.md`)) {
967
+ fail(`${skillRel}: missing profile routing ${profile}`);
968
+ }
969
+ }
970
+ if (!contractText(skill).includes("explicit declaration") || !contractText(skill).includes("layout alone does not activate")) {
971
+ fail(`${skillRel}: strict architecture profile requires explicit declaration`);
972
+ }
973
+
974
+ const reviewerRel = "agents/reviewer.md";
975
+ const reviewer = read(reviewerRel);
976
+ for (const token of [
977
+ "canonical_policy: required",
978
+ "primary_evidence: diff_and_original_artifacts",
979
+ "developer_summary_is_not_evidence",
980
+ "causality: required",
981
+ "review_stage: final",
982
+ "final_verdict_authority: reviewer",
983
+ "pre_existing_debt: non_blocking",
984
+ ]) {
985
+ if (!reviewer.includes(token)) fail(`${reviewerRel}: missing ${token}`);
986
+ }
987
+ if (!frontmatterBlock(reviewerRel).includes('"code-review-and-quality": allow')) {
988
+ fail(`${reviewerRel}: missing canonical review skill permission`);
989
+ }
990
+
991
+ for (const rel of [
992
+ "agents/review_quality.md",
993
+ "agents/review_security.md",
994
+ "agents/review_tests.md",
995
+ "agents/review_api.md",
996
+ ]) {
997
+ const text = read(rel);
998
+ for (const token of [
999
+ "canonical_policy: required",
1000
+ "causality: required",
1001
+ "review_stage: partial",
1002
+ "verdict: not_run",
1003
+ "integral_verdict: forbidden",
1004
+ "disposition",
1005
+ "causality",
1006
+ "profiles",
1007
+ "categories",
1008
+ "read_scope",
1009
+ "omitted_coverage",
1010
+ ]) {
1011
+ if (!text.includes(token)) fail(`${rel}: missing ${token}`);
1012
+ }
1013
+ }
1014
+ }
1015
+
250
1016
  function checkOrchestratedReviewContract() {
251
1017
  const preflightCommandRel = "commands/review-preflight.md";
252
1018
  const commandRel = "commands/review-orchestrated.md";
@@ -260,7 +1026,15 @@ function checkOrchestratedReviewContract() {
260
1026
 
261
1027
  if (exists("commands/review.md")) {
262
1028
  const review = read("commands/review.md");
263
- for (const token of ["agent: reviewer", "Review the current diff", "git diff"]) {
1029
+ for (const token of [
1030
+ "agent: reviewer",
1031
+ "subtask: false",
1032
+ "Review the current diff",
1033
+ "git diff",
1034
+ "canonical_policy: required",
1035
+ "review_stage: final",
1036
+ "final_verdict_authority: reviewer",
1037
+ ]) {
264
1038
  if (!review.includes(token)) fail(`commands/review.md: existing /review contract changed or missing ${token}`);
265
1039
  }
266
1040
  if (review.includes("review_coordinator") || review.includes("review-orchestrated")) {
@@ -273,7 +1047,7 @@ function checkOrchestratedReviewContract() {
273
1047
  for (const token of [
274
1048
  "agent: lead",
275
1049
  "recommended daily path",
276
- "rtk node scripts/review-orchestrated-prepare.mjs --dry-run",
1050
+ "OPENCODE_CONFIG_DIR",
277
1051
  "manifest.json",
278
1052
  "shared-review-context.md",
279
1053
  "patches/",
@@ -281,6 +1055,8 @@ function checkOrchestratedReviewContract() {
281
1055
  "Do not invoke reviewers",
282
1056
  "Do not claim an AI review was performed",
283
1057
  "Do not ask follow-up questions",
1058
+ "review_stage: preflight",
1059
+ "verdict: not_run",
284
1060
  ]) {
285
1061
  if (!command.includes(token)) fail(`${preflightCommandRel}: missing ${token}`);
286
1062
  }
@@ -290,7 +1066,7 @@ function checkOrchestratedReviewContract() {
290
1066
  const command = read(commandRel);
291
1067
  for (const token of [
292
1068
  "agent: review_coordinator",
293
- "node scripts/review-orchestrated-prepare.mjs $ARGUMENTS",
1069
+ "OPENCODE_CONFIG_DIR",
294
1070
  "manifest.json",
295
1071
  "shared-review-context.md",
296
1072
  "patches/",
@@ -311,6 +1087,8 @@ function checkOrchestratedReviewContract() {
311
1087
  "Always enumerate `review_quality`",
312
1088
  "skipped",
313
1089
  "lite",
1090
+ "review_stage: partial",
1091
+ "verdict: not_run",
314
1092
  ]) {
315
1093
  if (!command.includes(token)) fail(`${commandRel}: missing ${token}`);
316
1094
  }
@@ -351,11 +1129,9 @@ function checkOrchestratedReviewContract() {
351
1129
  fail("agents/review_coordinator.md: harmless preparer existence checks must not abort --agents");
352
1130
  }
353
1131
  for (const token of [
354
- "node scripts/review-orchestrated-prepare.mjs*",
355
- "node ./scripts/review-orchestrated-prepare.mjs*",
356
1132
  "node *scripts/review-orchestrated-prepare.mjs*",
357
- "Use a relative path",
358
- "Call the preparer exactly once",
1133
+ "OPENCODE_CONFIG_DIR",
1134
+ "Call it once",
359
1135
  "execution_plan.mode",
360
1136
  "preflight_only",
361
1137
  "--agents",
@@ -365,7 +1141,7 @@ function checkOrchestratedReviewContract() {
365
1141
  "at most one finding",
366
1142
  "Do not run `git diff`",
367
1143
  "timed_out",
368
- "always enumerate all four reviewers",
1144
+ "Always enumerate all four reviewers",
369
1145
  ]) {
370
1146
  if (!coordinator.includes(token)) fail(`agents/review_coordinator.md: missing preparer permission/routing token ${token}`);
371
1147
  }
@@ -1011,11 +1787,14 @@ function checkRouterScenarios() {
1011
1787
  "resume-checkpoint",
1012
1788
  "integration-unavailable",
1013
1789
  ]);
1014
- const allowedEvidence = new Set(["static_contract", "transcript_replay", "live_smoke", "manual_oracle"]);
1790
+ const allowedEvidence = orchestrationCatalog?.evidenceTypes
1791
+ ?? new Set(["static_contract", "transcript_replay", "live_smoke", "manual_oracle"]);
1015
1792
  const agentIdPattern = /^[a-z0-9]+(?:[-_][a-z0-9]+)*$/;
1016
1793
  const skillIdPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
1017
1794
  const slashCommandPattern = /^\/[a-z0-9]+(?:-[a-z0-9]+)*$/;
1018
- const validAgents = new Set();
1795
+ const validAgents = orchestrationCatalog?.agentIds
1796
+ ? new Set(orchestrationCatalog.agentIds)
1797
+ : new Set();
1019
1798
  const seenIds = new Set();
1020
1799
  const seenCategories = new Set();
1021
1800
 
@@ -1126,6 +1905,9 @@ function checkRouterScenarios() {
1126
1905
  fail(`${rel}: line ${line} invalid command_path ${value.command_path}`);
1127
1906
  } else {
1128
1907
  const commandName = value.command_path.slice(1);
1908
+ if (orchestrationCatalog && !orchestrationCatalog.commandIds.has(commandName)) {
1909
+ fail(`${rel}: line ${line} command_path ${value.command_path} outside selected orchestration profile`);
1910
+ }
1129
1911
  const commandRel = `commands/${commandName}.md`;
1130
1912
  const commandPath = path.join(root, commandRel);
1131
1913
  if (!exists(commandRel) || !fs.lstatSync(commandPath).isFile()) {
@@ -2007,14 +2789,15 @@ function checkRoutingDeclarativoContract() {
2007
2789
  fail("docs/ai/harness/commands.md: missing declarative routing token Declarative routing");
2008
2790
  }
2009
2791
 
2010
- for (const token of [
2011
- "`researcher`",
2012
- "`reviewer`",
2013
- "`designer`",
2014
- "`specifier`",
2015
- "`developer`",
2016
- "ask the user",
2017
- ]) {
2792
+ const routingTokens = (orchestrationCatalog?.routingTargets ?? [
2793
+ "researcher",
2794
+ "reviewer",
2795
+ "designer",
2796
+ "specifier",
2797
+ "developer",
2798
+ "ask-user",
2799
+ ]).map((target) => target === "ask-user" ? "ask the user" : `\`${target}\``);
2800
+ for (const token of routingTokens) {
2018
2801
  if (!freeSection.includes(token)) {
2019
2802
  fail(`docs/ai/harness/commands.md: missing declarative routing token ${token}`);
2020
2803
  }
@@ -2062,12 +2845,82 @@ function checkRetryPoliciesContract() {
2062
2845
  }
2063
2846
  }
2064
2847
 
2848
+ function checkShellExportGuardContract() {
2849
+ const policyRel = "scripts/shell-export-policy.mjs";
2850
+ const policyTestRel = "scripts/shell-export-policy.test.mjs";
2851
+ const pluginRel = "plugins/shell-export-guard.ts";
2852
+
2853
+ for (const rel of [policyRel, policyTestRel, pluginRel]) {
2854
+ if (!exists(rel)) fail(`${rel}: missing shell export guard surface`);
2855
+ }
2856
+
2857
+ if (!exists(policyRel) || !exists(policyTestRel) || !exists(pluginRel)) return;
2858
+
2859
+ const policy = read(policyRel);
2860
+ for (const token of [
2861
+ "classifyShellExport",
2862
+ "shell-export-environment-enumeration",
2863
+ "shell-export-sensitive-name",
2864
+ "shell-export-secret-source",
2865
+ "-p",
2866
+ ]) {
2867
+ if (!policy.includes(token)) {
2868
+ fail(`${policyRel}: missing shell export guard token ${token}`);
2869
+ }
2870
+ }
2871
+
2872
+ const plugin = read(pluginRel);
2873
+ for (const token of [
2874
+ "tool.execute.before",
2875
+ "classifyShellExport",
2876
+ "shell-export-guard",
2877
+ "bash",
2878
+ "shell",
2879
+ ]) {
2880
+ if (!plugin.includes(token)) {
2881
+ fail(`${pluginRel}: missing shell export guard token ${token}`);
2882
+ }
2883
+ }
2884
+ if (/\$\{?command\}?/.test(plugin)) {
2885
+ fail(`${pluginRel}: shell export guard must not include the raw command in diagnostics`);
2886
+ }
2887
+
2888
+ const policyTests = read(policyTestRel);
2889
+ for (const token of [
2890
+ "export",
2891
+ "API_KEY",
2892
+ "PATH",
2893
+ "NODE_ENV",
2894
+ "pi --export",
2895
+ "quoted prose",
2896
+ ]) {
2897
+ if (!policyTests.includes(token)) {
2898
+ fail(`${policyTestRel}: missing shell export policy scenario ${token}`);
2899
+ }
2900
+ }
2901
+
2902
+ const checksDocs = read("docs/ai/harness/checks.md");
2903
+ const readmeDocs = read("docs/ai/harness/README.md");
2904
+ for (const [rel, text] of [
2905
+ ["docs/ai/harness/checks.md", checksDocs],
2906
+ ["docs/ai/harness/README.md", readmeDocs],
2907
+ ]) {
2908
+ for (const token of ["shell-export", "defense in depth", "sandbox"]) {
2909
+ if (!text.includes(token)) {
2910
+ fail(`${rel}: missing shell export policy documentation token ${token}`);
2911
+ }
2912
+ }
2913
+ }
2914
+ }
2915
+
2065
2916
  checkConfig();
2066
2917
  checkAgentsIndex();
2067
2918
  checkFrontmatter();
2919
+ checkOrchestrationContracts();
2068
2920
  checkAgentDocsCoverage();
2069
2921
  checkCommandDocsCoverage();
2070
2922
  checkLoopContract();
2923
+ checkAutonomousContract();
2071
2924
  checkLeadRouterContract();
2072
2925
  checkFeatureContract();
2073
2926
  checkPlanContract();
@@ -2087,6 +2940,7 @@ checkCommandContracts();
2087
2940
  checkSkillRegistryPresence();
2088
2941
  checkLeadSkillResolution();
2089
2942
  checkAgentSkillLoading();
2943
+ checkCanonicalReviewPolicy();
2090
2944
  checkSkillRegistryGenerator();
2091
2945
  checkInitCommand();
2092
2946
  checkAutoForecastContract();
@@ -2098,6 +2952,7 @@ checkOrchestratedReviewContract();
2098
2952
  checkHitlDurableContract();
2099
2953
  checkRoutingDeclarativoContract();
2100
2954
  checkRetryPoliciesContract();
2955
+ checkShellExportGuardContract();
2101
2956
 
2102
2957
  if (errors.length > 0) {
2103
2958
  console.error("Harness check failed:");