@vibefield/puppeteer-adapter-claude 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/LICENSE +21 -0
  2. package/dist/detection.d.ts +78 -0
  3. package/dist/detection.d.ts.map +1 -0
  4. package/dist/detection.js +167 -0
  5. package/dist/detection.js.map +1 -0
  6. package/dist/driver.d.ts +145 -0
  7. package/dist/driver.d.ts.map +1 -0
  8. package/dist/driver.js +840 -0
  9. package/dist/driver.js.map +1 -0
  10. package/dist/generated/detection-surface.d.ts +30 -0
  11. package/dist/generated/detection-surface.d.ts.map +1 -0
  12. package/dist/generated/detection-surface.js +34 -0
  13. package/dist/generated/detection-surface.js.map +1 -0
  14. package/dist/generated/registry.d.ts +45 -0
  15. package/dist/generated/registry.d.ts.map +1 -0
  16. package/dist/generated/registry.js +287 -0
  17. package/dist/generated/registry.js.map +1 -0
  18. package/dist/index.d.ts +27 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +27 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/launch/hook-switches.d.ts +32 -0
  23. package/dist/launch/hook-switches.d.ts.map +1 -0
  24. package/dist/launch/hook-switches.js +56 -0
  25. package/dist/launch/hook-switches.js.map +1 -0
  26. package/dist/launch/invocation-grammar.d.ts +196 -0
  27. package/dist/launch/invocation-grammar.d.ts.map +1 -0
  28. package/dist/launch/invocation-grammar.js +857 -0
  29. package/dist/launch/invocation-grammar.js.map +1 -0
  30. package/dist/launch/native-invocation.d.ts +42 -0
  31. package/dist/launch/native-invocation.d.ts.map +1 -0
  32. package/dist/launch/native-invocation.js +130 -0
  33. package/dist/launch/native-invocation.js.map +1 -0
  34. package/dist/launch/prepare.d.ts +137 -0
  35. package/dist/launch/prepare.d.ts.map +1 -0
  36. package/dist/launch/prepare.js +317 -0
  37. package/dist/launch/prepare.js.map +1 -0
  38. package/dist/launch/settings.d.ts +63 -0
  39. package/dist/launch/settings.d.ts.map +1 -0
  40. package/dist/launch/settings.js +94 -0
  41. package/dist/launch/settings.js.map +1 -0
  42. package/dist/normalization/adapter.d.ts +3 -0
  43. package/dist/normalization/adapter.d.ts.map +1 -0
  44. package/dist/normalization/adapter.js +4 -0
  45. package/dist/normalization/adapter.js.map +1 -0
  46. package/dist/normalization/compaction.d.ts +4 -0
  47. package/dist/normalization/compaction.d.ts.map +1 -0
  48. package/dist/normalization/compaction.js +7 -0
  49. package/dist/normalization/compaction.js.map +1 -0
  50. package/dist/normalization/context-window.d.ts +3 -0
  51. package/dist/normalization/context-window.d.ts.map +1 -0
  52. package/dist/normalization/context-window.js +4 -0
  53. package/dist/normalization/context-window.js.map +1 -0
  54. package/dist/normalization/conversation.d.ts +3 -0
  55. package/dist/normalization/conversation.d.ts.map +1 -0
  56. package/dist/normalization/conversation.js +4 -0
  57. package/dist/normalization/conversation.js.map +1 -0
  58. package/dist/normalization/delegation.d.ts +4 -0
  59. package/dist/normalization/delegation.d.ts.map +1 -0
  60. package/dist/normalization/delegation.js +7 -0
  61. package/dist/normalization/delegation.js.map +1 -0
  62. package/dist/normalization/effort.d.ts +8 -0
  63. package/dist/normalization/effort.d.ts.map +1 -0
  64. package/dist/normalization/effort.js +16 -0
  65. package/dist/normalization/effort.js.map +1 -0
  66. package/dist/normalization/environment.d.ts +5 -0
  67. package/dist/normalization/environment.d.ts.map +1 -0
  68. package/dist/normalization/environment.js +10 -0
  69. package/dist/normalization/environment.js.map +1 -0
  70. package/dist/normalization/index.d.ts +20 -0
  71. package/dist/normalization/index.d.ts.map +1 -0
  72. package/dist/normalization/index.js +20 -0
  73. package/dist/normalization/index.js.map +1 -0
  74. package/dist/normalization/interaction.d.ts +38 -0
  75. package/dist/normalization/interaction.d.ts.map +1 -0
  76. package/dist/normalization/interaction.js +60 -0
  77. package/dist/normalization/interaction.js.map +1 -0
  78. package/dist/normalization/mode.d.ts +11 -0
  79. package/dist/normalization/mode.d.ts.map +1 -0
  80. package/dist/normalization/mode.js +37 -0
  81. package/dist/normalization/mode.js.map +1 -0
  82. package/dist/normalization/model.d.ts +5 -0
  83. package/dist/normalization/model.d.ts.map +1 -0
  84. package/dist/normalization/model.js +7 -0
  85. package/dist/normalization/model.js.map +1 -0
  86. package/dist/normalization/monitor-capabilities.d.ts +4 -0
  87. package/dist/normalization/monitor-capabilities.d.ts.map +1 -0
  88. package/dist/normalization/monitor-capabilities.js +121 -0
  89. package/dist/normalization/monitor-capabilities.js.map +1 -0
  90. package/dist/normalization/monitor.d.ts +46 -0
  91. package/dist/normalization/monitor.d.ts.map +1 -0
  92. package/dist/normalization/monitor.js +332 -0
  93. package/dist/normalization/monitor.js.map +1 -0
  94. package/dist/normalization/notification.d.ts +4 -0
  95. package/dist/normalization/notification.d.ts.map +1 -0
  96. package/dist/normalization/notification.js +9 -0
  97. package/dist/normalization/notification.js.map +1 -0
  98. package/dist/normalization/pipeline.d.ts +56 -0
  99. package/dist/normalization/pipeline.d.ts.map +1 -0
  100. package/dist/normalization/pipeline.js +472 -0
  101. package/dist/normalization/pipeline.js.map +1 -0
  102. package/dist/normalization/session.d.ts +6 -0
  103. package/dist/normalization/session.d.ts.map +1 -0
  104. package/dist/normalization/session.js +17 -0
  105. package/dist/normalization/session.js.map +1 -0
  106. package/dist/normalization/tool.d.ts +8 -0
  107. package/dist/normalization/tool.d.ts.map +1 -0
  108. package/dist/normalization/tool.js +64 -0
  109. package/dist/normalization/tool.js.map +1 -0
  110. package/dist/normalization/turn.d.ts +6 -0
  111. package/dist/normalization/turn.d.ts.map +1 -0
  112. package/dist/normalization/turn.js +15 -0
  113. package/dist/normalization/turn.js.map +1 -0
  114. package/dist/normalization/types.d.ts +47 -0
  115. package/dist/normalization/types.d.ts.map +1 -0
  116. package/dist/normalization/types.js +2 -0
  117. package/dist/normalization/types.js.map +1 -0
  118. package/dist/normalization/wire.d.ts +10 -0
  119. package/dist/normalization/wire.d.ts.map +1 -0
  120. package/dist/normalization/wire.js +75 -0
  121. package/dist/normalization/wire.js.map +1 -0
  122. package/dist/normalization/workspace.d.ts +5 -0
  123. package/dist/normalization/workspace.d.ts.map +1 -0
  124. package/dist/normalization/workspace.js +68 -0
  125. package/dist/normalization/workspace.js.map +1 -0
  126. package/dist/observation/hook-bridge.d.ts +72 -0
  127. package/dist/observation/hook-bridge.d.ts.map +1 -0
  128. package/dist/observation/hook-bridge.js +250 -0
  129. package/dist/observation/hook-bridge.js.map +1 -0
  130. package/dist/observation/otel/actor.d.ts +14 -0
  131. package/dist/observation/otel/actor.d.ts.map +1 -0
  132. package/dist/observation/otel/actor.js +44 -0
  133. package/dist/observation/otel/actor.js.map +1 -0
  134. package/dist/observation/otel/capability.d.ts +4 -0
  135. package/dist/observation/otel/capability.d.ts.map +1 -0
  136. package/dist/observation/otel/capability.js +24 -0
  137. package/dist/observation/otel/capability.js.map +1 -0
  138. package/dist/observation/otel/index.d.ts +6 -0
  139. package/dist/observation/otel/index.d.ts.map +1 -0
  140. package/dist/observation/otel/index.js +6 -0
  141. package/dist/observation/otel/index.js.map +1 -0
  142. package/dist/observation/otel/model.d.ts +9 -0
  143. package/dist/observation/otel/model.d.ts.map +1 -0
  144. package/dist/observation/otel/model.js +16 -0
  145. package/dist/observation/otel/model.js.map +1 -0
  146. package/dist/observation/otel/usage.d.ts +16 -0
  147. package/dist/observation/otel/usage.d.ts.map +1 -0
  148. package/dist/observation/otel/usage.js +75 -0
  149. package/dist/observation/otel/usage.js.map +1 -0
  150. package/dist/observation/otel/wire.d.ts +15 -0
  151. package/dist/observation/otel/wire.d.ts.map +1 -0
  152. package/dist/observation/otel/wire.js +147 -0
  153. package/dist/observation/otel/wire.js.map +1 -0
  154. package/dist/observation/semantic-provider.d.ts +45 -0
  155. package/dist/observation/semantic-provider.d.ts.map +1 -0
  156. package/dist/observation/semantic-provider.js +8 -0
  157. package/dist/observation/semantic-provider.js.map +1 -0
  158. package/dist/observation/status-channel.d.ts +70 -0
  159. package/dist/observation/status-channel.d.ts.map +1 -0
  160. package/dist/observation/status-channel.js +268 -0
  161. package/dist/observation/status-channel.js.map +1 -0
  162. package/dist/observation/transcript/conversation.d.ts +6 -0
  163. package/dist/observation/transcript/conversation.d.ts.map +1 -0
  164. package/dist/observation/transcript/conversation.js +170 -0
  165. package/dist/observation/transcript/conversation.js.map +1 -0
  166. package/dist/observation/transcript/index.d.ts +5 -0
  167. package/dist/observation/transcript/index.d.ts.map +1 -0
  168. package/dist/observation/transcript/index.js +5 -0
  169. package/dist/observation/transcript/index.js.map +1 -0
  170. package/dist/observation/transcript/provider.d.ts +7 -0
  171. package/dist/observation/transcript/provider.d.ts.map +1 -0
  172. package/dist/observation/transcript/provider.js +132 -0
  173. package/dist/observation/transcript/provider.js.map +1 -0
  174. package/dist/observation/transcript/services/jsonl-reader.d.ts +12 -0
  175. package/dist/observation/transcript/services/jsonl-reader.d.ts.map +1 -0
  176. package/dist/observation/transcript/services/jsonl-reader.js +140 -0
  177. package/dist/observation/transcript/services/jsonl-reader.js.map +1 -0
  178. package/dist/observation/transcript/services/yield.d.ts +3 -0
  179. package/dist/observation/transcript/services/yield.d.ts.map +1 -0
  180. package/dist/observation/transcript/services/yield.js +15 -0
  181. package/dist/observation/transcript/services/yield.js.map +1 -0
  182. package/dist/observation/transcript/wire.d.ts +26 -0
  183. package/dist/observation/transcript/wire.d.ts.map +1 -0
  184. package/dist/observation/transcript/wire.js +89 -0
  185. package/dist/observation/transcript/wire.js.map +1 -0
  186. package/dist/services/account-usage.d.ts +86 -0
  187. package/dist/services/account-usage.d.ts.map +1 -0
  188. package/dist/services/account-usage.js +813 -0
  189. package/dist/services/account-usage.js.map +1 -0
  190. package/dist/services/distribution.d.ts +64 -0
  191. package/dist/services/distribution.d.ts.map +1 -0
  192. package/dist/services/distribution.js +255 -0
  193. package/dist/services/distribution.js.map +1 -0
  194. package/dist/services/event-source.d.ts +29 -0
  195. package/dist/services/event-source.d.ts.map +1 -0
  196. package/dist/services/event-source.js +38 -0
  197. package/dist/services/event-source.js.map +1 -0
  198. package/dist/services/extensions.d.ts +46 -0
  199. package/dist/services/extensions.d.ts.map +1 -0
  200. package/dist/services/extensions.js +1263 -0
  201. package/dist/services/extensions.js.map +1 -0
  202. package/dist/services/models.d.ts +6 -0
  203. package/dist/services/models.d.ts.map +1 -0
  204. package/dist/services/models.js +90 -0
  205. package/dist/services/models.js.map +1 -0
  206. package/dist/services/profiles.d.ts +48 -0
  207. package/dist/services/profiles.d.ts.map +1 -0
  208. package/dist/services/profiles.js +176 -0
  209. package/dist/services/profiles.js.map +1 -0
  210. package/dist/services/prompt.d.ts +39 -0
  211. package/dist/services/prompt.d.ts.map +1 -0
  212. package/dist/services/prompt.js +107 -0
  213. package/dist/services/prompt.js.map +1 -0
  214. package/package.json +46 -3
  215. package/README.md +0 -3
