T-126: C clide shell client + _argv unwrap in the dispatcher

Third slice of T-99. After this `clide status` actually does
something when typed in a shell.

* native/clide-cli/clide.c — ~250 LOC C. Walks CWD up to .git,
  hashes the workspace root with FNV-1a 64-bit (byte-for-byte
  identical to the Dart side, pinned via reference vectors in
  paths_test.dart), opens the per-workspace socket, and ships argv
  across the wire as `{cmd:"_argv", args:{argv:[...]}}`.
* lib/src/cli/argv_dispatch.dart — registers the `_argv` sentinel
  command on the dispatcher. The handler runs the T-125 parser on
  the embedded argv and either re-dispatches the unwrapped request
  through the same dispatcher or returns the pre-built error
  response. Keeps the parser in Dart so the C side stays dumb.
* lib/src/ipc/paths.dart — fnv1a64Hex hoisted to a public helper +
  fixed to format as unsigned (Dart `int` is signed int64; the high
  bit lit a leading minus that broke the cross-language compare).
  Reference-vector tests added against the FNV reference.
* `make clide-cli` builds it via the host `cc`; output lands at
  native/<platform>/clide and is gitignored. Test
  test/cli/clide_cli_e2e_test.dart compiles + exercises the full
  round-trip; skips cleanly when no cc is on PATH.
* CONTRIBUTING.md gets a "C clide shell client" section.

T-128 (delete legacy IPC) unblocked.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-05-18 18:04:50 +02:00
co-authored by Claude
parent 1147bfac0e
commit 42955b6417
12 changed files with 638 additions and 23 deletions
+50
View File
@@ -0,0 +1,50 @@
/// Register the `_argv` sentinel command on a [DaemonDispatcher].
///
/// The C client (T-126) doesn't know the dispatcher's command surface
/// — it ships raw argv across the wire under cmd `_argv`. This handler
/// runs [parseArgv] on the embedded argv and either dispatches the
/// resulting [IpcRequest] or returns the pre-built error response.
///
/// Why a sentinel cmd rather than a top-level parse step in the IPC
/// server: keeps the server transport-agnostic — every consumer that
/// already has a typed [IpcRequest] goes the direct path; only the
/// CLI's raw-argv envelope hits this unwrap shim.
library;
import 'package:clide/src/cli/argv_to_request.dart';
import 'package:clide/src/daemon/dispatcher.dart';
import 'package:clide/src/ipc/envelope.dart';
import 'package:clide/src/ipc/schema_v1.dart';
/// Sentinel command id the C `clide` client sends. Anything else
/// 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&lt;String&gt;.
/// 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.
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),
ArgvError(:final response) => response,
};
});
}