@phren/cli 0.3.3 → 0.3.5
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.d.ts +6 -0
- package/dist/bridge/agent-hooks.js +66 -25
- package/dist/bridge/canary.d.ts +4 -0
- package/dist/bridge/canary.js +17 -4
- package/dist/bridge/changes.d.ts +7 -0
- package/dist/bridge/changes.js +6 -1
- package/dist/bridge/client.js +2 -1
- package/dist/bridge/command.js +7 -5
- package/dist/bridge/conductor-group.d.ts +1 -0
- package/dist/bridge/conductor-group.js +4 -3
- package/dist/bridge/dispatch-command.js +2 -2
- package/dist/bridge/fanouts.js +6 -2
- package/dist/bridge/hand-off.d.ts +1 -0
- package/dist/bridge/hand-off.js +3 -2
- package/dist/bridge/harness-status.d.ts +12 -0
- package/dist/bridge/harness-status.js +153 -0
- package/dist/bridge/health.d.ts +18 -0
- package/dist/bridge/health.js +30 -4
- package/dist/bridge/herdr.d.ts +6 -0
- package/dist/bridge/herdr.js +62 -8
- package/dist/bridge/install.js +4 -0
- package/dist/bridge/model-switch.d.ts +4 -1
- package/dist/bridge/model-switch.js +12 -7
- package/dist/bridge/models.js +3 -2
- package/dist/bridge/pane-status.d.ts +37 -0
- package/dist/bridge/pane-status.js +139 -0
- package/dist/bridge/pane-text.d.ts +3 -11
- package/dist/bridge/pane-text.js +9 -16
- package/dist/bridge/peers.js +9 -6
- package/dist/bridge/prompt-once.d.ts +26 -0
- package/dist/bridge/prompt-once.js +69 -0
- package/dist/bridge/protocol.d.ts +10 -0
- package/dist/bridge/protocol.js +10 -0
- package/dist/bridge/schedule-format.d.ts +2 -0
- package/dist/bridge/schedule-launch.d.ts +10 -1
- package/dist/bridge/schedule-launch.js +29 -3
- package/dist/bridge/schedule-watch.js +1 -1
- package/dist/bridge/schedules.d.ts +10 -0
- package/dist/bridge/schedules.js +40 -0
- package/dist/bridge/server-launch.js +12 -10
- package/dist/bridge/server-pane-routes.js +23 -9
- package/dist/bridge/server-routes.d.ts +1 -0
- package/dist/bridge/server-routes.js +1 -1
- package/dist/bridge/session-servers.js +5 -6
- package/dist/bridge/side-questions.js +6 -5
- package/dist/bridge/terminal-choice.d.ts +12 -5
- package/dist/bridge/terminal-choice.js +66 -0
- package/dist/bridge/terminal-herdr.d.ts +5 -0
- package/dist/bridge/terminal-herdr.js +57 -0
- package/dist/bridge/terminal-tmux.d.ts +111 -0
- package/dist/bridge/terminal-tmux.js +549 -0
- package/dist/bridge/terminal.d.ts +119 -0
- package/dist/bridge/terminal.js +66 -0
- package/dist/bridge/transcript-claude.d.ts +6 -0
- package/dist/bridge/transcript-claude.js +20 -0
- package/dist/bridge/transcript-opencode.js +1 -1
- package/dist/bridge/transcript-preview.d.ts +5 -0
- package/dist/bridge/transcript-preview.js +52 -2
- package/dist/bridge/transport.js +10 -4
- package/dist/bridge-hook.mjs +4852 -3391
- package/dist/cli-registry.js +7 -0
- package/dist/entrypoint.js +2 -1
- package/dist/init/init.js +4 -0
- package/dist/link/doctor.js +33 -30
- package/dist/modules/agent-package.d.ts +35 -0
- package/dist/modules/agent-package.js +133 -0
- package/dist/modules/registry.js +2 -2
- package/dist/session/utils.js +1 -1
- package/dist/tools/dispatch.js +2 -2
- package/package.json +1 -1
- package/plugins/opencode/phren-transcript.js +97 -6
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// What the Hook needs from the terminal multiplexer its agents run in: Herdr
|
|
2
|
+
// (terminal-herdr.ts) or, on a computer without it, tmux (terminal-tmux.ts).
|
|
3
|
+
// Nothing Herdr- or tmux-specific may leak past a provider's own file.
|
|
4
|
+
//
|
|
5
|
+
// Identity (which conversation a pane runs) and agent status are not the
|
|
6
|
+
// provider's job. A multiplexer that knows them reports them as `hints`; one
|
|
7
|
+
// that does not leaves them out and the Hook falls back to lifecycle hooks
|
|
8
|
+
// and process logs.
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
import { herdrPaneFromEnv, herdrSocketPath } from "./herdr.js";
|
|
11
|
+
import { BridgeError } from "./protocol.js";
|
|
12
|
+
import { herdrTerminal } from "./terminal-herdr.js";
|
|
13
|
+
import { tmuxPaneFromEnv, tmuxSocketName, tmuxTerminal } from "./terminal-tmux.js";
|
|
14
|
+
/** The pane this process runs in, from the variables its multiplexer sets:
|
|
15
|
+
* inside Herdr only Herdr's pane counts, elsewhere a tmux pane does. */
|
|
16
|
+
export async function terminalPaneFromEnv(env = process.env) {
|
|
17
|
+
if (env.HERDR_ENV === "1")
|
|
18
|
+
return env.HERDR_SOCKET_PATH ? herdrPaneFromEnv(env) : undefined;
|
|
19
|
+
return tmuxPaneFromEnv(env);
|
|
20
|
+
}
|
|
21
|
+
/** Which multiplexer a Hook server name belongs to: "tmux" and "tmux-<socket>"
|
|
22
|
+
* are tmux servers unless Herdr has a session of that name; every other name
|
|
23
|
+
* is a Herdr server, exactly as before tmux support. */
|
|
24
|
+
export function terminalKind(server) {
|
|
25
|
+
if (!tmuxSocketName(server))
|
|
26
|
+
return "herdr";
|
|
27
|
+
try {
|
|
28
|
+
return existsSync(herdrSocketPath(server)) ? "herdr" : "tmux";
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return "tmux";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** The multiplexer's name as the phone shows it in messages. */
|
|
35
|
+
export function terminalName(server) { return terminalKind(server) === "tmux" ? "tmux" : "Herdr"; }
|
|
36
|
+
const route = (server) => terminalKind(server) === "tmux" ? tmuxTerminal : herdrTerminal;
|
|
37
|
+
/** The provider for each server by its name: Herdr's or tmux's. */
|
|
38
|
+
export const routedTerminal = {
|
|
39
|
+
kind: "routed",
|
|
40
|
+
ping: server => route(server).ping(server),
|
|
41
|
+
snapshot: server => route(server).snapshot(server),
|
|
42
|
+
listPanes: server => route(server).listPanes(server),
|
|
43
|
+
processes: (server, pane) => route(server).processes(server, pane),
|
|
44
|
+
readScreen: (server, pane, read) => route(server).readScreen(server, pane, read),
|
|
45
|
+
sendKeys: (server, pane, keys) => route(server).sendKeys(server, pane, keys),
|
|
46
|
+
prompt: (server, pane, text, signal) => route(server).prompt(server, pane, text, signal),
|
|
47
|
+
create: (server, placement) => route(server).create(server, placement),
|
|
48
|
+
startAgent: (server, pane, agent) => route(server).startAgent(server, pane, agent),
|
|
49
|
+
focusPane: (server, pane) => route(server).focusPane(server, pane),
|
|
50
|
+
groupAction: (server, operation, group, label) => route(server).groupAction(server, operation, group, label),
|
|
51
|
+
};
|
|
52
|
+
/** True when a start or prompt was refused because the agent is still
|
|
53
|
+
* starting (a folder-trust or login screen holds it). Herdr says so with its
|
|
54
|
+
* own error code; another provider with `code`. */
|
|
55
|
+
export function agentNotReady(error) {
|
|
56
|
+
return error instanceof BridgeError && (error.details?.code === "agent_not_ready" || error.details?.herdrCode === "agent_not_ready");
|
|
57
|
+
}
|
|
58
|
+
let current = routedTerminal;
|
|
59
|
+
/** The multiplexer the Hook drives: each call goes to its server's provider. */
|
|
60
|
+
export function terminalProvider() { return current; }
|
|
61
|
+
/** For tests: drive the Hook through `provider`; the returned function restores the previous one. */
|
|
62
|
+
export function setTerminalProvider(provider) {
|
|
63
|
+
const previous = current;
|
|
64
|
+
current = provider;
|
|
65
|
+
return () => { current = previous; };
|
|
66
|
+
}
|
|
@@ -13,6 +13,12 @@ export declare function unwrapPastedContent(text: string): string;
|
|
|
13
13
|
* signature is a length-prefixed field reading "narration" (private
|
|
14
14
|
* reasoning reads "thinking" and is stored without text). */
|
|
15
15
|
export declare function isNarration(block: Record<string, unknown>): boolean;
|
|
16
|
+
/** What a Skill call loaded. Claude Code answers the call itself with only
|
|
17
|
+
* "Launching skill: <name>" and writes the skill's text as a hidden user row
|
|
18
|
+
* pointing back at the call (`sourceToolUseID`). That row alone crosses, as a
|
|
19
|
+
* second result for the same call, so the phone can show what the skill said;
|
|
20
|
+
* every other hidden row stays private. */
|
|
21
|
+
export declare function skillBody(raw: Json): Json | undefined;
|
|
16
22
|
/** A phren UserPromptSubmit injection, as `{ type: "phren_hook_context",
|
|
17
23
|
* parentUuid, content }`, or undefined for any other row. */
|
|
18
24
|
export declare function phrenHookContext(raw: Json, includeSidechain?: boolean): Json | undefined;
|
|
@@ -256,6 +256,23 @@ export function isNarration(block) {
|
|
|
256
256
|
}
|
|
257
257
|
/** The largest injection the phone is sent; the hook's own budget keeps real ones far smaller. */
|
|
258
258
|
const HOOK_CONTEXT_LIMIT = 16_384;
|
|
259
|
+
const SKILL_BODY = "Base directory for this skill:";
|
|
260
|
+
/** What a Skill call loaded. Claude Code answers the call itself with only
|
|
261
|
+
* "Launching skill: <name>" and writes the skill's text as a hidden user row
|
|
262
|
+
* pointing back at the call (`sourceToolUseID`). That row alone crosses, as a
|
|
263
|
+
* second result for the same call, so the phone can show what the skill said;
|
|
264
|
+
* every other hidden row stays private. */
|
|
265
|
+
export function skillBody(raw) {
|
|
266
|
+
if (raw.type !== "user" || raw.isMeta !== true || raw.isSidechain || typeof raw.sourceToolUseID !== "string" || !raw.sourceToolUseID)
|
|
267
|
+
return undefined;
|
|
268
|
+
const content = object(raw.message).content;
|
|
269
|
+
const text = typeof content === "string" ? content
|
|
270
|
+
: objects(content).filter(block => block.type === "text").map(block => String(block.text ?? "")).join("\n");
|
|
271
|
+
if (!text.startsWith(SKILL_BODY))
|
|
272
|
+
return undefined;
|
|
273
|
+
return { type: "user", timestamp: raw.timestamp, ...(typeof raw.uuid === "string" ? { uuid: raw.uuid } : {}),
|
|
274
|
+
message: { role: "user", content: [{ type: "tool_result", tool_use_id: raw.sourceToolUseID, content: text.slice(0, 32_768), phrenSkillBody: true }] } };
|
|
275
|
+
}
|
|
259
276
|
/** A phren UserPromptSubmit injection, as `{ type: "phren_hook_context",
|
|
260
277
|
* parentUuid, content }`, or undefined for any other row. */
|
|
261
278
|
export function phrenHookContext(raw, includeSidechain = false) {
|
|
@@ -334,6 +351,9 @@ export function visibleClaudeEvent(raw, includeSidechain = false) {
|
|
|
334
351
|
const hookContext = phrenHookContext(raw, includeSidechain);
|
|
335
352
|
if (hookContext)
|
|
336
353
|
return hookContext;
|
|
354
|
+
const skill = skillBody(raw);
|
|
355
|
+
if (skill)
|
|
356
|
+
return skill;
|
|
337
357
|
if (raw.isMeta || (raw.isSidechain && !includeSidechain) || !["user", "assistant", "system"].includes(String(raw.type)))
|
|
338
358
|
return undefined;
|
|
339
359
|
raw = Object.fromEntries(Object.entries(raw).filter(([key]) => CLAUDE_KEYS.has(key)));
|
|
@@ -9,7 +9,7 @@ export function visibleOpencodeEvent(raw, source, cwd) {
|
|
|
9
9
|
if (runEvent)
|
|
10
10
|
return runEvent;
|
|
11
11
|
}
|
|
12
|
-
// phren-agent's event log (
|
|
12
|
+
// phren-agent's event log (packages/agent/src/session/log.ts): the
|
|
13
13
|
// header and log/replace splices are bookkeeping; the three message
|
|
14
14
|
// events are the conversation. Reasoning blocks stay on the computer.
|
|
15
15
|
if (!["user/message", "assistant/message", "tool/results"].includes(String(raw.type)))
|
|
@@ -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,9 +223,31 @@ 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
|
-
return readPaneText(target.server, target.pane, {
|
|
250
|
+
return readPaneText(target.server, target.pane, { scope: "agent", source: "visible", lines: 80, stripAnsi: false, format: "ansi", timeoutMs: 2_000, what: "Preview pane read" });
|
|
229
251
|
}
|
|
230
252
|
// An SGR sequence (captured) or any other control sequence stripTerminal removes.
|
|
231
253
|
const PANE_CONTROL = /\x1b\[([0-?]*)[ -/]*([@-~])|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\r/g;
|
|
@@ -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/transport.js
CHANGED
|
@@ -7,7 +7,8 @@ import { spawn } from "node:child_process";
|
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { BridgeError, object, PROTOCOL, serverName, socketPath, bridgeRoot, atomic } from "./protocol.js";
|
|
10
|
-
import {
|
|
10
|
+
import { terminalKind, terminalProvider } from "./terminal.js";
|
|
11
|
+
import { tmuxAttach } from "./terminal-tmux.js";
|
|
11
12
|
import { launchDirectory } from "./projects.js";
|
|
12
13
|
/** Decode the base64url project folder from a `phren-hook v1 shell` command; undefined when it is not a path. */
|
|
13
14
|
export function decodeShellDirectory(encoded) {
|
|
@@ -20,7 +21,7 @@ export function decodeShellDirectory(encoded) {
|
|
|
20
21
|
return path.isAbsolute(dir) && !/[\x00-\x1f\x7f]/.test(dir) && !dir.includes("\ufffd") ? dir : undefined;
|
|
21
22
|
}
|
|
22
23
|
export function shellEnvironment(base = process.env) {
|
|
23
|
-
const env = Object.fromEntries(Object.entries(base).filter(([key]) => !key.startsWith("HERDR_")));
|
|
24
|
+
const env = Object.fromEntries(Object.entries(base).filter(([key]) => !key.startsWith("HERDR_") && key !== "TMUX" && key !== "TMUX_PANE"));
|
|
24
25
|
env.PATH = [path.join(homedir(), ".local/bin"), "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].join(":");
|
|
25
26
|
return env;
|
|
26
27
|
}
|
|
@@ -122,13 +123,18 @@ export async function dispatch(command) {
|
|
|
122
123
|
}
|
|
123
124
|
const terminal = /^phren-hook v1 terminal ([A-Za-z0-9_.-]{1,100})$/.exec(command);
|
|
124
125
|
if (!terminal || terminal[0] !== command)
|
|
125
|
-
throw new BridgeError(403, "This SSH key only permits Phren Hook, loopback web previews, project shells, and existing Herdr terminals.");
|
|
126
|
+
throw new BridgeError(403, "This SSH key only permits Phren Hook, loopback web previews, project shells, and existing Herdr or tmux terminals.");
|
|
126
127
|
requireHook();
|
|
127
128
|
const server = serverName.parse(terminal[1]);
|
|
128
129
|
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
129
130
|
throw new Error("Request an SSH terminal first.");
|
|
130
131
|
// Verify the named server exists; never create a workspace or an agent implicitly.
|
|
131
|
-
await
|
|
132
|
+
await terminalProvider().ping(server);
|
|
133
|
+
if (terminalKind(server) === "tmux") {
|
|
134
|
+
const { file, args } = tmuxAttach(server);
|
|
135
|
+
await attach(file, args, { env: shellEnvironment() }, "The tmux terminal disconnected.");
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
132
138
|
await attach("herdr", ["session", "attach", server], { env: shellEnvironment() }, "The Herdr terminal disconnected.");
|
|
133
139
|
}
|
|
134
140
|
/** Run one program on the inherited SSH PTY until it exits or the session hangs up. */
|