Skip to content

feat(policy): emit tool pack action instead of shell:spawn - #252

Merged
ferdingler merged 12 commits into
mainfrom
feature/tool-packs-one-gate
Nov 2, 2026
Merged

ferdingler merged 12 commits into
mainfrom
feature/tool-packs-one-gate

Conversation

@ferdingler

@ferdingler ferdingler commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR makes it so that when a shell command matches a Tool Pack action, Box emits the Dogwood event for that action instead of emitting shell:spawn. It also records its response with the exit status when the run ends. A spawn that no pack covers is decided as shell:spawn, just like before.

Gaps I did not close, on purpose:

  • Box reads the file identity when it decides, and the box runs the program later by its path. The file can change between the two. shell:spawn has the same gap today.
  • A name that no [tool] declares, on a file that no pack binds, is still shell:spawn.
  • A stdio MCP server start is still decided as shell:spawn.
  • A bound link that someone redirects to a new target: if you run that new target directly, Box refuses it, but the message is a bit misleading.
  • The new entry points stay crate-private for now. A follow-up PR I have planned adds the opener that loads the packs, so the engine and the bindings get one owner.

Related Issues

#38

Type of Change

New feature

Testing

I added tests for each claim: a shell:spawn rule neither admits nor refuses a bound program, the recorded exit status feeds a temporal rule, two packs share the mise shim binary, an undeclared name and a replaced file are refused under a policy that permits everything, and a table of spawns with empty bindings decides the same as before. I broke each guard on purpose and the tests caught it. I did not compile macOS locally, so CI covers it.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## 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
## Problem

The policy crate can decide a tool pack action and record its response,
and it can bind a pack to a program file and a called name. But no
enforcement point uses them. A spawn of a program that a pack covers is
still decided as `shell:spawn`. Also, a program file can bind to only one
pack, so only one tool on the mise shim binary can have a pack. And a
name that no `[tool]` declares on a bound file becomes the pack's
`unmodeled` action, so a rule that permits `unmodeled` admits a program
that the operator did not name.

## Solution

- The Shell adapter decides a spawn as its pack action when a pack binds
  the program file and the called name. The adapter reads the file
  identity (device and inode) at decision time, from the canonical path
  that the Shell resolved. It does not use an identity from startup. An
  allowed pack action records its `::response` with the exit status, or
  -1 when the run ends with no status. A spawn that no pack covers is
  decided as `shell:spawn`, as before.
- Several packs can bind one file. A bind is refused only when another
  pack binds the same (file, name) pair.
- Coverage has a new answer: refused. The adapter refuses the spawn, and
  no policy can permit it, in two cases: a name that no `[tool]` declares
  on a bound file, and a bound path (or a bound link) that leads to a
  different file now. The old answer "undeclared name gives `unmodeled`"
  is removed. `unmodeled` now means only that the grammar cannot read the
  command.
- `ProgramFile::read` canonicalizes the path before it reads the
  identity. `PackInvocation` takes the `ProgramFile` instead of a path
  string.
- New public names. Fernando approved them on one condition: no operator
  can reach the feature yet. Nothing in `crates/box` calls them, and there
  is no config key and no flag. The names are `BindingRefusal`, `Pack`,
  `PackBindings`, `PackError`, `ProgramFile`, `UnreadableProgramFile`, and
  the method `ShellPolicyInterceptor::into_handle_with_pack_bindings`.
  `Pack::load`, `PackBindings::{new, declare, bind}`, and
  `ProgramFile::{read, path}` are public. The facade count is now 58 with
  all features and 52 by default.
- Decision entries, which Fernando asked for in this change: a new entry
  `a-pack-action-replaces-shell-spawn`, and a rewrite in place of
  `a-tool-pack-binds-on-the-program-file-and-the-called-name`.
- MCP staging is not changed. No path outside the tests composes a pack
  schema into an engine, so a pack cannot reach the staged schema.

## Tests

- `adapters::shell::tests::a_bound_spawn_is_decided_as_its_pack_action_and_never_as_shell_spawn`
  pins that a `shell:spawn` permit does not admit a bound program, and a
  `shell:spawn` forbid does not refuse it.
- `an_admitted_pack_action_records_its_response_with_the_exit_status`
  pins the recorded status (1, -1, then 0) through a temporal rule.
- `an_undeclared_name_or_a_replaced_file_is_refused_whatever_the_policy_permits`
  and `a_removed_bound_file_is_refused` pin the refusal and its message
  under a policy that permits all actions.
