@phren/cli 0.3.72 → 0.3.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/agent-hooks.js +11 -1
- package/dist/bridge/browser-env.d.ts +1 -1
- package/dist/bridge/browser-env.js +34 -10
- package/dist/bridge/browser-watch.d.ts +12 -0
- package/dist/bridge/browser-watch.js +83 -0
- package/dist/bridge/claude-account-setup.js +3 -1
- package/dist/bridge/claude-accounts.d.ts +5 -1
- package/dist/bridge/claude-accounts.js +36 -6
- package/dist/bridge/codex-servers.d.ts +2 -0
- package/dist/bridge/codex-servers.js +1 -1
- package/dist/bridge/command.js +24 -5
- package/dist/bridge/dispatch-clone.d.ts +33 -0
- package/dist/bridge/dispatch-clone.js +176 -0
- package/dist/bridge/dispatch-command.d.ts +14 -0
- package/dist/bridge/dispatch-command.js +98 -13
- package/dist/bridge/dispatch-idempotency.d.ts +85 -0
- package/dist/bridge/dispatch-idempotency.js +235 -0
- package/dist/bridge/dispatch-returns.d.ts +6 -0
- package/dist/bridge/dispatch-returns.js +131 -1
- package/dist/bridge/dispatch-wait.d.ts +32 -0
- package/dist/bridge/dispatch-wait.js +177 -0
- package/dist/bridge/dispatch.d.ts +68 -2
- package/dist/bridge/dispatch.js +839 -25
- package/dist/bridge/fanouts.js +20 -3
- package/dist/bridge/files.d.ts +1 -1
- package/dist/bridge/git-credential.d.ts +44 -0
- package/dist/bridge/git-credential.js +113 -0
- package/dist/bridge/git-host-auth.d.ts +9 -1
- package/dist/bridge/git-host-auth.js +18 -5
- package/dist/bridge/git-host-gitboy.js +8 -1
- package/dist/bridge/git-hosts.d.ts +12 -1
- package/dist/bridge/git-publish.js +3 -2
- package/dist/bridge/herdr.d.ts +4 -0
- package/dist/bridge/herdr.js +29 -3
- package/dist/bridge/install.d.ts +1 -1
- package/dist/bridge/install.js +8 -4
- package/dist/bridge/launch-worktree.d.ts +2 -0
- package/dist/bridge/launch-worktree.js +5 -1
- package/dist/bridge/protocol.d.ts +7 -0
- package/dist/bridge/schedule-watch.js +13 -2
- package/dist/bridge/server-launch.d.ts +2 -0
- package/dist/bridge/server-launch.js +251 -145
- package/dist/bridge/server-routes.js +18 -2
- package/dist/bridge/server.js +12 -1
- package/dist/bridge/status-line-fast.d.ts +9 -0
- package/dist/bridge/status-line-fast.js +56 -0
- package/dist/bridge/terminal-herdr.d.ts +5 -1
- package/dist/bridge/terminal-herdr.js +65 -1
- package/dist/bridge/terminal-tmux.d.ts +2 -0
- package/dist/bridge/terminal-tmux.js +27 -6
- package/dist/bridge/terminal.d.ts +5 -1
- package/dist/bridge/transcript-claude.js +192 -112
- package/dist/bridge/transcript-preview.d.ts +2 -1
- package/dist/bridge/transcript-preview.js +85 -3
- package/dist/bridge/transcripts.js +17 -11
- package/dist/bridge/turn-records.js +16 -4
- package/dist/bridge/usage.d.ts +7 -1
- package/dist/bridge/usage.js +47 -31
- package/dist/bridge/worker-close.d.ts +15 -0
- package/dist/bridge/worker-close.js +304 -3
- package/dist/bridge/worker-identity.d.ts +51 -0
- package/dist/bridge/worker-identity.js +289 -0
- package/dist/bridge-hook.mjs +20857 -18606
- package/dist/cli/browser-hint.d.ts +2 -0
- package/dist/cli/browser-hint.js +21 -0
- package/dist/cli/hooks-context.d.ts +2 -2
- package/dist/cli/hooks-context.js +3 -3
- package/dist/cli/hooks.js +20 -11
- package/dist/cli-registry.js +5 -3
- package/dist/modules/registry.js +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { noteBrowserLaunch } from "./browser-watch.js";
|
|
1
3
|
import { markPaneClosed } from "./worker-close.js";
|
|
2
4
|
import { mkdir, mkdtemp, readFile, realpath, rmdir } from "node:fs/promises";
|
|
3
5
|
import { phrenStoreRoot } from "./transcripts.js";
|
|
@@ -5,7 +7,7 @@ import path from "node:path";
|
|
|
5
7
|
import { z } from "zod";
|
|
6
8
|
import { homeDir } from "../home-paths.js";
|
|
7
9
|
import { defaultPhrenPath } from "../phren-paths.js";
|
|
8
|
-
import { agentNames, findPane, isConductorName, paneChatState, paneIdentity, servers, snapshot } from "./herdr.js";
|
|
10
|
+
import { agentNames, findPane, isConductorName, paneChatState, paneIdentity, seedStartingToken, servers, snapshot } from "./herdr.js";
|
|
9
11
|
import { agentNotReady, terminalKind, terminalName, terminalProvider } from "./terminal.js";
|
|
10
12
|
import { tmuxScroll } from "./terminal-tmux.js";
|
|
11
13
|
import { intervalFromEnv } from "./limits.js";
|
|
@@ -18,6 +20,9 @@ import { groupConductor } from "./conductor-group.js";
|
|
|
18
20
|
import { clearConductor, conductorPane, noteConductorSession, readRoleState, recordConductor, runsAgent } from "./conductor-role.js";
|
|
19
21
|
import { localNames } from "./computer-names.js";
|
|
20
22
|
import { pretrustFolder } from "./folder-trust.js";
|
|
23
|
+
import { keyedExplicitEnv, prepareKeyedGitboy, removeAgentTokenFile } from "./git-credential.js";
|
|
24
|
+
import { createDispatchClone, dispatchClonePaths } from "./dispatch-clone.js";
|
|
25
|
+
import { acquireLaunchLock, markSubmitted, releaseLaunchLock } from "./worker-identity.js";
|
|
21
26
|
import { claudeHome, claudeLaunchEnv, isAccountSlug, DEFAULT_ACCOUNT } from "./claude-accounts.js";
|
|
22
27
|
import { pickClaudeAccount } from "./account-choice.js";
|
|
23
28
|
import { harnessInventoryWithin, hasUsable, launchCheckOff } from "./harnesses.js";
|
|
@@ -49,6 +54,17 @@ function effortArgs(kind, effort) {
|
|
|
49
54
|
return ["--reasoning", effort];
|
|
50
55
|
return [];
|
|
51
56
|
}
|
|
57
|
+
/** Refuse a keyed launch whose resolved arguments would skip approvals or allow everything. */
|
|
58
|
+
export function assertKeyedLaunchArgs(kind, args) {
|
|
59
|
+
const line = args.join(" ");
|
|
60
|
+
const unsafe = /--dangerously|--allow-all|--yolo|--full-auto|bypassPermissions/.test(line)
|
|
61
|
+
|| /(?:^|\s)-a\s+never(?:\s|$)/.test(line)
|
|
62
|
+
|| /(?:^|\s)-s\s+danger-full-access(?:\s|$)/.test(line)
|
|
63
|
+
|| /--ask-for-approval(?:=|\s+)never/.test(line)
|
|
64
|
+
|| /--sandbox(?:=|\s+)danger-full-access/.test(line);
|
|
65
|
+
if (unsafe)
|
|
66
|
+
throw new BridgeError(400, `A keyed ${kind} launch may not use skip-approval or allow-all flags.`);
|
|
67
|
+
}
|
|
52
68
|
/** phren's own agent runs as `phren agent`: the subcommand and its interactive TUI lead its arguments. */
|
|
53
69
|
const PHREN_AGENT_ARGS = ["agent", "-i"];
|
|
54
70
|
/**
|
|
@@ -229,6 +245,14 @@ async function startWhenShellReady(server, pane, agent) {
|
|
|
229
245
|
for (;;) {
|
|
230
246
|
try {
|
|
231
247
|
await terminalProvider().startAgent(server, pane, agent);
|
|
248
|
+
if (agent.env?.PHREN_BROWSER_SOCKET) {
|
|
249
|
+
const processes = await terminalProvider().processes(server, pane).catch(() => undefined);
|
|
250
|
+
if (processes) {
|
|
251
|
+
const s = await terminalProvider().snapshot(server).catch(() => undefined);
|
|
252
|
+
const current = s ? objects(s.panes).find(p => p.pane_id === pane) : undefined;
|
|
253
|
+
noteBrowserLaunch(processes.foregroundPids, agent.env, current ? { server, pane: current } : undefined);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
232
256
|
return;
|
|
233
257
|
}
|
|
234
258
|
catch (error) {
|
|
@@ -389,7 +413,16 @@ async function startSession(server, data, options) {
|
|
|
389
413
|
const kind = z.enum(launchKinds).parse(data.kind);
|
|
390
414
|
const effort = z.enum(launchEfforts).default("medium").parse(data.effort);
|
|
391
415
|
const named = data.account === undefined || data.account === null ? undefined : z.string().refine(isAccountSlug, "Account must be default or a lowercase slug.").parse(data.account);
|
|
392
|
-
|
|
416
|
+
let permissionMode = z.enum(PERMISSION_MODES).optional().parse(data.permissionMode ?? undefined);
|
|
417
|
+
if (data.idempotencyKey) {
|
|
418
|
+
if (kind !== "claude" && kind !== "codex") {
|
|
419
|
+
throw new BridgeError(400, "A dispatch with an idempotency key may run only claude or codex; this harness is refused.");
|
|
420
|
+
}
|
|
421
|
+
if (permissionMode && permissionMode !== "supervised") {
|
|
422
|
+
throw new BridgeError(400, `A dispatch with an idempotency key runs supervised; --permission-mode ${permissionMode} is refused.`);
|
|
423
|
+
}
|
|
424
|
+
permissionMode = "supervised";
|
|
425
|
+
}
|
|
393
426
|
if (permissionMode && role === "conductor")
|
|
394
427
|
throw new BridgeError(400, "A conductor starts with its own permissions; permissionMode is for workers.");
|
|
395
428
|
if (permissionMode && kind === "opencode")
|
|
@@ -409,6 +442,9 @@ async function startSession(server, data, options) {
|
|
|
409
442
|
const brief = data.brief === undefined || data.brief === null ? undefined : launchBriefSchema.parse(data.brief);
|
|
410
443
|
if (brief && role === "conductor")
|
|
411
444
|
throw new BridgeError(400, "A conductor starts with its own brief.");
|
|
445
|
+
// A launch's own token, so an ambiguous outcome can later be resolved by
|
|
446
|
+
// looking for the pane that carries it.
|
|
447
|
+
const suppliedStartingToken = data.startingToken === undefined || data.startingToken === null ? undefined : z.string().regex(/^[a-f0-9]{64}$/).parse(data.startingToken);
|
|
412
448
|
// Herdr's agent name is a slug (lowercase, digits, - or _, 1 to 32 chars);
|
|
413
449
|
// the label a person typed is not, so derive one from it.
|
|
414
450
|
const baseName = herdrAgentName(data.name === undefined ? label : plainText(200).parse(data.name));
|
|
@@ -451,10 +487,14 @@ async function startSession(server, data, options) {
|
|
|
451
487
|
const args = role === "conductor" ? [...await prepareConductor(kind, effort, model), ...(kind === "phren" ? phrenArgs : [])]
|
|
452
488
|
: [...(kind === "phren" ? [...PHREN_AGENT_ARGS, ...phrenArgs] : []), ...(model && kind === "phren" ? phrenModelArgs(model) : model && modelFlag[kind] ? [modelFlag[kind], model] : []), ...(data.effort === undefined ? [] : effortArgs(kind, effort)),
|
|
453
489
|
...(permissionMode && kind === "claude" ? ["--permission-mode", CLAUDE_NAMES[permissionMode]] : []), ...(resumeClaude ? ["--resume", resumeClaude] : []), ...(permissionMode && kind === "codex" ? codexModeFlags(permissionMode) : []), ...(permissionMode && kind === "copilot" ? copilotModeFlags(permissionMode) : [])];
|
|
490
|
+
if (data.idempotencyKey)
|
|
491
|
+
assertKeyedLaunchArgs(kind, args);
|
|
454
492
|
// A Codex worker runs on a Phren-owned app-server (codex-servers.ts): the
|
|
455
493
|
// pane joins the thread the Hook started, and the brief is that thread's
|
|
456
494
|
// first turn. The typed arguments below stay the fallback.
|
|
457
|
-
|
|
495
|
+
// A keyed Codex worker uses the typed explicit command so its durable
|
|
496
|
+
// worker identity file is written before the harness execs.
|
|
497
|
+
const structured = kind === "codex" && role === "agent" && !options.canary && !data.idempotencyKey && codexAppServerEnabled();
|
|
458
498
|
// OpenCode serves its own API on a port of its own (opencode-panes.ts): the
|
|
459
499
|
// Hook sends its prompts, answers its asks and interrupts it over HTTP, and
|
|
460
500
|
// the pane stays the owner's view. A brief goes the same way once it
|
|
@@ -466,164 +506,230 @@ async function startSession(server, data, options) {
|
|
|
466
506
|
const briefLaunch = brief && briefFile && launchesWithBrief(kind) ? briefArgs(kind, briefFile) : undefined;
|
|
467
507
|
// sudo -A in the new agent asks the phone for the password (sudo.ts).
|
|
468
508
|
const dispatchId = options.dispatchId ?? brief?.id;
|
|
469
|
-
const variables = { ...askpassEnv(), ...(dispatchId ? { [DISPATCH_ID_ENV]: dispatchId } : {}),
|
|
470
|
-
|
|
509
|
+
const variables = { ...askpassEnv(), ...(dispatchId ? { [DISPATCH_ID_ENV]: dispatchId } : {}),
|
|
510
|
+
...(suppliedStartingToken ? { PHREN_STARTING_TOKEN: suppliedStartingToken } : {}), ...served?.env, ...(home ? claudeLaunchEnv(home) : {}) };
|
|
471
511
|
if (workspace && !objects(before.workspaces).some(w => w.workspace_id === workspace))
|
|
472
512
|
throw new BridgeError(409, "The workspace changed.");
|
|
473
513
|
const knownWorkspaces = new Set(objects(before.workspaces).map(w => w.workspace_id));
|
|
474
514
|
const knownTabs = new Set(objects(before.tabs).map(t => t.tab_id));
|
|
475
515
|
// Created last, once nothing else can refuse the launch, so a refusal
|
|
476
|
-
// never leaves a
|
|
477
|
-
|
|
478
|
-
//
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
if (await realpath(agents) !== agents)
|
|
494
|
-
throw new BridgeError(403, "The agents folder must be inside the Phren directory.");
|
|
495
|
-
scratch = await mkdtemp(path.join(agents, `${new Date().toISOString().slice(0, 10)}-${herdrAgentName(label)}-`));
|
|
496
|
-
}
|
|
497
|
-
const cwd = scratch ?? worktree?.cwd ?? projectDirectory;
|
|
498
|
-
// Claude's folder-trust screen defaults to "No, exit" and Codex's holds the
|
|
499
|
-
// agent too; a folder the Hook picked or just created is trusted up front.
|
|
500
|
-
if (scratch || worktree || options.trustFolder)
|
|
501
|
-
await pretrustFolder(kind, cwd, scratch ? "new agent folder" : worktree ? `new worktree for ${worktree.branch}` : "project folder", home ? { ...process.env, ...claudeLaunchEnv(home) } : process.env);
|
|
502
|
-
if (!options.into) {
|
|
503
|
-
try {
|
|
504
|
-
await terminalProvider().create(server, { workspace, label, cwd, ...(env ? { env } : {}) });
|
|
516
|
+
// never leaves a checkout or branch behind. A keyed dispatch gets a fresh
|
|
517
|
+
// clone with its own managed global config; an unkeyed launch keeps the
|
|
518
|
+
// ordinary worktree of the user's checkout.
|
|
519
|
+
const keyed = role === "agent" && !!data.idempotencyKey;
|
|
520
|
+
if (keyed && !worktreeRequest)
|
|
521
|
+
throw new BridgeError(400, "A dispatch with an idempotency key requires --worktree: keyed workers run only in a Phren-managed clone.");
|
|
522
|
+
const keyedDispatchId = keyed ? z.string().uuid().parse(data.dispatchId ?? brief?.id ?? randomUUID()) : undefined;
|
|
523
|
+
const keyedWorkerFile = keyed ? dispatchClonePaths(keyedDispatchId).workerFile : undefined;
|
|
524
|
+
let launchLock;
|
|
525
|
+
if (keyed)
|
|
526
|
+
launchLock = await acquireLaunchLock(keyedDispatchId);
|
|
527
|
+
try {
|
|
528
|
+
let worktree;
|
|
529
|
+
if (worktreeRequest) {
|
|
530
|
+
worktree = keyed
|
|
531
|
+
? await createDispatchClone(projectDirectory, { branch: worktreeRequest.branch, dispatchId: keyedDispatchId, paths: dispatchClonePaths(keyedDispatchId) })
|
|
532
|
+
: await createLaunchWorktree(projectDirectory, worktreeRequest);
|
|
505
533
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
534
|
+
// The same root as the conductor, chosen by this computer's PHREN_PATH.
|
|
535
|
+
// mkdtemp keeps simultaneous chats with the same title isolated.
|
|
536
|
+
let scratch;
|
|
537
|
+
if (agentFolder) {
|
|
538
|
+
// Runtime folders are excluded from project discovery and store sync.
|
|
539
|
+
// Created before resolving the store: it may not exist yet, on a
|
|
540
|
+
// computer without one or before the Hook's own startup made it.
|
|
541
|
+
await mkdir(path.join(defaultPhrenPath(), ".runtime"), { recursive: true, mode: 0o700 });
|
|
542
|
+
const store = await realpath(defaultPhrenPath());
|
|
543
|
+
const runtime = path.join(store, ".runtime");
|
|
544
|
+
if (await realpath(runtime) !== runtime)
|
|
545
|
+
throw new BridgeError(403, "The runtime folder must be inside the Phren directory.");
|
|
546
|
+
const agents = path.join(runtime, "agents");
|
|
547
|
+
await mkdir(agents, { recursive: true, mode: 0o700 });
|
|
548
|
+
// A pre-existing symlink must not redirect the new folder outside the store.
|
|
549
|
+
if (await realpath(agents) !== agents)
|
|
550
|
+
throw new BridgeError(403, "The agents folder must be inside the Phren directory.");
|
|
551
|
+
scratch = await mkdtemp(path.join(agents, `${new Date().toISOString().slice(0, 10)}-${herdrAgentName(label)}-`));
|
|
511
552
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
553
|
+
const cwd = scratch ?? worktree?.cwd ?? projectDirectory;
|
|
554
|
+
// A keyed dispatch uses only the stored agent token and the clone's managed
|
|
555
|
+
// config. Its environment is an explicit allowlist, never an overlay on the
|
|
556
|
+
// Hook's own environment.
|
|
557
|
+
let keyedGitboy;
|
|
558
|
+
let agentTokenFile;
|
|
559
|
+
let keyedEnv;
|
|
560
|
+
if (keyed) {
|
|
561
|
+
try {
|
|
562
|
+
keyedGitboy = await prepareKeyedGitboy(cwd, { tokenFile: worktree.agentTokenFile, gitConfigFile: worktree.gitConfigFile });
|
|
563
|
+
}
|
|
564
|
+
catch (error) {
|
|
565
|
+
await worktree?.discard();
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
568
|
+
agentTokenFile = keyedGitboy?.tokenFile;
|
|
569
|
+
keyedEnv = keyedExplicitEnv(process.env, {
|
|
570
|
+
...(keyedGitboy?.env ?? {}),
|
|
571
|
+
...(dispatchId ? { [DISPATCH_ID_ENV]: dispatchId } : {}),
|
|
572
|
+
...(keyedWorkerFile ? { PHREN_WORKER_ID_FILE: keyedWorkerFile } : {}),
|
|
573
|
+
...(home ? claudeLaunchEnv(home) : {}),
|
|
574
|
+
});
|
|
524
575
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
576
|
+
const envVariables = keyedEnv ?? { ...variables };
|
|
577
|
+
const env = Object.keys(envVariables).length ? envVariables : undefined;
|
|
578
|
+
// Claude's folder-trust screen defaults to "No, exit" and Codex's holds the
|
|
579
|
+
// agent too; a folder the Hook picked or just created is trusted up front.
|
|
580
|
+
if (scratch || worktree || options.trustFolder)
|
|
581
|
+
await pretrustFolder(kind, cwd, scratch ? "new agent folder" : worktree ? `new worktree for ${worktree.branch}` : "project folder", home ? { ...process.env, ...claudeLaunchEnv(home) } : process.env);
|
|
582
|
+
if (!options.into) {
|
|
583
|
+
try {
|
|
584
|
+
await terminalProvider().create(server, { workspace, label, cwd, ...(env ? { env } : {}) });
|
|
585
|
+
}
|
|
586
|
+
catch (error) {
|
|
587
|
+
await removeAgentTokenFile(agentTokenFile);
|
|
588
|
+
await worktree?.discard();
|
|
589
|
+
if (scratch)
|
|
590
|
+
await rmdir(scratch).catch(() => undefined);
|
|
591
|
+
throw error;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
let created = options.into;
|
|
595
|
+
for (let attempt = 0; attempt < 25 && !created; attempt++) {
|
|
596
|
+
const s = await snapshot(server);
|
|
597
|
+
const fresh = objects(s.tabs).filter(t => !knownTabs.has(t.tab_id)
|
|
598
|
+
&& (workspace ? t.workspace_id === workspace : !knownWorkspaces.has(t.workspace_id)));
|
|
599
|
+
const tab = fresh.find(t => t.label === label)
|
|
600
|
+
?? fresh.find(t => objects(s.workspaces).some(w => w.workspace_id === t.workspace_id && w.label === label))
|
|
601
|
+
?? fresh[0];
|
|
602
|
+
const pane = tab && objects(s.panes).find(p => p.tab_id === tab.tab_id && p.workspace_id === tab.workspace_id && !p.agent);
|
|
603
|
+
if (tab && pane && id.safeParse(tab.workspace_id).success && id.safeParse(tab.tab_id).success && id.safeParse(pane.pane_id).success) {
|
|
604
|
+
created = { workspaceId: String(tab.workspace_id), tabId: String(tab.tab_id), paneId: String(pane.pane_id) };
|
|
605
|
+
}
|
|
606
|
+
else
|
|
607
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
608
|
+
}
|
|
609
|
+
if (!created) {
|
|
610
|
+
await removeAgentTokenFile(agentTokenFile);
|
|
611
|
+
throw new BridgeError(409, `${terminalName(server)} created "${label}" but its pane did not appear. Check ${terminalName(server)} on the computer.`);
|
|
612
|
+
}
|
|
613
|
+
if (suppliedStartingToken)
|
|
614
|
+
seedStartingToken(server, { workspace_id: created.workspaceId, tab_id: created.tabId, pane_id: created.paneId }, suppliedStartingToken);
|
|
615
|
+
const place = { workspace: created.workspaceId, tab: created.tabId, pane: created.paneId };
|
|
616
|
+
await options.onPlaced?.({ server, ...place, source: kind });
|
|
617
|
+
// The pane identity variables are ours (Herdr/tmux), not the caller's, and
|
|
618
|
+
// the worker's hooks need them under the explicit keyed environment too.
|
|
619
|
+
const paneEnv = terminalProvider().paneEnv?.(server, place) ?? {};
|
|
620
|
+
const identityEnv = Object.fromEntries(Object.entries(paneEnv)
|
|
621
|
+
.filter(([key]) => /^(?:HERDR_(?:ENV|SOCKET_PATH|WORKSPACE_ID|TAB_ID|PANE_ID)|TMUX|TMUX_PANE)$/.test(key)));
|
|
622
|
+
const launchEnv = keyedEnv ? { ...keyedEnv, ...identityEnv } : env;
|
|
623
|
+
const structuredLaunch = structured ? await codexServers.launch({ server, ...place }, { cwd, ...(model ? { model } : {}),
|
|
624
|
+
...(data.effort === undefined ? {} : { effort }),
|
|
625
|
+
env: keyedEnv ? { ...(launchEnv ?? {}) } : { ...paneEnv, ...(env ?? {}) }, envExact: !!keyedEnv,
|
|
626
|
+
...(brief ? { dispatchId: brief.id } : {}), startThread: !!brief, ...(permissionMode ? { remoteArgs: codexModeFlags(permissionMode) } : {}) }).catch(error => {
|
|
627
|
+
const note = `Codex app-server unavailable, typing instead: ${error instanceof Error ? error.message : String(error)}`;
|
|
628
|
+
if (error instanceof AppServerUnsupportedError)
|
|
629
|
+
logger.debug("launch", note);
|
|
630
|
+
else
|
|
631
|
+
logger.warn("launch", note);
|
|
632
|
+
return undefined;
|
|
633
|
+
}) : undefined;
|
|
634
|
+
const appServer = structuredLaunch?.entry;
|
|
635
|
+
const binding = { server, workspace: created.workspaceId, tab: created.tabId, pane: created.paneId, source: kind };
|
|
636
|
+
// The brief is the thread's first turn, acknowledged with its id before
|
|
637
|
+
// the pane even starts; the pane's TUI shows it running when it joins.
|
|
638
|
+
// Refused outright, nothing was sent and the caller types it; a lost
|
|
639
|
+
// reply may have started it, so it is not offered for typing again.
|
|
640
|
+
let briefTurn;
|
|
641
|
+
if (appServer?.threadId && brief) {
|
|
642
|
+
try {
|
|
643
|
+
// The thread's first turn carries the mode; the TUI joining it has no flags to set.
|
|
644
|
+
if (permissionMode)
|
|
645
|
+
codexServers.holdSettings(appServer, { ...CODEX_MODES[permissionMode] });
|
|
646
|
+
await codexServers.prompt(appServer, brief.text);
|
|
647
|
+
briefTurn = "sent";
|
|
648
|
+
await recordBriefArrival(brief.id, "UserPromptSubmit", { ...binding, session: appServer.threadId }).catch(() => undefined);
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
briefTurn = error instanceof AppServerRpcError ? undefined : "uncertain";
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
const agentArgs = [...(structuredLaunch ? structuredLaunch.args : [...args, ...(briefLaunch ?? [])]),
|
|
655
|
+
...(kind === "codex" ? ["-c", "check_for_update_on_startup=false"] : [])];
|
|
656
|
+
if (keyedDispatchId)
|
|
657
|
+
await markSubmitted(keyedDispatchId);
|
|
550
658
|
try {
|
|
551
|
-
|
|
552
|
-
if (permissionMode)
|
|
553
|
-
codexServers.holdSettings(appServer, { ...CODEX_MODES[permissionMode] });
|
|
554
|
-
await codexServers.prompt(appServer, brief.text);
|
|
555
|
-
briefTurn = "sent";
|
|
556
|
-
await recordBriefArrival(brief.id, "UserPromptSubmit", { ...binding, session: appServer.threadId }).catch(() => undefined);
|
|
659
|
+
await (kind === "codex" ? startCodex : startWhenShellReady)(server, created.paneId, { name, kind, args: agentArgs, timeoutMs: timeout, ...(launchEnv ? { env: launchEnv } : {}), ...(keyedEnv ? { envExact: true, freshPane: !options.into } : {}) });
|
|
557
660
|
}
|
|
558
661
|
catch (error) {
|
|
559
|
-
|
|
662
|
+
if (appServer && !agentNotReady(error))
|
|
663
|
+
await codexServers.stop(appServer).catch(() => undefined);
|
|
664
|
+
if (error instanceof BridgeError && error.message.startsWith("Codex exited at start:"))
|
|
665
|
+
throw error;
|
|
666
|
+
// A first-run screen (Claude's folder trust, a login notice) holds the
|
|
667
|
+
// agent at startup. It did start: hand the pane back so the owner answers
|
|
668
|
+
// that screen from the chat instead of stranding the workspace.
|
|
669
|
+
const blocked = agentNotReady(error);
|
|
670
|
+
if (!blocked) {
|
|
671
|
+
// A keyed worker may have started before the error (a snapshot read can
|
|
672
|
+
// fail after the harness runs): its token stays for the confirmed-
|
|
673
|
+
// termination cleanup, which knows the path from the receipt.
|
|
674
|
+
if (!keyedEnv)
|
|
675
|
+
await removeAgentTokenFile(agentTokenFile);
|
|
676
|
+
const host = terminalName(server);
|
|
677
|
+
const reason = error instanceof BridgeError && error.status === 504 ? "it did not become ready in time"
|
|
678
|
+
: error instanceof BridgeError && error.message.startsWith(`${host}: `) ? error.message.slice(host.length + 2) : `${host} reported an error`;
|
|
679
|
+
if (options.into)
|
|
680
|
+
throw new BridgeError(409, `${host} couldn't start ${kind} in the "${label}" pane (${reason}). The pane is still open at its shell prompt.`);
|
|
681
|
+
throw new BridgeError(409, `${host} couldn't start ${kind} in the new "${label}" pane (${reason}). The workspace was created and is still open on the computer — open it from ${host === "Herdr" ? "Herdr workspaces" : "its tmux session"}.`);
|
|
682
|
+
}
|
|
560
683
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const reason = error instanceof BridgeError && error.status === 504 ? "it did not become ready in time"
|
|
579
|
-
: error instanceof BridgeError && error.message.startsWith(`${host}: `) ? error.message.slice(host.length + 2) : `${host} reported an error`;
|
|
580
|
-
if (options.into)
|
|
581
|
-
throw new BridgeError(409, `${host} couldn't start ${kind} in the "${label}" pane (${reason}). The pane is still open at its shell prompt.`);
|
|
582
|
-
throw new BridgeError(409, `${host} couldn't start ${kind} in the new "${label}" pane (${reason}). The workspace was created and is still open on the computer — open it from ${host === "Herdr" ? "Herdr workspaces" : "its tmux session"}.`);
|
|
684
|
+
// Without a brief the pane's TUI started the thread; the Hook heard it.
|
|
685
|
+
if (appServer && !appServer.threadId)
|
|
686
|
+
await codexServers.awaitThread(appServer);
|
|
687
|
+
let servedBrief;
|
|
688
|
+
if (served) {
|
|
689
|
+
const variant = role === "conductor" || data.effort !== undefined ? effort : undefined;
|
|
690
|
+
const entry = await registerServedPane(server, created.paneId, cwd, served, { defaults: { ...(role === "conductor" ? { agent: "conductor" } : {}), ...(model ? { model } : {}), ...(variant ? { variant } : {}) } }).catch(() => undefined);
|
|
691
|
+
const sent = entry && brief ? await sendServedBrief(entry, brief.text) : undefined;
|
|
692
|
+
if (brief && sent?.sent) {
|
|
693
|
+
// Sent is enough to never type it again; the user turn appearing in
|
|
694
|
+
// the session is the acceptance the dispatch receipt waits for.
|
|
695
|
+
servedBrief = { session: sent.session, delivered: sent.delivered };
|
|
696
|
+
const at = { ...binding, session: sent.session };
|
|
697
|
+
await recordBriefArrival(brief.id, "SessionStart", at).catch(() => { });
|
|
698
|
+
if (sent.delivered)
|
|
699
|
+
await recordBriefArrival(brief.id, "UserPromptSubmit", at).catch(() => { });
|
|
700
|
+
}
|
|
583
701
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
702
|
+
const after = await snapshot(server);
|
|
703
|
+
const pane = findPane(after, { workspace: created.workspaceId, tab: created.tabId, pane: created.paneId });
|
|
704
|
+
const agentStatus = typeof pane?.agent_status === "string" ? pane.agent_status : undefined;
|
|
705
|
+
if (kind === "claude" && account)
|
|
706
|
+
recordPaneAccount(paneAccountKey(server, created.paneId), account, typeof pane?.terminal_id === "string" ? pane.terminal_id : undefined);
|
|
707
|
+
const sessionId = appServer?.threadId ?? (pane && pane.agent === kind ? await paneIdentity(server, pane) : undefined) ?? servedBrief?.session;
|
|
708
|
+
// The Hook, not the agent name, holds the role from here on.
|
|
709
|
+
if (role === "conductor" && !options.canary)
|
|
710
|
+
await recordConductor(server, pane ?? { pane_id: created.paneId, workspace_id: created.workspaceId, tab_id: created.tabId, agent: kind }, "launch", sessionId);
|
|
711
|
+
const chat = !sessionId && pane && pane.agent === kind ? await paneChatState(server, pane).catch(() => ({})) : {};
|
|
712
|
+
const target = sessionId ? { ...binding, session: sessionId }
|
|
713
|
+
: chat.starting === true ? { ...binding, starting: true, startingToken: chat.startingToken } : undefined;
|
|
714
|
+
// Register a dispatched or scheduled worker's job, so the resources report
|
|
715
|
+
// can name its agent and a sweep can end a leftover process group after its
|
|
716
|
+
// pane is gone. The process group is resolved on the next read.
|
|
717
|
+
if (brief && role === "agent") {
|
|
718
|
+
await new JobRegistry().register({ pane: { server, pane: created.paneId, ...(created.workspaceId ? { workspace: created.workspaceId } : {}), agent: kind, label },
|
|
719
|
+
...(sessionId ? { session: sessionId } : {}), agent: kind, label, command: kind }).catch(() => undefined);
|
|
601
720
|
}
|
|
721
|
+
return { ok: true, ...created, cwd, agent: kind, agentStatus, role, sessionId, target, ...(account ? { account } : {}), ...(choice ? { accountChoice: choice.reason } : {}), ...(permissionMode ? { permissionMode } : {}), ...(unchecked.length ? { unchecked } : {}),
|
|
722
|
+
// The caller types the brief itself unless it went with the launch.
|
|
723
|
+
...(brief ? { briefLaunched: appServer ? briefTurn !== undefined : !!briefLaunch || !!servedBrief,
|
|
724
|
+
briefState: appServer ? briefTurn ?? "unconfirmed" : served ? (servedBrief?.delivered ? "sent" : "uncertain") : briefLaunch ? "sent" : "unconfirmed" } : {}),
|
|
725
|
+
...(worktree ? { worktree: { path: worktree.path, branch: worktree.branch } } : {}), ...(agentTokenFile ? { agentTokenFile } : {}),
|
|
726
|
+
...(worktree?.cloneDir ? { cloneDir: worktree.cloneDir, gitConfigFile: worktree.gitConfigFile } : {}),
|
|
727
|
+
...(worktree?.workerFile ? { workerFile: worktree.workerFile } : {}) };
|
|
602
728
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
if (kind === "claude" && account)
|
|
607
|
-
recordPaneAccount(paneAccountKey(server, created.paneId), account, typeof pane?.terminal_id === "string" ? pane.terminal_id : undefined);
|
|
608
|
-
const sessionId = appServer?.threadId ?? (pane && pane.agent === kind ? await paneIdentity(server, pane) : undefined) ?? servedBrief?.session;
|
|
609
|
-
// The Hook, not the agent name, holds the role from here on.
|
|
610
|
-
if (role === "conductor" && !options.canary)
|
|
611
|
-
await recordConductor(server, pane ?? { pane_id: created.paneId, workspace_id: created.workspaceId, tab_id: created.tabId, agent: kind }, "launch", sessionId);
|
|
612
|
-
const chat = !sessionId && pane && pane.agent === kind ? await paneChatState(server, pane).catch(() => ({})) : {};
|
|
613
|
-
const target = sessionId ? { ...binding, session: sessionId }
|
|
614
|
-
: chat.starting === true ? { ...binding, starting: true, startingToken: chat.startingToken } : undefined;
|
|
615
|
-
// Register a dispatched or scheduled worker's job, so the resources report
|
|
616
|
-
// can name its agent and a sweep can end a leftover process group after its
|
|
617
|
-
// pane is gone. The process group is resolved on the next read.
|
|
618
|
-
if (brief && role === "agent") {
|
|
619
|
-
await new JobRegistry().register({ pane: { server, pane: created.paneId, ...(created.workspaceId ? { workspace: created.workspaceId } : {}), agent: kind, label },
|
|
620
|
-
...(sessionId ? { session: sessionId } : {}), agent: kind, label, command: kind }).catch(() => undefined);
|
|
729
|
+
finally {
|
|
730
|
+
if (launchLock)
|
|
731
|
+
await releaseLaunchLock(launchLock);
|
|
621
732
|
}
|
|
622
|
-
return { ok: true, ...created, cwd, agent: kind, agentStatus, role, sessionId, target, ...(account ? { account } : {}), ...(choice ? { accountChoice: choice.reason } : {}), ...(permissionMode ? { permissionMode } : {}), ...(unchecked.length ? { unchecked } : {}),
|
|
623
|
-
// The caller types the brief itself unless it went with the launch.
|
|
624
|
-
...(brief ? { briefLaunched: appServer ? briefTurn !== undefined : !!briefLaunch || !!servedBrief,
|
|
625
|
-
briefState: appServer ? briefTurn ?? "unconfirmed" : served ? (servedBrief?.delivered ? "sent" : "uncertain") : briefLaunch ? "sent" : "unconfirmed" } : {}),
|
|
626
|
-
...(worktree ? { worktree: { path: worktree.path, branch: worktree.branch } } : {}) };
|
|
627
733
|
}
|
|
628
734
|
export async function workspaceAction(server, operation, data) {
|
|
629
735
|
if (!["focus", "rename", "create", "close", "scroll"].includes(operation))
|
|
@@ -12,7 +12,7 @@ import { ownerRequest, requestPeer } from "./request-origin.js";
|
|
|
12
12
|
import { listMoves, moveSessionFields, readMove } from "./session-move.js";
|
|
13
13
|
import { getTaskRoute, getTaskDirectoryRoute, updateTaskRoute, createTaskRoute, saveTaskRoute, launchTaskRoute } from "./task-routes.js";
|
|
14
14
|
import { ownerInboxView } from "./owner-inbox-view.js";
|
|
15
|
-
import { closeFinishedWorker, closeOwnPane } from "./worker-close.js";
|
|
15
|
+
import { cancelDispatch, closeFinishedWorker, closeOwnPane } from "./worker-close.js";
|
|
16
16
|
import { reportWorker, readIntegrator, setIntegrator } from "./worker-reports.js";
|
|
17
17
|
import { sessionStalls } from "./stalls.js";
|
|
18
18
|
import { harnessInventoryWithin, launchCheckOff } from "./harnesses.js";
|
|
@@ -25,7 +25,7 @@ import { handOff } from "./hand-off.js";
|
|
|
25
25
|
import { BUILTIN_MODULES, disabledHint } from "../modules/registry.js";
|
|
26
26
|
import { homeDir } from "../home-paths.js";
|
|
27
27
|
import { resolveCodeStore, CodeRoutes } from "./code-routes.js";
|
|
28
|
-
import { dispatchProjectDirectory, dispatchStatus, originPaneSchema } from "./dispatch.js";
|
|
28
|
+
import { dispatchProjectDirectory, dispatchStatus, originPaneSchema, reconcileInterruptedDispatches } from "./dispatch.js";
|
|
29
29
|
import { hookWorkers } from "./dispatch-returns.js";
|
|
30
30
|
import { remoteChildren } from "./dispatch-tree.js";
|
|
31
31
|
import { briefArrival, briefId, briefRoot, launchesWithBrief, readLaunchBrief } from "./launch-brief.js";
|
|
@@ -218,6 +218,7 @@ export function workspacesReader(ctx) {
|
|
|
218
218
|
if (agents.length !== 1)
|
|
219
219
|
continue;
|
|
220
220
|
const chat = chatStates.get(agents[0]);
|
|
221
|
+
tab.browserWatch = chat?.browserWatch ?? "unknown";
|
|
221
222
|
if (chat?.starting === true)
|
|
222
223
|
tab.starting = true;
|
|
223
224
|
// After the identity probe above, which is what learns a pane's transcript.
|
|
@@ -532,6 +533,7 @@ export function createRouteHandler(ctx) {
|
|
|
532
533
|
result = { integrator: await readIntegrator() ?? null };
|
|
533
534
|
break;
|
|
534
535
|
case "/v1/dispatch":
|
|
536
|
+
await reconcileInterruptedDispatches();
|
|
535
537
|
result = { dispatches: await dispatchStatus() };
|
|
536
538
|
break;
|
|
537
539
|
// A session move (session-move.ts) by its id, or this computer's recent moves.
|
|
@@ -1235,6 +1237,12 @@ export function createRouteHandler(ctx) {
|
|
|
1235
1237
|
else if (url.pathname === "/v1/dispatch/close") {
|
|
1236
1238
|
result = await closeFinishedWorker(data, ctx.handOffs);
|
|
1237
1239
|
}
|
|
1240
|
+
else if (url.pathname === "/v1/dispatch/cancel") {
|
|
1241
|
+
// Cancel a running dispatch by id: stop its agent and close its pane.
|
|
1242
|
+
if (request.headers?.["x-phren-origin"] === "peer")
|
|
1243
|
+
throw new BridgeError(403, "A peer cannot cancel a dispatch on this computer.");
|
|
1244
|
+
result = await cancelDispatch(data);
|
|
1245
|
+
}
|
|
1238
1246
|
else if (url.pathname === "/v1/dispatch/close-self") {
|
|
1239
1247
|
result = await closeOwnPane(data);
|
|
1240
1248
|
}
|
|
@@ -1255,6 +1263,14 @@ export function createRouteHandler(ctx) {
|
|
|
1255
1263
|
else if (url.pathname === "/v1/dispatch/workers") {
|
|
1256
1264
|
result = await hookWorkers(agentHooks)(data);
|
|
1257
1265
|
}
|
|
1266
|
+
else if (url.pathname === "/v1/dispatch/returns/ack") {
|
|
1267
|
+
// `phren dispatch wait` acknowledges only the dispatch it followed,
|
|
1268
|
+
// never the other returns a conductor on this Hook still needs.
|
|
1269
|
+
if (request.headers?.["x-phren-origin"] === "peer")
|
|
1270
|
+
throw new BridgeError(403, "Peer conductor operations require the authenticated generation-scoped routes.");
|
|
1271
|
+
const body = z.object({ dispatch: z.string().uuid() }).strict().parse(data);
|
|
1272
|
+
result = await ctx.returns.acknowledgeOne(body.dispatch);
|
|
1273
|
+
}
|
|
1258
1274
|
else if (url.pathname === "/v1/dispatch/returns" && url.searchParams.get("peek") === "1") {
|
|
1259
1275
|
// The unread returns, left unread: a watcher (`phren dispatch returns --watch`) beside an agent
|
|
1260
1276
|
// conductor, which still takes them. Read here, never forwarded to a successor, which would take them.
|
package/dist/bridge/server.js
CHANGED
|
@@ -9,6 +9,7 @@ import { AccountFailover } from "./account-failover.js";
|
|
|
9
9
|
import { ownerInboxSources } from "./owner-inbox-sources.js";
|
|
10
10
|
import { OwnerInbox } from "./owner-inbox.js";
|
|
11
11
|
import { closeFinishedWorker } from "./worker-close.js";
|
|
12
|
+
import { cleanupIdempotencyLocks, markHookServerProcess } from "./dispatch-idempotency.js";
|
|
12
13
|
import { isLocalComputer } from "./dispatch-hosts.js";
|
|
13
14
|
import { hookPeers, peerRequest } from "./peers.js";
|
|
14
15
|
import { handOff } from "./hand-off.js";
|
|
@@ -37,7 +38,7 @@ import { approvalPushCapability } from "./push.js";
|
|
|
37
38
|
import { startChangeRetention } from "./changes.js";
|
|
38
39
|
import { CodeReindexer, CodeRoutes } from "./code-routes.js";
|
|
39
40
|
import { WorkspaceContextUsage } from "./context.js";
|
|
40
|
-
import { DispatchService } from "./dispatch.js";
|
|
41
|
+
import { DispatchService, reconcileInterruptedDispatches } from "./dispatch.js";
|
|
41
42
|
import { DispatchReturns, hookWorkers } from "./dispatch-returns.js";
|
|
42
43
|
import { findPane, paneChatState, paneIdentity, recentServers, sharedSnapshot, snapshot, validateTarget } from "./herdr.js";
|
|
43
44
|
import { LaunchLimiter } from "./limits.js";
|
|
@@ -79,11 +80,14 @@ import { CodexAuthKeeper, codexAuthRefreshEnabled } from "./codex-auth-refresh.j
|
|
|
79
80
|
import { localNames } from "./computer-names.js";
|
|
80
81
|
import { startStoreSyncLoop } from "../sync/store-sync.js";
|
|
81
82
|
import { SocketBudget, socketIdentity, socketKind } from "./socket-budget.js";
|
|
83
|
+
import { logger } from "../logger.js";
|
|
82
84
|
export { capabilities, capabilitiesForModules, requireRoute } from "./server-routes.js";
|
|
83
85
|
export { streamCloseReason } from "./server-stream.js";
|
|
84
86
|
export { herdrAgentName, launchSession } from "./server-launch.js";
|
|
85
87
|
export async function serve(version, options = {}) {
|
|
86
88
|
process.umask(0o077);
|
|
89
|
+
markHookServerProcess();
|
|
90
|
+
await cleanupIdempotencyLocks().catch(error => logger.warn("dispatch", `Could not clean leftover idempotency locks: ${error instanceof Error ? error.message : String(error)}`));
|
|
87
91
|
const modules = moduleSnapshot(defaultPhrenPath(), undefined, true);
|
|
88
92
|
if (!modules.has("hook"))
|
|
89
93
|
throw new BridgeError(404, disabledHint("hook"));
|
|
@@ -126,6 +130,9 @@ export async function serve(version, options = {}) {
|
|
|
126
130
|
localWorkers: hookWorkers(agentHooks),
|
|
127
131
|
close: async (receipt, verifiedPeer) => {
|
|
128
132
|
const data = { target: receipt.target, dispatch: receipt.moves?.slice().reverse().find(move => move.to.computer)?.id ?? receipt.id, turn: receipt.closePending.turn };
|
|
133
|
+
// Keyed dispatches are local-only: close on this Hook, never over a peer.
|
|
134
|
+
if (receipt.idempotencyKey)
|
|
135
|
+
return closeFinishedWorker(data, handOffs);
|
|
129
136
|
if (receipt.computerId === computerID)
|
|
130
137
|
return closeFinishedWorker(data, handOffs);
|
|
131
138
|
const peer = verifiedPeer ?? (await hookPeers().catch(() => [])).find(peer => peer.name === receipt.computer);
|
|
@@ -272,6 +279,10 @@ export async function serve(version, options = {}) {
|
|
|
272
279
|
throw new Error("Phren Hook is already running.");
|
|
273
280
|
await unlink(socketPath());
|
|
274
281
|
}
|
|
282
|
+
// Only the Hook that owns the socket reconciles dispatch state: a second
|
|
283
|
+
// `bridge serve` stops above before touching any receipt or key record.
|
|
284
|
+
if (dispatches)
|
|
285
|
+
await reconcileInterruptedDispatches().catch(error => logger.warn("dispatch", `Could not reconcile interrupted dispatches: ${error instanceof Error ? error.message : String(error)}`));
|
|
275
286
|
const storePulls = new StorePulls(scheduleStore);
|
|
276
287
|
const gitboyWebhooks = new GitboyWebhooks(root, storeId => storePulls.request(storeId), undefined, scheduler ? event => scheduler.ingestEvent(event) : undefined);
|
|
277
288
|
const browsers = new BrowserRegistry(root);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The script's file name in a version's folder, beside `bridge-hook.mjs`. */
|
|
2
|
+
export declare const FAST_STATUS_LINE_FILE = "claude-statusline.mjs";
|
|
3
|
+
export declare const fastStatusLinePath: (versionDir: string) => string;
|
|
4
|
+
/** The owner's status line under any number of Phren wrappers: what a status line that is Phren's wraps,
|
|
5
|
+
* down to one that is not. `null` when the innermost wrapped none; a value that is not Phren's is returned as is.
|
|
6
|
+
* Phren's is the quoted node, the quoted bundle or forwarder (whichever node and Hook folder it named),
|
|
7
|
+
* `usage-statusline` and the wrapped status line as base64. Self-contained: the forwarder embeds its source. */
|
|
8
|
+
export declare function unwrapStatusLine(value: unknown): unknown;
|
|
9
|
+
export declare const FAST_STATUS_LINE_SOURCE: string;
|