harnesstap 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/README.md +28 -15
  2. package/dist/apply-2GRNKR5H.js +67 -0
  3. package/dist/apply-2GRNKR5H.js.map +1 -0
  4. package/dist/approve-KQNCNH2R.js +181 -0
  5. package/dist/approve-KQNCNH2R.js.map +1 -0
  6. package/dist/audit-SLYOZCMI.js +434 -0
  7. package/dist/audit-SLYOZCMI.js.map +1 -0
  8. package/dist/auth-3IEVICFT.js +220 -0
  9. package/dist/auth-3IEVICFT.js.map +1 -0
  10. package/dist/bin.js +166 -0
  11. package/dist/bin.js.map +1 -0
  12. package/dist/chunk-2EIJYDNI.js +10945 -0
  13. package/dist/chunk-2EIJYDNI.js.map +1 -0
  14. package/dist/chunk-2H7UOFLK.js +11 -0
  15. package/dist/chunk-2H7UOFLK.js.map +1 -0
  16. package/dist/chunk-37E5M4JX.js +34 -0
  17. package/dist/chunk-37E5M4JX.js.map +1 -0
  18. package/dist/chunk-3FIWOI3H.js +98 -0
  19. package/dist/chunk-3FIWOI3H.js.map +1 -0
  20. package/dist/chunk-3IWTJCPA.js +6448 -0
  21. package/dist/chunk-3IWTJCPA.js.map +1 -0
  22. package/dist/chunk-3IZ7SEGT.js +346 -0
  23. package/dist/chunk-3IZ7SEGT.js.map +1 -0
  24. package/dist/chunk-3RBYT7QN.js +540 -0
  25. package/dist/chunk-3RBYT7QN.js.map +1 -0
  26. package/dist/chunk-4KNQZDZC.js +115 -0
  27. package/dist/chunk-4KNQZDZC.js.map +1 -0
  28. package/dist/chunk-5F3LNDZG.js +9 -0
  29. package/dist/chunk-5F3LNDZG.js.map +1 -0
  30. package/dist/chunk-63U7QWNY.js +364 -0
  31. package/dist/chunk-63U7QWNY.js.map +1 -0
  32. package/dist/chunk-6BY4BV5G.js +998 -0
  33. package/dist/chunk-6BY4BV5G.js.map +1 -0
  34. package/dist/chunk-7L2K4N25.js +610 -0
  35. package/dist/chunk-7L2K4N25.js.map +1 -0
  36. package/dist/chunk-7LWH5SWH.js +18 -0
  37. package/dist/chunk-7LWH5SWH.js.map +1 -0
  38. package/dist/chunk-BIBUCC2E.js +696 -0
  39. package/dist/chunk-BIBUCC2E.js.map +1 -0
  40. package/dist/chunk-BSOBXLYI.js +172 -0
  41. package/dist/chunk-BSOBXLYI.js.map +1 -0
  42. package/dist/chunk-C4QBVVEH.js +32 -0
  43. package/dist/chunk-C4QBVVEH.js.map +1 -0
  44. package/dist/chunk-CHQGE2HF.js +283 -0
  45. package/dist/chunk-CHQGE2HF.js.map +1 -0
  46. package/dist/chunk-DV74UZJI.js +87 -0
  47. package/dist/chunk-DV74UZJI.js.map +1 -0
  48. package/dist/chunk-DWVAR4BP.js +656 -0
  49. package/dist/chunk-DWVAR4BP.js.map +1 -0
  50. package/dist/chunk-DXKAKKLP.js +302 -0
  51. package/dist/chunk-DXKAKKLP.js.map +1 -0
  52. package/dist/chunk-EIWXS4RM.js +235 -0
  53. package/dist/chunk-EIWXS4RM.js.map +1 -0
  54. package/dist/chunk-EWBCFAF3.js +681 -0
  55. package/dist/chunk-EWBCFAF3.js.map +1 -0
  56. package/dist/chunk-F2L4VNQK.js +1759 -0
  57. package/dist/chunk-F2L4VNQK.js.map +1 -0
  58. package/dist/chunk-G26HZZDJ.js +1359 -0
  59. package/dist/chunk-G26HZZDJ.js.map +1 -0
  60. package/dist/chunk-GQKKX7OE.js +818 -0
  61. package/dist/chunk-GQKKX7OE.js.map +1 -0
  62. package/dist/chunk-GRJY22U6.js +691 -0
  63. package/dist/chunk-GRJY22U6.js.map +1 -0
  64. package/dist/chunk-H6DVP2SI.js +682 -0
  65. package/dist/chunk-H6DVP2SI.js.map +1 -0
  66. package/dist/chunk-HVVPTCKR.js +1173 -0
  67. package/dist/chunk-HVVPTCKR.js.map +1 -0
  68. package/dist/chunk-I6XFZLTJ.js +9 -0
  69. package/dist/chunk-I6XFZLTJ.js.map +1 -0
  70. package/dist/chunk-IBOABSIA.js +17 -0
  71. package/dist/chunk-IBOABSIA.js.map +1 -0
  72. package/dist/chunk-IK524ZDW.js +691 -0
  73. package/dist/chunk-IK524ZDW.js.map +1 -0
  74. package/dist/chunk-IRU7NBOT.js +141 -0
  75. package/dist/chunk-IRU7NBOT.js.map +1 -0
  76. package/dist/chunk-J4CKQXQ6.js +806 -0
  77. package/dist/chunk-J4CKQXQ6.js.map +1 -0
  78. package/dist/chunk-JKGSJGCC.js +311 -0
  79. package/dist/chunk-JKGSJGCC.js.map +1 -0
  80. package/dist/chunk-JQOKQKQT.js +158 -0
  81. package/dist/chunk-JQOKQKQT.js.map +1 -0
  82. package/dist/chunk-JRFUTIEH.js +426 -0
  83. package/dist/chunk-JRFUTIEH.js.map +1 -0
  84. package/dist/chunk-K2BPYEH5.js +491 -0
  85. package/dist/chunk-K2BPYEH5.js.map +1 -0
  86. package/dist/chunk-KCQC7YBK.js +7795 -0
  87. package/dist/chunk-KCQC7YBK.js.map +1 -0
  88. package/dist/chunk-KDAV2GUT.js +1357 -0
  89. package/dist/chunk-KDAV2GUT.js.map +1 -0
  90. package/dist/chunk-KDDXZBMC.js +583 -0
  91. package/dist/chunk-KDDXZBMC.js.map +1 -0
  92. package/dist/chunk-KMWHZSEG.js +41 -0
  93. package/dist/chunk-KMWHZSEG.js.map +1 -0
  94. package/dist/chunk-KRI4R7EM.js +25 -0
  95. package/dist/chunk-KRI4R7EM.js.map +1 -0
  96. package/dist/chunk-LNJ3WZZX.js +186 -0
  97. package/dist/chunk-LNJ3WZZX.js.map +1 -0
  98. package/dist/chunk-MWXA4PFE.js +103 -0
  99. package/dist/chunk-MWXA4PFE.js.map +1 -0
  100. package/dist/chunk-MY62SSKC.js +183 -0
  101. package/dist/chunk-MY62SSKC.js.map +1 -0
  102. package/dist/chunk-NAGAJ5UM.js +145 -0
  103. package/dist/chunk-NAGAJ5UM.js.map +1 -0
  104. package/dist/chunk-NJ7WRKIQ.js +532 -0
  105. package/dist/chunk-NJ7WRKIQ.js.map +1 -0
  106. package/dist/chunk-OS6NUIBJ.js +38 -0
  107. package/dist/chunk-OS6NUIBJ.js.map +1 -0
  108. package/dist/chunk-PXU2OS26.js +238 -0
  109. package/dist/chunk-PXU2OS26.js.map +1 -0
  110. package/dist/chunk-QO4LBDVI.js +496 -0
  111. package/dist/chunk-QO4LBDVI.js.map +1 -0
  112. package/dist/chunk-QRZPQNLX.js +65 -0
  113. package/dist/chunk-QRZPQNLX.js.map +1 -0
  114. package/dist/chunk-SNVAMWB7.js +40 -0
  115. package/dist/chunk-SNVAMWB7.js.map +1 -0
  116. package/dist/chunk-SPRVUATR.js +430 -0
  117. package/dist/chunk-SPRVUATR.js.map +1 -0
  118. package/dist/chunk-SY7G5QEI.js +35 -0
  119. package/dist/chunk-SY7G5QEI.js.map +1 -0
  120. package/dist/chunk-SZNBUIDR.js +6438 -0
  121. package/dist/chunk-SZNBUIDR.js.map +1 -0
  122. package/dist/chunk-TQ2NA4Z4.js +24 -0
  123. package/dist/chunk-TQ2NA4Z4.js.map +1 -0
  124. package/dist/chunk-TYULB6ZY.js +2959 -0
  125. package/dist/chunk-TYULB6ZY.js.map +1 -0
  126. package/dist/chunk-UJYFTXHV.js +296 -0
  127. package/dist/chunk-UJYFTXHV.js.map +1 -0
  128. package/dist/chunk-VC6OKCJF.js +184 -0
  129. package/dist/chunk-VC6OKCJF.js.map +1 -0
  130. package/dist/chunk-VL2NWCZV.js +118 -0
  131. package/dist/chunk-VL2NWCZV.js.map +1 -0
  132. package/dist/chunk-VL7BGD47.js +514 -0
  133. package/dist/chunk-VL7BGD47.js.map +1 -0
  134. package/dist/chunk-VQVUJYYY.js +244 -0
  135. package/dist/chunk-VQVUJYYY.js.map +1 -0
  136. package/dist/chunk-VZQG2JDV.js +9 -0
  137. package/dist/chunk-VZQG2JDV.js.map +1 -0
  138. package/dist/chunk-XFZQVYIN.js +115 -0
  139. package/dist/chunk-XFZQVYIN.js.map +1 -0
  140. package/dist/chunk-XGTTOO4R.js +84 -0
  141. package/dist/chunk-XGTTOO4R.js.map +1 -0
  142. package/dist/chunk-XQFT4PEP.js +60 -0
  143. package/dist/chunk-XQFT4PEP.js.map +1 -0
  144. package/dist/chunk-YDD3ES2K.js +571 -0
  145. package/dist/chunk-YDD3ES2K.js.map +1 -0
  146. package/dist/chunk-ZY2MZ2KQ.js +1140 -0
  147. package/dist/chunk-ZY2MZ2KQ.js.map +1 -0
  148. package/dist/compile-57EEIUMB.js +161 -0
  149. package/dist/compile-57EEIUMB.js.map +1 -0
  150. package/dist/config-4EJ3D7QJ.js +438 -0
  151. package/dist/config-4EJ3D7QJ.js.map +1 -0
  152. package/dist/doctor-EEV6P5CH.js +111 -0
  153. package/dist/doctor-EEV6P5CH.js.map +1 -0
  154. package/dist/environment-WFEG4DAT.js +2745 -0
  155. package/dist/environment-WFEG4DAT.js.map +1 -0
  156. package/dist/github-BSMQD72A.js +114 -0
  157. package/dist/github-BSMQD72A.js.map +1 -0
  158. package/dist/harness-VX3PNVQW.js +746 -0
  159. package/dist/harness-VX3PNVQW.js.map +1 -0
  160. package/dist/help-AW2HKX63.js +2079 -0
  161. package/dist/help-AW2HKX63.js.map +1 -0
  162. package/dist/help-BVFOZD7E.js +1892 -0
  163. package/dist/help-BVFOZD7E.js.map +1 -0
  164. package/dist/index.d.ts +164 -1
  165. package/dist/index.js +50 -59246
  166. package/dist/index.js.map +1 -1
  167. package/dist/init-SPN2GEZ4.js +873 -0
  168. package/dist/init-SPN2GEZ4.js.map +1 -0
  169. package/dist/lock-K2LLUU7H.js +455 -0
  170. package/dist/lock-K2LLUU7H.js.map +1 -0
  171. package/dist/marketplace-VEKSWGX3.js +495 -0
  172. package/dist/marketplace-VEKSWGX3.js.map +1 -0
  173. package/dist/mcp-T6DKIKSF.js +202 -0
  174. package/dist/mcp-T6DKIKSF.js.map +1 -0
  175. package/dist/migrate-OO37WSB2.js +1043 -0
  176. package/dist/migrate-OO37WSB2.js.map +1 -0
  177. package/dist/open-3V3QK5RK.js +32 -0
  178. package/dist/open-3V3QK5RK.js.map +1 -0
  179. package/dist/pack-V32UPC7W.js +99 -0
  180. package/dist/pack-V32UPC7W.js.map +1 -0
  181. package/dist/plugin-KOBNQ7GT.js +64 -0
  182. package/dist/plugin-KOBNQ7GT.js.map +1 -0
  183. package/dist/plugin-from-project-X3VO3MB6.js +16 -0
  184. package/dist/plugin-from-project-X3VO3MB6.js.map +1 -0
  185. package/dist/policy-F5MKZNOC.js +105 -0
  186. package/dist/policy-F5MKZNOC.js.map +1 -0
  187. package/dist/profile-H4PMH4XT.js +1886 -0
  188. package/dist/profile-H4PMH4XT.js.map +1 -0
  189. package/dist/project-QVNEJJGH.js +1392 -0
  190. package/dist/project-QVNEJJGH.js.map +1 -0
  191. package/dist/resource-GL4RLSGI.js +555 -0
  192. package/dist/resource-GL4RLSGI.js.map +1 -0
  193. package/dist/version-PBHZK44K.js +17 -0
  194. package/dist/version-PBHZK44K.js.map +1 -0
  195. package/package.json +21 -14
  196. package/schemas/ap-package.v1.json +36 -0
  197. package/schemas/fixtures/catalog-missing-schema.ap.json +13 -0
  198. package/schemas/fixtures/confidence.ap.json +13 -0
  199. package/schemas/fixtures/context7.ap.json +13 -0
  200. package/schemas/fixtures/minimal-with-schema.ap.json +13 -0
  201. package/schemas/fixtures/superpowers.ap.json +13 -0
  202. package/schemas/fixtures/third-party-skills.ap.json +13 -0
