package runner import ( "amadan.net/oficina/equipo/internal/runner/egress" "amadan.net/oficina/equipo/internal/runner/provider" "amadan.net/oficina/equipo/internal/runner/provider/claude" "amadan.net/oficina/equipo/internal/runner/provider/codex" "context" "os" "path/filepath" ) // PolicyInputs builds a provider policy's inputs from the runner's own // configuration; the policy hash is computed from them on every launch. It // grants no authority: the caller still needs a verified account lease. func PolicyInputs(ctx context.Context, c Config, s provider.Selection, binding provider.Binding, work, step, policyScratch string, withoutAccess ...bool) (provider.PolicyInputs, error) { r := Runtime{cfg: c} configured, _, err := r.binding(s) if err != nil { return provider.PolicyInputs{}, err } if configured.ID != binding.ID || configured.ProviderHome != binding.CredentialHome || configured.ExpectedIdentity != binding.Expected { return provider.PolicyInputs{}, provider.ErrIdentity } denies, err := r.policy(ctx, s) if err != nil { return provider.PolicyInputs{}, err } network, err := egress.ProviderPolicy(provider.NetworkContract{Provider: s.Provider}, binding.VerifiedDedicatedHome()) if err != nil { return provider.PolicyInputs{}, err } runtimeFiles := []provider.Mount{{Source: r.cfg.toolProxy(), Target: "/opt/equipo-tool-proxy", ReadOnly: true}, {Source: r.cfg.bwrap(), Target: "/opt/bwrap", ReadOnly: true}} binary := r.cfg.ClaudePath if s.Provider == "codex" { binary = r.cfg.CodexPath } binary, err = filepath.EvalSymlinks(binary) if err != nil { return provider.PolicyInputs{}, err } runtimeFiles = append(runtimeFiles, provider.Mount{Source: binary, Target: "/opt/" + s.Provider, ReadOnly: true}) if s.Provider == "codex" { runtimeFiles = append(runtimeFiles, provider.Mount{Source: r.cfg.CodexCodeModeHostPath, Target: "/opt/codex-code-mode-host", ReadOnly: true}) } if step == "implement" && c.GoRoot != "" { runtimeFiles = append(runtimeFiles, provider.Mount{Source: c.GoRoot, Target: "/opt/go", ReadOnly: true}) if _, err := os.Lstat(c.moduleCache()); !os.IsNotExist(err) { runtimeFiles = append(runtimeFiles, provider.Mount{Source: c.moduleCache(), Target: "/opt/go-mod", ReadOnly: true}) } } profile, err := provider.Profile(step) if err != nil { return provider.PolicyInputs{}, err } 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()} if step == "converse" && len(withoutAccess) > 0 && withoutAccess[0] { in.Tools = provider.WithoutAccess(in.Tools) } if s.Provider == "claude" { in, err = claude.PolicyInputs(binding, in, profile.Specialist, s.Model) } else { in, err = codex.PolicyInputs(binding, in, s.Model) } if err != nil { return provider.PolicyInputs{}, err } return in, nil }