input-inject: close lane (lead review); split app-shell into app-engine + app-ui; brief: app-engine
Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
c7d294a7a3
commit
ca9be2eb16
6 files changed
+225
-33
No files matched your search
@@ -116,38 +116,56 @@ concurrency, shared constants, checkpoints) is fixed in `docs/contracts.md`.
|
||||
*(`releaseAll()` and `lockThisMac()` are published; calling them on
|
||||
each recovery row is app-shell's wiring — see the lane's Handshakes.)*
|
||||
|
||||
## 6. app-shell (app + core + mac) — `Sources/mwb/*`, `Sources/MWBCore/Settings.swift`, `Sources/MWBMac/StatusItem.swift`, `Sources/MWBMac/SettingsWindow/*.swift`, `Sources/MWBMac/Notifications.swift`
|
||||
## 6. app-engine (app + core) — `Sources/mwb/main.swift`, `Sources/mwb/Engine.swift`, `Sources/mwb/EngineActions.swift`, `Sources/mwb/Recovery.swift`, `Sources/mwb/AppLifecycle.swift`, `Sources/MWBCore/Settings.swift`, `Sources/MWBMac/Log.swift`
|
||||
|
||||
- [ ] `Settings`: PowerToys schema (README §Settings), JSON load/save at
|
||||
`~/Library/Application Support/mwb-mac/settings.json` (0600),
|
||||
file watch, random key / `MachineID` / `DeviceID` on first run,
|
||||
`LastX/LastY/PackageID` persistence.
|
||||
`LastX/LastY/PackageID` persistence, hostname validation (D7);
|
||||
mapping to `SessionConfig`/`ChannelConfig`/`EdgeConfig`/
|
||||
`CaptureConfig`/`InjectorConfig` (C4).
|
||||
- [ ] The `Engine` actor (C3): owns Switcher, sequencer, replay filter,
|
||||
channel, tap, routing state, capture queue, injector, cursor,
|
||||
screens; publishes the routing snapshot; drains the capture ring;
|
||||
stamps ids once and forwards to every target (C1); dispatches
|
||||
`.packet` events to injector / switcher; applies every
|
||||
`SwitchAction`.
|
||||
- [ ] Recovery wiring (C2): every trigger row end-to-end — escape
|
||||
hotkeys, controlled-peer disconnect, 30 s silence, outbound stall,
|
||||
tap disable, permission loss, quit/crash handler — each ending in
|
||||
route-local + `releaseAll` + `Cursor.recouple`.
|
||||
- [ ] Open requests from lanes 3–5: reopen countdown while nothing is
|
||||
connected; `markControlled` on every switch; `EventTap.now()`
|
||||
timestamps; swallow flags (false in ALL mode); lock chord
|
||||
forwarding; layout into every `inject`; `HotKeyLockMachine` →
|
||||
`InjectorConfig`; `Screens.startObserving()` on main; `canInject`.
|
||||
- [ ] `mwb` runs as an `NSApplication` (LSUIElement) with a minimal
|
||||
status item showing only "mwb: running / permissions missing"
|
||||
and Quit — enough to run headless for CP0 smoke by the lead; the
|
||||
real UI is lane 7. `mwb --check-permissions` kept. Single
|
||||
instance; file log at `~/Library/Logs/mwb-mac/` without key
|
||||
material.
|
||||
|
||||
## 7. app-ui (mac) — `Sources/MWBMac/StatusItem.swift`, `Sources/MWBMac/SettingsWindow/*.swift`, `Sources/MWBMac/Notifications.swift`, `Sources/MWBMac/LaunchAgent.swift`, `Sources/mwb/UIBridge.swift`
|
||||
|
||||
- [ ] Menu-bar `NSStatusItem`: per-machine status dot in the documented
|
||||
colours (`doc/devdocs/modules/mousewithoutborders.md`), current
|
||||
controlled machine, Reconnect, Easy Mouse toggle, Lock all, Open
|
||||
Settings, Quit.
|
||||
- [ ] Settings window (SwiftUI): machine matrix editor (4 slots,
|
||||
drag-reorder, one/two rows), security key (show/generate/copy),
|
||||
port, every boolean in README §Settings, Easy Mouse picker, hotkey
|
||||
recorders, Name2IP editor, permissions status with "Open System
|
||||
Settings" buttons, LaunchAgent toggle.
|
||||
- [ ] Settings window (SwiftUI in an `NSHostingView`): machine matrix
|
||||
editor (4 slots, reorder, one/two rows), security key
|
||||
(show/generate/copy), port, every boolean in README §Settings,
|
||||
Easy Mouse picker, hotkey recorders, Name2IP editor, permissions
|
||||
status with "Open System Settings" buttons, LaunchAgent toggle
|
||||
(`SMAppService.mainApp`).
|
||||
- [ ] Status messages (`ShowClipboardAndNetworkStatusMessages`) via
|
||||
`UserNotifications`.
|
||||
- [ ] The `Engine` actor (C3): owns Switcher, sequencer, replay filter,
|
||||
connections, held-key state; publishes the routing snapshot; drains
|
||||
the capture ring (coalescing motion); stamps ids once and forwards
|
||||
to every target session (C1); dispatches `.packet` events.
|
||||
- [ ] Recovery wiring (C2): every trigger row implemented end-to-end —
|
||||
escape hotkeys, controlled-peer disconnect, 30 s silence while
|
||||
sending input, outbound stall, tap disable, permission loss,
|
||||
quit/crash handler.
|
||||
- [ ] Single instance; logs at `~/Library/Logs/mwb-mac/` without key material.
|
||||
- [ ] **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.
|
||||
|
||||
## 7. clipboard (core + net + mac) — `Sources/MWBCore/ClipboardCodec.swift`, `Sources/MWBMac/Pasteboard.swift`, `Sources/MWBNet/BulkChannel.swift`, `Sources/MWBMac/ReceivedFile.swift`
|
||||
## 8. clipboard (core + net + mac) — `Sources/MWBCore/ClipboardCodec.swift`, `Sources/MWBMac/Pasteboard.swift`, `Sources/MWBNet/BulkChannel.swift`, `Sources/MWBMac/ReceivedFile.swift`
|
||||
|
||||
- [ ] Text codec `TXT`/`RTF`/`HTM` + SEP, UTF-16LE, raw DEFLATE §6.1
|
||||
(Foundation `.zlib` is raw DEFLATE like .NET `DeflateStream`; say so);
|
||||
@@ -164,7 +182,7 @@ concurrency, shared constants, checkpoints) is fixed in `docs/contracts.md`.
|
||||
receive (text/RTF/HTML/PNG/file URL), `ShareClipboard` flag.
|
||||
- [ ] **Checkpoint CP2** (C5): clipboard both ways, in-band and bulk.
|
||||
|
||||
## 8. extras (mac + core) — `Sources/MWBMac/Awake.swift`, `Sources/MWBMac/Fullscreen.swift`, `Sources/MWBMac/FakeCursor.swift`
|
||||
## 9. extras (mac + core) — `Sources/MWBMac/Awake.swift`, `Sources/MWBMac/Fullscreen.swift`, `Sources/MWBMac/FakeCursor.swift`
|
||||
|
||||
- [ ] `BlockScreenSaverOnOtherMachines`: hold an `IOPMAssertion`
|
||||
(`PreventUserIdleDisplaySleep`) while `Awake` packets arrive within
|
||||
@@ -180,7 +198,7 @@ concurrency, shared constants, checkpoints) is fixed in `docs/contracts.md`.
|
||||
end-to-end with `NextMachine` §4.4.
|
||||
- [ ] **Checkpoint CP3** (C5).
|
||||
|
||||
## 9. polish — driven by the user's testing
|
||||
## 10. polish — driven by the user's testing
|
||||
|
||||
- [ ] Each finding from the user becomes a line here with the file that
|
||||
owns the fix.
|
||||
|
||||
+4
-4
@@ -105,7 +105,7 @@ and the findings become `TODO.md` lines for the next lane.
|
||||
|
||||
| after lane | checkpoint |
|
||||
|---|---|
|
||||
| 6 app-shell | **CP1** — menu bar, settings window, keyboard and mouse across two Macs and Mac ↔ Windows, every recovery row in C2 |
|
||||
| 7 clipboard | **CP2** — text/RTF/HTML/image/file both ways, in-band and bulk |
|
||||
| 8 extras | **CP3** — screensaver blocking, fullscreen rule, drawn cursor, corners, relative mode |
|
||||
| 9 polish | continuous, one checkpoint per batch of fixes |
|
||||
| 7 app-ui | **CP1** — menu bar, settings window, keyboard and mouse across two Macs and Mac ↔ Windows, every recovery row in C2 |
|
||||
| 8 clipboard | **CP2** — text/RTF/HTML/image/file both ways, in-band and bulk |
|
||||
| 9 extras | **CP3** — screensaver blocking, fullscreen rule, drawn cursor, corners, relative mode |
|
||||
| 10 polish | continuous, one checkpoint per batch of fixes |
|
||||
@@ -0,0 +1,152 @@
|
||||
# app-engine
|
||||
|
||||
## Goal
|
||||
|
||||
The part of the app that makes the pieces a running program: the
|
||||
`Engine` actor that contracts C1–C3 name as the owner of all shared
|
||||
state, the `Settings` model in the PowerToys schema, the mapping from
|
||||
settings to every lane's config struct (C4), the wiring
|
||||
tap → edge → switcher → channel → injector, and every recovery row of
|
||||
C2 implemented end-to-end. It ships `mwb` as a real `NSApplication`
|
||||
(LSUIElement) with a placeholder status item — just enough to run —
|
||||
so the lead can smoke it headless before the `app-ui` lane builds the
|
||||
real menu and settings window. This is the lane that finally answers
|
||||
the open requests lanes 3, 4 and 5 left for "app-shell".
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **`Engine` is one `actor` in the `mwb` target.** It owns: `Switcher`,
|
||||
`PacketSequencer`, `ReplayFilter`, `ControlChannel`, `EventTap`,
|
||||
`RoutingState`, `CaptureQueue`, `Injector`, `Cursor`, `Screens`,
|
||||
`Settings`. Nothing else holds a reference to those except through
|
||||
the Engine. The `EngineSink` implementation is a small
|
||||
`final class` that hops into the actor with `Task { await engine.… }`
|
||||
— ordering between hops is preserved by a single `AsyncStream` of
|
||||
sink events that the actor consumes in order, not by independent
|
||||
`Task`s.
|
||||
- **Draining the capture ring**: `EventTap`'s `onWake` closure resumes
|
||||
an `AsyncStream` continuation; the actor's drain loop `for await`s it
|
||||
and calls `queue.drain()`, handling each `CapturedInput` in order:
|
||||
`.edgeCandidate` → `switcher.crossing(...)` timestamped with
|
||||
`EventTap.now()` (input-capture request); `.key`/`.mouse` → stamp once
|
||||
with the sequencer, `channel.forward(packet, to: .peer(desMachineID))`
|
||||
or `.all` in ALL mode (C1); `.hotkey` → the actions below;
|
||||
`.tapLost`/`.overflow`/`.escapedToLocal` → the recovery routine.
|
||||
- **`SwitchAction` dispatch** (`EngineActions.swift`) is the port of what
|
||||
`MachineStuff.SwitchToMachine` / `Helper.HelperThread` / `Event.cs`
|
||||
do around a switch: `.send(packet)` → stamp + forward; `.parkCursor`
|
||||
→ `Cursor.park` per the consumer rule (move only when
|
||||
`destinationIsRemote || byHideMouseMessage`); routing snapshot
|
||||
rewritten with `destination`, `swallowKeys`/`swallowMouse` = remote
|
||||
and not ALL mode (input-capture request), `easyMouse`, hotkeys;
|
||||
`channel.markControlled(peerID:)` on **every** switch including back
|
||||
to local (control-channel request); `injector.releaseAll()` on every
|
||||
switch/lock/mode change (`MachineStuff.cs:1025`,
|
||||
`InitAndCleanup.cs:214-243`); `.persist` → save settings.
|
||||
- **Hotkeys**: `.switchMachine(slot)` → `switcher.switchToSlot`;
|
||||
`.lockMachine` → forward `Injector.lockChord(for:)` to the controlled
|
||||
peer as sequenced `Keyboard` packets (input-inject request), then lock
|
||||
locally when the double-press rule says ALL (`InputHook.cs:539-577`);
|
||||
`.reconnect` → `channel.reopenAll()`; `.toggleEasyMouse` → flip the
|
||||
setting, save, rewrite the snapshot; `.switchToAll` → ALL mode.
|
||||
- **Recovery** (`Recovery.swift`, C2): one `recoverLocal(reason:)` on the
|
||||
actor that routes local in `Switcher`, rewrites the snapshot, calls
|
||||
`injector.releaseAll()`, `cursor.recouple(to: lastLocal)`,
|
||||
`channel.markControlled(nil)` and logs the reason. Called from: escape
|
||||
hotkeys (the tap already flipped the snapshot; the actor finishes the
|
||||
job), `.tapLost`, `.overflow`, channel `disconnected` for the
|
||||
controlled peer (any reason), `Permissions` health-check loss, and the
|
||||
quit/crash path. The quit/crash path is `AppLifecycle.swift`:
|
||||
`applicationWillTerminate`, plus `signal(SIGTERM/SIGINT/SIGHUP)` and
|
||||
`atexit` handlers that call the injector's `releaseAll()` and
|
||||
`Cursor.recouple` **synchronously without the actor** (they cannot
|
||||
await) — both are documented as safe from any thread — and send
|
||||
`ByeBye` via `channel.sayGoodbye()` best-effort.
|
||||
- **Reopen countdown** (control-channel request, `frmScreen.cs:427-461`):
|
||||
the actor keeps a 1 s timer; while any matrix name has no connected
|
||||
client, every 10 s it calls `channel.reopenAll()`; on wake
|
||||
(`NSWorkspace.didWakeNotification`) and screen change immediately.
|
||||
- **`Settings`** (`MWBCore/Settings.swift`): a `Codable` struct with the
|
||||
exact PowerToys property names, types and defaults from README
|
||||
§Settings, wrapped in `{"name":"MouseWithoutBorders","version":"1.1",
|
||||
"properties":{…}}`; unknown keys preserved on save (decode into a
|
||||
dictionary, overlay known keys). Stored at
|
||||
`~/Library/Application Support/mwb-mac/settings.json`, mode 0600,
|
||||
written atomically (temp + rename). First run generates
|
||||
`SecurityKey` (`SecurityKey.random()`), `MachineID` (random positive
|
||||
`Int32`, `Setting.cs:1048-1083`), `DeviceID` (UUID).
|
||||
`PackageID` is written from `sequencer.current` on save and on quit
|
||||
(`Common.cs:906`). `MachineMatrixString` / `MachinePool` round-trip
|
||||
through `Matrix(string:)` / `MachinePool(string:)`. A
|
||||
`DispatchSource` file watcher reloads on external change
|
||||
(`Setting.cs:197-207`); a change of key, port or matrix triggers
|
||||
`channel.reconfigure`; others rewrite the snapshot/configs.
|
||||
- **Hostname** (D7): `gethostname()` with `.local`/domain suffix
|
||||
stripped, ASCII, ≤ 32; otherwise the app refuses to start the channel
|
||||
and shows the reason in the status item.
|
||||
- **Placeholder UI**: `NSStatusItem` with a title-only menu ("mwb
|
||||
0.1.0-dev — running" / "— permissions missing: …" / "— hostname
|
||||
invalid"), "Request Permissions…" (the only place `Permissions.request()`
|
||||
is called, on the user's click), and Quit. `app-ui` replaces it.
|
||||
- **Logging** (`MWBMac/Log.swift`): `os.Logger` plus a rotating file at
|
||||
`~/Library/Logs/mwb-mac/mwb.log` (1 MB × 3). Never key material,
|
||||
never keystrokes; peer names and statuses are fine.
|
||||
- **Single instance**: `flock` on
|
||||
`~/Library/Application Support/mwb-mac/mwb.pid`; a second launch
|
||||
exits 1 with a message.
|
||||
|
||||
## Handshakes
|
||||
|
||||
### Consumed
|
||||
|
||||
Everything published by wire-core, session-matrix, control-channel,
|
||||
input-capture and input-inject, exactly as their Handshakes sections
|
||||
read today. If an API turns out to be missing or wrong, the Dev files
|
||||
a request in this README and stops that item — it does not edit the
|
||||
other lane's files.
|
||||
|
||||
### Promised (to app-ui, clipboard, extras)
|
||||
|
||||
```swift
|
||||
public struct Settings: Codable, Sendable { … every README §Settings property …; static func load(from:) throws -> Settings; func save(to:) throws; var matrix: Matrix; var pool: MachinePool }
|
||||
public final class SettingsStore { init(url:); var current: Settings; func update(_ f: (inout Settings) -> Void) throws; var onExternalChange: ((Settings) -> Void)? }
|
||||
|
||||
actor Engine {
|
||||
init(settings: SettingsStore) throws
|
||||
func start() throws; func stop()
|
||||
func apply(_ settings: Settings) // re-maps every config
|
||||
var snapshot: EngineSnapshot // for the UI: peers + statuses, controlled machine, permissions, easy mouse on/off, last error
|
||||
func switchTo(slot: Int); func switchToAll(); func reconnect(); func lockAll(); func toggleEasyMouse()
|
||||
func recoverLocal(reason: RecoveryReason)
|
||||
var onSnapshotChange: (@Sendable (EngineSnapshot) -> Void)?
|
||||
}
|
||||
public struct EngineSnapshot: Sendable { peers: [PeerStatus]; controlled: String?; permissions: PermissionState; easyMouseEnabled: Bool; hostnameProblem: String?; lastRecovery: (RecoveryReason, Date)? }
|
||||
```
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [ ] `Sources/MWBCore/Settings.swift`: schema, defaults, load/save,
|
||||
first-run generation, matrix/pool round-trip, config mapping (C4)
|
||||
(`MouseWithoutBordersProperties.cs:165-206`, `Setting.cs:479-511,
|
||||
1048-1083`, `Common.cs:906`).
|
||||
- [ ] `Sources/MWBMac/Log.swift`: logger + rotating file.
|
||||
- [ ] `Sources/mwb/Engine.swift`: the actor, sink stream, drain loop,
|
||||
C1 forwarding, packet dispatch (`Receiver.cs` `ProcessPackage`
|
||||
cases for Mouse, Keyboard, HideMouse, MachineSwitched,
|
||||
NextMachine, Matrix, Heartbeat/Awake/Hello learning, ByeBye).
|
||||
- [ ] `Sources/mwb/EngineActions.swift`: `SwitchAction` and hotkey
|
||||
dispatch per Assumptions (`MachineStuff.cs:1007-1050`,
|
||||
`InputHook.cs:539-658`).
|
||||
- [ ] `Sources/mwb/Recovery.swift`: `recoverLocal`, every C2 trigger
|
||||
wired, reopen countdown (`frmScreen.cs:427-461`).
|
||||
- [ ] `Sources/mwb/AppLifecycle.swift` + `main.swift`: `NSApplication`
|
||||
delegate, placeholder status item, single instance, signal/atexit
|
||||
handlers, wake/screen notifications, `--check-permissions` and
|
||||
`--version` kept.
|
||||
- [ ] `docs/protocol.md`: append §10.6 with anything learned, cited.
|
||||
|
||||
## Work log
|
||||
|
||||
## QA log
|
||||
|
||||
## Review
|
||||
@@ -535,3 +535,16 @@ findings are behavioural, not typos.
|
||||
Verdict: REWORK
|
||||
|
||||
## Review
|
||||
|
||||
- 2026-09-16 (lead): inspected per `docs/loop.md` §5 after one rework
|
||||
round. Gates green run by me; two files in the brief's list plus TODO
|
||||
§5, protocol §10.5 and this README. Read the rework diff and the
|
||||
injector's structure: one tagged HID source, every post through it,
|
||||
raw VK into chord state and normalised VK into posting, `releaseAll`
|
||||
with no rate limit, bookkeeping on one queue. The only log line in
|
||||
the lane is a static string. QA confirmed the primary-bounds reading
|
||||
of `SendMouse`. Verdict: **merge**. Carry into app-engine: the five
|
||||
requests in this README's Handshakes (lock chord forwarding,
|
||||
`releaseAll` on every C2 row, layout into every `inject`,
|
||||
`HotKeyLockMachine` → `InjectorConfig.lockMachine`, `canInject`).
|
||||
CP1 questions: remote ⌘L locks this Mac; natural scrolling.
|
||||
+13
-5
@@ -156,11 +156,12 @@ Strictly one at a time, in this order (mirrors `TODO.md`):
|
||||
| 2 | session-matrix | merged 2026-09-16 (one rework) |
|
||||
| 3 | control-channel | merged 2026-09-16 (two reworks) |
|
||||
| 4 | input-capture | merged 2026-09-16 (one rework) |
|
||||
| 5 | input-inject | in progress |
|
||||
| 6 | app-shell | **CP1**: first manual acceptance checkpoint (contracts C5) |
|
||||
| 7 | clipboard | **CP2** |
|
||||
| 8 | extras | **CP3** |
|
||||
| 9 | polish | driven by the checkpoints' findings |
|
||||
| 5 | input-inject | merged 2026-09-16 (one rework) |
|
||||
| 6 | app-engine | the Engine actor, Settings, wiring, recovery; a headless-capable `mwb` |
|
||||
| 7 | app-ui | status item, settings window, notifications, LaunchAgent — **CP1** (contracts C5) |
|
||||
| 8 | clipboard | **CP2** |
|
||||
| 9 | extras | **CP3** |
|
||||
| 10 | polish | driven by the checkpoints' findings |
|
||||
|
||||
## 7. Escalations — things only the user can do
|
||||
|
||||
@@ -174,6 +175,13 @@ Strictly one at a time, in this order (mirrors `TODO.md`):
|
||||
|
||||
## 8. Lane log
|
||||
|
||||
- **2026-09-16, lane 5 (input-inject)** — Dev (Opus), QA (Sonnet)
|
||||
REWORK (chord state normalised too early; undocumented secure-desktop
|
||||
gate), Dev rework, lead inspection. What the brief got wrong: it
|
||||
claimed macOS "delivers" a modifier keycode as `flagsChanged` — the
|
||||
poster must synthesise it. After this lane the lead split app-shell
|
||||
into app-engine and app-ui: one lane for ~2 500 lines of actor,
|
||||
settings, wiring and SwiftUI was too much for one Dev/QA round.
|
||||
- **2026-09-16, lane 4 (input-capture)** — Dev (Opus), QA (Sonnet)
|
||||
REWORK with four host-side findings (unguarded `thread` field, a
|
||||
lock taken on the local path, a wrong lock-count claim, switch-to-all
|
||||
|
||||
+6
-5
@@ -83,7 +83,7 @@ lead's; a lane needing a change there files a Handshake request.
|
||||
|
||||
```
|
||||
bootstrap ─▶ wire-core ─▶ session-matrix ─▶ control-channel
|
||||
─▶ input-capture ─▶ input-inject ─▶ app-shell (first user-testable build)
|
||||
─▶ input-capture ─▶ input-inject ─▶ app-engine ─▶ app-ui (CP1)
|
||||
─▶ clipboard ─▶ extras ─▶ polish
|
||||
```
|
||||
|
||||
@@ -156,10 +156,11 @@ parallelism proof. Nothing starts before everything it consumes is merged.
|
||||
| 3 | control-channel | session-matrix, wire-core |
|
||||
| 4 | input-capture | session-matrix (Edge, coordinates) |
|
||||
| 5 | input-inject | input-capture (KeyMap, Screens, injected tag), session-matrix |
|
||||
| 6 | app-shell | all of the above |
|
||||
| 7 | clipboard | wire-core, control-channel, app-shell (Settings) |
|
||||
| 8 | extras | app-shell, session-matrix |
|
||||
| 9 | polish | everything |
|
||||
| 6 | app-engine | all of the above |
|
||||
| 7 | app-ui | app-engine |
|
||||
| 8 | clipboard | wire-core, control-channel, app-engine (Settings) |
|
||||
| 9 | extras | app-engine, session-matrix |
|
||||
| 10 | polish | everything |
|
||||
|
||||
`TODO.md`, `docs/protocol.md` and `docs/perf/README.md` are
|
||||
shared-by-nature: append in your own section only.
|
||||
Reference in new issue
Block a user