- `empty_bindings_decide_every_spawn_as_the_shell_spawn_path_does`
  compares a table of spawns with direct `shell:spawn` decisions, for
  empty bindings and for a binding on another file.
- `pack::bindings::tests` pin two packs on one shim binary, the refused
  undeclared names (a symlink `g`, a hard link), a replaced file, a new
  file behind a bound link, and the bind refusal on a bound pair.
- I broke each guard and the tests failed.
- Gates for `-p strands-box-policy`: build, test, clippy with and without
  `--all-features` (0 warnings in `crates/policy`), and fmt are green.
  `crates/box` is not changed. macOS was not compiled locally.
- Known gaps: the file can change between the decision and the exec
  (the same gap as `shell:spawn`). An undeclared name on a file that no
  pack binds is still `shell:spawn`. A stdio MCP server start is still
  decided as `shell:spawn`. A refusal does not enter history and does not
  reach the decision observer.
Base automatically changed from feature/tool-packs-decide-pack-action to main November 2, 2026 17:46
…e-gate

# Conflicts:
#	crates/policy/src/dogwood.rs
#	crates/policy/src/pack/corpus.rs
#	crates/policy/src/pack/invocation.rs
#	crates/policy/src/pack/mod.rs
#	crates/policy/src/policy.rs
#	crates/policy/src/policy/authority.rs
#	crates/policy/src/request.rs
#	crates/policy/src/schema.rs
#	docs/design/decisions.md
@ferdingler
ferdingler marked this pull request as ready for review November 2, 2026 18:16
@ferdingler ferdingler changed the title feat(policy): decide a pack-bound spawn as its pack action alone feat(policy): emit tool pack action instead of shell:spawn Nov 2, 2026

@kevin-orellana kevin-orellana left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redacted temporarily. Reviewing PR

Comment thread crates/policy/src/lib.rs Resolved
Comment thread crates/policy/src/pack/bindings.rs Resolved
Comment thread crates/policy/src/adapters/shell.rs Resolved
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Request Changes

The one-gate logic holds for each case I traced. The blocker is that the new public entry point, into_handle_with_pack_bindings, can't be used correctly outside the tests: with the only public opener, every bound spawn is denied, whatever the policy permits. Details are inline.

Assumptions and rules I checked that held
  • Empty bindings, or bindings that don't cover the spawned file, still give the same answer as today's shell:spawn path (empty_bindings_decide_every_spawn_as_the_shell_spawn_path_does).
  • The Shell's program_path is already canonical, so the file identity that ProgramFile::read gets at spawn time matches the identity that bind recorded.
  • A link named g to a bound git is refused as UndeclaredName, and a bound file that is replaced in place or relinked is refused for the name a pack bound.
  • rustup hard links (cargo and rustc on one inode) keep a declared rustc on shell:spawn.
  • An unbound ./git in the working directory stays shell:spawn.
  • An allowed pack action records its ::response exactly once, through submit and mark_indeterminate.
  • The façade counts in README.md and AGENTS.md match lib.rs (58 names with all features, 52 by default).
  • The policy-crate lib tests pass at 1696aa8 (236 passed).

The tests are thorough, and each guard has a case that fails when the guard is broken.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Approve

I re-reviewed at 65c2a3b. f9792ed and 65c2a3b fix all three findings from the earlier review, and I found nothing new. The pack gate stays dormant outside tests until the follow-up opener lands, so production spawns decide exactly as they do on main.

Assumptions and rules I checked that held
  • The façade on crates/policy/src/lib.rs is the same as on main, and the documented counts (52 and 46) match it. The frozen-surface rule holds.
  • into_handle_with_pack_bindings is test-only, so no build outside the tests can pair bindings with an engine that lacks the pack schemas.
  • In both clauses of replaced, a declared name with no pack stays shell:spawn after an in-place rename and after a link retarget. Bound names are Replaced in both layouts, as decisions.md now says.
  • Undeclared names on a replaced file are still refused: gitk is Replaced, and a hard-link swap to another bound file is UndeclaredName.
  • Clippy with --no-deps -D warnings passes for all features, default features, and shell-adapter alone. The policy-crate lib tests pass (236).

The follow-up opener needs to give the engine and the bindings a single owner. That is the remaining risk.

@ferdingler
ferdingler merged commit 8e09fdf into main Nov 2, 2026
22 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants