bugxhunter 0.8.7 → 0.9.1
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 +32 -5
- package/SECURITY.md +2 -3
- package/docker-compose.yml +25 -1
- package/package.json +1 -1
- package/server/dist/index.js +78 -3
- package/server/dist/nvidia-health.js +98 -0
- package/server/dist/playground-store.js +143 -0
- package/server/dist/providers.js +67 -5
- package/server/dist/render.js +78 -0
- package/server/dist/scx.js +15 -3
- package/server/dist/vault.js +20 -0
- package/web/dist/assets/index-DpbUOeo1.js +230 -0
- package/web/dist/assets/{index-D24Hwr09.css → index-gwJcczPG.css} +1 -1
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CFfhLePt.js +0 -127
package/README.md
CHANGED
|
@@ -15,8 +15,21 @@ green accents) and Fira Code throughout. Started from the `sovgov-poc` chatbot d
|
|
|
15
15
|
`plan` (read-only) agent. Every file edit and shell command waits for your approval.
|
|
16
16
|
Markdown replies, collapsible tool calls and reasoning, per-turn token counts, and a
|
|
17
17
|
**Changes** view of what the agent edited (git repos only — OpenCode tracks changes via git).
|
|
18
|
-
- **Playground** — chat with any SCX model directly (no agent), with
|
|
19
|
-
an embeddings-backed knowledge base and browser voice.
|
|
18
|
+
- **Playground** — chat with any SCX, NVIDIA or OpenRouter model directly (no agent), with
|
|
19
|
+
tool-calling, JSON mode, an embeddings-backed knowledge base and browser voice. Also:
|
|
20
|
+
- **Security presets** (code review, threat modelling, diagram review, diagram drawing,
|
|
21
|
+
phishing, log triage) and **compare mode** (2–3 models side by side, with speed and tokens).
|
|
22
|
+
- **Images** for vision models, and **draw.io files** (`.drawio`, compressed or not, and
|
|
23
|
+
`.drawio.svg`) for any model: the file becomes an exact text outline of its zones, boxes,
|
|
24
|
+
legend colours and arrows, so labels are never misread.
|
|
25
|
+
- **Diagrams in replies**: a model writes a ```` ```drawio ```` spec and the app draws it as an
|
|
26
|
+
editable `.drawio.svg` ([drawgen](https://github.com/cintelis/drawio-tools)), checks it, and
|
|
27
|
+
can send the problems back for a fix.
|
|
28
|
+
- **Threat-model canvas**: build a model from a diagram or description, track findings,
|
|
29
|
+
scope and coverage, zoom and pan, export JSON, `findings.md`, SVG or draw.io.
|
|
30
|
+
- **Saved sessions**: chats and canvases are sealed with the vault key on the runner
|
|
31
|
+
(Docker: the `runner-data` volume), never in browser storage.
|
|
32
|
+
- Retired NVIDIA models (their endpoints answer 404) are found and hidden automatically.
|
|
20
33
|
|
|
21
34
|
## Screenshots
|
|
22
35
|
|
|
@@ -92,12 +105,17 @@ the size (`npx bugxhunter docker --slim`, or `BXH_AGENT_FLAVOR=-slim` in `.env`)
|
|
|
92
105
|
key and turns on passkey sign-in. (`setup.ps1 -CopyScxKey` copies
|
|
93
106
|
the key into `.env` instead, in the clear.)
|
|
94
107
|
|
|
95
|
-
|
|
108
|
+
Three containers (plus the egress logger):
|
|
96
109
|
|
|
97
110
|
| Container | Holds | Network |
|
|
98
111
|
|---|---|---|
|
|
99
112
|
| `runner` | Web UI, login, SCX key, `/scx/v1` key proxy | shared bridge, published on 127.0.0.1 |
|
|
100
113
|
| `agent` | OpenCode, the agent's shell + scan tools, `/workspace` volume | shared bridge — **direct internet** |
|
|
114
|
+
| `render` | drawgen: model-written diagram specs → `.drawio.svg`, and `.drawio` files → outlines | internal network shared only with `runner` — **no internet** |
|
|
115
|
+
|
|
116
|
+
- Model output and uploaded diagram files are parsed in `render`, not in the `runner` that holds
|
|
117
|
+
the keys: no volumes, no secrets, read-only, non-root, 512 MB and 1 CPU, each job in its own
|
|
118
|
+
process with a 10 s limit. drawgen is installed from a release wheel pinned by SHA-256.
|
|
101
119
|
|
|
102
120
|
- The agent's model calls go to `runner`'s proxy with a proxy token; the proxy swaps in the real
|
|
103
121
|
key and only allows `/chat/completions` and `/models`. **The SCX key never enters the agent
|
|
@@ -298,6 +316,8 @@ from a Sigilant checkout beside this one; the image takes the SDK built from an
|
|
|
298
316
|
| `ALLOWED_HOSTS` | localhost only | Extra `Host` header values to accept (comma list), e.g. the domain a reverse proxy serves. Everything else gets 403, which blocks DNS-rebinding attacks |
|
|
299
317
|
| `OPEN_RUNNER_ALLOWED_ROOTS` | any folder | Local mode: folders the UI may open, PATH-style list (`;` on Windows, `:` elsewhere). Set it before sharing the app |
|
|
300
318
|
| `OPENCODE_URL` | unset (spawn locally) | Use a remote OpenCode server (Docker sets `http://agent:4096`) |
|
|
319
|
+
| `OPEN_RUNNER_RENDER_URL` | unset (diagrams off) | The render service for diagrams and `.drawio` files (Docker sets `http://render:8080`) |
|
|
320
|
+
| `OPEN_RUNNER_PLAYGROUND_DIR` | `playground/` beside the vault | Saved Playground chats and canvases, sealed with the vault key |
|
|
301
321
|
| `OPEN_RUNNER_WORKSPACE` | `/workspace` (local: `~/bugxhunter/repos`) | Remote mode: projects must live under this folder. Both modes: where GitHub clones land |
|
|
302
322
|
| `SCX_PROXY_TOKEN` | unset | Enables the `/scx/v1` key proxy for the sandboxed agent |
|
|
303
323
|
|
|
@@ -315,6 +335,8 @@ GHCR images by digest) and the signed `checksums.txt` that covers them all.
|
|
|
315
335
|
<!-- releases:start -->
|
|
316
336
|
| Release | Published | Checksums | Signature | Signature check | Build |
|
|
317
337
|
| --- | --- | --- | --- | --- | --- |
|
|
338
|
+
| [v0.9.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.9.0) | 2026-10-28 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.9.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.9.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/40700626754) |
|
|
339
|
+
| [v0.8.7](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.8.7) | 2026-10-28 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.7/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.7/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/40622263442) |
|
|
318
340
|
| [v0.8.6](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.8.6) | 2026-10-27 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.6/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.6/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/40601789047) |
|
|
319
341
|
| [v0.8.5](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.8.5) | 2026-10-21 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.5/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.5/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/39618294874) |
|
|
320
342
|
| [v0.8.4](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.8.4) | 2026-10-21 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.4/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.8.4/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/39600671629) |
|
|
@@ -350,9 +372,9 @@ npm test # vitest: the pure logic in server/src and web/src
|
|
|
350
372
|
npm run build # web -> web/dist, server -> server/dist (what the Docker image ships)
|
|
351
373
|
```
|
|
352
374
|
|
|
353
|
-
GitHub Actions: `ci.yml` runs the checks and builds
|
|
375
|
+
GitHub Actions: `ci.yml` runs the checks (including the render service's Python tests) and builds the Docker images on every push and PR,
|
|
354
376
|
`codeql.yml` scans for security issues weekly and on PRs, `docker-publish.yml` pushes the images to
|
|
355
|
-
GHCR (`ghcr.io/cintelis/bugxhunter-runner` and `bugxhunter-
|
|
377
|
+
GHCR (`ghcr.io/cintelis/bugxhunter-runner`, `bugxhunter-agent` and `bugxhunter-render`) on `master` and on `v*` tags, and Dependabot
|
|
356
378
|
keeps npm, Actions and base images current.
|
|
357
379
|
|
|
358
380
|
Server and browser share one type contract in `shared/` (`agent.d.ts`, `scx.d.ts`): the server's
|
|
@@ -391,6 +413,11 @@ publisher** on npmjs.com set to this repository and `release.yml`, once; no npm
|
|
|
391
413
|
| `server/src/opencode.ts` | Starts/stops the OpenCode server, one SDK client per project folder, event mapping |
|
|
392
414
|
| `server/src/index.ts` | Express: `/api/agent/*` (OpenCode) and `/api/chat`, `/api/models`, `/api/kb` (SCX) |
|
|
393
415
|
| `server/src/scx.ts`, `rag.ts` | SCX client and in-memory knowledge base (Playground) |
|
|
416
|
+
| `server/src/providers.ts`, `nvidia-health.ts` | NVIDIA / OpenRouter providers; hides NVIDIA models whose endpoints are retired |
|
|
417
|
+
| `server/src/playground-store.ts` | Saved Playground sessions, sealed with the vault key |
|
|
418
|
+
| `server/src/render.ts`, `docker/render-server.py`, `docker/drawio_outline.py` | The render service (diagrams, `.drawio` outlines) and the runner's client for it |
|
|
419
|
+
| `web/src/Canvas.tsx`, `web/src/canvas/` | The threat-model canvas |
|
|
420
|
+
| `web/src/DrawioBlock.tsx`, `diagrams.ts` | Diagrams in replies |
|
|
394
421
|
| `shared/` | Type contract between server and browser |
|
|
395
422
|
| `scripts/` | `sign-release.sh` (maintainer, offline key), `verify-release.sh` (users), `release-table.sh`, the release public key |
|
|
396
423
|
| `web/src/AgentPanel.tsx` | Runner transcript, approvals and session flow; `DiffModal.tsx` and `QuestionCard.tsx` hold the Changes view and agent questions |
|
package/SECURITY.md
CHANGED
|
@@ -11,7 +11,7 @@ Don't open a public issue for security problems.
|
|
|
11
11
|
- **Signed.** Every release's `checksums.txt` is signed with the Cintelis
|
|
12
12
|
release key, an Ed25519 key kept offline by the maintainer and never
|
|
13
13
|
stored on GitHub. It covers the release archives and `images.txt`, which
|
|
14
|
-
pins
|
|
14
|
+
pins the container images (runner, agent, agent-slim and render) by digest. `scripts/verify-release.sh` refuses
|
|
15
15
|
any release whose signature doesn't verify.
|
|
16
16
|
- **Built by CI, with provenance.** Release archives and images are built by
|
|
17
17
|
this repository's release workflow and carry a signed build-provenance
|
|
@@ -112,8 +112,7 @@ ssh-keygen -Y verify -f allowed_signers -I bugxhunter-release -n bugxhunter-rele
|
|
|
112
112
|
sha256sum --ignore-missing -c checksums.txt
|
|
113
113
|
|
|
114
114
|
# 3. pull the images by the digests in the signed images.txt, not by tag
|
|
115
|
-
docker pull "$
|
|
116
|
-
docker pull "$(sed -n 2p images.txt)"
|
|
115
|
+
while read -r ref; do docker pull "$ref"; done < images.txt
|
|
117
116
|
|
|
118
117
|
# 4. optionally, they were built by this repository's release workflow
|
|
119
118
|
gh attestation verify bugxhunter-runner_<version>_app.tar.gz --repo cintelis/bugxhunter-runner
|
package/docker-compose.yml
CHANGED
|
@@ -44,16 +44,19 @@ services:
|
|
|
44
44
|
OPENCODE_URL: http://agent:4096
|
|
45
45
|
OPEN_RUNNER_WORKSPACE: /workspace
|
|
46
46
|
OPEN_RUNNER_LOG_DIR: /logs # audit log, one JSONL file per day
|
|
47
|
+
OPEN_RUNNER_RENDER_URL: http://render:8080 # diagram specs -> editable .drawio.svg
|
|
47
48
|
volumes:
|
|
48
49
|
- workspace:/workspace # same volume as the agent: attachments
|
|
49
50
|
- logs:/logs # audit + egress logs; NOT mounted in the agent, so it can't edit them
|
|
50
51
|
- runner-data:/data # the sealed key vault (ciphertext only; see SECURITY.md)
|
|
51
52
|
ports:
|
|
52
53
|
- "127.0.0.1:${OPEN_RUNNER_PORT:-8790}:8790" # localhost only; put TLS in front before exposing
|
|
53
|
-
networks: [net]
|
|
54
|
+
networks: [net, render]
|
|
54
55
|
depends_on:
|
|
55
56
|
agent:
|
|
56
57
|
condition: service_healthy
|
|
58
|
+
render:
|
|
59
|
+
condition: service_healthy
|
|
57
60
|
read_only: true
|
|
58
61
|
tmpfs: [/tmp]
|
|
59
62
|
cap_drop: [ALL]
|
|
@@ -88,6 +91,25 @@ services:
|
|
|
88
91
|
start_period: 20s
|
|
89
92
|
restart: unless-stopped
|
|
90
93
|
|
|
94
|
+
# Diagram renderer: turns the diagram specs models write in the Playground into
|
|
95
|
+
# editable .drawio.svg files (drawgen). Model output is parsed here, not in the
|
|
96
|
+
# runner that holds the keys: no internet (the `render` network is internal and
|
|
97
|
+
# shared only with the runner), no volumes, no secrets, read-only, tiny limits.
|
|
98
|
+
render:
|
|
99
|
+
image: ghcr.io/cintelis/bugxhunter-render:${BXH_VERSION:-latest}
|
|
100
|
+
build:
|
|
101
|
+
context: .
|
|
102
|
+
dockerfile: docker/render.Dockerfile
|
|
103
|
+
networks: [render]
|
|
104
|
+
read_only: true
|
|
105
|
+
tmpfs: [/tmp]
|
|
106
|
+
cap_drop: [ALL]
|
|
107
|
+
security_opt: ["no-new-privileges:true"]
|
|
108
|
+
pids_limit: 64
|
|
109
|
+
mem_limit: 512m
|
|
110
|
+
cpus: 1
|
|
111
|
+
restart: unless-stopped
|
|
112
|
+
|
|
91
113
|
# Passive egress logger: shares the agent's network namespace and sniffs its
|
|
92
114
|
# outbound traffic (tcpdump), recording distinct destinations + DNS lookups to
|
|
93
115
|
# /logs/egress-<date>.jsonl. Log-only — it never blocks traffic and
|
|
@@ -111,6 +133,8 @@ services:
|
|
|
111
133
|
|
|
112
134
|
networks:
|
|
113
135
|
net: {} # normal bridge: agent + runner share it, agent reaches the internet via NAT
|
|
136
|
+
render: # runner <-> render only; internal, so the renderer has no route out
|
|
137
|
+
internal: true
|
|
114
138
|
|
|
115
139
|
volumes:
|
|
116
140
|
workspace: {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bugxhunter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
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",
|
package/server/dist/index.js
CHANGED
|
@@ -18,6 +18,9 @@ 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 * as playground from "./playground-store.js";
|
|
22
|
+
import * as nvidiaHealth from "./nvidia-health.js";
|
|
23
|
+
import * as render from "./render.js";
|
|
21
24
|
import { apiLimiter, fileLimiter, staticLimiter } from "./ratelimit.js";
|
|
22
25
|
import { createWorkspace, deleteWorkspace, listFiles, listWorkspaces, saveUpload, WORKSPACES_ROOT } from "./workspaces.js";
|
|
23
26
|
import * as github from "./github.js";
|
|
@@ -105,6 +108,11 @@ app.use("/api", (req, res, next) => {
|
|
|
105
108
|
});
|
|
106
109
|
// Prompts can carry attachments (base64), so allow larger bodies there.
|
|
107
110
|
app.use("/api/agent/prompt", express.json({ limit: "40mb" }));
|
|
111
|
+
// Playground vision turns carry images inline as base64 data URLs (4 x 5 MB max in the UI).
|
|
112
|
+
app.use("/api/chat", express.json({ limit: "32mb" }));
|
|
113
|
+
// Saved Playground sessions carry the same images, sealed into the body.
|
|
114
|
+
app.use("/api/playground", express.json({ limit: "40mb" }));
|
|
115
|
+
app.use("/api/render", express.json({ limit: "4mb" })); // a .drawio file; specs are capped in render.ts
|
|
108
116
|
app.use(express.json({ limit: "4mb" }));
|
|
109
117
|
// Rate limits before anything else under /api, sign-in included (see ratelimit.ts).
|
|
110
118
|
app.use("/api", apiLimiter);
|
|
@@ -135,6 +143,50 @@ const sendError = (res, e) => {
|
|
|
135
143
|
return res.status(500).json({ error: { message: String(e?.message ?? e) } });
|
|
136
144
|
};
|
|
137
145
|
app.get("/api/health", (_req, res) => res.json({ ok: true, baseUrl: PROVIDERS.scx.baseUrl }));
|
|
146
|
+
// --- Saved Playground sessions (see playground-store.ts) ---------------------
|
|
147
|
+
// Chats and canvases, sealed with the vault key into the runner-only data volume.
|
|
148
|
+
app.get("/api/playground/sessions/:kind", (req, res) => {
|
|
149
|
+
try {
|
|
150
|
+
res.json({ sessions: playground.list(req.params.kind) });
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
sendError(res, e);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
app.get("/api/playground/sessions/:kind/:id", (req, res) => {
|
|
157
|
+
try {
|
|
158
|
+
res.json(playground.get(req.params.kind, req.params.id));
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
sendError(res, e);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
app.put("/api/playground/sessions/:kind/:id", (req, res) => {
|
|
165
|
+
try {
|
|
166
|
+
const { title, body } = req.body ?? {};
|
|
167
|
+
res.json(playground.put(req.params.kind, req.params.id, String(title ?? ""), body));
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
sendError(res, e);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
app.delete("/api/playground/sessions/:kind/:id", (req, res) => {
|
|
174
|
+
try {
|
|
175
|
+
playground.remove(req.params.kind, req.params.id);
|
|
176
|
+
res.json({ ok: true });
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
sendError(res, e);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
app.delete("/api/playground/sessions/:kind", (req, res) => {
|
|
183
|
+
try {
|
|
184
|
+
res.json({ deleted: playground.removeAll(req.params.kind) });
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
sendError(res, e);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
138
190
|
// --- Key vault (see shared/vault.d.ts) --------------------------------------
|
|
139
191
|
// The browser does the key derivation and wrapping; these routes only store
|
|
140
192
|
// ciphertext, accept an unseal key into memory, and manage sealed items.
|
|
@@ -293,6 +345,26 @@ app.post("/api/github/clone", async (req, res) => {
|
|
|
293
345
|
sendError(res, e);
|
|
294
346
|
}
|
|
295
347
|
});
|
|
348
|
+
// --- Diagrams (drawgen, in the separate render service) ---------------------
|
|
349
|
+
app.get("/api/render/status", async (_req, res) => res.json(await render.status()));
|
|
350
|
+
app.post("/api/render/outline", async (req, res) => {
|
|
351
|
+
try {
|
|
352
|
+
res.json(await render.outline(req.body?.file));
|
|
353
|
+
}
|
|
354
|
+
catch (e) {
|
|
355
|
+
sendError(res, e);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
app.post("/api/render/drawio", async (req, res) => {
|
|
359
|
+
try {
|
|
360
|
+
res.json(await render.drawio(req.body?.spec));
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
sendError(res, e);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
/** Which NVIDIA models are hidden as retired, and when the catalogue was last probed. */
|
|
367
|
+
app.get("/api/models/nvidia-health", (_req, res) => res.json(nvidiaHealth.status()));
|
|
296
368
|
app.get("/api/models", async (_req, res) => {
|
|
297
369
|
try {
|
|
298
370
|
res.json({ data: await listModels() });
|
|
@@ -325,10 +397,13 @@ app.post("/api/chat", async (req, res) => {
|
|
|
325
397
|
}
|
|
326
398
|
}
|
|
327
399
|
}
|
|
328
|
-
const { client, model } = clientFor(String(params.model ?? ""));
|
|
400
|
+
const { client, model, provider } = clientFor(String(params.model ?? ""));
|
|
329
401
|
const call = { ...params, model };
|
|
402
|
+
// Keep the NVIDIA list honest: a 404 means the model was retired upstream.
|
|
403
|
+
const track = (p) => provider !== "nvidia" ? p : p.then((v) => { nvidiaHealth.markAlive(model); return v; }, (e) => { if (e instanceof SCXError && e.status === 404)
|
|
404
|
+
nvidiaHealth.markRetired(model); throw e; });
|
|
330
405
|
if (params.stream) {
|
|
331
|
-
const upstream = await client.chatStreamResponse(call);
|
|
406
|
+
const upstream = await track(client.chatStreamResponse(call));
|
|
332
407
|
res.setHeader("Content-Type", "text/event-stream");
|
|
333
408
|
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
334
409
|
res.setHeader("Connection", "keep-alive");
|
|
@@ -350,7 +425,7 @@ app.post("/api/chat", async (req, res) => {
|
|
|
350
425
|
res.end();
|
|
351
426
|
}
|
|
352
427
|
else {
|
|
353
|
-
const completion = await client.chat(call);
|
|
428
|
+
const completion = await track(client.chat(call));
|
|
354
429
|
res.json(retrieved.length
|
|
355
430
|
? { ...completion, scx_sources: retrieved.map((r) => ({ doc: r.doc, score: Number(r.score.toFixed(3)) })) }
|
|
356
431
|
: completion);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retired NVIDIA NIM models. NVIDIA's /v1/models keeps advertising models whose
|
|
3
|
+
* endpoints now answer 404, so the Playground list would offer dead models.
|
|
4
|
+
*
|
|
5
|
+
* A model is marked retired when a chat to it answers 404, either from a real
|
|
6
|
+
* Playground chat or from the background probe (a 1-token request to each
|
|
7
|
+
* catalogue model, at most once a day). It comes back if a later probe or chat
|
|
8
|
+
* succeeds. The list is not secret, so it is kept as plain JSON next to the vault.
|
|
9
|
+
*/
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { VAULT_FILE } from "./vault.js";
|
|
13
|
+
export const HEALTH_FILE = process.env.OPEN_RUNNER_NVIDIA_HEALTH_FILE ?? path.join(path.dirname(VAULT_FILE), "nvidia-models.json");
|
|
14
|
+
const PROBE_EVERY_MS = 24 * 60 * 60 * 1000;
|
|
15
|
+
/** Gap between probe requests, to stay well inside the free tier's rate limit. */
|
|
16
|
+
const PROBE_GAP_MS = Number(process.env.OPEN_RUNNER_NVIDIA_PROBE_GAP_MS ?? 1500);
|
|
17
|
+
let state = null;
|
|
18
|
+
let probing = null;
|
|
19
|
+
function load() {
|
|
20
|
+
if (state)
|
|
21
|
+
return state;
|
|
22
|
+
try {
|
|
23
|
+
const s = JSON.parse(fs.readFileSync(HEALTH_FILE, "utf8"));
|
|
24
|
+
state = { checkedAt: s.checkedAt ?? null, retired: s.retired && typeof s.retired === "object" ? s.retired : {} };
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
state = { checkedAt: null, retired: {} };
|
|
28
|
+
}
|
|
29
|
+
return state;
|
|
30
|
+
}
|
|
31
|
+
function save() {
|
|
32
|
+
try {
|
|
33
|
+
fs.mkdirSync(path.dirname(HEALTH_FILE), { recursive: true });
|
|
34
|
+
const tmp = `${HEALTH_FILE}.tmp`;
|
|
35
|
+
fs.writeFileSync(tmp, JSON.stringify(load(), null, 2));
|
|
36
|
+
fs.renameSync(tmp, HEALTH_FILE);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.error("[nvidia] could not save model health:", e.message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export const isRetired = (id) => id in load().retired;
|
|
43
|
+
export const retiredIds = () => Object.keys(load().retired).sort();
|
|
44
|
+
export function markRetired(id) {
|
|
45
|
+
const s = load();
|
|
46
|
+
if (s.retired[id])
|
|
47
|
+
return;
|
|
48
|
+
s.retired[id] = new Date().toISOString();
|
|
49
|
+
console.log(`[nvidia] ${id} answers 404, hiding it from the Playground`);
|
|
50
|
+
save();
|
|
51
|
+
}
|
|
52
|
+
export function markAlive(id) {
|
|
53
|
+
const s = load();
|
|
54
|
+
if (!s.retired[id])
|
|
55
|
+
return;
|
|
56
|
+
delete s.retired[id];
|
|
57
|
+
save();
|
|
58
|
+
}
|
|
59
|
+
export function status() {
|
|
60
|
+
const s = load();
|
|
61
|
+
return { checkedAt: s.checkedAt, probing: Boolean(probing), retired: retiredIds() };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Probe every id once if the last probe is older than a day (or `force`).
|
|
65
|
+
* Runs in the background; concurrent calls share one run.
|
|
66
|
+
*/
|
|
67
|
+
export function probeIfDue(ids, probeOne, force = false) {
|
|
68
|
+
if (probing)
|
|
69
|
+
return probing;
|
|
70
|
+
const s = load();
|
|
71
|
+
const due = force || !s.checkedAt || Date.now() - Date.parse(s.checkedAt) > PROBE_EVERY_MS;
|
|
72
|
+
if (!due || !ids.length)
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
probing = (async () => {
|
|
75
|
+
let gone = 0;
|
|
76
|
+
for (const id of ids) {
|
|
77
|
+
const r = await probeOne(id).catch(() => "unknown");
|
|
78
|
+
if (r === "missing") {
|
|
79
|
+
markRetired(id);
|
|
80
|
+
gone++;
|
|
81
|
+
}
|
|
82
|
+
else if (r === "ok")
|
|
83
|
+
markAlive(id);
|
|
84
|
+
if (PROBE_GAP_MS)
|
|
85
|
+
await new Promise((res) => setTimeout(res, PROBE_GAP_MS));
|
|
86
|
+
}
|
|
87
|
+
s.checkedAt = new Date().toISOString();
|
|
88
|
+
save();
|
|
89
|
+
console.log(`[nvidia] probed ${ids.length} models, ${gone} retired`);
|
|
90
|
+
})().finally(() => { probing = null; });
|
|
91
|
+
return probing;
|
|
92
|
+
}
|
|
93
|
+
/** For tests. */
|
|
94
|
+
export function _reset() {
|
|
95
|
+
state = null;
|
|
96
|
+
probing = null;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=nvidia-health.js.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saved Playground sessions (chats and threat-model canvases), encrypted with the vault key.
|
|
3
|
+
*
|
|
4
|
+
* One file per session next to the vault: /data/playground in Docker (the runner-only
|
|
5
|
+
* runner-data volume, never the agent's), ~/.config/bugxhunter/playground otherwise. Only ids,
|
|
6
|
+
* kind and timestamps are in the clear; the title and the body are sealed separately (the title
|
|
7
|
+
* so a listing doesn't decrypt every body), each bound to its record by its AAD. A copied
|
|
8
|
+
* volume or a stolen disk shows how many sessions exist and when, nothing about what is in them.
|
|
9
|
+
*/
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { VAULT_FILE, openData, sealData } from "./vault.js";
|
|
13
|
+
import { httpError } from "./errors.js";
|
|
14
|
+
import { audit } from "./audit.js";
|
|
15
|
+
export const PLAYGROUND_DIR = process.env.OPEN_RUNNER_PLAYGROUND_DIR ?? path.join(path.dirname(VAULT_FILE), "playground");
|
|
16
|
+
const KINDS = ["chat", "canvas"];
|
|
17
|
+
const ID = /^[a-z0-9][a-z0-9-]{7,63}$/;
|
|
18
|
+
/** Sealed body cap: four 5 MB images in base64 plus the transcript fit well under it. */
|
|
19
|
+
const MAX_BODY = 36 * 1024 * 1024;
|
|
20
|
+
const MAX_SESSIONS = 500;
|
|
21
|
+
function check(kind, id) {
|
|
22
|
+
if (!KINDS.includes(kind))
|
|
23
|
+
throw httpError(400, "Unknown session kind.");
|
|
24
|
+
if (id !== undefined && !ID.test(id))
|
|
25
|
+
throw httpError(400, "Malformed session id.");
|
|
26
|
+
}
|
|
27
|
+
const file = (kind, id) => path.join(PLAYGROUND_DIR, `${kind}-${id}.json`);
|
|
28
|
+
const aad = (kind, id, part) => `playground:${kind}:${id}:${part}`;
|
|
29
|
+
function read(kind, id) {
|
|
30
|
+
try {
|
|
31
|
+
const r = JSON.parse(fs.readFileSync(file(kind, id), "utf8"));
|
|
32
|
+
return r?.v === 1 && r.id === id && r.kind === kind ? r : null;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function list(kind) {
|
|
39
|
+
check(kind);
|
|
40
|
+
let names;
|
|
41
|
+
try {
|
|
42
|
+
names = fs.readdirSync(PLAYGROUND_DIR);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const name of names) {
|
|
49
|
+
const m = name.match(/^(chat|canvas)-([a-z0-9-]+)\.json$/);
|
|
50
|
+
if (!m || m[1] !== kind)
|
|
51
|
+
continue;
|
|
52
|
+
const r = read(kind, m[2]);
|
|
53
|
+
if (!r)
|
|
54
|
+
continue;
|
|
55
|
+
let title;
|
|
56
|
+
try {
|
|
57
|
+
title = openData(r.title, aad(kind, r.id, "title"));
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
if (e.status === 503)
|
|
61
|
+
throw e; // sealed: say so rather than list nothing
|
|
62
|
+
continue; // a record that won't open (other vault, tampered) is skipped, not fatal
|
|
63
|
+
}
|
|
64
|
+
out.push({ id: r.id, kind, title, createdAt: r.createdAt, updatedAt: r.updatedAt, bytes: r.body.ct.length });
|
|
65
|
+
}
|
|
66
|
+
return out.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
67
|
+
}
|
|
68
|
+
export function get(kind, id) {
|
|
69
|
+
check(kind, id);
|
|
70
|
+
const r = read(kind, id);
|
|
71
|
+
if (!r)
|
|
72
|
+
throw httpError(404, "No such saved session.");
|
|
73
|
+
try {
|
|
74
|
+
return {
|
|
75
|
+
id, kind,
|
|
76
|
+
title: openData(r.title, aad(kind, id, "title")),
|
|
77
|
+
updatedAt: r.updatedAt,
|
|
78
|
+
body: JSON.parse(openData(r.body, aad(kind, id, "body"))),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
if (e.status)
|
|
83
|
+
throw e;
|
|
84
|
+
throw httpError(422, "This saved session does not open with the current vault.");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export function put(kind, id, title, body) {
|
|
88
|
+
check(kind, id);
|
|
89
|
+
const json = JSON.stringify(body ?? null);
|
|
90
|
+
if (json.length > MAX_BODY)
|
|
91
|
+
throw httpError(413, "Session too large to save (images count towards it).");
|
|
92
|
+
const prev = read(kind, id);
|
|
93
|
+
if (!prev) {
|
|
94
|
+
let count = 0;
|
|
95
|
+
try {
|
|
96
|
+
count = fs.readdirSync(PLAYGROUND_DIR).filter((n) => n.endsWith(".json")).length;
|
|
97
|
+
}
|
|
98
|
+
catch { /* no dir yet */ }
|
|
99
|
+
if (count >= MAX_SESSIONS)
|
|
100
|
+
throw httpError(409, `Up to ${MAX_SESSIONS} saved sessions; delete some first.`);
|
|
101
|
+
}
|
|
102
|
+
const now = new Date().toISOString();
|
|
103
|
+
const record = {
|
|
104
|
+
v: 1, id, kind,
|
|
105
|
+
createdAt: prev?.createdAt ?? now,
|
|
106
|
+
updatedAt: now,
|
|
107
|
+
title: sealData(String(title || "Untitled").slice(0, 200), aad(kind, id, "title")),
|
|
108
|
+
body: sealData(json, aad(kind, id, "body")),
|
|
109
|
+
};
|
|
110
|
+
fs.mkdirSync(PLAYGROUND_DIR, { recursive: true, mode: 0o700 });
|
|
111
|
+
const target = file(kind, id);
|
|
112
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
113
|
+
fs.writeFileSync(tmp, JSON.stringify(record), { mode: 0o600 });
|
|
114
|
+
fs.renameSync(tmp, target);
|
|
115
|
+
if (!prev)
|
|
116
|
+
audit("playground.saved", { kind, id });
|
|
117
|
+
return { updatedAt: now };
|
|
118
|
+
}
|
|
119
|
+
export function remove(kind, id) {
|
|
120
|
+
check(kind, id);
|
|
121
|
+
fs.rmSync(file(kind, id), { force: true });
|
|
122
|
+
audit("playground.deleted", { kind, id });
|
|
123
|
+
}
|
|
124
|
+
export function removeAll(kind) {
|
|
125
|
+
check(kind);
|
|
126
|
+
let n = 0;
|
|
127
|
+
let names = [];
|
|
128
|
+
try {
|
|
129
|
+
names = fs.readdirSync(PLAYGROUND_DIR);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
for (const name of names) {
|
|
135
|
+
if (name.startsWith(`${kind}-`) && name.endsWith(".json")) {
|
|
136
|
+
fs.rmSync(path.join(PLAYGROUND_DIR, name), { force: true });
|
|
137
|
+
n++;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
audit("playground.deleted_all", { kind, count: n });
|
|
141
|
+
return n;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=playground-store.js.map
|
package/server/dist/providers.js
CHANGED
|
@@ -21,9 +21,10 @@ import crypto from "node:crypto";
|
|
|
21
21
|
import fs from "node:fs";
|
|
22
22
|
import os from "node:os";
|
|
23
23
|
import path from "node:path";
|
|
24
|
-
import { SCXClient } from "./scx.js";
|
|
24
|
+
import { SCXClient, SCXError } from "./scx.js";
|
|
25
25
|
import { httpError } from "./errors.js";
|
|
26
26
|
import * as vault from "./vault.js";
|
|
27
|
+
import * as nvidiaHealth from "./nvidia-health.js";
|
|
27
28
|
export const PROVIDERS = {
|
|
28
29
|
scx: {
|
|
29
30
|
id: "scx", name: "SCX.ai", baseUrl: process.env.SCX_BASE_URL ?? "https://api.scx.ai/v1",
|
|
@@ -196,16 +197,77 @@ export function nvidiaModel(id, meta) {
|
|
|
196
197
|
provider: "nvidia",
|
|
197
198
|
};
|
|
198
199
|
}
|
|
199
|
-
/**
|
|
200
|
-
function
|
|
200
|
+
/** NVIDIA NIM's live model ids (its /v1/models). Keyed, so the vault must be open. */
|
|
201
|
+
async function nvidiaCatalogueLive() {
|
|
202
|
+
const r = await fetch(`${PROVIDERS.nvidia.baseUrl}/models`, {
|
|
203
|
+
headers: { Authorization: `Bearer ${apiKey("nvidia")}` },
|
|
204
|
+
signal: AbortSignal.timeout(10_000),
|
|
205
|
+
});
|
|
206
|
+
if (!r.ok)
|
|
207
|
+
throw new Error(`NVIDIA /models replied ${r.status}`);
|
|
208
|
+
const data = (await r.json()).data ?? [];
|
|
209
|
+
return data.map((m) => m.id).filter((id) => Boolean(id));
|
|
210
|
+
}
|
|
211
|
+
/** Uncurated NVIDIA models that take images, judged from the id ("...-vision-...", "...-vl-..."). */
|
|
212
|
+
export const looksLikeVision = (id) => /vision|(^|[-/])vl($|-)/i.test(id);
|
|
213
|
+
/** A live NVIDIA model without curated metadata: the raw id with best-effort defaults. */
|
|
214
|
+
function nvidiaLiveModel(id) {
|
|
215
|
+
return {
|
|
216
|
+
id: `nim/${id}`,
|
|
217
|
+
name: id,
|
|
218
|
+
created: 0,
|
|
219
|
+
input_modalities: looksLikeVision(id) ? ["text", "image"] : ["text"],
|
|
220
|
+
output_modalities: ["text"],
|
|
221
|
+
context_length: null,
|
|
222
|
+
max_output_length: null,
|
|
223
|
+
pricing: {},
|
|
224
|
+
supported_sampling_parameters: ["temperature", "top_p", "max_tokens", "stop", "frequency_penalty", "presence_penalty", "seed"],
|
|
225
|
+
supported_features: [],
|
|
226
|
+
description: "NVIDIA NIM model from the live catalogue (metadata not curated; some endpoints are non-chat or may be unavailable).",
|
|
227
|
+
provider: "nvidia",
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* NVIDIA NIM models for the Playground: the full live catalogue (its /v1/models),
|
|
232
|
+
* same list the agent discovers, with curated metadata merged in for the known
|
|
233
|
+
* models. Falls back to the curated set if the catalogue can't be fetched (e.g.
|
|
234
|
+
* the vault is sealed, so there is no key to query it with).
|
|
235
|
+
*/
|
|
236
|
+
async function nvidiaModels() {
|
|
201
237
|
if (!configured("nvidia"))
|
|
202
238
|
return [];
|
|
203
|
-
|
|
239
|
+
const curated = () => NVIDIA_MODELS.filter((id) => NVIDIA_CATALOGUE[id]).map((id) => nvidiaModel(id, NVIDIA_CATALOGUE[id]));
|
|
240
|
+
try {
|
|
241
|
+
const ids = await nvidiaCatalogueLive();
|
|
242
|
+
if (!ids.length)
|
|
243
|
+
return curated();
|
|
244
|
+
void nvidiaHealth.probeIfDue(ids, probeNvidia);
|
|
245
|
+
return ids
|
|
246
|
+
.filter((id) => !nvidiaHealth.isRetired(id))
|
|
247
|
+
.map((id) => (NVIDIA_CATALOGUE[id] ? nvidiaModel(id, NVIDIA_CATALOGUE[id]) : nvidiaLiveModel(id)))
|
|
248
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
console.error("[nvidia] model list failed:", e.message);
|
|
252
|
+
return curated();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** One tiny chat to see whether an NVIDIA model's endpoint still exists (404 = retired). */
|
|
256
|
+
// A retired model answers 404 at once; a slow or queued one is just "unknown", so keep this short.
|
|
257
|
+
const probeClient = new SCXClient({ apiKey: () => apiKey("nvidia"), baseUrl: PROVIDERS.nvidia.baseUrl, timeoutMs: 15_000 });
|
|
258
|
+
export async function probeNvidia(id) {
|
|
259
|
+
try {
|
|
260
|
+
await probeClient.chat({ model: id, messages: [{ role: "user", content: "hi" }], max_tokens: 1, stream: false }, { timeoutMs: 15_000 });
|
|
261
|
+
return "ok";
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
return e instanceof SCXError && e.status === 404 ? "missing" : "unknown";
|
|
265
|
+
}
|
|
204
266
|
}
|
|
205
267
|
/** Every model the Playground can use: SCX's, plus OpenRouter's and NVIDIA's when their keys are configured. */
|
|
206
268
|
export async function listModels() {
|
|
207
269
|
const scx = (await clients.scx.listModels()).map((m) => ({ ...m, provider: "scx" }));
|
|
208
|
-
const nvidia = nvidiaModels();
|
|
270
|
+
const nvidia = await nvidiaModels();
|
|
209
271
|
if (!configured("openrouter"))
|
|
210
272
|
return [...scx, ...nvidia];
|
|
211
273
|
try {
|