diff --git a/docs/cli/agent.md b/docs/cli/agent.md index e413df7220..18a304981d 100644 --- a/docs/cli/agent.md +++ b/docs/cli/agent.md @@ -146,6 +146,8 @@ command refuses an unknown one up front. The hosted mint serves these: | `retro` | `actions:read`, `contents:read`, `pull_requests:write`, `issues:write`, `metadata:read` | vertex-ai, github-ro, github-artifacts | | `prioritize` | `contents:read`, `issues:write`, `organization_projects:write`, `metadata:read` | vertex-ai, github-ro | +A `review` agent also gets `readonly_repo: true`: the checked-out repository is made read-only in the sandbox, so a reviewer cannot modify the code it reviews. That matches `harness/review.yaml` in fullsend-ai/agents. + Pick the role whose permissions fit what the agent does. An unknown role fails immediately with this table, rather than returning `403` from the mint the first time the agent runs. To use a role the hosted mint does not serve, you diff --git a/internal/agentnew/render.go b/internal/agentnew/render.go index 5e917bc0d8..ca0ed2935d 100644 --- a/internal/agentnew/render.go +++ b/internal/agentnew/render.go @@ -105,6 +105,7 @@ func buildHarness(opts Options, role Role) (*harness.Harness, error) { Effort: opts.Effort, PostScript: "scripts/post-" + opts.Name + ".sh", TimeoutMinutes: opts.TimeoutMinutes, + ReadonlyRepo: role.ReadonlyRepo, Trigger: opts.Trigger, Env: &harness.EnvConfig{ Runner: map[string]string{ diff --git a/internal/agentnew/render_test.go b/internal/agentnew/render_test.go index 64515f25be..0baf6b8302 100644 --- a/internal/agentnew/render_test.go +++ b/internal/agentnew/render_test.go @@ -375,6 +375,12 @@ func TestRoleImageReachesTheHarness(t *testing.T) { if h.OpenShell == nil || !reflect.DeepEqual(h.OpenShell.Profiles, role.Profiles) { t.Errorf("role %q: profiles = %v, want %v", name, h.OpenShell, role.Profiles) } + // readonly_repo must survive into the emitted YAML, not only sit on + // the Role struct: a generated review harness that ships writable + // lets the reviewer modify the code it reviews. + if h.ReadonlyRepo != role.ReadonlyRepo || h.ReadonlyRepo != (name == "review") { + t.Errorf("role %q: readonly_repo = %v, want %v", name, h.ReadonlyRepo, name == "review") + } seen[role.Image] = true } // Both image constants must be reachable, or one is dead configuration. diff --git a/internal/agentnew/roles.go b/internal/agentnew/roles.go index 461672b81b..70cb78e882 100644 --- a/internal/agentnew/roles.go +++ b/internal/agentnew/roles.go @@ -38,6 +38,10 @@ type Role struct { Profiles []string // Image is the sandbox image this role's agents run under. Image string + // ReadonlyRepo mirrors the fleet: the review harness makes the checked-out + // repository read-only in the sandbox, so a reviewer cannot modify the + // code it reviews. Set for roles whose fleet harness sets `readonly_repo`. + ReadonlyRepo bool } // roleTable is the set of roles `agent new` will generate for. Excluded on @@ -60,9 +64,10 @@ var roleTable = map[string]Role{ "contents": "read", "pull_requests": "write", "issues": "write", "checks": "read", "metadata": "read", }, - Providers: []string{"providers/vertex-ai.yaml", "providers/github-ro.yaml"}, - Profiles: []string{"profiles/fullsend-vertex-ai.yaml", "profiles/fullsend-github-ro.yaml"}, - Image: config.DefaultCodeImage, + Providers: []string{"providers/vertex-ai.yaml", "providers/github-ro.yaml"}, + Profiles: []string{"profiles/fullsend-vertex-ai.yaml", "profiles/fullsend-github-ro.yaml"}, + Image: config.DefaultCodeImage, + ReadonlyRepo: true, }, "coder": { Name: "coder", diff --git a/internal/agentnew/roles_test.go b/internal/agentnew/roles_test.go index 0208526ac0..2cc3fea0db 100644 --- a/internal/agentnew/roles_test.go +++ b/internal/agentnew/roles_test.go @@ -126,3 +126,15 @@ func TestCoderUsesEmbeddedGithubProvider(t *testing.T) { t.Errorf("coder should use providers/github.yaml, got %v", role.Providers) } } + +// TestReviewRoleMountsTheRepositoryReadOnly pins fleet parity: the review +// harness in fullsend-ai/agents sets readonly_repo, and only the review role +// does. +func TestReviewRoleMountsTheRepositoryReadOnly(t *testing.T) { + for _, name := range RoleNames() { + want := name == "review" + if got := roleTable[name].ReadonlyRepo; got != want { + t.Errorf("role %q: ReadonlyRepo = %v, want %v", name, got, want) + } + } +}