@zew1me/pi-skills-patch 0.1.1-alpha.185 → 0.1.1-alpha.210
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 +111 -49
- package/dist/patches/pi-1.6.0/patched.sha256 +1 -1
- package/dist/patches/pi-1.6.0/pre-checkout-trust-upgrade.patch +25 -14
- package/dist/patches/{pi-1.5.2/patched.sha256 → pi-1.6.0/pre-error-cause-patched.sha256} +3 -3
- package/dist/patches/pi-1.6.0/pre-error-cause-upgrade.patch +15 -0
- package/dist/patches/pi-1.6.0/skills.patch +5 -3
- package/package.json +1 -1
- package/dist/patches/pi-1.0.3/baseline.absent +0 -2
- package/dist/patches/pi-1.0.3/baseline.sha256 +0 -8
- package/dist/patches/pi-1.0.3/patched.sha256 +0 -10
- package/dist/patches/pi-1.0.3/pre-checkout-trust-patched.sha256 +0 -10
- package/dist/patches/pi-1.0.3/pre-checkout-trust-upgrade.patch +0 -216
- package/dist/patches/pi-1.0.3/pre-expansion-patched.sha256 +0 -10
- package/dist/patches/pi-1.0.3/pre-expansion-upgrade.patch +0 -436
- package/dist/patches/pi-1.0.3/skills.patch +0 -1162
- package/dist/patches/pi-1.1.0/baseline.absent +0 -2
- package/dist/patches/pi-1.1.0/baseline.sha256 +0 -8
- package/dist/patches/pi-1.1.0/patched.sha256 +0 -10
- package/dist/patches/pi-1.1.0/pre-checkout-trust-patched.sha256 +0 -10
- package/dist/patches/pi-1.1.0/pre-checkout-trust-upgrade.patch +0 -216
- package/dist/patches/pi-1.1.0/pre-expansion-patched.sha256 +0 -10
- package/dist/patches/pi-1.1.0/pre-expansion-upgrade.patch +0 -436
- package/dist/patches/pi-1.1.0/skills.patch +0 -1168
- package/dist/patches/pi-1.3.0/baseline.absent +0 -2
- package/dist/patches/pi-1.3.0/baseline.sha256 +0 -8
- package/dist/patches/pi-1.3.0/patched.sha256 +0 -10
- package/dist/patches/pi-1.3.0/pre-checkout-trust-patched.sha256 +0 -10
- package/dist/patches/pi-1.3.0/pre-checkout-trust-upgrade.patch +0 -216
- package/dist/patches/pi-1.3.0/pre-expansion-patched.sha256 +0 -10
- package/dist/patches/pi-1.3.0/pre-expansion-upgrade.patch +0 -436
- package/dist/patches/pi-1.3.0/skills.patch +0 -1168
- package/dist/patches/pi-1.4.0/baseline.absent +0 -2
- package/dist/patches/pi-1.4.0/baseline.sha256 +0 -8
- package/dist/patches/pi-1.4.0/patched.sha256 +0 -10
- package/dist/patches/pi-1.4.0/pre-checkout-trust-patched.sha256 +0 -10
- package/dist/patches/pi-1.4.0/pre-checkout-trust-upgrade.patch +0 -216
- package/dist/patches/pi-1.4.0/skills.patch +0 -1168
- package/dist/patches/pi-1.5.2/baseline.absent +0 -2
- package/dist/patches/pi-1.5.2/baseline.sha256 +0 -8
- package/dist/patches/pi-1.5.2/pre-checkout-trust-patched.sha256 +0 -10
- package/dist/patches/pi-1.5.2/pre-checkout-trust-upgrade.patch +0 -216
- package/dist/patches/pi-1.5.2/skills.patch +0 -1168
|
@@ -1,216 +0,0 @@
|
|
|
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,10 +0,0 @@
|
|
|
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
|
-
2ca309a974c2a2e8235ed80fbbf54f471ce973f81cebd963a1ffd406614ac351 dist/core/skill-management.js
|
|
6
|
-
f0b3a3de117b9fef957850569127de1c07e863457b440417552e2809e21aa291 dist/core/skill-management-core.js
|
|
7
|
-
aadc130ac066e9129d910935fdfe9fcd06e2333e3889b86b11f62b155643fe56 docs/skills.md
|
|
8
|
-
e1ff73f68c6668278fe8dc0c12645cef032ad2c8d4c13536c223a33382fc02df dist/bundle/cli-runtime.js
|
|
9
|
-
bec9d85dfd59bac034fcef8c3951a8d7927dc82a3282ba271bf0214cf29f3bdc dist/bundle/rpc-entry.js
|
|
10
|
-
e79626f2dd6f94aa45d30f3fa63cd84319a6eefcd150b353cfaf274366926774 dist/bundle/cli.js
|
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
diff --git a/dist/core/skill-management-core.js b/dist/core/skill-management-core.js
|
|
2
|
-
index 2fd4257..dc70fae 100644
|
|
3
|
-
--- a/dist/core/skill-management-core.js
|
|
4
|
-
+++ b/dist/core/skill-management-core.js
|
|
5
|
-
@@ -160,7 +160,122 @@ export function configLocation(env, scope, cwd, agentDir) {
|
|
6
|
-
return {};
|
|
7
|
-
}
|
|
8
|
-
export function looksLikePath(value) {
|
|
9
|
-
- return value.includes("/") || value.includes("\\") || value.startsWith(".") || value.startsWith("~");
|
|
10
|
-
+ return (value.includes("/") ||
|
|
11
|
-
+ value.includes("\\") ||
|
|
12
|
-
+ value.startsWith(".") ||
|
|
13
|
-
+ value.startsWith("~") ||
|
|
14
|
-
+ value.startsWith("$"));
|
|
15
|
-
+}
|
|
16
|
-
+const environmentVariableReference = /\$(?:\{([A-Za-z_]\w*)\}|([A-Za-z_]\w*))/g;
|
|
17
|
-
+/**
|
|
18
|
-
+ * Expands `$NAME` and `${NAME}` references in a skill path.
|
|
19
|
-
+ *
|
|
20
|
-
+ * `/skills` arguments never pass through a shell, so without this a path such as `$HOME/skills/x` would be
|
|
21
|
-
+ * resolved against the working directory. An unset variable is left as written rather than removed: a path
|
|
22
|
-
+ * that genuinely contains `$` still resolves, and callers can name the variable when the path does not exist.
|
|
23
|
-
+ */
|
|
24
|
-
+export function expandEnvironmentVariables(env, input) {
|
|
25
|
-
+ const unset = [];
|
|
26
|
-
+ const value = input.replace(environmentVariableReference, (reference, braced, bare) => {
|
|
27
|
-
+ const name = braced ?? bare ?? "";
|
|
28
|
-
+ const expanded = env.environmentVariable(name);
|
|
29
|
-
+ if (expanded !== undefined)
|
|
30
|
-
+ return expanded;
|
|
31
|
-
+ if (!unset.includes(name))
|
|
32
|
-
+ unset.push(name);
|
|
33
|
-
+ return reference;
|
|
34
|
-
+ });
|
|
35
|
-
+ return { value, unset };
|
|
36
|
-
+}
|
|
37
|
-
+/** Resolves a path-like skill source to the absolute path it names, expanding variables and `~`. */
|
|
38
|
-
+function resolveSkillPath(env, source, cwd) {
|
|
39
|
-
+ return env.resolvePath(expandEnvironmentVariables(env, source).value, cwd, { trim: true });
|
|
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
|
-
+}
|
|
45
|
-
+/** True for a path that does not depend on the directory it is read from: absolute, `~`, or a `file:` URL. */
|
|
46
|
-
+function isAnchoredPath(env, value) {
|
|
47
|
-
+ return env.path.isAbsolute(value) || isTildePath(env, value) || value.startsWith("file:");
|
|
48
|
-
+}
|
|
49
|
-
+/** The checkout root for `cwd`; relative repository entries resolve against it. */
|
|
50
|
-
+function findRepoRoot(env, cwd) {
|
|
51
|
-
+ return git(env, cwd, ["rev-parse", "--show-toplevel"]);
|
|
52
|
-
+}
|
|
53
|
-
+/** `path` relative to `root` with `/` separators, comparing real paths, or undefined when it lies outside. */
|
|
54
|
-
+function pathInside(env, root, path) {
|
|
55
|
-
+ const real = (value) => (env.fs.existsSync(value) ? env.fs.realpathSync(value) : value);
|
|
56
|
-
+ const relative = env.path.relative(real(root), real(path));
|
|
57
|
-
+ if (relative === ".." || relative.startsWith(`..${env.path.sep}`) || env.path.isAbsolute(relative))
|
|
58
|
-
+ return undefined;
|
|
59
|
-
+ return relative.split(env.path.sep).join("/");
|
|
60
|
-
+}
|
|
61
|
-
+/**
|
|
62
|
-
+ * Chooses how an added path is written to configuration.
|
|
63
|
-
+ *
|
|
64
|
-
+ * Repository entries are shared by every checkout with the same remote, so a path inside the current checkout
|
|
65
|
-
+ * is stored relative to its root. Otherwise a `~` or `$NAME` spelling that resolves now is kept as typed, so it
|
|
66
|
-
+ * is expanded each time skills load rather than frozen at add time, and any other path is stored absolute,
|
|
67
|
-
+ * under `~` when it is in the home directory.
|
|
68
|
-
+ */
|
|
69
|
-
+function persistedForm(env, source, resolvedPath, context) {
|
|
70
|
-
+ const repoRelative = context.scope === "repo" && context.repoRoot !== undefined
|
|
71
|
-
+ ? pathInside(env, context.repoRoot, resolvedPath)
|
|
72
|
-
+ : undefined;
|
|
73
|
-
+ if (repoRelative !== undefined) {
|
|
74
|
-
+ return repoRelative === "" ? "." : looksLikePath(repoRelative) ? repoRelative : `./${repoRelative}`;
|
|
75
|
-
+ }
|
|
76
|
-
+ const typed = source.trim();
|
|
77
|
-
+ if (isPortableSpelling(env, typed))
|
|
78
|
-
+ return typed;
|
|
79
|
-
+ const home = pathInside(env, env.homedir(), resolvedPath);
|
|
80
|
-
+ return home === undefined ? resolvedPath : home === "" ? "~" : `~/${home}`;
|
|
81
|
-
+}
|
|
82
|
-
+/** Variables naming a working directory: a path spelled with them means the directory it named at add time. */
|
|
83
|
-
+const directoryVariables = new Set(["PWD", "OLDPWD"]);
|
|
84
|
-
+function referencesDirectoryVariable(typed) {
|
|
85
|
-
+ return [...typed.matchAll(environmentVariableReference)].some((match) => directoryVariables.has(match[1] ?? match[2] ?? ""));
|
|
86
|
-
+}
|
|
87
|
-
+/** True for a `~` or `$NAME` path that resolves the same way from any directory in the current environment. */
|
|
88
|
-
+function isPortableSpelling(env, typed) {
|
|
89
|
-
+ const spelled = isTildePath(env, typed) || typed.search(environmentVariableReference) !== -1;
|
|
90
|
-
+ if (!spelled || !looksLikePath(typed) || referencesDirectoryVariable(typed))
|
|
91
|
-
+ return false;
|
|
92
|
-
+ const { value, unset } = expandEnvironmentVariables(env, typed);
|
|
93
|
-
+ return unset.length === 0 && isAnchoredPath(env, value.trim());
|
|
94
|
-
+}
|
|
95
|
-
+function unsetVariableHint(env, source) {
|
|
96
|
-
+ const { unset } = expandEnvironmentVariables(env, source);
|
|
97
|
-
+ if (unset.length === 0)
|
|
98
|
-
+ return undefined;
|
|
99
|
-
+ const names = unset.map((name) => `$${name}`).join(", ");
|
|
100
|
-
+ return `environment variable ${names} ${unset.length === 1 ? "is" : "are"} not set`;
|
|
101
|
-
+}
|
|
102
|
-
+function skillNotFoundMessage(env, source) {
|
|
103
|
-
+ const hint = looksLikePath(source) ? unsetVariableHint(env, source) : undefined;
|
|
104
|
-
+ return `Skill not found in the catalog or at an existing path: ${source}${hint ? ` (${hint})` : ""}`;
|
|
105
|
-
+}
|
|
106
|
-
+/** Explains why a persisted path entry could not be found, beyond its simply not existing. */
|
|
107
|
-
+function unresolvedEntryHint(env, source, scope) {
|
|
108
|
-
+ if (!looksLikePath(source))
|
|
109
|
-
+ return undefined;
|
|
110
|
-
+ const unset = unsetVariableHint(env, source);
|
|
111
|
-
+ if (unset !== undefined)
|
|
112
|
-
+ return unset;
|
|
113
|
-
+ if (isAnchoredPath(env, expandEnvironmentVariables(env, source).value.trim()))
|
|
114
|
-
+ return undefined;
|
|
115
|
-
+ return scope === "repo"
|
|
116
|
-
+ ? "relative repository paths resolve against the root of the current checkout"
|
|
117
|
-
+ : "relative paths resolve against the working directory; remove it, then add it again to store its absolute path";
|
|
118
|
-
+}
|
|
119
|
-
+function unresolvedSkillDiagnostic(env, entry) {
|
|
120
|
-
+ const hint = unresolvedEntryHint(env, entry.source, entry.scope);
|
|
121
|
-
+ return {
|
|
122
|
-
+ type: "warning",
|
|
123
|
-
+ message: `Active skill could not be resolved${hint ? `: ${hint}` : ""}`,
|
|
124
|
-
+ path: entry.source,
|
|
125
|
-
+ };
|
|
126
|
-
}
|
|
127
|
-
/** True when `path` exists and Pi's own loader finds at least one skill in it. */
|
|
128
|
-
function containsSkills(env, path, options) {
|
|
129
|
-
@@ -175,36 +290,56 @@ function containsSkills(env, path, options) {
|
|
130
|
-
return skills.length > 0;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
- * Normalizes an entry already persisted in a configuration file.
|
|
134
|
-
+ * Normalizes an entry already persisted in a configuration file, for comparison.
|
|
135
|
-
*
|
|
136
|
-
* User input is normalized before it is stored, so a stored bare value is a catalog name and is compared
|
|
137
|
-
* literally. Resolving it against whatever happens to exist in the current directory would let an unrelated
|
|
138
|
-
- * local folder make a catalog-name entry match, or block, a path entry.
|
|
139
|
-
+ * local folder make a catalog-name entry match, or block, a path entry. A path entry compares by the real path
|
|
140
|
-
+ * it names, so `~/x`, `$HOME/x`, and a repository-relative `x` all match the same absolute path.
|
|
141
|
-
*/
|
|
142
|
-
-function normalizePersistedSource(env, source, options) {
|
|
143
|
-
+function normalizePersistedSource(env, source, context) {
|
|
144
|
-
if (!source)
|
|
145
|
-
return undefined;
|
|
146
|
-
- return looksLikePath(source) ? env.resolvePath(source, options.cwd, { trim: true }) : source;
|
|
147
|
-
+ if (!looksLikePath(source))
|
|
148
|
-
+ return source;
|
|
149
|
-
+ const value = expandEnvironmentVariables(env, source).value.trim();
|
|
150
|
-
+ const path = context.scope === "repo" && context.repoRoot !== undefined && !isAnchoredPath(env, value)
|
|
151
|
-
+ ? env.path.resolve(context.repoRoot, value)
|
|
152
|
-
+ : env.resolvePath(value, context.cwd, { trim: true });
|
|
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 } : {};
|
|
158
|
-
}
|
|
159
|
-
export function updatePersistedSkill(env, action, source, scope, options) {
|
|
160
|
-
const location = configLocation(env, scope, options.cwd, options.agentDir);
|
|
161
|
-
const path = location.path;
|
|
162
|
-
if (path === undefined)
|
|
163
|
-
throw new Error(`Scope ${scope} has no persisted configuration.`);
|
|
164
|
-
+ const context = {
|
|
165
|
-
+ cwd: options.cwd,
|
|
166
|
-
+ scope,
|
|
167
|
-
+ repoRoot: scope === "repo" ? findRepoRoot(env, options.cwd) : undefined,
|
|
168
|
-
+ };
|
|
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;
|
|
176
|
-
+ const matches = (entry) => normalizePersistedSource(env, sourceOf(entry), context) === key;
|
|
177
|
-
return withSkillConfigLock(env, path, () => {
|
|
178
|
-
const config = readJson(env, path);
|
|
179
|
-
const existing = location.key === undefined ? config : config[location.key];
|
|
180
|
-
const target = location.key === undefined ? config : isObjectRecord(existing) ? existing : {};
|
|
181
|
-
const enabled = enabledEntries(target);
|
|
182
|
-
- const matched = enabled.some((entry) => normalizePersistedSource(env, sourceOf(entry), options) === source);
|
|
183
|
-
+ const matched = enabled.some(matches);
|
|
184
|
-
if (action === "remove" && !matched)
|
|
185
|
-
return false;
|
|
186
|
-
target.enabled =
|
|
187
|
-
- action === "add"
|
|
188
|
-
- ? matched
|
|
189
|
-
- ? enabled
|
|
190
|
-
- : [...enabled, source]
|
|
191
|
-
- : enabled.filter((entry) => normalizePersistedSource(env, sourceOf(entry), options) !== source);
|
|
192
|
-
+ action === "add" ? (matched ? enabled : [...enabled, source]) : enabled.filter((entry) => !matches(entry));
|
|
193
|
-
if (location.key !== undefined)
|
|
194
|
-
config[location.key] = target;
|
|
195
|
-
writeJson(env, path, config);
|
|
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
|
|
209
|
-
return [...found.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
210
|
-
}
|
|
211
|
-
async function resolveSkillSource(env, source, options) {
|
|
212
|
-
- const resolvedPath = env.resolvePath(source, options.cwd, { trim: true });
|
|
213
|
-
if (looksLikePath(source)) {
|
|
214
|
-
+ const resolvedPath = resolveSkillPath(env, source, options.cwd);
|
|
215
|
-
return { normalized: resolvedPath, resolved: env.fs.existsSync(resolvedPath) ? resolvedPath : undefined };
|
|
216
|
-
}
|
|
217
|
-
+ const resolvedPath = env.resolvePath(source, options.cwd, { trim: true });
|
|
218
|
-
// Build the catalog once, then use it both to prefer catalog names over same-named local folders and to
|
|
219
|
-
// resolve the selected skill. A bare local folder is retained as a path only when no catalog entry wins.
|
|
220
|
-
const catalog = await getSkillCatalog(env, options);
|
|
221
|
-
@@ -360,6 +499,16 @@ async function runCatalogCommand(env, command, rest, surface, options) {
|
|
222
|
-
: [query ? "No matching skills." : "No catalog skills found."],
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
+/** What `add` writes for a resolved source: a catalog name as is, a path in its {@link persistedForm}. */
|
|
226
|
-
+function persistedAddForm(env, source, target, scope, cwd) {
|
|
227
|
-
+ if (!looksLikePath(source) && target === source)
|
|
228
|
-
+ return source;
|
|
229
|
-
+ return persistedForm(env, source, target, {
|
|
230
|
-
+ cwd,
|
|
231
|
-
+ scope,
|
|
232
|
-
+ repoRoot: scope === "repo" ? findRepoRoot(env, cwd) : undefined,
|
|
233
|
-
+ });
|
|
234
|
-
+}
|
|
235
|
-
async function runMutationCommand(env, command, rest, surface, options) {
|
|
236
|
-
const scopeList = `--global|--repo${options.allowSession ? "|--session" : ""}`;
|
|
237
|
-
const source = rest.find((arg) => !arg.startsWith("--"));
|
|
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.
|
|
241
|
-
const resolution = command === "add" ? await resolveSkillSource(env, source, options) : undefined;
|
|
242
|
-
- const target = command === "remove"
|
|
243
|
-
- ? looksLikePath(source)
|
|
244
|
-
- ? env.resolvePath(source, options.cwd, { trim: true })
|
|
245
|
-
- : source
|
|
246
|
-
- : resolution?.normalized;
|
|
247
|
-
+ const target = resolution?.normalized ?? (looksLikePath(source) ? resolveSkillPath(env, source, options.cwd) : source);
|
|
248
|
-
if (!target)
|
|
249
|
-
throw new Error(`Skill source is invalid: ${source}`);
|
|
250
|
-
if (command === "add" && !resolution?.resolved) {
|
|
251
|
-
- throw new Error(`Skill not found in the catalog or at an existing path: ${source}`);
|
|
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
|
-
+ };
|
|
260
|
-
}
|
|
261
|
-
- if (scope === "session")
|
|
262
|
-
- return { exitCode: 0, lines: [], session: { action: command, source: target } };
|
|
263
|
-
const updated = command === "add"
|
|
264
|
-
- ? updatePersistedSkill(env, command, target, scope, options)
|
|
265
|
-
+ ? updatePersistedSkill(env, command, persistedAddForm(env, source, target, scope, options.cwd), scope, {
|
|
266
|
-
+ ...options,
|
|
267
|
-
+ ...resolvedPathOption(target),
|
|
268
|
-
+ })
|
|
269
|
-
: removePersistedSkill(env, source, target, scope, options);
|
|
270
|
-
if (!updated)
|
|
271
|
-
throw new Error(`Skill is not enabled for ${scope} scope: ${source}`);
|
|
272
|
-
@@ -412,12 +565,17 @@ export async function runSkillsCommand(env, args, options) {
|
|
273
|
-
/**
|
|
274
|
-
* Resolves the skills that are explicitly active for this session into concrete paths.
|
|
275
|
-
*
|
|
276
|
-
- * Entries are either paths, which must exist, or catalog names, which are looked up by name. The catalog is
|
|
277
|
-
- * built at most once per call: every caller resolves a whole entry list in one pass, so a longer-lived cache
|
|
278
|
-
- * would only need invalidating without ever being reused.
|
|
279
|
-
+ * Entries are either paths, which must exist, or catalog names, which are looked up by name. Path entries
|
|
280
|
-
+ * are expanded here, each time skills load, rather than when they are added: `~` and `$NAME` take the current
|
|
281
|
-
+ * environment, and a relative repository entry resolves against the root of the current checkout. The loader
|
|
282
|
-
+ * keeps the result until its next reload (`/reload`, `/skills reload`, or the reload `/skills add` and
|
|
283
|
-
+ * `/skills remove` trigger), which is what makes this a once-per-session expansion. The catalog is built at
|
|
284
|
-
+ * most once per call: every caller resolves a whole entry list in one pass, so a longer-lived cache would only
|
|
285
|
-
+ * need invalidating without ever being reused.
|
|
286
|
-
*/
|
|
287
|
-
export async function resolveActiveSkillPaths(env, context) {
|
|
288
|
-
const { cwd, agentDir, settingsManager, resolvedSkillResources, resolveResourcePath } = context;
|
|
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 } : {}),
|
|
300
|
-
})).map((skill) => [skill.name, skill.filePath]));
|
|
301
|
-
return catalogPathsByName.get(name);
|
|
302
|
-
};
|
|
303
|
-
+ let repoRoot;
|
|
304
|
-
+ const entryPath = (entry) => {
|
|
305
|
-
+ const value = expandEnvironmentVariables(env, entry.source).value.trim();
|
|
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;
|
|
316
|
-
+ }
|
|
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;
|
|
322
|
-
+ };
|
|
323
|
-
for (const entry of entries) {
|
|
324
|
-
- const source = sourceOf(entry);
|
|
325
|
-
- if (!source)
|
|
326
|
-
+ if (!looksLikePath(entry.source)) {
|
|
327
|
-
+ const resolved = await findCatalogSkillPath(entry.source);
|
|
328
|
-
+ if (resolved)
|
|
329
|
-
+ paths.push(resolved);
|
|
330
|
-
+ else
|
|
331
|
-
+ diagnostics.push(unresolvedSkillDiagnostic(env, entry));
|
|
332
|
-
continue;
|
|
333
|
-
- const normalized = looksLikePath(source) ? resolveResourcePath(source) : source;
|
|
334
|
-
- const resolved = looksLikePath(source)
|
|
335
|
-
- ? env.fs.existsSync(normalized)
|
|
336
|
-
- ? normalized
|
|
337
|
-
- : undefined
|
|
338
|
-
- : await findCatalogSkillPath(normalized);
|
|
339
|
-
- if (resolved) {
|
|
340
|
-
- paths.push(resolved);
|
|
341
|
-
- }
|
|
342
|
-
- else {
|
|
343
|
-
- diagnostics.push({ type: "warning", message: "Active skill could not be resolved", path: source });
|
|
344
|
-
}
|
|
345
|
-
+ const path = entryPath(entry);
|
|
346
|
-
+ if (path === undefined)
|
|
347
|
-
+ continue;
|
|
348
|
-
+ if (env.fs.existsSync(path))
|
|
349
|
-
+ paths.push(path);
|
|
350
|
-
+ else
|
|
351
|
-
+ diagnostics.push(unresolvedSkillDiagnostic(env, entry));
|
|
352
|
-
}
|
|
353
|
-
return { paths, diagnostics };
|
|
354
|
-
}
|
|
355
|
-
@@ -464,7 +642,7 @@ export async function resolveActiveSkillPaths(env, context) {
|
|
356
|
-
export async function resolveSkillEntryPath(env, context, source) {
|
|
357
|
-
const { cwd, agentDir, settingsManager, resolvedSkillResources, resolveResourcePath } = context;
|
|
358
|
-
if (looksLikePath(source)) {
|
|
359
|
-
- const normalized = resolveResourcePath(source);
|
|
360
|
-
+ const normalized = resolveResourcePath(expandEnvironmentVariables(env, source).value);
|
|
361
|
-
return { normalized, resolved: env.fs.existsSync(normalized) ? normalized : undefined };
|
|
362
|
-
}
|
|
363
|
-
const catalog = await getSkillCatalog(env, {
|
|
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;
|
|
375
|
-
}
|
|
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.
|
|
389
|
-
- const normalized = looksLikePath(session.source) ? resolveResourcePath(session.source) : 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.
|
|
392
|
-
const skillPaths = looksLikePath(session.source)
|
|
393
|
-
? []
|
|
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];
|
|
412
|
-
diff --git a/dist/core/skill-management.js b/dist/core/skill-management.js
|
|
413
|
-
index 3d18e7d..8b712ef 100644
|
|
414
|
-
--- a/dist/core/skill-management.js
|
|
415
|
-
+++ b/dist/core/skill-management.js
|
|
416
|
-
@@ -28,6 +28,7 @@ const env = {
|
|
417
|
-
fs: { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync },
|
|
418
|
-
path: { dirname, isAbsolute, join, relative, resolve, sep },
|
|
419
|
-
homedir,
|
|
420
|
-
+ environmentVariable: (name) => process.env[name],
|
|
421
|
-
execFileSync,
|
|
422
|
-
processId: () => process.pid,
|
|
423
|
-
lockSync: (directory, options) => lockfile.lockSync(directory, options),
|
|
424
|
-
diff --git a/docs/skills.md b/docs/skills.md
|
|
425
|
-
index a6adcc6..6a7cf37 100644
|
|
426
|
-
--- a/docs/skills.md
|
|
427
|
-
+++ b/docs/skills.md
|
|
428
|
-
@@ -130,6 +130,8 @@ pi skills remove browser-testing-with-devtools --repo
|
|
429
|
-
|
|
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.
|
|
431
|
-
|
|
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`.
|
|
433
|
-
+
|
|
434
|
-
Use `--no-skills` to suppress global and repository active skills; explicit `--skill` paths still load.
|
|
435
|
-
|
|
436
|
-
## Write portable frontmatter
|