bugxhunter 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example CHANGED
@@ -24,6 +24,29 @@
24
24
  # has access (it may not appear in the Playground's live list even when it does).
25
25
  # ANTHROPIC_MODELS=claude-opus-5-5,claude-sonnet-5-5,claude-haiku-5-5,claude-mythos-5-2
26
26
 
27
+ # Optional: models on Amazon Bedrock in your own AWS account (GLM 5.3 by
28
+ # default), called directly. See "GLM 5.3 on Amazon Bedrock" in the README.
29
+ # BEDROCK_REGION=ap-southeast-2
30
+ # Ids the agent may use (the Playground lists them once a sign-in is set up).
31
+ # GLM 5.3 is global.zai.glm-5.3 from most regions, us.zai.glm-5.3 from US ones.
32
+ # BEDROCK_MODELS=global.zai.glm-5.3
33
+ # How hard Bedrock's reasoning models think when a call does not say: low,
34
+ # medium, high, xhigh or max. Unset = the model's default (max for GLM 5.3),
35
+ # which can spend a short output limit before any answer is written.
36
+ # BEDROCK_REASONING_EFFORT=medium
37
+ # Sign in with ONE of:
38
+ # - an AWS profile (IAM Identity Center / SSO, or an assumed role). In Docker,
39
+ # also uncomment the ~/.aws volume on the runner in docker-compose.yml.
40
+ # BEDROCK_AWS_PROFILE=my-sso-profile
41
+ # - an OIDC role (GitHub Actions, Kubernetes): the role, and the token's file.
42
+ # AWS_ROLE_ARN=arn:aws:iam::111122223333:role/bugxhunter-bedrock
43
+ # AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/tokens/aws
44
+ # - the compute's own role (EC2 instance profile; ECS needs nothing set).
45
+ # BEDROCK_AUTH=aws
46
+ # - a Bedrock API key: put it in the vault as AWS_BEARER_TOKEN_BEDROCK (keys
47
+ # dialog) rather than here.
48
+ # AWS_BEARER_TOKEN_BEDROCK=
49
+
27
50
  # GitHub needs nothing here: "Connect GitHub" in the sidebar signs in to the
28
51
  # public BugXHunter GitHub App (read-only). A fork that registers its own app
29
52
  # sets its Client ID and slug:
package/README.md CHANGED
@@ -15,7 +15,7 @@ green accents) and Fira Code throughout. Started from the `sovgov-poc` chatbot d
15
15
  `plan` (read-only) agent. Every file edit and shell command waits for your approval.
16
16
  Markdown replies, collapsible tool calls and reasoning, per-turn token counts, and a
17
17
  **Changes** view of what the agent edited (git repos only — OpenCode tracks changes via git).
18
- - **Playground** — chat with any SCX, Anthropic (Claude), NVIDIA or OpenRouter model directly (no agent), with
18
+ - **Playground** — chat with any SCX, Anthropic (Claude), NVIDIA, OpenRouter or Amazon Bedrock model directly (no agent), with
19
19
  tool-calling, JSON mode, an embeddings-backed knowledge base and browser voice. Also:
20
20
  - **Security presets** (code review, threat modelling, AI system review, pentest planning,
21
21
  diagram review, diagram drawing, tabletop exercises, CTF coaching, phishing, log triage,
@@ -29,6 +29,9 @@ green accents) and Fira Code throughout. Started from the `sovgov-poc` chatbot d
29
29
  - **Images** for vision models, and **draw.io files** (`.drawio`, compressed or not, and
30
30
  `.drawio.svg`) for any model: the file becomes an exact text outline of its zones, boxes,
31
31
  legend colours and arrows, so labels are never misread.
