@phren/cli 0.3.71 → 0.3.73

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 (164) hide show
  1. package/dist/bridge/agent-hooks.js +11 -1
  2. package/dist/bridge/browser-env.d.ts +5 -0
  3. package/dist/bridge/browser-env.js +110 -0
  4. package/dist/bridge/browser-protocol.d.ts +120 -0
  5. package/dist/bridge/browser-protocol.js +70 -0
  6. package/dist/bridge/browser-recordings.d.ts +63 -0
  7. package/dist/bridge/browser-recordings.js +148 -0
  8. package/dist/bridge/browser-registry.d.ts +64 -0
  9. package/dist/bridge/browser-registry.js +262 -0
  10. package/dist/bridge/browser-routes.d.ts +4 -0
  11. package/dist/bridge/browser-routes.js +39 -0
  12. package/dist/bridge/browser-shim/phren-playwright.cjs +184 -0
  13. package/dist/bridge/browser-socket.d.ts +2 -0
  14. package/dist/bridge/browser-socket.js +10 -0
  15. package/dist/bridge/browser-stream.d.ts +3 -0
  16. package/dist/bridge/browser-stream.js +129 -0
  17. package/dist/bridge/browser-watch.d.ts +12 -0
  18. package/dist/bridge/browser-watch.js +83 -0
  19. package/dist/bridge/claude-account-setup.js +3 -1
  20. package/dist/bridge/claude-accounts.d.ts +5 -1
  21. package/dist/bridge/claude-accounts.js +36 -6
  22. package/dist/bridge/codex-servers.d.ts +2 -0
  23. package/dist/bridge/codex-servers.js +1 -1
  24. package/dist/bridge/command.js +24 -5
  25. package/dist/bridge/dispatch-clone.d.ts +33 -0
  26. package/dist/bridge/dispatch-clone.js +176 -0
  27. package/dist/bridge/dispatch-command.d.ts +14 -0
  28. package/dist/bridge/dispatch-command.js +98 -13
  29. package/dist/bridge/dispatch-idempotency.d.ts +85 -0
  30. package/dist/bridge/dispatch-idempotency.js +235 -0
  31. package/dist/bridge/dispatch-returns.d.ts +6 -0
  32. package/dist/bridge/dispatch-returns.js +131 -1
  33. package/dist/bridge/dispatch-wait.d.ts +32 -0
  34. package/dist/bridge/dispatch-wait.js +177 -0
  35. package/dist/bridge/dispatch.d.ts +78 -2
  36. package/dist/bridge/dispatch.js +841 -25
  37. package/dist/bridge/dream-schedule.d.ts +133 -0
  38. package/dist/bridge/dream-schedule.js +322 -0
  39. package/dist/bridge/fanouts.js +20 -3
  40. package/dist/bridge/files.d.ts +1 -1
  41. package/dist/bridge/git-credential.d.ts +44 -0
  42. package/dist/bridge/git-credential.js +113 -0
  43. package/dist/bridge/git-host-auth.d.ts +9 -1
  44. package/dist/bridge/git-host-auth.js +18 -5
  45. package/dist/bridge/git-host-gitboy.js +8 -1
  46. package/dist/bridge/git-hosts.d.ts +12 -1
  47. package/dist/bridge/git-publish.js +3 -2
  48. package/dist/bridge/herdr.d.ts +4 -0
  49. package/dist/bridge/herdr.js +44 -9
  50. package/dist/bridge/install.d.ts +1 -1
  51. package/dist/bridge/install.js +12 -4
  52. package/dist/bridge/launch-brief.d.ts +11 -0
  53. package/dist/bridge/launch-brief.js +22 -0
  54. package/dist/bridge/launch-worktree.d.ts +2 -0
  55. package/dist/bridge/launch-worktree.js +5 -1
  56. package/dist/bridge/pane-status.js +1 -1
  57. package/dist/bridge/protocol.d.ts +7 -0
  58. package/dist/bridge/schedule-watch.js +13 -2
  59. package/dist/bridge/server-launch.d.ts +2 -0
  60. package/dist/bridge/server-launch.js +251 -145
  61. package/dist/bridge/server-routes.d.ts +3 -0
  62. package/dist/bridge/server-routes.js +33 -17
  63. package/dist/bridge/server-stream.d.ts +4 -0
  64. package/dist/bridge/server-stream.js +24 -5
  65. package/dist/bridge/server.js +35 -4
  66. package/dist/bridge/session-move.d.ts +10 -4
  67. package/dist/bridge/session-move.js +65 -34
  68. package/dist/bridge/simulator-stream.d.ts +2 -0
  69. package/dist/bridge/simulator-stream.js +2 -0
  70. package/dist/bridge/status-line-fast.d.ts +9 -0
  71. package/dist/bridge/status-line-fast.js +56 -0
  72. package/dist/bridge/tab-activity.d.ts +2 -0
  73. package/dist/bridge/tab-activity.js +15 -2
  74. package/dist/bridge/task-routes.d.ts +20 -16
  75. package/dist/bridge/task-routes.js +1 -1
  76. package/dist/bridge/terminal-herdr.d.ts +5 -1
  77. package/dist/bridge/terminal-herdr.js +67 -2
  78. package/dist/bridge/terminal-tmux.d.ts +2 -0
  79. package/dist/bridge/terminal-tmux.js +29 -7
  80. package/dist/bridge/terminal.d.ts +5 -1
  81. package/dist/bridge/transcript-claude.js +192 -112
  82. package/dist/bridge/transcript-preview.d.ts +2 -1
  83. package/dist/bridge/transcript-preview.js +85 -3
  84. package/dist/bridge/transcripts.js +17 -11
  85. package/dist/bridge/turn-records.js +16 -4
  86. package/dist/bridge/usage.d.ts +7 -1
  87. package/dist/bridge/usage.js +47 -31
  88. package/dist/bridge/worker-close.d.ts +15 -0
  89. package/dist/bridge/worker-close.js +304 -3
  90. package/dist/bridge/worker-identity.d.ts +51 -0
  91. package/dist/bridge/worker-identity.js +289 -0
  92. package/dist/bridge/worker-reports.js +15 -3
  93. package/dist/bridge-hook.mjs +39990 -36152
  94. package/dist/capabilities/mcp.js +1 -1
  95. package/dist/cli/browser-hint.d.ts +2 -0
  96. package/dist/cli/browser-hint.js +21 -0
  97. package/dist/cli/config-dreaming.d.ts +7 -0
  98. package/dist/cli/config-dreaming.js +72 -0
  99. package/dist/cli/config.js +6 -0
  100. package/dist/cli/dream.d.ts +59 -0
  101. package/dist/cli/dream.js +315 -0
  102. package/dist/cli/hooks-context.d.ts +2 -2
  103. package/dist/cli/hooks-context.js +3 -3
  104. package/dist/cli/hooks.js +20 -11
  105. package/dist/cli/namespaces-tasks.js +14 -0
  106. package/dist/cli-registry.js +28 -3
  107. package/dist/config/dreaming.d.ts +82 -0
  108. package/dist/config/dreaming.js +195 -0
  109. package/dist/config/resolve.js +11 -0
  110. package/dist/config/schema.d.ts +4 -4
  111. package/dist/config/schema.js +157 -1
  112. package/dist/content/citation-freshness.js +6 -0
  113. package/dist/content/learning.d.ts +1 -0
  114. package/dist/content/learning.js +2 -0
  115. package/dist/data/access.d.ts +1 -1
  116. package/dist/data/access.js +3 -1
  117. package/dist/data/task-contract.d.ts +5 -4
  118. package/dist/data/tasks.d.ts +5 -0
  119. package/dist/data/tasks.js +28 -2
  120. package/dist/dream/apply.d.ts +69 -0
  121. package/dist/dream/apply.js +372 -0
  122. package/dist/dream/budget.d.ts +78 -0
  123. package/dist/dream/budget.js +180 -0
  124. package/dist/dream/collect.d.ts +86 -0
  125. package/dist/dream/collect.js +449 -0
  126. package/dist/dream/eval/dream-adapter.d.ts +16 -0
  127. package/dist/dream/eval/dream-adapter.js +21 -0
  128. package/dist/dream/eval/fixture.d.ts +53 -0
  129. package/dist/dream/eval/fixture.js +172 -0
  130. package/dist/dream/eval/index.d.ts +40 -0
  131. package/dist/dream/eval/index.js +78 -0
  132. package/dist/dream/eval/score.d.ts +34 -0
  133. package/dist/dream/eval/score.js +99 -0
  134. package/dist/dream/eval/scripted-model.d.ts +19 -0
  135. package/dist/dream/eval/scripted-model.js +70 -0
  136. package/dist/dream/pages.d.ts +68 -0
  137. package/dist/dream/pages.js +220 -0
  138. package/dist/dream/privacy.d.ts +3 -0
  139. package/dist/dream/privacy.js +18 -0
  140. package/dist/dream/prompt.d.ts +13 -0
  141. package/dist/dream/prompt.js +84 -0
  142. package/dist/dream/run.d.ts +98 -0
  143. package/dist/dream/run.js +317 -0
  144. package/dist/dream/types.d.ts +74 -0
  145. package/dist/dream/types.js +4 -0
  146. package/dist/finding/lifecycle.d.ts +2 -2
  147. package/dist/finding/lifecycle.js +5 -2
  148. package/dist/finding/versions.d.ts +4 -0
  149. package/dist/finding/versions.js +28 -0
  150. package/dist/index.js +1 -0
  151. package/dist/modules/registry.js +10 -8
  152. package/dist/project-config.d.ts +3 -0
  153. package/dist/task/merge-links.d.ts +38 -0
  154. package/dist/task/merge-links.js +45 -0
  155. package/dist/task/reconcile.d.ts +39 -0
  156. package/dist/task/reconcile.js +201 -0
  157. package/dist/task/report-links.d.ts +10 -0
  158. package/dist/task/report-links.js +47 -0
  159. package/dist/tools/config.js +46 -4
  160. package/dist/tools/dispatch.js +2 -1
  161. package/dist/tools/dream.d.ts +3 -0
  162. package/dist/tools/dream.js +123 -0
  163. package/dist/tools/tasks.js +4 -1
  164. package/package.json +1 -1
