Desktop/dock-launched clide inherits a sparse PATH (no ~/.local/bin, brew, nvm, …), so pql/git/claude and PTY tools went missing. T-347 fixed only the toolchain/pql path on Linux; env.dart's expander was still macOS-only and claude/PTY/git used the raw PATH — the breakage recurred per spawn site because there were three divergent expanders. Consolidate into one resolver (lib/src/env/shell_env.dart): - primeLoginShellPath(): probe the user's real login shell once at startup (`$SHELL -l -c`, sentinel-framed, bounded timeout, graceful fallback to the process PATH). Captures the user's actual PATH, not a hardcoded guess. - expandToolPath(): the canonical merge (moved from toolchain_paths, which re-exports it for its tests) — unions the well-known user/local bin dirs. - resolvedToolPath(): currentSearchPath() + expandToolPath, the single call every spawn site uses. Routed through it: PTY children (registry.dart now overrides PATH), git (env.dart → operations.dart), the toolchain probe (toolchain_paths), and hosted claude (agent_bootstrap). Primed in main.dart's !kIsWeb boot. Deleted the macOS-only env.dart copy and the cli_install copy. Tests: new shell_env_test (probe + every fallback + merge); env_test and cli_install_test updated to the consolidated surface. analyze clean, web wasm build still green, make test green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
39 lines
1.8 KiB
Dart
39 lines
1.8 KiB
Dart
/// Default environment for PTY-spawned children and subprocess PATH
|
|
/// expansion for macOS GUI apps.
|
|
///
|
|
/// `xterm.dart` on the UI side + most shells + tmux + Claude CLI all
|
|
/// understand the 24-bit-colour triplet `TERM=xterm-256color` +
|
|
/// `COLORTERM=truecolor`. Without `COLORTERM` most apps fall back to
|
|
/// the 256-colour palette and the terminal looks washed out even though
|
|
/// the renderer can do true colour.
|
|
library;
|
|
|
|
import 'package:clide/src/env/shell_env.dart' show resolvedToolPath;
|
|
|
|
/// The full tool search PATH for PTY children and PATH-resolved subprocess
|
|
/// lookup — delegates to the shared resolver ([resolvedToolPath], T-439) so
|
|
/// every spawn site agrees: the login-shell PATH (probed once at startup)
|
|
/// unioned with the well-known user/local bin dirs. Previously this was a
|
|
/// macOS-only merge, so a Linux desktop launch left tools unresolvable.
|
|
String get expandedPath => resolvedToolPath();
|
|
|
|
/// Base env clide builds for every PTY child. Callers merge with the
|
|
/// user's environment — a child that needs user env like `HOME` /
|
|
/// `USER` / `SHELL` still gets them; the keys here override the ones
|
|
/// the child cares about.
|
|
const Map<String, String> clidePtyEnvDefaults = {
|
|
'TERM': 'xterm-256color',
|
|
'COLORTERM': 'truecolor',
|
|
// Encourages 24-bit emission from tooling that checks this:
|
|
'CLICOLOR_FORCE': '1',
|
|
// UTF-8 locale for the child and anything it spawns; safe to propagate.
|
|
'LANG': 'en_US.UTF-8',
|
|
'LC_ALL': 'en_US.UTF-8',
|
|
};
|
|
|
|
/// Merge [base] onto the process environment; clide defaults override
|
|
/// user env where they overlap. Explicit [overrides] win over both.
|
|
Map<String, String> mergePtyEnv({required Map<String, String> processEnv, Map<String, String>? overrides}) {
|
|
return {...processEnv, ...clidePtyEnvDefaults, ...?overrides};
|
|
}
|