@phren/cli 0.3.17 → 0.3.18

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.
@@ -0,0 +1,48 @@
1
+ import type { AgentHooks } from "./agent-hooks.js";
2
+ import { type Json, type Target } from "./protocol.js";
3
+ /** An agent's permission mode as its own footer names it, and the route that
4
+ * changes it by pressing Shift+Tab through the harness's cycle. The phone's
5
+ * mode picker reads `agentStatus.permissionMode` / `permissionModes` off the
6
+ * chat status stream and posts one back here. Only Claude Code draws the mode
7
+ * in its footer; Codex and OpenCode keep theirs in config, so they offer none. */
8
+ /** Claude Code's `permissionMode` values in Shift+Tab cycle order. "default" is
9
+ * the footer's "manual mode on"; "auto" is "auto mode on". */
10
+ export declare const PERMISSION_CYCLE: readonly ["default", "acceptEdits", "plan", "auto"];
11
+ /** `bypassPermissions` is in the cycle only for a session launched allowing
12
+ * bypass, so it is a valid mode but not part of the standard list. */
13
+ export declare const PERMISSION_MODE_VALUES: readonly ["default", "acceptEdits", "plan", "auto", "bypassPermissions"];
14
+ export type PermissionModeName = (typeof PERMISSION_MODE_VALUES)[number];
15
+ /** The modes a Claude pane offers, in Shift+Tab cycle order. `bypass` adds the
16
+ * one only a session launched with --allow-dangerously-skip-permissions has. */
17
+ export declare function permissionModes(bypass: boolean): PermissionModeName[];
18
+ /** Claude's permission mode from the footer line its TUI draws under the
19
+ * composer. The transcript lags it: a `permission-mode` row is written only
20
+ * when a prompt is submitted, and a fresh session has no file yet. The line may
21
+ * trail hints ("(shift+tab to cycle) · 1 agent"), so only its start counts. A
22
+ * mode the footer does not mark is `undefined`: "manual mode on" is default. */
23
+ export declare function claudeFooterMode(screen: string): PermissionModeName | undefined;
24
+ /** Only the owner changes a session's permission mode, from the phone. An
25
+ * agent's call names its own pane (`origin`), and none is accepted: an agent
26
+ * could otherwise lift itself or another pane past the per-grant
27
+ * `maxPermissionMode` ceiling, up to bypassPermissions. Same rule as
28
+ * `/v1/sudo/answer`. */
29
+ export declare function refuseAgentOrigin(actor: unknown): void;
30
+ /** One Shift+Tab transaction per pane owns its terminal input until it ends,
31
+ * like the settings switcher, so a mode change and a settings change never
32
+ * press into the same composer at once. */
33
+ export declare class PermissionModeSwitcher {
34
+ private readonly hooks;
35
+ private readonly wait;
36
+ private active;
37
+ constructor(hooks: AgentHooks, wait?: number);
38
+ private key;
39
+ assertAvailable(target: Target): void;
40
+ /** Steps the pane to `mode`, or refuses. Only Claude offers the cycle; the
41
+ * machine's authority policy never caps an owner's own choice. */
42
+ set(target: Target, mode: PermissionModeName, actor?: unknown): Promise<Json>;
43
+ private cycle;
44
+ /** The mode after a press: polled from the screen until it differs from
45
+ * `from`, because the TUI redraws the footer asynchronously. */
46
+ private changed;
47
+ private assertLive;
48
+ }
@@ -0,0 +1,144 @@
1
+ import { stripTerminal } from "../terminal-text.js";
2
+ import { validateTarget } from "./herdr.js";
3
+ import { BridgeError } from "./protocol.js";
4
+ import { terminalProvider } from "./terminal.js";
5
+ import { visibleTerminalChoice } from "./terminal-choice.js";
6
+ /** An agent's permission mode as its own footer names it, and the route that
7
+ * changes it by pressing Shift+Tab through the harness's cycle. The phone's
8
+ * mode picker reads `agentStatus.permissionMode` / `permissionModes` off the
9
+ * chat status stream and posts one back here. Only Claude Code draws the mode
10
+ * in its footer; Codex and OpenCode keep theirs in config, so they offer none. */
11
+ /** Claude Code's `permissionMode` values in Shift+Tab cycle order. "default" is
12
+ * the footer's "manual mode on"; "auto" is "auto mode on". */
13
+ export const PERMISSION_CYCLE = ["default", "acceptEdits", "plan", "auto"];
14
+ /** `bypassPermissions` is in the cycle only for a session launched allowing
15
+ * bypass, so it is a valid mode but not part of the standard list. */
16
+ export const PERMISSION_MODE_VALUES = [...PERMISSION_CYCLE, "bypassPermissions"];
17
+ /** The modes a Claude pane offers, in Shift+Tab cycle order. `bypass` adds the
18
+ * one only a session launched with --allow-dangerously-skip-permissions has. */
19
+ export function permissionModes(bypass) {
20
+ return [...PERMISSION_CYCLE, ...(bypass ? ["bypassPermissions"] : [])];
21
+ }
22
+ /** Claude's permission mode from the footer line its TUI draws under the
23
+ * composer. The transcript lags it: a `permission-mode` row is written only
24
+ * when a prompt is submitted, and a fresh session has no file yet. The line may
25
+ * trail hints ("(shift+tab to cycle) · 1 agent"), so only its start counts. A
26
+ * mode the footer does not mark is `undefined`: "manual mode on" is default. */
27
+ export function claudeFooterMode(screen) {
28
+ for (const line of stripTerminal(screen).split(/\r?\n/).map(line => line.trim()).filter(Boolean).slice(-8).reverse()) {
29
+ const text = line.replace(/^[⏵⏸]+\s*/, "");
30
+ if (text === line)
31
+ continue;
32
+ if (/bypass permissions on/i.test(text))
33
+ return "bypassPermissions";
34
+ if (/^manual mode on\b/i.test(text))
35
+ return "default";
36
+ if (/^accept edits on\b/i.test(text))
37
+ return "acceptEdits";
38
+ if (/^plan mode on\b/i.test(text))
39
+ return "plan";
40
+ if (/^auto mode on\b/i.test(text))
41
+ return "auto";
42
+ }
43
+ return undefined;
44
+ }
45
+ /** Only the owner changes a session's permission mode, from the phone. An
46
+ * agent's call names its own pane (`origin`), and none is accepted: an agent
47
+ * could otherwise lift itself or another pane past the per-grant
48
+ * `maxPermissionMode` ceiling, up to bypassPermissions. Same rule as
49
+ * `/v1/sudo/answer`. */
50
+ export function refuseAgentOrigin(actor) {
51
+ if (actor !== undefined)
52
+ throw new BridgeError(403, "Only the owner changes a session's permission mode, from the phone.");
53
+ }
54
+ /** Who chose the mode, for the reply: always the owner (see `refuseAgentOrigin`). */
55
+ function attribution() {
56
+ return { setBy: "owner" };
57
+ }
58
+ const STEP_WAIT_MS = 2_000, POLL_MS = 100;
59
+ /** One Shift+Tab transaction per pane owns its terminal input until it ends,
60
+ * like the settings switcher, so a mode change and a settings change never
61
+ * press into the same composer at once. */
62
+ export class PermissionModeSwitcher {
63
+ hooks;
64
+ wait;
65
+ active = new Set();
66
+ constructor(hooks, wait = STEP_WAIT_MS) {
67
+ this.hooks = hooks;
68
+ this.wait = wait;
69
+ }
70
+ key(target) { return `${target.server}:${target.pane}`; }
71
+ assertAvailable(target) {
72
+ if (this.active.has(this.key(target)))
73
+ throw new BridgeError(409, "A permission-mode change is already in progress. Wait for it to finish.");
74
+ }
75
+ /** Steps the pane to `mode`, or refuses. Only Claude offers the cycle; the
76
+ * machine's authority policy never caps an owner's own choice. */
77
+ async set(target, mode, actor) {
78
+ refuseAgentOrigin(actor);
79
+ this.assertAvailable(target);
80
+ if (target.source !== "claude")
81
+ throw new BridgeError(422, "Changing the permission mode is not supported for this harness. Open terminal to change it.");
82
+ this.active.add(this.key(target));
83
+ try {
84
+ return await this.cycle(target, mode, actor);
85
+ }
86
+ finally {
87
+ this.active.delete(this.key(target));
88
+ }
89
+ }
90
+ async cycle(target, mode, actor) {
91
+ const first = await validateTarget(target, false, true);
92
+ const terminal = first.terminal_id, status = String(first.agent_status);
93
+ // Shift+Tab is the composer's key: a turn or a dialog would take it first.
94
+ if (status === "working")
95
+ throw new BridgeError(409, "This agent is mid-turn. Permission changes happen between turns; choose the mode again when the turn ends.");
96
+ const screen = await this.hooks.paneAnsi(target).catch(() => undefined);
97
+ if (screen === undefined)
98
+ throw new BridgeError(409, "Could not read Claude's permission mode from its screen. Open terminal to check.");
99
+ if (status === "blocked" || status === "waiting" || this.hooks.approval(target) || this.hooks.terminalPrompt(target)
100
+ || visibleTerminalChoice(stripTerminal(screen))) {
101
+ throw new BridgeError(409, "A permission prompt or dialog is open. Answer it before changing the permission mode.");
102
+ }
103
+ let current = claudeFooterMode(screen);
104
+ if (!current)
105
+ throw new BridgeError(409, "Could not read Claude's permission mode from its screen. Open terminal to check.");
106
+ if (current === mode)
107
+ return { ok: true, permissionMode: current, ...attribution() };
108
+ // Shift+Tab steps through the modes this session offers. A full lap back to
109
+ // the start (one more press than the cycle holds) means it does not offer
110
+ // the one asked for. The bound grows if the cycle turns out to include one
111
+ // more mode than the standard list (bypass).
112
+ const modes = new Set(PERMISSION_CYCLE);
113
+ for (let presses = 0;; presses++) {
114
+ if (presses >= modes.size + 1)
115
+ throw new BridgeError(422, `Claude doesn't offer ${mode} in this session.`, { permissionMode: current });
116
+ await this.assertLive(target, terminal);
117
+ await terminalProvider().sendKeys(target.server, target.pane, ["shift+tab"]);
118
+ current = await this.changed(target, terminal, current);
119
+ modes.add(current);
120
+ if (current === mode)
121
+ return { ok: true, permissionMode: current, ...attribution() };
122
+ }
123
+ }
124
+ /** The mode after a press: polled from the screen until it differs from
125
+ * `from`, because the TUI redraws the footer asynchronously. */
126
+ async changed(target, terminal, from) {
127
+ const deadline = Date.now() + this.wait;
128
+ do {
129
+ await new Promise(resolve => setTimeout(resolve, POLL_MS));
130
+ await this.assertLive(target, terminal);
131
+ const mode = claudeFooterMode(await this.hooks.paneAnsi(target).catch(() => ""));
132
+ if (mode && mode !== from)
133
+ return mode;
134
+ } while (Date.now() < deadline);
135
+ throw new BridgeError(409, "Could not verify Claude's permission mode. Open terminal to check it.");
136
+ }
137
+ async assertLive(target, terminal) {
138
+ const pane = await validateTarget(target, false, true);
139
+ if (pane.terminal_id !== terminal)
140
+ throw new BridgeError(409, "The terminal changed during the permission-mode change.");
141
+ if (pane.agent_status === "working")
142
+ throw new BridgeError(409, "The agent started working during the permission-mode change. The result is unconfirmed; check the terminal.");
143
+ }
144
+ }
@@ -2,6 +2,7 @@ import type { ServerResponse } from "node:http";
2
2
  import type { AgentHooks } from "./agent-hooks.js";
