@cleocode/caamp 1.7.1 → 1.8.1
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/README.md +0 -0
- package/dist/chunk-CPHF5IM4.js +766 -0
- package/dist/chunk-CPHF5IM4.js.map +1 -0
- package/dist/{chunk-6T3TJQFF.js → chunk-LDTYDQGR.js} +162 -837
- package/dist/chunk-LDTYDQGR.js.map +1 -0
- package/dist/cli.d.ts +0 -0
- package/dist/cli.js +20 -18
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +195 -12
- package/dist/index.js +201 -47
- package/dist/index.js.map +1 -1
- package/dist/injector-TIUEM4X2.js +19 -0
- package/dist/injector-TIUEM4X2.js.map +1 -0
- package/package.json +7 -7
- package/providers/registry.json +0 -0
- package/dist/chunk-6T3TJQFF.js.map +0 -1
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/core/instructions/injector.ts
|
|
8
|
+
import { existsSync as existsSync2 } from "fs";
|
|
9
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
10
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
11
|
+
|
|
12
|
+
// src/core/registry/providers.ts
|
|
13
|
+
import { readFileSync } from "fs";
|
|
14
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
|
|
17
|
+
// src/core/paths/standard.ts
|
|
18
|
+
import { existsSync } from "fs";
|
|
19
|
+
import { homedir as homedir2 } from "os";
|
|
20
|
+
import { dirname, join as join2 } from "path";
|
|
21
|
+
|
|
22
|
+
// src/core/platform-paths.ts
|
|
23
|
+
import envPaths from "env-paths";
|
|
24
|
+
import { arch, homedir, hostname, platform, release } from "os";
|
|
25
|
+
import { isAbsolute, join, resolve } from "path";
|
|
26
|
+
var APP_NAME = "agents";
|
|
27
|
+
function resolveAgentsHomeOverride(value) {
|
|
28
|
+
if (value === void 0) return void 0;
|
|
29
|
+
const trimmed = value.trim();
|
|
30
|
+
if (trimmed.length === 0) return void 0;
|
|
31
|
+
if (trimmed === "~") return homedir();
|
|
32
|
+
if (trimmed.startsWith("~/")) return join(homedir(), trimmed.slice(2));
|
|
33
|
+
if (isAbsolute(trimmed)) return resolve(trimmed);
|
|
34
|
+
return resolve(homedir(), trimmed);
|
|
35
|
+
}
|
|
36
|
+
var _paths = null;
|
|
37
|
+
var _sysInfo = null;
|
|
38
|
+
var _lastAgentsHome = void 0;
|
|
39
|
+
function getPlatformPaths() {
|
|
40
|
+
const currentAgentsHome = process.env["AGENTS_HOME"];
|
|
41
|
+
if (_paths && currentAgentsHome !== _lastAgentsHome) {
|
|
42
|
+
_paths = null;
|
|
43
|
+
_sysInfo = null;
|
|
44
|
+
}
|
|
45
|
+
if (_paths) return _paths;
|
|
46
|
+
const ep = envPaths(APP_NAME, { suffix: "" });
|
|
47
|
+
_lastAgentsHome = currentAgentsHome;
|
|
48
|
+
_paths = {
|
|
49
|
+
data: resolveAgentsHomeOverride(currentAgentsHome) ?? ep.data,
|
|
50
|
+
config: ep.config,
|
|
51
|
+
cache: ep.cache,
|
|
52
|
+
log: ep.log,
|
|
53
|
+
temp: ep.temp
|
|
54
|
+
};
|
|
55
|
+
return _paths;
|
|
56
|
+
}
|
|
57
|
+
function getSystemInfo() {
|
|
58
|
+
if (_sysInfo) return _sysInfo;
|
|
59
|
+
const paths = getPlatformPaths();
|
|
60
|
+
_sysInfo = {
|
|
61
|
+
platform: platform(),
|
|
62
|
+
arch: arch(),
|
|
63
|
+
release: release(),
|
|
64
|
+
hostname: hostname(),
|
|
65
|
+
nodeVersion: process.version,
|
|
66
|
+
paths
|
|
67
|
+
};
|
|
68
|
+
return _sysInfo;
|
|
69
|
+
}
|
|
70
|
+
function _resetPlatformPathsCache() {
|
|
71
|
+
_paths = null;
|
|
72
|
+
_sysInfo = null;
|
|
73
|
+
_lastAgentsHome = void 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/core/paths/standard.ts
|
|
77
|
+
function getPlatformLocations() {
|
|
78
|
+
const home = homedir2();
|
|
79
|
+
const platform2 = process.platform;
|
|
80
|
+
if (platform2 === "win32") {
|
|
81
|
+
const appData = process.env["APPDATA"] ?? join2(home, "AppData", "Roaming");
|
|
82
|
+
return {
|
|
83
|
+
home,
|
|
84
|
+
config: appData,
|
|
85
|
+
vscodeConfig: join2(appData, "Code", "User"),
|
|
86
|
+
zedConfig: join2(appData, "Zed"),
|
|
87
|
+
claudeDesktopConfig: join2(appData, "Claude"),
|
|
88
|
+
applications: []
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (platform2 === "darwin") {
|
|
92
|
+
const config2 = process.env["XDG_CONFIG_HOME"] ?? join2(home, ".config");
|
|
93
|
+
return {
|
|
94
|
+
home,
|
|
95
|
+
config: config2,
|
|
96
|
+
vscodeConfig: join2(home, "Library", "Application Support", "Code", "User"),
|
|
97
|
+
zedConfig: join2(home, "Library", "Application Support", "Zed"),
|
|
98
|
+
claudeDesktopConfig: join2(home, "Library", "Application Support", "Claude"),
|
|
99
|
+
applications: ["/Applications", join2(home, "Applications")]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const config = process.env["XDG_CONFIG_HOME"] ?? join2(home, ".config");
|
|
103
|
+
return {
|
|
104
|
+
home,
|
|
105
|
+
config,
|
|
106
|
+
vscodeConfig: join2(config, "Code", "User"),
|
|
107
|
+
zedConfig: join2(config, "zed"),
|
|
108
|
+
claudeDesktopConfig: join2(config, "Claude"),
|
|
109
|
+
applications: []
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function getAgentsHome() {
|
|
113
|
+
return getPlatformPaths().data;
|
|
114
|
+
}
|
|
115
|
+
function getProjectAgentsDir(projectRoot = process.cwd()) {
|
|
116
|
+
return join2(projectRoot, ".agents");
|
|
117
|
+
}
|
|
118
|
+
function resolveProjectPath(relativePath, projectDir = process.cwd()) {
|
|
119
|
+
return join2(projectDir, relativePath);
|
|
120
|
+
}
|
|
121
|
+
function getCanonicalSkillsDir() {
|
|
122
|
+
return join2(getAgentsHome(), "skills");
|
|
123
|
+
}
|
|
124
|
+
function getLockFilePath() {
|
|
125
|
+
return join2(getAgentsHome(), ".caamp-lock.json");
|
|
126
|
+
}
|
|
127
|
+
function getAgentsMcpDir(scope = "global", projectDir) {
|
|
128
|
+
if (scope === "global") return join2(getAgentsHome(), "mcp");
|
|
129
|
+
return join2(projectDir ?? process.cwd(), ".agents", "mcp");
|
|
130
|
+
}
|
|
131
|
+
function getAgentsMcpServersPath(scope = "global", projectDir) {
|
|
132
|
+
return join2(getAgentsMcpDir(scope, projectDir), "servers.json");
|
|
133
|
+
}
|
|
134
|
+
function getAgentsInstructFile(scope = "global", projectDir) {
|
|
135
|
+
if (scope === "global") return join2(getAgentsHome(), "AGENTS.md");
|
|
136
|
+
return join2(projectDir ?? process.cwd(), ".agents", "AGENTS.md");
|
|
137
|
+
}
|
|
138
|
+
function getAgentsConfigPath(scope = "global", projectDir) {
|
|
139
|
+
if (scope === "global") return join2(getAgentsHome(), "config.toml");
|
|
140
|
+
return join2(projectDir ?? process.cwd(), ".agents", "config.toml");
|
|
141
|
+
}
|
|
142
|
+
function getAgentsWikiDir(scope = "global", projectDir) {
|
|
143
|
+
if (scope === "global") return join2(getAgentsHome(), "wiki");
|
|
144
|
+
return join2(projectDir ?? process.cwd(), ".agents", "wiki");
|
|
145
|
+
}
|
|
146
|
+
function getAgentsSpecDir(scope = "global", projectDir) {
|
|
147
|
+
if (scope === "global") return join2(getAgentsHome(), "spec");
|
|
148
|
+
return join2(projectDir ?? process.cwd(), ".agents", "spec");
|
|
149
|
+
}
|
|
150
|
+
function getAgentsLinksDir(scope = "global", projectDir) {
|
|
151
|
+
if (scope === "global") return join2(getAgentsHome(), "links");
|
|
152
|
+
return join2(projectDir ?? process.cwd(), ".agents", "links");
|
|
153
|
+
}
|
|
154
|
+
function resolveRegistryTemplatePath(template) {
|
|
155
|
+
const locations = getPlatformLocations();
|
|
156
|
+
return template.replace(/\$HOME/g, locations.home).replace(/\$CONFIG/g, locations.config).replace(/\$VSCODE_CONFIG/g, locations.vscodeConfig).replace(/\$ZED_CONFIG/g, locations.zedConfig).replace(/\$CLAUDE_DESKTOP_CONFIG/g, locations.claudeDesktopConfig).replace(/\$AGENTS_HOME/g, getAgentsHome());
|
|
157
|
+
}
|
|
158
|
+
function resolveProviderConfigPath(provider, scope, projectDir = process.cwd()) {
|
|
159
|
+
if (scope === "global") {
|
|
160
|
+
return provider.configPathGlobal;
|
|
161
|
+
}
|
|
162
|
+
if (!provider.configPathProject) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
return resolveProjectPath(provider.configPathProject, projectDir);
|
|
166
|
+
}
|
|
167
|
+
function resolvePreferredConfigScope(provider, useGlobalFlag) {
|
|
168
|
+
if (useGlobalFlag) {
|
|
169
|
+
return "global";
|
|
170
|
+
}
|
|
171
|
+
return provider.configPathProject ? "project" : "global";
|
|
172
|
+
}
|
|
173
|
+
function resolveProviderSkillsDir(provider, scope, projectDir = process.cwd()) {
|
|
174
|
+
if (scope === "global") {
|
|
175
|
+
return provider.pathSkills;
|
|
176
|
+
}
|
|
177
|
+
return resolveProjectPath(provider.pathProjectSkills, projectDir);
|
|
178
|
+
}
|
|
179
|
+
function resolveProviderSkillsDirs(provider, scope, projectDir = process.cwd()) {
|
|
180
|
+
const vendorPath = resolveProviderSkillsDir(provider, scope, projectDir);
|
|
181
|
+
const precedence = provider.capabilities?.skills?.precedence ?? "vendor-only";
|
|
182
|
+
const resolveAgentsPath = () => {
|
|
183
|
+
if (scope === "global") {
|
|
184
|
+
return provider.capabilities?.skills?.agentsGlobalPath ?? null;
|
|
185
|
+
}
|
|
186
|
+
const projectRelative = provider.capabilities?.skills?.agentsProjectPath ?? null;
|
|
187
|
+
return projectRelative ? join2(projectDir, projectRelative) : null;
|
|
188
|
+
};
|
|
189
|
+
switch (precedence) {
|
|
190
|
+
case "vendor-only":
|
|
191
|
+
return [vendorPath];
|
|
192
|
+
case "agents-canonical": {
|
|
193
|
+
const agentsPath = resolveAgentsPath();
|
|
194
|
+
return agentsPath ? [agentsPath] : [vendorPath];
|
|
195
|
+
}
|
|
196
|
+
case "agents-first": {
|
|
197
|
+
const agentsPath = resolveAgentsPath();
|
|
198
|
+
return agentsPath ? [agentsPath, vendorPath] : [vendorPath];
|
|
199
|
+
}
|
|
200
|
+
case "agents-supported": {
|
|
201
|
+
const agentsPath = resolveAgentsPath();
|
|
202
|
+
return agentsPath ? [vendorPath, agentsPath] : [vendorPath];
|
|
203
|
+
}
|
|
204
|
+
case "vendor-global-agents-project": {
|
|
205
|
+
if (scope === "global") {
|
|
206
|
+
return [vendorPath];
|
|
207
|
+
}
|
|
208
|
+
const agentsPath = resolveAgentsPath();
|
|
209
|
+
return agentsPath ? [agentsPath, vendorPath] : [vendorPath];
|
|
210
|
+
}
|
|
211
|
+
default:
|
|
212
|
+
return [vendorPath];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function resolveProviderProjectPath(provider, projectDir = process.cwd()) {
|
|
216
|
+
return resolveProjectPath(provider.pathProject, projectDir);
|
|
217
|
+
}
|
|
218
|
+
function resolveProvidersRegistryPath(startDir) {
|
|
219
|
+
const candidates = [
|
|
220
|
+
join2(startDir, "..", "..", "..", "providers", "registry.json"),
|
|
221
|
+
join2(startDir, "..", "providers", "registry.json")
|
|
222
|
+
];
|
|
223
|
+
for (const candidate of candidates) {
|
|
224
|
+
if (existsSync(candidate)) {
|
|
225
|
+
return candidate;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
let current = startDir;
|
|
229
|
+
for (let i = 0; i < 8; i += 1) {
|
|
230
|
+
const candidate = join2(current, "providers", "registry.json");
|
|
231
|
+
if (existsSync(candidate)) {
|
|
232
|
+
return candidate;
|
|
233
|
+
}
|
|
234
|
+
current = dirname(current);
|
|
235
|
+
}
|
|
236
|
+
throw new Error(`Cannot find providers/registry.json (searched from ${startDir})`);
|
|
237
|
+
}
|
|
238
|
+
function normalizeSkillSubPath(path) {
|
|
239
|
+
if (!path) return void 0;
|
|
240
|
+
const normalized = path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/SKILL\.md$/i, "").trim();
|
|
241
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
242
|
+
}
|
|
243
|
+
function buildSkillSubPathCandidates(marketplacePath, parsedPath) {
|
|
244
|
+
const candidates = [];
|
|
245
|
+
const base = normalizeSkillSubPath(marketplacePath);
|
|
246
|
+
const parsed = normalizeSkillSubPath(parsedPath);
|
|
247
|
+
if (base) candidates.push(base);
|
|
248
|
+
if (parsed) candidates.push(parsed);
|
|
249
|
+
const knownPrefixes = [".agents", ".claude"];
|
|
250
|
+
for (const value of [base, parsed]) {
|
|
251
|
+
if (!value || !value.startsWith("skills/")) continue;
|
|
252
|
+
for (const prefix of knownPrefixes) {
|
|
253
|
+
candidates.push(`${prefix}/${value}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (candidates.length === 0) {
|
|
257
|
+
candidates.push(void 0);
|
|
258
|
+
}
|
|
259
|
+
return Array.from(new Set(candidates));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/core/registry/providers.ts
|
|
263
|
+
var DEFAULT_SKILLS_CAPABILITY = {
|
|
264
|
+
agentsGlobalPath: null,
|
|
265
|
+
agentsProjectPath: null,
|
|
266
|
+
precedence: "vendor-only"
|
|
267
|
+
};
|
|
268
|
+
var DEFAULT_HOOKS_CAPABILITY = {
|
|
269
|
+
supported: [],
|
|
270
|
+
hookConfigPath: null,
|
|
271
|
+
hookFormat: null
|
|
272
|
+
};
|
|
273
|
+
var DEFAULT_SPAWN_CAPABILITY = {
|
|
274
|
+
supportsSubagents: false,
|
|
275
|
+
supportsProgrammaticSpawn: false,
|
|
276
|
+
supportsInterAgentComms: false,
|
|
277
|
+
supportsParallelSpawn: false,
|
|
278
|
+
spawnMechanism: null
|
|
279
|
+
};
|
|
280
|
+
function resolveCapabilities(raw) {
|
|
281
|
+
const skills = raw?.skills ? {
|
|
282
|
+
agentsGlobalPath: raw.skills.agentsGlobalPath ? resolveRegistryTemplatePath(raw.skills.agentsGlobalPath) : null,
|
|
283
|
+
agentsProjectPath: raw.skills.agentsProjectPath,
|
|
284
|
+
precedence: raw.skills.precedence
|
|
285
|
+
} : { ...DEFAULT_SKILLS_CAPABILITY };
|
|
286
|
+
const hooks = raw?.hooks ? {
|
|
287
|
+
supported: raw.hooks.supported,
|
|
288
|
+
hookConfigPath: raw.hooks.hookConfigPath ? resolveRegistryTemplatePath(raw.hooks.hookConfigPath) : null,
|
|
289
|
+
hookFormat: raw.hooks.hookFormat
|
|
290
|
+
} : { ...DEFAULT_HOOKS_CAPABILITY, supported: [] };
|
|
291
|
+
const spawn = raw?.spawn ? {
|
|
292
|
+
supportsSubagents: raw.spawn.supportsSubagents,
|
|
293
|
+
supportsProgrammaticSpawn: raw.spawn.supportsProgrammaticSpawn,
|
|
294
|
+
supportsInterAgentComms: raw.spawn.supportsInterAgentComms,
|
|
295
|
+
supportsParallelSpawn: raw.spawn.supportsParallelSpawn,
|
|
296
|
+
spawnMechanism: raw.spawn.spawnMechanism
|
|
297
|
+
} : { ...DEFAULT_SPAWN_CAPABILITY };
|
|
298
|
+
return { skills, hooks, spawn };
|
|
299
|
+
}
|
|
300
|
+
function findRegistryPath() {
|
|
301
|
+
const thisDir = dirname2(fileURLToPath(import.meta.url));
|
|
302
|
+
return resolveProvidersRegistryPath(thisDir);
|
|
303
|
+
}
|
|
304
|
+
var _registry = null;
|
|
305
|
+
var _providers = null;
|
|
306
|
+
var _aliasMap = null;
|
|
307
|
+
function resolveProvider(raw) {
|
|
308
|
+
return {
|
|
309
|
+
id: raw.id,
|
|
310
|
+
toolName: raw.toolName,
|
|
311
|
+
vendor: raw.vendor,
|
|
312
|
+
agentFlag: raw.agentFlag,
|
|
313
|
+
aliases: raw.aliases,
|
|
314
|
+
pathGlobal: resolveRegistryTemplatePath(raw.pathGlobal),
|
|
315
|
+
pathProject: raw.pathProject,
|
|
316
|
+
instructFile: raw.instructFile,
|
|
317
|
+
configKey: raw.configKey,
|
|
318
|
+
configFormat: raw.configFormat,
|
|
319
|
+
configPathGlobal: resolveRegistryTemplatePath(raw.configPathGlobal),
|
|
320
|
+
configPathProject: raw.configPathProject,
|
|
321
|
+
pathSkills: resolveRegistryTemplatePath(raw.pathSkills),
|
|
322
|
+
pathProjectSkills: raw.pathProjectSkills,
|
|
323
|
+
detection: {
|
|
324
|
+
methods: raw.detection.methods,
|
|
325
|
+
binary: raw.detection.binary,
|
|
326
|
+
directories: raw.detection.directories?.map(resolveRegistryTemplatePath),
|
|
327
|
+
appBundle: raw.detection.appBundle,
|
|
328
|
+
flatpakId: raw.detection.flatpakId
|
|
329
|
+
},
|
|
330
|
+
supportedTransports: raw.supportedTransports,
|
|
331
|
+
supportsHeaders: raw.supportsHeaders,
|
|
332
|
+
priority: raw.priority,
|
|
333
|
+
status: raw.status,
|
|
334
|
+
agentSkillsCompatible: raw.agentSkillsCompatible,
|
|
335
|
+
capabilities: resolveCapabilities(raw.capabilities)
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function loadRegistry() {
|
|
339
|
+
if (_registry) return _registry;
|
|
340
|
+
const registryPath = findRegistryPath();
|
|
341
|
+
const raw = readFileSync(registryPath, "utf-8");
|
|
342
|
+
_registry = JSON.parse(raw);
|
|
343
|
+
return _registry;
|
|
344
|
+
}
|
|
345
|
+
function ensureProviders() {
|
|
346
|
+
if (_providers) return;
|
|
347
|
+
const registry = loadRegistry();
|
|
348
|
+
_providers = /* @__PURE__ */ new Map();
|
|
349
|
+
_aliasMap = /* @__PURE__ */ new Map();
|
|
350
|
+
for (const [id, raw] of Object.entries(registry.providers)) {
|
|
351
|
+
const provider = resolveProvider(raw);
|
|
352
|
+
_providers.set(id, provider);
|
|
353
|
+
for (const alias of provider.aliases) {
|
|
354
|
+
_aliasMap.set(alias, id);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function getAllProviders() {
|
|
359
|
+
ensureProviders();
|
|
360
|
+
if (!_providers) return [];
|
|
361
|
+
return Array.from(_providers.values());
|
|
362
|
+
}
|
|
363
|
+
function getProvider(idOrAlias) {
|
|
364
|
+
ensureProviders();
|
|
365
|
+
const resolved = _aliasMap?.get(idOrAlias) ?? idOrAlias;
|
|
366
|
+
return _providers?.get(resolved);
|
|
367
|
+
}
|
|
368
|
+
function resolveAlias(idOrAlias) {
|
|
369
|
+
ensureProviders();
|
|
370
|
+
return _aliasMap?.get(idOrAlias) ?? idOrAlias;
|
|
371
|
+
}
|
|
372
|
+
function getProvidersByPriority(priority) {
|
|
373
|
+
return getAllProviders().filter((p) => p.priority === priority);
|
|
374
|
+
}
|
|
375
|
+
function getProvidersByStatus(status) {
|
|
376
|
+
return getAllProviders().filter((p) => p.status === status);
|
|
377
|
+
}
|
|
378
|
+
function getProvidersByInstructFile(file) {
|
|
379
|
+
return getAllProviders().filter((p) => p.instructFile === file);
|
|
380
|
+
}
|
|
381
|
+
function getInstructionFiles() {
|
|
382
|
+
const files = /* @__PURE__ */ new Set();
|
|
383
|
+
for (const p of getAllProviders()) {
|
|
384
|
+
files.add(p.instructFile);
|
|
385
|
+
}
|
|
386
|
+
return Array.from(files);
|
|
387
|
+
}
|
|
388
|
+
function getProviderCount() {
|
|
389
|
+
ensureProviders();
|
|
390
|
+
return _providers?.size ?? 0;
|
|
391
|
+
}
|
|
392
|
+
function getRegistryVersion() {
|
|
393
|
+
return loadRegistry().version;
|
|
394
|
+
}
|
|
395
|
+
function getProvidersByHookEvent(event) {
|
|
396
|
+
return getAllProviders().filter((p) => p.capabilities.hooks.supported.includes(event));
|
|
397
|
+
}
|
|
398
|
+
function getCommonHookEvents(providerIds) {
|
|
399
|
+
const providers = providerIds && providerIds.length > 0 ? providerIds.map((id) => getProvider(id)).filter((p) => p !== void 0) : getAllProviders();
|
|
400
|
+
if (providers.length === 0) return [];
|
|
401
|
+
const first = providers[0].capabilities.hooks.supported;
|
|
402
|
+
return first.filter(
|
|
403
|
+
(event) => providers.every((p) => p.capabilities.hooks.supported.includes(event))
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
function providerSupports(provider, dotPath) {
|
|
407
|
+
const parts = dotPath.split(".");
|
|
408
|
+
let current = provider.capabilities;
|
|
409
|
+
for (const part of parts) {
|
|
410
|
+
if (current == null || typeof current !== "object") return false;
|
|
411
|
+
current = current[part];
|
|
412
|
+
}
|
|
413
|
+
if (typeof current === "boolean") return current;
|
|
414
|
+
if (Array.isArray(current)) return current.length > 0;
|
|
415
|
+
return current != null;
|
|
416
|
+
}
|
|
417
|
+
function getSpawnCapableProviders() {
|
|
418
|
+
return getAllProviders().filter((p) => p.capabilities.spawn.supportsSubagents);
|
|
419
|
+
}
|
|
420
|
+
function getProvidersBySpawnCapability(flag) {
|
|
421
|
+
return getAllProviders().filter((p) => p.capabilities.spawn[flag] === true);
|
|
422
|
+
}
|
|
423
|
+
function getProvidersBySkillsPrecedence(precedence) {
|
|
424
|
+
return getAllProviders().filter((p) => p.capabilities.skills.precedence === precedence);
|
|
425
|
+
}
|
|
426
|
+
function getEffectiveSkillsPaths(provider, scope, projectDir) {
|
|
427
|
+
const vendorPath = resolveProviderSkillsDir(provider, scope, projectDir);
|
|
428
|
+
const { precedence, agentsGlobalPath, agentsProjectPath } = provider.capabilities.skills;
|
|
429
|
+
const resolveAgentsPath = () => {
|
|
430
|
+
if (scope === "global" && agentsGlobalPath) return agentsGlobalPath;
|
|
431
|
+
if (scope === "project" && agentsProjectPath && projectDir) {
|
|
432
|
+
return join3(projectDir, agentsProjectPath);
|
|
433
|
+
}
|
|
434
|
+
return null;
|
|
435
|
+
};
|
|
436
|
+
const agentsPath = resolveAgentsPath();
|
|
437
|
+
const scopeLabel = scope === "global" ? "global" : "project";
|
|
438
|
+
switch (precedence) {
|
|
439
|
+
case "vendor-only":
|
|
440
|
+
return [{ path: vendorPath, source: "vendor", scope: scopeLabel }];
|
|
441
|
+
case "agents-canonical":
|
|
442
|
+
return agentsPath ? [{ path: agentsPath, source: "agents", scope: scopeLabel }] : [];
|
|
443
|
+
case "agents-first":
|
|
444
|
+
return [
|
|
445
|
+
...agentsPath ? [{ path: agentsPath, source: "agents", scope: scopeLabel }] : [],
|
|
446
|
+
{ path: vendorPath, source: "vendor", scope: scopeLabel }
|
|
447
|
+
];
|
|
448
|
+
case "agents-supported":
|
|
449
|
+
return [
|
|
450
|
+
{ path: vendorPath, source: "vendor", scope: scopeLabel },
|
|
451
|
+
...agentsPath ? [{ path: agentsPath, source: "agents", scope: scopeLabel }] : []
|
|
452
|
+
];
|
|
453
|
+
case "vendor-global-agents-project":
|
|
454
|
+
if (scope === "global") {
|
|
455
|
+
return [{ path: vendorPath, source: "vendor", scope: "global" }];
|
|
456
|
+
}
|
|
457
|
+
return [
|
|
458
|
+
...agentsPath ? [{ path: agentsPath, source: "agents", scope: "project" }] : [],
|
|
459
|
+
{ path: vendorPath, source: "vendor", scope: "project" }
|
|
460
|
+
];
|
|
461
|
+
default:
|
|
462
|
+
return [{ path: vendorPath, source: "vendor", scope: scopeLabel }];
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function buildSkillsMap() {
|
|
466
|
+
return getAllProviders().map((p) => {
|
|
467
|
+
const { precedence, agentsGlobalPath, agentsProjectPath } = p.capabilities.skills;
|
|
468
|
+
const isVendorOnly = precedence === "vendor-only";
|
|
469
|
+
return {
|
|
470
|
+
providerId: p.id,
|
|
471
|
+
toolName: p.toolName,
|
|
472
|
+
precedence,
|
|
473
|
+
paths: {
|
|
474
|
+
global: isVendorOnly ? p.pathSkills : agentsGlobalPath ?? null,
|
|
475
|
+
project: isVendorOnly ? p.pathProjectSkills : agentsProjectPath ?? null
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
function getProviderCapabilities(idOrAlias) {
|
|
481
|
+
return getProvider(idOrAlias)?.capabilities;
|
|
482
|
+
}
|
|
483
|
+
function providerSupportsById(idOrAlias, capabilityPath) {
|
|
484
|
+
const provider = getProvider(idOrAlias);
|
|
485
|
+
if (!provider) return false;
|
|
486
|
+
return providerSupports(provider, capabilityPath);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// src/core/instructions/templates.ts
|
|
490
|
+
function buildInjectionContent(template) {
|
|
491
|
+
const lines = [];
|
|
492
|
+
for (const ref of template.references) {
|
|
493
|
+
lines.push(ref);
|
|
494
|
+
}
|
|
495
|
+
if (template.content && template.content.length > 0) {
|
|
496
|
+
if (lines.length > 0) {
|
|
497
|
+
lines.push("");
|
|
498
|
+
}
|
|
499
|
+
lines.push(...template.content);
|
|
500
|
+
}
|
|
501
|
+
return lines.join("\n");
|
|
502
|
+
}
|
|
503
|
+
function parseInjectionContent(content) {
|
|
504
|
+
const references = [];
|
|
505
|
+
const contentLines = [];
|
|
506
|
+
for (const line of content.split("\n")) {
|
|
507
|
+
const trimmed = line.trim();
|
|
508
|
+
if (!trimmed) continue;
|
|
509
|
+
if (trimmed.startsWith("@")) {
|
|
510
|
+
references.push(trimmed);
|
|
511
|
+
} else {
|
|
512
|
+
contentLines.push(line);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
references,
|
|
517
|
+
content: contentLines.length > 0 ? contentLines : void 0
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function generateInjectionContent(options) {
|
|
521
|
+
const lines = [];
|
|
522
|
+
lines.push("## CAAMP Managed Configuration");
|
|
523
|
+
lines.push("");
|
|
524
|
+
lines.push("This section is managed by [CAAMP](https://github.com/caamp/caamp).");
|
|
525
|
+
lines.push("Do not edit between the CAAMP markers manually.");
|
|
526
|
+
if (options?.mcpServerName) {
|
|
527
|
+
lines.push("");
|
|
528
|
+
lines.push(`### MCP Server: ${options.mcpServerName}`);
|
|
529
|
+
lines.push(`Configured via \`caamp mcp install\`.`);
|
|
530
|
+
}
|
|
531
|
+
if (options?.customContent) {
|
|
532
|
+
lines.push("");
|
|
533
|
+
lines.push(options.customContent);
|
|
534
|
+
}
|
|
535
|
+
return lines.join("\n");
|
|
536
|
+
}
|
|
537
|
+
function generateSkillsSection(skillNames) {
|
|
538
|
+
if (skillNames.length === 0) return "";
|
|
539
|
+
const lines = [];
|
|
540
|
+
lines.push("### Installed Skills");
|
|
541
|
+
lines.push("");
|
|
542
|
+
for (const name of skillNames) {
|
|
543
|
+
lines.push(`- \`${name}\` - Available via SKILL.md`);
|
|
544
|
+
}
|
|
545
|
+
return lines.join("\n");
|
|
546
|
+
}
|
|
547
|
+
function groupByInstructFile(providers) {
|
|
548
|
+
const groups = /* @__PURE__ */ new Map();
|
|
549
|
+
for (const provider of providers) {
|
|
550
|
+
const existing = groups.get(provider.instructFile) ?? [];
|
|
551
|
+
existing.push(provider);
|
|
552
|
+
groups.set(provider.instructFile, existing);
|
|
553
|
+
}
|
|
554
|
+
return groups;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/core/instructions/injector.ts
|
|
558
|
+
var MARKER_START = "<!-- CAAMP:START -->";
|
|
559
|
+
var MARKER_END = "<!-- CAAMP:END -->";
|
|
560
|
+
var MARKER_PATTERN = /<!-- CAAMP:START -->[\s\S]*?<!-- CAAMP:END -->/g;
|
|
561
|
+
var MARKER_PATTERN_SINGLE = /<!-- CAAMP:START -->[\s\S]*?<!-- CAAMP:END -->/;
|
|
562
|
+
async function checkInjection(filePath, expectedContent) {
|
|
563
|
+
if (!existsSync2(filePath)) return "missing";
|
|
564
|
+
const content = await readFile(filePath, "utf-8");
|
|
565
|
+
if (!MARKER_PATTERN_SINGLE.test(content)) return "none";
|
|
566
|
+
if (expectedContent) {
|
|
567
|
+
const blockContent = extractBlock(content);
|
|
568
|
+
if (blockContent && blockContent.trim() === expectedContent.trim()) {
|
|
569
|
+
return "current";
|
|
570
|
+
}
|
|
571
|
+
return "outdated";
|
|
572
|
+
}
|
|
573
|
+
return "current";
|
|
574
|
+
}
|
|
575
|
+
function extractBlock(content) {
|
|
576
|
+
const match = content.match(MARKER_PATTERN_SINGLE);
|
|
577
|
+
if (!match) return null;
|
|
578
|
+
return match[0].replace(MARKER_START, "").replace(MARKER_END, "").trim();
|
|
579
|
+
}
|
|
580
|
+
function buildBlock(content) {
|
|
581
|
+
return `${MARKER_START}
|
|
582
|
+
${content}
|
|
583
|
+
${MARKER_END}`;
|
|
584
|
+
}
|
|
585
|
+
async function inject(filePath, content) {
|
|
586
|
+
const block = buildBlock(content);
|
|
587
|
+
await mkdir(dirname3(filePath), { recursive: true });
|
|
588
|
+
if (!existsSync2(filePath)) {
|
|
589
|
+
await writeFile(filePath, `${block}
|
|
590
|
+
`, "utf-8");
|
|
591
|
+
return "created";
|
|
592
|
+
}
|
|
593
|
+
const existing = await readFile(filePath, "utf-8");
|
|
594
|
+
const matches = existing.match(MARKER_PATTERN);
|
|
595
|
+
if (matches && matches.length > 0) {
|
|
596
|
+
if (matches.length > 1) {
|
|
597
|
+
const updated3 = existing.replace(MARKER_PATTERN, "").replace(/^\n{2,}/, "\n").trim();
|
|
598
|
+
const finalContent = updated3 ? `${block}
|
|
599
|
+
|
|
600
|
+
${updated3}` : `${block}
|
|
601
|
+
`;
|
|
602
|
+
await writeFile(filePath, finalContent, "utf-8");
|
|
603
|
+
return "consolidated";
|
|
604
|
+
}
|
|
605
|
+
const existingBlock = extractBlock(existing);
|
|
606
|
+
if (existingBlock !== null && existingBlock.trim() === content.trim()) {
|
|
607
|
+
return "intact";
|
|
608
|
+
}
|
|
609
|
+
const updated2 = existing.replace(MARKER_PATTERN_SINGLE, block);
|
|
610
|
+
await writeFile(filePath, updated2, "utf-8");
|
|
611
|
+
return "updated";
|
|
612
|
+
}
|
|
613
|
+
const updated = `${block}
|
|
614
|
+
|
|
615
|
+
${existing}`;
|
|
616
|
+
await writeFile(filePath, updated, "utf-8");
|
|
617
|
+
return "added";
|
|
618
|
+
}
|
|
619
|
+
async function removeInjection(filePath) {
|
|
620
|
+
if (!existsSync2(filePath)) return false;
|
|
621
|
+
const content = await readFile(filePath, "utf-8");
|
|
622
|
+
if (!MARKER_PATTERN.test(content)) return false;
|
|
623
|
+
const cleaned = content.replace(MARKER_PATTERN, "").replace(/^\n{2,}/, "\n").trim();
|
|
624
|
+
if (!cleaned) {
|
|
625
|
+
const { rm } = await import("fs/promises");
|
|
626
|
+
await rm(filePath);
|
|
627
|
+
} else {
|
|
628
|
+
await writeFile(filePath, `${cleaned}
|
|
629
|
+
`, "utf-8");
|
|
630
|
+
}
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
async function checkAllInjections(providers, projectDir, scope, expectedContent) {
|
|
634
|
+
const results = [];
|
|
635
|
+
const checked = /* @__PURE__ */ new Set();
|
|
636
|
+
for (const provider of providers) {
|
|
637
|
+
const filePath = scope === "global" ? join4(provider.pathGlobal, provider.instructFile) : join4(projectDir, provider.instructFile);
|
|
638
|
+
if (checked.has(filePath)) continue;
|
|
639
|
+
checked.add(filePath);
|
|
640
|
+
const status = await checkInjection(filePath, expectedContent);
|
|
641
|
+
results.push({
|
|
642
|
+
file: filePath,
|
|
643
|
+
provider: provider.id,
|
|
644
|
+
status,
|
|
645
|
+
fileExists: existsSync2(filePath)
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
return results;
|
|
649
|
+
}
|
|
650
|
+
async function injectAll(providers, projectDir, scope, content) {
|
|
651
|
+
const results = /* @__PURE__ */ new Map();
|
|
652
|
+
const injected = /* @__PURE__ */ new Set();
|
|
653
|
+
for (const provider of providers) {
|
|
654
|
+
const filePath = scope === "global" ? join4(provider.pathGlobal, provider.instructFile) : join4(projectDir, provider.instructFile);
|
|
655
|
+
if (injected.has(filePath)) continue;
|
|
656
|
+
injected.add(filePath);
|
|
657
|
+
const action = await inject(filePath, content);
|
|
658
|
+
results.set(filePath, action);
|
|
659
|
+
}
|
|
660
|
+
return results;
|
|
661
|
+
}
|
|
662
|
+
async function ensureProviderInstructionFile(providerId, projectDir, options) {
|
|
663
|
+
const provider = getProvider(providerId);
|
|
664
|
+
if (!provider) {
|
|
665
|
+
throw new Error(`Unknown provider: "${providerId}". Check CAAMP provider registry.`);
|
|
666
|
+
}
|
|
667
|
+
const scope = options.scope ?? "project";
|
|
668
|
+
const filePath = scope === "global" ? join4(provider.pathGlobal, provider.instructFile) : join4(projectDir, provider.instructFile);
|
|
669
|
+
const template = {
|
|
670
|
+
references: options.references,
|
|
671
|
+
content: options.content
|
|
672
|
+
};
|
|
673
|
+
const injectionContent = buildInjectionContent(template);
|
|
674
|
+
const action = await inject(filePath, injectionContent);
|
|
675
|
+
return {
|
|
676
|
+
filePath,
|
|
677
|
+
instructFile: provider.instructFile,
|
|
678
|
+
action,
|
|
679
|
+
providerId: provider.id
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
async function ensureAllProviderInstructionFiles(providerIds, projectDir, options) {
|
|
683
|
+
const results = [];
|
|
684
|
+
const processed = /* @__PURE__ */ new Set();
|
|
685
|
+
for (const providerId of providerIds) {
|
|
686
|
+
const provider = getProvider(providerId);
|
|
687
|
+
if (!provider) {
|
|
688
|
+
throw new Error(`Unknown provider: "${providerId}". Check CAAMP provider registry.`);
|
|
689
|
+
}
|
|
690
|
+
const scope = options.scope ?? "project";
|
|
691
|
+
const filePath = scope === "global" ? join4(provider.pathGlobal, provider.instructFile) : join4(projectDir, provider.instructFile);
|
|
692
|
+
if (processed.has(filePath)) continue;
|
|
693
|
+
processed.add(filePath);
|
|
694
|
+
const template = {
|
|
695
|
+
references: options.references,
|
|
696
|
+
content: options.content
|
|
697
|
+
};
|
|
698
|
+
const injectionContent = buildInjectionContent(template);
|
|
699
|
+
const action = await inject(filePath, injectionContent);
|
|
700
|
+
results.push({
|
|
701
|
+
filePath,
|
|
702
|
+
instructFile: provider.instructFile,
|
|
703
|
+
action,
|
|
704
|
+
providerId: provider.id
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
return results;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
export {
|
|
711
|
+
__export,
|
|
712
|
+
getPlatformPaths,
|
|
713
|
+
getSystemInfo,
|
|
714
|
+
_resetPlatformPathsCache,
|
|
715
|
+
getPlatformLocations,
|
|
716
|
+
getAgentsHome,
|
|
717
|
+
getProjectAgentsDir,
|
|
718
|
+
getCanonicalSkillsDir,
|
|
719
|
+
getLockFilePath,
|
|
720
|
+
getAgentsMcpDir,
|
|
721
|
+
getAgentsMcpServersPath,
|
|
722
|
+
getAgentsInstructFile,
|
|
723
|
+
getAgentsConfigPath,
|
|
724
|
+
getAgentsWikiDir,
|
|
725
|
+
getAgentsSpecDir,
|
|
726
|
+
getAgentsLinksDir,
|
|
727
|
+
resolveRegistryTemplatePath,
|
|
728
|
+
resolveProviderConfigPath,
|
|
729
|
+
resolvePreferredConfigScope,
|
|
730
|
+
resolveProviderSkillsDir,
|
|
731
|
+
resolveProviderSkillsDirs,
|
|
732
|
+
resolveProviderProjectPath,
|
|
733
|
+
buildSkillSubPathCandidates,
|
|
734
|
+
getAllProviders,
|
|
735
|
+
getProvider,
|
|
736
|
+
resolveAlias,
|
|
737
|
+
getProvidersByPriority,
|
|
738
|
+
getProvidersByStatus,
|
|
739
|
+
getProvidersByInstructFile,
|
|
740
|
+
getInstructionFiles,
|
|
741
|
+
getProviderCount,
|
|
742
|
+
getRegistryVersion,
|
|
743
|
+
getProvidersByHookEvent,
|
|
744
|
+
getCommonHookEvents,
|
|
745
|
+
providerSupports,
|
|
746
|
+
getSpawnCapableProviders,
|
|
747
|
+
getProvidersBySpawnCapability,
|
|
748
|
+
getProvidersBySkillsPrecedence,
|
|
749
|
+
getEffectiveSkillsPaths,
|
|
750
|
+
buildSkillsMap,
|
|
751
|
+
getProviderCapabilities,
|
|
752
|
+
providerSupportsById,
|
|
753
|
+
buildInjectionContent,
|
|
754
|
+
parseInjectionContent,
|
|
755
|
+
generateInjectionContent,
|
|
756
|
+
generateSkillsSection,
|
|
757
|
+
groupByInstructFile,
|
|
758
|
+
checkInjection,
|
|
759
|
+
inject,
|
|
760
|
+
removeInjection,
|
|
761
|
+
checkAllInjections,
|
|
762
|
+
injectAll,
|
|
763
|
+
ensureProviderInstructionFile,
|
|
764
|
+
ensureAllProviderInstructionFiles
|
|
765
|
+
};
|
|
766
|
+
//# sourceMappingURL=chunk-CPHF5IM4.js.map
|