@christang/keel 5.154.0 → 5.155.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.154.0",
3
+ "version": "5.155.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.154.0 -->
1
+ <!-- keel:start version=5.155.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.
package/bin/keel.js CHANGED
@@ -3041,6 +3041,10 @@ function main() {
3041
3041
  if (process.argv[2] === "patrol") {
3042
3042
  return require("../src/core/patrol").runPatrol(process.argv.slice(3));
3043
3043
  }
3044
+ // `keel tick` likewise: the model-free step a host scheduler calls (#356).
3045
+ if (process.argv[2] === "tick") {
3046
+ return require("../src/core/tick").runTick(process.argv.slice(3));
3047
+ }
3044
3048
  if (process.argv[2] === "worktrees") {
3045
3049
  return require("../src/core/worktrees").runWorktrees(process.argv.slice(3));
3046
3050
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.154.0",
3
+ "version": "5.155.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.154.0",
9
+ "version": "5.155.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.154.0",
5
+ "version": "5.155.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.154.0",
3
+ "version": "5.155.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.154.0",
3
+ "version": "5.155.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",
@@ -661,7 +661,13 @@ function main() {
661
661
  );
662
662
  }
663
663
  // The patrolling role re-arms its schedule after a shift change (#260).
664
- if (context.patrol && context.patrol.role && context.patrol.hostTask) {
664
+ if (context.patrol && context.patrol.role && context.patrol.runner === "tick") {
665
+ // `keel tick` runs it from the host scheduler, which outlives the session.
666
+ lines.push(
667
+ `- patrol: role ${context.patrol.role}'s \`keel patrol\` is run by \`keel tick\` from the host scheduler (render it with \`keel tick task\`), `
668
+ + "which outlives this session; no session schedule is needed."
669
+ );
670
+ } else if (context.patrol && context.patrol.role && context.patrol.hostTask) {
665
671
  // A host scheduled task outlives the session (#295 D3).
666
672
  lines.push(
667
673
  `- patrol: role ${context.patrol.role} runs \`keel patrol\` every ${context.patrol.every} through host scheduled task `
@@ -49,8 +49,8 @@ REQUIRED_SCRIPTS = [
49
49
  "scripts/validate_plugin.py",
50
50
  ]
51
51
 
52
- PACKAGE_VERSION = "5.154.0"
53
- PROTOCOL_VERSION = "5.154.0"
52
+ PACKAGE_VERSION = "5.155.0"
53
+ PROTOCOL_VERSION = "5.155.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
@@ -3100,6 +3100,92 @@ def validate_patrol_next_scenario() -> int:
3100
3100
  return 0
3101
3101
 
3102
3102
 
3103
+ def validate_tick_runs_due_patrol_scenario() -> int:
3104
+ """The owner's CLI waker (2026-10-19, #356): `keel tick` runs the patrol when due.
3105
+
3106
+ A host scheduler (launchd) calls `keel tick` every few minutes; each call
3107
+ is one model-free step. It fetches and patrols only once the last run's
3108
+ recommended `next_at` has passed, records the next one, and otherwise exits
3109
+ quietly. `keel tick task` prints the launchd job and creates nothing.
3110
+ """
3111
+ label = "tick-runs-due-patrol:"
3112
+ with tempfile.TemporaryDirectory(prefix="keel-tick-") as raw:
3113
+ base = Path(raw)
3114
+ rtl, verify, env, _ = shift_scratch(base)
3115
+ write_text(rtl / "openspec/specs/.keep", "")
3116
+ write_authorize_config(rtl, "patrol:\n role: rtl\n every: 60m\n runner: tick\n cadence: adaptive\n")
3117
+ subprocess.run(["git", "add", "-A"], cwd=rtl, check=True, capture_output=True)
3118
+ subprocess.run(["git", "commit", "-q", "-m", "tick"], cwd=rtl, check=True, capture_output=True)
3119
+ store_root = mailbox_common_dir(rtl) / "keel-chat"
3120
+ log = store_root / "patrol" / "log" / "rtl.log"
3121
+ state = store_root / "tick" / "state.json"
3122
+
3123
+ def tick(*args: str) -> subprocess.CompletedProcess[str]:
3124
+ return run_keel(verify, "tick", "--repo", str(rtl), *args, env=env)
3125
+
3126
+ def runs() -> int:
3127
+ return len(log.read_text(encoding="utf-8").splitlines()) if log.exists() else 0
3128
+
3129
+ first = tick()
3130
+ if first.returncode != 0:
3131
+ report(f"{label} the first tick exited {first.returncode}: {first.stdout!r} {first.stderr!r}")
3132
+ return 1
3133
+ if runs() != 1:
3134
+ report(f"{label} the first tick did not run the patrol once: {runs()} log lines; {first.stdout!r}")
3135
+ return 1
3136
+ saved = json.loads(state.read_text(encoding="utf-8")) if state.exists() else {}
3137
+ if not saved.get("patrol", {}).get("next_at"):
3138
+ report(f"{label} the tick did not record the next patrol: {saved!r}")
3139
+ return 1
3140
+ second = tick()
3141
+ if second.returncode != 0 or runs() != 1:
3142
+ report(f"{label} a tick before next_at ran the patrol: {runs()} log lines; {second.stdout!r}")
3143
+ return 1
3144
+ if "not due" not in second.stdout:
3145
+ report(f"{label} a skipped tick does not say the patrol is not due: {second.stdout!r}")
3146
+ return 1
3147
+ saved["patrol"]["next_at"] = "2000-01-01T00:00:00+00:00"
3148
+ state.write_text(json.dumps(saved), encoding="utf-8")
3149
+ tick()
3150
+ if runs() != 2:
3151
+ report(f"{label} a tick after next_at did not run the patrol: {runs()} log lines.")
3152
+ return 1
3153
+
3154
+ rendered = run_keel(rtl, "tick", "task", env=env)
3155
+ if rendered.returncode != 0:
3156
+ report(f"{label} keel tick task failed: {rendered.stderr!r}")
3157
+ return 1
3158
+ for needle in ("<key>Label</key>", "<key>StartInterval</key>", "<integer>300</integer>", "<string>tick</string>",
3159
+ f"<string>{os.path.realpath(rtl)}</string>", "launchctl bootstrap", "Keel creates nothing"):
3160
+ if needle not in rendered.stdout:
3161
+ report(f"{label} keel tick task does not carry {needle!r}: {rendered.stdout!r}")
3162
+ return 1
3163
+ if list((base / "home").glob("**/*.plist")) if (base / "home").exists() else []:
3164
+ report(f"{label} keel tick task wrote a plist.")
3165
+ return 1
3166
+
3167
+ context = json.loads(run_keel(rtl, "context", "--json", env=env).stdout)
3168
+ if (context.get("patrol") or {}).get("runner") != "tick":
3169
+ report(f"{label} the coordinator's context does not carry runner tick: {context.get('patrol')!r}")
3170
+ return 1
3171
+ session = run_session_start_hook(
3172
+ rtl, {"hook_event_name": "SessionStart", "source": "startup", "cwd": str(rtl)},
3173
+ keel_cli=f'node "{ROOT / "bin" / "keel.js"}"',
3174
+ )
3175
+ reminder = session_start_context(session) or ""
3176
+ if "re-create it with the host" in reminder:
3177
+ report(f"{label} with runner: tick the coordinator is still told to re-create a session schedule: {reminder!r}")
3178
+ return 1
3179
+ if "keel tick" not in reminder:
3180
+ report(f"{label} with runner: tick the projection does not name keel tick: {reminder!r}")
3181
+ return 1
3182
+ if "tick-runs-due-patrol" not in {name for name, _ in SCENARIOS}:
3183
+ report(f"{label} scenario is not registered.")
3184
+ return 1
3185
+ report("tick-runs-due-patrol scenario passed.")
3186
+ return 0
3187
+
3188
+
3103
3189
  def validate_patrol_nudge_scenario() -> int:
3104
3190
  """Issues #307 part 1 and #313: the patrol nudges idle roles directly.
3105
3191
 
@@ -42145,6 +42231,7 @@ SCENARIOS: tuple = (
42145
42231
  ("coordinator-patrol", validate_coordinator_patrol_scenario),
42146
42232
  ("patrol-since-last", validate_patrol_since_last_scenario),
42147
42233
  ("patrol-next", validate_patrol_next_scenario),
42234
+ ("tick-runs-due-patrol", validate_tick_runs_due_patrol_scenario),
42148
42235
  ("patrol-exit-says-who-acts", validate_patrol_exit_says_who_acts_scenario),
42149
42236
  ("patrol-nudge", validate_patrol_nudge_scenario),
42150
42237
  ("patrol-escalate", validate_patrol_escalate_scenario),
@@ -955,8 +955,14 @@ function readPatrolDeclaration(repo) {
955
955
  if (window) cadence.quiet = { start: Number(window[1]) * 60 + Number(window[2]), end: Number(window[3]) * 60 + Number(window[4]) };
956
956
  else ignored.push(`quiet \`${block.quiet}\` is not a window such as 23:00-08:30`);
957
957
  }
958
+ // `runner: tick` says `keel tick` runs the patrol from the host scheduler.
959
+ let runner = null;
960
+ if (block.runner !== undefined) {
961
+ if (block.runner === "tick") runner = "tick";
962
+ else ignored.push(`runner \`${block.runner}\` is not tick`);
963
+ }
958
964
  const message = ignored.length ? `keel/config.yaml patrol: ${ignored.join("; ")}, so it is ignored.` : null;
959
- return { declared: true, role: block.role, every: block.every, hostTask, model, message, cadence };
965
+ return { declared: true, role: block.role, every: block.every, hostTask, model, message, cadence, runner };
960
966
  }
961
967
 
962
968
  function durationSeconds(value) {
@@ -965,6 +971,10 @@ function durationSeconds(value) {
965
971
  }
966
972
 
967
973
  function patrolReminder(patrol) {
974
+ if (patrol.runner === "tick") {
975
+ return `Patrol: role ${patrol.role}'s \`keel patrol\` is run by \`keel tick\` from the host scheduler (render it with \`keel tick task\`), `
976
+ + "which outlives this session; no session schedule is needed.";
977
+ }
968
978
  if (patrol.hostTask) {
969
979
  return `Patrol: role ${patrol.role} runs \`keel patrol\` every ${patrol.every} through host scheduled task `
970
980
  + `${patrol.hostTask}, which outlives this session; confirm it is still enabled rather than creating a schedule in this session.`;
@@ -877,6 +877,7 @@ function resolveContext(repo, options) {
877
877
  if (patrol.role && context.role === patrol.role) {
878
878
  context.patrol = { role: patrol.role, every: patrol.every };
879
879
  if (patrol.hostTask) context.patrol.hostTask = patrol.hostTask;
880
+ if (patrol.runner) context.patrol.runner = patrol.runner;
880
881
  }
881
882
  context.warnings.push(...gitWarnings(repo));
882
883
  // A broken `authorize:` declaration is otherwise reported only by
package/src/core/shift.js CHANGED
@@ -1034,7 +1034,7 @@ function runShift(argv) {
1034
1034
  const { readPatrolDeclaration, patrolReminder } = require("./config");
1035
1035
  const patrol = readPatrolDeclaration(where.worktree);
1036
1036
  const remind = patrol.role && result.role === patrol.role;
1037
- if (remind) result.patrol = { role: patrol.role, every: patrol.every, ...(patrol.hostTask ? { hostTask: patrol.hostTask } : {}) };
1037
+ if (remind) result.patrol = { role: patrol.role, every: patrol.every, ...(patrol.hostTask ? { hostTask: patrol.hostTask } : {}), ...(patrol.runner ? { runner: patrol.runner } : {}) };
1038
1038
  // A new coordinator learns whom its previous shift left unstarted (#289 D2).
1039
1039
  const waiting = (result.waiting || []).map((w) => w.role);
1040
1040
  const still = waiting.length ? `\n\nStill waiting for \`keel shift start\`: ${waiting.join(", ")}.` : "";
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+
3
+ // `keel tick` (the owner's CLI waker, 2026-10-19; #356): one model-free step a
4
+ // host scheduler such as launchd calls every few minutes. It runs the patrol
5
+ // only once the last run's recommended `next_at` has passed. The recurrence is
6
+ // the host's: Keel registers nothing, and `keel tick task` prints the job.
7
+ const fs = require("fs");
8
+ const os = require("os");
9
+ const path = require("path");
10
+ const { spawnSync } = require("child_process");
11
+ const store = require("./chat/store");
12
+
13
+ const USAGE = "keel tick [--repo <path>] [--json] one model-free step: run the patrol when it is due\n"
14
+ + " keel tick task [--json] [--repo <path>] print the launchd job that calls it";
15
+ const INTERVAL_SECONDS = 300;
16
+ const KEEL = path.resolve(__dirname, "..", "..", "bin", "keel.js");
17
+
18
+ class TickError extends Error {}
19
+
20
+ function stateFile(where) {
21
+ return path.join(where.root, "tick", "state.json");
22
+ }
23
+
24
+ function readState(where) {
25
+ const state = store.readJsonFile(stateFile(where));
26
+ return state && typeof state === "object" ? state : {};
27
+ }
28
+
29
+ // The patrol runs in the worktree bound to its role, whichever worktree called.
30
+ function patrolWorktree(where) {
31
+ const { readPatrolDeclaration } = require("./config");
32
+ const declaration = readPatrolDeclaration(where.worktree);
33
+ if (!declaration.role) {
34
+ return { declaration, worktree: null, why: declaration.message || "keel/config.yaml declares no `patrol:` with role and every." };
35
+ }
36
+ const bound = Object.entries(store.readJsonFile(path.join(where.root, "roles.json")))
37
+ .filter(([, role]) => role === declaration.role).map(([worktree]) => worktree).sort();
38
+ if (!bound.length) {
39
+ return { declaration, worktree: null, why: `No worktree is bound to role ${declaration.role}; bind one with \`keel chat role --set ${declaration.role}\` there first.` };
40
+ }
41
+ return { declaration, worktree: bound[0], why: null };
42
+ }
43
+
44
+ function tick(where, now = new Date()) {
45
+ const result = { patrol: null };
46
+ const found = patrolWorktree(where);
47
+ if (!found.worktree) {
48
+ result.patrol = { ran: false, why: found.why };
49
+ return result;
50
+ }
51
+ const state = readState(where);
52
+ const due = state.patrol && state.patrol.next_at ? Date.parse(state.patrol.next_at) : NaN;
53
+ if (!Number.isNaN(due) && due > now.getTime()) {
54
+ result.patrol = { ran: false, why: `patrol not due until ${state.patrol.next_at}`, next_at: state.patrol.next_at };
55
+ return result;
56
+ }
57
+ // The host task this replaces fetched first (F1); a failed fetch is reported
58
+ // and the patrol still runs on the refs it has.
59
+ const fetched = spawnSync("git", ["-C", found.worktree, "fetch", "-q", "origin"], { encoding: "utf8" });
60
+ const fetchError = fetched.status === 0 ? null : String(fetched.stderr || fetched.error || "fetch failed").trim();
61
+ const ran = spawnSync(process.execPath, [KEEL, "patrol", "--repo", found.worktree, "--since-last", "--notify", "--json"], {
62
+ cwd: found.worktree, encoding: "utf8",
63
+ });
64
+ let payload = {};
65
+ try {
66
+ payload = JSON.parse(ran.stdout);
67
+ } catch {
68
+ payload = {};
69
+ }
70
+ const next = payload.next_at || null;
71
+ state.patrol = { next_at: next, last_run: store.isoLocal(now), last_exit: ran.status };
72
+ store.writeJsonAtomic(where, stateFile(where), state);
73
+ result.patrol = {
74
+ ran: true, exit: ran.status, next_at: next, rule: payload.next_rule || null,
75
+ fetchError, error: ran.status === 1 ? String(ran.stderr || "").trim() : null,
76
+ };
77
+ return result;
78
+ }
79
+
80
+ function render(result) {
81
+ const p = result.patrol;
82
+ if (!p.ran) return `keel tick: ${p.why}`;
83
+ const lines = [`keel tick: ran the patrol (exit ${p.exit})${p.next_at ? `; next ${p.next_at} (${p.rule})` : ""}`];
84
+ if (p.fetchError) lines.push(`fetch failed: ${p.fetchError}`);
85
+ if (p.error) lines.push(`patrol failed: ${p.error}`);
86
+ return lines.join("\n");
87
+ }
88
+
89
+ function xml(text) {
90
+ return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
91
+ }
92
+
93
+ function task(where) {
94
+ const found = patrolWorktree(where);
95
+ if (!found.worktree) throw new TickError(found.why);
96
+ const label = `dev.keel.tick.${where.project.replace(/[^A-Za-z0-9.-]/g, "-")}`;
97
+ const logs = path.join(where.root, "tick");
98
+ const args = [process.execPath, KEEL, "tick", "--repo", found.worktree];
99
+ const plist = [
100
+ '<?xml version="1.0" encoding="UTF-8"?>',
101
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
102
+ '<plist version="1.0">',
103
+ "<dict>",
104
+ " <key>Label</key>", ` <string>${xml(label)}</string>`,
105
+ " <key>ProgramArguments</key>", " <array>", ...args.map((arg) => ` <string>${xml(arg)}</string>`), " </array>",
106
+ " <key>WorkingDirectory</key>", ` <string>${xml(found.worktree)}</string>`,
107
+ " <key>EnvironmentVariables</key>", " <dict>", " <key>PATH</key>", ` <string>${xml(process.env.PATH || "")}</string>`, " </dict>",
108
+ " <key>StartInterval</key>", ` <integer>${INTERVAL_SECONDS}</integer>`,
109
+ " <key>StandardOutPath</key>", ` <string>${xml(path.join(logs, "tick.log"))}</string>`,
110
+ " <key>StandardErrorPath</key>", ` <string>${xml(path.join(logs, "tick.err"))}</string>`,
111
+ "</dict>",
112
+ "</plist>",
113
+ ].join("\n");
114
+ const target = path.join(os.homedir(), "Library", "LaunchAgents", `${label}.plist`);
115
+ return { label, interval: INTERVAL_SECONDS, worktree: found.worktree, plist, target,
116
+ install: [`mkdir -p ${path.dirname(target)} && cat > ${target} <<'PLIST'\n${plist}\nPLIST`, `launchctl bootstrap gui/${process.getuid ? process.getuid() : "<uid>"} ${target}`] };
117
+ }
118
+
119
+ function renderTask(job) {
120
+ return [
121
+ `launchd job for \`keel tick\` (label ${job.label}): it calls \`keel tick\` every ${job.interval} s, and the tick runs the patrol of the worktree ${job.worktree} when due. Keel creates nothing: install it with the two commands below.`,
122
+ "",
123
+ job.plist,
124
+ "",
125
+ "Install:",
126
+ ...job.install,
127
+ "",
128
+ `Remove: launchctl bootout gui/${process.getuid ? process.getuid() : "<uid>"}/${job.label} && rm ${job.target}`,
129
+ ].join("\n");
130
+ }
131
+
132
+ function runTick(argv) {
133
+ try {
134
+ const options = { repo: process.cwd(), json: false };
135
+ const rest = [];
136
+ for (let index = 0; index < argv.length; index += 1) {
137
+ const arg = argv[index];
138
+ if (arg === "--json") options.json = true;
139
+ else if (arg === "--help" || arg === "-h") {
140
+ process.stdout.write(`${USAGE}\n`);
141
+ return 0;
142
+ } else if (arg === "--repo") {
143
+ const value = argv[++index];
144
+ if (!value || value.startsWith("--")) throw new TickError("--repo needs a path.");
145
+ options.repo = value;
146
+ } else if (arg.startsWith("--")) throw new TickError(`Unknown argument ${arg}. ${USAGE}`);
147
+ else rest.push(arg);
148
+ }
149
+ const where = store.requireLocation(path.resolve(options.repo));
150
+ if (rest[0] === "task") {
151
+ const job = task(where);
152
+ process.stdout.write(`${options.json ? JSON.stringify(job, null, 2) : renderTask(job)}\n`);
153
+ return 0;
154
+ }
155
+ if (rest.length) throw new TickError(`Unknown subcommand ${rest[0]}. ${USAGE}`);
156
+ const result = tick(where);
157
+ process.stdout.write(`${options.json ? JSON.stringify(result, null, 2) : render(result)}\n`);
158
+ return 0;
159
+ } catch (error) {
160
+ if (error instanceof TickError || error instanceof store.ChatError) {
161
+ process.stderr.write(`keel tick: ${error.message}\n`);
162
+ return 1;
163
+ }
164
+ throw error;
165
+ }
166
+ }
167
+
168
+ module.exports = { runTick, tick, TickError };