dvalincode 0.17.0 → 0.19.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 +320 -46
- package/README.zh-CN.md +277 -39
- package/THIRD_PARTY_NOTICES.md +98 -43
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/dvalin.d.ts +41 -1
- package/dist/commands/dvalin.js +219 -37
- package/dist/commands/dvalin.js.map +1 -1
- package/dist/commands/mcpInstall.d.ts +2 -0
- package/dist/commands/mcpInstall.js +69 -0
- package/dist/commands/mcpInstall.js.map +1 -0
- package/dist/commands/run.js +21 -0
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/security.d.ts +47 -0
- package/dist/commands/security.js +415 -0
- package/dist/commands/security.js.map +1 -0
- package/dist/dvalinCli.d.ts +3 -0
- package/dist/dvalinCli.js +36 -0
- package/dist/dvalinCli.js.map +1 -0
- package/dist/dvalinIndex.d.ts +2 -0
- package/dist/dvalinIndex.js +9 -0
- package/dist/dvalinIndex.js.map +1 -0
- package/dist/evidence/pack.d.ts +8 -0
- package/dist/evidence/pack.js +16 -0
- package/dist/evidence/pack.js.map +1 -1
- package/dist/harness/run.d.ts +15 -0
- package/dist/harness/run.js +45 -19
- package/dist/harness/run.js.map +1 -1
- package/dist/harness/verification.d.ts +56 -0
- package/dist/harness/verification.js +90 -0
- package/dist/harness/verification.js.map +1 -0
- package/dist/mcp/install.d.ts +48 -0
- package/dist/mcp/install.js +74 -0
- package/dist/mcp/install.js.map +1 -0
- package/dist/mcp/server.d.ts +10 -1
- package/dist/mcp/server.js +251 -34
- package/dist/mcp/server.js.map +1 -1
- package/dist/remediation/automate.d.ts +4 -1
- package/dist/remediation/automate.js +35 -18
- package/dist/remediation/automate.js.map +1 -1
- package/dist/remediation/diffScope.d.ts +29 -0
- package/dist/remediation/diffScope.js +107 -0
- package/dist/remediation/diffScope.js.map +1 -0
- package/dist/remediation/executor.d.ts +60 -0
- package/dist/remediation/executor.js +144 -0
- package/dist/remediation/executor.js.map +1 -0
- package/dist/remediation/localScan.d.ts +2 -1
- package/dist/remediation/localScan.js +73 -3
- package/dist/remediation/localScan.js.map +1 -1
- package/dist/remediation/sarif.d.ts +6 -0
- package/dist/remediation/sarif.js +36 -14
- package/dist/remediation/sarif.js.map +1 -1
- package/dist/remediation/scannerSuite.d.ts +21 -0
- package/dist/remediation/scannerSuite.js +65 -4
- package/dist/remediation/scannerSuite.js.map +1 -1
- package/dist/remediation/verify.d.ts +38 -0
- package/dist/remediation/verify.js +116 -0
- package/dist/remediation/verify.js.map +1 -0
- package/dist/security/baseline.d.ts +7 -0
- package/dist/security/baseline.js +26 -0
- package/dist/security/baseline.js.map +1 -0
- package/dist/security/config.d.ts +32 -0
- package/dist/security/config.js +131 -0
- package/dist/security/config.js.map +1 -0
- package/dist/security/contracts.d.ts +149 -0
- package/dist/security/contracts.js +231 -0
- package/dist/security/contracts.js.map +1 -0
- package/dist/security/fixRecord.d.ts +231 -0
- package/dist/security/fixRecord.js +327 -0
- package/dist/security/fixRecord.js.map +1 -0
- package/dist/security/fixRecordFile.d.ts +8 -0
- package/dist/security/fixRecordFile.js +37 -0
- package/dist/security/fixRecordFile.js.map +1 -0
- package/dist/security/fixRecordStore.d.ts +23 -0
- package/dist/security/fixRecordStore.js +74 -0
- package/dist/security/fixRecordStore.js.map +1 -0
- package/dist/security/render.d.ts +8 -0
- package/dist/security/render.js +20 -0
- package/dist/security/render.js.map +1 -0
- package/dist/security/suppressions.d.ts +12 -0
- package/dist/security/suppressions.js +60 -0
- package/dist/security/suppressions.js.map +1 -0
- package/dist/security/verifyRun.d.ts +21 -0
- package/dist/security/verifyRun.js +74 -0
- package/dist/security/verifyRun.js.map +1 -0
- package/dist/security/workflow.d.ts +98 -0
- package/dist/security/workflow.js +276 -0
- package/dist/security/workflow.js.map +1 -0
- package/dist/server/routes/remediation.d.ts +19 -0
- package/dist/server/routes/remediation.js +90 -18
- package/dist/server/routes/remediation.js.map +1 -1
- package/dist/tools/runCheck.d.ts +6 -0
- package/dist/tools/runCheck.js +1 -1
- package/dist/tools/runCheck.js.map +1 -1
- package/dist/tools/runSecuritySuite.d.ts +3 -0
- package/dist/tools/runSecuritySuite.js +18 -11
- package/dist/tools/runSecuritySuite.js.map +1 -1
- package/dist/tui/app.js +21 -2
- package/dist/tui/app.js.map +1 -1
- package/dist/tui/render.js +2 -0
- package/dist/tui/render.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +17 -10
package/dist/harness/run.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type AgentEvent } from '../agent/types.js';
|
|
|
2
2
|
import type { AgentMode, CodePermissionMode } from '../agent/modes.js';
|
|
3
3
|
import type { RunOrigin } from '../audit/log.js';
|
|
4
4
|
import { type UnattendedPermissionMode } from '../core/policy.js';
|
|
5
|
+
import { type HarnessVerification } from './verification.js';
|
|
5
6
|
export declare const DEFAULT_RUN_TIMEOUT_MINUTES = 25;
|
|
6
7
|
export type HarnessStopReason = 'done' | 'max_iterations' | 'timeout' | 'interrupted' | 'error';
|
|
7
8
|
export type HarnessRunResult = {
|
|
@@ -22,6 +23,20 @@ export type HarnessRunResult = {
|
|
|
22
23
|
output: string;
|
|
23
24
|
stopReason: HarnessStopReason;
|
|
24
25
|
error?: string;
|
|
26
|
+
/**
|
|
27
|
+
* What the turn's security scanning covered, and any Verified Fix Record it
|
|
28
|
+
* filed. Absent when the turn did neither — which is deliberately different
|
|
29
|
+
* from a scan whose coverage came back `unknown`. A consumer that cannot tell
|
|
30
|
+
* "nothing was scanned" from "the scan could not say what it looked at" is
|
|
31
|
+
* back to the problem this field exists to solve.
|
|
32
|
+
*
|
|
33
|
+
* It does not affect `exitCode`. Coverage describes the scan, not the run:
|
|
34
|
+
* a turn that completed its task with a half-blind scanner did not fail, and
|
|
35
|
+
* folding that into the process exit would silently change a documented
|
|
36
|
+
* contract for every existing consumer. The status is reported so a caller
|
|
37
|
+
* can gate on it deliberately.
|
|
38
|
+
*/
|
|
39
|
+
verification?: HarnessVerification;
|
|
25
40
|
};
|
|
26
41
|
export type HarnessRunRequest = {
|
|
27
42
|
content: string;
|
package/dist/harness/run.js
CHANGED
|
@@ -4,6 +4,7 @@ import { runAgentTurn } from '../agent/session.js';
|
|
|
4
4
|
import { DEFAULT_TURN_CONFIG } from '../agent/types.js';
|
|
5
5
|
import { loadPolicy, narrowerUnattendedPermissionMode, PolicyViolationError, unattendedPermissionAllowed, } from '../core/policy.js';
|
|
6
6
|
import { loadSession } from '../sessions/store.js';
|
|
7
|
+
import { createVerificationCollector } from './verification.js';
|
|
7
8
|
export const DEFAULT_RUN_TIMEOUT_MINUTES = 25;
|
|
8
9
|
/** A caller error that maps to the documented deterministic usage exit code. */
|
|
9
10
|
export class HarnessUsageError extends Error {
|
|
@@ -27,25 +28,43 @@ export async function executeHarnessRun(request, hooks = {}) {
|
|
|
27
28
|
let iterationsUsed = 0;
|
|
28
29
|
let usage = { inputTokens: 0, outputTokens: 0 };
|
|
29
30
|
let output = '';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
let verificationCollector;
|
|
32
|
+
const finish = (exitCode, stopReason, error, auditHead) => {
|
|
33
|
+
// Collected on every exit path, not only the successful one: a turn that
|
|
34
|
+
// scanned and then timed out still learned something about coverage, and
|
|
35
|
+
// dropping it would hide the scan precisely when the run needs explaining.
|
|
36
|
+
//
|
|
37
|
+
// Guarded because this runs inside the catch path too. A field that reports
|
|
38
|
+
// on the run must never be able to fail the run, or replace the error that
|
|
39
|
+
// actually ended it with one from the reporting itself.
|
|
40
|
+
let collected;
|
|
41
|
+
try {
|
|
42
|
+
collected = verificationCollector?.collect();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
collected = undefined;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
exitCode,
|
|
49
|
+
result: {
|
|
50
|
+
ok: exitCode === 0,
|
|
51
|
+
sessionId,
|
|
52
|
+
runId,
|
|
53
|
+
auditHead,
|
|
54
|
+
policyHash,
|
|
55
|
+
provider,
|
|
56
|
+
model,
|
|
57
|
+
iterationsUsed,
|
|
58
|
+
toolCalls,
|
|
59
|
+
usage,
|
|
60
|
+
wallSeconds: (Date.now() - startedAt) / 1000,
|
|
61
|
+
output,
|
|
62
|
+
stopReason,
|
|
63
|
+
...(error ? { error } : {}),
|
|
64
|
+
...(collected ? { verification: collected } : {}),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
};
|
|
49
68
|
let timeoutSignal;
|
|
50
69
|
try {
|
|
51
70
|
validatePositiveNumber(request.maxIterations, 'max iterations', true);
|
|
@@ -106,6 +125,12 @@ export async function executeHarnessRun(request, hooks = {}) {
|
|
|
106
125
|
const config = { maxIterations };
|
|
107
126
|
if (request.maxToolCalls !== undefined)
|
|
108
127
|
config.maxToolCallsPerTurn = request.maxToolCalls;
|
|
128
|
+
// Snapshot the fix-record store before the turn so the run is credited only
|
|
129
|
+
// with records it filed. A record is written by whatever `dvalin verify` the
|
|
130
|
+
// agent reaches for, under that command's own audit run, so there is no run
|
|
131
|
+
// id to join on -- what is new since this point is the only honest answer.
|
|
132
|
+
verificationCollector = createVerificationCollector(cwd);
|
|
133
|
+
verificationCollector.begin();
|
|
109
134
|
const turn = await runAgentTurn({
|
|
110
135
|
content: request.content,
|
|
111
136
|
cwd,
|
|
@@ -137,6 +162,7 @@ export async function executeHarnessRun(request, hooks = {}) {
|
|
|
137
162
|
toolCalls++;
|
|
138
163
|
if (event.type === 'llm_iteration')
|
|
139
164
|
iterationsUsed = event.iteration;
|
|
165
|
+
verificationCollector?.observe(event);
|
|
140
166
|
hooks.onEvent?.(event);
|
|
141
167
|
},
|
|
142
168
|
// A headless surface has no human approval channel. Any tool path that
|
package/dist/harness/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/harness/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAoC,MAAM,mBAAmB,CAAC;AAG1F,OAAO,EACL,UAAU,EACV,gCAAgC,EAChC,oBAAoB,EACpB,2BAA2B,GAE5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/harness/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAoC,MAAM,mBAAmB,CAAC;AAG1F,OAAO,EACL,UAAU,EACV,gCAAgC,EAChC,oBAAoB,EACpB,2BAA2B,GAE5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,2BAA2B,EAA4B,MAAM,mBAAmB,CAAC;AAE1F,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,CAAC;AA0E9C,gFAAgF;AAChF,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,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}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AgentEvent } from '../agent/types.js';
|
|
2
|
+
import { type SecurityCoverage, type SecurityCoverageStatus } from '../security/contracts.js';
|
|
3
|
+
import type { VerifiedFixRecord } from '../security/fixRecord.js';
|
|
4
|
+
/**
|
|
5
|
+
* What a headless run can say about the scanning it did.
|
|
6
|
+
*
|
|
7
|
+
* Every surface a human watches now shows coverage. This is the one with no
|
|
8
|
+
* human present, which makes it the one where a silent omission does the most
|
|
9
|
+
* damage: a CI gate reading "no findings" from a run where half the engines
|
|
10
|
+
* were missing is the machine-readable form of the bug the rest of this work
|
|
11
|
+
* closed.
|
|
12
|
+
*/
|
|
13
|
+
/** One security scan performed during the turn, with what it actually covered. */
|
|
14
|
+
export type HarnessScanCoverage = {
|
|
15
|
+
/** The tool that ran the scan, e.g. `run_security_suite`. */
|
|
16
|
+
tool: string;
|
|
17
|
+
toolCallId: string;
|
|
18
|
+
coverage: SecurityCoverage;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A Verified Fix Record filed during the turn.
|
|
22
|
+
*
|
|
23
|
+
* The record itself is not inlined — it is already a portable file, and
|
|
24
|
+
* `path` is what a consumer feeds to `dvalincode security verify-fix` to
|
|
25
|
+
* re-derive the verdict offline without re-running the agent.
|
|
26
|
+
*/
|
|
27
|
+
export type HarnessFixRecordRef = {
|
|
28
|
+
recordHash: string;
|
|
29
|
+
path: string;
|
|
30
|
+
/** Who edited the code. Recorded here as it is in the record: never consulted. */
|
|
31
|
+
executor: string;
|
|
32
|
+
assurance: VerifiedFixRecord['assurance'];
|
|
33
|
+
verified: boolean;
|
|
34
|
+
coverage: {
|
|
35
|
+
before: SecurityCoverageStatus;
|
|
36
|
+
after: SecurityCoverageStatus;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type HarnessVerification = {
|
|
40
|
+
/**
|
|
41
|
+
* The weakest coverage this run has evidence of, across every scan it ran and
|
|
42
|
+
* every record it filed. The single field a CI gate should read: taking the
|
|
43
|
+
* best or the last would let one complete scan speak for a partial one.
|
|
44
|
+
*/
|
|
45
|
+
coverageStatus: SecurityCoverageStatus;
|
|
46
|
+
scans: HarnessScanCoverage[];
|
|
47
|
+
fixRecords: HarnessFixRecordRef[];
|
|
48
|
+
};
|
|
49
|
+
export type VerificationCollector = {
|
|
50
|
+
/** Note which records already existed, so the run is credited only with what it filed. */
|
|
51
|
+
begin(): void;
|
|
52
|
+
observe(event: AgentEvent): void;
|
|
53
|
+
/** `undefined` when the turn neither scanned nor filed a record — see below. */
|
|
54
|
+
collect(): HarnessVerification | undefined;
|
|
55
|
+
};
|
|
56
|
+
export declare function createVerificationCollector(cwd: string, resolveDir?: () => string): VerificationCollector;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readdirSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { SECURITY_COVERAGE_STATUSES, securityProjectId, } from '../security/contracts.js';
|
|
4
|
+
import { defaultFixRecordDir, listFixRecords } from '../security/fixRecordStore.js';
|
|
5
|
+
/** `unknown` is weaker than `partial`: not knowing what ran is worse than knowing it was incomplete. */
|
|
6
|
+
const COVERAGE_RANK = { unknown: 0, partial: 1, complete: 2 };
|
|
7
|
+
function isCoverageStatus(value) {
|
|
8
|
+
return typeof value === 'string' && SECURITY_COVERAGE_STATUSES.includes(value);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Tool metadata is `Record<string, unknown>` by the time it reaches an event, so
|
|
12
|
+
* it is validated rather than cast. A malformed `coverage` is dropped: reporting
|
|
13
|
+
* a status this did not actually read would be the same failure one level up.
|
|
14
|
+
*/
|
|
15
|
+
function asCoverage(value) {
|
|
16
|
+
if (!value || typeof value !== 'object')
|
|
17
|
+
return undefined;
|
|
18
|
+
const candidate = value;
|
|
19
|
+
if (!isCoverageStatus(candidate.status))
|
|
20
|
+
return undefined;
|
|
21
|
+
if (!Array.isArray(candidate.scanners))
|
|
22
|
+
return undefined;
|
|
23
|
+
if (!Array.isArray(candidate.exclusions) || !Array.isArray(candidate.deferred) || !Array.isArray(candidate.notes)) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return candidate;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hashes of the records already on disk.
|
|
30
|
+
*
|
|
31
|
+
* Read from filenames rather than by parsing: `saveFixRecord` names every file
|
|
32
|
+
* after the record's own hash, so the directory listing is the hash set, and a
|
|
33
|
+
* store with thousands of records costs one readdir instead of thousands of
|
|
34
|
+
* re-derivations.
|
|
35
|
+
*/
|
|
36
|
+
function existingRecordHashes(dir) {
|
|
37
|
+
try {
|
|
38
|
+
return new Set(readdirSync(dir)
|
|
39
|
+
.filter(name => name.endsWith('.json'))
|
|
40
|
+
.map(name => name.slice(0, -'.json'.length)));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// No store yet, or unreadable. Either way nothing pre-existed that this run
|
|
44
|
+
// could be wrongly credited with.
|
|
45
|
+
return new Set();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function createVerificationCollector(cwd, resolveDir = defaultFixRecordDir) {
|
|
49
|
+
const scans = [];
|
|
50
|
+
let known = new Set();
|
|
51
|
+
let begun = false;
|
|
52
|
+
return {
|
|
53
|
+
begin() {
|
|
54
|
+
known = existingRecordHashes(resolveDir());
|
|
55
|
+
begun = true;
|
|
56
|
+
},
|
|
57
|
+
observe(event) {
|
|
58
|
+
if (event.type !== 'tool_result')
|
|
59
|
+
return;
|
|
60
|
+
const coverage = asCoverage(event.metadata?.coverage);
|
|
61
|
+
if (coverage)
|
|
62
|
+
scans.push({ tool: event.name, toolCallId: event.id, coverage });
|
|
63
|
+
},
|
|
64
|
+
collect() {
|
|
65
|
+
const dir = resolveDir();
|
|
66
|
+
// Without a starting point every record in the store would look new, so a
|
|
67
|
+
// collector that was never begun reports scans only.
|
|
68
|
+
const filed = begun
|
|
69
|
+
? listFixRecords(dir, { projectId: securityProjectId(cwd) }).filter(record => !known.has(record.recordHash))
|
|
70
|
+
: [];
|
|
71
|
+
if (!scans.length && !filed.length)
|
|
72
|
+
return undefined;
|
|
73
|
+
const fixRecords = filed.map(record => ({
|
|
74
|
+
recordHash: record.recordHash,
|
|
75
|
+
path: path.join(dir, `${record.recordHash}.json`),
|
|
76
|
+
executor: record.executor,
|
|
77
|
+
assurance: record.assurance,
|
|
78
|
+
verified: record.verdict.verified,
|
|
79
|
+
coverage: { before: record.before.coverage.status, after: record.after.coverage.status },
|
|
80
|
+
}));
|
|
81
|
+
const statuses = [
|
|
82
|
+
...scans.map(scan => scan.coverage.status),
|
|
83
|
+
...fixRecords.flatMap(record => [record.coverage.before, record.coverage.after]),
|
|
84
|
+
];
|
|
85
|
+
const coverageStatus = statuses.reduce((weakest, status) => (COVERAGE_RANK[status] < COVERAGE_RANK[weakest] ? status : weakest), 'complete');
|
|
86
|
+
return { coverageStatus, scans, fixRecords };
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=verification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/harness/verification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAwDpF,wGAAwG;AACxG,MAAM,aAAa,GAA2C,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAEtG,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,0BAAgD,CAAC,QAAQ,CAAC,KAAK,CAA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AC,OAAO,CAAC,QAAQ;gBACjC,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE;aACzF,CAAC,CAAC,CAAC;YAEJ,MAAM,QAAQ,GAA6B;gBACzC,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAC1C,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;aACjF,CAAC;YACF,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CACpC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EACxF,UAAoC,CACrC,CAAC;YAEF,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where each editor keeps its MCP configuration, and what shape it expects.
|
|
3
|
+
*
|
|
4
|
+
* The shapes are not the same, and the difference is silent: VS Code keys its
|
|
5
|
+
* servers under `servers`, Cursor under `mcpServers`. Putting Cursor's key in a
|
|
6
|
+
* VS Code file produces no error and no server — the tools simply never appear,
|
|
7
|
+
* which is a bad afternoon for whoever tries it. Encoding the difference here
|
|
8
|
+
* is the point of this module.
|
|
9
|
+
*
|
|
10
|
+
* Every entry below was read from that editor's own documentation. An editor
|
|
11
|
+
* whose format could not be confirmed is deliberately absent: a wrong config is
|
|
12
|
+
* worse than none, because it fails quietly.
|
|
13
|
+
*/
|
|
14
|
+
export type McpClientId = 'cursor' | 'vscode' | 'claude-code';
|
|
15
|
+
export declare const MCP_CLIENT_IDS: McpClientId[];
|
|
16
|
+
export type McpClient = {
|
|
17
|
+
id: McpClientId;
|
|
18
|
+
name: string;
|
|
19
|
+
/** Key the servers live under in the config file. */
|
|
20
|
+
serversKey: 'servers' | 'mcpServers';
|
|
21
|
+
/** Path relative to the project root. */
|
|
22
|
+
projectPath: string;
|
|
23
|
+
/** Path relative to the user's home directory, when the editor has one. */
|
|
24
|
+
userPath?: string;
|
|
25
|
+
/** Anything the user still has to do after the file is written. */
|
|
26
|
+
followUp?: string;
|
|
27
|
+
};
|
|
28
|
+
export declare function mcpClient(id: McpClientId): McpClient;
|
|
29
|
+
export type McpInstallTarget = {
|
|
30
|
+
client: McpClient;
|
|
31
|
+
file: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function resolveInstallTarget(id: McpClientId, root: string, global: boolean): McpInstallTarget;
|
|
34
|
+
/** The server entry itself, which is the same everywhere the key is not. */
|
|
35
|
+
export declare function dvalinServerEntry(workspace: string): Record<string, unknown>;
|
|
36
|
+
export type MergeOutcome = {
|
|
37
|
+
config: Record<string, unknown>;
|
|
38
|
+
/** `added` when there was no dvalin entry, `replaced` when one was overwritten. */
|
|
39
|
+
action: 'added' | 'replaced' | 'unchanged';
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Merge the Dvalin server into whatever is already there.
|
|
43
|
+
*
|
|
44
|
+
* An editor's MCP file usually belongs to the whole team, not to this tool, so
|
|
45
|
+
* the other servers in it survive untouched and key order is preserved.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mergeDvalinServer(existing: Record<string, unknown> | undefined, client: McpClient, workspace: string, serverName?: string): MergeOutcome;
|
|
48
|
+
export declare function renderConfig(config: Record<string, unknown>): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export const MCP_CLIENT_IDS = ['cursor', 'vscode', 'claude-code'];
|
|
4
|
+
const CLIENTS = {
|
|
5
|
+
cursor: {
|
|
6
|
+
id: 'cursor',
|
|
7
|
+
name: 'Cursor',
|
|
8
|
+
serversKey: 'mcpServers',
|
|
9
|
+
projectPath: path.join('.cursor', 'mcp.json'),
|
|
10
|
+
userPath: path.join('.cursor', 'mcp.json'),
|
|
11
|
+
},
|
|
12
|
+
vscode: {
|
|
13
|
+
id: 'vscode',
|
|
14
|
+
name: 'VS Code',
|
|
15
|
+
// Not `mcpServers`. VS Code is the odd one out, and the reason this module
|
|
16
|
+
// exists rather than a single documented snippet.
|
|
17
|
+
serversKey: 'servers',
|
|
18
|
+
projectPath: path.join('.vscode', 'mcp.json'),
|
|
19
|
+
followUp: 'VS Code keeps its user-level MCP config inside the profile folder; run the "MCP: Open User Configuration" command to edit it.',
|
|
20
|
+
},
|
|
21
|
+
'claude-code': {
|
|
22
|
+
id: 'claude-code',
|
|
23
|
+
name: 'Claude Code',
|
|
24
|
+
serversKey: 'mcpServers',
|
|
25
|
+
projectPath: '.mcp.json',
|
|
26
|
+
followUp: 'A .mcp.json arriving with a repository is untrusted until approved. Run `claude` once in the project and approve it, or use `claude mcp add --scope local` for your machine only.',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export function mcpClient(id) {
|
|
30
|
+
return CLIENTS[id];
|
|
31
|
+
}
|
|
32
|
+
export function resolveInstallTarget(id, root, global) {
|
|
33
|
+
const client = mcpClient(id);
|
|
34
|
+
if (!global)
|
|
35
|
+
return { client, file: path.join(root, client.projectPath) };
|
|
36
|
+
if (!client.userPath) {
|
|
37
|
+
throw new Error(`${client.name} has no user-level file this command can write. ${client.followUp ?? ''}`.trim());
|
|
38
|
+
}
|
|
39
|
+
return { client, file: path.join(homedir(), client.userPath) };
|
|
40
|
+
}
|
|
41
|
+
/** The server entry itself, which is the same everywhere the key is not. */
|
|
42
|
+
export function dvalinServerEntry(workspace) {
|
|
43
|
+
return {
|
|
44
|
+
command: 'npx',
|
|
45
|
+
args: ['-y', 'dvalincode', 'mcp-serve', '--workspace', workspace],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Merge the Dvalin server into whatever is already there.
|
|
50
|
+
*
|
|
51
|
+
* An editor's MCP file usually belongs to the whole team, not to this tool, so
|
|
52
|
+
* the other servers in it survive untouched and key order is preserved.
|
|
53
|
+
*/
|
|
54
|
+
export function mergeDvalinServer(existing, client, workspace, serverName = 'dvalin') {
|
|
55
|
+
const config = { ...(existing ?? {}) };
|
|
56
|
+
const servers = { ...(asRecord(config[client.serversKey]) ?? {}) };
|
|
57
|
+
const entry = dvalinServerEntry(workspace);
|
|
58
|
+
const previous = servers[serverName];
|
|
59
|
+
if (previous !== undefined && JSON.stringify(previous) === JSON.stringify(entry)) {
|
|
60
|
+
return { config: { ...config, [client.serversKey]: servers }, action: 'unchanged' };
|
|
61
|
+
}
|
|
62
|
+
servers[serverName] = entry;
|
|
63
|
+
config[client.serversKey] = servers;
|
|
64
|
+
return { config, action: previous === undefined ? 'added' : 'replaced' };
|
|
65
|
+
}
|
|
66
|
+
export function renderConfig(config) {
|
|
67
|
+
return `${JSON.stringify(config, null, 2)}\n`;
|
|
68
|
+
}
|
|
69
|
+
function asRecord(value) {
|
|
70
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
71
|
+
? value
|
|
72
|
+
: undefined;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/mcp/install.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAiB7B,MAAM,CAAC,MAAM,cAAc,GAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AAejF,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U,YAAY,CAAC,MAA+B;IAC1D,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzE,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
|
package/dist/mcp/server.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Readable, Writable } from 'node:stream';
|
|
2
2
|
import { type HarnessRunExecution, type HarnessRunHooks, type HarnessRunRequest } from '../harness/run.js';
|
|
3
3
|
import type { UnattendedPermissionMode } from '../core/policy.js';
|
|
4
|
-
import { type DvalinScannerId, type DvalinScanSuiteResult } from '../remediation/scannerSuite.js';
|
|
4
|
+
import { type DvalinScannerDescriptor, type DvalinScannerId, type DvalinScanSuiteResult } from '../remediation/scannerSuite.js';
|
|
5
|
+
import { type DiffScope } from '../remediation/diffScope.js';
|
|
6
|
+
import { runWorkflowVerification } from '../security/verifyRun.js';
|
|
7
|
+
import { createSecurityWorkflow, loadSecurityWorkflow, verifySecurityWorkflow } from '../security/workflow.js';
|
|
5
8
|
import { type Session } from '../sessions/store.js';
|
|
6
9
|
type JsonRpcId = string | number | null;
|
|
7
10
|
type JsonRpcResponse = {
|
|
@@ -24,10 +27,16 @@ export type McpServerDependencies = {
|
|
|
24
27
|
runScan: (cwd: string, options: {
|
|
25
28
|
scanners?: DvalinScannerId[];
|
|
26
29
|
timeoutMs?: number;
|
|
30
|
+
scope?: DiffScope;
|
|
27
31
|
}) => Promise<DvalinScanSuiteResult>;
|
|
28
32
|
loadSession: (id: string) => Promise<Session | null>;
|
|
29
33
|
renderReport: (runId: string) => string;
|
|
30
34
|
latestRun: () => string | null;
|
|
35
|
+
createWorkflow: typeof createSecurityWorkflow;
|
|
36
|
+
loadWorkflow: typeof loadSecurityWorkflow;
|
|
37
|
+
verifyWorkflow: typeof verifySecurityWorkflow;
|
|
38
|
+
runVerification: typeof runWorkflowVerification;
|
|
39
|
+
listScanners: () => Promise<DvalinScannerDescriptor[]>;
|
|
31
40
|
};
|
|
32
41
|
export type DvalinMcpServer = {
|
|
33
42
|
handleLine(line: string): Promise<JsonRpcResponse | null>;
|