@christang/keel 5.154.0 → 5.156.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/.claude-plugin/plugin.json +1 -1
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +4 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugins/keel/.claude-plugin/plugin.json +1 -1
- package/plugins/keel/.codex-plugin/plugin.json +1 -1
- package/plugins/keel/scripts/session-start.js +7 -1
- package/scripts/validate_plugin.py +193 -8
- package/src/core/chat/cli.js +24 -2
- package/src/core/chat/notice.js +33 -0
- package/src/core/config.js +11 -1
- package/src/core/context.js +1 -0
- package/src/core/patrol.js +5 -1
- package/src/core/shift.js +1 -1
- package/src/core/tick.js +197 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.156.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",
|
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
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.156.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@christang/keel",
|
|
9
|
-
"version": "5.
|
|
9
|
+
"version": "5.156.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fission-ai/openspec": "^1.4.1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.156.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.
|
|
3
|
+
"version": "5.156.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.
|
|
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.
|
|
53
|
-
PROTOCOL_VERSION = "5.
|
|
52
|
+
PACKAGE_VERSION = "5.156.0"
|
|
53
|
+
PROTOCOL_VERSION = "5.156.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
|
|
@@ -2502,6 +2502,102 @@ def validate_chat_mention_skips_code_scenario() -> int:
|
|
|
2502
2502
|
return 0
|
|
2503
2503
|
|
|
2504
2504
|
|
|
2505
|
+
def validate_chat_wake_now_cli_scenario() -> int:
|
|
2506
|
+
"""Issue #348 on the CLI (owner's CLI waker, 2026-10-19): one step wakes a role.
|
|
2507
|
+
|
|
2508
|
+
A background CLI session's hooks record its session id and process. When
|
|
2509
|
+
that process has exited, `keel chat wake now <role>` resumes it with
|
|
2510
|
+
`claude --bg --resume <id> "<pointer>"` in its worktree — no other flag, so
|
|
2511
|
+
the id is kept — and `keel tick` does the same once per new addressed
|
|
2512
|
+
record. A running session is left to the record itself, which wakes it.
|
|
2513
|
+
"""
|
|
2514
|
+
label = "chat-wake-now-cli:"
|
|
2515
|
+
with tempfile.TemporaryDirectory(prefix="keel-wake-348-") as raw:
|
|
2516
|
+
base = Path(raw)
|
|
2517
|
+
rtl, verify, env, _ = shift_scratch(base)
|
|
2518
|
+
calls = base / "claude-calls.jsonl"
|
|
2519
|
+
fake = base / "fake-claude"
|
|
2520
|
+
write_text(fake, "#!/usr/bin/env python3\nimport json, os, sys\n"
|
|
2521
|
+
f"open({str(calls)!r}, 'a').write(json.dumps({{'argv': sys.argv[1:], 'cwd': os.getcwd()}}) + '\\n')\n"
|
|
2522
|
+
"print('backgrounded · fake')\n")
|
|
2523
|
+
fake.chmod(0o755)
|
|
2524
|
+
env = {**env, "KEEL_CLAUDE": str(fake)}
|
|
2525
|
+
dead = subprocess.Popen(["true"])
|
|
2526
|
+
dead.wait()
|
|
2527
|
+
|
|
2528
|
+
def start(pid: int) -> None:
|
|
2529
|
+
subprocess.run(["node", str(ROOT / "bin" / "keel.js"), "chat", "hook", "session-start"], cwd=verify, text=True,
|
|
2530
|
+
capture_output=True, check=False,
|
|
2531
|
+
env={**env, "CLAUDE_CODE_ENTRYPOINT": "cli", "CLAUDE_CODE_SESSION_ID": "sess-verify-1", "CLAUDE_PID": str(pid)},
|
|
2532
|
+
input=json.dumps({"cwd": str(verify), "hook_event_name": "SessionStart", "session_id": "sess-verify-1", "source": "startup"}))
|
|
2533
|
+
|
|
2534
|
+
def made() -> list[dict]:
|
|
2535
|
+
return [json.loads(line) for line in calls.read_text().splitlines()] if calls.exists() else []
|
|
2536
|
+
|
|
2537
|
+
start(dead.pid)
|
|
2538
|
+
posted = run_keel(rtl, "chat", "dm", "verify", "rerun R009", env=env)
|
|
2539
|
+
if "keel chat wake now verify" not in posted.stdout:
|
|
2540
|
+
report(f"{label} a dm to a role whose CLI process exited does not name `keel chat wake now verify`: {posted.stdout!r}")
|
|
2541
|
+
return 1
|
|
2542
|
+
if "get_session" in posted.stdout:
|
|
2543
|
+
report(f"{label} a CLI role is given the desktop wake step: {posted.stdout!r}")
|
|
2544
|
+
return 1
|
|
2545
|
+
woke = run_keel(rtl, "chat", "wake", "now", "verify", env=env)
|
|
2546
|
+
if woke.returncode != 0:
|
|
2547
|
+
report(f"{label} keel chat wake now failed: {woke.stdout!r} {woke.stderr!r}")
|
|
2548
|
+
return 1
|
|
2549
|
+
if len(made()) != 1:
|
|
2550
|
+
report(f"{label} wake now did not run claude once: {made()!r}")
|
|
2551
|
+
return 1
|
|
2552
|
+
call = made()[0]
|
|
2553
|
+
if call["argv"][:3] != ["--bg", "--resume", "sess-verify-1"] or len(call["argv"]) != 4:
|
|
2554
|
+
report(f"{label} wake now ran claude with {call['argv']!r}, not --bg --resume <id> <prompt> and nothing else.")
|
|
2555
|
+
return 1
|
|
2556
|
+
if "keel chat unread" not in call["argv"][3]:
|
|
2557
|
+
report(f"{label} the resume prompt does not point at keel chat unread: {call['argv'][3]!r}")
|
|
2558
|
+
return 1
|
|
2559
|
+
if os.path.realpath(call["cwd"]) != os.path.realpath(verify):
|
|
2560
|
+
report(f"{label} claude was resumed in {call['cwd']}, not verify's worktree.")
|
|
2561
|
+
return 1
|
|
2562
|
+
|
|
2563
|
+
start(os.getpid())
|
|
2564
|
+
alive = run_keel(rtl, "chat", "wake", "now", "verify", env=env)
|
|
2565
|
+
if len(made()) != 1:
|
|
2566
|
+
report(f"{label} wake now resumed a role whose process is running: {made()!r}")
|
|
2567
|
+
return 1
|
|
2568
|
+
if "running" not in alive.stdout:
|
|
2569
|
+
report(f"{label} wake now does not say the session is running: {alive.stdout!r}")
|
|
2570
|
+
return 1
|
|
2571
|
+
|
|
2572
|
+
start(dead.pid)
|
|
2573
|
+
run_keel(rtl, "chat", "dm", "verify", "rerun R010", env=env)
|
|
2574
|
+
run_keel(verify, "tick", "--repo", str(rtl), env=env)
|
|
2575
|
+
if len(made()) != 2:
|
|
2576
|
+
report(f"{label} keel tick did not wake the exited role for its new record: {made()!r}")
|
|
2577
|
+
return 1
|
|
2578
|
+
run_keel(verify, "tick", "--repo", str(rtl), env=env)
|
|
2579
|
+
if len(made()) != 2:
|
|
2580
|
+
report(f"{label} a second tick woke the role again for the same record: {made()!r}")
|
|
2581
|
+
return 1
|
|
2582
|
+
time.sleep(2)
|
|
2583
|
+
nudged = run_keel(rtl, "patrol", "--nudge", "--idle", "1s", env=env).stdout
|
|
2584
|
+
escalation = next((l for l in nudged.splitlines() if "verify" in l and "wakes nothing" in l), "")
|
|
2585
|
+
if "keel chat wake now verify" not in escalation or "get_session" in escalation:
|
|
2586
|
+
report(f"{label} the patrol's nudge escalation for an ended CLI session is not `keel chat wake now verify`: {nudged!r}")
|
|
2587
|
+
return 1
|
|
2588
|
+
run_keel(rtl, "chat", "role", "--park", "verify", "--reason", "held for review", env=env)
|
|
2589
|
+
run_keel(rtl, "chat", "dm", "verify", "rerun R011", env=env)
|
|
2590
|
+
run_keel(verify, "tick", "--repo", str(rtl), env=env)
|
|
2591
|
+
if len(made()) != 2:
|
|
2592
|
+
report(f"{label} keel tick woke a parked role: {made()!r}")
|
|
2593
|
+
return 1
|
|
2594
|
+
if "chat-wake-now-cli" not in {name for name, _ in SCENARIOS}:
|
|
2595
|
+
report(f"{label} scenario is not registered.")
|
|
2596
|
+
return 1
|
|
2597
|
+
report("chat-wake-now-cli scenario passed.")
|
|
2598
|
+
return 0
|
|
2599
|
+
|
|
2600
|
+
|
|
2505
2601
|
def validate_chat_supersedes_scenario() -> int:
|
|
2506
2602
|
"""Issue #252: a record supersedes its author's earlier one.
|
|
2507
2603
|
|
|
@@ -3100,6 +3196,92 @@ def validate_patrol_next_scenario() -> int:
|
|
|
3100
3196
|
return 0
|
|
3101
3197
|
|
|
3102
3198
|
|
|
3199
|
+
def validate_tick_runs_due_patrol_scenario() -> int:
|
|
3200
|
+
"""The owner's CLI waker (2026-10-19, #356): `keel tick` runs the patrol when due.
|
|
3201
|
+
|
|
3202
|
+
A host scheduler (launchd) calls `keel tick` every few minutes; each call
|
|
3203
|
+
is one model-free step. It fetches and patrols only once the last run's
|
|
3204
|
+
recommended `next_at` has passed, records the next one, and otherwise exits
|
|
3205
|
+
quietly. `keel tick task` prints the launchd job and creates nothing.
|
|
3206
|
+
"""
|
|
3207
|
+
label = "tick-runs-due-patrol:"
|
|
3208
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-") as raw:
|
|
3209
|
+
base = Path(raw)
|
|
3210
|
+
rtl, verify, env, _ = shift_scratch(base)
|
|
3211
|
+
write_text(rtl / "openspec/specs/.keep", "")
|
|
3212
|
+
write_authorize_config(rtl, "patrol:\n role: rtl\n every: 60m\n runner: tick\n cadence: adaptive\n")
|
|
3213
|
+
subprocess.run(["git", "add", "-A"], cwd=rtl, check=True, capture_output=True)
|
|
3214
|
+
subprocess.run(["git", "commit", "-q", "-m", "tick"], cwd=rtl, check=True, capture_output=True)
|
|
3215
|
+
store_root = mailbox_common_dir(rtl) / "keel-chat"
|
|
3216
|
+
log = store_root / "patrol" / "log" / "rtl.log"
|
|
3217
|
+
state = store_root / "tick" / "state.json"
|
|
3218
|
+
|
|
3219
|
+
def tick(*args: str) -> subprocess.CompletedProcess[str]:
|
|
3220
|
+
return run_keel(verify, "tick", "--repo", str(rtl), *args, env=env)
|
|
3221
|
+
|
|
3222
|
+
def runs() -> int:
|
|
3223
|
+
return len(log.read_text(encoding="utf-8").splitlines()) if log.exists() else 0
|
|
3224
|
+
|
|
3225
|
+
first = tick()
|
|
3226
|
+
if first.returncode != 0:
|
|
3227
|
+
report(f"{label} the first tick exited {first.returncode}: {first.stdout!r} {first.stderr!r}")
|
|
3228
|
+
return 1
|
|
3229
|
+
if runs() != 1:
|
|
3230
|
+
report(f"{label} the first tick did not run the patrol once: {runs()} log lines; {first.stdout!r}")
|
|
3231
|
+
return 1
|
|
3232
|
+
saved = json.loads(state.read_text(encoding="utf-8")) if state.exists() else {}
|
|
3233
|
+
if not saved.get("patrol", {}).get("next_at"):
|
|
3234
|
+
report(f"{label} the tick did not record the next patrol: {saved!r}")
|
|
3235
|
+
return 1
|
|
3236
|
+
second = tick()
|
|
3237
|
+
if second.returncode != 0 or runs() != 1:
|
|
3238
|
+
report(f"{label} a tick before next_at ran the patrol: {runs()} log lines; {second.stdout!r}")
|
|
3239
|
+
return 1
|
|
3240
|
+
if "not due" not in second.stdout:
|
|
3241
|
+
report(f"{label} a skipped tick does not say the patrol is not due: {second.stdout!r}")
|
|
3242
|
+
return 1
|
|
3243
|
+
saved["patrol"]["next_at"] = "2000-01-01T00:00:00+00:00"
|
|
3244
|
+
state.write_text(json.dumps(saved), encoding="utf-8")
|
|
3245
|
+
tick()
|
|
3246
|
+
if runs() != 2:
|
|
3247
|
+
report(f"{label} a tick after next_at did not run the patrol: {runs()} log lines.")
|
|
3248
|
+
return 1
|
|
3249
|
+
|
|
3250
|
+
rendered = run_keel(rtl, "tick", "task", env=env)
|
|
3251
|
+
if rendered.returncode != 0:
|
|
3252
|
+
report(f"{label} keel tick task failed: {rendered.stderr!r}")
|
|
3253
|
+
return 1
|
|
3254
|
+
for needle in ("<key>Label</key>", "<key>StartInterval</key>", "<integer>300</integer>", "<string>tick</string>",
|
|
3255
|
+
f"<string>{os.path.realpath(rtl)}</string>", "launchctl bootstrap", "Keel creates nothing"):
|
|
3256
|
+
if needle not in rendered.stdout:
|
|
3257
|
+
report(f"{label} keel tick task does not carry {needle!r}: {rendered.stdout!r}")
|
|
3258
|
+
return 1
|
|
3259
|
+
if list((base / "home").glob("**/*.plist")) if (base / "home").exists() else []:
|
|
3260
|
+
report(f"{label} keel tick task wrote a plist.")
|
|
3261
|
+
return 1
|
|
3262
|
+
|
|
3263
|
+
context = json.loads(run_keel(rtl, "context", "--json", env=env).stdout)
|
|
3264
|
+
if (context.get("patrol") or {}).get("runner") != "tick":
|
|
3265
|
+
report(f"{label} the coordinator's context does not carry runner tick: {context.get('patrol')!r}")
|
|
3266
|
+
return 1
|
|
3267
|
+
session = run_session_start_hook(
|
|
3268
|
+
rtl, {"hook_event_name": "SessionStart", "source": "startup", "cwd": str(rtl)},
|
|
3269
|
+
keel_cli=f'node "{ROOT / "bin" / "keel.js"}"',
|
|
3270
|
+
)
|
|
3271
|
+
reminder = session_start_context(session) or ""
|
|
3272
|
+
if "re-create it with the host" in reminder:
|
|
3273
|
+
report(f"{label} with runner: tick the coordinator is still told to re-create a session schedule: {reminder!r}")
|
|
3274
|
+
return 1
|
|
3275
|
+
if "keel tick" not in reminder:
|
|
3276
|
+
report(f"{label} with runner: tick the projection does not name keel tick: {reminder!r}")
|
|
3277
|
+
return 1
|
|
3278
|
+
if "tick-runs-due-patrol" not in {name for name, _ in SCENARIOS}:
|
|
3279
|
+
report(f"{label} scenario is not registered.")
|
|
3280
|
+
return 1
|
|
3281
|
+
report("tick-runs-due-patrol scenario passed.")
|
|
3282
|
+
return 0
|
|
3283
|
+
|
|
3284
|
+
|
|
3103
3285
|
def validate_patrol_nudge_scenario() -> int:
|
|
3104
3286
|
"""Issues #307 part 1 and #313: the patrol nudges idle roles directly.
|
|
3105
3287
|
|
|
@@ -24428,7 +24610,7 @@ def validate_update_host_query_timeout_scenario() -> int:
|
|
|
24428
24610
|
"KEEL_UPDATE_NPM": str(launchers["npm"]),
|
|
24429
24611
|
"KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
|
|
24430
24612
|
"KEEL_UPDATE_CODEX": str(launchers["codex"]),
|
|
24431
|
-
"KEEL_UPDATE_QUERY_TIMEOUT_MS": "
|
|
24613
|
+
"KEEL_UPDATE_QUERY_TIMEOUT_MS": "30000",
|
|
24432
24614
|
"CODEX_HOME": str(tmp / "codex-home"),
|
|
24433
24615
|
"FAKE_LOG": str(log), "FAKE_STATE": str(state),
|
|
24434
24616
|
"FAKE_CODEX_SOURCE": str(source),
|
|
@@ -24453,12 +24635,13 @@ def validate_update_host_query_timeout_scenario() -> int:
|
|
|
24453
24635
|
report(f"{label} a claude plugin list --json that exited 3 does not read failed with exited 3: {claude!r}")
|
|
24454
24636
|
return 1
|
|
24455
24637
|
|
|
24456
|
-
|
|
24638
|
+
# Only the hung case needs a short limit; the others keep 30 s, so load cannot trip them.
|
|
24639
|
+
result, calls, took = update(env_extra={"FAKE_LIST_SLEEP_CODEX": "15", "KEEL_UPDATE_QUERY_TIMEOUT_MS": "4000"})
|
|
24457
24640
|
codex = line(result.stdout, "codex plugin")
|
|
24458
24641
|
if "absent" in codex:
|
|
24459
24642
|
report(f"{label} a hung codex plugin list --json was reported absent: {codex!r}")
|
|
24460
24643
|
return 1
|
|
24461
|
-
for needle in ("failed", "codex plugin list --json", "
|
|
24644
|
+
for needle in ("failed", "codex plugin list --json", "4 s"):
|
|
24462
24645
|
if needle not in codex:
|
|
24463
24646
|
report(f"{label} the hung-query line does not name {needle!r}: {codex!r}")
|
|
24464
24647
|
return 1
|
|
@@ -24471,8 +24654,8 @@ def validate_update_host_query_timeout_scenario() -> int:
|
|
|
24471
24654
|
if result.returncode == 0:
|
|
24472
24655
|
report(f"{label} a failed query left keel --update exiting 0.")
|
|
24473
24656
|
return 1
|
|
24474
|
-
if took >
|
|
24475
|
-
report(f"{label} the hung query held keel --update for {took:.1f} s, past
|
|
24657
|
+
if took > 20:
|
|
24658
|
+
report(f"{label} the hung query held keel --update for {took:.1f} s, past two 4 s attempts.")
|
|
24476
24659
|
return 1
|
|
24477
24660
|
|
|
24478
24661
|
result, _, _ = update(env_extra={"KEEL_UPDATE_CODEX": str(tmp / "no-such-codex")})
|
|
@@ -24480,7 +24663,7 @@ def validate_update_host_query_timeout_scenario() -> int:
|
|
|
24480
24663
|
report(f"{label} a missing codex executable no longer reads absent: {result.stdout!r}")
|
|
24481
24664
|
return 1
|
|
24482
24665
|
|
|
24483
|
-
result, _, _ = update("--dry-run", env_extra={"FAKE_LIST_SLEEP_CODEX": "
|
|
24666
|
+
result, _, _ = update("--dry-run", env_extra={"FAKE_LIST_SLEEP_CODEX": "15", "KEEL_UPDATE_QUERY_TIMEOUT_MS": "4000"})
|
|
24484
24667
|
if result.returncode != 0:
|
|
24485
24668
|
report(f"{label} --dry-run with a hung query exited {result.returncode}: {result.stdout!r}")
|
|
24486
24669
|
return 1
|
|
@@ -42141,10 +42324,12 @@ SCENARIOS: tuple = (
|
|
|
42141
42324
|
("resource-lock", validate_resource_lock_scenario),
|
|
42142
42325
|
("chat-supersedes", validate_chat_supersedes_scenario),
|
|
42143
42326
|
("chat-mention-skips-code", validate_chat_mention_skips_code_scenario),
|
|
42327
|
+
("chat-wake-now-cli", validate_chat_wake_now_cli_scenario),
|
|
42144
42328
|
("chat-ack", validate_chat_ack_scenario),
|
|
42145
42329
|
("coordinator-patrol", validate_coordinator_patrol_scenario),
|
|
42146
42330
|
("patrol-since-last", validate_patrol_since_last_scenario),
|
|
42147
42331
|
("patrol-next", validate_patrol_next_scenario),
|
|
42332
|
+
("tick-runs-due-patrol", validate_tick_runs_due_patrol_scenario),
|
|
42148
42333
|
("patrol-exit-says-who-acts", validate_patrol_exit_says_who_acts_scenario),
|
|
42149
42334
|
("patrol-nudge", validate_patrol_nudge_scenario),
|
|
42150
42335
|
("patrol-escalate", validate_patrol_escalate_scenario),
|
package/src/core/chat/cli.js
CHANGED
|
@@ -52,6 +52,7 @@ const USAGE = [
|
|
|
52
52
|
"keel chat wake remove (stop waking this worktree's role on this machine)",
|
|
53
53
|
"keel chat wake status [--json]",
|
|
54
54
|
"keel chat wake run --once [--worktree <path>] (what the waker's LaunchAgent runs)",
|
|
55
|
+
"keel chat wake now <role> (resume a role whose Claude Code CLI session has ended: claude --bg --resume <its id>)",
|
|
55
56
|
"Every command takes --repo <path> to act on another repository.",
|
|
56
57
|
];
|
|
57
58
|
|
|
@@ -248,7 +249,11 @@ function postResult(where, record, json) {
|
|
|
248
249
|
+ "this waits until it is unparked or its session runs again — route anything urgent through the coordinator.");
|
|
249
250
|
}
|
|
250
251
|
for (const role of offline) lines.push(`Queued for ${role}: offline; it will see this when its session next starts.`);
|
|
251
|
-
for (const entry of asleep) {
|
|
252
|
+
for (const entry of asleep.filter((item) => item.cli)) {
|
|
253
|
+
lines.push(`${entry.role}'s CLI session ${entry.session} has no running process, so this record alone wakes nothing; `
|
|
254
|
+
+ `resume it with \`keel chat wake now ${entry.role}\` (#348).`);
|
|
255
|
+
}
|
|
256
|
+
for (const entry of asleep.filter((item) => !item.cli)) {
|
|
252
257
|
lines.push(`${entry.role}'s desktop session ${entry.session} has no running process, so this record alone wakes nothing (#331). `
|
|
253
258
|
+ notice.wakeStep(entry.session, "You have unread keel chat records; run `keel chat unread`."));
|
|
254
259
|
}
|
|
@@ -676,8 +681,25 @@ function runWake(cwd, options) {
|
|
|
676
681
|
if (options.json) out(JSON.stringify(result));
|
|
677
682
|
return 0;
|
|
678
683
|
}
|
|
684
|
+
case "now": {
|
|
685
|
+
// One step for a role whose CLI session ended (#348 D3).
|
|
686
|
+
const role = options.positionals[2];
|
|
687
|
+
if (!role) throw new ChatError("keel chat wake now needs a role.");
|
|
688
|
+
store.checkName(role, "Role");
|
|
689
|
+
const where = store.requireLocation(cwd);
|
|
690
|
+
const presence = store.readJsonFile(path.join(where.root, "presence", `${role}.json`));
|
|
691
|
+
if (!presence.cli_session) throw new ChatError(`${role} has recorded no Claude Code CLI session, so there is nothing to resume.`);
|
|
692
|
+
const entry = notice.asleep(where, role);
|
|
693
|
+
if (!entry || !entry.cli) {
|
|
694
|
+
out(`${role}'s CLI session ${presence.cli_session} is running; a record addressed to it wakes it, so nothing was resumed.`);
|
|
695
|
+
return 0;
|
|
696
|
+
}
|
|
697
|
+
const resumed = notice.resumeCli(entry);
|
|
698
|
+
out(`${resumed.ok ? "Resumed" : "Could not resume"} ${role}'s CLI session ${entry.session} in ${entry.worktree}.${resumed.output ? `\n${resumed.output}` : ""}`);
|
|
699
|
+
return resumed.ok ? 0 : 1;
|
|
700
|
+
}
|
|
679
701
|
default:
|
|
680
|
-
throw new ChatError(`Unknown keel chat wake action ${JSON.stringify(action)}: use add, remove, status, or
|
|
702
|
+
throw new ChatError(`Unknown keel chat wake action ${JSON.stringify(action)}: use add, remove, status, run, or now.`);
|
|
681
703
|
}
|
|
682
704
|
}
|
|
683
705
|
|
package/src/core/chat/notice.js
CHANGED
|
@@ -97,6 +97,10 @@ function touchPresence(where, role, state = "online", host = null, started = nul
|
|
|
97
97
|
...(state === "offline"
|
|
98
98
|
? { desktop_session: previous.desktop_session || null, desktop_pid: previous.desktop_pid || null }
|
|
99
99
|
: desktopFields()),
|
|
100
|
+
// A Claude Code CLI session and its process, for the same reason (#348 D1).
|
|
101
|
+
...(state === "offline"
|
|
102
|
+
? { cli_session: previous.cli_session || null, cli_pid: previous.cli_pid || null, cli_worktree: previous.cli_worktree || null }
|
|
103
|
+
: cliFields(where)),
|
|
100
104
|
};
|
|
101
105
|
try {
|
|
102
106
|
store.writeJsonAtomic(where, presenceFile(where, role), record);
|
|
@@ -111,6 +115,13 @@ function desktopFields() {
|
|
|
111
115
|
return { desktop_session: id, desktop_pid: require("../shift").desktopProcess() };
|
|
112
116
|
}
|
|
113
117
|
|
|
118
|
+
function cliFields(where) {
|
|
119
|
+
const id = process.env.CLAUDE_CODE_SESSION_ID;
|
|
120
|
+
if (process.env.CLAUDE_CODE_ENTRYPOINT !== "cli" || !id) return { cli_session: null, cli_pid: null, cli_worktree: null };
|
|
121
|
+
const pid = Number(process.env.CLAUDE_PID);
|
|
122
|
+
return { cli_session: id, cli_pid: Number.isInteger(pid) && pid > 1 ? pid : null, cli_worktree: where.worktree };
|
|
123
|
+
}
|
|
124
|
+
|
|
114
125
|
function running(pid) {
|
|
115
126
|
try {
|
|
116
127
|
process.kill(pid, 0);
|
|
@@ -124,6 +135,13 @@ function running(pid) {
|
|
|
124
135
|
// record until something resumes it (#331 D2, measured in #320).
|
|
125
136
|
function asleep(where, role) {
|
|
126
137
|
const record = store.readJsonFile(presenceFile(where, role));
|
|
138
|
+
// An ended CLI session is resumed by `keel chat wake now` (#348 D2).
|
|
139
|
+
if (!record.desktop_session && record.cli_session) {
|
|
140
|
+
const cliPid = Number(record.cli_pid);
|
|
141
|
+
return Number.isInteger(cliPid) && cliPid > 1 && !running(cliPid)
|
|
142
|
+
? { role, session: record.cli_session, cli: true, worktree: record.cli_worktree || null }
|
|
143
|
+
: null;
|
|
144
|
+
}
|
|
127
145
|
if (!record.desktop_session) return null;
|
|
128
146
|
// With no process found when it was recorded, Keel cannot tell, and says nothing.
|
|
129
147
|
const pid = Number(record.desktop_pid);
|
|
@@ -136,6 +154,20 @@ function wakeStep(session, text) {
|
|
|
136
154
|
+ `then call \`send_message\` to \`${session}\` with ${JSON.stringify(text)}.`;
|
|
137
155
|
}
|
|
138
156
|
|
|
157
|
+
// The prompt an ended CLI session resumes with: a pointer, never the work.
|
|
158
|
+
const CLI_WAKE_PROMPT = "You have unread keel chat records; run keel context, then keel chat unread.";
|
|
159
|
+
|
|
160
|
+
// Resumes a role's recorded CLI session (#348 D3). Only `--bg --resume <id>`
|
|
161
|
+
// and the prompt: any other flag starts a copy with a new session id.
|
|
162
|
+
function resumeCli(entry) {
|
|
163
|
+
const claude = process.env.KEEL_CLAUDE || "claude";
|
|
164
|
+
const result = require("child_process").spawnSync(claude, ["--bg", "--resume", entry.session, CLI_WAKE_PROMPT], {
|
|
165
|
+
cwd: entry.worktree || undefined, encoding: "utf8",
|
|
166
|
+
});
|
|
167
|
+
const output = `${result.stdout || ""}${result.stderr || ""}`.trim();
|
|
168
|
+
return { ok: !result.error && result.status === 0, output: result.error ? result.error.message : output };
|
|
169
|
+
}
|
|
170
|
+
|
|
139
171
|
// --- parked roles (#316) ------------------------------------------------------------
|
|
140
172
|
|
|
141
173
|
function parkFile(where, role) {
|
|
@@ -519,6 +551,7 @@ module.exports = {
|
|
|
519
551
|
parkOf,
|
|
520
552
|
unpark,
|
|
521
553
|
wakeStep,
|
|
554
|
+
resumeCli,
|
|
522
555
|
check,
|
|
523
556
|
bridgeLine,
|
|
524
557
|
keptFile,
|
package/src/core/config.js
CHANGED
|
@@ -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.`;
|
package/src/core/context.js
CHANGED
|
@@ -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/patrol.js
CHANGED
|
@@ -308,7 +308,11 @@ function nudgeRoles(where, patroller, options) {
|
|
|
308
308
|
// A nudge to a desktop session with no running process wakes nothing,
|
|
309
309
|
// so the coordinator hears it on the first one (#331 D4).
|
|
310
310
|
const sleeping = sent.some((entry) => entry.role === role) ? notice.asleep(where, role) : null;
|
|
311
|
-
if (sleeping) {
|
|
311
|
+
if (sleeping && sleeping.cli) {
|
|
312
|
+
// An ended CLI session is resumed in one step (#348 D5).
|
|
313
|
+
escalations.push(`${role}'s CLI session ${sleeping.session} has no running process, so the nudge wakes nothing: `
|
|
314
|
+
+ `resume it with \`keel chat wake now ${role}\`.`);
|
|
315
|
+
} else if (sleeping) {
|
|
312
316
|
escalations.push(`${role}'s desktop session ${sleeping.session} has no running process, so the nudge wakes nothing: `
|
|
313
317
|
+ notice.wakeStep(sleeping.session, "You have unread keel chat records; run `keel chat unread`."));
|
|
314
318
|
}
|
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(", ")}.` : "";
|
package/src/core/tick.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
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
|
+
// Roles whose CLI session ended while a record addressed to them waits are
|
|
45
|
+
// resumed once per new record (#348 D4); a parked role is left alone.
|
|
46
|
+
function wakeEnded(where, state) {
|
|
47
|
+
const notice = require("./chat/notice");
|
|
48
|
+
const roles = [...new Set(Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean))].sort();
|
|
49
|
+
state.woken = state.woken || {};
|
|
50
|
+
const woken = [];
|
|
51
|
+
for (const role of roles) {
|
|
52
|
+
if (notice.parkOf(where, role)) continue;
|
|
53
|
+
const entry = notice.asleep(where, role);
|
|
54
|
+
if (!entry || !entry.cli) continue;
|
|
55
|
+
const waiting = store.unread(where, role).filter((record) => store.wakes(record, role)).map((record) => record.id).sort();
|
|
56
|
+
const newest = waiting[waiting.length - 1];
|
|
57
|
+
if (!newest || (state.woken[role] && state.woken[role] >= newest)) continue;
|
|
58
|
+
const resumed = notice.resumeCli(entry);
|
|
59
|
+
state.woken[role] = newest;
|
|
60
|
+
woken.push({ role, session: entry.session, record: newest, ok: resumed.ok, output: resumed.output });
|
|
61
|
+
}
|
|
62
|
+
return woken;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function tick(where, now = new Date()) {
|
|
66
|
+
const result = { patrol: null, woken: [] };
|
|
67
|
+
const wakeState = readState(where);
|
|
68
|
+
result.woken = wakeEnded(where, wakeState);
|
|
69
|
+
if (result.woken.length) store.writeJsonAtomic(where, stateFile(where), { ...readState(where), woken: wakeState.woken });
|
|
70
|
+
const found = patrolWorktree(where);
|
|
71
|
+
if (!found.worktree) {
|
|
72
|
+
result.patrol = { ran: false, why: found.why };
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
const state = readState(where);
|
|
76
|
+
const due = state.patrol && state.patrol.next_at ? Date.parse(state.patrol.next_at) : NaN;
|
|
77
|
+
if (!Number.isNaN(due) && due > now.getTime()) {
|
|
78
|
+
result.patrol = { ran: false, why: `patrol not due until ${state.patrol.next_at}`, next_at: state.patrol.next_at };
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
// The host task this replaces fetched first (F1); a failed fetch is reported
|
|
82
|
+
// and the patrol still runs on the refs it has.
|
|
83
|
+
const fetched = spawnSync("git", ["-C", found.worktree, "fetch", "-q", "origin"], { encoding: "utf8" });
|
|
84
|
+
const fetchError = fetched.status === 0 ? null : String(fetched.stderr || fetched.error || "fetch failed").trim();
|
|
85
|
+
const ran = spawnSync(process.execPath, [KEEL, "patrol", "--repo", found.worktree, "--since-last", "--notify", "--json"], {
|
|
86
|
+
cwd: found.worktree, encoding: "utf8",
|
|
87
|
+
});
|
|
88
|
+
let payload = {};
|
|
89
|
+
try {
|
|
90
|
+
payload = JSON.parse(ran.stdout);
|
|
91
|
+
} catch {
|
|
92
|
+
payload = {};
|
|
93
|
+
}
|
|
94
|
+
const next = payload.next_at || null;
|
|
95
|
+
state.patrol = { next_at: next, last_run: store.isoLocal(now), last_exit: ran.status };
|
|
96
|
+
store.writeJsonAtomic(where, stateFile(where), state);
|
|
97
|
+
result.patrol = {
|
|
98
|
+
ran: true, exit: ran.status, next_at: next, rule: payload.next_rule || null,
|
|
99
|
+
fetchError, error: ran.status === 1 ? String(ran.stderr || "").trim() : null,
|
|
100
|
+
};
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function render(result) {
|
|
105
|
+
const woke = (result.woken || []).map((w) => `keel tick: ${w.ok ? "resumed" : "could not resume"} ${w.role}'s CLI session ${w.session} for ${w.record}`);
|
|
106
|
+
return [...woke, renderPatrol(result)].join("\n");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function renderPatrol(result) {
|
|
110
|
+
const p = result.patrol;
|
|
111
|
+
if (!p.ran) return `keel tick: ${p.why}`;
|
|
112
|
+
const lines = [`keel tick: ran the patrol (exit ${p.exit})${p.next_at ? `; next ${p.next_at} (${p.rule})` : ""}`];
|
|
113
|
+
if (p.fetchError) lines.push(`fetch failed: ${p.fetchError}`);
|
|
114
|
+
if (p.error) lines.push(`patrol failed: ${p.error}`);
|
|
115
|
+
return lines.join("\n");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function xml(text) {
|
|
119
|
+
return String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function task(where) {
|
|
123
|
+
const found = patrolWorktree(where);
|
|
124
|
+
if (!found.worktree) throw new TickError(found.why);
|
|
125
|
+
const label = `dev.keel.tick.${where.project.replace(/[^A-Za-z0-9.-]/g, "-")}`;
|
|
126
|
+
const logs = path.join(where.root, "tick");
|
|
127
|
+
const args = [process.execPath, KEEL, "tick", "--repo", found.worktree];
|
|
128
|
+
const plist = [
|
|
129
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
130
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
131
|
+
'<plist version="1.0">',
|
|
132
|
+
"<dict>",
|
|
133
|
+
" <key>Label</key>", ` <string>${xml(label)}</string>`,
|
|
134
|
+
" <key>ProgramArguments</key>", " <array>", ...args.map((arg) => ` <string>${xml(arg)}</string>`), " </array>",
|
|
135
|
+
" <key>WorkingDirectory</key>", ` <string>${xml(found.worktree)}</string>`,
|
|
136
|
+
" <key>EnvironmentVariables</key>", " <dict>", " <key>PATH</key>", ` <string>${xml(process.env.PATH || "")}</string>`, " </dict>",
|
|
137
|
+
" <key>StartInterval</key>", ` <integer>${INTERVAL_SECONDS}</integer>`,
|
|
138
|
+
" <key>StandardOutPath</key>", ` <string>${xml(path.join(logs, "tick.log"))}</string>`,
|
|
139
|
+
" <key>StandardErrorPath</key>", ` <string>${xml(path.join(logs, "tick.err"))}</string>`,
|
|
140
|
+
"</dict>",
|
|
141
|
+
"</plist>",
|
|
142
|
+
].join("\n");
|
|
143
|
+
const target = path.join(os.homedir(), "Library", "LaunchAgents", `${label}.plist`);
|
|
144
|
+
return { label, interval: INTERVAL_SECONDS, worktree: found.worktree, plist, target,
|
|
145
|
+
install: [`mkdir -p ${path.dirname(target)} && cat > ${target} <<'PLIST'\n${plist}\nPLIST`, `launchctl bootstrap gui/${process.getuid ? process.getuid() : "<uid>"} ${target}`] };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function renderTask(job) {
|
|
149
|
+
return [
|
|
150
|
+
`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.`,
|
|
151
|
+
"",
|
|
152
|
+
job.plist,
|
|
153
|
+
"",
|
|
154
|
+
"Install:",
|
|
155
|
+
...job.install,
|
|
156
|
+
"",
|
|
157
|
+
`Remove: launchctl bootout gui/${process.getuid ? process.getuid() : "<uid>"}/${job.label} && rm ${job.target}`,
|
|
158
|
+
].join("\n");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function runTick(argv) {
|
|
162
|
+
try {
|
|
163
|
+
const options = { repo: process.cwd(), json: false };
|
|
164
|
+
const rest = [];
|
|
165
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
166
|
+
const arg = argv[index];
|
|
167
|
+
if (arg === "--json") options.json = true;
|
|
168
|
+
else if (arg === "--help" || arg === "-h") {
|
|
169
|
+
process.stdout.write(`${USAGE}\n`);
|
|
170
|
+
return 0;
|
|
171
|
+
} else if (arg === "--repo") {
|
|
172
|
+
const value = argv[++index];
|
|
173
|
+
if (!value || value.startsWith("--")) throw new TickError("--repo needs a path.");
|
|
174
|
+
options.repo = value;
|
|
175
|
+
} else if (arg.startsWith("--")) throw new TickError(`Unknown argument ${arg}. ${USAGE}`);
|
|
176
|
+
else rest.push(arg);
|
|
177
|
+
}
|
|
178
|
+
const where = store.requireLocation(path.resolve(options.repo));
|
|
179
|
+
if (rest[0] === "task") {
|
|
180
|
+
const job = task(where);
|
|
181
|
+
process.stdout.write(`${options.json ? JSON.stringify(job, null, 2) : renderTask(job)}\n`);
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
if (rest.length) throw new TickError(`Unknown subcommand ${rest[0]}. ${USAGE}`);
|
|
185
|
+
const result = tick(where);
|
|
186
|
+
process.stdout.write(`${options.json ? JSON.stringify(result, null, 2) : render(result)}\n`);
|
|
187
|
+
return 0;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error instanceof TickError || error instanceof store.ChatError) {
|
|
190
|
+
process.stderr.write(`keel tick: ${error.message}\n`);
|
|
191
|
+
return 1;
|
|
192
|
+
}
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
module.exports = { runTick, tick, TickError };
|