@firstpick/pi-package-webui 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +34 -5
  2. package/bin/pi-webui.mjs +606 -102
  3. package/lib/component-update-state.mjs +126 -0
  4. package/lib/npm-command.mjs +81 -0
  5. package/lib/queue-mutation.mjs +6 -0
  6. package/lib/trust-boundaries.mjs +1 -0
  7. package/lib/workspace-files-live-watcher.mjs +138 -0
  8. package/package.json +8 -3
  9. package/public/app.js +4231 -376
  10. package/public/index.html +265 -52
  11. package/public/mobile-shell-state.mjs +166 -0
  12. package/public/service-worker.js +60 -13
  13. package/public/styles.css +1790 -383
  14. package/public/subagent-gate-visibility.mjs +16 -0
  15. package/public/subagent-launch-slot-state.mjs +16 -0
  16. package/public/transcript-renderer.mjs +433 -0
  17. package/tests/boot-failure-diagnostics.test.mjs +63 -5
  18. package/tests/browser/control-deck-component-updates.spec.mjs +180 -0
  19. package/tests/browser/interaction-continuity.spec.mjs +897 -0
  20. package/tests/browser/mobile-foundation.spec.mjs +363 -0
  21. package/tests/browser/optimistic-prompt.spec.mjs +130 -0
  22. package/tests/browser/side-panel-section-reorder.spec.mjs +101 -0
  23. package/tests/browser/stats-overlay.spec.mjs +265 -0
  24. package/tests/chat-scroll-intent-static.test.mjs +6 -1
  25. package/tests/codex-fast-mode-static.test.mjs +8 -5
  26. package/tests/compact-sections-static.test.mjs +20 -2
  27. package/tests/compaction-mutation-contract.test.mjs +18 -4
  28. package/tests/compaction-static.test.mjs +1 -0
  29. package/tests/completion-signal-contract.test.mjs +13 -2
  30. package/tests/component-update-api-static.test.mjs +67 -0
  31. package/tests/component-update-state.test.mjs +80 -0
  32. package/tests/control-deck-component-updates-static.test.mjs +251 -0
  33. package/tests/fast-mode-client-static.test.mjs +7 -4
  34. package/tests/fixtures/fake-pi.mjs +305 -2
  35. package/tests/footer-provider-usage-visual-static.test.mjs +71 -0
  36. package/tests/git-panel-gitignore-static.test.mjs +104 -0
  37. package/tests/http-endpoints-harness.test.mjs +228 -2
  38. package/tests/interaction-state-stability-static.test.mjs +271 -0
  39. package/tests/mobile-continuity-tablet-static.test.mjs +55 -0
  40. package/tests/mobile-foundation-static.test.mjs +71 -0
  41. package/tests/mobile-phone-experience-static.test.mjs +65 -0
  42. package/tests/mobile-shell-state.test.mjs +69 -0
  43. package/tests/mobile-static.test.mjs +246 -39
  44. package/tests/mobile-transcript-cache-characterization.test.mjs +34 -0
  45. package/tests/native-parity-harness.test.mjs +2 -0
  46. package/tests/npm-command.test.mjs +64 -1
  47. package/tests/open-issue-wizard-static.test.mjs +2 -1
  48. package/tests/queue-edit-reorder-static.test.mjs +9 -1
  49. package/tests/queue-mutation-contract.test.mjs +22 -0
  50. package/tests/service-worker-lifecycle.test.mjs +120 -0
  51. package/tests/side-panel-section-reorder-static.test.mjs +68 -0
  52. package/tests/sse-backpressure-harness.test.mjs +137 -0
  53. package/tests/stats-dashboard-static.test.mjs +266 -0
  54. package/tests/streaming-ui-coupling.test.mjs +7 -1
  55. package/tests/subagent-gate-visibility.test.mjs +18 -2
  56. package/tests/subagent-launch-slot-state.test.mjs +32 -0
  57. package/tests/subagent-launch-slots-static.test.mjs +8 -2
  58. package/tests/subagents-helper.test.mjs +90 -0
  59. package/tests/terminal-tab-workspace-static.test.mjs +1 -1
  60. package/tests/update-commands.test.mjs +4 -0
  61. package/tests/workspace-files-live-updates-static.test.mjs +76 -0
  62. package/tests/workspace-files-live-watcher.test.mjs +95 -0
  63. package/webui-rpc-helper.mjs +175 -3
