Files
lucioandClaude Fable 5.1 08b243a29a contracts: sequencing, recovery, concurrency, shared constants, checkpoints
Written after an external review of the plan found cross-module
behaviour under-specified. TODO, topo, loop and the session-matrix
brief now reference docs/contracts.md.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-16 00:54:33 -07:00

148 lines
7.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CLAUDE.md — rules for all agents working on mwb-mac
mwb-mac is a macOS port of PowerToys "Mouse Without Borders" (MWB): one
keyboard and mouse shared across up to four machines on a LAN, with
clipboard sharing, that **interoperates on the wire with the unmodified
Windows MWB**. Read `README.md` for architecture, `docs/loop.md` for how
work is done, `docs/contracts.md` for the behaviour that spans modules
(sequencing, recovery, concurrency), `docs/topo.md` for the dependency
map and `TODO.md` for the backlog before doing anything. The reference implementation is
checked out at `/Users/guoliangchen/repo/PowerToys/src/modules/MouseWithoutBorders/`
(commit `3104d5c`, tag v0.101.2572.0) — read it, cite it, never edit it.
## How this project is developed (the user's standing instruction)
- **One dev loop at a time, directly in this repository.** Never two
lanes in flight, never a worktree: Dev, QA and the lead all work in
`/Users/guoliangchen/repo/mac_without_borders` on `main`. A lane is
Dev → QA → lead inspection, then the next lane starts.
- **Roles are fixed**: one Dev (Opus 5) ports the feature; one QA
(Sonnet 5) reviews the *code quality and completeness of the port*;
then the lead (Fable 5.1) inspects. The lead plans and reviews; it
does not write lane code.
- **The human is the tester.** Agents do not write test suites. There is
no gate that requires tests, and no lane is "incomplete" for lacking
them. What matters is that **every feature of the Windows version is
ported and the code reads as reasonable** — the user tests the app
end-to-end at the end.
- **Commit along the way.** Dev commits as it works, in small commits
with clear messages. A commit does not need to compile. Do not
push; the lead pushes after inspection.
- **No busywork.** No placeholder tests, no coverage chasing, no
abstractions for a second user that does not exist.
## Hard invariants (never break these)
1. **Wire compatibility is a contract, not a goal.** Packet layout, the
package-type numbering, the key derivation, the cipher mode and the
handshake are dictated by the Windows source (`docs/protocol.md`
is our transcription, with `file:line` citations). Any difference is
a bug on our side unless the Windows source changed. Every constant
in the codec and crypto code carries a comment citing the Windows
line it came from.
2. **Never act on an unauthenticated packet.** No input is injected, no
clipboard is written, no file is created from any packet that did
not decrypt and validate under the configured security key. There
is no "no key" mode. The key and decrypted keystrokes are never
logged, at any log level.
3. **The local machine is always recoverable.** Whatever happens on the
network, the user can regain their own keyboard and mouse: the
escape hotkey works while control is remote, control returns local
on any disconnect or on key-tap loss, and a
`kCGEventTapDisabledByTimeout` / `ByUserInput` tap is re-enabled
immediately. A build that can leave a Mac with a dead keyboard does
not ship.
4. **The event-tap callback never blocks.** No network, disk, locking on
contended locks, or allocation-heavy work inside the `CGEventTap`
callback; it classifies, enqueues and returns.
5. **Agents never drive the user's input devices.** No agent runs a
build that posts `CGEvent`s, writes the real pasteboard or moves the
real cursor. Agents build; the user runs. This machine is the user's
daily driver.
## Simplicity first
- Prefer the boring, obvious implementation. Port the Windows
behaviour, not the Windows shape: `Common.cs`, `SocketStuff.cs` and
`MachineStuff.cs` are grab-bags; ours are not.
- Apple frameworks first (Foundation, Network, AppKit, CoreGraphics,
CryptoKit/CommonCrypto). Adding a Swift package dependency requires
a written justification in the feature README.
- Small functions, descriptive names, shallow nesting. Code should be
readable top-to-bottom without jumping around.
- Match the style of the surrounding code.
## File and function size
- **Target 300–600 lines per file.** At 800, split. Above 1,200, an
explicit reason goes in the feature README.
- **Functions: 10–50 lines.** Anything over 80 gets a look; anything
over 150 needs a reason in a comment (a `switch` over `PackageType`
is the usual one).
- **The one-sentence test.** A human should be able to say what a file
is responsible for in one sentence. Several "and" clauses mean the
file wants to be several files.
## Swift standards
- Swift 6 language mode, strict concurrency on.
- `xcrun swift-format lint --strict` clean and `swift build -Xswiftc
-warnings-as-errors` clean **at the end of a lane** (`tools/gates.sh`).
Intermediate commits may be broken.
- No force-unwrap (`!`), `try!`, `fatalError` or `precondition` in
production code paths; throw or return `Result`. `main.swift`
argument handling may use them.
- Public items get a one-line doc comment saying what/why, not how.
- Layering is enforced by SwiftPM targets: `MWBCore` imports Foundation
and CommonCrypto only (no AppKit, CoreGraphics, Network); `MWBNet` is
Network.framework; `MWBMac` is AppKit/CoreGraphics; the executable
`mwb` is the only place they meet.
- C APIs (`CGEventTap`, `CommonCrypto`) are wrapped once, in one file
each, behind a Swift type; nothing else touches the raw API.
## Document-based development
Every feature lives in `docs/features/<feature-name>/README.md` with
these sections:
```markdown
# <feature name>
## Goal — one paragraph, what and why
## Assumptions — everything you assumed that isn't enforced by code
## Handshakes — interfaces/contracts with other modules: what you
consume from them, what you promise to them
## Status / TODO — checklist; keep current as you work
## Work log — dated entries by the dev agent: what was done, key
decisions, deviations from plan
## QA log — dated entries by the QA agent: what was reviewed,
and findings
## Review — reserved for the lead; do not write here
```
- **Dev agents**: update the README *as you work*, not at the end. Tick
finished items. If you change a handshake another module depends on,
say so in Handshakes and in the work log. Every fact taken from the
Windows source is cited as `App/<path>.cs:<line>`.
- **QA agents**: you review, you don't redesign and you don't write
tests. Read the port against the Windows source and the brief; find
what is missing, wrong or unreadable; record file:line findings in
the QA log. Small unambiguous fixes you may make directly and note.
- **Review** is written only by the lead. Respond to review comments by
fixing and logging in the work log, not by editing the Review section.
- `docs/protocol.md` is the one place the wire format is written down.
A feature that learns something new about the protocol updates it in
the same change, with the citation.
## Workflow
- Do not touch files outside your feature's stated scope. If you need a
change in another module, write it as a request in your README's
Handshakes section and stop.
- Update `TODO.md`: tick items your feature completes (leave the text).
- Never grant, request or script macOS permissions (Accessibility,
Input Monitoring, Screen Recording) on an agent's own initiative.
Report what is missing; the user grants it in System Settings.
- Any long-running command (a build sweep, a soak, anything you are
unsure about) goes through `tools/guard.sh` (8 GB / 30 min default).
A guard kill is a finding, not a reason to raise the limit.