agent-space-manager 0.0.0-stage → 1.0.1

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/agents.mjs ADDED
@@ -0,0 +1,653 @@
1
+ // agents.mjs
2
+ // Registry of major AI Coding Agents & IDEs, their native capability formats,
3
+ // and dynamic path resolution across Windows, macOS, and Linux.
4
+
5
+ import path from "node:path";
6
+ import os from "node:os";
7
+
8
+ export function getHomeDir() {
9
+ return process.env.ASM_HOME_OVERRIDE || process.env.USERPROFILE || process.env.HOME || os.homedir();
10
+ }
11
+
12
+ export function getAppDataDir(home = getHomeDir()) {
13
+ if (process.env.APPDATA) return process.env.APPDATA;
14
+ if (process.platform === "darwin") {
15
+ return path.join(home, "Library", "Application Support");
16
+ }
17
+ if (process.platform === "linux") {
18
+ return process.env.XDG_CONFIG_HOME || path.join(home, ".config");
19
+ }
20
+ return path.join(home, "AppData", "Roaming");
21
+ }
22
+
23
+ /**
24
+ * Expands leading `~`, `~/`, `~\`, `$HOME/`, `%USERPROFILE%\`, or `%APPDATA%\`
25
+ * into the real OS path so Node `fs` never creates a literal `~` directory.
26
+ */
27
+ export function expandHomePath(inputPath, home = getHomeDir(), appData = getAppDataDir(home)) {
28
+ if (!inputPath || typeof inputPath !== "string") return inputPath;
29
+ let trimmed = inputPath.trim();
30
+ if (!trimmed) return "";
31
+ // Strip surrounding quotes if user copied path with quotes (e.g. "D:\Path" or 'D:\Path')
32
+ trimmed = trimmed.replace(/^["']+|["']+$/g, "").trim();
33
+ if (!trimmed) return "";
34
+ if (trimmed === "~" || trimmed === "$HOME" || /^%USERPROFILE%$/i.test(trimmed)) {
35
+ return home;
36
+ }
37
+ if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) {
38
+ return path.join(home, trimmed.slice(2));
39
+ }
40
+ if (trimmed.startsWith("$HOME/") || trimmed.startsWith("$HOME\\")) {
41
+ return path.join(home, trimmed.slice(6));
42
+ }
43
+ if (/^%USERPROFILE%[\\/]/i.test(trimmed)) {
44
+ return path.join(home, trimmed.replace(/^%USERPROFILE%[\\/]/i, ""));
45
+ }
46
+ if (/^%APPDATA%[\\/]/i.test(trimmed)) {
47
+ return path.join(appData, trimmed.replace(/^%APPDATA%[\\/]/i, ""));
48
+ }
49
+ // Strip trailing slashes unless root like C:\ or /
50
+ if (trimmed.length > 3 && (trimmed.endsWith("/") || trimmed.endsWith("\\"))) {
51
+ trimmed = trimmed.replace(/[\\\/]+$/, "");
52
+ }
53
+ return trimmed;
54
+ }
55
+
56
+ /**
57
+ * 13 Standardized Agent Profiles.
58
+ * - mode: "bundle" links full plugin directories (<plugin>/plugin.json, skills/, mcp_config.json, etc.)
59
+ * AND links flattened skills/rules/agents so `/` slash commands and `@` mentions are universally discoverable.
60
+ * - mode: "convert" extracts and links individual skills (<skill>/SKILL.md), generates `/` slash commands,
61
+ * merges MCP servers into native config, and injects rules/agents into the agent's native discovery locations.
62
+ */
63
+ export const AGENT_PROFILES = {
64
+ antigravity: {
65
+ id: "antigravity",
66
+ label: "Antigravity (Google)",
67
+ mode: "bundle",
68
+ description: "Native plugin bundles (~/.gemini/config/plugins) + global skills/rules/agents (~/.gemini/config/skills)",
69
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: true },
70
+ match: /\b(antigravity|agy)\b/i,
71
+ exeNames: ["agy", "antigravity"],
72
+ resolvePaths(home = getHomeDir()) {
73
+ const base = path.join(home, ".gemini", "config");
74
+ return {
75
+ primary: path.join(base, "plugins"),
76
+ bundle: path.join(base, "plugins"),
77
+ skills: path.join(base, "skills"),
78
+ rulesDir: { dir: path.join(base, "rules"), suffix: ".md", format: "antigravity-rule" },
79
+ agentsDir: { dir: path.join(base, "agents"), suffix: ".md" },
80
+ mcp: { file: path.join(base, "mcp_config.json"), format: "json", key: "mcpServers" },
81
+ hooks: { file: path.join(base, "hooks.json"), format: "json" },
82
+ skillsJson: path.join(base, "skills.json"),
83
+ pluginsJson: path.join(base, "plugins.json"),
84
+ };
85
+ },
86
+ resolveProjectPaths(repoPath) {
87
+ return {
88
+ skills: path.join(repoPath, ".agents", "skills"),
89
+ rulesDir: path.join(repoPath, ".agents", "rules"),
90
+ agents: path.join(repoPath, ".agents", "agents"),
91
+ mcp: { file: path.join(repoPath, ".agents", "mcp_config.json"), format: "json", key: "mcpServers" },
92
+ hooks: { file: path.join(repoPath, ".agents", "hooks.json"), format: "json" },
93
+ excludeRel: [".agents/skills", ".agents/rules", ".agents/agents", ".agents/mcp_config.json", ".agents/hooks.json"],
94
+ };
95
+ },
96
+ },
97
+
98
+ "claude-code": {
99
+ id: "claude-code",
100
+ label: "Claude Code (Anthropic)",
101
+ mode: "convert",
102
+ description: "Skills in ~/.claude/skills, /commands in ~/.claude/commands, MCP in ~/.claude.json, Rules in ~/.claude/CLAUDE.md, @agents in ~/.claude/agents, Hooks in ~/.claude/hooks.json",
103
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: true },
104
+ match: /\bclaude\b/i,
105
+ exeNames: ["claude"],
106
+ resolvePaths(home = getHomeDir()) {
107
+ const claudeDir = path.join(home, ".claude");
108
+ return {
109
+ primary: path.join(claudeDir, "skills"),
110
+ skills: path.join(claudeDir, "skills"),
111
+ commandsDir: { dir: path.join(claudeDir, "commands"), suffix: ".md", format: "claude-command" },
112
+ agents: path.join(claudeDir, "agents"),
113
+ mcp: { file: path.join(home, ".claude.json"), format: "json", key: "mcpServers" },
114
+ rules: { file: path.join(claudeDir, "CLAUDE.md"), format: "import-block" },
115
+ hooks: { file: path.join(claudeDir, "hooks.json"), format: "json" },
116
+ };
117
+ },
118
+ resolveProjectPaths(repoPath) {
119
+ return {
120
+ skills: path.join(repoPath, ".claude", "skills"),
121
+ commandsDir: { dir: path.join(repoPath, ".claude", "commands"), suffix: ".md", format: "claude-command" },
122
+ agents: path.join(repoPath, ".claude", "agents"),
123
+ mcp: { file: path.join(repoPath, ".mcp.json"), format: "json", key: "mcpServers" },
124
+ rules: { file: path.join(repoPath, "CLAUDE.md"), format: "import-block" },
125
+ hooks: { file: path.join(repoPath, ".claude", "hooks.json"), format: "json" },
126
+ excludeRel: [".claude/skills", ".claude/commands", ".claude/agents", ".mcp.json", "CLAUDE.md", ".claude/hooks.json"],
127
+ };
128
+ },
129
+ },
130
+
131
+ codex: {
132
+ id: "codex",
133
+ label: "Codex CLI (OpenAI)",
134
+ mode: "convert",
135
+ description: "Skills in ~/.codex/skills, /prompts in ~/.codex/prompts, MCP in ~/.codex/config.toml, Rules in ~/.codex/AGENTS.md, @agents in ~/.codex/agents",
136
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: false },
137
+ match: /\bcodex\b/i,
138
+ exeNames: ["codex"],
139
+ resolvePaths(home = getHomeDir()) {
140
+ const codexDir = path.join(home, ".codex");
141
+ return {
142
+ primary: path.join(codexDir, "skills"),
143
+ skills: path.join(codexDir, "skills"),
144
+ commandsDir: { dir: path.join(codexDir, "prompts"), suffix: ".md", format: "markdown-command" },
145
+ agents: { dir: path.join(codexDir, "agents"), suffix: ".md" },
146
+ mcp: { file: path.join(codexDir, "config.toml"), format: "toml-block" },
147
+ rules: { file: path.join(codexDir, "AGENTS.md"), format: "inline-block" },
148
+ };
149
+ },
150
+ resolveProjectPaths(repoPath) {
151
+ return {
152
+ skills: path.join(repoPath, ".codex", "skills"),
153
+ commandsDir: { dir: path.join(repoPath, ".codex", "prompts"), suffix: ".md", format: "markdown-command" },
154
+ agents: { dir: path.join(repoPath, ".codex", "agents"), suffix: ".md" },
155
+ mcp: { file: path.join(repoPath, ".codex", "config.toml"), format: "toml-block" },
156
+ rules: { file: path.join(repoPath, "AGENTS.md"), format: "inline-block" },
157
+ excludeRel: [".codex/skills", ".codex/prompts", ".codex/agents", ".codex/config.toml", "AGENTS.md"],
158
+ };
159
+ },
160
+ },
161
+
162
+ opencode: {
163
+ id: "opencode",
164
+ label: "OpenCode",
165
+ mode: "convert",
166
+ description: "Skills (@) in ~/.config/opencode/skills, Slash commands (/) in commands/, Subagents (@) in agents/, MCP in opencode.json, Rules in AGENTS.md",
167
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: false },
168
+ match: /\bopencode\b/i,
169
+ exeNames: ["opencode", "opencode-cli"],
170
+ resolvePaths(home = getHomeDir()) {
171
+ const ocDir = path.join(home, ".config", "opencode");
172
+ return {
173
+ primary: path.join(ocDir, "skills"),
174
+ skills: path.join(ocDir, "skills"),
175
+ commandsDir: { dir: path.join(ocDir, "commands"), suffix: ".md", format: "opencode-command" },
176
+ agents: { dir: path.join(ocDir, "agents"), suffix: ".md", format: "opencode-agent" },
177
+ mcp: { file: path.join(ocDir, "opencode.json"), format: "opencode-json", key: "mcp" },
178
+ rules: { file: path.join(ocDir, "AGENTS.md"), format: "inline-block" },
179
+ };
180
+ },
181
+ resolveProjectPaths(repoPath) {
182
+ return {
183
+ skills: path.join(repoPath, ".opencode", "skills"),
184
+ commandsDir: { dir: path.join(repoPath, ".opencode", "commands"), suffix: ".md", format: "opencode-command" },
185
+ agents: { dir: path.join(repoPath, ".opencode", "agents"), suffix: ".md", format: "opencode-agent" },
186
+ mcp: { file: path.join(repoPath, "opencode.json"), format: "opencode-json", key: "mcp" },
187
+ rules: { file: path.join(repoPath, "AGENTS.md"), format: "inline-block" },
188
+ excludeRel: [".opencode/skills", ".opencode/commands", ".opencode/agents", "opencode.json", "AGENTS.md"],
189
+ };
190
+ },
191
+ },
192
+
193
+ "vscode-copilot": {
194
+ id: "vscode-copilot",
195
+ label: "VS Code / GitHub Copilot",
196
+ mode: "convert",
197
+ description: "Skills in ~/.copilot/skills, MCP in Code/User/mcp.json, /Prompts, Instructions & @Agents in Code/User/prompts, Hooks in ~/.copilot/hooks",
198
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: true },
199
+ match: /\b(vscode|copilot|visual\s*studio\s*code|code)\b/i,
200
+ exeNames: ["code"],
201
+ resolvePaths(home = getHomeDir(), appData = getAppDataDir(home)) {
202
+ const codeUser = path.join(appData, "Code", "User");
203
+ return {
204
+ primary: path.join(home, ".copilot", "skills"),
205
+ skills: path.join(home, ".copilot", "skills"),
206
+ commandsDir: { dir: path.join(codeUser, "prompts"), suffix: ".prompt.md", format: "copilot-prompt" },
207
+ mcp: { file: path.join(codeUser, "mcp.json"), format: "json", key: "servers" },
208
+ rulesDir: { dir: path.join(codeUser, "prompts"), suffix: ".instructions.md" },
209
+ agentsDir: { dir: path.join(codeUser, "prompts"), suffix: ".agent.md" },
210
+ hooks: { file: path.join(home, ".copilot", "hooks", "hooks.json"), format: "json" },
211
+ };
212
+ },
213
+ resolveProjectPaths(repoPath) {
214
+ return {
215
+ skills: path.join(repoPath, ".github", "skills"),
216
+ commandsDir: { dir: path.join(repoPath, ".github", "prompts"), suffix: ".prompt.md", format: "copilot-prompt" },
217
+ mcp: { file: path.join(repoPath, ".vscode", "mcp.json"), format: "json", key: "servers" },
218
+ rulesDir: { dir: path.join(repoPath, ".github", "instructions"), suffix: ".instructions.md" },
219
+ agentsDir: { dir: path.join(repoPath, ".github", "agents"), suffix: ".agent.md" },
220
+ hooks: { file: path.join(repoPath, ".github", "hooks", "hooks.json"), format: "json" },
221
+ excludeRel: [".github/skills", ".github/prompts", ".vscode/mcp.json", ".github/instructions", ".github/agents", ".github/hooks"],
222
+ };
223
+ },
224
+ },
225
+
226
+ cursor: {
227
+ id: "cursor",
228
+ label: "Cursor AI",
229
+ mode: "convert",
230
+ description: "Skills in ~/.cursor/skills, /commands in ~/.cursor/commands, MCP in ~/.cursor/mcp.json, Rules in ~/.cursor/rules, @agents in ~/.cursor/agents, Hooks in ~/.cursor/hooks.json",
231
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: true },
232
+ match: /\bcursor\b/i,
233
+ exeNames: ["cursor"],
234
+ resolvePaths(home = getHomeDir()) {
235
+ const curDir = path.join(home, ".cursor");
236
+ return {
237
+ primary: path.join(curDir, "skills"),
238
+ skills: path.join(curDir, "skills"),
239
+ commandsDir: { dir: path.join(curDir, "commands"), suffix: ".md", format: "markdown-command" },
240
+ rulesDir: { dir: path.join(curDir, "rules"), suffix: ".mdc" },
241
+ agentsDir: { dir: path.join(curDir, "agents"), suffix: ".md" },
242
+ mcp: { file: path.join(curDir, "mcp.json"), format: "json", key: "mcpServers" },
243
+ hooks: { file: path.join(curDir, "hooks.json"), format: "json" },
244
+ };
245
+ },
246
+ resolveProjectPaths(repoPath) {
247
+ return {
248
+ skills: path.join(repoPath, ".cursor", "skills"),
249
+ commandsDir: { dir: path.join(repoPath, ".cursor", "commands"), suffix: ".md", format: "markdown-command" },
250
+ mcp: { file: path.join(repoPath, ".cursor", "mcp.json"), format: "json", key: "mcpServers" },
251
+ rulesDir: path.join(repoPath, ".cursor", "rules"),
252
+ agentsDir: path.join(repoPath, ".cursor", "agents"),
253
+ hooks: { file: path.join(repoPath, ".cursor", "hooks.json"), format: "json" },
254
+ excludeRel: [".cursor/skills", ".cursor/commands", ".cursor/mcp.json", ".cursor/rules", ".cursor/agents", ".cursor/hooks.json"],
255
+ };
256
+ },
257
+ },
258
+
259
+ windsurf: {
260
+ id: "windsurf",
261
+ label: "Windsurf (Codeium)",
262
+ mode: "convert",
263
+ description: "Skills in ~/.codeium/windsurf/skills, /workflows in global_workflows/, MCP in mcp_config.json, Rules in memories/global_rules.md, Hooks in hooks.json",
264
+ capabilities: { skills: true, mcp: true, rules: true, agents: false, hooks: true },
265
+ match: /\b(windsurf|codeium)\b/i,
266
+ exeNames: ["windsurf"],
267
+ resolvePaths(home = getHomeDir()) {
268
+ const wsDir = path.join(home, ".codeium", "windsurf");
269
+ return {
270
+ primary: path.join(wsDir, "skills"),
271
+ skills: path.join(wsDir, "skills"),
272
+ commandsDir: { dir: path.join(wsDir, "global_workflows"), suffix: ".md", format: "markdown-command" },
273
+ mcp: { file: path.join(wsDir, "mcp_config.json"), format: "json", key: "mcpServers" },
274
+ rules: { file: path.join(wsDir, "memories", "global_rules.md"), format: "inline-block" },
275
+ hooks: { file: path.join(wsDir, "hooks.json"), format: "json" },
276
+ };
277
+ },
278
+ resolveProjectPaths(repoPath) {
279
+ return {
280
+ skills: path.join(repoPath, ".windsurf", "skills"),
281
+ commandsDir: { dir: path.join(repoPath, ".windsurf", "workflows"), suffix: ".md", format: "markdown-command" },
282
+ rulesDir: path.join(repoPath, ".windsurf", "rules"),
283
+ hooks: { file: path.join(repoPath, ".windsurf", "hooks.json"), format: "json" },
284
+ excludeRel: [".windsurf/skills", ".windsurf/workflows", ".windsurf/rules", ".windsurf/hooks.json"],
285
+ };
286
+ },
287
+ },
288
+
289
+ "gemini-cli": {
290
+ id: "gemini-cli",
291
+ label: "Gemini CLI (Standalone)",
292
+ mode: "convert",
293
+ description: "Skills in ~/.gemini/skills, /commands in ~/.gemini/commands, MCP in ~/.gemini/settings.json, Rules in ~/.gemini/GEMINI.md, @agents in ~/.gemini/agents, Hooks in ~/.gemini/hooks",
294
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: true },
295
+ match: /\bgemini[-_\s]*cli\b/i,
296
+ exeNames: ["gemini"],
297
+ resolvePaths(home = getHomeDir()) {
298
+ const gemDir = path.join(home, ".gemini");
299
+ return {
300
+ primary: path.join(gemDir, "skills"),
301
+ skills: path.join(gemDir, "skills"),
302
+ commandsDir: { dir: path.join(gemDir, "commands"), suffix: ".toml", format: "gemini-toml-command" },
303
+ agents: { dir: path.join(gemDir, "agents"), suffix: ".md" },
304
+ mcp: { file: path.join(gemDir, "settings.json"), format: "json", key: "mcpServers" },
305
+ rules: { file: path.join(gemDir, "GEMINI.md"), format: "inline-block" },
306
+ hooks: { file: path.join(gemDir, "hooks", "hooks.json"), format: "json" },
307
+ };
308
+ },
309
+ resolveProjectPaths(repoPath) {
310
+ return {
311
+ skills: path.join(repoPath, ".gemini", "skills"),
312
+ commandsDir: { dir: path.join(repoPath, ".gemini", "commands"), suffix: ".toml", format: "gemini-toml-command" },
313
+ agents: { dir: path.join(repoPath, ".gemini", "agents"), suffix: ".md" },
314
+ rules: { file: path.join(repoPath, "GEMINI.md"), format: "inline-block" },
315
+ mcp: { file: path.join(repoPath, ".gemini", "settings.json"), format: "json", key: "mcpServers" },
316
+ hooks: { file: path.join(repoPath, ".gemini", "hooks", "hooks.json"), format: "json" },
317
+ excludeRel: [".gemini/skills", ".gemini/commands", ".gemini/agents", "GEMINI.md", ".gemini/settings.json", ".gemini/hooks"],
318
+ };
319
+ },
320
+ },
321
+
322
+ cline: {
323
+ id: "cline",
324
+ label: "Cline (VS Code Extension)",
325
+ mode: "convert",
326
+ description: "Skills in ~/.cline/skills, /workflows in ~/Documents/Cline/Workflows, MCP in cline_mcp_settings.json, Rules in ~/Documents/Cline/Rules, Hooks in ~/Documents/Cline/Hooks",
327
+ capabilities: { skills: true, mcp: true, rules: true, agents: false, hooks: true },
328
+ match: /\b(cline|claude-dev)\b/i,
329
+ exeNames: ["cline"],
330
+ resolvePaths(home = getHomeDir(), appData = getAppDataDir(home)) {
331
+ const storage = path.join(appData, "Code", "User", "globalStorage", "saoudrizwan.claude-dev", "settings");
332
+ return {
333
+ primary: path.join(home, ".cline", "skills"),
334
+ skills: path.join(home, ".cline", "skills"),
335
+ commandsDir: { dir: path.join(home, "Documents", "Cline", "Workflows"), suffix: ".md", format: "markdown-command" },
336
+ mcp: { file: path.join(storage, "cline_mcp_settings.json"), format: "json", key: "mcpServers" },
337
+ rulesDir: { dir: path.join(home, "Documents", "Cline", "Rules"), suffix: ".md" },
338
+ hooks: { file: path.join(home, "Documents", "Cline", "Hooks", "hooks.json"), format: "json" },
339
+ };
340
+ },
341
+ resolveProjectPaths(repoPath) {
342
+ return {
343
+ skills: path.join(repoPath, ".cline", "skills"),
344
+ rulesDir: path.join(repoPath, ".clinerules"),
345
+ excludeRel: [".cline/skills", ".clinerules"],
346
+ };
347
+ },
348
+ },
349
+
350
+ "roo-code": {
351
+ id: "roo-code",
352
+ label: "Roo Code",
353
+ mode: "convert",
354
+ description: "Skills in ~/.roo/skills, /commands in ~/.roo/commands, MCP in rooveterinaryinc.roo-cline mcp_settings.json, Rules in ~/.roo/rules, @agents in ~/.roo/agents",
355
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: false },
356
+ match: /\b(roo|roo-code|roo-cline)\b/i,
357
+ exeNames: ["roo"],
358
+ resolvePaths(home = getHomeDir(), appData = getAppDataDir(home)) {
359
+ const storage = path.join(appData, "Code", "User", "globalStorage", "rooveterinaryinc.roo-cline", "settings");
360
+ return {
361
+ primary: path.join(home, ".roo", "skills"),
362
+ skills: path.join(home, ".roo", "skills"),
363
+ commandsDir: { dir: path.join(home, ".roo", "commands"), suffix: ".md", format: "markdown-command" },
364
+ agents: { dir: path.join(home, ".roo", "agents"), suffix: ".md" },
365
+ mcp: { file: path.join(storage, "mcp_settings.json"), format: "json", key: "mcpServers" },
366
+ rulesDir: { dir: path.join(home, ".roo", "rules"), suffix: ".md" },
367
+ };
368
+ },
369
+ resolveProjectPaths(repoPath) {
370
+ return {
371
+ skills: path.join(repoPath, ".roo", "skills"),
372
+ commandsDir: { dir: path.join(repoPath, ".roo", "commands"), suffix: ".md", format: "markdown-command" },
373
+ agents: { dir: path.join(repoPath, ".roo", "agents"), suffix: ".md" },
374
+ rulesDir: path.join(repoPath, ".roo", "rules"),
375
+ mcp: { file: path.join(repoPath, ".roo", "mcp.json"), format: "json", key: "mcpServers" },
376
+ excludeRel: [".roo/skills", ".roo/commands", ".roo/agents", ".roo/rules", ".roo/mcp.json"],
377
+ };
378
+ },
379
+ },
380
+
381
+ kiro: {
382
+ id: "kiro",
383
+ label: "Kiro (AWS)",
384
+ mode: "convert",
385
+ description: "Skills in ~/.kiro/skills, /workflows in ~/.kiro/workflows, MCP in ~/.kiro/settings/mcp.json, Steering rules in ~/.kiro/steering, @agents in ~/.kiro/agents, Hooks in ~/.kiro/hooks",
386
+ capabilities: { skills: true, mcp: true, rules: true, agents: true, hooks: true },
387
+ match: /\bkiro\b/i,
388
+ exeNames: ["kiro"],
389
+ resolvePaths(home = getHomeDir()) {
390
+ const kiroDir = path.join(home, ".kiro");
391
+ return {
392
+ primary: path.join(kiroDir, "skills"),
393
+ skills: path.join(kiroDir, "skills"),
394
+ commandsDir: { dir: path.join(kiroDir, "workflows"), suffix: ".md", format: "markdown-command" },
395
+ agents: { dir: path.join(kiroDir, "agents"), suffix: ".md" },
396
+ mcp: { file: path.join(kiroDir, "settings", "mcp.json"), format: "json", key: "mcpServers" },
397
+ rulesDir: { dir: path.join(kiroDir, "steering"), suffix: ".md" },
398
+ hooks: { file: path.join(kiroDir, "hooks", "hooks.json"), format: "json" },
399
+ };
400
+ },
401
+ resolveProjectPaths(repoPath) {
402
+ return {
403
+ skills: path.join(repoPath, ".kiro", "skills"),
404
+ commandsDir: { dir: path.join(repoPath, ".kiro", "workflows"), suffix: ".md", format: "markdown-command" },
405
+ agents: { dir: path.join(repoPath, ".kiro", "agents"), suffix: ".md" },
406
+ rulesDir: path.join(repoPath, ".kiro", "steering"),
407
+ mcp: { file: path.join(repoPath, ".kiro", "settings", "mcp.json"), format: "json", key: "mcpServers" },
408
+ hooks: { file: path.join(repoPath, ".kiro", "hooks", "hooks.json"), format: "json" },
409
+ excludeRel: [".kiro/skills", ".kiro/workflows", ".kiro/agents", ".kiro/steering", ".kiro/settings", ".kiro/hooks"],
410
+ };
411
+ },
412
+ },
413
+
414
+ "agents-universal": {
415
+ id: "agents-universal",
416
+ label: "Universal Agent Skills (~/.agents/skills)",
417
+ mode: "convert",
418
+ description: "Shared ~/.agents/skills directory read by OpenCode, Copilot, Codex, and Antigravity",
419
+ capabilities: { skills: true, mcp: false, rules: false, agents: false, hooks: false },
420
+ match: /\b(agents-universal|universal|\.agents)\b/i,
421
+ exeNames: [],
422
+ resolvePaths(home = getHomeDir()) {
423
+ const dir = path.join(home, ".agents", "skills");
424
+ return { primary: dir, skills: dir };
425
+ },
426
+ resolveProjectPaths(repoPath) {
427
+ return {
428
+ skills: path.join(repoPath, ".agents", "skills"),
429
+ excludeRel: [".agents/skills"],
430
+ };
431
+ },
432
+ },
433
+
434
+ custom: {
435
+ id: "custom",
436
+ label: "Custom Agent / Directory",
437
+ mode: "convert",
438
+ description: "User-specified target directory (links individual skills or plugin bundles)",
439
+ capabilities: { skills: true, mcp: false, rules: false, agents: false, hooks: false },
440
+ match: /^$/,
441
+ exeNames: [],
442
+ resolvePaths(home = getHomeDir(), _appData, customName = "agent") {
443
+ const clean = (customName || "agent").toLowerCase().replace(/[^a-z0-9_-]/g, "") || "agent";
444
+ const dir = path.join(home, `.${clean}`, "skills");
445
+ return { primary: dir, skills: dir };
446
+ },
447
+ resolveProjectPaths(repoPath) {
448
+ return {
449
+ skills: path.join(repoPath, ".agents", "skills"),
450
+ excludeRel: [".agents/skills"],
451
+ };
452
+ },
453
+ },
454
+ };
455
+
456
+ /**
457
+ * Infers the canonical agent profile ID from an IDE object, name, exePath, or configPath.
458
+ */
459
+ export function inferAgentType(ideOrName = "", exePath = "", configPath = "") {
460
+ if (ideOrName && typeof ideOrName === "object") {
461
+ if (ideOrName.agentType && AGENT_PROFILES[ideOrName.agentType]) {
462
+ return ideOrName.agentType;
463
+ }
464
+ return inferAgentType(ideOrName.name || ideOrName.id || "", ideOrName.exePath || "", ideOrName.configPath || "");
465
+ }
466
+
467
+ const rawName = String(ideOrName || "").trim();
468
+ const lowerName = rawName.toLowerCase();
469
+ if (AGENT_PROFILES[lowerName]) return lowerName;
470
+
471
+ const combined = `${rawName} ${exePath || ""} ${configPath || ""}`.toLowerCase();
472
+
473
+ // Order matters to prevent substring collisions:
474
+ // 1. Check OpenCode before VS Code ("opencode" contains "code")
475
+ if (/\bopencode\b/.test(combined)) return "opencode";
476
+ // 2. Check Roo Code before Cline or VS Code ("rooveterinaryinc.roo-cline" contains "cline" and "code")
477
+ if (/\broo\b|roo-cline|rooveterinaryinc/.test(combined)) return "roo-code";
478
+ // 3. Check Cline before Claude ("saoudrizwan.claude-dev" contains "claude")
479
+ if (/\bcline\b|claude-dev/.test(combined)) return "cline";
480
+ // 4. Check Gemini CLI vs Antigravity (.gemini/config/plugins is Antigravity; "gemini-cli" or "gemini cli" is Gemini CLI)
481
+ if (/gemini[-_\s]*cli/.test(combined) || (/[\\/]\.gemini[\\/]skills$/i.test(combined) && !/antigravity/i.test(combined))) {
482
+ return "gemini-cli";
483
+ }
484
+ if (/antigravity|\bagy\b|\.gemini[\\/]config/i.test(combined)) return "antigravity";
485
+ if (/\bcodex\b/.test(combined)) return "codex";
486
+ if (/\bclaude\b/.test(combined)) return "claude-code";
487
+ if (/\bcursor\b/.test(combined)) return "cursor";
488
+ if (/\bwindsurf\b|\bcodeium\b/.test(combined)) return "windsurf";
489
+ if (/\bkiro\b/.test(combined)) return "kiro";
490
+ if (/agents-universal|[\\/]\.agents[\\/]skills/i.test(combined)) return "agents-universal";
491
+ if (/\bvscode\b|\bcopilot\b|visual\s*studio\s*code|\bcode\b|code\.exe/i.test(combined)) return "vscode-copilot";
492
+
493
+ return "custom";
494
+ }
495
+
496
+ /**
497
+ * Returns serializable profile metadata for the UI picker and `/api/agents`.
498
+ */
499
+ export function listAgentProfilesForUi() {
500
+ const home = getHomeDir();
501
+ const appData = getAppDataDir(home);
502
+ return Object.values(AGENT_PROFILES).map((p) => {
503
+ const resolved = p.resolvePaths(home, appData);
504
+ const dummyRepo = "<repo>";
505
+ const proj = p.resolveProjectPaths ? p.resolveProjectPaths(dummyRepo) : null;
506
+ return {
507
+ id: p.id,
508
+ label: p.label,
509
+ mode: p.mode,
510
+ description: p.description,
511
+ capabilities: p.capabilities,
512
+ defaultConfigPath: resolved.primary,
513
+ paths: {
514
+ primary: resolved.primary,
515
+ bundle: resolved.bundle || (p.mode === "bundle" ? resolved.primary : null),
516
+ skills: resolved.skills || (p.mode === "bundle" ? path.join(path.dirname(resolved.primary), "skills") : resolved.primary),
517
+ commands: resolved.commandsDir?.dir || null,
518
+ mcp: resolved.mcp?.file || (p.mode === "bundle" ? path.join(path.dirname(resolved.primary), "mcp_config.json") : null),
519
+ rules: resolved.rules?.file || resolved.rulesDir?.dir || (p.mode === "bundle" ? path.join(path.dirname(resolved.primary), "rules") : null),
520
+ agents: (typeof resolved.agents === "object" ? resolved.agents?.dir : resolved.agents) || resolved.agentsDir?.dir || (p.mode === "bundle" ? path.join(path.dirname(resolved.primary), "agents") : null),
521
+ hooks: resolved.hooks?.file || (p.mode === "bundle" ? path.join(path.dirname(resolved.primary), "hooks.json") : null),
522
+ },
523
+ projectPaths: proj ? {
524
+ skills: proj.skills || null,
525
+ commands: proj.commandsDir?.dir || null,
526
+ mcp: proj.mcp?.file || null,
527
+ rules: proj.rules?.file || proj.rulesDir?.dir || proj.rulesDir || null,
528
+ agents: (typeof proj.agents === "object" ? proj.agents?.dir : proj.agents) || proj.agentsDir?.dir || null,
529
+ hooks: proj.hooks?.file || null,
530
+ } : null,
531
+ };
532
+ });
533
+ }
534
+
535
+ /**
536
+ * Resolves effective target paths for an IDE, merging agent profile defaults with user componentPaths overrides.
537
+ */
538
+ export function resolveEffectiveAgentPaths(ide, home = getHomeDir(), appData = getAppDataDir(home)) {
539
+ if (!ide) return {};
540
+ const agentType = inferAgentType(ide);
541
+ const profile = AGENT_PROFILES[agentType] || AGENT_PROFILES.custom;
542
+ const base = profile.resolvePaths(home, appData, ide.name || ide.id);
543
+ const cp = ide.componentPaths && typeof ide.componentPaths === "object" ? ide.componentPaths : {};
544
+
545
+ const res = { ...base };
546
+
547
+ if (cp.bundle) {
548
+ res.bundle = expandHomePath(cp.bundle, home, appData);
549
+ res.primary = res.bundle;
550
+ }
551
+ if (cp.skills) {
552
+ res.skills = expandHomePath(cp.skills, home, appData);
553
+ if (profile.mode !== "bundle" && !cp.bundle) {
554
+ res.primary = res.skills;
555
+ }
556
+ }
557
+ if (cp.commands) {
558
+ const dir = expandHomePath(cp.commands, home, appData);
559
+ res.commandsDir = typeof res.commandsDir === "object"
560
+ ? { ...res.commandsDir, dir }
561
+ : { dir, suffix: ".md", format: "markdown-command" };
562
+ }
563
+ if (cp.mcp) {
564
+ const file = expandHomePath(cp.mcp, home, appData);
565
+ res.mcp = typeof res.mcp === "object"
566
+ ? { ...res.mcp, file }
567
+ : { file, format: file.endsWith(".toml") ? "toml-block" : "json", key: "mcpServers" };
568
+ }
569
+ if (cp.rules) {
570
+ const rPath = expandHomePath(cp.rules, home, appData);
571
+ if (rPath.endsWith(".md") || rPath.endsWith(".mdc")) {
572
+ res.rules = typeof res.rules === "object"
573
+ ? { ...res.rules, file: rPath }
574
+ : { file: rPath, format: "inline-block" };
575
+ delete res.rulesDir;
576
+ } else {
577
+ res.rulesDir = typeof res.rulesDir === "object"
578
+ ? { ...res.rulesDir, dir: rPath }
579
+ : { dir: rPath, suffix: ".md" };
580
+ delete res.rules;
581
+ }
582
+ }
583
+ if (cp.agents) {
584
+ const aPath = expandHomePath(cp.agents, home, appData);
585
+ if (typeof res.agents === "object" && res.agents?.dir) {
586
+ res.agents = { ...res.agents, dir: aPath };
587
+ } else if (res.agentsDir) {
588
+ res.agentsDir = { ...res.agentsDir, dir: aPath };
589
+ } else {
590
+ res.agents = aPath;
591
+ }
592
+ }
593
+ if (cp.hooks) {
594
+ const hFile = expandHomePath(cp.hooks, home, appData);
595
+ res.hooks = typeof res.hooks === "object"
596
+ ? { ...res.hooks, file: hFile }
597
+ : { file: hFile, format: "json" };
598
+ }
599
+
600
+ // If primary configPath was explicitly passed on ide.configPath, expand it
601
+ if (ide.configPath && !cp.bundle && !cp.skills) {
602
+ res.primary = expandHomePath(ide.configPath, home, appData);
603
+ if (profile.mode === "bundle") {
604
+ res.bundle = res.primary;
605
+ } else {
606
+ res.skills = res.primary;
607
+ }
608
+ }
609
+
610
+ return res;
611
+ }
612
+
613
+ /**
614
+ * Resolves effective target paths for a Project repository, merging profile defaults with user componentPaths overrides.
615
+ */
616
+ export function resolveEffectiveProjectPaths(project, ide) {
617
+ const repoPath = expandHomePath(project?.repoPath || "");
618
+ const agentType = inferAgentType(ide || project?.ideId || "antigravity");
619
+ const profile = AGENT_PROFILES[agentType] || AGENT_PROFILES.custom;
620
+ const base = profile.resolveProjectPaths
621
+ ? profile.resolveProjectPaths(repoPath)
622
+ : { skills: path.join(repoPath, ".agents", "skills"), excludeRel: [".agents/skills"] };
623
+ const cp = project?.componentPaths && typeof project.componentPaths === "object" ? project.componentPaths : {};
624
+
625
+ const res = { ...base };
626
+ if (cp.skills) res.skills = expandHomePath(cp.skills);
627
+ if (cp.commands) {
628
+ const dir = expandHomePath(cp.commands);
629
+ res.commandsDir = typeof res.commandsDir === "object" ? { ...res.commandsDir, dir } : { dir, suffix: ".md", format: "markdown-command" };
630
+ }
631
+ if (cp.mcp) {
632
+ const file = expandHomePath(cp.mcp);
633
+ res.mcp = typeof res.mcp === "object" ? { ...res.mcp, file } : { file, format: file.endsWith(".toml") ? "toml-block" : "json", key: "mcpServers" };
634
+ }
635
+ if (cp.rules) {
636
+ const rPath = expandHomePath(cp.rules);
637
+ if (rPath.endsWith(".md") || rPath.endsWith(".mdc")) {
638
+ res.rules = typeof res.rules === "object" ? { ...res.rules, file: rPath } : { file: rPath, format: "inline-block" };
639
+ delete res.rulesDir;
640
+ } else {
641
+ res.rulesDir = typeof res.rulesDir === "object" ? { ...res.rulesDir, dir: rPath } : { dir: rPath, suffix: ".md" };
642
+ delete res.rules;
643
+ }
644
+ }
645
+ if (cp.agents) {
646
+ res.agents = expandHomePath(cp.agents);
647
+ }
648
+ if (cp.hooks) {
649
+ const file = expandHomePath(cp.hooks);
650
+ res.hooks = typeof res.hooks === "object" ? { ...res.hooks, file } : { file, format: "json" };
651
+ }
652
+ return res;
653
+ }