@christang/keel 5.136.0 → 5.137.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,4 +1,4 @@
1
- <!-- keel:start version=5.136.0 -->
1
+ <!-- keel:start version=5.137.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.136.0",
3
+ "version": "5.137.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.136.0",
9
+ "version": "5.137.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.136.0",
5
+ "version": "5.137.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.136.0",
3
+ "version": "5.137.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.136.0",
3
+ "version": "5.137.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",
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
47
47
  "scripts/validate_plugin.py",
48
48
  ]
49
49
 
50
- PACKAGE_VERSION = "5.136.0"
51
- PROTOCOL_VERSION = "5.136.0"
50
+ PACKAGE_VERSION = "5.137.0"
51
+ PROTOCOL_VERSION = "5.137.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,129 @@ def validate_shift_await_clear_scenario() -> int:
6965
6965
  return 0
6966
6966
 
6967
6967
 
6968
+ def validate_chat_wake_idle_desktop_scenario() -> int:
6969
+ """A record for an idle desktop session names the step that wakes it (#331).
6970
+
6971
+ On the Claude desktop app a session with no running Claude process reads
6972
+ no chat record, so a todo or a patrol nudge alone wakes nothing there
6973
+ (chat-wake-idle-desktop D1-D4). Outside the desktop app nothing changes.
6974
+ """
6975
+ label = "chat-wake-idle-desktop:"
6976
+ with tempfile.TemporaryDirectory(prefix="keel-chat-wake-idle-desktop-") as raw:
6977
+ base = Path(raw)
6978
+ rtl, verify, env, _ = shift_scratch(base)
6979
+ gone = subprocess.Popen(["node", "-e", ""])
6980
+ gone.wait()
6981
+ desktop = {**env, "CLAUDE_CODE_ENTRYPOINT": "claude-desktop", "CLAUDE_CODE_HOST_SESSION_ID": "local_test-331", "KEEL_SHIFT_DESKTOP_PID": str(gone.pid)}
6982
+
6983
+ def hook(environment: dict) -> subprocess.CompletedProcess[str]:
6984
+ return subprocess.run(
6985
+ ["node", str(ROOT / "bin" / "keel.js"), "chat", "hook", "session-start"],
6986
+ cwd=verify, env=environment, text=True, capture_output=True, check=False,
6987
+ input=json.dumps({"cwd": str(verify), "hook_event_name": "SessionStart", "source": "startup"}),
6988
+ )
6989
+
6990
+ steps = ("send_message", "get_session", "unarchive_session", "local_test-331")
6991
+ started = hook(desktop)
6992
+ if started.returncode != 0:
6993
+ report(f"{label} the desktop session-start hook failed: {started.stderr.strip()}")
6994
+ return 1
6995
+ run_keel(rtl, "chat", "group", "create", "soc", "verify", env=env)
6996
+ made = run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "R031 rerun", env=env)
6997
+ if made.returncode != 0:
6998
+ report(f"{label} todo failed: {made.stderr.strip()}")
6999
+ return 1
7000
+ for needle in steps:
7001
+ if needle not in made.stdout:
7002
+ report(f"{label} a todo for an idle desktop session does not name {needle}: {made.stdout.strip()}")
7003
+ return 1
7004
+ as_json = run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "R032 rerun", "--json", env=env)
7005
+ asleep = json.loads(as_json.stdout).get("asleep") if as_json.returncode == 0 else None
7006
+ if asleep != [{"role": "verify", "session": "local_test-331"}]:
7007
+ report(f"{label} --json does not carry asleep: {as_json.stdout.strip()} {as_json.stderr.strip()}")
7008
+ return 1
7009
+ stored = run_keel(verify, "chat", "todos", "--mine", env=desktop)
7010
+ if "R031 rerun" not in stored.stdout:
7011
+ report(f"{label} the todo was not stored: {stored.stdout.strip()}")
7012
+ return 1
7013
+ time.sleep(1.2)
7014
+ patrol = run_keel(rtl, "patrol", "--nudge", "--idle", "1s", env=env)
7015
+ if "nudged verify" not in patrol.stdout:
7016
+ report(f"{label} the patrol did not nudge verify: {patrol.stdout.strip()} {patrol.stderr.strip()}")
7017
+ return 1
7018
+ risks = [line for line in patrol.stdout.splitlines() if line.startswith("risk:")]
7019
+ if not any("local_test-331" in line and "send_message" in line for line in risks):
7020
+ report(f"{label} the first nudge to an idle desktop session reports no risk naming its wake step: {patrol.stdout.strip()}")
7021
+ return 1
7022
+ if hook(env).returncode != 0:
7023
+ report(f"{label} the plain session-start hook failed.")
7024
+ return 1
7025
+ plain = run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "R033 rerun", env=env)
7026
+ if any(needle in plain.stdout for needle in steps):
7027
+ report(f"{label} a todo for a session outside the desktop app still names a wake step: {plain.stdout.strip()}")
7028
+ return 1
7029
+ for relative in ("docs/chat-slack-setup.md", "docs/chat-slack-setup.zh-CN.md"):
7030
+ if "#331" not in (ROOT / relative).read_text(encoding="utf-8"):
7031
+ report(f"{label} {relative} does not mention #331.")
7032
+ return 1
7033
+ if "chat-wake-idle-desktop" not in {name for name, _ in SCENARIOS}:
7034
+ report(f"{label} scenario is not registered.")
7035
+ return 1
7036
+ report("chat-wake-idle-desktop scenario passed.")
7037
+ return 0
7038
+
7039
+
7040
+ def validate_shift_start_desktop_scenario() -> int:
7041
+ """`keel shift start` names the wake step for a note written on the desktop app.
7042
+
7043
+ A desktop session with no running process sees no chat record, so the
7044
+ start record alone wakes nobody there (#320, D1 of
7045
+ shift-start-desktop-wake). Elsewhere the output is unchanged.
7046
+ """
7047
+ label = "shift-start-desktop:"
7048
+ with tempfile.TemporaryDirectory(prefix="keel-shift-start-desktop-") as raw:
7049
+ base = Path(raw)
7050
+ rtl, verify, env, _ = shift_scratch(base)
7051
+ desktop = {**env, "CLAUDE_CODE_ENTRYPOINT": "claude-desktop", "CLAUDE_CODE_HOST_SESSION_ID": "local_test-320", "KEEL_SHIFT_DESKTOP_PID": "4242"}
7052
+ ready = run_keel(verify, "shift", "ready", "verify note: next is R030", env=desktop)
7053
+ if ready.returncode != 0:
7054
+ report(f"{label} ready on the desktop app failed: {ready.stderr.strip()}")
7055
+ return 1
7056
+ started = run_keel(rtl, "shift", "start", "verify", env=env)
7057
+ if started.returncode != 0:
7058
+ report(f"{label} start failed: {started.stderr.strip()}")
7059
+ return 1
7060
+ read = run_keel(verify, "chat", "read", "dm-rtl--verify", env=env)
7061
+ if "keel shift resume" not in read.stdout:
7062
+ report(f"{label} the start record did not reach dm-rtl--verify: {read.stdout.strip()} {read.stderr.strip()}")
7063
+ return 1
7064
+ for needle in ("send_message", "get_session", "unarchive_session", "local_test-320", "keel shift resume"):
7065
+ if needle not in started.stdout:
7066
+ report(f"{label} start for a desktop note does not name {needle}: {started.stdout.strip()}")
7067
+ return 1
7068
+ if "Woke" in started.stdout:
7069
+ report(f"{label} start for a desktop note still says it woke the role: {started.stdout.strip()}")
7070
+ return 1
7071
+ run_keel(verify, "shift", "resume", env=env)
7072
+ plain = run_keel(verify, "shift", "ready", "verify note: next is R031", env=env)
7073
+ if plain.returncode != 0:
7074
+ report(f"{label} ready outside the desktop app failed: {plain.stderr.strip()}")
7075
+ return 1
7076
+ other = run_keel(rtl, "shift", "start", "verify", env=env)
7077
+ if "Woke verify" not in other.stdout or "send_message" in other.stdout:
7078
+ report(f"{label} start for a note with no desktop session changed: {other.stdout.strip()}")
7079
+ return 1
7080
+ for relative, word in (("docs/shift-change.md", "#320"), ("docs/shift-change.zh-CN.md", "#320")):
7081
+ if word not in (ROOT / relative).read_text(encoding="utf-8"):
7082
+ report(f"{label} {relative} does not mention {word}.")
7083
+ return 1
7084
+ if "shift-start-desktop" not in {name for name, _ in SCENARIOS}:
7085
+ report(f"{label} scenario is not registered.")
7086
+ return 1
7087
+ report("shift-start-desktop scenario passed.")
7088
+ return 0
7089
+
7090
+
6968
7091
  def validate_shift_desktop_wake_overdue_scenario() -> int:
