@a1st/aix-core 0.0.12 → 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.
Files changed (316) hide show
  1. package/dist/backup.d.ts.map +1 -1
  2. package/dist/backup.js +13 -14
  3. package/dist/backup.js.map +1 -1
  4. package/dist/cache/cleanup.d.ts.map +1 -1
  5. package/dist/cache/cleanup.js +7 -8
  6. package/dist/cache/cleanup.js.map +1 -1
  7. package/dist/cache/clear.js +4 -4
  8. package/dist/cache/clear.js.map +1 -1
  9. package/dist/cache/status.d.ts.map +1 -1
  10. package/dist/cache/status.js +4 -5
  11. package/dist/cache/status.js.map +1 -1
  12. package/dist/discovery.d.ts.map +1 -1
  13. package/dist/discovery.js +18 -17
  14. package/dist/discovery.js.map +1 -1
  15. package/dist/editors/adapters/base.d.ts +6 -3
  16. package/dist/editors/adapters/base.d.ts.map +1 -1
  17. package/dist/editors/adapters/base.js +121 -40
  18. package/dist/editors/adapters/base.js.map +1 -1
  19. package/dist/editors/adapters/claude-code.d.ts +3 -3
  20. package/dist/editors/adapters/claude-code.d.ts.map +1 -1
  21. package/dist/editors/adapters/claude-code.js +4 -3
  22. package/dist/editors/adapters/claude-code.js.map +1 -1
  23. package/dist/editors/adapters/codex.d.ts +20 -10
  24. package/dist/editors/adapters/codex.d.ts.map +1 -1
  25. package/dist/editors/adapters/codex.js +75 -30
  26. package/dist/editors/adapters/codex.js.map +1 -1
  27. package/dist/editors/adapters/copilot.d.ts +5 -3
  28. package/dist/editors/adapters/copilot.d.ts.map +1 -1
  29. package/dist/editors/adapters/copilot.js +36 -8
  30. package/dist/editors/adapters/copilot.js.map +1 -1
  31. package/dist/editors/adapters/cursor.d.ts +2 -2
  32. package/dist/editors/adapters/cursor.d.ts.map +1 -1
  33. package/dist/editors/adapters/cursor.js +3 -2
  34. package/dist/editors/adapters/cursor.js.map +1 -1
  35. package/dist/editors/adapters/gemini.d.ts +34 -0
  36. package/dist/editors/adapters/gemini.d.ts.map +1 -0
  37. package/dist/editors/adapters/gemini.js +99 -0
  38. package/dist/editors/adapters/gemini.js.map +1 -0
  39. package/dist/editors/adapters/index.d.ts +2 -0
  40. package/dist/editors/adapters/index.d.ts.map +1 -1
  41. package/dist/editors/adapters/index.js +2 -0
  42. package/dist/editors/adapters/index.js.map +1 -1
  43. package/dist/editors/adapters/opencode.d.ts +25 -0
  44. package/dist/editors/adapters/opencode.d.ts.map +1 -0
  45. package/dist/editors/adapters/opencode.js +74 -0
  46. package/dist/editors/adapters/opencode.js.map +1 -0
  47. package/dist/editors/adapters/windsurf.d.ts +1 -1
  48. package/dist/editors/adapters/windsurf.d.ts.map +1 -1
  49. package/dist/editors/adapters/windsurf.js +2 -1
  50. package/dist/editors/adapters/windsurf.js.map +1 -1
  51. package/dist/editors/adapters/zed.d.ts.map +1 -1
  52. package/dist/editors/adapters/zed.js +8 -3
  53. package/dist/editors/adapters/zed.js.map +1 -1
  54. package/dist/editors/import.d.ts +61 -1
  55. package/dist/editors/import.d.ts.map +1 -1
  56. package/dist/editors/import.js +1014 -86
  57. package/dist/editors/import.js.map +1 -1
  58. package/dist/editors/index.d.ts +4 -4
  59. package/dist/editors/index.d.ts.map +1 -1
  60. package/dist/editors/index.js +2 -2
  61. package/dist/editors/index.js.map +1 -1
  62. package/dist/editors/install.d.ts.map +1 -1
  63. package/dist/editors/install.js +56 -8
  64. package/dist/editors/install.js.map +1 -1
  65. package/dist/editors/section-managed-markdown.d.ts +33 -0
  66. package/dist/editors/section-managed-markdown.d.ts.map +1 -0
  67. package/dist/editors/section-managed-markdown.js +97 -0
  68. package/dist/editors/section-managed-markdown.js.map +1 -0
  69. package/dist/editors/strategies/claude-code/hooks.d.ts +1 -0
  70. package/dist/editors/strategies/claude-code/hooks.d.ts.map +1 -1
  71. package/dist/editors/strategies/claude-code/hooks.js +17 -0
  72. package/dist/editors/strategies/claude-code/hooks.js.map +1 -1
  73. package/dist/editors/strategies/claude-code/mcp.d.ts.map +1 -1
  74. package/dist/editors/strategies/claude-code/mcp.js +2 -2
  75. package/dist/editors/strategies/claude-code/mcp.js.map +1 -1
  76. package/dist/editors/strategies/claude-code/prompts.d.ts +1 -1
  77. package/dist/editors/strategies/claude-code/prompts.d.ts.map +1 -1
  78. package/dist/editors/strategies/claude-code/prompts.js +37 -6
  79. package/dist/editors/strategies/claude-code/prompts.js.map +1 -1
  80. package/dist/editors/strategies/claude-code/rules.js +3 -3
  81. package/dist/editors/strategies/claude-code/rules.js.map +1 -1
  82. package/dist/editors/strategies/codex/prompts.d.ts +6 -5
  83. package/dist/editors/strategies/codex/prompts.d.ts.map +1 -1
  84. package/dist/editors/strategies/codex/prompts.js +49 -18
  85. package/dist/editors/strategies/codex/prompts.js.map +1 -1
  86. package/dist/editors/strategies/copilot/hooks.d.ts +2 -1
  87. package/dist/editors/strategies/copilot/hooks.d.ts.map +1 -1
  88. package/dist/editors/strategies/copilot/hooks.js +27 -18
  89. package/dist/editors/strategies/copilot/hooks.js.map +1 -1
  90. package/dist/editors/strategies/copilot/mcp.d.ts +3 -2
  91. package/dist/editors/strategies/copilot/mcp.d.ts.map +1 -1
  92. package/dist/editors/strategies/copilot/mcp.js +76 -41
  93. package/dist/editors/strategies/copilot/mcp.js.map +1 -1
  94. package/dist/editors/strategies/copilot/prompts.d.ts +2 -1
  95. package/dist/editors/strategies/copilot/prompts.d.ts.map +1 -1
  96. package/dist/editors/strategies/copilot/prompts.js +7 -5
  97. package/dist/editors/strategies/copilot/prompts.js.map +1 -1
  98. package/dist/editors/strategies/cursor/hooks.d.ts +1 -0
  99. package/dist/editors/strategies/cursor/hooks.d.ts.map +1 -1
  100. package/dist/editors/strategies/cursor/hooks.js +3 -0
  101. package/dist/editors/strategies/cursor/hooks.js.map +1 -1
  102. package/dist/editors/strategies/cursor/rules.js +3 -3
  103. package/dist/editors/strategies/cursor/rules.js.map +1 -1
  104. package/dist/editors/strategies/gemini/index.d.ts +4 -0
  105. package/dist/editors/strategies/gemini/index.d.ts.map +1 -0
  106. package/dist/editors/strategies/gemini/index.js +4 -0
  107. package/dist/editors/strategies/gemini/index.js.map +1 -0
  108. package/dist/editors/strategies/gemini/mcp.d.ts +19 -0
  109. package/dist/editors/strategies/gemini/mcp.d.ts.map +1 -0
  110. package/dist/editors/strategies/gemini/mcp.js +73 -0
  111. package/dist/editors/strategies/gemini/mcp.js.map +1 -0
  112. package/dist/editors/strategies/gemini/prompts.d.ts +34 -0
  113. package/dist/editors/strategies/gemini/prompts.d.ts.map +1 -0
  114. package/dist/editors/strategies/gemini/prompts.js +118 -0
  115. package/dist/editors/strategies/gemini/prompts.js.map +1 -0
  116. package/dist/editors/strategies/gemini/rules.d.ts +18 -0
  117. package/dist/editors/strategies/gemini/rules.d.ts.map +1 -0
  118. package/dist/editors/strategies/gemini/rules.js +36 -0
  119. package/dist/editors/strategies/gemini/rules.js.map +1 -0
  120. package/dist/editors/strategies/index.d.ts +1 -0
  121. package/dist/editors/strategies/index.d.ts.map +1 -1
  122. package/dist/editors/strategies/index.js +1 -0
  123. package/dist/editors/strategies/index.js.map +1 -1
  124. package/dist/editors/strategies/opencode/index.d.ts +4 -0
  125. package/dist/editors/strategies/opencode/index.d.ts.map +1 -0
  126. package/dist/editors/strategies/opencode/index.js +4 -0
  127. package/dist/editors/strategies/opencode/index.js.map +1 -0
  128. package/dist/editors/strategies/opencode/mcp.d.ts +17 -0
  129. package/dist/editors/strategies/opencode/mcp.d.ts.map +1 -0
  130. package/dist/editors/strategies/opencode/mcp.js +137 -0
  131. package/dist/editors/strategies/opencode/mcp.js.map +1 -0
  132. package/dist/editors/strategies/opencode/prompts.d.ts +20 -0
  133. package/dist/editors/strategies/opencode/prompts.d.ts.map +1 -0
  134. package/dist/editors/strategies/opencode/prompts.js +94 -0
  135. package/dist/editors/strategies/opencode/prompts.js.map +1 -0
  136. package/dist/editors/strategies/opencode/rules.d.ts +17 -0
  137. package/dist/editors/strategies/opencode/rules.d.ts.map +1 -0
  138. package/dist/editors/strategies/opencode/rules.js +31 -0
  139. package/dist/editors/strategies/opencode/rules.js.map +1 -0
  140. package/dist/editors/strategies/shared/global-mcp.d.ts.map +1 -1
  141. package/dist/editors/strategies/shared/global-mcp.js +4 -6
  142. package/dist/editors/strategies/shared/global-mcp.js.map +1 -1
  143. package/dist/editors/strategies/shared/native-skills.d.ts +8 -4
  144. package/dist/editors/strategies/shared/native-skills.d.ts.map +1 -1
  145. package/dist/editors/strategies/shared/native-skills.js +23 -23
  146. package/dist/editors/strategies/shared/native-skills.js.map +1 -1
  147. package/dist/editors/strategies/shared/no-hooks.d.ts +2 -1
  148. package/dist/editors/strategies/shared/no-hooks.d.ts.map +1 -1
  149. package/dist/editors/strategies/shared/no-hooks.js +4 -1
  150. package/dist/editors/strategies/shared/no-hooks.js.map +1 -1
  151. package/dist/editors/strategies/shared/pointer-skills.d.ts +5 -2
  152. package/dist/editors/strategies/shared/pointer-skills.d.ts.map +1 -1
  153. package/dist/editors/strategies/shared/pointer-skills.js +15 -10
  154. package/dist/editors/strategies/shared/pointer-skills.js.map +1 -1
  155. package/dist/editors/strategies/types.d.ts +9 -2
  156. package/dist/editors/strategies/types.d.ts.map +1 -1
  157. package/dist/editors/strategies/windsurf/hooks.d.ts +1 -0
  158. package/dist/editors/strategies/windsurf/hooks.d.ts.map +1 -1
  159. package/dist/editors/strategies/windsurf/hooks.js +5 -0
  160. package/dist/editors/strategies/windsurf/hooks.js.map +1 -1
  161. package/dist/editors/strategies/windsurf/prompts.js +2 -2
  162. package/dist/editors/strategies/windsurf/prompts.js.map +1 -1
  163. package/dist/editors/strategies/windsurf/rules.js +3 -3
  164. package/dist/editors/strategies/windsurf/rules.js.map +1 -1
  165. package/dist/editors/strategies/windsurf/skills.d.ts +1 -1
  166. package/dist/editors/strategies/windsurf/skills.d.ts.map +1 -1
  167. package/dist/editors/strategies/windsurf/skills.js +4 -2
  168. package/dist/editors/strategies/windsurf/skills.js.map +1 -1
  169. package/dist/editors/types.d.ts +39 -1
  170. package/dist/editors/types.d.ts.map +1 -1
  171. package/dist/entity-hash.d.ts +26 -0
  172. package/dist/entity-hash.d.ts.map +1 -0
  173. package/dist/entity-hash.js +106 -0
  174. package/dist/entity-hash.js.map +1 -0
  175. package/dist/env/ci.d.ts +0 -4
  176. package/dist/env/ci.d.ts.map +1 -1
  177. package/dist/env/ci.js +10 -8
  178. package/dist/env/ci.js.map +1 -1
  179. package/dist/errors.d.ts +5 -0
  180. package/dist/errors.d.ts.map +1 -1
  181. package/dist/errors.js +13 -1
  182. package/dist/errors.js.map +1 -1
  183. package/dist/frontmatter-utils.d.ts +7 -2
  184. package/dist/frontmatter-utils.d.ts.map +1 -1
  185. package/dist/frontmatter-utils.js +9 -2
  186. package/dist/frontmatter-utils.js.map +1 -1
  187. package/dist/fs/safe-rm.d.ts.map +1 -1
  188. package/dist/fs/safe-rm.js +15 -10
  189. package/dist/fs/safe-rm.js.map +1 -1
  190. package/dist/git-download.js +4 -4
  191. package/dist/git-download.js.map +1 -1
  192. package/dist/git-loader.d.ts.map +1 -1
  193. package/dist/git-loader.js +5 -6
  194. package/dist/git-loader.js.map +1 -1
  195. package/dist/global/index.d.ts +3 -4
  196. package/dist/global/index.d.ts.map +1 -1
  197. package/dist/global/index.js +2 -3
  198. package/dist/global/index.js.map +1 -1
  199. package/dist/global/processor.d.ts.map +1 -1
  200. package/dist/global/processor.js +18 -57
  201. package/dist/global/processor.js.map +1 -1
  202. package/dist/global/types.d.ts +2 -0
  203. package/dist/global/types.d.ts.map +1 -1
  204. package/dist/import-writer.d.ts +2 -0
  205. package/dist/import-writer.d.ts.map +1 -1
  206. package/dist/import-writer.js +22 -24
  207. package/dist/import-writer.js.map +1 -1
  208. package/dist/index.d.ts +6 -0
  209. package/dist/index.d.ts.map +1 -1
  210. package/dist/index.js +6 -0
  211. package/dist/index.js.map +1 -1
  212. package/dist/inheritance.d.ts.map +1 -1
  213. package/dist/inheritance.js +18 -17
  214. package/dist/inheritance.js.map +1 -1
  215. package/dist/loader.d.ts +8 -1
  216. package/dist/loader.d.ts.map +1 -1
  217. package/dist/loader.js +22 -9
  218. package/dist/loader.js.map +1 -1
  219. package/dist/lockfile.d.ts +31 -0
  220. package/dist/lockfile.d.ts.map +1 -0
  221. package/dist/lockfile.js +270 -0
  222. package/dist/lockfile.js.map +1 -0
  223. package/dist/mcp/env.d.ts.map +1 -1
  224. package/dist/mcp/env.js +3 -2
  225. package/dist/mcp/env.js.map +1 -1
  226. package/dist/merge.d.ts +9 -5
  227. package/dist/merge.d.ts.map +1 -1
  228. package/dist/merge.js +8 -6
  229. package/dist/merge.js.map +1 -1
  230. package/dist/npm/resolve.d.ts.map +1 -1
  231. package/dist/npm/resolve.js +15 -17
  232. package/dist/npm/resolve.js.map +1 -1
  233. package/dist/prompts/index.d.ts +1 -0
  234. package/dist/prompts/index.d.ts.map +1 -1
  235. package/dist/prompts/index.js +1 -0
  236. package/dist/prompts/index.js.map +1 -1
  237. package/dist/prompts/loader.d.ts.map +1 -1
  238. package/dist/prompts/loader.js +4 -5
  239. package/dist/prompts/loader.js.map +1 -1
  240. package/dist/prompts/to-skills.d.ts +26 -0
  241. package/dist/prompts/to-skills.d.ts.map +1 -0
  242. package/dist/prompts/to-skills.js +87 -0
  243. package/dist/prompts/to-skills.js.map +1 -0
  244. package/dist/reference-resolver.d.ts +86 -0
  245. package/dist/reference-resolver.d.ts.map +1 -0
  246. package/dist/reference-resolver.js +250 -0
  247. package/dist/reference-resolver.js.map +1 -0
  248. package/dist/remote-loader.d.ts.map +1 -1
  249. package/dist/remote-loader.js +35 -19
  250. package/dist/remote-loader.js.map +1 -1
  251. package/dist/rules/loader.d.ts.map +1 -1
  252. package/dist/rules/loader.js +4 -5
  253. package/dist/rules/loader.js.map +1 -1
  254. package/dist/rules/skill-rules.d.ts.map +1 -1
  255. package/dist/rules/skill-rules.js +2 -2
  256. package/dist/rules/skill-rules.js.map +1 -1
  257. package/dist/runtime/browser-dummy.d.ts +3 -0
  258. package/dist/runtime/browser-dummy.d.ts.map +1 -0
  259. package/dist/runtime/browser-dummy.js +46 -0
  260. package/dist/runtime/browser-dummy.js.map +1 -0
  261. package/dist/runtime/index.d.ts +9 -0
  262. package/dist/runtime/index.d.ts.map +1 -0
  263. package/dist/runtime/index.js +23 -0
  264. package/dist/runtime/index.js.map +1 -0
  265. package/dist/runtime/node.d.ts +3 -0
  266. package/dist/runtime/node.d.ts.map +1 -0
  267. package/dist/runtime/node.js +212 -0
  268. package/dist/runtime/node.js.map +1 -0
  269. package/dist/runtime/types.d.ts +130 -0
  270. package/dist/runtime/types.d.ts.map +1 -0
  271. package/dist/runtime/types.js +2 -0
  272. package/dist/runtime/types.js.map +1 -0
  273. package/dist/skills/cache.js +2 -2
  274. package/dist/skills/cache.js.map +1 -1
  275. package/dist/skills/parser.d.ts.map +1 -1
  276. package/dist/skills/parser.js +6 -2
  277. package/dist/skills/parser.js.map +1 -1
  278. package/dist/skills/reference-parser.d.ts.map +1 -1
  279. package/dist/skills/reference-parser.js +6 -6
  280. package/dist/skills/reference-parser.js.map +1 -1
  281. package/dist/skills/resolvers/git.d.ts.map +1 -1
  282. package/dist/skills/resolvers/git.js +4 -5
  283. package/dist/skills/resolvers/git.js.map +1 -1
  284. package/dist/skills/resolvers/local.d.ts.map +1 -1
  285. package/dist/skills/resolvers/local.js +2 -2
  286. package/dist/skills/resolvers/local.js.map +1 -1
  287. package/dist/skills/resolvers/npm.d.ts.map +1 -1
  288. package/dist/skills/resolvers/npm.js +2 -2
  289. package/dist/skills/resolvers/npm.js.map +1 -1
  290. package/dist/skills/validate.d.ts.map +1 -1
  291. package/dist/skills/validate.js +4 -4
  292. package/dist/skills/validate.js.map +1 -1
  293. package/dist/state/index.d.ts +3 -0
  294. package/dist/state/index.d.ts.map +1 -0
  295. package/dist/state/index.js +3 -0
  296. package/dist/state/index.js.map +1 -0
  297. package/dist/state/tracker.d.ts +68 -0
  298. package/dist/state/tracker.d.ts.map +1 -0
  299. package/dist/state/tracker.js +143 -0
  300. package/dist/state/tracker.js.map +1 -0
  301. package/dist/state/types.d.ts +37 -0
  302. package/dist/state/types.d.ts.map +1 -0
  303. package/dist/state/types.js +2 -0
  304. package/dist/state/types.js.map +1 -0
  305. package/dist/updater.d.ts.map +1 -1
  306. package/dist/updater.js +18 -19
  307. package/dist/updater.js.map +1 -1
  308. package/dist/url-parsing.d.ts +12 -1
  309. package/dist/url-parsing.d.ts.map +1 -1
  310. package/dist/url-parsing.js +26 -3
  311. package/dist/url-parsing.js.map +1 -1
  312. package/package.json +5 -1
  313. package/dist/global/tracking.d.ts +0 -109
  314. package/dist/global/tracking.d.ts.map +0 -1
  315. package/dist/global/tracking.js +0 -193
  316. package/dist/global/tracking.js.map +0 -1
