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.
Files changed (144) hide show
  1. package/README.md +261 -27
  2. package/README.zh-CN.md +203 -23
  3. package/dist/agent/compact.d.ts +8 -0
  4. package/dist/agent/compact.js +44 -5
  5. package/dist/agent/compact.js.map +1 -1
  6. package/dist/agent/loop.d.ts +5 -0
  7. package/dist/agent/loop.js +18 -9
  8. package/dist/agent/loop.js.map +1 -1
  9. package/dist/agent/runner.d.ts +15 -3
  10. package/dist/agent/runner.js +99 -9
  11. package/dist/agent/runner.js.map +1 -1
  12. package/dist/agent/session.d.ts +7 -0
  13. package/dist/agent/session.js +32 -4
  14. package/dist/agent/session.js.map +1 -1
  15. package/dist/agent/types.d.ts +5 -1
  16. package/dist/agent/types.js.map +1 -1
  17. package/dist/audit/log.d.ts +5 -1
  18. package/dist/audit/log.js.map +1 -1
  19. package/dist/cli.js +2 -0
  20. package/dist/cli.js.map +1 -1
  21. package/dist/commands/agents.d.ts +11 -0
  22. package/dist/commands/agents.js +223 -0
  23. package/dist/commands/agents.js.map +1 -0
  24. package/dist/commands/dvalin.d.ts +7 -1
  25. package/dist/commands/dvalin.js +209 -9
  26. package/dist/commands/dvalin.js.map +1 -1
  27. package/dist/commands/mcpInstall.d.ts +24 -0
  28. package/dist/commands/mcpInstall.js +62 -17
  29. package/dist/commands/mcpInstall.js.map +1 -1
  30. package/dist/commands/provider.js +6 -1
  31. package/dist/commands/provider.js.map +1 -1
  32. package/dist/commands/run.js +4 -2
  33. package/dist/commands/run.js.map +1 -1
  34. package/dist/commands/security.d.ts +15 -0
  35. package/dist/commands/security.js +273 -22
  36. package/dist/commands/security.js.map +1 -1
  37. package/dist/dvalinCli.js +2 -0
  38. package/dist/dvalinCli.js.map +1 -1
  39. package/dist/harness/run.d.ts +8 -2
  40. package/dist/harness/run.js +1 -1
  41. package/dist/harness/run.js.map +1 -1
  42. package/dist/mcp/agents.d.ts +41 -0
  43. package/dist/mcp/agents.js +129 -0
  44. package/dist/mcp/agents.js.map +1 -0
  45. package/dist/mcp/install.d.ts +43 -6
  46. package/dist/mcp/install.js +104 -1
  47. package/dist/mcp/install.js.map +1 -1
  48. package/dist/mcp/server.js +10 -2
  49. package/dist/mcp/server.js.map +1 -1
  50. package/dist/providers/anthropic.js +14 -2
  51. package/dist/providers/anthropic.js.map +1 -1
  52. package/dist/providers/openaiCompatible.js +7 -6
  53. package/dist/providers/openaiCompatible.js.map +1 -1
  54. package/dist/providers/retry.d.ts +32 -0
  55. package/dist/providers/retry.js +150 -0
  56. package/dist/providers/retry.js.map +1 -0
  57. package/dist/providers/trustedBaseUrls.js +1 -1
  58. package/dist/providers/trustedBaseUrls.js.map +1 -1
  59. package/dist/providers/types.d.ts +10 -0
  60. package/dist/remediation/automate.d.ts +1 -1
  61. package/dist/remediation/automate.js +2 -1
  62. package/dist/remediation/automate.js.map +1 -1
  63. package/dist/remediation/cases.d.ts +1 -0
  64. package/dist/remediation/cases.js +1 -0
  65. package/dist/remediation/cases.js.map +1 -1
  66. package/dist/remediation/codeQualityExport.d.ts +25 -0
  67. package/dist/remediation/codeQualityExport.js +24 -0
  68. package/dist/remediation/codeQualityExport.js.map +1 -0
  69. package/dist/remediation/codexSecurity.d.ts +54 -0
  70. package/dist/remediation/codexSecurity.js +366 -0
  71. package/dist/remediation/codexSecurity.js.map +1 -0
  72. package/dist/remediation/evasion.d.ts +61 -0
  73. package/dist/remediation/evasion.js +190 -0
  74. package/dist/remediation/evasion.js.map +1 -0
  75. package/dist/remediation/fixLoop.d.ts +255 -0
  76. package/dist/remediation/fixLoop.js +639 -0
  77. package/dist/remediation/fixLoop.js.map +1 -0
  78. package/dist/remediation/fixLoopStats.d.ts +93 -0
  79. package/dist/remediation/fixLoopStats.js +244 -0
  80. package/dist/remediation/fixLoopStats.js.map +1 -0
  81. package/dist/remediation/rebase.d.ts +44 -0
  82. package/dist/remediation/rebase.js +114 -0
  83. package/dist/remediation/rebase.js.map +1 -0
  84. package/dist/remediation/reproduce.d.ts +47 -0
  85. package/dist/remediation/reproduce.js +75 -0
  86. package/dist/remediation/reproduce.js.map +1 -0
  87. package/dist/remediation/sarif.d.ts +14 -1
  88. package/dist/remediation/sarif.js +21 -3
  89. package/dist/remediation/sarif.js.map +1 -1
  90. package/dist/remediation/scannerSuite.d.ts +52 -3
  91. package/dist/remediation/scannerSuite.js +347 -88
  92. package/dist/remediation/scannerSuite.js.map +1 -1
  93. package/dist/remediation/verify.d.ts +8 -0
  94. package/dist/remediation/verify.js +24 -11
  95. package/dist/remediation/verify.js.map +1 -1
  96. package/dist/security/config.d.ts +8 -2
  97. package/dist/security/config.js +10 -3
  98. package/dist/security/config.js.map +1 -1
  99. package/dist/security/contracts.js +15 -0
  100. package/dist/security/contracts.js.map +1 -1
  101. package/dist/security/fixRecord.d.ts +103 -8
  102. package/dist/security/fixRecord.js +113 -11
  103. package/dist/security/fixRecord.js.map +1 -1
  104. package/dist/security/fixRecordFile.d.ts +11 -2
  105. package/dist/security/fixRecordFile.js +20 -2
  106. package/dist/security/fixRecordFile.js.map +1 -1
  107. package/dist/security/fixRecordSignature.d.ts +104 -0
  108. package/dist/security/fixRecordSignature.js +227 -0
  109. package/dist/security/fixRecordSignature.js.map +1 -0
  110. package/dist/security/guardedScan.d.ts +39 -0
  111. package/dist/security/guardedScan.js +45 -0
  112. package/dist/security/guardedScan.js.map +1 -0
  113. package/dist/security/onboarding.d.ts +28 -0
  114. package/dist/security/onboarding.js +124 -0
  115. package/dist/security/onboarding.js.map +1 -0
  116. package/dist/security/reproduceInCi.d.ts +44 -0
  117. package/dist/security/reproduceInCi.js +96 -0
  118. package/dist/security/reproduceInCi.js.map +1 -0
  119. package/dist/security/reverify.d.ts +130 -0
  120. package/dist/security/reverify.js +361 -0
  121. package/dist/security/reverify.js.map +1 -0
  122. package/dist/security/suppressionGuard.d.ts +58 -0
  123. package/dist/security/suppressionGuard.js +216 -0
  124. package/dist/security/suppressionGuard.js.map +1 -0
  125. package/dist/security/verifyRun.js +14 -3
  126. package/dist/security/verifyRun.js.map +1 -1
  127. package/dist/security/workflow.d.ts +11 -1
  128. package/dist/security/workflow.js +2 -0
  129. package/dist/security/workflow.js.map +1 -1
  130. package/dist/server/routes/config.js +2 -0
  131. package/dist/server/routes/config.js.map +1 -1
  132. package/dist/server/routes/remediation.js +6 -5
  133. package/dist/server/routes/remediation.js.map +1 -1
  134. package/dist/tools/editFile.js +9 -2
  135. package/dist/tools/editFile.js.map +1 -1
  136. package/dist/tools/registry.d.ts +4 -1
  137. package/dist/tools/registry.js +29 -9
  138. package/dist/tools/registry.js.map +1 -1
  139. package/dist/tools/runSecuritySuite.d.ts +3 -0
  140. package/dist/tools/runSecuritySuite.js +2 -2
  141. package/dist/tools/runSecuritySuite.js.map +1 -1
  142. package/dist/version.d.ts +1 -1
  143. package/dist/version.js +1 -1
  144. package/package.json +1 -1