3
3
  import { type WorktreeWorker } from "./git-worktrees.js";
4
4
  import { type ModelSwitcher } from "./model-switch.js";
5
+ import { type PermissionModeSwitcher } from "./permission-mode.js";
5
6
  import type { SettingsSwitcher } from "./settings-switch.js";
6
7
  import { type Json, type Target } from "./protocol.js";
7
8
  import type { CodexQuestions } from "./questions.js";
@@ -13,6 +14,7 @@ export interface PaneRouteContext {
13
14
  agentHooks: AgentHooks;
14
15
  modelSwitcher: ModelSwitcher;
15
16
  settingsSwitcher: SettingsSwitcher;
17
+ permissionModeSwitcher: PermissionModeSwitcher;
16
18
  codexQuestions: CodexQuestions;
17
19
  sideQuestions: SideQuestions;
18
20
  }
@@ -10,6 +10,7 @@ import { agentNotReady, terminalProvider } from "./terminal.js";
10
10
  import { AppServerRpcError } from "./codex-app-server.js";
11
11
  import { CodexServerUnavailable, codexServers } from "./codex-servers.js";
12
12
  import { refuseWorkingSlash } from "./model-switch.js";
13
+ import { PERMISSION_MODE_VALUES, refuseAgentOrigin } from "./permission-mode.js";
13
14
  import { sessionWebServers } from "./session-servers.js";
