Skip to content

feat(runner): add declarative JSON gate policy - #34

Merged
jesse-merhi merged 5 commits into
mainfrom
jesse/openclaw-native-gate-policy
Jul 31, 2026
Merged

jesse-merhi merged 5 commits into
mainfrom
jesse/openclaw-native-gate-policy

Conversation

@jesse-merhi

@jesse-merhi jesse-merhi commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

New behavior

Trusted profiles can now attach declarative rules to the JSON already emitted by any built-in or command-defined scanner. Scanner implementations do not need ClawScan-specific policy support, wrappers, or changed exit codes.

  • equals matches string, boolean, or exact JSON-number values.
  • exists: true fires when a path resolves to non-empty evidence.
  • Ordered path aliases, array traversal, per-object field aliases, identifier normalization, and preferred-root fallback cover scanner schema variants.
  • JSON and exit-code rules compose; block wins over warn.
  • Failed or skipped scanners do not fire policy, while valid evidence from ordinary nonzero scanner exits remains gate-eligible.
  • Raw scanner JSON remains byte-identical, judge execution is unchanged, and gate actions remain record-only.
  • A published JSON Schema now gives .clawscan.yml authors completion and early validation without replacing ClawScan's runtime checks.

The existing embedded clawhub and clawhub-aig profiles deliberately remain gate-free and evidence-only. Declarative gates are opt-in through a custom profile; regression tests protect that compatibility contract.

Profile and artifact proof

An immutable third-party scanner can be gated directly. The schema directive is optional and understood by YAML language-server integrations:

# yaml-language-server: $schema=https://raw.githubusercontent.com/openclaw/clawscan/main/schemas/clawscan.schema.json

version: 1
profiles:
  review:
    scanners:
      - id: third-party
        command: third-party scan --json {{target}}
        gate:
          rules:
            - id: critical-risk
              path:
                - result.risk
                - result.risk_level
              equals: critical
              normalize: identifier
              action: block
            - id: any-policy-violation
              path: result.violations[]
              exists: true
              action: warn

A fired JSON rule is recorded alongside the preserved scanner evidence:

{
  "gate": "block",
  "gateRules": [
    {
      "scanner": "third-party",
      "rule": "critical-risk",
      "path": "result.risk",
      "value": "CRITICAL",
      "action": "block"
    }
  ]
}

How to verify

  1. Add the schema directive to a .clawscan.yml file and confirm an editor flags an unknown profile field, invalid scanner ID, missing {{target}}, malformed gate rule, or unsupported path expression.
  2. Resolve the same file with ClawScan and confirm supported profile syntax still loads normally.
  3. Resolve the embedded clawhub and clawhub-aig profiles and confirm neither produces gate rules.
  4. Feed fixture JSON that matches an equals or exists rule and inspect gate, gateRules, and the unchanged scanner raw value.
  5. Exercise ordered paths and per-field aliases with absent, null, empty, nonmatching, and matching values; confirm the first present field and first authoritative path control the verdict.
  6. Return valid JSON with an ordinary nonzero exit and combine a JSON rule with blockOnExitCode; confirm both rules fire and the strongest action is recorded.
  7. Return valid JSON from a timeout, signal, or reserved infrastructure exit; confirm the evidence is preserved but does not gate.

Checks

  • TMPDIR=/private/tmp go test -count=1 ./... — passed.
  • TMPDIR=/private/tmp go vet ./... — passed.
  • make docs-site — passed with no tracked output changes.
  • Repository pre-ship review — clean after fixing explicit-null alias resolution and aligning schema/runtime path validation.
  • Schema contract tests compile the Draft 2020-12 schema, validate the embedded ClawHub profile and every registered built-in scanner, and reject representative invalid scanner and gate declarations.

Implementation notes

The path language is intentionally small: dotted object fields, [] array traversal, and | field aliases. It is not a general JSONPath evaluator. Runtime parsing rejects unknown fields, duplicate IDs or paths, ambiguous conditions, invalid actions, unsupported normalization, malformed paths, and non-finite numeric values.

YAML-specific decoding and compatibility logic live in internal/profiles/yaml.go; resolver.go remains focused on profile selection and CLI option resolution. The schema provides authoring feedback, while runtime validation remains the source of truth for execution.

@jesse-merhi
jesse-merhi force-pushed the jesse/openclaw-native-gate-policy branch from 422c7a3 to b9605f9 Compare July 27, 2026 15:30
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed July 30, 2026, 11:16 PM ET / July 31, 2026, 03:16 UTC.

ClawSweeper review

What this changes

This PR adds opt-in declarative JSON gate rules to scanner profile definitions, records matching rules in run artifacts and CLI summaries, and publishes a JSON Schema for profile authoring.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for maintainer review. The declarative gate capability is not on current main, and the earlier P1 compatibility concern is addressed by the final PR head: embedded clawhub and clawhub-aig profiles remain gate-free while custom profiles opt in explicitly.

