@christang/keel 5.169.0 → 5.171.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.169.0",
3
+ "version": "5.171.0",
4
4
  "description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
5
5
  "author": {
6
6
  "name": "TanglmChris",
package/README.md CHANGED
@@ -491,8 +491,11 @@ the words Keel states criteria in, so a tier can only ever skip a file that deci
491
491
  what to skip is a declaration rather than the agent's own call on purpose — "do I need this help?" is
492
492
  the judgement a weak executor gets most wrong, and it would be answering it about itself.
493
493
 
494
- One skill is split today, `keel-run-single-task-goal`, and its body is 11% smaller for it. The other
495
- five are almost entirely criteria, so splitting them would move the half that has to stay.
494
+ Two skills carry a guidance file today. `keel-run-single-task-goal` was split, and its body is 11%
495
+ smaller for it. `keel-tdd-or-test-first` gained one rather than lost prose to it: a table that picks
496
+ a Verify strategy by what would make the Acceptance false, with right and wrong choices and when each
497
+ evidence form pays (#389). The other four are almost entirely criteria, so splitting them would move
498
+ the half that has to stay.
496
499
 
497
500
  ## How the agent uses these
498
501
 
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.169.0 -->
1
+ <!-- keel:start version=5.171.0 -->
2
2
  ## Keel Bootstrap
3
3
 
4
4
  - Start every session with `keel context`; OpenSpec artifacts and Git are the only durable authority — never native memory, goals, or transcripts.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.169.0",
3
+ "version": "5.171.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.169.0",
9
+ "version": "5.171.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@fission-ai/openspec": "^1.4.1"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@christang/keel",
3
3
  "displayName": "Keel",
4
4
  "description": "Keel OpenSpec execution discipline CLI for Claude Code, Codex, and OpenCode.",
5
- "version": "5.169.0",
5
+ "version": "5.171.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.169.0",
3
+ "version": "5.171.0",
4
4
  "description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
5
5
  "author": {
6
6
  "name": "TanglmChris",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.169.0",
3
+ "version": "5.171.0",
4
4
  "description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
5
5
  "author": {
6
6
  "name": "TanglmChris",
@@ -14,7 +14,7 @@ Read the selected task's compiled capsule: resolved Acceptance, Verify strategy
14
14
 
15
15
  ## Strategy selection
16
16
 
17
- `Verify` names one supported strategy chosen at authoring time as the least-cost proof of the resolved Acceptance:
17
+ `Verify` names one supported strategy chosen at authoring time as the least-cost proof of the resolved Acceptance. Choose it by what would make the Acceptance false: the task's size, its apparent risk, the model executing it, and the cost of running a red do not choose it. Read `guidance.md` beside this file before choosing, unless `keel/config.yaml` declares `executor_tier: high` — it holds a selection table, right and wrong choices, and when each evidence form pays. Every criterion is here, so an absent or unreadable declaration costs a read and nothing else.
18
18
 
19
19
  - `vertical-tdd`: new independently testable deterministic behavior; one check red then green at a time.
20
20
  - `regression-first`: an observable defect; reproduce it through the public interface first, then prove the fix with the same check.
@@ -27,6 +27,12 @@ Red-green strategies (`vertical-tdd`, `regression-first`) must record concrete p
27
27
 
28
28
  A check's `Fails with:` declares one literal its red must show. Declare one that every red of the check shares — the scenario or test label the check prints, a stable message prefix — rather than one exception type: a first red is often mixed, mostly one error with a few others, and a literal only some of them carry forces a re-record that predicts nothing new.
29
29
 
30
+ A check's `Detects:` names, as two inline-code literals joined by `->`, a mutation that puts a defect in and the failure it must produce; `keel gate task-complete` requires that failure literal in the check's `.detects` Evidence. It answers what a red cannot — a red shows the feature was absent, not that the check notices it broken — and a `(regression)` check, which has no red, may carry one. Keel neither runs nor judges the mutation.
31
+
32
+ A check's `Measured:` names one inline-code literal that `keel gate task-complete` requires in the check's own `M<n>` Evidence, binding a number to the output it came from. A number nobody declared is not checked.
33
+
34
+ A `(regression)` check asserts that something already green stays green; it owes bare Evidence and no `.red`/`.green`, and a red-green strategy keeps at least one untagged check. Its Evidence may read `deferred to C<n>`, naming a check declared once under `## Change Verify` and recorded under `## Change Evidence` before the change closes.
35
+
30
36
  A check's Evidence may read `artifact <path> sha256:<digest>` instead of retelling the output. `keel gate task-complete` checks the file exists and the digest matches, and refuses a path outside the change's own directory — archiving moves that directory, so a pointer outside it breaks. Keel hashes the bytes and reads nothing inside them: the claim the artifact supports stays yours.
31
37
 
32
38
  ## Domain lenses
@@ -43,7 +49,7 @@ and design disagree, stop and report the gap; do not infer the missing decision.
43
49
 
44
50
  ## TASK boundary
45
51
 
46
- Align every test or check with the selected OpenSpec task's acceptance criteria or verification evidence. Prove behavior through the public interface: evidence that only shows build success or internal shape does not satisfy a behavioral Acceptance, and mocking your own modules invalidates the proof — mock only at true system boundaries.
52
+ Align every test or check with the selected OpenSpec task's acceptance criteria or verification evidence. Prove behavior through the public interface: evidence that only shows build success or internal shape does not satisfy a behavioral Acceptance, and mocking your own modules invalidates the proof — mock only at true system boundaries. A green shows the code matches the check; whether the check matches the Acceptance stays Review's to judge, and a red-green pass does not stand in for timing, CDC, reset, or security evidence a domain lens names.
47
53
 
48
54
  ## Standalone use
49
55
 
@@ -0,0 +1,77 @@
1
+ # keel-tdd-or-test-first — guidance
2
+
3
+ How to pick a strategy and which evidence form fits it. Every criterion is in `SKILL.md`; nothing here
4
+ decides whether a task may start, pass, or complete.
5
+
6
+ ## Choosing from the Acceptance
7
+
8
+ Read the resolved Acceptance and ask what observation would make it false. The answer names the
9
+ strategy:
10
+
11
+ | The Acceptance says… | Strategy | What the first check shows |
12
+ |---|---|---|
13
+ | a defect someone observed is gone | `regression-first` | the defect, reproduced through the public interface before the fix |
14
+ | a new behavior exists that a check can call | `vertical-tdd` | one behavior absent, then present; the next check starts once this one is green |
15
+ | a generated or deterministic output stays as it is | `characterization` | the current output captured, then compared byte for byte |
16
+ | a large or structured output stays as it is | `snapshot-characterization` | a stored snapshot, compared on every run |
17
+ | a measured result does not move — a refactor, a move, a flow upgrade | `equivalence` | the A/B against `Base:` on the declared `Fields:` |
18
+ | an interactive surface behaves | `rendered-behavior` | the real rendered interface, driven the way a user drives it |
19
+ | a document, configuration, or diagnosis exists and says something checkable | `evidence-first` | the artifact or finding itself, named precisely enough to be wrong |
20
+
21
+ Right choices:
22
+
23
+ - "`keel lock release` frees a lease even when its notice cannot be posted" — a release failed in
24
+ front of someone, so `regression-first`, and M1 replays that release.
25
+ - "`keel triage` admits an issue whose number is listed under `issues:`" — new behavior, so
26
+ `vertical-tdd`.
27
+ - "the README names the new flag" — `evidence-first`, with a check that searches the README for the
28
+ flag; there is no earlier state of it that a red would teach anything about.
29
+ - "the moved constraint file gives the same WNS, TNS, and cell count" — `equivalence` against the
30
+ commit before the move.
31
+
32
+ Wrong choices, and why:
33
+
34
+ - `evidence-first` for a new CLI option because a red is slow to run. The option is new behavior; a
35
+ slow red is a cost, and the strategy is about what can fail, not what it costs.
36
+ - `equivalence` for a change that also adds a scenario. New behavior is not unchanged behavior: the
37
+ added part goes in a sibling red-green task, and `equivalence` covers what is meant to stay put.
38
+ - A lighter strategy because the change looks low-risk. Risk sets how many checks are worth writing,
39
+ not whether the ones written can fail.
40
+ - A lighter strategy because a strong model is running the task. A strong executor produces
41
+ confident work; a check that can contradict it is worth more there, not less.
42
+
43
+ ## When a red adds information
44
+
45
+ A red tells you two things a green cannot: the check reaches the behavior at all, and the failure
46
+ it showed is the one the task exists to remove. Both matter most when the code and the check come
47
+ from the same reading of the requirement — a misreading shared by both passes green every time.
48
+
49
+ A red adds nothing when there is no honest one to show: a guard over behavior that is already
50
+ green, a version marker, an output fixed before the task. Those have their own forms below; a red
51
+ staged by breaking the code on purpose and then restoring it records the staging, not the check.
52
+
53
+ ## Which evidence form pays
54
+
55
+ - `Fails with:` — when the red's text is predictable. Declare a literal every red of the check
56
+ shares, such as the scenario label it prints.
57
+ - `Detects:` `mutation` -> `failure` — when a plausible wrong implementation exists that the check
58
+ might not notice: an off-by-one at a boundary, a swapped condition, a guard that reads the wrong
59
+ field. Apply the mutation by hand, run the check, record the failure as `M<n>.detects`, and revert.
60
+ It is the one form a `(regression)` check can use to show it is not vacuous.
61
+ - `Measured:` — when Evidence quotes a number someone will rely on: a count, a size, a timing, a
62
+ slack. The literal ties the number to the output it came from.
63
+ - `(regression)` with `deferred to C<n>` — when several tasks would each rerun the same full suite.
64
+ Declare it once under `## Change Verify` and record it once under `## Change Evidence`.
65
+ - `artifact <path> sha256:<digest>` — when the output is too long to retell. Keep the file inside
66
+ the change directory; the claim it supports is still written in the Evidence.
67
+
68
+ ## A hardware example
69
+
70
+ A synchronous FIFO gains simultaneous read and write at full and at empty. That is new behavior, so
71
+ `vertical-tdd`; the boundary check carries `Detects:` with the mutation "full is computed before the
72
+ read pointer advances" and the failure "the full-and-read case drops a word". A later rename of the
73
+ same FIFO's signals and a move of its pipeline register, keeping cycle behavior, is `equivalence`
74
+ against the commit before it, with the testbench transaction log as `Fields:`.
75
+
76
+ Neither proves timing closure, CDC, reset, or security properties. Those are separate evidence, and
77
+ a matching lens under `keel/lenses/` names them.
@@ -51,8 +51,8 @@ REQUIRED_SCRIPTS = [
51
51
  "scripts/validate_plugin.py",
52
52
  ]
53
53
 
54
- PACKAGE_VERSION = "5.169.0"
55
- PROTOCOL_VERSION = "5.169.0"
54
+ PACKAGE_VERSION = "5.171.0"
55
+ PROTOCOL_VERSION = "5.171.0"
56
56
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
57
57
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
58
58
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -9537,6 +9537,163 @@ def validate_chat_notice_check_scenario() -> int:
9537
9537
  return 0
9538
9538
 
9539
9539
 
9540
+ def validate_chat_dm_long_role_names_scenario() -> int:
9541
+ """Issue #403 (kaiwu-ip, 2026-10-20): two long role names could not share a direct group.
9542
+
9543
+ `dm-<a>--<b>` of two 32-character-at-most role names can be up to 69
9544
+ characters, and the group-name check stopped at 32, so `keel chat dm`
9545
+ between `kaiwu-design-iecc` and `kaiwu-pm-iecc` failed. A direct group's
9546
+ name is valid when it is two different valid role names in sorted order,
9547
+ wherever a group is named, listed or authorized; any other name still
9548
+ follows the role-name pattern.
9549
+ """
9550
+ label = "chat-dm-long-role-names:"
9551
+ group = "dm-kaiwu-design-iecc--kaiwu-pm-iecc"
9552
+ with tempfile.TemporaryDirectory(prefix="keel-chat-403-") as raw:
9553
+ base = Path(raw)
9554
+ design = mailbox_repository(base / "design")
9555
+ pm = chat_worktree(design, base / "pm")
9556
+ env = chat_environment()
9557
+ for cwd, role in ((design, "kaiwu-design-iecc"), (pm, "kaiwu-pm-iecc")):
9558
+ bound = run_keel(cwd, "chat", "role", "--set", role, env=env)
9559
+ if bound.returncode != 0:
9560
+ report(f"{label} could not bind {role}: {bound.stderr!r}")
9561
+ return 1
9562
+
9563
+ def chat(cwd: Path, *args: str) -> subprocess.CompletedProcess[str]:
9564
+ return run_keel(cwd, "chat", *args, env=env)
9565
+
9566
+ sent = chat(design, "dm", "kaiwu-pm-iecc", "lease freed")
9567
+ if sent.returncode != 0:
9568
+ report(f"{label} a direct message between long role names failed: {sent.stderr.strip()!r}")
9569
+ return 1
9570
+ unread = chat(pm, "unread").stdout
9571
+ if "lease freed" not in unread:
9572
+ report(f"{label} kaiwu-pm-iecc does not have the message unread: {unread!r}")
9573
+ return 1
9574
+ peeked = chat(pm, group, "--peek")
9575
+ if peeked.returncode != 0:
9576
+ report(f"{label} `keel chat {group} --peek` failed: {peeked.stderr!r}")
9577
+ return 1
9578
+ if "lease freed" not in peeked.stdout:
9579
+ report(f"{label} `keel chat {group} --peek` does not print the message: {peeked.stdout!r}")
9580
+ return 1
9581
+ listed = chat(pm, "group", "list", "--json")
9582
+ groups = {row["name"]: row for row in json.loads(listed.stdout or "{}").get("groups", [])} if listed.returncode == 0 else {}
9583
+ if not groups.get(group, {}).get("direct"):
9584
+ report(f"{label} group list does not list {group} as direct: {listed.stdout!r} {listed.stderr!r}")
9585
+ return 1
9586
+ for cwd in (design, pm):
9587
+ write_text(cwd / "keel" / "config.yaml", f"authorize:\n - chat-reply:{group}\n")
9588
+ doctor = run_keel(design, "--doctor", env=env).stdout or ""
9589
+ if not re.search(r"chat-reply: authorized.*" + re.escape(group), doctor):
9590
+ report(f"{label} doctor does not read chat-reply:{group}: {[l for l in doctor.splitlines() if 'chat-reply' in l or 'authoriz' in l]!r}")
9591
+ return 1
9592
+ for bad in ("dm-kaiwu-pm-iecc--kaiwu-design-iecc", "Not_A_Group", "x" * 33):
9593
+ refused = chat(design, bad, "--peek")
9594
+ if refused.returncode == 0:
9595
+ report(f"{label} the group name {bad!r} was accepted: {refused.stdout!r}")
9596
+ return 1
9597
+ if "is not a valid name" not in refused.stderr:
9598
+ report(f"{label} the group name {bad!r} was refused, but not as an invalid name: {refused.stderr!r}")
9599
+ return 1
9600
+ if "chat-dm-long-role-names" not in {name for name, _ in SCENARIOS}:
9601
+ report(f"{label} scenario is not registered.")
9602
+ return 1
9603
+ report("chat-dm-long-role-names scenario passed.")
9604
+ return 0
9605
+
9606
+
9607
+ def validate_lock_notice_best_effort_scenario() -> int:
9608
+ """Issue #403 (kaiwu-ip, 2026-10-20): a lease could not be freed while its notice failed.
9609
+
9610
+ Release and the expiry sweep posted to the waiters before removing the
9611
+ lease, so a notice that could not be posted failed the command and kept
9612
+ the lease until a different role's command freed it. A lease is freed
9613
+ first; a notice that cannot be posted is a warning naming the role.
9614
+ """
9615
+ label = "lock-notice-best-effort:"
9616
+ with tempfile.TemporaryDirectory(prefix="keel-lock-403-") as raw:
9617
+ base = Path(raw)
9618
+ a, b, env = chat_scratch_group(base)
9619
+ c = chat_worktree(a, base / "design")
9620
+ d = chat_worktree(a, base / "pm")
9621
+ for tree, role in ((a, "integ"), (b, "sweep"), (c, "kaiwu-design-iecc"), (d, "kaiwu-pm-iecc")):
9622
+ bound = run_keel(tree, "chat", "role", "--set", role, env=env)
9623
+ if bound.returncode != 0:
9624
+ report(f"{label} could not bind {role}: {bound.stderr!r}")
9625
+ return 1
9626
+ lease_file = mailbox_common_dir(a) / "keel-chat" / "locks" / "main-checkout.json"
9627
+
9628
+ def lock(tree: Path, *args: str) -> subprocess.CompletedProcess[str]:
9629
+ return run_keel(tree, "lock", *args, env=env)
9630
+
9631
+ def hold_with_waiter() -> None:
9632
+ for tree, note in ((a, "integration run"), (b, "formal sweep")):
9633
+ lock(tree, "acquire", "main-checkout", "--for", "2h", "--note", note)
9634
+ if "sweep" not in lease_file.read_text():
9635
+ raise RuntimeError(f"sweep was not recorded as a waiter: {lease_file.read_text()!r}")
9636
+
9637
+ # The holder–waiter direct group is archived, so no message can be posted to it.
9638
+ run_keel(a, "chat", "dm", "sweep", "before the archive", env=env)
9639
+ archived = run_keel(a, "chat", "group", "archive", "dm-integ--sweep", env=env)
9640
+ if archived.returncode != 0:
9641
+ report(f"{label} could not archive dm-integ--sweep: {archived.stderr!r}")
9642
+ return 1
9643
+ hold_with_waiter()
9644
+ released = lock(a, "release", "main-checkout")
9645
+ if released.returncode != 0 or lease_file.exists():
9646
+ report(f"{label} a notice that could not be posted kept the lease: exit {released.returncode}, {released.stderr.strip()!r}")
9647
+ return 1
9648
+ if "warning" not in released.stderr or "sweep" not in released.stderr:
9649
+ report(f"{label} release did not warn naming sweep: {released.stderr!r}")
9650
+ return 1
9651
+ listed = lock(b, "list")
9652
+ if listed.returncode != 0:
9653
+ report(f"{label} keel lock list after the release failed: {listed.stderr!r}")
9654
+ return 1
9655
+ if "main-checkout" in listed.stdout:
9656
+ report(f"{label} keel lock list still shows the released lease: {listed.stdout!r}")
9657
+ return 1
9658
+
9659
+ hold_with_waiter()
9660
+ expired = json.loads(lease_file.read_text())
9661
+ expired["expires"] = "2000-01-01T00:00:00+00:00"
9662
+ lease_file.write_text(json.dumps(expired))
9663
+ swept = lock(a, "list")
9664
+ if swept.returncode != 0 or lease_file.exists():
9665
+ report(f"{label} an expired lease whose notice could not be posted was kept: exit {swept.returncode}, {swept.stderr.strip()!r}")
9666
+ return 1
9667
+ if "warning" not in swept.stderr or "sweep" not in swept.stderr:
9668
+ report(f"{label} the expiry sweep did not warn naming sweep: {swept.stderr!r}")
9669
+ return 1
9670
+
9671
+ lock(c, "acquire", "cpu-heavy", "--for", "10m", "--note", "heavy run")
9672
+ lock(d, "acquire", "cpu-heavy", "--for", "10m", "--note", "queued")
9673
+ released = lock(c, "release", "cpu-heavy")
9674
+ if released.returncode != 0:
9675
+ report(f"{label} release between long role names failed: {released.stderr.strip()!r}")
9676
+ return 1
9677
+ if "warning" in released.stderr:
9678
+ report(f"{label} release between long role names warned: {released.stderr.strip()!r}")
9679
+ return 1
9680
+ listed = lock(d, "list")
9681
+ if listed.returncode != 0:
9682
+ report(f"{label} keel lock list after the long-name release failed: {listed.stderr!r}")
9683
+ return 1
9684
+ if "cpu-heavy" in listed.stdout:
9685
+ report(f"{label} keel lock list still shows cpu-heavy after its release: {listed.stdout!r}")
9686
+ return 1
9687
+ if len(chat_records_with(a, "dm-kaiwu-design-iecc--kaiwu-pm-iecc", "lock cpu-heavy released by kaiwu-design-iecc")) != 1:
9688
+ report(f"{label} the waiter kaiwu-pm-iecc was not told of the release.")
9689
+ return 1
9690
+ if "lock-notice-best-effort" not in {name for name, _ in SCENARIOS}:
9691
+ report(f"{label} scenario is not registered.")
9692
+ return 1
9693
+ report("lock-notice-best-effort scenario passed.")
9694
+ return 0
9695
+
9696
+
9540
9697
  def validate_chat_reply_authorization_scenario() -> int:
9541
9698
  """Issue #195: answering in a declared group needs no per-session grant.
9542
9699
 
@@ -41192,7 +41349,7 @@ def validate_guidance_is_referenced_and_carries_no_criterion_scenario() -> int:
41192
41349
  skills_root = ROOT / "src/skills"
41193
41350
  guidance_files = sorted(skills_root.glob("*/guidance.md"))
41194
41351
 
41195
- # D4 splits exactly one skill today. An empty glob would satisfy every loop
41352
+ # Two skills carry one today (#135, #389). An empty glob would satisfy every loop
41196
41353
  # below without reading anything, so the count is asserted first.
41197
41354
  if not guidance_files:
41198
41355
  report(
@@ -41290,6 +41447,70 @@ def validate_guidance_is_referenced_and_carries_no_criterion_scenario() -> int:
41290
41447
  return 0
41291
41448
 
41292
41449
 
41450
+ def validate_tdd_strategy_guide_scenario() -> int:
41451
+ """Issue #389: the skill an executor loads to plan its checks says how to choose.
41452
+
41453
+ The strategy list is read from the parser, not repeated here, so a strategy
41454
+ added later without a selection row fails this scenario instead of passing
41455
+ a list that was never updated. The clauses are the ones the completion gate
41456
+ enforces; before #389 the skill named two of them and `AGENTS.md` the rest.
41457
+ """
41458
+ label = "tdd-strategy-guide"
41459
+ skill_dir = ROOT / "src/skills/keel-tdd-or-test-first"
41460
+ plugin_dir = ROOT / PLUGIN_ROOT / "skills/keel-tdd-or-test-first"
41461
+ guidance = skill_dir / "guidance.md"
41462
+ if not guidance.is_file():
41463
+ report(f"{label}: keel-tdd-or-test-first has no guidance.md beside its SKILL.md.")
41464
+ return 1
41465
+ contract = (ROOT / "src/core/task-contract.js").read_text(encoding="utf-8")
41466
+ declared = re.search(
41467
+ r"const SUPPORTED_VERIFICATION_STRATEGIES = \[(.*?)\];", contract, re.S
41468
+ )
41469
+ if not declared:
41470
+ report(f"{label}: SUPPORTED_VERIFICATION_STRATEGIES not found in task-contract.js.")
41471
+ return 1
41472
+ strategies = re.findall(r'^\s*"([a-z-]+)",', declared.group(1), re.M)
41473
+ if len(strategies) < 7:
41474
+ report(f"{label}: read {len(strategies)} strategies from the parser; expected at least 7.")
41475
+ return 1
41476
+ rows = [
41477
+ line for line in guidance.read_text(encoding="utf-8").splitlines()
41478
+ if line.startswith("|")
41479
+ ]
41480
+ for strategy in strategies:
41481
+ if not any(f"`{strategy}`" in row for row in rows):
41482
+ report(f"{label}: no selection row for {strategy} in the guidance table.")
41483
+ return 1
41484
+ body = (skill_dir / "SKILL.md").read_text(encoding="utf-8")
41485
+ for clause in (
41486
+ "Fails with:",
41487
+ "Detects:",
41488
+ "Measured:",
41489
+ "(regression)",
41490
+ "deferred to C",
41491
+ "artifact",
41492
+ ):
41493
+ if clause not in body:
41494
+ report(f"{label}: the skill body does not name {clause!r}.")
41495
+ return 1
41496
+ if "what would make" not in body:
41497
+ report(f"{label}: the skill body does not say a strategy is chosen by what would make the Acceptance false.")
41498
+ return 1
41499
+ for name in ("SKILL.md", "guidance.md"):
41500
+ shipped = plugin_dir / name
41501
+ if not shipped.is_file():
41502
+ report(f"{label}: the plugin has no keel-tdd-or-test-first/{name}.")
41503
+ return 1
41504
+ if shipped.read_bytes() != (skill_dir / name).read_bytes():
41505
+ report(f"{label}: the plugin's keel-tdd-or-test-first/{name} diverges from the canonical source.")
41506
+ return 1
41507
+ if label not in {name for name, _ in SCENARIOS}:
41508
+ report(f"{label}: the scenario registry does not include it.")
41509
+ return 1
41510
+ report(f"{label} scenario passed.")
41511
+ return 0
41512
+
41513
+
41293
41514
  def equivalence_task(
41294
41515
  *,
41295
41516
  base: str | None = "HEAD~1",
@@ -43176,6 +43397,8 @@ SCENARIOS: tuple = (
43176
43397
  ("shift-restore-authorization", validate_shift_restore_authorization_scenario),
43177
43398
  ("self-shift-authorization", validate_self_shift_authorization_scenario),
43178
43399
  ("resource-lock", validate_resource_lock_scenario),
43400
+ ("chat-dm-long-role-names", validate_chat_dm_long_role_names_scenario),
43401
+ ("lock-notice-best-effort", validate_lock_notice_best_effort_scenario),
43179
43402
  ("chat-supersedes", validate_chat_supersedes_scenario),
43180
43403
  ("chat-mention-skips-code", validate_chat_mention_skips_code_scenario),
43181
43404
  ("two-live-sessions-on-one-role", validate_two_live_sessions_on_one_role_scenario),
@@ -43364,6 +43587,7 @@ SCENARIOS: tuple = (
43364
43587
  "guidance-is-referenced-and-carries-no-criterion",
43365
43588
  validate_guidance_is_referenced_and_carries_no_criterion_scenario,
43366
43589
  ),
43590
+ ("tdd-strategy-guide", validate_tdd_strategy_guide_scenario),
43367
43591
  (
43368
43592
  "a-tier-declares-what-is-skipped",
43369
43593
  validate_a_tier_declares_what_is_skipped_scenario,
@@ -417,7 +417,7 @@ function dispatch(where, options) {
417
417
  const threshold = parseSince(options.since);
418
418
  if (threshold === null) throw new ChatError(`--since ${JSON.stringify(options.since)} is not a time; use 90s, 15m, 2h, 3d, or a date.`);
419
419
  const role = store.requireRole(where);
420
- if (options.group !== null) store.checkName(options.group, "Group");
420
+ if (options.group !== null) store.checkGroup(options.group);
421
421
  const digest = store.summary(where, role, threshold, { group: options.group });
422
422
  const sinceText = store.isoLocal(new Date(threshold));
423
423
  if (options.json) out(JSON.stringify({ since: sinceText, ...digest }));
@@ -116,6 +116,21 @@ function checkName(name, what) {
116
116
  }
117
117
  }
118
118
 
119
+ // A direct group is named for its two sorted roles, so its name can run to
120
+ // 69 characters (#403); any other group name follows the role-name pattern.
121
+ function validGroup(name) {
122
+ if (validName(name)) return true;
123
+ if (typeof name !== "string" || !isDirect(name)) return false;
124
+ const members = name.slice(3).split("--");
125
+ return members.length === 2 && members.every(validName) && members[0] < members[1];
126
+ }
127
+
128
+ function checkGroup(name) {
129
+ if (!validGroup(name)) {
130
+ throw new ChatError(`Group ${JSON.stringify(name)} is not a valid name: use ${NAME_PATTERN_TEXT}, or dm-<role>--<role> with the two roles sorted for a direct group.`);
131
+ }
132
+ }
133
+
119
134
  // --- roles and aliases ------------------------------------------------------
120
135
 
121
136
  function readRoles(root) {
@@ -341,7 +356,7 @@ function groupDir(where, group) {
341
356
 
342
357
  function listGroupNames(where) {
343
358
  try {
344
- return fs.readdirSync(path.join(where.root, "groups")).filter(validName).sort();
359
+ return fs.readdirSync(path.join(where.root, "groups")).filter(validGroup).sort();
345
360
  } catch {
346
361
  return [];
347
362
  }
@@ -513,7 +528,7 @@ function requireSpeaker(group, state, role) {
513
528
  }
514
529
 
515
530
  function createGroup(where, actor, group, members, { direct = false } = {}) {
516
- checkName(group, "Group");
531
+ checkGroup(group);
517
532
  if (RESERVED_GROUPS.has(group)) {
518
533
  throw new ChatError(`Group name ${group} is a keel chat subcommand; choose another.`);
519
534
  }
@@ -620,7 +635,7 @@ function findRecord(where, id) {
620
635
  function post(where, options) {
621
636
  const from = requireRole(where);
622
637
  const group = options.group;
623
- checkName(group, "Group");
638
+ checkGroup(group);
624
639
  const text = String(options.text || "");
625
640
  if (!text.trim()) throw new ChatError("A post needs text: give it after the group, or on stdin.");
626
641
  const { records, state } = loadGroup(where, group);
@@ -879,7 +894,7 @@ const WAIT_FORMS = "`--commit <sha> [--remote <name>]` or `--issue <n> --closed`
879
894
  function wait(where, options) {
880
895
  const from = requireRole(where);
881
896
  const group = options.group;
882
- checkName(group, "Group");
897
+ checkGroup(group);
883
898
  const byCommit = options.commit !== null && options.commit !== undefined;
884
899
  const byIssue = options.issue !== null && options.issue !== undefined;
885
900
  if (byCommit === byIssue) {
@@ -1027,7 +1042,7 @@ function unread(where, role) {
1027
1042
  }
1028
1043
 
1029
1044
  function view(where, role, group, { peek = false } = {}) {
1030
- checkName(group, "Group");
1045
+ checkGroup(group);
1031
1046
  const { records, state } = loadGroup(where, group);
1032
1047
  if (!peek && role && records.length) advanceCursor(where, role, group, records[records.length - 1].id);
1033
1048
  return { records, state };
@@ -1078,11 +1093,13 @@ module.exports = {
1078
1093
  changeMember,
1079
1094
  createGroup,
1080
1095
  currentRole,
1096
+ checkGroup,
1081
1097
  directName,
1082
1098
  directPost,
1083
1099
  findRecord,
1084
1100
  groupState,
1085
1101
  isDirect,
1102
+ validGroup,
1086
1103
  isoLocal,
1087
1104
  listGroups,
1088
1105
  listGroupNames,
@@ -62,10 +62,11 @@ const OPTIONALLY_SCOPED_AUTHORIZATION_ACTIONS = new Set(["push"]);
62
62
  const AUTHORIZATION_SCOPE_PATTERN = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
63
63
 
64
64
  // Each scoped action's form and shape. `chat-reply` names a chat group, whose
65
- // names follow the chat's own pattern (src/core/chat/store.js).
65
+ // names follow the chat's own pattern (src/core/chat/store.js), a direct
66
+ // group's included (#403).
66
67
  const AUTHORIZATION_SCOPES = {
67
68
  issue: { form: "<owner>/<repo>", pattern: AUTHORIZATION_SCOPE_PATTERN },
68
- "chat-reply": { form: "<group>", pattern: /^[a-z0-9][a-z0-9-]{0,31}$/ },
69
+ "chat-reply": { form: "<group>", pattern: /^(?:[a-z0-9][a-z0-9-]{0,31}|dm-[a-z0-9][a-z0-9-]{0,31}--[a-z0-9][a-z0-9-]{0,31})$/ },
69
70
  "issue-close": { form: "<owner>/<repo>", pattern: AUTHORIZATION_SCOPE_PATTERN },
70
71
  cleanup: { form: "scratch", pattern: /^scratch$/ },
71
72
  // Branch-name characters and `*`; `*` matches within one `/` segment and
package/src/core/lock.js CHANGED
@@ -119,25 +119,36 @@ function withMutation(where, action) {
119
119
 
120
120
  // Posts from the running worktree's role to every other role among the
121
121
  // targets. The running role is not messaged: it is the one reading the output.
122
+ // A message that cannot be posted is returned as a warning (#403): the lease
123
+ // is already freed, and a failed notice must not undo that.
122
124
  function notify(where, targets, text) {
123
125
  const from = store.currentRole(where);
124
- if (!from) return;
126
+ if (!from) return [];
127
+ const warnings = [];
125
128
  for (const role of new Set(targets.map((target) => target.role).filter(Boolean))) {
126
- if (role !== from) store.directPost(where, role, text);
129
+ if (role === from) continue;
130
+ try {
131
+ store.directPost(where, role, text);
132
+ } catch (error) {
133
+ if (!(error instanceof store.ChatError)) throw error;
134
+ warnings.push("warning: could not tell " + role + " that " + text + ": " + error.message);
135
+ }
127
136
  }
137
+ return warnings;
128
138
  }
129
139
 
130
140
  // Every freed lease is printed, whether or not anyone was messaged (D4).
131
141
  function reap(where) {
132
142
  const freed = [];
143
+ const warnings = [];
133
144
  for (const lease of readLeases(where)) {
134
145
  if (Date.parse(lease.expires) > Date.now()) continue;
135
146
  const text = "lock " + lease.resource + " expired at " + lease.expires + " (held by " + lease.holder + ": " + lease.note + ")";
136
- notify(where, [lease, ...lease.waiters], text);
137
- freed.push(text);
138
147
  fs.unlinkSync(path.join(lockDir(where), lease.resource + ".json"));
148
+ freed.push(text);
149
+ warnings.push(...notify(where, [lease, ...lease.waiters], text));
139
150
  }
140
- return freed;
151
+ return { freed, warnings };
141
152
  }
142
153
 
143
154
  function acquire(where, resource, expires, note) {
@@ -165,9 +176,8 @@ function release(where, resource) {
165
176
  const lease = readLeases(where).find((row) => row.resource === resource);
166
177
  if (!lease) throw new LockError("No live lease for " + resource + ".");
167
178
  if (lease.holder !== identity(where).holder) throw new LockError("Only " + lease.holder + " can release " + resource + " (" + lease.worktree + ").");
168
- notify(where, lease.waiters, "lock " + resource + " released by " + lease.holder);
169
179
  fs.unlinkSync(path.join(lockDir(where), resource + ".json"));
170
- return lease;
180
+ return { lease, warnings: notify(where, lease.waiters, "lock " + resource + " released by " + lease.holder) };
171
181
  }
172
182
 
173
183
  function runLock(argv) {
@@ -193,10 +203,12 @@ function runLock(argv) {
193
203
  }
194
204
  const where = store.requireLocation(options.repo);
195
205
  return withMutation(where, () => {
196
- for (const text of reap(where)) {
206
+ const reaped = reap(where);
207
+ for (const text of reaped.freed) {
197
208
  // Keep --json parseable, including when a command is later refused.
198
209
  (options.json ? process.stderr : process.stdout).write(text + "\n");
199
210
  }
211
+ for (const warning of reaped.warnings) process.stderr.write("keel lock: " + warning + "\n");
200
212
  if (extra.length || (action === "list" && resource)) throw new LockError("Unexpected argument for " + action + ".");
201
213
  if (action !== "acquire" && (options.duration !== null || options.note !== null)) throw new LockError("--for and --note are only valid for acquire.");
202
214
  const out = (data, text) => process.stdout.write((options.json ? JSON.stringify(data, null, 2) : text) + "\n");
@@ -206,8 +218,9 @@ function runLock(argv) {
206
218
  } else {
207
219
  checkResource(resource);
208
220
  if (action === "release") {
209
- const lease = release(where, resource);
221
+ const { lease, warnings } = release(where, resource);
210
222
  out({ released: lease }, "lock " + resource + " released by " + lease.holder);
223
+ for (const warning of warnings) process.stderr.write("keel lock: " + warning + "\n");
211
224
  } else {
212
225
  if (options.duration === null) throw new LockError("acquire requires --for <duration>.");
213
226
  if (!options.note || !options.note.trim()) throw new LockError("acquire requires a non-empty --note <why>.");