@a1st/aix-core 0.1.0 → 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.
Files changed (168) hide show
  1. package/dist/editors/adapters/base.d.ts +2 -1
  2. package/dist/editors/adapters/base.d.ts.map +1 -1
  3. package/dist/editors/adapters/base.js +10 -0
  4. package/dist/editors/adapters/base.js.map +1 -1
  5. package/dist/editors/adapters/claude-code.js +3 -3
  6. package/dist/editors/adapters/claude-code.js.map +1 -1
  7. package/dist/editors/adapters/codex.d.ts.map +1 -1
  8. package/dist/editors/adapters/codex.js +7 -15
  9. package/dist/editors/adapters/codex.js.map +1 -1
  10. package/dist/editors/adapters/copilot.d.ts +3 -2
  11. package/dist/editors/adapters/copilot.d.ts.map +1 -1
  12. package/dist/editors/adapters/copilot.js +21 -6
  13. package/dist/editors/adapters/copilot.js.map +1 -1
  14. package/dist/editors/adapters/gemini.d.ts +12 -2
  15. package/dist/editors/adapters/gemini.d.ts.map +1 -1
  16. package/dist/editors/adapters/gemini.js +51 -11
  17. package/dist/editors/adapters/gemini.js.map +1 -1
  18. package/dist/editors/import.d.ts +2 -1
  19. package/dist/editors/import.d.ts.map +1 -1
  20. package/dist/editors/import.js +95 -780
  21. package/dist/editors/import.js.map +1 -1
  22. package/dist/editors/install.d.ts.map +1 -1
  23. package/dist/editors/install.js +1 -3
  24. package/dist/editors/install.js.map +1 -1
  25. package/dist/editors/prompt-skill-installer.d.ts +17 -0
  26. package/dist/editors/prompt-skill-installer.d.ts.map +1 -0
  27. package/dist/editors/prompt-skill-installer.js +23 -0
  28. package/dist/editors/prompt-skill-installer.js.map +1 -0
  29. package/dist/editors/strategies/claude-code/hooks.d.ts +5 -1
  30. package/dist/editors/strategies/claude-code/hooks.d.ts.map +1 -1
  31. package/dist/editors/strategies/claude-code/hooks.js +270 -38
  32. package/dist/editors/strategies/claude-code/hooks.js.map +1 -1
  33. package/dist/editors/strategies/claude-code/mcp.d.ts +3 -2
  34. package/dist/editors/strategies/claude-code/mcp.d.ts.map +1 -1
  35. package/dist/editors/strategies/claude-code/mcp.js +6 -5
  36. package/dist/editors/strategies/claude-code/mcp.js.map +1 -1
  37. package/dist/editors/strategies/claude-code/prompts.d.ts.map +1 -1
  38. package/dist/editors/strategies/claude-code/prompts.js +15 -67
  39. package/dist/editors/strategies/claude-code/prompts.js.map +1 -1
  40. package/dist/editors/strategies/claude-code/rules.d.ts +1 -0
  41. package/dist/editors/strategies/claude-code/rules.d.ts.map +1 -1
  42. package/dist/editors/strategies/claude-code/rules.js +3 -0
  43. package/dist/editors/strategies/claude-code/rules.js.map +1 -1
  44. package/dist/editors/strategies/codex/prompts.d.ts.map +1 -1
  45. package/dist/editors/strategies/codex/prompts.js +20 -72
  46. package/dist/editors/strategies/codex/prompts.js.map +1 -1
  47. package/dist/editors/strategies/codex/rules.d.ts +2 -1
  48. package/dist/editors/strategies/codex/rules.d.ts.map +1 -1
  49. package/dist/editors/strategies/codex/rules.js +22 -0
  50. package/dist/editors/strategies/codex/rules.js.map +1 -1
  51. package/dist/editors/strategies/copilot/hooks.d.ts +7 -4
  52. package/dist/editors/strategies/copilot/hooks.d.ts.map +1 -1
  53. package/dist/editors/strategies/copilot/hooks.js +212 -50
  54. package/dist/editors/strategies/copilot/hooks.js.map +1 -1
  55. package/dist/editors/strategies/copilot/mcp.d.ts +1 -0
  56. package/dist/editors/strategies/copilot/mcp.d.ts.map +1 -1
  57. package/dist/editors/strategies/copilot/mcp.js +7 -0
  58. package/dist/editors/strategies/copilot/mcp.js.map +1 -1
  59. package/dist/editors/strategies/copilot/prompts.d.ts.map +1 -1
  60. package/dist/editors/strategies/copilot/prompts.js +17 -69
  61. package/dist/editors/strategies/copilot/prompts.js.map +1 -1
  62. package/dist/editors/strategies/cursor/hooks.d.ts +7 -2
  63. package/dist/editors/strategies/cursor/hooks.d.ts.map +1 -1
  64. package/dist/editors/strategies/cursor/hooks.js +171 -22
  65. package/dist/editors/strategies/cursor/hooks.js.map +1 -1
  66. package/dist/editors/strategies/cursor/prompts.d.ts.map +1 -1
  67. package/dist/editors/strategies/cursor/prompts.js +11 -44
  68. package/dist/editors/strategies/cursor/prompts.js.map +1 -1
  69. package/dist/editors/strategies/gemini/hooks.d.ts +18 -0
  70. package/dist/editors/strategies/gemini/hooks.d.ts.map +1 -0
  71. package/dist/editors/strategies/gemini/hooks.js +152 -0
  72. package/dist/editors/strategies/gemini/hooks.js.map +1 -0
  73. package/dist/editors/strategies/gemini/index.d.ts +1 -0
  74. package/dist/editors/strategies/gemini/index.d.ts.map +1 -1
  75. package/dist/editors/strategies/gemini/index.js +1 -0
  76. package/dist/editors/strategies/gemini/index.js.map +1 -1
  77. package/dist/editors/strategies/gemini/prompts.d.ts.map +1 -1
  78. package/dist/editors/strategies/gemini/prompts.js +7 -33
  79. package/dist/editors/strategies/gemini/prompts.js.map +1 -1
  80. package/dist/editors/strategies/gemini/rules.d.ts +2 -1
  81. package/dist/editors/strategies/gemini/rules.d.ts.map +1 -1
  82. package/dist/editors/strategies/gemini/rules.js +22 -0
  83. package/dist/editors/strategies/gemini/rules.js.map +1 -1
  84. package/dist/editors/strategies/opencode/import-utils.d.ts +5 -0
  85. package/dist/editors/strategies/opencode/import-utils.d.ts.map +1 -0
  86. package/dist/editors/strategies/opencode/import-utils.js +181 -0
  87. package/dist/editors/strategies/opencode/import-utils.js.map +1 -0
  88. package/dist/editors/strategies/opencode/mcp.d.ts +2 -0
  89. package/dist/editors/strategies/opencode/mcp.d.ts.map +1 -1
  90. package/dist/editors/strategies/opencode/mcp.js +11 -3
  91. package/dist/editors/strategies/opencode/mcp.js.map +1 -1
  92. package/dist/editors/strategies/opencode/prompts.d.ts +3 -1
  93. package/dist/editors/strategies/opencode/prompts.d.ts.map +1 -1
  94. package/dist/editors/strategies/opencode/prompts.js +72 -64
  95. package/dist/editors/strategies/opencode/prompts.js.map +1 -1
  96. package/dist/editors/strategies/opencode/rules.d.ts +3 -1
  97. package/dist/editors/strategies/opencode/rules.d.ts.map +1 -1
  98. package/dist/editors/strategies/opencode/rules.js +68 -0
  99. package/dist/editors/strategies/opencode/rules.js.map +1 -1
  100. package/dist/editors/strategies/shared/hook-import-utils.d.ts +21 -0
  101. package/dist/editors/strategies/shared/hook-import-utils.d.ts.map +1 -0
  102. package/dist/editors/strategies/shared/hook-import-utils.js +98 -0
  103. package/dist/editors/strategies/shared/hook-import-utils.js.map +1 -0
  104. package/dist/editors/strategies/shared/native-skills.d.ts +2 -0
  105. package/dist/editors/strategies/shared/native-skills.d.ts.map +1 -1
  106. package/dist/editors/strategies/shared/native-skills.js +6 -0
  107. package/dist/editors/strategies/shared/native-skills.js.map +1 -1
  108. package/dist/editors/strategies/shared/no-hooks.d.ts +7 -3
  109. package/dist/editors/strategies/shared/no-hooks.d.ts.map +1 -1
  110. package/dist/editors/strategies/shared/no-hooks.js +14 -2
  111. package/dist/editors/strategies/shared/no-hooks.js.map +1 -1
  112. package/dist/editors/strategies/shared/pointer-skills.d.ts +2 -0
  113. package/dist/editors/strategies/shared/pointer-skills.d.ts.map +1 -1
  114. package/dist/editors/strategies/shared/pointer-skills.js +6 -0
  115. package/dist/editors/strategies/shared/pointer-skills.js.map +1 -1
  116. package/dist/editors/strategies/shared/prompt-utils.d.ts +30 -0
  117. package/dist/editors/strategies/shared/prompt-utils.d.ts.map +1 -0
  118. package/dist/editors/strategies/shared/prompt-utils.js +101 -0
  119. package/dist/editors/strategies/shared/prompt-utils.js.map +1 -0
  120. package/dist/editors/strategies/types.d.ts +95 -0
  121. package/dist/editors/strategies/types.d.ts.map +1 -1
  122. package/dist/editors/strategies/windsurf/hooks.d.ts +5 -1
  123. package/dist/editors/strategies/windsurf/hooks.d.ts.map +1 -1
  124. package/dist/editors/strategies/windsurf/hooks.js +102 -21
  125. package/dist/editors/strategies/windsurf/hooks.js.map +1 -1
  126. package/dist/editors/strategies/windsurf/prompts.d.ts.map +1 -1
  127. package/dist/editors/strategies/windsurf/prompts.js +14 -62
  128. package/dist/editors/strategies/windsurf/prompts.js.map +1 -1
  129. package/dist/editors/strategies/windsurf/rules.js.map +1 -1
  130. package/dist/editors/strategies/zed/prompts.d.ts +2 -12
  131. package/dist/editors/strategies/zed/prompts.d.ts.map +1 -1
  132. package/dist/editors/strategies/zed/prompts.js +2 -19
  133. package/dist/editors/strategies/zed/prompts.js.map +1 -1
  134. package/dist/editors/strategies/zed/rules.d.ts +2 -1
  135. package/dist/editors/strategies/zed/rules.d.ts.map +1 -1
  136. package/dist/editors/strategies/zed/rules.js +27 -0
  137. package/dist/editors/strategies/zed/rules.js.map +1 -1
  138. package/dist/editors/types.d.ts +5 -0
  139. package/dist/editors/types.d.ts.map +1 -1
  140. package/dist/entity-hash.js.map +1 -1
  141. package/dist/format-error.d.ts +16 -3
  142. package/dist/format-error.d.ts.map +1 -1
  143. package/dist/format-error.js +101 -22
  144. package/dist/format-error.js.map +1 -1
  145. package/dist/fs/safe-rm.d.ts +2 -3
  146. package/dist/fs/safe-rm.d.ts.map +1 -1
  147. package/dist/fs/safe-rm.js +7 -1
  148. package/dist/fs/safe-rm.js.map +1 -1
  149. package/dist/global/processor.d.ts.map +1 -1
  150. package/dist/global/processor.js +3 -2
  151. package/dist/global/processor.js.map +1 -1
  152. package/dist/inheritance.js.map +1 -1
  153. package/dist/json.js.map +1 -1
  154. package/dist/loader.d.ts.map +1 -1
  155. package/dist/loader.js +3 -3
  156. package/dist/loader.js.map +1 -1
  157. package/dist/merge.js.map +1 -1
  158. package/dist/reference-resolver.js.map +1 -1
  159. package/dist/remote-loader.js.map +1 -1
  160. package/dist/rules/merger.d.ts.map +1 -1
  161. package/dist/rules/merger.js +2 -2
  162. package/dist/rules/merger.js.map +1 -1
  163. package/dist/rules/utils.js.map +1 -1
  164. package/dist/runtime/node.d.ts.map +1 -1
  165. package/dist/runtime/node.js +11 -4
  166. package/dist/runtime/node.js.map +1 -1
  167. package/dist/skills/resolve.js.map +1 -1
  168. package/package.json +10 -5
@@ -1,29 +1,6 @@
1
- import { dirname, isAbsolute, join } from 'pathe';
2
- import { createEmptyConfig, parseJsonc, } from '@a1st/aix-schema';
3
- import { WindsurfRulesStrategy } from './strategies/windsurf/rules.js';
4
- import { WindsurfPromptsStrategy } from './strategies/windsurf/prompts.js';
5
- import { WindsurfMcpStrategy } from './strategies/windsurf/mcp.js';
6
- import { StandardMcpStrategy } from './strategies/shared/standard-mcp.js';
7
- import { CursorRulesStrategy } from './strategies/cursor/rules.js';
8
- import { CursorPromptsStrategy } from './strategies/cursor/prompts.js';
9
- import { ClaudeCodeMcpStrategy } from './strategies/claude-code/mcp.js';
10
- import { ClaudeCodeRulesStrategy } from './strategies/claude-code/rules.js';
11
- import { ClaudeCodePromptsStrategy } from './strategies/claude-code/prompts.js';
12
- import { CopilotMcpStrategy } from './strategies/copilot/mcp.js';
13
- import { CopilotRulesStrategy } from './strategies/copilot/rules.js';
14
- import { CopilotPromptsStrategy } from './strategies/copilot/prompts.js';
15
- import { ZedMcpStrategy } from './strategies/zed/mcp.js';
16
- import { ZedRulesStrategy } from './strategies/zed/rules.js';
17
- import { ZedPromptsStrategy } from './strategies/zed/prompts.js';
18
- import { CodexRulesStrategy } from './strategies/codex/rules.js';
19
- import { CodexPromptsStrategy } from './strategies/codex/prompts.js';
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';
1
+ import { join } from 'pathe';
2
+ import { createEmptyConfig, } from '@a1st/aix-schema';
3
+ import { getAdapter } from './install.js';
27
4
  import { UnsupportedRuntimeCapabilityError } from '../errors.js';
