bugxhunter 0.9.7 → 0.10.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 +41 -0
- package/docker-compose.yml +13 -0
- package/package.json +1 -1
- package/server/dist/index.js +84 -2
- package/server/dist/opencode.js +20 -4
- package/server/dist/recon-driver.js +87 -3
- package/server/dist/recon-run.js +355 -0
- package/server/dist/recon.js +41 -20
- package/web/dist/assets/index-CBhVvqRv.js +299 -0
- package/web/dist/assets/{index-BjTwxExC.css → index-CjUMxwNm.css} +1 -1
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-DM-d9GKr.js +0 -298
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { driveRecon, extractReconCommand, parseTurnStatus, parseVerifierFindings, resolveHarness, } from "./recon-driver.js";
|
|
2
|
+
import { activeProfileName, originOf } from "./recon.js";
|
|
3
|
+
import { httpError } from "./errors.js";
|
|
4
|
+
/** The agent the driver prompts, and the subagent whose replies are verdicts. */
|
|
5
|
+
export const EXECUTOR_AGENT = "recon";
|
|
6
|
+
export const VERIFY_AGENT = "recon-verify";
|
|
7
|
+
/** How long a model that answered "rate limited" is routed around. */
|
|
8
|
+
const RATE_LIMIT_COOLDOWN_MS = 60_000;
|
|
9
|
+
const obj = (v) => (v && typeof v === "object" ? v : {});
|
|
10
|
+
const isRateLimit = (msg) => /\b429\b|rate.?limit|too many requests|overloaded|quota/i.test(msg);
|
|
11
|
+
function errorMessage(err) {
|
|
12
|
+
const e = obj(err);
|
|
13
|
+
const msg = obj(e.data).message ?? e.message ?? e.name;
|
|
14
|
+
const status = obj(e.data).statusCode;
|
|
15
|
+
return msg ? (status ? `${msg} (HTTP ${status})` : String(msg)) : JSON.stringify(err ?? {}).slice(0, 300);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Runs executor turns on one OpenCode session and applies the gate to the
|
|
19
|
+
* permissions that session and its subagents raise.
|
|
20
|
+
*/
|
|
21
|
+
export class OpencodeReconRunner {
|
|
22
|
+
backend;
|
|
23
|
+
sessionID;
|
|
24
|
+
env;
|
|
25
|
+
onGate;
|
|
26
|
+
/** Counters and the model in use, for the status the UI polls. */
|
|
27
|
+
gateCounts = { allowed: 0, asked: 0, denied: 0 };
|
|
28
|
+
rounds = 0;
|
|
29
|
+
model;
|
|
30
|
+
turn = null;
|
|
31
|
+
sub = null;
|
|
32
|
+
aborted = false;
|
|
33
|
+
/** The root session and the subagent sessions it spawned. */
|
|
34
|
+
family;
|
|
35
|
+
assistantMessages = new Set();
|
|
36
|
+
/** Latest token count per assistant message, across the family. */
|
|
37
|
+
messageTokens = new Map();
|
|
38
|
+
/** Tool call -> its input, so a permission can be matched to the exact command. */
|
|
39
|
+
toolInputs = new Map();
|
|
40
|
+
handledPermissions = new Set();
|
|
41
|
+
verified = new Set();
|
|
42
|
+
capped = new Map();
|
|
43
|
+
constructor(backend, sessionID, env, onGate = () => { }) {
|
|
44
|
+
this.backend = backend;
|
|
45
|
+
this.sessionID = sessionID;
|
|
46
|
+
this.env = env;
|
|
47
|
+
this.onGate = onGate;
|
|
48
|
+
this.family = new Set([sessionID]);
|
|
49
|
+
}
|
|
50
|
+
get tokens() {
|
|
51
|
+
let n = 0;
|
|
52
|
+
for (const t of this.messageTokens.values())
|
|
53
|
+
n += t;
|
|
54
|
+
return n;
|
|
55
|
+
}
|
|
56
|
+
/** Models to route around right now (those that recently answered "rate limited"). */
|
|
57
|
+
rateLimited() {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
const out = {};
|
|
60
|
+
for (const [model, until] of this.capped) {
|
|
61
|
+
if (until > now)
|
|
62
|
+
out[model] = true;
|
|
63
|
+
else
|
|
64
|
+
this.capped.delete(model);
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
/** Subscribe to events. Call once, before the first turn. */
|
|
69
|
+
async start() {
|
|
70
|
+
const sub = await this.backend.events();
|
|
71
|
+
this.sub = sub;
|
|
72
|
+
void (async () => {
|
|
73
|
+
try {
|
|
74
|
+
for await (const evt of sub.stream)
|
|
75
|
+
this.handle(evt);
|
|
76
|
+
this.fail(new Error("The event stream from OpenCode ended."));
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
this.fail(e instanceof Error ? e : new Error(String(e)));
|
|
80
|
+
}
|
|
81
|
+
})();
|
|
82
|
+
}
|
|
83
|
+
/** Stop: abort the turn in OpenCode and end the run. */
|
|
84
|
+
async stop() {
|
|
85
|
+
this.aborted = true;
|
|
86
|
+
await this.backend.abort(this.sessionID).catch(() => { });
|
|
87
|
+
this.fail(new Error("aborted"));
|
|
88
|
+
}
|
|
89
|
+
close() {
|
|
90
|
+
this.sub?.close();
|
|
91
|
+
this.sub = null;
|
|
92
|
+
}
|
|
93
|
+
get wasAborted() { return this.aborted; }
|
|
94
|
+
/** Does this run own `sessionID` (the root or one of its subagent sessions)? */
|
|
95
|
+
owns(sessionID) { return this.family.has(sessionID); }
|
|
96
|
+
async runTurn(args) {
|
|
97
|
+
if (this.aborted)
|
|
98
|
+
throw new Error("aborted");
|
|
99
|
+
if (this.turn)
|
|
100
|
+
throw new Error("a recon turn is already running");
|
|
101
|
+
this.model = args.model;
|
|
102
|
+
const done = new Promise((resolve, reject) => {
|
|
103
|
+
this.turn = {
|
|
104
|
+
model: args.model, gate: args.gate, resolve, reject,
|
|
105
|
+
tokensAtStart: this.tokens, sawAssistant: false,
|
|
106
|
+
toolsCompleted: new Set(), texts: new Map(), findings: [],
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
try {
|
|
110
|
+
await this.backend.prompt({ sessionID: this.sessionID, agent: EXECUTOR_AGENT, model: args.model, text: args.prompt });
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
this.turn = null;
|
|
114
|
+
throw e;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
return await done;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
this.rounds += 1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
fail(e) {
|
|
124
|
+
const t = this.turn;
|
|
125
|
+
this.turn = null;
|
|
126
|
+
t?.reject(e);
|
|
127
|
+
}
|
|
128
|
+
finish(extra = {}) {
|
|
129
|
+
const t = this.turn;
|
|
130
|
+
if (!t)
|
|
131
|
+
return;
|
|
132
|
+
this.turn = null;
|
|
133
|
+
const text = [...t.texts.values()].filter((p) => this.assistantMessages.has(p.messageID)).map((p) => p.text).join("\n");
|
|
134
|
+
t.resolve({
|
|
135
|
+
tokensUsed: Math.max(0, this.tokens - t.tokensAtStart),
|
|
136
|
+
findings: t.findings,
|
|
137
|
+
...parseTurnStatus(text, t.toolsCompleted.size),
|
|
138
|
+
...extra,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** One raw OpenCode event. Exposed for tests. */
|
|
142
|
+
handle(evt) {
|
|
143
|
+
const type = obj(evt).type;
|
|
144
|
+
const p = obj(obj(evt).properties);
|
|
145
|
+
switch (type) {
|
|
146
|
+
case "session.created":
|
|
147
|
+
case "session.updated": {
|
|
148
|
+
const info = obj(p.info);
|
|
149
|
+
if (info.id && info.parentID && this.family.has(info.parentID))
|
|
150
|
+
this.family.add(info.id);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
case "message.updated": {
|
|
154
|
+
const info = obj(p.info);
|
|
155
|
+
if (!info.id || info.role !== "assistant" || !this.family.has(info.sessionID))
|
|
156
|
+
return;
|
|
157
|
+
const t = obj(info.tokens);
|
|
158
|
+
this.messageTokens.set(info.id, (Number(t.input) || 0) + (Number(t.output) || 0) + (Number(t.reasoning) || 0));
|
|
159
|
+
if (info.sessionID === this.sessionID) {
|
|
160
|
+
this.assistantMessages.add(info.id);
|
|
161
|
+
if (this.turn)
|
|
162
|
+
this.turn.sawAssistant = true;
|
|
163
|
+
}
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
case "message.part.updated": {
|
|
167
|
+
const part = obj(p.part);
|
|
168
|
+
if (!this.family.has(part.sessionID))
|
|
169
|
+
return;
|
|
170
|
+
if (part.type === "tool")
|
|
171
|
+
this.onToolPart(part);
|
|
172
|
+
else if (part.type === "text" && part.sessionID === this.sessionID && this.turn && typeof part.text === "string") {
|
|
173
|
+
this.turn.texts.set(part.id, { messageID: part.messageID, text: part.text });
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
case "permission.asked":
|
|
178
|
+
case "permission.updated": {
|
|
179
|
+
// Older servers put the request in `properties`, newer ones may nest it.
|
|
180
|
+
const perm = p.id ? p : obj(p.permission);
|
|
181
|
+
if (perm.id && this.family.has(perm.sessionID))
|
|
182
|
+
this.onPermission(perm);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
case "session.idle":
|
|
186
|
+
// An idle with no assistant message yet is left over from before the prompt.
|
|
187
|
+
if (p.sessionID === this.sessionID && this.turn?.sawAssistant)
|
|
188
|
+
this.finish();
|
|
189
|
+
return;
|
|
190
|
+
case "session.error": {
|
|
191
|
+
// A subagent's error comes back to the executor as a failed task call.
|
|
192
|
+
if (p.sessionID && p.sessionID !== this.sessionID)
|
|
193
|
+
return;
|
|
194
|
+
if (!this.turn)
|
|
195
|
+
return;
|
|
196
|
+
if (this.aborted)
|
|
197
|
+
return this.fail(new Error("aborted"));
|
|
198
|
+
const msg = errorMessage(p.error);
|
|
199
|
+
if (isRateLimit(msg)) {
|
|
200
|
+
// Route around this model for a while; the driver picks a neighbour next round.
|
|
201
|
+
this.capped.set(this.turn.model, Date.now() + RATE_LIMIT_COOLDOWN_MS);
|
|
202
|
+
return this.finish({ madeProgress: true, stuck: false, done: false });
|
|
203
|
+
}
|
|
204
|
+
return this.fail(new Error(msg));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
onToolPart(part) {
|
|
209
|
+
const st = obj(part.state);
|
|
210
|
+
if (part.callID && st.input && typeof st.input === "object")
|
|
211
|
+
this.toolInputs.set(part.callID, st.input);
|
|
212
|
+
if (st.status !== "completed" && st.status !== "error")
|
|
213
|
+
return;
|
|
214
|
+
if (part.sessionID !== this.sessionID || !this.turn)
|
|
215
|
+
return;
|
|
216
|
+
this.turn.toolsCompleted.add(part.callID);
|
|
217
|
+
// The verifier's reply is the output of the executor's `task` call to it.
|
|
218
|
+
if (part.tool !== "task" || st.status !== "completed" || this.verified.has(part.callID))
|
|
219
|
+
return;
|
|
220
|
+
const input = obj(st.input);
|
|
221
|
+
if ((input.subagent_type ?? input.agent) !== VERIFY_AGENT || typeof st.output !== "string")
|
|
222
|
+
return;
|
|
223
|
+
this.verified.add(part.callID);
|
|
224
|
+
this.turn.findings.push(...parseVerifierFindings(st.output, this.env));
|
|
225
|
+
}
|
|
226
|
+
onPermission(perm) {
|
|
227
|
+
if (this.handledPermissions.has(perm.id))
|
|
228
|
+
return;
|
|
229
|
+
this.handledPermissions.add(perm.id);
|
|
230
|
+
const tool = String(perm.permission ?? perm.type ?? "").toLowerCase();
|
|
231
|
+
// The exact command: from the request if it carries one, else from the tool
|
|
232
|
+
// call it belongs to. Never from `patterns` (a glob is not what runs).
|
|
233
|
+
const callID = obj(perm.tool).callID ?? perm.callID;
|
|
234
|
+
const fromCall = callID ? this.toolInputs.get(callID)?.command : undefined;
|
|
235
|
+
const command = extractReconCommand(perm) ?? (typeof fromCall === "string" && fromCall.trim() ? fromCall : undefined);
|
|
236
|
+
// No turn (a stray permission after a stop) fails closed: the person decides.
|
|
237
|
+
const decision = this.turn ? this.turn.gate({ tool, command }) : "ask";
|
|
238
|
+
this.onGate({ session: perm.sessionID, tool, command, decision });
|
|
239
|
+
if (decision === "ask") {
|
|
240
|
+
this.gateCounts.asked += 1;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (decision === "allow")
|
|
244
|
+
this.gateCounts.allowed += 1;
|
|
245
|
+
else
|
|
246
|
+
this.gateCounts.denied += 1;
|
|
247
|
+
this.backend.replyPermission(perm.sessionID, perm.id, decision === "allow" ? "once" : "reject").catch(() => {
|
|
248
|
+
// Could not answer it: it stays pending, and the person at the UI decides.
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const runs = new Map();
|
|
253
|
+
function snapshot(run) {
|
|
254
|
+
const { state, runner } = run;
|
|
255
|
+
if (state.status === "running") {
|
|
256
|
+
state.rounds = runner.rounds;
|
|
257
|
+
state.tokens = runner.tokens;
|
|
258
|
+
state.model = runner.model;
|
|
259
|
+
state.gate = { ...runner.gateCounts };
|
|
260
|
+
}
|
|
261
|
+
return state;
|
|
262
|
+
}
|
|
263
|
+
/** The run started on this session, if any (running or finished). */
|
|
264
|
+
export function reconState(sessionID) {
|
|
265
|
+
const run = runs.get(sessionID);
|
|
266
|
+
return run ? snapshot(run) : null;
|
|
267
|
+
}
|
|
268
|
+
/** Is `sessionID` (a root or subagent session) part of a recon run that is still going? */
|
|
269
|
+
export function inRunningRecon(sessionID) {
|
|
270
|
+
for (const run of runs.values())
|
|
271
|
+
if (run.state.status === "running" && run.runner.owns(sessionID))
|
|
272
|
+
return true;
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
/** Validate and normalise what the browser sent for the environment. */
|
|
276
|
+
export function parseEnvFidelity(raw) {
|
|
277
|
+
const r = obj(raw);
|
|
278
|
+
const kind = r.kind === "staging" || r.kind === "production" ? r.kind : r.kind === "local" ? "local" : undefined;
|
|
279
|
+
if (!kind)
|
|
280
|
+
throw httpError(400, "env.kind must be local, staging or production");
|
|
281
|
+
const divergences = typeof r.divergences === "string" ? r.divergences.trim().slice(0, 2000) : "";
|
|
282
|
+
if (!divergences)
|
|
283
|
+
throw httpError(400, "env.divergences is required: say how this instance differs from production (or that it does not)");
|
|
284
|
+
const nonProdSettings = Array.isArray(r.nonProdSettings)
|
|
285
|
+
? r.nonProdSettings.filter((s) => typeof s === "string" && Boolean(s.trim())).map((s) => s.trim().slice(0, 200)).slice(0, 50)
|
|
286
|
+
: [];
|
|
287
|
+
return nonProdSettings.length ? { kind, divergences, nonProdSettings } : { kind, divergences };
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Start a supervised recon run on a session and return its state. The loop runs
|
|
291
|
+
* in the background; poll `reconState`. Throws 400 on bad input and 409 when the
|
|
292
|
+
* session already has a run going.
|
|
293
|
+
*/
|
|
294
|
+
export async function startRecon(o) {
|
|
295
|
+
const scope = o.scope.trim();
|
|
296
|
+
const objective = o.objective.trim();
|
|
297
|
+
if (!originOf(scope).host)
|
|
298
|
+
throw httpError(400, "scope must be one host or URL, e.g. https://staging.example.com");
|
|
299
|
+
if (!objective)
|
|
300
|
+
throw httpError(400, "objective is required");
|
|
301
|
+
if (runs.get(o.sessionID)?.state.status === "running")
|
|
302
|
+
throw httpError(409, "A recon run is already going on this session.");
|
|
303
|
+
const harness = resolveHarness(o.harness);
|
|
304
|
+
const runner = new OpencodeReconRunner(o.backend, o.sessionID, o.env.kind, (r) => o.log?.("recon.gate", { ...r, root: o.sessionID }));
|
|
305
|
+
const state = {
|
|
306
|
+
sessionID: o.sessionID, scope, objective, env: o.env, profile: activeProfileName(),
|
|
307
|
+
status: "running", rounds: 0, maxRounds: harness.maxRounds, tokens: 0, budgetTokens: harness.budgetTokens,
|
|
308
|
+
gate: { allowed: 0, asked: 0, denied: 0 }, findings: [], startedAt: Date.now(),
|
|
309
|
+
};
|
|
310
|
+
const run = { state, runner };
|
|
311
|
+
await runner.start(); // subscribed before the first prompt, so no event is missed
|
|
312
|
+
runs.set(o.sessionID, run);
|
|
313
|
+
o.log?.("recon.started", { session: o.sessionID, scope, objective, env: o.env, profile: state.profile, maxRounds: state.maxRounds, budgetTokens: state.budgetTokens });
|
|
314
|
+
let lastError;
|
|
315
|
+
const seam = {
|
|
316
|
+
async runTurn(args) {
|
|
317
|
+
try {
|
|
318
|
+
const res = await runner.runTurn(args);
|
|
319
|
+
state.findings.push(...res.findings.filter((f) => f.verdict !== "rejected"));
|
|
320
|
+
return res;
|
|
321
|
+
}
|
|
322
|
+
catch (e) {
|
|
323
|
+
lastError = String(e?.message ?? e);
|
|
324
|
+
throw e;
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
void driveRecon({ objective, scope, env: o.env, runner: seam, harness, rateLimited: () => runner.rateLimited() })
|
|
329
|
+
.then((result) => {
|
|
330
|
+
snapshot(run); // last live numbers before the status flips
|
|
331
|
+
state.status = "finished";
|
|
332
|
+
state.stopped = runner.wasAborted ? "aborted" : result.stopped;
|
|
333
|
+
state.findings = result.findings;
|
|
334
|
+
state.rounds = result.rounds;
|
|
335
|
+
if (state.stopped === "error")
|
|
336
|
+
state.error = lastError;
|
|
337
|
+
state.finishedAt = Date.now();
|
|
338
|
+
runner.close();
|
|
339
|
+
o.log?.("recon.finished", {
|
|
340
|
+
session: o.sessionID, stopped: state.stopped, rounds: state.rounds, tokens: state.tokens,
|
|
341
|
+
gate: state.gate, findings: state.findings, error: state.error,
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
return snapshot(run);
|
|
345
|
+
}
|
|
346
|
+
/** Stop the run on this session. Returns its state, or null when there is none. */
|
|
347
|
+
export async function stopRecon(sessionID) {
|
|
348
|
+
const run = runs.get(sessionID);
|
|
349
|
+
if (!run)
|
|
350
|
+
return null;
|
|
351
|
+
if (run.state.status === "running")
|
|
352
|
+
await run.runner.stop();
|
|
353
|
+
return snapshot(run);
|
|
354
|
+
}
|
|
355
|
+
//# sourceMappingURL=recon-run.js.map
|
package/server/dist/recon.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* a rate-limited model to a healthy neighbour. `EnvFidelity` tags every finding
|
|
12
12
|
* with the environment it was seen in.
|
|
13
13
|
*
|
|
14
|
-
* SECURITY — the approval gate
|
|
14
|
+
* SECURITY — the approval gate (supervision, not the boundary: see docs/recon-security.md). Two
|
|
15
15
|
* Mythos reviews showed that trying to CLASSIFY arbitrary shell is fail-open:
|
|
16
16
|
* the shell re-parses the string (chaining, substitution, redirection, globbing,
|
|
17
17
|
* $VAR expansion), so predicting what it will run is a losing game. So the gate
|
|
@@ -105,8 +105,18 @@ export function loadProfiles() {
|
|
|
105
105
|
catch { /* no file / bad json -> built-ins only */ }
|
|
106
106
|
return merged;
|
|
107
107
|
}
|
|
108
|
+
/** The profile used when RECON_PROFILE is unset and no Anthropic key is configured. */
|
|
109
|
+
export const OPEN_PROFILE = "recon-open";
|
|
110
|
+
let anthropicAvailable = true;
|
|
111
|
+
/**
|
|
112
|
+
* Tell the router whether Claude can be called at all. Without an Anthropic key
|
|
113
|
+
* the default profile (which puts triage/verify/escalate on Claude) cannot run,
|
|
114
|
+
* so the default becomes the open-weight profile. An explicit RECON_PROFILE or a
|
|
115
|
+
* per-role RECON_*_MODEL still wins: the operator asked for it.
|
|
116
|
+
*/
|
|
117
|
+
export function setAnthropicAvailable(available) { anthropicAvailable = available; }
|
|
108
118
|
export function activeProfileName() {
|
|
109
|
-
return (process.env.RECON_PROFILE || "").trim() || DEFAULT_PROFILE;
|
|
119
|
+
return (process.env.RECON_PROFILE || "").trim() || (anthropicAvailable ? DEFAULT_PROFILE : OPEN_PROFILE);
|
|
110
120
|
}
|
|
111
121
|
export function activeProfile() {
|
|
112
122
|
const profiles = loadProfiles();
|
|
@@ -136,7 +146,8 @@ function capped(model, s) {
|
|
|
136
146
|
const provider = model.split("/")[0];
|
|
137
147
|
return Boolean(s.rateLimited?.[model] || s.rateLimited?.[provider]);
|
|
138
148
|
}
|
|
139
|
-
|
|
149
|
+
/** The four role models, cheapest role first (executor, triage, verify, escalate). */
|
|
150
|
+
export function tierOrder() {
|
|
140
151
|
return [modelFor("executor"), modelFor("triage"), modelFor("verify"), modelFor("escalate")];
|
|
141
152
|
}
|
|
142
153
|
function cheapestHealthy(s) {
|
|
@@ -603,26 +614,36 @@ export function withScrubbedEnv(fn) {
|
|
|
603
614
|
process.env[k] = v;
|
|
604
615
|
}
|
|
605
616
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
*
|
|
609
|
-
|
|
610
|
-
|
|
617
|
+
/**
|
|
618
|
+
* Permission rules, not the older `tools` map: OpenCode turns `tools: { bash: true }`
|
|
619
|
+
* into a trailing `bash: allow` rule that outranks the global `bash: ask`, so the
|
|
620
|
+
* executor's shell would run with no approval and the gate would never be asked.
|
|
621
|
+
*
|
|
622
|
+
* Reviewer roles are read-only, and nothing in a recon run may reach out through
|
|
623
|
+
* webfetch or websearch: they read untrusted target output.
|
|
624
|
+
*/
|
|
625
|
+
const READ_ONLY = { bash: "deny", edit: "deny", task: "deny", webfetch: "deny", websearch: "deny" };
|
|
626
|
+
/** The executor: every shell command asks (the gate answers), file edits only in a "full" harness. */
|
|
627
|
+
function executorPermission() {
|
|
611
628
|
const full = harnessFor("executor").tools === "full";
|
|
612
|
-
return { bash:
|
|
629
|
+
return { bash: "ask", edit: full ? "ask" : "deny", task: "allow", webfetch: "deny", websearch: "deny" };
|
|
613
630
|
}
|
|
614
|
-
function subagent(model, description, prompt,
|
|
615
|
-
return { model, mode
|
|
631
|
+
function subagent(model, description, prompt, permission, mode = "subagent") {
|
|
632
|
+
return { model, mode, description, prompt, permission };
|
|
616
633
|
}
|
|
634
|
+
/** The line the executor ends every turn with; the driver reads it (parseTurnStatus). */
|
|
635
|
+
export const STATUS_LINE = "RECON-STATUS";
|
|
636
|
+
const STATUS_RULE = `End every turn with exactly one final line: "${STATUS_LINE}: continue" (there is more in-scope surface to test), "${STATUS_LINE}: stuck" (the current thread is blocked and you need help), or "${STATUS_LINE}: done" (the in-scope surface is exhausted).`;
|
|
617
637
|
/**
|
|
618
|
-
* The recon
|
|
619
|
-
* `routeModel` re-resolves live for escalation/shedding.
|
|
620
|
-
* after a profile change.
|
|
638
|
+
* The recon agents for OpenCode's config, resolved when called (the profile and
|
|
639
|
+
* env at that moment); `routeModel` re-resolves live for escalation/shedding.
|
|
640
|
+
* Restart to re-register after a profile change. The executor is mode "all": the
|
|
641
|
+
* driver prompts it directly, and it stays callable as a subagent.
|
|
621
642
|
*/
|
|
622
|
-
export const
|
|
623
|
-
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.",
|
|
624
|
-
"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.",
|
|
625
|
-
"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: {verdict: real|config-dependent|rejected, severity, standard_id, repro, prod_caveat}.",
|
|
626
|
-
"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.",
|
|
627
|
-
};
|
|
643
|
+
export const reconAgents = () => ({
|
|
644
|
+
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
|
+
"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),
|
|
647
|
+
"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
|
+
});
|
|
628
649
|
//# sourceMappingURL=recon.js.map
|