@firstpick/pi-package-webui 0.8.5 → 0.8.7
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 +18 -584
- package/bin/pi-webui-launcher.mjs +22 -0
- package/bin/pi-webui-update-supervisor.mjs +86 -0
- package/bin/pi-webui.mjs +933 -554
- package/index.ts +16 -6
- package/lib/component-update-state.mjs +21 -0
- package/lib/git-workflow-preferences.mjs +20 -2
- package/lib/optional-feature-catalog.mjs +1 -0
- package/lib/sampling-parameter-capabilities.mjs +160 -0
- package/lib/session-summary-core.mjs +4 -3
- package/lib/session-summary-preferences.mjs +16 -1
- package/lib/subagent-launch-slots.mjs +14 -2
- package/lib/trust-boundaries.mjs +16 -0
- package/lib/update/executor.mjs +99 -0
- package/lib/update/journal.mjs +175 -0
- package/lib/update/owners.mjs +70 -0
- package/lib/update/plan.mjs +134 -0
- package/lib/update/resolver.mjs +168 -0
- package/lib/update/supervisor.mjs +238 -0
- package/lib/update/verify.mjs +52 -0
- package/lib/update-commands.mjs +25 -13
- package/lib/webui-workspaces.mjs +17 -1
- package/lib/workspace-session-summaries.mjs +400 -0
- package/package.json +4 -4
- package/public/app.js +2487 -349
- package/public/index.html +200 -51
- package/public/middle-button-drag-scroll.mjs +154 -0
- package/public/sampling-parameter-controls.mjs +361 -0
- package/public/service-worker.js +5 -1
- package/public/stream-output-controller.mjs +327 -0
- package/public/styles.css +666 -71
- package/public/theme-contract.mjs +244 -0
- package/session-summary.ts +164 -4
- package/tests/aur-review-widget-static.test.mjs +2 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-deck-component-updates.spec.mjs +20 -22
- package/tests/browser/interaction-continuity.spec.mjs +2 -2
- package/tests/browser/middle-button-drag-scroll.spec.mjs +145 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +68 -23
- package/tests/browser/sampling-tooltip.spec.mjs +228 -0
- package/tests/browser/session-summary.spec.mjs +131 -3
- package/tests/browser/stream-output-isolation.spec.mjs +510 -0
- package/tests/browser/update-reconnect.spec.mjs +92 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/common-options-submenus-interaction-static.test.mjs +172 -0
- package/tests/common-options-submenus-markup-static.test.mjs +152 -0
- package/tests/component-update-api-static.test.mjs +22 -61
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +13 -237
- package/tests/durable-rpc-supervisor-harness.test.mjs +3 -1
- package/tests/fast-mode-client-static.test.mjs +3 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +49 -0
- package/tests/fixtures/fake-pi.mjs +269 -2
- package/tests/fixtures/update/tree-timeout-descendant.mjs +6 -0
- package/tests/fixtures/update/tree-timeout-parent.mjs +11 -0
- package/tests/git-footer-context-menu-static.test.mjs +58 -0
- package/tests/git-workflow-preferences.test.mjs +7 -1
- package/tests/guided-git-aur-review.test.mjs +4 -3
- package/tests/http-endpoints-harness.test.mjs +274 -23
- package/tests/middle-button-drag-scroll-static.test.mjs +24 -0
- package/tests/middle-button-drag-scroll.test.mjs +170 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +5 -6
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +85 -50
- package/tests/native-parity.test.mjs +1 -1
- package/tests/open-issue-wizard-static.test.mjs +2 -3
- package/tests/optional-feature-migration-frontend.test.mjs +9 -5
- package/tests/persistent-ui-layout-static.test.mjs +13 -2
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +43 -0
- package/tests/rpc-supervisor-host.test.mjs +11 -2
- package/tests/safety-guard-auto-review-harness.test.mjs +117 -0
- package/tests/safety-guard-auto-review-static.test.mjs +34 -0
- package/tests/sampling-native-controls-user-flow.test.mjs +752 -0
- package/tests/sampling-parameter-capabilities.test.mjs +167 -0
- package/tests/sampling-parameter-controls.test.mjs +241 -0
- package/tests/session-sampling-helper.test.mjs +228 -0
- package/tests/session-sampling-http.test.mjs +168 -0
- package/tests/session-sampling-ui-static.test.mjs +370 -0
- package/tests/session-summary-core.test.mjs +205 -10
- package/tests/side-panel-section-height-removal-static.test.mjs +34 -0
- package/tests/side-panel-section-reorder-static.test.mjs +3 -3
- package/tests/staged-content-hash-contract.test.mjs +52 -11
- package/tests/stream-lifecycle-core.test.mjs +134 -0
- package/tests/stream-output-controller.test.mjs +252 -0
- package/tests/stream-output-isolation-static.test.mjs +89 -0
- package/tests/streaming-ui-coupling.test.mjs +50 -0
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagent-launch-slots.test.mjs +18 -1
- package/tests/theme-contract.test.mjs +104 -0
- package/tests/theme-customizer-static.test.mjs +82 -0
- package/tests/theme-scheme-mode.test.mjs +15 -0
- package/tests/ui-layout-settings.test.mjs +18 -1
- package/tests/update-api-harness.test.mjs +111 -0
- package/tests/update-commands.test.mjs +15 -45
- package/tests/update-executor-process-tree-harness.test.mjs +22 -0
- package/tests/update-journal-harness.test.mjs +59 -0
- package/tests/update-lock-multiprocess-harness.test.mjs +46 -0
- package/tests/update-owners.test.mjs +27 -0
- package/tests/update-plan.test.mjs +58 -0
- package/tests/update-resolver.test.mjs +56 -0
- package/tests/update-supervisor-harness.test.mjs +57 -0
- package/tests/update-tab-restore-harness.test.mjs +24 -0
- package/tests/update-verify.test.mjs +31 -0
- package/tests/workspace-files-live-updates-static.test.mjs +13 -4
- package/tests/workspace-session-summaries.test.mjs +288 -0
- package/webui-rpc-helper.mjs +119 -0
package/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawn, type ChildProcessByStdio } from "node:child_process";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import type { Readable } from "node:stream";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
@@ -7,6 +8,7 @@ import { delay, takeValue, tokenizeArgs } from "@firstpick/pi-utils";
|
|
|
7
8
|
import { detachChildProcess as releaseStartedChild, isProcessRunning, terminateChildProcess as terminateFailedChild } from "@firstpick/pi-utils/process";
|
|
8
9
|
import { fetchJsonWithTimeout as fetchJsonWithTimeoutBase } from "@firstpick/pi-utils/http";
|
|
9
10
|
import { registerSubagentGate } from "./lib/subagent-gate.mjs";
|
|
11
|
+
import { createRestoreFile } from "./lib/update/supervisor.mjs";
|
|
10
12
|
import {
|
|
11
13
|
gitWorkflowPreferencesSummary,
|
|
12
14
|
readGitWorkflowPreferences,
|
|
@@ -16,7 +18,8 @@ import {
|
|
|
16
18
|
|
|
17
19
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
18
20
|
const packageRoot = __dirname;
|
|
19
|
-
const webuiBin = path.join(packageRoot, "bin", "pi-webui.mjs");
|
|
21
|
+
const webuiBin = path.join(packageRoot, "bin", "pi-webui-launcher.mjs");
|
|
22
|
+
const agentDir = process.env.PI_CODING_AGENT_DIR || path.join(homedir(), ".pi", "agent");
|
|
20
23
|
|
|
21
24
|
const DEFAULT_HOST = "127.0.0.1";
|
|
22
25
|
const DEFAULT_PORT = 31415;
|
|
@@ -216,7 +219,7 @@ function restorableTabsFromStatus(tabs: unknown, options: StartWebuiOptions): Re
|
|
|
216
219
|
if (!options.noSession) restoreTab.sessionFile = boundedString(state.sessionFile || tab.sessionFile, 4096);
|
|
217
220
|
|
|
218
221
|
restored.push(restoreTab);
|
|
219
|
-
if (restored.length >=
|
|
222
|
+
if (restored.length >= 256) break;
|
|
220
223
|
}
|
|
221
224
|
return restored;
|
|
222
225
|
}
|
|
@@ -247,7 +250,7 @@ function mergeRestorableTabsFromStatusSources(sources: unknown[], options: Start
|
|
|
247
250
|
const keys = restorableTabKeys(tab);
|
|
248
251
|
const existingIndex = keys.map((key) => keyToIndex.get(key)).find((index): index is number => index !== undefined);
|
|
249
252
|
if (existingIndex === undefined) {
|
|
250
|
-
if (merged.length >=
|
|
253
|
+
if (merged.length >= 256) continue;
|
|
251
254
|
const index = merged.length;
|
|
252
255
|
merged.push(tab);
|
|
253
256
|
for (const key of keys) keyToIndex.set(key, index);
|
|
@@ -258,7 +261,7 @@ function mergeRestorableTabsFromStatusSources(sources: unknown[], options: Start
|
|
|
258
261
|
}
|
|
259
262
|
}
|
|
260
263
|
|
|
261
|
-
return merged.slice(0,
|
|
264
|
+
return merged.slice(0, 256);
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
async function fetchRestorableTabs(url: string, existing: ExistingWebui, options: StartWebuiOptions): Promise<RestorableWebuiTab[]> {
|
|
@@ -463,7 +466,7 @@ async function startWebui(options: StartWebuiOptions, ctx: ExtensionCommandConte
|
|
|
463
466
|
if (options.piArgs.length > 0) args.push("--", ...options.piArgs);
|
|
464
467
|
|
|
465
468
|
const env = { ...process.env };
|
|
466
|
-
if (restoreTabs.length > 0) env.
|
|
469
|
+
if (restoreTabs.length > 0) env.PI_WEBUI_RESTORE_FILE = (await createRestoreFile(agentDir, restoreTabs)).file;
|
|
467
470
|
|
|
468
471
|
const child = spawn(process.execPath, args, {
|
|
469
472
|
cwd: ctx.cwd,
|
|
@@ -824,6 +827,12 @@ async function runGitWorkflowSetup(ctx: ExtensionCommandContext): Promise<void>
|
|
|
824
827
|
], current.stagingPolicy);
|
|
825
828
|
if (!stagingPolicy) return;
|
|
826
829
|
|
|
830
|
+
const reviewProcess = await selectGitWorkflowSetupValue(ctx, "Manual review process", [
|
|
831
|
+
{ value: "enabled", label: "Enabled when aur-review is available" },
|
|
832
|
+
{ value: "disabled", label: "Disabled — continue directly to message generation" },
|
|
833
|
+
], current.reviewProcessEnabled ? "enabled" : "disabled");
|
|
834
|
+
if (!reviewProcess) return;
|
|
835
|
+
|
|
827
836
|
const deliveryMode = await selectGitWorkflowSetupValue(ctx, "Default delivery path", [
|
|
828
837
|
{ value: "ask", label: "Ask each workflow" },
|
|
829
838
|
{ value: "current", label: "Prefer the current branch" },
|
|
@@ -846,6 +855,7 @@ async function runGitWorkflowSetup(ctx: ExtensionCommandContext): Promise<void>
|
|
|
846
855
|
},
|
|
847
856
|
commit: { language, defaultVariant, scope },
|
|
848
857
|
stagingPolicy,
|
|
858
|
+
reviewProcessEnabled: reviewProcess === "enabled",
|
|
849
859
|
deliveryMode,
|
|
850
860
|
verificationPolicy,
|
|
851
861
|
};
|
|
@@ -896,7 +906,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
896
906
|
};
|
|
897
907
|
|
|
898
908
|
pi.registerCommand("git-workflow-setup", {
|
|
899
|
-
description: "Configure the model, reasoning effort, staging, and commit defaults for guided Git",
|
|
909
|
+
description: "Configure the model, reasoning effort, staging, review process, and commit defaults for guided Git",
|
|
900
910
|
handler: async (_args, ctx) => runGitWorkflowSetup(ctx),
|
|
901
911
|
});
|
|
902
912
|
|
|
@@ -37,6 +37,27 @@ export function validateComponentUpdateRequest(body) {
|
|
|
37
37
|
return { ok: true, target: body.target };
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export function validateUpdatePlanRequest(body) {
|
|
41
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return { ok: false, error: "Request body must be an object." };
|
|
42
|
+
const keys = Object.keys(body).sort();
|
|
43
|
+
if (keys.some((key) => !["targets"].includes(key)) || !Array.isArray(body.targets) || body.targets.length < 1 || body.targets.length > 2) {
|
|
44
|
+
return { ok: false, error: "targets must contain one or both exact values: pi, webui." };
|
|
45
|
+
}
|
|
46
|
+
const targets = [...new Set(body.targets)];
|
|
47
|
+
if (targets.length !== body.targets.length || targets.some((target) => !TARGET_SET.has(target))) return { ok: false, error: "targets contains an unsupported or duplicate target." };
|
|
48
|
+
return { ok: true, targets };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function validateUpdateApplyRequest(body) {
|
|
52
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return { ok: false, error: "Request body must be an object." };
|
|
53
|
+
const keys = Object.keys(body).sort();
|
|
54
|
+
if (keys.join(",") !== "planDigest,transactionId") return { ok: false, error: "Apply accepts only transactionId and planDigest." };
|
|
55
|
+
if (!/^[A-Za-z0-9._-]{1,128}$/.test(String(body.transactionId || "")) || !/^[a-f0-9]{64}$/.test(String(body.planDigest || ""))) {
|
|
56
|
+
return { ok: false, error: "transactionId or planDigest is invalid." };
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, transactionId: body.transactionId, planDigest: body.planDigest };
|
|
59
|
+
}
|
|
60
|
+
|
|
40
61
|
function initialState(target) {
|
|
41
62
|
return {
|
|
42
63
|
target,
|
|
@@ -58,6 +58,7 @@ export function defaultGitWorkflowPreferences() {
|
|
|
58
58
|
scope: "auto",
|
|
59
59
|
},
|
|
60
60
|
stagingPolicy: "review",
|
|
61
|
+
reviewProcessEnabled: true,
|
|
61
62
|
deliveryMode: "ask",
|
|
62
63
|
verificationPolicy: "ask",
|
|
63
64
|
};
|
|
@@ -81,6 +82,7 @@ export function normalizeGitWorkflowPreferences(value) {
|
|
|
81
82
|
scope: choice(value?.commit?.scope, GIT_WORKFLOW_SCOPE_POLICIES, defaults.commit.scope),
|
|
82
83
|
},
|
|
83
84
|
stagingPolicy: choice(value?.stagingPolicy, GIT_WORKFLOW_STAGING_POLICIES, defaults.stagingPolicy),
|
|
85
|
+
reviewProcessEnabled: typeof value?.reviewProcessEnabled === "boolean" ? value.reviewProcessEnabled : defaults.reviewProcessEnabled,
|
|
84
86
|
deliveryMode: choice(value?.deliveryMode, GIT_WORKFLOW_DELIVERY_MODES, defaults.deliveryMode),
|
|
85
87
|
verificationPolicy: choice(value?.verificationPolicy, GIT_WORKFLOW_VERIFICATION_POLICIES, defaults.verificationPolicy),
|
|
86
88
|
};
|
|
@@ -109,6 +111,7 @@ export function gitWorkflowPreferencesSummary(preferences) {
|
|
|
109
111
|
`Thinking: ${value.generation.thinkingLevel}`,
|
|
110
112
|
`Commit: ${value.commit.language} · ${value.commit.defaultVariant} · scope ${value.commit.scope}`,
|
|
111
113
|
`Staging: ${value.stagingPolicy}`,
|
|
114
|
+
`Review process: ${value.reviewProcessEnabled ? "enabled" : "disabled"}`,
|
|
112
115
|
`Delivery: ${value.deliveryMode}`,
|
|
113
116
|
`Verification: ${value.verificationPolicy}`,
|
|
114
117
|
].join("\n");
|
|
@@ -246,6 +249,21 @@ async function readSettingsLockRecords(lockDirectory) {
|
|
|
246
249
|
}));
|
|
247
250
|
}
|
|
248
251
|
|
|
252
|
+
async function renameWithWindowsRetry(source, target) {
|
|
253
|
+
let lastError;
|
|
254
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
255
|
+
try {
|
|
256
|
+
await rename(source, target);
|
|
257
|
+
return;
|
|
258
|
+
} catch (error) {
|
|
259
|
+
lastError = error;
|
|
260
|
+
if (process.platform !== "win32" || !["EACCES", "EBUSY", "EPERM"].includes(error?.code)) throw error;
|
|
261
|
+
await delay(25 * (attempt + 1));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
throw lastError;
|
|
265
|
+
}
|
|
266
|
+
|
|
249
267
|
async function writeSettingsLockRecord(recordFile, value) {
|
|
250
268
|
const temporaryFile = `${recordFile}.${process.pid}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
251
269
|
let handle;
|
|
@@ -255,7 +273,7 @@ async function writeSettingsLockRecord(recordFile, value) {
|
|
|
255
273
|
await handle.sync();
|
|
256
274
|
await handle.close();
|
|
257
275
|
handle = undefined;
|
|
258
|
-
await
|
|
276
|
+
await renameWithWindowsRetry(temporaryFile, recordFile);
|
|
259
277
|
} catch (error) {
|
|
260
278
|
await handle?.close().catch(() => {});
|
|
261
279
|
await rm(temporaryFile, { force: true }).catch(() => {});
|
|
@@ -357,7 +375,7 @@ async function writePrivateAtomicSettings(storageFile, value) {
|
|
|
357
375
|
await handle.sync();
|
|
358
376
|
await handle.close();
|
|
359
377
|
handle = undefined;
|
|
360
|
-
await
|
|
378
|
+
await renameWithWindowsRetry(temporaryFile, storageFile);
|
|
361
379
|
await syncDirectoryBestEffort(path.dirname(storageFile));
|
|
362
380
|
} catch (error) {
|
|
363
381
|
await handle?.close().catch(() => {});
|
|
@@ -7,6 +7,7 @@ const entries = [
|
|
|
7
7
|
["releaseAur", "@firstpick/pi-extension-release-aur", "^0.1.8"],
|
|
8
8
|
["aurReview", "@firstpick/pi-extension-aur-review", "^0.1.1"],
|
|
9
9
|
["workflows", "@firstpick/pi-extension-workflows", "^0.1.7"],
|
|
10
|
+
["featureSystemPrompt", "@firstpick/pi-extension-feature-system-prompt", "^0.1.3"],
|
|
10
11
|
["safetyGuard", "@firstpick/pi-extension-safety-guard", "^0.2.6"],
|
|
11
12
|
["tuiSkillsCommand", "@firstpick/pi-extension-setup-skills", "^0.1.9"],
|
|
12
13
|
["todoProgressWidget", "@firstpick/pi-extension-todo-progress", "^0.2.9"],
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { SAMPLING_PARAMETER_KEYS } from "../public/sampling-parameter-controls.mjs";
|
|
2
|
+
|
|
3
|
+
export { SAMPLING_PARAMETER_KEYS };
|
|
4
|
+
|
|
5
|
+
export const BUILTIN_SAMPLING_APIS = Object.freeze([
|
|
6
|
+
"openai-completions",
|
|
7
|
+
"openai-responses",
|
|
8
|
+
"azure-openai-responses",
|
|
9
|
+
"openai-codex-responses",
|
|
10
|
+
"anthropic-messages",
|
|
11
|
+
"google-generative-ai",
|
|
12
|
+
"google-vertex",
|
|
13
|
+
"bedrock-converse-stream",
|
|
14
|
+
"mistral-conversations",
|
|
15
|
+
"pi-messages",
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const LABELS = Object.freeze({
|
|
19
|
+
temperature: "Temperature",
|
|
20
|
+
top_p: "Top P",
|
|
21
|
+
frequency_penalty: "Frequency Penalty",
|
|
22
|
+
presence_penalty: "Presence Penalty",
|
|
23
|
+
seed: "Seed",
|
|
24
|
+
top_k: "Top K",
|
|
25
|
+
min_p: "Min P",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const API_KEYS = Object.freeze({
|
|
29
|
+
"openai-completions": ["temperature", "top_p", "frequency_penalty", "presence_penalty", "seed"],
|
|
30
|
+
"openai-responses": ["temperature", "top_p"],
|
|
31
|
+
"azure-openai-responses": ["temperature", "top_p"],
|
|
32
|
+
"openai-codex-responses": ["temperature"],
|
|
33
|
+
"anthropic-messages": ["temperature"],
|
|
34
|
+
"google-generative-ai": ["temperature", "top_p", "frequency_penalty", "presence_penalty", "seed", "top_k"],
|
|
35
|
+
"google-vertex": ["temperature", "top_p", "frequency_penalty", "presence_penalty", "seed", "top_k"],
|
|
36
|
+
"bedrock-converse-stream": ["temperature", "top_p"],
|
|
37
|
+
"mistral-conversations": ["temperature"],
|
|
38
|
+
"pi-messages": ["temperature"],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function plainObject(value) {
|
|
42
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
43
|
+
const prototype = Object.getPrototypeOf(value);
|
|
44
|
+
return prototype === Object.prototype || prototype === null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function activeAnthropicThinking(model, thinkingLevel) {
|
|
48
|
+
return model?.reasoning === true && typeof thinkingLevel === "string" && thinkingLevel !== "off";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function unsupportedReason(api, key) {
|
|
52
|
+
if (!api || !Object.hasOwn(API_KEYS, api)) {
|
|
53
|
+
return `${LABELS[key]} is disabled because this provider has not declared support.`;
|
|
54
|
+
}
|
|
55
|
+
return `${api} does not declare ${LABELS[key]} support.`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Resolve deterministic, per-key support from the active model contract. */
|
|
59
|
+
export function resolveSamplingParameterCapabilities(model, { thinkingLevel } = {}) {
|
|
60
|
+
const api = typeof model?.api === "string" ? model.api : null;
|
|
61
|
+
const declared = Object.hasOwn(API_KEYS, api) ? new Set(API_KEYS[api]) : new Set();
|
|
62
|
+
const defaults = plainObject(model?.samplingParams) ? model.samplingParams : {};
|
|
63
|
+
const parameters = {};
|
|
64
|
+
|
|
65
|
+
for (const key of SAMPLING_PARAMETER_KEYS) {
|
|
66
|
+
let supported = declared.has(key);
|
|
67
|
+
let source = supported ? "api" : "unsupported";
|
|
68
|
+
let reason = supported ? `Supported by ${api}.` : unsupportedReason(api, key);
|
|
69
|
+
|
|
70
|
+
if (api === "openai-completions" && (key === "top_k" || key === "min_p") && Object.hasOwn(defaults, key)) {
|
|
71
|
+
supported = true;
|
|
72
|
+
source = "model";
|
|
73
|
+
reason = `Supported by ${api} because the active model declares ${LABELS[key]}.`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (api === "anthropic-messages" && key === "temperature" && supported) {
|
|
77
|
+
if (model?.compat?.supportsTemperature === false) {
|
|
78
|
+
supported = false;
|
|
79
|
+
source = "unsupported";
|
|
80
|
+
reason = "Temperature is disabled because the active Anthropic model marks it unsupported.";
|
|
81
|
+
} else if (activeAnthropicThinking(model, thinkingLevel)) {
|
|
82
|
+
supported = false;
|
|
83
|
+
source = "unsupported";
|
|
84
|
+
reason = "Temperature is disabled while Anthropic extended thinking is active.";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
parameters[key] = { supported, reason, source };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return parameters;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function filterSupportedSamplingParameters(values, parameters) {
|
|
95
|
+
if (!plainObject(values)) return {};
|
|
96
|
+
const filtered = {};
|
|
97
|
+
for (const key of SAMPLING_PARAMETER_KEYS) {
|
|
98
|
+
if (parameters?.[key]?.supported === true && Object.hasOwn(values, key)) filtered[key] = values[key];
|
|
99
|
+
}
|
|
100
|
+
return filtered;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function mergeNested(payload, property, additions) {
|
|
104
|
+
const existing = plainObject(payload[property]) ? payload[property] : {};
|
|
105
|
+
return { ...payload, [property]: { ...existing, ...additions } };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function anthropicPayloadHasThinking(payload) {
|
|
109
|
+
const type = plainObject(payload.thinking) ? payload.thinking.type : undefined;
|
|
110
|
+
return type === "enabled" || type === "adaptive";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Apply already-stored values to an API-native provider payload without mutating it. */
|
|
114
|
+
export function applySupportedSamplingParameters(payload, model, values, { thinkingLevel } = {}) {
|
|
115
|
+
if (!plainObject(payload)) return undefined;
|
|
116
|
+
const api = typeof model?.api === "string" ? model.api : null;
|
|
117
|
+
const parameters = resolveSamplingParameterCapabilities(model, { thinkingLevel });
|
|
118
|
+
const supported = filterSupportedSamplingParameters(values, parameters);
|
|
119
|
+
if (Object.keys(supported).length === 0) return undefined;
|
|
120
|
+
|
|
121
|
+
if (api === "anthropic-messages" && anthropicPayloadHasThinking(payload)) {
|
|
122
|
+
delete supported.temperature;
|
|
123
|
+
if (Object.keys(supported).length === 0) return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
switch (api) {
|
|
127
|
+
case "openai-completions":
|
|
128
|
+
case "openai-responses":
|
|
129
|
+
case "azure-openai-responses":
|
|
130
|
+
case "openai-codex-responses":
|
|
131
|
+
case "anthropic-messages":
|
|
132
|
+
case "mistral-conversations":
|
|
133
|
+
return { ...payload, ...supported };
|
|
134
|
+
case "google-generative-ai":
|
|
135
|
+
case "google-vertex":
|
|
136
|
+
return mergeNested(payload, "config", {
|
|
137
|
+
...(Object.hasOwn(supported, "temperature") && { temperature: supported.temperature }),
|
|
138
|
+
...(Object.hasOwn(supported, "top_p") && { topP: supported.top_p }),
|
|
139
|
+
...(Object.hasOwn(supported, "top_k") && { topK: supported.top_k }),
|
|
140
|
+
...(Object.hasOwn(supported, "frequency_penalty") && { frequencyPenalty: supported.frequency_penalty }),
|
|
141
|
+
...(Object.hasOwn(supported, "presence_penalty") && { presencePenalty: supported.presence_penalty }),
|
|
142
|
+
...(Object.hasOwn(supported, "seed") && { seed: supported.seed }),
|
|
143
|
+
});
|
|
144
|
+
case "bedrock-converse-stream":
|
|
145
|
+
return mergeNested(payload, "inferenceConfig", {
|
|
146
|
+
...(Object.hasOwn(supported, "temperature") && { temperature: supported.temperature }),
|
|
147
|
+
...(Object.hasOwn(supported, "top_p") && { topP: supported.top_p }),
|
|
148
|
+
});
|
|
149
|
+
case "pi-messages":
|
|
150
|
+
return mergeNested(payload, "options", {
|
|
151
|
+
...(Object.hasOwn(supported, "temperature") && { temperature: supported.temperature }),
|
|
152
|
+
});
|
|
153
|
+
default:
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function samplingApiSupportsAnyParameter(model, options) {
|
|
159
|
+
return Object.values(resolveSamplingParameterCapabilities(model, options)).some((capability) => capability.supported);
|
|
160
|
+
}
|
|
@@ -146,11 +146,12 @@ export function normalizeSummaryState(value) {
|
|
|
146
146
|
if (!value || typeof value !== "object" || value.version !== SESSION_SUMMARY_PROTOCOL_VERSION || !validSource(value.source)) return undefined;
|
|
147
147
|
let result;
|
|
148
148
|
try {
|
|
149
|
-
const
|
|
149
|
+
const resultInput = {
|
|
150
150
|
version: SESSION_SUMMARY_PROTOCOL_VERSION,
|
|
151
|
-
title: value.result?.title,
|
|
152
151
|
summaryMarkdown: value.result?.summaryMarkdown,
|
|
153
|
-
}
|
|
152
|
+
};
|
|
153
|
+
if (value.result?.title !== undefined) resultInput.title = value.result.title;
|
|
154
|
+
const parsed = parseSummaryObject(resultInput);
|
|
154
155
|
result = {
|
|
155
156
|
...(parsed.title ? { title: parsed.title } : {}),
|
|
156
157
|
summaryMarkdown: parsed.summaryMarkdown,
|
|
@@ -206,6 +206,21 @@ async function withConfigLock(storageFile, operation) {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
async function renameWithRetry(source, target) {
|
|
210
|
+
let lastError;
|
|
211
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
212
|
+
try {
|
|
213
|
+
await rename(source, target);
|
|
214
|
+
return;
|
|
215
|
+
} catch (error) {
|
|
216
|
+
lastError = error;
|
|
217
|
+
if (process.platform !== "win32" || !["EACCES", "EBUSY", "EPERM"].includes(error?.code)) throw error;
|
|
218
|
+
await delay(25 * (attempt + 1));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
throw lastError;
|
|
222
|
+
}
|
|
223
|
+
|
|
209
224
|
async function writePrivateAtomic(storageFile, value) {
|
|
210
225
|
await mkdir(path.dirname(storageFile), { recursive: true, mode: 0o700 });
|
|
211
226
|
const temporaryFile = path.join(path.dirname(storageFile), `.${path.basename(storageFile)}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`);
|
|
@@ -216,7 +231,7 @@ async function writePrivateAtomic(storageFile, value) {
|
|
|
216
231
|
await handle.sync();
|
|
217
232
|
await handle.close();
|
|
218
233
|
handle = undefined;
|
|
219
|
-
await
|
|
234
|
+
await renameWithRetry(temporaryFile, storageFile);
|
|
220
235
|
const persisted = await open(storageFile, "r+");
|
|
221
236
|
await persisted.chmod(0o600);
|
|
222
237
|
await persisted.close();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { lstat, realpath } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
|
|
5
6
|
export const SUBAGENT_LAUNCH_SLOTS_VERSION = 1;
|
|
@@ -252,7 +253,7 @@ export function validateSubagentLaunchSlotRoles(value, models = []) {
|
|
|
252
253
|
return normalizeSubagentLaunchSlotRoles(value);
|
|
253
254
|
}
|
|
254
255
|
|
|
255
|
-
export async function resolveSubagentLaunchSlotProjectKey(cwd) {
|
|
256
|
+
export async function resolveSubagentLaunchSlotProjectKey(cwd, { globalPiRoot = path.join(homedir(), ".pi") } = {}) {
|
|
256
257
|
const fallback = path.resolve(String(cwd || process.cwd()));
|
|
257
258
|
let current;
|
|
258
259
|
try {
|
|
@@ -261,11 +262,22 @@ export async function resolveSubagentLaunchSlotProjectKey(cwd) {
|
|
|
261
262
|
return fallback;
|
|
262
263
|
}
|
|
263
264
|
const canonicalCwd = current;
|
|
265
|
+
const pathKey = (value) => process.platform === "win32" ? path.normalize(value).toLowerCase() : path.normalize(value);
|
|
266
|
+
const globalPiRoots = new Set();
|
|
267
|
+
for (const candidate of [path.join(homedir(), ".pi"), globalPiRoot]) {
|
|
268
|
+
try {
|
|
269
|
+
globalPiRoots.add(pathKey(await realpath(candidate)));
|
|
270
|
+
} catch {
|
|
271
|
+
globalPiRoots.add(pathKey(path.resolve(candidate)));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
264
274
|
|
|
265
275
|
while (true) {
|
|
266
276
|
for (const marker of [".pi", ".git"]) {
|
|
277
|
+
const markerPath = path.join(current, marker);
|
|
278
|
+
if (marker === ".pi" && globalPiRoots.has(pathKey(markerPath))) continue;
|
|
267
279
|
try {
|
|
268
|
-
await lstat(
|
|
280
|
+
await lstat(markerPath);
|
|
269
281
|
return current;
|
|
270
282
|
} catch (error) {
|
|
271
283
|
if (error?.code !== "ENOENT") throw error;
|
package/lib/trust-boundaries.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ProjectTrustStore } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
1
3
|
export const TRUST_GUARD_TYPES = new Set([
|
|
2
4
|
"none",
|
|
3
5
|
"confirmation",
|
|
@@ -19,6 +21,9 @@ export const LOCALHOST_ONLY_POST_ROUTES = new Map([
|
|
|
19
21
|
["/api/restart", "Restart is only allowed from localhost"],
|
|
20
22
|
["/api/update", "Updating Pi from the Web UI is only allowed from localhost"],
|
|
21
23
|
["/api/component-update", "Component updates are only allowed from localhost"],
|
|
24
|
+
["/api/update/plan", "Creating update plans is only allowed from localhost"],
|
|
25
|
+
["/api/update/apply", "Applying updates is only allowed from localhost"],
|
|
26
|
+
["/api/update/rollback", "Rolling back updates is only allowed from localhost"],
|
|
22
27
|
["/api/shutdown", "Shutdown is only allowed from localhost"],
|
|
23
28
|
["/api/optional-feature-install", "Installing optional Web UI features is only allowed from localhost"],
|
|
24
29
|
["/api/skill-file", "Saving skill files is only allowed from localhost"],
|
|
@@ -28,6 +33,7 @@ export const LOCALHOST_ONLY_POST_ROUTES = new Map([
|
|
|
28
33
|
["/api/files/open-default", "Opening files in the default editor is only allowed from localhost"],
|
|
29
34
|
["/api/session-delete", "Deleting sessions is only allowed from localhost"],
|
|
30
35
|
["/api/auth-logout", "Removing stored provider credentials is only allowed from localhost"],
|
|
36
|
+
["/api/themes/custom", "Saving custom themes is only allowed from localhost"],
|
|
31
37
|
]);
|
|
32
38
|
|
|
33
39
|
export const REMOTE_SHELL_WARNING =
|
|
@@ -65,6 +71,16 @@ export function requireLocalhostRoute(req, pathname) {
|
|
|
65
71
|
if (message) requireLocalhost(req, message);
|
|
66
72
|
}
|
|
67
73
|
|
|
74
|
+
/** Uses the installed Pi trust store, including nearest-ancestor decisions. */
|
|
75
|
+
export function projectTrustDecision(cwd, agentDir) {
|
|
76
|
+
try {
|
|
77
|
+
return new ProjectTrustStore(agentDir).get(cwd) === true;
|
|
78
|
+
} catch {
|
|
79
|
+
// A malformed, unreadable, or lock-contended trust store must never grant access.
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
68
84
|
export function nativeParitySurfaces(matrix) {
|
|
69
85
|
return Array.isArray(matrix?.surfaces) ? matrix.surfaces : [];
|
|
70
86
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { terminateProcessTree } from "../process-tree.mjs";
|
|
3
|
+
import { failedTargetReceipt, reduceUpdateReceipts } from "./verify.mjs";
|
|
4
|
+
|
|
5
|
+
function boundedAppend(current, chunk, maxLength) {
|
|
6
|
+
const next = current + String(chunk || "");
|
|
7
|
+
return next.length <= maxLength ? next : next.slice(next.length - maxLength);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Spawn with argument arrays, terminate the whole tree on timeout, and await closure. */
|
|
11
|
+
export function executeCommand(command, args = [], {
|
|
12
|
+
cwd,
|
|
13
|
+
env,
|
|
14
|
+
timeoutMs = 120_000,
|
|
15
|
+
closeTimeoutMs = 10_000,
|
|
16
|
+
maxOutputLength = 16_000,
|
|
17
|
+
spawnImpl = spawn,
|
|
18
|
+
terminateTree = terminateProcessTree,
|
|
19
|
+
platform = process.platform,
|
|
20
|
+
} = {}) {
|
|
21
|
+
if (!command || !Array.isArray(args)) throw new TypeError("command and argument array are required");
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
const startedAt = Date.now();
|
|
24
|
+
let stdout = "";
|
|
25
|
+
let stderr = "";
|
|
26
|
+
let timedOut = false;
|
|
27
|
+
let settled = false;
|
|
28
|
+
let terminationError = "";
|
|
29
|
+
let closeTimer;
|
|
30
|
+
const child = spawnImpl(String(command), args.map(String), {
|
|
31
|
+
cwd,
|
|
32
|
+
env,
|
|
33
|
+
shell: false,
|
|
34
|
+
windowsHide: true,
|
|
35
|
+
detached: platform !== "win32",
|
|
36
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
child.stdout?.on("data", (chunk) => { stdout = boundedAppend(stdout, chunk, maxOutputLength); });
|
|
40
|
+
child.stderr?.on("data", (chunk) => { stderr = boundedAppend(stderr, chunk, maxOutputLength); });
|
|
41
|
+
|
|
42
|
+
const finish = (exitCode, signal, error = null, closureTimedOut = false) => {
|
|
43
|
+
if (settled) return;
|
|
44
|
+
settled = true;
|
|
45
|
+
clearTimeout(timeout);
|
|
46
|
+
clearTimeout(closeTimer);
|
|
47
|
+
resolve(Object.freeze({
|
|
48
|
+
command: String(command), args: Object.freeze(args.map(String)), exitCode,
|
|
49
|
+
signal: signal || null, timedOut, closureTimedOut,
|
|
50
|
+
stdout, stderr, error: error ? String(error.message || error) : terminationError,
|
|
51
|
+
durationMs: Date.now() - startedAt,
|
|
52
|
+
}));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
child.once("error", (error) => finish(null, null, error));
|
|
56
|
+
child.once("close", (code, signal) => finish(code, signal));
|
|
57
|
+
const timeout = setTimeout(() => {
|
|
58
|
+
timedOut = true;
|
|
59
|
+
try {
|
|
60
|
+
if (!terminateTree(child, "SIGKILL")) terminationError = "Process-tree termination could not be confirmed.";
|
|
61
|
+
} catch (error) {
|
|
62
|
+
terminationError = String(error?.message || error);
|
|
63
|
+
}
|
|
64
|
+
closeTimer = setTimeout(() => {
|
|
65
|
+
try { child.kill?.("SIGKILL"); } catch {}
|
|
66
|
+
finish(null, "SIGKILL", null, true);
|
|
67
|
+
}, Math.max(100, closeTimeoutMs));
|
|
68
|
+
closeTimer.unref?.();
|
|
69
|
+
}, Math.max(1, timeoutMs));
|
|
70
|
+
timeout.unref?.();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Execute immutable plan targets in order through an injectable runner seam. */
|
|
75
|
+
export async function executePlanTargets(plan, {
|
|
76
|
+
runner = executeCommand,
|
|
77
|
+
verifyTarget,
|
|
78
|
+
beforeTarget,
|
|
79
|
+
stopOnFailure = false,
|
|
80
|
+
} = {}) {
|
|
81
|
+
if (typeof verifyTarget !== "function") throw new TypeError("verifyTarget is required");
|
|
82
|
+
const receipts = [];
|
|
83
|
+
for (const target of plan?.targets || []) {
|
|
84
|
+
try {
|
|
85
|
+
if (beforeTarget) await beforeTarget(target);
|
|
86
|
+
const commandResult = await runner(target.command.command, target.command.args, { target });
|
|
87
|
+
if (commandResult.exitCode !== 0 || commandResult.timedOut || commandResult.error) {
|
|
88
|
+
receipts.push(failedTargetReceipt(target, commandResult.timedOut ? "Update command timed out." : "Update command failed.", { command: commandResult }));
|
|
89
|
+
if (stopOnFailure) break;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
receipts.push(await verifyTarget(target, commandResult));
|
|
93
|
+
} catch (error) {
|
|
94
|
+
receipts.push(failedTargetReceipt(target, String(error?.message || error)));
|
|
95
|
+
if (stopOnFailure) break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return reduceUpdateReceipts(receipts);
|
|
99
|
+
}
|