Files
clide/lib/src/pty/env.dart
T
Jeroen SchweitzerandClaude Opus 4.6 a6eca2561b remove dissolved daemon, retire ptyc, fix golden cross-platform
Complete three overdue cleanups discovered during macOS health check:

D-56 daemon dissolution: delete bin/clide.dart, DaemonServer,
and orphaned tests (test/cli/, subprocess_test, in_process_test).
Update stale "clide --daemon" references in i18n catalogs, error
messages, editor_commands, CI scripts, and decision records.

ptyc retirement: delete ptyc/ source tree, PtySession, scm_rights.
Remove from Toolchain resolution, ToolCheck gate, backend
serialization, testmode harness, Makefile, CI, and sandbox
entitlements. PTY spawning uses NativePty (Dart FFI forkpty) since
the terminal was absorbed in-tree. D-5 amended.

Golden tests: wire the existing but never-applied clideGoldenConfig
via flutter_test_config.dart. Disable CI goldens (Skia anti-aliasing
differs between macOS/Linux even with Ahem). Keep platform-keyed
goldens only — goldens/linux/ and goldens/macos/ each run on their
own OS.

Test suite: 826 pass, 0 fail on macOS (was 829 pass, 11 fail).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-07 18:40:01 +02:00

66 lines
2.2 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 'dart:io';
/// On macOS, GUI apps inherit a minimal PATH that omits Homebrew,
/// ~/.local/bin, and similar directories. This getter returns the
/// platform PATH with those well-known directories merged in.
/// On Linux/Windows it returns the PATH unchanged.
String get expandedPath {
_cachedPath ??= _buildExpandedPath();
return _cachedPath!;
}
String? _cachedPath;
String _buildExpandedPath() {
final base = Platform.environment['PATH'] ?? '';
if (!Platform.isMacOS) return base;
final home = Platform.environment['HOME'] ?? '';
final extras = <String>[
if (home.isNotEmpty) '$home/.local/bin',
'/opt/homebrew/bin',
'/opt/homebrew/sbin',
'/usr/local/bin',
];
final existing = base.split(':').toSet();
final missing = extras.where((p) => !existing.contains(p));
if (missing.isEmpty) return base;
return [...missing, ...existing].join(':');
}
/// 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',
// tmux inherits these when clide spawns tmux; 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,
if (overrides != null) ...overrides,
};
}