@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.
- package/dist/bridge/agent-hook-callback.js +11 -2
- package/dist/bridge/agent-hooks.d.ts +11 -1
- package/dist/bridge/agent-hooks.js +259 -40
- package/dist/bridge/changes.d.ts +2 -2
- package/dist/bridge/changes.js +11 -9
- package/dist/bridge/checkpoints.d.ts +24 -0
- package/dist/bridge/checkpoints.js +423 -0
- package/dist/bridge/claude-input-state.d.ts +14 -0
- package/dist/bridge/claude-input-state.js +58 -0
- package/dist/bridge/claude-queue.js +5 -2
- package/dist/bridge/claude-suggestion.d.ts +3 -0
- package/dist/bridge/claude-suggestion.js +10 -0
- package/dist/bridge/codex-threads.d.ts +7 -1
- package/dist/bridge/codex-threads.js +185 -56
- package/dist/bridge/conversation-search.d.ts +20 -0
- package/dist/bridge/conversation-search.js +928 -0
- package/dist/bridge/git-watch.d.ts +46 -0
- package/dist/bridge/git-watch.js +351 -0
- package/dist/bridge/git-worktree-remove.d.ts +44 -0
- package/dist/bridge/git-worktree-remove.js +140 -0
- package/dist/bridge/git-worktrees.d.ts +14 -0
- package/dist/bridge/git-worktrees.js +7 -3
- package/dist/bridge/git-write-policy.js +1 -1
- package/dist/bridge/gitboy-webhooks.d.ts +3 -1
- package/dist/bridge/gitboy-webhooks.js +26 -2
- package/dist/bridge/herdr.d.ts +6 -1
- package/dist/bridge/herdr.js +56 -10
- package/dist/bridge/hook-fast.js +13 -1
- package/dist/bridge/input-classification.d.ts +33 -0
- package/dist/bridge/input-classification.js +84 -0
- package/dist/bridge/pane-status.d.ts +3 -3
- package/dist/bridge/pane-status.js +16 -8
- package/dist/bridge/prompt-deliveries.d.ts +30 -4
- package/dist/bridge/prompt-deliveries.js +365 -13
- package/dist/bridge/prompt-identity.d.ts +8 -0
- package/dist/bridge/prompt-identity.js +15 -0
- package/dist/bridge/request-origin.js +2 -1
- package/dist/bridge/schedule-events.d.ts +17 -0
- package/dist/bridge/schedule-events.js +53 -0
- package/dist/bridge/schedule-format.d.ts +22 -2
- package/dist/bridge/schedule-format.js +40 -5
- package/dist/bridge/schedule-update.js +2 -1
- package/dist/bridge/schedule-watch.js +15 -5
- package/dist/bridge/schedules.d.ts +9 -0
- package/dist/bridge/schedules.js +120 -7
- package/dist/bridge/server-pane-routes.d.ts +7 -8
- package/dist/bridge/server-pane-routes.js +186 -82
- package/dist/bridge/server-routes.d.ts +26 -2
- package/dist/bridge/server-routes.js +180 -56
- package/dist/bridge/server-stream.js +66 -15
- package/dist/bridge/server.js +25 -7
- package/dist/bridge/session-activity.d.ts +49 -4
- package/dist/bridge/session-activity.js +47 -0
- package/dist/bridge/session-evidence.d.ts +18 -0
- package/dist/bridge/session-evidence.js +72 -0
- package/dist/bridge/session-seen.d.ts +23 -0
- package/dist/bridge/session-seen.js +69 -0
- package/dist/bridge/tab-activity.d.ts +26 -1
- package/dist/bridge/tab-activity.js +64 -9
- package/dist/bridge/terminal-resolve.d.ts +20 -0
- package/dist/bridge/terminal-resolve.js +145 -0
- package/dist/bridge/terminal-tmux.d.ts +8 -3
- package/dist/bridge/terminal-tmux.js +59 -7
- package/dist/bridge/transcript-claude.d.ts +12 -2
- package/dist/bridge/transcript-claude.js +91 -13
- package/dist/bridge/transcript-index.d.ts +4 -2
- package/dist/bridge/transcript-index.js +6 -5
- package/dist/bridge/transcript-preview.d.ts +16 -1
- package/dist/bridge/transcript-preview.js +171 -27
- package/dist/bridge/transcripts.d.ts +41 -1
- package/dist/bridge/transcripts.js +181 -23
- package/dist/bridge/turn-queue-pane.d.ts +6 -0
- package/dist/bridge/turn-queue-pane.js +30 -0
- package/dist/bridge/turn-queue.d.ts +86 -0
- package/dist/bridge/turn-queue.js +280 -0
- package/dist/bridge/turn-records.d.ts +18 -0
- package/dist/bridge/turn-records.js +77 -5
- package/dist/bridge-hook.mjs +7074 -3173
- package/dist/cli/config-shared.js +2 -1
- package/dist/cli/schedules.js +6 -1
- package/dist/content/secrets.js +1 -1
- package/dist/modules/registry.js +12 -11
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { constants } from "node:fs";
|
|
2
2
|
import { open } from "node:fs/promises";
|
|
3
3
|
import { codexThreadPreview } from "./codex-threads.js";
|
|
4
|
+
import { classifyClaudeInput } from "./input-classification.js";
|
|
4
5
|
import { readPaneText } from "./pane-text.js";
|
|
5
6
|
import { object, objects } from "./protocol.js";
|
|
6
7
|
import { withTranscriptIndex } from "./transcript-index.js";
|
|
@@ -28,6 +29,7 @@ export function claudePanePreview(rendered, prompt, previous = "", inTurn = fals
|
|
|
28
29
|
const lines = raw.map((line, index) => (/[─━═]{3,}/.test(line) && !/^\s*[│┃║]/.test(line))
|
|
29
30
|
|| (/[─━═]\s*$/.test(line) && /^\s*[❯>]\s*$/.test(raw[index + 1] ?? "")) ? "❯" : line.replace(/[\u2500-\u257f]/g, "").trimEnd());
|
|
30
31
|
const firstPrompt = prompt.trim().split(/\r?\n/)[0]?.trim();
|
|
32
|
+
// No verified textual anchor means no pane preview, including reconnects.
|
|
31
33
|
if (!firstPrompt)
|
|
32
34
|
return "";
|
|
33
35
|
let start = -1;
|
|
@@ -44,10 +46,11 @@ export function claudePanePreview(rendered, prompt, previous = "", inTurn = fals
|
|
|
44
46
|
// pasted-text placeholder): the newest prompt row with turn output under it (a block, the spinner, thinking)
|
|
45
47
|
// is this turn's, and everything above it is an older turn. The composer and a permission dialog's
|
|
46
48
|
// options have none under them.
|
|
47
|
-
|
|
49
|
+
const command = /<command-name>([^<]+)<\/command-name>/.exec(prompt)?.[1];
|
|
50
|
+
if (start < 0 && inTurn && !previous && command) {
|
|
48
51
|
const output = (line) => /^\s*[⏺●✻✽✶✢✳✦·∴⠁-⣿]/u.test(line) || !!parseClaudeSpinnerLine(line);
|
|
49
52
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
50
|
-
if (
|
|
53
|
+
if (lines[i].replace(/^\s*[❯>]\s*/, "").trim() !== command || !lines.slice(i + 1).some(output))
|
|
51
54
|
continue;
|
|
52
55
|
// Nothing written under this turn's prompt yet: no reply to show.
|
|
53
56
|
if (!lines.slice(i + 1).some(line => /^\s*[⏺●]/.test(line)))
|
|
@@ -56,13 +59,16 @@ export function claudePanePreview(rendered, prompt, previous = "", inTurn = fals
|
|
|
56
59
|
break;
|
|
57
60
|
}
|
|
58
61
|
}
|
|
62
|
+
if (start < 0 && !previous && lines.some(line => /^\s*[❯>]\s*\S/.test(line)))
|
|
63
|
+
return "";
|
|
59
64
|
const scrolled = start < 0;
|
|
60
65
|
if (scrolled && !previous && !inTurn)
|
|
61
66
|
return "";
|
|
62
67
|
const reply = [], shown = [];
|
|
63
68
|
// Scrolled past its ⏺, a reply already previewed continues from the top; without one, the top of the
|
|
64
|
-
// screen may be tool output, so only a ⏺ text block starts a reply.
|
|
65
|
-
|
|
69
|
+
// screen may be tool output, so only a ⏺ text block starts a reply. A marker alone cannot establish
|
|
70
|
+
// authorship: notices and tools share it, so each is classified before a reply can start.
|
|
71
|
+
let block = scrolled && !!previous ? "reply" : "none";
|
|
66
72
|
const body = lines.slice(Math.max(0, start)), rawBody = raw.slice(Math.max(0, start)), markedBody = marked.slice(Math.max(0, start));
|
|
67
73
|
// A "⏺" block whose next line is a "⎿" result is a tool call, collapsed
|
|
68
74
|
// ("⏺ Running 1 shell command…") or not; it lands as its own entry.
|
|
@@ -71,6 +77,10 @@ export function claudePanePreview(rendered, prompt, previous = "", inTurn = fals
|
|
|
71
77
|
for (let next = index + 1; next < body.length; next++) {
|
|
72
78
|
if (!body[next].trim())
|
|
73
79
|
continue;
|
|
80
|
+
// A notice can be drawn under a tool call's marker (" ⎿ Background
|
|
81
|
+
// command …"); it is not that call's result.
|
|
82
|
+
if (claudeNotice(body[next]))
|
|
83
|
+
return false;
|
|
74
84
|
// A result ("⎿") or a sub-agent tree ("├─ Plan · 0 tool uses") follows a tool call.
|
|
75
85
|
// A narrow pane wraps the call's description ("⏺ Finding retire wording
|
|
76
86
|
// around Power" / "Portal reports"); its "⎿", indented under the call as
|
|
@@ -91,13 +101,21 @@ export function claudePanePreview(rendered, prompt, previous = "", inTurn = fals
|
|
|
91
101
|
break;
|
|
92
102
|
if (/^\s*[✻✽✶✢✳✦·⠁-⣿]/u.test(line) || parseClaudeSpinnerLine(line))
|
|
93
103
|
continue;
|
|
104
|
+
// Claude Code's own notices (a background command's completion, a hook's
|
|
105
|
+
// output, a Monitor event, an interruption or a compaction) can share the
|
|
106
|
+
// reply's marker. They never clear or join an already collected reply, and
|
|
107
|
+
// their wrapped payload stays out until a fresh reply marker starts one.
|
|
108
|
+
if (claudeNotice(line)) {
|
|
109
|
+
block = "notice";
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
94
112
|
// Claude Code draws a finished or running tool group as an unbulleted,
|
|
95
113
|
// indented summary under the reply (" Ran 1 shell command", " Called
|
|
96
114
|
// phren, ran 1 shell command", " Running 1 shell command… grep -rn …").
|
|
97
115
|
// It starts a block after a blank line; it and its wrapped command lines
|
|
98
116
|
// are tool activity, which lands as its own entry.
|
|
99
117
|
if (!body[index - 1]?.trim() && claudeToolSummary(line)) {
|
|
100
|
-
|
|
118
|
+
block = "tool";
|
|
101
119
|
continue;
|
|
102
120
|
}
|
|
103
121
|
// A running tool group ("⏺ Running 2 agents…") and a tool call
|
|
@@ -105,19 +123,28 @@ export function claudePanePreview(rendered, prompt, previous = "", inTurn = fals
|
|
|
105
123
|
// text; it lands as its own entry a moment later.
|
|
106
124
|
if (/^\s*[⏺●]\s*[\w.:-]+(?: - [\w.:-]+)?(?: \(MCP\))?\(/.test(line) || (/^\s*[⏺●]/.test(line) && toolBlock(index))
|
|
107
125
|
|| /^\s*[⏺●]\s*(?:Running|Calling|Reading|Searching|Writing|Editing|Fetching|Updating|Listing|Creating)\b[^.!?]*(?:…|\.\.\.)/.test(line)) {
|
|
108
|
-
|
|
126
|
+
block = "tool";
|
|
109
127
|
continue;
|
|
110
128
|
}
|
|
129
|
+
const tidy = (value) => value.replace(/^\s*[⏺●]\s?/, "").replace(/[⠁-⣿✻✽✶✢✳]/gu, "");
|
|
130
|
+
const clean = tidy(line);
|
|
131
|
+
const skipped = /^\s*(?:↳|⎿|ctrl\+|shift\+|\? for shortcuts)/i.test(clean) || claudeChrome(clean);
|
|
111
132
|
if (/^\s*[⏺●]/.test(line)) {
|
|
112
133
|
reply.length = 0;
|
|
113
134
|
shown.length = 0;
|
|
114
|
-
|
|
135
|
+
block = "reply";
|
|
115
136
|
}
|
|
116
|
-
if (
|
|
137
|
+
else if (block === "reply") {
|
|
138
|
+
// A reply's wrapped rows stay indented under its marker; an unmarked,
|
|
139
|
+
// nonindented row (a notice's payload included) ends the acceptance.
|
|
140
|
+
if (line.trim() && !/^ {2,}\S/.test(line)) {
|
|
141
|
+
block = "none";
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else
|
|
117
146
|
continue;
|
|
118
|
-
|
|
119
|
-
const clean = tidy(line);
|
|
120
|
-
if (/^\s*(?:↳|⎿|ctrl\+|shift\+|\? for shortcuts)/i.test(clean) || claudeChrome(clean))
|
|
147
|
+
if (skipped)
|
|
121
148
|
continue;
|
|
122
149
|
reply.push(clean.replace(/^ {2}/, ""));
|
|
123
150
|
// A rule line has no marked twin: it never reaches here.
|
|
@@ -152,9 +179,32 @@ export function claudeChrome(line) {
|
|
|
152
179
|
|| /^(?:Tip|Hint):\s/i.test(text)
|
|
153
180
|
|| /^(?:⏵⏵|⏸)\s/.test(text)
|
|
154
181
|
|| /\b(?:auto-accept edits|plan mode) (?:on|off)\b/i.test(text)
|
|
182
|
+
|| /^(?:(?:manual|auto) mode|accept edits|auto-accept edits|plan mode|bypass permissions) (?:on|off)\b/i.test(text)
|
|
155
183
|
|| /^Context left until auto-compact\b/i.test(text)
|
|
156
184
|
|| /^(?:esc to (?:interrupt|cancel)|press esc)\b/i.test(text);
|
|
157
185
|
}
|
|
186
|
+
/** A notice line's detection text: terminal borders, indentation and the
|
|
187
|
+
* optional ⏺ / ● / ⎿ decoration are presentation, not part of what it says. */
|
|
188
|
+
function noticeText(line) {
|
|
189
|
+
return line.replace(/^[\s\u2500-\u257f]*/, "").replace(/^[⏺●⎿]\s*/, "").trim();
|
|
190
|
+
}
|
|
191
|
+
/** Claude Code's own notices, which share the reply's marker. A header starts
|
|
192
|
+
* a notice block; its wrapped payload must not be taken for reply text. */
|
|
193
|
+
function claudeNotice(line) {
|
|
194
|
+
const text = noticeText(line);
|
|
195
|
+
if (!text)
|
|
196
|
+
return false;
|
|
197
|
+
return /^Background command\s+["“]/.test(text)
|
|
198
|
+
|| /^Monitor event\b/.test(text)
|
|
199
|
+
|| /^<task-notification>/.test(text)
|
|
200
|
+
|| /^Agent\b.+\bcompleted\b/.test(text)
|
|
201
|
+
|| /^(?:SessionStart|UserPromptSubmit|PreToolUse|PostToolUse|Stop|SubagentStop|Notification|PreCompact|SessionEnd)(?::[\w-]+)? hook\b/.test(text)
|
|
202
|
+
|| /^Hook output:/.test(text)
|
|
203
|
+
|| /^(?:Interrupted by user\b|\[Request interrupted by user)/.test(text)
|
|
204
|
+
|| /^(?:Compacting conversation(?:…|\.\.\.)|Conversation compacted|Context compacted)/.test(text)
|
|
205
|
+
|| /^(?:⏵⏵|⏸)\s/.test(text)
|
|
206
|
+
|| /^(?:(?:manual|auto) mode|accept edits|auto-accept edits|plan mode|bypass permissions) (?:on|off)\b/i.test(text);
|
|
207
|
+
}
|
|
158
208
|
/** A block line that starts its own row even inside a paragraph: a list
|
|
159
209
|
* item, heading, quote, table row or code fence. */
|
|
160
210
|
/** No terminal pane Claude draws in is narrower than this. */
|
|
@@ -456,6 +506,8 @@ export class TranscriptPreviewStream {
|
|
|
456
506
|
* showing a landed block until a newer one is drawn, so only a block not among these is previewed. */
|
|
457
507
|
landedTexts = new Set();
|
|
458
508
|
ended = false;
|
|
509
|
+
lifecycleEnded = false;
|
|
510
|
+
retirementComplete = true;
|
|
459
511
|
/** Claude's own spinner word for the running turn, sent beside frames as
|
|
460
512
|
* `activityVerb` for older phones. */
|
|
461
513
|
verb;
|
|
@@ -466,6 +518,7 @@ export class TranscriptPreviewStream {
|
|
|
466
518
|
lastRead = -Infinity;
|
|
467
519
|
lastSent = -Infinity;
|
|
468
520
|
current = null;
|
|
521
|
+
clearPending = false;
|
|
469
522
|
observedLine = -1;
|
|
470
523
|
wasWorking = false;
|
|
471
524
|
/** Replies that already landed as entries: a sidecar or thread a tick
|
|
@@ -479,10 +532,13 @@ export class TranscriptPreviewStream {
|
|
|
479
532
|
}
|
|
480
533
|
observe(entries, reset = false) {
|
|
481
534
|
if (reset) {
|
|
535
|
+
this.clearPending ||= !!this.current;
|
|
482
536
|
this.observedLine = -1;
|
|
483
537
|
this.startedAt = undefined;
|
|
484
538
|
this.landed = false;
|
|
485
539
|
this.landedTexts.clear();
|
|
540
|
+
this.retirementComplete = true;
|
|
541
|
+
this.lifecycleEnded = false;
|
|
486
542
|
this.ended = false;
|
|
487
543
|
this.wasWorking = false;
|
|
488
544
|
this.completed.clear();
|
|
@@ -548,22 +604,32 @@ export class TranscriptPreviewStream {
|
|
|
548
604
|
}
|
|
549
605
|
continue;
|
|
550
606
|
}
|
|
551
|
-
if (this.target.source !== "claude")
|
|
607
|
+
if (this.target.source !== "claude" || raw.phrenExecution === "background")
|
|
552
608
|
continue;
|
|
553
609
|
const message = object(raw.message), blocks = objects(message.content);
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
610
|
+
const prompt = typeof message.content === "string" ? message.content : blocks.filter(b => b.type === "text").map(b => String(b.text ?? "")).join("\n");
|
|
611
|
+
const input = classifyClaudeInput({ text: prompt, hasImage: blocks.some(b => b.type === "image"), origin: raw.origin, commandMode: raw.commandMode,
|
|
612
|
+
isMeta: raw.isMeta, isSidechain: raw.isSidechain, isCompactSummary: raw.isCompactSummary,
|
|
613
|
+
toolResult: blocks.some(b => b.type === "tool_result") });
|
|
614
|
+
if (raw.type === "user" && input.category === "owner" && !raw.phrenQueued) {
|
|
615
|
+
if ((prompt.trim() || blocks.some(b => b.type === "image")) && typeof raw.timestamp === "string" && Number.isFinite(Date.parse(raw.timestamp))) {
|
|
616
|
+
this.clearPending ||= !!this.current;
|
|
557
617
|
this.startedAt = raw.timestamp;
|
|
558
618
|
this.prompt = prompt;
|
|
559
619
|
this.landed = false;
|
|
560
620
|
this.landedTexts.clear();
|
|
621
|
+
this.retirementComplete = true;
|
|
622
|
+
this.lifecycleEnded = false;
|
|
561
623
|
this.ended = false;
|
|
562
624
|
this.wasWorking = false;
|
|
563
625
|
this.verb = undefined;
|
|
564
626
|
this.activity = undefined;
|
|
565
627
|
}
|
|
566
628
|
}
|
|
629
|
+
else if (this.startedAt && raw.type === "user" && blocks.some(b => b.type === "tool_result")) {
|
|
630
|
+
// A tool result is the turn's own activity, never a new owner prompt.
|
|
631
|
+
this.landed = true;
|
|
632
|
+
}
|
|
567
633
|
else if (this.startedAt && ((raw.type === "assistant" && message.stop_reason === "end_turn")
|
|
568
634
|
|| (raw.type === "system" && raw.subtype === "turn_duration"))) {
|
|
569
635
|
// The transcript says the turn is over before the shared snapshot
|
|
@@ -579,8 +645,10 @@ export class TranscriptPreviewStream {
|
|
|
579
645
|
const texts = typeof message.content === "string" ? [message.content] : blocks.filter(b => b.type === "text").map(b => String(b.text ?? ""));
|
|
580
646
|
for (const text of texts.map(previewWords).filter(Boolean))
|
|
581
647
|
this.landedTexts.add(text);
|
|
582
|
-
while (this.landedTexts.size > 64)
|
|
648
|
+
while (this.landedTexts.size > 64) {
|
|
649
|
+
this.retirementComplete = false;
|
|
583
650
|
this.landedTexts.delete(this.landedTexts.values().next().value);
|
|
651
|
+
}
|
|
584
652
|
}
|
|
585
653
|
}
|
|
586
654
|
}
|
|
@@ -593,9 +661,67 @@ export class TranscriptPreviewStream {
|
|
|
593
661
|
// A short block ("Let me check.") is not a longer one that starts with its words.
|
|
594
662
|
!(landed.length < LANDED_MATCH_CHARS && words.length > landed.length) && drawsLanded(words, landed));
|
|
595
663
|
}
|
|
596
|
-
|
|
664
|
+
/** Seed a reconnect from a classified owner row in the verified transcript. */
|
|
665
|
+
seedTurn(turnStartedAt, prompt) {
|
|
666
|
+
if (this.startedAt || !prompt.trim() || !Number.isFinite(Date.parse(turnStartedAt)))
|
|
667
|
+
return;
|
|
668
|
+
this.startedAt = turnStartedAt;
|
|
669
|
+
this.prompt = prompt;
|
|
670
|
+
// The anchor came from a classified owner row in the verified transcript.
|
|
671
|
+
this.landed = true;
|
|
672
|
+
this.ended = false;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Accept a pane candidate monotonically. Within one block, only a growing
|
|
676
|
+
* extension (or a verified overlap) is taken; a shorter or unrelated screen
|
|
677
|
+
* cannot replace the accepted block. A later block is accepted only once the
|
|
678
|
+
* previous one landed (which clears `current` first) or the caller observed a
|
|
679
|
+
* structural boundary.
|
|
680
|
+
*/
|
|
681
|
+
acceptClaudeCandidate(candidate) {
|
|
682
|
+
const current = this.current && this.current.turnStartedAt === this.startedAt ? this.current.text : "";
|
|
683
|
+
if (!current)
|
|
684
|
+
return candidate.slice(0, MAX_TEXT);
|
|
685
|
+
if (candidate === current)
|
|
686
|
+
return "";
|
|
687
|
+
if (candidate.startsWith(current))
|
|
688
|
+
return candidate.slice(0, MAX_TEXT);
|
|
689
|
+
// A shorter screen is an incomplete redraw, never a replacement.
|
|
690
|
+
if (current.startsWith(candidate))
|
|
691
|
+
return "";
|
|
692
|
+
// Verified overlap: a redraw may drop the opening rows but keep a stretch.
|
|
693
|
+
for (let size = Math.min(current.length, 160); size >= 24; size -= 8) {
|
|
694
|
+
const overlap = current.slice(-size);
|
|
695
|
+
const at = candidate.indexOf(overlap);
|
|
696
|
+
if (at === 0)
|
|
697
|
+
return (current.slice(0, current.length - size) + candidate.slice(at)).slice(0, MAX_TEXT);
|
|
698
|
+
}
|
|
699
|
+
return "";
|
|
700
|
+
}
|
|
701
|
+
async update(status, file, now, lifecycle) {
|
|
597
702
|
const readAt = now ?? Date.now();
|
|
598
703
|
let next = null;
|
|
704
|
+
if (this.target.source === "claude" && lifecycle?.ended !== undefined) {
|
|
705
|
+
this.lifecycleEnded = lifecycle.ended;
|
|
706
|
+
if (this.lifecycleEnded) {
|
|
707
|
+
this.verb = undefined;
|
|
708
|
+
this.activity = undefined;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
// Settled rows and genuine ends clear in the same append, even between
|
|
712
|
+
// scrape ticks. Only pane reads and growth frames are throttled.
|
|
713
|
+
if (this.target.source === "claude" && this.current && (this.ended || this.lifecycleEnded || this.clearPending
|
|
714
|
+
|| this.current.turnStartedAt !== this.startedAt || this.hasLanded(this.current.text))) {
|
|
715
|
+
this.current = null;
|
|
716
|
+
this.clearPending = false;
|
|
717
|
+
if (this.ended || this.lifecycleEnded) {
|
|
718
|
+
this.verb = undefined;
|
|
719
|
+
this.activity = undefined;
|
|
720
|
+
this.sentActivity = "";
|
|
721
|
+
}
|
|
722
|
+
return { preview: null };
|
|
723
|
+
}
|
|
724
|
+
this.clearPending = false;
|
|
599
725
|
if (status === "working") {
|
|
600
726
|
this.wasWorking = true;
|
|
601
727
|
if (STREAMED_SOURCES.has(this.target.source)) {
|
|
@@ -609,23 +735,31 @@ export class TranscriptPreviewStream {
|
|
|
609
735
|
next = null;
|
|
610
736
|
}
|
|
611
737
|
}
|
|
612
|
-
else if (this.target.source === "claude" && this.startedAt && !this.ended) {
|
|
738
|
+
else if (this.target.source === "claude" && this.startedAt && !this.ended && !this.lifecycleEnded && this.retirementComplete) {
|
|
613
739
|
if (readAt - this.lastRead < PREVIEW_INTERVAL_MS)
|
|
614
740
|
return undefined;
|
|
615
741
|
this.lastRead = readAt;
|
|
616
742
|
// A reply block stops once it lands as an entry; the next one written after a tool or thinking
|
|
617
743
|
// previews in turn. Claude's spinner verb keeps naming the work until the turn ends.
|
|
618
744
|
const pane = await this.pane();
|
|
619
|
-
|
|
620
|
-
if (text && this.hasLanded(text))
|
|
621
|
-
text = "";
|
|
745
|
+
const candidate = claudePanePreview(pane, this.prompt, this.current?.turnStartedAt === this.startedAt ? this.current.text : "", this.landed);
|
|
622
746
|
const spinner = claudeSpinner(pane);
|
|
623
747
|
if (spinner) {
|
|
624
748
|
this.activity = spinner;
|
|
625
749
|
this.verb = spinner.verb;
|
|
626
750
|
}
|
|
627
|
-
if (
|
|
628
|
-
|
|
751
|
+
if (candidate && !this.hasLanded(candidate)) {
|
|
752
|
+
const accepted = this.acceptClaudeCandidate(candidate);
|
|
753
|
+
if (accepted)
|
|
754
|
+
next = { turnStartedAt: this.startedAt, text: accepted };
|
|
755
|
+
else if (this.current?.turnStartedAt === this.startedAt)
|
|
756
|
+
next = this.current;
|
|
757
|
+
}
|
|
758
|
+
else if (this.current?.turnStartedAt === this.startedAt) {
|
|
759
|
+
// An inconclusive scrape (empty, notice-only, transiently incomplete)
|
|
760
|
+
// never retires an accepted preview while work continues.
|
|
761
|
+
next = this.current;
|
|
762
|
+
}
|
|
629
763
|
}
|
|
630
764
|
else if (this.target.source === "copilot" && this.startedAt && !this.ended) {
|
|
631
765
|
// No reply text from the pane: only whether Copilot is thinking.
|
|
@@ -640,10 +774,20 @@ export class TranscriptPreviewStream {
|
|
|
640
774
|
}
|
|
641
775
|
}
|
|
642
776
|
else if (["claude", "copilot"].includes(this.target.source) && this.wasWorking) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
777
|
+
// Only a resolved genuine end terminates. A bare status snapshot can be a
|
|
778
|
+
// notification-driven idle or a stale terminal report; server-stream
|
|
779
|
+
// passes the resolver's answer as `lifecycle`. A caller without lifecycle evidence
|
|
780
|
+
// preserves the accepted Claude preview.
|
|
781
|
+
const ended = this.target.source === "copilot" || lifecycle?.ended === true;
|
|
782
|
+
if (ended) {
|
|
783
|
+
this.landed = true;
|
|
784
|
+
if (this.target.source === "copilot")
|
|
785
|
+
this.ended = true;
|
|
786
|
+
this.verb = undefined;
|
|
787
|
+
this.activity = undefined;
|
|
788
|
+
}
|
|
789
|
+
else if (this.current && this.current.turnStartedAt === this.startedAt)
|
|
790
|
+
next = this.current;
|
|
647
791
|
}
|
|
648
792
|
const sentAt = now ?? Date.now();
|
|
649
793
|
// The phone ticks the clock itself: only the verb, tokens and thinking
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type FileHandle } from "node:fs/promises";
|
|
1
2
|
import { type AccountRef } from "./claude-accounts.js";
|
|
2
3
|
import { type Json, type Provider, type Target } from "./protocol.js";
|
|
3
4
|
import { type ChangeLookup } from "./changes.js";
|
|
@@ -7,6 +8,7 @@ export { codeToolCalls, projectCodexRow, type CodeToolCall } from "./transcript-
|
|
|
7
8
|
export interface Entry {
|
|
8
9
|
line: number;
|
|
9
10
|
raw: Json;
|
|
11
|
+
promptEntryId?: string;
|
|
10
12
|
}
|
|
11
13
|
export interface ChildAgentRelation {
|
|
12
14
|
/** `id` is a parent-scoped public reference; local session and transcript details never leave Hook. */
|
|
@@ -77,6 +79,12 @@ export declare function targetTranscriptPath(target: {
|
|
|
77
79
|
source: Provider;
|
|
78
80
|
session: string;
|
|
79
81
|
}): Promise<string>;
|
|
82
|
+
/** Shared ambiguity rule for chat reads and the search index. A session ID
|
|
83
|
+
* alone cannot select between Claude account copies. Codex's caller falls
|
|
84
|
+
* back to its materialized store when no unique rollout can be chosen. */
|
|
85
|
+
export declare function selectTranscriptMatch<T extends {
|
|
86
|
+
id?: string | undefined;
|
|
87
|
+
}>(source: Provider, found: T[], account?: string): T | undefined;
|
|
80
88
|
/** `account` (a Claude home id) settles a session id found in more than one home. */
|
|
81
89
|
export declare function transcriptPath(source: Provider, session: string, account?: string): Promise<string>;
|
|
82
90
|
/** Keeps a materialized Codex thread current before a read; a no-op for
|
|
@@ -84,6 +92,22 @@ export declare function transcriptPath(source: Provider, session: string, accoun
|
|
|
84
92
|
export declare function refreshTranscript(file: string, source: Provider, session: string): Promise<void>;
|
|
85
93
|
/** Public conversation/tool events and real usage only. Never export private reasoning. */
|
|
86
94
|
export declare function visibleEvent(raw: Json, source: Provider, includeSidechain?: boolean, cwd?: string, queue?: ClaudeQueueState): Json | undefined;
|
|
95
|
+
export declare function ambiguousPromptIdentities(file: string, handle: FileHandle, index: {
|
|
96
|
+
revision: string;
|
|
97
|
+
lines: number;
|
|
98
|
+
rows: (handle: FileHandle, before: number, after: number, signal?: AbortSignal) => AsyncIterable<{
|
|
99
|
+
line: number;
|
|
100
|
+
bytes?: Buffer;
|
|
101
|
+
}>;
|
|
102
|
+
}, source: Provider, includeSidechain: boolean, signal?: AbortSignal): Promise<Set<string>>;
|
|
103
|
+
/** A finished turn's last public row, using the same absolute line key as
|
|
104
|
+
* stream frames and history pages. Reuse their incremental byte index and
|
|
105
|
+
* inspect at most 256 recent rows / 1 MiB, never scan the full history for a
|
|
106
|
+
* completion. Missing timestamps or an unresolved tail leave it manual. */
|
|
107
|
+
export declare function completionEntry(file: string, source: Provider, promptAt: string, stopAt: string, finalReply?: {
|
|
108
|
+
reply?: string;
|
|
109
|
+
truncated?: boolean;
|
|
110
|
+
}): Promise<string | undefined>;
|
|
87
111
|
/** Parse only the requested page; shared byte indexes make reopening and
|
|
88
112
|
* backward pagination independent of the amount of already-read history. */
|
|
89
113
|
export declare class TranscriptReader {
|
|
@@ -93,9 +117,25 @@ export declare class TranscriptReader {
|
|
|
93
117
|
private readonly changes?;
|
|
94
118
|
private readonly includeSidechain;
|
|
95
119
|
private readonly cwd?;
|
|
120
|
+
/** The phone delivery bound to each Claude queue row, by byte offset (PromptDeliveries). */
|
|
121
|
+
private readonly queueBindings?;
|
|
96
122
|
private revision?;
|
|
97
123
|
private nextLine;
|
|
98
|
-
|
|
124
|
+
private ambiguous;
|
|
125
|
+
constructor(file: string, source: Provider, imageLine?: number | undefined, changes?: ChangeLookup | undefined, includeSidechain?: boolean, cwd?: string | undefined,
|
|
126
|
+
/** The phone delivery bound to each Claude queue row, by byte offset (PromptDeliveries). */
|
|
127
|
+
queueBindings?: (() => Promise<Map<number, string> | undefined>) | undefined);
|
|
128
|
+
/** Prompt ids the latest page found ambiguous across the conversation. */
|
|
129
|
+
get ambiguousPromptIds(): ReadonlySet<string>;
|
|
130
|
+
/** A fresh opening page with the same reader options, for a reset after an
|
|
131
|
+
* identity already delivered by this stream became ambiguous. */
|
|
132
|
+
snapshot(signal?: AbortSignal): Promise<{
|
|
133
|
+
entries: Entry[];
|
|
134
|
+
totalLines: number;
|
|
135
|
+
startLine: number;
|
|
136
|
+
hasMore: boolean;
|
|
137
|
+
reset: boolean;
|
|
138
|
+
}>;
|
|
99
139
|
read(before?: number, signal?: AbortSignal): Promise<{
|
|
100
140
|
entries: Entry[];
|
|
101
141
|
totalLines: number;
|