Skip to content

feat(spec,policy): tool safety metadata + fail-closed policy derivation#124

Merged
leo-aa88 merged 4 commits into
mainfrom
feat/tool-safety-metadata-103
Jun 1, 2026
Merged

feat(spec,policy): tool safety metadata + fail-closed policy derivation#124
leo-aa88 merged 4 commits into
mainfrom
feat/tool-safety-metadata-103

Conversation

@leo-aa88
Copy link
Copy Markdown
Member

@leo-aa88 leo-aa88 commented Jun 1, 2026

Summary

Implements #103: tools self-describe blast radius via spec.safety, and the policy layer derives approval requirements when no explicit Policy rule matches.

  • internal/spec: ToolSafety block (trusted, sideEffects, requiresApproval), fail-closed ResolveToolSafety, NormalizeProjectGraph materialization, and SafetyFromMCPMeta / MergeToolSafety for MCP meta.mcp_flags precedence.
  • internal/policy: Derive truth table, CheckToolCall safety fallback (exit code 5 / approval_required when unattended), explicit approvals.requiredFor remains authoritative.
  • internal/plan: risk summary flags tools that will require approval with decision + source (explicit_policy_rule, safety_metadata, fail_closed_default).
  • Fixtures/examples: read-only native helpers set sideEffects: false; GitHub demo tools set trusted: true so policy can still gate write operations.

Test plan

  • make ci (verify-fmt, vet, go test -race ./...)
  • Unit tests: ResolveToolSafety truth table, Derive, policy evaluator safety fallback, plan risk safety messages
  • Integration: run_policy exit 5, pr-review-demo blocks post_comment, demo/hello workflows succeed with updated safety metadata

Made with Cursor

leo-aa88 and others added 3 commits June 1, 2026 04:29
Introduce spec.safety (trusted, sideEffects, requiresApproval) with
ResolveToolSafety defaults, NormalizeProjectGraph materialization, and
MCP meta.mcp_flags mapping helpers for issue #103.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add Derive/EffectiveToolDecision and consult safety metadata in
CheckToolCall after explicit approvals.requiredFor checks. Unattended
mutating tools without policy or trusted metadata return exit code 5.

Co-authored-by: Cursor <cursoragent@cursor.com>
Surface effective decision and source in plan risk summaries. Update
fixtures with explicit safety on demo and test tools so read-only native
helpers and trusted GitHub demos keep expected run behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

ReviewGate [WARN] WARN

Stats

  • Files changed: 39
  • Raw LOC changed: 957
  • LOC after §10.4 exclusions (human_loc_changed): 957
  • PR author class: human (human collaborator account) — login leo-aa88 (§10.4.2).

Warnings (3)

  • medium too_many_files_changed -- PR exceeds warn files_changed threshold: 39 files (threshold 25).
  • medium too_large_human_loc -- PR exceeds warn human_loc_changed threshold: 957 lines (threshold 800).
  • medium many_config_files -- This PR touches 16 config files, at or above the warning threshold of 1 (config_files_changed).

Suggested labels: reviewability-warn, too-large, config-change

File categories: 39 files (0 risky)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Automated review

Summary

Enhances tool safety metadata and policy derivation mechanisms with significant changes.

Findings

  • No issues found.

- Fix NewEvaluator/Engine.Evaluator godoc for nil-policy safety enforcement
- Add CHANGELOG [Unreleased] with breaking-change migration guide
- Document tool-level trusted vs requiredFor; plan prefix vs runtime exact match
- Mark MCP SafetyFromMCPMeta/MergeToolSafety as not wired yet
- Validate non-empty spec.safety blocks; export spec.BoolPtr
- Add run_safety CLI fixture: exit 5 from safety only (no Policy)
- Revert testGraphWithTools to production fail-closed defaults
- Add prefix vs exact approval tests; CONTRIBUTING CHANGELOG note

Co-authored-by: Cursor <cursoragent@cursor.com>
@leo-aa88 leo-aa88 merged commit 848451d into main Jun 1, 2026
7 checks passed
@leo-aa88 leo-aa88 deleted the feat/tool-safety-metadata-103 branch June 1, 2026 07:46
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.

1 participant