@henryqw/pi-add-dir 0.1.4 → 0.1.5
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/extensions/add-dir-helpers.ts +33 -13
- package/extensions/add-dir.ts +10 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
1
|
+
import { closeSync, openSync, readdirSync, readFileSync, readSync, realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { readdir } from "node:fs/promises";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
@@ -128,6 +128,29 @@ function skillDescription(content: string): string {
|
|
|
128
128
|
return value.replace(/^("|')|("|')$/g, "").trim() || "No description";
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// ponytail: 8KB head is enough for SKILL.md frontmatter descriptions; full-body reads stay in scanDirContext
|
|
132
|
+
function readHead(filePath: string, bytes = 8192): string | null {
|
|
133
|
+
let fd: number | undefined;
|
|
134
|
+
try {
|
|
135
|
+
fd = openSync(filePath, "r");
|
|
136
|
+
const buffer = Buffer.alloc(bytes);
|
|
137
|
+
const bytesRead = readSync(fd, buffer, 0, bytes, 0);
|
|
138
|
+
return buffer.toString("utf8", 0, bytesRead);
|
|
139
|
+
} catch {
|
|
140
|
+
return null;
|
|
141
|
+
} finally {
|
|
142
|
+
if (fd !== undefined) closeSync(fd);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ponytail: 8KB head covers typical frontmatter; falls back to full read only when opener present but closer missing (rare)
|
|
147
|
+
function readSkillFrontmatter(filePath: string): string | null {
|
|
148
|
+
const head = readHead(filePath, 8192);
|
|
149
|
+
if (head === null || !/^---\r?\n/.test(head)) return head;
|
|
150
|
+
if (/^---\r?\n[\s\S]*\r?\n---(?:\r?\n|$)/.test(head)) return head;
|
|
151
|
+
return readFileSafe(filePath);
|
|
152
|
+
}
|
|
153
|
+
|
|
131
154
|
export function buildContextInjection(dirs: AddedDir[]): string {
|
|
132
155
|
if (dirs.length === 0) return "";
|
|
133
156
|
|
|
@@ -138,23 +161,20 @@ export function buildContextInjection(dirs: AddedDir[]): string {
|
|
|
138
161
|
|
|
139
162
|
const registeredSkills = new Set<string>();
|
|
140
163
|
for (const dir of dirs) {
|
|
141
|
-
const ctx = scanDirContext(dir.absolutePath);
|
|
142
|
-
const skills = [...ctx.skills].filter(([name]) => {
|
|
143
|
-
if (registeredSkills.has(name)) return false;
|
|
144
|
-
registeredSkills.add(name);
|
|
145
|
-
return true;
|
|
146
|
-
});
|
|
147
164
|
sections.push(`### ${dir.label} - \`${dir.absolutePath}\``);
|
|
148
165
|
|
|
149
|
-
|
|
150
|
-
if (
|
|
166
|
+
const agentsMd = readContextFile(dir.absolutePath, "AGENTS.md");
|
|
167
|
+
if (agentsMd) sections.push(`\n#### AGENTS.md (from ${dir.label})\n${agentsMd}`);
|
|
168
|
+
const claudeMd = readContextFile(dir.absolutePath, "CLAUDE.md");
|
|
169
|
+
if (claudeMd) sections.push(`\n#### CLAUDE.md (from ${dir.label})\n${claudeMd}`);
|
|
151
170
|
|
|
171
|
+
const skills = skillFiles(dir.absolutePath).filter((skill) => !registeredSkills.has(skill.name));
|
|
152
172
|
if (skills.length > 0) {
|
|
153
173
|
sections.push(`\n#### Skills from ${dir.label} (registered as /skill:name commands):`);
|
|
154
|
-
for (const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
);
|
|
174
|
+
for (const skill of skills) {
|
|
175
|
+
registeredSkills.add(skill.name);
|
|
176
|
+
const description = skillDescription(readSkillFrontmatter(skill.path) ?? "");
|
|
177
|
+
sections.push(`- **${skill.name}**: ${description} - use \`/skill:${skill.name}\` or read \`${skill.path}\``);
|
|
158
178
|
}
|
|
159
179
|
}
|
|
160
180
|
}
|
package/extensions/add-dir.ts
CHANGED
|
@@ -170,6 +170,16 @@ export default function addDirExtension(pi: ExtensionAPI): void {
|
|
|
170
170
|
hasNewSkills: false,
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
+
const overlap = addedDirs.find(
|
|
174
|
+
(dir) => isWithinDir(dir.absolutePath, absolutePath) || isWithinDir(absolutePath, dir.absolutePath),
|
|
175
|
+
);
|
|
176
|
+
if (overlap) {
|
|
177
|
+
return {
|
|
178
|
+
ok: false,
|
|
179
|
+
message: `Directory overlaps already-added directory: ${overlap.absolutePath}`,
|
|
180
|
+
hasNewSkills: false,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
173
183
|
|
|
174
184
|
const context = scanDirContext(absolutePath);
|
|
175
185
|
const label = basename(absolutePath) || absolutePath;
|
|
@@ -382,7 +392,6 @@ export default function addDirExtension(pi: ExtensionAPI): void {
|
|
|
382
392
|
renderCall(args, theme) {
|
|
383
393
|
let text = theme.fg("toolTitle", theme.bold("search_external_files "));
|
|
384
394
|
text += theme.fg("accent", `"${cleanPath(args.pattern)}"`);
|
|
385
|
-
text += theme.fg("dim", ` across ${addedDirs.length} dir(s)`);
|
|
386
395
|
return new Text(text, 0, 0);
|
|
387
396
|
},
|
|
388
397
|
|