State each model stage's permitted tools in its prompt

A planner had no machine-readable view of the tool set later stages would
have, so it could emit acceptance checks that required tools (shell) the
implementer was not permitted, causing a blocked run.

modelPrompt now emits exactly one authoritative line naming the stage's
permitted tools, derived from the definition via the new effectiveTools
helper. effectiveTools reuses ToolNames: a present tools block, including
an explicit empty one, is returned as parsed; an absent block yields the
legacy mutating read/glob/grep/edit/shell bundle so it is never
misrepresented as empty or read-only. The bundle is declared once as
legacyTools and reused by tools.go, agent.go, pi.go and permissions.go.

The redundant client-side strings.Replace of the tools line is removed
from AgentClient.Generate and PiClient.Generate; the agent-only guidance
sentence is preserved by appending it in agent.go, and Pi appends a short
mapping line derived from piTools. Edit-scope and permitted-shell text,
routing, review, budgets and retries are unchanged.

Adds internal/stage/model_prompt_test.go covering explicit, absent and
explicit-empty blocks plus derivation edge cases, and a guard that the
agent prompt still carries the tools, edit-scope and shell-command text.
This commit is contained in:
2026-10-16 23:34:39 +01:00
parent 0937327e8c
commit c41bf4f5b0
6 changed files with 212 additions and 10 deletions
+22 -1
View File
@@ -35,6 +35,27 @@ func ToolNames(def Definition) ([]string, bool, error) {
return tools, true, nil
}
// legacyTools is the single declaration of the implicit tool set for a stage
// with no tools block: the mutating read/glob/grep/edit/shell bundle. It is
// never nil or empty, so an absent block is never represented as a read-only or
// text-only stage.
var legacyTools = []string{"read", "glob", "grep", "edit", "shell"}
// effectiveTools is the single materialisation point for the tools a model
// stage is permitted. A present tools block (including an explicit empty block)
// is returned exactly as parsed by ToolNames; an absent block yields the legacy
// mutating bundle so it is never silently narrowed to an empty or read-only set.
func effectiveTools(def Definition) ([]string, error) {
tools, explicit, err := ToolNames(def)
if err != nil {
return nil, err
}
if !explicit {
return legacyTools, nil
}
return tools, nil
}
// safeToReplay is the single definition of which post-admission work may be
// automatically retried. Only an explicit tools block that selects neither
// "edit" nor "shell" is side-effect free. An absent block is the legacy
@@ -59,7 +80,7 @@ func (c *AgentClient) permissionRules() []map[string]string {
// A missing block gets normal local agent tools. Explicit stage blocks still
// select which tools are available, including an empty block for text-only work.
if tools == nil {
tools = []string{"read", "glob", "grep", "edit", "shell"}
tools = legacyTools
}
allow := func(action, resource string) {
rules = append(rules, map[string]string{"action": action, "resource": resource, "effect": "allow"})