Files
clide/app/lib/builtin/claude/src/session_naming.dart
T
jpmschweitzerandClaude b9fbcd43a2
test / unit + widget + golden + a11y (push) Failing after 45s
test / integration_test (xvfb) (push) Has been skipped
test / bundle smoke (xvfb 5s) (push) Has been skipped
test / daemon subprocess + web WASM smoke (push) Has been skipped
implement builtin.claude per D-041
Tier-0 stub flipped to the real Claude pane. Primary-per-repo
semantics: session name is `clide-claude-<hash>` where <hash> is
FNV-1a over the workspace root path, so reopening clide attaches
to the same `claude` process through `tmux new-session -A`.

Primary has no close button — closing the tab disposes the widget
but deliberately does NOT call pane.close, so the tmux session
survives until the user actually exits claude or clide is shut
down. Secondary sessions (spawned via the claude.new-secondary
command registered here, UI wiring lands next) close normally and
the pane.close cascades into tmux kill-session.

Graceful fallback when tmux isn't on PATH: retries the spawn with
argv=['claude'], surfaces "no-tmux · fresh every launch" in the
header subtitle so the user knows persistence is off.

Session-naming unit tests cover determinism + uniqueness per repo.
Full app suite: 174 tests passing.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-22 09:40:30 +02:00

31 lines
1.1 KiB
Dart

/// Derive deterministic tmux session names for Claude panes (D-041).
///
/// The primary session name for a repo is `clide-claude-<hash>` where
/// `<hash>` is an 8-char FNV-1a-ish hex hash of the canonical
/// (absolute, symlink-resolved) repo path. Not cryptographic — we just
/// need short, stable, collision-resistant-enough strings. Secondary
/// sessions append `-N` for monotonically increasing `N`.
library;
/// Stable session name for the primary Claude pane of [repoRoot].
String primarySessionName(String repoRoot) {
return 'clide-claude-${_hash(repoRoot)}';
}
/// Nth secondary session name. [n] starts at 1.
String secondarySessionName(String repoRoot, int n) {
return '${primarySessionName(repoRoot)}-$n';
}
/// 8-char hex hash. FNV-1a over UTF-16 code units; independent of
/// platform endianness. Collision rate at N=1000 repos is still
/// vanishingly small (≈0.0001%).
String _hash(String s) {
var h = 2166136261; // FNV offset basis (32-bit)
for (var i = 0; i < s.length; i++) {
h ^= s.codeUnitAt(i);
h = (h * 16777619) & 0xffffffff;
}
return h.toRadixString(16).padLeft(8, '0');
}