@christang/keel 5.148.0 → 5.150.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.148.0",
3
+ "version": "5.150.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
@@ -842,15 +842,16 @@ keel patrol --issues /tmp/issues.json # as the coordinator's role
842
842
  as met and sends the waiting role one direct message, which wakes it. It lists every role's
843
843
  presence, last activity, and open todos, marking those idle beyond `--idle` (default `30m`). It
844
844
  fetches nothing, schedules nothing, calls no model, and writes nothing when nothing is new; it exits
845
- 0 then, 2 when it sent something, and 1 on an error, so a cheap scheduler — cron, `/loop`, CI — can
846
- wake the model only on 2. `keel chat waits` lists what is still awaited.
845
+ 0 then, 2 when the coordinator has something to act on — a risk, or its own wait met — 3 when it only
846
+ recorded something or told other roles, and 1 on an error, so a cheap scheduler — cron, `/loop`, CI —
847
+ can wake the model only on 2 (#350). `keel chat waits` lists what is still awaited.
847
848
 
848
849
  A patrol on an hourly schedule should report change, not state, or it wakes the coordinator every
849
850
  hour for a note deliberately left parked (#295). `keel patrol --since-last` keeps a snapshot per role
850
851
  — shift status, the remote default branch tip, the main checkout's uncommitted paths, each role's
851
852
  idleness and open todos, and the coordinator's addressed records unread beyond `--idle` — and prints
852
853
  only `changed:` lines for what differs from the previous run; the first run records a baseline. It
853
- writes that snapshot on every run, and exits 2 only when something changed. Add `--notify` and the
854
+ writes that snapshot on every run, and exits 3 when something changed and 2 only when a risk did. Add `--notify` and the
854
855
  coordinator gets one direct message from `keel-patrol`, which wakes its session, carrying only risks
855
856
  (#307): the shared checkout gaining uncommitted paths after a clean run, free disk the host reports with
856
857
  `--disk-free-gb` dropping below `--disk-min-gb` (default 20), and a role that left two nudges in a row
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.148.0 -->
1
+ <!-- keel:start version=5.150.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.148.0",
3
+ "version": "5.150.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.148.0",
9
+ "version": "5.150.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.148.0",
5
+ "version": "5.150.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.148.0",
3
+ "version": "5.150.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.148.0",
3
+ "version": "5.150.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",
@@ -49,8 +49,8 @@ REQUIRED_SCRIPTS = [
49
49
  "scripts/validate_plugin.py",
50
50
  ]
51
51
 
52
- PACKAGE_VERSION = "5.148.0"
53
- PROTOCOL_VERSION = "5.148.0"
52
+ PACKAGE_VERSION = "5.150.0"
53
+ PROTOCOL_VERSION = "5.150.0"
54
54
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
55
55
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
56
56
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -2450,6 +2450,57 @@ def chat_scratch_group(base: Path) -> tuple[Path, Path, dict[str, str]]:
2450
2450
  return rtl, verify, env
2451
2451
 
2452
2452
 
2453
+ def validate_chat_mention_skips_code_scenario() -> int:
2454
+ """Issue #345: `keel chat post` refused a whole message over `@<commit-id>`
2455
+ or an `@word` inside backticks.
2456
+
2457
+ The refusal exists so a typo cannot post a message that reaches nobody;
2458
+ a commit id (`branch @ 638059e4`) and quoted text are not mentions.
2459
+ """
2460
+ label = "chat-mention-skips-code:"
2461
+ with tempfile.TemporaryDirectory(prefix="keel-chat-345-") as raw:
2462
+ base = Path(raw)
2463
+ rtl, _verify, env = chat_scratch_group(base)
2464
+
2465
+ def post(text: str) -> subprocess.CompletedProcess[str]:
2466
+ return run_keel(rtl, "chat", "post", "soc", text, "--json", env=env)
2467
+
2468
+ for name, text in (
2469
+ ("commit-id", "main moved: claude/x @638059e4 waiting for the push window"),
2470
+ ("long-commit-id", "landed @638059e4c0ffee1234567890abcdef12345678"),
2471
+ ("inline-code", "write it as `@verifyy` in the note"),
2472
+ ("fenced", "example:\n```\nkeel chat post soc @nobody hi\n```\nthat is all"),
2473
+ ):
2474
+ result = post(text)
2475
+ if result.returncode != 0:
2476
+ report(f"{label} a post with {name} was refused: {result.stdout!r} {result.stderr!r}")
2477
+ return 1
2478
+ mentions = chat_json(result).get("mentions", [])
2479
+ if mentions:
2480
+ report(f"{label} a post with {name} recorded mentions {mentions!r}.")
2481
+ return 1
2482
+
2483
+ typo = post("@verifyy please check")
2484
+ if typo.returncode == 0:
2485
+ report(f"{label} a bare typo is no longer refused: {typo.stdout!r}")
2486
+ return 1
2487
+ if "@verifyy is not a member" not in typo.stderr:
2488
+ report(f"{label} a bare typo's refusal does not name it: {typo.stderr!r}")
2489
+ return 1
2490
+ real = post("`@nobody` is quoted, @verify is asked")
2491
+ if real.returncode != 0:
2492
+ report(f"{label} a real mention beside quoted text was refused: {real.stderr!r}")
2493
+ return 1
2494
+ if chat_json(real).get("mentions") != ["verify"]:
2495
+ report(f"{label} a real mention beside quoted text was not recorded alone: {real.stdout!r}")
2496
+ return 1
2497
+ if "chat-mention-skips-code" not in {name for name, _ in SCENARIOS}:
2498
+ report(f"{label} scenario is not registered.")
2499
+ return 1
2500
+ report("chat-mention-skips-code scenario passed.")
2501
+ return 0
2502
+
2503
+
2453
2504
  def validate_chat_supersedes_scenario() -> int:
2454
2505
  """Issue #252: a record supersedes its author's earlier one.
2455
2506
 
@@ -2807,7 +2858,7 @@ def validate_patrol_since_last_scenario() -> int:
2807
2858
  for args in (["commit", "-q", "--allow-empty", "-m", "landed"], ["push", "-q", "origin", "HEAD"]):
2808
2859
  subprocess.run(["git", *args], cwd=rtl, check=True, capture_output=True)
2809
2860
  second = patrol("--since-last", "--notify")
2810
- if second.returncode != 2:
2861
+ if second.returncode != 3:
2811
2862
  report(f"{label} the run after a change exited {second.returncode}: {second.stdout!r} {second.stderr!r}")
2812
2863
  return 1
2813
2864
  changed = [line for line in second.stdout.splitlines() if line.startswith("changed:")]
@@ -2835,6 +2886,65 @@ def validate_patrol_since_last_scenario() -> int:
2835
2886
  return 0
2836
2887
 
2837
2888
 
2889
+ def validate_patrol_exit_says_who_acts_scenario() -> int:
2890
+ """Issue #350: `keel patrol` exited 2 on pure state changes too.
2891
+
2892
+ A coordinator's schedule wakes its model on exit 2, so a run that only
2893
+ moved state or told other roles cost a model turn for nothing. Exit 2 now
2894
+ means the coordinator has something to act on — a risk, or its own wait
2895
+ met — and exit 3 means patrol recorded or delivered something for others.
2896
+ """
2897
+ label = "patrol-exit-says-who-acts:"
2898
+ with tempfile.TemporaryDirectory(prefix="keel-patrol-350-") as raw:
2899
+ base = Path(raw)
2900
+ rtl, verify, env, _ = shift_scratch(base)
2901
+
2902
+ def patrol(*args: str) -> subprocess.CompletedProcess[str]:
2903
+ return run_keel(rtl, "patrol", *args, env=env)
2904
+
2905
+ def push() -> str:
2906
+ for args in (["commit", "-q", "--allow-empty", "-m", "landed"], ["push", "-q", "origin", "HEAD"]):
2907
+ subprocess.run(["git", *args], cwd=rtl, check=True, capture_output=True)
2908
+ return subprocess.run(["git", "rev-parse", "HEAD"], cwd=rtl, text=True, capture_output=True, check=True).stdout.strip()
2909
+
2910
+ if patrol("--since-last", "--notify").returncode != 0:
2911
+ report(f"{label} the baseline run did not exit 0.")
2912
+ return 1
2913
+ push()
2914
+ moved = patrol("--since-last", "--notify")
2915
+ if moved.returncode != 3:
2916
+ report(f"{label} a run whose only news is the remote tip exited {moved.returncode}, not 3: {moved.stdout!r}")
2917
+ return 1
2918
+ (rtl / "stray.txt").write_text("x\n")
2919
+ risky = patrol("--since-last", "--notify")
2920
+ if risky.returncode != 2:
2921
+ report(f"{label} a run that found a risk exited {risky.returncode}, not 2: {risky.stdout!r}")
2922
+ return 1
2923
+ (rtl / "stray.txt").unlink()
2924
+
2925
+ sha = push()
2926
+ run_keel(verify, "chat", "wait", "soc", "--commit", sha, "rerun when it lands", env=env)
2927
+ theirs = patrol()
2928
+ if theirs.returncode != 3:
2929
+ report(f"{label} a run that met another role's wait exited {theirs.returncode}, not 3: {theirs.stdout!r}")
2930
+ return 1
2931
+ sha = push()
2932
+ run_keel(rtl, "chat", "wait", "soc", "--commit", sha, "merge the next slice", env=env)
2933
+ mine = patrol()
2934
+ if mine.returncode != 2:
2935
+ report(f"{label} a run that met the coordinator's own wait exited {mine.returncode}, not 2: {mine.stdout!r}")
2936
+ return 1
2937
+ helped = run_keel(rtl, "patrol", "--help", env=env)
2938
+ if "3:" not in helped.stdout:
2939
+ report(f"{label} --help does not document exit 3: {helped.stdout!r}")
2940
+ return 1
2941
+ if "patrol-exit-says-who-acts" not in {name for name, _ in SCENARIOS}:
2942
+ report(f"{label} scenario is not registered.")
2943
+ return 1
2944
+ report("patrol-exit-says-who-acts scenario passed.")
2945
+ return 0
2946
+
2947
+
2838
2948
  def validate_patrol_nudge_scenario() -> int:
2839
2949
  """Issues #307 part 1 and #313: the patrol nudges idle roles directly.
2840
2950
 
@@ -2878,8 +2988,8 @@ def validate_patrol_nudge_scenario() -> int:
2878
2988
  if any(line.startswith("nudged lint") for line in nudged(first)):
2879
2989
  report(f"{label} lint was nudged before any task closed: {nudged(first)!r}")
2880
2990
  return 1
2881
- if first.returncode != 2:
2882
- report(f"{label} a run that nudged exited {first.returncode}.")
2991
+ if first.returncode != 3:
2992
+ report(f"{label} a run that nudged exited {first.returncode}, not 3.")
2883
2993
  return 1
2884
2994
  if run_keel(verify, "chat", "notice", "--check", env=env).returncode != 0:
2885
2995
  report(f"{label} the nudge does not wake verify.")
@@ -3117,8 +3227,8 @@ def validate_coordinator_patrol_scenario() -> int:
3117
3227
 
3118
3228
  subprocess.run(["git", "push", "-q", "origin", "feature"], cwd=rtl, check=True, capture_output=True)
3119
3229
  landed = patrol()
3120
- if landed.returncode != 2:
3121
- report(f"{label} patrol after the push exited {landed.returncode}, not 2: {landed.stdout} {landed.stderr}")
3230
+ if landed.returncode != 3:
3231
+ report(f"{label} patrol after the push exited {landed.returncode}, not 3: {landed.stdout} {landed.stderr}")
3122
3232
  return 1
3123
3233
  if chat_json(chat(rtl, "waits", "--json")).get("waits"):
3124
3234
  report(f"{label} the met wait is still listed.")
@@ -3147,8 +3257,8 @@ def validate_coordinator_patrol_scenario() -> int:
3147
3257
  issues = base / "issues.json"
3148
3258
  issues.write_text(json.dumps([{"number": 42, "title": "clock fix", "state": "CLOSED", "labels": [], "updatedAt": "2026-10-11T00:00:00Z"}]), encoding="utf-8")
3149
3259
  closed = patrol("--issues", str(issues))
3150
- if closed.returncode != 2:
3151
- report(f"{label} patrol with issue 42 closed exited {closed.returncode}, not 2: {closed.stdout} {closed.stderr}")
3260
+ if closed.returncode != 3:
3261
+ report(f"{label} patrol with issue 42 closed exited {closed.returncode}, not 3: {closed.stdout} {closed.stderr}")
3152
3262
  return 1
3153
3263
  report("coordinator-patrol scenario passed.")
3154
3264
  return 0
@@ -3178,8 +3288,8 @@ def validate_patrol_issue_routing_scenario() -> int:
3178
3288
  return [r.get("text", "") for r in chat_json(run_keel(verify, "chat", "unread", "--json", env=env)).get("unread", []) if "#157" in r.get("text", "")]
3179
3289
 
3180
3290
  first = patrol("2026-10-11T01:00:00Z")
3181
- if first.returncode != 2:
3182
- report(f"{label} the first patrol exited {first.returncode}, not 2: {first.stdout} {first.stderr}")
3291
+ if first.returncode != 3:
3292
+ report(f"{label} the first patrol exited {first.returncode}, not 3: {first.stdout} {first.stderr}")
3183
3293
  return 1
3184
3294
  if len(notices()) != 1:
3185
3295
  report(f"{label} verify has {len(notices())} notices about #157, not 1.")
@@ -3196,8 +3306,8 @@ def validate_patrol_issue_routing_scenario() -> int:
3196
3306
  report(f"{label} the same update was sent again.")
3197
3307
  return 1
3198
3308
  later = patrol("2026-10-11T02:00:00Z")
3199
- if later.returncode != 2:
3200
- report(f"{label} a later update exited {later.returncode}, not 2.")
3309
+ if later.returncode != 3:
3310
+ report(f"{label} a later update exited {later.returncode}, not 3.")
3201
3311
  return 1
3202
3312
  if len(notices()) != 2:
3203
3313
  report(f"{label} a later update left {len(notices())} notices, not 2.")
@@ -41790,9 +41900,11 @@ SCENARIOS: tuple = (
41790
41900
  ("self-shift-authorization", validate_self_shift_authorization_scenario),
41791
41901
  ("resource-lock", validate_resource_lock_scenario),
41792
41902
  ("chat-supersedes", validate_chat_supersedes_scenario),
41903
+ ("chat-mention-skips-code", validate_chat_mention_skips_code_scenario),
41793
41904
  ("chat-ack", validate_chat_ack_scenario),
41794
41905
  ("coordinator-patrol", validate_coordinator_patrol_scenario),
41795
41906
  ("patrol-since-last", validate_patrol_since_last_scenario),
41907
+ ("patrol-exit-says-who-acts", validate_patrol_exit_says_who_acts_scenario),
41796
41908
  ("patrol-nudge", validate_patrol_nudge_scenario),
41797
41909
  ("patrol-escalate", validate_patrol_escalate_scenario),
41798
41910
  ("patrol-quota", validate_patrol_quota_scenario),
@@ -476,7 +476,8 @@ function lenientMentions(project, group, text) {
476
476
  const state = store.groupState(store.readLog(project.where, group));
477
477
  const aliases = store.aliasMap(project.where.root);
478
478
  const mentions = [];
479
- for (const match of String(text).matchAll(MENTION)) {
479
+ // Quoted text is not a mention here either (#345).
480
+ for (const match of store.mentionText(text).matchAll(MENTION)) {
480
481
  const token = match[2].replace(/[-/]+$/, "").toLowerCase();
481
482
  let role = null;
482
483
  if (token === store.ALL || token === store.OWNER || token.includes("/") || state.members.has(token)) role = token;
@@ -527,10 +527,23 @@ const MENTION = /(^|[^\w@/])@([A-Za-z0-9][A-Za-z0-9/-]*)/g;
527
527
  // `@role`, `@alias` (case-insensitive), `@all`, `@owner`, and the cross-project
528
528
  // `@project/role`. Anything else is refused by name, so a typo cannot post a
529
529
  // message that silently reaches nobody (design D3, D4).
530
+ // Quoted text is not a mention: a fenced block or an inline code span is
531
+ // blanked with spaces of its own length before the scan, so `@verify` written
532
+ // as an example neither refuses the post nor wakes anyone (#345).
533
+ function mentionText(text) {
534
+ return String(text)
535
+ .replace(/```[\s\S]*?(?:```|$)/g, (block) => block.replace(/[^\n]/g, " "))
536
+ .replace(/`[^`\n]*`/g, (span) => " ".repeat(span.length));
537
+ }
538
+
539
+ // `<branch> @ <sha>` is the commonest `@` in some projects; a hex token that
540
+ // names nobody is that commit id, not a typo of a role (#345).
541
+ const COMMIT_ID = /^[0-9a-f]{7,40}$/;
542
+
530
543
  function resolveMentions(where, group, state, text) {
531
544
  const aliases = aliasMap(where.root);
532
545
  const mentions = [];
533
- for (const match of String(text).matchAll(MENTION)) {
546
+ for (const match of mentionText(text).matchAll(MENTION)) {
534
547
  const token = match[2].replace(/[-/]+$/, "").toLowerCase();
535
548
  let role = null;
536
549
  if (token === ALL || token === OWNER) role = token;
@@ -540,6 +553,7 @@ function resolveMentions(where, group, state, text) {
540
553
  if (role && role !== ALL && role !== OWNER && !role.includes("/") && !state.members.has(role)) {
541
554
  throw new ChatError(`@${match[2]} names role ${role}, which is not a member of group ${group}.`);
542
555
  }
556
+ if (!role && COMMIT_ID.test(token)) continue;
543
557
  if (!role) {
544
558
  throw new ChatError(`@${match[2]} is not a member or alias in group ${group}.`);
545
559
  }
@@ -984,6 +998,7 @@ function readGroups(where, role, group) {
984
998
 
985
999
  module.exports = {
986
1000
  wait,
1001
+ mentionText,
987
1002
  openWaits,
988
1003
  markMet,
989
1004
  canAct,
@@ -14,9 +14,14 @@ const { parseSince } = require("./chat/view");
14
14
 
15
15
  const USAGE = "keel patrol [--issues <file>] [--idle <90s|15m|2h|3d>] [--since-last [--notify]] [--nudge] [--json] [--repo <path>]\n keel patrol task [--json] [--repo <path>] print the host scheduled task for `patrol:`";
16
16
  const NOTIFY_SENDER = "keel-patrol";
17
+ // 2 asks the coordinator to act — a risk, or a wait of its own now met — and
18
+ // 3 says patrol recorded or delivered something only other roles need: a
19
+ // coordinator's schedule wakes its model on 2, so a run that merely moved
20
+ // state no longer costs a turn (#350).
17
21
  const EXIT_QUIET = 0;
18
22
  const EXIT_ERROR = 1;
19
- const EXIT_WROTE = 2;
23
+ const EXIT_ACT = 2;
24
+ const EXIT_RECORDED = 3;
20
25
 
21
26
  class PatrolError extends Error {}
22
27
 
@@ -402,7 +407,7 @@ function hostTask(where) {
402
407
  "",
403
408
  `1. Run \`git -C ${at} fetch -q origin\`. If it fails, keep its error and continue.`,
404
409
  `2. Run \`keel patrol --repo ${at} --since-last --notify\`.`,
405
- `3. Exit 0: nothing changed. Exit 2: keel has already told ${role}. In both cases end without output. `
410
+ `3. Exit 0: nothing changed. Exit 2: keel has already told ${role} what to act on. Exit 3: keel recorded or told other roles only. In these cases end without output. `
406
411
  + "Exit 1: end with one line, `keel patrol failed: <its error output>`, adding the fetch error from step 1 if there was one.",
407
412
  ].join("\n");
408
413
  return {
@@ -465,7 +470,7 @@ function runPatrol(argv) {
465
470
  else if (arg === "--quota-alerts") options.quotaAlerts = String(argv[++index] || "").split(",").map(Number);
466
471
  else if (arg === "--quota-quiet-at") options.quotaQuietAt = Number(argv[++index]);
467
472
  else if (arg === "--help" || arg === "-h") {
468
- process.stdout.write(`${USAGE}\nExit 0: wrote nothing. 2: sent a notice or marked a wait met. 1: error.\n`);
473
+ process.stdout.write(`${USAGE}\nExit 0: wrote nothing. 2: something for you to act on (a risk, or your own wait met). 3: recorded or told other roles only. 1: error.\n`);
469
474
  return EXIT_QUIET;
470
475
  } else if (["--repo", "--issues", "--idle"].includes(arg)) {
471
476
  const value = argv[++index];
@@ -504,7 +509,9 @@ function runPatrol(argv) {
504
509
  }
505
510
  process.stdout.write(`${options.json ? JSON.stringify(result, null, 2) : render(result)}\n`);
506
511
  const changed = result.sinceLast && result.sinceLast.changes.length;
507
- const code = result.notices.length || result.held.length || changed || (result.nudges || []).length || result.risks.length ? EXIT_WROTE : EXIT_QUIET;
512
+ const own = result.held.some((held) => held.from === role);
513
+ const recorded = result.notices.length || result.held.length || changed || (result.nudges || []).length;
514
+ const code = result.risks.length || own ? EXIT_ACT : recorded ? EXIT_RECORDED : EXIT_QUIET;
508
515
  appendRunLog(where, role, code, result);
509
516
  return code;
510
517
  } catch (error) {