@christang/keel 5.155.0 → 5.156.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.155.0",
3
+ "version": "5.156.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,4 +1,4 @@
1
- <!-- keel:start version=5.155.0 -->
1
+ <!-- keel:start version=5.156.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.155.0",
3
+ "version": "5.156.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.155.0",
9
+ "version": "5.156.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.155.0",
5
+ "version": "5.156.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.155.0",
3
+ "version": "5.156.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.155.0",
3
+ "version": "5.156.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.155.0"
53
- PROTOCOL_VERSION = "5.155.0"
52
+ PACKAGE_VERSION = "5.156.0"
53
+ PROTOCOL_VERSION = "5.156.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
@@ -2502,6 +2502,102 @@ def validate_chat_mention_skips_code_scenario() -> int:
2502
2502
  return 0
2503
2503
 
2504
2504
 
2505
+ def validate_chat_wake_now_cli_scenario() -> int:
2506
+ """Issue #348 on the CLI (owner's CLI waker, 2026-10-19): one step wakes a role.
2507
+
2508
+ A background CLI session's hooks record its session id and process. When
2509
+ that process has exited, `keel chat wake now <role>` resumes it with
2510
+ `claude --bg --resume <id> "<pointer>"` in its worktree — no other flag, so
2511
+ the id is kept — and `keel tick` does the same once per new addressed
2512
+ record. A running session is left to the record itself, which wakes it.
2513
+ """
2514
+ label = "chat-wake-now-cli:"
2515
+ with tempfile.TemporaryDirectory(prefix="keel-wake-348-") as raw:
2516
+ base = Path(raw)
2517
+ rtl, verify, env, _ = shift_scratch(base)
2518
+ calls = base / "claude-calls.jsonl"
2519
+ fake = base / "fake-claude"
2520
+ write_text(fake, "#!/usr/bin/env python3\nimport json, os, sys\n"
2521
+ f"open({str(calls)!r}, 'a').write(json.dumps({{'argv': sys.argv[1:], 'cwd': os.getcwd()}}) + '\\n')\n"
2522
+ "print('backgrounded · fake')\n")
2523
+ fake.chmod(0o755)
2524
+ env = {**env, "KEEL_CLAUDE": str(fake)}
2525
+ dead = subprocess.Popen(["true"])
2526
+ dead.wait()
2527
+
2528
+ def start(pid: int) -> None:
2529
+ subprocess.run(["node", str(ROOT / "bin" / "keel.js"), "chat", "hook", "session-start"], cwd=verify, text=True,
2530
+ capture_output=True, check=False,
2531
+ env={**env, "CLAUDE_CODE_ENTRYPOINT": "cli", "CLAUDE_CODE_SESSION_ID": "sess-verify-1", "CLAUDE_PID": str(pid)},
2532
+ input=json.dumps({"cwd": str(verify), "hook_event_name": "SessionStart", "session_id": "sess-verify-1", "source": "startup"}))
2533
+
2534
+ def made() -> list[dict]:
2535
+ return [json.loads(line) for line in calls.read_text().splitlines()] if calls.exists() else []
2536
+
2537
+ start(dead.pid)
2538
+ posted = run_keel(rtl, "chat", "dm", "verify", "rerun R009", env=env)
2539
+ if "keel chat wake now verify" not in posted.stdout:
2540
+ report(f"{label} a dm to a role whose CLI process exited does not name `keel chat wake now verify`: {posted.stdout!r}")
2541
+ return 1
2542
+ if "get_session" in posted.stdout:
2543
+ report(f"{label} a CLI role is given the desktop wake step: {posted.stdout!r}")
2544
+ return 1
2545
+ woke = run_keel(rtl, "chat", "wake", "now", "verify", env=env)
2546
+ if woke.returncode != 0:
2547
+ report(f"{label} keel chat wake now failed: {woke.stdout!r} {woke.stderr!r}")
2548
+ return 1
2549
+ if len(made()) != 1:
2550
+ report(f"{label} wake now did not run claude once: {made()!r}")
2551
+ return 1
2552
+ call = made()[0]
2553
+ if call["argv"][:3] != ["--bg", "--resume", "sess-verify-1"] or len(call["argv"]) != 4:
2554
+ report(f"{label} wake now ran claude with {call['argv']!r}, not --bg --resume <id> <prompt> and nothing else.")
2555
+ return 1
2556
+ if "keel chat unread" not in call["argv"][3]:
2557
+ report(f"{label} the resume prompt does not point at keel chat unread: {call['argv'][3]!r}")
2558
+ return 1
2559
+ if os.path.realpath(call["cwd"]) != os.path.realpath(verify):
2560
+ report(f"{label} claude was resumed in {call['cwd']}, not verify's worktree.")
2561
+ return 1
2562
+
2563
+ start(os.getpid())
2564
+ alive = run_keel(rtl, "chat", "wake", "now", "verify", env=env)
2565
+ if len(made()) != 1:
2566
+ report(f"{label} wake now resumed a role whose process is running: {made()!r}")
2567
+ return 1
2568
+ if "running" not in alive.stdout:
2569
+ report(f"{label} wake now does not say the session is running: {alive.stdout!r}")
2570
+ return 1
2571
+
2572
+ start(dead.pid)
2573
+ run_keel(rtl, "chat", "dm", "verify", "rerun R010", env=env)
2574
+ run_keel(verify, "tick", "--repo", str(rtl), env=env)
2575
+ if len(made()) != 2:
2576
+ report(f"{label} keel tick did not wake the exited role for its new record: {made()!r}")
2577
+ return 1
2578
+ run_keel(verify, "tick", "--repo", str(rtl), env=env)
2579
+ if len(made()) != 2:
2580
+ report(f"{label} a second tick woke the role again for the same record: {made()!r}")
2581
+ return 1
2582
+ time.sleep(2)
2583
+ nudged = run_keel(rtl, "patrol", "--nudge", "--idle", "1s", env=env).stdout
2584
+ escalation = next((l for l in nudged.splitlines() if "verify" in l and "wakes nothing" in l), "")
2585
+ if "keel chat wake now verify" not in escalation or "get_session" in escalation:
2586
+ report(f"{label} the patrol's nudge escalation for an ended CLI session is not `keel chat wake now verify`: {nudged!r}")
2587
+ return 1
2588
+ run_keel(rtl, "chat", "role", "--park", "verify", "--reason", "held for review", env=env)
2589
+ run_keel(rtl, "chat", "dm", "verify", "rerun R011", env=env)
2590
+ run_keel(verify, "tick", "--repo", str(rtl), env=env)
2591
+ if len(made()) != 2:
2592
+ report(f"{label} keel tick woke a parked role: {made()!r}")
2593
+ return 1
2594
+ if "chat-wake-now-cli" not in {name for name, _ in SCENARIOS}:
2595
+ report(f"{label} scenario is not registered.")
2596
+ return 1
2597
+ report("chat-wake-now-cli scenario passed.")
2598
+ return 0
2599
+
2600
+
2505
2601
  def validate_chat_supersedes_scenario() -> int:
