@phren/cli 0.3.18 → 0.3.19
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 +5 -0
- package/dist/bridge/harnesses.d.ts +1 -1
- package/dist/bridge/harnesses.js +9 -2
- package/dist/bridge/health.d.ts +3 -2
- package/dist/bridge/health.js +4 -3
- package/dist/bridge/server-launch.js +15 -3
- package/dist/bridge/terminal-herdr.d.ts +7 -0
- package/dist/bridge/terminal-herdr.js +81 -7
- package/dist/bridge/terminal-tmux.js +2 -2
- package/dist/bridge/terminal.d.ts +3 -0
- package/dist/bridge/terminal.js +1 -0
- package/dist/bridge/transport.js +4 -3
- package/dist/bridge-hook.mjs +173 -103
- package/package.json +1 -1
|
@@ -1686,6 +1686,11 @@ export class AgentHooks {
|
|
|
1686
1686
|
const status = autoReview ? undefined : eventStatus(body.event);
|
|
1687
1687
|
if (status && typeof pane.terminal_id === "string")
|
|
1688
1688
|
notePaneStatus(target.server, target.pane, pane.terminal_id, status);
|
|
1689
|
+
// Herdr does not watch phren-agent: a pane the Hook reported as running
|
|
1690
|
+
// it (a phone launch) takes its status from these events.
|
|
1691
|
+
if (status && target.source === "phren" && pane.agent === "phren" && pane.agent_status !== status) {
|
|
1692
|
+
await terminalProvider().reportAgent?.(target.server, target.pane, "phren", status).catch(() => undefined);
|
|
1693
|
+
}
|
|
1689
1694
|
// What a shell call changed on disk: snapshot before, diff after.
|
|
1690
1695
|
const input = typeof body.input === "string" ? { patch: body.input } : object(body.input), command = [input.command, input.cmd].find(v => typeof v === "string");
|
|
1691
1696
|
// A shell call by name, or any tool whose input is a command line —
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AccountRef, type AuthRunner } from "./claude-accounts.js";
|
|
2
2
|
import { type ToolVersion } from "./health.js";
|
|
3
|
-
export type HarnessSource = "claude" | "codex" | "opencode" | "copilot";
|
|
3
|
+
export type HarnessSource = "claude" | "codex" | "opencode" | "copilot" | "phren";
|
|
4
4
|
export interface HarnessAccount extends AccountRef {
|
|
5
5
|
signedIn: boolean;
|
|
6
6
|
usable: boolean;
|
package/dist/bridge/harnesses.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
// What this computer can launch: each harness's install state and, for Claude and Codex, its accounts.
|
|
2
|
+
// `phren` is phren's own agent, run as `phren agent`; it needs no account here.
|
|
2
3
|
// Served as GET /v1/harnesses and as `harnesses` on /v1/dispatch/capacity. See docs/accounts.md.
|
|
3
4
|
import { existsSync } from "node:fs";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { codexHome } from "../home-paths.js";
|
|
6
7
|
import { claudeAccountRef, claudeAuthStatus, claudeHomes, CODEX_ACCOUNT } from "./claude-accounts.js";
|
|
7
8
|
import { toolVersion } from "./health.js";
|
|
8
|
-
const SOURCES = ["claude", "codex", "opencode", "copilot"];
|
|
9
|
+
const SOURCES = ["claude", "codex", "opencode", "copilot", "phren"];
|
|
10
|
+
/** The binary is `phren`; the agent answers `phren agent --version` from the separate @phren/agent package. */
|
|
11
|
+
const probeSource = (source) => source === "phren" ? toolVersion("phren agent", "phren", ["agent"]) : toolVersion(source);
|
|
9
12
|
export async function harnessInventory(deps = {}) {
|
|
10
13
|
const env = deps.env ?? process.env;
|
|
11
|
-
const probe = deps.toolVersion ??
|
|
14
|
+
const probe = deps.toolVersion ?? probeSource;
|
|
12
15
|
const harnesses = await Promise.all(SOURCES.map(async (source) => {
|
|
13
16
|
const found = await probe(source);
|
|
14
17
|
// Only a missing binary is definite; a slow or failing --version (a loaded computer) stays usable.
|
|
15
18
|
if (found.status === "missing")
|
|
16
19
|
return { source, installed: false, usable: false, reason: "Not installed" };
|
|
20
|
+
// `phren agent` without @phren/agent prints an install hint and no version.
|
|
21
|
+
if (source === "phren" && found.status === "error" && found.detail?.startsWith("--version exited")) {
|
|
22
|
+
return { source, installed: false, usable: false, reason: "Not installed: npm install -g @phren/agent" };
|
|
23
|
+
}
|
|
17
24
|
const base = { source, installed: true, ...(found.version ? { version: found.version } : {}) };
|
|
18
25
|
if (source === "claude") {
|
|
19
26
|
const accounts = await Promise.all(claudeHomes(env).map(async (home) => {
|
package/dist/bridge/health.d.ts
CHANGED
|
@@ -114,8 +114,9 @@ export interface HealthOptions {
|
|
|
114
114
|
devices: number;
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
/** `<tool> --version`, bounded to 3 seconds and remembered for 5 minutes.
|
|
118
|
-
|
|
117
|
+
/** `<tool> --version`, bounded to 3 seconds and remembered for 5 minutes. `args` come
|
|
118
|
+
* before `--version` for a tool behind a subcommand (`phren agent --version`). */
|
|
119
|
+
export declare function toolVersion(tool: string, executable?: string, args?: string[]): Promise<ToolVersion>;
|
|
119
120
|
/** Only for tests: forget cached versions. */
|
|
120
121
|
export declare function clearVersionCache(): void;
|
|
121
122
|
/** Branch and ahead/behind against the upstream as last fetched; nothing is fetched here. */
|
package/dist/bridge/health.js
CHANGED
|
@@ -38,14 +38,15 @@ const VERSION_TIMEOUT_MS = 3_000;
|
|
|
38
38
|
const VERSION_CACHE_MS = 5 * 60_000;
|
|
39
39
|
const PEER_TIMEOUT_MS = 5_000;
|
|
40
40
|
const versionCache = new Map();
|
|
41
|
-
/** `<tool> --version`, bounded to 3 seconds and remembered for 5 minutes.
|
|
42
|
-
|
|
41
|
+
/** `<tool> --version`, bounded to 3 seconds and remembered for 5 minutes. `args` come
|
|
42
|
+
* before `--version` for a tool behind a subcommand (`phren agent --version`). */
|
|
43
|
+
export function toolVersion(tool, executable = tool, args = []) {
|
|
43
44
|
const cached = versionCache.get(tool);
|
|
44
45
|
if (cached && Date.now() - cached.at < VERSION_CACHE_MS)
|
|
45
46
|
return cached.value;
|
|
46
47
|
const value = new Promise(resolve => {
|
|
47
48
|
let out = "", done = false;
|
|
48
|
-
const child = spawn(executable, ["--version"], { cwd: homedir(), stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, NO_COLOR: "1" } });
|
|
49
|
+
const child = spawn(executable, [...args, "--version"], { cwd: homedir(), stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, NO_COLOR: "1" } });
|
|
49
50
|
const finish = (result) => { if (!done) {
|
|
50
51
|
done = true;
|
|
51
52
|
clearTimeout(timer);
|
|
@@ -28,7 +28,7 @@ import { atomic, BridgeError, bridgeRoot, id, launchEfforts, objects, PERMISSION
|
|
|
28
28
|
import { CLAUDE_NAMES, CODEX_MODES, codexModeFlags } from "./settings-switch.js";
|
|
29
29
|
/** Starting agents in Herdr from the phone: the launch route's harness
|
|
30
30
|
* arguments, the conductor brief, and workspace, tab and pane actions. */
|
|
31
|
-
const launchKinds = ["codex", "claude", "copilot", "opencode"];
|
|
31
|
+
const launchKinds = ["codex", "claude", "copilot", "opencode", "phren"];
|
|
32
32
|
const plainText = (max) => z.string().min(1).max(max).refine(t => !/[\x00-\x1f\x7f]/.test(t));
|
|
33
33
|
async function conductorBrief() {
|
|
34
34
|
let source;
|
|
@@ -61,8 +61,13 @@ function effortArgs(kind, effort) {
|
|
|
61
61
|
return ["-c", `model_reasoning_effort=${effort}`];
|
|
62
62
|
if (kind === "opencode")
|
|
63
63
|
return ["--variant", effort];
|
|
64
|
+
// phren-agent takes low to xhigh, and max as xhigh.
|
|
65
|
+
if (kind === "phren")
|
|
66
|
+
return ["--reasoning", effort === "minimal" ? "low" : effort];
|
|
64
67
|
return [];
|
|
65
68
|
}
|
|
69
|
+
/** phren's own agent runs as `phren agent`: the subcommand and its interactive TUI lead its arguments. */
|
|
70
|
+
const PHREN_AGENT_ARGS = ["agent", "-i"];
|
|
66
71
|
async function prepareConductor(kind, effort, model) {
|
|
67
72
|
const brief = await conductorBrief();
|
|
68
73
|
const briefDirectory = path.join(bridgeRoot(), "conductor");
|
|
@@ -138,6 +143,7 @@ async function requireNoConductor(server, before, except) {
|
|
|
138
143
|
}
|
|
139
144
|
/** The phone names the pane's workspace and tab too; the CLI may know only the pane. */
|
|
140
145
|
const paneRequest = z.object({ workspaceId: id.optional(), tabId: id.optional(), paneId: id }).strict();
|
|
146
|
+
const PHREN_NO_CONDUCTOR = "phren agent cannot run as a conductor: it takes no system brief at startup.";
|
|
141
147
|
/** "Make conductor": the owner gives an agent already running in a pane on this computer the role. */
|
|
142
148
|
export async function makeConductor(server, data) {
|
|
143
149
|
const place = paneRequest.parse(data);
|
|
@@ -150,6 +156,8 @@ export async function makeConductor(server, data) {
|
|
|
150
156
|
throw new BridgeError(409, "No agent is running in this pane.");
|
|
151
157
|
if (pane.agent === "copilot")
|
|
152
158
|
throw new BridgeError(400, "Copilot cannot run as a conductor.");
|
|
159
|
+
if (pane.agent === "phren")
|
|
160
|
+
throw new BridgeError(400, PHREN_NO_CONDUCTOR);
|
|
153
161
|
const unchecked = await requireNoConductor(server, before, place.paneId);
|
|
154
162
|
const target = await targetForPane(server, pane);
|
|
155
163
|
await recordConductor(server, pane, "owner", typeof target?.session === "string" ? target.session : undefined);
|
|
@@ -239,8 +247,12 @@ export async function launchSession(server, data, options = {}) {
|
|
|
239
247
|
throw new BridgeError(400, "OpenCode takes its permissions from its own config; permissionMode is for Claude and Codex workers.");
|
|
240
248
|
if (permissionMode && kind === "copilot")
|
|
241
249
|
throw new BridgeError(400, "Copilot takes its permissions from its own settings; permissionMode is for Claude and Codex workers.");
|
|
250
|
+
if (permissionMode && kind === "phren")
|
|
251
|
+
throw new BridgeError(400, "phren agent takes its permissions from its own settings; permissionMode is for Claude and Codex workers.");
|
|
242
252
|
if (role === "conductor" && kind === "copilot")
|
|
243
253
|
throw new BridgeError(400, "Copilot cannot run as a conductor.");
|
|
254
|
+
if (role === "conductor" && kind === "phren")
|
|
255
|
+
throw new BridgeError(400, PHREN_NO_CONDUCTOR);
|
|
244
256
|
// A dispatched worker's or scheduled run's first prompt. It rides on the
|
|
245
257
|
// launch where the harness takes one; elsewhere the caller types it.
|
|
246
258
|
const brief = data.brief === undefined || data.brief === null ? undefined : launchBriefSchema.parse(data.brief);
|
|
@@ -257,7 +269,7 @@ export async function launchSession(server, data, options = {}) {
|
|
|
257
269
|
const wanted = options.canary ? "phren-canary" : role === "conductor" ? (isConductorName(baseName) ? baseName : herdrAgentName(`conductor-${baseName}`))
|
|
258
270
|
: isConductorName(baseName) ? herdrAgentName(`worker-${baseName}`) : baseName;
|
|
259
271
|
const model = typeof data.model === "string" && data.model.trim() ? plainText(200).parse(data.model.trim()) : undefined;
|
|
260
|
-
const modelFlag = { codex: "--model", claude: "--model", opencode: "--model" };
|
|
272
|
+
const modelFlag = { codex: "--model", claude: "--model", opencode: "--model", phren: "--model" };
|
|
261
273
|
let workspace = data.workspaceId === undefined ? undefined : id.parse(data.workspaceId);
|
|
262
274
|
// Herdr 0.9.1 refuses a start timeout of 3000 ms or less (invalid_agent_timeout).
|
|
263
275
|
const timeout = Math.min(120_000, Math.max(3_001, data.timeoutMs === undefined ? 45_000 : z.number().int().parse(data.timeoutMs)));
|
|
@@ -281,7 +293,7 @@ export async function launchSession(server, data, options = {}) {
|
|
|
281
293
|
if (conductorHere && conductorHere.workspace_id === workspace)
|
|
282
294
|
workspace = undefined;
|
|
283
295
|
const args = role === "conductor" ? await prepareConductor(kind, effort, model)
|
|
284
|
-
: [...(model && modelFlag[kind] ? [modelFlag[kind], model] : []), ...(data.effort === undefined ? [] : effortArgs(kind, effort)),
|
|
296
|
+
: [...(kind === "phren" ? PHREN_AGENT_ARGS : []), ...(model && modelFlag[kind] ? [modelFlag[kind], model] : []), ...(data.effort === undefined ? [] : effortArgs(kind, effort)),
|
|
285
297
|
...(permissionMode && kind === "claude" ? ["--permission-mode", CLAUDE_NAMES[permissionMode]] : []), ...(permissionMode && kind === "codex" ? codexModeFlags(permissionMode) : [])];
|
|
286
298
|
// A Codex worker runs on a Phren-owned app-server (codex-servers.ts): the
|
|
287
299
|
// pane joins the thread the Hook started, and the brief is that thread's
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { type Json } from "./protocol.js";
|
|
2
2
|
import type { TerminalPane, TerminalProvider } from "./terminal.js";
|
|
3
|
+
/** Who reports phren-agent's lifecycle to Herdr, which does not detect it itself. */
|
|
4
|
+
export declare const PHREN_REPORT_SOURCE = "phren-hook";
|
|
5
|
+
/** A word for a POSIX shell, quoted only when it needs it. */
|
|
6
|
+
export declare function shellWord(word: string): string;
|
|
7
|
+
/** What the Hook types into a Herdr pane's shell to start phren-agent:
|
|
8
|
+
* the agent, then Herdr's report of it released once it exits. */
|
|
9
|
+
export declare function phrenCommandLine(args: string[]): string;
|
|
3
10
|
/** A Herdr snapshot's panes in the provider's shape; Herdr's agent report becomes hints. */
|
|
4
11
|
export declare function herdrPanes(server: string, s: Json): TerminalPane[];
|
|
5
12
|
export declare const herdrTerminal: TerminalProvider;
|
|
@@ -3,8 +3,55 @@
|
|
|
3
3
|
// fake, so a test that records Herdr requests sees exactly what it did before
|
|
4
4
|
// the provider existed.
|
|
5
5
|
import { herdrSocketPath, rpc, snapshot } from "./herdr.js";
|
|
6
|
-
import { object, objects } from "./protocol.js";
|
|
6
|
+
import { BridgeError, object, objects } from "./protocol.js";
|
|
7
|
+
import { agentFromCommand } from "./terminal-tmux.js";
|
|
7
8
|
const text = (value) => typeof value === "string" && value ? value : undefined;
|
|
9
|
+
/** Who reports phren-agent's lifecycle to Herdr, which does not detect it itself. */
|
|
10
|
+
export const PHREN_REPORT_SOURCE = "phren-hook";
|
|
11
|
+
/** A word for a POSIX shell, quoted only when it needs it. */
|
|
12
|
+
export function shellWord(word) {
|
|
13
|
+
return /^[A-Za-z0-9_./:=@%+,-]+$/.test(word) ? word : `'${word.replace(/'/g, `'\\''`)}'`;
|
|
14
|
+
}
|
|
15
|
+
/** What the Hook types into a Herdr pane's shell to start phren-agent:
|
|
16
|
+
* the agent, then Herdr's report of it released once it exits. */
|
|
17
|
+
export function phrenCommandLine(args) {
|
|
18
|
+
return [["phren", ...args].map(shellWord).join(" "),
|
|
19
|
+
`herdr pane release-agent "$HERDR_PANE_ID" --source ${PHREN_REPORT_SOURCE} --agent phren >/dev/null 2>&1`].join("; ");
|
|
20
|
+
}
|
|
21
|
+
/** Whether `pane` runs phren-agent as Herdr reports it, for the prompt and key fallbacks below. */
|
|
22
|
+
async function reportedPhren(server, pane) {
|
|
23
|
+
const info = object((await rpc(server, "pane.get", { pane_id: pane }).catch(() => ({}))).pane);
|
|
24
|
+
return info.agent === "phren";
|
|
25
|
+
}
|
|
26
|
+
/** Herdr's `agent.prompt` and `agent.send_keys` take only agents it started;
|
|
27
|
+
* a phren-agent pane it knows by report gets the pane calls instead. */
|
|
28
|
+
function unnamedAgent(error) {
|
|
29
|
+
return error instanceof BridgeError && error.details?.herdrCode === "agent_not_ready" && /not an active named agent/.test(error.message);
|
|
30
|
+
}
|
|
31
|
+
/** Herdr's `agent.start` knows a fixed list of harnesses and phren-agent is
|
|
32
|
+
* not on it. The Hook types `phren agent ...` at the pane's login shell
|
|
33
|
+
* instead, waits for it to be the foreground program, then reports it to
|
|
34
|
+
* Herdr as agent "phren" under the launch name, so the pane reads as an agent
|
|
35
|
+
* like the others. Its own lifecycle hooks keep the status (agent-hooks.ts). */
|
|
36
|
+
async function startPhren(server, pane, { name, args, timeoutMs }) {
|
|
37
|
+
const before = object((await rpc(server, "pane.process_info", { pane_id: pane })).process_info);
|
|
38
|
+
// Same refusal as Herdr's own start, so the caller waits for the shell.
|
|
39
|
+
if (!Number.isSafeInteger(before.shell_pid) || before.foreground_process_group_id !== before.shell_pid)
|
|
40
|
+
throw new BridgeError(409, `Herdr: agent target pane ${pane} is not an available shell`, { herdrCode: "agent_pane_busy" });
|
|
41
|
+
await rpc(server, "pane.send_text", { pane_id: pane, text: phrenCommandLine(args) });
|
|
42
|
+
await rpc(server, "pane.send_keys", { pane_id: pane, keys: ["Enter"] });
|
|
43
|
+
const deadline = Date.now() + Math.min(timeoutMs, 30_000);
|
|
44
|
+
for (;;) {
|
|
45
|
+
const info = object((await rpc(server, "pane.process_info", { pane_id: pane })).process_info);
|
|
46
|
+
if (objects(info.foreground_processes).some(p => typeof p.cmdline === "string" && agentFromCommand(p.cmdline) === "phren"))
|
|
47
|
+
break;
|
|
48
|
+
if (Date.now() >= deadline)
|
|
49
|
+
throw new BridgeError(504, "phren agent did not start in the Herdr pane. Check that phren and @phren/agent are installed on the login shell's PATH.");
|
|
50
|
+
await new Promise(resolve => setTimeout(resolve, 250));
|
|
51
|
+
}
|
|
52
|
+
await rpc(server, "pane.report_agent", { pane_id: pane, source: PHREN_REPORT_SOURCE, agent: "phren", state: "idle" });
|
|
53
|
+
await rpc(server, "agent.rename", { target: pane, name }).catch(() => undefined);
|
|
54
|
+
}
|
|
8
55
|
/** A Herdr snapshot's panes in the provider's shape; Herdr's agent report becomes hints. */
|
|
9
56
|
export function herdrPanes(server, s) {
|
|
10
57
|
return objects(s.panes).filter(p => typeof p.pane_id === "string" && typeof p.tab_id === "string" && typeof p.workspace_id === "string").map(p => {
|
|
@@ -36,18 +83,42 @@ export const herdrTerminal = {
|
|
|
36
83
|
const answer = object(result.read ?? result);
|
|
37
84
|
return typeof answer.text === "string" ? answer.text : "";
|
|
38
85
|
},
|
|
39
|
-
async sendKeys(server, pane, keys) {
|
|
86
|
+
async sendKeys(server, pane, keys) {
|
|
87
|
+
try {
|
|
88
|
+
await rpc(server, "agent.send_keys", { target: pane, keys });
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (!unnamedAgent(error) || !await reportedPhren(server, pane))
|
|
92
|
+
throw error;
|
|
93
|
+
await rpc(server, "pane.send_keys", { pane_id: pane, keys });
|
|
94
|
+
}
|
|
95
|
+
},
|
|
40
96
|
async prompt(server, pane, text, signal) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
97
|
+
try {
|
|
98
|
+
if (signal)
|
|
99
|
+
await rpc(server, "agent.prompt", { target: pane, text }, signal);
|
|
100
|
+
else
|
|
101
|
+
await rpc(server, "agent.prompt", { target: pane, text });
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (!unnamedAgent(error) || !await reportedPhren(server, pane))
|
|
105
|
+
throw error;
|
|
106
|
+
// One bracketed paste keeps the newlines in phren-agent's composer; Enter submits it.
|
|
107
|
+
await rpc(server, "pane.send_text", { pane_id: pane, text: `\x1b[200~${text}\x1b[201~` }, signal);
|
|
108
|
+
await new Promise(resolve => setTimeout(resolve, 150));
|
|
109
|
+
await rpc(server, "pane.send_keys", { pane_id: pane, keys: ["Enter"] }, signal);
|
|
110
|
+
}
|
|
45
111
|
},
|
|
46
112
|
async create(server, { workspace, label, cwd, env }) {
|
|
47
113
|
await rpc(server, workspace ? "tab.create" : "workspace.create", { workspace_id: workspace, label, cwd, focus: false, env: env ?? {} });
|
|
48
114
|
},
|
|
49
115
|
// `agent.start` takes no environment; the pane's shell got it at `create`.
|
|
50
|
-
async startAgent(server, pane,
|
|
116
|
+
async startAgent(server, pane, agent) {
|
|
117
|
+
const { name, kind, args, timeoutMs } = agent;
|
|
118
|
+
if (kind === "phren") {
|
|
119
|
+
await startPhren(server, pane, agent);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
51
122
|
// Herdr waits up to `timeout_ms` for the agent to become ready; the socket waits a little longer.
|
|
52
123
|
await rpc(server, "agent.start", { name, kind, pane_id: pane, timeout_ms: timeoutMs, ...(args.length ? { args } : {}) }, undefined, timeoutMs + 5_000);
|
|
53
124
|
},
|
|
@@ -55,6 +126,9 @@ export const herdrTerminal = {
|
|
|
55
126
|
paneEnv(server, { workspace, tab, pane }) {
|
|
56
127
|
return { HERDR_ENV: "1", HERDR_SOCKET_PATH: herdrSocketPath(server), HERDR_WORKSPACE_ID: workspace, HERDR_TAB_ID: tab, HERDR_PANE_ID: pane };
|
|
57
128
|
},
|
|
129
|
+
async reportAgent(server, pane, agent, state) {
|
|
130
|
+
await rpc(server, "pane.report_agent", { pane_id: pane, source: PHREN_REPORT_SOURCE, agent, state });
|
|
131
|
+
},
|
|
58
132
|
async focusPane(server, pane) { await rpc(server, "pane.focus", { pane_id: pane }); },
|
|
59
133
|
async closePane(server, pane) { await rpc(server, "pane.close", { pane_id: pane }); },
|
|
60
134
|
async renamePane(server, pane, label) { await rpc(server, "pane.rename", { pane_id: pane, label }); },
|
|
@@ -208,7 +208,7 @@ export function agentFromCommand(command) {
|
|
|
208
208
|
return "phren";
|
|
209
209
|
// `phren agent` runs the same agent through the CLI.
|
|
210
210
|
const next = words[words.indexOf(program) + 1];
|
|
211
|
-
if ((name === "phren" || program.includes("@phren/cli/")) && next === "agent")
|
|
211
|
+
if ((name === "phren" || program.includes("@phren/cli/") || /\/packages\/cli\/dist\/index\.js$/.test(program)) && next === "agent")
|
|
212
212
|
return "phren";
|
|
213
213
|
return undefined;
|
|
214
214
|
}
|
|
@@ -437,7 +437,7 @@ export const tmuxTerminal = {
|
|
|
437
437
|
await tmux(server, ["new-session", "-d", "-s", sessionName(label, taken), "-x", "200", "-y", "50", ...directory, ...name]);
|
|
438
438
|
},
|
|
439
439
|
async startAgent(server, pane, { name, kind, args, timeoutMs, env }) {
|
|
440
|
-
if (!["claude", "codex", "copilot", "opencode"].includes(kind))
|
|
440
|
+
if (!["claude", "codex", "copilot", "opencode", "phren"].includes(kind))
|
|
441
441
|
throw new BridgeError(400, "This agent cannot be started in tmux.");
|
|
442
442
|
await requireDirectExec();
|
|
443
443
|
const target = toTmuxId(pane, "p"), row = await paneRow(server, target);
|
|
@@ -109,6 +109,9 @@ export interface TerminalProvider {
|
|
|
109
109
|
tab: string;
|
|
110
110
|
pane: string;
|
|
111
111
|
}): Record<string, string> | undefined;
|
|
112
|
+
/** Tells a multiplexer that watches its agents what one it cannot detect
|
|
113
|
+
* (phren-agent in Herdr) is doing. Absent where the Hook keeps that itself (tmux). */
|
|
114
|
+
reportAgent?(server: string, pane: string, agent: string, state: "idle" | "working" | "blocked"): Promise<void>;
|
|
112
115
|
focusPane(server: string, pane: string): Promise<void>;
|
|
113
116
|
/** Sets the pane's own label (Herdr's pane label, a tmux pane option), shown by the Hook as the session's name. */
|
|
114
117
|
closePane(server: string, pane: string): Promise<void>;
|
package/dist/bridge/terminal.js
CHANGED
|
@@ -52,6 +52,7 @@ export const routedTerminal = {
|
|
|
52
52
|
create: (server, placement) => route(server).create(server, placement),
|
|
53
53
|
startAgent: (server, pane, agent) => route(server).startAgent(server, pane, agent),
|
|
54
54
|
paneEnv: (server, place) => route(server).paneEnv?.(server, place),
|
|
55
|
+
reportAgent: async (server, pane, agent, state) => { await route(server).reportAgent?.(server, pane, agent, state); },
|
|
55
56
|
focusPane: (server, pane) => route(server).focusPane(server, pane),
|
|
56
57
|
closePane: (server, pane) => route(server).closePane(server, pane),
|
|
57
58
|
renamePane: (server, pane, label) => route(server).renamePane(server, pane, label),
|
package/dist/bridge/transport.js
CHANGED
|
@@ -107,7 +107,7 @@ export async function dispatch(command) {
|
|
|
107
107
|
}
|
|
108
108
|
// Without Herdr: a login shell, or one agent, in a validated project folder
|
|
109
109
|
// on the SSH PTY itself. Nothing persists after the phone disconnects.
|
|
110
|
-
const shell = /^phren-hook v1 shell ([A-Za-z0-9_-]{1,8192})(?: (codex|claude|copilot|opencode))?$/.exec(command);
|
|
110
|
+
const shell = /^phren-hook v1 shell ([A-Za-z0-9_-]{1,8192})(?: (codex|claude|copilot|opencode|phren))?$/.exec(command);
|
|
111
111
|
if (shell && shell[0] === command) {
|
|
112
112
|
requireHook();
|
|
113
113
|
const raw = decodeShellDirectory(shell[1]);
|
|
@@ -117,8 +117,9 @@ export async function dispatch(command) {
|
|
|
117
117
|
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
118
118
|
throw new Error("Request an SSH terminal first.");
|
|
119
119
|
const login = process.env.SHELL && path.isAbsolute(process.env.SHELL) ? process.env.SHELL : "/bin/sh";
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
// phren's own agent is the `phren agent` subcommand, in its interactive TUI.
|
|
121
|
+
const [file, args] = shell[2] === "phren" ? ["phren", ["agent", "-i"]] : shell[2] ? [shell[2], []] : [login, ["-l"]];
|
|
122
|
+
await attach(file, args, { cwd, env: shellEnvironment() }, shell[2] === "phren" ? "phren agent exited." : shell[2] ? `${shell[2]} exited.` : "The shell exited.");
|
|
122
123
|
return;
|
|
123
124
|
}
|
|
124
125
|
const terminal = /^phren-hook v1 terminal ([A-Za-z0-9_.-]{1,100})$/.exec(command);
|
package/dist/bridge-hook.mjs
CHANGED
|
@@ -25349,7 +25349,7 @@ var init_package_metadata = __esm({
|
|
|
25349
25349
|
__dirname = path15.dirname(fileURLToPath2(import.meta.url));
|
|
25350
25350
|
ROOT = path15.join(__dirname, "..");
|
|
25351
25351
|
PACKAGE_JSON_PATH = path15.join(ROOT, "package.json");
|
|
25352
|
-
BUNDLED_VERSION = true ? "0.3.
|
|
25352
|
+
BUNDLED_VERSION = true ? "0.3.19" : "0.0.0";
|
|
25353
25353
|
PACKAGE_JSON = readPackageJson();
|
|
25354
25354
|
PACKAGE_NAME = PACKAGE_JSON.name || "phren";
|
|
25355
25355
|
VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
|
|
@@ -34199,96 +34199,6 @@ ${pane}`;
|
|
|
34199
34199
|
}
|
|
34200
34200
|
});
|
|
34201
34201
|
|
|
34202
|
-
// src/bridge/terminal-herdr.ts
|
|
34203
|
-
function herdrPanes(server, s) {
|
|
34204
|
-
return objects(s.panes).filter((p) => typeof p.pane_id === "string" && typeof p.tab_id === "string" && typeof p.workspace_id === "string").map((p) => {
|
|
34205
|
-
const reported = object2(p.agent_session);
|
|
34206
|
-
const session = reported.kind === "id" && reported.agent === p.agent ? text(reported.value) : void 0;
|
|
34207
|
-
const hints = { agent: text(p.agent), status: text(p.agent_status), session };
|
|
34208
|
-
return {
|
|
34209
|
-
server,
|
|
34210
|
-
workspace: String(p.workspace_id),
|
|
34211
|
-
tab: String(p.tab_id),
|
|
34212
|
-
pane: String(p.pane_id),
|
|
34213
|
-
cwd: text(p.foreground_cwd) ?? text(p.cwd),
|
|
34214
|
-
title: text(p.title) ?? text(p.terminal_title_stripped),
|
|
34215
|
-
label: text(p.label),
|
|
34216
|
-
...hints.agent || hints.status || hints.session ? { hints } : {}
|
|
34217
|
-
};
|
|
34218
|
-
});
|
|
34219
|
-
}
|
|
34220
|
-
var text, herdrTerminal;
|
|
34221
|
-
var init_terminal_herdr = __esm({
|
|
34222
|
-
"src/bridge/terminal-herdr.ts"() {
|
|
34223
|
-
"use strict";
|
|
34224
|
-
init_herdr();
|
|
34225
|
-
init_protocol();
|
|
34226
|
-
text = (value2) => typeof value2 === "string" && value2 ? value2 : void 0;
|
|
34227
|
-
herdrTerminal = {
|
|
34228
|
-
kind: "herdr",
|
|
34229
|
-
async ping(server) {
|
|
34230
|
-
await rpc(server, "ping");
|
|
34231
|
-
},
|
|
34232
|
-
async snapshot(server) {
|
|
34233
|
-
return object2((await rpc(server, "session.snapshot")).snapshot);
|
|
34234
|
-
},
|
|
34235
|
-
async listPanes(server) {
|
|
34236
|
-
return herdrPanes(server, await snapshot(server));
|
|
34237
|
-
},
|
|
34238
|
-
async processes(server, pane) {
|
|
34239
|
-
const info = object2((await rpc(server, "pane.process_info", { pane_id: pane })).process_info);
|
|
34240
|
-
return {
|
|
34241
|
-
...Number.isSafeInteger(info.shell_pid) ? { shellPid: Number(info.shell_pid) } : {},
|
|
34242
|
-
foregroundPids: objects(info.foreground_processes).map((p) => p.pid).filter((p) => Number.isSafeInteger(p))
|
|
34243
|
-
};
|
|
34244
|
-
},
|
|
34245
|
-
async readScreen(server, pane, read) {
|
|
34246
|
-
const params = {
|
|
34247
|
-
...read.scope === "agent" ? { target: pane } : { pane_id: pane },
|
|
34248
|
-
source: read.source,
|
|
34249
|
-
lines: read.lines,
|
|
34250
|
-
strip_ansi: read.stripAnsi ?? true,
|
|
34251
|
-
// Herdr 0.9 answers plain text whatever `strip_ansi` says; "ansi" keeps the styles.
|
|
34252
|
-
...read.format ? { format: read.format } : {}
|
|
34253
|
-
};
|
|
34254
|
-
const result = await rpc(server, read.scope === "agent" ? "agent.read" : "pane.read", params, void 0, read.timeoutMs);
|
|
34255
|
-
const answer = object2(result.read ?? result);
|
|
34256
|
-
return typeof answer.text === "string" ? answer.text : "";
|
|
34257
|
-
},
|
|
34258
|
-
async sendKeys(server, pane, keys) {
|
|
34259
|
-
await rpc(server, "agent.send_keys", { target: pane, keys });
|
|
34260
|
-
},
|
|
34261
|
-
async prompt(server, pane, text4, signal) {
|
|
34262
|
-
if (signal) await rpc(server, "agent.prompt", { target: pane, text: text4 }, signal);
|
|
34263
|
-
else await rpc(server, "agent.prompt", { target: pane, text: text4 });
|
|
34264
|
-
},
|
|
34265
|
-
async create(server, { workspace, label: label2, cwd, env }) {
|
|
34266
|
-
await rpc(server, workspace ? "tab.create" : "workspace.create", { workspace_id: workspace, label: label2, cwd, focus: false, env: env ?? {} });
|
|
34267
|
-
},
|
|
34268
|
-
// `agent.start` takes no environment; the pane's shell got it at `create`.
|
|
34269
|
-
async startAgent(server, pane, { name, kind, args, timeoutMs }) {
|
|
34270
|
-
await rpc(server, "agent.start", { name, kind, pane_id: pane, timeout_ms: timeoutMs, ...args.length ? { args } : {} }, void 0, timeoutMs + 5e3);
|
|
34271
|
-
},
|
|
34272
|
-
// What Herdr sets in its own panes (herdrPaneFromEnv reads them back).
|
|
34273
|
-
paneEnv(server, { workspace, tab, pane }) {
|
|
34274
|
-
return { HERDR_ENV: "1", HERDR_SOCKET_PATH: herdrSocketPath(server), HERDR_WORKSPACE_ID: workspace, HERDR_TAB_ID: tab, HERDR_PANE_ID: pane };
|
|
34275
|
-
},
|
|
34276
|
-
async focusPane(server, pane) {
|
|
34277
|
-
await rpc(server, "pane.focus", { pane_id: pane });
|
|
34278
|
-
},
|
|
34279
|
-
async closePane(server, pane) {
|
|
34280
|
-
await rpc(server, "pane.close", { pane_id: pane });
|
|
34281
|
-
},
|
|
34282
|
-
async renamePane(server, pane, label2) {
|
|
34283
|
-
await rpc(server, "pane.rename", { pane_id: pane, label: label2 });
|
|
34284
|
-
},
|
|
34285
|
-
async groupAction(server, operation, { workspace, tab }, label2) {
|
|
34286
|
-
await rpc(server, `${tab ? "tab" : "workspace"}.${operation}`, { ...tab ? { tab_id: tab } : { workspace_id: workspace }, ...label2 ? { label: label2 } : {} });
|
|
34287
|
-
}
|
|
34288
|
-
};
|
|
34289
|
-
}
|
|
34290
|
-
});
|
|
34291
|
-
|
|
34292
34202
|
// src/bridge/claude-question-dialog.ts
|
|
34293
34203
|
function claudeQuestionDialog(text4) {
|
|
34294
34204
|
const lines = text4.split(/\r?\n/);
|
|
@@ -34977,7 +34887,7 @@ function agentFromCommand(command) {
|
|
|
34977
34887
|
if (name === "copilot" || program.includes("@github/copilot")) return "copilot";
|
|
34978
34888
|
if (name === "phren-agent" || program.includes("@phren/agent/") || /\/packages\/agent\/dist\/bin\.js$/.test(program)) return "phren";
|
|
34979
34889
|
const next = words[words.indexOf(program) + 1];
|
|
34980
|
-
if ((name === "phren" || program.includes("@phren/cli/")) && next === "agent") return "phren";
|
|
34890
|
+
if ((name === "phren" || program.includes("@phren/cli/") || /\/packages\/cli\/dist\/index\.js$/.test(program)) && next === "agent") return "phren";
|
|
34981
34891
|
return void 0;
|
|
34982
34892
|
}
|
|
34983
34893
|
function parseProcesses(text4) {
|
|
@@ -35372,7 +35282,7 @@ var init_terminal_tmux = __esm({
|
|
|
35372
35282
|
await tmux(server, ["new-session", "-d", "-s", sessionName(label2, taken), "-x", "200", "-y", "50", ...directory, ...name]);
|
|
35373
35283
|
},
|
|
35374
35284
|
async startAgent(server, pane, { name, kind, args, timeoutMs, env }) {
|
|
35375
|
-
if (!["claude", "codex", "copilot", "opencode"].includes(kind)) throw new BridgeError(400, "This agent cannot be started in tmux.");
|
|
35285
|
+
if (!["claude", "codex", "copilot", "opencode", "phren"].includes(kind)) throw new BridgeError(400, "This agent cannot be started in tmux.");
|
|
35376
35286
|
await requireDirectExec();
|
|
35377
35287
|
const target = toTmuxId(pane, "p"), row = await paneRow(server, target);
|
|
35378
35288
|
if (!row) throw new BridgeError(409, "This tmux pane changed. Refresh the computer.");
|
|
@@ -35444,6 +35354,149 @@ var init_terminal_tmux = __esm({
|
|
|
35444
35354
|
}
|
|
35445
35355
|
});
|
|
35446
35356
|
|
|
35357
|
+
// src/bridge/terminal-herdr.ts
|
|
35358
|
+
function shellWord(word) {
|
|
35359
|
+
return /^[A-Za-z0-9_./:=@%+,-]+$/.test(word) ? word : `'${word.replace(/'/g, `'\\''`)}'`;
|
|
35360
|
+
}
|
|
35361
|
+
function phrenCommandLine(args) {
|
|
35362
|
+
return [
|
|
35363
|
+
["phren", ...args].map(shellWord).join(" "),
|
|
35364
|
+
`herdr pane release-agent "$HERDR_PANE_ID" --source ${PHREN_REPORT_SOURCE} --agent phren >/dev/null 2>&1`
|
|
35365
|
+
].join("; ");
|
|
35366
|
+
}
|
|
35367
|
+
async function reportedPhren(server, pane) {
|
|
35368
|
+
const info = object2((await rpc(server, "pane.get", { pane_id: pane }).catch(() => ({}))).pane);
|
|
35369
|
+
return info.agent === "phren";
|
|
35370
|
+
}
|
|
35371
|
+
function unnamedAgent(error62) {
|
|
35372
|
+
return error62 instanceof BridgeError && error62.details?.herdrCode === "agent_not_ready" && /not an active named agent/.test(error62.message);
|
|
35373
|
+
}
|
|
35374
|
+
async function startPhren(server, pane, { name, args, timeoutMs }) {
|
|
35375
|
+
const before = object2((await rpc(server, "pane.process_info", { pane_id: pane })).process_info);
|
|
35376
|
+
if (!Number.isSafeInteger(before.shell_pid) || before.foreground_process_group_id !== before.shell_pid) throw new BridgeError(409, `Herdr: agent target pane ${pane} is not an available shell`, { herdrCode: "agent_pane_busy" });
|
|
35377
|
+
await rpc(server, "pane.send_text", { pane_id: pane, text: phrenCommandLine(args) });
|
|
35378
|
+
await rpc(server, "pane.send_keys", { pane_id: pane, keys: ["Enter"] });
|
|
35379
|
+
const deadline = Date.now() + Math.min(timeoutMs, 3e4);
|
|
35380
|
+
for (; ; ) {
|
|
35381
|
+
const info = object2((await rpc(server, "pane.process_info", { pane_id: pane })).process_info);
|
|
35382
|
+
if (objects(info.foreground_processes).some((p) => typeof p.cmdline === "string" && agentFromCommand(p.cmdline) === "phren")) break;
|
|
35383
|
+
if (Date.now() >= deadline) throw new BridgeError(504, "phren agent did not start in the Herdr pane. Check that phren and @phren/agent are installed on the login shell's PATH.");
|
|
35384
|
+
await new Promise((resolve11) => setTimeout(resolve11, 250));
|
|
35385
|
+
}
|
|
35386
|
+
await rpc(server, "pane.report_agent", { pane_id: pane, source: PHREN_REPORT_SOURCE, agent: "phren", state: "idle" });
|
|
35387
|
+
await rpc(server, "agent.rename", { target: pane, name }).catch(() => void 0);
|
|
35388
|
+
}
|
|
35389
|
+
function herdrPanes(server, s) {
|
|
35390
|
+
return objects(s.panes).filter((p) => typeof p.pane_id === "string" && typeof p.tab_id === "string" && typeof p.workspace_id === "string").map((p) => {
|
|
35391
|
+
const reported = object2(p.agent_session);
|
|
35392
|
+
const session = reported.kind === "id" && reported.agent === p.agent ? text(reported.value) : void 0;
|
|
35393
|
+
const hints = { agent: text(p.agent), status: text(p.agent_status), session };
|
|
35394
|
+
return {
|
|
35395
|
+
server,
|
|
35396
|
+
workspace: String(p.workspace_id),
|
|
35397
|
+
tab: String(p.tab_id),
|
|
35398
|
+
pane: String(p.pane_id),
|
|
35399
|
+
cwd: text(p.foreground_cwd) ?? text(p.cwd),
|
|
35400
|
+
title: text(p.title) ?? text(p.terminal_title_stripped),
|
|
35401
|
+
label: text(p.label),
|
|
35402
|
+
...hints.agent || hints.status || hints.session ? { hints } : {}
|
|
35403
|
+
};
|
|
35404
|
+
});
|
|
35405
|
+
}
|
|
35406
|
+
var text, PHREN_REPORT_SOURCE, herdrTerminal;
|
|
35407
|
+
var init_terminal_herdr = __esm({
|
|
35408
|
+
"src/bridge/terminal-herdr.ts"() {
|
|
35409
|
+
"use strict";
|
|
35410
|
+
init_herdr();
|
|
35411
|
+
init_protocol();
|
|
35412
|
+
init_terminal_tmux();
|
|
35413
|
+
text = (value2) => typeof value2 === "string" && value2 ? value2 : void 0;
|
|
35414
|
+
PHREN_REPORT_SOURCE = "phren-hook";
|
|
35415
|
+
herdrTerminal = {
|
|
35416
|
+
kind: "herdr",
|
|
35417
|
+
async ping(server) {
|
|
35418
|
+
await rpc(server, "ping");
|
|
35419
|
+
},
|
|
35420
|
+
async snapshot(server) {
|
|
35421
|
+
return object2((await rpc(server, "session.snapshot")).snapshot);
|
|
35422
|
+
},
|
|
35423
|
+
async listPanes(server) {
|
|
35424
|
+
return herdrPanes(server, await snapshot(server));
|
|
35425
|
+
},
|
|
35426
|
+
async processes(server, pane) {
|
|
35427
|
+
const info = object2((await rpc(server, "pane.process_info", { pane_id: pane })).process_info);
|
|
35428
|
+
return {
|
|
35429
|
+
...Number.isSafeInteger(info.shell_pid) ? { shellPid: Number(info.shell_pid) } : {},
|
|
35430
|
+
foregroundPids: objects(info.foreground_processes).map((p) => p.pid).filter((p) => Number.isSafeInteger(p))
|
|
35431
|
+
};
|
|
35432
|
+
},
|
|
35433
|
+
async readScreen(server, pane, read) {
|
|
35434
|
+
const params = {
|
|
35435
|
+
...read.scope === "agent" ? { target: pane } : { pane_id: pane },
|
|
35436
|
+
source: read.source,
|
|
35437
|
+
lines: read.lines,
|
|
35438
|
+
strip_ansi: read.stripAnsi ?? true,
|
|
35439
|
+
// Herdr 0.9 answers plain text whatever `strip_ansi` says; "ansi" keeps the styles.
|
|
35440
|
+
...read.format ? { format: read.format } : {}
|
|
35441
|
+
};
|
|
35442
|
+
const result = await rpc(server, read.scope === "agent" ? "agent.read" : "pane.read", params, void 0, read.timeoutMs);
|
|
35443
|
+
const answer = object2(result.read ?? result);
|
|
35444
|
+
return typeof answer.text === "string" ? answer.text : "";
|
|
35445
|
+
},
|
|
35446
|
+
async sendKeys(server, pane, keys) {
|
|
35447
|
+
try {
|
|
35448
|
+
await rpc(server, "agent.send_keys", { target: pane, keys });
|
|
35449
|
+
} catch (error62) {
|
|
35450
|
+
if (!unnamedAgent(error62) || !await reportedPhren(server, pane)) throw error62;
|
|
35451
|
+
await rpc(server, "pane.send_keys", { pane_id: pane, keys });
|
|
35452
|
+
}
|
|
35453
|
+
},
|
|
35454
|
+
async prompt(server, pane, text4, signal) {
|
|
35455
|
+
try {
|
|
35456
|
+
if (signal) await rpc(server, "agent.prompt", { target: pane, text: text4 }, signal);
|
|
35457
|
+
else await rpc(server, "agent.prompt", { target: pane, text: text4 });
|
|
35458
|
+
} catch (error62) {
|
|
35459
|
+
if (!unnamedAgent(error62) || !await reportedPhren(server, pane)) throw error62;
|
|
35460
|
+
await rpc(server, "pane.send_text", { pane_id: pane, text: `\x1B[200~${text4}\x1B[201~` }, signal);
|
|
35461
|
+
await new Promise((resolve11) => setTimeout(resolve11, 150));
|
|
35462
|
+
await rpc(server, "pane.send_keys", { pane_id: pane, keys: ["Enter"] }, signal);
|
|
35463
|
+
}
|
|
35464
|
+
},
|
|
35465
|
+
async create(server, { workspace, label: label2, cwd, env }) {
|
|
35466
|
+
await rpc(server, workspace ? "tab.create" : "workspace.create", { workspace_id: workspace, label: label2, cwd, focus: false, env: env ?? {} });
|
|
35467
|
+
},
|
|
35468
|
+
// `agent.start` takes no environment; the pane's shell got it at `create`.
|
|
35469
|
+
async startAgent(server, pane, agent) {
|
|
35470
|
+
const { name, kind, args, timeoutMs } = agent;
|
|
35471
|
+
if (kind === "phren") {
|
|
35472
|
+
await startPhren(server, pane, agent);
|
|
35473
|
+
return;
|
|
35474
|
+
}
|
|
35475
|
+
await rpc(server, "agent.start", { name, kind, pane_id: pane, timeout_ms: timeoutMs, ...args.length ? { args } : {} }, void 0, timeoutMs + 5e3);
|
|
35476
|
+
},
|
|
35477
|
+
// What Herdr sets in its own panes (herdrPaneFromEnv reads them back).
|
|
35478
|
+
paneEnv(server, { workspace, tab, pane }) {
|
|
35479
|
+
return { HERDR_ENV: "1", HERDR_SOCKET_PATH: herdrSocketPath(server), HERDR_WORKSPACE_ID: workspace, HERDR_TAB_ID: tab, HERDR_PANE_ID: pane };
|
|
35480
|
+
},
|
|
35481
|
+
async reportAgent(server, pane, agent, state) {
|
|
35482
|
+
await rpc(server, "pane.report_agent", { pane_id: pane, source: PHREN_REPORT_SOURCE, agent, state });
|
|
35483
|
+
},
|
|
35484
|
+
async focusPane(server, pane) {
|
|
35485
|
+
await rpc(server, "pane.focus", { pane_id: pane });
|
|
35486
|
+
},
|
|
35487
|
+
async closePane(server, pane) {
|
|
35488
|
+
await rpc(server, "pane.close", { pane_id: pane });
|
|
35489
|
+
},
|
|
35490
|
+
async renamePane(server, pane, label2) {
|
|
35491
|
+
await rpc(server, "pane.rename", { pane_id: pane, label: label2 });
|
|
35492
|
+
},
|
|
35493
|
+
async groupAction(server, operation, { workspace, tab }, label2) {
|
|
35494
|
+
await rpc(server, `${tab ? "tab" : "workspace"}.${operation}`, { ...tab ? { tab_id: tab } : { workspace_id: workspace }, ...label2 ? { label: label2 } : {} });
|
|
35495
|
+
}
|
|
35496
|
+
};
|
|
35497
|
+
}
|
|
35498
|
+
});
|
|
35499
|
+
|
|
35447
35500
|
// src/bridge/terminal.ts
|
|
35448
35501
|
var terminal_exports = {};
|
|
35449
35502
|
__export(terminal_exports, {
|
|
@@ -35510,6 +35563,9 @@ var init_terminal = __esm({
|
|
|
35510
35563
|
create: (server, placement) => route(server).create(server, placement),
|
|
35511
35564
|
startAgent: (server, pane, agent) => route(server).startAgent(server, pane, agent),
|
|
35512
35565
|
paneEnv: (server, place) => route(server).paneEnv?.(server, place),
|
|
35566
|
+
reportAgent: async (server, pane, agent, state) => {
|
|
35567
|
+
await route(server).reportAgent?.(server, pane, agent, state);
|
|
35568
|
+
},
|
|
35513
35569
|
focusPane: (server, pane) => route(server).focusPane(server, pane),
|
|
35514
35570
|
closePane: (server, pane) => route(server).closePane(server, pane),
|
|
35515
35571
|
renamePane: (server, pane, label2) => route(server).renamePane(server, pane, label2),
|
|
@@ -39361,7 +39417,7 @@ async function dispatch(command) {
|
|
|
39361
39417
|
await pipe2({ host: preview[1], port: Number(preview[2]) });
|
|
39362
39418
|
return;
|
|
39363
39419
|
}
|
|
39364
|
-
const shell = /^phren-hook v1 shell ([A-Za-z0-9_-]{1,8192})(?: (codex|claude|copilot|opencode))?$/.exec(command);
|
|
39420
|
+
const shell = /^phren-hook v1 shell ([A-Za-z0-9_-]{1,8192})(?: (codex|claude|copilot|opencode|phren))?$/.exec(command);
|
|
39365
39421
|
if (shell && shell[0] === command) {
|
|
39366
39422
|
requireHook();
|
|
39367
39423
|
const raw = decodeShellDirectory(shell[1]);
|
|
@@ -39369,8 +39425,8 @@ async function dispatch(command) {
|
|
|
39369
39425
|
const cwd = await launchDirectory(raw);
|
|
39370
39426
|
if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error("Request an SSH terminal first.");
|
|
39371
39427
|
const login = process.env.SHELL && path43.isAbsolute(process.env.SHELL) ? process.env.SHELL : "/bin/sh";
|
|
39372
|
-
const [file3, args] = shell[2] ? [shell[2], []] : [login, ["-l"]];
|
|
39373
|
-
await attach(file3, args, { cwd, env: shellEnvironment() }, shell[2] ? `${shell[2]} exited.` : "The shell exited.");
|
|
39428
|
+
const [file3, args] = shell[2] === "phren" ? ["phren", ["agent", "-i"]] : shell[2] ? [shell[2], []] : [login, ["-l"]];
|
|
39429
|
+
await attach(file3, args, { cwd, env: shellEnvironment() }, shell[2] === "phren" ? "phren agent exited." : shell[2] ? `${shell[2]} exited.` : "The shell exited.");
|
|
39374
39430
|
return;
|
|
39375
39431
|
}
|
|
39376
39432
|
const terminal2 = /^phren-hook v1 terminal ([A-Za-z0-9_.-]{1,100})$/.exec(command);
|
|
@@ -42773,12 +42829,12 @@ var VERSION_TIMEOUT_MS = 3e3;
|
|
|
42773
42829
|
var VERSION_CACHE_MS = 5 * 6e4;
|
|
42774
42830
|
var PEER_TIMEOUT_MS = 5e3;
|
|
42775
42831
|
var versionCache = /* @__PURE__ */ new Map();
|
|
42776
|
-
function toolVersion(tool, executable2 = tool) {
|
|
42832
|
+
function toolVersion(tool, executable2 = tool, args = []) {
|
|
42777
42833
|
const cached3 = versionCache.get(tool);
|
|
42778
42834
|
if (cached3 && Date.now() - cached3.at < VERSION_CACHE_MS) return cached3.value;
|
|
42779
42835
|
const value2 = new Promise((resolve11) => {
|
|
42780
42836
|
let out = "", done = false;
|
|
42781
|
-
const child = spawn8(executable2, ["--version"], { cwd: homedir14(), stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, NO_COLOR: "1" } });
|
|
42837
|
+
const child = spawn8(executable2, [...args, "--version"], { cwd: homedir14(), stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, NO_COLOR: "1" } });
|
|
42782
42838
|
const finish = (result) => {
|
|
42783
42839
|
if (!done) {
|
|
42784
42840
|
done = true;
|
|
@@ -43283,13 +43339,17 @@ init_home_paths();
|
|
|
43283
43339
|
init_claude_accounts();
|
|
43284
43340
|
import { existsSync as existsSync21 } from "node:fs";
|
|
43285
43341
|
import path62 from "node:path";
|
|
43286
|
-
var SOURCES = ["claude", "codex", "opencode", "copilot"];
|
|
43342
|
+
var SOURCES = ["claude", "codex", "opencode", "copilot", "phren"];
|
|
43343
|
+
var probeSource = (source) => source === "phren" ? toolVersion("phren agent", "phren", ["agent"]) : toolVersion(source);
|
|
43287
43344
|
async function harnessInventory(deps2 = {}) {
|
|
43288
43345
|
const env = deps2.env ?? process.env;
|
|
43289
|
-
const probe3 = deps2.toolVersion ??
|
|
43346
|
+
const probe3 = deps2.toolVersion ?? probeSource;
|
|
43290
43347
|
const harnesses = await Promise.all(SOURCES.map(async (source) => {
|
|
43291
43348
|
const found = await probe3(source);
|
|
43292
43349
|
if (found.status === "missing") return { source, installed: false, usable: false, reason: "Not installed" };
|
|
43350
|
+
if (source === "phren" && found.status === "error" && found.detail?.startsWith("--version exited")) {
|
|
43351
|
+
return { source, installed: false, usable: false, reason: "Not installed: npm install -g @phren/agent" };
|
|
43352
|
+
}
|
|
43293
43353
|
const base = { source, installed: true, ...found.version ? { version: found.version } : {} };
|
|
43294
43354
|
if (source === "claude") {
|
|
43295
43355
|
const accounts = await Promise.all(claudeHomes(env).map(async (home) => {
|
|
@@ -48570,6 +48630,9 @@ ${target.source}`) ?? 0) > Date.now();
|
|
|
48570
48630
|
const autoReview = body2.event === "PermissionRequest" && target.source === "codex" && body2.autoReview === true;
|
|
48571
48631
|
const status = autoReview ? void 0 : eventStatus(body2.event);
|
|
48572
48632
|
if (status && typeof pane.terminal_id === "string") notePaneStatus(target.server, target.pane, pane.terminal_id, status);
|
|
48633
|
+
if (status && target.source === "phren" && pane.agent === "phren" && pane.agent_status !== status) {
|
|
48634
|
+
await terminalProvider().reportAgent?.(target.server, target.pane, "phren", status).catch(() => void 0);
|
|
48635
|
+
}
|
|
48573
48636
|
const input2 = typeof body2.input === "string" ? { patch: body2.input } : object2(body2.input), command = [input2.command, input2.cmd].find((v) => typeof v === "string");
|
|
48574
48637
|
let dispatch2;
|
|
48575
48638
|
if (body2.event === "SessionStart" || body2.event === "UserPromptSubmit") {
|
|
@@ -56906,7 +56969,7 @@ init_codex_app_server();
|
|
|
56906
56969
|
init_codex_servers();
|
|
56907
56970
|
init_logger();
|
|
56908
56971
|
init_protocol();
|
|
56909
|
-
var launchKinds = ["codex", "claude", "copilot", "opencode"];
|
|
56972
|
+
var launchKinds = ["codex", "claude", "copilot", "opencode", "phren"];
|
|
56910
56973
|
var plainText = (max) => external_exports.string().min(1).max(max).refine((t) => !/[\x00-\x1f\x7f]/.test(t));
|
|
56911
56974
|
async function conductorBrief() {
|
|
56912
56975
|
let source;
|
|
@@ -56931,8 +56994,10 @@ function effortArgs(kind, effort) {
|
|
|
56931
56994
|
if (kind === "claude") return ["--effort", effort];
|
|
56932
56995
|
if (kind === "codex") return ["-c", `model_reasoning_effort=${effort}`];
|
|
56933
56996
|
if (kind === "opencode") return ["--variant", effort];
|
|
56997
|
+
if (kind === "phren") return ["--reasoning", effort === "minimal" ? "low" : effort];
|
|
56934
56998
|
return [];
|
|
56935
56999
|
}
|
|
57000
|
+
var PHREN_AGENT_ARGS = ["agent", "-i"];
|
|
56936
57001
|
async function prepareConductor(kind, effort, model) {
|
|
56937
57002
|
const brief = await conductorBrief();
|
|
56938
57003
|
const briefDirectory2 = path109.join(bridgeRoot(), "conductor");
|
|
@@ -56996,6 +57061,7 @@ async function requireNoConductor(server, before, except) {
|
|
|
56996
57061
|
return group.unchecked;
|
|
56997
57062
|
}
|
|
56998
57063
|
var paneRequest = external_exports.object({ workspaceId: id.optional(), tabId: id.optional(), paneId: id }).strict();
|
|
57064
|
+
var PHREN_NO_CONDUCTOR = "phren agent cannot run as a conductor: it takes no system brief at startup.";
|
|
56999
57065
|
async function makeConductor(server, data) {
|
|
57000
57066
|
const place = paneRequest.parse(data);
|
|
57001
57067
|
const before = await snapshot(server);
|
|
@@ -57003,6 +57069,7 @@ async function makeConductor(server, data) {
|
|
|
57003
57069
|
if (!pane) throw new BridgeError(409, "The pane changed.");
|
|
57004
57070
|
if (!runsAgent(pane)) throw new BridgeError(409, "No agent is running in this pane.");
|
|
57005
57071
|
if (pane.agent === "copilot") throw new BridgeError(400, "Copilot cannot run as a conductor.");
|
|
57072
|
+
if (pane.agent === "phren") throw new BridgeError(400, PHREN_NO_CONDUCTOR);
|
|
57006
57073
|
const unchecked = await requireNoConductor(server, before, place.paneId);
|
|
57007
57074
|
const target = await targetForPane(server, pane);
|
|
57008
57075
|
await recordConductor(server, pane, "owner", typeof target?.session === "string" ? target.session : void 0);
|
|
@@ -57058,13 +57125,15 @@ async function launchSession(server, data, options = {}) {
|
|
|
57058
57125
|
if (permissionMode && role === "conductor") throw new BridgeError(400, "A conductor starts with its own permissions; permissionMode is for workers.");
|
|
57059
57126
|
if (permissionMode && kind === "opencode") throw new BridgeError(400, "OpenCode takes its permissions from its own config; permissionMode is for Claude and Codex workers.");
|
|
57060
57127
|
if (permissionMode && kind === "copilot") throw new BridgeError(400, "Copilot takes its permissions from its own settings; permissionMode is for Claude and Codex workers.");
|
|
57128
|
+
if (permissionMode && kind === "phren") throw new BridgeError(400, "phren agent takes its permissions from its own settings; permissionMode is for Claude and Codex workers.");
|
|
57061
57129
|
if (role === "conductor" && kind === "copilot") throw new BridgeError(400, "Copilot cannot run as a conductor.");
|
|
57130
|
+
if (role === "conductor" && kind === "phren") throw new BridgeError(400, PHREN_NO_CONDUCTOR);
|
|
57062
57131
|
const brief = data.brief === void 0 || data.brief === null ? void 0 : launchBriefSchema.parse(data.brief);
|
|
57063
57132
|
if (brief && role === "conductor") throw new BridgeError(400, "A conductor starts with its own brief.");
|
|
57064
57133
|
const baseName = herdrAgentName(data.name === void 0 ? label2 : plainText(200).parse(data.name));
|
|
57065
57134
|
const wanted = options.canary ? "phren-canary" : role === "conductor" ? isConductorName(baseName) ? baseName : herdrAgentName(`conductor-${baseName}`) : isConductorName(baseName) ? herdrAgentName(`worker-${baseName}`) : baseName;
|
|
57066
57135
|
const model = typeof data.model === "string" && data.model.trim() ? plainText(200).parse(data.model.trim()) : void 0;
|
|
57067
|
-
const modelFlag = { codex: "--model", claude: "--model", opencode: "--model" };
|
|
57136
|
+
const modelFlag = { codex: "--model", claude: "--model", opencode: "--model", phren: "--model" };
|
|
57068
57137
|
let workspace = data.workspaceId === void 0 ? void 0 : id.parse(data.workspaceId);
|
|
57069
57138
|
const timeout = Math.min(12e4, Math.max(3001, data.timeoutMs === void 0 ? 45e3 : external_exports.number().int().parse(data.timeoutMs)));
|
|
57070
57139
|
await requireAvailable(kind, account);
|
|
@@ -57078,6 +57147,7 @@ async function launchSession(server, data, options = {}) {
|
|
|
57078
57147
|
const conductorHere = role === "agent" && workspace ? await conductorPane(server, before) : void 0;
|
|
57079
57148
|
if (conductorHere && conductorHere.workspace_id === workspace) workspace = void 0;
|
|
57080
57149
|
const args = role === "conductor" ? await prepareConductor(kind, effort, model) : [
|
|
57150
|
+
...kind === "phren" ? PHREN_AGENT_ARGS : [],
|
|
57081
57151
|
...model && modelFlag[kind] ? [modelFlag[kind], model] : [],
|
|
57082
57152
|
...data.effort === void 0 ? [] : effortArgs(kind, effort),
|
|
57083
57153
|
...permissionMode && kind === "claude" ? ["--permission-mode", CLAUDE_NAMES[permissionMode]] : [],
|
|
@@ -59767,7 +59837,7 @@ async function readSecret(prompt) {
|
|
|
59767
59837
|
// src/bridge/hook-main.ts
|
|
59768
59838
|
init_utils_helpers();
|
|
59769
59839
|
Object.assign(process.env, nonInteractiveGitEnv());
|
|
59770
|
-
runBridge(process.argv.slice(2), "0.3.
|
|
59840
|
+
runBridge(process.argv.slice(2), "0.3.19").then((code) => {
|
|
59771
59841
|
process.exitCode = code;
|
|
59772
59842
|
}).catch((error62) => {
|
|
59773
59843
|
console.error(error62 instanceof Error ? error62.message : "Phren Hook failed.");
|