Priority: P2
Reviewed head: 3c64e689ae761775c05ec78d83af0dbf3cb006e3
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused compatibility repairs, broad automated coverage, and clean reported checks; its remaining question is public product acceptance rather than a demonstrated code defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR author is a repository member, so the external-contributor real-behavior-proof gate does not apply; the PR also supplies detailed fixture and validation claims for maintainer review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR author is a repository member, so the external-contributor real-behavior-proof gate does not apply; the PR also supplies detailed fixture and validation claims for maintainer review.
Evidence reviewed 6 items Current-main status: The feature remains PR-only: GitHub reports this PR as open and unmerged, with head 3c64e689ae761775c05ec78d83af0dbf3cb006e3 against current main 3d041c6cc08c127f6b1cdaf0288058e86f15b6b2.
Prior compatibility finding resolved: The final head includes commit bd0a16e606f9f556779fd0f06572d9d3208534f7 (fix(profiles): preserve ClawHub gate behavior), and the final diff adds assertions that both embedded ClawHub profiles resolve with zero gate rules.
Opt-in profile boundary: The profile parser adds JSON rules beneath an explicit scanner gate.rules configuration, while the PR body and resolver tests retain the existing embedded-profile evidence-only contract.
Findings None None.
Security None None.

How this fits together

ClawScan turns YAML profile scanner entries into runner options, invokes scanners that preserve their raw JSON evidence, and writes artifacts for operators or an external judge. This PR inserts an optional gate-evaluation step over valid scanner JSON, producing recorded warn or block outcomes without changing scanner payloads.

flowchart LR
  A[Profile YAML] --> B[Profile resolver]
  B --> C[Scanner options]
  C --> D[Scanner JSON evidence]
  D --> E[Optional gate evaluation]
  E --> F[Run artifact]
  F --> G[CLI summary and judge input]
Loading

Decision needed

Question Recommendation
Should ClawScan expose declarative gate.rules as a supported public profile contract, including the documented JSON path and action semantics? Sponsor the opt-in gate contract: Accept the declarative gate language as a public profile feature, preserving the current gate-free embedded ClawHub profiles and the supplied compatibility tests.

Why: The patch is technically bounded and preserves the previously identified embedded-profile compatibility contract, but it creates a lasting user-facing configuration language and artifact behavior that needs maintainer acceptance.

Before merge

  • Resolve merge risk (P1) - Although gates are opt-in for custom profiles and embedded ClawHub profiles are now covered as gate-free, this introduces a durable public profile schema and changes scanner-result status handling for infrastructure exits; maintainers should confirm those semantics are the intended long-term contract before merge.
  • Complete next step (P2) - The patch no longer has a concrete mechanical blocker, but a maintainer must decide whether its new profile policy language belongs in the supported public CLI contract.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Changed surface 26 files affected; 2,304 additions and 265 deletions The proposal crosses profile decoding, runtime evaluation, scanner adapters, artifacts, schema validation, documentation, and tests.
Compatibility coverage 2 embedded profile assertions added The final diff directly checks that clawhub and clawhub-aig retain their gate-free behavior after the earlier review finding.
Validation signal 4 relevant GitHub checks succeeded Dependency review, tests, workflow linting, and submission validation passed for the reviewed head.

Merge-risk options

Maintainer options:

  1. Merge with the opt-in compatibility contract (recommended)
    Approve the public gate feature only with the embedded ClawHub profiles remaining gate-free and with the existing resolver and runner regression coverage retained.
  2. Narrow the gate language before merge
    Reduce the supported policy surface if maintainers do not want aliases, fallback behavior, or normalization to become permanent configuration commitments.
  3. Pause the core feature
    Close or defer the PR if evidence-only scanner artifacts plus the existing external judge are the preferred long-term policy boundary.

Technical review

Best possible solution:

Adopt the feature only with the gate language kept opt-in, the embedded ClawHub profiles permanently evidence-only, and focused regression coverage for profile resolution plus ordinary versus infrastructure scanner exits.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR proposes a new profile capability rather than reporting broken current-main behavior. The relevant verification is behavioral coverage of explicit gate rules and preservation of gate-free embedded profiles.

Is this the best way to solve the issue?

Yes, conditionally: evaluating raw scanner JSON from an opt-in profile rule is a narrow way to add policy without changing scanner implementations, provided maintainers accept the new configuration contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3d041c6cc08c.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR author is a repository member, so the external-contributor real-behavior-proof gate does not apply; the PR also supplies detailed fixture and validation claims for maintainer review.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded public configuration feature with meaningful operator-facing behavior but no evidence of an urgent regression.
  • merge-risk: 🚨 compatibility: The PR introduces a public policy schema and adjusts scanner-status semantics, so profile and artifact compatibility need explicit maintainer acceptance.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR author is a repository member, so the external-contributor real-behavior-proof gate does not apply; the PR also supplies detailed fixture and validation claims for maintainer review.

