@christang/keel 5.151.0 → 5.152.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.151.0",
3
+ "version": "5.152.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.151.0 -->
1
+ <!-- keel:start version=5.152.0 -->
2
2
  ## Keel Bootstrap
3
3
 
4
4
  - Start every session with `keel context`; OpenSpec artifacts and Git are the only durable authority — never native memory, goals, or transcripts.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.151.0",
3
+ "version": "5.152.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.151.0",
9
+ "version": "5.152.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.151.0",
5
+ "version": "5.152.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.151.0",
3
+ "version": "5.152.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.151.0",
3
+ "version": "5.152.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",
@@ -49,8 +49,8 @@ REQUIRED_SCRIPTS = [
49
49
  "scripts/validate_plugin.py",
50
50
  ]
51
51
 
52
- PACKAGE_VERSION = "5.151.0"
53
- PROTOCOL_VERSION = "5.151.0"
52
+ PACKAGE_VERSION = "5.152.0"
53
+ PROTOCOL_VERSION = "5.152.0"
54
54
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
55
55
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
56
56
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -6110,6 +6110,70 @@ def shift_scratch(base: Path) -> tuple[Path, Path, dict, Path]:
6110
6110
  return rtl, verify, env, remote
6111
6111
 
6112
6112
 
6113
+ def validate_shift_resume_checks_commits_scenario() -> int:
6114
+ """Issue #347: a shift note's commit ids go stale before the next shift reads it.
6115
+
6116
+ `keel shift resume` lists each commit id and `<branch> @ <sha>` the note
6117
+ names, checked against the remote-tracking refs as of the last fetch:
6118
+ already in the default branch, branch moved, branch gone, or not found.
6119
+ It fetches nothing.
6120
+ """
6121
+ label = "shift-resume-checks-commits:"
6122
+ with tempfile.TemporaryDirectory(prefix="keel-shift-347-") as raw:
6123
+ base = Path(raw)
6124
+ rtl, verify, env, _ = shift_scratch(base)
6125
+
6126
+ def git(*args: str) -> str:
6127
+ return subprocess.run(["git", *args], cwd=rtl, text=True, capture_output=True, check=True).stdout.strip()
6128
+
6129
+ git("commit", "-q", "--allow-empty", "-m", "landed")
6130
+ git("push", "-q", "origin", "HEAD")
6131
+ landed = git("rev-parse", "HEAD")
6132
+ default = git("rev-parse", "--abbrev-ref", "HEAD")
6133
+ tree = git("rev-parse", "HEAD^{tree}")
6134
+ old = git("commit-tree", tree, "-p", landed, "-m", "feat one")
6135
+ git("push", "-q", "origin", f"{old}:refs/heads/feat")
6136
+ new = git("commit-tree", tree, "-p", old, "-m", "feat two")
6137
+ git("push", "-q", "origin", f"{new}:refs/heads/feat")
6138
+ note = (f"A84 {landed[:8]} is waiting to be merged. feat @ {old[:8]} waits for the push window. "
6139
+ f"gone-branch @ {landed[:8]} too. deadbee1 was the old base. Dated 20261018.")
6140
+ readied = run_keel(verify, "shift", "ready", note, env=env)
6141
+ if readied.returncode != 0:
6142
+ report(f"{label} ready failed: {readied.stderr}")
6143
+ return 1
6144
+ resumed = run_keel(verify, "shift", "resume", env=env)
6145
+ if resumed.returncode != 0:
6146
+ report(f"{label} resume failed: {resumed.stderr}")
6147
+ return 1
6148
+ lines = resumed.stdout.splitlines()
6149
+
6150
+ def line_for(token: str) -> str:
6151
+ return next((l for l in lines if l.lstrip().startswith(("- " + token, token))), "")
6152
+
6153
+ checks = (
6154
+ (landed[:8], f"already in origin/{default}"),
6155
+ (f"feat @ {old[:8]}", f"branch moved: now {new[:8]}"),
6156
+ (f"gone-branch @ {landed[:8]}", "branch gone"),
6157
+ ("deadbee1", "not found"),
6158
+ )
6159
+ for token, want in checks:
6160
+ found = line_for(token)
6161
+ if want not in found:
6162
+ report(f"{label} {token!r} is not marked {want!r}: {found!r} in {resumed.stdout!r}")
6163
+ return 1
6164
+ if line_for("20261018"):
6165
+ report(f"{label} a date was read as a commit id: {resumed.stdout!r}")
6166
+ return 1
6167
+ if "not fetched" not in resumed.stdout:
6168
+ report(f"{label} the check does not say it did not fetch: {resumed.stdout!r}")
6169
+ return 1
6170
+ if "shift-resume-checks-commits" not in {name for name, _ in SCENARIOS}:
6171
+ report(f"{label} scenario is not registered.")
6172
+ return 1
6173
+ report("shift-resume-checks-commits scenario passed.")
6174
+ return 0
6175
+
6176
+
6113
6177
  def validate_shift_role_elsewhere_scenario() -> int:
