@firstpick/pi-package-webui 0.5.6 → 0.5.8
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 +3 -1
- package/bin/pi-webui.mjs +526 -28
- package/lib/git-worktrees.mjs +512 -0
- package/package.json +3 -3
- package/public/app.js +703 -118
- package/public/index.html +13 -7
- package/public/styles.css +365 -24
- package/tests/http-endpoints-harness.test.mjs +192 -1
- package/tests/mobile-static.test.mjs +52 -20
- package/tests/native-parity-harness.test.mjs +1 -1
- package/tests/native-parity.test.mjs +2 -2
- package/tests/streaming-ui-coupling.test.mjs +15 -4
- package/webui-rpc-helper.mjs +99 -1
- /package/{dev/docs → lib}/WEBUI_TUI_NATIVE_PARITY.json +0 -0
package/webui-rpc-helper.mjs
CHANGED
|
@@ -1,9 +1,40 @@
|
|
|
1
|
-
import { formatSkillsForPrompt } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import { AgentSession, formatSkillsForPrompt } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
3
|
const HELPER_COMMAND = "webui-helper";
|
|
4
4
|
const RESPONSE_PREFIX = "__PI_WEBUI_HELPER_RESPONSE__:";
|
|
5
5
|
const TOOLS_CONFIG_TYPE = "webui-tools-config";
|
|
6
6
|
const SKILLS_CONFIG_TYPE = "webui-skills-config";
|
|
7
|
+
const APP_RUNNER_CONTEXT_TYPE = "webui-app-runner-output";
|
|
8
|
+
|
|
9
|
+
const ACTIVE_COMMAND_SESSION_KEY = Symbol.for("pi.webui.helper.activeCommandSession");
|
|
10
|
+
|
|
11
|
+
function activeCommandSession() {
|
|
12
|
+
return globalThis[ACTIVE_COMMAND_SESSION_KEY];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function setActiveCommandSession(session) {
|
|
16
|
+
if (session) globalThis[ACTIVE_COMMAND_SESSION_KEY] = session;
|
|
17
|
+
else delete globalThis[ACTIVE_COMMAND_SESSION_KEY];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function installActiveCommandSessionCapture() {
|
|
21
|
+
const proto = AgentSession?.prototype;
|
|
22
|
+
if (!proto || proto.__webuiHelperCommandSessionCaptureInstalled) return;
|
|
23
|
+
const original = proto._tryExecuteExtensionCommand;
|
|
24
|
+
if (typeof original !== "function") return;
|
|
25
|
+
Object.defineProperty(proto, "__webuiHelperCommandSessionCaptureInstalled", { value: true });
|
|
26
|
+
proto._tryExecuteExtensionCommand = async function webuiHelperTryExecuteExtensionCommand(...args) {
|
|
27
|
+
const previous = activeCommandSession();
|
|
28
|
+
setActiveCommandSession(this);
|
|
29
|
+
try {
|
|
30
|
+
return await original.apply(this, args);
|
|
31
|
+
} finally {
|
|
32
|
+
setActiveCommandSession(previous);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
installActiveCommandSessionCapture();
|
|
7
38
|
|
|
8
39
|
function responseMessage(payload) {
|
|
9
40
|
return `${RESPONSE_PREFIX}${JSON.stringify(payload)}`;
|
|
@@ -43,6 +74,51 @@ function normalizeNameList(value) {
|
|
|
43
74
|
return names;
|
|
44
75
|
}
|
|
45
76
|
|
|
77
|
+
function queueMessageText(message) {
|
|
78
|
+
const content = message?.content;
|
|
79
|
+
if (typeof content === "string") return content;
|
|
80
|
+
if (!Array.isArray(content)) return "";
|
|
81
|
+
return content.filter((part) => part?.type === "text").map((part) => String(part.text || "")).join("\n");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function queuedMessagesSnapshot(session) {
|
|
85
|
+
return {
|
|
86
|
+
steering: Array.from(session?.getSteeringMessages?.() || []).map((item) => String(item || "")).filter((item) => item.trim()),
|
|
87
|
+
followUp: Array.from(session?.getFollowUpMessages?.() || []).map((item) => String(item || "")).filter((item) => item.trim()),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function normalizeQueueKind(value) {
|
|
92
|
+
const normalized = String(value || "").trim();
|
|
93
|
+
if (normalized === "follow-up" || normalized.toLowerCase() === "followup") return "followUp";
|
|
94
|
+
if (normalized === "steer") return "steering";
|
|
95
|
+
if (normalized === "steering" || normalized === "followUp") return normalized;
|
|
96
|
+
throw new Error("Queue removal requires kind 'followUp' or 'steering'");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function removeQueuedPrompt(payload = {}) {
|
|
100
|
+
const session = activeCommandSession();
|
|
101
|
+
if (!session) throw new Error("Web UI queue removal is unavailable in this Pi version; reload this tab and retry.");
|
|
102
|
+
const kind = normalizeQueueKind(payload.kind || "followUp");
|
|
103
|
+
const index = Number.parseInt(String(payload.index ?? ""), 10);
|
|
104
|
+
if (!Number.isInteger(index) || index < 0) throw new Error("Queue removal requires a zero-based item index");
|
|
105
|
+
const expectedText = String(payload.message ?? payload.text ?? "");
|
|
106
|
+
const tracked = kind === "followUp" ? session._followUpMessages : session._steeringMessages;
|
|
107
|
+
const agentQueue = kind === "followUp" ? session.agent?.followUpQueue : session.agent?.steeringQueue;
|
|
108
|
+
if (!Array.isArray(tracked) || !Array.isArray(agentQueue?.messages)) {
|
|
109
|
+
throw new Error("Web UI queue removal is not supported by this Pi runtime.");
|
|
110
|
+
}
|
|
111
|
+
const currentText = String(tracked[index] || "");
|
|
112
|
+
const agentText = queueMessageText(agentQueue.messages[index]);
|
|
113
|
+
if (!currentText || (expectedText && currentText !== expectedText) || (expectedText && agentText !== expectedText)) {
|
|
114
|
+
return { removed: false, reason: "queue-changed", queue: queuedMessagesSnapshot(session) };
|
|
115
|
+
}
|
|
116
|
+
tracked.splice(index, 1);
|
|
117
|
+
agentQueue.messages.splice(index, 1);
|
|
118
|
+
session._emitQueueUpdate?.();
|
|
119
|
+
return { removed: true, kind, index, message: currentText, queue: queuedMessagesSnapshot(session) };
|
|
120
|
+
}
|
|
121
|
+
|
|
46
122
|
function parseHelperArgs(args) {
|
|
47
123
|
let parsed;
|
|
48
124
|
try {
|
|
@@ -170,6 +246,24 @@ export default function webuiRpcHelper(pi) {
|
|
|
170
246
|
return skillState(ctx);
|
|
171
247
|
}
|
|
172
248
|
|
|
249
|
+
function transferAppRunnerContext(ctx, payload) {
|
|
250
|
+
const content = String(payload?.content || "").trimEnd();
|
|
251
|
+
if (!content.trim()) throw new Error("App runner context content is empty");
|
|
252
|
+
const details = payload?.details && typeof payload.details === "object" ? payload.details : {};
|
|
253
|
+
const isIdle = ctx.isIdle();
|
|
254
|
+
pi.sendMessage({
|
|
255
|
+
customType: APP_RUNNER_CONTEXT_TYPE,
|
|
256
|
+
content,
|
|
257
|
+
display: true,
|
|
258
|
+
details,
|
|
259
|
+
}, isIdle ? undefined : { deliverAs: "steer" });
|
|
260
|
+
return {
|
|
261
|
+
customType: APP_RUNNER_CONTEXT_TYPE,
|
|
262
|
+
delivery: isIdle ? "context" : "steer",
|
|
263
|
+
lineCount: Number(details.lineCount || 0) || undefined,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
173
267
|
function executeAction(action, payload, ctx) {
|
|
174
268
|
switch (action) {
|
|
175
269
|
case "tools-state":
|
|
@@ -180,6 +274,10 @@ export default function webuiRpcHelper(pi) {
|
|
|
180
274
|
return skillState(ctx);
|
|
181
275
|
case "skills-set":
|
|
182
276
|
return setSkillState(ctx, payload);
|
|
277
|
+
case "app-runner-context":
|
|
278
|
+
return transferAppRunnerContext(ctx, payload);
|
|
279
|
+
case "queue-remove":
|
|
280
|
+
return removeQueuedPrompt(payload);
|
|
183
281
|
default:
|
|
184
282
|
throw new Error(`Unknown ${HELPER_COMMAND} action: ${action}`);
|
|
185
283
|
}
|
|
File without changes
|