@phren/cli 0.3.31 → 0.3.33

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.
Files changed (68) hide show
  1. package/dist/bridge/agent-hooks.js +23 -7
  2. package/dist/bridge/approval-rules.d.ts +70 -0
  3. package/dist/bridge/approval-rules.js +231 -0
  4. package/dist/bridge/authority.d.ts +1 -2
  5. package/dist/bridge/authority.js +2 -7
  6. package/dist/bridge/changes.d.ts +4 -0
  7. package/dist/bridge/changes.js +47 -33
  8. package/dist/bridge/claude-suggestion.js +1 -1
  9. package/dist/bridge/computer-names.d.ts +4 -0
  10. package/dist/bridge/computer-names.js +19 -0
  11. package/dist/bridge/dispatch.js +1 -1
  12. package/dist/bridge/enroll.d.ts +6 -0
  13. package/dist/bridge/enroll.js +10 -4
  14. package/dist/bridge/git-worktrees.js +14 -17
  15. package/dist/bridge/git.d.ts +10 -2
  16. package/dist/bridge/git.js +148 -107
  17. package/dist/bridge/health.js +9 -5
  18. package/dist/bridge/herdr.js +6 -1
  19. package/dist/bridge/locate.js +14 -1
  20. package/dist/bridge/model-switch.d.ts +4 -0
  21. package/dist/bridge/model-switch.js +16 -4
  22. package/dist/bridge/projects.d.ts +8 -0
  23. package/dist/bridge/projects.js +142 -24
  24. package/dist/bridge/schedule-format.d.ts +12 -0
  25. package/dist/bridge/schedule-format.js +33 -2
  26. package/dist/bridge/schedules.d.ts +8 -1
  27. package/dist/bridge/schedules.js +109 -45
  28. package/dist/bridge/server-launch.js +39 -15
  29. package/dist/bridge/server-pane-routes.js +19 -11
  30. package/dist/bridge/server-routes.d.ts +2 -0
  31. package/dist/bridge/server-routes.js +36 -8
  32. package/dist/bridge/server.js +1 -0
  33. package/dist/bridge/settings-switch.js +2 -6
  34. package/dist/bridge/speech-key.d.ts +2 -9
  35. package/dist/bridge/speech-key.js +4 -37
  36. package/dist/bridge/terminal-tmux.js +22 -4
  37. package/dist/bridge/tmux-test-server.d.ts +13 -0
  38. package/dist/bridge/tmux-test-server.js +103 -0
  39. package/dist/bridge/transcript-claude.d.ts +3 -3
  40. package/dist/bridge/transcript-claude.js +7 -7
  41. package/dist/bridge/transcript-codex.js +6 -4
  42. package/dist/bridge/transcript-preview.js +1 -1
  43. package/dist/bridge/transcripts.js +14 -3
  44. package/dist/bridge-hook.mjs +2794 -2223
  45. package/dist/cli/schedules.js +8 -2
  46. package/dist/cli/session-stop.js +9 -1
  47. package/dist/cli-registry.js +1 -1
  48. package/dist/core/project-registry.d.ts +1 -0
  49. package/dist/core/project-registry.js +6 -2
  50. package/dist/core/project.d.ts +1 -0
  51. package/dist/core/project.js +5 -0
  52. package/dist/modules/registry.js +9 -7
  53. package/dist/phren-core.js +1 -1
  54. package/dist/phren-paths.d.ts +2 -2
  55. package/dist/phren-paths.js +2 -2
  56. package/dist/store-routing.d.ts +2 -2
  57. package/dist/store-routing.js +2 -2
  58. package/dist/sync/git-state.d.ts +13 -0
  59. package/dist/sync/git-state.js +22 -0
  60. package/dist/sync/store-merge.d.ts +2 -0
  61. package/dist/sync/store-merge.js +6 -1
  62. package/dist/test-global-setup.js +7 -0
  63. package/dist/tools/data.js +1 -1
  64. package/dist/tools/finding.js +1 -1
  65. package/dist/tools/search.js +1 -1
  66. package/dist/tools/tasks.js +1 -1
  67. package/package.json +1 -1
  68. package/starter/global/skills/conductor/SKILL.md +2 -2
