返回 CodeWhale
ENVIRONMENTS.md
根目录 / docs / ENVIRONMENTS.md
1 # Environment-specific caveats
2
3 > 阅读简体中文版:[zh_hans/ENVIRONMENTS.md](zh_hans/ENVIRONMENTS.md)。
4
5 Standard build/test/run commands live in `AGENTS.md` and `CONTRIBUTING.md`.
6 This file records only the non-obvious quirks of particular environments, so
7 they do not cost context on machines that will never hit them.
8
9 ## Cursor Cloud VMs
10
11 - **System build dep:** the build needs `libdbus-1-dev` (pulled in by
12 `crates/secrets` for the OS keyring). It is installed by the startup update
13 script; if a `cargo build` fails with a `dbus`/`pkg-config` error, that dep is
14 missing.
15 - **`rustup default` must be set:** some tests and runtime paths spawn shells in
16 temp dirs *outside* this checkout (e.g. `run_verifiers_background_*`, sub-agent
17 worktrees). Those spawned shells only see the repo's `rust-toolchain.toml`
18 override while inside `/workspace`, so without a global default they fail with
19 "rustup could not choose a version of rustc to run". The update script runs
20 `rustup default 1.100.0` to fix this.
21 - **Known env-specific test failures at `/workspace` (not code bugs):** because
22 the checkout sits directly under `/`, two `codewhale-tui` subagent tests fail
23 here — `git_repo_root_reports_attempted_paths_when_no_repo_found` (cannot
24 create a temp dir in the unwritable parent `/`) and
25 `create_isolated_worktree_reports_friendly_error_when_no_repo_found` (walking
26 up to `/` discovers `/workspace` itself as a repo). Both pass when the repo is
27 checked out under a normal, writable parent.
28
29 ## Running the agent without provider API keys
30
31 Point Codewhale at any local OpenAI-compatible endpoint via the keyless
32 `vllm`/`ollama`/`sglang` providers:
33
34 ```sh
35 CODEWHALE_PROVIDER=vllm VLLM_BASE_URL=http://127.0.0.1:8000/v1 VLLM_MODEL=<id> \
36 codewhale exec --auto "..."
37 ```
38
39 `codewhale exec` (add `--auto` for tool use) is the non-interactive path to
40 exercise the full agent loop. `--auto` enables Full Access by default: no
41 Codewhale shell sandbox, with trust mode on. Add `--sandbox workspace-write`
42 to keep the shell sandbox and file-tool workspace restrictions, with trust
43 mode off.
44
45 ## Keeping the host awake during a turn
46
47 While an interactive TUI turn is in flight, Codewhale holds the platform's
48 idle-sleep assertion, so an unattended machine does not idle into sleep
49 mid-turn and lose the work:
50
51 - macOS: `caffeinate -i`
52 - Linux: `systemd-inhibit --what=idle --why="Codewhale turn in flight" --mode=block cat`,
53 where `cat` reads a pipe Codewhale holds for the turn
54
55 The assertion is released the moment the turn ends — on Linux by closing that
56 pipe, so `cat` exits and `systemd-inhibit` follows without leaving a process
57 behind — and it covers *idle* sleep only: an explicit `sleep` / `pmset sleepnow`, a closed lid, or a low battery
58 still suspends the machine. Headless hosts — `exec`, app-server, CI — never
59 hold it, so a shared runner's power policy is untouched. Windows is not
60 implemented: `SetThreadExecutionState` is thread-affine and needs a holder that
61 pins the thread, so the gap is deliberate rather than silent.
62
63 If a turn is suspended anyway, the engine notices on wake — wall-clock elapsed
64 diverging from monotonic elapsed by more than the suspend threshold — reports
65 `System sleep detected; connection lost — retrying request`, and re-issues the
66 request instead of failing the turn (#2990).
67
68 ## Linux sandboxed terminals
69
70 Sandboxed PTYs require bubblewrap and util-linux `setsid` at `/usr/bin/setsid`
71 or `/bin/setsid`. Codewhale assigns the controlling terminal inside bubblewrap's
72 PID namespace so Ctrl-C reaches the foreground program without killing its
73 wrapper. A program that handles SIGINT can continue accepting input. Both
74 `exec_shell` PTY jobs and persistent terminal sessions use this path. Missing
75 `setsid` fails the PTY launch; it does not remove the sandbox. Non-PTY commands
76 do not require this helper. Namespace isolation, read-only mounts and
77 `--die-with-parent` cleanup remain in force.
78
79 ## Windows support and release qualification
80
81 Windows compatibility depends on the runtime architecture and terminal. The
82 native x64 CLI/TUI compatibility target is Windows 10 1607 (build 14393) or
83 later in the legacy Windows console. A release's actual executable and installer
84 must still pass startup and installation on that target; an import-table pass
85 alone does not prove it. Required Visual C++ runtime DLLs must also be present.
86
87 | Surface | Compatibility target or platform requirement | Qualification boundary |
88 | --- | --- | --- |
89 | Native x64 CLI/TUI | Windows 10 x64 1607, build 14393 | Final release bytes need an actual oldest-OS startup receipt |
90 | ConPTY API | Windows 10 1809, build 17763; Windows Server 2019 | This is Microsoft's API minimum; Codewhale's terminal-session routes remain Unix-only and return 501 on Windows |
91 | Current Windows Terminal | Windows 10 2004, build 19041, or later | This terminal has a newer prerequisite than the ConPTY API; use the legacy console for the x64 compatibility target |
92 | Native ARM64 CLI/TUI | Windows 11 ARM64 is the target | Exports observed on build 26300 (debug candidate) and build 26200 (release build, hosted probe); no minimum Windows 11 build or Windows 10 ARM64 support is inferred from those runs |
93 | NSIS installer | x86 setup/plugins under WOW64, installing x64 runtime bytes | Native ARM64 installation uses its archive/npm assets; generated Uninstall.exe and actual install behavior need separate receipts |
94
95 [Microsoft's ConPTY requirements](https://learn.microsoft.com/en-us/windows/console/createpseudoconsole)
96 and [current Terminal requirements](https://github.com/microsoft/terminal/blob/main/README.md)
97 are separate. Windows 11 supports x64 emulation on ARM64; an emulated x64 run
98 does not qualify native x64 execution or Windows 10 1607.
99
100 The release import guard uses separate per-machine profiles in
101 [`windows-import-floor.json`](../scripts/release/windows-import-floor.json).
102 Unknown import pairs, unlisted ordinals and delay-loaded dependencies stop the
103 gate. Its PASS covers the reviewed static import contract; it does not certify
104 all runtime features, the installed dependency closure or a minimum OS build.
105 The Native plugin host still requires its runtime capability APIs and
106 isolation probes; where DeriveCapabilitySidsFromName is absent it reports
107 Unsupported rather than weakening its sandbox. This feature limit is distinct
108 from CLI startup compatibility.
109
110 When a candidate's windows-arm64 import check stops on pairs the arm64
111 profile has not seen, requalify it with
112 [`windows-arm64-export-probe.yml`](../.github/workflows/windows-arm64-export-probe.yml).
113 Dispatch it with the candidate run's `run_id` and `source_sha`. On a
114 GitHub-hosted Windows 11 ARM64 runner it loads each imported DLL from System32
115 in a native ARM64 process, resolves every pair with GetProcAddress, and
116 uploads a probe JSON with module paths and hashes. Add only probe-resolved
117 pairs to the profile, record the run, runner OS build, binary SHA256 and counts
118 in its qualification, and rerun the candidate. The probe resolves exports
119 statically and does not launch the executables.
120
121 ### Recorded 0.10.2 candidate evidence
122
123 The 2026-10-13 qualification snapshot is source
124 [`cf7199b52e`](https://github.com/codewhale-hq/Codewhale/commit/cf7199b52ecb9147e4670ae7874924ffc30a6a67).
125 A default-feature debug ARM64 build on Windows 11 build 26300 produced executable
126 SHA256 `ca51f91562a0569ee43855715856e1cfee74e8a834bd6206183a3175373fdb2d`.
127 All 453 imported symbols resolved in a native ARM64 process using system-only
128 DLL lookup. The ordinary-user candidate checks passed 89 classifier tests and
129 one owner-crash recovery test, plus scoped editor wheel, Pinyin and undo checks.
130 This is neither a dist-profile release artifact nor installer acceptance, and
131 it establishes no oldest supported Windows 11 build.
132
133 The x64 profile comes from @LmeSzinc's
134 [#6953 export investigation](https://github.com/codewhale-hq/Codewhale/issues/6953)
135 on build 14393.447: all 411 v0.10.0 imports and 453 of 454 v0.10.1 imports resolved.
136 The missing DeriveCapabilitySidsFromName pair is excluded; the conservative
137 allowed union has 456 pairs. The x86 NSIS profile has 189 named Microsoft API
138 contracts predating 1607 and one explicitly identified ordinal: COMCTL32 #17 is
139 InitCommonControls in the x86 Windows SDK 10.0.26100.0 import library and stock
140 SysWOW64 DLL. Its [documented minimum is Vista](https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-initcommoncontrols).
141 The manifest retains official source URLs, image hashes, counts and the ordinal
142 identity; these qualify static contracts without claiming a 1607 installer run.
143
144 On 2026-10-16, probe run 38890634267 (Windows 11 ARM64 build 26200.9457)
145 resolved all 445 imports of the release-build windows-arm64 executables from
146 candidate run 38867608774, and the 7 pairs the 2026-10-13 profile had not seen
147 were added. Release candidate 38899652987 on the frozen 0.10.2 source
148 `14683c9983` then passed the import check on every Windows target: 445 imports
149 on ARM64, 453 on x64 including the installer payload, and 163 for the x86
150 setup.
151
152 ### Recorded 0.10.3 candidate evidence
153
154 Release candidate run 42381818665 on source `549ff01ebb` stopped the import
155 check on both 64-bit targets: 12 x64 pairs and 10 ARM64 pairs, all from DLLs
156 the profiles already listed. Probe run 42389141087 (Windows 11 ARM64 build
157 26200.9725) resolved all 444 imports of that candidate's ARM64 executables, and
158 the 10 new pairs were added. No x64 export probe exists, so the 12 x64 pairs are
159 recorded as documented Microsoft API contracts below the 14393 floor, labelled
160 separately from the #6953 reporter-observed exports; the x64 profile now allows
161 468 pairs. The candidate still has to pass the import check against its final
162 executable bytes, and neither addition is a 14393 or installer run.
163
164 Release candidate run 43186389246 on source `f5a3dda975` then stopped the same
165 check on three more pairs, `GetSidIdentifierAuthority`, `GetSidSubAuthority` and
166 `GetSidSubAuthorityCount` from advapi32.dll, on both 64-bit targets. Probe run
167 43197611105 (Windows 11 ARM64 build 26200.9725) resolved all 447 imports of
168 that candidate's ARM64 executables, and the 3 pairs were added. For x64 the 3
169 pairs are documented Microsoft API contracts (Windows XP minimum on each
170 function's reference page), labelled apart from the #6953 reporter-observed
171 exports; the x64 profile now allows 471 pairs and the ARM64 profile 473. The
172 same limit applies: the candidate still has to pass the import check against
173 its final executable bytes, and neither addition is a 14393 or installer run.
174
175 Release candidate run 43320217667, built after the stable toolchain moved to
176 Rust 1.100.0, stopped the check on two more kernel32.dll pairs,
177 `GetLogicalDrives` and `QueryDosDeviceW`, which the Rust 1.100.0 standard
178 library's Windows file system code imports. Probe run 43330905781 (Windows 11
179 ARM64 build 26200.9725) resolved all 449 imports of that candidate's ARM64
180 executables. For x64 the 2 pairs are documented Microsoft API contracts
181 (Windows XP minimum on each function's reference page); the x64 profile now
182 allows 473 pairs and the ARM64 profile 475, with the same limits as above.
183
184 Release candidate run 44379943827 on source `7616799f09` stopped the check on
185 `api-ms-win-crt-math-l1-1-0.dll!cosf` on both 64-bit targets (from `f32::cos()`
186 in 5.4.0 live motion) and `kernel32.dll!IsProcessorFeaturePresent` on x64 (from
187 the `windows-2025-vs2026` runner's MSVC 14.52 CRT/toolchain update, already
188 qualified on ARM64). Probe run 44417404125 (Windows 11 ARM64 build 26200.9974)
189 resolved all 449 imports of that candidate's ARM64 executables, and `cosf` was
190 added. For x64 the 2 pairs are documented Microsoft API contracts (10.0.10240
191 UCRT API-set minimum for `cosf` and Windows 2000 Professional minimum for
192 `IsProcessorFeaturePresent`); the x64 profile now allows 475 pairs and the
193 ARM64 profile 476, with the same limits as above.
194
195 At this snapshot, startup/installation of the final release bytes on an actual
196 1607 machine and the candidate's generated uninstaller were still unqualified.
197 The final frozen source, release import dumps, archive/native/npm installation,
198 packaged/native-app owner recovery and oldest-OS receipts belong in the release
199 acceptance packet. See [the release checklist](RELEASE_CHECKLIST.md).
200
201 ## Windows PowerShell execution policy
202
203 The shell tool runs PowerShell with `-ExecutionPolicy Bypass`. That sets only
204 the policy of the child process it launches: nothing is persisted, no
205 administrator rights are needed, and your own PowerShell windows keep their
206 policy. Without it, a machine whose local policy is `Restricted` (the Windows
207 client default) or `AllSigned` refuses the temporary `.ps1` script Codewhale
208 writes for multiline commands (#6745).
209
210 A policy set by Group Policy (the `MachinePolicy` or `UserPolicy` rows of
211 `Get-ExecutionPolicy -List`) outranks the process scope. On such a machine,
212 multiline commands are still refused and PowerShell's refusal is returned as
213 the command's error; Codewhale does not work around an administrator-enforced
214 policy. Single-line commands run through `-Command`, which the execution
215 policy does not govern. Scripts that a command itself calls run under the same
216 process scope; the shell tool's approval and sandbox settings, not the
217 execution policy, decide what may run.
218
219 To let the machine or user policy apply instead, set
220 `CODEWHALE_POWERSHELL_EXECUTION_POLICY=inherit` before starting Codewhale: the
221 shell tool then omits `-ExecutionPolicy` entirely, so a `Restricted` or
222 `AllSigned` policy refuses multiline commands that need the temporary `.ps1`
223 script. Unset, `bypass`, or any other value keeps the default `Bypass`.
224
225 ## Consolidated runtime commands
226
227 The current `codewhale` binary runs the TUI in-process. Release installers copy
228 the same bytes to the optional `codew` short command; no sibling
229 `codewhale-tui` executable is required. `DEEPSEEK_TUI_BIN` remains a legacy
230 replay/migration setting, not a current install requirement.
231
232 ## Environment-aware Fleet placement (preview)
233
234 A Fleet task can declare where it is able to run. The manager and scheduler
235 use the same placement decision when choosing a worker. Requirements
236 are hard constraints; `prefer` ranks only eligible environments. A busy or
237 ineligible worker does not prevent later queued tasks from using another eligible
238 worker. `max_workers` limits concurrency across the whole roster, rather than
239 restricting selection to the first entries.
240
241 The runtime accepts `workspace.placement` on a task and `environment` on a
242 configured worker. The same task contract flows into the existing subagent
243 launch manifest, and the selected environment becomes recorded task context.
244 This uses the existing Engine, Fleet ledger, permission checks and executor.
245 An explicit environment kind describes the operator's environment independently
246 of its transport: an Engine inside a cloud VM can run a `local` subprocess in
247 an environment declared `cloud`. Explicit environment IDs cannot name different hosts
248 within one document. Use explicit IDs when a task must stay on a specific host.
249
250 | Task field | Meaning |
251 | --- | --- |
252 | `environments` | Allowed environment IDs; empty permits any configured candidate |
253 | `kinds` | Allowed `local`, `remote` or `cloud` kinds |
254 | `capabilities` | Every named capability must be declared by the environment |
255 | `data` | Every named data handle must already be declared available there |
256 | `resources.cpu_cores`, `memory_mib`, `gpus` | Minimum declared capacity; missing capacity fails the requirement |
257 | `persistent` | Require persistent or temporary storage; unknown fails either explicit requirement |
258 | `max_cost_per_hour_microusd` | Upper bound on a declared hourly compute rate; unknown fails the requirement |
259 | `prefer` | Ordered preferred environment IDs, after all requirements pass |
260
261 These declarations select among configured execution targets. They grant no
262 tools, network access, secrets, filesystem access, cloud allocation or spend.
263 They are operator declarations, not live hardware measurements, resource
264 reservations, OS quotas or billing quotes. Data handles do not copy files or
265 credentials. A remote working directory must already contain the intended data.
266 Hourly rate matching does not replace task budgets or the platform's spend gate.
267
268 For CLI invocation, use `codewhale fleet run tasks.json --require-placement`
269 (and add `--check` to validate without creating a run). Placement is always
270 enforced by supporting Engines; the flag makes older binaries refuse the
271 invocation instead of silently ignoring new fields. API clients must check
272 `GET /v1/targets` for `placement.version == 1` before relying on these semantics.
273 Do not send placement-constrained specs to an older Engine without that gate.
274
275 Specs without placement constraints retain their existing worker order among
276 supported available hosts. If no configured environment can satisfy a new run,
277 creation fails before recording the run or launching a worker. `fleet run --check`
278 also avoids creating the ledger.
279 The selected worker is rechecked when its launch manifest is prepared. Busy
280 eligible workers leave work queued. Placement never silently relaxes a hard
281 requirement or provisions a different machine.
282
283 ### Preview and receipts
284
285 `POST /v1/fleet/placement` accepts the same JSON document as `fleet run` and
286 returns `execution: "preview"`, `grants_execution: false`, and one decision per
287 task. Preview requests are limited to 256 KiB and 64 tasks. Each decision
288 contains the selected worker/environment, the selection reason and typed
289 refusals for every rejected candidate. It has no live load,
290 connectivity or permission probe and creates nothing. An omitted worker list
291 previews this computer with unknown resources.
292
293 Each initial lease publishes a checksummed `environment_placement` JSON receipt
294 through the existing Fleet artifact stream. It includes the run, attempt,
295 candidates, requirements represented by the persisted task spec, and the
296 selected worker. Restart attempts retain that environment and recheck the
297 selected worker before dispatch; recovery does not silently move the task.
298 The evidence is marked `operator_declared`. The Runtime's existing worker,
299 artifact and event endpoints expose the receipt.
300
301 ### Tailscale and WhaleNet
302
303 `GET /v1/tailnet` reads the already-connected local Tailscale client. It returns
304 node IDs, names, OS, addresses and online status without enrolling devices or
305 altering tailnet policy. The request has a five-second deadline and bounded
306 output. Missing or disconnected Tailscale returns `tailnet_unavailable`.
307 `GET /v1/targets` advertises both the inventory and placement preview routes.
308 The routes use the Runtime API's existing authentication boundary.
309
310 An operator-authored Fleet worker can use this host declaration:
311
312 ```json
313 {
314 "id": "builder-slot",
315 "name": "Private builder",
316 "host": {
317 "kind": "tailscale",
318 "node_id": "NODE_ID_FROM_INVENTORY",
319 "user": "worker",
320 "working_directory": "/srv/example",
321 "codewhale_binary": "/usr/local/bin/codewhale"
322 },
323 "environment": {
324 "id": "builder",
325 "kind": "cloud",
326 "resources": { "cpu_cores": 8, "memory_mib": 32768, "gpus": 0 },
327 "capabilities": ["rust"],
328 "data": ["repo:example"],
329 "persistent": true,
330 "cost_per_hour_microusd": 2000000
331 }
332 }
333 ```
334
335 The corresponding task can require:
336
337 ```json
338 {
339 "id": "review",
340 "name": "Review the source",
341 "instructions": "Inspect the repository and return concrete findings. Do not change files.",
342 "worker": { "role": "reviewer" },
343 "workspace": {
344 "placement": {
345 "kinds": ["local", "cloud"],
346 "capabilities": ["rust"],
347 "data": ["repo:example"],
348 "resources": { "memory_mib": 8192 },
349 "max_cost_per_hour_microusd": 3000000,
350 "prefer": ["builder"]
351 }
352 },
353 "budget": { "max_steps": 20, "max_seconds": 600 }
354 }
355 ```
356
357 The rate and hardware above are example declarations, not an offer. Put workers
358 and tasks in the document's `workers` and `tasks` arrays. A local candidate
359 declaring only 4096 MiB would be refused for this task even if listed first.
360
361 Before each dispatch batch, Codewhale refreshes inventory on the blocking pool,
362 so a slow Tailscale client does not block the async runtime. At launch it resolves
363 the exact node ID again from that snapshot and refuses snapshots older than 30
364 seconds. It requires an online
365 peer advertising Tailscale SSH host keys, pins those keys in a private temporary
366 known-hosts file, and uses OpenSSH through `tailscale nc`. It disables SSH
367 configuration aliases and alternative host-key trust sources for that transport.
368 An absent node, missing keys or stale name never falls back to another address
369 or ordinary public SSH. The destination still enforces its tailnet and SSH
370 rules. A checksummed node-identity receipt records the selected node, address,
371 OS user and check time before SSH starts; it explicitly does not claim that
372 authentication or the task succeeded. The normal worker result supplies that
373 later evidence. In-place Tailscale host restarts are refused; a fresh Fleet
374 attempt performs a new identity check.
375
376 This works with an enrolled Tailscale-compatible network, including WhaleNet's
377 existing network foundation when its node advertises Tailscale SSH. Existing
378 SSH remote-process cleanup limitations still apply: a lost local connection
379 does not prove the remote process stopped. Remote tasks should remain bounded.
380
381 This preview does not enroll an agent as a separate node, implement the app's
382 per-machine consent flow, allocate Boat computers, sync workspaces, or enable
383 remote custom workers in the managed Fleet API. Those authority and lifecycle
384 paths remain owned by their existing runtime/platform surfaces. It is the
385 placement and connectivity foundation for that integration. ShannonNet stays
386 separate and deferred.
387
388 Transport references: [Tailscale SSH](https://tailscale.com/docs/features/tailscale-ssh),
389 [Tailscale CLI](https://tailscale.com/docs/reference/tailscale-cli), and the
390 [upstream SSH wrapper](https://github.com/tailscale/tailscale/blob/main/cmd/tailscale/cli/ssh.go).
391
391 lines MARKDOWN