28
5
  import { getRuntimeAdapter } from '../runtime/index.js';
29
6
  function existsSync(path) {
@@ -46,149 +23,14 @@ function readdir(path, options) {
46
23
  }
47
24
  return getRuntimeAdapter().fs.readdir(path);
48
25
  }
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
- };
138
- /**
139
- * Get the import strategies for an editor.
140
- */
141
- function getImportStrategies(editor) {
142
- switch (editor) {
143
- case 'windsurf':
144
- return {
145
- mcp: new WindsurfMcpStrategy(),
146
- rules: new WindsurfRulesStrategy(),
147
- prompts: new WindsurfPromptsStrategy(),
148
- };
149
- case 'cursor':
150
- return {
151
- mcp: new StandardMcpStrategy(),
152
- rules: new CursorRulesStrategy(),
153
- prompts: new CursorPromptsStrategy(),
154
- };
155
- case 'claude-code':
156
- return {
157
- mcp: new ClaudeCodeMcpStrategy(),
158
- rules: new ClaudeCodeRulesStrategy(),
159
- prompts: new ClaudeCodePromptsStrategy(),
160
- };
161
- case 'copilot':
162
- return {
163
- mcp: new CopilotMcpStrategy(),
164
- rules: new CopilotRulesStrategy(),
165
- prompts: new CopilotPromptsStrategy(),
166
- };
167
- case 'zed':
168
- return {
169
- mcp: new ZedMcpStrategy(),
170
- rules: new ZedRulesStrategy(),
171
- prompts: new ZedPromptsStrategy(),
172
- };
173
- case 'codex':
174
- return {
175
- mcp: new CodexMcpStrategy(),
176
- rules: new CodexRulesStrategy(),
177
- prompts: new CodexPromptsStrategy(),
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
- };
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;
191
32
  }
33
+ return isProjectRootConfig ? join(projectRoot, relativePath) : join(projectRoot, configDir, relativePath);
192
34
  }
193
35
  /**
194
36
  * Import configuration from an editor and convert to ai.json format.
@@ -208,21 +50,21 @@ export async function importFromEditor(editor, options = {}) {
208
50
  scopes: { mcp: {}, rules: {}, skills: {}, prompts: {}, hooks: {} },
209
51
  warnings: [],
210
52
  sources: { global: false, local: false },
211
- }, strategies = getImportStrategies(editor), projectRoot = options.projectRoot ?? getRuntimeAdapter().process.cwd(), scope = options.scope ?? 'all';
53
+ }, strategies = getAdapter(editor).getStrategyBundle(), projectRoot = options.projectRoot ?? getRuntimeAdapter().process.cwd(), scope = options.scope ?? 'all';
212
54
  if (scope === 'all' || scope === 'user') {
213
55
  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'));
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'));
219
61
  }
220
62
  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));
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));
226
68
  }
227
69
  return result;
228
70
  }
@@ -339,11 +181,12 @@ function normalizeImportedPrompt(strategy, [sourceName, rawContent], usedNames)
339
181
  * passed through another editor adapter.
340
182
  */
341
183
  export function normalizeEditorImport(editor, result) {
342
- const strategies = getImportStrategies(editor), usedRuleNames = new Set(), usedPromptNames = new Set(), usedSkillNames = new Set();
184
+ const strategies = getAdapter(editor).getStrategyBundle(), usedRuleNames = new Set(), usedPromptNames = new Set(), usedSkillNames = new Set();
343
185
  return {
344
186
  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)),
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)),
347
190
  skills: Object.entries(result.skills).map(([sourceName, ref]) => ({
348
191
  name: dedupeImportedName(sourceName, usedSkillNames),
349
192
  sourceName,
@@ -393,175 +236,15 @@ export function buildConfigFromEditorImport(editor, result) {
393
236
  }
394
237
  return config;
395
238
  }
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);
239
+ async function importHooks(strategy, configDir, source, projectRoot) {
240
+ const configPath = source === 'global'
241
+ ? buildGlobalPath(strategy.getGlobalConfigPath())
242
+ : buildProjectPath(strategy.getConfigPath(), projectRoot, configDir);
560
243
  if (!configPath) {
561
244
  return { hooks: {}, paths: {}, scopes: {}, warnings: [] };
562
245
  }
563
246
  try {
564
- const content = await readFile(configPath, 'utf-8'), parsed = parseImportedHooks(editor, content), scope = source === 'global' ? 'user' : 'project', eventNames = Object.keys(parsed.hooks);
247
+ const content = await readFile(configPath, 'utf-8'), parsed = strategy.parseImportedConfig(content), scope = source === 'global' ? 'user' : 'project', eventNames = Object.keys(parsed.hooks);
565
248
  return {
566
249
  hooks: parsed.hooks,
567
250
  paths: pathMapForNames(eventNames, configPath),
@@ -581,76 +264,22 @@ async function importHooks(editor, source, projectRoot) {
581
264
  };
582
265
  }
583
266
  }
584
- /** Editor config directory names */
585
- const EDITOR_CONFIG_DIRS = {
586
- windsurf: '.windsurf',
587
- cursor: '.cursor',
588
- 'claude-code': '.claude',
589
- copilot: '.vscode',
590
- zed: '.zed',
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'],
616
- };
617
267
  /**
618
268
  * Import MCP configuration from an editor's global config.
619
269
  */
620
- async function importMcpConfig(strategy, editor, _source) {
621
- const warnings = [], configPath = strategy.getGlobalMcpConfigPath();
622
- if (!configPath) {
623
- // Not a warning - some editors don't have global MCP config
624
- return { mcp: {}, paths: {}, scopes: {}, warnings };
625
- }
626
- const fullPath = editor === 'opencode'
627
- ? resolveOpenCodeConfigPath(join(homedir(), configPath))
628
- : join(homedir(), configPath);
629
- try {
630
- const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
631
- return {
632
- ...result,
633
- paths: pathMapForNames(Object.keys(result.mcp), fullPath),
634
- scopes: scopeMapForNames(Object.keys(result.mcp), 'user'),
635
- };
636
- }
637
- catch (err) {
638
- if (err.code !== 'ENOENT') {
639
- warnings.push(`Failed to read global MCP config at ${fullPath}: ${err.message}`);
640
- }
641
- }
642
- return { mcp: {}, paths: {}, scopes: {}, warnings };
270
+ async function importMcpConfig(strategy, _configDir, _source) {
271
+ return importMcpFromPaths(strategy, getGlobalMcpImportPaths(strategy), 'user', 'global MCP config');
643
272
  }
644
273
  /**
645
274
  * Import MCP configuration from project-local editor config.
646
275
  */
647
- async function importLocalMcpConfig(strategy, editor, projectRoot) {
276
+ async function importLocalMcpConfig(strategy, configDir, projectRoot) {
648
277
  const warnings = [];
649
278
  // Skip if MCP is not supported for project-local config (e.g., global-only editors)
650
279
  if (!strategy.isSupported() || strategy.isGlobalOnly?.()) {
651
280
  return { mcp: {}, paths: {}, scopes: {}, warnings };
652
281
  }
653
- for (const fullPath of getLocalMcpImportPaths(strategy, editor, projectRoot)) {
282
+ for (const fullPath of getLocalMcpImportPaths(strategy, projectRoot, configDir)) {
654
283
  try {
655
284
  // eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
656
285
  const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
@@ -669,22 +298,50 @@ async function importLocalMcpConfig(strategy, editor, projectRoot) {
669
298
  }
670
299
  return { mcp: {}, paths: {}, scopes: {}, warnings };
671
300
  }
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];
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));
678
305
  }
679
- return [
680
- primaryPath,
681
- join(projectRoot, '.github/mcp.json'),
682
- ];
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
+ }
334
+ }
335
+ }
336
+ return { mcp: {}, paths: {}, scopes: {}, warnings };
683
337
  }
684
338
  /**
685
339
  * Import rules from an editor's global config. Tags each rule with the name 'global'.
686
340
  */
687
- async function importGlobalRules(strategy, editor) {
341
+ async function importGlobalRules(strategy, _configDir) {
342
+ if (strategy.importGlobalRules) {
343
+ return strategy.importGlobalRules();
344
+ }
688
345
  const warnings = [], rulesPath = strategy.getGlobalRulesPath(), rules = [], paths = {}, scopes = {};
689
346
  if (rulesPath) {
690
347
  const fullPath = join(homedir(), rulesPath);
@@ -704,14 +361,7 @@ async function importGlobalRules(strategy, editor) {
704
361
  }
705
362
  }
706
363
  }
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] ?? [];
364
+ const ruleDirs = strategy.getGlobalRuleImportDirs?.() ?? [];
715
365
  for (const ruleDir of ruleDirs) {
716
366
  const fullPath = join(homedir(), ruleDir);
717
367
  try {
@@ -752,22 +402,11 @@ async function readGlobalRuleFile(path, name, warnings) {
752
402
  /**
753
403
  * Import rules from project-local editor config. Tags each rule with its filename (sans extension).
754
404
  */
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);
405
+ async function importLocalRules(strategy, configDir, projectRoot) {
406
+ if (strategy.importProjectRules) {
407
+ return strategy.importProjectRules(projectRoot, configDir);
766
408
  }
767
- if (editor === 'zed') {
768
- return importZedLocalRules(projectRoot);
769
- }
770
- const warnings = [], configDir = EDITOR_CONFIG_DIRS[editor], rulesDir = strategy.getRulesDir(), fullPath = join(projectRoot, configDir, rulesDir);
409
+ const warnings = [], rulesDir = strategy.getRulesDir(), fullPath = join(projectRoot, configDir, rulesDir);
771
410
  try {
772
411
  const files = await readdir(fullPath), ext = strategy.getFileExtension(), ruleFiles = files.filter((f) => f.endsWith(ext)), rules = [], paths = {}, scopes = {};
773
412
  for (const file of ruleFiles) {
@@ -792,111 +431,13 @@ async function importLocalRules(strategy, editor, projectRoot) {
792
431
  }
793
432
  return { rules: [], paths: {}, scopes: {}, warnings };
794
433
  }
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 };
895
- }
896
434
  /**
897
435
  * Import prompts/workflows from an editor's global config.
898
436
  */
899
- async function importPrompts(strategy, editor, _source) {
437
+ async function importPrompts(strategy, _configDir, _source) {
438
+ if (strategy.importGlobalPrompts) {
439
+ return strategy.importGlobalPrompts();
440
+ }
900
441
  const warnings = [], promptsPath = strategy.getGlobalPromptsPath();
901
442
  if (!promptsPath) {
902
443
  return { prompts: {}, paths: {}, scopes: {}, warnings };
@@ -911,26 +452,23 @@ async function importPrompts(strategy, editor, _source) {
911
452
  paths: promptPathMap(Object.keys(result.prompts), files, fullPath),
912
453
  scopes: scopeMapForNames(Object.keys(result.prompts), 'user'),
913
454
  };
914
- if (editor !== 'opencode') {
915
- return imported;
916
- }
917
- return mergePromptImports(await importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), 'user'), imported);
455
+ return imported;
918
456
  }
919
457
  catch (err) {
920
458
  if (err.code !== 'ENOENT') {
921
459
  warnings.push(`Failed to read global prompts from ${fullPath}: ${err.message}`);
922
460
  }
923
461
  }
924
- if (editor === 'opencode') {
925
- return importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), 'user');
926
- }
927
462
  return { prompts: {}, paths: {}, scopes: {}, warnings };
