bugxhunter 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -424,9 +424,22 @@ round after round:
424
424
  4. **Stop.** The run ends when the executor reports the surface exhausted, a round finds nothing
425
425
  new, the round or token cap is reached, it stays stuck after escalating, every model is
426
426
  rate-limited, a round fails, or you press stop.
427
-
428
- A strip above the composer shows the round, tokens, model and how many approvals the gate
429
- answered; the findings appear in the transcript. Gate decisions and the run's start and end go to
427
+ 5. **Chain.** When the loop ends with two or more findings, a chain pass tries to combine them
428
+ into attack paths. One turn on the escalation model proposes up to three paths, each naming the
429
+ findings it builds on (`F1`, `F2`, …). The executor then has up to three rounds per path to
430
+ show it end to end, under the same gate and scope, and hands it to `recon-verify`, which
431
+ rejects a path unless every step has its evidence and each step used what the one before
432
+ returned. A path that holds is recorded as *demonstrated*, rated on what the attacker ends up
433
+ with and never below the worst finding it uses; it is config-dependent if any of those is. A
434
+ path that stops (a write you declined, a step that did not work, the rounds running out) is
435
+ recorded as *partial*, with the step and the reason: a lead, not a finding. The pass does not
436
+ run after an error, rate limits or a stop. It spends what is left of the token budget and no
437
+ more: once a run has two findings, the main loop leaves 15% of the budget for it.
438
+
439
+ A strip above the composer shows the round (or the chain pass's turn), tokens, model and how many
440
+ approvals the gate answered. The results appear in the transcript: attack paths first, then the
441
+ findings, each numbered and marked with the paths it is part of, then the unproven paths with the
442
+ step each stopped at. The start dialog has a checkbox to leave the chain pass out of a run. Gate decisions and the run's start and end go to
430
443
  the audit log (`recon.gate`, `recon.started`, `recon.finished`). A run lives in the runner's
431
444
  memory: restarting the runner ends it (the session and its transcript stay).
432
445
 
@@ -508,6 +521,7 @@ GHCR images by digest) and the signed `checksums.txt` that covers them all.
508
521
  <!-- releases:start -->
509
522
  | Release | Published | Checksums | Signature | Signature check | Build |
510
523
  | --- | --- | --- | --- | --- | --- |
524
+ | [v0.12.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.12.0) | 2026-11-27 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.12.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.12.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/45961143760) |
511
525
  | [v0.11.1](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.11.1) | 2026-11-27 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.11.1/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.11.1/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/45953964866) |
512
526
  | [v0.11.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.11.0) | 2026-11-26 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.11.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.11.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/45788161293) |
513
527
  | [v0.10.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.10.0) | 2026-11-21 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.10.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.10.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/44896163152) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugxhunter",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "BugXHunter: an AI security-testing agent with a sandboxed runner, a passkey-sealed key vault and read-only GitHub access. `npx bugxhunter` runs it on your machine.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://bugxhunter.com",
@@ -876,7 +876,7 @@ app.post("/api/agent/recon", async (req, res) => {
876
876
  scope: String(b.scope ?? ""),
877
877
  objective: String(b.objective ?? ""),
878
878
  env: parseEnvFidelity(b.env),
879
- harness: parseReconHarness({ maxRounds: b.maxRounds, budgetTokens: b.budgetTokens }),
879
+ harness: parseReconHarness({ maxRounds: b.maxRounds, budgetTokens: b.budgetTokens, chainPass: b.chainPass }),
880
880
  backend: await reconBackend(directory),
881
881
  log: (event, data) => audit(event, { directory, ...data }),
882
882
  });
@@ -17,7 +17,7 @@
17
17
  * decision has to ride the event stream. The runner is handed `gate` and calls
18
18
  * it on each permission as it arrives.
19
19
  */
20
- import { routeModel, harnessFor, classifyCommand, commandHazard, allCapped, originOf, escalateAfter, STATUS_LINE, } from "./recon.js";
20
+ import { routeModel, harnessFor, classifyCommand, commandHazard, allCapped, originOf, escalateAfter, resolveChainPass, STATUS_LINE, } from "./recon.js";
21
21
  const SEVERITY_RANK = { low: 0, medium: 1, high: 2, critical: 3 };
22
22
  const worstSeverity = (fs) => {
23
23
  let best;
@@ -85,9 +85,13 @@ export class ReconRun {
85
85
  harness;
86
86
  spentTokens = 0;
87
87
  rounds = 0;
88
+ /** Turns the chain pass took (not counted in `rounds`, which caps the main loop). */
89
+ chainRounds = 0;
88
90
  /** Consecutive turns the executor reported stuck — the escalation signal. */
89
91
  attempts = 0;
90
92
  findings = [];
93
+ /** Attack paths from the chain pass: demonstrated ones and partial leads. */
94
+ chains = [];
91
95
  constructor(harness = {}) {
92
96
  this.harness = harness;
93
97
  }
@@ -96,17 +100,43 @@ export class ReconRun {
96
100
  recordRound() { this.rounds += 1; }
97
101
  recordStuck() { this.attempts += 1; }
98
102
  resetAttempts() { this.attempts = 0; }
99
- /** Keep every finding the verifier didn't reject. */
103
+ /**
104
+ * Keep every finding the verifier didn't reject, and number it (F1, F2, …) so an attack
105
+ * path can name it. The id is set on the finding itself: the run's live view holds the
106
+ * same object.
107
+ */
100
108
  addFindings(fs) {
101
- for (const f of fs)
102
- if (f.verdict !== "rejected")
103
- this.findings.push(f);
109
+ for (const f of fs) {
110
+ if (f.verdict === "rejected")
111
+ continue;
112
+ f.id = `F${this.findings.length + 1}`;
113
+ this.findings.push(f);
114
+ }
115
+ }
116
+ /** Keep the attack paths the verifier looked at, numbered P1, P2, …. */
117
+ addChains(cs) {
118
+ for (const c of cs) {
119
+ c.id = `P${this.chains.length + 1}`;
120
+ this.chains.push(c);
121
+ }
104
122
  }
105
123
  /** Uncached input tokens left, or undefined when the harness sets no budget. */
106
124
  budgetRemaining() {
107
125
  return this.harness.budgetTokens === undefined ? undefined : Math.max(0, this.harness.budgetTokens - this.spentTokens);
108
126
  }
109
- outOfBudget() { const r = this.budgetRemaining(); return r !== undefined && r <= 0; }
127
+ /** Is the budget spent, counting `reserve` tokens as already gone (the main loop leaves them for the chain pass)? */
128
+ outOfBudget(reserve = 0) { const r = this.budgetRemaining(); return r !== undefined && r - reserve <= 0; }
129
+ /**
130
+ * Tokens the main loop leaves for the chain pass: a share of the budget, held back only
131
+ * once the run has the two findings the pass needs. Without them there will be no pass,
132
+ * and the main loop may spend the whole budget as before.
133
+ */
134
+ chainReserve() {
135
+ const c = resolveChainPass(this.harness.chainPass);
136
+ if (!c.enabled || this.findings.length < 2 || this.harness.budgetTokens === undefined)
137
+ return 0;
138
+ return Math.floor(this.harness.budgetTokens * c.reservePercent / 100);
139
+ }
110
140
  outOfRounds() { return this.harness.maxRounds !== undefined && this.rounds >= this.harness.maxRounds; }
111
141
  /** The worst severity seen so far, for the escalation signal. */
112
142
  highestSeverity() {
@@ -206,6 +236,8 @@ export function parseVerifierFindings(text, env) {
206
236
  catch {
207
237
  continue;
208
238
  }
239
+ if (isChainVerdict(o))
240
+ continue; // an attack path is not a finding: parseVerifierChains reads it
209
241
  const verdict = VERDICTS.find((v) => v === String(get(o, "verdict")).toLowerCase());
210
242
  const severity = SEVERITIES.find((s) => s === String(get(o, "severity")).toLowerCase());
211
243
  const repro = clipText(get(o, "repro"), 4000);
@@ -220,16 +252,280 @@ export function parseVerifierFindings(text, env) {
220
252
  }
221
253
  return out;
222
254
  }
255
+ /* ─────────────── attack paths (the chain pass reads these; pure) ─────────────── */
256
+ const MAX_CHAIN_STEPS = 8;
257
+ /** The verifier marks a path's verdict `"kind": "chain"`; one that lists the findings it links counts too. */
258
+ function isChainVerdict(o) {
259
+ return String(get(o, "kind")).toLowerCase() === "chain" || Array.isArray(get(o, "links"));
260
+ }
261
+ /** "F2" from "F2", "f2", " 2 " or 2; undefined for anything else. */
262
+ function findingId(v) {
263
+ const m = /^\s*f?\s*(\d{1,4})\s*$/i.exec(typeof v === "number" ? String(v) : typeof v === "string" ? v : "");
264
+ return m ? `F${Number(m[1])}` : undefined;
265
+ }
266
+ /** The ids in `raw` that name a finding of this run, each once, in the order given. Unknown ones are dropped. */
267
+ function knownLinks(raw, findings) {
268
+ const known = new Set(findings.map((f) => f.id).filter((id) => Boolean(id)));
269
+ const out = [];
270
+ for (const v of Array.isArray(raw) ? raw : []) {
271
+ const id = findingId(v);
272
+ if (id && known.has(id) && !out.includes(id))
273
+ out.push(id);
274
+ }
275
+ return out;
276
+ }
277
+ /** A step given as text, or as an object with its action and evidence. */
278
+ function chainStep(v) {
279
+ const action = clipText(typeof v === "string" ? v : get(v, "action") ?? get(v, "step") ?? get(v, "what"), 600);
280
+ if (!action)
281
+ return undefined;
282
+ const evidence = typeof v === "string" ? undefined : clipText(get(v, "evidence") ?? get(v, "repro"), 2000);
283
+ return evidence ? { action, evidence } : { action };
284
+ }
223
285
  /**
224
- * Drive one supervised recon run to completion. Pure control flow over the
225
- * injected runner: route (and escalate) the executor model each round, run a
226
- * turn under the gate, fold in usage and findings, and stop on done / idle /
227
- * budget / rounds. The harness for the executor role supplies the caps.
286
+ * The paths the proposer suggested, from its reply: `{"paths": [...]}` or the path objects
287
+ * on their own. A path is kept only if it has two or more steps and builds on at least one
288
+ * finding of this run; ids that name no finding are dropped. At most `max` are returned, in
289
+ * the order given (the proposer ranks them). Like every model reply here, the text stays
290
+ * data: it is clipped, and nothing in it is acted on except through the gate.
228
291
  */
229
- export async function driveRecon(opts) {
230
- const run = new ReconRun(resolveHarness(opts.harness));
231
- const { host: scopeHost, port: scopePort } = originOf(opts.scope);
232
- const gate = (p) => reconGateDecision(p, { scopeHost, scopePort });
292
+ export function parseChainProposal(text, findings, max) {
293
+ const out = [];
294
+ const take = (o) => {
295
+ if (out.length >= max)
296
+ return;
297
+ const steps = (Array.isArray(get(o, "steps")) ? get(o, "steps") : [])
298
+ .map((s) => chainStep(s)?.action).filter((s) => Boolean(s)).slice(0, MAX_CHAIN_STEPS);
299
+ const links = knownLinks(get(o, "links") ?? get(o, "findings"), findings);
300
+ const goal = clipText(get(o, "goal") ?? get(o, "impact"), 400);
301
+ if (steps.length < 2 || !links.length || !goal)
302
+ return;
303
+ const unproven = Number(get(o, "unproven") ?? get(o, "unproven_step"));
304
+ out.push({
305
+ title: clipText(get(o, "title"), 200) ?? goal.slice(0, 80),
306
+ goal, links, steps,
307
+ ...(Number.isInteger(unproven) && unproven >= 1 && unproven <= steps.length ? { unproven } : {}),
308
+ });
309
+ };
310
+ for (const raw of jsonObjects(text ?? "")) {
311
+ let o;
312
+ try {
313
+ o = JSON.parse(raw);
314
+ }
315
+ catch {
316
+ continue;
317
+ }
318
+ const paths = get(o, "paths") ?? get(o, "chains");
319
+ if (Array.isArray(paths))
320
+ paths.forEach(take);
321
+ else
322
+ take(o);
323
+ }
324
+ return out;
325
+ }
326
+ /**
327
+ * The rules an attack path must meet whatever the verifier wrote:
328
+ * - a path with a step that has no evidence is partial, stopped at that step;
329
+ * - it is config-dependent if any finding it uses is;
330
+ * - a demonstrated path is never rated below the worst finding it uses (that finding
331
+ * stands on its own, so the path that contains it cannot be less serious).
332
+ */
333
+ export function applyChainRules(chain, findings) {
334
+ const used = findings.filter((f) => f.id && chain.links.includes(f.id));
335
+ const out = { ...chain };
336
+ const gap = out.steps.findIndex((s) => !s.evidence);
337
+ if (out.status === "demonstrated" && gap >= 0) {
338
+ out.status = "partial";
339
+ out.blockedAt = gap + 1;
340
+ out.blockedWhy = "no evidence for this step";
341
+ }
342
+ if (out.status === "demonstrated") {
343
+ delete out.blockedAt;
344
+ delete out.blockedWhy;
345
+ }
346
+ if (used.some((f) => f.verdict === "config-dependent")) {
347
+ out.verdict = "config-dependent";
348
+ out.prodCaveat ??= used.map((f) => f.prodCaveat).filter(Boolean).join(" ") || "Depends on a finding that depends on a non-production setting.";
349
+ }
350
+ if (out.status === "demonstrated") {
351
+ const floor = worstSeverity(used);
352
+ if (floor && SEVERITY_RANK[floor] > SEVERITY_RANK[out.severity])
353
+ out.severity = floor;
354
+ }
355
+ return out;
356
+ }
357
+ /**
358
+ * The verifier's verdicts on attack paths, from its reply. One is read only if it is valid
359
+ * JSON marked as a path, with a known verdict and severity, two or more steps, the impact,
360
+ * and at least one finding of this run among its links. A rejected path is dropped, and so
361
+ * is anything unparseable: nothing is promoted on a guess. The rules above are then applied.
362
+ */
363
+ export function parseVerifierChains(text, env, findings) {
364
+ const out = [];
365
+ for (const raw of jsonObjects(text ?? "")) {
366
+ let o;
367
+ try {
368
+ o = JSON.parse(raw);
369
+ }
370
+ catch {
371
+ continue;
372
+ }
373
+ if (!isChainVerdict(o))
374
+ continue;
375
+ const verdict = VERDICTS.find((v) => v === String(get(o, "verdict")).toLowerCase());
376
+ const severity = SEVERITIES.find((s) => s === String(get(o, "severity")).toLowerCase());
377
+ const steps = (Array.isArray(get(o, "steps")) ? get(o, "steps") : [])
378
+ .map(chainStep).filter((s) => Boolean(s)).slice(0, MAX_CHAIN_STEPS);
379
+ const links = knownLinks(get(o, "links"), findings);
380
+ const impact = clipText(get(o, "impact") ?? get(o, "goal"), 600);
381
+ if (!verdict || verdict === "rejected" || !severity || steps.length < 2 || !links.length || !impact)
382
+ continue;
383
+ const blockedAt = Number(get(o, "blocked_at") ?? get(o, "blockedAt"));
384
+ const partial = String(get(o, "status")).toLowerCase() === "partial";
385
+ out.push(applyChainRules({
386
+ title: clipText(get(o, "title"), 200) ?? impact.slice(0, 80),
387
+ severity, verdict, impact, links, steps, env,
388
+ status: partial ? "partial" : "demonstrated",
389
+ ...(partial && Number.isInteger(blockedAt) && blockedAt >= 1 && blockedAt <= steps.length ? { blockedAt } : {}),
390
+ ...(partial ? { blockedWhy: clipText(get(o, "blocked_why") ?? get(o, "blockedWhy"), 300) ?? "not demonstrated" } : {}),
391
+ standardId: clipText(get(o, "standard_id") ?? get(o, "standardId"), 60),
392
+ prodCaveat: clipText(get(o, "prod_caveat") ?? get(o, "prodCaveat"), 1000),
393
+ }, findings));
394
+ }
395
+ return out;
396
+ }
397
+ /* ─────────────── the chain pass ─────────────── */
398
+ const clipLine = (t, n) => { const one = t.replace(/\s+/g, " ").trim(); return one.length > n ? one.slice(0, n) + "…" : one; };
399
+ const findingLine = (f) => `${f.id} [${f.severity}${f.verdict === "config-dependent" ? ", config-dependent" : ""}] ${clipLine(f.title, 160)}: ${clipLine(f.repro, 300)}`;
400
+ /** The proposal turn: no tools, just which of the verified findings combine. */
401
+ export function buildChainProposalPrompt(findings, max) {
402
+ return [
403
+ "CHAIN PASS. The assessment loop has ended. Do not run any tool in this turn.",
404
+ `Verified findings of this run:\n${findings.map(findingLine).join("\n")}`,
405
+ `From these, and from anything you observed during this run, propose up to ${max} attack paths: sequences in which what one step returns is what the next step needs, and which reach something worse than any single finding does. Stay inside the declared scope. Every path must build on at least one finding above, named by its id. Put the most valuable path first. If nothing combines, say so and give an empty list.`,
406
+ 'Output one fenced json block and nothing after it: {"paths": [{"title": "short name", "goal": "what the attacker ends up with", "links": ["F1", "F3"], "steps": ["step 1", "step 2"], "unproven": the number of the step you are least sure of, or null}]}.',
407
+ ].join("\n\n");
408
+ }
409
+ /** The first turn on one path: show it end to end, then have the verifier rule on it. */
410
+ export function buildChainDemoPrompt(c, n, of, findings) {
411
+ const used = findings.filter((f) => f.id && c.links.includes(f.id));
412
+ return [
413
+ `ATTACK PATH ${n} of ${of}: ${c.title}`,
414
+ `Goal: ${c.goal}`,
415
+ `Builds on:\n${used.map(findingLine).join("\n")}`,
416
+ `Steps as proposed:\n${c.steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}${c.unproven ? `\nStep ${c.unproven} is the one that has not been shown.` : ""}`,
417
+ "Show this path end to end against the target, inside the same scope. Run each step with the smallest probe that settles it, using what the step before returned. Test nothing that is not on this path. Read-only probes run freely; a step that changes state pauses for human approval, and if it is declined the path stops there.",
418
+ "Then hand the whole path to recon-verify as an ATTACK PATH: for each step the request or command and the response, the finding ids it builds on, and what the attacker ends up with. If a step could not be shown, hand it over all the same and say which step and why: it is recorded as partial. Do not promote the path yourself.",
419
+ `End your turn with one final line: "${STATUS_LINE}: done" once the verifier has ruled on this path, "${STATUS_LINE}: continue" if it needs more probes, "${STATUS_LINE}: stuck" if it cannot be shown.`,
420
+ ].join("\n\n");
421
+ }
422
+ export const CHAIN_CONTINUE = `Continue with this attack path only: run the next step, then hand the whole path to recon-verify as an ATTACK PATH. End with "${STATUS_LINE}: done" once the verifier has ruled, "${STATUS_LINE}: continue" or "${STATUS_LINE}: stuck".`;
423
+ /** A proposed path nothing ruled on, kept as a lead: partial, rated as the worst finding it builds on. */
424
+ function leadFrom(c, findings, env, why) {
425
+ const used = findings.filter((f) => f.id && c.links.includes(f.id));
426
+ return applyChainRules({
427
+ title: c.title, impact: c.goal, links: c.links, env,
428
+ severity: worstSeverity(used) ?? "low", verdict: "real",
429
+ steps: c.steps.map((action) => ({ action })),
430
+ status: "partial", blockedWhy: why,
431
+ ...(c.unproven ? { blockedAt: c.unproven } : {}),
432
+ }, findings);
433
+ }
434
+ /**
435
+ * The chain pass: one turn to propose attack paths from the verified findings, then a few
436
+ * turns on each to show it and have the verifier rule. Same runner, same gate and same
437
+ * scope as the main loop; the pass can spend what is left of the token budget and no more.
438
+ * A path the verifier did not rule on is kept as a partial lead that says why.
439
+ */
440
+ async function driveChainPass(run, opts, gate, harness) {
441
+ const cfg = resolveChainPass(harness.chainPass);
442
+ if (!cfg.enabled)
443
+ return "off";
444
+ if (run.findings.length < 2)
445
+ return "few-findings";
446
+ if (run.outOfBudget())
447
+ return "budget";
448
+ const env = opts.env.kind;
449
+ const signals = (severityHint) => run.signals({ rateLimited: opts.rateLimited?.(), severityHint });
450
+ const record = (chains) => { run.addChains(chains); opts.onChainPass?.(run.chains); };
451
+ const turn = async (prompt, model) => {
452
+ const res = await opts.runner.runTurn({ prompt, model, gate });
453
+ run.chainRounds += 1;
454
+ run.recordUsage(res.tokensUsed);
455
+ run.addFindings(res.findings); // a new finding met on the way is kept like any other
456
+ return res;
457
+ };
458
+ if (allCapped(signals()))
459
+ return "rate-limited";
460
+ opts.onChainPass?.(run.chains);
461
+ let candidates;
462
+ try {
463
+ const res = await turn(buildChainProposalPrompt(run.findings, cfg.maxCandidates), routeModel("escalate", signals()));
464
+ candidates = parseChainProposal(res.text ?? "", run.findings, cfg.maxCandidates);
465
+ }
466
+ catch {
467
+ return "error";
468
+ }
469
+ if (!candidates.length)
470
+ return "no-paths";
471
+ for (let i = 0; i < candidates.length; i++) {
472
+ const c = candidates[i];
473
+ const rest = (why) => record(candidates.slice(i).map((x) => leadFrom(x, run.findings, env, why)));
474
+ if (run.outOfBudget()) {
475
+ rest("not tried: the token budget was spent");
476
+ return "ran";
477
+ }
478
+ run.resetAttempts();
479
+ // A path through a High or Critical finding gets the escalation model, as such a finding does in the main loop.
480
+ const grave = worstSeverity(run.findings.filter((f) => f.id && c.links.includes(f.id)));
481
+ let prompt = buildChainDemoPrompt(c, i + 1, candidates.length, run.findings);
482
+ let ruled = false, why = `not shown within ${cfg.maxRoundsPerChain} rounds`;
483
+ for (let round = 0; round < cfg.maxRoundsPerChain; round++) {
484
+ if (run.outOfBudget()) {
485
+ why = "not shown: the token budget was spent";
486
+ break;
487
+ }
488
+ const s = signals(grave);
489
+ if (allCapped(s)) {
490
+ rest("not tried: every model was rate-limited");
491
+ return "rate-limited";
492
+ }
493
+ let res;
494
+ try {
495
+ res = await turn(prompt, routeModel("executor", s));
496
+ }
497
+ catch {
498
+ rest("not tried: the run stopped");
499
+ return "error";
500
+ }
501
+ const chains = (res.verifierOutputs ?? []).flatMap((out) => parseVerifierChains(out, env, run.findings));
502
+ if (chains.length) {
503
+ record(chains);
504
+ ruled = true;
505
+ break;
506
+ }
507
+ if (res.stuck) {
508
+ run.recordStuck();
509
+ why = "the executor could not show it";
510
+ break;
511
+ }
512
+ if (res.done) {
513
+ why = "the verifier did not rule on it";
514
+ break;
515
+ }
516
+ if (!res.madeProgress) {
517
+ why = "the executor made no progress on it";
518
+ break;
519
+ }
520
+ prompt = CHAIN_CONTINUE;
521
+ }
522
+ if (!ruled)
523
+ record([leadFrom(c, run.findings, env, why)]);
524
+ }
525
+ return "ran";
526
+ }
527
+ /** The main loop: route the executor each round, run a turn under the gate, stop on done / idle / a cap. */
528
+ async function driveMainLoop(run, opts, gate) {
233
529
  const maxStuck = escalateAfter() + 2; // give escalation a chance before giving up
234
530
  let prompt = buildReconKickoff(opts);
235
531
  // One-shot: the worst severity found LAST turn informs THIS turn's routing, then clears.
@@ -238,14 +534,14 @@ export async function driveRecon(opts) {
238
534
  const signals = run.signals({ rateLimited: opts.rateLimited?.(), severityHint });
239
535
  // Every model is rate-limited — back off rather than thrash (H4).
240
536
  if (allCapped(signals))
241
- return finish(run, "rate-limited");
537
+ return "rate-limited";
242
538
  const model = routeModel("executor", signals);
243
539
  let res;
244
540
  try {
245
541
  res = await opts.runner.runTurn({ prompt, model, gate });
246
542
  }
247
543
  catch {
248
- return finish(run, "error"); // keep the findings gathered so far (M2)
544
+ return "error"; // keep the findings gathered so far (M2)
249
545
  }
250
546
  run.recordRound();
251
547
  run.recordUsage(res.tokensUsed);
@@ -256,19 +552,33 @@ export async function driveRecon(opts) {
256
552
  else
257
553
  run.resetAttempts();
258
554
  if (res.done)
259
- return finish(run, "done"); // a clean finish wins over the caps
260
- if (run.outOfBudget())
261
- return finish(run, "budget");
555
+ return "done"; // a clean finish wins over the caps
556
+ if (run.outOfBudget(run.chainReserve()))
557
+ return "budget"; // what is held back is for the chain pass
262
558
  if (run.outOfRounds())
263
- return finish(run, "rounds");
559
+ return "rounds";
264
560
  if (run.attempts >= maxStuck)
265
- return finish(run, "stuck"); // persistently stuck, even escalated (H3)
561
+ return "stuck"; // persistently stuck, even escalated (H3)
266
562
  if (!res.madeProgress && !res.stuck)
267
- return finish(run, "idle"); // surface spent
563
+ return "idle"; // surface spent
268
564
  prompt = RECON_CONTINUE;
269
565
  }
270
566
  }
271
- function finish(run, stopped) {
272
- return { findings: run.findings, rounds: run.rounds, tokens: run.spentTokens, stopped };
567
+ /**
568
+ * Drive one supervised recon run to completion. Pure control flow over the
569
+ * injected runner: the main loop (route and escalate the executor model each
570
+ * round, run a turn under the gate, fold in usage and findings, stop on done /
571
+ * idle / budget / rounds), then the chain pass over what it found. The harness
572
+ * for the executor role supplies the caps.
573
+ */
574
+ export async function driveRecon(opts) {
575
+ const harness = resolveHarness(opts.harness);
576
+ const run = new ReconRun(harness);
577
+ const { host: scopeHost, port: scopePort } = originOf(opts.scope);
578
+ const gate = (p) => reconGateDecision(p, { scopeHost, scopePort });
579
+ const stopped = await driveMainLoop(run, opts, gate);
580
+ // An error (which is also how a stop by the person arrives) or rate limits end the run: no pass.
581
+ const chainPass = stopped === "error" || stopped === "rate-limited" ? "skipped" : await driveChainPass(run, opts, gate, harness);
582
+ return { findings: run.findings, chains: run.chains, chainPass, rounds: run.rounds, chainRounds: run.chainRounds, tokens: run.spentTokens, stopped };
273
583
  }
274
584
  //# sourceMappingURL=recon-driver.js.map
@@ -103,7 +103,7 @@ export class OpencodeReconRunner {
103
103
  this.turn = {
104
104
  model: args.model, gate: args.gate, resolve, reject,
105
105
  tokensAtStart: this.tokens, sawAssistant: false,
106
- toolsCompleted: new Set(), texts: new Map(), findings: [],
106
+ toolsCompleted: new Set(), texts: new Map(), findings: [], verifierOutputs: [],
107
107
  };
108
108
  });
109
109
  try {
@@ -134,6 +134,8 @@ export class OpencodeReconRunner {
134
134
  t.resolve({
135
135
  tokensUsed: Math.max(0, this.tokens - t.tokensAtStart),
136
136
  findings: t.findings,
137
+ text,
138
+ verifierOutputs: t.verifierOutputs,
137
139
  ...parseTurnStatus(text, t.toolsCompleted.size),
138
140
  ...extra,
139
141
  });
@@ -222,6 +224,7 @@ export class OpencodeReconRunner {
222
224
  return;
223
225
  this.verified.add(part.callID);
224
226
  this.turn.findings.push(...parseVerifierFindings(st.output, this.env));
227
+ this.turn.verifierOutputs.push(st.output);
225
228
  }
226
229
  onPermission(perm) {
227
230
  if (this.handledPermissions.has(perm.id))
@@ -253,7 +256,11 @@ const runs = new Map();
253
256
  function snapshot(run) {
254
257
  const { state, runner } = run;
255
258
  if (state.status === "running") {
256
- state.rounds = runner.rounds;
259
+ // Once the chain pass has started, `rounds` stays at the main loop's count and its own turns are counted apart.
260
+ if (state.phase === "chains")
261
+ state.chainRounds = Math.max(0, runner.rounds - state.rounds);
262
+ else
263
+ state.rounds = runner.rounds;
257
264
  state.tokens = runner.tokens;
258
265
  state.model = runner.model;
259
266
  state.gate = { ...runner.gateCounts };
@@ -325,20 +332,30 @@ export async function startRecon(o) {
325
332
  }
326
333
  },
327
334
  };
328
- void driveRecon({ objective, scope, env: o.env, runner: seam, harness, rateLimited: () => runner.rateLimited() })
335
+ const onChainPass = (chains) => {
336
+ if (state.phase !== "chains") {
337
+ state.rounds = runner.rounds;
338
+ state.phase = "chains";
339
+ }
340
+ state.chains = [...chains];
341
+ };
342
+ void driveRecon({ objective, scope, env: o.env, runner: seam, harness, rateLimited: () => runner.rateLimited(), onChainPass })
329
343
  .then((result) => {
330
344
  snapshot(run); // last live numbers before the status flips
331
345
  state.status = "finished";
332
346
  state.stopped = runner.wasAborted ? "aborted" : result.stopped;
333
347
  state.findings = result.findings;
348
+ state.chains = result.chains;
349
+ state.chainPass = result.chainPass;
334
350
  state.rounds = result.rounds;
351
+ state.chainRounds = result.chainRounds;
335
352
  if (state.stopped === "error")
336
353
  state.error = lastError;
337
354
  state.finishedAt = Date.now();
338
355
  runner.close();
339
356
  o.log?.("recon.finished", {
340
357
  session: o.sessionID, stopped: state.stopped, rounds: state.rounds, tokens: state.tokens,
341
- gate: state.gate, findings: state.findings, error: state.error,
358
+ gate: state.gate, findings: state.findings, chainPass: state.chainPass, chains: state.chains, error: state.error,
342
359
  });
343
360
  });
344
361
  return snapshot(run);
@@ -24,6 +24,32 @@
24
24
  */
25
25
  import { readFileSync } from "node:fs";
26
26
  const ROLES = ["executor", "triage", "verify", "escalate"];
27
+ export const CHAIN_PASS_DEFAULTS = { enabled: true, maxCandidates: 3, maxRoundsPerChain: 3, reservePercent: 15 };
28
+ /** Upper bounds: a profile or a request can lower the caps, never lift them past these. */
29
+ export const CHAIN_PASS_LIMITS = { maxCandidates: 5, maxRoundsPerChain: 5, reservePercent: 50 };
30
+ /** The chain pass settings with the defaults filled in. */
31
+ export function resolveChainPass(c) {
32
+ return { ...CHAIN_PASS_DEFAULTS, ...(c ?? {}) };
33
+ }
34
+ function parseChainPass(raw) {
35
+ if (!raw || typeof raw !== "object")
36
+ return undefined;
37
+ const r = raw;
38
+ const c = {};
39
+ const int = (v, min, max) => (typeof v === "number" && Number.isInteger(v) && v >= min && v <= max ? v : undefined);
40
+ if (typeof r.enabled === "boolean")
41
+ c.enabled = r.enabled;
42
+ const candidates = int(r.maxCandidates, 1, CHAIN_PASS_LIMITS.maxCandidates);
43
+ const rounds = int(r.maxRoundsPerChain, 1, CHAIN_PASS_LIMITS.maxRoundsPerChain);
44
+ const reserve = int(r.reservePercent, 0, CHAIN_PASS_LIMITS.reservePercent);
45
+ if (candidates !== undefined)
46
+ c.maxCandidates = candidates;
47
+ if (rounds !== undefined)
48
+ c.maxRoundsPerChain = rounds;
49
+ if (reserve !== undefined)
50
+ c.reservePercent = reserve;
51
+ return Object.keys(c).length ? c : undefined;
52
+ }
27
53
  /** Built-in profiles, cheap -> capable (authored cheapest-role-first so shedding
28
54
  * and budget fallback pick the cheapest). `scx/*` is open-weight, `anthropic/*`
29
55
  * is Claude. `recon-open` works with no Anthropic key. */
@@ -64,6 +90,9 @@ export function parseReconHarness(raw) {
64
90
  h.tools = r.tools;
65
91
  if (r.effort === "low" || r.effort === "medium" || r.effort === "high")
66
92
  h.effort = r.effort;
93
+ const chainPass = parseChainPass(r.chainPass);
94
+ if (chainPass)
95
+ h.chainPass = chainPass;
67
96
  return Object.keys(h).length ? h : undefined;
68
97
  }
69
98
  export function parseProfile(def) {
@@ -643,7 +672,7 @@ const STATUS_RULE = `End every turn with exactly one final line: "${STATUS_LINE}
643
672
  export const reconAgents = () => ({
644
673
  recon: subagent(modelFor("executor"), "Supervised recon/autopwn executor: enumerate the in-scope target, hypothesise weaknesses, test them with low-impact probes, and hand candidates to recon-verify. Read-only shell; never mutates state without an approved step.", "You are the EXECUTOR in a supervised penetration test of a single, explicitly in-scope target. Work one hypothesis at a time: enumerate -> hypothesise a specific weakness (name the OWASP/API Top 10 or WSTG id) -> test it with the smallest, lowest-impact probe that settles it -> record exactly what you observed. Prefer read-only probes (GET, HEAD, nmap -sV, DNS, reading saved responses). Anything that changes state (POST that writes, PUT, PATCH, DELETE, file writes) is a RED LINE: stop and hand it to the human for approval, with the one request you want to run and why. When you believe you have a finding, call the recon-verify subagent with the evidence — do NOT promote it yourself. Stay strictly inside the declared scope. If you are stuck after a couple of tries, say so plainly rather than widening scope. " + STATUS_RULE, executorPermission(), "all"),
645
674
  "recon-triage": subagent(modelFor("triage"), "Fast, cheap triage of tool output: is this response interesting, already seen, or noise? Returns a one-line verdict and the single most promising next direction.", "You triage raw tool output for the executor. In two or three sentences: is there anything security-relevant here, have we effectively seen it already, and what is the single most promising next probe? Do not run tools or speculate beyond the output you were given.", READ_ONLY),
646
- "recon-verify": subagent(modelFor("verify"), "Adversarially verifies one candidate finding against the declared environment and the standards catalogue, assigns severity, and flags config-dependent findings before they are promoted.", "You VERIFY one candidate finding. Reject it unless there is concrete reproduction evidence (the request/command and the response that proves it). Assign severity with the project's rubric and cite the matching OWASP/API/WSTG id. CRITICAL: compare the finding against the declared environment fidelity — if it depends on a setting that differs from production (an auth flag off, a debug mode on, seed data), mark it config-dependent and say exactly what to re-test against production. Output exactly one fenced json block and nothing after it: {\"title\": \"short name of the finding\", \"verdict\": \"real\" | \"config-dependent\" | \"rejected\", \"severity\": \"low\" | \"medium\" | \"high\" | \"critical\", \"standard_id\": \"e.g. API1:2023\", \"repro\": \"the request or command and the response that proves it\", \"prod_caveat\": \"what to re-test against production, or an empty string\"}.", READ_ONLY),
675
+ "recon-verify": subagent(modelFor("verify"), "Adversarially verifies one candidate finding, or one attack path that builds on findings, against the declared environment and the standards catalogue, assigns severity, and flags config-dependent findings before they are promoted.", "You VERIFY one candidate finding. Reject it unless there is concrete reproduction evidence (the request/command and the response that proves it). Assign severity with the project's rubric and cite the matching OWASP/API/WSTG id. CRITICAL: compare the finding against the declared environment fidelity — if it depends on a setting that differs from production (an auth flag off, a debug mode on, seed data), mark it config-dependent and say exactly what to re-test against production. Output exactly one fenced json block and nothing after it: {\"title\": \"short name of the finding\", \"verdict\": \"real\" | \"config-dependent\" | \"rejected\", \"severity\": \"low\" | \"medium\" | \"high\" | \"critical\", \"standard_id\": \"e.g. API1:2023\", \"repro\": \"the request or command and the response that proves it\", \"prod_caveat\": \"what to re-test against production, or an empty string\"}. When you are handed an ATTACK PATH (several steps that build on findings named F1, F2 and so on) instead of one finding, rule on the path as a whole. Reject it unless every step has its own request or command and response, and the evidence shows that what one step returned was used in the next: steps that each work but do not connect are not a path. A path that stops at a step that could not be shown is partial, never demonstrated. Rate severity on what the attacker ends up with, and apply the same environment check. For a path, output the block in this form instead: {\"kind\": \"chain\", \"title\": \"short name of the path\", \"verdict\": \"real\" | \"config-dependent\" | \"rejected\", \"severity\": \"low\" | \"medium\" | \"high\" | \"critical\", \"standard_id\": \"e.g. API1:2023\", \"impact\": \"what the attacker ends up with\", \"links\": [\"F1\", \"F3\"], \"steps\": [{\"action\": \"what was done\", \"evidence\": \"the request or command and the response\"}], \"status\": \"demonstrated\" | \"partial\", \"blocked_at\": the number of the step it stopped at, or null, \"blocked_why\": \"why it stopped, or an empty string\", \"prod_caveat\": \"what to re-test against production, or an empty string\"}.", READ_ONLY),
647
676
  "recon-escalate": subagent(modelFor("escalate"), "Frontier escalation: called only when the executor is stuck or a High/Critical candidate needs deep adversarial review or multi-step exploit-chain reasoning. Read-only.", "You are the escalation reviewer, called rarely and only for hard cases: a stuck executor, or a High/Critical candidate that must survive adversarial scrutiny before it is reported. Reason carefully about exploitability and chaining, demand evidence, and be willing to downgrade or reject. Do not run tools; reason over what you are given and return a precise recommendation.", READ_ONLY),
648
677
  });
649
678
  //# sourceMappingURL=recon.js.map