7.7 KiB
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), docs/contracts.md, 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
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 onlyFoundationandCommonCrypto(CryptoKit for hashing). Enforced by the layering grep intools/gates.sh.MWBNetandMWBMacnever import each other. The executable is the only place they meet.- Nothing outside
MWBCoreinterprets packet bytes;MWBNethandsDatatoSessionandCipherReader,MWBMachandsCapturedInputvalues in and takesPacket-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-engine ─▶ app-ui (CP1)
─▶ 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.
- wire-core ◀──▶ session: the
PacketAPI shape (value type with typed union views,Datain/out). wire-core proposes in its README; session consumes as published. Closed when session lands. - wire-core ◀──▶ control-channel: streaming
write/readreturningDatawith internal partial-block buffering; header and sacrificial block handled inside the cipher types, not by the channel. Closed when control-channel lands. - session-matrix ◀──▶ control-channel:
Session.feed(_:),noteReceiveError(bytesReceived:),tick(now:inputEventCount:),drain() -> [Data],events() -> [SessionEvent],forward(_:)(contracts C1). The channel never inspects packet bytes and must pass read byte counts through, never collapse them. - session-matrix ◀──▶ input-capture:
Edge.crossing(...)returns aDirection?;Switcher.crossingturns it into a switch. Debounce lives inEdge; the tap suppliesCGPoints and timestamps. Geometry uses Foundation's bareCGRect/CGPoint(no.zero,minX,Equatable); helpers are onCoordinates, not CG extensions. - input-capture ◀──▶ input-inject: the injected-event tag value
(
eventSourceUserData) is one constant defined inMWBCore/InputTypes.swiftby input-capture and read byInjector.swift(contracts C4). - input-capture ◀──▶ input-inject:
Screens.desktopBoundsandprimaryBoundsin CG coordinates (top-left origin, points), passed intoCoordinates.fromUniversal/EdgeConfigas plainCGRects. - clipboard in-band ◀──▶ clipboard bulk (same lane): the
"<len>*<name>"header codec and the text tag/SEP codec live inClipboardCodec.swiftand are reused by bulk unchanged. - app-shell ◀──▶ everyone: earlier lanes take lane-specific config
structs (
SessionConfig,EdgeConfig,ChannelConfig,CaptureConfig); app-shell'sSettingsmaps onto them (contracts C4). - Engine (app-shell) ◀──▶ session-matrix, control-channel, input-capture, input-inject: the actor that owns shared state, the routing snapshot, the bounded queues and recovery (contracts C1–C3).
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-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.