@@ -15,6 +15,8 @@
15
15
  // assistant turns are appended to a dynamic transcript returned by
16
16
  // get_messages AFTER the three baseline messages, and get_state reports
17
17
  // isStreaming=true while a scripted flow runs.
18
+ // - FAKE_PI_STATS_PROMPT_CONTEXT=1: advertise /stats-webui and publish deterministic
19
+ // structured or malformed-subsection Prompt/context dashboard payloads.
18
20
  import { createInterface } from "node:readline";
19
21
  import { randomUUID } from "node:crypto";
20
22
  import { appendFileSync } from "node:fs";
@@ -46,6 +48,8 @@ const voiceScriptsEnabled = process.env.FAKE_PI_VOICE_SCRIPTS === "1";
46
48
  // consumers retain their current timing and log shapes.
47
49
  const continuityModeEnabled = process.env.FAKE_PI_CONTINUITY_MODE === "1";
48
50
  const largePayloadsEnabled = process.env.FAKE_PI_LARGE_PAYLOADS === "1";
51
+ const sseFloodEnabled = process.env.FAKE_PI_SSE_FLOOD === "1";
52
+ const statsPromptContextEnabled = process.env.FAKE_PI_STATS_PROMPT_CONTEXT === "1";
49
53
  const commandLogFile = process.env.FAKE_PI_LOG_FILE || "";
50
54
  const largeRpcText = "large-rpc-payload:" + "λ".repeat(70_000);
51
55
  const largeTokenSamples = Array.from({ length: 300 }, (_, index) => ({ index, input: index + 1, output: index + 2 }));
@@ -114,6 +118,11 @@ function mutateRuntimeQueue(payload = {}) {
114
118
  const [message] = runtimeQueue.followUpMessages.splice(operation.from, 1);
115
119
  runtimeQueue.followUp.splice(operation.to, 0, text);
116
120
  runtimeQueue.followUpMessages.splice(operation.to, 0, message);
121
+ } else if (operation.type === "delete") {
122
+ if (!Number.isInteger(operation.index) || operation.index < 0 || operation.index >= runtimeQueue.followUp.length
123
+ || runtimeQueue.followUp[operation.index] !== operation.expectedText) return failed("invalid-request");
124
+ runtimeQueue.followUp.splice(operation.index, 1);
125
+ runtimeQueue.followUpMessages.splice(operation.index, 1);
117
126
  } else {
118
127
  return failed("invalid-request");
119
128
  }
@@ -276,11 +285,165 @@ function runContinuityDelayedStream() {
276
285
  runScriptedSteps(steps);
277
286
  }
278
287
 
