@phren/cli 0.3.3 → 0.3.4
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-hooks.js +4 -3
- package/dist/bridge/model-switch.d.ts +4 -1
- package/dist/bridge/model-switch.js +7 -3
- package/dist/bridge/terminal-choice.d.ts +1 -5
- package/dist/bridge/terminal-choice.js +29 -0
- package/dist/bridge/transcript-preview.d.ts +5 -0
- package/dist/bridge/transcript-preview.js +51 -1
- package/dist/bridge-hook.mjs +63 -5
- package/package.json +1 -1
|
@@ -472,9 +472,10 @@ export class AgentHooks {
|
|
|
472
472
|
this.terminalPrompts.delete(key);
|
|
473
473
|
return;
|
|
474
474
|
}
|
|
475
|
-
// Codex draws "> 1. Yes, proceed (y)" rows
|
|
476
|
-
//
|
|
477
|
-
|
|
475
|
+
// Codex draws "> 1. Yes, proceed (y)" rows and Copilot a boxed select
|
|
476
|
+
// with a cursor row, both answered by moving to a row; the other
|
|
477
|
+
// fallbacks number rows without a key in the label.
|
|
478
|
+
const dialog = ["codex", "copilot"].includes(target.source) ? visibleTerminalChoice(text) : numberedDialog(text);
|
|
478
479
|
if (entry && !entry.dialog) {
|
|
479
480
|
// The permission the pane still shows after its hook let go: keep the
|
|
480
481
|
// request's own details and answer it with the dialog's rows, so the
|
|
@@ -2,8 +2,11 @@ import { AgentHooks } from "./agent-hooks.js";
|
|
|
2
2
|
import { ModelCatalog, type AgentModel } from "./models.js";
|
|
3
3
|
import { type Json, type Target } from "./protocol.js";
|
|
4
4
|
export declare const MODEL_BUSY = "This agent is working. The model switch can happen when the turn ends. Choose Switch after this turn.";
|
|
5
|
+
export declare const SLASH_BUSY = "This agent is working. Slash commands run between turns; send it again when this turn ends.";
|
|
5
6
|
/** Busy slash commands must never enter the harness's text queue. Claude's
|
|
6
|
-
* `/btw` side question is the one made to run beside a working turn.
|
|
7
|
+
* `/btw` side question is the one made to run beside a working turn. Only
|
|
8
|
+
* `/model` is told about the model switch; any other command (`/yolo`,
|
|
9
|
+
* `/compact`) is told it runs between turns. */
|
|
7
10
|
export declare function refuseWorkingSlash(pane: Json, text: string, source?: string): void;
|
|
8
11
|
/** The levels Claude Code's `/effort` takes (2.1.280) when the catalogue
|
|
9
12
|
* lists none for a model; Claude still refuses one the model lacks. */
|
|
@@ -6,13 +6,17 @@ import { BridgeError } from "./protocol.js";
|
|
|
6
6
|
import { sideQuestionText } from "./side-questions.js";
|
|
7
7
|
import { stripTerminal } from "../terminal-text.js";
|
|
8
8
|
export const MODEL_BUSY = "This agent is working. The model switch can happen when the turn ends. Choose Switch after this turn.";
|
|
9
|
+
export const SLASH_BUSY = "This agent is working. Slash commands run between turns; send it again when this turn ends.";
|
|
9
10
|
/** Busy slash commands must never enter the harness's text queue. Claude's
|
|
10
|
-
* `/btw` side question is the one made to run beside a working turn.
|
|
11
|
+
* `/btw` side question is the one made to run beside a working turn. Only
|
|
12
|
+
* `/model` is told about the model switch; any other command (`/yolo`,
|
|
13
|
+
* `/compact`) is told it runs between turns. */
|
|
11
14
|
export function refuseWorkingSlash(pane, text, source) {
|
|
12
15
|
if (source && sideQuestionText(source, text) !== undefined)
|
|
13
16
|
return;
|
|
14
|
-
if (pane.agent_status
|
|
15
|
-
|
|
17
|
+
if (pane.agent_status !== "working" || !/^\s*\//.test(text))
|
|
18
|
+
return;
|
|
19
|
+
throw new BridgeError(409, /^\s*\/model(?:\s|$)/.test(text) ? MODEL_BUSY : SLASH_BUSY);
|
|
16
20
|
}
|
|
17
21
|
const request = z.object({ model: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._\[\]:/-]{0,99}$/),
|
|
18
22
|
effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]).optional() });
|
|
@@ -15,11 +15,7 @@ export interface TerminalChoice {
|
|
|
15
15
|
options: TerminalChoiceOption[];
|
|
16
16
|
highlightedIndex?: number;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
* permission request carries: every non-empty line above the first numbered
|
|
20
|
-
* row (the "$ command" line included, the "Press enter" hint dropped), joined
|
|
21
|
-
* with newlines, then one option per row. Keyless rows require exactly one
|
|
22
|
-
* readable cursor so the Hook can navigate without confirming another row. */
|
|
18
|
+
export declare function unframed(text: string): string;
|
|
23
19
|
export declare function visibleTerminalChoice(text: string): TerminalChoice | undefined;
|
|
24
20
|
/** The pane's last non-empty line is a password read: sudo's "[sudo] password
|
|
25
21
|
* for user", or any "… Password:" prompt. */
|
|
@@ -92,7 +92,35 @@ function numberedOptions(text) {
|
|
|
92
92
|
* row (the "$ command" line included, the "Press enter" hint dropped), joined
|
|
93
93
|
* with newlines, then one option per row. Keyless rows require exactly one
|
|
94
94
|
* readable cursor so the Hook can navigate without confirming another row. */
|
|
95
|
+
/** Copilot CLI draws each select inside a box, so its rows read
|
|
96
|
+
* "│ ❯ 1. Yes │". Strip the frame (nested boxes too) so rows and the
|
|
97
|
+
* question read as bare lines. Inside a box the blank and border lines go,
|
|
98
|
+
* so the box's whole body (title, command, question) is one block above its
|
|
99
|
+
* options; the box's own edges become the blank lines around it. Text with
|
|
100
|
+
* no framed line passes through unchanged. */
|
|
101
|
+
const BAR = "│┃║";
|
|
102
|
+
const framed = new RegExp(`^\\s*[${BAR}] ?(.*?)\\s*[${BAR}]\\s*$`);
|
|
103
|
+
const border = /^[\s╭╮╰╯┌┐└┘├┤─━═│┃║]*$/;
|
|
104
|
+
export function unframed(text) {
|
|
105
|
+
let lines = text.split(/\r?\n/);
|
|
106
|
+
// Copilot's scrollbar: a "┃" closing most lines once the chat overflows.
|
|
107
|
+
const filled = lines.filter(line => line.trim());
|
|
108
|
+
if (filled.length && filled.filter(line => /┃\s*$/.test(line)).length * 2 > filled.length) {
|
|
109
|
+
lines = lines.map(line => line.replace(/\s*┃\s*$/, ""));
|
|
110
|
+
}
|
|
111
|
+
if (!lines.some(line => framed.test(line)))
|
|
112
|
+
return lines.join("\n");
|
|
113
|
+
return lines.flatMap(line => {
|
|
114
|
+
if (!framed.test(line))
|
|
115
|
+
return [border.test(line) ? "" : line];
|
|
116
|
+
let inner = line, match;
|
|
117
|
+
while ((match = framed.exec(inner)))
|
|
118
|
+
inner = match[1];
|
|
119
|
+
return border.test(inner) ? [] : [inner];
|
|
120
|
+
}).join("\n");
|
|
121
|
+
}
|
|
95
122
|
export function visibleTerminalChoice(text) {
|
|
123
|
+
text = unframed(text);
|
|
96
124
|
const parsed = numberedOptions(text);
|
|
97
125
|
const highlights = parsed.flatMap((option, index) => option.highlighted ? [index] : []);
|
|
98
126
|
const highlightedIndex = highlights.length === 1 ? highlights[0] : undefined;
|
|
@@ -136,6 +164,7 @@ export function passwordLine(text) {
|
|
|
136
164
|
* " · ", and a footer offering "Esc to cancel" gains the Escape option.
|
|
137
165
|
* Undefined without two numbered rows and a question. */
|
|
138
166
|
export function numberedDialog(text) {
|
|
167
|
+
text = unframed(text);
|
|
139
168
|
const row = /^\s*[>❯›▸▶»•*]?\s*(\d+)\.\s+(.+?)\s*$/;
|
|
140
169
|
const lines = text.split(/\r?\n/);
|
|
141
170
|
const first = lines.findIndex(line => row.test(line));
|
|
@@ -47,6 +47,11 @@ export declare function parseClaudeSpinnerLine(line: string): ClaudeSpinner | un
|
|
|
47
47
|
export declare function claudeSpinner(rendered: string): ClaudeSpinner | undefined;
|
|
48
48
|
/** The word Claude's own spinner shows ("✻ Pondering… (12s · esc to interrupt)"). */
|
|
49
49
|
export declare function claudeSpinnerVerb(rendered: string): string | undefined;
|
|
50
|
+
/** Copilot's reasoning state for the running turn, from the headers it draws
|
|
51
|
+
* above each reasoning block ("⌄ Thought for 16s", "Thinking" while it
|
|
52
|
+
* streams), newest below the turn's prompt line. Only the header is read:
|
|
53
|
+
* the reasoning under it ("│ …") never leaves the Hook. */
|
|
54
|
+
export declare function copilotThinking(rendered: string): ClaudeSpinner | undefined;
|
|
50
55
|
export declare function readPreviewPane(target: Target): Promise<string>;
|
|
51
56
|
/**
|
|
52
57
|
* One pane line as Markdown bold. Claude draws a reply's **bold** with SGR 1
|
|
@@ -223,6 +223,28 @@ export function claudeSpinner(rendered) {
|
|
|
223
223
|
export function claudeSpinnerVerb(rendered) {
|
|
224
224
|
return claudeSpinner(rendered)?.verb;
|
|
225
225
|
}
|
|
226
|
+
/** Copilot's reasoning state for the running turn, from the headers it draws
|
|
227
|
+
* above each reasoning block ("⌄ Thought for 16s", "Thinking" while it
|
|
228
|
+
* streams), newest below the turn's prompt line. Only the header is read:
|
|
229
|
+
* the reasoning under it ("│ …") never leaves the Hook. */
|
|
230
|
+
export function copilotThinking(rendered) {
|
|
231
|
+
// Copilot draws a scrollbar down the right edge once the chat overflows.
|
|
232
|
+
const lines = stripTerminal(rendered).split("\n").map(line => line.replace(/\s*┃\s*$/, ""));
|
|
233
|
+
let from = 0;
|
|
234
|
+
lines.forEach((line, index) => { if (/^\s*❯\s+(?!\d+[.)]\s)\S/.test(line))
|
|
235
|
+
from = index + 1; });
|
|
236
|
+
for (let i = lines.length - 1; i >= from; i--) {
|
|
237
|
+
const header = /^\s*[⌄⌃▾▸›>]?\s*(?:(Thinking)\b.*|Thought for (\S+))\s*$/.exec(lines[i]);
|
|
238
|
+
if (!header)
|
|
239
|
+
continue;
|
|
240
|
+
if (header[1])
|
|
241
|
+
return { verb: "Working", thinking: true };
|
|
242
|
+
const seconds = spinnerSeconds(header[2]);
|
|
243
|
+
if (seconds !== undefined)
|
|
244
|
+
return { verb: "Working", thinking: false, thoughtFor: seconds };
|
|
245
|
+
}
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
226
248
|
export function readPreviewPane(target) {
|
|
227
249
|
// With its styles: Claude's bold becomes Markdown; everything else strips.
|
|
228
250
|
return readPaneText(target.server, target.pane, { method: "agent.read", source: "visible", lines: 80, stripAnsi: false, format: "ansi", timeoutMs: 2_000, what: "Preview pane read" });
|
|
@@ -410,6 +432,23 @@ export class TranscriptPreviewStream {
|
|
|
410
432
|
this.ended = true;
|
|
411
433
|
continue;
|
|
412
434
|
}
|
|
435
|
+
if (this.target.source === "copilot") {
|
|
436
|
+
// A prompt starts the turn; idle or abort ends it (Copilot writes a
|
|
437
|
+
// turn_start/turn_end pair per model call, not per prompt).
|
|
438
|
+
if (raw.type === "user.message" && typeof raw.timestamp === "string") {
|
|
439
|
+
this.startedAt = raw.timestamp;
|
|
440
|
+
this.ended = false;
|
|
441
|
+
this.wasWorking = false;
|
|
442
|
+
this.verb = undefined;
|
|
443
|
+
this.activity = undefined;
|
|
444
|
+
}
|
|
445
|
+
else if (["session.idle", "abort"].includes(String(raw.type))) {
|
|
446
|
+
this.ended = true;
|
|
447
|
+
this.verb = undefined;
|
|
448
|
+
this.activity = undefined;
|
|
449
|
+
}
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
413
452
|
if (this.target.source !== "claude")
|
|
414
453
|
continue;
|
|
415
454
|
const message = object(raw.message), blocks = objects(message.content);
|
|
@@ -465,8 +504,19 @@ export class TranscriptPreviewStream {
|
|
|
465
504
|
if (text)
|
|
466
505
|
next = { turnStartedAt: this.startedAt, text };
|
|
467
506
|
}
|
|
507
|
+
else if (this.target.source === "copilot" && this.startedAt && !this.ended) {
|
|
508
|
+
// No reply text from the pane: only whether Copilot is thinking.
|
|
509
|
+
if (readAt - this.lastRead < PREVIEW_INTERVAL_MS)
|
|
510
|
+
return undefined;
|
|
511
|
+
this.lastRead = readAt;
|
|
512
|
+
const thinking = copilotThinking(await this.pane());
|
|
513
|
+
if (thinking) {
|
|
514
|
+
this.activity = thinking;
|
|
515
|
+
this.verb = thinking.verb;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
468
518
|
}
|
|
469
|
-
else if (this.target.source
|
|
519
|
+
else if (["claude", "copilot"].includes(this.target.source) && this.wasWorking) {
|
|
470
520
|
this.landed = true;
|
|
471
521
|
this.ended = true;
|
|
472
522
|
this.verb = undefined;
|
package/dist/bridge-hook.mjs
CHANGED
|
@@ -28275,7 +28275,7 @@ var init_package_metadata = __esm({
|
|
|
28275
28275
|
__dirname = path24.dirname(fileURLToPath2(import.meta.url));
|
|
28276
28276
|
ROOT = path24.join(__dirname, "..");
|
|
28277
28277
|
PACKAGE_JSON_PATH = path24.join(ROOT, "package.json");
|
|
28278
|
-
BUNDLED_VERSION = true ? "0.3.
|
|
28278
|
+
BUNDLED_VERSION = true ? "0.3.4" : "0.0.0";
|
|
28279
28279
|
PACKAGE_JSON = readPackageJson();
|
|
28280
28280
|
PACKAGE_NAME = PACKAGE_JSON.name || "phren";
|
|
28281
28281
|
VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
|
|
@@ -35027,7 +35027,25 @@ function numberedOptions(text3) {
|
|
|
35027
35027
|
}] : [];
|
|
35028
35028
|
});
|
|
35029
35029
|
}
|
|
35030
|
+
var BAR = "\u2502\u2503\u2551";
|
|
35031
|
+
var framed = new RegExp(`^\\s*[${BAR}] ?(.*?)\\s*[${BAR}]\\s*$`);
|
|
35032
|
+
var border = /^[\s╭╮╰╯┌┐└┘├┤─━═│┃║]*$/;
|
|
35033
|
+
function unframed(text3) {
|
|
35034
|
+
let lines = text3.split(/\r?\n/);
|
|
35035
|
+
const filled = lines.filter((line) => line.trim());
|
|
35036
|
+
if (filled.length && filled.filter((line) => /┃\s*$/.test(line)).length * 2 > filled.length) {
|
|
35037
|
+
lines = lines.map((line) => line.replace(/\s*┃\s*$/, ""));
|
|
35038
|
+
}
|
|
35039
|
+
if (!lines.some((line) => framed.test(line))) return lines.join("\n");
|
|
35040
|
+
return lines.flatMap((line) => {
|
|
35041
|
+
if (!framed.test(line)) return [border.test(line) ? "" : line];
|
|
35042
|
+
let inner = line, match;
|
|
35043
|
+
while (match = framed.exec(inner)) inner = match[1];
|
|
35044
|
+
return border.test(inner) ? [] : [inner];
|
|
35045
|
+
}).join("\n");
|
|
35046
|
+
}
|
|
35030
35047
|
function visibleTerminalChoice(text3) {
|
|
35048
|
+
text3 = unframed(text3);
|
|
35031
35049
|
const parsed = numberedOptions(text3);
|
|
35032
35050
|
const highlights = parsed.flatMap((option, index2) => option.highlighted ? [index2] : []);
|
|
35033
35051
|
const highlightedIndex = highlights.length === 1 ? highlights[0] : void 0;
|
|
@@ -35056,6 +35074,7 @@ function passwordLine(text3) {
|
|
|
35056
35074
|
return /password[^\n]*:\s*$/i.test(last);
|
|
35057
35075
|
}
|
|
35058
35076
|
function numberedDialog(text3) {
|
|
35077
|
+
text3 = unframed(text3);
|
|
35059
35078
|
const row = /^\s*[>❯›▸▶»•*]?\s*(\d+)\.\s+(.+?)\s*$/;
|
|
35060
35079
|
const lines = text3.split(/\r?\n/);
|
|
35061
35080
|
const first = lines.findIndex((line) => row.test(line));
|
|
@@ -35584,7 +35603,7 @@ var AgentHooks = class {
|
|
|
35584
35603
|
this.terminalPrompts.delete(key);
|
|
35585
35604
|
return;
|
|
35586
35605
|
}
|
|
35587
|
-
const dialog = target.source
|
|
35606
|
+
const dialog = ["codex", "copilot"].includes(target.source) ? visibleTerminalChoice(text3) : numberedDialog(text3);
|
|
35588
35607
|
if (entry && !entry.dialog) {
|
|
35589
35608
|
if (dialog?.title) {
|
|
35590
35609
|
entry.choice = dialog;
|
|
@@ -40470,9 +40489,11 @@ var SideQuestions = class {
|
|
|
40470
40489
|
|
|
40471
40490
|
// src/bridge/model-switch.ts
|
|
40472
40491
|
var MODEL_BUSY = "This agent is working. The model switch can happen when the turn ends. Choose Switch after this turn.";
|
|
40492
|
+
var SLASH_BUSY = "This agent is working. Slash commands run between turns; send it again when this turn ends.";
|
|
40473
40493
|
function refuseWorkingSlash(pane, text3, source) {
|
|
40474
40494
|
if (source && sideQuestionText(source, text3) !== void 0) return;
|
|
40475
|
-
if (pane.agent_status
|
|
40495
|
+
if (pane.agent_status !== "working" || !/^\s*\//.test(text3)) return;
|
|
40496
|
+
throw new BridgeError(409, /^\s*\/model(?:\s|$)/.test(text3) ? MODEL_BUSY : SLASH_BUSY);
|
|
40476
40497
|
}
|
|
40477
40498
|
var request5 = external_exports.object({
|
|
40478
40499
|
model: external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._\[\]:/-]{0,99}$/),
|
|
@@ -48038,6 +48059,21 @@ function claudeSpinner(rendered) {
|
|
|
48038
48059
|
}
|
|
48039
48060
|
return void 0;
|
|
48040
48061
|
}
|
|
48062
|
+
function copilotThinking(rendered) {
|
|
48063
|
+
const lines = stripTerminal(rendered).split("\n").map((line) => line.replace(/\s*┃\s*$/, ""));
|
|
48064
|
+
let from = 0;
|
|
48065
|
+
lines.forEach((line, index2) => {
|
|
48066
|
+
if (/^\s*❯\s+(?!\d+[.)]\s)\S/.test(line)) from = index2 + 1;
|
|
48067
|
+
});
|
|
48068
|
+
for (let i = lines.length - 1; i >= from; i--) {
|
|
48069
|
+
const header2 = /^\s*[⌄⌃▾▸›>]?\s*(?:(Thinking)\b.*|Thought for (\S+))\s*$/.exec(lines[i]);
|
|
48070
|
+
if (!header2) continue;
|
|
48071
|
+
if (header2[1]) return { verb: "Working", thinking: true };
|
|
48072
|
+
const seconds = spinnerSeconds(header2[2]);
|
|
48073
|
+
if (seconds !== void 0) return { verb: "Working", thinking: false, thoughtFor: seconds };
|
|
48074
|
+
}
|
|
48075
|
+
return void 0;
|
|
48076
|
+
}
|
|
48041
48077
|
function readPreviewPane(target) {
|
|
48042
48078
|
return readPaneText(
|
|
48043
48079
|
target.server,
|
|
@@ -48186,6 +48222,20 @@ var TranscriptPreviewStream = class {
|
|
|
48186
48222
|
else if (raw.type === "event_msg" && ["task_complete", "task_completed", "turn_aborted", "task_aborted"].includes(String(payload.type))) this.ended = true;
|
|
48187
48223
|
continue;
|
|
48188
48224
|
}
|
|
48225
|
+
if (this.target.source === "copilot") {
|
|
48226
|
+
if (raw.type === "user.message" && typeof raw.timestamp === "string") {
|
|
48227
|
+
this.startedAt = raw.timestamp;
|
|
48228
|
+
this.ended = false;
|
|
48229
|
+
this.wasWorking = false;
|
|
48230
|
+
this.verb = void 0;
|
|
48231
|
+
this.activity = void 0;
|
|
48232
|
+
} else if (["session.idle", "abort"].includes(String(raw.type))) {
|
|
48233
|
+
this.ended = true;
|
|
48234
|
+
this.verb = void 0;
|
|
48235
|
+
this.activity = void 0;
|
|
48236
|
+
}
|
|
48237
|
+
continue;
|
|
48238
|
+
}
|
|
48189
48239
|
if (this.target.source !== "claude") continue;
|
|
48190
48240
|
const message = object2(raw.message), blocks = objects(message.content);
|
|
48191
48241
|
if (raw.type === "user" && !raw.phrenQueued && !raw.isMeta && !blocks.some((b) => b.type === "tool_result")) {
|
|
@@ -48229,8 +48279,16 @@ var TranscriptPreviewStream = class {
|
|
|
48229
48279
|
this.verb = spinner.verb;
|
|
48230
48280
|
}
|
|
48231
48281
|
if (text3) next = { turnStartedAt: this.startedAt, text: text3 };
|
|
48282
|
+
} else if (this.target.source === "copilot" && this.startedAt && !this.ended) {
|
|
48283
|
+
if (readAt - this.lastRead < PREVIEW_INTERVAL_MS) return void 0;
|
|
48284
|
+
this.lastRead = readAt;
|
|
48285
|
+
const thinking = copilotThinking(await this.pane());
|
|
48286
|
+
if (thinking) {
|
|
48287
|
+
this.activity = thinking;
|
|
48288
|
+
this.verb = thinking.verb;
|
|
48289
|
+
}
|
|
48232
48290
|
}
|
|
48233
|
-
} else if (this.target.source
|
|
48291
|
+
} else if (["claude", "copilot"].includes(this.target.source) && this.wasWorking) {
|
|
48234
48292
|
this.landed = true;
|
|
48235
48293
|
this.ended = true;
|
|
48236
48294
|
this.verb = void 0;
|
|
@@ -49054,7 +49112,7 @@ async function readSecret(prompt) {
|
|
|
49054
49112
|
// src/bridge/hook-main.ts
|
|
49055
49113
|
init_utils_helpers();
|
|
49056
49114
|
Object.assign(process.env, nonInteractiveGitEnv());
|
|
49057
|
-
runBridge(process.argv.slice(2), "0.3.
|
|
49115
|
+
runBridge(process.argv.slice(2), "0.3.4").then((code) => {
|
|
49058
49116
|
process.exitCode = code;
|
|
49059
49117
|
}).catch((error62) => {
|
|
49060
49118
|
console.error(error62 instanceof Error ? error62.message : "Phren Hook failed.");
|