14
15
  import { repositoryDiff } from "./projects.js";
15
16
  import { BridgeError, MAX_FRAME, object, objects, startingTargetSchema, targetSchema } from "./protocol.js";
@@ -255,7 +256,7 @@ export async function paneRoute(ctx, url, data, response) {
255
256
  return promptOnce.run(id, promptScope(object(data.target), String(data.text ?? "")), async (typing) => object(await paneRouteOnce(ctx, url, data, response, typing)));
256
257
  }
257
258
  export async function paneRouteOnce(ctx, url, data, response, typing) {
258
- const { agentHooks, modelSwitcher, settingsSwitcher, codexQuestions, sideQuestions } = ctx;
259
+ const { agentHooks, modelSwitcher, settingsSwitcher, permissionModeSwitcher, codexQuestions, sideQuestions } = ctx;
259
260
  let result;
260
261
  if (url.pathname === "/v1/keys" && object(data.target).starting === true) {
261
262
  // A folder-trust or login prompt comes before the agent has a
@@ -328,10 +329,11 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
328
329
  const target = targetSchema.parse(data.target);
329
330
  // Uploads store bytes without answering or interrupting the agent.
330
331
  // They still require fresh identity, just like prompt mutations.
331
- const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model", "/v1/settings"].includes(url.pathname);
332
+ const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model", "/v1/settings", "/v1/agents/permission-mode"].includes(url.pathname);
332
333
  if (sendsInput) {
333
334
  modelSwitcher.assertAvailable(target);
334
335
  settingsSwitcher.assertAvailable(target);
336
+ permissionModeSwitcher.assertAvailable(target);
335
337
  sideQuestions.assertAvailable(target);
336
338
  }
337
339
  // A key press is how a prompt the agent draws in its terminal gets
@@ -341,6 +343,7 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
341
343
  if (sendsInput) {
342
344
  modelSwitcher.assertAvailable(target);
343
345
  settingsSwitcher.assertAvailable(target);
346
+ permissionModeSwitcher.assertAvailable(target);
344
347
  sideQuestions.assertAvailable(target);
345
348
  }
346
349
  if (url.pathname === "/v1/prompt") {
@@ -483,6 +486,13 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
483
486
  else if (url.pathname === "/v1/settings") {
484
487
  result = await settingsSwitcher.switch(target, data);
485
488
  }
489
+ else if (url.pathname === "/v1/agents/permission-mode") {
490
+ // The owner's own choice from the phone: no authority ceiling applies.
491
+ // An agent's call carries its pane as `origin` and is refused, so no
492
+ // agent can raise its own or another pane's mode past its ceiling.
493
+ refuseAgentOrigin(data && typeof data === "object" && "origin" in data ? data.origin ?? null : undefined);
494
+ result = await permissionModeSwitcher.set(target, z.enum(PERMISSION_MODE_VALUES).parse(data.mode));
495
+ }
486
496
  else if (url.pathname === "/v1/keys" && await agentHooks.servedKeys(target, z.array(z.enum(ANSWER_KEYS)).min(1).max(4).parse(data.keys), String(pane.agent_status))) {
487
497
  // A served OpenCode pane: Esc aborts its turn or declines its question,
488
498
  // a digit answers its question, over its own API.
@@ -14,6 +14,7 @@ import type { CodexQuestions } from "./questions.js";
14
14
  import type { TabActivityStore } from "./tab-activity.js";
15
15
  import type { ModelCatalog } from "./models.js";
16
16
  import type { ModelSwitcher } from "./model-switch.js";
17
+ import type { PermissionModeSwitcher } from "./permission-mode.js";
17
18
  import type { SettingsSwitcher } from "./settings-switch.js";
18
19
  import type { SideQuestions } from "./side-questions.js";
19
20
  import { type AccountUsageReader } from "./usage.js";
@@ -61,6 +62,7 @@ export interface RouteContext {
61
62
  modelCatalog: ModelCatalog;
62
63
  modelSwitcher: ModelSwitcher;
63
64
  settingsSwitcher: SettingsSwitcher;
65
+ permissionModeSwitcher: PermissionModeSwitcher;
64
66
  sideQuestions: SideQuestions;
65
67
  accountUsage: AccountUsageReader;
66
68
  resources: ResourceMonitor;
@@ -177,8 +177,8 @@ export function transcriptStreams(ctx) {
177
177
  : undefined);
178
178
  // Claude's own state comes from its footer, which leads the transcript.
179
179
  const codexServed = target.source === "codex" && !!codexServers.forTarget(target);
180
- const { settings, settingsState, suggestion } = settingsSwitcher ? await settingsSwitcher.streamSettings(target, pane.terminal_id, codexServed)
181
- : { settings: settingsCapabilities(target.source, codexServed), settingsState: undefined, suggestion: undefined };
180
+ const { settings, settingsState, suggestion, permissionMode, permissionModes } = settingsSwitcher ? await settingsSwitcher.streamSettings(target, pane.terminal_id, codexServed)
181
+ : { settings: settingsCapabilities(target.source, codexServed), settingsState: undefined, suggestion: undefined, permissionMode: undefined, permissionModes: undefined };
182
182
  // Claude's suggested next prompt, only between turns. The footer
183
183
  // read can be a throttle old, so one from before a turn this
184
184
  // stream saw start is stale: the turn cleared it.
@@ -192,6 +192,9 @@ export function transcriptStreams(ctx) {
192
192
  ...(waiting && agentHooks.passwordPrompt(target) ? { passwordPrompt: true } : {}),
193
193
  compacting: agentHooks.compacting(target),
194
194
  ...(nextPrompt ? { suggestion: nextPrompt } : {}),
195
+ // The mode Claude's footer shows and the cycle its picker offers,
196
+ // only from a confident read (a Claude pane's readable footer).
197
+ ...(permissionMode ? { permissionMode, permissionModes } : {}),
195
198
  ...(historyHealth.stalled ? { historyStalled: true, historyStalledSince: historyHealth.since } : {}),
196
199
  modules: info.modules, store: info.store, profile: info.profile, generation: info.generation,
197
200
  capabilities: { ...activeCapabilities, asyncQuestions: codexQuestions.availableFor(target),
@@ -36,6 +36,7 @@ import { childAgentTree } from "./transcripts.js";
36
36
  import { ModelCatalog } from "./models.js";
37
37
  import { ModelSwitcher } from "./model-switch.js";
38
38
  import { SettingsSwitcher } from "./settings-switch.js";
39
+ import { PermissionModeSwitcher } from "./permission-mode.js";
39
40
  import { SideQuestions } from "./side-questions.js";
40
41
  import { AccountUsageReader } from "./usage.js";
41
42
  import { ResourceMonitor } from "./resources.js";
@@ -134,11 +135,12 @@ export async function serve(version, options = {}) {
134
135
  const modelCatalog = options.modelCatalog ?? new ModelCatalog();
135
136
  const modelSwitcher = new ModelSwitcher(agentHooks, modelCatalog);
136
137
  const settingsSwitcher = new SettingsSwitcher(agentHooks);
138
+ const permissionModeSwitcher = new PermissionModeSwitcher(agentHooks);
137
139
  const sideQuestions = new SideQuestions();
138
140
  const handOffs = dispatches ? new HandOffQueue({
139
141
  validate: target => validateTarget(target, false, true),
140
142
  notify: (target, text, deliveryId, computer) => handOff({ computer, target, text, deliveryId }, { notifySender: false }),
141
- send: async (target, text, deliveryId, typing) => await paneRouteOnce({ agentHooks, modelSwitcher, settingsSwitcher, codexQuestions, sideQuestions }, new URL("http://phren.local/v1/prompt"), { target, text, deliveryId, hookQueued: true }, {}, typing),
143
+ send: async (target, text, deliveryId, typing) => await paneRouteOnce({ agentHooks, modelSwitcher, settingsSwitcher, permissionModeSwitcher, codexQuestions, sideQuestions }, new URL("http://phren.local/v1/prompt"), { target, text, deliveryId, hookQueued: true }, {}, typing),
142
144
  }) : undefined;
143
145
  const contextUsage = new WorkspaceContextUsage();
144
146
  const accountUsage = options.accountUsage ?? new AccountUsageReader();
@@ -206,7 +208,7 @@ export async function serve(version, options = {}) {
206
208
  sudo: agentHooks.sudo,
207
209
  });
208
210
  const http = createServer(createRouteHandler({ version, modules, info, computerID, scheduleStore, scheduler, dispatches, agentHooks,
209
- journal, tabActivity, contextUsage, modelCatalog, modelSwitcher, settingsSwitcher, sideQuestions, accountUsage, resources, codexQuestions, launches, locatedDirectories,
211
+ journal, tabActivity, contextUsage, modelCatalog, modelSwitcher, settingsSwitcher, permissionModeSwitcher, sideQuestions, accountUsage, resources, codexQuestions, launches, locatedDirectories,
210
212
  fanoutMessages, canary, streams, returns, handOffs, inbox }));
211
213
  http.requestTimeout = 20_000;
212
214
  http.headersTimeout = 10_000;
@@ -1,6 +1,8 @@
1
1
  import { AgentHooks } from "./agent-hooks.js";
2
2
  import { type CodexNextTurn } from "./codex-servers.js";
3
+ import { type PermissionModeName } from "./permission-mode.js";
3
4
  import { type Json, type PermissionMode, type Target } from "./protocol.js";
5
+ export { claudeFooterMode } from "./permission-mode.js";
4
6
  /** T3's CodexSessionRuntime mapping. The reviewer is always sent: leaving it
5
7
  * out would keep `auto_review` from an earlier turn. */
6
8
  export declare const CODEX_MODES: Record<PermissionMode, Pick<CodexNextTurn, "approvalPolicy" | "approvalsReviewer" | "sandboxPolicy">>;
@@ -17,11 +19,6 @@ export interface SettingsCapabilities {
17
19
  * from its transcript, but switching is not offered. Claude's cycle holds
18
20
  * `full-access` only when it was launched allowing bypass. */
19
21
  export declare function settingsCapabilities(source: string, codexServed: boolean, claudeBypass?: boolean): SettingsCapabilities | undefined;
20
- /** Claude's permission mode from the footer line its TUI draws under the
21
- * composer. The transcript lags it: a `permission-mode` row is written only
22
- * when a prompt is submitted, and a fresh session has no file yet. The line may
23
- * trail hints ("(shift+tab to cycle) · 1 agent"), so only its start counts. */
24
- export declare function claudeFooterMode(screen: string): string | undefined;
25
22
  export interface SettingsState {
26
23
  permissionMode?: string;
27
24
  plan?: boolean;
@@ -43,6 +40,8 @@ export declare class ClaudeSettingsReader {
43
40
  text: string;
44
41
  readAt: number;
45
42
  };
43
+ permissionMode?: PermissionModeName;
44
+ permissionModes?: PermissionModeName[];
46
45
  }>;
47
46
  }
48
47
  /** One settings transaction per pane owns its terminal input until it ends. */
@@ -53,7 +52,8 @@ export declare class SettingsSwitcher {
53
52
  private readonly reader;
54
53
  constructor(hooks: AgentHooks, wait?: number);
55
54
  /** A Claude pane's footer-read settings and capabilities for the stream,
56
- * with the suggested next prompt its input box shows. */
55
+ * with the suggested next prompt its input box shows and the raw permission
56
+ * mode (`agentStatus.permissionMode`) its picker offers. */
57
57
  streamSettings(target: Target, terminal: unknown, codexServed: boolean): Promise<{
58
58
  settings?: SettingsCapabilities;
59
59
  settingsState?: SettingsState;
@@ -61,6 +61,8 @@ export declare class SettingsSwitcher {
61
61
  text: string;
62
62
  readAt: number;
63
63
  };
64
+ permissionMode?: PermissionModeName;
65
+ permissionModes?: PermissionModeName[];
64
66
  }>;
65
67
  private key;
66
68
  assertAvailable(target: Target): void;
@@ -1,15 +1,17 @@
1
1
  import { open, stat } from "node:fs/promises";
2
2
  import { z } from "zod";
3
+ import { stripTerminal } from "../terminal-text.js";
3
4
  import { visibleTerminalChoice } from "./agent-hooks.js";
4
5
  import { claudeSuggestion } from "./claude-suggestion.js";
5
6
  import { codexServers } from "./codex-servers.js";
6
7
  import { validateTarget } from "./herdr.js";
7
8
  import { intervalFromEnv } from "./limits.js";
8
9
  import { emptyComposer } from "./model-switch.js";
10
+ import { claudeFooterMode, permissionModes } from "./permission-mode.js";
9
11
  import { BridgeError, object, PERMISSION_MODES } from "./protocol.js";
10
12
  import { terminalProvider } from "./terminal.js";
11
13
  import { transcriptPath } from "./transcripts.js";
12
- import { stripTerminal } from "../terminal-text.js";
14
+ export { claudeFooterMode } from "./permission-mode.js";
13
15
  /** T3's CodexSessionRuntime mapping. The reviewer is always sent: leaving it
14
16
  * out would keep `auto_review` from an earlier turn. */
15
17
  export const CODEX_MODES = {
@@ -41,28 +43,6 @@ export function settingsCapabilities(source, codexServed, claudeBypass = false)
41
43
  }
42
44
  const request = z.object({ permissionMode: z.enum(PERMISSION_MODES).optional(), plan: z.boolean().optional(), fast: z.boolean().optional() })
43
45
  .strict().refine(value => value.permissionMode !== undefined || value.plan !== undefined || value.fast !== undefined, "Choose a setting to change.");
44
- /** Claude's permission mode from the footer line its TUI draws under the
45
- * composer. The transcript lags it: a `permission-mode` row is written only
46
- * when a prompt is submitted, and a fresh session has no file yet. The line may
47
- * trail hints ("(shift+tab to cycle) · 1 agent"), so only its start counts. */
48
- export function claudeFooterMode(screen) {
49
- for (const line of stripTerminal(screen).split(/\r?\n/).map(line => line.trim()).filter(Boolean).slice(-8).reverse()) {
50
- const text = line.replace(/^[⏵⏸]+\s*/, "");
51
- if (text === line)
52
- continue;
53
- if (/bypass permissions on/i.test(text))
54
- return "bypassPermissions";
55
- if (/^manual mode on\b/i.test(text))
56
- return "default";
57
- if (/^accept edits on\b/i.test(text))
58
- return "acceptEdits";
59
- if (/^plan mode on\b/i.test(text))
60
- return "plan";
61
- if (/^auto mode on\b/i.test(text))
62
- return "auto";
63
- }
64
- return undefined;
65
- }
66
46
  /** A Claude pane's settings as its footer shows them, read at most once per
67
47
  * `PHREN_DIALOG_THROTTLE_MS` like the dialog check, and whether bypass was
68
48
  * ever seen in it (which is when full access is offered). The same read, with
@@ -96,7 +76,10 @@ export class ClaudeSettingsReader {
96
76
  }
97
77
  const phone = entry.mode ? CLAUDE_MODES[entry.mode] : undefined;
98
78
  return { bypass: entry.bypass, ...(phone ? { state: phone === "plan" ? { plan: true } : { permissionMode: phone, plan: false } } : {}),
99
- ...(entry.suggestion ? { suggestion: { text: entry.suggestion, readAt: entry.at } } : {}) };
79
+ ...(entry.suggestion ? { suggestion: { text: entry.suggestion, readAt: entry.at } } : {}),
80
+ // The raw Claude mode the phone's mode picker shows, only when the footer
81
+ // was read: an unreadable one is not a confident "default".
82
+ ...(entry.mode ? { permissionMode: entry.mode, permissionModes: permissionModes(entry.bypass) } : {}) };
100
83
  }
101
84
  }
102
85
  /** Claude's answer to a slash command: the first `<local-command-stdout>` user
@@ -137,14 +120,16 @@ export class SettingsSwitcher {
137
120
  this.reader = new ClaudeSettingsReader(hooks);
138
121
  }
139
122
  /** A Claude pane's footer-read settings and capabilities for the stream,
140
- * with the suggested next prompt its input box shows. */
123
+ * with the suggested next prompt its input box shows and the raw permission
124
+ * mode (`agentStatus.permissionMode`) its picker offers. */
141
125
  async streamSettings(target, terminal, codexServed) {
142
126
  if (target.source !== "claude") {
143
127
  const settings = settingsCapabilities(target.source, codexServed);
144
128
  return settings ? { settings } : {};
145
129
  }
146
- const { state, bypass, suggestion } = await this.reader.read(target, terminal);
147
- return { settings: settingsCapabilities("claude", false, bypass), ...(state ? { settingsState: state } : {}), ...(suggestion ? { suggestion } : {}) };
130
+ const { state, bypass, suggestion, permissionMode, permissionModes } = await this.reader.read(target, terminal);
131
+ return { settings: settingsCapabilities("claude", false, bypass), ...(state ? { settingsState: state } : {}), ...(suggestion ? { suggestion } : {}),
132
+ ...(permissionMode ? { permissionMode, permissionModes } : {}) };
148
133
  }
149
134
  key(target) { return `${target.server}:${target.pane}`; }
150
135
  assertAvailable(target) {
@@ -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.17" : "0.0.0";
25352
+ BUNDLED_VERSION = true ? "0.3.18" : "0.0.0";
25353
25353
  PACKAGE_JSON = readPackageJson();
25354
25354
  PACKAGE_NAME = PACKAGE_JSON.name || "phren";
25355
25355
  VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
@@ -37702,6 +37702,7 @@ var BUILTIN_MODULES = [
37702
37702
  "/v1/prompt/status",
37703
37703
  "/v1/model",
37704
37704
  "/v1/settings",
37705
+ "/v1/agents/permission-mode",
37705
37706
  "/v1/side-question/dismiss",
37706
37707
  "/v1/keys",
37707
37708
  "/v1/secret",
@@ -49522,6 +49523,105 @@ var ModelSwitcher = class {
49522
49523
  }
49523
49524
  };
49524
49525
 
49526
+ // src/bridge/permission-mode.ts
49527
+ init_terminal_text();
49528
+ init_herdr();
49529
+ init_protocol();
49530
+ init_terminal();
49531
+ init_terminal_choice();
49532
+ var PERMISSION_CYCLE = ["default", "acceptEdits", "plan", "auto"];
49533
+ var PERMISSION_MODE_VALUES = [...PERMISSION_CYCLE, "bypassPermissions"];
49534
+ function permissionModes(bypass) {
49535
+ return [...PERMISSION_CYCLE, ...bypass ? ["bypassPermissions"] : []];
49536
+ }
49537
+ function claudeFooterMode(screen) {
49538
+ for (const line of stripTerminal(screen).split(/\r?\n/).map((line2) => line2.trim()).filter(Boolean).slice(-8).reverse()) {
49539
+ const text4 = line.replace(/^[⏵⏸]+\s*/, "");
49540
+ if (text4 === line) continue;
49541
+ if (/bypass permissions on/i.test(text4)) return "bypassPermissions";
49542
+ if (/^manual mode on\b/i.test(text4)) return "default";
49543
+ if (/^accept edits on\b/i.test(text4)) return "acceptEdits";
49544
+ if (/^plan mode on\b/i.test(text4)) return "plan";
49545
+ if (/^auto mode on\b/i.test(text4)) return "auto";
49546
+ }
49547
+ return void 0;
49548
+ }
49549
+ function refuseAgentOrigin(actor) {
49550
+ if (actor !== void 0) throw new BridgeError(403, "Only the owner changes a session's permission mode, from the phone.");
49551
+ }
49552
+ function attribution() {
49553
+ return { setBy: "owner" };
49554
+ }
49555
+ var STEP_WAIT_MS = 2e3;
49556
+ var POLL_MS2 = 100;
49557
+ var PermissionModeSwitcher = class {
49558
+ constructor(hooks, wait = STEP_WAIT_MS) {
49559
+ this.hooks = hooks;
49560
+ this.wait = wait;
49561
+ }
49562
+ hooks;
49563
+ wait;
49564
+ active = /* @__PURE__ */ new Set();
49565
+ key(target) {
49566
+ return `${target.server}:${target.pane}`;
49567
+ }
49568
+ assertAvailable(target) {
49569
+ if (this.active.has(this.key(target))) throw new BridgeError(409, "A permission-mode change is already in progress. Wait for it to finish.");
49570
+ }
49571
+ /** Steps the pane to `mode`, or refuses. Only Claude offers the cycle; the
49572
+ * machine's authority policy never caps an owner's own choice. */
49573
+ async set(target, mode, actor) {
49574
+ refuseAgentOrigin(actor);
49575
+ this.assertAvailable(target);
49576
+ if (target.source !== "claude") throw new BridgeError(422, "Changing the permission mode is not supported for this harness. Open terminal to change it.");
49577
+ this.active.add(this.key(target));
49578
+ try {
49579
+ return await this.cycle(target, mode, actor);
49580
+ } finally {
49581
+ this.active.delete(this.key(target));
49582
+ }
49583
+ }
49584
+ async cycle(target, mode, actor) {
49585
+ const first = await validateTarget(target, false, true);
49586
+ const terminal2 = first.terminal_id, status = String(first.agent_status);
49587
+ 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.");
49588
+ const screen = await this.hooks.paneAnsi(target).catch(() => void 0);
49589
+ if (screen === void 0) throw new BridgeError(409, "Could not read Claude's permission mode from its screen. Open terminal to check.");
49590
+ if (status === "blocked" || status === "waiting" || this.hooks.approval(target) || this.hooks.terminalPrompt(target) || visibleTerminalChoice(stripTerminal(screen))) {
49591
+ throw new BridgeError(409, "A permission prompt or dialog is open. Answer it before changing the permission mode.");
49592
+ }
49593
+ let current2 = claudeFooterMode(screen);
49594
+ if (!current2) throw new BridgeError(409, "Could not read Claude's permission mode from its screen. Open terminal to check.");
49595
+ if (current2 === mode) return { ok: true, permissionMode: current2, ...attribution() };
49596
+ const modes = new Set(PERMISSION_CYCLE);
49597
+ for (let presses = 0; ; presses++) {
49598
+ if (presses >= modes.size + 1) throw new BridgeError(422, `Claude doesn't offer ${mode} in this session.`, { permissionMode: current2 });
49599
+ await this.assertLive(target, terminal2);
49600
+ await terminalProvider().sendKeys(target.server, target.pane, ["shift+tab"]);
49601
+ current2 = await this.changed(target, terminal2, current2);
49602
+ modes.add(current2);
49603
+ if (current2 === mode) return { ok: true, permissionMode: current2, ...attribution() };
49604
+ }
49605
+ }
49606
+ /** The mode after a press: polled from the screen until it differs from
49607
+ * `from`, because the TUI redraws the footer asynchronously. */
49608
+ async changed(target, terminal2, from) {
49609
+ const deadline = Date.now() + this.wait;
49610
+ do {
49611
+ await new Promise((resolve11) => setTimeout(resolve11, POLL_MS2));
49612
+ await this.assertLive(target, terminal2);
49613
+ const mode = claudeFooterMode(await this.hooks.paneAnsi(target).catch(() => ""));
49614
+ if (mode && mode !== from) return mode;
49615
+ } while (Date.now() < deadline);
49616
+ throw new BridgeError(409, "Could not verify Claude's permission mode. Open terminal to check it.");
49617
+ }
49618
+ async assertLive(target, terminal2) {
49619
+ const pane = await validateTarget(target, false, true);
49620
+ if (pane.terminal_id !== terminal2) throw new BridgeError(409, "The terminal changed during the permission-mode change.");
49621
+ 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.");
49622
+ }
49623
+ };
49624
+
49525
49625
  // src/bridge/session-servers.ts
49526
49626
  init_protocol();
49527
49627
  init_herdr();
@@ -49904,7 +50004,7 @@ async function paneRoute(ctx, url2, data, response) {
49904
50004
  );
49905
50005
  }
49906
50006
  async function paneRouteOnce(ctx, url2, data, response, typing) {
49907
- const { agentHooks, modelSwitcher, settingsSwitcher, codexQuestions, sideQuestions } = ctx;
50007
+ const { agentHooks, modelSwitcher, settingsSwitcher, permissionModeSwitcher, codexQuestions, sideQuestions } = ctx;
49908
50008
  let result;
49909
50009
  if (url2.pathname === "/v1/keys" && object2(data.target).starting === true) {
49910
50010
  const target = startingTargetSchema.parse(data.target);
@@ -49958,16 +50058,18 @@ async function paneRouteOnce(ctx, url2, data, response, typing) {
49958
50058
  }
49959
50059
  } else {
49960
50060
  const target = targetSchema.parse(data.target);
49961
- const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model", "/v1/settings"].includes(url2.pathname);
50061
+ const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model", "/v1/settings", "/v1/agents/permission-mode"].includes(url2.pathname);
49962
50062
  if (sendsInput) {
49963
50063
  modelSwitcher.assertAvailable(target);
49964
50064
  settingsSwitcher.assertAvailable(target);
50065
+ permissionModeSwitcher.assertAvailable(target);
49965
50066
  sideQuestions.assertAvailable(target);
49966
50067
  }
49967
50068
  const pane = await validateTarget(target, false, sendsInput || url2.pathname === "/v1/upload");
49968
50069
  if (sendsInput) {
49969
50070
  modelSwitcher.assertAvailable(target);
49970
50071
  settingsSwitcher.assertAvailable(target);
50072
+ permissionModeSwitcher.assertAvailable(target);
49971
50073
  sideQuestions.assertAvailable(target);
49972
50074
  }
49973
50075
  if (url2.pathname === "/v1/prompt") {
@@ -50052,6 +50154,9 @@ async function paneRouteOnce(ctx, url2, data, response, typing) {
50052
50154
  result = await modelSwitcher.switch(target, data);
50053
50155
  } else if (url2.pathname === "/v1/settings") {
50054
50156
  result = await settingsSwitcher.switch(target, data);
50157
+ } else if (url2.pathname === "/v1/agents/permission-mode") {
50158
+ refuseAgentOrigin(data && typeof data === "object" && "origin" in data ? data.origin ?? null : void 0);
50159
+ result = await permissionModeSwitcher.set(target, external_exports.enum(PERMISSION_MODE_VALUES).parse(data.mode));
50055
50160
  } 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
50161
  result = { ok: true };
50057
50162
  } else if (url2.pathname === "/v1/keys") {
@@ -51488,6 +51593,7 @@ init_transcripts();
51488
51593
 
51489
51594
  // src/bridge/settings-switch.ts
51490
51595
  init_zod();
51596
+ init_terminal_text();
51491
51597
  import { open as open20, stat as stat25 } from "node:fs/promises";
51492
51598
 
51493
51599
  // src/bridge/claude-suggestion.ts
@@ -51538,7 +51644,6 @@ init_limits();
51538
51644
  init_protocol();
51539
51645
  init_terminal();
51540
51646
  init_transcripts();
51541
- init_terminal_text();
51542
51647
  var CODEX_MODES = {
51543
51648
  supervised: { approvalPolicy: "untrusted", approvalsReviewer: "user", sandboxPolicy: { type: "readOnly" } },
51544
51649
  "auto-edits": { approvalPolicy: "on-request", approvalsReviewer: "user", sandboxPolicy: { type: "workspaceWrite" } },
@@ -51553,25 +51658,13 @@ function codexModeFlags(mode) {
51553
51658
  return ["-a", String(approvalPolicy), "-s", String(sandbox), ...approvalsReviewer === "auto_review" ? ["-c", 'approvals_reviewer="auto_review"'] : []];
51554
51659
  }
51555
51660
  var MAX_PRESSES = 6;
51556
- var STEP_WAIT_MS = 2e3;
51661
+ var STEP_WAIT_MS2 = 2e3;
51557
51662
  function settingsCapabilities(source, codexServed, claudeBypass = false) {
51558
51663
  if (source === "codex") return codexServed ? { permissionModes: [...PERMISSION_MODES], plan: true, fast: false } : { permissionModes: [], plan: false, fast: false };
51559
51664
  if (source === "claude") return { permissionModes: PERMISSION_MODES.filter((mode) => mode !== "full-access" || claudeBypass), plan: true, fast: true };
51560
51665
  return void 0;
51561
51666
  }
51562
51667
  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
51668
  var ClaudeSettingsReader = class {
51576
51669
  constructor(hooks, every = intervalFromEnv("PHREN_DIALOG_THROTTLE_MS", 3e3)) {
51577
51670
  this.hooks = hooks;
@@ -51598,7 +51691,10 @@ var ClaudeSettingsReader = class {
51598
51691
  return {
51599
51692
  bypass: entry2.bypass,
51600
51693
  ...phone ? { state: phone === "plan" ? { plan: true } : { permissionMode: phone, plan: false } } : {},
51601
- ...entry2.suggestion ? { suggestion: { text: entry2.suggestion, readAt: entry2.at } } : {}
51694
+ ...entry2.suggestion ? { suggestion: { text: entry2.suggestion, readAt: entry2.at } } : {},
51695
+ // The raw Claude mode the phone's mode picker shows, only when the footer
51696
+ // was read: an unreadable one is not a confident "default".
51697
+ ...entry2.mode ? { permissionMode: entry2.mode, permissionModes: permissionModes(entry2.bypass) } : {}
51602
51698
  };
51603
51699
  }
51604
51700
  };
@@ -51624,7 +51720,7 @@ async function commandOutput2(file3, from) {
51624
51720
  }
51625
51721
  var fileSize = async (file3) => file3 ? (await stat25(file3).catch(() => void 0))?.size ?? 0 : 0;
51626
51722
  var SettingsSwitcher = class {
51627
- constructor(hooks, wait = STEP_WAIT_MS) {
51723
+ constructor(hooks, wait = STEP_WAIT_MS2) {
51628
51724
  this.hooks = hooks;
51629
51725
  this.wait = wait;
51630
51726
  this.reader = new ClaudeSettingsReader(hooks);
@@ -51634,14 +51730,20 @@ var SettingsSwitcher = class {
51634
51730
  active = /* @__PURE__ */ new Set();
51635
51731
  reader;
51636
51732
  /** A Claude pane's footer-read settings and capabilities for the stream,
51637
- * with the suggested next prompt its input box shows. */
51733
+ * with the suggested next prompt its input box shows and the raw permission
51734
+ * mode (`agentStatus.permissionMode`) its picker offers. */
51638
51735
  async streamSettings(target, terminal2, codexServed) {
51639
51736
  if (target.source !== "claude") {
51640
51737
  const settings = settingsCapabilities(target.source, codexServed);
51641
51738
  return settings ? { settings } : {};
51642
51739
  }
51643
- const { state, bypass, suggestion } = await this.reader.read(target, terminal2);
51644
- return { settings: settingsCapabilities("claude", false, bypass), ...state ? { settingsState: state } : {}, ...suggestion ? { suggestion } : {} };
51740
+ const { state, bypass, suggestion, permissionMode, permissionModes: permissionModes2 } = await this.reader.read(target, terminal2);
51741
+ return {
51742
+ settings: settingsCapabilities("claude", false, bypass),
51743
+ ...state ? { settingsState: state } : {},
51744
+ ...suggestion ? { suggestion } : {},
51745
+ ...permissionMode ? { permissionMode, permissionModes: permissionModes2 } : {}
51746
+ };
51645
51747
  }
51646
51748
  key(target) {
51647
51749
  return `${target.server}:${target.pane}`;
@@ -58694,7 +58796,7 @@ function transcriptStreams(ctx) {
58694
58796
  choice: { title: queued.title, options: queued.options }
58695
58797
  } : void 0).catch(() => void 0) : void 0);
58696
58798
  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 };
58799
+ 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
58800
  const between = ["idle", "done"].includes(String(pane.agent_status)) && !pendingApproval && !servedQuestion;
58699
58801
  if (!between) busyAt = Date.now();
58700
58802
  const nextPrompt = between && suggestion && suggestion.readAt > busyAt ? suggestion.text : void 0;
@@ -58709,6 +58811,9 @@ function transcriptStreams(ctx) {
58709
58811
  ...waiting && agentHooks.passwordPrompt(target) ? { passwordPrompt: true } : {},
58710
58812
  compacting: agentHooks.compacting(target),
58711
58813
  ...nextPrompt ? { suggestion: nextPrompt } : {},
58814
+ // The mode Claude's footer shows and the cycle its picker offers,
58815
+ // only from a confident read (a Claude pane's readable footer).
58816
+ ...permissionMode ? { permissionMode, permissionModes: permissionModes2 } : {},
58712
58817
  ...historyHealth.stalled ? { historyStalled: true, historyStalledSince: historyHealth.since } : {},
58713
58818
  modules: info.modules,
58714
58819
  store: info.store,
@@ -59041,12 +59146,13 @@ async function serve(version3, options = {}) {
59041
59146
  const modelCatalog = options.modelCatalog ?? new ModelCatalog();
59042
59147
  const modelSwitcher = new ModelSwitcher(agentHooks, modelCatalog);
59043
59148
  const settingsSwitcher = new SettingsSwitcher(agentHooks);
59149
+ const permissionModeSwitcher = new PermissionModeSwitcher(agentHooks);
59044
59150
  const sideQuestions = new SideQuestions();
59045
59151
  const handOffs = dispatches ? new HandOffQueue({
59046
59152
  validate: (target) => validateTarget(target, false, true),
59047
59153
  notify: (target, text4, deliveryId, computer) => handOff({ computer, target, text: text4, deliveryId }, { notifySender: false }),
59048
59154
  send: async (target, text4, deliveryId, typing) => await paneRouteOnce(
59049
- { agentHooks, modelSwitcher, settingsSwitcher, codexQuestions, sideQuestions },
59155
+ { agentHooks, modelSwitcher, settingsSwitcher, permissionModeSwitcher, codexQuestions, sideQuestions },
59050
59156
  new URL("http://phren.local/v1/prompt"),
59051
59157
  { target, text: text4, deliveryId, hookQueued: true },
59052
59158
  {},
@@ -59149,6 +59255,7 @@ async function serve(version3, options = {}) {
59149
59255
  modelCatalog,
59150
59256
  modelSwitcher,
59151
59257
  settingsSwitcher,
59258
+ permissionModeSwitcher,
59152
59259
  sideQuestions,
59153
59260
  accountUsage,
59154
59261
  resources,
@@ -59660,7 +59767,7 @@ async function readSecret(prompt) {
59660
59767
  // src/bridge/hook-main.ts
59661
59768
  init_utils_helpers();
59662
59769
  Object.assign(process.env, nonInteractiveGitEnv());
59663
- runBridge(process.argv.slice(2), "0.3.17").then((code) => {
59770
+ runBridge(process.argv.slice(2), "0.3.18").then((code) => {
59664
59771
  process.exitCode = code;
59665
59772
  }).catch((error62) => {
59666
59773
  console.error(error62 instanceof Error ? error62.message : "Phren Hook failed.");
@@ -87,7 +87,7 @@ export const BUILTIN_MODULES = [
87
87
  ...routes("POST", [
88
88
  "/v1/push/register", "/v1/push/answer", "/v1/push/target", "/v1/files", "/v1/projects/add", "/v1/simulators/action",
89
89
  "/v1/workspaces/launch", "/v1/workspaces/create", "/v1/workspaces/focus", "/v1/workspaces/rename",
90
- "/v1/workspaces/close", "/v1/sessions/rename", "/v1/prompt", "/v1/prompt/status", "/v1/model", "/v1/settings", "/v1/side-question/dismiss", "/v1/keys", "/v1/secret", "/v1/upload",
90
+ "/v1/workspaces/close", "/v1/sessions/rename", "/v1/prompt", "/v1/prompt/status", "/v1/model", "/v1/settings", "/v1/agents/permission-mode", "/v1/side-question/dismiss", "/v1/keys", "/v1/secret", "/v1/upload",
91
91
  "/v1/approvals/answer", "/v1/questions/answer", "/v1/subagents/resume", "/v1/subagents/archive-finished", "/v1/canary",
92
92
  "/v1/speech", "/v1/sudo/answer", "/v1/jobs/cleanup",
93
93
  ]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "description": "Knowledge layer for AI agents - CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {