Repository navigation
feat(config): enable the tool packs feature behind a feature flag - #281
Conversation
## Problem The policy crate has a tool grammar model, a schema generator, and a binding table, but `box.toml` cannot carry a grammar and no non-test engine opener installs one. So an operator cannot write a rule on a `Tool::<name>` action, and the Box CLI cannot hand Box Core one finished `box.toml` that holds its grammars. The test-only opener also let a caller pair a `GrammarBindings` with an engine that did not know the schemas of those grammars. A spawn bound to such a grammar is denied with no message. The staged opener also held a rule that names an undeclared `Tool::git` action as if an MCP server named `git` could declare it later. The box then started and the rule did not enforce. ## Solution - Add the switch `[experimental-features] tool-grammars` (boolean, default `false`). - Add a sixth field `grammar` to `[tool.<name>]`. It holds the grammar inline, with the same keys as a grammar file. `[agent]` refuses it, and `[mcp.<name>]` refuses it as an unknown key. A grammar is refused while the switch is off. The maintainer approved this frozen-surface addition. - A record that selects `tool-grammars` is record version 25, so an older build refuses the box and does not misread it. `RECORD_VERSION` stays 21, because a record with the switch off has the same shape. - Load each table through the existing grammar model. Each refusal now names a key path in `box.toml`, for example `tool.git.grammar.shell.push.usage`. Box no longer reads a grammar from a file. The test corpus loads its files inside the tests. - Startup refuses a grammar over 64 KiB, measured as the table written out as TOML. It refuses a `program` that is not the name that its own `[tool]` command runs. It refuses two grammars with one `program` or one `name`. - The engine owns the grammar set. The new opener `PolicyEngine::open_staged_file_with_grammars` installs the grammar schemas below every MCP schema that stages later, and through a reload. `PolicyEngine::grammar_bindings` gives out bindings for exactly those grammars, and `GrammarBindings` has no other public constructor. `GrammarBindings::declare_tool` declares a tool's program file and called name, and binds the grammar whose `program` is that name. So a grammar binds every `[tool]` that runs its program. - `PolicyEngine::validate_with_grammars` and `PolicyEngine::check_with_grammars` validate against the same schemas, so the config-time check and `check_policy` agree with the run. - The staged opener no longer holds a rule on a qualified namespace, such as `Tool::git`, for an MCP schema. No MCP schema can declare it, so the load refuses the rule. - At startup, `run` prints one warning for each grammar: the Shell still decides a spawn as `shell:spawn`, so a rule on a grammar action does not fire yet. - New public names in `strands-box-policy`: `ToolGrammar`, `ToolGrammars`, `ToolGrammarError`, `GrammarBindings`, `BindingRefusal`, and the methods above. The facade is 57 names with all features and 51 by default. ## Tests - `tool_grammars.rs`: a box whose policy forbids `Tool::git::Action::"push"` starts with the grammar and the switch, writes record version 25, and prints the warning (`a_policy_naming_a_grammar_action_starts_with_its_grammar_and_the_switch`). The same policy with no grammar is refused at startup (`the_same_policy_without_the_grammar_is_refused_at_startup`). A grammar with the switch off is refused (`a_grammar_with_the_switch_off_is_refused_at_startup`). A box with the switch off and no grammar keeps record version 21 (`a_box_with_the_switch_off_and_no_grammar_is_unchanged`). - `tool_grammar_engine.rs` goes through the non-test opener: open and reload (`a_policy_that_names_a_grammar_action_opens_with_its_grammar`), the refusal with no grammar, the refusal of a rule held for an MCP schema (`a_grammar_action_rule_is_refused_rather_than_held_for_an_mcp_schema`), an MCP schema that stages over the grammar schema, validation, and the example on the configuration page (`the_grammar_and_the_rule_the_configuration_page_shows_load`). - Refusals: `a_tool_grammar_needs_the_tool_grammars_switch`, `a_grammar_is_refused_on_the_agent`, `a_grammar_whose_program_is_not_its_tools_called_name_is_refused`, `two_grammars_for_one_program_are_refused`, `two_grammars_with_one_name_are_refused`, `a_grammar_over_the_size_limit_is_refused_at_its_table`, `a_refusal_names_the_key_path_under_the_tool`, and `a_record_that_selects_tool_grammars_carries_its_own_version`. - Binding: `a_grammar_binds_every_declared_tool_that_runs_its_program` and `an_unreadable_tool_program_is_refused_when_declared`. - `check_policy`: `a_check_reads_the_actions_of_each_tool_grammar`. - The grammar corpus test keeps every file and expects the new key paths in each refusal. - I removed each new guard, saw its test fail, and restored it. - Gates on Linux aarch64: fmt, clippy with 0 owned warnings, the policy suite with and without features, `cargo doc` with `-D warnings`, and the box suite with all features. `box_shell::a_lua_busy_loop_does_not_starve_the_control_socket` failed under full-suite load and passed alone. - Not run: macOS. No test pins the box-level call to `declare_tool`, because nothing reads the bindings until the Shell consumes them.
Resolve each crates/policy file to the main version. Port two box tests to the merged API: a test that called the removed ToolGrammars::is_empty now validates a policy against the grammar, and a new ProcessSpec literal in run/commands.rs gets the grammar field.
…e-program refusal The merged policy crate has no 64 KiB grammar limit, so the user guide no longer states one. The guide now shows the exact text of the refusal of two grammars for one program, and of two grammars with one name. The unit tests compare the full text, and a run test checks that startup refuses two grammars for one program and stores no record.
crates/box/AGENTS.md said that [agent] holds grammar. It does not, so the field list keeps five fields and names grammar as a [tool] field behind the switch. The README and the architecture page now state the startup warning for each grammar.
A record with native-filesystem-policy on and tool-grammars off wrote a tool-grammars key at version 22, 23, or 24. An older build refuses that key, so the documented downgrade broke. The key is now written only when the switch is on. A test pins that a version 22 record holds no such key, and a test pins that [mcp.<name>] refuses a grammar table. The policy pages now say that a tool grammar adds Tool:: actions.
…e guide for a follow-up
|
Assessment: Request Changes Reviewed head Assumptions and rules checked that held
|
…cause macOS links /usr/bin/git
|
Assessment: Request Changes Reviewed head Assumptions and rules checked that held
|
|
Assessment: Request Changes Reviewed head Assumptions checked that held for the new commit
|
|
Assessment: Comment Reviewed head Checked at this head
|
…efuses a grammar record A record version stops an older build from misreading a newer box. An older build already refuses a record that holds a grammar table or the tool-grammars key, because ProcessSpec and ExperimentalFeatures deny unknown fields. So a box with tool-grammars on now writes the version it would write without the switch. The test a_grammar_record_is_refused_where_its_keys_are_unknown pins the refusal. The docs no longer name version 25.
|
Assessment: Comment Reviewed head Assumptions checked that held
|
|
@abhisheksp CI is green again. Since your approval, I dropped record version 25, because an older build already refuses a grammar record, and I put the line you asked about back. Could you take another look? |
Description
The policy half of tool grammars is now on main, but Box still can't load a grammar. There's nowhere to put one in
box.toml, and the box never opens the policy engine with any grammars. So nobody can write a rule on a grammar action likegit push.This PR is the box half. A tool can now carry its grammar inline in
box.toml. It's inline because the Box CLI compiles one finishedbox.tomlplus a policy, and that output has to run on its own with no other file. All of this sits behind a new experimental flag. With the flag off, a grammar is refused and the box behaves as before. Box checks each grammar at startup, opens the engine with the grammars, and checks the policy against their actions. An older build already refuses a box that uses a grammar, so I didn't add a new record version. Its message is less helpful than a version mismatch would be, and I accept that while the feature is experimental. I'm reworking how record versions mark features in a separate change. The new field on a tool and the flag were approved ahead of time as changes to a frozen surface. One more thing is deliberate: a rule on a grammar action loads, but it can't take effect until a follow-up PR I have planned teaches the shell to use grammars. The box warns at startup for each grammar. I chose to allow this while the feature is experimental. The docs here are only the reference entries: the new field, the flag, going back to an older build, and the startup refusals. The user guide for tool grammars comes in a follow-up PR I have planned.Related Issues
None.
Type of Change
New feature
Testing
I ran the box and policy test suites, formatting, and lint. Each startup refusal has a test: a grammar on the agent, a grammar with the flag off, a grammar for a different program than its tool runs, and two grammars for one program. I broke each one on purpose and its test caught it. Most end-to-end box tests can't run on my Linux machine because of a host mount setup that has nothing to do with this change, so CI covers those, along with macOS.
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.