@@ -0,0 +1,227 @@
1
+ import { createPrivateKey, createPublicKey, generateKeyPairSync, sign as signBytes, verify as verifyBytes, } from 'node:crypto';
2
+ import { readFileSync } from 'node:fs';
3
+ import { canonicalJSON, sha256 } from '../audit/hash.js';
4
+ import { UsageError } from '../core/exitCodes.js';
5
+ /**
6
+ * Signatures over a Verified Fix Record.
7
+ *
8
+ * `recordHash` makes a record tamper-*evident*: anyone can recompute it, so an
9
+ * edit that leaves it stale is caught. It cannot say who issued the record. A
10
+ * party that never ran a verification can write a self-consistent record — a
11
+ * passing exit code, a matching hash, a verdict that re-derives — and offline
12
+ * re-derivation will accept it, because there is nothing in the record a
13
+ * forger could not compute.
14
+ *
15
+ * A signature answers the question re-derivation cannot: *which key vouched for
16
+ * this record.* It answers nothing more. A valid signature from a key nobody
17
+ * trusts is a fact about the file, not a reason to believe it; trust comes from
18
+ * the reader naming the keys it accepts (`--trusted-key`), typically the key
19
+ * held by the CI job that re-executed the verification itself.
20
+ *
21
+ * What is signed is the record hash, not the record. The hash already commits
22
+ * to every field, so signing it binds the signature to the whole record without
23
+ * a second canonicalization rule that two implementations could disagree on.
24
+ */
25
+ export const FIX_RECORD_SIGNATURE_CONTEXT = 'dvalin-fix-record-signature/v1';
26
+ const KEY_ID = /^sha256:[0-9a-f]{64}$/;
27
+ const PEM_BLOCK = /-----BEGIN [A-Z ]+-----[\s\S]+?-----END [A-Z ]+-----/g;
28
+ /** The exact bytes a signature covers. Domain-separated so it cannot be replayed as another Dvalin signature. */
29
+ export function signaturePayload(input) {
30
+ return Buffer.from(canonicalJSON({
31
+ context: FIX_RECORD_SIGNATURE_CONTEXT,
32
+ recordHash: input.recordHash,
33
+ keyId: input.keyId,
34
+ signedAt: input.signedAt,
35
+ }), 'utf8');
36
+ }
37
+ export function publicKeyId(key) {
38
+ return `sha256:${sha256(key.export({ type: 'spki', format: 'der' }))}`;
39
+ }
40
+ export function generateSigningKeyPair() {
41
+ const { privateKey, publicKey } = generateKeyPairSync('ed25519');
42
+ return {
43
+ privateKeyPem: privateKey.export({ type: 'pkcs8', format: 'pem' }).toString(),
44
+ publicKeyPem: publicKey.export({ type: 'spki', format: 'pem' }).toString(),
45
+ keyId: publicKeyId(publicKey),
46
+ };
47
+ }
48
+ /** Parse an Ed25519 private key from PEM text. Any other key type is refused rather than silently used. */
49
+ export function parseSigningKey(pem, source = 'signing key') {
50
+ let key;
51
+ try {
52
+ key = createPrivateKey(pem);
53
+ }
54
+ catch (error) {
55
+ throw new UsageError(`Cannot read ${source}: ${error instanceof Error ? error.message : String(error)}`);
56
+ }
57
+ if (key.asymmetricKeyType !== 'ed25519') {
58
+ throw new UsageError(`${source} is a ${key.asymmetricKeyType ?? 'non-asymmetric'} key; fix records are signed with Ed25519 only.`);
59
+ }
60
+ return key;
61
+ }
62
+ /**
63
+ * The signing key for this process, if one was configured.
64
+ *
65
+ * An explicit file wins; then `DVALIN_SIGNING_KEY` (PEM text — the shape a CI
66
+ * secret takes); then `DVALIN_SIGNING_KEY_FILE`. No key configured is not an
67
+ * error: an unsigned record is still a valid, re-derivable record.
68
+ */
69
+ export function resolveSigningKey(explicitFile, env = process.env) {
70
+ if (explicitFile)
71
+ return parseSigningKey(readKeyFile(explicitFile), explicitFile);
72
+ const inline = env.DVALIN_SIGNING_KEY?.trim();
73
+ if (inline)
74
+ return parseSigningKey(inline, 'DVALIN_SIGNING_KEY');
75
+ const file = env.DVALIN_SIGNING_KEY_FILE?.trim();
76
+ if (file)
77
+ return parseSigningKey(readKeyFile(file), file);
78
+ return undefined;
79
+ }
80
+ /**
81
+ * Resolve the signing key, then remove it from this process's environment.
82
+ *
83
+ * For any command that runs project checks before signing. Checks are the
84
+ * change under review's own code — its tests, its build — and they inherit this
85
+ * process's environment. A key left in `DVALIN_SIGNING_KEY` while they run is a
86
+ * key the reviewed change can read and use to sign whatever it likes. Taken
87
+ * into memory here, it never reaches a child process.
88
+ */
89
+ export function takeSigningKey(explicitFile, env = process.env) {
90
+ const key = resolveSigningKey(explicitFile, env);
91
+ delete env.DVALIN_SIGNING_KEY;
92
+ delete env.DVALIN_SIGNING_KEY_FILE;
93
+ return key;
94
+ }
95
+ /**
96
+ * Sign a record's hash. Returns a new record; the input is not modified.
97
+ *
98
+ * `recordHash` excludes `signatures`, so adding one does not change the hash
99
+ * and a record can carry several (an issuer's and a CI re-verifier's). A second
100
+ * signature by the same key replaces the first.
101
+ */
102
+ export function signFixRecord(record, privateKey, options = {}) {
103
+ if (privateKey.asymmetricKeyType !== 'ed25519')
104
+ throw new UsageError('Fix records are signed with Ed25519 only.');
105
+ const publicKey = createPublicKey(privateKey);
106
+ const keyId = publicKeyId(publicKey);
107
+ const signedAt = options.signedAt ?? new Date().toISOString();
108
+ const signature = {
109
+ alg: 'ed25519',
110
+ keyId,
111
+ publicKey: publicKey.export({ type: 'spki', format: 'der' }).toString('base64'),
112
+ signedAt,
113
+ signature: signBytes(null, signaturePayload({ recordHash: record.recordHash, keyId, signedAt }), privateKey).toString('base64'),
114
+ };
115
+ const others = (record.signatures ?? []).filter(existing => existing.keyId !== keyId);
116
+ return { ...record, signatures: [...others, signature] };
117
+ }
118
+ /** Check every signature a record carries against its hash, and against the reader's trusted keys. */
119
+ export function checkFixRecordSignatures(record, trustedKeys = []) {
120
+ const signatures = Array.isArray(record.signatures) ? record.signatures : [];
121
+ const trusted = new Set(trustedKeys.map(key => key.keyId));
122
+ return signatures.map((value) => {
123
+ if (!isSignatureShape(value)) {
124
+ const keyId = value && typeof value === 'object' && typeof value.keyId === 'string'
125
+ ? String(value.keyId)
126
+ : 'unknown';
127
+ return { keyId, valid: false, trusted: false, problem: 'malformed signature entry' };
128
+ }
129
+ let publicKey;
130
+ try {
131
+ publicKey = createPublicKey({ key: Buffer.from(value.publicKey, 'base64'), format: 'der', type: 'spki' });
132
+ }
133
+ catch {
134
+ return { keyId: value.keyId, signedAt: value.signedAt, valid: false, trusted: false, problem: 'public key does not parse' };
135
+ }
136
+ if (publicKey.asymmetricKeyType !== 'ed25519') {
137
+ return { keyId: value.keyId, signedAt: value.signedAt, valid: false, trusted: false, problem: 'public key is not Ed25519' };
138
+ }
139
+ // The key id is a claim too. A signature that names one key and carries
140
+ // another must not be able to borrow the named key's trust.
141
+ if (publicKeyId(publicKey) !== value.keyId) {
142
+ return { keyId: value.keyId, signedAt: value.signedAt, valid: false, trusted: false, problem: 'keyId does not match the embedded public key' };
143
+ }
144
+ let valid = false;
145
+ try {
146
+ valid = verifyBytes(null, signaturePayload({ recordHash: record.recordHash, keyId: value.keyId, signedAt: value.signedAt }), publicKey, Buffer.from(value.signature, 'base64'));
147
+ }
148
+ catch {
149
+ valid = false;
150
+ }
151
+ return {
152
+ keyId: value.keyId,
153
+ signedAt: value.signedAt,
154
+ valid,
155
+ trusted: valid && trusted.has(value.keyId),
156
+ ...(valid ? {} : { problem: 'signature does not verify against this record' }),
157
+ };
158
+ });
159
+ }
160
+ /**
161
+ * Resolve trusted-key specs into key ids.
162
+ *
163
+ * A spec is a `sha256:<hex>` key id, a path to a PEM public key, or PEM text
164
+ * (possibly several blocks — the shape an environment variable takes). The key
165
+ * id is a hash of the whole public key, so pinning the id pins the key.
166
+ */
167
+ export function resolveTrustedKeys(specs, env = process.env) {
168
+ const all = [...specs];
169
+ const fromEnv = env.DVALIN_TRUSTED_KEYS?.trim();
170
+ if (fromEnv)
171
+ all.push(fromEnv);
172
+ const keys = [];
173
+ for (const raw of all) {
174
+ const spec = raw.trim();
175
+ if (!spec)
176
+ continue;
177
+ if (spec.includes('-----BEGIN')) {
178
+ for (const block of spec.match(PEM_BLOCK) ?? [])
179
+ keys.push({ keyId: publicKeyIdFromPem(block, 'inline PEM'), source: 'inline PEM' });
180
+ continue;
181
+ }
182
+ // Env values and repeated flags may still be comma or whitespace separated.
183
+ for (const part of spec.split(/[\s,]+/).filter(Boolean)) {
184
+ if (KEY_ID.test(part))
185
+ keys.push({ keyId: part, source: part });
186
+ else
187
+ keys.push({ keyId: publicKeyIdFromPem(readKeyFile(part), part), source: part });
188
+ }
189
+ }
190
+ const seen = new Set();
191
+ return keys.filter(key => (seen.has(key.keyId) ? false : (seen.add(key.keyId), true)));
192
+ }
193
+ export function isSignatureShape(value) {
194
+ if (!value || typeof value !== 'object' || Array.isArray(value))
195
+ return false;
196
+ const signature = value;
197
+ return signature.alg === 'ed25519'
198
+ && typeof signature.keyId === 'string'
199
+ && KEY_ID.test(signature.keyId)
200
+ && typeof signature.publicKey === 'string'
201
+ && typeof signature.signedAt === 'string'
202
+ && typeof signature.signature === 'string';
203
+ }
204
+ function publicKeyIdFromPem(pem, source) {
205
+ try {
206
+ // A private key also yields its public half; accept it so a key file
207
+ // pointed at by mistake still resolves to the right id.
208
+ const key = createPublicKey(pem);
209
+ if (key.asymmetricKeyType !== 'ed25519')
210
+ throw new UsageError(`${source} is not an Ed25519 public key.`);
211
+ return publicKeyId(key);
212
+ }
213
+ catch (error) {
214
+ if (error instanceof UsageError)
215
+ throw error;
216
+ throw new UsageError(`Cannot read trusted key ${source}: ${error instanceof Error ? error.message : String(error)}`);
217
+ }
218
+ }
219
+ function readKeyFile(file) {
220
+ try {
221
+ return readFileSync(file, 'utf8');
222
+ }
223
+ catch (error) {
224
+ throw new UsageError(`Cannot read key file ${file}: ${error instanceof Error ? error.message : String(error)}`);
225
+ }
226
+ }
227
+ //# sourceMappingURL=fixRecordSignature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixRecordSignature.js","sourceRoot":"","sources":["../../src/security/fixRecordSignature.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,IAAI,IAAI,SAAS,EACjB,MAAM,IAAI,WAAW,GAEtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,gCAAgC,CAAC;AAyB7E,MAAM,MAAM,GAAG,uBAAuB,CAAC;AACvC,MAAM,SAAS,GAAG,uDAAuD,CAAC;AAE1E,iHAAiH;AACjH,MAAM,UAAU,gBAAgB,CAAC,KAA8D;IAC7F,OAAO,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC;QAC/B,OAAO,EAAE,4BAA4B;QACrC,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC,EAAE,MAAM,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAc;IACxC,OAAO,UAAU,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MA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,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,GAAG,CAAC,iBAAiB,KAAK,SAAS;YAAE,MAAM,IAAI,UAAU,CAAC,GAAG,MAAM,gCAAgC,CAAC,CAAC;QACzG,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,UAAU;YAAE,MAAM,KAAK,CAAC;QAC7C,MAAM,IAAI,UAAU,CAAC,2BAA2B,MAAM,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACvH,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,UAAU,CAAC,wBAAwB,IAAI,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAClH,CAAC;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { type EvasionSignal } from '../remediation/evasion.js';
2
+ import { runDvalinScanSuite, type DvalinScannerId, type DvalinScanSuiteResult } from '../remediation/scannerSuite.js';
3
+ import type { SecurityFindingSnapshot } from './contracts.js';
4
+ import type { FixRecordEvasion } from './fixRecord.js';
5
+ import { type SuppressionChange } from './suppressionGuard.js';
6
+ /**
7
+ * The verifying scan every surface uses, so "verified" means one thing.
8
+ *
9
+ * The fix loop and CI `reverify` already judged a change with the
10
+ * suppressions it added undone and its evasions recorded. `dvalin verify`,
11
+ * the MCP `dvalin_verify_findings` tool and single-round `--fix --verify` did
12
+ * not, so an agent adding a `.snyk` entry got "verified" from them and not from
13
+ * the loop. They all scan through here now.
14
+ *
15
+ * Needs git to know what the change is. Without it — no repository, no base —
16
+ * the scan is plain and `evasion` is `undefined`, which tells the record
17
+ * builder to issue v2: a record that says it did not evaluate evasion, rather
18
+ * than one that fails for a reason the user cannot act on.
19
+ */
20
+ export type GuardedScan = {
21
+ result: DvalinScanSuiteResult;
22
+ suppressions: SuppressionChange[];
23
+ signals: EvasionSignal[];
24
+ /** For the record: `undefined` when the change could not be determined (no git). */
25
+ evasion: FixRecordEvasion[] | undefined;
26
+ base?: string;
27
+ };
28
+ export declare function guardedScan(input: {
29
+ root: string;
30
+ /** The commit the change is measured against; `HEAD` when the work is uncommitted. */
31
+ baseCommit?: string;
32
+ scanners: DvalinScannerId[];
33
+ timeoutMs?: number;
34
+ targets: SecurityFindingSnapshot[];
35
+ exempt?: string[];
36
+ runScan?: (cwd: string, options: NonNullable<Parameters<typeof runDvalinScanSuite>[1]>) => ReturnType<typeof runDvalinScanSuite>;
37
+ }): Promise<GuardedScan>;
38
+ /** The current HEAD, for a workflow about to be changed; undefined outside a repository. */
39
+ export declare function currentHead(root: string): Promise<string | undefined>;
@@ -0,0 +1,45 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { detectEvasion, toRecordEvasion } from '../remediation/evasion.js';
4
+ import { runDvalinScanSuite } from '../remediation/scannerSuite.js';
5
+ import { detectSuppressionChanges, neutralizeSuppressions } from './suppressionGuard.js';
6
+ const execFileAsync = promisify(execFile);
7
+ export async function guardedScan(input) {
8
+ const scan = input.runScan ?? runDvalinScanSuite;
9
+ const base = await resolveBase(input.root, input.baseCommit);
10
+ if (!base) {
11
+ return { result: await scan(input.root, { scanners: input.scanners, timeoutMs: input.timeoutMs }), suppressions: [], signals: [], evasion: undefined };
12
+ }
13
+ const suppressions = await detectSuppressionChanges(input.root, base);
14
+ let result;
15
+ if (suppressions.length) {
16
+ const neutral = await neutralizeSuppressions(input.root, base, suppressions);
17
+ try {
18
+ result = await scan(neutral.root, { scanners: input.scanners, timeoutMs: input.timeoutMs });
19
+ }
20
+ finally {
21
+ await neutral.cleanup();
22
+ }
23
+ }
24
+ else {
25
+ result = await scan(input.root, { scanners: input.scanners, timeoutMs: input.timeoutMs });
26
+ }
27
+ const signals = await detectEvasion(input.root, base, input.targets, { exempt: input.exempt });
28
+ return { result, suppressions, signals, evasion: signals.map(toRecordEvasion), base };
29
+ }
30
+ /** The current HEAD, for a workflow about to be changed; undefined outside a repository. */
31
+ export async function currentHead(root) {
32
+ return resolveBase(root, 'HEAD');
33
+ }
34
+ async function resolveBase(root, ref) {
35
+ if (!ref)
36
+ return undefined;
37
+ try {
38
+ const { stdout } = await execFileAsync('git', ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`], { cwd: root });
39
+ return stdout.trim() || undefined;
40
+ }
41
+ catch {
42
+ return undefined;
43
+ }
44
+ }
45
+ //# sourceMappingURL=guardedScan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardedScan.js","sourceRoot":"","sources":["../../src/security/guardedScan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAsB,MAAM,2BAA2B,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAoD,MAAM,gCAAgC,CAAC;AAGtH,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAA0B,MAAM,uBAAuB,CAAC;AAEjH,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAyB1C,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KASjC;IACC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,IAAI,kBAAkB,CAAC;IACjD,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC7D,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C,EAAE,IAAI,EAAE,CAAC;AACxF,CAAC;AAED,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY;IAC5C,OAAO,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,IAAY,EAAE,GAAuB;IAC9D,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAC3B,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,GAAG,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QACtH,OAAO,MAAM,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { DvalinScannerId } from '../remediation/scannerSuite.js';
2
+ import type { DvalinSecurityConfig } from './config.js';
3
+ /**
4
+ * `dvalin init` as one step from "never ran it" to "it gates my merges".
5
+ *
6
+ * Every step a new project has to discover on its own — write a policy, find
7
+ * which checks prove a fix, accept the backlog it already carries, wire up CI —
8
+ * is a step where adoption stops. Init does them, writes nothing it would
9
+ * overwrite, and says what it left for a person.
10
+ */
11
+ export type CiProvider = 'github' | 'gitlab';
12
+ export declare const CI_PROVIDERS: readonly CiProvider[];
13
+ /**
14
+ * The checks this project actually has. A policy naming a check the project
15
+ * lacks yields records that say the check was skipped, so only what can run is
16
+ * named. With nothing found, `test` stays: a record with no checks is honestly
17
+ * unverifiable, and the policy shows the slot to fill.
18
+ */
19
+ export declare function detectProjectChecks(root: string): Promise<DvalinSecurityConfig['checks']>;
20
+ /** Where this repository's merges are gated, from what is already in it. */
21
+ export declare function detectCiProvider(root: string): Promise<CiProvider | undefined>;
22
+ export declare const CI_TEMPLATE_PATHS: Record<CiProvider, string>;
23
+ export declare function renderCiTemplate(provider: CiProvider, version: string, scanners: DvalinScannerId[]): string;
24
+ /** Write a CI template unless something is already there. Returns whether it wrote. */
25
+ export declare function writeCiTemplate(root: string, provider: CiProvider, version: string, scanners: DvalinScannerId[], force?: boolean): Promise<{
26
+ path: string;
27
+ written: boolean;
28
+ }>;
@@ -0,0 +1,124 @@
1
+ import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { constants } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { pickProjectCheck } from '../tools/runCheck.js';
5
+ export const CI_PROVIDERS = ['github', 'gitlab'];
6
+ const CHECK_KINDS = ['test', 'typecheck', 'build', 'lint'];
7
+ /**
8
+ * The checks this project actually has. A policy naming a check the project
9
+ * lacks yields records that say the check was skipped, so only what can run is
10
+ * named. With nothing found, `test` stays: a record with no checks is honestly
11
+ * unverifiable, and the policy shows the slot to fill.
12
+ */
13
+ export async function detectProjectChecks(root) {
14
+ const found = [];
15
+ for (const kind of CHECK_KINDS) {
16
+ if (await pickProjectCheck(root, kind, []))
17
+ found.push(kind);
18
+ }
19
+ return found.length ? found : ['test'];
20
+ }
21
+ /** Where this repository's merges are gated, from what is already in it. */
22
+ export async function detectCiProvider(root) {
23
+ if (await exists(path.join(root, '.gitlab-ci.yml')))
24
+ return 'gitlab';
25
+ if (await exists(path.join(root, '.github')))
26
+ return 'github';
27
+ try {
28
+ const config = await readFile(path.join(root, '.git', 'config'), 'utf8');
29
+ if (/url\s*=\s*\S*github\.com[:/]/i.test(config))
30
+ return 'github';
31
+ if (/url\s*=\s*\S*gitlab\./i.test(config))
32
+ return 'gitlab';
33
+ }
34
+ catch {
35
+ // Not a git checkout, or a worktree whose config lives elsewhere.
36
+ }
37
+ return undefined;
38
+ }
39
+ export const CI_TEMPLATE_PATHS = {
40
+ github: '.github/workflows/dvalin.yml',
41
+ // Never `.gitlab-ci.yml` itself: that file is the project's whole pipeline,
42
+ // so ours is a separate file the project includes.
43
+ gitlab: '.gitlab/dvalin-security.yml',
44
+ };
45
+ export function renderCiTemplate(provider, version, scanners) {
46
+ return provider === 'github' ? renderGithubWorkflow(version, scanners) : renderGitlabJob(version);
47
+ }
48
+ function renderGithubWorkflow(version, scanners) {
49
+ return `# Written by \`dvalin init\`. Findings land inline on the pull request diff
50
+ # and in the Security tab. No API key, no model, no account.
51
+ name: Dvalin security
52
+
53
+ on:
54
+ pull_request:
55
+ push:
56
+ branches: [main]
57
+
58
+ permissions:
59
+ contents: read
60
+
61
+ jobs:
62
+ dvalin:
63
+ runs-on: ubuntu-latest
64
+ permissions:
65
+ contents: read
66
+ security-events: write # publish findings to code scanning
67
+ pull-requests: write # the summary comment
68
+ steps:
69
+ - uses: actions/checkout@v5 # pin by commit digest in production
70
+ with:
71
+ fetch-depth: 0 # so the diff can reach the base commit
72
+
73
+ - uses: arthurpanhku/dvalincode@v${version}
74
+ with:
75
+ scanners: ${scanners.join(',')}
76
+ fail-on: high
77
+ # Block only what a pull request adds, not the backlog the repository
78
+ # already carried.
79
+ diff: true
80
+ comment: 'true'
81
+ `;
82
+ }
83
+ function renderGitlabJob(version) {
84
+ return `# Written by \`dvalin init\`. Add it to your pipeline from .gitlab-ci.yml:
85
+ #
86
+ # include:
87
+ # - local: .gitlab/dvalin-security.yml
88
+ #
89
+ # The gate is dvalin.security.json: new findings at or above its severity fail
90
+ # the job, the committed baseline carries the backlog. Findings appear in the
91
+ # merge request's Code Quality widget.
92
+ dvalin-security:
93
+ stage: test
94
+ image: node:22-bookworm-slim
95
+ script:
96
+ - npx -y dvalincode@${version} security scan . --sarif dvalin.sarif --gitlab-codequality gl-code-quality-report.json --no-workflow
97
+ artifacts:
98
+ when: always
99
+ reports:
100
+ codequality: gl-code-quality-report.json
101
+ paths:
102
+ - dvalin.sarif
103
+ - gl-code-quality-report.json
104
+ `;
105
+ }
106
+ /** Write a CI template unless something is already there. Returns whether it wrote. */
107
+ export async function writeCiTemplate(root, provider, version, scanners, force = false) {
108
+ const target = path.join(root, CI_TEMPLATE_PATHS[provider]);
109
+ if (!force && await exists(target))
110
+ return { path: target, written: false };
111
+ await mkdir(path.dirname(target), { recursive: true });
112
+ await writeFile(target, renderCiTemplate(provider, version, scanners), 'utf8');
113
+ return { path: target, written: true };
114
+ }
115
+ async function exists(file) {
116
+ try {
117
+ await access(file, constants.F_OK);
118
+ return true;
119
+ }
120
+ catch {
121
+ return false;
122
+ }
123
+ }
124
+ //# sourceMappingURL=onboarding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onboarding.js","sourceRoot":"","sources":["../../src/security/onboarding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAcxD,MAAM,CAAC,MAAM,YAAY,GAA0B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAExE,MAAM,WAAW,GAAmC,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAE3F;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAY;IACpD,MAAM,KAAK,GAAmC,EAAE,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,IAAI,MAAM,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACzC,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IA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AACF,CAAC;AAED,uFAAuF;AACvF,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,IAAY,EACZ,QAAoB,EACpB,OAAe,EACf,QAA2B,EAC3B,KAAK,GAAG,KAAK;IAEb,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5D,IAAI,CAAC,KAAK,IAAI,MAAM,MAAM,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5E,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,MAAM,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;IAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACzC,CAAC;AAED,KAAK,UAAU,MAAM,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { type ReproRunner } from '../remediation/reproduce.js';
2
+ import type { FixRecordReproduction } from './fixRecord.js';
3
+ /**
4
+ * Re-execute a record's reproduction where its issuer has no say.
5
+ *
6
+ * The local loop observed the tests fail on the vulnerable code and pass after
7
+ * the fix. A record saying so is a claim. This makes it happen again on the CI
8
+ * checkout: the change's code is temporarily reverted to the base commit — tests
9
+ * kept — the tests are run and must fail, the change is restored, and the same
10
+ * tests must pass.
11
+ *
12
+ * Reverting in place, rather than running in a base worktree, is deliberate. A
13
+ * fresh worktree has no installed dependencies, so every test in it fails —
14
+ * which would "confirm" any reproduction at all. The checkout CI already
15
+ * prepared has them, and only the change's own files move.
16
+ *
17
+ * Only paths that look like tests are accepted from the record, and the
18
+ * command comes from the base policy or inference, never from the record.
19
+ */
20
+ export type CiReproduction = {
21
+ status: 'confirmed' | 'not-confirmed' | 'not-attempted';
22
+ detail: string[];
23
+ command?: string;
24
+ before?: {
25
+ exitCode: number | null;
26
+ };
27
+ after?: {
28
+ exitCode: number | null;
29
+ };
30
+ tests?: Array<{
31
+ path: string;
32
+ sha256: string | null;
33
+ }>;
34
+ };
35
+ export declare function rerunReproduction(input: {
36
+ root: string;
37
+ baseCommit: string;
38
+ claimed: FixRecordReproduction;
39
+ runner: ReproRunner | undefined;
40
+ run: (command: string) => Promise<{
41
+ exitCode: number | null;
42
+ tail: string;
43
+ }>;
44
+ }): Promise<CiReproduction>;
@@ -0,0 +1,96 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { promisify } from 'node:util';
5
+ import { isTestPath } from '../remediation/evasion.js';
6
+ import { classifyReproExit, hashFiles, reproCommand } from '../remediation/reproduce.js';
7
+ const execFileAsync = promisify(execFile);
8
+ export async function rerunReproduction(input) {
9
+ if (!input.runner) {
10
+ return { status: 'not-attempted', detail: ['no reproduction runner: set `reproduce` in the base commit\'s dvalin.security.json'] };
11
+ }
12
+ // The claim is untrusted input; its shape is checked before any of it is used.
13
+ const claimedTests = input.claimed?.tests;
14
+ if (!Array.isArray(claimedTests) || claimedTests.some(test => typeof test?.path !== 'string')) {
15
+ return { status: 'not-confirmed', detail: ['the record\'s reproduction is malformed'] };
16
+ }
17
+ const paths = input.claimed.tests.map(test => test.path);
18
+ const unsafe = paths.filter(file => path.isAbsolute(file) || file.split(/[\\/]/).includes('..') || !isTestPath(file));
19
+ if (unsafe.length || !paths.length) {
20
+ return { status: 'not-confirmed', detail: [`the record names reproduction paths that are not tests in this workspace: ${unsafe.join(', ') || 'none'}`] };
21
+ }
22
+ const tests = await hashFiles(input.root, paths);
23
+ const drifted = tests.filter((test, index) => test.sha256 !== input.claimed.tests[index].sha256).map(test => test.path);
24
+ if (drifted.length) {
25
+ return { status: 'not-confirmed', detail: [`reproduction tests differ from the ones the record says failed before the fix: ${drifted.join(', ')}`], tests };
26
+ }
27
+ const command = reproCommand(input.runner.template, paths);
28
+ const testSet = new Set(paths);
29
+ const prefix = (await git(input.root, ['rev-parse', '--show-prefix'])).trim();
30
+ const entries = (await git(input.root, ['diff', '--name-status', '--no-renames', '--relative', input.baseCommit, '--', '.']))
31
+ .split('\n').filter(Boolean)
32
+ .map(line => line.split('\t'))
33
+ .filter(([, file]) => file && !testSet.has(file));
34
+ if (!entries.length) {
35
+ return { status: 'not-confirmed', detail: ['the change has no code outside the reproduction tests, so there is no fix to revert'], command, tests };
36
+ }
37
+ // What to put back, captured before anything moves.
38
+ const restore = [];
39
+ for (const [code, file] of entries) {
40
+ restore.push({ file, content: code.startsWith('D') ? null : await readFile(path.join(input.root, file)) });
41
+ }
42
+ let before;
43
+ try {
44
+ for (const [code, file] of entries) {
45
+ const target = path.join(input.root, file);
46
+ if (code.startsWith('A')) {
47
+ await rm(target, { force: true });
48
+ }
49
+ else {
50
+ const original = await gitBuffer(input.root, ['show', `${input.baseCommit}:${prefix}${file}`]);
51
+ await mkdir(path.dirname(target), { recursive: true });
52
+ await writeFile(target, original);
53
+ }
54
+ }
55
+ before = await input.run(command);
56
+ }
57
+ finally {
58
+ for (const { file, content } of restore) {
59
+ const target = path.join(input.root, file);
60
+ if (content === null)
61
+ await rm(target, { force: true });
62
+ else {
63
+ await mkdir(path.dirname(target), { recursive: true });
64
+ await writeFile(target, content);
65
+ }
66
+ }
67
+ }
68
+ const after = await input.run(command);
69
+ const beforeOutcome = classifyReproExit(input.runner, before.exitCode, before.tail);
70
+ const afterOutcome = classifyReproExit(input.runner, after.exitCode, after.tail);
71
+ const detail = [];
72
+ if (beforeOutcome !== 'failed') {
73
+ detail.push(beforeOutcome === 'passed'
74
+ ? 'the tests passed with the fix reverted, so they do not reproduce the finding'
75
+ : `with the fix reverted the tests did not reach a failing assertion (exit ${before.exitCode ?? 'none'})`);
76
+ }
77
+ if (afterOutcome !== 'passed')
78
+ detail.push(`with the fix in place the tests did not pass (exit ${after.exitCode ?? 'none'})`);
79
+ return {
80
+ status: detail.length ? 'not-confirmed' : 'confirmed',
81
+ detail,
82
+ command,
83
+ before: { exitCode: before.exitCode },
84
+ after: { exitCode: after.exitCode },
85
+ tests,
86
+ };
87
+ }
88
+ async function git(cwd, args) {
89
+ const { stdout } = await execFileAsync('git', args, { cwd, maxBuffer: 64 * 1024 * 1024 });
90
+ return stdout;
91
+ }
92
+ async function gitBuffer(cwd, args) {
93
+ const { stdout } = await execFileAsync('git', args, { cwd, maxBuffer: 64 * 1024 * 1024, encoding: 'buffer' });
94
+ return stdout;
95
+ }
96
+ //# sourceMappingURL=reproduceInCi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reproduceInCi.js","sourceRoot":"","sources":["../../src/security/reproduceInCi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAoB,MAAM,6BAA6B,CAAC;AAG3G,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AA4B1C,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAMvC;IACC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC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