@zew1me/pi-skills-patch 0.1.1-alpha.183 → 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 +11 -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
|
@@ -62,10 +62,10 @@ index 0345dcb..3a90de3 100644
|
|
|
62
62
|
const resolved = this.resolveResourcePath(p);
|
|
63
63
|
diff --git a/dist/core/skill-management-core.js b/dist/core/skill-management-core.js
|
|
64
64
|
new file mode 100644
|
|
65
|
-
index 0000000..
|
|
65
|
+
index 0000000..dc70fae
|
|
66
66
|
--- /dev/null
|
|
67
67
|
+++ b/dist/core/skill-management-core.js
|
|
68
|
-
@@ -0,0 +1,
|
|
68
|
+
@@ -0,0 +1,749 @@
|
|
69
69
|
+/**
|
|
70
70
|
+ * Opt-in skill management for the patched Pi runtime.
|
|
71
71
|
+ *
|
|
@@ -259,9 +259,13 @@ index 0000000..0b4ae56
|
|
|
259
259
|
+function resolveSkillPath(env, source, cwd) {
|
|
260
260
|
+ return env.resolvePath(expandEnvironmentVariables(env, source).value, cwd, { trim: true });
|
|
261
261
|
+}
|
|
262
|
+
+/** Pi expands a tilde followed by a backslash only on Windows. */
|
|
263
|
+
+function isTildePath(env, value) {
|
|
264
|
+
+ return value === "~" || value.startsWith("~/") || (env.path.sep === "\\" && value.startsWith("~\\"));
|
|
265
|
+
+}
|
|
262
266
|
+/** True for a path that does not depend on the directory it is read from: absolute, `~`, or a `file:` URL. */
|
|
263
267
|
+function isAnchoredPath(env, value) {
|
|
264
|
-
+ return env.path.isAbsolute(value) ||
|
|
268
|
+
+ return env.path.isAbsolute(value) || isTildePath(env, value) || value.startsWith("file:");
|
|
265
269
|
+}
|
|
266
270
|
+/** The checkout root for `cwd`; relative repository entries resolve against it. */
|
|
267
271
|
+function findRepoRoot(env, cwd) {
|
|
@@ -303,7 +307,7 @@ index 0000000..0b4ae56
|
|
|
303
307
|
+}
|
|
304
308
|
+/** True for a `~` or `$NAME` path that resolves the same way from any directory in the current environment. */
|
|
305
309
|
+function isPortableSpelling(env, typed) {
|
|
306
|
-
+ const spelled =
|
|
310
|
+
+ const spelled = isTildePath(env, typed) || typed.search(environmentVariableReference) !== -1;
|
|
307
311
|
+ if (!spelled || !looksLikePath(typed) || referencesDirectoryVariable(typed))
|
|
308
312
|
+ return false;
|
|
309
313
|
+ const { value, unset } = expandEnvironmentVariables(env, typed);
|
|
@@ -372,6 +376,10 @@ index 0000000..0b4ae56
|
|
|
372
376
|
+ : env.resolvePath(value, context.cwd, { trim: true });
|
|
373
377
|
+ return env.fs.existsSync(path) ? env.fs.realpathSync(path) : path;
|
|
374
378
|
+}
|
|
379
|
+
+/** Supplies a pre-resolved identity for a path, leaving catalog names as literal keys. */
|
|
380
|
+
+function resolvedPathOption(source) {
|
|
381
|
+
+ return looksLikePath(source) ? { resolvedPath: source } : {};
|
|
382
|
+
+}
|
|
375
383
|
+export function updatePersistedSkill(env, action, source, scope, options) {
|
|
376
384
|
+ const location = configLocation(env, scope, options.cwd, options.agentDir);
|
|
377
385
|
+ const path = location.path;
|
|
@@ -382,7 +390,13 @@ index 0000000..0b4ae56
|
|
|
382
390
|
+ scope,
|
|
383
391
|
+ repoRoot: scope === "repo" ? findRepoRoot(env, options.cwd) : undefined,
|
|
384
392
|
+ };
|
|
385
|
-
+
|
|
393
|
+
+ // Expand only raw spellings, not a command's already-resolved path, which can contain literal `$`.
|
|
394
|
+
+ const { resolvedPath } = options;
|
|
395
|
+
+ const key = resolvedPath === undefined
|
|
396
|
+
+ ? normalizePersistedSource(env, source, context)
|
|
397
|
+
+ : env.fs.existsSync(resolvedPath)
|
|
398
|
+
+ ? env.fs.realpathSync(resolvedPath)
|
|
399
|
+
+ : resolvedPath;
|
|
386
400
|
+ const matches = (entry) => normalizePersistedSource(env, sourceOf(entry), context) === key;
|
|
387
401
|
+ return withSkillConfigLock(env, path, () => {
|
|
388
402
|
+ const config = readJson(env, path);
|
|
@@ -412,7 +426,10 @@ index 0000000..0b4ae56
|
|
|
412
426
|
+ const candidates = looksLikePath(source)
|
|
413
427
|
+ ? [target]
|
|
414
428
|
+ : [target, source, env.resolvePath(source, options.cwd, { trim: true })];
|
|
415
|
-
+ return [...new Set(candidates)].some((candidate) => updatePersistedSkill(env, "remove", candidate, scope,
|
|
429
|
+
+ return [...new Set(candidates)].some((candidate) => updatePersistedSkill(env, "remove", candidate, scope, {
|
|
430
|
+
+ ...options,
|
|
431
|
+
+ ...resolvedPathOption(candidate),
|
|
432
|
+
+ }));
|
|
416
433
|
+}
|
|
417
434
|
+export function getActiveSkillEntries(env, { cwd, agentDir, strict = false, onWarn }) {
|
|
418
435
|
+ const entries = [];
|
|
@@ -572,20 +589,24 @@ index 0000000..0b4ae56
|
|
|
572
589
|
+ // Removal never consults the catalog, whose package resolution can install missing packages. A stored bare
|
|
573
590
|
+ // value is a catalog name, so removing a bare name tries that literal name first and its resolved path after.
|
|
574
591
|
+ const resolution = command === "add" ? await resolveSkillSource(env, source, options) : undefined;
|
|
575
|
-
+ const target =
|
|
576
|
-
+ ? looksLikePath(source)
|
|
577
|
-
+ ? resolveSkillPath(env, source, options.cwd)
|
|
578
|
-
+ : source
|
|
579
|
-
+ : resolution?.normalized;
|
|
592
|
+
+ const target = resolution?.normalized ?? (looksLikePath(source) ? resolveSkillPath(env, source, options.cwd) : source);
|
|
580
593
|
+ if (!target)
|
|
581
594
|
+ throw new Error(`Skill source is invalid: ${source}`);
|
|
582
595
|
+ if (command === "add" && !resolution?.resolved) {
|
|
583
596
|
+ throw new Error(skillNotFoundMessage(env, source));
|
|
584
597
|
+ }
|
|
585
|
-
+ if (scope === "session")
|
|
586
|
-
+ return {
|
|
598
|
+
+ if (scope === "session") {
|
|
599
|
+
+ return {
|
|
600
|
+
+ exitCode: 0,
|
|
601
|
+
+ lines: [],
|
|
602
|
+
+ session: { action: command, source: target, ...(resolution?.resolved ? { resolved: resolution.resolved } : {}) },
|
|
603
|
+
+ };
|
|
604
|
+
+ }
|
|
587
605
|
+ const updated = command === "add"
|
|
588
|
-
+ ? updatePersistedSkill(env, command, persistedAddForm(env, source, target, scope, options.cwd), scope,
|
|
606
|
+
+ ? updatePersistedSkill(env, command, persistedAddForm(env, source, target, scope, options.cwd), scope, {
|
|
607
|
+
+ ...options,
|
|
608
|
+
+ ...resolvedPathOption(target),
|
|
609
|
+
+ })
|
|
589
610
|
+ : removePersistedSkill(env, source, target, scope, options);
|
|
590
611
|
+ if (!updated)
|
|
591
612
|
+ throw new Error(`Skill is not enabled for ${scope} scope: ${source}`);
|
|
@@ -622,6 +643,7 @@ index 0000000..0b4ae56
|
|
|
622
643
|
+ */
|
|
623
644
|
+export async function resolveActiveSkillPaths(env, context) {
|
|
624
645
|
+ const { cwd, agentDir, settingsManager, resolvedSkillResources, resolveResourcePath } = context;
|
|
646
|
+
+ const manager = settingsManager ?? env.createSettingsManager(cwd, agentDir);
|
|
625
647
|
+ const paths = [];
|
|
626
648
|
+ const diagnostics = [];
|
|
627
649
|
+ const entries = getActiveSkillEntries(env, {
|
|
@@ -634,7 +656,7 @@ index 0000000..0b4ae56
|
|
|
634
656
|
+ catalogPathsByName ??= new Map((await getSkillCatalog(env, {
|
|
635
657
|
+ cwd,
|
|
636
658
|
+ agentDir,
|
|
637
|
-
+
|
|
659
|
+
+ settingsManager: manager,
|
|
638
660
|
+ ...(resolvedSkillResources ? { resolvedSkillResources } : {}),
|
|
639
661
|
+ })).map((skill) => [skill.name, skill.filePath]));
|
|
640
662
|
+ return catalogPathsByName.get(name);
|
|
@@ -642,12 +664,22 @@ index 0000000..0b4ae56
|
|
|
642
664
|
+ let repoRoot;
|
|
643
665
|
+ const entryPath = (entry) => {
|
|
644
666
|
+ const value = expandEnvironmentVariables(env, entry.source).value.trim();
|
|
645
|
-
+ if (entry.scope
|
|
646
|
-
+
|
|
647
|
-
+
|
|
648
|
-
+
|
|
667
|
+
+ if (entry.scope !== "repo" || isAnchoredPath(env, value))
|
|
668
|
+
+ return resolveResourcePath(value);
|
|
669
|
+
+ // Entries follow the remote across clones, but trust belongs to the current checkout.
|
|
670
|
+
+ if (!manager.isProjectTrusted()) {
|
|
671
|
+
+ diagnostics.push({
|
|
672
|
+
+ type: "warning",
|
|
673
|
+
+ message: "Repository-relative active skill requires project trust",
|
|
674
|
+
+ path: entry.source,
|
|
675
|
+
+ });
|
|
676
|
+
+ return undefined;
|
|
649
677
|
+ }
|
|
650
|
-
+
|
|
678
|
+
+ repoRoot ??= { value: findRepoRoot(env, cwd) };
|
|
679
|
+
+ if (repoRoot.value !== undefined)
|
|
680
|
+
+ return env.path.resolve(repoRoot.value, value);
|
|
681
|
+
+ diagnostics.push(unresolvedSkillDiagnostic(env, entry));
|
|
682
|
+
+ return undefined;
|
|
651
683
|
+ };
|
|
652
684
|
+ for (const entry of entries) {
|
|
653
685
|
+ if (!looksLikePath(entry.source)) {
|
|
@@ -659,6 +691,8 @@ index 0000000..0b4ae56
|
|
|
659
691
|
+ continue;
|
|
660
692
|
+ }
|
|
661
693
|
+ const path = entryPath(entry);
|
|
694
|
+
+ if (path === undefined)
|
|
695
|
+
+ continue;
|
|
662
696
|
+ if (env.fs.existsSync(path))
|
|
663
697
|
+ paths.push(path);
|
|
664
698
|
+ else
|
|
@@ -693,15 +727,14 @@ index 0000000..0b4ae56
|
|
|
693
727
|
+ * Returns the line to show, or `undefined` when it has already reported an error. The list is mutated in
|
|
694
728
|
+ * place because the loader holds the same array.
|
|
695
729
|
+ */
|
|
696
|
-
+
|
|
697
|
-
+ const { cwd, agentDir,
|
|
730
|
+
+function applySessionSkillChange(env, session, context) {
|
|
731
|
+
+ const { cwd, agentDir, additionalSkillPaths } = context;
|
|
698
732
|
+ if (!additionalSkillPaths) {
|
|
699
733
|
+ context.showError("Session skill activation is unavailable for this resource loader.");
|
|
700
734
|
+ return undefined;
|
|
701
735
|
+ }
|
|
702
736
|
+ if (session.action === "add") {
|
|
703
|
-
+ const
|
|
704
|
-
+ const { resolved } = await resolveSkillEntryPath(env, pathContext, session.source);
|
|
737
|
+
+ const { resolved } = session;
|
|
705
738
|
+ if (!resolved) {
|
|
706
739
|
+ context.showError(`Skill not found in the catalog: ${session.source}`);
|
|
707
740
|
+ return undefined;
|
|
@@ -710,18 +743,15 @@ index 0000000..0b4ae56
|
|
|
710
743
|
+ additionalSkillPaths.push(resolved);
|
|
711
744
|
+ return `Enabled ${resolved} for this session.`;
|
|
712
745
|
+ }
|
|
713
|
-
+ // Removal must not resolve packages
|
|
714
|
-
+ //
|
|
715
|
-
+ const normalized = looksLikePath(session.source)
|
|
716
|
-
+ ? resolveResourcePath(expandEnvironmentVariables(env, session.source).value)
|
|
717
|
-
+ : session.source;
|
|
746
|
+
+ // Removal must not resolve packages or re-expand the already-normalized path.
|
|
747
|
+
+ // Recover bare names from the already-enabled paths instead.
|
|
718
748
|
+ const skillPaths = looksLikePath(session.source)
|
|
719
749
|
+ ? []
|
|
720
750
|
+ : env
|
|
721
751
|
+ .loadSkills({ cwd, agentDir, skillPaths: additionalSkillPaths, includeDefaults: false })
|
|
722
752
|
+ .skills.filter((skill) => skill.name === session.source)
|
|
723
753
|
+ .map((skill) => skill.filePath);
|
|
724
|
-
+ const direct = (path) => path === session.source ||
|
|
754
|
+
+ const direct = (path) => path === session.source || skillPaths.includes(path);
|
|
725
755
|
+ // A bare name added as a local path stays removable by that name after the path is deleted, but only when
|
|
726
756
|
+ // nothing matches it directly.
|
|
727
757
|
+ const localPath = looksLikePath(session.source) ? undefined : env.resolvePath(session.source, cwd, { trim: true });
|
|
@@ -765,7 +795,7 @@ index 0000000..0b4ae56
|
|
|
765
795
|
+ }
|
|
766
796
|
+ let lines = result.lines;
|
|
767
797
|
+ if (result.session) {
|
|
768
|
-
+ const line =
|
|
798
|
+
+ const line = applySessionSkillChange(env, result.session, context);
|
|
769
799
|
+ if (line === undefined)
|
|
770
800
|
+ return;
|
|
771
801
|
+ lines = [line];
|
|
@@ -1020,7 +1050,7 @@ index 7827bce..5df7c45 100644
|
|
|
1020
1050
|
if (this.session.isStreaming) {
|
|
1021
1051
|
this.showWarning("Wait for the current response to finish before reloading.");
|
|
1022
1052
|
diff --git a/docs/skills.md b/docs/skills.md
|
|
1023
|
-
index 19d2bf2..
|
|
1053
|
+
index 19d2bf2..6a7cf37 100644
|
|
1024
1054
|
--- a/docs/skills.md
|
|
1025
1055
|
+++ b/docs/skills.md
|
|
1026
1056
|
@@ -40,9 +40,11 @@ Use relative paths from the skill directory when referring to bundled files. Pi
|
|
@@ -1114,7 +1144,7 @@ index 19d2bf2..2a17b24 100644
|
|
|
1114
1144
|
+
|
|
1115
1145
|
+`--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.
|
|
1116
1146
|
+
|
|
1117
|
-
+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
|
|
1147
|
+
+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`.
|
|
1118
1148
|
+
|
|
1119
1149
|
+Use `--no-skills` to suppress global and repository active skills; explicit `--skill` paths still load.
|
|
1120
1150
|
+
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
02325568295034ef970414e4298ca4927373e96d715ce68213c82b31ea207d3e dist/main.js
|
|
4
4
|
5847a2578696c49c2af212f5b7a9847e8fbfe47c12168d706664aaa47af84b8b 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
|
a3e0c75e3d4c074cf3839d0660cdc866541a20b013f1da6221d7036f0f12c4e1 dist/bundle/rpc-entry.js
|
|
10
10
|
e79626f2dd6f94aa45d30f3fa63cd84319a6eefcd150b353cfaf274366926774 dist/bundle/cli.js
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
353afa95ba9b317a042571e92dd093d3bfd31fa7089311730a46346635ea32ff dist/core/resource-loader.js
|
|
2
|
+
6b212fda1510fcbb86fc9c53fc63335b1e8c6a03710223b53862d93e221afa73 dist/core/slash-commands.js
|
|
3
|
+
02325568295034ef970414e4298ca4927373e96d715ce68213c82b31ea207d3e dist/main.js
|
|
4
|
+
5847a2578696c49c2af212f5b7a9847e8fbfe47c12168d706664aaa47af84b8b 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
|
+
a3e0c75e3d4c074cf3839d0660cdc866541a20b013f1da6221d7036f0f12c4e1 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
|
+
|