@phren/cli 0.3.67 → 0.3.69

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 (83) hide show
  1. package/dist/bridge/agent-hook-callback.js +11 -2
  2. package/dist/bridge/agent-hooks.d.ts +11 -1
  3. package/dist/bridge/agent-hooks.js +259 -40
  4. package/dist/bridge/changes.d.ts +2 -2
  5. package/dist/bridge/changes.js +11 -9
  6. package/dist/bridge/checkpoints.d.ts +24 -0
  7. package/dist/bridge/checkpoints.js +423 -0
  8. package/dist/bridge/claude-input-state.d.ts +14 -0
  9. package/dist/bridge/claude-input-state.js +58 -0
  10. package/dist/bridge/claude-queue.js +5 -2
  11. package/dist/bridge/claude-suggestion.d.ts +3 -0
  12. package/dist/bridge/claude-suggestion.js +10 -0
  13. package/dist/bridge/codex-threads.d.ts +7 -1
  14. package/dist/bridge/codex-threads.js +185 -56
  15. package/dist/bridge/conversation-search.d.ts +20 -0
  16. package/dist/bridge/conversation-search.js +928 -0
  17. package/dist/bridge/git-watch.d.ts +46 -0
  18. package/dist/bridge/git-watch.js +351 -0
  19. package/dist/bridge/git-worktree-remove.d.ts +44 -0
  20. package/dist/bridge/git-worktree-remove.js +140 -0
  21. package/dist/bridge/git-worktrees.d.ts +14 -0
  22. package/dist/bridge/git-worktrees.js +7 -3
  23. package/dist/bridge/git-write-policy.js +1 -1
  24. package/dist/bridge/gitboy-webhooks.d.ts +3 -1
  25. package/dist/bridge/gitboy-webhooks.js +26 -2
  26. package/dist/bridge/herdr.d.ts +6 -1
  27. package/dist/bridge/herdr.js +56 -10
  28. package/dist/bridge/hook-fast.js +13 -1
  29. package/dist/bridge/input-classification.d.ts +33 -0
  30. package/dist/bridge/input-classification.js +84 -0
  31. package/dist/bridge/pane-status.d.ts +3 -3
  32. package/dist/bridge/pane-status.js +16 -8
  33. package/dist/bridge/prompt-deliveries.d.ts +30 -4
  34. package/dist/bridge/prompt-deliveries.js +365 -13
  35. package/dist/bridge/prompt-identity.d.ts +8 -0
  36. package/dist/bridge/prompt-identity.js +15 -0
  37. package/dist/bridge/request-origin.js +2 -1
  38. package/dist/bridge/schedule-events.d.ts +17 -0
  39. package/dist/bridge/schedule-events.js +53 -0
  40. package/dist/bridge/schedule-format.d.ts +22 -2
  41. package/dist/bridge/schedule-format.js +40 -5
  42. package/dist/bridge/schedule-update.js +2 -1
  43. package/dist/bridge/schedule-watch.js +15 -5
  44. package/dist/bridge/schedules.d.ts +9 -0
  45. package/dist/bridge/schedules.js +120 -7
  46. package/dist/bridge/server-pane-routes.d.ts +7 -8
  47. package/dist/bridge/server-pane-routes.js +186 -82
  48. package/dist/bridge/server-routes.d.ts +26 -2
  49. package/dist/bridge/server-routes.js +180 -56
  50. package/dist/bridge/server-stream.js +66 -15
  51. package/dist/bridge/server.js +25 -7
  52. package/dist/bridge/session-activity.d.ts +49 -4
  53. package/dist/bridge/session-activity.js +47 -0
  54. package/dist/bridge/session-evidence.d.ts +18 -0
  55. package/dist/bridge/session-evidence.js +72 -0
  56. package/dist/bridge/session-seen.d.ts +23 -0
  57. package/dist/bridge/session-seen.js +69 -0
  58. package/dist/bridge/tab-activity.d.ts +26 -1
  59. package/dist/bridge/tab-activity.js +64 -9
  60. package/dist/bridge/terminal-resolve.d.ts +20 -0
  61. package/dist/bridge/terminal-resolve.js +145 -0
  62. package/dist/bridge/terminal-tmux.d.ts +8 -3
  63. package/dist/bridge/terminal-tmux.js +59 -7
  64. package/dist/bridge/transcript-claude.d.ts +12 -2
  65. package/dist/bridge/transcript-claude.js +91 -13
  66. package/dist/bridge/transcript-index.d.ts +4 -2
  67. package/dist/bridge/transcript-index.js +6 -5
  68. package/dist/bridge/transcript-preview.d.ts +16 -1
  69. package/dist/bridge/transcript-preview.js +171 -27
  70. package/dist/bridge/transcripts.d.ts +41 -1
  71. package/dist/bridge/transcripts.js +181 -23
  72. package/dist/bridge/turn-queue-pane.d.ts +6 -0
  73. package/dist/bridge/turn-queue-pane.js +30 -0
  74. package/dist/bridge/turn-queue.d.ts +86 -0
  75. package/dist/bridge/turn-queue.js +280 -0
  76. package/dist/bridge/turn-records.d.ts +18 -0
  77. package/dist/bridge/turn-records.js +77 -5
  78. package/dist/bridge-hook.mjs +7074 -3173
  79. package/dist/cli/config-shared.js +2 -1
  80. package/dist/cli/schedules.js +6 -1
  81. package/dist/content/secrets.js +1 -1
  82. package/dist/modules/registry.js +12 -11
  83. package/package.json +1 -1
