@christang/keel 5.177.0 → 5.179.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.177.0",
3
+ "version": "5.179.0",
4
4
  "description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
5
5
  "author": {
6
6
  "name": "TanglmChris",
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.177.0 -->
1
+ <!-- keel:start version=5.179.0 -->
2
2
  ## Keel Bootstrap
3
3
 
4
4
  - Start every session with `keel context`; OpenSpec artifacts and Git are the durable authority, and memory or transcripts may only inform.
package/bin/keel.js CHANGED
@@ -1050,7 +1050,28 @@ function versionChange(before, after) {
1050
1050
  return before && after && before !== after ? `updated ${before} -> ${after}` : `current ${after || before || "unknown"}`;
1051
1051
  }
1052
1052
 
1053
- function updateClaudePlugin(options) {
1053
+ // Right after a release the Claude marketplace, read from Git, names a version
1054
+ // the npm registry this machine reaches does not serve yet, and the plugin
1055
+ // update exits with npm's E404; a rerun minutes later succeeds (#421). That is
1056
+ // read as lag only when the registry's own latest is older than the version
1057
+ // asked for; an E404 the registry cannot explain stays a failure.
1058
+ function registryLag(result, npm) {
1059
+ const said = `${result.stdout || ""}\n${result.stderr || ""}`;
1060
+ const match = /E404 No match found for version (\d+\.\d+\.\d+[^\s'"]*)/.exec(said);
1061
+ if (!match) return null;
1062
+ const limit = Number(process.env.KEEL_UPDATE_QUERY_TIMEOUT_MS) || 30 * 1000;
1063
+ const view = spawnSync(npm, ["view", PACKAGE_JSON.name, "version", "--prefer-online"], {
1064
+ encoding: "utf8",
1065
+ shell: process.platform === "win32",
1066
+ timeout: limit,
1067
+ });
1068
+ if (view.error || view.status !== 0) return null;
1069
+ const latest = String(view.stdout || "").trim();
1070
+ if (!/^\d+\.\d+\.\d+/.test(latest) || compareVersions(match[1], latest) <= 0) return null;
1071
+ return { wanted: match[1], latest };
1072
+ }
1073
+
1074
+ function updateClaudePlugin(options, npm) {
1054
1075
  const component = "claude plugin";
1055
1076
  const executable = process.env.KEEL_UPDATE_CLAUDE || "claude";
1056
1077
  const queried = claudeKeel(executable);
@@ -1078,7 +1099,21 @@ function updateClaudePlugin(options) {
1078
1099
  updateLine(component, "failed", `\`claude ${steps[0].join(" ")}\` failed twice; ${hostFailure(refreshed)}`);
1079
1100
  return false;
1080
1101
  }
1081
- if (!runHostSteps(component, "claude", executable, [steps[1]])) return false;
1102
+ const updated = hostRun(executable, steps[1]);
1103
+ if (updated.error || updated.status !== 0) {
1104
+ const lag = registryLag(updated, npm);
1105
+ if (lag) {
1106
+ updateLine(
1107
+ component,
1108
+ "pending",
1109
+ `the npm registry here does not serve ${lag.wanted} yet (its latest is ${lag.latest}); `
1110
+ + "rerun keel --update in a few minutes"
1111
+ );
1112
+ return true;
1113
+ }
1114
+ updateLine(component, "failed", `\`claude ${steps[1].join(" ")}\` ${hostFailure(updated)}`);
1115
+ return false;
1116
+ }
1082
1117
  const after = claudeKeel(executable);
1083
1118
  if (after && after.failed) {
1084
1119
  updateLine(component, "failed", `${after.failed} after the update, so its result is unverified`);
@@ -1303,7 +1338,17 @@ function updateGlobalCli(options, npm, source) {
1303
1338
  return false;
1304
1339
  }
1305
1340
  const packed = /-(\d+\.\d+\.\d+[^/]*?)\.tgz$/.exec(path.basename(tarball));
1306
- updateLine("cli", versionChange(PACKAGE_JSON.version, packed ? packed[1] : null), "applies to the next command that runs keel");
1341
+ // From the default source the packed version is the registry's latest as
1342
+ // this machine sees it, which is what `current` means right after a
1343
+ // release whose version has not reached that registry yet (#421).
1344
+ const latest = packed && source === DEFAULT_UPDATE_SOURCE
1345
+ ? `the npm registry's latest here is ${packed[1]}; `
1346
+ : "";
1347
+ updateLine(
1348
+ "cli",
1349
+ versionChange(PACKAGE_JSON.version, packed ? packed[1] : null),
1350
+ `${latest}applies to the next command that runs keel`
1351
+ );
1307
1352
  return true;
1308
1353
  } catch (error) {
1309
1354
  updateLine("cli", "failed", error.message);
@@ -1332,7 +1377,7 @@ function runGlobalUpdate(options) {
1332
1377
  // leaves the others to report, and any failure fails the command.
1333
1378
  const results = [
1334
1379
  updateGlobalCli(options, npm, source),
1335
- updateClaudePlugin(options),
1380
+ updateClaudePlugin(options, npm),
1336
1381
  updateCodexPlugin(options),
1337
1382
  ];
1338
1383
  return results.every(Boolean) ? 0 : 1;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.177.0",
3
+ "version": "5.179.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.177.0",
9
+ "version": "5.179.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@fission-ai/openspec": "^1.4.1"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@christang/keel",
3
3
  "displayName": "Keel",
4
4
  "description": "Keel OpenSpec execution discipline CLI for Claude Code, Codex, and OpenCode.",
5
- "version": "5.177.0",
5
+ "version": "5.179.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.177.0",
3
+ "version": "5.179.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.177.0",
3
+ "version": "5.179.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,72 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // Waits until the npm registry serves a published version (#421).
5
+ //
6
+ // `npm publish` returning is the write side saying the version exists; the
7
+ // read side that `npm install` and `claude plugin update` resolve against has
8
+ // lagged it by minutes (#153, #421). The publish job runs this between the
9
+ // publish and the release, so a release announces a version the registry
10
+ // already serves. A nonzero `npm view` is npm's E404 for a version it cannot
11
+ // see yet, and counts as not served. Mirrors and proxies may lag further;
12
+ // `keel --update` reports that case as `pending`.
13
+ //
14
+ // Usage:
15
+ // node scripts/await_registry.js <package> <version> [--interval-seconds N] [--timeout-seconds N]
16
+ //
17
+ // KEEL_AWAIT_NPM names the npm executable (default `npm`).
18
+
19
+ const { spawnSync } = require("child_process");
20
+
21
+ function fail(message) {
22
+ process.stderr.write(`await_registry: ${message}\n`);
23
+ process.exit(1);
24
+ }
25
+
26
+ function option(args, name, fallback) {
27
+ const index = args.indexOf(name);
28
+ if (index < 0) return fallback;
29
+ const value = Number(args[index + 1]);
30
+ if (!Number.isFinite(value) || value < 0) fail(`${name} needs a number of seconds`);
31
+ args.splice(index, 2);
32
+ return value;
33
+ }
34
+
35
+ function served(npm, spec, version) {
36
+ const result = spawnSync(npm, ["view", spec, "version", "--prefer-online"], {
37
+ encoding: "utf8",
38
+ shell: process.platform === "win32",
39
+ timeout: 60 * 1000,
40
+ });
41
+ return !result.error && result.status === 0 && String(result.stdout || "").trim() === version;
42
+ }
43
+
44
+ function sleep(seconds) {
45
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, seconds * 1000);
46
+ }
47
+
48
+ function main() {
49
+ const args = process.argv.slice(2);
50
+ const interval = option(args, "--interval-seconds", 15);
51
+ const limit = option(args, "--timeout-seconds", 15 * 60);
52
+ if (args.length !== 2) {
53
+ fail("usage: node scripts/await_registry.js <package> <version> [--interval-seconds N] [--timeout-seconds N]");
54
+ }
55
+ const [name, version] = args;
56
+ const spec = `${name}@${version}`;
57
+ const npm = process.env.KEEL_AWAIT_NPM || "npm";
58
+ const started = Date.now();
59
+ for (let polls = 1; ; polls += 1) {
60
+ if (served(npm, spec, version)) {
61
+ const seconds = Math.round((Date.now() - started) / 1000);
62
+ process.stdout.write(`await_registry: the registry serves ${spec} after ${seconds} s and ${polls} poll(s)\n`);
63
+ return;
64
+ }
65
+ if ((Date.now() - started) / 1000 + interval > limit) {
66
+ fail(`the registry did not serve ${spec} within ${limit} s (${polls} poll(s)); re-run the job to wait again`);
67
+ }
68
+ sleep(interval);
69
+ }
70
+ }
71
+
72
+ main();
@@ -51,8 +51,8 @@ REQUIRED_SCRIPTS = [
51
51
  "scripts/validate_plugin.py",
52
52
  ]
53
53
 
54
- PACKAGE_VERSION = "5.177.0"
55
- PROTOCOL_VERSION = "5.177.0"
54
+ PACKAGE_VERSION = "5.179.0"
55
+ PROTOCOL_VERSION = "5.179.0"
56
56
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
57
57
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
58
58
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -8338,8 +8338,9 @@ def validate_shift_cli_self_shift_scenario() -> int:
8338
8338
  if readied.returncode != 0:
8339
8339
  report(f"{label} ready --wake in a CLI session failed: {readied.stdout!r} {readied.stderr!r}")
8340
8340
  return 1
8341
- if "claude attach" not in readied.stdout or "--wake" in readied.stderr:
8342
- report(f"{label} ready --wake in a CLI session does not say how the old session is reopened: {readied.stdout!r}")
8341
+ # #418: nothing is kept by default, so the old session is removed and read through Keel's copy.
8342
+ if "keel shift history verify --show" not in readied.stdout or "--wake" in readied.stderr:
8343
+ report(f"{label} ready --wake in a CLI session does not say how the old session is read once removed: {readied.stdout!r}")
8343
8344
  return 1
8344
8345
  note = next((mailbox_common_dir(rtl) / "keel-chat" / "shift").glob("verify.md"), None)
8345
8346
  if not note:
@@ -8446,7 +8447,7 @@ def validate_shift_cli_keeps_old_sessions_scenario() -> int:
8446
8447
  """Issue #397 (owner, 2026-10-20): each CLI shift leaves a stopped session, and the list kept growing.
8447
8448
 
8448
8449
  After a delivered hand-over, the newest `shift: keep_old_sessions:`
8449
- (default 3) stopped background sessions in the role's bound worktrees stay
8450
+ (default 0 since #418, so the shift just handed over goes too) stopped background sessions in the role's bound worktrees stay
8450
8451
  listed; each older one is removed with `claude rm` once Keel's store holds
8451
8452
  a copy of its transcript. Only a session with a transcript, the host's or
8452
8453
  Keel's copy, counts (#401): one whose transcript is nowhere takes no slot and
@@ -8555,14 +8556,21 @@ def validate_shift_cli_keeps_old_sessions_scenario() -> int:
8555
8556
  report(f"{label} shift status does not name the removed sessions: {text!r}")
8556
8557
  return 1
8557
8558
 
8558
- # No declaration keeps three; a value that is not a whole number is named and three applies.
8559
+ # #418 (owner, 2026-10-21): no declaration keeps none, so the shift just handed over leaves the
8560
+ # session list too; a value that is not a whole number is named and none are kept.
8559
8561
  for keep in (None, "many"):
8560
8562
  olds = [old_row(1, bound["verify"]), old_row(2, bound["verify"]), old_row(4, bound["verify"])]
8561
8563
  setup(keep, olds)
8562
8564
  ids = sorted(r["argv"][1] for r in removed())
8563
- if ids != ["01010101"]:
8565
+ if ids != sorted(["01010101", "02020202", "04040404", OLD[:8]]):
8564
8566
  report(f"{label} the default keeps the wrong number of old sessions (keep_old_sessions {keep!r}): removed {ids!r}")
8565
8567
  return 1
8568
+ if not all(r["kept"] for r in removed()):
8569
+ report(f"{label} a session was removed before Keel's store held its transcript: {removed()!r}")
8570
+ return 1
8571
+ if f"keel shift history verify --show {OLD[:8]}" not in run_keel(rtl, "shift", "status", env=env).stdout:
8572
+ report(f"{label} shift status does not say how the removed old shift is read: {run_keel(rtl, 'shift', 'status', env=env).stdout!r}")
8573
+ return 1
8566
8574
  if keep == "many" and "keep_old_sessions" not in run_keel(rtl, "shift", "status", env=env).stdout:
8567
8575
  report(f"{label} an unreadable keep_old_sessions is not named: {run_keel(rtl, 'shift', 'status', env=env).stdout!r}")
8568
8576
  return 1
@@ -25259,7 +25267,10 @@ if (failOn && args.join(" ").includes(failOn)) {
25259
25267
  if (failed < failTimes) {
25260
25268
  state.failed = { ...(state.failed || {}), [host]: failed + 1 };
25261
25269
  save();
25262
- process.stderr.write(`fake ${host}: warming up\nfake ${host}: refused ${args.join(" ")}\n`);
25270
+ // FAKE_FAIL_STDERR_<HOST> replaces the refusal's last line, as a host's own
25271
+ // error text would read (#421).
25272
+ const said = process.env[`FAKE_FAIL_STDERR_${host.toUpperCase()}`] || `fake ${host}: refused ${args.join(" ")}`;
25273
+ process.stderr.write(`fake ${host}: warming up\n${said}\n`);
25263
25274
  process.exit(1);
25264
25275
  }
25265
25276
  }
@@ -25269,6 +25280,15 @@ if (host === "npm") {
25269
25280
  fs.writeFileSync(path.join(dest, "christang-keel-5.1.0.tgz"), "");
25270
25281
  process.stdout.write(JSON.stringify([{ filename: "christang-keel-5.1.0.tgz" }]));
25271
25282
  }
25283
+ // FAKE_NPM_LATEST is what `npm view <package> version` prints, and
25284
+ // FAKE_NPM_VIEW_EXIT makes it exit with that status instead (#421).
25285
+ if (args[0] === "view") {
25286
+ if (process.env.FAKE_NPM_VIEW_EXIT) {
25287
+ process.stderr.write("npm error code E404\n");
25288
+ process.exit(Number(process.env.FAKE_NPM_VIEW_EXIT));
25289
+ }
25290
+ process.stdout.write(`${process.env.FAKE_NPM_LATEST || "5.1.0"}\n`);
25291
+ }
25272
25292
  process.exit(0);
25273
25293
  }
25274
25294
  const joined = args.join(" ");
@@ -25447,6 +25467,101 @@ def validate_update_covers_installed_hosts_scenario() -> int:
25447
25467
  return 0
25448
25468
 
25449
25469
 
25470
+ def validate_update_registry_lag_scenario() -> int:
25471
+ """Issue #421: a version the registry does not serve yet is `pending`.
25472
+
25473
+ Right after a release, the Claude marketplace names the new version while
25474
+ the npm registry the machine reaches still serves the old one, and
25475
+ `claude plugin update` exits 1 with `E404 No match found for version`.
25476
+ A rerun minutes later succeeds, so that is not a failure; any E404 the
25477
+ registry's own answer does not explain still is.
25478
+ """
25479
+ label = "update-registry-lag:"
25480
+ e404 = ('✘ Failed to update plugin "keel@keel-marketplace": Could not resolve @christang/keel@5.2.0 '
25481
+ "from the npm registry: E404 No match found for version 5.2.0")
25482
+ with tempfile.TemporaryDirectory(prefix="keel-update-421-", ignore_cleanup_errors=True) as raw:
25483
+ tmp = Path(raw)
25484
+ fake = tmp / "fake.js"
25485
+ write_text(fake, UPDATE_FAKE)
25486
+ launchers = {}
25487
+ for host in ("npm", "claude", "codex"):
25488
+ launcher = tmp / f"fake-{host}"
25489
+ write_text(launcher, f'#!/bin/sh\nFAKE_HOST={host} exec node "{fake}" "$@"\n')
25490
+ launcher.chmod(0o755)
25491
+ launchers[host] = launcher
25492
+ source = tmp / "codex-source"
25493
+ write_text(source / "hooks/codex.json", "{}\n")
25494
+
25495
+ def update(env_extra: dict[str, str]):
25496
+ log = tmp / "log.jsonl"
25497
+ state = tmp / "state.json"
25498
+ for stale in (log, state):
25499
+ if stale.exists():
25500
+ stale.unlink()
25501
+ log.write_text("")
25502
+ env = dict(os.environ)
25503
+ env.update({
25504
+ "KEEL_UPDATE_NPM": str(launchers["npm"]),
25505
+ "KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
25506
+ "KEEL_UPDATE_CODEX": str(launchers["codex"]),
25507
+ "CODEX_HOME": str(tmp / "codex-home"),
25508
+ "FAKE_LOG": str(log), "FAKE_STATE": str(state),
25509
+ "FAKE_CODEX_SOURCE": str(source),
25510
+ "FAKE_FAIL_CLAUDE": "plugin update keel", "FAKE_FAIL_STDERR_CLAUDE": e404,
25511
+ })
25512
+ env.pop("KEEL_UPDATE_SOURCE", None)
25513
+ env.update(env_extra)
25514
+ result = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--update"], cwd=tmp, env=env,
25515
+ text=True, capture_output=True, check=False, timeout=60)
25516
+ lines = {}
25517
+ for component in ("cli", "claude plugin", "codex plugin"):
25518
+ found = [l for l in result.stdout.splitlines() if l.startswith(f"keel update: {component}:")]
25519
+ lines[component] = found[0] if len(found) == 1 else ""
25520
+ return result, lines
25521
+
25522
+ result, lines = update({"FAKE_NPM_LATEST": "5.1.0"})
25523
+ claude = lines["claude plugin"]
25524
+ if not claude.startswith("keel update: claude plugin: pending"):
25525
+ report(f"{label} a version the registry does not serve yet was not reported pending: {claude!r}")
25526
+ return 1
25527
+ for needle in ("5.2.0", "5.1.0", "rerun keel --update", "few minutes"):
25528
+ if needle not in claude:
25529
+ report(f"{label} the pending Claude line does not name {needle!r}: {claude!r}")
25530
+ return 1
25531
+ if "failed" in claude:
25532
+ report(f"{label} the pending Claude line still reads failed: {claude!r}")
25533
+ return 1
25534
+ if "registry's latest here is 5.1.0" not in lines["cli"]:
25535
+ report(f"{label} the CLI line does not name 5.1.0 as the registry's latest: {lines['cli']!r}")
25536
+ return 1
25537
+ if "5.0.0 -> 5.1.0" not in lines["codex plugin"]:
25538
+ report(f"{label} the Codex line did not still update: {lines['codex plugin']!r}")
25539
+ return 1
25540
+ if result.returncode != 0:
25541
+ report(f"{label} a pending Claude plugin failed the update: exit={result.returncode} {result.stdout!r}")
25542
+ return 1
25543
+
25544
+ for case, env_extra in (("the registry serves 5.2.0", {"FAKE_NPM_LATEST": "5.2.0"}),
25545
+ ("npm view exits 1", {"FAKE_NPM_VIEW_EXIT": "1"})):
25546
+ result, lines = update(env_extra)
25547
+ claude = lines["claude plugin"]
25548
+ if not claude.startswith("keel update: claude plugin: failed"):
25549
+ report(f"{label} when {case}, the Claude line does not read failed: {claude!r}")
25550
+ return 1
25551
+ if "E404 No match found" not in claude:
25552
+ report(f"{label} when {case}, the failed Claude line does not carry the host's E404: {claude!r}")
25553
+ return 1
25554
+ if result.returncode == 0:
25555
+ report(f"{label} when {case}, the update exited 0: {result.stdout!r}")
25556
+ return 1
25557
+
25558
+ if "update-registry-lag" not in {name for name, _ in SCENARIOS}:
25559
+ report(f"{label} scenario is not registered.")
25560
+ return 1
25561
+ report("update-registry-lag scenario passed.")
25562
+ return 0
25563
+
25564
+
25450
25565
  OVERLAY_START_RE = re.compile(r"<!--\s*keel:openspec-surface-overlay version=([^ ]+) -->")
25451
25566
  OVERLAY_BLOCK_RE = re.compile(
25452
25567
  r"<!--\s*keel:openspec-surface-overlay(?:\s+[^>]*)?\s*-->[\s\S]*?"
@@ -40497,6 +40612,121 @@ def workflow_job_block(workflow: str, job: str) -> str:
40497
40612
  return match.group(1) if match else ""
40498
40613
 
40499
40614
 
40615
+ def registry_wait_problem(workflow: str) -> str | None:
40616
+ """Return why `publish.yml` would release before the registry serves it, or None.
40617
+
40618
+ Takes text so a planted copy can prove the rule fires (#421).
40619
+ """
40620
+ publish = workflow_job_block(workflow, "publish")
40621
+ steps = re.split(r"\n(?= - name: )", publish)
40622
+ names = [re.match(r"\s*- name: ([^\n]*)", step).group(1).strip() if re.match(r"\s*- name: ", step) else ""
40623
+ for step in steps]
40624
+ waits = [i for i, step in enumerate(steps) if "scripts/await_registry.js" in step]
40625
+ if not waits:
40626
+ return f"releases before the registry serves the version — {PUBLISH_WORKFLOW} never runs scripts/await_registry.js."
40627
+ if "Publish" not in names or "Tag and release the landed version" not in names:
40628
+ return f"{PUBLISH_WORKFLOW} has no `Publish` or no `Tag and release the landed version` step to order the wait between."
40629
+ wait = waits[0]
40630
+ if not names.index("Publish") < wait < names.index("Tag and release the landed version"):
40631
+ return ("releases before the registry serves the version — the scripts/await_registry.js step is not "
40632
+ "between `Publish` and `Tag and release the landed version`.")
40633
+ condition = re.search(r"^\s*if: ([^\n]*)", steps[names.index("Publish")], re.M)
40634
+ if not condition or f"if: {condition.group(1)}" not in steps[wait]:
40635
+ return "the registry wait does not share the `Publish` step's skip condition."
40636
+ if "steps.plan.outputs.version" not in steps[wait]:
40637
+ return "the registry wait does not wait for the planned version."
40638
+ return None
40639
+
40640
+
40641
+ AWAIT_NPM_FAKE = r"""const fs = require("fs");
40642
+ const count = process.env.FAKE_COUNT;
40643
+ const calls = (fs.existsSync(count) ? Number(fs.readFileSync(count, "utf8")) : 0) + 1;
40644
+ fs.writeFileSync(count, String(calls));
40645
+ fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify(process.argv.slice(2)) + "\n");
40646
+ const after = process.env.FAKE_SERVE_AFTER;
40647
+ if (after === "never" || calls <= Number(after)) {
40648
+ process.stderr.write("npm error code E404\nnpm error 404 No match found for version 5.2.0\n");
40649
+ process.exit(1);
40650
+ }
40651
+ process.stdout.write("5.2.0\n");
40652
+ """
40653
+
40654
+
40655
+ def validate_publish_awaits_registry_scenario() -> int:
40656
+ """Issue #421: a release is created only once the registry serves it.
40657
+
40658
+ The release used to announce a version the registry's read side would not
40659
+ serve for minutes, and the first `keel --update` after it failed.
40660
+ """
40661
+ label = "publish-awaits-registry:"
40662
+ script = ROOT / "scripts/await_registry.js"
40663
+ if not script.is_file():
40664
+ report(f"{label} scripts/await_registry.js is missing.")
40665
+ return 1
40666
+ with tempfile.TemporaryDirectory(prefix="keel-await-421-", ignore_cleanup_errors=True) as raw:
40667
+ tmp = Path(raw)
40668
+ fake = tmp / "fake-npm.js"
40669
+ write_text(fake, AWAIT_NPM_FAKE)
40670
+ launcher = tmp / "fake-npm"
40671
+ write_text(launcher, f'#!/bin/sh\nexec node "{fake}" "$@"\n')
40672
+ launcher.chmod(0o755)
40673
+
40674
+ def wait(serve_after: str, *extra: str):
40675
+ count, log = tmp / "count", tmp / "log.jsonl"
40676
+ for stale in (count, log):
40677
+ if stale.exists():
40678
+ stale.unlink()
40679
+ log.write_text("")
40680
+ env = dict(os.environ)
40681
+ env.update({"KEEL_AWAIT_NPM": str(launcher), "FAKE_COUNT": str(count), "FAKE_LOG": str(log),
40682
+ "FAKE_SERVE_AFTER": serve_after})
40683
+ result = subprocess.run(["node", str(script), "@christang/keel", "5.2.0", "--interval-seconds", "0", *extra],
40684
+ cwd=tmp, env=env, text=True, capture_output=True, check=False, timeout=60)
40685
+ calls = [json.loads(line) for line in log.read_text().splitlines() if line.strip()]
40686
+ return result, calls
40687
+
40688
+ result, calls = wait("2")
40689
+ if result.returncode != 0 or len(calls) != 3:
40690
+ report(f"{label} a version served on the third poll did not end the wait after 3 polls with exit 0: "
40691
+ f"exit={result.returncode} polls={len(calls)} {result.stdout!r} {result.stderr!r}")
40692
+ return 1
40693
+ if calls[0][:3] != ["view", "@christang/keel@5.2.0", "version"]:
40694
+ report(f"{label} the wait did not ask npm for the exact version: {calls[0]!r}")
40695
+ return 1
40696
+
40697
+ result, calls = wait("never", "--timeout-seconds", "1")
40698
+ said = result.stdout + result.stderr
40699
+ if result.returncode == 0:
40700
+ report(f"{label} a version never served ended the wait with exit 0: {said!r}")
40701
+ return 1
40702
+ for needle in ("5.2.0", "1 s"):
40703
+ if needle not in said:
40704
+ report(f"{label} the timed-out wait does not name {needle!r}: {said!r}")
40705
+ return 1
40706
+
40707
+ workflow = (ROOT / PUBLISH_WORKFLOW).read_text(encoding="utf-8")
40708
+ problem = registry_wait_problem(workflow)
40709
+ if problem:
40710
+ report(f"{label} {problem}")
40711
+ return 1
40712
+ tag_step = workflow.find(" - name: Tag and release the landed version")
40713
+ wait_start = workflow.rfind(" - name: ", 0, workflow.find("scripts/await_registry.js"))
40714
+ wait_end = workflow.find("\n - name: ", wait_start + 1) + 1
40715
+ moved = workflow[:wait_start] + workflow[wait_end:] + workflow[wait_start:wait_end]
40716
+ if tag_step < 0:
40717
+ report(f"{label} {PUBLISH_WORKFLOW} has no `Tag and release the landed version` step to plant a copy against.")
40718
+ return 1
40719
+ if not registry_wait_problem(moved):
40720
+ report(f"{label} a planted copy with the wait moved after the tag step was not refused.")
40721
+ return 1
40722
+
40723
+ if "publish-awaits-registry" not in {name for name, _ in SCENARIOS}:
40724
+ report(f"{label} scenario is not registered.")
40725
+ return 1
40726
+ report("publish-awaits-registry scenario passed.")
40727
+ return 0
40728
+
40729
+
40500
40730
  def landing_problem(workflow: str) -> str | None:
40501
40731
  """Return the problem the landing path in `publish.yml` has, or None.
40502
40732
 
@@ -41542,9 +41772,11 @@ SCENARIOS: tuple = (
41542
41772
  ("update-claude-refresh-retry", validate_update_claude_refresh_retry_scenario),
41543
41773
  ("update-host-query-timeout", validate_update_host_query_timeout_scenario),
41544
41774
  ("update-codex-from-disk", validate_update_codex_from_disk_scenario),
41775
+ ("update-registry-lag", validate_update_registry_lag_scenario),
41545
41776
  ("refresh-covers-every-target", validate_refresh_covers_every_target_scenario),
41546
41777
  ("directory-branch-advances", validate_directory_branch_advances_scenario),
41547
41778
  ("release-notes-name-the-directory-branch", validate_release_notes_name_the_directory_branch_scenario),
41779
+ ("publish-awaits-registry", validate_publish_awaits_registry_scenario),
41548
41780
  ("directory-tree-is-the-package-renamed", validate_directory_tree_is_the_package_renamed_scenario),
41549
41781
  ("init-declares-plugin-auto-update", validate_init_declares_plugin_auto_update_scenario),
41550
41782
  ("context-names-the-protocol-refresh", validate_context_names_the_protocol_refresh_scenario),
@@ -166,6 +166,7 @@ const CONFIG_DECLARATIONS = [
166
166
  "read_only_roles",
167
167
  "issue_roles",
168
168
  "patrol",
169
+ "shift",
169
170
  "owner_language",
170
171
  ];
171
172
 
@@ -995,7 +996,9 @@ function readPatrolDeclaration(repo) {
995
996
  // `shift: permission_mode:` for the session a CLI hand-off starts (#357 D5).
996
997
  const PERMISSION_MODES = ["default", "acceptEdits", "auto", "plan", "bypassPermissions"];
997
998
  // `shift: keep_old_sessions:`, how many stopped old shift sessions a hand-over
998
- // leaves listed per role (#397 D2): a whole number, 3 when absent or unreadable.
999
+ // leaves listed per role (#397 D2): a whole number, 0 when absent or unreadable,
1000
+ // so the old shift leaves the session list where the owner could mistake it for
1001
+ // the current one (#418).
999
1002
  function readShiftDeclaration(repo) {
1000
1003
  const block = configMap(repo, "shift");
1001
1004
  const mode = block.permission_mode;
@@ -1004,9 +1007,9 @@ function readShiftDeclaration(repo) {
1004
1007
  if (PERMISSION_MODES.includes(mode)) permissionMode = mode;
1005
1008
  else if (mode !== undefined) messages.push(`keel/config.yaml shift: permission_mode \`${mode}\` is not one of ${PERMISSION_MODES.join(", ")}, so it is ignored.`);
1006
1009
  const keep = block.keep_old_sessions;
1007
- let keepOldSessions = 3;
1010
+ let keepOldSessions = 0;
1008
1011
  if (keep !== undefined && /^\d+$/.test(String(keep).trim())) keepOldSessions = Number(String(keep).trim());
1009
- else if (keep !== undefined) messages.push(`keel/config.yaml shift: keep_old_sessions \`${keep}\` is not a whole number, so 3 apply.`);
1012
+ else if (keep !== undefined) messages.push(`keel/config.yaml shift: keep_old_sessions \`${keep}\` is not a whole number, so 0 applies.`);
1010
1013
  return { permissionMode, keepOldSessions, message: messages.length ? messages.join(" ") : null };
1011
1014
  }
1012
1015
 
package/src/core/shift.js CHANGED
@@ -1204,8 +1204,13 @@ const CLEAR_HINT = [
1204
1204
  // or — without a chat role — the person who opens it.
1205
1205
  function clearHint(result) {
1206
1206
  if (result.queued) {
1207
+ const own = result.cli.session.slice(0, 8);
1208
+ // Nothing kept by default (#418): the old shift is removed once Keel holds its transcript.
1209
+ const kept = require("./config").readShiftDeclaration(result.worktree).keepOldSessions > 0
1210
+ ? `its conversation is kept, \`claude attach ${own}\` reopens it`
1211
+ : `then removes it from the session list once Keel's store holds its transcript, which \`keel shift history ${result.role} --show ${own}\` prints`;
1207
1212
  return "This is a Claude Code CLI session, which cannot clear itself (#357). End your turn now: once this session has finished, "
1208
- + `a waiter stops it — its conversation is kept, \`claude attach ${result.cli.session.slice(0, 8)}\` reopens it — and starts a new session `
1213
+ + `a waiter stops it — ${kept} — and starts a new session `
1209
1214
  + `named for its start, \`${result.role} · <MM-DD HH:MM>\`, in ${result.worktree} that runs \`keel shift resume\`; \`keel tick\` does the same if the waiter is gone. \`keel shift status\` shows the hand-off.`;
1210
1215
  }
1211
1216
  let last;