@firstpick/pi-package-webui 0.9.6 → 0.9.8
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 +13 -5
- package/bin/pi-webui.mjs +480 -96
- package/index.ts +2 -1
- package/lib/git-workflow-preferences.mjs +21 -1
- package/lib/optional-feature-catalog.mjs +1 -1
- package/lib/session-tree-event-targets.mjs +70 -0
- package/lib/subagent-launch-policy.mjs +375 -0
- package/lib/subagent-launch-slots.mjs +2 -1
- package/package.json +1 -1
- package/public/app.js +1348 -131
- package/public/guided-git-command-state.mjs +175 -1
- package/public/index.html +48 -9
- package/public/service-worker.js +1 -1
- package/public/styles.css +387 -34
- package/public/transcript-renderer.mjs +62 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-visibility.spec.mjs +141 -2
- package/tests/browser/events-tree-context-menu.spec.mjs +240 -0
- package/tests/browser/footer-model-advanced-layout.spec.mjs +512 -0
- package/tests/browser/guided-git-extension-command.spec.mjs +180 -0
- package/tests/browser/guided-git-fallback.spec.mjs +218 -0
- package/tests/browser/interaction-continuity.spec.mjs +33 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/compact-sections-static.test.mjs +4 -0
- package/tests/compaction-static.test.mjs +1 -1
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-visibility-static.test.mjs +66 -3
- package/tests/controls-layout-static.test.mjs +3 -3
- package/tests/events-tree-context-menu-static.test.mjs +131 -0
- package/tests/fast-mode-client-static.test.mjs +5 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/file-viewer-image-static.test.mjs +3 -3
- package/tests/fixtures/fake-pi.mjs +34 -3
- package/tests/git-footer-context-menu-static.test.mjs +103 -1
- package/tests/git-workflow-preferences.test.mjs +30 -1
- package/tests/guided-git-activation-http.test.mjs +194 -0
- package/tests/guided-git-activation-static.test.mjs +80 -0
- package/tests/guided-git-activation.test.mjs +244 -0
- package/tests/guided-git-fallback-runtime.test.mjs +419 -0
- package/tests/guided-git-fallback-ui-static.test.mjs +60 -0
- package/tests/guided-git-message-reliability-static.test.mjs +9 -7
- package/tests/guided-git-optional-feature.test.mjs +31 -0
- package/tests/http-endpoints-harness.test.mjs +3 -0
- package/tests/interaction-state-stability-static.test.mjs +1 -1
- package/tests/intercom-conversation-viewer-static.test.mjs +3 -3
- package/tests/main-output-loading-static.test.mjs +11 -9
- 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 +92 -9
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/prompt-input-vertical-scroll-static.test.mjs +6 -6
- package/tests/prompt-routing-input-clear-static.test.mjs +1 -1
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +23 -0
- package/tests/resource-defaults-helper.test.mjs +12 -0
- package/tests/session-sampling-helper.test.mjs +1 -0
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/session-tree-event-targets.test.mjs +106 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/subagent-launch-policy.test.mjs +532 -0
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagents-helper.test.mjs +211 -1
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +25 -0
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thinking-block-grouping.test.mjs +79 -0
- package/webui-rpc-helper.mjs +220 -3
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import vm from "node:vm";
|
|
3
|
+
import { applySubagentLaunchSlotDefaults } from "../lib/subagent-launch-policy.mjs";
|
|
4
|
+
import { defaultSubagentLaunchSlotRoles } from "../lib/subagent-launch-slots.mjs";
|
|
5
|
+
|
|
6
|
+
const roles = defaultSubagentLaunchSlotRoles();
|
|
7
|
+
roles.delegate[0] = { id: "delegate:base", model: "openai-codex/gpt-5.6-luna", thinking: "low" };
|
|
8
|
+
roles.reviewer[0] = { id: "reviewer:base", model: "openai-codex/gpt-5.6-sol", thinking: "high" };
|
|
9
|
+
roles.reviewer.push({ id: "reviewer:second", model: "openrouter/moonshotai/kimi-k3", thinking: "high" });
|
|
10
|
+
roles.worker[0] = { id: "worker:base", model: "openai-codex/gpt-5.6-sol", thinking: "high" };
|
|
11
|
+
const unexpiredPermit = () => Date.now() + 60_000;
|
|
12
|
+
const WORKFLOW_MARKER_SPOOF = "/* PI_WEBUI_SUBAGENT_LAUNCH_SLOTS_V1 */";
|
|
13
|
+
|
|
14
|
+
function workflowRuntime() {
|
|
15
|
+
const calls = [];
|
|
16
|
+
const runs = Object.freeze({
|
|
17
|
+
async run(key, params) { calls.push({ method: "run", key, ...params }); return { key, ok: true }; },
|
|
18
|
+
async all(items) { calls.push({ method: "all", items }); return items.map(({ key }) => ({ key, ok: true })); },
|
|
19
|
+
async status() { return {}; },
|
|
20
|
+
ref() { return ""; },
|
|
21
|
+
refs() { return ""; },
|
|
22
|
+
});
|
|
23
|
+
return { calls, runs };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function validatingWorkflowRuntime() {
|
|
27
|
+
const calls = [];
|
|
28
|
+
const runs = Object.freeze({
|
|
29
|
+
run(key, params) {
|
|
30
|
+
if (key === "invalid") throw new Error("invalid run key");
|
|
31
|
+
calls.push({ method: "run", key, ...params });
|
|
32
|
+
return Promise.resolve({ key, ok: true });
|
|
33
|
+
},
|
|
34
|
+
all(items) {
|
|
35
|
+
if (items.some((item) => item?.key === "invalid")) throw new Error("invalid all key");
|
|
36
|
+
calls.push({ method: "all", items });
|
|
37
|
+
return Promise.resolve(items.map(({ key }) => ({ key, ok: true })));
|
|
38
|
+
},
|
|
39
|
+
async status() { return {}; },
|
|
40
|
+
ref() { return ""; },
|
|
41
|
+
refs() { return ""; },
|
|
42
|
+
});
|
|
43
|
+
return { calls, runs };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function executeWorkflow(input, runs) {
|
|
47
|
+
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
|
|
48
|
+
return new AsyncFunction("runs", input.workflowScript)(runs);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function executeWorkflowInVm(input, runs) {
|
|
52
|
+
const context = vm.createContext({ runs }, { codeGeneration: { strings: false, wasm: false } });
|
|
53
|
+
const compiled = new vm.Script(`(async () => {\n${input.workflowScript}\n})()`, { filename: "workflow-policy-test.js" });
|
|
54
|
+
return compiled.runInContext(context);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
const input = { agent: "delegate", task: "Handle a bounded task" };
|
|
59
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
60
|
+
assert.equal(input.model, "openai-codex/gpt-5.6-luna:low", "a structured single launch should receive its role preset");
|
|
61
|
+
assert.deepEqual(report.applied.map(({ role, occurrence, location }) => [role, occurrence, location]), [["delegate", 1, "agent"]]);
|
|
62
|
+
assert.deepEqual(report.blocked, []);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
{
|
|
66
|
+
const input = { agent: "reviewer", task: "Use the configured model", model: "openai-codex/gpt-5.6-sol:high" };
|
|
67
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
68
|
+
assert.equal(input.model, "openai-codex/gpt-5.6-sol:high", "an exact explicit reviewer model should remain unchanged");
|
|
69
|
+
assert.deepEqual(report.blocked, []);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
{
|
|
73
|
+
const input = { agent: "reviewer", task: "Use the requested model", model: "anthropic/claude-opus-4-8:high" };
|
|
74
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
75
|
+
assert.equal(input.model, "anthropic/claude-opus-4-8:high", "an explicit reviewer mismatch must not be silently overwritten");
|
|
76
|
+
assert.deepEqual(report.blocked, [{
|
|
77
|
+
code: "reviewer-model-mismatch",
|
|
78
|
+
role: "reviewer",
|
|
79
|
+
occurrence: 1,
|
|
80
|
+
location: "agent",
|
|
81
|
+
slotId: "reviewer:base",
|
|
82
|
+
expectedModel: "openai-codex/gpt-5.6-sol:high",
|
|
83
|
+
requestedModel: "anthropic/claude-opus-4-8:high",
|
|
84
|
+
correctionModel: "openai-codex/gpt-5.6-sol:high",
|
|
85
|
+
}]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
{
|
|
89
|
+
const input = { agent: "reviewer", task: "Use lower thinking", model: "openai-codex/gpt-5.6-sol:low" };
|
|
90
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
91
|
+
assert.equal(report.blocked[0]?.code, "reviewer-thinking-mismatch", "a recognized terminal thinking suffix should be compared separately");
|
|
92
|
+
assert.equal(report.blocked[0]?.expectedModel, "openai-codex/gpt-5.6-sol:high");
|
|
93
|
+
assert.equal(report.blocked[0]?.requestedModel, "openai-codex/gpt-5.6-sol:low");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
{
|
|
97
|
+
const input = { agent: "reviewer", task: "Use an approved deviation", model: "anthropic/claude-opus-4-8:high" };
|
|
98
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles, {
|
|
99
|
+
deviations: [
|
|
100
|
+
{ id: "wrong-slot", role: "reviewer", occurrence: 2, requestedModel: input.model, expiresAt: unexpiredPermit() },
|
|
101
|
+
{ id: "permit-1", role: "reviewer", occurrence: 1, requestedModel: input.model, expiresAt: unexpiredPermit() },
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
assert.deepEqual(report.blocked, []);
|
|
105
|
+
assert.deepEqual(report.consumedDeviationIds, ["permit-1"], "only the matching occurrence/model deviation should be consumed");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
const input = { agent: "reviewer", task: "Do not accept an unbounded descriptor", model: "other/model:high" };
|
|
110
|
+
const deviations = Array.from({ length: 9 }, (_, index) => ({
|
|
111
|
+
id: `permit-${index + 1}`,
|
|
112
|
+
role: "reviewer",
|
|
113
|
+
occurrence: index === 8 ? 1 : 2,
|
|
114
|
+
requestedModel: input.model,
|
|
115
|
+
expiresAt: unexpiredPermit(),
|
|
116
|
+
}));
|
|
117
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles, { deviations });
|
|
118
|
+
assert.equal(report.blocked[0]?.code, "reviewer-model-mismatch", "deviation matching must ignore descriptors beyond the eight-item bound");
|
|
119
|
+
assert.deepEqual(report.consumedDeviationIds, []);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
{
|
|
123
|
+
const input = {
|
|
124
|
+
tasks: [
|
|
125
|
+
{ agent: "reviewer", task: "Review correctness", model: "openai-codex/gpt-5.6-sol:high" },
|
|
126
|
+
{ agent: "worker", task: "Implement the fix", model: "custom/worker-model:low" },
|
|
127
|
+
{ agent: "reviewer", task: "Review tests", model: "openai-codex/gpt-5.6-sol:high" },
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
const report = applySubagentLaunchSlotDefaults("subagent_gate", input, roles);
|
|
131
|
+
assert.equal(report.blocked.length, 1);
|
|
132
|
+
assert.deepEqual(
|
|
133
|
+
{ code: report.blocked[0].code, occurrence: report.blocked[0].occurrence, location: report.blocked[0].location },
|
|
134
|
+
{ code: "reviewer-model-mismatch", occurrence: 2, location: "tasks[2]" },
|
|
135
|
+
"reviewer occurrences should be enforced in task order independently of other roles",
|
|
136
|
+
);
|
|
137
|
+
assert.equal(input.tasks[1].model, "custom/worker-model:low", "non-reviewer explicit models must remain unchanged and unenforced");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
{
|
|
141
|
+
const input = {
|
|
142
|
+
tasks: [
|
|
143
|
+
{ agent: "reviewer", task: "Review correctness" },
|
|
144
|
+
{ agent: "worker", task: "Implement the fix" },
|
|
145
|
+
{ agent: "reviewer", task: "Review tests" },
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
const report = applySubagentLaunchSlotDefaults("subagent_gate", input, roles);
|
|
149
|
+
assert.deepEqual(input.tasks.map((task) => task.model), [
|
|
150
|
+
"openai-codex/gpt-5.6-sol:high",
|
|
151
|
+
"openai-codex/gpt-5.6-sol:high",
|
|
152
|
+
"openrouter/moonshotai/kimi-k3:high",
|
|
153
|
+
], "omitted models should still consume their configured role slots in task order");
|
|
154
|
+
assert.equal(report.applied.length, 3);
|
|
155
|
+
assert.deepEqual(report.blocked, []);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
{
|
|
159
|
+
const input = { tasks: [{ agent: "reviewer", task: "A", count: 2 }] };
|
|
160
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
161
|
+
assert.equal(input.tasks[0].model, undefined, "one counted task must not collapse heterogeneous reviewer slots into one model");
|
|
162
|
+
assert.equal(report.unsupported[0]?.reason, "count-needs-explicit-tasks");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
{
|
|
166
|
+
const input = {
|
|
167
|
+
workflowScript: "const first = await runs.run('review-1', {agent:'reviewer', task:'Review one'}); return runs.all([{key:'work', agent:'worker', task:'Implement'}, {key:'review-2', agent:'reviewer', task:'Review two'}])",
|
|
168
|
+
};
|
|
169
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
170
|
+
assert.match(input.workflowScript, /PI_WEBUI_SUBAGENT_LAUNCH_SLOTS_V1/, "workflow source should receive one runtime wrapper instead of heuristic call-site edits");
|
|
171
|
+
assert.equal(report.applied[0]?.reason, "runtime-role-defaults");
|
|
172
|
+
const runtime = workflowRuntime();
|
|
173
|
+
await executeWorkflow(input, runtime.runs);
|
|
174
|
+
assert.deepEqual(runtime.calls[0], {
|
|
175
|
+
method: "run",
|
|
176
|
+
key: "review-1",
|
|
177
|
+
agent: "reviewer",
|
|
178
|
+
task: "Review one",
|
|
179
|
+
model: "openai-codex/gpt-5.6-sol:high",
|
|
180
|
+
});
|
|
181
|
+
assert.deepEqual(runtime.calls[1].items.map(({ agent, model }) => [agent, model]), [
|
|
182
|
+
["worker", "openai-codex/gpt-5.6-sol:high"],
|
|
183
|
+
["reviewer", "openrouter/moonshotai/kimi-k3:high"],
|
|
184
|
+
], "workflow runs should fill omitted models in actual launch order");
|
|
185
|
+
const wrappedOnce = input.workflowScript;
|
|
186
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
187
|
+
assert.equal(input.workflowScript, wrappedOnce, "the workflow wrapper should be idempotent");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
{
|
|
191
|
+
const input = {
|
|
192
|
+
workflowScript: "return runs.run('review-1', {agent:'reviewer', task:'Review one', model:'other/model:high'})",
|
|
193
|
+
};
|
|
194
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
195
|
+
const runtime = workflowRuntime();
|
|
196
|
+
await assert.rejects(
|
|
197
|
+
executeWorkflow(input, runtime.runs),
|
|
198
|
+
(error) => {
|
|
199
|
+
assert.equal(error.code, "reviewer-model-policy-blocked");
|
|
200
|
+
assert.deepEqual(error.decisions.map(({ code, occurrence, location }) => ({ code, occurrence, location })), [
|
|
201
|
+
{ code: "reviewer-model-mismatch", occurrence: 1, location: "runs.run" },
|
|
202
|
+
]);
|
|
203
|
+
return true;
|
|
204
|
+
},
|
|
205
|
+
);
|
|
206
|
+
assert.deepEqual(runtime.calls, [], "a blocked runs.run must not reach the original runtime");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
{
|
|
210
|
+
const input = {
|
|
211
|
+
workflowScript: "return runs.all([{key:'review-1', agent:'reviewer', task:'One', model:'other/one:high'}, {key:'review-2', agent:'reviewer', task:'Two', model:'other/two:high'}])",
|
|
212
|
+
};
|
|
213
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
214
|
+
const runtime = workflowRuntime();
|
|
215
|
+
await assert.rejects(
|
|
216
|
+
executeWorkflow(input, runtime.runs),
|
|
217
|
+
(error) => {
|
|
218
|
+
assert.equal(error.code, "reviewer-model-policy-blocked");
|
|
219
|
+
assert.deepEqual(error.decisions.map(({ occurrence, location }) => ({ occurrence, location })), [
|
|
220
|
+
{ occurrence: 1, location: "runs.all[0]" },
|
|
221
|
+
{ occurrence: 2, location: "runs.all[1]" },
|
|
222
|
+
], "runs.all should preflight every item before reporting its bounded decisions");
|
|
223
|
+
return true;
|
|
224
|
+
},
|
|
225
|
+
);
|
|
226
|
+
assert.deepEqual(runtime.calls, [], "a runs.all mismatch must be detected before the original runs.all receives children");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
{
|
|
230
|
+
const input = {
|
|
231
|
+
workflowScript: "return runs.all([{key:'review-1', agent:'reviewer', task:'One', model:'other/one:high'}, {key:'review-2', agent:'reviewer', task:'Two', model:'openrouter/moonshotai/kimi-k3:high'}])",
|
|
232
|
+
};
|
|
233
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles, {
|
|
234
|
+
deviations: [{ id: "workflow-permit", role: "reviewer", occurrence: 1, requestedModel: "other/one:high", expiresAt: unexpiredPermit() }],
|
|
235
|
+
});
|
|
236
|
+
const runtime = workflowRuntime();
|
|
237
|
+
await executeWorkflow(input, runtime.runs);
|
|
238
|
+
assert.equal(runtime.calls.length, 1, "a matching workflow deviation should admit the atomic run group");
|
|
239
|
+
assert.equal(runtime.calls[0].method, "all");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
{
|
|
243
|
+
for (const method of ["run", "all"]) {
|
|
244
|
+
const call = method === "run"
|
|
245
|
+
? "return runs.run('review', {agent:'reviewer', task:'Review', model:'other/model:high'})"
|
|
246
|
+
: "return runs.all([{key:'review', agent:'reviewer', task:'Review', model:'other/model:high'}])";
|
|
247
|
+
const input = { workflowScript: `${WORKFLOW_MARKER_SPOOF}\n${call}` };
|
|
248
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
249
|
+
const runtime = workflowRuntime();
|
|
250
|
+
await assert.rejects(executeWorkflow(input, runtime.runs), (error) => error.code === "reviewer-model-policy-blocked");
|
|
251
|
+
assert.deepEqual(runtime.calls, [], `a model-supplied wrapper marker must not bypass runs.${method}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
{
|
|
256
|
+
const input = { workflowScript: "return runs.run('review', {agent:'reviewer', task:'VM execution'})" };
|
|
257
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
258
|
+
const runtime = workflowRuntime();
|
|
259
|
+
await executeWorkflowInVm(input, runtime.runs);
|
|
260
|
+
assert.equal(runtime.calls[0]?.model, "openai-codex/gpt-5.6-sol:high", "the wrapper must execute in the real workflow runtime's string-code-generation-disabled VM shape");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
{
|
|
264
|
+
const privateNames = [
|
|
265
|
+
"__piWebuiUserWorkflow",
|
|
266
|
+
"__piWebuiRoleSlots",
|
|
267
|
+
"__piWebuiDeviations",
|
|
268
|
+
"__piWebuiThinkingPattern",
|
|
269
|
+
"__piWebuiNow",
|
|
270
|
+
"__piWebuiRoleOccurrences",
|
|
271
|
+
"__piWebuiConsumedDeviationIndexes",
|
|
272
|
+
"__piWebuiOriginalRuns",
|
|
273
|
+
"__piWebuiParseModel",
|
|
274
|
+
"__piWebuiPrepare",
|
|
275
|
+
"__piWebuiThrowBlocked",
|
|
276
|
+
"__piWebuiRuns",
|
|
277
|
+
];
|
|
278
|
+
const input = { workflowScript: `return [${privateNames.map((name) => `typeof ${name}`).join(",")}];` };
|
|
279
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
280
|
+
const runtime = workflowRuntime();
|
|
281
|
+
assert.deepEqual(await executeWorkflow(input, runtime.runs), privateNames.map(() => "undefined"), "supplied workflow code must not close over wrapper-private state");
|
|
282
|
+
|
|
283
|
+
const bypass = { workflowScript: "return __piWebuiOriginalRuns.run('review', {agent:'reviewer', task:'Bypass', model:'other/model:high'})" };
|
|
284
|
+
applySubagentLaunchSlotDefaults("subagent", bypass, roles);
|
|
285
|
+
await assert.rejects(executeWorkflow(bypass, runtime.runs), /__piWebuiOriginalRuns is not defined/);
|
|
286
|
+
assert.deepEqual(runtime.calls, [], "supplied workflow code must not reach the original runs object by generated identifier");
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
{
|
|
290
|
+
for (const method of ["run", "all"]) {
|
|
291
|
+
const leakKey = `__piWebuiPolicyPoisonLeaks_${method}`;
|
|
292
|
+
const call = method === "run"
|
|
293
|
+
? "return await runs.run('review', {agent:'reviewer', task:'Review', model:'other/model:high'});"
|
|
294
|
+
: "return await runs.all([{key:'review', agent:'reviewer', task:'Review', model:'other/model:high'}]);";
|
|
295
|
+
const input = {
|
|
296
|
+
workflowScript: `
|
|
297
|
+
const leaks = [];
|
|
298
|
+
globalThis[${JSON.stringify(leakKey)}] = leaks;
|
|
299
|
+
const originalArrayIsArray = Array.isArray;
|
|
300
|
+
const originalFindIndex = Array.prototype.findIndex;
|
|
301
|
+
const originalSetHas = Set.prototype.has;
|
|
302
|
+
const originalSetAdd = Set.prototype.add;
|
|
303
|
+
const originalObjectAssign = Object.assign;
|
|
304
|
+
Array.isArray = function (value) { leaks[leaks.length] = value; return originalArrayIsArray(value); };
|
|
305
|
+
Array.prototype.findIndex = function () { leaks[leaks.length] = this; return 0; };
|
|
306
|
+
Set.prototype.has = function () { leaks[leaks.length] = this; return false; };
|
|
307
|
+
Set.prototype.add = function () { leaks[leaks.length] = this; return this; };
|
|
308
|
+
Object.assign = function (target) { leaks[leaks.length] = target; return target; };
|
|
309
|
+
try {
|
|
310
|
+
${call}
|
|
311
|
+
} finally {
|
|
312
|
+
Array.isArray = originalArrayIsArray;
|
|
313
|
+
Array.prototype.findIndex = originalFindIndex;
|
|
314
|
+
Set.prototype.has = originalSetHas;
|
|
315
|
+
Set.prototype.add = originalSetAdd;
|
|
316
|
+
Object.assign = originalObjectAssign;
|
|
317
|
+
}
|
|
318
|
+
`,
|
|
319
|
+
};
|
|
320
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
321
|
+
const runtime = workflowRuntime();
|
|
322
|
+
await assert.rejects(executeWorkflow(input, runtime.runs), (error) => error.code === "reviewer-model-policy-blocked");
|
|
323
|
+
assert.deepEqual(runtime.calls, [], `runs.${method} must still block a no-permit mismatch after mutable intrinsic poisoning`);
|
|
324
|
+
assert.deepEqual(globalThis[leakKey], [], `runs.${method} policy must not expose private state through poisoned intrinsics`);
|
|
325
|
+
delete globalThis[leakKey];
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
{
|
|
330
|
+
for (const method of ["run", "all"]) {
|
|
331
|
+
const call = method === "run"
|
|
332
|
+
? "return await runs.run('review', {agent:'reviewer', task:'Review', model:'other/model:high'});"
|
|
333
|
+
: "return await runs.all([{key:'review', agent:'reviewer', task:'Review', model:'other/model:high'}]);";
|
|
334
|
+
const input = {
|
|
335
|
+
workflowScript: `
|
|
336
|
+
const previous = Object.getOwnPropertyDescriptor(Array.prototype, '0');
|
|
337
|
+
Object.defineProperty(Array.prototype, '0', {
|
|
338
|
+
configurable: true,
|
|
339
|
+
set() { throw new Error('private indexed assignment reached poisoned prototype'); },
|
|
340
|
+
});
|
|
341
|
+
try {
|
|
342
|
+
${call}
|
|
343
|
+
} finally {
|
|
344
|
+
if (previous) Object.defineProperty(Array.prototype, '0', previous);
|
|
345
|
+
else delete Array.prototype[0];
|
|
346
|
+
}
|
|
347
|
+
`,
|
|
348
|
+
};
|
|
349
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
350
|
+
const runtime = workflowRuntime();
|
|
351
|
+
await assert.rejects(
|
|
352
|
+
executeWorkflow(input, runtime.runs),
|
|
353
|
+
(error) => error.code === "reviewer-model-policy-blocked",
|
|
354
|
+
`runs.${method} must define private array entries as own properties despite numeric prototype setters`,
|
|
355
|
+
);
|
|
356
|
+
assert.deepEqual(runtime.calls, [], `runs.${method} must not admit a mismatch through an inherited numeric setter`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
{
|
|
361
|
+
const input = {
|
|
362
|
+
workflowScript: `
|
|
363
|
+
let leakedSlots;
|
|
364
|
+
const previous = Object.getOwnPropertyDescriptor(Array.prototype, '2');
|
|
365
|
+
Object.defineProperty(Array.prototype, '2', {
|
|
366
|
+
configurable: true,
|
|
367
|
+
get() { leakedSlots = this; return undefined; },
|
|
368
|
+
});
|
|
369
|
+
try {
|
|
370
|
+
try {
|
|
371
|
+
await runs.all([
|
|
372
|
+
{key:'blocked', agent:'reviewer', task:'Block', model:'other/model:high'},
|
|
373
|
+
{key:'second', agent:'reviewer', task:'Second'},
|
|
374
|
+
{key:'overflow', agent:'reviewer', task:'Overflow'},
|
|
375
|
+
]);
|
|
376
|
+
} catch (error) {
|
|
377
|
+
if (error.code !== 'reviewer-model-policy-blocked') throw error;
|
|
378
|
+
}
|
|
379
|
+
} finally {
|
|
380
|
+
if (previous) Object.defineProperty(Array.prototype, '2', previous);
|
|
381
|
+
else delete Array.prototype[2];
|
|
382
|
+
}
|
|
383
|
+
if (leakedSlots) {
|
|
384
|
+
leakedSlots[0].model = 'other/model:high';
|
|
385
|
+
return runs.run('bypass', {agent:'reviewer', task:'Bypass', model:'other/model:high'});
|
|
386
|
+
}
|
|
387
|
+
return 'protected';
|
|
388
|
+
`,
|
|
389
|
+
};
|
|
390
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
391
|
+
const runtime = workflowRuntime();
|
|
392
|
+
assert.equal(await executeWorkflow(input, runtime.runs), "protected", "slot overflow must not consult inherited numeric getters on private slot arrays");
|
|
393
|
+
assert.deepEqual(runtime.calls, [], "an inherited slot getter must not leak mutable slot policy or admit a retry");
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
{
|
|
397
|
+
const poison = { workflowScript: "Set.prototype.has = () => false; WeakSet.prototype.has = () => true; return 'isolated';" };
|
|
398
|
+
applySubagentLaunchSlotDefaults("subagent", poison, roles);
|
|
399
|
+
assert.equal(await executeWorkflowInVm(poison, workflowRuntime().runs), "isolated");
|
|
400
|
+
|
|
401
|
+
const direct = { agent: "reviewer", task: "Host policy remains pristine", model: "other/model:high" };
|
|
402
|
+
const directReport = applySubagentLaunchSlotDefaults("subagent", direct, roles);
|
|
403
|
+
assert.equal(directReport.blocked[0]?.code, "reviewer-model-mismatch", "workflow VM prototype poisoning must not affect later host-side policy calls");
|
|
404
|
+
|
|
405
|
+
const nextWorkflow = { workflowScript: "return runs.run('review', {agent:'reviewer', task:'Next VM', model:'other/model:high'})" };
|
|
406
|
+
applySubagentLaunchSlotDefaults("subagent", nextWorkflow, roles);
|
|
407
|
+
const runtime = workflowRuntime();
|
|
408
|
+
await assert.rejects(executeWorkflowInVm(nextWorkflow, runtime.runs), (error) => error.code === "reviewer-model-policy-blocked");
|
|
409
|
+
assert.deepEqual(runtime.calls, [], "each top-level workflow VM must start with independent intrinsics");
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
{
|
|
413
|
+
const readsKey = "__piWebuiRunSnapshotReads";
|
|
414
|
+
const expectedModel = "openai-codex/gpt-5.6-sol:high";
|
|
415
|
+
const input = {
|
|
416
|
+
workflowScript: `
|
|
417
|
+
const reads = { agent: 0, model: 0 };
|
|
418
|
+
const target = { task: 'Stateful proxy review' };
|
|
419
|
+
const params = new Proxy(target, {
|
|
420
|
+
ownKeys() { return ['agent', 'task', 'model']; },
|
|
421
|
+
getOwnPropertyDescriptor() { return { enumerable: true, configurable: true }; },
|
|
422
|
+
get(source, property) {
|
|
423
|
+
if (property === 'agent') return ++reads.agent <= 2 ? 'reviewer' : 'worker';
|
|
424
|
+
if (property === 'model') return ++reads.model <= 3 ? ${JSON.stringify(expectedModel)} : 'other/model:high';
|
|
425
|
+
return source[property];
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
const result = await runs.run('review', params);
|
|
429
|
+
globalThis[${JSON.stringify(readsKey)}] = reads;
|
|
430
|
+
return result;
|
|
431
|
+
`,
|
|
432
|
+
};
|
|
433
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
434
|
+
const received = [];
|
|
435
|
+
const runtimeRuns = Object.freeze({
|
|
436
|
+
run(key, params) { received.push({ key, params }); return Promise.resolve({ key, ok: true }); },
|
|
437
|
+
all() { throw new Error("unexpected runs.all"); },
|
|
438
|
+
async status() { return {}; },
|
|
439
|
+
ref() { return ""; },
|
|
440
|
+
refs() { return ""; },
|
|
441
|
+
});
|
|
442
|
+
await executeWorkflow(input, runtimeRuns);
|
|
443
|
+
assert.deepEqual(globalThis[readsKey], { agent: 1, model: 1 }, "runs.run should read stateful policy fields only while creating its snapshot");
|
|
444
|
+
assert.equal(received[0]?.params.agent, "reviewer");
|
|
445
|
+
assert.equal(received[0]?.params.model, expectedModel, "runs.run must forward the same model snapshot that policy admitted");
|
|
446
|
+
assert.equal(Object.getOwnPropertyDescriptor(received[0]?.params, "model")?.get, undefined, "the forwarded runs.run snapshot must not retain a user getter");
|
|
447
|
+
delete globalThis[readsKey];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
{
|
|
451
|
+
const readsKey = "__piWebuiAllSnapshotReads";
|
|
452
|
+
const expectedModel = "openai-codex/gpt-5.6-sol:high";
|
|
453
|
+
const input = {
|
|
454
|
+
workflowScript: `
|
|
455
|
+
const reads = { agent: 0, model: 0 };
|
|
456
|
+
const item = {
|
|
457
|
+
key: 'review',
|
|
458
|
+
task: 'Stateful getter review',
|
|
459
|
+
get agent() { reads.agent += 1; return reads.agent === 1 ? 'reviewer' : 'worker'; },
|
|
460
|
+
get model() { reads.model += 1; return reads.model === 1 ? ${JSON.stringify(expectedModel)} : 'other/model:high'; },
|
|
461
|
+
};
|
|
462
|
+
const result = await runs.all([item]);
|
|
463
|
+
globalThis[${JSON.stringify(readsKey)}] = reads;
|
|
464
|
+
return result;
|
|
465
|
+
`,
|
|
466
|
+
};
|
|
467
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
468
|
+
const received = [];
|
|
469
|
+
const runtimeRuns = Object.freeze({
|
|
470
|
+
run() { throw new Error("unexpected runs.run"); },
|
|
471
|
+
all(items) { received.push(items); return Promise.resolve(items.map(({ key }) => ({ key, ok: true }))); },
|
|
472
|
+
async status() { return {}; },
|
|
473
|
+
ref() { return ""; },
|
|
474
|
+
refs() { return ""; },
|
|
475
|
+
});
|
|
476
|
+
await executeWorkflow(input, runtimeRuns);
|
|
477
|
+
const receivedItem = received[0]?.[0];
|
|
478
|
+
assert.deepEqual(globalThis[readsKey], { agent: 1, model: 1 }, "runs.all should snapshot each stateful item before policy evaluation");
|
|
479
|
+
assert.equal(receivedItem?.agent, "reviewer");
|
|
480
|
+
assert.equal(receivedItem?.model, expectedModel, "runs.all must forward the same item snapshot that policy admitted");
|
|
481
|
+
assert.equal(Object.getOwnPropertyDescriptor(receivedItem, "model")?.get, undefined, "the forwarded runs.all snapshot must not retain a user getter");
|
|
482
|
+
delete globalThis[readsKey];
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
{
|
|
486
|
+
const expiresAt = Date.now() + 1_000;
|
|
487
|
+
const input = { workflowScript: "return runs.run('review', {agent:'reviewer', task:'Delayed review', model:'other/model:high'})" };
|
|
488
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles, {
|
|
489
|
+
deviations: [{ id: "expiring-workflow-permit", role: "reviewer", occurrence: 1, requestedModel: "other/model:high", expiresAt }],
|
|
490
|
+
});
|
|
491
|
+
const runtime = workflowRuntime();
|
|
492
|
+
const realDateNow = Date.now;
|
|
493
|
+
Date.now = () => expiresAt + 1;
|
|
494
|
+
try {
|
|
495
|
+
await assert.rejects(executeWorkflow(input, runtime.runs), (error) => error.code === "reviewer-model-policy-blocked");
|
|
496
|
+
} finally {
|
|
497
|
+
Date.now = realDateNow;
|
|
498
|
+
}
|
|
499
|
+
assert.deepEqual(runtime.calls, [], "a leased permit that expires before use must not admit a delayed workflow child");
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
{
|
|
503
|
+
for (const method of ["run", "all"]) {
|
|
504
|
+
const call = method === "run"
|
|
505
|
+
? "try { runs.run('invalid', params); } catch {} return runs.run('valid', params);"
|
|
506
|
+
: "try { runs.all([{key:'invalid', ...params}]); } catch {} return runs.all([{key:'valid', ...params}]);";
|
|
507
|
+
const input = {
|
|
508
|
+
workflowScript: `const params = {agent:'reviewer', task:'Retry after validation', model:'other/model:high'}; ${call}`,
|
|
509
|
+
};
|
|
510
|
+
applySubagentLaunchSlotDefaults("subagent", input, roles, {
|
|
511
|
+
deviations: [{ id: `retry-${method}`, role: "reviewer", occurrence: 1, requestedModel: "other/model:high", expiresAt: unexpiredPermit() }],
|
|
512
|
+
});
|
|
513
|
+
const runtime = validatingWorkflowRuntime();
|
|
514
|
+
await executeWorkflow(input, runtime.runs);
|
|
515
|
+
assert.equal(runtime.calls.length, 1, `runs.${method} should retry after synchronous validation rejects the first call`);
|
|
516
|
+
const admitted = method === "run" ? runtime.calls[0] : runtime.calls[0].items[0];
|
|
517
|
+
assert.equal(admitted.model, "other/model:high", `runs.${method} should not spend occurrence or permit state on synchronous validation failure`);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
{
|
|
522
|
+
const input = { action: "status", id: "run-1" };
|
|
523
|
+
const report = applySubagentLaunchSlotDefaults("subagent", input, roles);
|
|
524
|
+
assert.deepEqual(report, {
|
|
525
|
+
applied: [],
|
|
526
|
+
unsupported: [],
|
|
527
|
+
blocked: [],
|
|
528
|
+
consumedDeviationIds: [],
|
|
529
|
+
}, "management calls must not receive launch defaults or policy decisions");
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
console.log("subagent-launch-policy.test.mjs passed");
|
|
@@ -28,7 +28,7 @@ assert.match(app, /const SUBAGENT_ASYNC_WIDGET_KEY = "subagent-async"[\s\S]*case
|
|
|
28
28
|
assert.match(app, /for \(const \[key, value\] of widgets\)[\s\S]*if \(key === SUBAGENT_ASYNC_WIDGET_KEY\) continue;/, "stale cached async-status widgets should remain hidden defensively");
|
|
29
29
|
assert.match(css, /\.subagent-source-badge[\s\S]*text-overflow: ellipsis[\s\S]*@media \(max-width: 720px\)/, "source badges should remain compact and responsive");
|
|
30
30
|
assert.match(html, /Managed and registered Pi agent runs[\s\S]*External agents/, "help should explain managed, registered, and external groups");
|
|
31
|
-
assert.match(html, /styles\.css\?v=
|
|
32
|
-
assert.match(worker, /pi-webui-pwa-
|
|
31
|
+
assert.match(html, /styles\.css\?v=142[\s\S]*app\.js\?v=172/, "browser assets should use the current subagent-observability revisions");
|
|
32
|
+
assert.match(worker, /pi-webui-pwa-v139/, "PWA cache identity should advance with subagent widget suppression");
|
|
33
33
|
|
|
34
34
|
console.log("subagent-observability-static.test.mjs passed");
|