@a1st/aix-core 0.0.6 → 0.1.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 +6 -6
- 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 +6 -3
- package/dist/editors/adapters/base.d.ts.map +1 -1
- package/dist/editors/adapters/base.js +121 -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 +37 -9
- package/dist/editors/adapters/codex.d.ts.map +1 -1
- package/dist/editors/adapters/codex.js +138 -21
- package/dist/editors/adapters/codex.js.map +1 -1
- package/dist/editors/adapters/copilot.d.ts +26 -0
- package/dist/editors/adapters/copilot.d.ts.map +1 -0
- package/dist/editors/adapters/copilot.js +72 -0
- package/dist/editors/adapters/copilot.js.map +1 -0
- 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 +34 -0
- package/dist/editors/adapters/gemini.d.ts.map +1 -0
- package/dist/editors/adapters/gemini.js +99 -0
- package/dist/editors/adapters/gemini.js.map +1 -0
- package/dist/editors/adapters/index.d.ts +3 -1
- package/dist/editors/adapters/index.d.ts.map +1 -1
- package/dist/editors/adapters/index.js +3 -1
- package/dist/editors/adapters/index.js.map +1 -1
- package/dist/editors/adapters/{vscode.d.ts → opencode.d.ts} +9 -8
- 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 +61 -1
- package/dist/editors/import.d.ts.map +1 -1
- package/dist/editors/import.js +1043 -92
- 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 -9
- package/dist/editors/install.js.map +1 -1
- 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 +1 -0
- package/dist/editors/strategies/claude-code/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/hooks.js +52 -5
- package/dist/editors/strategies/claude-code/hooks.js.map +1 -1
- package/dist/editors/strategies/claude-code/mcp.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/mcp.js +2 -2
- 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 +37 -6
- package/dist/editors/strategies/claude-code/prompts.js.map +1 -1
- package/dist/editors/strategies/claude-code/rules.js +3 -3
- package/dist/editors/strategies/claude-code/rules.js.map +1 -1
- package/dist/editors/strategies/codex/index.d.ts +1 -1
- package/dist/editors/strategies/codex/index.d.ts.map +1 -1
- package/dist/editors/strategies/codex/index.js +1 -1
- package/dist/editors/strategies/codex/index.js.map +1 -1
- package/dist/editors/strategies/codex/mcp.d.ts +0 -10
- package/dist/editors/strategies/codex/mcp.d.ts.map +1 -1
- package/dist/editors/strategies/codex/mcp.js +13 -27
- package/dist/editors/strategies/codex/mcp.js.map +1 -1
- package/dist/editors/strategies/codex/prompts.d.ts +7 -6
- package/dist/editors/strategies/codex/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/codex/prompts.js +51 -20
- package/dist/editors/strategies/codex/prompts.js.map +1 -1
- package/dist/editors/strategies/codex/rules.d.ts +3 -2
- package/dist/editors/strategies/codex/rules.d.ts.map +1 -1
- package/dist/editors/strategies/codex/rules.js +5 -4
- package/dist/editors/strategies/codex/rules.js.map +1 -1
- package/dist/editors/strategies/copilot/hooks.d.ts +15 -0
- package/dist/editors/strategies/copilot/hooks.d.ts.map +1 -0
- package/dist/editors/strategies/copilot/hooks.js +104 -0
- package/dist/editors/strategies/copilot/hooks.js.map +1 -0
- package/dist/editors/strategies/copilot/index.d.ts +5 -0
- package/dist/editors/strategies/copilot/index.d.ts.map +1 -0
- package/dist/editors/strategies/copilot/index.js +5 -0
- package/dist/editors/strategies/copilot/index.js.map +1 -0
- package/dist/editors/strategies/{vscode → copilot}/mcp.d.ts +4 -3
- package/dist/editors/strategies/copilot/mcp.d.ts.map +1 -0
- package/dist/editors/strategies/copilot/mcp.js +120 -0
- package/dist/editors/strategies/copilot/mcp.js.map +1 -0
- package/dist/editors/strategies/{vscode → copilot}/prompts.d.ts +7 -6
- package/dist/editors/strategies/copilot/prompts.d.ts.map +1 -0
- package/dist/editors/strategies/{vscode → copilot}/prompts.js +13 -11
- package/dist/editors/strategies/copilot/prompts.js.map +1 -0
- package/dist/editors/strategies/{vscode → copilot}/rules.d.ts +2 -2
- package/dist/editors/strategies/copilot/rules.d.ts.map +1 -0
- package/dist/editors/strategies/{vscode → copilot}/rules.js +5 -5
- package/dist/editors/strategies/copilot/rules.js.map +1 -0
- package/dist/editors/strategies/cursor/hooks.d.ts +1 -0
- package/dist/editors/strategies/cursor/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/cursor/hooks.js +14 -0
- package/dist/editors/strategies/cursor/hooks.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/index.d.ts +4 -0
- package/dist/editors/strategies/{vscode → gemini}/index.d.ts.map +1 -1
- package/dist/editors/strategies/gemini/index.js +4 -0
- package/dist/editors/strategies/{vscode → gemini}/index.js.map +1 -1
- 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 +118 -0
- package/dist/editors/strategies/gemini/prompts.js.map +1 -0
- package/dist/editors/strategies/gemini/rules.d.ts +18 -0
- package/dist/editors/strategies/gemini/rules.d.ts.map +1 -0
- package/dist/editors/strategies/gemini/rules.js +36 -0
- package/dist/editors/strategies/gemini/rules.js.map +1 -0
- package/dist/editors/strategies/index.d.ts +2 -1
- package/dist/editors/strategies/index.d.ts.map +1 -1
- package/dist/editors/strategies/index.js +2 -1
- package/dist/editors/strategies/index.js.map +1 -1
- 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 +17 -0
- package/dist/editors/strategies/opencode/mcp.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/mcp.js +137 -0
- package/dist/editors/strategies/opencode/mcp.js.map +1 -0
- package/dist/editors/strategies/opencode/prompts.d.ts +20 -0
- package/dist/editors/strategies/opencode/prompts.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/prompts.js +94 -0
- package/dist/editors/strategies/opencode/prompts.js.map +1 -0
- package/dist/editors/strategies/opencode/rules.d.ts +17 -0
- package/dist/editors/strategies/opencode/rules.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/rules.js +31 -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/native-skills.d.ts +9 -5
- package/dist/editors/strategies/shared/native-skills.d.ts.map +1 -1
- package/dist/editors/strategies/shared/native-skills.js +24 -24
- package/dist/editors/strategies/shared/native-skills.js.map +1 -1
- package/dist/editors/strategies/shared/no-hooks.d.ts +2 -1
- package/dist/editors/strategies/shared/no-hooks.d.ts.map +1 -1
- package/dist/editors/strategies/shared/no-hooks.js +4 -1
- package/dist/editors/strategies/shared/no-hooks.js.map +1 -1
- package/dist/editors/strategies/shared/no-mcp.d.ts +1 -1
- package/dist/editors/strategies/shared/no-mcp.js +1 -1
- package/dist/editors/strategies/shared/pointer-skills.d.ts +5 -2
- package/dist/editors/strategies/shared/pointer-skills.d.ts.map +1 -1
- package/dist/editors/strategies/shared/pointer-skills.js +15 -10
- package/dist/editors/strategies/shared/pointer-skills.js.map +1 -1
- package/dist/editors/strategies/types.d.ts +9 -2
- package/dist/editors/strategies/types.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/hooks.d.ts +1 -0
- package/dist/editors/strategies/windsurf/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/hooks.js +5 -0
- package/dist/editors/strategies/windsurf/hooks.js.map +1 -1
- package/dist/editors/strategies/windsurf/prompts.js +2 -2
- 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/types.d.ts +39 -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/frontmatter-parser.d.ts +1 -1
- package/dist/frontmatter-parser.js +3 -3
- package/dist/frontmatter-parser.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.map +1 -1
- package/dist/fs/safe-rm.js +15 -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 +40 -64
- package/dist/global/processor.js.map +1 -1
- package/dist/global/types.d.ts +4 -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/loader.d.ts +8 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +22 -9
- 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/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/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 +212 -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/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 +10 -6
- package/dist/editors/adapters/vscode.d.ts.map +0 -1
- package/dist/editors/adapters/vscode.js +0 -44
- package/dist/editors/adapters/vscode.js.map +0 -1
- package/dist/editors/strategies/vscode/index.d.ts +0 -4
- package/dist/editors/strategies/vscode/index.js +0 -4
- package/dist/editors/strategies/vscode/mcp.d.ts.map +0 -1
- package/dist/editors/strategies/vscode/mcp.js +0 -85
- package/dist/editors/strategies/vscode/mcp.js.map +0 -1
- package/dist/editors/strategies/vscode/prompts.d.ts.map +0 -1
- package/dist/editors/strategies/vscode/prompts.js.map +0 -1
- package/dist/editors/strategies/vscode/rules.d.ts.map +0 -1
- package/dist/editors/strategies/vscode/rules.js.map +0 -1
- 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,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { join } from 'pathe';
|
|
1
|
+
import { dirname, isAbsolute, join } from 'pathe';
|
|
2
|
+
import { createEmptyConfig, parseJsonc, } from '@a1st/aix-schema';
|
|
4
3
|
import { WindsurfRulesStrategy } from './strategies/windsurf/rules.js';
|
|
5
4
|
import { WindsurfPromptsStrategy } from './strategies/windsurf/prompts.js';
|
|
6
5
|
import { WindsurfMcpStrategy } from './strategies/windsurf/mcp.js';
|
|
@@ -10,15 +9,132 @@ import { CursorPromptsStrategy } from './strategies/cursor/prompts.js';
|
|
|
10
9
|
import { ClaudeCodeMcpStrategy } from './strategies/claude-code/mcp.js';
|
|
11
10
|
import { ClaudeCodeRulesStrategy } from './strategies/claude-code/rules.js';
|
|
12
11
|
import { ClaudeCodePromptsStrategy } from './strategies/claude-code/prompts.js';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
12
|
+
import { CopilotMcpStrategy } from './strategies/copilot/mcp.js';
|
|
13
|
+
import { CopilotRulesStrategy } from './strategies/copilot/rules.js';
|
|
14
|
+
import { CopilotPromptsStrategy } from './strategies/copilot/prompts.js';
|
|
16
15
|
import { ZedMcpStrategy } from './strategies/zed/mcp.js';
|
|
17
16
|
import { ZedRulesStrategy } from './strategies/zed/rules.js';
|
|
18
17
|
import { ZedPromptsStrategy } from './strategies/zed/prompts.js';
|
|
19
18
|
import { CodexRulesStrategy } from './strategies/codex/rules.js';
|
|
20
19
|
import { CodexPromptsStrategy } from './strategies/codex/prompts.js';
|
|
21
20
|
import { CodexMcpStrategy } from './strategies/codex/mcp.js';
|
|
21
|
+
import { GeminiRulesStrategy } from './strategies/gemini/rules.js';
|
|
22
|
+
import { GeminiPromptsStrategy } from './strategies/gemini/prompts.js';
|
|
23
|
+
import { GeminiMcpStrategy } from './strategies/gemini/mcp.js';
|
|
24
|
+
import { OpenCodeRulesStrategy } from './strategies/opencode/rules.js';
|
|
25
|
+
import { OpenCodePromptsStrategy } from './strategies/opencode/prompts.js';
|
|
26
|
+
import { OpenCodeMcpStrategy } from './strategies/opencode/mcp.js';
|
|
27
|
+
import { UnsupportedRuntimeCapabilityError } from '../errors.js';
|
|
28
|
+
import { getRuntimeAdapter } from '../runtime/index.js';
|
|
29
|
+
function existsSync(path) {
|
|
30
|
+
return getRuntimeAdapter().fs.existsSync(path);
|
|
31
|
+
}
|
|
32
|
+
function homedir() {
|
|
33
|
+
return getRuntimeAdapter().os.homedir();
|
|
34
|
+
}
|
|
35
|
+
function assertGlobalHomeAccess(action) {
|
|
36
|
+
if (!getRuntimeAdapter().host.supportsGlobalHomeAccess()) {
|
|
37
|
+
throw new UnsupportedRuntimeCapabilityError('global-home-access', action);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function readFile(path, encoding) {
|
|
41
|
+
return getRuntimeAdapter().fs.readFile(path, encoding);
|
|
42
|
+
}
|
|
43
|
+
function readdir(path, options) {
|
|
44
|
+
if (options) {
|
|
45
|
+
return getRuntimeAdapter().fs.readdir(path, options);
|
|
46
|
+
}
|
|
47
|
+
return getRuntimeAdapter().fs.readdir(path);
|
|
48
|
+
}
|
|
49
|
+
const CURSOR_HOOK_EVENT_MAP = {
|
|
50
|
+
session_start: 'sessionStart',
|
|
51
|
+
session_end: 'sessionEnd',
|
|
52
|
+
pre_tool_use: 'preToolUse',
|
|
53
|
+
post_tool_use: 'postToolUse',
|
|
54
|
+
pre_file_read: 'beforeReadFile',
|
|
55
|
+
pre_command: 'beforeShellExecution',
|
|
56
|
+
post_command: 'afterShellExecution',
|
|
57
|
+
pre_mcp_tool: 'beforeMCPExecution',
|
|
58
|
+
post_mcp_tool: 'afterMCPExecution',
|
|
59
|
+
post_file_write: 'afterFileEdit',
|
|
60
|
+
pre_prompt: 'beforeSubmitPrompt',
|
|
61
|
+
agent_stop: 'stop',
|
|
62
|
+
};
|
|
63
|
+
const WINDSURF_HOOK_EVENT_MAP = {
|
|
64
|
+
pre_file_read: 'pre_read_code',
|
|
65
|
+
post_file_read: 'post_read_code',
|
|
66
|
+
pre_file_write: 'pre_write_code',
|
|
67
|
+
post_file_write: 'post_write_code',
|
|
68
|
+
pre_command: 'pre_run_command',
|
|
69
|
+
post_command: 'post_run_command',
|
|
70
|
+
pre_mcp_tool: 'pre_mcp_tool_use',
|
|
71
|
+
post_mcp_tool: 'post_mcp_tool_use',
|
|
72
|
+
pre_prompt: 'pre_user_prompt',
|
|
73
|
+
agent_stop: 'post_cascade_response',
|
|
74
|
+
worktree_setup: 'post_setup_worktree',
|
|
75
|
+
};
|
|
76
|
+
const CLAUDE_CODE_HOOK_EVENT_MAP = {
|
|
77
|
+
pre_tool_use: 'PreToolUse',
|
|
78
|
+
post_tool_use: 'PostToolUse',
|
|
79
|
+
pre_file_read: 'PreToolUse',
|
|
80
|
+
post_file_read: 'PostToolUse',
|
|
81
|
+
pre_file_write: 'PreToolUse',
|
|
82
|
+
post_file_write: 'PostToolUse',
|
|
83
|
+
pre_command: 'PreToolUse',
|
|
84
|
+
post_command: 'PostToolUse',
|
|
85
|
+
pre_mcp_tool: 'PreToolUse',
|
|
86
|
+
post_mcp_tool: 'PostToolUse',
|
|
87
|
+
session_start: 'SessionStart',
|
|
88
|
+
session_end: 'SessionEnd',
|
|
89
|
+
agent_stop: 'Stop',
|
|
90
|
+
pre_prompt: 'UserPromptSubmit',
|
|
91
|
+
pre_compact: 'PreCompact',
|
|
92
|
+
post_compact: 'PostCompact',
|
|
93
|
+
subagent_start: 'SubagentStart',
|
|
94
|
+
subagent_stop: 'SubagentStop',
|
|
95
|
+
task_created: 'TaskCreated',
|
|
96
|
+
task_completed: 'TaskCompleted',
|
|
97
|
+
worktree_setup: 'WorktreeCreate',
|
|
98
|
+
};
|
|
99
|
+
const COPILOT_HOOK_EVENT_MAP = {
|
|
100
|
+
pre_tool_use: 'preToolUse',
|
|
101
|
+
post_tool_use: 'postToolUse',
|
|
102
|
+
pre_file_read: 'preToolUse',
|
|
103
|
+
post_file_read: 'postToolUse',
|
|
104
|
+
pre_file_write: 'preToolUse',
|
|
105
|
+
post_file_write: 'postToolUse',
|
|
106
|
+
pre_command: 'preToolUse',
|
|
107
|
+
post_command: 'postToolUse',
|
|
108
|
+
pre_mcp_tool: 'preToolUse',
|
|
109
|
+
post_mcp_tool: 'postToolUse',
|
|
110
|
+
session_start: 'sessionStart',
|
|
111
|
+
session_end: 'sessionEnd',
|
|
112
|
+
agent_stop: 'stop',
|
|
113
|
+
pre_prompt: 'userPromptSubmitted',
|
|
114
|
+
pre_compact: 'preCompact',
|
|
115
|
+
subagent_start: 'subagentStart',
|
|
116
|
+
subagent_stop: 'subagentStop',
|
|
117
|
+
};
|
|
118
|
+
const CLAUDE_CODE_HOOK_TOOL_MATCHERS = {
|
|
119
|
+
pre_command: 'Bash',
|
|
120
|
+
post_command: 'Bash',
|
|
121
|
+
pre_file_read: 'Read',
|
|
122
|
+
post_file_read: 'Read',
|
|
123
|
+
pre_file_write: 'Write|Edit',
|
|
124
|
+
post_file_write: 'Write|Edit',
|
|
125
|
+
pre_mcp_tool: 'mcp__.*',
|
|
126
|
+
post_mcp_tool: 'mcp__.*',
|
|
127
|
+
};
|
|
128
|
+
const COPILOT_HOOK_TOOL_MATCHERS = {
|
|
129
|
+
pre_command: 'Bash',
|
|
130
|
+
post_command: 'Bash',
|
|
131
|
+
pre_file_read: 'Read',
|
|
132
|
+
post_file_read: 'Read',
|
|
133
|
+
pre_file_write: 'Write|Edit',
|
|
134
|
+
post_file_write: 'Write|Edit',
|
|
135
|
+
pre_mcp_tool: 'mcp__.*',
|
|
136
|
+
post_mcp_tool: 'mcp__.*',
|
|
137
|
+
};
|
|
22
138
|
/**
|
|
23
139
|
* Get the import strategies for an editor.
|
|
24
140
|
*/
|
|
@@ -42,11 +158,11 @@ function getImportStrategies(editor) {
|
|
|
42
158
|
rules: new ClaudeCodeRulesStrategy(),
|
|
43
159
|
prompts: new ClaudeCodePromptsStrategy(),
|
|
44
160
|
};
|
|
45
|
-
case '
|
|
161
|
+
case 'copilot':
|
|
46
162
|
return {
|
|
47
|
-
mcp: new
|
|
48
|
-
rules: new
|
|
49
|
-
prompts: new
|
|
163
|
+
mcp: new CopilotMcpStrategy(),
|
|
164
|
+
rules: new CopilotRulesStrategy(),
|
|
165
|
+
prompts: new CopilotPromptsStrategy(),
|
|
50
166
|
};
|
|
51
167
|
case 'zed':
|
|
52
168
|
return {
|
|
@@ -60,6 +176,18 @@ function getImportStrategies(editor) {
|
|
|
60
176
|
rules: new CodexRulesStrategy(),
|
|
61
177
|
prompts: new CodexPromptsStrategy(),
|
|
62
178
|
};
|
|
179
|
+
case 'gemini':
|
|
180
|
+
return {
|
|
181
|
+
mcp: new GeminiMcpStrategy(),
|
|
182
|
+
rules: new GeminiRulesStrategy(),
|
|
183
|
+
prompts: new GeminiPromptsStrategy(),
|
|
184
|
+
};
|
|
185
|
+
case 'opencode':
|
|
186
|
+
return {
|
|
187
|
+
mcp: new OpenCodeMcpStrategy(),
|
|
188
|
+
rules: new OpenCodeRulesStrategy(),
|
|
189
|
+
prompts: new OpenCodePromptsStrategy(),
|
|
190
|
+
};
|
|
63
191
|
}
|
|
64
192
|
}
|
|
65
193
|
/**
|
|
@@ -75,170 +203,728 @@ export async function importFromEditor(editor, options = {}) {
|
|
|
75
203
|
rules: [],
|
|
76
204
|
skills: {},
|
|
77
205
|
prompts: {},
|
|
206
|
+
hooks: {},
|
|
207
|
+
paths: { mcp: {}, rules: {}, skills: {}, prompts: {}, hooks: {} },
|
|
208
|
+
scopes: { mcp: {}, rules: {}, skills: {}, prompts: {}, hooks: {} },
|
|
78
209
|
warnings: [],
|
|
79
210
|
sources: { global: false, local: false },
|
|
80
|
-
}, strategies = getImportStrategies(editor), projectRoot = options.projectRoot ?? process.cwd();
|
|
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);
|
|
211
|
+
}, strategies = getImportStrategies(editor), projectRoot = options.projectRoot ?? getRuntimeAdapter().process.cwd(), scope = options.scope ?? 'all';
|
|
212
|
+
if (scope === 'all' || scope === 'user') {
|
|
213
|
+
assertGlobalHomeAccess(`importing global ${editor} configuration`);
|
|
214
|
+
mergeImportMcp(result, await importMcpConfig(strategies.mcp, editor, 'global'));
|
|
215
|
+
mergeImportRules(result, await importGlobalRules(strategies.rules, editor));
|
|
216
|
+
mergeImportPrompts(result, await importPrompts(strategies.prompts, editor, 'global'));
|
|
217
|
+
mergeImportSkills(result, await importGlobalSkills(editor));
|
|
218
|
+
mergeImportHooks(result, await importHooks(editor, 'global'));
|
|
219
|
+
}
|
|
220
|
+
if (scope === 'all' || scope === 'project') {
|
|
221
|
+
mergeImportMcp(result, await importLocalMcpConfig(strategies.mcp, editor, projectRoot));
|
|
222
|
+
mergeImportRules(result, await importLocalRules(strategies.rules, editor, projectRoot));
|
|
223
|
+
mergeImportPrompts(result, await importLocalPrompts(strategies.prompts, editor, projectRoot));
|
|
224
|
+
mergeImportSkills(result, await importLocalSkills(editor, projectRoot));
|
|
225
|
+
mergeImportHooks(result, await importHooks(editor, 'project', projectRoot));
|
|
226
|
+
}
|
|
119
227
|
return result;
|
|
120
228
|
}
|
|
229
|
+
function mergeImportMcp(result, imported) {
|
|
230
|
+
if (Object.keys(imported.mcp).length > 0) {
|
|
231
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
232
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
Object.assign(result.mcp, imported.mcp);
|
|
236
|
+
Object.assign(result.paths.mcp, imported.paths);
|
|
237
|
+
Object.assign(result.scopes.mcp, imported.scopes);
|
|
238
|
+
result.warnings.push(...imported.warnings);
|
|
239
|
+
}
|
|
240
|
+
function mergeImportRules(result, imported) {
|
|
241
|
+
if (imported.rules.length > 0) {
|
|
242
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
243
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
result.rules.push(...imported.rules);
|
|
247
|
+
Object.assign(result.paths.rules, imported.paths);
|
|
248
|
+
Object.assign(result.scopes.rules, imported.scopes);
|
|
249
|
+
result.warnings.push(...imported.warnings);
|
|
250
|
+
}
|
|
251
|
+
function mergeImportPrompts(result, imported) {
|
|
252
|
+
if (Object.keys(imported.prompts).length > 0) {
|
|
253
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
254
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
Object.assign(result.prompts, imported.prompts);
|
|
258
|
+
Object.assign(result.paths.prompts, imported.paths);
|
|
259
|
+
Object.assign(result.scopes.prompts, imported.scopes);
|
|
260
|
+
result.warnings.push(...imported.warnings);
|
|
261
|
+
}
|
|
262
|
+
function mergeImportSkills(result, imported) {
|
|
263
|
+
if (Object.keys(imported.skills).length > 0) {
|
|
264
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
265
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
Object.assign(result.skills, imported.skills);
|
|
269
|
+
Object.assign(result.paths.skills, imported.paths);
|
|
270
|
+
Object.assign(result.scopes.skills, imported.scopes);
|
|
271
|
+
result.warnings.push(...imported.warnings);
|
|
272
|
+
}
|
|
273
|
+
function mergeImportHooks(result, imported) {
|
|
274
|
+
if (Object.keys(imported.hooks).length > 0) {
|
|
275
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
276
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
Object.assign(result.hooks, imported.hooks);
|
|
280
|
+
Object.assign(result.paths.hooks, imported.paths);
|
|
281
|
+
Object.assign(result.scopes.hooks, imported.scopes);
|
|
282
|
+
result.warnings.push(...imported.warnings);
|
|
283
|
+
}
|
|
284
|
+
function sanitizeImportedName(name) {
|
|
285
|
+
return name
|
|
286
|
+
.trim()
|
|
287
|
+
.toLowerCase()
|
|
288
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
289
|
+
.replace(/-+/g, '-')
|
|
290
|
+
.replace(/^-|-$/g, '') || 'imported-item';
|
|
291
|
+
}
|
|
292
|
+
function dedupeImportedName(name, used) {
|
|
293
|
+
const baseName = sanitizeImportedName(name);
|
|
294
|
+
let candidate = baseName, index = 1;
|
|
295
|
+
while (used.has(candidate)) {
|
|
296
|
+
candidate = `${baseName}-${index}`;
|
|
297
|
+
index += 1;
|
|
298
|
+
}
|
|
299
|
+
used.add(candidate);
|
|
300
|
+
return candidate;
|
|
301
|
+
}
|
|
302
|
+
function normalizeImportedRule(strategy, rule, usedNames) {
|
|
303
|
+
const normalized = {
|
|
304
|
+
name: dedupeImportedName(rule.name, usedNames),
|
|
305
|
+
sourceName: rule.name,
|
|
306
|
+
rawContent: rule.content,
|
|
307
|
+
content: rule.content,
|
|
308
|
+
};
|
|
309
|
+
if (!strategy.parseFrontmatter) {
|
|
310
|
+
return normalized;
|
|
311
|
+
}
|
|
312
|
+
const parsed = strategy.parseFrontmatter(rule.content);
|
|
313
|
+
normalized.content = parsed.content;
|
|
314
|
+
normalized.description = parsed.metadata.description;
|
|
315
|
+
normalized.activation = parsed.metadata.activation;
|
|
316
|
+
normalized.globs = parsed.metadata.globs;
|
|
317
|
+
return normalized;
|
|
318
|
+
}
|
|
319
|
+
function normalizeImportedPrompt(strategy, [sourceName, rawContent], usedNames) {
|
|
320
|
+
const normalized = {
|
|
321
|
+
name: dedupeImportedName(sourceName, usedNames),
|
|
322
|
+
sourceName,
|
|
323
|
+
rawContent,
|
|
324
|
+
content: rawContent,
|
|
325
|
+
};
|
|
326
|
+
if (!strategy.parseFrontmatter) {
|
|
327
|
+
return normalized;
|
|
328
|
+
}
|
|
329
|
+
const parsed = strategy.parseFrontmatter(rawContent);
|
|
330
|
+
normalized.content = parsed.content;
|
|
331
|
+
normalized.description = parsed.description;
|
|
332
|
+
normalized.argumentHint = Array.isArray(parsed.argumentHint)
|
|
333
|
+
? parsed.argumentHint.join(', ')
|
|
334
|
+
: parsed.argumentHint;
|
|
335
|
+
return normalized;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Convert imported editor content into normalized aix data that can be written to ai.json or
|
|
339
|
+
* passed through another editor adapter.
|
|
340
|
+
*/
|
|
341
|
+
export function normalizeEditorImport(editor, result) {
|
|
342
|
+
const strategies = getImportStrategies(editor), usedRuleNames = new Set(), usedPromptNames = new Set(), usedSkillNames = new Set();
|
|
343
|
+
return {
|
|
344
|
+
mcp: result.mcp,
|
|
345
|
+
rules: result.rules.map((rule) => normalizeImportedRule(strategies.rules, rule, usedRuleNames)),
|
|
346
|
+
prompts: Object.entries(result.prompts).map((entry) => normalizeImportedPrompt(strategies.prompts, entry, usedPromptNames)),
|
|
347
|
+
skills: Object.entries(result.skills).map(([sourceName, ref]) => ({
|
|
348
|
+
name: dedupeImportedName(sourceName, usedSkillNames),
|
|
349
|
+
sourceName,
|
|
350
|
+
ref,
|
|
351
|
+
})),
|
|
352
|
+
hooks: result.hooks,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Build an ai.json-shaped config object from imported editor content. This is the bridge used by
|
|
357
|
+
* `aix init --from` and `aix sync`, so editor-to-editor sync does not require a custom
|
|
358
|
+
* converter for every source/destination pair.
|
|
359
|
+
*/
|
|
360
|
+
export function buildConfigFromEditorImport(editor, result) {
|
|
361
|
+
const normalized = normalizeEditorImport(editor, result), config = createEmptyConfig();
|
|
362
|
+
config.mcp = normalized.mcp;
|
|
363
|
+
config.rules = Object.fromEntries(normalized.rules.map((rule) => {
|
|
364
|
+
const value = {
|
|
365
|
+
content: rule.content,
|
|
366
|
+
};
|
|
367
|
+
if (rule.description) {
|
|
368
|
+
value.description = rule.description;
|
|
369
|
+
}
|
|
370
|
+
if (rule.activation) {
|
|
371
|
+
value.activation = rule.activation;
|
|
372
|
+
}
|
|
373
|
+
if (rule.globs && rule.globs.length > 0) {
|
|
374
|
+
value.globs = rule.globs;
|
|
375
|
+
}
|
|
376
|
+
return [rule.name, value];
|
|
377
|
+
}));
|
|
378
|
+
config.prompts = Object.fromEntries(normalized.prompts.map((prompt) => {
|
|
379
|
+
const value = {
|
|
380
|
+
content: prompt.content,
|
|
381
|
+
};
|
|
382
|
+
if (prompt.description) {
|
|
383
|
+
value.description = prompt.description;
|
|
384
|
+
}
|
|
385
|
+
if (prompt.argumentHint) {
|
|
386
|
+
value.argumentHint = prompt.argumentHint;
|
|
387
|
+
}
|
|
388
|
+
return [prompt.name, value];
|
|
389
|
+
}));
|
|
390
|
+
config.skills = Object.fromEntries(normalized.skills.map((skill) => [skill.name, skill.ref]));
|
|
391
|
+
if (Object.keys(normalized.hooks).length > 0) {
|
|
392
|
+
config.hooks = normalized.hooks;
|
|
393
|
+
}
|
|
394
|
+
return config;
|
|
395
|
+
}
|
|
396
|
+
function getHookEventMap(editor) {
|
|
397
|
+
switch (editor) {
|
|
398
|
+
case 'cursor':
|
|
399
|
+
return CURSOR_HOOK_EVENT_MAP;
|
|
400
|
+
case 'windsurf':
|
|
401
|
+
return WINDSURF_HOOK_EVENT_MAP;
|
|
402
|
+
case 'claude-code':
|
|
403
|
+
return CLAUDE_CODE_HOOK_EVENT_MAP;
|
|
404
|
+
case 'copilot':
|
|
405
|
+
return COPILOT_HOOK_EVENT_MAP;
|
|
406
|
+
default:
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function getHookToolMatcherMap(editor) {
|
|
411
|
+
switch (editor) {
|
|
412
|
+
case 'claude-code':
|
|
413
|
+
return CLAUDE_CODE_HOOK_TOOL_MATCHERS;
|
|
414
|
+
case 'copilot':
|
|
415
|
+
return COPILOT_HOOK_TOOL_MATCHERS;
|
|
416
|
+
default:
|
|
417
|
+
return {};
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function getHookConfigPath(editor, projectRoot, source) {
|
|
421
|
+
if (editor === 'copilot' && source === 'global') {
|
|
422
|
+
return join(homedir(), '.copilot/hooks/hooks.json');
|
|
423
|
+
}
|
|
424
|
+
const configDir = EDITOR_CONFIG_DIRS[editor], hooksPath = getHooksConfigPathRelative(editor);
|
|
425
|
+
if (!hooksPath) {
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
switch (source) {
|
|
429
|
+
case 'global':
|
|
430
|
+
return join(homedir(), configDir, hooksPath);
|
|
431
|
+
case 'project':
|
|
432
|
+
if (!projectRoot) {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
return join(projectRoot, configDir, hooksPath);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function getHooksConfigPathRelative(editor) {
|
|
439
|
+
switch (editor) {
|
|
440
|
+
case 'cursor':
|
|
441
|
+
return 'hooks.json';
|
|
442
|
+
case 'windsurf':
|
|
443
|
+
return 'hooks.json';
|
|
444
|
+
case 'claude-code':
|
|
445
|
+
return 'settings.json';
|
|
446
|
+
case 'copilot':
|
|
447
|
+
return '../.github/hooks/hooks.json';
|
|
448
|
+
default:
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function parseHookAction(value) {
|
|
453
|
+
if (!value || typeof value !== 'object') {
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
const hook = value;
|
|
457
|
+
if (typeof hook.command !== 'string' || hook.command.length === 0) {
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
const action = {
|
|
461
|
+
command: hook.command,
|
|
462
|
+
};
|
|
463
|
+
if (typeof hook.timeout === 'number' && hook.timeout > 0) {
|
|
464
|
+
action.timeout = hook.timeout;
|
|
465
|
+
}
|
|
466
|
+
if (typeof hook.show_output === 'boolean') {
|
|
467
|
+
action.show_output = hook.show_output;
|
|
468
|
+
}
|
|
469
|
+
if (typeof hook.working_directory === 'string' && hook.working_directory.length > 0) {
|
|
470
|
+
action.working_directory = hook.working_directory;
|
|
471
|
+
}
|
|
472
|
+
return action;
|
|
473
|
+
}
|
|
474
|
+
function normalizeImportedMatcher(event, matcher, toolMatchers) {
|
|
475
|
+
if (!matcher) {
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
478
|
+
return toolMatchers[event] === matcher ? undefined : matcher;
|
|
479
|
+
}
|
|
480
|
+
function pushImportedMatchers(hooks, event, matchers) {
|
|
481
|
+
if (matchers.length === 0) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
hooks[event] = [...(hooks[event] ?? []), ...matchers];
|
|
485
|
+
}
|
|
486
|
+
function parseFlatHookEntries(rawHooks, eventMap) {
|
|
487
|
+
const hooks = {}, reverseEventMap = {};
|
|
488
|
+
for (const [event, nativeEvent] of Object.entries(eventMap)) {
|
|
489
|
+
reverseEventMap[nativeEvent] = event;
|
|
490
|
+
}
|
|
491
|
+
for (const [nativeEvent, rawActions] of Object.entries(rawHooks)) {
|
|
492
|
+
const event = reverseEventMap[nativeEvent];
|
|
493
|
+
if (!event || !Array.isArray(rawActions)) {
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
const actions = rawActions
|
|
497
|
+
.map((action) => parseHookAction(action))
|
|
498
|
+
.filter((action) => action !== null);
|
|
499
|
+
pushImportedMatchers(hooks, event, [{ hooks: actions }]);
|
|
500
|
+
}
|
|
501
|
+
return hooks;
|
|
502
|
+
}
|
|
503
|
+
function resolveMatcherBackedEvent(nativeEvent, matcher, eventMap, toolMatchers) {
|
|
504
|
+
const matchingEvents = Object.entries(eventMap)
|
|
505
|
+
.filter(([, mappedEvent]) => mappedEvent === nativeEvent)
|
|
506
|
+
.map(([event]) => event);
|
|
507
|
+
if (matchingEvents.length === 0) {
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
for (const event of matchingEvents) {
|
|
511
|
+
if (toolMatchers[event] === matcher) {
|
|
512
|
+
return event;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return matchingEvents.find((event) => !toolMatchers[event]) ?? matchingEvents[0] ?? null;
|
|
516
|
+
}
|
|
517
|
+
function parseMatcherHookEntries(rawHooks, eventMap, toolMatchers) {
|
|
518
|
+
const hooks = {};
|
|
519
|
+
for (const [nativeEvent, rawMatchers] of Object.entries(rawHooks)) {
|
|
520
|
+
if (!Array.isArray(rawMatchers)) {
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
for (const rawMatcher of rawMatchers) {
|
|
524
|
+
if (!rawMatcher || typeof rawMatcher !== 'object') {
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
const matcherValue = rawMatcher, event = resolveMatcherBackedEvent(nativeEvent, typeof matcherValue.matcher === 'string' ? matcherValue.matcher : undefined, eventMap, toolMatchers);
|
|
528
|
+
if (!event || !Array.isArray(matcherValue.hooks)) {
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
const actions = matcherValue.hooks
|
|
532
|
+
.map((action) => parseHookAction(action))
|
|
533
|
+
.filter((action) => action !== null);
|
|
534
|
+
pushImportedMatchers(hooks, event, [{
|
|
535
|
+
...(normalizeImportedMatcher(event, typeof matcherValue.matcher === 'string' ? matcherValue.matcher : undefined, toolMatchers) && {
|
|
536
|
+
matcher: normalizeImportedMatcher(event, typeof matcherValue.matcher === 'string' ? matcherValue.matcher : undefined, toolMatchers),
|
|
537
|
+
}),
|
|
538
|
+
hooks: actions,
|
|
539
|
+
}]);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return hooks;
|
|
543
|
+
}
|
|
544
|
+
function parseImportedHooks(editor, content) {
|
|
545
|
+
const eventMap = getHookEventMap(editor);
|
|
546
|
+
if (!eventMap) {
|
|
547
|
+
return { hooks: {}, warnings: [] };
|
|
548
|
+
}
|
|
549
|
+
const parsed = parseJsonc(content), warnings = parsed.errors.map((error) => `Failed to parse hooks config: ${error.message}`), rawHooks = parsed.data?.hooks;
|
|
550
|
+
if (!rawHooks || typeof rawHooks !== 'object') {
|
|
551
|
+
return { hooks: {}, warnings };
|
|
552
|
+
}
|
|
553
|
+
const toolMatchers = getHookToolMatcherMap(editor), hooks = editor === 'cursor' || editor === 'windsurf'
|
|
554
|
+
? parseFlatHookEntries(rawHooks, eventMap)
|
|
555
|
+
: parseMatcherHookEntries(rawHooks, eventMap, toolMatchers);
|
|
556
|
+
return { hooks, warnings };
|
|
557
|
+
}
|
|
558
|
+
async function importHooks(editor, source, projectRoot) {
|
|
559
|
+
const configPath = getHookConfigPath(editor, projectRoot, source);
|
|
560
|
+
if (!configPath) {
|
|
561
|
+
return { hooks: {}, paths: {}, scopes: {}, warnings: [] };
|
|
562
|
+
}
|
|
563
|
+
try {
|
|
564
|
+
const content = await readFile(configPath, 'utf-8'), parsed = parseImportedHooks(editor, content), scope = source === 'global' ? 'user' : 'project', eventNames = Object.keys(parsed.hooks);
|
|
565
|
+
return {
|
|
566
|
+
hooks: parsed.hooks,
|
|
567
|
+
paths: pathMapForNames(eventNames, configPath),
|
|
568
|
+
scopes: scopeMapForNames(eventNames, scope),
|
|
569
|
+
warnings: parsed.warnings,
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
catch (err) {
|
|
573
|
+
if (err.code === 'ENOENT') {
|
|
574
|
+
return { hooks: {}, paths: {}, scopes: {}, warnings: [] };
|
|
575
|
+
}
|
|
576
|
+
return {
|
|
577
|
+
hooks: {},
|
|
578
|
+
paths: {},
|
|
579
|
+
scopes: {},
|
|
580
|
+
warnings: [`Failed to read hooks config at ${configPath}: ${err.message}`],
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
}
|
|
121
584
|
/** Editor config directory names */
|
|
122
585
|
const EDITOR_CONFIG_DIRS = {
|
|
123
586
|
windsurf: '.windsurf',
|
|
124
587
|
cursor: '.cursor',
|
|
125
588
|
'claude-code': '.claude',
|
|
126
|
-
|
|
589
|
+
copilot: '.vscode',
|
|
127
590
|
zed: '.zed',
|
|
128
591
|
codex: '.codex',
|
|
592
|
+
gemini: '.gemini',
|
|
593
|
+
opencode: '.opencode',
|
|
594
|
+
};
|
|
595
|
+
const EDITOR_SKILL_DIRS = {
|
|
596
|
+
windsurf: ['.windsurf/skills'],
|
|
597
|
+
cursor: ['.cursor/skills'],
|
|
598
|
+
'claude-code': ['.claude/skills'],
|
|
599
|
+
copilot: ['.github/skills'],
|
|
600
|
+
zed: ['.aix/skills'],
|
|
601
|
+
codex: ['.agents/skills'],
|
|
602
|
+
gemini: ['.gemini/skills'],
|
|
603
|
+
opencode: ['.opencode/skills'],
|
|
604
|
+
};
|
|
605
|
+
const EDITOR_GLOBAL_RULE_DIRS = {
|
|
606
|
+
'claude-code': ['.claude/rules'],
|
|
607
|
+
};
|
|
608
|
+
const EDITOR_GLOBAL_SKILL_DIRS = {
|
|
609
|
+
windsurf: ['.windsurf/skills'],
|
|
610
|
+
cursor: ['.cursor/skills'],
|
|
611
|
+
'claude-code': ['.claude/skills'],
|
|
612
|
+
copilot: ['.copilot/skills'],
|
|
613
|
+
codex: ['.codex/skills'],
|
|
614
|
+
gemini: ['.gemini/skills'],
|
|
615
|
+
opencode: ['.config/opencode/skills'],
|
|
129
616
|
};
|
|
130
617
|
/**
|
|
131
618
|
* Import MCP configuration from an editor's global config.
|
|
132
619
|
*/
|
|
133
|
-
async function importMcpConfig(strategy,
|
|
620
|
+
async function importMcpConfig(strategy, editor, _source) {
|
|
134
621
|
const warnings = [], configPath = strategy.getGlobalMcpConfigPath();
|
|
135
622
|
if (!configPath) {
|
|
136
623
|
// Not a warning - some editors don't have global MCP config
|
|
137
|
-
return { mcp: {}, warnings };
|
|
624
|
+
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
138
625
|
}
|
|
139
|
-
const fullPath =
|
|
626
|
+
const fullPath = editor === 'opencode'
|
|
627
|
+
? resolveOpenCodeConfigPath(join(homedir(), configPath))
|
|
628
|
+
: join(homedir(), configPath);
|
|
140
629
|
try {
|
|
141
630
|
const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
|
|
142
|
-
return
|
|
631
|
+
return {
|
|
632
|
+
...result,
|
|
633
|
+
paths: pathMapForNames(Object.keys(result.mcp), fullPath),
|
|
634
|
+
scopes: scopeMapForNames(Object.keys(result.mcp), 'user'),
|
|
635
|
+
};
|
|
143
636
|
}
|
|
144
637
|
catch (err) {
|
|
145
638
|
if (err.code !== 'ENOENT') {
|
|
146
639
|
warnings.push(`Failed to read global MCP config at ${fullPath}: ${err.message}`);
|
|
147
640
|
}
|
|
148
641
|
}
|
|
149
|
-
return { mcp: {}, warnings };
|
|
642
|
+
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
150
643
|
}
|
|
151
644
|
/**
|
|
152
645
|
* Import MCP configuration from project-local editor config.
|
|
153
646
|
*/
|
|
154
647
|
async function importLocalMcpConfig(strategy, editor, projectRoot) {
|
|
155
|
-
const warnings = []
|
|
648
|
+
const warnings = [];
|
|
156
649
|
// Skip if MCP is not supported for project-local config (e.g., global-only editors)
|
|
157
650
|
if (!strategy.isSupported() || strategy.isGlobalOnly?.()) {
|
|
158
|
-
return { mcp: {}, warnings };
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
|
|
162
|
-
return result;
|
|
651
|
+
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
163
652
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
653
|
+
for (const fullPath of getLocalMcpImportPaths(strategy, editor, projectRoot)) {
|
|
654
|
+
try {
|
|
655
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
656
|
+
const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
|
|
657
|
+
return {
|
|
658
|
+
...result,
|
|
659
|
+
paths: pathMapForNames(Object.keys(result.mcp), fullPath),
|
|
660
|
+
scopes: scopeMapForNames(Object.keys(result.mcp), 'project'),
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
catch (err) {
|
|
664
|
+
if (err.code !== 'ENOENT' &&
|
|
665
|
+
err.code !== 'EISDIR') {
|
|
666
|
+
warnings.push(`Failed to read local MCP config at ${fullPath}: ${err.message}`);
|
|
667
|
+
}
|
|
168
668
|
}
|
|
169
669
|
}
|
|
170
|
-
return { mcp: {}, warnings };
|
|
670
|
+
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
671
|
+
}
|
|
672
|
+
function getLocalMcpImportPaths(strategy, editor, projectRoot) {
|
|
673
|
+
const configDir = EDITOR_CONFIG_DIRS[editor], mcpConfigPath = strategy.getConfigPath(), baseDir = strategy.isProjectRootConfig?.() ? projectRoot : join(projectRoot, configDir), primaryPath = editor === 'opencode'
|
|
674
|
+
? resolveOpenCodeConfigPath(join(baseDir, mcpConfigPath))
|
|
675
|
+
: join(baseDir, mcpConfigPath);
|
|
676
|
+
if (editor !== 'copilot') {
|
|
677
|
+
return [primaryPath];
|
|
678
|
+
}
|
|
679
|
+
return [
|
|
680
|
+
primaryPath,
|
|
681
|
+
join(projectRoot, '.github/mcp.json'),
|
|
682
|
+
];
|
|
171
683
|
}
|
|
172
684
|
/**
|
|
173
685
|
* Import rules from an editor's global config. Tags each rule with the name 'global'.
|
|
174
686
|
*/
|
|
175
|
-
async function importGlobalRules(strategy) {
|
|
176
|
-
const warnings = [], rulesPath = strategy.getGlobalRulesPath();
|
|
177
|
-
if (
|
|
178
|
-
|
|
687
|
+
async function importGlobalRules(strategy, editor) {
|
|
688
|
+
const warnings = [], rulesPath = strategy.getGlobalRulesPath(), rules = [], paths = {}, scopes = {};
|
|
689
|
+
if (rulesPath) {
|
|
690
|
+
const fullPath = join(homedir(), rulesPath);
|
|
691
|
+
try {
|
|
692
|
+
const content = await readFile(fullPath, 'utf-8'), parsed = strategy.parseGlobalRules(content);
|
|
693
|
+
for (const [index, rule] of parsed.rules.entries()) {
|
|
694
|
+
const name = index === 0 ? 'global' : `global-${index + 1}`;
|
|
695
|
+
rules.push({ content: rule, name, path: fullPath, scope: 'user' });
|
|
696
|
+
paths[name] = fullPath;
|
|
697
|
+
scopes[name] = 'user';
|
|
698
|
+
}
|
|
699
|
+
warnings.push(...parsed.warnings);
|
|
700
|
+
}
|
|
701
|
+
catch (err) {
|
|
702
|
+
if (err.code !== 'ENOENT') {
|
|
703
|
+
warnings.push(`Failed to read global rules from ${fullPath}: ${err.message}`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (editor === 'opencode') {
|
|
708
|
+
const configPath = resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), imported = await importOpenCodeInstructionRules(configPath, dirname(configPath), 'user');
|
|
709
|
+
rules.push(...imported.rules);
|
|
710
|
+
Object.assign(paths, imported.paths);
|
|
711
|
+
Object.assign(scopes, imported.scopes);
|
|
712
|
+
warnings.push(...imported.warnings);
|
|
713
|
+
}
|
|
714
|
+
const ruleDirs = EDITOR_GLOBAL_RULE_DIRS[editor] ?? [];
|
|
715
|
+
for (const ruleDir of ruleDirs) {
|
|
716
|
+
const fullPath = join(homedir(), ruleDir);
|
|
717
|
+
try {
|
|
718
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
719
|
+
const files = await readdir(fullPath), ext = strategy.getFileExtension(), ruleFiles = files.filter((file) => file.endsWith(ext)).toSorted();
|
|
720
|
+
for (const file of ruleFiles) {
|
|
721
|
+
const path = join(fullPath, file), name = file.slice(0, -ext.length);
|
|
722
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
723
|
+
const rule = await readGlobalRuleFile(path, name, warnings);
|
|
724
|
+
if (rule) {
|
|
725
|
+
rules.push(rule);
|
|
726
|
+
paths[name] = path;
|
|
727
|
+
scopes[name] = 'user';
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
catch (err) {
|
|
732
|
+
if (err.code !== 'ENOENT') {
|
|
733
|
+
warnings.push(`Failed to read global rules from ${fullPath}: ${err.message}`);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
179
736
|
}
|
|
180
|
-
|
|
737
|
+
return { rules, paths, scopes, warnings };
|
|
738
|
+
}
|
|
739
|
+
async function readGlobalRuleFile(path, name, warnings) {
|
|
181
740
|
try {
|
|
182
|
-
const content = await readFile(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
741
|
+
const content = await readFile(path, 'utf-8'), trimmed = content.trim();
|
|
742
|
+
if (!trimmed) {
|
|
743
|
+
return undefined;
|
|
744
|
+
}
|
|
745
|
+
return { content: trimmed, name, path, scope: 'user' };
|
|
187
746
|
}
|
|
188
747
|
catch (err) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
748
|
+
warnings.push(`Failed to read global rule ${path}: ${err.message}`);
|
|
749
|
+
return undefined;
|
|
192
750
|
}
|
|
193
|
-
return { rules: [], warnings };
|
|
194
751
|
}
|
|
195
752
|
/**
|
|
196
753
|
* Import rules from project-local editor config. Tags each rule with its filename (sans extension).
|
|
197
754
|
*/
|
|
198
755
|
async function importLocalRules(strategy, editor, projectRoot) {
|
|
756
|
+
// Codex uses AGENTS.md at the project root (not inside .codex/), so use a dedicated reader
|
|
757
|
+
if (editor === 'codex') {
|
|
758
|
+
return importCodexLocalRules(projectRoot);
|
|
759
|
+
}
|
|
760
|
+
// Gemini uses GEMINI.md at the project root (not inside .gemini/), similar to Codex
|
|
761
|
+
if (editor === 'gemini') {
|
|
762
|
+
return importGeminiLocalRules(projectRoot);
|
|
763
|
+
}
|
|
764
|
+
if (editor === 'opencode') {
|
|
765
|
+
return importOpenCodeLocalRules(projectRoot);
|
|
766
|
+
}
|
|
767
|
+
if (editor === 'zed') {
|
|
768
|
+
return importZedLocalRules(projectRoot);
|
|
769
|
+
}
|
|
199
770
|
const warnings = [], configDir = EDITOR_CONFIG_DIRS[editor], rulesDir = strategy.getRulesDir(), fullPath = join(projectRoot, configDir, rulesDir);
|
|
200
771
|
try {
|
|
201
|
-
const files = await readdir(fullPath), ext = strategy.getFileExtension(), ruleFiles = files.filter((f) => f.endsWith(ext)), rules = [];
|
|
772
|
+
const files = await readdir(fullPath), ext = strategy.getFileExtension(), ruleFiles = files.filter((f) => f.endsWith(ext)), rules = [], paths = {}, scopes = {};
|
|
202
773
|
for (const file of ruleFiles) {
|
|
203
774
|
try {
|
|
775
|
+
const path = join(fullPath, file);
|
|
204
776
|
// eslint-disable-next-line no-await-in-loop -- Sequential for simplicity
|
|
205
|
-
const content = await readFile(
|
|
206
|
-
rules.push({ content, name });
|
|
777
|
+
const content = await readFile(path, 'utf-8'), name = file.endsWith(ext) ? file.slice(0, -ext.length) : file;
|
|
778
|
+
rules.push({ content, name, path, scope: 'project' });
|
|
779
|
+
paths[name] = path;
|
|
780
|
+
scopes[name] = 'project';
|
|
207
781
|
}
|
|
208
782
|
catch {
|
|
209
783
|
// Skip files that can't be read
|
|
210
784
|
}
|
|
211
785
|
}
|
|
212
|
-
return { rules, warnings };
|
|
786
|
+
return { rules, paths, scopes, warnings };
|
|
213
787
|
}
|
|
214
788
|
catch (err) {
|
|
215
789
|
if (err.code !== 'ENOENT') {
|
|
216
790
|
warnings.push(`Failed to read local rules from ${fullPath}: ${err.message}`);
|
|
217
791
|
}
|
|
218
792
|
}
|
|
219
|
-
return { rules: [], warnings };
|
|
793
|
+
return { rules: [], paths: {}, scopes: {}, warnings };
|
|
794
|
+
}
|
|
795
|
+
async function importZedLocalRules(projectRoot) {
|
|
796
|
+
const warnings = [], rulesPath = join(projectRoot, '.rules');
|
|
797
|
+
try {
|
|
798
|
+
const content = await readFile(rulesPath, 'utf-8');
|
|
799
|
+
if (content.trim()) {
|
|
800
|
+
return {
|
|
801
|
+
rules: [
|
|
802
|
+
{
|
|
803
|
+
content: content.trim(),
|
|
804
|
+
name: 'project rules',
|
|
805
|
+
path: rulesPath,
|
|
806
|
+
scope: 'project',
|
|
807
|
+
},
|
|
808
|
+
],
|
|
809
|
+
paths: { 'project rules': rulesPath },
|
|
810
|
+
scopes: { 'project rules': 'project' },
|
|
811
|
+
warnings,
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
catch (err) {
|
|
816
|
+
if (err.code !== 'ENOENT') {
|
|
817
|
+
warnings.push(`Failed to read Zed rules from ${rulesPath}: ${err.message}`);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return { rules: [], paths: {}, scopes: {}, warnings };
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Import Codex rules from AGENTS.md at the project root. Codex discovers one AGENTS.md per
|
|
824
|
+
* directory from root→CWD, so we read the root file and tag it accordingly.
|
|
825
|
+
*/
|
|
826
|
+
async function importCodexLocalRules(projectRoot) {
|
|
827
|
+
const warnings = [], agentsPath = join(projectRoot, 'AGENTS.md');
|
|
828
|
+
try {
|
|
829
|
+
const content = await readFile(agentsPath, 'utf-8');
|
|
830
|
+
if (content.trim()) {
|
|
831
|
+
return {
|
|
832
|
+
rules: [
|
|
833
|
+
{ content: content.trim(), name: 'AGENTS', path: agentsPath, scope: 'project' },
|
|
834
|
+
],
|
|
835
|
+
paths: { AGENTS: agentsPath },
|
|
836
|
+
scopes: { AGENTS: 'project' },
|
|
837
|
+
warnings,
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
catch (err) {
|
|
842
|
+
if (err.code !== 'ENOENT') {
|
|
843
|
+
warnings.push(`Failed to read Codex rules from ${agentsPath}: ${err.message}`);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return { rules: [], paths: {}, scopes: {}, warnings };
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Import Gemini rules from GEMINI.md at the project root. Gemini CLI reads GEMINI.md for
|
|
850
|
+
* project-level context and instructions.
|
|
851
|
+
*/
|
|
852
|
+
async function importGeminiLocalRules(projectRoot) {
|
|
853
|
+
const warnings = [], geminiPath = join(projectRoot, 'GEMINI.md');
|
|
854
|
+
try {
|
|
855
|
+
const content = await readFile(geminiPath, 'utf-8');
|
|
856
|
+
if (content.trim()) {
|
|
857
|
+
return {
|
|
858
|
+
rules: [
|
|
859
|
+
{ content: content.trim(), name: 'GEMINI', path: geminiPath, scope: 'project' },
|
|
860
|
+
],
|
|
861
|
+
paths: { GEMINI: geminiPath },
|
|
862
|
+
scopes: { GEMINI: 'project' },
|
|
863
|
+
warnings,
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
catch (err) {
|
|
868
|
+
if (err.code !== 'ENOENT') {
|
|
869
|
+
warnings.push(`Failed to read Gemini rules from ${geminiPath}: ${err.message}`);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return { rules: [], paths: {}, scopes: {}, warnings };
|
|
873
|
+
}
|
|
874
|
+
async function importOpenCodeLocalRules(projectRoot) {
|
|
875
|
+
const warnings = [], agentsPath = join(projectRoot, 'AGENTS.md'), rules = [], paths = {}, scopes = {};
|
|
876
|
+
try {
|
|
877
|
+
const content = await readFile(agentsPath, 'utf-8');
|
|
878
|
+
if (content.trim()) {
|
|
879
|
+
rules.push({ content: content.trim(), name: 'AGENTS', path: agentsPath, scope: 'project' });
|
|
880
|
+
paths.AGENTS = agentsPath;
|
|
881
|
+
scopes.AGENTS = 'project';
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
catch (err) {
|
|
885
|
+
if (err.code !== 'ENOENT') {
|
|
886
|
+
warnings.push(`Failed to read OpenCode rules from ${agentsPath}: ${err.message}`);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
const imported = await importOpenCodeInstructionRules(resolveOpenCodeConfigPath(join(projectRoot, 'opencode.json')), projectRoot, 'project');
|
|
890
|
+
rules.push(...imported.rules);
|
|
891
|
+
Object.assign(paths, imported.paths);
|
|
892
|
+
Object.assign(scopes, imported.scopes);
|
|
893
|
+
warnings.push(...imported.warnings);
|
|
894
|
+
return { rules, paths, scopes, warnings };
|
|
220
895
|
}
|
|
221
896
|
/**
|
|
222
897
|
* Import prompts/workflows from an editor's global config.
|
|
223
898
|
*/
|
|
224
|
-
async function importPrompts(strategy, _source) {
|
|
899
|
+
async function importPrompts(strategy, editor, _source) {
|
|
225
900
|
const warnings = [], promptsPath = strategy.getGlobalPromptsPath();
|
|
226
901
|
if (!promptsPath) {
|
|
227
|
-
return { prompts: {}, warnings };
|
|
902
|
+
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
228
903
|
}
|
|
229
904
|
const fullPath = join(homedir(), promptsPath);
|
|
230
905
|
try {
|
|
231
906
|
const files = await readdir(fullPath), fileReader = async (filename) => {
|
|
232
907
|
return readFile(join(fullPath, filename), 'utf-8');
|
|
908
|
+
}, result = await strategy.parseGlobalPrompts(files, fileReader);
|
|
909
|
+
const imported = {
|
|
910
|
+
...result,
|
|
911
|
+
paths: promptPathMap(Object.keys(result.prompts), files, fullPath),
|
|
912
|
+
scopes: scopeMapForNames(Object.keys(result.prompts), 'user'),
|
|
233
913
|
};
|
|
234
|
-
|
|
914
|
+
if (editor !== 'opencode') {
|
|
915
|
+
return imported;
|
|
916
|
+
}
|
|
917
|
+
return mergePromptImports(await importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), 'user'), imported);
|
|
235
918
|
}
|
|
236
919
|
catch (err) {
|
|
237
920
|
if (err.code !== 'ENOENT') {
|
|
238
921
|
warnings.push(`Failed to read global prompts from ${fullPath}: ${err.message}`);
|
|
239
922
|
}
|
|
240
923
|
}
|
|
241
|
-
|
|
924
|
+
if (editor === 'opencode') {
|
|
925
|
+
return importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), 'user');
|
|
926
|
+
}
|
|
927
|
+
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
242
928
|
}
|
|
243
929
|
/**
|
|
244
930
|
* Import prompts/workflows from project-local editor config.
|
|
@@ -246,20 +932,285 @@ async function importPrompts(strategy, _source) {
|
|
|
246
932
|
async function importLocalPrompts(strategy, editor, projectRoot) {
|
|
247
933
|
const warnings = [], configDir = EDITOR_CONFIG_DIRS[editor], promptsDir = strategy.getPromptsDir(), fullPath = join(projectRoot, configDir, promptsDir);
|
|
248
934
|
if (!strategy.isSupported()) {
|
|
249
|
-
return { prompts: {}, warnings };
|
|
935
|
+
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
250
936
|
}
|
|
251
937
|
try {
|
|
252
938
|
const files = await readdir(fullPath), fileReader = async (filename) => {
|
|
253
939
|
return readFile(join(fullPath, filename), 'utf-8');
|
|
940
|
+
}, result = await strategy.parseGlobalPrompts(files, fileReader);
|
|
941
|
+
const imported = {
|
|
942
|
+
...result,
|
|
943
|
+
paths: promptPathMap(Object.keys(result.prompts), files, fullPath),
|
|
944
|
+
scopes: scopeMapForNames(Object.keys(result.prompts), 'project'),
|
|
254
945
|
};
|
|
255
|
-
|
|
946
|
+
if (editor !== 'opencode') {
|
|
947
|
+
return imported;
|
|
948
|
+
}
|
|
949
|
+
return mergePromptImports(await importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(projectRoot, 'opencode.json')), 'project'), imported);
|
|
256
950
|
}
|
|
257
951
|
catch (err) {
|
|
258
952
|
if (err.code !== 'ENOENT') {
|
|
259
953
|
warnings.push(`Failed to read local prompts from ${fullPath}: ${err.message}`);
|
|
260
954
|
}
|
|
261
955
|
}
|
|
262
|
-
|
|
956
|
+
if (editor === 'opencode') {
|
|
957
|
+
return importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(projectRoot, 'opencode.json')), 'project');
|
|
958
|
+
}
|
|
959
|
+
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
960
|
+
}
|
|
961
|
+
async function readOpenCodeConfig(configPath) {
|
|
962
|
+
try {
|
|
963
|
+
const parsed = parseJsonc(await readFile(configPath, 'utf-8'));
|
|
964
|
+
if (parsed.errors.length > 0 || !parsed.data) {
|
|
965
|
+
throw new Error('invalid JSONC');
|
|
966
|
+
}
|
|
967
|
+
return parsed.data;
|
|
968
|
+
}
|
|
969
|
+
catch (err) {
|
|
970
|
+
if (err.code === 'ENOENT') {
|
|
971
|
+
return null;
|
|
972
|
+
}
|
|
973
|
+
throw err;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
function resolveOpenCodeConfigPath(jsonPath) {
|
|
977
|
+
if (existsSync(jsonPath)) {
|
|
978
|
+
return jsonPath;
|
|
979
|
+
}
|
|
980
|
+
const jsoncPath = jsonPath.replace(/\.json$/, '.jsonc');
|
|
981
|
+
return existsSync(jsoncPath) ? jsoncPath : jsonPath;
|
|
982
|
+
}
|
|
983
|
+
async function importOpenCodeInstructionRules(configPath, baseDir, scope) {
|
|
984
|
+
const warnings = [], rules = [], paths = {}, scopes = {};
|
|
985
|
+
let config;
|
|
986
|
+
try {
|
|
987
|
+
config = await readOpenCodeConfig(configPath);
|
|
988
|
+
}
|
|
989
|
+
catch (err) {
|
|
990
|
+
warnings.push(`Failed to read OpenCode config from ${configPath}: ${err.message}`);
|
|
991
|
+
return { rules, paths, scopes, warnings };
|
|
992
|
+
}
|
|
993
|
+
if (!Array.isArray(config?.instructions)) {
|
|
994
|
+
return { rules, paths, scopes, warnings };
|
|
995
|
+
}
|
|
996
|
+
for (const instruction of config.instructions) {
|
|
997
|
+
if (typeof instruction !== 'string') {
|
|
998
|
+
warnings.push(`Skipping OpenCode instruction from ${configPath}: expected string path`);
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
1002
|
+
const imported = await importOpenCodeInstructionPattern(instruction, baseDir, scope);
|
|
1003
|
+
rules.push(...imported.rules);
|
|
1004
|
+
Object.assign(paths, imported.paths);
|
|
1005
|
+
Object.assign(scopes, imported.scopes);
|
|
1006
|
+
warnings.push(...imported.warnings);
|
|
1007
|
+
}
|
|
1008
|
+
return { rules, paths, scopes, warnings };
|
|
1009
|
+
}
|
|
1010
|
+
async function importOpenCodeInstructionPattern(instruction, baseDir, scope) {
|
|
1011
|
+
const pathsToRead = hasGlobSyntax(instruction)
|
|
1012
|
+
? await expandInstructionGlob(instruction, baseDir)
|
|
1013
|
+
: [resolveInstructionPath(instruction, baseDir)], rules = [], paths = {}, scopes = {}, warnings = [];
|
|
1014
|
+
if (pathsToRead.length === 0) {
|
|
1015
|
+
warnings.push(`OpenCode instruction pattern matched no files: ${instruction}`);
|
|
1016
|
+
}
|
|
1017
|
+
for (const path of pathsToRead) {
|
|
1018
|
+
try {
|
|
1019
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
1020
|
+
const content = await readFile(path, 'utf-8'), name = basenameWithoutMarkdown(path);
|
|
1021
|
+
if (!content.trim()) {
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
rules.push({ content: content.trim(), name, path, scope });
|
|
1025
|
+
paths[name] = path;
|
|
1026
|
+
scopes[name] = scope;
|
|
1027
|
+
}
|
|
1028
|
+
catch (err) {
|
|
1029
|
+
warnings.push(`Failed to read OpenCode instruction ${path}: ${err.message}`);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
return { rules, paths, scopes, warnings };
|
|
1033
|
+
}
|
|
1034
|
+
async function expandInstructionGlob(pattern, baseDir) {
|
|
1035
|
+
const root = isAbsolute(pattern) ? getGlobRoot(pattern) : baseDir, files = await listFilesRecursive(root), matcher = globToRegExp(isAbsolute(pattern) ? pattern : join(baseDir, pattern));
|
|
1036
|
+
return files.filter((file) => matcher.test(file)).toSorted();
|
|
1037
|
+
}
|
|
1038
|
+
async function listFilesRecursive(root) {
|
|
1039
|
+
const result = [];
|
|
1040
|
+
async function visit(dir) {
|
|
1041
|
+
let entries;
|
|
1042
|
+
try {
|
|
1043
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
1044
|
+
}
|
|
1045
|
+
catch {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
for (const entry of entries) {
|
|
1049
|
+
const path = join(dir, entry.name);
|
|
1050
|
+
if (entry.isDirectory()) {
|
|
1051
|
+
// eslint-disable-next-line no-await-in-loop -- Recursive walk is easier to reason about sequentially
|
|
1052
|
+
await visit(path);
|
|
1053
|
+
}
|
|
1054
|
+
else if (entry.isFile()) {
|
|
1055
|
+
result.push(path);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
await visit(root);
|
|
1060
|
+
return result;
|
|
1061
|
+
}
|
|
1062
|
+
function hasGlobSyntax(value) {
|
|
1063
|
+
return /[*?[\]{}]/.test(value);
|
|
1064
|
+
}
|
|
1065
|
+
function getGlobRoot(pattern) {
|
|
1066
|
+
const parts = pattern.split('/'), rootParts = [];
|
|
1067
|
+
for (const part of parts) {
|
|
1068
|
+
if (hasGlobSyntax(part)) {
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
rootParts.push(part);
|
|
1072
|
+
}
|
|
1073
|
+
return rootParts.join('/') || '/';
|
|
1074
|
+
}
|
|
1075
|
+
function globToRegExp(pattern) {
|
|
1076
|
+
const segments = pattern.split('/');
|
|
1077
|
+
let normalized = '^', startIndex = 0;
|
|
1078
|
+
if (segments[0] === '') {
|
|
1079
|
+
normalized += '/';
|
|
1080
|
+
startIndex = 1;
|
|
1081
|
+
}
|
|
1082
|
+
for (let i = startIndex; i < segments.length; i++) {
|
|
1083
|
+
const segment = segments[i] ?? '', isLast = i === segments.length - 1;
|
|
1084
|
+
if (segment === '**') {
|
|
1085
|
+
normalized += '(?:[^/]+/)*';
|
|
1086
|
+
continue;
|
|
1087
|
+
}
|
|
1088
|
+
normalized += escapeGlobSegment(segment);
|
|
1089
|
+
if (!isLast) {
|
|
1090
|
+
normalized += '/';
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return new RegExp(`${normalized}$`);
|
|
1094
|
+
}
|
|
1095
|
+
function escapeGlobSegment(segment) {
|
|
1096
|
+
return segment
|
|
1097
|
+
.replace(/[.+^${}()|\\]/g, '\\$&')
|
|
1098
|
+
.replace(/\*/g, '[^/]*')
|
|
1099
|
+
.replace(/\?/g, '[^/]');
|
|
1100
|
+
}
|
|
1101
|
+
function resolveInstructionPath(instruction, baseDir) {
|
|
1102
|
+
return isAbsolute(instruction) ? instruction : join(baseDir, instruction);
|
|
1103
|
+
}
|
|
1104
|
+
function basenameWithoutMarkdown(path) {
|
|
1105
|
+
const name = path.split('/').pop() ?? 'instruction';
|
|
1106
|
+
return name.replace(/\.(md|markdown|txt)$/i, '');
|
|
1107
|
+
}
|
|
1108
|
+
async function importOpenCodeConfigPrompts(configPath, scope) {
|
|
1109
|
+
const prompts = {}, paths = {}, scopes = {}, warnings = [];
|
|
1110
|
+
let config;
|
|
1111
|
+
try {
|
|
1112
|
+
config = await readOpenCodeConfig(configPath);
|
|
1113
|
+
}
|
|
1114
|
+
catch (err) {
|
|
1115
|
+
warnings.push(`Failed to read OpenCode config from ${configPath}: ${err.message}`);
|
|
1116
|
+
return { prompts, paths, scopes, warnings };
|
|
1117
|
+
}
|
|
1118
|
+
if (!config?.command) {
|
|
1119
|
+
return { prompts, paths, scopes, warnings };
|
|
1120
|
+
}
|
|
1121
|
+
for (const [name, command] of Object.entries(config.command)) {
|
|
1122
|
+
if (typeof command.template !== 'string') {
|
|
1123
|
+
warnings.push(`Skipping OpenCode command "${name}" from ${configPath}: missing template`);
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1126
|
+
prompts[name] = formatOpenCodeConfigPrompt(command);
|
|
1127
|
+
paths[name] = configPath;
|
|
1128
|
+
scopes[name] = scope;
|
|
1129
|
+
}
|
|
1130
|
+
return { prompts, paths, scopes, warnings };
|
|
1131
|
+
}
|
|
1132
|
+
function formatOpenCodeConfigPrompt(command) {
|
|
1133
|
+
if (typeof command.description !== 'string' || !command.description) {
|
|
1134
|
+
return String(command.template);
|
|
1135
|
+
}
|
|
1136
|
+
return `---\ndescription: ${JSON.stringify(command.description)}\n---\n\n${String(command.template)}`;
|
|
1137
|
+
}
|
|
1138
|
+
function mergePromptImports(base, overlay) {
|
|
1139
|
+
return {
|
|
1140
|
+
prompts: { ...base.prompts, ...overlay.prompts },
|
|
1141
|
+
paths: { ...base.paths, ...overlay.paths },
|
|
1142
|
+
scopes: { ...base.scopes, ...overlay.scopes },
|
|
1143
|
+
warnings: [...base.warnings, ...overlay.warnings],
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
async function importLocalSkills(editor, projectRoot) {
|
|
1147
|
+
const warnings = [], skills = {}, paths = {}, scopes = {};
|
|
1148
|
+
for (const skillDir of EDITOR_SKILL_DIRS[editor]) {
|
|
1149
|
+
const fullPath = join(projectRoot, skillDir);
|
|
1150
|
+
try {
|
|
1151
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
1152
|
+
const entries = await readdir(fullPath, { withFileTypes: true });
|
|
1153
|
+
for (const entry of entries) {
|
|
1154
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
1155
|
+
continue;
|
|
1156
|
+
}
|
|
1157
|
+
const path = join(fullPath, entry.name);
|
|
1158
|
+
if (!existsSync(join(path, 'SKILL.md'))) {
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
skills[entry.name] = path;
|
|
1162
|
+
paths[entry.name] = path;
|
|
1163
|
+
scopes[entry.name] = 'project';
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
catch (err) {
|
|
1167
|
+
if (err.code !== 'ENOENT') {
|
|
1168
|
+
warnings.push(`Failed to read skills from ${fullPath}: ${err.message}`);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return { skills, paths, scopes, warnings };
|
|
1173
|
+
}
|
|
1174
|
+
async function importGlobalSkills(editor) {
|
|
1175
|
+
const warnings = [], skills = {}, paths = {}, scopes = {};
|
|
1176
|
+
for (const skillDir of EDITOR_GLOBAL_SKILL_DIRS[editor] ?? []) {
|
|
1177
|
+
const fullPath = join(homedir(), skillDir);
|
|
1178
|
+
try {
|
|
1179
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
1180
|
+
const entries = await readdir(fullPath, { withFileTypes: true });
|
|
1181
|
+
for (const entry of entries) {
|
|
1182
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
const path = join(fullPath, entry.name);
|
|
1186
|
+
if (!existsSync(join(path, 'SKILL.md'))) {
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
skills[entry.name] = path;
|
|
1190
|
+
paths[entry.name] = path;
|
|
1191
|
+
scopes[entry.name] = 'user';
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
catch (err) {
|
|
1195
|
+
if (err.code !== 'ENOENT') {
|
|
1196
|
+
warnings.push(`Failed to read global skills from ${fullPath}: ${err.message}`);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return { skills, paths, scopes, warnings };
|
|
1201
|
+
}
|
|
1202
|
+
function pathMapForNames(names, path) {
|
|
1203
|
+
return Object.fromEntries(names.map((name) => [name, path]));
|
|
1204
|
+
}
|
|
1205
|
+
function scopeMapForNames(names, scope) {
|
|
1206
|
+
return Object.fromEntries(names.map((name) => [name, scope]));
|
|
1207
|
+
}
|
|
1208
|
+
function promptPathMap(names, files, basePath) {
|
|
1209
|
+
const fileByName = new Map(files.map((file) => [file.replace(/\.md$/, ''), file]));
|
|
1210
|
+
return Object.fromEntries(names.flatMap((name) => {
|
|
1211
|
+
const file = fileByName.get(name);
|
|
1212
|
+
return file ? [[name, join(basePath, file)]] : [];
|
|
1213
|
+
}));
|
|
263
1214
|
}
|
|
264
1215
|
/**
|
|
265
1216
|
* Get the global config path for an editor.
|