@phren/cli 0.3.11 → 0.3.13
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/account-usage.d.ts +124 -0
- package/dist/bridge/account-usage.js +258 -0
- package/dist/bridge/agent-hook-stores.d.ts +3 -0
- package/dist/bridge/agent-hook-stores.js +5 -0
- package/dist/bridge/agent-hooks.d.ts +162 -5
- package/dist/bridge/agent-hooks.js +682 -49
- package/dist/bridge/approval-summary.d.ts +16 -0
- package/dist/bridge/approval-summary.js +133 -0
- package/dist/bridge/authority-command.d.ts +20 -0
- package/dist/bridge/authority-command.js +120 -0
- package/dist/bridge/authority.d.ts +223 -0
- package/dist/bridge/authority.js +231 -0
- package/dist/bridge/claude-account-setup.d.ts +14 -0
- package/dist/bridge/claude-account-setup.js +69 -0
- package/dist/bridge/claude-accounts.d.ts +49 -0
- package/dist/bridge/claude-accounts.js +195 -0
- package/dist/bridge/code-routes.js +2 -2
- package/dist/bridge/codex-app-server.d.ts +144 -0
- package/dist/bridge/codex-app-server.js +319 -0
- package/dist/bridge/codex-auth-refresh.d.ts +33 -0
- package/dist/bridge/codex-auth-refresh.js +71 -0
- package/dist/bridge/codex-hook-trust.d.ts +27 -0
- package/dist/bridge/codex-hook-trust.js +237 -0
- package/dist/bridge/codex-question-reply.d.ts +16 -0
- package/dist/bridge/codex-question-reply.js +57 -0
- package/dist/bridge/codex-review-mode.d.ts +10 -0
- package/dist/bridge/codex-review-mode.js +74 -0
- package/dist/bridge/codex-servers.d.ts +217 -0
- package/dist/bridge/codex-servers.js +636 -0
- package/dist/bridge/command.js +97 -4
- package/dist/bridge/computer-identity.d.ts +75 -0
- package/dist/bridge/computer-identity.js +166 -0
- package/dist/bridge/conductor-group.d.ts +91 -8
- package/dist/bridge/conductor-group.js +105 -9
- package/dist/bridge/conductor-role.d.ts +94 -0
- package/dist/bridge/conductor-role.js +176 -0
- package/dist/bridge/conductor-sets.d.ts +20 -0
- package/dist/bridge/conductor-sets.js +59 -0
- package/dist/bridge/dispatch-command.d.ts +3 -0
- package/dist/bridge/dispatch-command.js +82 -12
- package/dist/bridge/dispatch-returns.d.ts +128 -19
- package/dist/bridge/dispatch-returns.js +371 -54
- package/dist/bridge/dispatch.d.ts +128 -3
- package/dist/bridge/dispatch.js +303 -42
- package/dist/bridge/fanouts.d.ts +7 -1
- package/dist/bridge/fanouts.js +39 -4
- package/dist/bridge/folder-trust.d.ts +56 -0
- package/dist/bridge/folder-trust.js +195 -0
- package/dist/bridge/grants.d.ts +22 -1
- package/dist/bridge/grants.js +57 -9
- package/dist/bridge/hand-off-queue.d.ts +74 -0
- package/dist/bridge/hand-off-queue.js +235 -0
- package/dist/bridge/hand-off.d.ts +30 -10
- package/dist/bridge/hand-off.js +79 -46
- package/dist/bridge/harness-status.d.ts +11 -0
- package/dist/bridge/harness-status.js +32 -0
- package/dist/bridge/harnesses.d.ts +39 -0
- package/dist/bridge/harnesses.js +65 -0
- package/dist/bridge/health.d.ts +2 -0
- package/dist/bridge/health.js +1 -1
- package/dist/bridge/herdr.d.ts +11 -2
- package/dist/bridge/herdr.js +98 -23
- package/dist/bridge/hook-fast.d.ts +4 -0
- package/dist/bridge/hook-fast.js +68 -0
- package/dist/bridge/install.d.ts +16 -1
- package/dist/bridge/install.js +102 -21
- package/dist/bridge/launch-brief.d.ts +96 -0
- package/dist/bridge/launch-brief.js +164 -0
- package/dist/bridge/model-switch.d.ts +3 -0
- package/dist/bridge/model-switch.js +17 -1
- package/dist/bridge/models.d.ts +8 -4
- package/dist/bridge/models.js +24 -8
- package/dist/bridge/mux-wire.d.ts +9 -0
- package/dist/bridge/mux-wire.js +19 -0
- package/dist/bridge/opencode-pane-server.d.ts +113 -0
- package/dist/bridge/opencode-pane-server.js +332 -0
- package/dist/bridge/opencode-panes.d.ts +111 -0
- package/dist/bridge/opencode-panes.js +295 -0
- package/dist/bridge/pane-accounts.d.ts +8 -0
- package/dist/bridge/pane-accounts.js +46 -0
- package/dist/bridge/pane-status.d.ts +12 -0
- package/dist/bridge/pane-status.js +50 -1
- package/dist/bridge/prompt-startup.d.ts +5 -0
- package/dist/bridge/prompt-startup.js +24 -0
- package/dist/bridge/protocol.d.ts +5 -0
- package/dist/bridge/protocol.js +4 -0
- package/dist/bridge/push.d.ts +11 -4
- package/dist/bridge/push.js +27 -4
- package/dist/bridge/questions.d.ts +37 -2
- package/dist/bridge/questions.js +158 -15
- package/dist/bridge/resources.d.ts +9 -3
- package/dist/bridge/resources.js +24 -8
- package/dist/bridge/schedule-format.d.ts +2 -0
- package/dist/bridge/schedule-format.js +3 -0
- package/dist/bridge/schedule-launch.d.ts +2 -1
- package/dist/bridge/schedule-launch.js +27 -53
- package/dist/bridge/schedule-watch.d.ts +24 -1
- package/dist/bridge/schedule-watch.js +89 -2
- package/dist/bridge/server-launch.d.ts +22 -5
- package/dist/bridge/server-launch.js +238 -32
- package/dist/bridge/server-overview.d.ts +10 -3
- package/dist/bridge/server-overview.js +32 -15
- package/dist/bridge/server-pane-routes.d.ts +3 -0
- package/dist/bridge/server-pane-routes.js +150 -18
- package/dist/bridge/server-routes.d.ts +11 -0
- package/dist/bridge/server-routes.js +214 -36
- package/dist/bridge/server-stream.d.ts +2 -0
- package/dist/bridge/server-stream.js +22 -8
- package/dist/bridge/server.d.ts +6 -1
- package/dist/bridge/server.js +58 -13
- package/dist/bridge/session-activity.d.ts +93 -0
- package/dist/bridge/session-activity.js +139 -0
- package/dist/bridge/session-rename.d.ts +48 -0
- package/dist/bridge/session-rename.js +190 -0
- package/dist/bridge/session-servers.js +2 -2
- package/dist/bridge/settings-switch.d.ts +60 -0
- package/dist/bridge/settings-switch.js +287 -0
- package/dist/bridge/speech-voice.d.ts +55 -0
- package/dist/bridge/speech-voice.js +132 -0
- package/dist/bridge/speech.d.ts +70 -11
- package/dist/bridge/speech.js +169 -41
- package/dist/bridge/stalls.d.ts +22 -0
- package/dist/bridge/stalls.js +57 -0
- package/dist/bridge/sudo.d.ts +209 -0
- package/dist/bridge/sudo.js +501 -0
- package/dist/bridge/terminal-herdr.js +9 -3
- package/dist/bridge/terminal-tmux.d.ts +15 -3
- package/dist/bridge/terminal-tmux.js +103 -13
- package/dist/bridge/terminal.d.ts +27 -4
- package/dist/bridge/terminal.js +8 -1
- package/dist/bridge/transcript-claude.d.ts +4 -0
- package/dist/bridge/transcript-claude.js +186 -16
- package/dist/bridge/transcript-codex.d.ts +0 -2
- package/dist/bridge/transcript-codex.js +29 -4
- package/dist/bridge/transcript-preview.d.ts +1 -0
- package/dist/bridge/transcript-preview.js +24 -4
- package/dist/bridge/transcripts.d.ts +15 -2
- package/dist/bridge/transcripts.js +47 -16
- package/dist/bridge/turn-records.d.ts +85 -0
- package/dist/bridge/turn-records.js +143 -0
- package/dist/bridge/uploads.d.ts +3 -0
- package/dist/bridge/uploads.js +14 -0
- package/dist/bridge/usage.d.ts +56 -10
- package/dist/bridge/usage.js +190 -45
- package/dist/bridge-hook.mjs +27975 -20636
- package/dist/cli/claude-unmanaged.d.ts +12 -0
- package/dist/cli/claude-unmanaged.js +105 -0
- package/dist/cli/schedules.js +2 -1
- package/dist/cli/session-start.js +10 -1
- package/dist/cli/session-stop.js +9 -1
- package/dist/cli-registry.js +31 -6
- package/dist/data/task-receipts.d.ts +19 -0
- package/dist/data/task-receipts.js +68 -0
- package/dist/data/tasks.js +4 -1
- package/dist/generated/memory-ui-graph.browser.js +63 -63
- package/dist/graph-core/model.js +24 -3
- package/dist/graph-core/types.d.ts +4 -1
- package/dist/graph-core/types.js +1 -0
- package/dist/init/init-preset.js +7 -3
- package/dist/init/init-uninstall.js +2 -11
- package/dist/init/teardown.d.ts +3 -0
- package/dist/init/teardown.js +47 -0
- package/dist/link/context.js +21 -9
- package/dist/mcp/plugin-mode.js +1 -1
- package/dist/memory-ui-graph.runtime.js +63 -63
- package/dist/modules/code-package.d.ts +1 -0
- package/dist/modules/code-package.js +36 -7
- package/dist/modules/registry.js +17 -16
- package/dist/profile-store.d.ts +6 -0
- package/dist/profile-store.js +25 -1
- package/dist/shell/graph/glyphs.js +4 -0
- package/dist/shell/graph/graph-view.js +2 -0
- package/dist/status.js +7 -1
- package/dist/sync/task-claim.js +3 -2
- package/dist/task/lifecycle.js +25 -4
- package/dist/test-global-setup.js +5 -0
- package/dist/tools/dispatch.js +52 -4
- package/dist/tools/tasks.js +10 -1
- package/package.json +1 -1
- package/plugins/opencode/phren-transcript.js +87 -4
- package/starter/global/AGENTS.md +4 -0
- package/starter/global/skills/conductor/SKILL.md +51 -4
|
@@ -3,6 +3,7 @@ import { logger } from "../logger.js";
|
|
|
3
3
|
import { sharedSnapshot } from "./herdr.js";
|
|
4
4
|
import { intervalFromEnv } from "./limits.js";
|
|
5
5
|
import { countTick } from "./metrics.js";
|
|
6
|
+
import { muxReplyForClient } from "./mux-wire.js";
|
|
6
7
|
import { MAX_FRAME } from "./protocol.js";
|
|
7
8
|
import { streamCloseReason } from "./server-stream.js";
|
|
8
9
|
/**
|
|
@@ -20,8 +21,10 @@ import { streamCloseReason } from "./server-stream.js";
|
|
|
20
21
|
*
|
|
21
22
|
* Frames: `{ type: "overview", ...workspaces, phren }` and
|
|
22
23
|
* `{ type: "heartbeat", phren }`. A phone that asks with `resources=1` also
|
|
23
|
-
* gets `{ type: "resources", resources }` first
|
|
24
|
-
* `OVERVIEW_RESOURCES_MS`
|
|
24
|
+
* gets `{ type: "resources", resources }` after the first overview, then at
|
|
25
|
+
* `OVERVIEW_RESOURCES_MS` intervals (an older phone never asks, so never meets it).
|
|
26
|
+
* One that asks with `sudo=1` gets `{ type: "sudo", requests }` after the first
|
|
27
|
+
* overview and whenever the pending sudo requests change.
|
|
25
28
|
*/
|
|
26
29
|
export const OVERVIEW_TICK_MS = intervalFromEnv("PHREN_OVERVIEW_TICK_MS", 5_000, 250, 60_000);
|
|
27
30
|
export const OVERVIEW_REFRESH_MS = intervalFromEnv("PHREN_OVERVIEW_REFRESH_MS", 10_000, 1_000, 120_000);
|
|
@@ -47,9 +50,26 @@ export function overviewStream(options) {
|
|
|
47
50
|
}
|
|
48
51
|
/** Streams one server's overview until the client closes. Returns the
|
|
49
52
|
* tick function, for tests that drive time themselves. */
|
|
50
|
-
return function stream(client, server, watchApprovals, withResources = false) {
|
|
51
|
-
let closed = false, busy = false, first = true;
|
|
53
|
+
return function stream(client, server, watchApprovals, withResources = false, typedMux = false, withSudo = false) {
|
|
54
|
+
let closed = false, busy = false, resourcesPending = false, first = true, overviewSent = false;
|
|
55
|
+
// Subscribed at once, so the phone counts as able to answer while the first overview builds.
|
|
56
|
+
const unsubscribe = withSudo && options.sudo
|
|
57
|
+
? options.sudo.subscribe(requests => { if (!closed && overviewSent)
|
|
58
|
+
send(client, { type: "sudo", requests }); }) : undefined;
|
|
52
59
|
let snapshotKey = "", builtAt = 0, sentKey = "", sentAt = 0, resourcesAt = -Infinity;
|
|
60
|
+
const collectResources = () => {
|
|
61
|
+
const at = now();
|
|
62
|
+
if (!withResources || !options.resources || resourcesPending || at - resourcesAt < resourcesMs)
|
|
63
|
+
return;
|
|
64
|
+
resourcesPending = true;
|
|
65
|
+
resourcesAt = at;
|
|
66
|
+
void Promise.resolve().then(() => options.resources()).then(resources => {
|
|
67
|
+
if (!closed && resources)
|
|
68
|
+
send(client, { type: "resources", resources });
|
|
69
|
+
}).catch(error => {
|
|
70
|
+
logger.warn("stream", `/v1/overview resources read failed: ${streamCloseReason(error)}`);
|
|
71
|
+
}).finally(() => { resourcesPending = false; });
|
|
72
|
+
};
|
|
53
73
|
const tick = async () => {
|
|
54
74
|
if (busy || closed)
|
|
55
75
|
return;
|
|
@@ -57,15 +77,6 @@ export function overviewStream(options) {
|
|
|
57
77
|
try {
|
|
58
78
|
countTick("overview-stream");
|
|
59
79
|
const at = now();
|
|
60
|
-
// Resources ride their own frame and clock; a failed read waits for the next.
|
|
61
|
-
if (withResources && options.resources && at - resourcesAt >= resourcesMs) {
|
|
62
|
-
resourcesAt = at;
|
|
63
|
-
const resources = await options.resources().catch(() => undefined);
|
|
64
|
-
if (closed)
|
|
65
|
-
return;
|
|
66
|
-
if (resources)
|
|
67
|
-
send(client, { type: "resources", resources });
|
|
68
|
-
}
|
|
69
80
|
// The first frame reads a fresh snapshot, as a poll would.
|
|
70
81
|
const held = await snapshot(server, first ? 0 : tickMs);
|
|
71
82
|
if (closed)
|
|
@@ -74,7 +85,7 @@ export function overviewStream(options) {
|
|
|
74
85
|
if (first || key !== snapshotKey || at - builtAt >= refreshMs) {
|
|
75
86
|
snapshotKey = key;
|
|
76
87
|
builtAt = at;
|
|
77
|
-
const overview = await options.read(server, held, watchApprovals);
|
|
88
|
+
const overview = muxReplyForClient(await options.read(server, held, watchApprovals), typedMux);
|
|
78
89
|
if (closed)
|
|
79
90
|
return;
|
|
80
91
|
const { phren: _phren, ...rows } = overview;
|
|
@@ -83,6 +94,9 @@ export function overviewStream(options) {
|
|
|
83
94
|
if (send(client, { type: "overview", ...overview })) {
|
|
84
95
|
sentKey = rowsKey;
|
|
85
96
|
sentAt = at;
|
|
97
|
+
if (!overviewSent && unsubscribe)
|
|
98
|
+
send(client, { type: "sudo", requests: options.sudo.list() });
|
|
99
|
+
overviewSent = true;
|
|
86
100
|
}
|
|
87
101
|
first = false;
|
|
88
102
|
return;
|
|
@@ -103,10 +117,13 @@ export function overviewStream(options) {
|
|
|
103
117
|
}
|
|
104
118
|
finally {
|
|
105
119
|
busy = false;
|
|
120
|
+
// Start this separately so ps and pane ownership cannot hold up the overview.
|
|
121
|
+
if (!closed)
|
|
122
|
+
collectResources();
|
|
106
123
|
}
|
|
107
124
|
};
|
|
108
125
|
const timer = setInterval(() => { void tick(); }, tickMs);
|
|
109
|
-
const stop = () => { closed = true; clearInterval(timer); };
|
|
126
|
+
const stop = () => { closed = true; clearInterval(timer); unsubscribe?.(); };
|
|
110
127
|
client.once("close", stop);
|
|
111
128
|
client.once("error", stop);
|
|
112
129
|
void tick();
|
|
@@ -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 { SettingsSwitcher } from "./settings-switch.js";
|
|
5
6
|
import { type Json, type Target } from "./protocol.js";
|
|
6
7
|
import type { CodexQuestions } from "./questions.js";
|
|
7
8
|
import { type SideQuestions } from "./side-questions.js";
|
|
@@ -11,6 +12,7 @@ import { type SideQuestions } from "./side-questions.js";
|
|
|
11
12
|
export interface PaneRouteContext {
|
|
12
13
|
agentHooks: AgentHooks;
|
|
13
14
|
modelSwitcher: ModelSwitcher;
|
|
15
|
+
settingsSwitcher: SettingsSwitcher;
|
|
14
16
|
codexQuestions: CodexQuestions;
|
|
15
17
|
sideQuestions: SideQuestions;
|
|
16
18
|
}
|
|
@@ -34,3 +36,4 @@ export declare function herdrWorktreeWorkers(s: Json): WorktreeWorker[];
|
|
|
34
36
|
* took, or ten minutes end the watch; a pane asking for input is never answered. */
|
|
35
37
|
export declare function followQueuedDelivery(agentHooks: AgentHooks, target: Target, terminal: unknown, text: string, intervalMs?: number): void;
|
|
36
38
|
export declare function paneRoute(ctx: PaneRouteContext, url: URL, data: Json, response: ServerResponse): Promise<unknown>;
|
|
39
|
+
export declare function paneRouteOnce(ctx: PaneRouteContext, url: URL, data: Json, response: ServerResponse, typing: () => void | Promise<void>): Promise<unknown>;
|
|
@@ -6,15 +6,19 @@ import { fanoutWorktrees } from "./fanouts.js";
|
|
|
6
6
|
import { gitWorktrees, resolveWorktree } from "./git-worktrees.js";
|
|
7
7
|
import { gitCommit, gitPullRequest, gitPush } from "./git-publish.js";
|
|
8
8
|
import { findPane, paneAgentName, paneChatState, paneIdentity, snapshot, startingPane, trustedDirectory, validateStartingTarget, validateTarget } from "./herdr.js";
|
|
9
|
-
import { terminalProvider } from "./terminal.js";
|
|
9
|
+
import { agentNotReady, terminalProvider } from "./terminal.js";
|
|
10
|
+
import { AppServerRpcError } from "./codex-app-server.js";
|
|
11
|
+
import { CodexServerUnavailable, codexServers } from "./codex-servers.js";
|
|
10
12
|
import { refuseWorkingSlash } from "./model-switch.js";
|
|
11
13
|
import { sessionWebServers } from "./session-servers.js";
|
|
12
14
|
import { repositoryDiff } from "./projects.js";
|
|
13
15
|
import { BridgeError, MAX_FRAME, object, objects, startingTargetSchema, targetSchema } from "./protocol.js";
|
|
14
|
-
import { childAgent, childAgentTree, conversationNamedPaths,
|
|
16
|
+
import { childAgent, childAgentTree, conversationNamedPaths, targetTranscriptPath } from "./transcripts.js";
|
|
15
17
|
import { sideQuestionText } from "./side-questions.js";
|
|
16
18
|
import { saveUpload } from "./uploads.js";
|
|
17
19
|
import { deliveryIdSchema, PromptOnce, promptScope } from "./prompt-once.js";
|
|
20
|
+
import { promptWithStartupRetry } from "./prompt-startup.js";
|
|
21
|
+
import { sendServedPrompt, servedPane } from "./opencode-panes.js";
|
|
18
22
|
export /** A file from the phone: a plain name and base64 bytes, bounded. */ function uploadBody(data) {
|
|
19
23
|
const name = z.string().regex(/^[A-Za-z0-9_][A-Za-z0-9_ .()-]{0,199}$/).refine(n => !n.includes("..")).parse(data.name);
|
|
20
24
|
const encoded = z.string().max(11_184_812).regex(/^[A-Za-z0-9+/]*={0,2}$/).parse(data.data);
|
|
@@ -225,6 +229,23 @@ async function typeSecret(server, pane, text) {
|
|
|
225
229
|
}
|
|
226
230
|
}
|
|
227
231
|
const promptOnce = new PromptOnce();
|
|
232
|
+
/** A prompt for an OpenCode pane the Hook started with its own server: sent
|
|
233
|
+
* over that API into the conversation the TUI shows (a new one, shown first,
|
|
234
|
+
* when it has none) and confirmed by the user turn appearing there. Undefined
|
|
235
|
+
* when the pane has no server entry, the text is a slash command (the TUI's
|
|
236
|
+
* own menus), or nothing reached OpenCode; the caller then types it. */
|
|
237
|
+
async function servedPrompt(target, session, text, typing) {
|
|
238
|
+
if (target.source !== "opencode" || text.trim().startsWith("/"))
|
|
239
|
+
return undefined;
|
|
240
|
+
const entry = servedPane(target.server, target.pane);
|
|
241
|
+
if (!entry)
|
|
242
|
+
return undefined;
|
|
243
|
+
await typing();
|
|
244
|
+
const sent = await sendServedPrompt(entry, session, text);
|
|
245
|
+
if (!sent.sent)
|
|
246
|
+
return undefined;
|
|
247
|
+
return sent.delivered ? { ok: true, delivered: true } : { ok: true, deliveryUncertain: true };
|
|
248
|
+
}
|
|
228
249
|
export async function paneRoute(ctx, url, data, response) {
|
|
229
250
|
if (url.pathname !== "/v1/prompt")
|
|
230
251
|
return paneRouteOnce(ctx, url, data, response, () => { });
|
|
@@ -233,8 +254,8 @@ export async function paneRoute(ctx, url, data, response) {
|
|
|
233
254
|
const id = deliveryIdSchema.parse(data.deliveryId);
|
|
234
255
|
return promptOnce.run(id, promptScope(object(data.target), String(data.text ?? "")), async (typing) => object(await paneRouteOnce(ctx, url, data, response, typing)));
|
|
235
256
|
}
|
|
236
|
-
async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
237
|
-
const { agentHooks, modelSwitcher, codexQuestions, sideQuestions } = ctx;
|
|
257
|
+
export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
258
|
+
const { agentHooks, modelSwitcher, settingsSwitcher, codexQuestions, sideQuestions } = ctx;
|
|
238
259
|
let result;
|
|
239
260
|
if (url.pathname === "/v1/keys" && object(data.target).starting === true) {
|
|
240
261
|
// A folder-trust or login prompt comes before the agent has a
|
|
@@ -261,10 +282,30 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
261
282
|
else if (url.pathname === "/v1/prompt" && object(data.target).starting === true) {
|
|
262
283
|
const target = startingTargetSchema.parse(data.target);
|
|
263
284
|
const pane = await validateStartingTarget(target);
|
|
285
|
+
if (typeof pane.startingSession === "string") {
|
|
286
|
+
const resolved = { ...target, session: pane.startingSession };
|
|
287
|
+
modelSwitcher.assertAvailable(resolved);
|
|
288
|
+
settingsSwitcher.assertAvailable(resolved);
|
|
289
|
+
sideQuestions.assertAvailable(resolved);
|
|
290
|
+
}
|
|
264
291
|
const text = z.string().min(1).max(32768).refine(t => !/[\x00-\x08\x0b-\x1f\x7f]/.test(t)).parse(data.text);
|
|
265
292
|
refuseWorkingSlash(pane, text);
|
|
266
|
-
typing
|
|
267
|
-
|
|
293
|
+
const served = await servedPrompt(target, undefined, text, typing);
|
|
294
|
+
if (served)
|
|
295
|
+
return served;
|
|
296
|
+
await typing();
|
|
297
|
+
await promptWithStartupRetry(() => terminalProvider().prompt(target.server, target.pane, text), async () => {
|
|
298
|
+
const current = await validateStartingTarget(target);
|
|
299
|
+
if (current.terminal_id !== pane.terminal_id)
|
|
300
|
+
throw new BridgeError(409, "This agent pane changed. Reopen the chat.");
|
|
301
|
+
if (typeof current.startingSession === "string") {
|
|
302
|
+
const resolved = { ...target, session: current.startingSession };
|
|
303
|
+
modelSwitcher.assertAvailable(resolved);
|
|
304
|
+
settingsSwitcher.assertAvailable(resolved);
|
|
305
|
+
sideQuestions.assertAvailable(resolved);
|
|
306
|
+
}
|
|
307
|
+
refuseWorkingSlash(current, text);
|
|
308
|
+
});
|
|
268
309
|
// A dispatched worker's brief is often long enough for Claude Code to
|
|
269
310
|
// swallow the Enter; a slash command opens a menu an Enter would answer.
|
|
270
311
|
const submitted = target.source !== "claude" || text.trim().startsWith("/")
|
|
@@ -287,9 +328,10 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
287
328
|
const target = targetSchema.parse(data.target);
|
|
288
329
|
// Uploads store bytes without answering or interrupting the agent.
|
|
289
330
|
// They still require fresh identity, just like prompt mutations.
|
|
290
|
-
const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model"].includes(url.pathname);
|
|
331
|
+
const sendsInput = ["/v1/prompt", "/v1/keys", "/v1/secret", "/v1/model", "/v1/settings"].includes(url.pathname);
|
|
291
332
|
if (sendsInput) {
|
|
292
333
|
modelSwitcher.assertAvailable(target);
|
|
334
|
+
settingsSwitcher.assertAvailable(target);
|
|
293
335
|
sideQuestions.assertAvailable(target);
|
|
294
336
|
}
|
|
295
337
|
// A key press is how a prompt the agent draws in its terminal gets
|
|
@@ -298,6 +340,7 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
298
340
|
const pane = await validateTarget(target, false, sendsInput || url.pathname === "/v1/upload");
|
|
299
341
|
if (sendsInput) {
|
|
300
342
|
modelSwitcher.assertAvailable(target);
|
|
343
|
+
settingsSwitcher.assertAvailable(target);
|
|
301
344
|
sideQuestions.assertAvailable(target);
|
|
302
345
|
}
|
|
303
346
|
if (url.pathname === "/v1/prompt") {
|
|
@@ -305,9 +348,15 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
305
348
|
// is pending there: an approval the Hook holds or saw, or a
|
|
306
349
|
// status Herdr cannot read. Otherwise the answer keys are the way.
|
|
307
350
|
const status = String(pane.agent_status);
|
|
308
|
-
if (
|
|
351
|
+
if (data.hookQueued === true && !["idle", "done"].includes(status))
|
|
352
|
+
throw new BridgeError(409, "The worker is busy; the hand-off remains queued.", { code: "hand-off-busy" });
|
|
353
|
+
if (status === "unknown" || (["blocked", "waiting"].includes(status) && (agentHooks.approval(target) || agentHooks.terminalPrompt(target) || agentHooks.servedQuestion(target)))) {
|
|
309
354
|
throw new BridgeError(409, "This agent needs input in the terminal first.");
|
|
310
355
|
}
|
|
356
|
+
const text = typeof data.text === "string" && data.text && data.text.length <= 32768 && !/[\x00-\x08\x0b-\x1f\x7f]/.test(data.text) ? data.text : undefined;
|
|
357
|
+
const served = text === undefined ? undefined : await servedPrompt(target, target.session, text, typing);
|
|
358
|
+
if (served)
|
|
359
|
+
return served;
|
|
311
360
|
}
|
|
312
361
|
if (url.pathname === "/v1/prompt") {
|
|
313
362
|
const text = z.string().min(1).max(32768).refine(t => !/[\x00-\x08\x0b-\x1f\x7f]/.test(t)).parse(data.text);
|
|
@@ -317,20 +366,63 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
317
366
|
// A working agent queues typed text and submits it when its turn
|
|
318
367
|
// ends, which can be minutes away; waiting for that only delays
|
|
319
368
|
// the phone. The record still guards the paste for ten minutes.
|
|
369
|
+
// Claude Code is the exception: it takes a message typed mid-turn at
|
|
370
|
+
// once and runs UserPromptSubmit about a third of a second later, so a
|
|
371
|
+
// busy Claude gets the idle wait and the phone a confirmed delivery.
|
|
320
372
|
refuseWorkingSlash(pane, text, target.source);
|
|
321
373
|
if (sideQuestionText(target.source, text) !== undefined) {
|
|
322
374
|
// Claude's `/btw` runs beside the turn and never reaches the transcript:
|
|
323
375
|
// the Hook reads its panel and the answer arrives as a side-answer frame.
|
|
324
|
-
typing();
|
|
376
|
+
await typing();
|
|
325
377
|
return { ok: true, delivered: true, sideQuestion: await sideQuestions.ask(target, pane, text) };
|
|
326
378
|
}
|
|
327
379
|
if (target.source === "codex" && /^\s*\/model\s+\S/i.test(text))
|
|
328
380
|
throw new BridgeError(422, "Use the model picker to switch Codex models.");
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
381
|
+
// A Codex pane on the Hook's own app-server takes the prompt as a turn on
|
|
382
|
+
// its thread, acknowledged with the turn id; nothing is typed. A slash
|
|
383
|
+
// command is the TUI's own and is still typed. An unreachable server
|
|
384
|
+
// sent nothing, so the pane is typed into instead; a request that may
|
|
385
|
+
// have reached it is reported uncertain and never retried.
|
|
386
|
+
const owned = text.trim().startsWith("/") ? undefined : codexServers.forTarget(target);
|
|
387
|
+
if (owned) {
|
|
388
|
+
await typing();
|
|
389
|
+
try {
|
|
390
|
+
const { turnId } = await codexServers.prompt(owned, text);
|
|
391
|
+
return { ok: true, delivered: true, turnId };
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
if (error instanceof AppServerRpcError)
|
|
395
|
+
throw new BridgeError(409, `Codex refused the message: ${error.message}`);
|
|
396
|
+
if (!(error instanceof CodexServerUnavailable))
|
|
397
|
+
return { ok: true, deliveryUncertain: true };
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
let busy = String(pane.agent_status) === "working";
|
|
401
|
+
let outcome = await promptWithStartupRetry(async () => {
|
|
402
|
+
const refused = new AbortController();
|
|
403
|
+
const expected = agentHooks.expectDelivery(target, text, busy && target.source !== "claude" ? 300 : 1_500, refused.signal);
|
|
404
|
+
await typing();
|
|
405
|
+
try {
|
|
406
|
+
await terminalProvider().prompt(target.server, target.pane, text);
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
if (agentNotReady(error))
|
|
410
|
+
refused.abort();
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
return expected;
|
|
414
|
+
}, async () => {
|
|
415
|
+
// The same conversation can move to another terminal instance. A
|
|
416
|
+
// retry must retain both bindings and all input reservations.
|
|
417
|
+
const current = await validateTarget(target, true, true);
|
|
418
|
+
if (current.terminal_id !== pane.terminal_id)
|
|
419
|
+
throw new BridgeError(409, "This agent pane changed. Reopen the chat.");
|
|
420
|
+
modelSwitcher.assertAvailable(target);
|
|
421
|
+
settingsSwitcher.assertAvailable(target);
|
|
422
|
+
sideQuestions.assertAvailable(target);
|
|
423
|
+
refuseWorkingSlash(current, text, target.source);
|
|
424
|
+
busy = String(current.agent_status) === "working";
|
|
425
|
+
}, data.hookQueued === true ? 0 : 20_000);
|
|
334
426
|
// Only Claude confirms plain prompts through its hook, and a slash
|
|
335
427
|
// command opens a menu that a second Enter would answer.
|
|
336
428
|
if (outcome === "pending" && target.source === "claude" && !text.trim().startsWith("/")) {
|
|
@@ -346,8 +438,11 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
346
438
|
// along so a Codex /permissions walk can find its confirmation.
|
|
347
439
|
if (/^\/[a-z][a-z0-9_-]*$/i.test(text.trim()))
|
|
348
440
|
agentHooks.menuOpened(target, text.trim());
|
|
441
|
+
const deliveryId = deliveryIdSchema.parse(data.deliveryId);
|
|
349
442
|
if (outcome === "delivered") {
|
|
350
443
|
result = { ok: true, delivered: true };
|
|
444
|
+
if (deliveryId)
|
|
445
|
+
agentHooks.trackDelivery(deliveryId, target, text, "delivered");
|
|
351
446
|
}
|
|
352
447
|
else if (outcome === "unsubmitted") {
|
|
353
448
|
result = { ok: true, deliveryUncertain: true, unsubmitted: true };
|
|
@@ -355,22 +450,44 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
355
450
|
else {
|
|
356
451
|
// The agent has not submitted it yet (a busy agent queues typed
|
|
357
452
|
// input). Recheck fresh identity and never retry; a late
|
|
358
|
-
// submission to another conversation is still refused above.
|
|
453
|
+
// submission to another conversation is still refused above. A bare
|
|
454
|
+
// ok acknowledges transport only, even if this is still the same
|
|
455
|
+
// conversation. Callers needing a submitted turn require delivered.
|
|
359
456
|
let confirmed = false;
|
|
360
457
|
try {
|
|
361
458
|
const current = findPane(await snapshot(target.server), target);
|
|
362
459
|
confirmed = !!current && current.terminal_id === pane.terminal_id && await paneIdentity(target.server, current, true) === target.session;
|
|
363
460
|
}
|
|
364
461
|
catch { /* No reliable post-delivery identity. */ }
|
|
365
|
-
|
|
462
|
+
// Still this conversation, in the same terminal: the agent holds the
|
|
463
|
+
// message (a busy turn queues it) and its hook has not submitted it
|
|
464
|
+
// yet. Queued, not delivered; `/v1/prompt/status` says when it lands.
|
|
465
|
+
if (confirmed && deliveryId)
|
|
466
|
+
agentHooks.trackDelivery(deliveryId, target, text, "queued");
|
|
467
|
+
result = { ok: true, ...(!confirmed ? { deliveryUncertain: true } : { queued: true }) };
|
|
366
468
|
}
|
|
367
469
|
}
|
|
470
|
+
else if (url.pathname === "/v1/prompt/status") {
|
|
471
|
+
// Asked by the phone's own delivery id, so no text is matched again.
|
|
472
|
+
const id = deliveryIdSchema.parse(data.deliveryId);
|
|
473
|
+
if (!id)
|
|
474
|
+
throw new BridgeError(400, "Name the message by its deliveryId.");
|
|
475
|
+
result = { ok: true, state: agentHooks.deliveryState(id, target) };
|
|
476
|
+
}
|
|
368
477
|
else if (url.pathname === "/v1/side-question/dismiss") {
|
|
369
478
|
result = sideQuestions.dismiss(target, z.string().uuid().parse(data.id));
|
|
370
479
|
}
|
|
371
480
|
else if (url.pathname === "/v1/model") {
|
|
372
481
|
result = await modelSwitcher.switch(target, data);
|
|
373
482
|
}
|
|
483
|
+
else if (url.pathname === "/v1/settings") {
|
|
484
|
+
result = await settingsSwitcher.switch(target, data);
|
|
485
|
+
}
|
|
486
|
+
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
|
+
// A served OpenCode pane: Esc aborts its turn or declines its question,
|
|
488
|
+
// a digit answers its question, over its own API.
|
|
489
|
+
result = { ok: true };
|
|
490
|
+
}
|
|
374
491
|
else if (url.pathname === "/v1/keys") {
|
|
375
492
|
const keys = z.array(z.enum(ANSWER_KEYS)).min(1).max(4).parse(data.keys);
|
|
376
493
|
const status = String(pane.agent_status), menu = agentHooks.menuOpen(target);
|
|
@@ -386,8 +503,15 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
386
503
|
if (!cancelled && !holding && (keys.every(key => key === "Escape") ? !["working", "blocked", "waiting", "unknown"].includes(status)
|
|
387
504
|
: !["blocked", "waiting", "unknown"].includes(status)))
|
|
388
505
|
throw new BridgeError(409, keys.every(key => key === "Escape") ? "This agent is no longer working." : "This agent is not waiting for an answer.");
|
|
506
|
+
// Esc on a working Codex pane the Hook runs on its own app-server:
|
|
507
|
+
// decline the thread's parked requests, then interrupt the turn.
|
|
508
|
+
const owned = !cancelled && !holding && keys.every(key => key === "Escape") ? codexServers.forTarget(target) : undefined;
|
|
389
509
|
if (cancelled) {
|
|
390
510
|
result = { ok: true };
|
|
511
|
+
}
|
|
512
|
+
else if (owned && await codexServers.interrupt(owned).catch(() => false)) {
|
|
513
|
+
agentHooks.clearTerminalPrompt(target);
|
|
514
|
+
result = { ok: true, interrupted: true };
|
|
391
515
|
// An older phone answers a released AskUserQuestion one question at
|
|
392
516
|
// a time with its digits; the Hook walks that question in the pane
|
|
393
517
|
// and submits the set after the last.
|
|
@@ -464,7 +588,7 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
464
588
|
const allowed = paths.length ? await agentHooks.changes.recordedPaths(`${target.source}:${target.session}`) : [];
|
|
465
589
|
if (paths.length) {
|
|
466
590
|
try {
|
|
467
|
-
allowed.push(...await conversationNamedPaths(await
|
|
591
|
+
allowed.push(...await conversationNamedPaths(await targetTranscriptPath(target), target.source, cwd, abort.signal));
|
|
468
592
|
}
|
|
469
593
|
catch {
|
|
470
594
|
abort.signal.throwIfAborted(); /* Missing transcripts grant no extra paths; recorded scope still works. */
|
|
@@ -507,11 +631,14 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
507
631
|
else if (url.pathname === "/v1/approvals/answer") {
|
|
508
632
|
const actionId = target.source === "opencode"
|
|
509
633
|
? z.string().regex(/^[A-Za-z0-9_]{1,200}$/).parse(data.actionId)
|
|
510
|
-
: z.string().uuid().parse(data.actionId);
|
|
634
|
+
: z.union([z.string().uuid(), z.string().regex(/^dialog-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)]).parse(data.actionId);
|
|
511
635
|
await agentHooks.answer(target, actionId, data.decision, data.updatedInput);
|
|
512
636
|
result = { ok: true };
|
|
513
637
|
}
|
|
514
638
|
else if (url.pathname === "/v1/questions/answer") {
|
|
639
|
+
// Only a Codex answer can carry the phone's uploads (codex-questions).
|
|
640
|
+
if (target.source !== "codex" && Array.isArray(data.attachments) && data.attachments.length)
|
|
641
|
+
throw new BridgeError(400, "This question takes no attachments.");
|
|
515
642
|
if (target.source === "claude") {
|
|
516
643
|
// Claude's AskUserQuestion, answered in its terminal dialog: the
|
|
517
644
|
// phone names the questions it shows, and the Hook answers only a
|
|
@@ -519,6 +646,11 @@ async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
519
646
|
const { questions, answers } = claudeQuestionAnswer(data);
|
|
520
647
|
await agentHooks.answerClaudeQuestions(target, questions, answers);
|
|
521
648
|
}
|
|
649
|
+
else if (target.source === "opencode") {
|
|
650
|
+
// A served OpenCode pane's question, answered over its own API.
|
|
651
|
+
const { questions, answers } = claudeQuestionAnswer(data);
|
|
652
|
+
await agentHooks.answerServedQuestion(target, questions, answers);
|
|
653
|
+
}
|
|
522
654
|
else
|
|
523
655
|
await codexQuestions.answer(target, data);
|
|
524
656
|
result = { ok: true };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HandOffQueue } from "./hand-off-queue.js";
|
|
1
2
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
3
|
import type { FanoutMessages } from "./fanout-messages.js";
|
|
3
4
|
import type { ModuleSnapshot } from "../modules/runtime.js";
|
|
@@ -12,6 +13,7 @@ import type { CodexQuestions } from "./questions.js";
|
|
|
12
13
|
import type { TabActivityStore } from "./tab-activity.js";
|
|
13
14
|
import type { ModelCatalog } from "./models.js";
|
|
14
15
|
import type { ModelSwitcher } from "./model-switch.js";
|
|
16
|
+
import type { SettingsSwitcher } from "./settings-switch.js";
|
|
15
17
|
import type { SideQuestions } from "./side-questions.js";
|
|
16
18
|
import { type AccountUsageReader } from "./usage.js";
|
|
17
19
|
import type { ResourceMonitor } from "./resources.js";
|
|
@@ -49,12 +51,14 @@ export interface RouteContext {
|
|
|
49
51
|
scheduler?: Scheduler;
|
|
50
52
|
dispatches?: DispatchService;
|
|
51
53
|
returns?: DispatchReturns;
|
|
54
|
+
handOffs?: HandOffQueue;
|
|
52
55
|
agentHooks: AgentHooks;
|
|
53
56
|
journal: ActivityJournal;
|
|
54
57
|
tabActivity: TabActivityStore;
|
|
55
58
|
contextUsage: WorkspaceContextUsage;
|
|
56
59
|
modelCatalog: ModelCatalog;
|
|
57
60
|
modelSwitcher: ModelSwitcher;
|
|
61
|
+
settingsSwitcher: SettingsSwitcher;
|
|
58
62
|
sideQuestions: SideQuestions;
|
|
59
63
|
accountUsage: AccountUsageReader;
|
|
60
64
|
resources: ResourceMonitor;
|
|
@@ -76,6 +80,7 @@ export declare const capabilities: {
|
|
|
76
80
|
terminal: string;
|
|
77
81
|
shell: string;
|
|
78
82
|
herdr: boolean;
|
|
83
|
+
sessionRename: boolean;
|
|
79
84
|
diff: boolean;
|
|
80
85
|
webServers: boolean;
|
|
81
86
|
webPreview: string;
|
|
@@ -89,16 +94,22 @@ export declare const capabilities: {
|
|
|
89
94
|
subagents: boolean;
|
|
90
95
|
sideQuestions: boolean;
|
|
91
96
|
dispatch: boolean;
|
|
97
|
+
conductorSets: boolean;
|
|
92
98
|
approvalPush: string;
|
|
93
99
|
simulators: boolean;
|
|
94
100
|
code: boolean;
|
|
95
101
|
overviewStream: boolean;
|
|
96
102
|
speech: boolean;
|
|
97
103
|
speechTimestamps: boolean;
|
|
104
|
+
speechVoices: boolean;
|
|
105
|
+
speechFormats: ("mp3_44100_192" | "pcm_24000" | "pcm_44100")[];
|
|
98
106
|
transcribe: boolean;
|
|
99
107
|
memoryStore: boolean;
|
|
100
108
|
promptOnce: boolean;
|
|
109
|
+
promptStatus: boolean;
|
|
101
110
|
resources: boolean;
|
|
111
|
+
sudo: boolean;
|
|
112
|
+
sudoOutcome: boolean;
|
|
102
113
|
};
|
|
103
114
|
export declare function capabilitiesForModules(snapshot: ModuleSnapshot): Record<string, unknown>;
|
|
104
115
|
export declare function requireRoute(snapshot: ModuleSnapshot, method: string, route: string): void;
|