@phren/cli 0.3.67 → 0.3.69
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-hook-callback.js +11 -2
- package/dist/bridge/agent-hooks.d.ts +11 -1
- package/dist/bridge/agent-hooks.js +259 -40
- package/dist/bridge/changes.d.ts +2 -2
- package/dist/bridge/changes.js +11 -9
- package/dist/bridge/checkpoints.d.ts +24 -0
- package/dist/bridge/checkpoints.js +423 -0
- package/dist/bridge/claude-input-state.d.ts +14 -0
- package/dist/bridge/claude-input-state.js +58 -0
- package/dist/bridge/claude-queue.js +5 -2
- package/dist/bridge/claude-suggestion.d.ts +3 -0
- package/dist/bridge/claude-suggestion.js +10 -0
- package/dist/bridge/codex-threads.d.ts +7 -1
- package/dist/bridge/codex-threads.js +185 -56
- package/dist/bridge/conversation-search.d.ts +20 -0
- package/dist/bridge/conversation-search.js +928 -0
- package/dist/bridge/git-watch.d.ts +46 -0
- package/dist/bridge/git-watch.js +351 -0
- package/dist/bridge/git-worktree-remove.d.ts +44 -0
- package/dist/bridge/git-worktree-remove.js +140 -0
- package/dist/bridge/git-worktrees.d.ts +14 -0
- package/dist/bridge/git-worktrees.js +7 -3
- package/dist/bridge/git-write-policy.js +1 -1
- package/dist/bridge/gitboy-webhooks.d.ts +3 -1
- package/dist/bridge/gitboy-webhooks.js +26 -2
- package/dist/bridge/herdr.d.ts +6 -1
- package/dist/bridge/herdr.js +56 -10
- package/dist/bridge/hook-fast.js +13 -1
- package/dist/bridge/input-classification.d.ts +33 -0
- package/dist/bridge/input-classification.js +84 -0
- package/dist/bridge/pane-status.d.ts +3 -3
- package/dist/bridge/pane-status.js +16 -8
- package/dist/bridge/prompt-deliveries.d.ts +30 -4
- package/dist/bridge/prompt-deliveries.js +365 -13
- package/dist/bridge/prompt-identity.d.ts +8 -0
- package/dist/bridge/prompt-identity.js +15 -0
- package/dist/bridge/request-origin.js +2 -1
- package/dist/bridge/schedule-events.d.ts +17 -0
- package/dist/bridge/schedule-events.js +53 -0
- package/dist/bridge/schedule-format.d.ts +22 -2
- package/dist/bridge/schedule-format.js +40 -5
- package/dist/bridge/schedule-update.js +2 -1
- package/dist/bridge/schedule-watch.js +15 -5
- package/dist/bridge/schedules.d.ts +9 -0
- package/dist/bridge/schedules.js +120 -7
- package/dist/bridge/server-pane-routes.d.ts +7 -8
- package/dist/bridge/server-pane-routes.js +186 -82
- package/dist/bridge/server-routes.d.ts +26 -2
- package/dist/bridge/server-routes.js +180 -56
- package/dist/bridge/server-stream.js +66 -15
- package/dist/bridge/server.js +25 -7
- package/dist/bridge/session-activity.d.ts +49 -4
- package/dist/bridge/session-activity.js +47 -0
- package/dist/bridge/session-evidence.d.ts +18 -0
- package/dist/bridge/session-evidence.js +72 -0
- package/dist/bridge/session-seen.d.ts +23 -0
- package/dist/bridge/session-seen.js +69 -0
- package/dist/bridge/tab-activity.d.ts +26 -1
- package/dist/bridge/tab-activity.js +64 -9
- package/dist/bridge/terminal-resolve.d.ts +20 -0
- package/dist/bridge/terminal-resolve.js +145 -0
- package/dist/bridge/terminal-tmux.d.ts +8 -3
- package/dist/bridge/terminal-tmux.js +59 -7
- package/dist/bridge/transcript-claude.d.ts +12 -2
- package/dist/bridge/transcript-claude.js +91 -13
- package/dist/bridge/transcript-index.d.ts +4 -2
- package/dist/bridge/transcript-index.js +6 -5
- package/dist/bridge/transcript-preview.d.ts +16 -1
- package/dist/bridge/transcript-preview.js +171 -27
- package/dist/bridge/transcripts.d.ts +41 -1
- package/dist/bridge/transcripts.js +181 -23
- package/dist/bridge/turn-queue-pane.d.ts +6 -0
- package/dist/bridge/turn-queue-pane.js +30 -0
- package/dist/bridge/turn-queue.d.ts +86 -0
- package/dist/bridge/turn-queue.js +280 -0
- package/dist/bridge/turn-records.d.ts +18 -0
- package/dist/bridge/turn-records.js +77 -5
- package/dist/bridge-hook.mjs +7074 -3173
- package/dist/cli/config-shared.js +2 -1
- package/dist/cli/schedules.js +6 -1
- package/dist/content/secrets.js +1 -1
- package/dist/modules/registry.js +12 -11
- package/package.json +1 -1
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import { checkpointRoute } from "./checkpoints.js";
|
|
2
|
+
import { turnQueueRoute } from "./turn-queue.js";
|
|
1
3
|
import { EXPECTED_REPOSITORY_REQUIRED, isGitWriteRoute } from "./git-write-policy.js";
|
|
2
4
|
import path from "node:path";
|
|
3
5
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
4
6
|
import { z } from "zod";
|
|
5
7
|
import { TURN_ENDED_WITHOUT_IT } from "./prompt-deliveries.js";
|
|
6
|
-
import {
|
|
8
|
+
import { screenDialog } from "./pane-status.js";
|
|
9
|
+
import { claudeInputMatches, claudeSubagentView } from "./claude-suggestion.js";
|
|
7
10
|
import { gitBranches, gitDiscard, gitLog, gitPulls, gitShow, gitStage, gitStatus, gitTree, gitUnstage } from "./git.js";
|
|
8
11
|
import { fanoutWorktrees } from "./fanouts.js";
|
|
9
12
|
import { gitWorktrees, resolveWorktree } from "./git-worktrees.js";
|
|
13
|
+
import { previewWorktreeRemoval, removeWorktree } from "./git-worktree-remove.js";
|
|
10
14
|
import { gitCommit, gitHostToken, gitMergeRequest, gitPullRequest, gitPush } from "./git-publish.js";
|
|
11
15
|
import { gitCheckout, gitFetch, gitPull } from "./git-sync.js";
|
|
12
16
|
import { gitApply, gitFile, sessionChanges } from "./git-review.js";
|
|
13
|
-
import { findPane, paneAgentName, paneChatState, paneIdentity, snapshot, startingPane, trustedDirectory, validateStartingTarget, validateTarget } from "./herdr.js";
|
|
17
|
+
import { findPane, paneAgentName, paneChatState, paneIdentity, serversStrict, snapshot, startingPane, trustedDirectory, validateStartingTarget, validateTarget } from "./herdr.js";
|
|
14
18
|
import { agentNotReady, terminalProvider } from "./terminal.js";
|
|
15
19
|
import { AppServerRpcError } from "./codex-app-server.js";
|
|
16
20
|
import { CodexServerUnavailable, codexServers } from "./codex-servers.js";
|
|
@@ -19,7 +23,7 @@ import { PERMISSION_MODE_VALUES, refuseAgentOrigin } from "./permission-mode.js"
|
|
|
19
23
|
import { sessionWebServers } from "./session-servers.js";
|
|
20
24
|
import { takesPrompt } from "./session-activity.js";
|
|
21
25
|
import { gitRoot, repositoryDiff, withGitReadDeadline } from "./projects.js";
|
|
22
|
-
import { BridgeError, MAX_FRAME, object, objects, startingTargetSchema, targetSchema } from "./protocol.js";
|
|
26
|
+
import { BridgeError, MAX_FRAME, object, objects, serverName, startingTargetSchema, targetSchema } from "./protocol.js";
|
|
23
27
|
import { childAgent, childAgentTree, conversationNamedPaths, targetTranscriptPath } from "./transcripts.js";
|
|
24
28
|
import { sideQuestionText } from "./side-questions.js";
|
|
25
29
|
import { saveUpload } from "./uploads.js";
|
|
@@ -92,6 +96,72 @@ export function herdrWorktreeWorkers(s) {
|
|
|
92
96
|
}
|
|
93
97
|
return workers;
|
|
94
98
|
}
|
|
99
|
+
/** Every live pane on a server with the folder it is running in, for a
|
|
100
|
+
* worktree-removal preview's session check. */
|
|
101
|
+
function paneSessions(s) {
|
|
102
|
+
const sessions = [];
|
|
103
|
+
for (const pane of objects(s.panes)) {
|
|
104
|
+
const cwd = typeof pane.foreground_cwd === "string" ? pane.foreground_cwd : pane.cwd;
|
|
105
|
+
if (typeof cwd !== "string" || !cwd) {
|
|
106
|
+
throw new BridgeError(503, "Could not determine a live pane's directory.", { code: "worktree-session-check-failed" });
|
|
107
|
+
}
|
|
108
|
+
const label = [pane.title, pane.label, paneAgentName(s, pane)].find(value => typeof value === "string" && value);
|
|
109
|
+
sessions.push({ pane: String(pane.pane_id), title: label || String(pane.pane_id), cwd });
|
|
110
|
+
}
|
|
111
|
+
return sessions;
|
|
112
|
+
}
|
|
113
|
+
/** A snapshot of a server that has stopped since discovery has no panes; any
|
|
114
|
+
* other failure leaves session discovery incomplete and must fail the request. */
|
|
115
|
+
function stoppedServer(error) {
|
|
116
|
+
if (!(error instanceof BridgeError))
|
|
117
|
+
return false;
|
|
118
|
+
const code = String(error.details?.code ?? "");
|
|
119
|
+
return code === "herdr-not-running" || code === "herdr-stale-socket" || code === "not_running";
|
|
120
|
+
}
|
|
121
|
+
/** Every live pane on every running terminal server, including the requesting
|
|
122
|
+
* one even when discovery left it out. A server that cannot be read, or any
|
|
123
|
+
* discovery failure, fails the request: removal is never allowed on an
|
|
124
|
+
* incomplete session check. */
|
|
125
|
+
async function allPaneSessions(requested = []) {
|
|
126
|
+
const running = await serversStrict();
|
|
127
|
+
const names = [...new Set([...requested, ...running.map(server => String(server.session)).filter(Boolean)])];
|
|
128
|
+
const snapshots = await Promise.all(names.map(async (name) => {
|
|
129
|
+
try {
|
|
130
|
+
return await snapshot(name);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (stoppedServer(error))
|
|
134
|
+
return { panes: [] };
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
return snapshots.flatMap(paneSessions);
|
|
139
|
+
}
|
|
140
|
+
/** The pane a worktree-removal request names: the full target when the app
|
|
141
|
+
* sends one, else the contract's optional server/pane pair. With no pane the
|
|
142
|
+
* Hook's own folder stands in. */
|
|
143
|
+
async function worktreeRemovalContext(data) {
|
|
144
|
+
const target = targetSchema.safeParse(data.target);
|
|
145
|
+
if (target.success) {
|
|
146
|
+
const pane = await validateTarget(target.data);
|
|
147
|
+
const cwd = await trustedDirectory(pane);
|
|
148
|
+
return { cwd, paneRoot: await gitRoot(cwd), sessions: await allPaneSessions([target.data.server]) };
|
|
149
|
+
}
|
|
150
|
+
const server = serverName.parse(typeof data.server === "string" && data.server ? data.server : "default");
|
|
151
|
+
const paneId = z.string().min(1).max(200).optional().parse(data.pane);
|
|
152
|
+
if (paneId === undefined) {
|
|
153
|
+
// No pane names the repository, so the Hook's own folder does; every
|
|
154
|
+
// session on every running server is still checked for one inside it.
|
|
155
|
+
const cwd = process.cwd();
|
|
156
|
+
return { cwd, paneRoot: await gitRoot(cwd), sessions: await allPaneSessions([server]) };
|
|
157
|
+
}
|
|
158
|
+
const s = await snapshot(server);
|
|
159
|
+
const pane = objects(s.panes).find(item => item.pane_id === paneId);
|
|
160
|
+
if (!pane)
|
|
161
|
+
throw new BridgeError(404, "That pane is not running on this computer.");
|
|
162
|
+
const cwd = await trustedDirectory(pane);
|
|
163
|
+
return { cwd, paneRoot: await gitRoot(cwd), sessions: await allPaneSessions([server]) };
|
|
164
|
+
}
|
|
95
165
|
/** The phone can press these and nothing else; never a typed string.
|
|
96
166
|
* `AltUp` is Codex's "edit/answer the last queued follow-up": it opens the
|
|
97
167
|
* queue, after which the option key (or typed text) is the answer. */
|
|
@@ -153,28 +223,46 @@ async function relaysSuggestion(target, text) {
|
|
|
153
223
|
}
|
|
154
224
|
/** Herdr answered the request with a refusal (a 409 carrying its own error code): it performed nothing. */
|
|
155
225
|
const herdrRefused = (error) => error instanceof BridgeError && error.status === 409 && typeof error.details?.herdrCode === "string";
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
226
|
+
/** Fresh terminal and conversation evidence for a delivery follow-up. Failure
|
|
227
|
+
* ends recovery; a later valid submission can still settle the failed receipt. */
|
|
228
|
+
async function deliveryPane(target, terminal) {
|
|
229
|
+
const pane = findPane(await snapshot(target.server), target);
|
|
230
|
+
if (!pane || typeof terminal !== "string" || pane.terminal_id !== terminal || pane.agent !== target.source)
|
|
231
|
+
throw new Error("The terminal instance changed or could not be verified.");
|
|
232
|
+
if (await paneIdentity(target.server, pane, true) !== target.session)
|
|
233
|
+
throw new Error("The conversation changed or could not be verified.");
|
|
234
|
+
return pane;
|
|
235
|
+
}
|
|
236
|
+
/** Screen reads cannot authorize a later key write: neither tmux nor Herdr
|
|
237
|
+
* exposes an atomic Claude composer/identity/held-state check-and-submit.
|
|
238
|
+
* Observe the receipt and report what can be verified, without writing keys.
|
|
239
|
+
* In particular, expanding a collapsed paste with keys would have the same
|
|
240
|
+
* race and still would not expose authoritative full composer text. */
|
|
241
|
+
async function observeIdleDelivery(agentHooks, target, terminal, text, id) {
|
|
242
|
+
const fail = (reason) => { agentHooks.deliveries.fail(id, target, reason); return "unsubmitted"; };
|
|
243
|
+
const guards = promptGuards(agentHooks, target);
|
|
244
|
+
try {
|
|
245
|
+
if (!id)
|
|
246
|
+
return fail("No delivery identity is available; check the terminal.");
|
|
247
|
+
const pane = await deliveryPane(target, terminal);
|
|
248
|
+
if (pane.agent_status === "working" && !guards.held())
|
|
249
|
+
return await agentHooks.deliveries.awaitLate(target, text);
|
|
250
|
+
if (!["idle", "done"].includes(String(pane.agent_status)))
|
|
251
|
+
return fail("The agent is not idle or done; observation stopped.");
|
|
252
|
+
if (guards.held())
|
|
253
|
+
return fail("The agent has a held approval, question or terminal prompt; observation stopped.");
|
|
254
|
+
const screen = await guards.screen();
|
|
255
|
+
// These are observations only. The owner or harness may change the input
|
|
256
|
+
// even before readScreen resolves; no screen result permits an Enter.
|
|
257
|
+
if (!agentHooks.deliveries.pending(target, text, id))
|
|
258
|
+
return agentHooks.deliveries.status(id, target).state === "delivered" ? "delivered" : "unsubmitted";
|
|
259
|
+
if (screenDialog(target.source, screen) || !claudeInputMatches(screen, text))
|
|
260
|
+
return fail("The full message cannot be verified in the input box; check the terminal.");
|
|
261
|
+
return fail("The message is visible but cannot be safely resubmitted; check and submit it in the terminal.");
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
return fail(error instanceof Error ? error.message : "The delivery checks failed; check the terminal.");
|
|
164
265
|
}
|
|
165
|
-
catch {
|
|
166
|
-
return "unknown";
|
|
167
|
-
} };
|
|
168
|
-
// A pane that turned working started a turn: its UserPromptSubmit is on its way (the agent runs its
|
|
169
|
-
// other hooks too). Wait for it rather than answering "queued" for a message the agent took.
|
|
170
|
-
if (await status() === "working")
|
|
171
|
-
return await agentHooks.deliveries.awaitLate(target, text);
|
|
172
|
-
const late = agentHooks.deliveries.awaitLate(target, text);
|
|
173
|
-
await terminalProvider().sendKeys(target.server, target.pane, ["enter"]);
|
|
174
|
-
const outcome = await late;
|
|
175
|
-
if (outcome !== "pending")
|
|
176
|
-
return outcome;
|
|
177
|
-
return await status() === "working" ? "pending" : "unsubmitted";
|
|
178
266
|
}
|
|
179
267
|
/** A Claude pane showing a subagent's view (its empty input reads "Message
|
|
180
268
|
* @<agent>…") takes typed text for that subagent, so a phone message never
|
|
@@ -253,76 +341,64 @@ export function retryAfterSubagentView(agentHooks, target, terminal, text, id, i
|
|
|
253
341
|
const expected = agentHooks.deliveries.expect(target, text, 1_500, undefined, id, typeof terminal === "string" ? terminal : undefined);
|
|
254
342
|
await terminalProvider().prompt(target.server, target.pane, text);
|
|
255
343
|
if (await expected === "pending")
|
|
256
|
-
await
|
|
344
|
+
await observeIdleDelivery(agentHooks, target, terminal, text, id);
|
|
257
345
|
};
|
|
258
346
|
const schedule = () => { const timer = setTimeout(() => void look().catch(() => undefined), intervalMs); timer.unref?.(); };
|
|
259
347
|
schedule();
|
|
260
348
|
}
|
|
261
|
-
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
export function followQueuedDelivery(agentHooks, target, terminal, text, intervalMs = 2_000) {
|
|
268
|
-
const started = Date.now();
|
|
269
|
-
let finishedLooks = 0;
|
|
349
|
+
/** Observe while the original conversation works, then allow 30 seconds for
|
|
350
|
+
* its submission acknowledgement after it finishes. A new legitimate turn
|
|
351
|
+
* resets that window. No observation sends input to the terminal. */
|
|
352
|
+
export function followQueuedDelivery(agentHooks, target, terminal, text, id, intervalMs = 2_000) {
|
|
353
|
+
let finishedAt;
|
|
354
|
+
const fail = (reason) => agentHooks.deliveries.fail(id, target, reason);
|
|
270
355
|
const look = async () => {
|
|
271
|
-
if (!agentHooks.deliveries.pending(target, text
|
|
356
|
+
if (!id || !agentHooks.deliveries.pending(target, text, id))
|
|
272
357
|
return;
|
|
273
|
-
let pane;
|
|
274
358
|
try {
|
|
275
|
-
pane =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
359
|
+
const pane = await deliveryPane(target, terminal);
|
|
360
|
+
const status = String(pane.agent_status);
|
|
361
|
+
if (promptGuards(agentHooks, target).held() || !["working", "idle", "done"].includes(status)) {
|
|
362
|
+
fail("The agent needs input or its status is unknown; observation stopped.");
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (status === "working")
|
|
366
|
+
finishedAt = undefined;
|
|
367
|
+
else {
|
|
368
|
+
finishedAt ??= Date.now();
|
|
369
|
+
if (Date.now() - finishedAt >= 30_000) {
|
|
370
|
+
await observeIdleDelivery(agentHooks, target, terminal, text, id);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
281
374
|
schedule();
|
|
282
|
-
return;
|
|
283
375
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const status = String(pane.agent_status);
|
|
287
|
-
finishedLooks = status === "idle" || status === "done" ? finishedLooks + 1 : 0;
|
|
288
|
-
if (finishedLooks >= 2) {
|
|
289
|
-
await resubmitIfIdle(agentHooks, target, text).catch(() => undefined);
|
|
290
|
-
return;
|
|
376
|
+
catch {
|
|
377
|
+
fail("The terminal or conversation could not be verified; observation stopped.");
|
|
291
378
|
}
|
|
292
|
-
schedule();
|
|
293
379
|
};
|
|
294
380
|
const schedule = () => { const timer = setTimeout(() => void look(), intervalMs); timer.unref?.(); };
|
|
295
381
|
schedule();
|
|
296
382
|
}
|
|
297
|
-
/** A
|
|
298
|
-
*
|
|
299
|
-
* Enter): press Enter once, only while it is idle, so a dialog is never
|
|
300
|
-
* answered. False when it still has not started. */
|
|
383
|
+
/** A starting pane has no verified conversation/delivery binding yet, so
|
|
384
|
+
* observe its initial submission without sending delayed keys. */
|
|
301
385
|
async function submitStartingPrompt(server, target, terminal, looks = 4, intervalMs = 500) {
|
|
302
|
-
|
|
386
|
+
for (let look = 0; look < looks; look++) {
|
|
387
|
+
await sleep(intervalMs);
|
|
303
388
|
try {
|
|
304
389
|
const pane = findPane(await snapshot(server), target);
|
|
305
|
-
|
|
390
|
+
if (!pane || pane.terminal_id !== terminal)
|
|
391
|
+
return false;
|
|
392
|
+
if (pane.agent_status === "working")
|
|
393
|
+
return true;
|
|
394
|
+
if (!["idle", "done"].includes(String(pane.agent_status)))
|
|
395
|
+
return false;
|
|
306
396
|
}
|
|
307
397
|
catch {
|
|
308
|
-
return
|
|
398
|
+
return false;
|
|
309
399
|
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
for (let look = 0; look < looks; look++) {
|
|
313
|
-
await sleep(intervalMs);
|
|
314
|
-
const current = await status();
|
|
315
|
-
if (current !== "idle" && current !== "done")
|
|
316
|
-
return current;
|
|
317
|
-
}
|
|
318
|
-
return "idle";
|
|
319
|
-
};
|
|
320
|
-
const first = await settled();
|
|
321
|
-
if (first !== "idle")
|
|
322
|
-
return first !== "gone";
|
|
323
|
-
await terminalProvider().sendKeys(server, target.pane, ["enter"]);
|
|
324
|
-
const second = await settled();
|
|
325
|
-
return second !== "idle" && second !== "gone";
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
326
402
|
}
|
|
327
403
|
/** One key per character; Herdr's send_keys takes single characters and named
|
|
328
404
|
* keys only, and a tty password read is corrupted by a bracketed paste. */
|
|
@@ -386,6 +462,11 @@ function deliveryReply(agentHooks, id, target, text) {
|
|
|
386
462
|
...(status.state === "queued" ? { queued: true } : {}), ...(status.reason ? { reason: status.reason } : {}) };
|
|
387
463
|
}
|
|
388
464
|
export async function paneRoute(ctx, url, data, response, headers = {}) {
|
|
465
|
+
if (url.pathname === "/v1/prompt/after-turn" || url.pathname.startsWith("/v1/prompt/after-turn/")) {
|
|
466
|
+
if (!ctx.turnQueue)
|
|
467
|
+
throw new BridgeError(404, "This Hook has no after-turn queue.");
|
|
468
|
+
return turnQueueRoute(ctx.turnQueue, url.pathname, data);
|
|
469
|
+
}
|
|
389
470
|
if (isGitWriteRoute(url.pathname) && data.expectedRepository === undefined) {
|
|
390
471
|
ctx.gitWrites?.record(url.pathname, headers);
|
|
391
472
|
if (EXPECTED_REPOSITORY_REQUIRED)
|
|
@@ -413,7 +494,15 @@ export async function paneRoute(ctx, url, data, response, headers = {}) {
|
|
|
413
494
|
export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
414
495
|
const { agentHooks, modelSwitcher, settingsSwitcher, permissionModeSwitcher, codexQuestions, sideQuestions } = ctx;
|
|
415
496
|
let result;
|
|
416
|
-
if (url.pathname === "/v1/
|
|
497
|
+
if (url.pathname === "/v1/git/worktrees/remove/preview" || url.pathname === "/v1/git/worktrees/remove") {
|
|
498
|
+
const worktree = z.string().max(64).parse(data.worktree);
|
|
499
|
+
const { cwd, paneRoot, sessions } = await worktreeRemovalContext(data);
|
|
500
|
+
if (url.pathname.endsWith("/preview"))
|
|
501
|
+
result = await previewWorktreeRemoval(cwd, worktree, { paneRoot, sessions });
|
|
502
|
+
else
|
|
503
|
+
result = await removeWorktree(cwd, worktree, z.string().min(1).max(128).parse(data.token), { paneRoot, sessions });
|
|
504
|
+
}
|
|
505
|
+
else if (url.pathname === "/v1/keys" && object(data.target).starting === true) {
|
|
417
506
|
// A folder-trust or login prompt comes before the agent has a
|
|
418
507
|
// conversation; the phone answers it on the starting binding.
|
|
419
508
|
const target = startingTargetSchema.parse(data.target);
|
|
@@ -462,8 +551,8 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
462
551
|
}
|
|
463
552
|
refuseWorkingSlash(current, text);
|
|
464
553
|
});
|
|
465
|
-
//
|
|
466
|
-
//
|
|
554
|
+
// Observe a fresh Claude pane without adding keys to its initial send;
|
|
555
|
+
// a slash command opens a menu and needs no submission observation.
|
|
467
556
|
const submitted = target.source !== "claude" || text.trim().startsWith("/")
|
|
468
557
|
|| await submitStartingPrompt(target.server, target, pane.terminal_id);
|
|
469
558
|
if (!submitted)
|
|
@@ -568,7 +657,7 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
568
657
|
catch (error) {
|
|
569
658
|
if (error instanceof AppServerRpcError) {
|
|
570
659
|
refused.abort();
|
|
571
|
-
throw new BridgeError(409, `Codex refused the message: ${error.message}
|
|
660
|
+
throw new BridgeError(409, `Codex refused the message: ${error.message}`, { promptNotSent: true });
|
|
572
661
|
}
|
|
573
662
|
if (error instanceof CodexServerUnavailable)
|
|
574
663
|
refused.abort();
|
|
@@ -596,6 +685,10 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
596
685
|
// request (its `agent.prompt` is one call). The record goes, or it would hold the pane's hand-offs.
|
|
597
686
|
if (!typed || agentNotReady(error) || herdrRefused(error))
|
|
598
687
|
refused.abort();
|
|
688
|
+
if (agentNotReady(error) || herdrRefused(error)) {
|
|
689
|
+
const refusal = error;
|
|
690
|
+
throw new BridgeError(refusal.status, refusal.message, { ...refusal.details, promptNotSent: true });
|
|
691
|
+
}
|
|
599
692
|
throw error;
|
|
600
693
|
}
|
|
601
694
|
return expected;
|
|
@@ -615,9 +708,9 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
615
708
|
// command opens a menu that a second Enter would answer.
|
|
616
709
|
if (outcome === "pending" && target.source === "claude" && !text.trim().startsWith("/")) {
|
|
617
710
|
if (!busy)
|
|
618
|
-
outcome = await
|
|
711
|
+
outcome = await observeIdleDelivery(agentHooks, target, pane.terminal_id, text, deliveryId);
|
|
619
712
|
else
|
|
620
|
-
followQueuedDelivery(agentHooks, target, pane.terminal_id, text);
|
|
713
|
+
followQueuedDelivery(agentHooks, target, pane.terminal_id, text, deliveryId);
|
|
621
714
|
}
|
|
622
715
|
if (deliveryId && target.source === "claude" && outcome !== "delivered")
|
|
623
716
|
retryAfterSubagentView(agentHooks, target, pane.terminal_id, text, deliveryId);
|
|
@@ -629,7 +722,8 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
629
722
|
if (outcome === "delivered")
|
|
630
723
|
result = { ok: true, delivered: true, state: "delivered" };
|
|
631
724
|
else if (outcome === "unsubmitted") {
|
|
632
|
-
const
|
|
725
|
+
const failed = deliveryId ? agentHooks.deliveries.status(deliveryId, target) : undefined;
|
|
726
|
+
const reason = failed?.state === "failed" && failed.reason ? failed.reason : "The agent did not take the message; it may still be in its input line.";
|
|
633
727
|
if (deliveryId)
|
|
634
728
|
agentHooks.deliveries.fail(deliveryId, target, reason);
|
|
635
729
|
result = { ok: true, deliveryUncertain: true, unsubmitted: true, ...(deliveryId ? { state: "failed", reason } : {}) };
|
|
@@ -833,6 +927,9 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
833
927
|
else if (url.pathname.startsWith("/v1/git/")) {
|
|
834
928
|
// Git routes read the pane's repository, or a spawned child's own
|
|
835
929
|
// worktree, exactly as /v1/diff resolves it.
|
|
930
|
+
const checkpoint = url.pathname.startsWith("/v1/git/checkpoints");
|
|
931
|
+
if (checkpoint && (data.child !== undefined || data.worktree !== undefined))
|
|
932
|
+
throw new BridgeError(400, "Checkpoints belong to the pane checkout; child and worktree selectors are unsupported.");
|
|
836
933
|
let cwd = await gitRepository(pane, target, data.child, data.worktree);
|
|
837
934
|
if (isGitWriteRoute(url.pathname)
|
|
838
935
|
&& data.expectedRepository !== undefined) {
|
|
@@ -842,7 +939,14 @@ export async function paneRouteOnce(ctx, url, data, response, typing) {
|
|
|
842
939
|
throw new BridgeError(409, "This pane's checkout changed. Refresh Changes before writing.", { code: "git-checkout-changed" });
|
|
843
940
|
cwd = root; // Execute in the validated root, never a path selected by the client.
|
|
844
941
|
}
|
|
845
|
-
if (
|
|
942
|
+
if (checkpoint)
|
|
943
|
+
result = await checkpointRoute(cwd, target, url.pathname === "/v1/git/checkpoints" ? "list" : url.pathname.slice("/v1/git/checkpoints/".length), data, async () => {
|
|
944
|
+
const current = await validateTarget(target, false, true);
|
|
945
|
+
if (await gitRoot(await trustedDirectory(current)) !== await gitRoot(cwd))
|
|
946
|
+
throw new BridgeError(409, "This pane’s checkout changed. Refresh Changes before writing.", { code: "git-checkout-changed" });
|
|
947
|
+
return current;
|
|
948
|
+
});
|
|
949
|
+
else if (url.pathname === "/v1/git/status")
|
|
846
950
|
result = await gitStatus(cwd, z.string().min(1).max(4096).optional().parse(data.untrackedPath));
|
|
847
951
|
else if (url.pathname === "/v1/git/worktrees")
|
|
848
952
|
result = await gitWorktrees(cwd, await worktreeWorkers(target));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TurnQueue } from "./turn-queue.js";
|
|
1
2
|
import type { ConductorSuccessionService } from "./conductor-succession.js";
|
|
2
3
|
import type { StorePulls } from "./store-pull.js";
|
|
3
4
|
import type { GitboyWebhooks } from "./gitboy-webhooks.js";
|
|
@@ -15,7 +16,7 @@ import { type DispatchReturns } from "./dispatch-returns.js";
|
|
|
15
16
|
import type { LaunchLimiter } from "./limits.js";
|
|
16
17
|
import { type Json } from "./protocol.js";
|
|
17
18
|
import type { CodexQuestions } from "./questions.js";
|
|
18
|
-
import type
|
|
19
|
+
import { type TabActivityStore } from "./tab-activity.js";
|
|
19
20
|
import type { ModelCatalog } from "./models.js";
|
|
20
21
|
import type { ModelSwitcher } from "./model-switch.js";
|
|
21
22
|
import type { PermissionModeSwitcher } from "./permission-mode.js";
|
|
@@ -49,6 +50,7 @@ export interface HookInfo {
|
|
|
49
50
|
readonly gatewayMs: number | undefined;
|
|
50
51
|
}
|
|
51
52
|
export interface RouteContext {
|
|
53
|
+
turnQueue?: TurnQueue;
|
|
52
54
|
version: string;
|
|
53
55
|
modules: ModuleSnapshot;
|
|
54
56
|
info: HookInfo;
|
|
@@ -83,7 +85,22 @@ export interface RouteContext {
|
|
|
83
85
|
}
|
|
84
86
|
/** How long the overview waits for per-tab git and transcript reads; the phone gives up at 20 s. */
|
|
85
87
|
export declare const OVERVIEW_ENRICH_BUDGET_MS = 5000;
|
|
88
|
+
type StatusRow = {
|
|
89
|
+
workspace: unknown;
|
|
90
|
+
tab: unknown;
|
|
91
|
+
status: unknown;
|
|
92
|
+
};
|
|
93
|
+
/** How long activity sampling may spend resolving background work before it
|
|
94
|
+
* leaves an unresolved row at its last known status. */
|
|
95
|
+
export declare const STATUS_ENRICH_BUDGET_MS = 2000;
|
|
96
|
+
/** The status each tab's row sends after the same background-work rules the
|
|
97
|
+
* overview applies: an idle or done tab whose ended turn still awaits shells or
|
|
98
|
+
* running children is working. The activity timer uses this while no overview
|
|
99
|
+
* is open, so its status clock still moves. A row whose background reads do not
|
|
100
|
+
* finish inside `budgetMs` is left out, which preserves its last known status. */
|
|
101
|
+
export declare function effectiveStatusRows(server: string, s: Json, budgetMs?: number, hooks?: AgentHooks): Promise<StatusRow[]>;
|
|
86
102
|
export declare const capabilities: {
|
|
103
|
+
turnCheckpoints: boolean;
|
|
87
104
|
transcript: boolean;
|
|
88
105
|
progress: boolean;
|
|
89
106
|
images: boolean;
|
|
@@ -96,6 +113,7 @@ export declare const capabilities: {
|
|
|
96
113
|
deskPresence: boolean;
|
|
97
114
|
herdr: boolean;
|
|
98
115
|
sessionRename: boolean;
|
|
116
|
+
sessionSeen: boolean;
|
|
99
117
|
diff: boolean;
|
|
100
118
|
webServers: boolean;
|
|
101
119
|
webPreview: string;
|
|
@@ -133,6 +151,7 @@ export declare const capabilities: {
|
|
|
133
151
|
memoryStore: boolean;
|
|
134
152
|
promptOnce: boolean;
|
|
135
153
|
promptStatus: boolean;
|
|
154
|
+
afterTurnQueue: boolean;
|
|
136
155
|
queuedMessageActions: string[];
|
|
137
156
|
deliveryFrames: boolean;
|
|
138
157
|
paneDeliveries: boolean;
|
|
@@ -162,6 +181,10 @@ export declare const capabilities: {
|
|
|
162
181
|
gitHosts: boolean;
|
|
163
182
|
projectHostToken: boolean;
|
|
164
183
|
gitRemoteIdentity: boolean;
|
|
184
|
+
gitWatch: boolean;
|
|
185
|
+
worktreeRemove: boolean;
|
|
186
|
+
terminalResolve: boolean;
|
|
187
|
+
conversationSearch: boolean;
|
|
165
188
|
};
|
|
166
189
|
export declare function capabilitiesForModules(snapshot: ModuleSnapshot): Record<string, unknown>;
|
|
167
190
|
export declare function requireRoute(snapshot: ModuleSnapshot, method: string, route: string): void;
|
|
@@ -173,5 +196,6 @@ export declare function selectedServer(url: URL): string;
|
|
|
173
196
|
* `/v1/overview` stream passes the shared one it already holds.
|
|
174
197
|
*/
|
|
175
198
|
export type WorkspacesReader = (server: string, s: Json, watchApprovals: boolean) => Promise<Json>;
|
|
176
|
-
export declare function workspacesReader(ctx: Pick<RouteContext, "modules" | "info" | "agentHooks" | "journal" | "tabActivity" | "contextUsage">): WorkspacesReader;
|
|
199
|
+
export declare function workspacesReader(ctx: Pick<RouteContext, "modules" | "info" | "agentHooks" | "journal" | "tabActivity" | "contextUsage" | "turnQueue">): WorkspacesReader;
|
|
177
200
|
export declare function createRouteHandler(ctx: RouteContext): (request: IncomingMessage, response: ServerResponse) => Promise<void>;
|
|
201
|
+
export {};
|