Repository navigation
feat(policy): decide and record tool pack actions in the policy engine - #247
Conversation
## Problem The policy crate can parse a command line with a tool pack, but no code decides the pack action that the parse gives. So the box cannot use a pack action as a decision, and a temporal rule cannot read what a pack action did. Also, the golden corpus test built the event with its own private copy of the event builder, and decided it with the Dogwood authorizer directly. Thus the test did not pin the production code. ## Solution - Add `PolicyEngine::decide_pack_action` (crate-private). It builds the `context.input` record from a parsed pack action (`Parsed::Action` or `Parsed::Unmodeled`), with the base fields `program`, `program_path`, `cwd`, `args`, `effects`, and `credential_reads`. It decides the record through the one live authority, with the same request gate, the same durable history, and the same observer as every other decision. - Add `PolicyEngine::record_pack_response` (crate-private). It records the `::response` of a decided pack action, with the exit status in `output.status`. - Add `PackInvocation` and `PackResponse` in the `pack` module, and the `ActionIdentity::PackAction` variant. - Let the complete open path take tool pack schema fragments. Only a test constructor, `PolicyEngine::open_with_packs`, uses it now. A later change adds the production load. - The corpus test now opens an engine with the pack, and decides each case through `decide_pack_action`. The private event builder and the direct authorizer are deleted. The exact rules and the negated rules of a corpus load into one engine, so each case takes one decision. - Add two entries to `docs/design/decisions.md`: a pack action names no enforcement point, and `unmodeled` is denied by default. The user asked for them in this change. Nothing calls the new functions outside tests. The `pub use` set does not change, and `adapters/shell.rs` does not change. ## Tests - `pack::corpus::every_corpus_case_is_typed_and_decided_by_the_policy_engine` pins that the engine types and decides each golden case, that the rule over the exact values allows it, and that no negated rule allows it. - `pack::corpus::a_group_permit_never_reaches_an_unmodeled_command_and_an_explicit_permit_does` pins that `unmodeled` is denied under only a `"*"` group permit, and that an explicit permit on `unmodeled` allows it. - `pack::invocation::tests::a_temporal_rule_reads_the_exit_status_that_a_pack_response_records` pins that `git push` is allowed only after `cargo test` exits 0. - `pack::invocation::tests::a_pack_decision_enters_the_one_history_and_reaches_the_observer` pins that a `shell:spawn` rule reads a pack decision from the same history, and that the observer sees the pack action and its resource. - `pack::invocation::tests::an_input_that_its_action_schema_does_not_type_is_refused_as_a_fault` pins that the request gate refuses an input that the action schema does not type, as an internal fault. - I broke each guard on purpose and the test failed: `unmodeled` in the `"*"` group, an unmodeled event with no `effects`, a wrong exit status, a wrong event namespace, no observer call, an inverted field value, and no request gate. - I ran build, test, clippy, and fmt for `strands-box-policy` with all features, on Linux. Clippy shows 0 warnings in `crates/policy`. I did not build on macOS; CI does that. - The corpus test now takes about 35 seconds in a debug build, because each corpus opens a durable engine.
…cide-pack-action # Conflicts: # docs/design/decisions.md
Codebase design: use one internal decision path. The shared handler removes duplicated decision handling, but the change still adds a second request contract across The difference is already visible in JSON itself is reasonable for fields defined by a pack schema. I recommend a private request type with variants for the existing Reviewed |
…engine decision path
|
Assessment: Comment I reviewed Checked and held
Scope noteThe description's sequence diagram shows Shell calling |
kevin-orellana
left a comment
There was a problem hiding this comment.
The shared decision path looks sound at 6057dfa. The full policy suite passed on 64-bit Arm Linux: 487 passed, seven marked ignored, and no runtime skips. Five additional probes and formatting passed.
The new functions have no production callers yet. The two existing review findings remain prerequisites for production integration: preserve completion history when a pending response is discarded, and carry pack definitions through discovery initialization.
Description
This PR adds the
decide_pack_actionfunction in the Tool Packs feature. This function is what lets Box actually make a decision (allow/deny) about a tool pack command. After this change, this is how the sequence of actions happen when an Agent runs a shell command.sequenceDiagram participant A as Agent participant B as Shell participant P as Pack Parser participant E as Policy Engine A->>B: git push --force origin main B->>P: read this command P-->>B: action "push", effects [force_push] B->>E: decide_pack_action(action) E->>E: check the rules and the history E-->>B: allowed, here's a receipt B->>B: run git B->>E: push finished with status 0 (with the receipt) E->>E: save it in the history B-->>A: git's outputRelated Issues
#38
Type of Change
New feature
Testing
The corpus test now decides every case through the real engine, which makes it slower (about 35 seconds in a debug build). I also added tests for
unmodeledbeing denied, a push allowed only after a passing test run, and a denied action leaving nothing to record, and I broke each guard on purpose and the tests caught it.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.