Skip to content

Network Policy Generalization [Spec + Impl] - #10

Merged
rhuss merged 1 commit into
mainfrom
078-network-policy-generalization
Jul 7, 2026
Merged

rhuss merged 1 commit into
mainfrom
078-network-policy-generalization

Conversation

@rhuss

@rhuss rhuss commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implementation of Network Policy Generalization for multi-agent support.

Each agent adapter now declares which domain groups it requires via a new RequiredDomainGroups() method on the Agent interface. The build system queries these declarations and composes network policies based on which agents are listed in the manifest.

Key changes:

  • Added RequiredDomainGroups() []string to the Agent interface
  • Added Agents field to the build manifest and MatchCondition struct
  • Changed claude-code.yaml from match: always: true to match: agents: [claude]
  • Replaced hardcoded if comp.Key == "claude_code" with generic collectAgentBinaries()
  • Added AllowedDomainsPerAgent for per-agent domain group configuration
  • Added openai builtin domain group and opencode.yaml policy component
  • Centralized default agent logic in Manifest.EffectiveAgents()

Backward compatible: manifests without an agents field default to ["claude"].

Artifacts

  • Spec: specs/078-network-policy-generalization/spec.md
  • Plan: specs/078-network-policy-generalization/plan.md
  • Tasks: specs/078-network-policy-generalization/tasks.md

Assisted-By: 🤖 Claude Code


Open in Devin Review

Summary by CodeRabbit

  • New Features

    • Added multi-agent build support with agent-aware policy generation and per-agent domain allowlists.
    • Introduced support for additional agent-specific network domains, including OpenAI-related endpoints.
  • Bug Fixes

    • Improved policy assembly so agent-specific rules and binaries are included only when relevant.
    • Preserved backward compatibility for builds that do not specify an agent list.
  • Documentation

    • Updated configuration and reference docs to explain agent selection, per-agent domain groups, and the new policy matching behavior.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR generalizes network policy generation to support multiple agents. It adds a RequiredDomainGroups() method to the Agent interface (implemented for Claude and OpenCode), a manifest-level agents field with per-agent domain allowlists, agent-based component matching, an OpenCode policy, and updated policy assembly logic replacing hardcoded Claude Code coupling.

Changes

Agent-aware policy assembly implementation