928
463
  }
929
464
  /**
930
465
  * Import prompts/workflows from project-local editor config.
931
466
  */
932
- async function importLocalPrompts(strategy, editor, projectRoot) {
933
- const warnings = [], configDir = EDITOR_CONFIG_DIRS[editor], promptsDir = strategy.getPromptsDir(), fullPath = join(projectRoot, configDir, promptsDir);
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);
934
472
  if (!strategy.isSupported()) {
935
473
  return { prompts: {}, paths: {}, scopes: {}, warnings };
936
474
  }
@@ -943,210 +481,19 @@ async function importLocalPrompts(strategy, editor, projectRoot) {
943
481
  paths: promptPathMap(Object.keys(result.prompts), files, fullPath),
944
482
  scopes: scopeMapForNames(Object.keys(result.prompts), 'project'),
945
483
  };
946
- if (editor !== 'opencode') {
947
- return imported;
948
- }
949
- return mergePromptImports(await importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(projectRoot, 'opencode.json')), 'project'), imported);
484
+ return imported;
950
485
  }
951
486
  catch (err) {
952
487
  if (err.code !== 'ENOENT') {
953
488
  warnings.push(`Failed to read local prompts from ${fullPath}: ${err.message}`);
954
489
  }
955
490
  }
956
- if (editor === 'opencode') {
957
- return importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(projectRoot, 'opencode.json')), 'project');
958
- }
959
491
  return { prompts: {}, paths: {}, scopes: {}, warnings };
