diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 029b742102..7b5a961c7e 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -134,7 +134,8 @@ jobs: run: | PIN=src/core/project/backends/boxRelease.json REPO=$(jq -er .box.repo "$PIN") - VER=$(jq -er .box.version "$PIN") + # A build may name its own release, for a release whose build of this machine is broken. + VER=$(jq -er ".box.${BUILD}.version // .box.version" "$PIN") ASSET=$(jq -er ".box.${BUILD}.asset" "$PIN") SHA=$(jq -er ".box.${BUILD}.sha256" "$PIN") # macOS's sha256sum passes a malformed checksum line, so check the hash's shape first. diff --git a/README.md b/README.md index 0b5ea60bb1..541f2ef314 100644 --- a/README.md +++ b/README.md @@ -214,10 +214,11 @@ to a Box project, and refuses a TypeScript runtime and a Bedrock Agent import th `agentcore export harness` refuses a Box project. Each box runtime needs its `"box": { "version": ... }` in `agentcore.json`, which create and add runtime write, and its local box profile; build and deploy stop without them. Build derives the AgentCore Runtime profile of -each runtime from its local profile. box comes from the public GitHub release `v0.1.11-preview.10` of -[mquang-amazon/box-releases](https://github.com/mquang-amazon/box-releases). No token or account -is needed to download it. Use that release's build for your machine for `agentcore dev` and the -profile checks of `build`: an older box cannot read the profiles that this CLI writes. +each runtime from its local profile. box comes from the `box-cli` archives of the public GitHub +release `v0.3.0` of [strands-agents/box](https://github.com/strands-agents/box/releases). No token +or account is needed to download it. Use that release's build for your machine for `agentcore dev` +and the profile checks of `build`: an older box cannot read the profiles that this CLI writes. On +macOS, use the build of `v0.3.0-preview.1` instead: the macOS build of `v0.3.0` does not run. `src/core/project/backends/boxRelease.json` pins the Linux build of box that ships to AgentCore Runtime, with its repository, version and SHA-256. It also pins the macOS arm64 build, which the e2e @@ -260,7 +261,7 @@ agentcore invoke --runtime agent --session-id my-box-session-0000000000000000000 agentcore logs runtime --name agent --since 15m --query '"running profile"' ``` -The CodeBuild log of the deploy shows `/tmp/box.tar.gz: OK` and `box 0.1.11-preview.10`. The +The CodeBuild log of the deploy shows `/tmp/box.tar.gz: OK` and `box 0.3.0`. The second answer should say teal, and the runtime log shows `running profile ...` with no `ERROR`, `blocked by egress control` or `AccessDenied` line. For a CodeZip agent, use `--template agent-python-strands-box` and skip the container settings. @@ -283,7 +284,7 @@ private VPC with no internet path. It writes `"containment": "PRIVATE_VPC"` on t - `ExpiredTokenException` from `aws` or `deploy`: your AWS credentials expired. Refresh them and run the command again. - `curl: (22) The requested URL returned error: 404` in the CodeBuild log, or a deploy error that - names the release URL: the pinned version is not published in `mquang-amazon/box-releases`. + names the release URL: the pinned version is not published in `strands-agents/box`. - `SHA-256 ... not the pinned` or `sha256sum: WARNING: 1 computed checksum did NOT match`: the release asset changed after it was pinned. Nothing was installed. - `box run` exits with an error in the runtime log: box refused its profile, and the agent does diff --git a/docs/box-local-testing.md b/docs/box-local-testing.md index e5e7ad5dac..bc54379dfe 100644 --- a/docs/box-local-testing.md +++ b/docs/box-local-testing.md @@ -16,7 +16,7 @@ A Box project ships box inside its deploy artifact, so the agent runs in a box o Each box runtime names its box release in `agentcore.json` with `"box": { "version": "" }`, which `agentcore create` writes and build keeps at the pinned release. `agentcore build` and `agentcore deploy` download the pinned release's Linux build from -[mquang-amazon/box-releases](https://github.com/mquang-amazon/box-releases) once into +[strands-agents/box](https://github.com/strands-agents/box/releases) once into `~/.agentcore/box/`, check its SHA-256s, and stage it into the zip, for a CodeZip runtime. For a container they write the release and its checksum into `.box-dist/box-release.env` instead. A container image downloads the Linux build while it builds, under `agentcore dev` too. For a CodeZip @@ -32,10 +32,11 @@ only for the box templates. The runtime's entry point and Dockerfile never decid Every box runtime runs the box version the CLI pins in `src/core/project/backends/boxRelease.json`. Build and deploy set each runtime's `box.version` to it, and say so when it named another; container `dev` stages the pinned box whatever `box.version` says. To try an unreleased box build, publish it -as a GitHub pre-release with the release's file names (the `aarch64-apple-darwin` and -`aarch64-unknown-linux-gnu` archives and `SHA256SUMS.txt`), for example in a fork of -[mquang-amazon/box-releases](https://github.com/mquang-amazon/box-releases), then run -`bun scripts/bump-box-release.ts --box --box-repo ` in your CLI checkout. +as a GitHub pre-release with the release's file names (the `box-cli-v-aarch64-apple-darwin` +and `box-cli-v-aarch64-unknown-linux-gnu` archives and `SHA256SUMS.txt`), for example in a +fork of [strands-agents/box](https://github.com/strands-agents/box), then run +`bun scripts/bump-box-release.ts --box --box-repo ` in your CLI checkout. Add +`--darwin-box ` to take the macOS build from another release of the same repository. ## Prerequisites @@ -43,7 +44,8 @@ as a GitHub pre-release with the release's file names (the `aarch64-apple-darwin [aws/agentcore-l3-cdk-constructs#470](https://github.com/aws/agentcore-l3-cdk-constructs/pull/470), as its `box-integration` branch does. The Box gateway that `create` writes has `enableApplicationLogs`, and an older L3 refuses it at synth with a `ConfigValidationError`. -- `box` `0.1.11-preview.10` on your `PATH`, the release the CLI pins. Use that release: the box +- `box` `0.3.0` on your `PATH` (`0.3.0-preview.1` on macOS), the release the CLI pins. Use that + release: the box features and the profiles that the CLI writes change together, so an older box can refuse the profiles. The CLI does not check the version of the box on your `PATH` yet. Build, deploy and dev run it to read the box profile with `box profile show --format json --full`, and CodeZip dev runs @@ -55,40 +57,43 @@ as a GitHub pre-release with the release's file names (the `aarch64-apple-darwin ## Install box box ships as a release archive per machine on -[mquang-amazon/box-releases](https://github.com/mquang-amazon/box-releases). There are builds for -macOS on an Apple chip (`aarch64-apple-darwin`) and Linux arm64 (`aarch64-unknown-linux-gnu`); there -is no x86 build yet. Each archive unpacks flat: `box`, its two helpers, `release.json`, and -`resources/` (box's packs, which it finds beside itself). +[strands-agents/box](https://github.com/strands-agents/box/releases). The CLI uses the `box-cli-v-*` archives, with builds +for macOS on an Apple chip (`aarch64-apple-darwin`), Linux arm64 (`aarch64-unknown-linux-gnu`) and +Linux x86_64 (`x86_64-unknown-linux-gnu`). The release's `box-v-*` archives hold box +without its packs; do not use them. Each `box-cli` archive unpacks flat: `box`, its two helpers, +`release.json`, and `resources/` (box's packs, which it finds beside itself). Download the archive for your machine, check it, and unpack it into a versioned folder. -macOS on an Apple chip: +macOS on an Apple chip, from `v0.3.0-preview.1`: the macOS build of `v0.3.0` does not run. ``` -mkdir -p ~/.local/share/box/0.1.11-preview.10 && cd ~/.local/share/box/0.1.11-preview.10 -curl -fSLO https://github.com/mquang-amazon/box-releases/releases/download/v0.1.11-preview.10/box-v0.1.11-preview.10-aarch64-apple-darwin.tar.gz -curl -fSLO https://github.com/mquang-amazon/box-releases/releases/download/v0.1.11-preview.10/SHA256SUMS.txt -grep aarch64-apple-darwin SHA256SUMS.txt | shasum -a 256 -c - -tar -xzf box-v0.1.11-preview.10-aarch64-apple-darwin.tar.gz +mkdir -p ~/.local/share/box/0.3.0-preview.1 && cd ~/.local/share/box/0.3.0-preview.1 +curl -fSLO https://github.com/strands-agents/box/releases/download/v0.3.0-preview.1/box-cli-v0.3.0-preview.1-aarch64-apple-darwin.tar.gz +curl -fSLO https://github.com/strands-agents/box/releases/download/v0.3.0-preview.1/SHA256SUMS.txt +grep box-cli-v0.3.0-preview.1-aarch64-apple-darwin SHA256SUMS.txt | shasum -a 256 -c - +tar -xzf box-cli-v0.3.0-preview.1-aarch64-apple-darwin.tar.gz ``` Linux arm64: ``` -mkdir -p ~/.local/share/box/0.1.11-preview.10 && cd ~/.local/share/box/0.1.11-preview.10 -curl -fSLO https://github.com/mquang-amazon/box-releases/releases/download/v0.1.11-preview.10/box-v0.1.11-preview.10-aarch64-unknown-linux-gnu.tar.gz -curl -fSLO https://github.com/mquang-amazon/box-releases/releases/download/v0.1.11-preview.10/SHA256SUMS.txt -grep aarch64-unknown-linux-gnu SHA256SUMS.txt | sha256sum -c - -tar -xzf box-v0.1.11-preview.10-aarch64-unknown-linux-gnu.tar.gz +mkdir -p ~/.local/share/box/0.3.0 && cd ~/.local/share/box/0.3.0 +curl -fSLO https://github.com/strands-agents/box/releases/download/v0.3.0/box-cli-v0.3.0-aarch64-unknown-linux-gnu.tar.gz +curl -fSLO https://github.com/strands-agents/box/releases/download/v0.3.0/SHA256SUMS.txt +grep box-cli-v0.3.0-aarch64-unknown-linux-gnu SHA256SUMS.txt | sha256sum -c - +tar -xzf box-cli-v0.3.0-aarch64-unknown-linux-gnu.tar.gz ``` The check must print `OK`. -Put the folder first on your `PATH`, for this shell and for new ones (use `~/.bashrc` for bash): +Put the folder first on your `PATH`, for this shell and for new ones (use `~/.bashrc` for bash). +`BOX_VERSION` is the folder you unpacked into: `0.3.0-preview.1` on macOS, `0.3.0` on Linux. ``` -export PATH="$HOME/.local/share/box/0.1.11-preview.10:$PATH" -grep -q 'share/box/0.1.11-preview.10' ~/.zshrc || echo 'export PATH="$HOME/.local/share/box/0.1.11-preview.10:$PATH"' >> ~/.zshrc +BOX_VERSION=0.3.0-preview.1 +export PATH="$HOME/.local/share/box/$BOX_VERSION:$PATH" +grep -q "share/box/$BOX_VERSION" ~/.zshrc || echo "export PATH=\"\$HOME/.local/share/box/$BOX_VERSION:\$PATH\"" >> ~/.zshrc ``` The `grep -q ... ||` adds the line only once, so running it again does not repeat it. When you move @@ -103,11 +108,11 @@ box --version - `which box` must name the folder you unpacked into. An older `box` earlier on your `PATH` (a source build, or Box Core's `box` in `/usr/local/bin`) wins otherwise. -- `box --version` should print the pinned `box 0.1.11-preview.10` (from +- `box --version` should print the pinned `box 0.3.0`, or `box 0.3.0-preview.1` on macOS (from `src/core/project/backends/boxRelease.json`). An older box can refuse the profiles that the CLI writes. - On macOS, if Gatekeeper refuses to run `box`, clear the download flag with - `xattr -dr com.apple.quarantine "$HOME/.local/share/box/0.1.11-preview.10"`. + `xattr -dr com.apple.quarantine "$HOME/.local/share/box/0.3.0-preview.1"`. To move to a newer release, unpack it into its own folder the same way and change the `PATH` line to that folder. @@ -150,13 +155,16 @@ bun install ## 1. Get AWS credentials -Deploy creates real resources, so it needs write access. This example uses `ada` with an Isengard -dev account; use whatever grants credentials for your dev account. +Deploy creates real resources, so it needs write access to a development AWS account. Sign in +with IAM Identity Center, or configure access keys, in the profile you deploy with: ``` -ada credentials update --account --provider isengard --role Admin +aws configure sso --profile +export AWS_PROFILE= ``` +`aws configure` works too, for access keys. + ## 2. Build and pack the local L3 constructs `npm pack` makes a tarball you install into the generated CDK app. This is more reliable than a @@ -204,7 +212,7 @@ Runtime profile, its policy files, and box in the `.box-dist/` folder of the cod build context, and write a copy of the profile, the generated packs, and the policy files into `.box//aws/` for you to read. -Box `0.1.11-linux-preview.7` names its packs `@box/base`, `@box/bedrock`, and `@box/agentcore`. A +The pinned box names its packs `@box/base`, `@box/bedrock`, and `@box/agentcore`. A profile that names a pack `box/` fails: box refuses it and names the `@box/` pack. - **Gateway targets.** Each host or `host:port` that an `[egress]` entry, an `[mcp]` server with @@ -311,11 +319,12 @@ the usual way, and stops on one that has `box.version` with The box release has these builds: -| Machine | Build | CodeZip dev | Container dev | -| ------------------- | ------------------------------------------ | ----------- | ------------- | -| macOS, Apple chip | `box-v-aarch64-apple-darwin` | yes | yes | -| Linux, arm64 | `box-v-aarch64-unknown-linux-gnu` | yes | yes | -| Linux or macOS, x86 | none | no | no | +| Machine | Build | CodeZip dev | Container dev | +| ----------------- | ---------------------------------------------- | ----------- | ------------- | +| macOS, Apple chip | `box-cli-v-aarch64-apple-darwin` | yes | yes | +| Linux, arm64 | `box-cli-v-aarch64-unknown-linux-gnu` | yes | yes | +| Linux, x86_64 | `box-cli-v-x86_64-unknown-linux-gnu` | untested | no | +| macOS, Intel | none | no | no | - The **container** image always uses the Linux arm64 build, because AgentCore Runtime is arm64. It runs on an Apple chip Mac through Finch or Docker, and on an arm64 Linux host. An x86 host would @@ -631,7 +640,7 @@ These outlive the stack. Delete them too: often has no agent venv yet, and box then names `.venv/bin/python` under a write grant. The error then says to run `uv sync` in the agent's folder (`app/`). - **Build cannot download box.** The error names the release URL. Check your network; a 404 means - the pinned version is not published in `mquang-amazon/box-releases`. + the pinned version is not published in `strands-agents/box`. - **`create` fails with `ENOENT while resolving package '@opentelemetry/core'`.** The CLI's dependencies are not installed, so `bun` fell back to its global cache. Run `bun install` in the CLI checkout (see "Install the CLI's dependencies"). diff --git a/scripts/bump-box-release.ts b/scripts/bump-box-release.ts index 17feb06df5..835e194815 100644 --- a/scripts/bump-box-release.ts +++ b/scripts/bump-box-release.ts @@ -6,7 +6,10 @@ installs on its macOS runner. It reads the release's SHA256SUMS.txt, so the file changes only to a version whose archives are published. It imports nothing from src/. - bun scripts/bump-box-release.ts --box [--box-repo ] + bun scripts/bump-box-release.ts --box [--darwin-box ] [--box-repo ] + + --darwin-box pins the macOS build of another release of the same repository, for a release whose + macOS build is broken. Without it, macOS comes from the --box release. **/ import { join, resolve } from "node:path"; @@ -27,6 +30,7 @@ const { values } = parseArgs({ args: Bun.argv.slice(2), options: { box: { type: "string" }, + "darwin-box": { type: "string" }, "box-repo": { type: "string" }, }, }); @@ -48,18 +52,32 @@ async function checksums(repo: string, version: string): Promise { + // The box CLI archive, which holds box, its helpers, its packs and release.json. A release's + // `box-v-*` archives hold only box and its helpers, with no packs. + const asset = `box-cli-v${version}-${target}.tar.gz`; + const sha256 = (await checksums(repo, version)).get(asset); if (!sha256) throw new Error(`${repo} v${version} lists no ${asset}`); return { target, asset, sha256 }; } + +const pinned = await Bun.file(FILE).json(); +const repo = values["box-repo"] ?? pinned.box.repo; +const version = values.box; +const darwinVersion = values["darwin-box"] ?? version; console.log(`box: ${pinned.box.repo} ${pinned.box.version} → ${repo} ${version}`); -const box = { repo, version, linux: pin(LINUX_TARGET), darwin: pin(DARWIN_TARGET) }; +if (darwinVersion !== version) console.log(`box macOS: ${darwinVersion}`); +const darwin = await pin(repo, darwinVersion, DARWIN_TARGET); +const box = { + repo, + version, + linux: await pin(repo, version, LINUX_TARGET), + darwin: darwinVersion === version ? darwin : { version: darwinVersion, ...darwin }, +}; await Bun.write(FILE, `${JSON.stringify({ box }, null, 2)}\n`); diff --git a/src/core/project/__fixtures__/box-network-build-stopped.golden.txt b/src/core/project/__fixtures__/box-network-build-stopped.golden.txt index 0f3b829682..f794d82221 100644 --- a/src/core/project/__fixtures__/box-network-build-stopped.golden.txt +++ b/src/core/project/__fixtures__/box-network-build-stopped.golden.txt @@ -5,7 +5,7 @@ Build stopped: 10 problems in the Box profile and agentcore.json. Build wrote no .box/agent_python_strands/local/policy.dw:7:1 This rule allows requests to every host, and each gateway target needs one fixed host. Add a condition that names each host, for example context.input.host == "api.example.com". .box/agent_python_strands/local/profile.toml:3:1 The rule "pack_mirrors", which a pack in `packs` adds, allows each host that matches "*.mirror.example.com", and each gateway target needs one fixed host. Name each host in the rule, for example context.input.host == "api.example.com". .box/agent_python_strands/local/profile.toml:3:1 [egress.legacy], which a pack in `packs` adds, reads its secret from credsd://prod, and the gateway cannot read credsd. Use an env:// secret, which build stores as an API key credential. -.box/agent_python_strands/local/profile.toml:50:1 [egress.signed] signs requests to api.example.com with aws://default, and the gateway signs only for Bedrock, AgentCore, and Lambda function URL hosts. Use an env:// secret for this host, or remove the secret. -.box/agent_python_strands/local/profile.toml:54:1 [egress.wide] has the wildcard destination "*.wide.example.com", and each gateway target needs one fixed host. Name each host in `destinations`. -.box/agent_python_strands/local/profile.toml:58:1 [mcp.docs] has the destination "docs.example.com/mcp", and the gateway route of an MCP server takes a host with no path. Remove /mcp from the destination. The agent's MCP client keeps the path in its URL. +.box/agent_python_strands/local/profile.toml:47:1 [egress.signed] signs requests to api.example.com with aws://default, and the gateway signs only for Bedrock, AgentCore, and Lambda function URL hosts. Use an env:// secret for this host, or remove the secret. +.box/agent_python_strands/local/profile.toml:51:1 [egress.wide] has the wildcard destination "*.wide.example.com", and each gateway target needs one fixed host. Name each host in `destinations`. +.box/agent_python_strands/local/profile.toml:55:1 [mcp.docs] has the destination "docs.example.com/mcp", and the gateway route of an MCP server takes a host with no path. Remove /mcp from the destination. The agent's MCP client keeps the path in its URL. agentcore/agentcore.json The gateway target 'gh' for api.github.com sends the API key credential 'github' in the header Authorization with the prefix Bearer, and [egress.github] sends no credential. Make the two the same, in agentcore.json or in .box/agent_python_strands/local/profile.toml. \ No newline at end of file diff --git a/src/core/project/__fixtures__/box-profile-show-open-routes.json b/src/core/project/__fixtures__/box-profile-show-open-routes.json deleted file mode 100644 index 59def0174f..0000000000 --- a/src/core/project/__fixtures__/box-profile-show-open-routes.json +++ /dev/null @@ -1 +0,0 @@ -{"profile":"open","packs":[{"name":"box/base","version":"1"}],"policies":["policy.dw"],"storage":"/private/tmp/acbox/home/.box/storage/open/default","project":null,"inputs":[{"name":"terminal.colorterm","value":"truecolor","source":"default"},{"name":"terminal.term","value":"xterm-256color","source":"env:TERM"}],"skipped":[],"dropped":[],"open_routes":[{"route":"auth","destinations":"login.example.com, auth.example.com:8443"},{"route":"github","destinations":"api.github.com"}],"copies":[],"links":[],"parts":[],"mcp":{"unstarted":[],"servers":[],"dropped":[],"path_dropped":[],"skipped":[],"unread":[]},"warnings":[],"box_toml":{"name":"open-preview","box_dir":"/private/tmp/acbox/home/.box/runs/open-preview/box","policy":"policy.dw","file-attributes":true,"agent":{"command":["/bin/sh"],"workspace":"/private/tmp/acbox/demo","env":{"COLORTERM":"truecolor","PATH":"/usr/bin:/bin","TERM":"xterm-256color"},"filesystem":{"deny":["/private/tmp/acbox/demo/.box"]}},"tool":{"uname":{"command":["/usr/bin/uname"],"env":{"PATH":"/usr/bin:/bin","TMPDIR":"/private/tmp/acbox/home/.box/runs/open-preview/tool-tmp/uname"},"filesystem":{"read":["/private/tmp/acbox/home/.box/runs/open-preview/tool-tmp/uname"],"write":["/private/tmp/acbox/home/.box/runs/open-preview/tool-tmp/uname"],"deny":["/private/tmp/acbox/demo/.box"]}}},"egress":{"keyed":{"destinations":["k.example.com:8443"],"secret":{"ref":"env://KEY"}}},"telemetry":{"records":{"destination":"/private/tmp/acbox/home/.box/runs/open-preview/records.jsonl","include":["deny","permit","trace","logs"],"kind":"file"}}},"policy":"// No admin paths on GitHub.\n@id(\"no_admin\") forbid (principal, action == Box::Action::\"http:request\", resource) when { context.input.host == \"api.github.com\" && context.input.path like \"/admin/*\" };\n\n@id(\"spawn_uname\") permit (principal, action == Box::Action::\"shell:spawn\", resource) when { context.input.program_path == \"/usr/bin/uname\" && context.input.program == \"uname\" };\n\n@id(\"route_auth_connect\") permit (principal, action == Box::Action::\"net:connect\", resource) when { (context.input.host == \"login.example.com\" && context.input.port == 443) || (context.input.host == \"auth.example.com\" && context.input.port == 8443) };\n@id(\"route_auth_request\") permit (principal, action == Box::Action::\"http:request\", resource) when { context.input.host == \"login.example.com\" || context.input.host == \"auth.example.com\" };\n@id(\"route_github_connect\") permit (principal, action == Box::Action::\"net:connect\", resource) when { (context.input.host == \"api.github.com\" && context.input.port == 443) };\n@id(\"route_github_request\") permit (principal, action == Box::Action::\"http:request\", resource) when { context.input.host == \"api.github.com\" };\n@id(\"route_keyed_connect\") permit (principal, action == Box::Action::\"net:connect\", resource) when { (context.input.host == \"k.example.com\" && context.input.port == 8443) };\n@id(\"route_keyed_request\") permit (principal, action == Box::Action::\"http:request\", resource) when { context.input.host == \"k.example.com\" };\n@id(\"box_home_write\") forbid (principal, action == Box::Action::\"fs:write\", resource) when { (context.input.path == \"~/.box\" || context.input.path like \"~/.box/*\") };\n@id(\"box_home_delete\") forbid (principal, action == Box::Action::\"fs:delete\", resource) when { (context.input.path == \"~/.box\" || context.input.path like \"~/.box/*\") };\n@id(\"box_home_move\") forbid (principal, action == Box::Action::\"fs:move\", resource) when { (context.input.path == \"~/.box\" || context.input.path like \"~/.box/*\") };\n\n@id(\"project_configuration_write\") forbid (principal, action == Box::Action::\"fs:write\", resource) when { context.input.path == \"/private/tmp/acbox/demo/.box\" || context.input.path like \"/private/tmp/acbox/demo/.box/*\" };\n@id(\"project_configuration_delete\") forbid (principal, action == Box::Action::\"fs:delete\", resource) when { context.input.path == \"/private/tmp/acbox/demo/.box\" || context.input.path like \"/private/tmp/acbox/demo/.box/*\" };\n@id(\"project_configuration_move\") forbid (principal, action == Box::Action::\"fs:move\", resource) when { context.input.path == \"/private/tmp/acbox/demo/.box\" || context.input.path like \"/private/tmp/acbox/demo/.box/*\" };\n"} diff --git a/src/core/project/backends/boxCodeZip.test.ts b/src/core/project/backends/boxCodeZip.test.ts index 43ff085c00..5d7e43dcfb 100644 --- a/src/core/project/backends/boxCodeZip.test.ts +++ b/src/core/project/backends/boxCodeZip.test.ts @@ -93,8 +93,6 @@ describe("stageBoxCodeZip", () => { expect(await readFile(join(dist, "resources", "shared", "base", "pack.toml"), "utf8")).toBe( "[pack]\n", ); - // box 0.1.11-mquang.preview.9 runs the Runtime's Python with no ffi shim. - expect(existsSync(join(dist, "ffi"))).toBe(false); // The Runtime profile is the one build derived from the local profile. const { runtimeProfile, runtimeProfileHeader } = model([]); expect(await readFile(join(dist, "profile.toml"), "utf8")).toBe( diff --git a/src/core/project/backends/boxRelease.json b/src/core/project/backends/boxRelease.json index 4a12171690..bfa3417c5a 100644 --- a/src/core/project/backends/boxRelease.json +++ b/src/core/project/backends/boxRelease.json @@ -1,16 +1,17 @@ { "box": { - "repo": "mquang-amazon/box-releases", - "version": "0.1.11-preview.10", + "repo": "strands-agents/box", + "version": "0.3.0", "linux": { "target": "aarch64-unknown-linux-gnu", - "asset": "box-v0.1.11-preview.10-aarch64-unknown-linux-gnu.tar.gz", - "sha256": "45740d3ea768783b9a8939111ea0a26efd2dacf27ffa86104a4634ce1c2dc583" + "asset": "box-cli-v0.3.0-aarch64-unknown-linux-gnu.tar.gz", + "sha256": "9c7c01b22374b0041823429ba068745829ac3800db7c43b762f1836b54b40658" }, "darwin": { + "version": "0.3.0-preview.1", "target": "aarch64-apple-darwin", - "asset": "box-v0.1.11-preview.10-aarch64-apple-darwin.tar.gz", - "sha256": "76a3909c5c99c435b6ead470be2f401a22c6155b5b60652263bfb1af3ef57e18" + "asset": "box-cli-v0.3.0-preview.1-aarch64-apple-darwin.tar.gz", + "sha256": "eaf085e443d0a1f6c9e5566194e786274c5bf30d6f7681923221f5680317bb77" } } } diff --git a/src/core/project/backends/boxRelease.test.ts b/src/core/project/backends/boxRelease.test.ts index 9f215f1d9f..59dcb4d8cf 100644 --- a/src/core/project/backends/boxRelease.test.ts +++ b/src/core/project/backends/boxRelease.test.ts @@ -31,7 +31,7 @@ async function temp(prefix: string): Promise { } const BINARIES = ["box", "strands-box-sock-alias", "strands-box-contain-trampoline"]; -const VERSION = "9.9.9-linux-preview.1"; +const VERSION = BOX_RELEASE.version; /** A tarball of `files` (relative path to content), and its SHA-256. */ async function tarball(name: string, files: Record) { @@ -56,13 +56,13 @@ async function fakeRelease(boxFiles?: Record) { "resources/config.toml": "", "release.json": JSON.stringify({ box_version: VERSION }), }; - const box = await tarball(`box-v${VERSION}-aarch64-unknown-linux-gnu.tar.gz`, files); + const box = await tarball(`box-cli-v${VERSION}-aarch64-unknown-linux-gnu.tar.gz`, files); const release: BoxRelease = { - repo: "owner/box-releases", + repo: BOX_RELEASE.repo, version: VERSION, linux: { target: "aarch64-unknown-linux-gnu", - asset: `box-v${VERSION}-aarch64-unknown-linux-gnu.tar.gz`, + asset: `box-cli-v${VERSION}-aarch64-unknown-linux-gnu.tar.gz`, sha256: box.sha256, }, }; @@ -107,7 +107,7 @@ describe("resolveBoxLinuxBuild from the box release", () => { expect( commands.filter((command) => command[0] === "curl").map((command) => command.at(-1)), ).toEqual([ - `https://github.com/owner/box-releases/releases/download/v${VERSION}/${release.linux.asset}`, + `https://github.com/${BOX_RELEASE.repo}/releases/download/v${VERSION}/${release.linux.asset}`, ]); }); @@ -187,7 +187,7 @@ describe("resolveBoxLinuxBuild from the box release", () => { ); await expect(resolveBoxLinuxBuild({}, { runner, home, release })).rejects.toThrow( - /has no release\.json for box 9\.9\.9-linux-preview\.1, or no box packs/, + `has no release.json for box ${VERSION}, or no box packs`, ); }); @@ -201,7 +201,7 @@ describe("resolveBoxLinuxBuild from the box release", () => { const result = resolveBoxLinuxBuild({}, { runner, home, release }); await expect(result).rejects.toThrow( - /downloaded from https:\/\/github\.com\/owner\/box-releases\/releases\/download\/v9\.9\.9-linux-preview\.1\/box-v/, + `downloaded from https://github.com/${BOX_RELEASE.repo}/releases/download/v${VERSION}/box-cli-v`, ); await expect(result).rejects.toThrow(/HTTP 404: Not Found/); }); @@ -254,24 +254,30 @@ describe("publishInstall", () => { describe("the pinned releases", () => { test("pins one box: the asset of its own version, its SHA-256, and its release page", () => { expect(BOX_RELEASE.linux.asset).toBe( - `box-v${BOX_RELEASE.version}-aarch64-unknown-linux-gnu.tar.gz`, + `box-cli-v${BOX_RELEASE.version}-aarch64-unknown-linux-gnu.tar.gz`, ); expect(BOX_RELEASE.linux.sha256).toMatch(/^[0-9a-f]{64}$/); - // The e2e workflow installs the macOS build on its macOS runner, from this pin. + // The e2e workflow installs the macOS build on its macOS runner, from this pin, of its own + // release when it names one. expect(BOX_RELEASE.darwin?.asset).toBe( - `box-v${BOX_RELEASE.version}-aarch64-apple-darwin.tar.gz`, + `box-cli-v${BOX_RELEASE.darwin?.version ?? BOX_RELEASE.version}-aarch64-apple-darwin.tar.gz`, ); expect(BOX_RELEASE.darwin?.sha256).toMatch(/^[0-9a-f]{64}$/); expect(BOX_RELEASE_PAGE).toBe( - `https://github.com/mquang-amazon/box-releases/releases/tag/v${BOX_RELEASE.version}`, + `https://github.com/strands-agents/box/releases/tag/v${BOX_RELEASE.version}`, ); }); - test("the install hint names the pinned release", () => { + test("the install hint names the box-cli archive of the pinned release, and the macOS release", () => { + // The macOS build of 0.3.0 does not run, so macOS gets the darwin pin's release. expect(BOX_INSTALL_HINT).toBe( - "Install box: download the build for your machine from " + - `https://github.com/mquang-amazon/box-releases/releases/tag/v${BOX_RELEASE.version}, unpack it ` + - "into a folder (tar -xzf -C ), and add that folder to your PATH.", + "Install box: download box-cli-v0.3.0-.tar.gz for your machine from " + + "https://github.com/strands-agents/box/releases/tag/v0.3.0 (not a box-v0.3.0-* archive, " + + "which has no packs), unpack it into a folder (tar -xzf -C ), and add " + + "that folder to your PATH. On macOS, use " + + "box-cli-v0.3.0-preview.1-aarch64-apple-darwin.tar.gz from " + + "https://github.com/strands-agents/box/releases/tag/v0.3.0-preview.1 instead: the macOS " + + "build of 0.3.0 does not run.", ); }); }); diff --git a/src/core/project/backends/boxRelease.ts b/src/core/project/backends/boxRelease.ts index 59dc93fb58..36a565ff28 100644 --- a/src/core/project/backends/boxRelease.ts +++ b/src/core/project/backends/boxRelease.ts @@ -26,13 +26,15 @@ const TargetAssetSchema = AssetSchema.extend({ target: z.string().min(1) }); /** * A box release: the Linux arm64 build that ships to AgentCore Runtime. Its archive holds box, * its helpers, its packs and release.json. `darwin`, the macOS arm64 build, is what the e2e - * workflow installs on its macOS runner; the CLI does not read it. + * workflow installs on its macOS runner; the CLI does not read it. Its own `version`, when set, + * names the release it comes from instead of `version`, for a release whose macOS build is + * broken. */ const BoxReleaseSchema = z.object({ repo: z.string().min(1), version: z.string().min(1), linux: TargetAssetSchema, - darwin: TargetAssetSchema.optional(), + darwin: TargetAssetSchema.extend({ version: z.string().min(1).optional() }).optional(), }); export type BoxRelease = z.infer; @@ -48,6 +50,18 @@ export const BOX_RELEASE: BoxRelease = PINNED.box; /** The GitHub release page of the pinned box, with a build for each machine it supports. */ export const BOX_RELEASE_PAGE = `https://github.com/${BOX_RELEASE.repo}/releases/tag/v${BOX_RELEASE.version}`; +/** + * Where macOS gets box when the darwin pin names its own release, because the pinned release's + * macOS build does not run; empty otherwise. + */ +const DARWIN_VERSION = BOX_RELEASE.darwin?.version; +export const BOX_MACOS_HINT = + DARWIN_VERSION !== undefined && DARWIN_VERSION !== BOX_RELEASE.version + ? `On macOS, use ${BOX_RELEASE.darwin?.asset} from ` + + `https://github.com/${BOX_RELEASE.repo}/releases/tag/v${DARWIN_VERSION} instead: the ` + + `macOS build of ${BOX_RELEASE.version} does not run.` + : ""; + /** Where a release's asset downloads from: the public GitHub release, no token needed. */ export function boxReleaseAssetUrl( release: Pick, @@ -68,8 +82,10 @@ export const BOX_BINARIES = [ * dev ask for when it is not on PATH. */ export const BOX_INSTALL_HINT = - `Install box: download the build for your machine from ${BOX_RELEASE_PAGE}, unpack it into ` + - "a folder (tar -xzf -C ), and add that folder to your PATH."; + `Install box: download box-cli-v${BOX_RELEASE.version}-.tar.gz for your machine from ` + + `${BOX_RELEASE_PAGE} (not a box-v${BOX_RELEASE.version}-* archive, which has no packs), unpack ` + + "it into a folder (tar -xzf -C ), and add that folder to your PATH." + + (BOX_MACOS_HINT === "" ? "" : ` ${BOX_MACOS_HINT}`); /** A Linux arm64 box for AgentCore Runtime. */ export type BoxLinuxBuild = { diff --git a/src/core/project/boxNetwork/policyParser.test.ts b/src/core/project/boxNetwork/policyParser.test.ts index 43e13bd184..1e50b86487 100644 --- a/src/core/project/boxNetwork/policyParser.test.ts +++ b/src/core/project/boxNetwork/policyParser.test.ts @@ -6,7 +6,7 @@ const HR = 'action == Box::Action::"http:request"'; const NO_ADMIN = `@id("no_admin") forbid (principal, ${HR}, resource) when { context.input.host == "api.github.com" && context.input.path like "/admin/*" };`; const MORE = `@id("more_rule") forbid (principal, ${HR}, resource) when { context.input.host == "example.com" };`; -/** Box's policy as box 0.1.11 prints it for two policy files and the route `github`. */ +/** Box's policy as box prints it for two policy files and the route `github`. */ const RESOLVED = [ "// No admin paths on GitHub.", NO_ADMIN, diff --git a/src/core/project/boxProfileResolver-test-support.ts b/src/core/project/boxProfileResolver-test-support.ts index 130a7cde0f..42ce15bac8 100644 --- a/src/core/project/boxProfileResolver-test-support.ts +++ b/src/core/project/boxProfileResolver-test-support.ts @@ -1,6 +1,6 @@ /** * A stand-in for `box profile show --format json --full`, for the tests of the Box network, and the - * network rules that box 0.1.11 prints. `boxProfileResolver.test.ts` compares the rules with the + * network rules that box prints. `boxProfileResolver.test.ts` compares the rules with the * real box when one with `--format json --full` is on PATH. */ import type { BoxProfileResolver, ResolvedBoxProfile } from "./boxProfileResolver"; diff --git a/src/core/project/boxProfileResolver.test.ts b/src/core/project/boxProfileResolver.test.ts index 1fa99c31ba..ad1d94b931 100644 --- a/src/core/project/boxProfileResolver.test.ts +++ b/src/core/project/boxProfileResolver.test.ts @@ -97,25 +97,21 @@ const SHOWN_POLICY = boxReachRules("mcp", "docs", ["docs.example.com"]); /** The last sentence of each error that says to install another box: the pinned release. */ -const INSTALL = `Install box ${BOX_RELEASE.version} (https://github.com/mquang-amazon/box-releases/releases/tag/v${BOX_RELEASE.version}), then retry.`; +const INSTALL = + `Install box ${BOX_RELEASE.version} (https://github.com/strands-agents/box/releases/tag/v${BOX_RELEASE.version}), then retry. ` + + "On macOS, use box-cli-v0.3.0-preview.1-aarch64-apple-darwin.tar.gz from " + + "https://github.com/strands-agents/box/releases/tag/v0.3.0-preview.1 instead: the macOS build " + + "of 0.3.0 does not run."; /** * `box profile show open --format json --full` for a profile with the routes `auth` and `github` * with no secret, the route `keyed` with one, and {@link POLICY}, as box prints it, with HOME at - * /tmp/acbox/home. Box 0.1.11-linux-preview.6 joins the destinations of an open route into one - * string, and 0.1.11-linux-preview.7 prints the second, a list. preview.6 printed the first for the - * same profile with its pack named box/base, the name it had before `@box/`. + * /tmp/acbox/home. */ -const OPEN_ROUTES_SHOWN = Object.entries({ - "one string": readFileSync( - join(import.meta.dir, "__fixtures__", "box-profile-show-open-routes.json"), - "utf8", - ), - "a list": readFileSync( - join(import.meta.dir, "__fixtures__", "box-profile-show-open-routes-list.json"), - "utf8", - ), -}); +const OPEN_ROUTES_SHOWN = readFileSync( + join(import.meta.dir, "__fixtures__", "box-profile-show-open-routes-list.json"), + "utf8", +); describe("parseBoxProfileShow", () => { test("takes the box.toml as a table in the order of the file, the policy.dw, the packs, and the warnings", () => { @@ -164,20 +160,17 @@ describe("parseBoxProfileShow", () => { ); }); - test.each(OPEN_ROUTES_SHOWN)( - "takes each open route, which box.toml leaves out, and its destinations from %s", - (_, shown) => { - const resolved = parseBoxProfileShow(shown, ".box/profile.toml"); - - expect(resolved.openRoutes).toEqual([ - { route: "auth", destinations: ["login.example.com", "auth.example.com:8443"] }, - { route: "github", destinations: ["api.github.com"] }, - ]); - expect(resolved.boxToml.egress).toEqual({ - keyed: { destinations: ["k.example.com:8443"], secret: { ref: "env://KEY" } }, - }); - }, - ); + test("takes each open route, which box.toml leaves out, and its destinations", () => { + const resolved = parseBoxProfileShow(OPEN_ROUTES_SHOWN, ".box/profile.toml"); + + expect(resolved.openRoutes).toEqual([ + { route: "auth", destinations: ["login.example.com", "auth.example.com:8443"] }, + { route: "github", destinations: ["api.github.com"] }, + ]); + expect(resolved.boxToml.egress).toEqual({ + keyed: { destinations: ["k.example.com:8443"], secret: { ref: "env://KEY" } }, + }); + }); const document = JSON.parse(SHOWN) as Record; const { box_toml: _boxToml, ...noBoxToml } = document; @@ -316,7 +309,7 @@ describe("BoxCliProfileResolver", () => { }); test("says to install the pinned box when an older box refuses an @box/ pack", async () => { - // Box 0.1.11-linux-preview.6 wraps its error, here inside the pack name's line. + // An older box wraps its error, here inside the pack name's line. const error = await failure( refusal([ 'box: error: /work/demo/.box/profile.toml: "@box/base" is', diff --git a/src/core/project/boxProfileResolver.ts b/src/core/project/boxProfileResolver.ts index c12e939397..997ac616c8 100644 --- a/src/core/project/boxProfileResolver.ts +++ b/src/core/project/boxProfileResolver.ts @@ -9,7 +9,7 @@ import { z } from "zod"; import { InvalidEnvironmentError } from "../../errors/errors"; import { ProcessFailedError, streamProcess, type ProcessStreamer } from "../../io"; import { resolveExecutable } from "../../io/exec"; -import { BOX_RELEASE, BOX_RELEASE_PAGE } from "./backends/boxRelease"; +import { BOX_MACOS_HINT, BOX_RELEASE, BOX_RELEASE_PAGE } from "./backends/boxRelease"; /** A pack of the profile, at the version Box resolves it to. */ export interface BoxPack { @@ -46,7 +46,9 @@ export interface BoxProfileResolver { } /** What to install, which each error names when the `box` on PATH cannot resolve a profile. */ -const INSTALL_BOX = `Install box ${BOX_RELEASE.version} (${BOX_RELEASE_PAGE}), then retry.`; +const INSTALL_BOX = + `Install box ${BOX_RELEASE.version} (${BOX_RELEASE_PAGE}), then retry.` + + (BOX_MACOS_HINT === "" ? "" : ` ${BOX_MACOS_HINT}`); /** The refusal of an `@box/` pack by a box from before those names. */ const OLD_BOX_PACK_NAME = /"@box\/[^"\s]+" is not a pack name/; @@ -54,21 +56,11 @@ const OLD_BOX_PACK_NAME = /"@box\/[^"\s]+" is not a pack name/; /** The error of a box that has no `--format` or `--full` option, as clap prints it. */ const REFUSED_JSON = /(?:unexpected argument|Found argument) '--(?:format|full)'/; -/** - * The destinations of an open route, as a list: box 0.1.11-linux-preview.6 joins them into one - * string with ", ", and later boxes print a list. - */ -const OpenRouteDestinations = z - .union([z.string(), z.array(z.string())]) - .transform((destinations) => - typeof destinations === "string" ? destinations.split(", ") : destinations, - ); - /** The parts of the document of `box profile show --format json --full` that build reads. */ const BoxProfileShowSchema = z.object({ box_toml: z.record(z.string(), z.unknown()), policy: z.string(), - open_routes: z.array(z.object({ route: z.string(), destinations: OpenRouteDestinations })), + open_routes: z.array(z.object({ route: z.string(), destinations: z.array(z.string()) })), packs: z.array(z.object({ name: z.string(), version: z.string() })).default([]), warnings: z.array(z.string()).default([]), }); diff --git a/src/core/project/manager.boxNetwork.test.ts b/src/core/project/manager.boxNetwork.test.ts index 8b8dc011a5..418ac11562 100644 --- a/src/core/project/manager.boxNetwork.test.ts +++ b/src/core/project/manager.boxNetwork.test.ts @@ -316,16 +316,18 @@ describe("build writes the Box network of the box profile", () => { renderAwsMetadataPolicy(), ); const egress = profile.egress as Record; - // The route of [egress.github] keeps the name of its entry, and goes to its target. + // The route of [egress.github] keeps the name of its entry, and goes to its target. The + // Bedrock route is the api-key route of @box/bedrock, whose env:// secret box takes beside a + // backend. expect(Object.keys(egress).sort()).toEqual([ "agentcore", - "bedrock", + "bedrock-api-key", "egress-httpbin-org", "github", ]); expect(egress.github).toEqual(gatewayRoute("egress-github", "api.github.com")); expect(egress["egress-httpbin-org"]).toEqual(gatewayRoute("egress-httpbin-org", "httpbin.org")); - expect(egress.bedrock).toEqual( + expect(egress["bedrock-api-key"]).toEqual( gatewayRoute("bedrock", "bedrock-runtime.us-west-2.amazonaws.com"), ); expect(await boxFiles(root)).toEqual(before); @@ -408,7 +410,7 @@ describe("build writes the Box network of the box profile", () => { string, { destinations: string[] } >; - expect(Object.keys(egress).sort()).toEqual(["agentcore", "bedrock"]); + expect(Object.keys(egress).sort()).toEqual(["agentcore", "bedrock-api-key"]); }); test("changes nothing on a second build", async () => { @@ -464,7 +466,7 @@ describe("build writes the Box network of the box profile", () => { ); expect(warnings).toEqual([]); const profile = await runtimeProfile(root); - expect(Object.keys(profile.egress as object)).toEqual(["bedrock", "agentcore"]); + expect(Object.keys(profile.egress as object)).toEqual(["bedrock-api-key", "agentcore"]); expect(profile.mcp).toEqual({ tools: { ...tools, backends: gatewayRoute("egress-tools", "tools.example.com").backends }, }); @@ -551,7 +553,7 @@ describe("build writes the Box network of the box profile", () => { expect(await targetNames(root)).toEqual(["bedrock", "agentcore"]); const egress = (await runtimeProfile(root)).egress as Record; // The route of [egress.memory] keeps the name of its entry, and goes to the agentcore target. - expect(Object.keys(egress)).toEqual(["bedrock", "memory"]); + expect(Object.keys(egress)).toEqual(["bedrock-api-key", "memory"]); expect(egress.memory).toEqual( gatewayRoute("agentcore", "bedrock-agentcore.us-west-2.amazonaws.com"), ); @@ -678,13 +680,13 @@ describe("build sets box.version to the pinned box", () => { test("updates a runtime's older box.version, and says so", async () => { const { manager, root } = await strandsProject(); const spec = JSON.parse(await text(root, SPEC)); - spec.runtimes[0].box = { version: "0.1.11-linux-preview.6" }; + spec.runtimes[0].box = { version: "0.2.4" }; await writeFile(path(root, SPEC), JSON.stringify(spec, undefined, 2)); const { steps } = await build(manager, root); expect(steps).toContain( - "updating box.version of runtime 'agent_python_strands' from 0.1.11-linux-preview.6 to " + + "updating box.version of runtime 'agent_python_strands' from 0.2.4 to " + `${BOX_RELEASE.version}, the box this CLI ships`, ); expect(JSON.parse(await text(root, SPEC)).runtimes[0].box).toEqual({ @@ -1073,11 +1075,13 @@ describe("build writes the Bedrock and Memory targets for the region it builds f outboundAuth: { region: "eu-central-1" }, }); const profile = await runtimeProfile(root); - expect(profile.options).toEqual({ bedrock: { region: "eu-central-1" } }); + expect(profile.options).toEqual({ bedrock: { region: "eu-central-1", "sign-in": "api-key" } }); const egress = profile.egress as Record; - expect(egress.bedrock!.destinations).toEqual(["bedrock-runtime.eu-central-1.amazonaws.com"]); + expect(egress["bedrock-api-key"]!.destinations).toEqual([ + "bedrock-runtime.eu-central-1.amazonaws.com", + ]); // The backend signs for the Runtime's own region, which box reads from AWS_REGION there. - expect(JSON.stringify(egress.bedrock!.backends)).toContain( + expect(JSON.stringify(egress["bedrock-api-key"]!.backends)).toContain( '"region":"${{ inputs.aws.region }}"', ); }); @@ -1090,7 +1094,9 @@ describe("build writes the Bedrock and Memory targets for the region it builds f const { targets } = await boxGateway(root); expect(targets.find(({ name }) => name === "bedrock")).toEqual(bedrockTarget("ap-northeast-1")); - expect((await runtimeProfile(root)).options).toEqual({ bedrock: { region: "ap-northeast-1" } }); + expect((await runtimeProfile(root)).options).toEqual({ + bedrock: { region: "ap-northeast-1", "sign-in": "api-key" }, + }); }); test("has box resolve the profile for that region, from a copy it then removes", async () => { diff --git a/src/core/project/manager.test.ts b/src/core/project/manager.test.ts index aa2cd15008..12751548ab 100644 --- a/src/core/project/manager.test.ts +++ b/src/core/project/manager.test.ts @@ -2351,7 +2351,7 @@ describe("FsProjectManager.build", () => { // The test runner downloads nothing, so build stops before synth and names the URL. await expect(drain(subject.build(project))).rejects.toThrow( - /downloaded from https:\/\/github\.com\/mquang-amazon\/box-releases\//, + /downloaded from https:\/\/github\.com\/strands-agents\/box\//, ); expect(commands.map(({ command }) => command[0])).toEqual(["curl"]); }); diff --git a/src/core/project/runtimeProfile/derive.test.ts b/src/core/project/runtimeProfile/derive.test.ts index eaec6ce02f..23f2d9186c 100644 --- a/src/core/project/runtimeProfile/derive.test.ts +++ b/src/core/project/runtimeProfile/derive.test.ts @@ -32,7 +32,7 @@ const context = (runtime: ProjectRuntime, places = new Map()) => places, }); -/** The keys of a profile that no rule of the derivation changes, as box 0.1.11-linux-preview.6 takes them. */ +/** The keys of a profile that no rule of the derivation changes, as box takes them. */ const CARRIED: TomlTable = { "agent-args": ["--verbose"], "file-attributes": true, diff --git a/src/core/project/runtimeProfile/rules/additions.test.ts b/src/core/project/runtimeProfile/rules/additions.test.ts index dd75a6545c..00ed6b30a6 100644 --- a/src/core/project/runtimeProfile/rules/additions.test.ts +++ b/src/core/project/runtimeProfile/rules/additions.test.ts @@ -14,6 +14,9 @@ import { readFileSync } from "node:fs"; import { join } from "node:path"; import { AWS_METADATA_POLICY_FILE, + BOX_BEDROCK_API_KEY_ROUTE, + BOX_BEDROCK_PACK, + BOX_BEDROCK_ROUTE, renderAgentCorePack, renderBoxProfile, } from "../../templates/boxProfile"; @@ -163,6 +166,29 @@ const OTEL_START: Record = { Container: ["${{ workspace }}/.venv/bin/opentelemetry-instrument"], }; +/** + * `profile`, a Runtime profile that the old renderer wrote, as the derivation writes it for box + * 0.3: with @box/bedrock, `bedrock.sign-in` is `api-key`, and the Bedrock route through the + * gateway is `[egress.bedrock-api-key]`, the pack's route for that sign-in. Nothing else changes. + */ +function withApiKeySignIn(profile: TomlTable): TomlTable { + const packs = profile.packs; + if (!Array.isArray(packs) || !packs.includes(BOX_BEDROCK_PACK)) return profile; + const result = structuredClone(profile); + const options = result.options as TomlTable; + options.bedrock = { ...(options.bedrock as TomlTable), "sign-in": "api-key" }; + const egress = result.egress as TomlTable | undefined; + if (egress !== undefined && Object.hasOwn(egress, BOX_BEDROCK_ROUTE)) { + result.egress = Object.fromEntries( + Object.entries(egress).map(([name, route]) => [ + name === BOX_BEDROCK_ROUTE ? BOX_BEDROCK_API_KEY_ROUTE : name, + route, + ]), + ); + } + return result; +} + /** * `profile`, a Runtime profile with OTEL off, as OTEL on gives it: the agent starts under * opentelemetry-instrument, and the default X-Ray target comes last when no target is @@ -196,7 +222,7 @@ const TELEMETRY_CASES: Record = { * the gateway fixture. The gateway fixture is recorded from renderRuntimeBoxProfile of * box-integration (f5503f02). The two template sets are recorded, with the default telemetry * target, from the renderer of aws/agentcore-cli#2867 (f40ebce7): box-integration (7252504c) with - * the `@box/` pack names and no ffi shim. + * the `@box/` pack names. */ const OLD_RENDERER = JSON.parse( readFileSync(join(import.meta.dir, "..", "__fixtures__", "old-renderer-tables.json"), "utf8"), @@ -274,10 +300,12 @@ describe("deriveRuntimeProfile on the created templates", () => { contextOf(runtime, { memories, telemetry }), ); - const recorded = withCreatePolicy( - OLD_RENDERER.templates[ - `${build} ${protocol} ${provider} memories=${memories.length} telemetry=${telemetryCase}` - ] as TomlTable, + const recorded = withApiKeySignIn( + withCreatePolicy( + OLD_RENDERER.templates[ + `${build} ${protocol} ${provider} memories=${memories.length} telemetry=${telemetryCase}` + ] as TomlTable, + ), ); const expected = otel ? withOtel(recorded, build) : recorded; expect(problems).toEqual([]); @@ -355,7 +383,8 @@ describe("deriveRuntimeProfile on each box template of create", () => { ]!, ); expect(problems).toEqual([]); - expect(profile).toEqual(otel ? withOtel(recorded, input.build as Build) : recorded); + const signedIn = withApiKeySignIn(recorded); + expect(profile).toEqual(otel ? withOtel(signedIn, input.build as Build) : signedIn); }, ); }); @@ -394,20 +423,14 @@ describe("the additions rule", () => { expect(local).toEqual(before); }); - test("removes the [tool.uname] table that a CodeZip template writes, and keeps each tool table of the user", () => { + test("writes no tool table for a CodeZip template, and keeps each tool table of the user", () => { const local = createdProfile(CODEZIP); const notes = { program: "/usr/bin/notes" }; - const changed = { filesystem: { deny_write: ["${{ workspace }}/app/agent/data"] } }; - expect(Object.keys(local.tool as TomlTable)).toEqual(["uname"]); + // The pinned box's @box/base has no tools, so the template gives none the project write grant. + expect(local).not.toHaveProperty("tool"); expect(apply(local, contextOf(CODEZIP)).table).not.toHaveProperty("tool"); - expect( - apply({ ...local, tool: { ...(local.tool as TomlTable), notes } }, contextOf(CODEZIP)).table - .tool, - ).toEqual({ notes }); - expect(apply({ ...local, tool: { uname: changed } }, contextOf(CODEZIP)).table.tool).toEqual({ - uname: changed, - }); + expect(apply({ ...local, tool: { notes } }, contextOf(CODEZIP)).table.tool).toEqual({ notes }); }); test("keeps the user's packs in their order, then adds the Runtime packs once", () => { @@ -445,19 +468,26 @@ describe("the additions rule", () => { }); }); - test("sets bedrock.region to the build region, and keeps the other options", () => { + test("sets bedrock.region to the build region and bedrock.sign-in to api-key, and keeps the other options", () => { + // Box refuses the aws:// route of @box/bedrock beside the gateway backend, so the Runtime + // signs in with the pack's api-key route, whose env:// secret box replaces with a stand-in. const dotted = { options: { bedrock: { region: CREATE_REGION }, other: { input: "x" } } }; const quoted = { options: { "bedrock.region": CREATE_REGION } }; + const signedIn = { options: { bedrock: { region: CREATE_REGION, "sign-in": "aws" } } }; expect(apply(dotted, contextOf(CODEZIP)).table.options).toEqual({ - bedrock: { region: BUILD_REGION }, + bedrock: { region: BUILD_REGION, "sign-in": "api-key" }, other: { input: "x" }, }); expect(apply(quoted, contextOf(CODEZIP)).table.options).toEqual({ "bedrock.region": BUILD_REGION, + "bedrock.sign-in": "api-key", + }); + expect(apply(signedIn, contextOf(CODEZIP)).table.options).toEqual({ + bedrock: { region: BUILD_REGION, "sign-in": "api-key" }, }); expect(apply({ packs: ["@box/bedrock"] }, contextOf(CODEZIP)).table.options).toEqual({ - bedrock: { region: BUILD_REGION }, + bedrock: { region: BUILD_REGION, "sign-in": "api-key" }, }); expect(apply({ packs: ["@box/base"] }, contextOf(CODEZIP)).table.options).toBeUndefined(); }); diff --git a/src/core/project/runtimeProfile/rules/additions.ts b/src/core/project/runtimeProfile/rules/additions.ts index 2416a76627..4121161903 100644 --- a/src/core/project/runtimeProfile/rules/additions.ts +++ b/src/core/project/runtimeProfile/rules/additions.ts @@ -7,6 +7,7 @@ * | `packs` | the user's packs in their order, then @box/agentcore, and @box/agentcore-codezip for CodeZip | * | `[profile] name` | the project's name | * | `[options] bedrock.region` | the build region, where the profile sets it or imports @box/bedrock | + * | `[options] bedrock.sign-in` | `api-key`, beside `bedrock.region`: the gateway signs each Bedrock call, and box refuses the `aws://` route of @box/bedrock beside its backend | * | `[agent] command` | the template's own command becomes its Runtime command; a command of the user loses `--reload` and `--reload-dir `; with OTEL on, a command of the venv's Python starts under opentelemetry-instrument | * | `[agent.env]` | a template value becomes its Runtime value; `LOCAL_DEV` goes; the region of the Runtime replaces a region of the user, with a warning; `AWS_PROFILE` goes, with a warning; the AWS stand-ins and (CodeZip) a `PYTHONPATH` of the code folder come in; each other value of the user stays | * | `[agent.filesystem]` | the template's grants become its Runtime grants; each grant of the user stays | @@ -23,6 +24,7 @@ import { AGENTCORE_CODEZIP_PACK_NAME, AGENTCORE_PACK_NAME, BOX_BEDROCK_PACK, + BOX_BEDROCK_RUNTIME_SIGN_IN, boxIngressPort, boxWorkloadPort, OBSERVABILITY_OFF_ENV, @@ -228,7 +230,8 @@ function runtimePacks(packs: unknown, context: RuntimeProfileContext): unknown { /** * `[options]` with `bedrock.region` in the build region, the region of the gateway's `bedrock` - * target: where the profile sets it, as a dotted or a quoted key, or where it imports @box/bedrock. + * target, and `bedrock.sign-in` of the route that goes through the gateway: where the profile sets + * `bedrock.region`, as a dotted or a quoted key, or where it imports @box/bedrock. */ function runtimeOptions(options: unknown, bedrock: boolean, region: string): unknown { if (options !== undefined && !isTable(options)) return options; @@ -236,8 +239,14 @@ function runtimeOptions(options: unknown, bedrock: boolean, region: string): unk const dotted = options !== undefined && isTable(options.bedrock); if (!quoted && !dotted && !bedrock) return options; const result: TomlTable = { ...options }; - if (quoted) result["bedrock.region"] = region; - if (dotted || !quoted) result.bedrock = { ...(result.bedrock as TomlTable), region }; + const signIn = BOX_BEDROCK_RUNTIME_SIGN_IN; + if (quoted) { + result["bedrock.region"] = region; + result["bedrock.sign-in"] = signIn; + } + if (dotted || !quoted) { + result.bedrock = { ...(result.bedrock as TomlTable), region, "sign-in": signIn }; + } return result; } diff --git a/src/core/project/runtimeProfile/rules/gateway.test.ts b/src/core/project/runtimeProfile/rules/gateway.test.ts index 585b2e30d5..4b708650dc 100644 --- a/src/core/project/runtimeProfile/rules/gateway.test.ts +++ b/src/core/project/runtimeProfile/rules/gateway.test.ts @@ -483,13 +483,20 @@ function rendered(label: string): TomlTable { /** * The `[egress]` routes of the old renderer under the keys that the gateway rule gives them: the * old renderer named each route after its target, and the rule names the route of the first host of - * an entry after the entry, so that a pack table of that name merges with it. The routes are the - * same. + * an entry after the entry, so that a pack table of that name merges with it. With @box/bedrock, + * the Bedrock route is `bedrock-api-key`, the route of the pack that the Runtime profile signs in + * with. The routes are the same. */ -const withEntryKeys = (egress: unknown) => +const withEntryKeys = (egress: unknown, bedrockPack = true) => Object.fromEntries( Object.entries(egress as TomlTable).map(([key, route]) => [ - { "egress-github": "github", "egress-models-api-one-example-com": "models" }[key] ?? key, + ( + { + ...(bedrockPack && { bedrock: "bedrock-api-key" }), + "egress-github": "github", + "egress-models-api-one-example-com": "models", + } as Record + )[key] ?? key, route, ]), ); @@ -702,7 +709,8 @@ describe("the gateway rule and the Runtime renderer it replaced", () => { ["MCP_DESTINATION_NOT_ONE_HOST", "pathed"], ]); expect(derived.problems).toEqual([]); - expect(derived.profile.egress).toEqual(withEntryKeys(old.egress)); + // The profile imports no @box/bedrock, so its Bedrock route keeps its name. + expect(derived.profile.egress).toEqual(withEntryKeys(old.egress, false)); expect(derived.profile.mcp).toBeUndefined(); expect(old.mcp).toBeUndefined(); }); diff --git a/src/core/project/runtimeProfile/rules/gateway.ts b/src/core/project/runtimeProfile/rules/gateway.ts index 321e267b6e..e4ef203c8d 100644 --- a/src/core/project/runtimeProfile/rules/gateway.ts +++ b/src/core/project/runtimeProfile/rules/gateway.ts @@ -15,12 +15,21 @@ * | an entry with no host in the Box network model | removed; the model fails the entry, and build stops | * * A stdio `[mcp.]` stays as it is: the `refusals` and `paths` rules own it. + * + * With @box/bedrock, the route of its `[egress.bedrock]` is `[egress.bedrock-api-key]`: the + * `additions` rule picks that route of the pack with `bedrock.sign-in = "api-key"`, because box + * refuses the `aws://` secret of `[egress.bedrock]` beside a backend. */ import { InputValidationError } from "../../../../errors/errors"; import type { AgentCoreGatewayTarget } from "../../../../projectSchemas/gateway"; import type { BoxHostSource, BoxNetworkHost } from "../../boxNetwork"; import { BOX_EGRESS_TARGET_PREFIX } from "../../boxNetwork/egress"; import { gatewayTargetFor } from "../../boxNetwork/projectSpec"; +import { + BOX_BEDROCK_API_KEY_ROUTE, + BOX_BEDROCK_PACK, + BOX_BEDROCK_ROUTE, +} from "../../templates/boxProfile"; import { isHttpServer, isTable } from "../projectPaths"; import { RUNTIME_AWS_SIGNER, @@ -44,6 +53,12 @@ interface GatewayRoute { export function apply(table: Readonly, context: RuntimeProfileContext): RuleResult { const routes = gatewayRoutes(context); const written = new Set(); + const bedrockPack = Array.isArray(table.packs) && table.packs.includes(BOX_BEDROCK_PACK); + // The route of @box/bedrock that the Runtime profile signs in with merges with this one. + const keyOf = (route: GatewayRoute) => { + const key = routeKey(route, routes, context); + return bedrockPack && key === BOX_BEDROCK_ROUTE ? BOX_BEDROCK_API_KEY_ROUTE : key; + }; const egress: TomlTable = {}; for (const [name, entry] of Object.entries(isTable(table.egress) ? table.egress : {})) { @@ -55,7 +70,7 @@ export function apply(table: Readonly, context: RuntimeProfileContext host.sources.some((source) => source.kind === "entry" && source.egressEntry === name), ); for (const route of routesOf(hosts, routes)) { - egress[routeKey(route, routes, context)] = egressRoute(entry, route); + egress[keyOf(route)] = egressRoute(entry, route); written.add(route.target); } } @@ -77,7 +92,7 @@ export function apply(table: Readonly, context: RuntimeProfileContext if (route.server) { mcp[route.server.mcpEntry] = mcpServer({}, route, route.server); } else { - egress[routeKey(route, routes, context)] = egressRoute({}, route); + egress[keyOf(route)] = egressRoute({}, route); } } diff --git a/src/core/project/templates/boxProfile.test.ts b/src/core/project/templates/boxProfile.test.ts index a6388bf879..3b51e40129 100644 --- a/src/core/project/templates/boxProfile.test.ts +++ b/src/core/project/templates/boxProfile.test.ts @@ -86,7 +86,6 @@ describe("renderBoxProfile", () => { filesystem: VENV_GRANTS, ingress: [{ listen: "127.0.0.1:8080", workload_port: 8081 }], }, - tool: { uname: { filesystem: { deny_write: VENV_GRANTS.deny_write } } }, egress: { bedrock: { secret: { ref: "aws://" } } }, }); }); @@ -109,7 +108,7 @@ describe("renderBoxProfile", () => { // agentcore dev starts box in app/, so ${{ workspace }} and the project grant are that // folder: agentcore/.env.local, with the model's key, .git and agentcore/cdk lie outside them. test("grants the agent its own folder and no other folder of the project", () => { - const { project, agent, tool } = profile("agent-python-strands-box", { + const { project, agent } = profile("agent-python-strands-box", { modelProvider: "OpenAI", apiKey: "sk-test", }); @@ -118,7 +117,6 @@ describe("renderBoxProfile", () => { const path = typeof grant === "string" ? grant : grant.path; expect(path).not.toMatch(/agentcore|\.git|\.\./); } - expect(JSON.stringify(tool)).not.toMatch(/agentcore|\.git|\.\./); }); test("names no host path, so the profile works on any machine and after a move", () => { diff --git a/src/core/project/templates/boxProfile.ts b/src/core/project/templates/boxProfile.ts index 6288d2bf9e..983252a58a 100644 --- a/src/core/project/templates/boxProfile.ts +++ b/src/core/project/templates/boxProfile.ts @@ -54,6 +54,23 @@ const BOX_BASE_PACK = "@box/base"; /** The pack of box that routes the Bedrock model calls, with its `[options] bedrock.region`. */ export const BOX_BEDROCK_PACK = "@box/bedrock"; +/** + * The route of {@link BOX_BEDROCK_PACK} that signs each Bedrock call with the AWS credentials, + * `aws://`, for its `bedrock.sign-in` input `aws`, the default. The local profile uses it. + */ +export const BOX_BEDROCK_ROUTE = "bedrock"; + +/** + * The route of {@link BOX_BEDROCK_PACK} for its `bedrock.sign-in` input `api-key`, whose secret is + * `env://AWS_BEARER_TOKEN_BEDROCK`. The Runtime profile uses it: there each Bedrock call goes + * through a Box gateway backend, and box takes only an `env://` secret beside a backend. Box gives + * the agent a stand-in for it and strips it, and the gateway signs the call with its own role. + */ +export const BOX_BEDROCK_API_KEY_ROUTE = "bedrock-api-key"; + +/** The `bedrock.sign-in` of the Runtime profile, which selects {@link BOX_BEDROCK_API_KEY_ROUTE}. */ +export const BOX_BEDROCK_RUNTIME_SIGN_IN = "api-key"; + /** {@link renderAgentCorePack}. */ export const AGENTCORE_PACK_NAME = "@box/agentcore"; export const AGENTCORE_PACK_PATH = "resources/packs/agentcore/pack.toml"; @@ -82,10 +99,12 @@ const ABSOLUTE_PATH_PATTERN = "(/[.]{0,2}[A-Za-z0-9_+-][A-Za-z0-9_.+-]*)+"; /** * The tools of @box/base that get the project's write grant: box gives each one its own grant, * so each lists the agent's `deny_write` folders as well. Taken from @box/base in the box release - * that `boxRelease.json` pins (0.1.11-preview.10). When the pin moves, check the tools of - * @box/base: box refuses a CodeZip box profile if a tool it misses gets the project write grant. + * that `boxRelease.json` pins (0.3.0, and 0.3.0-preview.1 for macOS), which has no tools: it + * dropped `uname`, and refuses a + * `[tool.uname]` table with no `command`. When the pin moves, check the tools of @box/base: box + * refuses a CodeZip box profile if a tool it misses gets the project write grant. */ -const BOX_BASE_PROJECT_WRITE_TOOLS = ["uname"]; +const BOX_BASE_PROJECT_WRITE_TOOLS: readonly string[] = []; type Protocol = NonNullable; diff --git a/src/handlers/project/migrate/index.test.ts b/src/handlers/project/migrate/index.test.ts index d560379459..10ceda2fdc 100644 --- a/src/handlers/project/migrate/index.test.ts +++ b/src/handlers/project/migrate/index.test.ts @@ -685,6 +685,7 @@ describe("agentcore migrate, applying", () => { ); }); + // On GitHub-hosted Windows runners this takes 4 to 5 s or more, past bun's 5 s default. test("--yes never applies a plan that isn't ready", async () => { await inCommittedV0Project(); const subject = scriptedCli({ ready: false }); @@ -692,8 +693,9 @@ describe("agentcore migrate, applying", () => { await expect(subject.run("--yes")).rejects.toBeInstanceOf(SilentCLIError); expect(subject.calls.apply).toBe(0); expect(subject.io.stderr()).toContain(MIGRATION_FAILURE_GUIDANCE); - }); + }, 30_000); + // On GitHub-hosted Windows runners this takes 4 to 5 s or more, past bun's 5 s default. test("on a terminal, asks first and applies on yes", async () => { await inCommittedV0Project(); const subject = scriptedCli({ isTTY: true, stdin: "y\n" }); @@ -709,7 +711,7 @@ describe("agentcore migrate, applying", () => { const err = subject.io.stderr(); expect(err.indexOf(CONFIRM_QUESTION.trim())).toBeGreaterThan(err.indexOf("Reading stack S")); expect(err.indexOf(CONFIRM_QUESTION.trim())).toBeLessThan(err.indexOf("Refactoring stack S")); - }); + }, 30_000); test("on a terminal, anything but yes cancels", async () => { await inCommittedV0Project();