@firstpick/pi-package-webui 0.8.6 → 0.8.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 +18 -606
- package/bin/pi-webui-launcher.mjs +22 -0
- package/bin/pi-webui-update-supervisor.mjs +86 -0
- package/bin/pi-webui.mjs +562 -524
- package/index.ts +8 -5
- package/lib/component-update-state.mjs +21 -0
- package/lib/git-workflow-preferences.mjs +17 -2
- package/lib/optional-feature-catalog.mjs +1 -0
- package/lib/sampling-parameter-capabilities.mjs +160 -0
- package/lib/session-summary-preferences.mjs +16 -1
- package/lib/subagent-launch-slots.mjs +14 -2
- package/lib/trust-boundaries.mjs +3 -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/package.json +4 -4
- package/public/app.js +1543 -109
- package/public/index.html +146 -48
- package/public/middle-button-drag-scroll.mjs +154 -0
- package/public/sampling-parameter-controls.mjs +361 -0
- package/public/service-worker.js +3 -1
- package/public/styles.css +512 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-deck-component-updates.spec.mjs +20 -22
- 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/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 +1 -1
- 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 +68 -1
- 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/http-endpoints-harness.test.mjs +68 -18
- 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 +4 -4
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +217 -24
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +13 -5
- package/tests/persistent-ui-layout-static.test.mjs +13 -2
- package/tests/prompt-routing-tab-status.test.mjs +8 -0
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +34 -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 +24 -11
- 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/subagent-launch-slots.test.mjs +18 -1
- package/tests/theme-customizer-static.test.mjs +1 -1
- 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/webui-rpc-helper.mjs +119 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveCanonicalPiRuntime, resolveWebuiRuntimeIdentity, sameRuntimeIdentity } from "../lib/update/resolver.mjs";
|
|
4
|
+
|
|
5
|
+
const bundledCli = "C:\\Agent\\npm\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js";
|
|
6
|
+
const pathDir = "C:\\PathPi";
|
|
7
|
+
const pathCli = `${pathDir}\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js`;
|
|
8
|
+
const explicitDir = "C:\\ExplicitPi";
|
|
9
|
+
const explicitShim = `${explicitDir}\\pi.cmd`;
|
|
10
|
+
const explicitCli = `${explicitDir}\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js`;
|
|
11
|
+
const existing = new Set([bundledCli, `${pathDir}\\pi.CMD`, pathCli, explicitShim, explicitCli, `${pathDir}\\node.exe`, `${explicitDir}\\node.exe`, "C:\\Node\\node.exe"]);
|
|
12
|
+
const runtime = {
|
|
13
|
+
platform: "win32",
|
|
14
|
+
execPath: "C:\\Node\\node.exe",
|
|
15
|
+
env: { PATH: pathDir, PATHEXT: ".EXE;.CMD" },
|
|
16
|
+
existsSync: (candidate) => existing.has(path.win32.normalize(candidate)),
|
|
17
|
+
realpathSync: (candidate) => path.win32.normalize(candidate),
|
|
18
|
+
};
|
|
19
|
+
const calls = [];
|
|
20
|
+
async function runCommand(command, args, options) {
|
|
21
|
+
calls.push({ command, args, options });
|
|
22
|
+
const cli = args[0];
|
|
23
|
+
if (cli === bundledCli) return { exitCode: 0, stdout: "pi 1.2.3", stderr: "" };
|
|
24
|
+
if (path.win32.normalize(cli || "") === path.win32.normalize(pathCli)) return { exitCode: 0, stdout: "9.9.9", stderr: "" };
|
|
25
|
+
if (path.win32.normalize(cli || "") === path.win32.normalize(explicitCli)) return { exitCode: 0, stdout: "v2.4.6", stderr: "" };
|
|
26
|
+
return { exitCode: 1, stdout: "", stderr: "missing" };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const selected = await resolveCanonicalPiRuntime({ bundledCli, runCommand, runtime });
|
|
30
|
+
assert.equal(selected.active.source, "bundled");
|
|
31
|
+
assert.equal(selected.active.version, "1.2.3");
|
|
32
|
+
assert.equal(selected.path.source, "path");
|
|
33
|
+
assert.equal(selected.path.version, "9.9.9");
|
|
34
|
+
assert.notEqual(selected.active.canonicalId, selected.path.canonicalId, "a newer PATH Pi must remain separately reported and untouched");
|
|
35
|
+
assert.deepEqual(selected.active.invocation.args, [bundledCli], "JavaScript launchers preserve argument arrays through Node normalization");
|
|
36
|
+
|
|
37
|
+
const explicit = await resolveCanonicalPiRuntime({ explicitCommand: explicitShim, bundledCli, runCommand, runtime });
|
|
38
|
+
assert.equal(explicit.active.source, "explicit");
|
|
39
|
+
assert.equal(explicit.active.cliPath, explicitCli);
|
|
40
|
+
assert.deepEqual(explicit.active.invocation.args, [explicitCli], "Windows explicit shims normalize to their exact installation CLI");
|
|
41
|
+
assert.equal(explicit.path, null, "explicit identity does not silently consult PATH");
|
|
42
|
+
|
|
43
|
+
const opaque = await resolveCanonicalPiRuntime({ explicitCommand: "opaque-custom-pi", runCommand, runtime });
|
|
44
|
+
assert.equal(opaque.active, null);
|
|
45
|
+
assert.equal(opaque.refusal.code, "explicit-pi-unresolved");
|
|
46
|
+
|
|
47
|
+
const unsupported = await resolveCanonicalPiRuntime({ bundledCli: "C:\\Missing\\cli.js", pathCommand: "missing-pi", runCommand, runtime });
|
|
48
|
+
assert.equal(unsupported.active, null);
|
|
49
|
+
assert.equal(unsupported.refusal.code, "pi-runtime-unverifiable");
|
|
50
|
+
|
|
51
|
+
const webui = resolveWebuiRuntimeIdentity({ packageRoot: "C:\\Agent\\npm\\node_modules\\@firstpick\\pi-package-webui", packageName: "@firstpick/pi-package-webui", version: "v0.8.6" }, runtime);
|
|
52
|
+
assert.equal(webui.version, "0.8.6");
|
|
53
|
+
assert.equal(sameRuntimeIdentity(webui, { canonicalId: webui.canonicalId }), true);
|
|
54
|
+
assert.ok(calls.every((call) => Array.isArray(call.args)));
|
|
55
|
+
assert.ok(calls.every((call) => call.options?.timeoutMs === 10_000), "runtime probes should use the fail-closed ten-second budget by default");
|
|
56
|
+
console.log("update-resolver.test.mjs passed");
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
listenWithRetry,
|
|
8
|
+
managedRuntimePaths,
|
|
9
|
+
probeCandidateRuntime,
|
|
10
|
+
readRuntimePointer,
|
|
11
|
+
rollbackRuntimePointer,
|
|
12
|
+
switchRuntimePointer,
|
|
13
|
+
writeRuntimePointer,
|
|
14
|
+
} from "../lib/update/supervisor.mjs";
|
|
15
|
+
|
|
16
|
+
const root = await mkdtemp(path.join(tmpdir(), "pi-webui-supervisor-"));
|
|
17
|
+
try {
|
|
18
|
+
const paths = managedRuntimePaths(root);
|
|
19
|
+
const makeRuntime = async (name, version) => {
|
|
20
|
+
const runtimeRoot = path.join(paths.runtimesDir, name);
|
|
21
|
+
const serverEntry = path.join(runtimeRoot, "bin", "pi-webui.mjs");
|
|
22
|
+
await mkdir(path.dirname(serverEntry), { recursive: true });
|
|
23
|
+
await writeFile(serverEntry, `if (process.argv[2] === "--candidate-probe") console.log(JSON.stringify({ok:true,version:${JSON.stringify(version)},piVersion:"9.9.9"}));\n`, "utf8");
|
|
24
|
+
return { runtimeRoot, serverEntry, version };
|
|
25
|
+
};
|
|
26
|
+
const first = await makeRuntime("first", "1.0.0");
|
|
27
|
+
const second = await makeRuntime("second", "2.0.0");
|
|
28
|
+
await switchRuntimePointer(root, first);
|
|
29
|
+
assert.equal((await readRuntimePointer(root, "current")).version, "1.0.0");
|
|
30
|
+
const bootstrapRollback = await rollbackRuntimePointer(root);
|
|
31
|
+
assert.equal(bootstrapRollback.bootstrapFallback, true, "the first failed managed activation must fall back to the installed bootstrap");
|
|
32
|
+
assert.equal(await readRuntimePointer(root, "current"), null);
|
|
33
|
+
await switchRuntimePointer(root, first);
|
|
34
|
+
await switchRuntimePointer(root, second);
|
|
35
|
+
assert.equal((await readRuntimePointer(root, "current")).version, "2.0.0");
|
|
36
|
+
assert.equal((await readRuntimePointer(root, "previous")).version, "1.0.0");
|
|
37
|
+
await rollbackRuntimePointer(root);
|
|
38
|
+
assert.equal((await readRuntimePointer(root, "current")).version, "1.0.0");
|
|
39
|
+
await assert.rejects(() => writeRuntimePointer(root, "current", { runtimeRoot: path.join(root, "escape"), serverEntry: path.join(root, "escape", "server.mjs"), version: "3.0.0" }), /escapes/);
|
|
40
|
+
const probe = await probeCandidateRuntime(second.serverEntry, { expectedVersion: "2.0.0", expectedPiVersion: "9.9.9" });
|
|
41
|
+
assert.equal(probe.ok, true);
|
|
42
|
+
assert.equal((await probeCandidateRuntime(second.serverEntry, { expectedVersion: "2.0.0", expectedPiVersion: "8.8.8" })).ok, false);
|
|
43
|
+
const wrongProbe = await probeCandidateRuntime(second.serverEntry, { expectedVersion: "9.0.0" });
|
|
44
|
+
assert.equal(wrongProbe.ok, false);
|
|
45
|
+
|
|
46
|
+
const occupied = createServer();
|
|
47
|
+
await new Promise((resolve) => occupied.listen(0, "127.0.0.1", resolve));
|
|
48
|
+
const port = occupied.address().port;
|
|
49
|
+
const replacement = createServer((_req, res) => res.end("ok"));
|
|
50
|
+
setTimeout(() => occupied.close(), 180);
|
|
51
|
+
const attempt = await listenWithRetry(replacement, { port, host: "127.0.0.1", attempts: 6, initialDelayMs: 50 });
|
|
52
|
+
assert.ok(attempt > 1, "EADDRINUSE startup should retry with bounded backoff");
|
|
53
|
+
await new Promise((resolve) => replacement.close(resolve));
|
|
54
|
+
} finally {
|
|
55
|
+
await rm(root, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
console.log("update supervisor harness passed");
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { access, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { createRestoreFile, readRestoreFileOnce } from "../lib/update/supervisor.mjs";
|
|
6
|
+
|
|
7
|
+
const root = await mkdtemp(path.join(tmpdir(), "pi-webui-restore-"));
|
|
8
|
+
try {
|
|
9
|
+
const tabs = Array.from({ length: 130 }, (_, index) => ({ id: `tab-${index + 1}`, index: index + 1, title: `Tab ${index + 1}`, cwd: root, sessionFile: path.join(root, `${index + 1}.jsonl`) }));
|
|
10
|
+
const handoff = await createRestoreFile(root, tabs);
|
|
11
|
+
assert.equal(handoff.count, 130, "private restore handoff must support at least 125 tabs");
|
|
12
|
+
const restored = await readRestoreFileOnce(handoff.file, root);
|
|
13
|
+
assert.equal(restored.length, 130);
|
|
14
|
+
assert.equal(restored[124].id, "tab-125");
|
|
15
|
+
await assert.rejects(() => access(handoff.file), /ENOENT/, "restore handoff must be deleted after its first read");
|
|
16
|
+
|
|
17
|
+
const outside = path.join(root, "outside.json");
|
|
18
|
+
await writeFile(outside, JSON.stringify({ schemaVersion: 1, tabs: [] }));
|
|
19
|
+
await assert.rejects(() => readRestoreFileOnce(outside, root), /outside the private temp root/);
|
|
20
|
+
await access(outside);
|
|
21
|
+
} finally {
|
|
22
|
+
await rm(root, { recursive: true, force: true });
|
|
23
|
+
}
|
|
24
|
+
console.log("update tab restore harness passed");
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { failedTargetReceipt, reduceUpdateReceipts, rolledBackTargetReceipt, verifyTargetResult } from "../lib/update/verify.mjs";
|
|
3
|
+
|
|
4
|
+
const pi = { id: "pi", kind: "pi", currentVersion: "1.0.0", targetVersion: "2.0.0" };
|
|
5
|
+
const webui = { id: "webui", kind: "webui", currentVersion: "0.8.6", targetVersion: "0.9.0" };
|
|
6
|
+
const identity = { canonicalId: "pi:/active/cli.js" };
|
|
7
|
+
for (const target of [pi, webui]) {
|
|
8
|
+
const unchanged = verifyTargetResult(target, { beforeIdentity: identity, afterIdentity: identity, afterVersion: target.currentVersion });
|
|
9
|
+
assert.equal(unchanged.status, "failed");
|
|
10
|
+
assert.match(unchanged.message, /without changing/i, `${target.kind} exit-zero/no-change must fail`);
|
|
11
|
+
}
|
|
12
|
+
const wrong = verifyTargetResult(pi, { beforeIdentity: identity, afterIdentity: identity, afterVersion: "1.5.0" });
|
|
13
|
+
assert.equal(wrong.status, "failed");
|
|
14
|
+
assert.match(wrong.message, /Expected exact version 2\.0\.0/);
|
|
15
|
+
const changedIdentity = verifyTargetResult(pi, { beforeIdentity: identity, afterIdentity: { canonicalId: "pi:/path/cli.js" }, afterVersion: "2.0.0" });
|
|
16
|
+
assert.equal(changedIdentity.status, "failed");
|
|
17
|
+
const success = verifyTargetResult(pi, { beforeIdentity: identity, afterIdentity: identity, afterVersion: "2.0.0" });
|
|
18
|
+
assert.equal(success.status, "success");
|
|
19
|
+
|
|
20
|
+
const partial = reduceUpdateReceipts([success, failedTargetReceipt(webui, "fixture failure")]);
|
|
21
|
+
assert.equal(partial.outcome, "partial");
|
|
22
|
+
assert.deepEqual(partial.receipts.map((item) => item.targetId), ["pi", "webui"], "partial receipts retain target order");
|
|
23
|
+
assert.deepEqual(partial.counts, { success: 1, failed: 1, rolledBack: 0 });
|
|
24
|
+
const optional = { id: "optional:statsCommand", kind: "optional", currentVersion: "1.0.0", targetVersion: "2.0.0" };
|
|
25
|
+
const webuiSuccess = verifyTargetResult(webui, { beforeIdentity: { canonicalId: "webui:/active" }, afterIdentity: { canonicalId: "webui:/active" }, afterVersion: "0.9.0" });
|
|
26
|
+
const optionalPartial = reduceUpdateReceipts([webuiSuccess, failedTargetReceipt(optional, "fixture optional-package failure")]);
|
|
27
|
+
assert.equal(optionalPartial.outcome, "partial", "a verified WebUI target plus a failed Pi-owned optional package must remain partial");
|
|
28
|
+
assert.deepEqual(optionalPartial.receipts.map((item) => item.targetId), ["webui", "optional:statsCommand"]);
|
|
29
|
+
assert.equal(reduceUpdateReceipts([failedTargetReceipt(pi, "failed")]).outcome, "failed");
|
|
30
|
+
assert.equal(reduceUpdateReceipts([rolledBackTargetReceipt(webui, "restored")]).outcome, "rolled-back");
|
|
31
|
+
console.log("update-verify.test.mjs passed");
|
|
@@ -52,25 +52,34 @@ assert.match(shutdown, /workspaceFilesLiveWatcher\.closeAll\(\)/, "server shutdo
|
|
|
52
52
|
|
|
53
53
|
// WS2 client-side contract assertions.
|
|
54
54
|
const handleEvent = functionBody(app, "handleEvent");
|
|
55
|
+
const renderSignature = functionBody(app, "fileTreeRenderSignature");
|
|
56
|
+
const renderTree = functionBody(app, "renderFileTree");
|
|
55
57
|
const loadDirectory = functionBody(app, "loadFileTreeDirectory");
|
|
58
|
+
const searchFiles = functionBody(app, "runFileTreeSearch");
|
|
56
59
|
const liveRefresh = functionBody(app, "refreshFileTreeLive");
|
|
57
60
|
const liveDirectories = functionBody(app, "refreshLoadedFileTreeDirectories");
|
|
58
61
|
|
|
59
62
|
assert.match(handleEvent, /case "webui_workspace_files_changed":\s*if \(event\.tabId && event\.tabId !== activeTabId\) break;\s*refreshFileTreeLive\(tabContext\)\.catch/, "workspace file changes should refresh only the matching active tab");
|
|
60
|
-
assert.match(
|
|
63
|
+
assert.match(renderSignature, /entriesByPath[\s\S]*fileTreeEntryRenderSignature[\s\S]*gitStatusByPath[\s\S]*selectedPath[\s\S]*searchEntries/, "file tree render identity should cover every state value that changes visible rows");
|
|
64
|
+
assert.doesNotMatch(renderSignature, /mtimeMs|size/, "content-only file metadata must not invalidate the visible file tree");
|
|
65
|
+
assert.match(renderTree, /const renderSignature = fileTreeRenderSignature\(\);\s*if \(renderSignature === fileTreeLastRenderSignature\) return;\s*fileTreeLastRenderSignature = renderSignature;[\s\S]*root\.replaceChildren\(\)/, "unchanged live snapshots should preserve the existing file-tree DOM");
|
|
66
|
+
assert.match(loadDirectory, /const hadCachedEntries = fileTreeState\.entriesByPath\.has\(normalized\);[\s\S]*?if \(!hadCachedEntries\) \{\s*setFileTreeStatus\(normalized \? `Loading \$\{normalized\}…` : "Loading workspace files…"\);\s*renderFileTree\(\);\s*\}/, "cached directories should preserve their rows without rendering transient loading state");
|
|
67
|
+
assert.match(loadDirectory, /renderResult && isCurrentTabContext\(tabContext\)/, "batched live refreshes should be able to defer rendering until all cached directories are updated");
|
|
61
68
|
assert.match(loadDirectory, /fileTreeState\.entriesByPath\.set\(normalized, entries\);\s*if \(!normalized \|\| !hadCachedEntries\) \{\s*setFileTreeStatus\(fileTreeEntriesStatus\(entries,/, "root refreshes should publish the updated item count while cached child refreshes leave it stable");
|
|
69
|
+
assert.match(searchFiles, /if \(!background\) \{[\s\S]*fileTreeState\.searchEntries = \[\][\s\S]*renderFileTree\(\)/, "background search refreshes should preserve current results while the request is in flight");
|
|
62
70
|
|
|
63
|
-
assert.match(liveRefresh, /fileTreeSearchQueryText\(\)[\s\S]*?await runFileTreeSearch\(\)[\s\S]*?await refreshLoadedFileTreeDirectories\(refreshContext\)/, "live refresh should
|
|
71
|
+
assert.match(liveRefresh, /fileTreeSearchQueryText\(\)[\s\S]*?await runFileTreeSearch\(\{ background: true \}\)[\s\S]*?await refreshLoadedFileTreeDirectories\(refreshContext\)/, "live refresh should update an active search in the background or refresh loaded directories");
|
|
64
72
|
assert.match(liveRefresh, /if \(fileTreeLiveRefreshInProgress\) \{\s*fileTreeLiveRefreshPendingContext = tabContext;\s*return;\s*\}/, "events arriving during a refresh should retain the pending tab context");
|
|
65
73
|
assert.match(liveRefresh, /refreshContext = fileTreeLiveRefreshPendingContext/, "a queued follow-up pass should replay the latest matching tab context");
|
|
66
74
|
assert.match(liveRefresh, /pendingContext && isCurrentTabContext\(pendingContext\)[\s\S]*?retryContext && isCurrentTabContext\(retryContext\)/, "completion should prefer a pending current-tab event over a same-tab loading retry");
|
|
67
75
|
assert.match(liveRefresh, /fileTreeLiveRefreshRetryTimer = setTimeout\([\s\S]*?refreshFileTreeLive\(nextContext\)/, "loading collisions should schedule a bounded follow-up refresh");
|
|
68
76
|
|
|
69
|
-
assert.match(liveDirectories, /if \(fileTreeState\.loading\.has\(FILE_TREE_ROOT_PATH\)\) return true;\s*await loadFileTreeDirectory\(FILE_TREE_ROOT_PATH, \{ force: true \}\);[\s\S]*?collectDirectories\(FILE_TREE_ROOT_PATH\);[\s\S]*?for \(const path of cachedDirectories\)/, "the root directory should reload first, or request a retry when it is already loading");
|
|
77
|
+
assert.match(liveDirectories, /if \(fileTreeState\.loading\.has\(FILE_TREE_ROOT_PATH\)\) return true;\s*await loadFileTreeDirectory\(FILE_TREE_ROOT_PATH, \{ force: true, renderResult: false \}\);[\s\S]*?collectDirectories\(FILE_TREE_ROOT_PATH\);[\s\S]*?for \(const path of cachedDirectories\)/, "the root directory should reload first without an intermediate render, or request a retry when it is already loading");
|
|
70
78
|
assert.match(liveDirectories, /\.sort\(\(a, b\) => a\.split\("\/"\)\.length - b\.split\("\/"\)\.length/, "loaded directories should refresh shallow-to-deep");
|
|
71
79
|
assert.match(liveDirectories, /if \(!knownDirectories\.has\(path\)\) \{\s*clearFileTreeEntryCache\(path\);\s*continue;\s*\}/, "directories missing after reload should be pruned from caches and expansion");
|
|
72
80
|
assert.match(liveDirectories, /if \(fileTreeState\.loading\.has\(path\)\) \{\s*skippedLoadingDirectory = true;\s*collectDirectories\(path\);\s*continue;\s*\}/, "already-loading directories should be preserved for a follow-up retry instead of being silently skipped or pruned");
|
|
73
|
-
assert.match(liveDirectories, /await loadFileTreeDirectory\(path, \{ force: true \}\);[\s\S]*?collectDirectories\(path\)/, "only directories still present should be reloaded and kept");
|
|
81
|
+
assert.match(liveDirectories, /await loadFileTreeDirectory\(path, \{ force: true, renderResult: false \}\);[\s\S]*?collectDirectories\(path\)/, "only directories still present should be reloaded and kept without intermediate renders");
|
|
82
|
+
assert.match(liveDirectories, /for \(const path of cachedDirectories\)[\s\S]*renderFileTree\(\);\s*return skippedLoadingDirectory;/, "one live refresh pass should commit at most one batched tree render");
|
|
74
83
|
assert.ok(!liveRefresh.includes("expanded.clear()") && !liveDirectories.includes("expanded.clear()"), "live refresh should preserve still-valid expanded directories");
|
|
75
84
|
|
|
76
85
|
console.log("workspace-files-live-updates-static.test.mjs passed");
|
package/webui-rpc-helper.mjs
CHANGED
|
@@ -9,11 +9,24 @@ import {
|
|
|
9
9
|
subagentLaunchSlotScopeEntry,
|
|
10
10
|
} from "./lib/subagent-launch-slots.mjs";
|
|
11
11
|
import { SUBAGENT_GATE_UPDATE_EVENT } from "./lib/subagent-gate.mjs";
|
|
12
|
+
import {
|
|
13
|
+
applySupportedSamplingParameters,
|
|
14
|
+
BUILTIN_SAMPLING_APIS,
|
|
15
|
+
filterSupportedSamplingParameters,
|
|
16
|
+
resolveSamplingParameterCapabilities,
|
|
17
|
+
} from "./lib/sampling-parameter-capabilities.mjs";
|
|
18
|
+
import {
|
|
19
|
+
SamplingParameterValidationError,
|
|
20
|
+
validateSamplingParameterObject,
|
|
21
|
+
} from "./public/sampling-parameter-controls.mjs";
|
|
12
22
|
|
|
13
23
|
const HELPER_COMMAND = "webui-helper";
|
|
14
24
|
const RESPONSE_PREFIX = "__PI_WEBUI_HELPER_RESPONSE__:";
|
|
15
25
|
const TOOLS_CONFIG_TYPE = "webui-tools-config";
|
|
16
26
|
const SKILLS_CONFIG_TYPE = "webui-skills-config";
|
|
27
|
+
const SAMPLING_CONFIG_TYPE = "webui-session-sampling-params-v1";
|
|
28
|
+
const SAMPLING_MAX_KEYS = 128;
|
|
29
|
+
const SAMPLING_MAX_BYTES = 16 * 1024;
|
|
17
30
|
const APP_RUNNER_CONTEXT_TYPE = "webui-app-runner-output";
|
|
18
31
|
const RETAINED_SUBAGENT_RUNS_TYPE = "webui-subagent-retained-runs-v1";
|
|
19
32
|
const WEBUI_SUBAGENTS_STATUS_KEY = "webui-subagents";
|
|
@@ -135,6 +148,30 @@ function lastBranchConfig(ctx, customType) {
|
|
|
135
148
|
return found;
|
|
136
149
|
}
|
|
137
150
|
|
|
151
|
+
function isPlainObject(value) {
|
|
152
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
153
|
+
const prototype = Object.getPrototypeOf(value);
|
|
154
|
+
return prototype === Object.prototype || prototype === null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function normalizeSamplingParams(value) {
|
|
158
|
+
if (!isPlainObject(value)) throw new Error("Sampling parameters must be a JSON object");
|
|
159
|
+
const keys = Object.keys(value);
|
|
160
|
+
if (keys.length > SAMPLING_MAX_KEYS) throw new Error(`Sampling parameters may contain at most ${SAMPLING_MAX_KEYS} top-level keys`);
|
|
161
|
+
let serialized;
|
|
162
|
+
try {
|
|
163
|
+
serialized = JSON.stringify(value);
|
|
164
|
+
} catch {
|
|
165
|
+
throw new Error("Sampling parameters must contain only JSON-compatible values");
|
|
166
|
+
}
|
|
167
|
+
if (Buffer.byteLength(serialized, "utf8") > SAMPLING_MAX_BYTES) {
|
|
168
|
+
throw new Error(`Sampling parameters must be at most ${SAMPLING_MAX_BYTES} bytes`);
|
|
169
|
+
}
|
|
170
|
+
const normalized = JSON.parse(serialized);
|
|
171
|
+
if (!isPlainObject(normalized)) throw new Error("Sampling parameters must be a JSON object");
|
|
172
|
+
return normalized;
|
|
173
|
+
}
|
|
174
|
+
|
|
138
175
|
function normalizeNameList(value) {
|
|
139
176
|
if (!Array.isArray(value)) return [];
|
|
140
177
|
const names = [];
|
|
@@ -797,6 +834,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
797
834
|
let enabledTools = new Set();
|
|
798
835
|
let disabledSkills = new Set();
|
|
799
836
|
let inheritedEnabledSkills = null;
|
|
837
|
+
let sessionSamplingParams = {};
|
|
800
838
|
let subagentLaunchSlotGuidance = "";
|
|
801
839
|
let subagentContext = null;
|
|
802
840
|
let subagentBridgeAvailable = false;
|
|
@@ -1408,6 +1446,72 @@ export default function webuiRpcHelper(pi) {
|
|
|
1408
1446
|
return pi.getAllTools().map((tool) => tool.name);
|
|
1409
1447
|
}
|
|
1410
1448
|
|
|
1449
|
+
function restoreSamplingParamsFromBranch(ctx) {
|
|
1450
|
+
const saved = lastBranchConfig(ctx, SAMPLING_CONFIG_TYPE);
|
|
1451
|
+
try {
|
|
1452
|
+
sessionSamplingParams = saved?.version === 1 ? normalizeSamplingParams(saved.samplingParams) : {};
|
|
1453
|
+
} catch {
|
|
1454
|
+
sessionSamplingParams = {};
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
function persistSamplingParams() {
|
|
1459
|
+
pi.appendEntry(SAMPLING_CONFIG_TYPE, { version: 1, samplingParams: sessionSamplingParams });
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
function samplingState(ctx) {
|
|
1463
|
+
const model = ctx.model;
|
|
1464
|
+
const api = typeof model?.api === "string" ? model.api : null;
|
|
1465
|
+
const parameters = resolveSamplingParameterCapabilities(model, { thinkingLevel: ctx.thinkingLevel });
|
|
1466
|
+
const supported = Object.values(parameters).some((capability) => capability.supported);
|
|
1467
|
+
const defaults = isPlainObject(model?.samplingParams) ? { ...model.samplingParams } : {};
|
|
1468
|
+
const session = { ...sessionSamplingParams };
|
|
1469
|
+
return {
|
|
1470
|
+
session,
|
|
1471
|
+
defaults,
|
|
1472
|
+
effective: {
|
|
1473
|
+
...filterSupportedSamplingParameters(defaults, parameters),
|
|
1474
|
+
...filterSupportedSamplingParameters(session, parameters),
|
|
1475
|
+
},
|
|
1476
|
+
support: {
|
|
1477
|
+
supported,
|
|
1478
|
+
api,
|
|
1479
|
+
model: model ? {
|
|
1480
|
+
provider: typeof model.provider === "string" ? model.provider : null,
|
|
1481
|
+
id: typeof model.id === "string" ? model.id : null,
|
|
1482
|
+
name: typeof model.name === "string" ? model.name : null,
|
|
1483
|
+
} : null,
|
|
1484
|
+
parameters,
|
|
1485
|
+
compatibleApis: [...BUILTIN_SAMPLING_APIS],
|
|
1486
|
+
message: supported
|
|
1487
|
+
? "Session sampling parameters apply to subsequent provider requests."
|
|
1488
|
+
: api
|
|
1489
|
+
? `Session sampling parameters are stored but not applied to ${api}.`
|
|
1490
|
+
: "Session sampling parameters are stored but no active model is available.",
|
|
1491
|
+
},
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
function setSamplingParams(ctx, payload) {
|
|
1496
|
+
const normalized = normalizeSamplingParams(payload?.samplingParams);
|
|
1497
|
+
const validation = validateSamplingParameterObject(normalized);
|
|
1498
|
+
if (!validation.valid) {
|
|
1499
|
+
throw new SamplingParameterValidationError(
|
|
1500
|
+
`Invalid sampling parameters: ${Object.values(validation.errors).join(" ")}`,
|
|
1501
|
+
validation.errors,
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
sessionSamplingParams = normalized;
|
|
1505
|
+
persistSamplingParams();
|
|
1506
|
+
return samplingState(ctx);
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
function resetSamplingParams(ctx) {
|
|
1510
|
+
sessionSamplingParams = {};
|
|
1511
|
+
persistSamplingParams();
|
|
1512
|
+
return samplingState(ctx);
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1411
1515
|
async function readGlobalResourceDefaults() {
|
|
1412
1516
|
try {
|
|
1413
1517
|
return (await readWebuiSettings()).resourceDefaults;
|
|
@@ -1607,6 +1711,12 @@ export default function webuiRpcHelper(pi) {
|
|
|
1607
1711
|
return skillState(ctx);
|
|
1608
1712
|
case "skills-set":
|
|
1609
1713
|
return setSkillState(ctx, payload);
|
|
1714
|
+
case "sampling-state":
|
|
1715
|
+
return samplingState(ctx);
|
|
1716
|
+
case "sampling-set":
|
|
1717
|
+
return setSamplingParams(ctx, payload);
|
|
1718
|
+
case "sampling-reset":
|
|
1719
|
+
return resetSamplingParams(ctx);
|
|
1610
1720
|
case "app-runner-context":
|
|
1611
1721
|
return transferAppRunnerContext(ctx, payload);
|
|
1612
1722
|
case "subagent-output":
|
|
@@ -1643,6 +1753,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1643
1753
|
const globalDefaults = await readGlobalResourceDefaults();
|
|
1644
1754
|
restoreToolsFromBranch(ctx, globalDefaults);
|
|
1645
1755
|
restoreSkillsFromBranch(ctx, globalDefaults);
|
|
1756
|
+
restoreSamplingParamsFromBranch(ctx);
|
|
1646
1757
|
await loadSubagentLaunchSlotGuidance(ctx);
|
|
1647
1758
|
subagentContext = ctx;
|
|
1648
1759
|
subagentPollGeneration += 1;
|
|
@@ -1660,6 +1771,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
1660
1771
|
const globalDefaults = await readGlobalResourceDefaults();
|
|
1661
1772
|
restoreToolsFromBranch(ctx, globalDefaults);
|
|
1662
1773
|
restoreSkillsFromBranch(ctx, globalDefaults);
|
|
1774
|
+
restoreSamplingParamsFromBranch(ctx);
|
|
1663
1775
|
subagentContext = ctx;
|
|
1664
1776
|
foregroundSubagentRuns.clear();
|
|
1665
1777
|
asyncSubagentRuns.clear();
|
|
@@ -1748,6 +1860,13 @@ export default function webuiRpcHelper(pi) {
|
|
|
1748
1860
|
for (const unsubscribe of subagentEventUnsubscribers) unsubscribe();
|
|
1749
1861
|
});
|
|
1750
1862
|
|
|
1863
|
+
pi.on("before_provider_request", (event, ctx) => {
|
|
1864
|
+
if (Object.keys(sessionSamplingParams).length === 0) return undefined;
|
|
1865
|
+
return applySupportedSamplingParameters(event.payload, ctx.model, sessionSamplingParams, {
|
|
1866
|
+
thinkingLevel: ctx.thinkingLevel,
|
|
1867
|
+
});
|
|
1868
|
+
});
|
|
1869
|
+
|
|
1751
1870
|
pi.on("input", async (event, ctx) => {
|
|
1752
1871
|
const match = String(event.text || "").trim().match(/^\/skill:([^\s]+)/i);
|
|
1753
1872
|
if (!match) return { action: "continue" };
|