Files
mac_without_borders/docs/topo.md
T
2026-09-15 23:55:57 -07:00

167 lines
7.6 KiB
Markdown

# topo.md — the dependency topology of mwb-mac
**Purpose.** The map an agent reads before touching anything: which
targets depend on which, which features consume which, and where the two
graphs meet. It exists so each lane starts only after everything it
consumes is merged, and so the lead knows which interfaces a lane can
break — every edge below is one.
Sources of truth this document is derived from (and defers to on
conflict): `Package.swift`, each `docs/features/<name>/README.md`
(**Handshakes** in particular), `README.md`, `CLAUDE.md`,
`docs/protocol.md`. Drafted 2026-09-15 at planning time; updated the same day after the
bootstrap merge (skeleton exists, file ownership tables below reflect it).
The lead updates it after every merged lane.
**Edge notation:**
| notation | meaning |
|---|---|
| `A ──▶ B` | **A consumes B.** B's published interface; B does not know A exists. Breaking B breaks A. |
| `A ◀──▶ B` | **Handshake.** A negotiated two-sided contract written down in one or both READMEs. Either side moving unilaterally breaks the other. |
| `A ─▶ B` | Not a dependency: `sequencing`, `standing promise`, `open request`. |
| *(absent)* | Nothing recorded. Confirm before treating as independent. |
---
## 1. Target dependency graph
```mermaid
graph TD
Core[MWBCore — Foundation + CommonCrypto only]
Net[MWBNet — Network.framework] --> Core
Mac[MWBMac — AppKit / CoreGraphics] --> Core
App[mwb executable] --> Core
App --> Net
App --> Mac
```
Standing promises:
- `MWBCore ─▶ everyone` (standing promise): imports only `Foundation`
and `CommonCrypto` (CryptoKit for hashing). Enforced by the layering
grep in `tools/gates.sh`.
- `MWBNet` and `MWBMac` never import each other. The executable is the
only place they meet.
- Nothing outside `MWBCore` interprets packet bytes; `MWBNet` hands
`Data` to `Session` and `CipherReader`, `MWBMac` hands
`CapturedInput` values in and takes `Packet`-derived commands out.
### 1.1 Intra-target structure that matters for lanes
`MWBCore` files and who owns them at planning time:
| file | lane | consumers |
|---|---|---|
| `Packet.swift`, `Framing.swift` | packet-codec | session, matrix-edge, clipboard-inband, control-channel, bulk |
| `MagicHash.swift`, `CipherStream.swift` | cipher-stream | session (magic), control-channel, clipboard-bulk |
| `Session.swift` | session | control-channel |
| `Matrix.swift`, `Edge.swift` | matrix-edge | mwb, event-tap (edge), input-inject (coords) |
| `KeyMap.swift` | event-tap | input-inject |
| `ClipboardCodec.swift` | clipboard-inband | clipboard-bulk (header format only) |
| `Settings.swift` | menubar-app | everyone via `mwb` |
`MWBMac` files owned at planning time:
| file | lane | note |
|---|---|---|
| `Permissions.swift` | bootstrap → **event-tap** | preflight shipped by bootstrap; event-tap adds `request…` and owns the file from wave 3 |
| `EventTap.swift` | event-tap | |
| `Injector.swift` | input-inject | defines the injected-event tag (handshake 5) |
| `Screens.swift`, `Cursor.swift` | screens-cursor | |
| `Pasteboard.swift` | clipboard-inband | |
| `StatusItem.swift` | menubar-app | |
`MWBNet/Placeholder.swift` is deleted by control-channel.
Tooling (`tools/`, `Package.swift`, `.swift-format`, `Resources/`) is the
lead's; a lane needing a change there files a Handshake request.
## 2. Feature dependency graph
### 2.1 Lane order (sequencing, `─▶`)
```
bootstrap ─▶ packet-codec ─▶ cipher-stream ─▶ session ─▶ matrix-edge
─▶ control-channel ─▶ event-tap ─▶ screens-cursor ─▶ input-inject
─▶ menubar-app (first user-testable build)
─▶ clipboard-inband ─▶ clipboard-bulk ─▶ end-to-end polish
```
### 2.2 Consumption edges (`──▶`)
| consumer | consumes | what |
|---|---|---|
| session | packet-codec | `Packet`, `PackageType`, `Framing` |
| session | cipher-stream | `magicNumber(for:)` only |
| matrix-edge | packet-codec | `Packet` (Matrix, NextMachine, Mouse encode) |
| control-channel | session, cipher-stream, packet-codec | everything above the socket |
| event-tap | matrix-edge | `Edge` decisions on captured moves |
| input-inject | event-tap (KeyMap), matrix-edge (de-normalization), screens-cursor (desktop bounds) | |
| screens-cursor | matrix-edge | rectangle definitions |
| clipboard-inband | packet-codec | 64-byte chunk packets |
| clipboard-bulk | cipher-stream, packet-codec, clipboard-inband | stream layout, `DATA`, header/text format |
| menubar-app | every `MWBCore` type, control-channel, event-tap, screens-cursor | wiring |
| end-to-end | all | |
### 2.3 Handshakes (`◀──▶`) — all open at planning time
Numbered so lanes can cite them. With serial lanes a handshake is simply
"the earlier lane publishes, the later lane consumes as published"; the
list still matters because it names the APIs the lead checks at
inspection.
1. **packet-codec ◀──▶ session**: the `Packet` API shape (value type
with typed union views, `Data` in/out). packet-codec proposes in its
README; session consumes as published. Closed when session lands.
2. **cipher-stream ◀──▶ control-channel**: streaming `write/read`
returning `Data` with internal partial-block buffering; header and
sacrificial block handled inside the cipher types, not by the
channel. Closed when control-channel lands.
3. **session ◀──▶ control-channel**: `Session.feed(_:) -> [Event]`,
`Session.outgoing() -> Data`, injected `Clock`. The channel never
inspects packet bytes.
4. **matrix-edge ◀──▶ event-tap**: `Edge.evaluate(point:rect:now:)`
returns a `Switch?` decision. Debounce lives in `Edge` with the
injected clock; the tap only supplies points and timestamps.
5. **event-tap ◀──▶ input-inject**: the injected-event tag value
(`eventSourceUserData`) is one constant defined in `MWBMac/Injector.swift`
and read by `EventTap.swift`.
6. **screens-cursor ◀──▶ input-inject**: `Screens.desktopBounds` and
`primaryBounds` in CG coordinates (top-left origin, points).
7. **clipboard-inband ◀──▶ clipboard-bulk**: the `"<len>*<name>"`
header codec and the text tag/SEP codec live in `ClipboardCodec.swift`
and are reused by bulk unchanged.
8. **menubar-app ◀──▶ everyone**: `Settings` is the one struct passed
down; lanes read fields, never the file.
## 3. Lane order
Lanes run **one at a time** (CLAUDE.md, the user's standing
instruction), so this section is an order, not a parallelism proof. The
order follows the consumption edges in §2.2: nothing is started before
everything it consumes is merged.
| # | lane | consumes (must be merged first) |
|---|---|---|
| 1 | packet-codec | bootstrap |
| 2 | cipher-stream | bootstrap |
| 3 | session | packet-codec, cipher-stream |
| 4 | matrix-edge | packet-codec |
| 5 | control-channel | session, cipher-stream, packet-codec |
| 6 | event-tap | matrix-edge |
| 7 | screens-cursor | matrix-edge |
| 8 | input-inject | event-tap (KeyMap), matrix-edge, screens-cursor |
| 9 | menubar-app | all of the above — the first build the user can test |
| 10 | clipboard-inband | packet-codec, menubar-app (Settings) |
| 11 | clipboard-bulk | cipher-stream, packet-codec, clipboard-inband |
| 12 | end-to-end polish | everything; driven by the user's testing |
`interop-vectors` is no longer a lane: there are no test suites. If a
Windows machine becomes available, the lead verifies protocol facts by
hand against a capture and flips `[transcribed]` marks in
`docs/protocol.md`.
`TODO.md`, `docs/protocol.md` and `docs/perf/README.md` are
shared-by-nature: append in your own section only.