diff --git a/bin/clide.dart b/bin/clide.dart index b2852576..8ea75dcc 100644 --- a/bin/clide.dart +++ b/bin/clide.dart @@ -13,6 +13,12 @@ import 'dart:convert'; import 'dart:io'; import 'package:clide/clide.dart'; +// Daemon-only deep imports — these pull in dart:ffi (PTY) and +// daemon-subsystem wiring that the Flutter app doesn't need and +// can't compile for web. See lib/clide.dart for the barrel split. +import 'package:clide/src/daemon/files_commands.dart'; +import 'package:clide/src/daemon/pane_commands.dart'; +import 'package:clide/src/panes/registry.dart'; Future main(List argv) async { if (argv.isEmpty) { diff --git a/lib/clide.dart b/lib/clide.dart index d867b248..f1ba13ed 100644 --- a/lib/clide.dart +++ b/lib/clide.dart @@ -8,21 +8,23 @@ /// * `decisions/architecture.md` `D-006` — CLI + event contract. library; +// Flutter-app-visible surface. Deliberately **does not** export the +// `pty/` or `panes/registry.dart` modules — those import `dart:ffi` +// and pull in the PTY machinery that only runs on desktop. The +// daemon entrypoint (`bin/clide.dart`) imports them via deep paths. +// +// `Pane` + `PaneKind` + the event-sink interfaces travel here because +// they're pure data types that both the app and the daemon reference. + export 'src/daemon/dispatcher.dart'; -export 'src/daemon/files_commands.dart'; -export 'src/daemon/pane_commands.dart'; export 'src/files/ignore.dart'; export 'src/files/listing.dart' show FileEntry, listDir; -export 'src/files/watcher.dart'; export 'src/ipc/envelope.dart'; export 'src/ipc/paths.dart'; export 'src/ipc/schema_v1.dart'; export 'src/ipc/server.dart'; export 'src/panes/event_sink.dart'; export 'src/panes/pane.dart' show Pane, PaneKind; -export 'src/panes/registry.dart' show PaneRegistry; -export 'src/pty/errors.dart' show PtyException; -export 'src/pty/pty.dart'; /// Build-time-stamped version string. /// diff --git a/lib/src/panes/pane.dart b/lib/src/panes/pane.dart index ae695430..97199eee 100644 --- a/lib/src/panes/pane.dart +++ b/lib/src/panes/pane.dart @@ -1,13 +1,11 @@ -/// A single active pane in the daemon. +/// A single active pane. Pure data — no PTY coupling so this type +/// travels cleanly into the Flutter app (which can't depend on +/// `dart:ffi`-using code for the web build). /// -/// Owns a [PtySession] plus whatever pane-level metadata the UI + -/// CLI need. The `kind:` field distinguishes general-purpose terminal -/// panes from Claude panes (D-041, not yet landed) from whatever -/// future pane-shaped surface Tier 1+ grows. +/// The daemon's [PaneRegistry] keeps a parallel `PtySession` keyed on +/// [id] and mutates [isClosed] when the session exits. library; -import '../pty/session.dart'; - /// Kind of a pane. Keep this enum small and explicit — each kind /// typically pairs with a bundled extension that manages its /// lifecycle (`builtin.terminal`, `builtin.claude`). @@ -25,28 +23,28 @@ enum PaneKind { } } -/// A live pane. Thin wrapper over [PtySession] — the registry is what -/// owns the session lifecycle; consumers of this class read state and -/// call [write] / [resize] via the session. class Pane { Pane({ required this.id, required this.kind, - required this.session, + required this.pid, required this.argv, this.cwd, this.title, + this.isClosed = false, }); final String id; final PaneKind kind; - final PtySession session; + final int pid; final List argv; final String? cwd; final String? title; - int get pid => session.pid; - bool get isClosed => session.isClosed; + /// Mutated by the registry when the child exits or the session + /// closes. Kept mutable so registry state doesn't need to replace + /// [Pane] instances on transition. + bool isClosed; Map toJson() => { 'id': id, diff --git a/lib/src/panes/registry.dart b/lib/src/panes/registry.dart index 84a34601..fcef8a4d 100644 --- a/lib/src/panes/registry.dart +++ b/lib/src/panes/registry.dart @@ -20,6 +20,7 @@ class PaneRegistry { final DaemonEventSink events; final Map _panes = {}; + final Map _sessions = {}; final Map> _subs = {}; int _nextId = 1; @@ -55,12 +56,13 @@ class PaneRegistry { final pane = Pane( id: id, kind: kind, - session: session, + pid: session.pid, argv: argv, cwd: cwd, title: title, ); _panes[id] = pane; + _sessions[id] = session; _emit('pane.spawned', id, pane.toJson()); @@ -77,15 +79,17 @@ class PaneRegistry { /// Send bytes to a pane's stdin. int write(String id, List bytes) { final p = _panes[id]; - if (p == null || p.isClosed) return 0; - return p.session.write(bytes); + final s = _sessions[id]; + if (p == null || p.isClosed || s == null) return 0; + return s.write(bytes); } /// Resize a pane + emit `pane.resized`. void resize(String id, {required int cols, required int rows}) { final p = _panes[id]; - if (p == null || p.isClosed) return; - p.session.resize(cols: cols, rows: rows); + final s = _sessions[id]; + if (p == null || p.isClosed || s == null) return; + s.resize(cols: cols, rows: rows); _emit('pane.resized', id, {'cols': cols, 'rows': rows}); } @@ -93,9 +97,11 @@ class PaneRegistry { Future close(String id) async { final p = _panes[id]; if (p == null) return; - await p.session.close(); + final s = _sessions[id]; + if (s != null) await s.close(); await _subs[id]?.cancel(); _subs.remove(id); + _sessions.remove(id); _panes.remove(id); _emit('pane.closed', id, const {}); } @@ -111,6 +117,7 @@ class PaneRegistry { void _onExit(Pane p) { if (_panes.containsKey(p.id)) { + p.isClosed = true; _emit('pane.exit', p.id, const {}); // Don't auto-close — keep the pane entry so `list` can show the // exited state until the consumer explicitly closes. A future diff --git a/test/daemon/files_commands_test.dart b/test/daemon/files_commands_test.dart index d4e3eada..9edc068c 100644 --- a/test/daemon/files_commands_test.dart +++ b/test/daemon/files_commands_test.dart @@ -4,6 +4,7 @@ library; import 'dart:io'; import 'package:clide/clide.dart'; +import 'package:clide/src/daemon/files_commands.dart'; import 'package:test/test.dart'; void main() { diff --git a/test/daemon/pane_commands_test.dart b/test/daemon/pane_commands_test.dart index 8381c215..3d741a00 100644 --- a/test/daemon/pane_commands_test.dart +++ b/test/daemon/pane_commands_test.dart @@ -9,6 +9,8 @@ import 'dart:convert'; import 'dart:io'; import 'package:clide/clide.dart'; +import 'package:clide/src/daemon/pane_commands.dart'; +import 'package:clide/src/panes/registry.dart'; import 'package:test/test.dart'; void main() { diff --git a/test/panes/registry_test.dart b/test/panes/registry_test.dart index 8544ea85..2bbc7848 100644 --- a/test/panes/registry_test.dart +++ b/test/panes/registry_test.dart @@ -10,6 +10,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:clide/clide.dart'; +import 'package:clide/src/panes/registry.dart'; import 'package:test/test.dart'; void main() { diff --git a/test/pty/session_test.dart b/test/pty/session_test.dart index 1efa0b96..18a8464b 100644 --- a/test/pty/session_test.dart +++ b/test/pty/session_test.dart @@ -9,7 +9,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:clide/clide.dart'; +import 'package:clide/src/pty/pty.dart'; import 'package:test/test.dart'; void main() {