@@ -1,6 +1,5 @@
1
- import { readFile, readdir } from 'node:fs/promises';
2
- import { homedir } from 'node:os';
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';
@@ -19,6 +18,123 @@ 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
  */
@@ -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,49 +203,384 @@ 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
- // 1. Import from GLOBAL config first (base layer)
82
- const globalMcp = await importMcpConfig(strategies.mcp, editor, 'global');
83
- if (Object.keys(globalMcp.mcp).length > 0) {
84
- result.sources.global = true;
85
- }
86
- Object.assign(result.mcp, globalMcp.mcp);
87
- result.warnings.push(...globalMcp.warnings);
88
- const globalRules = await importGlobalRules(strategies.rules);
89
- if (globalRules.rules.length > 0) {
90
- result.sources.global = true;
91
- }
92
- result.rules.push(...globalRules.rules);
93
- result.warnings.push(...globalRules.warnings);
94
- const globalPrompts = await importPrompts(strategies.prompts, 'global');
95
- if (Object.keys(globalPrompts.prompts).length > 0) {
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',
@@ -126,71 +589,165 @@ const EDITOR_CONFIG_DIRS = {
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, _editor, _source) {
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 = join(homedir(), configPath);
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 result;
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 = [], configDir = EDITOR_CONFIG_DIRS[editor], mcpConfigPath = strategy.getConfigPath(), baseDir = strategy.isProjectRootConfig?.() ? projectRoot : join(projectRoot, configDir), fullPath = join(baseDir, mcpConfigPath);
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
- catch (err) {
165
- if (err.code !== 'ENOENT' &&
166
- err.code !== 'EISDIR') {
167
- warnings.push(`Failed to read local MCP config at ${fullPath}: ${err.message}`);
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 (!rulesPath) {
178
- return { rules: [], warnings };
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);
179
713
  }
180
- const fullPath = join(homedir(), rulesPath);
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
+ }
736
+ }
737
+ return { rules, paths, scopes, warnings };
738
+ }
739
+ async function readGlobalRuleFile(path, name, warnings) {
181
740
  try {
182
- const content = await readFile(fullPath, 'utf-8'), parsed = strategy.parseGlobalRules(content);
183
- return {
184
- rules: parsed.rules.map((r) => ({ content: r, name: 'global' })),
185
- warnings: parsed.warnings,
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
- if (err.code !== 'ENOENT') {
190
- warnings.push(`Failed to read global rules from ${fullPath}: ${err.message}`);
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).
@@ -200,27 +757,67 @@ async function importLocalRules(strategy, editor, projectRoot) {
200
757
  if (editor === 'codex') {
201
758
  return importCodexLocalRules(projectRoot);
202
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
+ }
203
770
  const warnings = [], configDir = EDITOR_CONFIG_DIRS[editor], rulesDir = strategy.getRulesDir(), fullPath = join(projectRoot, configDir, rulesDir);
204
771
  try {
205
- 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 = {};
206
773
  for (const file of ruleFiles) {
207
774
  try {
775
+ const path = join(fullPath, file);
208
776
  // eslint-disable-next-line no-await-in-loop -- Sequential for simplicity
209
- const content = await readFile(join(fullPath, file), 'utf-8'), name = file.endsWith(ext) ? file.slice(0, -ext.length) : file;
210
- 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';
211
781
  }
212
782
  catch {
213
783
  // Skip files that can't be read
214
784
  }
215
785
  }
216
- return { rules, warnings };
786
+ return { rules, paths, scopes, warnings };
217
787
  }
218
788
  catch (err) {
219
789
  if (err.code !== 'ENOENT') {
220
790
  warnings.push(`Failed to read local rules from ${fullPath}: ${err.message}`);
221
791
  }
222
792
  }
223
- 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 };
224
821
  }
225
822
  /**
226
823
  * Import Codex rules from AGENTS.md at the project root. Codex discovers one AGENTS.md per
@@ -231,7 +828,14 @@ async function importCodexLocalRules(projectRoot) {
231
828
  try {
232
829
  const content = await readFile(agentsPath, 'utf-8');
233
830
  if (content.trim()) {
234
- return { rules: [{ content: content.trim(), name: 'AGENTS' }], warnings };
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
+ };
235
839
  }
236
840
  }
237
841
  catch (err) {
@@ -239,29 +843,88 @@ async function importCodexLocalRules(projectRoot) {
239
843
  warnings.push(`Failed to read Codex rules from ${agentsPath}: ${err.message}`);
240
844
  }
241
845
  }
242
- return { rules: [], warnings };
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 };
243
895
  }
244
896
  /**
245
897
  * Import prompts/workflows from an editor's global config.
246
898
  */
247
- async function importPrompts(strategy, _source) {
899
+ async function importPrompts(strategy, editor, _source) {
248
900
  const warnings = [], promptsPath = strategy.getGlobalPromptsPath();
249
901
  if (!promptsPath) {
250
- return { prompts: {}, warnings };
902
+ return { prompts: {}, paths: {}, scopes: {}, warnings };
251
903
  }
252
904
  const fullPath = join(homedir(), promptsPath);
253
905
  try {
254
906
  const files = await readdir(fullPath), fileReader = async (filename) => {
255
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'),
256
913
  };
257
- return strategy.parseGlobalPrompts(files, fileReader);
914
+ if (editor !== 'opencode') {
915
+ return imported;
916
+ }
917
+ return mergePromptImports(await importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), 'user'), imported);
258
918
  }
259
919
  catch (err) {
260
920
  if (err.code !== 'ENOENT') {
261
921
  warnings.push(`Failed to read global prompts from ${fullPath}: ${err.message}`);
262
922
  }
263
923
  }
264
- return { prompts: {}, warnings };
924
+ if (editor === 'opencode') {
925
+ return importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), 'user');
926
+ }
927
+ return { prompts: {}, paths: {}, scopes: {}, warnings };
265
928
  }