@@ -1,12 +1,11 @@
1
1
  import { open, stat } from "node:fs/promises";
2
2
  import { z } from "zod";
3
3
  import { stripTerminal } from "../terminal-text.js";
4
- import { visibleTerminalChoice } from "./agent-hooks.js";
5
4
  import { claudeSuggestion } from "./claude-suggestion.js";
6
5
  import { codexServers } from "./codex-servers.js";
7
6
  import { validateTarget } from "./herdr.js";
8
7
  import { intervalFromEnv } from "./limits.js";
9
- import { emptyComposer } from "./model-switch.js";
8
+ import { assertComposerReady } from "./model-switch.js";
10
9
  import { claudeFooterMode, permissionModes } from "./permission-mode.js";
11
10
  import { BridgeError, object, PERMISSION_MODES } from "./protocol.js";
12
11
  import { terminalProvider } from "./terminal.js";
@@ -216,10 +215,7 @@ export class SettingsSwitcher {
216
215
  const slash = async (command) => {
217
216
  // Typing into a draft would corrupt both it and the command.
218
217
  const before = await this.hooks.paneLines(target, false);
219
- const composer = before.split(/\r?\n/).reverse().find(line => /^\s*[›❯>]/.test(stripTerminal(line)));
220
- if (!composer || !emptyComposer(composer) || visibleTerminalChoice(stripTerminal(before))) {
221
- throw new BridgeError(409, "The terminal has a draft or an unreadable prompt. Open terminal before changing settings.");
222
- }
218
+ assertComposerReady(before, "change settings");
223
219
  await validate();
224
220
  await terminalProvider().prompt(target.server, target.pane, command);
225
221
  };
@@ -6,18 +6,12 @@
6
6
  export declare const SPEECH_KEY_ENV = "ELEVENLABS_API_KEY";
7
7
  export type SpeechKeySource = "environment" | "file";
8
8
  export declare function speechKeyFile(): string;
9
- /** Where the key lived before phren kept its own: the mina trailer config. It
10
- * is read once to migrate and never written or deleted. */
11
- export declare function legacySpeechKeyFile(env?: NodeJS.ProcessEnv): string;
12
9
  export declare function writeSpeechKey(key: string, file?: string): Promise<void>;
13
10
  export interface SpeechKeyPaths {
14
11
  env?: NodeJS.ProcessEnv;
15
12
  file?: string;
16
- legacy?: string;
17
13
  }
18
- /** ELEVENLABS_API_KEY, else the stored key. When nothing is stored yet and the
19
- * mina trailer config has a key, it is copied here once and read from here
20
- * after. */
14
+ /** ELEVENLABS_API_KEY, else the stored key. */
21
15
  export declare function resolveSpeechKey(paths?: SpeechKeyPaths): Promise<{
22
16
  key: string;
23
17
  source: SpeechKeySource;
@@ -28,6 +22,5 @@ export interface SpeechKeyStatus {
28
22
  detail: string;
29
23
  problem?: boolean;
30
24
  }
31
- /** Whether this computer has a key, for doctor. Never the key itself, and it
32
- * doesn't migrate: a read-only check. */
25
+ /** Whether this computer has a key, for doctor. Never the key itself. */
33
26
  export declare function speechKeyStatus(paths?: SpeechKeyPaths): Promise<SpeechKeyStatus>;
@@ -1,6 +1,5 @@
1
1
  import { mkdir, readFile, stat } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { homeDir } from "../home-paths.js";
4
3
  import { atomic, bridgeRoot } from "./protocol.js";
5
4
  /** The ElevenLabs key for spoken replies and Scribe dictation. It is machine
6
5
  * config, like apns.json: it lives in the Hook's own directory, mode 600, and
@@ -11,11 +10,6 @@ export const SPEECH_KEY_ENV = "ELEVENLABS_API_KEY";
11
10
  export function speechKeyFile() {
12
11
  return path.join(bridgeRoot(), "elevenlabs.json");
13
12
  }
14
- /** Where the key lived before phren kept its own: the mina trailer config. It
15
- * is read once to migrate and never written or deleted. */
16
- export function legacySpeechKeyFile(env = process.env) {
17
- return path.join(homeDir(env), ".config", "mina-trailer.json");
18
- }
19
13
  function clean(value) {
20
14
  return typeof value === "string" && value.trim() ? value.trim() : undefined;
21
15
  }
@@ -40,14 +34,6 @@ async function readStored(file) {
40
34
  return { state: "invalid" };
41
35
  }
42
36
  }
43
- async function readLegacy(file) {
44
- try {
45
- return clean(JSON.parse(await readFile(file, "utf8")).elevenlabs_api_key);
46
- }
47
- catch {
48
- return undefined;
49
- }
50
- }
51
37
  export async function writeSpeechKey(key, file = speechKeyFile()) {
52
38
  const value = clean(key);
53
39
  if (!value)
@@ -55,34 +41,19 @@ export async function writeSpeechKey(key, file = speechKeyFile()) {
55
41
  await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
56
42
  await atomic(file, JSON.stringify({ apiKey: value }) + "\n", 0o600);
57
43
  }
58
- /** ELEVENLABS_API_KEY, else the stored key. When nothing is stored yet and the
59
- * mina trailer config has a key, it is copied here once and read from here
60
- * after. */
44
+ /** ELEVENLABS_API_KEY, else the stored key. */
61
45
  export async function resolveSpeechKey(paths = {}) {
62
46
  const env = paths.env ?? process.env;
63
47
  const fromEnv = clean(env[SPEECH_KEY_ENV]);
64
48
  if (fromEnv)
65
49
  return { key: fromEnv, source: "environment" };
66
- const file = paths.file ?? speechKeyFile();
67
- const stored = await readStored(file);
68
- if (stored.state === "ok")
69
- return { key: stored.key, source: "file" };
70
- if (stored.state !== "missing")
71
- return undefined;
72
- const legacy = await readLegacy(paths.legacy ?? legacySpeechKeyFile(env));
73
- if (!legacy)
74
- return undefined;
75
- try {
76
- await writeSpeechKey(legacy, file);
77
- }
78
- catch { /* use it this once; the next call tries again */ }
79
- return { key: legacy, source: "file" };
50
+ const stored = await readStored(paths.file ?? speechKeyFile());
51
+ return stored.state === "ok" ? { key: stored.key, source: "file" } : undefined;
80
52
  }
81
53
  export async function readSpeechKey() {
82
54
  return (await resolveSpeechKey())?.key;
83
55
  }
84
- /** Whether this computer has a key, for doctor. Never the key itself, and it
85
- * doesn't migrate: a read-only check. */
56
+ /** Whether this computer has a key, for doctor. Never the key itself. */
86
57
  export async function speechKeyStatus(paths = {}) {
87
58
  const env = paths.env ?? process.env;
88
59
  const file = paths.file ?? speechKeyFile();
@@ -98,9 +69,5 @@ export async function speechKeyStatus(paths = {}) {
98
69
  case "unsafe": return { configured: false, problem: true, detail: `${file} is readable by other users; run chmod 600 on it` };
99
70
  case "invalid": return { configured: false, problem: true, detail: `${file} has no apiKey; ${setup}` };
100
71
  }
101
- const legacy = paths.legacy ?? legacySpeechKeyFile(env);
102
- if (await readLegacy(legacy)) {
103
- return { configured: true, detail: `not stored yet; the Hook copies it from ${legacy} on first use` };
104
- }
105
72
  return { configured: false, detail: `no ElevenLabs key, so spoken replies and Scribe dictation are off; ${setup}` };
106
73
  }
@@ -14,7 +14,7 @@
14
14
  import { execFile } from "node:child_process";
15
15
  import { accessSync, constants, existsSync, statSync } from "node:fs";
16
16
  import { lstat, readdir } from "node:fs/promises";
17
- import { hostname, userInfo } from "node:os";
17
+ import { hostname, tmpdir, userInfo } from "node:os";
18
18
  import path from "node:path";
19
19
  import { BridgeError, objects, serverName } from "./protocol.js";
20
20
  import { harnessStatus } from "./harness-status.js";
@@ -511,14 +511,32 @@ export const tmuxTerminal = {
511
511
  * socket and every other socket in the user's tmux folders (`tmux -L work`
512
512
  * is "tmux-work"), the 16 most recently active. Sockets are ordered by
513
513
  * activity, so stale socket files from killed runs can't crowd out a live
514
- * server. The hidden server is not among them. */
514
+ * server. The hidden server is not among them, nor a test's private server
515
+ * (by its socket name, or its sessions all in a test's temp folder). */
515
516
  async function ownerServers() {
516
- const sockets = [...new Set(["default", ...await deps.sockets().catch(() => [])])].filter(socket => socket !== "phren");
517
+ const sockets = [...new Set(["default", ...await deps.sockets().catch(() => [])])]
518
+ .filter(socket => socket !== "phren" && !isTestName(socket));
517
519
  // Sockets arrive most recently active first, so the cap keeps live servers.
518
520
  const names = sockets.flatMap(socket => tmuxServerName(socket) ?? []).slice(0, 16);
519
- const running = await Promise.all(names.map(name => tmuxTerminal.ping(name).then(() => true, () => false)));
521
+ const running = await Promise.all(names.map(name => tmux(name, ["list-sessions", "-F", "#{session_path}"], { timeoutMs: 3_000 })
522
+ .then(text => !isTestServer(text.split("\n").filter(Boolean)), () => false)));
520
523
  return names.filter((_, index) => running[index]);
521
524
  }
525
+ /** A name a test gives its private server or temp folder: a "test", "tests"
526
+ * or "it" word (phren-test-123, phren-scroll-test-123, phren-tmux-it-Qc4LM8). */
527
+ function isTestName(name) {
528
+ return /(^|[-_.])(tests?|it)([-_.]|$)/i.test(name) || /^phren.*test/i.test(name);
529
+ }
530
+ /** A server every session of which starts in a test's temp folder (a temp
531
+ * folder named like a test, or phren's own `phren-*` scratch folders): what a
532
+ * killed test run leaves behind on a socket with an ordinary name. */
533
+ function isTestServer(sessionPaths) {
534
+ const roots = [...new Set([tmpdir(), "/tmp", "/var/tmp"].map(root => path.resolve(root)))];
535
+ return sessionPaths.length > 0 && sessionPaths.every(folder => roots.some(root => {
536
+ const rest = path.relative(root, path.resolve(folder));
537
+ return rest !== "" && !rest.startsWith("..") && !path.isAbsolute(rest) && rest.split(path.sep).some(part => isTestName(part) || part.startsWith("phren-"));
538
+ }));
539
+ }
522
540
  /** The tmux servers the Hook drives, as `/v1/muxes` lists servers: the owner's
523
541
  * servers that answer, and (unless `hidden: false`) the hidden server whenever
524
542
  * tmux is installed (a launch starts it). An already running hidden server
@@ -0,0 +1,13 @@
1
+ /** The test socket for this process: `phren-<kind>-test-<pid>`. */
2
+ export declare function testSocketName(kind?: string): string;
3
+ /** A detached shell that kills the server on `socket` and removes its socket
4
+ * files once `pid` is gone. Answers its own pid. */
5
+ export declare function startWatchdog(pid: number, binary: string, socket: string): number | undefined;
6
+ /** Registers the teardown of the server on `socket` before the test starts it.
7
+ * `stop` is idempotent and synchronous, so the exit hook can call it too. */
8
+ export declare function privateTmuxServer(binary: string, socket: string): {
9
+ stop: () => void;
10
+ };
11
+ /** Kills the servers and removes the sockets earlier test runs left behind:
12
+ * test sockets whose owning process is gone. */
13
+ export declare function sweepTestServers(binary?: string): string[];
@@ -0,0 +1,103 @@
1
+ // A real tmux server on a private socket for an integration test, torn down
2
+ // however the run ends: afterAll, the worker's exit or a signal, or (when the
3
+ // worker is killed outright, as a timed-out or interrupted run can be) a
4
+ // watchdog that outlives it. A leaked server shows on the phone as sessions
5
+ // nobody can close, and its socket piles up in the tmux folder.
6
+ import { execFileSync, spawn } from "node:child_process";
7
+ import { readdirSync, unlinkSync } from "node:fs";
8
+ import path from "node:path";
9
+ import { tmuxSocketFolders } from "./terminal-tmux.js";
10
+ /** A test socket's name ends with the pid of the process that owns it. */
11
+ const TEST_SOCKET = /^phren-(?:[a-z]+-)*test(?:-[a-z]+)*-(\d+)$/;
12
+ /** The test socket for this process: `phren-<kind>-test-<pid>`. */
13
+ export function testSocketName(kind) {
14
+ return `phren-${kind ? `${kind}-` : ""}test-${process.pid}`;
15
+ }
16
+ function removeServer(binary, socket) {
17
+ try {
18
+ execFileSync(binary, ["-L", socket, "kill-server"], { stdio: "ignore", timeout: 5_000 });
19
+ }
20
+ catch { /* already gone */ }
21
+ // tmux can leave the socket file behind when the server is killed.
22
+ for (const dir of tmuxSocketFolders()) {
23
+ try {
24
+ unlinkSync(path.join(dir, socket));
25
+ }
26
+ catch { /* none */ }
27
+ }
28
+ }
29
+ const WATCHDOG = `pid=$1; tmux=$2; sock=$3; shift 3
30
+ while kill -0 "$pid" 2>/dev/null; do sleep 1; done
31
+ "$tmux" -L "$sock" kill-server 2>/dev/null
32
+ rm -f "$@"`;
33
+ /** A detached shell that kills the server on `socket` and removes its socket
34
+ * files once `pid` is gone. Answers its own pid. */
35
+ export function startWatchdog(pid, binary, socket) {
36
+ const files = tmuxSocketFolders().map(dir => path.join(dir, socket));
37
+ const child = spawn("/bin/sh", ["-c", WATCHDOG, "phren-tmux-watchdog", String(pid), binary, socket, ...files], { detached: true, stdio: "ignore" });
38
+ child.unref();
39
+ return child.pid;
40
+ }
41
+ /** Registers the teardown of the server on `socket` before the test starts it.
42
+ * `stop` is idempotent and synchronous, so the exit hook can call it too. */
43
+ export function privateTmuxServer(binary, socket) {
44
+ let stopped = false;
45
+ const watchdog = startWatchdog(process.pid, binary, socket);
46
+ const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
47
+ const onSignal = (signal) => {
48
+ stop();
49
+ // Nobody else handles it: die of it as the worker would have.
50
+ if (process.listenerCount(signal) === 0)
51
+ process.kill(process.pid, signal);
52
+ };
53
+ function stop() {
54
+ if (stopped)
55
+ return;
56
+ stopped = true;
57
+ process.removeListener("exit", stop);
58
+ for (const signal of signals)
59
+ process.removeListener(signal, onSignal);
60
+ removeServer(binary, socket);
61
+ if (watchdog) {
62
+ try {
63
+ process.kill(watchdog);
64
+ }
65
+ catch { /* already gone */ }
66
+ }
67
+ }
68
+ process.once("exit", stop);
69
+ for (const signal of signals)
70
+ process.once(signal, onSignal);
71
+ return { stop };
72
+ }
73
+ /** Kills the servers and removes the sockets earlier test runs left behind:
74
+ * test sockets whose owning process is gone. */
75
+ export function sweepTestServers(binary = "tmux") {
76
+ const swept = [];
77
+ for (const dir of tmuxSocketFolders()) {
78
+ let names;
79
+ try {
80
+ names = readdirSync(dir);
81
+ }
82
+ catch {
83
+ continue;
84
+ }
85
+ for (const name of names) {
86
+ const pid = Number(TEST_SOCKET.exec(name)?.[1]);
87
+ if (!pid || pid === process.pid || alive(pid))
88
+ continue;
89
+ removeServer(binary, name);
90
+ swept.push(name);
91
+ }
92
+ }
93
+ return swept;
94
+ }
95
+ function alive(pid) {
96
+ try {
97
+ process.kill(pid, 0);
98
+ return true;
99
+ }
100
+ catch (error) {
101
+ return error.code === "EPERM";
102
+ }
103
+ }
@@ -2,9 +2,9 @@ import { type Json } from "./protocol.js";
2
2
  import type { ChildAgentRelation } from "./transcripts.js";
3
3
  /** The checkout a Claude sub-agent edits in. Claude Code writes the isolated
4
4
  * worktree into the child's `.meta.json`; an older child falls back to the
5
- * `cwd` its own first rows record when that folder is a linked worktree (its
6
- * `.git` is a file). A child working in the parent's checkout gets nothing,
7
- * and a worktree already removed is not offered. */
5
+ * `cwd` its own first rows record. Preserve shared and missing checkout paths
6
+ * too: Git routes must fail explicitly when a checkout disappears, never
7
+ * substitute the parent repository. */
8
8
  export declare function claudeChildCheckout(file: string): Promise<Pick<ChildAgentRelation, "cwd" | "worktreeName" | "branch">>;
9
9
  export declare function claudeChildAgents(file: string, session: string): Promise<ChildAgentRelation[]>;
10
10
  /** How long a background skill's transcript may sit unchanged before it is
@@ -47,9 +47,9 @@ async function claudeChildModel(file) {
47
47
  }
48
48
  /** The checkout a Claude sub-agent edits in. Claude Code writes the isolated
49
49
  * worktree into the child's `.meta.json`; an older child falls back to the
50
- * `cwd` its own first rows record when that folder is a linked worktree (its
51
- * `.git` is a file). A child working in the parent's checkout gets nothing,
52
- * and a worktree already removed is not offered. */
50
+ * `cwd` its own first rows record. Preserve shared and missing checkout paths
51
+ * too: Git routes must fail explicitly when a checkout disappears, never
52
+ * substitute the parent repository. */
53
53
  export async function claudeChildCheckout(file) {
54
54
  const meta = await readFile(file.slice(0, -".jsonl".length) + ".meta.json", "utf8").then(v => object(JSON.parse(v))).catch(() => ({}));
55
55
  let cwd = typeof meta.worktreePath === "string" && path.isAbsolute(meta.worktreePath) ? meta.worktreePath : undefined;
@@ -61,8 +61,7 @@ export async function claudeChildCheckout(file) {
61
61
  try {
62
62
  const value = object(JSON.parse(line)).cwd;
63
63
  if (typeof value === "string" && path.isAbsolute(value)) {
64
- if ((await stat(path.join(value, ".git")).catch(() => undefined))?.isFile())
65
- cwd = value;
64
+ cwd = value;
66
65
  break;
67
66
  }
68
67
  }
@@ -73,9 +72,10 @@ export async function claudeChildCheckout(file) {
73
72
  input.close();
74
73
  branch = undefined;
75
74
  }
76
- if (!cwd || !(await stat(cwd).catch(() => undefined))?.isDirectory())
75
+ if (!cwd)
77
76
  return {};
78
- return { cwd, worktreeName: path.basename(cwd).slice(0, 200), ...(branch ? { branch } : {}) };
77
+ const linked = typeof meta.worktreePath === "string" || (await stat(path.join(cwd, ".git")).catch(() => undefined))?.isFile();
78
+ return { cwd, ...(linked ? { worktreeName: path.basename(cwd).slice(0, 200) } : {}), ...(branch ? { branch } : {}) };
79
79
  }
80
80
  async function withClaudeChildModels(relations) {
81
81
  return Promise.all(relations.map(async (relation) => {
@@ -453,10 +453,12 @@ function rememberProjectedCodeCall(callId) {
453
453
  projectedCodeCalls.delete(projectedCodeCalls.values().next().value);
454
454
  }
455
455
  function renameProjectedChanges(raw, base) {
456
- const changes = object(raw.phren_changes);
457
- if (!Object.keys(changes).length)
458
- return raw;
459
- return { ...raw, phren_changes: Object.fromEntries(Object.entries(changes).map(([key, value]) => [key === base ? `${base}:1` : key, value])) };
456
+ for (const field of ["phren_changes", "phren_change_errors"]) {
457
+ const changes = object(raw[field]);
458
+ if (Object.keys(changes).length)
459
+ raw = { ...raw, [field]: Object.fromEntries(Object.entries(changes).map(([key, value]) => [key === base ? `${base}:1` : key, value])) };
460
+ }
461
+ return raw;
460
462
  }
461
463
  /** Expand one Codex row: a code-mode call becomes one ordinary call per
462
464
  * invocation, each carrying the original source under `input.source`, and the
@@ -20,7 +20,7 @@ export function claudePanePreview(rendered, prompt, previous = "") {
20
20
  // below reads the plain line.
21
21
  const marked = screen.map(line => claudeBoldMarkdown(line).replace(/[\u2500-\u257f]/g, "").trimEnd());
22
22
  // The rule above the input box can carry the session title
23
- // ("───── Claude sesh ─"); it ends the reply, it is never part of it.
23
+ // ("───── Docs refresh ─"); it ends the reply, it is never part of it.
24
24
  // A narrow pane leaves the titled rule a single dash ("…title… ─"), so a
25
25
  // line that ends in a rule dash right above the input prompt ends it too.
26
26
  const lines = raw.map((line, index) => (/[─━═]{3,}/.test(line) && !/^\s*[│┃║]/.test(line))
@@ -343,11 +343,22 @@ export class TranscriptReader {
343
343
  continue;
344
344
  }
345
345
  const attached = {};
346
+ const failures = {};
346
347
  for (const id of ids) {
347
- const files = await this.changes.changes(id);
348
- if (files)
349
- attached[id] = files;
348
+ try {
349
+ const files = await this.changes.changes(id);
350
+ if (files)
351
+ attached[id] = files;
352
+ }
353
+ catch (error) {
354
+ // Keep the tool output visible; the outer malformed-row guard
355
+ // must never hide it just because Git could not collect changes.
356
+ failures[id] = { error: error instanceof BridgeError ? error.message : "Git change capture failed.",
357
+ code: error instanceof BridgeError ? error.details?.code ?? "git-capture-failed" : "git-capture-failed" };
358
+ }
350
359
  }
360
+ if (Object.keys(failures).length)
361
+ raw = { ...raw, phren_change_errors: failures };
351
362
  // A row that already carries a worker's own diff (OpenCode edit,
352
363
  // write or patch) keeps it; the shell lookup only fills in the rest.
353
364
  if (Object.keys(attached).length)