@firstpick/pi-package-webui 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -20
- package/bin/pi-webui.mjs +332 -39
- package/index.ts +10 -1
- package/lib/git-workflow-preferences.mjs +91 -22
- package/lib/subagent-launch-slots.mjs +304 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/lib/webui-output-mode.mjs +97 -0
- package/package.json +22 -22
- package/public/app.js +1629 -69
- package/public/fast-output-live.mjs +179 -0
- package/public/index.html +86 -12
- package/public/service-worker.js +3 -1
- package/public/styles.css +769 -37
- package/public/subagent-launch-slot-state.mjs +64 -0
- package/tests/chat-scroll-intent-static.test.mjs +59 -0
- package/tests/custom-message-markdown-static.test.mjs +15 -0
- package/tests/fast-mode-client-static.test.mjs +169 -0
- package/tests/fast-mode-output-work.test.mjs +69 -0
- package/tests/fast-mode-sse-harness.test.mjs +204 -0
- package/tests/fast-output-live.test.mjs +106 -0
- package/tests/fixtures/fake-pi.mjs +58 -0
- package/tests/fixtures/fast-mode-output-events.mjs +50 -0
- package/tests/footer-middle-truncation.test.mjs +2 -2
- package/tests/git-workflow-preferences.test.mjs +8 -2
- package/tests/http-endpoints-harness.test.mjs +74 -0
- package/tests/mobile-static.test.mjs +86 -15
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +43 -0
- package/tests/subagent-launch-slot-state.test.mjs +36 -0
- package/tests/subagent-launch-slots-static.test.mjs +34 -0
- package/tests/subagent-launch-slots.test.mjs +143 -0
- package/tests/subagents-helper.test.mjs +46 -0
- package/tests/webui-output-mode.test.mjs +73 -0
- package/webui-rpc-helper.mjs +37 -9
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { normalizeSubagentLaunchSlots } from "./subagent-launch-slots.mjs";
|
|
5
|
+
import { normalizeOutputMode, OUTPUT_MODE_NORMAL } from "./webui-output-mode.mjs";
|
|
4
6
|
|
|
5
7
|
export const GIT_WORKFLOW_SETUP_VERSION = 1;
|
|
6
8
|
export const GIT_WORKFLOW_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
@@ -22,8 +24,9 @@ export function supportedGitWorkflowThinkingLevels(model) {
|
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
const WEBUI_SETTINGS_VERSION =
|
|
27
|
+
const WEBUI_SETTINGS_VERSION = 4;
|
|
26
28
|
const WEBUI_SETTINGS_FILE_ENV = "PI_WEBUI_SETTINGS_FILE";
|
|
29
|
+
const webuiSettingsUpdateQueues = new Map();
|
|
27
30
|
|
|
28
31
|
function cleanBoundedString(value, maxLength = 512) {
|
|
29
32
|
return typeof value === "string" ? value.trim().slice(0, maxLength) : "";
|
|
@@ -135,46 +138,112 @@ export function normalizeResourceDefaults(value) {
|
|
|
135
138
|
};
|
|
136
139
|
}
|
|
137
140
|
|
|
141
|
+
function settingsObject(value) {
|
|
142
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function normalizedSettingsVersion(value) {
|
|
146
|
+
const stored = Number.isInteger(value?.version) ? value.version : 0;
|
|
147
|
+
return Math.max(WEBUI_SETTINGS_VERSION, stored, value?.subagentLaunchSlots !== undefined ? 5 : 0);
|
|
148
|
+
}
|
|
149
|
+
|
|
138
150
|
export function normalizeWebuiSettings(value) {
|
|
151
|
+
const source = settingsObject(value);
|
|
139
152
|
return {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
...source,
|
|
154
|
+
version: normalizedSettingsVersion(source),
|
|
155
|
+
remoteAuthEnabled: source.remoteAuthEnabled === true,
|
|
156
|
+
outputModeDefault: normalizeOutputMode(source.outputModeDefault, OUTPUT_MODE_NORMAL),
|
|
157
|
+
gitWorkflow: normalizeGitWorkflowPreferences(source.gitWorkflow),
|
|
158
|
+
resourceDefaults: normalizeResourceDefaults(source.resourceDefaults),
|
|
159
|
+
subagentLaunchSlots: normalizeSubagentLaunchSlots(source.subagentLaunchSlots),
|
|
144
160
|
};
|
|
145
161
|
}
|
|
146
162
|
|
|
147
|
-
|
|
163
|
+
async function readRawWebuiSettings(storageFile) {
|
|
148
164
|
try {
|
|
149
|
-
return
|
|
165
|
+
return settingsObject(JSON.parse(await readFile(storageFile, "utf8")));
|
|
150
166
|
} catch (error) {
|
|
151
|
-
if (error?.code === "ENOENT") return
|
|
167
|
+
if (error?.code === "ENOENT") return {};
|
|
152
168
|
throw new Error(`Cannot read Pi Web UI settings at ${storageFile}: ${error instanceof Error ? error.message : String(error)}`);
|
|
153
169
|
}
|
|
154
170
|
}
|
|
155
171
|
|
|
156
|
-
export async function
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
172
|
+
export async function readWebuiSettings(storageFile = webuiSettingsFile(), { reportInvalidOutputMode = false } = {}) {
|
|
173
|
+
const raw = await readRawWebuiSettings(storageFile);
|
|
174
|
+
const normalized = normalizeWebuiSettings(raw);
|
|
175
|
+
if (reportInvalidOutputMode && raw.outputModeDefault !== undefined && normalized.outputModeDefault !== raw.outputModeDefault) {
|
|
176
|
+
console.warn(`Invalid persisted Web UI output mode ${JSON.stringify(raw.outputModeDefault)} in ${storageFile}; using ${OUTPUT_MODE_NORMAL}.`);
|
|
177
|
+
}
|
|
178
|
+
return normalized;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function mergeWebuiSettings(rawCurrent, patch) {
|
|
182
|
+
const raw = settingsObject(rawCurrent);
|
|
183
|
+
const current = normalizeWebuiSettings(raw);
|
|
184
|
+
const patchValue = settingsObject(patch);
|
|
185
|
+
const hasLaunchSlotPatch = Object.hasOwn(patchValue, "subagentLaunchSlots");
|
|
186
|
+
const persistLaunchSlots = raw.subagentLaunchSlots !== undefined || hasLaunchSlotPatch;
|
|
187
|
+
const source = {
|
|
188
|
+
...raw,
|
|
189
|
+
...patchValue,
|
|
190
|
+
gitWorkflow: patchValue.gitWorkflow
|
|
191
|
+
? mergeGitWorkflowPreferences(current.gitWorkflow, patchValue.gitWorkflow)
|
|
163
192
|
: current.gitWorkflow,
|
|
164
|
-
resourceDefaults:
|
|
193
|
+
resourceDefaults: patchValue.resourceDefaults
|
|
165
194
|
? {
|
|
166
195
|
...current.resourceDefaults,
|
|
167
|
-
...
|
|
168
|
-
tools: { ...current.resourceDefaults.tools, ...(
|
|
169
|
-
skills: { ...current.resourceDefaults.skills, ...(
|
|
196
|
+
...patchValue.resourceDefaults,
|
|
197
|
+
tools: { ...current.resourceDefaults.tools, ...(patchValue.resourceDefaults.tools || {}) },
|
|
198
|
+
skills: { ...current.resourceDefaults.skills, ...(patchValue.resourceDefaults.skills || {}) },
|
|
170
199
|
}
|
|
171
200
|
: current.resourceDefaults,
|
|
172
|
-
}
|
|
201
|
+
};
|
|
202
|
+
if (persistLaunchSlots) {
|
|
203
|
+
source.subagentLaunchSlots = hasLaunchSlotPatch
|
|
204
|
+
? normalizeSubagentLaunchSlots(patchValue.subagentLaunchSlots)
|
|
205
|
+
: normalizeSubagentLaunchSlots(raw.subagentLaunchSlots);
|
|
206
|
+
source.version = Math.max(5, Number.isInteger(raw.version) ? raw.version : 0);
|
|
207
|
+
} else {
|
|
208
|
+
delete source.subagentLaunchSlots;
|
|
209
|
+
source.version = Math.max(WEBUI_SETTINGS_VERSION, Number.isInteger(raw.version) ? raw.version : 0);
|
|
210
|
+
}
|
|
211
|
+
return { settings: normalizeWebuiSettings(source), persistLaunchSlots };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function writeMergedWebuiSettings(rawCurrent, patch, storageFile) {
|
|
215
|
+
const { settings, persistLaunchSlots } = mergeWebuiSettings(rawCurrent, patch);
|
|
216
|
+
const persisted = { ...settings };
|
|
217
|
+
if (!persistLaunchSlots) delete persisted.subagentLaunchSlots;
|
|
173
218
|
await mkdir(path.dirname(storageFile), { recursive: true });
|
|
174
219
|
const temporaryFile = `${storageFile}.${process.pid}.${Date.now()}.tmp`;
|
|
175
|
-
await writeFile(temporaryFile, `${JSON.stringify(
|
|
220
|
+
await writeFile(temporaryFile, `${JSON.stringify(persisted, null, 2)}\n`, { mode: 0o600 });
|
|
176
221
|
await rename(temporaryFile, storageFile);
|
|
177
|
-
return
|
|
222
|
+
return settings;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Applies a settings patch against the latest on-disk snapshot and writes it
|
|
227
|
+
* atomically. Returning undefined from the updater avoids an unnecessary write.
|
|
228
|
+
*/
|
|
229
|
+
export function updateWebuiSettings(updater, storageFile = webuiSettingsFile()) {
|
|
230
|
+
const queueKey = path.resolve(storageFile);
|
|
231
|
+
const previous = webuiSettingsUpdateQueues.get(queueKey) || Promise.resolve();
|
|
232
|
+
const currentUpdate = previous.catch(() => {}).then(async () => {
|
|
233
|
+
const rawCurrent = await readRawWebuiSettings(storageFile);
|
|
234
|
+
const current = normalizeWebuiSettings(rawCurrent);
|
|
235
|
+
const patch = await updater(current);
|
|
236
|
+
if (patch === undefined) return current;
|
|
237
|
+
return writeMergedWebuiSettings(rawCurrent, patch, storageFile);
|
|
238
|
+
});
|
|
239
|
+
webuiSettingsUpdateQueues.set(queueKey, currentUpdate);
|
|
240
|
+
return currentUpdate.finally(() => {
|
|
241
|
+
if (webuiSettingsUpdateQueues.get(queueKey) === currentUpdate) webuiSettingsUpdateQueues.delete(queueKey);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export async function writeWebuiSettings(patch, storageFile = webuiSettingsFile()) {
|
|
246
|
+
return updateWebuiSettings(() => patch, storageFile);
|
|
178
247
|
}
|
|
179
248
|
|
|
180
249
|
export async function readGitWorkflowPreferences(storageFile = webuiSettingsFile()) {
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export const SUBAGENT_LAUNCH_SLOTS_VERSION = 1;
|
|
6
|
+
export const SUBAGENT_LAUNCH_SLOT_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
7
|
+
export const SUBAGENT_LAUNCH_SLOT_LIMITS = Object.freeze({
|
|
8
|
+
slotsPerRole: 8,
|
|
9
|
+
totalSlots: 32,
|
|
10
|
+
slotIdLength: 160,
|
|
11
|
+
modelIdLength: 240,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG = Object.freeze([
|
|
15
|
+
{ id: "context-builder", title: "Context builder", purpose: "Build focused context before delegation." },
|
|
16
|
+
{ id: "delegate", title: "Delegate", purpose: "Coordinate scoped delegation work." },
|
|
17
|
+
{ id: "oracle", title: "Oracle", purpose: "Resolve difficult design or implementation questions." },
|
|
18
|
+
{ id: "planner", title: "Planner", purpose: "Plan implementation work and acceptance checks." },
|
|
19
|
+
{ id: "researcher", title: "Researcher", purpose: "Research evidence and implementation options." },
|
|
20
|
+
{ id: "reviewer", title: "Reviewer", purpose: "Review implementation quality and correctness." },
|
|
21
|
+
{ id: "scout", title: "Scout", purpose: "Inspect repository context and constraints." },
|
|
22
|
+
{ id: "worker", title: "Worker", purpose: "Implement an assigned workstream." },
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const ROLE_IDS = new Set(SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG.map((role) => role.id));
|
|
26
|
+
const BASE_SLOT_IDS = new Set(SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG.map((role) => `${role.id}:base`));
|
|
27
|
+
const SLOT_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:_-]*$/;
|
|
28
|
+
const THINKING_SUFFIX_PATTERN = /:(off|minimal|low|medium|high|xhigh|max)$/i;
|
|
29
|
+
|
|
30
|
+
function isPlainObject(value) {
|
|
31
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function exactString(value, maxLength) {
|
|
35
|
+
return typeof value === "string" && value.length <= maxLength && value.trim() === value ? value : "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function subagentLaunchSlotBaseId(roleId) {
|
|
39
|
+
return `${roleId}:base`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function subagentLaunchSlotModelKey(model) {
|
|
43
|
+
return model?.provider && model?.id ? `${model.provider}/${model.id}` : "";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function supportedSubagentLaunchSlotThinkingLevels(model) {
|
|
47
|
+
if (!model?.reasoning) return ["off"];
|
|
48
|
+
const mapping = isPlainObject(model.thinkingLevelMap) ? model.thinkingLevelMap : {};
|
|
49
|
+
return SUBAGENT_LAUNCH_SLOT_THINKING_LEVELS.filter((level) => {
|
|
50
|
+
if (mapping[level] === null) return false;
|
|
51
|
+
if (["xhigh", "max"].includes(level)) return typeof mapping[level] === "string";
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isCanonicalSubagentLaunchSlotModel(value) {
|
|
57
|
+
const model = exactString(value, SUBAGENT_LAUNCH_SLOT_LIMITS.modelIdLength);
|
|
58
|
+
if (!model || !model.includes("/") || /\s/.test(model) || THINKING_SUFFIX_PATTERN.test(model)) return false;
|
|
59
|
+
const [provider, ...idParts] = model.split("/");
|
|
60
|
+
return !!provider && idParts.join("/").length > 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function isSafeSlotId(value) {
|
|
64
|
+
const id = exactString(value, SUBAGENT_LAUNCH_SLOT_LIMITS.slotIdLength);
|
|
65
|
+
return !!id && SLOT_ID_PATTERN.test(id);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function normalizedSlot(value, fallbackId) {
|
|
69
|
+
const raw = isPlainObject(value) ? value : {};
|
|
70
|
+
const id = isSafeSlotId(raw.id) ? raw.id : fallbackId;
|
|
71
|
+
const model = isCanonicalSubagentLaunchSlotModel(raw.model) ? raw.model : null;
|
|
72
|
+
const thinking = SUBAGENT_LAUNCH_SLOT_THINKING_LEVELS.includes(raw.thinking) ? raw.thinking : null;
|
|
73
|
+
return {
|
|
74
|
+
id,
|
|
75
|
+
model,
|
|
76
|
+
thinking: model ? thinking : null,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function normalizedRoleSlots(value, roleId) {
|
|
81
|
+
const baseId = subagentLaunchSlotBaseId(roleId);
|
|
82
|
+
const values = Array.isArray(value) ? value : [];
|
|
83
|
+
const slots = [];
|
|
84
|
+
const seen = new Set();
|
|
85
|
+
let base = null;
|
|
86
|
+
|
|
87
|
+
for (const value of values) {
|
|
88
|
+
const rawId = isPlainObject(value) && isSafeSlotId(value.id) ? value.id : "";
|
|
89
|
+
if (rawId === baseId && !base) base = normalizedSlot(value, baseId);
|
|
90
|
+
}
|
|
91
|
+
slots.push(base || normalizedSlot({}, baseId));
|
|
92
|
+
seen.add(baseId);
|
|
93
|
+
|
|
94
|
+
for (const value of values) {
|
|
95
|
+
const slot = normalizedSlot(value, "");
|
|
96
|
+
if (!slot.id || slot.id === baseId || BASE_SLOT_IDS.has(slot.id) || seen.has(slot.id)) continue;
|
|
97
|
+
if (slots.length >= SUBAGENT_LAUNCH_SLOT_LIMITS.slotsPerRole) break;
|
|
98
|
+
seen.add(slot.id);
|
|
99
|
+
slots.push(slot);
|
|
100
|
+
}
|
|
101
|
+
return slots;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function defaultSubagentLaunchSlotRoles() {
|
|
105
|
+
return Object.fromEntries(SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG.map((role) => [
|
|
106
|
+
role.id,
|
|
107
|
+
[{ id: subagentLaunchSlotBaseId(role.id), model: null, thinking: null }],
|
|
108
|
+
]));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function normalizeSubagentLaunchSlotRoles(value) {
|
|
112
|
+
const rawRoles = isPlainObject(value) ? value : {};
|
|
113
|
+
const normalizedByRole = new Map(SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG.map((role) => [
|
|
114
|
+
role.id,
|
|
115
|
+
normalizedRoleSlots(rawRoles[role.id], role.id),
|
|
116
|
+
]));
|
|
117
|
+
const roles = {};
|
|
118
|
+
const seen = new Set();
|
|
119
|
+
for (const role of SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG) {
|
|
120
|
+
const base = normalizedByRole.get(role.id)[0];
|
|
121
|
+
roles[role.id] = [base];
|
|
122
|
+
seen.add(base.id);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let remaining = SUBAGENT_LAUNCH_SLOT_LIMITS.totalSlots - seen.size;
|
|
126
|
+
for (const role of SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG) {
|
|
127
|
+
const slots = roles[role.id];
|
|
128
|
+
for (const slot of normalizedByRole.get(role.id).slice(1)) {
|
|
129
|
+
if (remaining <= 0 || seen.has(slot.id)) continue;
|
|
130
|
+
seen.add(slot.id);
|
|
131
|
+
remaining -= 1;
|
|
132
|
+
slots.push(slot);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return roles;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function normalizeScopeEntry(value) {
|
|
139
|
+
return { roles: normalizeSubagentLaunchSlotRoles(value?.roles) };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function isSafeProjectKey(value) {
|
|
143
|
+
return typeof value === "string"
|
|
144
|
+
&& value.length > 0
|
|
145
|
+
&& value.length <= 4096
|
|
146
|
+
&& path.isAbsolute(value)
|
|
147
|
+
&& !value.includes("\0");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function normalizeSubagentLaunchSlots(value) {
|
|
151
|
+
const source = isPlainObject(value) ? value : {};
|
|
152
|
+
const projects = {};
|
|
153
|
+
if (isPlainObject(source.projects)) {
|
|
154
|
+
for (const projectKey of Object.keys(source.projects).sort()) {
|
|
155
|
+
if (!isSafeProjectKey(projectKey) || !isPlainObject(source.projects[projectKey])) continue;
|
|
156
|
+
projects[projectKey] = normalizeScopeEntry(source.projects[projectKey]);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
version: SUBAGENT_LAUNCH_SLOTS_VERSION,
|
|
161
|
+
user: normalizeScopeEntry(source.user),
|
|
162
|
+
projects,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function subagentLaunchSlotScopeEntry(config, scope, projectKey) {
|
|
167
|
+
const normalized = normalizeSubagentLaunchSlots(config);
|
|
168
|
+
if (scope === "user") return { entry: normalized.user, inherited: false };
|
|
169
|
+
if (scope !== "project") throw new Error("scope must be user or project");
|
|
170
|
+
if (!isSafeProjectKey(projectKey)) throw new Error("projectKey must be an absolute canonical path");
|
|
171
|
+
const entry = normalized.projects[projectKey];
|
|
172
|
+
return { entry: entry || normalized.user, inherited: !entry };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function stableJson(value) {
|
|
176
|
+
if (Array.isArray(value)) return `[${value.map((item) => stableJson(item)).join(",")}]`;
|
|
177
|
+
if (isPlainObject(value)) {
|
|
178
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
|
|
179
|
+
}
|
|
180
|
+
return JSON.stringify(value);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function subagentLaunchSlotRevision(config, scope, projectKey) {
|
|
184
|
+
const normalized = normalizeSubagentLaunchSlots(config);
|
|
185
|
+
let revisionValue;
|
|
186
|
+
if (scope === "user") {
|
|
187
|
+
revisionValue = { scope: "user", entry: normalized.user };
|
|
188
|
+
} else if (scope === "project") {
|
|
189
|
+
if (!isSafeProjectKey(projectKey)) throw new Error("projectKey must be an absolute canonical path");
|
|
190
|
+
const projectEntry = normalized.projects[projectKey];
|
|
191
|
+
revisionValue = projectEntry
|
|
192
|
+
? { scope: "project", projectKey, entry: projectEntry }
|
|
193
|
+
: { scope: "project", projectKey, inherited: true, user: normalized.user };
|
|
194
|
+
} else {
|
|
195
|
+
throw new Error("scope must be user or project");
|
|
196
|
+
}
|
|
197
|
+
return createHash("sha256").update(stableJson(revisionValue)).digest("hex");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function validateSubagentLaunchSlotRoles(value, models = []) {
|
|
201
|
+
if (!isPlainObject(value)) throw new Error("roles must be an object");
|
|
202
|
+
const keys = Object.keys(value);
|
|
203
|
+
const unknown = keys.filter((key) => !ROLE_IDS.has(key));
|
|
204
|
+
if (unknown.length) throw new Error(`Unknown subagent role: ${unknown[0]}`);
|
|
205
|
+
|
|
206
|
+
const availableModels = new Map();
|
|
207
|
+
for (const model of Array.isArray(models) ? models : []) {
|
|
208
|
+
const key = subagentLaunchSlotModelKey(model);
|
|
209
|
+
if (key) availableModels.set(key, model);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const seenIds = new Set();
|
|
213
|
+
let totalSlots = 0;
|
|
214
|
+
for (const role of SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG) {
|
|
215
|
+
const slots = value[role.id];
|
|
216
|
+
if (!Array.isArray(slots)) throw new Error(`${role.id} slots are required`);
|
|
217
|
+
if (slots.length < 1) throw new Error(`${role.id} requires its base slot`);
|
|
218
|
+
if (slots.length > SUBAGENT_LAUNCH_SLOT_LIMITS.slotsPerRole) {
|
|
219
|
+
throw new Error(`${role.id} is limited to ${SUBAGENT_LAUNCH_SLOT_LIMITS.slotsPerRole} slots`);
|
|
220
|
+
}
|
|
221
|
+
const baseId = subagentLaunchSlotBaseId(role.id);
|
|
222
|
+
if (slots.filter((slot) => slot?.id === baseId).length !== 1) {
|
|
223
|
+
throw new Error(`${role.id} requires exactly one base slot`);
|
|
224
|
+
}
|
|
225
|
+
for (const slot of slots) {
|
|
226
|
+
if (!isPlainObject(slot) || !isSafeSlotId(slot.id)) throw new Error(`${role.id} has an invalid slot id`);
|
|
227
|
+
if (seenIds.has(slot.id)) throw new Error(`Duplicate slot id: ${slot.id}`);
|
|
228
|
+
seenIds.add(slot.id);
|
|
229
|
+
totalSlots += 1;
|
|
230
|
+
if (totalSlots > SUBAGENT_LAUNCH_SLOT_LIMITS.totalSlots) {
|
|
231
|
+
throw new Error(`Launch slots are limited to ${SUBAGENT_LAUNCH_SLOT_LIMITS.totalSlots} total`);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (slot.model !== null && !isCanonicalSubagentLaunchSlotModel(slot.model)) {
|
|
235
|
+
throw new Error(`${slot.id} has an invalid model`);
|
|
236
|
+
}
|
|
237
|
+
if (slot.thinking !== null && !SUBAGENT_LAUNCH_SLOT_THINKING_LEVELS.includes(slot.thinking)) {
|
|
238
|
+
throw new Error(`${slot.id} has an unsupported thinking level`);
|
|
239
|
+
}
|
|
240
|
+
if (slot.model === null && slot.thinking !== null) {
|
|
241
|
+
throw new Error(`${slot.id} cannot set thinking while inheriting its model`);
|
|
242
|
+
}
|
|
243
|
+
if (slot.model) {
|
|
244
|
+
const model = availableModels.get(slot.model);
|
|
245
|
+
if (!model) throw new Error(`Selected model is not currently available: ${slot.model}`);
|
|
246
|
+
if (slot.thinking && !supportedSubagentLaunchSlotThinkingLevels(model).includes(slot.thinking)) {
|
|
247
|
+
throw new Error(`${slot.model} does not support thinking level ${slot.thinking}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return normalizeSubagentLaunchSlotRoles(value);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export async function resolveSubagentLaunchSlotProjectKey(cwd) {
|
|
256
|
+
const fallback = path.resolve(String(cwd || process.cwd()));
|
|
257
|
+
let current;
|
|
258
|
+
try {
|
|
259
|
+
current = await realpath(fallback);
|
|
260
|
+
} catch {
|
|
261
|
+
return fallback;
|
|
262
|
+
}
|
|
263
|
+
const canonicalCwd = current;
|
|
264
|
+
|
|
265
|
+
while (true) {
|
|
266
|
+
for (const marker of [".pi", ".git"]) {
|
|
267
|
+
try {
|
|
268
|
+
await lstat(path.join(current, marker));
|
|
269
|
+
return current;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (error?.code !== "ENOENT") throw error;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const parent = path.dirname(current);
|
|
275
|
+
if (parent === current) return canonicalCwd;
|
|
276
|
+
current = parent;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function subagentLaunchSlotProjectLabel(projectKey) {
|
|
281
|
+
return path.basename(projectKey) || projectKey;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function formatSubagentLaunchSlotGuidance(roles) {
|
|
285
|
+
const normalized = normalizeSubagentLaunchSlotRoles(roles);
|
|
286
|
+
const assignments = [];
|
|
287
|
+
for (const role of SUBAGENT_LAUNCH_SLOT_ROLE_CATALOG) {
|
|
288
|
+
const slots = normalized[role.id];
|
|
289
|
+
if (!slots.some((slot) => slot.model)) continue;
|
|
290
|
+
for (const [index, slot] of slots.entries()) {
|
|
291
|
+
const model = slot.model
|
|
292
|
+
? slot.thinking ? `${slot.model}:${slot.thinking}` : slot.model
|
|
293
|
+
: "<inherit; omit the model field>";
|
|
294
|
+
assignments.push(`- ${role.id} slot ${index + 1}: agent=${role.id} model=${model}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (!assignments.length) return "";
|
|
298
|
+
return [
|
|
299
|
+
"## WebUI subagent launch slots",
|
|
300
|
+
"These are default model assignments for future delegation in this Pi tab. Explicit user instructions in the current request win.",
|
|
301
|
+
...assignments.slice(0, SUBAGENT_LAUNCH_SLOT_LIMITS.totalSlots),
|
|
302
|
+
"When launching multiple slots of one role, create separate task entries so each model remains explicit; do not replace them with count when model specs differ.",
|
|
303
|
+
].join("\n");
|
|
304
|
+
}
|
package/lib/trust-boundaries.mjs
CHANGED
|
@@ -13,6 +13,7 @@ export const LOCALHOST_ONLY_POST_ROUTES = new Map([
|
|
|
13
13
|
["/api/network/open", "Opening to the network is only allowed from localhost"],
|
|
14
14
|
["/api/network/close", "Closing network access is only allowed from localhost"],
|
|
15
15
|
["/api/remote-auth/settings", "Remote PIN authentication settings are only allowed from localhost"],
|
|
16
|
+
["/api/subagents/config", "Saving subagent launch-slot configuration is only allowed from localhost"],
|
|
16
17
|
["/api/recovery/plan", "Opening recovery plans is only allowed from localhost"],
|
|
17
18
|
["/api/restart", "Restart is only allowed from localhost"],
|
|
18
19
|
["/api/update", "Updating Pi from the Web UI is only allowed from localhost"],
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const OUTPUT_MODE_NORMAL = "normal";
|
|
2
|
+
export const OUTPUT_MODE_COMPACT_V1 = "compact-v1";
|
|
3
|
+
export const OUTPUT_MODE_PROTOCOL_VERSION = 1;
|
|
4
|
+
|
|
5
|
+
const OUTPUT_MODES = new Set([OUTPUT_MODE_NORMAL, OUTPUT_MODE_COMPACT_V1]);
|
|
6
|
+
const COMPACT_MESSAGE_UPDATE_TYPES = new Set(["text_delta", "thinking_delta", "toolcall_delta"]);
|
|
7
|
+
const COMPACT_SELF_CONTAINED_END_TYPES = new Set(["text_end", "thinking_end", "toolcall_end", "tool_call_end"]);
|
|
8
|
+
const SEMANTIC_BARRIER_TYPES = new Set([
|
|
9
|
+
"message_end",
|
|
10
|
+
"tool_execution_end",
|
|
11
|
+
"agent_end",
|
|
12
|
+
"agent_settled",
|
|
13
|
+
"compaction_end",
|
|
14
|
+
"pi_process_exit",
|
|
15
|
+
"pi_process_error",
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
function cleanOutputMode(value) {
|
|
19
|
+
return typeof value === "string" ? value.trim() : "";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function hasProtocolVersionOne(value) {
|
|
23
|
+
return value === OUTPUT_MODE_PROTOCOL_VERSION || value === String(OUTPUT_MODE_PROTOCOL_VERSION);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function directSelfContainedEnd(update) {
|
|
27
|
+
if (!COMPACT_SELF_CONTAINED_END_TYPES.has(update?.type)) return false;
|
|
28
|
+
return Object.prototype.hasOwnProperty.call(update, "content")
|
|
29
|
+
|| Object.prototype.hasOwnProperty.call(update, "toolCall")
|
|
30
|
+
|| Object.prototype.hasOwnProperty.call(update, "error")
|
|
31
|
+
|| Object.prototype.hasOwnProperty.call(update, "isError");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function compactAssistantMessageUpdate(event) {
|
|
35
|
+
if (!event || typeof event !== "object" || event.type !== "message_update") return null;
|
|
36
|
+
const update = event.assistantMessageEvent;
|
|
37
|
+
if (!update || typeof update !== "object" || Array.isArray(update)) return null;
|
|
38
|
+
|
|
39
|
+
const hasDirectDelta = COMPACT_MESSAGE_UPDATE_TYPES.has(update.type) && typeof update.delta === "string";
|
|
40
|
+
if (!hasDirectDelta && !directSelfContainedEnd(update)) return null;
|
|
41
|
+
|
|
42
|
+
const compactUpdate = { ...update };
|
|
43
|
+
delete compactUpdate.partial;
|
|
44
|
+
const compactEvent = { ...event, assistantMessageEvent: compactUpdate };
|
|
45
|
+
delete compactEvent.message;
|
|
46
|
+
return compactEvent;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function normalizeOutputMode(value, fallback = OUTPUT_MODE_NORMAL) {
|
|
50
|
+
const normalizedFallback = OUTPUT_MODES.has(cleanOutputMode(fallback)) ? cleanOutputMode(fallback) : OUTPUT_MODE_NORMAL;
|
|
51
|
+
const normalizedValue = cleanOutputMode(value);
|
|
52
|
+
return OUTPUT_MODES.has(normalizedValue) ? normalizedValue : normalizedFallback;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function resolveOutputModeDefault({ cliMode, envMode, persistedMode } = {}) {
|
|
56
|
+
const cli = cleanOutputMode(cliMode);
|
|
57
|
+
if (OUTPUT_MODES.has(cli)) return { mode: cli, source: "cli" };
|
|
58
|
+
const env = cleanOutputMode(envMode);
|
|
59
|
+
if (OUTPUT_MODES.has(env)) return { mode: env, source: "env" };
|
|
60
|
+
const persisted = cleanOutputMode(persistedMode);
|
|
61
|
+
if (OUTPUT_MODES.has(persisted)) return { mode: persisted, source: "persisted" };
|
|
62
|
+
return { mode: OUTPUT_MODE_NORMAL, source: "normal" };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function negotiateOutputMode({ requestedMode, protocolVersion, serverDefault } = {}) {
|
|
66
|
+
const protocolAccepted = hasProtocolVersionOne(protocolVersion);
|
|
67
|
+
const requested = cleanOutputMode(requestedMode);
|
|
68
|
+
const validRequest = protocolAccepted && ["auto", OUTPUT_MODE_NORMAL, OUTPUT_MODE_COMPACT_V1].includes(requested);
|
|
69
|
+
if (!validRequest) {
|
|
70
|
+
return {
|
|
71
|
+
requestedMode: OUTPUT_MODE_NORMAL,
|
|
72
|
+
protocolVersion: 0,
|
|
73
|
+
activeMode: OUTPUT_MODE_NORMAL,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
requestedMode: requested,
|
|
79
|
+
protocolVersion: OUTPUT_MODE_PROTOCOL_VERSION,
|
|
80
|
+
activeMode: requested === "auto" ? normalizeOutputMode(serverDefault) : requested,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function browserOutputEvent(event, { outputMode = OUTPUT_MODE_NORMAL } = {}) {
|
|
85
|
+
if (normalizeOutputMode(outputMode) !== OUTPUT_MODE_COMPACT_V1) return event;
|
|
86
|
+
if (event?.type === "tool_execution_update") return undefined;
|
|
87
|
+
return compactAssistantMessageUpdate(event) || event;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function encodeBrowserSseEvent(event, { outputMode = OUTPUT_MODE_NORMAL } = {}) {
|
|
91
|
+
const browserEvent = browserOutputEvent(event, { outputMode });
|
|
92
|
+
return browserEvent === undefined ? undefined : JSON.stringify(browserEvent);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function isOutputModeSemanticBarrier(event) {
|
|
96
|
+
return SEMANTIC_BARRIER_TYPES.has(event?.type);
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "Pi Web UI companion package with a local browser UI CLI plus /webui-start and /webui-status commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://github.com/Firstp1ck/
|
|
6
|
+
"homepage": "https://github.com/Firstp1ck/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/Firstp1ck/
|
|
9
|
+
"url": "git+https://github.com/Firstp1ck/pi-coding-agent-forge.git",
|
|
10
10
|
"directory": "pi-package-webui"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"extension"
|
|
21
21
|
],
|
|
22
22
|
"pi": {
|
|
23
|
-
"image": "https://raw.githubusercontent.com/Firstp1ck/
|
|
23
|
+
"image": "https://raw.githubusercontent.com/Firstp1ck/pi-coding-agent-forge/main/pi-package-webui/images/Webui_MainWindow_v0.4.8.png",
|
|
24
24
|
"extensions": [
|
|
25
25
|
"./index.ts",
|
|
26
26
|
"node_modules/@firstpick/pi-extension-bang-command-autocomplete/index.ts",
|
|
@@ -51,31 +51,31 @@
|
|
|
51
51
|
"pi-webui": "./bin/pi-webui.mjs"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
|
-
"check": "node --check public/app.js && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check webui-rpc-helper.mjs && node --check lib/git-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
|
|
54
|
+
"check": "node --check public/app.js && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check webui-rpc-helper.mjs && node --check lib/subagent-launch-slots.mjs && node --check lib/git-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
|
|
55
55
|
"test": "node tests/run-all.mjs"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@earendil-works/pi-coding-agent": "^0.
|
|
59
|
-
"@firstpick/pi-utils": "^0.2.
|
|
58
|
+
"@earendil-works/pi-coding-agent": "^0.82.0",
|
|
59
|
+
"@firstpick/pi-utils": "^0.2.5",
|
|
60
60
|
"mermaid": "^11.15.0",
|
|
61
61
|
"typebox": "^1.3.6"
|
|
62
62
|
},
|
|
63
63
|
"optionalDependencies": {
|
|
64
|
-
"@firstpick/pi-extension-bang-command-autocomplete": "^0.2.
|
|
65
|
-
"@firstpick/pi-extension-btw": "^0.1.
|
|
66
|
-
"@firstpick/pi-extension-fish-user-bash": "^0.2.
|
|
67
|
-
"@firstpick/pi-extension-git-footer-status": "^0.4.
|
|
68
|
-
"@firstpick/pi-extension-release-aur": "^0.1.
|
|
69
|
-
"@firstpick/pi-extension-release-npm": "^0.4.
|
|
70
|
-
"@firstpick/pi-extension-safety-guard": "^0.2.
|
|
71
|
-
"@firstpick/pi-extension-setup-skills": "^0.1.
|
|
72
|
-
"@firstpick/pi-extension-stats": "^0.2.
|
|
73
|
-
"@firstpick/pi-extension-todo-progress": "^0.2.
|
|
74
|
-
"@firstpick/pi-extension-tools": "^0.1.
|
|
75
|
-
"@firstpick/pi-extension-workflows": "^0.1.
|
|
76
|
-
"@firstpick/pi-package-remote-webui": "^0.1.
|
|
77
|
-
"@firstpick/pi-prompts-git-pr": "^0.1.
|
|
78
|
-
"@firstpick/pi-themes-bundle": "^0.1.
|
|
64
|
+
"@firstpick/pi-extension-bang-command-autocomplete": "^0.2.2",
|
|
65
|
+
"@firstpick/pi-extension-btw": "^0.1.4",
|
|
66
|
+
"@firstpick/pi-extension-fish-user-bash": "^0.2.2",
|
|
67
|
+
"@firstpick/pi-extension-git-footer-status": "^0.4.3",
|
|
68
|
+
"@firstpick/pi-extension-release-aur": "^0.1.8",
|
|
69
|
+
"@firstpick/pi-extension-release-npm": "^0.4.4",
|
|
70
|
+
"@firstpick/pi-extension-safety-guard": "^0.2.6",
|
|
71
|
+
"@firstpick/pi-extension-setup-skills": "^0.1.9",
|
|
72
|
+
"@firstpick/pi-extension-stats": "^0.2.9",
|
|
73
|
+
"@firstpick/pi-extension-todo-progress": "^0.2.9",
|
|
74
|
+
"@firstpick/pi-extension-tools": "^0.1.7",
|
|
75
|
+
"@firstpick/pi-extension-workflows": "^0.1.6",
|
|
76
|
+
"@firstpick/pi-package-remote-webui": "^0.1.8",
|
|
77
|
+
"@firstpick/pi-prompts-git-pr": "^0.1.5",
|
|
78
|
+
"@firstpick/pi-themes-bundle": "^0.1.5",
|
|
79
79
|
"node-pty": "^1.1.0"
|
|
80
80
|
},
|
|
81
81
|
"files": [
|