@firstpick/pi-package-webui 0.9.0 → 0.9.2
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/README.md +236 -24
- package/bin/pi-webui-launcher.mjs +23 -12
- package/bin/pi-webui.mjs +493 -65
- package/lib/agent-run-adapters.mjs +500 -0
- package/lib/agent-run-protocol.mjs +262 -0
- package/lib/agent-run-registry.mjs +339 -0
- package/lib/app-runner-terminal.mjs +40 -0
- package/lib/git-workflow-preferences.mjs +11 -4
- package/lib/trust-boundaries.mjs +2 -0
- package/lib/ui-layout-settings.mjs +172 -28
- package/lib/update/package-layout.mjs +50 -0
- package/lib/update/plan.mjs +11 -0
- package/package.json +2 -2
- package/public/app.js +1376 -337
- package/public/index.html +113 -68
- package/public/service-worker.js +1 -1
- package/public/styles.css +371 -93
- package/tests/agent-run-adapters.test.mjs +217 -0
- package/tests/agent-run-launcher.test.mjs +41 -0
- package/tests/agent-run-protocol.test.mjs +82 -0
- package/tests/agent-run-registry.test.mjs +102 -0
- package/tests/app-runner-terminal-static.test.mjs +28 -0
- package/tests/app-runner-terminal.test.mjs +65 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-deck-side-panels.spec.mjs +354 -0
- package/tests/browser/controls-layout.spec.mjs +122 -0
- package/tests/browser/file-tree-git-ignored.spec.mjs +113 -0
- package/tests/browser/interaction-continuity.spec.mjs +159 -0
- package/tests/browser/mobile-foundation.spec.mjs +26 -0
- package/tests/browser/model-search-focus.spec.mjs +96 -0
- package/tests/browser/optimistic-prompt.spec.mjs +22 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +224 -66
- package/tests/browser/subagent-observability.spec.mjs +87 -0
- package/tests/chat-scroll-intent-static.test.mjs +1 -1
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/component-update-api-static.test.mjs +2 -1
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +2 -0
- package/tests/control-deck-side-panels-static.test.mjs +68 -0
- package/tests/controls-layout-static.test.mjs +22 -0
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/file-tree-git-ignored-static.test.mjs +152 -0
- package/tests/file-tree-search-layout-static.test.mjs +2 -1
- package/tests/fixtures/fake-pi.mjs +43 -7
- package/tests/footer-provider-usage-visual-static.test.mjs +10 -8
- package/tests/git-workflow-preferences.test.mjs +55 -6
- package/tests/http-endpoints-harness.test.mjs +173 -14
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +18 -5
- package/tests/open-issue-wizard-static.test.mjs +2 -2
- package/tests/persistent-ui-layout-static.test.mjs +13 -13
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-context-menu-static.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +26 -16
- package/tests/side-panel-section-height-removal-static.test.mjs +4 -4
- package/tests/side-panel-section-reorder-static.test.mjs +16 -70
- package/tests/subagent-gate-visibility.test.mjs +2 -1
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +32 -0
- package/tests/subagent-reliability-integration.test.mjs +161 -0
- package/tests/subagents-helper.test.mjs +344 -4
- package/tests/terminal-tabs-resize-static.test.mjs +35 -0
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/ui-layout-settings.test.mjs +104 -32
- package/tests/update-api-harness.test.mjs +24 -10
- package/tests/update-package-layout.test.mjs +38 -0
- package/tests/update-plan.test.mjs +11 -1
- package/tests/webui-settings-locking.test.mjs +33 -3
- package/webui-rpc-helper.mjs +417 -28
package/bin/pi-webui.mjs
CHANGED
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
} from "../public/theme-contract.mjs";
|
|
23
23
|
import { authProvidersPayload, createAuthContext, logoutStoredProvider } from "../lib/auth-actions.mjs";
|
|
24
24
|
import { resolveCodexUsageAuth } from "../lib/codex-usage-auth.mjs";
|
|
25
|
+
import { AgentRunIndex, canonicalAgentRunId, normalizeAgentInstance } from "../lib/agent-run-protocol.mjs";
|
|
26
|
+
import { AgentRunRegistry } from "../lib/agent-run-registry.mjs";
|
|
25
27
|
import { resolveScopedModelsFromPatterns } from "../lib/scoped-models.mjs";
|
|
26
28
|
import {
|
|
27
29
|
readSessionSummaryPreferences,
|
|
@@ -47,6 +49,7 @@ import {
|
|
|
47
49
|
} from "../lib/session-actions.mjs";
|
|
48
50
|
import { sweepStaleTempEntries } from "../lib/temp-artifacts.mjs";
|
|
49
51
|
import { terminateProcessTree } from "../lib/process-tree.mjs";
|
|
52
|
+
import { consumeAppRunnerTerminalChunk } from "../lib/app-runner-terminal.mjs";
|
|
50
53
|
import { ThinkingStreamRecovery } from "../lib/thinking-stream-recovery.mjs";
|
|
51
54
|
import {
|
|
52
55
|
classifyGitPathFailure,
|
|
@@ -55,7 +58,8 @@ import {
|
|
|
55
58
|
} from "../lib/git-command-errors.mjs";
|
|
56
59
|
import { ComponentUpdateState, sanitizeComponentUpdateError, validateComponentUpdateRequest, validateUpdateApplyRequest, validateUpdatePlanRequest } from "../lib/component-update-state.mjs";
|
|
57
60
|
import { resolveCanonicalPiRuntime, resolveWebuiRuntimeIdentity } from "../lib/update/resolver.mjs";
|
|
58
|
-
import {
|
|
61
|
+
import { bundledPackageOwnership, packageOwnerRoot } from "../lib/update/package-layout.mjs";
|
|
62
|
+
import { createUpdatePlan, assertActionableUpdatePlan, assertPlanIdentity, assertUpdatePlanDigest } from "../lib/update/plan.mjs";
|
|
59
63
|
import { executeCommand, executePlanTargets } from "../lib/update/executor.mjs";
|
|
60
64
|
import { verifyTargetResult } from "../lib/update/verify.mjs";
|
|
61
65
|
import { acquireInstallLock, createUpdateJournal, readUpdateJournal, reconcileInterruptedUpdates, releaseInstallLock, transferInstallLock, transitionUpdateJournal } from "../lib/update/journal.mjs";
|
|
@@ -184,6 +188,10 @@ const WEBUI_HELPER_RESPONSE_PREFIX = "__PI_WEBUI_HELPER_RESPONSE__:";
|
|
|
184
188
|
const SAMPLING_PARAMS_HTTP_MAX_BYTES = 20 * 1024;
|
|
185
189
|
const WEBUI_SUBAGENTS_STATUS_KEY = "webui-subagents";
|
|
186
190
|
const WEBUI_SUBAGENTS_PAYLOAD_PREFIX = "PI_WEBUI_SUBAGENTS_V1 ";
|
|
191
|
+
const WEBUI_SUBAGENTS_V2_STATUS_KEY = "webui-subagents-v2";
|
|
192
|
+
const WEBUI_SUBAGENTS_V2_PAYLOAD_PREFIX = "PI_WEBUI_SUBAGENTS_V2 ";
|
|
193
|
+
const WEBUI_AGENT_RUN_LIMIT = 512;
|
|
194
|
+
const WEBUI_AGENT_RUN_DIAGNOSTIC_LIMIT = 128;
|
|
187
195
|
const WEBUI_SUBAGENT_RUN_LIMIT = 128;
|
|
188
196
|
const WEBUI_SUBAGENT_AGENT_LIMIT = 256;
|
|
189
197
|
const WEBUI_SUBAGENT_GATE_LIMIT = 32;
|
|
@@ -1841,16 +1849,17 @@ function latestEvents(limit = 40) {
|
|
|
1841
1849
|
return eventHistory.slice(-Math.max(0, Math.min(EVENT_HISTORY_LIMIT, limit)));
|
|
1842
1850
|
}
|
|
1843
1851
|
|
|
1844
|
-
function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20000, env = {} } = {}) {
|
|
1852
|
+
function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20000, env = {}, input, utf8Output = false } = {}) {
|
|
1845
1853
|
return new Promise((resolve) => {
|
|
1846
1854
|
const child = spawn(command, args, {
|
|
1847
1855
|
cwd,
|
|
1848
1856
|
// LC_ALL=C keeps tool output in English so error classification works
|
|
1849
1857
|
// regardless of locale.
|
|
1850
1858
|
env: { ...process.env, ...env, LC_ALL: "C" },
|
|
1851
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
1859
|
+
stdio: [input === undefined ? "ignore" : "pipe", "pipe", "pipe"],
|
|
1852
1860
|
windowsHide: true,
|
|
1853
1861
|
});
|
|
1862
|
+
if (utf8Output) child.stdout.setEncoding("utf8");
|
|
1854
1863
|
let stdout = "";
|
|
1855
1864
|
let stderr = "";
|
|
1856
1865
|
let stdoutTruncated = false;
|
|
@@ -1876,6 +1885,10 @@ function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20
|
|
|
1876
1885
|
stderr += String(chunk);
|
|
1877
1886
|
if (stderr.length > maxOutputLength) stderr = stderr.slice(-maxOutputLength);
|
|
1878
1887
|
});
|
|
1888
|
+
if (child.stdin) {
|
|
1889
|
+
child.stdin.on("error", () => {});
|
|
1890
|
+
child.stdin.end(input);
|
|
1891
|
+
}
|
|
1879
1892
|
child.on("error", (error) => {
|
|
1880
1893
|
const message = formatCommandSpawnError(command, error);
|
|
1881
1894
|
finish({ exitCode: undefined, stdout, stderr: message, error: message, errorCode: error?.code });
|
|
@@ -1888,13 +1901,7 @@ function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20
|
|
|
1888
1901
|
}
|
|
1889
1902
|
|
|
1890
1903
|
function nodeModulesParentForPackageRoot(root = packageRoot) {
|
|
1891
|
-
|
|
1892
|
-
const nodeModulesIndex = parts.lastIndexOf("node_modules");
|
|
1893
|
-
if (nodeModulesIndex >= 0) {
|
|
1894
|
-
const parent = parts.slice(0, nodeModulesIndex).join(path.sep);
|
|
1895
|
-
return parent || path.parse(root).root;
|
|
1896
|
-
}
|
|
1897
|
-
return root;
|
|
1904
|
+
return packageOwnerRoot(root);
|
|
1898
1905
|
}
|
|
1899
1906
|
|
|
1900
1907
|
function packageNodeModulesPath(nodeModulesRoot, packageName) {
|
|
@@ -4437,19 +4444,27 @@ function appendAppRunnerLine(run, line) {
|
|
|
4437
4444
|
function appendAppRunnerChunk(tab, run, chunk, streamName) {
|
|
4438
4445
|
if (!run || run.status !== "running") return;
|
|
4439
4446
|
const key = streamName === "stderr" ? "stderrRemainder" : "stdoutRemainder";
|
|
4440
|
-
const
|
|
4441
|
-
const
|
|
4442
|
-
|
|
4443
|
-
|
|
4447
|
+
const carriageReturnKey = streamName === "stderr" ? "stderrCarriageReturnPending" : "stdoutCarriageReturnPending";
|
|
4448
|
+
const reduced = consumeAppRunnerTerminalChunk({
|
|
4449
|
+
line: run[key],
|
|
4450
|
+
carriageReturnPending: run[carriageReturnKey],
|
|
4451
|
+
}, chunk);
|
|
4452
|
+
run[key] = reduced.line;
|
|
4453
|
+
run[carriageReturnKey] = reduced.carriageReturnPending;
|
|
4454
|
+
for (const line of reduced.lines) appendAppRunnerLine(run, line);
|
|
4444
4455
|
scheduleAppRunnerBroadcast(tab);
|
|
4445
4456
|
}
|
|
4446
4457
|
|
|
4447
4458
|
function flushAppRunnerRemainders(run) {
|
|
4448
|
-
for (const key of [
|
|
4459
|
+
for (const [key, carriageReturnKey] of [
|
|
4460
|
+
["stdoutRemainder", "stdoutCarriageReturnPending"],
|
|
4461
|
+
["stderrRemainder", "stderrCarriageReturnPending"],
|
|
4462
|
+
]) {
|
|
4449
4463
|
if (run?.[key]) {
|
|
4450
4464
|
appendAppRunnerLine(run, run[key]);
|
|
4451
4465
|
run[key] = "";
|
|
4452
4466
|
}
|
|
4467
|
+
if (run) run[carriageReturnKey] = false;
|
|
4453
4468
|
}
|
|
4454
4469
|
}
|
|
4455
4470
|
|
|
@@ -6064,6 +6079,46 @@ function withFileTreeGitStatus(entries = [], workspaceRoot, gitStatus) {
|
|
|
6064
6079
|
});
|
|
6065
6080
|
}
|
|
6066
6081
|
|
|
6082
|
+
async function readWorkspaceGitIgnoredPaths(workspaceRoot, entries = [], gitRoot = "") {
|
|
6083
|
+
try {
|
|
6084
|
+
const root = path.resolve(gitRoot || await getGitRoot(workspaceRoot));
|
|
6085
|
+
const candidates = new Set();
|
|
6086
|
+
for (const entry of entries) {
|
|
6087
|
+
if (!entry?.path) continue;
|
|
6088
|
+
const absolute = path.resolve(workspaceRoot, entry.path);
|
|
6089
|
+
if (absolute !== root && !pathInside(root, absolute)) continue;
|
|
6090
|
+
const relative = path.relative(root, absolute);
|
|
6091
|
+
if (!relative || path.isAbsolute(relative) || relative.startsWith(`..${path.sep}`)) continue;
|
|
6092
|
+
candidates.add(relative.split(path.sep).join("/"));
|
|
6093
|
+
}
|
|
6094
|
+
if (!candidates.size) return null;
|
|
6095
|
+
const input = `${[...candidates].join("\0")}\0`;
|
|
6096
|
+
const result = await runCommand("git", ["check-ignore", "-z", "--stdin"], {
|
|
6097
|
+
cwd: root,
|
|
6098
|
+
timeoutMs: GIT_CHANGES_COMMAND_TIMEOUT_MS,
|
|
6099
|
+
maxOutputLength: Math.max(20_000, input.length + 1),
|
|
6100
|
+
env: { GIT_OPTIONAL_LOCKS: "0" },
|
|
6101
|
+
input,
|
|
6102
|
+
utf8Output: true,
|
|
6103
|
+
});
|
|
6104
|
+
if (![0, 1].includes(result.exitCode) || result.timedOut || result.error || result.stdoutTruncated) return null;
|
|
6105
|
+
return { root, paths: new Set(result.stdout.split("\0").filter(Boolean)) };
|
|
6106
|
+
} catch {
|
|
6107
|
+
return null;
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
6110
|
+
|
|
6111
|
+
function withFileTreeGitIgnored(entries = [], workspaceRoot, gitIgnored) {
|
|
6112
|
+
if (!gitIgnored?.root || !gitIgnored.paths?.size) return entries;
|
|
6113
|
+
return entries.map((entry) => {
|
|
6114
|
+
if (!entry?.path) return entry;
|
|
6115
|
+
const absolute = path.resolve(workspaceRoot, entry.path);
|
|
6116
|
+
if (absolute !== gitIgnored.root && !pathInside(gitIgnored.root, absolute)) return entry;
|
|
6117
|
+
const relative = path.relative(gitIgnored.root, absolute).split(path.sep).join("/");
|
|
6118
|
+
return gitIgnored.paths.has(relative) ? { ...entry, gitIgnored: true } : entry;
|
|
6119
|
+
});
|
|
6120
|
+
}
|
|
6121
|
+
|
|
6067
6122
|
function fileTreeGitStatusPayload(workspaceRoot, gitStatus) {
|
|
6068
6123
|
if (!gitStatus?.root || !gitStatus.entries?.size) return null;
|
|
6069
6124
|
const root = path.resolve(workspaceRoot);
|
|
@@ -9117,6 +9172,40 @@ try {
|
|
|
9117
9172
|
|
|
9118
9173
|
process.env.PI_WEBUI_HOST = options.host;
|
|
9119
9174
|
process.env.PI_WEBUI_PORT = String(options.port);
|
|
9175
|
+
const agentRunRegistry = new AgentRunRegistry({ agentDir, port: options.port });
|
|
9176
|
+
const AGENT_RUN_PRUNE_INTERVAL_MS = 5 * 60_000;
|
|
9177
|
+
const AGENT_RUN_PROJECTION_DISMISSAL_RETENTION_MS = 24 * 60 * 60_000;
|
|
9178
|
+
const AGENT_RUN_PROJECTION_DISMISSAL_LIMIT = 2_048;
|
|
9179
|
+
const AGENT_RUN_TERMINAL_STATUSES = new Set(["done", "failed", "cancelled"]);
|
|
9180
|
+
const dismissedAgentRunProjectionKeys = new Map();
|
|
9181
|
+
let lastAgentRunPruneAt = 0;
|
|
9182
|
+
|
|
9183
|
+
function agentRunProjectionKey(instance) {
|
|
9184
|
+
return `${instance?.parentSessionId || "external"}\0${instance?.instanceId || ""}`;
|
|
9185
|
+
}
|
|
9186
|
+
|
|
9187
|
+
function agentRunProjectionCanBeDismissed(instance) {
|
|
9188
|
+
return AGENT_RUN_TERMINAL_STATUSES.has(instance?.status)
|
|
9189
|
+
|| (instance?.origin === "explicit-attach" && ["stale", "lost"].includes(instance?.status));
|
|
9190
|
+
}
|
|
9191
|
+
|
|
9192
|
+
function pruneDismissedAgentRunProjections(now = Date.now()) {
|
|
9193
|
+
for (const [key, dismissedAt] of dismissedAgentRunProjectionKeys) {
|
|
9194
|
+
if (!Number.isSafeInteger(dismissedAt) || now - dismissedAt > AGENT_RUN_PROJECTION_DISMISSAL_RETENTION_MS) dismissedAgentRunProjectionKeys.delete(key);
|
|
9195
|
+
}
|
|
9196
|
+
while (dismissedAgentRunProjectionKeys.size > AGENT_RUN_PROJECTION_DISMISSAL_LIMIT) {
|
|
9197
|
+
const oldest = dismissedAgentRunProjectionKeys.keys().next().value;
|
|
9198
|
+
if (oldest === undefined) break;
|
|
9199
|
+
dismissedAgentRunProjectionKeys.delete(oldest);
|
|
9200
|
+
}
|
|
9201
|
+
}
|
|
9202
|
+
|
|
9203
|
+
function dismissAgentRunProjection(instance, now = Date.now()) {
|
|
9204
|
+
const key = agentRunProjectionKey(instance);
|
|
9205
|
+
dismissedAgentRunProjectionKeys.delete(key);
|
|
9206
|
+
dismissedAgentRunProjectionKeys.set(key, now);
|
|
9207
|
+
pruneDismissedAgentRunProjections(now);
|
|
9208
|
+
}
|
|
9120
9209
|
const recoveryEndpointToken = String(process.env.PI_WEBUI_RECOVERY_TOKEN || "").trim() || `${randomUUID()}${randomUUID()}`;
|
|
9121
9210
|
const recoveryEndpointTokens = new Set([recoveryEndpointToken]);
|
|
9122
9211
|
|
|
@@ -9909,7 +9998,9 @@ function filterSessionSummaryTranscriptMessages(messages) {
|
|
|
9909
9998
|
}
|
|
9910
9999
|
|
|
9911
10000
|
function clearWebuiSubagents(tab) {
|
|
9912
|
-
if (tab)
|
|
10001
|
+
if (!tab) return;
|
|
10002
|
+
tab.webuiSubagents = null;
|
|
10003
|
+
tab.webuiAgentRuns = null;
|
|
9913
10004
|
}
|
|
9914
10005
|
|
|
9915
10006
|
function normalizeWebuiSubagentText(value, maxLength = 240) {
|
|
@@ -9918,7 +10009,15 @@ function normalizeWebuiSubagentText(value, maxLength = 240) {
|
|
|
9918
10009
|
}
|
|
9919
10010
|
|
|
9920
10011
|
function normalizeWebuiSubagentSource(value) {
|
|
9921
|
-
return
|
|
10012
|
+
return ["foreground", "workflow", "recovered"].includes(value) ? value : "async";
|
|
10013
|
+
}
|
|
10014
|
+
|
|
10015
|
+
function normalizeWebuiSubagentFleet(value) {
|
|
10016
|
+
if (!value || typeof value !== "object" || value.version !== 1) return null;
|
|
10017
|
+
const totalActive = Number.isSafeInteger(value.totalActive) && value.totalActive >= 0 ? value.totalActive : -1;
|
|
10018
|
+
const omitted = Number.isSafeInteger(value.omitted) && value.omitted >= 0 ? value.omitted : -1;
|
|
10019
|
+
if (totalActive < 0 || omitted < 0 || omitted > totalActive) return null;
|
|
10020
|
+
return { version: 1, totalActive, omitted };
|
|
9922
10021
|
}
|
|
9923
10022
|
|
|
9924
10023
|
function normalizeWebuiSubagentPayload(value) {
|
|
@@ -9949,9 +10048,14 @@ function normalizeWebuiSubagentPayload(value) {
|
|
|
9949
10048
|
});
|
|
9950
10049
|
}
|
|
9951
10050
|
if (status === "running" && !agents.length) continue;
|
|
10051
|
+
const source = normalizeWebuiSubagentSource(rawRun.source);
|
|
10052
|
+
const provisional = source === "recovered" || rawRun.provisional === true;
|
|
10053
|
+
const controllable = source !== "recovered" && !provisional && rawRun.controllable !== false;
|
|
9952
10054
|
runs.push({
|
|
9953
10055
|
id,
|
|
9954
|
-
source
|
|
10056
|
+
source,
|
|
10057
|
+
...(provisional ? { provisional: true } : {}),
|
|
10058
|
+
...(!controllable ? { controllable: false } : {}),
|
|
9955
10059
|
mode: ["single", "parallel", "chain"].includes(rawRun.mode) ? rawRun.mode : "single",
|
|
9956
10060
|
status,
|
|
9957
10061
|
startedAt: Number.isFinite(rawRun.startedAt) ? rawRun.startedAt : Date.now(),
|
|
@@ -10010,24 +10114,57 @@ function normalizeWebuiSubagentPayload(value) {
|
|
|
10010
10114
|
available: value.available === true,
|
|
10011
10115
|
updatedAt: Number.isFinite(value.updatedAt) ? value.updatedAt : Date.now(),
|
|
10012
10116
|
receivedAt: Date.now(),
|
|
10117
|
+
fleet: normalizeWebuiSubagentFleet(value.fleet),
|
|
10013
10118
|
runs: runs.sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id)),
|
|
10014
10119
|
gates: gates.sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id)),
|
|
10015
10120
|
};
|
|
10016
10121
|
}
|
|
10017
10122
|
|
|
10123
|
+
function normalizeWebuiAgentRunPayload(value) {
|
|
10124
|
+
if (!value || typeof value !== "object" || value.version !== 2) return null;
|
|
10125
|
+
const instances = [];
|
|
10126
|
+
const diagnostics = [];
|
|
10127
|
+
for (const raw of Array.isArray(value.instances) ? value.instances.slice(0, WEBUI_AGENT_RUN_LIMIT) : []) {
|
|
10128
|
+
try { instances.push(normalizeAgentInstance(raw)); }
|
|
10129
|
+
catch { diagnostics.push({ code: "invalid-helper-instance" }); }
|
|
10130
|
+
}
|
|
10131
|
+
for (const raw of Array.isArray(value.diagnostics) ? value.diagnostics.slice(-WEBUI_AGENT_RUN_DIAGNOSTIC_LIMIT) : []) {
|
|
10132
|
+
const code = normalizeWebuiSubagentText(raw?.code, 80);
|
|
10133
|
+
const producerId = normalizeWebuiSubagentText(raw?.producerId, 80);
|
|
10134
|
+
if (code) diagnostics.push({ code, ...(producerId ? { producerId } : {}) });
|
|
10135
|
+
}
|
|
10136
|
+
return {
|
|
10137
|
+
version: 2,
|
|
10138
|
+
available: value.available === true,
|
|
10139
|
+
updatedAt: Number.isFinite(value.updatedAt) ? value.updatedAt : Date.now(),
|
|
10140
|
+
receivedAt: Date.now(),
|
|
10141
|
+
instances,
|
|
10142
|
+
gateReferences: (Array.isArray(value.gateReferences) ? value.gateReferences : []).slice(0, 128).map((reference) => ({
|
|
10143
|
+
gateId: normalizeWebuiSubagentText(reference?.gateId, 160),
|
|
10144
|
+
attemptId: normalizeWebuiSubagentText(reference?.attemptId, 240),
|
|
10145
|
+
runId: normalizeWebuiSubagentText(reference?.runId, 160),
|
|
10146
|
+
instanceIds: (Array.isArray(reference?.instanceIds) ? reference.instanceIds : []).slice(0, 32).map((id) => normalizeWebuiSubagentText(id, 160)).filter(Boolean),
|
|
10147
|
+
resolved: reference?.resolved === true,
|
|
10148
|
+
})).filter((reference) => reference.gateId && reference.attemptId && reference.runId),
|
|
10149
|
+
diagnostics: diagnostics.slice(-WEBUI_AGENT_RUN_DIAGNOSTIC_LIMIT),
|
|
10150
|
+
};
|
|
10151
|
+
}
|
|
10152
|
+
|
|
10018
10153
|
function rememberWebuiSubagentsStatusEvent(tab, event) {
|
|
10019
|
-
if (event?.type !== "extension_ui_request" || event.method !== "setStatus"
|
|
10154
|
+
if (event?.type !== "extension_ui_request" || event.method !== "setStatus") return false;
|
|
10020
10155
|
const statusText = String(event.statusText || "");
|
|
10021
|
-
if (
|
|
10022
|
-
|
|
10156
|
+
if (event.statusKey === WEBUI_SUBAGENTS_V2_STATUS_KEY) {
|
|
10157
|
+
if (!statusText) { tab.webuiAgentRuns = null; return true; }
|
|
10158
|
+
if (!statusText.startsWith(WEBUI_SUBAGENTS_V2_PAYLOAD_PREFIX)) return true;
|
|
10159
|
+
try { tab.webuiAgentRuns = normalizeWebuiAgentRunPayload(JSON.parse(statusText.slice(WEBUI_SUBAGENTS_V2_PAYLOAD_PREFIX.length))); }
|
|
10160
|
+
catch { tab.webuiAgentRuns = null; }
|
|
10023
10161
|
return true;
|
|
10024
10162
|
}
|
|
10163
|
+
if (event.statusKey !== WEBUI_SUBAGENTS_STATUS_KEY) return false;
|
|
10164
|
+
if (!statusText) { tab.webuiSubagents = null; return true; }
|
|
10025
10165
|
if (!statusText.startsWith(WEBUI_SUBAGENTS_PAYLOAD_PREFIX)) return true;
|
|
10026
|
-
try {
|
|
10027
|
-
|
|
10028
|
-
} catch {
|
|
10029
|
-
tab.webuiSubagents = null;
|
|
10030
|
-
}
|
|
10166
|
+
try { tab.webuiSubagents = normalizeWebuiSubagentPayload(JSON.parse(statusText.slice(WEBUI_SUBAGENTS_PAYLOAD_PREFIX.length))); }
|
|
10167
|
+
catch { tab.webuiSubagents = null; }
|
|
10031
10168
|
return true;
|
|
10032
10169
|
}
|
|
10033
10170
|
|
|
@@ -10827,6 +10964,7 @@ function createTabRecord({ id, index, title, titleSource, conversationStarted, c
|
|
|
10827
10964
|
extensionWidgets: new Map(),
|
|
10828
10965
|
sessionSummary: null,
|
|
10829
10966
|
webuiSubagents: null,
|
|
10967
|
+
webuiAgentRuns: null,
|
|
10830
10968
|
subagentDisplayTitle: undefined,
|
|
10831
10969
|
subagentDisplayTitlePromise: undefined,
|
|
10832
10970
|
webuiHelperRequests: new Map(),
|
|
@@ -11012,43 +11150,191 @@ async function resolveSubagentDisplayTitle(tab) {
|
|
|
11012
11150
|
return tab.subagentDisplayTitlePromise;
|
|
11013
11151
|
}
|
|
11014
11152
|
|
|
11015
|
-
|
|
11153
|
+
function tabParentSessionId(tab) {
|
|
11154
|
+
const raw = tab?.lastState?.sessionId;
|
|
11155
|
+
return raw ? canonicalAgentRunId(raw, "session") : null;
|
|
11156
|
+
}
|
|
11157
|
+
|
|
11158
|
+
function legacyRunInstances(tab, run) {
|
|
11159
|
+
const parentSessionId = tabParentSessionId(tab) || `legacy-tab:${tab.id}`;
|
|
11160
|
+
const startedAt = Number.isSafeInteger(run.startedAt) ? run.startedAt : Date.now();
|
|
11161
|
+
return run.agents.map((agent) => {
|
|
11162
|
+
const status = ["running", "done", "failed", "cancelled"].includes(agent.status) ? agent.status : run.status;
|
|
11163
|
+
const endedAt = status === "running" ? null : Math.max(startedAt, Number.isSafeInteger(run.endedAt) ? run.endedAt : Date.now());
|
|
11164
|
+
return normalizeAgentInstance({
|
|
11165
|
+
version: 1,
|
|
11166
|
+
instanceId: canonicalAgentRunId(agent.id, "agent"),
|
|
11167
|
+
runId: canonicalAgentRunId(run.id, "run"),
|
|
11168
|
+
parentSessionId,
|
|
11169
|
+
launcher: run.source === "workflow" ? "workflow" : "pi-subagents",
|
|
11170
|
+
provider: run.source === "workflow" ? "workflow-run" : "webui-helper",
|
|
11171
|
+
origin: run.source,
|
|
11172
|
+
name: agent.name,
|
|
11173
|
+
status,
|
|
11174
|
+
startedAt,
|
|
11175
|
+
updatedAt: endedAt ?? Date.now(),
|
|
11176
|
+
endedAt,
|
|
11177
|
+
model: agent.model,
|
|
11178
|
+
thinking: agent.thinking,
|
|
11179
|
+
activityState: agent.activityState,
|
|
11180
|
+
currentTool: agent.currentTool,
|
|
11181
|
+
capabilities: {
|
|
11182
|
+
open: webuiSubagentRunSupportsInteraction(run),
|
|
11183
|
+
refresh: webuiSubagentRunSupportsInteraction(run),
|
|
11184
|
+
cancel: status === "running" && webuiSubagentRunSupportsInteraction(run),
|
|
11185
|
+
steer: false,
|
|
11186
|
+
},
|
|
11187
|
+
outputRef: { kind: "none" },
|
|
11188
|
+
});
|
|
11189
|
+
});
|
|
11190
|
+
}
|
|
11191
|
+
|
|
11192
|
+
function groupedCanonicalRuns(instances) {
|
|
11193
|
+
const byRun = new Map();
|
|
11194
|
+
for (const instance of instances) {
|
|
11195
|
+
const current = byRun.get(instance.runId) || [];
|
|
11196
|
+
current.push(instance);
|
|
11197
|
+
byRun.set(instance.runId, current);
|
|
11198
|
+
}
|
|
11199
|
+
return [...byRun.entries()].map(([runId, agents]) => {
|
|
11200
|
+
agents.sort((a, b) => a.startedAt - b.startedAt || a.instanceId.localeCompare(b.instanceId));
|
|
11201
|
+
const status = agents.some((agent) => agent.status === "running") ? "running"
|
|
11202
|
+
: agents.some((agent) => agent.status === "stale") ? "stale"
|
|
11203
|
+
: agents.some((agent) => agent.status === "lost") ? "lost"
|
|
11204
|
+
: agents.some((agent) => agent.status === "failed") ? "failed"
|
|
11205
|
+
: agents.some((agent) => agent.status === "cancelled") ? "cancelled" : "done";
|
|
11206
|
+
return {
|
|
11207
|
+
id: runId,
|
|
11208
|
+
source: agents[0].origin || agents[0].launcher,
|
|
11209
|
+
launcher: agents[0].launcher,
|
|
11210
|
+
provider: agents[0].provider,
|
|
11211
|
+
status,
|
|
11212
|
+
startedAt: Math.min(...agents.map((agent) => agent.startedAt)),
|
|
11213
|
+
endedAt: agents.every((agent) => Number.isSafeInteger(agent.endedAt)) ? Math.max(...agents.map((agent) => agent.endedAt)) : undefined,
|
|
11214
|
+
capabilities: {
|
|
11215
|
+
open: agents.some((agent) => agent.capabilities.open),
|
|
11216
|
+
refresh: agents.some((agent) => agent.capabilities.refresh),
|
|
11217
|
+
cancel: agents.some((agent) => agent.capabilities.cancel),
|
|
11218
|
+
steer: agents.some((agent) => agent.capabilities.steer),
|
|
11219
|
+
},
|
|
11220
|
+
agents: agents.map((agent) => ({
|
|
11221
|
+
id: agent.instanceId,
|
|
11222
|
+
instanceId: agent.instanceId,
|
|
11223
|
+
name: agent.name || "Agent",
|
|
11224
|
+
status: agent.status,
|
|
11225
|
+
launcher: agent.launcher,
|
|
11226
|
+
provider: agent.provider,
|
|
11227
|
+
origin: agent.origin,
|
|
11228
|
+
model: agent.model,
|
|
11229
|
+
thinking: agent.thinking,
|
|
11230
|
+
activityState: agent.activityState,
|
|
11231
|
+
currentTool: agent.currentTool,
|
|
11232
|
+
capabilities: agent.capabilities,
|
|
11233
|
+
outputRef: agent.outputRef,
|
|
11234
|
+
})),
|
|
11235
|
+
};
|
|
11236
|
+
}).sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id));
|
|
11237
|
+
}
|
|
11238
|
+
|
|
11239
|
+
async function webuiSubagentsData({ includeSelections = false } = {}) {
|
|
11016
11240
|
const sortedTabs = [...tabs.values()].sort((a, b) => a.index - b.index || a.title.localeCompare(b.title));
|
|
11017
11241
|
const tabSummaries = await Promise.all(sortedTabs.map(async (tab) => {
|
|
11018
11242
|
const status = tab.webuiSubagents || { version: 1, available: false, updatedAt: null, receivedAt: null, runs: [], gates: [] };
|
|
11019
11243
|
const runs = Array.isArray(status.runs) ? status.runs : [];
|
|
11020
11244
|
const gates = Array.isArray(status.gates) ? status.gates : [];
|
|
11021
|
-
const tabTitle = runs.length || gates.length ? await resolveSubagentDisplayTitle(tab) : tab.title;
|
|
11245
|
+
const tabTitle = runs.length || gates.length || tab.webuiAgentRuns?.instances?.length ? await resolveSubagentDisplayTitle(tab) : tab.title;
|
|
11022
11246
|
return {
|
|
11023
|
-
tabId: tab.id,
|
|
11024
|
-
tabIndex: tab.index,
|
|
11025
|
-
tabTitle,
|
|
11026
|
-
cwd: tab.cwd,
|
|
11247
|
+
tabId: tab.id, tabIndex: tab.index, tabTitle, cwd: tab.cwd,
|
|
11027
11248
|
sessionName: normalizeWebuiSubagentText(tab.lastState?.sessionName || tab.title, 160),
|
|
11028
11249
|
sessionFile: tabRestorableSessionFile(tab) || null,
|
|
11029
|
-
running: tab.rpc.isRunning(),
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
runs,
|
|
11034
|
-
gates,
|
|
11250
|
+
running: tab.rpc.isRunning(), available: status.available === true || tab.webuiAgentRuns?.available === true,
|
|
11251
|
+
updatedAt: status.updatedAt || tab.webuiAgentRuns?.updatedAt || null,
|
|
11252
|
+
receivedAt: status.receivedAt || tab.webuiAgentRuns?.receivedAt || null,
|
|
11253
|
+
fleet: status.fleet || null, runs, gates,
|
|
11035
11254
|
agentCount: runs.reduce((count, run) => count + run.agents.length, 0),
|
|
11036
11255
|
runningRuns: runs.filter((run) => run.status === "running").length,
|
|
11037
11256
|
runningAgents: runs.reduce((count, run) => count + run.agents.filter((agent) => agent.status === "running").length, 0),
|
|
11038
11257
|
gateCount: gates.length,
|
|
11039
11258
|
};
|
|
11040
11259
|
}));
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11260
|
+
const index = new AgentRunIndex();
|
|
11261
|
+
const selections = new Map();
|
|
11262
|
+
const diagnostics = [];
|
|
11263
|
+
for (const tab of sortedTabs) {
|
|
11264
|
+
const canonical = tab.webuiAgentRuns?.instances;
|
|
11265
|
+
if (Array.isArray(canonical)) {
|
|
11266
|
+
for (const instance of canonical) {
|
|
11267
|
+
index.upsert(instance, { producerId: instance.provider, lifecycleOwner: true, capabilityOwner: true });
|
|
11268
|
+
selections.set(`${instance.parentSessionId || "external"}\0${instance.instanceId}`, { kind: "helper", tab, instance });
|
|
11269
|
+
}
|
|
11270
|
+
diagnostics.push(...(tab.webuiAgentRuns.diagnostics || []));
|
|
11271
|
+
} else {
|
|
11272
|
+
for (const run of tab.webuiSubagents?.runs || []) for (const instance of legacyRunInstances(tab, run)) {
|
|
11273
|
+
index.upsert(instance, { producerId: instance.provider, lifecycleOwner: true, capabilityOwner: true });
|
|
11274
|
+
selections.set(`${instance.parentSessionId}\0${instance.instanceId}`, { kind: "legacy-helper", tab, instance, run, agent: run.agents.find((candidate) => canonicalAgentRunId(candidate.id, "agent") === instance.instanceId) });
|
|
11275
|
+
}
|
|
11276
|
+
}
|
|
11277
|
+
}
|
|
11278
|
+
let registrySnapshot = { records: [], diagnostics: [], omitted: 0, artifacts: new Map() };
|
|
11279
|
+
const reconcileNow = Date.now();
|
|
11280
|
+
pruneDismissedAgentRunProjections(reconcileNow);
|
|
11281
|
+
try {
|
|
11282
|
+
if (reconcileNow - lastAgentRunPruneAt >= AGENT_RUN_PRUNE_INTERVAL_MS) {
|
|
11283
|
+
lastAgentRunPruneAt = reconcileNow;
|
|
11284
|
+
try { await agentRunRegistry.prune({ now: reconcileNow }); }
|
|
11285
|
+
catch { diagnostics.push({ code: "registry-prune-unavailable" }); }
|
|
11286
|
+
}
|
|
11287
|
+
registrySnapshot = await agentRunRegistry.readRecords({ now: reconcileNow });
|
|
11288
|
+
} catch { diagnostics.push({ code: "registry-unavailable" }); }
|
|
11289
|
+
for (const record of registrySnapshot.records) {
|
|
11290
|
+
const key = agentRunProjectionKey(record.instance);
|
|
11291
|
+
if (dismissedAgentRunProjectionKeys.has(key)) {
|
|
11292
|
+
if (agentRunProjectionCanBeDismissed(record.instance)) continue;
|
|
11293
|
+
dismissedAgentRunProjectionKeys.delete(key);
|
|
11294
|
+
}
|
|
11295
|
+
index.upsert(record.instance, { producerId: record.producerId });
|
|
11296
|
+
if (!selections.has(key) || record.instance.outputRef.kind === "session-jsonl") selections.set(key, { kind: "registry", instance: record.instance, record });
|
|
11297
|
+
}
|
|
11298
|
+
diagnostics.push(...registrySnapshot.diagnostics, ...(registrySnapshot.omitted ? [{ code: "registry-records-omitted", count: registrySnapshot.omitted }] : []));
|
|
11299
|
+
|
|
11300
|
+
const byParent = new Map();
|
|
11301
|
+
for (const instance of index.values()) {
|
|
11302
|
+
const key = instance.parentSessionId || "external";
|
|
11303
|
+
const rows = byParent.get(key) || [];
|
|
11304
|
+
rows.push(instance);
|
|
11305
|
+
byParent.set(key, rows);
|
|
11306
|
+
}
|
|
11307
|
+
const groups = [];
|
|
11308
|
+
const claimedParents = new Set();
|
|
11309
|
+
for (const tabSummary of tabSummaries) {
|
|
11310
|
+
const tab = tabs.get(tabSummary.tabId);
|
|
11311
|
+
const parentId = tabParentSessionId(tab) || `legacy-tab:${tabSummary.tabId}`;
|
|
11312
|
+
claimedParents.add(parentId);
|
|
11313
|
+
groups.push({
|
|
11314
|
+
id: `tab:${tabSummary.tabId}`, kind: "tab", tabId: tabSummary.tabId, tabIndex: tabSummary.tabIndex,
|
|
11315
|
+
title: tabSummary.tabTitle, cwdLabel: path.basename(tabSummary.cwd) || tabSummary.cwd,
|
|
11316
|
+
runs: groupedCanonicalRuns(byParent.get(parentId) || []), gates: tabSummary.gates,
|
|
11317
|
+
});
|
|
11318
|
+
}
|
|
11319
|
+
const externalInstances = [...byParent.entries()].filter(([parent]) => !claimedParents.has(parent)).flatMap(([, rows]) => rows);
|
|
11320
|
+
if (externalInstances.length) groups.push({ id: "external", kind: "external", title: "External agents", runs: groupedCanonicalRuns(externalInstances), gates: [] });
|
|
11321
|
+
const instances = index.values();
|
|
11322
|
+
const counts = {
|
|
11323
|
+
totalRuns: groups.reduce((count, group) => count + group.runs.length, 0),
|
|
11324
|
+
totalAgents: instances.length,
|
|
11325
|
+
runningAgents: instances.filter((instance) => instance.status === "running").length,
|
|
11326
|
+
staleAgents: instances.filter((instance) => instance.status === "stale").length,
|
|
11327
|
+
byLauncher: Object.fromEntries([...new Set(instances.map((instance) => instance.launcher))].sort().map((launcher) => [launcher, instances.filter((instance) => instance.launcher === launcher).length])),
|
|
11328
|
+
};
|
|
11329
|
+
const fleet = tabSummaries.reduce((summary, tab) => ({ version: 1, totalActive: Math.min(Number.MAX_SAFE_INTEGER, summary.totalActive + Number(tab.fleet?.totalActive || 0)), omitted: Math.min(Number.MAX_SAFE_INTEGER, summary.omitted + Number(tab.fleet?.omitted || 0)) }), { version: 1, totalActive: 0, omitted: 0 });
|
|
11330
|
+
const overview = {
|
|
11331
|
+
version: 2, updatedAt: Date.now(), available: tabSummaries.some((tab) => tab.available) || registrySnapshot.records.length > 0,
|
|
11332
|
+
groups, counts, diagnostics: diagnostics.slice(-WEBUI_AGENT_RUN_DIAGNOSTIC_LIMIT), fleet,
|
|
11333
|
+
totalRuns: counts.totalRuns, totalAgents: counts.totalAgents,
|
|
11334
|
+
runningRuns: groups.reduce((count, group) => count + group.runs.filter((run) => run.status === "running").length, 0),
|
|
11335
|
+
runningAgents: counts.runningAgents, totalGates: tabSummaries.reduce((count, tab) => count + tab.gateCount, 0), tabs: tabSummaries,
|
|
11051
11336
|
};
|
|
11337
|
+
return includeSelections ? { overview, selections, registrySnapshot } : overview;
|
|
11052
11338
|
}
|
|
11053
11339
|
|
|
11054
11340
|
function normalizeWebuiSubagentTranscriptValue(value, maxLength = WEBUI_SUBAGENT_OUTPUT_LINE_LENGTH) {
|
|
@@ -11193,16 +11479,146 @@ function normalizeWebuiSubagentOutput(value, selection) {
|
|
|
11193
11479
|
};
|
|
11194
11480
|
}
|
|
11195
11481
|
|
|
11196
|
-
|
|
11482
|
+
function webuiSubagentRunSupportsInteraction(run) {
|
|
11483
|
+
return run?.source !== "recovered" && run?.provisional !== true && run?.controllable !== false;
|
|
11484
|
+
}
|
|
11485
|
+
|
|
11486
|
+
function requireInteractiveWebuiSubagentRun(tab, runId) {
|
|
11487
|
+
const normalizedRunId = normalizeWebuiSubagentText(runId, 160);
|
|
11488
|
+
const runs = Array.isArray(tab.webuiSubagents?.runs) ? tab.webuiSubagents.runs : [];
|
|
11489
|
+
const run = runs.find((candidate) => candidate.id === normalizedRunId);
|
|
11490
|
+
if (!run) throw makeHttpError(404, `Subagent run not found: ${normalizedRunId}`);
|
|
11491
|
+
if (!webuiSubagentRunSupportsInteraction(run)) throw makeHttpError(409, "Recovered provisional subagents are status-only");
|
|
11492
|
+
return run;
|
|
11493
|
+
}
|
|
11494
|
+
|
|
11495
|
+
function rejectUnsupportedWebuiSubagentRun(tab, runId) {
|
|
11496
|
+
const normalizedRunId = normalizeWebuiSubagentText(runId, 160);
|
|
11197
11497
|
const runs = Array.isArray(tab.webuiSubagents?.runs) ? tab.webuiSubagents.runs : [];
|
|
11198
|
-
const run = runs.find((candidate) => candidate.id ===
|
|
11199
|
-
if (!run) throw makeHttpError(
|
|
11498
|
+
const run = runs.find((candidate) => candidate.id === normalizedRunId);
|
|
11499
|
+
if (run && !webuiSubagentRunSupportsInteraction(run)) throw makeHttpError(409, "Recovered provisional subagents are status-only");
|
|
11500
|
+
return normalizedRunId;
|
|
11501
|
+
}
|
|
11502
|
+
|
|
11503
|
+
async function webuiSubagentOutputData(tab, runId, agentId) {
|
|
11504
|
+
const run = requireInteractiveWebuiSubagentRun(tab, runId);
|
|
11200
11505
|
const agent = (Array.isArray(run.agents) ? run.agents : []).find((candidate) => candidate.id === agentId);
|
|
11201
11506
|
if (!agent) throw makeHttpError(404, `Subagent not found: ${agentId}`);
|
|
11202
11507
|
const data = await sendWebuiHelperCommand(tab, "subagent-output", { runId, agentId });
|
|
11203
11508
|
return normalizeWebuiSubagentOutput(data, { run, agent });
|
|
11204
11509
|
}
|
|
11205
11510
|
|
|
11511
|
+
function canonicalOutputSelection(groupId, runId, instanceId, state) {
|
|
11512
|
+
const group = state.overview.groups.find((candidate) => candidate.id === groupId);
|
|
11513
|
+
const run = group?.runs.find((candidate) => candidate.id === runId);
|
|
11514
|
+
const agent = run?.agents.find((candidate) => candidate.instanceId === instanceId);
|
|
11515
|
+
if (!group || !run || !agent) throw makeHttpError(404, "Agent run output is no longer tracked");
|
|
11516
|
+
for (const selection of state.selections.values()) {
|
|
11517
|
+
if (selection.instance.runId !== runId || selection.instance.instanceId !== instanceId) continue;
|
|
11518
|
+
if (group.kind === "tab") {
|
|
11519
|
+
const tab = tabs.get(group.tabId);
|
|
11520
|
+
if (selection.tab?.id === group.tabId || selection.instance.parentSessionId === tabParentSessionId(tab)) return { group, run, agent, selection };
|
|
11521
|
+
} else if (!selection.instance.parentSessionId || ![...tabs.values()].some((tab) => tabParentSessionId(tab) === selection.instance.parentSessionId)) {
|
|
11522
|
+
return { group, run, agent, selection };
|
|
11523
|
+
}
|
|
11524
|
+
}
|
|
11525
|
+
throw makeHttpError(404, "Agent run output is no longer tracked");
|
|
11526
|
+
}
|
|
11527
|
+
|
|
11528
|
+
async function boundedSessionMessages(sessionFile, maximum = 256 * 1024) {
|
|
11529
|
+
const handle = await open(sessionFile, "r");
|
|
11530
|
+
try {
|
|
11531
|
+
const info = await handle.stat();
|
|
11532
|
+
const length = Math.min(info.size, maximum);
|
|
11533
|
+
const buffer = Buffer.alloc(length);
|
|
11534
|
+
await handle.read(buffer, 0, length, Math.max(0, info.size - length));
|
|
11535
|
+
const text = buffer.toString("utf8");
|
|
11536
|
+
const lines = text.split("\n");
|
|
11537
|
+
if (info.size > length) lines.shift();
|
|
11538
|
+
const messages = [];
|
|
11539
|
+
for (const line of lines) {
|
|
11540
|
+
if (!line || Buffer.byteLength(line) > 64 * 1024) continue;
|
|
11541
|
+
try {
|
|
11542
|
+
const entry = JSON.parse(line);
|
|
11543
|
+
if (entry?.type === "message" && entry.message) messages.push(entry.message);
|
|
11544
|
+
else if (["assistant", "toolResult"].includes(entry?.role)) messages.push(entry);
|
|
11545
|
+
} catch {}
|
|
11546
|
+
}
|
|
11547
|
+
return messages;
|
|
11548
|
+
} finally { await handle.close(); }
|
|
11549
|
+
}
|
|
11550
|
+
|
|
11551
|
+
function registryOutputData(instance, events = [], transcript = []) {
|
|
11552
|
+
const outputLines = events.filter((event) => typeof event?.message === "string").slice(-WEBUI_SUBAGENT_OUTPUT_LINE_LIMIT).map((event) => event.message.slice(0, WEBUI_SUBAGENT_OUTPUT_LINE_LENGTH));
|
|
11553
|
+
const recentTools = events.filter((event) => typeof event?.tool === "string").slice(-20).map((event) => ({ tool: event.tool.slice(0, 120), args: "", endMs: Number.isFinite(event.at) ? event.at : undefined }));
|
|
11554
|
+
return {
|
|
11555
|
+
version: 1, runId: instance.runId, source: instance.launcher, mode: "single", startedAt: instance.startedAt, updatedAt: instance.updatedAt,
|
|
11556
|
+
agent: {
|
|
11557
|
+
id: instance.instanceId, name: instance.name || "Agent", index: 0, nested: false, status: instance.status,
|
|
11558
|
+
activityState: instance.activityState, currentTool: instance.currentTool, model: instance.model, thinking: instance.thinking,
|
|
11559
|
+
telemetry: normalizeWebuiSubagentTelemetry(null, { model: instance.model, effort: instance.thinking }),
|
|
11560
|
+
recentTools, recentOutput: outputLines, transcript: normalizeWebuiSubagentTranscript(transcript),
|
|
11561
|
+
...(!outputLines.length && !transcript.length ? { unavailable: true, unavailableReason: "No bounded output has been registered for this agent." } : {}),
|
|
11562
|
+
},
|
|
11563
|
+
};
|
|
11564
|
+
}
|
|
11565
|
+
|
|
11566
|
+
async function canonicalWebuiSubagentOutputData(groupId, runId, instanceId) {
|
|
11567
|
+
const state = await webuiSubagentsData({ includeSelections: true });
|
|
11568
|
+
const { selection } = canonicalOutputSelection(groupId, runId, instanceId, state);
|
|
11569
|
+
const instance = selection.instance;
|
|
11570
|
+
if (!instance.capabilities.open) throw makeHttpError(409, "This agent provider does not support opening output");
|
|
11571
|
+
if (selection.kind === "legacy-helper") return webuiSubagentOutputData(selection.tab, selection.run.id, selection.agent.id);
|
|
11572
|
+
if (selection.kind === "helper") {
|
|
11573
|
+
if (instance.outputRef.kind !== "helper") return registryOutputData(instance);
|
|
11574
|
+
const data = await sendWebuiHelperCommand(selection.tab, "subagent-output", { outputId: instance.outputRef.id });
|
|
11575
|
+
const run = { id: instance.runId, source: instance.origin || "async", mode: "single", startedAt: instance.startedAt };
|
|
11576
|
+
const agent = { id: instance.instanceId, name: instance.name || "Agent", index: 0, model: instance.model, thinking: instance.thinking };
|
|
11577
|
+
return normalizeWebuiSubagentOutput(data, { run, agent });
|
|
11578
|
+
}
|
|
11579
|
+
if (instance.outputRef.kind === "session-jsonl") {
|
|
11580
|
+
const locator = await agentRunRegistry.resolveSessionLocator(instance.outputRef.id, { allowedRoots: allowedSessionDirs() });
|
|
11581
|
+
if (!locator) throw makeHttpError(404, "Registered session output is unavailable");
|
|
11582
|
+
return registryOutputData(instance, [], await boundedSessionMessages(locator.sessionFile));
|
|
11583
|
+
}
|
|
11584
|
+
if (["rpc-events", "json-events", "plain-log", "registry-artifact"].includes(instance.outputRef.kind)) {
|
|
11585
|
+
const artifact = await agentRunRegistry.readArtifact(instance.outputRef.id);
|
|
11586
|
+
return registryOutputData(instance, artifact?.events || []);
|
|
11587
|
+
}
|
|
11588
|
+
return registryOutputData(instance);
|
|
11589
|
+
}
|
|
11590
|
+
|
|
11591
|
+
async function canonicalWebuiSubagentAction(action, body) {
|
|
11592
|
+
const groupId = normalizeWebuiSubagentText(body.group, 240);
|
|
11593
|
+
const runId = normalizeWebuiSubagentText(body.runId || body.run, 160);
|
|
11594
|
+
const requestedAgentId = normalizeWebuiSubagentText(body.agentId || body.agent, 160);
|
|
11595
|
+
if (!groupId || !runId) throw makeHttpError(400, "group and runId are required");
|
|
11596
|
+
const state = await webuiSubagentsData({ includeSelections: true });
|
|
11597
|
+
const group = state.overview.groups.find((candidate) => candidate.id === groupId);
|
|
11598
|
+
const run = group?.runs.find((candidate) => candidate.id === runId);
|
|
11599
|
+
const agent = requestedAgentId ? run?.agents.find((candidate) => candidate.instanceId === requestedAgentId) : run?.agents[0];
|
|
11600
|
+
if (!group || !run || !agent) throw makeHttpError(404, "Agent run is no longer tracked");
|
|
11601
|
+
const { selection } = canonicalOutputSelection(groupId, runId, agent.instanceId, state);
|
|
11602
|
+
if (action === "cancel") {
|
|
11603
|
+
if (selection.kind !== "helper" && selection.kind !== "legacy-helper") throw makeHttpError(409, "This agent provider does not support cancellation");
|
|
11604
|
+
if (!agent.capabilities?.cancel) throw makeHttpError(409, "This agent provider does not support cancellation");
|
|
11605
|
+
return sendWebuiHelperCommand(selection.tab, "subagent-cancel", { runId: selection.kind === "legacy-helper" ? selection.run.id : selection.instance.runId, reason: body.reason, note: body.note });
|
|
11606
|
+
}
|
|
11607
|
+
if (!agentRunProjectionCanBeDismissed(selection.instance)) {
|
|
11608
|
+
throw makeHttpError(409, "Only terminal retained runs or stale attached-session projections can be dismissed");
|
|
11609
|
+
}
|
|
11610
|
+
if (selection.kind === "registry") {
|
|
11611
|
+
const registrySelections = run.agents.map((candidate) => canonicalOutputSelection(groupId, runId, candidate.instanceId, state).selection);
|
|
11612
|
+
if (registrySelections.some((candidate) => candidate.kind !== "registry" || !agentRunProjectionCanBeDismissed(candidate.instance))) {
|
|
11613
|
+
throw makeHttpError(409, "Only terminal registry-owned runs or stale attached-session projections can be dismissed as one projection");
|
|
11614
|
+
}
|
|
11615
|
+
for (const candidate of registrySelections) dismissAgentRunProjection(candidate.instance);
|
|
11616
|
+
return { runId: selection.instance.runId, dismissed: true };
|
|
11617
|
+
}
|
|
11618
|
+
if (selection.kind !== "helper" && selection.kind !== "legacy-helper") throw makeHttpError(409, `This agent provider does not support ${action}`);
|
|
11619
|
+
return sendWebuiHelperCommand(selection.tab, "subagent-dismiss", { runId: selection.kind === "legacy-helper" ? selection.run.id : selection.instance.runId });
|
|
11620
|
+
}
|
|
11621
|
+
|
|
11206
11622
|
function restorableTabDescriptor(tab, state = null) {
|
|
11207
11623
|
return normalizeRestoreTabDescriptor({
|
|
11208
11624
|
id: tab.id,
|
|
@@ -11433,10 +11849,9 @@ function updateOwnerForTarget(target, identities) {
|
|
|
11433
11849
|
}
|
|
11434
11850
|
const active = identities.pi.active;
|
|
11435
11851
|
const piRoot = active?.packageRoot || "";
|
|
11436
|
-
const
|
|
11437
|
-
const bundled = piRoot && exactUpdatePathInside(path.join(packageRoot, "node_modules"), piRoot);
|
|
11852
|
+
const bundled = bundledPackageOwnership({ hostPackageRoot: packageRoot, packageRoot: piRoot, source: active?.source });
|
|
11438
11853
|
if (bundled && webuiDevServer) return { manager: "unknown", packageRoot: piRoot, ownerRoot: packageRoot, sourceCheckout: true };
|
|
11439
|
-
if (bundled) return { manager: "npm", packageRoot: piRoot, ownerRoot:
|
|
11854
|
+
if (bundled) return { manager: "npm", packageRoot: piRoot, ownerRoot: bundled.ownerRoot, topLevel: true };
|
|
11440
11855
|
if ((active?.source === "explicit" || active?.source === "path") && piRoot) {
|
|
11441
11856
|
return { manager: "pi", packageRoot: piRoot, ownerRoot: piRoot, topLevel: true };
|
|
11442
11857
|
}
|
|
@@ -11453,7 +11868,7 @@ async function createServerOwnedUpdatePlan(targets) {
|
|
|
11453
11868
|
if (!status[target]?.checked || !status[target]?.latestVersion) throw makeHttpError(409, `${target} exact target metadata is unavailable.`);
|
|
11454
11869
|
}
|
|
11455
11870
|
const piRoot = identities.pi.active?.packageRoot || "";
|
|
11456
|
-
const bundledPi = Boolean(
|
|
11871
|
+
const bundledPi = Boolean(bundledPackageOwnership({ hostPackageRoot: packageRoot, packageRoot: piRoot, source: identities.pi.active?.source }));
|
|
11457
11872
|
const requested = new Set(targets);
|
|
11458
11873
|
const desiredPiVersion = requested.has("pi") ? status.pi.latestVersion : identities.pi.active?.version;
|
|
11459
11874
|
const desiredWebuiVersion = requested.has("webui") ? status.webui.latestVersion : identities.webui.version;
|
|
@@ -11555,6 +11970,7 @@ async function createServerOwnedUpdatePlan(targets) {
|
|
|
11555
11970
|
return { version: targetVersion, registry, metadata };
|
|
11556
11971
|
},
|
|
11557
11972
|
});
|
|
11973
|
+
assertActionableUpdatePlan(plan);
|
|
11558
11974
|
await createUpdateJournal(agentDir, plan);
|
|
11559
11975
|
return plan;
|
|
11560
11976
|
}
|
|
@@ -11612,6 +12028,7 @@ async function applyServerOwnedUpdate(transactionId, planDigest) {
|
|
|
11612
12028
|
const journal = await readUpdateJournal(agentDir, transactionId);
|
|
11613
12029
|
if (!journal) throw makeHttpError(404, "Update transaction was not found.");
|
|
11614
12030
|
assertUpdatePlanDigest(journal.plan, planDigest);
|
|
12031
|
+
assertActionableUpdatePlan(journal.plan);
|
|
11615
12032
|
if (journal.state !== "planned") throw makeHttpError(409, `Update transaction is already ${journal.state}.`);
|
|
11616
12033
|
piUpdateInProgress = true;
|
|
11617
12034
|
let lock = null;
|
|
@@ -13267,12 +13684,13 @@ async function getFileTreeData(tab, requestedPath = "") {
|
|
|
13267
13684
|
statFileTreeEntries(resolved.targetPath, dirents, resolved.root, resolved.realRoot),
|
|
13268
13685
|
readWorkspaceGitStatusIndex(resolved.root),
|
|
13269
13686
|
]);
|
|
13687
|
+
const gitIgnored = await readWorkspaceGitIgnoredPaths(resolved.root, listed.entries, gitStatus?.root);
|
|
13270
13688
|
return {
|
|
13271
13689
|
root: resolved.root,
|
|
13272
13690
|
displayRoot: displayPath(resolved.root),
|
|
13273
13691
|
path: resolved.relative,
|
|
13274
13692
|
displayPath: displayPath(resolved.targetPath),
|
|
13275
|
-
entries: withFileTreeGitStatus(listed.entries, resolved.root, gitStatus),
|
|
13693
|
+
entries: withFileTreeGitIgnored(withFileTreeGitStatus(listed.entries, resolved.root, gitStatus), resolved.root, gitIgnored),
|
|
13276
13694
|
gitStatus: fileTreeGitStatusPayload(resolved.root, gitStatus),
|
|
13277
13695
|
truncated: listed.truncated,
|
|
13278
13696
|
total: listed.total,
|
|
@@ -13358,11 +13776,12 @@ async function getFileSearchData(tab, rawQuery = "") {
|
|
|
13358
13776
|
}
|
|
13359
13777
|
}
|
|
13360
13778
|
truncated = queue.length > 0 || scanned >= FILE_SEARCH_MAX_SCANNED || entries.length >= FILE_SEARCH_MAX_RESULTS;
|
|
13779
|
+
const gitIgnored = await readWorkspaceGitIgnoredPaths(resolved.root, entries, gitStatus?.root);
|
|
13361
13780
|
return {
|
|
13362
13781
|
root: resolved.root,
|
|
13363
13782
|
displayRoot: displayPath(resolved.root),
|
|
13364
13783
|
query,
|
|
13365
|
-
entries: withFileTreeGitStatus(entries, resolved.root, gitStatus),
|
|
13784
|
+
entries: withFileTreeGitIgnored(withFileTreeGitStatus(entries, resolved.root, gitStatus), resolved.root, gitIgnored),
|
|
13366
13785
|
gitStatus: fileTreeGitStatusPayload(resolved.root, gitStatus),
|
|
13367
13786
|
truncated,
|
|
13368
13787
|
total: entries.length,
|
|
@@ -15296,11 +15715,14 @@ const server = createServer(async (req, res) => {
|
|
|
15296
15715
|
}
|
|
15297
15716
|
|
|
15298
15717
|
if (url.pathname === "/api/subagents/output" && req.method === "GET") {
|
|
15299
|
-
const tab = getRequestedTab(req, url);
|
|
15300
15718
|
const runId = normalizeWebuiSubagentText(url.searchParams.get("run"), 160);
|
|
15301
15719
|
const agentId = normalizeWebuiSubagentText(url.searchParams.get("agent"), 240);
|
|
15302
15720
|
if (!runId || !agentId) throw makeHttpError(400, "run and agent query parameters are required");
|
|
15303
|
-
|
|
15721
|
+
const groupId = normalizeWebuiSubagentText(url.searchParams.get("group"), 240);
|
|
15722
|
+
const data = groupId
|
|
15723
|
+
? await canonicalWebuiSubagentOutputData(groupId, runId, agentId)
|
|
15724
|
+
: await webuiSubagentOutputData(getRequestedTab(req, url), runId, agentId);
|
|
15725
|
+
sendJson(res, 200, { ok: true, data });
|
|
15304
15726
|
return;
|
|
15305
15727
|
}
|
|
15306
15728
|
|
|
@@ -15321,20 +15743,26 @@ const server = createServer(async (req, res) => {
|
|
|
15321
15743
|
if (url.pathname === "/api/subagents/cancel" && req.method === "POST") {
|
|
15322
15744
|
requireLocalhostRoute(req, url.pathname);
|
|
15323
15745
|
const body = await readJsonBody(req);
|
|
15746
|
+
if (body.group) {
|
|
15747
|
+
sendJson(res, 200, { ok: true, data: await canonicalWebuiSubagentAction("cancel", body) });
|
|
15748
|
+
return;
|
|
15749
|
+
}
|
|
15324
15750
|
const tab = getRequestedTab(req, url, body);
|
|
15325
|
-
|
|
15326
|
-
|
|
15327
|
-
reason: body.reason,
|
|
15328
|
-
note: body.note,
|
|
15329
|
-
}) });
|
|
15751
|
+
const runId = rejectUnsupportedWebuiSubagentRun(tab, body.runId);
|
|
15752
|
+
sendJson(res, 200, { ok: true, data: await sendWebuiHelperCommand(tab, "subagent-cancel", { runId, reason: body.reason, note: body.note }) });
|
|
15330
15753
|
return;
|
|
15331
15754
|
}
|
|
15332
15755
|
|
|
15333
15756
|
if (url.pathname === "/api/subagents/dismiss" && req.method === "POST") {
|
|
15334
15757
|
requireLocalhostRoute(req, url.pathname);
|
|
15335
15758
|
const body = await readJsonBody(req);
|
|
15759
|
+
if (body.group) {
|
|
15760
|
+
sendJson(res, 200, { ok: true, data: await canonicalWebuiSubagentAction("dismiss", body) });
|
|
15761
|
+
return;
|
|
15762
|
+
}
|
|
15336
15763
|
const tab = getRequestedTab(req, url, body);
|
|
15337
|
-
|
|
15764
|
+
const runId = rejectUnsupportedWebuiSubagentRun(tab, body.runId);
|
|
15765
|
+
sendJson(res, 200, { ok: true, data: await sendWebuiHelperCommand(tab, "subagent-dismiss", { runId }) });
|
|
15338
15766
|
return;
|
|
15339
15767
|
}
|
|
15340
15768
|
|