@phren/cli 0.3.68 → 0.3.70

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 (37) hide show
  1. package/dist/bridge/account-choice.js +3 -5
  2. package/dist/bridge/agent-hooks.d.ts +10 -4
  3. package/dist/bridge/agent-hooks.js +140 -68
  4. package/dist/bridge/claude-footer-mode.d.ts +7 -0
  5. package/dist/bridge/claude-footer-mode.js +24 -0
  6. package/dist/bridge/claude-question-dialog.js +10 -2
  7. package/dist/bridge/claude-question-lifecycle.d.ts +8 -0
  8. package/dist/bridge/claude-question-lifecycle.js +87 -0
  9. package/dist/bridge/claude-suggestion.d.ts +3 -0
  10. package/dist/bridge/claude-suggestion.js +10 -0
  11. package/dist/bridge/codex-threads.d.ts +9 -0
  12. package/dist/bridge/codex-threads.js +104 -37
  13. package/dist/bridge/conversation-search.js +29 -22
  14. package/dist/bridge/dialog-observation.d.ts +5 -0
  15. package/dist/bridge/dialog-observation.js +20 -0
  16. package/dist/bridge/pane-status.d.ts +3 -0
  17. package/dist/bridge/pane-status.js +66 -18
  18. package/dist/bridge/permission-mode.d.ts +1 -6
  19. package/dist/bridge/permission-mode.js +2 -23
  20. package/dist/bridge/prompt-deliveries.d.ts +1 -1
  21. package/dist/bridge/prompt-deliveries.js +6 -1
  22. package/dist/bridge/schedule-launch.js +2 -2
  23. package/dist/bridge/server-launch.js +1 -1
  24. package/dist/bridge/server-pane-routes.d.ts +5 -8
  25. package/dist/bridge/server-pane-routes.js +85 -77
  26. package/dist/bridge/server-stream.js +8 -12
  27. package/dist/bridge/session-activity.d.ts +1 -1
  28. package/dist/bridge/session-activity.js +2 -2
  29. package/dist/bridge/session-evidence.js +1 -1
  30. package/dist/bridge/terminal-choice.d.ts +3 -0
  31. package/dist/bridge/terminal-choice.js +59 -3
  32. package/dist/bridge/terminal-dialog-text.d.ts +7 -0
  33. package/dist/bridge/terminal-dialog-text.js +49 -0
  34. package/dist/bridge/transcripts.d.ts +3 -0
  35. package/dist/bridge/transcripts.js +19 -1
  36. package/dist/bridge-hook.mjs +3195 -2815
  37. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { logicalDialogLines } from "./terminal-dialog-text.js";
1
2
  import { z } from "zod";
2
3
  import { BridgeError, object, objects } from "./protocol.js";
3
4
  import { stripTerminal } from "../terminal-text.js";
@@ -122,7 +123,21 @@ export function unframed(text) {
122
123
  }
