actoviq-agent-sdk 0.4.7 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README-zh.md +8 -5
  3. package/README.md +9 -6
  4. package/assets/actoviq-icon.png +0 -0
  5. package/dist/src/browser/actoviqBrowserSession.d.ts +137 -0
  6. package/dist/src/browser/actoviqBrowserSession.d.ts.map +1 -0
  7. package/dist/src/browser/actoviqBrowserSession.js +623 -0
  8. package/dist/src/browser/actoviqBrowserSession.js.map +1 -0
  9. package/dist/src/browser/actoviqBrowserTools.d.ts +80 -0
  10. package/dist/src/browser/actoviqBrowserTools.d.ts.map +1 -0
  11. package/dist/src/browser/actoviqBrowserTools.js +177 -0
  12. package/dist/src/browser/actoviqBrowserTools.js.map +1 -0
  13. package/dist/src/browser/browserSettings.d.ts +8 -0
  14. package/dist/src/browser/browserSettings.d.ts.map +1 -0
  15. package/dist/src/browser/browserSettings.js +47 -0
  16. package/dist/src/browser/browserSettings.js.map +1 -0
  17. package/dist/src/cli/actoviq-react.js +144 -4
  18. package/dist/src/cli/actoviq-react.js.map +1 -1
  19. package/dist/src/computer/actoviqComputerUse.d.ts.map +1 -1
  20. package/dist/src/computer/actoviqComputerUse.js +226 -40
  21. package/dist/src/computer/actoviqComputerUse.js.map +1 -1
  22. package/dist/src/computer/e2bComputerUse.d.ts +57 -0
  23. package/dist/src/computer/e2bComputerUse.d.ts.map +1 -0
  24. package/dist/src/computer/e2bComputerUse.js +401 -0
  25. package/dist/src/computer/e2bComputerUse.js.map +1 -0
  26. package/dist/src/config/agentProfiles.d.ts +8 -1
  27. package/dist/src/config/agentProfiles.d.ts.map +1 -1
  28. package/dist/src/config/agentProfiles.js +86 -4
  29. package/dist/src/config/agentProfiles.js.map +1 -1
  30. package/dist/src/config/projectSessionDirectory.d.ts +22 -0
  31. package/dist/src/config/projectSessionDirectory.d.ts.map +1 -1
  32. package/dist/src/config/projectSessionDirectory.js +512 -46
  33. package/dist/src/config/projectSessionDirectory.js.map +1 -1
  34. package/dist/src/config/resolveRuntimeConfig.d.ts.map +1 -1
  35. package/dist/src/config/resolveRuntimeConfig.js +12 -7
  36. package/dist/src/config/resolveRuntimeConfig.js.map +1 -1
  37. package/dist/src/gui/actoviqGui.d.ts +3 -0
  38. package/dist/src/gui/actoviqGui.d.ts.map +1 -1
  39. package/dist/src/gui/actoviqGui.js +7247 -997
  40. package/dist/src/gui/actoviqGui.js.map +1 -1
  41. package/dist/src/gui/electronMain.js +21 -4
  42. package/dist/src/gui/electronMain.js.map +1 -1
  43. package/dist/src/gui/externalCliAgentMonitor.d.ts +15 -0
  44. package/dist/src/gui/externalCliAgentMonitor.d.ts.map +1 -0
  45. package/dist/src/gui/externalCliAgentMonitor.js +133 -0
  46. package/dist/src/gui/externalCliAgentMonitor.js.map +1 -0
  47. package/dist/src/gui/projectWorkbench.d.ts +2 -0
  48. package/dist/src/gui/projectWorkbench.d.ts.map +1 -1
  49. package/dist/src/gui/projectWorkbench.js +66 -1
  50. package/dist/src/gui/projectWorkbench.js.map +1 -1
  51. package/dist/src/gui/transcript/clientBundle.d.ts.map +1 -1
  52. package/dist/src/gui/transcript/clientBundle.js +157 -17
  53. package/dist/src/gui/transcript/clientBundle.js.map +1 -1
  54. package/dist/src/gui/transcript/parts.d.ts.map +1 -1
  55. package/dist/src/gui/transcript/parts.js +28 -0
  56. package/dist/src/gui/transcript/parts.js.map +1 -1
  57. package/dist/src/index.d.ts +36 -3
  58. package/dist/src/index.d.ts.map +1 -1
  59. package/dist/src/index.js +22 -2
  60. package/dist/src/index.js.map +1 -1
  61. package/dist/src/parity/actoviqBridgeSdk.d.ts +13 -1
  62. package/dist/src/parity/actoviqBridgeSdk.d.ts.map +1 -1
  63. package/dist/src/parity/actoviqBridgeSdk.js +1022 -83
  64. package/dist/src/parity/actoviqBridgeSdk.js.map +1 -1
  65. package/dist/src/parity/bridgeConfigs.d.ts +15 -0
  66. package/dist/src/parity/bridgeConfigs.d.ts.map +1 -1
  67. package/dist/src/parity/bridgeConfigs.js +112 -3
  68. package/dist/src/parity/bridgeConfigs.js.map +1 -1
  69. package/dist/src/parity/bridgeEventAdapter.d.ts +5 -1
  70. package/dist/src/parity/bridgeEventAdapter.d.ts.map +1 -1
  71. package/dist/src/parity/bridgeEventAdapter.js +65 -12
  72. package/dist/src/parity/bridgeEventAdapter.js.map +1 -1
  73. package/dist/src/parity/bridgeExecResolver.d.ts +10 -11
  74. package/dist/src/parity/bridgeExecResolver.d.ts.map +1 -1
  75. package/dist/src/parity/bridgeExecResolver.js +40 -23
  76. package/dist/src/parity/bridgeExecResolver.js.map +1 -1
  77. package/dist/src/parity/bridgeProcessTree.d.ts +3 -0
  78. package/dist/src/parity/bridgeProcessTree.d.ts.map +1 -0
  79. package/dist/src/parity/bridgeProcessTree.js +83 -0
  80. package/dist/src/parity/bridgeProcessTree.js.map +1 -0
  81. package/dist/src/parity/bridgeProviders.d.ts +16 -2
  82. package/dist/src/parity/bridgeProviders.d.ts.map +1 -1
  83. package/dist/src/parity/bridgeProviders.js +482 -100
  84. package/dist/src/parity/bridgeProviders.js.map +1 -1
  85. package/dist/src/parity/codewhaleRuntimeAdapter.d.ts +18 -0
  86. package/dist/src/parity/codewhaleRuntimeAdapter.d.ts.map +1 -0
  87. package/dist/src/parity/codewhaleRuntimeAdapter.js +350 -0
  88. package/dist/src/parity/codewhaleRuntimeAdapter.js.map +1 -0
  89. package/dist/src/parity/crushManagedClient.d.ts +84 -0
  90. package/dist/src/parity/crushManagedClient.d.ts.map +1 -0
  91. package/dist/src/parity/crushManagedClient.js +978 -0
  92. package/dist/src/parity/crushManagedClient.js.map +1 -0
  93. package/dist/src/parity/crushSessionHistory.d.ts +53 -0
  94. package/dist/src/parity/crushSessionHistory.d.ts.map +1 -0
  95. package/dist/src/parity/crushSessionHistory.js +358 -0
  96. package/dist/src/parity/crushSessionHistory.js.map +1 -0
  97. package/dist/src/parity/externalCliAuth.d.ts +23 -0
  98. package/dist/src/parity/externalCliAuth.d.ts.map +1 -0
  99. package/dist/src/parity/externalCliAuth.js +268 -0
  100. package/dist/src/parity/externalCliAuth.js.map +1 -0
  101. package/dist/src/parity/externalCliRuntimeManager.d.ts +138 -0
  102. package/dist/src/parity/externalCliRuntimeManager.d.ts.map +1 -0
  103. package/dist/src/parity/externalCliRuntimeManager.js +527 -0
  104. package/dist/src/parity/externalCliRuntimeManager.js.map +1 -0
  105. package/dist/src/parity/externalCliSessions.d.ts +90 -0
  106. package/dist/src/parity/externalCliSessions.d.ts.map +1 -0
  107. package/dist/src/parity/externalCliSessions.js +1436 -0
  108. package/dist/src/parity/externalCliSessions.js.map +1 -0
  109. package/dist/src/parity/reasonixAcpSession.d.ts +35 -0
  110. package/dist/src/parity/reasonixAcpSession.d.ts.map +1 -0
  111. package/dist/src/parity/reasonixAcpSession.js +472 -0
  112. package/dist/src/parity/reasonixAcpSession.js.map +1 -0
  113. package/dist/src/parity/reasonixManagedClient.d.ts +56 -0
  114. package/dist/src/parity/reasonixManagedClient.d.ts.map +1 -0
  115. package/dist/src/parity/reasonixManagedClient.js +293 -0
  116. package/dist/src/parity/reasonixManagedClient.js.map +1 -0
  117. package/dist/src/parity/reasonixSessionParser.d.ts +50 -0
  118. package/dist/src/parity/reasonixSessionParser.d.ts.map +1 -0
  119. package/dist/src/parity/reasonixSessionParser.js +440 -0
  120. package/dist/src/parity/reasonixSessionParser.js.map +1 -0
  121. package/dist/src/plugins/githubPlugin.d.ts +64 -0
  122. package/dist/src/plugins/githubPlugin.d.ts.map +1 -0
  123. package/dist/src/plugins/githubPlugin.js +261 -0
  124. package/dist/src/plugins/githubPlugin.js.map +1 -0
  125. package/dist/src/plugins/kimiWebBridgePlugin.d.ts +32 -0
  126. package/dist/src/plugins/kimiWebBridgePlugin.d.ts.map +1 -0
  127. package/dist/src/plugins/kimiWebBridgePlugin.js +214 -0
  128. package/dist/src/plugins/kimiWebBridgePlugin.js.map +1 -0
  129. package/dist/src/plugins/managedPluginCatalog.d.ts +47 -0
  130. package/dist/src/plugins/managedPluginCatalog.d.ts.map +1 -0
  131. package/dist/src/plugins/managedPluginCatalog.js +399 -0
  132. package/dist/src/plugins/managedPluginCatalog.js.map +1 -0
  133. package/dist/src/plugins/managedPluginHealth.d.ts +9 -0
  134. package/dist/src/plugins/managedPluginHealth.d.ts.map +1 -0
  135. package/dist/src/plugins/managedPluginHealth.js +149 -0
  136. package/dist/src/plugins/managedPluginHealth.js.map +1 -0
  137. package/dist/src/plugins/managedPluginRuntime.d.ts +14 -0
  138. package/dist/src/plugins/managedPluginRuntime.d.ts.map +1 -0
  139. package/dist/src/plugins/managedPluginRuntime.js +331 -0
  140. package/dist/src/plugins/managedPluginRuntime.js.map +1 -0
  141. package/dist/src/plugins/ocrPlugin.d.ts +46 -0
  142. package/dist/src/plugins/ocrPlugin.d.ts.map +1 -0
  143. package/dist/src/plugins/ocrPlugin.js +464 -0
  144. package/dist/src/plugins/ocrPlugin.js.map +1 -0
  145. package/dist/src/provider/client.d.ts +7 -1
  146. package/dist/src/provider/client.d.ts.map +1 -1
  147. package/dist/src/provider/client.js +61 -6
  148. package/dist/src/provider/client.js.map +1 -1
  149. package/dist/src/provider/openai-client.d.ts.map +1 -1
  150. package/dist/src/provider/openai-client.js +49 -3
  151. package/dist/src/provider/openai-client.js.map +1 -1
  152. package/dist/src/runtime/actoviqAgentExecutions.d.ts +85 -0
  153. package/dist/src/runtime/actoviqAgentExecutions.d.ts.map +1 -0
  154. package/dist/src/runtime/actoviqAgentExecutions.js +479 -0
  155. package/dist/src/runtime/actoviqAgentExecutions.js.map +1 -0
  156. package/dist/src/runtime/actoviqAgents.d.ts +15 -12
  157. package/dist/src/runtime/actoviqAgents.d.ts.map +1 -1
  158. package/dist/src/runtime/actoviqAgents.js +15 -0
  159. package/dist/src/runtime/actoviqAgents.js.map +1 -1
  160. package/dist/src/runtime/actoviqBackgroundTasks.d.ts +17 -2
  161. package/dist/src/runtime/actoviqBackgroundTasks.d.ts.map +1 -1
  162. package/dist/src/runtime/actoviqBackgroundTasks.js +291 -104
  163. package/dist/src/runtime/actoviqBackgroundTasks.js.map +1 -1
  164. package/dist/src/runtime/actoviqCompact.d.ts.map +1 -1
  165. package/dist/src/runtime/actoviqCompact.js +10 -75
  166. package/dist/src/runtime/actoviqCompact.js.map +1 -1
  167. package/dist/src/runtime/actoviqSkills.d.ts +14 -1
  168. package/dist/src/runtime/actoviqSkills.d.ts.map +1 -1
  169. package/dist/src/runtime/actoviqSkills.js +27 -2
  170. package/dist/src/runtime/actoviqSkills.js.map +1 -1
  171. package/dist/src/runtime/agentClient.d.ts +16 -2
  172. package/dist/src/runtime/agentClient.d.ts.map +1 -1
  173. package/dist/src/runtime/agentClient.js +745 -207
  174. package/dist/src/runtime/agentClient.js.map +1 -1
  175. package/dist/src/runtime/agentExecution.d.ts +196 -0
  176. package/dist/src/runtime/agentExecution.d.ts.map +1 -0
  177. package/dist/src/runtime/agentExecution.js +360 -0
  178. package/dist/src/runtime/agentExecution.js.map +1 -0
  179. package/dist/src/runtime/agentRuntimeDiscovery.d.ts +8 -2
  180. package/dist/src/runtime/agentRuntimeDiscovery.d.ts.map +1 -1
  181. package/dist/src/runtime/agentRuntimeDiscovery.js +30 -18
  182. package/dist/src/runtime/agentRuntimeDiscovery.js.map +1 -1
  183. package/dist/src/runtime/conversationEngine.d.ts +2 -1
  184. package/dist/src/runtime/conversationEngine.d.ts.map +1 -1
  185. package/dist/src/runtime/conversationEngine.js +66 -50
  186. package/dist/src/runtime/conversationEngine.js.map +1 -1
  187. package/dist/src/runtime/externalSkillCatalog.d.ts +107 -0
  188. package/dist/src/runtime/externalSkillCatalog.d.ts.map +1 -0
  189. package/dist/src/runtime/externalSkillCatalog.js +895 -0
  190. package/dist/src/runtime/externalSkillCatalog.js.map +1 -0
  191. package/dist/src/runtime/externalSkillPreferences.d.ts +25 -0
  192. package/dist/src/runtime/externalSkillPreferences.d.ts.map +1 -0
  193. package/dist/src/runtime/externalSkillPreferences.js +132 -0
  194. package/dist/src/runtime/externalSkillPreferences.js.map +1 -0
  195. package/dist/src/runtime/externalSkillRuntime.d.ts +31 -0
  196. package/dist/src/runtime/externalSkillRuntime.d.ts.map +1 -0
  197. package/dist/src/runtime/externalSkillRuntime.js +129 -0
  198. package/dist/src/runtime/externalSkillRuntime.js.map +1 -0
  199. package/dist/src/runtime/sessionTurnCoordinator.d.ts +2 -2
  200. package/dist/src/runtime/sessionTurnCoordinator.js +2 -2
  201. package/dist/src/storage/agentExecutionStore.d.ts +31 -0
  202. package/dist/src/storage/agentExecutionStore.d.ts.map +1 -0
  203. package/dist/src/storage/agentExecutionStore.js +413 -0
  204. package/dist/src/storage/agentExecutionStore.js.map +1 -0
  205. package/dist/src/storage/backgroundTaskStore.d.ts +5 -0
  206. package/dist/src/storage/backgroundTaskStore.d.ts.map +1 -1
  207. package/dist/src/storage/backgroundTaskStore.js +79 -3
  208. package/dist/src/storage/backgroundTaskStore.js.map +1 -1
  209. package/dist/src/storage/sessionStore.d.ts +8 -0
  210. package/dist/src/storage/sessionStore.d.ts.map +1 -1
  211. package/dist/src/storage/sessionStore.js +134 -18
  212. package/dist/src/storage/sessionStore.js.map +1 -1
  213. package/dist/src/team/teamGraphLayout.d.ts +53 -1
  214. package/dist/src/team/teamGraphLayout.d.ts.map +1 -1
  215. package/dist/src/team/teamGraphLayout.js +127 -1
  216. package/dist/src/team/teamGraphLayout.js.map +1 -1
  217. package/dist/src/team/teamGraphScaffold.d.ts.map +1 -1
  218. package/dist/src/team/teamGraphScaffold.js +31 -0
  219. package/dist/src/team/teamGraphScaffold.js.map +1 -1
  220. package/dist/src/team/teamGraphV3.d.ts +1 -0
  221. package/dist/src/team/teamGraphV3.d.ts.map +1 -1
  222. package/dist/src/team/teamGraphV3.js +24 -5
  223. package/dist/src/team/teamGraphV3.js.map +1 -1
  224. package/dist/src/team/teamPropose.d.ts +19 -0
  225. package/dist/src/team/teamPropose.d.ts.map +1 -0
  226. package/dist/src/team/teamPropose.js +126 -0
  227. package/dist/src/team/teamPropose.js.map +1 -0
  228. package/dist/src/tools/actoviqCoreTools.d.ts.map +1 -1
  229. package/dist/src/tools/actoviqCoreTools.js +3 -1
  230. package/dist/src/tools/actoviqCoreTools.js.map +1 -1
  231. package/dist/src/tools/exaSearch.d.ts +56 -0
  232. package/dist/src/tools/exaSearch.d.ts.map +1 -0
  233. package/dist/src/tools/exaSearch.js +170 -0
  234. package/dist/src/tools/exaSearch.js.map +1 -0
  235. package/dist/src/tools/tavilySearch.d.ts +34 -1
  236. package/dist/src/tools/tavilySearch.d.ts.map +1 -1
  237. package/dist/src/tools/tavilySearch.js +69 -54
  238. package/dist/src/tools/tavilySearch.js.map +1 -1
  239. package/dist/src/tools/todo/TodoWriteTool.d.ts +1 -1
  240. package/dist/src/tui/actoviqTui.d.ts +3 -1
  241. package/dist/src/tui/actoviqTui.d.ts.map +1 -1
  242. package/dist/src/tui/actoviqTui.js +1208 -92
  243. package/dist/src/tui/actoviqTui.js.map +1 -1
  244. package/dist/src/types.d.ts +223 -14
  245. package/dist/src/types.d.ts.map +1 -1
  246. package/dist/src/types.js.map +1 -1
  247. package/dist/src/ui/agentExecutionView.d.ts +111 -0
  248. package/dist/src/ui/agentExecutionView.d.ts.map +1 -0
  249. package/dist/src/ui/agentExecutionView.js +442 -0
  250. package/dist/src/ui/agentExecutionView.js.map +1 -0
  251. package/dist/src/ui/commandSurface.d.ts +2 -0
  252. package/dist/src/ui/commandSurface.d.ts.map +1 -1
  253. package/dist/src/ui/commandSurface.js +38 -3
  254. package/dist/src/ui/commandSurface.js.map +1 -1
  255. package/dist/src/workflow-v2/localIsolatedProcessExecutor.d.ts.map +1 -1
  256. package/dist/src/workflow-v2/localIsolatedProcessExecutor.js +6 -2
  257. package/dist/src/workflow-v2/localIsolatedProcessExecutor.js.map +1 -1
  258. package/package.json +35 -7
