Skip to content

feat: organization policy rule methods (/v1/org/policy)#52

Merged
guyb1 merged 1 commit into
mainfrom
feat/org-policy-methods
Jul 21, 2026
Merged

feat: organization policy rule methods (/v1/org/policy)#52
guyb1 merged 1 commit into
mainfrom
feat/org-policy-methods

Conversation

@guyb1

@guyb1 guyb1 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What

Adds the organization policy-engine surface to onecli.org — 10 methods over /v1/org/policy: listPolicyRules, getPolicyRule, createPolicyRule, updatePolicyRule, deletePolicyRule, reorderPolicyRules, getPolicyDefault, setPolicyDefault, publishPolicy, getPolicyLastPublish.

  • Staged model: writes land in the org draft and publish automatically; { skipPublish: true } stages for an explicit reviewed publishPolicy() (a publish snapshots the whole org draft, including other users' staged changes). A publish failure after a successful write rethrows the publish error unchanged — the write stays staged.
  • Honest types in both directions: PolicyRuleTarget models responses (arrays always present, unset scalars explicit null); PolicyRuleTargetInput models writes (optionals only — the API rejects nulls on write); OrgPolicyRuleIdentityInput excludes agent (the org API rejects agent identities); PolicyWriteResult<T> discriminates on published; conditions is a typed union (behavioral conditions or resource scoping).
  • Legacy createRule/updateRule/deleteRule are @deprecated — cloud deployments reject them with 410 Gone; self-hosted servers that have not cut over still accept them. A route-miss 404 on policy endpoints maps to a clear "requires OneCLI Cloud or Enterprise" hint.

Why

OneCLI Cloud runs the policy engine; org-wide guardrails are authored through /v1/org/policy. The SDK needs typed, publish-aware methods for it — and the request/response type split has to land before npm freezes the contract (responses carry nulls that write inputs reject; one shared type would make a read→write round-trip compile and then fail at runtime).

Verification

  • tsc clean, vitest 101/101, tsup build green.
  • Tests pin exact URLs (including id encoding), request bodies, the write-then-publish call order, skipPublish single-call behavior, publish-failure rethrow after a successful write, the ?status= query, orderedIds body, last-publish null, and the route-miss hint.

Review

Reviewed via the ship pipeline: hunk-by-hunk self-review, two independent adversarial reviewers, then a cross-repo fix-attacker pass verifying the fixes and the cross-repo contract against the server source. Skills applied: typescript-advanced-types (the input/output type split, discriminated result: 4 fixes), typescript-pro (API honesty, JSDoc: 2 fixes). Findings fixed: 1 high (shared target type conflated read/write shapes), 3 medium, 4 low. Final gates green.

Related PRs

Merge order: this PR and the CLI 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

Adds the /v1/org/policy surface to the org client (10 methods):
listPolicyRules, getPolicyRule, createPolicyRule, updatePolicyRule,
deletePolicyRule, reorderPolicyRules, getPolicyDefault, setPolicyDefault,
publishPolicy, and getPolicyLastPublish.

Writes publish automatically; pass { skipPublish: true } to stage and
review first (a publish snapshots the whole org draft, including changes
staged by other users). If the publish step fails after a successful
write, the write stays staged and the publish request's error is
rethrown unchanged.

Types are honest about both directions: PolicyRuleTarget models
responses (arrays always present, unset scalars explicit null) while
PolicyRuleTargetInput models writes (optionals only; the API rejects
nulls on write); org rule inputs exclude agent identities at the type
level (the org API rejects them); PolicyWriteResult discriminates on
`published`. The legacy createRule/updateRule/deleteRule methods are
marked @deprecated (cloud deployments reject them with 410 Gone).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@guyb1
guyb1 merged commit 7843b08 into main Jul 21, 2026
3 checks passed
@guyb1
guyb1 deleted the feat/org-policy-methods branch July 21, 2026 21:25
@guyb1 guyb1 mentioned this pull request Jul 21, 2026
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