@intentius/chant 0.124.40 → 0.124.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__fixtures__/oidc-emulator.d.ts +49 -0
- package/dist/__fixtures__/oidc-emulator.d.ts.map +1 -0
- package/dist/__fixtures__/oidc-emulator.js +89 -0
- package/dist/ci-handover.d.ts +117 -0
- package/dist/ci-handover.d.ts.map +1 -0
- package/dist/ci-handover.js +217 -0
- package/dist/ci-identity.d.ts +190 -0
- package/dist/ci-identity.d.ts.map +1 -0
- package/dist/ci-identity.js +219 -0
- package/dist/cli/handlers/approve.d.ts +2 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +20 -6
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +15 -1
- package/dist/cli/handlers/fan-out.js +16 -3
- package/dist/cli/handlers/gate-resume.d.ts +3 -0
- package/dist/cli/handlers/gate-resume.d.ts.map +1 -1
- package/dist/cli/handlers/gate-resume.js +15 -2
- package/dist/cli/handlers/lock.d.ts +8 -0
- package/dist/cli/handlers/lock.d.ts.map +1 -0
- package/dist/cli/handlers/lock.js +197 -0
- package/dist/cli/handlers/pr-env.d.ts +34 -0
- package/dist/cli/handlers/pr-env.d.ts.map +1 -0
- package/dist/cli/handlers/pr-env.js +436 -0
- package/dist/cli/handlers/pr.d.ts +74 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +503 -53
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +9 -0
- package/dist/cli/handlers/query.d.ts +6 -0
- package/dist/cli/handlers/query.d.ts.map +1 -0
- package/dist/cli/handlers/query.js +80 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +41 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +31 -2
- package/dist/cli/registry.d.ts +12 -2
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/fan-out-run.d.ts +28 -0
- package/dist/components/fan-out-run.d.ts.map +1 -1
- package/dist/components/fan-out-run.js +27 -3
- package/dist/components/pr-environment.d.ts +298 -0
- package/dist/components/pr-environment.d.ts.map +1 -0
- package/dist/components/pr-environment.js +406 -0
- package/dist/components/pr-hooks.d.ts +66 -0
- package/dist/components/pr-hooks.d.ts.map +1 -0
- package/dist/components/pr-hooks.js +119 -0
- package/dist/components/pr-pipeline.d.ts +72 -2
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +96 -5
- package/dist/components/pr-policy.d.ts +109 -0
- package/dist/components/pr-policy.d.ts.map +1 -0
- package/dist/components/pr-policy.js +150 -0
- package/dist/components/pr-run.d.ts.map +1 -1
- package/dist/components/pr-run.js +5 -3
- package/dist/gate-decision.d.ts +15 -2
- package/dist/gate-decision.d.ts.map +1 -1
- package/dist/gate-decision.js +17 -2
- package/dist/gate-policy.d.ts +140 -0
- package/dist/gate-policy.d.ts.map +1 -0
- package/dist/gate-policy.js +242 -0
- package/dist/lifecycle/gate-checkpoint.d.ts +1 -1
- package/dist/lifecycle/gate-checkpoint.js +1 -1
- package/dist/{workspace/trust → lifecycle}/gate-seal.d.ts +1 -1
- package/dist/lifecycle/gate-seal.d.ts.map +1 -0
- package/dist/lifecycle/query.d.ts +68 -0
- package/dist/lifecycle/query.d.ts.map +1 -0
- package/dist/lifecycle/query.js +246 -0
- package/dist/lifecycle/run-ledger.d.ts +13 -0
- package/dist/lifecycle/run-ledger.d.ts.map +1 -1
- package/dist/lifecycle/run-ledger.js +16 -0
- package/dist/lifecycle/target-lock.d.ts +97 -0
- package/dist/lifecycle/target-lock.d.ts.map +1 -0
- package/dist/lifecycle/target-lock.js +286 -0
- package/dist/op/activities/activity-contracts.d.ts +30 -0
- package/dist/op/activities/activity-contracts.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.js +26 -0
- package/dist/op/activities/index.d.ts +2 -0
- package/dist/op/activities/index.d.ts.map +1 -1
- package/dist/op/activities/index.js +4 -0
- package/dist/op/activities/review-agent.d.ts +137 -0
- package/dist/op/activities/review-agent.d.ts.map +1 -0
- package/dist/op/activities/review-agent.js +266 -0
- package/dist/op/builders.d.ts +9 -0
- package/dist/op/builders.d.ts.map +1 -1
- package/dist/op/builders.js +11 -0
- package/dist/op/cron.d.ts +8 -0
- package/dist/op/cron.d.ts.map +1 -1
- package/dist/op/cron.js +51 -0
- package/dist/op/gate-approval.d.ts +20 -13
- package/dist/op/gate-approval.d.ts.map +1 -1
- package/dist/op/gate-approval.js +13 -18
- package/dist/op/gate-quorum.d.ts +131 -0
- package/dist/op/gate-quorum.d.ts.map +1 -0
- package/dist/op/gate-quorum.js +183 -0
- package/dist/op/gate-resume.d.ts +4 -2
- package/dist/op/gate-resume.d.ts.map +1 -1
- package/dist/op/gate-resume.js +5 -4
- package/dist/op/gate-review.js +1 -1
- package/dist/op/gate.d.ts +32 -4
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +40 -24
- package/dist/op/index.d.ts +6 -4
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +4 -3
- package/dist/op/local-executor.d.ts.map +1 -1
- package/dist/op/local-executor.js +9 -3
- package/dist/op/op-waves-run.d.ts +62 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +190 -11
- package/dist/op/op-waves.d.ts +55 -3
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +63 -8
- package/dist/op/schedule-overdue.d.ts +57 -0
- package/dist/op/schedule-overdue.d.ts.map +1 -0
- package/dist/op/schedule-overdue.js +138 -0
- package/dist/override-gate.d.ts +2 -2
- package/dist/override-gate.d.ts.map +1 -1
- package/dist/override-gate.js +1 -1
- package/dist/pr-forge.d.ts +36 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +82 -0
- package/dist/pr-loop.d.ts +90 -1
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +77 -3
- package/dist/pr-post.d.ts +72 -0
- package/dist/pr-post.d.ts.map +1 -0
- package/dist/pr-post.js +134 -0
- package/dist/wave-blocked.d.ts +79 -0
- package/dist/wave-blocked.d.ts.map +1 -0
- package/dist/wave-blocked.js +245 -0
- package/dist/wave-engine.d.ts +6 -0
- package/dist/wave-engine.d.ts.map +1 -1
- package/dist/wave-engine.js +2 -0
- package/dist/wave-runtime.mjs +242 -242
- package/dist/workspace/__fixtures__/two-member-workspace.d.ts +1 -0
- package/dist/workspace/__fixtures__/two-member-workspace.d.ts.map +1 -1
- package/dist/workspace/__fixtures__/two-member-workspace.js +1 -1
- package/dist/workspace/ci-branches.d.ts +51 -0
- package/dist/workspace/ci-branches.d.ts.map +1 -0
- package/dist/workspace/ci-branches.js +69 -0
- package/dist/workspace/ci-cloud-identity.d.ts +11 -0
- package/dist/workspace/ci-cloud-identity.d.ts.map +1 -0
- package/dist/workspace/ci-cloud-identity.js +24 -0
- package/dist/workspace/ci-locks.d.ts +12 -0
- package/dist/workspace/ci-locks.d.ts.map +1 -0
- package/dist/workspace/ci-locks.js +6 -0
- package/dist/workspace/ci-run.d.ts +17 -1
- package/dist/workspace/ci-run.d.ts.map +1 -1
- package/dist/workspace/ci-run.js +64 -3
- package/dist/workspace/declaration.d.ts +63 -0
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +72 -1
- package/dist/workspace/declaration.schema.json +147 -0
- package/dist/workspace/identity-gate-rule.d.ts +1 -1
- package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
- package/dist/workspace/identity-gate-rule.js +1 -1
- package/dist/workspace/identity.d.ts +1 -1
- package/dist/workspace/identity.d.ts.map +1 -1
- package/dist/workspace/lineage-upgrade.d.ts.map +1 -1
- package/dist/workspace/lineage-upgrade.js +8 -5
- package/dist/workspace/member-pipeline.d.ts +6 -0
- package/dist/workspace/member-pipeline.d.ts.map +1 -1
- package/dist/workspace/member-pipeline.js +23 -0
- package/dist/workspace/pr-report.schema.json +73 -2
- package/dist/workspace/security.d.ts.map +1 -1
- package/dist/workspace/security.js +4 -0
- package/dist/workspace/status-gates.d.ts +3 -2
- package/dist/workspace/status-gates.d.ts.map +1 -1
- package/dist/workspace/status-gates.js +8 -7
- package/dist/workspace/status.d.ts.map +1 -1
- package/dist/workspace/status.js +4 -1
- package/dist/workspace/trust/seal.d.ts +2 -2
- package/dist/workspace/trust/seal.d.ts.map +1 -1
- package/dist/workspace/trust/seal.js +2 -2
- package/package.json +1 -1
- package/src/__fixtures__/oidc-emulator.ts +118 -0
- package/src/ci-handover.test.ts +209 -0
- package/src/ci-handover.ts +237 -0
- package/src/ci-identity.test.ts +201 -0
- package/src/ci-identity.ts +310 -0
- package/src/cli/handlers/approve.ts +18 -5
- package/src/cli/handlers/build.ts +15 -1
- package/src/cli/handlers/fan-out.ts +17 -4
- package/src/cli/handlers/gate-resume.ts +16 -2
- package/src/cli/handlers/lock.test.ts +98 -0
- package/src/cli/handlers/lock.ts +202 -0
- package/src/cli/handlers/operator.test.ts +3 -1
- package/src/cli/handlers/pr-env.ts +462 -0
- package/src/cli/handlers/pr-waves-blocked.test.ts +247 -0
- package/src/cli/handlers/pr.test.ts +184 -0
- package/src/cli/handlers/pr.ts +496 -59
- package/src/cli/handlers/promote.ts +9 -0
- package/src/cli/handlers/query.ts +78 -0
- package/src/cli/main.ts +41 -2
- package/src/cli/parse-args.ts +23 -2
- package/src/cli/registry.ts +12 -2
- package/src/components/fan-out-run.ts +39 -2
- package/src/components/fan-out-waves.test.ts +45 -1
- package/src/components/pr-environment.test.ts +249 -0
- package/src/components/pr-environment.ts +538 -0
- package/src/components/pr-hooks.test.ts +118 -0
- package/src/components/pr-hooks.ts +157 -0
- package/src/components/pr-pipeline.ts +130 -5
- package/src/components/pr-policy.test.ts +145 -0
- package/src/components/pr-policy.ts +211 -0
- package/src/components/pr-run.ts +5 -2
- package/src/gate-decision-bundle.test.ts +4 -3
- package/src/gate-decision.ts +39 -2
- package/src/gate-policy-bundle.test.ts +28 -0
- package/src/gate-policy.test.ts +162 -0
- package/src/gate-policy.ts +298 -0
- package/src/lifecycle/gate-checkpoint.ts +1 -1
- package/src/{workspace/trust → lifecycle}/gate-seal.ts +1 -1
- package/src/lifecycle/query.test.ts +91 -0
- package/src/lifecycle/query.ts +315 -0
- package/src/lifecycle/run-ledger.ts +18 -0
- package/src/lifecycle/target-lock.test.ts +195 -0
- package/src/lifecycle/target-lock.ts +347 -0
- package/src/op/activities/activity-contracts.ts +31 -0
- package/src/op/activities/index.ts +6 -0
- package/src/op/activities/review-agent.test.ts +240 -0
- package/src/op/activities/review-agent.ts +355 -0
- package/src/op/builders.ts +13 -0
- package/src/op/cron.ts +44 -0
- package/src/op/gate-alias.test.ts +2 -2
- package/src/op/gate-approval.test.ts +30 -9
- package/src/op/gate-approval.ts +23 -26
- package/src/op/gate-quorum.test.ts +139 -0
- package/src/op/gate-quorum.ts +248 -0
- package/src/op/gate-resume.ts +6 -3
- package/src/op/gate-review.ts +1 -1
- package/src/op/gate.ts +64 -23
- package/src/op/index.ts +13 -1
- package/src/op/local-executor.ts +9 -2
- package/src/op/op-waves-hook-targets.test.ts +126 -0
- package/src/op/op-waves-policy-hold.test.ts +66 -0
- package/src/op/op-waves-quorum.test.ts +101 -0
- package/src/op/op-waves-run.ts +233 -11
- package/src/op/op-waves.ts +83 -10
- package/src/op/schedule-overdue.test.ts +220 -0
- package/src/op/schedule-overdue.ts +161 -0
- package/src/override-gate-bundle.test.ts +1 -1
- package/src/override-gate.ts +2 -2
- package/src/pr-forge-bundle.test.ts +2 -2
- package/src/pr-forge.test.ts +33 -0
- package/src/pr-forge.ts +114 -0
- package/src/pr-loop-bundle.test.ts +2 -2
- package/src/pr-loop.test.ts +58 -0
- package/src/pr-loop.ts +146 -4
- package/src/pr-post.test.ts +141 -0
- package/src/pr-post.ts +159 -0
- package/src/wave-blocked-bundle.test.ts +25 -0
- package/src/wave-blocked.test.ts +146 -0
- package/src/wave-blocked.ts +271 -0
- package/src/wave-engine.ts +8 -0
- package/src/workspace/__fixtures__/two-member-workspace.ts +2 -2
- package/src/workspace/ci-branches.test.ts +62 -0
- package/src/workspace/ci-branches.ts +79 -0
- package/src/workspace/ci-cloud-identity.test.ts +53 -0
- package/src/workspace/ci-cloud-identity.ts +23 -0
- package/src/workspace/ci-locks.ts +16 -0
- package/src/workspace/ci-run-index.test.ts +2 -1
- package/src/workspace/ci-run.test.ts +107 -8
- package/src/workspace/ci-run.ts +72 -4
- package/src/workspace/declaration.schema.json +147 -0
- package/src/workspace/declaration.test.ts +76 -0
- package/src/workspace/declaration.ts +134 -2
- package/src/workspace/identity-gate-rule.ts +1 -1
- package/src/workspace/identity.ts +1 -1
- package/src/workspace/lineage-upgrade.ts +11 -8
- package/src/workspace/member-pipeline.test.ts +29 -0
- package/src/workspace/member-pipeline.ts +30 -0
- package/src/workspace/pr-report.schema.json +73 -2
- package/src/workspace/security.ts +4 -0
- package/src/workspace/status-gates.ts +9 -6
- package/src/workspace/status.ts +4 -1
- package/src/workspace/trust/gate-seal.test.ts +1 -1
- package/src/workspace/trust/seal.ts +2 -2
- package/dist/workspace/trust/gate-seal.d.ts.map +0 -1
- /package/dist/{workspace/trust → lifecycle}/gate-seal.js +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval rules (#4290): a gate's quorum as a list of rules, each with the
|
|
3
|
+
* targets it covers, how many approvers it needs, the roles that count, and
|
|
4
|
+
* whether one of them must not be the change's author.
|
|
5
|
+
*
|
|
6
|
+
* quorum: [
|
|
7
|
+
* { targets: ["prod-*"], count: 2, roles: ["platform"], notAuthor: true },
|
|
8
|
+
* { count: 1 },
|
|
9
|
+
* ]
|
|
10
|
+
*
|
|
11
|
+
* A gate takes every rule whose `targets` glob matches one of its targets
|
|
12
|
+
* (a rule with no `targets` covers every target), and passes once each rule
|
|
13
|
+
* it takes is met by distinct human approvers of its plan. A gate that takes
|
|
14
|
+
* no rule needs one human approval, the rule every gate had before.
|
|
15
|
+
*
|
|
16
|
+
* Roles come from `.chant/trust.json` at base (`roles`: role name to the
|
|
17
|
+
* principals that hold it), never from the approver's own claim. An
|
|
18
|
+
* approver counts toward `roles`, and as someone who is not the author, only
|
|
19
|
+
* when the approval proves who they are: a seal that verifies against the
|
|
20
|
+
* signers file at base, or under `pr-review` the forge review of the merged
|
|
21
|
+
* pull request. The judge of a gate decides that ({@link GateQuorumJudge});
|
|
22
|
+
* with none, no approval proves anything, so a rule naming roles or
|
|
23
|
+
* `notAuthor` is never met.
|
|
24
|
+
*
|
|
25
|
+
* This module is pure: no git, no file reads, no package, so
|
|
26
|
+
* `@intentius/chant/gate-decision` bundles it. The judge is built by the
|
|
27
|
+
* caller from the trust policy it read at base ({@link trustQuorumJudge}).
|
|
28
|
+
*/
|
|
29
|
+
import { type GateSigners } from "../lifecycle/gate-seal.js";
|
|
30
|
+
import type { GateResolutionRecord } from "../lifecycle/gate-ledger.js";
|
|
31
|
+
/** One approval rule. */
|
|
32
|
+
export interface GateQuorumRule {
|
|
33
|
+
/** Globs over the gate's targets (an Op wave's run targets, an Op gate's environment). Absent, the rule covers every target. */
|
|
34
|
+
targets?: string[];
|
|
35
|
+
/** Distinct human approvers the rule needs. At least 1. */
|
|
36
|
+
count: number;
|
|
37
|
+
/** When set, only an approver `.chant/trust.json` at base gives one of these roles counts, and only with a proven approval. */
|
|
38
|
+
roles?: string[];
|
|
39
|
+
/** When true, at least one counted approver is proven and is not the change's author. */
|
|
40
|
+
notAuthor?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** A gate's quorum: one rule (the form before #4290), or a list of them. */
|
|
43
|
+
export type GateQuorumSpec = GateQuorumRule | readonly GateQuorumRule[];
|
|
44
|
+
/** What a judge says about one approval. */
|
|
45
|
+
export interface QuorumJudgement {
|
|
46
|
+
/** The approval proves who `resolvedBy` is: a verified seal, or the forge's review. */
|
|
47
|
+
proven: boolean;
|
|
48
|
+
/** The roles `.chant/trust.json` at base gives the approver. Empty unless `proven`. */
|
|
49
|
+
roles: string[];
|
|
50
|
+
/** Whether the approver is the change's author. Undefined when nobody knows who the author is. */
|
|
51
|
+
author?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/** Judges one approval for the rules. */
|
|
54
|
+
export type GateQuorumJudge = (approval: GateResolutionRecord) => QuorumJudgement;
|
|
55
|
+
/** The judge with nothing to judge by: no approval proves anyone, and nobody's author is known. */
|
|
56
|
+
export declare const UNPROVEN_JUDGE: GateQuorumJudge;
|
|
57
|
+
/** How far one rule is met. */
|
|
58
|
+
export interface GateQuorumRuleProgress {
|
|
59
|
+
targets?: string[];
|
|
60
|
+
count: number;
|
|
61
|
+
roles?: string[];
|
|
62
|
+
notAuthor?: boolean;
|
|
63
|
+
/** The approvers it counts, oldest first. */
|
|
64
|
+
approvers: string[];
|
|
65
|
+
met: boolean;
|
|
66
|
+
/** Why the author could not be told apart, when `notAuthor` is set and nobody knows the author. */
|
|
67
|
+
authorUnknown?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/** The rules of a quorum, as a list. Absent, none. */
|
|
70
|
+
export declare function quorumRules(quorum: GateQuorumSpec | undefined): GateQuorumRule[];
|
|
71
|
+
/**
|
|
72
|
+
* Whether `target` matches `glob`: `*` within a `/` segment, `**` across
|
|
73
|
+
* segments (and `a/**\/b` across none), `?` one character. The same reading
|
|
74
|
+
* as the terraform lexicon's unit globs, so a Terragrunt root's glob means
|
|
75
|
+
* one thing in both.
|
|
76
|
+
*/
|
|
77
|
+
export declare function targetGlobMatch(glob: string, target: string): boolean;
|
|
78
|
+
/** The rules a gate whose targets are `targets` takes: those with no `targets`, and those a glob of matches one. */
|
|
79
|
+
export declare function quorumRulesFor(rules: readonly GateQuorumRule[], targets: readonly string[]): GateQuorumRule[];
|
|
80
|
+
/** The most approvers any rule needs, 1 with none. */
|
|
81
|
+
export declare function quorumNeed(rules: readonly GateQuorumRule[]): number;
|
|
82
|
+
/**
|
|
83
|
+
* Everything wrong with a quorum, one line each. `where` names it
|
|
84
|
+
* (`approval.quorum`). With `notAuthor: false`, a rule naming `notAuthor` is
|
|
85
|
+
* refused, since that caller has no author to judge by.
|
|
86
|
+
*/
|
|
87
|
+
export declare function quorumProblems(value: unknown, where: string, opts: {
|
|
88
|
+
notAuthor: boolean;
|
|
89
|
+
}): string[];
|
|
90
|
+
/** Whether two principals name the same person, compared trimmed and lower-cased. */
|
|
91
|
+
export declare const samePrincipal: (a: string, b: string) => boolean;
|
|
92
|
+
/** The roles `roles` (`.chant/trust.json`'s role grants) gives `who`, sorted. */
|
|
93
|
+
export declare function rolesOf(who: string, roles: Readonly<Record<string, readonly string[]>>): string[];
|
|
94
|
+
/** One approver as a rule counts them. */
|
|
95
|
+
export interface QuorumApprover {
|
|
96
|
+
who: string;
|
|
97
|
+
at: string;
|
|
98
|
+
judged: QuorumJudgement;
|
|
99
|
+
}
|
|
100
|
+
/** How far `rule` is met by `approvers`: each counted once, by name, oldest first. */
|
|
101
|
+
export declare function quorumRuleProgress(rule: GateQuorumRule, approvers: readonly QuorumApprover[]): GateQuorumRuleProgress;
|
|
102
|
+
/**
|
|
103
|
+
* Where a rule stands, in one line: `prod-*: 1 of 2 approvals (github:alice),
|
|
104
|
+
* needs 1 more from platform`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function quorumRuleLine(p: GateQuorumRuleProgress): string;
|
|
107
|
+
/** The rules that are not met, one line each joined by `; `. */
|
|
108
|
+
export declare function quorumWaiting(progress: readonly GateQuorumRuleProgress[]): string;
|
|
109
|
+
/** Whether a rule needs a proven approver: it names roles, or `notAuthor`. */
|
|
110
|
+
export declare const ruleNeedsProof: (rule: GateQuorumRule) => boolean;
|
|
111
|
+
/** What {@link trustQuorumJudge} judges by. */
|
|
112
|
+
export interface TrustQuorumInput {
|
|
113
|
+
/** The signers at base: an approval whose seal verifies for its approver against them is proven. */
|
|
114
|
+
signers: GateSigners;
|
|
115
|
+
/** `.chant/trust.json`'s role grants at base. */
|
|
116
|
+
roles: Readonly<Record<string, readonly string[]>>;
|
|
117
|
+
/** The change's authors, as principals. Absent, nobody knows who they are. */
|
|
118
|
+
authors?: readonly string[];
|
|
119
|
+
/**
|
|
120
|
+
* Under `pr-review`, the merged pull request's review, read from the forge
|
|
121
|
+
* in this run: a resolution that names this review's head and one of its
|
|
122
|
+
* approvers as `resolvedBy` is proven.
|
|
123
|
+
*/
|
|
124
|
+
review?: {
|
|
125
|
+
head: string;
|
|
126
|
+
approvers: readonly string[];
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** The judge a gate's rules are met by: proof from a seal or the live review, roles from trust.json at base. */
|
|
130
|
+
export declare function trustQuorumJudge(input: TrustQuorumInput): GateQuorumJudge;
|
|
131
|
+
//# sourceMappingURL=gate-quorum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate-quorum.d.ts","sourceRoot":"","sources":["../../src/op/gate-quorum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,yBAAyB;AACzB,MAAM,WAAW,cAAc;IAC7B,gIAAgI;IAChI,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IACd,+HAA+H;IAC/H,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,yFAAyF;IACzF,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,4EAA4E;AAC5E,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,SAAS,cAAc,EAAE,CAAC;AAExE,4CAA4C;AAC5C,MAAM,WAAW,eAAe;IAC9B,uFAAuF;IACvF,MAAM,EAAE,OAAO,CAAC;IAChB,uFAAuF;IACvF,KAAK,EAA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many approvers it needs, the roles that count, and
|
|
4
|
+
* whether one of them must not be the change's author.
|
|
5
|
+
*
|
|
6
|
+
* quorum: [
|
|
7
|
+
* { targets: ["prod-*"], count: 2, roles: ["platform"], notAuthor: true },
|
|
8
|
+
* { count: 1 },
|
|
9
|
+
* ]
|
|
10
|
+
*
|
|
11
|
+
* A gate takes every rule whose `targets` glob matches one of its targets
|
|
12
|
+
* (a rule with no `targets` covers every target), and passes once each rule
|
|
13
|
+
* it takes is met by distinct human approvers of its plan. A gate that takes
|
|
14
|
+
* no rule needs one human approval, the rule every gate had before.
|
|
15
|
+
*
|
|
16
|
+
* Roles come from `.chant/trust.json` at base (`roles`: role name to the
|
|
17
|
+
* principals that hold it), never from the approver's own claim. An
|
|
18
|
+
* approver counts toward `roles`, and as someone who is not the author, only
|
|
19
|
+
* when the approval proves who they are: a seal that verifies against the
|
|
20
|
+
* signers file at base, or under `pr-review` the forge review of the merged
|
|
21
|
+
* pull request. The judge of a gate decides that ({@link GateQuorumJudge});
|
|
22
|
+
* with none, no approval proves anything, so a rule naming roles or
|
|
23
|
+
* `notAuthor` is never met.
|
|
24
|
+
*
|
|
25
|
+
* This module is pure: no git, no file reads, no package, so
|
|
26
|
+
* `@intentius/chant/gate-decision` bundles it. The judge is built by the
|
|
27
|
+
* caller from the trust policy it read at base ({@link trustQuorumJudge}).
|
|
28
|
+
*/
|
|
29
|
+
import { gateSealRefusal } from "../lifecycle/gate-seal.js";
|
|
30
|
+
/** The judge with nothing to judge by: no approval proves anyone, and nobody's author is known. */
|
|
31
|
+
export const UNPROVEN_JUDGE = () => ({ proven: false, roles: [] });
|
|
32
|
+
/** The rules of a quorum, as a list. Absent, none. */
|
|
33
|
+
export function quorumRules(quorum) {
|
|
34
|
+
if (quorum === undefined)
|
|
35
|
+
return [];
|
|
36
|
+
return Array.isArray(quorum) ? [...quorum] : [quorum];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Whether `target` matches `glob`: `*` within a `/` segment, `**` across
|
|
40
|
+
* segments (and `a/**\/b` across none), `?` one character. The same reading
|
|
41
|
+
* as the terraform lexicon's unit globs, so a Terragrunt root's glob means
|
|
42
|
+
* one thing in both.
|
|
43
|
+
*/
|
|
44
|
+
export function targetGlobMatch(glob, target) {
|
|
45
|
+
const g = glob.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
46
|
+
let re = "";
|
|
47
|
+
for (let i = 0; i < g.length; i++) {
|
|
48
|
+
const c = g[i];
|
|
49
|
+
if (c === "*" && g[i + 1] === "*") {
|
|
50
|
+
if (g[i + 2] === "/") {
|
|
51
|
+
re += "(?:.*/)?";
|
|
52
|
+
i += 2;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
re += ".*";
|
|
56
|
+
i += 1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (c === "*")
|
|
60
|
+
re += "[^/]*";
|
|
61
|
+
else if (c === "?")
|
|
62
|
+
re += "[^/]";
|
|
63
|
+
else
|
|
64
|
+
re += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
65
|
+
}
|
|
66
|
+
return new RegExp(`^${re}$`).test(target.replace(/\\/g, "/").replace(/\/+$/, ""));
|
|
67
|
+
}
|
|
68
|
+
/** The rules a gate whose targets are `targets` takes: those with no `targets`, and those a glob of matches one. */
|
|
69
|
+
export function quorumRulesFor(rules, targets) {
|
|
70
|
+
return rules.filter((r) => r.targets === undefined || r.targets.some((g) => targets.some((t) => targetGlobMatch(g, t))));
|
|
71
|
+
}
|
|
72
|
+
/** The most approvers any rule needs, 1 with none. */
|
|
73
|
+
export function quorumNeed(rules) {
|
|
74
|
+
return rules.reduce((n, r) => Math.max(n, r.count), 1);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Everything wrong with a quorum, one line each. `where` names it
|
|
78
|
+
* (`approval.quorum`). With `notAuthor: false`, a rule naming `notAuthor` is
|
|
79
|
+
* refused, since that caller has no author to judge by.
|
|
80
|
+
*/
|
|
81
|
+
export function quorumProblems(value, where, opts) {
|
|
82
|
+
const list = Array.isArray(value) ? value : [value];
|
|
83
|
+
const problems = [];
|
|
84
|
+
if (Array.isArray(value) && value.length === 0)
|
|
85
|
+
problems.push(`\`${where}\` must name at least one rule`);
|
|
86
|
+
list.forEach((rule, i) => {
|
|
87
|
+
const at = Array.isArray(value) ? `${where}[${i}]` : where;
|
|
88
|
+
if (typeof rule !== "object" || rule === null || Array.isArray(rule)) {
|
|
89
|
+
problems.push(`\`${at}\` must be an object`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const q = rule;
|
|
93
|
+
if (typeof q.count !== "number" || !Number.isInteger(q.count) || q.count < 1)
|
|
94
|
+
problems.push(`\`${at}.count\` must be an integer of at least 1`);
|
|
95
|
+
if (q.roles !== undefined && (!Array.isArray(q.roles) || q.roles.length === 0 || q.roles.some((r) => typeof r !== "string" || r === ""))) {
|
|
96
|
+
problems.push(`\`${at}.roles\` must be a non-empty list of role names`);
|
|
97
|
+
}
|
|
98
|
+
if (q.targets !== undefined && (!Array.isArray(q.targets) || q.targets.length === 0 || q.targets.some((t) => typeof t !== "string" || t === ""))) {
|
|
99
|
+
problems.push(`\`${at}.targets\` must be a non-empty list of globs`);
|
|
100
|
+
}
|
|
101
|
+
if (q.notAuthor !== undefined && typeof q.notAuthor !== "boolean")
|
|
102
|
+
problems.push(`\`${at}.notAuthor\` must be true or false`);
|
|
103
|
+
if (q.notAuthor === true && !opts.notAuthor) {
|
|
104
|
+
problems.push(`\`${at}.notAuthor\` is not read here: an Op gate has no author to judge by. An Op waves spec's \`approvals.quorum\` reads it from the merged pull request`);
|
|
105
|
+
}
|
|
106
|
+
const known = new Set(["targets", "count", "roles", "notAuthor"]);
|
|
107
|
+
for (const key of Object.keys(q))
|
|
108
|
+
if (!known.has(key))
|
|
109
|
+
problems.push(`\`${at}.${key}\` is not a quorum field; use targets, count, roles or notAuthor`);
|
|
110
|
+
});
|
|
111
|
+
return problems;
|
|
112
|
+
}
|
|
113
|
+
const norm = (s) => s.normalize("NFKC").trim().toLowerCase();
|
|
114
|
+
/** Whether two principals name the same person, compared trimmed and lower-cased. */
|
|
115
|
+
export const samePrincipal = (a, b) => norm(a) === norm(b);
|
|
116
|
+
/** The roles `roles` (`.chant/trust.json`'s role grants) gives `who`, sorted. */
|
|
117
|
+
export function rolesOf(who, roles) {
|
|
118
|
+
return Object.entries(roles)
|
|
119
|
+
.filter(([, principals]) => principals.some((p) => samePrincipal(p, who)))
|
|
120
|
+
.map(([role]) => role)
|
|
121
|
+
.sort();
|
|
122
|
+
}
|
|
123
|
+
/** How far `rule` is met by `approvers`: each counted once, by name, oldest first. */
|
|
124
|
+
export function quorumRuleProgress(rule, approvers) {
|
|
125
|
+
const seen = new Set();
|
|
126
|
+
const counted = [];
|
|
127
|
+
for (const a of [...approvers].sort((x, y) => Date.parse(x.at) - Date.parse(y.at))) {
|
|
128
|
+
if (seen.has(norm(a.who)))
|
|
129
|
+
continue;
|
|
130
|
+
if (rule.roles?.length && !(a.judged.proven && a.judged.roles.some((r) => rule.roles.includes(r))))
|
|
131
|
+
continue;
|
|
132
|
+
seen.add(norm(a.who));
|
|
133
|
+
counted.push(a);
|
|
134
|
+
}
|
|
135
|
+
const notAuthor = !rule.notAuthor || counted.some((a) => a.judged.proven && a.judged.author === false);
|
|
136
|
+
const authorUnknown = rule.notAuthor === true && !notAuthor && counted.some((a) => a.judged.proven && a.judged.author === undefined);
|
|
137
|
+
return {
|
|
138
|
+
...(rule.targets ? { targets: [...rule.targets] } : {}),
|
|
139
|
+
count: rule.count,
|
|
140
|
+
...(rule.roles?.length ? { roles: [...rule.roles] } : {}),
|
|
141
|
+
...(rule.notAuthor ? { notAuthor: true } : {}),
|
|
142
|
+
approvers: counted.map((a) => a.who),
|
|
143
|
+
met: counted.length >= rule.count && notAuthor,
|
|
144
|
+
...(authorUnknown ? { authorUnknown: true } : {}),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Where a rule stands, in one line: `prod-*: 1 of 2 approvals (github:alice),
|
|
149
|
+
* needs 1 more from platform`.
|
|
150
|
+
*/
|
|
151
|
+
export function quorumRuleLine(p) {
|
|
152
|
+
const scope = p.targets ? p.targets.join(", ") : "every target";
|
|
153
|
+
const have = `${p.approvers.length} of ${p.count} approval${p.count === 1 ? "" : "s"}${p.approvers.length ? ` (${p.approvers.join(", ")})` : ""}`;
|
|
154
|
+
if (p.met)
|
|
155
|
+
return `${scope}: ${have}, met`;
|
|
156
|
+
const more = p.count - p.approvers.length;
|
|
157
|
+
const needs = [];
|
|
158
|
+
if (more > 0)
|
|
159
|
+
needs.push(`${more} more${p.roles?.length ? ` from ${p.roles.join(" or ")}` : ""}`);
|
|
160
|
+
if (p.notAuthor)
|
|
161
|
+
needs.push(more > 0 ? "one of them not the author" : "an approver who is not the author");
|
|
162
|
+
const unknown = p.authorUnknown ? " (the change's author is not known, so no approver can show they are someone else)" : "";
|
|
163
|
+
return `${scope}: ${have}, needs ${needs.join(", ")}${unknown}`;
|
|
164
|
+
}
|
|
165
|
+
/** The rules that are not met, one line each joined by `; `. */
|
|
166
|
+
export function quorumWaiting(progress) {
|
|
167
|
+
return progress.filter((p) => !p.met).map(quorumRuleLine).join("; ");
|
|
168
|
+
}
|
|
169
|
+
/** Whether a rule needs a proven approver: it names roles, or `notAuthor`. */
|
|
170
|
+
export const ruleNeedsProof = (rule) => (rule.roles?.length ?? 0) > 0 || rule.notAuthor === true;
|
|
171
|
+
/** The judge a gate's rules are met by: proof from a seal or the live review, roles from trust.json at base. */
|
|
172
|
+
export function trustQuorumJudge(input) {
|
|
173
|
+
return (r) => {
|
|
174
|
+
const sealed = r.seal !== undefined && r.seal !== null && gateSealRefusal(input.signers, r) === null;
|
|
175
|
+
const reviewed = input.review !== undefined && r.review?.head === input.review.head && input.review.approvers.some((a) => samePrincipal(a, r.resolvedBy));
|
|
176
|
+
const proven = sealed || reviewed;
|
|
177
|
+
return {
|
|
178
|
+
proven,
|
|
179
|
+
roles: proven ? rolesOf(r.resolvedBy, input.roles) : [],
|
|
180
|
+
...(input.authors !== undefined ? { author: input.authors.some((a) => samePrincipal(a, r.resolvedBy)) } : {}),
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
}
|
package/dist/op/gate-resume.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* `./gate`'s quorum rules.
|
|
9
9
|
*/
|
|
10
10
|
import type { GateResolutionRecord, PendingGateRecord } from "../lifecycle/gate-ledger.js";
|
|
11
|
+
import type { GateQuorumJudge } from "./gate-quorum.js";
|
|
11
12
|
export { isGateRunLocator, resolveGateRunLocator, resumeGateRun, resumeTokenFromEnv, type GateResumeOutcome, type GateRunLocator, type ResumeGateRunOptions, } from "../gate-resume-run.js";
|
|
12
13
|
/**
|
|
13
14
|
* The resolution that answers `standing`, read the way a run decides the gate
|
|
@@ -15,7 +16,8 @@ export { isGateRunLocator, resolveGateRunLocator, resumeGateRun, resumeTokenFrom
|
|
|
15
16
|
* gate ledger's pending facts, which place the human quorum's anchor (#3206);
|
|
16
17
|
* without them it is `standing` itself. A workspace's
|
|
17
18
|
* `identity.gates` rule is not applied here: the resumed job applies it, and
|
|
18
|
-
* waits again when the approval does not count.
|
|
19
|
+
* waits again when the approval does not count. `judge` proves approvers
|
|
20
|
+
* for approval rules that name roles (#4290); absent, none is proven.
|
|
19
21
|
*/
|
|
20
|
-
export declare function resolutionAnswering(resolutions: readonly GateResolutionRecord[], standing: PendingGateRecord, pending?: readonly PendingGateRecord[]): GateResolutionRecord | undefined;
|
|
22
|
+
export declare function resolutionAnswering(resolutions: readonly GateResolutionRecord[], standing: PendingGateRecord, pending?: readonly PendingGateRecord[], judge?: GateQuorumJudge): GateResolutionRecord | undefined;
|
|
21
23
|
//# sourceMappingURL=gate-resume.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate-resume.d.ts","sourceRoot":"","sources":["../../src/op/gate-resume.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"gate-resume.d.ts","sourceRoot":"","sources":["../../src/op/gate-resume.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGxF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,SAAS,oBAAoB,EAAE,EAC5C,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,SAAS,iBAAiB,EAAe,EAClD,KAAK,CAAC,EAAE,eAAe,GACtB,oBAAoB,GAAG,SAAS,CASlC"}
|
package/dist/op/gate-resume.js
CHANGED
|
@@ -16,16 +16,17 @@ export { isGateRunLocator, resolveGateRunLocator, resumeGateRun, resumeTokenFrom
|
|
|
16
16
|
* gate ledger's pending facts, which place the human quorum's anchor (#3206);
|
|
17
17
|
* without them it is `standing` itself. A workspace's
|
|
18
18
|
* `identity.gates` rule is not applied here: the resumed job applies it, and
|
|
19
|
-
* waits again when the approval does not count.
|
|
19
|
+
* waits again when the approval does not count. `judge` proves approvers
|
|
20
|
+
* for approval rules that name roles (#4290); absent, none is proven.
|
|
20
21
|
*/
|
|
21
|
-
export function resolutionAnswering(resolutions, standing, pending = [standing]) {
|
|
22
|
+
export function resolutionAnswering(resolutions, standing, pending = [standing], judge) {
|
|
22
23
|
const env = standing.environment;
|
|
23
24
|
const mine = resolutions.filter((r) => env === undefined || r.environment === env);
|
|
24
25
|
if (standing.approval) {
|
|
25
|
-
const tally = tallyGateApprovals(mine, standing.gate, standing.timestamp, standing.planDigest, standing.approval, humanQuorumSince(pending, standing));
|
|
26
|
+
const tally = tallyGateApprovals(mine, standing.gate, standing.timestamp, standing.planDigest, standing.approval, humanQuorumSince(pending, standing), judge);
|
|
26
27
|
if (tally.permit)
|
|
27
28
|
return tally.permit;
|
|
28
|
-
return tally.
|
|
29
|
+
return tally.met ? tally.counted[tally.counted.length - 1] : undefined;
|
|
29
30
|
}
|
|
30
31
|
return latestResolutionForPlan(mine, standing.gate, standing.timestamp, standing.planDigest).resolution;
|
|
31
32
|
}
|
package/dist/op/gate-review.js
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* back. The author's own review never counts.
|
|
30
30
|
*/
|
|
31
31
|
import { readFileSync } from "node:fs";
|
|
32
|
-
import { gateSealRefusal } from "../
|
|
32
|
+
import { gateSealRefusal } from "../lifecycle/gate-seal.js";
|
|
33
33
|
import { readTrustPolicy } from "../workspace/trust/policy.js";
|
|
34
34
|
import { gitRevisionSource } from "../workspace/record-source.js";
|
|
35
35
|
import { forgePrincipalOf, ForgeApiError } from "../pr-forge.js";
|
package/dist/op/gate.d.ts
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
import { type GateResolutionInput, type GateResolutionRecord, type PendingGateInput, type PendingGateRecord } from "../lifecycle/gate-ledger.js";
|
|
35
35
|
import { type AppliedGateRecord } from "../lifecycle/gate-applied.js";
|
|
36
36
|
import { type GateApprover, type ResolvedGateApproval } from "./gate-approval.js";
|
|
37
|
+
import { type GateQuorumJudge, type GateQuorumRuleProgress } from "./gate-quorum.js";
|
|
37
38
|
import { type GateCheckpoint } from "../lifecycle/gate-checkpoint.js";
|
|
38
39
|
import type { ResolvedGateAlias } from "./gate-alias.js";
|
|
39
40
|
/**
|
|
@@ -84,6 +85,16 @@ export interface GateLedgerPort {
|
|
|
84
85
|
approvalRule?(gate: string, at?: {
|
|
85
86
|
base?: string;
|
|
86
87
|
}): Promise<GateApprovalRule | null>;
|
|
88
|
+
/**
|
|
89
|
+
* The judge a gate's approval rules are met by (#4290): which approvals
|
|
90
|
+
* prove their approver (a seal verified against the signers at base) and
|
|
91
|
+
* the roles `.chant/trust.json` at base gives them. `at.base` as for
|
|
92
|
+
* {@link GateLedgerPort.approvalRule}. Absent, no approval proves anyone,
|
|
93
|
+
* so a rule naming roles is never met.
|
|
94
|
+
*/
|
|
95
|
+
quorumJudge?(gate: string, at?: {
|
|
96
|
+
base?: string;
|
|
97
|
+
}): Promise<GateQuorumJudge>;
|
|
87
98
|
/** The approvals a wave applied under (#3784), from `_gates/<op>/applied.jsonl`. Absent on a port that never spends approvals. */
|
|
88
99
|
readApplied?(op: string): Promise<AppliedGateRecord[]>;
|
|
89
100
|
/** Record that a wave is about to apply under an approval (#3784), which spends it. */
|
|
@@ -177,6 +188,13 @@ export interface GateCheckInput {
|
|
|
177
188
|
* it so `chant approve` can evaluate the policy.
|
|
178
189
|
*/
|
|
179
190
|
approval?: ResolvedGateApproval;
|
|
191
|
+
/**
|
|
192
|
+
* Judges approvals for `approval.quorum`'s rules (#4290). Absent, the
|
|
193
|
+
* port's {@link GateLedgerPort.quorumJudge} at its default base, else no
|
|
194
|
+
* approval proves anyone. A wave passes one that knows the change's author
|
|
195
|
+
* and the merged pull request's review.
|
|
196
|
+
*/
|
|
197
|
+
judge?: GateQuorumJudge;
|
|
180
198
|
/** ISO-8601 "now" — supplied by the caller, so the decision is deterministic under test. */
|
|
181
199
|
now?: string;
|
|
182
200
|
/**
|
|
@@ -264,6 +282,8 @@ export interface GateQuorumProgress {
|
|
|
264
282
|
/** Approvers whose approval counts toward the quorum, oldest first. */
|
|
265
283
|
approvers: string[];
|
|
266
284
|
need: number;
|
|
285
|
+
/** Where each approval rule the gate takes stands (#4290). Absent when it takes none. */
|
|
286
|
+
rules?: GateQuorumRuleProgress[];
|
|
267
287
|
}
|
|
268
288
|
/** Either the gate is answered, or it is a standing fact. */
|
|
269
289
|
export type GateCheck = {
|
|
@@ -319,8 +339,12 @@ export declare function approverOf(record: GateResolutionRecord): GateApprover;
|
|
|
319
339
|
export interface GateTally {
|
|
320
340
|
/** Distinct human approvers of this plan who count toward the quorum, one record each (their newest), oldest first. */
|
|
321
341
|
counted: GateResolutionRecord[];
|
|
322
|
-
/** The
|
|
342
|
+
/** The most approvers a rule needs, 1 when the gate declares none. */
|
|
323
343
|
need: number;
|
|
344
|
+
/** Every rule is met (#4290); with no rules, one human approved. */
|
|
345
|
+
met: boolean;
|
|
346
|
+
/** Where each rule stands (#4290). Absent when the gate takes no rule. */
|
|
347
|
+
rules?: GateQuorumRuleProgress[];
|
|
324
348
|
/** The newest approval whose recorded permit passes the gate on its own. Only in `enforce` mode, only for a permit recorded under `enforce`, and only under the gate's current policy version and resolved context. */
|
|
325
349
|
permit?: GateResolutionRecord;
|
|
326
350
|
/** The newest approval of this gate for a different plan, when the gate binds one. */
|
|
@@ -337,8 +361,12 @@ export interface GateTally {
|
|
|
337
361
|
* pending fact re-recorded for a changed mode or context keeps a partly
|
|
338
362
|
* filled quorum (#3206). It defaults to `sinceIso`.
|
|
339
363
|
*
|
|
340
|
-
* Of those, only a human's counts toward the quorum, once per `resolvedBy
|
|
341
|
-
*
|
|
364
|
+
* Of those, only a human's counts toward the quorum, once per `resolvedBy`.
|
|
365
|
+
* The quorum is a list of rules (#4290, `./gate-quorum.ts`), already the ones
|
|
366
|
+
* the gate takes: each is met by distinct humans, counting toward `roles`
|
|
367
|
+
* only an approver `judge` proves and gives one of them (roles from
|
|
368
|
+
* `.chant/trust.json` at base, never the approver's claim), and the gate
|
|
369
|
+
* passes when every rule is met. With no rule, one human passes it. An agent counts
|
|
342
370
|
* only through a recorded `allow` in `enforce` mode, evaluated under the
|
|
343
371
|
* policy version the gate declares now, recorded while the gate was in
|
|
344
372
|
* `enforce` (#2512), and evaluated under the context the gate resolves now
|
|
@@ -346,7 +374,7 @@ export interface GateTally {
|
|
|
346
374
|
* after the gate switches to `enforce`, and a `deny` never removes a human's approval: a policy can add
|
|
347
375
|
* a way through the gate but cannot take one away.
|
|
348
376
|
*/
|
|
349
|
-
export declare function tallyGateApprovals(records: GateResolutionRecord[], gate: string, sinceIso: string, planDigest: string | undefined, approval: ResolvedGateApproval, humansSinceIso?: string): GateTally;
|
|
377
|
+
export declare function tallyGateApprovals(records: GateResolutionRecord[], gate: string, sinceIso: string, planDigest: string | undefined, approval: ResolvedGateApproval, humansSinceIso?: string, judge?: GateQuorumJudge): GateTally;
|
|
350
378
|
/**
|
|
351
379
|
* Where a gate's human quorum starts counting (#3206): the oldest pending fact
|
|
352
380
|
* in the unbroken run of facts, newest first from `standing`, recorded for
|
package/dist/op/gate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/op/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EASL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAA2D,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5H,OAAO,EAAqB,KAAK,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/op/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EASL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAA2D,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5H,OAAO,EAAqB,KAAK,YAAY,EAAE,KAAK,oBAAoB,E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mBAAmB,CAuBnH;AAgED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAmNlG;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,MAAM,CAK1H;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAO9F"}
|
package/dist/op/gate.js
CHANGED
|
@@ -37,6 +37,7 @@ import { isModelAuthored } from "../lifecycle/gate-origin.js";
|
|
|
37
37
|
import { appliedGatePath, isApprovalSpent, parseAppliedGateLines } from "../lifecycle/gate-applied.js";
|
|
38
38
|
import { sortedJsonReplacer } from "../utils.js";
|
|
39
39
|
import { gateContextDigest } from "./gate-approval.js";
|
|
40
|
+
import { quorumNeed, quorumRuleProgress, quorumRules, ruleNeedsProof, samePrincipal, trustQuorumJudge, UNPROVEN_JUDGE, } from "./gate-quorum.js";
|
|
40
41
|
import { pushLifecycleReport, readBlobBySha, readBlobFromPath, readPathSha, requireLifecycleLedger, writeBlobToPath, RefCASConflictError } from "../lifecycle/git.js";
|
|
41
42
|
import { parseDuration } from "./duration.js";
|
|
42
43
|
import { ciRunIdFromEnv, resolveGateRunLocator } from "./gate-run-locator.js";
|
|
@@ -74,6 +75,12 @@ export function gitGateLedgerPort(opts) {
|
|
|
74
75
|
const { gateAdmission } = await import("../workspace/identity.js");
|
|
75
76
|
return gateAdmission(opts?.cwd ?? process.cwd(), gate, at?.base);
|
|
76
77
|
},
|
|
78
|
+
async quorumJudge(_gate, at) {
|
|
79
|
+
// #4290: the signers and role grants at base, never the approver's claim.
|
|
80
|
+
const { scopeSource } = await import("../workspace/write-scope.js");
|
|
81
|
+
const { policy } = scopeSource(opts?.cwd ?? process.cwd(), at?.base);
|
|
82
|
+
return trustQuorumJudge({ signers: policy, roles: policy.roles });
|
|
83
|
+
},
|
|
77
84
|
async appendResolution(input) {
|
|
78
85
|
const { record } = await appendGateResolution(input, opts);
|
|
79
86
|
return { record, ...(await pushLifecycleReport(opts)) };
|
|
@@ -209,8 +216,12 @@ export function approverOf(record) {
|
|
|
209
216
|
* pending fact re-recorded for a changed mode or context keeps a partly
|
|
210
217
|
* filled quorum (#3206). It defaults to `sinceIso`.
|
|
211
218
|
*
|
|
212
|
-
* Of those, only a human's counts toward the quorum, once per `resolvedBy
|
|
213
|
-
*
|
|
219
|
+
* Of those, only a human's counts toward the quorum, once per `resolvedBy`.
|
|
220
|
+
* The quorum is a list of rules (#4290, `./gate-quorum.ts`), already the ones
|
|
221
|
+
* the gate takes: each is met by distinct humans, counting toward `roles`
|
|
222
|
+
* only an approver `judge` proves and gives one of them (roles from
|
|
223
|
+
* `.chant/trust.json` at base, never the approver's claim), and the gate
|
|
224
|
+
* passes when every rule is met. With no rule, one human passes it. An agent counts
|
|
214
225
|
* only through a recorded `allow` in `enforce` mode, evaluated under the
|
|
215
226
|
* policy version the gate declares now, recorded while the gate was in
|
|
216
227
|
* `enforce` (#2512), and evaluated under the context the gate resolves now
|
|
@@ -218,12 +229,13 @@ export function approverOf(record) {
|
|
|
218
229
|
* after the gate switches to `enforce`, and a `deny` never removes a human's approval: a policy can add
|
|
219
230
|
* a way through the gate but cannot take one away.
|
|
220
231
|
*/
|
|
221
|
-
export function tallyGateApprovals(records, gate, sinceIso, planDigest, approval, humansSinceIso = sinceIso) {
|
|
232
|
+
export function tallyGateApprovals(records, gate, sinceIso, planDigest, approval, humansSinceIso = sinceIso, judge = UNPROVEN_JUDGE) {
|
|
222
233
|
const since = new Date(sinceIso).getTime();
|
|
223
234
|
const humansSince = Math.min(since, new Date(humansSinceIso).getTime());
|
|
224
235
|
const at = (r) => new Date(r.timestamp).getTime();
|
|
225
|
-
const
|
|
236
|
+
const rules = quorumRules(approval.quorum);
|
|
226
237
|
const context = gateContextDigest(approval.context);
|
|
238
|
+
// Each human once: their newest approval, or their newest proven one when they have one.
|
|
227
239
|
const byActor = new Map();
|
|
228
240
|
let permit;
|
|
229
241
|
let mismatched;
|
|
@@ -250,22 +262,22 @@ export function tallyGateApprovals(records, gate, sinceIso, planDigest, approval
|
|
|
250
262
|
decision.contextDigest === context && (!permit || at(r) >= at(permit))) {
|
|
251
263
|
permit = r;
|
|
252
264
|
}
|
|
253
|
-
|
|
254
|
-
if (approver.kind !== "human")
|
|
255
|
-
continue;
|
|
256
|
-
if (roles && !(approver.roles ?? []).some((role) => roles.includes(role)))
|
|
265
|
+
if (approverOf(r).kind !== "human")
|
|
257
266
|
continue;
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
267
|
+
const key = r.resolvedBy.normalize("NFKC").trim().toLowerCase();
|
|
268
|
+
const proven = rules.some(ruleNeedsProof) && judge(r).proven;
|
|
269
|
+
const prior = byActor.get(key);
|
|
270
|
+
if (!prior || (proven && !prior.proven) || (proven === prior.proven && at(r) >= at(prior.record)))
|
|
271
|
+
byActor.set(key, { record: r, proven });
|
|
261
272
|
}
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
need:
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
273
|
+
const humans = [...byActor.values()].map((v) => v.record).sort((a, b) => at(a) - at(b));
|
|
274
|
+
const extra = { ...(permit ? { permit } : {}), ...(mismatched ? { mismatched } : {}) };
|
|
275
|
+
if (rules.length === 0)
|
|
276
|
+
return { counted: humans, need: 1, met: humans.length >= 1, ...extra };
|
|
277
|
+
const approvers = humans.map((r) => ({ who: r.resolvedBy, at: r.timestamp, judged: judge(r) }));
|
|
278
|
+
const progress = rules.map((rule) => quorumRuleProgress(rule, approvers));
|
|
279
|
+
const counted = humans.filter((r) => progress.some((p) => p.approvers.some((a) => samePrincipal(a, r.resolvedBy))));
|
|
280
|
+
return { counted, need: quorumNeed(rules), met: progress.every((p) => p.met), rules: progress, ...extra };
|
|
269
281
|
}
|
|
270
282
|
/**
|
|
271
283
|
* Where a gate's human quorum starts counting (#3206): the oldest pending fact
|
|
@@ -503,11 +515,15 @@ export async function evaluateGate(port, input) {
|
|
|
503
515
|
standing.approval?.policy?.version === input.approval.policy?.version
|
|
504
516
|
? humanQuorumSince(pending, standing)
|
|
505
517
|
: since;
|
|
506
|
-
|
|
518
|
+
// #4290: who an approval proves, and their roles at base, for rules that read them.
|
|
519
|
+
const judge = quorumRules(input.approval.quorum).some(ruleNeedsProof)
|
|
520
|
+
? (input.judge ?? (await port.quorumJudge?.(input.gate)) ?? UNPROVEN_JUDGE)
|
|
521
|
+
: UNPROVEN_JUDGE;
|
|
522
|
+
const tally = tallyGateApprovals(resolutions, input.gate, since, input.planDigest, input.approval, humansSince, judge);
|
|
507
523
|
if (tally.permit) {
|
|
508
524
|
return { satisfied: true, resolution: tally.permit, via: "policy", approvals: tally.counted };
|
|
509
525
|
}
|
|
510
|
-
if (tally.
|
|
526
|
+
if (tally.met) {
|
|
511
527
|
return {
|
|
512
528
|
satisfied: true,
|
|
513
529
|
resolution: tally.counted[tally.counted.length - 1],
|
|
@@ -516,19 +532,19 @@ export async function evaluateGate(port, input) {
|
|
|
516
532
|
};
|
|
517
533
|
}
|
|
518
534
|
mismatched = tally.mismatched;
|
|
519
|
-
quorum = { approvers: tally.counted.map((r) => r.resolvedBy), need: tally.need };
|
|
535
|
+
quorum = { approvers: tally.counted.map((r) => r.resolvedBy), need: tally.need, ...(tally.rules ? { rules: tally.rules } : {}) };
|
|
520
536
|
// #3949: old and new approvals add up toward one quorum, each approver once.
|
|
521
537
|
const counted = new Set(tally.counted.map((r) => r.resolvedBy));
|
|
522
538
|
const extra = fromAliases.filter((r) => !counted.has(r.resolvedBy));
|
|
523
539
|
if (extra.length > 0) {
|
|
524
540
|
const asCarried = new Map(extra.map((r) => [{ version: 1, ...carriedApproval(r, input.op, input.gate, now) }, r]));
|
|
525
|
-
const combined = tallyGateApprovals([...resolutions, ...asCarried.keys()], input.gate, since, input.planDigest, input.approval, humansSince);
|
|
526
|
-
if (combined.
|
|
541
|
+
const combined = tallyGateApprovals([...resolutions, ...asCarried.keys()], input.gate, since, input.planDigest, input.approval, humansSince, judge);
|
|
542
|
+
if (combined.met) {
|
|
527
543
|
const written = await carry(combined.counted.filter((r) => asCarried.has(r)).map((r) => asCarried.get(r)));
|
|
528
544
|
const approvals = [...combined.counted.filter((r) => !asCarried.has(r)), ...written];
|
|
529
545
|
return { satisfied: true, resolution: written[written.length - 1], via: "alias", approvals, carried: written };
|
|
530
546
|
}
|
|
531
|
-
quorum = { approvers: combined.counted.map((r) => r.resolvedBy), need: combined.need };
|
|
547
|
+
quorum = { approvers: combined.counted.map((r) => r.resolvedBy), need: combined.need, ...(combined.rules ? { rules: combined.rules } : {}) };
|
|
532
548
|
}
|
|
533
549
|
}
|
|
534
550
|
else {
|