Skip to content

feat(opa): expose configured workspace context for structured tools - #163

Merged
nathankw merged 3 commits into
feat/opa-tool-policy-outcomesfrom
feat/opa-workspace-context
Nov 19, 2026
Merged

nathankw merged 3 commits into
feat/opa-tool-policy-outcomesfrom
feat/opa-workspace-context

Conversation

@nathankw

@nathankw nathankw commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Why this helps

An application can already include its workspace root in a structured tool call, but different tools use different argument names. Without a common field, every OPA policy must understand each application's payload format.

This PR lets operators map those names to input.intent.workspace, so policies can read one field. The workspace is the host-declared filesystem root for this invocation; it is separate from the command's working directory.

Stacked on #160, targeting feat/opa-tool-policy-outcomes. The diff adds workspace input context, documentation and tests. It does not add a workspace-containment rule or decision-model routing.

Example: where each snippet belongs

Only the configuration snippet in step 2 is a file edit. The tool arguments and OPA input below are runtime data, not additional configuration files. shell.run is an illustrative tool name; operators must use their actual exact tool name.

1. Host application: arguments submitted with a structured tool call

The host calls shell.run with these example arguments. This JSON belongs to the tool-call request; it is not copied into council.yaml. The host must supply or verify project_root from its authorized workspace.

{
  "command": "chmod 600 notes.txt",
  "cwd": "/projects/demo/src",
  "project_root": "/projects/demo"
}

2. Council configuration: edit the existing opa section in council.yaml

The repository default is configs/council.yaml. In the configuration used by your Council deployment, replace the empty workspace_arguments: {} mapping with:

opa:
  workspace_arguments:
    shell.run: project_root

This means: for the exact tool shell.run, read the workspace root from the top-level argument project_root. Merge this into the existing opa section rather than adding a second one. The Helm-packaged equivalent is deploy/kubernetes/nomos/files/council/council.yaml. Both shipped copies default to an empty mapping; the mapping above is an example deployment override.

3. Before mapping: generated OPA input

The next two snippets are abbreviated runtime input sent to OPA, generated by build_intent_filter_input() in nomos/opa/client.py. They are shown as YAML for readability; the actual OPA request uses JSON. Other existing input fields are omitted.

Without the mapping, the policy must know the host-specific argument name project_root:

intent:
  tool_arguments:
    command: chmod 600 notes.txt
    cwd: /projects/demo/src
    project_root: /projects/demo

4. After mapping: generated OPA input

The same tool-call arguments now produce the common input.intent.workspace field. No OPA input file needs to be edited—the Council generates this value from the configured mapping:

intent:
  workspace: /projects/demo
  tool_arguments:
    command: chmod 600 notes.txt
    cwd: /projects/demo/src
    project_root: /projects/demo

A Rego policy can read input.intent.workspace without knowing whether the host's argument is called project_root or another configured name. The original tool arguments remain intact.

The input comes from the same held, validated arguments used by #160. The existing argument digest still binds the original payload; no workspace field is added to the durable Intent or signed operation.

Contract and limits

  • The default mapping is empty. Match exact tool names and top-level argument keys, under any OPA profile. No wildcard matching or nested-key traversal is added.
  • A mapped, syntactically valid absolute POSIX or Windows root is preserved verbatim. A missing/invalid mapped value becomes workspace: null, meaning unknown scope. Unmapped tools and legacy shell requests omit the field. Policies requiring scope must handle absent/null explicitly; neither means safe or allowed.
  • Mapping is not authentication. The host must derive or overwrite the selected argument from its actual authorized workspace. A model-supplied path cannot establish its own permission boundary. The digest binds the submitted value, not its truth.
  • No filesystem lookup, symlink resolution, path-target extraction, shell-analyzer change or automatic approval is added. The original cwd remains in the tool arguments. Runtime confinement remains the host's responsibility.
  • This exposes the generic field to OPA only. Council already receives the original structured arguments; generic decision-model context and questions are a separate follow-up.

The default Council configuration and its Helm-packaged copy both show the empty opt-in mapping. See the workspace configuration and input examples.

Validation

  • 320 OPA/configuration regression tests passed, including 35 new workspace cases and the existing real Rego cases.
  • Tests cover exact mapping, multiple tool formats, all three exercised policy profiles, missing/invalid roots, POSIX/Windows paths, preserved arguments/digests, unchanged legacy input and the service-to-OPA policy-only handoff without minting a writ.
  • Pre-commit formatting, Ruff, mypy, Bandit, secret detection and public Council routing checks passed. Council configuration copies match; git diff --check passed.
  • No live model or external connector calls were needed or performed.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review: 2

  • main
  • develop

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@nathankw
nathankw marked this pull request as ready for review November 18, 2026 22:31

@drobison00 drobison00 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.

Claude - Opus 5.5 - Mira (engineer) via @drobison00

Approving. I reviewed the 3 commits this PR adds on top of feat/opa-tool-policy-outcomes (247beb2..304c127, 7 files) and checked every claim in the description against them.

Claim Result
Default mapping is empty in both shipped copies ✅ configs/council.yaml and the Helm council.yaml both add workspace_arguments: {} with an identical hunk. The pinned semantic hash test covers it.
Exact tool names and top-level keys, under any profile, with no wildcard or nested lookup ✅ A dict .get on the tool name, then on the argument key. The tests cover all three profiles, and scope.root is treated as a literal top-level key.
A valid absolute POSIX or Windows root is preserved verbatim; a missing or invalid value gives workspace: null; unmapped tools and legacy shell requests omit the field ✅ _workspace_root behaves this way. The projection only runs when the held tool-call material is present, so legacy requests never reach it.
The original arguments, the digest, the durable Intent and the signed operation are unchanged ✅ The workspace is added only to the OPA input dict. The tests compare the arguments and model_dump before and after.
Mapping is not authentication; no filesystem lookup, .. normalization or containment rule ✅ Matches both the code and the guide section.
35 new workspace cases ✅ 35 passed locally.

Local validation at 304c127:

  • Tests: opa test policies (OPA 1.17.0) passed 19/19. The OPA, shell and config tests passed 336/336, with NOMOS_TEST_OPA_BINARY set. In the full suite, the 9 failures are all in tests/assurance, caused by ModuleNotFoundError: trace_ingest in my environment. The same 9 fail on develop 2e27e6a, so they're unrelated to this PR.
  • Lint and CI: ruff check and ruff format --check are clean, and CI on the head is green.
  • Mutation checks: I made each of these changes to nomos/opa/client.py and confirmed the tests catch it:
    • accepting relative roots: 3 tests fail;
    • dropping the projection: 26 fail;
    • accepting padded roots: 1 fails;
    • projecting for unmapped tools: 3 fail.

Outside this diff (for #160, not blocking here): two things in the stacked base came up while I tested the combined head.

  1. Abbreviated long options escape the hard deny. GNU rm accepts unambiguous long-option abbreviations. rm --recu --forc / and rm --r --f / reach requires_human_approval instead of deny. I confirmed on coreutils 9.4 that rm --recu --forc force-deletes a tree, read-only file included. The guide's rule table lists recursive forced rm "and long options" as Forbidden, so that path can currently be approved by a human.
  2. The chart's Rego copy has drifted. 247beb2 changed option_arguments in policies/intent_filter.rego but not in deploy/kubernetes/nomos/files/policies/intent_filter.rego. The guide says the two "must remain identical". The outcomes match on the 30 commands I probed, and no test enforces that the copies stay in sync.

@nathankw
nathankw merged commit 418341d into feat/opa-tool-policy-outcomes Nov 19, 2026
14 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants