aicm 0.14.5 → 0.15.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.
package/README.md CHANGED
@@ -160,6 +160,7 @@ aicm automatically detects workspaces if your `package.json` contains a `workspa
160
160
 
161
161
  1. **Discover packages**: Automatically find all directories containing `aicm.json` files in your repository
162
162
  2. **Install per package**: Install rules and MCPs for each package individually in their respective directories
163
+ 3. **Merge MCP servers**: Write a merged `.cursor/mcp.json` at the repository root containing all MCP servers from every package
163
164
 
164
165
  ### How It Works
165
166
 
@@ -185,6 +186,20 @@ Running `npx aicm install` will install rules for each package in their respecti
185
186
  - `packages/backend/.cursor/rules/aicm/`
186
187
  - `services/api/.cursor/rules/aicm/`
187
188
 
189
+ ### Preset Packages in Workspaces
190
+
191
+ When you have a preset package within your workspace (a package that provides rules to be consumed by others), you can prevent aicm from installing rules into it by setting `skipInstall: true`:
192
+
193
+ ```json
194
+ {
195
+ "skipInstall": true,
196
+ "rulesDir": "./rules",
197
+ "targets": ["cursor"]
198
+ }
199
+ ```
200
+
201
+ This is useful when your workspace contains both consumer packages (that need rules installed) and provider packages (that only export rules).
202
+
188
203
  ## Configuration
189
204
 
190
205
  Create an `aicm.json` file in your project root, or an `aicm` key in your project's `package.json`.
@@ -195,7 +210,8 @@ Create an `aicm.json` file in your project root, or an `aicm` key in your projec
195
210
  "targets": ["cursor"],
196
211
  "presets": [],
197
212
  "overrides": {},
198
- "mcpServers": {}
213
+ "mcpServers": {},
214
+ "skipInstall": false
199
215
  }
200
216
  ```
201
217
 
@@ -205,6 +221,7 @@ Create an `aicm.json` file in your project root, or an `aicm` key in your projec
205
221
  - **overrides**: Map of rule names to `false` (disable) or a replacement file path.
206
222
  - **mcpServers**: MCP server configurations.
207
223
  - **workspaces**: Set to `true` to enable workspace mode. If not specified, aicm will automatically detect workspaces from your `package.json`.
224
+ - **skipInstall**: Set to `true` to skip rule installation for this package. Useful for preset packages that provide rules but shouldn't have rules installed into them.
208
225
 
209
226
  ### MCP Server Installation
210
227
 
@@ -13,6 +13,7 @@ const child_process_1 = require("child_process");
13
13
  const config_1 = require("../utils/config");
14
14
  const working_directory_1 = require("../utils/working-directory");
15
15
  const is_ci_1 = require("../utils/is-ci");
