@christang/keel 5.3.3 → 5.3.4

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.
@@ -37,8 +37,8 @@ REQUIRED_SCRIPTS = [
37
37
  "scripts/validate_plugin.py",
38
38
  ]
39
39
 
40
- PACKAGE_VERSION = "5.3.3"
41
- PROTOCOL_VERSION = "5.3.3"
40
+ PACKAGE_VERSION = "5.3.4"
41
+ PROTOCOL_VERSION = "5.3.4"
42
42
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
43
43
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
44
44
  OPENSPEC_CONFIG_PATH = Path("openspec/config.yaml")
@@ -50,7 +50,6 @@ OPENSPEC_SURFACE_OVERLAY_END = "<!-- keel:openspec-surface-overlay:end -->"
50
50
 
51
51
  SKILL_TARGETS = {"claude", "codex", "opencode"}
52
52
  HOOK_TARGETS = {"claude"}
53
- KEEL_HOOK_NAME = "keel-gate"
54
53
  AGENT_TARGETS: set[str] = set()
55
54
  ADAPTER_TARGETS = {"claude", "codex", "opencode"}
56
55
  AGENT_PROTOCOL_TARGETS = {"codex", "opencode"}
@@ -415,6 +414,17 @@ def validate_npm_package(errors: list[str]) -> None:
415
414
  errors.append(f"bin/keel.js missing required CLI support: {required}")
416
415
 
417
416
 
417
+ # Path expressions rooted at a tree the retirement check above requires to be
418
+ # absent. `src/core` and `src/skills` are live, so only the retired `src`
419
+ # children are listed.
420
+ RETIRED_PATH_EXPRESSIONS = (
421
+ r'ROOT\s*/\s*"dist"',
422
+ r'ROOT\s*/\s*"src"\s*/\s*"assets"',
423
+ r'ROOT\s*/\s*"src"\s*/\s*"hooks"',
424
+ r'ROOT\s*/\s*"src"\s*/\s*"adapters"',
425
+ )
426
+
427
+
418
428
  def validate_paths(errors: list[str]) -> None:
419
429
  for directory in REQUIRED_DIRECTORIES:
420
430
  if not (ROOT / directory).is_dir():
@@ -448,6 +458,43 @@ def validate_paths(errors: list[str]) -> None:
448
458
  f"retired custom distribution path must be removed: {retired}"
449
459
  )
450
460
 
461
+ # Every Keel marker that carries a version is a shipped claim about which
462
+ # version this is. Derive the set from the markers that exist rather than a
463
+ # fixed list, because a fixed list is the next thing to fall behind — which
464
+ # is exactly how the `.codex/` overlays sat four versions back unnoticed.
465
+ for marker_file in sorted(ROOT.rglob("*")):
466
+ if not marker_file.is_file() or not marker_file.suffix in (".md", ".json"):
467
+ continue
468
+ relative = marker_file.relative_to(ROOT).as_posix()
469
+ if relative.startswith(("node_modules/", "openspec/changes/archive/", "keel/archive/")):
470
+ continue
471
+ try:
472
+ text = marker_file.read_text(encoding="utf-8")
473
+ except (UnicodeDecodeError, OSError):
474
+ continue
475
+ for found in re.findall(r"keel:[a-z-]+(?::end)?\s+version=([0-9][^\s>]*)", text):
476
+ if found != PACKAGE_VERSION:
477
+ errors.append(
478
+ "shipped version marker disagrees with the package version "
479
+ f"{PACKAGE_VERSION}: {relative} says {found}"
480
+ )
481
+
482
+ # Asserting the trees are gone is not enough: a check that still resolves a
483
+ # path into one of them can only ever find nothing, and rglob over a missing
484
+ # directory yields no error, so the check reports success forever. Naming a
485
+ # retired tree in a string literal is fine — that is how the checks above
486
+ # state what must not exist; building a Path into one is not.
487
+ validator_source = (ROOT / "scripts" / "validate_plugin.py").read_text(
488
+ encoding="utf-8"
489
+ )
490
+ for line_number, line in enumerate(validator_source.splitlines(), start=1):
491
+ if any(re.search(pattern, line) for pattern in RETIRED_PATH_EXPRESSIONS):
492
+ errors.append(
493
+ "validator resolves a path under a retired distribution tree, "
494
+ "so the check it feeds can only iterate nothing: "
495
+ f"scripts/validate_plugin.py:{line_number}: {line.strip()}"
496
+ )
497
+
451
498
 
452
499
  def extract_managed_block(content: str) -> str | None:
453
500
  start_match = MANAGED_START_RE.search(content)
@@ -571,10 +618,20 @@ def validate_templates(errors: list[str]) -> None:
571
618
  f"{template['name']} includes forbidden content: {forbidden}"
572
619
  )
573
620
 
621
+ # What actually ships is whatever package.json declares, so derive the roots
622
+ # from there rather than naming a tree that can retire out from under the
623
+ # check the way `src/assets` and `dist` did.
624
+ packaged_roots = [
625
+ ROOT / entry
626
+ for entry in json.loads(
627
+ (ROOT / "package.json").read_text(encoding="utf-8")
628
+ ).get("files", [])
629
+ if (ROOT / entry).is_dir()
630
+ ]
631
+
574
632
  active_task_placeholders = [
575
633
  path.relative_to(ROOT).as_posix()
576
- for base in (ROOT / "src" / "assets", ROOT / "dist")
577
- if base.exists()
634
+ for base in packaged_roots
578
635
  for path in base.rglob("keel/TASK.md")
579
636
  ]
