Skip to content
Source
Sign inSign up
samwillis/jerry
Open History to see the last commit

AGENTS.md

163 lines18.1 KB

1# Developer guide
2​
3Instructions for coding agents and contributors working on Jerry. Run commands from the repository root. The [README](README.md) introduces the app; keep build commands, debugging instructions and implementation details here or in `docs/`.
4​
5## Working on the app
6​
7The bundle identifier and Keychain service are persistent compatibility identifiers. Keep them stable when changing the app’s public name, so existing preferences and credentials remain available. Keychain items must have explicit Jerry display labels; relabel legacy entries without replacing secrets or showing background authentication dialogs.
8​
9- Use Swift, AppKit and SpriteKit for the native macOS app. Keep platform-independent terrain, movement and mission logic in `Packages/ExpeditionCore`.
10- Jerry is the single explorer. AI actions reach controls through his physical movement and interaction; preserve this behavior when changing task execution.
11- Preserve click-through desktop behavior and non-activating dragging. Keyboard capture belongs to manual control and the task input, not idle exploration.
12- Keep local terrain capture separate from AI image sharing. Preserve the explicit permission and sharing settings; store credentials in Keychain. Never commit credentials or local account data.
13- Welcome, Settings and the journal share the notebook theme and native macOS window controls. Reuse the existing rig for character artwork and icons. Keep the menu to at most two levels.
14- Use the plans as design context; dated status notes describe earlier increments. Check current code and validation before treating historical requirements as unfinished work.
15- Run checks relevant to the change. Interactive focus, dragging, native chrome and permission behavior need manual verification; automated geometry checks do not establish those behaviors. Documentation-only edits need link and diff checks, not an app rebuild.
16- Update the relevant docs when behavior or workflows change. Do not claim public distribution readiness for an unsigned local build.
17​
18## Build and run
19​
20Requires Xcode with macOS developer support; deployment target is macOS 14 or later. Currently verified on the development Mac, not on every supported OS version.
21​
22```sh
23./scripts/build.sh
24open build/Build/Products/Debug/Jerry.app
25```
26​
27Or open `Jerry.xcodeproj`, select the **Jerry** scheme and **My Mac**, and run. If Xcode requests signing, select **Sign to Run Locally** for local development. The command-line build disables signing and is intended only for local use.
28​
29Look just above the Dock, near the horizontal centre of the primary display. The primary interface is the menu bar and desktop overlay. Jerry appears in the Dock and the Command–Tab switcher while a regular window is open. Use the Jerry menu bar icon to control or quit it. Quit a running copy before launching a newly built version.
30​
31Debug guides show exposed window tops in green, sides in pink, rescue screen boundaries in teal, and the character's input bounds in yellow. The label reports character state, climbable window count, and visible edge count. Terrain refreshes at approximately 10 Hz and uses window stacking order to subtract covered edges. Guides and geometry remain in logical points on the primary display.
32​
33Window discovery reads IDs, owning process IDs, bounds, layer, and opacity metadata, without reading titles or capturing images. Normal layer-zero windows are terrain candidates; visible application panels can occlude them. The transparent rendering/input panels and prompt, desktop background, and known shell helpers are excluded. Substantial titled Jerry windows, including the journal, are climbable terrain and occlude edges behind them; do not exclude the whole application PID. Terrain occlusion uses rectangles: shadows and transparent regions within a window are not modelled. Rope contact additionally uses a per-window corner radius. A window-detection failure reports `GEOMETRY UNAVAILABLE` and falls back to the screen floor. The expedition stays on the primary display. It hides and suspends during sleep, Space transitions, and detected full-screen Spaces, then refreshes geometry and resets its clock on return. These guards are conservative; full-screen traversal, Stage Manager, and multiple-display expeditions remain unsupported.
34​
35For a development launch with guides enabled, quit the running copy, then run:
36​
37```sh
38build/Build/Products/Debug/Jerry.app/Contents/MacOS/Jerry --debug-terrain
39```
40​
41To inspect geometry availability without launching the overlay:
42​
43```sh
44build/Build/Products/Debug/Jerry.app/Contents/MacOS/Jerry --terrain-report
45```
46​
47The report prints counts and existing screen-capture permission status, and never requests permission. Permission behavior depends on the local machine; do not assume screen-capture access is granted. Consult the validation notes for tested and untested cases. Apple's [window metadata documentation](https://developer.apple.com/documentation/coregraphics/cgwindowlistcopywindowinfo(_:_:)) describes the geometry API.
48​
49## Checks
50​
51```sh
52swift test --package-path Packages/ExpeditionCore
53```
54​
55These tests cover input state, coordinates, terrain, IK, contacts, seeded routing, all travel modes, mission beats, interruption, route continuation after landing, changing-terrain soak scenarios, and runtime policy. Native focus, click-through, and window alignment still require the interactive checks in the manual checklist.
56​
57Quit the running app before native checks to avoid global-shortcut conflicts. For native panel/lifecycle checks (Debug build, no real sleep or Space changes):
58​
59```sh
60build/Build/Products/Debug/Jerry.app/Contents/MacOS/Jerry --native-checks
61```
62​
63For AI integration and journal/settings checks (Debug build):
64​
65```sh
66build/Build/Products/Debug/Jerry.app/Contents/MacOS/Jerry --agent-checks
67```
68​
69For reproducible real-window fixtures, run `./scripts/terrain-fixture.sh`, then launch the printed app executable. `--exercise` makes the fixture move, narrow, cover, and close its own high window. The Debug explorer accepts `--fixture-terrain --start-on-window --trace-movement --performance-report` to isolate those real window records, begin on a top, and report state changes/frame timing. Add `--movement-only` to exercise wandering separately from the mission, or `--start-low --rope-demo --freeze-rope` for a paused rope-descent review. No titles or window images are read. `scripts/measure-process.py PID --seconds 30` reads local CPU time and RSS. See [prototype validation](docs/PROTOTYPE_VALIDATION.md) for results and limitations.
70​
71## Local release package
72​
73```sh
74./scripts/package.sh
75open build/Distribution/Jerry.app
76```
77​
78This produces a host-architecture Release app and `build/Distribution/Jerry-local-arm64.zip` on Apple Silicon. It is an unsigned local prototype. Developer ID signing and notarisation are still needed before distributing it to other Macs. The app prevents a second expedition instance from launching; quit the existing copy before switching builds.
79​
80## Developer ID signing and notarisation
81​
82Sign in through **Xcode → Settings → Apple Accounts**; signing in to the Apple Developer app alone does not add an Xcode account. Select the distribution team and install a **Developer ID Application** certificate with its private key. An active membership and suitable team permissions are required. Do not change the existing bundle identifier when selecting a team.
83​
84```sh
85./scripts/package-signed.sh "Developer ID Application: Company (TEAMID)" TEAMID
86```
87​
88The script checks the local identity, builds a fresh host-architecture Release app with Hardened Runtime and a secure timestamp, omits the debugger entitlement, and verifies its signature. Signed app bundles stay in `~/Library/Developer/Jerry/SignedRelease` rather than synced Documents folders, where Finder metadata can invalidate strict signature verification. Direct-distribution builds run outside App Sandbox because Jerry interacts with other applications; Accessibility and Screen Recording permissions remain required where applicable. The local unsigned build workflow is unchanged.
89​
90For notarisation, first store credentials using `xcrun notarytool store-credentials jerry-notary` in a user-controlled Terminal session, or configure a suitable App Store Connect API key. Keep passwords, keys and certificates outside the repository. Then pass the Keychain profile as the third argument:
91​
92```sh
93./scripts/package-signed.sh "Developer ID Application: Company (TEAMID)" TEAMID jerry-notary
94```
95​
96The script submits to Apple, staples and validates the ticket, checks Gatekeeper, then recreates the ZIP in `build/SignedDistribution`. A signature-only ZIP is labelled as not notarised and should not replace the notarised download. For interactive notarisation without separate credentials, archive with the same signing settings (and `CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO`), then use Xcode Organizer’s direct-distribution workflow. Do not pass `SKIP_INSTALL=NO` globally: it also installs the Swift package object and turns the archive into a generic archive. The equivalent command-line export uses `method=developer-id`, `destination=upload`, `teamID`, and manual signing in an export-options plist, then `xcodebuild -exportArchive -allowProvisioningUpdates`. After Apple finishes processing, `xcodebuild -exportNotarizedApp -archivePath … -exportPath …` exports the notarised app. Verify the staple and Gatekeeper result before packaging. An unsigned local build does not validate this workflow. Test desktop permissions, Keychain access, AI sign-in and physical interactions with the signed build before publishing it.
97​
98## Structure
99​
100- `Jerry/App`: lifecycle, menu bar controls and the shared desktop permission/setup flow.
101- `Jerry/Overlay`: transparent, non-activating overlay and display layout.
102- `Jerry/Desktop`: window metadata discovery and platform filtering.
103- `Jerry/Agent`: AI providers, credentials, computer interaction, Settings and the journal.
104- `Jerry/Rendering`: shared explorer rig, painted parts, mission props, ropes, and development guides.
105- `Jerry/Playground`: Debug-only clip controls, fake terrain, contact editing, and scale comparison.
106- `Packages/ExpeditionCore`: platform-independent geometry, terrain construction, attachments, movement, route planning, mission rules, and runtime policy.
107- [Implementation plan](docs/IMPLEMENTATION_PLAN.md), [product plan](docs/PLAN.md), and [manual checks](docs/MANUAL_TESTS.md).
108​
109## Journal persistence
110​
111The journal saves to `~/Library/Application Support/Jerry/Expeditions/<UUID>/journal.jsonl`. Preserve the versioned append-only records and per-expedition directories. Journal photographs are local JPEG assets referenced by optional UUID filenames on entries; never automatically attach them to AI requests. Keep writes off the main thread, preserve streaming deltas and flush task/shutdown boundaries. A restored task must remain paused until the user gives a direction; never replay saved computer actions automatically. Credentials and opaque provider transcripts do not belong in journal files. Tests must pass `journalDirectory: nil` / `storageDirectory: nil` or use disposable directories, never the real history. See [journal storage](docs/JOURNAL_STORAGE.md).
112​
113## Jerry On Line
114​
115JOL is optional. `Jerry/Agent/JOL*` owns native discovery, Keychain sign-in, committed journal synchronization and remote command coordination; `jol/` contains the Neon Functions server, web reader, schema and fixtures. Never start networking or read real history from a fixture. Keep remote missions disabled on launch and pause them for local takeover. All remote tasks go through Jerry’s existing physical-action pipeline. Do not replay ambiguous computer actions after a disconnect or expired lease.
116​
117Use `npm --prefix jol ci`, `npm --prefix jol run check`, `npm --prefix jol test` and `npm --prefix jol run build` from the repository root. `npm --prefix jol run preview` binds a synthetic web fixture to loopback only. `--jol-preview` opens the native Settings page without starting a connection. Hosted integration checks are explicitly opt-in (`npm --prefix jol run check:hosted`); they use gitignored deployment configuration and synthetic accounts/data. See [JOL setup and validation](docs/JOL_SETUP.md) before provisioning or deploying. Keep `.env*`, `.neon`, `.data`, credentials and deployed bundle outputs out of Git.
118​
119Legacy login-Keychain ACL changes may ignore a modern no-UI query flag. Credential status checks first inspect display attributes and avoid unnecessary relabelling; their synchronous `nonInteractiveKeychain` scope restores the previous interaction setting before returning. Keep that scope on the MainActor without suspension. Explicit sign-in/save actions are separate from background status reads.
120​
121## Global shortcuts
122​
123**Settings → Controls → Global shortcuts** records the Take/release control and Ask Jerry bindings. Each can be cleared with Delete while recording; Escape cancels, and Restore defaults resets both. Custom combinations require Command, Option or Control and are saved in UserDefaults. The menu and welcome guide reflect the current bindings.
124​
125`Jerry/App/GlobalShortcuts.swift` owns the shortcut value, preferences, local recorder and Carbon registration. Rebinding must retain the previous registration on conflict. Recording temporarily unregisters both global shortcuts and intercepts keys only in the Settings key window; commit/probe happens after key-up. Cancel, focus loss, section changes and closing Settings must restore registrations. No global keyboard monitor or extra Accessibility permission is needed for configuration. Native checks use an isolated preferences domain for persistence tests and exercise registration changes, conflicts, held-key suppression and clearing.
126​
127## Trigger an activity
128​
129Enable **Developer Tools** in **Settings → Advanced**, then use Jerry menu → **Developer Tools** for walking, climbing, grappling, rope actions, parachuting or looking for the sock. The explorer approaches suitable real terrain first, then performs the activity and returns to the idle-exploration setting. Unreachable choices are labelled and disabled. Requests made during a jump/corner/flight queue safely for the next support. **Enable Idle Exploration** controls automatic wandering after the action finishes.
130​
131Climbs now pull over the lip into a planted-foot standing pose; rope descents crouch and back over the lip; parachute trips crouch and jump clear before deploying. The rope pins on the top edge, follows its window’s rounded corner (12 points for notebook windows, an estimated 16 on macOS 26+ or 10 on older macOS for external windows), and leaves along the mathematical tangent towards the hands. Both straight-to-curve joins remain tangent as the explorer descends.
132​
133Grapple launches are limited to 35° from vertical at the muzzle, or 10° within one point of the viewport floor. `GrappleLaunchPolicy` is shared by graph routes, manual/AI aim and the final autonomous launch check. Floor graph vertices include points beneath exposed roofs so a route can walk into position before firing. These limits do not constrain the subsequent swing of an attached rope.
134​
135Aiming shows a green snapped rim when it is reachable, or an orange marker when no valid anchor is selected. Starting aim suggests a nearby rim; holding G redirects the arrows from movement/swinging to aiming. Release G to fire and return the arrows to movement. The mouse does not steer the aim. Refiring while hanging keeps the old rope attached while the new hook flies. The explorer transfers to the new line only after it latches; a failed shot leaves the old line intact. Left/right applies force along the rope tangent, with a 260 pt/s drive cap; opposite input brakes the swing.
136​
137## Animation playground
138​
139Enable Developer Tools in **Settings → Advanced**, then open **Developer Tools → Animation Playground…** from the Jerry menu, or quit the current app and run its executable with `--playground`. Preview every motion (including Landing), switch facing and background, pause/restart, slow playback, show joints, and tune stride, cadence, and bounce. **Preview time (pauses)** freezes an exact frame for inspection. Drag climbing handholds, the rope anchor, the grab pivot, or the body. A small actual-size explorer appears alongside the enlarged version. See [animation workflow and rig details](docs/ANIMATION_WORKFLOW.md).
140​
141The desktop and playground share the same articulated rig and animation controller. Knees bend towards the toes; elbow poles favour the back of the body. The desktop now drives those same movement poses from real surface routes. Use the shared rig rather than introducing separate desktop and playground artwork.
142​
143The explorer now has a painted material finish with soft highlights, fabric/canvas detail, leather boots, warm skin shading, and contrasting coloured outlines. **Flat shading** in the playground compares it with simple fills. The existing silhouettes, proportions, and movement are preserved.
144​
145## Application icon
146​
147The app icon uses Jerry’s actual rig on a warm paper tile. The master is `Jerry/Resources/AppIcon.png`; both builds bundle `AppIcon.icns`. Run `./scripts/render-app-icon.sh` to regenerate the master and native macOS sizes after character artwork changes. The exporter bakes geometry at icon resolution and leaves normal desktop rendering unchanged.
148​
149## Internal-window capture checks
150​
151For repeatable development checks, run the Debug executable with `--feature-checks` (uses existing Screen Recording access and creates its own disposable capture window). `scripts/terrain-fixture.sh` builds a scrollable test window; launch its executable with `--internal-terrain`, then launch Debug Jerry with `--inside-windows --fixture-terrain --debug-terrain`. These flags do not persist the opt-in setting.
152​
153## Documentation
154​
155- [Product plan and future ideas](docs/PLAN.md)
156- [Implementation plan](docs/IMPLEMENTATION_PLAN.md)
157- [Detailed prototype behavior](docs/PROTOTYPE_GUIDE.md)
158- [Computer-task integration](docs/AGENT_PROTOTYPE.md)
159- [Jerry On Line remote journal and mission proposal](docs/JOL_PLAN.md)
160- [Jerry On Line setup and prototype validation](docs/JOL_SETUP.md)
161- [Animation and rig workflow](docs/ANIMATION_WORKFLOW.md)
162- [Manual test checklist](docs/MANUAL_TESTS.md)
163- [Validation evidence and known limits](docs/PROTOTYPE_VALIDATION.md)