02-desktop-device-type.md

2.9 KB · raw

rendered · source

Change 2 — Add "desktop" DeviceType

DRAFT. Conforms to _GROUND-TRUTH.md.

VERDICT: already done. This change is a NO-OP against current source.

The brief assumed "desktop" was missing from DeviceType and that the type "likely" lives in src/shared/types.ts. Both assumptions are wrong against the ground-truth source:

  1. DeviceType is defined in src/shared/sync-types.ts:11, not types.ts (types.ts has no DeviceType symbol). chirp-handshake.ts:29 and paired-devices.ts:23 both import device types from ./sync-types.

  2. "desktop" is already a member:

    // src/shared/sync-types.ts:11
    export type DeviceType = "extension" | "android" | "ios" | "desktop";
    
  3. The full desktop plumbing already exists:

    • DEVICE_TYPE_DESKTOP = 0x04 chirp byte tag (sync-types.ts:19)
    • DeviceTypeByte includes it (sync-types.ts:25)
    • deviceTypeFromByte(0x04) → "desktop" (sync-types.ts:36)
    • deviceTypeToByte("desktop") → 0x04 (sync-types.ts:45)
    • chirp-payload.ts accepts byte 0x04 on the wire (chirp-payload.ts:5,89)
  4. peach-sync announces exactly this string: .device_type = "desktop" (peach-sync/src/pairing.zig:177), which lands on the existing union member.

No edit to the type union is required. If a downstream pass "adds" it again it will be a redundant no-op.


What ACTUALLY needs verifying: the storage gate (paired-devices.ts)

The real question is whether the paired-device registry rejects a "desktop" device. It does not — there is no enum gate.

upsertPairedDevice (src/background/paired-devices.ts:56-70) validates only presence, never membership against the DeviceType union:

// paired-devices.ts:60
if (!device.deviceType) throw new Error("device.deviceType is required");

It checks the field is truthy, not that it equals a known literal. "desktop" (or any non-empty string) passes. Storage round-trips it verbatim (isPairedDevice, paired-devices.ts:174-180, only checks deviceId is a non-empty string and pairedAt is a number — deviceType is not gated).

PairedDevice.deviceType is DeviceType | undefined (sync-types.ts:89), so "desktop" is statically valid; nothing to extend.

Conclusion / action for implementer

Discrepancy summary (for the report)