@@ -10,7 +10,7 @@ import { BridgeError, object, objects, sessionId } from "./protocol.js";
10
10
  import { materializeCodexThread, materializedRoot } from "./codex-threads.js";
11
11
  import { namedPaths, SHELL_TOOLS, outputCallIds } from "./changes.js";
12
12
  import { fanoutChildren } from "./fanouts.js";
13
- import { claudeChildAgents, visibleClaudeEvent } from "./transcript-claude.js";
13
+ import { claudeChildAgents, claudePromptIdentity, visibleClaudeEvent } from "./transcript-claude.js";
14
14
  import { childTranscriptBelongsTo, codeModeOutputCall, directChildAgents, findCodeModeCall, projectCodeModeOutput, projectCodexRow, rewriteProjectedOutput, visibleCodexEvent } from "./transcript-codex.js";
15
15
  import { visibleCopilotEvent } from "./transcript-copilot.js";
16
16
  import { visibleOpencodeEvent } from "./transcript-opencode.js";
@@ -206,6 +206,18 @@ export function targetTranscriptPath(target) {
206
206
  const account = target.source === "claude" ? paneAccount(paneAccountKey(target.server, target.pane))?.id : undefined;
207
207
  return transcriptPath(target.source, target.session, account);
208
208
  }
209
+ /** Shared ambiguity rule for chat reads and the search index. A session ID
210
+ * alone cannot select between Claude account copies. Codex's caller falls
211
+ * back to its materialized store when no unique rollout can be chosen. */
212
+ export function selectTranscriptMatch(source, found, account) {
213
+ let chosen = found;
214
+ if (source === "claude" && found.length > 1 && account) {
215
+ const preferred = found.filter(item => item.id === account);
216
+ if (preferred.length)
217
+ chosen = preferred;
218
+ }
219
+ return chosen.length === 1 ? chosen[0] : undefined;
220
+ }
209
221
  /** `account` (a Claude home id) settles a session id found in more than one home. */
