summaryrefslogtreecommitdiff
path: root/acp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'acp.lua')
-rw-r--r--acp.lua60
1 files changed, 52 insertions, 8 deletions
diff --git a/acp.lua b/acp.lua
index dc4abdb..7036011 100644
--- a/acp.lua
+++ b/acp.lua
@@ -68,17 +68,33 @@ local function private_profile()
local st=assert(uv.fs_lstat(dir)); assert(st.mode & 63==0 and uv.fs_access(dir,'W') and uv.fs_access(dir,'X'),'Google profile must be private and writable')
return dir
end
+local is_macos = uv.os_uname().sysname == 'Darwin'
+local panto = assert(uv.fs_realpath(uv.exepath()))
local function executable()
- assert(uv.os_uname().sysname=='Darwin','Google signature verification requires macOS')
for dir in (os.getenv('PATH') or ''):gmatch('[^:]+') do
- if dir:sub(1,1)=='/' and uv.fs_access(dir..'/agy','X') then return assert(uv.fs_realpath(dir..'/agy')) end
+ if dir:sub(1,1)=='/' and uv.fs_access(dir..'/agy','X') then
+ local bin = assert(uv.fs_realpath(dir..'/agy'))
+ if not is_macos then
+ local st = assert(uv.fs_stat(bin))
+ local uid = uv.getuid()
+ assert(st.type=='file' and (st.uid==uid or st.uid==0) and st.mode & 18==0,
+ 'agy binary must be owned by you or root and not group/world writable')
+ end
+ return bin
+ end
end
error('agy is not on PATH')
end
+local env_keys = {'USER','PATH','TMPDIR','LANG'}
+if not is_macos then
+ for _,k in ipairs({'DBUS_SESSION_BUS_ADDRESS','XDG_RUNTIME_DIR','GNOME_KEYRING_CONTROL','DISPLAY','WAYLAND_DISPLAY','XAUTHORITY'}) do
+ env_keys[#env_keys+1] = k
+ end
+end
-- The chat transport and the fixed read-only usage query share this trust boundary.
-- Neither inherits API keys or a user's default CLI profile.
local function verified(run, on_error)
- local finished, checker, watchdog = false, nil, uv.new_timer()
+ local finished, checker, watchdog = false, nil, nil
local function cancel()
if finished then return end
finished=true; close(watchdog)
@@ -86,12 +102,18 @@ local function verified(run, on_error)
end
local ok,err=pcall(function()
local bin,profile=executable(),private_profile()
- -- Isolate CLI settings via --gemini-dir, not HOME: macOS needs the
- -- user's home to find the default login Keychain.
+ -- Isolate CLI settings via --gemini-dir, not HOME: macOS needs HOME for
+ -- the login Keychain, and Unix keyrings also need D-Bus / XDG session vars.
local env={'HOME='..assert(os.getenv('HOME'))}
- for _,k in ipairs({'USER','PATH','TMPDIR','LANG'}) do
+ for _,k in ipairs(env_keys) do
if os.getenv(k) then env[#env+1]=k..'='..os.getenv(k) end
end
+ if not is_macos then
+ finished=true
+ local ran,why=pcall(run,bin,profile,env); if not ran then on_error(tostring(why)) end
+ return
+ end
+ watchdog=uv.new_timer()
watchdog:start(15000,0,function() cancel(); on_error('Google CLI signature check timed out') end)
checker=assert(uv.spawn('/usr/bin/codesign',{args={'--verify','--strict','-R=anchor apple generic and certificate leaf[subject.OU] = "EQHXZ8M8AV" and identifier "cli"',bin}},function(code,sig)
close(checker); checker=nil; if finished then return end
@@ -136,7 +158,29 @@ end
-- agy discovers named agents under <gemini-dir>/config/agents. Declare the
-- relay on the agent itself: session/new MCP servers need not be inherited by
-- custom agents. Never edit the user's agents or global MCP configuration.
-local function relay(s) return {name='pantograph',command='/usr/bin/nc',args={'-U',s.dir..'/mcp'},timeoutSeconds=1800} end
+local relay_script = table.concat({
+ "local uv=require('luv')",
+ "local function close(h) if h and not h:is_closing() then h:close() end end",
+ "local i,o,s=uv.new_pipe(false),uv.new_pipe(false),uv.new_pipe(false)",
+ "local n,eof=0,false",
+ "local function stop(c) close(i); close(s); close(o); if c then os.exit(c) end end",
+ "assert(i:open(0) and o:open(1))",
+ "s:connect(%q,function(err)",
+ "if err then stop(1); return end",
+ "i:read_start(function(e,d)",
+ "if e then stop(1) elseif not d then close(i); if not s:is_closing() then s:shutdown(function() end) end",
+ "elseif not s:is_closing() then s:write(d,function(w) if w then stop(1) end end) end",
+ "end)",
+ "s:read_start(function(e,d)",
+ "if e then stop(1) elseif not d then eof=true; close(i); close(s); if n==0 then close(o) end",
+ "elseif not o:is_closing() then n=n+1; o:write(d,function(w) n=n-1; if w then stop(1) elseif eof and n==0 then close(o) end end) end",
+ "end)",
+ "end)",
+ "uv.run()",
+}, ' ')
+local function relay(s)
+ return {name='pantograph',command=panto,args={'lua','-e',relay_script:format(s.dir..'/mcp')},timeoutSeconds=1800}
+end
local function install_agent(s, profile)
local dir=profile
for _,part in ipairs({'config','agents'}) do
@@ -387,7 +431,7 @@ function M.launch(s, first, resume_id)
cancel_check=verified(function(bin,profile,env)
stdin,stdout=uv.new_pipe(false),uv.new_pipe(false)
local agent=install_agent(s,profile)
- local args={'acp','--agent',agent,'--include-default-customizations=false','--gemini-dir',profile,'--sandbox','--disable-telemetry','--dangerously-skip-permissions'}
+ local args={'acp','--agent',agent,'--include-default-customizations=false','--gemini-dir',profile,'--disable-telemetry','--dangerously-skip-permissions'}
child,pid=uv.spawn(bin,{args=args,cwd=s.cwd,env=env,detached=true,stdio={stdin,stdout,nil}},function()
close(child); child=nil; if closed then cleanup() else s.fail('Antigravity exited; not replaying') end
end); if not child then local err=pid; pid=nil; error(tostring(err)) end; local buf=''