@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
|
@@ -3,6 +3,7 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import webuiRpcHelper from "../webui-rpc-helper.mjs";
|
|
6
|
+
import { defaultSubagentLaunchSlotRoles } from "../lib/subagent-launch-slots.mjs";
|
|
6
7
|
|
|
7
8
|
class EventBus {
|
|
8
9
|
constructor() {
|
|
@@ -50,6 +51,14 @@ const ctx = {
|
|
|
50
51
|
sessionManager: {
|
|
51
52
|
getBranch() { return []; },
|
|
52
53
|
},
|
|
54
|
+
getSystemPromptOptions() {
|
|
55
|
+
return {
|
|
56
|
+
skills: [
|
|
57
|
+
{ name: "repo-explorer", description: "Inspect repository context", filePath: "/tmp/repo-explorer/SKILL.md" },
|
|
58
|
+
{ name: "code-security", description: "Review code security", filePath: "/tmp/code-security/SKILL.md" },
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
},
|
|
53
62
|
ui: {
|
|
54
63
|
setStatus(key, text) {
|
|
55
64
|
statuses.push({ key, text });
|
|
@@ -61,6 +70,15 @@ const ctx = {
|
|
|
61
70
|
};
|
|
62
71
|
|
|
63
72
|
const asyncRunDir = await mkdtemp(path.join(tmpdir(), "pi-webui-subagent-output-test-"));
|
|
73
|
+
const settingsFile = path.join(asyncRunDir, "webui-settings.json");
|
|
74
|
+
const initialLaunchRoles = defaultSubagentLaunchSlotRoles();
|
|
75
|
+
initialLaunchRoles.reviewer[0] = { id: "reviewer:base", model: "fake/reviewer", thinking: "high" };
|
|
76
|
+
await writeFile(settingsFile, `${JSON.stringify({
|
|
77
|
+
version: 5,
|
|
78
|
+
resourceDefaults: { tools: { enabledTools: null }, skills: { enabledSkills: ["repo-explorer"] } },
|
|
79
|
+
subagentLaunchSlots: { version: 1, user: { roles: initialLaunchRoles }, projects: {} },
|
|
80
|
+
}, null, 2)}\n`);
|
|
81
|
+
process.env.PI_WEBUI_SETTINGS_FILE = settingsFile;
|
|
64
82
|
const asyncSessionFile = path.join(asyncRunDir, "reviewer-session.jsonl");
|
|
65
83
|
await writeFile(asyncSessionFile, [
|
|
66
84
|
JSON.stringify({ type: "message", timestamp: "2026-07-19T12:00:00.000Z", message: { role: "assistant", content: [{ type: "thinking", thinking: "Checking structured transcript extraction" }, { type: "text", text: "REVIEWER STREAM 1 OF 18" }, { type: "toolCall", id: "review-call", name: "bash", arguments: { command: "sleep 5" } }, { type: "text", text: "Review complete." }] } }),
|
|
@@ -106,6 +124,33 @@ const unsubscribeRpc = bus.on("subagents:rpc:v1:request", (request) => {
|
|
|
106
124
|
});
|
|
107
125
|
|
|
108
126
|
for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "startup" }, ctx);
|
|
127
|
+
const beforeAgentStart = (extensionHandlers.get("before_agent_start") || [])[0];
|
|
128
|
+
assert.ok(beforeAgentStart, "helper should register before_agent_start guidance");
|
|
129
|
+
const promptWithSkills = [
|
|
130
|
+
"Base system prompt.",
|
|
131
|
+
"The following skills provide specialized capabilities:",
|
|
132
|
+
"<available_skills>",
|
|
133
|
+
" <skill>",
|
|
134
|
+
" <name>repo-explorer</name>",
|
|
135
|
+
" </skill>",
|
|
136
|
+
" <skill>",
|
|
137
|
+
" <name>code-security</name>",
|
|
138
|
+
" </skill>",
|
|
139
|
+
"</available_skills>",
|
|
140
|
+
].join("\n");
|
|
141
|
+
const initialGuidance = await beforeAgentStart({ systemPrompt: promptWithSkills, systemPromptOptions: ctx.getSystemPromptOptions() });
|
|
142
|
+
assert.match(initialGuidance?.systemPrompt || "", /reviewer slot 1: agent=reviewer model=fake\/reviewer:high/, "session_start should cache effective launch-slot guidance");
|
|
143
|
+
assert.doesNotMatch(initialGuidance?.systemPrompt || "", /code-security/, "launch-slot guidance must compose with disabled-skill filtering");
|
|
144
|
+
const changedLaunchRoles = defaultSubagentLaunchSlotRoles();
|
|
145
|
+
changedLaunchRoles.reviewer[0] = { id: "reviewer:base", model: "fake/changed", thinking: "high" };
|
|
146
|
+
await writeFile(settingsFile, `${JSON.stringify({
|
|
147
|
+
version: 5,
|
|
148
|
+
resourceDefaults: { tools: { enabledTools: null }, skills: { enabledSkills: ["repo-explorer"] } },
|
|
149
|
+
subagentLaunchSlots: { version: 1, user: { roles: changedLaunchRoles }, projects: {} },
|
|
150
|
+
}, null, 2)}\n`);
|
|
151
|
+
const cachedGuidance = await beforeAgentStart({ systemPrompt: "Base system prompt.", systemPromptOptions: ctx.getSystemPromptOptions() });
|
|
152
|
+
assert.match(cachedGuidance?.systemPrompt || "", /fake\/reviewer:high/, "a settings save must not mutate the active helper snapshot");
|
|
153
|
+
assert.doesNotMatch(cachedGuidance?.systemPrompt || "", /fake\/changed:high/);
|
|
109
154
|
for (let attempt = 0; attempt < 20 && !statuses.some((entry) => entry.text?.startsWith("PI_WEBUI_SUBAGENTS_V1 ") && entry.text.includes("run-a")); attempt++) {
|
|
110
155
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
111
156
|
}
|
|
@@ -315,6 +360,7 @@ assert.equal(payload.runs.some((run) => run.source === "foreground"), false, "fo
|
|
|
315
360
|
|
|
316
361
|
for (const handler of extensionHandlers.get("session_shutdown") || []) await handler({ reason: "quit" }, ctx);
|
|
317
362
|
unsubscribeRpc();
|
|
363
|
+
delete process.env.PI_WEBUI_SETTINGS_FILE;
|
|
318
364
|
await rm(asyncRunDir, { recursive: true, force: true });
|
|
319
365
|
|
|
320
366
|
console.log("subagents-helper.test.mjs passed");
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import {
|
|
3
|
+
browserOutputEvent,
|
|
4
|
+
encodeBrowserSseEvent,
|
|
5
|
+
isOutputModeSemanticBarrier,
|
|
6
|
+
negotiateOutputMode,
|
|
7
|
+
normalizeOutputMode,
|
|
8
|
+
OUTPUT_MODE_COMPACT_V1,
|
|
9
|
+
OUTPUT_MODE_NORMAL,
|
|
10
|
+
resolveOutputModeDefault,
|
|
11
|
+
} from "../lib/webui-output-mode.mjs";
|
|
12
|
+
|
|
13
|
+
assert.equal(normalizeOutputMode("compact-v1"), OUTPUT_MODE_COMPACT_V1);
|
|
14
|
+
assert.equal(normalizeOutputMode("unknown", OUTPUT_MODE_COMPACT_V1), OUTPUT_MODE_COMPACT_V1);
|
|
15
|
+
assert.equal(normalizeOutputMode(undefined), OUTPUT_MODE_NORMAL);
|
|
16
|
+
assert.deepEqual(resolveOutputModeDefault({ cliMode: "compact-v1", envMode: "normal", persistedMode: "normal" }), { mode: "compact-v1", source: "cli" });
|
|
17
|
+
assert.deepEqual(resolveOutputModeDefault({ envMode: "compact-v1", persistedMode: "normal" }), { mode: "compact-v1", source: "env" });
|
|
18
|
+
assert.deepEqual(resolveOutputModeDefault({ persistedMode: "compact-v1" }), { mode: "compact-v1", source: "persisted" });
|
|
19
|
+
assert.deepEqual(resolveOutputModeDefault({ persistedMode: "invalid" }), { mode: "normal", source: "normal" });
|
|
20
|
+
|
|
21
|
+
assert.deepEqual(negotiateOutputMode({ requestedMode: "auto", protocolVersion: "1", serverDefault: "compact-v1" }), {
|
|
22
|
+
requestedMode: "auto",
|
|
23
|
+
protocolVersion: 1,
|
|
24
|
+
activeMode: "compact-v1",
|
|
25
|
+
});
|
|
26
|
+
assert.deepEqual(negotiateOutputMode({ requestedMode: "compact-v1", protocolVersion: 1, serverDefault: "normal" }), {
|
|
27
|
+
requestedMode: "compact-v1",
|
|
28
|
+
protocolVersion: 1,
|
|
29
|
+
activeMode: "compact-v1",
|
|
30
|
+
});
|
|
31
|
+
assert.deepEqual(negotiateOutputMode({ requestedMode: "compact-v1", protocolVersion: undefined, serverDefault: "compact-v1" }), {
|
|
32
|
+
requestedMode: "normal",
|
|
33
|
+
protocolVersion: 0,
|
|
34
|
+
activeMode: "normal",
|
|
35
|
+
});
|
|
36
|
+
assert.deepEqual(negotiateOutputMode({ requestedMode: "auto", protocolVersion: "2", serverDefault: "compact-v1" }), {
|
|
37
|
+
requestedMode: "normal",
|
|
38
|
+
protocolVersion: 0,
|
|
39
|
+
activeMode: "normal",
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const canonical = {
|
|
43
|
+
type: "message_update",
|
|
44
|
+
tabId: "tab-1",
|
|
45
|
+
tabActivity: { status: "working" },
|
|
46
|
+
message: { role: "assistant", content: [{ type: "text", text: "accumulated text" }] },
|
|
47
|
+
assistantMessageEvent: {
|
|
48
|
+
type: "text_delta",
|
|
49
|
+
delta: "",
|
|
50
|
+
contentIndex: 2,
|
|
51
|
+
partial: { role: "assistant", content: [{ type: "text", text: "accumulated text" }] },
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const original = structuredClone(canonical);
|
|
55
|
+
const compact = browserOutputEvent(canonical, { outputMode: "compact-v1" });
|
|
56
|
+
assert.notStrictEqual(compact, canonical, "compact output must be browser-only");
|
|
57
|
+
assert.equal(compact.message, undefined, "duplicate accumulated top-level message should be removed");
|
|
58
|
+
assert.equal(compact.assistantMessageEvent.partial, undefined, "duplicate accumulated partial should be removed");
|
|
59
|
+
assert.equal(compact.assistantMessageEvent.delta, "", "empty deltas are semantically meaningful");
|
|
60
|
+
assert.equal(compact.assistantMessageEvent.contentIndex, 2);
|
|
61
|
+
assert.deepEqual(canonical, original, "the parsed/scoped source event must never be mutated");
|
|
62
|
+
assert.equal(JSON.parse(encodeBrowserSseEvent(canonical, { outputMode: "compact-v1" })).assistantMessageEvent.delta, "");
|
|
63
|
+
|
|
64
|
+
const malformed = { type: "message_update", assistantMessageEvent: { type: "text_delta", delta: 4, partial: { text: "must remain" } }, message: { role: "assistant" } };
|
|
65
|
+
assert.strictEqual(browserOutputEvent(malformed, { outputMode: "compact-v1" }), malformed, "malformed delta shapes fail open");
|
|
66
|
+
const unknown = { type: "message_update", assistantMessageEvent: { type: "unknown_delta", delta: "x", partial: { text: "must remain" } }, message: { role: "assistant" } };
|
|
67
|
+
assert.strictEqual(browserOutputEvent(unknown, { outputMode: "compact-v1" }), unknown, "unknown update shapes fail open");
|
|
68
|
+
assert.equal(browserOutputEvent({ type: "tool_execution_update", partialResult: {} }, { outputMode: "compact-v1" }), undefined, "compact v1 omits only intermediate tool updates");
|
|
69
|
+
assert.deepEqual(browserOutputEvent({ type: "tool_execution_end", result: { content: [] } }, { outputMode: "compact-v1" }), { type: "tool_execution_end", result: { content: [] } });
|
|
70
|
+
assert.equal(isOutputModeSemanticBarrier({ type: "message_end" }), true);
|
|
71
|
+
assert.equal(isOutputModeSemanticBarrier({ type: "agent_start" }), false);
|
|
72
|
+
|
|
73
|
+
console.log("webui-output-mode.test.mjs passed");
|
package/webui-rpc-helper.mjs
CHANGED
|
@@ -2,6 +2,11 @@ import { closeSync, fstatSync, openSync, readFileSync, readSync } from "node:fs"
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { AgentSession, formatSkillsForPrompt } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { readWebuiSettings } from "./lib/git-workflow-preferences.mjs";
|
|
5
|
+
import {
|
|
6
|
+
formatSubagentLaunchSlotGuidance,
|
|
7
|
+
resolveSubagentLaunchSlotProjectKey,
|
|
8
|
+
subagentLaunchSlotScopeEntry,
|
|
9
|
+
} from "./lib/subagent-launch-slots.mjs";
|
|
5
10
|
import { SUBAGENT_GATE_UPDATE_EVENT } from "./lib/subagent-gate.mjs";
|
|
6
11
|
|
|
7
12
|
const HELPER_COMMAND = "webui-helper";
|
|
@@ -540,6 +545,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
540
545
|
let enabledTools = new Set();
|
|
541
546
|
let disabledSkills = new Set();
|
|
542
547
|
let inheritedEnabledSkills = null;
|
|
548
|
+
let subagentLaunchSlotGuidance = "";
|
|
543
549
|
let subagentContext = null;
|
|
544
550
|
let subagentBridgeAvailable = false;
|
|
545
551
|
let subagentPollTimer = null;
|
|
@@ -889,6 +895,18 @@ export default function webuiRpcHelper(pi) {
|
|
|
889
895
|
}
|
|
890
896
|
}
|
|
891
897
|
|
|
898
|
+
async function loadSubagentLaunchSlotGuidance(ctx) {
|
|
899
|
+
try {
|
|
900
|
+
const settings = await readWebuiSettings();
|
|
901
|
+
const projectKey = await resolveSubagentLaunchSlotProjectKey(ctx?.cwd);
|
|
902
|
+
const effective = subagentLaunchSlotScopeEntry(settings.subagentLaunchSlots, "project", projectKey);
|
|
903
|
+
subagentLaunchSlotGuidance = formatSubagentLaunchSlotGuidance(effective.entry.roles);
|
|
904
|
+
} catch (error) {
|
|
905
|
+
subagentLaunchSlotGuidance = "";
|
|
906
|
+
console.warn(`Web UI subagent launch slots could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
892
910
|
function persistToolsState() {
|
|
893
911
|
pi.appendEntry(TOOLS_CONFIG_TYPE, { enabledTools: [...enabledTools] });
|
|
894
912
|
}
|
|
@@ -1053,6 +1071,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1053
1071
|
const globalDefaults = await readGlobalResourceDefaults();
|
|
1054
1072
|
restoreToolsFromBranch(ctx, globalDefaults);
|
|
1055
1073
|
restoreSkillsFromBranch(ctx, globalDefaults);
|
|
1074
|
+
await loadSubagentLaunchSlotGuidance(ctx);
|
|
1056
1075
|
subagentContext = ctx;
|
|
1057
1076
|
subagentPollGeneration += 1;
|
|
1058
1077
|
foregroundSubagentRuns.clear();
|
|
@@ -1128,6 +1147,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1128
1147
|
|
|
1129
1148
|
pi.on("session_shutdown", () => {
|
|
1130
1149
|
subagentContext = null;
|
|
1150
|
+
subagentLaunchSlotGuidance = "";
|
|
1131
1151
|
subagentPollGeneration += 1;
|
|
1132
1152
|
clearTimeout(subagentPollTimer);
|
|
1133
1153
|
subagentPollTimer = null;
|
|
@@ -1147,14 +1167,22 @@ export default function webuiRpcHelper(pi) {
|
|
|
1147
1167
|
});
|
|
1148
1168
|
|
|
1149
1169
|
pi.on("before_agent_start", async (event) => {
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
if (
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1170
|
+
let nextPrompt = event.systemPrompt;
|
|
1171
|
+
let changed = false;
|
|
1172
|
+
if (disabledSkills.size !== 0 || inheritedEnabledSkills !== null) {
|
|
1173
|
+
const allSkills = Array.isArray(event.systemPromptOptions?.skills) ? event.systemPromptOptions.skills : [];
|
|
1174
|
+
const disabledNames = allSkills.filter((skill) => !isSkillEnabled(skill.name)).map((skill) => skill.name);
|
|
1175
|
+
if (disabledNames.length) {
|
|
1176
|
+
const filteredSkills = allSkills.filter((skill) => isSkillEnabled(skill.name));
|
|
1177
|
+
nextPrompt = replaceAvailableSkillsSection(nextPrompt, filteredSkills);
|
|
1178
|
+
for (const name of disabledNames) nextPrompt = nextPrompt.replace(skillBlockPattern(name), "");
|
|
1179
|
+
changed = true;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
if (subagentLaunchSlotGuidance) {
|
|
1183
|
+
nextPrompt = `${String(nextPrompt || "").trimEnd()}\n\n${subagentLaunchSlotGuidance}\n`;
|
|
1184
|
+
changed = true;
|
|
1185
|
+
}
|
|
1186
|
+
return changed ? { systemPrompt: nextPrompt } : undefined;
|
|
1159
1187
|
});
|
|
1160
1188
|
}
|