123
124
  export function visibleTerminalChoice(text) {
124
125
  text = unframed(text);
125
- const parsed = numberedOptions(text);
126
+ const screenLines = logicalDialogLines(text);
127
+ text = screenLines.join("\n");
128
+ const optionRow = /^\s*[>❯›▸▶»•*]?\s*\d+[.)]\s+/;
129
+ let last = screenLines.length - 1;
130
+ while (last >= 0 && !optionRow.test(screenLines[last]))
131
+ last--;
132
+ if (last < 0 || screenLines.slice(last + 1).some(line => line.trim()
133
+ && !/^\s*(?:press |enter\b|esc\b|[↑↓←→]|tab\b)/i.test(line)))
134
+ return undefined;
135
+ let first = last;
136
+ while (first > 0 && optionRow.test(screenLines[first - 1]))
137
+ first--;
138
+ if (screenLines.slice(0, first).filter(line => /^\s*```/.test(line)).length % 2)
139
+ return undefined;
140
+ const parsed = numberedOptions(screenLines.slice(first, last + 1).join("\n"));
126
141
  const highlights = parsed.flatMap((option, index) => option.highlighted ? [index] : []);
127
142
  const highlightedIndex = highlights.length === 1 ? highlights[0] : undefined;
128
143
  if (parsed.some(option => !option.hasKey) && highlightedIndex === undefined)
@@ -131,7 +146,7 @@ export function visibleTerminalChoice(text) {
131
146
  if (options.length < 2 || new Set(options.map(option => option.key)).size !== options.length)
132
147
  return undefined;
133
148
  const lines = text.split(/\r?\n/);
134
- const firstOption = lines.findIndex(line => /^\s*[>❯›▸▶»•*]?\s*\d+[.)]\s+/.test(line));
149
+ const firstOption = lines.findIndex((line, index) => index === first && /^\s*[>❯›▸▶»•*]?\s*\d+[.)]\s+/.test(line));
135
150
  const above = firstOption < 0 ? lines.slice(0, 1) : lines.slice(0, firstOption);
136
151
  // Only the question's own block: everything above the last blank line is
137
152
  // whatever the agent printed before it asked, and reading a pane of
@@ -145,7 +160,10 @@ export function visibleTerminalChoice(text) {
145
160
  && /^\s*(?:select|choose) (?:model|reasoning (?:level|effort))\b/i.test(line));
146
161
  const question = above.slice(menuStart >= 0 ? menuStart : Math.max(start, above.length - QUESTION_LINES));
147
162
  const title = question.map(line => line.trim()).filter(line => line && !/^press enter\b/i.test(line)).join("\n").trim();
148
- if (!title)
163
+ if (!title || question.some(line => /^\s*>/.test(line)))
164
+ return undefined;
165
+ if (!parsed.some(option => option.hasKey) && !screenLines.slice(last + 1).some(line => /^\s*(?:press |enter\b|esc\b|[↑↓←→]|tab\b)/i.test(line)) && !/[?]/.test(title)
166
+ && !/^(?:select|choose) (?:model|reasoning|permissions)\b/im.test(title))
149
167
  return undefined;
150
168
  return { title: title.slice(0, 4_000), options: options.slice(0, 12),
151
169
  ...(highlightedIndex !== undefined ? { highlightedIndex } : {}) };
@@ -170,6 +188,13 @@ export function opencodePermissionDialog(ansi) {
170
188
  const row = plain.findIndex((line, index) => index > header && OPENCODE_OPTIONS.every(label => line.includes(label)));
171
189
  if (row < 0 || row - header > 24)
172
190
  return undefined;
191
+ if (plain.slice(row + 1).some(line => {
192
+ const tail = content(line);
193
+ return tail.trim() && !/^\s{24,}/.test(tail) && !/^\s*(?:ctrl\+|enter\b|[←→⇆])/.test(tail);
194
+ }))
195
+ return undefined;
196
+ if (plain.slice(0, header).filter(line => /^\s*```/.test(line)).length % 2)
197
+ return undefined;
173
198
  // Lines pushed far right are OpenCode's status column, not the question.
174
199
  const body = plain.slice(header + 1, row).map(content)
175
200
  .filter(line => line.trim() && !/^\s{24,}/.test(line)).map(line => line.trim());
@@ -232,6 +257,37 @@ export function numberedDialog(text) {
232
257
  options.push({ label: "Cancel", key: "Escape" });
233
258
  return { title: title.slice(0, 4_000), options: options.slice(0, 12) };
234
259
  }