@@ -0,0 +1,289 @@
1
+ import { execFile } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import { lstat, mkdir, readFile, unlink, writeFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { promisify } from "node:util";
6
+ import { z } from "zod";
7
+ import { BridgeError, bridgeRoot } from "./protocol.js";
8
+ /**
9
+ * A keyed worker's durable identity: the PID and start time written by the
10
+ * launch wrapper before it execs the harness, plus the launch lock that says
11
+ * whether the launch handler is still placing it. Both survive a Hook restart
12
+ * and a replacement session in the same pane has a different PID or start time.
13
+ */
14
+ const exec = promisify(execFile);
15
+ const dispatchId = z.string().uuid();
16
+ export const SUBMITTED_GRACE_MS = 120_000;
17
+ export function workerFilePath(id) {
18
+ return path.join(bridgeRoot(), "clones", `${dispatchId.parse(id)}.worker`);
19
+ }
20
+ export function launchLockFile(id) {
21
+ return path.join(bridgeRoot(), "clones", `${dispatchId.parse(id)}.launching`);
22
+ }
23
+ export function submittedFilePath(id) {
24
+ return path.join(bridgeRoot(), "clones", `${dispatchId.parse(id)}.submitted`);
25
+ }
26
+ /** Mark a launch as submitted before its command is typed or spawned. */
27
+ export async function markSubmitted(id, at = new Date()) {
28
+ const file = submittedFilePath(id);
29
+ await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
30
+ await writeFile(file, at.toISOString(), { mode: 0o600 });
31
+ return at.toISOString();
32
+ }
33
+ async function submittedTime(id, fallback) {
34
+ const text = await readFile(submittedFilePath(id), "utf8").catch(() => undefined);
35
+ const value = text?.trim();
36
+ if (value) {
37
+ const ms = /^\d+$/.test(value) ? Number(value) : Date.parse(value);
38
+ if (Number.isFinite(ms))
39
+ return new Date(ms).toISOString();
40
+ }
41
+ if (fallback && Number.isFinite(Date.parse(fallback)))
42
+ return fallback;
43
+ return undefined;
44
+ }
45
+ /** Normalize `ps -o lstart=` and the wrapper's `tr -s " "` output to one form. */
46
+ function normalize(value) {
47
+ return value.trim().replace(/\s+/g, " ");
48
+ }
49
+ /** The process's start time, or undefined when no process has that PID. Throws when ps itself fails. */
50
+ export async function processStartTime(pid) {
51
+ try {
52
+ const { stdout } = await exec("ps", ["-o", "lstart=", "-p", String(pid)], { timeout: 3_000, maxBuffer: 4_096 });
53
+ return normalize(stdout) || undefined;
54
+ }
55
+ catch (error) {
56
+ if (error.code === 1)
57
+ return undefined;
58
+ throw error;
59
+ }
60
+ }
61
+ /** Whether the PID still belongs to the process that wrote `start`. */
62
+ export async function processMatches(pid, start) {
63
+ if (!Number.isSafeInteger(pid) || pid <= 0)
64
+ return "unknown";
65
+ let actual;
66
+ try {
67
+ actual = await processStartTime(pid);
68
+ }
69
+ catch {
70
+ return "unknown";
71
+ }
72
+ if (!actual)
73
+ return "gone";
74
+ if (!start)
75
+ return "unknown";
76
+ return actual === normalize(start) ? "alive" : "gone";
77
+ }
78
+ function parseWorker(text) {
79
+ const match = /^(\d+)\s+(.+)$/.exec(text.trim());
80
+ if (!match)
81
+ return undefined;
82
+ const pid = Number(match[1]);
83
+ if (!Number.isSafeInteger(pid) || pid <= 0)
84
+ return undefined;
85
+ return { pid, start: normalize(match[2]) };
86
+ }
87
+ /** The recorded worker process, if the identity file is readable and well-formed. */
88
+ export async function workerPid(id, file = workerFilePath(id)) {
89
+ const text = await readFile(file, "utf8").catch(() => undefined);
90
+ return text === undefined ? undefined : parseWorker(text);
91
+ }
92
+ function parseLock(text) {
93
+ try {
94
+ const value = z.object({ pid: z.number().int().positive(), start: z.string().optional(), nonce: z.string().min(1) }).parse(JSON.parse(text));
95
+ return value;
96
+ }
97
+ catch {
98
+ return undefined;
99
+ }
100
+ }
101
+ /** A held launch lock whose owner is alive means the launch is still placing. */
102
+ export async function launchInProgress(id) {
103
+ const file = launchLockFile(id);
104
+ const text = await readFile(file, "utf8").catch(error => {
105
+ if (error.code === "ENOENT")
106
+ return undefined;
107
+ throw error;
108
+ });
109
+ if (text === undefined)
110
+ return false;
111
+ const lock = parseLock(text);
112
+ if (!lock) {
113
+ // A crash can leave a partial lock. It is stale once the launch's own
114
+ // bounded window has passed; until then, fail closed.
115
+ const info = await lstat(file).catch(() => undefined);
116
+ return !!info && Date.now() - info.mtimeMs < 5 * 60_000;
117
+ }
118
+ return await processMatches(lock.pid, lock.start) !== "gone";
119
+ }
120
+ /** Whether a `ps -E` command line carries exactly our worker-file marker. */
121
+ function carriesMarker(command, file) {
122
+ const marker = `PHREN_WORKER_ID_FILE=${file}`;
123
+ const at = command.indexOf(marker);
124
+ if (at < 0)
125
+ return false;
126
+ const before = at === 0 ? " " : command[at - 1];
127
+ const after = command[at + marker.length] ?? " ";
128
+ return /\s/.test(before) && /\s/.test(after);
129
+ }
130
+ const PS_LINE = /^\s*(\d+)\s+([A-Z][a-z]{2}\s+[A-Z][a-z]{2}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4})\s+(.*)$/;
131
+ let processScanner;
132
+ /** Only for tests: replace the real same-user process scan. */
133
+ export function setWorkerProcessScan(scanner) {
134
+ processScanner = scanner;
135
+ }
136
+ /** A successful same-user process scan: the worker carrying our marker, if any. */
137
+ async function scanWorker(file) {
138
+ if (processScanner)
139
+ return processScanner(file);
140
+ try {
141
+ if (process.platform === "darwin") {
142
+ const { stdout } = await exec("ps", ["-axww", "-E", "-o", "pid=,lstart=,command="], { timeout: 5_000, maxBuffer: 16_777_216 });
143
+ for (const line of stdout.split("\n")) {
144
+ const match = PS_LINE.exec(line);
145
+ if (!match || !carriesMarker(match[3], file))
146
+ continue;
147
+ return { ok: true, worker: { pid: Number(match[1]), start: normalize(match[2]) } };
148
+ }
149
+ return { ok: true };
150
+ }
151
+ if (process.platform === "linux") {
152
+ const { stdout } = await exec("ps", ["-eww", "-o", "pid=,lstart=,args="], { timeout: 5_000, maxBuffer: 16_777_216 });
153
+ const marker = `PHREN_WORKER_ID_FILE=${file}`;
154
+ for (const line of stdout.split("\n")) {
155
+ const match = PS_LINE.exec(line);
156
+ if (!match)
157
+ continue;
158
+ const pid = Number(match[1]);
159
+ const environ = await readFile(`/proc/${pid}/environ`).catch(() => undefined);
160
+ if (!environ || !environ.includes(`${marker}\0`))
161
+ continue;
162
+ return { ok: true, worker: { pid, start: normalize(match[2]) } };
163
+ }
164
+ return { ok: true };
165
+ }
166
+ return { ok: false };
167
+ }
168
+ catch {
169
+ return { ok: false };
170
+ }
171
+ }
172
+ /**
173
+ * The worker's liveness. A present identity file is authoritative. Without one,
174
+ * a same-user process carrying this launch's worker-file marker is adopted;
175
+ * otherwise the submitted marker and the launch lock decide whether no worker
176
+ * can still be starting.
177
+ */
178
+ export async function workerAlive(id, file = workerFilePath(id), submittedAt) {
179
+ let lockLive = false;
180
+ try {
181
+ lockLive = await launchInProgress(id);
182
+ }
183
+ catch {
184
+ return "unknown";
185
+ }
186
+ let text;
187
+ try {
188
+ text = await readFile(file, "utf8");
189
+ }
190
+ catch (error) {
191
+ if (error.code !== "ENOENT")
192
+ return "unknown";
193
+ }
194
+ if (text !== undefined) {
195
+ const worker = parseWorker(text);
196
+ return worker ? processMatches(worker.pid, worker.start) : "unknown";
197
+ }
198
+ if (lockLive)
199
+ return "unknown";
200
+ const scan = await scanWorker(file);
201
+ if (!scan.ok)
202
+ return "unknown";
203
+ if (scan.worker) {
204
+ try {
205
+ await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
206
+ await writeFile(file, `${scan.worker.pid} ${scan.worker.start}\n`, { mode: 0o600 });
207
+ }
208
+ catch {
209
+ return "unknown";
210
+ }
211
+ return processMatches(scan.worker.pid, scan.worker.start);
212
+ }
213
+ const submitted = await submittedTime(id, submittedAt);
214
+ if (!submitted)
215
+ return "gone";
216
+ if (Date.now() - Date.parse(submitted) > SUBMITTED_GRACE_MS)
217
+ return "gone";
218
+ return "unknown";
219
+ }
220
+ /** Hold the launch lock for one keyed dispatch; a stale lock is replaced. */
221
+ export async function acquireLaunchLock(id) {
222
+ const file = launchLockFile(id);
223
+ await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
224
+ const start = await processStartTime(process.pid).catch(() => undefined);
225
+ const nonce = randomUUID();
226
+ const lock = { file, nonce, pid: process.pid, ...(start ? { start } : {}) };
227
+ const body = JSON.stringify(lock);
228
+ for (let attempt = 0; attempt < 3; attempt++) {
229
+ try {
230
+ await writeFile(file, body, { flag: "wx", mode: 0o600 });
231
+ return lock;
232
+ }
233
+ catch (error) {
234
+ if (error.code !== "EEXIST")
235
+ throw error;
236
+ if (await launchInProgress(id))
237
+ throw new BridgeError(409, "This dispatch's launch is already in progress.");
238
+ await unlink(file).catch(() => undefined);
239
+ }
240
+ }
241
+ throw new BridgeError(503, "The dispatch launch lock is busy; retry.");
242
+ }
243
+ export async function releaseLaunchLock(lock) {
244
+ const text = await readFile(lock.file, "utf8").catch(() => undefined);
245
+ if (text === undefined)
246
+ return;
247
+ try {
248
+ if (JSON.parse(text).nonce === lock.nonce)
249
+ await unlink(lock.file).catch(() => undefined);
250
+ }
251
+ catch { /* a replaced lock is not ours to remove */ }
252
+ }
253
+ /** Remove the worker identity and its temporary file after a confirmed termination. */
254
+ export async function removeWorkerFile(id) {
255
+ const file = workerFilePath(id);
256
+ await unlink(`${file}.tmp`).catch(() => undefined);
257
+ await unlink(file).catch(() => undefined);
258
+ }
259
+ /** SIGTERM the recorded process, then SIGKILL it if the same process is still alive after 10 s. */
260
+ export async function terminateWorker(pid, start) {
261
+ if (await processMatches(pid, start) !== "alive")
262
+ return;
263
+ try {
264
+ process.kill(pid, "SIGTERM");
265
+ }
266
+ catch {
267
+ return;
268
+ }
269
+ const deadline = Date.now() + 10_000;
270
+ while (Date.now() < deadline) {
271
+ if (await processMatches(pid, start) !== "alive")
272
+ return;
273
+ await new Promise(resolve => setTimeout(resolve, 200));
274
+ }
275
+ if (await processMatches(pid, start) !== "alive")
276
+ return;
277
+ try {
278
+ process.kill(pid, "SIGKILL");
279
+ }
280
+ catch {
281
+ return;
282
+ }
283
+ const killDeadline = Date.now() + 5_000;
284
+ while (Date.now() < killDeadline) {
285
+ if (await processMatches(pid, start) !== "alive")
286
+ return;
287
+ await new Promise(resolve => setTimeout(resolve, 200));
288
+ }
289
+ }
@@ -1,3 +1,6 @@
1
+ import { mergeTaskIdentitySchema } from "../task/merge-links.js";
2
+ import { recordTaskPrs } from "../task/report-links.js";
3
+ import { phrenStoreRoot } from "./transcripts.js";
1
4
  import { createHash } from "node:crypto";
