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
package/dist/core/store.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import type { ContractV02, ParityReport, WorkspacePaths } from "./types.js";
|
|
1
|
+
import type { ContractV02, Invariant, ParityReport, WorkspacePaths } from "./types.js";
|
|
2
2
|
export declare const CONTRACT_DIR = ".vibecode";
|
|
3
3
|
export declare const CONTRACT_FILE: string;
|
|
4
|
+
export declare const SPEC_FILE: string;
|
|
5
|
+
export declare const HOLDOUTS_FILE: string;
|
|
4
6
|
export declare const LAST_REPORT_FILE: string;
|
|
7
|
+
export declare const REPORT_HTML_FILE: string;
|
|
8
|
+
export declare const HISTORY_FILE: string;
|
|
5
9
|
export declare const ARTIFACTS_DIR: string;
|
|
6
10
|
export declare const CACHE_DIR: string;
|
|
11
|
+
export declare function resolveHoldoutVaultPath(cwd?: string): string;
|
|
7
12
|
export declare function resolveWorkspace(cwd?: string): WorkspacePaths;
|
|
8
13
|
export declare function ensureDir(dir: string): void;
|
|
9
14
|
export declare function readContract(cwd?: string): ContractV02;
|
|
10
15
|
export declare function readRawContract(cwd?: string): unknown;
|
|
11
|
-
export declare function writeContract(contract: unknown, cwd?: string, { force }?: {
|
|
16
|
+
export declare function writeContract(contract: unknown, cwd?: string, { force, preserveHoldouts, replaceHoldouts }?: {
|
|
12
17
|
force?: boolean;
|
|
18
|
+
preserveHoldouts?: boolean;
|
|
19
|
+
replaceHoldouts?: boolean;
|
|
13
20
|
}): string;
|
|
21
|
+
export declare function readHoldouts(cwd?: string): Invariant[];
|
|
22
|
+
export declare function readContractWithHoldouts(cwd?: string): ContractV02;
|
|
14
23
|
export declare function saveArtifact(bufferOrPath: Buffer | Uint8Array | string, relName: string, cwd?: string): string;
|
|
15
24
|
export declare function writeLastReport(report: ParityReport, cwd?: string): string;
|
|
16
25
|
export declare function readLastReport(cwd?: string): ParityReport | null;
|
package/dist/core/store.js
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
1
2
|
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
2
4
|
import path from "node:path";
|
|
3
|
-
import { VibecodeError, errorMessage } from "./errors.js";
|
|
5
|
+
import { VibecodeError, errorCode, errorMessage } from "./errors.js";
|
|
4
6
|
import { normalizeContract, assertValidContract } from "./schema.js";
|
|
5
7
|
export const CONTRACT_DIR = ".vibecode";
|
|
6
8
|
export const CONTRACT_FILE = path.join(CONTRACT_DIR, "contract.json");
|
|
9
|
+
export const SPEC_FILE = path.join(CONTRACT_DIR, "SPEC.md");
|
|
10
|
+
export const HOLDOUTS_FILE = path.join(CONTRACT_DIR, "holdouts.json");
|
|
7
11
|
export const LAST_REPORT_FILE = path.join(CONTRACT_DIR, "last-report.json");
|
|
12
|
+
export const REPORT_HTML_FILE = path.join(CONTRACT_DIR, "report.html");
|
|
13
|
+
export const HISTORY_FILE = path.join(CONTRACT_DIR, "history.json");
|
|
8
14
|
export const ARTIFACTS_DIR = path.join(CONTRACT_DIR, "artifacts");
|
|
9
15
|
export const CACHE_DIR = path.join(CONTRACT_DIR, "cache");
|
|
16
|
+
export function resolveHoldoutVaultPath(cwd = process.cwd()) {
|
|
17
|
+
const resolved = path.resolve(cwd);
|
|
18
|
+
let canonical = resolved;
|
|
19
|
+
if (fs.existsSync(resolved)) {
|
|
20
|
+
try {
|
|
21
|
+
canonical = fs.realpathSync(resolved);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
canonical = resolved;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const keySource = process.platform === "win32" ? canonical.toLowerCase() : canonical;
|
|
28
|
+
const workspaceKey = crypto.createHash("sha256").update(keySource).digest("hex").slice(0, 16);
|
|
29
|
+
const envVault = process.env.VIBECODE_VAULT_DIR?.trim();
|
|
30
|
+
const vaultBase = envVault ? path.resolve(envVault) : path.join(os.homedir(), ".vibecode-vault");
|
|
31
|
+
return path.join(vaultBase, workspaceKey, "holdouts.json");
|
|
32
|
+
}
|
|
10
33
|
export function resolveWorkspace(cwd = process.cwd()) {
|
|
11
34
|
const rootDir = path.resolve(cwd);
|
|
12
35
|
return {
|
|
@@ -14,7 +37,12 @@ export function resolveWorkspace(cwd = process.cwd()) {
|
|
|
14
37
|
contractPath: path.join(rootDir, CONTRACT_FILE),
|
|
15
38
|
reportPath: path.join(rootDir, LAST_REPORT_FILE),
|
|
16
39
|
artifactsDir: path.join(rootDir, ARTIFACTS_DIR),
|
|
17
|
-
cacheDir: path.join(rootDir, CACHE_DIR)
|
|
40
|
+
cacheDir: path.join(rootDir, CACHE_DIR),
|
|
41
|
+
specPath: path.join(rootDir, SPEC_FILE),
|
|
42
|
+
holdoutsPath: resolveHoldoutVaultPath(rootDir),
|
|
43
|
+
legacyHoldoutsPath: path.join(rootDir, HOLDOUTS_FILE),
|
|
44
|
+
reportHtmlPath: path.join(rootDir, REPORT_HTML_FILE),
|
|
45
|
+
historyPath: path.join(rootDir, HISTORY_FILE)
|
|
18
46
|
};
|
|
19
47
|
}
|
|
20
48
|
export function ensureDir(dir) {
|
|
@@ -43,20 +71,112 @@ export function readRawContract(cwd = process.cwd()) {
|
|
|
43
71
|
}
|
|
44
72
|
return JSON.parse(fs.readFileSync(contractPath, "utf8"));
|
|
45
73
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
74
|
+
function parseHoldoutsFile(filePath, label) {
|
|
75
|
+
let text;
|
|
76
|
+
try {
|
|
77
|
+
text = fs.readFileSync(filePath, "utf8");
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
const code = errorCode(err) ?? "READ_ERROR";
|
|
81
|
+
throw new VibecodeError("CONTRACT_INVALID", `Failed to read ${label} (${code}).`);
|
|
82
|
+
}
|
|
83
|
+
let raw;
|
|
84
|
+
try {
|
|
85
|
+
raw = JSON.parse(text);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
throw new VibecodeError("CONTRACT_INVALID", `Failed to parse ${label}: ${errorMessage(err)}`, { details: err });
|
|
89
|
+
}
|
|
90
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw) || !Array.isArray(raw.invariants)) {
|
|
91
|
+
throw new VibecodeError("CONTRACT_INVALID", `${label} must be a JSON object with an invariants array.`);
|
|
92
|
+
}
|
|
93
|
+
const rawInvariants = raw.invariants;
|
|
94
|
+
const synthetic = normalizeContract({
|
|
95
|
+
schemaVersion: "0.2.0",
|
|
96
|
+
target: { name: "holdouts", domains: ["cli"], sources: [] },
|
|
97
|
+
thresholds: { hardBehavioralParity: 1, softPerceptualParity: 0.85 },
|
|
98
|
+
invariants: rawInvariants
|
|
99
|
+
});
|
|
100
|
+
assertValidContract(synthetic);
|
|
101
|
+
return synthetic.invariants.map((inv) => ({ ...inv, holdout: true }));
|
|
102
|
+
}
|
|
103
|
+
function writeHoldoutsFile(holdoutsPath, schemaVersion, invariants) {
|
|
104
|
+
ensureDir(path.dirname(holdoutsPath));
|
|
105
|
+
const holdoutsTmp = holdoutsPath + ".tmp";
|
|
106
|
+
fs.writeFileSync(holdoutsTmp, JSON.stringify({ schemaVersion, invariants }, null, 2) + "\n", "utf8");
|
|
107
|
+
fs.renameSync(holdoutsTmp, holdoutsPath);
|
|
108
|
+
}
|
|
109
|
+
export function writeContract(contract, cwd = process.cwd(), { force = false, preserveHoldouts = false, replaceHoldouts = false } = {}) {
|
|
110
|
+
const initial = resolveWorkspace(cwd);
|
|
111
|
+
if (fs.existsSync(initial.contractPath) && !force) {
|
|
51
112
|
throw new VibecodeError("CONTRACT_INVALID", `Contract already exists at ${CONTRACT_FILE}. Use --force to overwrite.`);
|
|
52
113
|
}
|
|
53
114
|
const normalized = normalizeContract(contract);
|
|
54
115
|
assertValidContract(normalized);
|
|
116
|
+
const contractDir = path.join(initial.rootDir, CONTRACT_DIR);
|
|
117
|
+
ensureDir(contractDir);
|
|
118
|
+
const { contractPath, holdoutsPath, legacyHoldoutsPath } = resolveWorkspace(initial.rootDir);
|
|
119
|
+
const visible = normalized.invariants.filter((inv) => inv.holdout !== true);
|
|
120
|
+
const holdouts = normalized.invariants.filter((inv) => inv.holdout === true);
|
|
121
|
+
const visibleIds = new Set(visible.map((inv) => inv.id));
|
|
122
|
+
const visibleSlices = normalized.slices
|
|
123
|
+
? normalized.slices.map((slice) => ({
|
|
124
|
+
...slice,
|
|
125
|
+
invariantIds: slice.invariantIds.filter((id) => visibleIds.has(id))
|
|
126
|
+
}))
|
|
127
|
+
: undefined;
|
|
128
|
+
const visibleContract = {
|
|
129
|
+
...normalized,
|
|
130
|
+
invariants: visible,
|
|
131
|
+
...(visibleSlices ? { slices: visibleSlices } : {})
|
|
132
|
+
};
|
|
55
133
|
const tmp = contractPath + ".tmp";
|
|
56
|
-
fs.writeFileSync(tmp, JSON.stringify(
|
|
134
|
+
fs.writeFileSync(tmp, JSON.stringify(visibleContract, null, 2) + "\n", "utf8");
|
|
57
135
|
fs.renameSync(tmp, contractPath);
|
|
136
|
+
if (legacyHoldoutsPath && fs.existsSync(legacyHoldoutsPath)) {
|
|
137
|
+
if (holdouts.length === 0 && (!replaceHoldouts || preserveHoldouts) && !fs.existsSync(holdoutsPath)) {
|
|
138
|
+
try {
|
|
139
|
+
const migrated = parseHoldoutsFile(legacyHoldoutsPath, HOLDOUTS_FILE);
|
|
140
|
+
if (migrated.length > 0) {
|
|
141
|
+
writeHoldoutsFile(holdoutsPath, normalized.schemaVersion, migrated);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// Corrupt legacy file: skip migrating invalid payload, still unlink below.
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
fs.rmSync(legacyHoldoutsPath, { force: true });
|
|
149
|
+
}
|
|
150
|
+
if (holdouts.length > 0) {
|
|
151
|
+
writeHoldoutsFile(holdoutsPath, normalized.schemaVersion, holdouts);
|
|
152
|
+
}
|
|
153
|
+
else if (replaceHoldouts && !preserveHoldouts && fs.existsSync(holdoutsPath)) {
|
|
154
|
+
fs.rmSync(holdoutsPath, { force: true });
|
|
155
|
+
}
|
|
58
156
|
return contractPath;
|
|
59
157
|
}
|
|
158
|
+
export function readHoldouts(cwd = process.cwd()) {
|
|
159
|
+
const { holdoutsPath, legacyHoldoutsPath } = resolveWorkspace(cwd);
|
|
160
|
+
if (fs.existsSync(holdoutsPath)) {
|
|
161
|
+
return parseHoldoutsFile(holdoutsPath, "holdout vault");
|
|
162
|
+
}
|
|
163
|
+
if (legacyHoldoutsPath && fs.existsSync(legacyHoldoutsPath)) {
|
|
164
|
+
return parseHoldoutsFile(legacyHoldoutsPath, HOLDOUTS_FILE);
|
|
165
|
+
}
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
export function readContractWithHoldouts(cwd = process.cwd()) {
|
|
169
|
+
const contract = readContract(cwd);
|
|
170
|
+
const holdouts = readHoldouts(cwd);
|
|
171
|
+
if (holdouts.length === 0)
|
|
172
|
+
return contract;
|
|
173
|
+
const seen = new Set(contract.invariants.map((inv) => inv.id));
|
|
174
|
+
const extra = holdouts.filter((inv) => !seen.has(inv.id));
|
|
175
|
+
return {
|
|
176
|
+
...contract,
|
|
177
|
+
invariants: [...contract.invariants, ...extra]
|
|
178
|
+
};
|
|
179
|
+
}
|
|
60
180
|
export function saveArtifact(bufferOrPath, relName, cwd = process.cwd()) {
|
|
61
181
|
const { artifactsDir } = resolveWorkspace(cwd);
|
|
62
182
|
ensureDir(artifactsDir);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-domain target resolution and secret-safe runtime workflow variables.
|
|
3
|
+
*/
|
|
4
|
+
import type { Domain, Invariant } from "./types.js";
|
|
5
|
+
export type TargetMap = Partial<Record<Domain, string>>;
|
|
6
|
+
export declare const MAX_RUNTIME_VARS = 64;
|
|
7
|
+
export declare const MAX_RUNTIME_VAR_VALUE_CHARS = 16384;
|
|
8
|
+
export declare const RUNTIME_VAR_ENV_PREFIX = "VIBECODE_VAR_";
|
|
9
|
+
/** Infer a valid Domain for an invariant from its explicit domain or invariant type. */
|
|
10
|
+
export declare function inferDomainForInvariant(invariant: Partial<Pick<Invariant, "domain" | "type">>): Domain;
|
|
11
|
+
/** Validate a plain object mapping valid domains to non-empty target strings. */
|
|
12
|
+
export declare function validateTargetMapObject(raw: unknown): TargetMap;
|
|
13
|
+
/** Parse repeatable "<domain>=<target>" or JSON object target map entries. */
|
|
14
|
+
export declare function parseTargetMapEntries(rawEntries: readonly string[]): TargetMap;
|
|
15
|
+
/** Resolve the execution target for an invariant using domain-specific overrides or fallback target. */
|
|
16
|
+
export declare function resolveTargetForInvariant(invariant: Partial<Pick<Invariant, "domain" | "type">>, ctx?: {
|
|
17
|
+
target?: string;
|
|
18
|
+
targets?: TargetMap;
|
|
19
|
+
}): string | undefined;
|
|
20
|
+
/** Validate a plain object of runtime workflow variables (for SDK/MCP inputs). */
|
|
21
|
+
export declare function validateRuntimeVarsObject(raw: unknown): Record<string, string>;
|
|
22
|
+
/** Parse runtime workflow variables from optional VIBECODE_VAR_* env and repeatable "KEY=VALUE" entries. */
|
|
23
|
+
export declare function parseRuntimeVarEntries(rawEntries?: readonly string[], env?: Record<string, string | undefined>): Record<string, string>;
|
|
24
|
+
/** Return a new vars object where runtimeVars override contractVars without mutating inputs. */
|
|
25
|
+
export declare function mergeRuntimeVars(contractVars?: Record<string, string>, runtimeVars?: Record<string, string>): Record<string, string>;
|
|
26
|
+
/** Collect unique non-trivial runtime var values (length >= 4) sorted longest-first for scrubbing. */
|
|
27
|
+
export declare function collectRuntimeSecretValues(vars?: Record<string, string>): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Scrub runtime var values (raw & encoded) in O(N) per needle, then apply standard secret/vault redaction.
|
|
30
|
+
* All needles are located in the ORIGINAL text and their spans unioned before any replacement, so a
|
|
31
|
+
* replacement token can never be re-matched (sentinel collisions such as a var equal to "REDACTED") and
|
|
32
|
+
* overlapping/prefix-colliding secrets (e.g. "supersecret" + "supersecret_admin") never leave fragments.
|
|
33
|
+
*/
|
|
34
|
+
export declare function redactRuntimeVars(text: string, vars?: Record<string, string>): string;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-domain target resolution and secret-safe runtime workflow variables.
|
|
3
|
+
*/
|
|
4
|
+
import { VibecodeError } from "./errors.js";
|
|
5
|
+
import { VALID_DOMAINS, defineOwnProp, isForbiddenObjectKey, redactSecretSpans, redactSensitiveText, safeReadPlainObject, stripTerminalEscapes } from "./security.js";
|
|
6
|
+
export const MAX_RUNTIME_VARS = 64;
|
|
7
|
+
export const MAX_RUNTIME_VAR_VALUE_CHARS = 16_384;
|
|
8
|
+
export const RUNTIME_VAR_ENV_PREFIX = "VIBECODE_VAR_";
|
|
9
|
+
const REDACTED_VAR_TOKEN = "[REDACTED_VAR]";
|
|
10
|
+
// C0/DEL/C1 controls, Unicode line separators, and bidi overrides (Trojan Source spoofing of targets in reports).
|
|
11
|
+
// eslint-disable-next-line no-control-regex
|
|
12
|
+
const TARGET_CONTROL_CHARS_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029\u202a-\u202e\u2066-\u2069]/;
|
|
13
|
+
// Runtime var values may be multi-line (PEM keys) but must not carry other C0 controls such as ANSI escapes.
|
|
14
|
+
// eslint-disable-next-line no-control-regex
|
|
15
|
+
const VAR_VALUE_CONTROL_CHARS_RE = /[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]/;
|
|
16
|
+
const RUNTIME_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/;
|
|
17
|
+
const VALID_DOMAIN_LIST = [...VALID_DOMAINS].join(", ");
|
|
18
|
+
const byLengthDesc = (a, b) => b.length - a.length || (a < b ? -1 : a > b ? 1 : 0);
|
|
19
|
+
function configError(message, details) {
|
|
20
|
+
return new VibecodeError("CONFIG_INVALID", message, details !== undefined ? { details } : {});
|
|
21
|
+
}
|
|
22
|
+
/** Read own data properties of a plain object exactly once, rejecting getters and converting hostile Proxy trap errors. */
|
|
23
|
+
function ownDataEntries(raw, notPlainMessage) {
|
|
24
|
+
const res = safeReadPlainObject(raw, "object", {
|
|
25
|
+
forbiddenKeyPolicy: "keep",
|
|
26
|
+
includeNonEnumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (!res.ok) {
|
|
29
|
+
if (res.kind === "accessor") {
|
|
30
|
+
throw configError(`Accessor property ${JSON.stringify(res.key ?? "")} is not allowed; use plain data properties.`, { key: res.key });
|
|
31
|
+
}
|
|
32
|
+
if (res.kind === "proxy_error") {
|
|
33
|
+
throw configError(`${notPlainMessage} (${res.error})`);
|
|
34
|
+
}
|
|
35
|
+
throw configError(notPlainMessage);
|
|
36
|
+
}
|
|
37
|
+
return [...res.entries.entries()];
|
|
38
|
+
}
|
|
39
|
+
/** Own enumerable string data properties (accessors skipped so merge and redaction always see the same values). */
|
|
40
|
+
function stringDataEntries(source) {
|
|
41
|
+
if (!source || typeof source !== "object")
|
|
42
|
+
return [];
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const key of Object.keys(source)) {
|
|
45
|
+
if (isForbiddenObjectKey(key))
|
|
46
|
+
continue;
|
|
47
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
48
|
+
if (desc && "value" in desc && typeof desc.value === "string")
|
|
49
|
+
out.push([key, desc.value]);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function validateDomainKey(key) {
|
|
54
|
+
if (isForbiddenObjectKey(key) || !VALID_DOMAINS.has(key)) {
|
|
55
|
+
throw configError(`Invalid target domain ${JSON.stringify(key)}: expected one of ${VALID_DOMAIN_LIST}.`, { domain: key, validDomains: [...VALID_DOMAINS] });
|
|
56
|
+
}
|
|
57
|
+
return key;
|
|
58
|
+
}
|
|
59
|
+
function validateTargetValue(domain, value) {
|
|
60
|
+
if (typeof value !== "string")
|
|
61
|
+
throw configError(`Invalid target for domain "${domain}": expected a non-empty string.`, { domain });
|
|
62
|
+
if (TARGET_CONTROL_CHARS_RE.test(value))
|
|
63
|
+
throw configError(`Invalid target for domain "${domain}": control characters are not allowed.`, { domain });
|
|
64
|
+
const trimmed = value.trim();
|
|
65
|
+
if (!trimmed)
|
|
66
|
+
throw configError(`Invalid target for domain "${domain}": target must not be empty.`, { domain });
|
|
67
|
+
return trimmed;
|
|
68
|
+
}
|
|
69
|
+
function validateVarName(name, source) {
|
|
70
|
+
if (!name || isForbiddenObjectKey(name) || !RUNTIME_VAR_NAME_RE.test(name)) {
|
|
71
|
+
throw configError(`Invalid runtime variable name ${JSON.stringify(name)} in ${source}: must match /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/.`, { name, source });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function validateVarValue(name, value) {
|
|
75
|
+
if (typeof value !== "string")
|
|
76
|
+
throw configError(`Invalid runtime variable "${name}": value must be a string.`, { name });
|
|
77
|
+
if (value.includes("\0"))
|
|
78
|
+
throw configError(`Invalid runtime variable "${name}": NUL bytes are not allowed.`, { name });
|
|
79
|
+
if (VAR_VALUE_CONTROL_CHARS_RE.test(value))
|
|
80
|
+
throw configError(`Invalid runtime variable "${name}": control characters are not allowed.`, { name });
|
|
81
|
+
if (value.length > MAX_RUNTIME_VAR_VALUE_CHARS) {
|
|
82
|
+
throw configError(`Runtime variable "${name}" exceeds maximum length of ${MAX_RUNTIME_VAR_VALUE_CHARS} characters.`, {
|
|
83
|
+
name,
|
|
84
|
+
maxChars: MAX_RUNTIME_VAR_VALUE_CHARS
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
function setRuntimeVar(out, name, value, state) {
|
|
90
|
+
if (!Object.prototype.hasOwnProperty.call(out, name)) {
|
|
91
|
+
if (state.count >= MAX_RUNTIME_VARS) {
|
|
92
|
+
throw configError(`Too many runtime variables: maximum allowed is ${MAX_RUNTIME_VARS}.`, { maxVars: MAX_RUNTIME_VARS });
|
|
93
|
+
}
|
|
94
|
+
state.count++;
|
|
95
|
+
}
|
|
96
|
+
defineOwnProp(out, name, value);
|
|
97
|
+
}
|
|
98
|
+
/** Infer a valid Domain for an invariant from its explicit domain or invariant type. */
|
|
99
|
+
export function inferDomainForInvariant(invariant) {
|
|
100
|
+
if (typeof invariant?.domain === "string" && VALID_DOMAINS.has(invariant.domain)) {
|
|
101
|
+
return invariant.domain;
|
|
102
|
+
}
|
|
103
|
+
const type = typeof invariant?.type === "string" ? invariant.type.trim() : "";
|
|
104
|
+
if (type === "command")
|
|
105
|
+
return "cli";
|
|
106
|
+
if (type === "http" || type === "http_workflow" || type === "http_stream" || type === "ws_protocol" || type === "perf_budget")
|
|
107
|
+
return "api";
|
|
108
|
+
if (type.startsWith("web_"))
|
|
109
|
+
return "web";
|
|
110
|
+
if (type.startsWith("image_"))
|
|
111
|
+
return "image";
|
|
112
|
+
if (type.startsWith("video_"))
|
|
113
|
+
return "video";
|
|
114
|
+
if (type === "repo_exports")
|
|
115
|
+
return "repo";
|
|
116
|
+
return "cli";
|
|
117
|
+
}
|
|
118
|
+
/** Validate a plain object mapping valid domains to non-empty target strings. */
|
|
119
|
+
export function validateTargetMapObject(raw) {
|
|
120
|
+
const entries = ownDataEntries(raw, "Target map must be a plain object mapping domains to non-empty target strings.");
|
|
121
|
+
const out = {};
|
|
122
|
+
for (const [key, value] of entries) {
|
|
123
|
+
const domain = validateDomainKey(key);
|
|
124
|
+
defineOwnProp(out, domain, validateTargetValue(domain, value));
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
/** Parse repeatable "<domain>=<target>" or JSON object target map entries. */
|
|
129
|
+
export function parseTargetMapEntries(rawEntries) {
|
|
130
|
+
if (!Array.isArray(rawEntries))
|
|
131
|
+
throw configError("Target map entries must be an array of strings.");
|
|
132
|
+
const out = {};
|
|
133
|
+
for (const entry of rawEntries) {
|
|
134
|
+
if (typeof entry !== "string")
|
|
135
|
+
throw configError("Each target map entry must be a string.");
|
|
136
|
+
const trimmed = entry.trim();
|
|
137
|
+
if (!trimmed)
|
|
138
|
+
throw configError("Target map entry must not be empty.");
|
|
139
|
+
if (trimmed.startsWith("{")) {
|
|
140
|
+
let parsed;
|
|
141
|
+
try {
|
|
142
|
+
parsed = JSON.parse(trimmed);
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
throw configError(`Invalid JSON target map entry: ${err instanceof Error ? err.message : String(err)}`);
|
|
146
|
+
}
|
|
147
|
+
const validated = validateTargetMapObject(parsed);
|
|
148
|
+
for (const key of Object.keys(validated)) {
|
|
149
|
+
defineOwnProp(out, key, validated[key]);
|
|
150
|
+
}
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (TARGET_CONTROL_CHARS_RE.test(entry))
|
|
154
|
+
throw configError("Target map entry must not contain control characters.");
|
|
155
|
+
const eqIdx = entry.indexOf("=");
|
|
156
|
+
if (eqIdx === -1)
|
|
157
|
+
throw configError('Invalid target map entry: expected "<domain>=<target>" or a JSON object.');
|
|
158
|
+
const domain = validateDomainKey(entry.slice(0, eqIdx).trim());
|
|
159
|
+
defineOwnProp(out, domain, validateTargetValue(domain, entry.slice(eqIdx + 1)));
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
/** Resolve the execution target for an invariant using domain-specific overrides or fallback target. */
|
|
164
|
+
export function resolveTargetForInvariant(invariant, ctx) {
|
|
165
|
+
if (!ctx)
|
|
166
|
+
return undefined;
|
|
167
|
+
const domain = inferDomainForInvariant(invariant);
|
|
168
|
+
const targets = ctx.targets;
|
|
169
|
+
if (targets && typeof targets === "object" && Object.prototype.hasOwnProperty.call(targets, domain)) {
|
|
170
|
+
const mapped = targets[domain];
|
|
171
|
+
if (typeof mapped === "string" && mapped.trim().length > 0)
|
|
172
|
+
return mapped;
|
|
173
|
+
}
|
|
174
|
+
return typeof ctx.target === "string" && ctx.target.trim().length > 0 ? ctx.target : undefined;
|
|
175
|
+
}
|
|
176
|
+
/** Validate a plain object of runtime workflow variables (for SDK/MCP inputs). */
|
|
177
|
+
export function validateRuntimeVarsObject(raw) {
|
|
178
|
+
const entries = ownDataEntries(raw, "Runtime variables must be a plain object mapping variable names to strings.");
|
|
179
|
+
const out = {};
|
|
180
|
+
const state = { count: 0 };
|
|
181
|
+
for (const [key, value] of entries) {
|
|
182
|
+
validateVarName(key, "vars object");
|
|
183
|
+
setRuntimeVar(out, key, validateVarValue(key, value), state);
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
/** Parse runtime workflow variables from optional VIBECODE_VAR_* env and repeatable "KEY=VALUE" entries. */
|
|
188
|
+
export function parseRuntimeVarEntries(rawEntries, env) {
|
|
189
|
+
const out = {};
|
|
190
|
+
const state = { count: 0 };
|
|
191
|
+
if (env !== undefined) {
|
|
192
|
+
if (env === null || typeof env !== "object" || Array.isArray(env)) {
|
|
193
|
+
throw configError("Environment source for runtime variables must be an object.");
|
|
194
|
+
}
|
|
195
|
+
for (const envKey of Object.keys(env)) {
|
|
196
|
+
if (!envKey.startsWith(RUNTIME_VAR_ENV_PREFIX))
|
|
197
|
+
continue;
|
|
198
|
+
const rawVal = env[envKey];
|
|
199
|
+
if (rawVal === undefined)
|
|
200
|
+
continue;
|
|
201
|
+
const name = envKey.slice(RUNTIME_VAR_ENV_PREFIX.length);
|
|
202
|
+
validateVarName(name, `env ${envKey}`);
|
|
203
|
+
setRuntimeVar(out, name, validateVarValue(name, rawVal), state);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (rawEntries !== undefined) {
|
|
207
|
+
if (!Array.isArray(rawEntries))
|
|
208
|
+
throw configError("Runtime variable entries must be an array of strings.");
|
|
209
|
+
for (const entry of rawEntries) {
|
|
210
|
+
if (typeof entry !== "string")
|
|
211
|
+
throw configError("Each runtime variable entry must be a string.");
|
|
212
|
+
const eqIdx = entry.indexOf("=");
|
|
213
|
+
if (eqIdx === -1)
|
|
214
|
+
throw configError('Invalid runtime variable entry: expected "KEY=VALUE".');
|
|
215
|
+
const name = entry.slice(0, eqIdx);
|
|
216
|
+
validateVarName(name, "entry");
|
|
217
|
+
setRuntimeVar(out, name, validateVarValue(name, entry.slice(eqIdx + 1)), state);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
/** Return a new vars object where runtimeVars override contractVars without mutating inputs. */
|
|
223
|
+
export function mergeRuntimeVars(contractVars, runtimeVars) {
|
|
224
|
+
const out = {};
|
|
225
|
+
for (const source of [contractVars, runtimeVars]) {
|
|
226
|
+
for (const [key, value] of stringDataEntries(source))
|
|
227
|
+
defineOwnProp(out, key, value);
|
|
228
|
+
}
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
/** Collect unique non-trivial runtime var values (length >= 4) sorted longest-first for scrubbing. */
|
|
232
|
+
export function collectRuntimeSecretValues(vars) {
|
|
233
|
+
const unique = new Set();
|
|
234
|
+
for (const [, value] of stringDataEntries(vars)) {
|
|
235
|
+
if (value.length >= 4 && value.trim().length > 0)
|
|
236
|
+
unique.add(value);
|
|
237
|
+
}
|
|
238
|
+
return [...unique].sort(byLengthDesc);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Scrub runtime var values (raw & encoded) in O(N) per needle, then apply standard secret/vault redaction.
|
|
242
|
+
* All needles are located in the ORIGINAL text and their spans unioned before any replacement, so a
|
|
243
|
+
* replacement token can never be re-matched (sentinel collisions such as a var equal to "REDACTED") and
|
|
244
|
+
* overlapping/prefix-colliding secrets (e.g. "supersecret" + "supersecret_admin") never leave fragments.
|
|
245
|
+
*/
|
|
246
|
+
export function redactRuntimeVars(text, vars) {
|
|
247
|
+
const raw = String(text ?? "");
|
|
248
|
+
if (!raw)
|
|
249
|
+
return "";
|
|
250
|
+
const baseValues = collectRuntimeSecretValues(vars);
|
|
251
|
+
if (baseValues.length === 0)
|
|
252
|
+
return redactSensitiveText(raw);
|
|
253
|
+
// If any var value itself contains stripped control/escape chars, match raw spans first so
|
|
254
|
+
// control-char values are explicitly marked [REDACTED_VAR] before terminal-escape stripping
|
|
255
|
+
// reassembles ANSI-split secrets for the main pass.
|
|
256
|
+
const hasControlVar = baseValues.some((v) => stripTerminalEscapes(v) !== v);
|
|
257
|
+
const preScrubbed = hasControlVar ? redactSecretSpans(raw, baseValues, REDACTED_VAR_TOKEN) : raw;
|
|
258
|
+
const cleaned = stripTerminalEscapes(preScrubbed);
|
|
259
|
+
if (!cleaned)
|
|
260
|
+
return "";
|
|
261
|
+
return redactSensitiveText(redactSecretSpans(cleaned, baseValues, REDACTED_VAR_TOKEN));
|
|
262
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ContractV02 } from "./types.js";
|
|
2
|
+
export type TestExportFormat = "node-test" | "vitest" | "pytest" | "shell" | "playwright";
|
|
3
|
+
export interface ExportTestsOptions {
|
|
4
|
+
format?: TestExportFormat;
|
|
5
|
+
target?: string;
|
|
6
|
+
contractPath?: string;
|
|
7
|
+
includeSkippedComments?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ExportTestsResult {
|
|
10
|
+
format: TestExportFormat;
|
|
11
|
+
suggestedFilename: string;
|
|
12
|
+
code: string;
|
|
13
|
+
exportedCount: number;
|
|
14
|
+
skippedCount: number;
|
|
15
|
+
skippedIds: string[];
|
|
16
|
+
excludedHoldoutCount: number;
|
|
17
|
+
}
|
|
18
|
+
export interface WriteExportedTestsOptions extends ExportTestsOptions {
|
|
19
|
+
outPath: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WriteExportedTestsResult extends ExportTestsResult {
|
|
22
|
+
outPath: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function exportContractTests(contract: ContractV02, options?: ExportTestsOptions): ExportTestsResult;
|
|
25
|
+
export declare function writeExportedTests(contract: ContractV02, options: WriteExportedTestsOptions): WriteExportedTestsResult;
|