Evidence

What I checked:

  • Current-main status: The feature remains PR-only: GitHub reports this PR as open and unmerged, with head 3c64e689ae761775c05ec78d83af0dbf3cb006e3 against current main 3d041c6cc08c127f6b1cdaf0288058e86f15b6b2. (3c64e689ae76)
  • Prior compatibility finding resolved: The final head includes commit bd0a16e606f9f556779fd0f06572d9d3208534f7 (fix(profiles): preserve ClawHub gate behavior), and the final diff adds assertions that both embedded ClawHub profiles resolve with zero gate rules. (internal/profiles/resolver_test.go, bd0a16e606f9)
  • Opt-in profile boundary: The profile parser adds JSON rules beneath an explicit scanner gate.rules configuration, while the PR body and resolver tests retain the existing embedded-profile evidence-only contract. (internal/profiles/yaml.go, 3c64e689ae76)
  • Runner coverage: The runner test expansion covers equality and existence rules, path aliases and traversal, nonzero exits with valid JSON, and infrastructure-exit suppression, which are the central semantics of the new gate layer. (internal/runner/runner_test.go, d8e57e37a403)
  • Repository policy fit: The supplied repository AGENTS.md permits profile-based scanner configuration, requires raw scanner evidence to remain raw, and requires built-in scanner registration through the registry; the PR’s documented design preserves raw JSON and makes policy profile-driven. (AGENTS.md, 3d041c6cc08c)
  • Dependency and CI signal: The PR adds one Go JSON Schema library and its transitive checksum entries; the provided GitHub checks show Dependency review, Test, workflow linting, and submission validation all succeeded on the reviewed PR. (go.mod, 3c64e689ae76)

Likely related people:

  • jesse-merhi: Authored all five commits in this focused gate-policy series, including the follow-up that restores the embedded ClawHub gate-free behavior. (role: feature author and recent profile/gate contributor; confidence: high; commits: d8e57e37a403, 2954e46b3893, bd0a16e606f9; files: internal/profiles/yaml.go, internal/profiles/resolver_test.go, internal/runner/runner.go)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Obtain explicit maintainer acceptance of the public gate.rules contract and scanner-status semantics before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-29T22:08:06.634Z sha 2954e46 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T23:08:38.738Z sha 2954e46 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T11:09:53.100Z sha 2954e46 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T11:24:53.292Z sha 2954e46 :: found issues before merge. :: [P1] Preserve the existing ClawHub profile gate contract
  • reviewed 2026-07-30T17:20:21.655Z sha 2954e46 :: found issues before merge. :: [P1] Preserve the existing ClawHub profile gate contract
  • reviewed 2026-07-30T20:12:57.558Z sha 2954e46 :: found issues before merge. :: [P1] Preserve the existing ClawHub profile gate contract
  • reviewed 2026-07-30T22:11:45.377Z sha 2954e46 :: found issues before merge. :: [P1] Preserve the existing ClawHub profile gate contract
  • reviewed 2026-07-31T00:27:39.719Z sha 2954e46 :: found issues before merge. :: [P1] Preserve the existing ClawHub profile gate contract

@jesse-merhi
jesse-merhi force-pushed the jesse/openclaw-native-gate-policy branch from b9605f9 to 916d6df Compare July 28, 2026 14:36
@jesse-merhi jesse-merhi changed the title feat(runner): add native built-in gate policy feat(runner): add declarative JSON gate policy Jul 28, 2026
@jesse-merhi
jesse-merhi force-pushed the jesse/openclaw-native-gate-policy branch from 916d6df to d8e57e3 Compare July 28, 2026 14:54
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 28, 2026
@jesse-merhi

Copy link
Copy Markdown
Member Author

/clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. proof: sufficient Contributor real behavior proof is sufficient. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. labels Jul 29, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 31, 2026
@jesse-merhi
jesse-merhi marked this pull request as ready for review July 31, 2026 04:18
Copilot AI review requested due to automatic review settings July 31, 2026 04:18

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@clawsweeper

clawsweeper Bot commented Jul 31, 2026

Copy link
Copy Markdown

ClawSweeper status: review started.

I am starting a fresh review of this pull request: feat(runner): add declarative JSON gate policy This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@jesse-merhi
jesse-merhi merged commit 13c6cb5 into main Jul 31, 2026
13 checks passed
@vincentkoc
vincentkoc deleted the jesse/openclaw-native-gate-policy branch September 25, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants