| 1 | package runner |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/runner/egress" |
| 5 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 6 | "amadan.net/oficina/equipo/internal/runner/provider/claude" |
| 7 | "amadan.net/oficina/equipo/internal/runner/provider/codex" |
| 8 | "context" |
| 9 | "os" |
| 10 | "path/filepath" |
| 11 | ) |
| 12 | |
| 13 | // PolicyInputs builds a provider policy's inputs from the runner's own |
| 14 | // configuration; the policy hash is computed from them on every launch. It |
| 15 | // grants no authority: the caller still needs a verified account lease. |
| 16 | func PolicyInputs(ctx context.Context, c Config, s provider.Selection, binding provider.Binding, work, step, policyScratch string, withoutAccess ...bool) (provider.PolicyInputs, error) { |
| 17 | r := Runtime{cfg: c} |
| 18 | configured, _, err := r.binding(s) |
| 19 | if err != nil { |
| 20 | return provider.PolicyInputs{}, err |
| 21 | } |
| 22 | if configured.ID != binding.ID || configured.ProviderHome != binding.CredentialHome || configured.ExpectedIdentity != binding.Expected { |
| 23 | return provider.PolicyInputs{}, provider.ErrIdentity |
| 24 | } |
| 25 | denies, err := r.policy(ctx, s) |
| 26 | if err != nil { |
| 27 | return provider.PolicyInputs{}, err |
| 28 | } |
| 29 | network, err := egress.ProviderPolicy(provider.NetworkContract{Provider: s.Provider}, binding.VerifiedDedicatedHome()) |
| 30 | if err != nil { |
| 31 | return provider.PolicyInputs{}, err |
| 32 | } |
| 33 | runtimeFiles := []provider.Mount{{Source: r.cfg.toolProxy(), Target: "/opt/equipo-tool-proxy", ReadOnly: true}, {Source: r.cfg.bwrap(), Target: "/opt/bwrap", ReadOnly: true}} |
| 34 | binary := r.cfg.ClaudePath |
| 35 | if s.Provider == "codex" { |
| 36 | binary = r.cfg.CodexPath |
| 37 | } |
| 38 | binary, err = filepath.EvalSymlinks(binary) |
| 39 | if err != nil { |
| 40 | return provider.PolicyInputs{}, err |
| 41 | } |
| 42 | runtimeFiles = append(runtimeFiles, provider.Mount{Source: binary, Target: "/opt/" + s.Provider, ReadOnly: true}) |
| 43 | if s.Provider == "codex" { |
| 44 | runtimeFiles = append(runtimeFiles, provider.Mount{Source: r.cfg.CodexCodeModeHostPath, Target: "/opt/codex-code-mode-host", ReadOnly: true}) |
| 45 | } |
| 46 | if step == "implement" && c.GoRoot != "" { |
| 47 | runtimeFiles = append(runtimeFiles, provider.Mount{Source: c.GoRoot, Target: "/opt/go", ReadOnly: true}) |
| 48 | if _, err := os.Lstat(c.moduleCache()); !os.IsNotExist(err) { |
| 49 | runtimeFiles = append(runtimeFiles, provider.Mount{Source: c.moduleCache(), Target: "/opt/go-mod", ReadOnly: true}) |
| 50 | } |
| 51 | } |
| 52 | profile, err := provider.Profile(step) |
| 53 | if err != nil { |
| 54 | return provider.PolicyInputs{}, err |
| 55 | } |
| 56 | in := provider.PolicyInputs{Action: step, Workspace: work, Scratch: policyScratch, RuntimeFiles: runtimeFiles, DeniedPaths: denies.DeniedPaths, EgressHosts: network.Hosts, LauncherVersion: provider.LauncherVersion, BwrapVersion: "0.11.0", Tools: profile.MCPTools()} |
| 57 | if step == "converse" && len(withoutAccess) > 0 && withoutAccess[0] { |
| 58 | in.Tools = provider.WithoutAccess(in.Tools) |
| 59 | } |
| 60 | if s.Provider == "claude" { |
| 61 | in, err = claude.PolicyInputs(binding, in, profile.Specialist, s.Model) |
| 62 | } else { |
| 63 | in, err = codex.PolicyInputs(binding, in, s.Model) |
| 64 | } |
| 65 | if err != nil { |
| 66 | return provider.PolicyInputs{}, err |
| 67 | } |
| 68 | return in, nil |
| 69 | } |
| 70 | |