opencode-agent-orchestration-kit 1.0.31 → 1.0.33

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 (78) hide show
  1. package/README.md +41 -3
  2. package/SECURITY.md +7 -0
  3. package/docker/open-design/data/app.sqlite +0 -0
  4. package/docker/open-design/data/app.sqlite-shm +0 -0
  5. package/docker/open-design/data/app.sqlite-wal +0 -0
  6. package/docker/open-design/opencode-auth/log/2026-05-02T105802.log +17 -0
  7. package/docker/open-design/opencode-auth/log/2026-05-04T102127.log +16 -0
  8. package/docker/open-design/opencode-auth/opencode.db +0 -0
  9. package/docker/open-design/opencode-auth/opencode.db-shm +0 -0
  10. package/docker/open-design/opencode-auth/opencode.db-wal +0 -0
  11. package/docs/cli.md +72 -0
  12. package/docs/installation.md +25 -5
  13. package/docs/quickstart.md +1 -1
  14. package/docs/releases/v1.0.32.md +68 -0
  15. package/docs/releases/v1.0.33.md +72 -0
  16. package/docs/security.md +4 -0
  17. package/docs/supply-chain.md +9 -5
  18. package/docs/threat-model.md +244 -0
  19. package/docs/use-cases/README.md +31 -0
  20. package/docs/use-cases/direct-label-change/README.md +76 -0
  21. package/docs/use-cases/direct-label-change/before/package.json +8 -0
  22. package/docs/use-cases/direct-label-change/before/src/settings-label.mjs +1 -0
  23. package/docs/use-cases/direct-label-change/before/test/settings-label.test.mjs +8 -0
  24. package/docs/use-cases/direct-label-change/case.json +118 -0
  25. package/docs/use-cases/direct-label-change/expected/package.json +8 -0
  26. package/docs/use-cases/direct-label-change/expected/src/settings-label.mjs +1 -0
  27. package/docs/use-cases/direct-label-change/expected/test/settings-label.test.mjs +8 -0
  28. package/docs/use-cases/feature-tag-normalizer/README.md +78 -0
  29. package/docs/use-cases/feature-tag-normalizer/before/package.json +8 -0
  30. package/docs/use-cases/feature-tag-normalizer/before/src/normalize-tags.mjs +3 -0
  31. package/docs/use-cases/feature-tag-normalizer/before/test/normalize-tags.test.mjs +13 -0
  32. package/docs/use-cases/feature-tag-normalizer/case.json +119 -0
  33. package/docs/use-cases/feature-tag-normalizer/expected/package.json +8 -0
  34. package/docs/use-cases/feature-tag-normalizer/expected/src/normalize-tags.mjs +14 -0
  35. package/docs/use-cases/feature-tag-normalizer/expected/test/normalize-tags.test.mjs +18 -0
  36. package/docs/workflows.md +6 -0
  37. package/opencode/AGENTS.md +6 -0
  38. package/opencode/agents/review_api.md +3 -1
  39. package/opencode/agents/review_coordinator.md +3 -1
  40. package/opencode/agents/review_quality.md +3 -1
  41. package/opencode/agents/review_security.md +3 -1
  42. package/opencode/agents/review_tests.md +3 -1
  43. package/opencode/agents/reviewer.md +2 -2
  44. package/opencode/commands/loop.md +53 -14
  45. package/opencode/docs/ai/evolution/README.md +28 -0
  46. package/opencode/docs/ai/evolution/benchmarks/adversarial-scenarios.jsonl +11 -0
  47. package/opencode/docs/ai/harness/README.md +2 -0
  48. package/opencode/docs/ai/harness/agents.md +30 -4
  49. package/opencode/docs/ai/harness/checks.md +27 -0
  50. package/opencode/docs/ai/harness/commands.md +21 -4
  51. package/opencode/docs/ai/harness/orchestrated-review.md +4 -0
  52. package/opencode/docs/ai/harness/orchestration-contracts.json +891 -0
  53. package/opencode/package-lock.json +14 -8
  54. package/opencode/package.json +1 -0
  55. package/opencode/scripts/adversarial-harness.test.mjs +296 -0
  56. package/opencode/scripts/check-harness.mjs +826 -11
  57. package/opencode/scripts/check-harness.test.mjs +572 -1
  58. package/opencode/scripts/loop-state.mjs +1149 -0
  59. package/opencode/scripts/loop-state.test.mjs +577 -0
  60. package/opencode/scripts/review-orchestrated-prepare.mjs +33 -9
  61. package/package.json +4 -1
  62. package/scripts/check-supply-chain.mjs +11 -1
  63. package/scripts/check-supply-chain.test.mjs +47 -0
  64. package/scripts/check-threat-model.mjs +421 -0
  65. package/scripts/check-threat-model.test.mjs +304 -0
  66. package/scripts/check-use-cases.mjs +501 -0
  67. package/scripts/check-use-cases.test.mjs +225 -0
  68. package/scripts/check.sh +51 -1
  69. package/scripts/install-smoke.sh +24 -1
  70. package/scripts/manage-installation.mjs +567 -25
  71. package/scripts/manage-installation.test.mjs +418 -0
  72. package/scripts/oak.mjs +200 -0
  73. package/scripts/oak.test.mjs +277 -0
  74. package/scripts/package-smoke.mjs +57 -0
  75. package/scripts/package-smoke.test.mjs +75 -2
  76. package/scripts/version.mjs +1 -0
  77. package/scripts/version.test.mjs +3 -2
  78. package/supply-chain.json +1 -0
