T-129: event streaming over the socket — clide tail --events
Sixth slice of T-99. Long-lived event subscription path, the second
half of D-6.
Wire shape:
- Client sends `{cmd:"tail", args:{flags:{events:true, filter:X}}}`.
- Server responds with `{ok:true, data:{streaming:true, filter:X}}`.
- Server pushes `{type:"event", subsystem, kind, ts, data}` lines
until the client closes.
Server (lib/src/ipc/server.dart):
- Takes a DaemonBus, subscribes to DaemonEvent on start.
- Per-subsystem ring buffer (replayDepth=16 per D-6) populated on
every emit.
- `tail --events` connection: send ack, replay matching events from
ring, register the client for future fanout.
- _argv envelope now unwrapped at the server layer so the streaming
check sees the inner `tail` cmd (not just `_argv`).
- Broken subscriber writes drop the subscriber cleanly; the bus
doesn't block on a stalled client.
Client (native/clide-cli/clide.c):
- Sniffs `data.streaming:true` in the ack. If set, loops reading
JSON-line events to stdout (with fflush per line) until EOF.
Tests:
- test/ipc/server_streaming_test.dart — 8 cases covering ack shape,
filter, replay buffer (size + ordering), multi-subscriber fanout,
broken-subscriber cleanup.
- test/cli/clide_cli_e2e_test.dart gets a tail --events test that
spawns the C client, emits two events on the bus, asserts they
print on stdout.
T-99 children remaining: T-130 (MCP), T-131 (wrap-up).
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,30 +20,37 @@ import 'package:clide/src/ipc/schema_v1.dart';
|
||||
/// goes through the normal dispatcher path unchanged.
|
||||
const String argvSentinelCmd = '_argv';
|
||||
|
||||
/// Wire the `_argv` sentinel handler onto [dispatcher]. The handler:
|
||||
/// 1. Extracts `args.argv` as a List<String>.
|
||||
/// 2. Calls [parseArgv].
|
||||
/// 3. If parsed → re-dispatches the inner request through the
|
||||
/// *same* dispatcher (so per-handler logic runs once).
|
||||
/// 4. If error → returns the pre-built [IpcResponse] verbatim,
|
||||
/// patched with the outer request id so the client correlates.
|
||||
/// Unwrap an `_argv` IpcRequest into the inner parsed request, or
|
||||
/// return an error response if the envelope is malformed or the
|
||||
/// argv doesn't parse. Pure function — no dispatch. Used by both
|
||||
/// the IPC server (which needs the unwrapped cmd to decide whether
|
||||
/// to enter streaming mode for `tail --events`, per T-129) and the
|
||||
/// dispatcher-side handler below.
|
||||
ArgvParseResult unwrapArgvRequest(IpcRequest outer) {
|
||||
final raw = outer.args['argv'];
|
||||
if (raw is! List) {
|
||||
return ArgvError(IpcResponse.err(
|
||||
id: outer.id,
|
||||
error: IpcError(
|
||||
code: IpcExitCode.userError,
|
||||
kind: IpcErrorKind.userError,
|
||||
message: '_argv requires args.argv to be a JSON array',
|
||||
),
|
||||
));
|
||||
}
|
||||
return parseArgv(raw.cast<String>(), requestId: outer.id);
|
||||
}
|
||||
|
||||
/// Wire the `_argv` sentinel handler onto [dispatcher]. The handler
|
||||
/// unwraps the inner argv via [unwrapArgvRequest], dispatches the
|
||||
/// resulting request through the same dispatcher, and otherwise
|
||||
/// returns the pre-built error response. Kept registered for the
|
||||
/// non-streaming path; the IPC server intercepts before dispatch
|
||||
/// for `tail --events` (T-129).
|
||||
void registerArgvUnwrap(DaemonDispatcher dispatcher) {
|
||||
dispatcher.register(argvSentinelCmd, (outer) async {
|
||||
final raw = outer.args['argv'];
|
||||
if (raw is! List) {
|
||||
return IpcResponse.err(
|
||||
id: outer.id,
|
||||
error: IpcError(
|
||||
code: IpcExitCode.userError,
|
||||
kind: IpcErrorKind.userError,
|
||||
message: '_argv requires args.argv to be a JSON array',
|
||||
),
|
||||
);
|
||||
}
|
||||
final argv = raw.cast<String>();
|
||||
final result = parseArgv(argv, requestId: outer.id);
|
||||
return switch (result) {
|
||||
ArgvParsed(:final request) => dispatcher.dispatch(request),
|
||||
return switch (unwrapArgvRequest(outer)) {
|
||||
ArgvParsed(:final request) => await dispatcher.dispatch(request),
|
||||
ArgvError(:final response) => response,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user