diff --git a/internal/author/skill/SKILL.md b/internal/author/skill/SKILL.md index f2009c88..aef76850 100644 --- a/internal/author/skill/SKILL.md +++ b/internal/author/skill/SKILL.md @@ -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 diff --git a/internal/author/skill/references/format.md b/internal/author/skill/references/format.md index 5f48275c..15854164 100644 --- a/internal/author/skill/references/format.md +++ b/internal/author/skill/references/format.md @@ -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 diff --git a/internal/server/chat_turn_diff_test.go b/internal/server/chat_turn_diff_test.go index ae4b7b3c..39d1277f 100644 --- a/internal/server/chat_turn_diff_test.go +++ b/internal/server/chat_turn_diff_test.go @@ -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" { diff --git a/internal/server/check_stage.go b/internal/server/check_stage.go index d5b906ec..f36f846c 100644 --- a/internal/server/check_stage.go +++ b/internal/server/check_stage.go @@ -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 { diff --git a/internal/server/check_stage_test.go b/internal/server/check_stage_test.go index 7c7e6918..0ec51b56 100644 --- a/internal/server/check_stage_test.go +++ b/internal/server/check_stage_test.go @@ -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 { diff --git a/internal/server/retry_test.go b/internal/server/retry_test.go index 9d711b51..ba85eb17 100644 --- a/internal/server/retry_test.go +++ b/internal/server/retry_test.go @@ -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 diff --git a/internal/stage/model.go b/internal/stage/model.go index 49f173a9..2e15fd2f 100644 --- a/internal/stage/model.go +++ b/internal/stage/model.go @@ -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")