claudepluginhub 0.8.1 → 0.9.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 +30 -0
- package/dist/args.js +3 -1
- package/dist/fetch.d.ts +1 -0
- package/dist/fetch.js +1 -1
- package/dist/index.js +13 -0
- package/dist/recommend.d.ts +26 -0
- package/dist/recommend.js +338 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,8 +11,14 @@ npx claudepluginhub owner/repo
|
|
|
11
11
|
# ClaudePluginHub collection
|
|
12
12
|
npx claudepluginhub u/<userId>/<slug>
|
|
13
13
|
|
|
14
|
+
# ClaudePluginHub plugin by slug
|
|
15
|
+
npx claudepluginhub p/<slug>
|
|
16
|
+
|
|
14
17
|
# Full URL
|
|
15
18
|
npx claudepluginhub https://claudepluginhub.com/api/user-plugins/<userId>/<slug>/marketplace.json
|
|
19
|
+
|
|
20
|
+
# Recommend plugins for the current project
|
|
21
|
+
npx claudepluginhub recommend
|
|
16
22
|
```
|
|
17
23
|
|
|
18
24
|
## Identifier types
|
|
@@ -28,6 +34,10 @@ Installs a plugin or marketplace directly from a GitHub repository using Claude
|
|
|
28
34
|
|
|
29
35
|
Installs from a ClaudePluginHub user-curated collection. Components are downloaded directly and tracked in a lock file.
|
|
30
36
|
|
|
37
|
+
### `p/<slug>` (ClaudePluginHub)
|
|
38
|
+
|
|
39
|
+
Installs a single ClaudePluginHub plugin by its site slug via a wrapper marketplace (requires Claude Code).
|
|
40
|
+
|
|
31
41
|
### Full URL
|
|
32
42
|
|
|
33
43
|
Same as `u/` form but with the full marketplace JSON URL.
|
|
@@ -40,8 +50,26 @@ npx claudepluginhub add <identifier> Same as above
|
|
|
40
50
|
npx claudepluginhub update [identifier] Update (u/ collections only)
|
|
41
51
|
npx claudepluginhub list List (u/ collections only)
|
|
42
52
|
npx claudepluginhub remove <identifier> Remove
|
|
53
|
+
npx claudepluginhub recommend Recommend plugins for the current project
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Recommend
|
|
57
|
+
|
|
58
|
+
Run `npx claudepluginhub recommend` from a project root to get ranked plugin
|
|
59
|
+
recommendations for your detected stacks — no account, no setup.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npx claudepluginhub recommend # top 10 for your project
|
|
63
|
+
npx claudepluginhub recommend --limit 20 # more results (1-50)
|
|
64
|
+
npx claudepluginhub recommend --json # raw JSON, pipeable
|
|
43
65
|
```
|
|
44
66
|
|
|
67
|
+
Detection reads dependency **names** from `package.json`, `requirements.txt`,
|
|
68
|
+
`pyproject.toml`, `Cargo.toml`, and `go.mod`, plus which known config files
|
|
69
|
+
exist (e.g. `next.config.*`, `tailwind.config.*`). **Privacy:** only dependency
|
|
70
|
+
names and allowlisted config-filename prefixes are sent — never file contents,
|
|
71
|
+
never arbitrary filenames.
|
|
72
|
+
|
|
45
73
|
## Examples
|
|
46
74
|
|
|
47
75
|
```bash
|
|
@@ -56,6 +84,8 @@ npx claudepluginhub vercel/next.js --plugin cache-components
|
|
|
56
84
|
| `--plugin <name>` | Install a specific plugin from a marketplace repo |
|
|
57
85
|
| `--yes, -y` | Skip prompts (install all, project scope) |
|
|
58
86
|
| `--scope <scope>` | Set scope: `user`, `project` (default), `local` |
|
|
87
|
+
| `--limit <n>` | `recommend` only: number of results (1-50, default 10) |
|
|
88
|
+
| `--json` | `recommend` only: raw JSON output |
|
|
59
89
|
| `-h, --help` | Show help |
|
|
60
90
|
|
|
61
91
|
## Lifecycle differences
|
package/dist/args.js
CHANGED
|
@@ -75,7 +75,7 @@ export function parseArgs(argv) {
|
|
|
75
75
|
process.exit(1);
|
|
76
76
|
}
|
|
77
77
|
// Filter out flags and their values
|
|
78
|
-
const flagsWithValues = new Set(['--scope', '--plugin', '--source-path']);
|
|
78
|
+
const flagsWithValues = new Set(['--scope', '--plugin', '--source-path', '--limit']);
|
|
79
79
|
for (const f of COMPONENT_FLAGS)
|
|
80
80
|
flagsWithValues.add(f);
|
|
81
81
|
const positional = argv.filter((a, i) => !a.startsWith('-') &&
|
|
@@ -85,6 +85,8 @@ export function parseArgs(argv) {
|
|
|
85
85
|
// Route commands
|
|
86
86
|
if (first === 'list')
|
|
87
87
|
return { command: 'list', identifier: null, plugin, yes, scope, componentFlag };
|
|
88
|
+
if (first === 'recommend')
|
|
89
|
+
return { command: 'recommend', identifier: null, plugin, yes, scope, componentFlag };
|
|
88
90
|
if (first === 'update')
|
|
89
91
|
return { command: 'update', identifier: second, plugin, yes, scope, componentFlag };
|
|
90
92
|
if (first === 'remove')
|
package/dist/fetch.d.ts
CHANGED
package/dist/fetch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { printError, printWarning } from './output.js';
|
|
2
|
-
const BASE_URL = 'https://claudepluginhub.com';
|
|
2
|
+
export const BASE_URL = 'https://claudepluginhub.com';
|
|
3
3
|
const ALLOWED_HOSTS = ['claudepluginhub.com', 'www.claudepluginhub.com'];
|
|
4
4
|
export function resolveMarketplaceUrl(input) {
|
|
5
5
|
// Full URL
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ Commands:
|
|
|
28
28
|
update [identifier] Update installed collections
|
|
29
29
|
list List all installed collections
|
|
30
30
|
remove <identifier> Remove
|
|
31
|
+
recommend Recommend plugins for the current project
|
|
31
32
|
|
|
32
33
|
Identifiers:
|
|
33
34
|
owner/repo GitHub plugin or marketplace (via Claude Code)
|
|
@@ -51,6 +52,12 @@ Notes:
|
|
|
51
52
|
- Use \`claude plugin list\` for Claude Code plugins
|
|
52
53
|
- Standalone: \`npx claudepluginhub remove owner/repo\` for cleanup
|
|
53
54
|
|
|
55
|
+
Recommend (reads local manifest dependency names + config filenames only —
|
|
56
|
+
never file contents):
|
|
57
|
+
recommend Ranked plugins for your detected stacks
|
|
58
|
+
recommend --limit 20 Number of results (1-50, default 10)
|
|
59
|
+
recommend --json Raw JSON output
|
|
60
|
+
|
|
54
61
|
Options:
|
|
55
62
|
--plugin <name> Install a specific plugin from a marketplace repo
|
|
56
63
|
--skill <path> Install a single skill directly from a repo
|
|
@@ -73,6 +80,12 @@ async function main() {
|
|
|
73
80
|
validatePlugin(parsed);
|
|
74
81
|
validateComponentFlag(parsed);
|
|
75
82
|
const { command, identifier, plugin, yes, scope: scopeOverride, componentFlag } = parsed;
|
|
83
|
+
// recommend owns its banner (suppressed for --json so output stays pipeable)
|
|
84
|
+
if (command === 'recommend') {
|
|
85
|
+
const { runRecommend } = await import('./recommend.js');
|
|
86
|
+
await runRecommend(args);
|
|
87
|
+
process.exit(0);
|
|
88
|
+
}
|
|
76
89
|
printBanner();
|
|
77
90
|
// Handle non-install commands
|
|
78
91
|
if (command === 'list') {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface RecommendFlags {
|
|
2
|
+
limit: number;
|
|
3
|
+
json: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function parseRecommendFlags(argv: string[]): RecommendFlags;
|
|
6
|
+
export declare function parsePackageJsonDeps(content: string): string[];
|
|
7
|
+
export declare function parseRequirementsTxt(content: string): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Line-based TOML walk (no TOML dependency): track the current `[section]`
|
|
10
|
+
* and collect what each section contributes. Regexes over whole sections
|
|
11
|
+
* break on inline arrays (`features = ["derive"]`), so never use those here.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parsePyprojectToml(content: string): string[];
|
|
14
|
+
export declare function parseCargoToml(content: string): string[];
|
|
15
|
+
export declare function parseGoMod(content: string): string[];
|
|
16
|
+
export interface ProjectSignals {
|
|
17
|
+
dependencies: string[];
|
|
18
|
+
files: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Collect dependency names from known manifests in `cwd` plus telltale config
|
|
22
|
+
* filenames. Fail-soft per manifest: an unreadable or malformed file just
|
|
23
|
+
* contributes nothing (its filename still signals via `files`).
|
|
24
|
+
*/
|
|
25
|
+
export declare function collectProjectSignals(cwd: string): ProjectSignals;
|
|
26
|
+
export declare function runRecommend(argv: string[]): Promise<void>;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { BASE_URL } from './fetch.js';
|
|
4
|
+
import { print, printBanner, printStep, printError, BOLD, DIM, RESET, CYAN, YELLOW, } from './output.js';
|
|
5
|
+
/**
|
|
6
|
+
* `npx claudepluginhub recommend` — instant plugin recommendations for the
|
|
7
|
+
* current project. Reads local manifest dependency NAMES and telltale config
|
|
8
|
+
* FILENAMES (never file contents, never CLAUDE.md) and POSTs them to
|
|
9
|
+
* /api/recommend, where they resolve to vocabulary stacks server-side.
|
|
10
|
+
*/
|
|
11
|
+
const RECOMMEND_URL = `${BASE_URL}/api/recommend?source=cli`;
|
|
12
|
+
/** Server-side body caps (mirrors the /api/recommend Zod schema). */
|
|
13
|
+
const MAX_DEPENDENCIES = 500;
|
|
14
|
+
const MAX_FILES = 200;
|
|
15
|
+
const MAX_DEP_LENGTH = 128;
|
|
16
|
+
const DEFAULT_LIMIT = 10;
|
|
17
|
+
const MAX_LIMIT = 50;
|
|
18
|
+
/**
|
|
19
|
+
* Telltale filename prefixes. Privacy allowlist: when a cwd entry matches a
|
|
20
|
+
* prefix, the PREFIX ITSELF is sent — never the raw basename — so only
|
|
21
|
+
* strings from this fixed list ever leave the machine (a suffix like
|
|
22
|
+
* `next.config.<project-codename>.ts` carries zero recommendation signal
|
|
23
|
+
* anyway, since the server also prefix-matches). Mirrors the server's
|
|
24
|
+
* dep→tech FILE_PREFIX_TO_TECH list
|
|
25
|
+
* (src/features/stack-recommendations/lib/dep-to-tech.ts); drift is fail-soft
|
|
26
|
+
* in both directions — the server ignores unknown names, and a missing prefix
|
|
27
|
+
* here just loses one detection signal.
|
|
28
|
+
*/
|
|
29
|
+
const TELLTALE_PREFIXES = [
|
|
30
|
+
'next.config',
|
|
31
|
+
'nuxt.config',
|
|
32
|
+
'svelte.config',
|
|
33
|
+
'astro.config',
|
|
34
|
+
'remix.config',
|
|
35
|
+
'tailwind.config',
|
|
36
|
+
'vite.config',
|
|
37
|
+
'webpack.config',
|
|
38
|
+
'playwright.config',
|
|
39
|
+
'cypress.config',
|
|
40
|
+
'jest.config',
|
|
41
|
+
'vitest.config',
|
|
42
|
+
'tsconfig',
|
|
43
|
+
'cargo.toml',
|
|
44
|
+
'go.mod',
|
|
45
|
+
'go.sum',
|
|
46
|
+
'pyproject.toml',
|
|
47
|
+
'requirements.txt',
|
|
48
|
+
'setup.py',
|
|
49
|
+
'gemfile',
|
|
50
|
+
'composer.json',
|
|
51
|
+
'build.gradle',
|
|
52
|
+
'pom.xml',
|
|
53
|
+
'mix.exs',
|
|
54
|
+
'dockerfile',
|
|
55
|
+
'docker-compose',
|
|
56
|
+
'pnpm-lock.yaml',
|
|
57
|
+
'yarn.lock',
|
|
58
|
+
'package-lock.json',
|
|
59
|
+
'package.json',
|
|
60
|
+
'deno.json',
|
|
61
|
+
'bun.lockb',
|
|
62
|
+
'terraform.tf',
|
|
63
|
+
'main.tf',
|
|
64
|
+
'helmfile',
|
|
65
|
+
'pubspec.yaml',
|
|
66
|
+
'project.godot',
|
|
67
|
+
];
|
|
68
|
+
export function parseRecommendFlags(argv) {
|
|
69
|
+
const json = argv.includes('--json');
|
|
70
|
+
let limit = DEFAULT_LIMIT;
|
|
71
|
+
const limitIdx = argv.indexOf('--limit');
|
|
72
|
+
if (limitIdx !== -1) {
|
|
73
|
+
const val = argv[limitIdx + 1];
|
|
74
|
+
if (!val || val.startsWith('-')) {
|
|
75
|
+
printError('Missing value for --limit');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const parsed = Number(val);
|
|
79
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > MAX_LIMIT) {
|
|
80
|
+
printError(`Invalid --limit "${val}". Must be an integer 1-${MAX_LIMIT}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
limit = parsed;
|
|
84
|
+
}
|
|
85
|
+
return { limit, json };
|
|
86
|
+
}
|
|
87
|
+
/** Strip a Python requirement spec down to the bare package name. */
|
|
88
|
+
function pythonDepName(spec) {
|
|
89
|
+
return spec.trim().split(/[=<>!~;\[\s]/)[0].trim();
|
|
90
|
+
}
|
|
91
|
+
export function parsePackageJsonDeps(content) {
|
|
92
|
+
try {
|
|
93
|
+
const pkg = JSON.parse(content);
|
|
94
|
+
return [
|
|
95
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
96
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export function parseRequirementsTxt(content) {
|
|
104
|
+
const names = [];
|
|
105
|
+
for (const rawLine of content.split('\n')) {
|
|
106
|
+
const line = rawLine.trim();
|
|
107
|
+
// Skip comments, pip options (-r/-e/--hash …), and URL/path requirements.
|
|
108
|
+
if (!line || line.startsWith('#') || line.startsWith('-'))
|
|
109
|
+
continue;
|
|
110
|
+
if (line.includes('://') || line.startsWith('.') || line.startsWith('/'))
|
|
111
|
+
continue;
|
|
112
|
+
const name = pythonDepName(line);
|
|
113
|
+
if (name)
|
|
114
|
+
names.push(name);
|
|
115
|
+
}
|
|
116
|
+
return names;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Line-based TOML walk (no TOML dependency): track the current `[section]`
|
|
120
|
+
* and collect what each section contributes. Regexes over whole sections
|
|
121
|
+
* break on inline arrays (`features = ["derive"]`), so never use those here.
|
|
122
|
+
*/
|
|
123
|
+
export function parsePyprojectToml(content) {
|
|
124
|
+
const names = [];
|
|
125
|
+
let section = '';
|
|
126
|
+
let inDepsArray = false;
|
|
127
|
+
const pushQuoted = (line) => {
|
|
128
|
+
for (const quoted of line.matchAll(/["']([^"']+)["']/g)) {
|
|
129
|
+
const name = pythonDepName(quoted[1]);
|
|
130
|
+
if (name)
|
|
131
|
+
names.push(name);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
// A `]` inside a quoted spec (extras: "uvicorn[standard]>=0.20") must not
|
|
135
|
+
// close the array — strip quoted segments before checking.
|
|
136
|
+
const closesArray = (fragment) => fragment.replace(/["'][^"']*["']/g, '').includes(']');
|
|
137
|
+
for (const line of content.split('\n')) {
|
|
138
|
+
const header = line.match(/^\s*\[(.+?)\]\s*$/);
|
|
139
|
+
if (header) {
|
|
140
|
+
section = header[1];
|
|
141
|
+
inDepsArray = false;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
// PEP 621 arrays: [project] dependencies = [...], every key of
|
|
145
|
+
// [project.optional-dependencies], and PEP 735 [dependency-groups].
|
|
146
|
+
const isArraySection = section === 'project' ||
|
|
147
|
+
section === 'project.optional-dependencies' ||
|
|
148
|
+
section === 'dependency-groups';
|
|
149
|
+
if (isArraySection) {
|
|
150
|
+
if (inDepsArray) {
|
|
151
|
+
pushQuoted(line);
|
|
152
|
+
if (closesArray(line))
|
|
153
|
+
inDepsArray = false;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const assign = line.match(/^\s*([\w".-]+)\s*=\s*\[(.*)$/);
|
|
157
|
+
if (assign && (section !== 'project' || assign[1] === 'dependencies')) {
|
|
158
|
+
pushQuoted(assign[2]);
|
|
159
|
+
inDepsArray = !closesArray(assign[2]);
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
// Poetry tables: keys under [tool.poetry.dependencies] (+ group variants).
|
|
164
|
+
if (/^tool\.poetry(\.group\.[\w-]+)?\.(dev-)?dependencies$/.test(section)) {
|
|
165
|
+
const key = line.split('=')[0].trim().replace(/^["']|["']$/g, '');
|
|
166
|
+
if (key && !key.startsWith('#') && key !== 'python')
|
|
167
|
+
names.push(key);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return names;
|
|
171
|
+
}
|
|
172
|
+
export function parseCargoToml(content) {
|
|
173
|
+
const names = [];
|
|
174
|
+
let inDepSection = false;
|
|
175
|
+
for (const line of content.split('\n')) {
|
|
176
|
+
const header = line.match(/^\s*\[(.+?)\]\s*$/);
|
|
177
|
+
if (header) {
|
|
178
|
+
// [dependencies], [dev-dependencies], [workspace.dependencies],
|
|
179
|
+
// [target.'cfg(unix)'.dependencies], ...
|
|
180
|
+
inDepSection = /(^|\.)(dev-|build-)?dependencies$/.test(header[1]);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (!inDepSection)
|
|
184
|
+
continue;
|
|
185
|
+
const key = line.split('=')[0].trim();
|
|
186
|
+
if (key && !key.startsWith('#'))
|
|
187
|
+
names.push(key);
|
|
188
|
+
}
|
|
189
|
+
return names;
|
|
190
|
+
}
|
|
191
|
+
export function parseGoMod(content) {
|
|
192
|
+
const names = [];
|
|
193
|
+
const requireBlockRe = /require\s*\(([^)]*)\)/g;
|
|
194
|
+
const modulePathRe = /^\s*([\w.\-/]+)\s+v/;
|
|
195
|
+
for (const match of content.matchAll(requireBlockRe)) {
|
|
196
|
+
for (const line of match[1].split('\n')) {
|
|
197
|
+
const m = line.match(modulePathRe);
|
|
198
|
+
if (m)
|
|
199
|
+
names.push(m[1]);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// Single-line form: require example.com/pkg v1.2.3
|
|
203
|
+
for (const line of content.split('\n')) {
|
|
204
|
+
const m = line.match(/^require\s+([\w.\-/]+)\s+v/);
|
|
205
|
+
if (m)
|
|
206
|
+
names.push(m[1]);
|
|
207
|
+
}
|
|
208
|
+
return names;
|
|
209
|
+
}
|
|
210
|
+
const MANIFEST_PARSERS = [
|
|
211
|
+
['package.json', parsePackageJsonDeps],
|
|
212
|
+
['requirements.txt', parseRequirementsTxt],
|
|
213
|
+
['pyproject.toml', parsePyprojectToml],
|
|
214
|
+
['Cargo.toml', parseCargoToml],
|
|
215
|
+
['go.mod', parseGoMod],
|
|
216
|
+
];
|
|
217
|
+
/**
|
|
218
|
+
* Collect dependency names from known manifests in `cwd` plus telltale config
|
|
219
|
+
* filenames. Fail-soft per manifest: an unreadable or malformed file just
|
|
220
|
+
* contributes nothing (its filename still signals via `files`).
|
|
221
|
+
*/
|
|
222
|
+
export function collectProjectSignals(cwd) {
|
|
223
|
+
let entries;
|
|
224
|
+
try {
|
|
225
|
+
entries = readdirSync(cwd);
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return { dependencies: [], files: [] };
|
|
229
|
+
}
|
|
230
|
+
// Send the matched allowlist prefix, not the raw basename (see the
|
|
231
|
+
// TELLTALE_PREFIXES privacy note).
|
|
232
|
+
const matchedPrefixes = new Set();
|
|
233
|
+
for (const name of entries) {
|
|
234
|
+
const lower = name.toLowerCase();
|
|
235
|
+
for (const prefix of TELLTALE_PREFIXES) {
|
|
236
|
+
if (lower.startsWith(prefix))
|
|
237
|
+
matchedPrefixes.add(prefix);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const files = [...matchedPrefixes].slice(0, MAX_FILES);
|
|
241
|
+
const dependencies = new Set();
|
|
242
|
+
for (const [filename, parse] of MANIFEST_PARSERS) {
|
|
243
|
+
if (!entries.includes(filename))
|
|
244
|
+
continue;
|
|
245
|
+
let content;
|
|
246
|
+
try {
|
|
247
|
+
content = readFileSync(join(cwd, filename), 'utf8');
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
for (const dep of parse(content)) {
|
|
253
|
+
if (dep.length <= MAX_DEP_LENGTH)
|
|
254
|
+
dependencies.add(dep);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return { dependencies: [...dependencies].slice(0, MAX_DEPENDENCIES), files };
|
|
258
|
+
}
|
|
259
|
+
function formatCount(n) {
|
|
260
|
+
return n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n);
|
|
261
|
+
}
|
|
262
|
+
function truncate(text, max) {
|
|
263
|
+
return text.length > max ? `${text.slice(0, max - 1).trimEnd()}…` : text;
|
|
264
|
+
}
|
|
265
|
+
export async function runRecommend(argv) {
|
|
266
|
+
const { limit, json } = parseRecommendFlags(argv);
|
|
267
|
+
if (!json)
|
|
268
|
+
printBanner();
|
|
269
|
+
const signals = collectProjectSignals(process.cwd());
|
|
270
|
+
if (signals.dependencies.length === 0 && signals.files.length === 0) {
|
|
271
|
+
printError('No project manifests found in the current directory.\n' +
|
|
272
|
+
`Run from a project root, or browse ${BASE_URL}/tools/for-your-project`);
|
|
273
|
+
process.exit(1);
|
|
274
|
+
}
|
|
275
|
+
if (!json) {
|
|
276
|
+
printStep(`Detected ${signals.dependencies.length} dependencies, ${signals.files.length} project files`);
|
|
277
|
+
}
|
|
278
|
+
let response;
|
|
279
|
+
try {
|
|
280
|
+
response = await fetch(RECOMMEND_URL, {
|
|
281
|
+
method: 'POST',
|
|
282
|
+
headers: { 'content-type': 'application/json' },
|
|
283
|
+
body: JSON.stringify({
|
|
284
|
+
dependencies: signals.dependencies,
|
|
285
|
+
files: signals.files,
|
|
286
|
+
limit,
|
|
287
|
+
}),
|
|
288
|
+
signal: AbortSignal.timeout(15_000),
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
printError(`Network error: ${err.message}`);
|
|
293
|
+
process.exit(1);
|
|
294
|
+
}
|
|
295
|
+
if (!response.ok) {
|
|
296
|
+
if (response.status === 429) {
|
|
297
|
+
printError('Rate limit exceeded. Please wait a few minutes and try again.');
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
const message = await response
|
|
301
|
+
.json()
|
|
302
|
+
.then((body) => body.error)
|
|
303
|
+
.catch(() => null);
|
|
304
|
+
printError(message ?? `HTTP ${response.status}: ${response.statusText}`);
|
|
305
|
+
}
|
|
306
|
+
process.exit(1);
|
|
307
|
+
}
|
|
308
|
+
const body = (await response.json());
|
|
309
|
+
if (json) {
|
|
310
|
+
print(JSON.stringify(body, null, 2));
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (body.results.length === 0) {
|
|
314
|
+
print('');
|
|
315
|
+
print(`No recommendations yet for: ${body.stacks.join(', ')}`);
|
|
316
|
+
print(`${DIM}Browse plugins at ${BASE_URL}/plugins${RESET}`);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
print('');
|
|
320
|
+
print(`${BOLD}Recommended for:${RESET} ${CYAN}${body.stacks.join(' + ')}${RESET}`);
|
|
321
|
+
if (body.droppedStacks && body.droppedStacks.length > 0) {
|
|
322
|
+
print(`${DIM}(also detected: ${body.droppedStacks.join(', ')} — one request fuses at most ${body.stacks.length} stacks)${RESET}`);
|
|
323
|
+
}
|
|
324
|
+
print('');
|
|
325
|
+
body.results.forEach((item, i) => {
|
|
326
|
+
const rank = `${String(i + 1).padStart(2)}.`;
|
|
327
|
+
const stars = item.starCount > 0 ? ` ${YELLOW}★ ${formatCount(item.starCount)}${RESET}` : '';
|
|
328
|
+
print(`${BOLD}${rank} ${item.name}${RESET}${stars}`);
|
|
329
|
+
if (item.description) {
|
|
330
|
+
print(` ${DIM}${truncate(item.description, 90)}${RESET}`);
|
|
331
|
+
}
|
|
332
|
+
print(` ${CYAN}${item.install.command}${RESET}`);
|
|
333
|
+
print('');
|
|
334
|
+
});
|
|
335
|
+
// Link the always-live picker page, not /for/[stack] — low-coverage stacks
|
|
336
|
+
// (below the min-content gate) 404 there while the API still serves them.
|
|
337
|
+
print(`${DIM}Refine stacks: ${BASE_URL}/tools/for-your-project${RESET}`);
|
|
338
|
+
}
|