@@ -0,0 +1,998 @@
1
+ import {
2
+ githubGitConfigArgs,
3
+ githubHttpsRemoteForAuth,
4
+ resolveGithubAccessToken
5
+ } from "./chunk-GQKKX7OE.js";
6
+ import {
7
+ DEFAULT_MARKETPLACE_REFRESH_MAX_AGE_MINUTES,
8
+ loadSettings,
9
+ marketplaceRefreshMaxAgeMs,
10
+ parseTrackedBranches,
11
+ saveSettings
12
+ } from "./chunk-VQVUJYYY.js";
13
+ import {
14
+ mapGitStderr
15
+ } from "./chunk-DWVAR4BP.js";
16
+
17
+ // src/services/marketplace-registry.ts
18
+ import { homedir } from "os";
19
+ import { isAbsolute, resolve } from "path";
20
+ import { fileURLToPath } from "url";
21
+ function stripGitSuffix(value) {
22
+ return value.replace(/\.git$/i, "");
23
+ }
24
+ function isLocalFilesystemSource(value) {
25
+ if (value.startsWith("file:")) return true;
26
+ if (value.startsWith("/") || value.startsWith("./") || value.startsWith("../")) {
27
+ return true;
28
+ }
29
+ if (value.startsWith("~/")) return true;
30
+ if (/^[A-Za-z]:[\\/]/.test(value)) return true;
31
+ return false;
32
+ }
33
+ function normalizeMarketplaceUrl(url) {
34
+ const trimmed = url.trim();
35
+ if (!trimmed) return "";
36
+ if (trimmed.startsWith("file:")) {
37
+ try {
38
+ const parsed = new URL(trimmed);
39
+ if (parsed.protocol === "file:") {
40
+ return stripGitSuffix(fileURLToPath(parsed));
41
+ }
42
+ } catch {
43
+ }
44
+ }
45
+ if (isLocalFilesystemSource(trimmed)) {
46
+ const expanded = trimmed.startsWith("~/") ? resolve(homedir(), trimmed.slice(2)) : isAbsolute(trimmed) ? trimmed : resolve(trimmed);
47
+ return stripGitSuffix(expanded);
48
+ }
49
+ return stripGitSuffix(trimmed);
50
+ }
51
+ function marketplaceEntryPayload(name, url, platforms, trackedBranches) {
52
+ const branches = parseTrackedBranches(trackedBranches ?? []);
53
+ return {
54
+ name,
55
+ url,
56
+ platforms: [...platforms],
57
+ ...branches.length > 0 ? { trackedBranches: branches } : {}
58
+ };
59
+ }
60
+ function listMarketplaces(harnesstapDir) {
61
+ return loadSettings(harnesstapDir).plugins.marketplaces;
62
+ }
63
+ function addMarketplace(harnesstapDir, input) {
64
+ const url = normalizeMarketplaceUrl(input.url);
65
+ const name = input.name.trim();
66
+ if (!name) throw new Error("Marketplace name is required");
67
+ if (!url) throw new Error("Marketplace URL is required");
68
+ if (input.platforms.length === 0) {
69
+ throw new Error("At least one --platform is required");
70
+ }
71
+ const settings = loadSettings(harnesstapDir);
72
+ const existing = settings.plugins.marketplaces;
73
+ const byUrl = existing.find(
74
+ (e) => normalizeMarketplaceUrl(e.url) === url
75
+ );
76
+ if (byUrl) {
77
+ return { status: "already_configured", entry: byUrl };
78
+ }
79
+ const byName = existing.find((e) => e.name === name);
80
+ if (byName) {
81
+ throw new Error(
82
+ `Marketplace name conflict: "${name}" already points at ${byName.url}. Pass a different --name or remove it first.`
83
+ );
84
+ }
85
+ const entry = marketplaceEntryPayload(
86
+ name,
87
+ url,
88
+ input.platforms,
89
+ input.trackedBranches
90
+ );
91
+ saveSettings(harnesstapDir, {
92
+ ...settings,
93
+ plugins: {
94
+ ...settings.plugins,
95
+ marketplaces: [...existing, entry]
96
+ }
97
+ });
98
+ return { status: "added", entry };
99
+ }
100
+ function removeMarketplace(harnesstapDir, name) {
101
+ const settings = loadSettings(harnesstapDir);
102
+ const entry = settings.plugins.marketplaces.find((e) => e.name === name);
103
+ if (!entry) return { status: "not_found", name };
104
+ saveSettings(harnesstapDir, {
105
+ ...settings,
106
+ plugins: {
107
+ ...settings.plugins,
108
+ marketplaces: settings.plugins.marketplaces.filter((e) => e.name !== name)
109
+ }
110
+ });
111
+ return { status: "removed", entry };
112
+ }
113
+
114
+ // src/services/marketplace-catalog.ts
115
+ import {
116
+ existsSync as existsSync5,
117
+ mkdirSync as mkdirSync2,
118
+ mkdtempSync,
119
+ readFileSync as readFileSync4,
120
+ renameSync,
121
+ rmSync as rmSync2,
122
+ statSync as statSync3,
123
+ writeFileSync
124
+ } from "fs";
125
+ import { tmpdir } from "os";
126
+ import { dirname, join as join5 } from "path";
127
+
128
+ // src/plugins/refresh.ts
129
+ import { existsSync, mkdirSync, rmSync } from "fs";
130
+ import { join } from "path";
131
+
132
+ // src/utils/run-command-with-timeout.ts
133
+ import { spawnSync } from "child_process";
134
+ var DEFAULT_GIT_CLONE_TIMEOUT_MS = 12e4;
135
+ function runCommandWithTimeout(command, args, options) {
136
+ const timeoutMs = options?.timeoutMs ?? DEFAULT_GIT_CLONE_TIMEOUT_MS;
137
+ const result = spawnSync(command, args, {
138
+ encoding: "utf-8",
139
+ stdio: ["ignore", "pipe", "pipe"],
140
+ cwd: options?.cwd,
141
+ timeout: timeoutMs,
142
+ killSignal: "SIGTERM",
143
+ env: command === "git" ? { ...process.env, GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never" } : process.env
144
+ });
145
+ const spawnError = result.error;
146
+ if (spawnError && "code" in spawnError && spawnError.code === "ETIMEDOUT") {
147
+ return {
148
+ stdout: result.stdout?.toString() ?? "",
149
+ stderr: `Command timed out after ${timeoutMs}ms: ${command} ${args.join(" ")}`,
150
+ exitCode: 124
151
+ };
152
+ }
153
+ return {
154
+ stdout: result.stdout?.toString() ?? "",
155
+ stderr: result.stderr?.toString() ?? "",
156
+ exitCode: result.status ?? 1
157
+ };
158
+ }
159
+
160
+ // src/plugins/refresh.ts
161
+ function refreshGitSource(opts) {
162
+ const run = opts.runCommand ?? runCommandWithTimeout;
163
+ if (existsSync(opts.targetDir)) {
164
+ rmSync(opts.targetDir, { recursive: true, force: true });
165
+ }
166
+ mkdirSync(opts.targetDir, { recursive: true });
167
+ const token = resolveGithubAccessToken().token;
168
+ const url = githubHttpsRemoteForAuth(opts.url, token);
169
+ const cloneArgs = [...githubGitConfigArgs(token), "clone", "--depth", "1"];
170
+ if (opts.ref) cloneArgs.push("--branch", opts.ref);
171
+ cloneArgs.push(url, opts.targetDir);
172
+ const clone = run("git", cloneArgs, { timeoutMs: DEFAULT_GIT_CLONE_TIMEOUT_MS });
173
+ if (clone.exitCode !== 0) {
174
+ return {
175
+ ok: false,
176
+ message: mapGitStderr(clone.stderr.trim() || "git clone failed", opts.url)
177
+ };
178
+ }
179
+ const rev = run("git", [
180
+ ...githubGitConfigArgs(token),
181
+ "-C",
182
+ opts.targetDir,
183
+ "rev-parse",
184
+ "HEAD"
185
+ ]);
186
+ return {
187
+ ok: true,
188
+ sha: rev.stdout.trim(),
189
+ message: "Refreshed from git"
190
+ };
191
+ }
192
+ function cursorRepoSourceKey(url) {
193
+ return `cursor:repo:${url}`;
194
+ }
195
+ function cursorCacheRoot(homeRoot) {
196
+ return join(homeRoot, ".cursor", "plugins", "cache");
197
+ }
198
+ function cursorLocalRoot(homeRoot) {
199
+ return join(homeRoot, ".cursor", "plugins", "local");
200
+ }
201
+ function cursorMarketplacesRoot(homeRoot) {
202
+ return join(homeRoot, ".cursor", "plugins", "marketplaces");
203
+ }
204
+ function cursorProjectsMcpsRoot(homeRoot) {
205
+ return join(homeRoot, ".cursor", "projects", "mcps");
206
+ }
207
+
208
+ // src/services/builtin-marketplaces.ts
209
+ var CURSOR_PUBLIC_MARKETPLACE = "cursor-public";
210
+ var CURSOR_PUBLIC_GIT_URL = "https://github.com/cursor/plugins.git";
211
+ var CURSOR_PUBLIC_PLATFORMS = [
212
+ "cursor",
213
+ "claude-code"
214
+ ];
215
+ function isCursorPublicMarketplace(name) {
216
+ return name === CURSOR_PUBLIC_MARKETPLACE;
217
+ }
218
+ function builtinMarketplaceGitUrl(name) {
219
+ return isCursorPublicMarketplace(name) ? CURSOR_PUBLIC_GIT_URL : null;
220
+ }
221
+ function builtinMarketplaceEntry() {
222
+ return {
223
+ name: CURSOR_PUBLIC_MARKETPLACE,
224
+ url: CURSOR_PUBLIC_GIT_URL,
225
+ platforms: [...CURSOR_PUBLIC_PLATFORMS]
226
+ };
227
+ }
228
+
229
+ // src/services/marketplace-catalog-index.ts
230
+ import { existsSync as existsSync4, readdirSync as readdirSync2, readFileSync as readFileSync3, statSync as statSync2 } from "fs";
231
+ import { join as join4 } from "path";
232
+ import matter2 from "gray-matter";
233
+
234
+ // src/plugins/host-plugin-manifest.ts
235
+ import { existsSync as existsSync2, readFileSync } from "fs";
236
+ import { join as join2 } from "path";
237
+ var HOST_PLUGIN_MANIFEST_RELATIVE_PATHS = [
238
+ ".claude-plugin/plugin.json",
239
+ ".cursor-plugin/plugin.json",
240
+ ".codex-plugin/plugin.json",
241
+ ".github/plugin/plugin.json",
242
+ ".goose-plugin/plugin.json",
243
+ "plugin.json"
244
+ ];
245
+ function readJsonFile(path) {
246
+ if (!existsSync2(path)) return null;
247
+ try {
248
+ return JSON.parse(readFileSync(path, "utf-8"));
249
+ } catch {
250
+ return null;
251
+ }
252
+ }
253
+ function readFirstHostPluginManifest(installPath) {
254
+ for (const relativePath of HOST_PLUGIN_MANIFEST_RELATIVE_PATHS) {
255
+ const manifest = readJsonFile(
256
+ join2(installPath, relativePath)
257
+ );
258
+ if (manifest?.name) {
259
+ return manifest;
260
+ }
261
+ }
262
+ return null;
263
+ }
264
+ function parsePluginRef(ref) {
265
+ const at = ref.lastIndexOf("@");
266
+ if (at <= 0) return { name: ref, marketplace: "" };
267
+ return { name: ref.slice(0, at), marketplace: ref.slice(at + 1) };
268
+ }
269
+
270
+ // src/services/skill-discovery.ts
271
+ import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, statSync } from "fs";
272
+ import { join as join3, relative } from "path";
273
+ import matter from "gray-matter";
274
+ var SKILL_ROOTS = ["skills", ".agents/skills"];
275
+ function isDirectory(path) {
276
+ try {
277
+ return statSync(path).isDirectory();
278
+ } catch {
279
+ return false;
280
+ }
281
+ }
282
+ function scalarString(value) {
283
+ return typeof value === "string" ? value.trim() : "";
284
+ }
285
+ function parseSkillFrontmatterFallback(raw) {
286
+ if (!raw.startsWith("---")) {
287
+ return { data: {}, content: raw };
288
+ }
289
+ const end = raw.indexOf("\n---", 3);
290
+ if (end === -1) {
291
+ return { data: {}, content: raw };
292
+ }
293
+ const data = {};
294
+ for (const line of raw.slice(4, end).split("\n")) {
295
+ const separator = line.indexOf(":");
296
+ if (separator <= 0) continue;
297
+ const key = line.slice(0, separator).trim();
298
+ if (!key) continue;
299
+ let value = line.slice(separator + 1).trim();
300
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
301
+ value = value.slice(1, -1);
302
+ }
303
+ data[key] = value;
304
+ }
305
+ return {
306
+ data,
307
+ content: raw.slice(end + 4).replace(/^\n/, "")
308
+ };
309
+ }
310
+ function parseSkillMarkdown(raw) {
311
+ try {
312
+ const parsed = matter(raw);
313
+ return { data: parsed.data, content: parsed.content };
314
+ } catch {
315
+ return parseSkillFrontmatterFallback(raw);
316
+ }
317
+ }
318
+ function readSkillMd(skillDir) {
319
+ const skillPath = join3(skillDir, "SKILL.md");
320
+ if (!existsSync3(skillPath)) return null;
321
+ let raw;
322
+ try {
323
+ raw = readFileSync2(skillPath, "utf-8");
324
+ } catch {
325
+ return null;
326
+ }
327
+ const parsed = parseSkillMarkdown(raw);
328
+ const dirName = skillDir.split(/[/\\]/).pop() ?? "skill";
329
+ const name = scalarString(parsed.data.name);
330
+ return {
331
+ name: name || dirName,
332
+ description: scalarString(parsed.data.description),
333
+ body: parsed.content
334
+ };
335
+ }
336
+ function walkForSkills(rootPath, currentDir, results) {
337
+ if (!isDirectory(currentDir)) return;
338
+ const skill = readSkillMd(currentDir);
339
+ if (skill) {
340
+ const skillDirRelative = relative(rootPath, currentDir).split("\\").join("/");
341
+ const parts = skillDirRelative.split("/");
342
+ const category = parts.length >= 3 && parts[0] === "skills" ? parts[1] ?? "general" : "general";
343
+ results.push({
344
+ name: skill.name,
345
+ description: skill.description,
346
+ category,
347
+ skillDirRelative,
348
+ skillMdRelative: `${skillDirRelative}/SKILL.md`
349
+ });
350
+ return;
351
+ }
352
+ for (const entry of readdirSync(currentDir)) {
353
+ if (entry.startsWith(".")) continue;
354
+ walkForSkills(rootPath, join3(currentDir, entry), results);
355
+ }
356
+ }
357
+ function discoverSkillPackage(rootPath) {
358
+ const results = [];
359
+ for (const root of SKILL_ROOTS) {
360
+ const dir = join3(rootPath, root);
361
+ if (!isDirectory(dir)) continue;
362
+ for (const entry of readdirSync(dir)) {
363
+ if (entry.startsWith(".")) continue;
364
+ walkForSkills(rootPath, join3(dir, entry), results);
365
+ }
366
+ }
367
+ const byName = /* @__PURE__ */ new Map();
368
+ for (const skill of results) {
369
+ byName.set(skill.name, skill);
370
+ }
371
+ return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
372
+ }
373
+
374
+ // src/services/marketplace-catalog-index.ts
375
+ var PLUGIN_ROOT_WALK_SKIP = /* @__PURE__ */ new Set([".git", "node_modules", ".hg"]);
376
+ var PLUGIN_ROOT_WALK_MAX_DEPTH = 6;
377
+ var COMMAND_DIRS = ["commands", ".claude/commands"];
378
+ function isDirectory2(path) {
379
+ try {
380
+ return existsSync4(path) && statSync2(path).isDirectory();
381
+ } catch {
382
+ return false;
383
+ }
384
+ }
385
+ function uniqueStrings(values) {
386
+ const seen = /* @__PURE__ */ new Set();
387
+ const next = [];
388
+ for (const value of values) {
389
+ if (seen.has(value)) continue;
390
+ seen.add(value);
391
+ next.push(value);
392
+ }
393
+ return next;
394
+ }
395
+ function looksLikePluginRoot(path) {
396
+ for (const relative2 of HOST_PLUGIN_MANIFEST_RELATIVE_PATHS) {
397
+ if (existsSync4(join4(path, relative2))) return true;
398
+ }
399
+ return isDirectory2(join4(path, "skills")) || isDirectory2(join4(path, "commands"));
400
+ }
401
+ function walkNamedPluginRoot(dir, pluginName, depth) {
402
+ if (depth > PLUGIN_ROOT_WALK_MAX_DEPTH || !isDirectory2(dir)) {
403
+ return void 0;
404
+ }
405
+ try {
406
+ const entries = readdirSync2(dir, { withFileTypes: true });
407
+ for (const entry of entries) {
408
+ if (!entry.isDirectory() || PLUGIN_ROOT_WALK_SKIP.has(entry.name)) {
409
+ continue;
410
+ }
411
+ const child = join4(dir, entry.name);
412
+ if (entry.name === pluginName && looksLikePluginRoot(child)) {
413
+ return child;
414
+ }
415
+ const nested = walkNamedPluginRoot(child, pluginName, depth + 1);
416
+ if (nested) return nested;
417
+ }
418
+ } catch {
419
+ return void 0;
420
+ }
421
+ return void 0;
422
+ }
423
+ function resolveMarketplaceCatalogPluginRoot(marketplaceRoot, plugin) {
424
+ if (plugin.sourcePath) {
425
+ const fromSource = join4(marketplaceRoot, plugin.sourcePath);
426
+ if (isDirectory2(fromSource)) return fromSource;
427
+ }
428
+ const underPlugins = join4(marketplaceRoot, "plugins", plugin.name);
429
+ if (isDirectory2(underPlugins) && looksLikePluginRoot(underPlugins)) {
430
+ return underPlugins;
431
+ }
432
+ const atRoot = join4(marketplaceRoot, plugin.name);
433
+ if (isDirectory2(atRoot) && looksLikePluginRoot(atRoot)) {
434
+ return atRoot;
435
+ }
436
+ return walkNamedPluginRoot(marketplaceRoot, plugin.name, 0);
437
+ }
438
+ function commandContents(pluginRoot) {
439
+ const contents = [];
440
+ const seen = /* @__PURE__ */ new Set();
441
+ for (const relative2 of COMMAND_DIRS) {
442
+ const dir = join4(pluginRoot, relative2);
443
+ if (!isDirectory2(dir)) continue;
444
+ let entries;
445
+ try {
446
+ entries = readdirSync2(dir, { encoding: "utf8" });
447
+ } catch {
448
+ continue;
449
+ }
450
+ for (const entry of entries) {
451
+ const name = entry.replace(/\.(md|toml)$/, "");
452
+ if (name === entry || seen.has(name)) continue;
453
+ const absolute = join4(dir, entry);
454
+ let description;
455
+ if (entry.endsWith(".md")) {
456
+ try {
457
+ const parsed = matter2(readFileSync3(absolute, "utf8"));
458
+ if (typeof parsed.data.description === "string") {
459
+ description = parsed.data.description;
460
+ }
461
+ } catch {
462
+ description = void 0;
463
+ }
464
+ }
465
+ seen.add(name);
466
+ contents.push({
467
+ type: "command",
468
+ name,
469
+ ...description ? { description } : {}
470
+ });
471
+ }
472
+ }
473
+ return contents;
474
+ }
475
+ function enrichCatalogPlugin(marketplaceRoot, plugin) {
476
+ const pluginRoot = resolveMarketplaceCatalogPluginRoot(marketplaceRoot, plugin);
477
+ if (!pluginRoot) return plugin;
478
+ const manifest = readFirstHostPluginManifest(pluginRoot);
479
+ const description = plugin.description ?? manifest?.description;
480
+ const keywords = (manifest?.keywords ?? []).filter(
481
+ (keyword) => typeof keyword === "string" && keyword.trim().length > 0
482
+ );
483
+ const tags = uniqueStrings([...plugin.tags ?? [], ...keywords]);
484
+ let skills = [];
485
+ try {
486
+ skills = discoverSkillPackage(pluginRoot);
487
+ } catch {
488
+ skills = [];
489
+ }
490
+ const contents = [
491
+ ...skills.map((skill) => ({
492
+ type: "skill",
493
+ name: skill.name,
494
+ ...skill.description ? { description: skill.description } : {}
495
+ })),
496
+ ...commandContents(pluginRoot)
497
+ ];
498
+ return {
499
+ ...plugin,
500
+ ...description ? { description } : {},
501
+ ...tags.length > 0 ? { tags } : {},
502
+ ...contents.length > 0 ? { contents } : {}
503
+ };
504
+ }
505
+ function enrichCatalogPlugins(marketplaceRoot, plugins) {
506
+ if (!isDirectory2(marketplaceRoot)) return plugins;
507
+ return plugins.map((plugin) => enrichCatalogPlugin(marketplaceRoot, plugin));
508
+ }
509
+ function catalogPluginMatchesQuery(plugin, query) {
510
+ const needle = query.trim().toLowerCase();
511
+ if (!needle) return true;
512
+ if (plugin.name.toLowerCase().includes(needle)) return true;
513
+ if (plugin.ref.toLowerCase().includes(needle)) return true;
514
+ if (plugin.description?.toLowerCase().includes(needle)) return true;
515
+ for (const tag of plugin.tags ?? []) {
516
+ if (tag.toLowerCase().includes(needle)) return true;
517
+ }
518
+ for (const content of plugin.contents ?? []) {
519
+ if (content.name.toLowerCase().includes(needle)) return true;
520
+ if (content.description?.toLowerCase().includes(needle)) return true;
521
+ }
522
+ return false;
523
+ }
524
+
525
+ // src/services/marketplace-catalog-parse.ts
526
+ import { basename } from "path";
527
+ import semver from "semver";
528
+ function isRecord(value) {
529
+ return typeof value === "object" && value !== null && !Array.isArray(value);
530
+ }
531
+ function readMarketplaceName(raw) {
532
+ if (!isRecord(raw)) return "";
533
+ const name = raw.name;
534
+ return typeof name === "string" ? name : "";
535
+ }
536
+ function buildRef(name, marketplaceName) {
537
+ return marketplaceName ? `${name}@${marketplaceName}` : name;
538
+ }
539
+ function resolveVersion(entry) {
540
+ const version = entry.version;
541
+ if (typeof version === "string" && version.length > 0) return version;
542
+ const source = entry.source;
543
+ if (!isRecord(source)) return void 0;
544
+ const sha = source.sha;
545
+ if (typeof sha === "string" && sha.length > 0) return sha.slice(0, 12);
546
+ const ref = source.ref;
547
+ if (typeof ref === "string" && ref.length > 0) return ref;
548
+ return void 0;
549
+ }
550
+ function resolveDescription(entry) {
551
+ const description = entry.description;
552
+ return typeof description === "string" && description.length > 0 ? description : void 0;
553
+ }
554
+ function resolveTags(entry) {
555
+ const tags = entry.tags;
556
+ if (!Array.isArray(tags)) return void 0;
557
+ const next = tags.filter(
558
+ (tag) => typeof tag === "string" && tag.trim().length > 0
559
+ );
560
+ return next.length > 0 ? next : void 0;
561
+ }
562
+ function normalizeMarketplaceSourcePath(value) {
563
+ return value.replaceAll("\\", "/").replace(/^\.\//, "").replace(/\/+$/, "");
564
+ }
565
+ function resolveSourcePath(entry) {
566
+ const source = entry.source;
567
+ if (typeof source === "string" && source.trim().length > 0) {
568
+ return normalizeMarketplaceSourcePath(source);
569
+ }
570
+ const path = entry.path;
571
+ if (typeof path === "string" && path.trim().length > 0) {
572
+ return normalizeMarketplaceSourcePath(path);
573
+ }
574
+ return void 0;
575
+ }
576
+ function parsePluginEntry(entry, marketplaceName, resolveName) {
577
+ if (!isRecord(entry)) return void 0;
578
+ const name = resolveName(entry);
579
+ if (!name) return void 0;
580
+ const version = resolveVersion(entry);
581
+ const description = resolveDescription(entry);
582
+ const tags = resolveTags(entry);
583
+ const sourcePath = resolveSourcePath(entry);
584
+ const ref = buildRef(name, marketplaceName);
585
+ return {
586
+ name,
587
+ ...version !== void 0 ? { version } : {},
588
+ ref,
589
+ ...description !== void 0 ? { description } : {},
590
+ ...tags !== void 0 ? { tags } : {},
591
+ ...sourcePath !== void 0 ? { sourcePath } : {}
592
+ };
593
+ }
594
+ function parsePlugins(raw, marketplaceName, resolveName) {
595
+ if (!isRecord(raw)) return [];
596
+ const plugins = raw.plugins;
597
+ if (!Array.isArray(plugins)) return [];
598
+ const parsed = [];
599
+ for (const entry of plugins) {
600
+ const plugin = parsePluginEntry(entry, marketplaceName, resolveName);
601
+ if (plugin) parsed.push(plugin);
602
+ }
603
+ return parsed;
604
+ }
605
+ function resolveClaudePluginName(entry) {
606
+ const name = entry.name;
607
+ return typeof name === "string" && name.length > 0 ? name : void 0;
608
+ }
609
+ function resolveCursorPluginName(entry) {
610
+ const name = entry.name;
611
+ if (typeof name === "string" && name.length > 0) return name;
612
+ const path = entry.path;
613
+ if (typeof path === "string" && path.length > 0) {
614
+ const derived = basename(path);
615
+ return derived.length > 0 ? derived : void 0;
616
+ }
617
+ return void 0;
618
+ }
619
+ function parseClaudeMarketplaceManifest(raw) {
620
+ const marketplaceName = readMarketplaceName(raw);
621
+ const plugins = parsePlugins(raw, marketplaceName, resolveClaudePluginName);
622
+ return { marketplaceName, plugins };
623
+ }
624
+ function parseCursorMarketplaceManifest(raw) {
625
+ const marketplaceName = readMarketplaceName(raw);
626
+ const plugins = parsePlugins(raw, marketplaceName, resolveCursorPluginName);
627
+ return { marketplaceName, plugins };
628
+ }
629
+ function catalogSemver(version) {
630
+ if (!version?.trim()) return null;
631
+ const trimmed = version.trim();
632
+ const withoutV = trimmed.startsWith("v") ? trimmed.slice(1) : trimmed;
633
+ return semver.valid(withoutV);
634
+ }
635
+ function preferCatalogPlugin(current, incoming) {
636
+ const currentRank = catalogSemver(current.version);
637
+ const incomingRank = catalogSemver(incoming.version);
638
+ const preferIncoming = incomingRank !== null && (currentRank === null || semver.rcompare(incomingRank, currentRank) < 0);
639
+ const chosen = preferIncoming ? incoming : current;
640
+ const other = preferIncoming ? current : incoming;
641
+ const tags = uniqueStrings2([...chosen.tags ?? [], ...other.tags ?? []]);
642
+ const contents = chosen.contents?.length ? chosen.contents : other.contents;
643
+ return {
644
+ ...chosen,
645
+ version: chosen.version ?? other.version,
646
+ description: chosen.description ?? other.description,
647
+ sourcePath: chosen.sourcePath ?? other.sourcePath,
648
+ ...tags.length > 0 ? { tags } : {},
649
+ ...contents && contents.length > 0 ? { contents } : {}
650
+ };
651
+ }
652
+ function uniqueStrings2(values) {
653
+ const seen = /* @__PURE__ */ new Set();
654
+ const next = [];
655
+ for (const value of values) {
656
+ if (seen.has(value)) continue;
657
+ seen.add(value);
658
+ next.push(value);
659
+ }
660
+ return next;
661
+ }
662
+ function mergeCatalogPluginsByIdentity(plugins) {
663
+ const byName = /* @__PURE__ */ new Map();
664
+ for (const plugin of plugins) {
665
+ const existing = byName.get(plugin.name);
666
+ if (!existing) {
667
+ byName.set(plugin.name, plugin);
668
+ continue;
669
+ }
670
+ byName.set(plugin.name, preferCatalogPlugin(existing, plugin));
671
+ }
672
+ return [...byName.values()];
673
+ }
674
+
675
+ // src/services/marketplace-catalog.ts
676
+ var MARKETPLACE_CATALOG_INDEX_VERSION = 1;
677
+ var MANIFEST_PATHS = [
678
+ { path: ".claude-plugin/marketplace.json", platform: "claude-code" },
679
+ { path: ".cursor-plugin/marketplace.json", platform: "cursor" },
680
+ { path: "marketplace.json", platform: null }
681
+ ];
682
+ function marketplaceCacheDir(harnesstapDir, name) {
683
+ return join5(harnesstapDir, "cache", "marketplaces", name);
684
+ }
685
+ function marketplaceCatalogPath(harnesstapDir, name) {
686
+ return join5(marketplaceCacheDir(harnesstapDir, name), "catalog.json");
687
+ }
688
+ var MARKETPLACE_CATALOG_MAX_AGE_MS = marketplaceRefreshMaxAgeMs(
689
+ DEFAULT_MARKETPLACE_REFRESH_MAX_AGE_MINUTES
690
+ );
691
+ function isGooseOnly(platforms) {
692
+ return platforms.length === 1 && platforms[0] === "goose";
693
+ }
694
+ function catalogIsFresh(catalogPath, maxAgeMs) {
695
+ if (!existsSync5(catalogPath)) return false;
696
+ const ageMs = Date.now() - statSync3(catalogPath).mtimeMs;
697
+ return ageMs < maxAgeMs;
698
+ }
699
+ function readStoredCatalog(catalogPath) {
700
+ if (!existsSync5(catalogPath)) return void 0;
701
+ try {
702
+ const raw = JSON.parse(readFileSync4(catalogPath, "utf8"));
703
+ if (!Array.isArray(raw.plugins)) return void 0;
704
+ return raw;
705
+ } catch {
706
+ return void 0;
707
+ }
708
+ }
709
+ function writeStoredCatalog(catalogPath, catalog) {
710
+ mkdirSync2(dirname(catalogPath), { recursive: true });
711
+ writeFileSync(catalogPath, `${JSON.stringify(catalog, null, 2)}
712
+ `, "utf8");
713
+ }
714
+ function resolveManifest(cacheDir, platforms) {
715
+ for (const candidate of MANIFEST_PATHS) {
716
+ const manifestPath = join5(cacheDir, candidate.path);
717
+ if (!existsSync5(manifestPath)) continue;
718
+ if (candidate.platform) {
719
+ return { manifestPath, platform: candidate.platform };
720
+ }
721
+ if (platforms.includes("claude-code") || platforms.includes("copilot-cli")) {
722
+ return { manifestPath, platform: "claude-code" };
723
+ }
724
+ if (platforms.includes("cursor")) {
725
+ return { manifestPath, platform: "cursor" };
726
+ }
727
+ return void 0;
728
+ }
729
+ return void 0;
730
+ }
731
+ function parseManifest(platform, raw) {
732
+ switch (platform) {
733
+ case "claude-code":
734
+ return parseClaudeMarketplaceManifest(raw);
735
+ case "copilot-cli":
736
+ return parseClaudeMarketplaceManifest(raw);
737
+ case "cursor":
738
+ return parseCursorMarketplaceManifest(raw);
739
+ case "goose":
740
+ return { marketplaceName: "", plugins: [] };
741
+ default: {
742
+ const _exhaustive = platform;
743
+ return _exhaustive;
744
+ }
745
+ }
746
+ }
747
+ function catalogWithRegistryIdentity(parsed, registryName) {
748
+ const manifestName = parsed.marketplaceName.length > 0 && parsed.marketplaceName !== registryName ? parsed.marketplaceName : void 0;
749
+ return {
750
+ marketplaceName: registryName,
751
+ ...manifestName ? { manifestName } : {},
752
+ plugins: parsed.plugins.map((plugin) => ({
753
+ ...plugin,
754
+ ref: `${plugin.name}@${registryName}`
755
+ }))
756
+ };
757
+ }
758
+ function catalogRefreshEntry(harnesstapDir, name) {
759
+ const registered = listMarketplaces(harnesstapDir).find((entry) => entry.name === name);
760
+ if (registered) {
761
+ return registered;
762
+ }
763
+ const url = builtinMarketplaceGitUrl(name);
764
+ if (!url) {
765
+ return void 0;
766
+ }
767
+ return builtinMarketplaceEntry();
768
+ }
769
+ function parseCatalogFromDir(dir, platforms, registryName) {
770
+ const manifest = resolveManifest(dir, platforms);
771
+ if (!manifest) {
772
+ return {
773
+ ok: false,
774
+ message: "No marketplace manifest found (.claude-plugin/marketplace.json, .cursor-plugin/marketplace.json, or marketplace.json)."
775
+ };
776
+ }
777
+ let raw;
778
+ try {
779
+ raw = JSON.parse(readFileSync4(manifest.manifestPath, "utf8"));
780
+ } catch {
781
+ return { ok: false, message: "Failed to parse marketplace manifest JSON" };
782
+ }
783
+ return {
784
+ ok: true,
785
+ catalog: catalogWithRegistryIdentity(parseManifest(manifest.platform, raw), registryName)
786
+ };
787
+ }
788
+ function checkoutBranchName(dir) {
789
+ const result = runCommandWithTimeout("git", [
790
+ "-c",
791
+ "protocol.file.allow=always",
792
+ "-C",
793
+ dir,
794
+ "rev-parse",
795
+ "--abbrev-ref",
796
+ "HEAD"
797
+ ]);
798
+ const name = result.stdout.trim();
799
+ return result.exitCode === 0 && name && name !== "HEAD" ? name : "HEAD";
800
+ }
801
+ function versionsFromPlugins(plugins, branch) {
802
+ const rows = [];
803
+ for (const plugin of plugins) {
804
+ if (!plugin.version) continue;
805
+ rows.push({ name: plugin.name, version: plugin.version, branch });
806
+ }
807
+ return rows;
808
+ }
809
+ function refreshMarketplaceCatalog(harnesstapDir, options) {
810
+ const entry = catalogRefreshEntry(harnesstapDir, options.name);
811
+ if (!entry) {
812
+ return { ok: false, message: `Marketplace not found: ${options.name}` };
813
+ }
814
+ if (isGooseOnly(entry.platforms)) {
815
+ return {
816
+ ok: false,
817
+ message: "Marketplace catalog refresh is not supported for Goose-only marketplaces."
818
+ };
819
+ }
820
+ const cacheDir = marketplaceCacheDir(harnesstapDir, entry.name);
821
+ const catalogPath = marketplaceCatalogPath(harnesstapDir, entry.name);
822
+ const settings = loadSettings(harnesstapDir);
823
+ const maxAgeMs = marketplaceRefreshMaxAgeMs(
824
+ settings.plugins.marketplaceRefreshMaxAgeMinutes
825
+ );
826
+ if (!options.force && catalogIsFresh(catalogPath, maxAgeMs)) {
827
+ const stored2 = readStoredCatalog(catalogPath);
828
+ return {
829
+ ok: true,
830
+ message: "Catalog is up to date",
831
+ ...stored2?.sha ? { sha: stored2.sha } : {}
832
+ };
833
+ }
834
+ const refresh = refreshGitSource({
835
+ url: entry.url,
836
+ targetDir: cacheDir
837
+ });
838
+ if (!refresh.ok) {
839
+ return { ok: false, message: refresh.message };
840
+ }
841
+ const defaultCatalog = parseCatalogFromDir(cacheDir, entry.platforms, entry.name);
842
+ if (!defaultCatalog.ok) {
843
+ return defaultCatalog;
844
+ }
845
+ const defaultBranch = checkoutBranchName(cacheDir);
846
+ const extraBranches = parseTrackedBranches(entry.trackedBranches ?? []).filter(
847
+ (branch) => branch !== defaultBranch
848
+ );
849
+ const pluginVersions = versionsFromPlugins(defaultCatalog.catalog.plugins, defaultBranch);
850
+ const pluginBatches = [defaultCatalog.catalog.plugins];
851
+ for (const branch of extraBranches) {
852
+ const branchDir = mkdtempSync(join5(tmpdir(), "ht-mkt-branch-"));
853
+ try {
854
+ const branchRefresh = refreshGitSource({
855
+ url: entry.url,
856
+ targetDir: branchDir,
857
+ ref: branch
858
+ });
859
+ if (!branchRefresh.ok) {
860
+ return {
861
+ ok: false,
862
+ message: `Tracked branch "${branch}": ${branchRefresh.message}`
863
+ };
864
+ }
865
+ const branchCatalog = parseCatalogFromDir(branchDir, entry.platforms, entry.name);
866
+ if (!branchCatalog.ok) {
867
+ return {
868
+ ok: false,
869
+ message: `Tracked branch "${branch}": ${branchCatalog.message}`
870
+ };
871
+ }
872
+ pluginBatches.push(branchCatalog.catalog.plugins);
873
+ pluginVersions.push(...versionsFromPlugins(branchCatalog.catalog.plugins, branch));
874
+ } finally {
875
+ rmSync2(branchDir, { recursive: true, force: true });
876
+ }
877
+ }
878
+ const catalog = {
879
+ ...defaultCatalog.catalog,
880
+ plugins: enrichCatalogPlugins(
881
+ cacheDir,
882
+ mergeCatalogPluginsByIdentity(pluginBatches.flat())
883
+ )
884
+ };
885
+ const stored = {
886
+ ...catalog,
887
+ marketplaceEntryName: entry.name,
888
+ refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
889
+ indexVersion: MARKETPLACE_CATALOG_INDEX_VERSION,
890
+ ...refresh.sha ? { sha: refresh.sha } : {},
891
+ ...pluginVersions.length > 0 ? { pluginVersions } : {}
892
+ };
893
+ writeStoredCatalog(catalogPath, stored);
894
+ return {
895
+ ok: true,
896
+ message: refresh.message,
897
+ ...refresh.sha ? { sha: refresh.sha } : {}
898
+ };
899
+ }
900
+ function persistIndexedCatalog(harnesstapDir, name, stored) {
901
+ if (stored.indexVersion === MARKETPLACE_CATALOG_INDEX_VERSION) {
902
+ return stored;
903
+ }
904
+ const next = {
905
+ ...stored,
906
+ plugins: enrichCatalogPlugins(
907
+ marketplaceCacheDir(harnesstapDir, name),
908
+ stored.plugins
909
+ ),
910
+ indexVersion: MARKETPLACE_CATALOG_INDEX_VERSION
911
+ };
912
+ writeStoredCatalog(marketplaceCatalogPath(harnesstapDir, name), next);
913
+ return next;
914
+ }
915
+ function listCatalogPlugins(harnesstapDir, options) {
916
+ const stored = readStoredCatalog(marketplaceCatalogPath(harnesstapDir, options.name));
917
+ if (!stored) {
918
+ return [];
919
+ }
920
+ return persistIndexedCatalog(harnesstapDir, options.name, stored).plugins;
921
+ }
922
+ function ensureMarketplaceCatalog(harnesstapDir, options) {
923
+ refreshMarketplaceCatalog(harnesstapDir, {
924
+ name: options.name,
925
+ force: options.force ?? false
926
+ });
927
+ return listCatalogPlugins(harnesstapDir, { name: options.name });
928
+ }
929
+ function readMarketplaceManifest(root) {
930
+ const manifest = resolveManifest(root, ["claude-code", "cursor", "copilot-cli"]);
931
+ if (!manifest) return void 0;
932
+ try {
933
+ return JSON.parse(readFileSync4(manifest.manifestPath, "utf8"));
934
+ } catch {
935
+ return void 0;
936
+ }
937
+ }
938
+ function pluginMatchesQuery(plugin, query) {
939
+ return catalogPluginMatchesQuery(plugin, query);
940
+ }
941
+ function listCatalogSearchMarketplaces(harnesstapDir) {
942
+ const registered = listMarketplaces(harnesstapDir);
943
+ if (registered.some((entry) => builtinMarketplaceGitUrl(entry.name))) {
944
+ return registered;
945
+ }
946
+ return [...registered, builtinMarketplaceEntry()];
947
+ }
948
+ function searchCatalogPlugins(harnesstapDir, query, options = {}) {
949
+ const marketplaces = listCatalogSearchMarketplaces(harnesstapDir);
950
+ if (options.refresh) {
951
+ for (const marketplace of marketplaces) {
952
+ refreshMarketplaceCatalog(harnesstapDir, {
953
+ name: marketplace.name,
954
+ force: true
955
+ });
956
+ }
957
+ }
958
+ const trimmed = query.trim();
959
+ const results = [];
960
+ for (const marketplace of marketplaces) {
961
+ const plugins = listCatalogPlugins(harnesstapDir, { name: marketplace.name });
962
+ for (const plugin of plugins) {
963
+ if (!trimmed || pluginMatchesQuery(plugin, trimmed)) {
964
+ results.push(plugin);
965
+ }
966
+ }
967
+ }
968
+ return results;
969
+ }
970
+
971
+ export {
972
+ readJsonFile,
973
+ readFirstHostPluginManifest,
974
+ parsePluginRef,
975
+ DEFAULT_GIT_CLONE_TIMEOUT_MS,
976
+ runCommandWithTimeout,
977
+ refreshGitSource,
978
+ cursorRepoSourceKey,
979
+ cursorCacheRoot,
980
+ cursorLocalRoot,
981
+ cursorMarketplacesRoot,
982
+ cursorProjectsMcpsRoot,
983
+ isCursorPublicMarketplace,
984
+ builtinMarketplaceGitUrl,
985
+ builtinMarketplaceEntry,
986
+ normalizeMarketplaceUrl,
987
+ listMarketplaces,
988
+ addMarketplace,
989
+ removeMarketplace,
990
+ discoverSkillPackage,
991
+ marketplaceCacheDir,
992
+ refreshMarketplaceCatalog,
993
+ listCatalogPlugins,
994
+ ensureMarketplaceCatalog,
995
+ readMarketplaceManifest,
996
+ searchCatalogPlugins
997
+ };
998
+ //# sourceMappingURL=chunk-6BY4BV5G.js.map