16
+ const rules_file_writer_1 = require("../utils/rules-file-writer");
16
17
  function getTargetPaths() {
17
18
  const projectDir = process.cwd();
18
19
  return {
@@ -50,80 +51,6 @@ function extractNamespaceFromPresetPath(presetPath) {
50
51
  const parts = presetPath.split(node_path_1.default.sep);
51
52
  return parts.filter((part) => part.length > 0); // Filter out empty segments
52
53
  }
53
- function generateRulesFileContent(ruleFiles) {
54
- const alwaysApplyRules = [];
55
- const optInRules = [];
56
- for (const rule of ruleFiles) {
57
- // Parse metadata to determine rule type
58
- const metadata = rule.content.match(/^---\n([\s\S]*?)\n---/);
59
- let alwaysApply = false;
60
- if (metadata) {
61
- try {
62
- const frontmatter = metadata[1];
63
- // Simple YAML parsing for alwaysApply field
64
- const alwaysApplyMatch = frontmatter.match(/alwaysApply:\s*(true|false)/);
65
- if (alwaysApplyMatch) {
66
- alwaysApply = alwaysApplyMatch[1] === "true";
67
- }
68
- }
69
- catch (_a) {
70
- // If parsing fails, default to false
71
- }
72
- }
73
- if (alwaysApply) {
74
- alwaysApplyRules.push(`- ${rule.path}`);
75
- }
76
- else {
77
- optInRules.push(`- ${rule.path}`);
78
- }
79
- }
80
- let content = "<!-- AICM:BEGIN -->\n";
81
- if (alwaysApplyRules.length > 0) {
82
- content +=
83
- "The following rules always apply to all files in the project:\n";
84
- content += alwaysApplyRules.join("\n") + "\n\n";
85
- }
86
- if (optInRules.length > 0) {
87
- content +=
88
- "The following rules are available for the AI to include when needed:\n";
89
- content += optInRules.join("\n") + "\n\n";
90
- }
91
- content += "<!-- AICM:END -->";
92
- return content;
93
- }
94
- /**
95
- * Write rules file content to a file, preserving existing content outside markers
96
- */
97
- function writeRulesFile(rulesContent, rulesFilePath) {
98
- const RULES_BEGIN = "<!-- AICM:BEGIN -->";
99
- const RULES_END = "<!-- AICM:END -->";
100
- let fileContent;
101
- if (fs_extra_1.default.existsSync(rulesFilePath)) {
102
- const existingContent = fs_extra_1.default.readFileSync(rulesFilePath, "utf8");
103
- if (existingContent.includes(RULES_BEGIN) &&
104
- existingContent.includes(RULES_END)) {
105
- const beforeMarker = existingContent.split(RULES_BEGIN)[0];
106
- const afterMarker = existingContent.split(RULES_END)[1];
107
- fileContent = beforeMarker + rulesContent + afterMarker;
108
- }
109
- else {
110
- // Preserve the existing content and append markers
111
- let separator = "";
112
- if (!existingContent.endsWith("\n")) {
113
- separator += "\n";
114
- }
115
- if (!existingContent.endsWith("\n\n")) {
116
- separator += "\n";
117
- }
118
- fileContent = existingContent + separator + rulesContent;
119
- }
120
- }
121
- else {
122
- // Create new file with markers and content
123
- fileContent = rulesContent + "\n";
124
- }
125
- fs_extra_1.default.writeFileSync(rulesFilePath, fileContent);
126
- }
127
54
  /**
128
55
  * Write rules to a shared directory and update the given rules file
129
56
  */
@@ -161,11 +88,11 @@ function writeRulesForFile(rules, ruleDir, rulesFile) {
161
88
  return {
162
89
  name: rule.name,
163
90
  path: windsurfPathPosix,
164
- content: rule.content,
91
+ metadata: (0, rules_file_writer_1.parseRuleFrontmatter)(rule.content),
165
92
  };
166
93
  });
167
- const rulesContent = generateRulesFileContent(ruleFiles);
168
- writeRulesFile(rulesContent, node_path_1.default.join(process.cwd(), rulesFile));
94
+ const rulesContent = (0, rules_file_writer_1.generateRulesFileContent)(ruleFiles);
95
+ (0, rules_file_writer_1.writeRulesFile)(rulesContent, node_path_1.default.join(process.cwd(), rulesFile));
169
96
  }
170
97
  /**
171
98
  * Write all collected rules to their respective IDE targets
@@ -245,6 +172,37 @@ function writeMcpServersToFile(mcpServers, mcpPath) {
245
172
  };
246
173
  fs_extra_1.default.writeJsonSync(mcpPath, mergedConfig, { spaces: 2 });
247
174
  }
175
+ function mergeWorkspaceMcpServers(packages) {
176
+ const merged = {};
177
+ const info = {};
178
+ for (const pkg of packages) {
179
+ for (const [key, value] of Object.entries(pkg.config.mcpServers)) {
180
+ if (value === false)
181
+ continue;
182
+ const json = JSON.stringify(value);
183
+ if (!info[key]) {
184
+ info[key] = {
185
+ configs: new Set([json]),
186
+ packages: [pkg.relativePath],
187
+ chosen: pkg.relativePath,
188
+ };
189
+ }
190
+ else {
191
+ info[key].packages.push(pkg.relativePath);
192
+ info[key].configs.add(json);
193
+ info[key].chosen = pkg.relativePath;
194
+ }
195
+ merged[key] = value;
196
+ }
197
+ }
198
+ const conflicts = [];
199
+ for (const [key, data] of Object.entries(info)) {
200
+ if (data.configs.size > 1) {
201
+ conflicts.push({ key, packages: data.packages, chosen: data.chosen });
202
+ }
203
+ }
204
+ return { merged, conflicts };
205
+ }
248
206
  /**
249
207
  * Discover all packages with aicm configurations using git ls-files
250
208
  */
