@phren/cli 0.3.22 → 0.3.23
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 +48 -8
- package/dist/bridge/conductor-context.d.ts +7 -0
- package/dist/bridge/conductor-context.js +48 -0
- package/dist/bridge/hook-fast.d.ts +2 -0
- package/dist/bridge/hook-fast.js +20 -1
- package/dist/bridge/server-launch.js +3 -30
- package/dist/bridge/server-routes.js +67 -45
- package/dist/bridge-hook.mjs +488 -401
- package/dist/init/init-uninstall.js +1 -0
- package/dist/init/setup.js +11 -0
- package/dist/init/teardown.js +1 -0
- package/dist/link/link.js +2 -0
- package/dist/link/refresh.js +1 -1
- package/dist/modules/registry.js +1 -1
- package/dist/skill/files.js +7 -1
- package/package.json +1 -1
- package/plugins/opencode/phren-transcript.js +28 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { recordedConductor } from "./conductor-role.js";
|
|
2
|
+
import { conductorContext } from "./conductor-context.js";
|
|
1
3
|
import { defaultPhrenPath } from "../shared.js";
|
|
2
4
|
import { disabledHint } from "../modules/registry.js";
|
|
3
5
|
import { activateModules as moduleSnapshot } from "../modules/runtime.js";
|
|
@@ -9,8 +11,8 @@ import path from "node:path";
|
|
|
9
11
|
import { createHash, randomUUID } from "node:crypto";
|
|
10
12
|
import { hostname } from "node:os";
|
|
11
13
|
import { atomicInPrivateDir, BridgeError, bridgeRoot, object, objects, provider, targetSchema } from "./protocol.js";
|
|
12
|
-
import { findPane, knownPanes, paneForCodexSession, servers, snapshot, trustedDirectory, validateTarget } from "./herdr.js";
|
|
13
|
-
import { TOOL_HOOK_BUDGET_MS } from "./hook-fast.js";
|
|
14
|
+
import { findPane, knownPanes, paneIdentity, paneForCodexSession, servers, snapshot, trustedDirectory, validateTarget } from "./herdr.js";
|
|
15
|
+
import { hookOutput, TOOL_HOOK_BUDGET_MS } from "./hook-fast.js";
|
|
14
16
|
import { underCodexDaemon } from "./codex-daemon.js";
|
|
15
17
|
import { codexAutoReview } from "./codex-review-mode.js";
|
|
16
18
|
import { terminalPaneFromEnv, terminalProvider } from "./terminal.js";
|
|
@@ -1663,7 +1665,7 @@ export class AgentHooks {
|
|
|
1663
1665
|
await this.sudo.handle(req, res);
|
|
1664
1666
|
return;
|
|
1665
1667
|
}
|
|
1666
|
-
if (req.method !== "POST" || req.url
|
|
1668
|
+
if (req.method !== "POST" || !["/hook", "/conductor-context"].includes(req.url ?? ""))
|
|
1667
1669
|
throw new Error("Invalid callback");
|
|
1668
1670
|
let size = 0;
|
|
1669
1671
|
const chunks = [];
|
|
@@ -1674,6 +1676,38 @@ export class AgentHooks {
|
|
|
1674
1676
|
chunks.push(bytes);
|
|
1675
1677
|
}
|
|
1676
1678
|
const body = object(JSON.parse(Buffer.concat(chunks).toString()));
|
|
1679
|
+
// OpenCode asks when building the root session's system prompt. Resolve
|
|
1680
|
+
// its process against the current conductor; no inherited pane env or
|
|
1681
|
+
// plugin callback may create a session binding or a turn record here.
|
|
1682
|
+
if (req.url === "/conductor-context") {
|
|
1683
|
+
if (this.modules?.has("conductor") === false) {
|
|
1684
|
+
res.end("{}");
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
if (!Number.isSafeInteger(body.pid) || Number(body.pid) <= 0 || typeof body.session !== "string")
|
|
1688
|
+
throw new Error("Invalid context callback");
|
|
1689
|
+
const role = await recordedConductor();
|
|
1690
|
+
if (!role) {
|
|
1691
|
+
res.end("{}");
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
const s = await snapshot(role.server);
|
|
1695
|
+
const pane = objects(s.panes).find(p => p.pane_id === role.pane);
|
|
1696
|
+
if (!pane || pane.agent !== "opencode" || (role.terminal && pane.terminal_id !== role.terminal)) {
|
|
1697
|
+
res.end("{}");
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
const pids = (await terminalProvider().processes(role.server, role.pane)).foregroundPids;
|
|
1701
|
+
if (!pids.includes(Number(body.pid)) || await paneIdentity(role.server, pane, true) !== body.session) {
|
|
1702
|
+
res.end("{}");
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1705
|
+
const target = targetSchema.parse({ server: role.server, workspace: pane.workspace_id, tab: pane.tab_id,
|
|
1706
|
+
pane: role.pane, source: "opencode", session: body.session });
|
|
1707
|
+
const context = await conductorContext(target, s);
|
|
1708
|
+
res.end(JSON.stringify(context ? { context } : {}));
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1677
1711
|
let target = targetSchema.parse(body.target);
|
|
1678
1712
|
if (this.modules?.has("git") === false && ["PreToolUse", "PostToolUse"].includes(String(body.event))) {
|
|
1679
1713
|
res.statusCode = 404;
|
|
@@ -1752,11 +1786,17 @@ export class AgentHooks {
|
|
|
1752
1786
|
// A prompt refused here never starts a turn in this conversation.
|
|
1753
1787
|
if (answer.decision !== "block")
|
|
1754
1788
|
await this.recordTurn(target, pane, body, dispatch);
|
|
1755
|
-
|
|
1789
|
+
const context = answer.decision === "block" || this.modules?.has("conductor") === false ? undefined : await conductorContext(target, s).catch(() => undefined);
|
|
1790
|
+
res.end(JSON.stringify({ ...answer, ...(context ? { hookSpecificOutput: { hookEventName: "UserPromptSubmit", additionalContext: context } } : {}) }));
|
|
1756
1791
|
return;
|
|
1757
1792
|
}
|
|
1758
1793
|
if (body.event === "SessionStart" || body.event === "Stop")
|
|
1759
1794
|
await this.recordTurn(target, pane, body, dispatch);
|
|
1795
|
+
if (body.event === "SessionStart") {
|
|
1796
|
+
const context = this.modules?.has("conductor") === false ? undefined : await conductorContext(target, s).catch(() => undefined);
|
|
1797
|
+
res.end(JSON.stringify(context ? { hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: context } } : {}));
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1760
1800
|
if ((this.modules?.has("git") ?? true) && ["PreToolUse", "PostToolUse"].includes(String(body.event)) && capturesChanges(String(body.tool), input)) {
|
|
1761
1801
|
const conversation = `${target.source}:${target.session}`, id = String(body.toolUseId || "").slice(0, 200);
|
|
1762
1802
|
if (body.event === "PreToolUse") {
|
|
@@ -2009,10 +2049,10 @@ async function forwardHook(source, target, event, value, left) {
|
|
|
2009
2049
|
let result = "";
|
|
2010
2050
|
res.on("data", chunk => { result += chunk.toString(); if (result.length > 16_384)
|
|
2011
2051
|
req.destroy(); });
|
|
2012
|
-
//
|
|
2013
|
-
//
|
|
2014
|
-
res.on("end", () => { if (res.statusCode === 200
|
|
2015
|
-
process.stdout.write(result); resolve(); });
|
|
2052
|
+
// Forward approval/refusal decisions and validated turn context.
|
|
2053
|
+
// Tool callbacks stay silent, and an empty reply says nothing.
|
|
2054
|
+
res.on("end", () => { if (res.statusCode === 200)
|
|
2055
|
+
process.stdout.write(hookOutput(event, result)); resolve(); });
|
|
2016
2056
|
res.on("error", () => resolve());
|
|
2017
2057
|
});
|
|
2018
2058
|
req.on("error", () => resolve());
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Json, type Target } from "./protocol.js";
|
|
2
|
+
export declare function conductorBrief(): Promise<string>;
|
|
3
|
+
/** The same shipped brief used by launches, restored for an existing session. */
|
|
4
|
+
export declare function ensureConductorBrief(brief?: string): Promise<string>;
|
|
5
|
+
/** Only call after the callback has been placed in its live pane. The role
|
|
6
|
+
* follows the terminal, so inherited launch variables cannot confer it. */
|
|
7
|
+
export declare function conductorContext(target: Target, snapshot: Json): Promise<string | undefined>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { conductorPane, noteConductorSession, runsAgent } from "./conductor-role.js";
|
|
5
|
+
import { atomicInPrivateDir, BridgeError, bridgeRoot } from "./protocol.js";
|
|
6
|
+
export async function conductorBrief() {
|
|
7
|
+
let source;
|
|
8
|
+
if (typeof CONDUCTOR_SKILL_SOURCE === "string")
|
|
9
|
+
source = CONDUCTOR_SKILL_SOURCE;
|
|
10
|
+
else {
|
|
11
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
for (const candidate of [
|
|
13
|
+
path.join(here, "..", "starter", "global", "skills", "conductor", "SKILL.md"),
|
|
14
|
+
path.join(here, "..", "..", "starter", "global", "skills", "conductor", "SKILL.md"),
|
|
15
|
+
]) {
|
|
16
|
+
source = await readFile(candidate, "utf8").catch(() => undefined);
|
|
17
|
+
if (source !== undefined)
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (source === undefined)
|
|
22
|
+
throw new BridgeError(503, "The shipped conductor brief is unavailable. Reinstall Phren Hook.");
|
|
23
|
+
const match = /^---\r?\n[\s\S]*?\r?\n---\r?\n([\s\S]*)$/.exec(source);
|
|
24
|
+
const brief = (match?.[1] ?? source).trim();
|
|
25
|
+
if (!brief)
|
|
26
|
+
throw new BridgeError(503, "The shipped conductor brief is empty. Reinstall Phren Hook.");
|
|
27
|
+
return brief;
|
|
28
|
+
}
|
|
29
|
+
/** The same shipped brief used by launches, restored for an existing session. */
|
|
30
|
+
export async function ensureConductorBrief(brief) {
|
|
31
|
+
const file = path.join(bridgeRoot(), "conductor", "brief.md");
|
|
32
|
+
const content = (brief ?? await conductorBrief()) + "\n";
|
|
33
|
+
if (await readFile(file, "utf8").catch(() => undefined) !== content)
|
|
34
|
+
await atomicInPrivateDir(file, content);
|
|
35
|
+
return file;
|
|
36
|
+
}
|
|
37
|
+
/** Only call after the callback has been placed in its live pane. The role
|
|
38
|
+
* follows the terminal, so inherited launch variables cannot confer it. */
|
|
39
|
+
export async function conductorContext(target, snapshot) {
|
|
40
|
+
const pane = await conductorPane(target.server, snapshot);
|
|
41
|
+
if (!runsAgent(pane) || pane.pane_id !== target.pane || pane.agent !== target.source)
|
|
42
|
+
return undefined;
|
|
43
|
+
const file = await ensureConductorBrief();
|
|
44
|
+
await noteConductorSession(target.server, target.pane, target.session);
|
|
45
|
+
return `Phren role for this turn: conductor. Your role is attached to this live terminal and applies after startup, resume, model changes and compaction. Read the conductor brief at ${JSON.stringify(file)} before coordinating work if it is not already in context.
|
|
46
|
+
For questions about running work, start with Phren live_sessions (core: phren_admin action live_sessions; CLI: phren dispatch sessions). It includes linked computers and their sessions. Report unreachable and unlinked computers explicitly. Consult get_tasks and get_project_summary for the relevant projects, and dispatch_returns for worker outcomes.
|
|
47
|
+
Use dispatch for a new worker and hand_off for an existing session; preserve delivery IDs and check queued delivery status before retrying. Respect the owner's current limits on delegation, permissions and releases. Verify returns and tests before integrating or marking tasks done. Keep owner replies short and put detailed evidence in tasks. The role grants no additional permissions.`;
|
|
48
|
+
}
|
|
@@ -11,6 +11,8 @@ export declare const fastHookPath: (versionDir: string) => string;
|
|
|
11
11
|
* them, so once the budget is spent they give up and the tool runs.
|
|
12
12
|
*/
|
|
13
13
|
export declare const TOOL_HOOK_BUDGET_MS = 5000;
|
|
14
|
+
/** Keep permission replies and turn context, without turning tool callbacks into approvals. */
|
|
15
|
+
export declare function hookOutput(event: string, result: string): string;
|
|
14
16
|
/** The forwarder's source, with the ToolUse budget written in. */
|
|
15
17
|
export declare const fastHookSource: (toolBudgetMs?: number) => string;
|
|
16
18
|
export declare const FAST_HOOK_SOURCE: string;
|
package/dist/bridge/hook-fast.js
CHANGED
|
@@ -25,6 +25,24 @@ export const fastHookPath = (versionDir) => path.join(versionDir, FAST_HOOK_FILE
|
|
|
25
25
|
* them, so once the budget is spent they give up and the tool runs.
|
|
26
26
|
*/
|
|
27
27
|
export const TOOL_HOOK_BUDGET_MS = 5_000;
|
|
28
|
+
/** Keep permission replies and turn context, without turning tool callbacks into approvals. */
|
|
29
|
+
export function hookOutput(event, result) {
|
|
30
|
+
if (event === "PermissionRequest")
|
|
31
|
+
return result;
|
|
32
|
+
if (event !== "SessionStart" && event !== "UserPromptSubmit")
|
|
33
|
+
return "";
|
|
34
|
+
try {
|
|
35
|
+
const reply = JSON.parse(result);
|
|
36
|
+
if (event === "UserPromptSubmit" && reply?.decision === "block")
|
|
37
|
+
return result;
|
|
38
|
+
const output = reply?.hookSpecificOutput;
|
|
39
|
+
if (output?.hookEventName === event && typeof output.additionalContext === "string" && output.additionalContext.trim()) {
|
|
40
|
+
return JSON.stringify({ hookSpecificOutput: { hookEventName: event, additionalContext: output.additionalContext } });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch { /* A malformed reply adds no context. */ }
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
28
46
|
/** The forwarder's source, with the ToolUse budget written in. */
|
|
29
47
|
export const fastHookSource = (toolBudgetMs = TOOL_HOOK_BUDGET_MS) => `// Installed by Phren Hook: Claude Code's hook events, forwarded to the running Hook.
|
|
30
48
|
import { request } from "node:http";
|
|
@@ -32,6 +50,7 @@ import { homedir } from "node:os";
|
|
|
32
50
|
import path from "node:path";
|
|
33
51
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
34
52
|
const env = process.env, source = process.argv[2];
|
|
53
|
+
const hookOutput = ${hookOutput.toString()};
|
|
35
54
|
async function full() {
|
|
36
55
|
const bundle = path.join(path.dirname(fileURLToPath(import.meta.url)), "bridge-hook.mjs");
|
|
37
56
|
process.argv = [process.argv[0], bundle, "hook", source];
|
|
@@ -70,7 +89,7 @@ async function forward(place) {
|
|
|
70
89
|
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(data) } }, res => {
|
|
71
90
|
let result = "";
|
|
72
91
|
res.on("data", chunk => { result += chunk.toString(); if (result.length > 16_384) req.destroy(); });
|
|
73
|
-
res.on("end", () => { if (res.statusCode === 200
|
|
92
|
+
res.on("end", () => { if (res.statusCode === 200) process.stdout.write(hookOutput(event, result)); resolve(); });
|
|
74
93
|
res.on("error", () => resolve());
|
|
75
94
|
});
|
|
76
95
|
req.on("error", () => resolve()); req.on("timeout", () => { req.destroy(); resolve(); }); req.end(data);
|
|
@@ -2,7 +2,6 @@ import { markPaneClosed } from "./worker-close.js";
|
|
|
2
2
|
import { mkdir, readFile } from "node:fs/promises";
|
|
3
3
|
import { phrenStoreRoot } from "./transcripts.js";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
5
|
import { z } from "zod";
|
|
7
6
|
import { homeDir } from "../home-paths.js";
|
|
8
7
|
import { agentNames, findPane, isConductorName, paneChatState, paneIdentity, servers, snapshot } from "./herdr.js";
|
|
@@ -13,6 +12,7 @@ import { createLaunchWorktree, launchWorktreeSchema } from "./launch-worktree.js
|
|
|
13
12
|
import { askpassEnv } from "./sudo.js";
|
|
14
13
|
import { briefArgs, DISPATCH_ID_ENV, launchBriefSchema, launchesWithBrief, recordBriefArrival, writeLaunchBrief } from "./launch-brief.js";
|
|
15
14
|
import { prepareServedLaunch, registerServedPane, sendServedBrief } from "./opencode-panes.js";
|
|
15
|
+
import { conductorBrief, ensureConductorBrief } from "./conductor-context.js";
|
|
16
16
|
import { groupConductor } from "./conductor-group.js";
|
|
17
17
|
import { clearConductor, conductorPane, noteConductorSession, readRoleState, recordConductor, runsAgent } from "./conductor-role.js";
|
|
18
18
|
import { localNames } from "./computer-names.js";
|
|
@@ -25,35 +25,12 @@ import { AppServerRpcError } from "./codex-app-server.js";
|
|
|
25
25
|
import { codexAppServerEnabled, codexServers } from "./codex-servers.js";
|
|
26
26
|
import { logger } from "../logger.js";
|
|
27
27
|
import { JobRegistry } from "./job-registry.js";
|
|
28
|
-
import { atomic, BridgeError,
|
|
28
|
+
import { atomic, BridgeError, id, launchEfforts, objects, PERMISSION_MODES, provider } from "./protocol.js";
|
|
29
29
|
import { CLAUDE_NAMES, CODEX_MODES, codexModeFlags, copilotModeFlags } from "./settings-switch.js";
|
|
30
30
|
/** Starting agents in Herdr from the phone: the launch route's harness
|
|
31
31
|
* arguments, the conductor brief, and workspace, tab and pane actions. */
|
|
32
32
|
const launchKinds = ["codex", "claude", "copilot", "opencode", "phren"];
|
|
33
33
|
const plainText = (max) => z.string().min(1).max(max).refine(t => !/[\x00-\x1f\x7f]/.test(t));
|
|
34
|
-
async function conductorBrief() {
|
|
35
|
-
let source;
|
|
36
|
-
if (typeof CONDUCTOR_SKILL_SOURCE === "string")
|
|
37
|
-
source = CONDUCTOR_SKILL_SOURCE;
|
|
38
|
-
else {
|
|
39
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
40
|
-
for (const candidate of [
|
|
41
|
-
path.join(here, "..", "starter", "global", "skills", "conductor", "SKILL.md"),
|
|
42
|
-
path.join(here, "..", "..", "starter", "global", "skills", "conductor", "SKILL.md"),
|
|
43
|
-
]) {
|
|
44
|
-
source = await readFile(candidate, "utf8").catch(() => undefined);
|
|
45
|
-
if (source !== undefined)
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (source === undefined)
|
|
50
|
-
throw new BridgeError(503, "The shipped conductor brief is unavailable. Reinstall Phren Hook.");
|
|
51
|
-
const match = /^---\r?\n[\s\S]*?\r?\n---\r?\n([\s\S]*)$/.exec(source);
|
|
52
|
-
const brief = (match?.[1] ?? source).trim();
|
|
53
|
-
if (!brief)
|
|
54
|
-
throw new BridgeError(503, "The shipped conductor brief is empty. Reinstall Phren Hook.");
|
|
55
|
-
return brief;
|
|
56
|
-
}
|
|
57
34
|
/** How each harness takes a reasoning effort at startup. */
|
|
58
35
|
function effortArgs(kind, effort) {
|
|
59
36
|
if (kind === "claude")
|
|
@@ -133,11 +110,7 @@ export function phrenModelArgs(model) {
|
|
|
133
110
|
}
|
|
134
111
|
async function prepareConductor(kind, effort, model) {
|
|
135
112
|
const brief = await conductorBrief();
|
|
136
|
-
const
|
|
137
|
-
await mkdir(briefDirectory, { recursive: true, mode: 0o700 });
|
|
138
|
-
const briefFile = path.join(briefDirectory, "brief.md");
|
|
139
|
-
if (await readFile(briefFile, "utf8").catch(() => undefined) !== brief + "\n")
|
|
140
|
-
await atomic(briefFile, brief + "\n");
|
|
113
|
+
const briefFile = await ensureConductorBrief(brief);
|
|
141
114
|
// A multi-line argument cannot be typed safely into every shell (Herdr
|
|
142
115
|
// refuses it for zsh); Claude reads the brief from its file instead.
|
|
143
116
|
if (kind === "claude")
|
|
@@ -54,13 +54,17 @@ export const OVERVIEW_ENRICH_BUDGET_MS = 5_000;
|
|
|
54
54
|
const childActivityCache = new Map();
|
|
55
55
|
async function childActivity(source, session) {
|
|
56
56
|
const key = `${source}\0${session}`, now = Date.now(), cached = childActivityCache.get(key);
|
|
57
|
-
|
|
57
|
+
// A slow tree still belongs to the next overview. Expiring an in-flight
|
|
58
|
+
// read every five seconds starts it over before any answer can be reused.
|
|
59
|
+
if (cached && (cached.pending || now - cached.at < CHILD_ACTIVITY_CACHE_MS))
|
|
58
60
|
return cached.result;
|
|
59
61
|
const result = childAgentTree(source, session).then(tree => {
|
|
60
62
|
const running = runningChildAgents(tree);
|
|
61
63
|
return { runningChildren: running.length, childProviders: [...new Set(running.map(child => child.provider))].sort() };
|
|
62
64
|
}).catch(() => ({ runningChildren: 0, childProviders: [] }));
|
|
63
|
-
|
|
65
|
+
const entry = { at: now, pending: true, result };
|
|
66
|
+
void result.then(() => { entry.at = Date.now(); entry.pending = false; });
|
|
67
|
+
childActivityCache.set(key, entry);
|
|
64
68
|
while (childActivityCache.size > 128)
|
|
65
69
|
childActivityCache.delete(childActivityCache.keys().next().value);
|
|
66
70
|
return result;
|
|
@@ -163,9 +167,9 @@ export function workspacesReader(ctx) {
|
|
|
163
167
|
let expired = false;
|
|
164
168
|
let timer;
|
|
165
169
|
const budget = new Promise(resolve => { timer = setTimeout(resolve, OVERVIEW_ENRICH_BUDGET_MS); });
|
|
166
|
-
//
|
|
167
|
-
// turn still has background work, and which dispatch it is. It runs
|
|
168
|
-
//
|
|
170
|
+
// Each pane's own turn record (one small file): whether its ended
|
|
171
|
+
// turn still has background work, and which dispatch it is. It runs
|
|
172
|
+
// alongside the slower reads so a stuck transcript cannot hide children, but
|
|
169
173
|
// inside the budget, so a stuck disk cannot hold the overview either.
|
|
170
174
|
const awaited = new Map();
|
|
171
175
|
const records = Promise.all(tabs.map(async ({ group, tab }) => {
|
|
@@ -180,49 +184,67 @@ export function workspacesReader(ctx) {
|
|
|
180
184
|
return;
|
|
181
185
|
if (background)
|
|
182
186
|
awaited.set(tab, background);
|
|
183
|
-
markBackground(tab, background);
|
|
187
|
+
markBackground(tab, (background ?? 0) + (typeof tab.runningChildren === "number" ? tab.runningChildren : 0));
|
|
184
188
|
const target = targetSchema.safeParse(tab.target);
|
|
185
|
-
|
|
186
|
-
|
|
189
|
+
const stall = target.success && agents.length === 1
|
|
190
|
+
? await sessionStalls.observe(target.data, { ...agents[0], agent_status: tab.agentStatus }, async () => background) : {};
|
|
191
|
+
if (expired)
|
|
192
|
+
return;
|
|
193
|
+
Object.assign(tab, stall);
|
|
187
194
|
tab.title = title;
|
|
188
195
|
}));
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
196
|
+
// Separate bounded queues: a stalled git/model/step read cannot prevent
|
|
197
|
+
// the child tree from reaching the phone. Apply each answer as it arrives.
|
|
198
|
+
const eachTab = (read) => {
|
|
199
|
+
let next = 0;
|
|
200
|
+
return Promise.all(Array.from({ length: Math.min(4, tabs.length) }, async () => {
|
|
201
|
+
while (!expired && next < tabs.length)
|
|
202
|
+
await read(tabs[next++]);
|
|
203
|
+
}));
|
|
204
|
+
};
|
|
205
|
+
const identified = (group, tab) => {
|
|
206
|
+
const agents = agentsByTab.get(JSON.stringify([group.id, tab.id])) ?? [];
|
|
207
|
+
if (agents.length !== 1 || !provider.safeParse(agents[0].agent).success)
|
|
208
|
+
return undefined;
|
|
209
|
+
const session = chatStates.get(agents[0])?.sessionId;
|
|
210
|
+
return typeof session === "string" ? { source: agents[0].agent, session, pane: agents[0] } : undefined;
|
|
211
|
+
};
|
|
212
|
+
const enrich = Promise.all([
|
|
213
|
+
records,
|
|
214
|
+
eachTab(async ({ tab }) => {
|
|
215
|
+
if (!modules.has("git") || typeof tab.cwd !== "string" || !tab.agent)
|
|
216
|
+
return;
|
|
217
|
+
const branch = await repositoryBranch(tab.cwd);
|
|
218
|
+
if (!expired && branch !== undefined)
|
|
219
|
+
tab.branch = branch;
|
|
220
|
+
}),
|
|
221
|
+
eachTab(async ({ group, tab }) => {
|
|
222
|
+
const identity = identified(group, tab);
|
|
223
|
+
if (!identity)
|
|
224
|
+
return;
|
|
225
|
+
const children = await childActivity(identity.source, identity.session);
|
|
226
|
+
if (expired)
|
|
227
|
+
return;
|
|
228
|
+
Object.assign(tab, children);
|
|
229
|
+
markBackground(tab, (awaited.get(tab) ?? 0) + children.runningChildren);
|
|
230
|
+
}),
|
|
231
|
+
eachTab(async ({ group, tab }) => {
|
|
232
|
+
const identity = identified(group, tab);
|
|
233
|
+
if (!identity)
|
|
234
|
+
return;
|
|
235
|
+
const model = await currentModel(identity.source, identity.session).catch(() => undefined);
|
|
236
|
+
if (!expired && model)
|
|
237
|
+
tab.model = model;
|
|
238
|
+
}),
|
|
239
|
+
eachTab(async ({ group, tab }) => {
|
|
240
|
+
const identity = identified(group, tab);
|
|
241
|
+
if (!identity || identity.pane.agent_status !== "working")
|
|
242
|
+
return;
|
|
243
|
+
const step = await currentStep(identity.source, identity.session).catch(() => undefined);
|
|
244
|
+
if (!expired && step)
|
|
245
|
+
tab.currentStep = step;
|
|
246
|
+
}),
|
|
247
|
+
]);
|
|
226
248
|
await Promise.race([enrich, budget]);
|
|
227
249
|
expired = true;
|
|
228
250
|
clearTimeout(timer);
|