288
+ function runContinuityDelayedStart() {
289
+ runScriptedSteps([{ afterMs: 3500, run: runContinuityDelayedStream }]);
290
+ }
291
+
292
+ function runContinuityConfirmedBeforeTool() {
293
+ scriptedStreaming = true;
294
+ runScriptedSteps([{ afterMs: 1500, run: () => runTranscriptContinuityScenario("tool") }]);
295
+ }
296
+
297
+ function runTranscriptContinuityScenario(scenario) {
298
+ scriptedStreaming = true;
299
+ const run = ++continuityRun;
300
+ const tagged = (payload) => ({ ...payload, continuityRun: run, continuityScenario: scenario });
301
+ const steps = [];
302
+ const start = () => steps.push(
303
+ { afterMs: 40, run: () => emitScriptedEvent(tagged({ type: "agent_start" })) },
304
+ { afterMs: 40, run: () => emitScriptedEvent(tagged({ type: "message_start", message: { role: "assistant" } })) },
305
+ );
306
+ const finish = (message, afterMs = 160) => {
307
+ if (message) {
308
+ steps.push({ afterMs, run: () => {
309
+ const settledMessage = typeof message === "function" ? message() : message;
310
+ appendDynamicMessage(settledMessage);
311
+ emitScriptedEvent(tagged({ type: "message_end", message: settledMessage }));
312
+ } });
313
+ }
314
+ steps.push(
315
+ { afterMs: message ? 60 : afterMs, run: () => emitScriptedEvent(tagged({ type: "agent_end" })) },
316
+ { afterMs: 20, run: () => {
317
+ scriptedStreaming = false;
318
+ emitScriptedEvent(tagged({ type: "agent_settled" }));
319
+ } },
320
+ );
321
+ };
322
+ const assistant = (text) => ({ role: "assistant", content: [{ type: "text", text }], timestamp: Date.now() });
323
+
324
+ if (scenario === "reverse") {
325
+ const text = "backward selection literal survives";
326
+ start();
327
+ steps.push(
328
+ { afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: "backward selection literal" } })) },
329
+ { afterMs: 650, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: " survives" } })) },
330
+ );
331
+ finish(assistant(text), 400);
332
+ } else if (scenario === "duplicate") {
333
+ const text = "duplicate keyed selection literal";
334
+ start();
335
+ steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: text } })) });
336
+ finish(assistant(text), 400);
337
+ } else if (scenario === "pointer") {
338
+ const text = "pointer drag selection literal remains after update";
339
+ start();
340
+ steps.push(
341
+ { afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: "pointer drag selection literal" } })) },
342
+ { afterMs: 900, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: " remains after update" } })) },
343
+ );
344
+ finish(assistant(text), 1_000);
345
+ } else if (scenario === "thinking") {
346
+ start();
347
+ steps.push(
348
+ { afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "thinking_delta", delta: "thinking selection literal" } })) },
349
+ { afterMs: 650, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "thinking_delta", delta: " survives" } })) },
350
+ );
351
+ finish({ role: "assistant", content: [{ type: "thinking", thinking: "thinking selection literal survives" }, { type: "text", text: "thinking final answer" }], timestamp: Date.now() }, 450);
352
+ } else if (scenario === "tool") {
353
+ const toolCallId = `continuity-tool-${run}`;
354
+ const toolOutput = (revision) => [
355
+ "tool selection literal",
356
+ `unselected revision ${revision}`,
357
+ ...Array.from({ length: 64 }, (_, index) => `continuity output line ${String(index + 1).padStart(2, "0")} ${"x".repeat(160)}`),
358
+ ].join("\n");
359
+ steps.push(
360
+ { afterMs: 40, run: () => emitScriptedEvent(tagged({ type: "agent_start" })) },
361
+ { afterMs: 70, run: () => emitScriptedEvent(tagged({ type: "tool_execution_start", toolCallId, toolName: "read", args: { path: "continuity.txt" } })) },
362
+ { afterMs: 100, run: () => emitScriptedEvent(tagged({ type: "tool_execution_update", toolCallId, toolName: "read", partialResult: { content: [{ type: "text", text: toolOutput("one") }] } })) },
363
+ { afterMs: 700, run: () => emitScriptedEvent(tagged({ type: "tool_execution_update", toolCallId, toolName: "read", partialResult: { content: [{ type: "text", text: toolOutput("two") }] } })) },
364
+ { afterMs: 600, run: () => emitScriptedEvent(tagged({ type: "tool_execution_end", toolCallId, toolName: "read", isError: false, result: { content: [{ type: "text", text: toolOutput("two") }] } })) },
365
+ );
366
+ finish(null, 120);
367
+ } else if (scenario === "authoritative") {
368
+ start();
369
+ steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: "authoritative selection literal" } })) });
370
+ finish(assistant("authoritative replacement text"), 700);
371
+ } else if (scenario === "cadence") {
372
+ const prefix = "high cadence selection literal\n\n";
373
+ let finalText = prefix;
374
+ start();
375
+ steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: prefix } })) });
376
+ steps.push({ afterMs: 800, run: () => {
377
+ for (let index = 0; index < 96; index += 1) {
378
+ const delta = `c${String(index).padStart(2, "0")} `;
379
+ finalText += delta;
380
+ emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta } }));
381
+ }
382
+ } });
383
+ finish(() => assistant(finalText), 500);
384
+ } else if (scenario === "dwell") {
385
+ const prefix = "thirty second selection literal anchor\n\n";
386
+ let finalText = prefix;
387
+ start();
388
+ steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: prefix } })) });
389
+ for (let index = 0; index < 300; index += 1) {
390
+ const delta = `d${String(index).padStart(3, "0")} `;
391
+ finalText += delta;
392
+ steps.push({ afterMs: 100, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta } })) });
393
+ }
394
+ finish(() => assistant(finalText), 200);
395
+ } else if (scenario === "mode") {
396
+ const text = "output mode transition literal";
397
+ start();
398
+ steps.push(
399
+ { afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: text } })) },
400
+ { afterMs: 3_000, run: () => emitScriptedEvent(tagged({ type: "webui_output_mode", protocolVersion: 1, activeMode: "compact-v1" })) },
401
+ );
402
+ finish(assistant(text), 1_200);
403
+ } else if (scenario === "mermaid") {
404
+ const text = "Mermaid source selection literal\n\n```mermaid\ngraph TD\n A-->B\n```\n\n";
405
+ start();
406
+ steps.push({ afterMs: 120, run: () => emitScriptedEvent(tagged({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: text } })) });
407
+ finish(assistant(text), 1800);
408
+ } else {
409
+ return false;
410
+ }
411
+ runScriptedSteps(steps);
412
+ return true;
413
+ }
414
+
415
+ function handleTranscriptContinuityPrompt(command, base) {
416
+ if (!continuityModeEnabled) return false;
417
+ const match = String(command.message || "").trim().match(/^fixture transcript continuity (reverse|duplicate|pointer|thinking|tool|authoritative|cadence|dwell|mode|mermaid)$/);
418
+ if (!match) return false;
419
+ appendDynamicMessage({ role: "user", content: String(command.message), timestamp: Date.now() });
420
+ respond({ ...base, data: { output: `fake transcript continuity ${match[1]} accepted`, pid: process.pid } });
421
+ return runTranscriptContinuityScenario(match[1]);
422
+ }
423
+
424
+ function handleMobileBlockerPrompt(command, base) {
425
+ if (String(command.message || "").trim() !== "fixture mobile blocker") return false;
426
+ respond({ ...base, data: { output: "mobile blocker fixture accepted" } });
427
+ emitEvent({ type: "agent_start" });
428
+ emitEvent({
429
+ type: "extension_ui_request",
430
+ id: "fixture_blocker_12345678",
431
+ method: "confirm",
432
+ title: "Fixture blocker",
433
+ message: "Confirm the background-tab blocker.",
434
+ });
435
+ return true;
436
+ }
437
+
279
438
  function handleContinuityPrompt(command, base) {
280
- if (!continuityModeEnabled || String(command.message || "").trim() !== "fixture continuity delayed stream") return false;
439
+ if (!continuityModeEnabled) return false;
440
+ const message = String(command.message || "").trim();
441
+ if (!["fixture continuity delayed stream", "fixture continuity delayed start", "fixture continuity confirmed before tool"].includes(message)) return false;
281
442
  appendDynamicMessage({ role: "user", content: String(command.message), timestamp: Date.now() });
282
443
  respond({ ...base, data: { output: "fake continuity stream accepted", pid: process.pid } });
283
- runContinuityDelayedStream();
444
+ if (message === "fixture continuity delayed start") runContinuityDelayedStart();
445
+ else if (message === "fixture continuity confirmed before tool") runContinuityConfirmedBeforeTool();
446
+ else runContinuityDelayedStream();
284
447
  return true;
285
448
  }
