@firstpick/pi-package-webui 0.8.0 → 0.8.1
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 +22 -5
- package/bin/pi-webui.mjs +434 -100
- package/lib/npm-command.mjs +81 -0
- package/lib/queue-mutation.mjs +6 -0
- package/lib/workspace-files-live-watcher.mjs +138 -0
- package/package.json +8 -3
- package/public/app.js +2816 -314
- package/public/index.html +112 -27
- package/public/mobile-shell-state.mjs +166 -0
- package/public/service-worker.js +60 -13
- package/public/styles.css +1049 -371
- package/public/subagent-gate-visibility.mjs +16 -0
- package/public/subagent-launch-slot-state.mjs +16 -0
- package/public/transcript-renderer.mjs +433 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/interaction-continuity.spec.mjs +739 -0
- package/tests/browser/mobile-foundation.spec.mjs +352 -0
- package/tests/browser/optimistic-prompt.spec.mjs +130 -0
- package/tests/chat-scroll-intent-static.test.mjs +6 -1
- package/tests/codex-fast-mode-static.test.mjs +8 -5
- package/tests/compact-sections-static.test.mjs +20 -2
- package/tests/compaction-mutation-contract.test.mjs +18 -4
- package/tests/compaction-static.test.mjs +1 -0
- package/tests/completion-signal-contract.test.mjs +13 -2
- package/tests/fast-mode-client-static.test.mjs +7 -4
- package/tests/fixtures/fake-pi.mjs +181 -2
- package/tests/git-panel-gitignore-static.test.mjs +104 -0
- package/tests/http-endpoints-harness.test.mjs +228 -2
- package/tests/interaction-state-stability-static.test.mjs +254 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +55 -0
- package/tests/mobile-foundation-static.test.mjs +69 -0
- package/tests/mobile-phone-experience-static.test.mjs +65 -0
- package/tests/mobile-shell-state.test.mjs +69 -0
- package/tests/mobile-static.test.mjs +244 -38
- package/tests/mobile-transcript-cache-characterization.test.mjs +34 -0
- package/tests/npm-command.test.mjs +64 -1
- package/tests/open-issue-wizard-static.test.mjs +2 -1
- package/tests/queue-edit-reorder-static.test.mjs +9 -1
- package/tests/queue-mutation-contract.test.mjs +22 -0
- package/tests/service-worker-lifecycle.test.mjs +120 -0
- package/tests/sse-backpressure-harness.test.mjs +98 -0
- package/tests/streaming-ui-coupling.test.mjs +7 -1
- package/tests/subagent-gate-visibility.test.mjs +18 -2
- package/tests/subagent-launch-slot-state.test.mjs +32 -0
- package/tests/subagent-launch-slots-static.test.mjs +8 -2
- package/tests/subagents-helper.test.mjs +90 -0
- package/tests/terminal-tab-workspace-static.test.mjs +1 -1
- package/tests/update-commands.test.mjs +4 -0
- package/tests/workspace-files-live-updates-static.test.mjs +76 -0
- package/tests/workspace-files-live-watcher.test.mjs +95 -0
- package/webui-rpc-helper.mjs +175 -3
|
@@ -19,6 +19,9 @@ function functionSource(source, name) {
|
|
|
19
19
|
const context = vm.createContext({ console });
|
|
20
20
|
vm.runInContext(`
|
|
21
21
|
const TAB_ACTIVITY_IDLE_RECONCILE_GRACE_MS = 1200;
|
|
22
|
+
// The production server imports randomUUID from node:crypto; keep the
|
|
23
|
+
// extracted lifecycle contract deterministic while exercising run creation.
|
|
24
|
+
function randomUUID() { return "run_12345678"; }
|
|
22
25
|
function pendingExtensionUiRequests() { return []; }
|
|
23
26
|
function patchTabState(tab, patch) { tab.lastState = { ...(tab.lastState || {}), ...patch }; }
|
|
24
27
|
function rememberTabState(tab, state) { tab.lastState = state; }
|
|
@@ -27,6 +30,7 @@ vm.runInContext(`
|
|
|
27
30
|
${functionSource(server, "tabActivitySnapshot")}
|
|
28
31
|
${functionSource(server, "markTabWorking")}
|
|
29
32
|
${functionSource(server, "markTabDone")}
|
|
33
|
+
${functionSource(server, "markTabFailed")}
|
|
30
34
|
${functionSource(server, "markTabIdle")}
|
|
31
35
|
${functionSource(server, "stateHasVisibleWork")}
|
|
32
36
|
${functionSource(server, "activityRecentlyStarted")}
|
|
@@ -84,11 +88,18 @@ contract.event(compactionTab, { type: "compaction_end" });
|
|
|
84
88
|
assert.equal(compactionTab.activity.status, "idle");
|
|
85
89
|
assert.equal(compactionTab.activity.completionSerial, 0, "standalone compaction must not emit agent completion");
|
|
86
90
|
|
|
91
|
+
const failedTurnTab = contract.createTab();
|
|
92
|
+
contract.event(failedTurnTab, { type: "agent_start" });
|
|
93
|
+
contract.event(failedTurnTab, { type: "message_end", message: { role: "assistant", stopReason: "error" } });
|
|
94
|
+
contract.event(failedTurnTab, { type: "agent_settled" });
|
|
95
|
+
assert.equal(failedTurnTab.activity.status, "failed", "a terminal assistant error must remain distinct from successful completion");
|
|
96
|
+
assert.equal(failedTurnTab.activity.completionSerial, 1);
|
|
97
|
+
|
|
87
98
|
const failedProcessTab = contract.createTab();
|
|
88
99
|
contract.event(failedProcessTab, { type: "agent_start" });
|
|
89
100
|
contract.event(failedProcessTab, { type: "pi_process_error" });
|
|
90
|
-
assert.equal(failedProcessTab.activity.status, "
|
|
91
|
-
assert.equal(failedProcessTab.activity.completionSerial,
|
|
101
|
+
assert.equal(failedProcessTab.activity.status, "failed");
|
|
102
|
+
assert.equal(failedProcessTab.activity.completionSerial, 1, "a failed process must create one failed completion, not a successful one");
|
|
92
103
|
|
|
93
104
|
assert.match(app, /case "agent_settled":[\s\S]*?notifyAgentDone\(/, "the browser should notify only from settlement");
|
|
94
105
|
assert.doesNotMatch(functionSource(app, "handleInactiveTabEvent"), /event\.type === "agent_end"[\s\S]*?notifyAgentDone/, "background low-level run ends must not notify");
|
|
@@ -84,7 +84,8 @@ assert.doesNotMatch(compactUpdate, /event\.message|assistantMessageEvent\.partia
|
|
|
84
84
|
assert.match(compactUpdate, /reduceFastOutputLiveEvent\(compactLiveState, event\)/, "compact deltas should use the pure reducer");
|
|
85
85
|
assert.match(compactUpdate, /shouldConsumeFastOutputLiveEvent\(reduced\)/, "recognized compact empty end variants should be consumed instead of reaching normal handlers with stripped snapshots");
|
|
86
86
|
assert.match(helper, /function shouldConsumeFastOutputLiveEvent\(reduction = \{\}\)[\s\S]*?"text-end"[\s\S]*?"thinking-end"[\s\S]*?"toolcall-end"/, "the reducer policy should consume only recognized compact end variants when no DOM state changes");
|
|
87
|
-
assert.match(compactFlush,
|
|
87
|
+
assert.match(compactFlush, /transcriptRenderer\.updateTextSurface\(\{[\s\S]*?surface: compactTextNode,[\s\S]*?text: compactLiveState\.text/, "compact assistant text must update through the stable transcript text surface");
|
|
88
|
+
assert.doesNotMatch(compactFlush, /compactTextNode\.textContent\s*=/, "compact assistant streaming must not replace its selected text node");
|
|
88
89
|
assert.match(compactThinkingBubble, /title: "thinking \(live\)"[\s\S]*?compactThinkingAggregate: true[\s\S]*?compactThinkingKey: "live"[\s\S]*?compactThinkingDefaultExpanded: true[\s\S]*?make\("div", "markdown-body thinking-text compact-live-thinking"\)/, "compact live thinking should use one expanded-by-default aggregate disclosure with a stable key and established Markdown styles");
|
|
89
90
|
assert.match(resetCompactLiveOutput, /clearCompactThinkingDisclosureState\("live"\)/, "a new compact stream should clear any explicit live override and restore its expanded default");
|
|
90
91
|
assert.match(compactFlush, /compactThinkingNode\?\._rawThinkingText !== compactLiveState\.thinking[\s\S]*?renderThinkingMarkdown\(compactThinkingNode, compactLiveState\.thinking\)/, "compact live thinking should preserve Markdown formatting");
|
|
@@ -92,7 +93,7 @@ assert.doesNotMatch(compactFlush, /compactThinkingNode\.textContent|renderStream
|
|
|
92
93
|
assert.doesNotMatch(compactToolShell, /normalizeToolExecution|toolExecutionRenderSignature|renderToolExecution|handleToolExecutionUpdate|JSON\.stringify/, "compact tool shells must defer rich bodies and raw serialization");
|
|
93
94
|
assert.match(app, /case "tool_execution_update":\s+if \(!compactOutputActive\(\)\) handleToolExecutionUpdate\(event\);/, "compact mode should not build intermediate rich tool updates");
|
|
94
95
|
assert.match(app, /case "tool_execution_end":[\s\S]*?compactLiveScheduler\.flushNow\(\)[\s\S]*?renderCompactToolShell\(event, \{ complete: true \}\)[\s\S]*?finishCompactLiveOutput\(tabContext\)/, "compact tool completion should remain lightweight and request final reconciliation");
|
|
95
|
-
assert.match(resetStream, /resetCompactLiveOutput\(\)/, "reset and tab changes should cancel compact pending work");
|
|
96
|
+
assert.match(resetStream, /resetCompactLiveOutput\(\{ remove: !preserveCompact \}\)/, "reset and tab changes should cancel compact pending work while exact compact settlement may retain its adopted owner");
|
|
96
97
|
assert.match(app, /case "message_end": \{\s+if \(compactOutputActive\(\)\) finishCompactLiveOutput\(tabContext\);/, "message ends should synchronously flush compact output before reconciliation");
|
|
97
98
|
assert.match(app, /case "agent_end":\s+if \(compactOutputActive\(\)\) finishCompactLiveOutput\(tabContext\);/, "agent ends should synchronously flush compact output before reconciliation");
|
|
98
99
|
assert.match(compactTranscript, /message\.role !== "assistant"[\s\S]*?appendMarkdown\(body, output \|\| "_\[non-text output omitted in compact mode\]_"\)[\s\S]*?classList\.add\("compact-transcript-text"\)/, "reconciled compact-mode assistant output should preserve Markdown and explain omitted non-text output");
|
|
@@ -115,7 +116,8 @@ assert.match(orderedTranscriptItems, /if \(!compactOutputActive\(\)\) \{[\s\S]*?
|
|
|
115
116
|
assert.match(transcriptRenderEpoch, /compactOutputActive\(\) \? "compact" : "normal"/, "mode changes should invalidate the keyed transcript renderer");
|
|
116
117
|
assert.match(clearCompactToolShells, /removeCompactLiveBubble\(shell\?\.bubble\)[\s\S]*?compactToolShells\.clear\(\)/, "fast mode should remove previous transient tool shells from the DOM and registry");
|
|
117
118
|
assert.match(compactToolShell, /if \(!shell\) \{\s+clearCompactToolShells\(\)/, "a newly-started tool should replace the previous transient tool shell");
|
|
118
|
-
assert.match(compactToolShell, /shell\.status
|
|
119
|
+
assert.match(compactToolShell, /transcriptRenderer\.updateTextSurface\(\{[\s\S]*?surface: shell\.status[\s\S]*?text: complete[\s\S]*?event\?\.isError \? "failed" : "done"[\s\S]*?: "running"/, "the current transient tool shell should expose only a non-duplicated status through its stable transcript text surface");
|
|
120
|
+
assert.doesNotMatch(compactToolShell, /shell\.status\.textContent\s*=/, "compact tool status updates must not replace selected text nodes");
|
|
119
121
|
assert.match(styles, /\.message\.compact-tool-shell\s*\{[\s\S]*?display: grid[\s\S]*?grid-template-columns:[\s\S]*?padding: 0\.46rem 0\.62rem[\s\S]*?box-shadow: none/, "fast-mode tool activity should render as a compact horizontal row");
|
|
120
122
|
assert.match(styles, /\.compact-tool-shell \.compact-tool-status\s*\{[\s\S]*?display: inline-flex[\s\S]*?border-radius: 999px[\s\S]*?font-size: 0\.7rem[\s\S]*?text-transform: uppercase/, "the minimal tool status should remain visually distinct as a small pill");
|
|
121
123
|
assert.match(styles, /\.compact-tool-shell\.tool-running \.compact-tool-status[\s\S]*?\.compact-tool-shell\.tool-success \.compact-tool-status[\s\S]*?\.compact-tool-shell\.tool-error \.compact-tool-status/, "running, success, and failure tool states should have distinct visual tones");
|
|
@@ -152,7 +154,8 @@ assert.match(helper, /FAST_OUTPUT_FLUSH_INTERVAL_MS = 100/, "the live scheduler
|
|
|
152
154
|
assert.match(worker, /pi-webui-pwa-v\d+[\s\S]*?"\/fast-output-live\.mjs"/, "PWA cache identity and app shell should include the compact helper");
|
|
153
155
|
assert.match(html, /<label for="fastOutputModeSelect">Compact mode \(Experimental\)<\/label>/, "the sidebar should mark compact mode as experimental");
|
|
154
156
|
assert.match(html, /Lightweight browser rendering; Markdown final output; live thinking expanded; stored thinking grouped and collapsed/, "the sidebar should distinguish compact rendering from model inference");
|
|
155
|
-
|
|
157
|
+
// Intent preserved: the guarded PWA entry point must advance whenever app wiring changes.
|
|
158
|
+
assert.match(html, /id="webuiBootLoader"[^>]*data-app-src="\/app\.js\?v=103"/, "the guarded PWA entry point should cache-bust browser wiring");
|
|
156
159
|
assert.match(JSON.parse(packageRaw).scripts.check, /node --check public\/fast-output-live\.mjs/, "package checks should parse the compact helper");
|
|
157
160
|
|
|
158
161
|
const events = createFastModeOutputEvents();
|
|
@@ -46,6 +46,7 @@ const voiceScriptsEnabled = process.env.FAKE_PI_VOICE_SCRIPTS === "1";
|
|
|
46
46
|
// consumers retain their current timing and log shapes.
|
|
47
47
|
const continuityModeEnabled = process.env.FAKE_PI_CONTINUITY_MODE === "1";
|
|
48
48
|
const largePayloadsEnabled = process.env.FAKE_PI_LARGE_PAYLOADS === "1";
|
|
49
|
+
const sseFloodEnabled = process.env.FAKE_PI_SSE_FLOOD === "1";
|
|
49
50
|
const commandLogFile = process.env.FAKE_PI_LOG_FILE || "";
|
|
50
51
|
const largeRpcText = "large-rpc-payload:" + "λ".repeat(70_000);
|
|
51
52
|
const largeTokenSamples = Array.from({ length: 300 }, (_, index) => ({ index, input: index + 1, output: index + 2 }));
|
|
@@ -114,6 +115,11 @@ function mutateRuntimeQueue(payload = {}) {
|
|
|
114
115
|
const [message] = runtimeQueue.followUpMessages.splice(operation.from, 1);
|
|
115
116
|
runtimeQueue.followUp.splice(operation.to, 0, text);
|
|
116
117
|
runtimeQueue.followUpMessages.splice(operation.to, 0, message);
|
|
118
|
+
} else if (operation.type === "delete") {
|
|
119
|
+
if (!Number.isInteger(operation.index) || operation.index < 0 || operation.index >= runtimeQueue.followUp.length
|
|
120
|
+
|| runtimeQueue.followUp[operation.index] !== operation.expectedText) return failed("invalid-request");
|
|
121
|
+
runtimeQueue.followUp.splice(operation.index, 1);
|
|
122
|
+
runtimeQueue.followUpMessages.splice(operation.index, 1);
|
|
117
123
|
} else {
|
|
118
124
|
return failed("invalid-request");
|
|
119
125
|
}
|
|
@@ -276,11 +282,160 @@ function runContinuityDelayedStream() {
|
|
|
276
282
|
runScriptedSteps(steps);
|
|
277
283
|
}
|
|
278
284
|
|
|
285
|
+
function runContinuityDelayedStart() {
|
|
286
|
+
runScriptedSteps([{ afterMs: 3500, run: runContinuityDelayedStream }]);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function runContinuityConfirmedBeforeTool() {
|
|
290
|
+
scriptedStreaming = true;
|
|
291
|
+
runScriptedSteps([{ afterMs: 1500, run: () => runTranscriptContinuityScenario("tool") }]);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function runTranscriptContinuityScenario(scenario) {
|
|
295
|
+
scriptedStreaming = true;
|
|
296
|
+
const run = ++continuityRun;
|
|
297
|
+
const tagged = (payload) => ({ ...payload, continuityRun: run, continuityScenario: scenario });
|
|
298
|
+
const steps = [];
|
|
299
|
+
const start = () => steps.push(
|
|
300
|
+
{ afterMs: 40, run: () => emitScriptedEvent(tagged({ type: "agent_start" })) },
|
|
301
|
+
{ afterMs: 40, run: () => emitScriptedEvent(tagged({ type: "message_start", message: { role: "assistant" } })) },
|
|
302
|
+
);
|
|
303
|
+
const finish = (message, afterMs = 160) => {
|
|
304
|
+
if (message) {
|
|
305
|
+
steps.push({ afterMs, run: () => {
|
|
306
|
+
const settledMessage = typeof message === "function" ? message() : message;
|
|
307
|
+
appendDynamicMessage(settledMessage);
|
|
308
|
+
emitScriptedEvent(tagged({ type: "message_end", message: settledMessage }));
|
|
309
|
+
} });
|
|
310
|
+
}
|
|
311
|
+
steps.push(
|
|
312
|
+
{ afterMs: message ? 60 : afterMs, run: () => emitScriptedEvent(tagged({ type: "agent_end" })) },
|
|
313
|
+
{ afterMs: 20, run: () => {
|
|
314
|
+
scriptedStreaming = false;
|
|
315
|
+
emitScriptedEvent(tagged({ type: "agent_settled" }));
|
|
316
|
+
} },
|
|
317
|
+
);
|
|
318
|
+
};
|
|
319
|
+
const assistant = (text) => ({ role: "assistant", content: [{ type: "text", text }], timestamp: Date.now() });
|
|
320
|
+
|
|
321
|
+
if (scenario === "reverse") {
|
|
322
|
+
const text = "backward selection literal survives";
|
|
323
|
+
start();
|
|
324
|
+
steps.push(
|
|
325
|
+
{ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: "backward selection literal" } })) },
|
|
326
|
+
{ afterMs: 650, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: " survives" } })) },
|
|
327
|
+
);
|
|
328
|
+
finish(assistant(text), 400);
|
|
329
|
+
} else if (scenario === "duplicate") {
|
|
330
|
+
const text = "duplicate keyed selection literal";
|
|
331
|
+
start();
|
|
332
|
+
steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: text } })) });
|
|
333
|
+
finish(assistant(text), 400);
|
|
334
|
+
} else if (scenario === "pointer") {
|
|
335
|
+
const text = "pointer drag selection literal remains after update";
|
|
336
|
+
start();
|
|
337
|
+
steps.push(
|
|
338
|
+
{ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: "pointer drag selection literal" } })) },
|
|
339
|
+
{ afterMs: 900, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: " remains after update" } })) },
|
|
340
|
+
);
|
|
341
|
+
finish(assistant(text), 1_000);
|
|
342
|
+
} else if (scenario === "thinking") {
|
|
343
|
+
start();
|
|
344
|
+
steps.push(
|
|
345
|
+
{ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "thinking_delta", delta: "thinking selection literal" } })) },
|
|
346
|
+
{ afterMs: 650, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "thinking_delta", delta: " survives" } })) },
|
|
347
|
+
);
|
|
348
|
+
finish({ role: "assistant", content: [{ type: "thinking", thinking: "thinking selection literal survives" }, { type: "text", text: "thinking final answer" }], timestamp: Date.now() }, 450);
|
|
349
|
+
} else if (scenario === "tool") {
|
|
350
|
+
const toolCallId = `continuity-tool-${run}`;
|
|
351
|
+
steps.push(
|
|
352
|
+
{ afterMs: 40, run: () => emitScriptedEvent(tagged({ type: "agent_start" })) },
|
|
353
|
+
{ afterMs: 70, run: () => emitScriptedEvent(tagged({ type: "tool_execution_start", toolCallId, toolName: "read", args: { path: "continuity.txt" } })) },
|
|
354
|
+
{ afterMs: 100, run: () => emitScriptedEvent(tagged({ type: "tool_execution_update", toolCallId, toolName: "read", partialResult: { content: [{ type: "text", text: "tool selection literal\nunselected revision one" }] } })) },
|
|
355
|
+
{ afterMs: 700, run: () => emitScriptedEvent(tagged({ type: "tool_execution_update", toolCallId, toolName: "read", partialResult: { content: [{ type: "text", text: "tool selection literal\nunselected revision two" }] } })) },
|
|
356
|
+
{ afterMs: 600, run: () => emitScriptedEvent(tagged({ type: "tool_execution_end", toolCallId, toolName: "read", isError: false, result: { content: [{ type: "text", text: "tool selection literal\nunselected revision two" }] } })) },
|
|
357
|
+
);
|
|
358
|
+
finish(null, 120);
|
|
359
|
+
} else if (scenario === "authoritative") {
|
|
360
|
+
start();
|
|
361
|
+
steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: "authoritative selection literal" } })) });
|
|
362
|
+
finish(assistant("authoritative replacement text"), 700);
|
|
363
|
+
} else if (scenario === "cadence") {
|
|
364
|
+
const prefix = "high cadence selection literal\n\n";
|
|
365
|
+
let finalText = prefix;
|
|
366
|
+
start();
|
|
367
|
+
steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: prefix } })) });
|
|
368
|
+
steps.push({ afterMs: 800, run: () => {
|
|
369
|
+
for (let index = 0; index < 96; index += 1) {
|
|
370
|
+
const delta = `c${String(index).padStart(2, "0")} `;
|
|
371
|
+
finalText += delta;
|
|
372
|
+
emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta } }));
|
|
373
|
+
}
|
|
374
|
+
} });
|
|
375
|
+
finish(() => assistant(finalText), 500);
|
|
376
|
+
} else if (scenario === "dwell") {
|
|
377
|
+
const prefix = "thirty second selection literal anchor\n\n";
|
|
378
|
+
let finalText = prefix;
|
|
379
|
+
start();
|
|
380
|
+
steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: prefix } })) });
|
|
381
|
+
for (let index = 0; index < 300; index += 1) {
|
|
382
|
+
const delta = `d${String(index).padStart(3, "0")} `;
|
|
383
|
+
finalText += delta;
|
|
384
|
+
steps.push({ afterMs: 100, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta } })) });
|
|
385
|
+
}
|
|
386
|
+
finish(() => assistant(finalText), 200);
|
|
387
|
+
} else if (scenario === "mode") {
|
|
388
|
+
const text = "output mode transition literal";
|
|
389
|
+
start();
|
|
390
|
+
steps.push(
|
|
391
|
+
{ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: text } })) },
|
|
392
|
+
{ afterMs: 3_000, run: () => emitScriptedEvent(tagged({ type: "webui_output_mode", protocolVersion: 1, activeMode: "compact-v1" })) },
|
|
393
|
+
);
|
|
394
|
+
finish(assistant(text), 1_200);
|
|
395
|
+
} else if (scenario === "mermaid") {
|
|
396
|
+
const text = "Mermaid source selection literal\n\n```mermaid\ngraph TD\n A-->B\n```\n\n";
|
|
397
|
+
start();
|
|
398
|
+
steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: text } })) });
|
|
399
|
+
finish(assistant(text), 1800);
|
|
400
|
+
} else {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
runScriptedSteps(steps);
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function handleTranscriptContinuityPrompt(command, base) {
|
|
408
|
+
if (!continuityModeEnabled) return false;
|
|
409
|
+
const match = String(command.message || "").trim().match(/^fixture transcript continuity (reverse|duplicate|pointer|thinking|tool|authoritative|cadence|dwell|mode|mermaid)$/);
|
|
410
|
+
if (!match) return false;
|
|
411
|
+
appendDynamicMessage({ role: "user", content: String(command.message), timestamp: Date.now() });
|
|
412
|
+
respond({ ...base, data: { output: `fake transcript continuity ${match[1]} accepted`, pid: process.pid } });
|
|
413
|
+
return runTranscriptContinuityScenario(match[1]);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function handleMobileBlockerPrompt(command, base) {
|
|
417
|
+
if (String(command.message || "").trim() !== "fixture mobile blocker") return false;
|
|
418
|
+
respond({ ...base, data: { output: "mobile blocker fixture accepted" } });
|
|
419
|
+
emitEvent({ type: "agent_start" });
|
|
420
|
+
emitEvent({
|
|
421
|
+
type: "extension_ui_request",
|
|
422
|
+
id: "fixture_blocker_12345678",
|
|
423
|
+
method: "confirm",
|
|
424
|
+
title: "Fixture blocker",
|
|
425
|
+
message: "Confirm the background-tab blocker.",
|
|
426
|
+
});
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
|
|
279
430
|
function handleContinuityPrompt(command, base) {
|
|
280
|
-
if (!continuityModeEnabled
|
|
431
|
+
if (!continuityModeEnabled) return false;
|
|
432
|
+
const message = String(command.message || "").trim();
|
|
433
|
+
if (!["fixture continuity delayed stream", "fixture continuity delayed start", "fixture continuity confirmed before tool"].includes(message)) return false;
|
|
281
434
|
appendDynamicMessage({ role: "user", content: String(command.message), timestamp: Date.now() });
|
|
282
435
|
respond({ ...base, data: { output: "fake continuity stream accepted", pid: process.pid } });
|
|
283
|
-
|
|
436
|
+
if (message === "fixture continuity delayed start") runContinuityDelayedStart();
|
|
437
|
+
else if (message === "fixture continuity confirmed before tool") runContinuityConfirmedBeforeTool();
|
|
438
|
+
else runContinuityDelayedStream();
|
|
284
439
|
return true;
|
|
285
440
|
}
|
|
286
441
|
|
|
@@ -291,6 +446,16 @@ function handleLargePayloadPrompt(command, base) {
|
|
|
291
446
|
return true;
|
|
292
447
|
}
|
|
293
448
|
|
|
449
|
+
function handleSseFloodPrompt(command, base) {
|
|
450
|
+
if (!sseFloodEnabled || String(command.message || "").trim() !== "fixture sse flood") return false;
|
|
451
|
+
respond({ ...base, data: { output: "fake SSE flood accepted" } });
|
|
452
|
+
const payload = "s".repeat(8192);
|
|
453
|
+
for (let index = 0; index < 256; index += 1) {
|
|
454
|
+
emitEvent({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: `${index}:${payload}` } });
|
|
455
|
+
}
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
|
|
294
459
|
function handleVoiceScriptPrompt(command, base) {
|
|
295
460
|
if (!voiceScriptsEnabled) return false;
|
|
296
461
|
const message = String(command.message || "");
|
|
@@ -438,6 +603,17 @@ function handleWebuiHelperPrompt(command, base) {
|
|
|
438
603
|
currentToolArgs: "README.md",
|
|
439
604
|
model: agent.model || "anthropic/claude-opus-4-8:high",
|
|
440
605
|
thinking: agent.thinking || "high",
|
|
606
|
+
telemetry: {
|
|
607
|
+
promptInjectionTokens: 1234,
|
|
608
|
+
inputTokens: 300,
|
|
609
|
+
outputTokens: 100,
|
|
610
|
+
tokenSpeed: 20,
|
|
611
|
+
contextTokens: 240,
|
|
612
|
+
contextWindow: 200_000,
|
|
613
|
+
model: null,
|
|
614
|
+
effort: null,
|
|
615
|
+
rawSessionPayload: "must not leave fake helper telemetry",
|
|
616
|
+
},
|
|
441
617
|
recentTools: [{ tool: "grep", args: "Subagents", endMs: Date.now() - 200 }],
|
|
442
618
|
recentOutput: ["Inspecting current implementation", "Waiting for the next tool result"],
|
|
443
619
|
transcript: [
|
|
@@ -819,8 +995,11 @@ rl.on("line", (line) => {
|
|
|
819
995
|
if (handleWorkflowFixturePrompt(command, base)) return;
|
|
820
996
|
if (handleCodexFastModePrompt(command, base)) return;
|
|
821
997
|
if (handleTalkPrompt(command, base)) return;
|
|
998
|
+
if (handleMobileBlockerPrompt(command, base)) return;
|
|
999
|
+
if (handleTranscriptContinuityPrompt(command, base)) return;
|
|
822
1000
|
if (handleContinuityPrompt(command, base)) return;
|
|
823
1001
|
if (handleLargePayloadPrompt(command, base)) return;
|
|
1002
|
+
if (handleSseFloodPrompt(command, base)) return;
|
|
824
1003
|
if (handleVoiceScriptPrompt(command, base)) return;
|
|
825
1004
|
respond({ ...base, data: { output: "fake prompt accepted" } });
|
|
826
1005
|
return;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const app = await readFile(join(root, "public", "app.js"), "utf8");
|
|
8
|
+
|
|
9
|
+
function functionBody(name) {
|
|
10
|
+
const start = app.indexOf(`function ${name}(`);
|
|
11
|
+
assert.notEqual(start, -1, `${name} should be defined`);
|
|
12
|
+
const next = app.indexOf("\nfunction ", start + 1);
|
|
13
|
+
return app.slice(start, next === -1 ? app.length : next);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const menuItems = functionBody("gitPanelContextMenuItems");
|
|
17
|
+
const runAction = functionBody("runGitPanelAction");
|
|
18
|
+
|
|
19
|
+
// Repository menus must not gain the action.
|
|
20
|
+
const repositoryBranch = menuItems.slice(
|
|
21
|
+
menuItems.indexOf('if (kind === "repository")'),
|
|
22
|
+
menuItems.indexOf('const target = kind === "folder"'),
|
|
23
|
+
);
|
|
24
|
+
assert.ok(repositoryBranch.length > 0, "the repository menu branch should still exist");
|
|
25
|
+
assert.doesNotMatch(repositoryBranch, /gitignore/i, "repository context menus should not offer the .gitignore action");
|
|
26
|
+
|
|
27
|
+
// File/folder menus share one action entry that carries the selected kind.
|
|
28
|
+
assert.match(
|
|
29
|
+
menuItems,
|
|
30
|
+
/const ignoreAction = target === "folder" \? "ignore-folder" : "ignore-file";/,
|
|
31
|
+
"the menu should select the ignore action matching the selected row kind",
|
|
32
|
+
);
|
|
33
|
+
assert.match(
|
|
34
|
+
menuItems,
|
|
35
|
+
/const ignoreItem = \{ label: "Add to \.gitignore", disabled: gitPanelActionBusy\(card, ignoreAction, path\), run: \(\) => runGitPanelAction\(card, ignoreAction, path\) \};/,
|
|
36
|
+
"file and folder menus should share one busy-aware Add to .gitignore item",
|
|
37
|
+
);
|
|
38
|
+
assert.match(
|
|
39
|
+
menuItems,
|
|
40
|
+
/const target = kind === "folder" \? "folder" : "file";/,
|
|
41
|
+
"the action should resolve exactly the file or folder kind accepted by the endpoint",
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Staged rows keep their early return but still include the action.
|
|
45
|
+
const stagedBranch = menuItems.slice(
|
|
46
|
+
menuItems.indexOf('if (category === "staged")'),
|
|
47
|
+
menuItems.indexOf("const stageLabel ="),
|
|
48
|
+
);
|
|
49
|
+
assert.match(stagedBranch, /Unstage \$\{target\}/, "the staged branch should keep its unstage item");
|
|
50
|
+
assert.match(stagedBranch, /\bignoreItem,/, "the staged early-return branch should also offer Add to .gitignore");
|
|
51
|
+
|
|
52
|
+
// Changed/conflicted/untracked menus include the action before destructive controls.
|
|
53
|
+
const ignoreIndex = menuItems.indexOf("run: () => runGitPanelAction(card, \"stage\", path) }, ignoreItem]");
|
|
54
|
+
assert.ok(ignoreIndex > 0, "non-staged menus should list Add to .gitignore next to the stage item");
|
|
55
|
+
assert.ok(
|
|
56
|
+
ignoreIndex < menuItems.indexOf('label: "Discard changes…"') &&
|
|
57
|
+
ignoreIndex < menuItems.indexOf('label: "Delete file…"'),
|
|
58
|
+
"Add to .gitignore should be ordered ahead of the destructive discard/delete controls",
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Action flow: route, body, and kind handling.
|
|
62
|
+
assert.match(
|
|
63
|
+
app,
|
|
64
|
+
/async function runGitPanelAction\(card, action, path = ""\) \{/,
|
|
65
|
+
"the shared action runner should keep its existing signature",
|
|
66
|
+
);
|
|
67
|
+
assert.match(
|
|
68
|
+
runAction,
|
|
69
|
+
/const gitignoreAction = \(kind\) => \(\{\s*url: "\/api\/git-changes\/add-to-gitignore",\s*body: \{ path, kind \},/,
|
|
70
|
+
"the ignore action should POST path and kind to the approved endpoint",
|
|
71
|
+
);
|
|
72
|
+
assert.match(runAction, /"ignore-file": gitignoreAction\("file"\),/, "file rows should send kind file");
|
|
73
|
+
assert.match(runAction, /"ignore-folder": gitignoreAction\("folder"\),/, "folder rows should send kind folder");
|
|
74
|
+
|
|
75
|
+
// Feedback distinguishes newly added entries from already-present ones.
|
|
76
|
+
const ignoreConfig = runAction.slice(runAction.indexOf("const gitignoreAction ="), runAction.indexOf("const config = {"));
|
|
77
|
+
assert.match(ignoreConfig, /data\?\.added/, "success feedback should read the response added flag");
|
|
78
|
+
assert.match(ignoreConfig, /data\?\.entry \|\| path/, "success feedback should prefer the normalized response entry");
|
|
79
|
+
assert.match(ignoreConfig, /Added \$\{data\?\.entry \|\| path\} to \.gitignore\./, "newly added entries should report an addition");
|
|
80
|
+
assert.match(ignoreConfig, /\$\{data\?\.entry \|\| path\} is already in \.gitignore\./, "already-present entries should not claim an addition");
|
|
81
|
+
assert.match(ignoreConfig, /Tracked files stay tracked until removed from the index\./, "success feedback should clarify that .gitignore does not untrack indexed files");
|
|
82
|
+
assert.doesNotMatch(ignoreConfig, /confirm/, "the ignore action should not introduce confirmation UI");
|
|
83
|
+
assert.match(
|
|
84
|
+
runAction,
|
|
85
|
+
/addEvent\(typeof config\.done === "function" \? config\.done\(response\.data\) : config\.past, "success"\);/,
|
|
86
|
+
"response-derived feedback should replace the static past-tense message only when configured",
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Regression: shared busy, error, and refresh behavior stays in the flow.
|
|
90
|
+
assert.match(runAction, /const busyKey = `\$\{card\.root\}\\u0000\$\{action\}\\u0000\$\{path\}`;/, "the ignore action should reuse the shared busy key scheme");
|
|
91
|
+
assert.match(runAction, /if \(gitPanelState\.busy\.has\(busyKey\)\) return;/, "concurrent duplicate actions should still be blocked");
|
|
92
|
+
assert.match(runAction, /gitPanelState\.busy\.add\(busyKey\);/, "the shared busy state should still be set before the request");
|
|
93
|
+
assert.match(runAction, /gitPanelState\.busy\.delete\(busyKey\);/, "the shared busy state should still be cleared afterwards");
|
|
94
|
+
assert.match(runAction, /if \(!response\.ok\) throw new Error/, "the shared error path should still reject failed responses");
|
|
95
|
+
assert.match(runAction, /await loadGitPanelRepository\(card, \{ force: true \}\);/, "successful actions should still force a Git repository refresh");
|
|
96
|
+
assert.match(runAction, /requestGitFooterWebuiPayload\(\{ tabId: card\.tabId \}, \{ force: true \}\);/, "successful actions should still refresh footer Git state");
|
|
97
|
+
|
|
98
|
+
// Regression: existing actions keep their static messages and endpoints.
|
|
99
|
+
assert.match(runAction, /stage: \{ url: "\/api\/git-changes\/stage-file", body: \{ path \}, past: `Staged \$\{path\}\.` \}/, "the stage action should be unchanged");
|
|
100
|
+
assert.match(runAction, /unstage: \{ url: "\/api\/git-changes\/unstage-file", body: \{ path \}, past: `Unstaged \$\{path\}\.` \}/, "the unstage action should be unchanged");
|
|
101
|
+
assert.match(runAction, /url: "\/api\/git-changes\/discard-file"/, "the discard action should be unchanged");
|
|
102
|
+
assert.match(runAction, /url: "\/api\/git-changes\/delete-untracked"/, "the delete action should be unchanged");
|
|
103
|
+
|
|
104
|
+
console.log("git-panel-gitignore-static.test.mjs passed");
|