Agent Executor (AX) is Google's open agentic orchestration runtime
Go
Setup ~/.ax/antigravity once until a new update arrives (#278)
Jaana Dogan74731320788e
diff --git a/internal/config/config.go b/internal/config/config.goindex 2af5580..66a9a48 100644--- a/internal/config/config.go+++ b/internal/config/config.go@@ -18,6 +18,7 @@ package configimport ("fmt""os"+ "path/filepath""github.com/google/ax/internal/harness""github.com/google/ax/internal/harness/substrate"@@ -208,3 +209,11 @@ func (c *Config) Validate() error {return nil}++func AXAssetsDir() (string, error) {+ home, err := os.UserHomeDir()+ if err != nil {+ return "", fmt.Errorf("resolving home directory: %w", err)+ }+ return filepath.Join(home, ".ax"), nil+}diff --git a/internal/harness/antigravityinteractions/antigravityinteractions.go b/internal/harness/antigravityinteractions/antigravityinteractions.goindex d3370b6..d09cea7 100644--- a/internal/harness/antigravityinteractions/antigravityinteractions.go+++ b/internal/harness/antigravityinteractions/antigravityinteractions.go@@ -59,6 +59,7 @@ import ("sync""time"+ "github.com/google/ax/internal/config""github.com/google/ax/internal/harness""github.com/google/ax/proto""github.com/google/uuid"@@ -164,11 +165,11 @@ func cloudLocation() string {// kept separate to avoid the agent seeing or clobbering it. New still requires a// non-empty StateDir; callers apply this default.func DefaultStateDir() (string, error) {- home, err := os.UserHomeDir()+ axDir, err := config.AXAssetsDir()if err != nil {- return "", fmt.Errorf("resolving home directory for resume-cursor state: %w", err)+ return "", err}- return filepath.Join(home, ".ax", "antigravityinteractions", "cursors"), nil+ return filepath.Join(axDir, "antigravityinteractions", "cursors"), nil}// AntigravityInteractionsHarness implements Harness by talking to the publicdiff --git a/internal/pythonsidecar/setup.go b/internal/pythonsidecar/setup.goindex 777c184..344189d 100644--- a/internal/pythonsidecar/setup.go+++ b/internal/pythonsidecar/setup.go@@ -22,16 +22,14 @@ import ("os""os/exec""path/filepath"- "strings"++ "github.com/google/ax/internal/config")// SetupOptions configures asset extraction and environment setup for a Python sidecar.type SetupOptions struct {// FS is the embedded filesystem containing Python assets (e.g., python.FS). (Required)FS fs.FS- // TargetDir is the directory on disk where assets will be extracted.- // If empty, it defaults to filepath.Join(os.UserHomeDir(), ".ax"). (Optional)- TargetDir string}// Setup extracts the embedded filesystem assets to TargetDir.@@ -40,35 +38,29 @@ func Setup(ctx context.Context, opts SetupOptions) (string, error) {if opts.FS == nil {return "", fmt.Errorf("SetupOptions.FS cannot be nil")}-- targetDir := opts.TargetDir- if targetDir == "" {- home, err := os.UserHomeDir()- if err != nil {- return "", fmt.Errorf("resolving home directory for python target dir: %w", err)- }- targetDir = filepath.Join(home, ".ax")+ axDir, err := config.AXAssetsDir()+ if err != nil {+ return "", err}-- extractDir := filepath.Join(targetDir, "python")+ extractDir := filepath.Join(axDir, "python")reqPath := filepath.Join(extractDir, "antigravity", "requirements.txt")- result := targetDir + string(os.PathListSeparator) + extractDir-- if err := extractFS(ctx, opts.FS, extractDir); err != nil {+ pythonPath := axDir + string(os.PathListSeparator) + extractDir+ updated, err := extractFS(ctx, opts.FS, extractDir)+ if err != nil {return "", fmt.Errorf("failed to extract embedded assets: %w", err)}- pkgPath, err := install(ctx, reqPath)+ pkgPath, err := install(ctx, reqPath, updated)if err != nil {return "", err}-- return result + string(os.PathListSeparator) + pkgPath, nil+ return pythonPath + string(os.PathListSeparator) + pkgPath, nil}-func extractFS(ctx context.Context, filesystem fs.FS, destDir string) error {- return fs.WalkDir(filesystem, ".", func(path string, d fs.DirEntry, err error) error {+func extractFS(ctx context.Context, filesystem fs.FS, destDir string) (bool, error) {+ var updated bool+ err := fs.WalkDir(filesystem, ".", func(path string, d fs.DirEntry, err error) error {if err != nil {return err}@@ -76,34 +68,42 @@ func extractFS(ctx context.Context, filesystem fs.FS, destDir string) error {return ctx.Err()}+ destPath := filepath.Join(destDir, filepath.FromSlash(path))if d.IsDir() {- return nil+ return os.MkdirAll(destPath, 0755)}- destPath := filepath.Join(destDir, filepath.FromSlash(path))- rel, err := filepath.Rel(destDir, destPath)- if err != nil || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) || rel == ".." {- return fmt.Errorf("illegal file path in embedded FS: %s", path)+ info, err := d.Info()+ if err != nil {+ return err+ }++ stat, err := os.Stat(destPath)+ // If the file already exists on disk with the exact same size,+ // skip copying to preserve its timestamp and avoid false re-installations.+ if err == nil {+ if stat.Size() == info.Size() {+ return nil+ }}if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil {return fmt.Errorf("creating directory for %s: %w", destPath, err)}+ // There is at least, one file updated.+ updated = truesrc, err := filesystem.Open(path)if err != nil {return fmt.Errorf("opening embedded file %s: %w", path, err)}defer src.Close()- info, err := d.Info()mode := os.FileMode(0644)- if err == nil && info.Mode().Perm() != 0 {+ if info.Mode().Perm() != 0 {mode = info.Mode().Perm() | 0200}-_ = os.Chmod(destPath, 0644)-dst, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode)if err != nil {return fmt.Errorf("creating destination file %s: %w", destPath, err)@@ -113,17 +113,27 @@ func extractFS(ctx context.Context, filesystem fs.FS, destDir string) error {_ = dst.Close()return fmt.Errorf("writing file %s: %w", destPath, err)}-if err := dst.Close(); err != nil {return fmt.Errorf("closing file %s: %w", destPath, err)}-return nil})+ return updated, err}-func install(ctx context.Context, reqPath string) (string, error) {+func install(ctx context.Context, reqPath string, install bool) (string, error) {pkgDir := filepath.Join(filepath.Dir(reqPath), "site-packages")+ if !install {+ // Make sure that pip install ran once and we have+ // the dependencies installed under site-packages.+ if _, err := os.Stat(pkgDir); err == nil {+ return pkgDir, nil+ }+ }+ fmt.Println("Setting up Antigravity SDK, this may take a while...")++ // Some corp machines are overriding the indexes, ensure that+ // simple index is included where Antigravity SDK is distributed from.cmd := exec.CommandContext(ctx, "python3", "-m", "pip", "install", "--extra-index-url", "https://pypi.org/simple", "--target", pkgDir, "-r", reqPath)out, err := cmd.CombinedOutput()if err != nil {diff --git a/internal/pythonsidecar/setup_test.go b/internal/pythonsidecar/setup_test.goindex 77a8d6a..cfcf3da 100644--- a/internal/pythonsidecar/setup_test.go+++ b/internal/pythonsidecar/setup_test.go@@ -40,29 +40,27 @@ func TestSetup_EmbeddedFS(t *testing.T) {"proto/ax_pb2.py": &fstest.MapFile{Data: []byte("print('proto')")},}- targetDir := filepath.Join(t.TempDir(), "target")+ targetDir := filepath.Join(t.TempDir(), "home")+ axDir := filepath.Join(targetDir, ".ax")+ t.Setenv("HOME", targetDir)+opts := pythonsidecar.SetupOptions{- FS: testFS,- TargetDir: targetDir,+ FS: testFS,}-gotDir, err := pythonsidecar.Setup(context.Background(), opts)if err != nil {t.Fatalf("Setup() failed: %v", err)}- if !strings.HasPrefix(gotDir, targetDir) {- t.Errorf("expected gotDir to start with targetDir=%q, got %q", targetDir, gotDir)- }if !strings.Contains(gotDir, "python") {t.Errorf("expected gotDir to contain extracted python directory in PYTHONPATH, got %q", gotDir)}// Verify files were extracted under TargetDir/python- harnessPath := filepath.Join(targetDir, "python", "antigravity", "harness_server.py")+ harnessPath := filepath.Join(axDir, "python", "antigravity", "harness_server.py")if _, err := os.Stat(harnessPath); err != nil {t.Errorf("expected file %s to exist, got stat error: %v", harnessPath, err)}- protoPath := filepath.Join(targetDir, "python", "proto", "ax_pb2.py")+ protoPath := filepath.Join(axDir, "python", "proto", "ax_pb2.py")if _, err := os.Stat(protoPath); err != nil {t.Errorf("expected file %s to exist, got stat error: %v", protoPath, err)}