580
637
  if active_task_placeholders:
@@ -585,18 +642,9 @@ def validate_templates(errors: list[str]) -> None:
585
642
 
586
643
  backlog_assets = [
587
644
  path.relative_to(ROOT).as_posix()
588
- for base in (ROOT / "src" / "assets", ROOT / "dist")
589
- if base.exists()
645
+ for base in packaged_roots
590
646
  for path in base.rglob("keel/backlog/*")
591
647
  ]
592
- backlog_assets.extend(
593
- path.relative_to(ROOT).as_posix()
594
- for path in (
595
- ROOT / "src" / "assets" / "shared" / "backlog",
596
- ROOT / "dist" / "shared" / "assets" / "backlog",
597
- )
598
- if path.exists()
599
- )
600
648
  if backlog_assets:
601
649
  errors.append(
602
650
  "package must not include keel backlog assets: "
@@ -606,7 +654,6 @@ def validate_templates(errors: list[str]) -> None:
606
654
 
607
655
  def validate_openspec_schema(errors: list[str]) -> None:
608
656
  source_root = ROOT / "assets" / "openspec" / "schemas" / OPENSPEC_SCHEMA_NAME
609
- dist_root = source_root
610
657
  required_files = [
611
658
  "schema.yaml",
612
659
  "templates/proposal.md",
@@ -615,13 +662,12 @@ def validate_openspec_schema(errors: list[str]) -> None:
615
662
  "templates/tasks.md",
616
663
  ]
617
664
 
618
- for root_name, root in (("source", source_root), ("dist", dist_root)):
619
- for relative in required_files:
620
- if not (root / relative).is_file():
621
- errors.append(
622
- f"OpenSpec {root_name} schema missing file: "
623
- f"{root.relative_to(ROOT).as_posix()}/{relative}"
624
- )
665
+ for relative in required_files:
666
+ if not (source_root / relative).is_file():
667
+ errors.append(
668
+ "OpenSpec source schema missing file: "
669
+ f"{source_root.relative_to(ROOT).as_posix()}/{relative}"
670
+ )
625
671
 
626
672
  schema_path = source_root / "schema.yaml"
627
673
  tasks_template_path = source_root / "templates" / "tasks.md"
@@ -717,33 +763,11 @@ def validate_openspec_schema(errors: list[str]) -> None:
717
763
  f"{forbidden}"
718
764
  )
719
765
 
720
- if source_root.is_dir() and dist_root.is_dir():
721
- source_files = {
722
- path.relative_to(source_root).as_posix(): path.read_text(encoding="utf-8")
723
- for path in sorted(source_root.rglob("*"))
724
- if path.is_file()
725
- }
726
- dist_files = {
727
- path.relative_to(dist_root).as_posix(): path.read_text(encoding="utf-8")
728
- for path in sorted(dist_root.rglob("*"))
729
- if path.is_file()
730
- }
731
- if source_files != dist_files:
732
- missing = sorted(set(source_files) - set(dist_files))
733
- unexpected = sorted(set(dist_files) - set(source_files))
734
- changed = sorted(
735
- path
736
- for path in set(source_files) & set(dist_files)
737
- if source_files[path] != dist_files[path]
738
- )
739
- errors.append(
740
- "OpenSpec dist schema differs from source"
741
- + (
742
- f"; missing={missing}, unexpected={unexpected}, changed={changed}"
743
- if missing or unexpected or changed
744
- else ""
745
- )
746
- )
766
+ # A source-versus-dist comparison stood here, but `dist_root` was assigned
767
+ # `source_root`, so it diffed a directory against itself and could not fail.
768
+ # The pair that really needs comparing — this packaged copy against the
769
+ # repo-local one OpenSpec resolves — is asserted by
770
+ # `invalidation-authoring-surface`.
747
771
 
748
772
 
749
773
  def validate_skill_docs(errors: list[str]) -> None:
@@ -946,18 +970,17 @@ def snapshot_files(root: Path) -> dict[str, str]:
946
970
  return snapshot
947
971
 
948
972
 
