dvalincode 0.21.0 → 0.22.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 (120) hide show
  1. package/README.md +209 -4
  2. package/README.zh-CN.md +160 -4
  3. package/dist/agent/compact.d.ts +8 -0
  4. package/dist/agent/compact.js +44 -5
  5. package/dist/agent/compact.js.map +1 -1
  6. package/dist/agent/loop.d.ts +5 -0
  7. package/dist/agent/loop.js +16 -7
  8. package/dist/agent/loop.js.map +1 -1
  9. package/dist/agent/runner.d.ts +4 -3
  10. package/dist/agent/runner.js +81 -8
  11. package/dist/agent/runner.js.map +1 -1
  12. package/dist/agent/session.d.ts +7 -0
  13. package/dist/agent/session.js +27 -1
  14. package/dist/agent/session.js.map +1 -1
  15. package/dist/agent/types.d.ts +5 -1
  16. package/dist/agent/types.js.map +1 -1
  17. package/dist/audit/log.d.ts +5 -1
  18. package/dist/audit/log.js.map +1 -1
  19. package/dist/commands/dvalin.d.ts +7 -1
  20. package/dist/commands/dvalin.js +209 -9
  21. package/dist/commands/dvalin.js.map +1 -1
  22. package/dist/commands/provider.js +2 -0
  23. package/dist/commands/provider.js.map +1 -1
  24. package/dist/commands/run.js +4 -2
  25. package/dist/commands/run.js.map +1 -1
  26. package/dist/commands/security.d.ts +2 -0
  27. package/dist/commands/security.js +228 -14
  28. package/dist/commands/security.js.map +1 -1
  29. package/dist/harness/run.d.ts +8 -2
  30. package/dist/harness/run.js +1 -1
  31. package/dist/harness/run.js.map +1 -1
  32. package/dist/mcp/server.js +5 -2
  33. package/dist/mcp/server.js.map +1 -1
  34. package/dist/providers/anthropic.js +14 -2
  35. package/dist/providers/anthropic.js.map +1 -1
  36. package/dist/providers/openaiCompatible.js +7 -6
  37. package/dist/providers/openaiCompatible.js.map +1 -1
  38. package/dist/providers/retry.d.ts +32 -0
  39. package/dist/providers/retry.js +150 -0
  40. package/dist/providers/retry.js.map +1 -0
  41. package/dist/providers/types.d.ts +10 -0
  42. package/dist/remediation/automate.d.ts +1 -1
  43. package/dist/remediation/automate.js +2 -1
  44. package/dist/remediation/automate.js.map +1 -1
  45. package/dist/remediation/codeQualityExport.d.ts +25 -0
  46. package/dist/remediation/codeQualityExport.js +24 -0
  47. package/dist/remediation/codeQualityExport.js.map +1 -0
  48. package/dist/remediation/evasion.d.ts +61 -0
  49. package/dist/remediation/evasion.js +190 -0
  50. package/dist/remediation/evasion.js.map +1 -0
  51. package/dist/remediation/fixLoop.d.ts +255 -0
  52. package/dist/remediation/fixLoop.js +639 -0
  53. package/dist/remediation/fixLoop.js.map +1 -0
  54. package/dist/remediation/fixLoopStats.d.ts +93 -0
  55. package/dist/remediation/fixLoopStats.js +244 -0
  56. package/dist/remediation/fixLoopStats.js.map +1 -0
  57. package/dist/remediation/rebase.d.ts +44 -0
  58. package/dist/remediation/rebase.js +114 -0
  59. package/dist/remediation/rebase.js.map +1 -0
  60. package/dist/remediation/reproduce.d.ts +47 -0
  61. package/dist/remediation/reproduce.js +75 -0
  62. package/dist/remediation/reproduce.js.map +1 -0
  63. package/dist/remediation/sarif.d.ts +4 -1
  64. package/dist/remediation/sarif.js +19 -1
  65. package/dist/remediation/sarif.js.map +1 -1
  66. package/dist/remediation/scannerSuite.d.ts +51 -3
  67. package/dist/remediation/scannerSuite.js +346 -87
  68. package/dist/remediation/scannerSuite.js.map +1 -1
  69. package/dist/remediation/verify.d.ts +8 -0
  70. package/dist/remediation/verify.js +24 -11
  71. package/dist/remediation/verify.js.map +1 -1
  72. package/dist/security/config.d.ts +8 -2
  73. package/dist/security/config.js +10 -3
  74. package/dist/security/config.js.map +1 -1
  75. package/dist/security/contracts.js +15 -0
  76. package/dist/security/contracts.js.map +1 -1
  77. package/dist/security/fixRecord.d.ts +103 -8
  78. package/dist/security/fixRecord.js +113 -11
  79. package/dist/security/fixRecord.js.map +1 -1
  80. package/dist/security/fixRecordFile.d.ts +11 -2
  81. package/dist/security/fixRecordFile.js +20 -2
  82. package/dist/security/fixRecordFile.js.map +1 -1
  83. package/dist/security/fixRecordSignature.d.ts +104 -0
  84. package/dist/security/fixRecordSignature.js +227 -0
  85. package/dist/security/fixRecordSignature.js.map +1 -0
  86. package/dist/security/guardedScan.d.ts +39 -0
  87. package/dist/security/guardedScan.js +45 -0
  88. package/dist/security/guardedScan.js.map +1 -0
  89. package/dist/security/onboarding.d.ts +28 -0
  90. package/dist/security/onboarding.js +124 -0
  91. package/dist/security/onboarding.js.map +1 -0
  92. package/dist/security/reproduceInCi.d.ts +44 -0
  93. package/dist/security/reproduceInCi.js +96 -0
  94. package/dist/security/reproduceInCi.js.map +1 -0
  95. package/dist/security/reverify.d.ts +130 -0
  96. package/dist/security/reverify.js +361 -0
  97. package/dist/security/reverify.js.map +1 -0
  98. package/dist/security/suppressionGuard.d.ts +58 -0
  99. package/dist/security/suppressionGuard.js +216 -0
  100. package/dist/security/suppressionGuard.js.map +1 -0
  101. package/dist/security/verifyRun.js +14 -3
  102. package/dist/security/verifyRun.js.map +1 -1
  103. package/dist/security/workflow.d.ts +11 -1
  104. package/dist/security/workflow.js +2 -0
  105. package/dist/security/workflow.js.map +1 -1
  106. package/dist/server/routes/config.js +2 -0
  107. package/dist/server/routes/config.js.map +1 -1
  108. package/dist/server/routes/remediation.js +6 -5
  109. package/dist/server/routes/remediation.js.map +1 -1
  110. package/dist/tools/editFile.js +9 -2
  111. package/dist/tools/editFile.js.map +1 -1
  112. package/dist/tools/registry.d.ts +4 -1
  113. package/dist/tools/registry.js +29 -9
  114. package/dist/tools/registry.js.map +1 -1
  115. package/dist/tools/runSecuritySuite.d.ts +3 -0
  116. package/dist/tools/runSecuritySuite.js +2 -2
  117. package/dist/tools/runSecuritySuite.js.map +1 -1
  118. package/dist/version.d.ts +1 -1
  119. package/dist/version.js +1 -1
  120. package/package.json +1 -1
