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:
@@ -291,7 +291,6 @@ int main(int argc, char **argv) {
|
||||
close(fd);
|
||||
return EX_OSERR;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
/* Pull out `ok`, `data`/`error` from the response. */
|
||||
size_t ok_len = 0, data_len = 0, code_len = 0, msg_len = 0;
|
||||
@@ -302,11 +301,38 @@ int main(int argc, char **argv) {
|
||||
if (data) {
|
||||
fwrite(data, 1, data_len, stdout);
|
||||
fputc('\n', stdout);
|
||||
fflush(stdout);
|
||||
} else {
|
||||
fputs("{}\n", stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
/* If the server flagged this as a streaming response
|
||||
* (`tail --events` per T-129), loop-read event JSON-lines
|
||||
* until the connection closes. Detection: look for the
|
||||
* literal `"streaming":true` inside the data blob. */
|
||||
if (data && data_len > 0) {
|
||||
char data_copy[16384];
|
||||
size_t copy_len = data_len < sizeof(data_copy) - 1 ? data_len : sizeof(data_copy) - 1;
|
||||
memcpy(data_copy, data, copy_len);
|
||||
data_copy[copy_len] = '\0';
|
||||
if (strstr(data_copy, "\"streaming\":true") != NULL || strstr(data_copy, "\"streaming\": true") != NULL) {
|
||||
/* Streaming mode — keep reading event lines. Exit
|
||||
* 0 on EOF (server closed cleanly), non-zero on
|
||||
* read error. */
|
||||
char ev[65536];
|
||||
while (read_line(fd, ev, sizeof(ev)) == 0) {
|
||||
fputs(ev, stdout);
|
||||
fputc('\n', stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
close(fd);
|
||||
const char *code_v = json_value(resp, "code", &code_len);
|
||||
const char *msg_v = json_value(resp, "message", &msg_len);
|
||||
int exit_code = code_v ? (int)strtol(code_v, NULL, 10) : EX_SOFTWARE;
|
||||
|
||||
Reference in New Issue
Block a user