@a1st/aix-core 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/index.d.ts +3 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +3 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/loader.d.ts +16 -0
- package/dist/agents/loader.d.ts.map +1 -0
- package/dist/agents/loader.js +88 -0
- package/dist/agents/loader.js.map +1 -0
- package/dist/agents/parser.d.ts +14 -0
- package/dist/agents/parser.d.ts.map +1 -0
- package/dist/agents/parser.js +57 -0
- package/dist/agents/parser.js.map +1 -0
- package/dist/cache/paths.d.ts +4 -0
- package/dist/cache/paths.d.ts.map +1 -1
- package/dist/cache/paths.js +6 -0
- package/dist/cache/paths.js.map +1 -1
- package/dist/editors/adapters/base.d.ts +14 -1
- package/dist/editors/adapters/base.d.ts.map +1 -1
- package/dist/editors/adapters/base.js +72 -2
- package/dist/editors/adapters/base.js.map +1 -1
- package/dist/editors/adapters/claude-code.d.ts +2 -1
- package/dist/editors/adapters/claude-code.d.ts.map +1 -1
- package/dist/editors/adapters/claude-code.js +10 -6
- package/dist/editors/adapters/claude-code.js.map +1 -1
- package/dist/editors/adapters/codex.d.ts +2 -1
- package/dist/editors/adapters/codex.d.ts.map +1 -1
- package/dist/editors/adapters/codex.js +9 -16
- package/dist/editors/adapters/codex.js.map +1 -1
- package/dist/editors/adapters/copilot.d.ts +5 -3
- package/dist/editors/adapters/copilot.d.ts.map +1 -1
- package/dist/editors/adapters/copilot.js +30 -7
- package/dist/editors/adapters/copilot.js.map +1 -1
- package/dist/editors/adapters/cursor.d.ts +2 -1
- package/dist/editors/adapters/cursor.d.ts.map +1 -1
- package/dist/editors/adapters/cursor.js +7 -3
- package/dist/editors/adapters/cursor.js.map +1 -1
- package/dist/editors/adapters/gemini.d.ts +14 -3
- package/dist/editors/adapters/gemini.d.ts.map +1 -1
- package/dist/editors/adapters/gemini.js +56 -11
- package/dist/editors/adapters/gemini.js.map +1 -1
- package/dist/editors/adapters/opencode.d.ts +2 -1
- package/dist/editors/adapters/opencode.d.ts.map +1 -1
- package/dist/editors/adapters/opencode.js +9 -2
- package/dist/editors/adapters/opencode.js.map +1 -1
- package/dist/editors/adapters/windsurf.d.ts +2 -1
- package/dist/editors/adapters/windsurf.d.ts.map +1 -1
- package/dist/editors/adapters/windsurf.js +2 -0
- package/dist/editors/adapters/windsurf.js.map +1 -1
- package/dist/editors/adapters/zed.d.ts +2 -1
- package/dist/editors/adapters/zed.d.ts.map +1 -1
- package/dist/editors/adapters/zed.js +2 -1
- package/dist/editors/adapters/zed.js.map +1 -1
- package/dist/editors/import.d.ts +6 -1
- package/dist/editors/import.d.ts.map +1 -1
- package/dist/editors/import.js +173 -774
- package/dist/editors/import.js.map +1 -1
- package/dist/editors/install.d.ts.map +1 -1
- package/dist/editors/install.js +1 -3
- package/dist/editors/install.js.map +1 -1
- package/dist/editors/prompt-skill-installer.d.ts +17 -0
- package/dist/editors/prompt-skill-installer.d.ts.map +1 -0
- package/dist/editors/prompt-skill-installer.js +23 -0
- package/dist/editors/prompt-skill-installer.js.map +1 -0
- package/dist/editors/strategies/claude-code/hooks.d.ts +5 -1
- package/dist/editors/strategies/claude-code/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/hooks.js +270 -38
- package/dist/editors/strategies/claude-code/hooks.js.map +1 -1
- package/dist/editors/strategies/claude-code/mcp.d.ts +3 -2
- package/dist/editors/strategies/claude-code/mcp.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/mcp.js +6 -5
- package/dist/editors/strategies/claude-code/mcp.js.map +1 -1
- package/dist/editors/strategies/claude-code/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/prompts.js +15 -67
- package/dist/editors/strategies/claude-code/prompts.js.map +1 -1
- package/dist/editors/strategies/claude-code/rules.d.ts +1 -0
- package/dist/editors/strategies/claude-code/rules.d.ts.map +1 -1
- package/dist/editors/strategies/claude-code/rules.js +3 -0
- package/dist/editors/strategies/claude-code/rules.js.map +1 -1
- package/dist/editors/strategies/codex/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/codex/prompts.js +20 -72
- package/dist/editors/strategies/codex/prompts.js.map +1 -1
- package/dist/editors/strategies/codex/rules.d.ts +2 -1
- package/dist/editors/strategies/codex/rules.d.ts.map +1 -1
- package/dist/editors/strategies/codex/rules.js +22 -0
- package/dist/editors/strategies/codex/rules.js.map +1 -1
- package/dist/editors/strategies/copilot/hooks.d.ts +7 -4
- package/dist/editors/strategies/copilot/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/copilot/hooks.js +212 -50
- package/dist/editors/strategies/copilot/hooks.js.map +1 -1
- package/dist/editors/strategies/copilot/mcp.d.ts +1 -0
- package/dist/editors/strategies/copilot/mcp.d.ts.map +1 -1
- package/dist/editors/strategies/copilot/mcp.js +7 -0
- package/dist/editors/strategies/copilot/mcp.js.map +1 -1
- package/dist/editors/strategies/copilot/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/copilot/prompts.js +17 -69
- package/dist/editors/strategies/copilot/prompts.js.map +1 -1
- package/dist/editors/strategies/cursor/hooks.d.ts +7 -2
- package/dist/editors/strategies/cursor/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/cursor/hooks.js +171 -22
- package/dist/editors/strategies/cursor/hooks.js.map +1 -1
- package/dist/editors/strategies/cursor/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/cursor/prompts.js +11 -44
- package/dist/editors/strategies/cursor/prompts.js.map +1 -1
- package/dist/editors/strategies/gemini/hooks.d.ts +18 -0
- package/dist/editors/strategies/gemini/hooks.d.ts.map +1 -0
- package/dist/editors/strategies/gemini/hooks.js +152 -0
- package/dist/editors/strategies/gemini/hooks.js.map +1 -0
- package/dist/editors/strategies/gemini/index.d.ts +1 -0
- package/dist/editors/strategies/gemini/index.d.ts.map +1 -1
- package/dist/editors/strategies/gemini/index.js +1 -0
- package/dist/editors/strategies/gemini/index.js.map +1 -1
- package/dist/editors/strategies/gemini/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/gemini/prompts.js +7 -33
- package/dist/editors/strategies/gemini/prompts.js.map +1 -1
- package/dist/editors/strategies/gemini/rules.d.ts +2 -1
- package/dist/editors/strategies/gemini/rules.d.ts.map +1 -1
- package/dist/editors/strategies/gemini/rules.js +22 -0
- package/dist/editors/strategies/gemini/rules.js.map +1 -1
- package/dist/editors/strategies/opencode/import-utils.d.ts +5 -0
- package/dist/editors/strategies/opencode/import-utils.d.ts.map +1 -0
- package/dist/editors/strategies/opencode/import-utils.js +181 -0
- package/dist/editors/strategies/opencode/import-utils.js.map +1 -0
- package/dist/editors/strategies/opencode/mcp.d.ts +2 -0
- package/dist/editors/strategies/opencode/mcp.d.ts.map +1 -1
- package/dist/editors/strategies/opencode/mcp.js +11 -3
- package/dist/editors/strategies/opencode/mcp.js.map +1 -1
- package/dist/editors/strategies/opencode/prompts.d.ts +3 -1
- package/dist/editors/strategies/opencode/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/opencode/prompts.js +72 -64
- package/dist/editors/strategies/opencode/prompts.js.map +1 -1
- package/dist/editors/strategies/opencode/rules.d.ts +3 -1
- package/dist/editors/strategies/opencode/rules.d.ts.map +1 -1
- package/dist/editors/strategies/opencode/rules.js +68 -0
- package/dist/editors/strategies/opencode/rules.js.map +1 -1
- package/dist/editors/strategies/shared/agents.d.ts +28 -0
- package/dist/editors/strategies/shared/agents.d.ts.map +1 -0
- package/dist/editors/strategies/shared/agents.js +133 -0
- package/dist/editors/strategies/shared/agents.js.map +1 -0
- package/dist/editors/strategies/shared/hook-import-utils.d.ts +21 -0
- package/dist/editors/strategies/shared/hook-import-utils.d.ts.map +1 -0
- package/dist/editors/strategies/shared/hook-import-utils.js +98 -0
- package/dist/editors/strategies/shared/hook-import-utils.js.map +1 -0
- package/dist/editors/strategies/shared/index.d.ts +1 -0
- package/dist/editors/strategies/shared/index.d.ts.map +1 -1
- package/dist/editors/strategies/shared/index.js +1 -0
- package/dist/editors/strategies/shared/index.js.map +1 -1
- package/dist/editors/strategies/shared/native-skills.d.ts +2 -0
- package/dist/editors/strategies/shared/native-skills.d.ts.map +1 -1
- package/dist/editors/strategies/shared/native-skills.js +6 -0
- package/dist/editors/strategies/shared/native-skills.js.map +1 -1
- package/dist/editors/strategies/shared/no-hooks.d.ts +7 -3
- package/dist/editors/strategies/shared/no-hooks.d.ts.map +1 -1
- package/dist/editors/strategies/shared/no-hooks.js +14 -2
- package/dist/editors/strategies/shared/no-hooks.js.map +1 -1
- package/dist/editors/strategies/shared/pointer-skills.d.ts +2 -0
- package/dist/editors/strategies/shared/pointer-skills.d.ts.map +1 -1
- package/dist/editors/strategies/shared/pointer-skills.js +6 -0
- package/dist/editors/strategies/shared/pointer-skills.js.map +1 -1
- package/dist/editors/strategies/shared/prompt-utils.d.ts +30 -0
- package/dist/editors/strategies/shared/prompt-utils.d.ts.map +1 -0
- package/dist/editors/strategies/shared/prompt-utils.js +101 -0
- package/dist/editors/strategies/shared/prompt-utils.js.map +1 -0
- package/dist/editors/strategies/types.d.ts +127 -1
- package/dist/editors/strategies/types.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/hooks.d.ts +5 -1
- package/dist/editors/strategies/windsurf/hooks.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/hooks.js +102 -21
- package/dist/editors/strategies/windsurf/hooks.js.map +1 -1
- package/dist/editors/strategies/windsurf/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/windsurf/prompts.js +14 -62
- package/dist/editors/strategies/windsurf/prompts.js.map +1 -1
- package/dist/editors/strategies/windsurf/rules.js.map +1 -1
- package/dist/editors/strategies/zed/prompts.d.ts +2 -12
- package/dist/editors/strategies/zed/prompts.d.ts.map +1 -1
- package/dist/editors/strategies/zed/prompts.js +2 -19
- package/dist/editors/strategies/zed/prompts.js.map +1 -1
- package/dist/editors/strategies/zed/rules.d.ts +2 -1
- package/dist/editors/strategies/zed/rules.d.ts.map +1 -1
- package/dist/editors/strategies/zed/rules.js +27 -0
- package/dist/editors/strategies/zed/rules.js.map +1 -1
- package/dist/editors/types.d.ts +28 -1
- package/dist/editors/types.d.ts.map +1 -1
- package/dist/entity-hash.js.map +1 -1
- package/dist/format-error.d.ts +16 -3
- package/dist/format-error.d.ts.map +1 -1
- package/dist/format-error.js +101 -22
- package/dist/format-error.js.map +1 -1
- package/dist/fs/safe-rm.d.ts +2 -3
- package/dist/fs/safe-rm.d.ts.map +1 -1
- package/dist/fs/safe-rm.js +7 -1
- package/dist/fs/safe-rm.js.map +1 -1
- package/dist/global/processor.d.ts.map +1 -1
- package/dist/global/processor.js +3 -2
- package/dist/global/processor.js.map +1 -1
- package/dist/import-writer.d.ts +2 -0
- package/dist/import-writer.d.ts.map +1 -1
- package/dist/import-writer.js +35 -4
- package/dist/import-writer.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inheritance.js.map +1 -1
- package/dist/json.js.map +1 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +3 -3
- package/dist/loader.js.map +1 -1
- package/dist/lockfile.d.ts.map +1 -1
- package/dist/lockfile.js +31 -0
- package/dist/lockfile.js.map +1 -1
- package/dist/merge.d.ts +2 -1
- package/dist/merge.d.ts.map +1 -1
- package/dist/merge.js +10 -0
- package/dist/merge.js.map +1 -1
- package/dist/reference-resolver.js.map +1 -1
- package/dist/remote-loader.js.map +1 -1
- package/dist/rules/merger.d.ts.map +1 -1
- package/dist/rules/merger.js +2 -2
- package/dist/rules/merger.js.map +1 -1
- package/dist/rules/utils.js.map +1 -1
- package/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +11 -4
- package/dist/runtime/node.js.map +1 -1
- package/dist/skills/resolve.js.map +1 -1
- package/dist/state/tracker.d.ts.map +1 -1
- package/dist/state/tracker.js +4 -1
- package/dist/state/tracker.js.map +1 -1
- package/dist/state/types.d.ts +2 -1
- package/dist/state/types.d.ts.map +1 -1
- package/package.json +10 -5
package/dist/editors/import.js
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createEmptyConfig,
|
|
3
|
-
import {
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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.
|
|
@@ -203,26 +45,29 @@ export async function importFromEditor(editor, options = {}) {
|
|
|
203
45
|
rules: [],
|
|
204
46
|
skills: {},
|
|
205
47
|
prompts: {},
|
|
48
|
+
agents: {},
|
|
206
49
|
hooks: {},
|
|
207
|
-
paths: { mcp: {}, rules: {}, skills: {}, prompts: {}, hooks: {} },
|
|
208
|
-
scopes: { mcp: {}, rules: {}, skills: {}, prompts: {}, hooks: {} },
|
|
50
|
+
paths: { mcp: {}, rules: {}, skills: {}, prompts: {}, agents: {}, hooks: {} },
|
|
51
|
+
scopes: { mcp: {}, rules: {}, skills: {}, prompts: {}, agents: {}, hooks: {} },
|
|
209
52
|
warnings: [],
|
|
210
53
|
sources: { global: false, local: false },
|
|
211
|
-
}, strategies =
|
|
54
|
+
}, strategies = getAdapter(editor).getStrategyBundle(), projectRoot = options.projectRoot ?? getRuntimeAdapter().process.cwd(), scope = options.scope ?? 'all';
|
|
212
55
|
if (scope === 'all' || scope === 'user') {
|
|
213
56
|
assertGlobalHomeAccess(`importing global ${editor} configuration`);
|
|
214
|
-
mergeImportMcp(result, await importMcpConfig(strategies.
|
|
215
|
-
mergeImportRules(result, await importGlobalRules(strategies.
|
|
216
|
-
mergeImportPrompts(result, await importPrompts(strategies.
|
|
217
|
-
|
|
218
|
-
|
|
57
|
+
mergeImportMcp(result, await importMcpConfig(strategies.mcpStrategy, strategies.configDir, 'global'));
|
|
58
|
+
mergeImportRules(result, await importGlobalRules(strategies.rulesStrategy, strategies.configDir));
|
|
59
|
+
mergeImportPrompts(result, await importPrompts(strategies.promptsStrategy, strategies.configDir, 'global'));
|
|
60
|
+
mergeImportAgents(result, await importAgents(strategies.agentsStrategy, strategies.configDir, 'global'));
|
|
61
|
+
mergeImportSkills(result, await importSkills(strategies.skillsStrategy, 'user', projectRoot));
|
|
62
|
+
mergeImportHooks(result, await importHooks(strategies.hooksStrategy, strategies.configDir, 'global'));
|
|
219
63
|
}
|
|
220
64
|
if (scope === 'all' || scope === 'project') {
|
|
221
|
-
mergeImportMcp(result, await importLocalMcpConfig(strategies.
|
|
222
|
-
mergeImportRules(result, await importLocalRules(strategies.
|
|
223
|
-
mergeImportPrompts(result, await importLocalPrompts(strategies.
|
|
224
|
-
|
|
225
|
-
|
|
65
|
+
mergeImportMcp(result, await importLocalMcpConfig(strategies.mcpStrategy, strategies.configDir, projectRoot));
|
|
66
|
+
mergeImportRules(result, await importLocalRules(strategies.rulesStrategy, strategies.configDir, projectRoot));
|
|
67
|
+
mergeImportPrompts(result, await importLocalPrompts(strategies.promptsStrategy, strategies.configDir, projectRoot));
|
|
68
|
+
mergeImportAgents(result, await importAgents(strategies.agentsStrategy, strategies.configDir, 'project', projectRoot));
|
|
69
|
+
mergeImportSkills(result, await importSkills(strategies.skillsStrategy, 'project', projectRoot));
|
|
70
|
+
mergeImportHooks(result, await importHooks(strategies.hooksStrategy, strategies.configDir, 'project', projectRoot));
|
|
226
71
|
}
|
|
227
72
|
return result;
|
|
228
73
|
}
|
|
@@ -259,6 +104,17 @@ function mergeImportPrompts(result, imported) {
|
|
|
259
104
|
Object.assign(result.scopes.prompts, imported.scopes);
|
|
260
105
|
result.warnings.push(...imported.warnings);
|
|
261
106
|
}
|
|
107
|
+
function mergeImportAgents(result, imported) {
|
|
108
|
+
if (Object.keys(imported.agents).length > 0) {
|
|
109
|
+
for (const scope of Object.values(imported.scopes)) {
|
|
110
|
+
result.sources[scope === 'user' ? 'global' : 'local'] = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
Object.assign(result.agents, imported.agents);
|
|
114
|
+
Object.assign(result.paths.agents, imported.paths);
|
|
115
|
+
Object.assign(result.scopes.agents, imported.scopes);
|
|
116
|
+
result.warnings.push(...imported.warnings);
|
|
117
|
+
}
|
|
262
118
|
function mergeImportSkills(result, imported) {
|
|
263
119
|
if (Object.keys(imported.skills).length > 0) {
|
|
264
120
|
for (const scope of Object.values(imported.scopes)) {
|
|
@@ -339,11 +195,15 @@ function normalizeImportedPrompt(strategy, [sourceName, rawContent], usedNames)
|
|
|
339
195
|
* passed through another editor adapter.
|
|
340
196
|
*/
|
|
341
197
|
export function normalizeEditorImport(editor, result) {
|
|
342
|
-
const strategies =
|
|
198
|
+
const strategies = getAdapter(editor).getStrategyBundle(), usedRuleNames = new Set(), usedPromptNames = new Set(), usedAgentNames = new Set(), usedSkillNames = new Set();
|
|
343
199
|
return {
|
|
344
200
|
mcp: result.mcp,
|
|
345
|
-
rules: result.rules.map((rule) => normalizeImportedRule(strategies.
|
|
346
|
-
prompts: Object.entries(result.prompts)
|
|
201
|
+
rules: result.rules.map((rule) => normalizeImportedRule(strategies.rulesStrategy, rule, usedRuleNames)),
|
|
202
|
+
prompts: Object.entries(result.prompts)
|
|
203
|
+
.map((entry) => normalizeImportedPrompt(strategies.promptsStrategy, entry, usedPromptNames)),
|
|
204
|
+
agents: Object.values(result.agents).map((agent) => Object.assign({}, agent, {
|
|
205
|
+
name: dedupeImportedName(agent.name, usedAgentNames),
|
|
206
|
+
})),
|
|
347
207
|
skills: Object.entries(result.skills).map(([sourceName, ref]) => ({
|
|
348
208
|
name: dedupeImportedName(sourceName, usedSkillNames),
|
|
349
209
|
sourceName,
|
|
@@ -387,181 +247,88 @@ export function buildConfigFromEditorImport(editor, result) {
|
|
|
387
247
|
}
|
|
388
248
|
return [prompt.name, value];
|
|
389
249
|
}));
|
|
250
|
+
config.agents = Object.fromEntries(normalized.agents.map((agent) => {
|
|
251
|
+
const value = {
|
|
252
|
+
content: agent.content,
|
|
253
|
+
};
|
|
254
|
+
if (agent.description) {
|
|
255
|
+
value.description = agent.description;
|
|
256
|
+
}
|
|
257
|
+
if (agent.mode) {
|
|
258
|
+
value.mode = agent.mode;
|
|
259
|
+
}
|
|
260
|
+
if (agent.model) {
|
|
261
|
+
value.model = agent.model;
|
|
262
|
+
}
|
|
263
|
+
if (agent.tools && agent.tools.length > 0) {
|
|
264
|
+
value.tools = agent.tools;
|
|
265
|
+
}
|
|
266
|
+
if (agent.permissions && Object.keys(agent.permissions).length > 0) {
|
|
267
|
+
value.permissions = agent.permissions;
|
|
268
|
+
}
|
|
269
|
+
if (agent.mcp && Object.keys(agent.mcp).length > 0) {
|
|
270
|
+
value.mcp = agent.mcp;
|
|
271
|
+
}
|
|
272
|
+
if (agent.editor && Object.keys(agent.editor).length > 0) {
|
|
273
|
+
value.editor = agent.editor;
|
|
274
|
+
}
|
|
275
|
+
return [agent.name, value];
|
|
276
|
+
}));
|
|
390
277
|
config.skills = Object.fromEntries(normalized.skills.map((skill) => [skill.name, skill.ref]));
|
|
391
278
|
if (Object.keys(normalized.hooks).length > 0) {
|
|
392
279
|
config.hooks = normalized.hooks;
|
|
393
280
|
}
|
|
394
281
|
return config;
|
|
395
282
|
}
|
|
396
|
-
function
|
|
397
|
-
|
|
398
|
-
|
|
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;
|
|
283
|
+
async function importAgents(strategy, configDir, source, projectRoot) {
|
|
284
|
+
if (!strategy.isSupported()) {
|
|
285
|
+
return { agents: {}, paths: {}, scopes: {}, warnings: [] };
|
|
483
286
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
function parseFlatHookEntries(rawHooks, eventMap) {
|
|
487
|
-
const hooks = {}, reverseEventMap = {};
|
|
488
|
-
for (const [event, nativeEvent] of Object.entries(eventMap)) {
|
|
489
|
-
reverseEventMap[nativeEvent] = event;
|
|
287
|
+
if (source === 'global' && strategy.importGlobalAgents) {
|
|
288
|
+
return strategy.importGlobalAgents();
|
|
490
289
|
}
|
|
491
|
-
|
|
492
|
-
|
|
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 }]);
|
|
290
|
+
if (source === 'project' && projectRoot && strategy.importProjectAgents) {
|
|
291
|
+
return strategy.importProjectAgents(projectRoot, configDir);
|
|
500
292
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
.map(([event]) => event);
|
|
507
|
-
if (matchingEvents.length === 0) {
|
|
508
|
-
return null;
|
|
293
|
+
const agentsPath = source === 'global'
|
|
294
|
+
? buildGlobalPath(strategy.getGlobalAgentsPath())
|
|
295
|
+
: buildProjectPath(strategy.getAgentsDir(), projectRoot, configDir);
|
|
296
|
+
if (!agentsPath) {
|
|
297
|
+
return { agents: {}, paths: {}, scopes: {}, warnings: [] };
|
|
509
298
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
299
|
+
try {
|
|
300
|
+
const files = await readdir(agentsPath), markdownFiles = files.filter((file) => file.endsWith(strategy.getFileExtension())), entries = await Promise.all(markdownFiles.map(async (file) => {
|
|
301
|
+
const filePath = join(agentsPath, file), content = await readFile(filePath, 'utf-8'), sourceName = file.slice(0, -strategy.getFileExtension().length), agent = strategy.parseAgent(sourceName, content);
|
|
302
|
+
return { name: agent.name, path: filePath, agent };
|
|
303
|
+
})), scope = source === 'global' ? 'user' : 'project';
|
|
304
|
+
return {
|
|
305
|
+
agents: Object.fromEntries(entries.map((entry) => [entry.name, entry.agent])),
|
|
306
|
+
paths: Object.fromEntries(entries.map((entry) => [entry.name, entry.path])),
|
|
307
|
+
scopes: Object.fromEntries(entries.map((entry) => [entry.name, scope])),
|
|
308
|
+
warnings: [],
|
|
309
|
+
};
|
|
514
310
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
-
}]);
|
|
311
|
+
catch (err) {
|
|
312
|
+
if (err.code === 'ENOENT') {
|
|
313
|
+
return { agents: {}, paths: {}, scopes: {}, warnings: [] };
|
|
540
314
|
}
|
|
315
|
+
return {
|
|
316
|
+
agents: {},
|
|
317
|
+
paths: {},
|
|
318
|
+
scopes: {},
|
|
319
|
+
warnings: [`Failed to read agents at ${agentsPath}: ${err.message}`],
|
|
320
|
+
};
|
|
541
321
|
}
|
|
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
322
|
}
|
|
558
|
-
async function importHooks(
|
|
559
|
-
const configPath =
|
|
323
|
+
async function importHooks(strategy, configDir, source, projectRoot) {
|
|
324
|
+
const configPath = source === 'global'
|
|
325
|
+
? buildGlobalPath(strategy.getGlobalConfigPath())
|
|
326
|
+
: buildProjectPath(strategy.getConfigPath(), projectRoot, configDir);
|
|
560
327
|
if (!configPath) {
|
|
561
328
|
return { hooks: {}, paths: {}, scopes: {}, warnings: [] };
|
|
562
329
|
}
|
|
563
330
|
try {
|
|
564
|
-
const content = await readFile(configPath, 'utf-8'), parsed =
|
|
331
|
+
const content = await readFile(configPath, 'utf-8'), parsed = strategy.parseImportedConfig(content), scope = source === 'global' ? 'user' : 'project', eventNames = Object.keys(parsed.hooks);
|
|
565
332
|
return {
|
|
566
333
|
hooks: parsed.hooks,
|
|
567
334
|
paths: pathMapForNames(eventNames, configPath),
|
|
@@ -581,76 +348,22 @@ async function importHooks(editor, source, projectRoot) {
|
|
|
581
348
|
};
|
|
582
349
|
}
|
|
583
350
|
}
|
|
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
351
|
/**
|
|
618
352
|
* Import MCP configuration from an editor's global config.
|
|
619
353
|
*/
|
|
620
|
-
async function importMcpConfig(strategy,
|
|
621
|
-
|
|
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 };
|
|
354
|
+
async function importMcpConfig(strategy, _configDir, _source) {
|
|
355
|
+
return importMcpFromPaths(strategy, getGlobalMcpImportPaths(strategy), 'user', 'global MCP config');
|
|
643
356
|
}
|
|
644
357
|
/**
|
|
645
358
|
* Import MCP configuration from project-local editor config.
|
|
646
359
|
*/
|
|
647
|
-
async function importLocalMcpConfig(strategy,
|
|
360
|
+
async function importLocalMcpConfig(strategy, configDir, projectRoot) {
|
|
648
361
|
const warnings = [];
|
|
649
362
|
// Skip if MCP is not supported for project-local config (e.g., global-only editors)
|
|
650
363
|
if (!strategy.isSupported() || strategy.isGlobalOnly?.()) {
|
|
651
364
|
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
652
365
|
}
|
|
653
|
-
for (const fullPath of getLocalMcpImportPaths(strategy,
|
|
366
|
+
for (const fullPath of getLocalMcpImportPaths(strategy, projectRoot, configDir)) {
|
|
654
367
|
try {
|
|
655
368
|
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
656
369
|
const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
|
|
@@ -669,22 +382,50 @@ async function importLocalMcpConfig(strategy, editor, projectRoot) {
|
|
|
669
382
|
}
|
|
670
383
|
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
671
384
|
}
|
|
672
|
-
function
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
385
|
+
function getGlobalMcpImportPaths(strategy) {
|
|
386
|
+
const configuredPaths = strategy.getGlobalImportPaths?.();
|
|
387
|
+
if (configuredPaths && configuredPaths.length > 0) {
|
|
388
|
+
return configuredPaths.map((path) => buildGlobalPath(path)).filter((path) => Boolean(path));
|
|
389
|
+
}
|
|
390
|
+
const defaultPath = buildGlobalPath(strategy.getGlobalMcpConfigPath());
|
|
391
|
+
return defaultPath ? [defaultPath] : [];
|
|
392
|
+
}
|
|
393
|
+
function getLocalMcpImportPaths(strategy, projectRoot, configDir) {
|
|
394
|
+
const configuredPaths = strategy.getProjectImportPaths?.(projectRoot, configDir);
|
|
395
|
+
if (configuredPaths && configuredPaths.length > 0) {
|
|
396
|
+
return configuredPaths;
|
|
397
|
+
}
|
|
398
|
+
const defaultPath = buildProjectPath(strategy.getConfigPath(), projectRoot, configDir, strategy.isProjectRootConfig?.());
|
|
399
|
+
return defaultPath ? [defaultPath] : [];
|
|
400
|
+
}
|
|
401
|
+
async function importMcpFromPaths(strategy, paths, scope, label) {
|
|
402
|
+
const warnings = [];
|
|
403
|
+
for (const fullPath of paths) {
|
|
404
|
+
try {
|
|
405
|
+
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
406
|
+
const content = await readFile(fullPath, 'utf-8'), result = strategy.parseGlobalMcpConfig(content);
|
|
407
|
+
return {
|
|
408
|
+
...result,
|
|
409
|
+
paths: pathMapForNames(Object.keys(result.mcp), fullPath),
|
|
410
|
+
scopes: scopeMapForNames(Object.keys(result.mcp), scope),
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
catch (err) {
|
|
414
|
+
if (err.code !== 'ENOENT' &&
|
|
415
|
+
err.code !== 'EISDIR') {
|
|
416
|
+
warnings.push(`Failed to read ${label} at ${fullPath}: ${err.message}`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
678
419
|
}
|
|
679
|
-
return
|
|
680
|
-
primaryPath,
|
|
681
|
-
join(projectRoot, '.github/mcp.json'),
|
|
682
|
-
];
|
|
420
|
+
return { mcp: {}, paths: {}, scopes: {}, warnings };
|
|
683
421
|
}
|
|
684
422
|
/**
|
|
685
423
|
* Import rules from an editor's global config. Tags each rule with the name 'global'.
|
|
686
424
|
*/
|
|
687
|
-
async function importGlobalRules(strategy,
|
|
425
|
+
async function importGlobalRules(strategy, _configDir) {
|
|
426
|
+
if (strategy.importGlobalRules) {
|
|
427
|
+
return strategy.importGlobalRules();
|
|
428
|
+
}
|
|
688
429
|
const warnings = [], rulesPath = strategy.getGlobalRulesPath(), rules = [], paths = {}, scopes = {};
|
|
689
430
|
if (rulesPath) {
|
|
690
431
|
const fullPath = join(homedir(), rulesPath);
|
|
@@ -704,14 +445,7 @@ async function importGlobalRules(strategy, editor) {
|
|
|
704
445
|
}
|
|
705
446
|
}
|
|
706
447
|
}
|
|
707
|
-
|
|
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] ?? [];
|
|
448
|
+
const ruleDirs = strategy.getGlobalRuleImportDirs?.() ?? [];
|
|
715
449
|
for (const ruleDir of ruleDirs) {
|
|
716
450
|
const fullPath = join(homedir(), ruleDir);
|
|
717
451
|
try {
|
|
@@ -752,22 +486,11 @@ async function readGlobalRuleFile(path, name, warnings) {
|
|
|
752
486
|
/**
|
|
753
487
|
* Import rules from project-local editor config. Tags each rule with its filename (sans extension).
|
|
754
488
|
*/
|
|
755
|
-
async function importLocalRules(strategy,
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
return importCodexLocalRules(projectRoot);
|
|
759
|
-
}
|
|
760
|
-
// Gemini uses GEMINI.md at the project root (not inside .gemini/), similar to Codex
|
|
761
|
-
if (editor === 'gemini') {
|
|
762
|
-
return importGeminiLocalRules(projectRoot);
|
|
763
|
-
}
|
|
764
|
-
if (editor === 'opencode') {
|
|
765
|
-
return importOpenCodeLocalRules(projectRoot);
|
|
766
|
-
}
|
|
767
|
-
if (editor === 'zed') {
|
|
768
|
-
return importZedLocalRules(projectRoot);
|
|
489
|
+
async function importLocalRules(strategy, configDir, projectRoot) {
|
|
490
|
+
if (strategy.importProjectRules) {
|
|
491
|
+
return strategy.importProjectRules(projectRoot, configDir);
|
|
769
492
|
}
|
|
770
|
-
const warnings = [],
|
|
493
|
+
const warnings = [], rulesDir = strategy.getRulesDir(), fullPath = join(projectRoot, configDir, rulesDir);
|
|
771
494
|
try {
|
|
772
495
|
const files = await readdir(fullPath), ext = strategy.getFileExtension(), ruleFiles = files.filter((f) => f.endsWith(ext)), rules = [], paths = {}, scopes = {};
|
|
773
496
|
for (const file of ruleFiles) {
|
|
@@ -792,111 +515,13 @@ async function importLocalRules(strategy, editor, projectRoot) {
|
|
|
792
515
|
}
|
|
793
516
|
return { rules: [], paths: {}, scopes: {}, warnings };
|
|
794
517
|
}
|
|
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
518
|
/**
|
|
897
519
|
* Import prompts/workflows from an editor's global config.
|
|
898
520
|
*/
|
|
899
|
-
async function importPrompts(strategy,
|
|
521
|
+
async function importPrompts(strategy, _configDir, _source) {
|
|
522
|
+
if (strategy.importGlobalPrompts) {
|
|
523
|
+
return strategy.importGlobalPrompts();
|
|
524
|
+
}
|
|
900
525
|
const warnings = [], promptsPath = strategy.getGlobalPromptsPath();
|
|
901
526
|
if (!promptsPath) {
|
|
902
527
|
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
@@ -911,26 +536,23 @@ async function importPrompts(strategy, editor, _source) {
|
|
|
911
536
|
paths: promptPathMap(Object.keys(result.prompts), files, fullPath),
|
|
912
537
|
scopes: scopeMapForNames(Object.keys(result.prompts), 'user'),
|
|
913
538
|
};
|
|
914
|
-
|
|
915
|
-
return imported;
|
|
916
|
-
}
|
|
917
|
-
return mergePromptImports(await importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), 'user'), imported);
|
|
539
|
+
return imported;
|
|
918
540
|
}
|
|
919
541
|
catch (err) {
|
|
920
542
|
if (err.code !== 'ENOENT') {
|
|
921
543
|
warnings.push(`Failed to read global prompts from ${fullPath}: ${err.message}`);
|
|
922
544
|
}
|
|
923
545
|
}
|
|
924
|
-
if (editor === 'opencode') {
|
|
925
|
-
return importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(homedir(), '.config/opencode/opencode.json')), 'user');
|
|
926
|
-
}
|
|
927
546
|
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
928
547
|
}
|
|
929
548
|
/**
|
|
930
549
|
* Import prompts/workflows from project-local editor config.
|
|
931
550
|
*/
|
|
932
|
-
async function importLocalPrompts(strategy,
|
|
933
|
-
|
|
551
|
+
async function importLocalPrompts(strategy, configDir, projectRoot) {
|
|
552
|
+
if (strategy.importProjectPrompts) {
|
|
553
|
+
return strategy.importProjectPrompts(projectRoot, configDir);
|
|
554
|
+
}
|
|
555
|
+
const warnings = [], promptsDir = strategy.getPromptsDir(), fullPath = join(projectRoot, configDir, promptsDir);
|
|
934
556
|
if (!strategy.isSupported()) {
|
|
935
557
|
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
936
558
|
}
|
|
@@ -943,210 +565,19 @@ async function importLocalPrompts(strategy, editor, projectRoot) {
|
|
|
943
565
|
paths: promptPathMap(Object.keys(result.prompts), files, fullPath),
|
|
944
566
|
scopes: scopeMapForNames(Object.keys(result.prompts), 'project'),
|
|
945
567
|
};
|
|
946
|
-
|
|
947
|
-
return imported;
|
|
948
|
-
}
|
|
949
|
-
return mergePromptImports(await importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(projectRoot, 'opencode.json')), 'project'), imported);
|
|
568
|
+
return imported;
|
|
950
569
|
}
|
|
951
570
|
catch (err) {
|
|
952
571
|
if (err.code !== 'ENOENT') {
|
|
953
572
|
warnings.push(`Failed to read local prompts from ${fullPath}: ${err.message}`);
|
|
954
573
|
}
|
|
955
574
|
}
|
|
956
|
-
if (editor === 'opencode') {
|
|
957
|
-
return importOpenCodeConfigPrompts(resolveOpenCodeConfigPath(join(projectRoot, 'opencode.json')), 'project');
|
|
958
|
-
}
|
|
959
575
|
return { prompts: {}, paths: {}, scopes: {}, warnings };
|
|
960
576
|
}
|
|
961
|
-
async function
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
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);
|
|
577
|
+
async function importSkills(strategy, source, projectRoot) {
|
|
578
|
+
const warnings = [], skills = {}, paths = {}, scopes = {}, skillDirs = source === 'user' ? strategy.getGlobalImportDirs() : strategy.getProjectImportDirs(), root = source === 'user' ? homedir() : projectRoot;
|
|
579
|
+
for (const skillDir of skillDirs) {
|
|
580
|
+
const fullPath = join(root, skillDir);
|
|
1150
581
|
try {
|
|
1151
582
|
// eslint-disable-next-line no-await-in-loop -- Sequential keeps warning order deterministic
|
|
1152
583
|
const entries = await readdir(fullPath, { withFileTypes: true });
|
|
@@ -1160,7 +591,7 @@ async function importLocalSkills(editor, projectRoot) {
|
|
|
1160
591
|
}
|
|
1161
592
|
skills[entry.name] = path;
|
|
1162
593
|
paths[entry.name] = path;
|
|
1163
|
-
scopes[entry.name] =
|
|
594
|
+
scopes[entry.name] = source;
|
|
1164
595
|
}
|
|
1165
596
|
}
|
|
1166
597
|
catch (err) {
|
|
@@ -1171,34 +602,6 @@ async function importLocalSkills(editor, projectRoot) {
|
|
|
1171
602
|
}
|
|
1172
603
|
return { skills, paths, scopes, warnings };
|
|
1173
604
|
}
|
|
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
605
|
function pathMapForNames(names, path) {
|
|
1203
606
|
return Object.fromEntries(names.map((name) => [name, path]));
|
|
1204
607
|
}
|
|
@@ -1216,10 +619,6 @@ function promptPathMap(names, files, basePath) {
|
|
|
1216
619
|
* Get the global config path for an editor.
|
|
1217
620
|
*/
|
|
1218
621
|
export function getGlobalConfigPath(editor) {
|
|
1219
|
-
|
|
1220
|
-
if (!configPath) {
|
|
1221
|
-
return null;
|
|
1222
|
-
}
|
|
1223
|
-
return join(homedir(), configPath);
|
|
622
|
+
return buildGlobalPath(getAdapter(editor).getStrategyBundle().mcpStrategy.getGlobalMcpConfigPath());
|
|
1224
623
|
}
|
|
1225
624
|
//# sourceMappingURL=import.js.map
|