@zew1me/pi-skills-patch 0.1.1-alpha.162 → 0.1.1-alpha.185
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/ATTRIBUTION.md +23 -0
- package/dist/patches/pi-1.0.3/patched.sha256 +2 -2
- package/dist/patches/pi-1.0.3/pre-checkout-trust-patched.sha256 +10 -0
- package/dist/patches/pi-1.0.3/pre-checkout-trust-upgrade.patch +216 -0
- package/dist/patches/pi-1.0.3/pre-expansion-upgrade.patch +130 -33
- package/dist/patches/pi-1.0.3/skills.patch +63 -33
- package/dist/patches/pi-1.1.0/patched.sha256 +2 -2
- package/dist/patches/pi-1.1.0/pre-checkout-trust-patched.sha256 +10 -0
- package/dist/patches/pi-1.1.0/pre-checkout-trust-upgrade.patch +216 -0
- package/dist/patches/pi-1.1.0/pre-expansion-upgrade.patch +130 -33
- package/dist/patches/pi-1.1.0/skills.patch +63 -33
- package/dist/patches/pi-1.3.0/patched.sha256 +2 -2
- package/dist/patches/pi-1.3.0/pre-checkout-trust-patched.sha256 +10 -0
- package/dist/patches/pi-1.3.0/pre-checkout-trust-upgrade.patch +216 -0
- package/dist/patches/pi-1.3.0/pre-expansion-upgrade.patch +130 -33
- package/dist/patches/pi-1.3.0/skills.patch +63 -33
- package/dist/patches/pi-1.4.0/patched.sha256 +2 -2
- package/dist/patches/pi-1.4.0/pre-checkout-trust-patched.sha256 +10 -0
- package/dist/patches/pi-1.4.0/pre-checkout-trust-upgrade.patch +216 -0
- package/dist/patches/pi-1.4.0/skills.patch +63 -33
- package/dist/patches/pi-1.5.2/patched.sha256 +2 -2
- package/dist/patches/pi-1.5.2/pre-checkout-trust-patched.sha256 +10 -0
- package/dist/patches/pi-1.5.2/pre-checkout-trust-upgrade.patch +216 -0
- package/dist/patches/pi-1.5.2/skills.patch +63 -33
- package/dist/patches/pi-1.6.0/patched.sha256 +2 -2
- package/dist/patches/pi-1.6.0/pre-checkout-trust-patched.sha256 +10 -0
- package/dist/patches/pi-1.6.0/pre-checkout-trust-upgrade.patch +216 -0
- package/dist/patches/pi-1.6.0/skills.patch +63 -33
- package/package.json +1 -1
package/dist/ATTRIBUTION.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Attribution
|
|
2
2
|
|
|
3
|
+
## Checkout trust and skill path identity
|
|
4
|
+
|
|
5
|
+
- Source: [`nigel-upstart/pi-buildout`](https://github.com/nigel-upstart/pi-buildout)
|
|
6
|
+
- Revision reviewed:
|
|
7
|
+
[`dc102aa`](https://github.com/nigel-upstart/pi-buildout/commit/dc102aa22b5fb616b4e3b014e08b2fc67dc527e2)
|
|
8
|
+
- License: MIT (Copyright 2026 Nigel Stuke); the root `LICENSE` preserves the notice.
|
|
9
|
+
|
|
10
|
+
Adapted the fork's checkout trust gate, Windows tilde detection, and reuse of resolved paths for persisted and session
|
|
11
|
+
mutations. Copied and adapted the targeted regression tests. The rest of the fork's portable-path implementation,
|
|
12
|
+
version selection, and generated patches were not imported; the artifacts and migrations were built from local states.
|
|
13
|
+
|
|
14
|
+
## Patch builder Git isolation
|
|
15
|
+
|
|
16
|
+
- Source: [`nigel-upstart/pi-buildout`](https://github.com/nigel-upstart/pi-buildout)
|
|
17
|
+
- Revisions reviewed:
|
|
18
|
+
[`6b9d053`](https://github.com/nigel-upstart/pi-buildout/commit/6b9d053d2d16d3c1a68d52054b4498e80af137f1) and
|
|
19
|
+
[`83ef752`](https://github.com/nigel-upstart/pi-buildout/commit/83ef752ab224574b01b780ebfe9c30dff867e4f3)
|
|
20
|
+
- License: MIT (Copyright 2026 Nigel Stuke); the root `LICENSE` preserves the notice.
|
|
21
|
+
|
|
22
|
+
Adapted the fork's empty hook directory and explicit `a/` and `b/` diff prefixes in `scripts/build-pi-patch.mjs`. The
|
|
23
|
+
regression test reuses the fork's Git-serialized hook path containing `#`, with a separate fixture process. The fork's
|
|
24
|
+
patch artifacts, version selection, and release tooling were not adopted.
|
|
25
|
+
|
|
3
26
|
## Subagent context modes from `nigel-upstart/pi-buildout`
|
|
4
27
|
|
|
5
28
|
- Source: `nigel-upstart/pi-buildout`
|
|
@@ -3,8 +3,8 @@ ebf4f6c2de7d95e253cb36be6fecd2d2fc7b1a719227f88c5a3cc65a0aaa1b3b dist/core/reso
|
|
|
3
3
|
449d85fd9fa507f6558b54ed9c7c8cdd98d5aedc902dc4c34e72c7f7f204c7f5 dist/main.js
|
|
4
4
|
556bf3a093f8f3c8cf320fd9be13476d861b2fda8804d7228f4405cc07948ae7 dist/modes/interactive/interactive-mode.js
|
|
5
5
|
dce32d936de2732cac1bf9dbd0257fc2734cc530bb90e38c496cc25b6eec8f09 dist/core/skill-management.js
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
8f261e1425f0a297169a5abda041c9f84df428435ce7f8277bdd80a39656ed79 dist/core/skill-management-core.js
|
|
7
|
+
22cf701c147ec6c6da0d1962025cab71f221e471d6fb29688d70b8c2541b1726 docs/skills.md
|
|
8
8
|
e1ff73f68c6668278fe8dc0c12645cef032ad2c8d4c13536c223a33382fc02df dist/bundle/cli-runtime.js
|
|
9
9
|
bec9d85dfd59bac034fcef8c3951a8d7927dc82a3282ba271bf0214cf29f3bdc dist/bundle/rpc-entry.js
|
|
10
10
|
e79626f2dd6f94aa45d30f3fa63cd84319a6eefcd150b353cfaf274366926774 dist/bundle/cli.js
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
ebf4f6c2de7d95e253cb36be6fecd2d2fc7b1a719227f88c5a3cc65a0aaa1b3b dist/core/resource-loader.js
|
|
2
|
+
6b212fda1510fcbb86fc9c53fc63335b1e8c6a03710223b53862d93e221afa73 dist/core/slash-commands.js
|
|
3
|
+
449d85fd9fa507f6558b54ed9c7c8cdd98d5aedc902dc4c34e72c7f7f204c7f5 dist/main.js
|
|
4
|
+
556bf3a093f8f3c8cf320fd9be13476d861b2fda8804d7228f4405cc07948ae7 dist/modes/interactive/interactive-mode.js
|
|
5
|
+
dce32d936de2732cac1bf9dbd0257fc2734cc530bb90e38c496cc25b6eec8f09 dist/core/skill-management.js
|
|
6
|
+
afb5dac60cf8791d8d12888ea083173e978de5f0c04b7205fec6a834c2c46b57 dist/core/skill-management-core.js
|
|
7
|
+
9ed8e6da4be22f62f99a444d306abc20a5e0d8ba76ecab13de6e7460be2584d2 docs/skills.md
|
|
8
|
+
e1ff73f68c6668278fe8dc0c12645cef032ad2c8d4c13536c223a33382fc02df dist/bundle/cli-runtime.js
|
|
9
|
+
bec9d85dfd59bac034fcef8c3951a8d7927dc82a3282ba271bf0214cf29f3bdc dist/bundle/rpc-entry.js
|
|
10
|
+
e79626f2dd6f94aa45d30f3fa63cd84319a6eefcd150b353cfaf274366926774 dist/bundle/cli.js
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
diff --git a/dist/core/skill-management-core.js b/dist/core/skill-management-core.js
|
|
2
|
+
index 0b4ae56..dc70fae 100644
|
|
3
|
+
--- a/dist/core/skill-management-core.js
|
|
4
|
+
+++ b/dist/core/skill-management-core.js
|
|
5
|
+
@@ -191,9 +191,13 @@ export function expandEnvironmentVariables(env, input) {
|
|
6
|
+
function resolveSkillPath(env, source, cwd) {
|
|
7
|
+
return env.resolvePath(expandEnvironmentVariables(env, source).value, cwd, { trim: true });
|
|
8
|
+
}
|
|
9
|
+
+/** Pi expands a tilde followed by a backslash only on Windows. */
|
|
10
|
+
+function isTildePath(env, value) {
|
|
11
|
+
+ return value === "~" || value.startsWith("~/") || (env.path.sep === "\\" && value.startsWith("~\\"));
|
|
12
|
+
+}
|
|
13
|
+
/** True for a path that does not depend on the directory it is read from: absolute, `~`, or a `file:` URL. */
|
|
14
|
+
function isAnchoredPath(env, value) {
|
|
15
|
+
- return env.path.isAbsolute(value) || value === "~" || value.startsWith("~/") || value.startsWith("file:");
|
|
16
|
+
+ return env.path.isAbsolute(value) || isTildePath(env, value) || value.startsWith("file:");
|
|
17
|
+
}
|
|
18
|
+
/** The checkout root for `cwd`; relative repository entries resolve against it. */
|
|
19
|
+
function findRepoRoot(env, cwd) {
|
|
20
|
+
@@ -235,7 +239,7 @@ function referencesDirectoryVariable(typed) {
|
|
21
|
+
}
|
|
22
|
+
/** True for a `~` or `$NAME` path that resolves the same way from any directory in the current environment. */
|
|
23
|
+
function isPortableSpelling(env, typed) {
|
|
24
|
+
- const spelled = typed === "~" || typed.startsWith("~/") || typed.search(environmentVariableReference) !== -1;
|
|
25
|
+
+ const spelled = isTildePath(env, typed) || typed.search(environmentVariableReference) !== -1;
|
|
26
|
+
if (!spelled || !looksLikePath(typed) || referencesDirectoryVariable(typed))
|
|
27
|
+
return false;
|
|
28
|
+
const { value, unset } = expandEnvironmentVariables(env, typed);
|
|
29
|
+
@@ -304,6 +308,10 @@ function normalizePersistedSource(env, source, context) {
|
|
30
|
+
: env.resolvePath(value, context.cwd, { trim: true });
|
|
31
|
+
return env.fs.existsSync(path) ? env.fs.realpathSync(path) : path;
|
|
32
|
+
}
|
|
33
|
+
+/** Supplies a pre-resolved identity for a path, leaving catalog names as literal keys. */
|
|
34
|
+
+function resolvedPathOption(source) {
|
|
35
|
+
+ return looksLikePath(source) ? { resolvedPath: source } : {};
|
|
36
|
+
+}
|
|
37
|
+
export function updatePersistedSkill(env, action, source, scope, options) {
|
|
38
|
+
const location = configLocation(env, scope, options.cwd, options.agentDir);
|
|
39
|
+
const path = location.path;
|
|
40
|
+
@@ -314,7 +322,13 @@ export function updatePersistedSkill(env, action, source, scope, options) {
|
|
41
|
+
scope,
|
|
42
|
+
repoRoot: scope === "repo" ? findRepoRoot(env, options.cwd) : undefined,
|
|
43
|
+
};
|
|
44
|
+
- const key = normalizePersistedSource(env, source, context);
|
|
45
|
+
+ // Expand only raw spellings, not a command's already-resolved path, which can contain literal `$`.
|
|
46
|
+
+ const { resolvedPath } = options;
|
|
47
|
+
+ const key = resolvedPath === undefined
|
|
48
|
+
+ ? normalizePersistedSource(env, source, context)
|
|
49
|
+
+ : env.fs.existsSync(resolvedPath)
|
|
50
|
+
+ ? env.fs.realpathSync(resolvedPath)
|
|
51
|
+
+ : resolvedPath;
|
|
52
|
+
const matches = (entry) => normalizePersistedSource(env, sourceOf(entry), context) === key;
|
|
53
|
+
return withSkillConfigLock(env, path, () => {
|
|
54
|
+
const config = readJson(env, path);
|
|
55
|
+
@@ -344,7 +358,10 @@ function removePersistedSkill(env, source, target, scope, options) {
|
|
56
|
+
const candidates = looksLikePath(source)
|
|
57
|
+
? [target]
|
|
58
|
+
: [target, source, env.resolvePath(source, options.cwd, { trim: true })];
|
|
59
|
+
- return [...new Set(candidates)].some((candidate) => updatePersistedSkill(env, "remove", candidate, scope, options));
|
|
60
|
+
+ return [...new Set(candidates)].some((candidate) => updatePersistedSkill(env, "remove", candidate, scope, {
|
|
61
|
+
+ ...options,
|
|
62
|
+
+ ...resolvedPathOption(candidate),
|
|
63
|
+
+ }));
|
|
64
|
+
}
|
|
65
|
+
export function getActiveSkillEntries(env, { cwd, agentDir, strict = false, onWarn }) {
|
|
66
|
+
const entries = [];
|
|
67
|
+
@@ -504,20 +521,24 @@ async function runMutationCommand(env, command, rest, surface, options) {
|
|
68
|
+
// Removal never consults the catalog, whose package resolution can install missing packages. A stored bare
|
|
69
|
+
// value is a catalog name, so removing a bare name tries that literal name first and its resolved path after.
|
|
70
|
+
const resolution = command === "add" ? await resolveSkillSource(env, source, options) : undefined;
|
|
71
|
+
- const target = command === "remove"
|
|
72
|
+
- ? looksLikePath(source)
|
|
73
|
+
- ? resolveSkillPath(env, source, options.cwd)
|
|
74
|
+
- : source
|
|
75
|
+
- : resolution?.normalized;
|
|
76
|
+
+ const target = resolution?.normalized ?? (looksLikePath(source) ? resolveSkillPath(env, source, options.cwd) : source);
|
|
77
|
+
if (!target)
|
|
78
|
+
throw new Error(`Skill source is invalid: ${source}`);
|
|
79
|
+
if (command === "add" && !resolution?.resolved) {
|
|
80
|
+
throw new Error(skillNotFoundMessage(env, source));
|
|
81
|
+
}
|
|
82
|
+
- if (scope === "session")
|
|
83
|
+
- return { exitCode: 0, lines: [], session: { action: command, source: target } };
|
|
84
|
+
+ if (scope === "session") {
|
|
85
|
+
+ return {
|
|
86
|
+
+ exitCode: 0,
|
|
87
|
+
+ lines: [],
|
|
88
|
+
+ session: { action: command, source: target, ...(resolution?.resolved ? { resolved: resolution.resolved } : {}) },
|
|
89
|
+
+ };
|
|
90
|
+
+ }
|
|
91
|
+
const updated = command === "add"
|
|
92
|
+
- ? updatePersistedSkill(env, command, persistedAddForm(env, source, target, scope, options.cwd), scope, options)
|
|
93
|
+
+ ? updatePersistedSkill(env, command, persistedAddForm(env, source, target, scope, options.cwd), scope, {
|
|
94
|
+
+ ...options,
|
|
95
|
+
+ ...resolvedPathOption(target),
|
|
96
|
+
+ })
|
|
97
|
+
: removePersistedSkill(env, source, target, scope, options);
|
|
98
|
+
if (!updated)
|
|
99
|
+
throw new Error(`Skill is not enabled for ${scope} scope: ${source}`);
|
|
100
|
+
@@ -554,6 +575,7 @@ export async function runSkillsCommand(env, args, options) {
|
|
101
|
+
*/
|
|
102
|
+
export async function resolveActiveSkillPaths(env, context) {
|
|
103
|
+
const { cwd, agentDir, settingsManager, resolvedSkillResources, resolveResourcePath } = context;
|
|
104
|
+
+ const manager = settingsManager ?? env.createSettingsManager(cwd, agentDir);
|
|
105
|
+
const paths = [];
|
|
106
|
+
const diagnostics = [];
|
|
107
|
+
const entries = getActiveSkillEntries(env, {
|
|
108
|
+
@@ -566,7 +588,7 @@ export async function resolveActiveSkillPaths(env, context) {
|
|
109
|
+
catalogPathsByName ??= new Map((await getSkillCatalog(env, {
|
|
110
|
+
cwd,
|
|
111
|
+
agentDir,
|
|
112
|
+
- ...(settingsManager ? { settingsManager } : {}),
|
|
113
|
+
+ settingsManager: manager,
|
|
114
|
+
...(resolvedSkillResources ? { resolvedSkillResources } : {}),
|
|
115
|
+
})).map((skill) => [skill.name, skill.filePath]));
|
|
116
|
+
return catalogPathsByName.get(name);
|
|
117
|
+
@@ -574,12 +596,22 @@ export async function resolveActiveSkillPaths(env, context) {
|
|
118
|
+
let repoRoot;
|
|
119
|
+
const entryPath = (entry) => {
|
|
120
|
+
const value = expandEnvironmentVariables(env, entry.source).value.trim();
|
|
121
|
+
- if (entry.scope === "repo" && !isAnchoredPath(env, value)) {
|
|
122
|
+
- repoRoot ??= { value: findRepoRoot(env, cwd) };
|
|
123
|
+
- if (repoRoot.value !== undefined)
|
|
124
|
+
- return env.path.resolve(repoRoot.value, value);
|
|
125
|
+
+ if (entry.scope !== "repo" || isAnchoredPath(env, value))
|
|
126
|
+
+ return resolveResourcePath(value);
|
|
127
|
+
+ // Entries follow the remote across clones, but trust belongs to the current checkout.
|
|
128
|
+
+ if (!manager.isProjectTrusted()) {
|
|
129
|
+
+ diagnostics.push({
|
|
130
|
+
+ type: "warning",
|
|
131
|
+
+ message: "Repository-relative active skill requires project trust",
|
|
132
|
+
+ path: entry.source,
|
|
133
|
+
+ });
|
|
134
|
+
+ return undefined;
|
|
135
|
+
}
|
|
136
|
+
- return resolveResourcePath(value);
|
|
137
|
+
+ repoRoot ??= { value: findRepoRoot(env, cwd) };
|
|
138
|
+
+ if (repoRoot.value !== undefined)
|
|
139
|
+
+ return env.path.resolve(repoRoot.value, value);
|
|
140
|
+
+ diagnostics.push(unresolvedSkillDiagnostic(env, entry));
|
|
141
|
+
+ return undefined;
|
|
142
|
+
};
|
|
143
|
+
for (const entry of entries) {
|
|
144
|
+
if (!looksLikePath(entry.source)) {
|
|
145
|
+
@@ -591,6 +623,8 @@ export async function resolveActiveSkillPaths(env, context) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const path = entryPath(entry);
|
|
149
|
+
+ if (path === undefined)
|
|
150
|
+
+ continue;
|
|
151
|
+
if (env.fs.existsSync(path))
|
|
152
|
+
paths.push(path);
|
|
153
|
+
else
|
|
154
|
+
@@ -625,15 +659,14 @@ export async function resolveSkillEntryPath(env, context, source) {
|
|
155
|
+
* Returns the line to show, or `undefined` when it has already reported an error. The list is mutated in
|
|
156
|
+
* place because the loader holds the same array.
|
|
157
|
+
*/
|
|
158
|
+
-async function applySessionSkillChange(env, session, context) {
|
|
159
|
+
- const { cwd, agentDir, settingsManager, additionalSkillPaths, resolveResourcePath } = context;
|
|
160
|
+
+function applySessionSkillChange(env, session, context) {
|
|
161
|
+
+ const { cwd, agentDir, additionalSkillPaths } = context;
|
|
162
|
+
if (!additionalSkillPaths) {
|
|
163
|
+
context.showError("Session skill activation is unavailable for this resource loader.");
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
if (session.action === "add") {
|
|
167
|
+
- const pathContext = { cwd, agentDir, settingsManager, resolveResourcePath };
|
|
168
|
+
- const { resolved } = await resolveSkillEntryPath(env, pathContext, session.source);
|
|
169
|
+
+ const { resolved } = session;
|
|
170
|
+
if (!resolved) {
|
|
171
|
+
context.showError(`Skill not found in the catalog: ${session.source}`);
|
|
172
|
+
return undefined;
|
|
173
|
+
@@ -642,18 +675,15 @@ async function applySessionSkillChange(env, session, context) {
|
|
174
|
+
additionalSkillPaths.push(resolved);
|
|
175
|
+
return `Enabled ${resolved} for this session.`;
|
|
176
|
+
}
|
|
177
|
+
- // Removal must not resolve packages. Recover bare names from the already-enabled paths, and compare explicit
|
|
178
|
+
- // paths after applying the same resolution used by the resource loader.
|
|
179
|
+
- const normalized = looksLikePath(session.source)
|
|
180
|
+
- ? resolveResourcePath(expandEnvironmentVariables(env, session.source).value)
|
|
181
|
+
- : session.source;
|
|
182
|
+
+ // Removal must not resolve packages or re-expand the already-normalized path.
|
|
183
|
+
+ // Recover bare names from the already-enabled paths instead.
|
|
184
|
+
const skillPaths = looksLikePath(session.source)
|
|
185
|
+
? []
|
|
186
|
+
: env
|
|
187
|
+
.loadSkills({ cwd, agentDir, skillPaths: additionalSkillPaths, includeDefaults: false })
|
|
188
|
+
.skills.filter((skill) => skill.name === session.source)
|
|
189
|
+
.map((skill) => skill.filePath);
|
|
190
|
+
- const direct = (path) => path === session.source || path === normalized || skillPaths.includes(path);
|
|
191
|
+
+ const direct = (path) => path === session.source || skillPaths.includes(path);
|
|
192
|
+
// A bare name added as a local path stays removable by that name after the path is deleted, but only when
|
|
193
|
+
// nothing matches it directly.
|
|
194
|
+
const localPath = looksLikePath(session.source) ? undefined : env.resolvePath(session.source, cwd, { trim: true });
|
|
195
|
+
@@ -697,7 +727,7 @@ export async function handleSkillsInteractive(env, text, context) {
|
|
196
|
+
}
|
|
197
|
+
let lines = result.lines;
|
|
198
|
+
if (result.session) {
|
|
199
|
+
- const line = await applySessionSkillChange(env, result.session, context);
|
|
200
|
+
+ const line = applySessionSkillChange(env, result.session, context);
|
|
201
|
+
if (line === undefined)
|
|
202
|
+
return;
|
|
203
|
+
lines = [line];
|
|
204
|
+
diff --git a/docs/skills.md b/docs/skills.md
|
|
205
|
+
index 2a17b24..6a7cf37 100644
|
|
206
|
+
--- a/docs/skills.md
|
|
207
|
+
+++ b/docs/skills.md
|
|
208
|
+
@@ -130,7 +130,7 @@ pi skills remove browser-testing-with-devtools --repo
|
|
209
|
+
|
|
210
|
+
`--session` is interactive-only and lasts until the session ends. `--global` and `--repo` persist to their respective JSON configuration. `list` and `search` show catalog skills. `pi skills active` shows the configured global and repository entries; `/skills active` also shows session entries.
|
|
211
|
+
|
|
212
|
+
-Path arguments may use `~`, `$NAME`, or `${NAME}`; `/skills` expands them itself because its arguments never pass through a shell. With `--repo`, a path inside the current checkout is stored relative to the repository root, so the entry works in every clone and worktree with the same remote. Otherwise `add` keeps a `~` or `$NAME` spelling as typed and stores any other path as an absolute path, under `~` when it is in your home directory. Stored paths are expanded whenever Pi loads skills: at startup, after `/skills add` or `/skills remove`, and on `/reload` or `/skills reload`. Other relative entries resolve against the repository root in `repo-skills.json` and against the working directory in `skills.json`, so prefer absolute, `~`, or `$NAME` paths in `skills.json`.
|
|
213
|
+
+Path arguments may use `~`, `$NAME`, or `${NAME}`; `/skills` expands them itself because its arguments never pass through a shell. With `--repo`, a path inside the current checkout is stored relative to the repository root, so the entry follows every clone and worktree with the same remote, but loads only when the current checkout is trusted. Otherwise `add` keeps a `~` or `$NAME` spelling as typed and stores any other path as an absolute path, under `~` when it is in your home directory. Stored paths are expanded whenever Pi loads skills: at startup, after `/skills add` or `/skills remove`, and on `/reload` or `/skills reload`. Other relative entries resolve against the repository root in `repo-skills.json` and against the working directory in `skills.json`, so prefer absolute, `~`, or `$NAME` paths in `skills.json`.
|
|
214
|
+
|
|
215
|
+
Use `--no-skills` to suppress global and repository active skills; explicit `--skill` paths still load.
|
|
216
|
+
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
diff --git a/dist/core/skill-management-core.js b/dist/core/skill-management-core.js
|
|
2
|
-
index 2fd4257..
|
|
2
|
+
index 2fd4257..dc70fae 100644
|
|
3
3
|
--- a/dist/core/skill-management-core.js
|
|
4
4
|
+++ b/dist/core/skill-management-core.js
|
|
5
|
-
@@ -160,7 +160,
|
|
5
|
+
@@ -160,7 +160,122 @@ export function configLocation(env, scope, cwd, agentDir) {
|
|
6
6
|
return {};
|
|
7
7
|
}
|
|
8
8
|
export function looksLikePath(value) {
|
|
@@ -38,9 +38,13 @@ index 2fd4257..0b4ae56 100644
|
|
|
38
38
|
+function resolveSkillPath(env, source, cwd) {
|
|
39
39
|
+ return env.resolvePath(expandEnvironmentVariables(env, source).value, cwd, { trim: true });
|
|
40
40
|
+}
|
|
41
|
+
+/** Pi expands a tilde followed by a backslash only on Windows. */
|
|
42
|
+
+function isTildePath(env, value) {
|
|
43
|
+
+ return value === "~" || value.startsWith("~/") || (env.path.sep === "\\" && value.startsWith("~\\"));
|
|
44
|
+
+}
|
|
41
45
|
+/** True for a path that does not depend on the directory it is read from: absolute, `~`, or a `file:` URL. */
|
|
42
46
|
+function isAnchoredPath(env, value) {
|
|
43
|
-
+ return env.path.isAbsolute(value) ||
|
|
47
|
+
+ return env.path.isAbsolute(value) || isTildePath(env, value) || value.startsWith("file:");
|
|
44
48
|
+}
|
|
45
49
|
+/** The checkout root for `cwd`; relative repository entries resolve against it. */
|
|
46
50
|
+function findRepoRoot(env, cwd) {
|
|
@@ -82,7 +86,7 @@ index 2fd4257..0b4ae56 100644
|
|
|
82
86
|
+}
|
|
83
87
|
+/** True for a `~` or `$NAME` path that resolves the same way from any directory in the current environment. */
|
|
84
88
|
+function isPortableSpelling(env, typed) {
|
|
85
|
-
+ const spelled =
|
|
89
|
+
+ const spelled = isTildePath(env, typed) || typed.search(environmentVariableReference) !== -1;
|
|
86
90
|
+ if (!spelled || !looksLikePath(typed) || referencesDirectoryVariable(typed))
|
|
87
91
|
+ return false;
|
|
88
92
|
+ const { value, unset } = expandEnvironmentVariables(env, typed);
|
|
@@ -122,7 +126,7 @@ index 2fd4257..0b4ae56 100644
|
|
|
122
126
|
}
|
|
123
127
|
/** True when `path` exists and Pi's own loader finds at least one skill in it. */
|
|
124
128
|
function containsSkills(env, path, options) {
|
|
125
|
-
@@ -175,36 +
|
|
129
|
+
@@ -175,36 +290,56 @@ function containsSkills(env, path, options) {
|
|
126
130
|
return skills.length > 0;
|
|
127
131
|
}
|
|
128
132
|
/**
|
|
@@ -147,6 +151,10 @@ index 2fd4257..0b4ae56 100644
|
|
|
147
151
|
+ ? env.path.resolve(context.repoRoot, value)
|
|
148
152
|
+ : env.resolvePath(value, context.cwd, { trim: true });
|
|
149
153
|
+ return env.fs.existsSync(path) ? env.fs.realpathSync(path) : path;
|
|
154
|
+
+}
|
|
155
|
+
+/** Supplies a pre-resolved identity for a path, leaving catalog names as literal keys. */
|
|
156
|
+
+function resolvedPathOption(source) {
|
|
157
|
+
+ return looksLikePath(source) ? { resolvedPath: source } : {};
|
|
150
158
|
}
|
|
151
159
|
export function updatePersistedSkill(env, action, source, scope, options) {
|
|
152
160
|
const location = configLocation(env, scope, options.cwd, options.agentDir);
|
|
@@ -158,7 +166,13 @@ index 2fd4257..0b4ae56 100644
|
|
|
158
166
|
+ scope,
|
|
159
167
|
+ repoRoot: scope === "repo" ? findRepoRoot(env, options.cwd) : undefined,
|
|
160
168
|
+ };
|
|
161
|
-
+
|
|
169
|
+
+ // Expand only raw spellings, not a command's already-resolved path, which can contain literal `$`.
|
|
170
|
+
+ const { resolvedPath } = options;
|
|
171
|
+
+ const key = resolvedPath === undefined
|
|
172
|
+
+ ? normalizePersistedSource(env, source, context)
|
|
173
|
+
+ : env.fs.existsSync(resolvedPath)
|
|
174
|
+
+ ? env.fs.realpathSync(resolvedPath)
|
|
175
|
+
+ : resolvedPath;
|
|
162
176
|
+ const matches = (entry) => normalizePersistedSource(env, sourceOf(entry), context) === key;
|
|
163
177
|
return withSkillConfigLock(env, path, () => {
|
|
164
178
|
const config = readJson(env, path);
|
|
@@ -179,7 +193,19 @@ index 2fd4257..0b4ae56 100644
|
|
|
179
193
|
if (location.key !== undefined)
|
|
180
194
|
config[location.key] = target;
|
|
181
195
|
writeJson(env, path, config);
|
|
182
|
-
@@ -
|
|
196
|
+
@@ -223,7 +358,10 @@ function removePersistedSkill(env, source, target, scope, options) {
|
|
197
|
+
const candidates = looksLikePath(source)
|
|
198
|
+
? [target]
|
|
199
|
+
: [target, source, env.resolvePath(source, options.cwd, { trim: true })];
|
|
200
|
+
- return [...new Set(candidates)].some((candidate) => updatePersistedSkill(env, "remove", candidate, scope, options));
|
|
201
|
+
+ return [...new Set(candidates)].some((candidate) => updatePersistedSkill(env, "remove", candidate, scope, {
|
|
202
|
+
+ ...options,
|
|
203
|
+
+ ...resolvedPathOption(candidate),
|
|
204
|
+
+ }));
|
|
205
|
+
}
|
|
206
|
+
export function getActiveSkillEntries(env, { cwd, agentDir, strict = false, onWarn }) {
|
|
207
|
+
const entries = [];
|
|
208
|
+
@@ -307,10 +445,11 @@ export async function getSkillCatalog(env, { cwd, agentDir, settingsManager, res
|
|
183
209
|
return [...found.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
184
210
|
}
|
|
185
211
|
async function resolveSkillSource(env, source, options) {
|
|
@@ -192,7 +218,7 @@ index 2fd4257..0b4ae56 100644
|
|
|
192
218
|
// Build the catalog once, then use it both to prefer catalog names over same-named local folders and to
|
|
193
219
|
// resolve the selected skill. A bare local folder is retained as a path only when no catalog entry wins.
|
|
194
220
|
const catalog = await getSkillCatalog(env, options);
|
|
195
|
-
@@ -360,6 +
|
|
221
|
+
@@ -360,6 +499,16 @@ async function runCatalogCommand(env, command, rest, surface, options) {
|
|
196
222
|
: [query ? "No matching skills." : "No catalog skills found."],
|
|
197
223
|
};
|
|
198
224
|
}
|
|
@@ -209,29 +235,41 @@ index 2fd4257..0b4ae56 100644
|
|
|
209
235
|
async function runMutationCommand(env, command, rest, surface, options) {
|
|
210
236
|
const scopeList = `--global|--repo${options.allowSession ? "|--session" : ""}`;
|
|
211
237
|
const source = rest.find((arg) => !arg.startsWith("--"));
|
|
212
|
-
@@ -
|
|
238
|
+
@@ -372,20 +521,24 @@ async function runMutationCommand(env, command, rest, surface, options) {
|
|
239
|
+
// Removal never consults the catalog, whose package resolution can install missing packages. A stored bare
|
|
240
|
+
// value is a catalog name, so removing a bare name tries that literal name first and its resolved path after.
|
|
213
241
|
const resolution = command === "add" ? await resolveSkillSource(env, source, options) : undefined;
|
|
214
|
-
|
|
215
|
-
|
|
242
|
+
- const target = command === "remove"
|
|
243
|
+
- ? looksLikePath(source)
|
|
216
244
|
- ? env.resolvePath(source, options.cwd, { trim: true })
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
245
|
+
- : source
|
|
246
|
+
- : resolution?.normalized;
|
|
247
|
+
+ const target = resolution?.normalized ?? (looksLikePath(source) ? resolveSkillPath(env, source, options.cwd) : source);
|
|
220
248
|
if (!target)
|
|
221
249
|
throw new Error(`Skill source is invalid: ${source}`);
|
|
222
250
|
if (command === "add" && !resolution?.resolved) {
|
|
223
251
|
- throw new Error(`Skill not found in the catalog or at an existing path: ${source}`);
|
|
224
252
|
+ throw new Error(skillNotFoundMessage(env, source));
|
|
253
|
+
+ }
|
|
254
|
+
+ if (scope === "session") {
|
|
255
|
+
+ return {
|
|
256
|
+
+ exitCode: 0,
|
|
257
|
+
+ lines: [],
|
|
258
|
+
+ session: { action: command, source: target, ...(resolution?.resolved ? { resolved: resolution.resolved } : {}) },
|
|
259
|
+
+ };
|
|
225
260
|
}
|
|
226
|
-
|
|
227
|
-
|
|
261
|
+
- if (scope === "session")
|
|
262
|
+
- return { exitCode: 0, lines: [], session: { action: command, source: target } };
|
|
228
263
|
const updated = command === "add"
|
|
229
264
|
- ? updatePersistedSkill(env, command, target, scope, options)
|
|
230
|
-
+ ? updatePersistedSkill(env, command, persistedAddForm(env, source, target, scope, options.cwd), scope,
|
|
265
|
+
+ ? updatePersistedSkill(env, command, persistedAddForm(env, source, target, scope, options.cwd), scope, {
|
|
266
|
+
+ ...options,
|
|
267
|
+
+ ...resolvedPathOption(target),
|
|
268
|
+
+ })
|
|
231
269
|
: removePersistedSkill(env, source, target, scope, options);
|
|
232
270
|
if (!updated)
|
|
233
271
|
throw new Error(`Skill is not enabled for ${scope} scope: ${source}`);
|
|
234
|
-
@@ -412,
|
|
272
|
+
@@ -412,12 +565,17 @@ export async function runSkillsCommand(env, args, options) {
|
|
235
273
|
/**
|
|
236
274
|
* Resolves the skills that are explicitly active for this session into concrete paths.
|
|
237
275
|
*
|
|
@@ -248,19 +286,39 @@ index 2fd4257..0b4ae56 100644
|
|
|
248
286
|
*/
|
|
249
287
|
export async function resolveActiveSkillPaths(env, context) {
|
|
250
288
|
const { cwd, agentDir, settingsManager, resolvedSkillResources, resolveResourcePath } = context;
|
|
251
|
-
|
|
289
|
+
+ const manager = settingsManager ?? env.createSettingsManager(cwd, agentDir);
|
|
290
|
+
const paths = [];
|
|
291
|
+
const diagnostics = [];
|
|
292
|
+
const entries = getActiveSkillEntries(env, {
|
|
293
|
+
@@ -430,27 +588,47 @@ export async function resolveActiveSkillPaths(env, context) {
|
|
294
|
+
catalogPathsByName ??= new Map((await getSkillCatalog(env, {
|
|
295
|
+
cwd,
|
|
296
|
+
agentDir,
|
|
297
|
+
- ...(settingsManager ? { settingsManager } : {}),
|
|
298
|
+
+ settingsManager: manager,
|
|
299
|
+
...(resolvedSkillResources ? { resolvedSkillResources } : {}),
|
|
252
300
|
})).map((skill) => [skill.name, skill.filePath]));
|
|
253
301
|
return catalogPathsByName.get(name);
|
|
254
302
|
};
|
|
255
303
|
+ let repoRoot;
|
|
256
304
|
+ const entryPath = (entry) => {
|
|
257
305
|
+ const value = expandEnvironmentVariables(env, entry.source).value.trim();
|
|
258
|
-
+ if (entry.scope
|
|
259
|
-
+
|
|
260
|
-
+
|
|
261
|
-
+
|
|
306
|
+
+ if (entry.scope !== "repo" || isAnchoredPath(env, value))
|
|
307
|
+
+ return resolveResourcePath(value);
|
|
308
|
+
+ // Entries follow the remote across clones, but trust belongs to the current checkout.
|
|
309
|
+
+ if (!manager.isProjectTrusted()) {
|
|
310
|
+
+ diagnostics.push({
|
|
311
|
+
+ type: "warning",
|
|
312
|
+
+ message: "Repository-relative active skill requires project trust",
|
|
313
|
+
+ path: entry.source,
|
|
314
|
+
+ });
|
|
315
|
+
+ return undefined;
|
|
262
316
|
+ }
|
|
263
|
-
+
|
|
317
|
+
+ repoRoot ??= { value: findRepoRoot(env, cwd) };
|
|
318
|
+
+ if (repoRoot.value !== undefined)
|
|
319
|
+
+ return env.path.resolve(repoRoot.value, value);
|
|
320
|
+
+ diagnostics.push(unresolvedSkillDiagnostic(env, entry));
|
|
321
|
+
+ return undefined;
|
|
264
322
|
+ };
|
|
265
323
|
for (const entry of entries) {
|
|
266
324
|
- const source = sourceOf(entry);
|
|
@@ -285,6 +343,8 @@ index 2fd4257..0b4ae56 100644
|
|
|
285
343
|
- diagnostics.push({ type: "warning", message: "Active skill could not be resolved", path: source });
|
|
286
344
|
}
|
|
287
345
|
+ const path = entryPath(entry);
|
|
346
|
+
+ if (path === undefined)
|
|
347
|
+
+ continue;
|
|
288
348
|
+ if (env.fs.existsSync(path))
|
|
289
349
|
+ paths.push(path);
|
|
290
350
|
+ else
|
|
@@ -292,7 +352,7 @@ index 2fd4257..0b4ae56 100644
|
|
|
292
352
|
}
|
|
293
353
|
return { paths, diagnostics };
|
|
294
354
|
}
|
|
295
|
-
@@ -464,7 +
|
|
355
|
+
@@ -464,7 +642,7 @@ export async function resolveActiveSkillPaths(env, context) {
|
|
296
356
|
export async function resolveSkillEntryPath(env, context, source) {
|
|
297
357
|
const { cwd, agentDir, settingsManager, resolvedSkillResources, resolveResourcePath } = context;
|
|
298
358
|
if (looksLikePath(source)) {
|
|
@@ -301,17 +361,54 @@ index 2fd4257..0b4ae56 100644
|
|
|
301
361
|
return { normalized, resolved: env.fs.existsSync(normalized) ? normalized : undefined };
|
|
302
362
|
}
|
|
303
363
|
const catalog = await getSkillCatalog(env, {
|
|
304
|
-
@@ -
|
|
364
|
+
@@ -481,15 +659,14 @@ export async function resolveSkillEntryPath(env, context, source) {
|
|
365
|
+
* Returns the line to show, or `undefined` when it has already reported an error. The list is mutated in
|
|
366
|
+
* place because the loader holds the same array.
|
|
367
|
+
*/
|
|
368
|
+
-async function applySessionSkillChange(env, session, context) {
|
|
369
|
+
- const { cwd, agentDir, settingsManager, additionalSkillPaths, resolveResourcePath } = context;
|
|
370
|
+
+function applySessionSkillChange(env, session, context) {
|
|
371
|
+
+ const { cwd, agentDir, additionalSkillPaths } = context;
|
|
372
|
+
if (!additionalSkillPaths) {
|
|
373
|
+
context.showError("Session skill activation is unavailable for this resource loader.");
|
|
374
|
+
return undefined;
|
|
305
375
|
}
|
|
306
|
-
|
|
307
|
-
|
|
376
|
+
if (session.action === "add") {
|
|
377
|
+
- const pathContext = { cwd, agentDir, settingsManager, resolveResourcePath };
|
|
378
|
+
- const { resolved } = await resolveSkillEntryPath(env, pathContext, session.source);
|
|
379
|
+
+ const { resolved } = session;
|
|
380
|
+
if (!resolved) {
|
|
381
|
+
context.showError(`Skill not found in the catalog: ${session.source}`);
|
|
382
|
+
return undefined;
|
|
383
|
+
@@ -498,16 +675,15 @@ async function applySessionSkillChange(env, session, context) {
|
|
384
|
+
additionalSkillPaths.push(resolved);
|
|
385
|
+
return `Enabled ${resolved} for this session.`;
|
|
386
|
+
}
|
|
387
|
+
- // Removal must not resolve packages. Recover bare names from the already-enabled paths, and compare explicit
|
|
388
|
+
- // paths after applying the same resolution used by the resource loader.
|
|
308
389
|
- const normalized = looksLikePath(session.source) ? resolveResourcePath(session.source) : session.source;
|
|
309
|
-
+
|
|
310
|
-
+
|
|
311
|
-
+ : session.source;
|
|
390
|
+
+ // Removal must not resolve packages or re-expand the already-normalized path.
|
|
391
|
+
+ // Recover bare names from the already-enabled paths instead.
|
|
312
392
|
const skillPaths = looksLikePath(session.source)
|
|
313
393
|
? []
|
|
314
394
|
: env
|
|
395
|
+
.loadSkills({ cwd, agentDir, skillPaths: additionalSkillPaths, includeDefaults: false })
|
|
396
|
+
.skills.filter((skill) => skill.name === session.source)
|
|
397
|
+
.map((skill) => skill.filePath);
|
|
398
|
+
- const direct = (path) => path === session.source || path === normalized || skillPaths.includes(path);
|
|
399
|
+
+ const direct = (path) => path === session.source || skillPaths.includes(path);
|
|
400
|
+
// A bare name added as a local path stays removable by that name after the path is deleted, but only when
|
|
401
|
+
// nothing matches it directly.
|
|
402
|
+
const localPath = looksLikePath(session.source) ? undefined : env.resolvePath(session.source, cwd, { trim: true });
|
|
403
|
+
@@ -551,7 +727,7 @@ export async function handleSkillsInteractive(env, text, context) {
|
|
404
|
+
}
|
|
405
|
+
let lines = result.lines;
|
|
406
|
+
if (result.session) {
|
|
407
|
+
- const line = await applySessionSkillChange(env, result.session, context);
|
|
408
|
+
+ const line = applySessionSkillChange(env, result.session, context);
|
|
409
|
+
if (line === undefined)
|
|
410
|
+
return;
|
|
411
|
+
lines = [line];
|
|
315
412
|
diff --git a/dist/core/skill-management.js b/dist/core/skill-management.js
|
|
316
413
|
index 3d18e7d..8b712ef 100644
|
|
317
414
|
--- a/dist/core/skill-management.js
|
|
@@ -325,14 +422,14 @@ index 3d18e7d..8b712ef 100644
|
|
|
325
422
|
processId: () => process.pid,
|
|
326
423
|
lockSync: (directory, options) => lockfile.lockSync(directory, options),
|
|
327
424
|
diff --git a/docs/skills.md b/docs/skills.md
|
|
328
|
-
index a6adcc6..
|
|
425
|
+
index a6adcc6..6a7cf37 100644
|
|
329
426
|
--- a/docs/skills.md
|
|
330
427
|
+++ b/docs/skills.md
|
|
331
428
|
@@ -130,6 +130,8 @@ pi skills remove browser-testing-with-devtools --repo
|
|
332
429
|
|
|
333
430
|
`--session` is interactive-only and lasts until the session ends. `--global` and `--repo` persist to their respective JSON configuration. `list` and `search` show catalog skills. `pi skills active` shows the configured global and repository entries; `/skills active` also shows session entries.
|
|
334
431
|
|
|
335
|
-
+Path arguments may use `~`, `$NAME`, or `${NAME}`; `/skills` expands them itself because its arguments never pass through a shell. With `--repo`, a path inside the current checkout is stored relative to the repository root, so the entry
|
|
432
|
+
+Path arguments may use `~`, `$NAME`, or `${NAME}`; `/skills` expands them itself because its arguments never pass through a shell. With `--repo`, a path inside the current checkout is stored relative to the repository root, so the entry follows every clone and worktree with the same remote, but loads only when the current checkout is trusted. Otherwise `add` keeps a `~` or `$NAME` spelling as typed and stores any other path as an absolute path, under `~` when it is in your home directory. Stored paths are expanded whenever Pi loads skills: at startup, after `/skills add` or `/skills remove`, and on `/reload` or `/skills reload`. Other relative entries resolve against the repository root in `repo-skills.json` and against the working directory in `skills.json`, so prefer absolute, `~`, or `$NAME` paths in `skills.json`.
|
|
336
433
|
+
|
|
337
434
|
Use `--no-skills` to suppress global and repository active skills; explicit `--skill` paths still load.
|
|
338
435
|
|