@@ -64,6 +64,386 @@ function writeRouterScenarios(cwd, scenarios) {
64
64
  );
65
65
  }
66
66
 
67
+ const orchestrationContractRel =
68
+ "docs/ai/harness/orchestration-contracts.json";
69
+
70
+ function readOrchestrationContract(cwd) {
71
+ return JSON.parse(
72
+ fs.readFileSync(path.join(cwd, orchestrationContractRel), "utf8"),
73
+ );
74
+ }
75
+
76
+ function writeOrchestrationContract(cwd, contract) {
77
+ write(
78
+ orchestrationContractRel,
79
+ `${JSON.stringify(contract, null, 2)}\n`,
80
+ cwd,
81
+ );
82
+ }
83
+
84
+ test("orchestration contract file is required", () => {
85
+ const cwd = makeFixture();
86
+ try {
87
+ fs.rmSync(path.join(cwd, orchestrationContractRel), { force: true });
88
+
89
+ const result = runHarness(cwd);
90
+ assert.notEqual(result.status, 0, "checker accepted a missing orchestration contract");
91
+ assert.match(result.stderr, /missing orchestration contract/);
92
+ } finally {
93
+ fs.rmSync(cwd, { recursive: true, force: true });
94
+ }
95
+ });
96
+
97
+ test("orchestration contract file must be regular and non-symlink", () => {
98
+ const cwd = makeFixture();
99
+ const external = path.join(cwd, "external-contract.json");
100
+ try {
101
+ fs.writeFileSync(external, "{}\n");
102
+ fs.rmSync(path.join(cwd, orchestrationContractRel));
103
+ fs.symlinkSync(external, path.join(cwd, orchestrationContractRel));
104
+
105
+ const result = runHarness(cwd);
106
+ assert.notEqual(result.status, 0, "checker followed a symlinked orchestration contract");
107
+ assert.match(result.stderr, /regular non-symlink/);
108
+ } finally {
109
+ fs.rmSync(cwd, { recursive: true, force: true });
110
+ }
111
+ });
112
+
113
+ test("orchestration contract rejects an unknown top-level key", () => {
114
+ const cwd = makeFixture();
115
+ try {
116
+ const contract = readOrchestrationContract(cwd);
117
+ writeOrchestrationContract(cwd, { ...contract, scheduler: {} });
118
+
119
+ const result = runHarness(cwd);
120
+ assert.notEqual(result.status, 0, "checker accepted an unknown orchestration key");
121
+ assert.match(result.stderr, /must contain exactly/);
122
+ } finally {
123
+ fs.rmSync(cwd, { recursive: true, force: true });
124
+ }
125
+ });
126
+
127
+ test("orchestration contract header is closed", async (t) => {
128
+ for (const [label, mutate, pattern] of [
129
+ [
130
+ "schema version",
131
+ (contract) => ({ ...contract, schema_version: 2 }),
132
+ /schema_version must be 1/,
133
+ ],
134
+ [
135
+ "contract identity",
136
+ (contract) => ({ ...contract, contract_id: "other-contract" }),
137
+ /contract_id must be oak-orchestration/,
138
+ ],
139
+ ]) {
140
+ await t.test(label, () => {
141
+ const cwd = makeFixture();
142
+ try {
143
+ writeOrchestrationContract(cwd, mutate(readOrchestrationContract(cwd)));
144
+ const result = runHarness(cwd);
145
+ assert.notEqual(result.status, 0, `checker accepted invalid ${label}`);
146
+ assert.match(result.stderr, pattern);
147
+ } finally {
148
+ fs.rmSync(cwd, { recursive: true, force: true });
149
+ }
150
+ });
151
+ }
152
+ });
153
+
154
+ test("orchestration contract requires the canonical evidence catalog", () => {
155
+ const cwd = makeFixture();
156
+ try {
157
+ const contract = readOrchestrationContract(cwd);
158
+ writeOrchestrationContract(cwd, {
159
+ ...contract,
160
+ evidence_types: ["static_contract"],
161
+ });
162
+
163
+ const result = runHarness(cwd);
164
+ assert.notEqual(result.status, 0, "checker accepted an incomplete evidence catalog");
165
+ assert.match(result.stderr, /evidence_types must match the canonical catalog/);
166
+ } finally {
167
+ fs.rmSync(cwd, { recursive: true, force: true });
168
+ }
169
+ });
170
+
171
+ test("orchestration contract requires every harness agent", () => {
172
+ const cwd = makeFixture();
173
+ try {
174
+ const contract = readOrchestrationContract(cwd);
175
+ writeOrchestrationContract(cwd, { ...contract, agents: [] });
176
+
177
+ const result = runHarness(cwd);
178
+ assert.notEqual(result.status, 0, "checker accepted an empty agent catalog");
179
+ assert.match(result.stderr, /agent catalog must match harness agents/);
180
+ } finally {
181
+ fs.rmSync(cwd, { recursive: true, force: true });
182
+ }
183
+ });
184
+
185
+ test("orchestration agent contracts match frontmatter authority", async (t) => {
186
+ for (const [label, mutate, pattern] of [
187
+ [
188
+ "mode",
189
+ (agent) => ({ ...agent, mode: "subagent" }),
190
+ /agent lead mode must match frontmatter/,
191
+ ],
192
+ [
193
+ "write permission",
194
+ (agent) => ({
195
+ ...agent,
196
+ permission_invariants: {
197
+ ...agent.permission_invariants,
198
+ repository_write: "allow",
199
+ },
200
+ }),
201
+ /agent lead repository_write must match frontmatter/,
202
+ ],
203
+ [
204
+ "delegation allowlist",
205
+ (agent) => ({
206
+ ...agent,
207
+ delegates_to: agent.delegates_to.filter((id) => id !== "developer"),
208
+ }),
209
+ /agent lead delegates_to must match selected profile/,
210
+ ],
211
+ [
212
+ "closed shape",
213
+ (agent) => ({ ...agent, prompt: "forbidden" }),
214
+ /agent lead must contain exactly/,
215
+ ],
216
+ ]) {
217
+ await t.test(label, () => {
218
+ const cwd = makeFixture();
219
+ try {
220
+ const contract = readOrchestrationContract(cwd);
221
+ contract.agents = contract.agents.map((agent) =>
222
+ agent.id === "lead" ? mutate(agent) : agent
223
+ );
224
+ writeOrchestrationContract(cwd, contract);
225
+
226
+ const result = runHarness(cwd);
227
+ assert.notEqual(result.status, 0, `checker accepted invalid agent ${label}`);
228
+ assert.match(result.stderr, pattern);
229
+ } finally {
230
+ fs.rmSync(cwd, { recursive: true, force: true });
231
+ }
232
+ });
233
+ }
234
+ });
235
+
236
+ test("orchestration contract requires one exact inventory profile", () => {
237
+ const cwd = makeFixture();
238
+ try {
239
+ const contract = readOrchestrationContract(cwd);
240
+ writeOrchestrationContract(cwd, { ...contract, profiles: {} });
241
+
242
+ const result = runHarness(cwd);
243
+ assert.notEqual(result.status, 0, "checker accepted no inventory profile");
244
+ assert.match(result.stderr, /must select exactly one inventory profile/);
245
+ } finally {
246
+ fs.rmSync(cwd, { recursive: true, force: true });
247
+ }
248
+ });
249
+
250
+ test("orchestration profile preserves surface-specific delegations", () => {
251
+ const cwd = makeFixture();
252
+ try {
253
+ const contract = readOrchestrationContract(cwd);
254
+ contract.profiles.public.delegation_extensions = {
255
+ scoper: ["debugger"],
256
+ };
257
+ writeOrchestrationContract(cwd, contract);
258
+
259
+ const result = runHarness(cwd);
260
+ assert.notEqual(result.status, 0, "checker accepted a foreign delegation extension");
261
+ assert.match(result.stderr, /agent scoper delegates_to must match selected profile/);
262
+ } finally {
263
+ fs.rmSync(cwd, { recursive: true, force: true });
264
+ }
265
+ });
266
+
267
+ test("orchestration command contracts match command frontmatter", async (t) => {
268
+ for (const [label, mutate, pattern] of [
269
+ [
270
+ "root agent",
271
+ (command) => ({ ...command, root_agent: "developer" }),
272
+ /command feature root_agent must match frontmatter/,
273
+ ],
274
+ [
275
+ "subtask",
276
+ (command) => ({ ...command, subtask: true }),
277
+ /command feature subtask must match frontmatter/,
278
+ ],
279
+ [
280
+ "closed shape",
281
+ (command) => ({ ...command, prompt: "forbidden" }),
282
+ /command feature must contain exactly/,
283
+ ],
284
+ ]) {
285
+ await t.test(label, () => {
286
+ const cwd = makeFixture();
287
+ try {
288
+ const contract = readOrchestrationContract(cwd);
289
+ contract.commands = contract.commands.map((command) =>
290
+ command.id === "feature" ? mutate(command) : command
291
+ );
292
+ writeOrchestrationContract(cwd, contract);
293
+
294
+ const result = runHarness(cwd);
295
+ assert.notEqual(result.status, 0, `checker accepted invalid command ${label}`);
296
+ assert.match(result.stderr, pattern);
297
+ } finally {
298
+ fs.rmSync(cwd, { recursive: true, force: true });
299
+ }
300
+ });
301
+ }
302
+ });
303
+
304
+ test("orchestration workflow references declared agents", () => {
305
+ const cwd = makeFixture();
306
+ try {
307
+ const contract = readOrchestrationContract(cwd);
308
+ contract.workflows = [{
309
+ id: "invalid-flow",
310
+ entrypoints: ["freeform"],
311
+ stages: [{ agent: "ghost", requirement: "required" }],
312
+ barriers: [],
313
+ retry_policy: null,
314
+ completion_authority: { kind: "result-contract", agent: null },
315
+ required_evidence: ["static_contract"],
316
+ adaptive: true,
317
+ }];
318
+ writeOrchestrationContract(cwd, contract);
319
+
320
+ const result = runHarness(cwd);
321
+ assert.notEqual(result.status, 0, "checker accepted an unknown stage agent");
322
+ assert.match(result.stderr, /workflow invalid-flow stage agent must reference an agent/);
323
+ } finally {
324
+ fs.rmSync(cwd, { recursive: true, force: true });
325
+ }
326
+ });
327
+
328
+ test("orchestration retry limits are bounded", () => {
329
+ const cwd = makeFixture();
330
+ try {
331
+ const contract = readOrchestrationContract(cwd);
332
+ contract.retry_policies = [{
333
+ id: "developer-default",
334
+ scope: "developer",
335
+ max_attempts: 4,
336
+ requires_new_evidence: true,
337
+ on_exhaustion: "escalate-review",
338
+ }];
339
+ writeOrchestrationContract(cwd, contract);
340
+
341
+ const result = runHarness(cwd);
342
+ assert.notEqual(result.status, 0, "checker accepted an unbounded retry policy");
343
+ assert.match(result.stderr, /retry developer-default max_attempts must be between 1 and 3/);
344
+ } finally {
345
+ fs.rmSync(cwd, { recursive: true, force: true });
346
+ }
347
+ });
348
+
349
+ test("orchestration routing requires known targets", () => {
350
+ const cwd = makeFixture();
351
+ try {
352
+ const contract = readOrchestrationContract(cwd);
353
+ contract.routing_rules = [{
354
+ id: "invalid-route",
355
+ target: "ghost",
356
+ precedence: 1,
357
+ }];
358
+ writeOrchestrationContract(cwd, contract);
359
+
360
+ const result = runHarness(cwd);
361
+ assert.notEqual(result.status, 0, "checker accepted an unknown routing target");
362
+ assert.match(result.stderr, /routing rule invalid-route target must reference an agent or ask-user/);
363
+ } finally {
364
+ fs.rmSync(cwd, { recursive: true, force: true });
365
+ }
366
+ });
367
+
368
+ test("orchestration catalog preserves approved behavior", async (t) => {
369
+ for (const [label, mutate, pattern] of [
370
+ [
371
+ "command workflow",
372
+ (contract) => ({
373
+ ...contract,
374
+ commands: contract.commands.map((command) =>
375
+ command.id === "feature" ? { ...command, workflow: "plan" } : command
376
+ ),
377
+ }),
378
+ /command feature workflow must match its entrypoint/,
379
+ ],
380
+ [
381
+ "required workflow stage",
382
+ (contract) => ({
383
+ ...contract,
384
+ workflows: contract.workflows.map((workflow) =>
385
+ workflow.id === "plan"
386
+ ? { ...workflow, stages: workflow.stages.filter((stage) => stage.agent !== "specifier") }
387
+ : workflow
388
+ ),
389
+ }),
390
+ /workflow plan stages must match the approved sequence/,
391
+ ],
392
+ [
393
+ "retry invariant",
394
+ (contract) => ({
395
+ ...contract,
396
+ retry_policies: contract.retry_policies.map((policy) =>
397
+ policy.id === "developer-default" ? { ...policy, max_attempts: 3 } : policy
398
+ ),
399
+ }),
400
+ /retry developer-default must match the approved policy/,
401
+ ],
402
+ [
403
+ "routing invariant",
404
+ (contract) => ({
405
+ ...contract,
406
+ routing_rules: contract.routing_rules.map((rule) =>
407
+ rule.id === "reviewable-change" ? { ...rule, target: "developer" } : rule
408
+ ),
409
+ }),
410
+ /routing rule reviewable-change must match the approved rule/,
411
+ ],
412
+ [
413
+ "routing catalog",
414
+ (contract) => ({
415
+ ...contract,
416
+ routing_rules: contract.routing_rules.filter((rule) => rule.id !== "visual-impact"),
417
+ }),
418
+ /routing rule catalog must match the approved catalog/,
419
+ ],
420
+ [
421
+ "completion authority",
422
+ (contract) => ({
423
+ ...contract,
424
+ workflows: contract.workflows.map((workflow) =>
425
+ workflow.id === "loop"
426
+ ? { ...workflow, completion_authority: { kind: "agent", agent: "lead" } }
427
+ : workflow
428
+ ),
429
+ }),
430
+ /workflow loop completion authority must match the approved authority/,
431
+ ],
432
+ ]) {
433
+ await t.test(label, () => {
434
+ const cwd = makeFixture();
435
+ try {
436
+ writeOrchestrationContract(cwd, mutate(readOrchestrationContract(cwd)));
437
+ const result = runHarness(cwd);
438
+ assert.notEqual(result.status, 0, `checker accepted changed ${label}`);
439
+ assert.match(result.stderr, pattern);
440
+ } finally {
441
+ fs.rmSync(cwd, { recursive: true, force: true });
442
+ }
443
+ });
444
+ }
445
+ });
446
+
67
447
  const validLoopCommand = `---
68
448
  description: Run a bounded and verifiable engineering loop.
69
449
  agent: lead
@@ -72,10 +452,23 @@ agent: lead
72
452
  approval_gate: explicit_before_writes
73
453
  max_iterations_per_invocation: 3
74
454
  completion_authority: reviewer_only
75
- state_path: .opencode/loops/<slug>.md
455
+ canonical_state_path: .opencode/loops/<slug>.json
456
+ history_path: .opencode/loops/<slug>.history.jsonl
457
+ lock_path: .opencode/loops/<slug>.lock
458
+ human_view_path: .opencode/loops/<slug>.md
76
459
  worktree_mode: explicit_opt_in
77
460
 
78
461
  developer -> reviewer -> developer (state sync)
462
+
463
+ ## Phase 1
464
+
465
+ node scripts/loop-state.mjs inspect
466
+
467
+ ## Phase 2
468
+
469
+ node scripts/loop-state.mjs resume
470
+
471
+ ## Phase 3
79
472
  `;