32
+ - **Text files** (`.md`, `.markdown`, `.txt`) for any model, in chat, compare mode and the
33
+ canvas: a design note, a written description of a system or a log excerpt is read in the
34
+ browser and sent in full. Up to 5 files of 512 KB each per message.
32
35
  - **Diagrams in replies**: a model writes a ```` ```drawio ```` spec and the app draws it as an
33
36
  editable `.drawio.svg` ([drawgen](https://github.com/cintelis/drawio-tools)), checks it, and
34
37
  can send the problems back for a fix.
@@ -215,6 +218,92 @@ The agent never holds the key: its calls go to the runner's `/openrouter/v1` pro
215
218
  token, exactly like SCX, in both local and Docker modes. Pricing is OpenRouter's; the Playground
216
219
  shows each model's per-token rates.
217
220
 
221
+ ## GLM 5.3 on Amazon Bedrock
222
+
223
+ The runner can call models on [Amazon Bedrock](https://aws.amazon.com/bedrock/) directly, in your
224
+ own AWS account: GLM 5.3 by default, through Bedrock's OpenAI-compatible endpoint
225
+ (`bedrock-runtime.<region>.amazonaws.com/openai/v1`). The **Playground** lists them under an
226
+ **Amazon Bedrock** heading as `bedrock/<id>`; the **agent** gets them as `bedrock/<id>` too.
227
+
228
+ Set the region with `BEDROCK_REGION` (else `AWS_REGION`), then sign in one of these ways. The first
229
+ that is set up is used, and a Bedrock API key wins over all of them:
230
+
231
+ | Sign-in | Set | Use it when |
232
+ |---|---|---|
233
+ | **OIDC role** (web identity) | `AWS_ROLE_ARN` and `AWS_WEB_IDENTITY_TOKEN_FILE` | The runner runs where an identity provider issues it a token: GitHub Actions, Kubernetes (EKS IRSA), another OIDC issuer the role trusts. Nothing long-lived exists: the runner trades the token for role credentials through STS and renews them itself |
234
+ | **AWS profile** | `BEDROCK_AWS_PROFILE` (else `AWS_PROFILE`) | The runner is on your own machine. An IAM Identity Center (SSO) profile gives short-lived credentials that `aws sso login` renews; a profile with `role_arn` narrows them to a role that may only invoke the model |
235
+ | **The compute's role** | nothing on ECS; `BEDROCK_AUTH=aws` on EC2 or with a default profile | The runner is deployed in AWS: a task role, pod identity or instance profile |
236
+ | **Access keys** | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` (and `AWS_SESSION_TOKEN`) | Temporary keys pasted for a session. Avoid an IAM user's long-lived keys |
237
+ | **Bedrock API key** | vault item `AWS_BEARER_TOKEN_BEDROCK` (keys dialog), or `AWS_BEARER_TOKEN_BEDROCK_FILE` | You cannot give the runner an AWS identity. Sealed in the vault like the other keys. Short-term keys last 12 hours at most; a long-term key is an IAM user's standing credential, which AWS recommends for exploration only |
238
+
239
+ **Which to choose:** a role the runner is given beats anything it has to hold. Deployed in AWS, use
240
+ the compute's role; in CI or Kubernetes, the OIDC role; on your own machine, an SSO profile. Keep
241
+ the API key and access keys for when none of those is possible.
242
+
243
+ In Docker the profile needs your AWS config: uncomment the `~/.aws` volume on the `runner` service
244
+ in `docker-compose.yml` (read-only, and only the runner gets it), set `BEDROCK_AWS_PROFILE` and
245
+ `BEDROCK_REGION` in `.env`, and set `BEDROCK_MODELS=global.zai.glm-5.3` so the agent's picker shows
246
+ the model. When the SSO session lapses, model calls answer with a 503 that says so: run
247
+ `aws sso login` on the host and carry on, no restart needed. On Linux the files under `~/.aws` must
248
+ be readable by the container's user (uid 1000).
249
+
250
+ As with every provider, the agent holds nothing: its calls go to the runner's `/bedrock/v1` proxy
251
+ with the proxy token, and the runner signs them (SigV4) or adds the key. AWS credentials are
252
+ removed from the runner's environment at start-up, so the agent's shell does not inherit them in
253
+ local mode either.
254
+
255
+ Things to know:
256
+
257
+ - **Locking the vault stops Bedrock too.** AWS credentials are not vault items, so once a vault
258
+ exists the runner refuses to sign while it is sealed (model calls answer 503) and drops the
259
+ credentials it holds in memory. The first call after an unlock loads them afresh from the
260
+ profile or role. This is a gate in the runner, not encryption: a mounted `~/.aws` stays readable
261
+ to the runner's container, so give it a profile that can do no more than invoke the model.
262
+ - **Reasoning effort.** GLM 5.3 on Bedrock reasons at `max` effort unless told otherwise, and
263
+ reasoning counts against the output limit: at a 4,096-token limit a request can spend all of it
264
+ thinking and write nothing (the chat says so when that happens). The Playground's **Reasoning
265
+ effort** setting picks `low`, `medium`, `high`, `xhigh` or `max` per chat.
266
+ `BEDROCK_REASONING_EFFORT` sets the runner's default for every Bedrock call that names none,
267
+ the agent's included.
268
+ - **OpenAI's GPT models.** `global.openai.gpt-6.2-astra` and `global.openai.gpt-6-astra` are known
269
+ to the runner: add one to `BEDROCK_MODELS` to use it. They read images, so the threat-model
270
+ canvas can build from a screenshot. They take the output limit as `max_completion_tokens` and
271
+ refuse `stop` and any temperature or top-p but the default, so the runner renames the one and
272
+ drops the others. **They are for the Playground only**: Bedrock's Chat Completions route
273
+ refuses function tools for them (its Responses route takes them, which the runner does not
274
+ speak), so they are left out of the agent's model picker and the Playground sends them no tools.
275
+ They are not open-weight, and cost far more per token than GLM 5.3.
276
+ - **Only the models you list.** The agent can call a Bedrock model only if it is in
277
+ `BEDROCK_MODELS`; the proxy answers 403 for any other. The runner's AWS identity can usually
278
+ invoke more than that, and the agent runs untrusted input.
279
+ - **GLM 5.3 has no single-region form.** It is called through a cross-region inference profile:
280
+ `global.zai.glm-5.3` from most regions (inference may then run in any commercial AWS region), or
281
+ `us.zai.glm-5.3` from US regions only. Prompts, code and tool output go where the profile sends
282
+ them, so check that against where your engagement's data may be processed.
283
+ - **Access is per account.** AWS offers GLM 5.3 to eligible accounts only; one without it answers
284
+ `403 … is not available for this account` even though the model is listed.
285
+ - **Other ids.** `BEDROCK_MODELS` takes any model or inference-profile id the endpoint serves,
286
+ including the ARN of your own application inference profile (which puts the spend under that
287
+ profile's cost-allocation tags). Ids the runner has no metadata for get conservative limits.
288
+ - **Permissions.** The role needs `bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream`
289
+ on the inference profile and on the model behind it, and nothing else. A starting point:
290
+
291
+ ```json
292
+ {
293
+ "Version": "2012-10-17",
294
+ "Statement": [{
295
+ "Effect": "Allow",
296
+ "Action": ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"],
297
+ "Resource": [
298
+ "arn:aws:bedrock:ap-southeast-2:111122223333:inference-profile/global.zai.glm-5.3",
299
+ "arn:aws:bedrock:*::foundation-model/zai.glm-5.3"
300
+ ]
301
+ }]
302
+ }
303
+ ```
304
+
305
+ An API key also needs `bedrock:CallWithBearerToken`, which some organisations deny by policy.
306
+
218
307
  ## Claude via the Anthropic API
219
308
 
220
309
  1. Add your Anthropic key to the vault as `ANTHROPIC_API_KEY` (keys dialog). The **Playground**
@@ -371,6 +460,15 @@ nobody is there to unlock.
371
460
  | `ANTHROPIC_API_KEY` | the vault, else unset | Anthropic key in the clear; prefer the vault item of the same name |
372
461
  | `ANTHROPIC_MODELS` | `claude-opus-5-5,claude-sonnet-5-5,claude-haiku-5-5` | Claude model ids in the agent's picker (local mode; Docker: `docker/opencode.json`) |
373
462
  | `ANTHROPIC_BASE_URL` | `https://api.anthropic.com/v1` | Anthropic endpoint |
463
+ | `BEDROCK_REGION` | `AWS_REGION`, else `us-east-1` | AWS region whose Bedrock endpoint is called |
464
+ | `BEDROCK_MODELS` | `global.zai.glm-5.3` | Comma list of Bedrock model or inference-profile ids (Docker: set it to show them in the agent's picker) |
465
+ | `BEDROCK_REASONING_EFFORT` | unset (the model's default, `max` for GLM 5.3) | `low`, `medium`, `high`, `xhigh` or `max`: the effort for Bedrock calls that name none, from the Playground and the agent |
466
+ | `BEDROCK_AWS_PROFILE` | `AWS_PROFILE`, else unset | AWS profile (SSO, assumed role) the runner signs Bedrock calls with |
467
+ | `AWS_ROLE_ARN`, `AWS_WEB_IDENTITY_TOKEN_FILE` | unset | An OIDC role and the file holding the identity token; `AWS_ROLE_SESSION_NAME` names the session |
468
+ | `BEDROCK_AUTH` | unset | `aws` uses the compute's own role or the default profile (automatic on ECS) |
469
+ | `AWS_BEARER_TOKEN_BEDROCK_FILE` | unset | A file holding a Bedrock API key, as `SCX_API_FILE` |
470
+ | `AWS_BEARER_TOKEN_BEDROCK` | the vault, else unset | Bedrock API key in the clear; prefer the vault item of the same name. Wins over AWS credentials |
471
+ | `BEDROCK_BASE_URL` | the region's `bedrock-runtime` endpoint | Bedrock's OpenAI-compatible endpoint (for a VPC endpoint) |
374
472
  | `GITHUB_CLIENT_ID` | the BugXHunter app | A fork's own GitHub App (device flow); `GITHUB_APP_SLUG` names its install page |
375
473
  | `OPEN_RUNNER_VAULT_FILE` | `~/.config/bugxhunter/vault.json` | The sealed vault (Docker: `/data/vault.json` on the `runner-data` volume) |
376
474
  | `OPEN_RUNNER_VAULT_IDLE_MINUTES` | `120` | Auto-lock after this long without a model call or API write; `0` = never |
@@ -403,6 +501,8 @@ GHCR images by digest) and the signed `checksums.txt` that covers them all.
403
501
  <!-- releases:start -->
404
502
  | Release | Published | Checksums | Signature | Signature check | Build |
405
503
  | --- | --- | --- | --- | --- | --- |
504
+ | [v0.11.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.11.0) | 2026-11-26 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.11.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.11.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/45788161293) |
505
+ | [v0.10.0](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.10.0) | 2026-11-21 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.10.0/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.10.0/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/44896163152) |
406
506
  | [v0.9.7](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.9.7) | 2026-11-19 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.9.7/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.9.7/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/44437259098) |
