feat: command-descriptor registry (additive, parity-tested) — Phase 1 step 1

Merged
TH
5mo ago
+799-3

What

ADR-0008 Phase 1 step 1: introduce a single CommandDescriptor registry as the strangler-fig foundation for the command-descriptor migration. This is purely additive and dormant — nothing reads the new registry yet; it exists only to be proven byte-equal to today's hand tables.

New files (src/commands/descriptor/)

  • types.ts — CommandDescriptor type + defineCommandDescriptor(). Per command it carries the daemon route + request-policy traits (reusing the existing DaemonCommandDescriptor shape including the closure traits allowSessionlessDefaultDevice / skipSessionlessProviderDevice, not flattened), an optional CommandCapability entry, and batchable / mcpExposed flags.
  • registry.ts — commandDescriptors, the additive single source. Covers the full daemon key space (public + internal + gesture-alias names) plus the two capability/batch-only commands (app-switcher, install-from-source). Daemon traits, capability, and batchable are copied verbatim from DAEMON_COMMAND_DESCRIPTORS, BASE_COMMAND_CAPABILITY_MATRIX, and STRUCTURED_BATCH_COMMAND_NAMES.
  • derive.ts — pure folds: deriveDaemonCommandDescriptors, deriveCapabilityMatrix, deriveStructuredBatchCommandNames.
  • __tests__/parity.test.ts — asserts each derived table matches the live hand table. Function-valued traits (daemon closures + capability supports/unsupportedHint) are compared by presence + behavior on a representative request/device sample (mirroring daemon-command-registry.test.ts); every other field is deepEqual'd.

Derivations proven byte-equal

  • Daemon descriptors — order-exact deepEqual against DAEMON_COMMAND_DESCRIPTORS (closures by behavior).
  • Capability matrix — deepEqual against BASE_COMMAND_CAPABILITY_MATRIX (supports/unsupportedHint by behavior across 11 sample devices).
  • Structured-batch names — membership-equal to STRUCTURED_BATCH_COMMAND_NAMES. (Order is not reproduced: the daemon and batch hand tables are independently ordered, so one registry table cannot reproduce both array orders; the consumer dedupes into a Set, so ordering is cosmetic and deferred to a later slice.)

Additive / dormant guarantee

No consumers changed, nothing deleted, no import-graph inversion. The only edits outside src/commands/descriptor/ add an export keyword to three existing tables so the parity tests can read them: DAEMON_COMMAND_DESCRIPTORS + the DaemonCommandDescriptor type (daemon-command-registry.ts) and BASE_COMMAND_CAPABILITY_MATRIX (capabilities.ts). No behavior change.

Verification

  • tsc --noEmit ✅
  • oxfmt --write + oxlint --deny-warnings ✅
  • vitest run commands/descriptor daemon-command-registry capabilities batch → 7 files / 42 tests ✅