@@ -0,0 +1,895 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFile, readdir, realpath, stat } from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { resolveActoviqHome } from '../config/actoviqHome.js';
6
+ import { getDefaultActoviqBundledSkills } from './actoviqSkills.js';
7
+ const DEFAULT_MAX_SKILL_BYTES = 1024 * 1024;
8
+ const DEFAULT_SCAN_CONCURRENCY = 8;
9
+ const EMPTY_EXCLUSIONS = new Set();
10
+ const CODEX_EXCLUSIONS = new Set(['.system']);
11
+ /**
12
+ * Discover a normalized, read-only catalog without changing Actoviq settings or
13
+ * any native runtime directory. The result is intentionally metadata-only so it
14
+ * can be returned directly by GUI/TUI APIs.
15
+ */
16
+ export async function discoverActoviqSkillCatalog(options = {}) {
17
+ const descriptors = await buildSourceDescriptors(options);
18
+ const diagnostics = [];
19
+ const candidates = [];
20
+ for (const source of descriptors) {
21
+ const discovered = source.kind === 'bundled'
22
+ ? bundledCandidates(source)
23
+ : source.kind === 'commands'
24
+ ? await scanCommandSkillSource(source, options, diagnostics)
25
+ : await scanSkillSource(source, options, diagnostics);
26
+ source.skillCount = discovered.length;
27
+ candidates.push(...discovered);
28
+ }
29
+ const skills = deduplicateCandidates(candidates);
30
+ const conflicts = markConflicts(skills);
31
+ const visibleSources = options.includeMissingSources === false
32
+ ? descriptors.filter(source => source.status !== 'missing')
33
+ : descriptors;
34
+ return {
35
+ generatedAt: new Date().toISOString(),
36
+ sources: visibleSources
37
+ .sort((left, right) => left.order - right.order)
38
+ .map(toPublicSource),
39
+ skills: skills.sort(compareSkills),
40
+ conflicts,
41
+ diagnostics: diagnostics.sort(compareDiagnostics),
42
+ summary: {
43
+ sourceCount: visibleSources.length,
44
+ discoveredSourceCount: visibleSources.filter(source => source.status !== 'missing').length,
45
+ skillVariantCount: skills.length,
46
+ invocationCount: new Set(skills.map(skill => skill.name)).size,
47
+ conflictCount: conflicts.length,
48
+ diagnosticCount: diagnostics.length,
49
+ },
50
+ };
51
+ }
52
+ async function buildSourceDescriptors(options) {
53
+ const env = options.env ?? process.env;
54
+ const osHomeDir = path.resolve(options.osHomeDir ?? os.homedir());
55
+ const workDir = path.resolve(options.workDir ?? process.cwd());
56
+ const actoviqHomeDir = options.actoviqHomeDir?.trim()
57
+ ? path.resolve(options.actoviqHomeDir)
58
+ : resolveActoviqHome(undefined, { env, osHomeDir });
59
+ const claudeConfigDir = env.CLAUDE_CONFIG_DIR?.trim()
60
+ ? path.resolve(env.CLAUDE_CONFIG_DIR)
61
+ : path.join(osHomeDir, '.claude');
62
+ const codexHome = env.CODEX_HOME?.trim()
63
+ ? path.resolve(env.CODEX_HOME)
64
+ : path.join(osHomeDir, '.codex');
65
+ const trustedProjectSources = new Set(options.trustedProjectSourceIds ?? []);
66
+ const sources = [];
67
+ const add = (input) => {
68
+ const needsTrust = input.scope === 'project' && !trustedProjectSources.has(input.id);
69
+ sources.push({
70
+ ...input,
71
+ needsTrust,
72
+ order: sources.length,
73
+ skillCount: 0,
74
+ status: input.kind === 'bundled' ? 'ready' : 'missing',
75
+ });
76
+ };
77
+ if (options.includeBundledActoviq !== false) {
78
+ add({
79
+ id: 'actoviq:bundled',
80
+ label: 'Actoviq bundled skills',
81
+ provider: 'actoviq',
82
+ scope: 'bundled',
83
+ managedBy: 'Actoviq',
84
+ readOnly: true,
85
+ kind: 'bundled',
86
+ excludeDirectoryNames: EMPTY_EXCLUSIONS,
87
+ });
88
+ }
89
+ addDirectorySource(add, 'actoviq:user', 'Actoviq user skills', 'actoviq', 'user', path.join(actoviqHomeDir, 'skills'), false);
90
+ addDirectorySource(add, 'actoviq:project', 'Actoviq project skills', 'actoviq', 'project', path.join(workDir, '.actoviq', 'skills'), false);
91
+ addDirectorySource(add, 'actoviq:project-commands', 'Actoviq project commands', 'actoviq', 'project', path.join(workDir, '.actoviq', 'commands'), false, EMPTY_EXCLUSIONS, undefined, 'commands');
92
+ addDirectorySource(add, 'agents:user', 'Shared agent skills', 'agents', 'user', path.join(osHomeDir, '.agents', 'skills'), true);
93
+ addDirectorySource(add, 'agents:project', 'Project shared agent skills', 'agents', 'project', path.join(workDir, '.agents', 'skills'), true);
94
+ addDirectorySource(add, 'claude-code:user', 'Claude Code user skills', 'claude-code', 'user', path.join(claudeConfigDir, 'skills'), true);
95
+ addDirectorySource(add, 'claude-code:project', 'Claude Code project skills', 'claude-code', 'project', path.join(workDir, '.claude', 'skills'), true);
96
+ addDirectorySource(add, 'codex:user', 'Codex user skills', 'codex', 'user', path.join(codexHome, 'skills'), true, CODEX_EXCLUSIONS);
97
+ addDirectorySource(add, 'codex:project', 'Codex project skills', 'codex', 'project', path.join(workDir, '.codex', 'skills'), true, CODEX_EXCLUSIONS);
98
+ addDirectorySource(add, 'cursor:user', 'Cursor user skills', 'cursor', 'user', path.join(osHomeDir, '.cursor', 'skills'), true);
99
+ addDirectorySource(add, 'cursor:project', 'Cursor project skills', 'cursor', 'project', path.join(workDir, '.cursor', 'skills'), true);
100
+ addDirectorySource(add, 'cc-switch:user', 'cc-switch user skills', 'cc-switch', 'user', path.join(osHomeDir, '.cc-switch', 'skills'), true);
101
+ addDirectorySource(add, 'cc-switch:project', 'cc-switch project skills', 'cc-switch', 'project', path.join(workDir, '.cc-switch', 'skills'), true);
102
+ await addClaudePluginSources(add, claudeConfigDir, workDir);
103
+ await addCodexPluginSources(add, codexHome);
104
+ return sources;
105
+ }
106
+ function addDirectorySource(add, id, label, provider, scope, root, readOnly, excludeDirectoryNames = EMPTY_EXCLUSIONS, invocationPrefix, kind = 'directory') {
107
+ add({
108
+ id,
109
+ label,
110
+ provider,
111
+ scope,
112
+ root: path.resolve(root),
113
+ managedBy: providerLabel(provider),
114
+ readOnly,
115
+ kind,
116
+ excludeDirectoryNames,
117
+ ...(invocationPrefix ? { invocationPrefix } : {}),
118
+ });
119
+ }
120
+ async function addClaudePluginSources(add, claudeConfigDir, workDir) {
121
+ const installed = await readJsonRecord(path.join(claudeConfigDir, 'plugins', 'installed_plugins.json'));
122
+ const enabledPlugins = await readEffectiveClaudePluginActivations(claudeConfigDir, workDir);
123
+ const installedPlugins = asRecord(installed?.plugins);
124
+ if (!installedPlugins)
125
+ return;
126
+ for (const [pluginId, activation] of [...enabledPlugins].sort(([left], [right]) => left.localeCompare(right))) {
127
+ if (!activation.enabled)
128
+ continue;
129
+ const parsedId = parsePluginIdentifier(pluginId);
130
+ if (!parsedId)
131
+ continue;
132
+ const rawEntries = installedPlugins[pluginId];
133
+ const entries = (Array.isArray(rawEntries) ? rawEntries : [rawEntries])
134
+ .map(asRecord)
135
+ .filter((entry) => entry !== undefined)
136
+ .filter(entry => typeof entry.installPath === 'string' && entry.installPath.trim());
137
+ const installation = selectClaudePluginInstallation(entries, activation.scope, claudeConfigDir, workDir);
138
+ if (!installation)
139
+ continue;
140
+ const scope = activation.scope === 'project' || activation.scope === 'local' ? 'project' : 'user';
141
+ addDirectorySource(add, `claude-code:plugin:${pluginId}`, `${parsedId.pluginName} (${parsedId.marketplaceName}) Claude Code plugin skills`, 'claude-code', scope, path.join(installation.path, 'skills'), true, EMPTY_EXCLUSIONS, parsedId.pluginName);
142
+ }
143
+ }
144
+ async function readEffectiveClaudePluginActivations(claudeConfigDir, workDir) {
145
+ const layers = [
146
+ { scope: 'user', file: path.join(claudeConfigDir, 'settings.json') },
147
+ { scope: 'project', file: path.join(workDir, '.claude', 'settings.json') },
148
+ { scope: 'local', file: path.join(workDir, '.claude', 'settings.local.json') },
149
+ ];
150
+ const activations = new Map();
151
+ for (const layer of layers) {
152
+ const settings = await readJsonRecord(layer.file);
153
+ const configured = asRecord(settings?.enabledPlugins);
154
+ if (!configured)
155
+ continue;
156
+ for (const [pluginId, value] of Object.entries(configured)) {
157
+ if (typeof value !== 'boolean')
158
+ continue;
159
+ activations.set(pluginId, { enabled: value, scope: layer.scope });
160
+ }
161
+ }
162
+ return activations;
163
+ }
164
+ function selectClaudePluginInstallation(entries, activationScope, claudeConfigDir, workDir) {
165
+ const installations = entries.flatMap(entry => {
166
+ const rawInstallPath = entry.installPath.trim();
167
+ const installPath = path.resolve(path.isAbsolute(rawInstallPath)
168
+ ? rawInstallPath
169
+ : path.join(claudeConfigDir, 'plugins', rawInstallPath));
170
+ const scope = typeof entry.scope === 'string'
171
+ ? entry.scope.trim().toLowerCase()
172
+ : 'user';
173
+ const declaredProjectPath = ['projectPath', 'projectDir', 'workDir', 'cwd']
174
+ .map(key => entry[key])
175
+ .find((value) => typeof value === 'string' && value.trim().length > 0);
176
+ if ((scope === 'project' || scope === 'local')
177
+ && declaredProjectPath
178
+ && comparablePath(declaredProjectPath) !== comparablePath(workDir))
179
+ return [];
180
+ return [{ path: installPath, entry, scope }];
181
+ });
182
+ const scopeGroups = activationScope === 'user'
183
+ ? [['user'], ['managed'], ['project', 'local']]
184
+ : [[activationScope], ['project', 'local'], ['user'], ['managed']];
185
+ for (const scopes of scopeGroups) {
186
+ const installPaths = new Map();
187
+ for (const installation of installations) {
188
+ if (!scopes.includes(installation.scope))
189
+ continue;
190
+ installPaths.set(comparablePath(installation.path), installation);
191
+ }
192
+ if (installPaths.size === 1)
193
+ return [...installPaths.values()][0];
194
+ if (installPaths.size > 1)
195
+ return undefined;
196
+ }
197
+ return undefined;
198
+ }
199
+ async function addCodexPluginSources(add, codexHome) {
200
+ const configPath = path.join(codexHome, 'config.toml');
201
+ let config;
202
+ try {
203
+ config = await readFile(configPath, 'utf8');
204
+ }
205
+ catch {
206
+ return;
207
+ }
208
+ const parsedConfig = parseCodexPluginConfig(config, path.dirname(configPath));
209
+ for (const pluginId of [...parsedConfig.enabledPluginIds].sort()) {
210
+ const parsedId = parsePluginIdentifier(pluginId);
211
+ if (!parsedId)
212
+ continue;
213
+ const marketplaceSource = parsedConfig.marketplaceSources.get(parsedId.marketplaceName);
214
+ const marketplacePluginRoot = marketplaceSource
215
+ ? await existingDirectory(path.join(marketplaceSource, 'plugins', parsedId.pluginName))
216
+ : undefined;
217
+ const pluginRoot = marketplacePluginRoot ?? await resolveCodexCachedPluginRoot(codexHome, parsedId.marketplaceName, parsedId.pluginName);
218
+ if (!pluginRoot)
219
+ continue;
220
+ addDirectorySource(add, `codex:plugin:${pluginId}`, `${parsedId.pluginName} (${parsedId.marketplaceName}) Codex plugin skills`, 'codex', 'user', path.join(pluginRoot, 'skills'), true, EMPTY_EXCLUSIONS, parsedId.pluginName);
221
+ }
222
+ }
223
+ async function resolveCodexCachedPluginRoot(codexHome, marketplaceName, pluginName) {
224
+ const exactPluginRoot = path.join(codexHome, 'plugins', 'cache', marketplaceName, pluginName);
225
+ let versions;
226
+ try {
227
+ versions = (await readdir(exactPluginRoot, { withFileTypes: true }))
228
+ .filter(entry => entry.isDirectory() || entry.isSymbolicLink())
229
+ .sort((left, right) => left.name.localeCompare(right.name));
230
+ }
231
+ catch {
232
+ return undefined;
233
+ }
234
+ const latest = versions.find(entry => entry.name === 'latest');
235
+ if (latest)
236
+ return existingDirectory(path.join(exactPluginRoot, latest.name));
237
+ if (versions.length !== 1)
238
+ return undefined;
239
+ return existingDirectory(path.join(exactPluginRoot, versions[0].name));
240
+ }
241
+ function parseCodexPluginConfig(content, configDir) {
242
+ const marketplaceSources = new Map();
243
+ const pluginEnabled = new Map();
244
+ let section;
245
+ for (const line of content.replace(/\r\n?/gu, '\n').split('\n')) {
246
+ const header = line.match(/^\s*\[\s*(marketplaces|plugins)\.(?:"((?:[^"\\]|\\.)*)"|'((?:[^']|'')*)'|([A-Za-z0-9_.@-]+))\s*\]\s*(?:#.*)?$/u);
247
+ if (header) {
248
+ const name = header[2] !== undefined
249
+ ? parseDoubleQuotedString(`"${header[2]}"`)
250
+ : header[3] !== undefined ? header[3].replace(/''/gu, "'") : header[4];
251
+ section = name
252
+ ? { kind: header[1] === 'marketplaces' ? 'marketplace' : 'plugin', name }
253
+ : undefined;
254
+ continue;
255
+ }
256
+ if (/^\s*\[/u.test(line)) {
257
+ section = undefined;
258
+ continue;
259
+ }
260
+ if (!section)
261
+ continue;
262
+ if (section.kind === 'marketplace') {
263
+ const sourceMatch = line.match(/^\s*source\s*=\s*(.*?)\s*$/u);
264
+ const source = sourceMatch ? parseTomlString(sourceMatch[1]) : undefined;
265
+ if (source) {
266
+ marketplaceSources.set(section.name, path.resolve(path.isAbsolute(source) ? source : path.join(configDir, source)));
267
+ }
268
+ continue;
269
+ }
270
+ const enabledMatch = line.match(/^\s*enabled\s*=\s*(true|false)\s*(?:#.*)?$/u);
271
+ if (enabledMatch)
272
+ pluginEnabled.set(section.name, enabledMatch[1] === 'true');
273
+ }
274
+ return {
275
+ marketplaceSources,
276
+ enabledPluginIds: new Set([...pluginEnabled].filter(([, enabled]) => enabled).map(([pluginId]) => pluginId)),
277
+ };
278
+ }
279
+ function parseTomlString(value) {
280
+ const singleQuoted = value.match(/^'((?:[^']|'')*)'\s*(?:#.*)?$/u);
281
+ if (singleQuoted)
282
+ return singleQuoted[1].replace(/''/gu, "'");
283
+ const doubleQuoted = value.match(/^("(?:[^"\\]|\\.)*")\s*(?:#.*)?$/u);
284
+ return doubleQuoted ? parseDoubleQuotedString(doubleQuoted[1]) : undefined;
285
+ }
286
+ function parseDoubleQuotedString(value) {
287
+ try {
288
+ const parsed = JSON.parse(value);
289
+ return typeof parsed === 'string' ? parsed : undefined;
290
+ }
291
+ catch {
292
+ return undefined;
293
+ }
294
+ }
295
+ function parsePluginIdentifier(value) {
296
+ const separator = value.lastIndexOf('@');
297
+ if (separator <= 0 || separator === value.length - 1)
298
+ return undefined;
299
+ const pluginName = value.slice(0, separator);
300
+ const marketplaceName = value.slice(separator + 1);
301
+ return isSafePluginSegment(pluginName) && isSafePluginSegment(marketplaceName)
302
+ ? { pluginName, marketplaceName }
303
+ : undefined;
304
+ }
305
+ function isSafePluginSegment(value) {
306
+ return isInvocationName(value) && value !== '.' && value !== '..' && !/[\\/]/u.test(value);
307
+ }
308
+ async function readJsonRecord(filePath) {
309
+ try {
310
+ return asRecord(JSON.parse(await readFile(filePath, 'utf8')));
311
+ }
312
+ catch {
313
+ return undefined;
314
+ }
315
+ }
316
+ function asRecord(value) {
317
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
318
+ ? value
319
+ : undefined;
320
+ }
321
+ async function existingDirectory(candidate) {
322
+ try {
323
+ return (await stat(candidate)).isDirectory() ? path.resolve(candidate) : undefined;
324
+ }
325
+ catch {
326
+ return undefined;
327
+ }
328
+ }
329
+ function providerLabel(provider) {
330
+ switch (provider) {
331
+ case 'claude-code': return 'Claude Code';
332
+ case 'cc-switch': return 'cc-switch';
333
+ case 'agents': return 'Shared agent configuration';
334
+ case 'actoviq': return 'Actoviq';
335
+ case 'codex': return 'Codex';
336
+ case 'cursor': return 'Cursor';
337
+ }
338
+ }
339
+ function bundledCandidates(source) {
340
+ return getDefaultActoviqBundledSkills().map(definition => {
341
+ const serialized = JSON.stringify({
342
+ name: definition.name,
343
+ description: definition.description,
344
+ prompt: definition.prompt ?? '',
345
+ version: definition.version,
346
+ });
347
+ const contentHash = hashContent(serialized);
348
+ return {
349
+ name: definition.name,
350
+ aliases: [],
351
+ directoryName: definition.name,
352
+ description: definition.description,
353
+ version: definition.version,
354
+ invalid: false,
355
+ contentHash,
356
+ capabilities: [],
357
+ declaredAllowedTools: [...(definition.allowedTools ?? [])],
358
+ frontmatterKeys: [],
359
+ origins: [originFromSource(source, definition.name, 'bundled')],
360
+ diagnostics: [],
361
+ };
362
+ });
363
+ }
364
+ async function scanSkillSource(source, options, diagnostics) {
365
+ let entries;
366
+ try {
367
+ entries = await readdir(source.root, { withFileTypes: true });
368
+ source.status = source.needsTrust ? 'needs-trust' : 'ready';
369
+ }
370
+ catch (error) {
371
+ if (error.code === 'ENOENT') {
372
+ source.status = 'missing';
373
+ return [];
374
+ }
375
+ source.status = 'unreadable';
376
+ diagnostics.push({
377
+ code: 'source-unreadable',
378
+ severity: 'error',
379
+ sourceId: source.id,
380
+ path: source.root,
381
+ message: `Unable to read skill source ${source.label}.`,
382
+ });
383
+ return [];
384
+ }
385
+ const skillEntries = entries
386
+ .filter(entry => (entry.isDirectory() || entry.isSymbolicLink())
387
+ && !source.excludeDirectoryNames.has(entry.name))
388
+ .sort((left, right) => left.name.localeCompare(right.name));
389
+ const results = await mapWithConcurrency(skillEntries, normalizedConcurrency(options.scanConcurrency), entry => scanSkillEntry(source, entry, options, diagnostics));
390
+ return results.filter((candidate) => candidate !== undefined);
391
+ }
392
+ async function scanSkillEntry(source, entry, options, diagnostics) {
393
+ const skillRoot = path.join(source.root, entry.name);
394
+ return scanSkillFile(source, {
395
+ directoryName: entry.name,
396
+ fallbackName: entry.name,
397
+ skillRoot,
398
+ skillFile: path.join(skillRoot, 'SKILL.md'),
399
+ loadedFrom: 'skills',
400
+ declaredNameWins: true,
401
+ }, options, diagnostics);
402
+ }
403
+ async function scanCommandSkillSource(source, options, diagnostics) {
404
+ let files;
405
+ try {
406
+ await readdir(source.root);
407
+ source.status = source.needsTrust ? 'needs-trust' : 'ready';
408
+ files = await walkCommandMarkdownFiles(source.root);
409
+ }
410
+ catch (error) {
411
+ if (error.code === 'ENOENT') {
412
+ source.status = 'missing';
413
+ return [];
414
+ }
415
+ source.status = 'unreadable';
416
+ diagnostics.push({
417
+ code: 'source-unreadable',
418
+ severity: 'error',
419
+ sourceId: source.id,
420
+ path: source.root,
421
+ message: `Unable to read skill source ${source.label}.`,
422
+ });
423
+ return [];
424
+ }
425
+ const results = await mapWithConcurrency(files, normalizedConcurrency(options.scanConcurrency), (skillFile) => {
426
+ const relativeFile = path.relative(source.root, skillFile);
427
+ const isSkillFile = path.basename(skillFile).toUpperCase() === 'SKILL.MD';
428
+ const relativeName = isSkillFile
429
+ ? path.dirname(relativeFile)
430
+ : relativeFile.replace(/\.md$/iu, '');
431
+ const fallbackName = relativeName.split(path.sep).filter(Boolean).join(':');
432
+ return scanSkillFile(source, {
433
+ directoryName: relativeFile.replaceAll(path.sep, '/'),
434
+ fallbackName,
435
+ skillRoot: path.dirname(skillFile),
436
+ skillFile,
437
+ loadedFrom: 'commands',
438
+ declaredNameWins: false,
439
+ }, options, diagnostics);
440
+ });
441
+ return results.filter((candidate) => candidate !== undefined);
442
+ }
443
+ async function walkCommandMarkdownFiles(rootDir) {
444
+ const results = [];
445
+ const visit = async (currentDir) => {
446
+ const entries = (await readdir(currentDir, { withFileTypes: true }))
447
+ .sort((left, right) => left.name.localeCompare(right.name));
448
+ await Promise.all(entries.map(async (entry) => {
449
+ const fullPath = path.join(currentDir, entry.name);
450
+ if (entry.isDirectory()) {
451
+ await visit(fullPath);
452
+ }
453
+ else if (entry.isFile() && entry.name.toLowerCase().endsWith('.md')) {
454
+ results.push(fullPath);
455
+ }
456
+ }));
457
+ };
458
+ await visit(rootDir);
459
+ const byDirectory = new Map();
460
+ for (const filePath of results) {
461
+ const directory = path.dirname(filePath);
462
+ const entries = byDirectory.get(directory) ?? [];
463
+ entries.push(filePath);
464
+ byDirectory.set(directory, entries);
465
+ }
466
+ return [...byDirectory.values()]
467
+ .flatMap(entries => entries.find(filePath => path.basename(filePath).toUpperCase() === 'SKILL.MD')
468
+ ?? entries.sort((left, right) => left.localeCompare(right)))
469
+ .flat()
470
+ .sort((left, right) => left.localeCompare(right));
471
+ }
472
+ async function scanSkillFile(source, descriptor, options, diagnostics) {
473
+ const { directoryName, fallbackName, skillRoot, skillFile } = descriptor;
474
+ let fileStat;
475
+ try {
476
+ fileStat = await stat(skillFile);
477
+ if (!fileStat.isFile())
478
+ throw new Error('Skill definition is not a file.');
479
+ }
480
+ catch {
481
+ diagnostics.push({
482
+ code: 'missing-skill-file',
483
+ severity: 'warning',
484
+ sourceId: source.id,
485
+ path: skillRoot,
486
+ message: `Skipped ${fallbackName}: the skill definition was not found.`,
487
+ });
488
+ return undefined;
489
+ }
490
+ const maxSkillBytes = normalizedMaxSkillBytes(options.maxSkillBytes);
491
+ if (fileStat.size > maxSkillBytes) {
492
+ diagnostics.push({
493
+ code: 'skill-too-large',
494
+ severity: 'error',
495
+ sourceId: source.id,
496
+ path: skillFile,
497
+ message: `Skipped ${fallbackName}: the skill definition exceeds ${maxSkillBytes} bytes.`,
498
+ });
499
+ return undefined;
500
+ }
501
+ try {
502
+ const [raw, canonicalSkillRoot, canonicalSkillFile, capabilities] = await Promise.all([
503
+ readFile(skillFile, 'utf8'),
504
+ realpath(skillRoot),
505
+ realpath(skillFile),
506
+ detectCapabilities(skillRoot),
507
+ ]);
508
+ const parsed = parseSkillFrontmatter(raw);
509
+ const contentHash = hashContent(raw);
510
+ const diagnosticsForSkill = parsed.diagnostics.map(item => ({
511
+ ...item,
512
+ severity: 'error',
513
+ sourceId: source.id,
514
+ path: skillFile,
515
+ }));
516
+ const declaredName = parsed.values.name?.trim();
517
+ let aliases = [];
518
+ let name;
519
+ if (descriptor.declaredNameWins && declaredName && isInvocationName(declaredName)) {
520
+ name = declaredName;
521
+ if (declaredName !== fallbackName)
522
+ aliases.push(fallbackName);
523
+ }
524
+ else if (isInvocationName(fallbackName)) {
525
+ name = fallbackName;
526
+ if (declaredName && declaredName !== fallbackName)
527
+ aliases.push(declaredName);
528
+ }
529
+ else {
530
+ name = sanitizeInvocationName(descriptor.declaredNameWins ? declaredName || fallbackName : fallbackName, contentHash);
531
+ aliases.push(fallbackName);
532
+ }
533
+ if ((declaredName && !isInvocationName(declaredName)) || !isInvocationName(fallbackName)) {
534
+ diagnosticsForSkill.push({
535
+ code: 'invalid-name',
536
+ severity: 'warning',
537
+ sourceId: source.id,
538
+ path: skillFile,
539
+ message: `Normalized non-invocable skill name to "${name}".`,
540
+ });
541
+ }
542
+ if (source.invocationPrefix) {
543
+ name = `${source.invocationPrefix}:${name}`;
544
+ aliases = aliases.map(alias => `${source.invocationPrefix}:${alias}`);
545
+ }
546
+ diagnostics.push(...diagnosticsForSkill);
547
+ return {
548
+ name,
549
+ aliases: uniqueSorted(aliases.filter(alias => alias !== name)),
550
+ directoryName,
551
+ description: normalizeDescription(parsed.values.description, parsed.body, name),
552
+ version: nonEmpty(parsed.values.version),
553
+ invalid: parsed.invalid,
554
+ contentHash,
555
+ capabilities,
556
+ declaredAllowedTools: parseStringList(parsed.values['allowed-tools']),
557
+ frontmatterKeys: Object.keys(parsed.values).sort(),
558
+ origins: [{
559
+ ...originFromSource(source, directoryName, descriptor.loadedFrom),
560
+ skillRoot,
561
+ canonicalSkillRoot,
562
+ skillFile,
563
+ canonicalSkillFile,
564
+ }],
565
+ diagnostics: diagnosticsForSkill,
566
+ };
567
+ }
568
+ catch {
569
+ diagnostics.push({
570
+ code: 'skill-unreadable',
571
+ severity: 'error',
572
+ sourceId: source.id,
573
+ path: skillFile,
574
+ message: `Unable to read skill ${fallbackName}.`,
575
+ });
576
+ return undefined;
577
+ }
578
+ }
579
+ function originFromSource(source, directoryName, loadedFrom = 'skills') {
580
+ return {
581
+ sourceId: source.id,
582
+ sourceLabel: source.label,
583
+ provider: source.provider,
584
+ scope: source.scope,
585
+ directoryName,
586
+ loadedFrom,
587
+ readOnly: source.readOnly,
588
+ needsTrust: source.needsTrust,
589
+ };
590
+ }
591
+ async function detectCapabilities(skillRoot) {
592
+ const names = ['assets', 'references', 'scripts'];
593
+ const found = await Promise.all(names.map(async (name) => {
594
+ try {
595
+ return (await stat(path.join(skillRoot, name))).isDirectory() ? name : undefined;
596
+ }
597
+ catch {
598
+ return undefined;
599
+ }
600
+ }));
601
+ return found.filter((name) => name !== undefined);
602
+ }
603
+ function deduplicateCandidates(candidates) {
604
+ const byCanonicalPath = new Map();
605
+ const byNameAndHash = new Map();
606
+ const skills = [];
607
+ for (const candidate of candidates) {
608
+ const canonicalFile = candidate.origins[0]?.canonicalSkillFile;
609
+ const pathKey = canonicalFile
610
+ ? `${candidate.name}\0${comparablePath(canonicalFile)}`
611
+ : undefined;
612
+ const hashKey = `${candidate.name}\0${candidate.contentHash}`;
613
+ const existing = (pathKey ? byCanonicalPath.get(pathKey) : undefined)
614
+ ?? byNameAndHash.get(hashKey);
615
+ if (existing) {
616
+ mergeCandidate(existing, candidate);
617
+ if (pathKey)
618
+ byCanonicalPath.set(pathKey, existing);
619
+ byNameAndHash.set(hashKey, existing);
620
+ continue;
621
+ }
622
+ const firstOrigin = candidate.origins[0];
623
+ const skill = {
624
+ id: skillId(candidate.name, firstOrigin),
625
+ name: candidate.name,
626
+ aliases: uniqueSorted(candidate.aliases),
627
+ directoryName: candidate.directoryName,
628
+ description: candidate.description,
629
+ version: candidate.version,
630
+ status: candidate.invalid
631
+ ? 'invalid'
632
+ : firstOrigin.needsTrust ? 'needs-trust' : 'ready',
633
+ conflict: false,
634
+ contentHash: candidate.contentHash,
635
+ sourceId: firstOrigin.sourceId,
636
+ provider: firstOrigin.provider,
637
+ scope: firstOrigin.scope,
638
+ skillRoot: firstOrigin.skillRoot,
639
+ canonicalSkillRoot: firstOrigin.canonicalSkillRoot,
640
+ readOnly: firstOrigin.readOnly,
641
+ needsTrust: firstOrigin.needsTrust,
642
+ capabilities: [...candidate.capabilities],
643
+ declaredAllowedTools: [...candidate.declaredAllowedTools],
644
+ frontmatterKeys: [...candidate.frontmatterKeys],
645
+ origins: [...candidate.origins],
646
+ diagnostics: [...candidate.diagnostics],
647
+ };
648
+ skills.push(skill);
649
+ if (pathKey)
650
+ byCanonicalPath.set(pathKey, skill);
651
+ byNameAndHash.set(hashKey, skill);
652
+ }
653
+ return skills;
654
+ }
655
+ function mergeCandidate(entry, candidate) {
656
+ entry.aliases = uniqueSorted([...entry.aliases, ...candidate.aliases]);
657
+ entry.capabilities = uniqueSorted([
658
+ ...entry.capabilities,
659
+ ...candidate.capabilities,
660
+ ]);
661
+ entry.declaredAllowedTools = uniqueSorted([
662
+ ...entry.declaredAllowedTools,
663
+ ...candidate.declaredAllowedTools,
664
+ ]);
665
+ entry.frontmatterKeys = uniqueSorted([
666
+ ...entry.frontmatterKeys,
667
+ ...candidate.frontmatterKeys,
668
+ ]);
669
+ entry.origins.push(...candidate.origins);
670
+ entry.diagnostics.push(...candidate.diagnostics);
671
+ entry.readOnly = entry.origins.every(origin => origin.readOnly);
672
+ entry.needsTrust = entry.origins.every(origin => origin.needsTrust);
673
+ if (entry.status !== 'invalid') {
674
+ entry.status = entry.needsTrust ? 'needs-trust' : 'ready';
675
+ }
676
+ }
677
+ function markConflicts(skills) {
678
+ const byName = new Map();
679
+ for (const skill of skills) {
680
+ const entries = byName.get(skill.name) ?? [];
681
+ entries.push(skill);
682
+ byName.set(skill.name, entries);
683
+ }
684
+ const conflicts = [];
685
+ for (const [name, entries] of byName) {
686
+ if (entries.length < 2)
687
+ continue;
688
+ for (const entry of entries)
689
+ entry.conflict = true;
690
+ conflicts.push({
691
+ name,
692
+ skillIds: entries.map(entry => entry.id).sort(),
693
+ contentHashes: entries.map(entry => entry.contentHash).sort(),
694
+ sourceIds: uniqueSorted(entries.flatMap(entry => entry.origins.map(origin => origin.sourceId))),
695
+ });
696
+ }
697
+ return conflicts.sort((left, right) => left.name.localeCompare(right.name));
698
+ }
699
+ function parseSkillFrontmatter(content) {
700
+ const normalized = content.replace(/\r\n?/gu, '\n');
701
+ const lines = normalized.split('\n');
702
+ if (lines[0]?.trim() !== '---') {
703
+ return { values: {}, body: normalized.trim(), diagnostics: [], invalid: false };
704
+ }
705
+ const closeIndex = lines.findIndex((line, index) => index > 0 && line.trim() === '---');
706
+ if (closeIndex < 0) {
707
+ return {
708
+ values: {},
709
+ body: normalized.trim(),
710
+ diagnostics: [{
711
+ code: 'invalid-frontmatter',
712
+ message: 'Frontmatter opening delimiter has no closing delimiter.',
713
+ }],
714
+ invalid: true,
715
+ };
716
+ }
717
+ const values = {};
718
+ const frontmatterLines = lines.slice(1, closeIndex);
719
+ for (let index = 0; index < frontmatterLines.length;) {
720
+ const line = frontmatterLines[index];
721
+ const match = line.match(/^([A-Za-z0-9_-]+)\s*:\s*(.*)$/u);
722
+ if (!match) {
723
+ index += 1;
724
+ continue;
725
+ }
726
+ const key = match[1];
727
+ const rawValue = match[2].trim();
728
+ const block = rawValue.match(/^([>|])([+-]?)$/u);
729
+ if (!block) {
730
+ values[key] = parseScalar(rawValue);
731
+ index += 1;
732
+ continue;
733
+ }
734
+ const blockLines = [];
735
+ index += 1;
736
+ while (index < frontmatterLines.length) {
737
+ const next = frontmatterLines[index];
738
+ if (next.trim() && !/^\s/u.test(next))
739
+ break;
740
+ blockLines.push(next);
741
+ index += 1;
742
+ }
743
+ const normalizedBlock = stripCommonIndent(blockLines);
744
+ values[key] = block[1] === '|'
745
+ ? normalizedBlock.join('\n').replace(/\n+$/u, '')
746
+ : foldBlockLines(normalizedBlock);
747
+ }
748
+ return {
749
+ values,
750
+ body: lines.slice(closeIndex + 1).join('\n').trim(),
751
+ diagnostics: [],
752
+ invalid: false,
753
+ };
754
+ }
755
+ function parseScalar(value) {
756
+ const trimmed = value.trim();
757
+ const doubleQuoted = trimmed.match(/^("(?:[^"\\]|\\.)*")(?:\s+#.*)?$/u);
758
+ if (doubleQuoted) {
759
+ try {
760
+ const parsed = JSON.parse(doubleQuoted[1]);
761
+ return typeof parsed === 'string' ? parsed : doubleQuoted[1].slice(1, -1);
762
+ }
763
+ catch {
764
+ return doubleQuoted[1].slice(1, -1);
765
+ }
766
+ }
767
+ const singleQuoted = trimmed.match(/^'((?:[^']|'')*)'(?:\s+#.*)?$/u);
768
+ if (singleQuoted) {
769
+ return singleQuoted[1].replace(/''/gu, "'");
770
+ }
771
+ return trimmed.replace(/\s+#.*$/u, '').trim();
772
+ }
773
+ function stripCommonIndent(lines) {
774
+ const indents = lines
775
+ .filter(line => line.trim())
776
+ .map(line => line.match(/^\s*/u)?.[0].length ?? 0);
777
+ const commonIndent = indents.length > 0 ? Math.min(...indents) : 0;
778
+ return lines.map(line => line.trim() ? line.slice(commonIndent) : '');
779
+ }
780
+ function foldBlockLines(lines) {
781
+ let result = '';
782
+ let previousBlank = true;
783
+ for (const line of lines) {
784
+ const blank = line.length === 0;
785
+ if (blank) {
786
+ result = result.replace(/[ \t]+$/u, '') + '\n';
787
+ }
788
+ else if (!previousBlank && result) {
789
+ result += ` ${line}`;
790
+ }
791
+ else {
792
+ result += line;
793
+ }
794
+ previousBlank = blank;
795
+ }
796
+ return result.replace(/\n+$/u, '').trim();
797
+ }
798
+ function normalizeDescription(value, body, name) {
799
+ const explicit = value?.trim();
800
+ if (explicit)
801
+ return explicit;
802
+ const firstBodyLine = body
803
+ .split(/\r?\n/gu)
804
+ .map(line => line.replace(/^#+\s*/u, '').trim())
805
+ .find(Boolean);
806
+ return firstBodyLine?.slice(0, 240) || `Run the ${name} skill.`;
807
+ }
808
+ function parseStringList(value) {
809
+ if (!value?.trim())
810
+ return [];
811
+ const trimmed = value.trim();
812
+ const body = trimmed.startsWith('[') && trimmed.endsWith(']')
813
+ ? trimmed.slice(1, -1)
814
+ : trimmed;
815
+ return uniqueSorted(body
816
+ .split(',')
817
+ .map(item => parseScalar(item.trim()))
818
+ .filter(Boolean));
819
+ }
820
+ function isInvocationName(value) {
821
+ return Boolean(value)
822
+ && value.length <= 128
823
+ && !/[\s/\\\u0000-\u001f\u007f]/u.test(value);
824
+ }
825
+ function sanitizeInvocationName(value, contentHash) {
826
+ const normalized = value
827
+ .normalize('NFKC')
828
+ .trim()
829
+ .replace(/\s+/gu, '-')
830
+ .replace(/[/\\\u0000-\u001f\u007f]/gu, '')
831
+ .replace(/-+/gu, '-')
832
+ .slice(0, 128);
833
+ return normalized || `skill-${contentHash.slice(0, 8)}`;
834
+ }
835
+ function hashContent(content) {
836
+ return createHash('sha256').update(content).digest('hex');
837
+ }
838
+ function skillId(name, origin) {
839
+ return `skill:${hashContent(`${name}\0${origin.sourceId}\0${origin.directoryName}`).slice(0, 24)}`;
840
+ }
841
+ function comparablePath(value) {
842
+ const resolved = path.resolve(value);
843
+ return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
844
+ }
845
+ function nonEmpty(value) {
846
+ const normalized = value?.trim();
847
+ return normalized || undefined;
848
+ }
849
+ function uniqueSorted(values) {
850
+ return [...new Set(values)].sort((left, right) => left.localeCompare(right));
851
+ }
852
+ function normalizedMaxSkillBytes(value) {
853
+ return Number.isSafeInteger(value) && value > 0 ? value : DEFAULT_MAX_SKILL_BYTES;
854
+ }
855
+ function normalizedConcurrency(value) {
856
+ return Number.isSafeInteger(value) && value > 0
857
+ ? Math.min(value, 32)
858
+ : DEFAULT_SCAN_CONCURRENCY;
859
+ }
860
+ async function mapWithConcurrency(values, concurrency, worker) {
861
+ const results = new Array(values.length);
862
+ let nextIndex = 0;
863
+ const runners = Array.from({ length: Math.min(concurrency, Math.max(values.length, 1)) }, async () => {
864
+ while (nextIndex < values.length) {
865
+ const index = nextIndex;
866
+ nextIndex += 1;
867
+ results[index] = await worker(values[index]);
868
+ }
869
+ });
870
+ await Promise.all(runners);
871
+ return results;
872
+ }
873
+ function toPublicSource(source) {
874
+ return {
875
+ id: source.id,
876
+ label: source.label,
877
+ provider: source.provider,
878
+ scope: source.scope,
879
+ root: source.root,
880
+ managedBy: source.managedBy,
881
+ readOnly: source.readOnly,
882
+ needsTrust: source.needsTrust,
883
+ status: source.status,
884
+ skillCount: source.skillCount,
885
+ };
886
+ }
887
+ function compareSkills(left, right) {
888
+ return left.name.localeCompare(right.name) || left.contentHash.localeCompare(right.contentHash);
889
+ }
890
+ function compareDiagnostics(left, right) {
891
+ return left.sourceId.localeCompare(right.sourceId)
892
+ || (left.path ?? '').localeCompare(right.path ?? '')
893
+ || left.code.localeCompare(right.code);
894
+ }
895
+ //# sourceMappingURL=externalSkillCatalog.js.map