@christang/keel 5.199.0 → 5.201.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/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/scripts/fake_slack.py +13 -0
- package/scripts/validation/chat.py +147 -0
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/registry.py +5 -0
- package/src/core/chat/bridge.js +33 -5
- package/src/core/chat/cli.js +2 -1
- package/src/core/chat/notice.js +50 -9
- package/src/core/chat/slack.js +9 -3
- package/src/core/patrol.js +2 -0
- package/src/core/shift.js +5 -2
- package/src/core/tick.js +5 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.201.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/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.201.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.201.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.201.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.201.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/scripts/fake_slack.py
CHANGED
|
@@ -64,6 +64,9 @@ class FakeSlack:
|
|
|
64
64
|
# (token, channel) pairs `chat.postMessage` answers with
|
|
65
65
|
# `not_in_channel`, for a bot nobody invited.
|
|
66
66
|
self.not_in_channel: set[tuple[str, str]] = set()
|
|
67
|
+
# Methods answered with a chosen error body until cleared, such as a
|
|
68
|
+
# `missing_scope` with its `needed` field.
|
|
69
|
+
self.failing: dict[str, dict] = {}
|
|
67
70
|
# Which app token each Socket Mode connection was opened with.
|
|
68
71
|
self.socket_apps: dict[socket.socket, str] = {}
|
|
69
72
|
self.pending_apps: dict[str, str] = {}
|
|
@@ -93,6 +96,14 @@ class FakeSlack:
|
|
|
93
96
|
with self.lock:
|
|
94
97
|
self.rate_limit_next.append((method, retry_after))
|
|
95
98
|
|
|
99
|
+
def fail(self, method: str, body: dict | None) -> None:
|
|
100
|
+
"""Answer every call of `method` with `body` (HTTP 200), or normally again when `body` is None."""
|
|
101
|
+
with self.lock:
|
|
102
|
+
if body is None:
|
|
103
|
+
self.failing.pop(method, None)
|
|
104
|
+
else:
|
|
105
|
+
self.failing[method] = body
|
|
106
|
+
|
|
96
107
|
def calls_to(self, method: str) -> list[dict]:
|
|
97
108
|
with self.lock:
|
|
98
109
|
return [call for call in self.calls if call["method"] == method and not call.get("rate_limited")]
|
|
@@ -168,6 +179,8 @@ class FakeSlack:
|
|
|
168
179
|
self.calls.append({"method": method, "params": params, "rate_limited": True, "at": time.time()})
|
|
169
180
|
return 429, {"Retry-After": str(retry_after)}, {"ok": False, "error": "ratelimited"}
|
|
170
181
|
self.calls.append({"method": method, "params": params, "at": time.time()})
|
|
182
|
+
if method in self.failing:
|
|
183
|
+
return 200, {}, dict(self.failing[method])
|
|
171
184
|
token = str(params.get("_auth", "")).removeprefix("Bearer ")
|
|
172
185
|
identity = self.identities.get(token, {"user_id": "UBOT", "bot_id": "BBOT"})
|
|
173
186
|
if method == "auth.test":
|
|
@@ -510,6 +510,83 @@ def validate_chat_wake_skips_removed_session_scenario() -> int:
|
|
|
510
510
|
return 0
|
|
511
511
|
|
|
512
512
|
|
|
513
|
+
def validate_chat_wake_moved_worktree_scenario() -> int:
|
|
514
|
+
"""Issue #465: a session whose directory is gone is explained, not resumed.
|
|
515
|
+
|
|
516
|
+
After the workspace rename on 2026-10-25, presence and `claude agents` both
|
|
517
|
+
recorded each role's session under the old path. `claude --bg --resume`
|
|
518
|
+
printed `Workspace not trusted … could not be resolved on disk` and started
|
|
519
|
+
nothing. `wake now` now names the vanished directory and prints the fork
|
|
520
|
+
command to copy; the tick does not retry it; patrol and shift status list it.
|
|
521
|
+
"""
|
|
522
|
+
label = "chat-wake-moved-worktree:"
|
|
523
|
+
with tempfile.TemporaryDirectory(prefix="keel-wake-465-") as raw:
|
|
524
|
+
base = Path(raw)
|
|
525
|
+
rtl, verify, env, _ = shift_scratch(base)
|
|
526
|
+
gone = str(base / "renamed-away" / "verify")
|
|
527
|
+
calls = base / "claude-calls.jsonl"
|
|
528
|
+
fake = base / "fake-claude"
|
|
529
|
+
write_text(fake, "#!/usr/bin/env python3\nimport json, sys\n"
|
|
530
|
+
f"open({str(calls)!r}, 'a').write(json.dumps(sys.argv[1:]) + '\\n')\n"
|
|
531
|
+
"if sys.argv[1:3] == ['agents', '--json']:\n"
|
|
532
|
+
f" print(json.dumps([{{'kind': 'background', 'sessionId': 'sess-verify-1', 'id': 'sess-ver', 'cwd': {gone!r}}}]))\n"
|
|
533
|
+
"else:\n print('backgrounded · fake')\n")
|
|
534
|
+
fake.chmod(0o755)
|
|
535
|
+
env = {**env, "KEEL_CLAUDE": str(fake)}
|
|
536
|
+
dead = subprocess.Popen(["true"])
|
|
537
|
+
dead.wait()
|
|
538
|
+
chat_session_start(verify, env, "sess-verify-1", dead.pid)
|
|
539
|
+
presence_file = mailbox_common_dir(rtl) / "keel-chat" / "presence" / "verify.json"
|
|
540
|
+
presence = json.loads(presence_file.read_text(encoding="utf-8"))
|
|
541
|
+
presence["cli_worktree"] = gone
|
|
542
|
+
presence_file.write_text(json.dumps(presence), encoding="utf-8")
|
|
543
|
+
|
|
544
|
+
def resumes() -> list[list[str]]:
|
|
545
|
+
made = [json.loads(line) for line in calls.read_text().splitlines()] if calls.exists() else []
|
|
546
|
+
return [call for call in made if call[:1] == ["--bg"]]
|
|
547
|
+
|
|
548
|
+
woke = run_keel(rtl, "chat", "wake", "now", "verify", env=env)
|
|
549
|
+
said = woke.stdout + woke.stderr
|
|
550
|
+
if resumes():
|
|
551
|
+
report(f"{label} wake now resumed a session whose directory is gone: {resumes()!r}")
|
|
552
|
+
return 1
|
|
553
|
+
if woke.returncode == 0:
|
|
554
|
+
report(f"{label} wake now exits 0 for a session it could not resume: {said!r}")
|
|
555
|
+
return 1
|
|
556
|
+
if gone not in said:
|
|
557
|
+
report(f"{label} wake now does not name the directory that no longer exists: {said!r}")
|
|
558
|
+
return 1
|
|
559
|
+
if not any(f"cd {where} && claude --bg --fork-session --resume sess-verify-1" in said for where in (verify, os.path.realpath(verify))):
|
|
560
|
+
report(f"{label} wake now does not print the fork command for verify's worktree: {said!r}")
|
|
561
|
+
return 1
|
|
562
|
+
|
|
563
|
+
run_keel(rtl, "chat", "dm", "verify", "rerun R012", env=env)
|
|
564
|
+
run_keel(verify, "tick", "--repo", str(rtl), env=env)
|
|
565
|
+
if resumes():
|
|
566
|
+
report(f"{label} keel tick resumed a session whose directory is gone: {resumes()!r}")
|
|
567
|
+
return 1
|
|
568
|
+
risks = [line for line in run_keel(rtl, "patrol", env=env).stdout.splitlines() if "verify" in line and "no longer exists" in line]
|
|
569
|
+
if not risks:
|
|
570
|
+
report(f"{label} the patrol reports no risk for verify's session whose directory is gone.")
|
|
571
|
+
return 1
|
|
572
|
+
if "keel chat wake now verify" not in risks[0]:
|
|
573
|
+
report(f"{label} the patrol's risk does not name `keel chat wake now verify`: {risks[0]!r}")
|
|
574
|
+
return 1
|
|
575
|
+
status = run_keel(rtl, "shift", "status", env=env).stdout
|
|
576
|
+
listed = status.split("Sessions that cannot be resumed:", 1)
|
|
577
|
+
if len(listed) != 2:
|
|
578
|
+
report(f"{label} keel shift status has no `Sessions that cannot be resumed:` section: {status!r}")
|
|
579
|
+
return 1
|
|
580
|
+
if "verify" not in listed[1]:
|
|
581
|
+
report(f"{label} keel shift status does not list verify under `Sessions that cannot be resumed:`: {status!r}")
|
|
582
|
+
return 1
|
|
583
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
584
|
+
report(f"{label} the scenario registry does not include it.")
|
|
585
|
+
return 1
|
|
586
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
587
|
+
return 0
|
|
588
|
+
|
|
589
|
+
|
|
513
590
|
def validate_chat_wake_now_cli_scenario() -> int:
|
|
514
591
|
"""Issue #348 on the CLI (owner's CLI waker, 2026-10-19): one step wakes a role.
|
|
515
592
|
|
|
@@ -2989,6 +3066,76 @@ def validate_chat_bridge_lifecycle_scenario() -> int:
|
|
|
2989
3066
|
return 0
|
|
2990
3067
|
|
|
2991
3068
|
|
|
3069
|
+
def validate_chat_bridge_logs_once_scenario() -> int:
|
|
3070
|
+
"""Issue #460: a failure that never changes is logged once, and a missing scope is named.
|
|
3071
|
+
|
|
3072
|
+
On 2026-10-25 the bridge log held 2944 copies of one project's
|
|
3073
|
+
`this repository has no remote` (one per archive sync) and 278 of
|
|
3074
|
+
`catch-up failed: … missing_scope` (one per reconnect), and none named
|
|
3075
|
+
the scope Slack said was missing. A running bridge now logs each repeating
|
|
3076
|
+
failure once, a recovery once, and names Slack's `needed` scopes.
|
|
3077
|
+
"""
|
|
3078
|
+
label = "chat-bridge-logs-once:"
|
|
3079
|
+
if chat_bridge_node_missing("chat-bridge-logs-once"):
|
|
3080
|
+
return 3
|
|
3081
|
+
FakeSlack = fake_slack_class()
|
|
3082
|
+
with tempfile.TemporaryDirectory(prefix="keel-chat-460-") as raw, FakeSlack() as slack:
|
|
3083
|
+
base = Path(raw)
|
|
3084
|
+
rtl, _, env = chat_scratch_group(base)
|
|
3085
|
+
chat_slack_config(rtl, {"soc": "CSOC"})
|
|
3086
|
+
benv = {**chat_bridge_environment(env, base / "home", slack), "KEEL_CHAT_ARCHIVE_EVERY_MS": "300"}
|
|
3087
|
+
run_keel(rtl, "chat", "bridge", "add", env=benv)
|
|
3088
|
+
slack.fail("conversations.history", {"ok": False, "error": "missing_scope", "needed": "channels:history", "provided": "chat:write"})
|
|
3089
|
+
|
|
3090
|
+
def history_calls() -> int:
|
|
3091
|
+
return len(slack.calls_to("conversations.history"))
|
|
3092
|
+
|
|
3093
|
+
bridge = start_chat_bridge(rtl, benv)
|
|
3094
|
+
stderr = ""
|
|
3095
|
+
try:
|
|
3096
|
+
if not slack.wait_for(lambda: slack.sockets and history_calls() >= 1, 10):
|
|
3097
|
+
report(f"{label} the bridge never connected and caught up: {stop_chat_bridge(bridge).strip()}")
|
|
3098
|
+
return 1
|
|
3099
|
+
# Each reconnect is a new `hello` and so a new catch-up, which fails the same way.
|
|
3100
|
+
for _ in range(3):
|
|
3101
|
+
calls = history_calls()
|
|
3102
|
+
slack.drop_connections()
|
|
3103
|
+
if not slack.wait_for(lambda: history_calls() > calls, 15):
|
|
3104
|
+
report(f"{label} the bridge did not catch up again after a reconnect: {stop_chat_bridge(bridge).strip()}")
|
|
3105
|
+
return 1
|
|
3106
|
+
slack.fail("conversations.history", None)
|
|
3107
|
+
calls = history_calls()
|
|
3108
|
+
slack.drop_connections()
|
|
3109
|
+
# The reconnect backoff doubles while sessions stay short: 2, 4, 8, then 16 s.
|
|
3110
|
+
if not slack.wait_for(lambda: history_calls() > calls and slack.sockets, 30):
|
|
3111
|
+
report(f"{label} the bridge did not catch up after the scope was granted: {stop_chat_bridge(bridge).strip()}")
|
|
3112
|
+
return 1
|
|
3113
|
+
time.sleep(2)
|
|
3114
|
+
finally:
|
|
3115
|
+
stderr = stop_chat_bridge(bridge)
|
|
3116
|
+
lines = stderr.splitlines()
|
|
3117
|
+
refusals = [line for line in lines if "this repository has no remote" in line]
|
|
3118
|
+
if len(refusals) != 1:
|
|
3119
|
+
report(f"{label} the archive refusal was logged {len(refusals)} times over syncs every 300 ms, not once: {stderr!r}")
|
|
3120
|
+
return 1
|
|
3121
|
+
failed = [line for line in lines if "catch-up failed" in line]
|
|
3122
|
+
if len(failed) != 1:
|
|
3123
|
+
report(f"{label} the same catch-up failure was logged {len(failed)} times over four connects, not once: {stderr!r}")
|
|
3124
|
+
return 1
|
|
3125
|
+
if "missing_scope: needs channels:history" not in failed[0]:
|
|
3126
|
+
report(f"{label} the catch-up failure does not name the missing scope: {failed[0]!r}")
|
|
3127
|
+
return 1
|
|
3128
|
+
recovered = [line for line in lines if "catch-up works again" in line]
|
|
3129
|
+
if len(recovered) != 1:
|
|
3130
|
+
report(f"{label} the catch-up's recovery was logged {len(recovered)} times, not once: {stderr!r}")
|
|
3131
|
+
return 1
|
|
3132
|
+
if "chat-bridge-logs-once" not in {name for name, _ in registry.SCENARIOS}:
|
|
3133
|
+
report(f"{label} scenario is not registered.")
|
|
3134
|
+
return 1
|
|
3135
|
+
report("chat-bridge-logs-once scenario passed.")
|
|
3136
|
+
return 0
|
|
3137
|
+
|
|
3138
|
+
|
|
2992
3139
|
def validate_chat_bridge_start_race_scenario() -> int:
|
|
2993
3140
|
"""Issue #226: start, stop, install, and status follow launchd's state.
|
|
2994
3141
|
|
|
@@ -35,10 +35,10 @@ os.environ["KEEL_UPDATE_CLAUDE"] = str(Path(tempfile.gettempdir()) / "keel-suite
|
|
|
35
35
|
os.environ["KEEL_UPDATE_CODEX"] = str(Path(tempfile.gettempdir()) / "keel-suite-has-no-codex")
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
PACKAGE_VERSION = "5.
|
|
38
|
+
PACKAGE_VERSION = "5.201.0"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.201.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -101,6 +101,10 @@ SCENARIOS: tuple = (
|
|
|
101
101
|
"chat-bridge-start-race",
|
|
102
102
|
chat.validate_chat_bridge_start_race_scenario,
|
|
103
103
|
),
|
|
104
|
+
(
|
|
105
|
+
"chat-bridge-logs-once",
|
|
106
|
+
chat.validate_chat_bridge_logs_once_scenario,
|
|
107
|
+
),
|
|
104
108
|
(
|
|
105
109
|
"chat-owner-mention",
|
|
106
110
|
chat.validate_chat_owner_mention_scenario,
|
|
@@ -455,6 +459,7 @@ SCENARIOS: tuple = (
|
|
|
455
459
|
("chat-visitor-not-recorded", chat.validate_chat_visitor_not_recorded_scenario),
|
|
456
460
|
("chat-role-set-records-session", chat.validate_chat_role_set_records_session_scenario),
|
|
457
461
|
("chat-wake-skips-removed-session", chat.validate_chat_wake_skips_removed_session_scenario),
|
|
462
|
+
("chat-wake-moved-worktree", chat.validate_chat_wake_moved_worktree_scenario),
|
|
458
463
|
("chat-ack", chat.validate_chat_ack_scenario),
|
|
459
464
|
("coordinator-patrol", shift.validate_coordinator_patrol_scenario),
|
|
460
465
|
("patrol-since-last", shift.validate_patrol_since_last_scenario),
|
package/src/core/chat/bridge.js
CHANGED
|
@@ -892,6 +892,25 @@ function githubRepo(worktree) {
|
|
|
892
892
|
return result.status === 0 && match ? match[1] : null;
|
|
893
893
|
}
|
|
894
894
|
|
|
895
|
+
// A failure that repeats unchanged — an archive refusal at every sync, a
|
|
896
|
+
// catch-up failure at every reconnect — is logged once, again only when its
|
|
897
|
+
// line changes, and once more when it clears (#460 D1).
|
|
898
|
+
function onceLog(log) {
|
|
899
|
+
const last = new Map();
|
|
900
|
+
return {
|
|
901
|
+
failed(key, line) {
|
|
902
|
+
if (last.get(key) === line) return;
|
|
903
|
+
last.set(key, line);
|
|
904
|
+
log(line);
|
|
905
|
+
},
|
|
906
|
+
cleared(key, line) {
|
|
907
|
+
if (!last.has(key)) return;
|
|
908
|
+
last.delete(key);
|
|
909
|
+
log(line);
|
|
910
|
+
},
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
|
|
895
914
|
async function createContext(log, { needApp }) {
|
|
896
915
|
requireWebSocket();
|
|
897
916
|
const { bot, app } = lifecycle.tokens();
|
|
@@ -899,6 +918,7 @@ async function createContext(log, { needApp }) {
|
|
|
899
918
|
if (!bot) throw lifecycle.missingTokens("bot token");
|
|
900
919
|
const ctx = {
|
|
901
920
|
log,
|
|
921
|
+
once: onceLog(log),
|
|
902
922
|
token: bot,
|
|
903
923
|
appToken: app,
|
|
904
924
|
projects: prepareProjects(),
|
|
@@ -963,7 +983,11 @@ function socketSession(ctx, conn) {
|
|
|
963
983
|
if (data.type === "hello") {
|
|
964
984
|
conn.connected = true;
|
|
965
985
|
writeStatus(ctx);
|
|
966
|
-
|
|
986
|
+
const key = `catch-up:${conn.role || ""}`;
|
|
987
|
+
const whose = conn.role ? ` for ${conn.role}'s app` : "";
|
|
988
|
+
ctx.queue = ctx.queue.then(() => conn.onHello())
|
|
989
|
+
.then(() => { ctx.once.cleared(key, `catch-up works again${whose}.`); writeStatus(ctx); })
|
|
990
|
+
.catch((error) => ctx.once.failed(key, `catch-up failed${whose}: ${error.message}`));
|
|
967
991
|
return;
|
|
968
992
|
}
|
|
969
993
|
if (data.type === "disconnect") {
|
|
@@ -1065,20 +1089,24 @@ async function run(log) {
|
|
|
1065
1089
|
return stopped;
|
|
1066
1090
|
};
|
|
1067
1091
|
// Every ten minutes while connected, each project with archiving on is
|
|
1068
|
-
// synced to its keel-chat branch (D19).
|
|
1092
|
+
// synced to its keel-chat branch (D19). A refusal that never changes, such as
|
|
1093
|
+
// a repository with no remote, is logged once (#460 D1).
|
|
1094
|
+
const archiveEvery = /^\d+$/.test(process.env.KEEL_CHAT_ARCHIVE_EVERY_MS || "") ? Number(process.env.KEEL_CHAT_ARCHIVE_EVERY_MS) : 10 * 60 * 1000;
|
|
1069
1095
|
const archiveTimer = setInterval(() => {
|
|
1070
1096
|
if (!ctx.connected || ctx.stopping) return;
|
|
1071
1097
|
const archive = require("./archive");
|
|
1072
1098
|
for (const project of ctx.projects) {
|
|
1073
1099
|
if (!archive.archiveSettings(project.where.worktree).automatic) continue;
|
|
1100
|
+
const key = `archive:${project.where.project}`;
|
|
1074
1101
|
try {
|
|
1075
1102
|
const result = archive.sync(project.where);
|
|
1076
|
-
if (result.refused)
|
|
1103
|
+
if (result.refused) ctx.once.failed(key, `${project.where.project}: ${result.refused}`);
|
|
1104
|
+
else ctx.once.cleared(key, `${project.where.project}: archive sync works again.`);
|
|
1077
1105
|
} catch (error) {
|
|
1078
|
-
|
|
1106
|
+
ctx.once.failed(key, `${project.where.project}: archive sync failed: ${error.message}`);
|
|
1079
1107
|
}
|
|
1080
1108
|
}
|
|
1081
|
-
},
|
|
1109
|
+
}, archiveEvery);
|
|
1082
1110
|
archiveTimer.unref();
|
|
1083
1111
|
// Each second: honor a pause, notice a Keel upgrade, and send what is new.
|
|
1084
1112
|
const timer = setInterval(() => {
|
package/src/core/chat/cli.js
CHANGED
|
@@ -706,8 +706,9 @@ function runWake(cwd, options) {
|
|
|
706
706
|
out(`${role}'s CLI session ${presence.cli_session} is running; a record addressed to it wakes it, so nothing was resumed.`);
|
|
707
707
|
return 0;
|
|
708
708
|
}
|
|
709
|
-
const resumed = notice.resumeCli(entry);
|
|
709
|
+
const resumed = notice.resumeCli(entry, where);
|
|
710
710
|
if (resumed.removed) throw new ChatError(`${role}'s recorded CLI ${resumed.output}.`);
|
|
711
|
+
if (resumed.moved) throw new ChatError(`${role}'s recorded CLI ${resumed.output}`);
|
|
711
712
|
out(`${resumed.ok ? "Resumed" : "Could not resume"} ${role}'s CLI session ${entry.session} in ${entry.worktree}.${resumed.output ? `\n${resumed.output}` : ""}`);
|
|
712
713
|
return resumed.ok ? 0 : 1;
|
|
713
714
|
}
|
package/src/core/chat/notice.js
CHANGED
|
@@ -211,9 +211,25 @@ function wakeStep(session, text) {
|
|
|
211
211
|
// The prompt an ended CLI session resumes with: a pointer, never the work.
|
|
212
212
|
const CLI_WAKE_PROMPT = "You have unread keel chat records; run keel context, then keel chat unread.";
|
|
213
213
|
|
|
214
|
+
// The command that continues a session whose directory is gone in the role's
|
|
215
|
+
// worktree (#465 D1). Keel prints it and never runs it (D3): a fork is a new
|
|
216
|
+
// session with a new id, not a resume of the recorded one.
|
|
217
|
+
function forkCommand(where, entry) {
|
|
218
|
+
const bound = where
|
|
219
|
+
? Object.entries(store.readJsonFile(path.join(where.root, "roles.json")))
|
|
220
|
+
.filter(([worktree, name]) => name === entry.role && fs.existsSync(worktree)).map(([worktree]) => worktree)
|
|
221
|
+
: [];
|
|
222
|
+
const target = bound.length === 1 ? bound[0] : "<the role's worktree>";
|
|
223
|
+
const mode = bound.length === 1 ? require("../config").readShiftDeclaration(target).permissionMode : "auto";
|
|
224
|
+
const name = `${entry.role} · ${store.isoLocal(new Date()).slice(5, 16).replace("T", " ")}`;
|
|
225
|
+
const command = `cd ${target} && claude --bg --fork-session --resume ${entry.session} -n ${JSON.stringify(name)} --permission-mode ${mode} ${JSON.stringify(CLI_WAKE_PROMPT)}`;
|
|
226
|
+
return bound.length > 1 ? `${command}\n(the role is bound to ${bound.join(", ")}: use the one it works in)` : command;
|
|
227
|
+
}
|
|
228
|
+
|
|
214
229
|
// Resumes a role's recorded CLI session (#348 D3). Only `--bg --resume <id>`
|
|
215
|
-
// and the prompt: any other flag starts a copy with a new session id.
|
|
216
|
-
|
|
230
|
+
// and the prompt: any other flag starts a copy with a new session id. A
|
|
231
|
+
// session whose directory no longer exists resumes nothing (#465).
|
|
232
|
+
function resumeCli(entry, where = null) {
|
|
217
233
|
const claude = process.env.KEEL_CLAUDE || "claude";
|
|
218
234
|
// A session `claude rm` removed is gone for good (#415 D4): when the host's
|
|
219
235
|
// list can be read and lacks it, nothing is resumed. An unreadable list
|
|
@@ -221,19 +237,33 @@ function resumeCli(entry) {
|
|
|
221
237
|
const listed = require("child_process").spawnSync(claude, ["agents", "--json", "--all"], {
|
|
222
238
|
encoding: "utf8", timeout: 30 * 1000,
|
|
223
239
|
});
|
|
240
|
+
let row = null;
|
|
224
241
|
try {
|
|
225
242
|
const rows = JSON.parse(listed.stdout);
|
|
226
|
-
if (!listed.error && listed.status === 0 && Array.isArray(rows)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
243
|
+
if (!listed.error && listed.status === 0 && Array.isArray(rows)) {
|
|
244
|
+
row = rows.find((found) => found && found.sessionId === entry.session) || null;
|
|
245
|
+
if (!row) {
|
|
246
|
+
return {
|
|
247
|
+
ok: false,
|
|
248
|
+
removed: true,
|
|
249
|
+
output: `session ${entry.session} was removed: \`claude agents\` no longer lists it, so a new session must be started for the role in ${entry.worktree || "its worktree"}`,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
233
252
|
}
|
|
234
253
|
} catch {
|
|
235
254
|
// Not a list: fall through and resume.
|
|
236
255
|
}
|
|
256
|
+
// The host resumes a session only in the directory it registered, so one
|
|
257
|
+
// whose directory was renamed or removed cannot start (#465 F3).
|
|
258
|
+
const ran = (row && row.cwd) || entry.worktree;
|
|
259
|
+
if (ran && !fs.existsSync(ran)) {
|
|
260
|
+
return {
|
|
261
|
+
ok: false,
|
|
262
|
+
moved: true,
|
|
263
|
+
output: `session ${entry.session} ran in ${ran}, which no longer exists, and Claude Code resumes a session only in the directory it ran in. `
|
|
264
|
+
+ `To continue its conversation as a new session in the role's worktree, run:\n${forkCommand(where, entry)}`,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
237
267
|
const result = require("child_process").spawnSync(claude, ["--bg", "--resume", entry.session, CLI_WAKE_PROMPT], {
|
|
238
268
|
cwd: entry.worktree || undefined, encoding: "utf8",
|
|
239
269
|
});
|
|
@@ -244,6 +274,16 @@ function resumeCli(entry) {
|
|
|
244
274
|
return { ok: !result.error && result.status === 0, output: result.error ? result.error.message : output };
|
|
245
275
|
}
|
|
246
276
|
|
|
277
|
+
// Covered roles whose ended CLI session ran in a worktree that no longer
|
|
278
|
+
// exists (#465 D4). Presence only: the patrol asks the host nothing.
|
|
279
|
+
function movedSessionRisks(where, covers = () => true) {
|
|
280
|
+
const roles = [...new Set(Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean))].sort();
|
|
281
|
+
return roles.filter(covers).map((role) => asleep(where, role))
|
|
282
|
+
.filter((entry) => entry && entry.cli && entry.worktree && !fs.existsSync(entry.worktree))
|
|
283
|
+
.map((entry) => `${entry.role}'s CLI session ${entry.session} ran in ${entry.worktree}, which no longer exists, so it cannot be resumed; `
|
|
284
|
+
+ `\`keel chat wake now ${entry.role}\` prints the command that continues it in the role's worktree`);
|
|
285
|
+
}
|
|
286
|
+
|
|
247
287
|
// --- parked roles (#316) ------------------------------------------------------------
|
|
248
288
|
|
|
249
289
|
function parkFile(where, role) {
|
|
@@ -729,6 +769,7 @@ module.exports = {
|
|
|
729
769
|
unpark,
|
|
730
770
|
wakeStep,
|
|
731
771
|
resumeCli,
|
|
772
|
+
movedSessionRisks,
|
|
732
773
|
twinWarning,
|
|
733
774
|
check,
|
|
734
775
|
bridgeLine,
|
package/src/core/chat/slack.js
CHANGED
|
@@ -16,13 +16,17 @@ const FORM_METHODS = new Set([
|
|
|
16
16
|
"conversations.replies",
|
|
17
17
|
]);
|
|
18
18
|
|
|
19
|
+
// Slack names the scopes a `missing_scope` call needed and those the token
|
|
20
|
+
// has; the message names the needed ones, which is what the fix takes (#460 D2).
|
|
19
21
|
class SlackError extends Error {
|
|
20
|
-
constructor(method, error, { retryAfter = null, status = null } = {}) {
|
|
21
|
-
super(`Slack ${method} failed: ${error}${status ? ` (HTTP ${status})` : ""}`);
|
|
22
|
+
constructor(method, error, { retryAfter = null, status = null, needed = null, provided = null } = {}) {
|
|
23
|
+
super(`Slack ${method} failed: ${error}${needed ? `: needs ${needed}` : ""}${status ? ` (HTTP ${status})` : ""}`);
|
|
22
24
|
this.method = method;
|
|
23
25
|
this.error = error;
|
|
24
26
|
this.retryAfter = retryAfter;
|
|
25
27
|
this.status = status;
|
|
28
|
+
this.needed = needed;
|
|
29
|
+
this.provided = provided;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
|
|
@@ -69,7 +73,9 @@ async function call(method, params, token) {
|
|
|
69
73
|
throw new SlackError(method, "response was not JSON", { status: response.status });
|
|
70
74
|
}
|
|
71
75
|
if (!parsed || parsed.ok !== true) {
|
|
72
|
-
throw new SlackError(method, (parsed && parsed.error) || "unknown_error", {
|
|
76
|
+
throw new SlackError(method, (parsed && parsed.error) || "unknown_error", {
|
|
77
|
+
status: response.status, needed: (parsed && parsed.needed) || null, provided: (parsed && parsed.provided) || null,
|
|
78
|
+
});
|
|
73
79
|
}
|
|
74
80
|
return parsed;
|
|
75
81
|
}
|
package/src/core/patrol.js
CHANGED
|
@@ -559,6 +559,8 @@ function runPatrol(argv) {
|
|
|
559
559
|
if (quota) result.risks.push(quota);
|
|
560
560
|
// A CLI hand-off that failed or hangs (#357 D4), of the roles this patrol covers.
|
|
561
561
|
result.risks.push(...require("./shift").handOffRisks(where, Date.now(), (name) => name === role || options.coverage.covers(name)));
|
|
562
|
+
// An ended CLI session whose worktree is gone cannot be woken (#465 D4).
|
|
563
|
+
result.risks.push(...require("./chat/notice").movedSessionRisks(where, (name) => name === role || options.coverage.covers(name)));
|
|
562
564
|
// Near the limit nudges stop, since each wakes a large session (D3).
|
|
563
565
|
const quiet = options.quota !== null && options.quota >= options.quotaQuietAt;
|
|
564
566
|
if (options.nudge && quiet) result.paused = `nudges paused: quota at ${options.quota}%`;
|
package/src/core/shift.js
CHANGED
|
@@ -1605,9 +1605,12 @@ function runShift(argv) {
|
|
|
1605
1605
|
case "status": {
|
|
1606
1606
|
const rows = status(where);
|
|
1607
1607
|
const queue = handOffs(where);
|
|
1608
|
+
// Roles whose ended CLI session ran in a worktree that is gone (#465 D4).
|
|
1609
|
+
const unresumable = require("./chat/notice").movedSessionRisks(where);
|
|
1608
1610
|
const text = [rows.length ? rows.map(describe).join("\n") : "No shift change recorded.",
|
|
1609
|
-
...(queue.length ? ["", "Hand-offs (CLI, run by `keel tick`):", ...queue.map(describeHandOff)] : [])
|
|
1610
|
-
|
|
1611
|
+
...(queue.length ? ["", "Hand-offs (CLI, run by `keel tick`):", ...queue.map(describeHandOff)] : []),
|
|
1612
|
+
...(unresumable.length ? ["", "Sessions that cannot be resumed:", ...unresumable.map((line) => `- ${line}`)] : [])].join("\n");
|
|
1613
|
+
out({ roles: rows, handOffs: queue, unresumable }, text);
|
|
1611
1614
|
return 0;
|
|
1612
1615
|
}
|
|
1613
1616
|
default:
|
package/src/core/tick.js
CHANGED
|
@@ -96,13 +96,14 @@ function wakeEnded(where, state) {
|
|
|
96
96
|
const waiting = store.unread(where, role).filter((record) => store.wakes(record, role)).map((record) => record.id).sort();
|
|
97
97
|
const newest = waiting[waiting.length - 1];
|
|
98
98
|
if (!newest || (state.woken[role] && state.woken[role] >= newest)) continue;
|
|
99
|
-
const resumed = notice.resumeCli(entry);
|
|
100
|
-
// Marked woken only once it worked, the session
|
|
101
|
-
// failed for this record (#408 D3); a newer
|
|
99
|
+
const resumed = notice.resumeCli(entry, where);
|
|
100
|
+
// Marked woken only once it worked, the session or its directory is gone
|
|
101
|
+
// (#465 D2), or three tries failed for this record (#408 D3); a newer
|
|
102
|
+
// record starts the count again.
|
|
102
103
|
const before = (state.wake_attempts || {})[role];
|
|
103
104
|
const count = before && before.record === newest ? before.count + 1 : 1;
|
|
104
105
|
state.wake_attempts = { ...(state.wake_attempts || {}), [role]: { record: newest, count } };
|
|
105
|
-
if (resumed.ok || resumed.removed || count >= 3) state.woken[role] = newest;
|
|
106
|
+
if (resumed.ok || resumed.removed || resumed.moved || count >= 3) state.woken[role] = newest;
|
|
106
107
|
woken.push({ role, session: entry.session, record: newest, ok: resumed.ok, output: resumed.output });
|
|
107
108
|
}
|
|
108
109
|
return woken;
|