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.
Files changed (96) hide show
  1. package/README.md +202 -46
  2. package/README.zh-CN.md +170 -39
  3. package/THIRD_PARTY_NOTICES.md +98 -43
  4. package/dist/cli.js +4 -0
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands/dvalin.d.ts +9 -1
  7. package/dist/commands/dvalin.js +177 -37
  8. package/dist/commands/dvalin.js.map +1 -1
  9. package/dist/commands/mcpInstall.d.ts +2 -0
  10. package/dist/commands/mcpInstall.js +69 -0
  11. package/dist/commands/mcpInstall.js.map +1 -0
  12. package/dist/commands/security.d.ts +47 -0
  13. package/dist/commands/security.js +415 -0
  14. package/dist/commands/security.js.map +1 -0
  15. package/dist/dvalinCli.d.ts +3 -0
  16. package/dist/dvalinCli.js +36 -0
  17. package/dist/dvalinCli.js.map +1 -0
  18. package/dist/dvalinIndex.d.ts +2 -0
  19. package/dist/dvalinIndex.js +9 -0
  20. package/dist/dvalinIndex.js.map +1 -0
  21. package/dist/evidence/pack.d.ts +8 -0
  22. package/dist/evidence/pack.js +16 -0
  23. package/dist/evidence/pack.js.map +1 -1
  24. package/dist/mcp/install.d.ts +48 -0
  25. package/dist/mcp/install.js +74 -0
  26. package/dist/mcp/install.js.map +1 -0
  27. package/dist/mcp/server.d.ts +10 -1
  28. package/dist/mcp/server.js +215 -14
  29. package/dist/mcp/server.js.map +1 -1
  30. package/dist/remediation/automate.d.ts +4 -1
  31. package/dist/remediation/automate.js +35 -18
  32. package/dist/remediation/automate.js.map +1 -1
  33. package/dist/remediation/diffScope.d.ts +29 -0
  34. package/dist/remediation/diffScope.js +107 -0
  35. package/dist/remediation/diffScope.js.map +1 -0
  36. package/dist/remediation/executor.d.ts +60 -0
  37. package/dist/remediation/executor.js +144 -0
  38. package/dist/remediation/executor.js.map +1 -0
  39. package/dist/remediation/localScan.d.ts +2 -1
  40. package/dist/remediation/localScan.js +73 -3
  41. package/dist/remediation/localScan.js.map +1 -1
  42. package/dist/remediation/sarif.d.ts +6 -0
  43. package/dist/remediation/sarif.js +36 -14
  44. package/dist/remediation/sarif.js.map +1 -1
  45. package/dist/remediation/scannerSuite.d.ts +21 -0
  46. package/dist/remediation/scannerSuite.js +65 -4
  47. package/dist/remediation/scannerSuite.js.map +1 -1
  48. package/dist/remediation/verify.d.ts +38 -0
  49. package/dist/remediation/verify.js +116 -0
  50. package/dist/remediation/verify.js.map +1 -0
  51. package/dist/security/baseline.d.ts +7 -0
  52. package/dist/security/baseline.js +26 -0
  53. package/dist/security/baseline.js.map +1 -0
  54. package/dist/security/config.d.ts +32 -0
  55. package/dist/security/config.js +131 -0
  56. package/dist/security/config.js.map +1 -0
  57. package/dist/security/contracts.d.ts +149 -0
  58. package/dist/security/contracts.js +231 -0
  59. package/dist/security/contracts.js.map +1 -0
  60. package/dist/security/fixRecord.d.ts +125 -0
  61. package/dist/security/fixRecord.js +169 -0
  62. package/dist/security/fixRecord.js.map +1 -0
  63. package/dist/security/fixRecordFile.d.ts +8 -0
  64. package/dist/security/fixRecordFile.js +37 -0
  65. package/dist/security/fixRecordFile.js.map +1 -0
  66. package/dist/security/fixRecordStore.d.ts +23 -0
  67. package/dist/security/fixRecordStore.js +74 -0
  68. package/dist/security/fixRecordStore.js.map +1 -0
  69. package/dist/security/render.d.ts +8 -0
  70. package/dist/security/render.js +20 -0
  71. package/dist/security/render.js.map +1 -0
  72. package/dist/security/suppressions.d.ts +12 -0
  73. package/dist/security/suppressions.js +60 -0
  74. package/dist/security/suppressions.js.map +1 -0
  75. package/dist/security/verifyRun.d.ts +21 -0
  76. package/dist/security/verifyRun.js +74 -0
  77. package/dist/security/verifyRun.js.map +1 -0
  78. package/dist/security/workflow.d.ts +98 -0
  79. package/dist/security/workflow.js +263 -0
  80. package/dist/security/workflow.js.map +1 -0
  81. package/dist/server/routes/remediation.d.ts +19 -0
  82. package/dist/server/routes/remediation.js +90 -18
  83. package/dist/server/routes/remediation.js.map +1 -1
  84. package/dist/tools/runCheck.d.ts +6 -0
  85. package/dist/tools/runCheck.js +1 -1
  86. package/dist/tools/runCheck.js.map +1 -1
  87. package/dist/tools/runSecuritySuite.d.ts +3 -0
  88. package/dist/tools/runSecuritySuite.js +18 -11
  89. package/dist/tools/runSecuritySuite.js.map +1 -1
  90. package/dist/tui/app.js +21 -2
  91. package/dist/tui/app.js.map +1 -1
  92. package/dist/tui/render.js +2 -0
  93. package/dist/tui/render.js.map +1 -1
  94. package/dist/version.d.ts +1 -1
  95. package/dist/version.js +1 -1
  96. package/package.json +17 -10
