@firstpick/pi-package-webui 0.5.8 → 0.5.9

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/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=59" />
15
+ <link rel="stylesheet" href="/styles.css?v=60" />
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">
@@ -123,6 +123,7 @@
123
123
  aria-live="polite"
124
124
  >Follow-up</button>
125
125
  <div id="sessionSkillTags" class="composer-skill-tags" aria-live="polite" hidden></div>
126
+ <button id="conversationModeChip" class="composer-conversation-mode-chip" type="button" aria-live="polite" hidden>Voice: off</button>
126
127
  </div>
127
128
  <div id="busyPromptBehaviorMenu" class="composer-busy-mode-menu" role="menu" aria-labelledby="busyPromptBehaviorTag" hidden>
128
129
  <button class="composer-busy-mode-menu-item" type="button" role="menuitemradio" data-busy-prompt-behavior="followUp" aria-checked="true">
@@ -212,12 +213,15 @@
212
213
  aria-haspopup="menu"
213
214
  aria-expanded="false"
214
215
  aria-controls="optionsMenu"
215
- data-tooltip="Options: command palette, resume, reload, remote, name, clone, settings, export, fork, or tree."
216
+ data-tooltip="Options: command palette, natural conversation, resume, reload, remote, name, clone, settings, export, fork, or tree."
216
217
  ><svg class="composer-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 7h16M4 12h16M4 17h16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><circle cx="8" cy="7" r="1.6" fill="currentColor"/><circle cx="16" cy="12" r="1.6" fill="currentColor"/><circle cx="11" cy="17" r="1.6" fill="currentColor"/></svg></button>
217
218
  <div id="optionsMenu" class="composer-publish-menu-panel composer-options-menu-panel" role="menu" aria-label="Common Pi options">
218
219
  <button id="optionsCommandPaletteButton" class="composer-publish-menu-item composer-options-menu-item" type="button" role="menuitem">
219
220
  <span>Command Palette</span>
220
221
  </button>
222
+ <button id="optionsConversationModeButton" class="composer-publish-menu-item composer-options-menu-item composer-conversation-menu-item" type="button" role="menuitem" data-command="/talk" hidden>
223
+ <span>Start Conversation</span>
224
+ </button>
221
225
  <button id="optionsTreeButton" class="composer-publish-menu-item composer-options-menu-item" type="button" role="menuitem" data-command="/tree">
222
226
  <span>Tree</span>
223
227
  </button>
@@ -290,6 +294,7 @@
290
294
  aria-label="Follow-up: type your message first, then tap this button to send it as a follow-up."
291
295
  data-tooltip="Follow-up usage:&#10;1. Type your message in the textarea.&#10;2. Tap Follow-up to send it as a follow-up.&#10;Use for extra context or the next request."
292
296
  >Follow-up</button>
297
+ <button id="conversationModeEndButton" class="composer-conversation-end-button" type="button" title="End Natural Conversation Mode for this Pi tab" aria-label="End Natural Conversation Mode" hidden>End conversation</button>
293
298
  <button id="abortButton" class="composer-abort-button danger" type="button" title="Hold Esc or the Abort button for 3 seconds to abort the active Pi run" aria-label="Hold Esc or the Abort button for 3 seconds to abort the active Pi run" hidden disabled>Abort</button>
294
299
  <button
295
300
  id="btwButton"
@@ -395,7 +400,10 @@
395
400
  <span id="remoteAuthStatus" class="toggle-control-hint">Off</span>
396
401
  </span>
397
402
  </label>
398
- <button id="openNetworkButton" type="button">Open to network</button>
403
+ <div class="network-action-row">
404
+ <button id="openNetworkButton" type="button">Open to network</button>
405
+ <button id="showRemoteQrButton" type="button" hidden>Show QR code</button>
406
+ </div>
399
407
  </div>
400
408
  <div class="control-field server-control-field">
401
409
  <label for="serverActionSelect">Server</label>
@@ -746,6 +754,6 @@
746
754
  </form>
747
755
  </dialog>
748
756
 
749
- <script type="module" src="/app.js?v=58"></script>
757
+ <script type="module" src="/app.js?v=59"></script>
750
758
  </body>
751
759
  </html>
package/public/styles.css CHANGED
@@ -909,13 +909,15 @@ body.side-panel-collapsed .terminal-tabs-shell {
909
909
  gap: 0.42rem;
910
910
  align-items: center;
911
911
  }