407
507
  | [v0.9.6](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.9.6) | 2026-11-18 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.9.6/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.9.6/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/44381703840) |
408
508
  | [v0.9.5](https://github.com/cintelis/bugxhunter-runner/releases/tag/v0.9.5) | 2026-10-29 | [checksums.txt](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.9.5/checksums.txt) | [checksums.txt.sig](https://github.com/cintelis/bugxhunter-runner/releases/download/v0.9.5/checksums.txt.sig) | ✅ release key | [workflow run](https://github.com/cintelis/bugxhunter-runner/actions/runs/40882124130) |
@@ -491,9 +591,11 @@ publisher** on npmjs.com set to this repository and `release.yml`, once; no npm
491
591
  | `server/src/recon.ts`, `recon-driver.ts`, `recon-run.ts` | Supervised recon: the model router and approval gate, the driver loop, and the OpenCode side of a turn (`web/src/ReconPanel.tsx` is its UI) |
492
592
  | `server/src/scx.ts`, `rag.ts` | SCX client and in-memory knowledge base (Playground) |
493
593
  | `server/src/providers.ts`, `anthropic.ts`, `nvidia-health.ts` | Anthropic / NVIDIA / OpenRouter providers (Claude via the official SDK); hides NVIDIA models whose endpoints are retired |
594
+ | `server/src/bedrock.ts` | Amazon Bedrock: which AWS credentials the runner uses (OIDC role, profile, compute role) and the SigV4 signing of each call |
494
595
  | `server/src/playground-store.ts` | Saved Playground sessions, sealed with the vault key |
495
596
  | `server/src/render.ts`, `docker/render-server.py`, `docker/drawio_outline.py` | The render service (diagrams, `.drawio` outlines) and the runner's client for it |
496
597
  | `web/src/Canvas.tsx`, `web/src/canvas/` | The threat-model canvas |
598
+ | `web/src/imageAttach.tsx`, `textAttach.ts`, `wire.ts` | Attachments in the Playground's composers (images, draw.io files, Markdown and plain text) and how they are written into the message sent to the model |
497
599
  | `web/src/intel/`, `web/src/presets.ts`, `docker/agent-AGENTS.md` | The security catalogue (OWASP, ASVS, WSTG, STRIDE, MITRE ATLAS) as data, the prompts built from it, and the agent's methodology, which a test keeps in step with the catalogue |
498
600
  | `web/src/DrawioBlock.tsx`, `diagrams.ts` | Diagrams in replies |
499
601
  | `shared/` | Type contract between server and browser |
@@ -43,6 +43,22 @@ services:
43
43
  # (ANTHROPIC_API_KEY) or here; ANTHROPIC_MODELS lists the ids the agent's picker shows.
44
44
  ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
45
45
  ANTHROPIC_MODELS: ${ANTHROPIC_MODELS:-}
46
+ # Optional: models on Amazon Bedrock, called directly (GLM 5.3 by default). Sign in
47
+ # with ONE of these (see "Amazon Bedrock" in the README):
48
+ # - an AWS profile: mount your ~/.aws read-only (the volume below) and name the
49
+ # profile in BEDROCK_AWS_PROFILE. For an IAM Identity Center (SSO) profile,
50
+ # `aws sso login` on the host renews it; nothing long-lived is stored.
51
+ # - an OIDC role: AWS_ROLE_ARN plus AWS_WEB_IDENTITY_TOKEN_FILE (mount the token file).
52
+ # - a Bedrock API key: in the vault as AWS_BEARER_TOKEN_BEDROCK (keys dialog), or here.
53
+ # BEDROCK_MODELS lists the ids the agent may use (set it to show them in the Runner).
54
+ BEDROCK_REGION: ${BEDROCK_REGION:-}
55
+ BEDROCK_MODELS: ${BEDROCK_MODELS:-}
56
+ BEDROCK_REASONING_EFFORT: ${BEDROCK_REASONING_EFFORT:-} # low|medium|high|xhigh|max; unset = the model's default
57
+ BEDROCK_AWS_PROFILE: ${BEDROCK_AWS_PROFILE:-}
58
+ BEDROCK_AUTH: ${BEDROCK_AUTH:-}
59
+ AWS_ROLE_ARN: ${AWS_ROLE_ARN:-}
60
+ AWS_WEB_IDENTITY_TOKEN_FILE: ${AWS_WEB_IDENTITY_TOKEN_FILE:-}
61
+ AWS_BEARER_TOKEN_BEDROCK: ${AWS_BEARER_TOKEN_BEDROCK:-}
46
62
  # Supervised recon: the model profile (recon-open | recon-balanced | recon-quality;
47
63
  # default recon-balanced with an Anthropic key, recon-open without) and optional
48
64
  # per-role models. The agent gets the same per-role values (below).
@@ -63,6 +79,9 @@ services:
63
79
  - workspace:/workspace # same volume as the agent: attachments
64
80
  - logs:/logs # audit + egress logs; NOT mounted in the agent, so it can't edit them
65
81
  - runner-data:/data # the sealed key vault (ciphertext only; see SECURITY.md)
82
+ # Amazon Bedrock with an AWS profile (BEDROCK_AWS_PROFILE): uncomment to give the
83
+ # runner, and only the runner, your AWS config and SSO session, read-only.
84
+ # - ${HOME}/.aws:/home/node/.aws:ro
66
85
  ports:
67
86
  - "127.0.0.1:${OPEN_RUNNER_PORT:-8790}:8790" # localhost only; put TLS in front before exposing
68
87
  networks: [net, render]
@@ -87,6 +106,7 @@ services:
87
106
  SCX_PROXY_TOKEN: ${SCX_PROXY_TOKEN:?run docker/setup.ps1 first}
88
107
  OPENCODE_ENABLE_EXA: "1" # turns on OpenCode's websearch tool (Exa)
89
108
  OPENROUTER_MODELS: ${OPENROUTER_MODELS:-} # same list as runner: becomes an OpenCode provider via runner's proxy
109
+ BEDROCK_MODELS: ${BEDROCK_MODELS:-} # same list as runner; the AWS sign-in stays in the runner
90
110
  # Recon subagents run on open-weight models unless a role is set here (see docker/agent-entrypoint.sh).
91
111
  RECON_EXECUTOR_MODEL: ${RECON_EXECUTOR_MODEL:-}
92
112
  RECON_TRIAGE_MODEL: ${RECON_TRIAGE_MODEL:-}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugxhunter",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "BugXHunter: an AI security-testing agent with a sandboxed runner, a passkey-sealed key vault and read-only GitHub access. `npx bugxhunter` runs it on your machine.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://bugxhunter.com",
@@ -29,7 +29,10 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@anthropic-ai/sdk": "^1.3.0",
32
+ "@aws-sdk/credential-providers": "^3.1177.0",
32
33
  "@opencode-ai/sdk": "^1.17.11",
34
+ "@smithy/hash-node": "^4.5.2",
35
+ "@smithy/signature-v4": "^5.7.5",
33
36
  "dotenv": "^18.0.6",
34
37
  "express": "^5.2.1",
35
38
  "express-rate-limit": "^8.7.1",
@@ -0,0 +1,288 @@
1
+ /**
2
+ * Amazon Bedrock, called directly: open-weight models (GLM 5.3 by default) on
3
+ * Bedrock's OpenAI-compatible Chat Completions API,
4
+ * `https://bedrock-runtime.<region>.amazonaws.com/openai/v1`.
5
+ *
6
+ * Two ways to authenticate, both held by the runner and never by the agent:
7
+ *
8
+ * - AWS credentials, signing each call with SigV4. Where they come from, first
9
+ * match wins:
10
+ * 1. an OIDC web identity (AWS_ROLE_ARN + AWS_WEB_IDENTITY_TOKEN_FILE): the
11
+ * runner exchanges the token for short-lived role credentials through
12
+ * STS, and again whenever they are about to expire;
13
+ * 2. a shared profile (BEDROCK_AWS_PROFILE, else AWS_PROFILE) from
14
+ * ~/.aws/config: IAM Identity Center (SSO), an assumed role, or a
15
+ * credential process;
16
+ * 3. access keys in the environment (AWS_ACCESS_KEY_ID, ...);
17
+ * 4. the compute's own role (an ECS task role, EKS pod identity, an EC2
18
+ * instance profile): on ECS this is found by itself, elsewhere set
19
+ * BEDROCK_AUTH=aws.
20
+ * - A Bedrock API key (AWS_BEARER_TOKEN_BEDROCK), sent as a bearer token like
21
+ * every other provider's key. providers.ts reads it from the vault, a key
22
+ * file or the environment, and it wins over AWS credentials when both exist.
23
+ *
24
+ * AWS credentials are not vault items, so providers.ts gates them on the vault
25
+ * instead: once a vault exists nothing is signed while it is sealed, and
26
+ * sealing it drops the credentials held in memory here.
27
+ *
28
+ * Everything read from the environment here is removed from it, for the reason
29
+ * given in providers.ts: the OpenCode server is spawned with a copy of our
30
+ * environment, and the agent's shell inherits that.
31
+ */
32
+ import { fromIni, fromNodeProviderChain, fromTokenFile } from "@aws-sdk/credential-providers";
33
+ import { Hash } from "@smithy/hash-node";
34
+ import { SignatureV4 } from "@smithy/signature-v4";
35
+ import { httpError } from "./errors.js";
36
+ /** A region name, as it goes into the endpoint's host name. */
37
+ const REGION = /^[a-z]{2}(-[a-z]+)+-\d{1,2}$/;
38
+ function take(env, name) {
39
+ const value = env[name]?.trim();
40
+ delete env[name];
41
+ return value || undefined;
42
+ }
43
+ /** Read the Bedrock settings from `env`, removing the credential variables from it. */
44
+ export function readSettings(env = process.env) {
45
+ const named = env.BEDROCK_REGION?.trim() || env.AWS_REGION?.trim() || env.AWS_DEFAULT_REGION?.trim() || "us-east-1";
46
+ if (!REGION.test(named))
47
+ throw new Error(`BEDROCK_REGION: "${named}" is not an AWS region name (for example ap-southeast-2).`);
48
+ const region = named;
49
+ const baseUrl = (env.BEDROCK_BASE_URL?.trim() || `https://bedrock-runtime.${region}.amazonaws.com/openai/v1`).replace(/\/$/, "");
50
+ const accessKeyId = take(env, "AWS_ACCESS_KEY_ID");
51
+ const secretAccessKey = take(env, "AWS_SECRET_ACCESS_KEY");
52
+ const sessionToken = take(env, "AWS_SESSION_TOKEN");
53
+ const roleArn = take(env, "AWS_ROLE_ARN");
54
+ const tokenFile = take(env, "AWS_WEB_IDENTITY_TOKEN_FILE");
55
+ const sessionName = take(env, "AWS_ROLE_SESSION_NAME");
56
+ const ownProfile = take(env, "BEDROCK_AWS_PROFILE");
57
+ const profile = ownProfile ?? take(env, "AWS_PROFILE");
58
+ delete env.AWS_PROFILE;
59
+ const explicit = env.BEDROCK_AUTH?.trim().toLowerCase() === "aws";
60
+ const onEcs = Boolean(env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI || env.AWS_CONTAINER_CREDENTIALS_FULL_URI);
61
+ const base = { region, baseUrl };
62
+ if (roleArn && tokenFile) {
63
+ return {
64
+ ...base, mode: "web-identity", describe: `OIDC web identity, role ${roleArn}`,
65
+ credentials: fromTokenFile({
66
+ roleArn, webIdentityTokenFile: tokenFile, roleSessionName: sessionName ?? "bugxhunter-runner",
67
+ clientConfig: { region },
68
+ }),
69
+ };
70
+ }
71
+ if (profile) {
72
+ return {
73
+ ...base, mode: "profile", describe: `AWS profile "${profile}"`,
74
+ credentials: fromIni({ profile, clientConfig: { region } }),
75
+ };
76
+ }
77
+ if (accessKeyId && secretAccessKey) {
78
+ const fixed = { accessKeyId, secretAccessKey, ...(sessionToken ? { sessionToken } : {}) };
79
+ return {
80
+ ...base, mode: "static",
81
+ describe: sessionToken ? "temporary access keys in the environment" : "long-lived access keys in the environment",
82
+ credentials: async () => fixed,
83
+ };
84
+ }
85
+ if (explicit || onEcs) {
86
+ return {
87
+ ...base, mode: "chain", describe: "the compute's own AWS role",
88
+ credentials: fromNodeProviderChain({ clientConfig: { region } }),
89
+ };
90
+ }
91
+ return { ...base, mode: "none", describe: "none" };
92
+ }
93
+ /** Temporary credentials are replaced this long before they expire. */
94
+ const REFRESH_BEFORE_MS = 5 * 60_000;
95
+ /** Credentials without an expiry (a profile's static keys) are re-read this often, so a rotated file is noticed. */
96
+ const REREAD_MS = 5 * 60_000;
97
+ /**
98
+ * Cache a credential source: one lookup for concurrent callers, and a fresh one near expiry.
99
+ * `forget()` drops what is held, and the result of a lookup still in flight.
100
+ */
101
+ export function cached(source, now = Date.now) {
102
+ let held;
103
+ let pending;
104
+ let generation = 0;
105
+ const get = async () => {
106
+ if (held && now() < held.until)
107
+ return held.value;
108
+ if (pending)
109
+ return pending;
110
+ const mine = generation;
111
+ const lookup = source().then((value) => {
112
+ if (mine === generation) {
113
+ const expires = value.expiration?.getTime();
114
+ held = { value, until: expires ? expires - REFRESH_BEFORE_MS : now() + REREAD_MS };
115
+ }
116
+ return value;
117
+ }).finally(() => { if (pending === lookup)
118
+ pending = undefined; });
119
+ pending = lookup;
120
+ return lookup;
121
+ };
122
+ return Object.assign(get, {
123
+ forget() {
124
+ generation += 1;
125
+ held = undefined;
126
+ pending = undefined;
127
+ },
128
+ });
129
+ }
130
+ /** `request`'s headers with a SigV4 signature for Bedrock added (authorization, x-amz-date, and the session token if any). */
131
+ export async function signRequest(request, region, credentials, signingDate) {
132
+ const url = new URL(request.url);
133
+ const query = {};
134
+ for (const [k, v] of url.searchParams)
135
+ query[k] = v;
136
+ const signer = new SignatureV4({ service: "bedrock", region, credentials, sha256: Hash.bind(null, "sha256") });
137
+ const signed = await signer.sign({
138
+ method: request.method.toUpperCase(),
139
+ protocol: url.protocol,
140
+ hostname: url.hostname,
141
+ ...(url.port ? { port: Number(url.port) } : {}),
142
+ path: url.pathname,
143
+ query,
144
+ headers: { ...request.headers, host: url.host },
145
+ body: request.body,
146
+ }, signingDate ? { signingDate } : undefined);
147
+ const { host: _host, ...headers } = signed.headers;
148
+ return headers; // fetch sets Host itself, from the same URL
149
+ }
150
+ const oneLine = (e) => String(e?.message ?? e).replace(/\s+/g, " ").slice(0, 300);
151
+ export const settings = readSettings();
152
+ const source = settings.credentials ? cached(settings.credentials) : undefined;
153
+ /** Drop the AWS credentials held in memory (the vault was locked). The next call loads them afresh. */
154
+ export const forget = () => source?.forget();
155
+ /** Whether AWS credentials are set up for Bedrock (they may still fail to load: an SSO session can lapse). */
156
+ export const awsConfigured = () => settings.mode !== "none";
157
+ /** Sign one call to Bedrock with the runner's AWS credentials. Throws a 503 the client can explain. */
158
+ export async function sign(request) {
159
+ if (!source)
160
+ throw httpError(503, "No AWS credentials for Bedrock. Set BEDROCK_AWS_PROFILE, an OIDC role, or add AWS_BEARER_TOKEN_BEDROCK to the vault.");
161
+ let credentials;
162
+ try {
163
+ credentials = await source();
164
+ }
165
+ catch (e) {
166
+ const hint = settings.mode === "profile" ? " If it is an SSO profile, sign in again with `aws sso login`." : "";
167
+ throw httpError(503, `Could not load AWS credentials for Bedrock (${settings.describe}): ${oneLine(e)}.${hint}`);
168
+ }
169
+ return signRequest(request, settings.region, credentials);
170
+ }
171
+ const GLM_53 = { context: 1_000_000, output: 128_000, features: ["tools", "reasoning"] };
172
+ /**
173
+ * OpenAI's GPT models on Bedrock. Limits as OpenAI publishes them for the same models; they read
174
+ * images. Bedrock's Chat Completions route refuses function tools for them (its Responses route
175
+ * takes them, which the runner does not speak), so they are for the Playground, not the agent.
176
+ */
177
+ const GPT_ASTRA = { context: 1_050_000, output: 128_000, features: ["reasoning", "json_mode"], image: true, chatOnly: true };
178
+ /**
179
+ * Bedrock's OpenAI-compatible route has no model list, so the ids are named in
180
+ * BEDROCK_MODELS and the ones we know carry their limits here. GLM 5.3 has no
181
+ * single-region form: it is called through a cross-region inference profile,
182
+ * `global.` from most regions and `us.` from the US ones.
183
+ */
184
+ export const BEDROCK_CATALOGUE = {
185
+ "global.zai.glm-5.3": { ...GLM_53, name: "GLM 5.3 (Bedrock)", description: "Z.ai GLM 5.3 on Amazon Bedrock, through the global cross-region profile: inference may run in any commercial AWS region." },
186
+ "us.zai.glm-5.3": { ...GLM_53, name: "GLM 5.3 (Bedrock, US)", description: "Z.ai GLM 5.3 on Amazon Bedrock, kept to US regions. Callable from US regions only." },
187
+ "global.openai.gpt-6.2-astra": { ...GPT_ASTRA, name: "GPT-6.2 Astra (Bedrock)", description: "OpenAI GPT-6.2 Astra on Amazon Bedrock, through the global cross-region profile. Reads images. Not open-weight; sampling settings are fixed." },
188
+ "global.openai.gpt-6-astra": { ...GPT_ASTRA, name: "GPT-6 Astra (Bedrock)", description: "OpenAI GPT-6 Astra on Amazon Bedrock, through the global cross-region profile. Reads images. Not open-weight; sampling settings are fixed." },
189
+ };
190
+ /**
191
+ * OpenAI's hosted GPT models on Bedrock (not the open-weight gpt-oss ones), by id or by an
192
+ * inference profile of one. They take the output limit as `max_completion_tokens`, and refuse
193
+ * `stop` and any `temperature` or `top_p` but the default.
194
+ */
195
+ export const isOpenAiGpt = (model) => /(^|[./])openai\.gpt-(?!oss)/.test(model); // `/`: an ARN ends ".../openai.gpt-..."
196
+ /** Chat parameters the hosted GPT models refuse outright or accept only at their default. */
197
+ const GPT_REFUSED = ["temperature", "top_p", "stop", "frequency_penalty", "presence_penalty"];
198
+ /**
199
+ * A chat-completions request as the Bedrock model named in it accepts it. Returns the same
200
+ * object when there is nothing to change, so a caller can tell.
201
+ */
202
+ export function prepareRequest(params, effort = REASONING_EFFORT) {
203
+ let out = params;
204
+ const change = (next) => { out = next; };
205
+ if (effort && out.reasoning_effort === undefined)
206
+ change({ ...out, reasoning_effort: effort });
207
+ if (typeof out.model === "string" && isOpenAiGpt(out.model)) {
208
+ if (GPT_REFUSED.some((k) => out[k] !== undefined)) {
209
+ const kept = { ...out };
210
+ for (const k of GPT_REFUSED)
211
+ delete kept[k];
212
+ change(kept);
213
+ }
214
+ if (out.max_tokens !== undefined) {
215
+ const { max_tokens, ...rest } = out;
216
+ change({ ...rest, ...(rest.max_completion_tokens === undefined ? { max_completion_tokens: max_tokens } : {}) });
217
+ }
218
+ }
219
+ return out;
220
+ }
221
+ /**
222
+ * A Playground request without the tools a hosted GPT model would refuse the whole call over.
223
+ * The Playground sends whatever tools the chat has configured; the sidebar already shows such a
224
+ * model as having no tool support. The agent's calls are not touched: there the refusal must show.
225
+ */
226
+ export function withoutRefusedTools(params) {
227
+ if (typeof params.model !== "string" || !isOpenAiGpt(params.model))
228
+ return params;
229
+ if (params.tools === undefined && params.tool_choice === undefined)
230
+ return params;
231
+ const { tools: _tools, tool_choice: _choice, ...rest } = params;
232
+ return rest;
233
+ }
234
+ /** The models the agent may be offered: those in BEDROCK_MODELS that can call tools on this route. */
235
+ export const agentModels = () => BEDROCK_MODELS.filter((id) => !(BEDROCK_CATALOGUE[id]?.chatOnly ?? isOpenAiGpt(id)));
236
+ /** Whether the proxy may forward a call for this model: only the ids in BEDROCK_MODELS. */
237
+ export const allowsModel = (model) => typeof model === "string" && BEDROCK_MODELS.includes(model);
238
+ /** Model or inference-profile ids the Playground and agent may use (BEDROCK_MODELS, comma list). */
239
+ export const BEDROCK_MODELS = (process.env.BEDROCK_MODELS?.trim() || "global.zai.glm-5.3")
240
+ .split(",").map((s) => s.trim()).filter(Boolean);
241
+ /** Playground ids for Bedrock models: `bedrock/<model or inference-profile id>`. */
242
+ export const BEDROCK_PREFIX = "bedrock/";
243
+ // --- Reasoning effort -----------------------------------------------------------
244
+ /** The efforts Bedrock's Chat Completions route takes for GLM 5.3 (`none` and `minimal` are refused). */
245
+ export const REASONING_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
246
+ /** BEDROCK_REASONING_EFFORT as an effort, or undefined when it is not set. Throws on anything else. */
247
+ export function readReasoningEffort(value) {
248
+ const v = value?.trim().toLowerCase();
249
+ if (!v)
250
+ return undefined;
251
+ if (!REASONING_EFFORTS.includes(v)) {
252
+ throw new Error(`BEDROCK_REASONING_EFFORT: "${value}" is not one of ${REASONING_EFFORTS.join(", ")}.`);
253
+ }
254
+ return v;
255
+ }
256
+ /**
257
+ * The effort a Bedrock call gets when it names none (BEDROCK_REASONING_EFFORT). Unset, the
258
+ * model's own default stands, which for GLM 5.3 is `max`: thorough, but reasoning counts
259
+ * against the output limit, so a short limit can be spent before any answer is written.
260
+ */
261
+ export const REASONING_EFFORT = readReasoningEffort(process.env.BEDROCK_REASONING_EFFORT);
262
+ /** A chat-completions body as a JSON object, or undefined when it is not one. */
263
+ function bodyObject(body) {
264
+ if (!body.length)
265
+ return undefined;
266
+ try {
267
+ const parsed = JSON.parse(body.toString("utf8"));
268
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : undefined;
269
+ }
270
+ catch {
271
+ return undefined;
272
+ }
273
+ }
274
+ /**
275
+ * An agent's chat-completions body, as it arrives through the proxy, prepared for the model
276
+ * it names (see prepareRequest). Anything that is not a JSON object, or needs no change, is
277
+ * passed on byte for byte.
278
+ */
279
+ export function prepareBody(body, effort = REASONING_EFFORT) {
280
+ const parsed = bodyObject(body);
281
+ if (!parsed)
282
+ return body;
283
+ const prepared = prepareRequest(parsed, effort);
284
+ return prepared === parsed ? body : Buffer.from(JSON.stringify(prepared));
285
+ }
286
+ /** The model a proxied body names, if it is a JSON object that names one. */
287
+ export const bodyModel = (body) => bodyObject(body)?.model;
288
+ //# sourceMappingURL=bedrock.js.map
@@ -11,7 +11,8 @@ import express from "express";
11
11
  import fs from "node:fs";
12
12
  import path from "node:path";
13
13
  import { SCXError } from "./scx.js";
14
- import { PROVIDERS, PROXY_TOKEN, PORT, OPENROUTER_MODELS, apiKey, clients, clientFor, configured, isRetiredStatus, keySource, listModels, proxyPaths, proxyTokenOk, upstreamHeaders, } from "./providers.js";
14
+ import { PROVIDERS, PROXY_TOKEN, PORT, OPENROUTER_MODELS, clients, clientFor, configured, isRetiredStatus, keySource, listModels, proxyBody, proxyHeaders, proxyPaths, proxyRefusal, proxyTokenOk, } from "./providers.js";
15
+ import { REASONING_EFFORT as bedrockEffort, settings as bedrockSettings } from "./bedrock.js";
15
16
  import { KnowledgeBase, buildContextBlock } from "./rag.js";
16
17
  import { getClient, serverUrl, resolveDirectory, projectFile, listAgentModels, toUiEvent, toUiMessages, parseModelId, oc, query, httpError, SessionFamily, childSessions, markInterrupted, DEFAULT_DIRECTORY, DEFAULT_MODEL, REMOTE_URL, REPO_ROOT, ALLOWED_ROOTS, } from "./opencode.js";
17
18
  import { mountAuth, authRequired, issueSession } from "./auth.js";
@@ -63,10 +64,16 @@ for (const p of Object.values(PROVIDERS)) {
63
64
  chunks.push(c);
64
65
  const ctrl = new AbortController();
65
66
  res.on("close", () => ctrl.abort());
66
- const upstream = await fetch(p.baseUrl + sub + (req.url.includes("?") ? req.url.slice(req.url.indexOf("?")) : ""), {
67
+ const url = p.baseUrl + sub + (req.url.includes("?") ? req.url.slice(req.url.indexOf("?")) : "");
68
+ const received = Buffer.concat(chunks);
69
+ const refusal = req.method === "POST" ? proxyRefusal(p, received) : null;
70
+ if (refusal)
71
+ return res.status(403).json({ error: { message: refusal, type: "model_not_offered" } });
72
+ const body = req.method === "GET" || req.method === "HEAD" ? undefined : proxyBody(p, received);
73
+ const upstream = await fetch(url, {
67
74
  method: req.method,
68
- headers: upstreamHeaders(p, req.headers, apiKey(p.id)),
69
- body: req.method === "GET" || req.method === "HEAD" ? undefined : Buffer.concat(chunks),
75
+ headers: await proxyHeaders(p, req.headers, { method: req.method, url, body }),
76
+ body,
70
77
  signal: ctrl.signal,
71
78
  });
72
79
  res.status(upstream.status);
@@ -1015,13 +1022,16 @@ const server = app.listen(PORT, process.env.HOST ?? "127.0.0.1", () => {
1015
1022
  vault: "vault",
1016
1023
  file: "a key file (not in the clear in the environment)",
1017
1024
  env: ".env — consider moving it into the vault",
1025
+ aws: `AWS credentials (${bedrockSettings.describe}), region ${bedrockSettings.region}`,
1018
1026
  "opencode-auth": "OpenCode's auth.json — consider moving it into the vault",
1019
1027
  none: p.id === "scx" ? "none yet — set up the vault in the sidebar" : "not configured (optional)",
1020
1028
  }[src];
1021
- console.log(` ${p.name} key: ${where}`);
1029
+ console.log(` ${p.name} ${src === "aws" ? "sign-in" : "key"}: ${where}`);
1022
1030
  }
1023
1031
  if (vault.isInitialised())
1024
1032
  console.log(` vault: ${vault.VAULT_FILE} (${vault.isUnsealed() ? "unsealed" : "sealed — unlock it in the UI"})`);
1033
+ if (bedrockEffort && keySource("bedrock") !== "none")
1034
+ console.log(` Amazon Bedrock reasoning effort: ${bedrockEffort} (unless a call sets its own)`);
1025
1035
  if (OPENROUTER_MODELS.length)
1026
1036
  console.log(` OpenRouter models for the agent: ${OPENROUTER_MODELS.join(", ")}`);
1027
1037
  console.log(` agent: ${REMOTE_URL ? `remote OpenCode at ${REMOTE_URL}` : "local OpenCode"}`);
@@ -20,7 +20,7 @@ import { execFileSync } from "node:child_process";
20
20
  import { fileURLToPath } from "node:url";
21
21
  import { createOpencodeServer, createOpencodeClient } from "@opencode-ai/sdk";
22
22
  import { httpError } from "./errors.js";
23
- import { anthropicOpencodeProvider, openrouterOpencodeProvider, nvidiaOpencodeProvider, ANTHROPIC_MODELS, OPENROUTER_MODELS, PORT } from "./providers.js";
23
+ import { anthropicOpencodeProvider, bedrockOpencodeProvider, openrouterOpencodeProvider, nvidiaOpencodeProvider, ANTHROPIC_MODELS, OPENROUTER_MODELS, PORT } from "./providers.js";
24
24
  import { reconAgents, setAnthropicAvailable, tierOrder, withScrubbedEnv } from "./recon.js";
25
25
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
26
26
  /** BugXHunter's own folder: the default project when none is chosen. */
@@ -50,7 +50,7 @@ export const VISION_AGENT = {
50
50
  /**
51
51
  * Config layered on the user's own OpenCode setup. With OPENROUTER_MODELS set,
52
52
  * it adds an `openrouter` provider that calls back through this server's
53
- * key-injecting proxy, so the OpenRouter key stays in the vault. NVIDIA and
53
+ * key-injecting proxy, so the OpenRouter key stays in the vault. NVIDIA, Bedrock and
54
54
  * Anthropic work the same way when their keys are configured (Claude through
55
55
  * OpenCode's native Anthropic client, the ids in ANTHROPIC_MODELS).
56
56
  */
@@ -74,7 +74,8 @@ async function inlineConfig() {
74
74
  };
75
75
  }
76
76
  }
77
- const provider = { ...(openrouter ? { openrouter } : {}), ...(nvidia ? { nvidia } : {}), ...(anthropic ? { anthropic } : {}) };
77
+ const bedrock = bedrockOpencodeProvider(`http://127.0.0.1:${PORT}/bedrock/v1`);
78
+ const provider = { ...(openrouter ? { openrouter } : {}), ...(nvidia ? { nvidia } : {}), ...(anthropic ? { anthropic } : {}), ...(bedrock ? { bedrock } : {}) };
78
79
  return {
79
80
  model: DEFAULT_MODEL,
80
81
  agent: {