@firstpick/pi-package-webui 0.6.7 → 0.6.9
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 +14 -9
- package/bin/pi-webui.mjs +477 -157
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/auth-actions.mjs +30 -51
- package/lib/codex-usage-auth.mjs +61 -0
- package/lib/git-command-errors.mjs +68 -0
- package/lib/git-workflow-preferences.mjs +34 -1
- package/lib/native-export-payload.mjs +13 -0
- package/lib/npm-command.mjs +105 -0
- package/lib/process-tree.mjs +53 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/package.json +8 -8
- package/public/app.js +1864 -238
- package/public/index.html +217 -102
- package/public/service-worker.js +1 -1
- package/public/styles.css +1144 -209
- package/tests/app-runner-process-tree-harness.test.mjs +162 -0
- package/tests/codex-usage-auth.test.mjs +65 -0
- package/tests/fixtures/fake-pi.mjs +77 -3
- package/tests/git-command-errors.test.mjs +42 -0
- package/tests/git-workflow-preferences.test.mjs +14 -2
- package/tests/http-endpoints-harness.test.mjs +240 -3
- package/tests/mobile-static.test.mjs +138 -27
- package/tests/native-export-payload.test.mjs +26 -0
- package/tests/native-parity-harness.test.mjs +1 -1
- package/tests/native-parity.test.mjs +11 -2
- package/tests/npm-command.test.mjs +64 -0
- package/tests/remote-auth-settings-harness.test.mjs +33 -1
- package/tests/resource-defaults-helper.test.mjs +126 -0
- package/tests/session-auth-harness.test.mjs +2 -2
- package/webui-rpc-helper.mjs +47 -16
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveNpmCommandInvocation } from "../lib/npm-command.mjs";
|
|
4
|
+
|
|
5
|
+
const windowsExecPath = "C:\\PortableNode\\node.exe";
|
|
6
|
+
const bundledCli = "C:\\PortableNode\\node_modules\\npm\\bin\\npm-cli.js";
|
|
7
|
+
const requestedArgs = ["install", "--prefix", "C:\\Pi Packages", "@firstpick/example@latest"];
|
|
8
|
+
|
|
9
|
+
const bundled = resolveNpmCommandInvocation(requestedArgs, {
|
|
10
|
+
platform: "win32",
|
|
11
|
+
execPath: windowsExecPath,
|
|
12
|
+
env: { PATH: "C:\\Windows\\System32;C:\\PortableNode" },
|
|
13
|
+
existsSync: (candidate) => path.win32.normalize(candidate) === path.win32.normalize(bundledCli),
|
|
14
|
+
});
|
|
15
|
+
assert.equal(bundled.command, windowsExecPath, "Windows npm should run through the current Node executable");
|
|
16
|
+
assert.deepEqual(bundled.args, [bundledCli, ...requestedArgs], "Windows npm should prefix arguments with bundled npm-cli.js");
|
|
17
|
+
assert.equal(bundled.displayCommand, "npm", "automatic resolution should keep readable npm command output");
|
|
18
|
+
assert.equal(bundled.source, "node-cli");
|
|
19
|
+
|
|
20
|
+
const pathCli = "D:\\NodeOnPath\\node_modules\\npm\\bin\\npm-cli.js";
|
|
21
|
+
const fromPath = resolveNpmCommandInvocation(["root", "-g"], {
|
|
22
|
+
platform: "win32",
|
|
23
|
+
execPath: windowsExecPath,
|
|
24
|
+
env: { PATH: "C:\\Windows\\System32;D:\\NodeOnPath" },
|
|
25
|
+
existsSync: (candidate) => path.win32.normalize(candidate) === path.win32.normalize(pathCli),
|
|
26
|
+
});
|
|
27
|
+
assert.deepEqual(fromPath.args, [pathCli, "root", "-g"], "Windows resolution should find npm-cli.js beside an npm directory on PATH");
|
|
28
|
+
|
|
29
|
+
const configuredShim = "E:\\CustomNode\\npm.cmd";
|
|
30
|
+
const configuredCli = "E:\\CustomNode\\node_modules\\npm\\bin\\npm-cli.js";
|
|
31
|
+
const configured = resolveNpmCommandInvocation(["--version"], {
|
|
32
|
+
platform: "win32",
|
|
33
|
+
execPath: windowsExecPath,
|
|
34
|
+
env: { PI_WEBUI_NPM_BIN: configuredShim, PATH: "" },
|
|
35
|
+
existsSync: (candidate) => path.win32.normalize(candidate) === path.win32.normalize(configuredCli),
|
|
36
|
+
});
|
|
37
|
+
assert.equal(configured.command, windowsExecPath, "a configured npm.cmd shim should be normalized to its npm CLI");
|
|
38
|
+
assert.deepEqual(configured.args, [configuredCli, "--version"]);
|
|
39
|
+
assert.equal(configured.displayCommand, configuredShim);
|
|
40
|
+
|
|
41
|
+
const customExecutable = resolveNpmCommandInvocation(["install"], {
|
|
42
|
+
platform: "win32",
|
|
43
|
+
execPath: windowsExecPath,
|
|
44
|
+
env: { PI_WEBUI_NPM_BIN: "E:\\tools\\custom-npm.exe" },
|
|
45
|
+
existsSync: () => false,
|
|
46
|
+
});
|
|
47
|
+
assert.deepEqual(customExecutable, {
|
|
48
|
+
command: "E:\\tools\\custom-npm.exe",
|
|
49
|
+
args: ["install"],
|
|
50
|
+
displayCommand: "E:\\tools\\custom-npm.exe",
|
|
51
|
+
displayArgs: ["install"],
|
|
52
|
+
source: "configured-command",
|
|
53
|
+
}, "custom executable overrides should remain supported");
|
|
54
|
+
|
|
55
|
+
const fallback = resolveNpmCommandInvocation(["--version"], {
|
|
56
|
+
platform: "linux",
|
|
57
|
+
execPath: "/usr/bin/node",
|
|
58
|
+
env: { PATH: "/usr/bin" },
|
|
59
|
+
existsSync: () => false,
|
|
60
|
+
});
|
|
61
|
+
assert.equal(fallback.command, "npm", "non-bundled installations should retain PATH fallback behavior");
|
|
62
|
+
assert.deepEqual(fallback.args, ["--version"]);
|
|
63
|
+
|
|
64
|
+
console.log("npm command resolution tests passed");
|
|
@@ -13,6 +13,7 @@ const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
|
13
13
|
const port = 30000 + Math.floor(Math.random() * 20000);
|
|
14
14
|
const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-remote-auth-settings-"));
|
|
15
15
|
const settingsFile = path.join(cwd, "webui-settings.json");
|
|
16
|
+
const safetyGuardSettingsFile = path.join(cwd, "safety-guard.json");
|
|
16
17
|
|
|
17
18
|
async function request(pathname, { method = "GET", body, timeoutMs = 5_000 } = {}) {
|
|
18
19
|
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
|
|
@@ -33,6 +34,7 @@ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "12
|
|
|
33
34
|
env: {
|
|
34
35
|
...process.env,
|
|
35
36
|
PI_WEBUI_SETTINGS_FILE: settingsFile,
|
|
37
|
+
PI_SAFETY_GUARD_CONFIG_FILE: safetyGuardSettingsFile,
|
|
36
38
|
},
|
|
37
39
|
});
|
|
38
40
|
let serverOutput = "";
|
|
@@ -62,6 +64,36 @@ try {
|
|
|
62
64
|
assert.equal(startupAuth.body?.data?.auth?.enabled, true, "saved Remote PIN auth setting should enable auth at next startup");
|
|
63
65
|
assert.match(startupAuth.body?.data?.auth?.pin, /^\d{4}$/, "startup auth should generate a fresh PIN, not persist one");
|
|
64
66
|
|
|
67
|
+
const initialSafetyGuardSetup = await request("/api/safety-guard/config");
|
|
68
|
+
assert.equal(initialSafetyGuardSetup.status, 200);
|
|
69
|
+
assert.equal(initialSafetyGuardSetup.body?.data?.config?.enabled, true, "safety guard should default to enabled");
|
|
70
|
+
assert.deepEqual(initialSafetyGuardSetup.body?.data?.config?.contextLines, { before: 3, after: 3 });
|
|
71
|
+
assert.ok(initialSafetyGuardSetup.body?.data?.categories?.includes("database"));
|
|
72
|
+
|
|
73
|
+
const invalidSafetyGuardSetup = await request("/api/safety-guard/config", {
|
|
74
|
+
method: "POST",
|
|
75
|
+
body: { config: { contextLines: { before: 21 } } },
|
|
76
|
+
});
|
|
77
|
+
assert.equal(invalidSafetyGuardSetup.status, 400, "setup should reject context limits outside the canonical range");
|
|
78
|
+
|
|
79
|
+
const savedSafetyGuardSetup = await request("/api/safety-guard/config", {
|
|
80
|
+
method: "POST",
|
|
81
|
+
body: {
|
|
82
|
+
config: {
|
|
83
|
+
enabled: false,
|
|
84
|
+
categories: { docker: false },
|
|
85
|
+
protectedPaths: { edit: false },
|
|
86
|
+
contextLines: { before: 2, after: 4 },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
assert.equal(savedSafetyGuardSetup.status, 200);
|
|
91
|
+
assert.equal(savedSafetyGuardSetup.body?.data?.config?.enabled, false);
|
|
92
|
+
assert.equal(savedSafetyGuardSetup.body?.data?.config?.categories?.docker, false);
|
|
93
|
+
assert.deepEqual(savedSafetyGuardSetup.body?.data?.config?.contextLines, { before: 2, after: 4 });
|
|
94
|
+
const persistedSafetyGuardSetup = JSON.parse(await readFile(safetyGuardSettingsFile, "utf8"));
|
|
95
|
+
assert.equal(persistedSafetyGuardSetup.protectedPaths?.edit, false);
|
|
96
|
+
|
|
65
97
|
const initialGitSetup = await request("/api/git-workflow/preferences");
|
|
66
98
|
assert.equal(initialGitSetup.status, 200);
|
|
67
99
|
assert.equal(initialGitSetup.body?.data?.configured, false, "guided Git should require first-time model setup");
|
|
@@ -104,7 +136,7 @@ try {
|
|
|
104
136
|
const disableAuth = await request("/api/remote-auth/settings", { method: "POST", body: { enabled: false } });
|
|
105
137
|
assert.equal(disableAuth.status, 200);
|
|
106
138
|
const savedAfterDisable = JSON.parse(await readFile(settingsFile, "utf8"));
|
|
107
|
-
assert.equal(savedAfterDisable.version,
|
|
139
|
+
assert.equal(savedAfterDisable.version, 3, "Web UI settings should migrate to the resource-default schema version");
|
|
108
140
|
assert.equal(savedAfterDisable.remoteAuthEnabled, false, "disabling Remote PIN auth should persist the off preference");
|
|
109
141
|
assert.equal(savedAfterDisable.gitWorkflow?.generation?.modelId, "fake-model", "Remote PIN updates should preserve guided Git preferences");
|
|
110
142
|
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import webuiRpcHelper from "../webui-rpc-helper.mjs";
|
|
6
|
+
|
|
7
|
+
class EventBus {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.handlers = new Map();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
on(name, handler) {
|
|
13
|
+
const handlers = this.handlers.get(name) || new Set();
|
|
14
|
+
handlers.add(handler);
|
|
15
|
+
this.handlers.set(name, handlers);
|
|
16
|
+
return () => handlers.delete(handler);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
emit(name, value) {
|
|
20
|
+
for (const handler of [...(this.handlers.get(name) || [])]) handler(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const root = await mkdtemp(path.join(tmpdir(), "pi-webui-resource-defaults-"));
|
|
25
|
+
const settingsFile = path.join(root, "settings.json");
|
|
26
|
+
const previousSettingsFile = process.env.PI_WEBUI_SETTINGS_FILE;
|
|
27
|
+
process.env.PI_WEBUI_SETTINGS_FILE = settingsFile;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await writeFile(settingsFile, `${JSON.stringify({
|
|
31
|
+
version: 3,
|
|
32
|
+
resourceDefaults: {
|
|
33
|
+
tools: { enabledTools: ["read", "write"] },
|
|
34
|
+
skills: { enabledSkills: ["skill-a", "skill-c"] },
|
|
35
|
+
},
|
|
36
|
+
}, null, 2)}\n`, "utf8");
|
|
37
|
+
|
|
38
|
+
const extensionHandlers = new Map();
|
|
39
|
+
const registeredCommands = new Map();
|
|
40
|
+
const notifications = [];
|
|
41
|
+
const appendedEntries = [];
|
|
42
|
+
const bus = new EventBus();
|
|
43
|
+
let activeTools = ["read", "bash", "write"];
|
|
44
|
+
let branchEntries = [];
|
|
45
|
+
let availableSkills = [];
|
|
46
|
+
|
|
47
|
+
const pi = {
|
|
48
|
+
events: bus,
|
|
49
|
+
on(name, handler) {
|
|
50
|
+
const handlers = extensionHandlers.get(name) || [];
|
|
51
|
+
handlers.push(handler);
|
|
52
|
+
extensionHandlers.set(name, handlers);
|
|
53
|
+
},
|
|
54
|
+
registerCommand(name, command) { registeredCommands.set(name, command); },
|
|
55
|
+
getAllTools() {
|
|
56
|
+
return ["read", "bash", "write"].map((name) => ({ name, description: `${name} tool`, sourceInfo: { source: "builtin" } }));
|
|
57
|
+
},
|
|
58
|
+
getActiveTools() { return [...activeTools]; },
|
|
59
|
+
setActiveTools(names) { activeTools = [...names]; },
|
|
60
|
+
appendEntry(customType, data) { appendedEntries.push({ customType, data }); },
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const ctx = {
|
|
64
|
+
mode: "rpc",
|
|
65
|
+
hasUI: true,
|
|
66
|
+
cwd: root,
|
|
67
|
+
sessionManager: {
|
|
68
|
+
getBranch() { return branchEntries; },
|
|
69
|
+
},
|
|
70
|
+
getSystemPromptOptions() {
|
|
71
|
+
return {
|
|
72
|
+
skills: availableSkills.map((name) => ({ name, description: `${name} skill` })),
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
ui: {
|
|
76
|
+
setStatus() {},
|
|
77
|
+
notify(message, type) { notifications.push({ message, type }); },
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
webuiRpcHelper(pi);
|
|
82
|
+
const helperCommand = registeredCommands.get("webui-helper");
|
|
83
|
+
assert.ok(helperCommand?.handler, "resource defaults test requires the hidden helper command");
|
|
84
|
+
|
|
85
|
+
async function runHelper(action, payload = {}) {
|
|
86
|
+
const requestId = `${action}-${notifications.length}`;
|
|
87
|
+
await helperCommand.handler(JSON.stringify({ requestId, action, payload }), ctx);
|
|
88
|
+
const notice = notifications.findLast((entry) => entry.message.includes(`\"requestId\":\"${requestId}\"`));
|
|
89
|
+
assert.ok(notice, `${action} should emit a helper response`);
|
|
90
|
+
const response = JSON.parse(notice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
|
|
91
|
+
assert.equal(response.ok, true, response.error);
|
|
92
|
+
return response.data;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "startup" }, ctx);
|
|
96
|
+
availableSkills = ["skill-a", "skill-b", "skill-c"];
|
|
97
|
+
assert.deepEqual(activeTools, ["read", "write"], "a new session should inherit the global tool allowlist");
|
|
98
|
+
assert.deepEqual(
|
|
99
|
+
(await runHelper("skills-state")).skills.map((skill) => [skill.name, skill.enabled]),
|
|
100
|
+
[["skill-a", true], ["skill-b", false], ["skill-c", true]],
|
|
101
|
+
"a new session should inherit the global skill allowlist",
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
branchEntries = [
|
|
105
|
+
{ type: "custom", customType: "webui-tools-config", data: { enabledTools: ["bash"] } },
|
|
106
|
+
{ type: "custom", customType: "webui-skills-config", data: { disabledSkills: ["skill-a"] } },
|
|
107
|
+
];
|
|
108
|
+
for (const handler of extensionHandlers.get("session_start") || []) await handler({ reason: "resume" }, ctx);
|
|
109
|
+
assert.deepEqual(activeTools, ["bash"], "session tool choices should override the global default");
|
|
110
|
+
assert.deepEqual(
|
|
111
|
+
(await runHelper("skills-state")).skills.map((skill) => [skill.name, skill.enabled]),
|
|
112
|
+
[["skill-a", false], ["skill-b", true], ["skill-c", true]],
|
|
113
|
+
"session skill choices should override the global default",
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
await runHelper("tools-set", { enabledTools: ["read"] });
|
|
117
|
+
await runHelper("skills-set", { enabledSkills: ["skill-a", "skill-c"] });
|
|
118
|
+
assert.deepEqual(appendedEntries.map((entry) => entry.customType), ["webui-tools-config", "webui-skills-config"], "session updates should remain branch-persisted");
|
|
119
|
+
|
|
120
|
+
for (const handler of extensionHandlers.get("session_shutdown") || []) await handler({ reason: "quit" }, ctx);
|
|
121
|
+
console.log("resource-defaults-helper.test.mjs passed");
|
|
122
|
+
} finally {
|
|
123
|
+
if (previousSettingsFile === undefined) delete process.env.PI_WEBUI_SETTINGS_FILE;
|
|
124
|
+
else process.env.PI_WEBUI_SETTINGS_FILE = previousSettingsFile;
|
|
125
|
+
await rm(root, { recursive: true, force: true });
|
|
126
|
+
}
|
|
@@ -119,8 +119,8 @@ try {
|
|
|
119
119
|
assert.equal(deleted.method, "unlink");
|
|
120
120
|
assert.equal(existsSync(deletablePath), false);
|
|
121
121
|
|
|
122
|
-
const auth = createAuthContext();
|
|
123
|
-
const payload = authProvidersPayload(auth.
|
|
122
|
+
const auth = await createAuthContext();
|
|
123
|
+
const payload = await authProvidersPayload(auth.modelRuntime);
|
|
124
124
|
assert.ok(Array.isArray(payload.loginProviders));
|
|
125
125
|
assert.ok(Array.isArray(payload.logoutProviders));
|
|
126
126
|
assert.equal(payload.browserLoginSupported, false);
|
package/webui-rpc-helper.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
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
|
+
import { readWebuiSettings } from "./lib/git-workflow-preferences.mjs";
|
|
4
5
|
|
|
5
6
|
const HELPER_COMMAND = "webui-helper";
|
|
6
7
|
const RESPONSE_PREFIX = "__PI_WEBUI_HELPER_RESPONSE__:";
|
|
@@ -424,6 +425,7 @@ function parseSubagentStatusText(text, previousRuns = new Map()) {
|
|
|
424
425
|
export default function webuiRpcHelper(pi) {
|
|
425
426
|
let enabledTools = new Set();
|
|
426
427
|
let disabledSkills = new Set();
|
|
428
|
+
let inheritedEnabledSkills = null;
|
|
427
429
|
let subagentContext = null;
|
|
428
430
|
let subagentBridgeAvailable = false;
|
|
429
431
|
let subagentPollTimer = null;
|
|
@@ -655,6 +657,15 @@ export default function webuiRpcHelper(pi) {
|
|
|
655
657
|
return pi.getAllTools().map((tool) => tool.name);
|
|
656
658
|
}
|
|
657
659
|
|
|
660
|
+
async function readGlobalResourceDefaults() {
|
|
661
|
+
try {
|
|
662
|
+
return (await readWebuiSettings()).resourceDefaults;
|
|
663
|
+
} catch (error) {
|
|
664
|
+
console.warn(`Web UI resource defaults could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
665
|
+
return { tools: { enabledTools: null }, skills: { enabledSkills: null } };
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
658
669
|
function persistToolsState() {
|
|
659
670
|
pi.appendEntry(TOOLS_CONFIG_TYPE, { enabledTools: [...enabledTools] });
|
|
660
671
|
}
|
|
@@ -664,11 +675,13 @@ export default function webuiRpcHelper(pi) {
|
|
|
664
675
|
pi.setActiveTools([...enabledTools].filter((name) => existing.has(name)));
|
|
665
676
|
}
|
|
666
677
|
|
|
667
|
-
function restoreToolsFromBranch(ctx) {
|
|
678
|
+
function restoreToolsFromBranch(ctx, globalDefaults) {
|
|
668
679
|
const saved = lastBranchConfig(ctx, TOOLS_CONFIG_TYPE)?.enabledTools;
|
|
669
|
-
|
|
680
|
+
const inherited = globalDefaults?.tools?.enabledTools;
|
|
681
|
+
const selected = Array.isArray(saved) ? saved : inherited;
|
|
682
|
+
if (Array.isArray(selected)) {
|
|
670
683
|
const existing = new Set(allToolNames());
|
|
671
|
-
enabledTools = new Set(normalizeNameList(
|
|
684
|
+
enabledTools = new Set(normalizeNameList(selected).filter((name) => existing.has(name)));
|
|
672
685
|
applyTools();
|
|
673
686
|
return;
|
|
674
687
|
}
|
|
@@ -707,9 +720,20 @@ export default function webuiRpcHelper(pi) {
|
|
|
707
720
|
pi.appendEntry(SKILLS_CONFIG_TYPE, { disabledSkills: [...disabledSkills] });
|
|
708
721
|
}
|
|
709
722
|
|
|
710
|
-
function
|
|
723
|
+
function isSkillEnabled(name) {
|
|
724
|
+
return inheritedEnabledSkills instanceof Set ? inheritedEnabledSkills.has(name) : !disabledSkills.has(name);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function restoreSkillsFromBranch(ctx, globalDefaults) {
|
|
711
728
|
const saved = lastBranchConfig(ctx, SKILLS_CONFIG_TYPE)?.disabledSkills;
|
|
712
|
-
|
|
729
|
+
if (Array.isArray(saved)) {
|
|
730
|
+
inheritedEnabledSkills = null;
|
|
731
|
+
disabledSkills = new Set(normalizeNameList(saved));
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
const inherited = globalDefaults?.skills?.enabledSkills;
|
|
735
|
+
inheritedEnabledSkills = Array.isArray(inherited) ? new Set(normalizeNameList(inherited)) : null;
|
|
736
|
+
disabledSkills = new Set();
|
|
713
737
|
}
|
|
714
738
|
|
|
715
739
|
function skillsFromContext(ctx) {
|
|
@@ -718,7 +742,7 @@ export default function webuiRpcHelper(pi) {
|
|
|
718
742
|
return skills.map((skill) => ({
|
|
719
743
|
name: skill.name,
|
|
720
744
|
description: skill.description || "",
|
|
721
|
-
enabled:
|
|
745
|
+
enabled: isSkillEnabled(skill.name),
|
|
722
746
|
disableModelInvocation: skill.disableModelInvocation === true,
|
|
723
747
|
filePath: skill.filePath,
|
|
724
748
|
sourceInfo: safeSourceInfo(skill.sourceInfo),
|
|
@@ -726,13 +750,16 @@ export default function webuiRpcHelper(pi) {
|
|
|
726
750
|
}
|
|
727
751
|
|
|
728
752
|
function skillState(ctx) {
|
|
729
|
-
|
|
730
|
-
|
|
753
|
+
if (inheritedEnabledSkills === null) {
|
|
754
|
+
const known = new Set(skillsFromContext(ctx).map((skill) => skill.name));
|
|
755
|
+
disabledSkills = new Set([...disabledSkills].filter((name) => known.has(name)));
|
|
756
|
+
}
|
|
731
757
|
return { skills: skillsFromContext(ctx) };
|
|
732
758
|
}
|
|
733
759
|
|
|
734
760
|
function setSkillState(ctx, payload) {
|
|
735
761
|
const allNames = new Set(skillsFromContext(ctx).map((skill) => skill.name));
|
|
762
|
+
inheritedEnabledSkills = null;
|
|
736
763
|
if (Array.isArray(payload.enabledSkills)) {
|
|
737
764
|
const enabled = new Set(normalizeNameList(payload.enabledSkills));
|
|
738
765
|
disabledSkills = new Set([...allNames].filter((name) => !enabled.has(name)));
|
|
@@ -800,8 +827,9 @@ export default function webuiRpcHelper(pi) {
|
|
|
800
827
|
});
|
|
801
828
|
|
|
802
829
|
pi.on("session_start", async (_event, ctx) => {
|
|
803
|
-
|
|
804
|
-
|
|
830
|
+
const globalDefaults = await readGlobalResourceDefaults();
|
|
831
|
+
restoreToolsFromBranch(ctx, globalDefaults);
|
|
832
|
+
restoreSkillsFromBranch(ctx, globalDefaults);
|
|
805
833
|
subagentContext = ctx;
|
|
806
834
|
subagentPollGeneration += 1;
|
|
807
835
|
foregroundSubagentRuns.clear();
|
|
@@ -812,8 +840,9 @@ export default function webuiRpcHelper(pi) {
|
|
|
812
840
|
});
|
|
813
841
|
|
|
814
842
|
pi.on("session_tree", async (_event, ctx) => {
|
|
815
|
-
|
|
816
|
-
|
|
843
|
+
const globalDefaults = await readGlobalResourceDefaults();
|
|
844
|
+
restoreToolsFromBranch(ctx, globalDefaults);
|
|
845
|
+
restoreSkillsFromBranch(ctx, globalDefaults);
|
|
817
846
|
subagentContext = ctx;
|
|
818
847
|
});
|
|
819
848
|
|
|
@@ -875,18 +904,20 @@ export default function webuiRpcHelper(pi) {
|
|
|
875
904
|
const match = String(event.text || "").trim().match(/^\/skill:([^\s]+)/i);
|
|
876
905
|
if (!match) return { action: "continue" };
|
|
877
906
|
const skillName = match[1];
|
|
878
|
-
if (
|
|
907
|
+
if (isSkillEnabled(skillName)) return { action: "continue" };
|
|
879
908
|
ctx.ui.notify(`Skill /skill:${skillName} is disabled in the Web UI /skills selector.`, "warning");
|
|
880
909
|
return { action: "handled" };
|
|
881
910
|
});
|
|
882
911
|
|
|
883
912
|
pi.on("before_agent_start", async (event) => {
|
|
884
|
-
if (disabledSkills.size === 0) return;
|
|
913
|
+
if (disabledSkills.size === 0 && inheritedEnabledSkills === null) return;
|
|
885
914
|
const allSkills = Array.isArray(event.systemPromptOptions?.skills) ? event.systemPromptOptions.skills : [];
|
|
886
915
|
if (allSkills.length === 0) return;
|
|
887
|
-
const
|
|
916
|
+
const disabledNames = allSkills.filter((skill) => !isSkillEnabled(skill.name)).map((skill) => skill.name);
|
|
917
|
+
if (disabledNames.length === 0) return;
|
|
918
|
+
const filteredSkills = allSkills.filter((skill) => isSkillEnabled(skill.name));
|
|
888
919
|
let nextPrompt = replaceAvailableSkillsSection(event.systemPrompt, filteredSkills);
|
|
889
|
-
for (const name of
|
|
920
|
+
for (const name of disabledNames) nextPrompt = nextPrompt.replace(skillBlockPattern(name), "");
|
|
890
921
|
return { systemPrompt: nextPrompt };
|
|
891
922
|
});
|
|
892
923
|
}
|