@firstpick/pi-package-webui 0.7.3 → 0.7.5

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.
Files changed (34) hide show
  1. package/README.md +34 -20
  2. package/bin/pi-webui.mjs +332 -39
  3. package/index.ts +10 -1
  4. package/lib/git-workflow-preferences.mjs +91 -22
  5. package/lib/subagent-launch-slots.mjs +304 -0
  6. package/lib/trust-boundaries.mjs +1 -0
  7. package/lib/webui-output-mode.mjs +97 -0
  8. package/package.json +22 -22
  9. package/public/app.js +1629 -69
  10. package/public/fast-output-live.mjs +179 -0
  11. package/public/index.html +86 -12
  12. package/public/service-worker.js +3 -1
  13. package/public/styles.css +769 -37
  14. package/public/subagent-launch-slot-state.mjs +64 -0
  15. package/tests/chat-scroll-intent-static.test.mjs +59 -0
  16. package/tests/custom-message-markdown-static.test.mjs +15 -0
  17. package/tests/fast-mode-client-static.test.mjs +169 -0
  18. package/tests/fast-mode-output-work.test.mjs +69 -0
  19. package/tests/fast-mode-sse-harness.test.mjs +204 -0
  20. package/tests/fast-output-live.test.mjs +106 -0
  21. package/tests/fixtures/fake-pi.mjs +58 -0
  22. package/tests/fixtures/fast-mode-output-events.mjs +50 -0
  23. package/tests/footer-middle-truncation.test.mjs +2 -2
  24. package/tests/git-workflow-preferences.test.mjs +8 -2
  25. package/tests/http-endpoints-harness.test.mjs +74 -0
  26. package/tests/mobile-static.test.mjs +86 -15
  27. package/tests/remote-auth-settings-harness.test.mjs +1 -1
  28. package/tests/side-panel-resize-static.test.mjs +43 -0
  29. package/tests/subagent-launch-slot-state.test.mjs +36 -0
  30. package/tests/subagent-launch-slots-static.test.mjs +34 -0
  31. package/tests/subagent-launch-slots.test.mjs +143 -0
  32. package/tests/subagents-helper.test.mjs +46 -0
  33. package/tests/webui-output-mode.test.mjs +73 -0
  34. package/webui-rpc-helper.mjs +37 -9
