vibecode-anything 0.3.0 → 0.4.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 +239 -67
- package/dist/cli.js +2140 -73
- package/dist/core/adapters.d.ts +26 -3
- package/dist/core/adapters.js +411 -25
- package/dist/core/agent-adapter.d.ts +67 -0
- package/dist/core/agent-adapter.js +312 -0
- package/dist/core/anti-cheat.d.ts +6 -0
- package/dist/core/anti-cheat.js +372 -0
- package/dist/core/badge.d.ts +18 -0
- package/dist/core/badge.js +360 -0
- package/dist/core/cache.d.ts +47 -0
- package/dist/core/cache.js +403 -0
- package/dist/core/ci-export.d.ts +35 -0
- package/dist/core/ci-export.js +796 -0
- package/dist/core/ci-formats.d.ts +21 -0
- package/dist/core/ci-formats.js +388 -0
- package/dist/core/client-codegen.d.ts +36 -0
- package/dist/core/client-codegen.js +2538 -0
- package/dist/core/compose.d.ts +71 -0
- package/dist/core/compose.js +1088 -0
- package/dist/core/docs-export.d.ts +37 -0
- package/dist/core/docs-export.js +2706 -0
- package/dist/core/doctor.d.ts +21 -1
- package/dist/core/doctor.js +234 -21
- package/dist/core/exec.d.ts +26 -2
- package/dist/core/exec.js +235 -8
- package/dist/core/fixtures.d.ts +153 -0
- package/dist/core/fixtures.js +2245 -0
- package/dist/core/format.d.ts +77 -0
- package/dist/core/format.js +632 -0
- package/dist/core/fs-snapshot.d.ts +37 -0
- package/dist/core/fs-snapshot.js +216 -0
- package/dist/core/graphql-export.d.ts +34 -0
- package/dist/core/graphql-export.js +2482 -0
- package/dist/core/har-export.d.ts +29 -0
- package/dist/core/har-export.js +988 -0
- package/dist/core/html-report.d.ts +27 -0
- package/dist/core/html-report.js +1535 -0
- package/dist/core/http-export.d.ts +31 -0
- package/dist/core/http-export.js +726 -0
- package/dist/core/impact.d.ts +80 -0
- package/dist/core/impact.js +1412 -0
- package/dist/core/lint.d.ts +38 -0
- package/dist/core/lint.js +1111 -0
- package/dist/core/load-export.d.ts +37 -0
- package/dist/core/load-export.js +1813 -0
- package/dist/core/mcp-export.d.ts +35 -0
- package/dist/core/mcp-export.js +1736 -0
- package/dist/core/mock-server.d.ts +47 -0
- package/dist/core/mock-server.js +1722 -0
- package/dist/core/openapi-export.d.ts +44 -0
- package/dist/core/openapi-export.js +1074 -0
- package/dist/core/parity.d.ts +6 -1
- package/dist/core/parity.js +36 -1
- package/dist/core/playwright-exporter.d.ts +23 -0
- package/dist/core/playwright-exporter.js +1343 -0
- package/dist/core/png.js +45 -9
- package/dist/core/regression.d.ts +54 -0
- package/dist/core/regression.js +529 -0
- package/dist/core/responsive.d.ts +86 -0
- package/dist/core/responsive.js +606 -0
- package/dist/core/run.d.ts +74 -0
- package/dist/core/run.js +696 -0
- package/dist/core/scheduler.d.ts +24 -0
- package/dist/core/scheduler.js +162 -0
- package/dist/core/schema-export.d.ts +29 -0
- package/dist/core/schema-export.js +2215 -0
- package/dist/core/schema.d.ts +3 -2
- package/dist/core/schema.js +460 -17
- package/dist/core/security.d.ts +233 -0
- package/dist/core/security.js +1839 -0
- package/dist/core/server-export.d.ts +38 -0
- package/dist/core/server-export.js +3198 -0
- package/dist/core/spec-writer.d.ts +9 -0
- package/dist/core/spec-writer.js +1202 -0
- package/dist/core/store.d.ts +11 -2
- package/dist/core/store.js +128 -8
- package/dist/core/target-map.d.ts +34 -0
- package/dist/core/target-map.js +262 -0
- package/dist/core/test-exporter.d.ts +25 -0
- package/dist/core/test-exporter.js +1918 -0
- package/dist/core/types.d.ts +182 -14
- package/dist/core/visual-semantic.d.ts +67 -0
- package/dist/core/visual-semantic.js +673 -0
- package/dist/core/visual.js +65 -16
- package/dist/core/watch.d.ts +28 -3
- package/dist/core/watch.js +222 -12
- package/dist/core/yaml.d.ts +5 -0
- package/dist/core/yaml.js +1009 -0
- package/dist/diagnostics/diagnose.d.ts +53 -0
- package/dist/diagnostics/diagnose.js +1083 -0
- package/dist/diagnostics/flake.d.ts +71 -0
- package/dist/diagnostics/flake.js +608 -0
- package/dist/diagnostics/mutation-audit.d.ts +69 -0
- package/dist/diagnostics/mutation-audit.js +769 -0
- package/dist/diagnostics/spatial.d.ts +42 -0
- package/dist/diagnostics/spatial.js +346 -0
- package/dist/diagnostics/trends.d.ts +122 -0
- package/dist/diagnostics/trends.js +1190 -0
- package/dist/discovery/discover.d.ts +111 -0
- package/dist/discovery/discover.js +2017 -0
- package/dist/discovery/lock.d.ts +116 -0
- package/dist/discovery/lock.js +1505 -0
- package/dist/discovery/routes.d.ts +36 -0
- package/dist/discovery/routes.js +1494 -0
- package/dist/discovery/test-importer.d.ts +92 -0
- package/dist/discovery/test-importer.js +4952 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +99 -0
- package/dist/ingestors/api-collections.d.ts +28 -0
- package/dist/ingestors/api-collections.js +2335 -0
- package/dist/ingestors/api-repo.d.ts +2 -1
- package/dist/ingestors/api-repo.js +483 -85
- package/dist/ingestors/asyncapi.d.ts +26 -0
- package/dist/ingestors/asyncapi.js +2105 -0
- package/dist/ingestors/bridges.d.ts +2 -0
- package/dist/ingestors/bridges.js +702 -0
- package/dist/ingestors/cli.d.ts +2 -1
- package/dist/ingestors/cli.js +234 -46
- package/dist/ingestors/curl.d.ts +14 -0
- package/dist/ingestors/curl.js +1024 -0
- package/dist/ingestors/graphql.d.ts +56 -0
- package/dist/ingestors/graphql.js +1852 -0
- package/dist/ingestors/http-file.d.ts +20 -0
- package/dist/ingestors/http-file.js +923 -0
- package/dist/ingestors/index.js +486 -6
- package/dist/ingestors/openrpc.d.ts +29 -0
- package/dist/ingestors/openrpc.js +1807 -0
- package/dist/ingestors/proto.d.ts +47 -0
- package/dist/ingestors/proto.js +2690 -0
- package/dist/ingestors/trace.d.ts +10 -0
- package/dist/ingestors/trace.js +599 -0
- package/dist/ingestors/video.d.ts +4 -1
- package/dist/ingestors/video.js +86 -36
- package/dist/ingestors/web.d.ts +16 -1
- package/dist/ingestors/web.js +474 -32
- package/dist/mcp/server.js +3532 -67
- package/dist/oracles/api-repo.js +102 -30
- package/dist/oracles/cli.js +65 -17
- package/dist/oracles/http-workflow.d.ts +68 -0
- package/dist/oracles/http-workflow.js +828 -0
- package/dist/oracles/image.js +178 -28
- package/dist/oracles/index.d.ts +3 -1
- package/dist/oracles/index.js +243 -14
- package/dist/oracles/perf-budget.d.ts +90 -0
- package/dist/oracles/perf-budget.js +1329 -0
- package/dist/oracles/stream.d.ts +94 -0
- package/dist/oracles/stream.js +1268 -0
- package/dist/oracles/ui-states.d.ts +49 -0
- package/dist/oracles/ui-states.js +894 -0
- package/dist/oracles/video.d.ts +1 -1
- package/dist/oracles/video.js +232 -16
- package/dist/oracles/web.js +464 -73
- package/dist/plugins/builtins.d.ts +12 -0
- package/dist/plugins/builtins.js +1052 -0
- package/dist/plugins/registry.d.ts +86 -0
- package/dist/plugins/registry.js +554 -0
- package/dist/setup/index.js +145 -33
- package/package.json +56 -47
- package/skills/vibecode-anything/SKILL.md +75 -52
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency, typed local Plugin SDK registry & confined ESM loader.
|
|
3
|
+
*
|
|
4
|
+
* Strict erasable TypeScript (no enum, no namespace, no constructor parameter properties).
|
|
5
|
+
* Map-backed (zero prototype pollution) with timeout isolation and secret/vault redaction.
|
|
6
|
+
*/
|
|
7
|
+
import type { ContractV02, IngestOptions, Invariant, OracleContext, OracleInvariantOutcome, ParityReport, VerifyDeps } from "../core/types.js";
|
|
8
|
+
export type PluginKind = "ingestor" | "oracle" | "reporter";
|
|
9
|
+
export interface IngestorPlugin {
|
|
10
|
+
kind: "ingestor";
|
|
11
|
+
name: string;
|
|
12
|
+
version?: string;
|
|
13
|
+
domains: readonly string[];
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
ingest(source: string, options?: IngestOptions): Promise<ContractV02> | ContractV02;
|
|
16
|
+
}
|
|
17
|
+
export interface OraclePlugin {
|
|
18
|
+
kind: "oracle";
|
|
19
|
+
name: string;
|
|
20
|
+
version?: string;
|
|
21
|
+
invariantTypes: readonly string[];
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
verify(invariant: Invariant, ctx: OracleContext, deps?: VerifyDeps): Promise<OracleInvariantOutcome> | OracleInvariantOutcome;
|
|
24
|
+
}
|
|
25
|
+
export interface ReporterPlugin {
|
|
26
|
+
kind: "reporter";
|
|
27
|
+
name: string;
|
|
28
|
+
version?: string;
|
|
29
|
+
format: string;
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
render(report: ParityReport, options?: Record<string, unknown>): Promise<string> | string;
|
|
32
|
+
}
|
|
33
|
+
export type VibecodePlugin = IngestorPlugin | OraclePlugin | ReporterPlugin;
|
|
34
|
+
export interface PluginSummary {
|
|
35
|
+
kind: PluginKind;
|
|
36
|
+
name: string;
|
|
37
|
+
version?: string;
|
|
38
|
+
targets: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface RegisterPluginOptions {
|
|
41
|
+
allowOverride?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface PluginRegistryOptions {
|
|
44
|
+
maxPlugins?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface LoadLocalPluginsOptions {
|
|
47
|
+
registry?: PluginRegistry;
|
|
48
|
+
allowOverride?: boolean;
|
|
49
|
+
maxPlugins?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface LoadLocalPluginsResult {
|
|
52
|
+
registry: PluginRegistry;
|
|
53
|
+
loaded: string[];
|
|
54
|
+
}
|
|
55
|
+
export declare const DEFAULT_PLUGIN_TIMEOUT_MS = 10000;
|
|
56
|
+
export declare const MIN_PLUGIN_TIMEOUT_MS = 50;
|
|
57
|
+
export declare const MAX_PLUGIN_TIMEOUT_MS = 60000;
|
|
58
|
+
export declare const RESERVED_CORE_INVARIANT_TYPES: ReadonlySet<string>;
|
|
59
|
+
export declare const RESERVED_CORE_DOMAINS: ReadonlySet<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Runs a sync/async plugin task with a bounded timeout, clearing the timer on
|
|
62
|
+
* settlement so zero timers linger and late rejections never go unhandled.
|
|
63
|
+
* The timeout timer intentionally stays ref'd until settlement so an unresolved
|
|
64
|
+
* promise with no active I/O handles (e.g. `new Promise(() => {})`) still triggers
|
|
65
|
+
* `EXEC_TIMEOUT` cleanly instead of letting Node 22 exit the event loop early.
|
|
66
|
+
*/
|
|
67
|
+
export declare function runWithPluginTimeout<T>(label: string, timeoutMs: number | undefined, task: () => Promise<T> | T): Promise<T>;
|
|
68
|
+
export declare class PluginRegistry {
|
|
69
|
+
private readonly maxPlugins;
|
|
70
|
+
private readonly byName;
|
|
71
|
+
private readonly ingestors;
|
|
72
|
+
private readonly oracles;
|
|
73
|
+
private readonly reporters;
|
|
74
|
+
constructor(options?: PluginRegistryOptions);
|
|
75
|
+
private targetMapFor;
|
|
76
|
+
register(plugin: VibecodePlugin, options?: RegisterPluginOptions): void;
|
|
77
|
+
unregister(name: string): boolean;
|
|
78
|
+
list(): PluginSummary[];
|
|
79
|
+
getIngestor(domain: string): IngestorPlugin | null;
|
|
80
|
+
getOracle(invariantType: string): OraclePlugin | null;
|
|
81
|
+
getReporter(format: string): ReporterPlugin | null;
|
|
82
|
+
runOracle(invariant: Invariant, ctx: OracleContext, deps?: VerifyDeps): Promise<OracleInvariantOutcome | null>;
|
|
83
|
+
runReporter(format: string, report: ParityReport, options?: Record<string, unknown>): Promise<string>;
|
|
84
|
+
}
|
|
85
|
+
/** Loads and registers local ESM `.mjs`/`.js` plugins strictly confined to `cwd`. */
|
|
86
|
+
export declare function loadLocalPlugins(cwd: string, pluginPaths: readonly string[], options?: LoadLocalPluginsOptions): Promise<LoadLocalPluginsResult>;
|
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency, typed local Plugin SDK registry & confined ESM loader.
|
|
3
|
+
*
|
|
4
|
+
* Strict erasable TypeScript (no enum, no namespace, no constructor parameter properties).
|
|
5
|
+
* Map-backed (zero prototype pollution) with timeout isolation and secret/vault redaction.
|
|
6
|
+
*/
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { VibecodeError, toDiagnostic } from "../core/errors.js";
|
|
11
|
+
import { STRICT_CONTROL_CHARS_RE, hasCrossPlatformPathEscape, hasUnsafeRelativeSegment, hasVaultOrHoldoutSegment, isInsideVaultDirectory, isPathWithinDir, isRecordSafe, isSecretRelativePath, redactDeepValue, redactSensitiveText, safeString } from "../core/security.js";
|
|
12
|
+
export const DEFAULT_PLUGIN_TIMEOUT_MS = 10_000;
|
|
13
|
+
export const MIN_PLUGIN_TIMEOUT_MS = 50;
|
|
14
|
+
export const MAX_PLUGIN_TIMEOUT_MS = 60_000;
|
|
15
|
+
export const RESERVED_CORE_INVARIANT_TYPES = new Set([
|
|
16
|
+
"command", "web_route", "web_flow", "web_network", "web_ui_states",
|
|
17
|
+
"image_layout", "image_perceptual", "video_timeline",
|
|
18
|
+
"http", "http_workflow", "http_stream", "ws_protocol", "perf_budget", "repo_exports"
|
|
19
|
+
]);
|
|
20
|
+
export const RESERVED_CORE_DOMAINS = new Set([
|
|
21
|
+
"cli", "web", "image", "video", "api", "repo", "script", "url",
|
|
22
|
+
"rea", "cli-anything", "postman", "curl", "graphql", "http-file", "insomnia", "bruno", "asyncapi", "proto", "openrpc"
|
|
23
|
+
]);
|
|
24
|
+
const DEFAULT_MAX_LOCAL_PLUGINS = 32;
|
|
25
|
+
const HARD_MAX_LOCAL_PLUGINS = 256;
|
|
26
|
+
const MAX_TARGETS_PER_PLUGIN = 64;
|
|
27
|
+
const MAX_REDACT_DEPTH = 16;
|
|
28
|
+
const MAX_REDACT_NODES = 2048;
|
|
29
|
+
const MAX_OUTCOME_FAILURES = 256;
|
|
30
|
+
const PLUGIN_ID_RE = /^[a-z][a-z0-9_.:-]{0,63}$/;
|
|
31
|
+
const ALLOWED_PLUGIN_EXTS = new Set([".mjs", ".js"]);
|
|
32
|
+
const FORBIDDEN_IDS = new Set([
|
|
33
|
+
"__proto__",
|
|
34
|
+
"constructor",
|
|
35
|
+
"prototype",
|
|
36
|
+
"tostring",
|
|
37
|
+
"valueof",
|
|
38
|
+
"hasownproperty",
|
|
39
|
+
"isprototypeof",
|
|
40
|
+
"propertyisenumerable",
|
|
41
|
+
"tolocalestring"
|
|
42
|
+
]);
|
|
43
|
+
const VALID_STATUSES = new Set(["pass", "fail", "skipped", "warn", "error"]);
|
|
44
|
+
const isPlainObject = isRecordSafe;
|
|
45
|
+
function clampTimeout(timeoutMs) {
|
|
46
|
+
if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs))
|
|
47
|
+
return DEFAULT_PLUGIN_TIMEOUT_MS;
|
|
48
|
+
return Math.min(MAX_PLUGIN_TIMEOUT_MS, Math.max(MIN_PLUGIN_TIMEOUT_MS, Math.floor(timeoutMs)));
|
|
49
|
+
}
|
|
50
|
+
function validateId(label, raw) {
|
|
51
|
+
if (typeof raw !== "string" || !PLUGIN_ID_RE.test(raw) || FORBIDDEN_IDS.has(raw.toLowerCase())) {
|
|
52
|
+
throw new VibecodeError("CONFIG_INVALID", `Invalid ${label}: "${redactSensitiveText(safeString(raw))}" (must match ${PLUGIN_ID_RE.source})`);
|
|
53
|
+
}
|
|
54
|
+
return raw;
|
|
55
|
+
}
|
|
56
|
+
function validateTargetList(label, raw) {
|
|
57
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
58
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin ${label} must be a non-empty array`);
|
|
59
|
+
}
|
|
60
|
+
if (raw.length > MAX_TARGETS_PER_PLUGIN) {
|
|
61
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin ${label} exceeds maximum target count (${MAX_TARGETS_PER_PLUGIN})`);
|
|
62
|
+
}
|
|
63
|
+
return [...new Set(raw.map((entry) => validateId(label, entry)))];
|
|
64
|
+
}
|
|
65
|
+
function redactPluginMap(value) {
|
|
66
|
+
return redactDeepValue(value, {
|
|
67
|
+
maxDepth: MAX_REDACT_DEPTH,
|
|
68
|
+
maxNodes: MAX_REDACT_NODES,
|
|
69
|
+
sensitiveKeyMode: "strings",
|
|
70
|
+
sanitizeNonFiniteNumbers: true,
|
|
71
|
+
stringifyNonJsonPrimitives: true
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function safeToDiagnostic(err) {
|
|
75
|
+
try {
|
|
76
|
+
const diag = toDiagnostic(err);
|
|
77
|
+
return {
|
|
78
|
+
code: typeof diag.code === "string" && diag.code ? diag.code : "INTERNAL_ERROR",
|
|
79
|
+
message: safeString(diag.message),
|
|
80
|
+
...(typeof diag.adapter === "string" && diag.adapter ? { adapter: diag.adapter } : {}),
|
|
81
|
+
...(typeof diag.installHint === "string" && diag.installHint ? { installHint: diag.installHint } : {}),
|
|
82
|
+
...(typeof diag.fallbackHint === "string" && diag.fallbackHint ? { fallbackHint: diag.fallbackHint } : {})
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return { code: "INTERNAL_ERROR", message: safeString(err) || "Unknown plugin error" };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function redactDiagnostic(diag, pluginName) {
|
|
90
|
+
const out = {
|
|
91
|
+
code: typeof diag.code === "string" && diag.code ? redactSensitiveText(diag.code) : "EXEC_ERROR",
|
|
92
|
+
message: redactSensitiveText(safeString(diag.message)),
|
|
93
|
+
adapter: typeof diag.adapter === "string" && diag.adapter ? redactSensitiveText(diag.adapter) : `plugin:${pluginName}`
|
|
94
|
+
};
|
|
95
|
+
if (typeof diag.installHint === "string" && diag.installHint)
|
|
96
|
+
out.installHint = redactSensitiveText(diag.installHint);
|
|
97
|
+
if (typeof diag.fallbackHint === "string" && diag.fallbackHint)
|
|
98
|
+
out.fallbackHint = redactSensitiveText(diag.fallbackHint);
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
function normalizeOutcome(raw, pluginName) {
|
|
102
|
+
if (!isPlainObject(raw)) {
|
|
103
|
+
const message = redactSensitiveText(`Plugin "${pluginName}" returned a malformed outcome (expected object)`);
|
|
104
|
+
return {
|
|
105
|
+
status: "fail",
|
|
106
|
+
score: 0,
|
|
107
|
+
failures: [message],
|
|
108
|
+
reason: message,
|
|
109
|
+
diagnostic: { code: "EXEC_ERROR", message, adapter: `plugin:${pluginName}` },
|
|
110
|
+
metrics: { plugin: pluginName }
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const rawStatus = raw.status;
|
|
114
|
+
if (typeof rawStatus !== "string" || !VALID_STATUSES.has(rawStatus)) {
|
|
115
|
+
const message = `Plugin "${pluginName}" returned invalid outcome status "${redactSensitiveText(safeString(rawStatus))}"`;
|
|
116
|
+
return {
|
|
117
|
+
status: "fail",
|
|
118
|
+
score: 0,
|
|
119
|
+
failures: [message],
|
|
120
|
+
reason: message,
|
|
121
|
+
diagnostic: { code: "EXEC_ERROR", message, adapter: `plugin:${pluginName}` },
|
|
122
|
+
metrics: { plugin: pluginName }
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const status = rawStatus;
|
|
126
|
+
const score = typeof raw.score === "number" && Number.isFinite(raw.score)
|
|
127
|
+
? Math.max(0, Math.min(1, raw.score))
|
|
128
|
+
: (status === "pass" ? 1 : 0);
|
|
129
|
+
const outcome = { status, score };
|
|
130
|
+
if (Array.isArray(raw.failures)) {
|
|
131
|
+
const capped = raw.failures.length > MAX_OUTCOME_FAILURES ? raw.failures.slice(0, MAX_OUTCOME_FAILURES) : raw.failures;
|
|
132
|
+
outcome.failures = capped.map((f) => redactSensitiveText(safeString(f)));
|
|
133
|
+
}
|
|
134
|
+
if (typeof raw.reason === "string" && raw.reason.length > 0)
|
|
135
|
+
outcome.reason = redactSensitiveText(raw.reason);
|
|
136
|
+
if (isPlainObject(raw.diff)) {
|
|
137
|
+
outcome.diff = redactPluginMap(raw.diff);
|
|
138
|
+
}
|
|
139
|
+
outcome.metrics = isPlainObject(raw.metrics)
|
|
140
|
+
? {
|
|
141
|
+
...redactPluginMap(raw.metrics),
|
|
142
|
+
plugin: pluginName
|
|
143
|
+
}
|
|
144
|
+
: { plugin: pluginName };
|
|
145
|
+
if (isPlainObject(raw.diagnostic) && typeof raw.diagnostic.code === "string" && typeof raw.diagnostic.message === "string") {
|
|
146
|
+
outcome.diagnostic = redactDiagnostic(raw.diagnostic, pluginName);
|
|
147
|
+
}
|
|
148
|
+
return outcome;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Runs a sync/async plugin task with a bounded timeout, clearing the timer on
|
|
152
|
+
* settlement so zero timers linger and late rejections never go unhandled.
|
|
153
|
+
* The timeout timer intentionally stays ref'd until settlement so an unresolved
|
|
154
|
+
* promise with no active I/O handles (e.g. `new Promise(() => {})`) still triggers
|
|
155
|
+
* `EXEC_TIMEOUT` cleanly instead of letting Node 22 exit the event loop early.
|
|
156
|
+
*/
|
|
157
|
+
export async function runWithPluginTimeout(label, timeoutMs, task) {
|
|
158
|
+
const effectiveMs = clampTimeout(timeoutMs);
|
|
159
|
+
const safeLabel = redactSensitiveText(safeString(label) || "plugin");
|
|
160
|
+
let timer;
|
|
161
|
+
let settled = false;
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
const finish = (cb) => {
|
|
164
|
+
if (settled)
|
|
165
|
+
return;
|
|
166
|
+
settled = true;
|
|
167
|
+
if (timer !== undefined) {
|
|
168
|
+
clearTimeout(timer);
|
|
169
|
+
timer = undefined;
|
|
170
|
+
}
|
|
171
|
+
cb();
|
|
172
|
+
};
|
|
173
|
+
timer = setTimeout(() => {
|
|
174
|
+
finish(() => reject(new VibecodeError("EXEC_TIMEOUT", `Plugin "${safeLabel}" timed out after ${effectiveMs}ms`, {
|
|
175
|
+
adapter: `plugin:${safeLabel}`,
|
|
176
|
+
details: { plugin: safeLabel, timeoutMs: effectiveMs }
|
|
177
|
+
})));
|
|
178
|
+
}, effectiveMs);
|
|
179
|
+
let result;
|
|
180
|
+
try {
|
|
181
|
+
result = task();
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
finish(() => reject(err));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
Promise.resolve(result).then((value) => finish(() => resolve(value)), (err) => finish(() => reject(err)));
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
finish(() => reject(err));
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
export class PluginRegistry {
|
|
196
|
+
maxPlugins;
|
|
197
|
+
byName = new Map();
|
|
198
|
+
ingestors = new Map();
|
|
199
|
+
oracles = new Map();
|
|
200
|
+
reporters = new Map();
|
|
201
|
+
constructor(options = {}) {
|
|
202
|
+
const maxPlugins = options?.maxPlugins ?? HARD_MAX_LOCAL_PLUGINS;
|
|
203
|
+
if (typeof maxPlugins !== "number" || !Number.isSafeInteger(maxPlugins) || maxPlugins < 1 || maxPlugins > HARD_MAX_LOCAL_PLUGINS) {
|
|
204
|
+
throw new VibecodeError("CONFIG_INVALID", `maxPlugins must be an integer between 1 and ${HARD_MAX_LOCAL_PLUGINS}`);
|
|
205
|
+
}
|
|
206
|
+
this.maxPlugins = maxPlugins;
|
|
207
|
+
}
|
|
208
|
+
targetMapFor(kind) {
|
|
209
|
+
if (kind === "ingestor")
|
|
210
|
+
return this.ingestors;
|
|
211
|
+
if (kind === "oracle")
|
|
212
|
+
return this.oracles;
|
|
213
|
+
return this.reporters;
|
|
214
|
+
}
|
|
215
|
+
register(plugin, options = {}) {
|
|
216
|
+
if (!isPlainObject(plugin))
|
|
217
|
+
throw new VibecodeError("CONFIG_INVALID", "Plugin must be a non-null object");
|
|
218
|
+
const allowOverride = options?.allowOverride === true;
|
|
219
|
+
let rawName;
|
|
220
|
+
let rawVersion;
|
|
221
|
+
let rawTimeoutMs;
|
|
222
|
+
let rawKind;
|
|
223
|
+
try {
|
|
224
|
+
rawName = plugin.name;
|
|
225
|
+
rawVersion = plugin.version;
|
|
226
|
+
rawTimeoutMs = plugin.timeoutMs;
|
|
227
|
+
rawKind = plugin.kind;
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
throw new VibecodeError("CONFIG_INVALID", `Failed to inspect plugin metadata: ${redactSensitiveText(safeToDiagnostic(err).message)}`);
|
|
231
|
+
}
|
|
232
|
+
const name = validateId("plugin name", rawName);
|
|
233
|
+
if (rawVersion !== undefined &&
|
|
234
|
+
(typeof rawVersion !== "string" || !rawVersion.trim() || rawVersion.length > 64 || STRICT_CONTROL_CHARS_RE.test(rawVersion))) {
|
|
235
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin "${name}" has invalid version`);
|
|
236
|
+
}
|
|
237
|
+
if (rawTimeoutMs !== undefined && (typeof rawTimeoutMs !== "number" || !Number.isFinite(rawTimeoutMs) || rawTimeoutMs <= 0)) {
|
|
238
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin "${name}" timeoutMs must be a positive finite number`);
|
|
239
|
+
}
|
|
240
|
+
if (!allowOverride && this.byName.has(name)) {
|
|
241
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin "${name}" is already registered`);
|
|
242
|
+
}
|
|
243
|
+
if (!this.byName.has(name) && this.byName.size >= this.maxPlugins) {
|
|
244
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin registry limit reached (maxPlugins=${this.maxPlugins})`);
|
|
245
|
+
}
|
|
246
|
+
let kind;
|
|
247
|
+
let targets;
|
|
248
|
+
let reserved = null;
|
|
249
|
+
try {
|
|
250
|
+
if (rawKind === "ingestor") {
|
|
251
|
+
kind = "ingestor";
|
|
252
|
+
if (typeof plugin.ingest !== "function") {
|
|
253
|
+
throw new VibecodeError("CONFIG_INVALID", `Ingestor plugin "${name}" must define ingest()`);
|
|
254
|
+
}
|
|
255
|
+
targets = validateTargetList("domains", plugin.domains);
|
|
256
|
+
reserved = RESERVED_CORE_DOMAINS;
|
|
257
|
+
}
|
|
258
|
+
else if (rawKind === "oracle") {
|
|
259
|
+
kind = "oracle";
|
|
260
|
+
if (typeof plugin.verify !== "function") {
|
|
261
|
+
throw new VibecodeError("CONFIG_INVALID", `Oracle plugin "${name}" must define verify()`);
|
|
262
|
+
}
|
|
263
|
+
targets = validateTargetList("invariantTypes", plugin.invariantTypes);
|
|
264
|
+
reserved = RESERVED_CORE_INVARIANT_TYPES;
|
|
265
|
+
}
|
|
266
|
+
else if (rawKind === "reporter") {
|
|
267
|
+
kind = "reporter";
|
|
268
|
+
if (typeof plugin.render !== "function") {
|
|
269
|
+
throw new VibecodeError("CONFIG_INVALID", `Reporter plugin "${name}" must define render()`);
|
|
270
|
+
}
|
|
271
|
+
targets = [validateId("reporter format", plugin.format)];
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin "${name}" has unsupported kind "${redactSensitiveText(safeString(rawKind))}"`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
if (err instanceof VibecodeError)
|
|
279
|
+
throw err;
|
|
280
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin "${name}" failed validation: ${redactSensitiveText(safeToDiagnostic(err).message)}`);
|
|
281
|
+
}
|
|
282
|
+
const targetMap = this.targetMapFor(kind);
|
|
283
|
+
if (!allowOverride) {
|
|
284
|
+
for (const target of targets) {
|
|
285
|
+
if (reserved?.has(target)) {
|
|
286
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin "${name}" cannot override reserved core target "${target}" without allowOverride`);
|
|
287
|
+
}
|
|
288
|
+
const existing = targetMap.get(target);
|
|
289
|
+
if (existing && existing.name !== name) {
|
|
290
|
+
throw new VibecodeError("CONFIG_INVALID", `Target "${target}" is already registered by plugin "${existing.name}"`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (this.byName.has(name))
|
|
295
|
+
this.unregister(name);
|
|
296
|
+
const entry = {
|
|
297
|
+
plugin,
|
|
298
|
+
kind,
|
|
299
|
+
name,
|
|
300
|
+
...(typeof rawVersion === "string" ? { version: rawVersion } : {}),
|
|
301
|
+
...(typeof rawTimeoutMs === "number" ? { timeoutMs: rawTimeoutMs } : {}),
|
|
302
|
+
targets: Object.freeze([...targets])
|
|
303
|
+
};
|
|
304
|
+
this.byName.set(name, entry);
|
|
305
|
+
for (const target of targets)
|
|
306
|
+
targetMap.set(target, entry);
|
|
307
|
+
}
|
|
308
|
+
unregister(name) {
|
|
309
|
+
if (typeof name !== "string" || !name)
|
|
310
|
+
return false;
|
|
311
|
+
const entry = this.byName.get(name);
|
|
312
|
+
if (!entry)
|
|
313
|
+
return false;
|
|
314
|
+
this.byName.delete(name);
|
|
315
|
+
const targetMap = this.targetMapFor(entry.kind);
|
|
316
|
+
for (const target of entry.targets) {
|
|
317
|
+
if (targetMap.get(target) === entry)
|
|
318
|
+
targetMap.delete(target);
|
|
319
|
+
}
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
list() {
|
|
323
|
+
const out = [];
|
|
324
|
+
for (const entry of this.byName.values()) {
|
|
325
|
+
const targetMap = this.targetMapFor(entry.kind);
|
|
326
|
+
out.push({
|
|
327
|
+
kind: entry.kind,
|
|
328
|
+
name: entry.name,
|
|
329
|
+
...(entry.version ? { version: entry.version } : {}),
|
|
330
|
+
targets: entry.targets.filter((t) => targetMap.get(t) === entry)
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
335
|
+
getIngestor(domain) {
|
|
336
|
+
if (typeof domain !== "string" || !domain)
|
|
337
|
+
return null;
|
|
338
|
+
const entry = this.ingestors.get(domain);
|
|
339
|
+
return entry ? entry.plugin : null;
|
|
340
|
+
}
|
|
341
|
+
getOracle(invariantType) {
|
|
342
|
+
if (typeof invariantType !== "string" || !invariantType)
|
|
343
|
+
return null;
|
|
344
|
+
const entry = this.oracles.get(invariantType);
|
|
345
|
+
return entry ? entry.plugin : null;
|
|
346
|
+
}
|
|
347
|
+
getReporter(format) {
|
|
348
|
+
if (typeof format !== "string" || !format)
|
|
349
|
+
return null;
|
|
350
|
+
const entry = this.reporters.get(format);
|
|
351
|
+
return entry ? entry.plugin : null;
|
|
352
|
+
}
|
|
353
|
+
async runOracle(invariant, ctx, deps) {
|
|
354
|
+
const typeKey = typeof invariant?.type === "string" ? invariant.type : "";
|
|
355
|
+
const entry = typeKey ? this.oracles.get(typeKey) : undefined;
|
|
356
|
+
if (!entry)
|
|
357
|
+
return null;
|
|
358
|
+
const plugin = entry.plugin;
|
|
359
|
+
const pluginName = entry.name;
|
|
360
|
+
const inputTimeout = typeof invariant?.input?.timeoutMs === "number" && Number.isFinite(invariant.input.timeoutMs) && invariant.input.timeoutMs > 0
|
|
361
|
+
? invariant.input.timeoutMs
|
|
362
|
+
: undefined;
|
|
363
|
+
const requestedTimeout = typeof entry.timeoutMs === "number" && inputTimeout !== undefined
|
|
364
|
+
? Math.min(entry.timeoutMs, inputTimeout)
|
|
365
|
+
: (entry.timeoutMs ?? inputTimeout);
|
|
366
|
+
try {
|
|
367
|
+
const raw = await runWithPluginTimeout(pluginName, requestedTimeout, () => plugin.verify(invariant, ctx, deps));
|
|
368
|
+
return normalizeOutcome(raw, pluginName);
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
const diag = redactDiagnostic(safeToDiagnostic(err), pluginName);
|
|
372
|
+
return {
|
|
373
|
+
status: "fail",
|
|
374
|
+
score: 0,
|
|
375
|
+
failures: [redactSensitiveText(`Plugin "${pluginName}" failed: ${diag.message}`)],
|
|
376
|
+
reason: diag.message,
|
|
377
|
+
diagnostic: diag,
|
|
378
|
+
metrics: { plugin: pluginName }
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
async runReporter(format, report, options) {
|
|
383
|
+
const entry = typeof format === "string" && format ? this.reporters.get(format) : undefined;
|
|
384
|
+
if (!entry) {
|
|
385
|
+
throw new VibecodeError("UNSUPPORTED_FORMAT", `No reporter plugin registered for format "${redactSensitiveText(safeString(format))}"`);
|
|
386
|
+
}
|
|
387
|
+
const plugin = entry.plugin;
|
|
388
|
+
const pluginName = entry.name;
|
|
389
|
+
let raw;
|
|
390
|
+
try {
|
|
391
|
+
raw = await runWithPluginTimeout(pluginName, entry.timeoutMs, () => plugin.render(report, options));
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
if (err instanceof VibecodeError && err.code === "EXEC_TIMEOUT")
|
|
395
|
+
throw err;
|
|
396
|
+
const diag = redactDiagnostic(safeToDiagnostic(err), pluginName);
|
|
397
|
+
throw new VibecodeError("EXEC_ERROR", redactSensitiveText(`Reporter plugin "${pluginName}" failed: ${diag.message}`), {
|
|
398
|
+
adapter: diag.adapter
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
if (typeof raw !== "string") {
|
|
402
|
+
throw new VibecodeError("EXEC_ERROR", `Reporter plugin "${pluginName}" must return a string`);
|
|
403
|
+
}
|
|
404
|
+
return redactSensitiveText(raw);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function assertConfinedPluginPath(candidate, baseDir, display) {
|
|
408
|
+
if (!isPathWithinDir(candidate, baseDir, { allowEqual: false })) {
|
|
409
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin path escapes workspace: ${display}`);
|
|
410
|
+
}
|
|
411
|
+
if (hasVaultOrHoldoutSegment(candidate) || isInsideVaultDirectory(candidate)) {
|
|
412
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin path cannot reference vault or holdout files: ${display}`);
|
|
413
|
+
}
|
|
414
|
+
const rel = path.relative(baseDir, candidate);
|
|
415
|
+
if (hasUnsafeRelativeSegment(rel)) {
|
|
416
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin path contains unsafe segment: ${display}`);
|
|
417
|
+
}
|
|
418
|
+
if (isSecretRelativePath(rel)) {
|
|
419
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin path cannot target secret files: ${display}`);
|
|
420
|
+
}
|
|
421
|
+
if (!ALLOWED_PLUGIN_EXTS.has(path.extname(candidate).toLowerCase())) {
|
|
422
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin file must have .mjs or .js extension: ${display}`);
|
|
423
|
+
}
|
|
424
|
+
return rel;
|
|
425
|
+
}
|
|
426
|
+
function resolveSafePluginFile(resolvedCwd, realCwd, rawPath) {
|
|
427
|
+
if (typeof rawPath !== "string" || !rawPath.trim()) {
|
|
428
|
+
throw new VibecodeError("CONFIG_INVALID", "Plugin path must be a non-empty string");
|
|
429
|
+
}
|
|
430
|
+
const display = redactSensitiveText(rawPath.trim());
|
|
431
|
+
if (hasCrossPlatformPathEscape(rawPath))
|
|
432
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin path escapes workspace: ${display}`);
|
|
433
|
+
const trimmed = rawPath.trim();
|
|
434
|
+
if (hasVaultOrHoldoutSegment(trimmed))
|
|
435
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin path cannot reference vault or holdout files: ${display}`);
|
|
436
|
+
const resolved = path.resolve(resolvedCwd, trimmed);
|
|
437
|
+
assertConfinedPluginPath(resolved, resolvedCwd, display);
|
|
438
|
+
// Detect dangling symlinks escaping workspace or pointing to vault/secret before existsSync.
|
|
439
|
+
try {
|
|
440
|
+
const lstat = fs.lstatSync(resolved);
|
|
441
|
+
if (lstat.isSymbolicLink()) {
|
|
442
|
+
const linkTarget = path.resolve(path.dirname(resolved), fs.readlinkSync(resolved));
|
|
443
|
+
assertConfinedPluginPath(linkTarget, resolvedCwd, display);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
catch (err) {
|
|
447
|
+
if (err instanceof VibecodeError)
|
|
448
|
+
throw err;
|
|
449
|
+
// ENOENT or inaccessible handled below
|
|
450
|
+
}
|
|
451
|
+
if (!fs.existsSync(resolved))
|
|
452
|
+
throw new VibecodeError("NOT_FOUND", `Plugin file not found: ${display}`);
|
|
453
|
+
let realPath;
|
|
454
|
+
try {
|
|
455
|
+
realPath = fs.realpathSync(resolved);
|
|
456
|
+
}
|
|
457
|
+
catch (err) {
|
|
458
|
+
throw new VibecodeError("CONFIG_INVALID", `Failed to resolve plugin path ${display}: ${redactSensitiveText(safeToDiagnostic(err).message)}`);
|
|
459
|
+
}
|
|
460
|
+
const relPost = assertConfinedPluginPath(realPath, realCwd, display);
|
|
461
|
+
if (!fs.statSync(realPath).isFile())
|
|
462
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin path must be a regular file: ${display}`);
|
|
463
|
+
return { realPath, relPath: relPost.replace(/\\/g, "/") };
|
|
464
|
+
}
|
|
465
|
+
function extractModulePlugins(mod, relPath, remainingBudget) {
|
|
466
|
+
const seen = new Set();
|
|
467
|
+
const out = [];
|
|
468
|
+
const maxRawScan = Math.max(remainingBudget * 4, HARD_MAX_LOCAL_PLUGINS * 2);
|
|
469
|
+
const add = (item) => {
|
|
470
|
+
if (!seen.has(item)) {
|
|
471
|
+
seen.add(item);
|
|
472
|
+
out.push(item);
|
|
473
|
+
if (out.length > remainingBudget) {
|
|
474
|
+
throw new VibecodeError("CONFIG_INVALID", `Loaded plugin count exceeds maxPlugins`);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
if (mod.default !== undefined) {
|
|
479
|
+
if (Array.isArray(mod.default)) {
|
|
480
|
+
if (mod.default.length > maxRawScan) {
|
|
481
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin module "${redactSensitiveText(relPath)}" default export array exceeds maxPlugins`);
|
|
482
|
+
}
|
|
483
|
+
for (const item of mod.default)
|
|
484
|
+
add(item);
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
add(mod.default);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (mod.plugins !== undefined) {
|
|
491
|
+
if (!Array.isArray(mod.plugins)) {
|
|
492
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin module "${redactSensitiveText(relPath)}" named export "plugins" must be an array`);
|
|
493
|
+
}
|
|
494
|
+
if (mod.plugins.length > maxRawScan) {
|
|
495
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin module "${redactSensitiveText(relPath)}" plugins export exceeds maxPlugins`);
|
|
496
|
+
}
|
|
497
|
+
for (const item of mod.plugins)
|
|
498
|
+
add(item);
|
|
499
|
+
}
|
|
500
|
+
if (out.length === 0) {
|
|
501
|
+
throw new VibecodeError("CONFIG_INVALID", `Plugin module "${redactSensitiveText(relPath)}" exported no plugins`);
|
|
502
|
+
}
|
|
503
|
+
return out;
|
|
504
|
+
}
|
|
505
|
+
/** Loads and registers local ESM `.mjs`/`.js` plugins strictly confined to `cwd`. */
|
|
506
|
+
export async function loadLocalPlugins(cwd, pluginPaths, options = {}) {
|
|
507
|
+
if (typeof cwd !== "string" || !cwd.trim() || STRICT_CONTROL_CHARS_RE.test(cwd)) {
|
|
508
|
+
throw new VibecodeError("CONFIG_INVALID", "Workspace cwd must be a non-empty directory path");
|
|
509
|
+
}
|
|
510
|
+
if (!Array.isArray(pluginPaths))
|
|
511
|
+
throw new VibecodeError("CONFIG_INVALID", "pluginPaths must be an array");
|
|
512
|
+
const maxPlugins = options?.maxPlugins ?? DEFAULT_MAX_LOCAL_PLUGINS;
|
|
513
|
+
if (typeof maxPlugins !== "number" || !Number.isSafeInteger(maxPlugins) || maxPlugins < 1 || maxPlugins > HARD_MAX_LOCAL_PLUGINS) {
|
|
514
|
+
throw new VibecodeError("CONFIG_INVALID", `maxPlugins must be an integer between 1 and ${HARD_MAX_LOCAL_PLUGINS}`);
|
|
515
|
+
}
|
|
516
|
+
if (options?.registry !== undefined && !(options.registry instanceof PluginRegistry)) {
|
|
517
|
+
throw new VibecodeError("CONFIG_INVALID", "registry must be a PluginRegistry instance");
|
|
518
|
+
}
|
|
519
|
+
const resolvedCwd = path.resolve(cwd);
|
|
520
|
+
if (!fs.existsSync(resolvedCwd) || !fs.statSync(resolvedCwd).isDirectory()) {
|
|
521
|
+
throw new VibecodeError("NOT_FOUND", `Workspace directory not found: ${redactSensitiveText(cwd)}`);
|
|
522
|
+
}
|
|
523
|
+
const realCwd = fs.realpathSync(resolvedCwd);
|
|
524
|
+
if (pluginPaths.length > maxPlugins) {
|
|
525
|
+
throw new VibecodeError("CONFIG_INVALID", `Refusing to load ${pluginPaths.length} plugin paths (maxPlugins=${maxPlugins})`);
|
|
526
|
+
}
|
|
527
|
+
const registry = options?.registry ?? new PluginRegistry();
|
|
528
|
+
const loaded = [];
|
|
529
|
+
for (const rawPath of pluginPaths) {
|
|
530
|
+
const { realPath, relPath } = resolveSafePluginFile(resolvedCwd, realCwd, rawPath);
|
|
531
|
+
let mod;
|
|
532
|
+
try {
|
|
533
|
+
const fileUrl = pathToFileURL(realPath).href;
|
|
534
|
+
mod = (await runWithPluginTimeout(`load:${relPath}`, DEFAULT_PLUGIN_TIMEOUT_MS, () => import(fileUrl)));
|
|
535
|
+
}
|
|
536
|
+
catch (err) {
|
|
537
|
+
if (err instanceof VibecodeError)
|
|
538
|
+
throw err;
|
|
539
|
+
throw new VibecodeError("EXEC_ERROR", `Failed to load plugin "${redactSensitiveText(relPath)}": ${redactSensitiveText(safeToDiagnostic(err).message)}`);
|
|
540
|
+
}
|
|
541
|
+
const plugins = extractModulePlugins(mod, relPath, maxPlugins - loaded.length);
|
|
542
|
+
if (loaded.length + plugins.length > maxPlugins) {
|
|
543
|
+
throw new VibecodeError("CONFIG_INVALID", `Loaded plugin count exceeds maxPlugins (${maxPlugins})`);
|
|
544
|
+
}
|
|
545
|
+
for (const plugin of plugins) {
|
|
546
|
+
registry.register(plugin, { allowOverride: options?.allowOverride });
|
|
547
|
+
const registered = registry.list();
|
|
548
|
+
const last = registered[registered.length - 1];
|
|
549
|
+
if (last)
|
|
550
|
+
loaded.push(last.name);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return { registry, loaded };
|
|
554
|
+
}
|