bugxhunter 0.6.0 → 0.8.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/.env.example +1 -1
- package/README.md +15 -3
- package/bin/bugxhunter.mjs +15 -0
- package/package.json +3 -3
- package/server/dist/auth.js +1 -1
- package/server/dist/index.js +54 -16
- package/server/dist/opencode.js +105 -0
- package/server/dist/providers.js +1 -1
- package/web/dist/assets/index-BYyFGDCI.js +127 -0
- package/web/dist/assets/index-DvIQFEpS.css +1 -0
- package/web/dist/index.html +2 -2
- package/bugxhunter-0.6.0.tgz +0 -0
- package/web/dist/assets/index-CqhtWJfv.css +0 -1
- package/web/dist/assets/index-DFfqRBl8.js +0 -118
package/.env.example
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
# OPENROUTER_API_KEY=sk-or-...
|
|
13
13
|
# Comma list of OpenRouter model ids the AGENT may use (they appear in the
|
|
14
14
|
# Runner's model picker). The Playground sees the whole catalogue regardless.
|
|
15
|
-
# OPENROUTER_MODELS=anthropic/claude-sonnet-4.5,openai/gpt-
|
|
15
|
+
# OPENROUTER_MODELS=anthropic/claude-sonnet-4.5,openai/gpt-6.1-sol
|
|
16
16
|
|
|
17
17
|
# GitHub needs nothing here: "Connect GitHub" in the sidebar signs in to the
|
|
18
18
|
# public BugXHunter GitHub App (read-only). A fork that registers its own app
|
package/README.md
CHANGED
|
@@ -44,8 +44,8 @@ npx bugxhunter docker # the sandboxed stack instead (needs Docker Desktop):
|
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
`npm i -g bugxhunter` makes it a plain `bugxhunter` command; `bugxhunter --help` lists the
|
|
47
|
-
options (`--port`, `--dir`, `--no-open`; `docker --slim|--full`, `docker down|logs|ps
|
|
48
|
-
`vault reset`). The current
|
|
47
|
+
options (`--port`, `--dir`, `--no-open`; `docker --slim|--full`, `docker down|logs|ps`,
|
|
48
|
+
`docker export <path> [dest]`; `vault reset`). The current
|
|
49
49
|
folder becomes the default project. Then, in the sidebar: set up the [vault](#key-vault) with a
|
|
50
50
|
passkey, add your SCX.ai key as `SCX_API`, and [connect GitHub](#github-repositories-read-only).
|
|
51
51
|
The package is published by the release workflow with npm provenance: `npm audit signatures`
|
|
@@ -111,6 +111,12 @@ Two containers:
|
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
(Plain `docker compose cp` also copies in, but leaves files owned by root, so the agent can't edit them.)
|
|
114
|
+
- **Getting files out**: `/workspace` is a Docker volume, so there is no host folder to open. Any
|
|
115
|
+
file path the agent prints under the project (for example "Saved as
|
|
116
|
+
`/workspace/acme/app/analysis.md`") is a download link in the UI, served only for files inside
|
|
117
|
+
the project folder. From a terminal, `npx bugxhunter@latest docker export acme/app/analysis.md`
|
|
118
|
+
(or an absolute `/workspace/...` path; optional destination as the second argument) copies a file
|
|
119
|
+
or folder out.
|
|
114
120
|
- **The agent has direct internet** so scan tools run at full speed (`nmap`/`ping`/raw DNS work
|
|
115
121
|
via `NET_RAW`). Outbound connections are logged, not restricted — **only point the agent at targets you are authorised to test, and run this on a
|
|
116
122
|
trusted machine/VM.**
|
|
@@ -164,7 +170,7 @@ as well:
|
|
|
164
170
|
**Playground** then lists OpenRouter's models under their own heading, addressed as
|
|
165
171
|
`openrouter/<id>`.
|
|
166
172
|
2. For the **agent**, list the ids it may use in `OPENROUTER_MODELS` (comma-separated, e.g.
|
|
167
|
-
`anthropic/claude-sonnet-4.5,openai/gpt-
|
|
173
|
+
`anthropic/claude-sonnet-4.5,openai/gpt-6.1-sol`), in `.env`. Only those appear in the Runner's model
|
|
168
174
|
picker, as `openrouter/…`. In Docker, both containers read the same variable.
|
|
169
175
|
|
|
170
176
|
The agent never holds the key: its calls go to the runner's `/openrouter/v1` proxy with the proxy
|
|
@@ -209,6 +215,10 @@ labs, CTFs). Build with `--build-arg SECTOOLS=0` to leave them out.
|
|
|
209
215
|
(passive).
|
|
210
216
|
- **Secrets (local, no network):** `gitleaks` — scan copied-in repos and JS bundles for leaked keys.
|
|
211
217
|
- **Raw-socket:** `nmap`, `ping`, `traceroute`, `dig`/`host` (incl. zone transfer).
|
|
218
|
+
- **Not included — LLM red-teaming:** `promptfoo` (~1.4 GB installed) and `garak` (~2 GB with
|
|
219
|
+
CPU-only PyTorch, 5 GB+ if pip is left to pull the CUDA build) would more than double the image,
|
|
220
|
+
so the agent installs them on demand into the persistent `/workspace/.tools` volume. The recipe,
|
|
221
|
+
including pointing them at the runner's model proxy for grading, is in `docker/agent-AGENTS.md`.
|
|
212
222
|
|
|
213
223
|
All tools run directly against targets. The agent's `AGENTS.md` tells it to confirm authorisation
|
|
214
224
|
before scanning and to scan only hosts you name.
|
|
@@ -265,6 +275,8 @@ GHCR images by digest) and the signed `checksums.txt` that covers them all.
|
|
|
265
275
|
<!-- releases:start -->
|
|
266
276
|
| Release | Published | Checksums | Signature | Signature check | Build |
|
|
267
277
|
| --- | --- | --- | --- | --- | --- |
|
|
278
|
+
| [v0.7.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.7.0) | 2026-10-08 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.7.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.7.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/37718565914) |
|
|
279
|
+
| [v0.6.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.6.0) | 2026-10-08 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.6.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.6.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/37705423314) |
|
|
268
280
|
| [v0.5.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.5.0) | 2026-10-07 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.5.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.5.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/37702342512) |
|
|
269
281
|
| [v0.4.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.4.0) | 2026-10-07 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.4.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.4.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/37640130325) |
|
|
270
282
|
| [v0.3.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.3.0) | 2026-10-07 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.3.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.3.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/37636400569) |
|
package/bin/bugxhunter.mjs
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* (compose file + .env secrets), pulls the signed images
|
|
9
9
|
* matching this version, starts it, opens the UI.
|
|
10
10
|
* With args, runs `docker compose <args>` there (down, logs…).
|
|
11
|
+
* bugxhunter docker export <path> [dest] copy a file or folder out of /workspace (a Docker volume
|
|
12
|
+
* Finder cannot open) into dest, default: here
|
|
11
13
|
* bugxhunter vault reset break-glass: delete the key vault (see scripts/vault-reset.mjs)
|
|
12
14
|
*
|
|
13
15
|
* Local mode runs the agent on this machine: OpenCode is a dependency of this
|
|
@@ -42,6 +44,9 @@ if (flag("--help") || flag("-h")) {
|
|
|
42
44
|
--slim the agent image without the scan toolchain: half the download, code review only
|
|
43
45
|
--full back to the full image (the default)
|
|
44
46
|
bugxhunter docker <args> docker compose <args> in that folder, e.g. down, logs -f, ps
|
|
47
|
+
bugxhunter docker export <path> [dest]
|
|
48
|
+
copy a file or folder out of /workspace into dest (default: here);
|
|
49
|
+
<path> may be absolute (/workspace/acme/app/report.md) or relative to /workspace
|
|
45
50
|
bugxhunter vault reset delete the key vault when every unlock factor is lost
|
|
46
51
|
|
|
47
52
|
Docs: https://github.com/cintelis/bugxhunter-runner`);
|
|
@@ -143,6 +148,16 @@ async function dockerMode(rest) {
|
|
|
143
148
|
console.log(`${fresh ? "Created" : "Updated"} ${dir} (compose file + .env; secrets are random and never printed)`);
|
|
144
149
|
|
|
145
150
|
const compose = (a) => spawnSync("docker", ["compose", ...a], { cwd: dir, stdio: "inherit" }).status ?? 1;
|
|
151
|
+
if (rest[0] === "export") {
|
|
152
|
+
const src = rest[1];
|
|
153
|
+
if (!src) { console.error("usage: bugxhunter docker export <path-in-workspace> [dest]"); process.exit(2); }
|
|
154
|
+
const inside = src.startsWith("/") ? path.posix.normalize(src) : path.posix.join("/workspace", src);
|
|
155
|
+
if (!inside.startsWith("/workspace/")) { console.error("the path must be inside /workspace"); process.exit(2); }
|
|
156
|
+
const dest = path.resolve(rest[2] ?? path.posix.basename(inside));
|
|
157
|
+
const code = compose(["cp", `agent:${inside}`, dest]);
|
|
158
|
+
if (code === 0) console.log(`copied ${inside} → ${dest}`);
|
|
159
|
+
process.exit(code);
|
|
160
|
+
}
|
|
146
161
|
if (rest.length) process.exit(compose(rest));
|
|
147
162
|
console.log(`Pulling the signed images for v${pkg.version}${flavor ? " (slim agent: no scan toolchain)" : " (the agent image is large the first time; --slim halves it)"}…`);
|
|
148
163
|
if (compose(["pull"]) !== 0) process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bugxhunter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@opencode-ai/sdk": "^1.17.11",
|
|
32
|
-
"dotenv": "^
|
|
33
|
-
"express": "^
|
|
32
|
+
"dotenv": "^18.0.6",
|
|
33
|
+
"express": "^5.2.1",
|
|
34
34
|
"opencode-ai": "^1.18.35"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
package/server/dist/auth.js
CHANGED
|
@@ -221,7 +221,7 @@ export function mountAuth(app, allowedHosts) {
|
|
|
221
221
|
if (typeof req.body?.dek !== "string")
|
|
222
222
|
return res.status(400).json({ error: { message: "dek required" } });
|
|
223
223
|
try {
|
|
224
|
-
vault.unseal(req.body
|
|
224
|
+
vault.unseal(req.body?.dek); // throws 401 if it doesn't open the verifier
|
|
225
225
|
issueSession(req, res);
|
|
226
226
|
audit("auth.signin", { method: "recovery" });
|
|
227
227
|
res.json({ ok: true });
|
package/server/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import path from "node:path";
|
|
|
13
13
|
import { SCXError } from "./scx.js";
|
|
14
14
|
import { PROVIDERS, PROXY_TOKEN, PORT, OPENROUTER_MODELS, apiKey, clients, clientFor, keySource, listModels } from "./providers.js";
|
|
15
15
|
import { KnowledgeBase, buildContextBlock } from "./rag.js";
|
|
16
|
-
import { getClient, serverUrl, resolveDirectory, listAgentModels, toUiEvent, toUiMessages, parseModelId, oc, query, httpError, DEFAULT_DIRECTORY, DEFAULT_MODEL, REMOTE_URL, REPO_ROOT, ALLOWED_ROOTS, } from "./opencode.js";
|
|
16
|
+
import { getClient, serverUrl, resolveDirectory, projectFile, listAgentModels, toUiEvent, toUiMessages, parseModelId, oc, query, httpError, SessionFamily, childSessions, DEFAULT_DIRECTORY, DEFAULT_MODEL, REMOTE_URL, REPO_ROOT, ALLOWED_ROOTS, } from "./opencode.js";
|
|
17
17
|
import { mountAuth, authRequired, issueSession } from "./auth.js";
|
|
18
18
|
import { audit, followOpencode, LOG_DIR } from "./audit.js";
|
|
19
19
|
import { saveAttachments } from "./attachments.js";
|
|
@@ -43,7 +43,7 @@ if (TRUST_PROXY) {
|
|
|
43
43
|
const PROXY_PATHS = new Set(["/chat/completions", "/models"]);
|
|
44
44
|
for (const p of Object.values(PROVIDERS)) {
|
|
45
45
|
const prefix = `/${p.id}/v1`;
|
|
46
|
-
app.all(`${prefix}
|
|
46
|
+
app.all(`${prefix}/*path`, async (req, res) => {
|
|
47
47
|
const sub = req.path.slice(prefix.length);
|
|
48
48
|
const auth = req.headers.authorization ?? "";
|
|
49
49
|
if (auth !== `Bearer ${PROXY_TOKEN}`)
|
|
@@ -150,7 +150,7 @@ app.post("/api/vault/unseal", (req, res) => {
|
|
|
150
150
|
try {
|
|
151
151
|
if (typeof req.body?.dek !== "string")
|
|
152
152
|
return res.status(400).json({ error: { message: "dek required" } });
|
|
153
|
-
vault.unseal(req.body
|
|
153
|
+
vault.unseal(req.body?.dek);
|
|
154
154
|
res.json(vault.status(keySource("scx")));
|
|
155
155
|
}
|
|
156
156
|
catch (e) {
|
|
@@ -165,7 +165,7 @@ app.put("/api/vault/items/:name", (req, res) => {
|
|
|
165
165
|
try {
|
|
166
166
|
if (typeof req.body?.value !== "string")
|
|
167
167
|
return res.status(400).json({ error: { message: "value required" } });
|
|
168
|
-
vault.setItem(req.params.name, req.body
|
|
168
|
+
vault.setItem(req.params.name, req.body?.value);
|
|
169
169
|
res.json(vault.status(keySource("scx")));
|
|
170
170
|
}
|
|
171
171
|
catch (e) {
|
|
@@ -212,7 +212,7 @@ app.delete("/api/vault", (req, res) => {
|
|
|
212
212
|
try {
|
|
213
213
|
if (typeof req.body?.dek !== "string")
|
|
214
214
|
return res.status(400).json({ error: { message: "dek required" } });
|
|
215
|
-
vault.destroy(req.body
|
|
215
|
+
vault.destroy(req.body?.dek);
|
|
216
216
|
res.json(vault.status(keySource("scx")));
|
|
217
217
|
}
|
|
218
218
|
catch (e) {
|
|
@@ -427,6 +427,21 @@ app.get("/api/agent/directory", async (req, res) => {
|
|
|
427
427
|
sendError(res, e);
|
|
428
428
|
}
|
|
429
429
|
});
|
|
430
|
+
/**
|
|
431
|
+
* Download a file the agent wrote (the UI links paths it prints). The file
|
|
432
|
+
* must be inside the project folder; see projectFile.
|
|
433
|
+
*/
|
|
434
|
+
app.get("/api/agent/file", async (req, res) => {
|
|
435
|
+
try {
|
|
436
|
+
const directory = await resolveDirectory(req.query.directory);
|
|
437
|
+
const file = projectFile(directory, req.query.path);
|
|
438
|
+
audit("file.download", { directory, file });
|
|
439
|
+
res.download(file, path.basename(file));
|
|
440
|
+
}
|
|
441
|
+
catch (e) {
|
|
442
|
+
sendError(res, e);
|
|
443
|
+
}
|
|
444
|
+
});
|
|
430
445
|
/** Create a fresh agent session in a project folder. */
|
|
431
446
|
app.post("/api/agent/session", async (req, res) => {
|
|
432
447
|
try {
|
|
@@ -494,9 +509,29 @@ app.get("/api/agent/session/:id/messages", async (req, res) => {
|
|
|
494
509
|
try {
|
|
495
510
|
const directory = await resolveDirectory(req.query.directory);
|
|
496
511
|
const client = await getClient(directory);
|
|
497
|
-
const msgs = unwrap(await client.session.messages({ path: { id: req.params.id }, query: { directory } }));
|
|
512
|
+
const msgs = unwrap(await client.session.messages({ path: { id: req.params.id }, query: { directory } })) ?? [];
|
|
498
513
|
const todos = await oc(`/session/${encodeURIComponent(req.params.id)}/todo${query({ directory })}`).catch(() => []);
|
|
499
|
-
|
|
514
|
+
// Subagent sessions' messages are merged in by creation time and tagged
|
|
515
|
+
// with the subagent's title, so a resumed chat shows what the live stream
|
|
516
|
+
// did. Their user messages (the delegation prompt) are skipped: the parent's
|
|
517
|
+
// task tool call already shows it.
|
|
518
|
+
const stamped = [];
|
|
519
|
+
const stamp = (raw, subagent) => {
|
|
520
|
+
const ui = toUiMessages(raw);
|
|
521
|
+
raw.forEach((m, i) => {
|
|
522
|
+
if (subagent && m?.info?.role === "user")
|
|
523
|
+
return;
|
|
524
|
+
stamped.push({ at: m?.info?.time?.created ?? 0, msg: subagent ? { ...ui[i], subagent } : ui[i] });
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
stamp(msgs);
|
|
528
|
+
for (const child of await childSessions(directory, req.params.id)) {
|
|
529
|
+
try {
|
|
530
|
+
stamp(unwrap(await client.session.messages({ path: { id: child.id }, query: { directory } })) ?? [], child.title || "subagent");
|
|
531
|
+
}
|
|
532
|
+
catch { /* a vanished subagent session is not worth failing the resume */ }
|
|
533
|
+
}
|
|
534
|
+
const messages = stamped.sort((a, b) => a.at - b.at).map((s) => s.msg);
|
|
500
535
|
res.json({ messages, todos });
|
|
501
536
|
}
|
|
502
537
|
catch (e) {
|
|
@@ -577,13 +612,16 @@ app.get("/api/agent/pending", async (req, res) => {
|
|
|
577
612
|
try {
|
|
578
613
|
const sessionID = String(req.query.sessionID || "");
|
|
579
614
|
const directory = await resolveDirectory(req.query.directory);
|
|
615
|
+
// A subagent's prompt blocks the chat just like the root session's own.
|
|
616
|
+
const family = sessionID ? new SessionFamily(sessionID, await childSessions(directory, sessionID)) : null;
|
|
617
|
+
const inScope = (sid) => !family || family.has(sid);
|
|
580
618
|
const permsRaw = await oc(`/permission${query({ directory })}`).catch(() => []);
|
|
581
619
|
// GET /question lists every pending question request (same shape as the
|
|
582
620
|
// question.asked event); filter to this session like the permissions.
|
|
583
621
|
const qRaw = await oc(`/question${query({ directory })}`).catch(() => []);
|
|
584
622
|
const pending = {
|
|
585
623
|
permissions: permsRaw
|
|
586
|
-
.filter((p) =>
|
|
624
|
+
.filter((p) => inScope(p.sessionID))
|
|
587
625
|
.map((p) => ({
|
|
588
626
|
kind: "permission",
|
|
589
627
|
sessionID: p.sessionID,
|
|
@@ -592,15 +630,17 @@ app.get("/api/agent/pending", async (req, res) => {
|
|
|
592
630
|
title: p.metadata?.command ?? p.title,
|
|
593
631
|
pattern: p.patterns ?? p.pattern,
|
|
594
632
|
callID: p.callID,
|
|
633
|
+
subagent: family?.subagent(p.sessionID),
|
|
595
634
|
})),
|
|
596
635
|
questions: qRaw
|
|
597
|
-
.filter((q) =>
|
|
636
|
+
.filter((q) => inScope(q.sessionID))
|
|
598
637
|
.map((q) => ({
|
|
599
638
|
kind: "question",
|
|
600
639
|
sessionID: q.sessionID,
|
|
601
640
|
requestID: q.id,
|
|
602
641
|
questions: q.questions ?? [],
|
|
603
642
|
callID: q.tool?.callID,
|
|
643
|
+
subagent: family?.subagent(q.sessionID),
|
|
604
644
|
})),
|
|
605
645
|
};
|
|
606
646
|
res.json(pending);
|
|
@@ -705,16 +745,14 @@ app.get("/api/agent/events", async (req, res) => {
|
|
|
705
745
|
const sub = await client.event.subscribe({ query: { directory } });
|
|
706
746
|
let closed = false;
|
|
707
747
|
req.on("close", () => { closed = true; clearInterval(keepAlive); sub.stream.return?.(undefined); });
|
|
748
|
+
// This session's events plus its subagents' (tagged), seeded with the
|
|
749
|
+
// subagents that already exist; ones spawned later announce themselves on
|
|
750
|
+
// the stream. Without a session id everything is forwarded.
|
|
751
|
+
const family = sessionID ? new SessionFamily(sessionID, await childSessions(directory, sessionID)) : null;
|
|
708
752
|
for await (const evt of sub.stream) {
|
|
709
753
|
if (closed)
|
|
710
754
|
break;
|
|
711
|
-
|
|
712
|
-
const sid = evt?.properties?.part?.sessionID ??
|
|
713
|
-
evt?.properties?.sessionID ??
|
|
714
|
-
evt?.properties?.info?.sessionID;
|
|
715
|
-
if (sessionID && sid && sid !== sessionID)
|
|
716
|
-
continue;
|
|
717
|
-
const ui = toUiEvent(evt);
|
|
755
|
+
const ui = family ? family.relay(evt) : toUiEvent(evt);
|
|
718
756
|
if (ui)
|
|
719
757
|
res.write(`data: ${JSON.stringify(ui)}\n\n`);
|
|
720
758
|
}
|
package/server/dist/opencode.js
CHANGED
|
@@ -197,6 +197,34 @@ export async function resolveDirectory(dir) {
|
|
|
197
197
|
throw notFound(abs);
|
|
198
198
|
return abs;
|
|
199
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* A file inside a (validated) project folder, for the download route. The
|
|
202
|
+
* path may be absolute (as the agent prints it) or relative to the project;
|
|
203
|
+
* either way it must stay inside the project, after symlinks are resolved,
|
|
204
|
+
* and it must be a regular file. In Docker the runner mounts the same
|
|
205
|
+
* workspace volume at the same path, so the agent's paths are its own.
|
|
206
|
+
*/
|
|
207
|
+
export function projectFile(directory, file) {
|
|
208
|
+
const raw = typeof file === "string" ? file.trim() : "";
|
|
209
|
+
if (!raw)
|
|
210
|
+
throw httpError(400, "path required");
|
|
211
|
+
const P = REMOTE_URL ? path.posix : path;
|
|
212
|
+
const abs = P.isAbsolute(raw) ? P.normalize(raw) : P.resolve(directory, raw);
|
|
213
|
+
if (!isInside(abs, directory))
|
|
214
|
+
throw httpError(400, `Not inside the project: ${raw}`);
|
|
215
|
+
let real;
|
|
216
|
+
try {
|
|
217
|
+
real = fs.realpathSync(abs);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
throw httpError(404, `No such file: ${raw}`);
|
|
221
|
+
}
|
|
222
|
+
if (!isInside(real, fs.realpathSync(directory)))
|
|
223
|
+
throw httpError(400, `Not inside the project: ${raw}`);
|
|
224
|
+
if (!fs.statSync(real).isFile())
|
|
225
|
+
throw httpError(400, `Not a file: ${raw}`);
|
|
226
|
+
return real;
|
|
227
|
+
}
|
|
200
228
|
/** SDK client scoped to one project folder. */
|
|
201
229
|
export async function getClient(directory) {
|
|
202
230
|
const { url } = await getServer();
|
|
@@ -371,6 +399,83 @@ export function toUiEvent(evt) {
|
|
|
371
399
|
return null;
|
|
372
400
|
}
|
|
373
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* One chat's sessions: the root session plus the subagent sessions it spawns
|
|
404
|
+
* (OpenCode's task tool creates a child session per delegation, with
|
|
405
|
+
* `parentID` set). Without this the browser only ever saw the root: a
|
|
406
|
+
* subagent's output was invisible and its approval prompts went unanswered,
|
|
407
|
+
* leaving the chat "spinning" forever.
|
|
408
|
+
*/
|
|
409
|
+
export class SessionFamily {
|
|
410
|
+
rootID;
|
|
411
|
+
titles = new Map();
|
|
412
|
+
constructor(rootID, children = []) {
|
|
413
|
+
this.rootID = rootID;
|
|
414
|
+
// Parents may be listed after their children; a second pass catches grandchildren.
|
|
415
|
+
for (let i = 0; i < 2; i++)
|
|
416
|
+
for (const c of children)
|
|
417
|
+
this.add(c);
|
|
418
|
+
}
|
|
419
|
+
/** Adopt a session if its parent is in the family. Returns true when adopted. */
|
|
420
|
+
add(s) {
|
|
421
|
+
if (!s?.id || !s.parentID)
|
|
422
|
+
return false;
|
|
423
|
+
if (s.parentID !== this.rootID && !this.titles.has(s.parentID))
|
|
424
|
+
return false;
|
|
425
|
+
this.titles.set(s.id, s.title || "subagent");
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
has(sessionID) {
|
|
429
|
+
return sessionID === this.rootID || this.titles.has(sessionID);
|
|
430
|
+
}
|
|
431
|
+
/** The subagent's title, or undefined for the root session itself. */
|
|
432
|
+
subagent(sessionID) {
|
|
433
|
+
return this.titles.get(sessionID);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* What the browser gets for a raw OpenCode event: the root's events as they
|
|
437
|
+
* are, a subagent's tagged with its title, everything else dropped. A
|
|
438
|
+
* subagent's idle/error must not end the parent's turn, and its session and
|
|
439
|
+
* todo updates are not the chat's.
|
|
440
|
+
*/
|
|
441
|
+
relay(evt) {
|
|
442
|
+
const p = evt?.properties;
|
|
443
|
+
if ((evt?.type === "session.created" || evt?.type === "session.updated") && p?.info?.id)
|
|
444
|
+
this.add(p.info);
|
|
445
|
+
const ui = toUiEvent(evt);
|
|
446
|
+
if (!ui)
|
|
447
|
+
return null;
|
|
448
|
+
// Events carry the session id in different spots; some (permission.replied
|
|
449
|
+
// on older servers, question.*) carry none and pass through.
|
|
450
|
+
const sid = p?.part?.sessionID ?? p?.sessionID ?? p?.info?.sessionID ?? p?.permission?.sessionID ?? ui.sessionID;
|
|
451
|
+
if (!sid || sid === this.rootID)
|
|
452
|
+
return ui;
|
|
453
|
+
const title = this.titles.get(sid);
|
|
454
|
+
if (!title)
|
|
455
|
+
return null;
|
|
456
|
+
if (ui.kind === "idle" || ui.kind === "error" || ui.kind === "session" || ui.kind === "todo")
|
|
457
|
+
return null;
|
|
458
|
+
return { ...ui, subagent: title };
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Every subagent session under `rootID` (children, grandchildren, …), via
|
|
463
|
+
* OpenCode's children endpoint. Depth-limited; a failure yields an empty list
|
|
464
|
+
* so the chat still works without the subagent view.
|
|
465
|
+
*/
|
|
466
|
+
export async function childSessions(directory, rootID, depth = 3) {
|
|
467
|
+
if (depth <= 0)
|
|
468
|
+
return [];
|
|
469
|
+
const kids = await oc(`/session/${encodeURIComponent(rootID)}/children${query({ directory })}`).catch(() => []);
|
|
470
|
+
const out = [];
|
|
471
|
+
for (const k of kids ?? []) {
|
|
472
|
+
if (!k?.id)
|
|
473
|
+
continue;
|
|
474
|
+
out.push({ id: k.id, parentID: k.parentID ?? rootID, title: k.title });
|
|
475
|
+
out.push(...(await childSessions(directory, k.id, depth - 1)));
|
|
476
|
+
}
|
|
477
|
+
return out;
|
|
478
|
+
}
|
|
374
479
|
/**
|
|
375
480
|
* Stored messages (GET /session/:id/message) -> the same shape the browser
|
|
376
481
|
* builds from live events, so a resumed chat renders like a live one.
|
package/server/dist/providers.js
CHANGED
|
@@ -32,7 +32,7 @@ export const PROVIDERS = {
|
|
|
32
32
|
headers: { "HTTP-Referer": "https://bugxhunter.com", "X-Title": "BugXHunter" },
|
|
33
33
|
},
|
|
34
34
|
};
|
|
35
|
-
/** OpenRouter ids the agent may use (OPENROUTER_MODELS=anthropic/claude-sonnet-4.5,openai/gpt-
|
|
35
|
+
/** OpenRouter ids the agent may use (OPENROUTER_MODELS=anthropic/claude-sonnet-4.5,openai/gpt-6.1-sol). */
|
|
36
36
|
export const OPENROUTER_MODELS = (process.env.OPENROUTER_MODELS ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
37
37
|
export const PORT = Number(process.env.PORT ?? 8790);
|
|
38
38
|
/**
|