add Dart core package — IPC envelopes, daemon, ping round-trip

First real content for the `clide` Dart package at the repo root.
One AOT-compiled binary (ADR 0005) with two modes:

  * `clide --daemon`  long-running unix-socket server; listens on
    `$XDG_RUNTIME_DIR/clide-$USER.sock` with stale-socket
    reclaim, accepts JSON-lines request/response traffic, clean
    SIGTERM shutdown unlinks the socket file.
  * `clide <subcommand>`  one-shot; opens the socket, sends a
    request, writes the response JSON to stdout, exits with the
    dispatcher's error code per ADR 0006 (0/1/2/3/4). Unknown
    subcommands forward to the daemon so extensions can register
    their own without CLI changes.

Tier 0 handlers: `ping` (returns pong + version + UTC ts) and
`version`. Both are covered by `test/ipc/` + `test/daemon/`; the
subprocess test builds `bin/clide`, starts it, pings it, SIGTERMs
it, and asserts the socket file disappears.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-04-21 15:36:40 +02:00
co-authored by Claude
parent bded1a2b65
commit 235cbcc046
15 changed files with 1373 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
import 'package:clide/clide.dart' show clideVersion;
import 'package:clide/src/ipc/envelope.dart';
import 'package:clide/src/ipc/schema_v1.dart';
typedef CommandHandler = Future<IpcResponse> Function(IpcRequest req);
class DaemonDispatcher {
DaemonDispatcher() {
register('ping', _ping);
register('version', _version);
}
final Map<String, CommandHandler> _handlers = {};
void register(String cmd, CommandHandler handler) {
_handlers[cmd] = handler;
}
Future<IpcResponse> dispatch(IpcRequest req) async {
final h = _handlers[req.cmd];
if (h == null) {
return IpcResponse.err(
id: req.id,
error: IpcError(
code: IpcExitCode.notFound,
kind: IpcErrorKind.notFound,
message: 'unknown command: ${req.cmd}',
hint: 'run `clide --help` for the surface.',
),
);
}
return h(req);
}
Future<IpcResponse> _ping(IpcRequest req) async => IpcResponse.ok(
id: req.id,
data: {
'pong': true,
'ts': DateTime.now().toUtc().toIso8601String(),
'version': clideVersion,
},
);
Future<IpcResponse> _version(IpcRequest req) async => IpcResponse.ok(
id: req.id,
data: {'version': clideVersion},
);
}