release(v0.40.4): policy mode presets + plugin shakedown fix delivery#162
Conversation
Adds `vaara mode` CLI subcommand with three actions: - `vaara mode list` prints the four built-in preset operating points (eco, balanced, performance, strict) with thresholds and one-line descriptions. - `vaara mode show NAME` prints thresholds, description, and watt profile for a single preset. - `vaara mode emit NAME [--format json|yaml] [--output PATH]` emits a minimal valid Vaara policy document for the chosen preset, ready for the deployer to add action classes, sequences, and escalation routes. The new `vaara.policy.modes` module exposes `Mode`, `available_modes`, `get_mode`, `to_policy_dict`, `emit_json`, and `emit_yaml`. Presets are shaped like CPU power profiles. Emitted documents round-trip through `vaara.policy.from_dict`, `from_json`, and `from_yaml`. Bundles plugin shakedown fix delivery: - `plugins/claude-code-vaara-governance/.claude-plugin/plugin.json` bumped 0.1.0 to 0.1.1, picking up the session_start audit-DB creation fix from PR #161. - `.claude-plugin/marketplace.json` ref bumped v0.40.3 to v0.40.4 so marketplace users receive the plugin update. - `server.json` and `server-vaara-server.json` versioned to 0.40.4. 25 new tests in `tests/test_policy_modes.py` cover the preset registry, round-trip through all three loaders, and CLI dispatch.
📝 WalkthroughWalkthroughThis PR introduces a policy modes feature that allows users to select from four preset operating points (eco, balanced, performance, strict) each with predefined escalate/deny thresholds. It adds a new ChangesPolicy Modes Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/vaara/cli.py (1)
1145-1154: ⚡ Quick winPrefer the public API over private implementation details.
Line 1146 imports
_BY_NAME, which is a private module variable (indicated by the leading underscore). Line 1149 accesses it directly. Use the publicget_mode()function instead to respect encapsulation.♻️ Refactor to use public API
def _cmd_mode_list(_args: argparse.Namespace) -> int: - from vaara.policy.modes import _BY_NAME, available_modes + from vaara.policy.modes import available_modes, get_mode for name in available_modes(): - m = _BY_NAME[name] + m = get_mode(name) print( f"{name:12s} escalate={m.escalate:.2f} deny={m.deny:.2f} " f"{m.description}" ) return 0🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/vaara/cli.py` around lines 1145 - 1154, The function _cmd_mode_list currently imports and uses the private _BY_NAME mapping; change it to use the public API by importing and calling get_mode(name) for each mode from vaara.policy.modes instead of accessing _BY_NAME[name]; keep available_modes() to iterate names and replace m = _BY_NAME[name] with m = get_mode(name) so you respect encapsulation and avoid using the private symbol.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/vaara/cli.py`:
- Around line 1173-1188: In _cmd_mode_emit, the code writes to Path(args.output)
without expanding user home (~); update the write path to call expanduser on the
Path before writing (use Path(args.output).expanduser() when calling write_text)
so user-supplied paths like ~/output.json resolve consistently with other
commands (reference: function _cmd_mode_emit and the args.output usage).
---
Nitpick comments:
In `@src/vaara/cli.py`:
- Around line 1145-1154: The function _cmd_mode_list currently imports and uses
the private _BY_NAME mapping; change it to use the public API by importing and
calling get_mode(name) for each mode from vaara.policy.modes instead of
accessing _BY_NAME[name]; keep available_modes() to iterate names and replace m
= _BY_NAME[name] with m = get_mode(name) so you respect encapsulation and avoid
using the private symbol.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: bc0dc967-6840-489d-918a-c067fbd7a811
📒 Files selected for processing (12)
.claude-plugin/marketplace.jsonCHANGELOG.mdREADME.mdclients/ts/package.jsonplugins/claude-code-vaara-governance/.claude-plugin/plugin.jsonpyproject.tomlserver-vaara-server.jsonserver.jsonsrc/vaara/__init__.pysrc/vaara/cli.pysrc/vaara/policy/modes.pytests/test_policy_modes.py
| def _cmd_mode_emit(args: argparse.Namespace) -> int: | ||
| from vaara.policy.modes import emit_json, emit_yaml | ||
|
|
||
| try: | ||
| text = emit_yaml(args.name) if args.format == "yaml" else emit_json(args.name) | ||
| except KeyError as e: | ||
| print(f"vaara mode emit: {e}", file=sys.stderr) | ||
| return 2 | ||
| except ImportError as e: | ||
| print(f"vaara mode emit: {e}", file=sys.stderr) | ||
| return 1 | ||
| if args.output: | ||
| Path(args.output).write_text(text, encoding="utf-8") | ||
| else: | ||
| sys.stdout.write(text) | ||
| return 0 |
There was a problem hiding this comment.
Add .expanduser() when writing to user-supplied paths.
Line 1185 writes to Path(args.output) without expanding tilde (~) in paths. Other file-writing commands in this module consistently use .expanduser() (e.g., lines 603, 696). Without this, paths like ~/output.json will not resolve correctly.
🔧 Proposed fix
if args.output:
- Path(args.output).write_text(text, encoding="utf-8")
+ Path(args.output).expanduser().write_text(text, encoding="utf-8")
else:
sys.stdout.write(text)
return 0🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/vaara/cli.py` around lines 1173 - 1188, In _cmd_mode_emit, the code
writes to Path(args.output) without expanding user home (~); update the write
path to call expanduser on the Path before writing (use
Path(args.output).expanduser() when calling write_text) so user-supplied paths
like ~/output.json resolve consistently with other commands (reference: function
_cmd_mode_emit and the args.output usage).
Summary
Patch release. Two threads bundled.
Policy mode presets
New
vaara modeCLI subcommand with three actions, plus the matchingvaara.policy.modesmodule:vaara mode listprints the four built-in preset operating points (eco,balanced,performance,strict) with their thresholds and one-line descriptions.vaara mode show NAMEprints thresholds, description, and watt profile for a single preset.vaara mode emit NAME [--format json|yaml] [--output PATH]emits a minimal valid Vaara policy document for the chosen preset, ready for the deployer to add action classes, sequences, and escalation routes.Preset operating points are shaped like CPU power profiles:
ecobalancedperformancestrictEmitted documents round-trip through
vaara.policy.from_dict,from_json, andfrom_yamllike any other policy artifact.Plugin shakedown fix delivery
plugins/claude-code-vaara-governance/.claude-plugin/plugin.jsonbumped0.1.0to0.1.1, picking up the SessionStart audit-DB creation fix from fix(plugin): create audit DB on session start #161..claude-plugin/marketplace.jsonrefbumpedv0.40.3tov0.40.4so marketplace users receive the plugin update.Test plan
pytest tests/test_policy_modes.py25 passedruff check src/vaara/policy/modes.py src/vaara/cli.py tests/test_policy_modes.pycleanvaara mode list / show balanced / emit eco / emit strict --format yaml --output policy.yamlsmokemcp-publisher publishfor both registry slotsSummary by CodeRabbit
New Features
eco,balanced,performance,strict) with configurable risk thresholds.vaara modeCLI commands:list(display all modes),show(view mode details), andemit(export modes as Vaara policies in JSON or YAML format).Documentation