@christang/keel 5.217.0 → 5.218.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.217.0",
3
+ "version": "5.218.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.217.0 -->
1
+ <!-- keel:start version=5.218.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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.217.0",
3
+ "version": "5.218.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.217.0",
9
+ "version": "5.218.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.217.0",
5
+ "version": "5.218.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.217.0",
3
+ "version": "5.218.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.217.0",
3
+ "version": "5.218.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.217.0"
38
+ PACKAGE_VERSION = "5.218.0"
39
39
 
40
40
 
41
- PROTOCOL_VERSION = "5.217.0"
41
+ PROTOCOL_VERSION = "5.218.0"
42
42
 
43
43
 
44
44
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
@@ -428,6 +428,9 @@ SCENARIOS: tuple = (
428
428
  ("shift-cli-removes-after-exit", shift.validate_shift_cli_removes_after_exit_scenario),
429
429
  ("shift-cli-keeps-worktree-in-use", shift.validate_shift_cli_keeps_worktree_in_use_scenario),
430
430
  ("shift-cli-names-failed-removal", shift.validate_shift_cli_names_failed_removal_scenario),
431
+ ("shift-ready-says-session-stays", shift.validate_shift_ready_says_session_stays_scenario),
432
+ ("shift-ready-promises-removal-when-removable", shift.validate_shift_ready_promises_removal_when_removable_scenario),
433
+ ("shift-ready-kept-session-names-shared-worktree", shift.validate_shift_ready_kept_session_names_shared_worktree_scenario),
431
434
  ("shift-cli-names-host-failure", shift.validate_shift_cli_names_host_failure_scenario),
432
435
  ("tick-retries-failed-wake", shift.validate_tick_retries_failed_wake_scenario),
433
436
  ("shift-cli-handover-claims-once", shift.validate_shift_cli_handover_claims_once_scenario),
@@ -3726,14 +3726,20 @@ def validate_shift_cli_removes_after_exit_scenario() -> int:
3726
3726
  return 0
3727
3727
 
3728
3728
 
3729
- def handover_old_session(base: Path, row_cwd: Path, worktree_path: Path | None, **fake_env: str):
3729
+ def handover_old_session(base: Path, row_cwd: Path, worktree_path: Path | None, ready_out: list | None = None,
3730
+ config_text: str | None = None, **fake_env: str):
3730
3731
  """A delivered hand-over of `5b14fbae` from verify's worktree under the contract fake (#492).
3731
3732
 
3732
3733
  Returns the `rm` calls the fake logged and `keel shift status` from rtl.
3733
3734
  The row's `cwd` and the host's recorded `worktreePath` are the inputs.
3735
+ `ready_out`, when given, receives what `shift ready --wake` printed as text and then as `--json` (#506).
3734
3736
  """
3735
3737
  OLD = "5b14fbae-b6aa-40b6-a72a-b3f89d2c6eea"
3736
3738
  rtl, verify, env, _ = shift_scratch(base)
3739
+ if config_text is not None:
3740
+ write_text(verify / "keel" / "config.yaml", config_text)
3741
+ for git in (["add", "keel/config.yaml"], ["commit", "-q", "-m", "declare shift"], ["push", "-q", "origin", "HEAD"]):
3742
+ subprocess.run(["git", *git], cwd=verify, check=True, capture_output=True)
3737
3743
  row_cwd = {"rtl": rtl, "verify": verify}[str(row_cwd)]
3738
3744
  agents, calls, fake, config = base / "agents.json", base / "calls.jsonl", base / "fake-claude", base / "claude"
3739
3745
  write_text(fake, HANDOVER_CONTRACT_FAKE)
@@ -3755,6 +3761,9 @@ def handover_old_session(base: Path, row_cwd: Path, worktree_path: Path | None,
3755
3761
  readied = run_keel(verify, "shift", "ready", "--wake", "next: rerun R032", env=cli_env)
3756
3762
  if readied.returncode != 0:
3757
3763
  raise RuntimeError(f"ready --wake failed: {readied.stderr!r}")
3764
+ if ready_out is not None:
3765
+ as_json = run_keel(verify, "shift", "ready", "--wake", "--json", "next: rerun R032", env=cli_env)
3766
+ ready_out.extend([readied.stdout, as_json.stdout])
3758
3767
  run_keel(verify, "tick", "--repo", str(rtl), env=env)
3759
3768
  removals = [json.loads(line) for line in calls.read_text().splitlines() if json.loads(line)["argv"][:1] == ["rm"]]
3760
3769
  return removals, run_keel(rtl, "shift", "status", env=env).stdout, verify
@@ -3818,6 +3827,101 @@ def validate_shift_cli_names_failed_removal_scenario() -> int:
3818
3827
  return 0
3819
3828
 
3820
3829
 
3830
+ def validate_shift_ready_says_session_stays_scenario() -> int:
3831
+ """Issue #506: `shift ready` does not promise a removal the hand-over will not carry out.
3832
+
3833
+ The session had made its worktree with `EnterWorktree` and the new shift
3834
+ starts in it, so `claude rm` would delete the worktree and the hand-over
3835
+ leaves the session listed (#492). `ready` printed that it is removed.
3836
+ """
3837
+ label = "shift-ready-says-session-stays:"
3838
+ with tempfile.TemporaryDirectory(prefix="keel-shift-506a-") as raw:
3839
+ shown: list[str] = []
3840
+ try:
3841
+ removals, _status, verify = handover_old_session(Path(raw), Path("rtl"), Path("verify"), ready_out=shown)
3842
+ except RuntimeError as error:
3843
+ report(f"{label} {error}")
3844
+ return 1
3845
+ if len(shown) != 2:
3846
+ report(f"{label} the fixture did not return what ready printed: {shown!r}")
3847
+ return 1
3848
+ try:
3849
+ clear = json.loads(shown[1])["clear"]
3850
+ except (ValueError, KeyError) as error:
3851
+ report(f"{label} ready --json has no readable `clear` field ({error!r}): {shown[1]!r}")
3852
+ return 1
3853
+ for name, text in (("text", shown[0]), ("clear", clear)):
3854
+ if "removes it from the session list" in text:
3855
+ report(f"{label} the {name} hint promises a removal the hand-over does not carry out: {text!r}")
3856
+ return 1
3857
+ for needle in ("stays in `claude agents`", str(verify), "claude rm", "claude attach 5b14fbae"):
3858
+ if needle not in text:
3859
+ report(f"{label} the {name} hint does not say {needle!r}: {text!r}")
3860
+ return 1
3861
+ if any(r["argv"][1:2] == ["5b14fbae"] for r in removals):
3862
+ report(f"{label} the hand-over removed the session the hint said stays: {removals!r}")
3863
+ return 1
3864
+ if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
3865
+ report(f"{label} the scenario registry does not include it.")
3866
+ return 1
3867
+ report(f"{label.rstrip(':')} scenario passed.")
3868
+ return 0
3869
+
3870
+
3871
+ def validate_shift_ready_promises_removal_when_removable_scenario() -> int:
3872
+ """Issue #506: a session nothing keeps is still told it is removed, and is."""
3873
+ label = "shift-ready-promises-removal-when-removable:"
3874
+ with tempfile.TemporaryDirectory(prefix="keel-shift-506b-") as raw:
3875
+ shown: list[str] = []
3876
+ try:
3877
+ removals, _status, _verify = handover_old_session(Path(raw), Path("verify"), None, ready_out=shown)
3878
+ except RuntimeError as error:
3879
+ report(f"{label} {error}")
3880
+ return 1
3881
+ if len(shown) != 2:
3882
+ report(f"{label} the fixture did not return what ready printed: {shown!r}")
3883
+ return 1
3884
+ if "removes it from the session list" not in shown[0]:
3885
+ report(f"{label} the hint no longer promises the removal that follows: {shown[0]!r}")
3886
+ return 1
3887
+ if "stays in `claude agents`" in shown[0]:
3888
+ report(f"{label} the hint says a removable session stays: {shown[0]!r}")
3889
+ return 1
3890
+ if not any(r["argv"][1:2] == ["5b14fbae"] for r in removals):
3891
+ report(f"{label} the hand-over did not call claude rm for the session the hint said is removed: {removals!r}")
3892
+ return 1
3893
+ if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
3894
+ report(f"{label} the scenario registry does not include it.")
3895
+ return 1
3896
+ report(f"{label.rstrip(':')} scenario passed.")
3897
+ return 0
3898
+
3899
+
3900
+ def validate_shift_ready_kept_session_names_shared_worktree_scenario() -> int:
3901
+ """Issue #506: a kept session whose worktree is the new shift's says so."""
3902
+ label = "shift-ready-kept-session-names-shared-worktree:"
3903
+ with tempfile.TemporaryDirectory(prefix="keel-shift-506c-") as raw:
3904
+ shown: list[str] = []
3905
+ try:
3906
+ _removals, _status, verify = handover_old_session(Path(raw), Path("rtl"), Path("verify"), ready_out=shown,
3907
+ config_text="shift:\n keep_old_sessions: 1\n")
3908
+ except RuntimeError as error:
3909
+ report(f"{label} {error}")
3910
+ return 1
3911
+ if len(shown) != 2:
3912
+ report(f"{label} the fixture did not return what ready printed: {shown!r}")
3913
+ return 1
3914
+ for needle in ("its conversation is kept", "claude attach 5b14fbae", str(verify), "the new shift's"):
3915
+ if needle not in shown[0]:
3916
+ report(f"{label} the hint does not say {needle!r}: {shown[0]!r}")
3917
+ return 1
3918
+ if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
3919
+ report(f"{label} the scenario registry does not include it.")
3920
+ return 1
3921
+ report(f"{label.rstrip(':')} scenario passed.")
3922
+ return 0
3923
+
3924
+
3821
3925
  def validate_shift_cli_names_host_failure_scenario() -> int:
3822
3926
  """Issue #408: a hand-off the host cannot be asked about says why it waits."""
3823
3927
  label = "shift-cli-names-host-failure:"
package/src/core/shift.js CHANGED
@@ -636,6 +636,20 @@ function keptCopyOf(where, role, transcript) {
636
636
  }
637
637
  }
638
638
 
639
+ // Worktrees in use: the hand-off's, every bound one, and each other listed
640
+ // session's (#492 D2). `claude rm` deletes the worktree a session created, so a
641
+ // session whose worktree is in use stays listed. `ready` asks the same question
642
+ // to say so up front (#506 D1), without a listing, so the last reason is
643
+ // evaluated only when `listed` is given.
644
+ function worktreeInUse(roles, handOffWorktree, worktree, row, listed) {
645
+ const real = realpath(worktree);
646
+ if (handOffWorktree && realpath(handOffWorktree) === real) return "the new shift's worktree";
647
+ const binding = Object.entries(roles).find(([tree]) => realpath(tree) === real);
648
+ if (binding) return `bound to role ${binding[1]}`;
649
+ const other = (listed || []).find((r) => r && r !== row && r.cwd && realpath(r.cwd) === real);
650
+ return other ? `session ${other.id || other.sessionId.slice(0, 8)} runs there` : null;
651
+ }
652
+
639
653
  // After a delivered hand-over or a resume, the newest `keep` stopped background
640
654
  // sessions of the role stay listed; each older one is removed with `claude rm`
641
655
  // once Keel's store holds its transcript (#397 D2). `claude rm` leaves the
@@ -669,15 +683,7 @@ function removeOldSessions(claude, where, entry, keep) {
669
683
  })
