@firstpick/pi-package-webui 0.9.1 → 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 +21 -5
- package/bin/pi-webui-launcher.mjs +23 -12
- package/bin/pi-webui.mjs +479 -60
- 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/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 +1 -1
- package/public/app.js +1261 -314
- 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/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 +127 -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/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/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 +13 -3
- 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,
|
|
@@ -56,7 +58,8 @@ import {
|
|
|
56
58
|
} from "../lib/git-command-errors.mjs";
|
|
57
59
|
import { ComponentUpdateState, sanitizeComponentUpdateError, validateComponentUpdateRequest, validateUpdateApplyRequest, validateUpdatePlanRequest } from "../lib/component-update-state.mjs";
|
|
58
60
|
import { resolveCanonicalPiRuntime, resolveWebuiRuntimeIdentity } from "../lib/update/resolver.mjs";
|
|
59
|
-
import {
|
|
61
|
+
import { bundledPackageOwnership, packageOwnerRoot } from "../lib/update/package-layout.mjs";
|
|
62
|
+
import { createUpdatePlan, assertActionableUpdatePlan, assertPlanIdentity, assertUpdatePlanDigest } from "../lib/update/plan.mjs";
|
|
60
63
|
import { executeCommand, executePlanTargets } from "../lib/update/executor.mjs";
|
|
61
64
|
import { verifyTargetResult } from "../lib/update/verify.mjs";
|
|
62
65
|
import { acquireInstallLock, createUpdateJournal, readUpdateJournal, reconcileInterruptedUpdates, releaseInstallLock, transferInstallLock, transitionUpdateJournal } from "../lib/update/journal.mjs";
|
|
@@ -185,6 +188,10 @@ const WEBUI_HELPER_RESPONSE_PREFIX = "__PI_WEBUI_HELPER_RESPONSE__:";
|
|
|
185
188
|
const SAMPLING_PARAMS_HTTP_MAX_BYTES = 20 * 1024;
|
|
186
189
|
const WEBUI_SUBAGENTS_STATUS_KEY = "webui-subagents";
|
|
187
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;
|
|
188
195
|
const WEBUI_SUBAGENT_RUN_LIMIT = 128;
|
|
189
196
|
const WEBUI_SUBAGENT_AGENT_LIMIT = 256;
|
|
190
197
|
const WEBUI_SUBAGENT_GATE_LIMIT = 32;
|
|
@@ -1842,16 +1849,17 @@ function latestEvents(limit = 40) {
|
|
|
1842
1849
|
return eventHistory.slice(-Math.max(0, Math.min(EVENT_HISTORY_LIMIT, limit)));
|
|
1843
1850
|
}
|
|
1844
1851
|
|
|
1845
|
-
function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20000, env = {} } = {}) {
|
|
1852
|
+
function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20000, env = {}, input, utf8Output = false } = {}) {
|
|
1846
1853
|
return new Promise((resolve) => {
|
|
1847
1854
|
const child = spawn(command, args, {
|
|
1848
1855
|
cwd,
|
|
1849
1856
|
// LC_ALL=C keeps tool output in English so error classification works
|
|
1850
1857
|
// regardless of locale.
|
|
1851
1858
|
env: { ...process.env, ...env, LC_ALL: "C" },
|
|
1852
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
1859
|
+
stdio: [input === undefined ? "ignore" : "pipe", "pipe", "pipe"],
|
|
1853
1860
|
windowsHide: true,
|
|
1854
1861
|
});
|
|
1862
|
+
if (utf8Output) child.stdout.setEncoding("utf8");
|
|
1855
1863
|
let stdout = "";
|
|
1856
1864
|
let stderr = "";
|
|
1857
1865
|
let stdoutTruncated = false;
|
|
@@ -1877,6 +1885,10 @@ function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20
|
|
|
1877
1885
|
stderr += String(chunk);
|
|
1878
1886
|
if (stderr.length > maxOutputLength) stderr = stderr.slice(-maxOutputLength);
|
|
1879
1887
|
});
|
|
1888
|
+
if (child.stdin) {
|
|
1889
|
+
child.stdin.on("error", () => {});
|
|
1890
|
+
child.stdin.end(input);
|
|
1891
|
+
}
|
|
1880
1892
|
child.on("error", (error) => {
|
|
1881
1893
|
const message = formatCommandSpawnError(command, error);
|
|
1882
1894
|
finish({ exitCode: undefined, stdout, stderr: message, error: message, errorCode: error?.code });
|
|
@@ -1889,13 +1901,7 @@ function runCommand(command, args, { cwd, timeoutMs = 2000, maxOutputLength = 20
|
|
|
1889
1901
|
}
|
|
1890
1902
|
|
|
1891
1903
|
function nodeModulesParentForPackageRoot(root = packageRoot) {
|
|
1892
|
-
|
|
1893
|
-
const nodeModulesIndex = parts.lastIndexOf("node_modules");
|
|
1894
|
-
if (nodeModulesIndex >= 0) {
|
|
1895
|
-
const parent = parts.slice(0, nodeModulesIndex).join(path.sep);
|
|
1896
|
-
return parent || path.parse(root).root;
|
|
1897
|
-
}
|
|
1898
|
-
return root;
|
|
1904
|
+
return packageOwnerRoot(root);
|
|
1899
1905
|
}
|
|
1900
1906
|
|
|
1901
1907
|
function packageNodeModulesPath(nodeModulesRoot, packageName) {
|
|
@@ -6073,6 +6079,46 @@ function withFileTreeGitStatus(entries = [], workspaceRoot, gitStatus) {
|
|
|
6073
6079
|
});
|
|
6074
6080
|
}
|
|
6075
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
|
+
|
|
6076
6122
|
function fileTreeGitStatusPayload(workspaceRoot, gitStatus) {
|
|
6077
6123
|
if (!gitStatus?.root || !gitStatus.entries?.size) return null;
|
|
6078
6124
|
const root = path.resolve(workspaceRoot);
|
|
@@ -9126,6 +9172,40 @@ try {
|
|
|
9126
9172
|
|
|
9127
9173
|
process.env.PI_WEBUI_HOST = options.host;
|
|
9128
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
|
+
}
|
|
9129
9209
|
const recoveryEndpointToken = String(process.env.PI_WEBUI_RECOVERY_TOKEN || "").trim() || `${randomUUID()}${randomUUID()}`;
|
|
9130
9210
|
const recoveryEndpointTokens = new Set([recoveryEndpointToken]);
|
|
9131
9211
|
|
|
@@ -9918,7 +9998,9 @@ function filterSessionSummaryTranscriptMessages(messages) {
|
|
|
9918
9998
|
}
|
|
9919
9999
|
|
|
9920
10000
|
function clearWebuiSubagents(tab) {
|
|
9921
|
-
if (tab)
|
|
10001
|
+
if (!tab) return;
|
|
10002
|
+
tab.webuiSubagents = null;
|
|
10003
|
+
tab.webuiAgentRuns = null;
|
|
9922
10004
|
}
|
|
9923
10005
|
|
|
9924
10006
|
function normalizeWebuiSubagentText(value, maxLength = 240) {
|
|
@@ -9927,7 +10009,15 @@ function normalizeWebuiSubagentText(value, maxLength = 240) {
|
|
|
9927
10009
|
}
|
|
9928
10010
|
|
|
9929
10011
|
function normalizeWebuiSubagentSource(value) {
|
|
9930
|
-
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 };
|
|
9931
10021
|
}
|
|
9932
10022
|
|
|
9933
10023
|
function normalizeWebuiSubagentPayload(value) {
|
|
@@ -9958,9 +10048,14 @@ function normalizeWebuiSubagentPayload(value) {
|
|
|
9958
10048
|
});
|
|
9959
10049
|
}
|
|
9960
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;
|
|
9961
10054
|
runs.push({
|
|
9962
10055
|
id,
|
|
9963
|
-
source
|
|
10056
|
+
source,
|
|
10057
|
+
...(provisional ? { provisional: true } : {}),
|
|
10058
|
+
...(!controllable ? { controllable: false } : {}),
|
|
9964
10059
|
mode: ["single", "parallel", "chain"].includes(rawRun.mode) ? rawRun.mode : "single",
|
|
9965
10060
|
status,
|
|
9966
10061
|
startedAt: Number.isFinite(rawRun.startedAt) ? rawRun.startedAt : Date.now(),
|
|
@@ -10019,24 +10114,57 @@ function normalizeWebuiSubagentPayload(value) {
|
|
|
10019
10114
|
available: value.available === true,
|
|
10020
10115
|
updatedAt: Number.isFinite(value.updatedAt) ? value.updatedAt : Date.now(),
|
|
10021
10116
|
receivedAt: Date.now(),
|
|
10117
|
+
fleet: normalizeWebuiSubagentFleet(value.fleet),
|
|
10022
10118
|
runs: runs.sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id)),
|
|
10023
10119
|
gates: gates.sort((a, b) => a.startedAt - b.startedAt || a.id.localeCompare(b.id)),
|
|
10024
10120
|
};
|
|
10025
10121
|
}
|
|
10026
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
|
+
|
|
10027
10153
|
function rememberWebuiSubagentsStatusEvent(tab, event) {
|
|
10028
|
-
if (event?.type !== "extension_ui_request" || event.method !== "setStatus"
|
|
10154
|
+
if (event?.type !== "extension_ui_request" || event.method !== "setStatus") return false;
|
|
10029
10155
|
const statusText = String(event.statusText || "");
|
|
10030
|
-
if (
|
|
10031
|
-
|
|
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; }
|
|
10032
10161
|
return true;
|
|
10033
10162
|
}
|
|
10163
|
+
if (event.statusKey !== WEBUI_SUBAGENTS_STATUS_KEY) return false;
|
|
10164
|
+
if (!statusText) { tab.webuiSubagents = null; return true; }
|
|
10034
10165
|
if (!statusText.startsWith(WEBUI_SUBAGENTS_PAYLOAD_PREFIX)) return true;
|
|
10035
|
-
try {
|
|
10036
|
-
|
|
10037
|
-
} catch {
|
|
10038
|
-
tab.webuiSubagents = null;
|
|
10039
|
-
}
|
|
10166
|
+
try { tab.webuiSubagents = normalizeWebuiSubagentPayload(JSON.parse(statusText.slice(WEBUI_SUBAGENTS_PAYLOAD_PREFIX.length))); }
|
|
10167
|
+
catch { tab.webuiSubagents = null; }
|
|
10040
10168
|
return true;
|
|
10041
10169
|
}
|
|
10042
10170
|
|
|
@@ -10836,6 +10964,7 @@ function createTabRecord({ id, index, title, titleSource, conversationStarted, c
|
|
|
10836
10964
|
extensionWidgets: new Map(),
|
|
10837
10965
|
sessionSummary: null,
|
|
10838
10966
|
webuiSubagents: null,
|
|
10967
|
+
webuiAgentRuns: null,
|
|
10839
10968
|
subagentDisplayTitle: undefined,
|
|
10840
10969
|
subagentDisplayTitlePromise: undefined,
|
|
10841
10970
|
webuiHelperRequests: new Map(),
|
|
@@ -11021,43 +11150,191 @@ async function resolveSubagentDisplayTitle(tab) {
|
|
|
11021
11150
|
return tab.subagentDisplayTitlePromise;
|
|
11022
11151
|
}
|
|
11023
11152
|
|
|
11024
|
-
|
|
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 } = {}) {
|
|
11025
11240
|
const sortedTabs = [...tabs.values()].sort((a, b) => a.index - b.index || a.title.localeCompare(b.title));
|
|
11026
11241
|
const tabSummaries = await Promise.all(sortedTabs.map(async (tab) => {
|
|
11027
11242
|
const status = tab.webuiSubagents || { version: 1, available: false, updatedAt: null, receivedAt: null, runs: [], gates: [] };
|
|
11028
11243
|
const runs = Array.isArray(status.runs) ? status.runs : [];
|
|
11029
11244
|
const gates = Array.isArray(status.gates) ? status.gates : [];
|
|
11030
|
-
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;
|
|
11031
11246
|
return {
|
|
11032
|
-
tabId: tab.id,
|
|
11033
|
-
tabIndex: tab.index,
|
|
11034
|
-
tabTitle,
|
|
11035
|
-
cwd: tab.cwd,
|
|
11247
|
+
tabId: tab.id, tabIndex: tab.index, tabTitle, cwd: tab.cwd,
|
|
11036
11248
|
sessionName: normalizeWebuiSubagentText(tab.lastState?.sessionName || tab.title, 160),
|
|
11037
11249
|
sessionFile: tabRestorableSessionFile(tab) || null,
|
|
11038
|
-
running: tab.rpc.isRunning(),
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
runs,
|
|
11043
|
-
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,
|
|
11044
11254
|
agentCount: runs.reduce((count, run) => count + run.agents.length, 0),
|
|
11045
11255
|
runningRuns: runs.filter((run) => run.status === "running").length,
|
|
11046
11256
|
runningAgents: runs.reduce((count, run) => count + run.agents.filter((agent) => agent.status === "running").length, 0),
|
|
11047
11257
|
gateCount: gates.length,
|
|
11048
11258
|
};
|
|
11049
11259
|
}));
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
|
|
11059
|
-
|
|
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,
|
|
11060
11336
|
};
|
|
11337
|
+
return includeSelections ? { overview, selections, registrySnapshot } : overview;
|
|
11061
11338
|
}
|
|
11062
11339
|
|
|
11063
11340
|
function normalizeWebuiSubagentTranscriptValue(value, maxLength = WEBUI_SUBAGENT_OUTPUT_LINE_LENGTH) {
|
|
@@ -11202,16 +11479,146 @@ function normalizeWebuiSubagentOutput(value, selection) {
|
|
|
11202
11479
|
};
|
|
11203
11480
|
}
|
|
11204
11481
|
|
|
11205
|
-
|
|
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);
|
|
11206
11497
|
const runs = Array.isArray(tab.webuiSubagents?.runs) ? tab.webuiSubagents.runs : [];
|
|
11207
|
-
const run = runs.find((candidate) => candidate.id ===
|
|
11208
|
-
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);
|
|
11209
11505
|
const agent = (Array.isArray(run.agents) ? run.agents : []).find((candidate) => candidate.id === agentId);
|
|
11210
11506
|
if (!agent) throw makeHttpError(404, `Subagent not found: ${agentId}`);
|
|
11211
11507
|
const data = await sendWebuiHelperCommand(tab, "subagent-output", { runId, agentId });
|
|
11212
11508
|
return normalizeWebuiSubagentOutput(data, { run, agent });
|
|
11213
11509
|
}
|
|
11214
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
|
+
|
|
11215
11622
|
function restorableTabDescriptor(tab, state = null) {
|
|
11216
11623
|
return normalizeRestoreTabDescriptor({
|
|
11217
11624
|
id: tab.id,
|
|
@@ -11442,10 +11849,9 @@ function updateOwnerForTarget(target, identities) {
|
|
|
11442
11849
|
}
|
|
11443
11850
|
const active = identities.pi.active;
|
|
11444
11851
|
const piRoot = active?.packageRoot || "";
|
|
11445
|
-
const
|
|
11446
|
-
const bundled = piRoot && exactUpdatePathInside(path.join(packageRoot, "node_modules"), piRoot);
|
|
11852
|
+
const bundled = bundledPackageOwnership({ hostPackageRoot: packageRoot, packageRoot: piRoot, source: active?.source });
|
|
11447
11853
|
if (bundled && webuiDevServer) return { manager: "unknown", packageRoot: piRoot, ownerRoot: packageRoot, sourceCheckout: true };
|
|
11448
|
-
if (bundled) return { manager: "npm", packageRoot: piRoot, ownerRoot:
|
|
11854
|
+
if (bundled) return { manager: "npm", packageRoot: piRoot, ownerRoot: bundled.ownerRoot, topLevel: true };
|
|
11449
11855
|
if ((active?.source === "explicit" || active?.source === "path") && piRoot) {
|
|
11450
11856
|
return { manager: "pi", packageRoot: piRoot, ownerRoot: piRoot, topLevel: true };
|
|
11451
11857
|
}
|
|
@@ -11462,7 +11868,7 @@ async function createServerOwnedUpdatePlan(targets) {
|
|
|
11462
11868
|
if (!status[target]?.checked || !status[target]?.latestVersion) throw makeHttpError(409, `${target} exact target metadata is unavailable.`);
|
|
11463
11869
|
}
|
|
11464
11870
|
const piRoot = identities.pi.active?.packageRoot || "";
|
|
11465
|
-
const bundledPi = Boolean(
|
|
11871
|
+
const bundledPi = Boolean(bundledPackageOwnership({ hostPackageRoot: packageRoot, packageRoot: piRoot, source: identities.pi.active?.source }));
|
|
11466
11872
|
const requested = new Set(targets);
|
|
11467
11873
|
const desiredPiVersion = requested.has("pi") ? status.pi.latestVersion : identities.pi.active?.version;
|
|
11468
11874
|
const desiredWebuiVersion = requested.has("webui") ? status.webui.latestVersion : identities.webui.version;
|
|
@@ -11564,6 +11970,7 @@ async function createServerOwnedUpdatePlan(targets) {
|
|
|
11564
11970
|
return { version: targetVersion, registry, metadata };
|
|
11565
11971
|
},
|
|
11566
11972
|
});
|
|
11973
|
+
assertActionableUpdatePlan(plan);
|
|
11567
11974
|
await createUpdateJournal(agentDir, plan);
|
|
11568
11975
|
return plan;
|
|
11569
11976
|
}
|
|
@@ -11621,6 +12028,7 @@ async function applyServerOwnedUpdate(transactionId, planDigest) {
|
|
|
11621
12028
|
const journal = await readUpdateJournal(agentDir, transactionId);
|
|
11622
12029
|
if (!journal) throw makeHttpError(404, "Update transaction was not found.");
|
|
11623
12030
|
assertUpdatePlanDigest(journal.plan, planDigest);
|
|
12031
|
+
assertActionableUpdatePlan(journal.plan);
|
|
11624
12032
|
if (journal.state !== "planned") throw makeHttpError(409, `Update transaction is already ${journal.state}.`);
|
|
11625
12033
|
piUpdateInProgress = true;
|
|
11626
12034
|
let lock = null;
|
|
@@ -13276,12 +13684,13 @@ async function getFileTreeData(tab, requestedPath = "") {
|
|
|
13276
13684
|
statFileTreeEntries(resolved.targetPath, dirents, resolved.root, resolved.realRoot),
|
|
13277
13685
|
readWorkspaceGitStatusIndex(resolved.root),
|
|
13278
13686
|
]);
|
|
13687
|
+
const gitIgnored = await readWorkspaceGitIgnoredPaths(resolved.root, listed.entries, gitStatus?.root);
|
|
13279
13688
|
return {
|
|
13280
13689
|
root: resolved.root,
|
|
13281
13690
|
displayRoot: displayPath(resolved.root),
|
|
13282
13691
|
path: resolved.relative,
|
|
13283
13692
|
displayPath: displayPath(resolved.targetPath),
|
|
13284
|
-
entries: withFileTreeGitStatus(listed.entries, resolved.root, gitStatus),
|
|
13693
|
+
entries: withFileTreeGitIgnored(withFileTreeGitStatus(listed.entries, resolved.root, gitStatus), resolved.root, gitIgnored),
|
|
13285
13694
|
gitStatus: fileTreeGitStatusPayload(resolved.root, gitStatus),
|
|
13286
13695
|
truncated: listed.truncated,
|
|
13287
13696
|
total: listed.total,
|
|
@@ -13367,11 +13776,12 @@ async function getFileSearchData(tab, rawQuery = "") {
|
|
|
13367
13776
|
}
|
|
13368
13777
|
}
|
|
13369
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);
|
|
13370
13780
|
return {
|
|
13371
13781
|
root: resolved.root,
|
|
13372
13782
|
displayRoot: displayPath(resolved.root),
|
|
13373
13783
|
query,
|
|
13374
|
-
entries: withFileTreeGitStatus(entries, resolved.root, gitStatus),
|
|
13784
|
+
entries: withFileTreeGitIgnored(withFileTreeGitStatus(entries, resolved.root, gitStatus), resolved.root, gitIgnored),
|
|
13375
13785
|
gitStatus: fileTreeGitStatusPayload(resolved.root, gitStatus),
|
|
13376
13786
|
truncated,
|
|
13377
13787
|
total: entries.length,
|
|
@@ -15305,11 +15715,14 @@ const server = createServer(async (req, res) => {
|
|
|
15305
15715
|
}
|
|
15306
15716
|
|
|
15307
15717
|
if (url.pathname === "/api/subagents/output" && req.method === "GET") {
|
|
15308
|
-
const tab = getRequestedTab(req, url);
|
|
15309
15718
|
const runId = normalizeWebuiSubagentText(url.searchParams.get("run"), 160);
|
|
15310
15719
|
const agentId = normalizeWebuiSubagentText(url.searchParams.get("agent"), 240);
|
|
15311
15720
|
if (!runId || !agentId) throw makeHttpError(400, "run and agent query parameters are required");
|
|
15312
|
-
|
|
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 });
|
|
15313
15726
|
return;
|
|
15314
15727
|
}
|
|
15315
15728
|
|
|
@@ -15330,20 +15743,26 @@ const server = createServer(async (req, res) => {
|
|
|
15330
15743
|
if (url.pathname === "/api/subagents/cancel" && req.method === "POST") {
|
|
15331
15744
|
requireLocalhostRoute(req, url.pathname);
|
|
15332
15745
|
const body = await readJsonBody(req);
|
|
15746
|
+
if (body.group) {
|
|
15747
|
+
sendJson(res, 200, { ok: true, data: await canonicalWebuiSubagentAction("cancel", body) });
|
|
15748
|
+
return;
|
|
15749
|
+
}
|
|
15333
15750
|
const tab = getRequestedTab(req, url, body);
|
|
15334
|
-
|
|
15335
|
-
|
|
15336
|
-
reason: body.reason,
|
|
15337
|
-
note: body.note,
|
|
15338
|
-
}) });
|
|
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 }) });
|
|
15339
15753
|
return;
|
|
15340
15754
|
}
|
|
15341
15755
|
|
|
15342
15756
|
if (url.pathname === "/api/subagents/dismiss" && req.method === "POST") {
|
|
15343
15757
|
requireLocalhostRoute(req, url.pathname);
|
|
15344
15758
|
const body = await readJsonBody(req);
|
|
15759
|
+
if (body.group) {
|
|
15760
|
+
sendJson(res, 200, { ok: true, data: await canonicalWebuiSubagentAction("dismiss", body) });
|
|
15761
|
+
return;
|
|
15762
|
+
}
|
|
15345
15763
|
const tab = getRequestedTab(req, url, body);
|
|
15346
|
-
|
|
15764
|
+
const runId = rejectUnsupportedWebuiSubagentRun(tab, body.runId);
|
|
15765
|
+
sendJson(res, 200, { ok: true, data: await sendWebuiHelperCommand(tab, "subagent-dismiss", { runId }) });
|
|
15347
15766
|
return;
|
|
15348
15767
|
}
|
|
15349
15768
|
|