@christang/keel 5.137.0 → 5.138.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.137.0 -->
1
+ <!-- keel:start version=5.138.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.138.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.138.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.138.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.138.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.138.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.137.0"
51
- PROTOCOL_VERSION = "5.137.0"
50
+ PACKAGE_VERSION = "5.138.0"
51
+ PROTOCOL_VERSION = "5.138.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
 
@@ -40822,6 +40912,7 @@ SCENARIOS: tuple = (
40822
40912
  ("shift-desktop-wake-overdue", validate_shift_desktop_wake_overdue_scenario),
40823
40913
  ("shift-start-desktop", validate_shift_start_desktop_scenario),
40824
40914
  ("chat-wake-idle-desktop", validate_chat_wake_idle_desktop_scenario),
40915
+ ("chat-park-role", validate_chat_park_role_scenario),
40825
40916
  ("shift-await-clear", validate_shift_await_clear_scenario),
40826
40917
  ("shift-restore-authorization", validate_shift_restore_authorization_scenario),
40827
40918
  ("self-shift-authorization", validate_self_shift_authorization_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
  }