670
684
  .filter(({ transcript, kept }) => transcript || fs.existsSync(kept))
671
685
  .sort((a, b) => (Number(b.row.startedAt) || 0) - (Number(a.row.startedAt) || 0));
672
- // Worktrees in use: the hand-off's, every bound one, and each other listed session's (#492 D2).
673
- const inUse = (worktree, row) => {
674
- const real = realpath(worktree);
675
- if (entry.worktree && realpath(entry.worktree) === real) return "the new shift's worktree";
676
- const binding = Object.entries(roles).find(([tree]) => realpath(tree) === real);
677
- if (binding) return `bound to role ${binding[1]}`;
678
- const other = listed.find((r) => r && r !== row && r.cwd && realpath(r.cwd) === real);
679
- return other ? `session ${idOf(other)} runs there` : null;
680
- };
686
+ const inUse = (worktree, row) => worktreeInUse(roles, entry.worktree, worktree, row, listed);
681
687
  const removed = [];
682
688
  const notRemoved = old.slice(0, keep).map(({ row }) => ({ id: idOf(row), reason: "kept by `shift: keep_old_sessions`" }));
683
689
  for (const { row, worktree, transcript } of old.slice(keep)) {
@@ -1518,13 +1524,19 @@ const CLEAR_HINT = [
1518
1524
 
1519
1525
  // Who starts the new session (#293 D3): the coordinator that asked, nobody,
1520
1526
  // or — without a chat role — the person who opens it.
1521
- function clearHint(result) {
1527
+ function clearHint(result, where) {
1522
1528
  if (result.queued) {
1523
1529
  const own = result.cli.session.slice(0, 8);
1530
+ // The hand-over leaves this session listed when its worktree is in use (#492), and says so here (#506 D2).
1531
+ const host = hostWorktree({ id: own, sessionId: result.cli.session });
1532
+ const using = host && fs.existsSync(host)
1533
+ ? worktreeInUse(store.readJsonFile(path.join(where.root, "roles.json")), result.worktree, host, null, null) : null;
1524
1534
  // Nothing kept by default (#418): the old shift is removed once Keel holds its transcript.
1525
1535
  const kept = require("./config").readShiftDeclaration(result.worktree).keepOldSessions > 0
1526
- ? `its conversation is kept, \`claude attach ${own}\` reopens it`
1527
- : `then removes it from the session list once Keel's store holds its transcript, which \`keel shift history ${result.role} --show ${own}\` prints`;
1536
+ ? `its conversation is kept, \`claude attach ${own}\` reopens it${using ? `, beside the new shift, because its worktree ${host} is in use (${using})` : ""}`
1537
+ : using
1538
+ ? `it stays in \`claude agents\`, because its worktree ${host} is in use (${using}) and \`claude rm\` would delete it, and \`claude attach ${own}\` brings it back beside the new shift`
1539
+ : `then removes it from the session list once Keel's store holds its transcript, which \`keel shift history ${result.role} --show ${own}\` prints`;
1528
1540
  return "This is a Claude Code CLI session, which cannot clear itself (#357). End your turn now: once this session has finished, "
1529
1541
  + `a waiter stops it — ${kept} — and starts a new session `
1530
1542
  + `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.`;
@@ -1620,7 +1632,7 @@ function runShift(argv) {
1620
1632
  case "ready": {
1621
1633
  const result = ready(where, { ...options, text: rest.join(" ") });
1622
1634
  const whose = result.role || "this worktree (no chat role, so no request to close)";
1623
- const hint = clearHint(result);
1635
+ const hint = clearHint(result, where);
1624
1636
  out({ ...result, clear: hint }, `Stored the shift note for ${whose} at ${result.note}${result.closed.length ? ` and closed ${result.closed.join(", ")}` : ""}.\n${hint}`);
1625
1637
  return 0;
1626
1638
  }