dvalincode 0.17.0 → 0.18.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 +202 -46
- package/README.zh-CN.md +170 -39
- package/THIRD_PARTY_NOTICES.md +98 -43
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/dvalin.d.ts +9 -1
- package/dist/commands/dvalin.js +177 -37
- package/dist/commands/dvalin.js.map +1 -1
- package/dist/commands/mcpInstall.d.ts +2 -0
- package/dist/commands/mcpInstall.js +69 -0
- package/dist/commands/mcpInstall.js.map +1 -0
- package/dist/commands/security.d.ts +47 -0
- package/dist/commands/security.js +415 -0
- package/dist/commands/security.js.map +1 -0
- package/dist/dvalinCli.d.ts +3 -0
- package/dist/dvalinCli.js +36 -0
- package/dist/dvalinCli.js.map +1 -0
- package/dist/dvalinIndex.d.ts +2 -0
- package/dist/dvalinIndex.js +9 -0
- package/dist/dvalinIndex.js.map +1 -0
- package/dist/evidence/pack.d.ts +8 -0
- package/dist/evidence/pack.js +16 -0
- package/dist/evidence/pack.js.map +1 -1
- package/dist/mcp/install.d.ts +48 -0
- package/dist/mcp/install.js +74 -0
- package/dist/mcp/install.js.map +1 -0
- package/dist/mcp/server.d.ts +10 -1
- package/dist/mcp/server.js +215 -14
- package/dist/mcp/server.js.map +1 -1
- package/dist/remediation/automate.d.ts +4 -1
- package/dist/remediation/automate.js +35 -18
- package/dist/remediation/automate.js.map +1 -1
- package/dist/remediation/diffScope.d.ts +29 -0
- package/dist/remediation/diffScope.js +107 -0
- package/dist/remediation/diffScope.js.map +1 -0
- package/dist/remediation/executor.d.ts +60 -0
- package/dist/remediation/executor.js +144 -0
- package/dist/remediation/executor.js.map +1 -0
- package/dist/remediation/localScan.d.ts +2 -1
- package/dist/remediation/localScan.js +73 -3
- package/dist/remediation/localScan.js.map +1 -1
- package/dist/remediation/sarif.d.ts +6 -0
- package/dist/remediation/sarif.js +36 -14
- package/dist/remediation/sarif.js.map +1 -1
- package/dist/remediation/scannerSuite.d.ts +21 -0
- package/dist/remediation/scannerSuite.js +65 -4
- package/dist/remediation/scannerSuite.js.map +1 -1
- package/dist/remediation/verify.d.ts +38 -0
- package/dist/remediation/verify.js +116 -0
- package/dist/remediation/verify.js.map +1 -0
- package/dist/security/baseline.d.ts +7 -0
- package/dist/security/baseline.js +26 -0
- package/dist/security/baseline.js.map +1 -0
- package/dist/security/config.d.ts +32 -0
- package/dist/security/config.js +131 -0
- package/dist/security/config.js.map +1 -0
- package/dist/security/contracts.d.ts +149 -0
- package/dist/security/contracts.js +231 -0
- package/dist/security/contracts.js.map +1 -0
- package/dist/security/fixRecord.d.ts +125 -0
- package/dist/security/fixRecord.js +169 -0
- package/dist/security/fixRecord.js.map +1 -0
- package/dist/security/fixRecordFile.d.ts +8 -0
- package/dist/security/fixRecordFile.js +37 -0
- package/dist/security/fixRecordFile.js.map +1 -0
- package/dist/security/fixRecordStore.d.ts +23 -0
- package/dist/security/fixRecordStore.js +74 -0
- package/dist/security/fixRecordStore.js.map +1 -0
- package/dist/security/render.d.ts +8 -0
- package/dist/security/render.js +20 -0
- package/dist/security/render.js.map +1 -0
- package/dist/security/suppressions.d.ts +12 -0
- package/dist/security/suppressions.js +60 -0
- package/dist/security/suppressions.js.map +1 -0
- package/dist/security/verifyRun.d.ts +21 -0
- package/dist/security/verifyRun.js +74 -0
- package/dist/security/verifyRun.js.map +1 -0
- package/dist/security/workflow.d.ts +98 -0
- package/dist/security/workflow.js +263 -0
- package/dist/security/workflow.js.map +1 -0
- package/dist/server/routes/remediation.d.ts +19 -0
- package/dist/server/routes/remediation.js +90 -18
- package/dist/server/routes/remediation.js.map +1 -1
- package/dist/tools/runCheck.d.ts +6 -0
- package/dist/tools/runCheck.js +1 -1
- package/dist/tools/runCheck.js.map +1 -1
- package/dist/tools/runSecuritySuite.d.ts +3 -0
- package/dist/tools/runSecuritySuite.js +18 -11
- package/dist/tools/runSecuritySuite.js.map +1 -1
- package/dist/tui/app.js +21 -2
- package/dist/tui/app.js.map +1 -1
- package/dist/tui/render.js +2 -0
- package/dist/tui/render.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +17 -10
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { access, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { UsageError } from '../core/exitCodes.js';
|
|
5
|
+
export const SECURITY_CONFIG_FILE = 'dvalin.security.json';
|
|
6
|
+
export const DEFAULT_BASELINE_FILE = '.dvalin/baseline.json';
|
|
7
|
+
export const DEFAULT_SECURITY_CONFIG = {
|
|
8
|
+
version: 1,
|
|
9
|
+
scanners: ['builtin'],
|
|
10
|
+
gate: { severity: 'none', mode: 'all' },
|
|
11
|
+
baseline: DEFAULT_BASELINE_FILE,
|
|
12
|
+
checks: ['test'],
|
|
13
|
+
suppressions: [],
|
|
14
|
+
};
|
|
15
|
+
export const INITIALIZED_SECURITY_CONFIG = {
|
|
16
|
+
...DEFAULT_SECURITY_CONFIG,
|
|
17
|
+
gate: { severity: 'high', mode: 'new' },
|
|
18
|
+
};
|
|
19
|
+
export async function loadSecurityConfig(root, explicitPath) {
|
|
20
|
+
const candidate = explicitPath ? path.resolve(root, explicitPath) : path.join(root, SECURITY_CONFIG_FILE);
|
|
21
|
+
try {
|
|
22
|
+
await access(candidate, constants.R_OK);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
if (explicitPath)
|
|
26
|
+
throw new UsageError(`Security config not found: ${candidate}`);
|
|
27
|
+
return { config: structuredClone(DEFAULT_SECURITY_CONFIG) };
|
|
28
|
+
}
|
|
29
|
+
let parsed;
|
|
30
|
+
try {
|
|
31
|
+
parsed = JSON.parse(await readFile(candidate, 'utf8'));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new UsageError(`Invalid security config ${candidate}: ${error instanceof Error ? error.message : String(error)}`);
|
|
35
|
+
}
|
|
36
|
+
return { config: parseSecurityConfig(parsed, candidate), path: candidate };
|
|
37
|
+
}
|
|
38
|
+
export async function writeInitialSecurityConfig(root, force = false) {
|
|
39
|
+
const target = path.join(root, SECURITY_CONFIG_FILE);
|
|
40
|
+
if (!force) {
|
|
41
|
+
try {
|
|
42
|
+
await access(target, constants.F_OK);
|
|
43
|
+
throw new UsageError(`${SECURITY_CONFIG_FILE} already exists. Use --force to replace it.`);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof UsageError)
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
await writeFile(target, `${JSON.stringify(INITIALIZED_SECURITY_CONFIG, null, 2)}\n`, 'utf8');
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
export function parseSecurityConfig(value, source = SECURITY_CONFIG_FILE) {
|
|
54
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
55
|
+
throw new UsageError(`${source} must contain a JSON object.`);
|
|
56
|
+
const input = value;
|
|
57
|
+
if (input.version !== 1)
|
|
58
|
+
throw new UsageError(`${source}: version must be 1.`);
|
|
59
|
+
const scanners = parseScanners(input.scanners, source);
|
|
60
|
+
const gateInput = asRecord(input.gate);
|
|
61
|
+
const severity = gateInput?.severity ?? DEFAULT_SECURITY_CONFIG.gate.severity;
|
|
62
|
+
const mode = gateInput?.mode ?? DEFAULT_SECURITY_CONFIG.gate.mode;
|
|
63
|
+
if (!['critical', 'high', 'medium', 'low', 'none'].includes(String(severity))) {
|
|
64
|
+
throw new UsageError(`${source}: gate.severity must be critical, high, medium, low, or none.`);
|
|
65
|
+
}
|
|
66
|
+
if (mode !== 'all' && mode !== 'new')
|
|
67
|
+
throw new UsageError(`${source}: gate.mode must be all or new.`);
|
|
68
|
+
const baseline = input.baseline ?? DEFAULT_SECURITY_CONFIG.baseline;
|
|
69
|
+
if (typeof baseline !== 'string' || !baseline.trim())
|
|
70
|
+
throw new UsageError(`${source}: baseline must be a path string.`);
|
|
71
|
+
const checks = input.checks ?? DEFAULT_SECURITY_CONFIG.checks;
|
|
72
|
+
if (!Array.isArray(checks) || checks.some(check => !['test', 'typecheck', 'build', 'lint'].includes(String(check)))) {
|
|
73
|
+
throw new UsageError(`${source}: checks must contain only test, typecheck, build, or lint.`);
|
|
74
|
+
}
|
|
75
|
+
const suppressions = input.suppressions ?? [];
|
|
76
|
+
if (!Array.isArray(suppressions))
|
|
77
|
+
throw new UsageError(`${source}: suppressions must be an array.`);
|
|
78
|
+
return {
|
|
79
|
+
version: 1,
|
|
80
|
+
scanners,
|
|
81
|
+
gate: { severity: severity, mode },
|
|
82
|
+
baseline,
|
|
83
|
+
checks: [...new Set(checks)],
|
|
84
|
+
suppressions: suppressions.map((suppression, index) => parseSuppression(suppression, `${source}: suppressions[${index}]`)),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export function resolveSecurityPath(root, candidate) {
|
|
88
|
+
const resolvedRoot = path.resolve(root);
|
|
89
|
+
const resolved = path.resolve(resolvedRoot, candidate);
|
|
90
|
+
const relative = path.relative(resolvedRoot, resolved);
|
|
91
|
+
if (relative.startsWith('..' + path.sep) || relative === '..' || path.isAbsolute(relative)) {
|
|
92
|
+
throw new UsageError(`Security artifact path must stay inside the workspace: ${candidate}`);
|
|
93
|
+
}
|
|
94
|
+
return resolved;
|
|
95
|
+
}
|
|
96
|
+
function parseScanners(value, source) {
|
|
97
|
+
const scanners = value ?? DEFAULT_SECURITY_CONFIG.scanners;
|
|
98
|
+
const allowed = ['builtin', 'semgrep', 'trivy', 'osv-scanner'];
|
|
99
|
+
if (!Array.isArray(scanners) || !scanners.length || scanners.some(scanner => !allowed.includes(scanner))) {
|
|
100
|
+
throw new UsageError(`${source}: scanners must contain one or more of ${allowed.join(', ')}.`);
|
|
101
|
+
}
|
|
102
|
+
return [...new Set(scanners)];
|
|
103
|
+
}
|
|
104
|
+
function parseSuppression(value, source) {
|
|
105
|
+
const input = asRecord(value);
|
|
106
|
+
if (!input)
|
|
107
|
+
throw new UsageError(`${source} must be an object.`);
|
|
108
|
+
if (typeof input.reason !== 'string' || !input.reason.trim())
|
|
109
|
+
throw new UsageError(`${source}.reason is required.`);
|
|
110
|
+
if (!input.fingerprint && !input.ruleId)
|
|
111
|
+
throw new UsageError(`${source} needs fingerprint or ruleId.`);
|
|
112
|
+
for (const field of ['fingerprint', 'ruleId', 'path', 'owner', 'expiresAt']) {
|
|
113
|
+
if (input[field] !== undefined && typeof input[field] !== 'string')
|
|
114
|
+
throw new UsageError(`${source}.${field} must be a string.`);
|
|
115
|
+
}
|
|
116
|
+
if (typeof input.expiresAt === 'string' && !Number.isFinite(Date.parse(input.expiresAt))) {
|
|
117
|
+
throw new UsageError(`${source}.expiresAt must be an ISO date.`);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
fingerprint: input.fingerprint,
|
|
121
|
+
ruleId: input.ruleId,
|
|
122
|
+
path: input.path,
|
|
123
|
+
reason: input.reason,
|
|
124
|
+
owner: input.owner,
|
|
125
|
+
expiresAt: input.expiresAt,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function asRecord(value) {
|
|
129
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/security/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAC3D,MAAM,CAAC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IACnI,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;QACzF,MAAM,IAAI,UAAU,CAAC,GAAG,MAAM,iCAAiC,CAAC,CAAC;IACnE,CAAC;IACD,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,WAAiC;QACpD,MAAM,EAAE,KAAK,CAAC,MAA4B;QAC1C,IAAI,EAAE,KAAK,CAAC,IAA0B;QACtC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAA2B;QACxC,SAAS,EAAE,KAAK,CAAC,SAA+B;KACjD,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAgC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/G,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { RemediationFinding } from '../remediation/sarif.js';
|
|
2
|
+
import type { DvalinScannerId, DvalinScannerRun, DvalinScanSuiteResult } from '../remediation/scannerSuite.js';
|
|
3
|
+
export declare const SECURITY_SCHEMA_VERSION: 2;
|
|
4
|
+
/**
|
|
5
|
+
* Versions this build can *read*. Writers always emit the current version.
|
|
6
|
+
*
|
|
7
|
+
* A baseline is committed to the user's repository, so raising the version
|
|
8
|
+
* without accepting the previous one would break every repository that already
|
|
9
|
+
* has one on the first upgrade. Records written before coverage existed load
|
|
10
|
+
* fine and simply report `unknown` coverage — which is the honest answer for a
|
|
11
|
+
* scan that never recorded what it looked at.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SUPPORTED_SECURITY_SCHEMA_VERSIONS: readonly number[];
|
|
14
|
+
export declare const SECURITY_SEVERITIES: readonly ['critical', 'high', 'medium', 'low'];
|
|
15
|
+
export type SecuritySeverity = typeof SECURITY_SEVERITIES[number];
|
|
16
|
+
export type SecurityThreshold = SecuritySeverity | 'none';
|
|
17
|
+
export type SecurityGateMode = 'all' | 'new';
|
|
18
|
+
export type SecurityFindingSnapshot = {
|
|
19
|
+
fingerprint: string;
|
|
20
|
+
targetFingerprint: string;
|
|
21
|
+
findingId: string;
|
|
22
|
+
source: string;
|
|
23
|
+
/**
|
|
24
|
+
* Which engine produced this finding. Absent on records written before the
|
|
25
|
+
* field existed, and on imported SARIF from a tool outside the fleet; the
|
|
26
|
+
* delta falls back to matching `source` by name and, failing that, treats the
|
|
27
|
+
* finding's coverage as unattributable.
|
|
28
|
+
*/
|
|
29
|
+
scanner?: DvalinScannerId;
|
|
30
|
+
ruleId: string;
|
|
31
|
+
ruleName?: string;
|
|
32
|
+
severity: RemediationFinding['severity'];
|
|
33
|
+
securitySeverity?: string;
|
|
34
|
+
message: string;
|
|
35
|
+
path: string;
|
|
36
|
+
startLine?: number;
|
|
37
|
+
endLine?: number;
|
|
38
|
+
helpUri?: string;
|
|
39
|
+
tags: string[];
|
|
40
|
+
};
|
|
41
|
+
export type SecurityBaseline = {
|
|
42
|
+
schemaVersion: typeof SECURITY_SCHEMA_VERSION;
|
|
43
|
+
kind: 'dvalin-security-baseline';
|
|
44
|
+
createdAt: string;
|
|
45
|
+
scanId: string;
|
|
46
|
+
scanners: DvalinScannerId[];
|
|
47
|
+
/** Absent on baselines written before coverage was recorded. */
|
|
48
|
+
coverage?: SecurityCoverage;
|
|
49
|
+
findings: SecurityFindingSnapshot[];
|
|
50
|
+
};
|
|
51
|
+
export declare const SECURITY_COVERAGE_STATUSES: readonly ['complete', 'partial', 'unknown'];
|
|
52
|
+
export type SecurityCoverageStatus = typeof SECURITY_COVERAGE_STATUSES[number];
|
|
53
|
+
/**
|
|
54
|
+
* What the scan actually looked at.
|
|
55
|
+
*
|
|
56
|
+
* A gate result means nothing without it: "no findings" from a run where
|
|
57
|
+
* Semgrep was not installed and half the results were dropped is not the same
|
|
58
|
+
* answer as "no findings" from a complete run, and reporting them identically
|
|
59
|
+
* is the way a number stops meaning anything.
|
|
60
|
+
*/
|
|
61
|
+
export type SecurityCoverage = {
|
|
62
|
+
status: SecurityCoverageStatus;
|
|
63
|
+
/** Per-engine outcome for the engines this scan selected. */
|
|
64
|
+
scanners: Array<{
|
|
65
|
+
id: DvalinScannerId;
|
|
66
|
+
status: DvalinScannerRun['status'];
|
|
67
|
+
}>;
|
|
68
|
+
/** Deliberately not looked at: suppressions, ignore rules, policy denials. */
|
|
69
|
+
exclusions: string[];
|
|
70
|
+
/** Not fully examined, though nothing chose to skip it. */
|
|
71
|
+
deferred: string[];
|
|
72
|
+
notes: string[];
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* How each finding moved since the baseline.
|
|
76
|
+
*
|
|
77
|
+
* `unknown` exists because the alternative is a lie: a baseline finding absent
|
|
78
|
+
* from a run whose engine never executed has not been resolved, it has not been
|
|
79
|
+
* looked for. Before this field, such findings were reported as `resolved`.
|
|
80
|
+
*/
|
|
81
|
+
export type SecurityFindingDelta = {
|
|
82
|
+
new: SecurityFindingSnapshot[];
|
|
83
|
+
existing: SecurityFindingSnapshot[];
|
|
84
|
+
resolved: SecurityFindingSnapshot[];
|
|
85
|
+
/** Gone from the baseline by fingerprint, but the same rule is back in the same file. */
|
|
86
|
+
reopened: SecurityFindingSnapshot[];
|
|
87
|
+
/** Removed by an active suppression, with a recorded reason. */
|
|
88
|
+
dismissed: SecurityFindingSnapshot[];
|
|
89
|
+
/** Cannot be judged: the engine that would have found it did not complete. */
|
|
90
|
+
unknown: SecurityFindingSnapshot[];
|
|
91
|
+
};
|
|
92
|
+
export type SecurityGateResult = {
|
|
93
|
+
passed: boolean;
|
|
94
|
+
mode: SecurityGateMode;
|
|
95
|
+
threshold: SecurityThreshold;
|
|
96
|
+
considered: number;
|
|
97
|
+
blocking: SecurityFindingSnapshot[];
|
|
98
|
+
};
|
|
99
|
+
export type SecurityScanEnvelope = {
|
|
100
|
+
schemaVersion: typeof SECURITY_SCHEMA_VERSION;
|
|
101
|
+
scan: DvalinScanSuiteResult;
|
|
102
|
+
coverage: SecurityCoverage;
|
|
103
|
+
delta?: SecurityFindingDelta;
|
|
104
|
+
gate: SecurityGateResult;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Stable identity for a workspace, shared by the workflow, the fix record, and
|
|
108
|
+
* the Evidence Pack so all three agree on which project a record belongs to.
|
|
109
|
+
*/
|
|
110
|
+
export declare function securityProjectId(root: string): string;
|
|
111
|
+
export declare function severityOfFinding(finding: Pick<RemediationFinding, 'severity' | 'securitySeverity'>): SecuritySeverity;
|
|
112
|
+
export declare function findingFingerprint(finding: Pick<RemediationFinding, 'id' | 'source' | 'ruleId' | 'path' | 'startLine' | 'message'>): string;
|
|
113
|
+
/** A conservative verification key: a moved instance of the same rule in the same file still remains a target. */
|
|
114
|
+
export declare function findingTargetFingerprint(finding: Pick<RemediationFinding, 'source' | 'ruleId' | 'path'>): string;
|
|
115
|
+
/**
|
|
116
|
+
* Best-effort engine attribution for a finding.
|
|
117
|
+
*
|
|
118
|
+
* The suite tags its own findings at scan time; this name match is the fallback
|
|
119
|
+
* for records written before that tag existed. When neither resolves, the
|
|
120
|
+
* caller must treat the finding as unattributable rather than guessing.
|
|
121
|
+
*/
|
|
122
|
+
export declare function scannerIdForSource(source: string): DvalinScannerId | undefined;
|
|
123
|
+
export declare function snapshotFinding(finding: RemediationFinding): SecurityFindingSnapshot;
|
|
124
|
+
/**
|
|
125
|
+
* Describe what a completed scan actually covered, from facts the suite already
|
|
126
|
+
* recorded. Nothing here re-scans or estimates.
|
|
127
|
+
*/
|
|
128
|
+
export declare function deriveCoverage(result: DvalinScanSuiteResult, options?: {
|
|
129
|
+
suppressed?: Array<{
|
|
130
|
+
finding: Pick<RemediationFinding, 'path' | 'ruleId'>;
|
|
131
|
+
}>;
|
|
132
|
+
}): SecurityCoverage;
|
|
133
|
+
/** Coverage for a record that never captured any — genuinely not knowable after the fact. */
|
|
134
|
+
export declare function unknownCoverage(note: string): SecurityCoverage;
|
|
135
|
+
export declare function createBaseline(result: DvalinScanSuiteResult): SecurityBaseline;
|
|
136
|
+
export declare function compareWithBaseline(result: DvalinScanSuiteResult, baseline: SecurityBaseline, options?: {
|
|
137
|
+
suppressed?: Array<{
|
|
138
|
+
finding: RemediationFinding;
|
|
139
|
+
}>;
|
|
140
|
+
}): SecurityFindingDelta;
|
|
141
|
+
export declare function evaluateSecurityGate(input: {
|
|
142
|
+
result: DvalinScanSuiteResult;
|
|
143
|
+
threshold: SecurityThreshold;
|
|
144
|
+
mode: SecurityGateMode;
|
|
145
|
+
delta?: SecurityFindingDelta;
|
|
146
|
+
}): SecurityGateResult;
|
|
147
|
+
/** True for any schema version this build can read, not only the one it writes. */
|
|
148
|
+
export declare function isSupportedSecuritySchemaVersion(value: unknown): boolean;
|
|
149
|
+
export declare function isSecurityBaseline(value: unknown): value is SecurityBaseline;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export const SECURITY_SCHEMA_VERSION = 2;
|
|
4
|
+
/**
|
|
5
|
+
* Versions this build can *read*. Writers always emit the current version.
|
|
6
|
+
*
|
|
7
|
+
* A baseline is committed to the user's repository, so raising the version
|
|
8
|
+
* without accepting the previous one would break every repository that already
|
|
9
|
+
* has one on the first upgrade. Records written before coverage existed load
|
|
10
|
+
* fine and simply report `unknown` coverage — which is the honest answer for a
|
|
11
|
+
* scan that never recorded what it looked at.
|
|
12
|
+
*/
|
|
13
|
+
export const SUPPORTED_SECURITY_SCHEMA_VERSIONS = [1, 2];
|
|
14
|
+
export const SECURITY_SEVERITIES = ['critical', 'high', 'medium', 'low'];
|
|
15
|
+
export const SECURITY_COVERAGE_STATUSES = ['complete', 'partial', 'unknown'];
|
|
16
|
+
/**
|
|
17
|
+
* Stable identity for a workspace, shared by the workflow, the fix record, and
|
|
18
|
+
* the Evidence Pack so all three agree on which project a record belongs to.
|
|
19
|
+
*/
|
|
20
|
+
export function securityProjectId(root) {
|
|
21
|
+
return createHash('sha256').update(path.resolve(root)).digest('hex').slice(0, 16);
|
|
22
|
+
}
|
|
23
|
+
export function severityOfFinding(finding) {
|
|
24
|
+
const score = Number.parseFloat(finding.securitySeverity ?? '');
|
|
25
|
+
if (score >= 9)
|
|
26
|
+
return 'critical';
|
|
27
|
+
if (finding.severity === 'error' || score >= 7)
|
|
28
|
+
return 'high';
|
|
29
|
+
if (finding.severity === 'warning' || score >= 4)
|
|
30
|
+
return 'medium';
|
|
31
|
+
return 'low';
|
|
32
|
+
}
|
|
33
|
+
export function findingFingerprint(finding) {
|
|
34
|
+
return digest([
|
|
35
|
+
finding.source,
|
|
36
|
+
finding.id,
|
|
37
|
+
finding.ruleId,
|
|
38
|
+
normalizePath(finding.path),
|
|
39
|
+
String(finding.startLine ?? 0),
|
|
40
|
+
finding.message.trim().replace(/\s+/g, ' '),
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
/** A conservative verification key: a moved instance of the same rule in the same file still remains a target. */
|
|
44
|
+
export function findingTargetFingerprint(finding) {
|
|
45
|
+
return digest([finding.source, finding.ruleId, normalizePath(finding.path)]);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Best-effort engine attribution for a finding.
|
|
49
|
+
*
|
|
50
|
+
* The suite tags its own findings at scan time; this name match is the fallback
|
|
51
|
+
* for records written before that tag existed. When neither resolves, the
|
|
52
|
+
* caller must treat the finding as unattributable rather than guessing.
|
|
53
|
+
*/
|
|
54
|
+
export function scannerIdForSource(source) {
|
|
55
|
+
const name = source.toLowerCase();
|
|
56
|
+
if (name.includes('dvalin'))
|
|
57
|
+
return 'builtin';
|
|
58
|
+
if (name.includes('semgrep'))
|
|
59
|
+
return 'semgrep';
|
|
60
|
+
if (name.includes('trivy'))
|
|
61
|
+
return 'trivy';
|
|
62
|
+
if (name.includes('osv'))
|
|
63
|
+
return 'osv-scanner';
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
export function snapshotFinding(finding) {
|
|
67
|
+
const scanner = finding.scanner ?? scannerIdForSource(finding.source);
|
|
68
|
+
return {
|
|
69
|
+
fingerprint: findingFingerprint(finding),
|
|
70
|
+
targetFingerprint: findingTargetFingerprint(finding),
|
|
71
|
+
findingId: finding.id,
|
|
72
|
+
source: finding.source,
|
|
73
|
+
...(scanner ? { scanner } : {}),
|
|
74
|
+
ruleId: finding.ruleId,
|
|
75
|
+
ruleName: finding.ruleName,
|
|
76
|
+
severity: finding.severity,
|
|
77
|
+
securitySeverity: finding.securitySeverity,
|
|
78
|
+
message: finding.message,
|
|
79
|
+
path: normalizePath(finding.path),
|
|
80
|
+
startLine: finding.startLine,
|
|
81
|
+
endLine: finding.endLine,
|
|
82
|
+
helpUri: finding.helpUri,
|
|
83
|
+
tags: [...finding.tags],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Describe what a completed scan actually covered, from facts the suite already
|
|
88
|
+
* recorded. Nothing here re-scans or estimates.
|
|
89
|
+
*/
|
|
90
|
+
export function deriveCoverage(result, options = {}) {
|
|
91
|
+
const scanners = result.scanners.map(scanner => ({ id: scanner.id, status: scanner.status }));
|
|
92
|
+
const exclusions = [];
|
|
93
|
+
const deferred = [];
|
|
94
|
+
const notes = [];
|
|
95
|
+
const incomplete = result.scanners.filter(scanner => scanner.status !== 'completed');
|
|
96
|
+
for (const scanner of incomplete) {
|
|
97
|
+
deferred.push(`${scanner.name}: ${scanner.status}${scanner.error ? ` — ${scanner.error}` : ''}`);
|
|
98
|
+
}
|
|
99
|
+
if (result.skippedResults > 0) {
|
|
100
|
+
deferred.push(`${result.skippedResults} scanner result(s) dropped for lacking a safe workspace location`);
|
|
101
|
+
}
|
|
102
|
+
if (result.scope) {
|
|
103
|
+
// A scoped run answers "did this change introduce anything?". It has never
|
|
104
|
+
// seen the rest of the repository and must not imply that it has.
|
|
105
|
+
deferred.push(`scoped to ${result.scope.ref} (${result.scope.files} file(s)); the rest of the workspace was not scanned`);
|
|
106
|
+
}
|
|
107
|
+
const suppressed = options.suppressed ?? [];
|
|
108
|
+
for (const entry of suppressed) {
|
|
109
|
+
exclusions.push(`${entry.finding.ruleId} in ${entry.finding.path} (suppressed)`);
|
|
110
|
+
}
|
|
111
|
+
let status;
|
|
112
|
+
if (!scanners.length) {
|
|
113
|
+
status = 'unknown';
|
|
114
|
+
notes.push('No engine outcome was recorded for this scan.');
|
|
115
|
+
}
|
|
116
|
+
else if (deferred.length) {
|
|
117
|
+
status = 'partial';
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
status = 'complete';
|
|
121
|
+
}
|
|
122
|
+
return { status, scanners, exclusions, deferred, notes };
|
|
123
|
+
}
|
|
124
|
+
/** Coverage for a record that never captured any — genuinely not knowable after the fact. */
|
|
125
|
+
export function unknownCoverage(note) {
|
|
126
|
+
return { status: 'unknown', scanners: [], exclusions: [], deferred: [], notes: [note] };
|
|
127
|
+
}
|
|
128
|
+
export function createBaseline(result) {
|
|
129
|
+
return {
|
|
130
|
+
schemaVersion: SECURITY_SCHEMA_VERSION,
|
|
131
|
+
kind: 'dvalin-security-baseline',
|
|
132
|
+
createdAt: new Date().toISOString(),
|
|
133
|
+
scanId: result.id,
|
|
134
|
+
scanners: result.scanners.map(scanner => scanner.id),
|
|
135
|
+
coverage: deriveCoverage(result),
|
|
136
|
+
findings: result.findings.map(snapshotFinding),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export function compareWithBaseline(result, baseline, options = {}) {
|
|
140
|
+
const current = result.findings.map(snapshotFinding);
|
|
141
|
+
const baselineByFingerprint = new Map(baseline.findings.map(finding => [finding.fingerprint, finding]));
|
|
142
|
+
const currentFingerprints = new Set(current.map(finding => finding.fingerprint));
|
|
143
|
+
const baselineTargets = new Set(baseline.findings.map(finding => finding.targetFingerprint));
|
|
144
|
+
// Engines that did not complete leave a hole. A baseline finding behind that
|
|
145
|
+
// hole was not looked for, so it cannot be called resolved.
|
|
146
|
+
const completed = new Set(result.scanners.filter(run => run.status === 'completed').map(run => run.id));
|
|
147
|
+
const attempted = new Set(result.scanners.map(run => run.id));
|
|
148
|
+
const hasHole = result.scanners.some(run => run.status !== 'completed')
|
|
149
|
+
|| baseline.scanners.some(id => !attempted.has(id));
|
|
150
|
+
const covers = (finding) => {
|
|
151
|
+
if (!hasHole)
|
|
152
|
+
return true;
|
|
153
|
+
const scanner = finding.scanner ?? scannerIdForSource(finding.source);
|
|
154
|
+
// Unattributable and a hole exists: we cannot claim to have looked for it.
|
|
155
|
+
if (!scanner)
|
|
156
|
+
return false;
|
|
157
|
+
return completed.has(scanner);
|
|
158
|
+
};
|
|
159
|
+
const absent = baseline.findings.filter(finding => !currentFingerprints.has(finding.fingerprint));
|
|
160
|
+
const dismissed = (options.suppressed ?? []).map(entry => snapshotFinding(entry.finding));
|
|
161
|
+
const dismissedFingerprints = new Set(dismissed.map(finding => finding.fingerprint));
|
|
162
|
+
const unresolved = absent.filter(finding => !dismissedFingerprints.has(finding.fingerprint));
|
|
163
|
+
const added = current.filter(finding => !baselineByFingerprint.has(finding.fingerprint));
|
|
164
|
+
return {
|
|
165
|
+
new: added.filter(finding => !baselineTargets.has(finding.targetFingerprint)),
|
|
166
|
+
existing: current.filter(finding => baselineByFingerprint.has(finding.fingerprint)),
|
|
167
|
+
resolved: unresolved.filter(covers),
|
|
168
|
+
// Same rule, same file, different line or wording: the target came back.
|
|
169
|
+
reopened: added.filter(finding => baselineTargets.has(finding.targetFingerprint)),
|
|
170
|
+
dismissed,
|
|
171
|
+
unknown: unresolved.filter(finding => !covers(finding)),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export function evaluateSecurityGate(input) {
|
|
175
|
+
// A reopened finding is a new occurrence that happens to have a precedent in
|
|
176
|
+
// the baseline. It must face the gate exactly as `new` does — routing it to
|
|
177
|
+
// its own bucket without this would let a fresh critical hide behind any
|
|
178
|
+
// baselined finding of the same rule in the same file.
|
|
179
|
+
const considered = input.mode === 'new'
|
|
180
|
+
? input.delta
|
|
181
|
+
? [...input.delta.new, ...input.delta.reopened]
|
|
182
|
+
: input.result.findings.map(snapshotFinding)
|
|
183
|
+
: input.result.findings.map(snapshotFinding);
|
|
184
|
+
const thresholdIndex = input.threshold === 'none' ? -1 : SECURITY_SEVERITIES.indexOf(input.threshold);
|
|
185
|
+
const blocking = thresholdIndex === -1
|
|
186
|
+
? []
|
|
187
|
+
: considered.filter(finding => SECURITY_SEVERITIES.indexOf(severityOfFinding(finding)) <= thresholdIndex);
|
|
188
|
+
return {
|
|
189
|
+
passed: blocking.length === 0,
|
|
190
|
+
mode: input.mode,
|
|
191
|
+
threshold: input.threshold,
|
|
192
|
+
considered: considered.length,
|
|
193
|
+
blocking,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/** True for any schema version this build can read, not only the one it writes. */
|
|
197
|
+
export function isSupportedSecuritySchemaVersion(value) {
|
|
198
|
+
return typeof value === 'number' && SUPPORTED_SECURITY_SCHEMA_VERSIONS.includes(value);
|
|
199
|
+
}
|
|
200
|
+
export function isSecurityBaseline(value) {
|
|
201
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
202
|
+
return false;
|
|
203
|
+
const record = value;
|
|
204
|
+
return isSupportedSecuritySchemaVersion(record.schemaVersion)
|
|
205
|
+
&& record.kind === 'dvalin-security-baseline'
|
|
206
|
+
&& typeof record.createdAt === 'string'
|
|
207
|
+
&& typeof record.scanId === 'string'
|
|
208
|
+
&& Array.isArray(record.scanners)
|
|
209
|
+
&& Array.isArray(record.findings)
|
|
210
|
+
&& record.findings.every(isFindingSnapshot);
|
|
211
|
+
}
|
|
212
|
+
function isFindingSnapshot(value) {
|
|
213
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
214
|
+
return false;
|
|
215
|
+
const record = value;
|
|
216
|
+
return typeof record.fingerprint === 'string'
|
|
217
|
+
&& typeof record.targetFingerprint === 'string'
|
|
218
|
+
&& typeof record.findingId === 'string'
|
|
219
|
+
&& typeof record.source === 'string'
|
|
220
|
+
&& typeof record.ruleId === 'string'
|
|
221
|
+
&& typeof record.message === 'string'
|
|
222
|
+
&& typeof record.path === 'string'
|
|
223
|
+
&& Array.isArray(record.tags);
|
|
224
|
+
}
|
|
225
|
+
function digest(parts) {
|
|
226
|
+
return createHash('sha256').update(parts.join('\0')).digest('hex');
|
|
227
|
+
}
|
|
228
|
+
function normalizePath(filePath) {
|
|
229
|
+
return filePath.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/security/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAU,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAU,CAAC;AAwClF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAyDtF;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACpF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AI,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,MAAM,CAAC,KAAe;IAC7B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB;IACrC,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type SecurityCoverage, type SecurityFindingSnapshot } from './contracts.js';
|
|
2
|
+
import type { SecurityCheckEvidence } from './workflow.js';
|
|
3
|
+
/**
|
|
4
|
+
* A Verified Fix Record.
|
|
5
|
+
*
|
|
6
|
+
* Every other tool in this space asks the model that wrote the patch whether
|
|
7
|
+
* the patch is good. This records the opposite arrangement: who proposed the
|
|
8
|
+
* change is metadata, and the verdict rests on exit codes Dvalin observed and a
|
|
9
|
+
* re-scan Dvalin ran. That is what makes the record worth re-deriving, and what
|
|
10
|
+
* lets it describe a repair produced by any agent, or by a person.
|
|
11
|
+
*
|
|
12
|
+
* What it proves is narrow, and the narrowness is the point: *this finding is
|
|
13
|
+
* gone from this scan, and these checks were observed to pass.* It is not a
|
|
14
|
+
* statement that the code is free of vulnerabilities, and nothing in this
|
|
15
|
+
* module may be extended to imply that.
|
|
16
|
+
*/
|
|
17
|
+
export declare const FIX_RECORD_SCHEMA = "dvalin-fix-record/v1";
|
|
18
|
+
export declare const FIX_EXECUTORS: readonly ['dvalin', 'codex', 'claude-code', 'copilot', 'human', 'unknown'];
|
|
19
|
+
export type FixExecutor = typeof FIX_EXECUTORS[number];
|
|
20
|
+
export type FixRecordScan = {
|
|
21
|
+
scanId: string;
|
|
22
|
+
completedAt: string;
|
|
23
|
+
coverage: SecurityCoverage;
|
|
24
|
+
};
|
|
25
|
+
export type VerifiedFixRecord = {
|
|
26
|
+
schema: typeof FIX_RECORD_SCHEMA;
|
|
27
|
+
generatedAt: string;
|
|
28
|
+
tool: {
|
|
29
|
+
name: 'dvalincode';
|
|
30
|
+
version: string;
|
|
31
|
+
};
|
|
32
|
+
workflowId?: string;
|
|
33
|
+
projectId: string;
|
|
34
|
+
/** Who edited the code. Recorded, never consulted. */
|
|
35
|
+
executor: FixExecutor;
|
|
36
|
+
before: FixRecordScan & {
|
|
37
|
+
targets: SecurityFindingSnapshot[];
|
|
38
|
+
};
|
|
39
|
+
after: FixRecordScan & {
|
|
40
|
+
remainingTargets: SecurityFindingSnapshot[];
|
|
41
|
+
};
|
|
42
|
+
changes?: {
|
|
43
|
+
files: string[];
|
|
44
|
+
diffHash: string;
|
|
45
|
+
};
|
|
46
|
+
/** Commands Dvalin ran itself, with the exit codes it observed. */
|
|
47
|
+
checks: SecurityCheckEvidence[];
|
|
48
|
+
assurance: 'scan-only' | 'scan-and-checks';
|
|
49
|
+
verdict: {
|
|
50
|
+
verified: boolean;
|
|
51
|
+
reasons: string[];
|
|
52
|
+
};
|
|
53
|
+
/** Where in the hash-chained audit log this verification lives. */
|
|
54
|
+
audit?: {
|
|
55
|
+
runId: string;
|
|
56
|
+
headHash: string;
|
|
57
|
+
};
|
|
58
|
+
policyHash?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Reserved. v1 records are tamper-*evident* (anyone can re-derive the hash),
|
|
61
|
+
* not signed — signing proves who issued a record, which is a separate
|
|
62
|
+
* question needing key custody this format does not yet define.
|
|
63
|
+
*/
|
|
64
|
+
signatures?: never[];
|
|
65
|
+
recordHash: string;
|
|
66
|
+
};
|
|
67
|
+
export type FixRecordInput = {
|
|
68
|
+
workflowId?: string;
|
|
69
|
+
projectId: string;
|
|
70
|
+
executor?: FixExecutor;
|
|
71
|
+
before: FixRecordScan & {
|
|
72
|
+
targets: SecurityFindingSnapshot[];
|
|
73
|
+
};
|
|
74
|
+
after: FixRecordScan & {
|
|
75
|
+
remainingTargets: SecurityFindingSnapshot[];
|
|
76
|
+
};
|
|
77
|
+
changes?: {
|
|
78
|
+
files: string[];
|
|
79
|
+
diffHash: string;
|
|
80
|
+
};
|
|
81
|
+
checks: SecurityCheckEvidence[];
|
|
82
|
+
audit?: {
|
|
83
|
+
runId: string;
|
|
84
|
+
headHash: string;
|
|
85
|
+
};
|
|
86
|
+
policyHash?: string;
|
|
87
|
+
generatedAt?: string;
|
|
88
|
+
version?: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Decide the verdict here and nowhere else.
|
|
92
|
+
*
|
|
93
|
+
* Three callers produce these records; if each applied its own reading of
|
|
94
|
+
* "verified" the word would mean three things. The rules live in one function
|
|
95
|
+
* so that a record from the CLI, the MCP server, and the fix pipeline all mean
|
|
96
|
+
* the same thing.
|
|
97
|
+
*/
|
|
98
|
+
export declare function evaluateFixVerdict(input: {
|
|
99
|
+
checks: SecurityCheckEvidence[];
|
|
100
|
+
remainingTargets: SecurityFindingSnapshot[];
|
|
101
|
+
beforeCoverage: SecurityCoverage;
|
|
102
|
+
afterCoverage: SecurityCoverage;
|
|
103
|
+
}): {
|
|
104
|
+
verified: boolean;
|
|
105
|
+
reasons: string[];
|
|
106
|
+
};
|
|
107
|
+
export declare function buildFixRecord(input: FixRecordInput): VerifiedFixRecord;
|
|
108
|
+
/** Hash of everything except the hash itself, over canonical JSON so key order cannot change it. */
|
|
109
|
+
export declare function fixRecordHash(record: Omit<VerifiedFixRecord, 'recordHash'> | VerifiedFixRecord): string;
|
|
110
|
+
export type FixRecordVerification = {
|
|
111
|
+
ok: boolean;
|
|
112
|
+
reasons: string[];
|
|
113
|
+
record?: VerifiedFixRecord;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Re-derive a record offline.
|
|
117
|
+
*
|
|
118
|
+
* Needs no workspace, no network, and no Dvalin state — that is the property
|
|
119
|
+
* that lets a reviewer who trusts none of the above check the record anyway.
|
|
120
|
+
* It answers "is this record internally sound and unmodified", not "is the
|
|
121
|
+
* repair still good"; re-running the scanners is a separate, explicit step.
|
|
122
|
+
*/
|
|
123
|
+
export declare function verifyFixRecord(value: unknown): FixRecordVerification;
|
|
124
|
+
/** One-line summary for a terminal or a pull-request comment. */
|
|
125
|
+
export declare function renderFixRecord(record: VerifiedFixRecord): string;
|