@@ -310,17 +268,12 @@ async function installPackage(options = {}) {
310
268
  };
311
269
  }
312
270
  const { config, rules, mcpServers } = resolvedConfig;
313
- // Check if rules are defined (either directly or through presets)
314
- if (!rules || rules.length === 0) {
315
- // If there are no presets defined either, show a message
316
- if (!config.presets || config.presets.length === 0) {
317
- return {
318
- success: false,
319
- error: new Error("No rules defined in configuration"),
320
- installedRuleCount: 0,
321
- packagesCount: 0,
322
- };
323
- }
271
+ if (config.skipInstall === true) {
272
+ return {
273
+ success: true,
274
+ installedRuleCount: 0,
275
+ packagesCount: 0,
276
+ };
324
277
  }
325
278
  try {
326
279
  if (!options.dryRun) {
@@ -396,6 +349,9 @@ async function installWorkspaces(cwd, installOnCI, verbose = false, dryRun = fal
396
349
  }
397
350
  const allPackages = await discoverPackagesWithAicm(cwd);
398
351
  const packages = allPackages.filter((pkg) => {
352
+ if (pkg.config.config.skipInstall === true) {
353
+ return false;
354
+ }
399
355
  const isRoot = pkg.relativePath === ".";
400
356
  if (!isRoot)
401
357
  return true;
@@ -424,6 +380,15 @@ async function installWorkspaces(cwd, installOnCI, verbose = false, dryRun = fal
424
380
  verbose,
425
381
  dryRun,
426
382
  });
383
+ const { merged: rootMcp, conflicts } = mergeWorkspaceMcpServers(packages);
384
+ const hasCursorTarget = packages.some((p) => p.config.config.targets.includes("cursor"));
385
+ if (!dryRun && hasCursorTarget && Object.keys(rootMcp).length > 0) {
386
+ const mcpPath = node_path_1.default.join(cwd, ".cursor", "mcp.json");
387
+ writeMcpServersToFile(rootMcp, mcpPath);
388
+ }
389
+ for (const conflict of conflicts) {
390
+ console.warn(`Warning: MCP configuration conflict detected\n Key: "${conflict.key}"\n Packages: ${conflict.packages.join(", ")}\n Using configuration from: ${conflict.chosen}`);
391
+ }
427
392
  if (verbose) {
428
393
  result.packages.forEach((pkg) => {
429
394
  if (pkg.success) {
@@ -508,6 +473,9 @@ async function installCommand(installOnCI, verbose, dryRun) {
508
473
  console.log(`Dry run: validated ${rulesInstalledMessage}`);
509
474
  }
510
475
  }
476
+ else if (result.installedRuleCount === 0) {
477
+ console.log("No rules installed");
478
+ }
511
479
  else if (result.packagesCount > 1) {
512
480
  console.log(`Successfully installed ${rulesInstalledMessage} across ${result.packagesCount} packages`);
513
481
  }
@@ -6,6 +6,7 @@ export interface RawConfig {
6
6
  overrides?: Record<string, string | false>;
7
7
  mcpServers?: MCPServers;
8
8
  workspaces?: boolean;
9
+ skipInstall?: boolean;
9
10
  }
10
11
  export interface Config {
11
12
  rulesDir?: string;
@@ -14,6 +15,7 @@ export interface Config {
14
15
  overrides?: Record<string, string | false>;
15
16
  mcpServers?: MCPServers;
16
17
  workspaces?: boolean;
18
+ skipInstall?: boolean;
17
19
  }
18
20
  export type MCPServer = {
19
21
  command: string;
@@ -44,7 +46,7 @@ export interface ResolvedConfig {
44
46
  rules: RuleFile[];
45
47
  mcpServers: MCPServers;
46
48
  }
47
- export declare const ALLOWED_CONFIG_KEYS: readonly ["rulesDir", "targets", "presets", "overrides", "mcpServers", "workspaces"];
49
+ export declare const ALLOWED_CONFIG_KEYS: readonly ["rulesDir", "targets", "presets", "overrides", "mcpServers", "workspaces", "skipInstall"];
48
50
  export declare const SUPPORTED_TARGETS: readonly ["cursor", "windsurf", "codex"];
49
51
  export type SupportedTarget = (typeof SUPPORTED_TARGETS)[number];
50
52
  export declare function detectWorkspacesFromPackageJson(cwd: string): boolean;
@@ -27,6 +27,7 @@ exports.ALLOWED_CONFIG_KEYS = [
27
27
  "overrides",
28
28
  "mcpServers",
29
29
  "workspaces",
30
+ "skipInstall",
30
31
  ];
31
32
  exports.SUPPORTED_TARGETS = ["cursor", "windsurf", "codex"];
32
33
  function detectWorkspacesFromPackageJson(cwd) {
@@ -60,6 +61,7 @@ function applyDefaults(config, workspaces) {
60
61
  overrides: config.overrides || {},
61
62
  mcpServers: config.mcpServers || {},
62
63
  workspaces,
64
+ skipInstall: config.skipInstall || false,
63
65
  };
64
66
  }
65
67
  function validateConfig(config, configFilePath, cwd, isWorkspaceMode = false) {
@@ -1,3 +1,8 @@
1
+ export type RuleMetadata = Record<string, string | boolean | string[]>;
2
+ /**
3
+ * Parse YAML frontmatter blocks from a rule file and return a flat metadata object
4
+ */
5
+ export declare function parseRuleFrontmatter(content: string): RuleMetadata;
1
6
  /**
2
7
  * Write rules to the .windsurfrules file
3
8
  * This will update the content between the RULES_BEGIN and RULES_END markers
@@ -3,10 +3,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseRuleFrontmatter = parseRuleFrontmatter;
6
7
  exports.writeRulesFile = writeRulesFile;
7
8
  exports.generateRulesFileContent = generateRulesFileContent;
8
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
10
  const path_1 = __importDefault(require("path"));
11
+ /**
12
+ * Parse YAML frontmatter blocks from a rule file and return a flat metadata object
13
+ */
14
+ function parseRuleFrontmatter(content) {
15
+ const metadata = {};
16
+ // Support both LF and CRLF line endings
17
+ const frontmatterRegex = /^---\r?\n([\s\S]*?)\r?\n---/gm;
18
+ let match;
19
+ while ((match = frontmatterRegex.exec(content)) !== null) {
20
+ const lines = match[1].split("\n");
21
+ for (const line of lines) {
22
+ const trimmed = line.trim();
23
+ if (!trimmed)
24
+ continue;
25
+ const [key, ...rest] = trimmed.split(":");
26
+ if (!key)
27
+ continue;
28
+ const raw = rest.join(":").trim();
29
+ if (raw === "") {
30
+ metadata[key] = "";
31
+ }
32
+ else if (raw === "true" || raw === "false") {
33
+ metadata[key] = raw === "true";
34
+ }
35
+ else if (raw.startsWith("[") && raw.endsWith("]")) {
36
+ try {
37
+ const parsed = JSON.parse(raw.replace(/'/g, '"'));
38
+ metadata[key] = parsed;
39
+ }
40
+ catch (_a) {
41
+ metadata[key] = raw;
42
+ }
43
+ }
44
+ else if ((raw.startsWith('"') && raw.endsWith('"')) ||
45
+ (raw.startsWith("'") && raw.endsWith("'"))) {
46
+ metadata[key] = raw.slice(1, -1);
47
+ }
48
+ else {
49
+ metadata[key] = raw;
50
+ }
51
+ }
52
+ }
53
+ return metadata;
54
+ }
10
55
  const RULES_BEGIN = "<!-- AICM:BEGIN -->";
11
56
  const RULES_END = "<!-- AICM:END -->";
12
57
  const WARNING = "<!-- WARNING: Everything between these markers will be overwritten during installation -->";
@@ -118,7 +163,7 @@ function generateRulesFileContent(ruleFiles) {
118
163
  // Agent Requested rules
119
164
  if (agentRequestedRules.length > 0) {
120
165
  content +=
121
- "The following rules are available for the AI to include when needed:\n";
166
+ "The following rules can be loaded when relevant. Check each file's description:\n";
122
167
  agentRequestedRules.forEach((rule) => {
123
168
  content += `- ${rule}\n`;
124
169
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicm",
3
- "version": "0.14.5",
3
+ "version": "0.15.0",
4
4
  "description": "A TypeScript CLI tool for managing AI IDE rules across different projects and teams",
5
5
  "main": "dist/api.js",
6
6
  "types": "dist/api.d.ts",