forked from bots-garden/ori
| 🛟 Updated. | 1 | # Scripts |
| 2 | ||
| 3 | *[Version française](README.fr.md)* | |
| 4 | ||
| 5 | ## `launch-ori.applescript` — start the sandbox and open ori-desktop | |
| 6 | ||
| 7 | One gesture instead of two commands: the script starts (or restarts) the `ori` sandbox, waits until the ori server answers, then opens the desktop app. | |
| 8 | ||
| 9 | What it does, in order: | |
| 10 | ||
| 11 | 1. Finds the repository root from its own location (`<repo>/scripts/…`). Set the `repoDirOverride` property at the top of the file if you move it elsewhere. | |
| 12 | 2. Checks that `ori-desktop/build/bin/ori-desktop.app` exists; otherwise shows how to build it (`cd ori-desktop && wails build && xattr -cr build/bin/ori-desktop.app`). | |
| 13 | 3. If `sbx ls -q` already lists a sandbox named `ori`, restarts it with `sbx run -d --name ori`. Otherwise creates it: | |
| 14 | ```bash | |
| 15 | sbx run -d claude . --template k33g/ori:0.0.1 --kit ./kits/ori --name ori -p 5555:8888 | |
| 16 | ``` | |
| 17 | 4. Polls `http://localhost:5555/healthz` every 2 s, up to 90 s (`healthTimeoutSeconds`). If the server never answers it still opens the app and tells you where to look: `sbx exec ori cat /var/log/sbx-kit-startup.log`. | |
| 18 | 5. Opens `ori-desktop.app`, which auto-connects to the server URL it remembered last time (`~/Library/Application Support/ori-desktop/settings.json`, key `serverUrl`). Set it to `http://localhost:5555` on the first connection screen. | |
| 19 | ||
| 20 | Template, kit, ports, sandbox name and timeout are `property` lines at the top of the script. | |
| 21 | ||
| 22 | ### Run it from a terminal | |
| 23 | ||
| 24 | ```bash | |
| 25 | osascript scripts/launch-ori.applescript | |
| 26 | ``` | |
| 27 | ||
| 28 | ### Make it double-clickable | |
| 29 | ||
| 30 | Compile the script into an application bundle: | |
| 31 | ||
| 32 | ```bash | |
| 33 | osacompile -o "scripts/Launch Ori.app" scripts/launch-ori.applescript | |
| 34 | ``` | |
| 35 | ||
| 36 | - Double-click `scripts/Launch Ori.app` in the Finder, drag it to the Dock, or launch it from Spotlight ("Launch Ori"). | |
| 37 | - The `.app` is a build artefact and is gitignored (`scripts/*.app/`). Rebuild it after every edit of the `.applescript`. | |
| 38 | - Built locally, it carries no quarantine attribute, so Gatekeeper does not block it. macOS may ask once for permission to show notifications. | |
| 39 | - Progress is reported with notifications; a hard failure (app not built, `sbx run` failing, usually because Docker Desktop is not running) opens an alert dialog. | |
| 40 | ||
| 41 | ### Why these choices | |
| 42 | ||
| 43 | - **Finder launches get a minimal `PATH`** without `/opt/homebrew/bin`, so the script exports it before every shell command. | |
| 44 | - **`sbx run -d`** (detached) returns as soon as the sandbox exists, and exempts it from sbx's 30 s auto-stop. The kit then starts the ori server asynchronously, hence the health poll before opening the app. | |
| 45 | - **Restart instead of recreate** when the sandbox exists: re-running the create command would collide on the name, and `sbx rm` + create would lose the sandbox's Claude session. | |
| 46 | ||
| 47 | ### Test the handlers without creating a sandbox | |
| 48 | ||
| 49 | ```bash | |
| 50 | osacompile -o /tmp/launch-ori.scpt scripts/launch-ori.applescript | |
| 51 | osascript -e 'set s to load script POSIX file "/tmp/launch-ori.scpt" | |
| 52 | set s'"'"'s healthTimeoutSeconds to 4 | |
| 53 | return s'"'"'s waitForServer("http://localhost:5555")' # false unless something answers on :5555 | |
| 54 | ``` |