912
- .server-action-row {
912
+ .server-action-row,
913
+ .network-action-row {
913
914
  display: grid;
914
915
  grid-template-columns: minmax(0, 1fr) auto;
915
916
  gap: 0.42rem;
916
917
  align-items: center;
917
918
  }
918
- .server-action-row button {
919
+ .server-action-row button,
920
+ .network-action-row button {
919
921
  width: auto;
920
922
  min-width: 4.4rem;
921
923
  }
@@ -1090,6 +1092,15 @@ body.side-panel-collapsed .terminal-tabs-shell {
1090
1092
  border-color: transparent;
1091
1093
  background: linear-gradient(120deg, var(--ctp-yellow), var(--ctp-peach), var(--ctp-red));
1092
1094
  }
1095
+ #showRemoteQrButton {
1096
+ color: var(--ctp-teal);
1097
+ border-color: rgba(148, 226, 213, 0.32);
1098
+ }
1099
+ #showRemoteQrButton:not(:disabled):hover {
1100
+ color: #11111b;
1101
+ border-color: transparent;
1102
+ background: linear-gradient(120deg, var(--ctp-teal), var(--ctp-sky), var(--ctp-blue));
1103
+ }
1093
1104
  .optional-features-description {
1094
1105
  margin: 0 0 0.58rem;
1095
1106
  font-size: 0.74rem;
@@ -1589,6 +1600,11 @@ body.side-panel-collapsed .terminal-tabs-shell {
1589
1600
  outline: 1px solid rgba(137, 180, 250, 0.42);
1590
1601
  outline-offset: -1px;
1591
1602
  }
1603
+ .terminal-tab.conversation-mode-running,
1604
+ .terminal-tab-group-item.conversation-mode-running {
1605
+ border-color: rgba(148, 226, 213, 0.68);
1606
+ box-shadow: 0 0 1.15rem rgba(148, 226, 213, 0.24), inset 0 1px 0 rgba(255,255,255,0.06);
1607
+ }
1592
1608
  .terminal-tab.terminal-tab-drag-over,
1593
1609
  .terminal-tab-group-item.terminal-tab-drag-over {
1594
1610
  border-color: rgba(137, 180, 250, 0.82);
@@ -1646,6 +1662,22 @@ body.side-panel-collapsed .terminal-tabs-shell {
1646
1662
  text-transform: uppercase;
1647
1663
  animation: terminal-tab-app-runner-pulse 1.35s ease-in-out infinite;
1648
1664
  }
1665
+ .terminal-tab-conversation-indicator {
1666
+ flex: 0 0 auto;
1667
+ padding: 0.04rem 0.36rem;
1668
+ border: 1px solid rgba(148, 226, 213, 0.46);
1669
+ border-radius: 999px;
1670
+ color: var(--ctp-teal);
1671
+ background: rgba(148, 226, 213, 0.13);
1672
+ box-shadow: 0 0 0.7rem rgba(148, 226, 213, 0.28);
1673
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
1674
+ font-size: 0.56rem;
1675
+ font-weight: 900;
1676
+ letter-spacing: 0.08em;
1677
+ line-height: 1.12;
1678
+ text-transform: uppercase;
1679
+ animation: terminal-tab-app-runner-pulse 1.5s ease-in-out infinite;
1680
+ }
1649
1681
  .terminal-tab.activity-working > .terminal-tab-button .terminal-tab-activity-indicator {
1650
1682
  background: var(--ctp-yellow);
1651
1683
  box-shadow: 0 0 0 1px rgba(249, 226, 175, 0.34), 0 0 0.8rem rgba(249, 226, 175, 0.52);
@@ -2974,11 +3006,127 @@ button.footer-meta {
2974
3006
  font-weight: 800;
2975
3007
  text-align: center;
2976
3008
  }
3009
+ .git-pull-result-panel {
3010
+ display: grid;
3011
+ gap: 0.68rem;
3012
+ padding: 0.78rem;
3013
+ border: 1px solid rgba(166, 227, 161, 0.28);
3014
+ border-radius: 0.95rem;
3015
+ background:
3016
+ radial-gradient(circle at 0% 0%, rgba(166, 227, 161, 0.14), transparent 18rem),
3017
+ linear-gradient(135deg, rgba(var(--ctp-crust-rgb), 0.68), rgba(166, 227, 161, 0.07));
3018
+ box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 0.55rem 1.4rem rgba(var(--ctp-crust-rgb), 0.18);
3019
+ }
3020
+ .git-pull-result-header {
3021
+ display: flex;
3022
+ justify-content: space-between;
3023
+ gap: 0.75rem;
3024
+ min-width: 0;
3025
+ }
3026
+ .git-pull-result-copy {
3027
+ display: grid;
3028
+ gap: 0.12rem;
3029
+ min-width: 0;
3030
+ }
3031
+ .git-pull-result-kicker,
3032
+ .git-pull-file-list-label {
3033
+ color: var(--ctp-green);
3034
+ font-size: 0.66rem;
3035
+ font-weight: 950;
3036
+ letter-spacing: 0.14em;
3037
+ text-transform: uppercase;
3038
+ }
3039
+ .git-pull-result-copy strong {
3040
+ color: var(--ctp-text);
3041
+ font-size: 1rem;
3042
+ }
3043
+ .git-pull-result-meta {
3044
+ min-width: 0;
3045
+ overflow: hidden;
3046
+ color: rgba(var(--ctp-subtext-rgb), 0.72);
3047
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
3048
+ font-size: 0.76rem;
3049
+ text-overflow: ellipsis;
3050
+ white-space: nowrap;
3051
+ }
3052
+ .git-pull-result-metrics,
2977
3053
  .git-changes-overview {
2978
3054
  display: grid;
2979
3055
  grid-template-columns: repeat(5, minmax(7rem, 1fr));
2980
3056
  gap: 0.5rem;
2981
3057
  }
3058
+ .git-pull-result-metrics {
3059
+ grid-template-columns: repeat(4, minmax(7rem, 1fr));
3060
+ }
3061
+ .git-pull-file-list {
3062
+ display: grid;
3063
+ grid-template-columns: repeat(2, minmax(0, 1fr));
3064
+ gap: 0.42rem;
3065
+ min-width: 0;
3066
+ }
3067
+ .git-pull-file-list-label {
3068
+ grid-column: 1 / -1;
3069
+ }
3070
+ .git-pull-file {
3071
+ display: flex;
3072
+ align-items: center;
3073
+ justify-content: space-between;
3074
+ gap: 0.75rem;
3075
+ min-width: 0;
3076
+ padding: 0.42rem 0.56rem;
3077
+ border: 1px solid rgba(180, 190, 254, 0.14);
3078
+ border-radius: 0.58rem;
3079
+ background: rgba(var(--ctp-crust-rgb), 0.42);
3080
+ }
3081
+ .git-pull-file-path,
3082
+ .git-pull-file-stats {
3083
+ min-width: 0;
3084
+ overflow: hidden;
3085
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
3086
+ text-overflow: ellipsis;
3087
+ white-space: nowrap;
3088
+ }
3089
+ .git-pull-file-path {
3090
+ color: var(--ctp-text);
3091
+ font-weight: 850;
3092
+ }
3093
+ .git-pull-file-stats {
3094
+ flex: 0 0 auto;
3095
+ color: rgba(var(--ctp-subtext-rgb), 0.78);
3096
+ font-size: 0.76rem;
3097
+ font-weight: 850;
3098
+ }
3099
+ .git-pull-file.success .git-pull-file-stats { color: var(--ctp-green); }
3100
+ .git-pull-file.danger .git-pull-file-stats { color: var(--ctp-red); }
3101
+ .git-pull-result-more {
3102
+ grid-column: 1 / -1;
3103
+ color: rgba(var(--ctp-subtext-rgb), 0.72);
3104
+ font-size: 0.78rem;
3105
+ font-weight: 760;
3106
+ }
3107
+ .git-pull-output-details {
3108
+ overflow: hidden;
3109
+ border: 1px solid rgba(180, 190, 254, 0.14);
3110
+ border-radius: 0.68rem;
3111
+ background: rgba(var(--ctp-mantle-rgb), 0.42);
3112
+ }
3113
+ .git-pull-output-details summary {
3114
+ cursor: pointer;
3115
+ padding: 0.48rem 0.62rem;
3116
+ color: rgba(var(--ctp-subtext-rgb), 0.82);
3117
+ font-weight: 900;
3118
+ }
3119
+ .git-pull-output-details pre {
3120
+ max-height: 18rem;
3121
+ margin: 0;
3122
+ overflow: auto;
3123
+ padding: 0.62rem;
3124
+ border-top: 1px solid rgba(180, 190, 254, 0.12);
3125
+ color: rgba(var(--ctp-subtext-rgb), 0.84);
3126
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
3127
+ font-size: 0.78rem;
3128
+ white-space: pre-wrap;
3129
+ }
2982
3130
  .git-changes-chip {
2983
3131
  min-width: 0;
2984
3132
  padding: 0.48rem 0.58rem;
@@ -4938,6 +5086,67 @@ summary { cursor: pointer; color: var(--warning); }
4938
5086
  .composer-skill-tags[hidden] {
4939
5087
  display: none !important;
4940
5088
  }
5089
+ .composer-conversation-mode-chip {
5090
+ flex: 0 0 auto;
5091
+ min-height: 0;
5092
+ max-width: min(14rem, 100%);
5093
+ margin: 0;
5094
+ padding: 0.14rem 0.56rem;
5095
+ border: 1px solid rgba(148, 226, 213, 0.52);
5096
+ border-radius: 999px;
5097
+ color: var(--ctp-teal);
5098
+ background:
5099
+ linear-gradient(120deg, rgba(148, 226, 213, 0.28), rgba(166, 227, 161, 0.10)),
5100
+ var(--ctp-crust);
5101
+ box-shadow: 0 0.42rem 1rem rgba(var(--ctp-crust-rgb), 0.42), 0 0 1rem rgba(148, 226, 213, 0.22);
5102
+ font-size: 0.62rem;
5103
+ font-weight: 900;
5104
+ letter-spacing: 0.08em;
5105
+ line-height: 1.1;
5106
+ text-overflow: ellipsis;
5107
+ text-transform: uppercase;
5108
+ white-space: nowrap;
5109
+ }
5110
+ .composer-conversation-mode-chip[hidden],
5111
+ .composer-conversation-end-button[hidden] {
5112
+ display: none !important;
5113
+ }
5114
+ .composer-conversation-mode-chip:hover,
5115
+ .composer-conversation-mode-chip:focus-visible {
5116
+ border-color: rgba(148, 226, 213, 0.78);
5117
+ box-shadow: 0 0.42rem 1rem rgba(var(--ctp-crust-rgb), 0.42), 0 0 1.25rem rgba(148, 226, 213, 0.34);
5118
+ transform: translateY(-1px);
5119
+ }
5120
+ .composer.conversation-mode-active {
5121
+ border-color: rgba(148, 226, 213, 0.54);
5122
+ box-shadow: 0 0 1.35rem rgba(148, 226, 213, 0.22), 0 1.2rem 2.6rem rgba(var(--ctp-crust-rgb), 0.34);
5123
+ }
5124
+ body.conversation-mode-active .composer::before {
5125
+ opacity: 1;
5126
+ background: linear-gradient(90deg, transparent, var(--ctp-teal), var(--ctp-green), var(--ctp-teal), transparent);
5127
+ }
5128
+ .composer-conversation-menu-item.active {
5129
+ color: var(--ctp-teal);
5130
+ border-color: rgba(148, 226, 213, 0.50);
5131
+ background:
5132
+ linear-gradient(120deg, rgba(148, 226, 213, 0.20), rgba(166, 227, 161, 0.10)),
5133
+ var(--ctp-crust);
5134
+ }
5135
+ .composer-conversation-end-button {
5136
+ min-width: 8.4rem;
5137
+ color: var(--ctp-teal);
5138
+ border-color: rgba(148, 226, 213, 0.44);
5139
+ background:
5140
+ linear-gradient(120deg, rgba(148, 226, 213, 0.20), rgba(166, 227, 161, 0.10)),
5141
+ var(--ctp-crust);
5142
+ box-shadow: 0 0 1rem rgba(148, 226, 213, 0.22), inset 0 1px 0 rgba(255,255,255,0.05);
5143
+ }
5144
+ .composer-conversation-end-button:hover,
5145
+ .composer-conversation-end-button:focus-visible {
5146
+ color: #11111b;
5147
+ border-color: transparent;
5148
+ background: linear-gradient(120deg, var(--ctp-teal), var(--ctp-green));
5149
+ }
4941
5150
  .composer-skill-tag {
4942
5151
  display: inline-flex;
4943
5152
  align-items: center;
@@ -0,0 +1,114 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawn } from "node:child_process";
3
+ import { chmod, mkdtemp, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import path from "node:path";
6
+ import { setTimeout as delay } from "node:timers/promises";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
11
+ const serverScript = join(root, "bin", "pi-webui.mjs");
12
+ const compactingPi = join(root, "tests", "fixtures", "compacting-pi.mjs");
13
+ const port = 30000 + Math.floor(Math.random() * 20000);
14
+ const COMPACTION_TRIGGER = "__pi_webui_test_start_compaction__";
15
+ const RESUME_PROMPT = "resume automatically after compaction";
16
+
17
+ async function request(pathname, { method = "GET", body, timeoutMs = 5_000 } = {}) {
18
+ const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
19
+ method,
20
+ headers: body === undefined ? undefined : { "content-type": "application/json" },
21
+ body: body === undefined ? undefined : JSON.stringify(body),
22
+ signal: AbortSignal.timeout(timeoutMs),
23
+ });
24
+ let payload;
25
+ try {
26
+ payload = await response.json();
27
+ } catch {
28
+ payload = undefined;
29
+ }
30
+ return { status: response.status, body: payload };
31
+ }
32
+
33
+ async function waitFor(description, probe, { attempts = 60, intervalMs = 100 } = {}) {
34
+ let last;
35
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
36
+ last = await probe();
37
+ if (last) return last;
38
+ await delay(intervalMs);
39
+ }
40
+ assert.fail(`${description} did not happen in time${last ? `; last=${JSON.stringify(last)}` : ""}`);
41
+ }
42
+
43
+ const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-compaction-resume-"));
44
+ const settingsFile = path.join(cwd, "webui-settings.json");
45
+ await chmod(compactingPi, 0o755);
46
+
47
+ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "127.0.0.1", "--port", String(port), "--pi", compactingPi], {
48
+ stdio: ["ignore", "pipe", "pipe"],
49
+ env: { ...process.env, PI_WEBUI_SETTINGS_FILE: settingsFile },
50
+ });
51
+ let serverOutput = "";
52
+ child.stdout.on("data", (chunk) => { serverOutput += String(chunk); });
53
+ child.stderr.on("data", (chunk) => { serverOutput += String(chunk); });
54
+
55
+ try {
56
+ await waitFor("server health", async () => {
57
+ if (child.exitCode !== null) return false;
58
+ try {
59
+ const health = await request("/api/health", { timeoutMs: 1_000 });
60
+ return health.status === 200 && health.body?.ok === true ? health : false;
61
+ } catch {
62
+ return false;
63
+ }
64
+ }, { attempts: 100, intervalMs: 120 });
65
+
66
+ const tabsResponse = await request("/api/tabs");
67
+ assert.equal(tabsResponse.status, 200);
68
+ const tabId = tabsResponse.body?.data?.tabs?.[0]?.id || tabsResponse.body?.tabs?.[0]?.id;
69
+ assert.ok(tabId, "startup tab should have an id");
70
+
71
+ const startCompaction = await request("/api/prompt", {
72
+ method: "POST",
73
+ body: { tab: tabId, message: COMPACTION_TRIGGER },
74
+ });
75
+ assert.equal(startCompaction.status, 200, `compaction trigger should be accepted: ${startCompaction.body?.error || serverOutput}`);
76
+
77
+ await waitFor("compaction_start state", async () => {
78
+ const state = await request(`/api/state?tab=${encodeURIComponent(tabId)}`);
79
+ return state.body?.data?.isCompacting === true ? state : false;
80
+ });
81
+
82
+ const queuedPrompt = await request("/api/prompt", {
83
+ method: "POST",
84
+ body: { tab: tabId, message: RESUME_PROMPT },
85
+ });
86
+ assert.equal(queuedPrompt.status, 202, "prompt sent during compaction should be accepted into the Web UI resume queue");
87
+ assert.equal(queuedPrompt.body?.data?.queuedFor, "compaction");
88
+ assert.equal(queuedPrompt.body?.data?.queueLength, 1);
89
+
90
+ const messagesBeforeEnd = await request(`/api/messages?tab=${encodeURIComponent(tabId)}`);
91
+ assert.equal(messagesBeforeEnd.status, 200);
92
+ assert.equal((messagesBeforeEnd.body?.data?.messages || []).some((message) => String(message.content || "").includes(RESUME_PROMPT)), false, "queued prompt should not reach Pi before compaction_end");
93
+
94
+ await waitFor("compaction to finish", async () => {
95
+ const state = await request(`/api/state?tab=${encodeURIComponent(tabId)}`);
96
+ return state.body?.data?.isCompacting === false ? state : false;
97
+ }, { attempts: 80, intervalMs: 100 });
98
+
99
+ const resumedMessages = await waitFor("queued prompt to resume after compaction", async () => {
100
+ const messages = await request(`/api/messages?tab=${encodeURIComponent(tabId)}`);
101
+ const entries = messages.body?.data?.messages || [];
102
+ return entries.some((message) => String(message.content || "").includes(`prompt:${RESUME_PROMPT}`)) ? messages : false;
103
+ }, { attempts: 80, intervalMs: 100 });
104
+ assert.equal(resumedMessages.status, 200);
105
+
106
+ await request("/api/shutdown", { method: "POST" }).catch(() => undefined);
107
+ for (let attempt = 0; attempt < 50 && child.exitCode === null; attempt += 1) await delay(100);
108
+ assert.notEqual(child.exitCode, null, "server should exit after /api/shutdown");
109
+ } finally {
110
+ if (child.exitCode === null) child.kill("SIGKILL");
111
+ await rm(cwd, { recursive: true, force: true });
112
+ }
113
+
114
+ console.log("compaction-resume-harness.test.mjs passed");
@@ -0,0 +1,25 @@
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 [server, app] = await Promise.all([
8
+ readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
9
+ readFile(join(root, "public", "app.js"), "utf8"),
10
+ ]);
11
+
12
+ assert.match(server, /function maybeQueueCommandDuringCompaction\(tab, command\)[\s\S]*tab\?\.lastState\?\.isCompacting[\s\S]*enqueueCommandUntilCompactionEnds/, "server should queue prompt-like commands while the tab is compacting");
13
+ assert.match(server, /url\.pathname === "\/api\/prompt" && req\.method === "POST"[\s\S]*maybeQueueCommandDuringCompaction\(tab, command\)[\s\S]*sendJson\(res, 202/, "POST /api/prompt should return 202 when a prompt is queued for post-compaction resume");
14
+ assert.match(server, /if \(command\) \{[\s\S]*maybeQueueCommandDuringCompaction\(tab, command\)[\s\S]*sendJson\(res, 202/, "generic prompt-like POST commands should share the compaction queue path");
15
+ assert.match(server, /event\?\.type === "compaction_end" && event\.aborted !== true\)[\s\S]*flushCompactionQueue\(tab, event\)/, "non-aborted compaction_end should flush the queued resume prompt");
16
+ assert.match(server, /async function flushCompactionQueue\(tab, event = \{\}\)[\s\S]*queuedRetryCommand\(item\)/, "compaction queue flush should resume queued commands into active auto-retry runs");
17
+ assert.match(server, /async function flushCompactionQueue\(tab, event = \{\}\)[\s\S]*queuedPromptCommand\(item\)/, "compaction queue flush should start a new prompt when no run resumes automatically");
18
+ assert.match(server, /async function flushCompactionQueue\(tab, event = \{\}\)[\s\S]*queuedStreamingCommand\(item\)/, "compaction queue flush should send later queued items as steering or follow-up messages");
19
+ assert.match(server, /function stateWithPendingThinking\(tab, state\)[\s\S]*compactionQueueForTab\(tab\)\.length[\s\S]*pendingMessageCount/, "state responses should include Web UI compaction queue length while prompts wait to resume");
20
+
21
+ assert.match(app, /function isRunActive\(\) \{\n\s+return !!currentState\?\.isStreaming \|\| !!currentState\?\.isCompacting/, "frontend should treat compaction as an active run for composer controls");
22
+ assert.match(app, /const targetWasCompacting = !!currentState\?\.isCompacting;[\s\S]*const targetWasBusy = targetWasStreaming \|\| targetWasCompacting[\s\S]*if \(targetWasBusy\) body\.streamingBehavior = streamingBehavior \|\| busyBehavior/, "prompt send should use busy behavior while streaming or compacting");
23
+ assert.match(app, /case "webui_compaction_queue_update":[\s\S]*renderQueue\(event\)[\s\S]*queued compaction prompt sent; Pi is resuming/, "frontend should surface compaction queue and resume events");
24
+
25
+ console.log("compaction-static.test.mjs passed");
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env node
2
+ // JSONL RPC fixture that simulates a Pi session compacting while the Web UI
3
+ // queues a prompt for automatic resume after compaction_end.
4
+ import { createInterface } from "node:readline";
5
+
6
+ const COMPACTION_TRIGGER = "__pi_webui_test_start_compaction__";
7
+
8
+ let isCompacting = false;
9
+ let compactionTimer = null;
10
+ const received = [];
11
+
12
+ function respond(payload) {
13
+ process.stdout.write(`${JSON.stringify(payload)}\n`);
14
+ }
15
+
16
+ function emit(payload) {
17
+ process.stdout.write(`${JSON.stringify(payload)}\n`);
18
+ }
19
+
20
+ function statePayload() {
21
+ return {
22
+ model: { provider: "fake", id: "fake-model" },
23
+ thinkingLevel: "off",
24
+ isStreaming: false,
25
+ isCompacting,
26
+ steeringMode: "one-at-a-time",
27
+ followUpMode: "one-at-a-time",
28
+ sessionFile: undefined,
29
+ sessionId: "fake-compaction-session",
30
+ sessionName: "fake-compaction",
31
+ autoCompactionEnabled: true,
32
+ messageCount: received.length,
33
+ pendingMessageCount: 0,
34
+ };
35
+ }
36
+
37
+ function finishCompaction() {
38
+ compactionTimer = null;
39
+ isCompacting = false;
40
+ emit({
41
+ type: "compaction_end",
42
+ reason: "test",
43
+ result: { summary: "fake compaction summary", tokensBefore: 1000, estimatedTokensAfter: 100 },
44
+ aborted: false,
45
+ willRetry: false,
46
+ });
47
+ }
48
+
49
+ function startCompaction() {
50
+ if (compactionTimer) clearTimeout(compactionTimer);
51
+ isCompacting = true;
52
+ emit({ type: "compaction_start", reason: "test" });
53
+ compactionTimer = setTimeout(finishCompaction, 1500);
54
+ }
55
+
56
+ const rl = createInterface({ input: process.stdin });
57
+ rl.on("line", (line) => {
58
+ if (!line.trim()) return;
59
+ let command;
60
+ try {
61
+ command = JSON.parse(line);
62
+ } catch {
63
+ return;
64
+ }
65
+
66
+ const { id, type } = command || {};
67
+ if (!id || !type) return;
68
+ const base = { type: "response", id, command: type, success: true };
69
+
70
+ switch (type) {
71
+ case "get_state":
72
+ respond({ ...base, data: statePayload() });
73
+ return;
74
+ case "get_messages":
75
+ respond({
76
+ ...base,
77
+ data: {
78
+ messages: received.map((entry, index) => ({
79
+ role: "user",
80
+ content: `${entry.type}:${entry.message}`,
81
+ timestamp: 1000 + index,
82
+ })),
83
+ },
84
+ });
85
+ return;
86
+ case "get_available_models":
87
+ respond({ ...base, data: { models: [{ provider: "fake", id: "fake-model", name: "Fake Model" }] } });
88
+ return;
89
+ case "get_session_stats":
90
+ respond({ ...base, data: { tokens: 0 } });
91
+ return;
92
+ case "prompt": {
93
+ const message = String(command.message || "");
94
+ if (message === COMPACTION_TRIGGER) {
95
+ startCompaction();
96
+ respond({ ...base, data: { compacting: true } });
97
+ return;
98
+ }
99
+ received.push({ type: "prompt", message, streamingBehavior: command.streamingBehavior || "" });
100
+ respond({ ...base, data: { received: received.length } });
101
+ return;
102
+ }
103
+ case "steer":
104
+ case "follow_up":
105
+ received.push({ type, message: String(command.message || "") });
106
+ respond({ ...base, data: { received: received.length } });
107
+ return;
108
+ default:
109
+ respond({ ...base, data: {} });
110
+ }
111
+ });
112
+
113
+ process.on("exit", () => {
114
+ if (compactionTimer) clearTimeout(compactionTimer);
115
+ });
@@ -2,17 +2,62 @@
2
2
  // Minimal JSONL RPC stub standing in for the pi coding agent so HTTP endpoint
3
3
  // tests can boot the real pi-webui server without a model provider.
4
4
  import { createInterface } from "node:readline";
5
+ import { randomUUID } from "node:crypto";
5
6
 
6
7
  const sessionIndex = process.argv.indexOf("--session");
7
8
  const sessionFile = sessionIndex !== -1 ? process.argv[sessionIndex + 1] : undefined;
8
9
 
9
10
  let activeBash = 0;
10
11
  let peakBash = 0;
12
+ let thinkingLevel = "off";
13
+ let conversationEnabled = false;
11
14
 
12
15
  function respond(payload) {
13
16
  process.stdout.write(`${JSON.stringify(payload)}\n`);
14
17
  }
15
18
 
19
+ function emitEvent(payload) {
20
+ process.stdout.write(`${JSON.stringify(payload)}\n`);
21
+ }
22
+
23
+ function conversationStatusText() {
24
+ return conversationEnabled ? "Voice: listening" : "";
25
+ }
26
+
27
+ function emitConversationStatus() {
28
+ emitEvent({
29
+ type: "extension_ui_request",
30
+ id: randomUUID(),
31
+ method: "setStatus",
32
+ statusKey: "natural-conversation",
33
+ statusText: conversationStatusText(),
34
+ });
35
+ }
36
+
37
+ function handleTalkPrompt(command, base) {
38
+ const message = String(command.message || "").trim();
39
+ const match = message.match(/^\/(talk|voice|conversation)(?:\s+(\S+))?/i);
40
+ if (!match) return false;
41
+ const subcommand = String(match[2] || "").toLowerCase();
42
+ if (!subcommand) conversationEnabled = !conversationEnabled;
43
+ else if (["on", "enable", "start"].includes(subcommand)) conversationEnabled = true;
44
+ else if (["off", "disable", "end", "stop"].includes(subcommand)) conversationEnabled = false;
45
+ emitConversationStatus();
46
+ respond({
47
+ ...base,
48
+ data: {
49
+ output: conversationEnabled ? "Natural Conversation Mode on." : "Natural Conversation Mode off.",
50
+ conversationMode: {
51
+ enabled: conversationEnabled,
52
+ uiState: conversationEnabled ? "listening" : "off",
53
+ statusText: conversationStatusText(),
54
+ allowedTools: ["read", "grep", "find", "ls"],
55
+ },
56
+ },
57
+ });
58
+ return true;
59
+ }
60
+
16
61
  const rl = createInterface({ input: process.stdin });
17
62
  rl.on("line", (line) => {
18
63
  if (!line.trim()) return;
@@ -32,7 +77,7 @@ rl.on("line", (line) => {
32
77
  ...base,
33
78
  data: {
34
79
  model: { provider: "fake", id: "fake-model" },
35
- thinkingLevel: "off",
80
+ thinkingLevel,
36
81
  isStreaming: false,
37
82
  isCompacting: false,
38
83
  steeringMode: "one-at-a-time",
@@ -58,6 +103,26 @@ rl.on("line", (line) => {
58
103
  },
59
104
  });
60
105
  return;
106
+ case "get_commands":
107
+ respond({
108
+ ...base,
109
+ data: {
110
+ commands: [
111
+ { name: "talk", source: "extension", description: "Toggle Natural Conversation Mode" },
112
+ { name: "voice", source: "extension", description: "Natural Conversation Mode alias" },
113
+ { name: "conversation", source: "extension", description: "Natural Conversation Mode alias" },
114
+ ],
115
+ },
116
+ });
117
+ return;
118
+ case "prompt":
119
+ if (handleTalkPrompt(command, base)) return;
120
+ respond({ ...base, data: { output: "fake prompt accepted" } });
121
+ return;
122
+ case "set_thinking_level":
123
+ thinkingLevel = String(command.level || "off");
124
+ respond({ ...base, data: { level: thinkingLevel } });
125
+ return;
61
126
  case "get_available_models":
62
127
  respond({ ...base, data: { models: [{ provider: "fake", id: "fake-model", name: "Fake Model" }] } });
63
128
  return;