@a1st/aix-core 0.0.12 → 0.2.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/dist/backup.d.ts.map +1 -1
- package/dist/backup.js +13 -14
- package/dist/backup.js.map +1 -1
- package/dist/cache/cleanup.d.ts.map +1 -1
- package/dist/cache/cleanup.js +7 -8
- package/dist/cache/cleanup.js.map +1 -1
- package/dist/cache/clear.js +4 -4
- package/dist/cache/clear.js.map +1 -1
- package/dist/cache/status.d.ts.map +1 -1
- package/dist/cache/status.js +4 -5
- package/dist/cache/status.js.map +1 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +18 -17
- package/dist/discovery.js.map +1 -1
- package/dist/editors/adapters/base.d.ts +8 -4
- package/dist/editors/adapters/base.d.ts.map +1 -1
- package/dist/editors/adapters/base.js +131 -40
- package/dist/editors/adapters/base.js.map +1 -1
- package/dist/editors/adapters/claude-code.d.ts +3 -3
- package/dist/editors/adapters/claude-code.d.ts.map +1 -1
- package/dist/editors/adapters/claude-code.js +7 -6
- package/dist/editors/adapters/claude-code.js.map +1 -1
- package/dist/editors/adapters/codex.d.ts +20 -10
- package/dist/editors/adapters/codex.d.ts.map +1 -1
- package/dist/editors/adapters/codex.js +67 -30
- package/dist/editors/adapters/codex.js.map +1 -1
- package/dist/editors/adapters/copilot.d.ts +6 -3
- package/dist/editors/adapters/copilot.d.ts.map +1 -1
- package/dist/editors/adapters/copilot.js +53 -10
- package/dist/editors/adapters/copilot.js.map +1 -1
- package/dist/editors/adapters/cursor.d.ts +2 -2
- package/dist/editors/adapters/cursor.d.ts.map +1 -1
- package/dist/editors/adapters/cursor.js +3 -2
- package/dist/editors/adapters/cursor.js.map +1 -1
- package/dist/editors/adapters/gemini.d.ts +44 -0
- package/dist/editors/adapters/gemini.d.ts.map +1 -0
- package/dist/editors/adapters/gemini.js +139 -0
- package/dist/editors/adapters/gemini.js.map +1 -0
- package/dist/editors/adapters/index.d.ts +2 -0
- package/dist/editors/adapters/index.d.ts.map +1 -1
- package/dist/editors/adapters/index.js +2 -0
- package/dist/editors/adapters/index.js.map +1 -1
- package/dist/editors/adapters/opencode.d.ts +25 -0
- package/dist/editors/adapters/opencode.d.ts.map +1 -0
- package/dist/editors/adapters/opencode.js +74 -0
- package/dist/editors/adapters/opencode.js.map +1 -0
- package/dist/editors/adapters/windsurf.d.ts +1 -1
- package/dist/editors/adapters/windsurf.d.ts.map +1 -1
- package/dist/editors/adapters/windsurf.js +2 -1
- package/dist/editors/adapters/windsurf.js.map +1 -1
- package/dist/editors/adapters/zed.d.ts.map +1 -1
- package/dist/editors/adapters/zed.js +8 -3
- package/dist/editors/adapters/zed.js.map +1 -1
- package/dist/editors/import.d.ts +62 -1
- package/dist/editors/import.d.ts.map +1 -1
- package/dist/editors/import.js +431 -188
- package/dist/editors/import.js.map +1 -1
- package/dist/editors/index.d.ts +4 -4
- package/dist/editors/index.d.ts.map +1 -1
- package/dist/editors/index.js +2 -2
- package/dist/editors/index.js.map +1 -1
- package/dist/editors/install.d.ts.map +1 -1
- package/dist/editors/install.js +57 -11
- package/dist/editors/install.js.map +1 -1
- package/dist/editors/prompt-skill-installer.d.ts +17 -0
- package/dist/editors/prompt-skill-installer.d.ts.map +1 -0
- package/dist/editors/prompt-skill-installer.js +23 -0
- package/dist/editors/prompt-skill-installer.js.map +1 -0
- package/dist/editors/section-managed-markdown.d.ts +33 -0
- package/dist/editors/section-managed-markdown.d.ts.map +1 -0
- package/dist/editors/section-managed-markdown.js +97 -0
- package/dist/editors/section-managed-markdown.js.map +1 -0
- package/dist/editors/strategies/claude-code/hooks.d.ts +6 -1
- package/dist/editors/strategies/claude-code/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/hooks.js +278 -29
- package/dist/editors/strategies/claude-code/hooks.js.map +1 -1
- package/dist/editors/strategies/claude-code/mcp.d.ts +3 -2
- package/dist/editors/strategies/claude-code/mcp.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/mcp.js +8 -7
- package/dist/editors/strategies/claude-code/mcp.js.map +1 -1
- package/dist/editors/strategies/claude-code/prompts.d.ts +1 -1
- package/dist/editors/strategies/claude-code/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/prompts.js +18 -39
- package/dist/editors/strategies/claude-code/prompts.js.map +1 -1
- package/dist/editors/strategies/claude-code/rules.d.ts +1 -0
- package/dist/editors/strategies/claude-code/rules.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/rules.js +6 -3
- package/dist/editors/strategies/claude-code/rules.js.map +1 -1
- package/dist/editors/strategies/codex/prompts.d.ts +6 -5
- package/dist/editors/strategies/codex/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/codex/prompts.js +34 -55
- package/dist/editors/strategies/codex/prompts.js.map +1 -1
- package/dist/editors/strategies/codex/rules.d.ts +2 -1
- package/dist/editors/strategies/codex/rules.d.ts.map +1 -1
- package/dist/editors/strategies/codex/rules.js +22 -0
- package/dist/editors/strategies/codex/rules.js.map +1 -1
- package/dist/editors/strategies/copilot/hooks.d.ts +8 -4
- package/dist/editors/strategies/copilot/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/copilot/hooks.js +231 -60
- package/dist/editors/strategies/copilot/hooks.js.map +1 -1
- package/dist/editors/strategies/copilot/mcp.d.ts +4 -2
- package/dist/editors/strategies/copilot/mcp.d.ts.map +1 -1
- package/dist/editors/strategies/copilot/mcp.js +83 -41
- package/dist/editors/strategies/copilot/mcp.js.map +1 -1
- package/dist/editors/strategies/copilot/prompts.d.ts +2 -1
- package/dist/editors/strategies/copilot/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/copilot/prompts.js +21 -71
- package/dist/editors/strategies/copilot/prompts.js.map +1 -1
- package/dist/editors/strategies/cursor/hooks.d.ts +8 -2
- package/dist/editors/strategies/cursor/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/cursor/hooks.js +174 -22
- package/dist/editors/strategies/cursor/hooks.js.map +1 -1
- package/dist/editors/strategies/cursor/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/cursor/prompts.js +11 -44
- package/dist/editors/strategies/cursor/prompts.js.map +1 -1
- package/dist/editors/strategies/cursor/rules.js +3 -3
- package/dist/editors/strategies/cursor/rules.js.map +1 -1
- package/dist/editors/strategies/gemini/hooks.d.ts +18 -0
- package/dist/editors/strategies/gemini/hooks.d.ts.map +1 -0
- package/dist/editors/strategies/gemini/hooks.js +152 -0
- package/dist/editors/strategies/gemini/hooks.js.map +1 -0
- package/dist/editors/strategies/gemini/index.d.ts +5 -0
- package/dist/editors/strategies/gemini/index.d.ts.map +1 -0
- package/dist/editors/strategies/gemini/index.js +5 -0
- package/dist/editors/strategies/gemini/index.js.map +1 -0
- package/dist/editors/strategies/gemini/mcp.d.ts +19 -0
- package/dist/editors/strategies/gemini/mcp.d.ts.map +1 -0
- package/dist/editors/strategies/gemini/mcp.js +73 -0
- package/dist/editors/strategies/gemini/mcp.js.map +1 -0
- package/dist/editors/strategies/gemini/prompts.d.ts +34 -0
- package/dist/editors/strategies/gemini/prompts.d.ts.map +1 -0
- package/dist/editors/strategies/gemini/prompts.js +92 -0
- package/dist/editors/strategies/gemini/prompts.js.map +1 -0
- package/dist/editors/strategies/gemini/rules.d.ts +19 -0
- package/dist/editors/strategies/gemini/rules.d.ts.map +1 -0
- package/dist/editors/strategies/gemini/rules.js +58 -0
- package/dist/editors/strategies/gemini/rules.js.map +1 -0
- package/dist/editors/strategies/index.d.ts +1 -0
- package/dist/editors/strategies/index.d.ts.map +1 -1
- package/dist/editors/strategies/index.js +1 -0
- package/dist/editors/strategies/index.js.map +1 -1
- package/dist/editors/strategies/opencode/import-utils.d.ts +5 -0
- package/dist/editors/strategies/opencode/import-utils.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/import-utils.js +181 -0
- package/dist/editors/strategies/opencode/import-utils.js.map +1 -0
- package/dist/editors/strategies/opencode/index.d.ts +4 -0
- package/dist/editors/strategies/opencode/index.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/index.js +4 -0
- package/dist/editors/strategies/opencode/index.js.map +1 -0
- package/dist/editors/strategies/opencode/mcp.d.ts +19 -0
- package/dist/editors/strategies/opencode/mcp.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/mcp.js +145 -0
- package/dist/editors/strategies/opencode/mcp.js.map +1 -0
- package/dist/editors/strategies/opencode/prompts.d.ts +22 -0
- package/dist/editors/strategies/opencode/prompts.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/prompts.js +102 -0
- package/dist/editors/strategies/opencode/prompts.js.map +1 -0
- package/dist/editors/strategies/opencode/rules.d.ts +19 -0
- package/dist/editors/strategies/opencode/rules.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/rules.js +99 -0
- package/dist/editors/strategies/opencode/rules.js.map +1 -0
- package/dist/editors/strategies/shared/global-mcp.d.ts.map +1 -1
- package/dist/editors/strategies/shared/global-mcp.js +4 -6
- package/dist/editors/strategies/shared/global-mcp.js.map +1 -1
- package/dist/editors/strategies/shared/hook-import-utils.d.ts +21 -0
- package/dist/editors/strategies/shared/hook-import-utils.d.ts.map +1 -0
- package/dist/editors/strategies/shared/hook-import-utils.js +98 -0
- package/dist/editors/strategies/shared/hook-import-utils.js.map +1 -0
- package/dist/editors/strategies/shared/native-skills.d.ts +10 -4
- package/dist/editors/strategies/shared/native-skills.d.ts.map +1 -1
- package/dist/editors/strategies/shared/native-skills.js +29 -23
- package/dist/editors/strategies/shared/native-skills.js.map +1 -1
- package/dist/editors/strategies/shared/no-hooks.d.ts +8 -3
- package/dist/editors/strategies/shared/no-hooks.d.ts.map +1 -1
- package/dist/editors/strategies/shared/no-hooks.js +17 -2
- package/dist/editors/strategies/shared/no-hooks.js.map +1 -1
- package/dist/editors/strategies/shared/pointer-skills.d.ts +7 -2
- package/dist/editors/strategies/shared/pointer-skills.d.ts.map +1 -1
- package/dist/editors/strategies/shared/pointer-skills.js +21 -10
- package/dist/editors/strategies/shared/pointer-skills.js.map +1 -1
- package/dist/editors/strategies/shared/prompt-utils.d.ts +30 -0
- package/dist/editors/strategies/shared/prompt-utils.d.ts.map +1 -0
- package/dist/editors/strategies/shared/prompt-utils.js +101 -0
- package/dist/editors/strategies/shared/prompt-utils.js.map +1 -0
- package/dist/editors/strategies/types.d.ts +104 -2
- package/dist/editors/strategies/types.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/hooks.d.ts +6 -1
- package/dist/editors/strategies/windsurf/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/hooks.js +106 -20
- package/dist/editors/strategies/windsurf/hooks.js.map +1 -1
- package/dist/editors/strategies/windsurf/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/prompts.js +14 -62
- package/dist/editors/strategies/windsurf/prompts.js.map +1 -1
- package/dist/editors/strategies/windsurf/rules.js +3 -3
- package/dist/editors/strategies/windsurf/rules.js.map +1 -1
- package/dist/editors/strategies/windsurf/skills.d.ts +1 -1
- package/dist/editors/strategies/windsurf/skills.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/skills.js +4 -2
- package/dist/editors/strategies/windsurf/skills.js.map +1 -1
- package/dist/editors/strategies/zed/prompts.d.ts +2 -12
- package/dist/editors/strategies/zed/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/zed/prompts.js +2 -19
- package/dist/editors/strategies/zed/prompts.js.map +1 -1
- package/dist/editors/strategies/zed/rules.d.ts +2 -1
- package/dist/editors/strategies/zed/rules.d.ts.map +1 -1
- package/dist/editors/strategies/zed/rules.js +27 -0
- package/dist/editors/strategies/zed/rules.js.map +1 -1
- package/dist/editors/types.d.ts +44 -1
- package/dist/editors/types.d.ts.map +1 -1
- package/dist/entity-hash.d.ts +26 -0
- package/dist/entity-hash.d.ts.map +1 -0
- package/dist/entity-hash.js +106 -0
- package/dist/entity-hash.js.map +1 -0
- package/dist/env/ci.d.ts +0 -4
- package/dist/env/ci.d.ts.map +1 -1
- package/dist/env/ci.js +10 -8
- package/dist/env/ci.js.map +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +13 -1
- package/dist/errors.js.map +1 -1
- package/dist/format-error.d.ts +16 -3
- package/dist/format-error.d.ts.map +1 -1
- package/dist/format-error.js +101 -22
- package/dist/format-error.js.map +1 -1
- package/dist/frontmatter-utils.d.ts +7 -2
- package/dist/frontmatter-utils.d.ts.map +1 -1
- package/dist/frontmatter-utils.js +9 -2
- package/dist/frontmatter-utils.js.map +1 -1
- package/dist/fs/safe-rm.d.ts +2 -3
- package/dist/fs/safe-rm.d.ts.map +1 -1
- package/dist/fs/safe-rm.js +21 -10
- package/dist/fs/safe-rm.js.map +1 -1
- package/dist/git-download.js +4 -4
- package/dist/git-download.js.map +1 -1
- package/dist/git-loader.d.ts.map +1 -1
- package/dist/git-loader.js +5 -6
- package/dist/git-loader.js.map +1 -1
- package/dist/global/index.d.ts +3 -4
- package/dist/global/index.d.ts.map +1 -1
- package/dist/global/index.js +2 -3
- package/dist/global/index.js.map +1 -1
- package/dist/global/processor.d.ts.map +1 -1
- package/dist/global/processor.js +21 -59
- package/dist/global/processor.js.map +1 -1
- package/dist/global/types.d.ts +2 -0
- package/dist/global/types.d.ts.map +1 -1
- package/dist/import-writer.d.ts +2 -0
- package/dist/import-writer.d.ts.map +1 -1
- package/dist/import-writer.js +22 -24
- package/dist/import-writer.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/inheritance.d.ts.map +1 -1
- package/dist/inheritance.js +18 -17
- package/dist/inheritance.js.map +1 -1
- package/dist/json.js.map +1 -1
- package/dist/loader.d.ts +8 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +25 -12
- package/dist/loader.js.map +1 -1
- package/dist/lockfile.d.ts +31 -0
- package/dist/lockfile.d.ts.map +1 -0
- package/dist/lockfile.js +270 -0
- package/dist/lockfile.js.map +1 -0
- package/dist/mcp/env.d.ts.map +1 -1
- package/dist/mcp/env.js +3 -2
- package/dist/mcp/env.js.map +1 -1
- package/dist/merge.d.ts +9 -5
- package/dist/merge.d.ts.map +1 -1
- package/dist/merge.js +8 -6
- package/dist/merge.js.map +1 -1
- package/dist/npm/resolve.d.ts.map +1 -1
- package/dist/npm/resolve.js +15 -17
- package/dist/npm/resolve.js.map +1 -1
- package/dist/prompts/index.d.ts +1 -0
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +1 -0
- package/dist/prompts/index.js.map +1 -1
- package/dist/prompts/loader.d.ts.map +1 -1
- package/dist/prompts/loader.js +4 -5
- package/dist/prompts/loader.js.map +1 -1
- package/dist/prompts/to-skills.d.ts +26 -0
- package/dist/prompts/to-skills.d.ts.map +1 -0
- package/dist/prompts/to-skills.js +87 -0
- package/dist/prompts/to-skills.js.map +1 -0
- package/dist/reference-resolver.d.ts +86 -0
- package/dist/reference-resolver.d.ts.map +1 -0
- package/dist/reference-resolver.js +250 -0
- package/dist/reference-resolver.js.map +1 -0
- package/dist/remote-loader.d.ts.map +1 -1
- package/dist/remote-loader.js +35 -19
- package/dist/remote-loader.js.map +1 -1
- package/dist/rules/loader.d.ts.map +1 -1
- package/dist/rules/loader.js +4 -5
- package/dist/rules/loader.js.map +1 -1
- package/dist/rules/merger.d.ts.map +1 -1
- package/dist/rules/merger.js +2 -2
- package/dist/rules/merger.js.map +1 -1
- package/dist/rules/skill-rules.d.ts.map +1 -1
- package/dist/rules/skill-rules.js +2 -2
- package/dist/rules/skill-rules.js.map +1 -1
- package/dist/rules/utils.js.map +1 -1
- package/dist/runtime/browser-dummy.d.ts +3 -0
- package/dist/runtime/browser-dummy.d.ts.map +1 -0
- package/dist/runtime/browser-dummy.js +46 -0
- package/dist/runtime/browser-dummy.js.map +1 -0
- package/dist/runtime/index.d.ts +9 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +23 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/node.d.ts +3 -0
- package/dist/runtime/node.d.ts.map +1 -0
- package/dist/runtime/node.js +219 -0
- package/dist/runtime/node.js.map +1 -0
- package/dist/runtime/types.d.ts +130 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/skills/cache.js +2 -2
- package/dist/skills/cache.js.map +1 -1
- package/dist/skills/parser.d.ts.map +1 -1
- package/dist/skills/parser.js +6 -2
- package/dist/skills/parser.js.map +1 -1
- package/dist/skills/reference-parser.d.ts.map +1 -1
- package/dist/skills/reference-parser.js +6 -6
- package/dist/skills/reference-parser.js.map +1 -1
- package/dist/skills/resolve.js.map +1 -1
- package/dist/skills/resolvers/git.d.ts.map +1 -1
- package/dist/skills/resolvers/git.js +4 -5
- package/dist/skills/resolvers/git.js.map +1 -1
- package/dist/skills/resolvers/local.d.ts.map +1 -1
- package/dist/skills/resolvers/local.js +2 -2
- package/dist/skills/resolvers/local.js.map +1 -1
- package/dist/skills/resolvers/npm.d.ts.map +1 -1
- package/dist/skills/resolvers/npm.js +2 -2
- package/dist/skills/resolvers/npm.js.map +1 -1
- package/dist/skills/validate.d.ts.map +1 -1
- package/dist/skills/validate.js +4 -4
- package/dist/skills/validate.js.map +1 -1
- package/dist/state/index.d.ts +3 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +3 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/tracker.d.ts +68 -0
- package/dist/state/tracker.d.ts.map +1 -0
- package/dist/state/tracker.js +143 -0
- package/dist/state/tracker.js.map +1 -0
- package/dist/state/types.d.ts +37 -0
- package/dist/state/types.d.ts.map +1 -0
- package/dist/state/types.js +2 -0
- package/dist/state/types.js.map +1 -0
- package/dist/updater.d.ts.map +1 -1
- package/dist/updater.js +18 -19
- package/dist/updater.js.map +1 -1
- package/dist/url-parsing.d.ts +12 -1
- package/dist/url-parsing.d.ts.map +1 -1
- package/dist/url-parsing.js +26 -3
- package/dist/url-parsing.js.map +1 -1
- package/package.json +14 -5
- package/dist/global/tracking.d.ts +0 -109
- package/dist/global/tracking.d.ts.map +0 -1
- package/dist/global/tracking.js +0 -193
- package/dist/global/tracking.js.map +0 -1
package/dist/editors/import.js
CHANGED
|
@@ -1,67 +1,37 @@
|
|
|
1
|
-
import { readFile, readdir } from 'node:fs/promises';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
1
|
import { join } from 'pathe';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import { ZedRulesStrategy } from './strategies/zed/rules.js';
|
|
18
|
-
import { ZedPromptsStrategy } from './strategies/zed/prompts.js';
|
|
19
|
-
import { CodexRulesStrategy } from './strategies/codex/rules.js';
|
|
20
|
-
import { CodexPromptsStrategy } from './strategies/codex/prompts.js';
|
|
21
|
-
import { CodexMcpStrategy } from './strategies/codex/mcp.js';
|
|
22
|
-
/**
|
|
23
|
-
* Get the import strategies for an editor.
|
|
24
|
-
*/
|
|
25
|
-
function getImportStrategies(editor) {
|
|
26
|
-
switch (editor) {
|
|
27
|
-
case 'windsurf':
|
|
28
|
-
return {
|
|
29
|
-
mcp: new WindsurfMcpStrategy(),
|
|
30
|
-
rules: new WindsurfRulesStrategy(),
|
|
31
|
-
prompts: new WindsurfPromptsStrategy(),
|
|
32
|
-
};
|
|
33
|
-
case 'cursor':
|
|
34
|
-
return {
|
|
35
|
-
mcp: new StandardMcpStrategy(),
|
|
36
|
-
rules: new CursorRulesStrategy(),
|
|
37
|
-
prompts: new CursorPromptsStrategy(),
|
|
38
|
-
};
|
|
39
|
-
case 'claude-code':
|
|
40
|
-
return {
|
|
41
|
-
mcp: new ClaudeCodeMcpStrategy(),
|
|
42
|
-
rules: new ClaudeCodeRulesStrategy(),
|
|
43
|
-
prompts: new ClaudeCodePromptsStrategy(),
|
|
44
|
-
};
|
|
45
|
-
case 'copilot':
|
|
46
|
-
return {
|
|
47
|
-
mcp: new CopilotMcpStrategy(),
|
|
48
|
-
rules: new CopilotRulesStrategy(),
|
|
49
|
-
prompts: new CopilotPromptsStrategy(),
|
|
50
|
-
};
|
|
51
|
-
case 'zed':
|
|
52
|
-
return {
|
|
53
|
-
mcp: new ZedMcpStrategy(),
|
|
54
|
-
rules: new ZedRulesStrategy(),
|
|
55
|
-
prompts: new ZedPromptsStrategy(),
|
|
56
|
-
};
|
|
57
|
-
case 'codex':
|
|
58
|
-
return {
|
|
59
|
-
mcp: new CodexMcpStrategy(),
|
|
60
|
-
rules: new CodexRulesStrategy(),
|
|
61
|
-
prompts: new CodexPromptsStrategy(),
|
|
62
|
-
};
|
|
2
|
+
import { createEmptyConfig, } from '@a1st/aix-schema';
|
|
3
|
+
import { getAdapter } from './install.js';
|
|
4
|
+
import { UnsupportedRuntimeCapabilityError } from '../errors.js';
|
|
5
|
+
import { getRuntimeAdapter } from '../runtime/index.js';
|
|
6
|
+
function existsSync(path) {
|
|
7
|
+
return getRuntimeAdapter().fs.existsSync(path);
|
|
8
|
+
}
|
|
9
|
+
function homedir() {
|
|
10
|
+
return getRuntimeAdapter().os.homedir();
|
|
11
|
+
}
|
|
12
|
+
function assertGlobalHomeAccess(action) {
|
|
13
|
+
if (!getRuntimeAdapter().host.supportsGlobalHomeAccess()) {
|
|
14
|
+
throw new UnsupportedRuntimeCapabilityError('global-home-access', action);
|
|
63
15
|
}
|
|
64
16
|
}
|
|
17
|
+
function readFile(path, encoding) {
|
|
18
|
+
return getRuntimeAdapter().fs.readFile(path, encoding);
|
|
19
|
+
}
|
|
20
|
+
function readdir(path, options) {
|
|
21
|
+
if (options) {
|
|
22
|
+
return getRuntimeAdapter().fs.readdir(path, options);
|
|
23
|
+
}
|
|
24
|
+
return getRuntimeAdapter().fs.readdir(path);
|
|
25
|
+
}
|
|
26
|
+
function buildGlobalPath(relativePath) {
|
|
27
|
+
return relativePath ? join(homedir(), relativePath) : null;
|
|
28
|
+
}
|
|
29
|
+
function buildProjectPath(relativePath, projectRoot, configDir, isProjectRootConfig = false) {
|
|
30
|
+
if (!projectRoot) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return isProjectRootConfig ? join(projectRoot, relativePath) : join(projectRoot, configDir, relativePath);
|
|
34
|
+
}
|
|
65
35
|
/**
|
|
66
36
|
* Import configuration from an editor and convert to ai.json format.
|
|
67
37
|
* Merges global config with project-local editor config: Object.assign({}, global, local)
|
|
@@ -75,223 +45,496 @@ export async function importFromEditor(editor, options = {}) {
|
|
|
75
45
|
rules: [],
|
|
76
46
|
skills: {},
|
|
77
47
|
prompts: {},
|
|
48
|
+
hooks: {},
|
|
49
|
+
paths: { mcp: {}, rules: {}, skills: {}, prompts: {}, hooks: {} },
|
|
50
|
+
scopes: { mcp: {}, rules: {}, skills: {}, prompts: {}, hooks: {} },
|
|
78
51
|
warnings: [],
|
|
79
52
|
sources: { global: false, local: false },
|
|
80
|
-
}, strategies =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
result.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
result.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
result.sources.global = true;
|
|
97
|
-
}
|
|
98
|
-
Object.assign(result.prompts, globalPrompts.prompts);
|
|
99
|
-
result.warnings.push(...globalPrompts.warnings);
|
|
100
|
-
// 2. Import from LOCAL editor config (overlay - overrides global)
|
|
101
|
-
const localMcp = await importLocalMcpConfig(strategies.mcp, editor, projectRoot);
|
|
102
|
-
if (Object.keys(localMcp.mcp).length > 0) {
|
|
103
|
-
result.sources.local = true;
|
|
104
|
-
}
|
|
105
|
-
Object.assign(result.mcp, localMcp.mcp);
|
|
106
|
-
result.warnings.push(...localMcp.warnings);
|
|
107
|
-
const localRules = await importLocalRules(strategies.rules, editor, projectRoot);
|
|
108
|
-
if (localRules.rules.length > 0) {
|
|
109
|
-
result.sources.local = true;
|
|
110
|
-
}
|
|
111
|
-
result.rules.push(...localRules.rules);
|
|
112
|
-
result.warnings.push(...localRules.warnings);
|
|
113
|
-
const localPrompts = await importLocalPrompts(strategies.prompts, editor, projectRoot);
|
|
114
|
-
if (Object.keys(localPrompts.prompts).length > 0) {
|
|
115
|
-
result.sources.local = true;
|
|
116
|
-
}
|
|
117
|
-
Object.assign(result.prompts, localPrompts.prompts);
|
|
118
|
-
result.warnings.push(...localPrompts.warnings);
|
|
53
|
+
}, strategies = getAdapter(editor).getStrategyBundle(), projectRoot = options.projectRoot ?? getRuntimeAdapter().process.cwd(), scope = options.scope ?? 'all';
|
|
54
|
+
if (scope === 'all' || scope === 'user') {
|
|
55
|
+
assertGlobalHomeAccess(`importing global ${editor} configuration`);
|
|
56
|
+
mergeImportMcp(result, await importMcpConfig(strategies.mcpStrategy, strategies.configDir, 'global'));
|
|
57
|
+
mergeImportRules(result, await importGlobalRules(strategies.rulesStrategy, strategies.configDir));
|
|
58
|
+
mergeImportPrompts(result, await importPrompts(strategies.promptsStrategy, strategies.configDir, 'global'));
|
|
59
|
+
mergeImportSkills(result, await importSkills(strategies.skillsStrategy, 'user', projectRoot));
|
|
60
|
+
mergeImportHooks(result, await importHooks(strategies.hooksStrategy, strategies.configDir, 'global'));
|
|
61
|
+
}
|
|
62
|
+
if (scope === 'all' || scope === 'project') {
|
|
63
|
+
mergeImportMcp(result, await importLocalMcpConfig(strategies.mcpStrategy, strategies.configDir, projectRoot));
|
|
64
|
+
mergeImportRules(result, await importLocalRules(strategies.rulesStrategy, strategies.configDir, projectRoot));
|
|
65
|
+
mergeImportPrompts(result, await importLocalPrompts(strategies.promptsStrategy, strategies.configDir, projectRoot));
|
|
66
|
+
mergeImportSkills(result, await importSkills(strategies.skillsStrategy, 'project', projectRoot));
|
|
67
|
+
mergeImportHooks(result, await importHooks(strategies.hooksStrategy, strategies.configDir, 'project', projectRoot));
|
|
68
|
+
}
|
|
119
69
|
return result;
|
|
120
70
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
71
|
+
function mergeImportMcp(result, imported) {
|
|
72
|
+
if (Object.keys(imported.mcp).length > 0) {
|
|
73
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
74
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
Object.assign(result.mcp, imported.mcp);
|
|
78
|
+
Object.assign(result.paths.mcp, imported.paths);
|
|
79
|
+
Object.assign(result.scopes.mcp, imported.scopes);
|
|
80
|
+
result.warnings.push(...imported.warnings);
|
|
81
|
+
}
|
|
82
|
+
function mergeImportRules(result, imported) {
|
|
83
|
+
if (imported.rules.length > 0) {
|
|
84
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
85
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
result.rules.push(...imported.rules);
|
|
89
|
+
Object.assign(result.paths.rules, imported.paths);
|
|
90
|
+
Object.assign(result.scopes.rules, imported.scopes);
|
|
91
|
+
result.warnings.push(...imported.warnings);
|
|
92
|
+
}
|
|
93
|
+
function mergeImportPrompts(result, imported) {
|
|
94
|
+
if (Object.keys(imported.prompts).length > 0) {
|
|
95
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
96
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
Object.assign(result.prompts, imported.prompts);
|
|
100
|
+
Object.assign(result.paths.prompts, imported.paths);
|
|
101
|
+
Object.assign(result.scopes.prompts, imported.scopes);
|
|
102
|
+
result.warnings.push(...imported.warnings);
|
|
103
|
+
}
|
|
104
|
+
function mergeImportSkills(result, imported) {
|
|
105
|
+
if (Object.keys(imported.skills).length > 0) {
|
|
106
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
107
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
Object.assign(result.skills, imported.skills);
|
|
111
|
+
Object.assign(result.paths.skills, imported.paths);
|
|
112
|
+
Object.assign(result.scopes.skills, imported.scopes);
|
|
113
|
+
result.warnings.push(...imported.warnings);
|
|
114
|
+
}
|
|
115
|
+
function mergeImportHooks(result, imported) {
|
|
116
|
+
if (Object.keys(imported.hooks).length > 0) {
|
|
117
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
118
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
Object.assign(result.hooks, imported.hooks);
|
|
122
|
+
Object.assign(result.paths.hooks, imported.paths);
|
|
123
|
+
Object.assign(result.scopes.hooks, imported.scopes);
|
|
124
|
+
result.warnings.push(...imported.warnings);
|
|
125
|
+
}
|
|
126
|
+
function sanitizeImportedName(name) {
|
|
127
|
+
return name
|
|
128
|
+
.trim()
|
|
129
|
+
.toLowerCase()
|
|
130
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
131
|
+
.replace(/-+/g, '-')
|
|
132
|
+
.replace(/^-|-$/g, '') || 'imported-item';
|
|
133
|
+
}
|
|
134
|
+
function dedupeImportedName(name, used) {
|
|
135
|
+
const baseName = sanitizeImportedName(name);
|
|
136
|
+
let candidate = baseName, index = 1;
|
|
137
|
+
while (used.has(candidate)) {
|
|
138
|
+
candidate = `${baseName}-${index}`;
|
|
139
|
+
index += 1;
|
|
140
|
+
}
|
|
141
|
+
used.add(candidate);
|
|
142
|
+
return candidate;
|
|
143
|
+
}
|
|
144
|
+
function normalizeImportedRule(strategy, rule, usedNames) {
|
|
145
|
+
const normalized = {
|
|
146
|
+
name: dedupeImportedName(rule.name, usedNames),
|
|
147
|
+
sourceName: rule.name,
|
|
148
|
+
rawContent: rule.content,
|
|
149
|
+
content: rule.content,
|
|
150
|
+
};
|
|
151
|
+
if (!strategy.parseFrontmatter) {
|
|
152
|
+
return normalized;
|
|
153
|
+
}
|
|
154
|
+
const parsed = strategy.parseFrontmatter(rule.content);
|
|
155
|
+
normalized.content = parsed.content;
|
|
156
|
+
normalized.description = parsed.metadata.description;
|
|
157
|
+
normalized.activation = parsed.metadata.activation;
|
|
158
|
+
normalized.globs = parsed.metadata.globs;
|
|
159
|
+
return normalized;
|
|
160
|
+
}
|
|
161
|
+
function normalizeImportedPrompt(strategy, [sourceName, rawContent], usedNames) {
|
|
162
|
+
const normalized = {
|
|
163
|
+
name: dedupeImportedName(sourceName, usedNames),
|
|
164
|
+
sourceName,
|
|
165
|
+
rawContent,
|
|
166
|
+
content: rawContent,
|
|
167
|
+
};
|
|
168
|
+
if (!strategy.parseFrontmatter) {
|
|
169
|
+
return normalized;
|
|
170
|
+
}
|
|
171
|
+
const parsed = strategy.parseFrontmatter(rawContent);
|
|
172
|
+
normalized.content = parsed.content;
|
|
173
|
+
normalized.description = parsed.description;
|
|
174
|
+
normalized.argumentHint = Array.isArray(parsed.argumentHint)
|
|
175
|
+
? parsed.argumentHint.join(', ')
|
|
176
|
+
: parsed.argumentHint;
|
|
177
|
+
return normalized;
|
|
178
|
+
}
|
|
130
179
|
/**
|
|
131
|
-
*
|
|
180
|
+
* Convert imported editor content into normalized aix data that can be written to ai.json or
|
|
181
|
+
* passed through another editor adapter.
|
|
132
182
|
*/
|
|
133
|
-
|
|
134
|
-
const
|
|
183
|
+
export function normalizeEditorImport(editor, result) {
|
|
184
|
+
const strategies = getAdapter(editor).getStrategyBundle(), usedRuleNames = new Set(), usedPromptNames = new Set(), usedSkillNames = new Set();
|
|
185
|
+
return {
|
|
186
|
+
mcp: result.mcp,
|
|
187
|
+
rules: result.rules.map((rule) => normalizeImportedRule(strategies.rulesStrategy, rule, usedRuleNames)),
|
|
188
|
+
prompts: Object.entries(result.prompts)
|
|
189
|
+
.map((entry) => normalizeImportedPrompt(strategies.promptsStrategy, entry, usedPromptNames)),
|
|
190
|
+
skills: Object.entries(result.skills).map(([sourceName, ref]) => ({
|
|
191
|
+
name: dedupeImportedName(sourceName, usedSkillNames),
|
|
192
|
+
sourceName,
|
|
193
|
+
ref,
|
|
194
|
+
})),
|
|
195
|
+
hooks: result.hooks,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Build an ai.json-shaped config object from imported editor content. This is the bridge used by
|
|
200
|
+
* `aix init --from` and `aix sync`, so editor-to-editor sync does not require a custom
|
|
201
|
+
* converter for every source/destination pair.
|
|
202
|
+
*/
|
|
203
|
+
export function buildConfigFromEditorImport(editor, result) {
|
|
204
|
+
const normalized = normalizeEditorImport(editor, result), config = createEmptyConfig();
|
|
205
|
+
config.mcp = normalized.mcp;
|
|
206
|
+
config.rules = Object.fromEntries(normalized.rules.map((rule) => {
|
|
207
|
+
const value = {
|
|
208
|
+
content: rule.content,
|
|
209
|
+
};
|
|
210
|
+
if (rule.description) {
|
|
211
|
+
value.description = rule.description;
|
|
212
|
+
}
|
|
213
|
+
if (rule.activation) {
|
|
214
|
+
value.activation = rule.activation;
|
|
215
|
+
}
|
|
216
|
+
if (rule.globs && rule.globs.length > 0) {
|
|
217
|
+
value.globs = rule.globs;
|
|
218
|
+
}
|
|
219
|
+
return [rule.name, value];
|
|
220
|
+
}));
|
|
221
|
+
config.prompts = Object.fromEntries(normalized.prompts.map((prompt) => {
|
|
222
|
+
const value = {
|
|
223
|
+
content: prompt.content,
|
|
224
|
+
};
|
|
225
|
+
if (prompt.description) {
|
|
226
|
+
value.description = prompt.description;
|
|
227
|
+
}
|
|
228
|
+
if (prompt.argumentHint) {
|
|
229
|
+
value.argumentHint = prompt.argumentHint;
|
|
230
|
+
}
|
|
231
|
+
return [prompt.name, value];
|
|
232
|
+
}));
|
|
233
|
+
config.skills = Object.fromEntries(normalized.skills.map((skill) => [skill.name, skill.ref]));
|
|
234
|
+
if (Object.keys(normalized.hooks).length > 0) {
|
|
235
|
+
config.hooks = normalized.hooks;
|
|
236
|
+
}
|
|
237
|
+
return config;
|
|
238
|
+
}
|
|
239
|
+
async function importHooks(strategy, configDir, source, projectRoot) {
|
|
240
|
+
const configPath = source === 'global'
|
|
241
|
+
? buildGlobalPath(strategy.getGlobalConfigPath())
|
|
242
|
+
: buildProjectPath(strategy.getConfigPath(), projectRoot, configDir);
|
|
135
243
|
if (!configPath) {
|
|
136
|
-
|
|
137
|
-
return { mcp: {}, warnings };
|
|
244
|
+
return { hooks: {}, paths: {}, scopes: {}, warnings: [] };
|
|
138
245
|
}
|
|
139
|
-
const fullPath = join(homedir(), configPath);
|
|
140
246
|
try {
|
|
141
|
-
const content = await readFile(
|
|
142
|
-
return
|
|
247
|
+
const content = await readFile(configPath, 'utf-8'), parsed = strategy.parseImportedConfig(content), scope = source === 'global' ? 'user' : 'project', eventNames = Object.keys(parsed.hooks);
|
|
248
|
+
return {
|
|
249
|
+
hooks: parsed.hooks,
|
|
250
|
+
paths: pathMapForNames(eventNames, configPath),
|
|
251
|
+
scopes: scopeMapForNames(eventNames, scope),
|
|
252
|
+
warnings: parsed.warnings,
|
|
253
|
+
};
|
|
143
254
|
}
|
|
144
255
|
catch (err) {
|
|
145
|
-
if (err.code
|
|
146
|
-
|
|
256
|
+
if (err.code === 'ENOENT') {
|
|
257
|
+
return { hooks: {}, paths: {}, scopes: {}, warnings: [] };
|
|
147
258
|
}
|
|
259
|
+
return {
|
|
260
|
+
hooks: {},
|
|
261
|
+
paths: {},
|
|
262
|
+
scopes: {},
|
|
263
|
+
warnings: [`Failed to read hooks config at ${configPath}: ${err.message}`],
|
|
264
|
+
};
|
|
148
265
|
}
|
|
149
|
-
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Import MCP configuration from an editor's global config.
|
|
269
|
+
*/
|
|
270
|
+
async function importMcpConfig(strategy, _configDir, _source) {
|
|
271
|
+
return importMcpFromPaths(strategy, getGlobalMcpImportPaths(strategy), 'user', 'global MCP config');
|
|
150
272
|
}
|
|
151
273
|
/**
|
|
152
274
|
* Import MCP configuration from project-local editor config.
|
|
153
275
|
*/
|
|
154
|
-
async function importLocalMcpConfig(strategy,
|
|
155
|
-
const warnings = []
|
|
276
|
+
async function importLocalMcpConfig(strategy, configDir, projectRoot) {
|
|
277
|
+
const warnings = [];
|
|
156
278
|
// Skip if MCP is not supported for project-local config (e.g., global-only editors)
|
|
157
279
|
if (!strategy.isSupported() || strategy.isGlobalOnly?.()) {
|
|
158
|
-
return { mcp: {}, warnings };
|
|
280
|
+
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
159
281
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
282
|
+
for (const fullPath of getLocalMcpImportPaths(strategy, projectRoot, configDir)) {
|
|
283
|
+
try {
|
|
284
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
285
|
+
const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
|
|
286
|
+
return {
|
|
287
|
+
...result,
|
|
288
|
+
paths: pathMapForNames(Object.keys(result.mcp), fullPath),
|
|
289
|
+
scopes: scopeMapForNames(Object.keys(result.mcp), 'project'),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
catch (err) {
|
|
293
|
+
if (err.code !== 'ENOENT' &&
|
|
294
|
+
err.code !== 'EISDIR') {
|
|
295
|
+
warnings.push(`Failed to read local MCP config at ${fullPath}: ${err.message}`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
163
298
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
299
|
+
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
300
|
+
}
|
|
301
|
+
function getGlobalMcpImportPaths(strategy) {
|
|
302
|
+
const configuredPaths = strategy.getGlobalImportPaths?.();
|
|
303
|
+
if (configuredPaths && configuredPaths.length > 0) {
|
|
304
|
+
return configuredPaths.map((path) => buildGlobalPath(path)).filter((path) => Boolean(path));
|
|
305
|
+
}
|
|
306
|
+
const defaultPath = buildGlobalPath(strategy.getGlobalMcpConfigPath());
|
|
307
|
+
return defaultPath ? [defaultPath] : [];
|
|
308
|
+
}
|
|
309
|
+
function getLocalMcpImportPaths(strategy, projectRoot, configDir) {
|
|
310
|
+
const configuredPaths = strategy.getProjectImportPaths?.(projectRoot, configDir);
|
|
311
|
+
if (configuredPaths && configuredPaths.length > 0) {
|
|
312
|
+
return configuredPaths;
|
|
313
|
+
}
|
|
314
|
+
const defaultPath = buildProjectPath(strategy.getConfigPath(), projectRoot, configDir, strategy.isProjectRootConfig?.());
|
|
315
|
+
return defaultPath ? [defaultPath] : [];
|
|
316
|
+
}
|
|
317
|
+
async function importMcpFromPaths(strategy, paths, scope, label) {
|
|
318
|
+
const warnings = [];
|
|
319
|
+
for (const fullPath of paths) {
|
|
320
|
+
try {
|
|
321
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
322
|
+
const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
|
|
323
|
+
return {
|
|
324
|
+
...result,
|
|
325
|
+
paths: pathMapForNames(Object.keys(result.mcp), fullPath),
|
|
326
|
+
scopes: scopeMapForNames(Object.keys(result.mcp), scope),
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
catch (err) {
|
|
330
|
+
if (err.code !== 'ENOENT' &&
|
|
331
|
+
err.code !== 'EISDIR') {
|
|
332
|
+
warnings.push(`Failed to read ${label} at ${fullPath}: ${err.message}`);
|
|
333
|
+
}
|
|
168
334
|
}
|
|
169
335
|
}
|
|
170
|
-
return { mcp: {}, warnings };
|
|
336
|
+
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
171
337
|
}
|
|
172
338
|
/**
|
|
173
339
|
* Import rules from an editor's global config. Tags each rule with the name 'global'.
|
|
174
340
|
*/
|
|
175
|
-
async function importGlobalRules(strategy) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
341
|
+
async function importGlobalRules(strategy, _configDir) {
|
|
342
|
+
if (strategy.importGlobalRules) {
|
|
343
|
+
return strategy.importGlobalRules();
|
|
344
|
+
}
|
|
345
|
+
const warnings = [], rulesPath = strategy.getGlobalRulesPath(), rules = [], paths = {}, scopes = {};
|
|
346
|
+
if (rulesPath) {
|
|
347
|
+
const fullPath = join(homedir(), rulesPath);
|
|
348
|
+
try {
|
|
349
|
+
const content = await readFile(fullPath, 'utf-8'), parsed = strategy.parseGlobalRules(content);
|
|
350
|
+
for (const [index, rule] of parsed.rules.entries()) {
|
|
351
|
+
const name = index === 0 ? 'global' : `global-${index + 1}`;
|
|
352
|
+
rules.push({ content: rule, name, path: fullPath, scope: 'user' });
|
|
353
|
+
paths[name] = fullPath;
|
|
354
|
+
scopes[name] = 'user';
|
|
355
|
+
}
|
|
356
|
+
warnings.push(...parsed.warnings);
|
|
357
|
+
}
|
|
358
|
+
catch (err) {
|
|
359
|
+
if (err.code !== 'ENOENT') {
|
|
360
|
+
warnings.push(`Failed to read global rules from ${fullPath}: ${err.message}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const ruleDirs = strategy.getGlobalRuleImportDirs?.() ?? [];
|
|
365
|
+
for (const ruleDir of ruleDirs) {
|
|
366
|
+
const fullPath = join(homedir(), ruleDir);
|
|
367
|
+
try {
|
|
368
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
369
|
+
const files = await readdir(fullPath), ext = strategy.getFileExtension(), ruleFiles = files.filter((file) => file.endsWith(ext)).toSorted();
|
|
370
|
+
for (const file of ruleFiles) {
|
|
371
|
+
const path = join(fullPath, file), name = file.slice(0, -ext.length);
|
|
372
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
373
|
+
const rule = await readGlobalRuleFile(path, name, warnings);
|
|
374
|
+
if (rule) {
|
|
375
|
+
rules.push(rule);
|
|
376
|
+
paths[name] = path;
|
|
377
|
+
scopes[name] = 'user';
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
if (err.code !== 'ENOENT') {
|
|
383
|
+
warnings.push(`Failed to read global rules from ${fullPath}: ${err.message}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
179
386
|
}
|
|
180
|
-
|
|
387
|
+
return { rules, paths, scopes, warnings };
|
|
388
|
+
}
|
|
389
|
+
async function readGlobalRuleFile(path, name, warnings) {
|
|
181
390
|
try {
|
|
182
|
-
const content = await readFile(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
391
|
+
const content = await readFile(path, 'utf-8'), trimmed = content.trim();
|
|
392
|
+
if (!trimmed) {
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
|
395
|
+
return { content: trimmed, name, path, scope: 'user' };
|
|
187
396
|
}
|
|
188
397
|
catch (err) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
398
|
+
warnings.push(`Failed to read global rule ${path}: ${err.message}`);
|
|
399
|
+
return undefined;
|
|
192
400
|
}
|
|
193
|
-
return { rules: [], warnings };
|
|
194
401
|
}
|
|
195
402
|
/**
|
|
196
403
|
* Import rules from project-local editor config. Tags each rule with its filename (sans extension).
|
|
197
404
|
*/
|
|
198
|
-
async function importLocalRules(strategy,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return importCodexLocalRules(projectRoot);
|
|
405
|
+
async function importLocalRules(strategy, configDir, projectRoot) {
|
|
406
|
+
if (strategy.importProjectRules) {
|
|
407
|
+
return strategy.importProjectRules(projectRoot, configDir);
|
|
202
408
|
}
|
|
203
|
-
const warnings = [],
|
|
409
|
+
const warnings = [], rulesDir = strategy.getRulesDir(), fullPath = join(projectRoot, configDir, rulesDir);
|
|
204
410
|
try {
|
|
205
|
-
const files = await readdir(fullPath), ext = strategy.getFileExtension(), ruleFiles = files.filter((f) => f.endsWith(ext)), rules = [];
|
|
411
|
+
const files = await readdir(fullPath), ext = strategy.getFileExtension(), ruleFiles = files.filter((f) => f.endsWith(ext)), rules = [], paths = {}, scopes = {};
|
|
206
412
|
for (const file of ruleFiles) {
|
|
207
413
|
try {
|
|
414
|
+
const path = join(fullPath, file);
|
|
208
415
|
// eslint-disable-next-line no-await-in-loop -- Sequential for simplicity
|
|
209
|
-
const content = await readFile(
|
|
210
|
-
rules.push({ content, name });
|
|
416
|
+
const content = await readFile(path, 'utf-8'), name = file.endsWith(ext) ? file.slice(0, -ext.length) : file;
|
|
417
|
+
rules.push({ content, name, path, scope: 'project' });
|
|
418
|
+
paths[name] = path;
|
|
419
|
+
scopes[name] = 'project';
|
|
211
420
|
}
|
|
212
421
|
catch {
|
|
213
422
|
// Skip files that can't be read
|
|
214
423
|
}
|
|
215
424
|
}
|
|
216
|
-
return { rules, warnings };
|
|
425
|
+
return { rules, paths, scopes, warnings };
|
|
217
426
|
}
|
|
218
427
|
catch (err) {
|
|
219
428
|
if (err.code !== 'ENOENT') {
|
|
220
429
|
warnings.push(`Failed to read local rules from ${fullPath}: ${err.message}`);
|
|
221
430
|
}
|
|
222
431
|
}
|
|
223
|
-
return { rules: [], warnings };
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Import Codex rules from AGENTS.md at the project root. Codex discovers one AGENTS.md per
|
|
227
|
-
* directory from root→CWD, so we read the root file and tag it accordingly.
|
|
228
|
-
*/
|
|
229
|
-
async function importCodexLocalRules(projectRoot) {
|
|
230
|
-
const warnings = [], agentsPath = join(projectRoot, 'AGENTS.md');
|
|
231
|
-
try {
|
|
232
|
-
const content = await readFile(agentsPath, 'utf-8');
|
|
233
|
-
if (content.trim()) {
|
|
234
|
-
return { rules: [{ content: content.trim(), name: 'AGENTS' }], warnings };
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
catch (err) {
|
|
238
|
-
if (err.code !== 'ENOENT') {
|
|
239
|
-
warnings.push(`Failed to read Codex rules from ${agentsPath}: ${err.message}`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return { rules: [], warnings };
|
|
432
|
+
return { rules: [], paths: {}, scopes: {}, warnings };
|
|
243
433
|
}
|
|
244
434
|
/**
|
|
245
435
|
* Import prompts/workflows from an editor's global config.
|
|
246
436
|
*/
|
|
247
|
-
async function importPrompts(strategy, _source) {
|
|
437
|
+
async function importPrompts(strategy, _configDir, _source) {
|
|
438
|
+
if (strategy.importGlobalPrompts) {
|
|
439
|
+
return strategy.importGlobalPrompts();
|
|
440
|
+
}
|
|
248
441
|
const warnings = [], promptsPath = strategy.getGlobalPromptsPath();
|
|
249
442
|
if (!promptsPath) {
|
|
250
|
-
return { prompts: {}, warnings };
|
|
443
|
+
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
251
444
|
}
|
|
252
445
|
const fullPath = join(homedir(), promptsPath);
|
|
253
446
|
try {
|
|
254
447
|
const files = await readdir(fullPath), fileReader = async (filename) => {
|
|
255
448
|
return readFile(join(fullPath, filename), 'utf-8');
|
|
449
|
+
}, result = await strategy.parseGlobalPrompts(files, fileReader);
|
|
450
|
+
const imported = {
|
|
451
|
+
...result,
|
|
452
|
+
paths: promptPathMap(Object.keys(result.prompts), files, fullPath),
|
|
453
|
+
scopes: scopeMapForNames(Object.keys(result.prompts), 'user'),
|
|
256
454
|
};
|
|
257
|
-
return
|
|
455
|
+
return imported;
|
|
258
456
|
}
|
|
259
457
|
catch (err) {
|
|
260
458
|
if (err.code !== 'ENOENT') {
|
|
261
459
|
warnings.push(`Failed to read global prompts from ${fullPath}: ${err.message}`);
|
|
262
460
|
}
|
|
263
461
|
}
|
|
264
|
-
return { prompts: {}, warnings };
|
|
462
|
+
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
265
463
|
}
|
|
266
464
|
/**
|
|
267
465
|
* Import prompts/workflows from project-local editor config.
|
|
268
466
|
*/
|
|
269
|
-
async function importLocalPrompts(strategy,
|
|
270
|
-
|
|
467
|
+
async function importLocalPrompts(strategy, configDir, projectRoot) {
|
|
468
|
+
if (strategy.importProjectPrompts) {
|
|
469
|
+
return strategy.importProjectPrompts(projectRoot, configDir);
|
|
470
|
+
}
|
|
471
|
+
const warnings = [], promptsDir = strategy.getPromptsDir(), fullPath = join(projectRoot, configDir, promptsDir);
|
|
271
472
|
if (!strategy.isSupported()) {
|
|
272
|
-
return { prompts: {}, warnings };
|
|
473
|
+
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
273
474
|
}
|
|
274
475
|
try {
|
|
275
476
|
const files = await readdir(fullPath), fileReader = async (filename) => {
|
|
276
477
|
return readFile(join(fullPath, filename), 'utf-8');
|
|
478
|
+
}, result = await strategy.parseGlobalPrompts(files, fileReader);
|
|
479
|
+
const imported = {
|
|
480
|
+
...result,
|
|
481
|
+
paths: promptPathMap(Object.keys(result.prompts), files, fullPath),
|
|
482
|
+
scopes: scopeMapForNames(Object.keys(result.prompts), 'project'),
|
|
277
483
|
};
|
|
278
|
-
return
|
|
484
|
+
return imported;
|
|
279
485
|
}
|
|
280
486
|
catch (err) {
|
|
281
487
|
if (err.code !== 'ENOENT') {
|
|
282
488
|
warnings.push(`Failed to read local prompts from ${fullPath}: ${err.message}`);
|
|
283
489
|
}
|
|
284
490
|
}
|
|
285
|
-
return { prompts: {}, warnings };
|
|
491
|
+
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
492
|
+
}
|
|
493
|
+
async function importSkills(strategy, source, projectRoot) {
|
|
494
|
+
const warnings = [], skills = {}, paths = {}, scopes = {}, skillDirs = source === 'user' ? strategy.getGlobalImportDirs() : strategy.getProjectImportDirs(), root = source === 'user' ? homedir() : projectRoot;
|
|
495
|
+
for (const skillDir of skillDirs) {
|
|
496
|
+
const fullPath = join(root, skillDir);
|
|
497
|
+
try {
|
|
498
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
499
|
+
const entries = await readdir(fullPath, { withFileTypes: true });
|
|
500
|
+
for (const entry of entries) {
|
|
501
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
const path = join(fullPath, entry.name);
|
|
505
|
+
if (!existsSync(join(path, 'SKILL.md'))) {
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
skills[entry.name] = path;
|
|
509
|
+
paths[entry.name] = path;
|
|
510
|
+
scopes[entry.name] = source;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
catch (err) {
|
|
514
|
+
if (err.code !== 'ENOENT') {
|
|
515
|
+
warnings.push(`Failed to read skills from ${fullPath}: ${err.message}`);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return { skills, paths, scopes, warnings };
|
|
520
|
+
}
|
|
521
|
+
function pathMapForNames(names, path) {
|
|
522
|
+
return Object.fromEntries(names.map((name) => [name, path]));
|
|
523
|
+
}
|
|
524
|
+
function scopeMapForNames(names, scope) {
|
|
525
|
+
return Object.fromEntries(names.map((name) => [name, scope]));
|
|
526
|
+
}
|
|
527
|
+
function promptPathMap(names, files, basePath) {
|
|
528
|
+
const fileByName = new Map(files.map((file) => [file.replace(/\.md$/, ''), file]));
|
|
529
|
+
return Object.fromEntries(names.flatMap((name) => {
|
|
530
|
+
const file = fileByName.get(name);
|
|
531
|
+
return file ? [[name, join(basePath, file)]] : [];
|
|
532
|
+
}));
|
|
286
533
|
}
|
|
287
534
|
/**
|
|
288
535
|
* Get the global config path for an editor.
|
|
289
536
|
*/
|
|
290
537
|
export function getGlobalConfigPath(editor) {
|
|
291
|
-
|
|
292
|
-
if (!configPath) {
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
return join(homedir(), configPath);
|
|
538
|
+
return buildGlobalPath(getAdapter(editor).getStrategyBundle().mcpStrategy.getGlobalMcpConfigPath());
|
|
296
539
|
}
|
|
297
540
|
//# sourceMappingURL=import.js.map
|