windows-development-sandbox 0.0.0-stage → 1.0.5
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/README.md +78 -2
- package/config.example.json +332 -0
- package/dist/api.d.ts +31 -0
- package/dist/api.js +30 -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 +32 -0
- package/dist/cli/args.js +111 -0
- package/dist/cli/commands/accounts.d.ts +2 -0
- package/dist/cli/commands/accounts.js +52 -0
- package/dist/cli/commands/context.d.ts +21 -0
- package/dist/cli/commands/context.js +54 -0
- package/dist/cli/commands/data.d.ts +46 -0
- package/dist/cli/commands/data.js +249 -0
- package/dist/cli/commands/index.d.ts +8 -0
- package/dist/cli/commands/index.js +8 -0
- package/dist/cli/commands/launch.d.ts +5 -0
- package/dist/cli/commands/launch.js +152 -0
- package/dist/cli/commands/maintenance.d.ts +8 -0
- package/dist/cli/commands/maintenance.js +125 -0
- package/dist/cli/commands/repair.d.ts +59 -0
- package/dist/cli/commands/repair.js +332 -0
- package/dist/cli/commands/sessions.d.ts +11 -0
- package/dist/cli/commands/sessions.js +113 -0
- package/dist/cli/commands/setup.d.ts +45 -0
- package/dist/cli/commands/setup.js +152 -0
- package/dist/cli/index.d.ts +14 -0
- package/dist/cli/index.js +96 -0
- package/dist/cli/manifest.d.ts +95 -0
- package/dist/cli/manifest.js +87 -0
- package/dist/cli/menu.d.ts +22 -0
- package/dist/cli/menu.js +187 -0
- package/dist/cli/settings.d.ts +11 -0
- package/dist/cli/settings.js +156 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.js +103 -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/local-config.d.ts +12 -0
- package/dist/core/local-config.js +64 -0
- package/dist/core/schema.d.ts +604 -0
- package/dist/core/schema.js +264 -0
- package/dist/core/types.d.ts +162 -0
- package/dist/core/types.js +1 -0
- package/dist/core/util.d.ts +53 -0
- package/dist/core/util.js +145 -0
- package/dist/core/workspace.d.ts +23 -0
- package/dist/core/workspace.js +162 -0
- package/dist/guest/daemon.d.ts +1 -0
- package/dist/guest/daemon.js +186 -0
- package/dist/guest/db.d.ts +1 -0
- package/dist/guest/db.js +60 -0
- package/dist/guest/env.d.ts +49 -0
- package/dist/guest/env.js +99 -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 +12 -0
- package/dist/guest/guide.js +68 -0
- package/dist/guest/main.d.ts +1 -0
- package/dist/guest/main.js +120 -0
- package/dist/guest/ptyhost.d.ts +40 -0
- package/dist/guest/ptyhost.js +94 -0
- package/dist/guest/setup/agents.d.ts +8 -0
- package/dist/guest/setup/agents.js +73 -0
- package/dist/guest/setup/claude.d.ts +21 -0
- package/dist/guest/setup/claude.js +138 -0
- package/dist/guest/setup/environment.d.ts +6 -0
- package/dist/guest/setup/environment.js +65 -0
- package/dist/guest/setup/hooks.d.ts +1 -0
- package/dist/guest/setup/hooks.js +36 -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/binstall.d.ts +7 -0
- package/dist/guest/toolchains/binstall.js +55 -0
- package/dist/guest/toolchains/catalogue.d.ts +51 -0
- package/dist/guest/toolchains/catalogue.js +31 -0
- package/dist/guest/toolchains/cli.d.ts +10 -0
- package/dist/guest/toolchains/cli.js +64 -0
- package/dist/guest/toolchains/common.d.ts +37 -0
- package/dist/guest/toolchains/common.js +124 -0
- package/dist/guest/toolchains/databases.d.ts +7 -0
- package/dist/guest/toolchains/databases.js +226 -0
- package/dist/guest/toolchains/git.d.ts +3 -0
- package/dist/guest/toolchains/git.js +112 -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 +13 -0
- package/dist/guest/toolchains/index.js +122 -0
- package/dist/guest/toolchains/java.d.ts +8 -0
- package/dist/guest/toolchains/java.js +96 -0
- package/dist/guest/toolchains/managers.d.ts +16 -0
- package/dist/guest/toolchains/managers.js +82 -0
- package/dist/guest/toolchains/msvc.d.ts +10 -0
- package/dist/guest/toolchains/msvc.js +216 -0
- package/dist/guest/toolchains/native.d.ts +12 -0
- package/dist/guest/toolchains/native.js +220 -0
- package/dist/guest/toolchains/node.d.ts +3 -0
- package/dist/guest/toolchains/node.js +132 -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 +47 -0
- package/dist/guest/toolchains/runtimes.d.ts +17 -0
- package/dist/guest/toolchains/runtimes.js +40 -0
- package/dist/guest/toolchains/scripting.d.ts +10 -0
- package/dist/guest/toolchains/scripting.js +137 -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 +22 -0
- package/dist/host/accounts.d.ts +32 -0
- package/dist/host/accounts.js +119 -0
- package/dist/host/channel.d.ts +37 -0
- package/dist/host/channel.js +180 -0
- package/dist/host/claude-profile.d.ts +15 -0
- package/dist/host/claude-profile.js +103 -0
- package/dist/host/cleanup.d.ts +23 -0
- package/dist/host/cleanup.js +66 -0
- package/dist/host/generate.d.ts +15 -0
- package/dist/host/generate.js +185 -0
- package/dist/host/personalize.d.ts +10 -0
- package/dist/host/personalize.js +97 -0
- package/dist/host/platform.d.ts +17 -0
- package/dist/host/platform.js +114 -0
- package/dist/host/project-scan.d.ts +23 -0
- package/dist/host/project-scan.js +173 -0
- package/dist/host/repo-guard.d.ts +23 -0
- package/dist/host/repo-guard.js +128 -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 +127 -0
- package/dist/host/window.d.ts +4 -0
- package/dist/host/window.js +68 -0
- package/dist/runtime/daemon.js +20291 -0
- package/dist/runtime/db.js +20423 -0
- package/dist/runtime/gitguard.js +84 -0
- package/dist/runtime/main.js +22398 -0
- package/dist/runtime/view.js +19966 -0
- package/dist/selftest/cli.test.d.ts +2 -0
- package/dist/selftest/cli.test.js +30 -0
- package/dist/selftest/config.test.d.ts +3 -0
- package/dist/selftest/config.test.js +74 -0
- package/dist/selftest/data.test.d.ts +2 -0
- package/dist/selftest/data.test.js +73 -0
- package/dist/selftest/detect.test.d.ts +2 -0
- package/dist/selftest/detect.test.js +42 -0
- package/dist/selftest/fixtures.d.ts +232 -0
- package/dist/selftest/fixtures.js +63 -0
- package/dist/selftest/guest.test.d.ts +3 -0
- package/dist/selftest/guest.test.js +61 -0
- package/dist/selftest/harness.d.ts +14 -0
- package/dist/selftest/harness.js +36 -0
- package/dist/selftest/helpers.test.d.ts +2 -0
- package/dist/selftest/helpers.test.js +125 -0
- package/dist/selftest/host.test.d.ts +2 -0
- package/dist/selftest/host.test.js +71 -0
- package/dist/selftest/index.d.ts +1 -0
- package/dist/selftest/index.js +56 -0
- package/dist/selftest/live.test.d.ts +7 -0
- package/dist/selftest/live.test.js +127 -0
- package/dist/selftest/mirror.test.d.ts +3 -0
- package/dist/selftest/mirror.test.js +74 -0
- package/dist/selftest/security.test.d.ts +3 -0
- package/dist/selftest/security.test.js +143 -0
- package/dist/selftest/setup.test.d.ts +2 -0
- package/dist/selftest/setup.test.js +23 -0
- package/dist/selftest/sync.test.d.ts +3 -0
- package/dist/selftest/sync.test.js +82 -0
- package/dist/shared/download.d.ts +58 -0
- package/dist/shared/download.js +200 -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 +9 -0
- package/dist/shared/paths.js +22 -0
- package/dist/shared/pty-client.d.ts +86 -0
- package/dist/shared/pty-client.js +227 -0
- package/dist/shared/rundir.d.ts +30 -0
- package/dist/shared/rundir.js +86 -0
- package/dist/shared/safe-remove.d.ts +10 -0
- package/dist/shared/safe-remove.js +55 -0
- package/dist/shared/schema.d.ts +84 -0
- package/dist/shared/schema.js +51 -0
- package/dist/shared/system.d.ts +15 -0
- package/dist/shared/system.js +19 -0
- package/dist/sync/claude-mem.d.ts +8 -0
- package/dist/sync/claude-mem.js +77 -0
- package/dist/sync/history.d.ts +30 -0
- package/dist/sync/history.js +129 -0
- package/dist/sync/watcher.d.ts +13 -0
- package/dist/sync/watcher.js +116 -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/gitshim.cs +35 -0
- package/sandbox/logon.cmd +16 -0
- package/sandbox/ptyhost.cs +603 -0
- package/sandbox/trust.cmd +35 -0
- package/sandbox/vswhere.cs +83 -0
- package/schemas/config.schema.json +1062 -0
- package/schemas/sandbox-config.schema.json +952 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// Every setting, defined once with zod: the user config (~/.agent-sandbox/config.json) and the much smaller subset a
|
|
2
|
+
// project's .sandbox-config.json may change. Types are inferred from these schemas, and the JSON Schema files in
|
|
3
|
+
// schemas/ (editor autocomplete and docs via "$schema") are generated from them at build time.
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { isValidGuestPath } from '../shared/guest-paths.js';
|
|
7
|
+
// Rules (and RESERVED_GUEST) live in shared/guest-paths.ts: the host re-checks them before writing the .wsb.
|
|
8
|
+
export const GuestPath = z.string().refine(isValidGuestPath, 'reserved or invalid guest path (a folder under C:\\ other than Windows, Program Files, Users, AgentData, Mirror, ..., or on drive D: to Z:)');
|
|
9
|
+
const Name = z.string().regex(/^[A-Za-z0-9_-]+$/, 'letters, numbers, - and _ only');
|
|
10
|
+
const Strings = z.array(z.string());
|
|
11
|
+
const toggle = (description) => z.strictObject({ enabled: z.boolean().describe(description) });
|
|
12
|
+
const SchemaRef = z.string().describe('Path or URL of the JSON Schema for editor autocomplete and docs.');
|
|
13
|
+
export const GitAccess = z.enum(['full', 'readonly', 'none'])
|
|
14
|
+
.describe('full: normal git. readonly: status/log/diff/show/blame only (no commit, push, checkout, ...). none: no git at all; .git is hidden from the agent.');
|
|
15
|
+
const GuestWorkspace = z.union([z.literal('auto'), z.literal('mirror'), GuestPath]).describe('Where the workspace appears inside the sandbox. "auto" = C:\\Workspace\\<folder name>. "mirror" = the same path as on this PC, so absolute paths in configs and build caches match (another drive letter such as F: is a subst drive onto C:\\Mirror\\F); paths the sandbox reserves (C:\\Users\\..., C:\\Program Files\\...) fall back to "auto".');
|
|
16
|
+
export const Mapping = z.strictObject({
|
|
17
|
+
host: z.string().min(1).describe('Folder on this PC (relative paths are relative to the config file).'),
|
|
18
|
+
guest: GuestPath.describe('Where it appears inside the sandbox, e.g. C:\\Assets, or on another drive letter (D: to Z:) such as F:\\SteamLibrary\\steamapps\\common\\Game: mapped to C:\\Mirror\\F\\... and shown as F: (subst) at boot.'),
|
|
19
|
+
readOnly: z.boolean().describe('true = the agent can only read it.'),
|
|
20
|
+
optional: z.boolean().optional().describe('true = skip it quietly when the host folder does not exist.'),
|
|
21
|
+
});
|
|
22
|
+
export const Harness = z.strictObject({
|
|
23
|
+
hostExecutable: z.string().optional().describe('Executable copied from this PC when installed here (e.g. claude.exe).'),
|
|
24
|
+
hostDir: z.string().optional().describe('Folder of hostExecutable on this PC, or "auto" to search PATH and ~/.local/bin.'),
|
|
25
|
+
npmPackage: z.string().optional().describe('npm package installed inside the sandbox when there is no host copy.'),
|
|
26
|
+
npmBin: z.string().optional().describe('Command the npm package provides.'),
|
|
27
|
+
uvPackage: z.string().optional().describe('Python package installed with `uv tool install` inside the sandbox (e.g. aider-chat).'),
|
|
28
|
+
uvBin: z.string().optional().describe('Command the uv package provides.'),
|
|
29
|
+
arguments: Strings.describe('Arguments always passed to the agent.'),
|
|
30
|
+
environment: z.record(z.string(), z.string()).describe('Environment variables for the agent.'),
|
|
31
|
+
resumeArguments: Strings.optional().describe('Arguments used when the agent is restarted in place (e.g. after an account switch) so it resumes the conversation.'),
|
|
32
|
+
})
|
|
33
|
+
.refine((h) => h.hostExecutable || h.npmPackage || h.uvPackage, 'needs hostExecutable, npmPackage or uvPackage')
|
|
34
|
+
.refine((h) => !h.uvPackage || h.uvBin, 'needs uvBin when uvPackage is set')
|
|
35
|
+
.refine((h) => !h.npmPackage || h.npmBin, 'needs npmBin when npmPackage is set');
|
|
36
|
+
const Sandbox = z.strictObject({
|
|
37
|
+
memoryMb: z.union([z.literal('auto'), z.number().int().min(2048)]).describe('Sandbox RAM in MB (>= 2048), or "auto": free RAM minus reserveHostMb, capped at maxMemoryMb.'),
|
|
38
|
+
maxMemoryMb: z.number().int().positive().describe('Upper limit for memoryMb "auto".'),
|
|
39
|
+
reserveHostMb: z.number().int().nonnegative().describe('RAM always left for this PC when memoryMb is "auto".'),
|
|
40
|
+
vGpu: z.boolean().describe('Virtual GPU. Off by default: Microsoft notes it widens the sandbox attack surface.'),
|
|
41
|
+
networking: z.boolean().describe('Internet access. false is the only hard network isolation Windows Sandbox offers.'),
|
|
42
|
+
clipboard: z.boolean().describe('Shared clipboard between this PC and the sandbox.'),
|
|
43
|
+
audioInput: z.boolean().describe('Microphone access.'),
|
|
44
|
+
videoInput: z.boolean().describe('Camera access.'),
|
|
45
|
+
printerRedirection: z.boolean().describe('Printers from this PC.'),
|
|
46
|
+
protectedClient: z.boolean().describe('Run the sandbox window in Protected Client mode (recommended).'),
|
|
47
|
+
headless: z.boolean().describe('Hide the sandbox window (sbx-show brings it back). A headless sandbox shuts down when its last session ends.'),
|
|
48
|
+
});
|
|
49
|
+
const Git = z.strictObject({ enabled: z.boolean().describe('Provide Git for Windows (and Git Bash, which Claude Code needs).'), access: GitAccess });
|
|
50
|
+
const Provisioning = z.strictObject({
|
|
51
|
+
copyFromHost: z.boolean().describe('Copy Node, Git, nvm and the agent from this PC when they are installed here.'),
|
|
52
|
+
fallbackToInstall: z.boolean().describe('Download anything that cannot be copied from this PC.'),
|
|
53
|
+
refresh: z.boolean().describe('Re-copy / re-download everything on the next launch.'),
|
|
54
|
+
git: Git,
|
|
55
|
+
terminal: toggle('Windows Terminal as the sandbox window (downloaded once).'),
|
|
56
|
+
});
|
|
57
|
+
/** true, false, or "auto": only when the project uses it (found from files like go.mod in the workspace or one level down). */
|
|
58
|
+
export const Enabled = z.union([z.boolean(), z.literal('auto')]);
|
|
59
|
+
const enabled = (what, markers) => Enabled.describe(what + ' true, false, or "auto" = only when the project has ' + markers + '.');
|
|
60
|
+
const Packages = (what, example) => Strings.describe(what + ', installed once and kept (e.g. ' + example + ').');
|
|
61
|
+
const Toolchains = z.strictObject({
|
|
62
|
+
node: z.strictObject({
|
|
63
|
+
version: z.string().min(1).describe('Default Node version for nvm. "host" = the Node on this PC. A project\'s .nvmrc / .node-version wins.'),
|
|
64
|
+
extraVersions: Strings.describe('More Node versions to install (switch with nvm use). On top of the up to 3 versions copied from this PC\'s nvm, not counted towards that limit.'),
|
|
65
|
+
corepack: z.boolean().describe('pnpm and yarn through corepack (a project\'s "packageManager" in package.json picks the version).'),
|
|
66
|
+
volta: Enabled.describe('Volta: true, false, or "auto" = when the project\'s package.json has "volta" pins or this PC uses Volta. With pins, Volta\'s node/npm/yarn/pnpm come first on PATH.'),
|
|
67
|
+
globalPackages: Packages('npm packages installed globally into the default Node version', '["typescript", "npm-check-updates"]'),
|
|
68
|
+
}),
|
|
69
|
+
python: z.strictObject({
|
|
70
|
+
enabled: enabled('Python 3 (CPython with pip).', 'pyproject.toml, requirements.txt, setup.py, Pipfile or .python-version'),
|
|
71
|
+
version: z.string().min(1).describe('Python 3 version prefix, e.g. "3" or "3.12". A project\'s .python-version wins.'),
|
|
72
|
+
python2: z.boolean().describe('Also install Python 2.7 as python2 / pip2.'),
|
|
73
|
+
pyenv: Enabled.describe('pyenv-win (pyenv install / local / global): true, false, or "auto" = when this PC uses pyenv. .python-version is honoured either way, and `uv python install` always works.'),
|
|
74
|
+
tools: Packages('Python command-line tools installed with `uv tool install` (needs uv)', '["poetry", "ruff", "pre-commit"]'),
|
|
75
|
+
}),
|
|
76
|
+
rust: z.strictObject({
|
|
77
|
+
enabled: enabled('Rust via rustup (cargo, rustc).', 'Cargo.toml or rust-toolchain(.toml)'),
|
|
78
|
+
toolchain: z.string().min(1).describe('Default toolchain, e.g. "stable". rust-toolchain.toml in a project wins.'),
|
|
79
|
+
host: z.string().min(1).describe('Host triple, or "auto": x86_64-pc-windows-msvc when the MSVC toolchain is on (like most PCs), else x86_64-pc-windows-gnu (MinGW is its linker).'),
|
|
80
|
+
components: Packages('Extra rustup components', '["rust-src", "llvm-tools"]'),
|
|
81
|
+
targets: Packages('Extra rustup targets', '["wasm32-unknown-unknown"]'),
|
|
82
|
+
crates: Packages('Binaries for cargo: prebuilt via cargo-binstall when the crate publishes a Windows build, else compiled with `cargo install --locked` (slow the first time)', '["sccache", "cargo-nextest", "cargo-deny"]'),
|
|
83
|
+
targetDir: z.string().min(1).describe('"shared": cargo\'s default target\\ (shared with builds on this PC, so builds on either side invalidate the other), "separate": <workspace>\\target\\sandbox (kept, no cross-talk), "local": on the sandbox\'s own disk (fastest, lost every boot), or a guest path.'),
|
|
84
|
+
}),
|
|
85
|
+
msvc: z.strictObject({
|
|
86
|
+
enabled: enabled('MSVC (cl, link) and the Windows SDK, portable from Microsoft\'s Visual Studio manifest (~1-2 GB once), with vcvars64.bat and vswhere.', 'a .vcxproj, CMakePresets.json, a script calling vcvars/vswhere, or a Rust project when this PC builds Rust with MSVC'),
|
|
87
|
+
acceptLicense: z.boolean().describe('Required to install MSVC: you accept the Visual Studio licence terms (https://visualstudio.microsoft.com/license-terms/), which need a Visual Studio licence.'),
|
|
88
|
+
msvcVersion: z.string().min(1).describe('"latest" or an MSVC tools version prefix, e.g. "14.44".'),
|
|
89
|
+
sdkVersion: z.string().min(1).describe('"latest" or a Windows SDK build, e.g. "26100" or "10.0.22621".'),
|
|
90
|
+
}),
|
|
91
|
+
cpp: z.strictObject({
|
|
92
|
+
enabled: enabled('MinGW-w64 GCC with CMake, Ninja, premake5 and mingw32-make (also Rust\'s linker).', 'CMakeLists.txt, Makefile, meson.build, premake5.lua or Cargo.toml'),
|
|
93
|
+
flexBison: z.boolean().describe('win_flex / win_bison, the parser generators many C/C++ projects (game engines among them) need; CMake finds them.'),
|
|
94
|
+
}),
|
|
95
|
+
dotnet: z.strictObject({
|
|
96
|
+
enabled: enabled('.NET SDK (C#, F#).', 'a .sln, .slnx, .csproj, .fsproj or global.json'),
|
|
97
|
+
channels: Strings.describe('SDK channels, e.g. ["LTS", "8.0"]. A project\'s global.json is installed too.'),
|
|
98
|
+
tools: Packages('Global .NET tools (`dotnet tool install -g`)', '["dotnet-ef", "csharpier"]'),
|
|
99
|
+
workloads: Packages('SDK workloads (`dotnet workload install`)', '["aspire", "wasm-tools"]'),
|
|
100
|
+
frameworkTargets: Strings.describe('.NET Framework reference assemblies (targeting packs) from NuGet, so net4x and old-style .csproj projects build without Visual Studio, e.g. ["net48", "net472", "net462"]. The 4.8 runtime itself ships with Windows.'),
|
|
101
|
+
netfx35: z.boolean().describe('.NET Framework 3.5 runtime (a Windows feature, enabled from Windows Update on every boot; a few minutes).'),
|
|
102
|
+
}),
|
|
103
|
+
go: z.strictObject({
|
|
104
|
+
enabled: enabled('Go.', 'go.mod or go.work'),
|
|
105
|
+
version: z.string().min(1).describe('"stable" or a version prefix such as "1.23". A go.mod asking for newer fetches it itself (GOTOOLCHAIN=auto).'),
|
|
106
|
+
tools: Packages('Go tools (`go install <path>@<version>`)', '["golang.org/x/tools/gopls@latest"]'),
|
|
107
|
+
}),
|
|
108
|
+
java: z.strictObject({
|
|
109
|
+
enabled: enabled('Java: Eclipse Temurin JDK.', 'pom.xml, build.gradle(.kts), settings.gradle(.kts), mvnw, gradlew or .java-version'),
|
|
110
|
+
version: z.string().min(1).describe('"lts" (newest LTS) or a major version such as "21". A project\'s .java-version or .sdkmanrc wins.'),
|
|
111
|
+
maven: z.boolean().describe('Apache Maven (mvn). A project\'s mvnw works either way.'),
|
|
112
|
+
gradle: z.boolean().describe('Gradle (gradle). A project\'s gradlew works either way.'),
|
|
113
|
+
}),
|
|
114
|
+
ruby: z.strictObject({
|
|
115
|
+
enabled: enabled('Ruby (RubyInstaller, with gem and bundler). Gems with C extensions need MSYS2, which is not included.', 'Gemfile, a .gemspec or .ruby-version'),
|
|
116
|
+
version: z.string().min(1).describe('Version prefix, e.g. "3" or "3.3". A project\'s .ruby-version wins.'),
|
|
117
|
+
gems: Packages('Gems installed globally', '["rubocop"]'),
|
|
118
|
+
}),
|
|
119
|
+
php: z.strictObject({
|
|
120
|
+
enabled: enabled('PHP (with the Visual C++ runtime it needs, installed on every boot).', 'composer.json, artisan or .php-version'),
|
|
121
|
+
version: z.string().min(1).describe('Version prefix, e.g. "8" or "8.3". A project\'s .php-version wins.'),
|
|
122
|
+
composer: z.boolean().describe('Composer.'),
|
|
123
|
+
}),
|
|
124
|
+
deno: z.strictObject({ enabled: enabled('Deno.', 'deno.json, deno.jsonc or deno.lock') }),
|
|
125
|
+
pwsh: z.strictObject({ enabled: Enabled.describe('PowerShell 7 (pwsh), portable (~110 MB once); `powershell` stays Windows PowerShell 5.1. true, false, or "auto" = when a .ps1 at the root or one folder down has #Requires -Version 7 / -PSEdition Core or a `pwsh ...` usage line, or, in a folder that is no project yet, when this PC has PowerShell 7.') }),
|
|
126
|
+
cli: z.strictObject({
|
|
127
|
+
gh: Enabled.describe('GitHub CLI (gh). Only with provisioning.git.access "full": gh can push and merge through the GitHub API, past a read-only git. Your PC\'s gh login is never copied; `gh auth login` inside persists (GH_CONFIG_DIR). "auto" = when the project has a .github folder.'),
|
|
128
|
+
zstd: Enabled.describe('Zstandard (zstd). "auto" = off; set true to get it.'),
|
|
129
|
+
openssl: Enabled.describe('`openssl` on PATH, from the copy Git for Windows ships (its mingw64\\bin is not put on PATH, so it cannot shadow MinGW\'s gcc). "auto" = on.'),
|
|
130
|
+
}).describe('Small portable command-line tools from their GitHub releases, installed once into tools\\cli.'),
|
|
131
|
+
bun: toggle('Bun runtime (claude-mem needs it).'),
|
|
132
|
+
uv: toggle('uv, the Python package manager (claude-mem needs it).'),
|
|
133
|
+
vcRuntime: toggle('Microsoft Visual C++ runtime for tools that need it (a real installer, so it runs on every boot, ~15 s). PHP installs it regardless.'),
|
|
134
|
+
mesa: z.strictObject({
|
|
135
|
+
enabled: z.boolean().describe('Mesa 3D (llvmpipe): OpenGL 4.5 in software for games and apps when there is no GPU (sandbox.vGpu off). Copy opengl32.dll and libgallium_wgl.dll from %MESA_DIR% next to the program\'s .exe.'),
|
|
136
|
+
vulkan: z.boolean().describe('Also software Vulkan 1.4 (Mesa lavapipe) with the Khronos loader, registered for every program; for wgpu set WGPU_BACKEND=vulkan.'),
|
|
137
|
+
}),
|
|
138
|
+
vscode: toggle('Portable VS Code inside the sandbox (code on PATH, desktop shortcut); its settings and extensions persist.'),
|
|
139
|
+
environment: z.record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/, 'letters, digits and _ only'), z.string()).describe('Extra environment variables for the agent and every terminal, e.g. registry mirrors: {"NPM_CONFIG_REGISTRY": "https://...", "PIP_INDEX_URL": "https://..."}.'),
|
|
140
|
+
});
|
|
141
|
+
const Port = z.number().int().min(1024).max(65535);
|
|
142
|
+
const dbEnabled = (name) => Enabled.describe(name + ': true, false, or "auto" = only when the project needs it (found from compose files, dependencies of every language, Prisma/ORM config and connection strings).');
|
|
143
|
+
const Databases = z.strictObject({
|
|
144
|
+
postgres: z.strictObject({
|
|
145
|
+
enabled: dbEnabled('PostgreSQL (with psql, pg_dump). User postgres, no password, localhost only'),
|
|
146
|
+
version: z.string().min(1).describe('"latest" or a major version such as "16". A compose file pinning postgres:<major> wins.'),
|
|
147
|
+
port: Port.describe('Port inside the sandbox.'),
|
|
148
|
+
}),
|
|
149
|
+
mysql: z.strictObject({
|
|
150
|
+
enabled: dbEnabled('MySQL-compatible database (MariaDB). User root, no password, localhost only'),
|
|
151
|
+
version: z.string().min(1).describe('"lts" (newest MariaDB LTS) or a MariaDB series such as "11.4".'),
|
|
152
|
+
port: Port.describe('Port inside the sandbox.'),
|
|
153
|
+
}),
|
|
154
|
+
mongodb: z.strictObject({
|
|
155
|
+
enabled: dbEnabled('MongoDB with mongosh, localhost only'),
|
|
156
|
+
version: z.string().min(1).describe('"latest" or a version prefix such as "8.0".'),
|
|
157
|
+
port: Port.describe('Port inside the sandbox.'),
|
|
158
|
+
}),
|
|
159
|
+
redis: z.strictObject({
|
|
160
|
+
enabled: dbEnabled('Redis (community Windows build), localhost only'),
|
|
161
|
+
port: Port.describe('Port inside the sandbox.'),
|
|
162
|
+
}),
|
|
163
|
+
dynamodb: z.strictObject({
|
|
164
|
+
enabled: dbEnabled('DynamoDB Local (Amazon\'s official emulator, on the Java toolchain) with dynamodb-admin, a web UI to browse and edit tables'),
|
|
165
|
+
port: Port.describe('DynamoDB endpoint port inside the sandbox (http://localhost:<port>).'),
|
|
166
|
+
adminPort: Port.describe('dynamodb-admin web UI port (open http://localhost:<adminPort> in the sandbox\'s browser).'),
|
|
167
|
+
admin: z.boolean().describe('Run dynamodb-admin next to DynamoDB Local.'),
|
|
168
|
+
}),
|
|
169
|
+
sqlserver: z.strictObject({
|
|
170
|
+
enabled: dbEnabled('SQL Server. It cannot run inside Windows Sandbox; when a project needs it you get a hint to reach the one on this PC through hostAccess.forwards'),
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
const Secrets = z.strictObject({
|
|
174
|
+
strip: z.boolean().describe('Remove credentials from everything copied into the sandbox (your Claude settings.json "env" and credential helpers, MCP servers\' env, headers and arguments): AWS, Azure, Google Cloud, Cloudflare, hosting, CI, registries, payment, AI API keys, database URLs, anything named *_TOKEN / *_SECRET / *PASSWORD* / *_KEY or *PROD*, and values that look like keys.'),
|
|
175
|
+
allow: Strings.describe('Variable names that may go in anyway; * matches anything, e.g. ["AWS_REGION", "AWS_PROFILE", "MY_APP_*"].'),
|
|
176
|
+
patterns: Strings.describe('More variable names to treat as secrets; * matches anything, e.g. ["ACME_*", "*_INTERNAL_URL"].'),
|
|
177
|
+
warnFiles: z.boolean().describe('Warn at launch about files in the workspace that usually hold secrets (.env, *.pem, credentials.json, ...). The agent CAN read them: Windows Sandbox maps the whole folder.'),
|
|
178
|
+
});
|
|
179
|
+
const Attach = z.strictObject({
|
|
180
|
+
enabled: z.boolean().describe('Allow sandbox claude --terminal / sandbox attach from this PC.'),
|
|
181
|
+
reuseSession: z.boolean().describe('sandbox claude -t in a running sandbox reattaches to this folder\'s session when no terminal on this PC is attached to it (--new always starts another).'),
|
|
182
|
+
auto: z.boolean().describe('Starting an agent attaches this terminal automatically, as if you passed -t (only in an interactive terminal).'),
|
|
183
|
+
autoHide: z.boolean().describe('Hide the Windows Sandbox window whenever this terminal attaches; it keeps running (sandbox show brings it back).'),
|
|
184
|
+
});
|
|
185
|
+
const ClaudeProfile = z.strictObject({
|
|
186
|
+
enabled: z.boolean().describe('Copy selected Claude settings from this PC into the sandbox.'),
|
|
187
|
+
hostDir: z.string().describe('Your Claude folder, or "auto" (~/.claude or CLAUDE_CONFIG_DIR).'),
|
|
188
|
+
include: z.array(z.string().regex(/^[A-Za-z0-9._-]+$/)).describe('Files and folders copied from it.'),
|
|
189
|
+
globalStateFile: z.string().describe('Your .claude.json, or "auto". Empty string = do not copy.'),
|
|
190
|
+
copyCredentials: z.boolean().describe('Copy your Claude LOGIN into the sandbox. Prefer sandbox account instead.'),
|
|
191
|
+
overwrite: z.boolean().describe('Refresh these settings from this PC on every launch.'),
|
|
192
|
+
syncHistory: z.boolean().describe('Bring all conversation history in, and sync new history back (path-translated).'),
|
|
193
|
+
syncClaudeMem: z.boolean().describe('Bring claude-mem data in, and its database back when the sandbox closes.'),
|
|
194
|
+
});
|
|
195
|
+
export const Config = z.strictObject({
|
|
196
|
+
$schema: SchemaRef.optional(),
|
|
197
|
+
defaultHarness: Name.describe('Agent started by `sandbox launch` (sandbox claude always runs claude).'),
|
|
198
|
+
guestWorkspace: GuestWorkspace,
|
|
199
|
+
readOnly: z.boolean().describe('Map the workspace read-only.'),
|
|
200
|
+
mappings: z.array(Mapping).describe('Extra folders from this PC.'),
|
|
201
|
+
sandbox: Sandbox,
|
|
202
|
+
storage: z.strictObject({
|
|
203
|
+
root: z.string().min(1).describe('Where everything is kept on this PC (tools, databases, logins, launches).'),
|
|
204
|
+
persistAgentState: z.boolean().describe('Keep agent logins and history between sandboxes.'),
|
|
205
|
+
dataName: Name.describe('Name of the persistent data set (C:\\AgentData) shared by all workspaces.'),
|
|
206
|
+
}),
|
|
207
|
+
network: z.strictObject({ blockPrivateRanges: z.boolean().describe('Block your LAN (10/8, 172.16/12, 192.168/16, SMB) from inside the sandbox.') }),
|
|
208
|
+
provisioning: Provisioning,
|
|
209
|
+
toolchains: Toolchains,
|
|
210
|
+
databases: Databases.describe('Databases running inside the sandbox. Data persists in C:\\AgentData\\databases; each one starts at boot.'),
|
|
211
|
+
attach: Attach,
|
|
212
|
+
secrets: Secrets,
|
|
213
|
+
personalization: toggle('Copy your desktop look (theme, accent, taskbar, wallpaper, ...) into the sandbox.'),
|
|
214
|
+
claudeProfile: ClaudeProfile,
|
|
215
|
+
harnesses: z.record(Name, Harness).describe('Agents that can run in the sandbox.'),
|
|
216
|
+
hooks: z.strictObject({ failFast: z.boolean().describe('Stop when a hook script fails.') }),
|
|
217
|
+
}).refine((c) => c.harnesses[c.defaultHarness] !== undefined, { message: 'defaultHarness must be one of the configured harnesses', path: ['defaultHarness'] });
|
|
218
|
+
/**
|
|
219
|
+
* What a project's .sandbox-config.json may change. A repo can ship this file, so it can NOT touch storage, agent
|
|
220
|
+
* executables, host folders for tools or Claude settings, or anything else outside this list.
|
|
221
|
+
*/
|
|
222
|
+
export const LocalOverrides = z.strictObject({
|
|
223
|
+
$schema: SchemaRef,
|
|
224
|
+
harness: Name.describe('Agent for this project.'),
|
|
225
|
+
guestWorkspace: GuestWorkspace,
|
|
226
|
+
readOnly: z.boolean().describe('Map this project read-only.'),
|
|
227
|
+
mappings: z.array(Mapping).describe('Extra folders (relative to this file).'),
|
|
228
|
+
scripts: Strings.describe('Scripts (.ps1 / .mjs / .cmd, relative to this file) run inside the sandbox before the agent.'),
|
|
229
|
+
sandbox: Sandbox.partial(),
|
|
230
|
+
network: z.strictObject({ blockPrivateRanges: z.boolean() }).partial(),
|
|
231
|
+
provisioning: Provisioning.pick({ copyFromHost: true, fallbackToInstall: true, refresh: true }).extend({ git: Git.partial(), terminal: toggle('Windows Terminal as the sandbox window.').partial() }).partial(),
|
|
232
|
+
// Every toolchain setting, each one optional (a project usually only switches languages on or pins a version).
|
|
233
|
+
toolchains: z.strictObject({
|
|
234
|
+
..._.mapValues(_.omit(Toolchains.shape, 'environment'), (shape) => shape.partial()),
|
|
235
|
+
environment: Toolchains.shape.environment,
|
|
236
|
+
}).partial(),
|
|
237
|
+
databases: z.strictObject(_.mapValues(Databases.shape, (shape) => shape.partial())).partial(),
|
|
238
|
+
attach: Attach.partial(),
|
|
239
|
+
personalization: toggle('Copy your desktop look into the sandbox.').partial(),
|
|
240
|
+
claudeProfile: ClaudeProfile.pick({ enabled: true, include: true, overwrite: true, copyCredentials: true, syncHistory: true, syncClaudeMem: true }).partial(),
|
|
241
|
+
hooks: z.strictObject({ failFast: z.boolean() }).partial(),
|
|
242
|
+
}).partial();
|
|
243
|
+
/** One readable line per problem: "sandbox.memoryMb: Too small: expected number to be >=2048". */
|
|
244
|
+
export const describeIssues = (error) => error.issues.map((issue) => {
|
|
245
|
+
const at = issue.path.join('.');
|
|
246
|
+
if (issue.code === 'unrecognized_keys')
|
|
247
|
+
return issue.keys.map((k) => (at ? at + '.' : '') + k + ' is not allowed here').join('; ');
|
|
248
|
+
return (at || 'value') + ': ' + issue.message;
|
|
249
|
+
});
|
|
250
|
+
/** JSON Schema documents for editors. The user config only lists what it changes, so nothing in it is required. */
|
|
251
|
+
export const jsonSchemas = () => {
|
|
252
|
+
const dropRequired = (node) => {
|
|
253
|
+
if (Array.isArray(node))
|
|
254
|
+
return node.map(dropRequired);
|
|
255
|
+
if (typeof node !== 'object' || node === null)
|
|
256
|
+
return node;
|
|
257
|
+
return Object.fromEntries(Object.entries(node).filter(([k]) => k !== 'required').map(([k, v]) => [k, dropRequired(v)]));
|
|
258
|
+
};
|
|
259
|
+
const toSchema = (schema, title) => ({ title, ...z.toJSONSchema(schema, { io: 'input', unrepresentable: 'any' }) });
|
|
260
|
+
return {
|
|
261
|
+
'config.schema.json': dropRequired(toSchema(Config, 'windows-development-sandbox user config (~/.agent-sandbox/config.json)')),
|
|
262
|
+
'sandbox-config.schema.json': toSchema(LocalOverrides, 'windows-development-sandbox project config (.sandbox-config.json)'),
|
|
263
|
+
};
|
|
264
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { Config as ConfigSchema, GitAccess as GitAccessSchema, Harness as HarnessSchema, LocalOverrides, Mapping as MappingSchema } from './schema.js';
|
|
3
|
+
export type { AttachEndpointT as AttachEndpoint, GuestRequestT as GuestRequest, GuestResponseT as GuestResponse, SandboxStatusT as SandboxStatus, SessionStatusT as SessionStatus } from '../shared/schema.js';
|
|
4
|
+
export type Config = z.output<typeof ConfigSchema>;
|
|
5
|
+
export type Overrides = z.output<typeof LocalOverrides>;
|
|
6
|
+
export type GitAccess = z.output<typeof GitAccessSchema>;
|
|
7
|
+
export type Harness = z.output<typeof HarnessSchema>;
|
|
8
|
+
export type Mapping = z.output<typeof MappingSchema>;
|
|
9
|
+
export type Toolchains = Config['toolchains'];
|
|
10
|
+
export type ClaudeProfileConfig = Config['claudeProfile'];
|
|
11
|
+
export interface ResolvedMapping {
|
|
12
|
+
host: string;
|
|
13
|
+
guest: string;
|
|
14
|
+
readOnly: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface LocalConfigFile {
|
|
17
|
+
path: string;
|
|
18
|
+
hash: string;
|
|
19
|
+
data: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface LoadedConfig {
|
|
22
|
+
config: Config;
|
|
23
|
+
configPath: string | null;
|
|
24
|
+
base: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RunRequest {
|
|
27
|
+
packageRoot: string;
|
|
28
|
+
loaded: LoadedConfig;
|
|
29
|
+
cwd: string;
|
|
30
|
+
workspace?: string;
|
|
31
|
+
harness?: string;
|
|
32
|
+
noAgent: boolean;
|
|
33
|
+
noLocalConfig: boolean;
|
|
34
|
+
trustConfig: boolean;
|
|
35
|
+
scripts: string[];
|
|
36
|
+
headless?: boolean;
|
|
37
|
+
/** --database: start these whatever the config and detection say. */
|
|
38
|
+
databases?: string[];
|
|
39
|
+
nodeVersion?: string;
|
|
40
|
+
pythonVersion?: string;
|
|
41
|
+
ask?: (question: string) => Promise<boolean>;
|
|
42
|
+
}
|
|
43
|
+
export interface ResolvedRun {
|
|
44
|
+
config: Config;
|
|
45
|
+
storageRoot: string;
|
|
46
|
+
dataPath: string;
|
|
47
|
+
workspaceHost: string;
|
|
48
|
+
harnessName: string;
|
|
49
|
+
scripts: string[];
|
|
50
|
+
localConfigPath: string | null;
|
|
51
|
+
notes: string[];
|
|
52
|
+
versions: ToolVersions;
|
|
53
|
+
}
|
|
54
|
+
/** A requested version plus where the request came from (shown to the user). */
|
|
55
|
+
export interface VersionSpec {
|
|
56
|
+
spec: string;
|
|
57
|
+
source: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ToolVersions {
|
|
60
|
+
node: VersionSpec;
|
|
61
|
+
nodeExtra: string[];
|
|
62
|
+
python: VersionSpec;
|
|
63
|
+
}
|
|
64
|
+
export interface HostProbe {
|
|
65
|
+
nodeDir: string | null;
|
|
66
|
+
harnessExe: {
|
|
67
|
+
dir: string;
|
|
68
|
+
file: string;
|
|
69
|
+
} | null;
|
|
70
|
+
gitDir: string | null;
|
|
71
|
+
nvmDir: string | null;
|
|
72
|
+
hostNodeVersion: string;
|
|
73
|
+
/** This PC's Node is one of nvm's versions, so it comes in with nvm and nodeDir stays unmapped. */
|
|
74
|
+
nvmNode?: boolean;
|
|
75
|
+
/** This PC has Volta / pyenv-win (VOLTA_HOME / PYENV set). */
|
|
76
|
+
volta?: boolean;
|
|
77
|
+
pyenv?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/** A database the sandbox runs, and why ("compose.yaml: a compose service runs Postgres"). */
|
|
80
|
+
export interface DatabasePlan {
|
|
81
|
+
database: 'postgres' | 'mysql' | 'sqlserver' | 'mongodb' | 'redis' | 'dynamodb';
|
|
82
|
+
reasons: string[];
|
|
83
|
+
version: string;
|
|
84
|
+
port: number;
|
|
85
|
+
adminPort?: number;
|
|
86
|
+
}
|
|
87
|
+
/** databases: the plan to use instead of scanning the workspace (tests). */
|
|
88
|
+
/** databases / pcLanguages: use these instead of scanning (tests). */
|
|
89
|
+
export interface GenerateOptions {
|
|
90
|
+
packageRoot: string;
|
|
91
|
+
run: ResolvedRun;
|
|
92
|
+
harnessArgs: string[];
|
|
93
|
+
probe: HostProbe;
|
|
94
|
+
freeMemoryBytes?: number;
|
|
95
|
+
databases?: DatabasePlan[];
|
|
96
|
+
pcLanguages?: import('./detect-toolchains.js').AutoToolchain[];
|
|
97
|
+
}
|
|
98
|
+
export interface Generated {
|
|
99
|
+
wsbPath: string;
|
|
100
|
+
launchPath: string;
|
|
101
|
+
launchId: string;
|
|
102
|
+
sessionPath: string;
|
|
103
|
+
memoryMb: number;
|
|
104
|
+
mappings: ResolvedMapping[];
|
|
105
|
+
profile: ProfileResult;
|
|
106
|
+
databases: DatabasePlan[];
|
|
107
|
+
toolchains: Record<import('./detect-toolchains.js').AutoToolchain, import('./detect-toolchains.js').ToolchainDecision>;
|
|
108
|
+
}
|
|
109
|
+
/** secretsRemoved: what secrets.strip kept on this PC, e.g. "settings.json env.AWS_SECRET_ACCESS_KEY". */
|
|
110
|
+
export interface ProfileResult {
|
|
111
|
+
hostDir: string | null;
|
|
112
|
+
staged: string[];
|
|
113
|
+
skipped: string[];
|
|
114
|
+
credentials: boolean;
|
|
115
|
+
secretsRemoved: string[];
|
|
116
|
+
}
|
|
117
|
+
/** Written by the host to C:\AgentLaunch\session.json (read-only for the guest): everything the guest needs to know. */
|
|
118
|
+
export interface GuestSession {
|
|
119
|
+
launchId: string;
|
|
120
|
+
project: string;
|
|
121
|
+
workspace: string;
|
|
122
|
+
workspaceHost: string;
|
|
123
|
+
harnessName: string;
|
|
124
|
+
harness: Harness | null;
|
|
125
|
+
harnessArguments: string[];
|
|
126
|
+
persistAgentState: boolean;
|
|
127
|
+
networking: boolean;
|
|
128
|
+
headless: boolean;
|
|
129
|
+
network: Config['network'];
|
|
130
|
+
provisioning: Config['provisioning'];
|
|
131
|
+
toolchains: Toolchains;
|
|
132
|
+
databases: DatabasePlan[];
|
|
133
|
+
versions: ToolVersions;
|
|
134
|
+
/** Every database `sbx-db start` can run later (older launch folders lack it). */
|
|
135
|
+
databaseCatalog?: DatabasePlan[];
|
|
136
|
+
attach: Config['attach'];
|
|
137
|
+
hooks: Config['hooks'];
|
|
138
|
+
/** nodeVersion: this PC's Node (e.g. 22.11.0), found under nvm\v<version> when nvm is mapped, else under node. */
|
|
139
|
+
/** volta / pyenv: this PC uses them (their "auto" settings turn them on in the sandbox too). */
|
|
140
|
+
hostTools: {
|
|
141
|
+
node: boolean;
|
|
142
|
+
nodeVersion: string | null;
|
|
143
|
+
harnessExecutable: string | null;
|
|
144
|
+
git: boolean;
|
|
145
|
+
nvm: boolean;
|
|
146
|
+
volta?: boolean;
|
|
147
|
+
pyenv?: boolean;
|
|
148
|
+
};
|
|
149
|
+
claudeProfile: {
|
|
150
|
+
overwrite: boolean;
|
|
151
|
+
items: string[];
|
|
152
|
+
credentials: boolean;
|
|
153
|
+
hostConfigDir: string | null;
|
|
154
|
+
syncClaudeMem: boolean;
|
|
155
|
+
};
|
|
156
|
+
personalization: boolean;
|
|
157
|
+
/** Drives other than C: that bootstrap.ps1 makes with subst before anything uses them: letter D-Z onto C:\Mirror\<letter>. */
|
|
158
|
+
substDrives?: {
|
|
159
|
+
letter: string;
|
|
160
|
+
target: string;
|
|
161
|
+
}[];
|
|
162
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare const isWin: boolean;
|
|
2
|
+
/** An expected problem the user can act on: what went wrong, and (optionally) how to fix it. */
|
|
3
|
+
export declare class UserError extends Error {
|
|
4
|
+
readonly fix?: string | undefined;
|
|
5
|
+
constructor(message: string, fix?: string | undefined);
|
|
6
|
+
}
|
|
7
|
+
/** Throws a UserError. Typed explicitly so TypeScript narrows after calls (arrow functions need it to act as never). */
|
|
8
|
+
export declare const fail: (message: string, fix?: string) => never;
|
|
9
|
+
/**
|
|
10
|
+
* Parses JSON with comments and trailing commas (JSONC, like VS Code's settings.json). Errors name the file, line
|
|
11
|
+
* and column, and say what to fix.
|
|
12
|
+
*/
|
|
13
|
+
export declare const parseJsonc: <T>(text: string, source: string) => T;
|
|
14
|
+
export declare const readJsonc: <T>(file: string) => T;
|
|
15
|
+
export declare const errMsg: (e: unknown) => string;
|
|
16
|
+
export declare const ensureDir: (p: string) => void;
|
|
17
|
+
export declare const dirExists: (p: string) => boolean;
|
|
18
|
+
export declare const fileExists: (p: string) => boolean;
|
|
19
|
+
export declare const readJson: <T>(p: string) => T;
|
|
20
|
+
export declare const tryReadJson: <T>(p: string) => T | null;
|
|
21
|
+
export declare const writeJson: (p: string, value: unknown) => void;
|
|
22
|
+
export declare const realPath: (p: string) => string;
|
|
23
|
+
export declare const xmlEscape: (v: string) => string;
|
|
24
|
+
export declare const homeDir: () => string;
|
|
25
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
26
|
+
/** Expands %VAR% and resolves relative paths against `base`. */
|
|
27
|
+
export declare const expandPath: (input: string, base: string) => string;
|
|
28
|
+
export declare const isRootPath: (p: string) => boolean;
|
|
29
|
+
export declare const isUserProfile: (p: string) => boolean;
|
|
30
|
+
export declare const isInsideOrEqual: (parent: string, child: string) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Text that came from the sandbox, made safe to print: control characters and escape sequences are removed except
|
|
33
|
+
* plain colours (SGR), so nothing written by the sandbox can drive your terminal (titles, clipboard, cursor tricks).
|
|
34
|
+
*/
|
|
35
|
+
export declare const safeText: (text: string) => string;
|
|
36
|
+
export declare const findOnPath: (names: string[]) => string | null;
|
|
37
|
+
/** True if `p` itself is a symlink or junction (lstat; never follows it). */
|
|
38
|
+
export declare const isLink: (p: string) => boolean;
|
|
39
|
+
/** Removes a symlink or junction itself (never its target). Junctions need rmdir on Windows. */
|
|
40
|
+
export declare const removeLink: (p: string) => void;
|
|
41
|
+
/**
|
|
42
|
+
* The sandbox can write anywhere in its data folder, so it could swap a folder for a junction that points at this
|
|
43
|
+
* PC's own disk. Before the host reads, writes or deletes anything under `root`, every existing path component from
|
|
44
|
+
* `root` down to `target` must be a plain folder/file. Throws otherwise.
|
|
45
|
+
*/
|
|
46
|
+
export declare const assertNoLinks: (root: string, target: string) => void;
|
|
47
|
+
/** Runs a PowerShell script and returns its exit code (and stdout when `capture`). */
|
|
48
|
+
export declare const runPowerShell: (script: string, capture?: boolean) => {
|
|
49
|
+
status: number;
|
|
50
|
+
stdout: string;
|
|
51
|
+
};
|
|
52
|
+
/** Async variant (does not block the event loop), resolving with stdout. */
|
|
53
|
+
export declare const runPowerShellAsync: (script: string) => Promise<string>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
5
|
+
import { SYSTEM } from '../shared/system.js';
|
|
6
|
+
import { parse as parseJsoncText, printParseErrorCode } from 'jsonc-parser';
|
|
7
|
+
export const isWin = process.platform === 'win32';
|
|
8
|
+
/** An expected problem the user can act on: what went wrong, and (optionally) how to fix it. */
|
|
9
|
+
export class UserError extends Error {
|
|
10
|
+
fix;
|
|
11
|
+
constructor(message, fix) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.fix = fix;
|
|
14
|
+
this.name = 'UserError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Throws a UserError. Typed explicitly so TypeScript narrows after calls (arrow functions need it to act as never). */
|
|
18
|
+
export const fail = (message, fix) => { throw new UserError(message, fix); };
|
|
19
|
+
/**
|
|
20
|
+
* Parses JSON with comments and trailing commas (JSONC, like VS Code's settings.json). Errors name the file, line
|
|
21
|
+
* and column, and say what to fix.
|
|
22
|
+
*/
|
|
23
|
+
export const parseJsonc = (text, source) => {
|
|
24
|
+
const errors = [];
|
|
25
|
+
const value = parseJsoncText(text.replace(/^/, ''), errors, { allowTrailingComma: true, disallowComments: false });
|
|
26
|
+
if (errors.length) {
|
|
27
|
+
const { offset, error } = errors[0];
|
|
28
|
+
const before = text.slice(0, offset).split(/\r?\n/);
|
|
29
|
+
fail(source + ' is not valid JSON (line ' + before.length + ', column ' + (before[before.length - 1].length + 1) + ': ' + printParseErrorCode(error) + ').', 'Fix that spot in the file. Comments (// and /* */) and trailing commas are fine.');
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
export const readJsonc = (file) => parseJsonc(fs.readFileSync(file, 'utf8'), file);
|
|
34
|
+
export const errMsg = (e) => e instanceof Error ? e.message : String(e);
|
|
35
|
+
export const ensureDir = (p) => { fs.mkdirSync(p, { recursive: true }); };
|
|
36
|
+
export const dirExists = (p) => { try {
|
|
37
|
+
return fs.statSync(p).isDirectory();
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
} };
|
|
42
|
+
export const fileExists = (p) => { try {
|
|
43
|
+
return fs.statSync(p).isFile();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
} };
|
|
48
|
+
export const readJson = (p) => JSON.parse(fs.readFileSync(p, 'utf8').replace(/^\uFEFF/, ''));
|
|
49
|
+
export const tryReadJson = (p) => { try {
|
|
50
|
+
return readJson(p);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
} };
|
|
55
|
+
export const writeJson = (p, value) => { ensureDir(path.dirname(p)); fs.writeFileSync(p, JSON.stringify(value, null, 2) + '\n', 'utf8'); };
|
|
56
|
+
export const realPath = (p) => { try {
|
|
57
|
+
return fs.realpathSync(p);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return p;
|
|
61
|
+
} };
|
|
62
|
+
export const xmlEscape = (v) => v.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
63
|
+
export const homeDir = () => process.env.USERPROFILE ?? os.homedir();
|
|
64
|
+
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
65
|
+
/** Expands %VAR% and resolves relative paths against `base`. */
|
|
66
|
+
export const expandPath = (input, base) => {
|
|
67
|
+
const expanded = input.replace(/%([^%]+)%/g, (_m, name) => process.env[name] ?? '%' + name + '%').replace(/^~(?=$|[\\/])/, homeDir());
|
|
68
|
+
return path.resolve(path.isAbsolute(expanded) ? expanded : path.join(base, expanded));
|
|
69
|
+
};
|
|
70
|
+
export const isRootPath = (p) => { const n = path.resolve(p); return n.toLowerCase() === path.parse(n).root.toLowerCase(); };
|
|
71
|
+
export const isUserProfile = (p) => { const profile = process.env.USERPROFILE ?? process.env.HOME ?? ''; return profile !== '' && path.resolve(p).toLowerCase() === path.resolve(profile).toLowerCase(); };
|
|
72
|
+
export const isInsideOrEqual = (parent, child) => {
|
|
73
|
+
const rel = path.relative(path.resolve(parent).toLowerCase(), path.resolve(child).toLowerCase());
|
|
74
|
+
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Text that came from the sandbox, made safe to print: control characters and escape sequences are removed except
|
|
78
|
+
* plain colours (SGR), so nothing written by the sandbox can drive your terminal (titles, clipboard, cursor tricks).
|
|
79
|
+
*/
|
|
80
|
+
export const safeText = (text) => text.replace(/\x1b\[[0-9;]*m|\x1b(\[[0-9;?]*[ -\/]*[@-~]|\][^\x07\x1b]*(\x07|\x1b\\)|[@-Z\\-_])|[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, (m) => (/^\x1b\[[0-9;]*m$/.test(m) ? m : ''));
|
|
81
|
+
export const findOnPath = (names) => {
|
|
82
|
+
const dirs = (process.env.PATH ?? process.env.Path ?? '').split(path.delimiter).filter((d) => d !== '');
|
|
83
|
+
for (const name of names)
|
|
84
|
+
for (const dir of dirs) {
|
|
85
|
+
const candidate = path.join(dir, name);
|
|
86
|
+
if (fileExists(candidate))
|
|
87
|
+
return candidate;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
91
|
+
/** True if `p` itself is a symlink or junction (lstat; never follows it). */
|
|
92
|
+
export const isLink = (p) => { try {
|
|
93
|
+
return fs.lstatSync(p).isSymbolicLink();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
} };
|
|
98
|
+
/** Removes a symlink or junction itself (never its target). Junctions need rmdir on Windows. */
|
|
99
|
+
export const removeLink = (p) => { try {
|
|
100
|
+
fs.unlinkSync(p);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
fs.rmdirSync(p);
|
|
104
|
+
} };
|
|
105
|
+
/**
|
|
106
|
+
* The sandbox can write anywhere in its data folder, so it could swap a folder for a junction that points at this
|
|
107
|
+
* PC's own disk. Before the host reads, writes or deletes anything under `root`, every existing path component from
|
|
108
|
+
* `root` down to `target` must be a plain folder/file. Throws otherwise.
|
|
109
|
+
*/
|
|
110
|
+
export const assertNoLinks = (root, target) => {
|
|
111
|
+
const rel = path.relative(path.resolve(root), path.resolve(target));
|
|
112
|
+
if (rel.startsWith('..') || path.isAbsolute(rel))
|
|
113
|
+
fail('Refusing to touch ' + target + ': it is outside ' + root);
|
|
114
|
+
let current = path.resolve(root);
|
|
115
|
+
for (const part of ['', ...rel.split(path.sep).filter(Boolean)]) {
|
|
116
|
+
current = part ? path.join(current, part) : current;
|
|
117
|
+
if (isLink(current))
|
|
118
|
+
fail('Refusing to touch ' + target + ': ' + current + ' is a link (possible escape attempt from the sandbox).');
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* PowerShell arguments for a script passed encoded (no quoting issues, no progress-bar noise on stderr). Output is
|
|
123
|
+
* UTF-8: Windows PowerShell 5.1 otherwise writes redirected stdout in the OEM code page, mangling non-ASCII (regional
|
|
124
|
+
* date formats, wallpaper paths). UTF8Encoding($false): no byte-order mark in front of the output.
|
|
125
|
+
*/
|
|
126
|
+
const powerShellArgs = (script) => {
|
|
127
|
+
const prelude = "[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false\n$ProgressPreference = 'SilentlyContinue'\n";
|
|
128
|
+
const encoded = Buffer.from(prelude + script, 'utf16le').toString('base64');
|
|
129
|
+
return ['-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', encoded];
|
|
130
|
+
};
|
|
131
|
+
/** Runs a PowerShell script and returns its exit code (and stdout when `capture`). */
|
|
132
|
+
export const runPowerShell = (script, capture = false) => {
|
|
133
|
+
const result = spawnSync(SYSTEM.powershell(), powerShellArgs(script), { stdio: capture ? ['ignore', 'pipe', 'inherit'] : 'inherit', encoding: 'utf8', windowsHide: true });
|
|
134
|
+
if (result.error)
|
|
135
|
+
throw result.error;
|
|
136
|
+
return { status: result.status ?? 1, stdout: result.stdout ?? '' };
|
|
137
|
+
};
|
|
138
|
+
/** Async variant (does not block the event loop), resolving with stdout. */
|
|
139
|
+
export const runPowerShellAsync = (script) => new Promise((resolve, reject) => {
|
|
140
|
+
const child = spawn(SYSTEM.powershell(), powerShellArgs(script), { stdio: ['ignore', 'pipe', 'inherit'], windowsHide: true });
|
|
141
|
+
let out = '';
|
|
142
|
+
child.stdout.on('data', (d) => { out += d.toString('utf8'); });
|
|
143
|
+
child.on('error', reject);
|
|
144
|
+
child.on('close', () => resolve(out));
|
|
145
|
+
});
|