2
5
  import { lstat, readFile } from "node:fs/promises";
3
6
  import path from "node:path";
@@ -6,7 +9,7 @@ import { atomicInPrivateDir, BridgeError, bridgeRoot, targetSchema } from "./pro
6
9
  import { paneIdentity, findPane, snapshot, validateTarget } from "./herdr.js";
7
10
  import { originPaneSchema } from "./dispatch.js";
8
11
  import { paneTurn } from "./dispatch-returns.js";
9
- import { briefArrival, briefId } from "./launch-brief.js";
12
+ import { briefArrival, briefId, briefTask } from "./launch-brief.js";
10
13
  import { integratorSchema, prsSchema, reportText as text } from "./return-contract.js";
11
14
  export { integratorSchema, prsSchema, pullRequestSchema } from "./return-contract.js";
12
15
  // `promptSeq` is absent for a report bound by its dispatch instead of a recorded prompt (`reportWorker`).
@@ -23,7 +26,7 @@ const reportFile = (target) => path.join(bridgeRoot(), "worker-reports", `${key(
23
26
  * still reports; the evidence binds to its current turn, the one the next
24
27
  * Stop ends, and never to a prompt submitted after the report. */
25
28
  export async function reportWorker(input) {
26
- const data = z.object({ origin: originPaneSchema, prs: prsSchema, dispatch: briefId.optional() }).strict().parse(input);
29
+ const data = z.object({ origin: originPaneSchema, prs: prsSchema, task: mergeTaskIdentitySchema.optional(), dispatch: briefId.optional() }).strict().parse(input);
27
30
  const pane = findPane(await snapshot(data.origin.server), data.origin);
28
31
  if (!pane)
29
32
  throw new BridgeError(409, "The worker pane changed.");
@@ -35,7 +38,16 @@ export async function reportWorker(input) {
35
38
  if (promptSeq === undefined && !(typeof pane.terminal_id === "string" && await arrivedHere(data.dispatch ?? (record && record.session === session ? record.dispatch : undefined), target)))
36
39
  throw new BridgeError(409, "The Hook has not recorded this worker's submitted turn yet, and no dispatch it launched arrived in this pane.");
37
40
  await atomicInPrivateDir(reportFile(target), reportSchema.parse({ target, terminal: pane.terminal_id, ...(promptSeq !== undefined ? { promptSeq } : {}), prs: data.prs, at: new Date().toISOString() }));
38
- return { ok: true, target, prs: data.prs };
41
+ const dispatch = data.dispatch ?? record?.dispatch;
42
+ const task = data.task ?? (dispatch ? await briefTask(dispatch) : undefined);
43
+ let taskLinks;
44
+ try {
45
+ taskLinks = recordTaskPrs(phrenStoreRoot(), data.prs, task, dispatch);
46
+ }
47
+ catch {
48
+ taskLinks = { linked: false, error: "PR report saved, but the private task link could not be saved. Retry the report." };
49
+ }
50
+ return { ok: true, target, prs: data.prs, taskLinks };
39
51
  }
40
52
  /** Whether this Hook launched dispatch `id` and its brief arrived in exactly this pane and conversation. */
41
53
  async function arrivedHere(id, target) {