@christang/keel 5.197.1 → 5.199.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 +31 -2
- 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/validation/common.py +2 -2
- package/scripts/validation/hosts.py +71 -2
- package/scripts/validation/registry.py +2 -0
- package/scripts/validation/shift.py +145 -1
- package/src/core/shift.js +33 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.199.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
|
@@ -1300,6 +1300,27 @@ function updateCodexPlugin(options) {
|
|
|
1300
1300
|
return true;
|
|
1301
1301
|
}
|
|
1302
1302
|
|
|
1303
|
+
// The version the global prefix holds (#459 D1): what `npm install -g` wrote,
|
|
1304
|
+
// read rather than assumed, since an install that exits 0 once left the
|
|
1305
|
+
// prefix a release behind while the line said `updated`.
|
|
1306
|
+
function installedCli(npm) {
|
|
1307
|
+
const root = spawnSync(npm, ["root", "-g"], {
|
|
1308
|
+
encoding: "utf8",
|
|
1309
|
+
shell: process.platform === "win32",
|
|
1310
|
+
timeout: Number(process.env.KEEL_UPDATE_QUERY_TIMEOUT_MS) || 30 * 1000,
|
|
1311
|
+
});
|
|
1312
|
+
const dir = String(root.stdout || "").trim().split(/\r?\n/).pop();
|
|
1313
|
+
if (root.error || root.status !== 0 || !dir) {
|
|
1314
|
+
return { version: null, why: `npm root -g ${root.error ? root.error.message : `exited ${root.status} with ${dir ? "output" : "no output"}`}` };
|
|
1315
|
+
}
|
|
1316
|
+
const file = path.join(dir, "@christang", "keel", "package.json");
|
|
1317
|
+
try {
|
|
1318
|
+
return { version: JSON.parse(fs.readFileSync(file, "utf8")).version || null, file, why: `${file} names no version` };
|
|
1319
|
+
} catch (error) {
|
|
1320
|
+
return { version: null, file, why: `${file} cannot be read (${error.code || error.message})` };
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1303
1324
|
function updateGlobalCli(options, npm, source) {
|
|
1304
1325
|
if (options.dryRun) {
|
|
1305
1326
|
process.stdout.write(
|
|
@@ -1321,6 +1342,7 @@ function updateGlobalCli(options, npm, source) {
|
|
|
1321
1342
|
return true;
|
|
1322
1343
|
}
|
|
1323
1344
|
|
|
1345
|
+
const before = installedCli(npm);
|
|
1324
1346
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "keel-update-"));
|
|
1325
1347
|
try {
|
|
1326
1348
|
const packArgs = [
|
|
@@ -1358,10 +1380,17 @@ function updateGlobalCli(options, npm, source) {
|
|
|
1358
1380
|
const latest = packed && source === DEFAULT_UPDATE_SOURCE
|
|
1359
1381
|
? `the npm registry's latest here is ${packed[1]}; `
|
|
1360
1382
|
: "";
|
|
1383
|
+
// What the prefix holds now decides the line (#459 D2–D4).
|
|
1384
|
+
const after = installedCli(npm);
|
|
1385
|
+
if (after.version && packed && after.version !== packed[1]) {
|
|
1386
|
+
updateLine("cli", "failed", `npm install -g ${path.basename(tarball)} exited 0, but ${after.file} holds ${after.version}`);
|
|
1387
|
+
return false;
|
|
1388
|
+
}
|
|
1389
|
+
const unverified = after.version ? "" : `; not verified: ${after.why}`;
|
|
1361
1390
|
updateLine(
|
|
1362
1391
|
"cli",
|
|
1363
|
-
versionChange(PACKAGE_JSON.version, packed ? packed[1] : null),
|
|
1364
|
-
`${latest}applies to the next command that runs keel`
|
|
1392
|
+
versionChange(before.version || PACKAGE_JSON.version, after.version || (packed ? packed[1] : null)),
|
|
1393
|
+
`${latest}applies to the next command that runs keel${unverified}`
|
|
1365
1394
|
);
|
|
1366
1395
|
return true;
|
|
1367
1396
|
} catch (error) {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.199.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.199.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.199.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.199.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",
|
|
@@ -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.199.0"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.199.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -484,8 +484,15 @@ def validate_update_pack_install_scenario() -> int:
|
|
|
484
484
|
for line in call_log.read_text(encoding="utf-8").splitlines()
|
|
485
485
|
if line.strip()
|
|
486
486
|
]
|
|
487
|
+
# `npm root -g` is read before packing and after installing (#459), and
|
|
488
|
+
# changes nothing; the calls that change something are still two.
|
|
489
|
+
reads = [call for call in calls if call[:2] == ["root", "-g"]]
|
|
490
|
+
calls = [call for call in calls if call[:2] != ["root", "-g"]]
|
|
491
|
+
if len(reads) != 2:
|
|
492
|
+
report(f"update-pack-install scenario read the global prefix {len(reads)} time(s), not before and after.")
|
|
493
|
+
return 1
|
|
487
494
|
if len(calls) != 2:
|
|
488
|
-
report("update-pack-install scenario expected exactly two npm calls.")
|
|
495
|
+
report("update-pack-install scenario expected exactly two npm calls that change something.")
|
|
489
496
|
report(json.dumps(calls, indent=2))
|
|
490
497
|
return 1
|
|
491
498
|
|
|
@@ -2568,6 +2575,14 @@ if (host === "npm") {
|
|
|
2568
2575
|
fs.writeFileSync(path.join(dest, "christang-keel-5.1.0.tgz"), "");
|
|
2569
2576
|
process.stdout.write(JSON.stringify([{ filename: "christang-keel-5.1.0.tgz" }]));
|
|
2570
2577
|
}
|
|
2578
|
+
// FAKE_NPM_ROOT is the global prefix `npm root -g` names, and an
|
|
2579
|
+
// `install -g` writes the version FAKE_NPM_INSTALLS names there (#459).
|
|
2580
|
+
if (args[0] === "root" && process.env.FAKE_NPM_ROOT) process.stdout.write(`${process.env.FAKE_NPM_ROOT}\n`);
|
|
2581
|
+
if (args[0] === "install" && process.env.FAKE_NPM_ROOT && process.env.FAKE_NPM_INSTALLS) {
|
|
2582
|
+
const dir = path.join(process.env.FAKE_NPM_ROOT, "@christang", "keel");
|
|
2583
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
2584
|
+
fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify({ name: "@christang/keel", version: process.env.FAKE_NPM_INSTALLS }));
|
|
2585
|
+
}
|
|
2571
2586
|
// FAKE_NPM_LATEST is what `npm view <package> version` prints, and
|
|
2572
2587
|
// FAKE_NPM_VIEW_EXIT makes it exit with that status instead (#421).
|
|
2573
2588
|
if (args[0] === "view") {
|
|
@@ -2821,7 +2836,7 @@ def validate_update_covers_installed_hosts_scenario() -> int:
|
|
|
2821
2836
|
|
|
2822
2837
|
result, calls = update()
|
|
2823
2838
|
expected = [
|
|
2824
|
-
["npm", "pack"], ["npm", "install", "-g"],
|
|
2839
|
+
["npm", "root", "-g"], ["npm", "pack"], ["npm", "install", "-g"], ["npm", "root", "-g"],
|
|
2825
2840
|
["claude", "plugin", "marketplace", "update", "keel-marketplace"],
|
|
2826
2841
|
["claude", "plugin", "update", "keel@keel-marketplace"],
|
|
2827
2842
|
["codex", "plugin", "marketplace", "upgrade", "keel-marketplace"],
|
|
@@ -3297,6 +3312,60 @@ def validate_update_claude_refresh_retry_scenario() -> int:
|
|
|
3297
3312
|
return 0
|
|
3298
3313
|
|
|
3299
3314
|
|
|
3315
|
+
def validate_update_verifies_installed_cli_scenario() -> int:
|
|
3316
|
+
"""Issue #459: the CLI line reports what the global prefix holds.
|
|
3317
|
+
|
|
3318
|
+
An `npm install -g` that exits 0 while the prefix keeps another version
|
|
3319
|
+
is a failure, and the before version comes from the prefix, not from the
|
|
3320
|
+
copy of keel that happens to be running.
|
|
3321
|
+
"""
|
|
3322
|
+
label = "update-verifies-installed-cli:"
|
|
3323
|
+
with tempfile.TemporaryDirectory(prefix="keel-update-459-", ignore_cleanup_errors=True) as raw:
|
|
3324
|
+
tmp = Path(raw)
|
|
3325
|
+
fake = tmp / "fake.js"
|
|
3326
|
+
write_text(fake, UPDATE_FAKE)
|
|
3327
|
+
npm = tmp / "fake-npm"
|
|
3328
|
+
write_text(npm, f'#!/bin/sh\nFAKE_HOST=npm exec node "{fake}" "$@"\n')
|
|
3329
|
+
npm.chmod(0o755)
|
|
3330
|
+
prefix = tmp / "global"
|
|
3331
|
+
installed = prefix / "@christang" / "keel" / "package.json"
|
|
3332
|
+
|
|
3333
|
+
def update(installs: str) -> tuple[subprocess.CompletedProcess[str], str]:
|
|
3334
|
+
write_text(installed, json.dumps({"name": "@christang/keel", "version": "5.0.0"}))
|
|
3335
|
+
env = dict(os.environ)
|
|
3336
|
+
env.update({
|
|
3337
|
+
"KEEL_UPDATE_NPM": str(npm), "KEEL_UPDATE_CLAUDE": str(tmp / "no-claude"),
|
|
3338
|
+
"KEEL_UPDATE_CODEX": str(tmp / "no-codex"), "FAKE_LOG": str(tmp / "log.jsonl"),
|
|
3339
|
+
"FAKE_STATE": str(tmp / "state.json"), "FAKE_NPM_ROOT": str(prefix), "FAKE_NPM_INSTALLS": installs,
|
|
3340
|
+
})
|
|
3341
|
+
env.pop("KEEL_UPDATE_SOURCE", None)
|
|
3342
|
+
result = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--update"], cwd=tmp, env=env,
|
|
3343
|
+
text=True, capture_output=True, check=False, timeout=120)
|
|
3344
|
+
line = next((l for l in result.stdout.splitlines() if l.startswith("keel update: cli:")), "")
|
|
3345
|
+
return result, line
|
|
3346
|
+
|
|
3347
|
+
result, line = update("5.0.9")
|
|
3348
|
+
if "failed" not in line:
|
|
3349
|
+
report(f"{label} an install that left the prefix at 5.0.9 does not read failed: {line!r}")
|
|
3350
|
+
return 1
|
|
3351
|
+
for needle in (str(installed), "5.0.9"):
|
|
3352
|
+
if needle not in line:
|
|
3353
|
+
report(f"{label} the failed line does not name {needle!r}: {line!r}")
|
|
3354
|
+
return 1
|
|
3355
|
+
if result.returncode == 0:
|
|
3356
|
+
report(f"{label} an install that did not take left keel --update exiting 0.")
|
|
3357
|
+
return 1
|
|
3358
|
+
result, line = update("5.1.0")
|
|
3359
|
+
if "updated 5.0.0 -> 5.1.0" not in line:
|
|
3360
|
+
report(f"{label} an install that took does not read updated 5.0.0 -> 5.1.0: {line!r}")
|
|
3361
|
+
return 1
|
|
3362
|
+
if result.returncode != 0:
|
|
3363
|
+
report(f"{label} an install that took left keel --update exiting {result.returncode}: {result.stdout!r}")
|
|
3364
|
+
return 1
|
|
3365
|
+
report("update-verifies-installed-cli scenario passed.")
|
|
3366
|
+
return 0
|
|
3367
|
+
|
|
3368
|
+
|
|
3300
3369
|
def validate_update_host_query_retry_scenario() -> int:
|
|
3301
3370
|
"""Issue #365: `codex plugin list --json` usually answers in about 1 s and
|
|
3302
3371
|
sometimes took 58 s through the owner's proxy.
|
|
@@ -395,6 +395,7 @@ SCENARIOS: tuple = (
|
|
|
395
395
|
("update-covers-installed-hosts", hosts.validate_update_covers_installed_hosts_scenario),
|
|
396
396
|
("update-codex-refresh-retry", hosts.validate_update_codex_refresh_retry_scenario),
|
|
397
397
|
("update-host-query-retry", hosts.validate_update_host_query_retry_scenario),
|
|
398
|
+
("update-verifies-installed-cli", hosts.validate_update_verifies_installed_cli_scenario),
|
|
398
399
|
("update-claude-refresh-retry", hosts.validate_update_claude_refresh_retry_scenario),
|
|
399
400
|
("update-host-query-timeout", hosts.validate_update_host_query_timeout_scenario),
|
|
400
401
|
("update-codex-from-disk", hosts.validate_update_codex_from_disk_scenario),
|
|
@@ -415,6 +416,7 @@ SCENARIOS: tuple = (
|
|
|
415
416
|
("shift-self-wake", shift.validate_shift_self_wake_scenario),
|
|
416
417
|
("shift-cli-self-shift", shift.validate_shift_cli_self_shift_scenario),
|
|
417
418
|
("shift-cli-keeps-old-sessions", shift.validate_shift_cli_keeps_old_sessions_scenario),
|
|
419
|
+
("shift-resume-removes-old-sessions", shift.validate_shift_resume_removes_old_sessions_scenario),
|
|
418
420
|
("shift-cli-removes-after-exit", shift.validate_shift_cli_removes_after_exit_scenario),
|
|
419
421
|
("shift-cli-names-host-failure", shift.validate_shift_cli_names_host_failure_scenario),
|
|
420
422
|
("tick-retries-failed-wake", shift.validate_tick_retries_failed_wake_scenario),
|
|
@@ -3742,9 +3742,20 @@ def validate_shift_cli_keeps_old_sessions_scenario() -> int:
|
|
|
3742
3742
|
# #418 (owner, 2026-10-21): no declaration keeps none, so the shift just handed over leaves the
|
|
3743
3743
|
# session list too; a value that is not a whole number is named and none are kept.
|
|
3744
3744
|
for keep in (None, "many"):
|
|
3745
|
-
|
|
3745
|
+
# #462: after a rename a session's working directory names no bound worktree; Keel's copy of its
|
|
3746
|
+
# transcript under verify still makes it verify's, and one kept under no role stays.
|
|
3747
|
+
moved, stray = old_row(7, str(base / "renamed-away" / "verify")), old_row(8, str(base / "renamed-away" / "other"))
|
|
3748
|
+
(kept_dir / f"{moved['sessionId']}.jsonl.gz").write_bytes(gzip.compress(b'{"type": "user"}\n'))
|
|
3749
|
+
olds = [old_row(1, bound["verify"]), old_row(2, bound["verify"]), old_row(4, bound["verify"]), moved, stray]
|
|
3746
3750
|
setup(keep, olds)
|
|
3747
3751
|
ids = sorted(r["argv"][1] for r in removed())
|
|
3752
|
+
if "07070707" not in ids:
|
|
3753
|
+
report(f"{label} a session of verify's from a missing worktree stayed: {ids!r}")
|
|
3754
|
+
return 1
|
|
3755
|
+
if "08080808" in ids:
|
|
3756
|
+
report(f"{label} a session from a missing worktree kept under no role was removed: {ids!r}")
|
|
3757
|
+
return 1
|
|
3758
|
+
ids = [i for i in ids if i != "07070707"]
|
|
3748
3759
|
if ids != sorted(["01010101", "02020202", "04040404", OLD[:8]]):
|
|
3749
3760
|
report(f"{label} the default keeps the wrong number of old sessions (keep_old_sessions {keep!r}): removed {ids!r}")
|
|
3750
3761
|
return 1
|
|
@@ -3764,6 +3775,139 @@ def validate_shift_cli_keeps_old_sessions_scenario() -> int:
|
|
|
3764
3775
|
return 0
|
|
3765
3776
|
|
|
3766
3777
|
|
|
3778
|
+
def validate_shift_resume_removes_old_sessions_scenario() -> int:
|
|
3779
|
+
"""Issue #462 (owner, 2026-10-25): a takeover Keel did not carry out left the old shift listed.
|
|
3780
|
+
|
|
3781
|
+
After the workspace rename the owner opened a session by hand and it ran
|
|
3782
|
+
`keel shift resume`; only a delivered hand-over removed old sessions, and it
|
|
3783
|
+
matched them by a working directory the rename had moved. `resume` of a
|
|
3784
|
+
note a CLI session wrote, in a Claude Code session, now removes them as a
|
|
3785
|
+
hand-over does, and a session whose transcript Keel keeps under the role is
|
|
3786
|
+
the role's wherever it ran. It asks the host only when it may remove
|
|
3787
|
+
something.
|
|
3788
|
+
"""
|
|
3789
|
+
label = "shift-resume-removes-old-sessions:"
|
|
3790
|
+
OLD = "5b14fbae-b6aa-40b6-a72a-b3f89d2c6eea"
|
|
3791
|
+
NEW = "c0ffee00-1111-2222-3333-444444444444"
|
|
3792
|
+
MOVED = "07070707-0000-0000-0000-000000000007"
|
|
3793
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-462-") as raw:
|
|
3794
|
+
base = Path(raw)
|
|
3795
|
+
rtl, verify, env, _ = shift_scratch(base)
|
|
3796
|
+
calls, agents = base / "claude-calls.jsonl", base / "agents.json"
|
|
3797
|
+
config_dir = base / "claude-config"
|
|
3798
|
+
shift_root = mailbox_common_dir(rtl) / "keel-chat" / "shift"
|
|
3799
|
+
kept_dir = shift_root / "transcripts" / "verify"
|
|
3800
|
+
fake = base / "fake-claude"
|
|
3801
|
+
# The row shapes of shift-cli-keeps-old-sessions: a stopped row has no `status`; `rm` drops the row and
|
|
3802
|
+
# logs whether Keel's copy was there when it ran.
|
|
3803
|
+
write_text(fake, "#!/usr/bin/env python3\nimport json, os, sys\n"
|
|
3804
|
+
f"agents, kept = {str(agents)!r}, {str(kept_dir)!r}\n"
|
|
3805
|
+
"argv = sys.argv[1:]\n"
|
|
3806
|
+
"rows = json.loads(open(agents).read())\n"
|
|
3807
|
+
"record = {'argv': argv}\n"
|
|
3808
|
+
"if argv[:1] == ['rm']:\n"
|
|
3809
|
+
" gone = [row for row in rows if row['id'] == argv[1]]\n"
|
|
3810
|
+
" record['kept'] = bool(gone) and os.path.exists(os.path.join(kept, gone[0]['sessionId'] + '.jsonl.gz'))\n"
|
|
3811
|
+
" rows = [row for row in rows if row['id'] != argv[1]]\n"
|
|
3812
|
+
f"open({str(calls)!r}, 'a').write(json.dumps(record) + '\\n')\n"
|
|
3813
|
+
"if argv[:2] == ['agents', '--json']:\n print(json.dumps(rows)); sys.exit(0)\n"
|
|
3814
|
+
"open(agents, 'w').write(json.dumps(rows)); print('ok'); sys.exit(0)\n")
|
|
3815
|
+
fake.chmod(0o755)
|
|
3816
|
+
env = {**env, "KEEL_CLAUDE": str(fake), "CLAUDE_CONFIG_DIR": str(config_dir)}
|
|
3817
|
+
exited = subprocess.Popen(["true"])
|
|
3818
|
+
exited.wait()
|
|
3819
|
+
old_cli = {**env, "CLAUDE_CODE_ENTRYPOINT": "cli", "CLAUDE_CODE_SESSION_ID": OLD, "CLAUDE_PID": str(exited.pid)}
|
|
3820
|
+
new_cli = {**env, "CLAUDE_CODE_ENTRYPOINT": "cli", "CLAUDE_CODE_SESSION_ID": NEW, "CLAUDE_PID": str(os.getpid())}
|
|
3821
|
+
roles = json.loads((mailbox_common_dir(rtl) / "keel-chat" / "roles.json").read_text(encoding="utf-8"))
|
|
3822
|
+
bound = {role: path for path, role in roles.items()}
|
|
3823
|
+
moved_cwd = str(base / "renamed-away" / "verify")
|
|
3824
|
+
|
|
3825
|
+
def transcript(cwd: str, session: str) -> None:
|
|
3826
|
+
project = config_dir / "projects" / re.sub(r"[^A-Za-z0-9]", "-", cwd)
|
|
3827
|
+
project.mkdir(parents=True, exist_ok=True)
|
|
3828
|
+
(project / f"{session}.jsonl").write_text(json.dumps(
|
|
3829
|
+
{"type": "user", "timestamp": "2026-10-21T01:00:00.000Z", "cwd": cwd, "message": {"role": "user", "content": "carry on"}}) + "\n",
|
|
3830
|
+
encoding="utf-8")
|
|
3831
|
+
|
|
3832
|
+
def row(session: str, cwd: str, n: int, **extra: object) -> dict:
|
|
3833
|
+
return {"kind": "background", "name": "verify", "sessionId": session, "id": session[:8], "state": "stopped",
|
|
3834
|
+
"cwd": cwd, "startedAt": 1792400000000 + n * 1000, **extra}
|
|
3835
|
+
|
|
3836
|
+
def readied(text: str) -> None:
|
|
3837
|
+
calls.write_text("")
|
|
3838
|
+
done = run_keel(verify, "shift", "ready", text, env=old_cli)
|
|
3839
|
+
if done.returncode != 0:
|
|
3840
|
+
raise RuntimeError(f"ready failed: {done.stdout} {done.stderr}")
|
|
3841
|
+
|
|
3842
|
+
def host_calls() -> list[list[str]]:
|
|
3843
|
+
return [json.loads(line)["argv"] for line in calls.read_text().splitlines()]
|
|
3844
|
+
|
|
3845
|
+
# The old shift and a pre-rename one Keel kept under verify are verify's; rtl's stopped session is not,
|
|
3846
|
+
# and the session running resume is live.
|
|
3847
|
+
transcript(bound["verify"], OLD)
|
|
3848
|
+
transcript(bound["rtl"], "05050505-0000-0000-0000-000000000005")
|
|
3849
|
+
kept_dir.mkdir(parents=True, exist_ok=True)
|
|
3850
|
+
(kept_dir / f"{MOVED}.jsonl.gz").write_bytes(gzip.compress(b'{"type": "user"}\n'))
|
|
3851
|
+
agents.write_text(json.dumps([
|
|
3852
|
+
row(MOVED, moved_cwd, 1), row("05050505-0000-0000-0000-000000000005", bound["rtl"], 5),
|
|
3853
|
+
row(OLD, bound["verify"], 8),
|
|
3854
|
+
row(NEW, bound["verify"], 9, status="busy", state="working", pid=os.getpid()),
|
|
3855
|
+
]))
|
|
3856
|
+
readied("next: rerun R021")
|
|
3857
|
+
resumed = run_keel(verify, "shift", "resume", env=new_cli)
|
|
3858
|
+
if resumed.returncode != 0:
|
|
3859
|
+
report(f"{label} resume exited {resumed.returncode}: {resumed.stderr!r}")
|
|
3860
|
+
return 1
|
|
3861
|
+
if "next: rerun R021" not in resumed.stdout:
|
|
3862
|
+
report(f"{label} resume did not print the note: {resumed.stdout!r}")
|
|
3863
|
+
return 1
|
|
3864
|
+
gone = [json.loads(line) for line in calls.read_text().splitlines() if json.loads(line)["argv"][:1] == ["rm"]]
|
|
3865
|
+
if not gone:
|
|
3866
|
+
report(f"{label} resume removed no old session: {calls.read_text()!r}")
|
|
3867
|
+
return 1
|
|
3868
|
+
ids = sorted(r["argv"][1] for r in gone)
|
|
3869
|
+
if ids != sorted([OLD[:8], MOVED[:8]]):
|
|
3870
|
+
report(f"{label} resume removed {ids!r}, not the shift handed over and verify's session from a missing worktree.")
|
|
3871
|
+
return 1
|
|
3872
|
+
if not all(r["kept"] for r in gone):
|
|
3873
|
+
report(f"{label} a session was removed before Keel's store held its transcript: {gone!r}")
|
|
3874
|
+
return 1
|
|
3875
|
+
left = {r["id"] for r in json.loads(agents.read_text())}
|
|
3876
|
+
if left != {"05050505", NEW[:8]}:
|
|
3877
|
+
report(f"{label} rtl's session and the current one should stay, and the listed ones are {sorted(left)!r}")
|
|
3878
|
+
return 1
|
|
3879
|
+
for needle in (OLD[:8], MOVED[:8], "keel shift history verify --show"):
|
|
3880
|
+
if needle not in resumed.stdout:
|
|
3881
|
+
report(f"{label} resume does not name {needle!r}: {resumed.stdout!r}")
|
|
3882
|
+
return 1
|
|
3883
|
+
|
|
3884
|
+
# Outside a Claude Code host, and in the session Keel's own delivered hand-over started, there is nothing to
|
|
3885
|
+
# ask the host: the first runs no `claude`, and the hand-over already removed them.
|
|
3886
|
+
readied("next: rerun R022")
|
|
3887
|
+
plain = run_keel(verify, "shift", "resume", env=env)
|
|
3888
|
+
if "next: rerun R022" not in plain.stdout:
|
|
3889
|
+
report(f"{label} resume outside a Claude Code host did not print the note: {plain.stdout!r}")
|
|
3890
|
+
return 1
|
|
3891
|
+
if host_calls():
|
|
3892
|
+
report(f"{label} resume outside a Claude Code host called claude: {host_calls()!r}")
|
|
3893
|
+
return 1
|
|
3894
|
+
readied("next: rerun R023")
|
|
3895
|
+
write_text(shift_root / "queue" / "verify.json", json.dumps(
|
|
3896
|
+
{"role": "verify", "session": OLD, "worktree": bound["verify"], "state": "delivered", "new_session": NEW[:8]}))
|
|
3897
|
+
handed = run_keel(verify, "shift", "resume", env=new_cli)
|
|
3898
|
+
if "next: rerun R023" not in handed.stdout:
|
|
3899
|
+
report(f"{label} resume after a delivered hand-over did not print the note: {handed.stdout!r}")
|
|
3900
|
+
return 1
|
|
3901
|
+
if host_calls():
|
|
3902
|
+
report(f"{label} resume after a delivered hand-over called claude: {host_calls()!r}")
|
|
3903
|
+
return 1
|
|
3904
|
+
if "shift-resume-removes-old-sessions" not in {name for name, _ in registry.SCENARIOS}:
|
|
3905
|
+
report(f"{label} scenario is not registered.")
|
|
3906
|
+
return 1
|
|
3907
|
+
report("shift-resume-removes-old-sessions scenario passed.")
|
|
3908
|
+
return 0
|
|
3909
|
+
|
|
3910
|
+
|
|
3767
3911
|
def validate_shift_history_show_scenario() -> int:
|
|
3768
3912
|
"""Issue #397 (owner, 2026-10-20): a shift no longer in `claude agents` can be read in full.
|
|
3769
3913
|
|
package/src/core/shift.js
CHANGED
|
@@ -612,21 +612,24 @@ function keptCopyOf(where, role, transcript) {
|
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
|
|
615
|
-
// After a delivered hand-over, the newest `keep` stopped background
|
|
616
|
-
// the role
|
|
617
|
-
//
|
|
618
|
-
//
|
|
619
|
-
//
|
|
620
|
-
//
|
|
615
|
+
// After a delivered hand-over or a resume, the newest `keep` stopped background
|
|
616
|
+
// sessions of the role stay listed; each older one is removed with `claude rm`
|
|
617
|
+
// once Keel's store holds its transcript (#397 D2). `claude rm` leaves the
|
|
618
|
+
// host's transcript (F4). Only a session with a transcript, the host's or
|
|
619
|
+
// Keel's copy, is a shift: one never given a prompt has neither, so it takes no
|
|
620
|
+
// slot and stays (#401). A session is the role's when it ran in a bound
|
|
621
|
+
// worktree, or when Keel keeps its transcript under the role: a renamed or
|
|
622
|
+
// moved worktree leaves a `cwd` no binding names (#462 D2).
|
|
621
623
|
function removeOldSessions(claude, where, entry, keep) {
|
|
622
624
|
const bound = new Set(Object.entries(store.readJsonFile(path.join(where.root, "roles.json")))
|
|
623
625
|
.filter(([, name]) => name === entry.role).map(([worktree]) => realpath(worktree)));
|
|
624
626
|
const listed = listAgents(claude);
|
|
625
627
|
if (!listed) return [];
|
|
626
628
|
const { keptFile } = require("./chat/notice");
|
|
629
|
+
const roles = (row) => bound.has(realpath(row.cwd)) || fs.existsSync(keptFile(where, entry.role, `${row.sessionId}.jsonl`));
|
|
627
630
|
const old = listed
|
|
628
|
-
.filter((row) => row && row.kind === "background" && !row.status && row.cwd &&
|
|
629
|
-
&& row.
|
|
631
|
+
.filter((row) => row && row.kind === "background" && !row.status && row.cwd && row.sessionId && roles(row)
|
|
632
|
+
&& row.id !== entry.new_session)
|
|
630
633
|
.map((row) => ({ row, transcript: hostTranscript(row.cwd, row.sessionId),
|
|
631
634
|
kept: keptFile(where, entry.role, `${row.sessionId}.jsonl`) }))
|
|
632
635
|
.filter(({ transcript, kept }) => transcript || fs.existsSync(kept))
|
|
@@ -1064,6 +1067,23 @@ function lastFetch(cwd) {
|
|
|
1064
1067
|
}
|
|
1065
1068
|
}
|
|
1066
1069
|
|
|
1070
|
+
// A takeover Keel did not carry out — a session opened by hand — removes the
|
|
1071
|
+
// old shift's sessions at resume, as a delivered hand-over does (#462 D1). It
|
|
1072
|
+
// asks the host only from a Claude Code session, for a note a CLI session
|
|
1073
|
+
// wrote, and not in the session a delivered hand-over started, which already
|
|
1074
|
+
// removed them.
|
|
1075
|
+
function removeAtResume(where, role, text) {
|
|
1076
|
+
const old = String(text).match(/^CLI session: (\S+)\.$/m);
|
|
1077
|
+
const current = process.env.CLAUDE_CODE_SESSION_ID || "";
|
|
1078
|
+
if (!old || !process.env.CLAUDE_CODE_ENTRYPOINT) return [];
|
|
1079
|
+
const queued = store.readJsonFile(queueFile(where, role));
|
|
1080
|
+
if (queued && queued.state === "delivered" && queued.new_session && current.startsWith(queued.new_session)) return [];
|
|
1081
|
+
const pid = String(text).match(/^CLI process: (\d+)\.$/m);
|
|
1082
|
+
const entry = { role, session: old[1], pid: pid ? Number(pid[1]) : null, new_session: current.slice(0, 8) || null };
|
|
1083
|
+
const { readShiftDeclaration } = require("./config");
|
|
1084
|
+
return removeOldSessions(process.env.KEEL_CLAUDE || "claude", where, entry, readShiftDeclaration(where.worktree).keepOldSessions);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1067
1087
|
function resume(where, named = null) {
|
|
1068
1088
|
const role = resumeRole(where, named);
|
|
1069
1089
|
const note = waitingNote(where, role);
|
|
@@ -1087,7 +1107,7 @@ function resume(where, named = null) {
|
|
|
1087
1107
|
? store.post(where, { group, text, refs: [REF] })
|
|
1088
1108
|
: store.writeRecord(where, { group, kind: "message", from: role, refs: [REF], text })).id;
|
|
1089
1109
|
}
|
|
1090
|
-
return { role, note: history, text, told, waiting: role ? unstarted(where, role) : [], commits: noteCommits(where.worktree, text, knownSessionIds(where)), merged_branch: mergedBranch(where.worktree), fetched: lastFetch(where.worktree) };
|
|
1110
|
+
return { role, note: history, text, told, removed: removeAtResume(where, role, text), waiting: role ? unstarted(where, role) : [], commits: noteCommits(where.worktree, text, knownSessionIds(where)), merged_branch: mergedBranch(where.worktree), fetched: lastFetch(where.worktree) };
|
|
1091
1111
|
}
|
|
1092
1112
|
|
|
1093
1113
|
function status(where) {
|
|
@@ -1557,7 +1577,10 @@ function runShift(argv) {
|
|
|
1557
1577
|
? `\n\nThis worktree is on ${merged.branch ? `\`${merged.branch}\`` : "a detached HEAD"}, already in ${merged.base} and `
|
|
1558
1578
|
+ `${merged.behind} commit${merged.behind === 1 ? "" : "s"} behind it: start new work from ${merged.base}.`
|
|
1559
1579
|
: "";
|
|
1560
|
-
|
|
1580
|
+
const removed = (result.removed || []).length
|
|
1581
|
+
? `\n\nRemoved old sessions from claude agents: ${result.removed.join(", ")}; \`keel shift history ${result.role} --show <id>\` prints each.`
|
|
1582
|
+
: "";
|
|
1583
|
+
out(result, `${result.text.replace(/\s+$/, "")}${commits}${stale}\n\n(The note moved to ${result.note}.)${removed}${still}${remind ? `\n\n${patrolReminder(patrol)}` : ""}${remote}`);
|
|
1561
1584
|
return 0;
|
|
1562
1585
|
}
|
|
1563
1586
|
case "history": {
|