@@ -0,0 +1,61 @@
1
+ import type { SecurityFindingSnapshot } from '../security/contracts.js';
2
+ import type { FixRecordEvasion } from '../security/fixRecord.js';
3
+ /**
4
+ * Ways to make a finding stop being reported without fixing it.
5
+ *
6
+ * The suppression guard handles the bluntest one — telling the scanner to
7
+ * look away. These are the next ones an agent under "until the scanner is
8
+ * clean" pressure reaches for, and each is visible in the diff:
9
+ *
10
+ * - **equivalent sink**: the dangerous call is rewritten into a sibling the
11
+ * rule does not match — `eval(x)` becomes `new Function(x)()`, `exec(cmd)`
12
+ * becomes `spawn(cmd, { shell: true })`. The vulnerability is the same; only
13
+ * the spelling moved. Flagged when the change adds a sink of the same family
14
+ * as a target it claims to fix.
15
+ * - **target file deleted**: the finding is gone because the code is. Removing
16
+ * functionality may be right, but it is a product decision, not a repair, and
17
+ * it is made by a person in its own change.
18
+ * - **tests deleted or assertions removed**: the checks pass because they ask
19
+ * less. A fix that needs a test to stop asserting is not a fix.
20
+ *
21
+ * These are heuristics, and say so: a signal is a reason the loop will not
22
+ * call the change verified, with the evidence attached, not a claim of intent.
23
+ * What is not detected here — a sink in a family not listed, logic deleted
24
+ * inside a file that survives, untested changed lines — is not detected.
25
+ */
26
+ export type EvasionSignal = {
27
+ kind: 'equivalent-sink';
28
+ path: string;
29
+ line: number;
30
+ family: SinkFamily;
31
+ text: string;
32
+ } | {
33
+ kind: 'target-file-deleted';
34
+ path: string;
35
+ ruleId: string;
36
+ } | {
37
+ kind: 'test-deleted';
38
+ path: string;
39
+ } | {
40
+ kind: 'assertions-removed';
41
+ path: string;
42
+ removed: number;
43
+ };
44
+ export type SinkFamily = 'code-execution' | 'command-execution' | 'sql' | 'html' | 'deserialization';
45
+ export declare function isTestPath(file: string): boolean;
46
+ export declare function sinkFamilyOf(finding: Pick<SecurityFindingSnapshot, 'ruleId' | 'message'>): SinkFamily | undefined;
47
+ export declare function detectEvasion(cwd: string, baseCommit: string, targets: SecurityFindingSnapshot[], options?: {
48
+ exempt?: string[];
49
+ }): Promise<EvasionSignal[]>;
50
+ /** The record's form of a signal: location and kind, no code (FV-15). */
51
+ export declare function toRecordEvasion(signal: EvasionSignal): FixRecordEvasion;
52
+ export declare function describeEvasion(signal: EvasionSignal): string;
53
+ export declare function evasionKey(signal: EvasionSignal): string;
54
+ /** Added and removed lines per file from a zero-context diff, new-side line numbers for additions. */
55
+ export declare function parseDiff(diff: string): {
56
+ added: Map<string, Array<{
57
+ line: number;
58
+ text: string;
59
+ }>>;
60
+ removed: Map<string, string[]>;
61
+ };
@@ -0,0 +1,190 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { readFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { promisify } from 'node:util';
5
+ const execFileAsync = promisify(execFile);
6
+ /** Which family a finding belongs to, read from its rule and message. */
7
+ const FAMILY_OF_FINDING = [
8
+ { family: 'code-execution', pattern: /\beval\b|code[-_ ]?injection|dynamic code|function constructor/i },
9
+ { family: 'command-execution', pattern: /command[-_ ]?injection|os[-_ ]?command|shell|child[-_ ]?process|subprocess/i },
10
+ { family: 'sql', pattern: /\bsql\b|sqli/i },
11
+ { family: 'html', pattern: /xss|cross[-_ ]?site|html[-_ ]?injection|innerhtml|dangerously/i },
12
+ { family: 'deserialization', pattern: /deserializ|pickle|unserialize|yaml\.load/i },
13
+ ];
14
+ /** Dangerous calls per family. A fix for that family that adds one of these has moved the sink, not removed it. */
15
+ const SINKS = {
16
+ 'code-execution': [
17
+ /\beval\s*\(/,
18
+ /\bnew\s+Function\s*\(/,
19
+ /\b(?:setTimeout|setInterval)\s*\(\s*['"`]/,
20
+ /\bvm\.(?:runIn\w*|compileFunction)\s*\(/,
21
+ /\bexec\s*\(\s*compile\s*\(/,
22
+ ],
23
+ 'command-execution': [
24
+ /\bshell\s*:\s*true\b/,
25
+ /\bshell\s*=\s*True\b/,
26
+ /\bexecSync\s*\(/,
27
+ /\bchild_process\.exec\s*\(/,
28
+ /\bos\.(?:system|popen)\s*\(/,
29
+ /\bRuntime\.getRuntime\(\)\.exec\s*\(/,
30
+ ],
31
+ sql: [
32
+ /['"`]\s*(?:SELECT|INSERT|UPDATE|DELETE)\b[^'"`]*['"`]\s*\+/i,
33
+ /\$\{[^}]+\}[^`]*\b(?:FROM|WHERE|VALUES|SET)\b|\b(?:SELECT|INSERT|UPDATE|DELETE)\b[^`]*\$\{/i,
34
+ /\.(?:raw|unsafe|queryRaw|executeRaw)\w*\s*\(/,
35
+ /\bf['"]\s*(?:SELECT|INSERT|UPDATE|DELETE)\b/i,
36
+ ],
37
+ html: [
38
+ /\b(?:innerHTML|outerHTML)\s*=/,
39
+ /\bdangerouslySetInnerHTML\b/,
40
+ /\binsertAdjacentHTML\s*\(/,
41
+ /\bdocument\.write(?:ln)?\s*\(/,
42
+ /\bv-html\b/,
43
+ /\|\s*safe\b|\bmark_safe\s*\(/,
44
+ ],
45
+ deserialization: [
46
+ /\bpickle\.loads?\s*\(/,
47
+ /\byaml\.load\s*\((?![^)]*SafeLoader)/,
48
+ /\bunserialize\s*\(/,
49
+ /\bObjectInputStream\b/,
50
+ /\bMarshal\.load\b/,
51
+ ],
52
+ };
53
+ const TEST_PATH = /(?:^|\/)(?:tests?|specs?|__tests__|testdata)\/|(?:^|\/)[^/]*\.(?:test|spec)\.[cm]?[jt]sx?$|(?:^|\/)test_[^/]*\.py$|(?:^|\/)[^/]*_test\.(?:py|go)$|(?:^|\/)[^/]*Tests?\.(?:java|kt|cs)$/i;
54
+ const ASSERTION = /\b(?:expect|assert\w*|should|t\.(?:Error|Fatal)\w*|require\.\w+|verify)\b/;
55
+ export function isTestPath(file) {
56
+ return TEST_PATH.test(file.split('\\').join('/'));
57
+ }
58
+ export function sinkFamilyOf(finding) {
59
+ const text = `${finding.ruleId} ${finding.message}`;
60
+ return FAMILY_OF_FINDING.find(entry => entry.pattern.test(text))?.family;
61
+ }
62
+ export async function detectEvasion(cwd, baseCommit, targets, options = {}) {
63
+ const exempt = new Set(options.exempt ?? []);
64
+ const signals = [];
65
+ const status = await git(cwd, ['diff', '--name-status', '--no-renames', '--relative', baseCommit, '--', '.']);
66
+ const deleted = new Set();
67
+ for (const line of status.split('\n').filter(Boolean)) {
68
+ const [code, file] = line.split('\t');
69
+ if (code?.startsWith('D') && file)
70
+ deleted.add(file);
71
+ }
72
+ for (const target of targets) {
73
+ if (deleted.has(target.path))
74
+ signals.push({ kind: 'target-file-deleted', path: target.path, ruleId: target.ruleId });
75
+ }
76
+ for (const file of deleted) {
77
+ if (isTestPath(file) && !exempt.has(file))
78
+ signals.push({ kind: 'test-deleted', path: file });
79
+ }
80
+ const diff = parseDiff(await git(cwd, ['diff', '--unified=0', '--no-color', '--no-ext-diff', '--relative', baseCommit, '--', '.']));
81
+ const untracked = (await git(cwd, ['ls-files', '--others', '--exclude-standard'])).split('\n').filter(Boolean);
82
+ const families = new Set(targets.map(sinkFamilyOf).filter((family) => Boolean(family)));
83
+ const addedLines = new Map(diff.added);
84
+ for (const file of untracked) {
85
+ if (addedLines.has(file))
86
+ continue;
87
+ const content = await readTracked(cwd, file);
88
+ addedLines.set(file, content.split('\n').map((text, index) => ({ line: index + 1, text })));
89
+ }
90
+ for (const [file, lines] of addedLines) {
91
+ // A test that exercises the vulnerable call is how reproduction works.
92
+ if (isTestPath(file) || exempt.has(file))
93
+ continue;
94
+ for (const { line, text } of lines) {
95
+ for (const family of families) {
96
+ if (SINKS[family].some(pattern => pattern.test(text))) {
97
+ signals.push({ kind: 'equivalent-sink', path: file, line, family, text: text.trim().slice(0, 160) });
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ }
103
+ for (const [file, removed] of diff.removed) {
104
+ if (!isTestPath(file) || exempt.has(file) || deleted.has(file))
105
+ continue;
106
+ const lostAssertions = removed.filter(text => ASSERTION.test(text)).length
107
+ - (diff.added.get(file) ?? []).filter(({ text }) => ASSERTION.test(text)).length;
108
+ if (lostAssertions > 0)
109
+ signals.push({ kind: 'assertions-removed', path: file, removed: lostAssertions });
110
+ }
111
+ return signals;
112
+ }
113
+ /** The record's form of a signal: location and kind, no code (FV-15). */
114
+ export function toRecordEvasion(signal) {
115
+ switch (signal.kind) {
116
+ case 'equivalent-sink': return { kind: signal.kind, path: signal.path, line: signal.line, family: signal.family };
117
+ case 'target-file-deleted': return { kind: signal.kind, path: signal.path, ruleId: signal.ruleId };
118
+ case 'test-deleted': return { kind: signal.kind, path: signal.path };
119
+ case 'assertions-removed': return { kind: signal.kind, path: signal.path, removed: signal.removed };
120
+ }
121
+ }
122
+ export function describeEvasion(signal) {
123
+ switch (signal.kind) {
124
+ case 'equivalent-sink':
125
+ return `${signal.path}:${signal.line} adds a ${signal.family} sink (\`${signal.text}\`) — the same kind of call the fix was meant to remove`;
126
+ case 'target-file-deleted':
127
+ return `${signal.path} was deleted; ${signal.ruleId} is gone because the code is, which is a product decision for a person, not a repair`;
128
+ case 'test-deleted':
129
+ return `${signal.path} (a test) was deleted`;
130
+ case 'assertions-removed':
131
+ return `${signal.path} lost ${signal.removed} assertion(s)`;
132
+ }
133
+ }
134
+ export function evasionKey(signal) {
135
+ return signal.kind === 'equivalent-sink'
136
+ ? `evasion:${signal.kind}:${signal.path}:${signal.text}`
137
+ : `evasion:${signal.kind}:${signal.path}`;
138
+ }
139
+ /** Added and removed lines per file from a zero-context diff, new-side line numbers for additions. */
140
+ export function parseDiff(diff) {
141
+ const added = new Map();
142
+ const removed = new Map();
143
+ let oldFile;
144
+ let newFile;
145
+ let next = 0;
146
+ let inHeader = false;
147
+ for (const raw of diff.split('\n')) {
148
+ if (raw.startsWith('diff --git ')) {
149
+ inHeader = true;
150
+ oldFile = newFile = undefined;
151
+ continue;
152
+ }
153
+ if (inHeader) {
154
+ if (raw.startsWith('--- ')) {
155
+ const name = raw.slice(4).trim();
156
+ oldFile = name === '/dev/null' ? undefined : name.replace(/^a\//, '');
157
+ continue;
158
+ }
159
+ if (raw.startsWith('+++ ')) {
160
+ const name = raw.slice(4).trim();
161
+ newFile = name === '/dev/null' ? undefined : name.replace(/^b\//, '');
162
+ continue;
163
+ }
164
+ if (!raw.startsWith('@@'))
165
+ continue;
166
+ }
167
+ const hunk = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(raw);
168
+ if (hunk) {
169
+ inHeader = false;
170
+ next = Number(hunk[1]);
171
+ continue;
172
+ }
173
+ if (raw.startsWith('+') && newFile) {
174
+ added.set(newFile, [...(added.get(newFile) ?? []), { line: next, text: raw.slice(1) }]);
175
+ next += 1;
176
+ }
177
+ else if (raw.startsWith('-') && oldFile) {
178
+ removed.set(oldFile, [...(removed.get(oldFile) ?? []), raw.slice(1)]);
179
+ }
180
+ }
181
+ return { added, removed };
182
+ }
183
+ async function readTracked(cwd, file) {
184
+ return readFile(path.join(cwd, file), 'utf8').catch(() => '');
185
+ }
186
+ async function git(cwd, args) {
187
+ const { stdout } = await execFileAsync('git', args, { cwd, maxBuffer: 64 * 1024 * 1024 });
188
+ return stdout;
189
+ }
190
+ //# sourceMappingURL=evasion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evasion.js","sourceRoot":"","sources":["../../src/remediation/evasion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAiC1C,yEAAyE;AACzE,MAAM,iBAAiB,GAAmD;IACxE,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,iEAAiE,EAAE;IACxG,EAAE,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,6EAA6E,EAAE;IACvH,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE;IAC3C,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gEAAgE,EAAE;IAC7F,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,2CAA2C,EAAE;CACpF,CAAC;AAEF,mHAAmH;AACnH,MAAM,KAAK,GAAiC;IA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,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;IAC1F,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,255 @@
1
+ import { type SecurityFindingSnapshot, type SecurityThreshold } from '../security/contracts.js';
2
+ import { type FixExecutor, type FixRecordReproduction, type VerifiedFixRecord } from '../security/fixRecord.js';
3
+ import { type SuppressionChange } from '../security/suppressionGuard.js';
4
+ import type { SecurityCheckEvidence } from '../security/workflow.js';
5
+ import type { ExecutorEvent, RemediationExecutor } from './executor.js';
6
+ import { runDvalinScanSuite, type DvalinScannerId, type DvalinScanSuiteResult } from './scannerSuite.js';
7
+ import type { RemediationFinding } from './sarif.js';
8
+ import { type EvasionSignal } from './evasion.js';
9
+ import { type ReproRunner } from './reproduce.js';
10
+ /**
11
+ * The bounded fix loop: an executor edits, Dvalin judges, and only the delta
12
+ * goes back.
13
+ *
14
+ * This replaces the round trip a person does by hand today — push the agent's
15
+ * patch, watch the CI scanner block it again, paste the output back into the
16
+ * agent, rebase, repeat. Here every round is judged where the patch is, with the
17
+ * same engines the gate uses, and the executor hears only what is still wrong.
18
+ *
19
+ * The executor is never the judge. It does not see the scan, does not run the
20
+ * checks that count, and cannot make a finding go away by suppressing it: the
21
+ * suppressions it adds are undone before each scan (`suppressionGuard`) and are
22
+ * themselves an open problem until removed. What it says about its own work is
23
+ * shown to the person, and nothing else reads it.
24
+ *
25
+ * The loop stops when one of these holds, and says which:
26
+ *
27
+ * - `verified` — every target gone, nothing blocking introduced, every
28
+ * check observed passing, no suppression added;
29
+ * - `budget-exhausted` — the round limit was reached first;
30
+ * - `stalled` — a round changed nothing that was open, or the open
31
+ * set stopped shrinking; more rounds would cost without
32
+ * converging;
33
+ * - `not-auto-fixable` — every target needs a person (e.g. no fixed version of
34
+ * a dependency exists);
35
+ * - `unverifiable` — the engines that find the targets, or the checks,
36
+ * could not run; no edit can fix that;
37
+ * - `rebase-conflict` — with `rebase`, upstream moved and the executor could not
38
+ * resolve the conflicts; the tree is left as it was;
39
+ * - `not-reproduced` — with reproduce-then-fix, no test written for the code
40
+ * findings failed on the vulnerable code. The finding may
41
+ * be a false positive or unreachable: a person triages it,
42
+ * and no fix is attempted on a vulnerability nobody could
43
+ * demonstrate.
44
+ *
45
+ * With reproduce-then-fix (`reproduce`), code findings get a phase before any
46
+ * fix: the executor writes tests only, Dvalin requires them to fail on the
47
+ * vulnerable code, hashes them, and from then on requires them to pass
48
+ * unchanged. See `reproduce.ts`. Evasion signals (`evasion.ts`) are open
49
+ * problems in every fix round.
50
+ */
51
+ export type FixLoopOutcome = 'verified' | 'budget-exhausted' | 'stalled' | 'not-auto-fixable' | 'unverifiable' | 'not-reproduced' | 'rebase-conflict';
52
+ /**
53
+ * Which stop rule fired. `outcome` is what a person acts on; this is what the
54
+ * loop is tuned on — two stalls for different reasons need different fixes.
55
+ */
56
+ export type FixLoopStopRule = 'clean' | 'engine-incomplete' | 'no-checks' | 'no-change' | 'oscillating' | 'budget' | 'nothing-fixable' | 'not-reproduced' | 'rebase-conflict';
57
+ export type TargetClass = 'dependency' | 'code';
58
+ export type FixLoopObservation = {
59
+ scan: DvalinScanSuiteResult;
60
+ checks: SecurityCheckEvidence[];
61
+ checkTails: string[];
62
+ suppressions: SuppressionChange[];
63
+ remaining: SecurityFindingSnapshot[];
64
+ /** Everything the change introduced, unfiltered. */
65
+ introduced: SecurityFindingSnapshot[];
66
+ /** The part of `introduced` at or above the gate. */
67
+ blocking: SecurityFindingSnapshot[];
68
+ /** Engines that produce the targets but did not complete — their targets are unknown, not gone. */
69
+ incompleteEngines: string[];
70
+ /** Ways the change may have hidden a finding instead of fixing it. */
71
+ evasion: EvasionSignal[];
72
+ /** Reproduction tests that changed or vanished since they were shown to fail. */
73
+ reproTampered: string[];
74
+ hasChanges: boolean;
75
+ /** Stable keys for everything still open; the loop's measure of progress. */
76
+ open: string[];
77
+ };
78
+ export type FixLoopRound = {
79
+ /** `reproduce` rounds write tests only; `fix` rounds are counted against `maxRounds`. */
80
+ phase: 'reproduce' | 'fix';
81
+ round: number;
82
+ durationMs: number;
83
+ remaining: number;
84
+ blockingIntroduced: number;
85
+ failedChecks: string[];
86
+ suppressions: number;
87
+ evasion: number;
88
+ open: number;
89
+ /** Targets closed by the end of this round, out of the loop's targets. */
90
+ fixed: number;
91
+ /** Reproduce rounds only: what still stood between the tests and a demonstrated failure. */
92
+ problems?: string[];
93
+ /** Set when upstream had moved and the change was rebased before this round was judged. */
94
+ rebased?: {
95
+ from: string;
96
+ to: string;
97
+ conflicts: string[];
98
+ };
99
+ /**
100
+ * How this round was scanned. `narrowed`: per-file engines looked only at
101
+ * the files the change touched and the targets' files. A narrowed round that
102
+ * would have stopped is `confirmed` by a full scan, and only the full scan
103
+ * decides; `decisionChanged` records when the two disagreed.
104
+ */
105
+ scan?: {
106
+ mode: 'narrowed' | 'full';
107
+ durationMs: number;
108
+ confirmed?: boolean;
109
+ decisionChanged?: boolean;
110
+ };
111
+ };
112
+ export type FixLoopResult = {
113
+ id: string;
114
+ outcome: FixLoopOutcome;
115
+ /** One sentence a person can act on. */
116
+ reason: string;
117
+ stopRule: FixLoopStopRule;
118
+ rounds: FixLoopRound[];
119
+ /** Targets the loop did not attempt, and why. */
120
+ needsHuman: Array<{
121
+ finding: SecurityFindingSnapshot;
122
+ reason: string;
123
+ }>;
124
+ final?: FixLoopObservation;
125
+ record?: VerifiedFixRecord;
126
+ /** Present when reproduce-then-fix ran. */
127
+ reproduction?: FixRecordReproduction;
128
+ /** The executor conversation, for a follow-up turn such as publishing. */
129
+ session?: string;
130
+ /** Where the round log was written, when it could be. */
131
+ logPath?: string | null;
132
+ };
133
+ export type FixLoopInput = {
134
+ /** Where the executor edits: an isolated worktree, or a clean workspace. */
135
+ cwd: string;
136
+ /** The commit the change is measured against. Suppressions are judged relative to it. */
137
+ baseCommit: string;
138
+ /** The scan the loop is answering. */
139
+ before: DvalinScanSuiteResult;
140
+ /** What must close. */
141
+ targets: RemediationFinding[];
142
+ /** Everything the repository already had, so pre-existing findings are not blamed on the change. */
143
+ baseline: RemediationFinding[];
144
+ scanners: DvalinScannerId[];
145
+ threshold: SecurityThreshold;
146
+ maxRounds: number;
147
+ executor: RemediationExecutor;
148
+ executorLabel: FixExecutor;
149
+ provider?: string;
150
+ timeoutMs?: number;
151
+ verifyCommands?: string[];
152
+ /** Context for the first prompt, e.g. which worktree and branch. */
153
+ worktreeContext?: string;
154
+ /**
155
+ * Reproduce-then-fix for code findings. Absent: code findings are fixed
156
+ * without a reproduction. Dependency findings never need one.
157
+ */
158
+ reproduce?: {
159
+ runner: ReproRunner;
160
+ rounds: number;
161
+ };
162
+ /**
163
+ * Keep the change on top of a moving base: before the loop starts and after
164
+ * every executor turn, rebase onto this ref when it has moved, then judge.
165
+ * The baseline is re-scanned on the new base, so findings upstream brought in
166
+ * are not blamed on the fix. Needs an isolated worktree branch.
167
+ */
168
+ rebase?: {
169
+ onto: string;
170
+ maxConflictRounds: number;
171
+ };
172
+ onRound?: (round: FixLoopRound, observation: FixLoopObservation) => void;
173
+ onReproduceRound?: (round: FixLoopRound) => void;
174
+ onExecutorEvent?: (event: ExecutorEvent) => void;
175
+ /**
176
+ * Scan every round in full. Off by default: between rounds, per-file engines
177
+ * rescan only what changed and the targets' files, and every stop is
178
+ * confirmed by a full scan before it is decided or recorded.
179
+ */
180
+ fullScanEveryRound?: boolean;
181
+ /** Dependency seams for deterministic tests. */
182
+ runScan?: typeof runDvalinScanSuite;
183
+ runChecks?: (cwd: string) => Promise<{
184
+ evidence: SecurityCheckEvidence[];
185
+ outputTails: string[];
186
+ }>;
187
+ runRepro?: (cwd: string, command: string) => Promise<{
188
+ exitCode: number | null;
189
+ tail: string;
190
+ }>;
191
+ logDir?: string;
192
+ };
193
+ export declare function classifyTarget(finding: Pick<RemediationFinding, 'scanner' | 'source' | 'path'>): TargetClass;
194
+ /** Why a target should go to a person instead of the loop, or undefined if the loop should try. */
195
+ export declare function notAutoFixableReason(finding: Pick<RemediationFinding, 'scanner' | 'source' | 'path' | 'message'>): string | undefined;
196
+ export declare function runFixLoop(original: FixLoopInput): Promise<FixLoopResult>;
197
+ /** The stop rule. Exported because it is the policy, and the policy is what should be tested. */
198
+ export declare function decide(observation: FixLoopObservation, previous: FixLoopObservation | undefined, state: {
199
+ round: number;
200
+ maxRounds: number;
201
+ best: number;
202
+ roundsWithoutImprovement: number;
203
+ }): {
204
+ outcome: FixLoopOutcome;
205
+ reason: string;
206
+ rule: FixLoopStopRule;
207
+ } | undefined;
208
+ export declare function buildLoopInitialPrompt(targets: RemediationFinding[], maxRounds: number, worktreeContext?: string, reproTests?: string[]): string;
209
+ /** Only the delta: what is still open and why. The executor never sees a verdict it could argue with. */
210
+ export declare function buildLoopFeedbackPrompt(observation: FixLoopObservation, context: {
211
+ round: number;
212
+ maxRounds: number;
213
+ targets: SecurityFindingSnapshot[];
214
+ }): string;
215
+ export declare function buildReproducePrompt(targets: RemediationFinding[], rounds: number, worktreeContext?: string): string;
216
+ export declare function buildReproduceFeedbackPrompt(problems: string[], context: {
217
+ attempt: number;
218
+ rounds: number;
219
+ }): string;
220
+ export declare const FIX_LOOP_LOG_VERSION = 2;
221
+ type FixLoopLogContext = {
222
+ startedAt: string;
223
+ finishedAt: string;
224
+ executor: FixExecutor;
225
+ maxRounds: number;
226
+ /** `total` counts every target asked for; the split counts the ones the loop attempted. */
227
+ targets: {
228
+ total: number;
229
+ dependency: number;
230
+ code: number;
231
+ };
232
+ };
233
+ /**
234
+ * One loop, as written to the round log. Version 1 logs lack the context
235
+ * fields and `stopRule`; readers treat those as unknown.
236
+ */
237
+ export type FixLoopLog = {
238
+ kind: 'dvalin-fix-loop';
239
+ schemaVersion: number;
240
+ id: string;
241
+ outcome: FixLoopOutcome;
242
+ stopRule?: FixLoopStopRule;
243
+ reason: string;
244
+ rounds: FixLoopRound[];
245
+ needsHuman: Array<{
246
+ ruleId: string;
247
+ path?: string;
248
+ reason: string;
249
+ }>;
250
+ reproduction: string | null;
251
+ evasion: string[];
252
+ recordHash: string | null;
253
+ } & Partial<FixLoopLogContext>;
254
+ export declare function defaultFixLoopDir(): string;
255
+ export {};