claudepluginhub 0.12.0 → 0.13.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 +3 -1
- package/dist/doctor/estimate.d.ts +4 -19
- package/dist/doctor/estimate.js +74 -18
- package/dist/doctor/inventory.d.ts +6 -0
- package/dist/doctor/inventory.js +81 -14
- package/dist/doctor/report.d.ts +7 -1
- 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
|
}
|
|
@@ -71,7 +71,9 @@ function componentsEqual(a, b) {
|
|
|
71
71
|
x.name !== y.name ||
|
|
72
72
|
x.description !== y.description ||
|
|
73
73
|
x.estimable !== y.estimable ||
|
|
74
|
-
x.
|
|
74
|
+
x.disableModelInvocation !== y.disableModelInvocation ||
|
|
75
|
+
x.listingChars !== y.listingChars ||
|
|
76
|
+
x.listingComplete !== y.listingComplete ||
|
|
75
77
|
x.bodyChars !== y.bodyChars ||
|
|
76
78
|
x.hash !== y.hash)
|
|
77
79
|
return false;
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import type { ScanResult } from './report.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* Rule: tokens ≈ ceil(characters / 4), computed from local file contents.
|
|
6
|
-
* - Always-on = the plugin's listing text: each skill/command/agent's
|
|
7
|
-
* frontmatter name + description (mirrors the documented semantics of
|
|
8
|
-
* `claude plugin details`, which counts "listing text ... added to every
|
|
9
|
-
* session"). Hooks/MCP/LSP are NOT estimated.
|
|
10
|
-
* - On-invoke = a component's full body, paid when it fires.
|
|
11
|
-
*
|
|
12
|
-
* All values are estimates: render with a `~` prefix and say so. Components
|
|
13
|
-
* whose frontmatter the bounded reader could not understand are excluded and
|
|
14
|
-
* the plugin is flagged `estimated: false` (unestimated ≠ invalid).
|
|
15
|
-
* `claude plugin details` is the authoritative source; Doctor never parses
|
|
16
|
-
* its human output.
|
|
17
|
-
*/
|
|
18
|
-
export declare const CHARS_PER_TOKEN = 4;
|
|
19
|
-
export declare function estimateTokens(chars: number): number;
|
|
2
|
+
export declare function estimateListingTokens(listingChars: number): number;
|
|
3
|
+
export declare function estimateInvocationTokens(bodyChars: number): number;
|
|
20
4
|
export declare function formatApproxTokens(n: number): string;
|
|
21
5
|
export interface PluginEstimate {
|
|
22
6
|
alwaysOnTokens: number;
|
|
23
|
-
/** True when every skill/command/agent in the plugin was estimable
|
|
7
|
+
/** True when every skill/command/agent in the plugin was estimable and
|
|
8
|
+
* listing text was fully determined. */
|
|
24
9
|
estimated: boolean;
|
|
25
10
|
largestOnInvoke: {
|
|
26
11
|
path: string;
|
package/dist/doctor/estimate.js
CHANGED
|
@@ -2,26 +2,78 @@ import { compareBytes } from './report.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* THE context-estimate heuristic — centralized here, documented once.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
5
|
+
* Listing tokens ≈ ceil(listingChars / 4.5) + 5 per model-visible component.
|
|
6
|
+
* Invocation tokens ≈ ceil(bodyChars / 4.25), where bodyChars EXCLUDES frontmatter.
|
|
7
|
+
*
|
|
8
|
+
* The two ratios model different serialized content:
|
|
9
|
+
* - LISTING (4.5 chars/tok) — structured key/value listing with JSON separators;
|
|
10
|
+
* the +5 per-component overhead covers serialization framing.
|
|
11
|
+
* - INVOCATION (4.25 chars/tok) — raw Markdown body injected as-is; the lower
|
|
12
|
+
* ratio accounts for short-token-dense content in commands and structured
|
|
13
|
+
* Markdown that tokenizes less efficiently than prose.
|
|
14
|
+
*
|
|
15
|
+
* Calibrated against `claude plugin details` output (Claude values are supplied
|
|
16
|
+
* benchmark data, not commands executed in the implementation environment):
|
|
17
|
+
*
|
|
18
|
+
* Always-on listing:
|
|
19
|
+
* pr-review-toolkit (7 components): formula → ~1.5k, Claude → ~1,404
|
|
20
|
+
* commit-commands (3 commands): formula → ~75, Claude → ~76
|
|
21
|
+
* code-review (1 command): formula → ~14, Claude → ~19
|
|
22
|
+
* frontend-design (1 skill): formula → ~54, Claude → ~54
|
|
23
|
+
*
|
|
24
|
+
* Invocation body (all pr-review-toolkit agents + commands):
|
|
25
|
+
* silent-failure-hunter: 1,483 vs Claude ~1,400 (+6%)
|
|
26
|
+
* review-pr: 1,138 vs Claude ~1,100 (+3%)
|
|
27
|
+
* type-design-analyzer: 1,029 vs Claude ~990 (+4%)
|
|
28
|
+
* comment-analyzer: 1,026 vs Claude ~990 (+4%)
|
|
29
|
+
* pr-test-analyzer: 938 vs Claude ~900 (+4%)
|
|
30
|
+
* code-simplifier: 683 vs Claude ~660 (+3%)
|
|
31
|
+
* code-reviewer: 611 vs Claude ~590 (+4%)
|
|
32
|
+
* Invocation body (other plugins):
|
|
33
|
+
* code-review cmd: 1,688 vs Claude ~1,900 (-11%)
|
|
34
|
+
* frontend-design skill: 1,874 vs Claude ~1,700 (+10%)
|
|
35
|
+
* clean_gone: 397 vs Claude ~450 (-12%)
|
|
36
|
+
* commit-push-pr: 143 vs Claude ~160 (-11%)
|
|
37
|
+
* commit: 121 vs Claude ~140 (-14%)
|
|
38
|
+
* Worst-case error: ~14%. No claim of tokenizer parity.
|
|
39
|
+
*
|
|
40
|
+
* - Always-on = the plugin's listing text: each model-visible skill/command/
|
|
41
|
+
* agent's frontmatter listing fields (name + description; skills and legacy
|
|
42
|
+
* commands also include when_to_use, capped at 1,536 combined chars), plus
|
|
43
|
+
* per-component overhead. Skills and commands with
|
|
44
|
+
* `disable-model-invocation: true` are excluded (not listed for model
|
|
45
|
+
* selection); agents ignore this field. Hooks/MCP/LSP are NOT estimated.
|
|
46
|
+
* - On-invoke = a component's body (EXCLUDING frontmatter), paid when it fires.
|
|
47
|
+
*
|
|
48
|
+
* All values are estimates: render with `~`, `<`, or `0` prefix and say so.
|
|
49
|
+
* Components whose frontmatter the bounded reader could not understand are
|
|
50
|
+
* excluded and the plugin is flagged `estimated: false` (unestimated ≠ invalid).
|
|
15
51
|
* `claude plugin details` is the authoritative source; Doctor never parses
|
|
16
52
|
* its human output.
|
|
53
|
+
*
|
|
54
|
+
* Limitations:
|
|
55
|
+
* - Plugin skills are managed through `/plugin`, not `skillOverrides`.
|
|
56
|
+
* Configurable listing caps or token budgets may make Doctor differ from
|
|
57
|
+
* Claude's effective post-budget context.
|
|
58
|
+
* - Skills and commands without a frontmatter description may use a
|
|
59
|
+
* first-body-paragraph fallback that the bounded parser cannot determine;
|
|
60
|
+
* such components mark the listing estimate incomplete rather than silently
|
|
61
|
+
* undercounting.
|
|
17
62
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
63
|
+
const LISTING_CHARS_PER_TOKEN = 4.5;
|
|
64
|
+
const INVOCATION_CHARS_PER_TOKEN = 4.25;
|
|
65
|
+
const PER_COMPONENT_OVERHEAD = 5;
|
|
66
|
+
export function estimateListingTokens(listingChars) {
|
|
67
|
+
return Math.ceil(listingChars / LISTING_CHARS_PER_TOKEN) + PER_COMPONENT_OVERHEAD;
|
|
68
|
+
}
|
|
69
|
+
export function estimateInvocationTokens(bodyChars) {
|
|
70
|
+
return Math.ceil(bodyChars / INVOCATION_CHARS_PER_TOKEN);
|
|
21
71
|
}
|
|
22
72
|
export function formatApproxTokens(n) {
|
|
23
|
-
if (n
|
|
24
|
-
return
|
|
73
|
+
if (n === 0)
|
|
74
|
+
return '~0';
|
|
75
|
+
if (n < 20)
|
|
76
|
+
return '<20';
|
|
25
77
|
if (n < 1000)
|
|
26
78
|
return `~${Math.round(n / 10) * 10}`;
|
|
27
79
|
if (n < 10000) {
|
|
@@ -34,14 +86,18 @@ export function formatApproxTokens(n) {
|
|
|
34
86
|
export function estimatePlugin(scan) {
|
|
35
87
|
const relevant = scan.components.filter((c) => c.type === 'skill' || c.type === 'command' || c.type === 'agent');
|
|
36
88
|
const estimable = relevant.filter((c) => c.estimable);
|
|
37
|
-
|
|
89
|
+
// disable-model-invocation applies to skills and commands only.
|
|
90
|
+
// An agent carrying the field still contributes its normal listing.
|
|
91
|
+
const modelVisible = estimable.filter((c) => !(c.disableModelInvocation && (c.type === 'skill' || c.type === 'command')));
|
|
92
|
+
const alwaysOnTokens = modelVisible.reduce((sum, c) => sum + estimateListingTokens(c.listingChars), 0);
|
|
38
93
|
const largestOnInvoke = estimable
|
|
39
|
-
.map((c) => ({ path: c.relPath, tokens:
|
|
94
|
+
.map((c) => ({ path: c.relPath, tokens: estimateInvocationTokens(c.bodyChars) }))
|
|
40
95
|
.sort((a, b) => b.tokens - a.tokens || compareBytes(a.path, b.path))
|
|
41
96
|
.slice(0, 3);
|
|
97
|
+
const listingComplete = modelVisible.every((c) => c.listingComplete);
|
|
42
98
|
return {
|
|
43
99
|
alwaysOnTokens,
|
|
44
|
-
estimated: estimable.length === relevant.length && !scan.incomplete,
|
|
100
|
+
estimated: estimable.length === relevant.length && !scan.incomplete && listingComplete,
|
|
45
101
|
largestOnInvoke,
|
|
46
102
|
};
|
|
47
103
|
}
|
|
@@ -55,7 +55,13 @@ export declare function createScanner(overrides?: Partial<ScanLimits>): Scanner;
|
|
|
55
55
|
interface ParsedFrontmatter {
|
|
56
56
|
name: string | null;
|
|
57
57
|
description: string | null;
|
|
58
|
+
/** Skills and legacy commands: the documented `when_to_use` field. */
|
|
59
|
+
whenToUse: string | null;
|
|
58
60
|
understood: boolean;
|
|
61
|
+
/** Byte offset where the body begins (after closing `---\n`). 0 = no frontmatter. */
|
|
62
|
+
bodyStartOffset: number;
|
|
63
|
+
/** True only for the unquoted YAML boolean `true`. */
|
|
64
|
+
disableModelInvocation: boolean;
|
|
59
65
|
}
|
|
60
66
|
export declare function parseFrontmatter(content: string): ParsedFrontmatter;
|
|
61
67
|
export declare function hashComponentContent(content: string): string;
|
package/dist/doctor/inventory.js
CHANGED
|
@@ -23,6 +23,10 @@ export const TOOL_MATCHED_EVENTS = new Set([
|
|
|
23
23
|
const FRONTMATTER_MAX_LINES = 100;
|
|
24
24
|
const FRONTMATTER_MAX_BYTES = 16 * 1024;
|
|
25
25
|
const MAX_KEYS = 50;
|
|
26
|
+
/** Default cap on combined description + when_to_use listing text (chars).
|
|
27
|
+
* Configurable listing caps/budgets may cause Doctor to differ from Claude's
|
|
28
|
+
* effective post-budget context. */
|
|
29
|
+
const LISTING_DESC_CAP = 1536;
|
|
26
30
|
/**
|
|
27
31
|
* Aggregate cap on hook/MCP/LSP/monitor facts per plugin. Parse helpers stop
|
|
28
32
|
* producing at MAX_FACTS_PER_TYPE + 1 so the scanner can DETECT the overflow
|
|
@@ -515,28 +519,53 @@ function readBlockScalar(lines, startIndex, limit, indicator, chomping) {
|
|
|
515
519
|
return { value, nextIndex: i, truncated: false };
|
|
516
520
|
}
|
|
517
521
|
export function parseFrontmatter(content) {
|
|
522
|
+
const empty = {
|
|
523
|
+
name: null, description: null, whenToUse: null,
|
|
524
|
+
understood: true, bodyStartOffset: 0, disableModelInvocation: false,
|
|
525
|
+
};
|
|
518
526
|
if (!content.startsWith('---'))
|
|
519
|
-
return
|
|
527
|
+
return empty;
|
|
520
528
|
const slice = content.slice(0, FRONTMATTER_MAX_BYTES);
|
|
521
529
|
const lines = slice.split('\n');
|
|
522
530
|
let name = null;
|
|
523
531
|
let description = null;
|
|
532
|
+
let whenToUse = null;
|
|
524
533
|
let closed = false;
|
|
534
|
+
let disableModelInvocation = false;
|
|
525
535
|
const lineLimit = Math.min(lines.length, FRONTMATTER_MAX_LINES);
|
|
536
|
+
let offset = lines[0].length + 1; // skip opening '---\n'
|
|
526
537
|
for (let i = 1; i < lineLimit; i += 1) {
|
|
527
538
|
const line = lines[i];
|
|
528
539
|
if (/^---\s*$/.test(line) && !line.startsWith(' ') && !line.startsWith('\t')) {
|
|
529
540
|
closed = true;
|
|
541
|
+
offset += line.length + 1;
|
|
530
542
|
break;
|
|
531
543
|
}
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
544
|
+
const dmiMatch = line.match(/^disable-model-invocation\s*:\s*(.*)$/);
|
|
545
|
+
if (dmiMatch) {
|
|
546
|
+
// Only unquoted YAML boolean `true` disables. Quoted "true", 'true',
|
|
547
|
+
// yes, 1, and malformed values must NOT silently disable.
|
|
548
|
+
disableModelInvocation = dmiMatch[1].trim() === 'true';
|
|
549
|
+
offset += line.length + 1;
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
// Only the documented `when_to_use` spelling is recognized.
|
|
553
|
+
// `when-to-use` (hyphen) has no official compatibility contract and must
|
|
554
|
+
// not silently change estimates.
|
|
555
|
+
const match = line.match(/^(name|description|when_to_use)\s*:\s*(.*)$/);
|
|
556
|
+
if (!match) {
|
|
557
|
+
offset += line.length + 1;
|
|
534
558
|
continue;
|
|
559
|
+
}
|
|
560
|
+
const key = match[1];
|
|
535
561
|
const value = match[2].trim();
|
|
536
562
|
// Explicit indent indicators (|2, >2, >+1, etc.) are uncommon and complex —
|
|
537
563
|
// mark as not understood rather than risk a wrong parse.
|
|
538
564
|
if (BLOCK_SCALAR_EXPLICIT_INDENT_RE.test(value)) {
|
|
539
|
-
return {
|
|
565
|
+
return {
|
|
566
|
+
name, description, whenToUse,
|
|
567
|
+
understood: false, bodyStartOffset: content.length, disableModelInvocation,
|
|
568
|
+
};
|
|
540
569
|
}
|
|
541
570
|
const blockMatch = value.match(BLOCK_SCALAR_RE);
|
|
542
571
|
if (blockMatch) {
|
|
@@ -544,24 +573,42 @@ export function parseFrontmatter(content) {
|
|
|
544
573
|
const chomping = blockMatch[2];
|
|
545
574
|
const result = readBlockScalar(lines, i + 1, lineLimit, indicator, chomping);
|
|
546
575
|
if (result.truncated) {
|
|
547
|
-
return {
|
|
576
|
+
return {
|
|
577
|
+
name, description, whenToUse,
|
|
578
|
+
understood: false, bodyStartOffset: content.length, disableModelInvocation,
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
// Advance offset for the key line and all block-scalar lines consumed
|
|
582
|
+
for (let j = i; j < result.nextIndex; j++) {
|
|
583
|
+
offset += lines[j].length + 1;
|
|
548
584
|
}
|
|
549
585
|
i = result.nextIndex - 1;
|
|
550
|
-
if (
|
|
586
|
+
if (key === 'name')
|
|
551
587
|
name = result.value;
|
|
552
|
-
else
|
|
588
|
+
else if (key === 'description')
|
|
553
589
|
description = result.value;
|
|
590
|
+
else
|
|
591
|
+
whenToUse = result.value;
|
|
554
592
|
continue;
|
|
555
593
|
}
|
|
556
|
-
if (value === '')
|
|
594
|
+
if (value === '') {
|
|
595
|
+
offset += line.length + 1;
|
|
557
596
|
continue;
|
|
597
|
+
}
|
|
558
598
|
const unquoted = value.replace(/^["']/, '').replace(/["']$/, '');
|
|
559
|
-
if (
|
|
599
|
+
if (key === 'name')
|
|
560
600
|
name = unquoted;
|
|
561
|
-
else
|
|
601
|
+
else if (key === 'description')
|
|
562
602
|
description = unquoted;
|
|
603
|
+
else
|
|
604
|
+
whenToUse = unquoted;
|
|
605
|
+
offset += line.length + 1;
|
|
563
606
|
}
|
|
564
|
-
|
|
607
|
+
const bodyStartOffset = closed ? Math.min(offset, content.length) : content.length;
|
|
608
|
+
return {
|
|
609
|
+
name, description, whenToUse,
|
|
610
|
+
understood: closed, bodyStartOffset, disableModelInvocation,
|
|
611
|
+
};
|
|
565
612
|
}
|
|
566
613
|
function normalizeForHash(content) {
|
|
567
614
|
return content.replace(/\r\n/g, '\n').replace(/\s+$/, '');
|
|
@@ -582,7 +629,9 @@ function buildComponent(type, relPath, content) {
|
|
|
582
629
|
name: type === 'skill' ? basename(relPath) : fileStem(relPath),
|
|
583
630
|
description: null,
|
|
584
631
|
estimable: false,
|
|
585
|
-
|
|
632
|
+
disableModelInvocation: false,
|
|
633
|
+
listingChars: 0,
|
|
634
|
+
listingComplete: true,
|
|
586
635
|
bodyChars: 0,
|
|
587
636
|
hash: null,
|
|
588
637
|
};
|
|
@@ -590,14 +639,32 @@ function buildComponent(type, relPath, content) {
|
|
|
590
639
|
const frontmatter = parseFrontmatter(content);
|
|
591
640
|
const fallbackName = type === 'skill' ? basename(relPath.replace(/\/SKILL\.md$/, '')) : fileStem(relPath);
|
|
592
641
|
const name = frontmatter.name ?? (fallbackName === 'SKILL.md' ? 'skill' : fallbackName);
|
|
642
|
+
// Skills and legacy commands list name + description + whenToUse (capped at
|
|
643
|
+
// 1,536 chars for description+whenToUse combined); agents list name + description.
|
|
644
|
+
// The component name is outside that cap.
|
|
645
|
+
const isSkillOrCommand = type === 'skill' || type === 'command';
|
|
646
|
+
const descLen = frontmatter.description?.length ?? 0;
|
|
647
|
+
const wtuLen = isSkillOrCommand ? (frontmatter.whenToUse?.length ?? 0) : 0;
|
|
648
|
+
const cappedDescWtu = isSkillOrCommand
|
|
649
|
+
? Math.min(descLen + wtuLen, LISTING_DESC_CAP)
|
|
650
|
+
: descLen;
|
|
651
|
+
const listingChars = name.length + cappedDescWtu;
|
|
652
|
+
// Skills/commands without a description may use a first-body-paragraph
|
|
653
|
+
// fallback that the bounded parser cannot safely determine — mark listing
|
|
654
|
+
// incomplete. Agents use only name+description semantics.
|
|
655
|
+
const listingComplete = isSkillOrCommand
|
|
656
|
+
? frontmatter.description !== null
|
|
657
|
+
: true;
|
|
593
658
|
return {
|
|
594
659
|
type,
|
|
595
660
|
relPath,
|
|
596
661
|
name,
|
|
597
662
|
description: frontmatter.description,
|
|
598
663
|
estimable: frontmatter.understood,
|
|
599
|
-
|
|
600
|
-
|
|
664
|
+
disableModelInvocation: frontmatter.disableModelInvocation,
|
|
665
|
+
listingChars,
|
|
666
|
+
listingComplete,
|
|
667
|
+
bodyChars: content.length - frontmatter.bodyStartOffset,
|
|
601
668
|
hash: type === 'outputStyle' ? null : hashComponentContent(content),
|
|
602
669
|
};
|
|
603
670
|
}
|
package/dist/doctor/report.d.ts
CHANGED
|
@@ -79,7 +79,13 @@ export interface ComponentInfo {
|
|
|
79
79
|
description: string | null;
|
|
80
80
|
/** False when the bounded frontmatter reader could not understand the file. */
|
|
81
81
|
estimable: boolean;
|
|
82
|
-
|
|
82
|
+
/** True only for unquoted YAML boolean `true` in frontmatter. */
|
|
83
|
+
disableModelInvocation: boolean;
|
|
84
|
+
/** Characters contributing to the session listing: name + description + whenToUse (skills). */
|
|
85
|
+
listingChars: number;
|
|
86
|
+
/** False when the bounded parser could not determine all listing text (e.g. skill
|
|
87
|
+
* with no description may use a first-body-paragraph fallback we cannot safely parse). */
|
|
88
|
+
listingComplete: boolean;
|
|
83
89
|
bodyChars: number;
|
|
84
90
|
/** Normalized content hash — only for skill/command/agent. */
|
|
85
91
|
hash: string | null;
|
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
|
+
}
|