ADR: Executable Tool Contracts
Status: accepted
Context
An LLM sees a tool through three independently maintained surfaces:
Description()explains when and how to call it.Schema()constrains the generated arguments.Run()implements the behavior.
When these surfaces disagree, a detailed description makes failures more likely because the model confidently relies on behavior that does not exist. Static descriptions also drift from configured timeouts and output limits.
Decision
Keep the existing tool.Tool interface, but treat each implementation as one
executable contract.
- Configurable values are stored on the tool instance and rendered into the embedded description at construction time.
tool.RenderDescriptionrejects missing or malformed placeholders.tool.ValidateDefinitionvalidates the model-visible definition in tests.- JSON schemas reject unknown properties and express required, bounded, and
enum inputs. Mutually exclusive fields are described in property text and
enforced in
Run; top-leveloneOf/allOf/anyOfare forbidden because Anthropic’s toolinput_schemarejects them. - Filesystem tools share workspace-relative path resolution.
- Model-visible output is bounded independently from TUI presentation.
The registry continues to construct llm.ToolDefinition from the existing
Name, Description, and Schema methods. This keeps native, LSP, and MCP
integration stable.
Description structure
Every registered built-in description has four parts:
- A one-sentence purpose.
When to use.When not to use, naming the preferred alternative.Behavior and limits.
Only non-obvious input formats include an example. Configurable limits are template placeholders rendered from the effective runtime values.
Path semantics
All native filesystem tools use the workspace as the base for relative paths. Absolute paths remain accepted.
Mutating tools (write, edit, delete, patch) refuse paths that
resolve outside the workspace (tool.ErrOutsideWorkspace): ..
escapes, absolute paths outside the root, and symlinks that leave the
root. Permission policy still decides allow/ask/deny inside that
root. Read-only tools (read, glob, grep, list) do not apply this
confine so the model can inspect paths the user names.
Directory symlinks are listed but are not followed by the current search and
listing implementations. Native glob, grep, and list do not apply
.gitignore; their descriptions state this explicitly.
Tool routing
Only list is model-visible for directory listing:
recursive:falselists immediate children.recursive:trueproduces a bounded tree.
The former ls tool has been removed; use list with recursive:false for a
shallow peek.
Dedicated filesystem tools take precedence over shell equivalents. The bash
contract directs the model to use working_dir, separates dependent from
independent commands, and limits model history without truncating the live TUI
stream.
Output budgets
Limits protect model context, not only terminal rendering:
read: 2,000 lines or 100 KiB per file, with a continuation line number.grep: 200 matches by default and at most 2,000.glob: 1,000 paths.list: 2,000 entries.bash: 200 KiB using deterministic head-and-tail retention.
Every truncated result explains the limit and how to narrow or continue the operation. A result exactly equal to a limit is not labelled truncated unless an additional result exists.
Validation
Contract tests cover:
- valid names, descriptions, and object schemas;
additionalProperties:falsefor registered native tools;- required description sections;
- runtime-rendered values with no unresolved placeholders;
- workspace-relative paths and
readinput exclusivity; - output caps, continuation markers, and full streaming output for
bash.
Consequences
Descriptions can no longer be edited safely without considering schema, runtime, and tests. Constructors may panic on invalid embedded placeholders; this is a developer configuration error discovered during startup and CI.
The architecture does not yet provide attachment-aware reads or a
full-output artifact store for shell commands. Those must not be claimed
by descriptions before implementation. Workspace containment for mutating
file tools is implemented (ConfinePath); do not describe writes
outside the workspace as succeeding.
The active TUI retains complete streamed shell output, while LLM/session history stores the bounded form. Consequently, rebuilding chat solely from a persisted session cannot recover omitted shell bytes until a separate tool-output artifact store is implemented.