Repository navigation
feat(policy): tier-based policy selector with combined access-mode UI #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8588ba
feat(policy): tier-based policy selector with combined access-mode UI
cheese-head c433ea4
merge(policy): resolve conflicts merging origin/main into preset-tiers
ericksoa 83ba9dd
Merge branch 'main' into preset-tiers
ericksoa 23bd618
Merge branch 'main' into preset-tiers
ericksoa 0e7db1f
fix(policy): address CodeRabbit review feedback
ericksoa f02a079
Merge branch 'main' into preset-tiers
ericksoa d4ebf13
chore(test): rename policy-tiers tests from .js to .ts
ericksoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| // Tier management — load tier definitions and resolve preset selections. | ||
| // | ||
| // Tiers are defined in nemoclaw-blueprint/policies/tiers.yaml. | ||
| // Each tier is a named posture (restricted, balanced, open) that maps to | ||
| // a set of policy presets and their default access levels. | ||
| // | ||
| // The base sandbox policy is always applied regardless of tier. | ||
| // Tiers layer additional presets on top of that baseline. | ||
|
|
||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
| const YAML = require("yaml"); | ||
| const { ROOT } = require("./runner"); | ||
|
|
||
| const TIERS_FILE = path.join(ROOT, "nemoclaw-blueprint", "policies", "tiers.yaml"); | ||
|
|
||
| /** | ||
| * Load and return all tier definitions from tiers.yaml. | ||
| * Preserves the order defined in the file (restrictive → open). | ||
| * | ||
| * @returns {{ name: string, label: string, description: string, presets: Array<{name: string, access: string}> }[]} | ||
| */ | ||
| function listTiers() { | ||
| const content = fs.readFileSync(TIERS_FILE, "utf-8"); | ||
| const parsed = YAML.parse(content); | ||
| return parsed.tiers; | ||
| } | ||
|
|
||
| /** | ||
| * Return a single tier definition by name. | ||
| * Returns null if the tier does not exist. | ||
| * | ||
| * @param {string} name | ||
| * @returns {{ name: string, label: string, description: string, presets: Array<{name: string, access: string}> } | null} | ||
| */ | ||
| function getTier(name) { | ||
| return listTiers().find((t) => t.name === name) ?? null; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve the final preset list for a tier, applying any per-preset access | ||
| * overrides supplied by the user. | ||
| * | ||
| * overrides is a map of preset name → access level, e.g.: | ||
| * { npm: "read-write", huggingface: "read" } | ||
| * | ||
| * Presets can also be excluded by passing a `selected` allowlist — only | ||
| * presets whose names appear in the list are kept. | ||
| * | ||
| * @param {string} tierName | ||
| * @param {{ overrides?: Record<string, string>, selected?: string[] | null }} [options] | ||
| * @returns {{ name: string, access: string }[]} | ||
| */ | ||
| function resolveTierPresets(tierName, { overrides = {}, selected = null } = {}) { | ||
| const tier = getTier(tierName); | ||
| if (!tier) { | ||
| throw new Error(`Unknown tier: ${tierName}`); | ||
| } | ||
|
|
||
| let presets = tier.presets.map((p) => ({ | ||
| name: p.name, | ||
| access: overrides[p.name] ?? p.access, | ||
| })); | ||
|
|
||
| if (selected !== null) { | ||
| const allowSet = new Set(selected); | ||
| presets = presets.filter((p) => allowSet.has(p.name)); | ||
| } | ||
|
|
||
| return presets; | ||
| } | ||
|
|
||
| module.exports = { | ||
| TIERS_FILE, | ||
| listTiers, | ||
| getTier, | ||
| resolveTierPresets, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Tier definitions for the NemoClaw policy selector. | ||
| # | ||
| # Each tier maps to a named posture. The base sandbox policy | ||
| # (openclaw-sandbox.yaml) is always applied regardless of tier. | ||
| # Tiers add presets on top of that baseline. | ||
| # | ||
| # access values: | ||
| # read — GET only (or equivalent read-only rules for that service) | ||
| # read-write — GET + POST/PUT/PATCH (explicitly opt-in; never the default) | ||
|
|
||
| tiers: | ||
| - name: restricted | ||
| label: Restricted | ||
| description: Base sandbox only. No third-party network access beyond inference and core agent tooling. | ||
| presets: [] | ||
|
|
||
| - name: balanced | ||
| label: Balanced | ||
| description: Full dev tooling and web search. Package installs, model downloads, and inference. No messaging platform access. | ||
| presets: | ||
| - { name: npm, access: read-write } | ||
| - { name: pypi, access: read-write } | ||
| - { name: huggingface, access: read-write } | ||
| - { name: brew, access: read-write } | ||
| - { name: brave, access: read-write } | ||
|
|
||
| - name: open | ||
| label: Open | ||
| description: Broad access across third-party services including messaging and productivity. User accepts responsibility for the expanded scope. | ||
| presets: | ||
| - { name: npm, access: read-write } | ||
| - { name: pypi, access: read-write } | ||
| - { name: huggingface, access: read-write } | ||
| - { name: brew, access: read-write } | ||
| - { name: brave, access: read-write } | ||
| - { name: slack, access: read-write } | ||
| - { name: discord, access: read-write } | ||
| - { name: telegram, access: read-write } | ||
| - { name: jira, access: read-write } | ||
| - { name: outlook, access: read-write } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| // DEV SCRIPT — NOT FOR PRODUCTION USE | ||
| // | ||
| // Manual smoke-test for the interactive tier selector and preset access-mode UI. | ||
| // Stubs out heavy I/O (openshell, registry, credentials) so the TUI can be exercised | ||
| // without a real NemoClaw installation. | ||
| // | ||
| // Usage: | ||
| // node scripts/dev-tier-selector.js | ||
| // | ||
| // This script is intentionally not part of the vitest suite. For automated coverage | ||
| // of this flow see test/policy-tiers-onboard.test.js. | ||
|
|
||
| "use strict"; | ||
|
|
||
| const readline = require("readline"); | ||
|
|
||
| // ── Stubs ────────────────────────────────────────────────────────────────── | ||
| const creds = require("../bin/lib/credentials.js"); | ||
| const runner = require("../bin/lib/runner.js"); | ||
| const registry = require("../bin/lib/registry.js"); | ||
|
|
||
| creds.ensureApiKey = async () => {}; | ||
| creds.getCredential = () => null; | ||
| creds.prompt = (msg) => | ||
| new Promise((resolve) => { | ||
| const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); | ||
| rl.question(msg, (answer) => { | ||
| rl.close(); | ||
| resolve(answer); | ||
| }); | ||
| }); | ||
|
|
||
| runner.run = () => {}; | ||
| runner.runCapture = () => ""; | ||
|
|
||
| registry.getSandbox = () => ({ name: "test-sb", model: null, provider: null }); | ||
| registry.registerSandbox = () => true; | ||
| registry.updateSandbox = () => true; | ||
|
|
||
| // ── Run ──────────────────────────────────────────────────────────────────── | ||
| const { selectPolicyTier, selectTierPresetsAndAccess } = require("../bin/lib/onboard.js"); | ||
| const policies = require("../bin/lib/policies.js"); | ||
|
|
||
| (async () => { | ||
| const tier = await selectPolicyTier(); | ||
| console.log("\nSelected tier:", tier); | ||
|
|
||
| const allPresets = policies.listPresets(); | ||
| const resolved = await selectTierPresetsAndAccess(tier, allPresets); | ||
| console.log("\nResolved presets:", resolved); | ||
| })().catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard manual default fallback with model-id safety checks.
When
defaultModelIdis invalid and non-curated, the fallbackpromptFncan repeatedly return that invalid default, causing an endless validation loop.💡 Proposed fix
🤖 Prompt for AI Agents