Layer / File(s) Summary
Agent interface and implementations
cc-deck/internal/agent/agent.go, cc-deck/internal/agent/claude.go, cc-deck/internal/agent/opencode.go, cc-deck/internal/agent/*_test.go, cc-deck/internal/agent/registry_test.go, cc-deck/internal/cmd/ws_new_test.go, cc-deck/internal/credential/resolve_test.go
Adds RequiredDomainGroups() []string to the Agent interface, implements it in ClaudeAgent (returns anthropic) and OpenCodeAgent (returns openai), updates test stubs, and adds unit tests.
Manifest agent fields and defaulting
cc-deck/internal/build/manifest.go
Adds Manifest.Agents and NetworkConfig.AllowedDomainsPerAgent, validates non-empty agent names, and introduces EffectiveAgents() defaulting to ["claude"].
Agent-based component matching
cc-deck/internal/build/component.go, cc-deck/internal/build/component_test.go, cc-deck/internal/build/policies/claude-code.yaml, cc-deck/internal/build/policies/opencode.yaml
Adds MatchCondition.Agents, updates validation and MatchComponent to check agents against EffectiveAgents(), switches claude-code.yaml from always: true to agent-scoped matching, and adds a new opencode.yaml policy.
Per-agent domain group and MCP binary assembly
cc-deck/internal/build/policy.go, cc-deck/internal/build/policy_test.go, cc-deck/internal/network/builtin.go
Expands per-agent domain groups into network policies with dedup/warnings, replaces claude_code-specific MCP binary logic with collectAgentBinaries, adds ValidateAgentDomainGroups, adds openai builtin domain group, and adds extensive tests.
Docs updates
README.md, docs/modules/reference/pages/configuration.adoc
Documents multi-agent agents: field, per-agent domain groups, agent-matched components, and updated MCP policy generation behavior.
Misc supporting updates
cc-deck/CLAUDE.md, cc-deck/brainstorm/idea-inbox.md
Updates plan pointer and adds brainstorming idea entries.

Feature specification and planning documents

Layer / File(s) Summary
Spec-driven documents
specs/078-network-policy-generalization/*
Adds spec.md, plan.md, research.md, data-model.md, contracts/agent-domain-groups.md, tasks.md, checklists/requirements.md, and review-findings.md for the feature.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Manifest
  participant AssemblePolicyCore
  participant AgentAdapter
  participant Resolver
  participant NetworkPolicy

  Manifest->>AssemblePolicyCore: EffectiveAgents()
  loop for each agent
    AssemblePolicyCore->>AgentAdapter: RequiredDomainGroups()
    AssemblePolicyCore->>Manifest: AllowedDomainsPerAgent[agent]
    AssemblePolicyCore->>Resolver: expand domain groups
    Resolver-->>AssemblePolicyCore: endpoints or warning
    AssemblePolicyCore->>NetworkPolicy: add uncovered endpoints
  end
  AssemblePolicyCore->>AssemblePolicyCore: collectAgentBinaries(matched components)
  AssemblePolicyCore->>NetworkPolicy: attach agentBinaries to MCP/pkg_node policies
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the PR’s main theme: generalizing network policy, with both spec and implementation work included.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 078-network-policy-generalization

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@rhuss
rhuss requested a review from Copilot July 7, 2026 19:46
rhuss added a commit that referenced this pull request Jul 7, 2026
Applied fixes from bot review comments:
- Comment #3539183377: Add claude.ai and platform.claude.com to claude-code.yaml to prevent extra agent_anthropic entry (SC-001)
- Comment #3539222279: Fix contract doc to describe shared groups as builtin components, not tool matches
- Comment #3539222282: Add language tag to fenced code block in data-model.md
- Comment #3539222287: Fix plan.md to show vertex-ai.yaml as credential-matched (consistent with research.md R5)
- Comment #3539222304: Align FR-005 with component-based binary collection design

Assisted-By: 🤖 Claude Code

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

rhuss added a commit that referenced this pull request Jul 7, 2026
Applied fixes from bot review comments:
- Comment #3539249153: Fix docs to show correct opencode.yaml endpoints (api.openai.com, openrouter.ai)
- Comment #3539249185: Rewrite dedup test to verify actual endpoint deduplication via shared domain groups
- Comment #3539249234: Remove stray nonroot-write.txt test artifact from source tree
- Comment #3539262510: Same as above (Devin also flagged)

Assisted-By: 🤖 Claude Code
Each agent adapter declares required domain groups via
RequiredDomainGroups() on the Agent interface. The build system
queries agent adapters based on the manifest's agents list,
replacing hardcoded claude_code matching with generic agent-based
component selection.

Key changes:
- Add RequiredDomainGroups() to Agent interface
- Add Agents field to Manifest and MatchCondition structs
- Replace match: always: true with match: agents: [claude]
- Generalize MCP binary lookup via collectAgentBinaries()
- Add AllowedDomainsPerAgent for per-agent domain config
- Add openai builtin group and opencode.yaml policy component
- Centralize default agent logic in Manifest.EffectiveAgents()

Backward compatible: manifests without agents field default to
["claude"].

Assisted-By: 🤖 Claude Code
@rhuss
rhuss force-pushed the 078-network-policy-generalization branch from 455f2a1 to d505e1b Compare July 7, 2026 21:02
@rhuss
rhuss merged commit d3928e2 into main Jul 7, 2026
10 of 12 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Open in Devin Review

Comment on lines +16 to +19
- host: claude.ai
port: 443
- host: platform.claude.com
port: 443

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 New endpoints added to the Claude Code policy component break the stated backward-compatibility guarantee

Two new endpoint entries are added to the Claude Code policy component (claude.ai:443 and platform.claude.com:443 at cc-deck/internal/build/policies/claude-code.yaml:16-19) alongside the match-condition change, so existing single-agent Claude builds produce different policy output than before.

Impact: Users upgrading cc-deck will see their generated OpenShell policies change unexpectedly, which may cause policy-diff validation failures or require re-approval of sandbox configurations.

Spec requirement SC-001 and the verification gap

The feature spec at specs/078-network-policy-generalization/spec.md:106 states:

SC-001: A build with only Claude Code configured produces a policy byte-identical to the current output (zero regression)

The task list at specs/078-network-policy-generalization/tasks.md:105 marks T030 as complete:

Verify backward compatibility: build a policy with an existing manifest (no agents field) and diff against the pre-change output

However, the actual test TestAssemblePolicy_ExplicitClaudeAgent at cc-deck/internal/build/policy_test.go:1448-1462 only verifies that agents: nil and agents: [claude] produce the same output as each other. It does not compare against the pre-change baseline.

The old claude-code.yaml had 5 endpoints:

  • api.anthropic.com, statsig.anthropic.com, sentry.io, downloads.claude.ai, raw.githubusercontent.com

The new file has 7 endpoints, adding claude.ai and platform.claude.com. These additions are unrelated to the network policy generalization feature (changing always: true to agents: [claude]) and should be in a separate change if SC-001 is to be honored.

Prompt for agents
The claude-code.yaml file has two new endpoints (claude.ai:443 and platform.claude.com:443) added in the same PR that changes the match condition from always:true to agents:[claude]. The spec requirement SC-001 requires byte-identical policy output for single-agent Claude builds before and after this change. Either remove the two new endpoints from this PR and add them in a separate change, or update SC-001 in the spec to acknowledge the intentional endpoint additions and update the backward-compatibility test to verify only the structural equivalence (match condition change) rather than byte-identical output.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
specs/078-network-policy-generalization/spec.md (1)

51-53: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Align this scenario with the component-based binary flow.

The scenario still says MCP endpoint processing uses the agent interface to locate binaries, but FR-005 and D5 both chose component-based binary collection instead. Update the wording so the spec does not point implementers back to the discarded approach.

Proposed fix
- **Given** the current `policy.go` with `if comp.Key == "claude_code"`, **When** the generalization is applied, **Then** MCP endpoint processing uses the agent interface to locate binaries for any agent, not just Claude Code.
+ **Given** the current `policy.go` with `if comp.Key == "claude_code"`, **When** the generalization is applied, **Then** MCP endpoint processing collects binaries from agent-matched policy components for any agent, not just Claude Code.
🤖 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 `@specs/078-network-policy-generalization/spec.md` around lines 51 - 53, The
scenario wording still refers to MCP endpoint processing using the agent
interface to locate binaries, which conflicts with the chosen component-based
binary flow. Update the spec text in the generalized network policy scenario so
it describes component-based binary collection and policy matching, and remove
any reference to agent-interface binary lookup; use the existing terms from
`claude-code.yaml` and `policy.go` to keep the scenario aligned with the
implemented approach.
🤖 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 `@cc-deck/brainstorm/idea-inbox.md`:
- Around line 5-14: The markdown heading hierarchy in idea-inbox.md skips from
the document title to level 3, which breaks heading increment rules. Update the
idea section headings such as credential-aware-domain-resolution and
agent-name-validation to use the same level as other top-level ideas, and ensure
the surrounding structure stays consistent with the existing markdown in that
file.

---

Duplicate comments:
In `@specs/078-network-policy-generalization/spec.md`:
- Around line 51-53: The scenario wording still refers to MCP endpoint
processing using the agent interface to locate binaries, which conflicts with
the chosen component-based binary flow. Update the spec text in the generalized
network policy scenario so it describes component-based binary collection and
policy matching, and remove any reference to agent-interface binary lookup; use
the existing terms from `claude-code.yaml` and `policy.go` to keep the scenario
aligned with the implemented approach.
🪄 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

Run ID: 3b5422de-2317-44a3-b774-60d6fd2df733

📥 Commits

Reviewing files that changed from the base of the PR and between 3626a10 and d505e1b.

📒 Files selected for processing (28)
  • README.md
  • cc-deck/CLAUDE.md
  • cc-deck/brainstorm/idea-inbox.md
  • cc-deck/internal/agent/agent.go
  • cc-deck/internal/agent/claude.go
  • cc-deck/internal/agent/claude_test.go
  • cc-deck/internal/agent/opencode.go
  • cc-deck/internal/agent/opencode_test.go
  • cc-deck/internal/agent/registry_test.go
  • cc-deck/internal/build/component.go
  • cc-deck/internal/build/component_test.go
  • cc-deck/internal/build/manifest.go
  • cc-deck/internal/build/policies/claude-code.yaml
  • cc-deck/internal/build/policies/opencode.yaml
  • cc-deck/internal/build/policy.go
  • cc-deck/internal/build/policy_test.go
  • cc-deck/internal/cmd/ws_new_test.go
  • cc-deck/internal/credential/resolve_test.go
  • cc-deck/internal/network/builtin.go
  • docs/modules/reference/pages/configuration.adoc
  • specs/078-network-policy-generalization/checklists/requirements.md
  • specs/078-network-policy-generalization/contracts/agent-domain-groups.md
  • specs/078-network-policy-generalization/data-model.md
  • specs/078-network-policy-generalization/plan.md
  • specs/078-network-policy-generalization/research.md
  • specs/078-network-policy-generalization/review-findings.md
  • specs/078-network-policy-generalization/spec.md
  • specs/078-network-policy-generalization/tasks.md
✅ Files skipped from review due to trivial changes (7)
  • specs/078-network-policy-generalization/checklists/requirements.md
  • cc-deck/internal/agent/registry_test.go
  • cc-deck/CLAUDE.md
  • cc-deck/internal/network/builtin.go
  • cc-deck/internal/cmd/ws_new_test.go
  • cc-deck/internal/credential/resolve_test.go
  • README.md
🚧 Files skipped from review as they are similar to previous changes (12)
  • cc-deck/internal/agent/agent.go
  • cc-deck/internal/agent/opencode.go
  • cc-deck/internal/build/policies/opencode.yaml
  • cc-deck/internal/agent/claude_test.go
  • cc-deck/internal/agent/claude.go
  • cc-deck/internal/agent/opencode_test.go
  • docs/modules/reference/pages/configuration.adoc
  • cc-deck/internal/build/component.go
  • cc-deck/internal/build/policy.go
  • cc-deck/internal/build/component_test.go
  • cc-deck/internal/build/policy_test.go
  • cc-deck/internal/build/manifest.go

Comment on lines +5 to +14
### credential-aware-domain-resolution

- **Source**: triage
- **Date**: 2026-07-07
- **Reference**: PR #10 (078-network-policy-generalization)
- **Summary**: Agents that support multiple credential backends (e.g., OpenCode supports both OpenAI and Anthropic) only declare their primary API domain group. When a user configures an alternate credential mode, the required domains for that backend are missing from the generated policy. Additionally, the policy component endpoint list and the builtin domain group can diverge (e.g., openrouter.ai in opencode.yaml but not in the openai builtin group).

> Devin flagged that OpenCodeAgent.RequiredDomainGroups() returns only ["openai"] despite CredentialSpecs() declaring both openai and anthropic modes. Separately, opencode.yaml includes openrouter.ai:443 but the openai builtin group does not, creating asymmetry between sandbox and container-level domain filtering.

### agent-name-validation

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the heading hierarchy.

### jumps from the title straight to level 3 and will trip markdownlint's heading-increment rule. Make both idea headings ##.

Proposed fix
-### credential-aware-domain-resolution
+## credential-aware-domain-resolution
@@
-### agent-name-validation
+## agent-name-validation
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### credential-aware-domain-resolution
- **Source**: triage
- **Date**: 2026-07-07
- **Reference**: PR #10 (078-network-policy-generalization)
- **Summary**: Agents that support multiple credential backends (e.g., OpenCode supports both OpenAI and Anthropic) only declare their primary API domain group. When a user configures an alternate credential mode, the required domains for that backend are missing from the generated policy. Additionally, the policy component endpoint list and the builtin domain group can diverge (e.g., openrouter.ai in opencode.yaml but not in the openai builtin group).
> Devin flagged that OpenCodeAgent.RequiredDomainGroups() returns only ["openai"] despite CredentialSpecs() declaring both openai and anthropic modes. Separately, opencode.yaml includes openrouter.ai:443 but the openai builtin group does not, creating asymmetry between sandbox and container-level domain filtering.
### agent-name-validation
## credential-aware-domain-resolution
- **Source**: triage
- **Date**: 2026-07-07
- **Reference**: PR `#10` (078-network-policy-generalization)
- **Summary**: Agents that support multiple credential backends (e.g., OpenCode supports both OpenAI and Anthropic) only declare their primary API domain group. When a user configures an alternate credential mode, the required domains for that backend are missing from the generated policy. Additionally, the policy component endpoint list and the builtin domain group can diverge (e.g., openrouter.ai in opencode.yaml but not in the openai builtin group).
> Devin flagged that OpenCodeAgent.RequiredDomainGroups() returns only ["openai"] despite CredentialSpecs() declaring both openai and anthropic modes. Separately, opencode.yaml includes openrouter.ai:443 but the openai builtin group does not, creating asymmetry between sandbox and container-level domain filtering.
## agent-name-validation
🧰 Tools
🪛 LanguageTool

[grammar] ~10-~10: Ensure spelling is correct
Context: ... policy component endpoint list and the builtin domain group can diverge (e.g., openrou...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~10-~10: Ensure spelling is correct
Context: ... in opencode.yaml but not in the openai builtin group). > Devin flagged that OpenCodeA...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🪛 markdownlint-cli2 (0.22.1)

[warning] 5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

🤖 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 `@cc-deck/brainstorm/idea-inbox.md` around lines 5 - 14, The markdown heading
hierarchy in idea-inbox.md skips from the document title to level 3, which
breaks heading increment rules. Update the idea section headings such as
credential-aware-domain-resolution and agent-name-validation to use the same
level as other top-level ideas, and ensure the surrounding structure stays
consistent with the existing markdown in that file.

Source: Linters/SAST tools

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