@juicesharp/rpiv-args 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/args.ts +57 -6
  2. package/package.json +1 -1
package/args.ts CHANGED
@@ -24,7 +24,9 @@
24
24
  * template literal below.
25
25
  */
26
26
 
27
- import { readFileSync } from "node:fs";
27
+ import { existsSync, readFileSync } from "node:fs";
28
+ import { homedir } from "node:os";
29
+ import { dirname, join, resolve } from "node:path";
28
30
  import {
29
31
  type BeforeAgentStartEvent,
30
32
  type BeforeAgentStartEventResult,
@@ -124,13 +126,62 @@ export function invalidateSkillIndex(): void {
124
126
  skillIndex = null;
125
127
  }
126
128
 
127
- /** Build the name→path index by asking Pi for its currently-loaded skills. */
129
+ function findGitRepoRoot(startDir: string): string | null {
130
+ let dir = resolve(startDir);
131
+ while (true) {
132
+ if (existsSync(join(dir, ".git"))) return dir;
133
+ const parent = dirname(dir);
134
+ if (parent === dir) return null;
135
+ dir = parent;
136
+ }
137
+ }
138
+
139
+ function collectAncestorAgentsSkillDirs(startDir: string): string[] {
140
+ const skillDirs: string[] = [];
141
+ const gitRepoRoot = findGitRepoRoot(startDir);
142
+ let dir = resolve(startDir);
143
+ while (true) {
144
+ skillDirs.push(join(dir, ".agents", "skills"));
145
+ if (gitRepoRoot && dir === gitRepoRoot) break;
146
+ const parent = dirname(dir);
147
+ if (parent === dir) break;
148
+ dir = parent;
149
+ }
150
+ return skillDirs;
151
+ }
152
+
153
+ function addExistingPath(paths: string[], seen: Set<string>, path: string): void {
154
+ const resolved = resolve(path);
155
+ if (!existsSync(resolved) || seen.has(resolved)) return;
156
+ seen.add(resolved);
157
+ paths.push(resolved);
158
+ }
159
+
160
+ /** Collect Pi's default skill locations in collision-precedence order. */
161
+ export function collectDefaultSkillPaths(cwd: string, agentDir: string): string[] {
162
+ const paths: string[] = [];
163
+ const seen = new Set<string>();
164
+ const userAgentsSkillsDir = join(homedir(), ".agents", "skills");
165
+
166
+ addExistingPath(paths, seen, join(resolve(cwd), ".pi", "skills"));
167
+ for (const dir of collectAncestorAgentsSkillDirs(cwd)) {
168
+ if (resolve(dir) !== resolve(userAgentsSkillsDir)) addExistingPath(paths, seen, dir);
169
+ }
170
+ addExistingPath(paths, seen, join(agentDir, "skills"));
171
+ addExistingPath(paths, seen, userAgentsSkillsDir);
172
+
173
+ return paths;
174
+ }
175
+
176
+ /** Build the name→path index by asking Pi for its default skill locations. */
128
177
  function buildSkillIndex(): Map<string, SkillIndexEntry> {
178
+ const cwd = process.cwd();
179
+ const agentDir = getAgentDir();
129
180
  const { skills } = loadSkills({
130
- cwd: process.cwd(),
131
- agentDir: getAgentDir(),
132
- skillPaths: [],
133
- includeDefaults: true,
181
+ cwd,
182
+ agentDir,
183
+ skillPaths: collectDefaultSkillPaths(cwd, agentDir),
184
+ includeDefaults: false,
134
185
  });
135
186
  const index = new Map<string, SkillIndexEntry>();
136
187
  for (const s of skills as Skill[]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-args",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Pi extension. Shell-style $1 and $ARGUMENTS placeholders, expanded into your Pi skills at invocation.",
5
5
  "keywords": [
6
6
  "pi-package",