aicm 0.8.0 → 0.9.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 +2 -2
- package/dist/commands/install.js +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/config.d.ts +10 -1
- package/dist/utils/config.js +24 -10
- package/dist/utils/rule-writer.js +53 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,12 +37,12 @@ In your project's `aicm.json`, reference the package and the specific rule:
|
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
2. **Add a
|
|
40
|
+
2. **Add a prepare script** to your `package.json`:
|
|
41
41
|
|
|
42
42
|
```json
|
|
43
43
|
{
|
|
44
44
|
"scripts": {
|
|
45
|
-
"
|
|
45
|
+
"prepare": "npx -y aicm install"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
```
|
package/dist/commands/install.js
CHANGED
|
@@ -108,6 +108,8 @@ async function install(options = {}) {
|
|
|
108
108
|
const ruleType = (0, rule_detector_1.detectRuleType)(source);
|
|
109
109
|
// Get the base path of the preset file if this rule came from a preset
|
|
110
110
|
const ruleBasePath = (0, config_1.getRuleSource)(config, name);
|
|
111
|
+
// Get the original preset path for namespacing
|
|
112
|
+
const originalPresetPath = (0, config_1.getOriginalPresetPath)(config, name);
|
|
111
113
|
// Collect the rule based on its type
|
|
112
114
|
try {
|
|
113
115
|
let ruleContent;
|
|
@@ -122,6 +124,10 @@ async function install(options = {}) {
|
|
|
122
124
|
errorMessages.push(`Unknown rule type: ${ruleType}`);
|
|
123
125
|
continue;
|
|
124
126
|
}
|
|
127
|
+
// Add the preset path to the rule content for namespacing
|
|
128
|
+
if (originalPresetPath) {
|
|
129
|
+
ruleContent.presetPath = originalPresetPath;
|
|
130
|
+
}
|
|
125
131
|
(0, rule_collector_1.addRuleToCollection)(ruleCollection, ruleContent, config.ides);
|
|
126
132
|
installedRuleCount++;
|
|
127
133
|
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/utils/config.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Config, Rules } from "../types";
|
|
2
2
|
interface ConfigWithMeta extends Config {
|
|
3
3
|
__ruleSources?: Record<string, string>;
|
|
4
|
+
__originalPresetPaths?: Record<string, string>;
|
|
4
5
|
}
|
|
5
|
-
export
|
|
6
|
+
export interface PresetPathInfo {
|
|
7
|
+
fullPath: string;
|
|
8
|
+
originalPath: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function getFullPresetPath(presetPath: string): PresetPathInfo | null;
|
|
6
11
|
/**
|
|
7
12
|
* Load a preset file and return its rules and mcpServers
|
|
8
13
|
*/
|
|
@@ -23,6 +28,10 @@ export declare function getConfig(): Config | null;
|
|
|
23
28
|
* Get the source preset path for a rule if it came from a preset
|
|
24
29
|
*/
|
|
25
30
|
export declare function getRuleSource(config: Config, ruleName: string): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get the original preset path for a rule if it came from a preset
|
|
33
|
+
*/
|
|
34
|
+
export declare function getOriginalPresetPath(config: Config, ruleName: string): string | undefined;
|
|
26
35
|
/**
|
|
27
36
|
* Save the configuration to the aicm.json file
|
|
28
37
|
*/
|
package/dist/utils/config.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.loadPreset = loadPreset;
|
|
|
8
8
|
exports.loadAicmConfigCosmiconfig = loadAicmConfigCosmiconfig;
|
|
9
9
|
exports.getConfig = getConfig;
|
|
10
10
|
exports.getRuleSource = getRuleSource;
|
|
11
|
+
exports.getOriginalPresetPath = getOriginalPresetPath;
|
|
11
12
|
exports.saveConfig = saveConfig;
|
|
12
13
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
13
14
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -15,7 +16,7 @@ const cosmiconfig_1 = require("cosmiconfig");
|
|
|
15
16
|
const CONFIG_FILE = "aicm.json";
|
|
16
17
|
function getFullPresetPath(presetPath) {
|
|
17
18
|
if (presetPath.endsWith(".json") && fs_extra_1.default.pathExistsSync(presetPath)) {
|
|
18
|
-
return presetPath;
|
|
19
|
+
return { fullPath: presetPath, originalPath: presetPath };
|
|
19
20
|
}
|
|
20
21
|
try {
|
|
21
22
|
let absolutePresetPath;
|
|
@@ -30,7 +31,9 @@ function getFullPresetPath(presetPath) {
|
|
|
30
31
|
paths: [__dirname, process.cwd()],
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
|
-
return fs_extra_1.default.existsSync(absolutePresetPath)
|
|
34
|
+
return fs_extra_1.default.existsSync(absolutePresetPath)
|
|
35
|
+
? { fullPath: absolutePresetPath, originalPath: presetPath }
|
|
36
|
+
: null;
|
|
34
37
|
}
|
|
35
38
|
catch (_a) {
|
|
36
39
|
return null;
|
|
@@ -40,11 +43,11 @@ function getFullPresetPath(presetPath) {
|
|
|
40
43
|
* Load a preset file and return its rules and mcpServers
|
|
41
44
|
*/
|
|
42
45
|
function loadPreset(presetPath) {
|
|
43
|
-
const
|
|
44
|
-
if (!
|
|
46
|
+
const pathInfo = getFullPresetPath(presetPath);
|
|
47
|
+
if (!pathInfo) {
|
|
45
48
|
throw new Error(`Error loading preset: "${presetPath}". Make sure the package is installed in your project.`);
|
|
46
49
|
}
|
|
47
|
-
const presetContent = fs_extra_1.default.readFileSync(
|
|
50
|
+
const presetContent = fs_extra_1.default.readFileSync(pathInfo.fullPath, "utf8");
|
|
48
51
|
let preset;
|
|
49
52
|
try {
|
|
50
53
|
preset = JSON.parse(presetContent);
|
|
@@ -69,10 +72,10 @@ function processPresets(config) {
|
|
|
69
72
|
const preset = loadPreset(presetPath);
|
|
70
73
|
if (!preset)
|
|
71
74
|
continue;
|
|
72
|
-
const
|
|
73
|
-
if (!
|
|
75
|
+
const pathInfo = getFullPresetPath(presetPath);
|
|
76
|
+
if (!pathInfo)
|
|
74
77
|
continue;
|
|
75
|
-
mergePresetRules(config, preset.rules,
|
|
78
|
+
mergePresetRules(config, preset.rules, pathInfo);
|
|
76
79
|
if (preset.mcpServers) {
|
|
77
80
|
mergePresetMcpServers(config, preset.mcpServers);
|
|
78
81
|
}
|
|
@@ -81,7 +84,7 @@ function processPresets(config) {
|
|
|
81
84
|
/**
|
|
82
85
|
* Merge preset rules into the config
|
|
83
86
|
*/
|
|
84
|
-
function mergePresetRules(config, presetRules,
|
|
87
|
+
function mergePresetRules(config, presetRules, pathInfo) {
|
|
85
88
|
for (const [ruleName, rulePath] of Object.entries(presetRules)) {
|
|
86
89
|
// Cancel if set to false in config
|
|
87
90
|
if (Object.prototype.hasOwnProperty.call(config.rules, ruleName) &&
|
|
@@ -89,13 +92,17 @@ function mergePresetRules(config, presetRules, presetPath) {
|
|
|
89
92
|
delete config.rules[ruleName];
|
|
90
93
|
if (config.__ruleSources)
|
|
91
94
|
delete config.__ruleSources[ruleName];
|
|
95
|
+
if (config.__originalPresetPaths)
|
|
96
|
+
delete config.__originalPresetPaths[ruleName];
|
|
92
97
|
continue;
|
|
93
98
|
}
|
|
94
99
|
// Only add if not already defined in config (override handled by config)
|
|
95
100
|
if (!Object.prototype.hasOwnProperty.call(config.rules, ruleName)) {
|
|
96
101
|
config.rules[ruleName] = rulePath;
|
|
97
102
|
config.__ruleSources = config.__ruleSources || {};
|
|
98
|
-
config.__ruleSources[ruleName] =
|
|
103
|
+
config.__ruleSources[ruleName] = pathInfo.fullPath;
|
|
104
|
+
config.__originalPresetPaths = config.__originalPresetPaths || {};
|
|
105
|
+
config.__originalPresetPaths[ruleName] = pathInfo.originalPath;
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
}
|
|
@@ -159,6 +166,13 @@ function getRuleSource(config, ruleName) {
|
|
|
159
166
|
var _a;
|
|
160
167
|
return (_a = config.__ruleSources) === null || _a === void 0 ? void 0 : _a[ruleName];
|
|
161
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Get the original preset path for a rule if it came from a preset
|
|
171
|
+
*/
|
|
172
|
+
function getOriginalPresetPath(config, ruleName) {
|
|
173
|
+
var _a;
|
|
174
|
+
return (_a = config.__originalPresetPaths) === null || _a === void 0 ? void 0 : _a[ruleName];
|
|
175
|
+
}
|
|
162
176
|
/**
|
|
163
177
|
* Save the configuration to the aicm.json file
|
|
164
178
|
*/
|
|
@@ -23,6 +23,21 @@ function writeRulesToTargets(collection) {
|
|
|
23
23
|
writeWindsurfRulesFromCollection(collection.windsurf, idePaths.windsurf);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Extract a normalized namespace from a preset path
|
|
28
|
+
* @param presetPath The original preset path
|
|
29
|
+
* @returns An array of path segments to use for namespacing
|
|
30
|
+
*/
|
|
31
|
+
function extractNamespaceFromPresetPath(presetPath) {
|
|
32
|
+
// Special case: npm package names always use forward slashes, regardless of platform
|
|
33
|
+
if (presetPath.startsWith("@")) {
|
|
34
|
+
// For scoped packages like @scope/package/subdir, create nested directories
|
|
35
|
+
return presetPath.split("/");
|
|
36
|
+
}
|
|
37
|
+
// Handle both Unix and Windows style path separators
|
|
38
|
+
const parts = presetPath.split(/[/\\]/);
|
|
39
|
+
return parts.filter((part) => part.length > 0); // Filter out empty segments
|
|
40
|
+
}
|
|
26
41
|
/**
|
|
27
42
|
* Write rules to Cursor's rules directory
|
|
28
43
|
* @param rules The rules to write
|
|
@@ -31,7 +46,20 @@ function writeRulesToTargets(collection) {
|
|
|
31
46
|
function writeCursorRules(rules, cursorRulesDir) {
|
|
32
47
|
fs_extra_1.default.emptyDirSync(cursorRulesDir);
|
|
33
48
|
for (const rule of rules) {
|
|
34
|
-
|
|
49
|
+
let rulePath;
|
|
50
|
+
// Parse rule name into path segments using platform-specific path separator
|
|
51
|
+
const ruleNameParts = rule.name.split(/[/\\]/).filter(Boolean);
|
|
52
|
+
if (rule.presetPath) {
|
|
53
|
+
// For rules from presets, create a namespaced directory structure
|
|
54
|
+
const namespace = extractNamespaceFromPresetPath(rule.presetPath);
|
|
55
|
+
// Path will be: cursorRulesDir/namespace/rule-name.mdc
|
|
56
|
+
rulePath = node_path_1.default.join(cursorRulesDir, ...namespace, ...ruleNameParts);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// For local rules, maintain the original flat structure
|
|
60
|
+
rulePath = node_path_1.default.join(cursorRulesDir, ...ruleNameParts);
|
|
61
|
+
}
|
|
62
|
+
const ruleFile = rulePath + ".mdc";
|
|
35
63
|
fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(ruleFile));
|
|
36
64
|
if (fs_extra_1.default.existsSync(rule.sourcePath)) {
|
|
37
65
|
fs_extra_1.default.copyFileSync(rule.sourcePath, ruleFile);
|
|
@@ -49,11 +77,33 @@ function writeCursorRules(rules, cursorRulesDir) {
|
|
|
49
77
|
function writeWindsurfRulesFromCollection(rules, ruleDir) {
|
|
50
78
|
fs_extra_1.default.emptyDirSync(ruleDir);
|
|
51
79
|
const ruleFiles = rules.map((rule) => {
|
|
52
|
-
|
|
80
|
+
let rulePath;
|
|
81
|
+
// Parse rule name into path segments using platform-specific path separator
|
|
82
|
+
const ruleNameParts = rule.name.split(/[/\\]/).filter(Boolean);
|
|
83
|
+
if (rule.presetPath) {
|
|
84
|
+
// For rules from presets, create a namespaced directory structure
|
|
85
|
+
const namespace = extractNamespaceFromPresetPath(rule.presetPath);
|
|
86
|
+
// Path will be: ruleDir/namespace/rule-name.md
|
|
87
|
+
rulePath = node_path_1.default.join(ruleDir, ...namespace, ...ruleNameParts);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// For local rules, maintain the original flat structure
|
|
91
|
+
rulePath = node_path_1.default.join(ruleDir, ...ruleNameParts);
|
|
92
|
+
}
|
|
93
|
+
const physicalRulePath = rulePath + ".md";
|
|
53
94
|
fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(physicalRulePath));
|
|
54
95
|
fs_extra_1.default.writeFileSync(physicalRulePath, rule.content);
|
|
55
96
|
const relativeRuleDir = node_path_1.default.basename(ruleDir); // Gets '.rules'
|
|
56
|
-
|
|
97
|
+
// For the Windsurf rules file, we need to maintain the same structure
|
|
98
|
+
let windsurfPath;
|
|
99
|
+
if (rule.presetPath) {
|
|
100
|
+
const namespace = extractNamespaceFromPresetPath(rule.presetPath);
|
|
101
|
+
windsurfPath =
|
|
102
|
+
node_path_1.default.join(relativeRuleDir, ...namespace, ...ruleNameParts) + ".md";
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
windsurfPath = node_path_1.default.join(relativeRuleDir, ...ruleNameParts) + ".md";
|
|
106
|
+
}
|
|
57
107
|
// Normalize to POSIX style for cross-platform compatibility in .windsurfrules
|
|
58
108
|
const windsurfPathPosix = windsurfPath.replace(/\\/g, "/");
|
|
59
109
|
return {
|