@christang/keel 5.82.0 → 5.84.0

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.
@@ -38,8 +38,8 @@ REQUIRED_SCRIPTS = [
38
38
  "scripts/validate_plugin.py",
39
39
  ]
40
40
 
41
- PACKAGE_VERSION = "5.82.0"
42
- PROTOCOL_VERSION = "5.82.0"
41
+ PACKAGE_VERSION = "5.84.0"
42
+ PROTOCOL_VERSION = "5.84.0"
43
43
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
44
44
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
45
45
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -2170,6 +2170,472 @@ def validate_decisions_are_selectable_scenario() -> int:
2170
2170
  return 0
2171
2171
 
2172
2172
 
2173
+ def mailbox_repository(root: Path) -> Path:
2174
+ """A committed scratch repository whose mailbox tests can add worktrees."""
2175
+ root.mkdir(parents=True, exist_ok=True)
2176
+ for args in (
2177
+ ["init", "-q", "-b", "main"],
2178
+ ["config", "user.email", "keel@example.invalid"],
2179
+ ["config", "user.name", "Keel Validation"],
2180
+ ["commit", "-q", "--allow-empty", "-m", "seed"],
2181
+ ):
2182
+ subprocess.run(["git", *args], cwd=root, check=True, capture_output=True)
2183
+ return root
2184
+
2185
+
2186
+ def mailbox_common_dir(repo: Path) -> Path:
2187
+ raw = subprocess.run(
2188
+ ["git", "rev-parse", "--path-format=absolute", "--git-common-dir"],
2189
+ cwd=repo, check=True, capture_output=True, text=True,
2190
+ ).stdout.strip()
2191
+ return Path(raw)
2192
+
2193
+
2194
+ def validate_mailbox_cli_scenario() -> int:
2195
+ """Issue #180: worktrees of one repository exchange Markdown mail by role.
2196
+
2197
+ Everything goes through public `keel mail`: binding roles, sending from
2198
+ one worktree, listing and reading in another, isolation from a second
2199
+ repository, the reply link, and that unread mail changes no context.
2200
+ """
2201
+ label = "mailbox-cli: keel mail"
2202
+ with tempfile.TemporaryDirectory(prefix="keel-mailbox-") as raw:
2203
+ base = Path(raw)
2204
+ rtl = mailbox_repository(base / "rtl")
2205
+ verify = base / "verify"
2206
+ subprocess.run(
2207
+ ["git", "worktree", "add", "-q", "-b", "verify", str(verify)],
2208
+ cwd=rtl, check=True, capture_output=True,
2209
+ )
2210
+ other = mailbox_repository(base / "other")
2211
+ env = {key: value for key, value in os.environ.items() if key != "KEEL_MAIL_ROLE"}
2212
+
2213
+ def mail(cwd: Path, *args: str) -> subprocess.CompletedProcess[str]:
2214
+ return run_keel(cwd, "mail", *args, env=env)
2215
+
2216
+ unbound = mail(rtl, "send", "--to", "verify", "--subject", "s", "--body", "b")
2217
+ if unbound.returncode == 0:
2218
+ report(f"{label} send from an unbound worktree succeeded.")
2219
+ return 1
2220
+ if "keel mail role --set" not in unbound.stderr:
2221
+ report(f"{label} the unbound-sender refusal does not name `keel mail role --set`.")
2222
+ report((unbound.stderr or unbound.stdout).strip())
2223
+ return 1
2224
+ bad = mail(rtl, "role", "--set", "Bad Name")
2225
+ if bad.returncode == 0:
2226
+ report(f"{label} role --set accepted the invalid name 'Bad Name'.")
2227
+ return 1
2228
+ if "[a-z0-9]" not in bad.stderr:
2229
+ report(f"{label} the invalid-role refusal does not name the pattern: {bad.stderr.strip()}")
2230
+ return 1
2231
+ if (mailbox_common_dir(rtl) / "keel-mailbox").exists():
2232
+ report(f"{label} a refused role wrote to the mailbox.")
2233
+ return 1
2234
+
2235
+ for cwd, role in ((rtl, "rtl"), (verify, "verify"), (other, "verify")):
2236
+ bound = mail(cwd, "role", "--set", role)
2237
+ if bound.returncode != 0:
2238
+ report(f"{label} role --set {role} failed: {bound.stderr.strip()}")
2239
+ return 1
2240
+ shown = mail(verify, "role", "--json")
2241
+ if shown.returncode != 0:
2242
+ report(f"{label} role --json failed: {shown.stderr.strip()}")
2243
+ return 1
2244
+ if json.loads(shown.stdout).get("role") != "verify":
2245
+ report(f"{label} role did not report the bound role: {shown.stdout.strip()}")
2246
+ return 1
2247
+
2248
+ context_before = run_keel(verify, "context", "--json", env=env)
2249
+
2250
+ sent = mail(
2251
+ rtl, "send", "--to", "verify", "--subject", "Stimulus misreads spec",
2252
+ "--body", "Fix the testcase and rerun.", "--ref", "abc1234", "--json",
2253
+ )
2254
+ if sent.returncode != 0:
2255
+ report(f"{label} send failed: {sent.stderr.strip()}")
2256
+ return 1
2257
+ message_id = json.loads(sent.stdout).get("id", "")
2258
+
2259
+ listed = mail(verify, "list", "--json")
2260
+ unread = json.loads(listed.stdout).get("unread", []) if listed.returncode == 0 else []
2261
+ if [(m.get("from"), m.get("subject")) for m in unread] != [("rtl", "Stimulus misreads spec")]:
2262
+ report(f"{label} list in the verify worktree did not show the message: {listed.stdout.strip()}")
2263
+ return 1
2264
+ box = mailbox_common_dir(rtl) / "keel-mailbox" / "verify"
2265
+ files = list((box / "new").glob("*.md"))
2266
+ if len(files) != 1:
2267
+ report(f"{label} expected one message file under {box / 'new'}, found {len(files)}.")
2268
+ return 1
2269
+ if not (box / ".signal").is_file():
2270
+ report(f"{label} the signal file {box / '.signal'} is missing.")
2271
+ return 1
2272
+ text = files[0].read_text(encoding="utf-8")
2273
+ for needle in (
2274
+ f"id: {message_id}", "from: rtl", "to: verify", "created: ",
2275
+ "subject: Stimulus misreads spec", "refs:", "abc1234",
2276
+ "Fix the testcase and rerun.",
2277
+ ):
2278
+ if needle not in text:
2279
+ report(f"{label} message file lacks {needle!r}:\n{text}")
2280
+ return 1
2281
+ if not text.startswith("---\n"):
2282
+ report(f"{label} message file has no frontmatter.")
2283
+ return 1
2284
+
2285
+ elsewhere = mail(other, "list", "--json")
2286
+ if elsewhere.returncode != 0:
2287
+ report(f"{label} list failed in the separate repository: {elsewhere.stderr.strip()}")
2288
+ return 1
2289
+ if json.loads(elsewhere.stdout).get("unread"):
2290
+ report(f"{label} a separate repository saw the message.")
2291
+ return 1
2292
+
2293
+ context_after = run_keel(verify, "context", "--json", env=env)
2294
+ before, after = json.loads(context_before.stdout), json.loads(context_after.stdout)
2295
+ if (before.get("status"), before.get("nextAction")) != (after.get("status"), after.get("nextAction")):
2296
+ report(f"{label} unread mail changed keel context.")
2297
+ return 1
2298
+
2299
+ read = mail(verify, "read")
2300
+ if read.returncode != 0:
2301
+ report(f"{label} read failed: {read.stderr.strip()}")
2302
+ return 1
2303
+ for needle in ("Stimulus misreads spec", "Fix the testcase and rerun.", "not an instruction from the user"):
2304
+ if needle not in read.stdout:
2305
+ report(f"{label} read output lacks {needle!r}: {read.stdout.strip()}")
2306
+ return 1
2307
+ after_read = json.loads(mail(verify, "list", "--json").stdout).get("unread")
2308
+ if after_read:
2309
+ report(f"{label} list still shows unread mail after read: {after_read!r}")
2310
+ return 1
2311
+ if list((box / "new").glob("*.md")):
2312
+ report(f"{label} read left the message in new/.")
2313
+ return 1
2314
+ if len(list((box / "done").glob("*.md"))) != 1:
2315
+ report(f"{label} read did not put the message in done/.")
2316
+ return 1
2317
+
2318
+ reply = mail(verify, "send", "--to", "rtl", "--subject", "Re: stimulus", "--reply-to", message_id, "--body", "Done.")
2319
+ replies = list((mailbox_common_dir(rtl) / "keel-mailbox" / "rtl" / "new").glob("*.md"))
2320
+ if reply.returncode != 0:
2321
+ report(f"{label} the reply failed: {reply.stderr.strip()}")
2322
+ return 1
2323
+ if len(replies) != 1:
2324
+ report(f"{label} expected one reply in rtl/new, found {len(replies)}.")
2325
+ return 1
2326
+ if f"reply_to: {message_id}" not in replies[0].read_text(encoding="utf-8"):
2327
+ report(f"{label} the reply did not carry reply_to {message_id}.")
2328
+ return 1
2329
+
2330
+ if "mailbox-cli" not in {name for name, _ in SCENARIOS}:
2331
+ report("mailbox-cli: scenario is not registered.")
2332
+ return 1
2333
+ report("mailbox-cli scenario passed.")
2334
+ return 0
2335
+
2336
+
2337
+ def validate_mailbox_claude_hooks_scenario() -> int:
2338
+ """Issue #180: Claude Code learns of mail at start, per prompt, and idle.
2339
+
2340
+ Runs the shipped hook script with host-shaped stdin. Wake-up itself is the
2341
+ host's file watcher plus `asyncRewake` (probed on Claude Code 2.1.283, see
2342
+ the cross-host-mailbox design F1/F2); what Keel owns, and checks here, is
2343
+ the contract the host acts on: the output shape and the exit code.
2344
+ """
2345
+ label = "mailbox-claude-hooks:"
2346
+ script = ROOT / PLUGIN_ROOT / "scripts/mail-hook.js"
2347
+ with tempfile.TemporaryDirectory(prefix="keel-mailhook-") as raw:
2348
+ base = Path(raw)
2349
+ rtl = mailbox_repository(base / "rtl")
2350
+ verify = base / "verify"
2351
+ subprocess.run(
2352
+ ["git", "worktree", "add", "-q", "-b", "verify", str(verify)],
2353
+ cwd=rtl, check=True, capture_output=True,
2354
+ )
2355
+ unbound = mailbox_repository(base / "unbound")
2356
+ env = {key: value for key, value in os.environ.items() if key != "KEEL_MAIL_ROLE"}
2357
+ env["KEEL_CLI"] = f'node "{ROOT / "bin" / "keel.js"}"'
2358
+
2359
+ def hook(cwd: Path, event: str, host_event: str) -> subprocess.CompletedProcess[str]:
2360
+ return subprocess.run(
2361
+ ["node", str(script), event],
2362
+ cwd=cwd, env=env, text=True, capture_output=True, check=False,
2363
+ input=json.dumps({"hook_event_name": host_event, "cwd": str(cwd)}),
2364
+ )
2365
+
2366
+ events = (
2367
+ ("session-start", "SessionStart"),
2368
+ ("user-prompt-submit", "UserPromptSubmit"),
2369
+ ("file-changed", "FileChanged"),
2370
+ )
2371
+ if not script.is_file():
2372
+ report(f"{label} {script.relative_to(ROOT)} does not exist.")
2373
+ return 1
2374
+ for event, host_event in events:
2375
+ quiet = hook(unbound, event, host_event)
2376
+ if quiet.returncode != 0:
2377
+ report(f"{label} {event} exited {quiet.returncode} in an unbound worktree.")
2378
+ return 1
2379
+ if quiet.stdout.strip() or quiet.stderr.strip():
2380
+ report(f"{label} {event} wrote output in an unbound worktree: {(quiet.stdout + quiet.stderr).strip()!r}")
2381
+ return 1
2382
+
2383
+ for cwd, role in ((rtl, "rtl"), (verify, "verify")):
2384
+ run_keel(cwd, "mail", "role", "--set", role, env=env)
2385
+ sent = run_keel(
2386
+ rtl, "mail", "send", "--to", "verify", "--subject", "Rerun the regression",
2387
+ "--body", "Spec section 4 was misread.", "--json", env=env,
2388
+ )
2389
+ if sent.returncode != 0:
2390
+ report(f"{label} could not send the fixture message: {sent.stderr.strip()}")
2391
+ return 1
2392
+ message_id = json.loads(sent.stdout)["id"]
2393
+ signal = mailbox_common_dir(rtl) / "keel-mailbox" / "verify" / ".signal"
2394
+ inbox = mailbox_common_dir(rtl) / "keel-mailbox" / "verify" / "new"
2395
+
2396
+ def names_the_message(text: str) -> str | None:
2397
+ for needle in (message_id, "`rtl`", "Rerun the regression", "keel mail read", "not an instruction from the user"):
2398
+ if needle not in text:
2399
+ return needle
2400
+ return None
2401
+
2402
+ start = hook(verify, "session-start", "SessionStart")
2403
+ if start.returncode != 0:
2404
+ report(f"{label} session-start exited {start.returncode}: {start.stderr.strip()}")
2405
+ return 1
2406
+ output = json.loads(start.stdout).get("hookSpecificOutput", {})
2407
+ if output.get("hookEventName") != "SessionStart":
2408
+ report(f"{label} session-start output names event {output.get('hookEventName')!r}.")
2409
+ return 1
2410
+ missing = names_the_message(output.get("additionalContext", ""))
2411
+ if missing:
2412
+ report(f"{label} session-start additionalContext lacks {missing!r}.")
2413
+ return 1
2414
+ if output.get("watchPaths") != [str(signal)]:
2415
+ report(f"{label} session-start watchPaths is {output.get('watchPaths')!r}, not [{str(signal)!r}].")
2416
+ return 1
2417
+
2418
+ prompt = hook(verify, "user-prompt-submit", "UserPromptSubmit")
2419
+ if prompt.returncode != 0:
2420
+ report(f"{label} user-prompt-submit exited {prompt.returncode}.")
2421
+ return 1
2422
+ prompt_output = json.loads(prompt.stdout).get("hookSpecificOutput", {})
2423
+ if prompt_output.get("hookEventName") != "UserPromptSubmit":
2424
+ report(f"{label} user-prompt-submit output names event {prompt_output.get('hookEventName')!r}.")
2425
+ return 1
2426
+ missing = names_the_message(prompt_output.get("additionalContext", ""))
2427
+ if missing:
2428
+ report(f"{label} user-prompt-submit additionalContext lacks {missing!r}.")
2429
+ return 1
2430
+
2431
+ wake = hook(verify, "file-changed", "FileChanged")
2432
+ if wake.returncode != 2:
2433
+ report(f"{label} file-changed exited {wake.returncode} with unread mail; 2 is what wakes the session.")
2434
+ return 1
2435
+ missing = names_the_message(wake.stderr)
2436
+ if missing:
2437
+ report(f"{label} file-changed stderr lacks {missing!r}.")
2438
+ return 1
2439
+ if len(list(inbox.glob("*.md"))) != 1:
2440
+ report(f"{label} a hook moved or removed the unread message.")
2441
+ return 1
2442
+
2443
+ run_keel(verify, "mail", "read", env=env)
2444
+ after = hook(verify, "file-changed", "FileChanged")
2445
+ if after.returncode != 0:
2446
+ report(f"{label} file-changed exited {after.returncode} after the mail was read.")
2447
+ return 1
2448
+ if after.stderr.strip():
2449
+ report(f"{label} file-changed wrote {after.stderr.strip()!r} with no unread mail.")
2450
+ return 1
2451
+ quiet_prompt = hook(verify, "user-prompt-submit", "UserPromptSubmit")
2452
+ if quiet_prompt.stdout.strip():
2453
+ report(f"{label} user-prompt-submit still announced mail after it was read.")
2454
+ return 1
2455
+
2456
+ if "mailbox-claude-hooks" not in {name for name, _ in SCENARIOS}:
2457
+ report(f"{label} scenario is not registered.")
2458
+ return 1
2459
+ report("mailbox-claude-hooks scenario passed.")
2460
+ return 0
2461
+
2462
+
2463
+ def validate_record_derives_skeleton_scenario() -> int:
2464
+ """Issue #179: `--record` writes the record slots a capsule implies.
2465
+
2466
+ Every slot it writes is a placeholder the gates still refuse as unfilled,
2467
+ so this changes who types the bookkeeping and not what completion needs.
2468
+ """
2469
+ label = "record-derives-skeleton:"
2470
+ fixture = task_capsule_compact_fixture()
2471
+ no_evidence = fixture.replace(
2472
+ " - Evidence:\n - Contract: pending\n - M1: pending\n", ""
2473
+ )
2474
+ red_green = no_evidence.replace(
2475
+ " - Strategy: evidence-first\n"
2476
+ " - Reason: this is a gate fixture; it exercises contract structure and has no executable behavior that can fail first\n"
2477
+ " - M1: node test.js\n",
2478
+ " - Strategy: vertical-tdd\n"
2479
+ " - M1: node test.js asserts the feature. Fails with: `boom`\n"
2480
+ " - M2 (regression): node old.js stays green\n"
2481
+ " - M3: node edge.js asserts the edge. Fails with: `edge` Detects: `drop the guard` -> `edge`\n",
2482
+ )
2483
+ if red_green == no_evidence:
2484
+ report(f"{label} the fixture's Verify block moved; update this scenario.")
2485
+ return 1
2486
+ expected_slots = [
2487
+ " - M1: pending",
2488
+ " - M1.red: pending",
2489
+ " - M1.green: pending",
2490
+ " - M2: pending",
2491
+ " - M3: pending",
2492
+ " - M3.red: pending",
2493
+ " - M3.green: pending",
2494
+ " - M3.detects: pending",
2495
+ " - Review:",
2496
+ " - Status: pending",
2497
+ " - Acceptance check: pending",
2498
+ " - Scope check: pending",
2499
+ " - Findings: pending",
2500
+ " - Blocker: none",
2501
+ " - Reauthorizations: none",
2502
+ ]
2503
+ with tempfile.TemporaryDirectory(prefix="keel-skeleton-") as raw:
2504
+ repo = Path(raw)
2505
+ tasks = repo / "openspec/changes/demo/tasks.md"
2506
+
2507
+ def record(*extra: str) -> tuple[int, dict]:
2508
+ result = run_keel(
2509
+ repo, "gate", "task-start", "--change", "demo", "--task", "1.1",
2510
+ *extra, "--json",
2511
+ )
2512
+ return result.returncode, json.loads(result.stdout)
2513
+
2514
+ write_text(tasks, red_green)
2515
+ code, payload = record("--record", "--no-guard")
2516
+ if code != 0:
2517
+ report(f"{label} --record refused a valid task with no Evidence: {payload.get('problems')!r}")
2518
+ return 1
2519
+ if payload.get("record", {}).get("status") != "recorded":
2520
+ report(f"{label} the outcome was {payload.get('record')!r}, not recorded.")
2521
+ return 1
2522
+ fingerprint = payload["contract"]["fingerprint"]["value"]
2523
+ after = tasks.read_text(encoding="utf-8")
2524
+ before_lines, after_lines = red_green.splitlines(), after.splitlines()
2525
+ added = [line for line in after_lines if line not in before_lines]
2526
+ want = [" - Evidence:", f" - Contract: keel-task-capsule/v1 sha256:{fingerprint}", *expected_slots]
2527
+ if added != want:
2528
+ report(f"{label} --record added {added!r}, expected {want!r}.")
2529
+ return 1
2530
+ if [line for line in before_lines if line not in after_lines]:
2531
+ report(f"{label} --record removed or rewrote a line outside the Evidence it added.")
2532
+ return 1
2533
+ code, again = record("--record", "--no-guard")
2534
+ if code != 0 or tasks.read_text(encoding="utf-8") != after:
2535
+ report(f"{label} a second --record was not byte-identical.")
2536
+ return 1
2537
+ if again.get("record", {}).get("status") != "unchanged":
2538
+ report(f"{label} a second --record reported {again.get('record')!r}, not unchanged.")
2539
+ return 1
2540
+ completion = run_keel(repo, "gate", "task-complete", "--change", "demo", "--task", "1.1", "--json")
2541
+ if completion.returncode == 0:
2542
+ report(f"{label} task-complete accepted a task whose slots were only filled with pending.")
2543
+ return 1
2544
+
2545
+ kept = red_green.replace(
2546
+ " - Stop if:\n",
2547
+ " - Evidence:\n - M1: pass. node test.js printed ok.\n - Stop if:\n",
2548
+ )
2549
+ write_text(tasks, kept)
2550
+ code, payload = record("--record", "--no-guard")
2551
+ text = tasks.read_text(encoding="utf-8")
2552
+ if code != 0:
2553
+ report(f"{label} --record refused a task with a partial Evidence block: {payload.get('problems')!r}")
2554
+ return 1
2555
+ if " - M1: pass. node test.js printed ok." not in text:
2556
+ report(f"{label} --record rewrote an existing concrete M1 line.")
2557
+ return 1
2558
+ if " - M1: pending" in text:
2559
+ report(f"{label} --record added a second M1 slot beside the kept one.")
2560
+ return 1
2561
+ if " - M1.red: pending" not in text:
2562
+ report(f"{label} --record did not add the missing M1.red slot beside the kept M1.")
2563
+ return 1
2564
+
2565
+ write_text(tasks, no_evidence)
2566
+ code, payload = record("--record", "--no-guard")
2567
+ text = tasks.read_text(encoding="utf-8")
2568
+ if code != 0:
2569
+ report(f"{label} --record refused a valid evidence-first task: {payload.get('problems')!r}")
2570
+ return 1
2571
+ if ".red:" in text or ".green:" in text:
2572
+ report(f"{label} an evidence-first task was given .red/.green slots.")
2573
+ return 1
2574
+
2575
+ broken = red_green.replace(" - Strategy: vertical-tdd\n", "")
2576
+ write_text(tasks, broken)
2577
+ code, payload = record("--record")
2578
+ if code == 0:
2579
+ report(f"{label} --record filled slots around a task with no Strategy.")
2580
+ return 1
2581
+ if tasks.read_text(encoding="utf-8") != broken:
2582
+ report(f"{label} a refused --record wrote to tasks.md.")
2583
+ return 1
2584
+ if (repo / "keel/guard.json").exists():
2585
+ report(f"{label} a refused --record wrote the guard manifest.")
2586
+ return 1
2587
+
2588
+ write_text(tasks, fixture.replace(" - M1: pending\n", ""))
2589
+ code, payload = record()
2590
+ messages = [item.get("message", "") for item in payload.get("problems", [])]
2591
+ if code == 0:
2592
+ report(f"{label} task-start without --record accepted a missing M1 slot.")
2593
+ return 1
2594
+ if not any("--record" in message for message in messages):
2595
+ report(f"{label} the evidence-label-mismatch refusal does not name --record: {messages!r}")
2596
+ return 1
2597
+
2598
+ if "record-derives-skeleton" not in {name for name, _ in SCENARIOS}:
2599
+ report(f"{label} scenario is not registered.")
2600
+ return 1
2601
+ report("record-derives-skeleton scenario passed.")
2602
+ return 0
2603
+
2604
+
2605
+ def validate_review_checklist_defers_to_gate_scenario() -> int:
2606
+ """Issue #179: Review guidance keeps what no gate can judge, and only that.
2607
+
2608
+ `task-complete` refuses a missing or drifted Contract anchor and missing
2609
+ `.red`/`.green` Evidence on its own, so asking the agent to confirm them
2610
+ again is reading cost without a criterion. What stays is the judgment.
2611
+ """
2612
+ label = "review-checklist-defers-to-gate:"
2613
+ for root in ("src/skills", f"{PLUGIN_ROOT}/skills"):
2614
+ text = (ROOT / root / "keel-review-checklist" / "SKILL.md").read_text(encoding="utf-8")
2615
+ flat = " ".join(text.split())
2616
+ for restated in (
2617
+ "Evidence `Contract` line records the task-start capsule fingerprint",
2618
+ "confirm concrete per-label `.red` and `.green` Evidence exists",
2619
+ ):
2620
+ if restated in flat:
2621
+ report(f"{label} {root} keel-review-checklist still restates a gate refusal: {restated!r}")
2622
+ return 1
2623
+ for kept in (
2624
+ "evidence-first tasks",
2625
+ "observable proof",
2626
+ "through the public interface",
2627
+ "not build-only or shape-only",
2628
+ ):
2629
+ if kept not in flat:
2630
+ report(f"{label} {root} keel-review-checklist lost the judgment {kept!r}.")
2631
+ return 1
2632
+ if "review-checklist-defers-to-gate" not in {name for name, _ in SCENARIOS}:
2633
+ report(f"{label} scenario is not registered.")
2634
+ return 1
2635
+ report("review-checklist-defers-to-gate scenario passed.")
2636
+ return 0
2637
+
2638
+
2173
2639
  def validate_covers_annotation_entry_scenario() -> int:
