pi-subagent-manager 1.12.0 → 1.13.0
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/dist/orch/extensions.js +22 -7
- package/dist/prefs/settings.js +19 -8
- package/dist/ui/settings-ui.js +8 -4
- package/package.json +1 -1
package/dist/orch/extensions.js
CHANGED
|
@@ -2,6 +2,7 @@ import { realpath, readFile } from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { DefaultPackageManager, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { AGENT_DIR_EXTENSION_PREFIX } from "../prefs/settings.js";
|
|
5
6
|
const ENTRY_EXT = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
|
|
6
7
|
const MANAGER_ENTRY = fileURLToPath(new URL(`../index${ENTRY_EXT}`, import.meta.url));
|
|
7
8
|
export function extensionDisplayName(file) {
|
|
@@ -35,13 +36,18 @@ async function isManagerExtension(file, packageRoot) {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
function relativeWithin(base, file) {
|
|
40
|
+
const relative = path.relative(base, file);
|
|
41
|
+
return relative && !path.isAbsolute(relative) && relative !== ".." &&
|
|
42
|
+
!relative.startsWith(`..${path.sep}`) ? relative : undefined;
|
|
43
|
+
}
|
|
38
44
|
export async function discoverSubagentExtensions(options) {
|
|
39
45
|
const settingsManager = SettingsManager.create(options.cwd, options.agentDir, {
|
|
40
46
|
projectTrusted: options.projectTrusted,
|
|
41
47
|
});
|
|
42
48
|
const packages = new DefaultPackageManager({ ...options, settingsManager });
|
|
43
49
|
const resources = await packages.resolve(async () => "skip");
|
|
44
|
-
const
|
|
50
|
+
const extensions = [];
|
|
45
51
|
const seen = new Set();
|
|
46
52
|
for (const resource of resources.extensions) {
|
|
47
53
|
if (!resource.enabled || resource.path.startsWith("builtin:"))
|
|
@@ -52,15 +58,24 @@ export async function discoverSubagentExtensions(options) {
|
|
|
52
58
|
if (seen.has(resolved))
|
|
53
59
|
continue;
|
|
54
60
|
seen.add(resolved);
|
|
55
|
-
|
|
61
|
+
const projectFile = resource.metadata.scope === "project"
|
|
62
|
+
? relativeWithin(options.cwd, resource.path)
|
|
63
|
+
: undefined;
|
|
64
|
+
const agentFile = resource.metadata.scope === "user"
|
|
65
|
+
? relativeWithin(options.agentDir, resource.path)
|
|
66
|
+
: undefined;
|
|
67
|
+
const id = agentFile
|
|
68
|
+
? AGENT_DIR_EXTENSION_PREFIX + agentFile.split(path.sep).join("/")
|
|
69
|
+
: projectFile ?? resolved;
|
|
70
|
+
extensions.push({ id, path: resolved });
|
|
56
71
|
}
|
|
57
|
-
return
|
|
72
|
+
return extensions;
|
|
58
73
|
}
|
|
59
74
|
export function selectSubagentExtensions(available, selection) {
|
|
60
|
-
if (selection === true)
|
|
61
|
-
return [...available];
|
|
62
75
|
if (selection === false)
|
|
63
76
|
return [];
|
|
64
|
-
const selected = new Set(selection);
|
|
65
|
-
return available
|
|
77
|
+
const selected = new Set(selection === true ? [] : selection);
|
|
78
|
+
return available
|
|
79
|
+
.filter(({ id, path }) => selection === true || selected.has(id) || selected.has(path))
|
|
80
|
+
.map(({ path }) => path);
|
|
66
81
|
}
|
package/dist/prefs/settings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { closeSync, constants, fchmodSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
|
|
4
4
|
export const SUBAGENT_MODES = ["off", "opportunistic", "orchestration"];
|
|
5
5
|
export const WIDGET_MODES = ["full", "minimal"];
|
|
6
6
|
const COST_DISPLAY_MODES = ["pi-footer-event", "pi-footer-status", "pi-status"];
|
|
@@ -20,6 +20,7 @@ export const MODEL_SELECTION_MODES = [
|
|
|
20
20
|
"pick-first-scoped",
|
|
21
21
|
"use-current",
|
|
22
22
|
];
|
|
23
|
+
export const AGENT_DIR_EXTENSION_PREFIX = "$PI_CODING_AGENT_DIR/";
|
|
23
24
|
export function settingsValueEqual(a, b) {
|
|
24
25
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
25
26
|
}
|
|
@@ -91,9 +92,24 @@ function isSupportedKey(key) {
|
|
|
91
92
|
function positiveSafeInteger(value) {
|
|
92
93
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
93
94
|
}
|
|
95
|
+
function isExtensionSelectionPath(entry) {
|
|
96
|
+
if (typeof entry !== "string" || !entry || entry.includes("\0"))
|
|
97
|
+
return false;
|
|
98
|
+
if (entry.startsWith(AGENT_DIR_EXTENSION_PREFIX)) {
|
|
99
|
+
const suffix = entry.slice(AGENT_DIR_EXTENSION_PREFIX.length);
|
|
100
|
+
return !suffix.includes("\\") &&
|
|
101
|
+
suffix.split("/").every((part) => part && part !== "." && part !== "..");
|
|
102
|
+
}
|
|
103
|
+
if (entry === AGENT_DIR_EXTENSION_PREFIX.slice(0, -1))
|
|
104
|
+
return false;
|
|
105
|
+
if (isAbsolute(entry))
|
|
106
|
+
return resolve(entry) === entry;
|
|
107
|
+
return normalize(entry) === entry &&
|
|
108
|
+
entry !== "." && entry !== ".." && !entry.startsWith(`..${sep}`) && !entry.endsWith(sep);
|
|
109
|
+
}
|
|
94
110
|
function requirement(key) {
|
|
95
111
|
if (key === "subagentExtensions")
|
|
96
|
-
return "subagentExtensions must be a boolean or an array of absolute
|
|
112
|
+
return "subagentExtensions must be a boolean or an array of absolute, project-relative, or $PI_CODING_AGENT_DIR paths";
|
|
97
113
|
if (key === "nerdFontIcons" ||
|
|
98
114
|
key === "finalRecap" ||
|
|
99
115
|
key === "checklistIntegration" ||
|
|
@@ -159,12 +175,7 @@ function parseSettings(content) {
|
|
|
159
175
|
continue;
|
|
160
176
|
}
|
|
161
177
|
if (key === "subagentExtensions") {
|
|
162
|
-
if (typeof value !== "boolean" &&
|
|
163
|
-
!(Array.isArray(value) &&
|
|
164
|
-
value.every((entry) => typeof entry === "string" &&
|
|
165
|
-
entry.length > 0 &&
|
|
166
|
-
resolve(entry) === entry &&
|
|
167
|
-
!entry.includes("\0"))))
|
|
178
|
+
if (typeof value !== "boolean" && !(Array.isArray(value) && value.every(isExtensionSelectionPath)))
|
|
168
179
|
throw new Error(requirement(key));
|
|
169
180
|
layer.subagentExtensions =
|
|
170
181
|
typeof value === "boolean" ? value : [...new Set(value)].sort();
|
package/dist/ui/settings-ui.js
CHANGED
|
@@ -141,12 +141,16 @@ function provenanceLegend(theme) {
|
|
|
141
141
|
`${global} Global · ${project} Current Project · ${global} ${project} Both`);
|
|
142
142
|
}
|
|
143
143
|
async function configureSubagentExtensions(ctx, draft, agentDir) {
|
|
144
|
-
const
|
|
144
|
+
const discovered = await discoverSubagentExtensions({
|
|
145
145
|
cwd: ctx.cwd,
|
|
146
146
|
agentDir,
|
|
147
147
|
projectTrusted: ctx.isProjectTrusted(),
|
|
148
148
|
});
|
|
149
|
-
const
|
|
149
|
+
const available = new Set(discovered.map(({ id }) => id));
|
|
150
|
+
const idsByPath = new Map(discovered.map(({ path, id }) => [path, id]));
|
|
151
|
+
const selected = new Set(draft.subagentExtensions === true
|
|
152
|
+
? available
|
|
153
|
+
: (draft.subagentExtensions || []).map((file) => idsByPath.get(file) ?? file));
|
|
150
154
|
const files = [...new Set([...available, ...selected])].sort();
|
|
151
155
|
let selectedId;
|
|
152
156
|
while (true) {
|
|
@@ -154,8 +158,8 @@ async function configureSubagentExtensions(ctx, draft, agentDir) {
|
|
|
154
158
|
...files.map((file) => ({
|
|
155
159
|
id: file,
|
|
156
160
|
label: `${selected.has(file) ? "[x]" : "[ ]"} ${extensionDisplayName(file)}`,
|
|
157
|
-
value: available.
|
|
158
|
-
help: `${file}\n${available.
|
|
161
|
+
value: available.has(file) ? (selected.has(file) ? "On" : "Off") : "Unavailable",
|
|
162
|
+
help: `${file}\n${available.has(file) ? "Reload this extension in newly opened subagent sessions." : "Not currently discoverable/trusted; will not load. Toggle Off to remove the saved selection."}\nSpace/Enter toggles. Changes are saved only with outer Save and apply.`,
|
|
159
163
|
})),
|
|
160
164
|
{
|
|
161
165
|
id: "back",
|