A weird little creature that lives in your Mac. The camera watches the room locally, people become anonymous cartoon characters (πΈ π§ π₯ π½ π¦ π€ π± π¦ π» π), and Laya directs harmless toy chaos at them: bubbles, rubber ducks, tomatoes, balloons, sponges, confetti, rainbows, emoji bursts, transformations and surprises.
Videos: simulation mode (the game + debug panel + Laya's decisions) Β· screensaver (a real person, rendered as a cartoon character β the screensaver never sees the camera image, only anonymous boxes).
Camera (AVFoundation ~30fps) β Vision body boxes (~10fps) β PersonTracker β GameEngine (60fps)
β GameSnapshot (JSON only)
βΌ
DirectorCoordinator β Laya sidecar (127.0.0.1:8777)
β RandomDirector (local fallback)
β DirectorDecision
βΌ
GameEvent β SpriteKit renderer β screen
The source is MIT licensed: clone it, build it, use it, change it, ship it β free, forever.
If you would rather not build anything, a ready-to-run build is on Lemon Squeezy for βΉ99 (about $1). It is the same software; you are paying for the convenience and for the next version getting written.
Download MacAttack-0.1.0.dmg, open it,
run Install.command (right-click β Open if Gatekeeper complains), then:
- Open Mac Attack, allow the camera.
- Optional: Debug Mode β LAYA β Set Up Laya (one-time, ~2.5 GB, needs Python 3.10+). Without it the game runs on its built-in random director.
- Debug Mode β SCREENSAVER HELPER β Install Helper.
- System Settings βΊ Screen Saver βΊ Mac Attack.
Unsigned build. This is signed ad-hoc, so macOS will warn on first launch (right-click β Open) and may re-ask for camera permission after each rebuild. Signing with an Apple Developer ID removes both.
Requirements: macOS 14+, Swift 6 toolchain (Command Line Tools are enough; Xcode is not needed).
# one-time: Laya sidecar environment (reuses the cached HF checkpoints in ~/.cache/huggingface)
python3 -m venv LayaDirector/.venv && LayaDirector/.venv/bin/pip install -r LayaDirector/requirements.txt
./scripts/build_app.sh # β build/MacAttack.app
open build/MacAttack.app # camera mode
open build/MacAttack.app --args --simulate --debug
./scripts/test.sh # 24 unit tests (tracker, engine state machine, sampling, fallback, sim)The app starts the Laya sidecar itself (LayaDirector/run.sh) and stops it on quit; a watchdog
relaunches it if it dies, and the sidecar exits on its own if the app disappears. You can also run
it manually: LayaDirector/run.sh (then the app just connects).
Launch flags: --simulate, --autopilot (sim + random humans), --chaos, --debug,
--no-sound, --no-sidecar, --slow-laya (+3 s per decision), --laya-port N, --no-activate.
First launch in Camera mode shows the standard macOS prompt ("Mac Attack watches the room
locallyβ¦"). If denied, the canvas shows a card with Open Privacy Settings and Use Simulation
Mode. To change later: System Settings βΊ Privacy & Security βΊ Camera βΊ Mac Attack. To re-test
the prompt: tccutil reset Camera local.macattack.
The bundle is ad-hoc signed unless a signing identity exists (SIGN_IDENTITY=... or an
"Apple Development" cert is auto-detected). With ad-hoc signing macOS may ask again after a rebuild.
- Camera / Simulation β segmented control in the header. Simulation replaces the camera with
fake humans (same
TrackSnapshots the tracker produces), so the whole game runs without a camera. - Debug Mode β checkbox in the header. Opens the side panel:
- Developer controls: Spawn Human, Spawn 2 Humans, Clear Humans, Chaos Mode, Trigger Laya, Bubble Attack, Confetti, Duck Rain, More Effects (all 11), Reset. Spawning switches to Simulation.
- Simulation: autopilot, per-human behavior (wander/stationary/left/right/zigzag/frantic), nudge, remove.
- Camera/perception: status, device, detection fps/latency, upper-body toggle, face-box assist, detection boxes overlay, render fps/node count, start/stop camera.
- People: position %, movement, velocity, dwell, hits.
- Laya: health, device, latency, Use Laya / Simulate slow Laya toggles, last decision with the top probabilities per question and the exact text Laya read; decision log (Laya vs Local).
- Chaos β hotter sampling temperature, shorter cooldowns, fewer dramatic pauses.
Laya (pip install laya, Convai Innovations, HF convaiinnovations/laya) is a non-autoregressive
typed-decision model: Router().predict(state, questions) answers choice / score / noul
questions in one forward pass with calibrated probabilities. It is PyTorch, so it runs in a local
FastAPI sidecar (LayaDirector/server.py, 127.0.0.1 only, English checkpoint, MPS on Apple Silicon).
- The engine builds a
GameSnapshot(ids, normalized boxes, movement, velocity, dwell time, character type, hits, combo, last event, trigger). No pixels, no identity. - The sidecar turns it into a one-paragraph situation ("2 humans in view. person-1 is the frog on
the left, just arrived, moving leftβ¦") and asks 8 questions:
style(projectile/area/transform/ surprise),projectile(5),area(4),target(visible people + everyone),intensity(score),reaction(8),hold_back(noul),mood(4). - Swift (
LayaDecisionMapper) samples those distributions (T=1, T=1.8 in chaos) instead of taking argmax, down-weights repeating the last gag, and scaleshold_backso doing nothing is an occasional pause. Same situation, different outcomes, still following Laya's taste. - Decisions are event-driven: on arrival, on departure, after each effect's cooldown (2.5β5 s, 1β2.2 s in chaos), or on "Trigger Laya". One request in flight, never in the render loop.
DirectorCoordinatoruses Laya only when/statusis ready and the answer arrives within 2 s; otherwiseRandomDirectordecides. The engine also has its own 3 s guard. The UI showsDirector: LayaorDirector: Local Fallback.
Design notes from measuring the real model: a single 11-option choice falls in Laya's choice:11+
temperature bucket, which ships uncalibrated (probabilities saturate to 1.0), so the effect is split
into style + a β€5-option pick. Sending the situation as text instead of the raw JSON halves latency
(~630 ms β ~340 ms on MPS) because Laya re-reads the state once per question.
Builds are ad-hoc signed by default, which is why macOS warns about them. With a paid Apple Developer ID the same scripts produce a build that opens without any warning:
# once: store an app-specific password for notarytool
xcrun notarytool store-credentials macattack-notary \
--apple-id you@example.com --team-id TEAMID --password <app-specific-password>
SIGN_IDENTITY="Developer ID Application: Your Name (TEAMID)" \
NOTARY_PROFILE=macattack-notary \
./scripts/make_dmg.sh 1.0.0That signs the app and the screensaver with the hardened runtime and
Resources/MacAttack.entitlements (camera, plus the exceptions the Python sidecar needs), signs
the disk image, submits it to Apple, waits, staples the ticket and verifies it with spctl.
A stable signing identity also stops macOS re-asking for camera permission after every update.
The Laya checkpoint costs about 2.4 GB resident while loaded, so it is not kept around:
- Idle unload. After 3 minutes with no decisions the sidecar drops the checkpoint and returns the
memory (measured: 2,398 MB β 320 MB). The next decision wakes it in the background β the game
falls back to its local director for the few seconds that takes. Tune with
LAYA_IDLE_UNLOAD(seconds; 0 disables). - Nothing runs until it is needed. In screensaver-helper mode the sidecar is not started at login: it starts when the screensaver first asks for people, and is stopped entirely if the screensaver stays away for 10 minutes. An idle Mac runs the helper alone, at ~26 MB.
- Watch it yourself:
curl -s localhost:8777/statusreportsstate(ready/sleeping/loading), andtop -l 1 -pid $(pgrep -f LayaDirector) -stats memshows the real footprint (psRSS under-reports it badly β it showed 46 MB for a 2.4 GB process).
- Vision
VNDetectHumanRectanglesRequestβ body rectangles only. Optional face-box assist (VNDetectFaceRectanglesRequest, on by default, toggle in Debug) adds a head-and-shoulders box when someone sits too close for body detection: rectangles only, no landmarks, no recognition, no identity, nothing kept between frames. - Pixel buffers are processed in the capture callback and released; no file output, no recording,
no frame persistence, no network except
127.0.0.1to the sidecar (HF_HUB_OFFLINE=1). - Ids are per-session counters (
person-N); characters are random per track. - Camera stops on quit/mode switch; the sidecar is terminated on quit and self-exits if orphaned.
Sources/MacAttackCore/ (no AVFoundation/Vision/SpriteKit β reusable for the Phase 2 saver)
Game/ Models (Person, GameEvent, EffectKindβ¦), GameState + GameSnapshot, GameEngine, Narrator
Director/ GameDirector, RandomDirector, Sampler, DirectorCoordinator (timeouts/fallback/health)
Laya/ LayaAdapter (HTTP client + LayaDecisionMapper), LayaSidecar (process lifecycle)
Perception/ PersonTracker
Simulation/ SimulationWorld
Sources/MacAttack/
App/ Camera/ Perception/ (VisionPersonDetector) Rendering/ (GameScene, CharacterNode, FXLayer) Debug/
LayaDirector/ server.py, questions.py, run.sh, requirements.txt
scripts/ build_app.sh, test.sh, soak.sh
Tests/MacAttackCoreTests/
- Laya is a classifier, not a planner: "direction" is question design + sampling. It is noticeably
opinionated on some questions (e.g.
projectilestrongly prefers duck rain in some situations); the anti-repeat weight and chaos temperature keep things varied. - Laya latency on MPS is ~300β600 ms, up to ~1 s while the camera and Vision are also busy; decisions that exceed 2 s fall back locally. First model load takes ~10β40 s (fallback director meanwhile).
- The sidecar needs ~1 GB+ (unified memory) for the English checkpoint.
- Body detection is weak when only a face is visible; face-box assist covers it. Very fast motion can briefly swap ids between two people who cross.
- Tracking is 2-D and approximate; approaching/retreating is inferred from box size.
- Ad-hoc signing can re-trigger the camera prompt after rebuilds.
- SwiftUI's
@Stateis a macro in the macOS 27 SDK whose plugin ships only with Xcode, so the app avoids it;scripts/test.shpasses the swift-testing plugin path explicitly for the same reason.
Mac Attack is also a real macOS screensaver (System Settings βΊ Screen Saver βΊ Mac Attack).
Why there are two pieces. macOS never gives a screensaver camera access: a .saver runs inside
Apple's sandboxed legacyScreenSaver host, and a camera request there is attributed to that host
and refused without ever prompting (measured, not assumed β see Sources/MacAttackSaver). Anything
the saver spawns inherits that sandbox, and open is blocked too. So:
MacAttack.app --helper (launchd agent, normal sandbox-free user session)
βββ camera + Vision β anonymous person boxes only
βββ Laya sidecar β 127.0.0.1:8777
βββ serves 127.0.0.1:8778 β { camera, tracks[ id,x,y,w,h,vx,vy,movement,dwell ] }
β (no images, ever)
MacAttack.saver β polls 10Γ/s, runs the game engine, renders, asks Laya
The helper keeps the camera off until the screensaver actually asks for people (a lease), and switches it off again a few seconds after the screensaver stops. The menu bar item shows which it is.
The screensaver draws the cartoon world only β it cannot show the camera image, because it never receives one.
git clone https://github.com/dockndevai/mac-attack.git && cd mac-attack
python3 -m venv LayaDirector/.venv && LayaDirector/.venv/bin/pip install -r LayaDirector/requirements.txt
./scripts/build_app.sh # builds build/MacAttack.app
./scripts/build_saver.sh --install # builds + installs ~/Library/Screen Savers/MacAttack.saver
open build/MacAttack.app # allow the camera when macOS asksThen:
- In the app, tick Debug Mode β SCREENSAVER HELPER β Install Helper (runs at login).
- System Settings βΊ Screen Saver βΊ Mac Attack, and set "Start Screen Saverβ¦" to a few minutes.
The first Laya decision needs the model in ~/.cache/huggingface (~2.2 GB, downloaded on first run
of the sidecar). Until it is ready the local fallback director runs the game.
To remove: Remove Helper in the app, delete ~/Library/Screen Savers/MacAttack.saver, and
launchctl bootout gui/$UID/local.macattack.helper if it is still loaded.
- No camera image on screen (by design and by sandbox).
- It does not run on the macOS lock/login screen: Apple only runs its own screensavers there, and there is no user session for the helper before login.
- Ad-hoc signing means a rebuild can invalidate the camera grant; the helper then re-requests it.
./scripts/test.sh: 24/24 pass (tracker enter/leave/flicker/multi-person/motion, engine full loop, hold-back, escapeβidle, stale target, stuck directorβlocal fallback, transform, 50Γ enter/leave, Laya mapping, sampling, snapshot contains only abstract fields, unreachable Layaβfallback, sim bounds).- Camera mode (live): permission prompt, preview, Vision detection ~8.5 fps at ~25 ms, person β character, Laya READY on MPS directing events.
- Soak
scripts/soak.sh 40(simulation autopilot + chaos, isolated instance): 40 min, ~2,290 s of game time, 455 events (407 Laya / 57 fallback), no crash.- Laya killed at 11 min β fallback took over, watchdog relaunched the sidecar, back to Laya.
- Laya frozen (SIGSTOP) for 60 s at 22 min β decisions timed out to fallback, recovered on thaw.
- SIGTERM of the app β sidecar self-exited (parent watch); normal quit β camera + sidecar stopped.
- App CPU avg 13% (max 36%); RSS 56β647 MB, fluctuating with no upward trend (ended at 59 MB); live effect nodes stayed β€ 15. Sidecar ~0β10% CPU between decisions, ~1 GB unified memory.
- Render fps was ~12 in the soak because its window was occluded (macOS throttles hidden windows); visible windows render at 60 fps.
- Not tested automatically: camera-denied flow (needs
tccutil reset Camera local.macattack) and camera unplug. Both paths show a status card with a Simulation fallback.
Mac Attack is MIT licensed β see LICENSE.
The director is Laya by Convai Innovations, Apache-2.0. Mac Attack does not redistribute the model: the optional setup step downloads it from Hugging Face into your own cache.
Built with Claude Code.
