Ports InputSimulation.SendKey/SendMouse/InputProcessKeyEx and
InitAndCleanup.ReleaseAllKeys onto CGEvent posting: one tagged
hidSystemState source, held-key/button bookkeeping on the injector's
serial queue, click counting macOS needs and Windows drops, the
relative/absolute coordinate rules of Receiver.cs:147-153, and the
remote Win+L / Ctrl+Alt+Del interception.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Answers the four QA findings of 2026-09-16 by number, with what changed
and why, and records that the round was build-only: no tap created, no
`CGEvent` posted, no cursor moved, no permission requested.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 4: `ProcessHotKeys` never returns `false` for a matched
`HotKeySwitch2AllPC` (`InputHook.cs:518-522`) — unlike every other hotkey
branch it falls through, so a chord that does not itself hold Ctrl+Alt
toggles ALL mode and still reaches the OS. `HotkeyMatch` grows
`swallows`, true for every hotkey except that one when its configured
chord requires neither Ctrl nor Alt; `handleKey` then queues the action
and carries on encoding the key as an ordinary keystroke, which is what
`ProcessHotKeys` returning `true` leaves to `KeyboardEvent` and
`CallNextHookEx`. Documented in docs/protocol.md §4.5 and in the feature
README, including the residual narrowing (Windows also requires the VK to
land in the switch-machine range, `:611-620`). Unreachable today: the
shortcut ships empty (`MouseWithoutBordersProperties.cs:30`) and an empty
hotkey never matches (`Common.cs:127-129`).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 3: the Assumptions bullet claimed "three acquisitions per
event at most (snapshot, virtual cursor, counters)", which named neither
`Screens` nor `CaptureQueue` and undercounted every path. Replaced with
the four lock objects the callback can reach and the count on each of the
four paths — local key 2, local move 3-4, remote key 3, remote move 5-6 —
counted from the code, with the extras (unmapped key, hotkey, escape,
modifier transitions) spelled out.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 2: `screens.layout` (a locked read) was taken before the
destination branch, but only the remote branch uses it. The local branch
is what runs for essentially every mouse event while this Mac keeps its
own pointer, so it was paying for a lock acquisition it discarded
(invariant 4: minimum work on the local path). Moved inside the
`isRemote` branch, matching `handleScroll`, which already checked the
destination before reading the layout.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 1: `EventTap.thread` was a plain `var` read in `start()` and
written in both `start()` and `stop()`, while the class comment claimed
every cross-thread field was locked and `stop()` claimed to be safe from
any thread (the contracts-C2 signal-handler recovery calls it off the tap
thread). `runLoopLock` becomes `stateLock` and guards both fields;
`start()` claims the slot and tests it in one critical section so two
concurrent starts cannot both install a tap.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Verified every Status/TODO tick against InputHook.cs/Event.cs/VK.cs/WM.cs/
WinAPI.cs/Common.cs and docs/protocol.md §10.4, docs/contracts.md C2-C4.
Findings: EventTap.thread unguarded across start()/stop() despite the
class's own Sendable-safety claim; screens.layout fetched unconditionally
on the hot local-mouse-move path; README's lock-count claim undercounts
actual acquisitions; a disabled-by-default Switch2AllPC swallow quirk vs
Windows. No typos fixed (all findings need real changes).
Co-Authored-By: Claude Sonnet 5 <[email protected]>
In remote mode one physical move queues a .mouse and an .edgeCandidate,
so matching only the last entry meant the kinds alternated and motion was
never coalesced -- the ring would fill at two entries per move whenever
the Engine stalled, which is the case C3's coalescing exists to survive.
The scan stops at the first non-motion entry so transitions keep order.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
§10.4 records ten things the lane established from the Windows source
(one-sided hotkey matching, the three meanings of Md.WheelDelta, the
virtual cursor and its primary+-1 clamp, the unconditional relative bias,
SwitchLocation, synthesised LLKHF bits, the eleven ReleaseAllKeys VKs, the
two input counters, monitor enumeration) plus the macOS device masks. The
README's Assumptions and Handshakes now describe what shipped, with the
nine decisions and three deliberate non-ports in the work log.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Latest-wins is right for an absolute position and wrong for a
MOVE_MOUSE_RELATIVE delta, which would have silently dropped motion in
MoveMouseRelatively mode.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
EventTap is InputHook on CGEventTap: one dedicated run-loop thread, the
injected-event tag passed through, keys/modifiers/mouse/scroll encoded to
WM_*/LLKHF_*, the virtual cursor clamped to primary+-1 as InputHook does,
Easy Mouse gating on edge candidates, and tap-loss re-enabling the tap
AND routing local (C2). HotkeyMatcher ports ProcessHotKeys including the
500 ms double-press lock and the Shift/Win veto; Permissions gains
request() and the 5 s health check.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ScreenLayout is GetScreenConfig/MonitorEnumProc on CGDisplayBounds, with
the four corners BlockMouseAtScreenCorners needs, refreshed on
didChangeScreenParameters. Cursor is HideMouseCursor plus the macOS-only
decoupling that keeps the real pointer still while a peer is controlled.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
RoutingState holds the snapshot and the virtual cursor behind one
OSAllocatedUnfairLock so the tap callback can decide synchronously
(contracts C3); CaptureQueue is the 4096-entry ring with the C3
coalescing and overflow policy, plus notices that survive a full ring.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The shared vocabulary of the input path (contracts C3, C4): the injected
event tag, the WM_*/LLKHF_* numbers, the routing snapshot, CapturedInput,
the hotkey config with the PowerToys defaults, and the macOS keycode <->
Windows VK table with the NX device modifier masks.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Round-2 QA finding: the channel reset beatInputEventCount on its own
clock, out of phase with every connection's heartbeat instant, so a
session could send Heartbeat (20) where Windows sends Awake (21) — and
Awake is what drives the peer's Common.HumanBeingDetected()
(Receiver.cs:245-248), the default-on BlockScreenSaver mechanism.
Windows's beat is the send: SendAwakeBeat() compares
lastRealInputEventCount against Event.RealInputEventCount and re-records
it in the same call (Common.cs:542-559). So the comparison belongs at the
send. Session.tick(now:userActive:) becomes
Session.tick(now:inputEventCount:), taking the raw process-wide counter
(Event.cs:51-55, InputHook.cs:223, 345) and keeping its own
beatInputEventCount — Common.lastRealInputEventCount, Common.cs:543 —
recorded on both branches (:558).
ControlChannel loses lastBeatAt and beatInputEventCount entirely;
noteUserActivity() only increments the counter and tick() hands the same
value to every connection. No userActive-shaped name is left in Sources.
Sources/MWBCore/Session.swift is session-matrix's file, edited for this
fix with the lead's authorisation, as is that lane's Handshakes section.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Verified the rework against SocketStuff.cs, Common.cs, Event.cs and
InputHook.cs: finding 1 (Resolver two-group control flow) and finding 2
(id-collision gated to outbound) are both correctly fixed and cited, and
the literal ask for finding 3 (counter compare, not sliding window) is met.
But reading how ControlChannel's userActive is actually consumed by
Session.tick (Sources/MWBCore/Session.swift) turned up a new problem: the
channel's own beat-reset clock (ControlChannel.swift:457-471) is not
synchronized with any connection's actual heartbeat send, which is decided
independently by each Session's own nextHeartbeat. A connection can read
userActive == false at its own send instant even though real input happened
since its own previous heartbeat, silently downgrading Awake to Heartbeat
for that peer — in the default (blockScreenSaver = true) configuration.
Documented with a concrete timeline; verdict REWORK.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Dated 2026-09-16 work-log entry answering findings 1-3 by number plus the
CLAUDE.md re-read, and the Assumptions bullets the fixes changed (name
resolution per group, the client-only id collision, the userActive
counter rule).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Item 4 of the rework brief: re-read the four MWBNet files against
CLAUDE.md. Sizes (189/234/356/524), function lengths, layering, the
one-sentence responsibility test, no force-unwrap/try!/fatalError/
precondition, no logging of any kind and no packet interpretation all
hold; `swift-format format -i` is a no-op on all four. Three citations
were off and are corrected against the source:
- `Common.SendByeBye` is Common.cs:611-615, not 612-616 (ControlChannel,
PeerConnection).
- `SkSend`'s stamp-and-fan-out is Common.cs:916-930, and the
`Des == ID.ALL` matrix test is :922-930, not :912-930 / :919-929.
`DisconnectReason.idCollision` and `channelDetectedIDCollision` now say
in their doc comments what the previous commit made true in the code:
the collision is looked for on outbound connections only
(SocketStuff.cs:1980-1992).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 3. `tick` computed `userActive` as "input within the last
heartbeat interval". `SendAwakeBeat` instead sends `Awake` when
`lastRealInputEventCount != Event.RealInputEventCount` — real input since
the previous heartbeat — and re-records the counter every time it runs
(Common.cs:545-558). Keep the same two counters: `noteUserActivity()` is
`Event.RealInputEventCount++` (InputHook.cs:223, 345) and the channel
re-records on its own heartbeat boundary, which is the one global beat
Windows's 100 ms timer runs for every socket (frmScreen.cs:565-575).
Also fixes the stale citation for this rule in docs/protocol.md §3.3,
which pointed at SendHeartBeat/screen-capture code (Common.cs:499-513,
662-676) instead of SendAwakeBeat.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 2. The id check ran for every connection that finished its
handshake, so an inbound peer announcing our own id could force-close
every socket and make the app draw a new machine id. Windows runs the id
comparison and the keep-the-first-client rule as two branches of one
block gated by `status == Connected && tcp.IsClient`
(SocketStuff.cs:1980-1981): a server-accepted socket reaches neither.
Move the collision check inside the `isOutbound` gate the dedup half
already had, and say so in the README and docs/protocol.md §10.3 note 3.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 1. `Resolver.addresses` applied one same-subnet check to the
union of the Name2IP mappings and the DNS results. `StartNewTcpClient`
checks each group on its own: the mapped group's failure is a `return`
that skips `Dns.GetHostEntry` entirely (SocketStuff.cs:934-937, 950), so
nothing is dialled for that name that round; the DNS group's failure
(:1037-1040) drops only the DNS addresses, because the mapped ones have
already been dialled (:941). Port that control flow, and document it in
the feature README's Assumptions and docs/protocol.md §10.3 note 6.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Verified gates, TODO ticks against SocketStuff.cs, C1-C4 compliance,
Sendable justification and no key/packet logging. Two undocumented
behavioural deviations from Windows found by line-by-line comparison:
Resolver.addresses merges the Name2IP/DNS same-subnet checks instead of
running them separately (and misses Windows's early return when the
Name2IP group fails its check), and ControlChannel detects machine-id
collision on inbound connections too where Windows gates that on
IsClient. A third, minor, doc-only note on the userActive heuristic.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Verified the rework against the reference checkout at 3104d5c: read-error
counting now matches SocketStuff.cs:1330-1529/1531, Switcher.learn persists
only on a new machine (MachineStuff.cs:737/755), parkCursor carries the
HideMouseCursor gate (Common.cs:1488, MachineStuff.cs:1025), and contract
C1's forward(_:)-only stamping matches SkSend (Common.cs:901-935). Fixed a
trivially wrong citation in protocol.md §10.2 note 11 (Common.cs:914 ->
916, the actual PackageID increment line). tools/gates.sh green.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Re-read all seven files: no force-unwrap, try!, fatalError or
precondition; longest file 422 lines (Session.swift), longest function 26
(countUntrusted); nothing logs. Corrected four SocketStuff.cs citations
that were off by one or two against the reference checkout (:1390->:1389,
:1441->:1439, the untrusted branch :1386-1500 -> :1387-1529).
`xcrun swift-format format -i --recursive Sources Package.swift` made no
further changes; tools/gates.sh green.
Work log gains a dated rework entry answering QA findings 1-3 and
contract C1 by number.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Session.send(_:) is gone as a public entry point. Application traffic gets
its Id once from the process-wide PacketSequencer and reaches each target
connection through forward(_:), which never re-stamps; the per-connection
stamp survives only as `private func originate(_:)` for the packets
Windows also sends per connection — the handshake pair, heartbeats, Hi and
ByeBye. Nothing outside the type can now sequence an application packet.
README Assumptions and Handshakes say this is API-enforced rather than a
convention. protocol.md gains §10.2 note 11: SkSend increments PackageID
once before the socket loop (Common.cs:914) and hands the same DATA to
every matching socket, which is exactly what makes the receiver's 50-entry
replay ring collapse a peer pair's duplicate delivery.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 3. HideMouseCursor moves the real cursor only when
(desMachineID != MachineID && desMachineID != ID.ALL) || byHideMouseMessage
(Common.cs:1488), and SwitchToMachine calls it after setting DesMachineID
(MachineStuff.cs:1025) — so control coming home parks nothing. The action
is now .parkCursor(destinationIsRemote:byHideMouseMessage:), both halves
of that gate pre-evaluated by Switcher (new .destinationIsRemote), so
input-inject can implement it without reading the Windows source. Spelled
out as a consumer rule in the README's Handshakes.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 2. AddToMachinePool returns inside the TryFindMachineByName
branch (MachineStuff.cs:737), before the UpdateMachinePoolStringSetting()
at :755 — which is reachable only from the fall-through "new machine"
path. Switcher.learn was returning [.persistMachinePool] from the known
branch too, asking the app to write MachinePool to disk on every
heartbeat cadence tick from every already-known peer. It now returns [].
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
QA finding 1. TcpReceiveData does not signal a bad read out of band: it
rewrites the buffer's type byte to PackageType.Error (0 bytes) or
PackageType.Invalid (short read) (SocketStuff.cs:574-578, 588-593) and
MainTCPRoutine runs that package through the whole loop body — the
private errCount for the Error case (:1332-1364), then the same untrusted
counting as any garbage packet (:1370-1529). So a run of malformed reads
ends in .invalidKey, not .error, and the trusted branch's
`receivedCount > 0` guard (:1531) keeps a 0-byte read out of the receiver.
Session.noteReceiveError now takes the byte count and feeds a synthetic
.error/.invalid packet through the new receive(_:bytesReceived:), which
is the loop body; feed() goes through it too. Written up as protocol
§10.2 note 10 and in the README's Assumptions.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Written after an external review of the plan found cross-module
behaviour under-specified. TODO, topo, loop and the session-matrix
brief now reference docs/contracts.md.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Verified handshake/trust gate, dedup ring, one-row/two-row neighbour
search, matrix packet encoding, edge/landing geometry and the relative
and pixel biases against the Windows source; all faithful. Three
findings: the 10-untrusted-packets rule doesn't count read errors like
Windows does, Switcher.learn persists the pool on every known-peer
heartbeat, and SwitchAction.parkCursor doesn't carry enough information
for a future consumer to replicate HideMouseCursor's real-cursor-move
gating without rereading the Windows source.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Verdict: PASS. Checked every PackageType value, byte offset, the
checksum range, the magic-hash shift/overflow expression, PBKDF2
parameters and the 48-byte stream preamble against the Windows source
directly, and re-derived the documented magic-number and PBKDF2
examples independently in Python. No findings beyond the hex-gloss typo
already fixed in the prior commit.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
334517251 decimal is 0x13F0_5403, not 0x13EC_4F03; the decimal value
(independently re-verified against a Python SHA-512 chain) was already
correct, only the hex gloss was wrong.