156 lines
6.9 KiB
Markdown
156 lines
6.9 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` | wire-core | session, session-matrix, clipboard, control-channel, bulk |
|
|
| `MagicHash.swift`, `CipherStream.swift` | wire-core | session-matrix (magic), control-channel, clipboard |
|
|
| `Session.swift` | session-matrix | control-channel |
|
|
| `Matrix.swift`, `Edge.swift` | session-matrix | mwb, input-capture (edge), input-inject (coords) |
|
|
| `KeyMap.swift` | input-capture | input-inject |
|
|
| `ClipboardCodec.swift` | clipboard | clipboard (header format only) |
|
|
| `Settings.swift` | app-shell | everyone via `mwb` |
|
|
|
|
`MWBMac` files owned at planning time:
|
|
|
|
| file | lane | note |
|
|
|---|---|---|
|
|
| `Permissions.swift` | bootstrap → **input-capture** | preflight shipped by bootstrap; input-capture adds `request…` and owns the file from wave 3 |
|
|
| `EventTap.swift` | input-capture | |
|
|
| `Injector.swift` | input-inject | defines the injected-event tag (handshake 5) |
|
|
| `Screens.swift`, `Cursor.swift` | input-capture | |
|
|
| `Pasteboard.swift` | clipboard | |
|
|
| `StatusItem.swift` | app-shell | |
|
|
|
|
`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 ─▶ wire-core ─▶ session-matrix ─▶ control-channel
|
|
─▶ input-capture ─▶ input-inject ─▶ app-shell (first user-testable build)
|
|
─▶ clipboard ─▶ extras ─▶ polish
|
|
```
|
|
|
|
### 2.2 Consumption edges (`──▶`)
|
|
|
|
| consumer | consumes | what |
|
|
|---|---|---|
|
|
| session-matrix | wire-core | `Packet`, `PackageType`, `Framing` |
|
|
| session-matrix | wire-core | `magicNumber(for:)` only |
|
|
| session-matrix | wire-core | `Packet` (Matrix, NextMachine, Mouse encode) |
|
|
| control-channel | session, wire-core, wire-core | everything above the socket |
|
|
| input-capture | session-matrix | `Edge` decisions on captured moves |
|
|
| input-inject | input-capture (KeyMap), session-matrix (de-normalization), input-capture (desktop bounds) | |
|
|
| input-capture | session-matrix | rectangle definitions |
|
|
| clipboard | wire-core | 64-byte chunk packets |
|
|
| clipboard | wire-core, wire-core, clipboard | stream layout, `DATA`, header/text format |
|
|
| app-shell | every `MWBCore` type, control-channel, input-capture, input-capture | 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. **wire-core ◀──▶ session**: the `Packet` API shape (value type
|
|
with typed union views, `Data` in/out). wire-core proposes in its
|
|
README; session consumes as published. Closed when session lands.
|
|
2. **wire-core ◀──▶ 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. **session-matrix ◀──▶ input-capture**: `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. **input-capture ◀──▶ input-inject**: the injected-event tag value
|
|
(`eventSourceUserData`) is one constant defined in `MWBMac/Injector.swift`
|
|
and read by `EventTap.swift`.
|
|
6. **input-capture ◀──▶ input-inject**: `Screens.desktopBounds` and
|
|
`primaryBounds` in CG coordinates (top-left origin, points).
|
|
7. **clipboard ◀──▶ clipboard**: the `"<len>*<name>"`
|
|
header codec and the text tag/SEP codec live in `ClipboardCodec.swift`
|
|
and are reused by bulk unchanged.
|
|
8. **app-shell ◀──▶ 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), so this is an order, not a
|
|
parallelism proof. Nothing starts before everything it consumes is merged.
|
|
|
|
| # | lane | consumes |
|
|
|---|---|---|
|
|
| 1 | wire-core | bootstrap |
|
|
| 2 | session-matrix | wire-core |
|
|
| 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 |
|
|
|
|
`TODO.md`, `docs/protocol.md` and `docs/perf/README.md` are
|
|
shared-by-nature: append in your own section only.
|