@@ -0,0 +1,169 @@
1
+ import { canonicalJSON, sha256 } from '../audit/hash.js';
2
+ import { VERSION } from '../version.js';
3
+ import { SECURITY_COVERAGE_STATUSES, } from './contracts.js';
4
+ /**
5
+ * A Verified Fix Record.
6
+ *
7
+ * Every other tool in this space asks the model that wrote the patch whether
8
+ * the patch is good. This records the opposite arrangement: who proposed the
9
+ * change is metadata, and the verdict rests on exit codes Dvalin observed and a
10
+ * re-scan Dvalin ran. That is what makes the record worth re-deriving, and what
11
+ * lets it describe a repair produced by any agent, or by a person.
12
+ *
13
+ * What it proves is narrow, and the narrowness is the point: *this finding is
14
+ * gone from this scan, and these checks were observed to pass.* It is not a
15
+ * statement that the code is free of vulnerabilities, and nothing in this
16
+ * module may be extended to imply that.
17
+ */
18
+ export const FIX_RECORD_SCHEMA = 'dvalin-fix-record/v1';
19
+ export const FIX_EXECUTORS = ['dvalin', 'codex', 'claude-code', 'copilot', 'human', 'unknown'];
20
+ /**
21
+ * Decide the verdict here and nowhere else.
22
+ *
23
+ * Three callers produce these records; if each applied its own reading of
24
+ * "verified" the word would mean three things. The rules live in one function
25
+ * so that a record from the CLI, the MCP server, and the fix pipeline all mean
26
+ * the same thing.
27
+ */
28
+ export function evaluateFixVerdict(input) {
29
+ const reasons = [];
30
+ if (input.remainingTargets.length) {
31
+ reasons.push(`${input.remainingTargets.length} original finding target(s) still present after the re-scan`);
32
+ }
33
+ if (!input.checks.length) {
34
+ // Matches the rule the verifier already applies: a project whose checks
35
+ // cannot be run has not demonstrated anything, so it does not pass by default.
36
+ reasons.push('no project check could be run, so the repair is unverifiable');
37
+ }
38
+ const failed = input.checks.filter(check => !check.passed);
39
+ if (failed.length) {
40
+ reasons.push(`${failed.length} observed check(s) failed: ${failed.map(check => check.kind).join(', ')}`);
41
+ }
42
+ // A caveat, not a failure. Partial coverage does not make a passing check
43
+ // false — it bounds what the record is entitled to claim, and saying so is
44
+ // the difference between evidence and a badge.
45
+ const caveats = [];
46
+ if (input.afterCoverage.status !== 'complete') {
47
+ caveats.push(`the verifying scan's coverage is ${input.afterCoverage.status}, so this record covers only what was scanned`);
48
+ }
49
+ if (input.beforeCoverage.status !== 'complete') {
50
+ caveats.push(`the original scan's coverage was ${input.beforeCoverage.status}`);
51
+ }
52
+ return { verified: reasons.length === 0, reasons: [...reasons, ...caveats] };
53
+ }
54
+ export function buildFixRecord(input) {
55
+ const verdict = evaluateFixVerdict({
56
+ checks: input.checks,
57
+ remainingTargets: input.after.remainingTargets,
58
+ beforeCoverage: input.before.coverage,
59
+ afterCoverage: input.after.coverage,
60
+ });
61
+ const record = {
62
+ schema: FIX_RECORD_SCHEMA,
63
+ generatedAt: input.generatedAt ?? new Date().toISOString(),
64
+ tool: { name: 'dvalincode', version: input.version ?? VERSION },
65
+ ...(input.workflowId ? { workflowId: input.workflowId } : {}),
66
+ projectId: input.projectId,
67
+ executor: input.executor ?? 'unknown',
68
+ before: input.before,
69
+ after: input.after,
70
+ ...(input.changes ? { changes: input.changes } : {}),
71
+ checks: input.checks,
72
+ assurance: input.checks.length ? 'scan-and-checks' : 'scan-only',
73
+ verdict,
74
+ ...(input.audit ? { audit: input.audit } : {}),
75
+ ...(input.policyHash ? { policyHash: input.policyHash } : {}),
76
+ };
77
+ return { ...record, recordHash: fixRecordHash(record) };
78
+ }
79
+ /** Hash of everything except the hash itself, over canonical JSON so key order cannot change it. */
80
+ export function fixRecordHash(record) {
81
+ const { recordHash: _ignored, ...rest } = record;
82
+ return sha256(canonicalJSON(rest));
83
+ }
84
+ /**
85
+ * Re-derive a record offline.
86
+ *
87
+ * Needs no workspace, no network, and no Dvalin state — that is the property
88
+ * that lets a reviewer who trusts none of the above check the record anyway.
89
+ * It answers "is this record internally sound and unmodified", not "is the
90
+ * repair still good"; re-running the scanners is a separate, explicit step.
91
+ */
92
+ export function verifyFixRecord(value) {
93
+ if (!isFixRecordShape(value)) {
94
+ return { ok: false, reasons: ['Not a Dvalin fix record, or written by an unsupported schema version.'] };
95
+ }
96
+ const record = value;
97
+ const reasons = [];
98
+ const expected = fixRecordHash(record);
99
+ if (expected !== record.recordHash) {
100
+ reasons.push(`recordHash mismatch: the record has been modified since it was issued (expected ${expected}, found ${record.recordHash})`);
101
+ }
102
+ // The verdict is derived, so a record whose stored verdict disagrees with its
103
+ // own evidence has been edited in a way the hash alone would catch only if
104
+ // the hash were left stale. Recomputing it closes that door.
105
+ const derived = evaluateFixVerdict({
106
+ checks: record.checks,
107
+ remainingTargets: record.after.remainingTargets,
108
+ beforeCoverage: record.before.coverage,
109
+ afterCoverage: record.after.coverage,
110
+ });
111
+ if (derived.verified !== record.verdict.verified) {
112
+ reasons.push(`verdict does not follow from the record's own evidence: stored ${record.verdict.verified}, derived ${derived.verified}`);
113
+ }
114
+ const expectedAssurance = record.checks.length ? 'scan-and-checks' : 'scan-only';
115
+ if (record.assurance !== expectedAssurance) {
116
+ reasons.push(`assurance says ${record.assurance} but the record carries ${record.checks.length} check(s)`);
117
+ }
118
+ return { ok: reasons.length === 0, reasons, record };
119
+ }
120
+ /** One-line summary for a terminal or a pull-request comment. */
121
+ export function renderFixRecord(record) {
122
+ const lines = [
123
+ `Fix record ${record.recordHash.slice(0, 12)} · ${record.verdict.verified ? 'VERIFIED' : 'NOT VERIFIED'} · ${record.assurance}`,
124
+ ` executor: ${record.executor} (recorded, not consulted)`,
125
+ ` targets: ${record.before.targets.length} before · ${record.after.remainingTargets.length} remaining`,
126
+ ` coverage: ${record.before.coverage.status} → ${record.after.coverage.status}`,
127
+ ];
128
+ for (const check of record.checks) {
129
+ lines.push(` ${check.passed ? '✓' : '✗'} ${check.kind}: ${check.command}${check.exitCode === null ? '' : ` (exit ${check.exitCode})`}`);
130
+ }
131
+ for (const reason of record.verdict.reasons)
132
+ lines.push(` · ${reason}`);
133
+ if (record.audit)
134
+ lines.push(` audit: run ${record.audit.runId} @ ${record.audit.headHash.slice(0, 12)}`);
135
+ return lines.join('\n');
136
+ }
137
+ function isFixRecordShape(value) {
138
+ if (!value || typeof value !== 'object' || Array.isArray(value))
139
+ return false;
140
+ const record = value;
141
+ return record.schema === FIX_RECORD_SCHEMA
142
+ && typeof record.generatedAt === 'string'
143
+ && typeof record.projectId === 'string'
144
+ && typeof record.recordHash === 'string'
145
+ && (record.assurance === 'scan-only' || record.assurance === 'scan-and-checks')
146
+ && FIX_EXECUTORS.includes(record.executor)
147
+ && Array.isArray(record.checks)
148
+ && isVerdict(record.verdict)
149
+ && isScanSide(record.before, 'targets')
150
+ && isScanSide(record.after, 'remainingTargets');
151
+ }
152
+ function isVerdict(value) {
153
+ if (!value || typeof value !== 'object')
154
+ return false;
155
+ const verdict = value;
156
+ return typeof verdict.verified === 'boolean' && Array.isArray(verdict.reasons);
157
+ }
158
+ function isScanSide(value, findingsKey) {
159
+ if (!value || typeof value !== 'object')
160
+ return false;
161
+ const side = value;
162
+ const coverage = side.coverage;
163
+ return typeof side.scanId === 'string'
164
+ && typeof side.completedAt === 'string'
165
+ && !!coverage
166
+ && SECURITY_COVERAGE_STATUSES.includes(coverage.status)
167
+ && Array.isArray(side[findingsKey]);
168
+ }
169
+ //# sourceMappingURL=fixRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixRecord.js","sourceRoot":"","sources":["../../src/security/fixRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,kBAAkB,C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AAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type FixRecordVerification } from './fixRecord.js';
2
+ export type FixRecordFileVerification = FixRecordVerification & {
3
+ path: string;
4
+ };
5
+ /** Load and re-derive a fix record without consulting a workspace or network. */
6
+ export declare function verifyFixRecordFile(recordPath: string, cwd?: string): Promise<FixRecordFileVerification>;
7
+ /** Human-readable verification output shared by the CLI and interactive TUI. */
8
+ export declare function renderFixRecordVerification(check: FixRecordVerification): string;
@@ -0,0 +1,37 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { UsageError } from '../core/exitCodes.js';
4
+ import { renderFixRecord, verifyFixRecord, } from './fixRecord.js';
5
+ /** Load and re-derive a fix record without consulting a workspace or network. */
6
+ export async function verifyFixRecordFile(recordPath, cwd = process.cwd()) {
7
+ const target = path.resolve(cwd, recordPath);
8
+ let parsed;
9
+ try {
10
+ parsed = JSON.parse(await readFile(target, 'utf8'));
11
+ }
12
+ catch (error) {
13
+ throw new UsageError(`Cannot read fix record ${target}: ${error instanceof Error ? error.message : String(error)}`);
14
+ }
15
+ return { path: target, ...verifyFixRecord(parsed) };
16
+ }
17
+ /** Human-readable verification output shared by the CLI and interactive TUI. */
18
+ export function renderFixRecordVerification(check) {
19
+ if (!check.record)
20
+ throw new UsageError('Not a Dvalin fix record.');
21
+ if (check.ok) {
22
+ const meaning = check.record.verdict.verified
23
+ ? 'It attests that these findings were gone and these checks were observed to pass. It is not a claim that the code is free of vulnerabilities.'
24
+ : 'Its NOT VERIFIED verdict and caveats are intact; this record does not attest that the repair passed verification.';
25
+ return [
26
+ renderFixRecord(check.record),
27
+ '',
28
+ 'Re-derived successfully: this record is unmodified and its verdict follows from its own evidence.',
29
+ meaning,
30
+ ].join('\n');
31
+ }
32
+ return [
33
+ 'This fix record did not re-derive:',
34
+ ...check.reasons.map(reason => ` · ${reason}`),
35
+ ].join('\n');
36
+ }
37
+ //# sourceMappingURL=fixRecordFile.js.map
@@ -0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AmH,CAAC;QACxH,OAAO;YACL,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC;YAC7B,EAAE;YACF,mGAAmG;YACnG,OAAO;SACR,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;IACD,OAAO;QACL,oCAAoC;QACpC,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,MAAM,EAAE,CAAC;KAChD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type VerifiedFixRecord } from './fixRecord.js';
2
+ /**
3
+ * Where issued fix records accumulate.
4
+ *
5
+ * Kept beside the audit log rather than inside a workflow, because a record
6
+ * outlives the workflow that produced it and is the thing a reviewer wants to
7
+ * collect. Writes never throw into a verification: failing to file a record is
8
+ * not a reason to fail the repair it describes.
9
+ */
10
+ export declare function defaultFixRecordDir(): string;
11
+ /** Persist a record under its own hash, so filing the same one twice is a no-op. */
12
+ export declare function saveFixRecord(record: VerifiedFixRecord, dir?: string): string | null;
13
+ /**
14
+ * Records that still re-derive, newest first, optionally narrowed to one project.
15
+ *
16
+ * A record that no longer verifies is skipped rather than surfaced: an Evidence
17
+ * Pack that carried one would be asserting something it cannot support, and the
18
+ * pack's own verification would reject it anyway.
19
+ */
20
+ export declare function listFixRecords(dir?: string, options?: {
21
+ limit?: number;
22
+ projectId?: string;
23
+ }): VerifiedFixRecord[];
@@ -0,0 +1,74 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { randomUUID } from 'node:crypto';
5
+ import { verifyFixRecord } from './fixRecord.js';
6
+ /**
7
+ * Where issued fix records accumulate.
8
+ *
9
+ * Kept beside the audit log rather than inside a workflow, because a record
10
+ * outlives the workflow that produced it and is the thing a reviewer wants to
11
+ * collect. Writes never throw into a verification: failing to file a record is
12
+ * not a reason to fail the repair it describes.
13
+ */
14
+ export function defaultFixRecordDir() {
15
+ return process.env.DVALINCODE_FIX_RECORD_DIR
16
+ ?? path.join(os.homedir(), '.dvalincode', 'security', 'fix-records');
17
+ }
18
+ /** Persist a record under its own hash, so filing the same one twice is a no-op. */
19
+ export function saveFixRecord(record, dir = defaultFixRecordDir()) {
20
+ const target = path.join(dir, `${record.recordHash}.json`);
21
+ try {
22
+ mkdirSync(dir, { recursive: true });
23
+ if (existsSync(target))
24
+ return target;
25
+ const temporary = `${target}.${process.pid}.${randomUUID().slice(0, 8)}.tmp`;
26
+ writeFileSync(temporary, `${JSON.stringify(record, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
27
+ renameSync(temporary, target);
28
+ return target;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ /**
35
+ * Records that still re-derive, newest first, optionally narrowed to one project.
36
+ *
37
+ * A record that no longer verifies is skipped rather than surfaced: an Evidence
38
+ * Pack that carried one would be asserting something it cannot support, and the
39
+ * pack's own verification would reject it anyway.
40
+ */
41
+ export function listFixRecords(dir = defaultFixRecordDir(), options = {}) {
42
+ const limit = options.limit ?? 50;
43
+ if (!existsSync(dir))
44
+ return [];
45
+ let names;
46
+ try {
47
+ names = readdirSync(dir).filter(name => name.endsWith('.json'));
48
+ }
49
+ catch {
50
+ return [];
51
+ }
52
+ const records = [];
53
+ for (const name of names) {
54
+ try {
55
+ const parsed = JSON.parse(readFileSync(path.join(dir, name), 'utf8'));
56
+ const check = verifyFixRecord(parsed);
57
+ if (!check.ok || !check.record)
58
+ continue;
59
+ // The store is install-global; a record from another repository is
60
+ // someone else's file paths and rule ids, and does not belong in this
61
+ // project's evidence.
62
+ if (options.projectId && check.record.projectId !== options.projectId)
63
+ continue;
64
+ records.push(check.record);
65
+ }
66
+ catch {
67
+ // An unreadable file is not evidence; leave it out rather than guess.
68
+ }
69
+ }
70
+ return records
71
+ .sort((a, b) => b.generatedAt.localeCompare(a.generatedAt))
72
+ .slice(0, limit);
73
+ }
74
+ //# sourceMappingURL=fixRecordStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixRecordStore.js","sourceRoot":"","sources":["../../src/security/fixRecordStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtG,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAA0B,MAAM,gBAAgB,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,OAAO,CAAC,GAAG,CAAC,yBAAyB;WACvC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AACzE,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,aAAa,CAAC,MAAyB,EAAE,GAAG,GAAW,mBAAmB,EAAE;IAC1F,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,OAAO,CAAC,CAAC;IAC3D,IAAI,CAAC;QACH,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpC,IAAI,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO,MAAM,CAAC;QACtC,MAAM,SAAS,GAAG,GAAG,MAAM,IAAI,OAAO,CAAC,GAAG,IAAI,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC;QAC7E,aAAa,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EA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;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,sEAAsE;QACxE,CAAC;IACH,CAAC;IACD,OAAO,OAAO;SACX,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;SAC1D,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACrB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { SecurityCoverage, SecurityGateResult } from './contracts.js';
2
+ /**
3
+ * State the coverage next to the verdict, always. A gate result read without it
4
+ * says more than the scan knows.
5
+ */
6
+ export declare function renderCoverage(coverage: SecurityCoverage): string;
7
+ /** `none` is an advisory policy, not a security pass. */
8
+ export declare function renderSecurityGate(gate: SecurityGateResult): string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * State the coverage next to the verdict, always. A gate result read without it
3
+ * says more than the scan knows.
4
+ */
5
+ export function renderCoverage(coverage) {
6
+ const lines = [`Coverage: ${coverage.status}`];
7
+ for (const entry of coverage.deferred)
8
+ lines.push(` · deferred: ${entry}`);
9
+ for (const entry of coverage.exclusions)
10
+ lines.push(` · excluded: ${entry}`);
11
+ for (const note of coverage.notes)
12
+ lines.push(` · ${note}`);
13
+ return lines.join('\n');
14
+ }
15
+ /** `none` is an advisory policy, not a security pass. */
16
+ export function renderSecurityGate(gate) {
17
+ const status = gate.threshold === 'none' ? 'ADVISORY' : gate.passed ? 'PASS' : 'FAIL';
18
+ return `Gate: ${status} · ${gate.mode} findings · threshold ${gate.threshold}`;
19
+ }
20
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/security/render.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAA0B;IACvD,MAAM,KAAK,GAAG,CAAC,aAAa,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/C,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC;IAC5E,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,UAAU;QAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC;IAC9E,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAC7D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,kBAAkB,CAAC,IAAwB;IACzD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACtF,OAAO,SAAS,MAAM,MAAM,IAAI,CAAC,IAAI,yBAAyB,IAAI,CAAC,SAAS,EAAE,CAAC;AACjF,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { RemediationFinding } from '../remediation/sarif.js';
2
+ import type { DvalinScanSuiteResult } from '../remediation/scannerSuite.js';
3
+ import type { SecuritySuppression } from './config.js';
4
+ export type SuppressionResult = {
5
+ result: DvalinScanSuiteResult;
6
+ suppressed: Array<{
7
+ finding: RemediationFinding;
8
+ suppression: SecuritySuppression;
9
+ }>;
10
+ expired: SecuritySuppression[];
11
+ };
12
+ export declare function applySecuritySuppressions(result: DvalinScanSuiteResult, suppressions: SecuritySuppression[], now?: Date): SuppressionResult;
@@ -0,0 +1,60 @@
1
+ import { findingFingerprint } from './contracts.js';
2
+ export function applySecuritySuppressions(result, suppressions, now = new Date()) {
3
+ const expired = suppressions.filter(suppression => suppression.expiresAt && Date.parse(suppression.expiresAt) <= now.getTime());
4
+ const active = suppressions.filter(suppression => !expired.includes(suppression));
5
+ const suppressed = [];
6
+ const findings = result.findings.filter(finding => {
7
+ const fingerprint = findingFingerprint(finding);
8
+ const match = active.find(suppression => (suppression.fingerprint === fingerprint || (!suppression.fingerprint && suppression.ruleId === finding.ruleId))
9
+ && (!suppression.path || normalizePath(suppression.path) === normalizePath(finding.path)));
10
+ if (!match)
11
+ return true;
12
+ suppressed.push({ finding, suppression: match });
13
+ return false;
14
+ });
15
+ return {
16
+ result: { ...result, findings, metrics: metricsFor(findings), score: scoreFor(findings), grade: gradeFor(scoreFor(findings)) },
17
+ suppressed,
18
+ expired,
19
+ };
20
+ }
21
+ function metricsFor(findings) {
22
+ const metrics = { critical: 0, high: 0, medium: 0, low: 0, files: 0, rules: 0 };
23
+ const files = new Set();
24
+ const rules = new Set();
25
+ for (const finding of findings) {
26
+ const score = Number.parseFloat(finding.securitySeverity ?? '');
27
+ if (score >= 9)
28
+ metrics.critical++;
29
+ else if (finding.severity === 'error' || score >= 7)
30
+ metrics.high++;
31
+ else if (finding.severity === 'warning' || score >= 4)
32
+ metrics.medium++;
33
+ else
34
+ metrics.low++;
35
+ files.add(finding.path);
36
+ rules.add(`${finding.source}:${finding.ruleId}`);
37
+ }
38
+ metrics.files = files.size;
39
+ metrics.rules = rules.size;
40
+ return metrics;
41
+ }
42
+ function scoreFor(findings) {
43
+ const metrics = metricsFor(findings);
44
+ return Math.max(0, 100 - metrics.critical * 22 - metrics.high * 12 - metrics.medium * 5 - metrics.low);
45
+ }
46
+ function gradeFor(score) {
47
+ if (score >= 90)
48
+ return 'A';
49
+ if (score >= 80)
50
+ return 'B';
51
+ if (score >= 70)
52
+ return 'C';
53
+ if (score >= 60)
54
+ return 'D';
55
+ return 'F';
56
+ }
57
+ function normalizePath(filePath) {
58
+ return filePath.replace(/\\/g, '/').replace(/^\.\//, '');
59
+ }
60
+ //# sourceMappingURL=suppressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suppressions.js","sourceRoot":"","sources":["../../src/security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,KAAK,CAAC,IAAI,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,QAAQ,CAAC,QAA8B;IAC9C,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AACzG,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa;IAC7B,IAAI,KAAK,IAAI,EAAE;QAAE,OAAO,GAAG,CAAC;IAC5B,IAAI,KAAK,IAAI,EAAE;QAAE,OAAO,GAAG,CAAC;IAC5B,IAAI,KAAK,IAAI,EAAE;QAAE,OAAO,GAAG,CAAC;IAC5B,IAAI,KAAK,IAAI,EAAE;QAAE,OAAO,GAAG,CAAC;IAC5B,OAAO,GAAG,CAAC;AACb,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,21 @@
1
+ import { runDvalinScanSuite } from '../remediation/scannerSuite.js';
2
+ import type { DvalinSecurityConfig } from './config.js';
3
+ import type { FixExecutor } from './fixRecord.js';
4
+ import { type SecurityWorkflow } from './workflow.js';
5
+ /**
6
+ * The one verification path.
7
+ *
8
+ * Every surface that verifies a repair — this command, the `--fix --verify`
9
+ * pipeline, and the MCP server — comes through here, so "verified" means the
10
+ * same thing regardless of who asked. Dvalin re-scans, Dvalin runs the checks,
11
+ * and the record is issued from what Dvalin observed.
12
+ */
13
+ export declare function runWorkflowVerification(input: {
14
+ workflow: SecurityWorkflow;
15
+ checks: DvalinSecurityConfig['checks'];
16
+ timeoutMs?: number;
17
+ executor?: FixExecutor;
18
+ verifyCommands?: string[];
19
+ /** Dependency seam used by MCP hosts and deterministic contract tests. */
20
+ runScan?: (cwd: string, options: NonNullable<Parameters<typeof runDvalinScanSuite>[1]>) => ReturnType<typeof runDvalinScanSuite>;
21
+ }): Promise<SecurityWorkflow>;
@@ -0,0 +1,74 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { AuditSink } from '../audit/log.js';
3
+ import { loadPolicy } from '../core/policy.js';
4
+ import { runProjectVerification } from '../remediation/verify.js';
5
+ import { runDvalinScanSuite } from '../remediation/scannerSuite.js';
6
+ import { deriveCoverage } from './contracts.js';
7
+ import { saveFixRecord } from './fixRecordStore.js';
8
+ import { evaluateWorkflowVerificationGate, verifySecurityWorkflow, } from './workflow.js';
9
+ /**
10
+ * The one verification path.
11
+ *
12
+ * Every surface that verifies a repair — this command, the `--fix --verify`
13
+ * pipeline, and the MCP server — comes through here, so "verified" means the
14
+ * same thing regardless of who asked. Dvalin re-scans, Dvalin runs the checks,
15
+ * and the record is issued from what Dvalin observed.
16
+ */
17
+ export async function runWorkflowVerification(input) {
18
+ const { workflow } = input;
19
+ // The checks are governed commands; opening a run puts them in the
20
+ // hash-chained log so the record has something to anchor to.
21
+ const audit = new AuditSink(`verify-${randomUUID().slice(0, 8)}`);
22
+ const loadedPolicy = loadPolicy(workflow.root);
23
+ audit.append({
24
+ type: 'run_start',
25
+ task: `security verify ${workflow.id}`,
26
+ mode: 'security-verify',
27
+ provider: 'none',
28
+ model: 'none',
29
+ cwd: workflow.root,
30
+ gitHead: null,
31
+ policyHash: loadedPolicy.hash,
32
+ });
33
+ let result;
34
+ let verification;
35
+ let status = 'done';
36
+ try {
37
+ result = await (input.runScan ?? runDvalinScanSuite)(workflow.root, {
38
+ scanners: workflow.scanners,
39
+ timeoutMs: input.timeoutMs,
40
+ });
41
+ verification = await runProjectVerification({
42
+ cwd: workflow.root,
43
+ kinds: input.checks,
44
+ commands: input.verifyCommands?.length ? input.verifyCommands : undefined,
45
+ timeoutMs: input.timeoutMs,
46
+ audit,
47
+ });
48
+ }
49
+ catch (error) {
50
+ // Recorded as what it was. A run that threw must not be written into the
51
+ // chain as a clean completion — that is the one thing the log exists to
52
+ // make impossible.
53
+ status = 'error';
54
+ throw error;
55
+ }
56
+ finally {
57
+ audit.append({ type: 'run_end', status, iterations: 1, warnings: audit.getWarnings() });
58
+ }
59
+ const gate = evaluateWorkflowVerificationGate(workflow, result);
60
+ const updated = await verifySecurityWorkflow({
61
+ workflow,
62
+ result,
63
+ gate,
64
+ checks: verification.evidence,
65
+ coverage: deriveCoverage(result),
66
+ executor: input.executor,
67
+ audit: { runId: audit.runId, headHash: audit.head() },
68
+ policyHash: loadedPolicy.hash,
69
+ });
70
+ if (updated.verification?.record)
71
+ saveFixRecord(updated.verification.record);
72
+ return updated;
73
+ }
74
+ //# sourceMappingURL=verifyRun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyRun.js","sourceRoot":"","sources":["../../src/security/verifyRun.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAA8B,MAAM,gCAAgC,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EACL,gCAAgC,EAChC,sBAAsB,GAEvB,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,KAW7C;IACC,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,mEAAmE;IACnE,6DAA6D;IAC7D,MAAM,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