@kolisachint/hoocode-agent 0.4.108 → 0.4.110
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/CHANGELOG.md +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts +79 -0
- package/dist/core/agent-session-compaction.d.ts.map +1 -0
- package/dist/core/agent-session-compaction.js +346 -0
- package/dist/core/agent-session-compaction.js.map +1 -0
- package/dist/core/agent-session-retry.d.ts +76 -0
- package/dist/core/agent-session-retry.d.ts.map +1 -0
- package/dist/core/agent-session-retry.js +192 -0
- package/dist/core/agent-session-retry.js.map +1 -0
- package/dist/core/agent-session-skills.d.ts +34 -0
- package/dist/core/agent-session-skills.d.ts.map +1 -0
- package/dist/core/agent-session-skills.js +52 -0
- package/dist/core/agent-session-skills.js.map +1 -0
- package/dist/core/agent-session-stats.d.ts +74 -0
- package/dist/core/agent-session-stats.d.ts.map +1 -0
- package/dist/core/agent-session-stats.js +187 -0
- package/dist/core/agent-session-stats.js.map +1 -0
- package/dist/core/agent-session-tree-navigation.d.ts +69 -0
- package/dist/core/agent-session-tree-navigation.d.ts.map +1 -0
- package/dist/core/agent-session-tree-navigation.js +198 -0
- package/dist/core/agent-session-tree-navigation.js.map +1 -0
- package/dist/core/agent-session.d.ts +10 -66
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +96 -806
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/context-files.d.ts +25 -0
- package/dist/core/context-files.d.ts.map +1 -0
- package/dist/core/context-files.js +97 -0
- package/dist/core/context-files.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +3 -519
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/package-resource-discovery.d.ts +62 -0
- package/dist/core/package-resource-discovery.d.ts.map +1 -0
- package/dist/core/package-resource-discovery.js +530 -0
- package/dist/core/package-resource-discovery.js.map +1 -0
- package/dist/core/resource-loader.d.ts +1 -10
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +4 -83
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts +5 -140
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +4 -81
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-storage.d.ts +29 -0
- package/dist/core/settings-storage.d.ts.map +1 -0
- package/dist/core/settings-storage.js +90 -0
- package/dist/core/settings-storage.js.map +1 -0
- package/dist/core/settings-types.d.ts +128 -0
- package/dist/core/settings-types.d.ts.map +1 -0
- package/dist/core/settings-types.js +9 -0
- package/dist/core/settings-types.js.map +1 -0
- package/examples/extensions/bash-spawn-hook.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
-
import {
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
5
|
function getEnv() {
|
|
6
6
|
if (process.platform !== "linux" || Object.keys(process.env).length > 0) {
|
|
7
7
|
return process.env;
|
|
@@ -21,15 +21,14 @@ function getEnv() {
|
|
|
21
21
|
return process.env;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
import {
|
|
24
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
25
25
|
import { globSync } from "glob";
|
|
26
|
-
import ignore from "ignore";
|
|
27
|
-
import { minimatch } from "minimatch";
|
|
28
26
|
import { CONFIG_DIR_NAME } from "../config.js";
|
|
29
27
|
import { shouldUseWindowsShell } from "../utils/child-process.js";
|
|
30
28
|
import { parseGitUrl } from "../utils/git.js";
|
|
31
29
|
import { canonicalizePath, isLocalPath } from "../utils/paths.js";
|
|
32
30
|
import { isStdoutTakenOver } from "./output-guard.js";
|
|
31
|
+
import { applyPatterns, collectAncestorAgentsSkillDirs, collectAutoExtensionEntries, collectAutoPromptEntries, collectAutoSkillEntries, collectAutoThemeEntries, collectResourceFiles, getHomeDir, hasGlobPattern, isEnabledByOverrides, isOverridePattern, RESOURCE_TYPES, SETTINGS_RESOURCE_TYPES, splitPatterns, } from "./package-resource-discovery.js";
|
|
33
32
|
const NETWORK_TIMEOUT_MS = 10000;
|
|
34
33
|
const UPDATE_CHECK_CONCURRENCY = 4;
|
|
35
34
|
const GIT_UPDATE_CONCURRENCY = 4;
|
|
@@ -60,521 +59,6 @@ function resourcePrecedenceRank(m) {
|
|
|
60
59
|
const sourceRank = m.source === "local" ? 0 : m.origin === "claude-code" ? 2 : 1;
|
|
61
60
|
return scopeBase + sourceRank;
|
|
62
61
|
}
|
|
63
|
-
const RESOURCE_TYPES = ["extensions", "skills", "prompts", "themes", "agents"];
|
|
64
|
-
const SETTINGS_RESOURCE_TYPES = ["extensions", "skills", "prompts", "themes"];
|
|
65
|
-
const FILE_PATTERNS = {
|
|
66
|
-
extensions: /\.(ts|js)$/,
|
|
67
|
-
skills: /\.md$/,
|
|
68
|
-
prompts: /\.md$/,
|
|
69
|
-
themes: /\.json$/,
|
|
70
|
-
agents: /\.md$/,
|
|
71
|
-
};
|
|
72
|
-
const IGNORE_FILE_NAMES = [".gitignore", ".ignore", ".fdignore"];
|
|
73
|
-
function toPosixPath(p) {
|
|
74
|
-
return p.split(sep).join("/");
|
|
75
|
-
}
|
|
76
|
-
function getHomeDir() {
|
|
77
|
-
return process.env.HOME || homedir();
|
|
78
|
-
}
|
|
79
|
-
function prefixIgnorePattern(line, prefix) {
|
|
80
|
-
const trimmed = line.trim();
|
|
81
|
-
if (!trimmed)
|
|
82
|
-
return null;
|
|
83
|
-
if (trimmed.startsWith("#") && !trimmed.startsWith("\\#"))
|
|
84
|
-
return null;
|
|
85
|
-
let pattern = line;
|
|
86
|
-
let negated = false;
|
|
87
|
-
if (pattern.startsWith("!")) {
|
|
88
|
-
negated = true;
|
|
89
|
-
pattern = pattern.slice(1);
|
|
90
|
-
}
|
|
91
|
-
else if (pattern.startsWith("\\!")) {
|
|
92
|
-
pattern = pattern.slice(1);
|
|
93
|
-
}
|
|
94
|
-
if (pattern.startsWith("/")) {
|
|
95
|
-
pattern = pattern.slice(1);
|
|
96
|
-
}
|
|
97
|
-
const prefixed = prefix ? `${prefix}${pattern}` : pattern;
|
|
98
|
-
return negated ? `!${prefixed}` : prefixed;
|
|
99
|
-
}
|
|
100
|
-
function addIgnoreRules(ig, dir, rootDir) {
|
|
101
|
-
const relativeDir = relative(rootDir, dir);
|
|
102
|
-
const prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : "";
|
|
103
|
-
for (const filename of IGNORE_FILE_NAMES) {
|
|
104
|
-
const ignorePath = join(dir, filename);
|
|
105
|
-
if (!existsSync(ignorePath))
|
|
106
|
-
continue;
|
|
107
|
-
try {
|
|
108
|
-
const content = readFileSync(ignorePath, "utf-8");
|
|
109
|
-
const patterns = content
|
|
110
|
-
.split(/\r?\n/)
|
|
111
|
-
.map((line) => prefixIgnorePattern(line, prefix))
|
|
112
|
-
.filter((line) => Boolean(line));
|
|
113
|
-
if (patterns.length > 0) {
|
|
114
|
-
ig.add(patterns);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
catch { }
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function isPattern(s) {
|
|
121
|
-
return s.startsWith("!") || s.startsWith("+") || s.startsWith("-") || s.includes("*") || s.includes("?");
|
|
122
|
-
}
|
|
123
|
-
function isOverridePattern(s) {
|
|
124
|
-
return s.startsWith("!") || s.startsWith("+") || s.startsWith("-");
|
|
125
|
-
}
|
|
126
|
-
function hasGlobPattern(s) {
|
|
127
|
-
return s.includes("*") || s.includes("?");
|
|
128
|
-
}
|
|
129
|
-
function splitPatterns(entries) {
|
|
130
|
-
const plain = [];
|
|
131
|
-
const patterns = [];
|
|
132
|
-
for (const entry of entries) {
|
|
133
|
-
if (isPattern(entry)) {
|
|
134
|
-
patterns.push(entry);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
plain.push(entry);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return { plain, patterns };
|
|
141
|
-
}
|
|
142
|
-
function collectFiles(dir, filePattern, skipNodeModules = true, ignoreMatcher, rootDir) {
|
|
143
|
-
const files = [];
|
|
144
|
-
if (!existsSync(dir))
|
|
145
|
-
return files;
|
|
146
|
-
const root = rootDir ?? dir;
|
|
147
|
-
const ig = ignoreMatcher ?? ignore();
|
|
148
|
-
addIgnoreRules(ig, dir, root);
|
|
149
|
-
try {
|
|
150
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
151
|
-
for (const entry of entries) {
|
|
152
|
-
if (entry.name.startsWith("."))
|
|
153
|
-
continue;
|
|
154
|
-
if (skipNodeModules && entry.name === "node_modules")
|
|
155
|
-
continue;
|
|
156
|
-
const fullPath = join(dir, entry.name);
|
|
157
|
-
let isDir = entry.isDirectory();
|
|
158
|
-
let isFile = entry.isFile();
|
|
159
|
-
if (entry.isSymbolicLink()) {
|
|
160
|
-
try {
|
|
161
|
-
const stats = statSync(fullPath);
|
|
162
|
-
isDir = stats.isDirectory();
|
|
163
|
-
isFile = stats.isFile();
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const relPath = toPosixPath(relative(root, fullPath));
|
|
170
|
-
const ignorePath = isDir ? `${relPath}/` : relPath;
|
|
171
|
-
if (ig.ignores(ignorePath))
|
|
172
|
-
continue;
|
|
173
|
-
if (isDir) {
|
|
174
|
-
files.push(...collectFiles(fullPath, filePattern, skipNodeModules, ig, root));
|
|
175
|
-
}
|
|
176
|
-
else if (isFile && filePattern.test(entry.name)) {
|
|
177
|
-
files.push(fullPath);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch {
|
|
182
|
-
// Ignore errors
|
|
183
|
-
}
|
|
184
|
-
return files;
|
|
185
|
-
}
|
|
186
|
-
function collectSkillEntries(dir, mode, ignoreMatcher, rootDir) {
|
|
187
|
-
const entries = [];
|
|
188
|
-
if (!existsSync(dir))
|
|
189
|
-
return entries;
|
|
190
|
-
const root = rootDir ?? dir;
|
|
191
|
-
const ig = ignoreMatcher ?? ignore();
|
|
192
|
-
addIgnoreRules(ig, dir, root);
|
|
193
|
-
try {
|
|
194
|
-
const dirEntries = readdirSync(dir, { withFileTypes: true });
|
|
195
|
-
for (const entry of dirEntries) {
|
|
196
|
-
if (entry.name !== "SKILL.md") {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
const fullPath = join(dir, entry.name);
|
|
200
|
-
let isFile = entry.isFile();
|
|
201
|
-
if (entry.isSymbolicLink()) {
|
|
202
|
-
try {
|
|
203
|
-
isFile = statSync(fullPath).isFile();
|
|
204
|
-
}
|
|
205
|
-
catch {
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
const relPath = toPosixPath(relative(root, fullPath));
|
|
210
|
-
if (isFile && !ig.ignores(relPath)) {
|
|
211
|
-
entries.push(fullPath);
|
|
212
|
-
return entries;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
for (const entry of dirEntries) {
|
|
216
|
-
if (entry.name.startsWith("."))
|
|
217
|
-
continue;
|
|
218
|
-
if (entry.name === "node_modules")
|
|
219
|
-
continue;
|
|
220
|
-
const fullPath = join(dir, entry.name);
|
|
221
|
-
let isDir = entry.isDirectory();
|
|
222
|
-
let isFile = entry.isFile();
|
|
223
|
-
if (entry.isSymbolicLink()) {
|
|
224
|
-
try {
|
|
225
|
-
const stats = statSync(fullPath);
|
|
226
|
-
isDir = stats.isDirectory();
|
|
227
|
-
isFile = stats.isFile();
|
|
228
|
-
}
|
|
229
|
-
catch {
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
const relPath = toPosixPath(relative(root, fullPath));
|
|
234
|
-
if (mode === "pi" && dir === root && isFile && entry.name.endsWith(".md") && !ig.ignores(relPath)) {
|
|
235
|
-
entries.push(fullPath);
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
if (!isDir)
|
|
239
|
-
continue;
|
|
240
|
-
if (ig.ignores(`${relPath}/`))
|
|
241
|
-
continue;
|
|
242
|
-
entries.push(...collectSkillEntries(fullPath, mode, ig, root));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
catch {
|
|
246
|
-
// Ignore errors
|
|
247
|
-
}
|
|
248
|
-
return entries;
|
|
249
|
-
}
|
|
250
|
-
function collectAutoSkillEntries(dir, mode) {
|
|
251
|
-
return collectSkillEntries(dir, mode);
|
|
252
|
-
}
|
|
253
|
-
function findGitRepoRoot(startDir) {
|
|
254
|
-
let dir = resolve(startDir);
|
|
255
|
-
while (true) {
|
|
256
|
-
if (existsSync(join(dir, ".git"))) {
|
|
257
|
-
return dir;
|
|
258
|
-
}
|
|
259
|
-
const parent = dirname(dir);
|
|
260
|
-
if (parent === dir) {
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
dir = parent;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function collectAncestorAgentsSkillDirs(startDir) {
|
|
267
|
-
const skillDirs = [];
|
|
268
|
-
const resolvedStartDir = resolve(startDir);
|
|
269
|
-
const gitRepoRoot = findGitRepoRoot(resolvedStartDir);
|
|
270
|
-
let dir = resolvedStartDir;
|
|
271
|
-
while (true) {
|
|
272
|
-
skillDirs.push(join(dir, ".agents", "skills"));
|
|
273
|
-
if (gitRepoRoot && dir === gitRepoRoot) {
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
const parent = dirname(dir);
|
|
277
|
-
if (parent === dir) {
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
dir = parent;
|
|
281
|
-
}
|
|
282
|
-
return skillDirs;
|
|
283
|
-
}
|
|
284
|
-
function collectAutoPromptEntries(dir) {
|
|
285
|
-
const entries = [];
|
|
286
|
-
if (!existsSync(dir))
|
|
287
|
-
return entries;
|
|
288
|
-
const ig = ignore();
|
|
289
|
-
addIgnoreRules(ig, dir, dir);
|
|
290
|
-
try {
|
|
291
|
-
const dirEntries = readdirSync(dir, { withFileTypes: true });
|
|
292
|
-
for (const entry of dirEntries) {
|
|
293
|
-
if (entry.name.startsWith("."))
|
|
294
|
-
continue;
|
|
295
|
-
if (entry.name === "node_modules")
|
|
296
|
-
continue;
|
|
297
|
-
const fullPath = join(dir, entry.name);
|
|
298
|
-
let isFile = entry.isFile();
|
|
299
|
-
if (entry.isSymbolicLink()) {
|
|
300
|
-
try {
|
|
301
|
-
isFile = statSync(fullPath).isFile();
|
|
302
|
-
}
|
|
303
|
-
catch {
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
const relPath = toPosixPath(relative(dir, fullPath));
|
|
308
|
-
if (ig.ignores(relPath))
|
|
309
|
-
continue;
|
|
310
|
-
if (isFile && entry.name.endsWith(".md")) {
|
|
311
|
-
entries.push(fullPath);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
catch {
|
|
316
|
-
// Ignore errors
|
|
317
|
-
}
|
|
318
|
-
return entries;
|
|
319
|
-
}
|
|
320
|
-
function collectAutoThemeEntries(dir) {
|
|
321
|
-
const entries = [];
|
|
322
|
-
if (!existsSync(dir))
|
|
323
|
-
return entries;
|
|
324
|
-
const ig = ignore();
|
|
325
|
-
addIgnoreRules(ig, dir, dir);
|
|
326
|
-
try {
|
|
327
|
-
const dirEntries = readdirSync(dir, { withFileTypes: true });
|
|
328
|
-
for (const entry of dirEntries) {
|
|
329
|
-
if (entry.name.startsWith("."))
|
|
330
|
-
continue;
|
|
331
|
-
if (entry.name === "node_modules")
|
|
332
|
-
continue;
|
|
333
|
-
const fullPath = join(dir, entry.name);
|
|
334
|
-
let isFile = entry.isFile();
|
|
335
|
-
if (entry.isSymbolicLink()) {
|
|
336
|
-
try {
|
|
337
|
-
isFile = statSync(fullPath).isFile();
|
|
338
|
-
}
|
|
339
|
-
catch {
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
const relPath = toPosixPath(relative(dir, fullPath));
|
|
344
|
-
if (ig.ignores(relPath))
|
|
345
|
-
continue;
|
|
346
|
-
if (isFile && entry.name.endsWith(".json")) {
|
|
347
|
-
entries.push(fullPath);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
catch {
|
|
352
|
-
// Ignore errors
|
|
353
|
-
}
|
|
354
|
-
return entries;
|
|
355
|
-
}
|
|
356
|
-
function readHooCodeManifestFile(packageJsonPath) {
|
|
357
|
-
try {
|
|
358
|
-
const content = readFileSync(packageJsonPath, "utf-8");
|
|
359
|
-
const pkg = JSON.parse(content);
|
|
360
|
-
return pkg.hoocode ?? pkg.pi ?? null;
|
|
361
|
-
}
|
|
362
|
-
catch {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
function resolveExtensionEntries(dir) {
|
|
367
|
-
const packageJsonPath = join(dir, "package.json");
|
|
368
|
-
if (existsSync(packageJsonPath)) {
|
|
369
|
-
const manifest = readHooCodeManifestFile(packageJsonPath);
|
|
370
|
-
if (manifest?.extensions?.length) {
|
|
371
|
-
const entries = [];
|
|
372
|
-
for (const extPath of manifest.extensions) {
|
|
373
|
-
const resolvedExtPath = resolve(dir, extPath);
|
|
374
|
-
if (existsSync(resolvedExtPath)) {
|
|
375
|
-
entries.push(resolvedExtPath);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
if (entries.length > 0) {
|
|
379
|
-
return entries;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
const indexTs = join(dir, "index.ts");
|
|
384
|
-
const indexJs = join(dir, "index.js");
|
|
385
|
-
if (existsSync(indexTs)) {
|
|
386
|
-
return [indexTs];
|
|
387
|
-
}
|
|
388
|
-
if (existsSync(indexJs)) {
|
|
389
|
-
return [indexJs];
|
|
390
|
-
}
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
function collectAutoExtensionEntries(dir) {
|
|
394
|
-
const entries = [];
|
|
395
|
-
if (!existsSync(dir))
|
|
396
|
-
return entries;
|
|
397
|
-
// First check if this directory itself has explicit extension entries (package.json or index)
|
|
398
|
-
const rootEntries = resolveExtensionEntries(dir);
|
|
399
|
-
if (rootEntries) {
|
|
400
|
-
return rootEntries;
|
|
401
|
-
}
|
|
402
|
-
// Otherwise, discover extensions from directory contents
|
|
403
|
-
const ig = ignore();
|
|
404
|
-
addIgnoreRules(ig, dir, dir);
|
|
405
|
-
try {
|
|
406
|
-
const dirEntries = readdirSync(dir, { withFileTypes: true });
|
|
407
|
-
for (const entry of dirEntries) {
|
|
408
|
-
if (entry.name.startsWith("."))
|
|
409
|
-
continue;
|
|
410
|
-
if (entry.name === "node_modules")
|
|
411
|
-
continue;
|
|
412
|
-
const fullPath = join(dir, entry.name);
|
|
413
|
-
let isDir = entry.isDirectory();
|
|
414
|
-
let isFile = entry.isFile();
|
|
415
|
-
if (entry.isSymbolicLink()) {
|
|
416
|
-
try {
|
|
417
|
-
const stats = statSync(fullPath);
|
|
418
|
-
isDir = stats.isDirectory();
|
|
419
|
-
isFile = stats.isFile();
|
|
420
|
-
}
|
|
421
|
-
catch {
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
const relPath = toPosixPath(relative(dir, fullPath));
|
|
426
|
-
const ignorePath = isDir ? `${relPath}/` : relPath;
|
|
427
|
-
if (ig.ignores(ignorePath))
|
|
428
|
-
continue;
|
|
429
|
-
if (isFile && (entry.name.endsWith(".ts") || entry.name.endsWith(".js"))) {
|
|
430
|
-
entries.push(fullPath);
|
|
431
|
-
}
|
|
432
|
-
else if (isDir) {
|
|
433
|
-
const resolvedEntries = resolveExtensionEntries(fullPath);
|
|
434
|
-
if (resolvedEntries) {
|
|
435
|
-
entries.push(...resolvedEntries);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
catch {
|
|
441
|
-
// Ignore errors
|
|
442
|
-
}
|
|
443
|
-
return entries;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Collect resource files from a directory based on resource type.
|
|
447
|
-
* Extensions use smart discovery (index.ts in subdirs), others use recursive collection.
|
|
448
|
-
*/
|
|
449
|
-
function collectResourceFiles(dir, resourceType) {
|
|
450
|
-
if (resourceType === "skills") {
|
|
451
|
-
return collectSkillEntries(dir, "pi");
|
|
452
|
-
}
|
|
453
|
-
if (resourceType === "extensions") {
|
|
454
|
-
return collectAutoExtensionEntries(dir);
|
|
455
|
-
}
|
|
456
|
-
return collectFiles(dir, FILE_PATTERNS[resourceType]);
|
|
457
|
-
}
|
|
458
|
-
function matchesAnyPattern(filePath, patterns, baseDir) {
|
|
459
|
-
const rel = toPosixPath(relative(baseDir, filePath));
|
|
460
|
-
const name = basename(filePath);
|
|
461
|
-
const filePathPosix = toPosixPath(filePath);
|
|
462
|
-
const isSkillFile = name === "SKILL.md";
|
|
463
|
-
const parentDir = isSkillFile ? dirname(filePath) : undefined;
|
|
464
|
-
const parentRel = isSkillFile ? toPosixPath(relative(baseDir, parentDir)) : undefined;
|
|
465
|
-
const parentName = isSkillFile ? basename(parentDir) : undefined;
|
|
466
|
-
const parentDirPosix = isSkillFile ? toPosixPath(parentDir) : undefined;
|
|
467
|
-
return patterns.some((pattern) => {
|
|
468
|
-
const normalizedPattern = toPosixPath(pattern);
|
|
469
|
-
if (minimatch(rel, normalizedPattern) ||
|
|
470
|
-
minimatch(name, normalizedPattern) ||
|
|
471
|
-
minimatch(filePathPosix, normalizedPattern)) {
|
|
472
|
-
return true;
|
|
473
|
-
}
|
|
474
|
-
if (!isSkillFile)
|
|
475
|
-
return false;
|
|
476
|
-
return (minimatch(parentRel, normalizedPattern) ||
|
|
477
|
-
minimatch(parentName, normalizedPattern) ||
|
|
478
|
-
minimatch(parentDirPosix, normalizedPattern));
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
function normalizeExactPattern(pattern) {
|
|
482
|
-
const normalized = pattern.startsWith("./") || pattern.startsWith(".\\") ? pattern.slice(2) : pattern;
|
|
483
|
-
return toPosixPath(normalized);
|
|
484
|
-
}
|
|
485
|
-
function matchesAnyExactPattern(filePath, patterns, baseDir) {
|
|
486
|
-
if (patterns.length === 0)
|
|
487
|
-
return false;
|
|
488
|
-
const rel = toPosixPath(relative(baseDir, filePath));
|
|
489
|
-
const name = basename(filePath);
|
|
490
|
-
const filePathPosix = toPosixPath(filePath);
|
|
491
|
-
const isSkillFile = name === "SKILL.md";
|
|
492
|
-
const parentDir = isSkillFile ? dirname(filePath) : undefined;
|
|
493
|
-
const parentRel = isSkillFile ? toPosixPath(relative(baseDir, parentDir)) : undefined;
|
|
494
|
-
const parentDirPosix = isSkillFile ? toPosixPath(parentDir) : undefined;
|
|
495
|
-
return patterns.some((pattern) => {
|
|
496
|
-
const normalized = normalizeExactPattern(pattern);
|
|
497
|
-
if (normalized === rel || normalized === filePathPosix) {
|
|
498
|
-
return true;
|
|
499
|
-
}
|
|
500
|
-
if (!isSkillFile)
|
|
501
|
-
return false;
|
|
502
|
-
return normalized === parentRel || normalized === parentDirPosix;
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
function getOverridePatterns(entries) {
|
|
506
|
-
return entries.filter((pattern) => pattern.startsWith("!") || pattern.startsWith("+") || pattern.startsWith("-"));
|
|
507
|
-
}
|
|
508
|
-
function isEnabledByOverrides(filePath, patterns, baseDir) {
|
|
509
|
-
const overrides = getOverridePatterns(patterns);
|
|
510
|
-
const excludes = overrides.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1));
|
|
511
|
-
const forceIncludes = overrides.filter((pattern) => pattern.startsWith("+")).map((pattern) => pattern.slice(1));
|
|
512
|
-
const forceExcludes = overrides.filter((pattern) => pattern.startsWith("-")).map((pattern) => pattern.slice(1));
|
|
513
|
-
let enabled = true;
|
|
514
|
-
if (excludes.length > 0 && matchesAnyPattern(filePath, excludes, baseDir)) {
|
|
515
|
-
enabled = false;
|
|
516
|
-
}
|
|
517
|
-
if (forceIncludes.length > 0 && matchesAnyExactPattern(filePath, forceIncludes, baseDir)) {
|
|
518
|
-
enabled = true;
|
|
519
|
-
}
|
|
520
|
-
if (forceExcludes.length > 0 && matchesAnyExactPattern(filePath, forceExcludes, baseDir)) {
|
|
521
|
-
enabled = false;
|
|
522
|
-
}
|
|
523
|
-
return enabled;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Apply patterns to paths and return a Set of enabled paths.
|
|
527
|
-
* Pattern types:
|
|
528
|
-
* - Plain patterns: include matching paths
|
|
529
|
-
* - `!pattern`: exclude matching paths
|
|
530
|
-
* - `+path`: force-include exact path (overrides exclusions)
|
|
531
|
-
* - `-path`: force-exclude exact path (overrides force-includes)
|
|
532
|
-
*/
|
|
533
|
-
function applyPatterns(allPaths, patterns, baseDir) {
|
|
534
|
-
const includes = [];
|
|
535
|
-
const excludes = [];
|
|
536
|
-
const forceIncludes = [];
|
|
537
|
-
const forceExcludes = [];
|
|
538
|
-
for (const p of patterns) {
|
|
539
|
-
if (p.startsWith("+")) {
|
|
540
|
-
forceIncludes.push(p.slice(1));
|
|
541
|
-
}
|
|
542
|
-
else if (p.startsWith("-")) {
|
|
543
|
-
forceExcludes.push(p.slice(1));
|
|
544
|
-
}
|
|
545
|
-
else if (p.startsWith("!")) {
|
|
546
|
-
excludes.push(p.slice(1));
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
includes.push(p);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
// Step 1: Apply includes (or all if no includes)
|
|
553
|
-
let result;
|
|
554
|
-
if (includes.length === 0) {
|
|
555
|
-
result = [...allPaths];
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
result = allPaths.filter((filePath) => matchesAnyPattern(filePath, includes, baseDir));
|
|
559
|
-
}
|
|
560
|
-
// Step 2: Apply excludes
|
|
561
|
-
if (excludes.length > 0) {
|
|
562
|
-
result = result.filter((filePath) => !matchesAnyPattern(filePath, excludes, baseDir));
|
|
563
|
-
}
|
|
564
|
-
// Step 3: Force-include (add back from allPaths, overriding exclusions)
|
|
565
|
-
if (forceIncludes.length > 0) {
|
|
566
|
-
for (const filePath of allPaths) {
|
|
567
|
-
if (!result.includes(filePath) && matchesAnyExactPattern(filePath, forceIncludes, baseDir)) {
|
|
568
|
-
result.push(filePath);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
// Step 4: Force-exclude (remove even if included or force-included)
|
|
573
|
-
if (forceExcludes.length > 0) {
|
|
574
|
-
result = result.filter((filePath) => !matchesAnyExactPattern(filePath, forceExcludes, baseDir));
|
|
575
|
-
}
|
|
576
|
-
return new Set(result);
|
|
577
|
-
}
|
|
578
62
|
export class DefaultPackageManager {
|
|
579
63
|
cwd;
|
|
580
64
|
agentDir;
|