feat: apply max budget enforcement to all safe-output tools#91
feat: apply max budget enforcement to all safe-output tools#91jamesadevine merged 3 commits intomainfrom
Conversation
Move the max safe-output budget from per-config-struct fields to the ToolResult trait as DEFAULT_MAX, making it a first-class concept that each tool declares at the type level. - Add DEFAULT_MAX associated constant (default: 1) to ToolResult trait - Extend tool_result! macro with optional default_max parameter - Remove max field and default_max() from all 6 config structs - Replace MaxConfig deserialization with resolve_max() that reads the operator's frontmatter override, falling back to T::DEFAULT_MAX - Use register_budgets! macro to build budget map from concrete types - Simplify config structs to derive(Default) where possible Adding a new budgeted tool now only requires: 1. Set default_max in the tool_result! macro (or override DEFAULT_MAX) 2. Add the type to register_budgets!() in execute.rs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b318654 to
2bf3cf8
Compare
🔍 Rust PR ReviewSummary: Solid refactor — the generic budget enforcement approach is clean and well-tested, but there's one panic-risk bug and a couple of maintainability concerns worth addressing. Findings🐛 Bugs / Logic Issues
|
- Fix UTF-8 panic in extract_entry_context: use char_indices() for safe truncation instead of byte-offset slicing - Add safety comment above register_budgets! noting the manual sync requirement when adding new ToolResult implementors - Expand tool_result! macro doc comment to explain both arms (with and without default_max) - Add test for multi-byte UTF-8 title truncation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔍 Rust PR ReviewSummary: Looks good — the budget generalization is correct and well-tested. One ongoing maintenance concern worth flagging. Findings
|
extract_entry_context runs before execute_sanitized, so raw NDJSON strings could contain newlines or other control characters that produce misleading log entries. Strip control chars from title and path fields before formatting into log messages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔍 Rust PR ReviewSummary: Looks good — clean, correct refactor with a couple of minor observations worth noting. Findings
|
Summary
Previously only update-work-item and comment-on-work-item had the max frontmatter option and budget enforcement in Stage 2 execution. The other four tools (create-work-item, create-pull-request, create-wiki-page, update-wiki-page) had no limits.
This PR raises max to a first-class concept on the ToolResult trait, making budget enforcement automatic and consistent across all safe-output tools.
Design
Each tool declares its default budget via the ToolResult trait. The tool_result! macro accepts an optional default_max parameter. Operators can still override max in front-matter YAML. In execute.rs, a register_budgets! macro builds the budget HashMap from concrete types.
Changes
Testing