6969
7092
  """`keel shift status` flags a desktop note whose wake is overdue.
6970
7093
 
@@ -40697,6 +40820,8 @@ SCENARIOS: tuple = (
40697
40820
  ("shift-without-role", validate_shift_without_role_scenario),
40698
40821
  ("shift-desktop-wake", validate_shift_desktop_wake_scenario),
40699
40822
  ("shift-desktop-wake-overdue", validate_shift_desktop_wake_overdue_scenario),
40823
+ ("shift-start-desktop", validate_shift_start_desktop_scenario),
40824
+ ("chat-wake-idle-desktop", validate_chat_wake_idle_desktop_scenario),
40700
40825
  ("shift-await-clear", validate_shift_await_clear_scenario),
40701
40826
  ("shift-restore-authorization", validate_shift_restore_authorization_scenario),
40702
40827
  ("self-shift-authorization", validate_self_shift_authorization_scenario),
@@ -177,14 +177,27 @@ function offlineMentions(where, record) {
177
177
  .filter((role) => notice.presenceOf(where, role).state === "offline");
178
178
  }
179
179
 
180
+ // A woken role whose desktop session has no running process reads nothing
181
+ // until something resumes it (#331 D3), so the poster is given the step.
182
+ function asleepTargets(where, record) {
183
+ const bound = Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean);
184
+ 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);
186
+ }
187
+
180
188
  function postResult(where, record, json) {
181
- const offline = offlineMentions(where, record);
189
+ const asleep = asleepTargets(where, record);
190
+ const offline = offlineMentions(where, record).filter((role) => !asleep.some((entry) => entry.role === role));
182
191
  if (json) {
183
- out(JSON.stringify({ id: record.id, group: record.group, from: record.from, mentions: record.mentions, offline }));
192
+ out(JSON.stringify({ id: record.id, group: record.group, from: record.from, mentions: record.mentions, offline, asleep }));
184
193
  return;
185
194
  }
186
195
  const lines = [`Posted ${record.id} to ${record.group}.`];
187
196
  for (const role of offline) lines.push(`Queued for ${role}: offline; it will see this when its session next starts.`);
197
+ for (const entry of asleep) {
198
+ lines.push(`${entry.role}'s desktop session ${entry.session} has no running process, so this record alone wakes nothing (#331). `
199
+ + notice.wakeStep(entry.session, "You have unread keel chat records; run `keel chat unread`."));
200
+ }
188
201
  out(lines.join("\n"));
189
202
  }
190
203
 
@@ -91,6 +91,11 @@ function touchPresence(where, role, state = "online", host = null, started = nul
91
91
  // start in the same second as the `ready` still orders after it.
92
92
  session_started: started ? new Date().toISOString() : previous.session_started || null,
93
93
  session_source: started ? started.source : previous.session_source || null,
94
+ // The desktop app's session and its Claude process (#331 D1): an ended
95
+ // session keeps them, since it is the one that needs waking.
96
+ ...(state === "offline"
97
+ ? { desktop_session: previous.desktop_session || null, desktop_pid: previous.desktop_pid || null }
98
+ : desktopFields()),
94
99
  };
95
100
  try {
96
101
  store.writeJsonAtomic(where, presenceFile(where, role), record);
@@ -99,6 +104,37 @@ function touchPresence(where, role, state = "online", host = null, started = nul
99
104
  }
100
105
  }
101
106
 
107
+ function desktopFields() {
108
+ const id = process.env.CLAUDE_CODE_HOST_SESSION_ID;
109
+ if (process.env.CLAUDE_CODE_ENTRYPOINT !== "claude-desktop" || !id) return { desktop_session: null, desktop_pid: null };
110
+ return { desktop_session: id, desktop_pid: require("../shift").desktopProcess() };
111
+ }
112
+
113
+ function running(pid) {
114
+ try {
115
+ process.kill(pid, 0);
116
+ return true;
117
+ } catch (error) {
118
+ return error.code === "EPERM";
119
+ }
120
+ }
121
+
122
+ // A role whose desktop session has no running Claude process reads no chat
123
+ // record until something resumes it (#331 D2, measured in #320).
124
+ function asleep(where, role) {
125
+ const record = store.readJsonFile(presenceFile(where, role));
126
+ if (!record.desktop_session) return null;
127
+ // With no process found when it was recorded, Keel cannot tell, and says nothing.
128
+ const pid = Number(record.desktop_pid);
129
+ return Number.isInteger(pid) && pid > 1 && !running(pid) ? { role, session: record.desktop_session } : null;
130
+ }
131
+
132
+ // The step that wakes it (#331 D3), as the shift start names it (#320).
133
+ function wakeStep(session, text) {
134
+ return `Wake it: call \`get_session\` on \`${session}\`; when it reports the session archived, call \`unarchive_session\` on it; `
135
+ + `then call \`send_message\` to \`${session}\` with ${JSON.stringify(text)}.`;
136
+ }
137
+
102
138
  const ONLINE_WINDOW_MS = 24 * 60 * 60 * 1000;
103
139
 
104
140
  // `online`, `idle`, or `offline`, with the time of last activity (D10).
@@ -381,6 +417,8 @@ function check(cwd) {
381
417
 
382
418
  module.exports = {
383
419
  NOTICE_LIMIT,
420
+ asleep,
421
+ wakeStep,
384
422
  check,
385
423
  bridgeLine,
386
424
  hook,
@@ -297,6 +297,13 @@ function nudgeRoles(where, patroller, options) {
297
297
  mine.resume = stamp;
298
298
  }
299
299
  }
300
+ // A nudge to a desktop session with no running process wakes nothing,
301
+ // so the coordinator hears it on the first one (#331 D4).
302
+ const sleeping = sent.some((entry) => entry.role === role) ? notice.asleep(where, role) : null;
303
+ if (sleeping) {
304
+ escalations.push(`${role}'s desktop session ${sleeping.session} has no running process, so the nudge wakes nothing: `
305
+ + notice.wakeStep(sleeping.session, "You have unread keel chat records; run `keel chat unread`."));
306
+ }
300
307
  state[role] = mine;
301
308
  }
302
309
  store.writeJsonAtomic(where, stateFile, state);
package/src/core/shift.js CHANGED
@@ -557,7 +557,10 @@ function start(where, role, text) {
557
557
  `${role}: your new shift starts now. First run \`keel context\`, then \`keel shift resume\` to read the note your previous shift left, then continue from it.`,
558
558
  text ? `Next: ${text}` : "",
559
559
  ].filter(Boolean).join("\n");
560
- return store.post(where, { group, text: body, refs: [REF] });
560
+ // A note written on the Claude desktop app names its session: there a
561
+ // session with no running process sees no chat record (#320 D1).
562
+ const desktop = (fs.readFileSync(notePath(where, role), "utf8").match(/^Desktop session: (\S+?)\.$/m) || [])[1] || null;
563
+ return { record: store.post(where, { group, text: body, refs: [REF] }), body, desktop };
561
564
  }
562
565
 
563
566
  // `--role` reads a role's note from a worktree bound to no other role (#293 D5).
@@ -903,8 +906,17 @@ function runShift(argv) {
903
906
  }
904
907
  case "start": {
905
908
  if (!rest[0]) throw new ShiftError("keel shift start needs the role.");
906
- const record = start(where, rest[0], rest.slice(1).join(" "));
907
- out({ id: record.id, group: record.group, role: rest[0] }, `Woke ${rest[0]} to start its new shift (${record.id} in ${record.group}).`);
909
+ const { record, body, desktop } = start(where, rest[0], rest.slice(1).join(" "));
910
+ const posted = `(${record.id} in ${record.group})`;
911
+ out(
912
+ { id: record.id, group: record.group, role: rest[0], desktop },
913
+ desktop
914
+ ? [
915
+ `Posted the start for ${rest[0]} ${posted}. Its note was written on the Claude desktop app, where a session with no running process sees no chat record (#320), so this alone wakes nothing.`,
916
+ `Wake it: call \`get_session\` on \`${desktop}\`; when it reports the session archived, call \`unarchive_session\` on it; then call \`send_message\` to \`${desktop}\` with: '${body.replace(/\n/g, " ")}'`,
917
+ ].join("\n")
918
+ : `Woke ${rest[0]} to start its new shift ${posted}.`,
919
+ );
908
920
  return 0;
909
921
  }
910
922
  case "resume": {