plugins 0.4.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,237 +1,17 @@
1
- # plugins [![NPM version](https://badge.fury.io/js/plugins.svg)](http://badge.fury.io/js/plugins)
1
+ # plugins
2
2
 
3
- > Run a string through a plugin stack.
3
+ Install open-plugin format plugins into agent tools.
4
4
 
5
- ## Install
5
+ ## Usage
6
6
 
7
- Install with [npm](https://www.npmjs.com/)
8
-
9
- ```sh
10
- $ npm i plugins --save
11
- ```
12
-
13
- See [the examples](examples/).
14
-
15
- ## Table of contents
16
-
17
- <!-- toc -->
18
-
19
- * [Docs](#docs)
20
- * [Creating plugins](#creating-plugins)
21
- - [sync](#sync)
22
- - [async](#async)
23
- - [Directly run plugins](#directly-run-plugins)
24
- * [API](#api)
25
- * [Related projects](#related-projects)
26
- * [Running tests](#running-tests)
27
- * [Contributing](#contributing)
28
- * [Author](#author)
29
- * [License](#license)
30
-
31
- _(Table of contents generated by [verb])_
32
-
33
- <!-- tocstop -->
34
-
35
- ## Docs
36
-
37
- See [the examples](examples/).
38
-
39
- ## Creating plugins
40
-
41
- > A plugin can take any arguments and **must return a function**.
42
-
43
- ### sync
44
-
45
- Plugins just return a value.
46
-
47
- **Example:**
48
-
49
- ```js
50
- var plugins = new Plugins();
51
-
52
- plugins
53
- .use(function (str) {
54
- return str + 'a';
55
- })
56
- .use(function (str) {
57
- return str + 'b';
58
- })
59
- .use(function (str) {
60
- return str + 'c';
61
- });
62
-
63
- console.log(plugins.run('alphabet-'));
64
- //=> 'alphabet-abc'
65
- ```
66
-
67
- ### async
68
-
69
- Pass `next` as the last argument to run plugins asynchronously.
70
-
71
- **Example:**
72
-
73
- ```js
74
- var plugins = new Plugins();
75
-
76
- plugins
77
- .use(function (str, next) {
78
- next(null, str + 'a');
79
- })
80
- .use(function (str, next) {
81
- next(null, str + 'b');
82
- })
83
- .use(function (str, next) {
84
- next(null, str + 'c');
85
- });
86
-
87
- plugins.run('alphabet-', function (err, str) {
88
- console.log(str); //=> 'alphabet-abc'
89
- });
90
- ```
91
-
92
- ### Directly run plugins
93
-
94
- To run plugins **without** `.use()`, pass an array of functions as a section argument to `.run()`.
95
-
96
- **sync example:**
97
-
98
- ```js
99
- var plugins = new Plugins();
100
-
101
- var a = function(val) {
102
- return val + 'a';
103
- };
104
- var b = function(val) {
105
- return val + 'b';
106
- };
107
- var c = function(val) {
108
- return val + 'c';
109
- };
110
-
111
- console.log(plugins.run('alphabet-', [a, b, c]));
112
- //=> 'alphabet-abc'
113
- ```
114
-
115
- **async example:**
116
-
117
- ```js
118
- var plugins = new Plugins();
119
-
120
- var a = function (str, next) {
121
- next(null, str + 'a');
122
- };
123
- var b = function (str, next) {
124
- next(null, str + 'b');
125
- };
126
- var c = function (str, next) {
127
- next(null, str + 'c');
128
- };
129
-
130
- plugins.run('alphabet-', [a, b, c], function (err, str) {
131
- console.log(str); //=> 'alphabet-abc'
132
- });
133
- ```
134
-
135
- ## API
136
-
137
- See [the examples](examples/).
138
-
139
- ### [Plugins](index.js#L23)
140
-
141
- Initialize `Plugins`
142
-
143
- **Example**
144
-
145
- ```js
146
- var Plugins = require('plugins');
147
- var plugins = new Plugins();
7
+ ```bash
8
+ npx plugins add <repo-path-or-url>
148
9
  ```
149
10
 
150
- ### [.use](index.js#L57)
151
-
152
- Add a plugin `fn` to the `plugins` stack.
153
-
154
- **Params**
155
-
156
- * `fn` **{Function}**: Plugin function to add to the `plugins` stack.
157
- * `returns` **{Object}** `Plugins`: to enable chaining.
11
+ ## Development
158
12
 
159
- **Example**
160
-
161
- ```js
162
- plugins
163
- .use(foo)
164
- .use(bar)
165
- .use(baz)
13
+ ```bash
14
+ npm install
15
+ npm run build
16
+ node dist/index.js --help
166
17
  ```
167
-
168
- ### [.run](index.js#L73)
169
-
170
- Call each `fn` in the `plugins` stack to iterate over `val`.
171
-
172
- **Params**
173
-
174
- * `val` **{Array|Object|String}**: The value to iterate over.
175
-
176
- **Example**
177
-
178
- ```js
179
- plugins.run(value)
180
- ```
181
-
182
- ### [.iterator](index.js#L87)
183
-
184
- Register an iterator `fn` by its `type`.
185
-
186
- **Params**
187
-
188
- * `type` **{String}**: The iterator type.
189
- * `fn` **{Function}**: Iterator function
190
-
191
- ### [.pipeline](index.js#L103)
192
-
193
- Add each plugin to a pipeline to be used with streams. Plugins must either be a stream or a function that returns a stream.
194
-
195
- **Params**
196
-
197
- * `val` **{Array|Object|String}**: The value to iterate over.
198
-
199
- **Example**
200
-
201
- ```js
202
- var pipeline = plugins.pipeline(plugin());
203
- ```
204
-
205
- ## Related projects
206
-
207
- [async-array-reduce](https://github.com/jonschlinkert/async-array-reduce): Async reduce.
208
-
209
- ## Running tests
210
-
211
- Install dev dependencies:
212
-
213
- ```sh
214
- $ npm i -d && npm test
215
- ```
216
-
217
- ## Contributing
218
-
219
- Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/plugins/issues/new)
220
-
221
- ## Author
222
-
223
- **Jon Schlinkert**
224
-
225
- + [github/jonschlinkert](https://github.com/jonschlinkert)
226
- + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
227
-
228
- ## License
229
-
230
- Copyright © 2015 Jon Schlinkert
231
- Released under the MIT license.
232
-
233
- ***
234
-
235
- _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 14, 2015._
236
-
237
- [verb]: https://github.com/assemble/verb
package/dist/index.js ADDED
@@ -0,0 +1,737 @@
1
+ #!/usr/bin/env node
2
+
3
+ // index.ts
4
+ import { parseArgs } from "util";
5
+ import { resolve, join as join4 } from "path";
6
+ import { execSync as execSync3 } from "child_process";
7
+ import { existsSync as existsSync3, rmSync, mkdirSync } from "fs";
8
+ import { createInterface } from "readline";
9
+
10
+ // lib/discover.ts
11
+ import { join } from "path";
12
+ import { readFile, readdir, stat } from "fs/promises";
13
+ import { existsSync } from "fs";
14
+ async function discover(repoPath) {
15
+ const marketplacePaths = [
16
+ join(repoPath, "marketplace.json"),
17
+ join(repoPath, ".plugin", "marketplace.json"),
18
+ join(repoPath, ".claude-plugin", "marketplace.json"),
19
+ join(repoPath, ".cursor-plugin", "marketplace.json")
20
+ ];
21
+ for (const mp of marketplacePaths) {
22
+ if (await fileExists(mp)) {
23
+ const data = await readJson(mp);
24
+ if (data && typeof data === "object" && "plugins" in data && Array.isArray(data.plugins)) {
25
+ return discoverFromMarketplace(repoPath, data);
26
+ }
27
+ }
28
+ }
29
+ if (await isPluginDir(repoPath)) {
30
+ const plugin = await inspectPlugin(repoPath);
31
+ return plugin ? [plugin] : [];
32
+ }
33
+ const plugins = [];
34
+ await scanForPlugins(repoPath, plugins, 2);
35
+ return plugins;
36
+ }
37
+ async function scanForPlugins(dirPath, results, depth) {
38
+ if (depth <= 0) return;
39
+ const entries = await readDirSafe(dirPath);
40
+ for (const entry of entries) {
41
+ if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
42
+ const childPath = join(dirPath, entry.name);
43
+ if (await isPluginDir(childPath)) {
44
+ const plugin = await inspectPlugin(childPath);
45
+ if (plugin) results.push(plugin);
46
+ } else {
47
+ await scanForPlugins(childPath, results, depth - 1);
48
+ }
49
+ }
50
+ }
51
+ async function discoverFromMarketplace(repoPath, marketplace) {
52
+ const plugins = [];
53
+ const root = marketplace.metadata?.pluginRoot ?? ".";
54
+ for (const entry of marketplace.plugins) {
55
+ const sourcePath = join(repoPath, root, entry.source.replace(/^\.\//, ""));
56
+ if (!await dirExists(sourcePath)) {
57
+ console.warn(` Warning: plugin source not found: ${entry.source}`);
58
+ continue;
59
+ }
60
+ let skills;
61
+ if (entry.skills && Array.isArray(entry.skills)) {
62
+ skills = [];
63
+ for (const skillPath of entry.skills) {
64
+ const resolvedPath = join(repoPath, root, skillPath.replace(/^\.\//, ""));
65
+ const skillMd = join(resolvedPath, "SKILL.md");
66
+ if (await fileExists(skillMd)) {
67
+ const content = await readFile(skillMd, "utf-8");
68
+ const fm = parseFrontmatter(content);
69
+ skills.push({
70
+ name: fm.name ?? dirName(resolvedPath),
71
+ description: fm.description ?? ""
72
+ });
73
+ }
74
+ }
75
+ } else {
76
+ skills = await discoverSkills(sourcePath);
77
+ }
78
+ let manifest = null;
79
+ for (const manifestDir of [".plugin", ".claude-plugin", ".cursor-plugin"]) {
80
+ const manifestPath = join(sourcePath, manifestDir, "plugin.json");
81
+ if (await fileExists(manifestPath)) {
82
+ manifest = await readJson(manifestPath);
83
+ break;
84
+ }
85
+ }
86
+ const [commands, agents, rules, hasHooks, hasMcp, hasLsp] = await Promise.all([
87
+ discoverCommands(sourcePath),
88
+ discoverAgents(sourcePath),
89
+ discoverRules(sourcePath),
90
+ fileExists(join(sourcePath, "hooks", "hooks.json")),
91
+ fileExists(join(sourcePath, ".mcp.json")),
92
+ fileExists(join(sourcePath, ".lsp.json"))
93
+ ]);
94
+ const name = entry.name || manifest?.name || dirName(sourcePath);
95
+ plugins.push({
96
+ name,
97
+ version: entry.version || manifest?.version || void 0,
98
+ description: entry.description || manifest?.description || void 0,
99
+ path: sourcePath,
100
+ marketplace: marketplace.name,
101
+ skills,
102
+ commands,
103
+ agents,
104
+ rules,
105
+ hasHooks,
106
+ hasMcp,
107
+ hasLsp,
108
+ manifest,
109
+ explicitSkillPaths: entry.skills,
110
+ marketplaceEntry: entry
111
+ });
112
+ }
113
+ return plugins;
114
+ }
115
+ async function isPluginDir(dirPath) {
116
+ const checks = [
117
+ join(dirPath, ".plugin", "plugin.json"),
118
+ join(dirPath, ".claude-plugin", "plugin.json"),
119
+ join(dirPath, ".cursor-plugin", "plugin.json"),
120
+ join(dirPath, "skills"),
121
+ join(dirPath, "commands"),
122
+ join(dirPath, "agents"),
123
+ join(dirPath, "SKILL.md")
124
+ ];
125
+ for (const check of checks) {
126
+ if (await pathExists(check)) return true;
127
+ }
128
+ return false;
129
+ }
130
+ async function inspectPlugin(pluginPath) {
131
+ let manifest = null;
132
+ for (const manifestDir of [".plugin", ".claude-plugin", ".cursor-plugin"]) {
133
+ const manifestPath = join(pluginPath, manifestDir, "plugin.json");
134
+ if (await fileExists(manifestPath)) {
135
+ manifest = await readJson(manifestPath);
136
+ break;
137
+ }
138
+ }
139
+ const name = manifest?.name ?? dirName(pluginPath);
140
+ const [skills, commands, agents, rules, hasHooks, hasMcp, hasLsp] = await Promise.all([
141
+ discoverSkills(pluginPath),
142
+ discoverCommands(pluginPath),
143
+ discoverAgents(pluginPath),
144
+ discoverRules(pluginPath),
145
+ fileExists(join(pluginPath, "hooks", "hooks.json")),
146
+ fileExists(join(pluginPath, ".mcp.json")),
147
+ fileExists(join(pluginPath, ".lsp.json"))
148
+ ]);
149
+ return {
150
+ name,
151
+ version: manifest?.version,
152
+ description: manifest?.description,
153
+ path: pluginPath,
154
+ marketplace: void 0,
155
+ skills,
156
+ commands,
157
+ agents,
158
+ rules,
159
+ hasHooks,
160
+ hasMcp,
161
+ hasLsp,
162
+ manifest,
163
+ explicitSkillPaths: void 0,
164
+ marketplaceEntry: void 0
165
+ };
166
+ }
167
+ async function discoverSkills(pluginPath) {
168
+ const skillsDir = join(pluginPath, "skills");
169
+ const entries = await readDirSafe(skillsDir);
170
+ const skills = [];
171
+ for (const entry of entries) {
172
+ if (!entry.isDirectory()) continue;
173
+ const skillMd = join(skillsDir, entry.name, "SKILL.md");
174
+ if (await fileExists(skillMd)) {
175
+ const content = await readFile(skillMd, "utf-8");
176
+ const fm = parseFrontmatter(content);
177
+ skills.push({
178
+ name: fm.name ?? entry.name,
179
+ description: fm.description ?? ""
180
+ });
181
+ }
182
+ }
183
+ if (skills.length === 0) {
184
+ const rootSkill = join(pluginPath, "SKILL.md");
185
+ if (await fileExists(rootSkill)) {
186
+ const content = await readFile(rootSkill, "utf-8");
187
+ const fm = parseFrontmatter(content);
188
+ skills.push({
189
+ name: fm.name ?? dirName(pluginPath),
190
+ description: fm.description ?? ""
191
+ });
192
+ }
193
+ }
194
+ return skills;
195
+ }
196
+ async function discoverCommands(pluginPath) {
197
+ const commandsDir = join(pluginPath, "commands");
198
+ const entries = await readDirSafe(commandsDir);
199
+ const commands = [];
200
+ for (const entry of entries) {
201
+ if (!entry.isFile() || !entry.name.match(/\.(md|mdc|markdown)$/)) continue;
202
+ const filePath = join(commandsDir, entry.name);
203
+ const content = await readFile(filePath, "utf-8");
204
+ const fm = parseFrontmatter(content);
205
+ commands.push({
206
+ name: entry.name.replace(/\.(md|mdc|markdown)$/, ""),
207
+ description: fm.description ?? ""
208
+ });
209
+ }
210
+ return commands;
211
+ }
212
+ async function discoverAgents(pluginPath) {
213
+ const agentsDir = join(pluginPath, "agents");
214
+ const entries = await readDirSafe(agentsDir);
215
+ const agents = [];
216
+ for (const entry of entries) {
217
+ if (!entry.isFile() || !entry.name.match(/\.(md|mdc|markdown)$/)) continue;
218
+ const filePath = join(agentsDir, entry.name);
219
+ const content = await readFile(filePath, "utf-8");
220
+ const fm = parseFrontmatter(content);
221
+ if (fm.name && fm.description) {
222
+ agents.push({
223
+ name: fm.name,
224
+ description: fm.description
225
+ });
226
+ }
227
+ }
228
+ return agents;
229
+ }
230
+ async function discoverRules(pluginPath) {
231
+ const rulesDir = join(pluginPath, "rules");
232
+ const entries = await readDirSafe(rulesDir);
233
+ const rules = [];
234
+ for (const entry of entries) {
235
+ if (!entry.isFile() || !entry.name.match(/\.(mdc|md|markdown)$/)) continue;
236
+ const filePath = join(rulesDir, entry.name);
237
+ const content = await readFile(filePath, "utf-8");
238
+ const fm = parseFrontmatter(content);
239
+ rules.push({
240
+ name: entry.name.replace(/\.(mdc|md|markdown)$/, ""),
241
+ description: fm.description ?? ""
242
+ });
243
+ }
244
+ return rules;
245
+ }
246
+ function parseFrontmatter(content) {
247
+ const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
248
+ if (!match?.[1]) return {};
249
+ const result = {};
250
+ for (const line of match[1].split("\n")) {
251
+ const kv = line.match(/^(\w[\w-]*):\s*(.+)$/);
252
+ if (kv) {
253
+ let val = kv[2].trim();
254
+ if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
255
+ val = val.slice(1, -1);
256
+ }
257
+ if (val === "true") {
258
+ result[kv[1]] = true;
259
+ } else if (val === "false") {
260
+ result[kv[1]] = false;
261
+ } else {
262
+ result[kv[1]] = val;
263
+ }
264
+ }
265
+ }
266
+ return result;
267
+ }
268
+ function dirName(p) {
269
+ const parts = p.replace(/\/$/, "").split("/");
270
+ return parts[parts.length - 1] ?? "unknown";
271
+ }
272
+ async function fileExists(path) {
273
+ try {
274
+ const s = await stat(path);
275
+ return s.isFile();
276
+ } catch {
277
+ return false;
278
+ }
279
+ }
280
+ async function dirExists(dirPath) {
281
+ try {
282
+ const s = await stat(dirPath);
283
+ return s.isDirectory();
284
+ } catch {
285
+ return false;
286
+ }
287
+ }
288
+ async function pathExists(p) {
289
+ return existsSync(p);
290
+ }
291
+ async function readJson(path) {
292
+ try {
293
+ const content = await readFile(path, "utf-8");
294
+ return JSON.parse(content);
295
+ } catch {
296
+ return null;
297
+ }
298
+ }
299
+ async function readDirSafe(dirPath) {
300
+ try {
301
+ return await readdir(dirPath, { withFileTypes: true });
302
+ } catch {
303
+ return [];
304
+ }
305
+ }
306
+
307
+ // lib/targets.ts
308
+ import { join as join2 } from "path";
309
+ import { homedir } from "os";
310
+ import { execSync } from "child_process";
311
+ var HOME = homedir();
312
+ var TARGET_DEFS = [
313
+ {
314
+ id: "claude-code",
315
+ name: "Claude Code",
316
+ description: "Anthropic's CLI coding agent",
317
+ configPath: join2(HOME, ".claude")
318
+ },
319
+ {
320
+ id: "cursor",
321
+ name: "Cursor",
322
+ description: "AI-powered code editor",
323
+ configPath: join2(HOME, ".cursor")
324
+ }
325
+ // Future targets can be added here:
326
+ // {
327
+ // id: "opencode",
328
+ // name: "OpenCode",
329
+ // description: "Open-source coding agent",
330
+ // configPath: join(HOME, ".config", "opencode"),
331
+ // },
332
+ ];
333
+ async function getTargets() {
334
+ const targets = [];
335
+ for (const def of TARGET_DEFS) {
336
+ const detected = detectTarget(def);
337
+ targets.push({ ...def, detected });
338
+ }
339
+ return targets;
340
+ }
341
+ function detectTarget(def) {
342
+ switch (def.id) {
343
+ case "claude-code":
344
+ return detectBinary("claude");
345
+ case "cursor":
346
+ return detectBinary("cursor") && detectBinary("claude");
347
+ default:
348
+ return false;
349
+ }
350
+ }
351
+ function detectBinary(name) {
352
+ try {
353
+ execSync(`which ${name}`, { stdio: "pipe" });
354
+ return true;
355
+ } catch {
356
+ return false;
357
+ }
358
+ }
359
+
360
+ // lib/install.ts
361
+ import { join as join3, relative } from "path";
362
+ import { mkdir, cp, readFile as readFile2, writeFile } from "fs/promises";
363
+ import { existsSync as existsSync2 } from "fs";
364
+ import { execSync as execSync2 } from "child_process";
365
+ import { homedir as homedir2 } from "os";
366
+ function installerKey(targetId) {
367
+ switch (targetId) {
368
+ case "claude-code":
369
+ case "cursor":
370
+ return "claude-code";
371
+ default:
372
+ return targetId;
373
+ }
374
+ }
375
+ var completedInstallers = /* @__PURE__ */ new Set();
376
+ async function installPlugins(plugins, target, scope, repoPath, source) {
377
+ const key = installerKey(target.id);
378
+ if (completedInstallers.has(key)) {
379
+ return;
380
+ }
381
+ switch (key) {
382
+ case "claude-code":
383
+ await installToClaudeCode(plugins, scope, repoPath, source);
384
+ break;
385
+ default:
386
+ throw new Error(`Unsupported target: ${target.id}`);
387
+ }
388
+ completedInstallers.add(key);
389
+ }
390
+ async function installToClaudeCode(plugins, scope, repoPath, source) {
391
+ const marketplaceName = plugins[0]?.marketplace ?? deriveMarketplaceName(source);
392
+ console.log("\nPreparing plugins for Claude Code...");
393
+ await prepareForClaudeCode(plugins, repoPath, marketplaceName);
394
+ const claudePath = findClaude();
395
+ console.log(`Adding marketplace from local path: ${repoPath}`);
396
+ console.log(` Using claude binary: ${claudePath}`);
397
+ try {
398
+ const version = execSync2(`${claudePath} --version`, { encoding: "utf-8", stdio: "pipe" }).trim();
399
+ console.log(` Claude Code version: ${version}`);
400
+ } catch {
401
+ console.log(` Warning: could not get claude version`);
402
+ }
403
+ try {
404
+ const result = execSync2(`${claudePath} plugin marketplace add ${repoPath}`, {
405
+ encoding: "utf-8",
406
+ stdio: "pipe"
407
+ });
408
+ console.log(" Marketplace added.");
409
+ if (result.trim()) console.log(` Output: ${result.trim()}`);
410
+ } catch (err) {
411
+ const stderr = err.stderr?.toString().trim() ?? "";
412
+ const stdout = err.stdout?.toString().trim() ?? "";
413
+ if (stderr.includes("already") || stdout.includes("already")) {
414
+ console.log(" Marketplace already registered.");
415
+ } else {
416
+ console.error(`Failed to add marketplace.`);
417
+ console.error(` Command: ${claudePath} plugin marketplace add ${repoPath}`);
418
+ console.error(` stdout: ${stdout}`);
419
+ console.error(` stderr: ${stderr}`);
420
+ console.error(` exit code: ${err.status}`);
421
+ process.exit(1);
422
+ }
423
+ }
424
+ for (const plugin of plugins) {
425
+ const pluginRef = `${plugin.name}@${marketplaceName}`;
426
+ console.log(`
427
+ Installing ${pluginRef}...`);
428
+ try {
429
+ execSync2(`${claudePath} plugin install ${pluginRef} --scope ${scope}`, {
430
+ encoding: "utf-8",
431
+ stdio: "pipe"
432
+ });
433
+ console.log(` Installed.`);
434
+ } catch (err) {
435
+ const stderr = err.stderr?.toString().trim() ?? "";
436
+ const stdout = err.stdout?.toString().trim() ?? "";
437
+ if (stderr.includes("already") || stdout.includes("already")) {
438
+ console.log(` Already installed.`);
439
+ } else {
440
+ console.error(` Failed to install ${pluginRef}.`);
441
+ console.error(` Command: ${claudePath} plugin install ${pluginRef} --scope ${scope}`);
442
+ console.error(` stdout: ${stdout}`);
443
+ console.error(` stderr: ${stderr}`);
444
+ console.error(` exit code: ${err.status}`);
445
+ }
446
+ }
447
+ }
448
+ }
449
+ async function prepareForClaudeCode(plugins, repoPath, marketplaceName) {
450
+ const claudePluginDir = join3(repoPath, ".claude-plugin");
451
+ await mkdir(claudePluginDir, { recursive: true });
452
+ const marketplaceJson = {
453
+ name: marketplaceName,
454
+ owner: { name: "plugins" },
455
+ plugins: plugins.map((p) => {
456
+ const rel = relative(repoPath, p.path);
457
+ const sourcePath = rel === "" ? "./" : `./${rel}`;
458
+ const entry = {
459
+ name: p.name,
460
+ source: sourcePath,
461
+ description: p.description ?? ""
462
+ };
463
+ if (p.version) entry.version = p.version;
464
+ if (p.manifest?.author) entry.author = p.manifest.author;
465
+ if (p.manifest?.license) entry.license = p.manifest.license;
466
+ if (p.manifest?.keywords) entry.keywords = p.manifest.keywords;
467
+ return entry;
468
+ })
469
+ };
470
+ await writeFile(
471
+ join3(claudePluginDir, "marketplace.json"),
472
+ JSON.stringify(marketplaceJson, null, 2)
473
+ );
474
+ console.log(" Generated .claude-plugin/marketplace.json");
475
+ for (const plugin of plugins) {
476
+ await preparePluginDirForVendor(plugin, ".claude-plugin", "CLAUDE_PLUGIN_ROOT");
477
+ }
478
+ }
479
+ function findClaude() {
480
+ try {
481
+ const path = execSync2("which claude", { encoding: "utf-8", stdio: "pipe" }).trim();
482
+ if (path) return path;
483
+ } catch {
484
+ }
485
+ const home = homedir2();
486
+ const candidates = [
487
+ join3(home, ".local", "bin", "claude"),
488
+ join3(home, ".bun", "bin", "claude"),
489
+ "/usr/local/bin/claude"
490
+ ];
491
+ for (const candidate of candidates) {
492
+ if (existsSync2(candidate)) return candidate;
493
+ }
494
+ return "claude";
495
+ }
496
+ async function preparePluginDirForVendor(plugin, vendorDir, envVar) {
497
+ const pluginPath = plugin.path;
498
+ const openPluginDir = join3(pluginPath, ".plugin");
499
+ const vendorPluginDir = join3(pluginPath, vendorDir);
500
+ const hasOpenPlugin = existsSync2(join3(openPluginDir, "plugin.json"));
501
+ const hasVendorPlugin = existsSync2(join3(vendorPluginDir, "plugin.json"));
502
+ if (hasOpenPlugin && !hasVendorPlugin) {
503
+ await cp(openPluginDir, vendorPluginDir, { recursive: true });
504
+ console.log(` ${plugin.name}: translated .plugin/ -> ${vendorDir}/`);
505
+ }
506
+ if (!hasOpenPlugin && !hasVendorPlugin) {
507
+ await mkdir(vendorPluginDir, { recursive: true });
508
+ await writeFile(
509
+ join3(vendorPluginDir, "plugin.json"),
510
+ JSON.stringify(
511
+ {
512
+ name: plugin.name,
513
+ description: plugin.description ?? "",
514
+ version: plugin.version ?? "0.0.0"
515
+ },
516
+ null,
517
+ 2
518
+ )
519
+ );
520
+ console.log(` ${plugin.name}: generated ${vendorDir}/plugin.json`);
521
+ }
522
+ await translateEnvVars(pluginPath, plugin.name, envVar);
523
+ }
524
+ var KNOWN_PLUGIN_ROOT_VARS = [
525
+ "PLUGIN_ROOT",
526
+ "CLAUDE_PLUGIN_ROOT",
527
+ "CURSOR_PLUGIN_ROOT"
528
+ ];
529
+ async function translateEnvVars(pluginPath, pluginName, envVar) {
530
+ const configFiles = [
531
+ join3(pluginPath, "hooks", "hooks.json"),
532
+ join3(pluginPath, ".mcp.json"),
533
+ join3(pluginPath, ".lsp.json")
534
+ ];
535
+ const target = `\${${envVar}}`;
536
+ const patterns = KNOWN_PLUGIN_ROOT_VARS.filter((v) => v !== envVar).map((v) => `\${${v}}`);
537
+ for (const filePath of configFiles) {
538
+ if (!existsSync2(filePath)) continue;
539
+ let content = await readFile2(filePath, "utf-8");
540
+ let changed = false;
541
+ for (const pattern of patterns) {
542
+ if (content.includes(pattern)) {
543
+ content = content.replaceAll(pattern, target);
544
+ changed = true;
545
+ }
546
+ }
547
+ if (changed) {
548
+ await writeFile(filePath, content);
549
+ console.log(
550
+ ` ${pluginName}: translated plugin root -> \${${envVar}} in ${filePath.split("/").pop()}`
551
+ );
552
+ }
553
+ }
554
+ }
555
+ function deriveMarketplaceName(source) {
556
+ if (source.match(/^[\w-]+\/[\w.-]+$/)) {
557
+ return source.replace("/", "-");
558
+ }
559
+ try {
560
+ const url = new URL(source);
561
+ const parts2 = url.pathname.replace(/\.git$/, "").split("/").filter(Boolean);
562
+ if (parts2.length >= 2) {
563
+ return `${parts2[parts2.length - 2]}-${parts2[parts2.length - 1]}`;
564
+ }
565
+ } catch {
566
+ }
567
+ const parts = source.replace(/\/$/, "").split("/");
568
+ return parts[parts.length - 1] ?? "plugins";
569
+ }
570
+
571
+ // index.ts
572
+ var { values, positionals } = parseArgs({
573
+ args: process.argv.slice(2),
574
+ options: {
575
+ help: { type: "boolean", short: "h" },
576
+ target: { type: "string", short: "t" },
577
+ scope: { type: "string", short: "s", default: "user" },
578
+ yes: { type: "boolean", short: "y" }
579
+ },
580
+ allowPositionals: true,
581
+ strict: true
582
+ });
583
+ var [command, ...rest] = positionals;
584
+ if (values.help || !command) {
585
+ printUsage();
586
+ process.exit(0);
587
+ }
588
+ switch (command) {
589
+ case "add":
590
+ await cmdInstall(rest[0], values);
591
+ break;
592
+ case "discover":
593
+ await cmdDiscover(rest[0]);
594
+ break;
595
+ case "targets":
596
+ await cmdTargets();
597
+ break;
598
+ default:
599
+ await cmdInstall(command, values);
600
+ }
601
+ function printUsage() {
602
+ console.log(`
603
+ plugins - Install open-plugin format plugins into agent tools
604
+
605
+ Usage:
606
+ plugins add <repo-path-or-url> Install plugins from a repo
607
+ plugins discover <repo-path-or-url> Discover plugins in a repo
608
+ plugins targets List available install targets
609
+ plugins <repo-path-or-url> Shorthand for add
610
+
611
+ Options:
612
+ -t, --target <target> Target tool (e.g. claude-code). Default: auto-detect
613
+ -s, --scope <scope> Install scope: user, project, local. Default: user
614
+ -y, --yes Skip confirmation prompts
615
+ -h, --help Show this help
616
+ `);
617
+ }
618
+ async function cmdDiscover(source) {
619
+ if (!source) {
620
+ console.error("Error: provide a repo path or URL");
621
+ process.exit(1);
622
+ }
623
+ const repoPath = resolveSource(source);
624
+ const plugins = await discover(repoPath);
625
+ if (plugins.length === 0) {
626
+ console.log("No plugins found.");
627
+ return;
628
+ }
629
+ console.log(`Found ${plugins.length} plugin(s) in ${source}:
630
+ `);
631
+ for (const p of plugins) {
632
+ printPlugin(p);
633
+ }
634
+ }
635
+ async function cmdTargets() {
636
+ const targets = await getTargets();
637
+ if (targets.length === 0) {
638
+ console.log("No supported targets detected.");
639
+ return;
640
+ }
641
+ console.log("Available install targets:\n");
642
+ for (const t of targets) {
643
+ console.log(` ${t.name}`);
644
+ console.log(` ${t.description}`);
645
+ console.log(` Config: ${t.configPath}`);
646
+ console.log(` Status: ${t.detected ? "detected" : "not found"}`);
647
+ console.log();
648
+ }
649
+ }
650
+ async function cmdInstall(source, opts) {
651
+ if (!source) {
652
+ console.error("Error: provide a repo path or URL");
653
+ process.exit(1);
654
+ }
655
+ const repoPath = resolveSource(source);
656
+ const plugins = await discover(repoPath);
657
+ if (plugins.length === 0) {
658
+ console.log("No plugins found.");
659
+ return;
660
+ }
661
+ const targets = await getTargets();
662
+ const detectedTargets = targets.filter((t) => t.detected);
663
+ let installTargets;
664
+ if (opts.target) {
665
+ const found = targets.find((t) => t.id === opts.target);
666
+ if (!found) {
667
+ console.error(`Unknown target: ${opts.target}`);
668
+ console.error(`Available: ${targets.map((t) => t.id).join(", ")}`);
669
+ process.exit(1);
670
+ }
671
+ installTargets = [found];
672
+ } else if (detectedTargets.length === 0) {
673
+ console.error("No supported targets detected. Use --target to specify one.");
674
+ process.exit(1);
675
+ } else {
676
+ installTargets = detectedTargets;
677
+ }
678
+ console.log(`Found ${plugins.length} plugin(s):
679
+ `);
680
+ for (const p of plugins) {
681
+ printPlugin(p);
682
+ }
683
+ console.log(`Targets: ${installTargets.map((t) => t.name).join(", ")}`);
684
+ console.log(`Scope: ${opts.scope ?? "user"}
685
+ `);
686
+ if (!opts.yes) {
687
+ const response = await readLine("Install? [y/N] ");
688
+ if (response.trim().toLowerCase() !== "y") {
689
+ console.log("Aborted.");
690
+ return;
691
+ }
692
+ }
693
+ const scope = opts.scope ?? "user";
694
+ for (const target of installTargets) {
695
+ await installPlugins(plugins, target, scope, repoPath, source);
696
+ }
697
+ console.log("\nDone. Restart your agent tools to load the plugins.");
698
+ }
699
+ function printPlugin(p) {
700
+ console.log(` ${p.name} (v${p.version ?? "0.0.0"})`);
701
+ if (p.description) console.log(` ${p.description}`);
702
+ const parts = [];
703
+ if (p.skills.length) parts.push(`${p.skills.length} skill(s)`);
704
+ if (p.commands.length) parts.push(`${p.commands.length} command(s)`);
705
+ if (p.agents.length) parts.push(`${p.agents.length} agent(s)`);
706
+ if (p.rules.length) parts.push(`${p.rules.length} rule(s)`);
707
+ if (p.hasHooks) parts.push("hooks");
708
+ if (p.hasMcp) parts.push("MCP servers");
709
+ if (p.hasLsp) parts.push("LSP servers");
710
+ if (parts.length) console.log(` Components: ${parts.join(", ")}`);
711
+ console.log();
712
+ }
713
+ function resolveSource(source) {
714
+ if (source.startsWith("https://") || source.startsWith("git@") || source.match(/^[\w-]+\/[\w.-]+$/)) {
715
+ const url = source.match(/^[\w-]+\/[\w.-]+$/) ? `https://github.com/${source}` : source;
716
+ const cacheDir = join4(process.env.HOME ?? "~", ".cache", "plugins");
717
+ mkdirSync(cacheDir, { recursive: true });
718
+ const slug = url.replace(/^https?:\/\//, "").replace(/\.git$/, "").replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
719
+ const tmpDir = join4(cacheDir, slug);
720
+ if (existsSync3(join4(tmpDir, ".git", "HEAD"))) {
721
+ rmSync(tmpDir, { recursive: true, force: true });
722
+ }
723
+ console.log(`Cloning ${url}...`);
724
+ execSync3(`git clone --depth 1 -q ${url} ${tmpDir}`, { stdio: "inherit" });
725
+ return tmpDir;
726
+ }
727
+ return resolve(source);
728
+ }
729
+ function readLine(prompt) {
730
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
731
+ return new Promise((resolve2) => {
732
+ rl.question(prompt, (answer) => {
733
+ rl.close();
734
+ resolve2(answer);
735
+ });
736
+ });
737
+ }
package/package.json CHANGED
@@ -1,49 +1,20 @@
1
1
  {
2
2
  "name": "plugins",
3
- "description": "Run a string through a plugin stack.",
4
- "version": "0.4.1",
5
- "homepage": "https://github.com/jonschlinkert/plugins",
6
- "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7
- "repository": "jonschlinkert/plugins",
8
- "bugs": {
9
- "url": "https://github.com/jonschlinkert/plugins/issues"
3
+ "version": "1.0.0",
4
+ "description": "Install open-plugin format plugins into agent tools",
5
+ "type": "module",
6
+ "bin": {
7
+ "plugins": "dist/index.js"
10
8
  },
11
- "license": "MIT",
12
9
  "files": [
13
- "index.js",
14
- "iterators.js"
10
+ "dist"
15
11
  ],
16
- "main": "index.js",
17
- "engines": {
18
- "node": ">=0.10.0"
19
- },
20
12
  "scripts": {
21
- "test": "mocha"
13
+ "build": "tsup",
14
+ "start": "node dist/index.js"
22
15
  },
23
16
  "devDependencies": {
24
- "fs-utils": "^0.6.0",
25
- "mocha": "^2.2.5",
26
- "should": "^7.0.4"
27
- },
28
- "dependencies": {
29
- "async-array-reduce": "^0.1.0",
30
- "event-stream": "^3.3.1"
31
- },
32
- "keywords": [
33
- "extension",
34
- "extensions",
35
- "helper",
36
- "helpers",
37
- "middleware",
38
- "use",
39
- "plugin",
40
- "fn",
41
- "fns",
42
- "plugins"
43
- ],
44
- "verb": {
45
- "related": {
46
- "list": "async-array-reduce"
47
- }
17
+ "tsup": "^8",
18
+ "typescript": "^5"
48
19
  }
49
- }
20
+ }
package/LICENSE DELETED
@@ -1,24 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014, 2015 Jon Schlinkert.
4
-
5
- Permission is hereby granted, free of charge, to any person
6
- obtaining a copy of this software and associated documentation
7
- files (the "Software"), to deal in the Software without
8
- restriction, including without limitation the rights to use,
9
- copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the
11
- Software is furnished to do so, subject to the following
12
- conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
- OTHER DEALINGS IN THE SOFTWARE.
package/index.js DELETED
@@ -1,119 +0,0 @@
1
- /*!
2
- * plugins <https://github.com/jonschlinkert/plugins>
3
- *
4
- * Copyright (c) 2014 Jon Schlinkert, contributors.
5
- * Licensed under the MIT License
6
- */
7
-
8
- 'use strict';
9
-
10
- var iterators = require('./iterators');
11
-
12
- /**
13
- * Initialize `Plugins`
14
- *
15
- * ```js
16
- * var Plugins = require('plugins');
17
- * var plugins = new Plugins();
18
- * ```
19
- * @constructor
20
- * @api public
21
- */
22
-
23
- function Plugins(options) {
24
- if (!(this instanceof Plugins)) {
25
- return new Plugins(options);
26
- }
27
- this.iterators = {};
28
- this.fns = [];
29
- this.init();
30
- }
31
-
32
- /**
33
- * Register default iterators
34
- */
35
-
36
- Plugins.prototype.init = function() {
37
- this.iterator('async', iterators.async.bind(this));
38
- this.iterator('stream', iterators.stream.bind(this));
39
- this.iterator('sync', iterators.sync.bind(this));
40
- };
41
-
42
- /**
43
- * Add a plugin `fn` to the `plugins` stack.
44
- *
45
- * ```js
46
- * plugins
47
- * .use(foo)
48
- * .use(bar)
49
- * .use(baz)
50
- * ```
51
- *
52
- * @param {Function} `fn` Plugin function to add to the `plugins` stack.
53
- * @return {Object} `Plugins` to enable chaining.
54
- * @api public
55
- */
56
-
57
- Plugins.prototype.use = function (fn) {
58
- this.fns.push(fn);
59
- return this;
60
- };
61
-
62
- /**
63
- * Call each `fn` in the `plugins` stack
64
- * to iterate over `val`.
65
- *
66
- * ```js
67
- * plugins.run(value)
68
- * ```
69
- * @param {Array|Object|String} `val` The value to iterate over.
70
- * @api public
71
- */
72
-
73
- Plugins.prototype.run = function () {
74
- var last = arguments[arguments.length - 1];
75
- var type = isFunction(last) ? 'async' : 'sync';
76
- return this.iterators[type].apply(this, arguments);
77
- };
78
-
79
- /**
80
- * Register an iterator `fn` by its `type`.
81
- *
82
- * @param {String} `type` The iterator type.
83
- * @param {Function} `fn` Iterator function
84
- * @api public
85
- */
86
-
87
- Plugins.prototype.iterator = function(type, fn) {
88
- this.iterators[type] = fn;
89
- return this;
90
- };
91
-
92
- /**
93
- * Add each plugin to a pipeline to be used with streams.
94
- * Plugins must either be a stream or a function that returns a stream.
95
- *
96
- * ```js
97
- * var pipeline = plugins.pipeline(plugin());
98
- * ```
99
- * @param {Array|Object|String} `val` The value to iterate over.
100
- * @api public
101
- */
102
-
103
- Plugins.prototype.pipeline = function() {
104
- return this.iterators.stream.apply(this, arguments);
105
- };
106
-
107
- /**
108
- * Utilities
109
- */
110
-
111
- function isFunction(val) {
112
- return typeof val === 'function';
113
- }
114
-
115
- /**
116
- * Expose `Plugins`
117
- */
118
-
119
- module.exports = Plugins;
package/iterators.js DELETED
@@ -1,102 +0,0 @@
1
- var reduce = require('async-array-reduce');
2
- var es = require('event-stream');
3
-
4
- /**
5
- * Expose `iterators`
6
- */
7
-
8
- var iterators = module.exports;
9
-
10
- /**
11
- * Async iterator
12
- */
13
-
14
- iterators.async = function asyncIterator(val) {
15
- var args = [].slice.call(arguments);
16
- var fns = this.fns;
17
- var cb = args.pop();
18
-
19
- // if the second arg is an array,
20
- // assume it's a plugin array
21
- if (Array.isArray(args[1])) {
22
- fns = fns.concat(args.pop());
23
- }
24
-
25
- var isArray = Array.isArray(args[0]);
26
- var self = this, i = 0;
27
-
28
- return reduce(fns, args, function (acc, fn, next) {
29
- acc = arrayify(acc);
30
- if (isArray && i > 0) acc = [acc];
31
- i++;
32
- fn.apply(self, acc.concat(next));
33
- }.bind(this), cb);
34
- };
35
-
36
- /**
37
- * Sync iterator
38
- */
39
-
40
- iterators.sync = function syncIterator() {
41
- var args = [].slice.call(arguments);
42
- var fns = this.fns;
43
-
44
- if (Array.isArray(args[1])) {
45
- fns = fns.concat(args.pop());
46
- }
47
-
48
- return fns.reduce(function (acc, fn) {
49
- return fn.apply(this, arrayify(acc));
50
- }, args);
51
- };
52
-
53
- /**
54
- * Stream iterator
55
- * TODO: this needs to be updated to work like an iterator.
56
- * currently it works like a plugin itself.
57
- */
58
-
59
- iterators.stream = function streamIterator() {
60
- var args = [].slice.call(arguments);
61
- var fns = this.fns;
62
-
63
- if (Array.isArray(args[0])) {
64
- fns = fns.concat(args.unshift());
65
- }
66
-
67
- var len = fns.length, i = -1;
68
- var pipeline = [];
69
-
70
- while (++i < len) {
71
- var fn = fns[i];
72
- // if stream, push into pipeline
73
- if (isStream(fn)) {
74
- pipeline.push(fn);
75
- continue;
76
- }
77
- // otherwise, call the function and pass in the args
78
- // expect a stream to be returned to push onto the pipeline
79
- try {
80
- pipeline.push(fn.apply(this, args));
81
- } catch (err) {
82
- throw err;
83
- }
84
- }
85
- return es.pipe.apply(es, pipeline);
86
- };
87
-
88
- /**
89
- * Utilities
90
- */
91
-
92
- function isStream(obj) {
93
- return typeof obj === 'object' && obj.pipe && isFunction(obj.pipe);
94
- }
95
-
96
- function isFunction(val) {
97
- return typeof val === 'function';
98
- }
99
-
100
- function arrayify(val) {
101
- return Array.isArray(val) ? val : [val];
102
- }