feat(contracts): authority-gated governance — GovernanceGate contract (#200)#209
Merged
Merged
Conversation
…tract (#200) Names and contracts the propose→gate→commit invariant that was emerging as an unnamed dryRun pattern across charter and colonyos. Makes the invariants enforceable at type-check time rather than by convention. Types in @stackbilt/types (generic, reusable): - GovernanceDecision = 'approve' | 'override' | 'dismiss' - GovernanceProposal — id (deterministic), alreadyCompliant, delta, expires? - GovernanceReceipt — proposalId, decision, committedAt - GovernanceGate<Context, P extends GovernanceProposal> — propose + commit Implementation in @stackbilt/policies: - PolicyGovernanceProposal extends GovernanceProposal (adds repoPath for commit replay without re-passing context through the interface) - PolicyGovernanceGate implements GovernanceGate<string, PolicyGovernanceProposal> wrapping applyPolicies; propose() never writes, commit('dismiss') is a no-op, proposal id is a sha256 of resolved repoPath + delta Invariants verified by 6 new tests: - propose() does not write files - propose() is idempotent (same state → same id) - commit('approve') writes and emits receipt - commit('dismiss') does not write, still emits receipt - commit('override') applies even when alreadyCompliant - alreadyCompliant proposals have empty delta Closes #200 Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
Names and contracts the propose→gate→commit invariant (#200). The pattern existed as an emergent unnamed mechanism (
dryRunflag onapplyPolicies) but was not contracted, not enforced at the type level, and not auditable.What changed
@stackbilt/types— new generic contract (no deps):GovernanceDecision = 'approve' | 'override' | 'dismiss'GovernanceProposal— stableid,alreadyCompliant,delta: string[], optionalexpiresGovernanceReceipt—proposalId,decision,committedAtGovernanceGate<Context, P extends GovernanceProposal>—propose(context)+commit(proposal, decision)@stackbilt/policies— concrete implementation:PolicyGovernanceProposal extends GovernanceProposal(addsrepoPathfor commit replay)PolicyGovernanceGate implements GovernanceGate<string, PolicyGovernanceProposal>propose()callsapplyPolicies(dryRun: true)— never writescommit('approve'|'override')callsapplyPolicies(dryRun: false)commit('dismiss')— no-op, receipt still emittedidis sha256 of resolved repoPath + delta (deterministic for same state)Invariants enforced
PolicyGovernanceProposalwhich onlypropose()producescommit('dismiss')skipsapplyPoliciesentirelyGovernanceReceipt— non-nullablePolicyGovernanceGatetakes opts at construction; cannot self-elevateapplyPoliciesunchanged — additive onlyThe existing
applyPoliciesfunction andStampOptions/PolicyStampResulttypes are untouched. The gate wraps them. OSS additive-only policy satisfied.Test plan
pnpm run buildcleanCloses #200
🤖 Generated with Claude Code