dvalincode 0.21.0 → 0.23.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 +261 -27
- package/README.zh-CN.md +203 -23
- 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 +18 -9
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/runner.d.ts +15 -3
- package/dist/agent/runner.js +99 -9
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/session.d.ts +7 -0
- package/dist/agent/session.js +32 -4
- 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/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/agents.d.ts +11 -0
- package/dist/commands/agents.js +223 -0
- package/dist/commands/agents.js.map +1 -0
- 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/mcpInstall.d.ts +24 -0
- package/dist/commands/mcpInstall.js +62 -17
- package/dist/commands/mcpInstall.js.map +1 -1
- package/dist/commands/provider.js +6 -1
- 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 +15 -0
- package/dist/commands/security.js +273 -22
- package/dist/commands/security.js.map +1 -1
- package/dist/dvalinCli.js +2 -0
- package/dist/dvalinCli.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/agents.d.ts +41 -0
- package/dist/mcp/agents.js +129 -0
- package/dist/mcp/agents.js.map +1 -0
- package/dist/mcp/install.d.ts +43 -6
- package/dist/mcp/install.js +104 -1
- package/dist/mcp/install.js.map +1 -1
- package/dist/mcp/server.js +10 -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/trustedBaseUrls.js +1 -1
- package/dist/providers/trustedBaseUrls.js.map +1 -1
- 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/cases.d.ts +1 -0
- package/dist/remediation/cases.js +1 -0
- package/dist/remediation/cases.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/codexSecurity.d.ts +54 -0
- package/dist/remediation/codexSecurity.js +366 -0
- package/dist/remediation/codexSecurity.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 +14 -1
- package/dist/remediation/sarif.js +21 -3
- package/dist/remediation/sarif.js.map +1 -1
- package/dist/remediation/scannerSuite.d.ts +52 -3
- package/dist/remediation/scannerSuite.js +347 -88
- 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,223 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { EXIT, UsageError } from '../core/exitCodes.js';
|
|
6
|
+
import { AGENT_IDS, agentName, detectAgents } from '../mcp/agents.js';
|
|
7
|
+
import { CC_SWITCH_APPS, ccSwitchImportLink, codexMcpAddArgs } from '../mcp/install.js';
|
|
8
|
+
import { installCodex, planJsonInstall, shellWord, writeJsonInstall } from './mcpInstall.js';
|
|
9
|
+
const execFileAsync = promisify(execFile);
|
|
10
|
+
export function registerAgentsCommand(program) {
|
|
11
|
+
const agents = program
|
|
12
|
+
.command('agents')
|
|
13
|
+
.description('Find the coding agents on this machine and connect Dvalin to them');
|
|
14
|
+
agents
|
|
15
|
+
.command('list', { isDefault: true })
|
|
16
|
+
.description('Show the coding agents found here and where Dvalin is connected')
|
|
17
|
+
.option('--json', 'print the result as JSON')
|
|
18
|
+
.option('--name <name>', 'server entry name to look for', 'dvalin')
|
|
19
|
+
.action(async (options) => {
|
|
20
|
+
const root = process.cwd();
|
|
21
|
+
const found = await detectAgents({ root, serverName: options.name });
|
|
22
|
+
if (options.json) {
|
|
23
|
+
console.log(JSON.stringify(found, null, 2));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
printAgents(found, root);
|
|
27
|
+
});
|
|
28
|
+
agents
|
|
29
|
+
.command('connect')
|
|
30
|
+
.description('Plan connecting Dvalin to the agents found here; apply it only with --yes')
|
|
31
|
+
.argument('[agents...]', `agents to connect (default: every one found without Dvalin): ${AGENT_IDS.join(', ')}`)
|
|
32
|
+
.option('--yes', 'apply the plan')
|
|
33
|
+
.option('--global', "use each agent's user-level config instead of the project's (Codex and CC Switch are always user-level)")
|
|
34
|
+
.option('--workspace <dir>', 'workspace the server is allowed to read', '.')
|
|
35
|
+
.option('--name <name>', 'name for the server entry', 'dvalin')
|
|
36
|
+
.action(async (requested, options) => {
|
|
37
|
+
const root = process.cwd();
|
|
38
|
+
const found = await detectAgents({ root, serverName: options.name });
|
|
39
|
+
const ids = selectAgents(found, requested);
|
|
40
|
+
if (ids.length === 0) {
|
|
41
|
+
const installed = found.filter(agent => agent.installed && agent.id !== 'cc-switch');
|
|
42
|
+
console.log(installed.length
|
|
43
|
+
? 'Dvalin is already connected to every agent found here. `dvalin agents` shows where.'
|
|
44
|
+
: `No supported coding agent was found on this machine. Name one to configure it anyway: dvalin agents connect <${AGENT_IDS.join('|')}>`);
|
|
45
|
+
printCcSwitchHint(found, ids);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const steps = [];
|
|
49
|
+
for (const id of ids)
|
|
50
|
+
steps.push(await planStep(id, found, options, root));
|
|
51
|
+
console.log(options.yes ? 'Connecting Dvalin:' : 'Plan (nothing is written yet):');
|
|
52
|
+
for (const step of steps) {
|
|
53
|
+
const agent = found.find(candidate => candidate.id === step.id);
|
|
54
|
+
const missing = agent?.installed ? '' : ' (not found on this machine)';
|
|
55
|
+
console.log(` ${agentName(step.id).padEnd(12)} ${step.summary}${missing}`);
|
|
56
|
+
for (const line of step.details ?? [])
|
|
57
|
+
console.log(` ${''.padEnd(12)} ${line}`);
|
|
58
|
+
}
|
|
59
|
+
if (!options.yes) {
|
|
60
|
+
console.log('\nReview it, then rerun with --yes to apply it.');
|
|
61
|
+
printCcSwitchHint(found, ids);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let failed = 0;
|
|
65
|
+
for (const step of steps) {
|
|
66
|
+
if (!step.apply)
|
|
67
|
+
continue;
|
|
68
|
+
console.log('');
|
|
69
|
+
try {
|
|
70
|
+
for (const line of await step.apply())
|
|
71
|
+
console.log(line);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
failed += 1;
|
|
75
|
+
console.error(`✗ ${agentName(step.id)}: ${message(error)}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
printCcSwitchHint(found, ids);
|
|
79
|
+
if (failed)
|
|
80
|
+
process.exitCode = EXIT.runtimeError;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The agents a `connect` covers: the ones named, or else every installed agent
|
|
85
|
+
* that has no Dvalin entry anywhere yet. CC Switch is only ever connected by
|
|
86
|
+
* name, because connecting it opens a dialog in another application.
|
|
87
|
+
*/
|
|
88
|
+
export function selectAgents(found, requested) {
|
|
89
|
+
if (requested.length)
|
|
90
|
+
return [...new Set(requested.map(parseAgentId))];
|
|
91
|
+
return found
|
|
92
|
+
.filter(agent => agent.installed && agent.id !== 'cc-switch' && agent.configured.length === 0)
|
|
93
|
+
.map(agent => agent.id);
|
|
94
|
+
}
|
|
95
|
+
/** The installed agents CC Switch can sync an MCP server into. */
|
|
96
|
+
export function ccSwitchTargets(found) {
|
|
97
|
+
return found.filter(agent => agent.installed && ccSwitchApp(agent.id) !== undefined);
|
|
98
|
+
}
|
|
99
|
+
function ccSwitchApp(id) {
|
|
100
|
+
return id === 'cc-switch' ? undefined : CC_SWITCH_APPS[id];
|
|
101
|
+
}
|
|
102
|
+
async function planStep(id, found, options, root) {
|
|
103
|
+
if (id === 'cc-switch')
|
|
104
|
+
return planCcSwitch(found, options);
|
|
105
|
+
if (id === 'codex') {
|
|
106
|
+
const command = ['codex', ...codexMcpAddArgs(options.workspace, options.name)].map(shellWord).join(' ');
|
|
107
|
+
return {
|
|
108
|
+
id,
|
|
109
|
+
summary: `run ${command} (Codex's own config writer; user-level)`,
|
|
110
|
+
apply: async () => {
|
|
111
|
+
await installCodex({ workspace: options.workspace, name: options.name });
|
|
112
|
+
return [];
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const plan = await planJsonInstall(id, {
|
|
118
|
+
root,
|
|
119
|
+
global: Boolean(options.global),
|
|
120
|
+
workspace: options.workspace,
|
|
121
|
+
name: options.name,
|
|
122
|
+
});
|
|
123
|
+
const file = displayPath(plan.file, root);
|
|
124
|
+
if (plan.action === 'unchanged')
|
|
125
|
+
return { id, summary: `already connected: ${file}` };
|
|
126
|
+
return {
|
|
127
|
+
id,
|
|
128
|
+
summary: plan.action === 'added' ? `add '${options.name}' to ${file}` : `replace '${options.name}' in ${file}`,
|
|
129
|
+
apply: async () => {
|
|
130
|
+
await writeJsonInstall(plan);
|
|
131
|
+
const verb = plan.action === 'added' ? 'Added' : 'Replaced';
|
|
132
|
+
return [`${verb} '${options.name}' in ${plan.file}`, ...(plan.client.followUp ? [plan.client.followUp] : [])];
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
return { id, summary: `skipped: ${message(error)}` };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function planCcSwitch(found, options) {
|
|
141
|
+
const targets = ccSwitchTargets(found);
|
|
142
|
+
if (targets.length === 0) {
|
|
143
|
+
return {
|
|
144
|
+
id: 'cc-switch',
|
|
145
|
+
summary: 'skipped: none of the agents CC Switch syncs MCP into (Claude Code, Codex, Gemini CLI, OpenCode) was found',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const apps = targets.map(agent => ccSwitchApp(agent.id));
|
|
149
|
+
const link = ccSwitchImportLink(apps, options.workspace, options.name);
|
|
150
|
+
return {
|
|
151
|
+
id: 'cc-switch',
|
|
152
|
+
summary: `open CC Switch's import dialog for ${targets.map(agent => agent.name).join(', ')}; CC Switch asks before it writes anything`,
|
|
153
|
+
details: [link],
|
|
154
|
+
apply: async () => {
|
|
155
|
+
try {
|
|
156
|
+
await openUrl(link);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw new Error(`could not open the link (${message(error)}). Open it yourself, with the CC Switch desktop app installed:\n${link}`);
|
|
160
|
+
}
|
|
161
|
+
return ['Opened CC Switch. Confirm the import there; it then writes Dvalin into each app it listed.'];
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function printAgents(found, root) {
|
|
166
|
+
console.log('Coding agents on this machine');
|
|
167
|
+
for (const agent of found) {
|
|
168
|
+
console.log(` ${agent.installed ? '✓' : '·'} ${agent.name.padEnd(12)} ${agent.installed ? agent.evidence.join(', ') : 'not found'}`);
|
|
169
|
+
if (agent.id === 'cc-switch') {
|
|
170
|
+
if (agent.installed)
|
|
171
|
+
console.log(' can sync Dvalin into the agents it manages: dvalin agents connect cc-switch');
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (agent.configured.length) {
|
|
175
|
+
console.log(` Dvalin: ${agent.configured.map(entry => `${entry.scope} ${displayPath(entry.file, root)}`).join(', ')}`);
|
|
176
|
+
}
|
|
177
|
+
else if (agent.installed) {
|
|
178
|
+
console.log(' Dvalin: not connected');
|
|
179
|
+
}
|
|
180
|
+
if (agent.unreadable.length) {
|
|
181
|
+
console.log(` could not read: ${agent.unreadable.map(file => displayPath(file, root)).join(', ')}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const pending = selectAgents(found, []);
|
|
185
|
+
console.log('');
|
|
186
|
+
console.log(pending.length
|
|
187
|
+
? `Next: \`dvalin agents connect\` plans Dvalin for ${pending.map(agentName).join(', ')}.`
|
|
188
|
+
: 'Nothing to connect: every agent found here already has Dvalin.');
|
|
189
|
+
}
|
|
190
|
+
function printCcSwitchHint(found, ids) {
|
|
191
|
+
const ccSwitch = found.find(agent => agent.id === 'cc-switch');
|
|
192
|
+
if (!ccSwitch?.installed || ids.includes('cc-switch'))
|
|
193
|
+
return;
|
|
194
|
+
console.log('CC Switch is installed. To manage Dvalin from CC Switch instead, run `dvalin agents connect cc-switch`.');
|
|
195
|
+
}
|
|
196
|
+
function parseAgentId(value) {
|
|
197
|
+
if (AGENT_IDS.includes(value))
|
|
198
|
+
return value;
|
|
199
|
+
throw new UsageError(`Unknown agent '${value}'. Expected one of: ${AGENT_IDS.join(', ')}.`);
|
|
200
|
+
}
|
|
201
|
+
/** Relative to the project when inside it, `~/...` when under home, absolute otherwise. */
|
|
202
|
+
function displayPath(file, root) {
|
|
203
|
+
for (const [base, prefix] of [[root, ''], [homedir(), '~/']]) {
|
|
204
|
+
const relative = path.relative(base, file);
|
|
205
|
+
if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
|
|
206
|
+
return `${prefix}${relative.split(path.sep).join('/')}`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return file;
|
|
210
|
+
}
|
|
211
|
+
async function openUrl(url) {
|
|
212
|
+
if (process.platform === 'darwin')
|
|
213
|
+
await execFileAsync('open', [url]);
|
|
214
|
+
// Not `cmd /c start`: cmd would split the link at its `&`s.
|
|
215
|
+
else if (process.platform === 'win32')
|
|
216
|
+
await execFileAsync('rundll32', ['url.dll,FileProtocolHandler', url]);
|
|
217
|
+
else
|
|
218
|
+
await execFileAsync('xdg-open', [url]);
|
|
219
|
+
}
|
|
220
|
+
function message(error) {
|
|
221
|
+
return error instanceof Error ? error.message : String(error);
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/commands/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,IAAI,EAAE,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K,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAU,EAAE,CAAC;QACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3C,IAAI,QAAQ,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,GAAW;IAChC,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAAE,MAAM,aAAa,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtE,4DAA4D;SACvD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,MAAM,aAAa,CAAC,UAAU,EAAE,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC,CAAC;;QACxG,MAAM,aAAa,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
2
|
import { snapshotFinding, type SecurityCoverage } from '../security/contracts.js';
|
|
3
|
-
import { type FixExecutor } from '../security/fixRecord.js';
|
|
3
|
+
import { type FixExecutor, type FixRecordEvasion } from '../security/fixRecord.js';
|
|
4
4
|
import type { SecurityCheckEvidence } from '../security/workflow.js';
|
|
5
|
+
import { type FixLoopResult } from '../remediation/fixLoop.js';
|
|
5
6
|
import { type DvalinScannerId, type DvalinScanSuiteResult } from '../remediation/scannerSuite.js';
|
|
6
7
|
declare const SEVERITIES: readonly ['critical', 'high', 'medium', 'low'];
|
|
7
8
|
type FailSeverity = typeof SEVERITIES[number] | 'none';
|
|
@@ -29,6 +30,8 @@ export declare function buildRunFixRecord(input: {
|
|
|
29
30
|
files: string[];
|
|
30
31
|
diffHash: string;
|
|
31
32
|
};
|
|
33
|
+
/** Evasion evidence from a guarded scan; supplying it issues a v3 record. */
|
|
34
|
+
evasion?: FixRecordEvasion[];
|
|
32
35
|
}): import("../security/fixRecord.js").VerifiedFixRecord;
|
|
33
36
|
/**
|
|
34
37
|
* What the re-scan sees that the baseline did not — the repair's side effects.
|
|
@@ -46,4 +49,7 @@ export declare function introducedSince(baseline: DvalinScanSuiteResult['finding
|
|
|
46
49
|
* current one. Everything else is a two-character status, a space, then the path.
|
|
47
50
|
*/
|
|
48
51
|
export declare function parsePorcelainZ(output: string): string[];
|
|
52
|
+
/** Where a draft PR carries its fix record; the CI example reads it from here. */
|
|
53
|
+
export declare const PR_RECORD_PATH = ".dvalin/fix-record.json";
|
|
54
|
+
export declare function renderLoopResult(loop: FixLoopResult): string;
|
|
49
55
|
export {};
|
package/dist/commands/dvalin.js
CHANGED
|
@@ -10,14 +10,21 @@ import { sha256 } from '../audit/hash.js';
|
|
|
10
10
|
import { deriveCoverage, findingTargetFingerprint, securityProjectId, snapshotFinding } from '../security/contracts.js';
|
|
11
11
|
import { renderCoverage } from '../security/render.js';
|
|
12
12
|
import { FIX_EXECUTORS, buildFixRecord, renderFixRecord } from '../security/fixRecord.js';
|
|
13
|
+
import { guardedScan } from '../security/guardedScan.js';
|
|
13
14
|
import { saveFixRecord } from '../security/fixRecordStore.js';
|
|
14
15
|
import { EXECUTOR_IDS, resolveExecutor, } from '../remediation/executor.js';
|
|
15
16
|
import { createRemediationWorktree } from '../remediation/worktree.js';
|
|
16
|
-
import {
|
|
17
|
+
import { classifyTarget, runFixLoop } from '../remediation/fixLoop.js';
|
|
18
|
+
import { resolveReproRunner } from '../remediation/reproduce.js';
|
|
19
|
+
import { describeEvasion } from '../remediation/evasion.js';
|
|
20
|
+
import { loadSecurityConfig } from '../security/config.js';
|
|
21
|
+
import { signFixRecord, takeSigningKey } from '../security/fixRecordSignature.js';
|
|
22
|
+
import { describeSuppressionChange } from '../security/suppressionGuard.js';
|
|
23
|
+
import { DEFAULT_SCANNER_IDS, DVALIN_SCANNER_IDS, runDvalinScanSuite, } from '../remediation/scannerSuite.js';
|
|
17
24
|
import { buildDvalinSarif } from '../remediation/sarifExport.js';
|
|
18
25
|
import { buildAutomatedFixPrompt, buildDraftPrPrompt, evaluateVerificationGate, extractDraftPrUrl, } from '../remediation/automate.js';
|
|
19
26
|
const execFileAsync = promisify(execFile);
|
|
20
|
-
const SCANNER_IDS =
|
|
27
|
+
const SCANNER_IDS = DVALIN_SCANNER_IDS;
|
|
21
28
|
const SEVERITIES = ['critical', 'high', 'medium', 'low'];
|
|
22
29
|
export function parseDvalinScannerIds(value) {
|
|
23
30
|
const ids = value.split(',').map(item => item.trim()).filter(Boolean);
|
|
@@ -96,7 +103,7 @@ export function registerDvalinCommand(program) {
|
|
|
96
103
|
.command('dvalin')
|
|
97
104
|
.description('Run Dvalin white-box security scanners')
|
|
98
105
|
.argument('[path]', 'workspace path', '.')
|
|
99
|
-
.option('--scanners <ids>', `comma-separated scanners: ${SCANNER_IDS.join(', ')}`,
|
|
106
|
+
.option('--scanners <ids>', `comma-separated scanners: ${SCANNER_IDS.join(', ')} (Snyk engines upload to Snyk and run only when named)`, DEFAULT_SCANNER_IDS.join(','))
|
|
100
107
|
.option('--timeout <seconds>', 'timeout for each external scanner', '300')
|
|
101
108
|
.option('--limit <count>', 'maximum findings shown in text output', '20')
|
|
102
109
|
.option('--json', 'print the complete scan result as JSON')
|
|
@@ -113,6 +120,15 @@ export function registerDvalinCommand(program) {
|
|
|
113
120
|
.option('--executor <name>', `who performs a --fix: ${EXECUTOR_IDS.join(', ')}`, 'dvalin')
|
|
114
121
|
.option('--verify-command <cmd>', 'command Dvalin runs to verify a fix; repeatable. Detected from the project when omitted', collectVerifyCommand, [])
|
|
115
122
|
.option('--record <file>', 'write the Verified Fix Record as JSON, whether or not the gate passed')
|
|
123
|
+
.option('--until-clean', 'loop: after each fix, re-scan and re-run the checks, and send only what is still wrong back to the executor')
|
|
124
|
+
.option('--max-rounds <count>', 'with --until-clean, the most fix rounds before stopping', '3')
|
|
125
|
+
.option('--no-reproduce', 'with --until-clean, skip reproduce-then-fix for code findings')
|
|
126
|
+
.option('--repro-command <template>', 'how to run only the reproduction tests, with {files} or {dirs} (default: policy `reproduce`, else inferred)')
|
|
127
|
+
.option('--repro-rounds <count>', 'with --until-clean, attempts at a failing reproduction test before handing the finding to a person', '2')
|
|
128
|
+
.option('--rebase-onto <ref>', 'with --until-clean, keep the fix rebased onto this ref (e.g. origin/main) and judge it there; fetched when it names a remote')
|
|
129
|
+
.option('--conflict-rounds <count>', 'with --rebase-onto, attempts at resolving rebase conflicts before handing them to a person', '2')
|
|
130
|
+
.option('--full-rescan', 'with --until-clean, scan the whole project every round (default: between rounds, per-file engines rescan only changed and target files; every stop is confirmed by a full scan)')
|
|
131
|
+
.option('--sign-key <file>', 'sign the fix record with this Ed25519 private key (default: DVALIN_SIGNING_KEY / DVALIN_SIGNING_KEY_FILE)')
|
|
116
132
|
.action(async (inputPath, options) => {
|
|
117
133
|
const root = path.resolve(process.cwd(), inputPath);
|
|
118
134
|
const scanners = parseDvalinScannerIds(options.scanners);
|
|
@@ -120,8 +136,23 @@ export function registerDvalinCommand(program) {
|
|
|
120
136
|
const limit = positiveInteger(options.limit, '--limit');
|
|
121
137
|
const maxFixes = positiveInteger(options.maxFixes, '--max-fixes');
|
|
122
138
|
const failOn = parseFailSeverity(options.failOn);
|
|
123
|
-
const shouldFix = Boolean(options.fix || options.verify || options.draftPr);
|
|
124
|
-
const shouldVerify = Boolean(options.verify || options.draftPr);
|
|
139
|
+
const shouldFix = Boolean(options.fix || options.verify || options.draftPr || options.untilClean);
|
|
140
|
+
const shouldVerify = Boolean(options.verify || options.draftPr || options.untilClean);
|
|
141
|
+
const maxRounds = positiveInteger(options.maxRounds, '--max-rounds');
|
|
142
|
+
const reproRounds = positiveInteger(options.reproRounds, '--repro-rounds');
|
|
143
|
+
const conflictRounds = positiveInteger(options.conflictRounds, '--conflict-rounds');
|
|
144
|
+
if (options.rebaseOnto && !options.untilClean)
|
|
145
|
+
throw new UsageError('--rebase-onto needs --until-clean.');
|
|
146
|
+
if (options.fullRescan && !options.untilClean)
|
|
147
|
+
throw new UsageError('--full-rescan needs --until-clean.');
|
|
148
|
+
if (options.rebaseOnto && options.inPlace) {
|
|
149
|
+
throw new UsageError('--rebase-onto rewrites the branch it works on, so it needs the isolated worktree; remove --in-place.');
|
|
150
|
+
}
|
|
151
|
+
// Taken before any check runs: checks are the change's own code.
|
|
152
|
+
const signingKey = shouldVerify ? takeSigningKey(options.signKey) : undefined;
|
|
153
|
+
if (options.reproCommand && !/\{(?:files|dirs)\}/.test(options.reproCommand)) {
|
|
154
|
+
throw new UsageError('--repro-command must contain {files} or {dirs}.');
|
|
155
|
+
}
|
|
125
156
|
if (options.json && shouldFix)
|
|
126
157
|
throw new UsageError('--json cannot be combined with --fix, --verify, or --draft-pr.');
|
|
127
158
|
if (options.draftPr && options.inPlace) {
|
|
@@ -172,6 +203,16 @@ export function registerDvalinCommand(program) {
|
|
|
172
203
|
executor: executor,
|
|
173
204
|
verifyCommands: options.verifyCommand,
|
|
174
205
|
recordPath: options.record,
|
|
206
|
+
signingKey,
|
|
207
|
+
loop: options.untilClean
|
|
208
|
+
? {
|
|
209
|
+
maxRounds,
|
|
210
|
+
threshold: failOn === 'none' ? 'high' : failOn,
|
|
211
|
+
reproduce: options.reproduce ? { flag: options.reproCommand, rounds: reproRounds } : undefined,
|
|
212
|
+
rebase: options.rebaseOnto ? { onto: options.rebaseOnto, maxConflictRounds: conflictRounds } : undefined,
|
|
213
|
+
fullScanEveryRound: options.fullRescan,
|
|
214
|
+
}
|
|
215
|
+
: undefined,
|
|
175
216
|
});
|
|
176
217
|
}
|
|
177
218
|
else if (shouldFix) {
|
|
@@ -216,6 +257,86 @@ async function runAutomatedRemediation(input) {
|
|
|
216
257
|
}
|
|
217
258
|
for (const remediationCase of cases)
|
|
218
259
|
await updateRemediationCase(remediationCase.id, { status: 'fixing' });
|
|
260
|
+
if (input.loop) {
|
|
261
|
+
const { stdout: head } = await execFileAsync('git', ['rev-parse', 'HEAD'], { cwd });
|
|
262
|
+
// The runner comes from the person (flag) or the policy, read before the
|
|
263
|
+
// executor has touched anything — never from the executor.
|
|
264
|
+
let reproduce;
|
|
265
|
+
if (input.loop.reproduce && input.findings.some(finding => classifyTarget(finding) === 'code')) {
|
|
266
|
+
const configured = (await loadSecurityConfig(cwd).catch(() => undefined))?.config.reproduce;
|
|
267
|
+
const runner = await resolveReproRunner(cwd, { flag: input.loop.reproduce.flag, configured });
|
|
268
|
+
if (runner) {
|
|
269
|
+
reproduce = { runner, rounds: input.loop.reproduce.rounds };
|
|
270
|
+
console.log(`\nReproduce-then-fix: code findings must first be shown failing with \`${runner.template}\` (${runner.source}).`);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
console.log('\nReproduce-then-fix skipped: no test runner was detected. Pass --repro-command or set `reproduce` in dvalin.security.json. The fix record will carry no reproduction.');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
console.log(`\n${executor.name}: fixing, then Dvalin judges — at most ${input.loop.maxRounds} round(s)…`);
|
|
277
|
+
const loop = await runFixLoop({
|
|
278
|
+
cwd,
|
|
279
|
+
baseCommit: head.trim(),
|
|
280
|
+
before: input.before,
|
|
281
|
+
targets: input.findings,
|
|
282
|
+
baseline: input.baselineFindings,
|
|
283
|
+
scanners: input.scanners,
|
|
284
|
+
threshold: input.loop.threshold,
|
|
285
|
+
maxRounds: input.loop.maxRounds,
|
|
286
|
+
executor,
|
|
287
|
+
executorLabel: fixExecutorFor(executor.id),
|
|
288
|
+
provider: input.provider,
|
|
289
|
+
timeoutMs: input.timeoutMs,
|
|
290
|
+
verifyCommands: input.verifyCommands,
|
|
291
|
+
worktreeContext,
|
|
292
|
+
reproduce,
|
|
293
|
+
rebase: input.loop.rebase,
|
|
294
|
+
fullScanEveryRound: input.loop.fullScanEveryRound,
|
|
295
|
+
onRound: renderLoopRound,
|
|
296
|
+
onReproduceRound: renderReproduceRound,
|
|
297
|
+
onExecutorEvent: renderAutomationEvent,
|
|
298
|
+
});
|
|
299
|
+
console.log(renderLoopResult(loop));
|
|
300
|
+
if (loop.record && input.signingKey)
|
|
301
|
+
loop.record = signFixRecord(loop.record, input.signingKey);
|
|
302
|
+
if (loop.record) {
|
|
303
|
+
saveFixRecord(loop.record);
|
|
304
|
+
if (input.recordPath) {
|
|
305
|
+
const target = path.resolve(process.cwd(), input.recordPath);
|
|
306
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
307
|
+
await writeFile(target, `${JSON.stringify(loop.record, null, 2)}\n`, 'utf8');
|
|
308
|
+
console.log(`Fix record written to ${target}`);
|
|
309
|
+
}
|
|
310
|
+
console.log(renderFixRecord(loop.record));
|
|
311
|
+
}
|
|
312
|
+
if (loop.outcome !== 'verified') {
|
|
313
|
+
throw new Error(`Dvalin fix loop stopped: ${loop.outcome} — ${loop.reason}`);
|
|
314
|
+
}
|
|
315
|
+
for (const remediationCase of cases)
|
|
316
|
+
await updateRemediationCase(remediationCase.id, { status: 'verified' });
|
|
317
|
+
const after = loop.final.scan;
|
|
318
|
+
if (!input.draftPr)
|
|
319
|
+
return after;
|
|
320
|
+
// The record travels with the branch, so CI can re-execute it with
|
|
321
|
+
// `reverify` instead of taking this machine's word for it.
|
|
322
|
+
await mkdir(path.join(cwd, '.dvalin'), { recursive: true });
|
|
323
|
+
await writeFile(path.join(cwd, PR_RECORD_PATH), `${JSON.stringify(loop.record, null, 2)}\n`, 'utf8');
|
|
324
|
+
console.log(`\n${executor.name}: publishing verified remediation as a draft PR…`);
|
|
325
|
+
const publishTurn = await executor.run({
|
|
326
|
+
prompt: buildDraftPrPrompt(input.findings, PR_RECORD_PATH),
|
|
327
|
+
resume: loop.session,
|
|
328
|
+
cwd,
|
|
329
|
+
provider: input.provider,
|
|
330
|
+
}, renderAutomationEvent);
|
|
331
|
+
console.log(`\n${publishTurn.output}\n`);
|
|
332
|
+
const url = extractDraftPrUrl(publishTurn.output);
|
|
333
|
+
if (!url)
|
|
334
|
+
throw new Error('Draft PR publication did not return a GitHub pull request URL.');
|
|
335
|
+
console.log(`Draft PR: ${url}`);
|
|
336
|
+
return after;
|
|
337
|
+
}
|
|
338
|
+
// Taken before the executor edits anything: what the repair is measured against.
|
|
339
|
+
const { stdout: startHead } = await execFileAsync('git', ['rev-parse', 'HEAD'], { cwd });
|
|
219
340
|
console.log(`\n${executor.name}: validating and fixing findings…`);
|
|
220
341
|
const fixTurn = await executor.run({
|
|
221
342
|
prompt: buildAutomatedFixPrompt(input.findings, worktreeContext),
|
|
@@ -242,7 +363,20 @@ async function runAutomatedRemediation(input) {
|
|
|
242
363
|
console.log(` · not detected in this project: ${verification.skipped.join(', ')}. Use --verify-command to name them.`);
|
|
243
364
|
}
|
|
244
365
|
console.log('Dvalin gate: independently re-running scanners…');
|
|
245
|
-
|
|
366
|
+
// Suppressions the repair added are undone for this scan, and its evasions
|
|
367
|
+
// recorded — the same judgement the fix loop, `dvalin verify` and CI apply.
|
|
368
|
+
const guarded = await guardedScan({
|
|
369
|
+
root: cwd,
|
|
370
|
+
baseCommit: startHead.trim(),
|
|
371
|
+
scanners: input.scanners,
|
|
372
|
+
timeoutMs: input.timeoutMs,
|
|
373
|
+
targets: input.findings.map(snapshotFinding),
|
|
374
|
+
});
|
|
375
|
+
const after = guarded.result;
|
|
376
|
+
for (const change of guarded.suppressions)
|
|
377
|
+
console.log(` ! ${describeSuppressionChange(change)} — undone for this scan`);
|
|
378
|
+
for (const signal of guarded.signals)
|
|
379
|
+
console.log(` ! ${describeEvasion(signal)}`);
|
|
246
380
|
const { stdout: status } = await execFileAsync('git', ['status', '--porcelain'], { cwd });
|
|
247
381
|
const gate = evaluateVerificationGate({
|
|
248
382
|
originals: input.findings,
|
|
@@ -255,7 +389,7 @@ async function runAutomatedRemediation(input) {
|
|
|
255
389
|
// Issued whether or not the gate passed: a record that says a repair did not
|
|
256
390
|
// verify is exactly as useful as one that says it did, and dropping it on
|
|
257
391
|
// failure would leave the only unrecorded outcome the one worth recording.
|
|
258
|
-
|
|
392
|
+
let record = buildRunFixRecord({
|
|
259
393
|
root: input.root,
|
|
260
394
|
executor: fixExecutorFor(executor.id),
|
|
261
395
|
before: input.before,
|
|
@@ -264,7 +398,10 @@ async function runAutomatedRemediation(input) {
|
|
|
264
398
|
baseline: input.baselineFindings,
|
|
265
399
|
checks: verification.evidence,
|
|
266
400
|
changes: await changesFrom(cwd),
|
|
401
|
+
evasion: guarded.evasion,
|
|
267
402
|
});
|
|
403
|
+
if (input.signingKey)
|
|
404
|
+
record = signFixRecord(record, input.signingKey);
|
|
268
405
|
saveFixRecord(record);
|
|
269
406
|
if (input.recordPath) {
|
|
270
407
|
const target = path.resolve(process.cwd(), input.recordPath);
|
|
@@ -273,8 +410,12 @@ async function runAutomatedRemediation(input) {
|
|
|
273
410
|
console.log(`Fix record written to ${target}`);
|
|
274
411
|
}
|
|
275
412
|
console.log(renderFixRecord(record));
|
|
276
|
-
|
|
277
|
-
|
|
413
|
+
// The record decides, as it does for `dvalin verify`: a repair the record
|
|
414
|
+
// does not verify — an evasion, a suppression that left the target in
|
|
415
|
+
// place — does not pass here because an older gate happened to.
|
|
416
|
+
if (!gate.passed || !record.verdict.verified) {
|
|
417
|
+
const reasons = [...new Set([...gate.reasons, ...(record.verdict.verified ? [] : record.verdict.reasons)])];
|
|
418
|
+
throw new Error(`Dvalin verification gate failed: ${reasons.join('; ')}`);
|
|
278
419
|
}
|
|
279
420
|
for (const remediationCase of cases)
|
|
280
421
|
await updateRemediationCase(remediationCase.id, { status: 'verified' });
|
|
@@ -334,6 +475,7 @@ export function buildRunFixRecord(input) {
|
|
|
334
475
|
gate: { threshold: 'high', mode: 'new' },
|
|
335
476
|
introduced: introducedSince(input.baseline, input.after),
|
|
336
477
|
},
|
|
478
|
+
...(input.evasion ? { evasion: input.evasion } : {}),
|
|
337
479
|
...(input.changes ? { changes: input.changes } : {}),
|
|
338
480
|
checks: input.checks,
|
|
339
481
|
});
|
|
@@ -408,6 +550,64 @@ function parseExecutorId(value) {
|
|
|
408
550
|
return value;
|
|
409
551
|
throw new UsageError(`Unknown --executor '${value}'. Expected one of: ${EXECUTOR_IDS.join(', ')}.`);
|
|
410
552
|
}
|
|
553
|
+
/** Where a draft PR carries its fix record; the CI example reads it from here. */
|
|
554
|
+
export const PR_RECORD_PATH = '.dvalin/fix-record.json';
|
|
555
|
+
function renderReproduceRound(round) {
|
|
556
|
+
console.log(`\nDvalin · reproduce ${round.round}: ${round.problems?.length ? `not yet — ${round.problems.join('; ')}` : 'tests fail on the vulnerable code ✓'} (${Math.round(round.durationMs / 1000)}s)`);
|
|
557
|
+
}
|
|
558
|
+
function renderLoopRound(round, observation) {
|
|
559
|
+
const parts = [
|
|
560
|
+
`${round.fixed} fixed`,
|
|
561
|
+
`${round.remaining} remaining`,
|
|
562
|
+
`${round.blockingIntroduced} introduced`,
|
|
563
|
+
round.failedChecks.length ? `checks failing: ${round.failedChecks.join(', ')}` : `checks ${observation.checks.length ? 'pass' : 'not run'}`,
|
|
564
|
+
...(round.suppressions ? [`${round.suppressions} suppression(s) added — undone for the scan`] : []),
|
|
565
|
+
...(round.evasion ? [`${round.evasion} evasion signal(s)`] : []),
|
|
566
|
+
];
|
|
567
|
+
if (round.rebased) {
|
|
568
|
+
console.log(`\nDvalin · rebased onto ${round.rebased.to.slice(0, 12)}${round.rebased.conflicts.length ? ` (resolved conflicts in ${round.rebased.conflicts.join(', ')})` : ''}; baseline re-scanned there`);
|
|
569
|
+
}
|
|
570
|
+
console.log(`\nDvalin · round ${round.round}: ${parts.join(' · ')} (${Math.round(round.durationMs / 1000)}s${round.scan ? `, scan ${scanLabel(round.scan)}` : ''})`);
|
|
571
|
+
for (const change of observation.suppressions.slice(0, 5))
|
|
572
|
+
console.log(` ! ${describeSuppressionChange(change)}`);
|
|
573
|
+
for (const signal of observation.evasion.slice(0, 5))
|
|
574
|
+
console.log(` ! ${describeEvasion(signal)}`);
|
|
575
|
+
for (const file of observation.reproTampered)
|
|
576
|
+
console.log(` ! reproduction test changed: ${file}`);
|
|
577
|
+
}
|
|
578
|
+
function scanLabel(scan) {
|
|
579
|
+
const seconds = `${Math.round(scan.durationMs / 1000)}s`;
|
|
580
|
+
if (!scan.confirmed)
|
|
581
|
+
return `${scan.mode} ${seconds}`;
|
|
582
|
+
return `${seconds}, confirmed by a full scan${scan.decisionChanged ? ' — which changed the decision' : ''}`;
|
|
583
|
+
}
|
|
584
|
+
export function renderLoopResult(loop) {
|
|
585
|
+
const reproduceRounds = loop.rounds.filter(round => round.phase === 'reproduce').length;
|
|
586
|
+
const fixRounds = loop.rounds.length - reproduceRounds;
|
|
587
|
+
const lines = [`\nFix loop ${loop.outcome.toUpperCase()} after ${fixRounds} fix round(s)${reproduceRounds ? ` and ${reproduceRounds} reproduce attempt(s)` : ''}: ${loop.reason}`];
|
|
588
|
+
if (loop.reproduction)
|
|
589
|
+
lines.push(`Reproduction: ${loop.reproduction.status} · ${loop.reproduction.tests.map(test => test.path).join(', ')}`);
|
|
590
|
+
if (loop.needsHuman.length) {
|
|
591
|
+
lines.push(`Needs a person (${loop.needsHuman.length}):`);
|
|
592
|
+
for (const entry of loop.needsHuman)
|
|
593
|
+
lines.push(` · ${entry.finding.ruleId} in ${entry.finding.path} — ${entry.reason}`);
|
|
594
|
+
}
|
|
595
|
+
if (loop.outcome !== 'verified' && loop.final) {
|
|
596
|
+
for (const finding of loop.final.remaining.slice(0, 10))
|
|
597
|
+
lines.push(` ✗ still present: ${finding.ruleId} at ${finding.path}${finding.startLine ? `:${finding.startLine}` : ''}`);
|
|
598
|
+
for (const finding of loop.final.blocking.slice(0, 10))
|
|
599
|
+
lines.push(` ✗ introduced: ${finding.ruleId} at ${finding.path}${finding.startLine ? `:${finding.startLine}` : ''}`);
|
|
600
|
+
for (const check of loop.final.checks.filter(check => !check.passed))
|
|
601
|
+
lines.push(` ✗ check failing: ${check.command}`);
|
|
602
|
+
for (const signal of loop.final.evasion)
|
|
603
|
+
lines.push(` ✗ not a fix: ${describeEvasion(signal)}`);
|
|
604
|
+
for (const file of loop.final.reproTampered)
|
|
605
|
+
lines.push(` ✗ reproduction test changed: ${file}`);
|
|
606
|
+
}
|
|
607
|
+
if (loop.logPath)
|
|
608
|
+
lines.push(`Round log: ${loop.logPath}`);
|
|
609
|
+
return lines.join('\n');
|
|
610
|
+
}
|
|
411
611
|
function renderAutomationEvent(event) {
|
|
412
612
|
if (event.type === 'tool_call')
|
|
413
613
|
console.log(` → ${event.name}`);
|