返回 CodeWhale
review-main.ts
根目录 / crates / engine / extension-host / src / dsh / review-main.ts
1 /** Detached trusted offline reviewer. No HostRoot, plugin import or expression evaluation. */
2 import { reviewComposition, type ReviewedComposition } from './composition.ts'
3 import {reviewAgentPresets, type PresetReviewInput} from './agent-presets.ts'
4 import satisfies from 'semver/functions/satisfies.js'
5 import validRange from 'semver/ranges/valid.js'
6
7 try {
8 let bytes = 0
9 const chunks: Buffer[] = []
10 for await (const chunk of process.stdin) {
11 const part = Buffer.from(chunk)
12 bytes += part.length
13 if (bytes > 8 * 1024 * 1024) throw new Error('review request exceeds 8 MiB')
14 chunks.push(part)
15 }
16 const input = JSON.parse(Buffer.concat(chunks).toString('utf8')) as ReviewedComposition & { compatibility?: { range: string; version: string } }
17 const result = (input as any).kind === 'agent-presets' ? await reviewAgentPresets(input as unknown as PresetReviewInput) : reviewComposition(input)
18 let compatibility: string | undefined
19 if (input.compatibility !== undefined) {
20 const { range, version } = input.compatibility
21 if (typeof range !== 'string' || typeof version !== 'string') throw new Error('invalid compatibility request')
22 const options = { includePrerelease: true }
23 compatibility = range.trim() === '' || validRange(range, options) === null ? 'invalid' : satisfies(version, range, options) ? 'match' : 'mismatch'
24 }
25 const output = JSON.stringify(compatibility === undefined ? result : { ...result, compatibility })
26 if (Buffer.byteLength(output) > 8 * 1024 * 1024) throw new Error('review response exceeds 8 MiB')
27 process.stdout.write(output)
28 } catch {
29 // Parser diagnostics can contain source literals. Emit a source-free error.
30 process.stderr.write('DSH composition review refused invalid or oversized data.\n')
31 process.exitCode = 1
32 }
33
33 lines TYPESCRIPT