nandi/oripublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

launch-ori.applescript · 84 lines · 3.6 KBAppleScript Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
-- 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 (<repo>/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

-- <repo>/scripts/<this file or app> → <repo>
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 <url>/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