2506
2602
  """Issue #252: a record supersedes its author's earlier one.
2507
2603
 
@@ -24514,7 +24610,7 @@ def validate_update_host_query_timeout_scenario() -> int:
24514
24610
  "KEEL_UPDATE_NPM": str(launchers["npm"]),
24515
24611
  "KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
24516
24612
  "KEEL_UPDATE_CODEX": str(launchers["codex"]),
24517
- "KEEL_UPDATE_QUERY_TIMEOUT_MS": "1500",
24613
+ "KEEL_UPDATE_QUERY_TIMEOUT_MS": "30000",
24518
24614
  "CODEX_HOME": str(tmp / "codex-home"),
24519
24615
  "FAKE_LOG": str(log), "FAKE_STATE": str(state),
24520
24616
  "FAKE_CODEX_SOURCE": str(source),
@@ -24539,12 +24635,13 @@ def validate_update_host_query_timeout_scenario() -> int:
24539
24635
  report(f"{label} a claude plugin list --json that exited 3 does not read failed with exited 3: {claude!r}")
24540
24636
  return 1
24541
24637
 
24542
- result, calls, took = update(env_extra={"FAKE_LIST_SLEEP_CODEX": "10"})
24638
+ # Only the hung case needs a short limit; the others keep 30 s, so load cannot trip them.
24639
+ result, calls, took = update(env_extra={"FAKE_LIST_SLEEP_CODEX": "15", "KEEL_UPDATE_QUERY_TIMEOUT_MS": "4000"})
24543
24640
  codex = line(result.stdout, "codex plugin")
24544
24641
  if "absent" in codex:
24545
24642
  report(f"{label} a hung codex plugin list --json was reported absent: {codex!r}")
24546
24643
  return 1
24547
- for needle in ("failed", "codex plugin list --json", "1.5 s"):
24644
+ for needle in ("failed", "codex plugin list --json", "4 s"):
24548
24645
  if needle not in codex:
24549
24646
  report(f"{label} the hung-query line does not name {needle!r}: {codex!r}")
24550
24647
  return 1
@@ -24557,8 +24654,8 @@ def validate_update_host_query_timeout_scenario() -> int:
24557
24654
  if result.returncode == 0:
24558
24655
  report(f"{label} a failed query left keel --update exiting 0.")
24559
24656
  return 1
24560
- if took > 9:
24561
- report(f"{label} the hung query held keel --update for {took:.1f} s, past its 1.5 s limit.")
24657
+ if took > 20:
24658
+ report(f"{label} the hung query held keel --update for {took:.1f} s, past two 4 s attempts.")
24562
24659
  return 1
24563
24660
 
24564
24661
  result, _, _ = update(env_extra={"KEEL_UPDATE_CODEX": str(tmp / "no-such-codex")})
@@ -24566,7 +24663,7 @@ def validate_update_host_query_timeout_scenario() -> int:
24566
24663
  report(f"{label} a missing codex executable no longer reads absent: {result.stdout!r}")
24567
24664
  return 1
24568
24665
 
24569
- result, _, _ = update("--dry-run", env_extra={"FAKE_LIST_SLEEP_CODEX": "10"})
24666
+ result, _, _ = update("--dry-run", env_extra={"FAKE_LIST_SLEEP_CODEX": "15", "KEEL_UPDATE_QUERY_TIMEOUT_MS": "4000"})
24570
24667
  if result.returncode != 0:
24571
24668
  report(f"{label} --dry-run with a hung query exited {result.returncode}: {result.stdout!r}")
24572
24669
  return 1
@@ -42227,6 +42324,7 @@ SCENARIOS: tuple = (
42227
42324
  ("resource-lock", validate_resource_lock_scenario),
42228
42325
  ("chat-supersedes", validate_chat_supersedes_scenario),
42229
42326
  ("chat-mention-skips-code", validate_chat_mention_skips_code_scenario),
42327
+ ("chat-wake-now-cli", validate_chat_wake_now_cli_scenario),
42230
42328
  ("chat-ack", validate_chat_ack_scenario),
42231
42329
  ("coordinator-patrol", validate_coordinator_patrol_scenario),
42232
42330
  ("patrol-since-last", validate_patrol_since_last_scenario),
@@ -52,6 +52,7 @@ const USAGE = [
52
52
  "keel chat wake remove (stop waking this worktree's role on this machine)",
53
53
  "keel chat wake status [--json]",
54
54
  "keel chat wake run --once [--worktree <path>] (what the waker's LaunchAgent runs)",
55
+ "keel chat wake now <role> (resume a role whose Claude Code CLI session has ended: claude --bg --resume <its id>)",
55
56
  "Every command takes --repo <path> to act on another repository.",
56
57
  ];
57
58
 
@@ -248,7 +249,11 @@ function postResult(where, record, json) {
248
249
  + "this waits until it is unparked or its session runs again — route anything urgent through the coordinator.");
249
250
  }
250
251
  for (const role of offline) lines.push(`Queued for ${role}: offline; it will see this when its session next starts.`);
251
- for (const entry of asleep) {
252
+ for (const entry of asleep.filter((item) => item.cli)) {
253
+ lines.push(`${entry.role}'s CLI session ${entry.session} has no running process, so this record alone wakes nothing; `
254
+ + `resume it with \`keel chat wake now ${entry.role}\` (#348).`);
255
+ }
256
+ for (const entry of asleep.filter((item) => !item.cli)) {
252
257
  lines.push(`${entry.role}'s desktop session ${entry.session} has no running process, so this record alone wakes nothing (#331). `
253
258
  + notice.wakeStep(entry.session, "You have unread keel chat records; run `keel chat unread`."));
254
259
  }
@@ -676,8 +681,25 @@ function runWake(cwd, options) {
676
681
  if (options.json) out(JSON.stringify(result));
677
682
  return 0;
678
683
  }
684
+ case "now": {
685
+ // One step for a role whose CLI session ended (#348 D3).
686
+ const role = options.positionals[2];
687
+ if (!role) throw new ChatError("keel chat wake now needs a role.");
688
+ store.checkName(role, "Role");
689
+ const where = store.requireLocation(cwd);
690
+ const presence = store.readJsonFile(path.join(where.root, "presence", `${role}.json`));
691
+ if (!presence.cli_session) throw new ChatError(`${role} has recorded no Claude Code CLI session, so there is nothing to resume.`);
692
+ const entry = notice.asleep(where, role);
693
+ if (!entry || !entry.cli) {
694
+ out(`${role}'s CLI session ${presence.cli_session} is running; a record addressed to it wakes it, so nothing was resumed.`);
695
+ return 0;
696
+ }
697
+ const resumed = notice.resumeCli(entry);
698
+ out(`${resumed.ok ? "Resumed" : "Could not resume"} ${role}'s CLI session ${entry.session} in ${entry.worktree}.${resumed.output ? `\n${resumed.output}` : ""}`);
699
+ return resumed.ok ? 0 : 1;
700
+ }
679
701
  default:
680
- throw new ChatError(`Unknown keel chat wake action ${JSON.stringify(action)}: use add, remove, status, or run.`);
702
+ throw new ChatError(`Unknown keel chat wake action ${JSON.stringify(action)}: use add, remove, status, run, or now.`);
681
703
  }
682
704
  }
683
705
 
@@ -97,6 +97,10 @@ function touchPresence(where, role, state = "online", host = null, started = nul
97
97
  ...(state === "offline"
98
98
  ? { desktop_session: previous.desktop_session || null, desktop_pid: previous.desktop_pid || null }
99
99
  : desktopFields()),
100
+ // A Claude Code CLI session and its process, for the same reason (#348 D1).
101
+ ...(state === "offline"
102
+ ? { cli_session: previous.cli_session || null, cli_pid: previous.cli_pid || null, cli_worktree: previous.cli_worktree || null }
103
+ : cliFields(where)),
100
104
  };
101
105
  try {
102
106
  store.writeJsonAtomic(where, presenceFile(where, role), record);
@@ -111,6 +115,13 @@ function desktopFields() {
111
115
  return { desktop_session: id, desktop_pid: require("../shift").desktopProcess() };
112
116
  }
113
117
 
118
+ function cliFields(where) {
119
+ const id = process.env.CLAUDE_CODE_SESSION_ID;
120
+ if (process.env.CLAUDE_CODE_ENTRYPOINT !== "cli" || !id) return { cli_session: null, cli_pid: null, cli_worktree: null };
121
+ const pid = Number(process.env.CLAUDE_PID);
122
+ return { cli_session: id, cli_pid: Number.isInteger(pid) && pid > 1 ? pid : null, cli_worktree: where.worktree };
123
+ }
124
+
114
125
  function running(pid) {
115
126
  try {
116
127
  process.kill(pid, 0);
@@ -124,6 +135,13 @@ function running(pid) {
124
135
  // record until something resumes it (#331 D2, measured in #320).
125
136
  function asleep(where, role) {
126
137
  const record = store.readJsonFile(presenceFile(where, role));
138
+ // An ended CLI session is resumed by `keel chat wake now` (#348 D2).
139
+ if (!record.desktop_session && record.cli_session) {
140
+ const cliPid = Number(record.cli_pid);
141
+ return Number.isInteger(cliPid) && cliPid > 1 && !running(cliPid)
142
+ ? { role, session: record.cli_session, cli: true, worktree: record.cli_worktree || null }
143
+ : null;
144
+ }
127
145
  if (!record.desktop_session) return null;
128
146
  // With no process found when it was recorded, Keel cannot tell, and says nothing.
129
147
  const pid = Number(record.desktop_pid);
@@ -136,6 +154,20 @@ function wakeStep(session, text) {
136
154
  + `then call \`send_message\` to \`${session}\` with ${JSON.stringify(text)}.`;
137
155
  }
138
156
 
157
+ // The prompt an ended CLI session resumes with: a pointer, never the work.
158
+ const CLI_WAKE_PROMPT = "You have unread keel chat records; run keel context, then keel chat unread.";
159
+
160
+ // Resumes a role's recorded CLI session (#348 D3). Only `--bg --resume <id>`
161
+ // and the prompt: any other flag starts a copy with a new session id.
162
+ function resumeCli(entry) {
163
+ const claude = process.env.KEEL_CLAUDE || "claude";
164
+ const result = require("child_process").spawnSync(claude, ["--bg", "--resume", entry.session, CLI_WAKE_PROMPT], {
165
+ cwd: entry.worktree || undefined, encoding: "utf8",
166
+ });
167
+ const output = `${result.stdout || ""}${result.stderr || ""}`.trim();
168
+ return { ok: !result.error && result.status === 0, output: result.error ? result.error.message : output };
169
+ }
170
+
139
171
  // --- parked roles (#316) ------------------------------------------------------------
140
172
 
141
173
  function parkFile(where, role) {
@@ -519,6 +551,7 @@ module.exports = {
519
551
  parkOf,
520
552
  unpark,
521
553
  wakeStep,
554
+ resumeCli,
522
555
  check,
523
556
  bridgeLine,
524
557
  keptFile,
@@ -308,7 +308,11 @@ function nudgeRoles(where, patroller, options) {
308
308
  // A nudge to a desktop session with no running process wakes nothing,
309
309
  // so the coordinator hears it on the first one (#331 D4).
310
310
  const sleeping = sent.some((entry) => entry.role === role) ? notice.asleep(where, role) : null;
311
- if (sleeping) {
311
+ if (sleeping && sleeping.cli) {
312
+ // An ended CLI session is resumed in one step (#348 D5).
313
+ escalations.push(`${role}'s CLI session ${sleeping.session} has no running process, so the nudge wakes nothing: `
314
+ + `resume it with \`keel chat wake now ${role}\`.`);
315
+ } else if (sleeping) {
312
316
  escalations.push(`${role}'s desktop session ${sleeping.session} has no running process, so the nudge wakes nothing: `
313
317
  + notice.wakeStep(sleeping.session, "You have unread keel chat records; run `keel chat unread`."));
314
318
  }
package/src/core/tick.js CHANGED
@@ -41,8 +41,32 @@ function patrolWorktree(where) {
41
41
  return { declaration, worktree: bound[0], why: null };
42
42
  }
43
43
 
44
+ // Roles whose CLI session ended while a record addressed to them waits are
45
+ // resumed once per new record (#348 D4); a parked role is left alone.
46
+ function wakeEnded(where, state) {
47
+ const notice = require("./chat/notice");
48
+ const roles = [...new Set(Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean))].sort();
49
+ state.woken = state.woken || {};
50
+ const woken = [];
51
+ for (const role of roles) {
52
+ if (notice.parkOf(where, role)) continue;
53
+ const entry = notice.asleep(where, role);
54
+ if (!entry || !entry.cli) continue;
55
+ const waiting = store.unread(where, role).filter((record) => store.wakes(record, role)).map((record) => record.id).sort();
56
+ const newest = waiting[waiting.length - 1];
57
+ if (!newest || (state.woken[role] && state.woken[role] >= newest)) continue;
58
+ const resumed = notice.resumeCli(entry);
59
+ state.woken[role] = newest;
60
+ woken.push({ role, session: entry.session, record: newest, ok: resumed.ok, output: resumed.output });
61
+ }
62
+ return woken;
63
+ }
64
+
44
65
  function tick(where, now = new Date()) {
45
- const result = { patrol: null };
66
+ const result = { patrol: null, woken: [] };
67
+ const wakeState = readState(where);
68
+ result.woken = wakeEnded(where, wakeState);
69
+ if (result.woken.length) store.writeJsonAtomic(where, stateFile(where), { ...readState(where), woken: wakeState.woken });
46
70
  const found = patrolWorktree(where);
47
71
  if (!found.worktree) {
48
72
  result.patrol = { ran: false, why: found.why };
@@ -78,6 +102,11 @@ function tick(where, now = new Date()) {
78
102
  }
79
103
 
80
104
  function render(result) {
105
+ const woke = (result.woken || []).map((w) => `keel tick: ${w.ok ? "resumed" : "could not resume"} ${w.role}'s CLI session ${w.session} for ${w.record}`);
106
+ return [...woke, renderPatrol(result)].join("\n");
107
+ }
108
+
109
+ function renderPatrol(result) {
81
110
  const p = result.patrol;
82
111
  if (!p.ran) return `keel tick: ${p.why}`;
83
112
  const lines = [`keel tick: ran the patrol (exit ${p.exit})${p.next_at ? `; next ${p.next_at} (${p.rule})` : ""}`];