@christang/keel 5.143.0 → 5.145.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.143.0",
3
+ "version": "5.145.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.143.0 -->
1
+ <!-- keel:start version=5.145.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.
package/bin/keel.js CHANGED
@@ -1097,12 +1097,19 @@ function hostFails(executable, args) {
1097
1097
  return Boolean(result.error) || result.status !== 0;
1098
1098
  }
1099
1099
 
1100
+ // Why a host step failed: its spawn error, or its exit status with the last
1101
+ // line it wrote to stderr, so the cause is visible the first time (#359).
1102
+ function hostFailure(result) {
1103
+ if (result.error) return result.error.message;
1104
+ const last = String(result.stderr || "").trim().split(/\r?\n/).pop().trim();
1105
+ return `exited ${result.status}${last ? `: ${last}` : ""}`;
1106
+ }
1107
+
1100
1108
  function runHostSteps(component, name, executable, steps) {
1101
1109
  for (const args of steps) {
1102
1110
  const result = hostRun(executable, args);
1103
1111
  if (result.error || result.status !== 0) {
1104
- const why = result.error ? result.error.message : `exited ${result.status}`;
1105
- updateLine(component, "failed", `\`${name} ${args.join(" ")}\` ${why}`);
1112
+ updateLine(component, "failed", `\`${name} ${args.join(" ")}\` ${hostFailure(result)}`);
1106
1113
  return false;
1107
1114
  }
1108
1115
  }
@@ -1133,7 +1140,15 @@ function updateClaudePlugin(options) {
1133
1140
  updateLine(component, "absent", "Claude Code is not installed here or has no Keel plugin");
1134
1141
  return true;
1135
1142
  }
1136
- if (!runHostSteps(component, "claude", executable, steps)) return false;
1143
+ // The refresh fetches over the network, and on a proxied link it has failed
1144
+ // once and passed on a direct retry; one retry absorbs that, as for Codex (#359).
1145
+ let refreshed = hostRun(executable, steps[0]);
1146
+ if (refreshed.error || refreshed.status !== 0) refreshed = hostRun(executable, steps[0]);
1147
+ if (refreshed.error || refreshed.status !== 0) {
1148
+ updateLine(component, "failed", `\`claude ${steps[0].join(" ")}\` failed twice; ${hostFailure(refreshed)}`);
1149
+ return false;
1150
+ }
1151
+ if (!runHostSteps(component, "claude", executable, [steps[1]])) return false;
1137
1152
  const after = claudeKeel(executable);
1138
1153
  if (after && after.failed) {
1139
1154
  updateLine(component, "failed", `${after.failed} after the update, so its result is unverified`);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.143.0",
3
+ "version": "5.145.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.143.0",
9
+ "version": "5.145.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.143.0",
5
+ "version": "5.145.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.143.0",
3
+ "version": "5.145.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.143.0",
3
+ "version": "5.145.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.143.0"
53
- PROTOCOL_VERSION = "5.143.0"
52
+ PACKAGE_VERSION = "5.145.0"
53
+ PROTOCOL_VERSION = "5.145.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
@@ -6373,6 +6373,91 @@ def validate_shift_keeps_transcripts_scenario() -> int:
6373
6373
  return 0
6374
6374
 
6375
6375
 
6376
+ def validate_shift_keeps_found_transcripts_scenario() -> int:
6377
+ """Issue #361: a transcript `history` finds but never recorded is kept too.
6378
+
6379
+ Transcripts from before segments were recorded (#304) are listed
6380
+ `(found)`; the hook copied only recorded segments, and `history` read a
6381
+ copy only through a segment record, so the oldest conversations were the
6382
+ ones left unkept.
6383
+ """
6384
+ label = "shift-keeps-found-transcripts:"
6385
+ with tempfile.TemporaryDirectory(prefix="keel-shift-361-") as raw:
6386
+ base = Path(raw)
6387
+ rtl, verify, env, _ = shift_scratch(base)
6388
+ kept_dir = mailbox_common_dir(rtl) / "keel-chat" / "shift" / "transcripts" / "verify"
6389
+ roles = json.loads((mailbox_common_dir(rtl) / "keel-chat" / "roles.json").read_text(encoding="utf-8"))
6390
+ bound = next(path for path, role in roles.items() if role == "verify")
6391
+ project = base / "claude-config" / "projects" / re.sub(r"[^A-Za-z0-9]", "-", bound)
6392
+ project.mkdir(parents=True)
6393
+ env = {**env, "CLAUDE_CONFIG_DIR": str(base / "claude-config")}
6394
+
6395
+ def transcript(name: str, opening: str, said: str) -> Path:
6396
+ path = project / f"{name}.jsonl"
6397
+ path.write_text("\n".join(json.dumps(record) for record in (
6398
+ {"type": "user", "timestamp": "2026-10-02T01:00:00.000Z", "cwd": bound, "message": {"role": "user", "content": opening}},
6399
+ {"type": "assistant", "timestamp": "2026-10-02T01:00:05.000Z", "cwd": bound,
6400
+ "message": {"role": "assistant", "content": [{"type": "text", "text": said}]}},
6401
+ )) + "\n", encoding="utf-8")
6402
+ return path
6403
+
6404
+ def hook(path: Path) -> None:
6405
+ for event, name in (("session-start", "SessionStart"), ("user-prompt-submit", "UserPromptSubmit")):
6406
+ subprocess.run(
6407
+ ["node", str(ROOT / "bin" / "keel.js"), "chat", "hook", event],
6408
+ cwd=verify, env=env, text=True, capture_output=True, check=False,
6409
+ input=json.dumps({"cwd": str(verify), "hook_event_name": name, "session_id": "s1",
6410
+ "prompt": "go", "source": "startup", "transcript_path": str(path)}),
6411
+ )
6412
+
6413
+ old = transcript("old", "start the shift", "The ECC syndrome table was settled on day one.")
6414
+ scheduled = transcript("patrol", '<scheduled-task name="patrol">run', "patrol ran")
6415
+ listed = run_keel(verify, "shift", "history", "verify", env=env)
6416
+ if "(found)" not in next((l for l in listed.stdout.splitlines() if "old.jsonl" in l), ""):
6417
+ report(f"{label} the unrecorded transcript is not listed as found: {listed.stdout!r} {listed.stderr!r}")
6418
+ return 1
6419
+ hook(transcript("a", "carry on", "first recorded shift"))
6420
+ hook(transcript("b", "carry on", "second recorded shift"))
6421
+ kept_old = kept_dir / "old.jsonl.gz"
6422
+ if not kept_old.is_file():
6423
+ report(f"{label} a segment change left the found transcript unkept: "
6424
+ f"{sorted(p.name for p in kept_dir.glob('*')) if kept_dir.exists() else 'no directory'}")
6425
+ return 1
6426
+ if gzip.decompress(kept_old.read_bytes()) != old.read_bytes():
6427
+ report(f"{label} the found transcript's copy is not its bytes.")
6428
+ return 1
6429
+ if (kept_dir / "patrol.jsonl.gz").exists():
6430
+ report(f"{label} a scheduled run's transcript was kept as the role's conversation.")
6431
+ return 1
6432
+ if (kept_dir / "b.jsonl.gz").exists():
6433
+ report(f"{label} the current transcript was copied while it is still being written.")
6434
+ return 1
6435
+
6436
+ old.unlink()
6437
+ listed = run_keel(verify, "shift", "history", "verify", env=env)
6438
+ line = next((l for l in listed.stdout.splitlines() if "old.jsonl" in l), "")
6439
+ if "(missing)" in line:
6440
+ report(f"{label} the found transcript, deleted but kept, is listed missing: {listed.stdout!r}")
6441
+ return 1
6442
+ if "(kept)" not in line:
6443
+ report(f"{label} the found transcript, deleted but kept, is not listed (kept): {listed.stdout!r}")
6444
+ return 1
6445
+ found = run_keel(verify, "shift", "history", "verify", "--grep", "syndrome table", env=env)
6446
+ if "syndrome table" not in found.stdout:
6447
+ report(f"{label} --grep does not search the found transcript's copy: {found.stdout!r} {found.stderr!r}")
6448
+ return 1
6449
+ hook(transcript("c", "carry on", "third recorded shift"))
6450
+ listed = run_keel(verify, "shift", "history", "verify", env=env)
6451
+ if sum(1 for l in listed.stdout.splitlines() if "old.jsonl" in l) != 1:
6452
+ report(f"{label} another segment change did not leave the kept found transcript listed once: {listed.stdout!r}")
6453
+ return 1
6454
+ if "shift-keeps-found-transcripts" not in {name for name, _ in SCENARIOS}:
6455
+ report(f"{label} scenario is not registered.")
6456
+ return 1
6457
+ report("shift-keeps-found-transcripts scenario passed.")
6458
+ return 0
6459
+
6460
+
6376
6461
  def validate_shift_history_scenario() -> int:
6377
6462
  """Issue #304: a cleared shift's conversation stays findable.
6378
6463
 
@@ -23771,6 +23856,7 @@ if (failOn && args.join(" ").includes(failOn)) {
23771
23856
  if (failed < failTimes) {
23772
23857
  state.failed = { ...(state.failed || {}), [host]: failed + 1 };
23773
23858
  save();
23859
+ process.stderr.write(`fake ${host}: warming up\nfake ${host}: refused ${args.join(" ")}\n`);
23774
23860
  process.exit(1);
23775
23861
  }
23776
23862
  }
@@ -24047,6 +24133,97 @@ def validate_update_host_query_timeout_scenario() -> int:
24047
24133
  return 0
24048
24134
 
24049
24135
 
24136
+ def validate_update_claude_refresh_retry_scenario() -> int:
24137
+ """Issue #359: the Claude marketplace refresh failed once and passed on a direct retry.
24138
+
24139
+ `keel --update` retries `claude plugin marketplace update` once, as it does
24140
+ Codex's refresh, and a step that still fails names the host's last stderr
24141
+ line instead of only its exit status.
24142
+ """
24143
+ label = "update-claude-refresh-retry:"
24144
+ refresh = ["claude", "plugin", "marketplace", "update", "keel-marketplace"]
24145
+ plugin_update = ["claude", "plugin", "update", "keel@keel-marketplace"]
24146
+ with tempfile.TemporaryDirectory(prefix="keel-update-359-", ignore_cleanup_errors=True) as raw:
24147
+ tmp = Path(raw)
24148
+ fake = tmp / "fake.js"
24149
+ write_text(fake, UPDATE_FAKE)
24150
+ launchers = {}
24151
+ for host in ("npm", "claude", "codex"):
24152
+ launcher = tmp / f"fake-{host}"
24153
+ write_text(launcher, f'#!/bin/sh\nFAKE_HOST={host} exec node "{fake}" "$@"\n')
24154
+ launcher.chmod(0o755)
24155
+ launchers[host] = launcher
24156
+
24157
+ def update(fail_on: str, times: str):
24158
+ log, state = tmp / "log.jsonl", tmp / "state.json"
24159
+ for stale in (log, state):
24160
+ if stale.exists():
24161
+ stale.unlink()
24162
+ log.write_text("")
24163
+ env = dict(os.environ)
24164
+ env.update({
24165
+ "KEEL_UPDATE_NPM": str(launchers["npm"]), "KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
24166
+ "KEEL_UPDATE_CODEX": str(launchers["codex"]), "CODEX_HOME": str(tmp / "codex-home"),
24167
+ "FAKE_LOG": str(log), "FAKE_STATE": str(state), "FAKE_CODEX_SOURCE": str(tmp / "codex-source"),
24168
+ "FAKE_FAIL_CLAUDE": fail_on, "FAKE_FAIL_TIMES_CLAUDE": times,
24169
+ })
24170
+ env.pop("KEEL_UPDATE_SOURCE", None)
24171
+ result = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--update"], cwd=tmp, env=env,
24172
+ text=True, capture_output=True, check=False, timeout=60)
24173
+ calls = [json.loads(line) for line in log.read_text().splitlines() if line.strip()]
24174
+ line = [l for l in result.stdout.splitlines() if l.startswith("keel update: claude plugin:")]
24175
+ return result, calls, (line[0] if len(line) == 1 else "")
24176
+
24177
+ result, calls, line = update("marketplace update", "1")
24178
+ runs = sum(1 for c in calls if c[:5] == refresh)
24179
+ if runs != 2:
24180
+ report(f"{label} the Claude marketplace update ran {runs} time(s) after one failure, not 2: {calls!r}")
24181
+ return 1
24182
+ if sum(1 for c in calls if c[:4] == plugin_update) != 1:
24183
+ report(f"{label} a refresh that succeeded on retry did not run plugin update once: {calls!r}")
24184
+ return 1
24185
+ if "5.0.0 -> 5.1.0" not in line:
24186
+ report(f"{label} a refresh that succeeded on retry did not report the new version: {line!r}")
24187
+ return 1
24188
+ if result.returncode != 0:
24189
+ report(f"{label} a refresh that succeeded on retry exited {result.returncode}: {result.stdout!r}")
24190
+ return 1
24191
+
24192
+ result, calls, line = update("marketplace update", "9")
24193
+ runs = sum(1 for c in calls if c[:5] == refresh)
24194
+ if runs != 2:
24195
+ report(f"{label} a lasting failure ran the marketplace update {runs} time(s), not 2: {calls!r}")
24196
+ return 1
24197
+ if any(c[:4] == plugin_update for c in calls):
24198
+ report(f"{label} a lasting refresh failure still ran plugin update: {calls!r}")
24199
+ return 1
24200
+ if result.returncode == 0:
24201
+ report(f"{label} a lasting refresh failure left the exit status 0: {result.stdout!r}")
24202
+ return 1
24203
+ for needle in ("failed", "failed twice", "fake claude: refused plugin marketplace update"):
24204
+ if needle not in line:
24205
+ report(f"{label} the failed Claude line does not name {needle!r}: {line!r}")
24206
+ return 1
24207
+ if "warming up" in line:
24208
+ report(f"{label} the failed Claude line carries more than the last stderr line: {line!r}")
24209
+ return 1
24210
+
24211
+ # A step with no retry still names the host's own error, not only its status.
24212
+ result, calls, line = update("plugin update keel", "9")
24213
+ if sum(1 for c in calls if c[:4] == plugin_update) != 1:
24214
+ report(f"{label} a failing plugin update was retried or skipped: {calls!r}")
24215
+ return 1
24216
+ for needle in ("failed", "exited 1", "fake claude: refused plugin update"):
24217
+ if needle not in line:
24218
+ report(f"{label} the failed plugin-update line does not name {needle!r}: {line!r}")
24219
+ return 1
24220
+ if "update-claude-refresh-retry" not in {name for name, _ in SCENARIOS}:
24221
+ report(f"{label} scenario is not registered.")
24222
+ return 1
24223
+ report("update-claude-refresh-retry scenario passed.")
24224
+ return 0
24225
+
24226
+
24050
24227
  def validate_update_codex_refresh_retry_scenario() -> int:
24051
24228
  """Issue #329: a slow link can cut Codex's whole-repository marketplace clone.
24052
24229
 
@@ -41335,6 +41512,7 @@ SCENARIOS: tuple = (
41335
41512
  ("adopted-update-is-silent-unless-reload", validate_adopted_update_is_silent_unless_reload_scenario),
41336
41513
  ("update-covers-installed-hosts", validate_update_covers_installed_hosts_scenario),
41337
41514
  ("update-codex-refresh-retry", validate_update_codex_refresh_retry_scenario),
41515
+ ("update-claude-refresh-retry", validate_update_claude_refresh_retry_scenario),
41338
41516
  ("update-host-query-timeout", validate_update_host_query_timeout_scenario),
41339
41517
  ("refresh-covers-every-target", validate_refresh_covers_every_target_scenario),
41340
41518
  ("directory-branch-advances", validate_directory_branch_advances_scenario),
@@ -41352,6 +41530,7 @@ SCENARIOS: tuple = (
41352
41530
  ("owner-language-after-tools", validate_owner_language_after_tools_scenario),
41353
41531
  ("shift-history", validate_shift_history_scenario),
41354
41532
  ("shift-keeps-transcripts", validate_shift_keeps_transcripts_scenario),
41533
+ ("shift-keeps-found-transcripts", validate_shift_keeps_found_transcripts_scenario),
41355
41534
  ("role-drift", validate_role_drift_scenario),
41356
41535
  ("host-run-session", validate_host_run_session_scenario),
41357
41536
  ("shift-without-role", validate_shift_without_role_scenario),
@@ -268,6 +268,13 @@ function keptFile(where, role, transcript) {
268
268
  // copy. The host deletes transcripts after its cleanup period (30 days by
269
269
  // default for Claude), so the copy is what keeps a shift's conversation. The
270
270
  // current segment is left alone: it is still being written.
271
+ function writeKept(target, transcript) {
272
+ fs.mkdirSync(path.dirname(target), { recursive: true });
273
+ const temporary = `${target}.${process.pid}.tmp`;
274
+ fs.writeFileSync(temporary, zlib.gzipSync(fs.readFileSync(transcript)));
275
+ fs.renameSync(temporary, target);
276
+ }
277
+
271
278
  function keepEnded(where, role, segments) {
272
279
  for (const segment of segments) {
273
280
  if (!segment.ended || !segment.transcript) continue;
@@ -276,16 +283,45 @@ function keepEnded(where, role, segments) {
276
283
  const target = keptFile(where, role, segment.transcript);
277
284
  const kept = segment.kept_from;
278
285
  if (fs.existsSync(target) && kept && kept.size === source.size && kept.mtime === source.mtimeMs) continue;
279
- fs.mkdirSync(path.dirname(target), { recursive: true });
280
- const temporary = `${target}.${process.pid}.tmp`;
281
- fs.writeFileSync(temporary, zlib.gzipSync(fs.readFileSync(segment.transcript)));
282
- fs.renameSync(temporary, target);
286
+ writeKept(target, segment.transcript);
283
287
  segment.kept = target;
284
288
  segment.kept_from = { size: source.size, mtime: source.mtimeMs };
285
289
  } catch {
286
290
  // The host's file may already be gone; a copy is a convenience.
287
291
  }
288
292
  }
293
+ keepFound(where, role, segments);
294
+ }
295
+
296
+ // The transcripts `history` finds for the role but no record names — those
297
+ // from before segments were recorded (#304) — are kept too, and recorded,
298
+ // still marked found, so `history` lists them once the host's file is gone
299
+ // and later changes refresh their copy like any other ended segment (#361).
300
+ // Each is read once, when it is first recorded.
301
+ function keepFound(where, role, segments) {
302
+ const recorded = new Set(segments.map((segment) => segment.transcript));
303
+ let found = [];
304
+ try {
305
+ found = require("../shift").foundTranscripts(where, role, (transcript) => !recorded.has(transcript));
306
+ } catch {
307
+ return;
308
+ }
309
+ const added = [];
310
+ for (const segment of found) {
311
+ if (recorded.has(segment.transcript)) continue;
312
+ recorded.add(segment.transcript);
313
+ try {
314
+ const source = fs.statSync(segment.transcript);
315
+ const target = keptFile(where, role, segment.transcript);
316
+ // A copy at least as new as the transcript, such as one made by hand, is kept as it is.
317
+ if (!fs.existsSync(target) || fs.statSync(target).mtimeMs < source.mtimeMs) writeKept(target, segment.transcript);
318
+ added.push({ ...segment, kept: target, kept_from: { size: source.size, mtime: source.mtimeMs } });
319
+ } catch {
320
+ // As for a recorded segment, a copy is a convenience.
321
+ }
322
+ }
323
+ // The current segment stays last: `recordSegment` reads it there.
324
+ segments.splice(Math.max(segments.length - 1, 0), 0, ...added);
289
325
  }
290
326
 
291
327
  function recordSegment(where, role, transcript) {
@@ -485,6 +521,7 @@ module.exports = {
485
521
  wakeStep,
486
522
  check,
487
523
  bridgeLine,
524
+ keptFile,
488
525
  hook,
489
526
  noticeText,
490
527
  presenceFile,
package/src/core/shift.js CHANGED
@@ -707,7 +707,8 @@ function grepTranscript(file, needle, limit = 3) {
707
707
 
708
708
  // Transcripts Claude already keeps for a worktree (#304 D6, F5): its project
709
709
  // directory is the cwd with every non-alphanumeric character turned into `-`.
710
- function claudeTranscripts(worktree) {
710
+ // `wanted` is asked before a file is read, so a caller can skip the parse.
711
+ function claudeTranscripts(worktree, wanted = () => true) {
711
712
  const config = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
712
713
  const found = [];
713
714
  for (const cwd of new Set([worktree, realpath(worktree)])) {
@@ -715,6 +716,7 @@ function claudeTranscripts(worktree) {
715
716
  for (const name of safeList(dir)) {
716
717
  if (!name.endsWith(".jsonl")) continue;
717
718
  const file = path.join(dir, name);
719
+ if (!wanted(file)) continue;
718
720
  let first = null;
719
721
  let last = null;
720
722
  let opening = null;
@@ -741,6 +743,13 @@ function claudeTranscripts(worktree) {
741
743
  return found;
742
744
  }
743
745
 
746
+ // The Claude transcripts of every worktree bound to `role`, scheduled runs left out.
747
+ function foundTranscripts(where, role, wanted) {
748
+ const bound = Object.entries(store.readJsonFile(path.join(where.root, "roles.json")))
749
+ .filter(([, name]) => name === role).map(([worktree]) => worktree);
750
+ return bound.flatMap((worktree) => claudeTranscripts(worktree, wanted));
751
+ }
752
+
744
753
  function history(where, named, grep) {
745
754
  const role = named || store.currentRole(where);
746
755
  if (!role) throw new ShiftError("keel shift history needs a role: name it, or run it in a worktree bound to one.");
@@ -749,9 +758,11 @@ function history(where, named, grep) {
749
758
  const stored = fs.existsSync(file) ? store.readJsonFile(file).segments : [];
750
759
  const recorded = Array.isArray(stored) ? stored : [];
751
760
  const known = new Set(recorded.map((segment) => segment.transcript));
752
- const bound = Object.entries(store.readJsonFile(path.join(where.root, "roles.json")))
753
- .filter(([, name]) => name === role).map(([worktree]) => worktree);
754
- const earlier = bound.flatMap(claudeTranscripts).filter((segment) => !known.has(segment.transcript));
761
+ const earlier = foundTranscripts(where, role).filter((segment) => !known.has(segment.transcript));
762
+ const { keptFile } = require("./chat/notice");
763
+ // A found segment has no record to name its copy, so the kept path is looked at directly (#361).
764
+ const keptCopy = (segment) => [segment.kept, keptFile(where, role, segment.transcript)]
765
+ .find((file) => file && fs.existsSync(file)) || null;
755
766
  const seen = new Set();
756
767
  // Newest first; the sort is stable, so segments recorded in the same second keep their order.
757
768
  const segments = [...recorded.slice().reverse(), ...earlier]
@@ -760,7 +771,7 @@ function history(where, named, grep) {
760
771
  .map((segment) => ({
761
772
  ...segment,
762
773
  exists: fs.existsSync(segment.transcript),
763
- kept: segment.kept && fs.existsSync(segment.kept) ? segment.kept : null,
774
+ kept: keptCopy(segment),
764
775
  }));
765
776
  const notes = safeList(path.join(shiftDir(where), "history"))
766
777
  .filter((name) => name.startsWith(`${role}-`) && name.endsWith(".md"))
@@ -1021,4 +1032,4 @@ function waitingFor(repo) {
1021
1032
  }
1022
1033
 
1023
1034
  module.exports = {
1024
- desktopProcess, check, describe, runShift, shiftStatus: status, waitingFor };
1035
+ desktopProcess, foundTranscripts, check, describe, runShift, shiftStatus: status, waitingFor };