@firstpick/pi-package-webui 0.7.2 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +38 -25
  2. package/bin/pi-webui.mjs +469 -106
  3. package/index.ts +10 -1
  4. package/lib/git-live-watcher.mjs +135 -0
  5. package/lib/git-message-artifacts.mjs +103 -0
  6. package/lib/git-workflow-preferences.mjs +10 -3
  7. package/lib/process-tree.mjs +3 -1
  8. package/lib/webui-output-mode.mjs +97 -0
  9. package/package.json +7 -6
  10. package/public/app.js +1170 -97
  11. package/public/fast-output-live.mjs +179 -0
  12. package/public/index.html +31 -5
  13. package/public/service-worker.js +2 -1
  14. package/public/styles.css +474 -12
  15. package/tests/app-runner-windows-conpty-harness.test.mjs +140 -0
  16. package/tests/danger-button-contrast-static.test.mjs +32 -0
  17. package/tests/fast-mode-client-static.test.mjs +121 -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 +59 -0
  22. package/tests/fixtures/fast-mode-output-events.mjs +50 -0
  23. package/tests/footer-middle-truncation.test.mjs +118 -0
  24. package/tests/git-live-watcher.test.mjs +93 -0
  25. package/tests/git-message-artifacts.test.mjs +59 -0
  26. package/tests/git-panel-live-updates-static.test.mjs +54 -0
  27. package/tests/git-panel-render-stability-static.test.mjs +1 -1
  28. package/tests/git-workflow-preferences.test.mjs +8 -2
  29. package/tests/guided-git-message-reliability-static.test.mjs +38 -0
  30. package/tests/http-endpoints-harness.test.mjs +61 -5
  31. package/tests/image-payload-hardening-harness.test.mjs +115 -0
  32. package/tests/mobile-static.test.mjs +79 -20
  33. package/tests/pi-footer-calibration-static.test.mjs +55 -0
  34. package/tests/remote-auth-settings-harness.test.mjs +1 -1
  35. package/tests/runtime-error-visibility.test.mjs +63 -0
  36. package/tests/side-panel-context-menu-static.test.mjs +74 -0
  37. package/tests/webui-output-mode.test.mjs +73 -0
