@olegkoval/agent-skills 1.82.0 → 1.83.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/adapters/claude/olko-github-pr/skills/lekker-review/references/codex-workflow.md +14 -2
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-cases.mjs +44 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-filesystem.mjs +24 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-invocation.mjs +25 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-report.mjs +29 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/boundary-source.mjs +20 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/defect-scoring.mjs +56 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/eval-runner.mjs +30 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/native-results.mjs +13 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/normalize-native-result.mjs +31 -0
- package/package.json +1 -1
- package/plugins/olko-apple-kit/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-creative/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-garmin-kit/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-git-tools/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-github-pr/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-github-pr/skills/lekker-review/references/codex-workflow.md +14 -2
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-cases.mjs +44 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-filesystem.mjs +24 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-invocation.mjs +25 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-report.mjs +29 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/boundary-source.mjs +20 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/defect-scoring.mjs +56 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/eval-runner.mjs +30 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/native-results.mjs +13 -0
- package/plugins/olko-github-pr/skills/lekker-review/scripts/normalize-native-result.mjs +31 -0
- package/plugins/olko-obsidian/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-product/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-reflection/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-release/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-skill-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-web-ops/.claude-plugin/plugin.json +1 -1
|
@@ -89,6 +89,17 @@ bounded task:
|
|
|
89
89
|
4. Write the shared result contract to
|
|
90
90
|
`<scratchpad>/codex-review-<dimension>.json`, re-read it, and return the path.
|
|
91
91
|
|
|
92
|
+
Before accepting each result, the coordinator runs the trusted installed helper:
|
|
93
|
+
`node <SKILL_ROOT>/scripts/normalize-native-result.mjs <dimension> <raw-result> <normalized-result>`.
|
|
94
|
+
Save its stdout separately; never overwrite the raw result. A successful envelope
|
|
95
|
+
contains the raw byte hash and validated `document` for downstream deduplication.
|
|
96
|
+
The helper exclusively creates `<normalized-result>` with that document on success;
|
|
97
|
+
use a fresh coordinator-assigned path. It never overwrites an existing file.
|
|
98
|
+
Inputs exceeding 8 MiB are unavailable before JSON parsing.
|
|
99
|
+
Only exact `{file,line}` location objects become `path:line` strings; ambiguous or
|
|
100
|
+
unsafe locations remain invalid. A nonzero exit or `available: false` makes the
|
|
101
|
+
review unavailable. Preserve the reason and raw output; never substitute empty findings.
|
|
102
|
+
|
|
92
103
|
For the implementation dimension, explicitly apply the root-cause-versus-
|
|
93
104
|
symptom check in `references/agents/implementation.md` to bug-fix PRs. Require
|
|
94
105
|
evidence that the reported defect remains unresolved or a contract is violated
|
|
@@ -119,10 +130,11 @@ required-dimension completion; those checks remain mandatory here.
|
|
|
119
130
|
Use `apply_patch` to write `<scratchpad>/codex-dedup-manifest.json`:
|
|
120
131
|
|
|
121
132
|
```json
|
|
122
|
-
{"dimensions":[{"name":"quality","path":"<
|
|
133
|
+
{"dimensions":[{"name":"quality","path":"<normalized quality result JSON>"}]}
|
|
123
134
|
```
|
|
124
135
|
|
|
125
|
-
Use absolute result paths
|
|
136
|
+
Use absolute normalized result paths created by the successful helper, never raw
|
|
137
|
+
reviewer files or stdout envelopes. Include every valid selected dimension, even one
|
|
126
138
|
with empty findings, in the original selected-dimension order. Use
|
|
127
139
|
coordinator-assigned names and paths, never finding-supplied attribution.
|
|
128
140
|
Keep unavailable dimensions explicitly
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
|
|
3
|
+
const hash = value => createHash('sha256').update(value).digest('hex')
|
|
4
|
+
const bytes = value => Buffer.byteLength(value, 'utf8')
|
|
5
|
+
const alphabets = Object.freeze({ ascii: 'abcdefghijklmnopqrstuvwxyz0123456789', multibyte: '界é🙂' })
|
|
6
|
+
|
|
7
|
+
function fill(length, alphabet, seed, index) {
|
|
8
|
+
const chars = [...alphabet]
|
|
9
|
+
return Array.from({ length }, (_, offset) => {
|
|
10
|
+
const value = createHash('sha256').update(`${seed}:${index}:${offset}`).digest().readUInt32BE(0)
|
|
11
|
+
return chars[value % chars.length]
|
|
12
|
+
}).join('')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function fitComponent(prefix, body, suffix, limit) {
|
|
16
|
+
if (!Number.isSafeInteger(limit) || limit < 0) throw new Error('component limit must be a nonnegative integer')
|
|
17
|
+
const room = limit - bytes(prefix) - bytes(suffix)
|
|
18
|
+
if (room < 0) return { status: 'rejected', value: null, bytes: bytes(prefix) + bytes(suffix) }
|
|
19
|
+
const chars = [...body]
|
|
20
|
+
const firstOverflow = chars.findIndex((char, index) => bytes(chars.slice(0, index + 1).join('')) > room)
|
|
21
|
+
const kept = chars.slice(0, firstOverflow < 0 ? chars.length : firstOverflow).join('')
|
|
22
|
+
const value = prefix + kept + suffix
|
|
23
|
+
return { status: bytes(value) <= limit ? 'available' : 'rejected', value: bytes(value) <= limit ? value : null, bytes: bytes(value) }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function generateBoundaryCases({ seed, limit, prefix = '', suffix = '', count = 32, kinds = ['ascii', 'multibyte'] }) {
|
|
27
|
+
if (!Number.isSafeInteger(seed) || !Number.isSafeInteger(limit) || limit < 1 || !Number.isSafeInteger(count) || count < 1 || count > 100) {
|
|
28
|
+
throw new Error('seed, positive limit, and count from 1 to 100 are required')
|
|
29
|
+
}
|
|
30
|
+
const room = Math.max(0, limit - bytes(prefix) - bytes(suffix))
|
|
31
|
+
const lengths = [...new Set([0, 1, Math.max(0, room - 1), room, room + 1, Math.max(0, room - 6), room + 6])]
|
|
32
|
+
if (!Array.isArray(kinds) || kinds.length === 0 || kinds.some(kind => !(kind in alphabets))) throw new Error('known case kinds are required')
|
|
33
|
+
return Array.from({ length: count }, (_, index) => {
|
|
34
|
+
const kind = kinds[index % kinds.length]
|
|
35
|
+
const alphabet = alphabets[kind]
|
|
36
|
+
const size = lengths[index % lengths.length]
|
|
37
|
+
const body = fill(size, alphabet, seed, index)
|
|
38
|
+
const input = body + suffix
|
|
39
|
+
const fitted = fitComponent(prefix, body, suffix, limit)
|
|
40
|
+
return Object.freeze({ id: `${kind}-${index}`, kind, input, component: fitted.value,
|
|
41
|
+
inputSha256: hash(input), componentSha256: fitted.value === null ? null : hash(fitted.value),
|
|
42
|
+
inputBytes: bytes(input), outputBytes: fitted.bytes, status: fitted.status, limit })
|
|
43
|
+
})
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
export function observeComponentLimit(parentDir) {
|
|
5
|
+
const probeDir = join(parentDir, 'limit-probe')
|
|
6
|
+
mkdirSync(probeDir)
|
|
7
|
+
const attempt = length => {
|
|
8
|
+
const path = join(probeDir, 'x'.repeat(length))
|
|
9
|
+
try { writeFileSync(path, ''); rmSync(path); return true } catch (error) {
|
|
10
|
+
if (['ENAMETOOLONG', 'EINVAL'].includes(error.code)) return false
|
|
11
|
+
throw error
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
let low = 1, high = 1024
|
|
16
|
+
if (attempt(high)) throw new Error('filesystem component limit exceeds bounded observation range')
|
|
17
|
+
while (low < high) {
|
|
18
|
+
const middle = Math.ceil((low + high) / 2)
|
|
19
|
+
if (attempt(middle)) low = middle
|
|
20
|
+
else high = middle - 1
|
|
21
|
+
}
|
|
22
|
+
return low
|
|
23
|
+
} finally { rmSync(probeDir, { recursive: true, force: true }) }
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { join, resolve } from 'node:path'
|
|
5
|
+
|
|
6
|
+
const sha256 = value => createHash('sha256').update(value).digest('hex')
|
|
7
|
+
|
|
8
|
+
export function runTrustedCli({ source, target, repoSlug, outputDir, id, timeoutMs = 5000 }) {
|
|
9
|
+
const dir = resolve(outputDir, id)
|
|
10
|
+
const home = join(dir, 'home'), state = join(dir, 'state'), scripts = join(dir, 'scripts')
|
|
11
|
+
mkdirSync(home, { recursive: true }); mkdirSync(state, { recursive: true }); mkdirSync(scripts, { recursive: true })
|
|
12
|
+
const cli = join(scripts, 'run-log.mjs')
|
|
13
|
+
writeFileSync(cli, source.bytes)
|
|
14
|
+
const child = spawnSync(process.execPath, [cli, 'start', '--repo', `trusted/${repoSlug}`, '--target', target,
|
|
15
|
+
'--mode', 'branch', '--depth', 'scan', '--engine', 'workflow', '--host', 'codex'], {
|
|
16
|
+
cwd: dir, env: { HOME: home, LEKKER_STATE_DIR: state, TMPDIR: dir, PATH: '/usr/bin:/bin' }, encoding: 'buffer', timeout: timeoutMs,
|
|
17
|
+
})
|
|
18
|
+
const stdout = child.stdout ?? Buffer.alloc(0), stderr = child.stderr ?? Buffer.alloc(0)
|
|
19
|
+
writeFileSync(join(dir, 'stdout.raw'), stdout); writeFileSync(join(dir, 'stderr.raw'), stderr)
|
|
20
|
+
const exitClass = child.status === 0 ? 'success'
|
|
21
|
+
: child.status === 1 && stderr.toString('utf8').includes('ENAMETOOLONG') ? 'component-limit' : 'unexpected'
|
|
22
|
+
return { status: child.error?.code === 'ETIMEDOUT' ? 'timeout' : child.error || child.signal ? 'unavailable' : 'observed',
|
|
23
|
+
exitCode: child.status, signal: child.signal ?? null, stdoutSha256: sha256(stdout), stderrSha256: sha256(stderr),
|
|
24
|
+
stdoutFile: `${id}/stdout.raw`, stderrFile: `${id}/stderr.raw`, errorCode: child.error?.code ?? null, exitClass }
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function isCandidate(row) {
|
|
2
|
+
const original = row.runs?.original, defective = row.runs?.defective, repaired = row.runs?.repaired
|
|
3
|
+
return original?.status === 'observed' && defective?.status === 'observed'
|
|
4
|
+
&& original.exitClass === 'success' && defective.exitClass === 'component-limit'
|
|
5
|
+
&& (!repaired || repaired.status === 'observed' && repaired.exitCode === 0)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function assembleBoundaryReport({ source, provenance, seed, componentLimit, prefixSha256, suffixSha256,
|
|
9
|
+
cases, results, shrinkResults, outputDir, reduced }) {
|
|
10
|
+
const allResults = [...results, ...shrinkResults]
|
|
11
|
+
const candidates = allResults.filter(isCandidate).map(row => ({ id: row.id, input: row.input,
|
|
12
|
+
evidenceClass: 'composed trusted CLI probe', inputSha256: row.inputSha256,
|
|
13
|
+
outcomes: Object.fromEntries(Object.entries(row.runs).map(([role, result]) => [role, result.exitCode])) }))
|
|
14
|
+
const roles = ['original', 'defective', ...(provenance?.sources?.repaired ? ['repaired'] : [])]
|
|
15
|
+
const incomplete = results.length !== cases.length || allResults.length > 100
|
|
16
|
+
|| allResults.some(row => row.status !== 'available' || roles.some(role => !row.runs?.[role])
|
|
17
|
+
|| Object.values(row.runs).some(run => run?.status !== 'observed'
|
|
18
|
+
|| run.exitClass === 'unexpected'))
|
|
19
|
+
return { schema: 1, status: incomplete ? 'unavailable' : 'available', reason: incomplete ? 'timeout, unexpected exit, or incomplete invocation coverage' : null,
|
|
20
|
+
source, provenance, seed, contract: { maxComponentBytes: componentLimit, count: allResults.length,
|
|
21
|
+
validInput: 'nonempty ASCII target slug [a-z0-9-]+; run-log start arguments fixed by adapter',
|
|
22
|
+
prefixSha256, suffixSha256 },
|
|
23
|
+
artifactRoot: outputDir, results: allResults, candidates, reducedCounterexample: reduced ? {
|
|
24
|
+
id: reduced.id, input: reduced.input, inputSha256: reduced.inputSha256,
|
|
25
|
+
method: 'bounded binary search over ASCII prefix lengths',
|
|
26
|
+
scope: 'reduced counterexample; not a proof of global minimality',
|
|
27
|
+
outcomes: Object.fromEntries(Object.entries(reduced.runs).map(([role, result]) => [role, result.exitCode])),
|
|
28
|
+
} : null }
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
|
|
4
|
+
export const RUN_LOG_SOURCE = 'plugins/olko-github-pr/skills/lekker-review/scripts/run-log.mjs'
|
|
5
|
+
const gitEnv = { PATH: '/usr/bin:/bin', HOME: '/nonexistent', GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null' }
|
|
6
|
+
|
|
7
|
+
export function readTrustedSource(root, commit) {
|
|
8
|
+
if (!/^[a-f0-9]{40}$/.test(commit ?? '')) throw new Error('trusted source needs an exact commit SHA')
|
|
9
|
+
let resolved
|
|
10
|
+
try {
|
|
11
|
+
resolved = execFileSync('git', ['--no-replace-objects', '-C', root, 'rev-parse', '--verify', `${commit}^{commit}`], {
|
|
12
|
+
encoding: 'utf8', env: gitEnv, stdio: ['ignore', 'pipe', 'ignore'],
|
|
13
|
+
}).trim()
|
|
14
|
+
} catch { throw new Error('trusted commit is unavailable') }
|
|
15
|
+
if (resolved !== commit) throw new Error('trusted commit did not resolve exactly')
|
|
16
|
+
let bytes
|
|
17
|
+
try { bytes = execFileSync('git', ['--no-replace-objects', '-C', root, 'show', `${resolved}:${RUN_LOG_SOURCE}`], { env: gitEnv, stdio: ['ignore', 'pipe', 'ignore'] }) }
|
|
18
|
+
catch { throw new Error('trusted CLI source is unavailable at the pinned commit') }
|
|
19
|
+
return { commit: resolved, bytes, sha256: createHash('sha256').update(bytes).digest('hex') }
|
|
20
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Score already-validated defect evidence without reading files or observing time.
|
|
2
|
+
import { validateDefectEvaluation, validateDefectManifest } from './defect-policy.mjs'
|
|
3
|
+
|
|
4
|
+
const requireEvaluations = value => {
|
|
5
|
+
if (!Array.isArray(value)) throw new Error('evaluations must be an array')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function scoreEvaluation(manifest, registry, evaluations, evaluation, index) {
|
|
9
|
+
const previousRunIds = evaluations.slice(0, index).map(item => item?.run?.runId)
|
|
10
|
+
const checked = validateDefectEvaluation(manifest, evaluation, evaluation?.findingsSha256, previousRunIds)
|
|
11
|
+
if (!checked.valid) return { available: false, reason: checked.reason, caseId: checked.caseId, index }
|
|
12
|
+
const { runId, caseId, testCase, decisions } = checked
|
|
13
|
+
const confirmed = decisions.filter(item => item.verdict === 'confirmed').map(item => item.defectId)
|
|
14
|
+
const unique = confirmed.filter((id, itemIndex, all) => all.indexOf(id) === itemIndex)
|
|
15
|
+
const known = unique.filter(id => registry.defectIds.includes(id))
|
|
16
|
+
const unknown = unique.filter(id => !registry.defectIds.includes(id))
|
|
17
|
+
const unexpected = unique.filter(id => !testCase.expectedDefects.includes(id))
|
|
18
|
+
const unresolved = decisions.filter(item => item.verdict === 'unresolved').length
|
|
19
|
+
const needsAdjudication = unexpected.length > 0
|
|
20
|
+
return { available: unresolved === 0 && !needsAdjudication,
|
|
21
|
+
reason: unresolved ? 'unresolved adjudication' : needsAdjudication ? 'confirmed defect outside case contract needs corpus adjudication' : null,
|
|
22
|
+
caseId, runId, expected: testCase.expectedDefects, knownConfirmed: known, unknownConfirmed: unknown,
|
|
23
|
+
unexpectedConfirmed: unexpected, confirmedClaims: confirmed.length,
|
|
24
|
+
falseAlarms: decisions.filter(item => item.verdict === 'false-alarm').length,
|
|
25
|
+
unresolved, judged: unresolved === 0, clean: testCase.expectedDefects.length === 0, needsAdjudication }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function summarize(manifest, rows) {
|
|
29
|
+
const ready = rows.filter(row => row.available)
|
|
30
|
+
const judged = rows.filter(row => row.judged)
|
|
31
|
+
const coverageComplete = manifest.cases.every(testCase => rows.filter(row => row.available && row.caseId === testCase.id).length === testCase.expectedRuns)
|
|
32
|
+
&& rows.every(row => row.available)
|
|
33
|
+
const expected = ready.reduce((count, row) => count + row.expected.length, 0)
|
|
34
|
+
const detected = ready.reduce((count, row) => count + row.knownConfirmed.filter(id => row.expected.includes(id)).length, 0)
|
|
35
|
+
const confirmedClaims = judged.reduce((count, row) => count + row.confirmedClaims, 0)
|
|
36
|
+
const uniqueConfirmed = judged.reduce((count, row) => count + row.knownConfirmed.length + row.unknownConfirmed.length, 0)
|
|
37
|
+
const falseAlarms = judged.reduce((count, row) => count + row.falseAlarms, 0)
|
|
38
|
+
const cleanRows = ready.filter(row => row.clean)
|
|
39
|
+
return { available: coverageComplete, coverageComplete, recall: coverageComplete && expected ? detected / expected : null,
|
|
40
|
+
precision: confirmedClaims + falseAlarms ? confirmedClaims / (confirmedClaims + falseAlarms) : null,
|
|
41
|
+
falseAlarms, falseAlarmsPerReview: judged.length ? falseAlarms / judged.length : null,
|
|
42
|
+
cleanAlarmRate: cleanRows.length ? cleanRows.filter(row => row.falseAlarms > 0).length / cleanRows.length : null,
|
|
43
|
+
unresolved: rows.reduce((count, row) => count + (row.unresolved || 0), 0), expectedDefects: expected,
|
|
44
|
+
confirmedExpected: judged.reduce((count, row) => count + row.knownConfirmed.filter(id => row.expected.includes(id)).length, 0),
|
|
45
|
+
confirmedUnexpected: rows.reduce((count, row) => count + (row.unexpectedConfirmed || []).length, 0),
|
|
46
|
+
confirmedUnknown: rows.reduce((count, row) => count + (row.unknownConfirmed || []).length, 0),
|
|
47
|
+
confirmedClaims, uniqueConfirmedDefects: uniqueConfirmed, scoredRuns: ready.length,
|
|
48
|
+
distinctCases: rows.filter((row, index) => row.caseId && rows.findIndex(prior => prior.caseId === row.caseId) === index).length,
|
|
49
|
+
needsAdjudication: rows.some(row => row.needsAdjudication), rows }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function scoreDefectCorpus(manifest, evaluations) {
|
|
53
|
+
const registry = validateDefectManifest(manifest)
|
|
54
|
+
requireEvaluations(evaluations)
|
|
55
|
+
return summarize(manifest, evaluations.map((item, index) => scoreEvaluation(manifest, registry, evaluations, item, index)))
|
|
56
|
+
}
|
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
// verdict-affecting finding (critical or important) is a false positive.
|
|
22
22
|
|
|
23
23
|
import { readFileSync } from 'node:fs';
|
|
24
|
+
import { createHash } from 'node:crypto';
|
|
24
25
|
import { join } from 'node:path';
|
|
25
26
|
import { fileURLToPath } from 'node:url';
|
|
27
|
+
import { scoreDefectCorpus } from './defect-scoring.mjs';
|
|
26
28
|
|
|
27
29
|
export const LINE_WINDOW = 10;
|
|
28
30
|
const BLOCKING = new Set(['critical', 'important']);
|
|
@@ -174,6 +176,34 @@ export function score(manifest, results) {
|
|
|
174
176
|
|
|
175
177
|
function main(argv) {
|
|
176
178
|
const flag = (n) => { const i = argv.indexOf('--' + n); return i === -1 ? null : argv[i + 1]; };
|
|
179
|
+
if (argv.includes('--defects')) {
|
|
180
|
+
const manifestPath = flag('manifest'), resultsPath = flag('results'), adjudicationPath = flag('adjudication');
|
|
181
|
+
if (!manifestPath || !resultsPath || !adjudicationPath || [manifestPath, resultsPath, adjudicationPath].some(value => value.startsWith('--'))) {
|
|
182
|
+
console.error('usage: eval-runner.mjs --defects --manifest <manifest.json> --results <defect-runs.json> --adjudication <adjudication.json> [--json]');
|
|
183
|
+
process.exitCode = 2; return;
|
|
184
|
+
}
|
|
185
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
186
|
+
const results = JSON.parse(readFileSync(resultsPath, 'utf8'));
|
|
187
|
+
const adjudication = JSON.parse(readFileSync(adjudicationPath, 'utf8'));
|
|
188
|
+
const evaluations = Array.isArray(results.runs) ? results.runs.map(run => {
|
|
189
|
+
const matches = Array.isArray(adjudication.evaluations)
|
|
190
|
+
? adjudication.evaluations.filter(item => item?.runId === run?.runId) : [];
|
|
191
|
+
const bytes = typeof run?.findingsBytes === 'string' ? Buffer.from(run.findingsBytes, 'utf8') : Buffer.alloc(0);
|
|
192
|
+
let findings = null;
|
|
193
|
+
try { findings = JSON.parse(bytes.toString('utf8')); } catch { /* scorer marks malformed evidence unavailable */ }
|
|
194
|
+
return { run: { ...run, findings }, adjudication: matches.length === 1 ? matches[0] : null,
|
|
195
|
+
findingsSha256: createHash('sha256').update(bytes).digest('hex') };
|
|
196
|
+
}) : [];
|
|
197
|
+
const out = scoreDefectCorpus(manifest, evaluations);
|
|
198
|
+
if (argv.includes('--json')) console.log(JSON.stringify(out));
|
|
199
|
+
else {
|
|
200
|
+
const pct = value => value === null ? 'n/a' : `${Math.round(value * 100)}%`;
|
|
201
|
+
console.log(`defect evaluation ${out.available ? 'complete' : 'unavailable'}: recall ${pct(out.recall)}, precision ${pct(out.precision)}, false alarms ${out.falseAlarms}, unresolved ${out.unresolved}, distinct cases ${out.distinctCases}`);
|
|
202
|
+
}
|
|
203
|
+
if (!out.coverageComplete || !out.available) process.exitCode = 1;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
console.error('legacy heuristic mode: location-only scoring; use --defects for adjudicated scoring');
|
|
177
207
|
const results = flag('results');
|
|
178
208
|
const archiveIndex = argv.indexOf('--archive');
|
|
179
209
|
const archive = archiveIndex === -1 ? null : argv[archiveIndex + 1];
|
|
@@ -7,6 +7,19 @@ const instances = /^(?!\/)(?!.*\\)(?![A-Za-z]:)(?!(?:.*\/)?\.\.(?:\/|:)).+:[1-9]
|
|
|
7
7
|
const ruleException = /^(PROJECT:[a-z0-9]+(-[a-z0-9]+)*|weakens-project-rule)$/
|
|
8
8
|
const dimensions = ['deps', 'triage-quality', 'triage-logic', 'quality', 'implementation', 'simplification', 'conventions', 'test-quality', 'project-rules']
|
|
9
9
|
|
|
10
|
+
/** Canonicalize location objects without altering or replacing the raw document. */
|
|
11
|
+
export function normalizeNativeResult(dimension, document) {
|
|
12
|
+
const location = value => record(value) && Object.keys(value).length === 2
|
|
13
|
+
&& typeof value.file === 'string' && !/[\x00-\x1f\x7f:]/.test(value.file)
|
|
14
|
+
&& Number.isSafeInteger(value.line) && value.line > 0
|
|
15
|
+
&& instances.test(`${value.file}:${value.line}`) ? `${value.file}:${value.line}` : value
|
|
16
|
+
const normalized = record(document) && Array.isArray(document.findings)
|
|
17
|
+
? { ...document, findings: Array.from(document.findings, finding => record(finding) && Array.isArray(finding.otherInstances)
|
|
18
|
+
? { ...finding, otherInstances: Array.from(finding.otherInstances, location) } : finding) } : document
|
|
19
|
+
const validation = validateNativeResult(dimension, normalized)
|
|
20
|
+
return { ...validation, document: validation.available ? normalized : null }
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
function validBoundary(value) {
|
|
11
24
|
return record(value) && text(value.entryPoint) && text(value.consumer)
|
|
12
25
|
&& optionalStrings(value, ['decisionPoint', 'realizationPoint', 'stateOwner', 'evidenceClass'])
|
package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/normalize-native-result.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { openSync, readSync, closeSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { normalizeNativeResult } from './native-results.mjs'
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const [dimension, input, output, ...extra] = process.argv.slice(2)
|
|
8
|
+
if (!dimension || !input || extra.length) throw new Error('invalid arguments')
|
|
9
|
+
const limit = 8 * 1024 * 1024, buffer = Buffer.alloc(limit + 1)
|
|
10
|
+
const fd = openSync(input, 'r')
|
|
11
|
+
let length = 0
|
|
12
|
+
try {
|
|
13
|
+
while (length < buffer.length) {
|
|
14
|
+
const count = readSync(fd, buffer, length, buffer.length - length, null)
|
|
15
|
+
if (!count) break
|
|
16
|
+
length += count
|
|
17
|
+
}
|
|
18
|
+
} finally { closeSync(fd) }
|
|
19
|
+
if (length > limit) {
|
|
20
|
+
console.log(JSON.stringify({ available: false, dimension, reason: 'raw reviewer result exceeds 8 MiB', document: null }))
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
23
|
+
const raw = buffer.subarray(0, length)
|
|
24
|
+
const result = normalizeNativeResult(dimension, JSON.parse(raw.toString('utf8')))
|
|
25
|
+
if (result.available && output) writeFileSync(output, JSON.stringify(result.document), { flag: 'wx' })
|
|
26
|
+
console.log(JSON.stringify({ ...result, rawSha256: createHash('sha256').update(raw).digest('hex') }))
|
|
27
|
+
if (!result.available) process.exitCode = 1
|
|
28
|
+
} catch {
|
|
29
|
+
console.log(JSON.stringify({ available: false, reason: 'raw reviewer result missing or malformed', document: null }))
|
|
30
|
+
process.exitCode = 1
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -89,6 +89,17 @@ bounded task:
|
|
|
89
89
|
4. Write the shared result contract to
|
|
90
90
|
`<scratchpad>/codex-review-<dimension>.json`, re-read it, and return the path.
|
|
91
91
|
|
|
92
|
+
Before accepting each result, the coordinator runs the trusted installed helper:
|
|
93
|
+
`node <SKILL_ROOT>/scripts/normalize-native-result.mjs <dimension> <raw-result> <normalized-result>`.
|
|
94
|
+
Save its stdout separately; never overwrite the raw result. A successful envelope
|
|
95
|
+
contains the raw byte hash and validated `document` for downstream deduplication.
|
|
96
|
+
The helper exclusively creates `<normalized-result>` with that document on success;
|
|
97
|
+
use a fresh coordinator-assigned path. It never overwrites an existing file.
|
|
98
|
+
Inputs exceeding 8 MiB are unavailable before JSON parsing.
|
|
99
|
+
Only exact `{file,line}` location objects become `path:line` strings; ambiguous or
|
|
100
|
+
unsafe locations remain invalid. A nonzero exit or `available: false` makes the
|
|
101
|
+
review unavailable. Preserve the reason and raw output; never substitute empty findings.
|
|
102
|
+
|
|
92
103
|
For the implementation dimension, explicitly apply the root-cause-versus-
|
|
93
104
|
symptom check in `references/agents/implementation.md` to bug-fix PRs. Require
|
|
94
105
|
evidence that the reported defect remains unresolved or a contract is violated
|
|
@@ -119,10 +130,11 @@ required-dimension completion; those checks remain mandatory here.
|
|
|
119
130
|
Use `apply_patch` to write `<scratchpad>/codex-dedup-manifest.json`:
|
|
120
131
|
|
|
121
132
|
```json
|
|
122
|
-
{"dimensions":[{"name":"quality","path":"<
|
|
133
|
+
{"dimensions":[{"name":"quality","path":"<normalized quality result JSON>"}]}
|
|
123
134
|
```
|
|
124
135
|
|
|
125
|
-
Use absolute result paths
|
|
136
|
+
Use absolute normalized result paths created by the successful helper, never raw
|
|
137
|
+
reviewer files or stdout envelopes. Include every valid selected dimension, even one
|
|
126
138
|
with empty findings, in the original selected-dimension order. Use
|
|
127
139
|
coordinator-assigned names and paths, never finding-supplied attribution.
|
|
128
140
|
Keep unavailable dimensions explicitly
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
|
|
3
|
+
const hash = value => createHash('sha256').update(value).digest('hex')
|
|
4
|
+
const bytes = value => Buffer.byteLength(value, 'utf8')
|
|
5
|
+
const alphabets = Object.freeze({ ascii: 'abcdefghijklmnopqrstuvwxyz0123456789', multibyte: '界é🙂' })
|
|
6
|
+
|
|
7
|
+
function fill(length, alphabet, seed, index) {
|
|
8
|
+
const chars = [...alphabet]
|
|
9
|
+
return Array.from({ length }, (_, offset) => {
|
|
10
|
+
const value = createHash('sha256').update(`${seed}:${index}:${offset}`).digest().readUInt32BE(0)
|
|
11
|
+
return chars[value % chars.length]
|
|
12
|
+
}).join('')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function fitComponent(prefix, body, suffix, limit) {
|
|
16
|
+
if (!Number.isSafeInteger(limit) || limit < 0) throw new Error('component limit must be a nonnegative integer')
|
|
17
|
+
const room = limit - bytes(prefix) - bytes(suffix)
|
|
18
|
+
if (room < 0) return { status: 'rejected', value: null, bytes: bytes(prefix) + bytes(suffix) }
|
|
19
|
+
const chars = [...body]
|
|
20
|
+
const firstOverflow = chars.findIndex((char, index) => bytes(chars.slice(0, index + 1).join('')) > room)
|
|
21
|
+
const kept = chars.slice(0, firstOverflow < 0 ? chars.length : firstOverflow).join('')
|
|
22
|
+
const value = prefix + kept + suffix
|
|
23
|
+
return { status: bytes(value) <= limit ? 'available' : 'rejected', value: bytes(value) <= limit ? value : null, bytes: bytes(value) }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function generateBoundaryCases({ seed, limit, prefix = '', suffix = '', count = 32, kinds = ['ascii', 'multibyte'] }) {
|
|
27
|
+
if (!Number.isSafeInteger(seed) || !Number.isSafeInteger(limit) || limit < 1 || !Number.isSafeInteger(count) || count < 1 || count > 100) {
|
|
28
|
+
throw new Error('seed, positive limit, and count from 1 to 100 are required')
|
|
29
|
+
}
|
|
30
|
+
const room = Math.max(0, limit - bytes(prefix) - bytes(suffix))
|
|
31
|
+
const lengths = [...new Set([0, 1, Math.max(0, room - 1), room, room + 1, Math.max(0, room - 6), room + 6])]
|
|
32
|
+
if (!Array.isArray(kinds) || kinds.length === 0 || kinds.some(kind => !(kind in alphabets))) throw new Error('known case kinds are required')
|
|
33
|
+
return Array.from({ length: count }, (_, index) => {
|
|
34
|
+
const kind = kinds[index % kinds.length]
|
|
35
|
+
const alphabet = alphabets[kind]
|
|
36
|
+
const size = lengths[index % lengths.length]
|
|
37
|
+
const body = fill(size, alphabet, seed, index)
|
|
38
|
+
const input = body + suffix
|
|
39
|
+
const fitted = fitComponent(prefix, body, suffix, limit)
|
|
40
|
+
return Object.freeze({ id: `${kind}-${index}`, kind, input, component: fitted.value,
|
|
41
|
+
inputSha256: hash(input), componentSha256: fitted.value === null ? null : hash(fitted.value),
|
|
42
|
+
inputBytes: bytes(input), outputBytes: fitted.bytes, status: fitted.status, limit })
|
|
43
|
+
})
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
export function observeComponentLimit(parentDir) {
|
|
5
|
+
const probeDir = join(parentDir, 'limit-probe')
|
|
6
|
+
mkdirSync(probeDir)
|
|
7
|
+
const attempt = length => {
|
|
8
|
+
const path = join(probeDir, 'x'.repeat(length))
|
|
9
|
+
try { writeFileSync(path, ''); rmSync(path); return true } catch (error) {
|
|
10
|
+
if (['ENAMETOOLONG', 'EINVAL'].includes(error.code)) return false
|
|
11
|
+
throw error
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
let low = 1, high = 1024
|
|
16
|
+
if (attempt(high)) throw new Error('filesystem component limit exceeds bounded observation range')
|
|
17
|
+
while (low < high) {
|
|
18
|
+
const middle = Math.ceil((low + high) / 2)
|
|
19
|
+
if (attempt(middle)) low = middle
|
|
20
|
+
else high = middle - 1
|
|
21
|
+
}
|
|
22
|
+
return low
|
|
23
|
+
} finally { rmSync(probeDir, { recursive: true, force: true }) }
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { join, resolve } from 'node:path'
|
|
5
|
+
|
|
6
|
+
const sha256 = value => createHash('sha256').update(value).digest('hex')
|
|
7
|
+
|
|
8
|
+
export function runTrustedCli({ source, target, repoSlug, outputDir, id, timeoutMs = 5000 }) {
|
|
9
|
+
const dir = resolve(outputDir, id)
|
|
10
|
+
const home = join(dir, 'home'), state = join(dir, 'state'), scripts = join(dir, 'scripts')
|
|
11
|
+
mkdirSync(home, { recursive: true }); mkdirSync(state, { recursive: true }); mkdirSync(scripts, { recursive: true })
|
|
12
|
+
const cli = join(scripts, 'run-log.mjs')
|
|
13
|
+
writeFileSync(cli, source.bytes)
|
|
14
|
+
const child = spawnSync(process.execPath, [cli, 'start', '--repo', `trusted/${repoSlug}`, '--target', target,
|
|
15
|
+
'--mode', 'branch', '--depth', 'scan', '--engine', 'workflow', '--host', 'codex'], {
|
|
16
|
+
cwd: dir, env: { HOME: home, LEKKER_STATE_DIR: state, TMPDIR: dir, PATH: '/usr/bin:/bin' }, encoding: 'buffer', timeout: timeoutMs,
|
|
17
|
+
})
|
|
18
|
+
const stdout = child.stdout ?? Buffer.alloc(0), stderr = child.stderr ?? Buffer.alloc(0)
|
|
19
|
+
writeFileSync(join(dir, 'stdout.raw'), stdout); writeFileSync(join(dir, 'stderr.raw'), stderr)
|
|
20
|
+
const exitClass = child.status === 0 ? 'success'
|
|
21
|
+
: child.status === 1 && stderr.toString('utf8').includes('ENAMETOOLONG') ? 'component-limit' : 'unexpected'
|
|
22
|
+
return { status: child.error?.code === 'ETIMEDOUT' ? 'timeout' : child.error || child.signal ? 'unavailable' : 'observed',
|
|
23
|
+
exitCode: child.status, signal: child.signal ?? null, stdoutSha256: sha256(stdout), stderrSha256: sha256(stderr),
|
|
24
|
+
stdoutFile: `${id}/stdout.raw`, stderrFile: `${id}/stderr.raw`, errorCode: child.error?.code ?? null, exitClass }
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function isCandidate(row) {
|
|
2
|
+
const original = row.runs?.original, defective = row.runs?.defective, repaired = row.runs?.repaired
|
|
3
|
+
return original?.status === 'observed' && defective?.status === 'observed'
|
|
4
|
+
&& original.exitClass === 'success' && defective.exitClass === 'component-limit'
|
|
5
|
+
&& (!repaired || repaired.status === 'observed' && repaired.exitCode === 0)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function assembleBoundaryReport({ source, provenance, seed, componentLimit, prefixSha256, suffixSha256,
|
|
9
|
+
cases, results, shrinkResults, outputDir, reduced }) {
|
|
10
|
+
const allResults = [...results, ...shrinkResults]
|
|
11
|
+
const candidates = allResults.filter(isCandidate).map(row => ({ id: row.id, input: row.input,
|
|
12
|
+
evidenceClass: 'composed trusted CLI probe', inputSha256: row.inputSha256,
|
|
13
|
+
outcomes: Object.fromEntries(Object.entries(row.runs).map(([role, result]) => [role, result.exitCode])) }))
|
|
14
|
+
const roles = ['original', 'defective', ...(provenance?.sources?.repaired ? ['repaired'] : [])]
|
|
15
|
+
const incomplete = results.length !== cases.length || allResults.length > 100
|
|
16
|
+
|| allResults.some(row => row.status !== 'available' || roles.some(role => !row.runs?.[role])
|
|
17
|
+
|| Object.values(row.runs).some(run => run?.status !== 'observed'
|
|
18
|
+
|| run.exitClass === 'unexpected'))
|
|
19
|
+
return { schema: 1, status: incomplete ? 'unavailable' : 'available', reason: incomplete ? 'timeout, unexpected exit, or incomplete invocation coverage' : null,
|
|
20
|
+
source, provenance, seed, contract: { maxComponentBytes: componentLimit, count: allResults.length,
|
|
21
|
+
validInput: 'nonempty ASCII target slug [a-z0-9-]+; run-log start arguments fixed by adapter',
|
|
22
|
+
prefixSha256, suffixSha256 },
|
|
23
|
+
artifactRoot: outputDir, results: allResults, candidates, reducedCounterexample: reduced ? {
|
|
24
|
+
id: reduced.id, input: reduced.input, inputSha256: reduced.inputSha256,
|
|
25
|
+
method: 'bounded binary search over ASCII prefix lengths',
|
|
26
|
+
scope: 'reduced counterexample; not a proof of global minimality',
|
|
27
|
+
outcomes: Object.fromEntries(Object.entries(reduced.runs).map(([role, result]) => [role, result.exitCode])),
|
|
28
|
+
} : null }
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
|
|
4
|
+
export const RUN_LOG_SOURCE = 'plugins/olko-github-pr/skills/lekker-review/scripts/run-log.mjs'
|
|
5
|
+
const gitEnv = { PATH: '/usr/bin:/bin', HOME: '/nonexistent', GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null' }
|
|
6
|
+
|
|
7
|
+
export function readTrustedSource(root, commit) {
|
|
8
|
+
if (!/^[a-f0-9]{40}$/.test(commit ?? '')) throw new Error('trusted source needs an exact commit SHA')
|
|
9
|
+
let resolved
|
|
10
|
+
try {
|
|
11
|
+
resolved = execFileSync('git', ['--no-replace-objects', '-C', root, 'rev-parse', '--verify', `${commit}^{commit}`], {
|
|
12
|
+
encoding: 'utf8', env: gitEnv, stdio: ['ignore', 'pipe', 'ignore'],
|
|
13
|
+
}).trim()
|
|
14
|
+
} catch { throw new Error('trusted commit is unavailable') }
|
|
15
|
+
if (resolved !== commit) throw new Error('trusted commit did not resolve exactly')
|
|
16
|
+
let bytes
|
|
17
|
+
try { bytes = execFileSync('git', ['--no-replace-objects', '-C', root, 'show', `${resolved}:${RUN_LOG_SOURCE}`], { env: gitEnv, stdio: ['ignore', 'pipe', 'ignore'] }) }
|
|
18
|
+
catch { throw new Error('trusted CLI source is unavailable at the pinned commit') }
|
|
19
|
+
return { commit: resolved, bytes, sha256: createHash('sha256').update(bytes).digest('hex') }
|
|
20
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Score already-validated defect evidence without reading files or observing time.
|
|
2
|
+
import { validateDefectEvaluation, validateDefectManifest } from './defect-policy.mjs'
|
|
3
|
+
|
|
4
|
+
const requireEvaluations = value => {
|
|
5
|
+
if (!Array.isArray(value)) throw new Error('evaluations must be an array')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function scoreEvaluation(manifest, registry, evaluations, evaluation, index) {
|
|
9
|
+
const previousRunIds = evaluations.slice(0, index).map(item => item?.run?.runId)
|
|
10
|
+
const checked = validateDefectEvaluation(manifest, evaluation, evaluation?.findingsSha256, previousRunIds)
|
|
11
|
+
if (!checked.valid) return { available: false, reason: checked.reason, caseId: checked.caseId, index }
|
|
12
|
+
const { runId, caseId, testCase, decisions } = checked
|
|
13
|
+
const confirmed = decisions.filter(item => item.verdict === 'confirmed').map(item => item.defectId)
|
|
14
|
+
const unique = confirmed.filter((id, itemIndex, all) => all.indexOf(id) === itemIndex)
|
|
15
|
+
const known = unique.filter(id => registry.defectIds.includes(id))
|
|
16
|
+
const unknown = unique.filter(id => !registry.defectIds.includes(id))
|
|
17
|
+
const unexpected = unique.filter(id => !testCase.expectedDefects.includes(id))
|
|
18
|
+
const unresolved = decisions.filter(item => item.verdict === 'unresolved').length
|
|
19
|
+
const needsAdjudication = unexpected.length > 0
|
|
20
|
+
return { available: unresolved === 0 && !needsAdjudication,
|
|
21
|
+
reason: unresolved ? 'unresolved adjudication' : needsAdjudication ? 'confirmed defect outside case contract needs corpus adjudication' : null,
|
|
22
|
+
caseId, runId, expected: testCase.expectedDefects, knownConfirmed: known, unknownConfirmed: unknown,
|
|
23
|
+
unexpectedConfirmed: unexpected, confirmedClaims: confirmed.length,
|
|
24
|
+
falseAlarms: decisions.filter(item => item.verdict === 'false-alarm').length,
|
|
25
|
+
unresolved, judged: unresolved === 0, clean: testCase.expectedDefects.length === 0, needsAdjudication }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function summarize(manifest, rows) {
|
|
29
|
+
const ready = rows.filter(row => row.available)
|
|
30
|
+
const judged = rows.filter(row => row.judged)
|
|
31
|
+
const coverageComplete = manifest.cases.every(testCase => rows.filter(row => row.available && row.caseId === testCase.id).length === testCase.expectedRuns)
|
|
32
|
+
&& rows.every(row => row.available)
|
|
33
|
+
const expected = ready.reduce((count, row) => count + row.expected.length, 0)
|
|
34
|
+
const detected = ready.reduce((count, row) => count + row.knownConfirmed.filter(id => row.expected.includes(id)).length, 0)
|
|
35
|
+
const confirmedClaims = judged.reduce((count, row) => count + row.confirmedClaims, 0)
|
|
36
|
+
const uniqueConfirmed = judged.reduce((count, row) => count + row.knownConfirmed.length + row.unknownConfirmed.length, 0)
|
|
37
|
+
const falseAlarms = judged.reduce((count, row) => count + row.falseAlarms, 0)
|
|
38
|
+
const cleanRows = ready.filter(row => row.clean)
|
|
39
|
+
return { available: coverageComplete, coverageComplete, recall: coverageComplete && expected ? detected / expected : null,
|
|
40
|
+
precision: confirmedClaims + falseAlarms ? confirmedClaims / (confirmedClaims + falseAlarms) : null,
|
|
41
|
+
falseAlarms, falseAlarmsPerReview: judged.length ? falseAlarms / judged.length : null,
|
|
42
|
+
cleanAlarmRate: cleanRows.length ? cleanRows.filter(row => row.falseAlarms > 0).length / cleanRows.length : null,
|
|
43
|
+
unresolved: rows.reduce((count, row) => count + (row.unresolved || 0), 0), expectedDefects: expected,
|
|
44
|
+
confirmedExpected: judged.reduce((count, row) => count + row.knownConfirmed.filter(id => row.expected.includes(id)).length, 0),
|
|
45
|
+
confirmedUnexpected: rows.reduce((count, row) => count + (row.unexpectedConfirmed || []).length, 0),
|
|
46
|
+
confirmedUnknown: rows.reduce((count, row) => count + (row.unknownConfirmed || []).length, 0),
|
|
47
|
+
confirmedClaims, uniqueConfirmedDefects: uniqueConfirmed, scoredRuns: ready.length,
|
|
48
|
+
distinctCases: rows.filter((row, index) => row.caseId && rows.findIndex(prior => prior.caseId === row.caseId) === index).length,
|
|
49
|
+
needsAdjudication: rows.some(row => row.needsAdjudication), rows }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function scoreDefectCorpus(manifest, evaluations) {
|
|
53
|
+
const registry = validateDefectManifest(manifest)
|
|
54
|
+
requireEvaluations(evaluations)
|
|
55
|
+
return summarize(manifest, evaluations.map((item, index) => scoreEvaluation(manifest, registry, evaluations, item, index)))
|
|
56
|
+
}
|
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
// verdict-affecting finding (critical or important) is a false positive.
|
|
22
22
|
|
|
23
23
|
import { readFileSync } from 'node:fs';
|
|
24
|
+
import { createHash } from 'node:crypto';
|
|
24
25
|
import { join } from 'node:path';
|
|
25
26
|
import { fileURLToPath } from 'node:url';
|
|
27
|
+
import { scoreDefectCorpus } from './defect-scoring.mjs';
|
|
26
28
|
|
|
27
29
|
export const LINE_WINDOW = 10;
|
|
28
30
|
const BLOCKING = new Set(['critical', 'important']);
|
|
@@ -174,6 +176,34 @@ export function score(manifest, results) {
|
|
|
174
176
|
|
|
175
177
|
function main(argv) {
|
|
176
178
|
const flag = (n) => { const i = argv.indexOf('--' + n); return i === -1 ? null : argv[i + 1]; };
|
|
179
|
+
if (argv.includes('--defects')) {
|
|
180
|
+
const manifestPath = flag('manifest'), resultsPath = flag('results'), adjudicationPath = flag('adjudication');
|
|
181
|
+
if (!manifestPath || !resultsPath || !adjudicationPath || [manifestPath, resultsPath, adjudicationPath].some(value => value.startsWith('--'))) {
|
|
182
|
+
console.error('usage: eval-runner.mjs --defects --manifest <manifest.json> --results <defect-runs.json> --adjudication <adjudication.json> [--json]');
|
|
183
|
+
process.exitCode = 2; return;
|
|
184
|
+
}
|
|
185
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
186
|
+
const results = JSON.parse(readFileSync(resultsPath, 'utf8'));
|
|
187
|
+
const adjudication = JSON.parse(readFileSync(adjudicationPath, 'utf8'));
|
|
188
|
+
const evaluations = Array.isArray(results.runs) ? results.runs.map(run => {
|
|
189
|
+
const matches = Array.isArray(adjudication.evaluations)
|
|
190
|
+
? adjudication.evaluations.filter(item => item?.runId === run?.runId) : [];
|
|
191
|
+
const bytes = typeof run?.findingsBytes === 'string' ? Buffer.from(run.findingsBytes, 'utf8') : Buffer.alloc(0);
|
|
192
|
+
let findings = null;
|
|
193
|
+
try { findings = JSON.parse(bytes.toString('utf8')); } catch { /* scorer marks malformed evidence unavailable */ }
|
|
194
|
+
return { run: { ...run, findings }, adjudication: matches.length === 1 ? matches[0] : null,
|
|
195
|
+
findingsSha256: createHash('sha256').update(bytes).digest('hex') };
|
|
196
|
+
}) : [];
|
|
197
|
+
const out = scoreDefectCorpus(manifest, evaluations);
|
|
198
|
+
if (argv.includes('--json')) console.log(JSON.stringify(out));
|
|
199
|
+
else {
|
|
200
|
+
const pct = value => value === null ? 'n/a' : `${Math.round(value * 100)}%`;
|
|
201
|
+
console.log(`defect evaluation ${out.available ? 'complete' : 'unavailable'}: recall ${pct(out.recall)}, precision ${pct(out.precision)}, false alarms ${out.falseAlarms}, unresolved ${out.unresolved}, distinct cases ${out.distinctCases}`);
|
|
202
|
+
}
|
|
203
|
+
if (!out.coverageComplete || !out.available) process.exitCode = 1;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
console.error('legacy heuristic mode: location-only scoring; use --defects for adjudicated scoring');
|
|
177
207
|
const results = flag('results');
|
|
178
208
|
const archiveIndex = argv.indexOf('--archive');
|
|
179
209
|
const archive = archiveIndex === -1 ? null : argv[archiveIndex + 1];
|
|
@@ -7,6 +7,19 @@ const instances = /^(?!\/)(?!.*\\)(?![A-Za-z]:)(?!(?:.*\/)?\.\.(?:\/|:)).+:[1-9]
|
|
|
7
7
|
const ruleException = /^(PROJECT:[a-z0-9]+(-[a-z0-9]+)*|weakens-project-rule)$/
|
|
8
8
|
const dimensions = ['deps', 'triage-quality', 'triage-logic', 'quality', 'implementation', 'simplification', 'conventions', 'test-quality', 'project-rules']
|
|
9
9
|
|
|
10
|
+
/** Canonicalize location objects without altering or replacing the raw document. */
|
|
11
|
+
export function normalizeNativeResult(dimension, document) {
|
|
12
|
+
const location = value => record(value) && Object.keys(value).length === 2
|
|
13
|
+
&& typeof value.file === 'string' && !/[\x00-\x1f\x7f:]/.test(value.file)
|
|
14
|
+
&& Number.isSafeInteger(value.line) && value.line > 0
|
|
15
|
+
&& instances.test(`${value.file}:${value.line}`) ? `${value.file}:${value.line}` : value
|
|
16
|
+
const normalized = record(document) && Array.isArray(document.findings)
|
|
17
|
+
? { ...document, findings: Array.from(document.findings, finding => record(finding) && Array.isArray(finding.otherInstances)
|
|
18
|
+
? { ...finding, otherInstances: Array.from(finding.otherInstances, location) } : finding) } : document
|
|
19
|
+
const validation = validateNativeResult(dimension, normalized)
|
|
20
|
+
return { ...validation, document: validation.available ? normalized : null }
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
function validBoundary(value) {
|
|
11
24
|
return record(value) && text(value.entryPoint) && text(value.consumer)
|
|
12
25
|
&& optionalStrings(value, ['decisionPoint', 'realizationPoint', 'stateOwner', 'evidenceClass'])
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { openSync, readSync, closeSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { normalizeNativeResult } from './native-results.mjs'
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const [dimension, input, output, ...extra] = process.argv.slice(2)
|
|
8
|
+
if (!dimension || !input || extra.length) throw new Error('invalid arguments')
|
|
9
|
+
const limit = 8 * 1024 * 1024, buffer = Buffer.alloc(limit + 1)
|
|
10
|
+
const fd = openSync(input, 'r')
|
|
11
|
+
let length = 0
|
|
12
|
+
try {
|
|
13
|
+
while (length < buffer.length) {
|
|
14
|
+
const count = readSync(fd, buffer, length, buffer.length - length, null)
|
|
15
|
+
if (!count) break
|
|
16
|
+
length += count
|
|
17
|
+
}
|
|
18
|
+
} finally { closeSync(fd) }
|
|
19
|
+
if (length > limit) {
|
|
20
|
+
console.log(JSON.stringify({ available: false, dimension, reason: 'raw reviewer result exceeds 8 MiB', document: null }))
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
23
|
+
const raw = buffer.subarray(0, length)
|
|
24
|
+
const result = normalizeNativeResult(dimension, JSON.parse(raw.toString('utf8')))
|
|
25
|
+
if (result.available && output) writeFileSync(output, JSON.stringify(result.document), { flag: 'wx' })
|
|
26
|
+
console.log(JSON.stringify({ ...result, rawSha256: createHash('sha256').update(raw).digest('hex') }))
|
|
27
|
+
if (!result.available) process.exitCode = 1
|
|
28
|
+
} catch {
|
|
29
|
+
console.log(JSON.stringify({ available: false, reason: 'raw reviewer result missing or malformed', document: null }))
|
|
30
|
+
process.exitCode = 1
|
|
31
|
+
}
|