210
222
  export async function transcriptPath(source, session, account) {
211
223
  if (!sessionId.safeParse(session).success)
@@ -226,13 +238,8 @@ export async function transcriptPath(source, session, account) {
226
238
  for (const match of matches)
227
239
  found.push({ id: entry.id, root, match });
228
240
  }
229
- let chosen = found;
230
- if (source === "claude" && found.length > 1 && account) {
231
- const preferred = found.filter(item => item.id === account);
232
- if (preferred.length)
233
- chosen = preferred;
234
- }
235
- if (chosen.length !== 1) {
241
+ const chosen = selectTranscriptMatch(source, found, account);
242
+ if (!chosen) {
236
243
  // Codex 0.155 keeps new threads only in its sqlite store; the Hook
237
244
  // materializes those into a rollout-shaped file of its own.
238
245
  const materialized = source === "codex" ? await materializeCodexThread(session) : undefined;
@@ -240,8 +247,8 @@ export async function transcriptPath(source, session, account) {
240
247
  return materialized;
241
248
  throw new BridgeError(404, "The transcript is not available for this conversation.", { code: "transcript-unavailable" });
242
249
  }
243
- const file = await realpath(chosen[0].match);
244
- if (!file.startsWith(chosen[0].root + path.sep))
250
+ const file = await realpath(chosen.match);
251
+ if (!file.startsWith(chosen.root + path.sep))
245
252
  throw new BridgeError(403, "The transcript points outside its agent folder.");
246
253
  return file;
247
254
  }
@@ -261,6 +268,121 @@ export function visibleEvent(raw, source, includeSidechain = false, cwd, queue)
261
268
  return visibleClaudeEvent(raw, includeSidechain, queue);
262
269
  return visibleCopilotEvent(raw);
263
270
  }
271
+ /** Apply the code-mode wrapper projection used by both stream pages and
272
+ * completion lookup. Covered script status rows never become public entries. */
273
+ async function projectTranscriptEvent(raw, source, line, rows) {
274
+ const call = raw && source === "codex" ? codeModeOutputCall(raw) : undefined;
275
+ return raw && call ? projectCodeModeOutput(raw, await findCodeModeCall(rows, line, call)) : raw;
276
+ }
277
+ function projectTranscriptRows(raw, source) {
278
+ return source === "codex" ? projectCodexRow(raw) : { rows: [raw] };
279
+ }
280
+ /** Prompt ids seen on eligible user rows across the whole conversation, kept
281
+ * per file revision and extended by appends so every page and reader applies
282
+ * the same ambiguity rule. */
283
+ const promptIdentityCounts = new Map();
284
+ export async function ambiguousPromptIdentities(file, handle, index, source, includeSidechain, signal) {
285
+ if (source !== "claude")
286
+ return new Set();
287
+ const key = `${file}\0${source}\0${includeSidechain ? 1 : 0}`;
288
+ const current = promptIdentityCounts.get(key);
289
+ const reset = !current || current.revision !== index.revision || current.lines > index.lines;
290
+ const ambiguous = (counts) => {
291
+ const ids = new Set();
292
+ for (const [id, count] of counts)
293
+ if (count > 1)
294
+ ids.add(id);
295
+ return ids;
296
+ };
297
+ if (!reset && current && current.lines === index.lines)
298
+ return ambiguous(current.counts);
299
+ // Work on a private copy. Nothing is published until the whole scan succeeds,
300
+ // so an aborted or failed read leaves the previous counts and position intact.
301
+ const counts = new Map(reset || !current ? [] : current.counts), start = reset || !current ? 0 : current.lines;
302
+ if (start < index.lines) {
303
+ const queue = {};
304
+ for await (const row of index.rows(handle, index.lines, start, signal)) {
305
+ signal?.throwIfAborted();
306
+ if (!row.bytes)
307
+ continue;
308
+ try {
309
+ const original = object(JSON.parse(row.bytes.toString()));
310
+ const id = claudePromptIdentity(original, visibleClaudeEvent(original, includeSidechain, queue));
311
+ if (id)
312
+ counts.set(id, (counts.get(id) ?? 0) + 1);
313
+ }
314
+ catch { /* A malformed row cannot make another prompt ambiguous. */ }
315
+ }
316
+ }
317
+ promptIdentityCounts.delete(key);
318
+ promptIdentityCounts.set(key, { revision: index.revision, lines: index.lines, counts });
319
+ while (promptIdentityCounts.size > 64)
320
+ promptIdentityCounts.delete(promptIdentityCounts.keys().next().value);
321
+ return ambiguous(counts);
322
+ }
323
+ const completionEntries = new Map();
324
+ /** A finished turn's last public row, using the same absolute line key as
325
+ * stream frames and history pages. Reuse their incremental byte index and
326
+ * inspect at most 256 recent rows / 1 MiB, never scan the full history for a
327
+ * completion. Missing timestamps or an unresolved tail leave it manual. */
328
+ export async function completionEntry(file, source, promptAt, stopAt, finalReply) {
329
+ const since = Date.parse(promptAt), until = Date.parse(stopAt);
330
+ if (!Number.isFinite(since) || !Number.isFinite(until) || until < since || (source === "claude" && finalReply?.truncated))
331
+ return undefined;
332
+ return withTranscriptIndex(file, async (handle, index) => {
333
+ const key = `${file}\0${source}`, signature = JSON.stringify([index.revision, index.lines, promptAt, stopAt, finalReply?.reply, finalReply?.truncated]);
334
+ const cached = completionEntries.get(key);
335
+ if (cached?.signature === signature)
336
+ return cached.entry;
337
+ let entry, bytes = 0;
338
+ for await (const row of index.rows(handle, index.lines, Math.max(0, index.lines - 256))) {
339
+ if (!row.bytes || (bytes += row.bytes.length) > 1_048_576)
340
+ break;
341
+ try {
342
+ const raw = await projectTranscriptEvent(visibleEvent(object(JSON.parse(row.bytes.toString())), source), source, row.line, (before, after) => index.rows(handle, before, after));
343
+ if (!raw || raw.isSidechain === true)
344
+ continue;
345
+ const projected = projectTranscriptRows(raw, source).rows.map(value => chatFrame(value, source));
346
+ if (!projected.length || Buffer.byteLength(JSON.stringify(projected)) >= 2_097_152)
347
+ continue;
348
+ // Progress can repeat the final reply verbatim. Require terminal
349
+ // evidence even when the text matches the Stop's complete reply.
350
+ if (source === "claude") {
351
+ if (raw.type !== "assistant")
352
+ continue;
353
+ const message = object(raw.message), content = message.content;
354
+ if (message.stop_reason !== "end_turn")
355
+ continue;
356
+ const blocks = objects(content);
357
+ if (!(typeof content === "string" ? content.trim() : blocks.some(block => ["text", "image", "tool_use", "tool_result"].includes(String(block.type)))))
358
+ continue;
359
+ const text = typeof content === "string" ? content.trim()
360
+ : blocks.filter(block => block.type === "text").map(block => String(block.text ?? "")).join("\n").trim();
361
+ if (finalReply?.reply && text) {
362
+ if (text !== finalReply.reply.trim())
363
+ continue;
364
+ }
365
+ }
366
+ const stamp = raw.timestamp ?? raw.time;
367
+ const at = typeof stamp === "string" ? Date.parse(stamp) : NaN;
368
+ // An undated candidate could be the final row: falling back to an
369
+ // earlier answer would let the phone mark an unseen reply seen.
370
+ if (!Number.isFinite(at))
371
+ break;
372
+ if (at < since || at > until)
373
+ continue;
374
+ entry = String(row.line);
375
+ break;
376
+ }
377
+ catch { /* Malformed rows do not identify a completion. */ }
378
+ }
379
+ completionEntries.delete(key);
380
+ completionEntries.set(key, { signature, entry });
381
+ while (completionEntries.size > 128)
382
+ completionEntries.delete(completionEntries.keys().next().value);
383
+ return entry;
384
+ });
385
+ }
264
386
  /** Parse only the requested page; shared byte indexes make reopening and
265
387
  * backward pagination independent of the amount of already-read history. */
266
388
  export class TranscriptReader {
@@ -270,15 +392,27 @@ export class TranscriptReader {
270
392
  changes;
271
393
  includeSidechain;
272
394
  cwd;
395
+ queueBindings;
273
396
  revision;
274
397
  nextLine = 0;
275
- constructor(file, source, imageLine, changes, includeSidechain = false, cwd) {
398
+ ambiguous = new Set();
399
+ constructor(file, source, imageLine, changes, includeSidechain = false, cwd,
400
+ /** The phone delivery bound to each Claude queue row, by byte offset (PromptDeliveries). */
401
+ queueBindings) {
276
402
  this.file = file;
277
403
  this.source = source;
278
404
  this.imageLine = imageLine;
279
405
  this.changes = changes;
280
406
  this.includeSidechain = includeSidechain;
281
407
  this.cwd = cwd;
408
+ this.queueBindings = queueBindings;
409
+ }
410
+ /** Prompt ids the latest page found ambiguous across the conversation. */
411
+ get ambiguousPromptIds() { return this.ambiguous; }
412
+ /** A fresh opening page with the same reader options, for a reset after an
413
+ * identity already delivered by this stream became ambiguous. */
414
+ snapshot(signal) {
415
+ return new TranscriptReader(this.file, this.source, this.imageLine, this.changes, this.includeSidechain, this.cwd, this.queueBindings).read(undefined, signal);
282
416
  }
283
417
  async read(before, signal) {
284
418
  return this.readPage(before, undefined, signal);
@@ -311,13 +445,23 @@ export class TranscriptReader {
311
445
  const byteBudget = opening ? 1_048_576 : 4_194_304;
312
446
  let bytes = 0, cursor = end, held;
313
447
  // Claude's queue pairing: the row scan is newest-first, so a prompt turn
314
- // is seen before the content-free dequeue that delivered it.
315
- const queue = {};
448
+ // is seen before the content-free dequeue that delivered it. The bindings
449
+ // name the phone message behind each queue occurrence when the Hook has
450
+ // tracked the send, so the queue row and its consumption share one id.
451
+ const bindings = this.imageLine === undefined && this.source === "claude" && this.queueBindings
452
+ ? await this.queueBindings().catch(() => undefined) : undefined;
453
+ const queue = bindings
454
+ ? { deliveryFor: (_raw, offset) => offset === undefined ? undefined : bindings.get(offset) } : {};
316
455
  for await (const row of index.rows(handle, end, lower, signal)) {
317
456
  signal?.throwIfAborted();
457
+ queue.offset = row.offset;
318
458
  let rows = [];
459
+ let promptEntryId;
319
460
  try {
320
- let raw = row.bytes && visibleEvent(object(JSON.parse(row.bytes.toString())), this.source, this.includeSidechain, this.cwd, queue);
461
+ // Read the native identity from the original row before visibility
462
+ // filtering removes harness metadata from the projected entry.
463
+ const original = row.bytes ? object(JSON.parse(row.bytes.toString())) : undefined;
464
+ let raw = original && visibleEvent(original, this.source, this.includeSidechain, this.cwd, queue);
321
465
  // A child agent's transcript is the sidechain. Its rows are that
322
466
  // conversation's own turns, not something for the reader to skip.
323
467
  if (raw && this.includeSidechain && raw.isSidechain === true) {
@@ -326,9 +470,7 @@ export class TranscriptReader {
326
470
  }
327
471
  // A code-mode script's result follows from the script it answers,
328
472
  // a few rows earlier: hidden when its items carry the actions.
329
- const codeModeCall = raw && this.source === "codex" ? codeModeOutputCall(raw) : undefined;
330
- if (raw && codeModeCall)
331
- raw = projectCodeModeOutput(raw, await findCodeModeCall((upper, lower) => index.rows(handle, upper, lower, signal), row.line, codeModeCall));
473
+ raw = await projectTranscriptEvent(raw, this.source, row.line, (upper, lower) => index.rows(handle, upper, lower, signal));
332
474
  if (raw) {
333
475
  if (this.changes && this.imageLine === undefined) {
334
476
  // A shell call's output carries what it changed on disk. While
@@ -364,10 +506,12 @@ export class TranscriptReader {
364
506
  if (Object.keys(attached).length)
365
507
  raw = { ...raw, phren_changes: { ...attached, ...object(raw.phren_changes) } };
366
508
  }
367
- const projected = this.source === "codex" ? projectCodexRow(raw) : { rows: [raw] };
509
+ const projected = projectTranscriptRows(raw, this.source);
368
510
  rows = this.imageLine === row.line ? projected.rows : projected.rows.map(r => chatFrame(r, this.source));
369
511
  if (projected.base)
370
512
  rewriteProjectedOutput(entries, projected.base);
513
+ if (this.source === "claude" && original)
514
+ promptEntryId = claudePromptIdentity(original, raw);
371
515
  }
372
516
  }
373
517
  catch { /* A malformed old row cannot block the next readable page. */ }
@@ -379,7 +523,7 @@ export class TranscriptReader {
379
523
  break;
380
524
  // Rows arrive newest first; reverse a row's blocks so the page
381
525
  // lists several calls from one source in the order they were written.
382
- entries.push(...rows.slice().reverse().map(raw => ({ line: row.line, raw })));
526
+ entries.push(...rows.slice().reverse().map(raw => ({ line: row.line, raw, ...(promptEntryId ? { promptEntryId } : {}) })));
383
527
  bytes += size;
384
528
  }
385
529
  }
@@ -387,16 +531,30 @@ export class TranscriptReader {
387
531
  if (entries.length >= entryBudget)
388
532
  break;
389
533
  }
390
- if (before === undefined) {
391
- this.revision = index.revision;
392
- this.nextLine = held ?? index.lines;
393
- }
394
534
  // Live reads run newest first. After a long disconnect or a burst of
395
535
  // output, a bounded page can stop before the phone's cursor. Mark that
396
536
  // page as a replacement so its start becomes a usable older-page cursor
397
537
  // instead of silently merging two disjoint windows. A pending diff
398
538
  // holds its row for a later poll and is not a completed page.
399
539
  const skippedLiveLines = before === undefined && held === undefined && cursor > lower;
540
+ // One prompt identity on several displayed prompts is ambiguous, so
541
+ // none of them may claim it, whichever page or reader sees it.
542
+ // A cursor resume must also invalidate identities retained by the phone,
543
+ // even when the resumed page contains no prompt rows at all.
544
+ if (resuming || entries.some(entry => entry.promptEntryId)) {
545
+ this.ambiguous = await ambiguousPromptIdentities(this.file, handle, index, this.source, this.includeSidechain, signal);
546
+ for (const entry of entries)
547
+ if (entry.promptEntryId && this.ambiguous.has(entry.promptEntryId))
548
+ delete entry.promptEntryId;
549
+ }
550
+ else if (reset)
551
+ this.ambiguous.clear();
552
+ // Only a completed read (including the fallible identity scan) advances
553
+ // the live cursor, so a retry rereads the same rows.
554
+ if (before === undefined) {
555
+ this.revision = index.revision;
556
+ this.nextLine = held ?? index.lines;
557
+ }
400
558
  // The phone resumes after `totalLines - 1`, so a live page does not
401
559
  // count a held row or what follows it: those are still owed. An older
402
560
  // page is never a replacement. The history route reads with a fresh
@@ -0,0 +1,6 @@
1
+ import type { AgentHooks } from "./agent-hooks.js";
2
+ import { type Target } from "./protocol.js";
3
+ import type { TurnQueuePane } from "./turn-queue.js";
4
+ /** Read the same guarded hook/plugin turn records used by dispatch returns.
5
+ * OpenCode's plugin supplies timestamped turns rather than lifecycle hooks. */
6
+ export declare function turnQueuePaneReader(agentHooks: Pick<AgentHooks, "approval" | "terminalPrompt" | "servedQuestion">): (target: Target) => Promise<TurnQueuePane | undefined>;
@@ -0,0 +1,30 @@
1
+ import { paneTurn } from "./dispatch-returns.js";
2
+ import { findPane, paneIdentity, snapshot } from "./herdr.js";
3
+ import { screenDialog } from "./pane-status.js";
4
+ import { readFinalTurn } from "./schedule-watch.js";
5
+ import { ownRecord, liveWork, takesPrompt } from "./session-activity.js";
6
+ import { promptGuards } from "./server-pane-routes.js";
7
+ import { childAgentTree, runningChildAgents } from "./transcripts.js";
8
+ /** Read the same guarded hook/plugin turn records used by dispatch returns.
9
+ * OpenCode's plugin supplies timestamped turns rather than lifecycle hooks. */
10
+ export function turnQueuePaneReader(agentHooks) {
11
+ return async (target) => {
12
+ const pane = findPane(await snapshot(target.server), { ...target, source: undefined });
13
+ if (!pane)
14
+ return undefined;
15
+ const session = await paneIdentity(target.server, pane, true);
16
+ if (pane.agent !== target.source || session !== target.session)
17
+ return { terminal: String(pane.terminal_id), source: String(pane.agent), session, background: 0, held: true, ready: false };
18
+ const record = ownRecord(await paneTurn(target.server, pane, target.source), pane, target.source, session);
19
+ const guards = promptGuards(agentHooks, target);
20
+ const [final, children, screen] = await Promise.all([
21
+ session && target.source !== "phren" ? readFinalTurn(target.source, session) : undefined,
22
+ session ? childAgentTree(target.source, session) : [],
23
+ guards.screen(),
24
+ ]);
25
+ return { terminal: String(pane.terminal_id), source: String(pane.agent), session, record,
26
+ background: liveWork(record, final, runningChildAgents(children).length) ?? 0,
27
+ held: guards.held() || screenDialog(target.source, screen),
28
+ ready: await takesPrompt(target.server, pane, session, guards) };
29
+ };
30
+ }
@@ -0,0 +1,86 @@
1
+ import { z } from "zod";
2
+ import { type Target } from "./protocol.js";
3
+ import type { DeliveryStatus } from "./prompt-deliveries.js";
4
+ import { type TurnRecord } from "./turn-records.js";
5
+ declare const itemSchema: z.ZodObject<{
6
+ id: z.ZodString;
7
+ target: z.ZodObject<{
8
+ server: z.ZodString;
9
+ workspace: z.ZodString;
10
+ tab: z.ZodString;
11
+ pane: z.ZodString;
12
+ source: z.ZodEnum<{
13
+ claude: "claude";
14
+ codex: "codex";
15
+ copilot: "copilot";
16
+ opencode: "opencode";
17
+ phren: "phren";
18
+ }>;
19
+ session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
20
+ }, z.core.$strip>;
21
+ terminal: z.ZodString;
22
+ text: z.ZodString;
23
+ state: z.ZodEnum<{
24
+ cancelled: "cancelled";
25
+ delivered: "delivered";
26
+ failed: "failed";
27
+ queued: "queued";
28
+ sending: "sending";
29
+ unknown: "unknown";
30
+ }>;
31
+ reason: z.ZodOptional<z.ZodEnum<{
32
+ "agent-restarted": "agent-restarted";
33
+ "conversation-changed": "conversation-changed";
34
+ "delivery-failed": "delivery-failed";
35
+ "pane-closed": "pane-closed";
36
+ }>>;
37
+ detail: z.ZodOptional<z.ZodString>;
38
+ createdAt: z.ZodString;
39
+ updatedAt: z.ZodString;
40
+ }, z.core.$strip>;
41
+ export type TurnQueueItem = z.infer<typeof itemSchema>;
42
+ export interface TurnQueuePane {
43
+ terminal: string;
44
+ source: string;
45
+ session?: string;
46
+ record?: TurnRecord;
47
+ /** Includes session-activity's awaited shells and running children. */
48
+ background: number;
49
+ held: boolean;
50
+ ready: boolean;
51
+ }
52
+ export interface TurnQueueDeps {
53
+ /** Undefined means confirmed absent; transport/read failures must throw. */
54
+ current(target: Target): Promise<TurnQueuePane | undefined>;
55
+ send(target: Target, text: string, id: string, typing: () => Promise<void>): Promise<Record<string, unknown>>;
56
+ delivery(target: Target, id: string): DeliveryStatus;
57
+ /** During the typing recheck, exclude only this item’s own reservation. */
58
+ holding(target: Target, exceptId?: string): boolean;
59
+ }
60
+ export declare class TurnQueue {
61
+ private file;
62
+ private deps;
63
+ private items;
64
+ private boundaries;
65
+ private serial;
66
+ private ticking?;
67
+ constructor(file: string, deps: TurnQueueDeps);
68
+ private run;
69
+ private save;
70
+ private prune;
71
+ count(server: string, pane: string): number;
72
+ list(target: Target): TurnQueueItem[];
73
+ private find;
74
+ enqueue(target: Target, id: string, text: string): Promise<TurnQueueItem>;
75
+ change(target: Target, id: string, text?: string): Promise<TurnQueueItem>;
76
+ private fail;
77
+ private settle;
78
+ private eligible;
79
+ tick(): Promise<void>;
80
+ private reconcilable;
81
+ private drain;
82
+ }
83
+ /** POST siblings of /v1/prompt, with its full authenticated target contract.
84
+ * Listing/editing/cancelling use the original target even after its pane closes. */
85
+ export declare function turnQueueRoute(queue: TurnQueue, route: string, data: unknown): Promise<unknown>;
86
+ export {};