@@ -0,0 +1,179 @@
1
+ export const FAST_OUTPUT_FLUSH_INTERVAL_MS = 100;
2
+
3
+ function text(value) {
4
+ return typeof value === "string" ? value : "";
5
+ }
6
+
7
+ function toolCallName(update = {}) {
8
+ const value = update.name || update.toolName || update.toolCall?.name || "";
9
+ return text(value).trim();
10
+ }
11
+
12
+ function toolCallId(update = {}) {
13
+ const value = update.toolCallId || update.toolCall?.id || update.id || "";
14
+ return text(value).trim();
15
+ }
16
+
17
+ function toolCallArguments(update = {}) {
18
+ const value = update.toolCall?.arguments ?? update.arguments ?? update.args;
19
+ if (typeof value === "string") return value;
20
+ if (value === undefined || value === null) return "";
21
+ try {
22
+ return JSON.stringify(value);
23
+ } catch {
24
+ return "";
25
+ }
26
+ }
27
+
28
+ export function createFastOutputLiveState() {
29
+ return {
30
+ text: "",
31
+ thinking: "",
32
+ toolCall: { id: "", name: "", arguments: "", complete: false },
33
+ changed: false,
34
+ };
35
+ }
36
+
37
+ export function seedFastOutputLiveState({ text: seededText = "", thinking: seededThinking = "" } = {}) {
38
+ return {
39
+ ...createFastOutputLiveState(),
40
+ text: text(seededText),
41
+ thinking: text(seededThinking),
42
+ };
43
+ }
44
+
45
+ export function fastOutputLiveTextAndThinking(state = {}) {
46
+ return {
47
+ text: text(state.text),
48
+ thinking: text(state.thinking),
49
+ };
50
+ }
51
+
52
+ export function shouldConsumeFastOutputLiveEvent(reduction = {}) {
53
+ return reduction.changed === true || ["text-end", "thinking-end", "toolcall-end"].includes(reduction.kind);
54
+ }
55
+
56
+ /**
57
+ * Pure compact-v1 reducer. It consumes only the direct compact fields: no
58
+ * accumulated message or partial snapshot is read, so raw Unicode deltas stay
59
+ * intact until final transcript reconciliation.
60
+ */
61
+ export function reduceFastOutputLiveEvent(state = createFastOutputLiveState(), event = {}) {
62
+ const update = event?.type === "message_update" && event.assistantMessageEvent && typeof event.assistantMessageEvent === "object"
63
+ ? event.assistantMessageEvent
64
+ : null;
65
+ if (!update) return { state, changed: false, kind: "ignored" };
66
+
67
+ const current = {
68
+ text: text(state.text),
69
+ thinking: text(state.thinking),
70
+ toolCall: { ...createFastOutputLiveState().toolCall, ...(state.toolCall || {}) },
71
+ changed: false,
72
+ };
73
+ const delta = text(update.delta);
74
+ let changed = false;
75
+ let kind = "ignored";
76
+
77
+ if (update.type === "text_delta") {
78
+ current.text += delta;
79
+ changed = true;
80
+ kind = "text";
81
+ } else if (update.type === "thinking_delta") {
82
+ current.thinking += delta;
83
+ changed = true;
84
+ kind = "thinking";
85
+ } else if (update.type === "toolcall_delta") {
86
+ current.toolCall = {
87
+ ...current.toolCall,
88
+ id: toolCallId(update) || current.toolCall.id,
89
+ name: toolCallName(update) || current.toolCall.name,
90
+ arguments: current.toolCall.arguments + delta,
91
+ complete: false,
92
+ };
93
+ changed = true;
94
+ kind = "toolcall";
95
+ } else if (update.type === "text_end") {
96
+ const finalText = text(update.content) || text(update.text) || delta;
97
+ if (finalText) current.text = finalText;
98
+ changed = Boolean(finalText);
99
+ kind = "text-end";
100
+ } else if (update.type === "thinking_end") {
101
+ const finalThinking = text(update.content) || text(update.thinking) || delta;
102
+ if (finalThinking) current.thinking = finalThinking;
103
+ changed = Boolean(finalThinking);
104
+ kind = "thinking-end";
105
+ } else if (update.type === "toolcall_end" || update.type === "tool_call_end") {
106
+ const argumentsText = toolCallArguments(update) || delta || current.toolCall.arguments;
107
+ current.toolCall = {
108
+ ...current.toolCall,
109
+ id: toolCallId(update) || current.toolCall.id,
110
+ name: toolCallName(update) || current.toolCall.name,
111
+ arguments: argumentsText,
112
+ complete: true,
113
+ };
114
+ changed = true;
115
+ kind = "toolcall-end";
116
+ }
117
+
118
+ if (!changed) return { state, changed: false, kind };
119
+ current.changed = true;
120
+ return { state: current, changed: true, kind };
121
+ }
122
+
123
+ /**
124
+ * First output flushes immediately. Later writes coalesce to a maximum of one
125
+ * flush per interval. The clock and timer hooks make this deterministic in
126
+ * Node tests as well as browsers.
127
+ */
128
+ export function createSustainedFlushScheduler({
129
+ flush,
130
+ now = () => Date.now(),
131
+ setTimer = (callback, delay) => setTimeout(callback, delay),
132
+ clearTimer = (timer) => clearTimeout(timer),
133
+ intervalMs = FAST_OUTPUT_FLUSH_INTERVAL_MS,
134
+ } = {}) {
135
+ if (typeof flush !== "function") throw new TypeError("flush is required");
136
+ let timer = null;
137
+ let pending = false;
138
+ let lastFlushAt = null;
139
+
140
+ const run = () => {
141
+ timer = null;
142
+ if (!pending) return false;
143
+ pending = false;
144
+ lastFlushAt = now();
145
+ flush();
146
+ return true;
147
+ };
148
+
149
+ const schedule = () => {
150
+ if (timer !== null || !pending) return;
151
+ const elapsed = lastFlushAt === null ? intervalMs : Math.max(0, now() - lastFlushAt);
152
+ timer = setTimer(run, Math.max(0, intervalMs - elapsed));
153
+ };
154
+
155
+ return {
156
+ request() {
157
+ pending = true;
158
+ if (lastFlushAt === null) return run();
159
+ schedule();
160
+ return false;
161
+ },
162
+ flushNow() {
163
+ if (timer !== null) {
164
+ clearTimer(timer);
165
+ timer = null;
166
+ }
167
+ return run();
168
+ },
169
+ cancel() {
170
+ if (timer !== null) clearTimer(timer);
171
+ timer = null;
172
+ pending = false;
173
+ lastFlushAt = null;
174
+ },
175
+ pending() {
176
+ return pending;
177
+ },
178
+ };
179
+ }
package/public/index.html CHANGED
@@ -12,7 +12,7 @@
12
12
  <link rel="manifest" href="/manifest.webmanifest" />
13
13
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
14
14
  <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
15
- <link rel="stylesheet" href="/styles.css?v=80" />
15
+ <link rel="stylesheet" href="/styles.css?v=81" />
16
16
  </head>
17
17
  <body>
18
18
  <button id="sidePanelExpandButton" class="side-panel-expand-button" type="button" aria-controls="sidePanel" aria-expanded="false" aria-label="Expand side panel" title="Expand side panel">
@@ -147,6 +147,7 @@
147
147
  aria-live="polite"
148
148
  >Follow-up</button>
149
149
  <div id="sessionSkillTags" class="composer-skill-tags" aria-live="polite" hidden></div>
150
+ <span id="featureCategoryTag" class="composer-feature-category-tag" aria-live="polite" aria-atomic="true" hidden></span>
150
151
  <button id="conversationModeChip" class="composer-conversation-mode-chip" type="button" aria-live="polite" hidden>Voice: off</button>
151
152
  <button id="workflowModeChip" class="composer-workflow-mode-chip" type="button" aria-live="polite" aria-pressed="true" hidden>Workflow: on</button>
152
153
  </div>
