@firstpick/pi-package-webui 0.9.2 → 0.9.4
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 +14 -8
- package/bin/pi-webui.mjs +256 -39
- package/index.ts +266 -1
- package/lib/git-workflow-preferences.mjs +8 -25
- package/lib/intercom-conversations.mjs +491 -0
- package/lib/intercom-transcript-filter.mjs +99 -0
- package/lib/resource-selection.mjs +140 -0
- package/package.json +2 -2
- package/public/app.js +1061 -119
- package/public/index.html +31 -6
- package/public/service-worker.js +2 -1
- package/public/stream-output-controller.mjs +15 -0
- package/public/styles.css +426 -1
- package/public/syntax-highlight.mjs +622 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/interaction-continuity.spec.mjs +34 -0
- package/tests/browser/intercom-conversation-viewer.spec.mjs +357 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +61 -0
- package/tests/browser/resource-profiles.spec.mjs +200 -0
- package/tests/browser/subagent-observability.spec.mjs +29 -0
- package/tests/codex-fast-mode-static.test.mjs +7 -6
- package/tests/common-options-submenus-interaction-static.test.mjs +2 -0
- package/tests/common-options-submenus-markup-static.test.mjs +1 -0
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/composer-skill-tag-layout.test.mjs +32 -2
- package/tests/control-deck-component-updates-static.test.mjs +4 -0
- package/tests/controls-layout-static.test.mjs +3 -3
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +5 -5
- package/tests/file-viewer-image-static.test.mjs +69 -0
- package/tests/fixtures/fake-pi.mjs +105 -6
- package/tests/foreground-transcript-catch-up-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +5 -5
- package/tests/git-panel-live-updates-static.test.mjs +3 -3
- package/tests/git-workflow-preferences.test.mjs +4 -4
- package/tests/http-endpoints-harness.test.mjs +124 -2
- package/tests/intercom-conversation-viewer-static.test.mjs +106 -0
- package/tests/intercom-conversations-http.test.mjs +252 -0
- package/tests/intercom-conversations.test.mjs +374 -0
- package/tests/intercom-main-transcript-suppression-static.test.mjs +52 -0
- package/tests/intercom-tag-layout-static.test.mjs +46 -0
- package/tests/intercom-transcript-filter.test.mjs +98 -0
- package/tests/main-output-loading-static.test.mjs +59 -0
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +6 -6
- 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 +66 -42
- package/tests/native-parity.test.mjs +8 -7
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +5 -5
- package/tests/optional-feature-resource-setup-static.test.mjs +29 -0
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/resource-defaults-helper.test.mjs +60 -6
- package/tests/resource-selection.test.mjs +114 -0
- package/tests/resource-tui-extension.test.mjs +23 -0
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-output-controller.test.mjs +8 -0
- package/tests/stream-output-isolation-static.test.mjs +2 -2
- package/tests/streaming-ui-coupling.test.mjs +5 -0
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +5 -3
- package/tests/subagent-reliability-integration.test.mjs +23 -1
- package/tests/subagent-workflow-section-static.test.mjs +67 -0
- package/tests/subagents-helper.test.mjs +313 -1
- package/tests/syntax-highlight.test.mjs +235 -0
- package/tests/syntax-highlighting-static.test.mjs +84 -0
- package/tests/terminal-cwd-grouping-static.test.mjs +22 -0
- package/tests/theme-customizer-static.test.mjs +5 -5
- package/tests/thinking-format-parser.test.mjs +64 -0
- package/tests/webui-settings-locking.test.mjs +1 -1
- package/webui-rpc-helper.mjs +417 -74
package/webui-rpc-helper.mjs
CHANGED
|
@@ -9,6 +9,10 @@ import {
|
|
|
9
9
|
normalizeProviderSnapshot,
|
|
10
10
|
} from "./lib/agent-run-protocol.mjs";
|
|
11
11
|
import { readWebuiSettings } from "./lib/git-workflow-preferences.mjs";
|
|
12
|
+
import {
|
|
13
|
+
branchResourceDirective,
|
|
14
|
+
resolveResourceSelection,
|
|
15
|
+
} from "./lib/resource-selection.mjs";
|
|
12
16
|
import { mutatePiRuntimeFollowUpQueue } from "./lib/queue-mutation.mjs";
|
|
13
17
|
import {
|
|
14
18
|
formatSubagentLaunchSlotGuidance,
|
|
@@ -51,6 +55,9 @@ const SUBAGENT_RPC_VERSION = 1;
|
|
|
51
55
|
const SUBAGENT_RPC_REQUEST_EVENT = "subagents:rpc:v1:request";
|
|
52
56
|
const SUBAGENT_RPC_READY_EVENT = "subagents:rpc:v1:ready";
|
|
53
57
|
const SUBAGENT_RPC_REPLY_PREFIX = "subagents:rpc:v1:reply:";
|
|
58
|
+
const SUBAGENT_ASYNC_STATUS_SNAPSHOT_KIND = "pi-subagents.async-status-snapshot";
|
|
59
|
+
const SUBAGENT_ASYNC_STATUS_SNAPSHOT_VERSION = 1;
|
|
60
|
+
const SUBAGENT_ASYNC_STATUS_SNAPSHOT_RUN_LIMIT = 32;
|
|
54
61
|
const SUBAGENT_ASYNC_STARTED_EVENT = "subagent:async-started";
|
|
55
62
|
const SUBAGENT_ASYNC_COMPLETE_EVENT = "subagent:async-complete";
|
|
56
63
|
const WORKFLOW_SUBAGENTS_EVENT = "firstpick:workflow-subagents:v1";
|
|
@@ -837,12 +844,13 @@ function parseSubagentStatusText(text, previousRuns = new Map()) {
|
|
|
837
844
|
if (runMatch) {
|
|
838
845
|
const id = subagentText(runMatch[1], 160);
|
|
839
846
|
const segments = rawLine.split(" | ").map((part) => part.trim());
|
|
840
|
-
const mode = segments.map((part) => part.match(/^(single|parallel|chain)\b/)?.[1]).find(Boolean);
|
|
847
|
+
const mode = segments.map((part) => part.match(/^(single|parallel|chain|workflow)\b/)?.[1]).find(Boolean);
|
|
841
848
|
const previous = previousRuns.get(id);
|
|
842
849
|
current = {
|
|
843
850
|
id,
|
|
844
851
|
source: "async",
|
|
845
852
|
mode: subagentMode(mode, previous?.mode),
|
|
853
|
+
workflow: mode === "workflow" || previous?.workflow === true,
|
|
846
854
|
status: runMatch[2].toLowerCase(),
|
|
847
855
|
startedAt: previous?.startedAt || Date.now(),
|
|
848
856
|
agents: [],
|
|
@@ -885,13 +893,53 @@ function parseSubagentStatusText(text, previousRuns = new Map()) {
|
|
|
885
893
|
nested: /^\s{4,}\d+\./.test(rawLine),
|
|
886
894
|
});
|
|
887
895
|
}
|
|
888
|
-
|
|
896
|
+
// Keep active headers even before their first child step is persisted. Dynamic
|
|
897
|
+
// workflow runs can report a running header for several polls while their
|
|
898
|
+
// worker locator is still being written. Dropping that header makes absence
|
|
899
|
+
// reconciliation falsely finish the run, after which later worker details are
|
|
900
|
+
// deliberately ignored as stale and the UI is left with a fleet placeholder.
|
|
901
|
+
return runs.filter((run) => run.status === "running");
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function parseAsyncSubagentSnapshot(value, previousRuns = new Map()) {
|
|
905
|
+
if (!value || typeof value !== "object"
|
|
906
|
+
|| value.kind !== SUBAGENT_ASYNC_STATUS_SNAPSHOT_KIND
|
|
907
|
+
|| value.version !== SUBAGENT_ASYNC_STATUS_SNAPSHOT_VERSION
|
|
908
|
+
|| !Array.isArray(value.runs)) return [];
|
|
909
|
+
const runs = [];
|
|
910
|
+
const seen = new Set();
|
|
911
|
+
for (const candidate of value.runs.slice(0, SUBAGENT_ASYNC_STATUS_SNAPSHOT_RUN_LIMIT)) {
|
|
912
|
+
const id = subagentText(candidate?.id, 160);
|
|
913
|
+
if (!id || seen.has(id) || candidate?.state !== "running") continue;
|
|
914
|
+
seen.add(id);
|
|
915
|
+
const previous = previousRuns.get(id);
|
|
916
|
+
const workflow = candidate?.kind === "workflow" || previous?.workflow === true;
|
|
917
|
+
runs.push({
|
|
918
|
+
id,
|
|
919
|
+
source: "async",
|
|
920
|
+
mode: subagentMode(undefined, previous?.mode),
|
|
921
|
+
workflow,
|
|
922
|
+
status: "running",
|
|
923
|
+
startedAt: Number.isSafeInteger(candidate?.startedAt) && candidate.startedAt >= 0
|
|
924
|
+
? candidate.startedAt
|
|
925
|
+
: Number.isFinite(previous?.startedAt) ? previous.startedAt : Date.now(),
|
|
926
|
+
agents: [],
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
return runs;
|
|
889
930
|
}
|
|
890
931
|
|
|
891
932
|
export default function webuiRpcHelper(pi) {
|
|
933
|
+
let runtimeToolBaseline;
|
|
892
934
|
let enabledTools = new Set();
|
|
893
935
|
let disabledSkills = new Set();
|
|
894
936
|
let inheritedEnabledSkills = null;
|
|
937
|
+
let toolsPinned = false;
|
|
938
|
+
let skillsPinned = false;
|
|
939
|
+
let toolSelectionSource = "runtime";
|
|
940
|
+
let skillSelectionSource = "runtime";
|
|
941
|
+
let resourceGeneration = 0;
|
|
942
|
+
let resourceRpcActive = false;
|
|
895
943
|
let sessionSamplingParams = {};
|
|
896
944
|
let subagentLaunchSlotGuidance = "";
|
|
897
945
|
let subagentContext = null;
|
|
@@ -910,6 +958,8 @@ export default function webuiRpcHelper(pi) {
|
|
|
910
958
|
const agentRunProviderSnapshots = new Map();
|
|
911
959
|
const agentRunProviderDiagnostics = [];
|
|
912
960
|
const helperAgentRunOutputSelections = new Map();
|
|
961
|
+
// Canonical projection key -> dismissed lifecycle end. Keeps duplicate providers from recreating cleared rows.
|
|
962
|
+
const dismissedHelperAgentRunProjections = new Map();
|
|
913
963
|
const subagentStatusRequestsInFlight = new Set();
|
|
914
964
|
const asyncSubagentRuns = new Map();
|
|
915
965
|
const foregroundSubagentRuns = new Map();
|
|
@@ -924,6 +974,34 @@ export default function webuiRpcHelper(pi) {
|
|
|
924
974
|
];
|
|
925
975
|
}
|
|
926
976
|
|
|
977
|
+
function helperAgentRunProjectionKey(instance) {
|
|
978
|
+
return `${instance?.parentSessionId || "external"}\0${instance?.instanceId || ""}`;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function rememberDismissedHelperAgentRunProjections(instances) {
|
|
982
|
+
for (const instance of instances) {
|
|
983
|
+
const key = helperAgentRunProjectionKey(instance);
|
|
984
|
+
if (!instance?.instanceId || dismissedHelperAgentRunProjections.has(key)) continue;
|
|
985
|
+
dismissedHelperAgentRunProjections.set(key, Number.isFinite(instance.endedAt) ? instance.endedAt : Number.isFinite(instance.startedAt) ? instance.startedAt : 0);
|
|
986
|
+
}
|
|
987
|
+
while (dismissedHelperAgentRunProjections.size > AGENT_RUN_INSTANCE_LIMIT) {
|
|
988
|
+
const oldest = dismissedHelperAgentRunProjections.keys().next().value;
|
|
989
|
+
if (oldest === undefined) break;
|
|
990
|
+
dismissedHelperAgentRunProjections.delete(oldest);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function helperAgentRunProjectionIsDismissed(instance) {
|
|
995
|
+
const key = helperAgentRunProjectionKey(instance);
|
|
996
|
+
if (!dismissedHelperAgentRunProjections.has(key)) return false;
|
|
997
|
+
const dismissedLifecycleEnd = dismissedHelperAgentRunProjections.get(key);
|
|
998
|
+
if (instance?.status === "running" && Number.isFinite(instance.startedAt) && instance.startedAt > dismissedLifecycleEnd) {
|
|
999
|
+
dismissedHelperAgentRunProjections.delete(key);
|
|
1000
|
+
return false;
|
|
1001
|
+
}
|
|
1002
|
+
return true;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
927
1005
|
function trimFinishedSubagentRuns() {
|
|
928
1006
|
const finished = ordinarySubagentRunEntries()
|
|
929
1007
|
.filter(({ run }) => run?.status && run.status !== "running")
|
|
@@ -1212,7 +1290,6 @@ export default function webuiRpcHelper(pi) {
|
|
|
1212
1290
|
const launcher = gateRunIds.has(run.id) ? "gate" : workflow ? "workflow" : "pi-subagents";
|
|
1213
1291
|
return (Array.isArray(run.agents) ? run.agents : []).map((agent) => {
|
|
1214
1292
|
const status = canonicalAgentRunStatus(run.status, agent.status);
|
|
1215
|
-
const openable = !recovered;
|
|
1216
1293
|
return {
|
|
1217
1294
|
version: 1,
|
|
1218
1295
|
instanceId: canonicalAgentRunId(agent.id, `${canonicalRunId}-agent`),
|
|
@@ -1231,16 +1308,14 @@ export default function webuiRpcHelper(pi) {
|
|
|
1231
1308
|
activityState: agent.activityState && CANONICAL_AGENT_RUN_ID_PATTERN.test(agent.activityState) ? agent.activityState : undefined,
|
|
1232
1309
|
currentTool: agent.currentTool,
|
|
1233
1310
|
capabilities: {
|
|
1234
|
-
open:
|
|
1235
|
-
refresh:
|
|
1236
|
-
//
|
|
1311
|
+
open: true,
|
|
1312
|
+
refresh: true,
|
|
1313
|
+
// Aggregate fleet recovery grants a read-only metadata view, never lifecycle control.
|
|
1237
1314
|
cancel: status === "running" && !workflow && !recovered && run.controllable !== false,
|
|
1238
1315
|
steer: false,
|
|
1239
1316
|
},
|
|
1240
|
-
outputRef:
|
|
1241
|
-
|
|
1242
|
-
: { kind: "none" },
|
|
1243
|
-
_selection: openable ? { runId: run.id, agentId: agent.id } : null,
|
|
1317
|
+
outputRef: { kind: "helper", id: helperAgentRunOutputId(run.id, agent.id) },
|
|
1318
|
+
_selection: { runId: run.id, agentId: agent.id },
|
|
1244
1319
|
};
|
|
1245
1320
|
});
|
|
1246
1321
|
}
|
|
@@ -1262,6 +1337,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1262
1337
|
for (const run of runs) {
|
|
1263
1338
|
for (const candidate of canonicalInstancesFromPublicRun(run, gateRunIds)) {
|
|
1264
1339
|
const { _selection: selection, ...instance } = candidate;
|
|
1340
|
+
if (instance.status === "running") dismissedHelperAgentRunProjections.delete(helperAgentRunProjectionKey(instance));
|
|
1265
1341
|
try {
|
|
1266
1342
|
// The helper owns lifecycle and capabilities for the rows it observes directly.
|
|
1267
1343
|
index.upsert(instance, { producerId: instance.provider, lifecycleOwner: true, capabilityOwner: true });
|
|
@@ -1278,6 +1354,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1278
1354
|
|
|
1279
1355
|
for (const [producerId, rows] of agentRunProviderSnapshots) {
|
|
1280
1356
|
for (const instance of rows.values()) {
|
|
1357
|
+
if (helperAgentRunProjectionIsDismissed(instance)) continue;
|
|
1281
1358
|
try {
|
|
1282
1359
|
// Foreign producers may enrich an existing instance but never seize ownership.
|
|
1283
1360
|
index.upsert(instance, { producerId, lifecycleOwner: false, capabilityOwner: false });
|
|
@@ -1390,10 +1467,18 @@ export default function webuiRpcHelper(pi) {
|
|
|
1390
1467
|
}
|
|
1391
1468
|
|
|
1392
1469
|
function findTrackedSubagent(runId, agentId) {
|
|
1393
|
-
const
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1470
|
+
const entry = ordinarySubagentRunEntries().find((candidate) => candidate.run?.id === runId);
|
|
1471
|
+
if (entry) {
|
|
1472
|
+
const agent = (Array.isArray(entry.run.agents) ? entry.run.agents : []).find((candidate) => candidate?.id === agentId);
|
|
1473
|
+
if (!agent) throw new Error(`Subagent not found: ${agentId}`);
|
|
1474
|
+
return { run: entry.run, agent };
|
|
1475
|
+
}
|
|
1476
|
+
const recovered = [...recoveredSubagentRuns.values()].find((candidate) => candidate?.id === runId);
|
|
1477
|
+
if (recovered?.agent?.id !== agentId) throw new Error(`Subagent run not found: ${runId}`);
|
|
1478
|
+
return {
|
|
1479
|
+
run: { id: recovered.id, source: "recovered", mode: "single", status: "running", startedAt: recovered.startedAt, provisional: true, controllable: false },
|
|
1480
|
+
agent: { ...recovered.agent, status: "running", index: 0, nested: false },
|
|
1481
|
+
};
|
|
1397
1482
|
}
|
|
1398
1483
|
|
|
1399
1484
|
function findWorkflowSubagent(runId, agentId) {
|
|
@@ -1404,6 +1489,24 @@ export default function webuiRpcHelper(pi) {
|
|
|
1404
1489
|
return { run, agent };
|
|
1405
1490
|
}
|
|
1406
1491
|
|
|
1492
|
+
function claimRecoveredSubagentMatches(agents) {
|
|
1493
|
+
const available = [...recoveredSubagentRuns.entries()]
|
|
1494
|
+
.sort((left, right) => Number(left[1]?.startedAt || 0) - Number(right[1]?.startedAt || 0));
|
|
1495
|
+
return agents.map((agent) => {
|
|
1496
|
+
const name = subagentAgentName(agent?.name);
|
|
1497
|
+
const matchesName = (run) => run?.agent?.identity === name || run?.agent?.name === name;
|
|
1498
|
+
const exactModelIndex = available.findIndex(([, run]) => matchesName(run)
|
|
1499
|
+
&& agent?.model && run.agent.model && agent.model === run.agent.model);
|
|
1500
|
+
const matchIndex = exactModelIndex >= 0
|
|
1501
|
+
? exactModelIndex
|
|
1502
|
+
: available.findIndex(([, run]) => matchesName(run));
|
|
1503
|
+
if (matchIndex < 0) return undefined;
|
|
1504
|
+
const [[key, run]] = available.splice(matchIndex, 1);
|
|
1505
|
+
recoveredSubagentRuns.delete(key);
|
|
1506
|
+
return run;
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1407
1510
|
function workflowSubagentOutputSnapshot(run, agent) {
|
|
1408
1511
|
return {
|
|
1409
1512
|
version: 1,
|
|
@@ -1477,13 +1580,132 @@ export default function webuiRpcHelper(pi) {
|
|
|
1477
1580
|
if (sessionFile && path.isAbsolute(sessionFile) && path.extname(sessionFile) === ".jsonl") agent.sessionFile = path.normalize(sessionFile);
|
|
1478
1581
|
}
|
|
1479
1582
|
|
|
1583
|
+
function subagentRunningAgentsFromStatus(run, status) {
|
|
1584
|
+
return (Array.isArray(status?.steps) ? status.steps : [])
|
|
1585
|
+
.slice(0, 128)
|
|
1586
|
+
.map((step, offset) => {
|
|
1587
|
+
if (step?.status !== "running") return undefined;
|
|
1588
|
+
const name = subagentAgentName(step.agent);
|
|
1589
|
+
if (!name) return undefined;
|
|
1590
|
+
const index = Number.isInteger(step.index) && step.index >= 0 ? step.index : offset;
|
|
1591
|
+
const sessionFile = subagentText(step.sessionFile, 4096);
|
|
1592
|
+
return {
|
|
1593
|
+
id: `${run.id}:step:${index}:${name}`,
|
|
1594
|
+
name,
|
|
1595
|
+
status: "running",
|
|
1596
|
+
index,
|
|
1597
|
+
currentTool: subagentText(step.currentTool, 120) || undefined,
|
|
1598
|
+
activityState: subagentText(step.activityState, 80) || undefined,
|
|
1599
|
+
currentPath: subagentText(step.currentPath, 1000) || undefined,
|
|
1600
|
+
turnCount: Number.isFinite(step.turnCount) ? step.turnCount : undefined,
|
|
1601
|
+
toolCount: Number.isFinite(step.toolCount) ? step.toolCount : undefined,
|
|
1602
|
+
tokens: Number.isFinite(step.tokens?.total) ? step.tokens.total : Number.isFinite(step.tokens) ? step.tokens : undefined,
|
|
1603
|
+
model: subagentModel(step.model) || undefined,
|
|
1604
|
+
thinking: subagentThinking(step.thinking) || subagentThinkingFromModel(step.model) || undefined,
|
|
1605
|
+
recentTools: subagentRecentTools(step.recentTools),
|
|
1606
|
+
recentOutput: subagentOutputLines(step.recentOutput),
|
|
1607
|
+
sessionFile: sessionFile && path.isAbsolute(sessionFile) && path.extname(sessionFile) === ".jsonl" ? path.normalize(sessionFile) : undefined,
|
|
1608
|
+
nested: false,
|
|
1609
|
+
};
|
|
1610
|
+
})
|
|
1611
|
+
.filter(Boolean);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1480
1614
|
async function enrichAsyncSubagentRun(run) {
|
|
1481
1615
|
const statusByDir = new Map();
|
|
1616
|
+
const agents = Array.isArray(run?.agents) ? run.agents : [];
|
|
1617
|
+
if (!agents.some((agent) => agent?.status === "running")) {
|
|
1618
|
+
const targetRunId = subagentText(run?.id, 160);
|
|
1619
|
+
let asyncDir = subagentText(run?.asyncDir, 4096);
|
|
1620
|
+
if (!asyncDir && targetRunId) {
|
|
1621
|
+
try {
|
|
1622
|
+
const data = await requestSubagentStatus({ id: targetRunId });
|
|
1623
|
+
asyncDir = subagentAsyncDirFromStatusText(data?.text);
|
|
1624
|
+
} catch {
|
|
1625
|
+
// The aggregate snapshot still keeps the run alive until a locator resolves.
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
if (asyncDir) {
|
|
1629
|
+
run.asyncDir = asyncDir;
|
|
1630
|
+
let status = null;
|
|
1631
|
+
try {
|
|
1632
|
+
status = JSON.parse(readFileSync(path.join(asyncDir, "status.json"), "utf8"));
|
|
1633
|
+
} catch {
|
|
1634
|
+
// A status write can be briefly between atomic replacements.
|
|
1635
|
+
}
|
|
1636
|
+
if (status && (!status.runId || status.runId === targetRunId)) {
|
|
1637
|
+
statusByDir.set(asyncDir, status);
|
|
1638
|
+
run.workflow = status.mode === "workflow" || run.workflow === true;
|
|
1639
|
+
run.mode = subagentMode(status.mode, run.mode);
|
|
1640
|
+
if (!Number.isFinite(run.startedAt) && Number.isFinite(status.startedAt)) run.startedAt = status.startedAt;
|
|
1641
|
+
const discovered = subagentRunningAgentsFromStatus(run, status);
|
|
1642
|
+
if (discovered.length) {
|
|
1643
|
+
run.agents = [
|
|
1644
|
+
...agents.filter((agent) => !discovered.some((candidate) => candidate.index === agent.index && candidate.name === agent.name)),
|
|
1645
|
+
...discovered.map((agent) => ({
|
|
1646
|
+
...agents.find((candidate) => candidate.index === agent.index && candidate.name === agent.name),
|
|
1647
|
+
...agent,
|
|
1648
|
+
})),
|
|
1649
|
+
];
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1482
1654
|
for (const agent of Array.isArray(run?.agents) ? run.agents : []) {
|
|
1655
|
+
if (agent?.status !== "running") continue;
|
|
1483
1656
|
await enrichAsyncSubagentAgent(run, agent, statusByDir);
|
|
1484
1657
|
}
|
|
1485
1658
|
}
|
|
1486
1659
|
|
|
1660
|
+
function trackSubagentGateAttempts(gate) {
|
|
1661
|
+
for (const attempt of Array.isArray(gate?.attempts) ? gate.attempts : []) {
|
|
1662
|
+
const runId = subagentText(attempt?.runId, 160);
|
|
1663
|
+
const agentName = subagentAgentName(attempt?.agent);
|
|
1664
|
+
if (!runId || !agentName || attempt?.status !== "running") continue;
|
|
1665
|
+
|
|
1666
|
+
const [recovered] = claimRecoveredSubagentMatches([{ name: agentName, model: subagentModel(attempt?.model) || undefined }]);
|
|
1667
|
+
const existing = ordinarySubagentRunEntries().find((entry) => entry.run?.id === runId)?.run;
|
|
1668
|
+
if (existing) {
|
|
1669
|
+
if (recovered && Array.isArray(existing.agents) && existing.agents.length === 1) {
|
|
1670
|
+
const [agent] = existing.agents;
|
|
1671
|
+
Object.assign(agent, {
|
|
1672
|
+
model: agent.model || recovered.agent?.model,
|
|
1673
|
+
thinking: agent.thinking || recovered.agent?.thinking,
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
continue;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
const startedAt = Number.isFinite(attempt?.startedAt)
|
|
1680
|
+
? attempt.startedAt
|
|
1681
|
+
: Number.isFinite(recovered?.startedAt)
|
|
1682
|
+
? recovered.startedAt
|
|
1683
|
+
: Date.now();
|
|
1684
|
+
const run = {
|
|
1685
|
+
id: runId,
|
|
1686
|
+
source: "async",
|
|
1687
|
+
mode: "single",
|
|
1688
|
+
status: "running",
|
|
1689
|
+
startedAt,
|
|
1690
|
+
eventSeenAt: Date.now(),
|
|
1691
|
+
agents: [{
|
|
1692
|
+
...recovered?.agent,
|
|
1693
|
+
id: `${runId}:0:${agentName}`,
|
|
1694
|
+
name: agentName,
|
|
1695
|
+
status: "running",
|
|
1696
|
+
index: 0,
|
|
1697
|
+
model: subagentModel(attempt?.model) || recovered?.agent?.model,
|
|
1698
|
+
thinking: subagentThinkingFromModel(attempt?.model) || recovered?.agent?.thinking,
|
|
1699
|
+
nested: false,
|
|
1700
|
+
}],
|
|
1701
|
+
};
|
|
1702
|
+
asyncSubagentRuns.set(runId, run);
|
|
1703
|
+
void enrichAsyncSubagentRun(run).finally(() => {
|
|
1704
|
+
if (asyncSubagentRuns.get(runId) === run) publishSubagentStatus();
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1487
1709
|
function subagentOutputSnapshotFromAgent(run, agent, patch = {}) {
|
|
1488
1710
|
const model = subagentModel(patch.model || agent.model) || undefined;
|
|
1489
1711
|
const thinking = subagentThinking(patch.thinking || agent.thinking) || undefined;
|
|
@@ -1493,7 +1715,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1493
1715
|
return {
|
|
1494
1716
|
version: 1,
|
|
1495
1717
|
runId: run.id,
|
|
1496
|
-
source:
|
|
1718
|
+
source: ["foreground", "recovered"].includes(run.source) ? run.source : "async",
|
|
1497
1719
|
mode: subagentMode(run.mode),
|
|
1498
1720
|
startedAt: Number.isFinite(run.startedAt) ? run.startedAt : Date.now(),
|
|
1499
1721
|
updatedAt: Number.isFinite(patch.updatedAt) ? patch.updatedAt : Date.now(),
|
|
@@ -1516,6 +1738,8 @@ export default function webuiRpcHelper(pi) {
|
|
|
1516
1738
|
recentTools: subagentRecentTools(patch.recentTools || agent.recentTools),
|
|
1517
1739
|
recentOutput: subagentOutputLines(patch.recentOutput || agent.recentOutput),
|
|
1518
1740
|
transcript: Array.isArray(patch.transcript) ? patch.transcript : [],
|
|
1741
|
+
unavailable: patch.unavailable === true || undefined,
|
|
1742
|
+
unavailableReason: patch.unavailable === true ? subagentText(patch.unavailableReason, 1000) || "Live output is unavailable for this recovered agent." : undefined,
|
|
1519
1743
|
error: subagentText(patch.error, 1000) || undefined,
|
|
1520
1744
|
},
|
|
1521
1745
|
};
|
|
@@ -1542,6 +1766,12 @@ export default function webuiRpcHelper(pi) {
|
|
|
1542
1766
|
const agentId = subagentText(payload.agentId, 240);
|
|
1543
1767
|
if (!runId || !agentId) throw new Error("Subagent output requires runId and agentId");
|
|
1544
1768
|
const { run, agent } = findTrackedSubagent(runId, agentId);
|
|
1769
|
+
if (run.source === "recovered") {
|
|
1770
|
+
return subagentOutputSnapshotFromAgent(run, agent, {
|
|
1771
|
+
unavailable: true,
|
|
1772
|
+
unavailableReason: "This active pi-subagents child was recovered from aggregate fleet metadata; detailed live output is unavailable until its run locator is observed.",
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1545
1775
|
if (run.source === "foreground") return subagentOutputSnapshotFromAgent(run, agent, { updatedAt: run.endedAt });
|
|
1546
1776
|
if (run.status !== "running") {
|
|
1547
1777
|
if (!agent.sessionFile && agent.asyncDir) {
|
|
@@ -1619,9 +1849,16 @@ export default function webuiRpcHelper(pi) {
|
|
|
1619
1849
|
const addSlots = (runs, priority) => {
|
|
1620
1850
|
for (const run of runs) {
|
|
1621
1851
|
if (run?.status !== "running") continue;
|
|
1852
|
+
const slotPriority = parsedIds.has(run.id) ? 0 : priority;
|
|
1853
|
+
// pi-subagents publishes one aggregate fleet entry named "workflow" for
|
|
1854
|
+
// each orchestration run. It is a controller, not a model-powered agent.
|
|
1855
|
+
// Claim it against the known workflow container so it cannot become an
|
|
1856
|
+
// empty recovered Workflow row beside the real child agent.
|
|
1857
|
+
if (run.workflow === true) slots.push({ run, identity: "workflow", priority: slotPriority, claimed: false });
|
|
1622
1858
|
for (const agent of Array.isArray(run.agents) ? run.agents : []) {
|
|
1623
|
-
|
|
1624
|
-
|
|
1859
|
+
const identity = subagentAgentName(agent?.name);
|
|
1860
|
+
if (agent?.status !== "running" || !identity) continue;
|
|
1861
|
+
slots.push({ run, agent, identity, priority: slotPriority, claimed: false });
|
|
1625
1862
|
}
|
|
1626
1863
|
}
|
|
1627
1864
|
};
|
|
@@ -1632,7 +1869,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1632
1869
|
const matchedRunIds = new Set();
|
|
1633
1870
|
const unmatched = [];
|
|
1634
1871
|
for (const entry of fleet.entries) {
|
|
1635
|
-
const slot = slots.find((candidate) => !candidate.claimed && candidate.
|
|
1872
|
+
const slot = slots.find((candidate) => !candidate.claimed && candidate.identity === entry.agent);
|
|
1636
1873
|
if (!slot) {
|
|
1637
1874
|
unmatched.push(entry);
|
|
1638
1875
|
continue;
|
|
@@ -1654,6 +1891,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1654
1891
|
agent: {
|
|
1655
1892
|
id: `fleet:${entry.key}:agent`,
|
|
1656
1893
|
name: entry.name,
|
|
1894
|
+
identity: entry.agent,
|
|
1657
1895
|
model: entry.model,
|
|
1658
1896
|
thinking: entry.thinking,
|
|
1659
1897
|
},
|
|
@@ -1678,6 +1916,12 @@ export default function webuiRpcHelper(pi) {
|
|
|
1678
1916
|
const data = await requestSubagentStatus();
|
|
1679
1917
|
if (generation !== subagentPollGeneration || sequence <= subagentAppliedPollSequence) return;
|
|
1680
1918
|
const parsedRuns = parseSubagentStatusText(data?.text, asyncSubagentRuns);
|
|
1919
|
+
const parsedRunIds = new Set(parsedRuns.map((run) => run.id));
|
|
1920
|
+
for (const run of parseAsyncSubagentSnapshot(data?.asyncSnapshot, asyncSubagentRuns)) {
|
|
1921
|
+
if (parsedRunIds.has(run.id)) continue;
|
|
1922
|
+
parsedRunIds.add(run.id);
|
|
1923
|
+
parsedRuns.push(run);
|
|
1924
|
+
}
|
|
1681
1925
|
const nextRuns = [];
|
|
1682
1926
|
for (const run of parsedRuns) {
|
|
1683
1927
|
const previous = asyncSubagentRuns.get(run.id);
|
|
@@ -1784,6 +2028,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1784
2028
|
id,
|
|
1785
2029
|
source: "async",
|
|
1786
2030
|
mode: subagentMode(info.mode, Array.isArray(info.chain) ? "chain" : "single"),
|
|
2031
|
+
workflow: info.mode === "workflow" || undefined,
|
|
1787
2032
|
status: "running",
|
|
1788
2033
|
startedAt: Date.now(),
|
|
1789
2034
|
eventSeenAt: Date.now(),
|
|
@@ -1802,12 +2047,18 @@ export default function webuiRpcHelper(pi) {
|
|
|
1802
2047
|
pi.events.on(SUBAGENT_GATE_UPDATE_EVENT, (value) => {
|
|
1803
2048
|
const id = subagentText(value?.id, 160);
|
|
1804
2049
|
if (!id) return;
|
|
1805
|
-
|
|
2050
|
+
const gate = { ...value, id };
|
|
2051
|
+
subagentGates.set(id, gate);
|
|
2052
|
+
trackSubagentGateAttempts(gate);
|
|
1806
2053
|
while (subagentGates.size > 32) subagentGates.delete(subagentGates.keys().next().value);
|
|
1807
2054
|
publishSubagentStatus();
|
|
1808
2055
|
}),
|
|
1809
2056
|
].filter((unsubscribe) => typeof unsubscribe === "function");
|
|
1810
2057
|
|
|
2058
|
+
function runtimeTools() {
|
|
2059
|
+
return runtimeToolBaseline ??= normalizeNameList(pi.getActiveTools());
|
|
2060
|
+
}
|
|
2061
|
+
|
|
1811
2062
|
function allToolNames() {
|
|
1812
2063
|
return pi.getAllTools().map((tool) => tool.name);
|
|
1813
2064
|
}
|
|
@@ -1879,12 +2130,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1879
2130
|
}
|
|
1880
2131
|
|
|
1881
2132
|
async function readGlobalResourceDefaults() {
|
|
1882
|
-
|
|
1883
|
-
return (await readWebuiSettings()).resourceDefaults;
|
|
1884
|
-
} catch (error) {
|
|
1885
|
-
console.warn(`Web UI resource defaults could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
1886
|
-
return { tools: { enabledTools: null }, skills: { enabledSkills: null } };
|
|
1887
|
-
}
|
|
2133
|
+
return (await readWebuiSettings()).resourceDefaults;
|
|
1888
2134
|
}
|
|
1889
2135
|
|
|
1890
2136
|
async function loadSubagentLaunchSlotGuidance(ctx) {
|
|
@@ -1899,8 +2145,10 @@ export default function webuiRpcHelper(pi) {
|
|
|
1899
2145
|
}
|
|
1900
2146
|
}
|
|
1901
2147
|
|
|
1902
|
-
function persistToolsState() {
|
|
1903
|
-
pi.appendEntry(TOOLS_CONFIG_TYPE,
|
|
2148
|
+
function persistToolsState(mode = "explicit") {
|
|
2149
|
+
pi.appendEntry(TOOLS_CONFIG_TYPE, mode === "inherit"
|
|
2150
|
+
? { version: 2, mode: "inherit" }
|
|
2151
|
+
: { version: 2, mode: "explicit", enabledTools: [...enabledTools] });
|
|
1904
2152
|
}
|
|
1905
2153
|
|
|
1906
2154
|
function applyTools() {
|
|
@@ -1908,23 +2156,24 @@ export default function webuiRpcHelper(pi) {
|
|
|
1908
2156
|
pi.setActiveTools([...enabledTools].filter((name) => existing.has(name)));
|
|
1909
2157
|
}
|
|
1910
2158
|
|
|
1911
|
-
function restoreToolsFromBranch(ctx,
|
|
1912
|
-
const
|
|
1913
|
-
|
|
1914
|
-
const
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
enabledTools = new Set(pi.getActiveTools());
|
|
2159
|
+
function restoreToolsFromBranch(ctx, resourceDefaults, model = ctx.model) {
|
|
2160
|
+
const directive = branchResourceDirective(lastBranchConfig(ctx, TOOLS_CONFIG_TYPE), "tools");
|
|
2161
|
+
toolsPinned = directive.pinned;
|
|
2162
|
+
const baseline = runtimeTools();
|
|
2163
|
+
const resolved = directive.pinned
|
|
2164
|
+
? { names: directive.names || [], source: "session" }
|
|
2165
|
+
: resolveResourceSelection(resourceDefaults, "tools", model?.provider, model?.id, baseline);
|
|
2166
|
+
enabledTools = new Set(resolved.names || baseline);
|
|
2167
|
+
toolSelectionSource = resolved.source;
|
|
2168
|
+
applyTools();
|
|
1922
2169
|
}
|
|
1923
2170
|
|
|
1924
2171
|
function toolState() {
|
|
1925
2172
|
const active = new Set(pi.getActiveTools());
|
|
1926
|
-
enabledTools = new Set([...active]);
|
|
1927
2173
|
return {
|
|
2174
|
+
pinned: toolsPinned,
|
|
2175
|
+
source: toolSelectionSource,
|
|
2176
|
+
enabledTools: [...enabledTools],
|
|
1928
2177
|
tools: pi.getAllTools().map((tool) => ({
|
|
1929
2178
|
name: tool.name,
|
|
1930
2179
|
description: tool.description || "",
|
|
@@ -1934,39 +2183,75 @@ export default function webuiRpcHelper(pi) {
|
|
|
1934
2183
|
};
|
|
1935
2184
|
}
|
|
1936
2185
|
|
|
1937
|
-
function setToolState(payload) {
|
|
2186
|
+
async function setToolState(ctx, payload) {
|
|
2187
|
+
if (payload?.mode === "inherit") {
|
|
2188
|
+
persistToolsState("inherit");
|
|
2189
|
+
await recomputeResourceState(ctx);
|
|
2190
|
+
return toolState();
|
|
2191
|
+
}
|
|
1938
2192
|
const existing = new Set(allToolNames());
|
|
1939
2193
|
if (Array.isArray(payload.enabledTools)) {
|
|
1940
|
-
enabledTools = new Set(normalizeNameList(payload.enabledTools)
|
|
2194
|
+
enabledTools = new Set(normalizeNameList(payload.enabledTools));
|
|
1941
2195
|
} else if (Array.isArray(payload.disabledTools)) {
|
|
1942
2196
|
const disabled = new Set(normalizeNameList(payload.disabledTools));
|
|
1943
2197
|
enabledTools = new Set([...existing].filter((name) => !disabled.has(name)));
|
|
1944
2198
|
} else {
|
|
1945
|
-
throw new Error("Tool update requires enabledTools or
|
|
2199
|
+
throw new Error("Tool update requires enabledTools, disabledTools, or inherit mode");
|
|
1946
2200
|
}
|
|
2201
|
+
toolsPinned = true;
|
|
2202
|
+
toolSelectionSource = "session";
|
|
1947
2203
|
applyTools();
|
|
1948
2204
|
persistToolsState();
|
|
1949
2205
|
return toolState();
|
|
1950
2206
|
}
|
|
1951
2207
|
|
|
1952
|
-
function persistSkillsState() {
|
|
1953
|
-
pi.appendEntry(SKILLS_CONFIG_TYPE,
|
|
2208
|
+
function persistSkillsState(mode = "explicit") {
|
|
2209
|
+
pi.appendEntry(SKILLS_CONFIG_TYPE, mode === "inherit"
|
|
2210
|
+
? { version: 2, mode: "inherit" }
|
|
2211
|
+
: { version: 2, mode: "explicit", enabledSkills: [...(inheritedEnabledSkills || [])] });
|
|
1954
2212
|
}
|
|
1955
2213
|
|
|
1956
2214
|
function isSkillEnabled(name) {
|
|
1957
2215
|
return inheritedEnabledSkills instanceof Set ? inheritedEnabledSkills.has(name) : !disabledSkills.has(name);
|
|
1958
2216
|
}
|
|
1959
2217
|
|
|
1960
|
-
function restoreSkillsFromBranch(ctx,
|
|
1961
|
-
const
|
|
1962
|
-
|
|
2218
|
+
function restoreSkillsFromBranch(ctx, resourceDefaults, model = ctx.model) {
|
|
2219
|
+
const directive = branchResourceDirective(lastBranchConfig(ctx, SKILLS_CONFIG_TYPE), "skills");
|
|
2220
|
+
skillsPinned = directive.pinned;
|
|
2221
|
+
disabledSkills = new Set();
|
|
2222
|
+
if (directive.pinned && directive.legacyDisabledNames !== null) {
|
|
1963
2223
|
inheritedEnabledSkills = null;
|
|
1964
|
-
disabledSkills = new Set(
|
|
2224
|
+
disabledSkills = new Set(directive.legacyDisabledNames);
|
|
2225
|
+
skillSelectionSource = "session";
|
|
1965
2226
|
return;
|
|
1966
2227
|
}
|
|
1967
|
-
const
|
|
1968
|
-
|
|
1969
|
-
|
|
2228
|
+
const resolved = directive.pinned
|
|
2229
|
+
? { names: directive.names || [], source: "session" }
|
|
2230
|
+
: resolveResourceSelection(resourceDefaults, "skills", model?.provider, model?.id, null);
|
|
2231
|
+
inheritedEnabledSkills = resolved.names === null ? null : new Set(resolved.names);
|
|
2232
|
+
skillSelectionSource = resolved.source;
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
function activeModelKey(model) {
|
|
2236
|
+
return model?.provider && model?.id ? `${model.provider}\0${model.id}` : "";
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
async function recomputeResourceState(ctx, requestedModel = ctx.model) {
|
|
2240
|
+
if (ctx?.mode !== "rpc") return false;
|
|
2241
|
+
const generation = ++resourceGeneration;
|
|
2242
|
+
const requestedKey = activeModelKey(requestedModel);
|
|
2243
|
+
let resourceDefaults;
|
|
2244
|
+
try {
|
|
2245
|
+
resourceDefaults = await readGlobalResourceDefaults();
|
|
2246
|
+
} catch (error) {
|
|
2247
|
+
console.warn(`Web UI resource defaults could not be read; retaining the last safe resource state: ${error instanceof Error ? error.message : String(error)}`);
|
|
2248
|
+
ctx.ui?.notify?.("Resource defaults could not be read; tools and skills remain unchanged.", "error");
|
|
2249
|
+
return false;
|
|
2250
|
+
}
|
|
2251
|
+
if (generation !== resourceGeneration || activeModelKey(ctx.model) !== requestedKey) return false;
|
|
2252
|
+
restoreToolsFromBranch(ctx, resourceDefaults, requestedModel);
|
|
2253
|
+
restoreSkillsFromBranch(ctx, resourceDefaults, requestedModel);
|
|
2254
|
+
return true;
|
|
1970
2255
|
}
|
|
1971
2256
|
|
|
1972
2257
|
function skillsFromContext(ctx) {
|
|
@@ -1987,20 +2272,34 @@ export default function webuiRpcHelper(pi) {
|
|
|
1987
2272
|
const known = new Set(skillsFromContext(ctx).map((skill) => skill.name));
|
|
1988
2273
|
disabledSkills = new Set([...disabledSkills].filter((name) => known.has(name)));
|
|
1989
2274
|
}
|
|
1990
|
-
return {
|
|
2275
|
+
return {
|
|
2276
|
+
pinned: skillsPinned,
|
|
2277
|
+
source: skillSelectionSource,
|
|
2278
|
+
enabledSkills: inheritedEnabledSkills instanceof Set
|
|
2279
|
+
? [...inheritedEnabledSkills]
|
|
2280
|
+
: skillsFromContext(ctx).filter((skill) => !disabledSkills.has(skill.name)).map((skill) => skill.name),
|
|
2281
|
+
skills: skillsFromContext(ctx),
|
|
2282
|
+
};
|
|
1991
2283
|
}
|
|
1992
2284
|
|
|
1993
|
-
function setSkillState(ctx, payload) {
|
|
2285
|
+
async function setSkillState(ctx, payload) {
|
|
2286
|
+
if (payload?.mode === "inherit") {
|
|
2287
|
+
persistSkillsState("inherit");
|
|
2288
|
+
await recomputeResourceState(ctx);
|
|
2289
|
+
return skillState(ctx);
|
|
2290
|
+
}
|
|
1994
2291
|
const allNames = new Set(skillsFromContext(ctx).map((skill) => skill.name));
|
|
1995
|
-
inheritedEnabledSkills = null;
|
|
1996
2292
|
if (Array.isArray(payload.enabledSkills)) {
|
|
1997
|
-
|
|
1998
|
-
disabledSkills = new Set([...allNames].filter((name) => !enabled.has(name)));
|
|
2293
|
+
inheritedEnabledSkills = new Set(normalizeNameList(payload.enabledSkills));
|
|
1999
2294
|
} else if (Array.isArray(payload.disabledSkills)) {
|
|
2000
|
-
|
|
2295
|
+
const disabled = new Set(normalizeNameList(payload.disabledSkills));
|
|
2296
|
+
inheritedEnabledSkills = new Set([...allNames].filter((name) => !disabled.has(name)));
|
|
2001
2297
|
} else {
|
|
2002
|
-
throw new Error("Skill update requires enabledSkills or
|
|
2298
|
+
throw new Error("Skill update requires enabledSkills, disabledSkills, or inherit mode");
|
|
2003
2299
|
}
|
|
2300
|
+
disabledSkills = new Set();
|
|
2301
|
+
skillsPinned = true;
|
|
2302
|
+
skillSelectionSource = "session";
|
|
2004
2303
|
persistSkillsState();
|
|
2005
2304
|
return skillState(ctx);
|
|
2006
2305
|
}
|
|
@@ -2028,6 +2327,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
2028
2327
|
if (!runId) throw new Error("Subagent dismiss requires runId");
|
|
2029
2328
|
const entry = findTrackedSubagentRun(runId);
|
|
2030
2329
|
if (entry.run.status === "running") throw new Error(`Cannot dismiss running subagent run: ${runId}`);
|
|
2330
|
+
rememberDismissedHelperAgentRunProjections(canonicalInstancesFromPublicRun(entry.run, new Set()));
|
|
2031
2331
|
entry.runs.delete(entry.key);
|
|
2032
2332
|
persistRetainedSubagentRuns();
|
|
2033
2333
|
publishSubagentStatus();
|
|
@@ -2070,13 +2370,21 @@ export default function webuiRpcHelper(pi) {
|
|
|
2070
2370
|
async function executeAction(action, payload, ctx) {
|
|
2071
2371
|
switch (action) {
|
|
2072
2372
|
case "tools-state":
|
|
2373
|
+
if (ctx.mode !== "rpc") throw new Error("Web UI resource controls require RPC mode");
|
|
2073
2374
|
return toolState();
|
|
2074
2375
|
case "tools-set":
|
|
2075
|
-
|
|
2376
|
+
if (ctx.mode !== "rpc") throw new Error("Web UI resource controls require RPC mode");
|
|
2377
|
+
return setToolState(ctx, payload);
|
|
2076
2378
|
case "skills-state":
|
|
2379
|
+
if (ctx.mode !== "rpc") throw new Error("Web UI resource controls require RPC mode");
|
|
2077
2380
|
return skillState(ctx);
|
|
2078
2381
|
case "skills-set":
|
|
2382
|
+
if (ctx.mode !== "rpc") throw new Error("Web UI resource controls require RPC mode");
|
|
2079
2383
|
return setSkillState(ctx, payload);
|
|
2384
|
+
case "resources-recompute":
|
|
2385
|
+
if (ctx.mode !== "rpc") throw new Error("Web UI resource controls require RPC mode");
|
|
2386
|
+
if (!(await recomputeResourceState(ctx))) throw new Error("Resource defaults could not be applied; current resources remain unchanged");
|
|
2387
|
+
return { tools: toolState(), skills: skillState(ctx) };
|
|
2080
2388
|
case "sampling-state":
|
|
2081
2389
|
return samplingState(ctx);
|
|
2082
2390
|
case "sampling-set":
|
|
@@ -2116,9 +2424,11 @@ export default function webuiRpcHelper(pi) {
|
|
|
2116
2424
|
});
|
|
2117
2425
|
|
|
2118
2426
|
pi.on("session_start", async (_event, ctx) => {
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2427
|
+
resourceRpcActive = ctx.mode === "rpc";
|
|
2428
|
+
if (resourceRpcActive) {
|
|
2429
|
+
if (runtimeToolBaseline === undefined) enabledTools = new Set(runtimeTools());
|
|
2430
|
+
await recomputeResourceState(ctx);
|
|
2431
|
+
}
|
|
2122
2432
|
restoreSamplingParamsFromBranch(ctx);
|
|
2123
2433
|
await loadSubagentLaunchSlotGuidance(ctx);
|
|
2124
2434
|
subagentContext = ctx;
|
|
@@ -2138,9 +2448,8 @@ export default function webuiRpcHelper(pi) {
|
|
|
2138
2448
|
});
|
|
2139
2449
|
|
|
2140
2450
|
pi.on("session_tree", async (_event, ctx) => {
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
restoreSkillsFromBranch(ctx, globalDefaults);
|
|
2451
|
+
resourceRpcActive = ctx.mode === "rpc";
|
|
2452
|
+
if (resourceRpcActive) await recomputeResourceState(ctx);
|
|
2144
2453
|
restoreSamplingParamsFromBranch(ctx);
|
|
2145
2454
|
subagentContext = ctx;
|
|
2146
2455
|
subagentPollGeneration += 1;
|
|
@@ -2158,6 +2467,12 @@ export default function webuiRpcHelper(pi) {
|
|
|
2158
2467
|
scheduleSubagentStatusPoll(subagentPollGeneration, 0);
|
|
2159
2468
|
});
|
|
2160
2469
|
|
|
2470
|
+
pi.on("model_select", async (event, ctx) => {
|
|
2471
|
+
if (ctx.mode !== "rpc") return;
|
|
2472
|
+
resourceRpcActive = true;
|
|
2473
|
+
await recomputeResourceState(ctx, event.model);
|
|
2474
|
+
});
|
|
2475
|
+
|
|
2161
2476
|
pi.on("tool_execution_start", (event, ctx) => {
|
|
2162
2477
|
if (event.toolName !== "subagent" || event.args?.action) return;
|
|
2163
2478
|
const id = subagentText(event.toolCallId, 160);
|
|
@@ -2193,11 +2508,36 @@ export default function webuiRpcHelper(pi) {
|
|
|
2193
2508
|
pi.on("tool_execution_update", (event, ctx) => {
|
|
2194
2509
|
if (event.toolName !== "subagent") return;
|
|
2195
2510
|
const id = subagentText(event.toolCallId, 160);
|
|
2196
|
-
|
|
2511
|
+
if (!id) return;
|
|
2512
|
+
const details = event.partialResult?.details || event.result?.details;
|
|
2513
|
+
const controlRunId = subagentText(details?.runId, 160);
|
|
2514
|
+
const agents = subagentRunningAgentsFromDetails(details, controlRunId || id);
|
|
2515
|
+
let run = foregroundSubagentRuns.get(id);
|
|
2516
|
+
if (!run && controlRunId && agents.length) {
|
|
2517
|
+
const recoveredMatches = claimRecoveredSubagentMatches(agents);
|
|
2518
|
+
const startedAt = recoveredMatches
|
|
2519
|
+
.map((match) => match?.startedAt)
|
|
2520
|
+
.filter(Number.isFinite)
|
|
2521
|
+
.sort((left, right) => left - right)[0];
|
|
2522
|
+
run = {
|
|
2523
|
+
id: controlRunId,
|
|
2524
|
+
source: "foreground",
|
|
2525
|
+
mode: subagentMode(details?.mode),
|
|
2526
|
+
status: "running",
|
|
2527
|
+
startedAt: Number.isFinite(startedAt) ? startedAt : Date.now(),
|
|
2528
|
+
controlRunId,
|
|
2529
|
+
workflowProvisional: false,
|
|
2530
|
+
agents: agents.map((agent, index) => ({
|
|
2531
|
+
...recoveredMatches[index]?.agent,
|
|
2532
|
+
...agent,
|
|
2533
|
+
model: agent.model || recoveredMatches[index]?.agent?.model,
|
|
2534
|
+
thinking: agent.thinking || recoveredMatches[index]?.agent?.thinking,
|
|
2535
|
+
})),
|
|
2536
|
+
};
|
|
2537
|
+
foregroundSubagentRuns.set(id, run);
|
|
2538
|
+
}
|
|
2197
2539
|
if (!run || run.status !== "running") return;
|
|
2198
2540
|
subagentContext = ctx;
|
|
2199
|
-
const details = event.partialResult?.details || event.result?.details;
|
|
2200
|
-
const agents = subagentRunningAgentsFromDetails(details, details?.runId || id);
|
|
2201
2541
|
if (agents.length) {
|
|
2202
2542
|
run.workflowProvisional = false;
|
|
2203
2543
|
const runningAgents = agents.map((agent) => {
|
|
@@ -2215,9 +2555,9 @@ export default function webuiRpcHelper(pi) {
|
|
|
2215
2555
|
.map((agent) => ({ ...agent, status: agent.status === "running" ? "done" : agent.status }));
|
|
2216
2556
|
run.agents = [...completedAgents, ...runningAgents];
|
|
2217
2557
|
}
|
|
2218
|
-
if (
|
|
2219
|
-
run.controlRunId =
|
|
2220
|
-
run.id =
|
|
2558
|
+
if (controlRunId) {
|
|
2559
|
+
run.controlRunId = controlRunId;
|
|
2560
|
+
run.id = controlRunId;
|
|
2221
2561
|
}
|
|
2222
2562
|
run.mode = subagentMode(details?.mode, run.mode);
|
|
2223
2563
|
publishSubagentStatus();
|
|
@@ -2234,6 +2574,8 @@ export default function webuiRpcHelper(pi) {
|
|
|
2234
2574
|
});
|
|
2235
2575
|
|
|
2236
2576
|
pi.on("session_shutdown", () => {
|
|
2577
|
+
resourceRpcActive = false;
|
|
2578
|
+
resourceGeneration += 1;
|
|
2237
2579
|
subagentContext = null;
|
|
2238
2580
|
subagentLaunchSlotGuidance = "";
|
|
2239
2581
|
subagentPollGeneration += 1;
|
|
@@ -2257,6 +2599,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
2257
2599
|
});
|
|
2258
2600
|
|
|
2259
2601
|
pi.on("input", async (event, ctx) => {
|
|
2602
|
+
if (!resourceRpcActive || ctx.mode !== "rpc") return { action: "continue" };
|
|
2260
2603
|
const match = String(event.text || "").trim().match(/^\/skill:([^\s]+)/i);
|
|
2261
2604
|
if (!match) return { action: "continue" };
|
|
2262
2605
|
const skillName = match[1];
|
|
@@ -2268,11 +2611,11 @@ export default function webuiRpcHelper(pi) {
|
|
|
2268
2611
|
pi.on("before_agent_start", async (event) => {
|
|
2269
2612
|
let nextPrompt = event.systemPrompt;
|
|
2270
2613
|
let changed = false;
|
|
2271
|
-
if (disabledSkills.size !== 0 || inheritedEnabledSkills !== null) {
|
|
2614
|
+
if (resourceRpcActive && (disabledSkills.size !== 0 || inheritedEnabledSkills !== null)) {
|
|
2272
2615
|
const allSkills = Array.isArray(event.systemPromptOptions?.skills) ? event.systemPromptOptions.skills : [];
|
|
2273
2616
|
const disabledNames = allSkills.filter((skill) => !isSkillEnabled(skill.name)).map((skill) => skill.name);
|
|
2274
|
-
|
|
2275
|
-
|
|
2617
|
+
const filteredSkills = allSkills.filter((skill) => isSkillEnabled(skill.name) && skill.disableModelInvocation !== true);
|
|
2618
|
+
if (disabledNames.length || filteredSkills.length !== allSkills.length) {
|
|
2276
2619
|
nextPrompt = replaceAvailableSkillsSection(nextPrompt, filteredSkills);
|
|
2277
2620
|
for (const name of disabledNames) nextPrompt = nextPrompt.replace(skillBlockPattern(name), "");
|
|
2278
2621
|
changed = true;
|