bugxhunter 0.8.1 → 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 +11 -3
- package/server/dist/opencode.js +1 -0
- package/server/dist/providers.js +34 -5
- package/server/dist/ratelimit.js +26 -0
- package/web/dist/assets/{index-C8MAQ2Y2.js → index-Crcy3YbK.js} +1 -1
- package/web/dist/index.html +1 -1
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
|
@@ -18,6 +18,7 @@ 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);
|
|
@@ -777,8 +783,9 @@ app.get("/api/agent/events", async (req, res) => {
|
|
|
777
783
|
// Production (Docker): serve the built web app from the same origin.
|
|
778
784
|
const WEB_DIST = path.join(REPO_ROOT, "web", "dist");
|
|
779
785
|
if (process.env.NODE_ENV === "production" && fs.existsSync(WEB_DIST)) {
|
|
786
|
+
app.use(staticLimiter);
|
|
780
787
|
app.use(express.static(WEB_DIST, { index: false }));
|
|
781
|
-
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")));
|
|
782
789
|
}
|
|
783
790
|
// Body-parser failures (oversized attachment payloads, malformed JSON) and
|
|
784
791
|
// anything a route threw synchronously: answer in JSON like every other error.
|
|
@@ -798,6 +805,7 @@ const server = app.listen(PORT, process.env.HOST ?? "127.0.0.1", () => {
|
|
|
798
805
|
const src = keySource(p.id);
|
|
799
806
|
const where = {
|
|
800
807
|
vault: "vault",
|
|
808
|
+
file: "a key file (not in the clear in the environment)",
|
|
801
809
|
env: ".env — consider moving it into the vault",
|
|
802
810
|
"opencode-auth": "OpenCode's auth.json — consider moving it into the vault",
|
|
803
811
|
none: p.id === "scx" ? "none yet — set up the vault in the sidebar" : "not configured (optional)",
|
package/server/dist/opencode.js
CHANGED
|
@@ -525,6 +525,7 @@ export function toUiMessages(raw) {
|
|
|
525
525
|
tokens: info.tokens,
|
|
526
526
|
cost: info.cost,
|
|
527
527
|
model: info.modelID ? `${info.providerID}/${info.modelID}` : undefined,
|
|
528
|
+
time: info.time ? { created: info.time.created, completed: info.time.completed } : undefined,
|
|
528
529
|
error: info.error ? errorText(info.error) : undefined,
|
|
529
530
|
};
|
|
530
531
|
});
|
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
|
|
@@ -50,7 +50,7 @@ Error generating stack: `+l.message+`
|
|
|
50
50
|
`))!==-1;){const ne=m.slice(0,q).replace(/\r$/,"");if(m=m.slice(q+1),!ne.startsWith("data:"))continue;const be=ne.slice(5).trim();if(be==="[DONE]"){Mg(p,u),u.onDone(E);return}let fe;try{fe=JSON.parse(be)}catch{continue}if(fe.error){u.onError(fe.error.message??"stream error");return}if(fe.scx_sources){(y=u.onSources)==null||y.call(u,fe.scx_sources);continue}const F=(R=fe.choices)==null?void 0:R[0],P=F==null?void 0:F.delta;if(P!=null&&P.content&&u.onDelta(P.content),P!=null&&P.tool_calls)for(const I of P.tool_calls){const K=I.index??0;p[K]??(p[K]={id:I.id??`call_${K}`,type:"function",function:{name:"",arguments:""}}),I.id&&(p[K].id=I.id),(b=I.function)!=null&&b.name&&(p[K].function.name+=I.function.name),(v=I.function)!=null&&v.arguments&&(p[K].function.arguments+=I.function.arguments)}F!=null&&F.finish_reason&&(E=F.finish_reason),fe.usage&&((L=u.onUsage)==null||L.call(u,{prompt:fe.usage.prompt_tokens,completion:fe.usage.completion_tokens,reasoning:(S=fe.usage.completion_tokens_details)==null?void 0:S.reasoning_tokens}))}}Mg(p,u),u.onDone(E)}async function Vb(s,u){var p,E,y,R,b,v;const r=await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...s,stream:!1}),signal:u.signal});if(!r.ok){u.onError(await tr(r)||`Chat request failed (${r.status})`);return}const o=await r.json();o.scx_sources&&((p=u.onSources)==null||p.call(u,o.scx_sources));const d=(E=o.choices)==null?void 0:E[0],m=d==null?void 0:d.message;m!=null&&m.content&&u.onDelta(m.content),(y=m==null?void 0:m.tool_calls)!=null&&y.length&&((R=u.onToolCalls)==null||R.call(u,m.tool_calls)),o.usage&&((v=u.onUsage)==null||v.call(u,{prompt:o.usage.prompt_tokens,completion:o.usage.completion_tokens,reasoning:(b=o.usage.completion_tokens_details)==null?void 0:b.reasoning_tokens})),u.onDone((d==null?void 0:d.finish_reason)??null)}function Mg(s,u){const r=Object.values(s).filter(o=>o.function.name);r.length&&u.onToolCalls&&u.onToolCalls(r)}async function tr(s){var u;try{const r=await s.json();return((u=r==null?void 0:r.error)==null?void 0:u.message)??""}catch{return""}}async function Kb(s){const u=await fetch(`/api/agent/sessions?directory=${encodeURIComponent(s)}`);if(!u.ok)throw new Error(await Gn(u)||`Could not list sessions (${u.status})`);return(await u.json()).sessions}async function Jb(s,u){const r=await fetch(`/api/agent/session/${encodeURIComponent(s)}/messages?directory=${encodeURIComponent(u)}`);if(!r.ok)throw new Error(await Gn(r)||`Could not load session (${r.status})`);return r.json()}async function $b(s,u){const r=await fetch(`/api/agent/session/${encodeURIComponent(s)}?directory=${encodeURIComponent(u)}`,{method:"DELETE"});if(!r.ok)throw new Error(await Gn(r)||`Could not delete session (${r.status})`)}async function Ib(s){const u=await fetch(`/api/agent/commands?directory=${encodeURIComponent(s)}`);return u.ok?(await u.json()).commands:[]}async function Fb(s){const u=await fetch("/api/agent/command",{method:"POST",headers:ei(),body:JSON.stringify(s)});if(!u.ok)throw new Error(await Gn(u)||`Command failed (${u.status})`)}async function Wb(s,u,r){const o=await fetch("/api/agent/compact",{method:"POST",headers:ei(),body:JSON.stringify({sessionID:s,directory:u,model:r})});if(!o.ok)throw new Error(await Gn(o)||`Compact failed (${o.status})`)}async function Pb(){const s=await fetch("/api/agent/status");if(!s.ok)throw new Error(await Gn(s)||`Agent server not ready (${s.status})`);return s.json()}async function gy(s){const u=await fetch(`/api/agent/directory?directory=${encodeURIComponent(s)}`);if(!u.ok)throw new Error(await Gn(u)||`Folder not found (${u.status})`);return(await u.json()).directory}async function e1(s,u){const r=await fetch(`/api/agent/pending?sessionID=${encodeURIComponent(s)}&directory=${encodeURIComponent(u)}`);return r.ok?r.json():{permissions:[],questions:[]}}async function t1(s){const u=await fetch("/api/agent/session",{method:"POST",headers:ei(),body:JSON.stringify({directory:s})});if(!u.ok)throw new Error(await Gn(u)||`Could not create session (${u.status})`);return u.json()}async function n1(s){const u=await fetch("/api/agent/prompt",{method:"POST",headers:ei(),body:JSON.stringify(s)});if(!u.ok)throw new Error(await Gn(u)||`Prompt failed (${u.status})`)}async function l1(s){const u=await fetch("/api/agent/permission",{method:"POST",headers:ei(),body:JSON.stringify(s)});if(!u.ok)throw new Error(await Gn(u)||`Permission reply failed (${u.status})`)}async function a1(s){const u=await fetch("/api/agent/question",{method:"POST",headers:ei(),body:JSON.stringify(s)});if(!u.ok)throw new Error(await Gn(u)||`Answer failed (${u.status})`)}async function i1(s,u){await fetch("/api/agent/abort",{method:"POST",headers:ei(),body:JSON.stringify({sessionID:s,directory:u})})}async function s1(s,u){const r=await fetch(`/api/agent/diff?sessionID=${encodeURIComponent(s)}&directory=${encodeURIComponent(u)}`);return r.ok?(await r.json()).diff:null}async function u1(s,u,r,o,d){let m=1e3,p=!1;for(;!o.aborted;){try{await c1(s,u,r,o,()=>{m=1e3,p&&(d==null||d()),p=!0})}catch(E){if(o.aborted)return;if(E.fatal)throw E}if(o.aborted)return;await new Promise(E=>setTimeout(E,m)),m=Math.min(m*2,1e4)}}async function c1(s,u,r,o,d){const m=await fetch(`/api/agent/events?sessionID=${encodeURIComponent(s)}&directory=${encodeURIComponent(u)}`,{signal:o});if(!m.ok||!m.body)throw Object.assign(new Error(await Gn(m)||`Event stream failed (${m.status})`),{fatal:!0});d();const p=m.body.getReader(),E=new TextDecoder;let y="";for(;;){const{value:R,done:b}=await p.read();if(b)break;y+=E.decode(R,{stream:!0});let v;for(;(v=y.indexOf(`
|
|
51
51
|
`))!==-1;){const S=y.slice(0,v).replace(/\r$/,"");if(y=y.slice(v+1),!!S.startsWith("data:"))try{r(JSON.parse(S.slice(5).trim()))}catch{}}}}const ei=()=>({"Content-Type":"application/json"});async function Gn(s){var u,r;try{return((r=(u=await s.json())==null?void 0:u.error)==null?void 0:r.message)??""}catch{return""}}let r1=0;const Kf=()=>`tool_${Date.now().toString(36)}_${(r1++).toString(36)}`,o1=s=>s.map(u=>u.id?u:{...u,id:Kf()}),f1=s=>s.map(({id:u,...r})=>r);function yy({cursor:s=!1}){return c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"prompt",children:">_"}),c.jsxs("span",{className:"word",children:["Bug",c.jsx("span",{className:"x",children:"X"}),"Hunter",s&&c.jsx("span",{className:"cursor big","aria-hidden":!0})]})]})}function d1({size:s=20,tagline:u=!0}){return c.jsxs("div",{className:"brand","aria-label":"BugXHunter",children:[c.jsx("span",{className:"logo",style:{fontSize:s},children:c.jsx(yy,{})}),u&&c.jsx("span",{className:"brand-sub",children:"Open-source AI security testing"})]})}function vy(){return typeof window<"u"&&!!(window.SpeechRecognition||window.webkitSpeechRecognition)}function h1(s){const u=window.SpeechRecognition||window.webkitSpeechRecognition;if(!u)return{stop:()=>{},promise:Promise.resolve("")};const r=new u;r.lang=navigator.language||"en-US",r.interimResults=!0,r.continuous=!1;let o="";const d=new Promise(m=>{var p;r.onresult=E=>{var R;let y="";for(let b=E.resultIndex;b<E.results.length;b++){const v=E.results[b][0].transcript;E.results[b].isFinal?o+=v:y+=v}(R=s.onPartial)==null||R.call(s,o+y)},r.onend=()=>{var E;(E=s.onEnd)==null||E.call(s),m(o.trim())},r.onerror=()=>m(o.trim()),(p=s.onStart)==null||p.call(s),r.start()});return{stop:()=>r.stop(),promise:d}}let Qc=null;function m1(s){if(typeof window>"u"||!window.speechSynthesis)return;const u=s.replace(/[*_`#>]/g,"").replace(/\[(\d+)\]/g,"").trim();u&&(window.speechSynthesis.cancel(),Qc=new SpeechSynthesisUtterance(u),Qc.rate=1.05,window.speechSynthesis.speak(Qc))}function p1(){typeof window<"u"&&window.speechSynthesis&&window.speechSynthesis.cancel(),Qc=null}function ld({title:s,tooltip:u,children:r}){return c.jsxs("header",{className:"term-bar",children:[c.jsx("span",{className:"dot r","aria-hidden":!0}),c.jsx("span",{className:"dot y","aria-hidden":!0}),c.jsx("span",{className:"dot g","aria-hidden":!0}),c.jsx("span",{className:"term-title",title:u??s,children:s}),r&&c.jsx("div",{className:"head-actions",children:r})]})}const g1={p:"$ ",out:"[*] ",ok:"[+] "};function by({lines:s}){const u=k.useMemo(()=>{var m;return typeof window<"u"&&!!((m=window.matchMedia)!=null&&m.call(window,"(prefers-reduced-motion: reduce)").matches)},[]),[r,o]=k.useState(()=>u?{line:s.length,chars:0,started:!0}:{line:0,chars:0,started:!1});k.useEffect(()=>{if(r.line>=s.length)return;const m=s[r.line],p=r.chars<m.text.length,E=r.started?p?m.pace??22:260:400,y=setTimeout(()=>{o(p?{line:r.line,chars:r.chars+1,started:!0}:{line:r.line+1,chars:0,started:!0})},E);return()=>clearTimeout(y)},[r,s]);const d=r.line>=s.length;return c.jsxs("div",{className:"boot",children:[s.map((m,p)=>{if(p>r.line)return c.jsx("div",{className:"line","aria-hidden":!0},p);const E=p<r.line,y=E?m.text:m.text.slice(0,r.chars);return c.jsxs("div",{className:"line",children:[c.jsx("span",{className:m.kind,children:g1[m.kind]}),y,E&&m.ok?c.jsxs("span",{className:"ok",children:[" ",m.ok]}):null,p===r.line&&r.started&&c.jsx("span",{className:"cursor"})]},p)}),d&&c.jsxs("div",{className:"line",children:[c.jsx("span",{className:"p",children:"$ "}),c.jsx("span",{className:"cursor"})]})]})}async function nn(s,u){var o,d;const r=await fetch(s,{headers:{"Content-Type":"application/json"},...u});if(!r.ok){let m=`${r.status}`;try{m=((d=(o=await r.json())==null?void 0:o.error)==null?void 0:d.message)??m}catch{}throw new Error(m)}return r.json()}const Ta=s=>({method:"POST",body:s===void 0?void 0:JSON.stringify(s)}),y1=()=>nn("/api/vault"),v1=(s,u)=>nn("/api/vault/init",Ta({doc:s,dek:u})),xy=s=>nn("/api/vault/unseal",Ta({dek:s})),b1=()=>nn("/api/vault/seal",Ta()),x1=(s,u)=>nn(`/api/vault/items/${encodeURIComponent(s)}`,{method:"PUT",body:JSON.stringify({value:u})}),S1=s=>nn(`/api/vault/items/${encodeURIComponent(s)}`,{method:"DELETE"}),Ug=(s,u)=>nn("/api/vault/methods",Ta({method:s,dek:u})),T1=s=>nn(`/api/vault/methods/${encodeURIComponent(s)}`,{method:"DELETE"}),E1=s=>nn("/api/vault",{method:"DELETE",body:JSON.stringify({dek:s})}),N1=()=>nn("/api/auth/me"),Uf=()=>nn("/api/auth/methods"),_1=()=>nn("/api/auth/challenge",Ta()),w1=s=>nn("/api/auth/passkey",Ta(s)),j1=s=>nn("/api/auth/recover",Ta({dek:s})),A1=()=>nn("/api/auth/logout",Ta()),k1=6e5,ad="bugxhunter-vault-prf-v1",C1="bugxhunter-vault-kek-v1",O1="bugxhunter-vault-ok",$i=new TextEncoder,Sa=crypto.subtle,Vt={enc:s=>btoa(String.fromCharCode(...s instanceof Uint8Array?s:new Uint8Array(s))),dec:s=>Uint8Array.from(atob(s),u=>u.charCodeAt(0))},Tl={enc:s=>Vt.enc(s).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),dec:s=>Vt.dec(s.replace(/-/g,"+").replace(/_/g,"/")+"=".repeat((4-s.length%4)%4))},El=s=>crypto.getRandomValues(new Uint8Array(s)),Gl=s=>s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength);async function Sy(s,u){const r=await Sa.importKey("raw",$i.encode(s),"PBKDF2",!1,["deriveBits"]),o=await Sa.deriveBits({name:"PBKDF2",hash:u.hash,salt:Gl(Vt.dec(u.salt)),iterations:u.iterations},r,256);return new Uint8Array(o)}async function Ty(s,u,r){if(s.length!==32)throw new Error("PRF output must be 32 bytes");let o;if(u.passphrase){if(!r)throw new Error("This passkey was enrolled with a passphrase; enter it as well.");const p=await Sy(r,u.passphrase);o=new Uint8Array(64),o.set(s,0),o.set(p,32),p.fill(0)}else o=new Uint8Array(s);const d=await Sa.importKey("raw",Gl(o),"HKDF",!1,["deriveKey"]),m=await Sa.deriveKey({name:"HKDF",hash:"SHA-256",salt:Gl(Vt.dec(u.hkdfSalt)),info:$i.encode(C1)},d,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"]);return o.fill(0),m}async function nr(s,u){const r=await Sy(s,u),o=await Sa.importKey("raw",Gl(r),"AES-GCM",!1,["encrypt","decrypt"]);return r.fill(0),o}async function tu(s,u,r){const o=El(12),d=await Sa.encrypt({name:"AES-GCM",iv:Gl(o),additionalData:$i.encode(r)},s,Gl(u));return{iv:Vt.enc(o),ct:Vt.enc(d)}}async function id(s,u,r){const o=await Sa.decrypt({name:"AES-GCM",iv:Gl(Vt.dec(u.iv)),additionalData:$i.encode(r)},s,Gl(Vt.dec(u.ct)));return new Uint8Array(o)}const Jf="ABCDEFGHJKLMNPQRSTUVWXYZ23456789";function R1(){const s=El(16);let u=0,r=0,o="";for(const d of s)for(r=r<<8|d,u+=8;u>=5;)o+=Jf[r>>>u-5&31],u-=5;return u>0&&(o+=Jf[r<<5-u&31]),o.match(/.{1,5}/g).join("-")}const sd=s=>s.toUpperCase().replace(/[^A-Z2-9]/g,"");function $f(s){const u=sd(s);return u.length===26&&[...u].every(r=>Jf.includes(r))}const ud=s=>`${s}-${Tl.enc(El(6))}`,Ey=()=>({name:"PBKDF2",hash:"SHA-256",iterations:k1,salt:Vt.enc(El(16))});async function Ny(s,u,r){const o={type:"passkey",id:ud("pk"),label:r,credentialId:u.credentialId,transports:u.transports,publicKey:u.publicKey,alg:u.alg,signCount:0,prfSalt:ad,hkdfSalt:Vt.enc(El(16)),wrapped:{iv:"",ct:""},createdAt:new Date().toISOString()};return o.wrapped=await tu(await Ty(u.prf,o),s,o.id),o}async function cd(s,u){const r={type:"password",id:ud("pw"),label:"Backup passphrase",kdf:Ey(),wrapped:{iv:"",ct:""},createdAt:new Date().toISOString()};return r.wrapped=await tu(await nr(u,r.kdf),s,r.id),r}async function D1(s){const u=El(32),r=await Sa.importKey("raw",Gl(u),"AES-GCM",!1,["encrypt"]),o=new Date().toISOString(),d=[await Ny(u,s,s.label)];s.passphrase&&d.push(await cd(u,s.passphrase));const m=R1(),p={type:"recovery",id:ud("rc"),label:"Recovery code",kdf:Ey(),wrapped:{iv:"",ct:""},createdAt:o};p.wrapped=await tu(await nr(sd(m),p.kdf),u,p.id),d.push(p);const E={};for(const[b,v]of Object.entries(s.items))v&&(E[b]=await tu(r,$i.encode(v),b));const y={version:1,createdAt:o,methods:d,verifier:await tu(r,$i.encode(O1),"verifier"),items:E},R=Vt.enc(u);return u.fill(0),{doc:y,dek:R,recoveryCode:m}}async function _y(s,u,r){const o=await Ty(u,s,r);return Vt.enc(await id(o,s.wrapped,s.id))}async function wy(s,u){const r=await nr(u,s.kdf);return Vt.enc(await id(r,s.wrapped,s.id))}async function jy(s,u){const r=await nr(sd(u),s.kdf);return Vt.enc(await id(r,s.wrapped,s.id))}class Xl extends Error{constructor(u){super(u),this.name="PrfUnsupportedError"}}class rd extends Error{constructor(){super("Passkey prompt cancelled or timed out."),this.name="PasskeyCancelledError"}}const Ii=()=>typeof window<"u"&&!!window.PublicKeyCredential&&!!navigator.credentials,z1=new TextEncoder;function Zc(){const s=location.hostname;if(/^\d{1,3}(\.\d{1,3}){3}$/.test(s)||s.startsWith("["))throw new Xl(`Passkeys can't be bound to an IP address (${s}). Open the app via http://localhost:${location.port||80} or a hostname.`);return s}function Ay(s){const u=s;return(u==null?void 0:u.name)==="NotAllowedError"?new rd:(u==null?void 0:u.name)==="OperationError"?new Xl("Another passkey request is pending in this tab. Close any stray OS dialog or reload, then try again."):(u==null?void 0:u.name)==="SecurityError"?new Xl(`The browser refused the passkey request (SecurityError: ${u.message}). Passkeys need https or localhost, and a relying-party name equal to the page's host (${location.hostname}).`):(u==null?void 0:u.name)==="NotSupportedError"||(u==null?void 0:u.name)==="ConstraintError"?new Xl(`The authenticator can't do this (${u.name}: ${u.message}).`):u instanceof Error?new Error(`${u.name??"Error"}: ${u.message}`):new Error(String(s))}const ky=s=>({prf:{eval:{first:z1.encode(s)}}});async function Cy(s,u){var R,b,v,S;if(!Ii())throw new Xl("This browser has no passkey support.");let r;try{r=await navigator.credentials.create({publicKey:{rp:{id:Zc(),name:"BugXHunter"},user:{id:El(16),name:s,displayName:"BugXHunter vault"},challenge:El(32),pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-8},{type:"public-key",alg:-257}],authenticatorSelection:{residentKey:"preferred",userVerification:"required"},timeout:12e4,extensions:ky(u)}})}catch(L){throw Ay(L)}if(!r)throw new rd;const o=r.getClientExtensionResults();if(!((R=o.prf)!=null&&R.enabled))throw new Xl("This passkey can't derive keys (no PRF support). Use a platform passkey (Windows Hello, Touch ID, Android) or a recent security key, in Chrome, Edge or Safari 18+.");const d=r.response,m=(b=d.getPublicKey)==null?void 0:b.call(d);if(!m)throw new Xl("This browser doesn't expose the passkey's public key (needed for sign-in). Use Chrome, Edge or Safari.");const p=((v=d.getTransports)==null?void 0:v.call(d))??void 0,E=Tl.enc(new Uint8Array(r.rawId)),y=(S=o.prf.results)!=null&&S.first?new Uint8Array(o.prf.results.first):(await od({challenge:Tl.enc(El(32)),rpId:Zc(),allowCredentials:[{id:E,transports:p}]},u)).prf;return{credentialId:E,transports:p,prf:y,publicKey:Vt.enc(m),alg:d.getPublicKeyAlgorithm()}}async function od(s,u){var p,E;if(!Ii())throw new Xl("This browser has no passkey support.");const r=Zc();s.rpId&&s.rpId!==r&&console.warn(`[vault] server suggested rpId ${s.rpId}; using the page's host ${r}`);let o;try{o=await navigator.credentials.get({publicKey:{rpId:r,challenge:Tl.dec(s.challenge),allowCredentials:s.allowCredentials.map(y=>({type:"public-key",id:Tl.dec(y.id),transports:y.transports})),userVerification:"required",timeout:12e4,extensions:ky(u)}})}catch(y){throw Ay(y)}if(!o)throw new rd;const d=o.response,m=o.getClientExtensionResults();return{assertion:{credentialId:Tl.enc(new Uint8Array(o.rawId)),clientDataJSON:Tl.enc(new Uint8Array(d.clientDataJSON)),authenticatorData:Tl.enc(new Uint8Array(d.authenticatorData)),signature:Tl.enc(new Uint8Array(d.signature))},prf:(E=(p=m.prf)==null?void 0:p.results)!=null&&E.first?new Uint8Array(m.prf.results.first):void 0}}async function M1(s,u,r){const{prf:o}=await od({challenge:Tl.enc(El(32)),rpId:Zc(),allowCredentials:[{id:s,transports:u}]},r);if(!o)throw new Xl("The authenticator returned no PRF output. Use a passkey that supports PRF, or your recovery code.");return o}let fd=null;const Vc=s=>{fd=s},dd=()=>{fd=null},U1=()=>fd,If="or:unauthorized";async function L1(){dd(),await A1().catch(()=>{}),window.location.reload()}function H1({children:s}){const[u,r]=k.useState("checking");return k.useEffect(()=>{N1().then(d=>r(d.required?d.authenticated?"signed-in":"signed-out":"open")).catch(()=>r("open"));const o=()=>r("signed-out");return window.addEventListener(If,o),()=>window.removeEventListener(If,o)},[]),u==="checking"?null:u==="signed-out"?c.jsx(B1,{onSuccess:()=>r("signed-in")}):c.jsx(c.Fragment,{children:s})}function B1({onSuccess:s}){const[u,r]=k.useState("passkey"),[o,d]=k.useState(""),[m,p]=k.useState(""),[E,y]=k.useState(""),[R,b]=k.useState(!1),[v,S]=k.useState(!1),[L,B]=k.useState(!1),[ee,q]=k.useState(null),[ne,be]=k.useState(null);k.useEffect(()=>{Uf().then(({methods:I})=>{b(I.some(K=>K.type==="passkey"&&!!K.passphrase)),S(I.some(K=>K.type==="password"))}).catch(()=>{})},[]);async function fe(){var I;B(!0),q(null),be(null);try{const K=await _1();if("open"in K)return s();const{methods:oe}=await Uf(),re=oe.filter(Ge=>Ge.type==="passkey"),Ne=((I=re[0])==null?void 0:I.prfSalt)??"bugxhunter-vault-prf-v1",{assertion:ce,prf:J}=await od(K,Ne);await w1(ce);const _e=re.find(Ge=>Ge.credentialId===ce.credentialId);if(_e&&J)try{const Ge=await _y(_e,J,_e.passphrase?o:void 0);await xy(Ge),Vc(Ge)}catch{be(_e.passphrase?"Signed in; the vault stays locked (passphrase?) — unlock it from the sidebar.":"Signed in, but the vault didn't unlock — unlock it from the sidebar.")}s()}catch(K){q(K.message),B(!1)}}async function F(I){B(!0),q(null);try{const{methods:K}=await Uf();let oe;try{if(I==="password"){const re=K.find(Ne=>Ne.type==="password");if(!re)throw new Error("no method");oe=await wy(re,m)}else{const re=K.find(Ne=>Ne.type==="recovery");if(!re)throw new Error("no method");oe=await jy(re,E)}}catch{throw new Error(I==="password"?"Wrong backup passphrase.":"That recovery code doesn't open the vault.")}await j1(oe),Vc(oe),s()}catch(K){q(K.message),B(!1)}}const P=()=>{u==="passkey"?fe():u==="password"?F("password"):u==="recovery"&&F("recovery")};return c.jsx("div",{className:"login-page grid-bg",children:c.jsxs("form",{className:"login-card",onSubmit:I=>{I.preventDefault(),P()},children:[c.jsx(ld,{title:"bugxhunter@redteam: ~/login"}),c.jsxs("div",{className:"login-body",children:[c.jsx("span",{className:"logo login-mark",style:{fontSize:34},"aria-label":"BugXHunter",children:c.jsx(yy,{cursor:!0})}),c.jsx("div",{className:"login-tag",children:"Open-source AI security testing"}),u==="passkey"&&c.jsxs(c.Fragment,{children:[R&&c.jsxs(c.Fragment,{children:[c.jsxs("label",{htmlFor:"pp",children:["vault passphrase ",c.jsx("span",{className:"muted",children:"(this passkey was enrolled with one)"})]}),c.jsx("input",{id:"pp",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,onChange:I=>d(I.target.value)})]}),!Ii()&&c.jsx("div",{className:"form-status error",children:"This browser has no passkey support. Use Chrome, Edge or Safari, or a backup."}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",type:"submit",autoFocus:!R,disabled:L||!Ii(),children:L?"waiting for the passkey…":"./sign_in --passkey →"})}),c.jsxs("div",{className:"login-links",children:[v&&c.jsx("button",{type:"button",className:"link-btn",disabled:L,onClick:()=>{r("password"),q(null)},children:"use the backup passphrase"}),c.jsx("button",{type:"button",className:"link-btn",disabled:L,onClick:()=>{r("recovery"),q(null)},children:"use the recovery code"})]})]}),u==="password"&&c.jsxs(c.Fragment,{children:[c.jsx("label",{htmlFor:"bp",children:"backup passphrase"}),c.jsx("input",{id:"bp",type:"password",autoFocus:!0,autoComplete:"current-password",value:m,onChange:I=>p(I.target.value)}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",type:"submit",disabled:L||!m,children:L?"checking…":"./sign_in --passphrase →"})}),c.jsxs("div",{className:"login-links",children:[c.jsx("button",{type:"button",className:"link-btn",disabled:L,onClick:()=>{r("passkey"),q(null)},children:"back to the passkey"}),c.jsx("button",{type:"button",className:"link-btn",disabled:L,onClick:()=>{r("recovery"),q(null)},children:"use the recovery code"})]})]}),u==="recovery"&&c.jsxs(c.Fragment,{children:[c.jsx("label",{htmlFor:"rc",children:"recovery code"}),c.jsx("input",{id:"rc",type:"text",className:"mono",autoFocus:!0,autoComplete:"off",spellCheck:!1,placeholder:"XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-X",value:E,onChange:I=>y(I.target.value)}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",type:"submit",disabled:L||!$f(E),children:L?"checking…":"./sign_in --recovery →"})}),c.jsx("p",{className:"hint",style:{margin:0},children:"This signs you in and unlocks the vault. Enrol a new passkey right after, from the keys dialog."}),c.jsxs("div",{className:"login-links",children:[c.jsx("button",{type:"button",className:"link-btn",disabled:L,onClick:()=>{r("passkey"),q(null)},children:"back to the passkey"}),c.jsx("button",{type:"button",className:"link-btn",disabled:L,onClick:()=>{r("lost"),q(null)},children:"lost that too?"})]})]}),u==="lost"&&c.jsxs(c.Fragment,{children:[c.jsx("p",{className:"hint",style:{margin:0},children:"Without the passkey, the backup passphrase or the recovery code the vault's secrets can't be recovered — by design, and by anyone. Someone with access to the server's files can reset it, which deletes the vault and reopens the app for a fresh setup:"}),c.jsx("pre",{className:"tool-output",style:{borderTop:"1px solid var(--border)"},children:`npm run vault:reset
|
|
52
52
|
# Docker:
|
|
53
|
-
docker compose exec runner rm /data/vault.json`}),c.jsx("p",{className:"hint",style:{margin:0},children:"Nothing on the network can do this, which is what keeps the lock meaningful."}),c.jsx("button",{type:"button",className:"link-btn",onClick:()=>{r("passkey"),q(null)},children:"back"})]}),ne&&c.jsx("div",{className:"form-status success",children:ne}),ee&&c.jsx("div",{className:"form-status error",children:ee})]})]})})}function lr({title:s,onClose:u,children:r}){return k.useEffect(()=>{if(!u)return;const o=d=>d.key==="Escape"&&u();return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[u]),c.jsx("div",{className:"overlay vault-dialog",onClick:u,children:c.jsxs("div",{className:"modal",role:"dialog","aria-label":s,onClick:o=>o.stopPropagation(),children:[c.jsxs("div",{className:"modal-head",children:[c.jsxs("span",{className:"modal-title",children:[c.jsx("span",{className:"dot y","aria-hidden":!0}),s]}),u&&c.jsx("button",{className:"icon-btn close-x",onClick:u,"aria-label":"Close",title:"Close (Esc)",children:"✕"})]}),c.jsx("div",{className:"modal-body",children:r})]})})}const nu=10,Kc=()=>`BugXHunter vault (${location.hostname})`,Lf="__custom__",Vi=[{name:"SCX_API",short:"SCX.ai — the default provider",label:"SCX.ai model key — the default provider"},{name:"OPENROUTER_API_KEY",short:"OpenRouter — one key, its whole catalogue",label:"OpenRouter key — unlocks its model catalogue (optional)"}],q1={SCX_API:"sk-scx-…",OPENROUTER_API_KEY:"sk-or-…"};function X1(){const[s,u]=k.useState(null),[r,o]=k.useState(null),[d,m]=k.useState(Date.now()),p=k.useCallback(()=>y1().then(u).catch(()=>{}),[]);k.useEffect(()=>{p();const b=setInterval(()=>{p(),m(Date.now())},3e4);return()=>clearInterval(b)},[p]);const E=()=>{o(null),p()},y=k.useCallback(()=>{dd(),b1().then(u).catch(()=>{})},[]);if(k.useEffect(()=>{const b=v=>{(v.ctrlKey||v.metaKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),y())};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[y]),!s)return null;const R=s.initialised?s.unsealed?c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"vault-state open",title:s.idleMinutes?`Auto-locks after ${s.idleMinutes} min without activity`:"Auto-lock off",children:["vault open",s.sealsAt?` · locks in ${Z1(s.sealsAt-d)}`:""]}),c.jsx("button",{className:"icon-btn vault-btn",onClick:()=>o("manage"),title:"Keys in the vault","aria-label":"Keys in the vault",children:c.jsx(Y1,{})}),c.jsx("button",{className:"icon-btn vault-btn",onClick:y,title:"Lock the vault (Ctrl+Shift+L)","aria-label":"Lock the vault (Ctrl+Shift+L)",children:c.jsx(Q1,{})})]}):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"vault-state sealed",children:"vault locked"}),c.jsx("button",{className:"icon-btn vault-btn primary",onClick:()=>o("unlock"),title:"Unlock the vault","aria-label":"Unlock the vault",children:c.jsx(G1,{})})]}):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"vault-state none",title:s.keySource==="none"?"No model key yet":`Model key comes from ${s.keySource==="env"?".env":"OpenCode's auth.json"}, in the clear`,children:s.keySource==="none"?"no vault, no model key":"vault not set up"}),c.jsx("button",{className:"btn primary sm",onClick:()=>o("setup"),children:"set_up"})]});return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"vault-row",children:R}),r==="setup"&&c.jsx(V1,{onClose:E}),r==="unlock"&&c.jsx(K1,{status:s,onClose:E}),r==="manage"&&c.jsx(J1,{status:s,onChange:u,onClose:E})]})}const G1=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[c.jsx("circle",{cx:"12",cy:"16",r:"1"}),c.jsx("rect",{width:"18",height:"12",x:"3",y:"10",rx:"2"}),c.jsx("path",{d:"M7 10V7a5 5 0 0 1 9.33-2.5"})]}),Y1=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[c.jsx("path",{d:"M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z"}),c.jsx("path",{d:"m14 7 3 3"}),c.jsx("path",{d:"m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814"})]}),Q1=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[c.jsx("path",{d:"M12 13v3"}),c.jsx("path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 01-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 011-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 011.52 0C14.51 3.81 17 5 19 5a1 1 0 011 1z"}),c.jsx("circle",{cx:"12",cy:"11",r:"2"})]});function Z1(s){const u=Math.max(0,Math.round(s/6e4));return u>=60?`${Math.floor(u/60)}h ${String(u%60).padStart(2,"0")}m`:`${u}m`}const Hf=["passkey","key","backups"];function V1({onClose:s}){const[u,r]=k.useState("passkey"),[o,d]=k.useState(null),[m,p]=k.useState("SCX_API"),[E,y]=k.useState(""),[R,b]=k.useState(""),[v,S]=k.useState(""),[L,B]=k.useState(null),[ee,q]=k.useState(!1),[ne,be]=k.useState(!1),[fe,F]=k.useState(!1),[P,I]=k.useState(null);async function K(){F(!0),I(null);try{d(await Cy(Kc(),ad)),r("key")}catch(ce){I(ce.message)}finally{F(!1)}}async function oe(){if(o){F(!0),I(null);try{B(await D1({...o,label:Kc(),items:E.trim()?{[m]:E.trim()}:{}})),r("backups")}catch(ce){I(ce.message)}finally{F(!1)}}}async function re(){if(L){F(!0),I(null);try{let ce=L.doc;R&&(ce={...ce,methods:[...ce.methods,await cd(Vt.dec(L.dek),R)]}),await v1(ce,L.dek),Vc(L.dek),s()}catch(ce){I(ce.message),F(!1)}}}const Ne=!R||R.length>=nu&&R===v;return c.jsxs(lr,{title:"vault --init",onClose:u==="backups"?void 0:s,children:[c.jsx("div",{className:"steps",children:Hf.map(ce=>c.jsx("span",{className:ce===u?"on":Hf.indexOf(ce)<Hf.indexOf(u)?"done":"",children:ce},ce))}),u==="passkey"&&c.jsxs(c.Fragment,{children:[c.jsx("p",{children:"Your model keys will be sealed at rest, and this passkey will unlock them and sign you in — one touch. The authenticator (Windows Hello, Touch ID, Android, or a security key) derives a secret that never leaves it. Works in Chrome, Edge and Safari 18+; Firefox can't do this yet."}),!Ii()&&c.jsx("div",{className:"form-status error",children:"This browser has no passkey support."}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:fe||!Ii(),onClick:K,children:fe?"waiting for the authenticator…":"create passkey →"})})]}),u==="key"&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["Passkey enrolled. Add a model key now, or later from the keys dialog (where you can add the other provider too). It goes straight into the sealed vault; ",c.jsx("code",{className:"mono",children:".env"})," can then drop the key."]}),c.jsx("label",{htmlFor:"v-provider",children:"Provider"}),c.jsx("select",{id:"v-provider",className:"mono",value:m,onChange:ce=>p(ce.target.value),children:Vi.map(ce=>c.jsx("option",{value:ce.name,children:ce.short},ce.name))}),c.jsxs("label",{htmlFor:"v-key",children:[m," (optional)"]}),c.jsx("input",{id:"v-key",type:"password",autoFocus:!0,autoComplete:"off",placeholder:q1[m]??"",value:E,onChange:ce=>y(ce.target.value)}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:fe,onClick:oe,children:fe?"sealing…":"next →"})})]}),u==="backups"&&L&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["Backups, for when the passkey isn't at hand. This recovery code is shown ",c.jsx("b",{children:"once"})," and stored nowhere — keep it offline, like a password-manager note or paper."]}),c.jsxs("button",{type:"button",className:"recovery-code"+(ne?" copied":""),"aria-label":"Recovery code — click to copy",title:"Click to copy",onClick:()=>{var ce;(ce=navigator.clipboard)==null||ce.writeText(L.recoveryCode).then(()=>{be(!0),setTimeout(()=>be(!1),2e3)}).catch(()=>{})},children:[c.jsx("span",{className:"code",children:L.recoveryCode}),c.jsx("span",{className:"copy-hint",children:ne?"✓ copied":"click to copy"})]}),c.jsxs("label",{className:"check",children:[c.jsx("input",{type:"checkbox",checked:ee,onChange:ce=>q(ce.target.checked)})," I have stored this code somewhere safe."]}),c.jsxs("label",{htmlFor:"v-pass",children:["Backup passphrase (optional, at least ",nu," characters)"]}),c.jsx("input",{id:"v-pass",type:"password",autoComplete:"new-password",value:R,onChange:ce=>b(ce.target.value)}),R&&c.jsxs(c.Fragment,{children:[c.jsx("label",{htmlFor:"v-pass2",children:"Again"}),c.jsx("input",{id:"v-pass2",type:"password",autoComplete:"new-password",value:v,onChange:ce=>S(ce.target.value)}),v&&R!==v&&c.jsx("div",{className:"form-status error",children:"The passphrases differ."})]}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:!ee||!Ne||fe,onClick:re,children:fe?"creating…":"create vault →"})})]}),P&&c.jsx("div",{className:"form-status error",children:P})]})}function K1({status:s,onClose:u}){const[r,o]=k.useState("passkey"),[d,m]=k.useState(""),[p,E]=k.useState(""),[y,R]=k.useState(!1),[b,v]=k.useState(null),S=s.methods.find(F=>F.type==="passkey"),L=s.methods.find(F=>F.type==="password"),B=s.methods.find(F=>F.type==="recovery"),ee=!!(S!=null&&S.passphrase);async function q(F,P){R(!0),v(null);try{let I;try{I=await F()}catch(K){throw K instanceof Error&&/Passkey|authenticator|pending|origin/i.test(K.message)?K:new Error(P)}await xy(I),Vc(I),u()}catch(I){v(I.message),R(!1)}}const ne=()=>S&&q(async()=>{const F=await M1(S.credentialId,S.transports,S.prfSalt);return _y(S,F,ee?d:void 0)},ee?"Wrong passphrase, or a different passkey than the one enrolled.":"A different passkey than the one enrolled."),be=()=>L&&q(()=>wy(L,d),"Wrong backup passphrase."),fe=()=>B&&q(()=>jy(B,p),"That recovery code doesn't open the vault.");return c.jsxs(lr,{title:"vault --unlock",onClose:u,children:[r==="passkey"&&c.jsxs(c.Fragment,{children:[c.jsx("p",{children:ee?"This passkey was enrolled with a passphrase: enter it, then confirm with the passkey.":"One touch: confirm with your passkey."}),ee&&c.jsxs(c.Fragment,{children:[c.jsx("label",{htmlFor:"v-unlock-pass",children:"Passphrase"}),c.jsx("input",{id:"v-unlock-pass",type:"password",autoFocus:!0,autoComplete:"current-password",value:d,onChange:F=>m(F.target.value),onKeyDown:F=>{F.key==="Enter"&&d&&ne()}})]}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",autoFocus:!ee,disabled:y||!S||ee&&!d,onClick:ne,children:y?"waiting for the authenticator…":"unlock with passkey →"})}),c.jsxs("div",{className:"login-links",children:[L&&c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("password"),v(null)},children:"use the backup passphrase"}),B&&c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("recovery"),v(null)},children:"use the recovery code"})]})]}),r==="password"&&c.jsxs(c.Fragment,{children:[c.jsx("label",{htmlFor:"v-unlock-pw",children:"Backup passphrase"}),c.jsx("input",{id:"v-unlock-pw",type:"password",autoFocus:!0,autoComplete:"current-password",value:d,onChange:F=>m(F.target.value),onKeyDown:F=>{F.key==="Enter"&&d&&be()}}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:y||!d,onClick:be,children:y?"unlocking…":"unlock →"})}),c.jsxs("div",{className:"login-links",children:[c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("passkey"),v(null)},children:"use the passkey instead"}),B&&c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("recovery"),v(null)},children:"use the recovery code"})]})]}),r==="recovery"&&c.jsxs(c.Fragment,{children:[c.jsx("p",{children:"Enter the recovery code shown when the vault was created."}),c.jsx("label",{htmlFor:"v-code",children:"Recovery code"}),c.jsx("input",{id:"v-code",type:"text",className:"mono",autoFocus:!0,autoComplete:"off",spellCheck:!1,placeholder:"XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-X",value:p,onChange:F=>E(F.target.value),onKeyDown:F=>{F.key==="Enter"&&$f(p)&&fe()}}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:y||!$f(p),onClick:fe,children:y?"unlocking…":"unlock →"})}),c.jsxs("div",{className:"login-links",children:[c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("passkey"),v(null)},children:"use the passkey instead"}),L&&c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("password"),v(null)},children:"use the backup passphrase"})]})]}),b&&c.jsx("div",{className:"form-status error",children:b})]})}function J1({status:s,onChange:u,onClose:r}){const[o,d]=k.useState("SCX_API"),[m,p]=k.useState(""),[E,y]=k.useState(""),[R,b]=k.useState(!1),[v,S]=k.useState(""),[L,B]=k.useState(!1),[ee,q]=k.useState(null),ne=U1(),be=s.methods.filter(J=>J.type==="passkey"),fe=s.methods.find(J=>J.type==="password");async function F(J){B(!0),q(null);try{const _e=await J();_e&&u(_e)}catch(_e){q(_e.message)}finally{B(!1)}}const P=()=>{if(!ne)throw new Error("Unlock the vault in this tab first (the change must wrap the current key).");return Vt.dec(ne)},I=()=>F(async()=>{const J=await x1(o.trim().toUpperCase(),m);return p(""),J}),K=J=>F(()=>S1(J)),oe=J=>F(()=>T1(J)),re=()=>F(async()=>{const J=P(),_e=await Ny(J,await Cy(Kc(),ad),Kc());return Ug(_e,ne)}),Ne=()=>F(async()=>{const J=P(),_e=await Ug(await cd(J,E),ne);return b(!1),y(""),_e}),ce=()=>F(async()=>{P();const J=await E1(ne);return dd(),r(),J});return c.jsxs(lr,{title:"vault --keys",onClose:r,children:[c.jsx("p",{children:"Secrets sealed in the vault. Values are never shown again; replace one by saving it under the same name."}),c.jsxs("div",{className:"vault-items",children:[Vi.map(J=>{const _e=s.items.includes(J.name);return c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:_e?"ok":"missing","aria-hidden":!0,children:_e?"✓":"○"}),c.jsxs("span",{className:"name",children:[J.name,c.jsxs("span",{className:"desc",children:[" — ",J.label]})]}),_e?c.jsx("button",{className:"btn danger",disabled:L,onClick:()=>K(J.name),title:"Remove",children:"✕"}):c.jsx("button",{className:"btn sm",disabled:L,onClick:()=>{d(J.name),setTimeout(()=>{var Ge;return(Ge=document.getElementById("v-value"))==null?void 0:Ge.focus()},0)},children:"add"})]},J.name)}),s.items.filter(J=>!Vi.some(_e=>_e.name===J)).map(J=>c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:"ok","aria-hidden":!0,children:"✓"}),c.jsx("span",{className:"name",children:J}),c.jsx("button",{className:"btn danger",disabled:L,onClick:()=>K(J),title:"Remove",children:"✕"})]},J))]}),c.jsx("label",{htmlFor:"v-name",children:"Key"}),c.jsxs("select",{id:"v-name",className:"mono",value:Vi.some(J=>J.name===o)?o:Lf,onChange:J=>d(J.target.value===Lf?"":J.target.value),children:[Vi.map(J=>c.jsxs("option",{value:J.name,children:[J.name,s.items.includes(J.name)?" (replace)":""]},J.name)),c.jsx("option",{value:Lf,children:"custom…"})]}),!Vi.some(J=>J.name===o)&&c.jsx("input",{type:"text",className:"mono",placeholder:"NAME_IN_UPPER_SNAKE_CASE","aria-label":"Custom key name",value:o,onChange:J=>d(J.target.value),spellCheck:!1,autoFocus:!0}),c.jsx("label",{htmlFor:"v-value",children:"Value"}),c.jsx("input",{id:"v-value",type:"password",autoComplete:"off",value:m,onChange:J=>p(J.target.value),onKeyDown:J=>{J.key==="Enter"&&m&&I()}}),c.jsxs("div",{className:"perm-actions",children:[c.jsx("button",{className:"btn primary sm",disabled:L||!m||!o.trim(),onClick:I,children:L?"sealing…":"save"}),c.jsx("span",{className:"hint",style:{margin:0},children:s.idleMinutes?`Auto-locks after ${s.idleMinutes} min idle.`:"Auto-lock is off."})]}),c.jsx("div",{className:"section-title",children:"passkeys"}),c.jsx("p",{children:"Each passkey unlocks the vault and signs you in with one touch. Keep two, on different devices, so losing one is not an emergency."}),c.jsx("div",{className:"vault-items",children:be.map(J=>c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:J.canLogin?"ok":"warn","aria-hidden":!0,children:J.canLogin?"✓":"!"}),c.jsxs("span",{className:"name",children:[J.label,J.passphrase?" — needs its passphrase (older enrolment)":"",J.canLogin?"":" — unlock only, can't sign in; add a new passkey"]}),c.jsx("button",{className:"btn danger",disabled:L||be.length<=1,onClick:()=>oe(J.id),title:be.length<=1?"Add another passkey first":"Remove",children:"✕"})]},J.id))}),c.jsx("div",{className:"perm-actions",children:c.jsx("button",{className:"btn sm",disabled:L||!ne,onClick:re,title:ne?"":"Unlock the vault in this tab first",children:L?"waiting for the authenticator…":"+ add passkey"})}),c.jsx("div",{className:"section-title",children:"backups"}),c.jsx("p",{children:"The recovery code from setup always works. A backup passphrase is optional: a way in on a device without the passkey."}),c.jsxs("div",{className:"vault-items",children:[c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:"ok","aria-hidden":!0,children:"✓"}),c.jsx("span",{className:"name",children:"Recovery code"})]}),fe&&c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:"ok","aria-hidden":!0,children:"✓"}),c.jsx("span",{className:"name",children:"Backup passphrase"}),c.jsx("button",{className:"btn danger",disabled:L,onClick:()=>oe(fe.id),title:"Remove",children:"✕"})]})]}),R?c.jsxs(c.Fragment,{children:[c.jsxs("label",{htmlFor:"v-newpass",children:[fe?"New backup passphrase":"Backup passphrase"," (at least ",nu," characters)"]}),c.jsx("input",{id:"v-newpass",type:"password",autoFocus:!0,autoComplete:"new-password",value:E,onChange:J=>y(J.target.value),onKeyDown:J=>{J.key==="Enter"&&E.length>=nu&&Ne()}}),c.jsxs("div",{className:"perm-actions",children:[c.jsx("button",{className:"btn primary sm",disabled:L||E.length<nu,onClick:Ne,children:L?"sealing…":"save"}),c.jsx("button",{className:"btn sm",disabled:L,onClick:()=>b(!1),children:"cancel"})]})]}):c.jsx("div",{className:"perm-actions",children:c.jsx("button",{className:"btn sm",disabled:L||!ne,onClick:()=>b(!0),title:ne?"":"Unlock the vault in this tab first",children:fe?"replace backup passphrase":"+ set a backup passphrase"})}),c.jsx("div",{className:"section-title",children:"danger zone"}),c.jsxs("p",{children:["Delete the vault to start over with new factors. Its secrets are gone; the app reopens without sign-in until a new vault exists. Lost every factor instead? Run ",c.jsx("code",{className:"mono",children:"npm run vault:reset"})," on the server."]}),c.jsxs("div",{className:"perm-actions",children:[c.jsx("input",{type:"text",className:"mono",placeholder:"type DELETE",value:v,onChange:J=>S(J.target.value),style:{width:160}}),c.jsx("button",{className:"btn danger-outline sm",disabled:L||v!=="DELETE"||!ne,onClick:ce,children:"delete vault"})]}),ee&&c.jsx("div",{className:"form-status error",children:ee})]})}function wn({size:s=14,children:u,className:r}){return c.jsx("svg",{className:r,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:u})}const hd=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}),c.jsx("path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}),c.jsx("path",{d:"M10 9H8"}),c.jsx("path",{d:"M16 13H8"}),c.jsx("path",{d:"M16 17H8"})]}),$1=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34"}),c.jsx("path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}),c.jsx("path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z"})]}),I1=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M12 19h8"}),c.jsx("path",{d:"m4 17 6-6-6-6"})]}),Lg=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"m21 21-4.34-4.34"}),c.jsx("circle",{cx:"11",cy:"11",r:"8"})]}),F1=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1"}),c.jsx("path",{d:"m21 21-1.9-1.9"}),c.jsx("circle",{cx:"17",cy:"17",r:"3"})]}),W1=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M3 5h.01"}),c.jsx("path",{d:"M3 12h.01"}),c.jsx("path",{d:"M3 19h.01"}),c.jsx("path",{d:"M8 5h13"}),c.jsx("path",{d:"M8 12h13"}),c.jsx("path",{d:"M8 19h13"})]}),P1=s=>c.jsxs(wn,{...s,children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),c.jsx("path",{d:"M2 12h20"})]}),ex=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M13 5h8"}),c.jsx("path",{d:"M13 12h8"}),c.jsx("path",{d:"M13 19h8"}),c.jsx("path",{d:"m3 17 2 2 4-4"}),c.jsx("path",{d:"m3 7 2 2 4-4"})]}),tx=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719"}),c.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),c.jsx("path",{d:"M12 17h.01"})]}),nx=s=>c.jsx(wn,{...s,children:c.jsx("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z"})}),lx=s=>c.jsxs(wn,{...s,children:[c.jsx("line",{x1:"6",x2:"6",y1:"3",y2:"15"}),c.jsx("circle",{cx:"18",cy:"6",r:"3"}),c.jsx("circle",{cx:"6",cy:"18",r:"3"}),c.jsx("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),Oy=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),c.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),ax=s=>c.jsx(wn,{...s,children:c.jsx("path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"})});function ix({tool:s,size:u=14}){switch(s){case"read":return c.jsx(hd,{size:u});case"write":case"edit":case"patch":case"apply_patch":return c.jsx($1,{size:u});case"bash":return c.jsx(I1,{size:u});case"grep":return c.jsx(Lg,{size:u});case"glob":case"list":return c.jsx(F1,{size:u});case"webfetch":return c.jsx(P1,{size:u});case"websearch":return c.jsx(Lg,{size:u});case"todowrite":case"todoread":return c.jsx(ex,{size:u});case"task":return c.jsx(W1,{size:u});case"question":return c.jsx(tx,{size:u});default:return c.jsx(nx,{size:u})}}async function ti(s,u){var o,d;const r=await fetch(s,{headers:{"Content-Type":"application/json"},...u});if(!r.ok){let m=`${r.status}`;try{m=((d=(o=await r.json())==null?void 0:o.error)==null?void 0:d.message)??m}catch{}throw new Error(m)}return r.json()}const sx=()=>ti("/api/github"),ux=()=>ti("/api/github/repos").then(s=>s.repos),cx=s=>ti(`/api/github/branches?repo=${encodeURIComponent(s)}`).then(u=>u.branches),rx=s=>ti("/api/github/clone",{method:"POST",body:JSON.stringify(s)}),ox=()=>ti("/api/github/connect/start",{method:"POST"}),fx=s=>ti("/api/github/connect/poll",{method:"POST",body:JSON.stringify({id:s})}),dx=()=>ti("/api/github/connect",{method:"DELETE"});function hx(s){if(!s)return"";const u=Math.max(0,(Date.now()-new Date(s).getTime())/1e3);return u<3600?`${Math.max(1,Math.round(u/60))} min ago`:u<86400?`${Math.round(u/3600)} h ago`:u<86400*30?`${Math.round(u/86400)} d ago`:u<86400*365?`${Math.round(u/(86400*30))} mo ago`:`${Math.round(u/(86400*365))} y ago`}function mx({onOpen:s,onClose:u}){const[r,o]=k.useState(null),[d,m]=k.useState(null),[p,E]=k.useState(null),[y,R]=k.useState(""),[b,v]=k.useState(null),[S,L]=k.useState(null),[B,ee]=k.useState(""),[q,ne]=k.useState(null),[be,fe]=k.useState(null),[F,P]=k.useState(null),[I,K]=k.useState(!1),oe=k.useCallback(()=>sx().then(Z=>{o(Z),m(null)}).catch(Z=>m(Z.message)),[]);k.useEffect(()=>{oe()},[oe]);const re=!!(r!=null&&r.connected&&!r.sealed&&!r.error),Ne=k.useCallback(()=>{ne("repos"),ux().then(E).catch(Z=>fe(Z.message)).finally(()=>ne(Z=>Z==="repos"?null:Z))},[]);k.useEffect(()=>{re&&Ne()},[re,Ne]),k.useEffect(()=>{if(!re)return;const Z=()=>Ne();return window.addEventListener("focus",Z),()=>window.removeEventListener("focus",Z)},[re,Ne]);const ce=k.useRef(null),J=()=>{ce.current&&(window.clearTimeout(ce.current),ce.current=null)};k.useEffect(()=>J,[]);async function _e(){ne("connect"),fe(null);try{const Z=await ox();P(Z);try{await navigator.clipboard.writeText(Z.userCode),K(!0)}catch{K(!1)}const ve=async()=>{try{const Ke=await fx(Z.id);if(Ke.status==="pending"){ce.current=window.setTimeout(ve,Z.interval*1e3);return}if(P(null),ne(null),Ke.status==="connected"){await oe();return}fe(Ke.status==="denied"?"The sign-in was cancelled on GitHub.":"The code expired. Start again.")}catch(Ke){P(null),ne(null),fe(Ke.message)}};ce.current=window.setTimeout(ve,Z.interval*1e3)}catch(Z){ne(null),fe(Z.message)}}function Ge(){J(),P(null),ne(null)}async function Me(){fe(null);try{await dx(),E(null),v(null),await oe()}catch(Z){fe(Z.message)}}function te(Z){v(Z),ee(Z.defaultBranch),L(null),fe(null),ne("branches"),cx(Z.fullName).then(ve=>{L(ve),!ve.some(Ke=>Ke.name===Z.defaultBranch)&&ve[0]&&ee(ve[0].name)}).catch(ve=>fe(ve.message)).finally(()=>ne(ve=>ve==="branches"?null:ve))}async function me(){if(b){ne("clone"),fe(null);try{const Z=await rx({repo:b.fullName,branch:B});s(Z.directory),u()}catch(Z){fe(Z.message)}finally{ne(null)}}}const pe=k.useMemo(()=>{const Z=y.trim().toLowerCase();return(p??[]).filter(ve=>!Z||ve.fullName.toLowerCase().includes(Z)||(ve.description??"").toLowerCase().includes(Z))},[p,y]);return c.jsxs(lr,{title:"github --clone",onClose:u,children:[d&&c.jsx("div",{className:"hint danger",children:d}),r&&!r.connected&&!F&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["Clone a repository into the workspace so the agent can review it. ",c.jsx("b",{children:"Read-only"}),": the app can only read code, it reaches only the repositories you install it on, and nothing in the sandbox can push."]}),c.jsx("div",{className:"perm-actions center",children:c.jsxs("button",{className:"btn primary wide",disabled:q!==null,onClick:_e,children:[c.jsx(Oy,{size:15})," ",q==="connect"?"contacting GitHub…":"Connect GitHub"]})}),r.storage==="memory"&&c.jsx("div",{className:"hint",style:{textAlign:"center"},children:"No vault yet, so the sign-in is kept until the runner restarts. Set up the vault to keep it."})]}),F&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["Enter this code on GitHub to connect. ",I?"It is on your clipboard.":"Click it to copy."]}),c.jsx("button",{className:"recovery-code gh-code",onClick:()=>navigator.clipboard.writeText(F.userCode).then(()=>K(!0)).catch(()=>{}),title:"Copy",children:F.userCode}),c.jsx("div",{className:"perm-actions center",children:c.jsx("a",{className:"btn primary wide",href:F.verificationUri,target:"_blank",rel:"noreferrer",children:"Open github.com/login/device ↗"})}),c.jsxs("div",{className:"hint",style:{textAlign:"center"},children:["Waiting for your approval… this finishes by itself. ",c.jsx("button",{className:"link-btn",onClick:Ge,children:"cancel"})]})]}),(r==null?void 0:r.sealed)&&c.jsx("p",{children:"Your GitHub sign-in is in the vault, which is locked. Unlock it (the lock icon below) and reopen this dialog."}),(r==null?void 0:r.error)&&c.jsx("div",{className:"hint danger",children:r.error}),re&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"gh-head",children:[c.jsxs("span",{children:["connected as ",c.jsx("b",{children:r.login}),r.storage==="memory"?" · until restart (no vault yet)":""," · ",c.jsx("button",{className:"link-btn",onClick:Me,children:"disconnect"})]}),c.jsx("a",{href:r.installUrl,target:"_blank",rel:"noreferrer",children:"choose repositories on GitHub ↗"})]}),r.clones.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"section-title",children:"in the workspace"}),c.jsx("div",{className:"vault-items",children:r.clones.map(Z=>c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:"ok","aria-hidden":!0,children:"✓"}),c.jsxs("span",{className:"name",title:Z.directory,children:[Z.fullName,c.jsxs("span",{className:"desc",children:[" — ",Z.branch??"detached"]})]}),c.jsx("button",{className:"btn sm",onClick:()=>{s(Z.directory),u()},children:"open"})]},Z.directory))})]}),p&&p.length===0?c.jsxs("div",{className:"gh-callout",children:[c.jsx("b",{children:"One more step."})," Signing in says who you are; which repositories BugXHunter may read is chosen separately, on GitHub's install screen. An organisation's owner may have to approve it. This list refreshes when you come back.",c.jsx("div",{className:"perm-actions center",children:c.jsx("a",{className:"btn primary wide",href:r.installUrl,target:"_blank",rel:"noreferrer",children:"Choose repositories on GitHub ↗"})})]}):c.jsxs(c.Fragment,{children:[c.jsx("input",{type:"text",className:"mono",placeholder:"filter repositories…",value:y,onChange:Z=>R(Z.target.value),spellCheck:!1,autoFocus:!0}),c.jsxs("div",{className:"gh-list",role:"listbox","aria-label":"Repositories",children:[q==="repos"&&!p&&c.jsx("div",{className:"hint",children:"loading…"}),p&&p.length>0&&pe.length===0&&c.jsx("div",{className:"hint",children:"Nothing matches."}),pe.map(Z=>c.jsxs("button",{className:`gh-repo${(b==null?void 0:b.fullName)===Z.fullName?" selected":""}`,role:"option","aria-selected":(b==null?void 0:b.fullName)===Z.fullName,onClick:()=>te(Z),children:[c.jsxs("span",{className:"gh-name",children:[Z.fullName,Z.private&&c.jsx("span",{className:"badge",children:"private"}),Z.archived&&c.jsx("span",{className:"badge",children:"archived"}),Z.directory&&c.jsx("span",{className:"badge on",children:"in workspace"})]}),Z.description&&c.jsx("span",{className:"gh-desc",children:Z.description}),c.jsxs("span",{className:"gh-meta",children:[c.jsx(lx,{size:11})," ",Z.defaultBranch,Z.pushedAt?` · pushed ${hx(Z.pushedAt)}`:""]})]},Z.fullName))]})]}),b&&c.jsxs("div",{className:"gh-clone",children:[c.jsx("label",{htmlFor:"gh-branch",children:"Branch"}),c.jsx("select",{id:"gh-branch",className:"mono",value:B,onChange:Z=>ee(Z.target.value),disabled:!S,children:(S??[{name:B,isDefault:!0}]).map(Z=>c.jsxs("option",{value:Z.name,children:[Z.name,Z.isDefault?" (default)":""]},Z.name))}),c.jsx("button",{className:"btn primary sm",disabled:q!==null||!B,onClick:me,children:q==="clone"?b.directory?"updating…":"cloning…":b.directory?"update & open":"clone & open"})]}),b&&c.jsxs("div",{className:"hint",children:["Lands in ",c.jsxs("span",{className:"mono",children:[r.cloneRoot,"/",b.fullName]}),". An existing clone is fast-forwarded, never reset; the agent's local edits stay."]})]}),be&&c.jsx("div",{className:"hint danger",children:be})]})}const px={type:"function",function:{name:"get_weather",description:"Get the current weather for a city",parameters:{type:"object",properties:{city:{type:"string",description:"City name"}},required:["city"]}}};function gx({onCollapse:s,sessions:u,mode:r,setMode:o,runner:d,status:m,statusError:p,onOpenDirectory:E,config:y,setConfig:R,models:b,modelError:v,activeModel:S,onReset:L}){var Q;const B=(C,W)=>R(ie=>({...ie,[C]:W})),[ee,q]=k.useState(!1);k.useEffect(()=>{const C=()=>fetch("/api/auth/me").then(ie=>ie.json()).then(ie=>q(!!ie.required)).catch(()=>{});C();const W=setInterval(C,3e4);return()=>clearInterval(W)},[]);const[ne,be]=k.useState([]),[fe,F]=k.useState(""),[P,I]=k.useState(""),[K,oe]=k.useState(!1),[re,Ne]=k.useState(null),[ce,J]=k.useState(null);k.useEffect(()=>{Gb().then(be).catch(()=>{})},[]);async function _e(){if(P.trim()){oe(!0),Ne(null);try{const C=await Yb(fe.trim()||`Document ${ne.length+1}`,P);be(C),F(""),I(""),y.useKnowledge||B("useKnowledge",!0)}catch(C){Ne(String(C.message??C))}finally{oe(!1)}}}async function Ge(C){be(await Qb(C))}const Me=(S==null?void 0:S.supported_features)??[],te=Me.includes("tools"),me=Me.includes("json_mode"),pe=Me.includes("reasoning"),Z=b.filter(C=>C.output_modalities.includes("text")),ve=["scx","openrouter"].map(C=>[C,Z.filter(W=>(W.provider??"scx")===C)]).filter(([,C])=>C.length>0);function Ke(C,W){R(ie=>{const w=ie.tools.slice();return w[C]={...w[C],function:{...w[C].function,...W}},{...ie,tools:w}})}function at(C,W){try{const ie=JSON.parse(W);Ke(C,{parameters:ie})}catch{}}function Ot(C){if(!C)return null;const W=C.function??C;return W!=null&&W.name?{type:"function",id:Kf(),function:{name:W.name,description:W.description,parameters:W.parameters??W.schema}}:null}async function T(){J(null);try{const C=await fetch("/example-tools.json",{cache:"no-store"});if(!C.ok)throw new Error(`No example-tools.json yet (${C.status}) — add web/public/example-tools.json first.`);const W=await C.json(),ie=(Array.isArray(W)?W:W.tools??[]).map(Ot).filter(Boolean);if(!ie.length)throw new Error("File had no valid tools.");let w=0;R(Y=>{const le=new Set(Y.tools.map(je=>je.function.name)),Oe=ie.filter(je=>!le.has(je.function.name));return w=Oe.length,{...Y,tools:[...Y.tools,...Oe]}}),J(w?`Loaded ${w} tool${w>1?"s":""}.`:"Already loaded.")}catch(C){J(String(C.message??C))}}function z(){const C=new Blob([JSON.stringify(y,null,2)],{type:"application/json"}),W=URL.createObjectURL(C),ie=document.createElement("a");ie.href=W,ie.download=`${y.name.replace(/\s+/g,"-").toLowerCase()||"bot"}.json`,ie.click(),URL.revokeObjectURL(W)}return c.jsxs("aside",{className:"sidebar",children:[c.jsxs("div",{className:"sidebar-head",children:[c.jsxs("div",{className:"sidebar-top",children:[c.jsx(d1,{}),c.jsx("button",{className:"sidebar-toggle",onClick:s,title:"Hide sidebar (Ctrl+B)","aria-label":"Hide sidebar",children:"«"})]}),c.jsx("div",{className:"mode-switch",children:["runner","playground"].map(C=>c.jsx("button",{className:"seg"+(r===C?" on":""),onClick:()=>o(C),children:C==="runner"?"Runner":"Playground"},C))})]}),r==="runner"?c.jsx(yx,{runner:d,status:m,statusError:p,onOpen:E,sessions:u}):c.jsxs("div",{className:"sidebar-body",children:[c.jsx("p",{className:"hint",style:{marginTop:0},children:"Chat with any SCX model directly — no agent, no file access. Useful for comparing models and prompts."}),c.jsx("div",{className:"section-title",children:"Identity"}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Bot name"}),c.jsx("input",{type:"text",value:y.name,onChange:C=>B("name",C.target.value)})]}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Model"}),c.jsx("select",{value:y.model,onChange:C=>B("model",C.target.value),children:ve.map(([C,W])=>c.jsx("optgroup",{label:C==="openrouter"?"OpenRouter":"SCX.ai",children:W.map(ie=>c.jsxs("option",{value:ie.id,children:[ie.name,ie.context_length?` · ${Math.round(ie.context_length/1e3)}k ctx`:""]},ie.id))},C))}),v&&c.jsx("div",{className:"hint",style:{color:"var(--danger)"},children:v}),(S==null?void 0:S.description)&&c.jsx("div",{className:"hint",children:S.description}),c.jsxs("div",{className:"cap-badges",children:[c.jsx("span",{className:"badge"+(te?" on":""),children:"tools"}),c.jsx("span",{className:"badge"+(me?" on":""),children:"json"}),c.jsx("span",{className:"badge"+(pe?" on":""),children:"reasoning"}),(Q=S==null?void 0:S.datacenters)==null?void 0:Q.map(C=>c.jsx("span",{className:"badge",children:C.country_code},C.country_code))]})]}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"System prompt"}),c.jsx("textarea",{value:y.system,onChange:C=>B("system",C.target.value),placeholder:"Describe the bot's personality, role, and rules…",style:{minHeight:110}})]}),c.jsx("div",{className:"section-title",children:"Generation"}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Temperature"}),c.jsxs("div",{className:"range-row",children:[c.jsx("input",{type:"range",min:0,max:2,step:.05,value:y.temperature,onChange:C=>B("temperature",Number(C.target.value))}),c.jsx("span",{className:"range-val",children:y.temperature.toFixed(2)})]})]}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Top P"}),c.jsxs("div",{className:"range-row",children:[c.jsx("input",{type:"range",min:0,max:1,step:.05,value:y.topP,onChange:C=>B("topP",Number(C.target.value))}),c.jsx("span",{className:"range-val",children:y.topP.toFixed(2)})]})]}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Max output tokens"}),c.jsxs("div",{className:"range-row",children:[c.jsx("input",{type:"range",min:64,max:(S==null?void 0:S.max_output_length)??4096,step:64,value:Math.min(y.maxTokens,(S==null?void 0:S.max_output_length)??4096),onChange:C=>B("maxTokens",Number(C.target.value))}),c.jsx("span",{className:"range-val",children:y.maxTokens})]})]}),c.jsx(Bc,{label:"Stream responses",sub:"Token-by-token output via SSE",checked:y.stream,onChange:C=>B("stream",C)}),c.jsx(Bc,{label:"JSON mode",sub:me?"Force valid JSON output":"Not supported by this model",checked:y.jsonMode&&me,disabled:!me,onChange:C=>B("jsonMode",C)}),c.jsxs("div",{className:"section-title",children:["Tools ",te?"":"(model has no tool support)"]}),y.tools.map((C,W)=>c.jsxs("div",{className:"tool-card",children:[c.jsxs("div",{className:"tc-head",children:[c.jsx("input",{type:"text",value:C.function.name,placeholder:"function_name",onChange:ie=>Ke(W,{name:ie.target.value})}),c.jsx("button",{className:"btn danger",onClick:()=>R(ie=>({...ie,tools:ie.tools.filter((w,Y)=>Y!==W)})),children:"✕"})]}),c.jsx("input",{type:"text",value:C.function.description??"",placeholder:"description",style:{marginBottom:8},onChange:ie=>Ke(W,{description:ie.target.value})}),c.jsx("textarea",{defaultValue:JSON.stringify(C.function.parameters??{},null,2),onChange:ie=>at(W,ie.target.value),spellCheck:!1}),c.jsx("div",{className:"hint",children:"JSON Schema for the function parameters."})]},C.id??W)),c.jsxs("div",{className:"btn-row",children:[c.jsx("button",{className:"btn block ghost mini",disabled:!te,onClick:()=>R(C=>({...C,tools:[...C.tools,{...structuredClone(px),id:Kf()}]})),children:"+ Add tool"}),c.jsx("button",{className:"btn block ghost mini",onClick:T,title:"Import tools from web/public/example-tools.json",children:"↓ Load example tools"})]}),ce&&c.jsx("div",{className:"hint",style:{color:ce.startsWith("Loaded")?"var(--accent-2)":"var(--muted-2)"},children:ce}),c.jsx("div",{className:"section-title",children:"Knowledge (RAG)"}),c.jsx(Bc,{label:"Ground answers in knowledge",sub:ne.length?`Retrieve from ${ne.length} doc${ne.length>1?"s":""} via embeddings`:"Add a document to enable",checked:y.useKnowledge&&ne.length>0,disabled:ne.length===0,onChange:C=>B("useKnowledge",C)}),ne.map(C=>c.jsxs("div",{className:"tool-card",style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8},children:[c.jsxs("div",{style:{minWidth:0},children:[c.jsx("div",{style:{fontSize:13,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.name}),c.jsxs("div",{className:"hint",style:{margin:0},children:[C.chunks," chunks · ",C.chars.toLocaleString()," chars"]})]}),c.jsx("button",{className:"btn danger",onClick:()=>Ge(C.id),children:"✕"})]},C.id)),c.jsxs("div",{className:"field",style:{marginTop:10},children:[c.jsx("input",{type:"text",placeholder:"Document name (optional)",value:fe,onChange:C=>F(C.target.value),style:{marginBottom:8}}),c.jsx("textarea",{placeholder:"Paste text to give your bot a knowledge base…",value:P,onChange:C=>I(C.target.value),style:{minHeight:80}}),re&&c.jsx("div",{className:"hint",style:{color:"var(--danger)"},children:re}),c.jsx("button",{className:"btn block ghost mini",style:{marginTop:8},disabled:K||!P.trim(),onClick:_e,children:K?"Embedding…":"+ Add to knowledge base"})]}),c.jsx("div",{className:"section-title",children:"Voice"}),c.jsx(Bc,{label:"Speak replies aloud",sub:"Browser text-to-speech",checked:y.speak,onChange:C=>B("speak",C)}),c.jsxs("div",{className:"hint",children:[vy()?"Mic dictation available in the composer.":"Voice input not supported in this browser."," ","SCX-native audio (scx-tts/scx-stt) is gated on this tier."]}),c.jsx("div",{className:"section-title",children:"Session"}),c.jsxs("div",{className:"btn-row",children:[c.jsx("button",{className:"btn block ghost",onClick:L,children:"Clear chat"}),c.jsx("button",{className:"btn block ghost",onClick:z,children:"Export"})]})]}),c.jsxs("div",{className:"sidebar-foot",children:[c.jsx(X1,{}),ee&&c.jsx("button",{className:"btn ghost sm block",onClick:L1,children:"Sign out"}),c.jsxs("a",{className:"powered-by",href:"https://www.anthropic.com/claude/mythos",target:"_blank",rel:"noopener noreferrer","aria-label":"Reviewed by Claude Mythos 5.1",children:[c.jsx("span",{className:"powered-by-lead",children:"Reviewed by"}),c.jsx("img",{className:"powered-by-logo",src:"/claude-logo-ivory.svg",alt:"Claude",width:"83",height:"18"}),c.jsx("span",{className:"powered-by-model",children:"Mythos 5.1"})]})]})]})}function yx({runner:s,status:u,statusError:r,onOpen:o,sessions:d}){const[m,p]=k.useState(s.directory),[E,y]=k.useState(null),[R,b]=k.useState(!1),[v,S]=k.useState(!1);k.useEffect(()=>p(s.directory),[s.directory]);async function L(q=m){if(q.trim()){b(!0),y(null);try{o(await gy(q))}catch(ne){y(String(ne.message??ne))}finally{b(!1)}}}const B=s.recent.filter(q=>q!==s.directory),ee=(u==null?void 0:u.models.filter(q=>q.id.startsWith("scx/")).length)??0;return c.jsxs("div",{className:"sidebar-body",children:[c.jsx("div",{className:"section-title",children:"Project"}),c.jsxs("div",{className:"field",children:[c.jsxs("form",{className:"dir-row",onSubmit:q=>{q.preventDefault(),L()},children:[c.jsx("input",{type:"text",className:"mono",value:m,onChange:q=>p(q.target.value),placeholder:"C:\\code\\my-project",spellCheck:!1}),c.jsx("button",{className:"btn sm",type:"submit",disabled:R||!m.trim()||m===s.directory,children:"Open"})]}),E&&c.jsx("div",{className:"hint danger",children:E}),c.jsx("div",{className:"hint",children:"The agent reads, edits and runs commands in this folder. Switching folders starts a new session."}),c.jsxs("button",{className:"btn sm gh-open",onClick:()=>S(!0),title:"Clone a repository into the workspace (read-only)",children:[c.jsx(Oy,{size:13})," clone from GitHub"]}),v&&c.jsx(mx,{onOpen:q=>L(q),onClose:()=>S(!1)})]}),B.length>0&&c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Recent"}),c.jsx("div",{className:"recent-list",children:B.map(q=>c.jsxs("button",{className:"recent-item",onClick:()=>L(q),title:q,children:[c.jsx("span",{className:"recent-name",children:q.split(/[\\/]/).filter(Boolean).pop()}),c.jsx("span",{className:"recent-path mono",children:q})]},q))})]}),s.directory&&c.jsx(vx,{directory:s.directory,nav:d}),c.jsx("div",{className:"section-title",children:"Agents"}),c.jsxs("div",{className:"agent-info",children:[c.jsxs("div",{className:"ai-row",children:[c.jsx("span",{className:"ai-name",children:"build"}),c.jsx("span",{className:"hint",children:"edits & runs"})]}),c.jsx("div",{className:"hint ai-desc",children:"Every file edit and shell command waits for your approval."}),c.jsxs("div",{className:"ai-row",children:[c.jsx("span",{className:"ai-name",children:"plan"}),c.jsx("span",{className:"hint",children:"read-only"})]}),c.jsx("div",{className:"hint ai-desc",children:"Explores and reasons without changing anything."})]}),c.jsx("div",{className:"section-title",children:"Engine"}),r?c.jsx("div",{className:"hint danger",children:r}):c.jsxs("div",{className:"engine",children:[c.jsxs("div",{children:[c.jsx("span",{className:"muted",children:"Agent"}),c.jsx("span",{children:"OpenCode"})]}),c.jsxs("div",{children:[c.jsx("span",{className:"muted",children:"Provider"}),c.jsxs("span",{children:["SCX.ai · ",ee," models"]})]}),c.jsxs("div",{children:[c.jsx("span",{className:"muted",children:"Default"}),c.jsx("span",{className:"mono",children:(u==null?void 0:u.defaultModel)??"…"})]})]})]})}function vx({directory:s,nav:u}){const[r,o]=k.useState(null),[d,m]=k.useState(null),[p,E]=k.useState(null),[y,R]=k.useState(!1);k.useEffect(()=>{let S=!0;return Kb(s).then(L=>{S&&(o(L),m(null))}).catch(L=>S&&m(String(L.message??L))),()=>{S=!1}},[s,u.version,u.active]),k.useEffect(()=>{if(!p)return;const S=setTimeout(()=>E(null),3e3);return()=>clearTimeout(S)},[p]);async function b(S){if(p!==S){E(S);return}E(null);try{await $b(S,s),u.active===S&&u.open(null),o(L=>(L==null?void 0:L.filter(B=>B.id!==S))??null)}catch(L){m(String(L.message??L))}}const v=y?r??[]:(r??[]).slice(0,8);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"section-title",children:"Sessions"}),c.jsx("button",{className:"btn ghost sm block new-session",onClick:()=>u.open(null),children:"+ New session"}),d&&c.jsx("div",{className:"hint danger",children:d}),r&&r.length===0&&c.jsx("div",{className:"hint",children:"No past sessions in this folder yet."}),c.jsx("div",{className:"session-list",children:v.map(S=>c.jsxs("div",{className:"session-item"+(S.id===u.active?" on":""),children:[c.jsxs("button",{className:"session-open",onClick:()=>u.open(S.id),title:S.title,children:[c.jsx("span",{className:"session-title",children:S.title||"Untitled session"}),c.jsxs("span",{className:"session-meta",children:[bx(S.updated),S.files>0&&c.jsxs(c.Fragment,{children:[" · ",c.jsxs("span",{className:"adds",children:["+",S.additions]})," ",c.jsxs("span",{className:"dels",children:["−",S.deletions]})]})]})]}),c.jsx("button",{className:"session-del"+(p===S.id?" confirm":""),onClick:()=>b(S.id),title:p===S.id?"Click again to delete":"Delete session","aria-label":p===S.id?"Confirm delete":"Delete session",children:p===S.id?"Delete?":"✕"})]},S.id))}),r&&r.length>8&&c.jsx("button",{className:"btn ghost sm block",onClick:()=>R(S=>!S),children:y?"Show fewer":`Show all ${r.length}`})]})}function bx(s){if(!s)return"";const u=Math.max(0,(Date.now()-s)/1e3);return u<60?"just now":u<3600?`${Math.floor(u/60)}m ago`:u<86400?`${Math.floor(u/3600)}h ago`:u<7*86400?`${Math.floor(u/86400)}d ago`:new Date(s).toLocaleDateString()}function Bc({label:s,sub:u,checked:r,onChange:o,disabled:d}){return c.jsxs("div",{className:"toggle",children:[c.jsxs("div",{className:"tg-label",children:[s,u&&c.jsx("small",{children:u})]}),c.jsxs("label",{className:"switch"+(d?" disabled":""),children:[c.jsx("input",{type:"checkbox",checked:r,disabled:d,onChange:m=>o(m.target.checked)}),c.jsx("span",{})]})]})}function md(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var ni=md();function Ry(s){ni=s}var Fa={exec:()=>null};function Zi(s){let u=[];return r=>{let o=Math.max(0,Math.min(3,r-1)),d=u[o];return d||(d=s(o),u[o]=d),d}}function Ce(s,u=""){let r=typeof s=="string"?s:s.source,o={replace:(d,m)=>{let p=typeof m=="string"?m:m.source;return p=p.replace(Zt.caret,"$1"),r=r.replace(d,p),o},getRegex:()=>new RegExp(r,u)};return o}var xx=((s="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+s)}catch{return!1}})(),Zt={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:s=>new RegExp(`^( {0,3}${s})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:Zi(s=>new RegExp(`^ {0,${s}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:Zi(s=>new RegExp(`^ {0,${s}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:Zi(s=>new RegExp(`^ {0,${s}}(?:\`\`\`|~~~)`)),headingBeginRegex:Zi(s=>new RegExp(`^ {0,${s}}#`)),htmlBeginRegex:Zi(s=>new RegExp(`^ {0,${s}}(?:</?(?:${au})(?: +|$|/?>)|<(?:script|pre|style|textarea|!--))`,"i")),blockquoteBeginRegex:Zi(s=>new RegExp(`^ {0,${s}}>`))},Sx=/^(?:[ \t]*(?:\n|$))+/,Tx=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ex=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,lu=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Nx=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,pd=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Dy=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,zy=Ce(Dy).replace(/bull/g,pd).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),_x=Ce(Dy).replace(/bull/g,pd).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),gd=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,wx=/^[^\n]+/,yd=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,jx=Ce(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",yd).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ax=Ce(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,pd).getRegex(),au="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",vd=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,kx=Ce("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",vd).replace("tag",au).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),My=s=>Ce(gd).replace("hr",lu).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",s).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",au).getRegex(),Cx=My(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),Ox=My(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),Rx=Ce(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ox).getRegex(),bd={blockquote:Rx,code:Tx,def:jx,fences:Ex,heading:Nx,hr:lu,html:kx,lheading:zy,list:Ax,newline:Sx,paragraph:Cx,table:Fa,text:wx},Hg=Ce("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",lu).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",au).getRegex(),Dx={...bd,lheading:_x,table:Hg,paragraph:Ce(gd).replace("hr",lu).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Hg).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",au).getRegex()},zx={...bd,html:Ce(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",vd).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Fa,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Ce(gd).replace("hr",lu).replace("heading",` *#{1,6} *[^
|
|
53
|
+
docker compose exec runner rm /data/vault.json`}),c.jsx("p",{className:"hint",style:{margin:0},children:"Nothing on the network can do this, which is what keeps the lock meaningful."}),c.jsx("button",{type:"button",className:"link-btn",onClick:()=>{r("passkey"),q(null)},children:"back"})]}),ne&&c.jsx("div",{className:"form-status success",children:ne}),ee&&c.jsx("div",{className:"form-status error",children:ee})]})]})})}function lr({title:s,onClose:u,children:r}){return k.useEffect(()=>{if(!u)return;const o=d=>d.key==="Escape"&&u();return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[u]),c.jsx("div",{className:"overlay vault-dialog",onClick:u,children:c.jsxs("div",{className:"modal",role:"dialog","aria-label":s,onClick:o=>o.stopPropagation(),children:[c.jsxs("div",{className:"modal-head",children:[c.jsxs("span",{className:"modal-title",children:[c.jsx("span",{className:"dot y","aria-hidden":!0}),s]}),u&&c.jsx("button",{className:"icon-btn close-x",onClick:u,"aria-label":"Close",title:"Close (Esc)",children:"✕"})]}),c.jsx("div",{className:"modal-body",children:r})]})})}const nu=10,Kc=()=>`BugXHunter vault (${location.hostname})`,Lf="__custom__",Vi=[{name:"SCX_API",short:"SCX.ai — the default provider",label:"SCX.ai model key — the default provider"},{name:"OPENROUTER_API_KEY",short:"OpenRouter — one key, its whole catalogue",label:"OpenRouter key — unlocks its model catalogue (optional)"}],q1={SCX_API:"sk-scx-…",OPENROUTER_API_KEY:"sk-or-…"};function X1(){const[s,u]=k.useState(null),[r,o]=k.useState(null),[d,m]=k.useState(Date.now()),p=k.useCallback(()=>y1().then(u).catch(()=>{}),[]);k.useEffect(()=>{p();const b=setInterval(()=>{p(),m(Date.now())},3e4);return()=>clearInterval(b)},[p]);const E=()=>{o(null),p()},y=k.useCallback(()=>{dd(),b1().then(u).catch(()=>{})},[]);if(k.useEffect(()=>{const b=v=>{(v.ctrlKey||v.metaKey)&&v.shiftKey&&v.key.toLowerCase()==="l"&&(v.preventDefault(),y())};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[y]),!s)return null;const R=s.initialised?s.unsealed?c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"vault-state open",title:s.idleMinutes?`Auto-locks after ${s.idleMinutes} min without activity`:"Auto-lock off",children:["vault open",s.sealsAt?` · locks in ${Z1(s.sealsAt-d)}`:""]}),c.jsx("button",{className:"icon-btn vault-btn",onClick:()=>o("manage"),title:"Keys in the vault","aria-label":"Keys in the vault",children:c.jsx(Y1,{})}),c.jsx("button",{className:"icon-btn vault-btn",onClick:y,title:"Lock the vault (Ctrl+Shift+L)","aria-label":"Lock the vault (Ctrl+Shift+L)",children:c.jsx(Q1,{})})]}):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"vault-state sealed",children:"vault locked"}),c.jsx("button",{className:"icon-btn vault-btn primary",onClick:()=>o("unlock"),title:"Unlock the vault","aria-label":"Unlock the vault",children:c.jsx(G1,{})})]}):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"vault-state none",title:s.keySource==="none"?"No model key yet":s.keySource==="file"?"Model key comes from a key file":`Model key comes from ${s.keySource==="env"?".env":"OpenCode's auth.json"}, in the clear`,children:s.keySource==="none"?"no vault, no model key":"vault not set up"}),c.jsx("button",{className:"btn primary sm",onClick:()=>o("setup"),children:"set_up"})]});return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"vault-row",children:R}),r==="setup"&&c.jsx(V1,{onClose:E}),r==="unlock"&&c.jsx(K1,{status:s,onClose:E}),r==="manage"&&c.jsx(J1,{status:s,onChange:u,onClose:E})]})}const G1=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[c.jsx("circle",{cx:"12",cy:"16",r:"1"}),c.jsx("rect",{width:"18",height:"12",x:"3",y:"10",rx:"2"}),c.jsx("path",{d:"M7 10V7a5 5 0 0 1 9.33-2.5"})]}),Y1=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[c.jsx("path",{d:"M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z"}),c.jsx("path",{d:"m14 7 3 3"}),c.jsx("path",{d:"m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814"})]}),Q1=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[c.jsx("path",{d:"M12 13v3"}),c.jsx("path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 01-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 011-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 011.52 0C14.51 3.81 17 5 19 5a1 1 0 011 1z"}),c.jsx("circle",{cx:"12",cy:"11",r:"2"})]});function Z1(s){const u=Math.max(0,Math.round(s/6e4));return u>=60?`${Math.floor(u/60)}h ${String(u%60).padStart(2,"0")}m`:`${u}m`}const Hf=["passkey","key","backups"];function V1({onClose:s}){const[u,r]=k.useState("passkey"),[o,d]=k.useState(null),[m,p]=k.useState("SCX_API"),[E,y]=k.useState(""),[R,b]=k.useState(""),[v,S]=k.useState(""),[L,B]=k.useState(null),[ee,q]=k.useState(!1),[ne,be]=k.useState(!1),[fe,F]=k.useState(!1),[P,I]=k.useState(null);async function K(){F(!0),I(null);try{d(await Cy(Kc(),ad)),r("key")}catch(ce){I(ce.message)}finally{F(!1)}}async function oe(){if(o){F(!0),I(null);try{B(await D1({...o,label:Kc(),items:E.trim()?{[m]:E.trim()}:{}})),r("backups")}catch(ce){I(ce.message)}finally{F(!1)}}}async function re(){if(L){F(!0),I(null);try{let ce=L.doc;R&&(ce={...ce,methods:[...ce.methods,await cd(Vt.dec(L.dek),R)]}),await v1(ce,L.dek),Vc(L.dek),s()}catch(ce){I(ce.message),F(!1)}}}const Ne=!R||R.length>=nu&&R===v;return c.jsxs(lr,{title:"vault --init",onClose:u==="backups"?void 0:s,children:[c.jsx("div",{className:"steps",children:Hf.map(ce=>c.jsx("span",{className:ce===u?"on":Hf.indexOf(ce)<Hf.indexOf(u)?"done":"",children:ce},ce))}),u==="passkey"&&c.jsxs(c.Fragment,{children:[c.jsx("p",{children:"Your model keys will be sealed at rest, and this passkey will unlock them and sign you in — one touch. The authenticator (Windows Hello, Touch ID, Android, or a security key) derives a secret that never leaves it. Works in Chrome, Edge and Safari 18+; Firefox can't do this yet."}),!Ii()&&c.jsx("div",{className:"form-status error",children:"This browser has no passkey support."}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:fe||!Ii(),onClick:K,children:fe?"waiting for the authenticator…":"create passkey →"})})]}),u==="key"&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["Passkey enrolled. Add a model key now, or later from the keys dialog (where you can add the other provider too). It goes straight into the sealed vault; ",c.jsx("code",{className:"mono",children:".env"})," can then drop the key."]}),c.jsx("label",{htmlFor:"v-provider",children:"Provider"}),c.jsx("select",{id:"v-provider",className:"mono",value:m,onChange:ce=>p(ce.target.value),children:Vi.map(ce=>c.jsx("option",{value:ce.name,children:ce.short},ce.name))}),c.jsxs("label",{htmlFor:"v-key",children:[m," (optional)"]}),c.jsx("input",{id:"v-key",type:"password",autoFocus:!0,autoComplete:"off",placeholder:q1[m]??"",value:E,onChange:ce=>y(ce.target.value)}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:fe,onClick:oe,children:fe?"sealing…":"next →"})})]}),u==="backups"&&L&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["Backups, for when the passkey isn't at hand. This recovery code is shown ",c.jsx("b",{children:"once"})," and stored nowhere — keep it offline, like a password-manager note or paper."]}),c.jsxs("button",{type:"button",className:"recovery-code"+(ne?" copied":""),"aria-label":"Recovery code — click to copy",title:"Click to copy",onClick:()=>{var ce;(ce=navigator.clipboard)==null||ce.writeText(L.recoveryCode).then(()=>{be(!0),setTimeout(()=>be(!1),2e3)}).catch(()=>{})},children:[c.jsx("span",{className:"code",children:L.recoveryCode}),c.jsx("span",{className:"copy-hint",children:ne?"✓ copied":"click to copy"})]}),c.jsxs("label",{className:"check",children:[c.jsx("input",{type:"checkbox",checked:ee,onChange:ce=>q(ce.target.checked)})," I have stored this code somewhere safe."]}),c.jsxs("label",{htmlFor:"v-pass",children:["Backup passphrase (optional, at least ",nu," characters)"]}),c.jsx("input",{id:"v-pass",type:"password",autoComplete:"new-password",value:R,onChange:ce=>b(ce.target.value)}),R&&c.jsxs(c.Fragment,{children:[c.jsx("label",{htmlFor:"v-pass2",children:"Again"}),c.jsx("input",{id:"v-pass2",type:"password",autoComplete:"new-password",value:v,onChange:ce=>S(ce.target.value)}),v&&R!==v&&c.jsx("div",{className:"form-status error",children:"The passphrases differ."})]}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:!ee||!Ne||fe,onClick:re,children:fe?"creating…":"create vault →"})})]}),P&&c.jsx("div",{className:"form-status error",children:P})]})}function K1({status:s,onClose:u}){const[r,o]=k.useState("passkey"),[d,m]=k.useState(""),[p,E]=k.useState(""),[y,R]=k.useState(!1),[b,v]=k.useState(null),S=s.methods.find(F=>F.type==="passkey"),L=s.methods.find(F=>F.type==="password"),B=s.methods.find(F=>F.type==="recovery"),ee=!!(S!=null&&S.passphrase);async function q(F,P){R(!0),v(null);try{let I;try{I=await F()}catch(K){throw K instanceof Error&&/Passkey|authenticator|pending|origin/i.test(K.message)?K:new Error(P)}await xy(I),Vc(I),u()}catch(I){v(I.message),R(!1)}}const ne=()=>S&&q(async()=>{const F=await M1(S.credentialId,S.transports,S.prfSalt);return _y(S,F,ee?d:void 0)},ee?"Wrong passphrase, or a different passkey than the one enrolled.":"A different passkey than the one enrolled."),be=()=>L&&q(()=>wy(L,d),"Wrong backup passphrase."),fe=()=>B&&q(()=>jy(B,p),"That recovery code doesn't open the vault.");return c.jsxs(lr,{title:"vault --unlock",onClose:u,children:[r==="passkey"&&c.jsxs(c.Fragment,{children:[c.jsx("p",{children:ee?"This passkey was enrolled with a passphrase: enter it, then confirm with the passkey.":"One touch: confirm with your passkey."}),ee&&c.jsxs(c.Fragment,{children:[c.jsx("label",{htmlFor:"v-unlock-pass",children:"Passphrase"}),c.jsx("input",{id:"v-unlock-pass",type:"password",autoFocus:!0,autoComplete:"current-password",value:d,onChange:F=>m(F.target.value),onKeyDown:F=>{F.key==="Enter"&&d&&ne()}})]}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",autoFocus:!ee,disabled:y||!S||ee&&!d,onClick:ne,children:y?"waiting for the authenticator…":"unlock with passkey →"})}),c.jsxs("div",{className:"login-links",children:[L&&c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("password"),v(null)},children:"use the backup passphrase"}),B&&c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("recovery"),v(null)},children:"use the recovery code"})]})]}),r==="password"&&c.jsxs(c.Fragment,{children:[c.jsx("label",{htmlFor:"v-unlock-pw",children:"Backup passphrase"}),c.jsx("input",{id:"v-unlock-pw",type:"password",autoFocus:!0,autoComplete:"current-password",value:d,onChange:F=>m(F.target.value),onKeyDown:F=>{F.key==="Enter"&&d&&be()}}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:y||!d,onClick:be,children:y?"unlocking…":"unlock →"})}),c.jsxs("div",{className:"login-links",children:[c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("passkey"),v(null)},children:"use the passkey instead"}),B&&c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("recovery"),v(null)},children:"use the recovery code"})]})]}),r==="recovery"&&c.jsxs(c.Fragment,{children:[c.jsx("p",{children:"Enter the recovery code shown when the vault was created."}),c.jsx("label",{htmlFor:"v-code",children:"Recovery code"}),c.jsx("input",{id:"v-code",type:"text",className:"mono",autoFocus:!0,autoComplete:"off",spellCheck:!1,placeholder:"XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-X",value:p,onChange:F=>E(F.target.value),onKeyDown:F=>{F.key==="Enter"&&$f(p)&&fe()}}),c.jsx("div",{className:"perm-actions center",children:c.jsx("button",{className:"btn primary wide",disabled:y||!$f(p),onClick:fe,children:y?"unlocking…":"unlock →"})}),c.jsxs("div",{className:"login-links",children:[c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("passkey"),v(null)},children:"use the passkey instead"}),L&&c.jsx("button",{className:"link-btn",disabled:y,onClick:()=>{o("password"),v(null)},children:"use the backup passphrase"})]})]}),b&&c.jsx("div",{className:"form-status error",children:b})]})}function J1({status:s,onChange:u,onClose:r}){const[o,d]=k.useState("SCX_API"),[m,p]=k.useState(""),[E,y]=k.useState(""),[R,b]=k.useState(!1),[v,S]=k.useState(""),[L,B]=k.useState(!1),[ee,q]=k.useState(null),ne=U1(),be=s.methods.filter(J=>J.type==="passkey"),fe=s.methods.find(J=>J.type==="password");async function F(J){B(!0),q(null);try{const _e=await J();_e&&u(_e)}catch(_e){q(_e.message)}finally{B(!1)}}const P=()=>{if(!ne)throw new Error("Unlock the vault in this tab first (the change must wrap the current key).");return Vt.dec(ne)},I=()=>F(async()=>{const J=await x1(o.trim().toUpperCase(),m);return p(""),J}),K=J=>F(()=>S1(J)),oe=J=>F(()=>T1(J)),re=()=>F(async()=>{const J=P(),_e=await Ny(J,await Cy(Kc(),ad),Kc());return Ug(_e,ne)}),Ne=()=>F(async()=>{const J=P(),_e=await Ug(await cd(J,E),ne);return b(!1),y(""),_e}),ce=()=>F(async()=>{P();const J=await E1(ne);return dd(),r(),J});return c.jsxs(lr,{title:"vault --keys",onClose:r,children:[c.jsx("p",{children:"Secrets sealed in the vault. Values are never shown again; replace one by saving it under the same name."}),c.jsxs("div",{className:"vault-items",children:[Vi.map(J=>{const _e=s.items.includes(J.name);return c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:_e?"ok":"missing","aria-hidden":!0,children:_e?"✓":"○"}),c.jsxs("span",{className:"name",children:[J.name,c.jsxs("span",{className:"desc",children:[" — ",J.label]})]}),_e?c.jsx("button",{className:"btn danger",disabled:L,onClick:()=>K(J.name),title:"Remove",children:"✕"}):c.jsx("button",{className:"btn sm",disabled:L,onClick:()=>{d(J.name),setTimeout(()=>{var Ge;return(Ge=document.getElementById("v-value"))==null?void 0:Ge.focus()},0)},children:"add"})]},J.name)}),s.items.filter(J=>!Vi.some(_e=>_e.name===J)).map(J=>c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:"ok","aria-hidden":!0,children:"✓"}),c.jsx("span",{className:"name",children:J}),c.jsx("button",{className:"btn danger",disabled:L,onClick:()=>K(J),title:"Remove",children:"✕"})]},J))]}),c.jsx("label",{htmlFor:"v-name",children:"Key"}),c.jsxs("select",{id:"v-name",className:"mono",value:Vi.some(J=>J.name===o)?o:Lf,onChange:J=>d(J.target.value===Lf?"":J.target.value),children:[Vi.map(J=>c.jsxs("option",{value:J.name,children:[J.name,s.items.includes(J.name)?" (replace)":""]},J.name)),c.jsx("option",{value:Lf,children:"custom…"})]}),!Vi.some(J=>J.name===o)&&c.jsx("input",{type:"text",className:"mono",placeholder:"NAME_IN_UPPER_SNAKE_CASE","aria-label":"Custom key name",value:o,onChange:J=>d(J.target.value),spellCheck:!1,autoFocus:!0}),c.jsx("label",{htmlFor:"v-value",children:"Value"}),c.jsx("input",{id:"v-value",type:"password",autoComplete:"off",value:m,onChange:J=>p(J.target.value),onKeyDown:J=>{J.key==="Enter"&&m&&I()}}),c.jsxs("div",{className:"perm-actions",children:[c.jsx("button",{className:"btn primary sm",disabled:L||!m||!o.trim(),onClick:I,children:L?"sealing…":"save"}),c.jsx("span",{className:"hint",style:{margin:0},children:s.idleMinutes?`Auto-locks after ${s.idleMinutes} min idle.`:"Auto-lock is off."})]}),c.jsx("div",{className:"section-title",children:"passkeys"}),c.jsx("p",{children:"Each passkey unlocks the vault and signs you in with one touch. Keep two, on different devices, so losing one is not an emergency."}),c.jsx("div",{className:"vault-items",children:be.map(J=>c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:J.canLogin?"ok":"warn","aria-hidden":!0,children:J.canLogin?"✓":"!"}),c.jsxs("span",{className:"name",children:[J.label,J.passphrase?" — needs its passphrase (older enrolment)":"",J.canLogin?"":" — unlock only, can't sign in; add a new passkey"]}),c.jsx("button",{className:"btn danger",disabled:L||be.length<=1,onClick:()=>oe(J.id),title:be.length<=1?"Add another passkey first":"Remove",children:"✕"})]},J.id))}),c.jsx("div",{className:"perm-actions",children:c.jsx("button",{className:"btn sm",disabled:L||!ne,onClick:re,title:ne?"":"Unlock the vault in this tab first",children:L?"waiting for the authenticator…":"+ add passkey"})}),c.jsx("div",{className:"section-title",children:"backups"}),c.jsx("p",{children:"The recovery code from setup always works. A backup passphrase is optional: a way in on a device without the passkey."}),c.jsxs("div",{className:"vault-items",children:[c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:"ok","aria-hidden":!0,children:"✓"}),c.jsx("span",{className:"name",children:"Recovery code"})]}),fe&&c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:"ok","aria-hidden":!0,children:"✓"}),c.jsx("span",{className:"name",children:"Backup passphrase"}),c.jsx("button",{className:"btn danger",disabled:L,onClick:()=>oe(fe.id),title:"Remove",children:"✕"})]})]}),R?c.jsxs(c.Fragment,{children:[c.jsxs("label",{htmlFor:"v-newpass",children:[fe?"New backup passphrase":"Backup passphrase"," (at least ",nu," characters)"]}),c.jsx("input",{id:"v-newpass",type:"password",autoFocus:!0,autoComplete:"new-password",value:E,onChange:J=>y(J.target.value),onKeyDown:J=>{J.key==="Enter"&&E.length>=nu&&Ne()}}),c.jsxs("div",{className:"perm-actions",children:[c.jsx("button",{className:"btn primary sm",disabled:L||E.length<nu,onClick:Ne,children:L?"sealing…":"save"}),c.jsx("button",{className:"btn sm",disabled:L,onClick:()=>b(!1),children:"cancel"})]})]}):c.jsx("div",{className:"perm-actions",children:c.jsx("button",{className:"btn sm",disabled:L||!ne,onClick:()=>b(!0),title:ne?"":"Unlock the vault in this tab first",children:fe?"replace backup passphrase":"+ set a backup passphrase"})}),c.jsx("div",{className:"section-title",children:"danger zone"}),c.jsxs("p",{children:["Delete the vault to start over with new factors. Its secrets are gone; the app reopens without sign-in until a new vault exists. Lost every factor instead? Run ",c.jsx("code",{className:"mono",children:"npm run vault:reset"})," on the server."]}),c.jsxs("div",{className:"perm-actions",children:[c.jsx("input",{type:"text",className:"mono",placeholder:"type DELETE",value:v,onChange:J=>S(J.target.value),style:{width:160}}),c.jsx("button",{className:"btn danger-outline sm",disabled:L||v!=="DELETE"||!ne,onClick:ce,children:"delete vault"})]}),ee&&c.jsx("div",{className:"form-status error",children:ee})]})}function wn({size:s=14,children:u,className:r}){return c.jsx("svg",{className:r,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:u})}const hd=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}),c.jsx("path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}),c.jsx("path",{d:"M10 9H8"}),c.jsx("path",{d:"M16 13H8"}),c.jsx("path",{d:"M16 17H8"})]}),$1=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34"}),c.jsx("path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}),c.jsx("path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z"})]}),I1=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M12 19h8"}),c.jsx("path",{d:"m4 17 6-6-6-6"})]}),Lg=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"m21 21-4.34-4.34"}),c.jsx("circle",{cx:"11",cy:"11",r:"8"})]}),F1=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1"}),c.jsx("path",{d:"m21 21-1.9-1.9"}),c.jsx("circle",{cx:"17",cy:"17",r:"3"})]}),W1=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M3 5h.01"}),c.jsx("path",{d:"M3 12h.01"}),c.jsx("path",{d:"M3 19h.01"}),c.jsx("path",{d:"M8 5h13"}),c.jsx("path",{d:"M8 12h13"}),c.jsx("path",{d:"M8 19h13"})]}),P1=s=>c.jsxs(wn,{...s,children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),c.jsx("path",{d:"M2 12h20"})]}),ex=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M13 5h8"}),c.jsx("path",{d:"M13 12h8"}),c.jsx("path",{d:"M13 19h8"}),c.jsx("path",{d:"m3 17 2 2 4-4"}),c.jsx("path",{d:"m3 7 2 2 4-4"})]}),tx=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719"}),c.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),c.jsx("path",{d:"M12 17h.01"})]}),nx=s=>c.jsx(wn,{...s,children:c.jsx("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z"})}),lx=s=>c.jsxs(wn,{...s,children:[c.jsx("line",{x1:"6",x2:"6",y1:"3",y2:"15"}),c.jsx("circle",{cx:"18",cy:"6",r:"3"}),c.jsx("circle",{cx:"6",cy:"18",r:"3"}),c.jsx("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),Oy=s=>c.jsxs(wn,{...s,children:[c.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),c.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),ax=s=>c.jsx(wn,{...s,children:c.jsx("path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"})});function ix({tool:s,size:u=14}){switch(s){case"read":return c.jsx(hd,{size:u});case"write":case"edit":case"patch":case"apply_patch":return c.jsx($1,{size:u});case"bash":return c.jsx(I1,{size:u});case"grep":return c.jsx(Lg,{size:u});case"glob":case"list":return c.jsx(F1,{size:u});case"webfetch":return c.jsx(P1,{size:u});case"websearch":return c.jsx(Lg,{size:u});case"todowrite":case"todoread":return c.jsx(ex,{size:u});case"task":return c.jsx(W1,{size:u});case"question":return c.jsx(tx,{size:u});default:return c.jsx(nx,{size:u})}}async function ti(s,u){var o,d;const r=await fetch(s,{headers:{"Content-Type":"application/json"},...u});if(!r.ok){let m=`${r.status}`;try{m=((d=(o=await r.json())==null?void 0:o.error)==null?void 0:d.message)??m}catch{}throw new Error(m)}return r.json()}const sx=()=>ti("/api/github"),ux=()=>ti("/api/github/repos").then(s=>s.repos),cx=s=>ti(`/api/github/branches?repo=${encodeURIComponent(s)}`).then(u=>u.branches),rx=s=>ti("/api/github/clone",{method:"POST",body:JSON.stringify(s)}),ox=()=>ti("/api/github/connect/start",{method:"POST"}),fx=s=>ti("/api/github/connect/poll",{method:"POST",body:JSON.stringify({id:s})}),dx=()=>ti("/api/github/connect",{method:"DELETE"});function hx(s){if(!s)return"";const u=Math.max(0,(Date.now()-new Date(s).getTime())/1e3);return u<3600?`${Math.max(1,Math.round(u/60))} min ago`:u<86400?`${Math.round(u/3600)} h ago`:u<86400*30?`${Math.round(u/86400)} d ago`:u<86400*365?`${Math.round(u/(86400*30))} mo ago`:`${Math.round(u/(86400*365))} y ago`}function mx({onOpen:s,onClose:u}){const[r,o]=k.useState(null),[d,m]=k.useState(null),[p,E]=k.useState(null),[y,R]=k.useState(""),[b,v]=k.useState(null),[S,L]=k.useState(null),[B,ee]=k.useState(""),[q,ne]=k.useState(null),[be,fe]=k.useState(null),[F,P]=k.useState(null),[I,K]=k.useState(!1),oe=k.useCallback(()=>sx().then(Z=>{o(Z),m(null)}).catch(Z=>m(Z.message)),[]);k.useEffect(()=>{oe()},[oe]);const re=!!(r!=null&&r.connected&&!r.sealed&&!r.error),Ne=k.useCallback(()=>{ne("repos"),ux().then(E).catch(Z=>fe(Z.message)).finally(()=>ne(Z=>Z==="repos"?null:Z))},[]);k.useEffect(()=>{re&&Ne()},[re,Ne]),k.useEffect(()=>{if(!re)return;const Z=()=>Ne();return window.addEventListener("focus",Z),()=>window.removeEventListener("focus",Z)},[re,Ne]);const ce=k.useRef(null),J=()=>{ce.current&&(window.clearTimeout(ce.current),ce.current=null)};k.useEffect(()=>J,[]);async function _e(){ne("connect"),fe(null);try{const Z=await ox();P(Z);try{await navigator.clipboard.writeText(Z.userCode),K(!0)}catch{K(!1)}const ve=async()=>{try{const Ke=await fx(Z.id);if(Ke.status==="pending"){ce.current=window.setTimeout(ve,Z.interval*1e3);return}if(P(null),ne(null),Ke.status==="connected"){await oe();return}fe(Ke.status==="denied"?"The sign-in was cancelled on GitHub.":"The code expired. Start again.")}catch(Ke){P(null),ne(null),fe(Ke.message)}};ce.current=window.setTimeout(ve,Z.interval*1e3)}catch(Z){ne(null),fe(Z.message)}}function Ge(){J(),P(null),ne(null)}async function Me(){fe(null);try{await dx(),E(null),v(null),await oe()}catch(Z){fe(Z.message)}}function te(Z){v(Z),ee(Z.defaultBranch),L(null),fe(null),ne("branches"),cx(Z.fullName).then(ve=>{L(ve),!ve.some(Ke=>Ke.name===Z.defaultBranch)&&ve[0]&&ee(ve[0].name)}).catch(ve=>fe(ve.message)).finally(()=>ne(ve=>ve==="branches"?null:ve))}async function me(){if(b){ne("clone"),fe(null);try{const Z=await rx({repo:b.fullName,branch:B});s(Z.directory),u()}catch(Z){fe(Z.message)}finally{ne(null)}}}const pe=k.useMemo(()=>{const Z=y.trim().toLowerCase();return(p??[]).filter(ve=>!Z||ve.fullName.toLowerCase().includes(Z)||(ve.description??"").toLowerCase().includes(Z))},[p,y]);return c.jsxs(lr,{title:"github --clone",onClose:u,children:[d&&c.jsx("div",{className:"hint danger",children:d}),r&&!r.connected&&!F&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["Clone a repository into the workspace so the agent can review it. ",c.jsx("b",{children:"Read-only"}),": the app can only read code, it reaches only the repositories you install it on, and nothing in the sandbox can push."]}),c.jsx("div",{className:"perm-actions center",children:c.jsxs("button",{className:"btn primary wide",disabled:q!==null,onClick:_e,children:[c.jsx(Oy,{size:15})," ",q==="connect"?"contacting GitHub…":"Connect GitHub"]})}),r.storage==="memory"&&c.jsx("div",{className:"hint",style:{textAlign:"center"},children:"No vault yet, so the sign-in is kept until the runner restarts. Set up the vault to keep it."})]}),F&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["Enter this code on GitHub to connect. ",I?"It is on your clipboard.":"Click it to copy."]}),c.jsx("button",{className:"recovery-code gh-code",onClick:()=>navigator.clipboard.writeText(F.userCode).then(()=>K(!0)).catch(()=>{}),title:"Copy",children:F.userCode}),c.jsx("div",{className:"perm-actions center",children:c.jsx("a",{className:"btn primary wide",href:F.verificationUri,target:"_blank",rel:"noreferrer",children:"Open github.com/login/device ↗"})}),c.jsxs("div",{className:"hint",style:{textAlign:"center"},children:["Waiting for your approval… this finishes by itself. ",c.jsx("button",{className:"link-btn",onClick:Ge,children:"cancel"})]})]}),(r==null?void 0:r.sealed)&&c.jsx("p",{children:"Your GitHub sign-in is in the vault, which is locked. Unlock it (the lock icon below) and reopen this dialog."}),(r==null?void 0:r.error)&&c.jsx("div",{className:"hint danger",children:r.error}),re&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"gh-head",children:[c.jsxs("span",{children:["connected as ",c.jsx("b",{children:r.login}),r.storage==="memory"?" · until restart (no vault yet)":""," · ",c.jsx("button",{className:"link-btn",onClick:Me,children:"disconnect"})]}),c.jsx("a",{href:r.installUrl,target:"_blank",rel:"noreferrer",children:"choose repositories on GitHub ↗"})]}),r.clones.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"section-title",children:"in the workspace"}),c.jsx("div",{className:"vault-items",children:r.clones.map(Z=>c.jsxs("div",{className:"vault-item",children:[c.jsx("span",{className:"ok","aria-hidden":!0,children:"✓"}),c.jsxs("span",{className:"name",title:Z.directory,children:[Z.fullName,c.jsxs("span",{className:"desc",children:[" — ",Z.branch??"detached"]})]}),c.jsx("button",{className:"btn sm",onClick:()=>{s(Z.directory),u()},children:"open"})]},Z.directory))})]}),p&&p.length===0?c.jsxs("div",{className:"gh-callout",children:[c.jsx("b",{children:"One more step."})," Signing in says who you are; which repositories BugXHunter may read is chosen separately, on GitHub's install screen. An organisation's owner may have to approve it. This list refreshes when you come back.",c.jsx("div",{className:"perm-actions center",children:c.jsx("a",{className:"btn primary wide",href:r.installUrl,target:"_blank",rel:"noreferrer",children:"Choose repositories on GitHub ↗"})})]}):c.jsxs(c.Fragment,{children:[c.jsx("input",{type:"text",className:"mono",placeholder:"filter repositories…",value:y,onChange:Z=>R(Z.target.value),spellCheck:!1,autoFocus:!0}),c.jsxs("div",{className:"gh-list",role:"listbox","aria-label":"Repositories",children:[q==="repos"&&!p&&c.jsx("div",{className:"hint",children:"loading…"}),p&&p.length>0&&pe.length===0&&c.jsx("div",{className:"hint",children:"Nothing matches."}),pe.map(Z=>c.jsxs("button",{className:`gh-repo${(b==null?void 0:b.fullName)===Z.fullName?" selected":""}`,role:"option","aria-selected":(b==null?void 0:b.fullName)===Z.fullName,onClick:()=>te(Z),children:[c.jsxs("span",{className:"gh-name",children:[Z.fullName,Z.private&&c.jsx("span",{className:"badge",children:"private"}),Z.archived&&c.jsx("span",{className:"badge",children:"archived"}),Z.directory&&c.jsx("span",{className:"badge on",children:"in workspace"})]}),Z.description&&c.jsx("span",{className:"gh-desc",children:Z.description}),c.jsxs("span",{className:"gh-meta",children:[c.jsx(lx,{size:11})," ",Z.defaultBranch,Z.pushedAt?` · pushed ${hx(Z.pushedAt)}`:""]})]},Z.fullName))]})]}),b&&c.jsxs("div",{className:"gh-clone",children:[c.jsx("label",{htmlFor:"gh-branch",children:"Branch"}),c.jsx("select",{id:"gh-branch",className:"mono",value:B,onChange:Z=>ee(Z.target.value),disabled:!S,children:(S??[{name:B,isDefault:!0}]).map(Z=>c.jsxs("option",{value:Z.name,children:[Z.name,Z.isDefault?" (default)":""]},Z.name))}),c.jsx("button",{className:"btn primary sm",disabled:q!==null||!B,onClick:me,children:q==="clone"?b.directory?"updating…":"cloning…":b.directory?"update & open":"clone & open"})]}),b&&c.jsxs("div",{className:"hint",children:["Lands in ",c.jsxs("span",{className:"mono",children:[r.cloneRoot,"/",b.fullName]}),". An existing clone is fast-forwarded, never reset; the agent's local edits stay."]})]}),be&&c.jsx("div",{className:"hint danger",children:be})]})}const px={type:"function",function:{name:"get_weather",description:"Get the current weather for a city",parameters:{type:"object",properties:{city:{type:"string",description:"City name"}},required:["city"]}}};function gx({onCollapse:s,sessions:u,mode:r,setMode:o,runner:d,status:m,statusError:p,onOpenDirectory:E,config:y,setConfig:R,models:b,modelError:v,activeModel:S,onReset:L}){var Q;const B=(C,W)=>R(ie=>({...ie,[C]:W})),[ee,q]=k.useState(!1);k.useEffect(()=>{const C=()=>fetch("/api/auth/me").then(ie=>ie.json()).then(ie=>q(!!ie.required)).catch(()=>{});C();const W=setInterval(C,3e4);return()=>clearInterval(W)},[]);const[ne,be]=k.useState([]),[fe,F]=k.useState(""),[P,I]=k.useState(""),[K,oe]=k.useState(!1),[re,Ne]=k.useState(null),[ce,J]=k.useState(null);k.useEffect(()=>{Gb().then(be).catch(()=>{})},[]);async function _e(){if(P.trim()){oe(!0),Ne(null);try{const C=await Yb(fe.trim()||`Document ${ne.length+1}`,P);be(C),F(""),I(""),y.useKnowledge||B("useKnowledge",!0)}catch(C){Ne(String(C.message??C))}finally{oe(!1)}}}async function Ge(C){be(await Qb(C))}const Me=(S==null?void 0:S.supported_features)??[],te=Me.includes("tools"),me=Me.includes("json_mode"),pe=Me.includes("reasoning"),Z=b.filter(C=>C.output_modalities.includes("text")),ve=["scx","openrouter"].map(C=>[C,Z.filter(W=>(W.provider??"scx")===C)]).filter(([,C])=>C.length>0);function Ke(C,W){R(ie=>{const w=ie.tools.slice();return w[C]={...w[C],function:{...w[C].function,...W}},{...ie,tools:w}})}function at(C,W){try{const ie=JSON.parse(W);Ke(C,{parameters:ie})}catch{}}function Ot(C){if(!C)return null;const W=C.function??C;return W!=null&&W.name?{type:"function",id:Kf(),function:{name:W.name,description:W.description,parameters:W.parameters??W.schema}}:null}async function T(){J(null);try{const C=await fetch("/example-tools.json",{cache:"no-store"});if(!C.ok)throw new Error(`No example-tools.json yet (${C.status}) — add web/public/example-tools.json first.`);const W=await C.json(),ie=(Array.isArray(W)?W:W.tools??[]).map(Ot).filter(Boolean);if(!ie.length)throw new Error("File had no valid tools.");let w=0;R(Y=>{const le=new Set(Y.tools.map(je=>je.function.name)),Oe=ie.filter(je=>!le.has(je.function.name));return w=Oe.length,{...Y,tools:[...Y.tools,...Oe]}}),J(w?`Loaded ${w} tool${w>1?"s":""}.`:"Already loaded.")}catch(C){J(String(C.message??C))}}function z(){const C=new Blob([JSON.stringify(y,null,2)],{type:"application/json"}),W=URL.createObjectURL(C),ie=document.createElement("a");ie.href=W,ie.download=`${y.name.replace(/\s+/g,"-").toLowerCase()||"bot"}.json`,ie.click(),URL.revokeObjectURL(W)}return c.jsxs("aside",{className:"sidebar",children:[c.jsxs("div",{className:"sidebar-head",children:[c.jsxs("div",{className:"sidebar-top",children:[c.jsx(d1,{}),c.jsx("button",{className:"sidebar-toggle",onClick:s,title:"Hide sidebar (Ctrl+B)","aria-label":"Hide sidebar",children:"«"})]}),c.jsx("div",{className:"mode-switch",children:["runner","playground"].map(C=>c.jsx("button",{className:"seg"+(r===C?" on":""),onClick:()=>o(C),children:C==="runner"?"Runner":"Playground"},C))})]}),r==="runner"?c.jsx(yx,{runner:d,status:m,statusError:p,onOpen:E,sessions:u}):c.jsxs("div",{className:"sidebar-body",children:[c.jsx("p",{className:"hint",style:{marginTop:0},children:"Chat with any SCX model directly — no agent, no file access. Useful for comparing models and prompts."}),c.jsx("div",{className:"section-title",children:"Identity"}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Bot name"}),c.jsx("input",{type:"text",value:y.name,onChange:C=>B("name",C.target.value)})]}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Model"}),c.jsx("select",{value:y.model,onChange:C=>B("model",C.target.value),children:ve.map(([C,W])=>c.jsx("optgroup",{label:C==="openrouter"?"OpenRouter":"SCX.ai",children:W.map(ie=>c.jsxs("option",{value:ie.id,children:[ie.name,ie.context_length?` · ${Math.round(ie.context_length/1e3)}k ctx`:""]},ie.id))},C))}),v&&c.jsx("div",{className:"hint",style:{color:"var(--danger)"},children:v}),(S==null?void 0:S.description)&&c.jsx("div",{className:"hint",children:S.description}),c.jsxs("div",{className:"cap-badges",children:[c.jsx("span",{className:"badge"+(te?" on":""),children:"tools"}),c.jsx("span",{className:"badge"+(me?" on":""),children:"json"}),c.jsx("span",{className:"badge"+(pe?" on":""),children:"reasoning"}),(Q=S==null?void 0:S.datacenters)==null?void 0:Q.map(C=>c.jsx("span",{className:"badge",children:C.country_code},C.country_code))]})]}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"System prompt"}),c.jsx("textarea",{value:y.system,onChange:C=>B("system",C.target.value),placeholder:"Describe the bot's personality, role, and rules…",style:{minHeight:110}})]}),c.jsx("div",{className:"section-title",children:"Generation"}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Temperature"}),c.jsxs("div",{className:"range-row",children:[c.jsx("input",{type:"range",min:0,max:2,step:.05,value:y.temperature,onChange:C=>B("temperature",Number(C.target.value))}),c.jsx("span",{className:"range-val",children:y.temperature.toFixed(2)})]})]}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Top P"}),c.jsxs("div",{className:"range-row",children:[c.jsx("input",{type:"range",min:0,max:1,step:.05,value:y.topP,onChange:C=>B("topP",Number(C.target.value))}),c.jsx("span",{className:"range-val",children:y.topP.toFixed(2)})]})]}),c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Max output tokens"}),c.jsxs("div",{className:"range-row",children:[c.jsx("input",{type:"range",min:64,max:(S==null?void 0:S.max_output_length)??4096,step:64,value:Math.min(y.maxTokens,(S==null?void 0:S.max_output_length)??4096),onChange:C=>B("maxTokens",Number(C.target.value))}),c.jsx("span",{className:"range-val",children:y.maxTokens})]})]}),c.jsx(Bc,{label:"Stream responses",sub:"Token-by-token output via SSE",checked:y.stream,onChange:C=>B("stream",C)}),c.jsx(Bc,{label:"JSON mode",sub:me?"Force valid JSON output":"Not supported by this model",checked:y.jsonMode&&me,disabled:!me,onChange:C=>B("jsonMode",C)}),c.jsxs("div",{className:"section-title",children:["Tools ",te?"":"(model has no tool support)"]}),y.tools.map((C,W)=>c.jsxs("div",{className:"tool-card",children:[c.jsxs("div",{className:"tc-head",children:[c.jsx("input",{type:"text",value:C.function.name,placeholder:"function_name",onChange:ie=>Ke(W,{name:ie.target.value})}),c.jsx("button",{className:"btn danger",onClick:()=>R(ie=>({...ie,tools:ie.tools.filter((w,Y)=>Y!==W)})),children:"✕"})]}),c.jsx("input",{type:"text",value:C.function.description??"",placeholder:"description",style:{marginBottom:8},onChange:ie=>Ke(W,{description:ie.target.value})}),c.jsx("textarea",{defaultValue:JSON.stringify(C.function.parameters??{},null,2),onChange:ie=>at(W,ie.target.value),spellCheck:!1}),c.jsx("div",{className:"hint",children:"JSON Schema for the function parameters."})]},C.id??W)),c.jsxs("div",{className:"btn-row",children:[c.jsx("button",{className:"btn block ghost mini",disabled:!te,onClick:()=>R(C=>({...C,tools:[...C.tools,{...structuredClone(px),id:Kf()}]})),children:"+ Add tool"}),c.jsx("button",{className:"btn block ghost mini",onClick:T,title:"Import tools from web/public/example-tools.json",children:"↓ Load example tools"})]}),ce&&c.jsx("div",{className:"hint",style:{color:ce.startsWith("Loaded")?"var(--accent-2)":"var(--muted-2)"},children:ce}),c.jsx("div",{className:"section-title",children:"Knowledge (RAG)"}),c.jsx(Bc,{label:"Ground answers in knowledge",sub:ne.length?`Retrieve from ${ne.length} doc${ne.length>1?"s":""} via embeddings`:"Add a document to enable",checked:y.useKnowledge&&ne.length>0,disabled:ne.length===0,onChange:C=>B("useKnowledge",C)}),ne.map(C=>c.jsxs("div",{className:"tool-card",style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:8},children:[c.jsxs("div",{style:{minWidth:0},children:[c.jsx("div",{style:{fontSize:13,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.name}),c.jsxs("div",{className:"hint",style:{margin:0},children:[C.chunks," chunks · ",C.chars.toLocaleString()," chars"]})]}),c.jsx("button",{className:"btn danger",onClick:()=>Ge(C.id),children:"✕"})]},C.id)),c.jsxs("div",{className:"field",style:{marginTop:10},children:[c.jsx("input",{type:"text",placeholder:"Document name (optional)",value:fe,onChange:C=>F(C.target.value),style:{marginBottom:8}}),c.jsx("textarea",{placeholder:"Paste text to give your bot a knowledge base…",value:P,onChange:C=>I(C.target.value),style:{minHeight:80}}),re&&c.jsx("div",{className:"hint",style:{color:"var(--danger)"},children:re}),c.jsx("button",{className:"btn block ghost mini",style:{marginTop:8},disabled:K||!P.trim(),onClick:_e,children:K?"Embedding…":"+ Add to knowledge base"})]}),c.jsx("div",{className:"section-title",children:"Voice"}),c.jsx(Bc,{label:"Speak replies aloud",sub:"Browser text-to-speech",checked:y.speak,onChange:C=>B("speak",C)}),c.jsxs("div",{className:"hint",children:[vy()?"Mic dictation available in the composer.":"Voice input not supported in this browser."," ","SCX-native audio (scx-tts/scx-stt) is gated on this tier."]}),c.jsx("div",{className:"section-title",children:"Session"}),c.jsxs("div",{className:"btn-row",children:[c.jsx("button",{className:"btn block ghost",onClick:L,children:"Clear chat"}),c.jsx("button",{className:"btn block ghost",onClick:z,children:"Export"})]})]}),c.jsxs("div",{className:"sidebar-foot",children:[c.jsx(X1,{}),ee&&c.jsx("button",{className:"btn ghost sm block",onClick:L1,children:"Sign out"}),c.jsxs("a",{className:"powered-by",href:"https://www.anthropic.com/claude/mythos",target:"_blank",rel:"noopener noreferrer","aria-label":"Reviewed by Claude Mythos 5.1",children:[c.jsx("span",{className:"powered-by-lead",children:"Reviewed by"}),c.jsx("img",{className:"powered-by-logo",src:"/claude-logo-ivory.svg",alt:"Claude",width:"83",height:"18"}),c.jsx("span",{className:"powered-by-model",children:"Mythos 5.1"})]})]})]})}function yx({runner:s,status:u,statusError:r,onOpen:o,sessions:d}){const[m,p]=k.useState(s.directory),[E,y]=k.useState(null),[R,b]=k.useState(!1),[v,S]=k.useState(!1);k.useEffect(()=>p(s.directory),[s.directory]);async function L(q=m){if(q.trim()){b(!0),y(null);try{o(await gy(q))}catch(ne){y(String(ne.message??ne))}finally{b(!1)}}}const B=s.recent.filter(q=>q!==s.directory),ee=(u==null?void 0:u.models.filter(q=>q.id.startsWith("scx/")).length)??0;return c.jsxs("div",{className:"sidebar-body",children:[c.jsx("div",{className:"section-title",children:"Project"}),c.jsxs("div",{className:"field",children:[c.jsxs("form",{className:"dir-row",onSubmit:q=>{q.preventDefault(),L()},children:[c.jsx("input",{type:"text",className:"mono",value:m,onChange:q=>p(q.target.value),placeholder:"C:\\code\\my-project",spellCheck:!1}),c.jsx("button",{className:"btn sm",type:"submit",disabled:R||!m.trim()||m===s.directory,children:"Open"})]}),E&&c.jsx("div",{className:"hint danger",children:E}),c.jsx("div",{className:"hint",children:"The agent reads, edits and runs commands in this folder. Switching folders starts a new session."}),c.jsxs("button",{className:"btn sm gh-open",onClick:()=>S(!0),title:"Clone a repository into the workspace (read-only)",children:[c.jsx(Oy,{size:13})," clone from GitHub"]}),v&&c.jsx(mx,{onOpen:q=>L(q),onClose:()=>S(!1)})]}),B.length>0&&c.jsxs("div",{className:"field",children:[c.jsx("label",{children:"Recent"}),c.jsx("div",{className:"recent-list",children:B.map(q=>c.jsxs("button",{className:"recent-item",onClick:()=>L(q),title:q,children:[c.jsx("span",{className:"recent-name",children:q.split(/[\\/]/).filter(Boolean).pop()}),c.jsx("span",{className:"recent-path mono",children:q})]},q))})]}),s.directory&&c.jsx(vx,{directory:s.directory,nav:d}),c.jsx("div",{className:"section-title",children:"Agents"}),c.jsxs("div",{className:"agent-info",children:[c.jsxs("div",{className:"ai-row",children:[c.jsx("span",{className:"ai-name",children:"build"}),c.jsx("span",{className:"hint",children:"edits & runs"})]}),c.jsx("div",{className:"hint ai-desc",children:"Every file edit and shell command waits for your approval."}),c.jsxs("div",{className:"ai-row",children:[c.jsx("span",{className:"ai-name",children:"plan"}),c.jsx("span",{className:"hint",children:"read-only"})]}),c.jsx("div",{className:"hint ai-desc",children:"Explores and reasons without changing anything."})]}),c.jsx("div",{className:"section-title",children:"Engine"}),r?c.jsx("div",{className:"hint danger",children:r}):c.jsxs("div",{className:"engine",children:[c.jsxs("div",{children:[c.jsx("span",{className:"muted",children:"Agent"}),c.jsx("span",{children:"OpenCode"})]}),c.jsxs("div",{children:[c.jsx("span",{className:"muted",children:"Provider"}),c.jsxs("span",{children:["SCX.ai · ",ee," models"]})]}),c.jsxs("div",{children:[c.jsx("span",{className:"muted",children:"Default"}),c.jsx("span",{className:"mono",children:(u==null?void 0:u.defaultModel)??"…"})]})]})]})}function vx({directory:s,nav:u}){const[r,o]=k.useState(null),[d,m]=k.useState(null),[p,E]=k.useState(null),[y,R]=k.useState(!1);k.useEffect(()=>{let S=!0;return Kb(s).then(L=>{S&&(o(L),m(null))}).catch(L=>S&&m(String(L.message??L))),()=>{S=!1}},[s,u.version,u.active]),k.useEffect(()=>{if(!p)return;const S=setTimeout(()=>E(null),3e3);return()=>clearTimeout(S)},[p]);async function b(S){if(p!==S){E(S);return}E(null);try{await $b(S,s),u.active===S&&u.open(null),o(L=>(L==null?void 0:L.filter(B=>B.id!==S))??null)}catch(L){m(String(L.message??L))}}const v=y?r??[]:(r??[]).slice(0,8);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"section-title",children:"Sessions"}),c.jsx("button",{className:"btn ghost sm block new-session",onClick:()=>u.open(null),children:"+ New session"}),d&&c.jsx("div",{className:"hint danger",children:d}),r&&r.length===0&&c.jsx("div",{className:"hint",children:"No past sessions in this folder yet."}),c.jsx("div",{className:"session-list",children:v.map(S=>c.jsxs("div",{className:"session-item"+(S.id===u.active?" on":""),children:[c.jsxs("button",{className:"session-open",onClick:()=>u.open(S.id),title:S.title,children:[c.jsx("span",{className:"session-title",children:S.title||"Untitled session"}),c.jsxs("span",{className:"session-meta",children:[bx(S.updated),S.files>0&&c.jsxs(c.Fragment,{children:[" · ",c.jsxs("span",{className:"adds",children:["+",S.additions]})," ",c.jsxs("span",{className:"dels",children:["−",S.deletions]})]})]})]}),c.jsx("button",{className:"session-del"+(p===S.id?" confirm":""),onClick:()=>b(S.id),title:p===S.id?"Click again to delete":"Delete session","aria-label":p===S.id?"Confirm delete":"Delete session",children:p===S.id?"Delete?":"✕"})]},S.id))}),r&&r.length>8&&c.jsx("button",{className:"btn ghost sm block",onClick:()=>R(S=>!S),children:y?"Show fewer":`Show all ${r.length}`})]})}function bx(s){if(!s)return"";const u=Math.max(0,(Date.now()-s)/1e3);return u<60?"just now":u<3600?`${Math.floor(u/60)}m ago`:u<86400?`${Math.floor(u/3600)}h ago`:u<7*86400?`${Math.floor(u/86400)}d ago`:new Date(s).toLocaleDateString()}function Bc({label:s,sub:u,checked:r,onChange:o,disabled:d}){return c.jsxs("div",{className:"toggle",children:[c.jsxs("div",{className:"tg-label",children:[s,u&&c.jsx("small",{children:u})]}),c.jsxs("label",{className:"switch"+(d?" disabled":""),children:[c.jsx("input",{type:"checkbox",checked:r,disabled:d,onChange:m=>o(m.target.checked)}),c.jsx("span",{})]})]})}function md(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var ni=md();function Ry(s){ni=s}var Fa={exec:()=>null};function Zi(s){let u=[];return r=>{let o=Math.max(0,Math.min(3,r-1)),d=u[o];return d||(d=s(o),u[o]=d),d}}function Ce(s,u=""){let r=typeof s=="string"?s:s.source,o={replace:(d,m)=>{let p=typeof m=="string"?m:m.source;return p=p.replace(Zt.caret,"$1"),r=r.replace(d,p),o},getRegex:()=>new RegExp(r,u)};return o}var xx=((s="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+s)}catch{return!1}})(),Zt={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:s=>new RegExp(`^( {0,3}${s})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:Zi(s=>new RegExp(`^ {0,${s}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:Zi(s=>new RegExp(`^ {0,${s}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:Zi(s=>new RegExp(`^ {0,${s}}(?:\`\`\`|~~~)`)),headingBeginRegex:Zi(s=>new RegExp(`^ {0,${s}}#`)),htmlBeginRegex:Zi(s=>new RegExp(`^ {0,${s}}(?:</?(?:${au})(?: +|$|/?>)|<(?:script|pre|style|textarea|!--))`,"i")),blockquoteBeginRegex:Zi(s=>new RegExp(`^ {0,${s}}>`))},Sx=/^(?:[ \t]*(?:\n|$))+/,Tx=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ex=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,lu=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Nx=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,pd=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Dy=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,zy=Ce(Dy).replace(/bull/g,pd).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),_x=Ce(Dy).replace(/bull/g,pd).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),gd=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,wx=/^[^\n]+/,yd=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,jx=Ce(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",yd).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ax=Ce(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,pd).getRegex(),au="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",vd=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,kx=Ce("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",vd).replace("tag",au).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),My=s=>Ce(gd).replace("hr",lu).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",s).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",au).getRegex(),Cx=My(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),Ox=My(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),Rx=Ce(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ox).getRegex(),bd={blockquote:Rx,code:Tx,def:jx,fences:Ex,heading:Nx,hr:lu,html:kx,lheading:zy,list:Ax,newline:Sx,paragraph:Cx,table:Fa,text:wx},Hg=Ce("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",lu).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",au).getRegex(),Dx={...bd,lheading:_x,table:Hg,paragraph:Ce(gd).replace("hr",lu).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Hg).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",au).getRegex()},zx={...bd,html:Ce(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",vd).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Fa,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Ce(gd).replace("hr",lu).replace("heading",` *#{1,6} *[^
|
|
54
54
|
]`).replace("lheading",zy).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Mx=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Ux=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Uy=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,Lx=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Yl=/[\p{P}\p{S}]/u,Fi=/[\s\p{P}\p{S}]/u,iu=/[^\s\p{P}\p{S}]/u,Hx=Ce(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Fi).getRegex(),Bx=/[\p{Pi}\p{Ps}"']/u,Ly=/(?!~)[\p{P}\p{S}]/u,qx=/(?!~)[\s\p{P}\p{S}]/u,Xx=/(?:[^\s\p{P}\p{S}]|~)/u,Gx=Ce(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",xx?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Hy=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Yx=Ce(Hy,"u").replace(/punct/g,Yl).getRegex(),Qx=Ce(Hy,"u").replace(/punct/g,Ly).getRegex(),Zx=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,Vx=Ce(Zx,"u").replace(/openQuote/g,Bx).replace(/punct/g,Yl).getRegex(),By="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Kx=Ce(By,"gu").replace(/notPunctSpace/g,iu).replace(/punctSpace/g,Fi).replace(/punct/g,Yl).getRegex(),Jx=Ce(By,"gu").replace(/notPunctSpace/g,Xx).replace(/punctSpace/g,qx).replace(/punct/g,Ly).getRegex(),$x="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",Ix=Ce($x,"gu").replace(/notPunctSpace/g,iu).replace(/punctSpace/g,Fi).replace(/punct/g,Yl).getRegex(),Fx=Ce("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,iu).replace(/punctSpace/g,Fi).replace(/punct/g,Yl).getRegex(),Wx="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",Px=Ce(Wx,"gu").replace(/notPunctSpace/g,iu).replace(/punctSpace/g,Fi).replace(/punct/g,Yl).getRegex(),eS=Ce(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,Yl).getRegex(),tS="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",nS=Ce(tS,"gu").replace(/notPunctSpace/g,iu).replace(/punctSpace/g,Fi).replace(/punct/g,Yl).getRegex(),lS=Ce(/\\(punct)/,"gu").replace(/punct/g,Yl).getRegex(),aS=Ce(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),iS=Ce(vd).replace("(?:-->|$)","-->").getRegex(),sS=Ce("^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",iS).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),qy=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,Jc=Ce(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",qy).getRegex(),uS=Ce(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label",Jc).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),cS=Ce(/^!?\[(label)\]\[(ref)\]/).replace("label",Jc).replace("ref",yd).getRegex(),rS=Ce(/^!?\[(ref)\](?:\[\])?/).replace("ref",yd).getRegex(),Bg=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,oS=Ce(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",qy).getRegex(),fS=Ce("reflink|nolink(?!\\()","g").replace("reflink",Ce(/^!?\[(label)\]\[(ref)\]/).replace("label",oS).replace("ref",Bg).getRegex()).replace("nolink",Ce(/^!?\[(ref)\](?:\[\])?/).replace("ref",Bg).getRegex()).getRegex(),qg=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,dS=/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/,hS=Ce(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,dS).getRegex(),xd={_backpedal:Fa,anyPunctuation:lS,autolink:aS,blockSkip:Gx,br:Uy,code:Ux,del:Fa,delLDelim:Fa,delRDelim:Fa,emStrongLDelim:Yx,emStrongRDelimAst:Kx,emStrongRDelimUnd:Fx,escape:Mx,link:uS,nolink:rS,punctuation:Hx,reflink:cS,reflinkSearch:fS,tag:sS,text:Lx,url:Fa},mS={...xd,emStrongLDelim:Vx,emStrongRDelimAst:Ix,emStrongRDelimUnd:Px,link:Ce(/^!?\[(label)\]\((.*?)\)/).replace("label",Jc).getRegex(),reflink:Ce(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Jc).getRegex()},Ff={...xd,emStrongRDelimAst:Jx,emStrongLDelim:Qx,delLDelim:eS,delRDelim:nS,url:Ce(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",hS).replace("protocol",qg).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:Ce(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace("protocol",qg).replace(/emailProtocol/g,/(?:mailto|xmpp):/).getRegex()},pS={...Ff,br:Ce(Uy).replace("{2,}","*").getRegex(),text:Ce(Ff.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},qc={normal:bd,gfm:Dx,pedantic:zx},$s={normal:xd,gfm:Ff,breaks:pS,pedantic:mS},gS={"&":"&","<":"<",">":">",'"':""","'":"'"},Xg=s=>gS[s];function Nn(s,u){if(u){if(Zt.escapeTest.test(s))return s.replace(Zt.escapeReplace,Xg)}else if(Zt.escapeTestNoEncode.test(s))return s.replace(Zt.escapeReplaceNoEncode,Xg);return s}function yS(s){return s.replace(Zt.numericCharacterReference,(u,r,o)=>{let d=r===void 0?Number.parseInt(o,16):Number.parseInt(r,10);return d===0||d>1114111||d>=55296&&d<=57343?"�":String.fromCodePoint(d)})}function Gg(s){try{s=encodeURI(s).replace(Zt.percentDecode,"%")}catch{return null}return s}function Yg(s,u){var m;let r=s.replace(Zt.findPipe,(p,E,y)=>{let R=!1,b=E;for(;--b>=0&&y[b]==="\\";)R=!R;return R?"|":" |"}),o=r.split(Zt.splitPipe),d=0;if(o[0].trim()||o.shift(),o.length>0&&!((m=o.at(-1))!=null&&m.trim())&&o.pop(),u)if(o.length>u)o.splice(u);else for(;o.length<u;)o.push("");for(;d<o.length;d++)o[d]=o[d].trim().replace(Zt.slashPipe,"|");return o}function va(s,u,r){let o=s.length;if(o===0)return"";let d=0;for(;d<o&&s.charAt(o-d-1)===u;)d++;return s.slice(0,o-d)}function Qg(s){let u=s.split(`
|
|
55
55
|
`),r=u.length-1;for(;r>=0&&Zt.blankLine.test(u[r]);)r--;return u.length-r<=2?s:u.slice(0,r+1).join(`
|
|
56
56
|
`)}function $c(s){return s.trim().toLowerCase().toUpperCase().toLowerCase()}function Zg(s,u){if(s.indexOf(u[0])===-1&&s.indexOf(u[1])===-1)return-1;let r=0;for(let o=0;o<s.length;o++)if(s[o]==="\\")o++;else if(s[o]===u[0])r++;else if(s[o]===u[1]&&(r--,r<0))return o;return r>0?-2:-1}function Vg(s,u=0){let r=u,o="";for(let d of s)if(d===" "){let m=4-r%4;o+=" ".repeat(m),r+=m}else o+=d,r++;return o}function Kg(s,u,r,o,d){let m=u.href,p=u.title||null,E=s[1].replace(d.other.outputLinkReplace,"$1"),y=s[0].charAt(0)==="!";o.state.inLink=!0;let R=o.state.linkEmitted,b=o.state.inRawBlock;o.state.linkEmitted=!1;let v=o.inlineTokens(E),S=o.state.linkEmitted;if(o.state.linkEmitted=R,o.state.inLink=!1,!y){if(S){o.state.inRawBlock=b;return}o.state.linkEmitted=!0}return{type:y?"image":"link",raw:r,href:m,title:p,text:E,tokens:v}}function vS(s,u,r){let o=s.match(r.other.indentCodeCompensation);if(o===null)return u;let d=o[1];return u.split(`
|
package/web/dist/index.html
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
12
12
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
13
13
|
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
|
14
|
-
<script type="module" crossorigin src="/assets/index-
|
|
14
|
+
<script type="module" crossorigin src="/assets/index-Crcy3YbK.js"></script>
|
|
15
15
|
<link rel="stylesheet" crossorigin href="/assets/index-D-MACAHb.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|