Read-only enforcement applies to stages with shell but no edit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:55:10 +00:00
parent 87016ef5dc
commit 57ea922c59
7 changed files with 22 additions and 17 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ the server's provider/model. Read `references/format.md` and
`land`. A `type=check` stage runs listed shell commands on the server, no
model, and routes on `pass`/`fail`: put one before review and use one with
`delivery=true` as the landing gate rather than having a model run the suite.
Stages without `edit` must not change the workspace (the server fails the
Stages with `shell` but no `edit` must not change the workspace (the server fails the
visit); give reviewers a `permissions.shell` allow-list.
Keep prompts short and objective: what the stage should produce and any real
+2 -2
View File
@@ -117,7 +117,7 @@ evidence route to `blocked` when declared, else `error`; never fabricate a resul
only when the user asks or a measured visit exists (`references/practices.md`).
- `delivery=true`: the landing stage's gate (below), on any harness, or on a
check stage.
- `allow_workspace_changes=true`: lets a stage without `edit` leave file changes
- `allow_workspace_changes=true`: lets a stage with `shell` but no `edit` leave file changes
in the run directory (below).
- `auto_skip=false`: disable the server skip fallback for a stage that declares a
`skipped` edge (`references/operations.md`, Server skip fallback).
@@ -144,7 +144,7 @@ prefix (`git diff *` -> `Bash(git diff:*)`, any arguments; claude only). Claude
Code checks each part of a chained command, and every other command is
refused. A read-only reviewer: `{"shell":["git diff *","git log *","go test ./..."]}`.
A stage whose `tools` block lacks `edit` must leave the run directory as it
A stage whose `tools` block has `shell` but not `edit` must leave the run directory as it
found it: the server compares the workspace before and after the visit and
fails the visit (`permission denied: ... changed the workspace (added x, ...)`,
following the `error` edge) when any file changed, outside the run's artifact
+1 -1
View File
@@ -126,7 +126,7 @@ func TestChatTurnDiffMarksBoundedPatchesTruncated(t *testing.T) {
dir := gitRepo(t, map[string]string{"a.txt": "x\n"})
h := turnDiffHub(t, dir)
h.startRoomTurnDiff("ses_1")
writeTurnFile(t, dir, "big.txt", strings.Repeat("line\n", 6000))
writeTurnFile(t, dir, "big.txt", strings.Repeat("line\n", 21000))
endDiffTurn(h, "ses_1")
turns := recordedTurns(t, h, "ses_1")
if len(turns) != 1 || !turns[0].Truncated || turns[0].Files != 1 || turns[0].Status != "partial" {
+13 -6
View File
@@ -68,20 +68,27 @@ func checkVerdict(output stage.Values) *protocol.StageVerdict {
return &protocol.StageVerdict{Reason: summary, ReasonSource: protocol.VerdictReasonFallback}
}
// readOnlyViolation reports the files a stage without edit left changed in
// the run directory. Paths under the stage's artifacts directory, the run's
// shared public directory and a harness state directory that lives inside the
// workspace (for example CLAUDE_CONFIG_DIR) are the harness's or the run's own
// and are not counted. It returns "" when the stage may change files or none
// changed.
// readOnlyViolation reports the files a stage with shell but without edit
// left changed in the run directory: its shell is for reading, testing and
// committing, not for writing. A stage without shell cannot write at all (a
// change during it is not its own), and a stage with edit may write. Paths
// under the stage's artifacts directory, the run's shared public directory and
// a harness state directory that lives inside the workspace (for example
// CLAUDE_CONFIG_DIR) are the harness's or the run's own and are not counted.
// It returns "" when the stage may change files or none changed.
func readOnlyViolation(def stage.Definition, tools []string, explicitTools bool, changes *protocol.StageFileChanges, workspace string, ignored []string) string {
if stage.EffectiveType(def.Type) != stage.ModelType || !explicitTools || def.Configs["allow_workspace_changes"] == "true" || changes == nil {
return ""
}
shell := false
for _, tool := range tools {
if tool == "edit" {
return ""
}
shell = shell || tool == "shell"
}
if !shell {
return ""
}
var prefixes []string
for _, dir := range ignored {
+2 -1
View File
@@ -195,7 +195,8 @@ func TestReadOnlyViolationIgnoresHarnessAndRunDirectories(t *testing.T) {
t.Fatal(v)
}
for name, ok := range map[string]bool{
"edit tool": readOnlyViolation(def, []string{"edit"}, true, changes, "/w", nil) == "",
"edit tool": readOnlyViolation(def, []string{"edit", "shell"}, true, changes, "/w", nil) == "",
"no shell (cannot write)": readOnlyViolation(def, []string{"read"}, true, changes, "/w", nil) == "",
"no tools block (legacy bundle)": readOnlyViolation(def, nil, false, changes, "/w", nil) == "",
} {
if !ok {
+2 -5
View File
@@ -597,10 +597,7 @@ esac
runStage := func(name, tools string) (status, sessions, diagnostic string) {
t.Helper()
workspace := t.TempDir()
// The fake harness keeps its counters outside the workspace: a read-only
// stage must leave the run directory unchanged.
state := t.TempDir()
script := strings.ReplaceAll(scriptTemplate, "@STATE@", state)
script := strings.ReplaceAll(scriptTemplate, "@STATE@", workspace)
if err := os.WriteFile(executable, []byte(script), 0700); err != nil {
t.Fatal(err)
}
@@ -626,7 +623,7 @@ esac
if len(detail.Steps) > 0 {
diagnostic = detail.Steps[0].Diagnostic
}
if data, err := os.ReadFile(filepath.Join(state, "sessions")); err == nil {
if data, err := os.ReadFile(filepath.Join(workspace, "sessions")); err == nil {
sessions = strings.TrimSpace(string(data))
}
return detail.Status, sessions, diagnostic
+1 -1
View File
@@ -111,7 +111,7 @@ func (ModelStage) Spec(def Definition) (ModelSpec, error) {
if value := def.Configs["auto_skip"]; value != "" && value != "true" && value != "false" {
return ModelSpec{}, fmt.Errorf("auto_skip must be true or false")
}
// allow_workspace_changes=true lets a stage without edit leave file changes
// allow_workspace_changes=true lets a stage with shell but no edit leave file changes
// in the run directory; by default the runner fails such a visit.
if value := def.Configs["allow_workspace_changes"]; value != "" && value != "true" && value != "false" {
return ModelSpec{}, fmt.Errorf("allow_workspace_changes must be true or false")