2174
2640
  """Issue #49 Section 1's fail-open half, owner-decided 2026-08-17: a Covers
2175
2641
  entry that opens with a critical-statement identifier and a dash
@@ -14090,6 +14556,13 @@ def validate_core_gates_scenario() -> int:
14090
14556
  " - Evidence:\n"
14091
14557
  f" - Contract: {anchor}\n"
14092
14558
  " - M1: pending\n"
14559
+ " - Review:\n"
14560
+ " - Status: pending\n"
14561
+ " - Acceptance check: pending\n"
14562
+ " - Scope check: pending\n"
14563
+ " - Findings: pending\n"
14564
+ " - Blocker: none\n"
14565
+ " - Reauthorizations: none\n"
14093
14566
  " - Report:\n"
14094
14567
  " - Summary\n"
14095
14568
  )
@@ -14237,24 +14710,23 @@ def validate_core_gates_scenario() -> int:
14237
14710
  write_text(record_tasks, record_task("pending").replace(
14238
14711
  " - Contract: pending\n", ""
14239
14712
  ))
14713
+ # Issue #179: a missing anchor is a missing record slot, which
14714
+ # `--record` now derives instead of refusing; refusal is kept for an
14715
+ # authoring error (see `record-derives-skeleton`).
14240
14716
  missing_anchor = run_keel(
14241
14717
  record_repo, "gate", "task-start",
14242
- "--change", "demo", "--task", "1.1", "--record", "--json",
14718
+ "--change", "demo", "--task", "1.1", "--record", "--no-guard", "--json",
14243
14719
  )
14244
- if (
14245
- missing_anchor.returncode != 3
14246
- or not any(
14247
- problem.get("code") == "record-refused"
14248
- for problem in json.loads(missing_anchor.stdout).get("problems", [])
14249
- )
14250
- or (record_repo / "keel/guard.json").exists()
14251
- ):
14720
+ if missing_anchor.returncode != 0:
14252
14721
  report(
14253
- "core-gates scenario --record with a missing anchor must "
14254
- "refuse and write nothing, not even the guard manifest."
14722
+ "core-gates scenario --record with a missing anchor must add "
14723
+ "the anchor and pass."
14255
14724
  )
14256
14725
  report((missing_anchor.stderr or missing_anchor.stdout).strip())
14257
14726
  return 1
14727
+ if " - Contract: keel-task-capsule/v1 sha256:" not in record_tasks.read_text(encoding="utf-8"):
14728
+ report("core-gates scenario --record did not write the missing Contract anchor.")
14729
+ return 1
14258
14730
 
14259
14731
  invalid_base = run_keel(
14260
14732
  completion_repo,
@@ -15207,11 +15679,46 @@ def validate_native_plugin_manifests_scenario() -> int:
15207
15679
  "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/",
15208
15680
  )
15209
15681
  )
15682
+ # Plus the Claude-only mailbox hooks (#180). They stay out of hooks.json,
15683
+ # which Codex loads too: FileChanged and `asyncRewake` are Claude Code's.
15684
+ def mail_hook(event: str, **extra: object) -> dict:
15685
+ return {
15686
+ "type": "command",
15687
+ "command": "node",
15688
+ "args": [
15689
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/mail-hook.js",
15690
+ event,
15691
+ ],
15692
+ "timeout": 10,
15693
+ **extra,
15694
+ }
15695
+
15696
+ expected_hooks["SessionStart"] = [
15697
+ *expected_hooks.get("SessionStart", []),
15698
+ {"hooks": [mail_hook("session-start")]},
15699
+ ]
15700
+ expected_hooks["UserPromptSubmit"] = [{"hooks": [mail_hook("user-prompt-submit")]}]
15701
+ expected_hooks["FileChanged"] = [
15702
+ {"hooks": [mail_hook("file-changed", asyncRewake=True)]}
15703
+ ]
15210
15704
  if root_manifest.get("hooks") != expected_hooks:
15211
15705
  report(
15212
15706
  "native-plugin-manifests root plugin manifest hooks diverge "
15213
15707
  f"from {PLUGIN_ROOT}/hooks/hooks.json after resolving script paths "
15214
- f"from the repository root: {root_manifest.get('hooks')!r}"
15708
+ "from the repository root, plus the Claude-only mailbox hooks: "
15709
+ f"{root_manifest.get('hooks')!r}"
15710
+ )
15711
+ return 1
15712
+ if sorted(plugin_hooks) != ["PreToolUse", "SessionStart"]:
15713
+ report(
15714
+ f"native-plugin-manifests {PLUGIN_ROOT}/hooks/hooks.json, which Codex "
15715
+ f"also loads, declares events beyond SessionStart and PreToolUse: {sorted(plugin_hooks)!r}"
15716
+ )
15717
+ return 1
15718
+ if "asyncRewake" in json.dumps(plugin_hooks):
15719
+ report(
15720
+ f"native-plugin-manifests {PLUGIN_ROOT}/hooks/hooks.json carries the "
15721
+ "Claude-only asyncRewake field."
15215
15722
  )
15216
15723
  return 1
15217
15724
 
@@ -31904,6 +32411,22 @@ SCENARIOS: tuple = (
31904
32411
  "decisions-are-selectable",
31905
32412
  validate_decisions_are_selectable_scenario,
31906
32413
  ),
32414
+ (
32415
+ "mailbox-cli",
32416
+ validate_mailbox_cli_scenario,
32417
+ ),
32418
+ (
32419
+ "mailbox-claude-hooks",
32420
+ validate_mailbox_claude_hooks_scenario,
32421
+ ),
32422
+ (
32423
+ "record-derives-skeleton",
32424
+ validate_record_derives_skeleton_scenario,
32425
+ ),
32426
+ (
32427
+ "review-checklist-defers-to-gate",
32428
+ validate_review_checklist_defers_to_gate_scenario,
32429
+ ),
31907
32430
  (
31908
32431
  "covers-annotation-entry",
31909
32432
  validate_covers_annotation_entry_scenario,