@phren/cli 0.3.17 → 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/permission-mode.d.ts +48 -0
- package/dist/bridge/permission-mode.js +144 -0
- package/dist/bridge/server-launch.js +15 -3
- package/dist/bridge/server-pane-routes.d.ts +2 -0
- package/dist/bridge/server-pane-routes.js +12 -2
- package/dist/bridge/server-routes.d.ts +2 -0
- package/dist/bridge/server-stream.js +5 -2
- package/dist/bridge/server.js +4 -2
- package/dist/bridge/settings-switch.d.ts +8 -6
- package/dist/bridge/settings-switch.js +12 -27
- 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 +303 -126
- package/dist/modules/registry.js +1 -1
- package/package.json +1 -1
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),
|
|
@@ -37702,6 +37758,7 @@ var BUILTIN_MODULES = [
|
|
|
37702
37758
|
"/v1/prompt/status",
|
|
37703
37759
|
"/v1/model",
|
|
37704
37760
|
"/v1/settings",
|
|
37761
|
+
"/v1/agents/permission-mode",
|
|
37705
37762
|
"/v1/side-question/dismiss",
|
|
37706
37763
|
"/v1/keys",
|
|
37707
37764
|
"/v1/secret",
|
|
@@ -39360,7 +39417,7 @@ async function dispatch(command) {
|
|
|
39360
39417
|
await pipe2({ host: preview[1], port: Number(preview[2]) });
|
|
39361
39418
|
return;
|
|
39362
39419
|
}
|
|
39363
|
-
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);
|
|
39364
39421
|
if (shell && shell[0] === command) {
|
|
39365
39422
|
requireHook();
|
|
39366
39423
|
const raw = decodeShellDirectory(shell[1]);
|
|
@@ -39368,8 +39425,8 @@ async function dispatch(command) {
|
|
|
39368
39425
|
const cwd = await launchDirectory(raw);
|
|
39369
39426
|
if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error("Request an SSH terminal first.");
|
|
39370
39427
|
const login = process.env.SHELL && path43.isAbsolute(process.env.SHELL) ? process.env.SHELL : "/bin/sh";
|
|
39371
|
-
const [file3, args] = shell[2] ? [shell[2], []] : [login, ["-l"]];
|
|
39372
|
-
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.");
|
|
39373
39430
|
return;
|
|
39374
39431
|
}
|
|
39375
39432
|
const terminal2 = /^phren-hook v1 terminal ([A-Za-z0-9_.-]{1,100})$/.exec(command);
|
|
@@ -42772,12 +42829,12 @@ var VERSION_TIMEOUT_MS = 3e3;
|
|
|
42772
42829
|
var VERSION_CACHE_MS = 5 * 6e4;
|
|
42773
42830
|
var PEER_TIMEOUT_MS = 5e3;
|
|
42774
42831
|
var versionCache = /* @__PURE__ */ new Map();
|
|
42775
|
-
function toolVersion(tool, executable2 = tool) {
|
|
42832
|
+
function toolVersion(tool, executable2 = tool, args = []) {
|
|
42776
42833
|
const cached3 = versionCache.get(tool);
|
|
42777
42834
|
if (cached3 && Date.now() - cached3.at < VERSION_CACHE_MS) return cached3.value;
|
|
42778
42835
|
const value2 = new Promise((resolve11) => {
|
|
42779
42836
|
let out = "", done = false;
|
|
42780
|
-
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" } });
|
|
42781
42838
|
const finish = (result) => {
|
|
42782
42839
|
if (!done) {
|
|
42783
42840
|
done = true;
|
|
@@ -43282,13 +43339,17 @@ init_home_paths();
|
|
|
43282
43339
|
init_claude_accounts();
|
|
43283
43340
|
import { existsSync as existsSync21 } from "node:fs";
|
|
43284
43341
|
import path62 from "node:path";
|
|
43285
|
-
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);
|
|
43286
43344
|
async function harnessInventory(deps2 = {}) {
|
|
43287
43345
|
const env = deps2.env ?? process.env;
|
|
43288
|
-
const probe3 = deps2.toolVersion ??
|
|
43346
|
+
const probe3 = deps2.toolVersion ?? probeSource;
|
|
43289
43347
|
const harnesses = await Promise.all(SOURCES.map(async (source) => {
|
|
43290
43348
|
const found = await probe3(source);
|
|
43291
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
|
+
}
|
|
43292
43353
|
const base = { source, installed: true, ...found.version ? { version: found.version } : {} };
|
|
43293
43354
|
if (source === "claude") {
|
|
43294
43355
|
const accounts = await Promise.all(claudeHomes(env).map(async (home) => {
|
|
@@ -48569,6 +48630,9 @@ ${target.source}`) ?? 0) > Date.now();
|
|
|
48569
48630
|
const autoReview = body2.event === "PermissionRequest" && target.source === "codex" && body2.autoReview === true;
|
|
48570
48631
|
const status = autoReview ? void 0 : eventStatus(body2.event);
|
|
48571
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
|
+
}
|
|
48572
48636
|
const input2 = typeof body2.input === "string" ? { patch: body2.input } : object2(body2.input), command = [input2.command, input2.cmd].find((v) => typeof v === "string");
|
|
48573
48637
|
let dispatch2;
|
|
48574
48638
|
if (body2.event === "SessionStart" || body2.event === "UserPromptSubmit") {
|
|
@@ -49522,6 +49586,105 @@ var ModelSwitcher = class {
|
|
|
49522
49586
|
}
|
|
49523
49587
|
};
|
|
49524
49588
|
|
|
49589
|
+
// src/bridge/permission-mode.ts
|
|
49590
|
+
init_terminal_text();
|
|
49591
|
+
init_herdr();
|
|
49592
|
+
init_protocol();
|
|
49593
|
+
init_terminal();
|
|
49594
|
+
init_terminal_choice();
|
|
49595
|
+
var PERMISSION_CYCLE = ["default", "acceptEdits", "plan", "auto"];
|
|
49596
|
+
var PERMISSION_MODE_VALUES = [...PERMISSION_CYCLE, "bypassPermissions"];
|
|
49597
|
+
function permissionModes(bypass) {
|
|
49598
|
+
return [...PERMISSION_CYCLE, ...bypass ? ["bypassPermissions"] : []];
|
|
49599
|
+
}
|
|
49600
|
+
function claudeFooterMode(screen) {
|
|
49601
|
+
for (const line of stripTerminal(screen).split(/\r?\n/).map((line2) => line2.trim()).filter(Boolean).slice(-8).reverse()) {
|
|
49602
|
+
const text4 = line.replace(/^[⏵⏸]+\s*/, "");
|
|
49603
|
+
if (text4 === line) continue;
|
|
49604
|
+
if (/bypass permissions on/i.test(text4)) return "bypassPermissions";
|
|
49605
|
+
if (/^manual mode on\b/i.test(text4)) return "default";
|
|
49606
|
+
if (/^accept edits on\b/i.test(text4)) return "acceptEdits";
|
|
49607
|
+
if (/^plan mode on\b/i.test(text4)) return "plan";
|
|
49608
|
+
if (/^auto mode on\b/i.test(text4)) return "auto";
|
|
49609
|
+
}
|
|
49610
|
+
return void 0;
|
|
49611
|
+
}
|
|
49612
|
+
function refuseAgentOrigin(actor) {
|
|
49613
|
+
if (actor !== void 0) throw new BridgeError(403, "Only the owner changes a session's permission mode, from the phone.");
|
|
49614
|
+
}
|
|
49615
|
+
function attribution() {
|
|
49616
|
+
return { setBy: "owner" };
|
|
49617
|
+
}
|
|
49618
|
+
var STEP_WAIT_MS = 2e3;
|
|
49619
|
+
var POLL_MS2 = 100;
|
|
49620
|
+
var PermissionModeSwitcher = class {
|
|
49621
|
+
constructor(hooks, wait = STEP_WAIT_MS) {
|
|
49622
|
+
this.hooks = hooks;
|
|
49623
|
+
this.wait = wait;
|
|
49624
|
+
}
|
|
49625
|
+
hooks;
|
|
49626
|
+
wait;
|
|
49627
|
+
active = /* @__PURE__ */ new Set();
|
|
49628
|
+
key(target) {
|
|
49629
|
+
return `${target.server}:${target.pane}`;
|
|
49630
|
+
}
|
|
49631
|
+
assertAvailable(target) {
|
|
49632
|
+
if (this.active.has(this.key(target))) throw new BridgeError(409, "A permission-mode change is already in progress. Wait for it to finish.");
|
|
49633
|
+
}
|
|
49634
|
+
/** Steps the pane to `mode`, or refuses. Only Claude offers the cycle; the
|
|
49635
|
+
* machine's authority policy never caps an owner's own choice. */
|
|
49636
|
+
async set(target, mode, actor) {
|
|
49637
|
+
refuseAgentOrigin(actor);
|
|
49638
|
+
this.assertAvailable(target);
|
|
49639
|
+
if (target.source !== "claude") throw new BridgeError(422, "Changing the permission mode is not supported for this harness. Open terminal to change it.");
|
|
49640
|
+
this.active.add(this.key(target));
|
|
49641
|
+
try {
|
|
49642
|
+
return await this.cycle(target, mode, actor);
|
|
49643
|
+
} finally {
|
|
49644
|
+
this.active.delete(this.key(target));
|
|
49645
|
+
}
|
|
49646
|
+
}
|
|
49647
|
+
async cycle(target, mode, actor) {
|
|
49648
|
+
const first = await validateTarget(target, false, true);
|
|
49649
|
+
const terminal2 = first.terminal_id, status = String(first.agent_status);
|
|
49650
|
+
if (status === "working") throw new BridgeError(409, "This agent is mid-turn. Permission changes happen between turns; choose the mode again when the turn ends.");
|
|
49651
|
+
const screen = await this.hooks.paneAnsi(target).catch(() => void 0);
|
|
49652
|
+
if (screen === void 0) throw new BridgeError(409, "Could not read Claude's permission mode from its screen. Open terminal to check.");
|
|
49653
|
+
if (status === "blocked" || status === "waiting" || this.hooks.approval(target) || this.hooks.terminalPrompt(target) || visibleTerminalChoice(stripTerminal(screen))) {
|
|
49654
|
+
throw new BridgeError(409, "A permission prompt or dialog is open. Answer it before changing the permission mode.");
|
|
49655
|
+
}
|
|
49656
|
+
let current2 = claudeFooterMode(screen);
|
|
49657
|
+
if (!current2) throw new BridgeError(409, "Could not read Claude's permission mode from its screen. Open terminal to check.");
|
|
49658
|
+
if (current2 === mode) return { ok: true, permissionMode: current2, ...attribution() };
|
|
49659
|
+
const modes = new Set(PERMISSION_CYCLE);
|
|
49660
|
+
for (let presses = 0; ; presses++) {
|
|
49661
|
+
if (presses >= modes.size + 1) throw new BridgeError(422, `Claude doesn't offer ${mode} in this session.`, { permissionMode: current2 });
|
|
49662
|
+
await this.assertLive(target, terminal2);
|
|
49663
|
+
await terminalProvider().sendKeys(target.server, target.pane, ["shift+tab"]);
|
|
49664
|
+
current2 = await this.changed(target, terminal2, current2);
|
|
49665
|
+
modes.add(current2);
|
|
49666
|
+
if (current2 === mode) return { ok: true, permissionMode: current2, ...attribution() };
|
|
49667
|
+
}
|
|
49668
|
+
}
|
|
49669
|
+
/** The mode after a press: polled from the screen until it differs from
|
|
49670
|
+
* `from`, because the TUI redraws the footer asynchronously. */
|
|
49671
|
+
async changed(target, terminal2, from) {
|
|
49672
|
+
const deadline = Date.now() + this.wait;
|
|
49673
|
+
do {
|
|
49674
|
+
await new Promise((resolve11) => setTimeout(resolve11, POLL_MS2));
|
|
49675
|
+
await this.assertLive(target, terminal2);
|
|
49676
|
+
const mode = claudeFooterMode(await this.hooks.paneAnsi(target).catch(() => ""));
|
|
49677
|
+
if (mode && mode !== from) return mode;
|
|
49678
|
+
} while (Date.now() < deadline);
|
|
49679
|
+
throw new BridgeError(409, "Could not verify Claude's permission mode. Open terminal to check it.");
|
|
49680
|
+
}
|
|
49681
|
+
async assertLive(target, terminal2) {
|
|
49682
|
+
const pane = await validateTarget(target, false, true);
|
|
49683
|
+
if (pane.terminal_id !== terminal2) throw new BridgeError(409, "The terminal changed during the permission-mode change.");
|
|
49684
|
+
if (pane.agent_status === "working") throw new BridgeError(409, "The agent started working during the permission-mode change. The result is unconfirmed; check the terminal.");
|
|
49685
|
+
}
|
|
49686
|
+
};
|
|
49687
|
+
|
|
49525
49688
|
// src/bridge/session-servers.ts
|
|
49526
49689
|
init_protocol();
|
|
49527
49690
|
init_herdr();
|
|
@@ -49904,7 +50067,7 @@ async function paneRoute(ctx, url2, data, response) {
|
|
|
49904
50067
|
);
|
|
49905
50068
|
}
|
|
49906
50069
|
async function paneRouteOnce(ctx, url2, data, response, typing) {
|
|
49907
|
-
const { agentHooks, modelSwitcher, settingsSwitcher, codexQuestions, sideQuestions } = ctx;
|
|
50070
|
+
const { agentHooks, modelSwitcher, settingsSwitcher, permissionModeSwitcher, codexQuestions, sideQuestions } = ctx;
|
|
49908
50071
|
let result;
|
|
49909
50072
|
if (url2.pathname === "/v1/keys" && object2(data.target).starting === true) {
|
|
49910
50073
|
const target = startingTargetSchema.parse(data.target);
|
|
@@ -49958,16 +50121,18 @@ async function paneRouteOnce(ctx, url2, data, response, typing) {
|
|
|
49958
50121
|
}
|
|
49959
50122
|
} else {
|
|
49960
50123
|
const target = targetSchema.parse(data.target);
|
|
49961
|
-
const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model", "/v1/settings"].includes(url2.pathname);
|
|
50124
|
+
const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model", "/v1/settings", "/v1/agents/permission-mode"].includes(url2.pathname);
|
|
49962
50125
|
if (sendsInput) {
|
|
49963
50126
|
modelSwitcher.assertAvailable(target);
|
|
49964
50127
|
settingsSwitcher.assertAvailable(target);
|
|
50128
|
+
permissionModeSwitcher.assertAvailable(target);
|
|
49965
50129
|
sideQuestions.assertAvailable(target);
|
|
49966
50130
|
}
|
|
49967
50131
|
const pane = await validateTarget(target, false, sendsInput || url2.pathname === "/v1/upload");
|
|
49968
50132
|
if (sendsInput) {
|
|
49969
50133
|
modelSwitcher.assertAvailable(target);
|
|
49970
50134
|
settingsSwitcher.assertAvailable(target);
|
|
50135
|
+
permissionModeSwitcher.assertAvailable(target);
|
|
49971
50136
|
sideQuestions.assertAvailable(target);
|
|
49972
50137
|
}
|
|
49973
50138
|
if (url2.pathname === "/v1/prompt") {
|
|
@@ -50052,6 +50217,9 @@ async function paneRouteOnce(ctx, url2, data, response, typing) {
|
|
|
50052
50217
|
result = await modelSwitcher.switch(target, data);
|
|
50053
50218
|
} else if (url2.pathname === "/v1/settings") {
|
|
50054
50219
|
result = await settingsSwitcher.switch(target, data);
|
|
50220
|
+
} else if (url2.pathname === "/v1/agents/permission-mode") {
|
|
50221
|
+
refuseAgentOrigin(data && typeof data === "object" && "origin" in data ? data.origin ?? null : void 0);
|
|
50222
|
+
result = await permissionModeSwitcher.set(target, external_exports.enum(PERMISSION_MODE_VALUES).parse(data.mode));
|
|
50055
50223
|
} else if (url2.pathname === "/v1/keys" && await agentHooks.servedKeys(target, external_exports.array(external_exports.enum(ANSWER_KEYS)).min(1).max(4).parse(data.keys), String(pane.agent_status))) {
|
|
50056
50224
|
result = { ok: true };
|
|
50057
50225
|
} else if (url2.pathname === "/v1/keys") {
|
|
@@ -51488,6 +51656,7 @@ init_transcripts();
|
|
|
51488
51656
|
|
|
51489
51657
|
// src/bridge/settings-switch.ts
|
|
51490
51658
|
init_zod();
|
|
51659
|
+
init_terminal_text();
|
|
51491
51660
|
import { open as open20, stat as stat25 } from "node:fs/promises";
|
|
51492
51661
|
|
|
51493
51662
|
// src/bridge/claude-suggestion.ts
|
|
@@ -51538,7 +51707,6 @@ init_limits();
|
|
|
51538
51707
|
init_protocol();
|
|
51539
51708
|
init_terminal();
|
|
51540
51709
|
init_transcripts();
|
|
51541
|
-
init_terminal_text();
|
|
51542
51710
|
var CODEX_MODES = {
|
|
51543
51711
|
supervised: { approvalPolicy: "untrusted", approvalsReviewer: "user", sandboxPolicy: { type: "readOnly" } },
|
|
51544
51712
|
"auto-edits": { approvalPolicy: "on-request", approvalsReviewer: "user", sandboxPolicy: { type: "workspaceWrite" } },
|
|
@@ -51553,25 +51721,13 @@ function codexModeFlags(mode) {
|
|
|
51553
51721
|
return ["-a", String(approvalPolicy), "-s", String(sandbox), ...approvalsReviewer === "auto_review" ? ["-c", 'approvals_reviewer="auto_review"'] : []];
|
|
51554
51722
|
}
|
|
51555
51723
|
var MAX_PRESSES = 6;
|
|
51556
|
-
var
|
|
51724
|
+
var STEP_WAIT_MS2 = 2e3;
|
|
51557
51725
|
function settingsCapabilities(source, codexServed, claudeBypass = false) {
|
|
51558
51726
|
if (source === "codex") return codexServed ? { permissionModes: [...PERMISSION_MODES], plan: true, fast: false } : { permissionModes: [], plan: false, fast: false };
|
|
51559
51727
|
if (source === "claude") return { permissionModes: PERMISSION_MODES.filter((mode) => mode !== "full-access" || claudeBypass), plan: true, fast: true };
|
|
51560
51728
|
return void 0;
|
|
51561
51729
|
}
|
|
51562
51730
|
var request8 = external_exports.object({ permissionMode: external_exports.enum(PERMISSION_MODES).optional(), plan: external_exports.boolean().optional(), fast: external_exports.boolean().optional() }).strict().refine((value2) => value2.permissionMode !== void 0 || value2.plan !== void 0 || value2.fast !== void 0, "Choose a setting to change.");
|
|
51563
|
-
function claudeFooterMode(screen) {
|
|
51564
|
-
for (const line of stripTerminal(screen).split(/\r?\n/).map((line2) => line2.trim()).filter(Boolean).slice(-8).reverse()) {
|
|
51565
|
-
const text4 = line.replace(/^[⏵⏸]+\s*/, "");
|
|
51566
|
-
if (text4 === line) continue;
|
|
51567
|
-
if (/bypass permissions on/i.test(text4)) return "bypassPermissions";
|
|
51568
|
-
if (/^manual mode on\b/i.test(text4)) return "default";
|
|
51569
|
-
if (/^accept edits on\b/i.test(text4)) return "acceptEdits";
|
|
51570
|
-
if (/^plan mode on\b/i.test(text4)) return "plan";
|
|
51571
|
-
if (/^auto mode on\b/i.test(text4)) return "auto";
|
|
51572
|
-
}
|
|
51573
|
-
return void 0;
|
|
51574
|
-
}
|
|
51575
51731
|
var ClaudeSettingsReader = class {
|
|
51576
51732
|
constructor(hooks, every = intervalFromEnv("PHREN_DIALOG_THROTTLE_MS", 3e3)) {
|
|
51577
51733
|
this.hooks = hooks;
|
|
@@ -51598,7 +51754,10 @@ var ClaudeSettingsReader = class {
|
|
|
51598
51754
|
return {
|
|
51599
51755
|
bypass: entry2.bypass,
|
|
51600
51756
|
...phone ? { state: phone === "plan" ? { plan: true } : { permissionMode: phone, plan: false } } : {},
|
|
51601
|
-
...entry2.suggestion ? { suggestion: { text: entry2.suggestion, readAt: entry2.at } } : {}
|
|
51757
|
+
...entry2.suggestion ? { suggestion: { text: entry2.suggestion, readAt: entry2.at } } : {},
|
|
51758
|
+
// The raw Claude mode the phone's mode picker shows, only when the footer
|
|
51759
|
+
// was read: an unreadable one is not a confident "default".
|
|
51760
|
+
...entry2.mode ? { permissionMode: entry2.mode, permissionModes: permissionModes(entry2.bypass) } : {}
|
|
51602
51761
|
};
|
|
51603
51762
|
}
|
|
51604
51763
|
};
|
|
@@ -51624,7 +51783,7 @@ async function commandOutput2(file3, from) {
|
|
|
51624
51783
|
}
|
|
51625
51784
|
var fileSize = async (file3) => file3 ? (await stat25(file3).catch(() => void 0))?.size ?? 0 : 0;
|
|
51626
51785
|
var SettingsSwitcher = class {
|
|
51627
|
-
constructor(hooks, wait =
|
|
51786
|
+
constructor(hooks, wait = STEP_WAIT_MS2) {
|
|
51628
51787
|
this.hooks = hooks;
|
|
51629
51788
|
this.wait = wait;
|
|
51630
51789
|
this.reader = new ClaudeSettingsReader(hooks);
|
|
@@ -51634,14 +51793,20 @@ var SettingsSwitcher = class {
|
|
|
51634
51793
|
active = /* @__PURE__ */ new Set();
|
|
51635
51794
|
reader;
|
|
51636
51795
|
/** A Claude pane's footer-read settings and capabilities for the stream,
|
|
51637
|
-
* with the suggested next prompt its input box shows
|
|
51796
|
+
* with the suggested next prompt its input box shows and the raw permission
|
|
51797
|
+
* mode (`agentStatus.permissionMode`) its picker offers. */
|
|
51638
51798
|
async streamSettings(target, terminal2, codexServed) {
|
|
51639
51799
|
if (target.source !== "claude") {
|
|
51640
51800
|
const settings = settingsCapabilities(target.source, codexServed);
|
|
51641
51801
|
return settings ? { settings } : {};
|
|
51642
51802
|
}
|
|
51643
|
-
const { state, bypass, suggestion } = await this.reader.read(target, terminal2);
|
|
51644
|
-
return {
|
|
51803
|
+
const { state, bypass, suggestion, permissionMode, permissionModes: permissionModes2 } = await this.reader.read(target, terminal2);
|
|
51804
|
+
return {
|
|
51805
|
+
settings: settingsCapabilities("claude", false, bypass),
|
|
51806
|
+
...state ? { settingsState: state } : {},
|
|
51807
|
+
...suggestion ? { suggestion } : {},
|
|
51808
|
+
...permissionMode ? { permissionMode, permissionModes: permissionModes2 } : {}
|
|
51809
|
+
};
|
|
51645
51810
|
}
|
|
51646
51811
|
key(target) {
|
|
51647
51812
|
return `${target.server}:${target.pane}`;
|
|
@@ -56804,7 +56969,7 @@ init_codex_app_server();
|
|
|
56804
56969
|
init_codex_servers();
|
|
56805
56970
|
init_logger();
|
|
56806
56971
|
init_protocol();
|
|
56807
|
-
var launchKinds = ["codex", "claude", "copilot", "opencode"];
|
|
56972
|
+
var launchKinds = ["codex", "claude", "copilot", "opencode", "phren"];
|
|
56808
56973
|
var plainText = (max) => external_exports.string().min(1).max(max).refine((t) => !/[\x00-\x1f\x7f]/.test(t));
|
|
56809
56974
|
async function conductorBrief() {
|
|
56810
56975
|
let source;
|
|
@@ -56829,8 +56994,10 @@ function effortArgs(kind, effort) {
|
|
|
56829
56994
|
if (kind === "claude") return ["--effort", effort];
|
|
56830
56995
|
if (kind === "codex") return ["-c", `model_reasoning_effort=${effort}`];
|
|
56831
56996
|
if (kind === "opencode") return ["--variant", effort];
|
|
56997
|
+
if (kind === "phren") return ["--reasoning", effort === "minimal" ? "low" : effort];
|
|
56832
56998
|
return [];
|
|
56833
56999
|
}
|
|
57000
|
+
var PHREN_AGENT_ARGS = ["agent", "-i"];
|
|
56834
57001
|
async function prepareConductor(kind, effort, model) {
|
|
56835
57002
|
const brief = await conductorBrief();
|
|
56836
57003
|
const briefDirectory2 = path109.join(bridgeRoot(), "conductor");
|
|
@@ -56894,6 +57061,7 @@ async function requireNoConductor(server, before, except) {
|
|
|
56894
57061
|
return group.unchecked;
|
|
56895
57062
|
}
|
|
56896
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.";
|
|
56897
57065
|
async function makeConductor(server, data) {
|
|
56898
57066
|
const place = paneRequest.parse(data);
|
|
56899
57067
|
const before = await snapshot(server);
|
|
@@ -56901,6 +57069,7 @@ async function makeConductor(server, data) {
|
|
|
56901
57069
|
if (!pane) throw new BridgeError(409, "The pane changed.");
|
|
56902
57070
|
if (!runsAgent(pane)) throw new BridgeError(409, "No agent is running in this pane.");
|
|
56903
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);
|
|
56904
57073
|
const unchecked = await requireNoConductor(server, before, place.paneId);
|
|
56905
57074
|
const target = await targetForPane(server, pane);
|
|
56906
57075
|
await recordConductor(server, pane, "owner", typeof target?.session === "string" ? target.session : void 0);
|
|
@@ -56956,13 +57125,15 @@ async function launchSession(server, data, options = {}) {
|
|
|
56956
57125
|
if (permissionMode && role === "conductor") throw new BridgeError(400, "A conductor starts with its own permissions; permissionMode is for workers.");
|
|
56957
57126
|
if (permissionMode && kind === "opencode") throw new BridgeError(400, "OpenCode takes its permissions from its own config; permissionMode is for Claude and Codex workers.");
|
|
56958
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.");
|
|
56959
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);
|
|
56960
57131
|
const brief = data.brief === void 0 || data.brief === null ? void 0 : launchBriefSchema.parse(data.brief);
|
|
56961
57132
|
if (brief && role === "conductor") throw new BridgeError(400, "A conductor starts with its own brief.");
|
|
56962
57133
|
const baseName = herdrAgentName(data.name === void 0 ? label2 : plainText(200).parse(data.name));
|
|
56963
57134
|
const wanted = options.canary ? "phren-canary" : role === "conductor" ? isConductorName(baseName) ? baseName : herdrAgentName(`conductor-${baseName}`) : isConductorName(baseName) ? herdrAgentName(`worker-${baseName}`) : baseName;
|
|
56964
57135
|
const model = typeof data.model === "string" && data.model.trim() ? plainText(200).parse(data.model.trim()) : void 0;
|
|
56965
|
-
const modelFlag = { codex: "--model", claude: "--model", opencode: "--model" };
|
|
57136
|
+
const modelFlag = { codex: "--model", claude: "--model", opencode: "--model", phren: "--model" };
|
|
56966
57137
|
let workspace = data.workspaceId === void 0 ? void 0 : id.parse(data.workspaceId);
|
|
56967
57138
|
const timeout = Math.min(12e4, Math.max(3001, data.timeoutMs === void 0 ? 45e3 : external_exports.number().int().parse(data.timeoutMs)));
|
|
56968
57139
|
await requireAvailable(kind, account);
|
|
@@ -56976,6 +57147,7 @@ async function launchSession(server, data, options = {}) {
|
|
|
56976
57147
|
const conductorHere = role === "agent" && workspace ? await conductorPane(server, before) : void 0;
|
|
56977
57148
|
if (conductorHere && conductorHere.workspace_id === workspace) workspace = void 0;
|
|
56978
57149
|
const args = role === "conductor" ? await prepareConductor(kind, effort, model) : [
|
|
57150
|
+
...kind === "phren" ? PHREN_AGENT_ARGS : [],
|
|
56979
57151
|
...model && modelFlag[kind] ? [modelFlag[kind], model] : [],
|
|
56980
57152
|
...data.effort === void 0 ? [] : effortArgs(kind, effort),
|
|
56981
57153
|
...permissionMode && kind === "claude" ? ["--permission-mode", CLAUDE_NAMES[permissionMode]] : [],
|
|
@@ -58694,7 +58866,7 @@ function transcriptStreams(ctx) {
|
|
|
58694
58866
|
choice: { title: queued.title, options: queued.options }
|
|
58695
58867
|
} : void 0).catch(() => void 0) : void 0);
|
|
58696
58868
|
const codexServed = target.source === "codex" && !!codexServers.forTarget(target);
|
|
58697
|
-
const { settings, settingsState, suggestion } = settingsSwitcher ? await settingsSwitcher.streamSettings(target, pane.terminal_id, codexServed) : { settings: settingsCapabilities(target.source, codexServed), settingsState: void 0, suggestion: void 0 };
|
|
58869
|
+
const { settings, settingsState, suggestion, permissionMode, permissionModes: permissionModes2 } = settingsSwitcher ? await settingsSwitcher.streamSettings(target, pane.terminal_id, codexServed) : { settings: settingsCapabilities(target.source, codexServed), settingsState: void 0, suggestion: void 0, permissionMode: void 0, permissionModes: void 0 };
|
|
58698
58870
|
const between = ["idle", "done"].includes(String(pane.agent_status)) && !pendingApproval && !servedQuestion;
|
|
58699
58871
|
if (!between) busyAt = Date.now();
|
|
58700
58872
|
const nextPrompt = between && suggestion && suggestion.readAt > busyAt ? suggestion.text : void 0;
|
|
@@ -58709,6 +58881,9 @@ function transcriptStreams(ctx) {
|
|
|
58709
58881
|
...waiting && agentHooks.passwordPrompt(target) ? { passwordPrompt: true } : {},
|
|
58710
58882
|
compacting: agentHooks.compacting(target),
|
|
58711
58883
|
...nextPrompt ? { suggestion: nextPrompt } : {},
|
|
58884
|
+
// The mode Claude's footer shows and the cycle its picker offers,
|
|
58885
|
+
// only from a confident read (a Claude pane's readable footer).
|
|
58886
|
+
...permissionMode ? { permissionMode, permissionModes: permissionModes2 } : {},
|
|
58712
58887
|
...historyHealth.stalled ? { historyStalled: true, historyStalledSince: historyHealth.since } : {},
|
|
58713
58888
|
modules: info.modules,
|
|
58714
58889
|
store: info.store,
|
|
@@ -59041,12 +59216,13 @@ async function serve(version3, options = {}) {
|
|
|
59041
59216
|
const modelCatalog = options.modelCatalog ?? new ModelCatalog();
|
|
59042
59217
|
const modelSwitcher = new ModelSwitcher(agentHooks, modelCatalog);
|
|
59043
59218
|
const settingsSwitcher = new SettingsSwitcher(agentHooks);
|
|
59219
|
+
const permissionModeSwitcher = new PermissionModeSwitcher(agentHooks);
|
|
59044
59220
|
const sideQuestions = new SideQuestions();
|
|
59045
59221
|
const handOffs = dispatches ? new HandOffQueue({
|
|
59046
59222
|
validate: (target) => validateTarget(target, false, true),
|
|
59047
59223
|
notify: (target, text4, deliveryId, computer) => handOff({ computer, target, text: text4, deliveryId }, { notifySender: false }),
|
|
59048
59224
|
send: async (target, text4, deliveryId, typing) => await paneRouteOnce(
|
|
59049
|
-
{ agentHooks, modelSwitcher, settingsSwitcher, codexQuestions, sideQuestions },
|
|
59225
|
+
{ agentHooks, modelSwitcher, settingsSwitcher, permissionModeSwitcher, codexQuestions, sideQuestions },
|
|
59050
59226
|
new URL("http://phren.local/v1/prompt"),
|
|
59051
59227
|
{ target, text: text4, deliveryId, hookQueued: true },
|
|
59052
59228
|
{},
|
|
@@ -59149,6 +59325,7 @@ async function serve(version3, options = {}) {
|
|
|
59149
59325
|
modelCatalog,
|
|
59150
59326
|
modelSwitcher,
|
|
59151
59327
|
settingsSwitcher,
|
|
59328
|
+
permissionModeSwitcher,
|
|
59152
59329
|
sideQuestions,
|
|
59153
59330
|
accountUsage,
|
|
59154
59331
|
resources,
|
|
@@ -59660,7 +59837,7 @@ async function readSecret(prompt) {
|
|
|
59660
59837
|
// src/bridge/hook-main.ts
|
|
59661
59838
|
init_utils_helpers();
|
|
59662
59839
|
Object.assign(process.env, nonInteractiveGitEnv());
|
|
59663
|
-
runBridge(process.argv.slice(2), "0.3.
|
|
59840
|
+
runBridge(process.argv.slice(2), "0.3.19").then((code) => {
|
|
59664
59841
|
process.exitCode = code;
|
|
59665
59842
|
}).catch((error62) => {
|
|
59666
59843
|
console.error(error62 instanceof Error ? error62.message : "Phren Hook failed.");
|