summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/workflows
diff options
context:
space:
mode:
authorMorgan Lunt <morganl@anthropic.com>2026-09-23 19:18:55 -0700
committerMorgan Lunt <morganl@anthropic.com>2026-09-24 17:49:55 -0700
commitcbba09effc7046cf649b78dc4b84e95cf1a64edd (patch)
treeaa1a3f30d7e07320042491e7b1319835da52dfc0 /plugins/code-modernization/workflows
parent5a8191cd213bd4f4b2a0dd237d450aed029d2752 (diff)
code-modernization: harden-scan reports the coverage it lost instead of dropping it
When a verifier agent died, harden-scan dropped its finding: the finding was neither confirmed nor refuted and nothing in the result mentioned it. When a finder agent died, its whole vulnerability class vanished the same way, so a class nobody scanned looked like a class that was clean. Both also flattered the false-positive rate, which was divided by every finding, judged or not (issue #6109). The workflow now pairs each result with its input by position. Finder classes that returned nothing come back as deadFinders, findings no refuter judged come back as unverified with a reason, and both are counted in stats. Neither is in findings, so what counts as confirmed is unchanged, and the false-positive rate is refuted over judged findings. When nothing dies the result is identical to before. modernize-harden now writes a Coverage gaps section under the scorecard in SECURITY_FINDINGS.md that names the classes not scanned and the findings not judged, and offers to re-run just those. The workflow takes them back as optional classes and findings arguments and reports its own gaps the same way. The agent estimate now states the formula from the code (5 finders, one refuter per distinct finding, one second judge per finding still Critical or High) instead of a fixed range.
Diffstat (limited to 'plugins/code-modernization/workflows')
-rw-r--r--plugins/code-modernization/workflows/harden-scan.js91
1 files changed, 81 insertions, 10 deletions
diff --git a/plugins/code-modernization/workflows/harden-scan.js b/plugins/code-modernization/workflows/harden-scan.js
index 99ea4fd9..befaf77a 100644
--- a/plugins/code-modernization/workflows/harden-scan.js
+++ b/plugins/code-modernization/workflows/harden-scan.js
@@ -3,7 +3,7 @@ export const meta = {
description:
'Security scan as class-scoped parallel finders with adversarial per-finding verification — false positives die before SECURITY_FINDINGS.md',
whenToUse:
- 'Invoked by /code-modernization:modernize-harden when the Workflow tool is available. Requires args {system}. Covers the scan + triage input only — remediation patch drafting and the per-hunk review loop stay in the calling session (they write files and handle raw credentials).',
+ 'Invoked by /code-modernization:modernize-harden when the Workflow tool is available. Requires args {system}; optional {classes, findings} re-run only the coverage gaps an earlier run returned (deadFinders, unverified). Covers the scan + triage input only — remediation patch drafting and the per-hunk review loop stay in the calling session (they write files and handle raw credentials).',
phases: [
{ title: 'Find', detail: 'one finder per vulnerability class' },
{ title: 'Verify', detail: 'one refuter per finding; second judge for Critical/High' },
@@ -103,8 +103,46 @@ const CLASSES = [
{ key: 'input', brief: 'missing input validation, path traversal, insecure deserialization, and unsafe file handling.' },
]
-const found = await parallel(
- CLASSES.map(c => () =>
+// ---- Re-run of an earlier run's coverage gaps ---------------------------------
+// A run reports what it could not cover: `deadFinders` (classes nobody scanned)
+// and `unverified` (findings no refuter judged). Passing them back as
+// args.classes and args.findings runs ONLY those — the named finder classes,
+// and a verdict pass over the named findings. Give neither for the full scan.
+const isRerun = ARGS.classes != null || ARGS.findings != null
+for (const k of ['classes', 'findings']) {
+ if (ARGS[k] != null && !Array.isArray(ARGS[k])) {
+ throw new Error(`modernize-harden-scan: args.${k} must be a list (got ${typeof ARGS[k]})`)
+ }
+}
+const rerunClasses = ARGS.classes || []
+const unknownClasses = rerunClasses.filter(k => !CLASSES.some(c => c.key === k))
+if (unknownClasses.length) {
+ throw new Error(
+ `modernize-harden-scan: unknown finder class ${JSON.stringify(unknownClasses)} — valid classes: ${CLASSES.map(c => c.key).join(', ')}`,
+ )
+}
+const FINDING_FIELDS = ['cwe', 'source', 'title', 'exploitScenario', 'recommendedFix']
+const carried = (ARGS.findings || []).map((f, i) => {
+ if (
+ !f ||
+ typeof f !== 'object' ||
+ FINDING_FIELDS.some(k => typeof f[k] !== 'string' || !f[k]) ||
+ !['Critical', 'High', 'Medium', 'Low'].includes(f.severity)
+ ) {
+ throw new Error(
+ `modernize-harden-scan: args.findings[${i}] is not a finding (needs string ${FINDING_FIELDS.join(', ')} and a severity of Critical, High, Medium or Low)`,
+ )
+ }
+ const { unverifiedReason, ...finding } = f
+ return finding
+})
+if (isRerun && !rerunClasses.length && !carried.length) {
+ throw new Error('modernize-harden-scan: args.classes and args.findings are both empty — nothing to re-run (omit both for the full scan)')
+}
+const activeClasses = isRerun ? CLASSES.filter(c => rerunClasses.includes(c.key)) : CLASSES
+
+const found = activeClasses.length === 0 ? [] : await parallel(
+ activeClasses.map(c => () =>
agent(
`Adversarially audit ${legacyDir} for ONE class of security vulnerability: ${c.brief}
Cover only what applies to the detected stack (web items don't apply to a batch system). Every finding needs a precise repo-relative file:line citation you actually read, a CWE ID, and a one-sentence exploit scenario.
@@ -119,11 +157,21 @@ ${UNTRUSTED}`,
),
)
+// parallel() keeps positions: found[i] belongs to activeClasses[i] and is null
+// when that finder was skipped, died on a terminal error, or threw (for
+// example once the token budget is spent). A class nobody scanned must never
+// read as a class that is clean, so name it.
+const deadFinders = activeClasses.filter((c, i) => !found[i]).map(c => c.key)
+if (deadFinders.length) {
+ log(`${deadFinders.length} of ${activeClasses.length} finder(s) returned nothing — NOT scanned: ${deadFinders.join(', ')} (returned in deadFinders; re-run just these with args.classes)`)
+}
+
const injectionFlags = []
const all = found.filter(Boolean).flatMap(r => {
for (const s of r.injectionSuspects || []) injectionFlags.push(s)
return r.findings || []
})
+all.unshift(...carried) // re-run: findings an earlier run left unjudged
const toolOutputs = found.filter(Boolean).map(r => r.toolOutput).filter(Boolean)
// Dedup across classes (the same hardcoded credential surfaces under auth AND secrets)
@@ -170,16 +218,26 @@ const verified = await parallel(
const survivors = []
const refuted = []
-for (const item of verified.filter(Boolean)) {
- const { f, v } = item
- if (!v) continue
- if (v.real) {
+const unverified = [] // findings no refuter judged — returned, never counted as confirmed or as refuted
+// parallel() keeps positions: verified[i] is the verdict for deduped[i]. It is
+// null when the thunk threw (agent error, token budget spent) and {v: null}
+// when the agent returned nothing. Walk by index so a finding that got no
+// verdict is recorded instead of disappearing from the run.
+deduped.forEach((f, i) => {
+ const v = verified[i] && verified[i].v
+ if (!v) {
+ unverified.push({ ...f, unverifiedReason: 'no refuter verdict (agent skipped, errored, or the token budget ran out)' })
+ } else if (v.real) {
survivors.push(v.adjustedSeverity ? { ...f, severity: v.adjustedSeverity, severityNote: v.reason } : f)
} else {
refuted.push({ ...f, refutationReason: v.reason })
}
-}
-log(`${survivors.length} findings survived refutation; ${refuted.length} killed as false positives`)
+})
+unverified.sort((a, b) => SEV_RANK[a.severity] - SEV_RANK[b.severity])
+log(
+ `${survivors.length} findings survived refutation; ${refuted.length} killed as false positives` +
+ (unverified.length ? `; ${unverified.length} NOT judged (returned in unverified, not counted as confirmed or refuted)` : ''),
+)
// Second, independent confirmation for what remains Critical/High — these drive the patch.
const critHigh = survivors.filter(f => SEV_RANK[f.severity] <= 1)
@@ -210,15 +268,28 @@ survivors.sort((a, b) => SEV_RANK[a.severity] - SEV_RANK[b.severity])
// ---- Return -------------------------------------------------------------------
// The calling session writes SECURITY_FINDINGS.md, the SECRETS.local.md
// quarantine, and drafts/reviews the remediation patches — never the agents.
+const judged = survivors.length + refuted.length
return {
system,
findings: survivors,
refuted,
+ // Coverage gaps — NOT part of `findings`. unverified: findings no refuter
+ // judged (pass back as args.findings). deadFinders: classes whose finder
+ // returned nothing, so nobody scanned them (pass back as args.classes).
+ unverified,
+ deadFinders,
credentialFindings: survivors.filter(f => f.isCredential),
toolOutputs,
injectionFlags: [...new Set(injectionFlags)],
stats: {
bySeverity: survivors.reduce((acc, f) => ({ ...acc, [f.severity]: (acc[f.severity] || 0) + 1 }), {}),
- falsePositiveRate: deduped.length ? Math.round((refuted.length / deduped.length) * 100) + '%' : 'n/a',
+ // refuted / judged: a finding no refuter judged is neither refuted nor kept,
+ // so it stays out of the denominator instead of flattering the rate.
+ falsePositiveRate: judged ? Math.round((refuted.length / judged) * 100) + '%' : 'n/a',
+ finders: activeClasses.length,
+ deadFinders,
+ distinctFindings: deduped.length,
+ judged,
+ unverified: unverified.length,
},
}