bugxhunter 0.8.0 → 0.8.2
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 +31 -2
- package/bin/bugxhunter.mjs +5 -5
- package/package.json +2 -1
- package/server/dist/attachments.js +6 -3
- package/server/dist/audit.js +7 -2
- package/server/dist/auth.js +3 -0
- package/server/dist/github.js +9 -7
- package/server/dist/index.js +21 -8
- package/server/dist/opencode.js +29 -0
- package/server/dist/providers.js +34 -5
- package/server/dist/ratelimit.js +26 -0
- package/web/dist/assets/{index-BYyFGDCI.js → index-Crcy3YbK.js} +11 -11
- package/web/dist/assets/{index-DvIQFEpS.css → index-D-MACAHb.css} +1 -1
- package/web/dist/index.html +2 -2
package/README.md
CHANGED
|
@@ -151,7 +151,10 @@ agent can call a model. **Ctrl+Shift+L** locks it at once. The crypto is symmetr
|
|
|
151
151
|
see [SECURITY.md](SECURITY.md#the-key-vault).
|
|
152
152
|
|
|
153
153
|
While the vault is locked, model calls fail with a clear "vault is sealed" message. Without a vault
|
|
154
|
-
the app falls back to `SCX_API` in `.env` or
|
|
154
|
+
the app takes the key from a key file (`SCX_API_FILE`), else falls back to `SCX_API` in `.env` or
|
|
155
|
+
OpenCode's `auth.json`, in the clear. A key file is for a runner nobody unlocks, such as one behind
|
|
156
|
+
Sigilant: mount it as a secret; it is re-read on every call, so replacing it rotates the key, and if
|
|
157
|
+
it cannot be read the call fails rather than falling back to a key in the clear.
|
|
155
158
|
|
|
156
159
|
**Sign-in is the same passkey.** Once a vault exists the API needs a session, and the ways in are
|
|
157
160
|
a WebAuthn assertion with one of the vault's passkeys (verified server-side), the backup
|
|
@@ -236,6 +239,28 @@ before scanning and to scan only hosts you name.
|
|
|
236
239
|
To fence the agent to a specific lab/target range, add firewall rules on the Docker host or the VM
|
|
237
240
|
you run this in — Docker's bridge NAT doesn't restrict outbound on its own.
|
|
238
241
|
|
|
242
|
+
## Through Sigilant (governed runs)
|
|
243
|
+
|
|
244
|
+
`sigilant/` is the runner's side of running under [Sigilant](https://github.com/cintelis/sigilant): the runner is a
|
|
245
|
+
registered agent there, every call it makes is decided by a gateway against the scope the customer signed, risky ones
|
|
246
|
+
wait for a person, and each is written to a signed audit chain. Two processes, one image (`sigilant/Dockerfile`):
|
|
247
|
+
|
|
248
|
+
| | |
|
|
249
|
+
|---|---|
|
|
250
|
+
| `serve-tools.ts` | the tools a gateway forwards to: `repo.read`, `repo.comment`, `repo.block`, `repo.alerts` (GitHub's own Dependabot, code scanning and secret scanning alerts, read through the app), `target.request`, `finding.record`, `retest.summary` (what a retest came to, once, at its end), and for discovery `repo.scan`, `net.discover`, `discovery.report`; `run.usage`, which the runner's own process reports each step's usage with; GitHub with the engagement's token (`GITHUB_TOKEN_FILE`) |
|
|
251
|
+
| `github-app.ts` | the runner on GitHub as a GitHub App: a JWT signed with the app's key, exchanged for an installation token and renewed before it runs out, so that comments and reviews carry the app's name and logo (GitHub requires RS256 for the JWT; that RSA is GitHub's, confined to this file) |
|
|
252
|
+
| `usage.ts` | follows a run on the runner and reports each step — tokens, cost, time, tool calls — through the gateway as it completes; `run.ts` and the webhook do this for every run they start |
|
|
253
|
+
| `serve-bridge.ts` | an MCP server the agent is pointed at (`mcp.sigilant` in OpenCode's config), which holds the runner's identity and puts every call through the gateway |
|
|
254
|
+
| `opencode.json`, `AGENTS.md` | the agent's configuration for a governed run, merged over the image's (`OPENCODE_CONFIG`): the bridge as its one MCP server, the sandbox's own tools off, and what a denial or a held call means |
|
|
255
|
+
| `run.ts` | starts a run on the runner's API with nobody at the keyboard: `--pr owner/name#N` reviews a pull request |
|
|
256
|
+
| `serve-webhook.ts` | the webhooks: GitHub's (`/hooks/github`), where a pull request opened or updated on a repository it serves starts that review, and a deploy's (`/hooks/deploy`), where a deploy of a target it serves starts a retest of what changed; signatures checked, deliveries seen before ignored |
|
|
257
|
+
| `serve-scheduler.ts` | the timetable: a retest of each target every so often (`SCHEDULE_RETEST_EVERY`, 24h) and a discovery of the scope less often (`SCHEDULE_DISCOVER_EVERY`, 7d), each run followed and its usage reported; remembers when each last ran in the workspace, so a restart neither forgets nor starts everything again; `--now retest` or `--now discover` for one by hand |
|
|
258
|
+
| `deploy.ts` | tells the webhook a deploy has happened — the target, its version, the paths it changed — signed and named, so that CI or the host starts the retest with one command |
|
|
259
|
+
|
|
260
|
+
The package stands on its own (`cd sigilant && npm install && npm run typecheck && npm test`), with `@sigilant/sdk`
|
|
261
|
+
from a Sigilant checkout beside this one; the image takes the SDK built from an image of Sigilant's
|
|
262
|
+
(`SIGILANT_SDK_IMAGE`). Sigilant's `deploy/compose/bugxhunter.yaml` runs both beside its stack.
|
|
263
|
+
|
|
239
264
|
## Configuration (environment variables)
|
|
240
265
|
|
|
241
266
|
| Variable | Default | Purpose |
|
|
@@ -244,7 +269,9 @@ you run this in — Docker's bridge NAT doesn't restrict outbound on its own.
|
|
|
244
269
|
| `OPEN_RUNNER_DIR` | this folder | Default project folder |
|
|
245
270
|
| `OPEN_RUNNER_AGENT_PORT` | `8791` | Port for the OpenCode server |
|
|
246
271
|
| `PORT` | `8790` | Backend port |
|
|
247
|
-
| `
|
|
272
|
+
| `SCX_API_FILE` | unset | A file holding the SCX key, re-read on every call; for a runner with no one to unlock the vault. Ignored once a vault exists |
|
|
273
|
+
| `SCX_API` | the vault, else `opencode auth login` | SCX key in the clear; ignored once a vault or key file exists (prefer either) |
|
|
274
|
+
| `OPENROUTER_API_KEY_FILE` | unset | A file holding the OpenRouter key, as `SCX_API_FILE` |
|
|
248
275
|
| `OPENROUTER_API_KEY` | the vault, else unset | OpenRouter key in the clear; prefer the vault item of the same name |
|
|
249
276
|
| `OPENROUTER_MODELS` | unset | Comma list of OpenRouter model ids the agent may use; becomes an OpenCode provider through the proxy |
|
|
250
277
|
| `OPENROUTER_BASE_URL` | `https://openrouter.ai/api/v1` | OpenRouter endpoint |
|
|
@@ -275,6 +302,8 @@ GHCR images by digest) and the signed `checksums.txt` that covers them all.
|
|
|
275
302
|
<!-- releases:start -->
|
|
276
303
|
| Release | Published | Checksums | Signature | Signature check | Build |
|
|
277
304
|
| --- | --- | --- | --- | --- | --- |
|
|
305
|
+
| [v0.8.1](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.8.1) | 2026-10-09 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.1/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.1/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/37888271992) |
|
|
306
|
+
| [v0.8.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.8.0) | 2026-10-09 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/37885369502) |
|
|
278
307
|
| [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
308
|
| [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) |
|
|
280
309
|
| [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) |
|
package/bin/bugxhunter.mjs
CHANGED
|
@@ -130,11 +130,11 @@ async function dockerMode(rest) {
|
|
|
130
130
|
fs.copyFileSync(path.join(ROOT, "docker-compose.yml"), path.join(dir, "docker-compose.yml"));
|
|
131
131
|
const envFile = path.join(dir, ".env");
|
|
132
132
|
const vals = new Map();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
let envText = "";
|
|
134
|
+
try { envText = fs.readFileSync(envFile, "utf8"); } catch (e) { if (e.code !== "ENOENT") throw e; }
|
|
135
|
+
for (const line of envText.split(/\r?\n/)) {
|
|
136
|
+
const m = /^\s*([A-Z0-9_]+)=(.*)$/.exec(line);
|
|
137
|
+
if (m) vals.set(m[1], m[2]);
|
|
138
138
|
}
|
|
139
139
|
const fresh = !vals.size;
|
|
140
140
|
if (!vals.get("OPEN_RUNNER_SECRET")) vals.set("OPEN_RUNNER_SECRET", crypto.randomBytes(32).toString("base64url"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bugxhunter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
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",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@opencode-ai/sdk": "^1.17.11",
|
|
32
32
|
"dotenv": "^18.0.6",
|
|
33
33
|
"express": "^5.2.1",
|
|
34
|
+
"express-rate-limit": "^8.7.1",
|
|
34
35
|
"opencode-ai": "^1.18.35"
|
|
35
36
|
},
|
|
36
37
|
"publishConfig": {
|
|
@@ -35,7 +35,7 @@ function uniquePath(dir, name) {
|
|
|
35
35
|
return candidate;
|
|
36
36
|
}
|
|
37
37
|
export function saveAttachments(directory, files, inlineImages = true) {
|
|
38
|
-
const dir = path.
|
|
38
|
+
const dir = path.resolve(directory, "attachments");
|
|
39
39
|
fs.mkdirSync(dir, { recursive: true });
|
|
40
40
|
const parts = [];
|
|
41
41
|
const saved = [];
|
|
@@ -46,8 +46,11 @@ export function saveAttachments(directory, files, inlineImages = true) {
|
|
|
46
46
|
}
|
|
47
47
|
const name = safeName(f.name);
|
|
48
48
|
const mime = f.mime || "application/octet-stream";
|
|
49
|
-
const abs = uniquePath(dir, name);
|
|
50
|
-
|
|
49
|
+
const abs = path.resolve(uniquePath(dir, name));
|
|
50
|
+
// safeName already keeps it to a bare file name; this makes the rule explicit.
|
|
51
|
+
if (!abs.startsWith(dir + path.sep))
|
|
52
|
+
throw Object.assign(new Error(`Refusing to save ${f.name} outside attachments/`), { status: 400 });
|
|
53
|
+
fs.writeFileSync(abs, bytes, { flag: "wx" });
|
|
51
54
|
const rel = path.relative(directory, abs).split(path.sep).join("/");
|
|
52
55
|
saved.push({ name: path.basename(abs), path: rel, bytes: bytes.length, mime });
|
|
53
56
|
if (mime.startsWith("image/")) {
|
package/server/dist/audit.js
CHANGED
|
@@ -22,8 +22,13 @@ function ensureDir() {
|
|
|
22
22
|
fs.mkdirSync(LOG_DIR, { recursive: true });
|
|
23
23
|
// Keep logs out of git status / the Changes view.
|
|
24
24
|
const ignore = path.join(LOG_DIR, ".gitignore");
|
|
25
|
-
|
|
26
|
-
fs.writeFileSync(ignore, "*\n");
|
|
25
|
+
try {
|
|
26
|
+
fs.writeFileSync(ignore, "*\n", { flag: "wx" });
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
if (e.code !== "EEXIST")
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
27
32
|
ready = true;
|
|
28
33
|
}
|
|
29
34
|
catch (e) {
|
package/server/dist/auth.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import crypto from "node:crypto";
|
|
21
21
|
import * as vault from "./vault.js";
|
|
22
22
|
import { audit } from "./audit.js";
|
|
23
|
+
import { authLimiter } from "./ratelimit.js";
|
|
23
24
|
const SECRET = process.env.OPEN_RUNNER_SECRET || crypto.randomBytes(32).toString("hex");
|
|
24
25
|
const COOKIE = "or_session";
|
|
25
26
|
const MAX_AGE_S = 7 * 24 * 3600;
|
|
@@ -172,6 +173,8 @@ export function verifyAssertion(a, allowedHosts) {
|
|
|
172
173
|
}
|
|
173
174
|
// --- routes ------------------------------------------------------------------------
|
|
174
175
|
export function mountAuth(app, allowedHosts) {
|
|
176
|
+
// Sign-in is the one place worth guessing at; the recovery code is 128 bits, but no reason to allow a stream.
|
|
177
|
+
app.use("/api/auth", authLimiter);
|
|
175
178
|
app.get("/api/auth/me", (req, res) => {
|
|
176
179
|
const me = { required: authRequired(), authenticated: isAuthenticated(req) };
|
|
177
180
|
res.json(me);
|
package/server/dist/github.js
CHANGED
|
@@ -347,15 +347,17 @@ async function api(tok, route) {
|
|
|
347
347
|
}
|
|
348
348
|
throw httpError(r.status === 404 || r.status === 403 ? r.status : 502, `GitHub: ${message}`);
|
|
349
349
|
}
|
|
350
|
-
/**
|
|
351
|
-
|
|
350
|
+
/**
|
|
351
|
+
* The token's account, remembered so the status call stays cheap. One entry:
|
|
352
|
+
* there is one connection at a time, and a new token (refresh, reconnect)
|
|
353
|
+
* simply replaces it.
|
|
354
|
+
*/
|
|
355
|
+
let lastLogin = null;
|
|
352
356
|
async function whoami(tok) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (hit && Date.now() - hit.at < 10 * 60_000)
|
|
356
|
-
return hit.login;
|
|
357
|
+
if (lastLogin && lastLogin.tok === tok && Date.now() - lastLogin.at < 10 * 60_000)
|
|
358
|
+
return lastLogin.login;
|
|
357
359
|
const me = await api(tok, "/user");
|
|
358
|
-
|
|
360
|
+
lastLogin = { tok, login: me.login, at: Date.now() };
|
|
359
361
|
return me.login;
|
|
360
362
|
}
|
|
361
363
|
export async function status() {
|
package/server/dist/index.js
CHANGED
|
@@ -13,11 +13,12 @@ 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, projectFile, listAgentModels, toUiEvent, toUiMessages, parseModelId, oc, query, httpError, SessionFamily, childSessions, 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, markInterrupted, 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";
|
|
20
20
|
import * as vault from "./vault.js";
|
|
21
|
+
import { apiLimiter, fileLimiter, staticLimiter } from "./ratelimit.js";
|
|
21
22
|
import * as github from "./github.js";
|
|
22
23
|
// Keys, the proxy token and the provider clients live in providers.ts, which
|
|
23
24
|
// also scrubs every secret from the environment before OpenCode is spawned.
|
|
@@ -104,6 +105,8 @@ app.use("/api", (req, res, next) => {
|
|
|
104
105
|
// Prompts can carry attachments (base64), so allow larger bodies there.
|
|
105
106
|
app.use("/api/agent/prompt", express.json({ limit: "40mb" }));
|
|
106
107
|
app.use(express.json({ limit: "4mb" }));
|
|
108
|
+
// Rate limits before anything else under /api, sign-in included (see ratelimit.ts).
|
|
109
|
+
app.use("/api", apiLimiter);
|
|
107
110
|
mountAuth(app, ALLOWED_HOSTS);
|
|
108
111
|
// Any authenticated write counts as activity for the vault's auto-lock (reads
|
|
109
112
|
// don't, so the sidebar's status polling can't keep it open).
|
|
@@ -112,6 +115,8 @@ app.use("/api", (req, _res, next) => {
|
|
|
112
115
|
vault.touch();
|
|
113
116
|
next();
|
|
114
117
|
});
|
|
118
|
+
/** An error (or anything) as a single log line, newlines escaped. */
|
|
119
|
+
const oneLine = (e) => String(e instanceof Error ? e.stack ?? e.message : e).replace(/\r/g, "").replace(/\n/g, " | ");
|
|
115
120
|
const sendError = (res, e) => {
|
|
116
121
|
if (e instanceof SCXError) {
|
|
117
122
|
// The provider rejecting our key is a configuration problem here, not the
|
|
@@ -124,7 +129,8 @@ const sendError = (res, e) => {
|
|
|
124
129
|
const status = e?.status;
|
|
125
130
|
if (status)
|
|
126
131
|
return res.status(status).json({ error: { message: e.message } });
|
|
127
|
-
|
|
132
|
+
// One line: an error message can carry request input, and a newline in it would forge log lines.
|
|
133
|
+
console.error("[server error]", oneLine(e));
|
|
128
134
|
return res.status(500).json({ error: { message: String(e?.message ?? e) } });
|
|
129
135
|
};
|
|
130
136
|
app.get("/api/health", (_req, res) => res.json({ ok: true, baseUrl: PROVIDERS.scx.baseUrl }));
|
|
@@ -431,7 +437,7 @@ app.get("/api/agent/directory", async (req, res) => {
|
|
|
431
437
|
* Download a file the agent wrote (the UI links paths it prints). The file
|
|
432
438
|
* must be inside the project folder; see projectFile.
|
|
433
439
|
*/
|
|
434
|
-
app.get("/api/agent/file", async (req, res) => {
|
|
440
|
+
app.get("/api/agent/file", fileLimiter, async (req, res) => {
|
|
435
441
|
try {
|
|
436
442
|
const directory = await resolveDirectory(req.query.directory);
|
|
437
443
|
const file = projectFile(directory, req.query.path);
|
|
@@ -515,19 +521,24 @@ app.get("/api/agent/session/:id/messages", async (req, res) => {
|
|
|
515
521
|
// with the subagent's title, so a resumed chat shows what the live stream
|
|
516
522
|
// did. Their user messages (the delegation prompt) are skipped: the parent's
|
|
517
523
|
// task tool call already shows it.
|
|
524
|
+
// Tool calls left "running" by an idle session were cut off: shown as
|
|
525
|
+
// interrupted rather than spinning forever. /session/status lists the
|
|
526
|
+
// non-idle sessions; one it doesn't mention is idle.
|
|
527
|
+
const status = await oc(`/session/status${query({ directory })}`).catch(() => ({}));
|
|
528
|
+
const idle = (id) => (status?.[id]?.type ?? "idle") === "idle";
|
|
518
529
|
const stamped = [];
|
|
519
|
-
const stamp = (raw, subagent) => {
|
|
520
|
-
const ui = toUiMessages(raw);
|
|
530
|
+
const stamp = (raw, sessionID, subagent) => {
|
|
531
|
+
const ui = markInterrupted(toUiMessages(raw), idle(sessionID));
|
|
521
532
|
raw.forEach((m, i) => {
|
|
522
533
|
if (subagent && m?.info?.role === "user")
|
|
523
534
|
return;
|
|
524
535
|
stamped.push({ at: m?.info?.time?.created ?? 0, msg: subagent ? { ...ui[i], subagent } : ui[i] });
|
|
525
536
|
});
|
|
526
537
|
};
|
|
527
|
-
stamp(msgs);
|
|
538
|
+
stamp(msgs, req.params.id);
|
|
528
539
|
for (const child of await childSessions(directory, req.params.id)) {
|
|
529
540
|
try {
|
|
530
|
-
stamp(unwrap(await client.session.messages({ path: { id: child.id }, query: { directory } })) ?? [], child.title || "subagent");
|
|
541
|
+
stamp(unwrap(await client.session.messages({ path: { id: child.id }, query: { directory } })) ?? [], child.id, child.title || "subagent");
|
|
531
542
|
}
|
|
532
543
|
catch { /* a vanished subagent session is not worth failing the resume */ }
|
|
533
544
|
}
|
|
@@ -772,8 +783,9 @@ app.get("/api/agent/events", async (req, res) => {
|
|
|
772
783
|
// Production (Docker): serve the built web app from the same origin.
|
|
773
784
|
const WEB_DIST = path.join(REPO_ROOT, "web", "dist");
|
|
774
785
|
if (process.env.NODE_ENV === "production" && fs.existsSync(WEB_DIST)) {
|
|
786
|
+
app.use(staticLimiter);
|
|
775
787
|
app.use(express.static(WEB_DIST, { index: false }));
|
|
776
|
-
app.get(/^(?!\/api\/|\/scx\/).*/, (_req, res) => res.sendFile(path.join(WEB_DIST, "index.html")));
|
|
788
|
+
app.get(/^(?!\/api\/|\/scx\/).*/, staticLimiter, (_req, res) => res.sendFile(path.join(WEB_DIST, "index.html")));
|
|
777
789
|
}
|
|
778
790
|
// Body-parser failures (oversized attachment payloads, malformed JSON) and
|
|
779
791
|
// anything a route threw synchronously: answer in JSON like every other error.
|
|
@@ -793,6 +805,7 @@ const server = app.listen(PORT, process.env.HOST ?? "127.0.0.1", () => {
|
|
|
793
805
|
const src = keySource(p.id);
|
|
794
806
|
const where = {
|
|
795
807
|
vault: "vault",
|
|
808
|
+
file: "a key file (not in the clear in the environment)",
|
|
796
809
|
env: ".env — consider moving it into the vault",
|
|
797
810
|
"opencode-auth": "OpenCode's auth.json — consider moving it into the vault",
|
|
798
811
|
none: p.id === "scx" ? "none yet — set up the vault in the sidebar" : "not configured (optional)",
|
package/server/dist/opencode.js
CHANGED
|
@@ -33,6 +33,19 @@ export const REMOTE_URL = process.env.OPENCODE_URL?.replace(/\/$/, "");
|
|
|
33
33
|
export const WORKSPACE_ROOT = process.env.OPEN_RUNNER_WORKSPACE ?? "/workspace";
|
|
34
34
|
export const DEFAULT_DIRECTORY = process.env.OPEN_RUNNER_DIR ?? (REMOTE_URL ? WORKSPACE_ROOT : REPO_ROOT);
|
|
35
35
|
export const DEFAULT_MODEL = process.env.OPEN_RUNNER_MODEL ?? "scx/GLM-5.3";
|
|
36
|
+
/**
|
|
37
|
+
* Model for the `vision` subagent. Not every model takes images (SCX's GLM-5.3
|
|
38
|
+
* receives an attachment as base64 text and tries to decode it by hand);
|
|
39
|
+
* the main agent delegates screenshots to this one instead.
|
|
40
|
+
*/
|
|
41
|
+
export const VISION_MODEL = process.env.OPEN_RUNNER_VISION_MODEL ?? "scx/GLM-5.3-Flash";
|
|
42
|
+
export const VISION_AGENT = {
|
|
43
|
+
model: VISION_MODEL,
|
|
44
|
+
mode: "subagent",
|
|
45
|
+
description: "Looks at screenshots and other images and reports exactly what they show. Use when the current model cannot view images: give it the file path(s) and what to look for.",
|
|
46
|
+
prompt: "You look at images for another agent that cannot. Read the image file(s) you are given (screenshots, diagrams, photos) with the read tool and report precisely what they show: visible text verbatim, layout, UI elements and their labels/placement, error messages, colours where they matter. Do not speculate beyond what is visible. Do not run commands or edit files.",
|
|
47
|
+
tools: { bash: false, edit: false, write: false, task: false },
|
|
48
|
+
};
|
|
36
49
|
/**
|
|
37
50
|
* Config layered on the user's own OpenCode setup. With OPENROUTER_MODELS set,
|
|
38
51
|
* it adds an `openrouter` provider that calls back through this server's
|
|
@@ -45,6 +58,7 @@ async function inlineConfig() {
|
|
|
45
58
|
agent: {
|
|
46
59
|
build: { model: DEFAULT_MODEL },
|
|
47
60
|
plan: { model: DEFAULT_MODEL },
|
|
61
|
+
vision: VISION_AGENT,
|
|
48
62
|
},
|
|
49
63
|
permission: { edit: "ask", bash: "ask" },
|
|
50
64
|
...(openrouter ? { provider: { openrouter } } : {}),
|
|
@@ -511,10 +525,25 @@ export function toUiMessages(raw) {
|
|
|
511
525
|
tokens: info.tokens,
|
|
512
526
|
cost: info.cost,
|
|
513
527
|
model: info.modelID ? `${info.providerID}/${info.modelID}` : undefined,
|
|
528
|
+
time: info.time ? { created: info.time.created, completed: info.time.completed } : undefined,
|
|
514
529
|
error: info.error ? errorText(info.error) : undefined,
|
|
515
530
|
};
|
|
516
531
|
});
|
|
517
532
|
}
|
|
533
|
+
/**
|
|
534
|
+
* A tool call still "running" in a session that is idle was cut off (the turn
|
|
535
|
+
* was aborted, or OpenCode restarted mid-call): nothing will ever complete it,
|
|
536
|
+
* and the browser would spin on it forever. Mark such calls interrupted. A
|
|
537
|
+
* busy session's messages are returned unchanged.
|
|
538
|
+
*/
|
|
539
|
+
export function markInterrupted(messages, idle) {
|
|
540
|
+
if (!idle)
|
|
541
|
+
return messages;
|
|
542
|
+
return messages.map((m) => ({
|
|
543
|
+
...m,
|
|
544
|
+
parts: m.parts.map((p) => p.type === "tool" && (p.status === "running" || p.status === "pending") ? { ...p, status: "interrupted" } : p),
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
518
547
|
/** Pull a readable message out of an OpenCode error payload. */
|
|
519
548
|
function errorText(err) {
|
|
520
549
|
const msg = err?.data?.message ?? err?.message ?? err?.name;
|
package/server/dist/providers.js
CHANGED
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
* its catalogue (https://openrouter.ai/models). Both speak the OpenAI API, so
|
|
4
4
|
* one client class and one key-injecting proxy serve both.
|
|
5
5
|
*
|
|
6
|
-
* Keys: the vault item (SCX_API, OPENROUTER_API_KEY) first, then
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Keys: the vault item (SCX_API, OPENROUTER_API_KEY) first, then a key file
|
|
7
|
+
* (SCX_API_FILE, OPENROUTER_API_KEY_FILE), then .env, then OpenCode's own auth
|
|
8
|
+
* store. A key file is for a runner nobody is at the keyboard of, where the
|
|
9
|
+
* vault cannot be unlocked: a mounted secret, re-read on every call so that
|
|
10
|
+
* replacing the file rotates the key without a restart. Keys in the
|
|
11
|
+
* environment are read once here and scrubbed from it, and so are the key
|
|
12
|
+
* files' paths: the OpenCode server is spawned with a copy of our environment,
|
|
9
13
|
* and the agent's shell inherits that.
|
|
10
14
|
*
|
|
11
15
|
* In the Playground, OpenRouter models are addressed as `openrouter/<id>`.
|
|
@@ -23,11 +27,11 @@ import * as vault from "./vault.js";
|
|
|
23
27
|
export const PROVIDERS = {
|
|
24
28
|
scx: {
|
|
25
29
|
id: "scx", name: "SCX.ai", baseUrl: process.env.SCX_BASE_URL ?? "https://api.scx.ai/v1",
|
|
26
|
-
vaultItem: "SCX_API", envVars: ["SCX_API", "SCX_API_KEY"], authId: "scx",
|
|
30
|
+
vaultItem: "SCX_API", envVars: ["SCX_API", "SCX_API_KEY"], fileVar: "SCX_API_FILE", authId: "scx",
|
|
27
31
|
},
|
|
28
32
|
openrouter: {
|
|
29
33
|
id: "openrouter", name: "OpenRouter", baseUrl: process.env.OPENROUTER_BASE_URL ?? "https://openrouter.ai/api/v1",
|
|
30
|
-
vaultItem: "OPENROUTER_API_KEY", envVars: ["OPENROUTER_API_KEY"], authId: "openrouter",
|
|
34
|
+
vaultItem: "OPENROUTER_API_KEY", envVars: ["OPENROUTER_API_KEY"], fileVar: "OPENROUTER_API_KEY_FILE", authId: "openrouter",
|
|
31
35
|
// Attribution headers OpenRouter asks apps to send.
|
|
32
36
|
headers: { "HTTP-Referer": "https://bugxhunter.com", "X-Title": "BugXHunter" },
|
|
33
37
|
},
|
|
@@ -52,6 +56,7 @@ function readAuthStore() {
|
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
const envKeys = {};
|
|
59
|
+
const keyFiles = {};
|
|
55
60
|
const authKeys = readAuthStore();
|
|
56
61
|
for (const p of Object.values(PROVIDERS)) {
|
|
57
62
|
for (const v of p.envVars)
|
|
@@ -61,6 +66,21 @@ for (const p of Object.values(PROVIDERS)) {
|
|
|
61
66
|
}
|
|
62
67
|
for (const v of p.envVars)
|
|
63
68
|
delete process.env[v];
|
|
69
|
+
if (process.env[p.fileVar]?.trim())
|
|
70
|
+
keyFiles[p.id] = process.env[p.fileVar].trim();
|
|
71
|
+
delete process.env[p.fileVar];
|
|
72
|
+
}
|
|
73
|
+
/** The key in a provider's key file, read now; undefined if it has none, or it is empty. */
|
|
74
|
+
function fileKey(id) {
|
|
75
|
+
const file = keyFiles[id];
|
|
76
|
+
if (!file)
|
|
77
|
+
return undefined;
|
|
78
|
+
try {
|
|
79
|
+
return fs.readFileSync(file, "utf8").trim() || undefined;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
64
84
|
}
|
|
65
85
|
for (const k of ["SCX_PROXY_TOKEN", "OPEN_RUNNER_SECRET"])
|
|
66
86
|
delete process.env[k];
|
|
@@ -69,6 +89,8 @@ export function keySource(id) {
|
|
|
69
89
|
const p = PROVIDERS[id];
|
|
70
90
|
if (vault.isInitialised() && vault.status("none").items.includes(p.vaultItem))
|
|
71
91
|
return "vault";
|
|
92
|
+
if (keyFiles[id])
|
|
93
|
+
return "file";
|
|
72
94
|
if (envKeys[id])
|
|
73
95
|
return "env";
|
|
74
96
|
if (authKeys[p.authId])
|
|
@@ -81,6 +103,13 @@ export function apiKey(id) {
|
|
|
81
103
|
const p = PROVIDERS[id];
|
|
82
104
|
switch (keySource(id)) {
|
|
83
105
|
case "vault": return vault.getItem(p.vaultItem); // throws 503 while sealed
|
|
106
|
+
case "file": {
|
|
107
|
+
const key = fileKey(id);
|
|
108
|
+
// A key file named and then not readable is a fault, never a reason to fall back to a key in the clear.
|
|
109
|
+
if (!key)
|
|
110
|
+
throw httpError(503, `The ${p.name} key file ${p.fileVar} names cannot be read, or is empty.`);
|
|
111
|
+
return key;
|
|
112
|
+
}
|
|
84
113
|
case "env": return envKeys[id];
|
|
85
114
|
case "opencode-auth": return authKeys[p.authId];
|
|
86
115
|
default:
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request rate limits, per client IP, per minute.
|
|
3
|
+
*
|
|
4
|
+
* The runner is single-user and localhost-only by default, so these are not
|
|
5
|
+
* about load: they cap what a script on the same machine (or a page that got
|
|
6
|
+
* past the Host check) can do in a burst, and they make the sign-in routes
|
|
7
|
+
* useless for guessing. The general limit sits well above what the UI itself
|
|
8
|
+
* sends (status polls, session lists, one SSE stream).
|
|
9
|
+
*/
|
|
10
|
+
import { rateLimit } from "express-rate-limit";
|
|
11
|
+
const limiter = (limit, what) => rateLimit({
|
|
12
|
+
windowMs: 60_000,
|
|
13
|
+
limit,
|
|
14
|
+
standardHeaders: "draft-7",
|
|
15
|
+
legacyHeaders: false,
|
|
16
|
+
message: { error: { message: `Too many ${what} requests; try again in a minute.`, code: "rate_limited" } },
|
|
17
|
+
});
|
|
18
|
+
/** Everything under /api. */
|
|
19
|
+
export const apiLimiter = limiter(1200, "API");
|
|
20
|
+
/** Sign-in: challenge, passkey assertion, recovery. */
|
|
21
|
+
export const authLimiter = limiter(30, "sign-in");
|
|
22
|
+
/** File downloads from the project folder. */
|
|
23
|
+
export const fileLimiter = limiter(120, "download");
|
|
24
|
+
/** The built web app (production). */
|
|
25
|
+
export const staticLimiter = limiter(1200, "page");
|
|
26
|
+
//# sourceMappingURL=ratelimit.js.map
|