@christang/keel 5.162.0 → 5.164.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 +4 -1
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +18 -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/commands/shift.md +47 -0
- package/scripts/validate_plugin.py +161 -2
- package/src/core/chat/lifecycle.js +3 -2
- package/src/core/chat/wake.js +3 -2
- package/src/core/launchd.js +76 -0
- package/src/core/tick.js +3 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.164.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",
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
"agents": [
|
|
21
21
|
"./plugins/keel/agents/keel-single-task-goal-claude.md"
|
|
22
22
|
],
|
|
23
|
+
"commands": [
|
|
24
|
+
"./plugins/keel/commands/shift.md"
|
|
25
|
+
],
|
|
23
26
|
"hooks": {
|
|
24
27
|
"SessionStart": [
|
|
25
28
|
{
|
package/bin/keel.js
CHANGED
|
@@ -2314,12 +2314,30 @@ function runDoctor(options) {
|
|
|
2314
2314
|
printFastPrePushSurface(repo);
|
|
2315
2315
|
printSourceRepoCliResolution(repo);
|
|
2316
2316
|
printChatRoleDrift(repo);
|
|
2317
|
+
printLaunchdJobs();
|
|
2317
2318
|
|
|
2318
2319
|
return authorizationOk ? checkStatus : 1;
|
|
2319
2320
|
}
|
|
2320
2321
|
|
|
2321
2322
|
// Chat role bindings that drifted from where sessions run (#301 D3). Nothing
|
|
2322
2323
|
// is printed without a chat store that binds roles.
|
|
2324
|
+
// A launchd job that names a node an upgrade removed fails silently every
|
|
2325
|
+
// interval (#387); the report does not change doctor's exit status, since the
|
|
2326
|
+
// job belongs to the machine and not to this repository.
|
|
2327
|
+
function printLaunchdJobs() {
|
|
2328
|
+
const jobs = require("../src/core/launchd").inspectJobs();
|
|
2329
|
+
if (!jobs.length) return;
|
|
2330
|
+
const gone = jobs.filter((job) => !job.exists);
|
|
2331
|
+
for (const job of gone) {
|
|
2332
|
+
printDoctorLine(
|
|
2333
|
+
"launchd",
|
|
2334
|
+
"problem",
|
|
2335
|
+
`${job.name} runs ${job.program || "no program"}, which does not exist; re-create it with \`${job.recreate}\``
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
2338
|
+
if (!gone.length) printDoctorLine("launchd", "ok", `${jobs.length} dev.keel job${jobs.length === 1 ? "" : "s"}, each naming a node that exists`);
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2323
2341
|
function printChatRoleDrift(repo) {
|
|
2324
2342
|
let where = null;
|
|
2325
2343
|
try {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.164.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.164.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.164.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.164.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",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Change this session's own shift — check for loose ends, write the hand-off note, arm the wake
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Change this session's shift: leave a note for the next one and let Keel start it. The mechanism is `keel shift`; this command only orders the steps. `docs/shift-change.md` in the Keel package says more when a step below is not enough.
|
|
6
|
+
|
|
7
|
+
## 1. Check for loose ends
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
keel shift check
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Exit 0 means ready. Exit 1 lists items. Deal with each before going on, or stop and ask the owner when one is not yours to settle:
|
|
14
|
+
|
|
15
|
+
- Uncommitted changes, unpushed commits, a write guard, a lock lease, a linked worktree: commit and push, run `keel guard clear`, release the lease, or remove the worktree you made. Do not discard work to make the list empty.
|
|
16
|
+
- A process: tell the host's from yours. A keep-awake the host started under this session, such as `caffeinate -i -t 300`, ends by itself, so it may stay. A server, watcher or job you started is yours: stop it, or ask the owner before leaving it running.
|
|
17
|
+
|
|
18
|
+
A shift in the middle of a task throws away working state that compaction would have kept. If the task is not at a boundary, say so to the owner before going on.
|
|
19
|
+
|
|
20
|
+
## 2. Write the hand-off note
|
|
21
|
+
|
|
22
|
+
The note is all the next shift has. Put in it:
|
|
23
|
+
|
|
24
|
+
- what you did, and where it lives: branch, worktree, PR, issue, file;
|
|
25
|
+
- the next step, concrete enough to start from;
|
|
26
|
+
- what you are waiting on, and what it unblocks;
|
|
27
|
+
- what you left running or uncommitted on purpose, and why.
|
|
28
|
+
|
|
29
|
+
Name commits and branches by id; `keel shift resume` checks them against the remote. Carry over what the owner already approved, because the next shift cannot ask this one.
|
|
30
|
+
|
|
31
|
+
## 3. Hand over
|
|
32
|
+
|
|
33
|
+
Use a quoted heredoc, so backticks in the note are not run. When step 1 listed only the host's own processes, add `--force-reason "<which process, and that the host owns it>"`.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
keel shift ready --wake --file - <<'EOF'
|
|
37
|
+
<the note>
|
|
38
|
+
EOF
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Read what it prints and do what it says for this host:
|
|
42
|
+
|
|
43
|
+
- Claude CLI background session: end your turn at once with one short line. A waiter replaces this session when it has finished, so do not start other work or ask the owner anything after `ready`: a session waiting on an answer is not replaced.
|
|
44
|
+
- Claude desktop app: it prints four steps. Take them without pausing when `keel/config.yaml` declares `self-shift` under `authorize:`, and ask the owner first when it does not.
|
|
45
|
+
- No chat role: `ready` is refused and names `keel chat role --set`. Bind a role first, or ask the owner who starts the new session.
|
|
46
|
+
|
|
47
|
+
The one line you end on names the note's path and where the next session starts.
|
|
@@ -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.164.0"
|
|
53
|
+
PROTOCOL_VERSION = "5.164.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
|
|
@@ -3365,6 +3365,163 @@ def validate_patrol_next_scenario() -> int:
|
|
|
3365
3365
|
return 0
|
|
3366
3366
|
|
|
3367
3367
|
|
|
3368
|
+
def validate_launchd_stable_node_scenario() -> int:
|
|
3369
|
+
"""Issue #387: a launchd job must name a node that outlives `brew upgrade`.
|
|
3370
|
+
|
|
3371
|
+
`keel tick task` printed `process.execPath`, Homebrew's versioned Cellar
|
|
3372
|
+
path, which is gone after an upgrade; launchd then fails silently every
|
|
3373
|
+
interval. The jobs now name the `node` on PATH that is the same binary (the
|
|
3374
|
+
symlink the package manager keeps current), leave plugin cache directories
|
|
3375
|
+
out of PATH, and `keel --doctor` reports a job whose node no longer exists.
|
|
3376
|
+
"""
|
|
3377
|
+
label = "launchd-stable-node:"
|
|
3378
|
+
with tempfile.TemporaryDirectory(prefix="keel-launchd-387-") as raw:
|
|
3379
|
+
base = Path(raw)
|
|
3380
|
+
rtl, cx, env, _ = chat_wake_scratch(base)
|
|
3381
|
+
real = os.path.realpath(shutil.which("node") or "node")
|
|
3382
|
+
versioned = base / "cellar" / "node" / "9.9.9" / "bin"
|
|
3383
|
+
versioned.mkdir(parents=True)
|
|
3384
|
+
(versioned / "node").symlink_to(real)
|
|
3385
|
+
stable = base / "bin"
|
|
3386
|
+
stable.mkdir()
|
|
3387
|
+
(stable / "node").symlink_to(versioned / "node")
|
|
3388
|
+
cache = base / "home" / ".claude" / "plugins" / "cache" / "keel-marketplace" / "keel" / "5.149.0" / "bin"
|
|
3389
|
+
cache.mkdir(parents=True)
|
|
3390
|
+
path = os.pathsep.join([str(cache), str(stable), os.environ.get("PATH", "")])
|
|
3391
|
+
env = {**env, "PATH": path}
|
|
3392
|
+
write_text(rtl / "openspec/specs/.keep", "")
|
|
3393
|
+
write_authorize_config(rtl, "patrol:\n role: rtl\n every: 60m\n runner: tick\n")
|
|
3394
|
+
subprocess.run(["git", "add", "-A"], cwd=rtl, check=True, capture_output=True)
|
|
3395
|
+
subprocess.run(["git", "commit", "-q", "-m", "tick"], cwd=rtl, check=True, capture_output=True)
|
|
3396
|
+
|
|
3397
|
+
def keel(cwd: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
|
3398
|
+
return subprocess.run([str(stable / "node"), str(ROOT / "bin" / "keel.js"), *args], cwd=cwd, env=env,
|
|
3399
|
+
text=True, capture_output=True, check=False)
|
|
3400
|
+
|
|
3401
|
+
def program(plist: str) -> str:
|
|
3402
|
+
return (re.search(r"<key>ProgramArguments</key>\s*<array>\s*<string>(.*?)</string>", plist, re.S) or [None, ""])[1]
|
|
3403
|
+
|
|
3404
|
+
def path_of(plist: str) -> str:
|
|
3405
|
+
return (re.search(r"<key>PATH</key>\s*<string>(.*?)</string>", plist, re.S) or [None, ""])[1]
|
|
3406
|
+
|
|
3407
|
+
task = keel(rtl, "tick", "task")
|
|
3408
|
+
if task.returncode != 0:
|
|
3409
|
+
report(f"{label} keel tick task failed: {task.stderr!r}")
|
|
3410
|
+
return 1
|
|
3411
|
+
if program(task.stdout) != str(stable / "node"):
|
|
3412
|
+
report(f"{label} the tick job names the versioned node: {program(task.stdout)!r}, not {str(stable / 'node')!r}")
|
|
3413
|
+
return 1
|
|
3414
|
+
if str(stable) not in path_of(task.stdout).split(os.pathsep) or "plugins/cache" in path_of(task.stdout):
|
|
3415
|
+
report(f"{label} the tick job's PATH is not the stable directories without the plugin cache: {path_of(task.stdout)!r}")
|
|
3416
|
+
return 1
|
|
3417
|
+
|
|
3418
|
+
added = keel(cx, "chat", "wake", "add")
|
|
3419
|
+
plists = sorted((base / "agents").glob("dev.keel.chat-wake.*.plist"))
|
|
3420
|
+
if added.returncode != 0 or len(plists) != 1:
|
|
3421
|
+
report(f"{label} keel chat wake add wrote {len(plists)} LaunchAgents: {(added.stdout + added.stderr).strip()!r}")
|
|
3422
|
+
return 1
|
|
3423
|
+
waker = plists[0].read_text(encoding="utf-8")
|
|
3424
|
+
if program(waker) != str(stable / "node"):
|
|
3425
|
+
report(f"{label} the chat waker's LaunchAgent names the versioned node: {program(waker)!r}")
|
|
3426
|
+
return 1
|
|
3427
|
+
if "plugins/cache" in path_of(waker):
|
|
3428
|
+
report(f"{label} the chat waker's LaunchAgent keeps a plugin cache directory in PATH: {path_of(waker)!r}")
|
|
3429
|
+
return 1
|
|
3430
|
+
|
|
3431
|
+
gone = base / "Cellar" / "node" / "0.0.0" / "bin" / "node"
|
|
3432
|
+
broken = base / "agents" / "dev.keel.tick.x.plist"
|
|
3433
|
+
broken.write_text(task.stdout[task.stdout.index("<?xml"):task.stdout.index("</plist>") + 8].replace(str(stable / "node"), str(gone)), encoding="utf-8")
|
|
3434
|
+
problem = keel(rtl, "--doctor")
|
|
3435
|
+
line = next((l for l in problem.stdout.splitlines() if l.startswith("launchd: problem")), "")
|
|
3436
|
+
for needle in ("dev.keel.tick.x.plist", str(gone), "keel tick task"):
|
|
3437
|
+
if needle not in line:
|
|
3438
|
+
report(f"{label} doctor does not name {needle!r} for a job whose node is gone: {problem.stdout!r}")
|
|
3439
|
+
return 1
|
|
3440
|
+
broken.write_text(broken.read_text(encoding="utf-8").replace(str(gone), str(stable / "node")), encoding="utf-8")
|
|
3441
|
+
fine = keel(rtl, "--doctor")
|
|
3442
|
+
if "launchd: ok" not in fine.stdout or "launchd: problem" in fine.stdout:
|
|
3443
|
+
report(f"{label} doctor does not report ok once the node exists: {fine.stdout!r}")
|
|
3444
|
+
return 1
|
|
3445
|
+
if "launchd-stable-node" not in {name for name, _ in SCENARIOS}:
|
|
3446
|
+
report(f"{label} scenario is not registered.")
|
|
3447
|
+
return 1
|
|
3448
|
+
report("launchd-stable-node scenario passed.")
|
|
3449
|
+
return 0
|
|
3450
|
+
|
|
3451
|
+
|
|
3452
|
+
def validate_shift_slash_command_scenario() -> int:
|
|
3453
|
+
"""Issue #386: a session changes its own shift with one slash command.
|
|
3454
|
+
|
|
3455
|
+
`/keel:shift` is a command file in the Claude plugin that orders what a
|
|
3456
|
+
session does: check, settle each loose end (a keep-awake the host started,
|
|
3457
|
+
such as `caffeinate`, is not one), write the note, `ready --wake`. The
|
|
3458
|
+
scenario finds it through the root manifest and runs its own fenced `keel
|
|
3459
|
+
shift` lines in a clean worktree bound to a role, so a flag `keel` no
|
|
3460
|
+
longer accepts, or a heredoc that stores nothing, fails it.
|
|
3461
|
+
"""
|
|
3462
|
+
label = "shift-slash-command:"
|
|
3463
|
+
manifest = json.loads((ROOT / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8"))
|
|
3464
|
+
declared = manifest.get("commands") or []
|
|
3465
|
+
if not declared:
|
|
3466
|
+
report(f"{label} the root manifest declares no command")
|
|
3467
|
+
return 1
|
|
3468
|
+
files = [ROOT / entry for entry in declared if (ROOT / entry).name == "shift.md"]
|
|
3469
|
+
if len(files) != 1 or not files[0].is_file():
|
|
3470
|
+
report(f"{label} the root manifest's commands {declared!r} do not resolve to one plugins/keel/commands/shift.md")
|
|
3471
|
+
return 1
|
|
3472
|
+
if files[0].relative_to(ROOT).parts[:3] != ("plugins", "keel", "commands"):
|
|
3473
|
+
report(f"{label} the command is not under plugins/keel/commands: {files[0]}")
|
|
3474
|
+
return 1
|
|
3475
|
+
text = files[0].read_text(encoding="utf-8")
|
|
3476
|
+
front = re.match(r"---\n(.*?)\n---\n", text, re.S)
|
|
3477
|
+
if not front or not re.search(r"^description: \S", front.group(1), re.M):
|
|
3478
|
+
report(f"{label} the command has no front matter with a description.")
|
|
3479
|
+
return 1
|
|
3480
|
+
for needle in ("caffeinate", "--force-reason", "self-shift", "end your turn"):
|
|
3481
|
+
if needle not in text:
|
|
3482
|
+
report(f"{label} the command does not say {needle!r}.")
|
|
3483
|
+
return 1
|
|
3484
|
+
blocks = re.findall(r"```bash\n(.*?)```", text, re.S)
|
|
3485
|
+
lines = [b for b in blocks if b.lstrip().startswith("keel shift")]
|
|
3486
|
+
if [b.split()[2] for b in lines] != ["check", "ready"]:
|
|
3487
|
+
report(f"{label} the command's keel shift blocks are not check, then ready: {[b.split()[:3] for b in lines]!r}")
|
|
3488
|
+
return 1
|
|
3489
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-386-") as raw:
|
|
3490
|
+
base = Path(raw)
|
|
3491
|
+
_rtl, verify, env, _ = shift_scratch(base)
|
|
3492
|
+
shim = base / "shim"
|
|
3493
|
+
write_text(shim / "keel", f'#!/bin/sh\nexec node "{ROOT / "bin" / "keel.js"}" "$@"\n')
|
|
3494
|
+
(shim / "keel").chmod(0o755)
|
|
3495
|
+
env = {**env, "PATH": f"{shim}{os.pathsep}{os.environ.get('PATH', '')}", "KEEL_SHIFT_WAKE_TIMEOUT_MS": "2000"}
|
|
3496
|
+
checked = subprocess.run(["sh", "-c", lines[0]], cwd=verify, env=env, text=True, capture_output=True, check=False)
|
|
3497
|
+
if checked.returncode != 0:
|
|
3498
|
+
report(f"{label} the command's check line exited {checked.returncode} in a clean worktree: {checked.stdout!r} {checked.stderr!r}")
|
|
3499
|
+
return 1
|
|
3500
|
+
handed = subprocess.run(["sh", "-c", lines[1]], cwd=verify, env=env, text=True, capture_output=True, check=False)
|
|
3501
|
+
if handed.returncode != 0:
|
|
3502
|
+
report(f"{label} the command's ready line exited {handed.returncode}: {handed.stdout!r} {handed.stderr!r}")
|
|
3503
|
+
return 1
|
|
3504
|
+
body = re.search(r"<<'EOF'\n(.*?)\nEOF", lines[1], re.S)
|
|
3505
|
+
stored = mailbox_common_dir(verify) / "keel-chat" / "shift" / "verify.md"
|
|
3506
|
+
if not body:
|
|
3507
|
+
report(f"{label} the command's ready line carries no quoted heredoc: {lines[1]!r}")
|
|
3508
|
+
return 1
|
|
3509
|
+
if not stored.exists():
|
|
3510
|
+
report(f"{label} the command's ready line stored no note at {stored}: {handed.stdout!r}")
|
|
3511
|
+
return 1
|
|
3512
|
+
if body.group(1).strip() not in stored.read_text(encoding="utf-8"):
|
|
3513
|
+
report(f"{label} the stored note is not the heredoc's: {stored.read_text(encoding='utf-8')!r}")
|
|
3514
|
+
return 1
|
|
3515
|
+
if "wake is armed" not in handed.stdout:
|
|
3516
|
+
report(f"{label} the command's ready line did not arm the wake: {handed.stdout!r}")
|
|
3517
|
+
return 1
|
|
3518
|
+
if "shift-slash-command" not in {name for name, _ in SCENARIOS}:
|
|
3519
|
+
report(f"{label} scenario is not registered.")
|
|
3520
|
+
return 1
|
|
3521
|
+
report("shift-slash-command scenario passed.")
|
|
3522
|
+
return 0
|
|
3523
|
+
|
|
3524
|
+
|
|
3368
3525
|
def validate_tick_runs_due_patrol_scenario() -> int:
|
|
3369
3526
|
"""The owner's CLI waker (2026-10-19, #356): `keel tick` runs the patrol when due.
|
|
3370
3527
|
|
|
@@ -42791,6 +42948,8 @@ SCENARIOS: tuple = (
|
|
|
42791
42948
|
("patrol-since-last", validate_patrol_since_last_scenario),
|
|
42792
42949
|
("patrol-next", validate_patrol_next_scenario),
|
|
42793
42950
|
("tick-runs-due-patrol", validate_tick_runs_due_patrol_scenario),
|
|
42951
|
+
("launchd-stable-node", validate_launchd_stable_node_scenario),
|
|
42952
|
+
("shift-slash-command", validate_shift_slash_command_scenario),
|
|
42794
42953
|
("patrol-exit-says-who-acts", validate_patrol_exit_says_who_acts_scenario),
|
|
42795
42954
|
("patrol-nudge", validate_patrol_nudge_scenario),
|
|
42796
42955
|
("patrol-escalate", validate_patrol_escalate_scenario),
|
|
@@ -125,8 +125,9 @@ function xml(text) {
|
|
|
125
125
|
|
|
126
126
|
function plistText() {
|
|
127
127
|
const cli = path.resolve(__dirname, "..", "..", "..", "bin", "keel.js");
|
|
128
|
-
const
|
|
129
|
-
const
|
|
128
|
+
const { stableNode, launchdPath } = require("../launchd");
|
|
129
|
+
const args = [stableNode(), cli, "chat", "bridge", "run"];
|
|
130
|
+
const environment = { PATH: launchdPath(process.env.PATH) };
|
|
130
131
|
if (process.env.KEEL_HOME) environment.KEEL_HOME = process.env.KEEL_HOME;
|
|
131
132
|
if (process.env.KEEL_CHAT_MACHINE) environment.KEEL_CHAT_MACHINE = process.env.KEEL_CHAT_MACHINE;
|
|
132
133
|
const log = path.join(bridgeDir(), "bridge.log");
|
package/src/core/chat/wake.js
CHANGED
|
@@ -125,8 +125,9 @@ function xml(text) {
|
|
|
125
125
|
|
|
126
126
|
function plistText(label, worktree, signal) {
|
|
127
127
|
const cli = path.resolve(__dirname, "..", "..", "..", "bin", "keel.js");
|
|
128
|
-
const
|
|
129
|
-
const
|
|
128
|
+
const { stableNode, launchdPath } = require("../launchd");
|
|
129
|
+
const args = [stableNode(), cli, "chat", "wake", "run", "--once", "--worktree", worktree];
|
|
130
|
+
const environment = { PATH: launchdPath(process.env.PATH) };
|
|
130
131
|
for (const key of ["KEEL_HOME", "KEEL_CHAT_CODEX"]) {
|
|
131
132
|
if (process.env[key]) environment[key] = process.env[key];
|
|
132
133
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// What the LaunchAgents Keel prints or writes (`keel tick task`, `keel chat
|
|
4
|
+
// wake add`, the chat bridge) name, so that they outlive a package upgrade
|
|
5
|
+
// (#387). A launchd job runs long after the shell that rendered it.
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
|
|
10
|
+
// `process.execPath` is the binary's real location, which `brew upgrade` moves
|
|
11
|
+
// (`/opt/homebrew/Cellar/node/<version>/bin/node`). The `node` a person types is
|
|
12
|
+
// the symlink the manager keeps current, so a name on PATH that resolves to this
|
|
13
|
+
// same binary is the one to write; when none does, the real path is all there is.
|
|
14
|
+
function stableNode(env = process.env) {
|
|
15
|
+
const exec = process.execPath;
|
|
16
|
+
let real;
|
|
17
|
+
try {
|
|
18
|
+
real = fs.realpathSync(exec);
|
|
19
|
+
} catch {
|
|
20
|
+
return exec;
|
|
21
|
+
}
|
|
22
|
+
for (const dir of String(env.PATH || "").split(path.delimiter)) {
|
|
23
|
+
if (!dir) continue;
|
|
24
|
+
const candidate = path.join(dir, "node");
|
|
25
|
+
try {
|
|
26
|
+
if (fs.realpathSync(candidate) === real) return candidate;
|
|
27
|
+
} catch {
|
|
28
|
+
// not on this directory
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return exec;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A Claude plugin cache directory belongs to one release (`…/keel/5.149.0/bin`)
|
|
35
|
+
// and is stale after the next update. The jobs call node and keel.js by
|
|
36
|
+
// absolute path, so nothing in it is needed.
|
|
37
|
+
const PLUGIN_CACHE = /[\\/]\.claude[\\/]plugins[\\/]cache[\\/]/;
|
|
38
|
+
|
|
39
|
+
function launchdPath(value) {
|
|
40
|
+
const text = value || "/usr/bin:/bin:/usr/sbin:/sbin";
|
|
41
|
+
return text.split(path.delimiter).filter((dir) => dir && !PLUGIN_CACHE.test(`${dir}${path.sep}`)).join(path.delimiter);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function agentsDir() {
|
|
45
|
+
return process.env.KEEL_CHAT_LAUNCH_AGENTS_DIR || path.join(os.homedir(), "Library", "LaunchAgents");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const RECREATE = [
|
|
49
|
+
[/^dev\.keel\.tick\./, "keel tick task"],
|
|
50
|
+
[/^dev\.keel\.chat-wake\./, "keel chat wake add"],
|
|
51
|
+
[/^dev\.keel\.chat-bridge/, "keel chat bridge install"],
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
// Each `dev.keel.*` LaunchAgent with the program it runs and whether that exists.
|
|
55
|
+
function inspectJobs() {
|
|
56
|
+
let names = [];
|
|
57
|
+
try {
|
|
58
|
+
names = fs.readdirSync(agentsDir()).filter((name) => /^dev\.keel\..*\.plist$/.test(name)).sort();
|
|
59
|
+
} catch {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
return names.map((name) => {
|
|
63
|
+
let text = "";
|
|
64
|
+
try {
|
|
65
|
+
text = fs.readFileSync(path.join(agentsDir(), name), "utf8");
|
|
66
|
+
} catch {
|
|
67
|
+
// unreadable: reported as no program below
|
|
68
|
+
}
|
|
69
|
+
const match = text.match(/<key>ProgramArguments<\/key>\s*<array>\s*<string>([^<]*)<\/string>/);
|
|
70
|
+
const program = match ? match[1].replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&") : null;
|
|
71
|
+
const recreate = (RECREATE.find(([pattern]) => pattern.test(name)) || [null, "the command that wrote it"])[1];
|
|
72
|
+
return { name, program, exists: Boolean(program) && fs.existsSync(program), recreate };
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = { stableNode, launchdPath, inspectJobs };
|
package/src/core/tick.js
CHANGED
|
@@ -9,6 +9,7 @@ const os = require("os");
|
|
|
9
9
|
const path = require("path");
|
|
10
10
|
const { spawnSync } = require("child_process");
|
|
11
11
|
const store = require("./chat/store");
|
|
12
|
+
const { stableNode, launchdPath } = require("./launchd");
|
|
12
13
|
|
|
13
14
|
const USAGE = "keel tick [--repo <path>] [--json] one model-free step: run the patrol when it is due\n"
|
|
14
15
|
+ " keel tick task [--json] [--repo <path>] print the launchd job that calls it";
|
|
@@ -126,7 +127,7 @@ function task(where) {
|
|
|
126
127
|
if (!found.worktree) throw new TickError(found.why);
|
|
127
128
|
const label = `dev.keel.tick.${where.project.replace(/[^A-Za-z0-9.-]/g, "-")}`;
|
|
128
129
|
const logs = path.join(where.root, "tick");
|
|
129
|
-
const args = [
|
|
130
|
+
const args = [stableNode(), KEEL, "tick", "--repo", found.worktree];
|
|
130
131
|
const plist = [
|
|
131
132
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
132
133
|
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
@@ -135,7 +136,7 @@ function task(where) {
|
|
|
135
136
|
" <key>Label</key>", ` <string>${xml(label)}</string>`,
|
|
136
137
|
" <key>ProgramArguments</key>", " <array>", ...args.map((arg) => ` <string>${xml(arg)}</string>`), " </array>",
|
|
137
138
|
" <key>WorkingDirectory</key>", ` <string>${xml(found.worktree)}</string>`,
|
|
138
|
-
" <key>EnvironmentVariables</key>", " <dict>", " <key>PATH</key>", ` <string>${xml(process.env.PATH
|
|
139
|
+
" <key>EnvironmentVariables</key>", " <dict>", " <key>PATH</key>", ` <string>${xml(launchdPath(process.env.PATH))}</string>`, " </dict>",
|
|
139
140
|
" <key>StartInterval</key>", ` <integer>${INTERVAL_SECONDS}</integer>`,
|
|
140
141
|
" <key>StandardOutPath</key>", ` <string>${xml(path.join(logs, "tick.log"))}</string>`,
|
|
141
142
|
" <key>StandardErrorPath</key>", ` <string>${xml(path.join(logs, "tick.err"))}</string>`,
|