diff --git a/TODO.md b/TODO.md index 9526360..c9ff408 100644 --- a/TODO.md +++ b/TODO.md @@ -163,10 +163,11 @@ concurrency, shared constants, checkpoints) is fixed in `docs/contracts.md`. - [x] Status messages (`ShowClipboardAndNetworkStatusMessages`) via `UserNotifications`: connected / lost / wrong key, gated on the setting and on the process having a bundle identifier. -- [ ] **Checkpoint CP1 (contracts C5)**: hand `dist/mwb.app` to the user - with the checklist: switch by edge and hotkey, wrap, one/two rows, - keyboard with modifiers and function keys, wheel, reconnect after - sleep, wrong key, and every C2 recovery row. +- [x] **Checkpoint CP1 (contracts C5)**: `dist/mwb.app` handed to the + user 2026-09-16 with the checklist: switch by edge and hotkey, + wrap, one/two rows, keyboard with modifiers and function keys, + wheel, reconnect after sleep, wrong key, and every C2 recovery + row. Findings land in §10. ## 8. clipboard (core + net + mac) — `Sources/MWBCore/ClipboardCodec.swift`, `Sources/MWBMac/Pasteboard.swift`, `Sources/MWBNet/BulkChannel.swift`, `Sources/MWBMac/ReceivedFile.swift` @@ -194,7 +195,8 @@ concurrency, shared constants, checkpoints) is fixed in `docs/contracts.md`. `EasyMouseFullscreenSwitchBlockExcludedApps`: frontmost app via `NSWorkspace`, fullscreen via the Accessibility API; excluded-apps editor in the settings window. -- [ ] `DrawMouseCursor` / `DrawMouseEx`: a borderless transparent overlay +- [ ] `Settings.drawMouseCursor` accessor + the Behaviour-pane toggle + (app-ui's open request), then `DrawMouseCursor` / `DrawMouseEx`: a borderless transparent overlay window drawing a cursor image where the remote pointer is, so the user sees where the pointer went (Windows `CustomCursor.cs`). - [ ] `BlockMouseAtScreenCorners` end-to-end; `MoveMouseRelatively` @@ -205,6 +207,9 @@ concurrency, shared constants, checkpoints) is fixed in `docs/contracts.md`. - [ ] Each finding from the user becomes a line here with the file that owns the fix. +- [ ] `Engine`↔`UIBridge` strong cycle (`AppLifecycle.swift`, + `UIBridge.swift`): make one side weak before any second pair can + exist (QA, app-ui). ## Later (post-v1) diff --git a/docs/features/app-ui/README.md b/docs/features/app-ui/README.md index 382cfab..252c8e0 100644 --- a/docs/features/app-ui/README.md +++ b/docs/features/app-ui/README.md @@ -503,3 +503,16 @@ Five deviations from the shape this section sketched at planning time: Verdict: PASS ## Review + +- 2026-09-16 (lead): inspected per `docs/loop.md` §5. Gates and an + ad-hoc bundle green, run by me; diff limited to the brief's files, the + authorised status-item parts of `AppLifecycle.swift`, one Info.plist + key, TODO §7. QA verified every §Settings property has a control (bar + `DrawMouseCursor`, deferred to extras with its accessor), the colour + table, the recorder mapping, the single `Permissions.request()` call + site and the absence of key logging. The strong `Engine`↔`UIBridge` + cycle QA noted is accepted for a process-lifetime pair; noted in TODO + §10. Verdict: **merge**. **CP1 is now due**: `dist/mwb.app` built + ad-hoc; the user signs with their own identity for TCC persistence, + grants Accessibility and Input Monitoring, and runs the C5 checklist. + Nothing from `NSApplication.run()` inwards has ever executed. diff --git a/docs/features/clipboard/README.md b/docs/features/clipboard/README.md new file mode 100644 index 0000000..01d74be --- /dev/null +++ b/docs/features/clipboard/README.md @@ -0,0 +1,135 @@ +# clipboard + +## Goal + +Clipboard sharing as PowerToys does it (`docs/protocol.md` §6): text in +its three flavours, PNG images and single files, sent in-band over the +control channel when small and over the separate bulk connection on +port 15100 when large, pulled by the machine the user switches to or +pushed on request; received files land in `~/Desktop/MouseWithoutBorders/` +exactly as on Windows. `ShareClipboard` and `TransferFile` gate it. +This lane ends at **CP2**. + +## Assumptions + +- **Formats** (`Helper/FormHelper.cs:180-218, 269-330`, `Clipboard.cs: + 1148-1194`): text is `"TXT"+plain+SEP+"RTF"+rtf+SEP+"HTM"+html+SEP` + in UTF-16LE, raw-DEFLATE compressed (`Clipboard.cs:190-201`). The + HTML flavour on Windows is **CF_HTML** (the `Version:…StartHTML:…` + header block, `DataFormats.Html`); on receive we strip that header to + the fragment before writing `NSPasteboard.PasteboardType.html`, and + on send we wrap our HTML in a CF_HTML header with correct byte + offsets. Images are PNG bytes (`FormHelper.cs:281`); `NSPasteboard` + `.png` if present, else `.tiff` re-encoded via `NSBitmapImageRep`. + Files: exactly one `fileURL`; a directory is refused with the Windows + message (`SocketStuff.cs:1693`). +- **Foundation's `.zlib` algorithm is raw DEFLATE** (no zlib header), + the same stream .NET `DeflateStream` writes. The Dev confirms this + once in the scratchpad against Python `zlib.decompress(d, -15)` and + records the result in §10.7; if it is not, `compression_stream` with + `COMPRESSION_ZLIB` is used instead. +- **Small payloads** (≤ 1 MB after compression, `Clipboard.cs:43`) go + in-band: 64-byte `ClipboardText (124)` / `ClipboardImage (125)` + packets with 48 payload bytes at offset 16, `Des = ALL`, terminated by + `ClipboardDataEnd (76)`, last chunk zero-padded with no length field + (`Clipboard.cs:253-306`). They are app-stamped and forwarded (C1). + The receiver keeps one `Reassembler` per sender: appends chunks, + finishes on `ClipboardDataEnd`, aborts after 100 interleaved foreign + packets (`:308-373`); trailing zeros are part of the DEFLATE stream + and the decoder tolerates them. +- **Big payloads and files** (`Clipboard.cs:498-923, 961-1060`, + `SocketStuff.cs:1673-1811`): on a local copy that is too big, or any + file, the machine broadcasts `Clipboard (69)` ("I have big data") and + remembers `clipboardCopiedTime` (30 s window, `Clipboard.cs:42`). + When a peer is switched *to* (`MachineSwitched (77)`, `Receiver.cs: + 284-291`, `Event.cs:219-231`) and the source has fresh big data, the + peer **pulls**: it connects to the source's port 15100, both sides + exchange the cipher preamble (§2.3) and one 64-byte `DATA` + (`Clipboard (69)` from the puller, checked with + `MachinePool.resolveID(name) == Src` and connected, `:1009`), then the + source writes the 1024-byte UTF-16LE header `"*"` and the + bytes in 1 MB chunks, files padded to 32 bytes; the puller reads + exactly `len`. If the puller has no outbound client to the source it + asks with `ClipboardAsk (78)` and the source **pushes** (`ClipboardPush + (79)` as the first `DATA`). Whether the 64-byte `DATA` on the bulk + connection is framed with checksum/magic (§1.3) is decided by reading + `Clipboard.ShakeHand` and recorded in §10.7. +- **Destination**: `~/Desktop/MouseWithoutBorders/` + (`Common.cs:1291-1330`), written to a temp file in the same directory + and renamed into place; incomplete transfers deleted, an existing + destination kept until success (`ReceivedDestinationFile.cs`). Files + > 100 MB refused with the Windows message (`Clipboard.cs:44`). After a + file lands the folder is revealed in Finder (`Clipboard.cs:840-848`). + Received text/image is written to `NSPasteboard.general` and the + resulting `changeCount` remembered so it is not re-shared. +- **Pasteboard watching**: poll `changeCount` every 500 ms on a + background queue; ignore changes within 1 s of the previous one + (`Clipboard.cs:100-107`); ignore our own writes; only when + `ShareClipboard` is on; files only when `TransferFile` is on. +- **Ownership**: the bulk listener/connections live in `MWBNet/BulkChannel` + on their own queue and report through a small sink; the policy (who + has big data, when to pull/push/ask, the 30 s window) lives in + `mwb/ClipboardBridge.swift`, driven by the Engine's `.packet` events. + The Engine's `dispatch` gains one line per clipboard packet type that + hands the packet to the bridge (authorised edit of `Engine.swift`, + those cases only). `PostAction` values (`ClipboardPostAction.cs`): + `Desktop` → file to the Desktop folder; `Mspaint` → out of scope. +- **Never act before trust**: bulk connections are accepted only from + a `Src` that resolves to a connected, trusted peer; everything else + is closed without reading a payload (invariant 2). + +## Handshakes + +### Consumed + +- `wire-core`: `Packet.payload48`, `CipherWriter`/`CipherReader`, `MagicHash`. +- `session-matrix`: `MachinePool.resolveID`, `Switcher` state via the Engine. +- `control-channel`: `ControlChannel.forward` (in-band chunks), `PeerStatus`. +- `app-engine`: `Engine` `.packet` dispatch hook, `Settings.shareClipboard/transferFile/tcpPort`. + +### Promised (to extras, polish) + +```swift +// MWBCore/ClipboardCodec.swift +public struct ClipboardText: Sendable { plain: String?; rtf: Data?; html: String? } +public enum ClipboardContent: Sendable { text(ClipboardText); image(png: Data); file(URL) } +public enum ClipboardCodec { encodeText(_:) throws -> Data; decodeText(_:) throws -> ClipboardText; cfHTML(wrap:) / cfHTML(unwrap:); chunkPackets(payload:type:) -> [Packet]; } +public final class Reassembler { func feed(_ p: Packet) -> Data? /* complete payload */; var abandoned: Bool } +// MWBMac/Pasteboard.swift +public final class PasteboardWatcher { init(onChange: @escaping @Sendable (ClipboardContent) -> Void); start(); stop(); func write(_:) } +// MWBMac/ReceivedFile.swift +public enum ReceivedFile { static func destinationDirectory() throws -> URL; static func stage(name:) throws -> StagedFile; StagedFile.commit()/discard() } +// MWBNet/BulkChannel.swift +public final class BulkChannel { init(config: ChannelConfig, sink: BulkSink); start(); stop(); func serve(_ content: ClipboardContent, until: TimeInterval); func pull(from address: String, peerID:, peerName:) ; func push(_ content:, to address:) } +public protocol BulkSink: AnyObject, Sendable { received(_ content: ClipboardContent, from peerID: UInt32); isTrusted(peerName:peerID:) -> Bool; failed(reason: String) } +``` + +## Status / TODO + +- [ ] `Sources/MWBCore/ClipboardCodec.swift`: tag/SEP text codec, + UTF-16LE, DEFLATE (verified raw), CF_HTML wrap/unwrap, 48-byte + chunking, `Reassembler` (`Clipboard.cs:43-47, 190-201, 253-373, + 1148-1194`, `FormHelper.cs:180-330`). +- [ ] `Sources/MWBMac/Pasteboard.swift`: watcher and writer per + Assumptions (`Clipboard.cs:100-107`, `FormHelper.cs`). +- [ ] `Sources/MWBMac/ReceivedFile.swift`: staging + atomic commit + + reveal (`ReceivedDestinationFile.cs`, `Common.cs:1291-1330`, + `Clipboard.cs:669-711, 840-848, 943-959`). +- [ ] `Sources/MWBNet/BulkChannel.swift` (+ `BulkConnection.swift` if + needed): listener on port, pull/push connections, preamble, the + 64-byte `DATA` exchange, 1024-byte header, chunked body, trust + gate (`Clipboard.cs:425-449, 498-923, 961-1060`, `SocketStuff.cs: + 1673-1811, 1832-1836`). +- [ ] `Sources/mwb/ClipboardBridge.swift`: policy (small → in-band, + big/file → `Clipboard (69)` + serve; on `MachineSwitched` pull or + `ClipboardAsk`; 30 s window; `ShareClipboard`/`TransferFile`); + `Engine.swift` dispatch hooks (authorised). +- [ ] `docs/protocol.md`: append §10.7 (DEFLATE check, bulk `DATA` + framing answer, CF_HTML), cited. +- [ ] **Checkpoint CP2** is the lead's after merge. + +## Work log + +## QA log + +## Review diff --git a/docs/loop.md b/docs/loop.md index fef5967..38d0c5e 100644 --- a/docs/loop.md +++ b/docs/loop.md @@ -158,8 +158,8 @@ Strictly one at a time, in this order (mirrors `TODO.md`): | 4 | input-capture | merged 2026-09-16 (one rework) | | 5 | input-inject | merged 2026-09-16 (one rework) | | 6 | app-engine | merged 2026-09-16 (one rework) | -| 7 | app-ui | in progress — ends at **CP1** (contracts C5) | -| 8 | clipboard | **CP2** | +| 7 | app-ui | merged 2026-09-16 — **CP1 handed to the user** | +| 8 | clipboard | in progress — **CP2** | | 9 | extras | **CP3** | | 10 | polish | driven by the checkpoints' findings | @@ -175,6 +175,10 @@ Strictly one at a time, in this order (mirrors `TODO.md`): ## 8. Lane log +- **2026-09-16, lane 7 (app-ui)** — Dev (Opus), QA (Sonnet) PASS with + one low finding (a process-lifetime retain cycle), lead merge. First + lane with no rework. CP1 handed to the user the same day; the lead + continues with clipboard and extras while CP1 findings come in. - **2026-09-16, lane 6 (app-engine)** — Dev (Opus), QA (Sonnet) REWORK (settings file mode inherited from a copied-in file; key release missing on two switch-home paths; `ByeBye` on the signal