# TODO — mwb-mac backlog, one lane at a time Legend: **(core)** `MWBCore`, **(net)** `MWBNet`, **(mac)** `MWBMac`, **(app)** executable/tooling. Lanes run strictly in this order (`docs/topo.md` §3, `docs/loop.md` §6); each lane ticks only its own lines. Items describe Windows behaviour to port, with the `docs/protocol.md` section that specifies it. No test-writing items exist by the user's instruction — the user tests the app. --- ## 0. bootstrap (app) — done 2026-09-15 - [x] SwiftPM skeleton, four targets, layering enforced by `tools/gates.sh`. - [x] `tools/gates.sh` (lint + build), `tools/bundle.sh`, `tools/lane.sh`, `.swift-format`, `Resources/Info.plist`. - [x] `mwb --version`, `mwb --check-permissions`. - [x] `docs/loop.md`, `docs/features/TEMPLATE.md`. - [x] Xcode 27.0 installed; toolchain verified. ## 1. packet-codec (core) — `Sources/MWBCore/Packet.swift`, `Framing.swift` - [ ] `PackageType` (raw `UInt8`, every value in protocol §1.2), the big/small rule §1.1, unknown values tolerated. - [ ] `Packet` value type over a 32/64-byte little-endian buffer with the union views: mouse, keyboard, nonce, postAction, machineName, 48-byte clipboard payload at offset 16. - [ ] ASCII, space-padded, 32-byte machine name; non-ASCII refused. - [ ] `Framing.seal` / `Framing.open` exactly as §1.3 (checksum over bytes 2..31 only; magic top 16 bits; bytes 1–3 zeroed on open). ## 2. cipher-stream (core) — `Sources/MWBCore/MagicHash.swift`, `CipherStream.swift` - [ ] `magicNumber(for:)` per §2.1 (50 001 SHA-512 rounds, `<< 23` overlap, UTF-16 unit truncated to a byte, 32-byte buffer). - [ ] PBKDF2-HMAC-SHA512, 100 000 rounds, 32 bytes, via CommonCrypto. - [ ] `CipherWriter` / `CipherReader`: 16+16 cleartext header, 16-byte sacrificial block, AES-256-CBC no padding, streaming with partial block buffering (§2.3). Descriptions never include secrets. ## 3. session (core) — `Sources/MWBCore/Session.swift` - [ ] Sans-I/O state machine: `feed(bytes) -> [Event]`, `outgoing() -> Data`, `SocketStatus` NA…Connected (§3.2). - [ ] Handshake: 10× `Handshake`, nonce complement, `HandshakeAck`, adopt peer name/id, >10 untrusted packets ⇒ InvalidKey, self-connection close, >10 failures from one endpoint ⇒ give up (§3.2). - [ ] Dedup ring of 50 ids with the four exemptions (§1.4). - [ ] Heartbeat 60 s / 300 s, `Awake` vs `Heartbeat`, `Hi` counting, `ByeBye`, 25 min liveness; injected clock (§3.3). ## 4. matrix-edge (core) — `Sources/MWBCore/Matrix.swift`, `Edge.swift` - [ ] `Matrix` (4 slots, one/two rows, wrap), `MachinePool` (`Name:Id,…` serialisation, 25 min alive) §4.1. - [ ] `Matrix` packet encode/decode (slot in `Src`, flags in `Type`) §4.2; learning peers from Heartbeat/Hello/Awake. - [ ] `LiveMachineMatrix`, move left/right/up/down, `desMachineID`, ALL mode. - [ ] Edge detection §4.3 (primary-vs-desktop rectangle rule, 100 ms debounce, corner blocking) and coordinate normalisation §4.4 (all four rectangle cases, relative-move biases, `NextMachine`). ## 5. control-channel (net) — `Sources/MWBNet/ControlChannel.swift`, `Resolver.swift` - [ ] `NWListener` on port+1, both IP families; one `NWConnection` per non-local matrix name; 1 s retry for 30 s; one client socket per peer (§3.1). - [ ] `Resolver`: `getaddrinfo` + `Name2IP` lines; optional /16 and reverse-lookup checks (§7). - [ ] One `Session` + one cipher pair per connection; serialised sends with 500 ms timeout; 32-then-32 receive. - [ ] Reconnect on path change, wake, reset, hotkey; delete `Placeholder.swift`. ## 6. event-tap (mac) — `Sources/MWBMac/EventTap.swift`, `Permissions.swift`, `Sources/MWBCore/KeyMap.swift` - [ ] `Permissions.request…` added to the existing preflight file. - [ ] Session-level, head-insert, swallowing `CGEventTap` for keys, flags, mouse, scroll; enqueue and return; pass tagged injected events; re-enable on timeout/user-input disable (invariants 3, 4). - [ ] Modifier tracking and hotkey matching per §4.5 with D4 mapping (⌘=Win, ⌥=Alt); Easy Mouse modes. - [ ] `KeyMap`: macOS keycode ↔ Windows VK, `flagsChanged` → modifier VK pairs, `LLKHF` flags; `WM_*` mouse mapping, wheel ×120, X-buttons, absolute 0..65535 moves (§5). ## 7. screens-cursor (mac) — `Sources/MWBMac/Screens.swift`, `Cursor.swift` - [ ] Display list, primary, desktop union, corner points; refresh on screen-parameter change. - [ ] Park/hide cursor (primary centre-x, y=4), decouple cursor while controlling a remote, restore on return; `HideMouse (50)` (§5.3). ## 8. input-inject (mac) — `Sources/MWBMac/Injector.swift` - [ ] `Keyboard` packet → `CGEvent` down/up via KeyMap; modifiers as `flagsChanged`; repeat as repeated downs. - [ ] `Mouse` packet → absolute move (de-normalise onto desktop bounds §4.4), buttons with click-count, wheel (`WheelDelta`/120), X-buttons. - [ ] Injected-event tag; `ReleaseAllKeys` on switch/lock; remote Win+L → lock; remote Ctrl+Alt+Del → ignored. ## 9. menubar-app (app + core + mac) — `Sources/mwb/*`, `Sources/MWBMac/StatusItem.swift`, `Sources/MWBCore/Settings.swift` - [ ] `Settings`: PowerToys schema (README §Settings), load/save/watch, 0600, random key / `MachineID` / `DeviceID` on first run. - [ ] Menu-bar item with per-machine status dots in the documented colours; matrix editor; key entry; port; toggles; Reconnect; Quit. - [ ] Permissions onboarding; LaunchAgent install/uninstall; single instance; logs without key material. - [ ] Wire everything: tap → edge → session → channel → injector. - [ ] **Hand `dist/mwb.app` to the user** with a checklist: switch by edge and hotkey, wrap, one/two rows, keyboard with modifiers and function keys, wheel, reconnect after sleep, wrong key, peer killed mid-control. ## 10. clipboard-inband (core + mac) — `Sources/MWBCore/ClipboardCodec.swift`, `Sources/MWBMac/Pasteboard.swift` - [ ] Text codec `TXT`/`RTF`/`HTM` + SEP, UTF-16LE, raw DEFLATE (§6.1); confirm Foundation `.zlib` matches .NET `DeflateStream` by reasoning from the docs, note the decision. - [ ] 48-byte chunks at offset 16, `ClipboardDataEnd`, zero-padding semantics, 1 MB limit (§6.2); PNG images. - [ ] `NSPasteboard` polling (500 ms), 1 s suppression, write on receive, `ShareClipboard` flag. ## 11. clipboard-bulk (net) — `Sources/MWBNet/BulkChannel.swift` - [ ] Listener on port; `Clipboard (69)` broadcast; pull on `MachineSwitched`, push on `ClipboardAsk` (§6.3). - [ ] Bulk handshake, 1024-byte UTF-16LE `"*"` header, 1 MB chunks, 32-byte file padding, exact-length read, atomic commit to `~/Desktop/MouseWithoutBorders/`; 100 MB limit; `TransferFile` flag. ## 12. end-to-end polish - [ ] Driven entirely by the user's testing findings; each becomes a line here with the lane that owns the fix. ## 13. Later (post-v1) - [ ] Keychain storage for `SecurityKey` (D3). - [ ] Easy Mouse fullscreen suppression + excluded apps. - [ ] `Heartbeat_ex` key propagation (§3.3). - [ ] "Swap ⌘/⌃ when controlling Windows" option. - [ ] Non-US keyboard layouts: by position vs by character. - [ ] CI on the Gitea runner running `tools/gates.sh` (lint + build only). - [ ] Updates, notarization, Homebrew cask. ## 14. Out of scope, with reasons (D6) - Windows service / logon-screen / UAC secure-desktop control: the macOS login window cannot be driven from a user-session event tap. - Explorer drag-and-drop (§6.4): depends on a Windows-shell helper. - Screen capture to Paint: niche; packets ignored and logged. - GPO, telemetry, `ShowOriginalUI`: Windows-only. - Animated fake cursor (`DrawMouse`): cosmetic.