-- launch-ori.applescript — start (or restart) the "ori" sandbox, wait for the -- ori server to answer on the published host port, then open ori-desktop. -- -- Run from a terminal: osascript scripts/launch-ori.applescript -- Build a double-clickable app: -- osacompile -o "scripts/Launch Ori.app" scripts/launch-ori.applescript -- -- The repository root is derived from this file's location (/scripts/…); -- set repoDirOverride if you move the script or the compiled app elsewhere. property sandboxName : "ori" property templateRef : "k33g/ori:0.0.2" property kitPath : "./kits/ori" property hostPort : 5555 property sandboxPort : 8888 property healthTimeoutSeconds : 90 property desktopAppRelPath : "ori-desktop/build/bin/ori-desktop.app" property repoDirOverride : "" on run set repoDir to my resolveRepoDir() -- Finder / Spotlight launches get a minimal PATH without Homebrew. set shellPrefix to "export PATH=/opt/homebrew/bin:/usr/local/bin:$PATH; cd " & quoted form of repoDir & "; " set serverURL to "http://localhost:" & hostPort set appPath to repoDir & "/" & desktopAppRelPath try do shell script "test -d " & quoted form of appPath on error display alert "ori-desktop.app not found" message "Expected at:" & return & appPath & return & return & "Build it first:" & return & "cd ori-desktop && wails build && xattr -cr build/bin/ori-desktop.app" as critical return end try if my sandboxExists(shellPrefix) then -- `sbx run -d --name ori` restarts a stopped sandbox without attaching. -- If it is already running sbx may complain; the health check below -- decides whether that matters, so we only notify here. display notification "Restarting existing sandbox “" & sandboxName & "”…" with title "Ori" try do shell script shellPrefix & "sbx run -d --name " & quoted form of sandboxName on error errMsg display notification "sbx run --name: " & errMsg with title "Ori" end try else display notification "Creating sandbox “" & sandboxName & "” from " & templateRef & "…" with title "Ori" try do shell script shellPrefix & "sbx run -d claude . --template " & quoted form of templateRef & " --kit " & quoted form of kitPath & " --name " & quoted form of sandboxName & " -p " & hostPort & ":" & sandboxPort & "/tcp" on error errMsg display alert "sbx run failed" message errMsg & return & return & "Is Docker Desktop running?" as critical return end try end if if my waitForServer(serverURL) then display notification "Server ready at " & serverURL with title "Ori" else display notification "No answer on " & serverURL & "/healthz after " & healthTimeoutSeconds & " s — opening the app anyway. Check: sbx exec ori cat /var/log/sbx-kit-startup.log" with title "Ori" end if do shell script "open " & quoted form of appPath end run -- /scripts/ on resolveRepoDir() if repoDirOverride is not "" then return repoDirOverride set scriptPath to POSIX path of (path to me) return do shell script "d=" & quoted form of scriptPath & "; d=${d%/}; cd \"$(dirname \"$d\")/..\" && pwd" end resolveRepoDir on sandboxExists(shellPrefix) set names to do shell script shellPrefix & "sbx ls -q 2>/dev/null || true" return (paragraphs of names) contains sandboxName end sandboxExists -- Poll GET /healthz every 2 s until it answers 2xx or the budget runs out. on waitForServer(serverURL) set attempts to healthTimeoutSeconds div 2 try do shell script "for i in $(seq 1 " & attempts & "); do curl -sf -m 2 " & quoted form of (serverURL & "/healthz") & " >/dev/null && exit 0; sleep 2; done; exit 1" return true on error return false end try end waitForServer