claudepluginhub 0.12.1 → 0.14.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/dist/collection-install.d.ts +33 -0
- package/dist/collection-install.js +46 -3
- package/dist/doctor/equivalence.js +4 -0
- package/dist/doctor/html-report.js +2 -0
- package/dist/doctor/inventory.js +66 -0
- package/dist/doctor/report.d.ts +14 -0
- package/dist/doctor/run.js +1 -0
- package/dist/index.js +5 -2
- package/dist/prompts.d.ts +13 -0
- package/dist/prompts.js +85 -1
- package/dist/recommend.d.ts +9 -0
- package/dist/recommend.js +168 -4
- package/package.json +1 -1
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
import type { Scope } from './prompts.js';
|
|
2
|
+
import type { MarketplaceJSON } from './fetch.js';
|
|
3
|
+
/**
|
|
4
|
+
* Structured outcome of one plugin install attempt, discriminated on `ok` so
|
|
5
|
+
* a failure always carries its `stage` and `error`. `stage` names the step
|
|
6
|
+
* that failed so callers can classify failures without parsing `error` text
|
|
7
|
+
* (the recommend flow maps stages to its allowlisted failureClass enum —
|
|
8
|
+
* never the raw error string).
|
|
9
|
+
*/
|
|
10
|
+
export type PluginInstallResult = {
|
|
11
|
+
name: string;
|
|
12
|
+
ok: true;
|
|
13
|
+
} | {
|
|
14
|
+
name: string;
|
|
15
|
+
ok: false;
|
|
16
|
+
stage: 'validate' | 'marketplace_add' | 'install';
|
|
17
|
+
/** Native command output or a validation message — display only, never sent anywhere. */
|
|
18
|
+
error: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Install a single plugin from a fetched marketplace manifest: validate the
|
|
22
|
+
* marketplace name, find the EXPECTED plugin by name (never a blind
|
|
23
|
+
* `plugins[0]`), register the marketplace, install. Prompt-free and
|
|
24
|
+
* exit-free — always returns a structured result, so interactive callers
|
|
25
|
+
* (collection/wrapper installs, the recommend flow) own their own output and
|
|
26
|
+
* exit semantics.
|
|
27
|
+
*
|
|
28
|
+
* `skipMarketplaceAdd` lets multi-plugin callers that registered the shared
|
|
29
|
+
* marketplace once up-front (runNativeManifestInstall) reuse the entry-lookup
|
|
30
|
+
* + install steps without re-adding per plugin.
|
|
31
|
+
*/
|
|
32
|
+
export declare function installPluginFromManifest(manifest: MarketplaceJSON, pluginName: string, registerUrl: string, scope: Scope, opts?: {
|
|
33
|
+
skipMarketplaceAdd?: boolean;
|
|
34
|
+
}): PluginInstallResult;
|
|
2
35
|
export declare function runCollectionInstall(url: string, yes: boolean, scopeOverride: Scope | null): Promise<void>;
|
|
3
36
|
/**
|
|
4
37
|
* Install a single plugin via its ClaudePluginHub wrapper marketplace
|
|
@@ -15,6 +15,48 @@ function isInstallableMarketplaceName(name) {
|
|
|
15
15
|
!name.includes('..') &&
|
|
16
16
|
name !== '.');
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Install a single plugin from a fetched marketplace manifest: validate the
|
|
20
|
+
* marketplace name, find the EXPECTED plugin by name (never a blind
|
|
21
|
+
* `plugins[0]`), register the marketplace, install. Prompt-free and
|
|
22
|
+
* exit-free — always returns a structured result, so interactive callers
|
|
23
|
+
* (collection/wrapper installs, the recommend flow) own their own output and
|
|
24
|
+
* exit semantics.
|
|
25
|
+
*
|
|
26
|
+
* `skipMarketplaceAdd` lets multi-plugin callers that registered the shared
|
|
27
|
+
* marketplace once up-front (runNativeManifestInstall) reuse the entry-lookup
|
|
28
|
+
* + install steps without re-adding per plugin.
|
|
29
|
+
*/
|
|
30
|
+
export function installPluginFromManifest(manifest, pluginName, registerUrl, scope, opts = {}) {
|
|
31
|
+
if (!isInstallableMarketplaceName(manifest.name)) {
|
|
32
|
+
return {
|
|
33
|
+
name: pluginName,
|
|
34
|
+
ok: false,
|
|
35
|
+
stage: 'validate',
|
|
36
|
+
error: `marketplace name "${manifest.name}" is not accepted by Claude Code`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const entry = manifest.plugins.find((p) => p.name === pluginName);
|
|
40
|
+
if (!entry) {
|
|
41
|
+
return {
|
|
42
|
+
name: pluginName,
|
|
43
|
+
ok: false,
|
|
44
|
+
stage: 'validate',
|
|
45
|
+
error: `plugin "${pluginName}" not found in the manifest`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (!opts.skipMarketplaceAdd) {
|
|
49
|
+
const addResult = claudeMarketplaceAdd(registerUrl, scope);
|
|
50
|
+
if (!addResult.ok) {
|
|
51
|
+
return { name: pluginName, ok: false, stage: 'marketplace_add', error: addResult.output };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const installResult = claudePluginInstall(entry.name, manifest.name, scope);
|
|
55
|
+
if (!installResult.ok) {
|
|
56
|
+
return { name: pluginName, ok: false, stage: 'install', error: installResult.output };
|
|
57
|
+
}
|
|
58
|
+
return { name: pluginName, ok: true };
|
|
59
|
+
}
|
|
18
60
|
/**
|
|
19
61
|
* Install from a hosted marketplace manifest by delegating to Claude Code's
|
|
20
62
|
* native plugin system: `claude plugin marketplace add <url>` once, then
|
|
@@ -94,16 +136,17 @@ async function runNativeManifestInstall(url, yes, scopeOverride, kind) {
|
|
|
94
136
|
process.exit(1);
|
|
95
137
|
}
|
|
96
138
|
printSuccess(`Marketplace "${manifest.name}" added`);
|
|
97
|
-
// Install each selected plugin
|
|
139
|
+
// Install each selected plugin via the shared prompt-free operation (the
|
|
140
|
+
// marketplace was registered once above, so each call skips the add step).
|
|
98
141
|
let failures = 0;
|
|
99
142
|
for (const plugin of selectedPlugins) {
|
|
100
143
|
printStep(`Installing ${plugin.name}...`);
|
|
101
|
-
const result =
|
|
144
|
+
const result = installPluginFromManifest(manifest, plugin.name, registerUrl.toString(), scope, { skipMarketplaceAdd: true });
|
|
102
145
|
if (result.ok) {
|
|
103
146
|
printSuccess(plugin.name);
|
|
104
147
|
}
|
|
105
148
|
else {
|
|
106
|
-
printFail(plugin.name, result.
|
|
149
|
+
printFail(plugin.name, result.error);
|
|
107
150
|
failures++;
|
|
108
151
|
}
|
|
109
152
|
}
|
|
@@ -204,6 +204,10 @@ export function scanEquivalent(aRecord, aScan, bRecord, bScan) {
|
|
|
204
204
|
return false;
|
|
205
205
|
if (sortedStrings(aScan.themeFiles).join('\0') !== sortedStrings(bScan.themeFiles).join('\0'))
|
|
206
206
|
return false;
|
|
207
|
+
// Two installations with different workflow scripts register different slash
|
|
208
|
+
// commands — never collapse them into one "equivalent" row.
|
|
209
|
+
if (sortedStrings(aScan.workflowFiles).join('\0') !== sortedStrings(bScan.workflowFiles).join('\0'))
|
|
210
|
+
return false;
|
|
207
211
|
if (sortedStrings(aScan.parseErrors).join('\0') !== sortedStrings(bScan.parseErrors).join('\0'))
|
|
208
212
|
return false;
|
|
209
213
|
if (sortedStrings(aScan.symlinksSkipped).join('\0') !== sortedStrings(bScan.symlinksSkipped).join('\0'))
|
|
@@ -52,6 +52,8 @@ function capsSummary(caps) {
|
|
|
52
52
|
parts.push(`lsp: ${caps.lsp.total}`);
|
|
53
53
|
if (caps.monitors.total > 0)
|
|
54
54
|
parts.push(`monitors: ${caps.monitors.total}`);
|
|
55
|
+
if (caps.workflowCount > 0)
|
|
56
|
+
parts.push(`workflows: ${caps.workflowCount}`);
|
|
55
57
|
if (caps.binCount > 0)
|
|
56
58
|
parts.push(`bin: ${caps.binCount}`);
|
|
57
59
|
return parts.length > 0 ? parts.join(', ') : 'none';
|
package/dist/doctor/inventory.js
CHANGED
|
@@ -61,6 +61,7 @@ export function createScanner(overrides) {
|
|
|
61
61
|
mcp: [],
|
|
62
62
|
lsp: [],
|
|
63
63
|
monitors: [],
|
|
64
|
+
workflowFiles: [],
|
|
64
65
|
bin: [],
|
|
65
66
|
parseErrors: [],
|
|
66
67
|
symlinksSkipped: [],
|
|
@@ -979,6 +980,8 @@ function scanPlugin(rootCanonical, state, result, read, walk, openDirect) {
|
|
|
979
980
|
['mcpServers', manifest.mcpServers, isPathArrayOrObject],
|
|
980
981
|
['lspServers', manifest.lspServers, isPathArrayOrObject],
|
|
981
982
|
['monitors', monitorsValue, isPathArrayOrObject],
|
|
983
|
+
// Top-level only — `workflows` is NOT an `experimental.*` field.
|
|
984
|
+
['workflows', manifest.workflows, isPathOrArray],
|
|
982
985
|
['dependencies', manifest.dependencies, (v) => Array.isArray(v)],
|
|
983
986
|
];
|
|
984
987
|
for (const [field, value, valid] of checks) {
|
|
@@ -1022,6 +1025,7 @@ function scanPlugin(rootCanonical, state, result, read, walk, openDirect) {
|
|
|
1022
1025
|
...boundPaths(stringPaths(manifest.mcpServers), state),
|
|
1023
1026
|
...boundPaths(stringPaths(manifest.lspServers), state),
|
|
1024
1027
|
...boundPaths(stringPaths(manifest.monitors !== undefined ? manifest.monitors : experimental.monitors), state),
|
|
1028
|
+
...boundPaths(stringPaths(manifest.workflows), state),
|
|
1025
1029
|
];
|
|
1026
1030
|
for (const rel of [...new Set(declared)].sort()) {
|
|
1027
1031
|
// Contained lexical resolve first: a "../…" or absolute declaration is
|
|
@@ -1177,6 +1181,68 @@ function scanPlugin(rootCanonical, state, result, read, walk, openDirect) {
|
|
|
1177
1181
|
if (inline.length > 0)
|
|
1178
1182
|
pushFacts(result.monitors, parseMonitorEntries(inline));
|
|
1179
1183
|
}
|
|
1184
|
+
// --- workflows/ (spec: top-level manifest field, REPLACES the default dir) --
|
|
1185
|
+
// Mirrors the measured loader behaviour, which is narrower than every other
|
|
1186
|
+
// component scan here:
|
|
1187
|
+
// - `.js` ONLY, matched case-sensitively (`W.JS` is silently not loaded)
|
|
1188
|
+
// - direct children only — `workflows/sub/w.js` never loads
|
|
1189
|
+
// Files are LISTED, never read and never executed. The invocation name lives
|
|
1190
|
+
// in the script's `export const meta`, which needs a JS parser the CLI does
|
|
1191
|
+
// not ship, so no name is claimed here.
|
|
1192
|
+
const workflowsRoots = boundPaths(stringPaths(manifest.workflows), state);
|
|
1193
|
+
for (const root of workflowsRoots.length > 0 ? [...new Set(workflowsRoots)].sort() : ['workflows']) {
|
|
1194
|
+
const dirReal = containedReal(rootCanonical, root, state);
|
|
1195
|
+
if (dirReal === null)
|
|
1196
|
+
continue;
|
|
1197
|
+
let entries = [];
|
|
1198
|
+
try {
|
|
1199
|
+
entries = readdirSync(dirReal).sort();
|
|
1200
|
+
}
|
|
1201
|
+
catch {
|
|
1202
|
+
entries = [];
|
|
1203
|
+
}
|
|
1204
|
+
if (entries.length > MAX_KEYS) {
|
|
1205
|
+
state.limitsHit.add('max-facts');
|
|
1206
|
+
state.incomplete = true;
|
|
1207
|
+
}
|
|
1208
|
+
for (const entry of entries.slice(0, MAX_KEYS)) {
|
|
1209
|
+
// Case-SENSITIVE: the loader does not lowercase, so `W.JS` is not a workflow.
|
|
1210
|
+
if (!entry.endsWith('.js'))
|
|
1211
|
+
continue;
|
|
1212
|
+
const abs = join(dirReal, entry);
|
|
1213
|
+
let info;
|
|
1214
|
+
try {
|
|
1215
|
+
info = lstatSync(abs);
|
|
1216
|
+
}
|
|
1217
|
+
catch {
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
// Same containment rule as bin/ below: `statSync` alone FOLLOWS symlinks,
|
|
1221
|
+
// so an entry resolving outside the plugin root would be listed as a
|
|
1222
|
+
// legitimate workflow of this plugin and the report would not be marked
|
|
1223
|
+
// incomplete — the one signal that tells the reader the scan was bounded.
|
|
1224
|
+
if (info.isSymbolicLink()) {
|
|
1225
|
+
try {
|
|
1226
|
+
const real = realpathSync(abs);
|
|
1227
|
+
if (!isWithin(rootCanonical, real)) {
|
|
1228
|
+
state.symlinksSkipped.push(`${root}/${entry}`);
|
|
1229
|
+
state.incomplete = true;
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
info = statSync(real);
|
|
1233
|
+
}
|
|
1234
|
+
catch {
|
|
1235
|
+
state.symlinksSkipped.push(`${root}/${entry}`);
|
|
1236
|
+
state.incomplete = true;
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
if (!info.isFile())
|
|
1241
|
+
continue;
|
|
1242
|
+
state.filesScanned += 1;
|
|
1243
|
+
result.workflowFiles.push(`${root}/${entry}`);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1180
1246
|
// --- bin/ (spec: on PATH while the plugin is enabled; tree-only, no manifest) --------
|
|
1181
1247
|
// The directory itself goes through the contained-realpath helper: a bin/
|
|
1182
1248
|
// that is a symlink pointing outside the root must not be listed at all.
|
package/dist/doctor/report.d.ts
CHANGED
|
@@ -167,6 +167,8 @@ export interface ScanResult {
|
|
|
167
167
|
mcp: McpFact[];
|
|
168
168
|
lsp: LspFact[];
|
|
169
169
|
monitors: MonitorFact[];
|
|
170
|
+
/** Plugin-relative paths of workflow scripts. Never read/parsed — never executed. */
|
|
171
|
+
workflowFiles: string[];
|
|
170
172
|
bin: {
|
|
171
173
|
relPath: string;
|
|
172
174
|
executable: boolean;
|
|
@@ -228,6 +230,18 @@ export interface PluginCapabilities {
|
|
|
228
230
|
executable: string | null;
|
|
229
231
|
}>;
|
|
230
232
|
binCount: number;
|
|
233
|
+
/**
|
|
234
|
+
* Count of `workflows/` scripts found (default dir or the manifest's
|
|
235
|
+
* replaces-default path; `.js`, direct children only).
|
|
236
|
+
*
|
|
237
|
+
* A COUNT, not a per-item list, deliberately: the invocation name a workflow
|
|
238
|
+
* registers lives in its `export const meta = {…}`, and extracting that
|
|
239
|
+
* requires a JS parser the CLI does not ship. Emitting file basenames as if
|
|
240
|
+
* they were command names would be a fabricated claim — the runtime uses
|
|
241
|
+
* `meta.name`, which frequently differs from the filename. Report what we can
|
|
242
|
+
* actually see.
|
|
243
|
+
*/
|
|
244
|
+
workflowCount: number;
|
|
231
245
|
}
|
|
232
246
|
export interface PluginEntry {
|
|
233
247
|
id: string;
|
package/dist/doctor/run.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -56,9 +56,12 @@ Notes:
|
|
|
56
56
|
|
|
57
57
|
Recommend (reads local manifest dependency names + config filenames only —
|
|
58
58
|
never file contents):
|
|
59
|
-
recommend Top plugins grouped by each detected stack
|
|
59
|
+
recommend Top plugins grouped by each detected stack;
|
|
60
|
+
in a terminal, optionally select up to 5 to
|
|
61
|
+
install via Claude Code (anonymous outcomes of
|
|
62
|
+
attempted installs are reported)
|
|
60
63
|
recommend --limit 6 Results per stack (1-50, default 4)
|
|
61
|
-
recommend --json Raw JSON output
|
|
64
|
+
recommend --json Raw JSON output (never interactive)
|
|
62
65
|
|
|
63
66
|
Options:
|
|
64
67
|
--plugin <name> Install a specific plugin from a marketplace repo
|
package/dist/prompts.d.ts
CHANGED
|
@@ -5,5 +5,18 @@ export interface SelectableItem {
|
|
|
5
5
|
selected: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function checkboxPrompt(title: string, items: SelectableItem[]): Promise<number[] | null>;
|
|
8
|
+
/**
|
|
9
|
+
* Recommendation-specific multi-select. Differs from `checkboxPrompt` (which
|
|
10
|
+
* existing collection/component selectors keep unchanged) in three deliberate
|
|
11
|
+
* ways:
|
|
12
|
+
* - NO select-all: the 'a' key is ignored — recommendations are opt-in per
|
|
13
|
+
* item, never bulk-installed.
|
|
14
|
+
* - Hard selection cap: toggling ON past `maxSelected` is rejected with
|
|
15
|
+
* immediate hint feedback; toggling OFF always works.
|
|
16
|
+
* - Non-TTY fallback returns [] (select nothing) — recommend must never
|
|
17
|
+
* auto-install in a non-interactive run, unlike checkboxPrompt's
|
|
18
|
+
* all-selected fallback.
|
|
19
|
+
*/
|
|
20
|
+
export declare function recommendPrompt(title: string, items: SelectableItem[], maxSelected: number): Promise<number[] | null>;
|
|
8
21
|
export declare function confirmPrompt(message: string): Promise<boolean>;
|
|
9
22
|
export declare function scopePrompt(defaultScope?: Scope): Promise<Scope | null>;
|
package/dist/prompts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RESET, BOLD, DIM, GREEN, CYAN, INVERSE, HIDE_CURSOR, SHOW_CURSOR, moveUp, } from './output.js';
|
|
1
|
+
import { RESET, BOLD, DIM, GREEN, CYAN, INVERSE, HIDE_CURSOR, SHOW_CURSOR, CLEAR_LINE, moveUp, } from './output.js';
|
|
2
2
|
function isInteractive() {
|
|
3
3
|
return !!process.stdin.isTTY;
|
|
4
4
|
}
|
|
@@ -82,6 +82,90 @@ export async function checkboxPrompt(title, items) {
|
|
|
82
82
|
write(SHOW_CURSOR);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
function renderRecommendSelect(title, items, cursor, maxSelected, atCap) {
|
|
86
|
+
// Every line starts with CLEAR_LINE: the cap hint changes width between
|
|
87
|
+
// renders ("(max 5)" vs "(max 5 reached)"), so overwriting in place would
|
|
88
|
+
// otherwise leave residue from the longer variant.
|
|
89
|
+
const lines = [`${CLEAR_LINE}${BOLD}${title}${RESET}`];
|
|
90
|
+
const capHint = atCap ? `(max ${maxSelected} reached)` : `(max ${maxSelected})`;
|
|
91
|
+
lines.push(`${CLEAR_LINE}${DIM} Space=toggle Enter=confirm Ctrl+C=skip ${capHint}${RESET}`);
|
|
92
|
+
for (let i = 0; i < items.length; i++) {
|
|
93
|
+
const item = items[i];
|
|
94
|
+
const marker = item.selected ? `${GREEN}[x]${RESET}` : `[ ]`;
|
|
95
|
+
const prefix = i === cursor ? `${INVERSE}>` : ' ';
|
|
96
|
+
const label = i === cursor ? `${BOLD}${item.label}${RESET}` : item.label;
|
|
97
|
+
const desc = item.description ? ` ${DIM}${item.description}${RESET}` : '';
|
|
98
|
+
const suffix = i === cursor ? RESET : '';
|
|
99
|
+
lines.push(`${CLEAR_LINE}${prefix} ${marker} ${label}${desc}${suffix}`);
|
|
100
|
+
}
|
|
101
|
+
return lines.join('\n');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Recommendation-specific multi-select. Differs from `checkboxPrompt` (which
|
|
105
|
+
* existing collection/component selectors keep unchanged) in three deliberate
|
|
106
|
+
* ways:
|
|
107
|
+
* - NO select-all: the 'a' key is ignored — recommendations are opt-in per
|
|
108
|
+
* item, never bulk-installed.
|
|
109
|
+
* - Hard selection cap: toggling ON past `maxSelected` is rejected with
|
|
110
|
+
* immediate hint feedback; toggling OFF always works.
|
|
111
|
+
* - Non-TTY fallback returns [] (select nothing) — recommend must never
|
|
112
|
+
* auto-install in a non-interactive run, unlike checkboxPrompt's
|
|
113
|
+
* all-selected fallback.
|
|
114
|
+
*/
|
|
115
|
+
export async function recommendPrompt(title, items, maxSelected) {
|
|
116
|
+
if (!isInteractive()) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
const wasRaw = process.stdin.isRaw;
|
|
120
|
+
process.stdin.setRawMode(true);
|
|
121
|
+
process.stdin.resume();
|
|
122
|
+
write(HIDE_CURSOR);
|
|
123
|
+
let cursor = 0;
|
|
124
|
+
const totalLines = items.length + 2; // title + hint + items
|
|
125
|
+
const selectedCount = () => items.filter((item) => item.selected).length;
|
|
126
|
+
write(renderRecommendSelect(title, items, cursor, maxSelected, false));
|
|
127
|
+
try {
|
|
128
|
+
while (true) {
|
|
129
|
+
const key = await readKey();
|
|
130
|
+
const str = key.toString();
|
|
131
|
+
// Ctrl+C — skip installing, not an error
|
|
132
|
+
if (str === '\x03') {
|
|
133
|
+
write('\n' + SHOW_CURSOR);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
// Enter
|
|
137
|
+
if (str === '\r' || str === '\n') {
|
|
138
|
+
write('\n' + SHOW_CURSOR);
|
|
139
|
+
return items
|
|
140
|
+
.map((item, i) => (item.selected ? i : -1))
|
|
141
|
+
.filter((i) => i !== -1);
|
|
142
|
+
}
|
|
143
|
+
// Space - toggle (ON only below the cap; OFF always allowed)
|
|
144
|
+
if (str === ' ') {
|
|
145
|
+
if (items[cursor].selected || selectedCount() < maxSelected) {
|
|
146
|
+
items[cursor].selected = !items[cursor].selected;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// NOTE: no 'a' (select-all) handler by design.
|
|
150
|
+
// Arrow up or 'k'
|
|
151
|
+
if (str === '\x1b[A' || str === 'k') {
|
|
152
|
+
cursor = cursor > 0 ? cursor - 1 : items.length - 1;
|
|
153
|
+
}
|
|
154
|
+
// Arrow down or 'j'
|
|
155
|
+
if (str === '\x1b[B' || str === 'j') {
|
|
156
|
+
cursor = cursor < items.length - 1 ? cursor + 1 : 0;
|
|
157
|
+
}
|
|
158
|
+
// Re-render
|
|
159
|
+
write(moveUp(totalLines - 1) + '\r');
|
|
160
|
+
write(renderRecommendSelect(title, items, cursor, maxSelected, selectedCount() >= maxSelected));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
process.stdin.setRawMode(wasRaw ?? false);
|
|
165
|
+
process.stdin.pause();
|
|
166
|
+
write(SHOW_CURSOR);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
85
169
|
export async function confirmPrompt(message) {
|
|
86
170
|
if (!isInteractive())
|
|
87
171
|
return true;
|
package/dist/recommend.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hard cap on plugins selectable in one interactive recommend run. Deliberate
|
|
3
|
+
* selection-safety bound: the selector has no select-all and every item starts
|
|
4
|
+
* unchecked, so a run can never bulk-install a 20-item recommendation list.
|
|
5
|
+
* Coupled surfaces when raising: the server's MAX_OUTCOMES cap
|
|
6
|
+
* (/api/recommend/outcome — must deploy FIRST, or over-cap outcome reports
|
|
7
|
+
* silently schema-reject) and the "up to 5" literal in index.ts help text.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RECOMMEND_MAX_SELECTIONS = 5;
|
|
1
10
|
export interface RecommendFlags {
|
|
2
11
|
limit: number;
|
|
3
12
|
json: boolean;
|
package/dist/recommend.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { readFileSync, readdirSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { BASE_URL } from './fetch.js';
|
|
4
|
-
import {
|
|
3
|
+
import { BASE_URL, fetchMarketplace } from './fetch.js';
|
|
4
|
+
import { checkClaudeCli } from './native.js';
|
|
5
|
+
import { installPluginFromManifest } from './collection-install.js';
|
|
6
|
+
import { recommendPrompt, scopePrompt, confirmPrompt } from './prompts.js';
|
|
7
|
+
import { print, printBanner, printStep, printSuccess, printFail, printError, BOLD, DIM, RESET, CYAN, YELLOW, } from './output.js';
|
|
5
8
|
/**
|
|
6
9
|
* `npx claudepluginhub recommend` — instant plugin recommendations for the
|
|
7
10
|
* current project. Reads local manifest dependency NAMES and telltale config
|
|
@@ -20,6 +23,15 @@ const MAX_DEP_LENGTH = 128;
|
|
|
20
23
|
*/
|
|
21
24
|
const DEFAULT_LIMIT = 4;
|
|
22
25
|
const MAX_LIMIT = 50;
|
|
26
|
+
/**
|
|
27
|
+
* Hard cap on plugins selectable in one interactive recommend run. Deliberate
|
|
28
|
+
* selection-safety bound: the selector has no select-all and every item starts
|
|
29
|
+
* unchecked, so a run can never bulk-install a 20-item recommendation list.
|
|
30
|
+
* Coupled surfaces when raising: the server's MAX_OUTCOMES cap
|
|
31
|
+
* (/api/recommend/outcome — must deploy FIRST, or over-cap outcome reports
|
|
32
|
+
* silently schema-reject) and the "up to 5" literal in index.ts help text.
|
|
33
|
+
*/
|
|
34
|
+
export const RECOMMEND_MAX_SELECTIONS = 5;
|
|
23
35
|
/**
|
|
24
36
|
* Telltale filename prefixes. Privacy allowlist: when a cwd entry matches a
|
|
25
37
|
* prefix, the PREFIX ITSELF is sent — never the raw basename — so only
|
|
@@ -397,7 +409,159 @@ export async function runRecommend(argv) {
|
|
|
397
409
|
});
|
|
398
410
|
print('');
|
|
399
411
|
});
|
|
400
|
-
//
|
|
401
|
-
//
|
|
412
|
+
// Interactive install (TTY only). The footer prints AFTER the flow so the
|
|
413
|
+
// last line is always the refine link, whatever path was taken.
|
|
414
|
+
await runInteractiveInstall(body);
|
|
415
|
+
}
|
|
416
|
+
/** Always the last output: the picker page link (not /for/[stack] — low-coverage stacks 404 there). */
|
|
417
|
+
function printFooter() {
|
|
402
418
|
print(`${DIM}Refine stacks: ${BASE_URL}/tools/for-your-project${RESET}`);
|
|
403
419
|
}
|
|
420
|
+
const STAGE_TO_FAILURE_CLASS = {
|
|
421
|
+
validate: 'manifest_invalid',
|
|
422
|
+
marketplace_add: 'marketplace_add_failed',
|
|
423
|
+
install: 'install_failed',
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* Optional interactive tail of `recommend`: select up to
|
|
427
|
+
* RECOMMEND_MAX_SELECTIONS recommended plugins, pick one scope, confirm, and
|
|
428
|
+
* install each through the shared wrapper-marketplace path (identical to
|
|
429
|
+
* `p/<slug>`). Skipped entirely for non-TTY runs (both streams checked —
|
|
430
|
+
* stdin alone misses `recommend | cat`) and when nothing is natively
|
|
431
|
+
* installable. Exits 1 when any selected install failed.
|
|
432
|
+
*/
|
|
433
|
+
async function runInteractiveInstall(body) {
|
|
434
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
435
|
+
printFooter();
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
// Maintainer-override items are manual-only and never selectable — their
|
|
439
|
+
// override command is already printed above and is NEVER executed here.
|
|
440
|
+
const installable = body.sections.flatMap((section) => section.results
|
|
441
|
+
.filter((item) => !item.install.maintainerOverride && item.install.claude !== null)
|
|
442
|
+
.map((item) => ({ item, stack: section.stack })));
|
|
443
|
+
if (installable.length === 0) {
|
|
444
|
+
printFooter();
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
// Prerequisite check BEFORE asking the user to make any decisions. Not an
|
|
448
|
+
// error exit: the recommendations already printed successfully and the
|
|
449
|
+
// install tail is optional — checkClaudeCli() prints the actionable hint,
|
|
450
|
+
// then the run ends cleanly with the footer like every other skip path.
|
|
451
|
+
// (Exit 1 stays reserved for attempted installs that failed, below.)
|
|
452
|
+
if (!checkClaudeCli()) {
|
|
453
|
+
print('');
|
|
454
|
+
printFooter();
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
print('');
|
|
458
|
+
const chosen = await recommendPrompt('Install plugins:', installable.map(({ item, stack }) => ({
|
|
459
|
+
label: `${item.name} (${formatStackLabel(stack)})`,
|
|
460
|
+
selected: false,
|
|
461
|
+
})), RECOMMEND_MAX_SELECTIONS);
|
|
462
|
+
if (chosen === null || chosen.length === 0) {
|
|
463
|
+
print('');
|
|
464
|
+
printFooter();
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const selected = chosen.map((i) => installable[i]);
|
|
468
|
+
print('');
|
|
469
|
+
const scope = await scopePrompt('project');
|
|
470
|
+
if (scope === null) {
|
|
471
|
+
print('');
|
|
472
|
+
printFooter();
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
// Final confirmation with the exact names, count, and scope. Declining
|
|
476
|
+
// exits cleanly with zero mutations. The reporting disclosure prints BEFORE
|
|
477
|
+
// this prompt — confirming is what leads to the outcome report, so the user
|
|
478
|
+
// must see it while declining still prevents the send.
|
|
479
|
+
print('');
|
|
480
|
+
print(`${BOLD}Selected:${RESET} ${selected.map(({ item }) => item.name).join(', ')}`);
|
|
481
|
+
print(`${DIM}Anonymous install outcomes are reported to claudepluginhub.com.${RESET}`);
|
|
482
|
+
const confirmed = await confirmPrompt(`Install ${selected.length} plugin${selected.length === 1 ? '' : 's'} with ${scope} scope?`);
|
|
483
|
+
if (!confirmed) {
|
|
484
|
+
print('');
|
|
485
|
+
printFooter();
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
print('');
|
|
489
|
+
const outcomes = [];
|
|
490
|
+
for (const { item } of selected) {
|
|
491
|
+
printStep(`Installing ${item.name}...`);
|
|
492
|
+
const manifestUrl = `${BASE_URL}/api/plugins/${item.slug}/marketplace.json`;
|
|
493
|
+
const manifest = await fetchMarketplace(manifestUrl);
|
|
494
|
+
if (!manifest) {
|
|
495
|
+
printFail(item.name);
|
|
496
|
+
outcomes.push({ slug: item.slug, status: 'failed', failureClass: 'fetch_failed' });
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
// Wrapper manifests name their single plugin after the slug; the shared
|
|
500
|
+
// installer verifies that by name instead of trusting plugins[0].
|
|
501
|
+
const result = installPluginFromManifest(manifest, item.slug, manifestUrl, scope);
|
|
502
|
+
if (result.ok) {
|
|
503
|
+
printSuccess(item.name);
|
|
504
|
+
outcomes.push({ slug: item.slug, status: 'installed' });
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
printFail(item.name, result.error);
|
|
508
|
+
outcomes.push({
|
|
509
|
+
slug: item.slug,
|
|
510
|
+
status: 'failed',
|
|
511
|
+
failureClass: STAGE_TO_FAILURE_CLASS[result.stage],
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const installed = outcomes.filter((o) => o.status === 'installed').length;
|
|
516
|
+
const failed = outcomes.length - installed;
|
|
517
|
+
print('');
|
|
518
|
+
print(`${BOLD}${installed} installed, ${failed} failed.${RESET}`);
|
|
519
|
+
await reportOutcomes(body.outcomeProof, outcomes);
|
|
520
|
+
print('');
|
|
521
|
+
print(`${DIM}Manage: claude plugin list | claude plugin uninstall <name>${RESET}`);
|
|
522
|
+
print('');
|
|
523
|
+
// Repeats the pre-confirm disclosure adjacent to the actual send, and
|
|
524
|
+
// deliberately prints even when reportOutcomes skipped it (no proof from an
|
|
525
|
+
// older server, POST failure): over-disclosing beats a privacy notice
|
|
526
|
+
// that's absent on runs where the report DID go out.
|
|
527
|
+
print(`${DIM}Anonymous install outcomes are reported to claudepluginhub.com.${RESET}`);
|
|
528
|
+
printFooter();
|
|
529
|
+
if (failed > 0) {
|
|
530
|
+
process.exit(1);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Fail-soft outcome report: echo the server's signed proof back with only
|
|
535
|
+
* {pluginId, status, failureClass} per ATTEMPTED plugin — never dependency
|
|
536
|
+
* names, paths, plugin inventories, command output, or raw error text. Any
|
|
537
|
+
* failure here is invisible and never changes the local install result; runs
|
|
538
|
+
* where nothing was selected never reach this call.
|
|
539
|
+
*/
|
|
540
|
+
async function reportOutcomes(proof, outcomes) {
|
|
541
|
+
if (!proof || outcomes.length === 0)
|
|
542
|
+
return;
|
|
543
|
+
const bySlug = new Map(proof.items.map((p) => [p.slug, p.pluginId]));
|
|
544
|
+
const payload = outcomes.flatMap((o) => {
|
|
545
|
+
const pluginId = bySlug.get(o.slug);
|
|
546
|
+
if (!pluginId)
|
|
547
|
+
return [];
|
|
548
|
+
return [
|
|
549
|
+
o.status === 'failed'
|
|
550
|
+
? { pluginId, status: o.status, failureClass: o.failureClass }
|
|
551
|
+
: { pluginId, status: o.status },
|
|
552
|
+
];
|
|
553
|
+
});
|
|
554
|
+
if (payload.length === 0)
|
|
555
|
+
return;
|
|
556
|
+
try {
|
|
557
|
+
await fetch(`${BASE_URL}/api/recommend/outcome`, {
|
|
558
|
+
method: 'POST',
|
|
559
|
+
headers: { 'content-type': 'application/json' },
|
|
560
|
+
body: JSON.stringify({ proof, outcomes: payload }),
|
|
561
|
+
signal: AbortSignal.timeout(5_000),
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
catch {
|
|
565
|
+
// Silent by contract: outcome telemetry must never affect the user's run.
|
|
566
|
+
}
|
|
567
|
+
}
|