aicm 0.20.1 → 0.20.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.
@@ -1,421 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.installWorkspaces = installWorkspaces;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const hooks_1 = require("../utils/hooks");
10
- const working_directory_1 = require("../utils/working-directory");
11
- const workspace_discovery_1 = require("../utils/workspace-discovery");
12
- const install_1 = require("./install");
13
- function mergeWorkspaceCommands(packages) {
14
- var _a;
15
- const commands = [];
16
- const seenPresetCommands = new Set();
17
- for (const pkg of packages) {
18
- const hasCursorTarget = pkg.config.config.targets.includes("cursor");
19
- if (!hasCursorTarget) {
20
- continue;
21
- }
22
- for (const command of (_a = pkg.config.commands) !== null && _a !== void 0 ? _a : []) {
23
- if (command.presetName) {
24
- const presetKey = `${command.presetName}::${command.name}`;
25
- if (seenPresetCommands.has(presetKey)) {
26
- continue;
27
- }
28
- seenPresetCommands.add(presetKey);
29
- }
30
- commands.push(command);
31
- }
32
- }
33
- return commands;
34
- }
35
- function collectWorkspaceCommandTargets(packages) {
36
- const targets = new Set();
37
- for (const pkg of packages) {
38
- if (pkg.config.config.targets.includes("cursor")) {
39
- targets.add("cursor");
40
- }
41
- }
42
- return Array.from(targets);
43
- }
44
- /**
45
- * Merge skills from multiple workspace packages
46
- * Skills are merged flat (not namespaced by preset)
47
- * Dedupes preset skills that appear in multiple packages
48
- */
49
- function mergeWorkspaceSkills(packages) {
50
- var _a;
51
- const skills = [];
52
- const seenPresetSkills = new Set();
53
- for (const pkg of packages) {
54
- // Skills are supported by cursor, claude, and codex targets
55
- const hasSkillsTarget = pkg.config.config.targets.includes("cursor") ||
56
- pkg.config.config.targets.includes("claude") ||
57
- pkg.config.config.targets.includes("codex");
58
- if (!hasSkillsTarget) {
59
- continue;
60
- }
61
- for (const skill of (_a = pkg.config.skills) !== null && _a !== void 0 ? _a : []) {
62
- if (skill.presetName) {
63
- // Dedupe preset skills by preset+name combination
64
- const presetKey = `${skill.presetName}::${skill.name}`;
65
- if (seenPresetSkills.has(presetKey)) {
66
- continue;
67
- }
68
- seenPresetSkills.add(presetKey);
69
- }
70
- skills.push(skill);
71
- }
72
- }
73
- return skills;
74
- }
75
- /**
76
- * Collect all targets that support skills from workspace packages
77
- */
78
- function collectWorkspaceSkillTargets(packages) {
79
- const targets = new Set();
80
- for (const pkg of packages) {
81
- for (const target of pkg.config.config.targets) {
82
- // Skills are supported by cursor, claude, and codex
83
- if (target === "cursor" || target === "claude" || target === "codex") {
84
- targets.add(target);
85
- }
86
- }
87
- }
88
- return Array.from(targets);
89
- }
90
- /**
91
- * Merge agents from multiple workspace packages
92
- * Agents are merged flat (not namespaced by preset)
93
- * Dedupes preset agents that appear in multiple packages
94
- */
95
- function mergeWorkspaceAgents(packages) {
96
- var _a;
97
- const agents = [];
98
- const seenPresetAgents = new Set();
99
- for (const pkg of packages) {
100
- // Agents are supported by cursor and claude targets
101
- const hasAgentsTarget = pkg.config.config.targets.includes("cursor") ||
102
- pkg.config.config.targets.includes("claude");
103
- if (!hasAgentsTarget) {
104
- continue;
105
- }
106
- for (const agent of (_a = pkg.config.agents) !== null && _a !== void 0 ? _a : []) {
107
- if (agent.presetName) {
108
- // Dedupe preset agents by preset+name combination
109
- const presetKey = `${agent.presetName}::${agent.name}`;
110
- if (seenPresetAgents.has(presetKey)) {
111
- continue;
112
- }
113
- seenPresetAgents.add(presetKey);
114
- }
115
- agents.push(agent);
116
- }
117
- }
118
- return agents;
119
- }
120
- /**
121
- * Collect all targets that support agents from workspace packages
122
- */
123
- function collectWorkspaceAgentTargets(packages) {
124
- const targets = new Set();
125
- for (const pkg of packages) {
126
- for (const target of pkg.config.config.targets) {
127
- // Agents are supported by cursor and claude
128
- if (target === "cursor" || target === "claude") {
129
- targets.add(target);
130
- }
131
- }
132
- }
133
- return Array.from(targets);
134
- }
135
- function mergeWorkspaceMcpServers(packages) {
136
- const merged = {};
137
- const info = {};
138
- for (const pkg of packages) {
139
- for (const [key, value] of Object.entries(pkg.config.mcpServers)) {
140
- if (value === false)
141
- continue;
142
- const json = JSON.stringify(value);
143
- if (!info[key]) {
144
- info[key] = {
145
- configs: new Set([json]),
146
- packages: [pkg.relativePath],
147
- chosen: pkg.relativePath,
148
- };
149
- }
150
- else {
151
- info[key].packages.push(pkg.relativePath);
152
- info[key].configs.add(json);
153
- info[key].chosen = pkg.relativePath;
154
- }
155
- merged[key] = value;
156
- }
157
- }
158
- const conflicts = [];
159
- for (const [key, data] of Object.entries(info)) {
160
- if (data.configs.size > 1) {
161
- conflicts.push({ key, packages: data.packages, chosen: data.chosen });
162
- }
163
- }
164
- return { merged, conflicts };
165
- }
166
- /**
167
- * Merge hooks from multiple workspace packages
168
- */
169
- function mergeWorkspaceHooks(packages) {
170
- const allHooksConfigs = [];
171
- const allHookFiles = [];
172
- for (const pkg of packages) {
173
- // Collect hooks configs
174
- if (pkg.config.hooks) {
175
- allHooksConfigs.push(pkg.config.hooks);
176
- }
177
- // Collect hook files
178
- allHookFiles.push(...pkg.config.hookFiles);
179
- }
180
- // Merge hooks configs
181
- const merged = (0, hooks_1.mergeHooksConfigs)(allHooksConfigs);
182
- // Dedupe hook files by basename with MD5 checking
183
- const dedupedHookFiles = (0, hooks_1.dedupeHookFiles)(allHookFiles);
184
- return { merged, hookFiles: dedupedHookFiles };
185
- }
186
- /**
187
- * Install aicm configurations for all packages in a workspace
188
- */
189
- async function installWorkspacesPackages(packages, options = {}) {
190
- const results = [];
191
- let totalRuleCount = 0;
192
- let totalCommandCount = 0;
193
- let totalAssetCount = 0;
194
- let totalHookCount = 0;
195
- let totalSkillCount = 0;
196
- let totalAgentCount = 0;
197
- // Install packages sequentially for now (can be parallelized later)
198
- for (const pkg of packages) {
199
- const packagePath = pkg.absolutePath;
200
- try {
201
- const result = await (0, install_1.installPackage)({
202
- ...options,
203
- cwd: packagePath,
204
- config: pkg.config,
205
- });
206
- totalRuleCount += result.installedRuleCount;
207
- totalCommandCount += result.installedCommandCount;
208
- totalAssetCount += result.installedAssetCount;
209
- totalHookCount += result.installedHookCount;
210
- totalSkillCount += result.installedSkillCount;
211
- totalAgentCount += result.installedAgentCount;
212
- results.push({
213
- path: pkg.relativePath,
214
- success: result.success,
215
- error: result.error,
216
- installedRuleCount: result.installedRuleCount,
217
- installedCommandCount: result.installedCommandCount,
218
- installedAssetCount: result.installedAssetCount,
219
- installedHookCount: result.installedHookCount,
220
- installedSkillCount: result.installedSkillCount,
221
- installedAgentCount: result.installedAgentCount,
222
- });
223
- }
224
- catch (error) {
225
- results.push({
226
- path: pkg.relativePath,
227
- success: false,
228
- error: error instanceof Error ? error : new Error(String(error)),
229
- installedRuleCount: 0,
230
- installedCommandCount: 0,
231
- installedAssetCount: 0,
232
- installedHookCount: 0,
233
- installedSkillCount: 0,
234
- installedAgentCount: 0,
235
- });
236
- }
237
- }
238
- const failedPackages = results.filter((r) => !r.success);
239
- return {
240
- success: failedPackages.length === 0,
241
- packages: results,
242
- totalRuleCount,
243
- totalCommandCount,
244
- totalAssetCount,
245
- totalHookCount,
246
- totalSkillCount,
247
- totalAgentCount,
248
- };
249
- }
250
- /**
251
- * Install rules across multiple packages in a workspace
252
- */
253
- async function installWorkspaces(cwd, installOnCI, verbose = false, dryRun = false) {
254
- return (0, working_directory_1.withWorkingDirectory)(cwd, async () => {
255
- if (verbose) {
256
- console.log(chalk_1.default.blue("🔍 Discovering packages..."));
257
- }
258
- const allPackages = await (0, workspace_discovery_1.discoverPackagesWithAicm)(cwd);
259
- const packages = allPackages.filter((pkg) => {
260
- if (pkg.config.config.skipInstall === true) {
261
- return false;
262
- }
263
- const isRoot = pkg.relativePath === ".";
264
- if (!isRoot)
265
- return true;
266
- // For root directories, only keep if it has rules, commands, skills, agents, or presets
267
- const hasRules = pkg.config.rules && pkg.config.rules.length > 0;
268
- const hasCommands = pkg.config.commands && pkg.config.commands.length > 0;
269
- const hasSkills = pkg.config.skills && pkg.config.skills.length > 0;
270
- const hasAgents = pkg.config.agents && pkg.config.agents.length > 0;
271
- const hasPresets = pkg.config.config.presets && pkg.config.config.presets.length > 0;
272
- return hasRules || hasCommands || hasSkills || hasAgents || hasPresets;
273
- });
274
- if (packages.length === 0) {
275
- return {
276
- success: false,
277
- error: new Error("No packages with aicm configurations found"),
278
- installedRuleCount: 0,
279
- installedCommandCount: 0,
280
- installedAssetCount: 0,
281
- installedHookCount: 0,
282
- installedSkillCount: 0,
283
- installedAgentCount: 0,
284
- packagesCount: 0,
285
- };
286
- }
287
- if (verbose) {
288
- console.log(chalk_1.default.blue(`Found ${packages.length} packages with aicm configurations:`));
289
- packages.forEach((pkg) => {
290
- console.log(chalk_1.default.gray(` - ${pkg.relativePath}`));
291
- });
292
- console.log(chalk_1.default.blue(`📦 Installing configurations...`));
293
- }
294
- const result = await installWorkspacesPackages(packages, {
295
- installOnCI,
296
- verbose,
297
- dryRun,
298
- });
299
- const workspaceCommands = mergeWorkspaceCommands(packages);
300
- const workspaceCommandTargets = collectWorkspaceCommandTargets(packages);
301
- if (workspaceCommands.length > 0) {
302
- (0, install_1.warnPresetCommandCollisions)(workspaceCommands);
303
- }
304
- if (!dryRun &&
305
- workspaceCommands.length > 0 &&
306
- workspaceCommandTargets.length > 0) {
307
- const dedupedWorkspaceCommands = (0, install_1.dedupeCommandsForInstall)(workspaceCommands);
308
- // Collect all assets from packages
309
- const allAssets = packages.flatMap((pkg) => { var _a; return (_a = pkg.config.assets) !== null && _a !== void 0 ? _a : []; });
310
- // Copy assets to root
311
- (0, install_1.writeAssetsToTargets)(allAssets, workspaceCommandTargets);
312
- (0, install_1.writeCommandsToTargets)(dedupedWorkspaceCommands, workspaceCommandTargets);
313
- }
314
- // Merge and write skills for workspace
315
- const workspaceSkills = mergeWorkspaceSkills(packages);
316
- const workspaceSkillTargets = collectWorkspaceSkillTargets(packages);
317
- if (workspaceSkills.length > 0) {
318
- (0, install_1.warnPresetSkillCollisions)(workspaceSkills);
319
- }
320
- if (!dryRun &&
321
- workspaceSkills.length > 0 &&
322
- workspaceSkillTargets.length > 0) {
323
- const dedupedWorkspaceSkills = (0, install_1.dedupeSkillsForInstall)(workspaceSkills);
324
- (0, install_1.writeSkillsToTargets)(dedupedWorkspaceSkills, workspaceSkillTargets);
325
- }
326
- // Merge and write agents for workspace
327
- const workspaceAgents = mergeWorkspaceAgents(packages);
328
- const workspaceAgentTargets = collectWorkspaceAgentTargets(packages);
329
- if (workspaceAgents.length > 0) {
330
- (0, install_1.warnPresetAgentCollisions)(workspaceAgents);
331
- }
332
- if (!dryRun &&
333
- workspaceAgents.length > 0 &&
334
- workspaceAgentTargets.length > 0) {
335
- const dedupedWorkspaceAgents = (0, install_1.dedupeAgentsForInstall)(workspaceAgents);
336
- (0, install_1.writeAgentsToTargets)(dedupedWorkspaceAgents, workspaceAgentTargets);
337
- }
338
- const { merged: rootMcp, conflicts } = mergeWorkspaceMcpServers(packages);
339
- const hasCursorTarget = packages.some((p) => p.config.config.targets.includes("cursor"));
340
- if (!dryRun && hasCursorTarget && Object.keys(rootMcp).length > 0) {
341
- const mcpPath = node_path_1.default.join(cwd, ".cursor", "mcp.json");
342
- (0, install_1.writeMcpServersToFile)(rootMcp, mcpPath);
343
- }
344
- for (const conflict of conflicts) {
345
- console.warn(`Warning: MCP configuration conflict detected\n Key: "${conflict.key}"\n Packages: ${conflict.packages.join(", ")}\n Using configuration from: ${conflict.chosen}`);
346
- }
347
- // Merge and write hooks for workspace
348
- const { merged: rootHooks, hookFiles: rootHookFiles } = mergeWorkspaceHooks(packages);
349
- const hasHooks = rootHooks.hooks && Object.keys(rootHooks.hooks).length > 0;
350
- if (!dryRun && hasCursorTarget && (hasHooks || rootHookFiles.length > 0)) {
351
- (0, hooks_1.writeHooksToCursor)(rootHooks, rootHookFiles, cwd);
352
- }
353
- if (verbose) {
354
- result.packages.forEach((pkg) => {
355
- if (pkg.success) {
356
- const summaryParts = [`${pkg.installedRuleCount} rules`];
357
- if (pkg.installedCommandCount > 0) {
358
- summaryParts.push(`${pkg.installedCommandCount} command${pkg.installedCommandCount === 1 ? "" : "s"}`);
359
- }
360
- if (pkg.installedHookCount > 0) {
361
- summaryParts.push(`${pkg.installedHookCount} hook${pkg.installedHookCount === 1 ? "" : "s"}`);
362
- }
363
- if (pkg.installedSkillCount > 0) {
364
- summaryParts.push(`${pkg.installedSkillCount} skill${pkg.installedSkillCount === 1 ? "" : "s"}`);
365
- }
366
- if (pkg.installedAgentCount > 0) {
367
- summaryParts.push(`${pkg.installedAgentCount} agent${pkg.installedAgentCount === 1 ? "" : "s"}`);
368
- }
369
- console.log(chalk_1.default.green(`✅ ${pkg.path} (${summaryParts.join(", ")})`));
370
- }
371
- else {
372
- console.log(chalk_1.default.red(`❌ ${pkg.path}: ${pkg.error}`));
373
- }
374
- });
375
- }
376
- const failedPackages = result.packages.filter((r) => !r.success);
377
- if (failedPackages.length > 0) {
378
- console.log(chalk_1.default.yellow(`Installation completed with errors`));
379
- if (verbose) {
380
- const commandSummary = result.totalCommandCount > 0
381
- ? `, ${result.totalCommandCount} command${result.totalCommandCount === 1 ? "" : "s"} total`
382
- : "";
383
- const hookSummary = result.totalHookCount > 0
384
- ? `, ${result.totalHookCount} hook${result.totalHookCount === 1 ? "" : "s"} total`
385
- : "";
386
- const skillSummary = result.totalSkillCount > 0
387
- ? `, ${result.totalSkillCount} skill${result.totalSkillCount === 1 ? "" : "s"} total`
388
- : "";
389
- const agentSummary = result.totalAgentCount > 0
390
- ? `, ${result.totalAgentCount} agent${result.totalAgentCount === 1 ? "" : "s"} total`
391
- : "";
392
- console.log(chalk_1.default.green(`Successfully installed: ${result.packages.length - failedPackages.length}/${result.packages.length} packages (${result.totalRuleCount} rule${result.totalRuleCount === 1 ? "" : "s"} total${commandSummary}${hookSummary}${skillSummary}${agentSummary})`));
393
- console.log(chalk_1.default.red(`Failed packages: ${failedPackages.map((p) => p.path).join(", ")}`));
394
- }
395
- const errorDetails = failedPackages
396
- .map((p) => `${p.path}: ${p.error}`)
397
- .join("; ");
398
- return {
399
- success: false,
400
- error: new Error(`Package installation failed for ${failedPackages.length} package(s): ${errorDetails}`),
401
- installedRuleCount: result.totalRuleCount,
402
- installedCommandCount: result.totalCommandCount,
403
- installedAssetCount: result.totalAssetCount,
404
- installedHookCount: result.totalHookCount,
405
- installedSkillCount: result.totalSkillCount,
406
- installedAgentCount: result.totalAgentCount,
407
- packagesCount: result.packages.length,
408
- };
409
- }
410
- return {
411
- success: true,
412
- installedRuleCount: result.totalRuleCount,
413
- installedCommandCount: result.totalCommandCount,
414
- installedAssetCount: result.totalAssetCount,
415
- installedHookCount: result.totalHookCount,
416
- installedSkillCount: result.totalSkillCount,
417
- installedAgentCount: result.totalAgentCount,
418
- packagesCount: result.packages.length,
419
- };
420
- });
421
- }
@@ -1,110 +0,0 @@
1
- import { ResolvedConfig, CommandFile, AssetFile, SkillFile, AgentFile, MCPServers, SupportedTarget } from "../utils/config";
2
- export interface InstallOptions {
3
- /**
4
- * Base directory to use instead of process.cwd()
5
- */
6
- cwd?: string;
7
- /**
8
- * Custom config object to use instead of loading from file
9
- */
10
- config?: ResolvedConfig;
11
- /**
12
- * allow installation on CI environments
13
- */
14
- installOnCI?: boolean;
15
- /**
16
- * Show verbose output during installation
17
- */
18
- verbose?: boolean;
19
- /**
20
- * Perform a dry run without writing any files
21
- */
22
- dryRun?: boolean;
23
- }
24
- /**
25
- * Result of the install operation
26
- */
27
- export interface InstallResult {
28
- /**
29
- * Whether the operation was successful
30
- */
31
- success: boolean;
32
- /**
33
- * Error object if the operation failed
34
- */
35
- error?: Error;
36
- /**
37
- * Number of rules installed
38
- */
39
- installedRuleCount: number;
40
- /**
41
- * Number of commands installed
42
- */
43
- installedCommandCount: number;
44
- /**
45
- * Number of assets installed
46
- */
47
- installedAssetCount: number;
48
- /**
49
- * Number of hooks installed
50
- */
51
- installedHookCount: number;
52
- /**
53
- * Number of skills installed
54
- */
55
- installedSkillCount: number;
56
- /**
57
- * Number of agents installed
58
- */
59
- installedAgentCount: number;
60
- /**
61
- * Number of packages installed
62
- */
63
- packagesCount: number;
64
- }
65
- export declare function writeAssetsToTargets(assets: AssetFile[], targets: SupportedTarget[]): void;
66
- export declare function writeCommandsToTargets(commands: CommandFile[], targets: SupportedTarget[]): void;
67
- /**
68
- * Write skills to all supported target directories
69
- */
70
- export declare function writeSkillsToTargets(skills: SkillFile[], targets: SupportedTarget[]): void;
71
- /**
72
- * Warn about skill name collisions from different presets
73
- */
74
- export declare function warnPresetSkillCollisions(skills: SkillFile[]): void;
75
- /**
76
- * Dedupe skills by name (last one wins)
77
- */
78
- export declare function dedupeSkillsForInstall(skills: SkillFile[]): SkillFile[];
79
- /**
80
- * Write agents to all supported target directories
81
- * Similar to skills, agents are written directly to the agents directory
82
- * with a .aicm.json metadata file tracking which agents are managed
83
- */
84
- export declare function writeAgentsToTargets(agents: AgentFile[], targets: SupportedTarget[]): void;
85
- /**
86
- * Warn about agent name collisions from different presets
87
- */
88
- export declare function warnPresetAgentCollisions(agents: AgentFile[]): void;
89
- /**
90
- * Dedupe agents by name (last one wins)
91
- */
92
- export declare function dedupeAgentsForInstall(agents: AgentFile[]): AgentFile[];
93
- export declare function warnPresetCommandCollisions(commands: CommandFile[]): void;
94
- export declare function dedupeCommandsForInstall(commands: CommandFile[]): CommandFile[];
95
- /**
96
- * Write MCP servers configuration to a specific file
97
- */
98
- export declare function writeMcpServersToFile(mcpServers: MCPServers, mcpPath: string): void;
99
- /**
100
- * Install rules for a single package (used within workspaces and standalone installs)
101
- */
102
- export declare function installPackage(options?: InstallOptions): Promise<InstallResult>;
103
- /**
104
- * Core implementation of the rule installation logic
105
- */
106
- export declare function install(options?: InstallOptions): Promise<InstallResult>;
107
- /**
108
- * CLI command wrapper for install
109
- */
110
- export declare function installCommand(installOnCI?: boolean, verbose?: boolean, dryRun?: boolean): Promise<void>;