266
929
  /**
267
930
  * Import prompts/workflows from project-local editor config.
@@ -269,20 +932,285 @@ async function importPrompts(strategy, _source) {
269
932
  async function importLocalPrompts(strategy, editor, projectRoot) {
270
933
  const warnings = [], configDir = EDITOR_CONFIG_DIRS[editor], promptsDir = strategy.getPromptsDir(), fullPath = join(projectRoot, configDir, promptsDir);
271
934
  if (!strategy.isSupported()) {
272
- return { prompts: {}, warnings };
935
+ return { prompts: {}, paths: {}, scopes: {}, warnings };
273
936
  }
274
937
  try {
275
938
  const files = await readdir(fullPath), fileReader = async (filename) => {
276
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'),
277
945
  };
278
- return strategy.parseGlobalPrompts(files, fileReader);
946
+ if (editor !== 'opencode') {
947
+ return imported;
948
+ }
949
+ return mergePromptImports(await importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(projectRoot, 'opencode.json')), 'project'), imported);
279
950
  }
280
951
  catch (err) {
281
952
  if (err.code !== 'ENOENT') {
282
953
  warnings.push(`Failed to read local prompts from ${fullPath}: ${err.message}`);
283
954
  }
284
955
  }
285
- return { prompts: {}, warnings };
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
+ }));
286
1214
  }
287
1215
  /**
288
1216
  * Get the global config path for an editor.