# 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 to make parallel multi-agent development safe — every edge below is an interface somebody can break. An absent edge is only a candidate for independent work: confirm imports, shared files and open handshakes before assigning ownership. Sources of truth this document is derived from (and defers to on conflict): `Package.swift`, each `docs/features//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 CT[MWBCoreTests] --> Core NT[MWBNetTests] --> Net ``` Standing promises: - `MWBCore ─▶ everyone` (standing promise): imports only `Foundation` and `CommonCrypto`. Enforced by a test in `MWBCoreTests` that greps the target's sources. - `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; `Tests/MWBNetTests/PlaceholderTests.swift` likewise. 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 Milestone order (sequencing, `─▶`) ``` bootstrap ─▶ { packet-codec ‖ cipher-stream } ─▶ { session ‖ matrix-edge } ─▶ { control-channel ‖ event-tap } ─▶ { input-inject ‖ screens-cursor } ─▶ { clipboard-inband ‖ menubar-app } ─▶ { clipboard-bulk ‖ interop-vectors } ─▶ end-to-end ─▶ soak ``` ### 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 | | interop-vectors | packet-codec, cipher-stream, clipboard-inband | fixtures are tests for these | | end-to-end | all | | ### 2.3 Handshakes (`◀──▶`) — all open at planning time Numbered so lanes can cite them. A lane that needs one not listed here files it in its README and flags it in its report; the lead adds it. 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 `"*"` 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. Which pairs may run in parallel Proven independent by disjoint files **and** no edge above: | wave | lane A | lane B | shared files | |---|---|---|---| | 1 | packet-codec | cipher-stream | none (both create their own files; `Package.swift` untouched) | | 2 | session | matrix-edge | none; both consume packet-codec read-only | | 3 | control-channel | event-tap | none; different targets | | 4 | input-inject | screens-cursor | **edge 6** — screens-cursor publishes its API in its README first; input-inject codes against the README. Acceptable only because the API is two rectangles. | | 5 | clipboard-inband | menubar-app | `Settings.swift` is menubar-app's; clipboard reads `ShareClipboard` via a constructor parameter, not the struct | | 6 | clipboard-bulk | interop-vectors | `Tests/Fixtures/` is interop-vectors'; bulk adds tests under `Tests/MWBNetTests/` only | Anything not in this table runs serially. `TODO.md`, `docs/protocol.md` and `docs/perf/README.md` are shared-by-nature: append in your own section only.