260
+ /** Claude's live permission UI, rather than numbered prose in its output.
261
+ * The prompt, contiguous options, selection and final hint belong to one block. */
262
+ export function claudePermissionDialog(text) {
263
+ const lines = logicalDialogLines(stripTerminal(text));
264
+ while (lines.length && !lines.at(-1).trim())
265
+ lines.pop();
266
+ if (!/^\s*(?:Enter to (?:select|confirm).*?·\s*)?Esc to cancel(?:\s*·.*)?$/i.test(lines.at(-1) ?? ""))
267
+ return;
268
+ const footer = lines.length - 1;
269
+ let end = footer - 1;
270
+ while (end >= 0 && !lines[end].trim())
271
+ end--;
272
+ const row = /^\s*(❯)?\s*(\d+)\.\s+(.+)$/;
273
+ let start = end;
274
+ while (start >= 0 && row.test(lines[start]))
275
+ start--;
276
+ const rows = lines.slice(start + 1, end + 1);
277
+ if (rows.length < 2 || rows.filter(line => row.exec(line)?.[1]).length !== 1)
278
+ return;
279
+ if (rows.some((line, index) => Number(row.exec(line)[2]) !== index + 1))
280
+ return;
281
+ while (start >= 0 && !lines[start].trim())
282
+ start--;
283
+ // Claude's permission prompt is a question on its own line. Quoted/fenced
284
+ // examples and composer text are not the harness's prompt.
285
+ if (!/^\s*(?:Do you want to |Would you like to |Allow |Trust |Teach auto mode about your environment|Ready to code).*\?\s*$/i.test(lines[start] ?? ""))
286
+ return;
287
+ if (lines.slice(0, start + 1).filter(line => /^\s*```/.test(line)).length % 2)
288
+ return;
289
+ return numberedDialog(lines.slice(start).join("\n"));
290
+ }
235
291
  /** Read the question a terminal dialog is asking from the request it carries:
236
292
  * an explicit options list, or numbered lines inside its text. Undefined when
237
293
  * there are not at least two answerable choices. */
@@ -0,0 +1,7 @@
1
+ /** Fold the harness's footer, including an unindented soft wrap, without
2
+ * swallowing newer output below it. */
3
+ export declare function joinDialogFooters(lines: string[]): string[];
4
+ /** Physical rows in a narrow pane are not option boundaries. A continuation
5
+ * starts in the label's column; prompt continuations end at the question mark.
6
+ * Keep blank rows, chrome, new composers and hints as block boundaries. */
7
+ export declare function logicalDialogLines(text: string): string[];
@@ -0,0 +1,49 @@
1
+ /** Fold the harness's footer, including an unindented soft wrap, without
2
+ * swallowing newer output below it. */
3
+ export function joinDialogFooters(lines) {
4
+ const result = [];
5
+ let footer = -1;
6
+ for (const line of lines) {
7
+ if (footer >= 0 && /^\s*(?:[↑↓←→/·]+\s*|Esc\b|Tab\b|Enter\b|to\b|cancel\b|select\b|navigate\b|confirm\b|amend\b)/i.test(line)) {
8
+ result[footer] += " " + line.trim();
9
+ continue;
10
+ }
11
+ footer = /^\s*(?:Enter to\b|Press enter\b|Esc to\b|↑\/↓ to\b)/i.test(line) ? result.length : -1;
12
+ result.push(line);
13
+ }
14
+ return result;
15
+ }
16
+ const OPTION = /^(\s*[>❯›▸▶»•*]?\s*\d+[.)]\s+)(.+)$/;
17
+ const PROMPT = /^\s*(?:Do you want to |Would you like to |Allow |Trust |Teach auto mode about your environment|Ready to code)/i;
18
+ /** Physical rows in a narrow pane are not option boundaries. A continuation
19
+ * starts in the label's column; prompt continuations end at the question mark.
20
+ * Keep blank rows, chrome, new composers and hints as block boundaries. */
21
+ export function logicalDialogLines(text) {
22
+ const result = [];
23
+ let option = -1, column = 0, prompt = -1;
24
+ for (const line of text.split(/\r?\n/).map(line => line.trimEnd())) {
25
+ const row = OPTION.exec(line);
26
+ if (row) {
27
+ option = result.length;
28
+ column = row[1].length;
29
+ prompt = -1;
30
+ result.push(line);
31
+ continue;
32
+ }
33
+ const boundary = !line.trim() || /^\s*(?:[❯›>│`─]|Esc\b|Enter\b|Press enter\b|Tab\b|[↑↓←→])/i.test(line);
34
+ if (!boundary && option >= 0 && /^\s*/.exec(line)[0].length >= column) {
35
+ result[option] += " " + line.trim();
36
+ continue;
37
+ }
38
+ option = -1;
39
+ if (!boundary && prompt >= 0) {
40
+ result[prompt] += " " + line.trim();
41
+ if (/\?\s*$/.test(line))
42
+ prompt = -1;
43
+ continue;
44
+ }
45
+ prompt = PROMPT.test(line) && !/\?\s*$/.test(line) ? result.length : -1;
46
+ result.push(line);
47
+ }
48
+ return joinDialogFooters(result);
49
+ }
@@ -122,6 +122,9 @@ export declare class TranscriptReader {
122
122
  private revision?;
123
123
  private nextLine;
124
124
  private ambiguous;
125
+ private questionBoundary?;
126
+ private resolvedQuestionIds;
127
+ resolveClaudeQuestionsThrough(at: number | undefined): void;
125
128
  constructor(file: string, source: Provider, imageLine?: number | undefined, changes?: ChangeLookup | undefined, includeSidechain?: boolean, cwd?: string | undefined,
126
129
  /** The phone delivery bound to each Claude queue row, by byte offset (PromptDeliveries). */
127
130
  queueBindings?: (() => Promise<Map<number, string> | undefined>) | undefined);
@@ -1,3 +1,4 @@
1
+ import { claudeQuestionResolutions, projectClaudeQuestionResolutions } from "./claude-question-lifecycle.js";
1
2
  import { readdir, realpath, lstat } from "node:fs/promises";
2
3
  import { createHash } from "node:crypto";
3
4
  import { homedir } from "node:os";
@@ -396,6 +397,9 @@ export class TranscriptReader {
396
397
  revision;
397
398
  nextLine = 0;
398
399
  ambiguous = new Set();
400
+ questionBoundary;
401
+ resolvedQuestionIds = "";
402
+ resolveClaudeQuestionsThrough(at) { this.questionBoundary = at; }
399
403
  constructor(file, source, imageLine, changes, includeSidechain = false, cwd,
400
404
  /** The phone delivery bound to each Claude queue row, by byte offset (PromptDeliveries). */
401
405
  queueBindings) {
@@ -412,7 +416,9 @@ export class TranscriptReader {
412
416
  /** A fresh opening page with the same reader options, for a reset after an
413
417
  * identity already delivered by this stream became ambiguous. */
414
418
  snapshot(signal) {
415
- return new TranscriptReader(this.file, this.source, this.imageLine, this.changes, this.includeSidechain, this.cwd, this.queueBindings).read(undefined, signal);
419
+ const reader = new TranscriptReader(this.file, this.source, this.imageLine, this.changes, this.includeSidechain, this.cwd, this.queueBindings);
420
+ reader.resolveClaudeQuestionsThrough(this.questionBoundary);
421
+ return reader.read(undefined, signal);
416
422
  }
417
423
  async read(before, signal) {
418
424
  return this.readPage(before, undefined, signal);
@@ -424,6 +430,16 @@ export class TranscriptReader {
424
430
  return this.readPage(undefined, afterLine, signal);
425
431
  }
426
432
  async readPage(before, afterLine, signal) {
433
+ const resolvedQuestions = this.source === "claude" && !this.includeSidechain
434
+ ? await claudeQuestionResolutions(this.file, this.questionBoundary, signal) : new Set();
435
+ const identities = JSON.stringify([...resolvedQuestions]);
436
+ if (identities !== this.resolvedQuestionIds) {
437
+ // A question can resolve without a transcript append (Stop/owner hook).
438
+ // Replace the tail so a client that already saw its call sees its resolution.
439
+ if (this.resolvedQuestionIds)
440
+ this.revision = undefined;
441
+ this.resolvedQuestionIds = identities;
442
+ }
427
443
  return withTranscriptIndex(this.file, async (handle, index) => {
428
444
  const reset = this.revision !== index.revision;
429
445
  const end = Math.min(before ?? index.lines, index.lines);
@@ -506,6 +522,8 @@ export class TranscriptReader {
506
522
  if (Object.keys(attached).length)
507
523
  raw = { ...raw, phren_changes: { ...attached, ...object(raw.phren_changes) } };
508
524
  }
525
+ if (this.source === "claude")
526
+ raw = projectClaudeQuestionResolutions(raw, resolvedQuestions);
509
527
  const projected = projectTranscriptRows(raw, this.source);
510
528
  rows = this.imageLine === row.line ? projected.rows : projected.rows.map(r => chatFrame(r, this.source));
511
529
  if (projected.base)