@@ -0,0 +1,106 @@
1
+ import assert from "node:assert/strict";
2
+ import {
3
+ createFastOutputLiveState,
4
+ createSustainedFlushScheduler,
5
+ fastOutputLiveTextAndThinking,
6
+ reduceFastOutputLiveEvent,
7
+ seedFastOutputLiveState,
8
+ shouldConsumeFastOutputLiveEvent,
9
+ } from "../public/fast-output-live.mjs";
10
+
11
+ class FakeClock {
12
+ #now = 0;
13
+ #nextId = 1;
14
+ #timers = new Map();
15
+
16
+ now = () => this.#now;
17
+ setTimer = (callback, delay) => {
18
+ const id = this.#nextId++;
19
+ this.#timers.set(id, { callback, at: this.#now + delay });
20
+ return id;
21
+ };
22
+ clearTimer = (id) => this.#timers.delete(id);
23
+ advance(ms) {
24
+ this.#now += ms;
25
+ let due = [...this.#timers.entries()].filter(([, timer]) => timer.at <= this.#now).sort((a, b) => a[1].at - b[1].at);
26
+ while (due.length) {
27
+ for (const [id, timer] of due) {
28
+ this.#timers.delete(id);
29
+ timer.callback();
30
+ }
31
+ due = [...this.#timers.entries()].filter(([, timer]) => timer.at <= this.#now).sort((a, b) => a[1].at - b[1].at);
32
+ }
33
+ }
34
+ }
35
+
36
+ let state = createFastOutputLiveState();
37
+ let reduction = reduceFastOutputLiveEvent(state, { type: "message_update", assistantMessageEvent: { type: "text_delta", delta: "A🦄" } });
38
+ state = reduction.state;
39
+ assert.equal(reduction.changed, true);
40
+ assert.equal(state.text, "A🦄", "raw Unicode text deltas should be retained exactly");
41
+
42
+ reduction = reduceFastOutputLiveEvent(state, { type: "message_update", assistantMessageEvent: { type: "thinking_delta", delta: "plan\n" } });
43
+ state = reduction.state;
44
+ assert.equal(state.thinking, "plan\n", "thinking deltas should use a separate raw accumulator");
45
+
46
+ reduction = reduceFastOutputLiveEvent(state, { type: "message_update", assistantMessageEvent: { type: "toolcall_delta", delta: "{\"path\":", toolCall: { id: "tool-1", name: "read" } } });
47
+ state = reduction.state;
48
+ reduction = reduceFastOutputLiveEvent(reduction.state, { type: "message_update", assistantMessageEvent: { type: "toolcall_end", toolCall: { id: "tool-1", name: "read", arguments: { path: "README.md" } } } });
49
+ assert.equal(reduction.state.toolCall.id, "tool-1");
50
+ assert.equal(reduction.state.toolCall.name, "read");
51
+ assert.equal(reduction.state.toolCall.arguments, '{"path":"README.md"}');
52
+ assert.equal(reduction.state.toolCall.complete, true, "self-contained tool end should preserve direct completion data");
53
+
54
+ reduction = reduceFastOutputLiveEvent(reduction.state, { type: "message_update", assistantMessageEvent: { type: "text_end", content: "final ✅" } });
55
+ assert.equal(reduction.state.text, "final ✅", "self-contained text ends should reconcile from direct compact fields");
56
+ assert.equal(reduceFastOutputLiveEvent(reduction.state, { type: "message_update", assistantMessageEvent: { type: "error", errorMessage: "preserve normal error handling" } }).changed, false, "unrecognized/error shapes should remain available to normal diagnostics");
57
+
58
+ // A1: seed normal live content before compact deltas replace its DOM bubble.
59
+ const seededFromNormal = seedFastOutputLiveState({ text: "before switch", thinking: "reasoning before switch" });
60
+ assert.deepEqual(fastOutputLiveTextAndThinking(seededFromNormal), { text: "before switch", thinking: "reasoning before switch" }, "normal live text/thinking should seed one compact live state");
61
+ const continuedCompact = reduceFastOutputLiveEvent(seededFromNormal, { type: "message_update", assistantMessageEvent: { type: "text_delta", delta: " + compact delta" } });
62
+ assert.equal(continuedCompact.state.text, "before switch + compact delta", "compact deltas should continue the seeded normal text in one state");
63
+
64
+ // A2: snapshot compact state before normal rich rendering resumes.
65
+ assert.deepEqual(fastOutputLiveTextAndThinking(continuedCompact.state), { text: "before switch + compact delta", thinking: "reasoning before switch" }, "compact live text/thinking should transfer intact to normal mode");
66
+
67
+ // A3: recognized empty compact end variants have stripped snapshots, so consume
68
+ // them rather than falling into normal handlers that expect those snapshots.
69
+ const emptyCompactTextEnd = reduceFastOutputLiveEvent(createFastOutputLiveState(), { type: "message_update", assistantMessageEvent: { type: "text_end", content: "", delta: "" } });
70
+ const emptyCompactThinkingEnd = reduceFastOutputLiveEvent(createFastOutputLiveState(), { type: "message_update", assistantMessageEvent: { type: "thinking_end", content: "", delta: "" } });
71
+ assert.equal(emptyCompactTextEnd.changed, false, "empty self-contained ends should not request a DOM write");
72
+ assert.equal(emptyCompactTextEnd.kind, "text-end");
73
+ assert.equal(emptyCompactThinkingEnd.changed, false, "empty thinking ends should not request a DOM write");
74
+ assert.equal(emptyCompactThinkingEnd.kind, "thinking-end");
75
+ assert.equal(shouldConsumeFastOutputLiveEvent(emptyCompactTextEnd), true, "recognized empty text end variants should be consumed safely");
76
+ assert.equal(shouldConsumeFastOutputLiveEvent(emptyCompactThinkingEnd), true, "recognized empty thinking end variants should be consumed safely");
77
+ assert.equal(shouldConsumeFastOutputLiveEvent({ changed: false, kind: "ignored" }), false, "unknown compact shapes should still fall through to normal diagnostics");
78
+
79
+ const clock = new FakeClock();
80
+ const flushes = [];
81
+ const scheduler = createSustainedFlushScheduler({
82
+ flush: () => flushes.push(clock.now()),
83
+ now: clock.now,
84
+ setTimer: clock.setTimer,
85
+ clearTimer: clock.clearTimer,
86
+ });
87
+
88
+ assert.equal(scheduler.request(), true, "the first pending output should flush immediately for liveness");
89
+ assert.deepEqual(flushes, [0]);
90
+ scheduler.request();
91
+ clock.advance(99);
92
+ assert.deepEqual(flushes, [0], "sustained output must wait for the 100 ms coalescing boundary");
93
+ clock.advance(1);
94
+ assert.deepEqual(flushes, [0, 100]);
95
+ scheduler.request();
96
+ clock.advance(25);
97
+ assert.equal(scheduler.flushNow(), true, "terminal boundaries synchronously flush pending output");
98
+ assert.deepEqual(flushes, [0, 100, 125]);
99
+ clock.advance(200);
100
+ assert.deepEqual(flushes, [0, 100, 125], "a terminal flush cancels its pending timer");
101
+ scheduler.request();
102
+ scheduler.cancel();
103
+ clock.advance(200);
104
+ assert.deepEqual(flushes, [0, 100, 125], "reset/tab/mode cancellation drops pending compact work");
105
+
106
+ console.log("fast-output-live.test.mjs passed");
@@ -307,6 +307,63 @@ function handleDocumentArtifactFixturePrompt(command, base) {
307
307
  return true;
308
308
  }
309
309
 
310
+ function fastModeMessageUpdate(delta, accumulated) {
311
+ const partial = { role: "assistant", content: [{ type: "text", text: accumulated }] };
312
+ return {
313
+ type: "message_update",
314
+ message: partial,
315
+ assistantMessageEvent: { type: "text_delta", delta, contentIndex: 0, partial },
316
+ };
317
+ }
318
+
319
+ function runFastModeFixtureFlow({ barrierOnly = false } = {}) {
320
+ const toolCallId = "fast-mode-tool";
321
+ const firstText = "fast mode first delta ";
322
+ const finalText = `${firstText}and final delta`;
323
+ const finish = () => {
324
+ emitEvent({ type: "message_end", message: { role: "assistant", content: [{ type: "text", text: finalText }] } });
325
+ emitEvent({ type: "agent_end" });
326
+ };
327
+ emitEvent({ type: "agent_start" });
328
+ emitEvent({ type: "message_start", message: { role: "assistant" } });
329
+ emitEvent(fastModeMessageUpdate(firstText, firstText));
330
+ if (barrierOnly) {
331
+ setTimeout(finish, 180);
332
+ return;
333
+ }
334
+ setTimeout(() => {
335
+ emitEvent({ type: "tool_execution_start", toolCallId, toolName: "read", args: { path: "fast-mode.txt" } });
336
+ emitEvent({ type: "tool_execution_update", toolCallId, toolName: "read", partialResult: { content: [{ type: "text", text: "intermediate tool work" }] } });
337
+ emitEvent({ type: "tool_execution_end", toolCallId, toolName: "read", isError: false, result: { content: [{ type: "text", text: "final tool result" }] } });
338
+ emitEvent({ type: "pi_stderr", text: "fast mode fixture diagnostic" });
339
+ emitEvent({ type: "extension_ui_request", id: "fast-mode-dialog", method: "confirm", title: "Fast mode dialog", message: "Preserve this dialog" });
340
+ emitEvent(fastModeMessageUpdate("and final delta", finalText));
341
+ finish();
342
+ }, 20);
343
+ }
344
+
345
+ function runFastModeHistoryFlow() {
346
+ let accumulated = "";
347
+ emitEvent({ type: "agent_start" });
348
+ emitEvent({ type: "message_start", message: { role: "assistant" } });
349
+ for (let index = 0; index < 512; index += 1) {
350
+ const delta = `h${String(index).padStart(3, "0")}`;
351
+ accumulated += delta;
352
+ emitEvent(fastModeMessageUpdate(delta, accumulated));
353
+ }
354
+ emitEvent({ type: "message_end", message: { role: "assistant", content: [{ type: "text", text: accumulated }] } });
355
+ emitEvent({ type: "agent_end" });
356
+ }
357
+
358
+ function handleFastModeFixturePrompt(command, base) {
359
+ const message = String(command.message || "").trim();
360
+ if (!["fixture fast mode flow", "fixture fast mode barrier", "fixture fast mode history"].includes(message)) return false;
361
+ respond({ ...base, data: { output: "fast mode fixture accepted" } });
362
+ if (message.endsWith("history")) runFastModeHistoryFlow();
363
+ else runFastModeFixtureFlow({ barrierOnly: message.endsWith("barrier") });
364
+ return true;
365
+ }
366
+
310
367
  function handleTransportFixturePrompt(command, base) {
311
368
  const message = String(command.message || "").trim();
312
369
  if (message === "fixture stderr diagnostic") {
@@ -510,6 +567,7 @@ rl.on("line", (line) => {
510
567
  }
511
568
  case "prompt":
512
569
  if (handleWebuiHelperPrompt(command, base)) return;
570
+ if (handleFastModeFixturePrompt(command, base)) return;
513
571
  if (handleTransportFixturePrompt(command, base)) return;
514
572
  if (handleSubagentFixturePrompt(command, base)) return;
515
573
  if (handleDocumentArtifactFixturePrompt(command, base)) return;
@@ -0,0 +1,50 @@
1
+ const DELTA_COUNT = 512;
2
+ const DELTA_BYTES = 32;
3
+
4
+ function fixedDelta(index) {
5
+ return `d${String(index).padStart(4, "0")}${"x".repeat(DELTA_BYTES - 5)}`;
6
+ }
7
+
8
+ function assistantSnapshot(text) {
9
+ return {
10
+ role: "assistant",
11
+ content: [{ type: "text", text }],
12
+ };
13
+ }
14
+
15
+ export function createFastModeOutputEvents() {
16
+ const events = [
17
+ { type: "agent_start", tabId: "fast-mode-trace" },
18
+ { type: "tool_execution_start", tabId: "fast-mode-trace", toolCallId: "trace-tool", toolName: "read", args: { path: "trace.txt" } },
19
+ { type: "tool_execution_end", tabId: "fast-mode-trace", toolCallId: "trace-tool", toolName: "read", isError: false, result: { content: [{ type: "text", text: "trace result" }] } },
20
+ { type: "pi_stdout_parse_error", tabId: "fast-mode-trace", error: "trace diagnostic" },
21
+ { type: "message_start", tabId: "fast-mode-trace", message: { role: "assistant" } },
22
+ ];
23
+ let accumulated = "";
24
+ for (let index = 0; index < DELTA_COUNT; index += 1) {
25
+ const delta = fixedDelta(index);
26
+ accumulated += delta;
27
+ const snapshot = assistantSnapshot(accumulated);
28
+ events.push({
29
+ type: "message_update",
30
+ tabId: "fast-mode-trace",
31
+ contentIndex: 0,
32
+ message: snapshot,
33
+ assistantMessageEvent: {
34
+ type: "text_delta",
35
+ delta,
36
+ contentIndex: 0,
37
+ partial: assistantSnapshot(accumulated),
38
+ },
39
+ });
40
+ }
41
+ events.push(
42
+ { type: "message_end", tabId: "fast-mode-trace", message: assistantSnapshot(accumulated) },
43
+ { type: "agent_end", tabId: "fast-mode-trace" },
44
+ );
45
+ return events;
46
+ }
47
+
48
+ export function fixedFastModeTraceMetadata() {
49
+ return { deltaCount: DELTA_COUNT, deltaBytes: DELTA_BYTES, finalBytes: DELTA_COUNT * DELTA_BYTES };
50
+ }
@@ -111,8 +111,8 @@ assert.match(
111
111
  );
112
112
  assert.match(
113
113
  css,
114
- /\.middle-truncate-start \{[\s\S]*?min-width:\s*6ch;[\s\S]*?text-overflow:\s*ellipsis[\s\S]*?\.middle-truncate-end \{[\s\S]*?flex:\s*0 0 auto/,
115
- "responsive styling should shrink the prefix while keeping the suffix fixed",
114
+ /\.middle-truncate-start \{[\s\S]*?flex:\s*0 1 auto;[\s\S]*?min-width:\s*6ch;[\s\S]*?text-overflow:\s*ellipsis[\s\S]*?\.middle-truncate-end \{[\s\S]*?flex:\s*0 0 auto/,
115
+ "responsive styling should keep split path parts contiguous until the prefix must shrink, then preserve the suffix",
116
116
  );
117
117
 
118
118
  console.log("footer-middle-truncation.test.mjs passed");
@@ -31,14 +31,18 @@ const settingsFile = path.join(root, "settings.json");
31
31
  try {
32
32
  await writeFile(settingsFile, `${JSON.stringify({ version: 1, remoteAuthEnabled: true }, null, 2)}\n`, "utf8");
33
33
  const migrated = await readWebuiSettings(settingsFile);
34
- assert.equal(migrated.version, 3);
34
+ assert.equal(migrated.version, 4);
35
35
  assert.equal(migrated.remoteAuthEnabled, true, "legacy Remote PIN state should survive schema migration");
36
+ assert.equal(migrated.outputModeDefault, "normal", "legacy settings should default browser output to normal");
36
37
  assert.equal(isGitWorkflowSetupComplete(migrated.gitWorkflow), false);
37
38
  assert.equal(migrated.resourceDefaults.tools.enabledTools, null, "legacy settings should inherit Pi's normal tool defaults");
38
39
  assert.equal(migrated.resourceDefaults.skills.enabledSkills, null, "legacy settings should inherit Pi's normal skill defaults");
39
40
  assert.equal(migrated.gitWorkflow.stagingPolicy, "review");
40
41
  assert.equal(migrated.gitWorkflow.generation.thinkingLevel, "low");
41
42
 
43
+ await writeFile(settingsFile, `${JSON.stringify({ version: 4, remoteAuthEnabled: true, outputModeDefault: "unsupported" }, null, 2)}\n`, "utf8");
44
+ assert.equal((await readWebuiSettings(settingsFile)).outputModeDefault, "normal", "invalid persisted output modes must fail closed to normal");
45
+
42
46
  const saved = await writeGitWorkflowPreferences({
43
47
  generation: { provider: "fake", modelId: "fake-model", thinkingLevel: "off", unavailablePolicy: "ask" },
44
48
  commit: { language: "de", defaultVariant: "long", scope: "required" },
@@ -53,6 +57,7 @@ try {
53
57
  assert.equal(saved.stagingPolicy, "preserve");
54
58
 
55
59
  await writeWebuiSettings({
60
+ outputModeDefault: "compact-v1",
56
61
  resourceDefaults: {
57
62
  tools: { enabledTools: ["read", " write ", "read", ""] },
58
63
  skills: { enabledSkills: ["repo-explorer", "code-security"] },
@@ -65,8 +70,9 @@ try {
65
70
  assert.equal(partiallyUpdated.deliveryMode, "current");
66
71
 
67
72
  const persisted = JSON.parse(await readFile(settingsFile, "utf8"));
68
- assert.equal(persisted.version, 3);
73
+ assert.equal(persisted.version, 4);
69
74
  assert.equal(persisted.remoteAuthEnabled, true);
75
+ assert.equal(persisted.outputModeDefault, "compact-v1", "output-mode default should persist beside existing Web UI settings");
70
76
  assert.equal(persisted.gitWorkflow.generation.provider, "fake");
71
77
  assert.deepEqual(persisted.resourceDefaults.tools.enabledTools, ["read", "write"], "global tool defaults should be normalized and deduplicated");
72
78
  assert.deepEqual(persisted.resourceDefaults.skills.enabledSkills, ["repo-explorer", "code-security"], "global skill defaults should persist beside other Web UI settings");
@@ -258,6 +258,15 @@ try {
258
258
  assert.equal(gzipResponse.headers.get("content-encoding"), "gzip", "styles.css should fall back to gzip");
259
259
  await gzipResponse.arrayBuffer();
260
260
 
261
+ // app.js statically imports the fast-output helper at startup. Verify the
262
+ // real server serves it so an omitted allowlist entry cannot disable the UI.
263
+ const fastOutputModuleResponse = await fetch(`http://127.0.0.1:${port}/fast-output-live.mjs`, {
264
+ signal: AbortSignal.timeout(5_000),
265
+ });
266
+ assert.equal(fastOutputModuleResponse.status, 200, "fast-output-live.mjs must be served for the Web UI entry point");
267
+ assert.match(fastOutputModuleResponse.headers.get("content-type") || "", /text\/javascript/, "fast-output-live.mjs should use a JavaScript MIME type");
268
+ assert.equal(await fastOutputModuleResponse.text(), await readFile(join(root, "public", "fast-output-live.mjs"), "utf8"), "served fast-output-live.mjs must match the source module");
269
+
261
270
  // The browser voice loop is dynamically imported by app.js; a missing static
262
271
  // allowlist entry would 404 the module and silently disable voice mode.
263
272
  const voiceModuleResponse = await fetch(`http://127.0.0.1:${port}/voice-conversation.mjs`, {
@@ -305,6 +314,65 @@ try {
305
314
  const tabId = tabList[0].id;
306
315
  assert.ok(tabId, "tab should have an id");
307
316
 
317
+ const initialUserLaunchSlots = await request("127.0.0.1", `/api/subagents/config?tab=${encodeURIComponent(tabId)}&scope=user`);
318
+ assert.equal(initialUserLaunchSlots.status, 200, `user launch-slot config should load: ${initialUserLaunchSlots.body?.error || ""}`);
319
+ assert.equal(initialUserLaunchSlots.body?.data?.reloadRequired, false);
320
+ assert.equal(initialUserLaunchSlots.body?.data?.roleMetadata?.length, 8, "launch-slot config should expose the documented builtin role metadata");
321
+ assert.deepEqual(initialUserLaunchSlots.body?.data?.roles?.reviewer, [{ id: "reviewer:base", model: null, thinking: null }], "launch-slot defaults should materialize a stable base slot");
322
+ assert.deepEqual(initialUserLaunchSlots.body?.data?.modelThinkingLevels?.["fake/fake-model"], ["off"], "the active tab model registry should drive supported thinking choices");
323
+
324
+ const userLaunchDraft = JSON.parse(JSON.stringify(initialUserLaunchSlots.body.data.roles));
325
+ userLaunchDraft.reviewer[0] = { id: "reviewer:base", model: "fake/fake-model", thinking: "off" };
326
+ userLaunchDraft.reviewer.push({ id: "reviewer-secondary", model: "fake/fake-model", thinking: "off" });
327
+ const savedUserLaunchSlots = await request("127.0.0.1", "/api/subagents/config", {
328
+ method: "POST",
329
+ body: { tab: tabId, scope: "user", revision: initialUserLaunchSlots.body.data.revision, roles: userLaunchDraft },
330
+ });
331
+ assert.equal(savedUserLaunchSlots.status, 200, `user launch-slot config should save: ${savedUserLaunchSlots.body?.error || ""}`);
332
+ assert.equal(savedUserLaunchSlots.body?.data?.saved, true);
333
+ assert.equal(savedUserLaunchSlots.body?.data?.changed, true);
334
+ assert.equal(savedUserLaunchSlots.body?.data?.reloadRequired, true, "a changed save must require active-tab reload before helper guidance changes");
335
+ assert.deepEqual(savedUserLaunchSlots.body?.data?.roles?.reviewer, userLaunchDraft.reviewer, "same-role launch slots must retain independent explicit model specs");
336
+ const persistedLaunchSlots = JSON.parse(await readFile(settingsFile, "utf8"));
337
+ assert.equal(persistedLaunchSlots.version, 5, "launch-slot persistence should upgrade the private WebUI settings envelope");
338
+ assert.deepEqual(persistedLaunchSlots.subagentLaunchSlots?.user?.roles?.reviewer, userLaunchDraft.reviewer);
339
+
340
+ const inheritedProjectLaunchSlots = await request("127.0.0.1", `/api/subagents/config?tab=${encodeURIComponent(tabId)}&scope=project`);
341
+ assert.equal(inheritedProjectLaunchSlots.status, 200);
342
+ assert.equal(inheritedProjectLaunchSlots.body?.data?.inherited, true, "project scope must inherit user launch slots until customized");
343
+ assert.deepEqual(inheritedProjectLaunchSlots.body?.data?.roles?.reviewer, userLaunchDraft.reviewer);
344
+ const projectLaunchDraft = JSON.parse(JSON.stringify(inheritedProjectLaunchSlots.body.data.roles));
345
+ projectLaunchDraft.reviewer[0] = { id: "reviewer:base", model: null, thinking: null };
346
+ const savedProjectLaunchSlots = await request("127.0.0.1", "/api/subagents/config", {
347
+ method: "POST",
348
+ body: { tab: tabId, scope: "project", revision: inheritedProjectLaunchSlots.body.data.revision, roles: projectLaunchDraft },
349
+ });
350
+ assert.equal(savedProjectLaunchSlots.status, 200);
351
+ assert.equal(savedProjectLaunchSlots.body?.data?.inherited, false, "saving project roles should create an explicit project entry");
352
+ assert.equal(savedProjectLaunchSlots.body?.data?.roles?.reviewer?.[0]?.model, null);
353
+ const resetProjectLaunchSlots = await request("127.0.0.1", "/api/subagents/config", {
354
+ method: "POST",
355
+ body: { tab: tabId, scope: "project", revision: savedProjectLaunchSlots.body.data.revision, inherit: true },
356
+ });
357
+ assert.equal(resetProjectLaunchSlots.status, 200);
358
+ assert.equal(resetProjectLaunchSlots.body?.data?.inherited, true, "project inherit reset should remove only the explicit project entry");
359
+ assert.deepEqual(resetProjectLaunchSlots.body?.data?.roles?.reviewer, userLaunchDraft.reviewer);
360
+
361
+ const settingsBeforeStaleLaunchSave = await readFile(settingsFile, "utf8");
362
+ const staleLaunchSave = await request("127.0.0.1", "/api/subagents/config", {
363
+ method: "POST",
364
+ body: { tab: tabId, scope: "user", revision: initialUserLaunchSlots.body.data.revision, roles: userLaunchDraft },
365
+ });
366
+ assert.equal(staleLaunchSave.status, 409, "stale launch-slot revisions must not overwrite current settings");
367
+ assert.equal(await readFile(settingsFile, "utf8"), settingsBeforeStaleLaunchSave, "a rejected stale launch-slot save must leave the settings file byte-for-byte unchanged");
368
+ const invalidLaunchDraft = JSON.parse(JSON.stringify(userLaunchDraft));
369
+ invalidLaunchDraft.reviewer[0].model = "fake/fake-model:high";
370
+ const invalidLaunchSave = await request("127.0.0.1", "/api/subagents/config", {
371
+ method: "POST",
372
+ body: { tab: tabId, scope: "user", revision: savedUserLaunchSlots.body.data.revision, roles: invalidLaunchDraft },
373
+ });
374
+ assert.equal(invalidLaunchSave.status, 400, "thinking-suffixed persisted model IDs must be rejected on save");
375
+
308
376
  const malformedInlineImage = await request("127.0.0.1", "/api/prompt", {
309
377
  method: "POST",
310
378
  body: { tab: tabId, message: "malformed inline image fixture", images: [{ type: "image", mimeType: "image/png", data: "137,80,78,71,13,10,26,10" }] },
@@ -1849,6 +1917,12 @@ try {
1849
1917
  });
1850
1918
  assert.equal(remoteFileSave.status, 403, "file saves must be localhost-only");
1851
1919
 
1920
+ const remoteLaunchSlotSave = await request(lan, "/api/subagents/config", {
1921
+ method: "POST",
1922
+ body: { tab: tabId, scope: "user", revision: "remote-request-must-not-read", roles: {} },
1923
+ });
1924
+ assert.equal(remoteLaunchSlotSave.status, 403, "launch-slot saves must be localhost-only before the request body is processed");
1925
+
1852
1926
  const remoteFileOpenDefault = await request(lan, "/api/files/open-default", {
1853
1927
  method: "POST",
1854
1928
  body: { tab: tabId, path: viewerRelative },