286
449
 
@@ -291,6 +454,18 @@ function handleLargePayloadPrompt(command, base) {
291
454
  return true;
292
455
  }
293
456
 
457
+ function handleSseFloodPrompt(command, base) {
458
+ const message = String(command.message || "").trim();
459
+ if (!sseFloodEnabled || !["fixture sse flood", "fixture sse stall flood"].includes(message)) return false;
460
+ respond({ ...base, data: { output: "fake SSE flood accepted" } });
461
+ const payload = "s".repeat(8192);
462
+ const eventCount = message === "fixture sse stall flood" ? 4096 : 256;
463
+ for (let index = 0; index < eventCount; index += 1) {
464
+ emitEvent({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: `${index}:${payload}` } });
465
+ }
466
+ return true;
467
+ }
468
+
294
469
  function handleVoiceScriptPrompt(command, base) {
295
470
  if (!voiceScriptsEnabled) return false;
296
471
  const message = String(command.message || "");
@@ -438,6 +613,17 @@ function handleWebuiHelperPrompt(command, base) {
438
613
  currentToolArgs: "README.md",
439
614
  model: agent.model || "anthropic/claude-opus-4-8:high",
440
615
  thinking: agent.thinking || "high",
616
+ telemetry: {
617
+ promptInjectionTokens: 1234,
618
+ inputTokens: 300,
619
+ outputTokens: 100,
620
+ tokenSpeed: 20,
621
+ contextTokens: 240,
622
+ contextWindow: 200_000,
623
+ model: null,
624
+ effort: null,
625
+ rawSessionPayload: "must not leave fake helper telemetry",
626
+ },
441
627
  recentTools: [{ tool: "grep", args: "Subagents", endMs: Date.now() - 200 }],
442
628
  recentOutput: ["Inspecting current implementation", "Waiting for the next tool result"],
443
629
  transcript: [
@@ -723,6 +909,118 @@ function handleTalkPrompt(command, base) {
723
909
  return true;
724
910
  }
725
911
 
912
+ function statsPromptContextFixturePayload({ malformedSnapshot = false } = {}) {
913
+ const hostileLabel = `System <img src=x onerror="globalThis.fixturePwned=true"> & "quoted" ${"long-label-".repeat(16)}`;
914
+ const payload = {
915
+ type: "firstpick.pi-extension-stats.overlay",
916
+ version: 1,
917
+ generatedAt: Date.now(),
918
+ open: true,
919
+ scopeLabel: "fixture prompt context",
920
+ scope: { mode: "range", days: 14 },
921
+ sessionCount: 0,
922
+ scopedSessionCount: 0,
923
+ dayCount: 14,
924
+ activeDayCount: 0,
925
+ totals: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0, cost: 0 },
926
+ promptEstimate: {
927
+ total: 300, low: 270, high: 330, confidence: "fixture", calibrationMultiplier: 1,
928
+ calibrationSamples: 0, source: "export-html", settled: true, attempts: 0,
929
+ warning: null, systemPromptChars: 0, activeToolSchemas: 2,
930
+ },
931
+ promptContext: {
932
+ initialPrompt: {
933
+ totalTokens: 300,
934
+ lowTokens: 270,
935
+ highTokens: 330,
936
+ confidence: "fixture",
937
+ source: "export-html",
938
+ warning: null,
939
+ estimateMethod: "weighted-character-estimate-with-largest-remainder-calibration",
940
+ components: [
941
+ { id: "system-prompt-1", kind: "system-prompt", label: hostileLabel, chars: null, uncalibratedTokens: 300, tokens: 300, percent: 100 },
942
+ { id: "framing-1", kind: "framing", label: "Zero-token framing", chars: 0, uncalibratedTokens: 0, tokens: 0, percent: 0 },
943
+ ],
944
+ },
945
+ snapshot: {
946
+ source: "export-html",
947
+ settled: true,
948
+ attempts: 0,
949
+ warning: null,
950
+ systemPromptChars: 0,
951
+ estimateComponents: {
952
+ promptText: malformedSnapshot ? "not-a-number" : 0,
953
+ toolSchemas: 25,
954
+ framing: 0,
955
+ calibration: { multiplier: 1, samples: 0 },
956
+ },
957
+ metadata: { currentDate: null, cwdDisplay: null, extraGuidelineCount: 0 },
958
+ tools: {
959
+ totalCount: 3,
960
+ omittedCount: 1,
961
+ items: [
962
+ { name: "<script>fixture-tool</script>", description: "Text-safe <b>description</b> & symbols", parameterSummary: "0 params", estimatedTokens: 0 },
963
+ { name: "read", description: null, parameterSummary: "1 param, 1 required", estimatedTokens: 25 },
964
+ ],
965
+ },
966
+ toolPromptEntries: { totalCount: 2, omittedCount: 0, names: ["<unsafe-entry>", "read"] },
967
+ skills: { totalCount: 2, omittedCount: 1, items: [{ name: "fixture-skill", description: "Hostile </details> stays text" }] },
968
+ contextFiles: {
969
+ totalCount: 2,
970
+ omittedCount: 0,
971
+ items: [
972
+ { displayPath: `nested/${"overflow-segment-".repeat(18)}context.md`, chars: null },
973
+ { displayPath: "zero.md", chars: 0 },
974
+ ],
975
+ },
976
+ },
977
+ currentContext: {
978
+ usage: { tokens: 0, contextWindow: null, percent: 0 },
979
+ breakdown: {
980
+ estimateMethod: "weighted-character-estimate",
981
+ reconstruction: "complete",
982
+ estimatedTotalTokens: 200,
983
+ actualMinusEstimatedTokens: -200,
984
+ sources: [
985
+ { id: "user-messages-1", kind: "user-messages", label: `User ${"overflow-source-".repeat(18)}`, chars: 800, estimatedTokens: 200, percent: 100 },
986
+ ],
987
+ },
988
+ },
989
+ },
990
+ summary: {},
991
+ daily: [],
992
+ models: [],
993
+ expensiveSessions: [],
994
+ lines: {
995
+ graph: ["RAW_GRAPH_FIXTURE"],
996
+ promptInjection: ["RAW_PROMPT_INJECTION <keep>& exact"],
997
+ promptDetailed: ["RAW_PROMPT_DETAILED </pre> exact"],
998
+ tokenBreakdown: ["RAW_CONTEXT_BREAKDOWN <raw> exact"],
999
+ costTrend: ["RAW_COST_TREND"],
1000
+ cache: ["RAW_CACHE"],
1001
+ modelComparison: ["RAW_MODEL_COMPARISON"],
1002
+ expensiveSessions: ["RAW_EXPENSIVE_SESSIONS"],
1003
+ },
1004
+ };
1005
+ return payload;
1006
+ }
1007
+
1008
+ function handleStatsPromptContextFixturePrompt(command, base) {
1009
+ if (!statsPromptContextEnabled) return false;
1010
+ const message = String(command.message || "").trim();
1011
+ const malformedSnapshot = message === "fixture stats prompt malformed";
1012
+ if (!malformedSnapshot && !/^\/stats-webui(?:\s|$)/.test(message)) return false;
1013
+ respond({ ...base, data: { output: malformedSnapshot ? "malformed stats prompt fixture emitted" : "structured stats prompt fixture emitted" } });
1014
+ emitEvent({
1015
+ type: "extension_ui_request",
1016
+ id: randomUUID(),
1017
+ method: "setStatus",
1018
+ statusKey: "stats-webui",
1019
+ statusText: JSON.stringify(statsPromptContextFixturePayload({ malformedSnapshot })),
1020
+ });
1021
+ return true;
1022
+ }
1023
+
726
1024
  const rl = createInterface({ input: process.stdin });
727
1025
  rl.on("line", (line) => {
728
1026
  if (!line.trim()) return;
@@ -789,6 +1087,7 @@ rl.on("line", (line) => {
789
1087
  { name: "conversation", source: "extension", description: "Natural Conversation Mode alias" },
790
1088
  { name: "fast-mode", source: "extension", description: "Toggle Codex subscription Fast mode" },
791
1089
  { name: "workflow", source: "extension", description: "Run and inspect JavaScript workflows" },
1090
+ ...(statsPromptContextEnabled ? [{ name: "stats-webui", source: "extension", description: "Publish fixture stats dashboard" }] : []),
792
1091
  ],
793
1092
  },
794
1093
  });
@@ -811,6 +1110,7 @@ rl.on("line", (line) => {
811
1110
  return;
812
1111
  }
813
1112
  case "prompt":
1113
+ if (handleStatsPromptContextFixturePrompt(command, base)) return;
814
1114
  if (handleWebuiHelperPrompt(command, base)) return;
815
1115
  if (handleFastModeFixturePrompt(command, base)) return;
816
1116
  if (handleTransportFixturePrompt(command, base)) return;
@@ -819,8 +1119,11 @@ rl.on("line", (line) => {
819
1119
  if (handleWorkflowFixturePrompt(command, base)) return;
820
1120
  if (handleCodexFastModePrompt(command, base)) return;
821
1121
  if (handleTalkPrompt(command, base)) return;
1122
+ if (handleMobileBlockerPrompt(command, base)) return;
1123
+ if (handleTranscriptContinuityPrompt(command, base)) return;
822
1124
  if (handleContinuityPrompt(command, base)) return;
823
1125
  if (handleLargePayloadPrompt(command, base)) return;
1126
+ if (handleSseFloodPrompt(command, base)) return;
824
1127
  if (handleVoiceScriptPrompt(command, base)) return;
825
1128
  respond({ ...base, data: { output: "fake prompt accepted" } });
826
1129
  return;
@@ -0,0 +1,71 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+
4
+ const [app, css, producer, parser] = await Promise.all([
5
+ readFile(new URL("../public/app.js", import.meta.url), "utf8"),
6
+ readFile(new URL("../public/styles.css", import.meta.url), "utf8"),
7
+ readFile(new URL("../../pi-extension-git-footer-status/index.ts", import.meta.url), "utf8"),
8
+ readFile(new URL("../../pi-extension-git-footer-status/provider-usage.ts", import.meta.url), "utf8"),
9
+ ]);
10
+
11
+ const between = (source, start, end) => {
12
+ const startIndex = source.indexOf(start);
13
+ assert.notEqual(startIndex, -1, `missing section start: ${start}`);
14
+ const endIndex = source.indexOf(end, startIndex + start.length);
15
+ assert.notEqual(endIndex, -1, `missing section end: ${end}`);
16
+ return source.slice(startIndex, endIndex);
17
+ };
18
+
19
+ const normalizeChip = between(app, "function normalizeFooterPayloadChip", "function currentGitFooterCacheCwd");
20
+ const usageNormalization = normalizeChip.slice(normalizeChip.indexOf("if (value.usageWindows"));
21
+ const applyUsage = between(app, "function applyFooterUsageWindows", "const FOOTER_MIDDLE_TRUNCATION_END_CHARS");
22
+ const shapeKey = between(app, "function gitFooterChipShapeKey", "function footerBranchPickerRenderKey");
23
+ const inPlaceUpdate = between(app, "function updateGitFooterChipNodeValue", "let gitFooterRenderCache");
24
+
25
+ assert.match(parser, /x-codex-primary-window-minutes/, "Codex parser should read the primary window duration");
26
+ assert.match(parser, /x-codex-secondary-window-minutes/, "Codex parser should read the secondary window duration");
27
+ assert.match(parser, /windowMinutes === 10_080\) return "weekly"/, "Codex weekly windows should have a truthful compact label");
28
+ assert.match(parser, /return fallback;/, "missing Codex durations should use neutral labels rather than guessed 5h\/7d labels");
29
+ assert.match(parser, /usage\.primary\.label[\s\S]*usage\.secondary\.label/, "formatted text should use snapshot labels");
30
+
31
+ assert.match(producer, /usageWindows\?:\s*\{\s*primaryPercent:\s*number;\s*secondaryPercent:\s*number;/s, "producer should type the optional usageWindows contract");
32
+ assert.match(producer, /usageWindows:\s*\{\s*primaryPercent:\s*providerUsage\.primary\.usedPercent,\s*secondaryPercent:\s*providerUsage\.secondary\.usedPercent,/s, "Usage chip should publish both normalized window percentages");
33
+ assert.match(app, /usage:\s*"Provider subscription usage\.[^"]*provider-reported primary and secondary rate windows\./, "Usage tooltip should explain both provider-reported windows rather than using generic fallback copy");
34
+
35
+ assert.match(usageNormalization, /value\.usageWindows\.primaryPercent/, "consumer should read structured primary metadata");
36
+ assert.match(usageNormalization, /value\.usageWindows\.secondaryPercent/, "consumer should read structured secondary metadata");
37
+ assert.match(usageNormalization, /Number\.isFinite\(primaryPercent\)\s*&&\s*Number\.isFinite\(secondaryPercent\)/, "consumer should require both finite window values");
38
+ assert.match(usageNormalization, /chip\.usageWindows\s*=\s*\{\s*primaryPercent,\s*secondaryPercent\s*\}/, "consumer should preserve the two structured values");
39
+ assert.doesNotMatch(usageNormalization, /chip\.value|value\.value|5h.*match|7d.*match/s, "usage-window normalization must not parse display text");
40
+
41
+ assert.match(app, /if \(chip\.usageWindows\) applyFooterUsageWindows\(node, chip\.usageWindows\);/, "initial rendering should apply Usage visuals");
42
+ assert.match(applyUsage, /Math\.min\(100, Math\.max\(0, primaryPercent\)\)/, "primary visual should clamp defensively");
43
+ assert.match(applyUsage, /Math\.min\(100, Math\.max\(0, secondaryPercent\)\)/, "secondary visual should clamp defensively");
44
+ assert.match(applyUsage, /--usage-primary/, "primary should have an independent CSS width variable");
45
+ assert.match(applyUsage, /--usage-secondary/, "secondary should have an independent CSS width variable");
46
+ assert.doesNotMatch(applyUsage, /\.value|5h.*match|7d.*match/s, "visual application must not parse display text");
47
+ assert.match(shapeKey, /key === "title" && chip\?\.key === "usage"/, "dynamic Usage titles should not force a full footer rebuild");
48
+ assert.match(shapeKey, /key === "usageWindows"[\s\S]*shape\.usageWindows = value \? true : false/, "shape key should track visual capability, not changing percentages");
49
+ assert.match(inPlaceUpdate, /chip\.key === "usage"[\s\S]*gitFooterPayloadTooltip\(chip\)/, "in-place Usage updates should rebuild the complete dynamic tooltip");
50
+ assert.match(inPlaceUpdate, /setAttribute\("aria-label", nextTooltip\.replace/, "in-place tooltip updates should keep the aria-label current");
51
+ assert.match(inPlaceUpdate, /if \(chip\.usageWindows\) applyFooterUsageWindows\(node, chip\.usageWindows\);/, "live updates should refresh both widths in place");
52
+
53
+ const sharedOverlay = css.match(/\.footer-usage-card\.has-usage-windows::before,\s*\.footer-usage-card\.has-usage-windows::after\s*\{([^}]+)\}/s)?.[1] ?? "";
54
+ const primaryLane = css.match(/\.footer-usage-card\.has-usage-windows::before\s*\{([^}]+)\}/s)?.[1] ?? "";
55
+ const secondaryLane = [...css.matchAll(/\.footer-usage-card\.has-usage-windows::after\s*\{([^}]+)\}/gs)]
56
+ .map((match) => match[1] ?? "")
57
+ .find((body) => /bottom:\s*0/.test(body)) ?? "";
58
+ const foreground = css.match(/\.footer-usage-card > \*\s*\{([^}]+)\}/s)?.[1] ?? "";
59
+
60
+ assert.match(sharedOverlay, /height:\s*50%/, "each usage lane should occupy half the chip height");
61
+ assert.match(sharedOverlay, /background:\s*var\(--context-card-gradient\)/, "usage lanes should reuse the Context gradient");
62
+ assert.match(sharedOverlay, /opacity:\s*0\.34/, "usage lanes should retain Context-like translucent contrast");
63
+ assert.match(primaryLane, /top:\s*0/, "primary lane should be the top lane");
64
+ assert.match(primaryLane, /border-bottom:\s*1px solid/, "the two lanes should have a subtle visual separator");
65
+ assert.match(primaryLane, /var\(--usage-primary\)/, "top lane width should use the primary percentage");
66
+ assert.match(secondaryLane, /bottom:\s*0/, "secondary lane should be the bottom lane");
67
+ assert.match(secondaryLane, /var\(--usage-secondary\)/, "bottom lane width should use the secondary percentage");
68
+ assert.match(foreground, /position:\s*relative/, "Usage content should establish foreground positioning");
69
+ assert.match(foreground, /z-index:\s*1/, "Usage text should stay above both overlays");
70
+
71
+ console.log("footer provider usage visual static tests passed");
@@ -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");