@christang/keel 5.137.0 → 5.139.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.
package/README.md CHANGED
@@ -223,7 +223,10 @@ Declare one entry per glob; `*` matches within one `/` segment and `**` across t
223
223
  other scope, this one is enforced: while any `push:` glob is declared, the Claude write guard checks
224
224
  every `git push` a `Bash` call runs, with or without a task, and refuses one to any other branch, or
225
225
  one whose target it cannot tell — `--all`, `--mirror`, `--tags`, a shell variable, no configured
226
- push destination — naming `git push origin <branch>` instead. A bare `push` keeps its old meaning,
226
+ push destination — naming `git push origin <branch>` instead. A push that also carries annotated
227
+ tags — `--follow-tags`, or `push.followTags` set in git config — is a tag push (#327): no `push:`
228
+ glob allows it, so it is refused naming `--no-follow-tags`, unless every branch it pushes is
229
+ `push-protected`, where it is asked about like any protected push. A bare `push` keeps its old meaning,
227
230
  and declaring it beside a `push:` glob is refused, because it would silently widen the glob. Codex
228
231
  has no such hook, so there the scope is carried, not enforced.
229
232
 
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.137.0 -->
1
+ <!-- keel:start version=5.139.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.137.0",
3
+ "version": "5.139.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.137.0",
9
+ "version": "5.139.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.137.0",
5
+ "version": "5.139.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.137.0",
3
+ "version": "5.139.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.137.0",
3
+ "version": "5.139.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",
@@ -368,8 +368,13 @@ function findPushes(command, cwd) {
368
368
  let cdBefore = false;
369
369
  for (const words of shellSegments(command)) {
370
370
  let i = 0;
371
- while (i < words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i].text)) i += 1;
372
- while (i < words.length && PREFIX_COMMANDS.has(words[i].text)) i += 1;
371
+ const assigned = [];
372
+ while (i < words.length) {
373
+ const assignment = words[i].text.match(/^([A-Za-z_][A-Za-z0-9_]*)=/);
374
+ if (assignment) assigned.push(assignment[1]);
375
+ else if (!PREFIX_COMMANDS.has(words[i].text)) break;
376
+ i += 1;
377
+ }
373
378
  const head = words[i] ? words[i].text : "";
374
379
  if (head === "cd" || head === "pushd") {
375
380
  cdBefore = true;
@@ -385,12 +390,16 @@ function findPushes(command, cwd) {
385
390
  let dir = cwd;
386
391
  i += 1;
387
392
  let unknownGlobal = null;
393
+ let expandedConfig = null;
394
+ const config = [];
388
395
  while (i < words.length && words[i].text.startsWith("-")) {
389
396
  const option = words[i].text;
390
397
  if (option === "-C" && words[i + 1]) {
391
398
  dir = path.resolve(dir, words[i + 1].text);
392
399
  i += 2;
393
400
  } else if (option === "-c" && words[i + 1]) {
401
+ if (words[i + 1].expands) expandedConfig = words[i + 1].text;
402
+ config.push("-c", words[i + 1].text);
394
403
  i += 2;
395
404
  } else if (option === "--no-pager" || option === "-P") {
396
405
  i += 1;
@@ -404,7 +413,18 @@ function findPushes(command, cwd) {
404
413
  pushes.push({ undetermined: `the git option \`${unknownGlobal}\` is not one the guard reads` });
405
414
  continue;
406
415
  }
407
- pushes.push({ dir, cdBefore, args: words.slice(i + 1) });
416
+ if (expandedConfig) {
417
+ pushes.push({ undetermined: `the git config \`-c ${expandedConfig}\` is expanded by the shell` });
418
+ continue;
419
+ }
420
+ // A GIT_CONFIG* assignment can turn on push.followTags for this command
421
+ // only, where the guard cannot read it (#327).
422
+ const configVar = assigned.find((name) => name.startsWith("GIT_CONFIG"));
423
+ if (configVar) {
424
+ pushes.push({ undetermined: `\`${configVar}\` sets git config the guard cannot read` });
425
+ continue;
426
+ }
427
+ pushes.push({ dir, cdBefore, config, args: words.slice(i + 1) });
408
428
  }
409
429
  return pushes;
410
430
  }
@@ -429,6 +449,7 @@ function pushTargets(push) {
429
449
  if (push.undetermined) return push;
430
450
  const positionals = [];
431
451
  let deleting = false;
452
+ let followTags = null;
432
453
  for (let i = 0; i < push.args.length; i += 1) {
433
454
  const word = push.args[i];
434
455
  if (word.expands) return { undetermined: `\`${word.text}\` is expanded by the shell` };
@@ -444,6 +465,8 @@ function pushTargets(push) {
444
465
  const name = text.includes("=") ? text.slice(0, text.indexOf("=")) : text;
445
466
  if (PUSH_UNDETERMINED.has(name)) return { undetermined: `\`${name}\` pushes refs the guard cannot list` };
446
467
  if (name === "-d" || name === "--delete") deleting = true;
468
+ if (name === "--follow-tags") followTags = true;
469
+ if (name === "--no-follow-tags") followTags = false;
447
470
  if (PUSH_VALUED.has(name)) {
448
471
  if (!text.includes("=")) i += 1;
449
472
  continue;
@@ -458,6 +481,14 @@ function pushTargets(push) {
458
481
  }
459
482
  return { undetermined: `the push option \`${text}\` is not one the guard reads` };
460
483
  }
484
+ // A push that carries annotated tags is a tag push (#327). git resolves the
485
+ // config itself, so boolean spellings, key case and `-c` order are its own.
486
+ let tags = null;
487
+ if (followTags === true) tags = "`--follow-tags`";
488
+ else if (followTags === null && gitOut(push.dir,
489
+ [...(push.config || []), "config", "--type=bool", "--get", "push.followTags"]) === "true") {
490
+ tags = "`push.followTags`";
491
+ }
461
492
  const refspecs = positionals.slice(1);
462
493
  const needsCurrent = () => {
463
494
  if (push.cdBefore) return { undetermined: "the directory changes before it, so its branch is unknown here" };
@@ -467,7 +498,7 @@ function pushTargets(push) {
467
498
  const unknown = needsCurrent();
468
499
  if (unknown) return unknown;
469
500
  const branch = pushDestination(push.dir);
470
- return branch ? { targets: [branch] } : { undetermined: "the branch has no configured push destination" };
501
+ return branch ? { targets: [branch], tags } : { undetermined: "the branch has no configured push destination" };
471
502
  }
472
503
  const targets = [];
473
504
  for (const raw of refspecs) {
@@ -486,7 +517,7 @@ function pushTargets(push) {
486
517
  else if (dst.startsWith("refs/")) return { undetermined: `\`${raw}\` is not a branch` };
487
518
  targets.push(dst);
488
519
  }
489
- return { targets };
520
+ return { targets, tags };
490
521
  }
491
522
 
492
523
  function checkPushes(event) {
@@ -495,6 +526,7 @@ function checkPushes(event) {
495
526
  if (!/\bgit\b/.test(command) || !/\bpush\b/.test(command)) return 0;
496
527
  const cwd = typeof event.cwd === "string" && event.cwd ? event.cwd : process.cwd();
497
528
  const asks = [];
529
+ let carriesTags = false;
498
530
  for (const push of findPushes(command, cwd)) {
499
531
  const top = gitOut(push.dir || cwd, ["rev-parse", "--show-toplevel"]);
500
532
  if (!top) continue;
@@ -513,7 +545,20 @@ function checkPushes(event) {
513
545
  );
514
546
  return 0;
515
547
  }
516
- const unlisted = result.targets.filter((branch) => !globs.some((glob) => globPattern(glob).test(branch)));
548
+ // A push carrying tags passes on no `push:` glob; only a protected
549
+ // branch's ask can carry it, so each branch must be a protected one.
550
+ if (result.tags && !result.targets.every((b) => protectedEntries.some((e) => globPattern(e.glob).test(b)))) {
551
+ deny(
552
+ `Keel push guard: this push also pushes annotated tags (${result.tags}), and `
553
+ + `keel/config.yaml limits push to ${declared}; no \`push:\` grant covers tags. Push the `
554
+ + "branch alone with `--no-follow-tags`, or ask the owner to publish the tags."
555
+ );
556
+ return 0;
557
+ }
558
+ if (result.tags) carriesTags = true;
559
+ const unlisted = result.tags
560
+ ? result.targets
561
+ : result.targets.filter((branch) => !globs.some((glob) => globPattern(glob).test(branch)));
517
562
  const outside = [];
518
563
  for (const branch of unlisted) {
519
564
  const entry = protectedEntries.find((e) => globPattern(e.glob).test(branch));
@@ -554,9 +599,10 @@ function checkPushes(event) {
554
599
  );
555
600
  return 0;
556
601
  }
602
+ const tagNote = carriesTags ? " This push also pushes annotated tags (`--follow-tags` or `push.followTags`)." : "";
557
603
  ask(
558
604
  `Keel push guard: ${branches} is a protected branch (keel/config.yaml `
559
- + "push-protected). Confirm only if the user approves this one push; the next push asks again."
605
+ + `push-protected).${tagNote} Confirm only if the user approves this one push; the next push asks again.`
560
606
  );
561
607
  }
562
608
  return 0;
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
47
47
  "scripts/validate_plugin.py",
48
48
  ]
49
49
 
50
- PACKAGE_VERSION = "5.137.0"
51
- PROTOCOL_VERSION = "5.137.0"
50
+ PACKAGE_VERSION = "5.139.0"
51
+ PROTOCOL_VERSION = "5.139.0"
52
52
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
53
53
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
54
54
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -6965,6 +6965,96 @@ def validate_shift_await_clear_scenario() -> int:
6965
6965
  return 0
6966
6966
 
6967
6967
 
6968
+ def validate_chat_park_role_scenario() -> int:
6969
+ """A role parked on purpose is left alone, and posters are told (#316).
6970
+
6971
+ `keel chat role --park` records the park; posts naming the role say it is
6972
+ parked; the patrol neither nudges it nor reports it; `--unpark` summarizes
6973
+ what waited; a session running as the role ends the park (chat-park-role
6974
+ D1-D5).
6975
+ """
6976
+ label = "chat-park-role:"
6977
+ with tempfile.TemporaryDirectory(prefix="keel-chat-park-role-") as raw:
6978
+ base = Path(raw)
6979
+ rtl, verify, env, _ = shift_scratch(base)
6980
+ run_keel(rtl, "chat", "group", "create", "soc", "verify", env=env)
6981
+ ghost = run_keel(rtl, "chat", "role", "--park", "ghost", env=env)
6982
+ if ghost.returncode == 0:
6983
+ report(f"{label} parking an unbound role was accepted: {ghost.stdout.strip()}")
6984
+ return 1
6985
+ run_keel(rtl, "chat", "post", "soc", "@verify please rerun R007", env=env)
6986
+ time.sleep(1.2)
6987
+ parked = run_keel(rtl, "chat", "role", "--park", "verify", "--reason", "until R040", env=env)
6988
+ made = run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "R041 rerun", env=env)
6989
+ if made.returncode != 0:
6990
+ report(f"{label} a todo for a parked role failed: {made.stderr.strip()}")
6991
+ return 1
6992
+ if "verify is parked" not in made.stdout:
6993
+ report(f"{label} a todo for a parked role does not say verify is parked: {made.stdout.strip()} (--park: {parked.stderr.strip() or parked.stdout.strip()})")
6994
+ return 1
6995
+ if "until R040" not in made.stdout:
6996
+ report(f"{label} a todo for a parked role does not give the reason: {made.stdout.strip()}")
6997
+ return 1
6998
+ as_json = run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "R042 rerun", "--json", env=env)
6999
+ entries = json.loads(as_json.stdout).get("parked") if as_json.returncode == 0 else None
7000
+ if not entries or entries[0].get("role") != "verify" or entries[0].get("reason") != "until R040":
7001
+ report(f"{label} --json does not carry parked: {as_json.stdout.strip()}")
7002
+ return 1
7003
+
7004
+ def patrol() -> subprocess.CompletedProcess[str]:
7005
+ return run_keel(rtl, "patrol", "--nudge", "--idle", "1s", env=env)
7006
+
7007
+ for attempt in (1, 2):
7008
+ time.sleep(1.2)
7009
+ run = patrol()
7010
+ lines = run.stdout.splitlines()
7011
+ if any(line.startswith("nudged verify") for line in lines):
7012
+ report(f"{label} patrol run {attempt} nudged the parked role: {run.stdout.strip()}")
7013
+ return 1
7014
+ if any(line.startswith(("risk:", "drift:")) and "verify" in line for line in lines):
7015
+ report(f"{label} patrol run {attempt} reported the parked role: {run.stdout.strip()}")
7016
+ return 1
7017
+ if not any(line.startswith("role verify:") and "parked" in line for line in lines):
7018
+ report(f"{label} patrol run {attempt} does not show verify as parked: {run.stdout.strip()}")
7019
+ return 1
7020
+ unparked = run_keel(rtl, "chat", "role", "--unpark", "verify", env=env)
7021
+ if unparked.returncode != 0:
7022
+ report(f"{label} --unpark failed: {unparked.stderr.strip()}")
7023
+ return 1
7024
+ if "waited" not in unparked.stdout:
7025
+ report(f"{label} --unpark does not report what waited: {unparked.stdout.strip()}")
7026
+ return 1
7027
+ time.sleep(1.2)
7028
+ after = patrol()
7029
+ if "nudged verify: unread" not in after.stdout:
7030
+ report(f"{label} after --unpark the patrol did not nudge verify: {after.stdout.strip()}")
7031
+ return 1
7032
+ plain = run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "R043 rerun", env=env)
7033
+ if "parked" in plain.stdout:
7034
+ report(f"{label} a todo after --unpark still says parked: {plain.stdout.strip()}")
7035
+ return 1
7036
+ run_keel(rtl, "chat", "role", "--park", "verify", env=env)
7037
+ time.sleep(1.2)
7038
+ subprocess.run(
7039
+ ["node", str(ROOT / "bin" / "keel.js"), "chat", "hook", "session-start"],
7040
+ cwd=verify, env=env, text=True, capture_output=True, check=False,
7041
+ input=json.dumps({"cwd": str(verify), "hook_event_name": "SessionStart", "source": "startup"}),
7042
+ )
7043
+ resumed = run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "R044 rerun", env=env)
7044
+ if "parked" in resumed.stdout:
7045
+ report(f"{label} a session running as verify did not end the park: {resumed.stdout.strip()}")
7046
+ return 1
7047
+ for relative in ("docs/chat-slack-setup.md", "docs/chat-slack-setup.zh-CN.md"):
7048
+ if "--park" not in (ROOT / relative).read_text(encoding="utf-8"):
7049
+ report(f"{label} {relative} does not mention --park.")
7050
+ return 1
7051
+ if "chat-park-role" not in {name for name, _ in SCENARIOS}:
7052
+ report(f"{label} scenario is not registered.")
7053
+ return 1
7054
+ report("chat-park-role scenario passed.")
7055
+ return 0
7056
+
7057
+
6968
7058
  def validate_chat_wake_idle_desktop_scenario() -> int:
6969
7059
  """A record for an idle desktop session names the step that wakes it (#331).
6970
7060
 
@@ -32074,6 +32164,111 @@ def validate_push_guard_redirects_scenario() -> int:
32074
32164
  return 0
32075
32165
 
32076
32166
 
32167
+ def validate_push_guard_follow_tags_scenario() -> int:
32168
+ """Issue #327: a push that carries annotated tags is a tag push.
32169
+
32170
+ The real hook denies `--follow-tags`, `push.followTags` from the repository
32171
+ config or `git -c`, and a `GIT_CONFIG*` assignment on a `push:` branch;
32172
+ turning tag carriage off restores the branch push; a protected branch is
32173
+ asked about with its tags; and nothing is checked without a push scope.
32174
+ """
32175
+ label = "push-guard-follow-tags:"
32176
+ with tempfile.TemporaryDirectory(prefix="keel-push-follow-tags-") as raw:
32177
+ base = Path(raw)
32178
+ repo = mailbox_repository(base / "repo")
32179
+ pm = chat_worktree(repo, base / "pm")
32180
+ rtl = chat_worktree(repo, base / "rtl")
32181
+ env = chat_environment()
32182
+ run_keel(pm, "chat", "role", "--set", "iecc-pm", env=env)
32183
+ run_keel(rtl, "chat", "role", "--set", "rtl", env=env)
32184
+ hook_env = {
32185
+ k: v for k, v in os.environ.items()
32186
+ if k not in ("KEEL_CHAT_ROLE", "KEEL_MAIL_ROLE") and not k.startswith("GIT_CONFIG")
32187
+ }
32188
+ hook_env["CLAUDE_PLUGIN_ROOT"] = str(ROOT / PLUGIN_ROOT)
32189
+
32190
+ def declare(entries: list[str]) -> None:
32191
+ for cwd in (pm, rtl):
32192
+ write_authorize_config(cwd, "authorize:\n" + "".join(f" - {e}\n" for e in entries))
32193
+
32194
+ def decide(cwd: Path, command: str) -> dict:
32195
+ event = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": str(cwd), "permission_mode": "default"}
32196
+ result = subprocess.run(
32197
+ ["node", str(ROOT / PLUGIN_ROOT / "scripts/pretooluse-guard.js")],
32198
+ cwd=cwd, env=hook_env, input=json.dumps(event), text=True, capture_output=True, check=False,
32199
+ )
32200
+ return pretooluse_decision(result) or {"permissionDecision": "pass"}
32201
+
32202
+ def expect(what: str, cwd: Path, command: str, want: str, needles: tuple[str, ...] = ()) -> bool:
32203
+ decision = decide(cwd, command)
32204
+ if decision.get("permissionDecision") != want:
32205
+ verdict = "allowed" if decision.get("permissionDecision") == "pass" else decision.get("permissionDecision")
32206
+ report(f"{label} {what} was {verdict}, not {want} ({command!r}): {decision!r}")
32207
+ return False
32208
+ reason = decision.get("permissionDecisionReason", "")
32209
+ for needle in needles:
32210
+ if needle not in reason:
32211
+ report(f"{label} {what} does not name {needle!r}: {reason!r}")
32212
+ return False
32213
+ return True
32214
+
32215
+ def set_follow_tags(value: str | None) -> None:
32216
+ args = ["config", "push.followTags", value] if value else ["config", "--unset", "push.followTags"]
32217
+ subprocess.run(["git", *args], cwd=rtl, check=False, capture_output=True)
32218
+
32219
+ declare(["push:flow-*"])
32220
+ branch = "origin flow-release"
32221
+ if not expect("--follow-tags push to a granted branch", rtl, f"git push --follow-tags {branch}", "deny",
32222
+ ("--follow-tags", "--no-follow-tags")):
32223
+ report(f"{label} --follow-tags push to a granted branch was allowed")
32224
+ return 1
32225
+ if not expect("--follow-tags undone by --no-follow-tags", rtl,
32226
+ f"git push --follow-tags --no-follow-tags {branch}", "pass"):
32227
+ return 1
32228
+ if not expect("a plain push to a granted branch", rtl, f"git push {branch}", "pass"):
32229
+ return 1
32230
+ if not expect("git -c push.followTags=true", rtl, f"git -c push.followTags=true push {branch}", "deny",
32231
+ ("push.followTags",)):
32232
+ return 1
32233
+ set_follow_tags("true")
32234
+ if not expect("a plain push under push.followTags=true", rtl, f"git push {branch}", "deny", ("push.followTags",)):
32235
+ return 1
32236
+ if not expect("git -c push.followTags=false over the config", rtl,
32237
+ f"git -c push.followTags=false push {branch}", "pass"):
32238
+ return 1
32239
+ set_follow_tags(None)
32240
+ if not expect("a GIT_CONFIG_COUNT assignment", rtl,
32241
+ f"GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=push.followTags GIT_CONFIG_VALUE_0=true git push {branch}",
32242
+ "deny", ("GIT_CONFIG_COUNT",)):
32243
+ return 1
32244
+
32245
+ if not expect("a GIT_CONFIG_COUNT assignment behind env", rtl,
32246
+ f"env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=push.followTags GIT_CONFIG_VALUE_0=true git push {branch}",
32247
+ "deny", ("GIT_CONFIG_COUNT",)):
32248
+ return 1
32249
+ if not expect("a shell-expanded git -c", rtl, f'git -c "$CFG" push {branch}', "deny", ("expanded",)):
32250
+ return 1
32251
+ if not expect("a push to main behind `env FOO=1`", rtl, "env FOO=1 git push origin main", "deny", ("`main`",)):
32252
+ return 1
32253
+
32254
+ declare(["push:flow-*", "push-protected:main@iecc-pm"])
32255
+ if not expect("the coordinator's --follow-tags push to main", pm, "git push --follow-tags origin main", "ask",
32256
+ ("`main`", "annotated tags")):
32257
+ return 1
32258
+ if not expect("another role's --follow-tags push to main", rtl, "git push --follow-tags origin main", "deny",
32259
+ ("iecc-pm",)):
32260
+ return 1
32261
+ if not expect("a --follow-tags push to a granted branch beside a protected one", pm,
32262
+ f"git push --follow-tags {branch}", "deny", ("--no-follow-tags",)):
32263
+ return 1
32264
+
32265
+ declare(["commit"])
32266
+ if not expect("a --follow-tags push with no push scope", rtl, f"git push --follow-tags {branch}", "pass"):
32267
+ return 1
32268
+ report("push-guard-follow-tags scenario passed.")
32269
+ return 0
32270
+
32271
+
32077
32272
  def validate_touch_write_guard_scenario() -> int:
32078
32273
  with tempfile.TemporaryDirectory(
32079
32274
  prefix="keel-touch-guard-", ignore_cleanup_errors=True
@@ -40822,6 +41017,7 @@ SCENARIOS: tuple = (
40822
41017
  ("shift-desktop-wake-overdue", validate_shift_desktop_wake_overdue_scenario),
40823
41018
  ("shift-start-desktop", validate_shift_start_desktop_scenario),
40824
41019
  ("chat-wake-idle-desktop", validate_chat_wake_idle_desktop_scenario),
41020
+ ("chat-park-role", validate_chat_park_role_scenario),
40825
41021
  ("shift-await-clear", validate_shift_await_clear_scenario),
40826
41022
  ("shift-restore-authorization", validate_shift_restore_authorization_scenario),
40827
41023
  ("self-shift-authorization", validate_self_shift_authorization_scenario),
@@ -40857,6 +41053,7 @@ SCENARIOS: tuple = (
40857
41053
  ("touch-write-guard", validate_touch_write_guard_scenario),
40858
41054
  ("push-branch-guard", validate_push_branch_guard_scenario),
40859
41055
  ("push-guard-redirects", validate_push_guard_redirects_scenario),
41056
+ ("push-guard-follow-tags", validate_push_guard_follow_tags_scenario),
40860
41057
  ("push-protected-guard", validate_push_protected_guard_scenario),
40861
41058
  ("touch-guard-record-layer", validate_touch_guard_record_layer_scenario),
40862
41059
  ("repo-action-mode", validate_repo_action_mode_scenario),
@@ -16,6 +16,7 @@ const { ChatError } = store;
16
16
 
17
17
  const USAGE = [
18
18
  "keel chat role [--set <name>] [--alias <alias>] [--prune] [--json] (--prune: drop bindings to removed worktrees)",
19
+ "keel chat role --park <role> [--reason <text>] | --unpark <role> (a role parked on purpose is not nudged or reported by the patrol)",
19
20
  "keel chat group create <group> [--member <role>]...",
20
21
  "keel chat group add|remove <group> <role> [--listen] (--listen: receives the group, may ack and close its todos, does not post)",
21
22
  "keel chat group archive <group>",
@@ -57,6 +58,9 @@ const USAGE = [
57
58
  const VALUED = {
58
59
  "--set": "set",
59
60
  "--alias": "alias",
61
+ "--park": "park",
62
+ "--unpark": "unpark",
63
+ "--reason": "reason",
60
64
  "--reply-to": "replyTo",
61
65
  "--supersedes": "supersedes",
62
66
  "--not-a-loop": "notALoop",
@@ -180,19 +184,60 @@ function offlineMentions(where, record) {
180
184
  // A woken role whose desktop session has no running process reads nothing
181
185
  // until something resumes it (#331 D3), so the poster is given the step.
182
186
  function asleepTargets(where, record) {
187
+ return wokenRoles(where, record).map((role) => notice.asleep(where, role)).filter(Boolean);
188
+ }
189
+
190
+ function wokenRoles(where, record) {
183
191
  const bound = Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean);
184
192
  const candidates = [...new Set([...bound, ...(record.mentions || []), ...(record.assignee ? [record.assignee] : [])])];
185
- return candidates.filter((role) => store.wakes(record, role)).sort().map((role) => notice.asleep(where, role)).filter(Boolean);
193
+ return candidates.filter((role) => store.wakes(record, role)).sort();
194
+ }
195
+
196
+ function boundRoles(where) {
197
+ return new Set(Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean));
198
+ }
199
+
200
+ // `keel chat role --park/--unpark` (#316 D1, D3).
201
+ function runPark(where, options) {
202
+ if (options.park !== null && options.unpark !== null) throw new ChatError("Give --park or --unpark, not both.");
203
+ const role = options.park !== null ? options.park : options.unpark;
204
+ if (options.park !== null) {
205
+ if (!boundRoles(where).has(role)) {
206
+ throw new ChatError(`No worktree is bound to ${role}, so there is nothing to park; \`keel chat role\` in its worktree shows its name.`);
207
+ }
208
+ const record = notice.park(where, role, store.currentRole(where), options.reason);
209
+ if (options.json) out(JSON.stringify(record));
210
+ else out(`Parked ${role}${options.reason ? `: ${options.reason}` : ""}. The patrol leaves it alone and posters are told, until \`keel chat role --unpark ${role}\` or its session runs again.`);
211
+ return 0;
212
+ }
213
+ const removed = notice.unpark(where, role);
214
+ const waiting = store.unread(where, role).filter((record) => store.wakes(record, role)).sort((a, b) => (a.id < b.id ? -1 : 1));
215
+ if (options.json) {
216
+ out(JSON.stringify({ role, unparked: removed, waiting: waiting.length, since: waiting.length ? waiting[0].created : null }));
217
+ return 0;
218
+ }
219
+ const head = removed ? `Unparked ${role}.` : `${role} was not parked.`;
220
+ out(waiting.length
221
+ ? `${head} ${waiting.length} addressed record(s) waited since ${waiting[0].created}; ${role} reads them with \`keel chat unread\`.`
222
+ : `${head} Nothing addressed to it waited.`);
223
+ return 0;
186
224
  }
187
225
 
188
226
  function postResult(where, record, json) {
189
- const asleep = asleepTargets(where, record);
190
- const offline = offlineMentions(where, record).filter((role) => !asleep.some((entry) => entry.role === role));
227
+ const parked = wokenRoles(where, record).map((role) => notice.parkOf(where, role)).filter(Boolean);
228
+ const isParked = (role) => parked.some((entry) => entry.role === role);
229
+ const asleep = asleepTargets(where, record).filter((entry) => !isParked(entry.role));
230
+ const offline = offlineMentions(where, record).filter((role) => !isParked(role) && !asleep.some((entry) => entry.role === role));
191
231
  if (json) {
192
- out(JSON.stringify({ id: record.id, group: record.group, from: record.from, mentions: record.mentions, offline, asleep }));
232
+ out(JSON.stringify({ id: record.id, group: record.group, from: record.from, mentions: record.mentions, offline, asleep, parked }));
193
233
  return;
194
234
  }
195
235
  const lines = [`Posted ${record.id} to ${record.group}.`];
236
+ // A parked role is told nothing new by the post; the poster is (#316 D5).
237
+ for (const entry of parked) {
238
+ lines.push(`${entry.role} is parked since ${entry.at}${entry.by ? ` by ${entry.by}` : ""}${entry.reason ? `: ${entry.reason}` : ""}; `
239
+ + "this waits until it is unparked or its session runs again — route anything urgent through the coordinator.");
240
+ }
196
241
  for (const role of offline) lines.push(`Queued for ${role}: offline; it will see this when its session next starts.`);
197
242
  for (const entry of asleep) {
198
243
  lines.push(`${entry.role}'s desktop session ${entry.session} has no running process, so this record alone wakes nothing (#331). `
@@ -299,6 +344,7 @@ function dispatch(where, options) {
299
344
  const [command, ...rest] = options.positionals;
300
345
  switch (command) {
301
346
  case "role": {
347
+ if (options.park !== null || options.unpark !== null) return runPark(where, options);
302
348
  if (options.prune) {
303
349
  // Bindings to removed worktrees (#301 D4).
304
350
  const pruned = require("./drift").pruneBindings(where);
@@ -37,10 +37,12 @@ function removedBindings(where) {
37
37
  }
38
38
 
39
39
  function roleDrift(where, now = Date.now()) {
40
- const { presenceFile } = require("./notice");
40
+ const { presenceFile, parkOf } = require("./notice");
41
41
  const roles = [...new Set(Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean))].sort();
42
42
  const unattended = [];
43
43
  for (const role of roles) {
44
+ // A role parked on purpose is not unattended (#316 D4).
45
+ if (parkOf(where, role)) continue;
44
46
  const waiting = [];
45
47
  let unread = [];
46
48
  try {
@@ -135,6 +135,35 @@ function wakeStep(session, text) {
135
135
  + `then call \`send_message\` to \`${session}\` with ${JSON.stringify(text)}.`;
136
136
  }
137
137
 
138
+ // --- parked roles (#316) ------------------------------------------------------------
139
+
140
+ function parkFile(where, role) {
141
+ return path.join(where.root, "parked", `${role}.json`);
142
+ }
143
+
144
+ function park(where, role, by, reason) {
145
+ const record = { role, reason: reason || null, by: by || null, at: new Date().toISOString() };
146
+ store.writeJsonAtomic(where, parkFile(where, role), record);
147
+ return record;
148
+ }
149
+
150
+ function unpark(where, role) {
151
+ const file = parkFile(where, role);
152
+ const existed = fs.existsSync(file);
153
+ fs.rmSync(file, { force: true });
154
+ return existed;
155
+ }
156
+
157
+ // A park is in effect until a session runs as the role after it (D2).
158
+ function parkOf(where, role) {
159
+ const record = store.readJsonFile(parkFile(where, role));
160
+ const at = Date.parse(record.at || "");
161
+ if (Number.isNaN(at)) return null;
162
+ const last = Date.parse(store.readJsonFile(presenceFile(where, role)).last_active || "");
163
+ if (!Number.isNaN(last) && last > at) return null;
164
+ return { role, at: store.isoLocal(new Date(at)), by: record.by || null, reason: record.reason || null };
165
+ }
166
+
138
167
  const ONLINE_WINDOW_MS = 24 * 60 * 60 * 1000;
139
168
 
140
169
  // `online`, `idle`, or `offline`, with the time of last activity (D10).
@@ -418,6 +447,9 @@ function check(cwd) {
418
447
  module.exports = {
419
448
  NOTICE_LIMIT,
420
449
  asleep,
450
+ park,
451
+ parkOf,
452
+ unpark,
421
453
  wakeStep,
422
454
  check,
423
455
  bridgeLine,
@@ -91,6 +91,7 @@ function patrol(where, role, options) {
91
91
  presence: presence.state,
92
92
  lastActive: presence.last_active,
93
93
  idle: Number.isNaN(last) || last < threshold,
94
+ parked: Boolean(notice.parkOf(where, name)),
94
95
  openTodos: store.openTodos(where, { assignee: name }).length,
95
96
  });
96
97
  }
@@ -155,7 +156,7 @@ function currentSnapshot(where, role, result, options) {
155
156
  // Free disk as the host measured it (#307 part 3 D1).
156
157
  if (options.diskFreeGb !== null) entries.disk = options.diskFreeGb < options.diskMinGb ? "low" : "ok";
157
158
  for (const row of result.roles) {
158
- entries[`role ${row.role}`] = `${row.idle ? "idle" : "active"}, ${row.openTodos} open todo${row.openTodos === 1 ? "" : "s"}`;
159
+ entries[`role ${row.role}`] = `${row.parked ? "parked" : row.idle ? "idle" : "active"}, ${row.openTodos} open todo${row.openTodos === 1 ? "" : "s"}`;
159
160
  }
160
161
  const threshold = parseSince(options.idle);
161
162
  const unread = store.unread(where, role)
@@ -244,6 +245,8 @@ function nudgeRoles(where, patroller, options) {
244
245
  .filter((role) => role !== patroller).sort();
245
246
  const closures = closedTodos(where);
246
247
  for (const role of roles) {
248
+ // A role parked on purpose is left alone, its state kept (#316 D4).
249
+ if (notice.parkOf(where, role)) continue;
247
250
  // The first look only records the tasks already closed (#313 D1).
248
251
  if (!state[role] || !Array.isArray(state[role].closedSeen)) {
249
252
  state[role] = { ...(state[role] || {}), closedSeen: (closures.get(role) || []).map((entry) => entry.done) };
@@ -351,7 +354,7 @@ function render(result) {
351
354
  for (const line of result.sinceLast ? [] : result.drift) lines.push(`drift: ${line.text}`);
352
355
  // A scheduled run reports roles only through what changed (D1).
353
356
  for (const row of result.sinceLast ? [] : result.roles) {
354
- lines.push(`role ${row.role}: ${row.presence}${row.idle ? " (idle)" : ""}, last active ${row.lastActive || "unknown"}, ${row.openTodos} open todo${row.openTodos === 1 ? "" : "s"}`);
357
+ lines.push(`role ${row.role}: ${row.presence}${row.idle ? " (idle)" : ""}${row.parked ? ", parked" : ""}, last active ${row.lastActive || "unknown"}, ${row.openTodos} open todo${row.openTodos === 1 ? "" : "s"}`);
355
358
  }
356
359
  return lines.join("\n");
357
360
  }