dvalincode 0.20.1 → 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.
- package/README.md +209 -4
- package/README.zh-CN.md +160 -4
- package/dist/agent/compact.d.ts +8 -0
- package/dist/agent/compact.js +44 -5
- package/dist/agent/compact.js.map +1 -1
- package/dist/agent/loop.d.ts +5 -0
- package/dist/agent/loop.js +16 -7
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/runner.d.ts +4 -3
- package/dist/agent/runner.js +81 -8
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/session.d.ts +7 -0
- package/dist/agent/session.js +27 -1
- package/dist/agent/session.js.map +1 -1
- package/dist/agent/types.d.ts +5 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/audit/log.d.ts +5 -1
- package/dist/audit/log.js.map +1 -1
- package/dist/commands/dvalin.d.ts +7 -1
- package/dist/commands/dvalin.js +209 -9
- package/dist/commands/dvalin.js.map +1 -1
- package/dist/commands/provider.js +2 -0
- package/dist/commands/provider.js.map +1 -1
- package/dist/commands/run.js +4 -2
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/security.d.ts +2 -0
- package/dist/commands/security.js +228 -14
- package/dist/commands/security.js.map +1 -1
- package/dist/core/policy.d.ts +15 -0
- package/dist/core/policy.js +115 -4
- package/dist/core/policy.js.map +1 -1
- package/dist/harness/run.d.ts +8 -2
- package/dist/harness/run.js +1 -1
- package/dist/harness/run.js.map +1 -1
- package/dist/mcp/server.js +5 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/providers/anthropic.js +14 -2
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/openaiCompatible.js +7 -6
- package/dist/providers/openaiCompatible.js.map +1 -1
- package/dist/providers/retry.d.ts +32 -0
- package/dist/providers/retry.js +150 -0
- package/dist/providers/retry.js.map +1 -0
- package/dist/providers/types.d.ts +10 -0
- package/dist/remediation/automate.d.ts +1 -1
- package/dist/remediation/automate.js +2 -1
- package/dist/remediation/automate.js.map +1 -1
- package/dist/remediation/codeQualityExport.d.ts +25 -0
- package/dist/remediation/codeQualityExport.js +24 -0
- package/dist/remediation/codeQualityExport.js.map +1 -0
- package/dist/remediation/evasion.d.ts +61 -0
- package/dist/remediation/evasion.js +190 -0
- package/dist/remediation/evasion.js.map +1 -0
- package/dist/remediation/fixLoop.d.ts +255 -0
- package/dist/remediation/fixLoop.js +639 -0
- package/dist/remediation/fixLoop.js.map +1 -0
- package/dist/remediation/fixLoopStats.d.ts +93 -0
- package/dist/remediation/fixLoopStats.js +244 -0
- package/dist/remediation/fixLoopStats.js.map +1 -0
- package/dist/remediation/rebase.d.ts +44 -0
- package/dist/remediation/rebase.js +114 -0
- package/dist/remediation/rebase.js.map +1 -0
- package/dist/remediation/reproduce.d.ts +47 -0
- package/dist/remediation/reproduce.js +75 -0
- package/dist/remediation/reproduce.js.map +1 -0
- package/dist/remediation/sarif.d.ts +4 -1
- package/dist/remediation/sarif.js +19 -1
- package/dist/remediation/sarif.js.map +1 -1
- package/dist/remediation/scannerSuite.d.ts +51 -3
- package/dist/remediation/scannerSuite.js +346 -87
- package/dist/remediation/scannerSuite.js.map +1 -1
- package/dist/remediation/verify.d.ts +8 -0
- package/dist/remediation/verify.js +24 -11
- package/dist/remediation/verify.js.map +1 -1
- package/dist/security/config.d.ts +8 -2
- package/dist/security/config.js +10 -3
- package/dist/security/config.js.map +1 -1
- package/dist/security/contracts.js +15 -0
- package/dist/security/contracts.js.map +1 -1
- package/dist/security/fixRecord.d.ts +103 -8
- package/dist/security/fixRecord.js +113 -11
- package/dist/security/fixRecord.js.map +1 -1
- package/dist/security/fixRecordFile.d.ts +11 -2
- package/dist/security/fixRecordFile.js +20 -2
- package/dist/security/fixRecordFile.js.map +1 -1
- package/dist/security/fixRecordSignature.d.ts +104 -0
- package/dist/security/fixRecordSignature.js +227 -0
- package/dist/security/fixRecordSignature.js.map +1 -0
- package/dist/security/guardedScan.d.ts +39 -0
- package/dist/security/guardedScan.js +45 -0
- package/dist/security/guardedScan.js.map +1 -0
- package/dist/security/onboarding.d.ts +28 -0
- package/dist/security/onboarding.js +124 -0
- package/dist/security/onboarding.js.map +1 -0
- package/dist/security/reproduceInCi.d.ts +44 -0
- package/dist/security/reproduceInCi.js +96 -0
- package/dist/security/reproduceInCi.js.map +1 -0
- package/dist/security/reverify.d.ts +130 -0
- package/dist/security/reverify.js +361 -0
- package/dist/security/reverify.js.map +1 -0
- package/dist/security/suppressionGuard.d.ts +58 -0
- package/dist/security/suppressionGuard.js +216 -0
- package/dist/security/suppressionGuard.js.map +1 -0
- package/dist/security/verifyRun.js +14 -3
- package/dist/security/verifyRun.js.map +1 -1
- package/dist/security/workflow.d.ts +11 -1
- package/dist/security/workflow.js +2 -0
- package/dist/security/workflow.js.map +1 -1
- package/dist/server/routes/config.js +2 -0
- package/dist/server/routes/config.js.map +1 -1
- package/dist/server/routes/remediation.js +6 -5
- package/dist/server/routes/remediation.js.map +1 -1
- package/dist/tools/editFile.js +9 -2
- package/dist/tools/editFile.js.map +1 -1
- package/dist/tools/registry.d.ts +4 -1
- package/dist/tools/registry.js +29 -9
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/runSecuritySuite.d.ts +3 -0
- package/dist/tools/runSecuritySuite.js +2 -2
- package/dist/tools/runSecuritySuite.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { mkdirSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { AuditSink } from '../audit/log.js';
|
|
9
|
+
import { sha256 } from '../audit/hash.js';
|
|
10
|
+
import { loadPolicy } from '../core/policy.js';
|
|
11
|
+
import { deriveCoverage, scannerIdForSource, securityProjectId, snapshotFinding, } from '../security/contracts.js';
|
|
12
|
+
import { blockingIntroduced, buildFixRecord, } from '../security/fixRecord.js';
|
|
13
|
+
import { introducedSince } from '../security/reverify.js';
|
|
14
|
+
import { describeSuppressionChange, detectSuppressionChanges, neutralizeSuppressions, } from '../security/suppressionGuard.js';
|
|
15
|
+
import { runDvalinScanSuite } from './scannerSuite.js';
|
|
16
|
+
import { runProjectVerification } from './verify.js';
|
|
17
|
+
import { describeEvasion, detectEvasion, evasionKey, isTestPath, toRecordEvasion } from './evasion.js';
|
|
18
|
+
import { classifyReproExit, hashFiles, reproCommand } from './reproduce.js';
|
|
19
|
+
import { buildConflictPrompt, syncWithUpstream } from './rebase.js';
|
|
20
|
+
const execFileAsync = promisify(execFile);
|
|
21
|
+
const MANIFEST = /(?:^|\/)(?:package(?:-lock)?\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|requirements[^/]*\.txt|Pipfile(?:\.lock)?|poetry\.lock|pyproject\.toml|go\.(?:mod|sum)|Cargo\.(?:toml|lock)|Gemfile(?:\.lock)?|composer\.(?:json|lock)|pom\.xml|build\.gradle(?:\.kts)?|gradle\.lockfile|packages\.lock\.json|[^/]+\.csproj)$/i;
|
|
22
|
+
/** Advisory wording that means no release fixes it — an upgrade loop cannot converge. */
|
|
23
|
+
const NO_FIX = /no (?:upgrade|patch|fix|remediation)(?: or patch)?(?: path| version)? (?:is )?available|no fixed version|not fixed in any version|fixed version:? none/i;
|
|
24
|
+
export function classifyTarget(finding) {
|
|
25
|
+
const engine = finding.scanner ?? scannerIdForSource(finding.source);
|
|
26
|
+
if (engine === 'snyk-oss' || engine === 'osv-scanner')
|
|
27
|
+
return 'dependency';
|
|
28
|
+
return MANIFEST.test(finding.path) ? 'dependency' : 'code';
|
|
29
|
+
}
|
|
30
|
+
/** Why a target should go to a person instead of the loop, or undefined if the loop should try. */
|
|
31
|
+
export function notAutoFixableReason(finding) {
|
|
32
|
+
if (classifyTarget(finding) === 'dependency' && NO_FIX.test(finding.message)) {
|
|
33
|
+
return 'no fixed version of this dependency is available; it needs a risk decision or a replacement, not an upgrade';
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
export async function runFixLoop(original) {
|
|
38
|
+
// A copy, because a rebase moves the base every later step is measured from.
|
|
39
|
+
const input = { ...original };
|
|
40
|
+
const startedAt = new Date();
|
|
41
|
+
const id = `fixloop-${startedAt.toISOString().replace(/[:.]/g, '-')}-${randomUUID().slice(0, 8)}`;
|
|
42
|
+
const needsHuman = [];
|
|
43
|
+
const targets = [];
|
|
44
|
+
for (const finding of input.targets) {
|
|
45
|
+
const reason = notAutoFixableReason(finding);
|
|
46
|
+
if (reason)
|
|
47
|
+
needsHuman.push({ finding: snapshotFinding(finding), reason });
|
|
48
|
+
else
|
|
49
|
+
targets.push(finding);
|
|
50
|
+
}
|
|
51
|
+
// Dependencies first: their fix is close to deterministic, and an upgrade
|
|
52
|
+
// can move code findings too.
|
|
53
|
+
targets.sort((a, b) => Number(classifyTarget(b) === 'dependency') - Number(classifyTarget(a) === 'dependency'));
|
|
54
|
+
const finish = (result) => {
|
|
55
|
+
const full = { id, needsHuman, ...result };
|
|
56
|
+
full.logPath = writeLoopLog(full, {
|
|
57
|
+
startedAt: startedAt.toISOString(),
|
|
58
|
+
finishedAt: new Date().toISOString(),
|
|
59
|
+
executor: input.executorLabel,
|
|
60
|
+
maxRounds: input.maxRounds,
|
|
61
|
+
targets: {
|
|
62
|
+
total: input.targets.length,
|
|
63
|
+
dependency: targets.filter(target => classifyTarget(target) === 'dependency').length,
|
|
64
|
+
code: targets.filter(target => classifyTarget(target) === 'code').length,
|
|
65
|
+
},
|
|
66
|
+
}, input.logDir);
|
|
67
|
+
return full;
|
|
68
|
+
};
|
|
69
|
+
if (!targets.length) {
|
|
70
|
+
return finish({
|
|
71
|
+
outcome: 'not-auto-fixable',
|
|
72
|
+
stopRule: 'nothing-fixable',
|
|
73
|
+
reason: `none of the ${input.targets.length} target(s) can be fixed by an edit; they need a person`,
|
|
74
|
+
rounds: [],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const audit = new AuditSink(id);
|
|
78
|
+
const policy = loadPolicy(input.cwd);
|
|
79
|
+
audit.append({
|
|
80
|
+
type: 'run_start',
|
|
81
|
+
task: `security fix loop over ${targets.length} target(s), at most ${input.maxRounds} round(s)`,
|
|
82
|
+
mode: 'security-verify',
|
|
83
|
+
provider: 'none',
|
|
84
|
+
model: 'none',
|
|
85
|
+
cwd: input.cwd,
|
|
86
|
+
gitHead: input.baseCommit,
|
|
87
|
+
policyHash: policy.hash,
|
|
88
|
+
});
|
|
89
|
+
const targetSnapshots = targets.map(snapshotFinding);
|
|
90
|
+
let baselineSnapshots = input.baseline.map(snapshotFinding);
|
|
91
|
+
const rounds = [];
|
|
92
|
+
let session;
|
|
93
|
+
let previous;
|
|
94
|
+
let best = Number.POSITIVE_INFINITY;
|
|
95
|
+
let roundsWithoutImprovement = 0;
|
|
96
|
+
let status = 'done';
|
|
97
|
+
let result;
|
|
98
|
+
let repro;
|
|
99
|
+
/** Rebase onto upstream if it moved. Conflicts go to the executor, conflicts only. */
|
|
100
|
+
const sync = async () => {
|
|
101
|
+
if (!input.rebase)
|
|
102
|
+
return {};
|
|
103
|
+
const onto = input.rebase.onto;
|
|
104
|
+
const outcome = await syncWithUpstream({
|
|
105
|
+
cwd: input.cwd,
|
|
106
|
+
baseCommit: input.baseCommit,
|
|
107
|
+
onto,
|
|
108
|
+
maxConflictRounds: input.rebase.maxConflictRounds,
|
|
109
|
+
resolveConflicts: async (files, attempt) => {
|
|
110
|
+
const turn = await input.executor.run({ prompt: buildConflictPrompt(onto, files, attempt), cwd: input.cwd, resume: session, provider: input.provider }, input.onExecutorEvent);
|
|
111
|
+
session = turn.session ?? session;
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
if (outcome.status === 'conflict')
|
|
115
|
+
return { conflict: outcome };
|
|
116
|
+
if (outcome.status === 'up-to-date')
|
|
117
|
+
return {};
|
|
118
|
+
input.baseCommit = outcome.base;
|
|
119
|
+
baselineSnapshots = (await scanAt(input, outcome.base)).findings.map(snapshotFinding);
|
|
120
|
+
return { rebased: { from: outcome.from, to: outcome.to, conflicts: outcome.conflicts } };
|
|
121
|
+
};
|
|
122
|
+
const conflictStop = (conflict) => finish({
|
|
123
|
+
outcome: 'rebase-conflict',
|
|
124
|
+
stopRule: 'rebase-conflict',
|
|
125
|
+
reason: `${conflict.detail}: ${conflict.files.join(', ') || 'unknown files'} — a person has to rebase this change; the working tree is as it was before the rebase`,
|
|
126
|
+
rounds,
|
|
127
|
+
session,
|
|
128
|
+
});
|
|
129
|
+
try {
|
|
130
|
+
// Start from the current base, so the executor's first edit is not
|
|
131
|
+
// already behind.
|
|
132
|
+
const initial = await sync();
|
|
133
|
+
if (initial.conflict)
|
|
134
|
+
return conflictStop(initial.conflict);
|
|
135
|
+
const codeTargets = targets.filter(target => classifyTarget(target) === 'code');
|
|
136
|
+
if (input.reproduce && codeTargets.length) {
|
|
137
|
+
let problems = [];
|
|
138
|
+
for (let attempt = 1; attempt <= input.reproduce.rounds; attempt++) {
|
|
139
|
+
const startedAt = Date.now();
|
|
140
|
+
const prompt = attempt === 1
|
|
141
|
+
? buildReproducePrompt(codeTargets, input.reproduce.rounds, input.worktreeContext)
|
|
142
|
+
: buildReproduceFeedbackPrompt(problems, { attempt, rounds: input.reproduce.rounds });
|
|
143
|
+
const turn = await input.executor.run({ prompt, cwd: input.cwd, resume: session, provider: input.provider }, input.onExecutorEvent);
|
|
144
|
+
session = turn.session ?? session;
|
|
145
|
+
const attemptResult = await attemptReproduction(input, input.reproduce.runner, audit);
|
|
146
|
+
problems = attemptResult.problems;
|
|
147
|
+
const summary = {
|
|
148
|
+
phase: 'reproduce',
|
|
149
|
+
round: attempt,
|
|
150
|
+
durationMs: Date.now() - startedAt,
|
|
151
|
+
remaining: targetSnapshots.length,
|
|
152
|
+
blockingIntroduced: 0,
|
|
153
|
+
failedChecks: [],
|
|
154
|
+
suppressions: 0,
|
|
155
|
+
evasion: 0,
|
|
156
|
+
open: problems.length,
|
|
157
|
+
fixed: 0,
|
|
158
|
+
problems,
|
|
159
|
+
};
|
|
160
|
+
rounds.push(summary);
|
|
161
|
+
input.onReproduceRound?.(summary);
|
|
162
|
+
if (!problems.length) {
|
|
163
|
+
repro = attemptResult.state;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!repro) {
|
|
168
|
+
return finish({
|
|
169
|
+
outcome: 'not-reproduced',
|
|
170
|
+
stopRule: 'not-reproduced',
|
|
171
|
+
reason: `after ${input.reproduce.rounds} attempt(s) no test failed on the vulnerable code (${problems.join('; ')}); the finding may be a false positive or unreachable — a person should triage it before anything is fixed`,
|
|
172
|
+
rounds,
|
|
173
|
+
session,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
for (let round = 1; round <= input.maxRounds; round++) {
|
|
178
|
+
const startedAt = Date.now();
|
|
179
|
+
const prompt = round === 1
|
|
180
|
+
? buildLoopInitialPrompt(targets, input.maxRounds, input.worktreeContext, repro?.tests.map(test => test.path))
|
|
181
|
+
: buildLoopFeedbackPrompt(previous, { round, maxRounds: input.maxRounds, targets: targetSnapshots });
|
|
182
|
+
const turn = await input.executor.run({ prompt, cwd: input.cwd, resume: session, provider: input.provider }, input.onExecutorEvent);
|
|
183
|
+
session = turn.session ?? session;
|
|
184
|
+
// Judged on today's base, not the one the edit started from.
|
|
185
|
+
const synced = await sync();
|
|
186
|
+
if (synced.conflict)
|
|
187
|
+
return conflictStop(synced.conflict);
|
|
188
|
+
const mode = input.fullScanEveryRound ? 'full' : 'narrowed';
|
|
189
|
+
let observation = await observe(input, targetSnapshots, baselineSnapshots, audit, repro, { mode });
|
|
190
|
+
const scan = { mode: observation.scan.narrowed ? 'narrowed' : 'full', durationMs: observation.scanMs };
|
|
191
|
+
let stop = decide(observation, previous, { round, maxRounds: input.maxRounds, best, roundsWithoutImprovement });
|
|
192
|
+
// A narrowed scan steers the executor; it never decides. Any stop it
|
|
193
|
+
// would cause is re-judged on a full scan of the same tree, and only
|
|
194
|
+
// that one is recorded.
|
|
195
|
+
if (stop && observation.scan.narrowed) {
|
|
196
|
+
const full = await observe(input, targetSnapshots, baselineSnapshots, audit, repro, { mode: 'full', reuse: observation });
|
|
197
|
+
const fullStop = decide(full, previous, { round, maxRounds: input.maxRounds, best, roundsWithoutImprovement });
|
|
198
|
+
scan.confirmed = true;
|
|
199
|
+
scan.decisionChanged = fullStop?.outcome !== stop.outcome || fullStop?.rule !== stop.rule;
|
|
200
|
+
scan.durationMs += full.scanMs;
|
|
201
|
+
observation = full;
|
|
202
|
+
stop = fullStop;
|
|
203
|
+
}
|
|
204
|
+
const fixed = targetSnapshots.length - observation.remaining.length;
|
|
205
|
+
const summary = {
|
|
206
|
+
phase: 'fix',
|
|
207
|
+
round,
|
|
208
|
+
durationMs: Date.now() - startedAt,
|
|
209
|
+
remaining: observation.remaining.length,
|
|
210
|
+
blockingIntroduced: observation.blocking.length,
|
|
211
|
+
failedChecks: observation.checks.filter(check => !check.passed).map(check => check.kind),
|
|
212
|
+
suppressions: observation.suppressions.length,
|
|
213
|
+
evasion: observation.evasion.length,
|
|
214
|
+
open: observation.open.length,
|
|
215
|
+
fixed,
|
|
216
|
+
...(synced.rebased ? { rebased: synced.rebased } : {}),
|
|
217
|
+
scan,
|
|
218
|
+
};
|
|
219
|
+
rounds.push(summary);
|
|
220
|
+
input.onRound?.(summary, observation);
|
|
221
|
+
if (observation.open.length < best) {
|
|
222
|
+
best = observation.open.length;
|
|
223
|
+
roundsWithoutImprovement = 0;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
roundsWithoutImprovement += 1;
|
|
227
|
+
}
|
|
228
|
+
previous = observation;
|
|
229
|
+
if (stop) {
|
|
230
|
+
const reproduction = repro ? reproductionEvidence(repro, observation) : undefined;
|
|
231
|
+
result = finish({
|
|
232
|
+
outcome: stop.outcome,
|
|
233
|
+
reason: stop.reason,
|
|
234
|
+
stopRule: stop.rule,
|
|
235
|
+
rounds,
|
|
236
|
+
final: observation,
|
|
237
|
+
record: await issueRecord(input, targetSnapshots, observation, audit, reproduction),
|
|
238
|
+
...(reproduction ? { reproduction } : {}),
|
|
239
|
+
session,
|
|
240
|
+
});
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
status = 'error';
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
audit.append({ type: 'run_end', status, iterations: rounds.length, warnings: audit.getWarnings() });
|
|
251
|
+
}
|
|
252
|
+
// `decide` always stops on the last round, so the loop never falls through.
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
/** The stop rule. Exported because it is the policy, and the policy is what should be tested. */
|
|
256
|
+
export function decide(observation, previous, state) {
|
|
257
|
+
if (!observation.open.length)
|
|
258
|
+
return { outcome: 'verified', rule: 'clean', reason: 'every target is gone, nothing blocking was introduced, and every check passed' };
|
|
259
|
+
if (observation.incompleteEngines.length) {
|
|
260
|
+
return {
|
|
261
|
+
outcome: 'unverifiable',
|
|
262
|
+
rule: 'engine-incomplete',
|
|
263
|
+
reason: `${observation.incompleteEngines.join(', ')} did not complete, so the targets it finds cannot be confirmed gone; fix the engine, not the code`,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (!observation.checks.length) {
|
|
267
|
+
return { outcome: 'unverifiable', rule: 'no-checks', reason: 'no project check could be run, so no repair can be verified; name one with --verify-command' };
|
|
268
|
+
}
|
|
269
|
+
if (previous && sameSet(observation.open, previous.open)) {
|
|
270
|
+
return { outcome: 'stalled', rule: 'no-change', reason: `round ${state.round} left exactly the same ${observation.open.length} problem(s) open as the round before` };
|
|
271
|
+
}
|
|
272
|
+
// Two rounds in a row that do not beat the best so far: the loop is
|
|
273
|
+
// oscillating — fixing one thing and breaking another — not converging.
|
|
274
|
+
if (observation.open.length >= state.best && state.roundsWithoutImprovement >= 1) {
|
|
275
|
+
return { outcome: 'stalled', rule: 'oscillating', reason: `the open problems have not dropped below ${state.best} for two rounds` };
|
|
276
|
+
}
|
|
277
|
+
if (state.round >= state.maxRounds) {
|
|
278
|
+
return { outcome: 'budget-exhausted', rule: 'budget', reason: `${observation.open.length} problem(s) still open after ${state.maxRounds} round(s)` };
|
|
279
|
+
}
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
async function observe(input, targets, baseline, audit, repro, options) {
|
|
283
|
+
const scan = input.runScan ?? runDvalinScanSuite;
|
|
284
|
+
const suppressions = options.reuse?.suppressions ?? await detectSuppressionChanges(input.cwd, input.baseCommit);
|
|
285
|
+
const narrow = options.mode === 'narrowed' ? { files: await narrowedFiles(input.cwd, input.baseCommit, targets) } : undefined;
|
|
286
|
+
const scanOptions = { scanners: input.scanners, timeoutMs: input.timeoutMs, ...(narrow ? { narrow } : {}) };
|
|
287
|
+
const scanStarted = Date.now();
|
|
288
|
+
let result;
|
|
289
|
+
if (suppressions.length) {
|
|
290
|
+
const neutral = await neutralizeSuppressions(input.cwd, input.baseCommit, suppressions);
|
|
291
|
+
try {
|
|
292
|
+
result = await scan(neutral.root, scanOptions);
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
await neutral.cleanup();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
result = await scan(input.cwd, scanOptions);
|
|
300
|
+
}
|
|
301
|
+
const scanMs = Date.now() - scanStarted;
|
|
302
|
+
let checkRun;
|
|
303
|
+
let reproTampered;
|
|
304
|
+
let evasion;
|
|
305
|
+
let hasChanges;
|
|
306
|
+
if (options.reuse) {
|
|
307
|
+
checkRun = { evidence: options.reuse.checks, outputTails: options.reuse.checkTails };
|
|
308
|
+
reproTampered = options.reuse.reproTampered;
|
|
309
|
+
evasion = options.reuse.evasion;
|
|
310
|
+
hasChanges = options.reuse.hasChanges;
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
const projectChecks = input.runChecks
|
|
314
|
+
? await input.runChecks(input.cwd)
|
|
315
|
+
: await runProjectVerification({
|
|
316
|
+
cwd: input.cwd,
|
|
317
|
+
commands: input.verifyCommands?.length ? input.verifyCommands : undefined,
|
|
318
|
+
timeoutMs: input.timeoutMs,
|
|
319
|
+
audit,
|
|
320
|
+
});
|
|
321
|
+
checkRun = { evidence: [...projectChecks.evidence], outputTails: [...projectChecks.outputTails] };
|
|
322
|
+
// The reproduction tests, run as a check that must pass like any other, and
|
|
323
|
+
// compared byte-for-byte with what was shown to fail.
|
|
324
|
+
reproTampered = [];
|
|
325
|
+
if (repro) {
|
|
326
|
+
const now = await hashFiles(input.cwd, repro.tests.map(test => test.path));
|
|
327
|
+
for (const [index, test] of now.entries()) {
|
|
328
|
+
if (test.sha256 !== repro.tests[index].sha256)
|
|
329
|
+
reproTampered.push(test.path);
|
|
330
|
+
}
|
|
331
|
+
const run = await runRepro(input, repro.command, audit);
|
|
332
|
+
checkRun.evidence.push({ kind: 'reproduce', command: repro.command, exitCode: run.exitCode, passed: classifyReproExit(repro.runner, run.exitCode, run.tail) === 'passed' });
|
|
333
|
+
checkRun.outputTails.push(run.tail);
|
|
334
|
+
}
|
|
335
|
+
evasion = await detectEvasion(input.cwd, input.baseCommit, targets, { exempt: repro?.tests.map(test => test.path) });
|
|
336
|
+
hasChanges = Boolean((await git(input.cwd, ['status', '--porcelain'])).trim())
|
|
337
|
+
|| Boolean((await git(input.cwd, ['diff', '--name-only', input.baseCommit]).catch(() => '')).trim());
|
|
338
|
+
}
|
|
339
|
+
const current = result.findings.map(snapshotFinding);
|
|
340
|
+
const present = new Set(current.map(finding => finding.targetFingerprint));
|
|
341
|
+
const remaining = targets.filter(target => present.has(target.targetFingerprint));
|
|
342
|
+
const introduced = introducedSince(baseline, current);
|
|
343
|
+
const blocking = blockingIntroduced(introduced, { threshold: input.threshold, mode: 'new' });
|
|
344
|
+
const completed = new Set(result.scanners.filter(run => run.status === 'completed').map(run => run.id));
|
|
345
|
+
const incompleteEngines = [...new Set(targets
|
|
346
|
+
.map(target => target.scanner ?? scannerIdForSource(target.source))
|
|
347
|
+
.filter((engine) => Boolean(engine))
|
|
348
|
+
.filter(engine => !completed.has(engine)))];
|
|
349
|
+
const open = [
|
|
350
|
+
...remaining.map(finding => `target:${finding.targetFingerprint}`),
|
|
351
|
+
...blocking.map(finding => `introduced:${finding.fingerprint}`),
|
|
352
|
+
...checkRun.evidence.filter(check => !check.passed).map(check => `check:${check.kind}:${check.command}`),
|
|
353
|
+
...suppressions.map(change => `suppression:${describeSuppressionChange(change)}`),
|
|
354
|
+
...evasion.map(evasionKey),
|
|
355
|
+
...reproTampered.map(file => `reproduction-changed:${file}`),
|
|
356
|
+
...(checkRun.evidence.length ? [] : ['checks:none']),
|
|
357
|
+
...incompleteEngines.map(engine => `engine:${engine}`),
|
|
358
|
+
].sort();
|
|
359
|
+
return {
|
|
360
|
+
scan: result,
|
|
361
|
+
scanMs,
|
|
362
|
+
checks: checkRun.evidence,
|
|
363
|
+
checkTails: checkRun.outputTails,
|
|
364
|
+
suppressions,
|
|
365
|
+
remaining,
|
|
366
|
+
introduced,
|
|
367
|
+
blocking,
|
|
368
|
+
incompleteEngines,
|
|
369
|
+
evasion,
|
|
370
|
+
reproTampered,
|
|
371
|
+
hasChanges,
|
|
372
|
+
open,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* What a narrowed round rescans: every file changed since the base (new files
|
|
377
|
+
* included), and every file a target sits in — a target in a file the change
|
|
378
|
+
* never touched must still be seen, not mistaken for fixed. Paths are relative
|
|
379
|
+
* to the workspace, as findings are.
|
|
380
|
+
*/
|
|
381
|
+
async function narrowedFiles(cwd, baseCommit, targets) {
|
|
382
|
+
const changed = await git(cwd, ['diff', '--name-only', '--relative', '--diff-filter=d', baseCommit]).catch(() => '');
|
|
383
|
+
const untracked = await git(cwd, ['ls-files', '--others', '--exclude-standard']).catch(() => '');
|
|
384
|
+
return [...new Set([
|
|
385
|
+
...`${changed}\n${untracked}`.split('\n').map(line => line.trim()).filter(Boolean),
|
|
386
|
+
...targets.map(target => target.path).filter(Boolean),
|
|
387
|
+
])].sort();
|
|
388
|
+
}
|
|
389
|
+
export function buildLoopInitialPrompt(targets, maxRounds, worktreeContext, reproTests) {
|
|
390
|
+
const dependencies = targets.filter(target => classifyTarget(target) === 'dependency');
|
|
391
|
+
const code = targets.filter(target => classifyTarget(target) === 'code');
|
|
392
|
+
const list = (findings, offset) => findings.map((finding, index) => [
|
|
393
|
+
`${offset + index + 1}. ${finding.source} / ${finding.ruleId}`,
|
|
394
|
+
` ${finding.path}${finding.startLine ? `:${finding.startLine}` : ''}`,
|
|
395
|
+
` ${finding.message}`,
|
|
396
|
+
].join('\n'));
|
|
397
|
+
return [
|
|
398
|
+
'Fix the security findings below. Dvalin will re-scan and run the project checks itself after you finish, and send back only what is still wrong.',
|
|
399
|
+
`You have at most ${maxRounds} round(s). Stopping early with an honest account is better than a patch that hides a finding.`,
|
|
400
|
+
worktreeContext ?? '',
|
|
401
|
+
'',
|
|
402
|
+
...(dependencies.length ? ['Vulnerable dependencies:', ...list(dependencies, 0), ''] : []),
|
|
403
|
+
...(code.length ? ['Code findings:', ...list(code, dependencies.length), ''] : []),
|
|
404
|
+
...(reproTests?.length ? [
|
|
405
|
+
`These tests reproduce the code findings and fail on the current code: ${reproTests.join(', ')}. Make them pass by fixing the code. Do not edit them — they are compared byte-for-byte.`,
|
|
406
|
+
'',
|
|
407
|
+
] : []),
|
|
408
|
+
'Rules:',
|
|
409
|
+
...(dependencies.length ? [
|
|
410
|
+
'- Dependencies: upgrade to the lowest version that fixes the advisory (the message usually names it) using the project\'s package manager, so the lockfile is regenerated rather than hand-edited. Upgrade the direct dependency that pulls in a vulnerable transitive one. Remove a dependency only if it is unused.',
|
|
411
|
+
] : []),
|
|
412
|
+
...(code.length ? [
|
|
413
|
+
'- Code: validate each finding against reachable data flow, then fix the cause with the smallest behavior-preserving change. Rewriting the sink into a form the rule does not match is not a fix.',
|
|
414
|
+
] : []),
|
|
415
|
+
'- Never add a scanner suppression (.snyk, .semgrepignore, .trivyignore, // deepcode ignore, nosemgrep, nosec, NOSONAR) and never weaken or delete tests. Suppressions are undone before each scan and count against you.',
|
|
416
|
+
'- Do not delete the vulnerable file or feature to make a finding disappear, and do not move the dangerous call into a sibling (eval → new Function, exec → spawn with shell: true). Both are detected and not accepted.',
|
|
417
|
+
'- Run the focused checks for what you changed. Do not commit, push, or open a pull request.',
|
|
418
|
+
'Finish with a short summary: what you changed, and any finding you believe is a false positive and why.',
|
|
419
|
+
].filter(line => line !== '').join('\n');
|
|
420
|
+
}
|
|
421
|
+
/** Only the delta: what is still open and why. The executor never sees a verdict it could argue with. */
|
|
422
|
+
export function buildLoopFeedbackPrompt(observation, context) {
|
|
423
|
+
const where = (finding) => `${finding.path}${finding.startLine ? `:${finding.startLine}` : ''}`;
|
|
424
|
+
const lines = [
|
|
425
|
+
`Round ${context.round} of ${context.maxRounds}. Dvalin re-scanned and ran the checks itself after your last change. ${context.targets.length - observation.remaining.length} of ${context.targets.length} target(s) are now gone — do not regress them. Still open:`,
|
|
426
|
+
];
|
|
427
|
+
if (observation.remaining.length) {
|
|
428
|
+
lines.push('', `Still present (${observation.remaining.length}):`);
|
|
429
|
+
for (const finding of observation.remaining)
|
|
430
|
+
lines.push(`- ${finding.source} / ${finding.ruleId} at ${where(finding)}: ${finding.message}`);
|
|
431
|
+
}
|
|
432
|
+
if (observation.blocking.length) {
|
|
433
|
+
lines.push('', `Introduced by your change (${observation.blocking.length}) — these did not exist before:`);
|
|
434
|
+
for (const finding of observation.blocking)
|
|
435
|
+
lines.push(`- ${finding.source} / ${finding.ruleId} at ${where(finding)}: ${finding.message}`);
|
|
436
|
+
}
|
|
437
|
+
const failed = observation.checks.map((check, index) => ({ check, tail: observation.checkTails[index] ?? '' })).filter(entry => !entry.check.passed);
|
|
438
|
+
if (failed.length) {
|
|
439
|
+
lines.push('', `Checks failing (${failed.length}):`);
|
|
440
|
+
for (const { check, tail } of failed) {
|
|
441
|
+
lines.push(`- ${check.kind}: \`${check.command}\` exited ${check.exitCode ?? 'without an exit code'}`);
|
|
442
|
+
if (tail.trim())
|
|
443
|
+
lines.push('```', tail.trim(), '```');
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (observation.suppressions.length) {
|
|
447
|
+
lines.push('', `Suppressions you added (${observation.suppressions.length}) — they were ignored when scanning and must be removed:`);
|
|
448
|
+
for (const change of observation.suppressions)
|
|
449
|
+
lines.push(`- ${describeSuppressionChange(change)}`);
|
|
450
|
+
}
|
|
451
|
+
if (observation.evasion.length) {
|
|
452
|
+
lines.push('', `Not accepted as fixes (${observation.evasion.length}) — each hides a finding rather than removing it:`);
|
|
453
|
+
for (const signal of observation.evasion)
|
|
454
|
+
lines.push(`- ${describeEvasion(signal)}`);
|
|
455
|
+
}
|
|
456
|
+
if (observation.reproTampered.length) {
|
|
457
|
+
lines.push('', `Reproduction tests you changed (${observation.reproTampered.length}) — restore them exactly; the fix has to make them pass as they were written:`);
|
|
458
|
+
for (const file of observation.reproTampered)
|
|
459
|
+
lines.push(`- ${file}`);
|
|
460
|
+
}
|
|
461
|
+
if (!observation.hasChanges)
|
|
462
|
+
lines.push('', 'Your last turn left no change in the working tree.');
|
|
463
|
+
lines.push('', 'Fix what is listed, then stop. Same rules as before: no suppressions, no weakened tests, no commits.');
|
|
464
|
+
return lines.join('\n');
|
|
465
|
+
}
|
|
466
|
+
/** Scan a commit in a throwaway worktree, at the same subdirectory as the workspace. */
|
|
467
|
+
async function scanAt(input, commit) {
|
|
468
|
+
const repoRoot = (await git(input.cwd, ['rev-parse', '--show-toplevel'])).trim();
|
|
469
|
+
const prefix = (await git(input.cwd, ['rev-parse', '--show-prefix'])).trim();
|
|
470
|
+
const scratch = await mkdtemp(path.join(os.tmpdir(), 'dvalin-rebase-base-'));
|
|
471
|
+
const tree = path.join(scratch, 'tree');
|
|
472
|
+
try {
|
|
473
|
+
await git(repoRoot, ['worktree', 'add', '--detach', '--quiet', tree, commit]);
|
|
474
|
+
return await (input.runScan ?? runDvalinScanSuite)(path.join(tree, prefix), { scanners: input.scanners, timeoutMs: input.timeoutMs });
|
|
475
|
+
}
|
|
476
|
+
finally {
|
|
477
|
+
await git(repoRoot, ['worktree', 'remove', '--force', tree]).catch(() => undefined);
|
|
478
|
+
await rm(scratch, { recursive: true, force: true }).catch(() => undefined);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* One reproduction attempt, judged here: tests only, at least one, and they
|
|
483
|
+
* fail on the code as it is — by a failing test, not a broken runner.
|
|
484
|
+
*/
|
|
485
|
+
async function attemptReproduction(input, runner, audit) {
|
|
486
|
+
const tracked = (await git(input.cwd, ['diff', '--name-only', '--relative', input.baseCommit])).split('\n').filter(Boolean);
|
|
487
|
+
const untracked = (await git(input.cwd, ['ls-files', '--others', '--exclude-standard'])).split('\n').filter(Boolean);
|
|
488
|
+
const deleted = new Set((await git(input.cwd, ['diff', '--name-only', '--diff-filter=D', '--relative', input.baseCommit])).split('\n').filter(Boolean));
|
|
489
|
+
const changed = [...new Set([...tracked, ...untracked])].filter(file => !deleted.has(file)).sort();
|
|
490
|
+
const tests = changed.filter(isTestPath);
|
|
491
|
+
const nonTest = [...changed.filter(file => !isTestPath(file)), ...deleted];
|
|
492
|
+
const problems = [];
|
|
493
|
+
if (nonTest.length)
|
|
494
|
+
problems.push(`only tests may change in this phase, but these did: ${nonTest.join(', ')} — revert them`);
|
|
495
|
+
if (!tests.length) {
|
|
496
|
+
problems.push('no test file was added or changed');
|
|
497
|
+
return { problems };
|
|
498
|
+
}
|
|
499
|
+
const command = reproCommand(runner.template, tests);
|
|
500
|
+
const run = await runRepro(input, command, audit);
|
|
501
|
+
const outcome = classifyReproExit(runner, run.exitCode, run.tail);
|
|
502
|
+
if (outcome === 'passed')
|
|
503
|
+
problems.push(`\`${command}\` passed on the vulnerable code, so the tests do not reproduce the finding`);
|
|
504
|
+
if (outcome === 'error')
|
|
505
|
+
problems.push(`\`${command}\` did not reach a failing test (exit ${run.exitCode ?? 'none'}): ${run.tail.split('\n').slice(-5).join(' ').slice(0, 400)}`);
|
|
506
|
+
if (problems.length)
|
|
507
|
+
return { problems };
|
|
508
|
+
return {
|
|
509
|
+
problems,
|
|
510
|
+
state: { runner, command, tests: await hashFiles(input.cwd, tests), before: { exitCode: run.exitCode } },
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
async function runRepro(input, command, audit) {
|
|
514
|
+
if (input.runRepro)
|
|
515
|
+
return input.runRepro(input.cwd, command);
|
|
516
|
+
const run = await runProjectVerification({ cwd: input.cwd, commands: [command], timeoutMs: input.timeoutMs, audit });
|
|
517
|
+
return { exitCode: run.evidence[0]?.exitCode ?? null, tail: run.outputTails[0] ?? '' };
|
|
518
|
+
}
|
|
519
|
+
function reproductionEvidence(repro, observation) {
|
|
520
|
+
const after = observation.checks.find(check => check.kind === 'reproduce');
|
|
521
|
+
const flipped = Boolean(after?.passed) && !observation.reproTampered.length;
|
|
522
|
+
return {
|
|
523
|
+
status: flipped ? 'reproduced' : 'failed-before-fix',
|
|
524
|
+
command: repro.command,
|
|
525
|
+
tests: repro.tests,
|
|
526
|
+
before: repro.before,
|
|
527
|
+
...(after ? { after: { exitCode: after.exitCode } } : {}),
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
export function buildReproducePrompt(targets, rounds, worktreeContext) {
|
|
531
|
+
return [
|
|
532
|
+
'Before anything is fixed, demonstrate the code findings below with tests. Do NOT fix them yet.',
|
|
533
|
+
worktreeContext ?? '',
|
|
534
|
+
'',
|
|
535
|
+
...targets.map((finding, index) => [
|
|
536
|
+
`${index + 1}. ${finding.source} / ${finding.ruleId}`,
|
|
537
|
+
` ${finding.path}${finding.startLine ? `:${finding.startLine}` : ''}`,
|
|
538
|
+
` ${finding.message}`,
|
|
539
|
+
].join('\n')),
|
|
540
|
+
'',
|
|
541
|
+
'Write focused security regression tests in the project\'s existing test framework and test directory:',
|
|
542
|
+
'- Drive the vulnerable entry point with a malicious input (an injection payload, a traversal path, a script tag) and assert the safe behavior — the input is rejected, escaped, or not executed.',
|
|
543
|
+
'- The tests must FAIL on the current code because the vulnerability is real, not because something is missing: do not import functions that do not exist yet.',
|
|
544
|
+
'- Change test files only. Dvalin will run just these tests on the current code and require them to fail.',
|
|
545
|
+
`- You have ${rounds} attempt(s). If a finding cannot be demonstrated — unreachable code, a false positive — say so and why; that is a valid answer.`,
|
|
546
|
+
'Finish with the test file paths and, per finding, the payload you used.',
|
|
547
|
+
].filter(line => line !== '').join('\n');
|
|
548
|
+
}
|
|
549
|
+
export function buildReproduceFeedbackPrompt(problems, context) {
|
|
550
|
+
return [
|
|
551
|
+
`Reproduction attempt ${context.attempt} of ${context.rounds}. Dvalin ran your tests on the current code. Not yet a reproduction:`,
|
|
552
|
+
...problems.map(problem => `- ${problem}`),
|
|
553
|
+
'',
|
|
554
|
+
'Adjust the tests (tests only, no fixes) so they fail on the current code because of the vulnerability.',
|
|
555
|
+
].join('\n');
|
|
556
|
+
}
|
|
557
|
+
async function issueRecord(input, targets, observation, audit, reproduction) {
|
|
558
|
+
return buildFixRecord({
|
|
559
|
+
projectId: securityProjectId(input.cwd),
|
|
560
|
+
executor: input.executorLabel,
|
|
561
|
+
before: {
|
|
562
|
+
scanId: input.before.id,
|
|
563
|
+
completedAt: input.before.completedAt,
|
|
564
|
+
coverage: deriveCoverage(input.before),
|
|
565
|
+
targets,
|
|
566
|
+
},
|
|
567
|
+
after: {
|
|
568
|
+
scanId: observation.scan.id,
|
|
569
|
+
completedAt: observation.scan.completedAt,
|
|
570
|
+
coverage: deriveCoverage(observation.scan),
|
|
571
|
+
remainingTargets: observation.remaining,
|
|
572
|
+
},
|
|
573
|
+
regression: { gate: { threshold: input.threshold, mode: 'new' }, introduced: observation.introduced },
|
|
574
|
+
evasion: observation.evasion.map(toRecordEvasion),
|
|
575
|
+
...(await changesSince(input.cwd, input.baseCommit)),
|
|
576
|
+
checks: observation.checks,
|
|
577
|
+
...(reproduction ? { reproduction } : {}),
|
|
578
|
+
audit: { runId: audit.runId, headHash: audit.head() },
|
|
579
|
+
policyHash: loadPolicy(input.cwd).hash,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
async function changesSince(cwd, baseCommit) {
|
|
583
|
+
try {
|
|
584
|
+
const tracked = (await git(cwd, ['diff', '--name-only', baseCommit])).split('\n').filter(Boolean);
|
|
585
|
+
const untracked = (await git(cwd, ['ls-files', '--others', '--exclude-standard'])).split('\n').filter(Boolean);
|
|
586
|
+
const files = [...new Set([...tracked, ...untracked])].sort();
|
|
587
|
+
if (!files.length)
|
|
588
|
+
return {};
|
|
589
|
+
const diff = await git(cwd, ['diff', '--no-color', '--no-ext-diff', baseCommit]);
|
|
590
|
+
return { changes: { files, diffHash: sha256(`${diff}\n${untracked.join('\n')}`) } };
|
|
591
|
+
}
|
|
592
|
+
catch {
|
|
593
|
+
return {};
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
export const FIX_LOOP_LOG_VERSION = 2;
|
|
597
|
+
export function defaultFixLoopDir() {
|
|
598
|
+
return process.env.DVALINCODE_FIX_LOOP_DIR ?? path.join(os.homedir(), '.dvalincode', 'security', 'fix-loops');
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Every loop is logged — rounds to green, where it stalled, what it was told.
|
|
602
|
+
* That is what tunes the loop, and the only honest evidence of whether it
|
|
603
|
+
* works. A log that cannot be written never fails the loop.
|
|
604
|
+
*/
|
|
605
|
+
function writeLoopLog(result, context, dir = defaultFixLoopDir()) {
|
|
606
|
+
const target = path.join(dir, `${result.id}.json`);
|
|
607
|
+
const body = {
|
|
608
|
+
kind: 'dvalin-fix-loop',
|
|
609
|
+
schemaVersion: FIX_LOOP_LOG_VERSION,
|
|
610
|
+
id: result.id,
|
|
611
|
+
...context,
|
|
612
|
+
outcome: result.outcome,
|
|
613
|
+
stopRule: result.stopRule,
|
|
614
|
+
reason: result.reason,
|
|
615
|
+
rounds: result.rounds,
|
|
616
|
+
needsHuman: result.needsHuman.map(entry => ({ ruleId: entry.finding.ruleId, path: entry.finding.path, reason: entry.reason })),
|
|
617
|
+
reproduction: result.reproduction?.status ?? null,
|
|
618
|
+
evasion: (result.final?.evasion ?? []).map(describeEvasion),
|
|
619
|
+
recordHash: result.record?.recordHash ?? null,
|
|
620
|
+
};
|
|
621
|
+
try {
|
|
622
|
+
mkdirSync(dir, { recursive: true });
|
|
623
|
+
const temporary = `${target}.${process.pid}.tmp`;
|
|
624
|
+
writeFileSync(temporary, `${JSON.stringify(body, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
625
|
+
renameSync(temporary, target);
|
|
626
|
+
return target;
|
|
627
|
+
}
|
|
628
|
+
catch {
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
function sameSet(a, b) {
|
|
633
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
634
|
+
}
|
|
635
|
+
async function git(cwd, args) {
|
|
636
|
+
const { stdout } = await execFileAsync('git', args, { cwd, maxBuffer: 64 * 1024 * 1024 });
|
|
637
|
+
return stdout;
|
|
638
|
+
}
|
|
639
|
+
//# sourceMappingURL=fixLoop.js.map
|