960
492
  }
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);
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);
1150
497
  try {
1151
498
  // eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
1152
499
  const entries = await readdir(fullPath, { withFileTypes: true });
@@ -1160,7 +507,7 @@ async function importLocalSkills(editor, projectRoot) {
1160
507
  }
1161
508
  skills[entry.name] = path;
1162
509
  paths[entry.name] = path;
1163
- scopes[entry.name] = 'project';
510
+ scopes[entry.name] = source;
1164
511
  }
1165
512
  }
1166
513
  catch (err) {
@@ -1171,34 +518,6 @@ async function importLocalSkills(editor, projectRoot) {
1171
518
  }
1172
519
  return { skills, paths, scopes, warnings };
1173
520
  }
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
521
  function pathMapForNames(names, path) {
1203
522
  return Object.fromEntries(names.map((name) => [name, path]));
1204
523
  }
@@ -1216,10 +535,6 @@ function promptPathMap(names, files, basePath) {
1216
535
  * Get the global config path for an editor.
1217
536
  */
1218
537
  export function getGlobalConfigPath(editor) {
1219
- const strategies = getImportStrategies(editor), configPath = strategies.mcp.getGlobalMcpConfigPath();
1220
- if (!configPath) {
1221
- return null;
1222
- }
1223
- return join(homedir(), configPath);
538
+ return buildGlobalPath(getAdapter(editor).getStrategyBundle().mcpStrategy.getGlobalMcpConfigPath());
1224
539
  }
1225
540
  //# sourceMappingURL=import.js.map