Nothing has spawned tmux since D-77 moved Claude session persistence to `--resume`; Claude and terminal panes spawn `claude` or the shell directly. But the toolchain still resolved tmux and listed it in `missing`, so on mac/linux a box without tmux showed a spurious "tmux not found" warning in the welcome view + status bar. The windows-support branch had special-cased that away with a `!Platform.isWindows` guard — the tell that the requirement was dead everywhere, not platform-specific. Drop tmux from ResolvedPaths / ToolchainView / Toolchain (field, getter, `missing`, PATH resolution) on every platform, removing the Windows guards with it. Strip the testmode tmux probes and the comments / CLAUDE.md line that claimed clide spawns tmux. (The dead ToolCheck class that also gated on tmux was already deleted on main and dropped in the preceding merge.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
169 lines
6.4 KiB
Dart
169 lines
6.4 KiB
Dart
/// Flutter-free toolchain data + resolution.
|
|
///
|
|
/// Split out of `toolchain.dart` so that pure-Dart consumers (the IPC
|
|
/// subsystems exported through `package:clide/clide.dart`, e.g.
|
|
/// [GitClient] and [PqlClient]) don't transitively pull in
|
|
/// `package:flutter/foundation.dart`. The live, listenable `Toolchain`
|
|
/// stays in `toolchain.dart`; everything here is plain Dart and runs
|
|
/// fine under `dart test`.
|
|
library;
|
|
|
|
import 'dart:io';
|
|
|
|
/// Serializable result of tool resolution (crosses isolate boundary).
|
|
class ResolvedPaths {
|
|
const ResolvedPaths({this.git, this.pql, this.shell, this.gitEnv});
|
|
|
|
final String? git;
|
|
final String? pql;
|
|
final String? shell;
|
|
final Map<String, String>? gitEnv;
|
|
}
|
|
|
|
/// Read-only view of resolved tool paths. The concrete `Toolchain`
|
|
/// (in `toolchain.dart`) implements this on top of `ChangeNotifier`;
|
|
/// pure-Dart clients depend on the interface so they stay Flutter-free.
|
|
abstract class ToolchainView {
|
|
/// A fixed, already-resolved view over [paths]. Flutter-free — handy
|
|
/// for tests and isolate-side code that has a [ResolvedPaths] but no
|
|
/// need for the listenable `Toolchain`.
|
|
const factory ToolchainView.resolved(ResolvedPaths paths) = _StaticToolchain;
|
|
|
|
String get git;
|
|
String get pql;
|
|
String get shell;
|
|
Map<String, String>? get gitEnv;
|
|
bool get resolved;
|
|
bool get allOk;
|
|
List<String> get missing;
|
|
}
|
|
|
|
class _StaticToolchain implements ToolchainView {
|
|
const _StaticToolchain(this._paths);
|
|
|
|
final ResolvedPaths _paths;
|
|
|
|
@override
|
|
String get git => _paths.git ?? 'git';
|
|
@override
|
|
String get pql => _paths.pql ?? 'pql';
|
|
@override
|
|
String get shell => _paths.shell ?? (Platform.isWindows ? 'powershell.exe' : '/bin/bash');
|
|
@override
|
|
Map<String, String>? get gitEnv => _paths.gitEnv;
|
|
@override
|
|
bool get resolved => true;
|
|
@override
|
|
bool get allOk => missing.isEmpty;
|
|
@override
|
|
List<String> get missing => [if (_paths.git == null) 'git', if (_paths.pql == null) 'pql'];
|
|
}
|
|
|
|
/// Top-level function for compute/isolate use. Returns a plain-data
|
|
/// result with all tool paths resolved against trusted locations only.
|
|
///
|
|
/// Critically does NOT take a workspace path: per T-98, resolving the
|
|
/// dugite-bundled git against the open workspace was a code-execution
|
|
/// vector (a malicious repo could plant `native/dugite/bin/git`).
|
|
/// Dugite is resolved against the install directory + an explicit env
|
|
/// override; everything else comes from PATH.
|
|
ResolvedPaths resolveToolchainPaths() {
|
|
String? git;
|
|
Map<String, String>? gitEnv;
|
|
final dugiteGit = _resolveDugiteGit();
|
|
if (dugiteGit != null) {
|
|
git = dugiteGit;
|
|
final dugiteRoot = File(dugiteGit).parent.parent.path;
|
|
gitEnv = {'GIT_EXEC_PATH': '$dugiteRoot/libexec/git-core', 'GIT_TEMPLATE_DIR': '$dugiteRoot/share/git-core/templates'};
|
|
} else {
|
|
git = _findOnPath('git');
|
|
}
|
|
|
|
return ResolvedPaths(git: git, pql: _findOnPath('pql'), shell: _resolveShell(), gitEnv: gitEnv);
|
|
}
|
|
|
|
/// The user's interactive shell. POSIX honours `$SHELL`; Windows has
|
|
/// no such convention — prefer PowerShell 7 (`pwsh`), fall back to
|
|
/// Windows PowerShell (present on every supported Windows).
|
|
String? _resolveShell() {
|
|
if (Platform.isWindows) {
|
|
return _findOnPath('pwsh') ?? _findOnPath('powershell');
|
|
}
|
|
return _findOnPath(Platform.environment['SHELL']?.split('/').last ?? 'bash');
|
|
}
|
|
|
|
/// Locate the dugite-bundled git binary in trusted install locations
|
|
/// only. **Never inspects workspace-relative paths** — see T-98.
|
|
///
|
|
/// Search order:
|
|
/// 1. `CLIDE_DUGITE_DIR` env var (dev override; points at a dugite
|
|
/// root that contains `bin/git`).
|
|
/// 2. `<exe-parent>/dugite/bin/git` — production bundle layout.
|
|
/// 3. `<exe-parent>/lib/dugite/bin/git` — alternate bundle layout
|
|
/// (mirrors Linux's INSTALL_BUNDLE_LIB_DIR convention).
|
|
///
|
|
/// Returns null if no dugite is found; caller falls back to PATH git.
|
|
String? _resolveDugiteGit() {
|
|
// dugite-native's Windows layout differs (cmd\git.exe, mingw64
|
|
// libexec) and isn't wired up yet — PATH git serves Windows until
|
|
// the bundle work lands.
|
|
if (Platform.isWindows) return null;
|
|
final candidates = <String>[];
|
|
final envDir = Platform.environment['CLIDE_DUGITE_DIR'];
|
|
if (envDir != null && envDir.isNotEmpty) {
|
|
candidates.add('$envDir/bin/git');
|
|
}
|
|
final exeDir = File(Platform.resolvedExecutable).parent.path;
|
|
candidates.add('$exeDir/dugite/bin/git');
|
|
candidates.add('$exeDir/lib/dugite/bin/git');
|
|
return _firstExisting(candidates);
|
|
}
|
|
|
|
String? _findOnPath(String name) {
|
|
final sep = Platform.isWindows ? ';' : ':';
|
|
for (final dir in _expandedPath().split(sep)) {
|
|
if (dir.isEmpty) continue;
|
|
if (Platform.isWindows) {
|
|
// PATHEXT-style probe — a bare `pql` on PATH is really pql.exe.
|
|
for (final ext in const ['.exe', '.bat', '.cmd', '.com', '']) {
|
|
final f = File('$dir\\$name$ext');
|
|
if (f.existsSync()) return f.path;
|
|
}
|
|
} else {
|
|
final f = File('$dir/$name');
|
|
if (f.existsSync()) return f.path;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
String? _firstExisting(List<String> candidates) {
|
|
for (final c in candidates) {
|
|
if (File(c).existsSync()) return c;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// Build expanded PATH inline — must be self-contained for isolate use.
|
|
String _expandedPath() =>
|
|
expandToolPath(Platform.environment['PATH'] ?? '', isMac: Platform.isMacOS, isLinux: Platform.isLinux, home: Platform.environment['HOME']);
|
|
|
|
/// Pure PATH-expansion logic, extracted so it's testable without touching the
|
|
/// process environment.
|
|
///
|
|
/// A desktop-launched app (macOS or Linux) inherits a minimal PATH that lacks
|
|
/// the user bin dirs where tools like `pql` install (`~/.local/bin`), so tool
|
|
/// resolution fails even though a terminal launch would find them. Re-add the
|
|
/// common user/local bin dirs — that any are missing means they're prepended,
|
|
/// so they take precedence over a stale system copy (T-347). Homebrew dirs are
|
|
/// macOS-only. On other platforms the base PATH passes through unchanged.
|
|
String expandToolPath(String base, {required bool isMac, required bool isLinux, String? home}) {
|
|
if (!isMac && !isLinux) return base;
|
|
final h = home ?? '';
|
|
final extras = <String>[if (h.isNotEmpty) '$h/.local/bin', if (isMac) '/opt/homebrew/bin', if (isMac) '/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(':');
|
|
}
|