@@ -0,0 +1,1263 @@
1
+ /**
2
+ * Claude Code extensions (RFC 006 C1): the plugins, marketplaces, MCP servers
3
+ * and skills one profile's root holds, read from Claude Code's own store files.
4
+ * Never from `claude mcp list`, which connects to every server it lists, and
5
+ * never from a credential store: a server's environment and headers are read
6
+ * as names only.
7
+ *
8
+ * Layout per James's probe of 2.1.282 (puppeteer
9
+ * draft/CLAUDE-PLUGINS-SKILLS-MCP.md, 2026-09-24):
10
+ * - The app-state file holds user servers (top-level `mcpServers`) and
11
+ * one-project servers (`projects[<path>].mcpServers`, switched off per
12
+ * project by `disabledMcpServers`). A managed root keeps it at
13
+ * `<root>/.claude.json`; the native default beside the root, at
14
+ * `~/.claude.json`.
15
+ * - `settings.json` `enabledPlugins` says which installed plugins load, and
16
+ * `skillOverrides` can switch a skill off.
17
+ * - `plugins/installed_plugins.json` is `{ version, plugins: { <id>: [{ scope,
18
+ * version, installPath, … }] } }`; `plugins/known_marketplaces.json` maps a
19
+ * marketplace to `{ source, installLocation, lastUpdated }`, and
20
+ * `known_marketplaces_claudeai.json` the ones claude.ai added; plugins the
21
+ * claude.ai account turns on are downloaded to `plugins/synced/`. A
22
+ * plugin's folder holds `.claude-plugin/plugin.json`, `.mcp.json`,
23
+ * `skills/<name>/SKILL.md`, and the `commands/*.md`, `agents/*.md` and
24
+ * `hooks/hooks.json` whose names a listing shows.
25
+ * - Personal skills are `<root>/skills/<name>/SKILL.md`; `skills/synced/` holds
26
+ * the account's. A linked skill folder is read from its target.
27
+ * - A marketplace's catalog (C2) is the `.claude-plugin/marketplace.json` in
28
+ * its `installLocation`: a git source's clone under `plugins/marketplaces/`,
29
+ * or a folder Claude Code reads in place. Each entry installs as `<entry
30
+ * name>@<marketplace>`, the key `installed_plugins.json` keeps it by, and
31
+ * `plugins/flagged-plugins.json` names the ones Claude Code took out.
32
+ * A project's `.mcp.json` and `.claude/` live in its working tree, not the
33
+ * profile, and are not read here.
34
+ */
35
+ import { lstat, readdir, readFile, readlink, realpath, stat } from 'node:fs/promises';
36
+ import { homedir } from 'node:os';
37
+ import { basename, dirname, isAbsolute, join, resolve, sep } from 'node:path';
38
+ import { describeArgv, describeMcpCommand, describeMcpUrl, EXTENSION_COMMAND_NAME, EXTENSION_PLUGIN_NAME, extensionActUnavailable, extensionCommandPlan, extensionNotOwnWords, extensionSignInAbsentWords, extensionSkillFolderPlan, extensionTerminalPlan, isExtensionSource, mcpServerDefinition, parseSkillFrontmatter, } from '@vibefield/puppeteer-core';
39
+ import { resolveClaudeExecutable } from '../detection.js';
40
+ import { CLAUDE_PROFILE_ROOT_VARIABLE } from './profiles.js';
41
+ /** The app-state file grows with project history; past this it is not parsed. */
42
+ const MAX_STORE_BYTES = 64 * 1024 * 1024;
43
+ const MAX_MANIFEST_BYTES = 1024 * 1024;
44
+ const MAX_SKILLS_PER_FOLDER = 512;
45
+ /** A marketplace's catalog is read whole; past this it is not read. */
46
+ const MAX_CATALOG_BYTES = 4 * 1024 * 1024;
47
+ /**
48
+ * Only a catalog's first entries have their folders read for what they bring
49
+ * (Anthropic's own lists some 300); the rest show what their entry says.
50
+ */
51
+ const MAX_CATALOG_FOLDERS = 400;
52
+ /** Core's bounds on one catalog. */
53
+ const MAX_CATALOG_MARKETPLACES = 256;
54
+ const MAX_CATALOG_PLUGINS = 8_192;
55
+ /** A remote server's address has a scheme; `claude mcp add` would read one starting with a hyphen as a flag. */
56
+ const REMOTE_ADDRESS = /^[A-Za-z][A-Za-z0-9+.-]*:\/\//u;
57
+ /** One argument of Claude Code's own command: never a flag, never a space or a control character. */
58
+ const COMMAND_ARGUMENT = /^(?!-)[^\s\u0000-\u001f\u007f]{1,512}$/u;
59
+ /** Core's bound on a string a listing shows: a source, a location, a command line. */
60
+ const MAX_SHOWN = 8_192;
61
+ /** Core's bound on an item's id. */
62
+ const MAX_ID = 512;
63
+ const rec = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
64
+ const text = (value) => {
65
+ const trimmed = typeof value === 'string' ? value.trim() : '';
66
+ return trimmed.length > 0 ? trimmed : undefined;
67
+ };
68
+ const isString = (value) => typeof value === 'string';
69
+ const strings = (value) => (Array.isArray(value) ? value.filter(isString) : []);
70
+ /**
71
+ * A string a listing shows, or nothing when it is past Core's bound: a field
72
+ * left out, where one too long would fail the whole read's schema.
73
+ */
74
+ const bounded = (value) => value !== undefined && value.length <= MAX_SHOWN ? value : undefined;
75
+ const ISO_WITH_OFFSET = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/u;
76
+ /** A store file that is absent reads as empty; one that exists and cannot be parsed is a failure the caller reports. */
77
+ async function readJsonValue(path, limit = MAX_STORE_BYTES) {
78
+ let size;
79
+ try {
80
+ size = (await stat(path)).size;
81
+ }
82
+ catch (error) {
83
+ if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
84
+ return undefined;
85
+ throw error;
86
+ }
87
+ if (size > limit)
88
+ throw new Error(`${path} is larger than ${limit} bytes`);
89
+ return JSON.parse(await readFile(path, 'utf8'));
90
+ }
91
+ async function readJson(path, limit = MAX_STORE_BYTES) {
92
+ const value = await readJsonValue(path, limit);
93
+ if (value === undefined)
94
+ return undefined;
95
+ const document = rec(value);
96
+ if (!document)
97
+ throw new Error(`${path} is not a JSON object`);
98
+ return document;
99
+ }
100
+ async function readText(path, limit = MAX_MANIFEST_BYTES) {
101
+ try {
102
+ if ((await stat(path)).size > limit)
103
+ return undefined;
104
+ return await readFile(path, 'utf8');
105
+ }
106
+ catch {
107
+ return undefined;
108
+ }
109
+ }
110
+ function transportOf(definition) {
111
+ const type = text(definition.type);
112
+ if (type === undefined || type === 'stdio')
113
+ return text(definition.command) ? 'stdio' : undefined;
114
+ if (type === 'http' || type === 'streamable-http')
115
+ return 'http';
116
+ if (type === 'sse' || type === 'ws')
117
+ return type;
118
+ return undefined;
119
+ }
120
+ /**
121
+ * One server definition as a listing may show it. A definition Claude Code
122
+ * itself skips — a `url` with no `type`, an unknown type — yields nothing.
123
+ */
124
+ function serverItem(name, value, fields) {
125
+ const server = rec(value);
126
+ if (!server || !text(name))
127
+ return undefined;
128
+ const transport = transportOf(server);
129
+ if (!transport)
130
+ return undefined;
131
+ const target = transport === 'stdio'
132
+ ? describeMcpCommand(text(server.command), strings(server.args))
133
+ : text(server.url)
134
+ ? describeMcpUrl(text(server.url))
135
+ : undefined;
136
+ if (!target)
137
+ return undefined;
138
+ const envNames = Object.keys(rec(server.env) ?? {});
139
+ const headerNames = Object.keys(rec(server.headers) ?? {});
140
+ const env = envNames.filter((key) => /^[A-Za-z_][A-Za-z0-9_]{0,127}$/u.test(key));
141
+ const headers = headerNames.filter((key) => /^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/u.test(key));
142
+ // What another agent could take is decided from the server as Claude Code
143
+ // keeps it, before any masking and with every name it keeps: an argument that
144
+ // is not a string, or a name the listing drops, would make it another server.
145
+ const argsKept = server.args === undefined || (Array.isArray(server.args) && server.args.every(isString));
146
+ const definition = argsKept
147
+ ? mcpServerDefinition({
148
+ transport,
149
+ command: text(server.command),
150
+ args: strings(server.args),
151
+ url: text(server.url),
152
+ env: envNames,
153
+ headers: headerNames,
154
+ })
155
+ : undefined;
156
+ return {
157
+ kind: 'mcp-server',
158
+ ...fields,
159
+ name: name.trim().slice(0, 256),
160
+ transport,
161
+ target,
162
+ ...(env.length > 0 ? { env: env.slice(0, 64) } : {}),
163
+ ...(headers.length > 0 ? { headers: headers.slice(0, 64) } : {}),
164
+ ...(definition ? { definition } : {}),
165
+ };
166
+ }
167
+ /** A plugin's servers: `.mcp.json`, whose top level is `mcpServers` or the map itself, or an inline `mcpServers` in its manifest. */
168
+ function pluginServers(manifest, dotMcp) {
169
+ const inline = rec(manifest?.mcpServers);
170
+ const file = dotMcp ? (rec(dotMcp.mcpServers) ?? dotMcp) : undefined;
171
+ return { ...(file ?? {}), ...(inline ?? {}) };
172
+ }
173
+ /** A hook event as Claude Code names one: `PreToolUse`, `SessionStart`. */
174
+ const HOOK_EVENT = /^[A-Za-z][A-Za-z0-9_]*$/u;
175
+ /**
176
+ * Who made a plugin, as its manifest or its catalog entry says: a string, or
177
+ * an object's `name`, and never an address. npm's `Name <email> (address)`
178
+ * keeps the name alone, a parenthesised address or email goes, and so does any
179
+ * other word with an `@` inside it. Each pattern stops at the next bracket of
180
+ * its own kind, so text anyone may write is read in one pass however it is
181
+ * crafted.
182
+ */
183
+ function authorOf(manifest) {
184
+ const author = manifest?.author;
185
+ const name = typeof author === 'string' ? author : rec(author)?.name;
186
+ if (typeof name !== 'string')
187
+ return undefined;
188
+ const shown = name
189
+ .replace(/<[^<>]*>/gu, ' ')
190
+ .replace(/\([^()]*\)/gu, (group) => (group.includes('://') || group.includes('@') ? ' ' : group))
191
+ .split(/[\s\u0000-\u001f\u007f]+/u)
192
+ .filter((word) => !word.slice(1, -1).includes('@'))
193
+ .join(' ')
194
+ .trim()
195
+ .slice(0, 256)
196
+ .trimEnd();
197
+ return shown.length > 0 ? shown : undefined;
198
+ }
199
+ /** A plugin's homepage, else its repository, as {@link describeMcpUrl} shows an address: only an http(s) one. */
200
+ function homepageOf(manifest) {
201
+ const repository = manifest?.repository;
202
+ for (const candidate of [manifest?.homepage, typeof repository === 'string' ? repository : rec(repository)?.url]) {
203
+ const address = text(candidate);
204
+ if (address === undefined || !/^https?:\/\//iu.test(address))
205
+ continue;
206
+ const shown = describeMcpUrl(address);
207
+ if (/^https?:\/\//u.test(shown) && shown.length <= 8_192)
208
+ return shown;
209
+ }
210
+ return undefined;
211
+ }
212
+ /** Where paths may lead: inside `base`, itself a real path. */
213
+ function insideOf(base) {
214
+ return async (path) => {
215
+ try {
216
+ const real = await realpath(path);
217
+ return real === base || real.startsWith(`${base}${sep}`) ? real : undefined;
218
+ }
219
+ catch {
220
+ return undefined;
221
+ }
222
+ };
223
+ }
224
+ /** Names as a listing shows them: each once, sorted, none empty or longer than Core takes. */
225
+ function partNames(found, max) {
226
+ return [...new Set(found.map((name) => name.trim()).filter((name) => name.length > 0 && name.length <= 256))]
227
+ .sort((a, b) => a.localeCompare(b))
228
+ .slice(0, max);
229
+ }
230
+ /**
231
+ * The events a hooks document runs on: `{ hooks: { <event>: […] } }`, or the
232
+ * events at the top level. An event's hooks are a list, so a `description`
233
+ * beside them is not one.
234
+ */
235
+ function hookEvents(document) {
236
+ const hooks = document === undefined ? {} : 'hooks' in document ? (rec(document.hooks) ?? {}) : document;
237
+ return Object.entries(hooks)
238
+ .filter(([name, value]) => HOOK_EVENT.test(name) && Array.isArray(value))
239
+ .map(([name]) => name);
240
+ }
241
+ /**
242
+ * The names of what a plugin runs beside its servers and skills: its commands
243
+ * (`commands/*.md`), its agents (`agents/*.md`) and the events its hooks run on
244
+ * (`hooks/hooks.json`). Read only inside its folder, so a part that is a link
245
+ * leading out of it is never followed; a link among the files is not taken.
246
+ */
247
+ async function pluginParts(folder) {
248
+ let base;
249
+ try {
250
+ base = await realpath(folder);
251
+ }
252
+ catch {
253
+ return undefined;
254
+ }
255
+ const inside = insideOf(base);
256
+ const markdownNames = async (part) => {
257
+ const dir = await inside(join(folder, part));
258
+ if (dir === undefined)
259
+ return [];
260
+ try {
261
+ return (await readdir(dir, { withFileTypes: true }))
262
+ .filter((entry) => entry.isFile() && entry.name.endsWith('.md') && !entry.name.startsWith('.'))
263
+ .map((entry) => entry.name.slice(0, -'.md'.length).trim());
264
+ }
265
+ catch {
266
+ return [];
267
+ }
268
+ };
269
+ let events = [];
270
+ const hooksFile = await inside(join(folder, 'hooks', 'hooks.json'));
271
+ if (hooksFile !== undefined) {
272
+ events = hookEvents(await readJson(hooksFile, MAX_MANIFEST_BYTES).catch(() => undefined));
273
+ }
274
+ const commands = partNames(await markdownNames('commands'), 256);
275
+ const agents = partNames(await markdownNames('agents'), 256);
276
+ const hooks = partNames(events, 64);
277
+ if (commands.length === 0 && agents.length === 0 && hooks.length === 0)
278
+ return undefined;
279
+ return {
280
+ ...(commands.length > 0 ? { commands } : {}),
281
+ ...(agents.length > 0 ? { agents } : {}),
282
+ ...(hooks.length > 0 ? { hooks } : {}),
283
+ };
284
+ }
285
+ /** Every `<name>/SKILL.md` directly under a skills folder, following linked folders to their targets. */
286
+ async function skillFolders(parent, skip = new Set()) {
287
+ let entries;
288
+ try {
289
+ entries = (await readdir(parent, { withFileTypes: true })).slice(0, MAX_SKILLS_PER_FOLDER);
290
+ }
291
+ catch {
292
+ return [];
293
+ }
294
+ const found = [];
295
+ for (const entry of entries) {
296
+ if (entry.name.startsWith('.') || skip.has(entry.name))
297
+ continue;
298
+ const folder = join(parent, entry.name);
299
+ let linkTarget;
300
+ try {
301
+ if ((await lstat(folder)).isSymbolicLink())
302
+ linkTarget = resolve(dirname(folder), await readlink(folder));
303
+ if (!(await stat(folder)).isDirectory())
304
+ continue;
305
+ }
306
+ catch {
307
+ continue;
308
+ }
309
+ const markdown = await readText(join(folder, 'SKILL.md'));
310
+ if (markdown === undefined)
311
+ continue;
312
+ const frontmatter = parseSkillFrontmatter(markdown);
313
+ found.push({
314
+ folder,
315
+ name: entry.name,
316
+ ...(frontmatter.description ? { description: frontmatter.description.slice(0, 2_048) } : {}),
317
+ ...(linkTarget ? { linkTarget } : {}),
318
+ });
319
+ }
320
+ return found.sort((a, b) => a.name.localeCompare(b.name));
321
+ }
322
+ /** The folder Claude Code reads a person's skills from in one profile, the account's `synced/` inside it. */
323
+ function skillsFolder(profile) {
324
+ return join(profile.dataRoot, 'skills');
325
+ }
326
+ function skillItem(skill, fields) {
327
+ return {
328
+ kind: 'skill',
329
+ ...fields,
330
+ name: skill.name.slice(0, 256),
331
+ location: skill.folder,
332
+ ...(skill.description ? { description: skill.description } : {}),
333
+ ...(skill.linkTarget ? { linkTarget: skill.linkTarget } : {}),
334
+ };
335
+ }
336
+ /**
337
+ * A root's own installs by id (user scope): a project's or a local one belongs
338
+ * to a working tree. An id past Core's bound is no key Claude Code's install
339
+ * gives, and would fail the whole inventory's schema.
340
+ */
341
+ function userInstalls(installed) {
342
+ const found = new Map();
343
+ for (const [id, records] of Object.entries(rec(installed?.plugins) ?? {})) {
344
+ const record = (Array.isArray(records) ? records : [])
345
+ .map(rec)
346
+ .find((candidate) => candidate && text(candidate.scope) === 'user');
347
+ if (record && text(id) && id.length <= MAX_ID)
348
+ found.set(id, record);
349
+ }
350
+ return found;
351
+ }
352
+ /** Claude Code's own marketplace, which it adds itself the first time it starts in a root. */
353
+ const OFFICIAL_MARKETPLACE = 'claude-plugins-official';
354
+ const OFFICIAL_REPOSITORY = 'anthropics/claude-plugins-official';
355
+ const OFFICIAL_ADDRESS = /^https:\/\/github\.com\/anthropics\/claude-plugins-official(?:\.git)?\/?$/iu;
356
+ /**
357
+ * The marketplaces a root knows: the ones fetched for it, then the ones
358
+ * claude.ai added, the first by a name kept. Claude Code's own is `bundled`
359
+ * only from Anthropic's repository, since Claude Code refuses its name to any
360
+ * other source. A list file that exists and cannot be read is named.
361
+ */
362
+ async function knownMarketplaces(pluginsRoot) {
363
+ const marketplaces = [];
364
+ const unreadable = [];
365
+ const named = new Set();
366
+ for (const [file, origin] of [
367
+ ['known_marketplaces.json', 'own'],
368
+ ['known_marketplaces_claudeai.json', 'managed'],
369
+ ]) {
370
+ let document;
371
+ try {
372
+ document = await readJson(join(pluginsRoot, file), MAX_MANIFEST_BYTES * 4);
373
+ }
374
+ catch {
375
+ unreadable.push(file);
376
+ }
377
+ for (const [key, value] of Object.entries(document ?? {})) {
378
+ const entry = rec(value);
379
+ if (!entry || !text(key) || key.length > MAX_ID || named.has(key))
380
+ continue;
381
+ named.add(key);
382
+ const source = rec(entry.source);
383
+ const url = text(source?.url);
384
+ const repo = text(source?.repo);
385
+ const path = repo === undefined && url === undefined ? text(source?.path) : undefined;
386
+ const from = bounded(repo ?? path ?? (url ? describeMcpUrl(url) : undefined));
387
+ // a listing shows where the clone is; no path past Core's bound is one a disk takes anyway
388
+ const location = bounded(text(entry.installLocation));
389
+ const updatedAt = text(entry.lastUpdated);
390
+ const official = origin === 'own' &&
391
+ key === OFFICIAL_MARKETPLACE &&
392
+ (repo !== undefined
393
+ ? repo.toLowerCase() === OFFICIAL_REPOSITORY
394
+ : url !== undefined && OFFICIAL_ADDRESS.test(url));
395
+ marketplaces.push({
396
+ key,
397
+ origin: official ? 'bundled' : origin,
398
+ ...(from ? { source: from } : {}),
399
+ ...(updatedAt && ISO_WITH_OFFSET.test(updatedAt) ? { updatedAt } : {}),
400
+ ...(location ? { location } : {}),
401
+ ...(path ? { path } : {}),
402
+ });
403
+ }
404
+ }
405
+ return { marketplaces, unreadable };
406
+ }
407
+ /**
408
+ * One marketplace's catalog as Claude Code last fetched it: the
409
+ * `.claude-plugin/marketplace.json` in its clone or its folder, or the file
410
+ * itself for a source that is one (its plugins' folders are beside that
411
+ * `.claude-plugin/`). One that is not there, too large or no catalog is said
412
+ * in words, never thrown.
413
+ */
414
+ async function readCatalog(location) {
415
+ const notFetched = { unread: 'Claude Code has not fetched its catalog' };
416
+ if (location === undefined || !isAbsolute(location))
417
+ return notFetched;
418
+ let file = join(location, '.claude-plugin', 'marketplace.json');
419
+ let folder = location;
420
+ let size;
421
+ try {
422
+ if (location.endsWith('.json') && (await stat(location)).isFile()) {
423
+ file = location;
424
+ folder = dirname(location);
425
+ if (basename(folder) === '.claude-plugin')
426
+ folder = dirname(folder);
427
+ }
428
+ size = (await stat(file)).size;
429
+ }
430
+ catch (error) {
431
+ const code = error.code;
432
+ return code === 'ENOENT' || code === 'ENOTDIR' ? notFetched : { unread: 'Its catalog could not be read' };
433
+ }
434
+ if (size > MAX_CATALOG_BYTES)
435
+ return { unread: 'Its catalog is larger than 4 MiB' };
436
+ let parsed;
437
+ try {
438
+ parsed = JSON.parse(await readFile(file, 'utf8'));
439
+ }
440
+ catch (error) {
441
+ return { unread: error instanceof SyntaxError ? 'Its catalog is not valid JSON' : 'Its catalog could not be read' };
442
+ }
443
+ const document = rec(parsed);
444
+ return document && Array.isArray(document.plugins)
445
+ ? { document, folder }
446
+ : { unread: 'Its catalog has no list of plugins' };
447
+ }
448
+ /** Sources Claude Code fetches from elsewhere at install: offline, only the entry says anything of them. */
449
+ const REMOTE_SOURCES = new Set(['github', 'url', 'git', 'git-subdir', 'npm', 'command', 'archive']);
450
+ const COMMIT = /^[0-9a-f]{40}$/iu;
451
+ /**
452
+ * Where a listed plugin comes from: a folder inside the marketplace (a path,
453
+ * `./review`, or an object naming one), or somewhere Claude Code fetches it
454
+ * from at install, with the commit the entry pins and what Claude Code asks
455
+ * first.
456
+ */
457
+ function entrySource(value) {
458
+ const path = text(value);
459
+ if (path !== undefined)
460
+ return { kind: 'folder', path };
461
+ const source = rec(value);
462
+ const type = text(source?.source);
463
+ if (!source || type === undefined)
464
+ return undefined;
465
+ if (!REMOTE_SOURCES.has(type) && text(source.path) !== undefined)
466
+ return { kind: 'folder', path: text(source.path) };
467
+ const sha = text(source.sha);
468
+ return {
469
+ kind: 'remote',
470
+ ...(sha !== undefined && COMMIT.test(sha) ? { sha: sha.toLowerCase() } : {}),
471
+ asks: sourceAsks(type, source),
472
+ };
473
+ }
474
+ /**
475
+ * What Claude Code asks, or runs, before a remote plugin's code is there: a
476
+ * command source's command, which it shows and asks the person to accept, and
477
+ * an npm package, which npm fetches with its install scripts.
478
+ */
479
+ function sourceAsks(type, source) {
480
+ if (type === 'command') {
481
+ // Claude Code still asks when the command is one this read cannot show
482
+ return [{ kind: 'command', command: sourceCommand(source) ?? 'a command its catalog names' }];
483
+ }
484
+ const name = type === 'npm' ? text(source.package) : undefined;
485
+ if (name === undefined)
486
+ return [];
487
+ const version = text(source.version);
488
+ const command = describeMcpCommand('npm', ['install', version === undefined ? name : `${name}@${version}`]);
489
+ return [{ kind: 'fetch', command: command.slice(0, MAX_SHOWN) }];
490
+ }
491
+ /**
492
+ * A command source's command as a person reads it before accepting it: a line
493
+ * word by word, or the catalog's own arguments — word by word where a word
494
+ * inside one is masked, so nothing secret shows in a quoted argument.
495
+ */
496
+ function sourceCommand(source) {
497
+ const argv = Array.isArray(source.command)
498
+ ? strings(source.command)
499
+ : text(source.command) !== undefined
500
+ ? [text(source.command), ...strings(source.args)]
501
+ : [];
502
+ const words = argv.flatMap((arg) => arg.split(/\s+/u)).filter((word) => word.length > 0);
503
+ if (words.length === 0)
504
+ return undefined;
505
+ const byWord = describeMcpCommand(words[0], words.slice(1));
506
+ const shown = argv.length === 1 || byWord !== describeArgv(words) ? byWord : describeMcpCommand(argv[0], argv.slice(1));
507
+ return shown.slice(0, MAX_SHOWN);
508
+ }
509
+ const serverNames = (servers) => Object.entries(servers)
510
+ .filter(([, definition]) => rec(definition) !== undefined)
511
+ .map(([name]) => name);
512
+ /**
513
+ * What a catalog entry names itself: its commands and agents by file
514
+ * (`./commands/ship.md`; a folder names none) or by key where it maps names,
515
+ * the events of its inline hooks and its inline servers — all a remote entry
516
+ * says before it is fetched, and what an entry adds to its folder.
517
+ */
518
+ function entryParts(entry) {
519
+ const files = (value) => rec(value) !== undefined
520
+ ? Object.keys(rec(value))
521
+ : (typeof value === 'string' ? [value] : strings(value))
522
+ .map((path) => basename(path.trim()))
523
+ .filter((file) => file.endsWith('.md') && !file.startsWith('.'))
524
+ .map((file) => file.slice(0, -'.md'.length));
525
+ return {
526
+ commands: files(entry.commands),
527
+ agents: files(entry.agents),
528
+ hooks: hookEvents(rec(entry.hooks)),
529
+ servers: serverNames(pluginServers(entry, undefined)),
530
+ };
531
+ }
532
+ /** The skills a plugin's folder brings, by folder name: each `skills/<name>/SKILL.md` that stays inside it. */
533
+ async function skillNames(folder, inside) {
534
+ const skills = await inside(join(folder, 'skills'));
535
+ if (skills === undefined)
536
+ return [];
537
+ let entries;
538
+ try {
539
+ entries = (await readdir(skills)).slice(0, MAX_SKILLS_PER_FOLDER);
540
+ }
541
+ catch {
542
+ return [];
543
+ }
544
+ const names = [];
545
+ for (const name of entries) {
546
+ if (name.startsWith('.'))
547
+ continue;
548
+ const markdown = await inside(join(skills, name, 'SKILL.md'));
549
+ const isFile = markdown === undefined
550
+ ? false
551
+ : await stat(markdown).then((found) => found.isFile(), () => false);
552
+ if (isFile)
553
+ names.push(name);
554
+ }
555
+ return names;
556
+ }
557
+ /**
558
+ * A listed plugin's folder inside its marketplace, read before it is
559
+ * installed: its manifest, and the names of what it brings — commands, agents,
560
+ * hook events, servers and skills. Only a folder inside the marketplace's is
561
+ * read, and inside it nothing that leads out of it.
562
+ */
563
+ async function listedFolder(folder, marketplace) {
564
+ const real = await marketplace(folder);
565
+ if (real === undefined)
566
+ return { parts: {} };
567
+ const inside = insideOf(real);
568
+ const json = async (path) => {
569
+ const found = await inside(path);
570
+ return found === undefined ? undefined : readJson(found, MAX_MANIFEST_BYTES).catch(() => undefined);
571
+ };
572
+ const manifest = await json(join(real, '.claude-plugin', 'plugin.json'));
573
+ const dotMcp = await json(join(real, '.mcp.json'));
574
+ return {
575
+ ...(manifest ? { manifest } : {}),
576
+ parts: {
577
+ ...(await pluginParts(real)),
578
+ servers: serverNames(pluginServers(manifest, dotMcp)),
579
+ skills: await skillNames(real, inside),
580
+ },
581
+ };
582
+ }
583
+ const PART_BOUNDS = {
584
+ commands: 256,
585
+ agents: 256,
586
+ hooks: 64,
587
+ servers: 64,
588
+ skills: 256,
589
+ tools: 256,
590
+ };
591
+ /** What a listed plugin brings, as a listing shows it: each kind's names once, sorted, within Core's bounds. */
592
+ function catalogParts(...found) {
593
+ const parts = {};
594
+ for (const kind of Object.keys(PART_BOUNDS)) {
595
+ const names = partNames(found.flatMap((one) => [...(one[kind] ?? [])]), PART_BOUNDS[kind]);
596
+ if (names.length > 0)
597
+ parts[kind] = names;
598
+ }
599
+ return Object.keys(parts).length > 0 ? parts : undefined;
600
+ }
601
+ /** Claude Code's version of a plugin: its manifest's or its entry's, else a 12-hex digest of what it fetched, or `unknown`. */
602
+ const DIGEST = /^[0-9a-f]{12}$/iu;
603
+ const versionKind = (version) => version === 'unknown' ? 'unknown' : DIGEST.test(version) ? 'digest' : 'version';
604
+ /**
605
+ * Whether the copy a root holds is older than its catalog's, by Claude Code's
606
+ * own rule: `claude plugin update` takes any version that is not the one
607
+ * installed. A commit the entry pins decides against the commit installed;
608
+ * else two versions of one kind (two semvers, two digests) that differ — a
609
+ * digest against a semver, or `unknown`, says nothing.
610
+ */
611
+ function newerListed(version, sha, record) {
612
+ const commit = text(record.gitCommitSha)?.toLowerCase();
613
+ if (sha !== undefined && commit !== undefined && /^[0-9a-f]{7,40}$/u.test(commit))
614
+ return !sha.startsWith(commit);
615
+ const held = text(record.version);
616
+ if (version === undefined || held === undefined)
617
+ return false;
618
+ const kind = versionKind(version);
619
+ return kind !== 'unknown' && kind === versionKind(held) && version !== held;
620
+ }
621
+ /**
622
+ * The plugins Claude Code took out because their marketplace flagged them
623
+ * (`plugins/flagged-plugins.json`), by id. Its shape is not documented: a list
624
+ * of ids or of `{ plugin }` rows, or an object keyed by id, alone or under
625
+ * `plugins`.
626
+ */
627
+ function flaggedPlugins(value) {
628
+ const ids = new Set();
629
+ const add = (candidate) => {
630
+ const id = text(candidate) ?? text(rec(candidate)?.plugin) ?? text(rec(candidate)?.id);
631
+ if (id !== undefined)
632
+ ids.add(id);
633
+ };
634
+ const listed = Array.isArray(value) ? value : (rec(value)?.plugins ?? value);
635
+ if (Array.isArray(listed))
636
+ listed.forEach(add);
637
+ else
638
+ Object.keys(rec(listed) ?? {}).forEach(add);
639
+ return ids;
640
+ }
641
+ /**
642
+ * A declared marketplace's source as Claude Code's own add takes it: a
643
+ * repository or a git address with the ref it names, or an absolute folder —
644
+ * never an address a listing would mask.
645
+ */
646
+ function addableSource(source) {
647
+ const ref = text(source?.ref);
648
+ const pinned = (from) => (ref === undefined ? from : `${from}#${ref}`);
649
+ const repo = text(source?.repo);
650
+ const url = text(source?.url);
651
+ const path = text(source?.path);
652
+ const candidate = repo !== undefined
653
+ ? pinned(repo)
654
+ : url !== undefined
655
+ ? describeMcpUrl(url) === url
656
+ ? pinned(url)
657
+ : undefined
658
+ : path !== undefined && isAbsolute(path)
659
+ ? path
660
+ : undefined;
661
+ return candidate !== undefined && isExtensionSource(candidate) ? candidate : undefined;
662
+ }
663
+ /**
664
+ * The plugins one catalog lists, each by the key Claude Code installs it by
665
+ * (`<entry name>@<marketplace>`): an entry needs a name and a source, and a
666
+ * second by one name is skipped. Only the first entries' folders are read,
667
+ * and every held one's, whose version decides `newer`; the rest show what
668
+ * their entry says. A catalog that lists more than `room` plugins does not fit
669
+ * beside the others: undefined, known one entry past the room, before any
670
+ * folder is read.
671
+ */
672
+ async function listedPlugins(key, read, context, room) {
673
+ const entries = [];
674
+ const seen = new Set();
675
+ for (const value of read.document.plugins) {
676
+ const entry = rec(value);
677
+ const name = text(entry?.name);
678
+ const source = entry === undefined ? undefined : entrySource(entry.source);
679
+ if (entry === undefined || name === undefined || source === undefined)
680
+ continue;
681
+ const id = `${name}@${key}`;
682
+ if (name.length > 256 || id.length > MAX_ID || seen.has(id))
683
+ continue;
684
+ seen.add(id);
685
+ entries.push({ entry, name, id, source });
686
+ if (entries.length > room)
687
+ return undefined;
688
+ }
689
+ const real = await realpath(read.folder).catch(() => undefined);
690
+ const marketplace = real === undefined ? async () => undefined : insideOf(real);
691
+ // `metadata.pluginRoot` goes before every relative source
692
+ const pluginRoot = text(rec(read.document.metadata)?.pluginRoot) ?? '.';
693
+ const listed = [];
694
+ for (let start = 0; start < entries.length; start += 16) {
695
+ const batch = entries
696
+ .slice(start, start + 16)
697
+ .map(async ({ entry, name, id, source }, offset) => {
698
+ const record = context.installed.get(id);
699
+ const folder = source.kind === 'folder' && (start + offset < MAX_CATALOG_FOLDERS || record !== undefined)
700
+ ? await listedFolder(resolve(read.folder, pluginRoot, source.path), marketplace)
701
+ : { parts: {} };
702
+ const manifest = folder.manifest;
703
+ // the manifest's version is Claude Code's first choice, the entry's its next
704
+ const version = [text(manifest?.version), text(entry.version)].find((candidate) => candidate !== undefined && candidate.length <= 128);
705
+ // the entry speaks for the listing; the manifest where it is silent
706
+ const description = text(entry.description) ?? text(manifest?.description);
707
+ const category = text(entry.category);
708
+ const author = authorOf(entry) ?? authorOf(manifest);
709
+ const homepage = homepageOf(entry) ?? homepageOf(manifest);
710
+ const brings = catalogParts(folder.parts, entryParts(entry));
711
+ const asks = source.kind === 'remote' ? source.asks : [];
712
+ const newer = record !== undefined && newerListed(version, source.kind === 'remote' ? source.sha : undefined, record);
713
+ return {
714
+ id,
715
+ name,
716
+ marketplace: key,
717
+ ...(description ? { description: description.slice(0, 2_048) } : {}),
718
+ ...(author ? { author } : {}),
719
+ ...(category && category.length <= 64 ? { category } : {}),
720
+ ...(version ? { version } : {}),
721
+ ...(homepage ? { homepage } : {}),
722
+ ...(brings ? { brings } : {}),
723
+ ...(asks.length > 0 ? { asks } : {}),
724
+ ...(context.flagged.has(id) ? { blocked: 'Claude Code flagged it and took it out' } : {}),
725
+ ...(record !== undefined ? { held: id } : {}),
726
+ ...(newer ? { newer: true } : {}),
727
+ };
728
+ });
729
+ listed.push(...(await Promise.all(batch)));
730
+ }
731
+ return listed;
732
+ }
733
+ /** Claude Code extensions capability: its own store files, per profile root. */
734
+ export function createClaudeExtensionService(options = {}) {
735
+ const home = options.home ?? homedir();
736
+ const now = options.now ?? (() => new Date());
737
+ const provider = {
738
+ id: 'claude',
739
+ label: 'Claude',
740
+ support: {
741
+ // installed only from a marketplace, whose catalog it keeps: `--plugin-dir` loads a folder for one
742
+ // session, never into a root
743
+ plugins: { store: 'profile', changes: 'command', read: true, catalog: true },
744
+ marketplaces: {
745
+ store: 'profile',
746
+ changes: 'command',
747
+ read: true,
748
+ sources: 'A GitHub repository (owner/repo), a git address, a folder, or the address of a marketplace.json',
749
+ },
750
+ mcpServers: { store: 'profile', changes: 'command', read: true },
751
+ skills: { store: 'profile', changes: 'folder', read: true },
752
+ },
753
+ };
754
+ const executable = resolveClaudeExecutable(options.executable, options.env ?? process.env);
755
+ // Acts (RFC 006 C2): Claude Code has no switch that turns a server off for a
756
+ // whole profile (`/mcp` does it one project at a time), so a user server is
757
+ // only removed — `claude mcp remove --scope user <name>`, which also deletes
758
+ // a remote server's stored sign-in. A skill's switch is a settings key. A
759
+ // remote server signs in with `claude mcp login <name>` (a browser, so a
760
+ // terminal) and out with `claude mcp logout <name>`: the report's shell
761
+ // forms, not probed. The sign-in lands in the root's own keychain item, and
762
+ // no read here can see it (the keychain is never opened).
763
+ //
764
+ // An add is the report's `claude mcp add <name> -- <command> [args…]`, or
765
+ // `<name> <url>` with `--transport http|sse`, at user scope, the name first
766
+ // because `-e` takes every word after it; each variable goes in as
767
+ // `-e NAME=${NAME:-}`, never its value, since Claude Code expands `${VAR}` in
768
+ // command, args, env, url and headers from its own environment when it loads
769
+ // the server. The empty default is there because Claude Code refuses a config
770
+ // naming a variable it has no value and no default for: a Claude started
771
+ // without the host's values keeps its other servers, and this one gets none.
772
+ // The report's forms, not probed.
773
+ //
774
+ // A skill a host keeps is linked into the root's `skills/`, which Claude Code
775
+ // follows ("Symlinked skill folders in those three locations are read from
776
+ // the target and loaded once", its skills docs); a person's own goes as a
777
+ // link taken away, or a folder moved to where the host keeps it.
778
+ //
779
+ // A plugin the root installed turns on and off with `claude plugin
780
+ // enable|disable <id>`, updates to the newest its marketplace has with
781
+ // `claude plugin update <id>`, and goes with `claude plugin uninstall <id>`,
782
+ // which, once no scope holds it, deletes what it stored in
783
+ // `plugins/data/<id>/` unless given `--keep-data`: a remove keeps that data,
784
+ // a purge does not. The forms are the report's
785
+ // (draft/CLAUDE-PLUGINS-SKILLS-MCP.md: `claude plugin
786
+ // install|uninstall|enable|disable|update`, the data folder's `--keep-data`,
787
+ // the install scopes), not probed. Each runs at `--scope user`, since only
788
+ // the root's own user-scope install is the profile's; a project's or a local
789
+ // one belongs to a working tree.
790
+ //
791
+ // A plugin a catalog lists installs with `claude plugin install <name>@<marketplace>`.
792
+ // An install and an update take `-y`, which Claude Code requires "when stdin
793
+ // or stdout is not a TTY" (RFC 006's resolved question 6, from 2.1.263's
794
+ // help); without it, an act the runtime runs is refused. `-y` is a blanket
795
+ // yes, though: it would also accept, unseen, the command a marketplace runs
796
+ // to fetch a plugin, so a plugin with that source installs in a terminal
797
+ // without it, where the person answers Claude Code's own prompt. A marketplace
798
+ // is added with `claude plugin marketplace add <source>`, fetched again with
799
+ // `update <name>` and removed with `remove <name>`, which uninstalls the
800
+ // plugins installed from it — the report's forms, not probed, and given no
801
+ // `-y`, which an option parser would refuse where the command has none.
802
+ const profileEnv = (profile) => profile.kind === 'managed' ? { [CLAUDE_PROFILE_ROOT_VARIABLE]: profile.dataRoot } : {};
803
+ // Grok and OpenCode also load the skills in the home's `~/.claude/skills`
804
+ // whatever their own profile, so a skill placed in or taken from the native
805
+ // default's reaches them; a managed root's folder is its own.
806
+ const borrowedSkills = join(home, '.claude', 'skills');
807
+ function planSkill(profile, item, act, keepIn) {
808
+ // `skills/synced` is the account's synced skills, which Claude Code writes
809
+ // itself; a case-folding disk (macOS's, Windows') takes `Synced` for it too.
810
+ if (act === 'add' && item.id.toLowerCase() === 'synced') {
811
+ return extensionActUnavailable({ kind: 'skill', id: item.id }, act, 'unsupported', "Claude Code keeps your account's synced skills in skills/synced");
812
+ }
813
+ const folder = skillsFolder(profile);
814
+ return extensionSkillFolderPlan({
815
+ label: 'Claude Code',
816
+ folder,
817
+ item,
818
+ act,
819
+ ...(keepIn === undefined ? {} : { keepIn }),
820
+ reaches: folder === borrowedSkills ? ['shared-folder'] : [],
821
+ home,
822
+ });
823
+ }
824
+ /** A user server lands in the profile's own app state, which no other profile reads. */
825
+ function planAdd(profile, item) {
826
+ const target = { kind: item.kind, id: item.id };
827
+ const unsupported = (message) => extensionActUnavailable(target, 'add', 'unsupported', message);
828
+ const definition = item.definition;
829
+ if (definition === undefined)
830
+ return unsupported('Claude Code adds a server only from its command line or address');
831
+ if (!EXTENSION_COMMAND_NAME.test(item.id)) {
832
+ return extensionActUnavailable(target, 'add', 'no-command', "Claude Code's commands do not take this server's name");
833
+ }
834
+ const add = [executable, 'mcp', 'add', item.id];
835
+ let argv;
836
+ switch (definition.transport) {
837
+ case 'stdio':
838
+ argv = [
839
+ ...add,
840
+ '--scope',
841
+ 'user',
842
+ ...(definition.env ?? []).flatMap((name) => ['-e', `${name}=\${${name}:-}`]),
843
+ '--',
844
+ definition.command,
845
+ ...definition.args,
846
+ ];
847
+ break;
848
+ case 'http':
849
+ case 'sse':
850
+ if (!REMOTE_ADDRESS.test(definition.url)) {
851
+ return unsupported('Claude Code reaches a remote server only at an address');
852
+ }
853
+ argv = [...add, definition.url, '--scope', 'user', '--transport', definition.transport];
854
+ break;
855
+ default:
856
+ return unsupported("Claude Code's mcp add takes a stdio, HTTP or SSE server");
857
+ }
858
+ return extensionCommandPlan({ target, act: 'add', argv, env: profileEnv(profile), reaches: [] });
859
+ }
860
+ function planPlugin(profile, item, act, options) {
861
+ const target = { kind: item.kind, id: item.id };
862
+ if (item.origin !== 'own') {
863
+ // `<folder>@synced`: the account's, downloaded from claude.ai with no install record of the root's
864
+ return extensionActUnavailable(target, act, 'not-own', item.origin === 'managed'
865
+ ? 'It comes with your Claude account, from claude.ai, and changes there'
866
+ : extensionNotOwnWords('Claude Code', item));
867
+ }
868
+ if (act === 'add') {
869
+ return extensionActUnavailable(target, act, 'unsupported', 'Claude Code installs a plugin from its marketplace');
870
+ }
871
+ if (act === 'sign-in' || act === 'sign-out') {
872
+ return extensionActUnavailable(target, act, 'unsupported', 'Claude Code has no sign-in for a plugin');
873
+ }
874
+ if (act === 'install' && options.source !== undefined) {
875
+ return extensionActUnavailable(target, act, 'unsupported', 'Claude Code installs a plugin from a marketplace; `--plugin-dir` loads a folder for one session only');
876
+ }
877
+ if (!EXTENSION_PLUGIN_NAME.test(item.id)) {
878
+ return extensionActUnavailable(target, act, act === 'install' ? 'unsupported' : 'no-command', "Claude Code's commands do not take this plugin's name");
879
+ }
880
+ const scoped = (verb, ...flags) => [
881
+ executable,
882
+ 'plugin',
883
+ verb,
884
+ item.id,
885
+ '--scope',
886
+ 'user',
887
+ ...flags,
888
+ ];
889
+ const env = profileEnv(profile);
890
+ // Grok loads every plugin in the home's own ~/.claude/plugins/installed_plugins.json, in each of its
891
+ // profiles and whatever enabledPlugins says: an install, an uninstall or an update in the native default
892
+ // reaches it, a switch does not. A managed root's plugins are its own.
893
+ const shared = profile.kind === 'managed' ? [] : ['shared-folder'];
894
+ if (act === 'install') {
895
+ // a marketplace that fetches it by running a command: the person accepts that command at Claude Code's prompt
896
+ if (options.listed?.asks?.some((ask) => ask.kind === 'command') === true) {
897
+ return extensionTerminalPlan({ target, act, argv: scoped('install'), env, reaches: shared });
898
+ }
899
+ return extensionCommandPlan({ target, act, argv: scoped('install', '-y'), env, reaches: shared });
900
+ }
901
+ const argv = act === 'remove'
902
+ ? scoped('uninstall', '--keep-data')
903
+ : act === 'purge'
904
+ ? scoped('uninstall')
905
+ : act === 'update'
906
+ ? scoped('update', '-y')
907
+ : scoped(act);
908
+ const reaches = act === 'remove' || act === 'purge' || act === 'update' ? shared : [];
909
+ return extensionCommandPlan({ target, act, argv, env, reaches });
910
+ }
911
+ /** A marketplace is added from a source, fetched again or removed, each with Claude Code's own command. */
912
+ function planMarketplace(profile, item, act) {
913
+ const target = { kind: item.kind, id: item.id };
914
+ if (act !== 'add' && act !== 'update' && act !== 'remove') {
915
+ return extensionActUnavailable(target, act, 'unsupported', 'Claude Code adds, fetches and removes a marketplace; it has no switch for one');
916
+ }
917
+ const env = profileEnv(profile);
918
+ const marketplace = (verb, argument) => [executable, 'plugin', 'marketplace', verb, argument];
919
+ // Grok lists the git marketplaces in the home's own ~/.claude/plugins/known_marketplaces.json in every
920
+ // profile of its own; a managed root's are its own.
921
+ const shared = profile.kind === 'managed' ? [] : ['shared-folder'];
922
+ if (act === 'add') {
923
+ // the runtime names a marketplace it adds by its source, until Claude Code names it from its catalog
924
+ if (item.source === undefined || !isExtensionSource(item.source)) {
925
+ return extensionActUnavailable(target, act, 'unsupported', 'Claude Code adds a marketplace from a repository, a git address, a folder or an address');
926
+ }
927
+ return extensionCommandPlan({ target, act, argv: marketplace('add', item.source), env, reaches: shared });
928
+ }
929
+ if (item.origin === 'managed') {
930
+ return extensionActUnavailable(target, act, 'not-own', 'It comes with your Claude account, from claude.ai, and changes there');
931
+ }
932
+ // Claude Code's own marketplace is the person's to fetch or remove like any other
933
+ if (item.origin !== 'own' && item.origin !== 'bundled') {
934
+ return extensionActUnavailable(target, act, 'not-own', extensionNotOwnWords('Claude Code', item));
935
+ }
936
+ if (!COMMAND_ARGUMENT.test(item.id)) {
937
+ return extensionActUnavailable(target, act, 'unsupported', "Claude Code's commands do not take this marketplace's name");
938
+ }
939
+ if (act === 'update') {
940
+ return extensionCommandPlan({ target, act, argv: marketplace('update', item.id), env, reaches: shared });
941
+ }
942
+ // a marketplace's removal uninstalls every plugin installed from it
943
+ return extensionCommandPlan({
944
+ target,
945
+ act,
946
+ argv: marketplace('remove', item.id),
947
+ env,
948
+ reaches: ['plugins', ...shared],
949
+ });
950
+ }
951
+ /** Installed, updated, and removed with its data: a plugin's acts alone. */
952
+ const PLUGIN_ONLY = {
953
+ install: 'Claude Code installs only plugins',
954
+ update: 'Claude Code updates only plugins',
955
+ purge: 'Claude Code removes only a plugin with its data',
956
+ };
957
+ function plan(profile, item, act, options = {}) {
958
+ if (item.kind === 'plugin')
959
+ return planPlugin(profile, item, act, options);
960
+ if (item.kind === 'marketplace')
961
+ return planMarketplace(profile, item, act);
962
+ const pluginOnly = PLUGIN_ONLY[act];
963
+ if (pluginOnly !== undefined) {
964
+ return extensionActUnavailable({ kind: item.kind, id: item.id }, act, 'unsupported', pluginOnly);
965
+ }
966
+ if (item.kind === 'skill') {
967
+ if (act === 'add' || act === 'remove')
968
+ return planSkill(profile, item, act, options.keepIn);
969
+ }
970
+ else if (act === 'add') {
971
+ // an add plans from the server as Claude Code would hold it once added, always its own
972
+ return planAdd(profile, item);
973
+ }
974
+ const target = { kind: item.kind, id: item.id };
975
+ if (item.origin !== 'own') {
976
+ return extensionActUnavailable(target, act, 'not-own', extensionNotOwnWords('Claude Code', item));
977
+ }
978
+ if (item.kind === 'skill') {
979
+ return extensionActUnavailable(target, act, 'no-command', 'Claude Code turns a skill off only in its settings');
980
+ }
981
+ if (act === 'enable' || act === 'disable') {
982
+ return extensionActUnavailable(target, act, 'no-command', 'Claude Code has no switch for a whole profile: /mcp turns a server off one project at a time');
983
+ }
984
+ const absent = act === 'remove' ? undefined : extensionSignInAbsentWords('Claude Code', item);
985
+ if (absent !== undefined)
986
+ return extensionActUnavailable(target, act, 'no-sign-in', absent);
987
+ if (!EXTENSION_COMMAND_NAME.test(item.id)) {
988
+ return extensionActUnavailable(target, act, 'no-command', "Claude Code's commands do not take this server's name");
989
+ }
990
+ const env = profileEnv(profile);
991
+ if (act === 'remove') {
992
+ return extensionCommandPlan({
993
+ target,
994
+ act,
995
+ argv: [executable, 'mcp', 'remove', '--scope', 'user', item.id],
996
+ env,
997
+ reaches: item.transport === 'stdio' ? ['definition'] : ['definition', 'sign-in'],
998
+ });
999
+ }
1000
+ const fields = { target, act, argv: [executable, 'mcp', act === 'sign-in' ? 'login' : 'logout', item.id], env };
1001
+ return act === 'sign-in' ? extensionTerminalPlan(fields) : extensionCommandPlan(fields);
1002
+ }
1003
+ return {
1004
+ provider,
1005
+ plan,
1006
+ async inventory(profile) {
1007
+ const root = profile.dataRoot;
1008
+ // The native default keeps its app state beside its root, not inside it.
1009
+ const appState = profile.kind === 'managed' ? join(root, '.claude.json') : join(home, '.claude.json');
1010
+ const pluginsRoot = join(root, 'plugins');
1011
+ const items = [];
1012
+ const unread = [];
1013
+ const cannotRead = (kind, what) => {
1014
+ if (!unread.some((entry) => entry.kind === kind))
1015
+ unread.push({ kind, message: `${what} could not be read` });
1016
+ };
1017
+ let settings;
1018
+ try {
1019
+ settings = await readJson(join(root, 'settings.json'), MAX_MANIFEST_BYTES * 4);
1020
+ }
1021
+ catch {
1022
+ cannotRead('plugin', 'settings.json');
1023
+ }
1024
+ const enabledPlugins = rec(settings?.enabledPlugins) ?? {};
1025
+ const skillOverrides = rec(settings?.skillOverrides) ?? {};
1026
+ // Marketplaces: the ones fetched for this root, and the ones claude.ai added.
1027
+ const known = await knownMarketplaces(pluginsRoot);
1028
+ for (const file of known.unreadable)
1029
+ cannotRead('marketplace', file);
1030
+ for (const marketplace of known.marketplaces) {
1031
+ items.push({
1032
+ kind: 'marketplace',
1033
+ id: marketplace.key,
1034
+ name: marketplace.key.slice(0, 256),
1035
+ origin: marketplace.origin,
1036
+ enabled: true,
1037
+ ...(marketplace.source ? { source: marketplace.source } : {}),
1038
+ ...(marketplace.updatedAt ? { updatedAt: marketplace.updatedAt } : {}),
1039
+ ...(marketplace.location ? { location: marketplace.location } : {}),
1040
+ });
1041
+ }
1042
+ // Plugins installed for this root (user scope), and the account's synced ones.
1043
+ const plugins = [];
1044
+ let installed;
1045
+ try {
1046
+ installed = await readJson(join(pluginsRoot, 'installed_plugins.json'), MAX_MANIFEST_BYTES * 8);
1047
+ }
1048
+ catch {
1049
+ cannotRead('plugin', 'installed_plugins.json');
1050
+ }
1051
+ for (const [id, record] of userInstalls(installed)) {
1052
+ const [name, marketplace] = id.split('@');
1053
+ const version = text(record.version);
1054
+ const location = bounded(text(record.installPath));
1055
+ plugins.push({
1056
+ item: {
1057
+ kind: 'plugin',
1058
+ id,
1059
+ name: (name || id).slice(0, 256),
1060
+ origin: 'own',
1061
+ enabled: enabledPlugins[id] === true,
1062
+ ...(version ? { version: version.slice(0, 128) } : {}),
1063
+ ...(marketplace ? { marketplace } : {}),
1064
+ ...(location ? { location } : {}),
1065
+ },
1066
+ ...(text(record.installPath) ? { folder: text(record.installPath) } : {}),
1067
+ });
1068
+ }
1069
+ try {
1070
+ for (const entry of await readdir(join(pluginsRoot, 'synced'), { withFileTypes: true })) {
1071
+ if (entry.name.startsWith('.') || !entry.isDirectory())
1072
+ continue;
1073
+ const id = `${entry.name}@synced`;
1074
+ const folder = join(pluginsRoot, 'synced', entry.name);
1075
+ plugins.push({
1076
+ item: {
1077
+ kind: 'plugin',
1078
+ id,
1079
+ name: entry.name.slice(0, 256),
1080
+ origin: 'managed',
1081
+ enabled: true,
1082
+ location: folder,
1083
+ },
1084
+ folder,
1085
+ });
1086
+ }
1087
+ }
1088
+ catch {
1089
+ // No synced plugins: the account turned none on, or the root never signed in to claude.ai.
1090
+ }
1091
+ for (const { item, folder } of plugins) {
1092
+ let manifest;
1093
+ let dotMcp;
1094
+ // A plugin whose manifest or server file does not parse still counts as installed.
1095
+ if (folder) {
1096
+ manifest = await readJson(join(folder, '.claude-plugin', 'plugin.json'), MAX_MANIFEST_BYTES).catch(() => undefined);
1097
+ dotMcp = await readJson(join(folder, '.mcp.json'), MAX_MANIFEST_BYTES).catch(() => undefined);
1098
+ }
1099
+ const description = text(manifest?.description);
1100
+ const author = authorOf(manifest);
1101
+ const homepage = homepageOf(manifest);
1102
+ const brings = folder ? await pluginParts(folder) : undefined;
1103
+ items.push({
1104
+ ...item,
1105
+ ...(description ? { description: description.slice(0, 2_048) } : {}),
1106
+ ...(author ? { author } : {}),
1107
+ ...(homepage ? { homepage } : {}),
1108
+ ...(brings ? { brings } : {}),
1109
+ });
1110
+ if (!folder)
1111
+ continue;
1112
+ for (const [name, definition] of Object.entries(pluginServers(manifest, dotMcp))) {
1113
+ const server = serverItem(name, definition, {
1114
+ id: `plugin:${item.id}:${name}`,
1115
+ origin: 'plugin',
1116
+ enabled: item.enabled,
1117
+ plugin: item.id,
1118
+ });
1119
+ if (server)
1120
+ items.push(server);
1121
+ }
1122
+ for (const skill of await skillFolders(join(folder, 'skills'))) {
1123
+ items.push(skillItem(skill, {
1124
+ id: `plugin:${item.id}:${skill.name}`,
1125
+ origin: 'plugin',
1126
+ enabled: item.enabled,
1127
+ plugin: item.id,
1128
+ }));
1129
+ }
1130
+ }
1131
+ // Servers: this root's own, and the ones kept for one project.
1132
+ let state;
1133
+ try {
1134
+ state = await readJson(appState);
1135
+ }
1136
+ catch {
1137
+ cannotRead('mcp-server', '.claude.json');
1138
+ }
1139
+ for (const [name, definition] of Object.entries(rec(state?.mcpServers) ?? {})) {
1140
+ const server = serverItem(name, definition, { id: name, origin: 'own', enabled: true, location: appState });
1141
+ if (server)
1142
+ items.push(server);
1143
+ }
1144
+ for (const [project, value] of Object.entries(rec(state?.projects) ?? {})) {
1145
+ const entry = rec(value);
1146
+ const disabled = new Set(strings(entry?.disabledMcpServers));
1147
+ for (const [name, definition] of Object.entries(rec(entry?.mcpServers) ?? {})) {
1148
+ const server = serverItem(name, definition, {
1149
+ id: `project:${project}:${name}`,
1150
+ origin: 'project',
1151
+ enabled: !disabled.has(name),
1152
+ project,
1153
+ location: appState,
1154
+ });
1155
+ if (server)
1156
+ items.push(server);
1157
+ }
1158
+ }
1159
+ // Skills: the person's, then the account's synced ones.
1160
+ const skillOn = (name) => text(skillOverrides[name]) !== 'off';
1161
+ // the folder an act plans in, so a remove finds the skill a read found in it
1162
+ const skills = skillsFolder(profile);
1163
+ for (const skill of await skillFolders(skills, new Set(['synced']))) {
1164
+ items.push(skillItem(skill, { id: skill.name, origin: 'own', enabled: skillOn(skill.name) }));
1165
+ }
1166
+ for (const skill of await skillFolders(join(skills, 'synced'))) {
1167
+ items.push(skillItem(skill, { id: `synced:${skill.name}`, origin: 'managed', enabled: skillOn(skill.name) }));
1168
+ }
1169
+ return {
1170
+ provider: 'claude',
1171
+ profileId: profile.id,
1172
+ fetchedAt: now().toISOString(),
1173
+ items,
1174
+ ...(unread.length > 0 ? { unread } : {}),
1175
+ // The store files are Claude Code's own and undocumented as an interface.
1176
+ source: { kind: 'native-store', stability: 'experimental' },
1177
+ };
1178
+ },
1179
+ /**
1180
+ * What the root could install, from the catalogs Claude Code already
1181
+ * fetched: file reads only, so a catalog is as fresh as its marketplace's
1182
+ * `updatedAt`. A catalog that cannot be read is its marketplace's `unread`;
1183
+ * the list of marketplaces itself unread is a failure, since what the root
1184
+ * knows is that list.
1185
+ */
1186
+ async catalog(profile) {
1187
+ const root = profile.dataRoot;
1188
+ const pluginsRoot = join(root, 'plugins');
1189
+ const known = await knownMarketplaces(pluginsRoot);
1190
+ if (known.unreadable.length > 0) {
1191
+ return {
1192
+ status: 'unavailable',
1193
+ provider: 'claude',
1194
+ message: `${known.unreadable[0]} could not be read`,
1195
+ retryable: true,
1196
+ };
1197
+ }
1198
+ const settings = await readJson(join(root, 'settings.json'), MAX_MANIFEST_BYTES * 4).catch(() => undefined);
1199
+ const installed = await readJson(join(pluginsRoot, 'installed_plugins.json'), MAX_MANIFEST_BYTES * 8).catch(() => undefined);
1200
+ const flagged = await readJsonValue(join(pluginsRoot, 'flagged-plugins.json'), MAX_MANIFEST_BYTES * 4).catch(() => undefined);
1201
+ const context = { installed: userInstalls(installed), flagged: flaggedPlugins(flagged) };
1202
+ const marketplaces = [];
1203
+ const plugins = [];
1204
+ for (const marketplace of known.marketplaces.slice(0, MAX_CATALOG_MARKETPLACES)) {
1205
+ const listing = {
1206
+ id: marketplace.key,
1207
+ name: marketplace.key.slice(0, 256),
1208
+ origin: marketplace.origin,
1209
+ ...(marketplace.source ? { source: marketplace.source } : {}),
1210
+ ...(marketplace.updatedAt ? { updatedAt: marketplace.updatedAt } : {}),
1211
+ };
1212
+ // a folder or a marketplace.json source is read in place
1213
+ const read = await readCatalog(marketplace.location ?? marketplace.path);
1214
+ if ('unread' in read) {
1215
+ marketplaces.push({ ...listing, unread: read.unread });
1216
+ continue;
1217
+ }
1218
+ const listed = await listedPlugins(marketplace.key, read, context, MAX_CATALOG_PLUGINS - plugins.length);
1219
+ if (listed === undefined) {
1220
+ marketplaces.push({ ...listing, unread: 'It lists more plugins than can be shown beside the others' });
1221
+ continue;
1222
+ }
1223
+ marketplaces.push(listing);
1224
+ plugins.push(...listed);
1225
+ }
1226
+ // What Claude Code adds by itself when it next starts in this root, which the root does not know yet.
1227
+ const knownNames = new Set(known.marketplaces.map((marketplace) => marketplace.key));
1228
+ const suggested = knownNames.has(OFFICIAL_MARKETPLACE)
1229
+ ? []
1230
+ : [
1231
+ {
1232
+ name: OFFICIAL_MARKETPLACE,
1233
+ source: OFFICIAL_REPOSITORY,
1234
+ message: 'Claude Code adds claude-plugins-official the first time it starts in this profile',
1235
+ },
1236
+ ];
1237
+ for (const [name, declared] of Object.entries(rec(settings?.extraKnownMarketplaces) ?? {})) {
1238
+ if (suggested.length >= 4)
1239
+ break;
1240
+ if (!text(name) || name.length > 256 || knownNames.has(name) || suggested.some((one) => one.name === name)) {
1241
+ continue;
1242
+ }
1243
+ const source = addableSource(rec(rec(declared)?.source));
1244
+ suggested.push({
1245
+ name,
1246
+ ...(source ? { source } : {}),
1247
+ message: 'Claude Code fetches it the next time it starts',
1248
+ });
1249
+ }
1250
+ return {
1251
+ provider: 'claude',
1252
+ profileId: profile.id,
1253
+ fetchedAt: now().toISOString(),
1254
+ marketplaces,
1255
+ plugins,
1256
+ ...(suggested.length > 0 ? { suggested } : {}),
1257
+ // a marketplace.json is Claude Code's documented format for a catalog
1258
+ source: { kind: 'native-store', stability: 'documented' },
1259
+ };
1260
+ },
1261
+ };
1262
+ }
1263
+ //# sourceMappingURL=extensions.js.map