@christang/keel 5.136.1 → 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.1 -->
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.1",
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.1",
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.1",
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.1",
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.1",
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.1"
51
- PROTOCOL_VERSION = "5.136.1"
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,78 @@ 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
+
6968
7040
  def validate_shift_start_desktop_scenario() -> int:
6969
7041
  """`keel shift start` names the wake step for a note written on the desktop app.
6970
7042
 
@@ -40749,6 +40821,7 @@ SCENARIOS: tuple = (
40749
40821
  ("shift-desktop-wake", validate_shift_desktop_wake_scenario),
40750
40822
  ("shift-desktop-wake-overdue", validate_shift_desktop_wake_overdue_scenario),
40751
40823
  ("shift-start-desktop", validate_shift_start_desktop_scenario),
40824
+ ("chat-wake-idle-desktop", validate_chat_wake_idle_desktop_scenario),
40752
40825
  ("shift-await-clear", validate_shift_await_clear_scenario),
40753
40826
  ("shift-restore-authorization", validate_shift_restore_authorization_scenario),
40754
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);