diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 79e7f52..d8a2df2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -29,6 +29,13 @@ jobs: with: fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install tsx + run: npm install -g tsx + - name: Resolve version id: vars run: | @@ -44,7 +51,7 @@ jobs: - name: Determine latest id: latest run: | - node scripts/release/main.js --version "${{ steps.vars.outputs.version }}" --print-latest --output "$GITHUB_OUTPUT" + ./scripts/release/main.ts --version "${{ steps.vars.outputs.version }}" --print-latest --output "$GITHUB_OUTPUT" binaries: name: "Build & Upload Binaries" @@ -97,11 +104,11 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_RELEASES_SECRET_ACCESS_KEY }} run: | VERSION="${{ needs.setup.outputs.version }}" - BINARY_NAME="sandbox-daemon-${{ matrix.target }}${{ matrix.binary_ext }}" + BINARY_NAME="sandbox-agent-${{ matrix.target }}${{ matrix.binary_ext }}" aws s3 cp \ "dist/${BINARY_NAME}" \ - "s3://rivet-releases/sandbox-daemon/${VERSION}/${BINARY_NAME}" \ + "s3://rivet-releases/sandbox-agent/${VERSION}/${BINARY_NAME}" \ --region auto \ --endpoint-url https://2a94c6a0ced8d35ea63cddc86c2681e7.r2.cloudflarestorage.com \ --checksum-algorithm CRC32 @@ -109,7 +116,7 @@ jobs: if [ "${{ needs.setup.outputs.latest }}" = "true" ]; then aws s3 cp \ "dist/${BINARY_NAME}" \ - "s3://rivet-releases/sandbox-daemon/latest/${BINARY_NAME}" \ + "s3://rivet-releases/sandbox-agent/latest/${BINARY_NAME}" \ --region auto \ --endpoint-url https://2a94c6a0ced8d35ea63cddc86c2681e7.r2.cloudflarestorage.com \ --checksum-algorithm CRC32 @@ -128,6 +135,9 @@ jobs: with: node-version: 20 + - name: Install tsx + run: npm install -g tsx + - name: Install AWS CLI run: | sudo apt-get update @@ -149,4 +159,4 @@ jobs: LATEST_FLAG="--no-latest" fi - node scripts/release/main.js --version "$VERSION" $LATEST_FLAG --upload-typescript --upload-install + ./scripts/release/main.ts --version "$VERSION" $LATEST_FLAG --upload-typescript --upload-install diff --git a/.gitignore b/.gitignore index ab792bc..eed4da8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ build/ target/ # Package manager -pnpm-lock.yaml package-lock.json yarn.lock diff --git a/Cargo.toml b/Cargo.toml index 3a4500e..ddf382d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,9 @@ [workspace] resolver = "2" members = ["engine/packages/*"] + +[workspace.package] +version = "0.1.0" +edition = "2021" +authors = ["Sandbox Agent Contributors"] +license = "Apache-2.0" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d448362 --- /dev/null +++ b/LICENSE @@ -0,0 +1,190 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + +Copyright 2026 Sandbox Agent Contributors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 6163891..0f1a9c7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Sandbox Daemon +# Sandbox Agent SDK Run inside sandboxes to provide support @@ -81,9 +81,9 @@ TODO This project aims to solve 3 problems with agents: -- **Universal Agent API**: Claude Code, Codex, Amp, and OpenCode all have put a lot of work in to the agent scaffold. Each have respective pros and cons and need to be easy to be swapped between. -- **Agent Transcript**: Maintaining agent transcripts is difficult since the agent manages its own sessions. This provides a simpler way to read and retrieve agent transcripts in your system. +- **Universal Coding Agent API**: Claude Code, Codex, Amp, and OpenCode all have put a lot of work in to the agent scaffold. Each have respective pros and cons and need to be easy to be swapped between. - **Agents In Sandboxes**: There are many complications with running agents inside of sandbox providers. This lets you run a simple curl command to spawn an HTTP server for using any agent from within the sandbox. +- **Agent Transcript**: Maintaining agent transcripts is difficult since the agent manages its own sessions. This provides a simpler way to read and retrieve agent transcripts in your system. Features out of scope: diff --git a/docker/release/build.sh b/docker/release/build.sh index f8f0301..fba51f2 100755 --- a/docker/release/build.sh +++ b/docker/release/build.sh @@ -8,25 +8,25 @@ case $TARGET in echo "Building for Linux x86_64 musl" DOCKERFILE="linux-x86_64.Dockerfile" TARGET_STAGE="builder" - BINARY="sandbox-daemon-$TARGET" + BINARY="sandbox-agent-$TARGET" ;; x86_64-pc-windows-gnu) echo "Building for Windows x86_64" DOCKERFILE="windows.Dockerfile" TARGET_STAGE="" - BINARY="sandbox-daemon-$TARGET.exe" + BINARY="sandbox-agent-$TARGET.exe" ;; x86_64-apple-darwin) echo "Building for macOS x86_64" DOCKERFILE="macos-x86_64.Dockerfile" TARGET_STAGE="x86_64-builder" - BINARY="sandbox-daemon-$TARGET" + BINARY="sandbox-agent-$TARGET" ;; aarch64-apple-darwin) echo "Building for macOS aarch64" DOCKERFILE="macos-aarch64.Dockerfile" TARGET_STAGE="aarch64-builder" - BINARY="sandbox-daemon-$TARGET" + BINARY="sandbox-agent-$TARGET" ;; *) echo "Unsupported target: $TARGET" @@ -36,12 +36,12 @@ case $TARGET in DOCKER_BUILDKIT=1 if [ -n "$TARGET_STAGE" ]; then - docker build --target "$TARGET_STAGE" -f "docker/release/$DOCKERFILE" -t "sandbox-daemon-builder-$TARGET" . + docker build --target "$TARGET_STAGE" -f "docker/release/$DOCKERFILE" -t "sandbox-agent-builder-$TARGET" . else - docker build -f "docker/release/$DOCKERFILE" -t "sandbox-daemon-builder-$TARGET" . + docker build -f "docker/release/$DOCKERFILE" -t "sandbox-agent-builder-$TARGET" . fi -CONTAINER_ID=$(docker create "sandbox-daemon-builder-$TARGET") +CONTAINER_ID=$(docker create "sandbox-agent-builder-$TARGET") mkdir -p dist docker cp "$CONTAINER_ID:/artifacts/$BINARY" "dist/" diff --git a/docker/release/linux-x86_64.Dockerfile b/docker/release/linux-x86_64.Dockerfile index 1609e66..906c09d 100644 --- a/docker/release/linux-x86_64.Dockerfile +++ b/docker/release/linux-x86_64.Dockerfile @@ -20,8 +20,8 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/build/target \ RUSTFLAGS="-C target-feature=+crt-static" \ - cargo build -p sandbox-daemon-core --release --target x86_64-unknown-linux-musl && \ + cargo build -p sandbox-agent-core --release --target x86_64-unknown-linux-musl && \ mkdir -p /artifacts && \ - cp target/x86_64-unknown-linux-musl/release/sandbox-daemon /artifacts/sandbox-daemon-x86_64-unknown-linux-musl + cp target/x86_64-unknown-linux-musl/release/sandbox-agent /artifacts/sandbox-agent-x86_64-unknown-linux-musl CMD ["ls", "-la", "/artifacts"] diff --git a/docker/release/macos-aarch64.Dockerfile b/docker/release/macos-aarch64.Dockerfile index d0d6c99..cc048da 100644 --- a/docker/release/macos-aarch64.Dockerfile +++ b/docker/release/macos-aarch64.Dockerfile @@ -55,8 +55,8 @@ COPY . . RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/build/target \ - cargo build -p sandbox-daemon-core --release --target aarch64-apple-darwin && \ + cargo build -p sandbox-agent-core --release --target aarch64-apple-darwin && \ mkdir -p /artifacts && \ - cp target/aarch64-apple-darwin/release/sandbox-daemon /artifacts/sandbox-daemon-aarch64-apple-darwin + cp target/aarch64-apple-darwin/release/sandbox-agent /artifacts/sandbox-agent-aarch64-apple-darwin CMD ["ls", "-la", "/artifacts"] diff --git a/docker/release/macos-x86_64.Dockerfile b/docker/release/macos-x86_64.Dockerfile index d477e15..1797434 100644 --- a/docker/release/macos-x86_64.Dockerfile +++ b/docker/release/macos-x86_64.Dockerfile @@ -55,8 +55,8 @@ COPY . . RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/build/target \ - cargo build -p sandbox-daemon-core --release --target x86_64-apple-darwin && \ + cargo build -p sandbox-agent-core --release --target x86_64-apple-darwin && \ mkdir -p /artifacts && \ - cp target/x86_64-apple-darwin/release/sandbox-daemon /artifacts/sandbox-daemon-x86_64-apple-darwin + cp target/x86_64-apple-darwin/release/sandbox-agent /artifacts/sandbox-agent-x86_64-apple-darwin CMD ["ls", "-la", "/artifacts"] diff --git a/docker/release/windows.Dockerfile b/docker/release/windows.Dockerfile index 6d00e7b..6577e68 100644 --- a/docker/release/windows.Dockerfile +++ b/docker/release/windows.Dockerfile @@ -42,8 +42,8 @@ COPY . . RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/build/target \ - cargo build -p sandbox-daemon-core --release --target x86_64-pc-windows-gnu && \ + cargo build -p sandbox-agent-core --release --target x86_64-pc-windows-gnu && \ mkdir -p /artifacts && \ - cp target/x86_64-pc-windows-gnu/release/sandbox-daemon.exe /artifacts/sandbox-daemon-x86_64-pc-windows-gnu.exe + cp target/x86_64-pc-windows-gnu/release/sandbox-agent.exe /artifacts/sandbox-agent-x86_64-pc-windows-gnu.exe CMD ["ls", "-la", "/artifacts"] diff --git a/engine/packages/agent-credentials/Cargo.toml b/engine/packages/agent-credentials/Cargo.toml index 05a0889..7429988 100644 --- a/engine/packages/agent-credentials/Cargo.toml +++ b/engine/packages/agent-credentials/Cargo.toml @@ -1,7 +1,9 @@ [package] -name = "sandbox-daemon-agent-credentials" -version = "0.1.0" -edition = "2021" +name = "sandbox-agent-agent-credentials" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [dependencies] serde = { version = "1.0", features = ["derive"] } diff --git a/engine/packages/agent-management/Cargo.toml b/engine/packages/agent-management/Cargo.toml index 0ccdd34..73022b1 100644 --- a/engine/packages/agent-management/Cargo.toml +++ b/engine/packages/agent-management/Cargo.toml @@ -1,13 +1,15 @@ [package] -name = "sandbox-daemon-agent-management" -version = "0.1.0" -edition = "2021" +name = "sandbox-agent-agent-management" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [dependencies] thiserror = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -sandbox-daemon-agent-credentials = { path = "../agent-credentials" } +sandbox-agent-agent-credentials = { path = "../agent-credentials" } reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"] } flate2 = "1.0" tar = "0.4" diff --git a/engine/packages/agent-management/src/credentials.rs b/engine/packages/agent-management/src/credentials.rs index 3a6e9e1..fcef001 100644 --- a/engine/packages/agent-management/src/credentials.rs +++ b/engine/packages/agent-management/src/credentials.rs @@ -1 +1 @@ -pub use sandbox_daemon_agent_credentials::*; +pub use sandbox_agent_agent_credentials::*; diff --git a/engine/packages/agent-schema/Cargo.toml b/engine/packages/agent-schema/Cargo.toml index 29d9375..f8350d7 100644 --- a/engine/packages/agent-schema/Cargo.toml +++ b/engine/packages/agent-schema/Cargo.toml @@ -1,7 +1,9 @@ [package] -name = "sandbox-daemon-agent-schema" -version = "0.1.0" -edition = "2021" +name = "sandbox-agent-agent-schema" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [dependencies] serde = { version = "1.0", features = ["derive"] } diff --git a/engine/packages/agent-schema/build.rs b/engine/packages/agent-schema/build.rs index bba50e2..7fc5c21 100644 --- a/engine/packages/agent-schema/build.rs +++ b/engine/packages/agent-schema/build.rs @@ -1,4 +1,5 @@ use std::fs; +use std::io::{self, Write}; use std::path::Path; fn main() { @@ -16,10 +17,16 @@ fn main() { let schema_path = schema_dir.join(file); // Tell cargo to rerun if schema changes - println!("cargo:rerun-if-changed={}", schema_path.display()); + emit_stdout(&format!( + "cargo:rerun-if-changed={}", + schema_path.display() + )); if !schema_path.exists() { - eprintln!("Warning: Schema file not found: {}", schema_path.display()); + emit_stdout(&format!( + "cargo:warning=Schema file not found: {}", + schema_path.display() + )); // Write empty module let out_path = Path::new(&out_dir).join(format!("{}.rs", name)); fs::write(&out_path, "// Schema not found\n").unwrap(); @@ -49,6 +56,16 @@ fn main() { fs::write(&out_path, formatted) .unwrap_or_else(|e| panic!("Failed to write {}: {}", out_path.display(), e)); - println!("cargo:warning=Generated {} types from {}", name, file); + emit_stdout(&format!( + "cargo:warning=Generated {} types from {}", + name, file + )); } } + +fn emit_stdout(message: &str) { + let mut out = io::stdout(); + let _ = out.write_all(message.as_bytes()); + let _ = out.write_all(b"\n"); + let _ = out.flush(); +} diff --git a/engine/packages/error/Cargo.toml b/engine/packages/error/Cargo.toml index 297ac59..7845173 100644 --- a/engine/packages/error/Cargo.toml +++ b/engine/packages/error/Cargo.toml @@ -1,7 +1,9 @@ [package] -name = "sandbox-daemon-error" -version = "0.1.0" -edition = "2021" +name = "sandbox-agent-error" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [dependencies] serde = { version = "1.0", features = ["derive"] } diff --git a/engine/packages/error/src/lib.rs b/engine/packages/error/src/lib.rs index 4db9e55..60609c2 100644 --- a/engine/packages/error/src/lib.rs +++ b/engine/packages/error/src/lib.rs @@ -24,18 +24,18 @@ pub enum ErrorType { impl ErrorType { pub fn as_urn(&self) -> &'static str { match self { - Self::InvalidRequest => "urn:sandbox-daemon:error:invalid_request", - Self::UnsupportedAgent => "urn:sandbox-daemon:error:unsupported_agent", - Self::AgentNotInstalled => "urn:sandbox-daemon:error:agent_not_installed", - Self::InstallFailed => "urn:sandbox-daemon:error:install_failed", - Self::AgentProcessExited => "urn:sandbox-daemon:error:agent_process_exited", - Self::TokenInvalid => "urn:sandbox-daemon:error:token_invalid", - Self::PermissionDenied => "urn:sandbox-daemon:error:permission_denied", - Self::SessionNotFound => "urn:sandbox-daemon:error:session_not_found", - Self::SessionAlreadyExists => "urn:sandbox-daemon:error:session_already_exists", - Self::ModeNotSupported => "urn:sandbox-daemon:error:mode_not_supported", - Self::StreamError => "urn:sandbox-daemon:error:stream_error", - Self::Timeout => "urn:sandbox-daemon:error:timeout", + Self::InvalidRequest => "urn:sandbox-agent:error:invalid_request", + Self::UnsupportedAgent => "urn:sandbox-agent:error:unsupported_agent", + Self::AgentNotInstalled => "urn:sandbox-agent:error:agent_not_installed", + Self::InstallFailed => "urn:sandbox-agent:error:install_failed", + Self::AgentProcessExited => "urn:sandbox-agent:error:agent_process_exited", + Self::TokenInvalid => "urn:sandbox-agent:error:token_invalid", + Self::PermissionDenied => "urn:sandbox-agent:error:permission_denied", + Self::SessionNotFound => "urn:sandbox-agent:error:session_not_found", + Self::SessionAlreadyExists => "urn:sandbox-agent:error:session_already_exists", + Self::ModeNotSupported => "urn:sandbox-agent:error:mode_not_supported", + Self::StreamError => "urn:sandbox-agent:error:stream_error", + Self::Timeout => "urn:sandbox-agent:error:timeout", } } diff --git a/engine/packages/openapi-gen/Cargo.toml b/engine/packages/openapi-gen/Cargo.toml index 3f73783..92ccdb2 100644 --- a/engine/packages/openapi-gen/Cargo.toml +++ b/engine/packages/openapi-gen/Cargo.toml @@ -1,12 +1,17 @@ [package] -name = "sandbox-daemon-openapi-gen" -version = "0.1.0" -edition = "2021" +name = "sandbox-agent-openapi-gen" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true build = "build.rs" [dependencies] +tracing = "0.1" +tracing-logfmt = "0.3" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [build-dependencies] -sandbox-daemon-core = { path = "../sandbox-daemon" } +sandbox-agent-core = { path = "../sandbox-agent" } serde_json = "1.0" utoipa = "4.2" diff --git a/engine/packages/openapi-gen/build.rs b/engine/packages/openapi-gen/build.rs index 4bb79bd..5bbe297 100644 --- a/engine/packages/openapi-gen/build.rs +++ b/engine/packages/openapi-gen/build.rs @@ -1,12 +1,13 @@ use std::fs; +use std::io::{self, Write}; use std::path::Path; -use sandbox_daemon_core::router::ApiDoc; +use sandbox_agent_core::router::ApiDoc; use utoipa::OpenApi; fn main() { - println!("cargo:rerun-if-changed=../sandbox-daemon/src/router.rs"); - println!("cargo:rerun-if-changed=../sandbox-daemon/src/lib.rs"); + emit_stdout("cargo:rerun-if-changed=../sandbox-agent/src/router.rs"); + emit_stdout("cargo:rerun-if-changed=../sandbox-agent/src/lib.rs"); let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR not set"); let out_path = Path::new(&out_dir).join("openapi.json"); @@ -16,5 +17,15 @@ fn main() { .expect("Failed to serialize OpenAPI spec"); fs::write(&out_path, json).expect("Failed to write OpenAPI spec"); - println!("cargo:warning=Generated OpenAPI spec at {}", out_path.display()); + emit_stdout(&format!( + "cargo:warning=Generated OpenAPI spec at {}", + out_path.display() + )); +} + +fn emit_stdout(message: &str) { + let mut out = io::stdout(); + let _ = out.write_all(message.as_bytes()); + let _ = out.write_all(b"\n"); + let _ = out.flush(); } diff --git a/engine/packages/openapi-gen/src/main.rs b/engine/packages/openapi-gen/src/main.rs index b03ed94..7b74a6f 100644 --- a/engine/packages/openapi-gen/src/main.rs +++ b/engine/packages/openapi-gen/src/main.rs @@ -1,8 +1,12 @@ use std::env; use std::fs; +use std::io::Write; use std::path::PathBuf; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; + fn main() { + init_logging(); let mut out: Option = None; let mut stdout = false; let mut args = env::args().skip(1).peekable(); @@ -26,15 +30,30 @@ fn main() { } } - let schema = sandbox_daemon_openapi_gen::OPENAPI_JSON; + let schema = sandbox_agent_openapi_gen::OPENAPI_JSON; if stdout { - println!("{schema}"); + write_stdout(schema); return; } let out = out.unwrap_or_else(|| PathBuf::from("openapi.json")); if let Err(err) = fs::write(&out, schema) { - eprintln!("failed to write {}: {err}", out.display()); + tracing::error!(path = %out.display(), error = %err, "failed to write openapi schema"); std::process::exit(1); } } + +fn init_logging() { + let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); + tracing_subscriber::registry() + .with(filter) + .with(tracing_logfmt::builder().layer().with_writer(std::io::stderr)) + .init(); +} + +fn write_stdout(text: &str) { + let mut out = std::io::stdout(); + let _ = out.write_all(text.as_bytes()); + let _ = out.write_all(b"\n"); + let _ = out.flush(); +} diff --git a/engine/packages/sandbox-daemon/Cargo.toml b/engine/packages/sandbox-agent/Cargo.toml similarity index 57% rename from engine/packages/sandbox-daemon/Cargo.toml rename to engine/packages/sandbox-agent/Cargo.toml index 2af1f96..e5fa063 100644 --- a/engine/packages/sandbox-daemon/Cargo.toml +++ b/engine/packages/sandbox-agent/Cargo.toml @@ -1,10 +1,12 @@ [package] -name = "sandbox-daemon-core" -version = "0.1.0" -edition = "2021" +name = "sandbox-agent-core" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [[bin]] -name = "sandbox-daemon" +name = "sandbox-agent" path = "src/main.rs" [dependencies] @@ -14,10 +16,10 @@ serde_json = "1.0" axum = "0.7" clap = { version = "4.5", features = ["derive"] } futures = "0.3" -sandbox-daemon-error = { path = "../error" } -sandbox-daemon-agent-management = { path = "../agent-management" } -sandbox-daemon-agent-credentials = { path = "../agent-credentials" } -sandbox-daemon-universal-agent-schema = { path = "../universal-agent-schema" } +sandbox-agent-error = { path = "../error" } +sandbox-agent-agent-management = { path = "../agent-management" } +sandbox-agent-agent-credentials = { path = "../agent-credentials" } +sandbox-agent-universal-agent-schema = { path = "../universal-agent-schema" } reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls", "stream"] } dirs = "5.0" time = { version = "0.3", features = ["parsing", "formatting"] } @@ -26,6 +28,9 @@ tokio-stream = { version = "0.1", features = ["sync"] } tower-http = { version = "0.5", features = ["cors"] } utoipa = { version = "4.2", features = ["axum_extras"] } schemars = "0.8" +tracing = "0.1" +tracing-logfmt = "0.3" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dev-dependencies] tempfile = "3.10" diff --git a/engine/packages/sandbox-agent/src/credentials.rs b/engine/packages/sandbox-agent/src/credentials.rs new file mode 100644 index 0000000..fcef001 --- /dev/null +++ b/engine/packages/sandbox-agent/src/credentials.rs @@ -0,0 +1 @@ +pub use sandbox_agent_agent_credentials::*; diff --git a/engine/packages/sandbox-daemon/src/lib.rs b/engine/packages/sandbox-agent/src/lib.rs similarity index 100% rename from engine/packages/sandbox-daemon/src/lib.rs rename to engine/packages/sandbox-agent/src/lib.rs diff --git a/engine/packages/sandbox-daemon/src/main.rs b/engine/packages/sandbox-agent/src/main.rs similarity index 90% rename from engine/packages/sandbox-daemon/src/main.rs rename to engine/packages/sandbox-agent/src/main.rs index 0391682..f1dadf6 100644 --- a/engine/packages/sandbox-daemon/src/main.rs +++ b/engine/packages/sandbox-agent/src/main.rs @@ -4,23 +4,24 @@ use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; use reqwest::blocking::Client as HttpClient; use reqwest::Method; -use sandbox_daemon_agent_management::agents::AgentManager; -use sandbox_daemon_core::router::{ +use sandbox_agent_agent_management::agents::AgentManager; +use sandbox_agent_core::router::{ AgentInstallRequest, AppState, AuthConfig, CreateSessionRequest, MessageRequest, PermissionReply, PermissionReplyRequest, QuestionReplyRequest, }; -use sandbox_daemon_core::router::{AgentListResponse, AgentModesResponse, CreateSessionResponse, EventsResponse}; -use sandbox_daemon_core::router::build_router; +use sandbox_agent_core::router::{AgentListResponse, AgentModesResponse, CreateSessionResponse, EventsResponse}; +use sandbox_agent_core::router::build_router; use serde::Serialize; use serde_json::Value; use thiserror::Error; use tower_http::cors::{Any, CorsLayer}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; const API_PREFIX: &str = "/v1"; #[derive(Parser, Debug)] -#[command(name = "sandbox-daemon")] -#[command(about = "Sandbox daemon for managing coding agents", version)] +#[command(name = "sandbox-agent")] +#[command(about = "Sandbox agent for managing coding agents", version)] struct Cli { #[command(subcommand)] command: Option, @@ -215,6 +216,7 @@ enum CliError { } fn main() { + init_logging(); let cli = Cli::parse(); let result = match &cli.command { @@ -223,11 +225,19 @@ fn main() { }; if let Err(err) = result { - eprintln!("{err}"); + tracing::error!(error = %err, "sandbox-agent failed"); std::process::exit(1); } } +fn init_logging() { + let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); + tracing_subscriber::registry() + .with(filter) + .with(tracing_logfmt::builder().layer().with_writer(std::io::stderr)) + .init(); +} + fn run_server(cli: &Cli) -> Result<(), CliError> { let auth = if cli.no_token { AuthConfig::disabled() @@ -262,8 +272,8 @@ fn run_server(cli: &Cli) -> Result<(), CliError> { fn default_install_dir() -> PathBuf { dirs::data_dir() - .map(|dir| dir.join("sandbox-daemon").join("bin")) - .unwrap_or_else(|| PathBuf::from(".").join(".sandbox-daemon").join("bin")) + .map(|dir| dir.join("sandbox-agent").join("bin")) + .unwrap_or_else(|| PathBuf::from(".").join(".sandbox-agent").join("bin")) } fn run_client(command: &Command, cli: &Cli) -> Result<(), CliError> { @@ -502,7 +512,7 @@ fn print_json_response( let parsed: T = serde_json::from_str(&text)?; let pretty = serde_json::to_string_pretty(&parsed)?; - println!("{pretty}"); + write_stdout_line(&pretty)?; Ok(()) } @@ -515,8 +525,7 @@ fn print_text_response(response: reqwest::blocking::Response) -> Result<(), CliE return Err(CliError::HttpStatus(status)); } - print!("{text}"); - std::io::stdout().flush()?; + write_stdout(&text)?; Ok(()) } @@ -533,9 +542,32 @@ fn print_empty_response(response: reqwest::blocking::Response) -> Result<(), Cli fn print_error_body(text: &str) -> Result<(), CliError> { if let Ok(json) = serde_json::from_str::(text) { let pretty = serde_json::to_string_pretty(&json)?; - eprintln!("{pretty}"); + write_stderr_line(&pretty)?; } else { - eprintln!("{text}"); + write_stderr_line(text)?; } Ok(()) } + +fn write_stdout(text: &str) -> Result<(), CliError> { + let mut out = std::io::stdout(); + out.write_all(text.as_bytes())?; + out.flush()?; + Ok(()) +} + +fn write_stdout_line(text: &str) -> Result<(), CliError> { + let mut out = std::io::stdout(); + out.write_all(text.as_bytes())?; + out.write_all(b"\n")?; + out.flush()?; + Ok(()) +} + +fn write_stderr_line(text: &str) -> Result<(), CliError> { + let mut out = std::io::stderr(); + out.write_all(text.as_bytes())?; + out.write_all(b"\n")?; + out.flush()?; + Ok(()) +} diff --git a/engine/packages/sandbox-daemon/src/router.rs b/engine/packages/sandbox-agent/src/router.rs similarity index 99% rename from engine/packages/sandbox-daemon/src/router.rs rename to engine/packages/sandbox-agent/src/router.rs index 756ee71..7b455fb 100644 --- a/engine/packages/sandbox-daemon/src/router.rs +++ b/engine/packages/sandbox-agent/src/router.rs @@ -16,8 +16,8 @@ use axum::Json; use axum::Router; use futures::{stream, StreamExt}; use reqwest::Client; -use sandbox_daemon_error::{AgentError, ErrorType, ProblemDetails, SandboxError}; -use sandbox_daemon_universal_agent_schema::{ +use sandbox_agent_error::{AgentError, ErrorType, ProblemDetails, SandboxError}; +use sandbox_agent_universal_agent_schema::{ convert_amp, convert_claude, convert_codex, convert_opencode, AttachmentSource, CrashInfo, EventConversion, PermissionRequest, PermissionToolRef, QuestionInfo, QuestionOption, QuestionRequest, QuestionToolRef, Started, UniversalEvent, UniversalEventData, @@ -31,10 +31,10 @@ use tokio_stream::wrappers::BroadcastStream; use tokio::time::sleep; use utoipa::{OpenApi, ToSchema}; -use sandbox_daemon_agent_management::agents::{ +use sandbox_agent_agent_management::agents::{ AgentError as ManagerError, AgentId, AgentManager, InstallOptions, SpawnOptions, StreamingSpawn, }; -use sandbox_daemon_agent_management::credentials::{ +use sandbox_agent_agent_management::credentials::{ extract_all_credentials, CredentialExtractionOptions, ExtractedCredentials, }; diff --git a/engine/packages/sandbox-daemon/tests/agents.rs b/engine/packages/sandbox-agent/tests/agents.rs similarity index 97% rename from engine/packages/sandbox-daemon/tests/agents.rs rename to engine/packages/sandbox-agent/tests/agents.rs index b5de6f7..79aad4c 100644 --- a/engine/packages/sandbox-daemon/tests/agents.rs +++ b/engine/packages/sandbox-agent/tests/agents.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; -use sandbox_daemon_agent_management::agents::{ +use sandbox_agent_agent_management::agents::{ AgentError, AgentId, AgentManager, InstallOptions, SpawnOptions, }; -use sandbox_daemon_agent_management::credentials::{ +use sandbox_agent_agent_management::credentials::{ extract_all_credentials, CredentialExtractionOptions, }; diff --git a/engine/packages/sandbox-daemon/src/credentials.rs b/engine/packages/sandbox-daemon/src/credentials.rs deleted file mode 100644 index 3a6e9e1..0000000 --- a/engine/packages/sandbox-daemon/src/credentials.rs +++ /dev/null @@ -1 +0,0 @@ -pub use sandbox_daemon_agent_credentials::*; diff --git a/engine/packages/universal-agent-schema/Cargo.toml b/engine/packages/universal-agent-schema/Cargo.toml index dde308a..dc0bbd3 100644 --- a/engine/packages/universal-agent-schema/Cargo.toml +++ b/engine/packages/universal-agent-schema/Cargo.toml @@ -1,10 +1,12 @@ [package] -name = "sandbox-daemon-universal-agent-schema" -version = "0.1.0" -edition = "2021" +name = "sandbox-agent-universal-agent-schema" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [dependencies] -sandbox-daemon-agent-schema = { path = "../agent-schema" } +sandbox-agent-agent-schema = { path = "../agent-schema" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" schemars = "0.8" diff --git a/engine/packages/universal-agent-schema/src/lib.rs b/engine/packages/universal-agent-schema/src/lib.rs index 28c3632..0b055d4 100644 --- a/engine/packages/universal-agent-schema/src/lib.rs +++ b/engine/packages/universal-agent-schema/src/lib.rs @@ -4,7 +4,7 @@ use schemars::JsonSchema; use thiserror::Error; use utoipa::ToSchema; -pub use sandbox_daemon_agent_schema::{amp, claude, codex, opencode}; +pub use sandbox_agent_agent_schema::{amp, claude, codex, opencode}; #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, ToSchema)] #[serde(rename_all = "camelCase")] diff --git a/frontend/packages/web/index.html b/frontend/packages/web/index.html index 5f236b3..02d4f4d 100644 --- a/frontend/packages/web/index.html +++ b/frontend/packages/web/index.html @@ -3,7 +3,7 @@ - Sandbox Daemon Console + Sandbox Agent Console