80
473
 
81
474
  function writeLoopFixture(cwd, command) {
@@ -84,6 +477,123 @@ function writeLoopFixture(cwd, command) {
84
477
  fs.appendFileSync(docsPath, "\n## `/loop`\n");
85
478
  }
86
479
 
480
+ test("adversarial corpus rejects a missing threat", () => {
481
+ const cwd = makeFixture();
482
+ try {
483
+ const rel = "docs/ai/evolution/benchmarks/adversarial-scenarios.jsonl";
484
+ const records = fs.readFileSync(path.join(cwd, rel), "utf8")
485
+ .trim()
486
+ .split("\n")
487
+ .map(JSON.parse)
488
+ .filter((record) => record.threat !== "network-exfiltration");
489
+ write(rel, `${records.map(JSON.stringify).join("\n")}\n`, cwd);
490
+
491
+ const result = runHarness(cwd);
492
+ assert.notEqual(result.status, 0, "checker accepted a missing adversarial threat");
493
+ assert.match(result.stderr, /missing threat network-exfiltration/);
494
+ } finally {
495
+ fs.rmSync(cwd, { recursive: true, force: true });
496
+ }
497
+ });
498
+
499
+ test("adversarial corpus rejects non-portable fixture values", () => {
500
+ const cwd = makeFixture();
501
+ try {
502
+ const rel = "docs/ai/evolution/benchmarks/adversarial-scenarios.jsonl";
503
+ write(
504
+ rel,
505
+ fs.readFileSync(path.join(cwd, rel), "utf8")
506
+ .replace("PATCH_CANARY_IGNORE_POLICY", "../private"),
507
+ cwd,
508
+ );
509
+
510
+ const result = runHarness(cwd);
511
+ assert.notEqual(result.status, 0, "checker accepted a local path in the portable corpus");
512
+ assert.match(result.stderr, /input_fixture must be a portable symbolic identifier/);
513
+ } finally {
514
+ fs.rmSync(cwd, { recursive: true, force: true });
515
+ }
516
+ });
517
+
518
+ test("adversarial surface rejects an allowlisted rtk wrapper", () => {
519
+ const cwd = makeFixture();
520
+ try {
521
+ const rel = "agents/review_security.md";
522
+ write(
523
+ rel,
524
+ fs.readFileSync(path.join(cwd, rel), "utf8")
525
+ .replace('"rtk *": ask', '"rtk *": allow'),
526
+ cwd,
527
+ );
528
+
529
+ const result = runHarness(cwd);
530
+ assert.notEqual(result.status, 0, "checker accepted an allowlisted shell wrapper");
531
+ assert.match(result.stderr, /wrapper command rtk \* must require approval/);
532
+ } finally {
533
+ fs.rmSync(cwd, { recursive: true, force: true });
534
+ }
535
+ });
536
+
537
+ test("adversarial surface rejects review network allow", () => {
538
+ const cwd = makeFixture();
539
+ try {
540
+ const rel = "agents/review_security.md";
541
+ write(
542
+ rel,
543
+ fs.readFileSync(path.join(cwd, rel), "utf8")
544
+ .replace("webfetch: deny", "webfetch: allow"),
545
+ cwd,
546
+ );
547
+
548
+ const result = runHarness(cwd);
549
+ assert.notEqual(result.status, 0, "checker accepted network access for orchestrated review");
550
+ assert.match(result.stderr, /review network permission must include webfetch: deny/);
551
+ } finally {
552
+ fs.rmSync(cwd, { recursive: true, force: true });
553
+ }
554
+ });
555
+
556
+ test("agent frontmatter rejects shell permissions nested under websearch", () => {
557
+ const cwd = makeFixture();
558
+ try {
559
+ const rel = "agents/review_tests.md";
560
+ write(
561
+ rel,
562
+ fs.readFileSync(path.join(cwd, rel), "utf8")
563
+ .replace(
564
+ " websearch: deny",
565
+ ' websearch: deny\n "shell canary*": allow',
566
+ ),
567
+ cwd,
568
+ );
569
+
570
+ const result = runHarness(cwd);
571
+ assert.notEqual(result.status, 0, "checker accepted a shell permission nested under websearch");
572
+ assert.match(result.stderr, /quoted command permission cannot be nested under websearch/);
573
+ } finally {
574
+ fs.rmSync(cwd, { recursive: true, force: true });
575
+ }
576
+ });
577
+
578
+ test("adversarial surface rejects a missing repository trust boundary", () => {
579
+ const cwd = makeFixture();
580
+ try {
581
+ const rel = "AGENTS.md";
582
+ write(
583
+ rel,
584
+ fs.readFileSync(path.join(cwd, rel), "utf8")
585
+ .replace("local documentation, and their metadata as", "local documentation, and their metadata as ordinary"),
586
+ cwd,
587
+ );
588
+
589
+ const result = runHarness(cwd);
590
+ assert.notEqual(result.status, 0, "checker accepted a missing repository trust boundary");
591
+ assert.match(result.stderr, /missing adversarial trust boundary/);
592
+ } finally {
593
+ fs.rmSync(cwd, { recursive: true, force: true });
594
+ }
595
+ });
596
+
87
597
  test("harness accepts prose evidence that mentions markdown filenames", () => {
88
598
  const cwd = makeFixture();
89
599
  try {
@@ -234,6 +744,67 @@ test("harness rejects loop when developer can approve itself", () => {
234
744
  }
235
745
  });
236
746
 
747
+ test("harness rejects loop without canonical structured state", () => {
748
+ const cwd = makeFixture();
749
+ try {
750
+ writeLoopFixture(
751
+ cwd,
752
+ validLoopCommand.replace(
753
+ "canonical_state_path: .opencode/loops/<slug>.json",
754
+ "canonical_state_path: .opencode/loops/<slug>.md",
755
+ ),
756
+ );
757
+
758
+ const result = runHarness(cwd);
759
+ assert.notEqual(result.status, 0, "checker accepted markdown as canonical loop state");
760
+ assert.match(
761
+ result.stderr,
762
+ /commands\/loop\.md: missing canonical_state_path: \.opencode\/loops\/<slug>\.json/,
763
+ );
764
+ } finally {
765
+ fs.rmSync(cwd, { recursive: true, force: true });
766
+ }
767
+ });
768
+
769
+ test("harness rejects a missing durable loop runtime", () => {
770
+ const cwd = makeFixture();
771
+ try {
772
+ fs.rmSync(path.join(cwd, "scripts/loop-state.mjs"));
773
+
774
+ const result = runHarness(cwd);
775
+ assert.notEqual(result.status, 0, "checker accepted a missing loop state runtime");
776
+ assert.match(result.stderr, /scripts\/loop-state\.mjs: missing regular file/);
777
+ } finally {
778
+ fs.rmSync(cwd, { recursive: true, force: true });
779
+ }
780
+ });
781
+
782
+ test("harness rejects loop resume writes before approval", () => {
783
+ const cwd = makeFixture();
784
+ try {
785
+ writeLoopFixture(
786
+ cwd,
787
+ validLoopCommand.replace(
788
+ "node scripts/loop-state.mjs inspect",
789
+ "node scripts/loop-state.mjs resume",
790
+ ),
791
+ );
792
+
793
+ const result = runHarness(cwd);
794
+ assert.notEqual(result.status, 0, "checker accepted resume before approval");
795
+ assert.match(
796
+ result.stderr,
797
+ /commands\/loop\.md: resume preflight must use read-only loop-state inspect/,
798
+ );
799
+ assert.match(
800
+ result.stderr,
801
+ /commands\/loop\.md: loop-state resume cannot run before approval/,
802
+ );
803
+ } finally {
804
+ fs.rmSync(cwd, { recursive: true, force: true });
805
+ }
806
+ });
807
+
237
808
  test("harness rejects evolve flow when evaluator/debugger/evolver order is inverted", () => {
238
809
  const cwd = makeFixture();
239
810
  try {