6114
6178
  """Issues #290, #291: a note filed under the role from another worktree.
6115
6179
 
@@ -41961,6 +42025,7 @@ SCENARIOS: tuple = (
41961
42025
  ("owner-language", validate_owner_language_scenario),
41962
42026
  ("owner-language-after-tools", validate_owner_language_after_tools_scenario),
41963
42027
  ("shift-history", validate_shift_history_scenario),
42028
+ ("shift-resume-checks-commits", validate_shift_resume_checks_commits_scenario),
41964
42029
  ("shift-keeps-transcripts", validate_shift_keeps_transcripts_scenario),
41965
42030
  ("shift-keeps-found-transcripts", validate_shift_keeps_found_transcripts_scenario),
41966
42031
  ("role-drift", validate_role_drift_scenario),
package/src/core/shift.js CHANGED
@@ -575,6 +575,65 @@ function resumeRole(where, named) {
575
575
  return named;
576
576
  }
577
577
 
578
+ // Notes cite `<branch> @ <sha>` and bare commit ids, which go stale between
579
+ // `ready` and `resume` (#347). Each is marked against the remote-tracking refs
580
+ // as they are: Keel fetches nothing, and says when they were last fetched.
581
+ const NOTE_PAIR = /([A-Za-z0-9][\w./-]*)\s*@\s*([0-9a-f]{7,40})\b/g;
582
+ const NOTE_SHA = /(?<![\w@/-])([0-9a-f]{7,40})\b/g;
583
+ const looksLikeSha = (token) => /[a-f]/.test(token) && /\d/.test(token);
584
+
585
+ function remoteDefault(cwd) {
586
+ const head = git(cwd, ["symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD"]);
587
+ if (head.ok && head.out) return head.out;
588
+ for (const name of ["origin/main", "origin/master"]) {
589
+ if (git(cwd, ["rev-parse", "--verify", "--quiet", `refs/remotes/${name}`]).ok) return name;
590
+ }
591
+ return null;
592
+ }
593
+
594
+ function noteCommits(cwd, text) {
595
+ const seen = new Set();
596
+ const named = [];
597
+ for (const match of String(text).matchAll(NOTE_PAIR)) {
598
+ if (!looksLikeSha(match[2])) continue;
599
+ named.push({ index: match.index, branch: match[1], sha: match[2], token: `${match[1]} @ ${match[2]}` });
600
+ seen.add(match.index + match[0].length - match[2].length);
601
+ }
602
+ for (const match of String(text).matchAll(NOTE_SHA)) {
603
+ if (!looksLikeSha(match[1]) || seen.has(match.index)) continue;
604
+ named.push({ index: match.index, branch: null, sha: match[1], token: match[1] });
605
+ }
606
+ named.sort((a, b) => a.index - b.index);
607
+ const listed = new Set();
608
+ const base = remoteDefault(cwd);
609
+ const commits = [];
610
+ for (const item of named) {
611
+ if (listed.has(item.token)) continue;
612
+ listed.add(item.token);
613
+ const marks = [];
614
+ const full = git(cwd, ["rev-parse", "--verify", "--quiet", `${item.sha}^{commit}`]);
615
+ if (!full.ok) marks.push("not found");
616
+ else if (base && git(cwd, ["merge-base", "--is-ancestor", full.out, base]).ok) marks.push(`already in ${base}`);
617
+ if (item.branch) {
618
+ const tip = git(cwd, ["rev-parse", "--verify", "--quiet", `refs/remotes/origin/${item.branch}`]);
619
+ if (!tip.ok) marks.push("branch gone");
620
+ else if (!full.ok || tip.out !== full.out) marks.push(`branch moved: now ${tip.out.slice(0, 8)}`);
621
+ }
622
+ commits.push({ token: item.token, marks: marks.length ? marks : ["current"] });
623
+ }
624
+ return commits;
625
+ }
626
+
627
+ function lastFetch(cwd) {
628
+ const file = git(cwd, ["rev-parse", "--git-path", "FETCH_HEAD"]);
629
+ if (!file.ok) return null;
630
+ try {
631
+ return store.isoLocal(fs.statSync(path.resolve(cwd, file.out)).mtime);
632
+ } catch {
633
+ return null;
634
+ }
635
+ }
636
+
578
637
  function resume(where, named = null) {
579
638
  const role = resumeRole(where, named);
580
639
  const note = waitingNote(where, role);
@@ -584,7 +643,7 @@ function resume(where, named = null) {
584
643
  const history = path.join(shiftDir(where), "history", `${role || path.basename(note, ".md")}-${stamp}.md`);
585
644
  fs.mkdirSync(path.dirname(history), { recursive: true });
586
645
  fs.renameSync(note, history);
587
- if (!role) return { role: null, note: history, text, told: null };
646
+ if (!role) return { role: null, note: history, text, told: null, commits: noteCommits(where.worktree, text), fetched: lastFetch(where.worktree) };
588
647
  // The cold-start message has done its work once the note is read.
589
648
  for (const record of store.unread(where, role)) {
590
649
  if (isShift(record)) store.advanceCursor(where, role, record.group, record.id);
@@ -598,7 +657,7 @@ function resume(where, named = null) {
598
657
  ? store.post(where, { group, text, refs: [REF] })
599
658
  : store.writeRecord(where, { group, kind: "message", from: role, refs: [REF], text })).id;
600
659
  }
601
- return { role, note: history, text, told, waiting: role ? unstarted(where, role) : [] };
660
+ return { role, note: history, text, told, waiting: role ? unstarted(where, role) : [], commits: noteCommits(where.worktree, text), fetched: lastFetch(where.worktree) };
602
661
  }
603
662
 
604
663
  function status(where) {
@@ -986,7 +1045,11 @@ function runShift(argv) {
986
1045
  + "`set_remote_control(\"self\", true)`, and rename the session back with `set_session_title`. "
987
1046
  + "Declaring `shift-restore` under authorize: in keel/config.yaml lets a woken session do this without asking."
988
1047
  : "";
989
- out(result, `${result.text.replace(/\s+$/, "")}\n\n(The note moved to ${result.note}.)${still}${remind ? `\n\n${patrolReminder(patrol)}` : ""}${remote}`);
1048
+ const commits = (result.commits || []).length
1049
+ ? `\n\nCommits the note names, against the remote-tracking refs (not fetched; last fetch ${result.fetched || "never"}):\n`
1050
+ + result.commits.map((c) => `- ${c.token}: ${c.marks.join("; ")}`).join("\n")
1051
+ : "";
1052
+ out(result, `${result.text.replace(/\s+$/, "")}${commits}\n\n(The note moved to ${result.note}.)${still}${remind ? `\n\n${patrolReminder(patrol)}` : ""}${remote}`);
990
1053
  return 0;
991
1054
  }
992
1055
  case "history": {