@christang/keel 5.124.0 → 5.125.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.
package/README.md CHANGED
@@ -808,10 +808,10 @@ nudge wakes a large session.
808
808
 
809
809
  `keel patrol --nudge` goes further and nudges each idle role itself, with one direct message from
810
810
  `keel-patrol` that wakes its session (#307): when records addressed to it have waited longer than
811
- `--idle` (at most every two hours); when the host reports with `--context <role>=<percent>` that its
812
- context is at or above `--shift-at` (default 50) and nothing waits, telling it to change its own shift
813
- with `keel shift ready --wake` (at most every six hours); and when a note it filed with `ready --wake`
814
- was never resumed. A note filed without `--wake` — a coordinator parking a role — is left alone, and
811
+ `--idle` (at most every two hours); when a todo assigned to it is closed, telling it to change shift
812
+ at that task boundary — with `keel shift ready --wake` if another todo is still open for it, or plain
813
+ `ready` to wait for the coordinator — since a shift follows a finished task and the host compacts
814
+ within one (#313); and when a note it filed with `ready --wake` was never resumed. A note filed without `--wake` — a coordinator parking a role — is left alone, and
815
815
  Keel's own messages never count as waiting.
816
816
 
817
817
  With `--issues`, patrol also routes issue updates (#242): `issue_roles:` in `keel/config.yaml`
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.124.0 -->
1
+ <!-- keel:start version=5.125.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.124.0",
3
+ "version": "5.125.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.124.0",
9
+ "version": "5.125.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.124.0",
5
+ "version": "5.125.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.124.0",
3
+ "version": "5.125.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.124.0",
3
+ "version": "5.125.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.124.0"
51
- PROTOCOL_VERSION = "5.124.0"
50
+ PACKAGE_VERSION = "5.125.0"
51
+ PROTOCOL_VERSION = "5.125.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
@@ -2828,11 +2828,12 @@ def validate_patrol_since_last_scenario() -> int:
2828
2828
 
2829
2829
 
2830
2830
  def validate_patrol_nudge_scenario() -> int:
2831
- """Issue #307 part 1: the patrol nudges idle roles directly, rate-limited.
2831
+ """Issues #307 part 1 and #313: the patrol nudges idle roles directly.
2832
2832
 
2833
- Unread addressed records, a host-reported context share, and a
2834
- self-initiated shift note each nudge once; a parked note and the
2835
- patrol's own messages never do.
2833
+ Addressed unread records nudge once per window; a closed todo nudges a
2834
+ shift change at that task boundary, naming `--wake` only while another
2835
+ todo is open; a self-initiated note nudges a resume; a parked note and
2836
+ the patrol's own messages never do; context is no longer an input.
2836
2837
  """
2837
2838
  label = "patrol-nudge:"
2838
2839
  with tempfile.TemporaryDirectory(prefix="keel-patrol-nudge-") as raw:
@@ -2842,6 +2843,12 @@ def validate_patrol_nudge_scenario() -> int:
2842
2843
  lint = chat_worktree(rtl, base / "lint")
2843
2844
  subprocess.run(["git", "push", "-q", "-u", "origin", "HEAD"], cwd=lint, check=True, capture_output=True)
2844
2845
  run_keel(lint, "chat", "role", "--set", "lint", env=env)
2846
+ run_keel(rtl, "chat", "group", "add", "soc", "lint", env=env)
2847
+ todo_ids = []
2848
+ for text in ("R009 timing fix", "R010 lint cleanup"):
2849
+ made = run_keel(rtl, "chat", "todo", "soc", "--assignee", "lint", text, "--json", env=env)
2850
+ todo_ids.append(json.loads(made.stdout)["id"])
2851
+ run_keel(lint, "chat", "read", env=env)
2845
2852
  run_keel(rtl, "chat", "post", "soc", "@verify please rerun R007", env=env)
2846
2853
  time.sleep(1.2)
2847
2854
 
@@ -2851,45 +2858,60 @@ def validate_patrol_nudge_scenario() -> int:
2851
2858
  def nudged(result: subprocess.CompletedProcess[str]) -> list[str]:
2852
2859
  return [line for line in result.stdout.splitlines() if line.startswith("nudged ")]
2853
2860
 
2861
+ def told_lint(needle: str) -> str:
2862
+ return "\n".join(chat_records_with(rtl, "dm-keel-patrol--lint", needle))
2863
+
2854
2864
  seen: list[str] = []
2855
- first = nudge("--context", "lint=40")
2865
+ first = nudge()
2856
2866
  seen += nudged(first)
2857
2867
  if "nudged verify: unread" not in nudged(first):
2858
2868
  report(f"{label} verify was not nudged for unread: {first.stdout!r} {first.stderr!r}")
2859
2869
  return 1
2860
2870
  if any(line.startswith("nudged lint") for line in nudged(first)):
2861
- report(f"{label} lint was nudged below the shift threshold: {nudged(first)!r}")
2871
+ report(f"{label} lint was nudged before any task closed: {nudged(first)!r}")
2862
2872
  return 1
2863
2873
  if first.returncode != 2:
2864
2874
  report(f"{label} a run that nudged exited {first.returncode}.")
2865
2875
  return 1
2866
- if not chat_records_with(rtl, "dm-keel-patrol--verify", "keel chat unread"):
2867
- report(f"{label} no keel-patrol record reached verify.")
2868
- return 1
2869
2876
  if run_keel(verify, "chat", "notice", "--check", env=env).returncode != 0:
2870
2877
  report(f"{label} the nudge does not wake verify.")
2871
2878
  return 1
2872
- second = nudge("--context", "lint=62")
2879
+ run_keel(lint, "chat", "done", todo_ids[0], env=env)
2880
+ time.sleep(1.2)
2881
+ second = nudge()
2873
2882
  seen += nudged(second)
2874
2883
  if nudged(second) != ["nudged lint: shift"]:
2875
- report(f"{label} the second run should nudge only lint's shift: {second.stdout!r}")
2884
+ report(f"{label} closing a todo should nudge only lint's shift: {second.stdout!r} {second.stderr!r}")
2876
2885
  return 1
2877
- shift_text = "\n".join(chat_records_with(rtl, "dm-keel-patrol--lint", "context is at 62%"))
2878
- if "keel shift ready --wake" not in shift_text:
2879
- report(f"{label} the shift nudge does not name keel shift ready --wake: {shift_text!r}")
2886
+ if "keel shift ready --wake" not in told_lint("R009"):
2887
+ report(f"{label} with a todo still open, the shift nudge does not name ready --wake: {told_lint('R009')!r}")
2880
2888
  return 1
2881
- if "Remote Control" not in shift_text:
2882
- report(f"{label} the shift nudge does not name Remote Control: {shift_text!r}")
2889
+ if "Remote Control" not in told_lint("R009"):
2890
+ report(f"{label} the shift nudge does not name Remote Control.")
2883
2891
  return 1
2884
2892
  time.sleep(1.2)
2885
- third = nudge("--context", "lint=62")
2893
+ third = nudge()
2886
2894
  seen += nudged(third)
2887
2895
  if nudged(third):
2888
- report(f"{label} a run within the rate limits nudged: {nudged(third)!r}")
2896
+ report(f"{label} a run with nothing new nudged: {nudged(third)!r}")
2889
2897
  return 1
2890
2898
  if third.returncode != 0:
2891
2899
  report(f"{label} a run that nudged nobody exited {third.returncode}.")
2892
2900
  return 1
2901
+ run_keel(lint, "chat", "done", todo_ids[1], env=env)
2902
+ time.sleep(1.2)
2903
+ fourth = nudge()
2904
+ seen += nudged(fourth)
2905
+ if "nudged lint: shift" not in nudged(fourth):
2906
+ report(f"{label} closing the last todo did not nudge lint: {fourth.stdout!r}")
2907
+ return 1
2908
+ last = told_lint("R010")
2909
+ if "wait for the coordinator" not in last:
2910
+ report(f"{label} with no todo left, the shift nudge does not say to wait for the coordinator: {last!r}")
2911
+ return 1
2912
+ if "--wake" in last:
2913
+ report(f"{label} with no todo left, the shift nudge still names --wake: {last!r}")
2914
+ return 1
2893
2915
  armed = run_keel(lint, "shift", "ready", "--wake", "lint note", env=env)
2894
2916
  if armed.returncode != 0:
2895
2917
  report(f"{label} lint's ready --wake failed: {armed.stderr}")
@@ -2898,17 +2920,24 @@ def validate_patrol_nudge_scenario() -> int:
2898
2920
  report(f"{label} verify's ready failed.")
2899
2921
  return 1
2900
2922
  time.sleep(1.2)
2901
- fourth = nudge()
2902
- seen += nudged(fourth)
2903
- if "nudged lint: resume" not in nudged(fourth):
2904
- report(f"{label} lint's self-initiated note was not nudged to resume: {fourth.stdout!r}")
2923
+ fifth = nudge()
2924
+ seen += nudged(fifth)
2925
+ if "nudged lint: resume" not in nudged(fifth):
2926
+ report(f"{label} lint's self-initiated note was not nudged to resume: {fifth.stdout!r}")
2905
2927
  return 1
2906
- if "nudged verify: resume" in nudged(fourth):
2928
+ if "nudged verify: resume" in nudged(fifth):
2907
2929
  report(f"{label} verify's parked note was nudged to resume.")
2908
2930
  return 1
2909
2931
  if "nudged lint: unread" in seen:
2910
2932
  report(f"{label} lint was nudged over the patrol's own message.")
2911
2933
  return 1
2934
+ retired = nudge("--context", "lint=62")
2935
+ if retired.returncode != 1:
2936
+ report(f"{label} --context exited {retired.returncode}.")
2937
+ return 1
2938
+ if "retired" not in retired.stderr:
2939
+ report(f"{label} the --context refusal does not say it was retired: {retired.stderr!r}")
2940
+ return 1
2912
2941
  report("patrol-nudge scenario passed.")
2913
2942
  return 0
2914
2943
 
@@ -12,7 +12,7 @@ const store = require("./chat/store");
12
12
  const notice = require("./chat/notice");
13
13
  const { parseSince } = require("./chat/view");
14
14
 
15
- const USAGE = "keel patrol [--issues <file>] [--idle <90s|15m|2h|3d>] [--since-last [--notify]] [--nudge [--context <role>=<pct>]... [--shift-at <pct>]] [--json] [--repo <path>]\n keel patrol task [--json] [--repo <path>] print the host scheduled task for `patrol:`";
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
17
  const EXIT_QUIET = 0;
18
18
  const EXIT_ERROR = 1;
@@ -204,19 +204,8 @@ function sinceLast(where, role, result, options) {
204
204
 
205
205
  const KEEL_SENDERS = new Set([NOTIFY_SENDER, "keel-shift", "keel"]);
206
206
  const UNREAD_EVERY_MS = Number(process.env.KEEL_PATROL_UNREAD_EVERY_MS) > 0 ? Number(process.env.KEEL_PATROL_UNREAD_EVERY_MS) : 2 * 60 * 60 * 1000;
207
- const SHIFT_EVERY_MS = 6 * 60 * 60 * 1000;
208
207
  const SELF_INITIATED = "Self-initiated: this shift armed `keel shift ready --wake`.";
209
208
 
210
- function parseContexts(values) {
211
- const contexts = new Map();
212
- for (const value of values) {
213
- const match = String(value).match(/^([a-z0-9][a-z0-9-]{0,31})=(\d{1,3}(?:\.\d+)?)%?$/);
214
- if (!match) throw new PatrolError(`--context ${value} is not <role>=<percent>.`);
215
- contexts.set(match[1], Number(match[2]));
216
- }
217
- return contexts;
218
- }
219
-
220
209
  function sendNudge(where, role, kind, text) {
221
210
  const group = store.directName(NOTIFY_SENDER, role);
222
211
  if (!store.groupState(store.readLog(where, group)).exists) {
@@ -226,6 +215,24 @@ function sendNudge(where, role, kind, text) {
226
215
  return { role, kind, text };
227
216
  }
228
217
 
218
+ // Closed todos per assignee: each `done` record and the todo it closes.
219
+ function closedTodos(where) {
220
+ const byRole = new Map();
221
+ for (const name of store.listGroupNames(where)) {
222
+ const records = store.readLog(where, name);
223
+ const todos = new Map(records.filter((r) => r.kind === "todo").map((r) => [r.id, r]));
224
+ for (const record of records) {
225
+ if (record.kind !== "done" || !todos.has(record.target)) continue;
226
+ const todo = todos.get(record.target);
227
+ if (!todo.assignee) continue;
228
+ if (!byRole.has(todo.assignee)) byRole.set(todo.assignee, []);
229
+ byRole.get(todo.assignee).push({ done: record.id, todo: todo.id, title: String(todo.text || "").split("\n")[0].slice(0, 80) });
230
+ }
231
+ }
232
+ for (const list of byRole.values()) list.sort((a, b) => (a.done < b.done ? -1 : 1));
233
+ return byRole;
234
+ }
235
+
229
236
  function nudgeRoles(where, patroller, options) {
230
237
  const stateFile = path.join(where.root, "patrol", "nudges.json");
231
238
  const state = store.readJsonFile(stateFile);
@@ -235,7 +242,12 @@ function nudgeRoles(where, patroller, options) {
235
242
  const escalations = [];
236
243
  const roles = [...new Set(Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean))]
237
244
  .filter((role) => role !== patroller).sort();
245
+ const closures = closedTodos(where);
238
246
  for (const role of roles) {
247
+ // The first look only records the tasks already closed (#313 D1).
248
+ if (!state[role] || !Array.isArray(state[role].closedSeen)) {
249
+ state[role] = { ...(state[role] || {}), closedSeen: (closures.get(role) || []).map((entry) => entry.done) };
250
+ }
239
251
  const last = Date.parse(notice.presenceOf(where, role).last_active || "");
240
252
  if (!Number.isNaN(last) && last >= idleBefore) continue;
241
253
  const mine = state[role] || {};
@@ -260,15 +272,19 @@ function nudgeRoles(where, patroller, options) {
260
272
  } else {
261
273
  mine.unanswered = 0;
262
274
  }
263
- if (!waiting.length && !noteText && options.contexts.has(role) && options.contexts.get(role) >= options.shiftAt) {
264
- const recent = Date.parse(mine.shift || "");
265
- if (Number.isNaN(recent) || now - recent >= SHIFT_EVERY_MS) {
266
- sent.push(sendNudge(where, role, "shift",
267
- `${role}: your context is at ${options.contexts.get(role)}%. Change your own shift: \`keel shift check\`, `
268
- + "then `keel shift ready --wake \"<note>\"`, then clear this session. A session serving Remote Control "
269
- + "cannot be cleared: turn it off, clear, then turn it back on."));
270
- mine.shift = store.isoLocal(new Date(now));
271
- }
275
+ // A finished task is the shift boundary (#313 D2); within a task the host compacts.
276
+ const fresh = (closures.get(role) || []).filter((entry) => !mine.closedSeen.includes(entry.done));
277
+ if (fresh.length && !noteText) {
278
+ const task = fresh[fresh.length - 1];
279
+ const open = store.openTodos(where, { assignee: role }).length;
280
+ const next = open
281
+ ? `\`keel shift ready --wake "<note>"\` — you still hold ${open} open todo(s)`
282
+ : "`keel shift ready \"<note>\"`, and wait for the coordinator to start you with new work";
283
+ sent.push(sendNudge(where, role, "shift",
284
+ `${role}: your task ${task.todo} ("${task.title}") was closed. Change shift at this task boundary: `
285
+ + `\`keel shift check\`, then ${next}, then clear this session (a session serving Remote Control cannot be `
286
+ + "cleared: turn it off, clear, then turn it back on)."));
287
+ mine.closedSeen = [...mine.closedSeen, ...fresh.map((entry) => entry.done)];
272
288
  }
273
289
  if (noteText && noteText.includes(SELF_INITIATED)) {
274
290
  const written = fs.statSync(note).mtime;
@@ -422,7 +438,7 @@ function runPatrol(argv) {
422
438
  throw error;
423
439
  }
424
440
  }
425
- const options = { repo: process.cwd(), issues: null, idle: "30m", json: false, sinceLast: false, notify: false, nudge: false, context: [], shiftAt: 50, diskFreeGb: null, diskMinGb: 20, quota: null, quotaAlerts: [90, 95, 99], quotaQuietAt: 90 };
441
+ const options = { repo: process.cwd(), issues: null, idle: "30m", json: false, sinceLast: false, notify: false, nudge: false, diskFreeGb: null, diskMinGb: 20, quota: null, quotaAlerts: [90, 95, 99], quotaQuietAt: 90 };
426
442
  try {
427
443
  for (let index = 0; index < argv.length; index += 1) {
428
444
  const arg = argv[index];
@@ -430,8 +446,9 @@ function runPatrol(argv) {
430
446
  else if (arg === "--since-last") options.sinceLast = true;
431
447
  else if (arg === "--notify") options.notify = true;
432
448
  else if (arg === "--nudge") options.nudge = true;
433
- else if (arg === "--context") options.context.push(argv[++index] || "");
434
- else if (arg === "--shift-at") options.shiftAt = Number(argv[++index]);
449
+ else if (arg === "--context" || arg === "--shift-at") {
450
+ throw new PatrolError(`${arg}: --context and --shift-at were retired in 5.125.0 (#313): a shift follows a task's close, and compaction within a task stays the host's.`);
451
+ }
435
452
  else if (arg === "--disk-free-gb") options.diskFreeGb = Number(argv[++index]);
436
453
  else if (arg === "--disk-min-gb") options.diskMinGb = Number(argv[++index]);
437
454
  else if (arg === "--quota") options.quota = Number(argv[++index]);
@@ -447,8 +464,6 @@ function runPatrol(argv) {
447
464
  } else throw new PatrolError(`Unknown argument ${arg}. ${USAGE}`);
448
465
  }
449
466
  if (options.notify && !options.sinceLast) throw new PatrolError("--notify sends the risks found since the last run, so it needs --since-last.");
450
- if (!(options.shiftAt > 0 && options.shiftAt <= 100)) throw new PatrolError("--shift-at needs a percentage from 1 to 100.");
451
- options.contexts = parseContexts(options.context);
452
467
  if (options.diskFreeGb !== null && !(options.diskFreeGb >= 0)) throw new PatrolError("--disk-free-gb needs a number of gigabytes.");
453
468
  if (!(options.diskMinGb > 0)) throw new PatrolError("--disk-min-gb needs a positive number of gigabytes.");
454
469
  const percent = (value) => Number.isFinite(value) && value >= 0 && value <= 100;