windows-development-sandbox 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.sandbox-config.example.json +14 -0
- package/LICENSE +21 -0
- package/README.md +94 -2
- package/config.example.json +349 -0
- package/dist/api.d.ts +31 -0
- package/dist/api.js +31 -0
- package/dist/bin/agent-sandbox.d.ts +2 -0
- package/dist/bin/agent-sandbox.js +3 -0
- package/dist/bin/claude-host.d.ts +2 -0
- package/dist/bin/claude-host.js +5 -0
- package/dist/bin/claude-sbx.d.ts +2 -0
- package/dist/bin/claude-sbx.js +3 -0
- package/dist/bin/codex-sbx.d.ts +2 -0
- package/dist/bin/codex-sbx.js +3 -0
- package/dist/bin/gemini-sbx.d.ts +2 -0
- package/dist/bin/gemini-sbx.js +3 -0
- package/dist/bin/sandbox.d.ts +2 -0
- package/dist/bin/sandbox.js +4 -0
- package/dist/bin/sbx-hide.d.ts +2 -0
- package/dist/bin/sbx-hide.js +3 -0
- package/dist/bin/sbx-show.d.ts +2 -0
- package/dist/bin/sbx-show.js +3 -0
- package/dist/cli/args.d.ts +52 -0
- package/dist/cli/args.js +143 -0
- package/dist/cli/colors.d.ts +24 -0
- package/dist/cli/colors.js +42 -0
- package/dist/cli/commands/accounts.d.ts +2 -0
- package/dist/cli/commands/accounts.js +52 -0
- package/dist/cli/commands/agent-commands.d.ts +6 -0
- package/dist/cli/commands/agent-commands.js +61 -0
- package/dist/cli/commands/context.d.ts +23 -0
- package/dist/cli/commands/context.js +57 -0
- package/dist/cli/commands/data/clean.d.ts +15 -0
- package/dist/cli/commands/data/clean.js +101 -0
- package/dist/cli/commands/data/collect.d.ts +11 -0
- package/dist/cli/commands/data/collect.js +54 -0
- package/dist/cli/commands/data/index.d.ts +4 -0
- package/dist/cli/commands/data/index.js +45 -0
- package/dist/cli/commands/data/remove.d.ts +2 -0
- package/dist/cli/commands/data/remove.js +30 -0
- package/dist/cli/commands/index.d.ts +10 -0
- package/dist/cli/commands/index.js +10 -0
- package/dist/cli/commands/launch.d.ts +29 -0
- package/dist/cli/commands/launch.js +333 -0
- package/dist/cli/commands/maintenance.d.ts +8 -0
- package/dist/cli/commands/maintenance.js +154 -0
- package/dist/cli/commands/project.d.ts +29 -0
- package/dist/cli/commands/project.js +63 -0
- package/dist/cli/commands/projects.d.ts +14 -0
- package/dist/cli/commands/projects.js +146 -0
- package/dist/cli/commands/repair/checks.d.ts +2 -0
- package/dist/cli/commands/repair/checks.js +170 -0
- package/dist/cli/commands/repair/finders.d.ts +30 -0
- package/dist/cli/commands/repair/finders.js +108 -0
- package/dist/cli/commands/repair/index.d.ts +12 -0
- package/dist/cli/commands/repair/index.js +61 -0
- package/dist/cli/commands/repair/types.d.ts +26 -0
- package/dist/cli/commands/repair/types.js +3 -0
- package/dist/cli/commands/restart.d.ts +6 -0
- package/dist/cli/commands/restart.js +85 -0
- package/dist/cli/commands/sessions.d.ts +12 -0
- package/dist/cli/commands/sessions.js +257 -0
- package/dist/cli/commands/setup/checks.d.ts +13 -0
- package/dist/cli/commands/setup/checks.js +71 -0
- package/dist/cli/commands/setup/facts.d.ts +31 -0
- package/dist/cli/commands/setup/facts.js +60 -0
- package/dist/cli/commands/setup/index.d.ts +2 -0
- package/dist/cli/commands/setup/index.js +43 -0
- package/dist/cli/commands/user-config.d.ts +8 -0
- package/dist/cli/commands/user-config.js +41 -0
- package/dist/cli/history.d.ts +11 -0
- package/dist/cli/history.js +21 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +121 -0
- package/dist/cli/manifest.d.ts +103 -0
- package/dist/cli/manifest.js +107 -0
- package/dist/cli/menu-multi.d.ts +12 -0
- package/dist/cli/menu-multi.js +82 -0
- package/dist/cli/menu.d.ts +14 -0
- package/dist/cli/menu.js +290 -0
- package/dist/cli/progress.d.ts +9 -0
- package/dist/cli/progress.js +49 -0
- package/dist/cli/settings/edit.d.ts +13 -0
- package/dist/cli/settings/edit.js +19 -0
- package/dist/cli/settings/index.d.ts +8 -0
- package/dist/cli/settings/index.js +131 -0
- package/dist/cli/settings/prompts.d.ts +7 -0
- package/dist/cli/settings/prompts.js +48 -0
- package/dist/cli/settings/schema.d.ts +33 -0
- package/dist/cli/settings/schema.js +29 -0
- package/dist/cli/validate.d.ts +17 -0
- package/dist/cli/validate.js +89 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.js +106 -0
- package/dist/core/detect-databases.d.ts +15 -0
- package/dist/core/detect-databases.js +147 -0
- package/dist/core/detect-pwsh.d.ts +18 -0
- package/dist/core/detect-pwsh.js +111 -0
- package/dist/core/detect-toolchains.d.ts +30 -0
- package/dist/core/detect-toolchains.js +58 -0
- package/dist/core/disk.d.ts +16 -0
- package/dist/core/disk.js +55 -0
- package/dist/core/local-config.d.ts +20 -0
- package/dist/core/local-config.js +77 -0
- package/dist/core/project-policy.d.ts +15 -0
- package/dist/core/project-policy.js +35 -0
- package/dist/core/prompt.d.ts +4 -0
- package/dist/core/prompt.js +15 -0
- package/dist/core/safe-paths.d.ts +4 -0
- package/dist/core/safe-paths.js +37 -0
- package/dist/core/schema/common.d.ts +17 -0
- package/dist/core/schema/common.js +15 -0
- package/dist/core/schema/config.d.ts +594 -0
- package/dist/core/schema/config.js +63 -0
- package/dist/core/schema/databases.d.ts +33 -0
- package/dist/core/schema/databases.js +35 -0
- package/dist/core/schema/harness.d.ts +12 -0
- package/dist/core/schema/harness.js +17 -0
- package/dist/core/schema/json-schema.d.ts +5 -0
- package/dist/core/schema/json-schema.js +25 -0
- package/dist/core/schema/profile.d.ts +27 -0
- package/dist/core/schema/profile.js +29 -0
- package/dist/core/schema/projects.d.ts +9 -0
- package/dist/core/schema/projects.js +11 -0
- package/dist/core/schema/sandbox.d.ts +50 -0
- package/dist/core/schema/sandbox.js +36 -0
- package/dist/core/schema/toolchains.d.ts +93 -0
- package/dist/core/schema/toolchains.js +83 -0
- package/dist/core/schema.d.ts +6 -0
- package/dist/core/schema.js +8 -0
- package/dist/core/types.d.ts +190 -0
- package/dist/core/types.js +1 -0
- package/dist/core/util.d.ts +60 -0
- package/dist/core/util.js +154 -0
- package/dist/core/workspace.d.ts +18 -0
- package/dist/core/workspace.js +128 -0
- package/dist/guest/boot-env.d.ts +4 -0
- package/dist/guest/boot-env.js +25 -0
- package/dist/guest/cmdline.d.ts +12 -0
- package/dist/guest/cmdline.js +23 -0
- package/dist/guest/daemon/exec.d.ts +5 -0
- package/dist/guest/daemon/exec.js +32 -0
- package/dist/guest/daemon/project.d.ts +14 -0
- package/dist/guest/daemon/project.js +132 -0
- package/dist/guest/daemon/session.d.ts +13 -0
- package/dist/guest/daemon/session.js +139 -0
- package/dist/guest/daemon/shutdown.d.ts +1 -0
- package/dist/guest/daemon/shutdown.js +21 -0
- package/dist/guest/daemon/state.d.ts +17 -0
- package/dist/guest/daemon/state.js +31 -0
- package/dist/guest/daemon.d.ts +1 -0
- package/dist/guest/daemon.js +53 -0
- package/dist/guest/db.d.ts +1 -0
- package/dist/guest/db.js +75 -0
- package/dist/guest/env.d.ts +51 -0
- package/dist/guest/env.js +101 -0
- package/dist/guest/gitguard.d.ts +7 -0
- package/dist/guest/gitguard.js +60 -0
- package/dist/guest/gitrules.d.ts +2 -0
- package/dist/guest/gitrules.js +11 -0
- package/dist/guest/guide.d.ts +16 -0
- package/dist/guest/guide.js +69 -0
- package/dist/guest/helpers.d.ts +3 -0
- package/dist/guest/helpers.js +26 -0
- package/dist/guest/main.d.ts +1 -0
- package/dist/guest/main.js +130 -0
- package/dist/guest/ports.d.ts +6 -0
- package/dist/guest/ports.js +22 -0
- package/dist/guest/project-context.d.ts +7 -0
- package/dist/guest/project-context.js +10 -0
- package/dist/guest/project-env.d.ts +20 -0
- package/dist/guest/project-env.js +20 -0
- package/dist/guest/project-status.d.ts +5 -0
- package/dist/guest/project-status.js +17 -0
- package/dist/guest/ptyhost.d.ts +22 -0
- package/dist/guest/ptyhost.js +36 -0
- package/dist/guest/setup/agents.d.ts +11 -0
- package/dist/guest/setup/agents.js +87 -0
- package/dist/guest/setup/claude.d.ts +21 -0
- package/dist/guest/setup/claude.js +146 -0
- package/dist/guest/setup/environment.d.ts +16 -0
- package/dist/guest/setup/environment.js +69 -0
- package/dist/guest/setup/hooks.d.ts +9 -0
- package/dist/guest/setup/hooks.js +50 -0
- package/dist/guest/setup/network.d.ts +10 -0
- package/dist/guest/setup/network.js +99 -0
- package/dist/guest/setup/policy.d.ts +3 -0
- package/dist/guest/setup/policy.js +18 -0
- package/dist/guest/setup/user.d.ts +7 -0
- package/dist/guest/setup/user.js +47 -0
- package/dist/guest/toolchains/catalogue.d.ts +55 -0
- package/dist/guest/toolchains/catalogue.js +31 -0
- package/dist/guest/toolchains/cli.d.ts +10 -0
- package/dist/guest/toolchains/cli.js +72 -0
- package/dist/guest/toolchains/common.d.ts +54 -0
- package/dist/guest/toolchains/common.js +147 -0
- package/dist/guest/toolchains/databases/dynamodb.d.ts +8 -0
- package/dist/guest/toolchains/databases/dynamodb.js +52 -0
- package/dist/guest/toolchains/databases/index.d.ts +6 -0
- package/dist/guest/toolchains/databases/index.js +62 -0
- package/dist/guest/toolchains/databases/mongodb.d.ts +3 -0
- package/dist/guest/toolchains/databases/mongodb.js +31 -0
- package/dist/guest/toolchains/databases/mysql.d.ts +3 -0
- package/dist/guest/toolchains/databases/mysql.js +38 -0
- package/dist/guest/toolchains/databases/postgres.d.ts +5 -0
- package/dist/guest/toolchains/databases/postgres.js +38 -0
- package/dist/guest/toolchains/databases/redis.d.ts +3 -0
- package/dist/guest/toolchains/databases/redis.js +16 -0
- package/dist/guest/toolchains/databases/server.d.ts +14 -0
- package/dist/guest/toolchains/databases/server.js +52 -0
- package/dist/guest/toolchains/git.d.ts +3 -0
- package/dist/guest/toolchains/git.js +121 -0
- package/dist/guest/toolchains/go.d.ts +3 -0
- package/dist/guest/toolchains/go.js +33 -0
- package/dist/guest/toolchains/index.d.ts +17 -0
- package/dist/guest/toolchains/index.js +80 -0
- package/dist/guest/toolchains/java.d.ts +8 -0
- package/dist/guest/toolchains/java.js +96 -0
- package/dist/guest/toolchains/leftovers.d.ts +2 -0
- package/dist/guest/toolchains/leftovers.js +26 -0
- package/dist/guest/toolchains/managers.d.ts +16 -0
- package/dist/guest/toolchains/managers.js +84 -0
- package/dist/guest/toolchains/native/binstall.d.ts +7 -0
- package/dist/guest/toolchains/native/binstall.js +52 -0
- package/dist/guest/toolchains/native/cpp.d.ts +4 -0
- package/dist/guest/toolchains/native/cpp.js +38 -0
- package/dist/guest/toolchains/native/dotnet.d.ts +4 -0
- package/dist/guest/toolchains/native/dotnet.js +103 -0
- package/dist/guest/toolchains/native/mesa.d.ts +7 -0
- package/dist/guest/toolchains/native/mesa.js +46 -0
- package/dist/guest/toolchains/native/msvc/environment.d.ts +16 -0
- package/dist/guest/toolchains/native/msvc/environment.js +57 -0
- package/dist/guest/toolchains/native/msvc/index.d.ts +6 -0
- package/dist/guest/toolchains/native/msvc/index.js +48 -0
- package/dist/guest/toolchains/native/msvc/packages.d.ts +6 -0
- package/dist/guest/toolchains/native/msvc/packages.js +156 -0
- package/dist/guest/toolchains/native/msvc/tree.d.ts +15 -0
- package/dist/guest/toolchains/native/msvc/tree.js +21 -0
- package/dist/guest/toolchains/native/rust.d.ts +3 -0
- package/dist/guest/toolchains/native/rust.js +45 -0
- package/dist/guest/toolchains/node.d.ts +3 -0
- package/dist/guest/toolchains/node.js +152 -0
- package/dist/guest/toolchains/plan.d.ts +22 -0
- package/dist/guest/toolchains/plan.js +96 -0
- package/dist/guest/toolchains/pwsh.d.ts +4 -0
- package/dist/guest/toolchains/pwsh.js +14 -0
- package/dist/guest/toolchains/python.d.ts +3 -0
- package/dist/guest/toolchains/python.js +54 -0
- package/dist/guest/toolchains/runtimes.d.ts +19 -0
- package/dist/guest/toolchains/runtimes.js +38 -0
- package/dist/guest/toolchains/scripting/php.d.ts +3 -0
- package/dist/guest/toolchains/scripting/php.js +71 -0
- package/dist/guest/toolchains/scripting/ruby.d.ts +3 -0
- package/dist/guest/toolchains/scripting/ruby.js +47 -0
- package/dist/guest/toolchains/scripting/vcruntime.d.ts +7 -0
- package/dist/guest/toolchains/scripting/vcruntime.js +45 -0
- package/dist/guest/toolchains/versions.d.ts +47 -0
- package/dist/guest/toolchains/versions.js +77 -0
- package/dist/guest/toolchains/vscode.d.ts +2 -0
- package/dist/guest/toolchains/vscode.js +53 -0
- package/dist/guest/view.d.ts +1 -0
- package/dist/guest/view.js +42 -0
- package/dist/host/accounts.d.ts +32 -0
- package/dist/host/accounts.js +128 -0
- package/dist/host/agent-commands.d.ts +25 -0
- package/dist/host/agent-commands.js +145 -0
- package/dist/host/attach.d.ts +17 -0
- package/dist/host/attach.js +69 -0
- package/dist/host/channel.d.ts +38 -0
- package/dist/host/channel.js +162 -0
- package/dist/host/claude-profile.d.ts +15 -0
- package/dist/host/claude-profile.js +107 -0
- package/dist/host/cleanup.d.ts +23 -0
- package/dist/host/cleanup.js +57 -0
- package/dist/host/database-plan.d.ts +12 -0
- package/dist/host/database-plan.js +52 -0
- package/dist/host/generate.d.ts +7 -0
- package/dist/host/generate.js +98 -0
- package/dist/host/join.d.ts +28 -0
- package/dist/host/join.js +76 -0
- package/dist/host/launch/mappings.d.ts +3 -0
- package/dist/host/launch/mappings.js +50 -0
- package/dist/host/launch/projects.d.ts +15 -0
- package/dist/host/launch/projects.js +56 -0
- package/dist/host/launch/stage.d.ts +11 -0
- package/dist/host/launch/stage.js +66 -0
- package/dist/host/launch/wsb.d.ts +10 -0
- package/dist/host/launch/wsb.js +34 -0
- package/dist/host/pc-scan.d.ts +6 -0
- package/dist/host/pc-scan.js +37 -0
- package/dist/host/personalize.d.ts +10 -0
- package/dist/host/personalize.js +97 -0
- package/dist/host/platform.d.ts +19 -0
- package/dist/host/platform.js +126 -0
- package/dist/host/project-scan.d.ts +7 -0
- package/dist/host/project-scan.js +89 -0
- package/dist/host/projects.d.ts +100 -0
- package/dist/host/projects.js +147 -0
- package/dist/host/repo-guard.d.ts +36 -0
- package/dist/host/repo-guard.js +219 -0
- package/dist/host/secrets.d.ts +14 -0
- package/dist/host/secrets.js +133 -0
- package/dist/host/terminal.d.ts +32 -0
- package/dist/host/terminal.js +130 -0
- package/dist/host/test-guard.d.ts +6 -0
- package/dist/host/test-guard.js +15 -0
- package/dist/host/window.d.ts +4 -0
- package/dist/host/window.js +72 -0
- package/dist/host/wsb.d.ts +37 -0
- package/dist/host/wsb.js +101 -0
- package/dist/runtime/daemon.js +28494 -0
- package/dist/runtime/db.js +26387 -0
- package/dist/runtime/gitguard.js +84 -0
- package/dist/runtime/main.js +28622 -0
- package/dist/runtime/view.js +25841 -0
- package/dist/selftest/accounts.test.d.ts +2 -0
- package/dist/selftest/accounts.test.js +44 -0
- package/dist/selftest/agent-commands.test.d.ts +2 -0
- package/dist/selftest/agent-commands.test.js +47 -0
- package/dist/selftest/channel.test.d.ts +2 -0
- package/dist/selftest/channel.test.js +37 -0
- package/dist/selftest/cli.test.d.ts +2 -0
- package/dist/selftest/cli.test.js +118 -0
- package/dist/selftest/cmdline.test.d.ts +2 -0
- package/dist/selftest/cmdline.test.js +45 -0
- package/dist/selftest/config.test.d.ts +2 -0
- package/dist/selftest/config.test.js +38 -0
- package/dist/selftest/data.test.d.ts +2 -0
- package/dist/selftest/data.test.js +80 -0
- package/dist/selftest/detect.test.d.ts +2 -0
- package/dist/selftest/detect.test.js +58 -0
- package/dist/selftest/fixtures.d.ts +272 -0
- package/dist/selftest/fixtures.js +80 -0
- package/dist/selftest/generate.test.d.ts +2 -0
- package/dist/selftest/generate.test.js +63 -0
- package/dist/selftest/git-access.test.d.ts +2 -0
- package/dist/selftest/git-access.test.js +26 -0
- package/dist/selftest/guest-boot.test.d.ts +2 -0
- package/dist/selftest/guest-boot.test.js +76 -0
- package/dist/selftest/harness.d.ts +51 -0
- package/dist/selftest/harness.js +77 -0
- package/dist/selftest/host-sim.test.d.ts +2 -0
- package/dist/selftest/host-sim.test.js +93 -0
- package/dist/selftest/hostile-input.test.d.ts +2 -0
- package/dist/selftest/hostile-input.test.js +54 -0
- package/dist/selftest/index.d.ts +8 -0
- package/dist/selftest/index.js +155 -0
- package/dist/selftest/links.test.d.ts +2 -0
- package/dist/selftest/links.test.js +50 -0
- package/dist/selftest/live-daemon.test.d.ts +2 -0
- package/dist/selftest/live-daemon.test.js +91 -0
- package/dist/selftest/live-git.test.d.ts +2 -0
- package/dist/selftest/live-git.test.js +60 -0
- package/dist/selftest/live-projects.test.d.ts +2 -0
- package/dist/selftest/live-projects.test.js +127 -0
- package/dist/selftest/live.d.ts +65 -0
- package/dist/selftest/live.js +109 -0
- package/dist/selftest/local-config.test.d.ts +2 -0
- package/dist/selftest/local-config.test.js +107 -0
- package/dist/selftest/mirror.test.d.ts +2 -0
- package/dist/selftest/mirror.test.js +101 -0
- package/dist/selftest/network.test.d.ts +2 -0
- package/dist/selftest/network.test.js +28 -0
- package/dist/selftest/personalization.test.d.ts +2 -0
- package/dist/selftest/personalization.test.js +53 -0
- package/dist/selftest/projects.test.d.ts +2 -0
- package/dist/selftest/projects.test.js +254 -0
- package/dist/selftest/repair.test.d.ts +2 -0
- package/dist/selftest/repair.test.js +42 -0
- package/dist/selftest/repo-guard.test.d.ts +2 -0
- package/dist/selftest/repo-guard.test.js +63 -0
- package/dist/selftest/secrets.test.d.ts +2 -0
- package/dist/selftest/secrets.test.js +71 -0
- package/dist/selftest/setup.test.d.ts +2 -0
- package/dist/selftest/setup.test.js +46 -0
- package/dist/selftest/suite.d.ts +13 -0
- package/dist/selftest/suite.js +1 -0
- package/dist/selftest/sync.test.d.ts +2 -0
- package/dist/selftest/sync.test.js +94 -0
- package/dist/selftest/test-guard.test.d.ts +2 -0
- package/dist/selftest/test-guard.test.js +49 -0
- package/dist/selftest/toolchains.test.d.ts +2 -0
- package/dist/selftest/toolchains.test.js +103 -0
- package/dist/selftest/workspace.test.d.ts +2 -0
- package/dist/selftest/workspace.test.js +53 -0
- package/dist/shared/download.d.ts +60 -0
- package/dist/shared/download.js +215 -0
- package/dist/shared/guest-paths.d.ts +30 -0
- package/dist/shared/guest-paths.js +61 -0
- package/dist/shared/netrules.d.ts +18 -0
- package/dist/shared/netrules.js +98 -0
- package/dist/shared/paths.d.ts +14 -0
- package/dist/shared/paths.js +28 -0
- package/dist/shared/projects.d.ts +53 -0
- package/dist/shared/projects.js +67 -0
- package/dist/shared/pty-client.d.ts +86 -0
- package/dist/shared/pty-client.js +227 -0
- package/dist/shared/rundir.d.ts +39 -0
- package/dist/shared/rundir.js +94 -0
- package/dist/shared/safe-remove.d.ts +10 -0
- package/dist/shared/safe-remove.js +66 -0
- package/dist/shared/schema.d.ts +527 -0
- package/dist/shared/schema.js +90 -0
- package/dist/shared/system.d.ts +15 -0
- package/dist/shared/system.js +19 -0
- package/dist/shared/test-guard.d.ts +4 -0
- package/dist/shared/test-guard.js +37 -0
- package/dist/sync/claude-mem.d.ts +8 -0
- package/dist/sync/claude-mem.js +79 -0
- package/dist/sync/history.d.ts +41 -0
- package/dist/sync/history.js +161 -0
- package/dist/sync/watcher.d.ts +21 -0
- package/dist/sync/watcher.js +135 -0
- package/hooks/post-agent/README.txt +1 -0
- package/hooks/pre-provision/README.txt +1 -0
- package/package.json +91 -4
- package/sandbox/bootstrap.ps1 +258 -0
- package/sandbox/cpucap.ps1 +51 -0
- package/sandbox/gitshim.cs +35 -0
- package/sandbox/logon.cmd +18 -0
- package/sandbox/openssl.cs +42 -0
- package/sandbox/ptyhost.cs +614 -0
- package/sandbox/trust.cmd +35 -0
- package/sandbox/vswhere.cs +83 -0
- package/schemas/config.schema.json +1161 -0
- package/schemas/sandbox-config.schema.json +968 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Attaching this terminal to an agent session inside the sandbox. Only addresses on this PC's own Hyper-V network are
|
|
2
|
+
// trusted, and everything the sandbox reports is printed through safeText.
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import { fail, safeText, sleep } from '../core/util.js';
|
|
6
|
+
import { connect, DETACH_KEY, queryViewers, runTerminalClient } from '../shared/pty-client.js';
|
|
7
|
+
import { currentSessions } from './channel.js';
|
|
8
|
+
import { insideSandbox } from './platform.js';
|
|
9
|
+
const ipToInt = (ip) => ip.split('.').reduce((n, part) => n * 256 + Number(part), 0);
|
|
10
|
+
/**
|
|
11
|
+
* True only for IPv4 addresses inside the subnet of one of this PC's Hyper-V adapters ("vEthernet ..."), which is
|
|
12
|
+
* where Windows Sandbox lives. Stops a compromised sandbox from pointing the host (and your keystrokes) anywhere else.
|
|
13
|
+
*/
|
|
14
|
+
export const isSandboxAddress = (ip, interfaces = os.networkInterfaces()) => {
|
|
15
|
+
if (!net.isIPv4(ip))
|
|
16
|
+
return false;
|
|
17
|
+
return Object.entries(interfaces).some(([name, list]) => /^vEthernet/i.test(name) && (list ?? []).some((i) => {
|
|
18
|
+
if (i.family !== 'IPv4' || i.internal)
|
|
19
|
+
return false;
|
|
20
|
+
const mask = ipToInt(i.netmask);
|
|
21
|
+
return mask !== 0 && (ipToInt(i.address) & mask) === (ipToInt(ip) & mask) && i.address !== ip;
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
/** Where this PC may connect for a session: only addresses on its own Hyper-V network (null if there are none). */
|
|
25
|
+
const hostEndpoint = (session) => {
|
|
26
|
+
// Inside the sandbox every session is on loopback; on the PC only addresses on its Hyper-V network are trusted.
|
|
27
|
+
const addresses = insideSandbox() ? ['127.0.0.1'] : session.attach?.addresses.filter((a) => isSandboxAddress(a)) ?? [];
|
|
28
|
+
return session.attach && addresses.length ? { ...session.attach, addresses } : null;
|
|
29
|
+
};
|
|
30
|
+
/** Who is watching a session right now (closed terminals do not count); null when it cannot be asked. */
|
|
31
|
+
export const sessionViewers = (session) => {
|
|
32
|
+
const endpoint = hostEndpoint(session);
|
|
33
|
+
return endpoint ? queryViewers(endpoint) : Promise.resolve(null);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The newest running session of this agent in exactly this folder that no terminal on this PC is attached to, so
|
|
37
|
+
* sandbox claude -t picks it back up instead of starting another. A session that cannot answer is never reused.
|
|
38
|
+
*/
|
|
39
|
+
export const findUnwatchedSession = async (dataPath, harness, cwd) => {
|
|
40
|
+
const candidates = currentSessions(dataPath).filter((s) => s.harness === harness && s.cwd.toLowerCase() === cwd.toLowerCase()).reverse().slice(0, 8);
|
|
41
|
+
for (const session of candidates)
|
|
42
|
+
if ((await sessionViewers(session))?.remote === 0)
|
|
43
|
+
return session;
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
/** Bridges this terminal to a session. Returns the agent's exit code, or 0 when the user detaches. */
|
|
47
|
+
export const attachTerminal = async (session) => {
|
|
48
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
49
|
+
fail('--terminal / attach needs an interactive terminal.', 'Run it directly in Windows Terminal or PowerShell, not through a pipe or script.');
|
|
50
|
+
if (!session.attach)
|
|
51
|
+
fail('This session cannot be attached to: networking or attach is disabled for this sandbox.', 'Set sandbox.networking and attach.enabled to true, then start a new sandbox.');
|
|
52
|
+
const endpoint = hostEndpoint(session) ?? fail('Refusing to connect: the sandbox reported no address on this PC\'s Hyper-V (vEthernet) network (' + session.attach.addresses.join(', ') + ').', 'Use the sandbox window instead (sbx-show); if this keeps happening, run sandbox doctor.');
|
|
53
|
+
const socket = await connect(endpoint);
|
|
54
|
+
console.log('Attaching to ' + safeText(session.harness) + ' session ' + session.id + ' (' + safeText(session.cwd) + '). Detach any time with Ctrl+]');
|
|
55
|
+
await sleep(400);
|
|
56
|
+
const result = await runTerminalClient(socket, session.attach.token, { detachKey: DETACH_KEY });
|
|
57
|
+
switch (result.reason) {
|
|
58
|
+
case 'detach':
|
|
59
|
+
console.log('Detached. The session keeps running; reattach with: sandbox attach ' + session.id);
|
|
60
|
+
return 0;
|
|
61
|
+
case 'exit':
|
|
62
|
+
console.log(safeText(session.harness) + ' exited with code ' + result.exitCode + '.');
|
|
63
|
+
return result.exitCode;
|
|
64
|
+
case 'error': fail('The sandbox refused the connection: ' + result.message, 'Try sandbox attach again; the session may have restarted.');
|
|
65
|
+
default:
|
|
66
|
+
console.log('Connection to the sandbox closed.');
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { GuestRequest, GuestResponse, Harness, SandboxStatus, SessionStatus } from '../core/types.js';
|
|
2
|
+
import type { ProjectSpecT } from '../shared/schema.js';
|
|
3
|
+
/** Where progress lines go: printed by default; a spinner passes its own. Text from the sandbox, made safe first. */
|
|
4
|
+
export type Progress = (line: string) => void;
|
|
5
|
+
/** Waits until the sandbox finished provisioning, reporting each boot step. */
|
|
6
|
+
export declare const waitForReady: (dataPath: string, launchId: string | null, isAlive: () => boolean, progress?: Progress) => Promise<SandboxStatus>;
|
|
7
|
+
export declare const sendRequest: (dataPath: string, request: GuestRequest) => void;
|
|
8
|
+
export declare const waitForResponse: (dataPath: string, requestId: string, isAlive: () => boolean, timeoutMs: number) => Promise<GuestResponse>;
|
|
9
|
+
/** project: a project registered after boot (provisioned first). harnessSpec: the agent's definition, for an agent the sandbox did not boot with. */
|
|
10
|
+
export declare const requestSession: (dataPath: string, harness: string, args: string[], cwd: string, extra?: {
|
|
11
|
+
project?: ProjectSpecT;
|
|
12
|
+
harnessSpec?: Harness;
|
|
13
|
+
}) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Provisions a registered project without starting an agent and waits for it, printing its progress (the guest's
|
|
16
|
+
* run\projects\<name>.json) as it goes. Throws when it failed.
|
|
17
|
+
*/
|
|
18
|
+
export declare const prepareProject: (dataPath: string, project: ProjectSpecT, isAlive: () => boolean, progress?: Progress) => Promise<GuestResponse>;
|
|
19
|
+
export declare const waitForSession: (dataPath: string, sessionId: string, isAlive: () => boolean, timeoutMs?: number, progress?: Progress) => Promise<SessionStatus>;
|
|
20
|
+
/** Runs a command inside the sandbox (in the workspace or a folder below it) and returns its output. */
|
|
21
|
+
export declare const execInSandbox: (dataPath: string, command: string[], cwd: string, timeoutSeconds: number, isAlive: () => boolean) => Promise<GuestResponse>;
|
|
22
|
+
/** Restarts running sessions in place (they resume via the harness's resumeArguments, e.g. claude --continue). */
|
|
23
|
+
export declare const restartSessions: (dataPath: string, harness: string | null, isAlive: () => boolean, cwd?: string) => Promise<GuestResponse>;
|
|
24
|
+
export declare const pingSandbox: (dataPath: string, isAlive: () => boolean) => Promise<GuestResponse>;
|
|
25
|
+
export declare const runningSessions: (dataPath: string) => SessionStatus[];
|
|
26
|
+
/** Most sessions the host will ever contact for one listing: a sandbox can write as many session files as it likes. */
|
|
27
|
+
export declare const MAX_QUERIED_SESSIONS = 32;
|
|
28
|
+
/** Running sessions of the sandbox that is running now (its launch id), newest last, capped. */
|
|
29
|
+
export declare const currentSessions: (dataPath: string) => SessionStatus[];
|
|
30
|
+
/** Sessions in this guest folder or below (one project's) first, each group newest first. */
|
|
31
|
+
export declare const sessionsFirstIn: (sessions: SessionStatus[], guestDir: string | null) => SessionStatus[];
|
|
32
|
+
/**
|
|
33
|
+
* The session with this id (or id prefix), else the most recently started running one: in `guestDir` (the project
|
|
34
|
+
* you are in) when it has one, else any.
|
|
35
|
+
*/
|
|
36
|
+
export declare const pickSession: (dataPath: string, sessionId?: string, guestDir?: string | null) => SessionStatus;
|
|
37
|
+
/** Forgets status from a previous sandbox run so nothing stale is picked up. */
|
|
38
|
+
export declare const resetRunDir: (dataPath: string) => void;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Host side of the sandbox channel: follow the boot and send requests (sessions, exec, restart, ping). Attaching a
|
|
2
|
+
// terminal to a session is in attach.ts. Everything read from the run folder is guest-written and treated as untrusted.
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import { assertNoLinks, fail, isLink, removeLink, safeText, sleep } from '../core/util.js';
|
|
6
|
+
import { isWithin } from '../shared/projects.js';
|
|
7
|
+
import { listSessions, now, readProjectStatus, readResponse, readSandboxStatus, readSession, runPaths, writeJsonAtomic } from '../shared/rundir.js';
|
|
8
|
+
import { safeRemove } from '../shared/safe-remove.js';
|
|
9
|
+
import { assertTestWritable, refuseInSelfTest } from './test-guard.js';
|
|
10
|
+
const BOOT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
11
|
+
const id = () => Date.now().toString(36) + crypto.randomBytes(3).toString('hex');
|
|
12
|
+
const until = async (timeoutMs, isAlive, poll, timeoutMessage) => {
|
|
13
|
+
const deadline = Date.now() + timeoutMs;
|
|
14
|
+
for (let round = 0; Date.now() < deadline; round++) {
|
|
15
|
+
const value = poll();
|
|
16
|
+
if (value !== null && value !== undefined)
|
|
17
|
+
return value;
|
|
18
|
+
if (round % 10 === 0 && !isAlive())
|
|
19
|
+
fail('Windows Sandbox closed (or is not running).', 'Start it again with sandbox claude; sandbox logs shows what happened.');
|
|
20
|
+
await sleep(500);
|
|
21
|
+
}
|
|
22
|
+
fail(timeoutMessage, 'Check what the sandbox is doing with sandbox logs -f (or sbx-show to see its window).');
|
|
23
|
+
};
|
|
24
|
+
const printLine = (line) => console.log(line);
|
|
25
|
+
/** Waits until the sandbox finished provisioning, reporting each boot step. */
|
|
26
|
+
export const waitForReady = (dataPath, launchId, isAlive, progress = (m) => printLine(' [sandbox] ' + m)) => {
|
|
27
|
+
let last = '';
|
|
28
|
+
return until(BOOT_TIMEOUT_MS, isAlive, () => {
|
|
29
|
+
const status = readSandboxStatus(dataPath);
|
|
30
|
+
if (!status || (launchId !== null && status.launchId !== launchId))
|
|
31
|
+
return null;
|
|
32
|
+
if (status.message !== last) {
|
|
33
|
+
progress(safeText(status.message).slice(0, 300));
|
|
34
|
+
last = status.message;
|
|
35
|
+
}
|
|
36
|
+
if (status.phase === 'failed')
|
|
37
|
+
fail('The sandbox failed to start: ' + status.message, 'See sandbox logs for details; the sandbox window shows the error too (sbx-show if headless).');
|
|
38
|
+
return status.phase === 'ready' ? status : null;
|
|
39
|
+
}, 'Timed out waiting for the sandbox to finish provisioning.');
|
|
40
|
+
};
|
|
41
|
+
export const sendRequest = (dataPath, request) => {
|
|
42
|
+
assertTestWritable(dataPath);
|
|
43
|
+
// Asking the sandbox to power off is the one request with an effect outside it, so the self-test never sends it.
|
|
44
|
+
if (request.kind === 'exec' && /shutdown/i.test(request.command[0] ?? ''))
|
|
45
|
+
refuseInSelfTest('shut down Windows Sandbox');
|
|
46
|
+
assertNoLinks(dataPath, runPaths(dataPath).requests);
|
|
47
|
+
writeJsonAtomic(runPaths(dataPath).request(request.id), request);
|
|
48
|
+
};
|
|
49
|
+
export const waitForResponse = (dataPath, requestId, isAlive, timeoutMs) => until(timeoutMs, isAlive, () => {
|
|
50
|
+
const response = readResponse(dataPath, requestId);
|
|
51
|
+
if (response)
|
|
52
|
+
try {
|
|
53
|
+
assertNoLinks(dataPath, runPaths(dataPath).responses);
|
|
54
|
+
fs.rmSync(runPaths(dataPath).response(requestId), { force: true });
|
|
55
|
+
}
|
|
56
|
+
catch { /* a planted link: the answer is read, nothing is deleted */ }
|
|
57
|
+
return response;
|
|
58
|
+
}, 'The sandbox did not answer (its session daemon may have stopped).');
|
|
59
|
+
/** project: a project registered after boot (provisioned first). harnessSpec: the agent's definition, for an agent the sandbox did not boot with. */
|
|
60
|
+
export const requestSession = (dataPath, harness, args, cwd, extra = {}) => {
|
|
61
|
+
const requestId = id();
|
|
62
|
+
sendRequest(dataPath, { kind: 'session', id: requestId, harness, args, cwd, ...(extra.project ? { project: extra.project } : {}), ...(extra.harnessSpec ? { harnessSpec: extra.harnessSpec } : {}), createdAt: now() });
|
|
63
|
+
return requestId;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Provisions a registered project without starting an agent and waits for it, printing its progress (the guest's
|
|
67
|
+
* run\projects\<name>.json) as it goes. Throws when it failed.
|
|
68
|
+
*/
|
|
69
|
+
export const prepareProject = async (dataPath, project, isAlive, progress = (m) => printLine(' [' + project.name + '] ' + m)) => {
|
|
70
|
+
const requestId = id();
|
|
71
|
+
sendRequest(dataPath, { kind: 'project', id: requestId, project, createdAt: now() });
|
|
72
|
+
let last = '';
|
|
73
|
+
const response = await until(60 * 60 * 1000, isAlive, () => {
|
|
74
|
+
const status = readProjectStatus(dataPath, project.name);
|
|
75
|
+
if (status && status.message !== last) {
|
|
76
|
+
progress(safeText(status.message).slice(0, 300));
|
|
77
|
+
last = status.message;
|
|
78
|
+
}
|
|
79
|
+
return readResponse(dataPath, requestId);
|
|
80
|
+
}, 'Timed out waiting for the project to be set up.');
|
|
81
|
+
try {
|
|
82
|
+
assertNoLinks(dataPath, runPaths(dataPath).responses);
|
|
83
|
+
fs.rmSync(runPaths(dataPath).response(requestId), { force: true });
|
|
84
|
+
}
|
|
85
|
+
catch { /* read, nothing deleted */ }
|
|
86
|
+
if (!response.ok)
|
|
87
|
+
fail(safeText(response.message), 'See sandbox logs for details.');
|
|
88
|
+
return response;
|
|
89
|
+
};
|
|
90
|
+
export const waitForSession = (dataPath, sessionId, isAlive, timeoutMs = 15 * 60 * 1000, progress = (m) => printLine(' [session] ' + m)) => {
|
|
91
|
+
let last = '';
|
|
92
|
+
return until(timeoutMs, isAlive, () => {
|
|
93
|
+
const session = readSession(dataPath, sessionId);
|
|
94
|
+
if (!session)
|
|
95
|
+
return null;
|
|
96
|
+
if (session.message !== last) {
|
|
97
|
+
progress(safeText(session.message).slice(0, 300));
|
|
98
|
+
last = session.message;
|
|
99
|
+
}
|
|
100
|
+
if (session.phase === 'failed')
|
|
101
|
+
fail('The agent session failed to start: ' + session.message, 'See sandbox logs for details.');
|
|
102
|
+
if (session.phase === 'exited')
|
|
103
|
+
fail('The agent exited right away (code ' + session.exitCode + ').', 'Check sandbox logs; a wrong agent argument is the usual cause.');
|
|
104
|
+
return session.phase === 'running' ? session : null;
|
|
105
|
+
}, 'Timed out waiting for the session to start.');
|
|
106
|
+
};
|
|
107
|
+
/** Runs a command inside the sandbox (in the workspace or a folder below it) and returns its output. */
|
|
108
|
+
export const execInSandbox = async (dataPath, command, cwd, timeoutSeconds, isAlive) => {
|
|
109
|
+
const requestId = id();
|
|
110
|
+
sendRequest(dataPath, { kind: 'exec', id: requestId, command, cwd, timeoutSeconds, createdAt: now() });
|
|
111
|
+
return waitForResponse(dataPath, requestId, isAlive, (timeoutSeconds + 30) * 1000);
|
|
112
|
+
};
|
|
113
|
+
/** Restarts running sessions in place (they resume via the harness's resumeArguments, e.g. claude --continue). */
|
|
114
|
+
export const restartSessions = async (dataPath, harness, isAlive, cwd) => {
|
|
115
|
+
const requestId = id();
|
|
116
|
+
sendRequest(dataPath, { kind: 'restart', id: requestId, harness, ...(cwd ? { cwd } : {}), createdAt: now() });
|
|
117
|
+
return waitForResponse(dataPath, requestId, isAlive, 30000);
|
|
118
|
+
};
|
|
119
|
+
export const pingSandbox = async (dataPath, isAlive) => {
|
|
120
|
+
const requestId = id();
|
|
121
|
+
sendRequest(dataPath, { kind: 'ping', id: requestId, createdAt: now() });
|
|
122
|
+
return waitForResponse(dataPath, requestId, isAlive, 15000);
|
|
123
|
+
};
|
|
124
|
+
export const runningSessions = (dataPath) => listSessions(dataPath).filter((s) => s.phase === 'running');
|
|
125
|
+
/** Most sessions the host will ever contact for one listing: a sandbox can write as many session files as it likes. */
|
|
126
|
+
export const MAX_QUERIED_SESSIONS = 32;
|
|
127
|
+
/** Running sessions of the sandbox that is running now (its launch id), newest last, capped. */
|
|
128
|
+
export const currentSessions = (dataPath) => {
|
|
129
|
+
const launchId = readSandboxStatus(dataPath)?.launchId;
|
|
130
|
+
return runningSessions(dataPath).filter((s) => s.launchId === launchId).slice(-MAX_QUERIED_SESSIONS);
|
|
131
|
+
};
|
|
132
|
+
/** Sessions in this guest folder or below (one project's) first, each group newest first. */
|
|
133
|
+
export const sessionsFirstIn = (sessions, guestDir) => {
|
|
134
|
+
const newest = [...sessions].reverse();
|
|
135
|
+
if (!guestDir)
|
|
136
|
+
return newest;
|
|
137
|
+
return [...newest.filter((s) => isWithin(guestDir, s.cwd)), ...newest.filter((s) => !isWithin(guestDir, s.cwd))];
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* The session with this id (or id prefix), else the most recently started running one: in `guestDir` (the project
|
|
141
|
+
* you are in) when it has one, else any.
|
|
142
|
+
*/
|
|
143
|
+
export const pickSession = (dataPath, sessionId, guestDir = null) => {
|
|
144
|
+
const running = runningSessions(dataPath);
|
|
145
|
+
if (running.length === 0)
|
|
146
|
+
fail('No agent session is running in the sandbox.', 'Start one with sandbox claude (it opens a new session in the running sandbox).');
|
|
147
|
+
if (!sessionId)
|
|
148
|
+
return sessionsFirstIn(running, guestDir)[0];
|
|
149
|
+
return running.find((s) => s.id === sessionId || s.id.startsWith(sessionId)) ?? fail('No running session "' + sessionId + '".', 'Running sessions: ' + running.map((s) => s.id).join(', ') + ' (sandbox sessions lists them).');
|
|
150
|
+
};
|
|
151
|
+
/** Forgets status from a previous sandbox run so nothing stale is picked up. */
|
|
152
|
+
export const resetRunDir = (dataPath) => {
|
|
153
|
+
const p = runPaths(dataPath);
|
|
154
|
+
// A link (planted by a sandbox) is removed itself and never followed, including `run` itself.
|
|
155
|
+
if (isLink(p.run)) {
|
|
156
|
+
removeLink(p.run);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
for (const target of [p.sandbox, p.requests, p.responses, p.sessions, p.projects]) {
|
|
160
|
+
safeRemove(target, dataPath);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ClaudeProfileConfig, ProfileResult } from '../core/types.js';
|
|
2
|
+
import { type SecretsConfig } from './secrets.js';
|
|
3
|
+
export declare const hostClaudeDir: (settings: ClaudeProfileConfig) => string;
|
|
4
|
+
export declare const hostGlobalStateFile: (settings: ClaudeProfileConfig) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Copies SELECTED Claude settings from this PC into the launch folder. Conversation history is handled
|
|
7
|
+
* separately by history.ts (it needs path translation), and the login only travels when copyCredentials is on.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* What of your .claude.json the sandbox gets: everything except secrets and other projects. API keys and the account
|
|
11
|
+
* block stay on this PC (logins travel only through `sandbox account`), and of the per-project entries only
|
|
12
|
+
* this workspace's (with its MCP servers) is kept; other projects' entries can hold their MCP servers' tokens.
|
|
13
|
+
*/
|
|
14
|
+
export declare const sandboxGlobalState: (state: Record<string, unknown>, workspaceHost: string) => Record<string, unknown>;
|
|
15
|
+
export declare const stageClaudeProfile: (settings: ClaudeProfileConfig, launchPath: string, workspaceHost: string, secrets: SecretsConfig) => ProfileResult;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { stripMcpServers, stripSettings } from './secrets.js';
|
|
4
|
+
import { dirExists, ensureDir, fileExists, homeDir, isLink, readJson, writeJson } from '../core/util.js';
|
|
5
|
+
const MAX_BYTES = 250 * 1024 * 1024;
|
|
6
|
+
/** Real files only: a link inside ~/.claude (even a loop or a dead one) is neither followed nor counted nor copied. */
|
|
7
|
+
const directorySize = (dir) => {
|
|
8
|
+
let total = 0;
|
|
9
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
10
|
+
const full = path.join(dir, entry.name);
|
|
11
|
+
if (entry.isDirectory())
|
|
12
|
+
total += directorySize(full);
|
|
13
|
+
else if (entry.isFile())
|
|
14
|
+
total += fs.statSync(full).size;
|
|
15
|
+
}
|
|
16
|
+
return total;
|
|
17
|
+
};
|
|
18
|
+
const validJson = (file) => {
|
|
19
|
+
try {
|
|
20
|
+
JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export const hostClaudeDir = (settings) => {
|
|
28
|
+
return settings.hostDir === 'auto' ? (process.env.CLAUDE_CONFIG_DIR ?? path.join(homeDir(), '.claude')) : settings.hostDir;
|
|
29
|
+
};
|
|
30
|
+
export const hostGlobalStateFile = (settings) => {
|
|
31
|
+
if (settings.globalStateFile !== 'auto')
|
|
32
|
+
return settings.globalStateFile;
|
|
33
|
+
return process.env.CLAUDE_CONFIG_DIR ? path.join(process.env.CLAUDE_CONFIG_DIR, '.claude.json') : path.join(homeDir(), '.claude.json');
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Copies SELECTED Claude settings from this PC into the launch folder. Conversation history is handled
|
|
37
|
+
* separately by history.ts (it needs path translation), and the login only travels when copyCredentials is on.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* What of your .claude.json the sandbox gets: everything except secrets and other projects. API keys and the account
|
|
41
|
+
* block stay on this PC (logins travel only through `sandbox account`), and of the per-project entries only
|
|
42
|
+
* this workspace's (with its MCP servers) is kept; other projects' entries can hold their MCP servers' tokens.
|
|
43
|
+
*/
|
|
44
|
+
export const sandboxGlobalState = (state, workspaceHost) => {
|
|
45
|
+
const { primaryApiKey: _key, customApiKeyResponses: _responses, oauthAccount: _account, projects, ...rest } = state;
|
|
46
|
+
const same = (key) => key.replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase() === workspaceHost.replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase();
|
|
47
|
+
const own = Object.entries((projects ?? {})).filter(([key]) => same(key));
|
|
48
|
+
return { ...rest, projects: Object.fromEntries(own) };
|
|
49
|
+
};
|
|
50
|
+
export const stageClaudeProfile = (settings, launchPath, workspaceHost, secrets) => {
|
|
51
|
+
const result = { hostDir: null, staged: [], skipped: [], credentials: false, secretsRemoved: [] };
|
|
52
|
+
if (!settings.enabled)
|
|
53
|
+
return result;
|
|
54
|
+
const hostDir = hostClaudeDir(settings);
|
|
55
|
+
result.hostDir = hostDir;
|
|
56
|
+
const target = path.join(launchPath, 'claude-profile');
|
|
57
|
+
ensureDir(target);
|
|
58
|
+
// The login file goes only through copyCredentials (a project file asking for it is flagged); include never copies it.
|
|
59
|
+
const items = settings.include.filter((name) => name.toLowerCase() !== '.credentials.json');
|
|
60
|
+
if (settings.copyCredentials)
|
|
61
|
+
items.push('.credentials.json');
|
|
62
|
+
for (const name of items) {
|
|
63
|
+
if (!/^[A-Za-z0-9._-]+$/.test(name) || name === '.' || name === '..') {
|
|
64
|
+
result.skipped.push(name + ' (invalid name)');
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const source = path.join(hostDir, name);
|
|
68
|
+
const destination = path.join(target, name);
|
|
69
|
+
if (fileExists(source)) {
|
|
70
|
+
if (name.toLowerCase().endsWith('.json') && !validJson(source)) {
|
|
71
|
+
result.skipped.push(name + ' (invalid JSON on host; fix or remove it)');
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// Claude's settings can carry credentials in "env" and commands that fetch them; those stay here.
|
|
75
|
+
if (/^settings(.local)?.json$/i.test(name))
|
|
76
|
+
writeJson(destination, stripSettings(readJson(source), secrets, result.secretsRemoved));
|
|
77
|
+
else
|
|
78
|
+
fs.copyFileSync(source, destination);
|
|
79
|
+
}
|
|
80
|
+
else if (dirExists(source)) {
|
|
81
|
+
if (directorySize(source) > MAX_BYTES) {
|
|
82
|
+
result.skipped.push(name + ' (over 250 MB)');
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
fs.cpSync(source, destination, { recursive: true, force: true, filter: (from) => from === source || !isLink(from) });
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
result.skipped.push(name + ' (not found)');
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
result.staged.push(name);
|
|
92
|
+
if (name === '.credentials.json')
|
|
93
|
+
result.credentials = true;
|
|
94
|
+
}
|
|
95
|
+
if (settings.globalStateFile !== '') {
|
|
96
|
+
const globalFile = hostGlobalStateFile(settings);
|
|
97
|
+
if (!fileExists(globalFile))
|
|
98
|
+
result.skipped.push('.claude.json (not found)');
|
|
99
|
+
else if (!validJson(globalFile))
|
|
100
|
+
result.skipped.push('.claude.json (invalid JSON on host)');
|
|
101
|
+
else {
|
|
102
|
+
writeJson(path.join(target, '.claude.json'), stripMcpServers(sandboxGlobalState(readJson(globalFile), workspaceHost), secrets, result.secretsRemoved));
|
|
103
|
+
result.staged.push('.claude.json');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface PruneOptions {
|
|
2
|
+
launchDays: number;
|
|
3
|
+
logDays: number;
|
|
4
|
+
conflictDays: number;
|
|
5
|
+
keep: string[];
|
|
6
|
+
now?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface PruneResult {
|
|
9
|
+
launches: number;
|
|
10
|
+
logs: number;
|
|
11
|
+
leftovers: number;
|
|
12
|
+
bytes: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_PRUNE: PruneOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Deletes, under the storage root:
|
|
17
|
+
* - launch folders older than `launchDays` (a launch folder is only used by the sandbox it started; `keep` protects the running one)
|
|
18
|
+
* - sandbox logs older than `logDays`
|
|
19
|
+
* - interrupted downloads/copies (*.staging-*, *.incoming, *.tmp) older than a day
|
|
20
|
+
* - claude-mem conflict copies older than `conflictDays`
|
|
21
|
+
*/
|
|
22
|
+
export declare const pruneStorage: (storageRoot: string, options?: Partial<PruneOptions>) => PruneResult;
|
|
23
|
+
export declare const describePrune: (r: PruneResult) => string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Keeps storage from growing forever. Runs automatically on every launch and via `sandbox clean`.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
import { sizeOf } from '../core/disk.js';
|
|
6
|
+
import { dirExists, isLink } from '../core/util.js';
|
|
7
|
+
import { safeRemove } from '../shared/safe-remove.js';
|
|
8
|
+
const DAY = 24 * 60 * 60 * 1000;
|
|
9
|
+
export const DEFAULT_PRUNE = { launchDays: 7, logDays: 14, conflictDays: 30, keep: [] };
|
|
10
|
+
const ageMs = (p, now) => { try {
|
|
11
|
+
return now - fs.lstatSync(p).mtimeMs;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return 0;
|
|
15
|
+
} };
|
|
16
|
+
/** Entries of a real folder; a link in place of a folder yields nothing (it is never listed or entered). */
|
|
17
|
+
const children = (dir) => (dirExists(dir) && !isLink(dir) ? fs.readdirSync(dir).map((name) => path.join(dir, name)) : []);
|
|
18
|
+
/**
|
|
19
|
+
* Deletes, under the storage root:
|
|
20
|
+
* - launch folders older than `launchDays` (a launch folder is only used by the sandbox it started; `keep` protects the running one)
|
|
21
|
+
* - sandbox logs older than `logDays`
|
|
22
|
+
* - interrupted downloads/copies (*.staging-*, *.incoming, *.tmp) older than a day
|
|
23
|
+
* - claude-mem conflict copies older than `conflictDays`
|
|
24
|
+
*/
|
|
25
|
+
export const pruneStorage = (storageRoot, options = {}) => {
|
|
26
|
+
const o = { ...DEFAULT_PRUNE, ...options };
|
|
27
|
+
const now = o.now ?? Date.now();
|
|
28
|
+
const result = { launches: 0, logs: 0, leftovers: 0, bytes: 0 };
|
|
29
|
+
const remove = (p, counter) => {
|
|
30
|
+
result.bytes += sizeOf(p);
|
|
31
|
+
safeRemove(p, storageRoot);
|
|
32
|
+
result[counter]++;
|
|
33
|
+
};
|
|
34
|
+
for (const launch of children(path.join(storageRoot, 'launches'))) {
|
|
35
|
+
if (!o.keep.includes(path.basename(launch)) && ageMs(launch, now) > o.launchDays * DAY)
|
|
36
|
+
remove(launch, 'launches');
|
|
37
|
+
}
|
|
38
|
+
for (const data of children(path.join(storageRoot, 'data'))) {
|
|
39
|
+
for (const log of children(path.join(data, 'logs')))
|
|
40
|
+
if (ageMs(log, now) > o.logDays * DAY)
|
|
41
|
+
remove(log, 'logs');
|
|
42
|
+
const runDir = path.join(data, 'run');
|
|
43
|
+
const dirs = [path.join(data, 'tools'), path.join(data, 'state'), ...(isLink(runDir) ? [] : [runDir, path.join(runDir, 'responses')])];
|
|
44
|
+
for (const dir of dirs) {
|
|
45
|
+
for (const entry of children(dir)) {
|
|
46
|
+
const name = path.basename(entry);
|
|
47
|
+
const leftover = /\.staging-[0-9a-f]+$|\.incoming$|\.tmp$/i.test(name) && ageMs(entry, now) > DAY;
|
|
48
|
+
const oldResponse = dir.endsWith('responses') && ageMs(entry, now) > DAY;
|
|
49
|
+
const oldConflict = /\.conflict-\d+$/.test(name) && ageMs(entry, now) > o.conflictDays * DAY;
|
|
50
|
+
if (leftover || oldResponse || oldConflict)
|
|
51
|
+
remove(entry, 'leftovers');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
export const describePrune = (r) => r.launches + r.logs + r.leftovers === 0 ? 'nothing to clean' : _.compact([r.launches && r.launches + ' launch folder(s)', r.logs && r.logs + ' log(s)', r.leftovers && r.leftovers + ' leftover(s)']).join(', ') + ' removed (' + Math.round(r.bytes / 1048576) + ' MB)';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config, DatabasePlan } from '../core/types.js';
|
|
2
|
+
import { type Database, type ProjectFile } from '../core/detect-databases.js';
|
|
3
|
+
/**
|
|
4
|
+
* What to run in this sandbox: databases set to true, plus "auto" ones the project needs. SQL Server is reported (so
|
|
5
|
+
* the user hears about it) but cannot run inside Windows Sandbox.
|
|
6
|
+
*/
|
|
7
|
+
export declare const planDatabases: (config: Config["databases"], workspace: string, probe?: {
|
|
8
|
+
files?: ProjectFile[];
|
|
9
|
+
host?: Database[];
|
|
10
|
+
}) => DatabasePlan[];
|
|
11
|
+
/** Every database the sandbox can run, so `sbx-db start <name>` works for ones that did not start at boot. */
|
|
12
|
+
export declare const databaseCatalog: (config: Config["databases"]) => DatabasePlan[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { DATABASES, detectDatabases } from '../core/detect-databases.js';
|
|
2
|
+
import { hostDatabases } from './pc-scan.js';
|
|
3
|
+
import { readProjectFiles } from './project-scan.js';
|
|
4
|
+
/** The version a compose file pins (postgres:16-alpine -> 16, mongo:7.0 -> 7.0), if any. */
|
|
5
|
+
const pinnedVersion = (files, image) => {
|
|
6
|
+
for (const file of files) {
|
|
7
|
+
const match = image.exec(file.text);
|
|
8
|
+
if (match?.[1] && /^\d+(\.\d+)?/.test(match[1]))
|
|
9
|
+
return /^\d+(\.\d+)?/.exec(match[1])[0];
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* What to run in this sandbox: databases set to true, plus "auto" ones the project needs. SQL Server is reported (so
|
|
15
|
+
* the user hears about it) but cannot run inside Windows Sandbox.
|
|
16
|
+
*/
|
|
17
|
+
export const planDatabases = (config, workspace, probe = {}) => {
|
|
18
|
+
const autos = DATABASES.filter((db) => config[db].enabled === 'auto');
|
|
19
|
+
const files = autos.length ? probe.files ?? readProjectFiles(workspace) : [];
|
|
20
|
+
const detected = autos.length ? detectDatabases(files, probe.host ?? hostDatabases) : [];
|
|
21
|
+
const plan = databasePlanner(config, files.filter((f) => /compose/i.test(f.path)));
|
|
22
|
+
return DATABASES.flatMap((database) => {
|
|
23
|
+
const setting = config[database].enabled;
|
|
24
|
+
const found = detected.find((d) => d.database === database);
|
|
25
|
+
if (setting === true)
|
|
26
|
+
return [plan(database, ['enabled in config'])];
|
|
27
|
+
if (setting === 'auto' && found)
|
|
28
|
+
return [plan(database, found.reasons)];
|
|
29
|
+
return [];
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
/** Every database the sandbox can run, so `sbx-db start <name>` works for ones that did not start at boot. */
|
|
33
|
+
export const databaseCatalog = (config) => {
|
|
34
|
+
const plan = databasePlanner(config, []);
|
|
35
|
+
return DATABASES.filter((db) => db !== 'sqlserver').map((db) => plan(db, ['started with sbx-db']));
|
|
36
|
+
};
|
|
37
|
+
/** Version (a compose file's image tag wins), port and admin UI for one database. */
|
|
38
|
+
const databasePlanner = (config, compose) => {
|
|
39
|
+
const versions = {
|
|
40
|
+
postgres: pinnedVersion(compose, /image:\s*["']?(?:[\w.-]+\/)*postgres:([\w.-]+)/i) ?? (config.postgres.version === 'latest' ? 'latest' : config.postgres.version),
|
|
41
|
+
mysql: config.mysql.version,
|
|
42
|
+
mongodb: pinnedVersion(compose, /image:\s*["']?(?:[\w.-]+\/)*mongo:([\w.-]+)/i) ?? config.mongodb.version,
|
|
43
|
+
redis: 'latest',
|
|
44
|
+
dynamodb: 'latest',
|
|
45
|
+
sqlserver: '',
|
|
46
|
+
};
|
|
47
|
+
const ports = { postgres: config.postgres.port, mysql: config.mysql.port, mongodb: config.mongodb.port, redis: config.redis.port, dynamodb: config.dynamodb.port, sqlserver: 1433 };
|
|
48
|
+
return (database, reasons) => ({
|
|
49
|
+
database, reasons, version: versions[database], port: ports[database],
|
|
50
|
+
...(database === 'dynamodb' && config.dynamodb.admin ? { adminPort: config.dynamodb.adminPort } : {}),
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GenerateOptions, Generated } from '../core/types.js';
|
|
2
|
+
import { decideToolchains } from '../core/detect-toolchains.js';
|
|
3
|
+
/** Which toolchains the project needs ("auto" settings follow the project's files and what this PC has). */
|
|
4
|
+
export declare const decideProjectToolchains: (o: Pick<GenerateOptions, "run" | "pcLanguages">) => ReturnType<typeof decideToolchains>;
|
|
5
|
+
export declare const generateSandbox: (o: GenerateOptions) => Generated & {
|
|
6
|
+
personalization: string;
|
|
7
|
+
};
|