feat: policy command family (/v1/policy + /v1/org/policy)#93
Merged
Conversation
Adds `onecli policy` and `onecli org policy`, the staged draft-to-publish policy engine surface (10 operations per scope): rules list/get/create/update/delete/reorder, default get/set, publish, and status (a client-composed staged diff via a faithful Go port of the server's policy-diff library). Writes auto-publish only when the scope's draft has no other staged changes; otherwise the publish is withheld (`publishSkipped` + `pendingChanges` in the output) so a write never ships someone else's half-finished edits. `--publish-all` overrides the guard; `--no-publish` always stages. `--json` PATCH payloads are sent verbatim as raw JSON so explicit nulls (the only way to clear rateLimit/conditions server-side) reach the wire. The legacy `rules` / `org rules` commands keep working against self-hosted servers that predate the policy engine and now point at the policy family in their help text; cloud deployments reject legacy writes with 410 Gone. New GONE and VALIDATION_ERROR error codes map 410/422 responses to actionable output. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Adds the policy-engine command surface:
onecli policy(project scope) andonecli org policy(organization scope, admin org key):rules list|get|create|update|delete|reorder,default get|set,publish,status— 10 operations per scope against/v1/policyand/v1/org/policy.publishSkipped,pendingChangesin the JSON output) so a write never ships someone else's staged edits.--publish-alloverrides,--no-publishalways stages.statuscomposes the staged diff client-side via a faithful Go port of the server's policy-diff library (custom rules only, keyed bylogicalId).--jsonPATCH bodies: sent verbatim, so explicit JSON nulls (the only way to clearrateLimit/conditionsserver-side) reach the wire.GONE/VALIDATION_ERRORcodes for 410/422; route-miss 404s upgrade to an actionable "this server does not support the (org) policy API" message; a missing-project 401/400 points at--projectinstead of the misleadingauth login.rules/org rulescommands keep working against self-hosted servers that predate the policy engine; their help now points at the policy family (cloud deployments reject legacy writes with410 Gone).Why
OneCLI Cloud runs the policy engine; the legacy
/v1/ruleswrite surface returns410 Gonethere. The CLI needs first-class commands for the canonical API, with the staged draft→publish semantics made safe for agent use (a publish snapshots the whole scope draft, so the guard prevents accidentally enforcing other users' staged changes).Verification
go build/go vetclean,golangci-lint0 issues,go test -race -count=1green.connectionIdfield), status-query routing, the reorder body, verbatim raw PATCH bodies (nulls survive), 410/422/403 envelope pass-through, route-miss 404 upgrade vs resource-404 pass-through,last-publishJSON null.""vs null distinct, reorder + default-change counting), plus a composition test pinning the publish guard's four GET feed.--publish-all/ publish-failure-after-write / contradictory flags.Review
Reviewed via the ship pipeline: hunk-by-hunk self-review, then two independent adversarial reviewers, then a cross-repo fix-attacker pass verifying the fixes and the cross-repo contract (paths, field names, enums, status codes,
logicalIdsemantics) against the server source. Skills applied:agent-first-cli(command surface / output contracts: 3 fixes),golang-patterns+golang-pro(raw-body handling, diff-port fidelity: 4 fixes). Findings fixed: 1 high (typed--jsonround-trip silently dropped JSON null clears — now raw pass-through, wire-tested), 2 medium, 6 low. Final gates green.Related PRs
Merge order: this PR and the SDK PR are independent and can merge anytime (the API is live on OneCLI Cloud and current Enterprise releases); the docs PR merges last.
🤖 Generated with Claude Code