Repository navigation
feat(opa): expose configured workspace context for structured tools - #163
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review: 2
Please check the settings in the CodeRabbit UI or the
|
drobison00
left a comment
There was a problem hiding this comment.
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, withNOMOS_TEST_OPA_BINARYset. In the full suite, the 9 failures are all intests/assurance, caused byModuleNotFoundError: trace_ingestin my environment. The same 9 fail ondevelop2e27e6a, so they're unrelated to this PR. - Lint and CI:
ruff checkandruff format --checkare clean, and CI on the head is green. - Mutation checks: I made each of these changes to
nomos/opa/client.pyand 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.
- Abbreviated long options escape the hard deny. GNU
rmaccepts unambiguous long-option abbreviations.rm --recu --forc /andrm --r --f /reachrequires_human_approvalinstead ofdeny. I confirmed on coreutils 9.4 thatrm --recu --forcforce-deletes a tree, read-only file included. The guide's rule table lists recursive forcedrm"and long options" as Forbidden, so that path can currently be approved by a human. - The chart's Rego copy has drifted.
247beb2changedoption_argumentsinpolicies/intent_filter.regobut not indeploy/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.
418341d
into
feat/opa-tool-policy-outcomes
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.runis 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.runwith these example arguments. This JSON belongs to the tool-call request; it is not copied intocouncil.yaml. The host must supply or verifyproject_rootfrom its authorized workspace.{ "command": "chmod 600 notes.txt", "cwd": "/projects/demo/src", "project_root": "/projects/demo" }2. Council configuration: edit the existing
opasection incouncil.yamlThe repository default is
configs/council.yaml. In the configuration used by your Council deployment, replace the emptyworkspace_arguments: {}mapping with:This means: for the exact tool
shell.run, read the workspace root from the top-level argumentproject_root. Merge this into the existingopasection rather than adding a second one. The Helm-packaged equivalent isdeploy/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()innomos/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:4. After mapping: generated OPA input
The same tool-call arguments now produce the common
input.intent.workspacefield. No OPA input file needs to be edited—the Council generates this value from the configured mapping:A Rego policy can read
input.intent.workspacewithout knowing whether the host's argument is calledproject_rootor 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
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.cwdremains in the tool arguments. Runtime confinement remains the host's responsibility.The default Council configuration and its Helm-packaged copy both show the empty opt-in mapping. See the workspace configuration and input examples.
Validation
git diff --checkpassed.