bugxhunter 0.12.0 → 0.14.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 +261 -39
- package/package.json +1 -1
- package/server/dist/auth.js +4 -0
- package/server/dist/index.js +202 -11
- package/server/dist/recon-batch.js +202 -0
- package/server/dist/recon-driver.js +642 -30
- package/server/dist/recon-evidence.js +53 -0
- package/server/dist/recon-memory.js +227 -0
- package/server/dist/recon-run.js +62 -5
- package/server/dist/recon-session.js +260 -0
- package/server/dist/recon.js +76 -6
- package/server/dist/vault.js +11 -0
- package/server/dist/zip.js +54 -0
- package/web/dist/assets/index-DTJE8gwZ.js +303 -0
- package/web/dist/assets/{index-B1Wq0jKz.css → index-Du7TnY-M.css} +1 -1
- package/web/dist/bxh-extension/background.js +21 -0
- package/web/dist/bxh-extension/manifest.json +11 -0
- package/web/dist/bxh-extension/payload.d.ts +12 -0
- package/web/dist/bxh-extension/payload.js +43 -0
- package/web/dist/bxh-extension/popup.css +14 -0
- package/web/dist/bxh-extension/popup.html +24 -0
- package/web/dist/bxh-extension/popup.js +61 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-0S40kM52.js +0 -303
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the commands of a recon run really returned, kept so a verdict can be held to it.
|
|
3
|
+
*
|
|
4
|
+
* The verifier is a model: it is shown the executor's account of a response, and could be
|
|
5
|
+
* shown a paraphrase or an invention. So it is asked to quote the response, and the quotes
|
|
6
|
+
* are looked up here, in the output the run's own shell commands produced (which the runner
|
|
7
|
+
* reads from the agent's event stream, not from anything a model wrote). A quote that is
|
|
8
|
+
* found proves the text was really returned to this run; it does not prove the finding.
|
|
9
|
+
*
|
|
10
|
+
* Pure and in memory: the log lives as long as the run.
|
|
11
|
+
*/
|
|
12
|
+
/** A quote shorter than this (after whitespace is collapsed) proves nothing: "200", "true", "admin". */
|
|
13
|
+
export const MIN_QUOTE = 12;
|
|
14
|
+
const MAX_OUTPUT = 400_000;
|
|
15
|
+
const MAX_TOTAL = 8_000_000;
|
|
16
|
+
const MAX_QUOTES = 5;
|
|
17
|
+
/** Whitespace collapsed, so a wrapped or re-indented copy of a response still matches. Case is kept. */
|
|
18
|
+
export const normalise = (text) => text.replace(/\s+/g, " ").trim();
|
|
19
|
+
export class EvidenceLog {
|
|
20
|
+
outputs = [];
|
|
21
|
+
total = 0;
|
|
22
|
+
/** How many command outputs are held. */
|
|
23
|
+
get size() { return this.outputs.length; }
|
|
24
|
+
/** Record one command's output. The oldest are dropped once the log is full. */
|
|
25
|
+
add(output) {
|
|
26
|
+
const text = normalise(String(output ?? "").slice(0, MAX_OUTPUT));
|
|
27
|
+
if (!text)
|
|
28
|
+
return;
|
|
29
|
+
this.outputs.push(text);
|
|
30
|
+
this.total += text.length;
|
|
31
|
+
while (this.total > MAX_TOTAL && this.outputs.length > 1)
|
|
32
|
+
this.total -= this.outputs.shift().length;
|
|
33
|
+
}
|
|
34
|
+
/** Was this text really returned by a command of this run? */
|
|
35
|
+
has(quote) {
|
|
36
|
+
const q = normalise(quote);
|
|
37
|
+
return q.length >= MIN_QUOTE && this.outputs.some((o) => o.includes(q));
|
|
38
|
+
}
|
|
39
|
+
/** Hold a verdict's quotes to the log. */
|
|
40
|
+
check(quotes) {
|
|
41
|
+
const usable = (quotes ?? []).filter((q) => normalise(q).length >= MIN_QUOTE);
|
|
42
|
+
if (!usable.length)
|
|
43
|
+
return "unquoted";
|
|
44
|
+
return usable.every((q) => this.has(q)) ? "quoted" : "unmatched";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** The quotes of a verdict as the verifier wrote them: strings only, a handful, each of bounded length. */
|
|
48
|
+
export function readQuotes(raw) {
|
|
49
|
+
if (!Array.isArray(raw))
|
|
50
|
+
return [];
|
|
51
|
+
return raw.filter((q) => typeof q === "string" && Boolean(q.trim())).slice(0, MAX_QUOTES).map((q) => q.slice(0, 600));
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=recon-evidence.js.map
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What supervised recon runs found, kept between runs and across restarts, encrypted with
|
|
3
|
+
* the vault key.
|
|
4
|
+
*
|
|
5
|
+
* One file per finished run next to the vault: /data/recon in Docker (the runner-only
|
|
6
|
+
* runner-data volume, never the agent's), ~/.config/bugxhunter/recon otherwise. Only an id
|
|
7
|
+
* and the finish time are in the clear; the target, the session and everything the run
|
|
8
|
+
* found are sealed, bound to the record by its AAD. A copied volume shows how many runs
|
|
9
|
+
* there were and when, nothing about what was tested or found.
|
|
10
|
+
*
|
|
11
|
+
* Two things read it back: a new run on the same target starts from what earlier runs
|
|
12
|
+
* verified there (`recall`), and a session shows its last run again after a restart
|
|
13
|
+
* (`lastForSession`). Without a vault nothing is kept; with a locked one a finished run
|
|
14
|
+
* waits in memory and is written when the vault is next unlocked.
|
|
15
|
+
*/
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import crypto from "node:crypto";
|
|
19
|
+
import { VAULT_FILE, isInitialised, isUnsealed, onUnsealed, openData, sealData } from "./vault.js";
|
|
20
|
+
import { httpError } from "./errors.js";
|
|
21
|
+
import { audit } from "./audit.js";
|
|
22
|
+
import { originOf } from "./recon.js";
|
|
23
|
+
const dir = () => process.env.OPEN_RUNNER_RECON_DIR ?? path.join(path.dirname(VAULT_FILE), "recon");
|
|
24
|
+
/** Runs kept in all; the oldest are dropped past this. */
|
|
25
|
+
export const MAX_RUNS = 300;
|
|
26
|
+
/** What one recall hands a new run: enough to start from, not the whole history. */
|
|
27
|
+
const MAX_RECALLED_FINDINGS = 40;
|
|
28
|
+
const MAX_RECALLED_PATHS = 10;
|
|
29
|
+
const MAX_RECALLED_LEADS = 15;
|
|
30
|
+
const MAX_PENDING = 20;
|
|
31
|
+
const ID = /^[0-9]{13}-[a-f0-9]{12}$/;
|
|
32
|
+
const aad = (id) => `recon:${id}:body`;
|
|
33
|
+
const file = (id) => path.join(dir(), `${id}.json`);
|
|
34
|
+
/** The key runs are grouped by: the target's host and port, whatever path or scheme the scope was typed with. */
|
|
35
|
+
export function targetKey(scope) {
|
|
36
|
+
const { host, port } = originOf(scope.trim());
|
|
37
|
+
return host ? `${host}:${port}` : undefined;
|
|
38
|
+
}
|
|
39
|
+
function ids() {
|
|
40
|
+
try {
|
|
41
|
+
return fs.readdirSync(dir()).filter((n) => n.endsWith(".json")).map((n) => n.slice(0, -5)).filter((id) => ID.test(id)).sort();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Every stored run that opens with the current vault, oldest first. Throws 503 while the vault is locked. */
|
|
48
|
+
function all() {
|
|
49
|
+
// Said even when nothing is stored yet, so "locked" is never shown as "nothing remembered".
|
|
50
|
+
if (isInitialised() && !isUnsealed())
|
|
51
|
+
throw httpError(503, "The vault is sealed (locked). Unlock it to read what earlier runs found.");
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const id of ids()) {
|
|
54
|
+
let r;
|
|
55
|
+
try {
|
|
56
|
+
r = JSON.parse(fs.readFileSync(file(id), "utf8"));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (r?.v !== 1 || r.id !== id)
|
|
62
|
+
continue;
|
|
63
|
+
try {
|
|
64
|
+
const body = JSON.parse(openData(r.body, aad(id)));
|
|
65
|
+
if (typeof body.target === "string" && body.state && Array.isArray(body.state.findings))
|
|
66
|
+
out.push({ id, target: body.target, state: body.state });
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
if (e.status === 503)
|
|
70
|
+
throw e;
|
|
71
|
+
// a record from another vault, or a tampered one: skipped, not fatal
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/** The same, or nothing when the vault is locked or absent: reading memory never fails a run. */
|
|
77
|
+
function allOrNone() {
|
|
78
|
+
try {
|
|
79
|
+
return all();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function write(state) {
|
|
86
|
+
const target = targetKey(state.scope);
|
|
87
|
+
if (!target)
|
|
88
|
+
return;
|
|
89
|
+
const finishedAt = state.finishedAt ?? Date.now();
|
|
90
|
+
const id = `${String(finishedAt).padStart(13, "0")}-${crypto.randomBytes(6).toString("hex")}`;
|
|
91
|
+
const record = { v: 1, id, finishedAt: new Date(finishedAt).toISOString(), body: sealData(JSON.stringify({ target, state }), aad(id)) };
|
|
92
|
+
fs.mkdirSync(dir(), { recursive: true, mode: 0o700 });
|
|
93
|
+
const tmp = `${file(id)}.${process.pid}.tmp`;
|
|
94
|
+
fs.writeFileSync(tmp, JSON.stringify(record), { mode: 0o600 });
|
|
95
|
+
fs.renameSync(tmp, file(id));
|
|
96
|
+
const have = ids();
|
|
97
|
+
for (const old of have.slice(0, Math.max(0, have.length - MAX_RUNS)))
|
|
98
|
+
fs.rmSync(file(old), { force: true });
|
|
99
|
+
}
|
|
100
|
+
/** Finished runs that could not be written because the vault was locked. Held in this process only. */
|
|
101
|
+
const pending = [];
|
|
102
|
+
/**
|
|
103
|
+
* Keep a finished run. `saved`: written. `pending`: the vault is locked, so it waits in
|
|
104
|
+
* memory until the next unlock (and is lost if the runner restarts first). `off`: there is
|
|
105
|
+
* no vault, or the write failed, and nothing is kept.
|
|
106
|
+
*/
|
|
107
|
+
export function remember(state) {
|
|
108
|
+
if (state.status !== "finished")
|
|
109
|
+
return "off";
|
|
110
|
+
try {
|
|
111
|
+
write(state);
|
|
112
|
+
audit("recon.remembered", { session: state.sessionID, findings: state.findings.length, paths: state.chains?.length ?? 0 });
|
|
113
|
+
return "saved";
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
if (e.status === 503) {
|
|
117
|
+
pending.push(state);
|
|
118
|
+
if (pending.length > MAX_PENDING)
|
|
119
|
+
pending.shift();
|
|
120
|
+
return "pending";
|
|
121
|
+
}
|
|
122
|
+
return "off";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** Write the runs that finished while the vault was locked. */
|
|
126
|
+
export function flushPending() {
|
|
127
|
+
for (const state of pending.splice(0)) {
|
|
128
|
+
try {
|
|
129
|
+
write(state);
|
|
130
|
+
state.kept = "saved";
|
|
131
|
+
audit("recon.remembered", { session: state.sessionID, findings: state.findings.length, paths: state.chains?.length ?? 0, late: true });
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// still not writable: this run is not kept
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
onUnsealed(flushPending);
|
|
139
|
+
const sameFinding = (title, standardId) => `${title.toLowerCase().replace(/\s+/g, " ").trim()}|${(standardId ?? "").toLowerCase()}`;
|
|
140
|
+
/** What earlier runs on a target verified, newest first and without repeats. */
|
|
141
|
+
export function recallFrom(runs) {
|
|
142
|
+
if (!runs.length)
|
|
143
|
+
return undefined;
|
|
144
|
+
const newestFirst = [...runs].sort((a, b) => (b.finishedAt ?? b.startedAt) - (a.finishedAt ?? a.startedAt));
|
|
145
|
+
const findings = new Map();
|
|
146
|
+
const paths = new Map();
|
|
147
|
+
// A finding a later run retested and found fixed is no longer a lead: older runs' record of it is passed over.
|
|
148
|
+
const fixed = new Set();
|
|
149
|
+
for (const run of newestFirst) {
|
|
150
|
+
const seen = run.finishedAt ?? run.startedAt;
|
|
151
|
+
for (const r of run.retests ?? []) {
|
|
152
|
+
const key = sameFinding(r.title, r.standardId);
|
|
153
|
+
if (r.result === "fixed" && !findings.has(key))
|
|
154
|
+
fixed.add(key);
|
|
155
|
+
}
|
|
156
|
+
for (const f of run.findings) {
|
|
157
|
+
if (f.verdict === "rejected")
|
|
158
|
+
continue;
|
|
159
|
+
const key = sameFinding(f.title, f.standardId);
|
|
160
|
+
if (fixed.has(key))
|
|
161
|
+
continue;
|
|
162
|
+
const known = findings.get(key);
|
|
163
|
+
if (known) {
|
|
164
|
+
known.runs += 1;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
findings.set(key, { title: f.title, severity: f.severity, verdict: f.verdict, standardId: f.standardId, repro: f.repro, env: f.env, seen, runs: 1 });
|
|
168
|
+
}
|
|
169
|
+
for (const c of run.chains ?? []) {
|
|
170
|
+
const key = sameFinding(c.title);
|
|
171
|
+
if (paths.has(key))
|
|
172
|
+
continue;
|
|
173
|
+
paths.set(key, { title: c.title, severity: c.severity, status: c.status, impact: c.impact, steps: c.steps.map((s) => s.action), seen });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const rank = { critical: 3, high: 2, medium: 1, low: 0 };
|
|
177
|
+
// Only the newest exploring run's open leads: an older run's were either followed since or are stale.
|
|
178
|
+
const lastExplored = newestFirst.find((r) => r.mode !== "retest");
|
|
179
|
+
const leads = (lastExplored?.leads ?? []).filter((l) => l.status === "open").map((l) => l.text).slice(0, MAX_RECALLED_LEADS);
|
|
180
|
+
return {
|
|
181
|
+
runs: runs.length,
|
|
182
|
+
...(leads.length ? { leads } : {}),
|
|
183
|
+
lastRun: newestFirst[0].finishedAt ?? newestFirst[0].startedAt,
|
|
184
|
+
findings: [...findings.values()].sort((a, b) => rank[b.severity] - rank[a.severity] || b.seen - a.seen).slice(0, MAX_RECALLED_FINDINGS),
|
|
185
|
+
// Demonstrated paths first: a partial one is only a lead.
|
|
186
|
+
paths: [...paths.values()].sort((a, b) => Number(b.status === "demonstrated") - Number(a.status === "demonstrated") || b.seen - a.seen).slice(0, MAX_RECALLED_PATHS),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** What earlier runs verified on this target, or undefined when there is nothing (or the vault is locked). */
|
|
190
|
+
export function recall(scope) {
|
|
191
|
+
const target = targetKey(scope);
|
|
192
|
+
if (!target)
|
|
193
|
+
return undefined;
|
|
194
|
+
return recallFrom(allOrNone().filter((r) => r.target === target).map((r) => r.state));
|
|
195
|
+
}
|
|
196
|
+
/** The last finished run on a session, so its results are still there after a restart. */
|
|
197
|
+
export function lastForSession(sessionID) {
|
|
198
|
+
if (!sessionID)
|
|
199
|
+
return null;
|
|
200
|
+
const mine = allOrNone().filter((r) => r.state.sessionID === sessionID);
|
|
201
|
+
return mine.length ? { ...mine[mine.length - 1].state, kept: "saved" } : null;
|
|
202
|
+
}
|
|
203
|
+
/** The targets something is remembered about, most recent first. Throws 503 while the vault is locked. */
|
|
204
|
+
export function targets() {
|
|
205
|
+
const by = new Map();
|
|
206
|
+
for (const r of all())
|
|
207
|
+
by.set(r.target, [...(by.get(r.target) ?? []), r.state]);
|
|
208
|
+
return [...by.entries()].map(([target, runs]) => {
|
|
209
|
+
const r = recallFrom(runs);
|
|
210
|
+
return { target, runs: r.runs, findings: r.findings.length, paths: r.paths.length, lastRun: r.lastRun };
|
|
211
|
+
}).sort((a, b) => b.lastRun - a.lastRun);
|
|
212
|
+
}
|
|
213
|
+
/** Forget every run on one target. Returns how many were deleted. Throws 503 while the vault is locked. */
|
|
214
|
+
export function forget(scope) {
|
|
215
|
+
const target = targetKey(scope);
|
|
216
|
+
if (!target)
|
|
217
|
+
return 0;
|
|
218
|
+
const mine = all().filter((r) => r.target === target);
|
|
219
|
+
for (const r of mine)
|
|
220
|
+
fs.rmSync(file(r.id), { force: true });
|
|
221
|
+
for (let i = pending.length - 1; i >= 0; i--)
|
|
222
|
+
if (targetKey(pending[i].scope) === target)
|
|
223
|
+
pending.splice(i, 1);
|
|
224
|
+
audit("recon.forgotten", { runs: mine.length });
|
|
225
|
+
return mine.length;
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=recon-memory.js.map
|
package/server/dist/recon-run.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { driveRecon, extractReconCommand, parseTurnStatus, parseVerifierFindings, resolveHarness, } from "./recon-driver.js";
|
|
2
2
|
import { activeProfileName, originOf } from "./recon.js";
|
|
3
3
|
import { httpError } from "./errors.js";
|
|
4
|
+
import { EvidenceLog } from "./recon-evidence.js";
|
|
4
5
|
/** The agent the driver prompts, and the subagent whose replies are verdicts. */
|
|
5
6
|
export const EXECUTOR_AGENT = "recon";
|
|
6
7
|
export const VERIFY_AGENT = "recon-verify";
|
|
@@ -39,6 +40,9 @@ export class OpencodeReconRunner {
|
|
|
39
40
|
toolInputs = new Map();
|
|
40
41
|
handledPermissions = new Set();
|
|
41
42
|
verified = new Set();
|
|
43
|
+
/** What the run's shell commands really returned, from the event stream: what quotes are held to. */
|
|
44
|
+
evidence = new EvidenceLog();
|
|
45
|
+
recorded = new Set();
|
|
42
46
|
capped = new Map();
|
|
43
47
|
constructor(backend, sessionID, env, onGate = () => { }) {
|
|
44
48
|
this.backend = backend;
|
|
@@ -91,6 +95,8 @@ export class OpencodeReconRunner {
|
|
|
91
95
|
this.sub = null;
|
|
92
96
|
}
|
|
93
97
|
get wasAborted() { return this.aborted; }
|
|
98
|
+
/** Hold quotes to what this run's commands really returned. */
|
|
99
|
+
proof(quotes) { return this.evidence.check(quotes); }
|
|
94
100
|
/** Does this run own `sessionID` (the root or one of its subagent sessions)? */
|
|
95
101
|
owns(sessionID) { return this.family.has(sessionID); }
|
|
96
102
|
async runTurn(args) {
|
|
@@ -103,7 +109,7 @@ export class OpencodeReconRunner {
|
|
|
103
109
|
this.turn = {
|
|
104
110
|
model: args.model, gate: args.gate, resolve, reject,
|
|
105
111
|
tokensAtStart: this.tokens, sawAssistant: false,
|
|
106
|
-
toolsCompleted: new Set(), texts: new Map(), findings: [],
|
|
112
|
+
toolsCompleted: new Set(), texts: new Map(), findings: [], verifierOutputs: [],
|
|
107
113
|
};
|
|
108
114
|
});
|
|
109
115
|
try {
|
|
@@ -134,6 +140,8 @@ export class OpencodeReconRunner {
|
|
|
134
140
|
t.resolve({
|
|
135
141
|
tokensUsed: Math.max(0, this.tokens - t.tokensAtStart),
|
|
136
142
|
findings: t.findings,
|
|
143
|
+
text,
|
|
144
|
+
verifierOutputs: t.verifierOutputs,
|
|
137
145
|
...parseTurnStatus(text, t.toolsCompleted.size),
|
|
138
146
|
...extra,
|
|
139
147
|
});
|
|
@@ -211,6 +219,11 @@ export class OpencodeReconRunner {
|
|
|
211
219
|
this.toolInputs.set(part.callID, st.input);
|
|
212
220
|
if (st.status !== "completed" && st.status !== "error")
|
|
213
221
|
return;
|
|
222
|
+
// Every shell command of the run, the subagents' included: its output is the record quotes are checked against.
|
|
223
|
+
if (part.tool === "bash" && part.callID && typeof st.output === "string" && !this.recorded.has(part.callID)) {
|
|
224
|
+
this.recorded.add(part.callID);
|
|
225
|
+
this.evidence.add(st.output);
|
|
226
|
+
}
|
|
214
227
|
if (part.sessionID !== this.sessionID || !this.turn)
|
|
215
228
|
return;
|
|
216
229
|
this.turn.toolsCompleted.add(part.callID);
|
|
@@ -221,7 +234,8 @@ export class OpencodeReconRunner {
|
|
|
221
234
|
if ((input.subagent_type ?? input.agent) !== VERIFY_AGENT || typeof st.output !== "string")
|
|
222
235
|
return;
|
|
223
236
|
this.verified.add(part.callID);
|
|
224
|
-
this.turn.findings.push(...parseVerifierFindings(st.output, this.env));
|
|
237
|
+
this.turn.findings.push(...parseVerifierFindings(st.output, this.env).map((f) => ({ ...f, proof: this.evidence.check(f.quotes) })));
|
|
238
|
+
this.turn.verifierOutputs.push(st.output);
|
|
225
239
|
}
|
|
226
240
|
onPermission(perm) {
|
|
227
241
|
if (this.handledPermissions.has(perm.id))
|
|
@@ -253,7 +267,11 @@ const runs = new Map();
|
|
|
253
267
|
function snapshot(run) {
|
|
254
268
|
const { state, runner } = run;
|
|
255
269
|
if (state.status === "running") {
|
|
256
|
-
|
|
270
|
+
// Once the chain pass has started, `rounds` stays at the main loop's count and its own turns are counted apart.
|
|
271
|
+
if (state.phase === "chains")
|
|
272
|
+
state.chainRounds = Math.max(0, runner.rounds - state.rounds);
|
|
273
|
+
else
|
|
274
|
+
state.rounds = runner.rounds;
|
|
257
275
|
state.tokens = runner.tokens;
|
|
258
276
|
state.model = runner.model;
|
|
259
277
|
state.gate = { ...runner.gateCounts };
|
|
@@ -306,6 +324,9 @@ export async function startRecon(o) {
|
|
|
306
324
|
sessionID: o.sessionID, scope, objective, env: o.env, profile: activeProfileName(),
|
|
307
325
|
status: "running", rounds: 0, maxRounds: harness.maxRounds, tokens: 0, budgetTokens: harness.budgetTokens,
|
|
308
326
|
gate: { allowed: 0, asked: 0, denied: 0 }, findings: [], startedAt: Date.now(),
|
|
327
|
+
...(o.retest?.length ? { mode: "retest", retests: [] } : {}),
|
|
328
|
+
...(o.session ? { session: { capturedAt: o.session.capturedAt, cookies: o.session.cookies, authorization: o.session.authorization } } : {}),
|
|
329
|
+
...(o.prior ? { memory: { runs: o.prior.runs, findings: o.prior.findings.length, paths: o.prior.paths.length, lastRun: o.prior.lastRun } } : {}),
|
|
309
330
|
};
|
|
310
331
|
const run = { state, runner };
|
|
311
332
|
await runner.start(); // subscribed before the first prompt, so no event is missed
|
|
@@ -313,6 +334,7 @@ export async function startRecon(o) {
|
|
|
313
334
|
o.log?.("recon.started", { session: o.sessionID, scope, objective, env: o.env, profile: state.profile, maxRounds: state.maxRounds, budgetTokens: state.budgetTokens });
|
|
314
335
|
let lastError;
|
|
315
336
|
const seam = {
|
|
337
|
+
proof: (quotes) => runner.proof(quotes),
|
|
316
338
|
async runTurn(args) {
|
|
317
339
|
try {
|
|
318
340
|
const res = await runner.runTurn(args);
|
|
@@ -325,20 +347,55 @@ export async function startRecon(o) {
|
|
|
325
347
|
}
|
|
326
348
|
},
|
|
327
349
|
};
|
|
328
|
-
|
|
350
|
+
const onChainPass = (chains) => {
|
|
351
|
+
if (state.phase !== "chains") {
|
|
352
|
+
state.rounds = runner.rounds;
|
|
353
|
+
state.phase = "chains";
|
|
354
|
+
}
|
|
355
|
+
state.chains = [...chains];
|
|
356
|
+
};
|
|
357
|
+
const onRetest = (retests) => { state.retests = [...retests]; };
|
|
358
|
+
const onLeads = (leads) => { state.leads = leads.map((l) => ({ ...l })); };
|
|
359
|
+
// A path recorded during the main loop: shown at once, and the run stays in its main phase.
|
|
360
|
+
const onChains = (chains) => { state.chains = [...chains]; };
|
|
361
|
+
void driveRecon({ objective, scope, env: o.env, runner: seam, harness, rateLimited: () => runner.rateLimited(), onChainPass, onChains, prior: o.prior, session: o.session, retest: o.retest, onRetest, onLeads })
|
|
329
362
|
.then((result) => {
|
|
330
363
|
snapshot(run); // last live numbers before the status flips
|
|
331
364
|
state.status = "finished";
|
|
332
365
|
state.stopped = runner.wasAborted ? "aborted" : result.stopped;
|
|
333
366
|
state.findings = result.findings;
|
|
367
|
+
state.chains = result.chains;
|
|
368
|
+
if (result.leads.length)
|
|
369
|
+
state.leads = result.leads;
|
|
370
|
+
if (result.retests)
|
|
371
|
+
state.retests = result.retests;
|
|
372
|
+
else
|
|
373
|
+
state.chainPass = result.chainPass; // a retest run has no chain pass to report on
|
|
334
374
|
state.rounds = result.rounds;
|
|
375
|
+
state.chainRounds = result.chainRounds;
|
|
335
376
|
if (state.stopped === "error")
|
|
336
377
|
state.error = lastError;
|
|
337
378
|
state.finishedAt = Date.now();
|
|
338
379
|
runner.close();
|
|
380
|
+
try {
|
|
381
|
+
o.session?.cleanup();
|
|
382
|
+
}
|
|
383
|
+
catch { /* the folder is gone or not ours to remove */ }
|
|
384
|
+
if (o.remember) {
|
|
385
|
+
try {
|
|
386
|
+
state.kept = o.remember(state);
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
state.kept = "off";
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
try {
|
|
393
|
+
o.onFinished?.(state);
|
|
394
|
+
}
|
|
395
|
+
catch { /* the listener's failure is not the run's */ }
|
|
339
396
|
o.log?.("recon.finished", {
|
|
340
397
|
session: o.sessionID, stopped: state.stopped, rounds: state.rounds, tokens: state.tokens,
|
|
341
|
-
gate: state.gate, findings: state.findings, error: state.error,
|
|
398
|
+
gate: state.gate, findings: state.findings, chainPass: state.chainPass, chains: state.chains, error: state.error,
|
|
342
399
|
});
|
|
343
400
|
});
|
|
344
401
|
return snapshot(run);
|