949
- def packaged_openspec_schema_install_paths() -> list[str]:
950
- schema_root = (
951
- ROOT
952
- / "dist"
953
- / "shared"
954
- / "assets"
955
- / "openspec"
956
- / "schemas"
957
- / OPENSPEC_SCHEMA_NAME
973
+ def packaged_openspec_schema_install_paths(root: Path | None = None) -> list[str]:
974
+ # The root the installer itself reads (install_to_repo.openspec_schema_actions),
975
+ # which raises on the same condition. A validator that answered `[]` here left
976
+ # six install/uninstall/clear assertions iterating nothing and reporting pass.
977
+ schema_root = root if root is not None else (
978
+ ROOT / "assets" / "openspec" / "schemas" / OPENSPEC_SCHEMA_NAME
958
979
  )
959
980
  if not schema_root.is_dir():
960
- return []
981
+ raise FileNotFoundError(
982
+ f"packaged OpenSpec schema root is missing: {schema_root}"
983
+ )
961
984
 
962
985
  return [
963
986
  (OPENSPEC_SCHEMA_ROOT / path.relative_to(schema_root)).as_posix()
@@ -2462,22 +2485,6 @@ def validate_update_default_registry_scenario() -> int:
2462
2485
  return 0
2463
2486
 
2464
2487
 
2465
- def run_keel_hook(repo: Path, event: dict) -> subprocess.CompletedProcess[str]:
2466
- env = dict(os.environ)
2467
- env["KEEL_CLI"] = str(ROOT / "bin/keel.js")
2468
- return subprocess.run(
2469
- ["node", str(ROOT / "dist" / "claude" / "hooks" / KEEL_HOOK_NAME / "keel-gate.js")],
2470
- cwd=repo,
2471
- env=env,
2472
- input=json.dumps(event),
2473
- text=True,
2474
- encoding="utf-8",
2475
- errors="replace",
2476
- capture_output=True,
2477
- check=False,
2478
- )
2479
-
2480
-
2481
2488
  def gate_task(
2482
2489
  *,
2483
2490
  checked: bool,
@@ -3642,13 +3649,561 @@ SCHEMA_COPY_PAIRS = (
3642
3649
  )
3643
3650
 
3644
3651
 
3652
+ def validate_anchor_reverification_bound_scenario() -> int:
3653
+ label = "anchor-reverification-bound"
3654
+
3655
+ # The fingerprint is described as recompiled and compared at resume,
3656
+ # projection, and completion, with no stated bound. It holds while the
3657
+ # change is live: the capsule records each authority's source as a path
3658
+ # under the change directory, and archiving renames that directory. An
3659
+ # unstated boundary reads as no boundary, so demonstrate where it is.
3660
+ with tempfile.TemporaryDirectory(prefix="keel-anchor-bound-") as raw_tmp:
3661
+ repo = Path(raw_tmp) / "repo"
3662
+ repo.mkdir()
3663
+ live = repo / "openspec/changes/demo/tasks.md"
3664
+ write_text(live, task_contract_fixture(evidence=("Contract: pending", "M1: pending")))
3665
+
3666
+ recorded = run_keel(
3667
+ repo, "gate", "task-start", "--change", "demo", "--task", "1.1",
3668
+ "--record", "--json",
3669
+ )
3670
+ payload = json.loads(recorded.stdout)
3671
+ if payload.get("status") != "pass":
3672
+ report(f"{label} could not record an anchor on a live change.")
3673
+ report(json.dumps(payload.get("problems", []), indent=2))
3674
+ return 1
3675
+ anchor = payload["contract"]["fingerprint"]["value"]
3676
+
3677
+ # Live: recompiling reproduces the recorded value, which is the
3678
+ # guarantee the resident protocol states.
3679
+ again = json.loads(
3680
+ run_keel(
3681
+ repo, "gate", "task-start", "--change", "demo", "--task", "1.1", "--json"
3682
+ ).stdout
3683
+ )
3684
+ if again["contract"]["fingerprint"]["value"] != anchor:
3685
+ report(f"{label} a live anchor did not recompile to its recorded value.")
3686
+ return 1
3687
+
3688
+ # Archived: the gate refuses to select the change at all, so the bound
3689
+ # is enforced rather than merely documented.
3690
+ archived = repo / "openspec/changes/archive/2026-07-28-demo/tasks.md"
3691
+ write_text(archived, live.read_text(encoding="utf-8"))
3692
+ refused = run_keel(
3693
+ repo, "gate", "task-start",
3694
+ "--change", "archive/2026-07-28-demo", "--task", "1.1",
3695
+ )
3696
+ if refused.returncode == 0 or "invalid change name" not in (
3697
+ refused.stderr + refused.stdout
3698
+ ):
3699
+ report(
3700
+ f"{label} the gate accepted an archived change; the bound this "
3701
+ "documents is supposed to be enforced, not advisory."
3702
+ )
3703
+ report((refused.stderr or refused.stdout).strip())
3704
+ return 1
3705
+
3706
+ # And the reason the refusal is right: compiling the archived copy
3707
+ # directly yields a different fingerprint, because each authority's
3708
+ # `source` names the directory the task now lives in.
3709
+ probe = subprocess.run(
3710
+ [
3711
+ "node", "-e",
3712
+ "const {loadTaskContract}=require(process.argv[1]);"
3713
+ "const c=loadTaskContract(process.argv[2],'archive/2026-07-28-demo','1.1');"
3714
+ "process.stdout.write(c.contract.fingerprint.value);",
3715
+ str(ROOT / "src/core/task-contract.js"),
3716
+ str(repo),
3717
+ ],
3718
+ text=True, encoding="utf-8", capture_output=True, check=False,
3719
+ )
3720
+ if probe.returncode != 0:
3721
+ report(f"{label} could not compile the archived copy directly.")
3722
+ report((probe.stderr or probe.stdout).strip())
3723
+ return 1
3724
+ if probe.stdout.strip() == anchor:
3725
+ report(
3726
+ f"{label} the archived copy reproduced the anchor, so the "
3727
+ "documented bound no longer describes reality — revisit the "
3728
+ "protocol wording rather than relaxing this check."
3729
+ )
3730
+ return 1
3731
+
3732
+ # And the resident protocol must say where the guarantee stops.
3733
+ resident = (ROOT / "AGENTS.md").read_text(encoding="utf-8")
3734
+ if "while its change is live" not in resident:
3735
+ report(
3736
+ f"{label} the resident protocol describes recompilation without "
3737
+ "stating that it holds while the change is live."
3738
+ )
3739
+ return 1
3740
+
3741
+ report(f"{label} scenario passed.")
3742
+ return 0
3743
+
3744
+
3745
+ def validate_authoring_surface_owner_and_tags_scenario() -> int:
3746
+ label = "authoring-surface-owner-and-tags"
3747
+
3748
+ # Both rules this change adds widen what a gate accepts. An author only
3749
+ # benefits if the shipped surface says so, so the template, the artifact
3750
+ # instruction the CLI hands back, and the resident protocol each state them.
3751
+ template = (
3752
+ ROOT / "openspec/schemas/keel-spec-driven/templates/tasks.md"
3753
+ ).read_text(encoding="utf-8")
3754
+ resident = (ROOT / "AGENTS.md").read_text(encoding="utf-8")
3755
+
3756
+ # Read the instruction the way an author receives it — through the CLI in a
3757
+ # repository Keel installed — rather than from the schema file it is
3758
+ # composed from, so a change that never reaches the author is a failure.
3759
+ with tempfile.TemporaryDirectory(prefix="keel-authoring-surface-") as raw_tmp:
3760
+ repo = Path(raw_tmp) / "repo"
3761
+ repo.mkdir()
3762
+ install = run_keel(repo, "--install")
3763
+ if install.returncode != 0:
3764
+ report(f"{label} keel --install failed.")
3765
+ report((install.stderr or install.stdout).strip())
3766
+ return 1
3767
+ created = run_openspec(repo, "new", "change", "surface-probe")
3768
+ if created is None:
3769
+ report(f"{label} skipped: the openspec CLI is not on PATH.")
3770
+ return 3
3771
+ if created.returncode != 0:
3772
+ report(f"{label} could not scaffold a change to read the instruction.")
3773
+ report((created.stderr or created.stdout).strip())
3774
+ return 1
3775
+ instructions = run_openspec(
3776
+ repo, "instructions", "tasks", "--change", "surface-probe"
3777
+ )
3778
+ if instructions is None or instructions.returncode != 0:
3779
+ report(f"{label} could not read the tasks artifact instruction.")
3780
+ if instructions is not None:
3781
+ report((instructions.stderr or instructions.stdout).strip())
3782
+ return 1
3783
+ instruction = instructions.stdout
3784
+
3785
+ for surface, text in (("tasks template", template), ("tasks instruction", instruction)):
3786
+ for needle in (
3787
+ "regression",
3788
+ "at least one check untagged",
3789
+ ):
3790
+ if needle not in text:
3791
+ report(f"{label} {surface} does not describe the tag: {needle}")
3792
+ return 1
3793
+ # D6 — the wording trap: red and green accompany the bare label.
3794
+ if "in addition to" not in text.lower():
3795
+ report(
3796
+ f"{label} {surface} still reads as though `.red`/`.green` "
3797
+ "replace the bare M<n> Evidence rather than accompanying it."
3798
+ )
3799
+ return 1
3800
+ if "repo-relative path that exists" not in text:
3801
+ report(
3802
+ f"{label} {surface} does not state the existing-path owner form."
3803
+ )
3804
+ return 1
3805
+ if "HANDOFF" not in text:
3806
+ report(f"{label} {surface} does not state that HANDOFF is refused.")
3807
+ return 1
3808
+
3809
+ for needle in (
3810
+ "regression-only-strategy",
3811
+ "in addition to the bare",
3812
+ "any repo-relative path that exists",
3813
+ ):
3814
+ if needle not in resident:
3815
+ report(f"{label} resident protocol does not state: {needle}")
3816
+ return 1
3817
+
3818
+ for local, packaged in SCHEMA_COPY_PAIRS:
3819
+ if (ROOT / local).read_text(encoding="utf-8") != (
3820
+ ROOT / packaged
3821
+ ).read_text(encoding="utf-8"):
3822
+ report(f"{label} schema copies diverge: {local} vs {packaged}")
3823
+ return 1
3824
+
3825
+ report(f"{label} scenario passed.")
3826
+ return 0
3827
+
3828
+
3829
+ def validate_durable_owner_vocabulary_scenario() -> int:
3830
+ label = "durable-owner-vocabulary"
3831
+
3832
+ # The accepted owner forms are shape checks: a gate cannot resolve a URL or
3833
+ # confirm an archive path is the right one. A repo-relative path is the one
3834
+ # form it can actually check, so refusing it drew the line in the least
3835
+ # defensible place.
3836
+ with tempfile.TemporaryDirectory(prefix="keel-owner-vocab-") as raw_tmp:
3837
+ repo = Path(raw_tmp) / "repo"
3838
+ repo.mkdir()
3839
+ tasks_path = repo / "openspec/changes/demo/tasks.md"
3840
+ write_text(repo / "openspec/FOLLOWUP.md", "# Follow-ups\n")
3841
+ write_text(repo / "keel/HANDOFF.md", "pointer\n")
3842
+ write_text(repo / "keel/archive/notes/2026-07-28-example.md", "note\n")
3843
+
3844
+ def invalidation_start(closure: str) -> dict:
3845
+ write_text(
3846
+ tasks_path,
3847
+ task_contract_fixture().replace(
3848
+ "## Invalidates\n\n- None.\n\n",
3849
+ '## Invalidates\n\n- I1: "the wording that is now wrong" '
3850
+ f"— somewhere in the repo. {closure}\n\n",
3851
+ ),
3852
+ )
3853
+ result = run_keel(
3854
+ repo, "gate", "task-start", "--change", "demo", "--task", "1.1", "--json"
3855
+ )
3856
+ return json.loads(result.stdout)
3857
+
3858
+ def completion(findings: str) -> dict:
3859
+ fixture = (
3860
+ task_contract_fixture(evidence=("M1: check exercised.",))
3861
+ .replace("- [ ] 1.1", "- [x] 1.1")
3862
+ .replace(" - Status: pending\n", " - Status: pass\n")
3863
+ .replace(
3864
+ " - Acceptance check: pending\n",
3865
+ " - Acceptance check: behavior proven through the public CLI.\n",
3866
+ )
3867
+ .replace(
3868
+ " - Scope check: pending\n",
3869
+ " - Scope check: writes stayed inside Touch.\n",
3870
+ )
3871
+ .replace(
3872
+ " - Findings: pending\n", f" - Findings: {findings}\n"
3873
+ )
3874
+ )
3875
+ write_text(tasks_path, fixture)
3876
+ result = run_keel(
3877
+ repo, "gate", "task-complete", "--change", "demo", "--task", "1.1", "--json"
3878
+ )
3879
+ return json.loads(result.stdout)
3880
+
3881
+ def close(closure: str) -> dict:
3882
+ write_text(
3883
+ tasks_path,
3884
+ task_contract_fixture(evidence=("M1: check exercised.",))
3885
+ .replace("- [ ] 1.1", "- [x] 1.1")
3886
+ .replace(" - Status: pending\n", " - Status: pass\n")
3887
+ .replace(
3888
+ " - Acceptance check: pending\n",
3889
+ " - Acceptance check: proven.\n",
3890
+ )
3891
+ .replace(" - Scope check: pending\n", " - Scope check: inside Touch.\n")
3892
+ .replace(" - Findings: pending\n", " - Findings: none\n")
3893
+ + f"\n## Expectation Coverage\n\n- E1: the expectation. {closure}\n",
3894
+ )
3895
+ write_text(repo / "openspec/changes/demo/proposal.md", "# Proposal\n")
3896
+ write_text(repo / "openspec/changes/demo/design.md", "## Context\n\nfixture\n")
3897
+ write_text(
3898
+ repo / "openspec/changes/demo/specs/demo/spec.md",
3899
+ "## ADDED Requirements\n",
3900
+ )
3901
+ result = run_keel(
3902
+ repo, "gate", "change-close", "--change", "demo", "--action", "sync", "--json"
3903
+ )
3904
+ return json.loads(result.stdout)
3905
+
3906
+ # M1 — an existing repo path closes an entry in all three shared places.
3907
+ ledger = "Durable owner: openspec/FOLLOWUP.md"
3908
+ payload = invalidation_start(ledger)
3909
+ if payload.get("status") != "pass":
3910
+ report(f"{label} refused a repo ledger as an invalidation owner.")
3911
+ report(json.dumps(payload.get("problems", []), indent=2))
3912
+ return 1
3913
+
3914
+ payload = completion(f"the IDE shell contract gap. {ledger}")
3915
+ if payload.get("status") != "pass":
3916
+ report(f"{label} refused a repo ledger as a Findings owner.")
3917
+ report(json.dumps(payload.get("problems", []), indent=2))
3918
+ return 1
3919
+
3920
+ payload = close(ledger)
3921
+ if any(
3922
+ item.get("code") == "expectation-closure"
3923
+ for item in payload.get("problems", [])
3924
+ ):
3925
+ report(f"{label} refused a repo ledger as an Expectation Coverage owner.")
3926
+ report(json.dumps(payload.get("problems", []), indent=2))
3927
+ return 1
3928
+
3929
+ # And a path with no file behind it is refused, distinguishably.
3930
+ payload = invalidation_start("Durable owner: openspec/NOT-THERE.md")
3931
+ codes = {item.get("code") for item in payload.get("problems", [])}
3932
+ messages = " ".join(
3933
+ item.get("message", "") for item in payload.get("problems", [])
3934
+ )
3935
+ if (
3936
+ payload.get("status") != "fail"
3937
+ or "invalidation-owner-missing" not in codes
3938
+ or "openspec/NOT-THERE.md" not in messages
3939
+ ):
3940
+ report(f"{label} accepted a durable owner with no file behind it.")
3941
+ report(json.dumps(payload.get("problems", []), indent=2))
3942
+ return 1
3943
+
3944
+ # M2 — the pointer override is still not an owner, although it exists.
3945
+ payload = invalidation_start("Durable owner: keel/HANDOFF.md")
3946
+ messages = " ".join(
3947
+ item.get("message", "") for item in payload.get("problems", [])
3948
+ )
3949
+ if payload.get("status") != "fail" or "HANDOFF" not in messages:
3950
+ report(f"{label} accepted keel/HANDOFF.md as a durable owner.")
3951
+ report(json.dumps(payload.get("problems", []), indent=2))
3952
+ return 1
3953
+
3954
+ # A refusal names the forms it accepts, including the new one.
3955
+ payload = invalidation_start("no closure at all")
3956
+ messages = " ".join(
3957
+ item.get("message", "") for item in payload.get("problems", [])
3958
+ )
3959
+ for expected in ("Durable owner:", "repo-relative path that exists", "Discard reason:"):
3960
+ if expected not in messages:
3961
+ report(f"{label} refusal does not name the accepted form: {expected}")
3962
+ report(messages)
3963
+ return 1
3964
+
3965
+ # M3 — every previously accepted form still closes.
3966
+ for closure in (
3967
+ "Durable owner: openspec/changes/demo/proposal.md",
3968
+ "Durable owner: keel/archive/notes/2026-07-28-example.md",
3969
+ "Durable owner: https://github.com/TanglmChris/keel/issues/20",
3970
+ "Discard reason: it stands as written.",
3971
+ ):
3972
+ write_text(repo / "openspec/changes/demo/proposal.md", "# Proposal\n")
3973
+ payload = invalidation_start(closure)
3974
+ if payload.get("status") != "pass":
3975
+ report(f"{label} dropped a previously accepted form: {closure}")
3976
+ report(json.dumps(payload.get("problems", []), indent=2))
3977
+ return 1
3978
+
3979
+ report(f"{label} scenario passed.")
3980
+ return 0
3981
+
3982
+
3983
+ def regression_tag_fixture(
3984
+ commands: tuple[str, ...],
3985
+ evidence: tuple[str, ...],
3986
+ *,
3987
+ strategy: str = "vertical-tdd",
3988
+ ) -> str:
3989
+ return (
3990
+ task_contract_fixture(commands=commands, evidence=evidence)
3991
+ .replace(
3992
+ " - Commands:\n",
3993
+ f" - Verification Strategy: {strategy}\n - Commands:\n",
3994
+ )
3995
+ .replace(" - Status: pending\n", " - Status: pass\n")
3996
+ .replace(
3997
+ " - Acceptance check: pending\n",
3998
+ " - Acceptance check: behavior proven through the public CLI.\n",
3999
+ )
4000
+ .replace(
4001
+ " - Scope check: pending\n",
4002
+ " - Scope check: writes stayed inside Touch.\n",
4003
+ )
4004
+ .replace(" - Findings: pending\n", " - Findings: none\n")
4005
+ )
4006
+
4007
+
4008
+ def validate_regression_check_tag_scenario() -> int:
4009
+ label = "regression-check-tag"
4010
+
4011
+ # A regression check asserts that something already green is still green, so
4012
+ # it has no honest red. Requiring one leaves an author fabricating evidence
4013
+ # or folding the guard into the behavior check; the tag is the third option.
4014
+ with tempfile.TemporaryDirectory(prefix="keel-regression-tag-") as raw_tmp:
4015
+ repo = Path(raw_tmp) / "repo"
4016
+ repo.mkdir()
4017
+ tasks_path = repo / "openspec/changes/demo/tasks.md"
4018
+
4019
+ def complete(fixture: str) -> dict:
4020
+ write_text(tasks_path, fixture)
4021
+ result = run_keel(
4022
+ repo, "gate", "task-complete", "--change", "demo", "--task", "1.1", "--json"
4023
+ )
4024
+ return json.loads(result.stdout)
4025
+
4026
+ def start(fixture: str) -> dict:
4027
+ write_text(tasks_path, fixture)
4028
+ result = run_keel(
4029
+ repo, "gate", "task-start", "--change", "demo", "--task", "1.1", "--json"
4030
+ )
4031
+ return json.loads(result.stdout)
4032
+
4033
+ mixed_commands = (
4034
+ "M1: behavior reaches the public interface",
4035
+ "M2 (regression): the existing suite stays green",
4036
+ )
4037
+
4038
+ # M1 — a tagged check completes without red/green, and the untagged one
4039
+ # still needs both.
4040
+ payload = complete(
4041
+ regression_tag_fixture(
4042
+ mixed_commands,
4043
+ (
4044
+ "M1: behavior exercised.",
4045
+ "M1.red: failed before the implementation.",
4046
+ "M1.green: passed after.",
4047
+ "M2: existing suite still green.",
4048
+ ),
4049
+ )
4050
+ )
4051
+ if payload.get("status") != "pass":
4052
+ report(f"{label} refused a tagged regression check that needs no red.")
4053
+ report(json.dumps(payload.get("problems", []), indent=2))
4054
+ return 1
4055
+
4056
+ # D5 — the exemption is from red-green, not from evidence.
4057
+ payload = complete(
4058
+ regression_tag_fixture(
4059
+ mixed_commands,
4060
+ (
4061
+ "M1: behavior exercised.",
4062
+ "M1.red: failed before the implementation.",
4063
+ "M1.green: passed after.",
4064
+ "M2: pending",
4065
+ ),
4066
+ )
4067
+ )
4068
+ if payload.get("status") != "fail" or not any(
4069
+ "M2" in item.get("message", "")
4070
+ for item in payload.get("problems", [])
4071
+ ):
4072
+ report(f"{label} completed a tagged check with no evidence at all.")
4073
+ report(json.dumps(payload, indent=2))
4074
+ return 1
4075
+
4076
+ # M2 — the strategy cannot be emptied out by tagging every check.
4077
+ payload = start(
4078
+ regression_tag_fixture(
4079
+ (
4080
+ "M1 (regression): the existing suite stays green",
4081
+ "M2 (regression): the golden files stay byte-identical",
4082
+ ),
4083
+ ("M1: pending", "M2: pending"),
4084
+ )
4085
+ )
4086
+ codes = {item.get("code") for item in payload.get("problems", [])}
4087
+ if payload.get("status") != "fail" or "regression-only-strategy" not in codes:
4088
+ report(
4089
+ f"{label} accepted a red-green strategy whose every check is tagged."
4090
+ )
4091
+ report(json.dumps(payload, indent=2))
4092
+ return 1
4093
+
4094
+ # M3 — an untagged check emits no tag key, so its capsule and fingerprint
4095
+ # are byte-identical to what they were before the tag existed.
4096
+ payload = start(
4097
+ regression_tag_fixture(
4098
+ ("M1: behavior reaches the public interface",),
4099
+ ("M1: pending",),
4100
+ )
4101
+ )
4102
+ entries = (
4103
+ payload.get("contract", {})
4104
+ .get("capsule", {})
4105
+ .get("verification", {})
4106
+ .get("commands", [])
4107
+ )
4108
+ if payload.get("status") != "pass" or [sorted(entry) for entry in entries] != [
4109
+ ["check", "label"]
4110
+ ]:
4111
+ report(
4112
+ f"{label} changed the compiled shape of an untagged check, which "
4113
+ "moves every recorded contract fingerprint."
4114
+ )
4115
+ report(json.dumps(entries, indent=2))
4116
+ return 1
4117
+
4118
+ # And a tagged check does declare itself in the capsule, so the exemption
4119
+ # is a visible term of the contract rather than a silent skip.
4120
+ payload = start(
4121
+ regression_tag_fixture(mixed_commands, ("M1: pending", "M2: pending"))
4122
+ )
4123
+ tagged = next(
4124
+ (
4125
+ entry
4126
+ for entry in payload.get("contract", {})
4127
+ .get("capsule", {})
4128
+ .get("verification", {})
4129
+ .get("commands", [])
4130
+ if entry.get("label") == "M2"
4131
+ ),
4132
+ None,
4133
+ )
4134
+ if not tagged or tagged.get("regression") is not True:
4135
+ report(f"{label} did not record the regression tag in the capsule.")
4136
+ report(json.dumps(payload.get("contract", {}), indent=2))
4137
+ return 1
4138
+
4139
+ report(f"{label} scenario passed.")
4140
+ return 0
4141
+
4142
+
4143
+ def validate_packaged_schema_derivation_scenario() -> int:
4144
+ label = "packaged-schema-derivation"
4145
+
4146
+ # The helper derives the consumer-repo paths every install/uninstall/clear
4147
+ # assertion iterates. When its root stopped existing it returned an empty
4148
+ # list, so those loops compared nothing and reported success. Anchor it to
4149
+ # what the installer really writes, and make emptiness a failure here.
4150
+ try:
4151
+ packaged_openspec_schema_install_paths(ROOT / "no-such-packaged-root")
4152
+ except FileNotFoundError as error:
4153
+ if "no-such-packaged-root" not in str(error):
4154
+ report(f"{label} missing-root failure does not name the path it expected.")
4155
+ report(str(error))
4156
+ return 1
4157
+ else:
4158
+ report(
4159
+ f"{label} returned a set for a missing packaged root instead of failing; "
4160
+ "an absent root must not silently empty its callers' assertions."
4161
+ )
4162
+ return 1
4163
+
4164
+ derived = packaged_openspec_schema_install_paths()
4165
+ if not derived:
4166
+ report(
4167
+ f"{label} derived no packaged schema paths, so every assertion that "
4168
+ "iterates them verifies nothing."
4169
+ )
4170
+ return 1
4171
+
4172
+ with tempfile.TemporaryDirectory(prefix="keel-packaged-schema-") as raw_tmp:
4173
+ repo = Path(raw_tmp) / "repo"
4174
+ repo.mkdir()
4175
+ install = run_keel(repo, "--install")
4176
+ if install.returncode != 0:
4177
+ report(f"{label} keel --install failed.")
4178
+ report((install.stderr or install.stdout).strip())
4179
+ return 1
4180
+
4181
+ schema_root = repo / OPENSPEC_SCHEMA_ROOT
4182
+ installed = sorted(
4183
+ path.relative_to(repo).as_posix()
4184
+ for path in schema_root.rglob("*")
4185
+ if path.is_file()
4186
+ )
4187
+ if installed != sorted(derived):
4188
+ report(
4189
+ f"{label} derived paths do not match what keel --install wrote."
4190
+ )
4191
+ report(f"derived: {sorted(derived)}")
4192
+ report(f"installed: {installed}")
4193
+ return 1
4194
+
4195
+ report(f"{label} scenario passed.")
4196
+ return 0
4197
+
4198
+
3645
4199
  def validate_invalidation_authoring_surface_scenario() -> int:
3646
4200
  label = "invalidation-authoring-surface"
3647
4201
 
3648
4202
  # The two schema copies are the repo-local one OpenSpec resolves and the
3649
- # packaged one `keel --init` writes. compact-task-authoring already means to
3650
- # assert they agree, but its canonical root does not exist in this layout, so
3651
- # its rglob compares nothing; this states the pair explicitly.
4203
+ # packaged one `keel --init` writes. This is the only check that asserts they
4204
+ # agree: compact-task-authoring used to imply it through a projection loop
4205
+ # rooted at trees that no longer exist, so it compared nothing and has since
4206
+ # been removed.
3652
4207
  for local, packaged in SCHEMA_COPY_PAIRS:
3653
4208
  local_text = (ROOT / local).read_text(encoding="utf-8")
3654
4209
  packaged_text = (ROOT / packaged).read_text(encoding="utf-8")
@@ -4611,6 +5166,9 @@ def validate_tracker_durable_owner_scenario() -> int:
4611
5166
  report((handoff.stderr or handoff.stdout).strip())
4612
5167
  return 1
4613
5168
 
5169
+ # The archive path must now exist to own anything: a note nobody wrote
5170
+ # owns nothing, and a path is the one owner form a gate can check.
5171
+ write_text(repo / "keel/archive/follow-ups/x.md", "follow-up note\n")
4614
5172
  archived = complete("stale local note; owner keel/archive/follow-ups/x.md")
4615
5173
  if archived.returncode != 0:
4616
5174
  report(
@@ -7661,13 +8219,7 @@ def validate_expectation_alignment_real_tasks_scenario() -> int:
7661
8219
 
7662
8220
 
7663
8221
  def validate_compact_task_authoring_scenario() -> int:
7664
- source_root = (
7665
- ROOT / "src" / "assets" / "shared" / "openspec" / "schemas" / OPENSPEC_SCHEMA_NAME
7666
- )
7667
8222
  local_root = ROOT / "openspec" / "schemas" / OPENSPEC_SCHEMA_NAME
7668
- dist_root = (
7669
- ROOT / "dist" / "shared" / "assets" / "openspec" / "schemas" / OPENSPEC_SCHEMA_NAME
7670
- )
7671
8223
 
7672
8224
  which = run_openspec(ROOT, "schema", "which", OPENSPEC_SCHEMA_NAME, "--json")
7673
8225
  if which is None or which.returncode != 0:
@@ -7726,21 +8278,9 @@ def validate_compact_task_authoring_scenario() -> int:
7726
8278
  )
7727
8279
  return 1
7728
8280
 
7729
- for projection_root, label in ((dist_root, "dist"), (local_root, "repo-local")):
7730
- for source_file in sorted(source_root.rglob("*")):
7731
- if not source_file.is_file():
7732
- continue
7733
- relative = source_file.relative_to(source_root)
7734
- projected = projection_root / relative
7735
- if not projected.is_file() or (
7736
- source_file.read_text(encoding="utf-8")
7737
- != projected.read_text(encoding="utf-8")
7738
- ):
7739
- report(
7740
- f"compact-task-authoring {label} projection diverges from "
7741
- f"canonical source: {relative.as_posix()}"
7742
- )
7743
- return 1
8281
+ # The projection loop that stood here compared against `src/assets` and
8282
+ # `dist`, both retired, so it iterated nothing. `invalidation-authoring-surface`
8283
+ # asserts the two copies that do exist are byte-identical.
7744
8284
 
7745
8285
  with tempfile.TemporaryDirectory(prefix="keel-compact-") as raw_tmp:
7746
8286
  repo = Path(raw_tmp) / "fixture"
@@ -10287,6 +10827,20 @@ def validate_thin_native_install_scenario() -> int:
10287
10827
  )
10288
10828
  return 1
10289
10829
 
10830
+ # The bootstrap is the whole resident protocol a consumer gets, and the
10831
+ # qualifier "for product files" left readers to infer what it excluded.
10832
+ # The inference actually made was that tasks.md belongs in Touch.
10833
+ if not re.search(r"Touch\b[^\n]*\bbound", block, re.IGNORECASE):
10834
+ report("thin-native-install bootstrap does not state what Touch bounds.")
10835
+ return 1
10836
+ if not re.search(r"change'?s own dir|own change dir", block, re.IGNORECASE):
10837
+ report(
10838
+ "thin-native-install bootstrap does not name the record-write "
10839
+ "exemption, so a consumer still infers that tasks.md belongs in "
10840
+ "Touch."
10841
+ )
10842
+ return 1
10843
+
10290
10844
  claude_text = (repo / "CLAUDE.md").read_text(encoding="utf-8")
10291
10845
  if claude_text.count("@AGENTS.md") != 1:
10292
10846
  report(
@@ -11006,7 +11560,7 @@ def validate_resident_topic_matching_scenario() -> int:
11006
11560
  """
11007
11561
  label = "resident-topic-matching"
11008
11562
  source = (ROOT / "assets/bootstrap/AGENTS.md").read_text(encoding="utf-8")
11009
- original = "Touch is the write boundary for product files;"
11563
+ original = "Touch bounds product writes; the change's own dir is exempt."
11010
11564
  if original not in source:
11011
11565
  report(
11012
11566
  f"{label}: the fixture's anchor sentence is not in the bootstrap; "
@@ -12073,7 +12627,11 @@ def validate_touch_guard_surface_scenario() -> int:
12073
12627
  report(f"touch-guard-surface: README lacks guard guidance: {needle}.")
12074
12628
  return 1
12075
12629
  bootstrap = (ROOT / "assets/bootstrap/AGENTS.md").read_text(encoding="utf-8")
12076
- if "keel guard" not in bootstrap:
12630
+ # The bootstrap must tell a consumer the guard exists and how to opt out;
12631
+ # it no longer spends bytes naming `keel guard clear`, which `keel --help`
12632
+ # and `keel guard status` carry. `--no-guard` is the flag it does name, so
12633
+ # that one stays literal and a rename of it still fails here.
12634
+ if "--no-guard" not in bootstrap or "guards it by default" not in bootstrap:
12077
12635
  report("touch-guard-surface: bootstrap does not mention the guard.")
12078
12636
  return 1
12079
12637
  registered = {name for name, _ in SCENARIOS}
@@ -12452,6 +13010,17 @@ SCENARIOS: tuple = (
12452
13010
  ("runner-skip-accounting", validate_runner_skip_accounting_scenario),
12453
13011
  ("resident-topic-matching", validate_resident_topic_matching_scenario),
12454
13012
  ("task-start-invalidation", validate_task_start_invalidation_scenario),
13013
+ ("regression-check-tag", validate_regression_check_tag_scenario),
13014
+ ("durable-owner-vocabulary", validate_durable_owner_vocabulary_scenario),
13015
+ ("anchor-reverification-bound", validate_anchor_reverification_bound_scenario),
13016
+ (
13017
+ "authoring-surface-owner-and-tags",
13018
+ validate_authoring_surface_owner_and_tags_scenario,
13019
+ ),
13020
+ (
13021
+ "packaged-schema-derivation",
13022
+ validate_packaged_schema_derivation_scenario,
13023
+ ),
12455
13024
  (
12456
13025
  "invalidation-authoring-surface",
12457
13026
  validate_invalidation_authoring_surface_scenario,