Skip to content

feat(policy): implement stronger safety model with scoped approvals and path allowlists#5

Merged
dubscode merged 2 commits intomainfrom
feat/stronger-safety-model
Mar 4, 2026
Merged

feat(policy): implement stronger safety model with scoped approvals and path allowlists#5
dubscode merged 2 commits intomainfrom
feat/stronger-safety-model

Conversation

@dubscode
Copy link
Contributor

@dubscode dubscode commented Mar 3, 2026

Summary

  • Implement stronger policy decision contracts with structured explanation envelope fields: decision, matchedRules, scopeContext, reasonCodes
  • Add scoped persisted approvals with exact scope matching, expiration handling, and revocation support
  • Enforce canonical path allowlists for guarded operations with deny-by-default semantics in allowlist-enabled automation paths
  • Add compatibility adapter fields for legacy policy consumers and update interactive parsing fallback
  • Archive and sync the OpenSpec change stronger-safety-model into main specs

Key Files

  • src/policy/engine.ts
  • src/policy/schemas.ts
  • src/policy/path-guard.ts
  • src/policy/scoped-approvals.ts
  • src/tools/registry.ts
  • tests/policy-engine.test.ts
  • tests/integration/policy-approval.integration.test.ts
  • docs/policy-safety-model.md

Validation

  • pnpm checks

🥞 DubStack

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

PR Checks Summary

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements a stricter, explainable safety policy model by adding scoped persisted approvals and enforcing canonical path allowlists (especially for automation writes), while keeping legacy decision compatibility for existing consumers.

Changes:

  • Extend the policy decision contract with structured explanation fields (decision, matchedRules, scopeContext, reasonCodes) and add a legacy adapter.
  • Add scoped approval persistence (in-memory) with TTL + revocation, and integrate reuse logic into the policy engine.
  • Enforce canonicalized path allowlists for guarded operations, plus new unit/integration test coverage and operator-facing documentation.

Reviewed changes

Copilot reviewed 18 out of 24 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tests/tool-registry.test.ts Updates AGENTS automation write tests to include cwd + path allowlist enforcement and legacy outcome assertions.
tests/policy-engine.test.ts Adds focused unit tests for scoped approvals, determinism, and path allowlist enforcement (incl. canonicalization failures).
tests/integration/policy-approval.integration.test.ts Expands integration coverage for scoped approval reuse and allowlist boundary enforcement.
src/tools/schemas.ts Exposes a ToolSideEffect type inferred from the zod enum.
src/tools/registry.ts Plumbs cwd and approvalGranted into policy evaluation; adds policyOutcomeLegacy compatibility output.
src/policy/scoped-approvals.ts Introduces an in-memory scoped approval store with exact-match lookup + revocation.
src/policy/schemas.ts Expands policy schema (per-operation path allowlists, TTL) and decision schema (explanations + reason codes) with legacy conversion helper.
src/policy/reason-codes.ts Adds a standardized reason-code taxonomy for policy outcomes.
src/policy/path-guard.ts Adds command path extraction + canonicalization utilities and allowlist boundary checks.
src/policy/engine.ts Reworks policy evaluation to enforce allowlists, reuse/expire/revoke scoped approvals, and emit deterministic explanation envelopes.
src/policy/defaults.ts Adds defaults for new policy knobs (per-operation allowlists, allowlist enforcement ops, TTL).
src/cli/app.tsx Adds fallback to legacy policy outcome payloads for CLI display/telemetry.
openspec/specs/scoped-persisted-approvals/spec.md New spec describing scoped persisted approval requirements.
openspec/specs/path-allowlist-enforcement/spec.md New spec describing canonical path allowlist enforcement requirements.
openspec/specs/explainable-policy-decisions/spec.md New spec describing deterministic, explainable policy decision requirements.
openspec/changes/stronger-safety-model/tasks.md Removes the active tasks document (archived).
openspec/changes/archive/2026-03-03-stronger-safety-model/tasks.md Adds archived, completed task list for the stronger safety model change.
openspec/changes/archive/2026-03-03-stronger-safety-model/specs/scoped-persisted-approvals/spec.md Archives the scoped approvals spec delta.
openspec/changes/archive/2026-03-03-stronger-safety-model/specs/path-allowlist-enforcement/spec.md Archives the path allowlist enforcement spec delta.
openspec/changes/archive/2026-03-03-stronger-safety-model/specs/explainable-policy-decisions/spec.md Archives the explainable decisions spec delta.
openspec/changes/archive/2026-03-03-stronger-safety-model/proposal.md Archives proposal context and impact for the change.
openspec/changes/archive/2026-03-03-stronger-safety-model/design.md Archives design/risks/migration plan for the change.
openspec/changes/archive/2026-03-03-stronger-safety-model/.openspec.yaml Adds openspec archive metadata for the change.
docs/policy-safety-model.md Adds operator-facing guidance for interpreting denials and configuring allowlists/scoped approvals.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dubscode dubscode changed the base branch from test/broader-integration-coverage-and-pr-checks to main March 4, 2026 00:51
dubscode added 2 commits March 3, 2026 16:57
…nd path allowlists

Add explainable decision envelopes with reason codes, scoped persisted approval reuse/expiry/revocation,
canonical path allowlist enforcement, legacy policy adapter compatibility, expanded policy integration tests,
operator guidance docs, and archive/sync for stronger-safety-model OpenSpec change.
- always emit policyOutcomeLegacy from effective decision payloads

- add explicit approval-scope-granted and missing-target-path reason codes

- de-flake symlink tests, harden temp cleanup, and complete spec/doc purpose text
@dubscode dubscode force-pushed the feat/stronger-safety-model branch from dd64c0b to 8df752f Compare March 4, 2026 00:58
@dubscode dubscode merged commit 3a1aa3f into main Mar 4, 2026
1 check passed
@dubscode dubscode deleted the feat/stronger-safety-model branch March 4, 2026 00:59
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