@@ -399,7 +400,7 @@
399
400
  </div>
400
401
  </div>
401
402
  <div class="file-viewer-content">
402
- <textarea id="fileViewerEditor" class="file-viewer-editor" spellcheck="false" aria-label="File contents"></textarea>
403
+ <textarea id="fileViewerEditor" class="file-viewer-editor" wrap="soft" spellcheck="false" aria-label="File contents"></textarea>
403
404
  <div id="fileViewerPreview" class="file-viewer-preview markdown-body" tabindex="0" hidden></div>
404
405
  </div>
405
406
  <p id="fileViewerStatus" class="file-viewer-status muted" role="status" aria-live="polite"></p>
@@ -437,7 +438,7 @@
437
438
  </h2>
438
439
  <div id="sidePanelSectionControls" class="side-panel-section-content" hidden>
439
440
  <div class="side-panel-controls">
440
- <p class="controls-intro">Session controls affect the active Pi tab. Interface preferences are saved in this browser.</p>
441
+ <p class="controls-intro">Session controls affect the active Pi tab. Interface preferences are saved in this browser. Output processing is a shared server default.</p>
441
442
 
442
443
  <section class="control-group" aria-labelledby="sessionControlsTitle">
443
444
  <div class="control-group-header">
@@ -547,6 +548,30 @@
547
548
  </div>
548
549
  </section>
549
550
 
551
+ <section class="control-group output-processing-control-group" aria-labelledby="outputProcessingControlsTitle">
552
+ <div class="control-group-header">
553
+ <div class="control-group-heading">
554
+ <h3 id="outputProcessingControlsTitle">Output processing</h3>
555
+ <p>Choose the default live-output path for auto-negotiated Web UI connections.</p>
556
+ </div>
557
+ <span class="control-scope-badge">Server</span>
558
+ </div>
559
+ <div class="control-field">
560
+ <div class="control-field-header">
561
+ <label for="fastOutputModeSelect">Fast mode</label>
562
+ <span class="control-field-context">Rich final output is preserved</span>
563
+ </div>
564
+ <div class="control-action-row">
565
+ <select id="fastOutputModeSelect" title="Output processing mode" aria-describedby="fastOutputModeStatus">
566
+ <option value="normal">Normal</option>
567
+ <option value="compact-v1">Fast</option>
568
+ </select>
569
+ <button id="setFastOutputModeButton" class="control-apply-button" type="button" aria-label="Apply selected output processing mode" disabled>Apply</button>
570
+ </div>
571
+ <div id="fastOutputModeStatus" class="toggle-control-hint" role="status" aria-live="polite">Loading server default…</div>
572
+ </div>
573
+ </section>
574
+
550
575
  <section id="networkControlField" class="control-group network-control-field" aria-labelledby="remoteAccessControlsTitle" hidden>
551
576
  <div class="control-group-header">
552
577
  <div class="control-group-heading">
@@ -650,7 +675,7 @@
650
675
  <div id="sidePanelSectionOptionalFeatures" class="side-panel-section-content" hidden>
651
676
  <p class="optional-features-description muted">
652
677
  For additional WebUI feature requests, please
653
- <a href="https://github.com/Firstp1ck/npm-packages/issues/new" target="_blank" rel="noopener noreferrer">open a GitHub issue</a>
678
+ <a href="https://github.com/Firstp1ck/pi-coding-agent-forge/issues/new" target="_blank" rel="noopener noreferrer">open a GitHub issue</a>
654
679
  so they can be reviewed and considered for implementation.
655
680
  </p>
656
681
  <div id="optionalFeaturesBox" class="optional-features-box muted">Checking optional features…</div>
@@ -775,6 +800,7 @@
775
800
  <button type="button" role="menuitem" class="danger" data-file-menu-action="delete">Delete…</button>
776
801
  </div>
777
802
  <div id="gitPanelContextMenu" class="file-context-menu git-side-panel-context-menu" role="menu" aria-label="Git actions" hidden></div>
803
+ <div id="sidePanelContextMenu" class="file-context-menu side-panel-context-menu" role="menu" aria-label="Choose visible side panel sections" hidden></div>
778
804
 
779
805
  <aside id="undoToast" class="undo-toast" aria-live="polite" aria-atomic="true" hidden>
780
806
  <span id="undoToastMessage" class="undo-toast-message"></span>
@@ -1090,6 +1116,6 @@
1090
1116
  </form>
1091
1117
  </dialog>
1092
1118
 
1093
- <script type="module" src="/app.js?v=80"></script>
1119
+ <script type="module" src="/app.js?v=82"></script>
1094
1120
  </body>
1095
1121
  </html>
@@ -1,9 +1,10 @@
1
- const CACHE_NAME = "pi-webui-pwa-v33";
1
+ const CACHE_NAME = "pi-webui-pwa-v35";
2
2
  const APP_SHELL = [
3
3
  "/",
4
4
  "/index.html",
5
5
  "/styles.css",
6
6
  "/app.js",
7
+ "/fast-output-live.mjs",
7
8
  "/voice-conversation.mjs",
8
9
  "/favicon.svg",
9
10
  "/apple-touch-icon.png",