@manifesto-ai/governance 0.1.0
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/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/index.d.ts +472 -0
- package/dist/index.js +1002 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Manifesto AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @manifesto-ai/governance
|
|
2
|
+
|
|
3
|
+
> Split-native governance protocol for legitimacy, authority, and proposal lifecycle.
|
|
4
|
+
|
|
5
|
+
`@manifesto-ai/governance` is the package to use when you need to reason about proposal legitimacy directly. It owns the governance lifecycle and composes with `@manifesto-ai/lineage` when you need branch-aware sealing.
|
|
6
|
+
|
|
7
|
+
> **Current Contract Note:** The current public package contract is documented in [docs/governance-SPEC-2.0.0v.md](docs/governance-SPEC-2.0.0v.md). The v1.0.0 governance spec remains available as the historical split-era baseline.
|
|
8
|
+
|
|
9
|
+
## What This Package Owns
|
|
10
|
+
|
|
11
|
+
- proposal lifecycle and status changes
|
|
12
|
+
- actor and authority binding
|
|
13
|
+
- execution-key policy and context
|
|
14
|
+
- governance events and event dispatch
|
|
15
|
+
- in-memory governance storage
|
|
16
|
+
- intent-instance helpers
|
|
17
|
+
|
|
18
|
+
## When to Use It
|
|
19
|
+
|
|
20
|
+
Use `@manifesto-ai/governance` directly when you want:
|
|
21
|
+
|
|
22
|
+
- custom governance evaluation or policy logic
|
|
23
|
+
- isolated tests for proposal lifecycle behavior
|
|
24
|
+
- explicit control over authority and event dispatch
|
|
25
|
+
- a lower-level building block for `@manifesto-ai/world`
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import {
|
|
31
|
+
createGovernanceEventDispatcher,
|
|
32
|
+
createGovernanceService,
|
|
33
|
+
createInMemoryGovernanceStore,
|
|
34
|
+
} from "@manifesto-ai/governance";
|
|
35
|
+
import { createLineageService, createInMemoryLineageStore } from "@manifesto-ai/lineage";
|
|
36
|
+
|
|
37
|
+
const lineageStore = createInMemoryLineageStore();
|
|
38
|
+
const lineage = createLineageService(lineageStore);
|
|
39
|
+
const governanceStore = createInMemoryGovernanceStore();
|
|
40
|
+
const governance = createGovernanceService(governanceStore, {
|
|
41
|
+
lineageService: lineage,
|
|
42
|
+
});
|
|
43
|
+
const eventDispatcher = createGovernanceEventDispatcher({ service: governance });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Docs
|
|
47
|
+
|
|
48
|
+
- [Docs Landing](docs/README.md)
|
|
49
|
+
- [Governance Guide](docs/GUIDE.md)
|
|
50
|
+
- [Governance Specification](docs/governance-SPEC-2.0.0v.md)
|
|
51
|
+
- [Historical v1 Baseline](docs/governance-SPEC-1.0.0v.md)
|
|
52
|
+
- [VERSION-INDEX](docs/VERSION-INDEX.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { ErrorValue, Intent as Intent$1, Snapshot } from '@manifesto-ai/core';
|
|
2
|
+
export { Snapshot } from '@manifesto-ai/core';
|
|
3
|
+
import { WorldId, BranchId, World, PreparedLineageCommit, LineageService } from '@manifesto-ai/lineage';
|
|
4
|
+
export { ArtifactRef, BranchId, PreparedLineageCommit, World, WorldId } from '@manifesto-ai/lineage';
|
|
5
|
+
|
|
6
|
+
type ProposalId = string;
|
|
7
|
+
type DecisionId = string;
|
|
8
|
+
type ActorId = string;
|
|
9
|
+
type AuthorityId = string;
|
|
10
|
+
type ExecutionKey = string;
|
|
11
|
+
type ActorKind = "human" | "agent" | "system";
|
|
12
|
+
type AuthorityKind = "auto" | "human" | "policy" | "tribunal";
|
|
13
|
+
type ProposalStatus = "submitted" | "evaluating" | "approved" | "rejected" | "executing" | "completed" | "failed" | "superseded";
|
|
14
|
+
type SupersedeReason = "branch_switch" | "head_advance" | "manual_cancel";
|
|
15
|
+
interface ActorRef {
|
|
16
|
+
readonly actorId: ActorId;
|
|
17
|
+
readonly kind: ActorKind;
|
|
18
|
+
readonly name?: string;
|
|
19
|
+
readonly meta?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
interface AuthorityRef {
|
|
22
|
+
readonly authorityId: AuthorityId;
|
|
23
|
+
readonly kind: AuthorityKind;
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
}
|
|
26
|
+
interface IntentScope {
|
|
27
|
+
readonly allowedPaths?: readonly string[];
|
|
28
|
+
readonly note?: string;
|
|
29
|
+
}
|
|
30
|
+
type SourceKind = "ui" | "api" | "agent" | "system";
|
|
31
|
+
interface SourceRef {
|
|
32
|
+
readonly kind: SourceKind;
|
|
33
|
+
readonly eventId: string;
|
|
34
|
+
}
|
|
35
|
+
interface IntentOrigin {
|
|
36
|
+
readonly projectionId: string;
|
|
37
|
+
readonly source: SourceRef;
|
|
38
|
+
readonly actor: ActorRef;
|
|
39
|
+
readonly note?: string;
|
|
40
|
+
}
|
|
41
|
+
interface IntentBody {
|
|
42
|
+
readonly type: string;
|
|
43
|
+
readonly input?: unknown;
|
|
44
|
+
readonly scopeProposal?: IntentScope;
|
|
45
|
+
}
|
|
46
|
+
interface IntentInstance {
|
|
47
|
+
readonly body: IntentBody;
|
|
48
|
+
readonly intentId: string;
|
|
49
|
+
readonly intentKey: string;
|
|
50
|
+
readonly meta: {
|
|
51
|
+
readonly origin: IntentOrigin;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
interface Intent {
|
|
55
|
+
readonly type: string;
|
|
56
|
+
readonly intentId: string;
|
|
57
|
+
readonly input?: unknown;
|
|
58
|
+
readonly scopeProposal?: IntentScope;
|
|
59
|
+
}
|
|
60
|
+
interface ExecutionKeyContext {
|
|
61
|
+
readonly proposalId: ProposalId;
|
|
62
|
+
readonly actorId: ActorId;
|
|
63
|
+
readonly baseWorld: WorldId;
|
|
64
|
+
readonly branchId: BranchId;
|
|
65
|
+
readonly attempt: number;
|
|
66
|
+
}
|
|
67
|
+
type ExecutionKeyPolicy = (context: ExecutionKeyContext) => ExecutionKey;
|
|
68
|
+
interface Proposal {
|
|
69
|
+
readonly proposalId: ProposalId;
|
|
70
|
+
readonly baseWorld: WorldId;
|
|
71
|
+
readonly branchId: BranchId;
|
|
72
|
+
readonly actorId: ActorId;
|
|
73
|
+
readonly authorityId: AuthorityId;
|
|
74
|
+
readonly intent: Intent;
|
|
75
|
+
readonly status: ProposalStatus;
|
|
76
|
+
readonly executionKey: ExecutionKey;
|
|
77
|
+
readonly submittedAt: number;
|
|
78
|
+
readonly decidedAt?: number;
|
|
79
|
+
readonly completedAt?: number;
|
|
80
|
+
readonly decisionId?: DecisionId;
|
|
81
|
+
readonly epoch: number;
|
|
82
|
+
readonly resultWorld?: WorldId;
|
|
83
|
+
readonly supersededReason?: SupersedeReason;
|
|
84
|
+
readonly approvedScope?: unknown;
|
|
85
|
+
}
|
|
86
|
+
type FinalDecision = {
|
|
87
|
+
readonly kind: "approved";
|
|
88
|
+
} | {
|
|
89
|
+
readonly kind: "rejected";
|
|
90
|
+
readonly reason?: string;
|
|
91
|
+
};
|
|
92
|
+
interface DecisionRecord {
|
|
93
|
+
readonly decisionId: DecisionId;
|
|
94
|
+
readonly proposalId: ProposalId;
|
|
95
|
+
readonly authorityId: AuthorityId;
|
|
96
|
+
readonly decision: FinalDecision;
|
|
97
|
+
readonly decidedAt: number;
|
|
98
|
+
}
|
|
99
|
+
type AuthorityPolicy = {
|
|
100
|
+
readonly mode: "auto_approve";
|
|
101
|
+
readonly reason?: string;
|
|
102
|
+
} | {
|
|
103
|
+
readonly mode: "hitl";
|
|
104
|
+
readonly delegate: ActorRef;
|
|
105
|
+
readonly timeout?: number;
|
|
106
|
+
readonly onTimeout?: "approve" | "reject";
|
|
107
|
+
} | {
|
|
108
|
+
readonly mode: "policy_rules";
|
|
109
|
+
readonly rules: readonly PolicyRule[];
|
|
110
|
+
readonly defaultDecision: "approve" | "reject" | "escalate";
|
|
111
|
+
readonly escalateTo?: AuthorityRef;
|
|
112
|
+
} | {
|
|
113
|
+
readonly mode: "tribunal";
|
|
114
|
+
readonly members: readonly ActorRef[];
|
|
115
|
+
readonly quorum: QuorumRule;
|
|
116
|
+
readonly timeout?: number;
|
|
117
|
+
readonly onTimeout?: "approve" | "reject";
|
|
118
|
+
};
|
|
119
|
+
interface ActorAuthorityBinding {
|
|
120
|
+
readonly actorId: ActorId;
|
|
121
|
+
readonly authorityId: AuthorityId;
|
|
122
|
+
readonly policy: AuthorityPolicy;
|
|
123
|
+
}
|
|
124
|
+
type PolicyCondition = {
|
|
125
|
+
readonly kind: "intent_type";
|
|
126
|
+
readonly types: readonly string[];
|
|
127
|
+
} | {
|
|
128
|
+
readonly kind: "scope_pattern";
|
|
129
|
+
readonly pattern: string;
|
|
130
|
+
} | {
|
|
131
|
+
readonly kind: "custom";
|
|
132
|
+
readonly evaluator: string;
|
|
133
|
+
};
|
|
134
|
+
interface PolicyRule {
|
|
135
|
+
readonly condition: PolicyCondition;
|
|
136
|
+
readonly decision: "approve" | "reject" | "escalate";
|
|
137
|
+
readonly reason?: string;
|
|
138
|
+
}
|
|
139
|
+
type QuorumRule = {
|
|
140
|
+
readonly kind: "unanimous";
|
|
141
|
+
} | {
|
|
142
|
+
readonly kind: "majority";
|
|
143
|
+
} | {
|
|
144
|
+
readonly kind: "threshold";
|
|
145
|
+
readonly count: number;
|
|
146
|
+
};
|
|
147
|
+
type WaitingFor = {
|
|
148
|
+
readonly kind: "human";
|
|
149
|
+
readonly delegate: ActorRef;
|
|
150
|
+
} | {
|
|
151
|
+
readonly kind: "tribunal";
|
|
152
|
+
readonly members: readonly ActorRef[];
|
|
153
|
+
} | {
|
|
154
|
+
readonly kind: "timeout";
|
|
155
|
+
readonly until: number;
|
|
156
|
+
};
|
|
157
|
+
type AuthorityResponse = {
|
|
158
|
+
readonly kind: "approved";
|
|
159
|
+
readonly approvedScope: IntentScope | null;
|
|
160
|
+
} | {
|
|
161
|
+
readonly kind: "rejected";
|
|
162
|
+
readonly reason?: string;
|
|
163
|
+
} | {
|
|
164
|
+
readonly kind: "pending";
|
|
165
|
+
readonly waitingFor: WaitingFor;
|
|
166
|
+
};
|
|
167
|
+
interface Vote {
|
|
168
|
+
readonly voter: ActorRef;
|
|
169
|
+
readonly decision: "approve" | "reject" | "abstain";
|
|
170
|
+
readonly reasoning?: string;
|
|
171
|
+
readonly votedAt: number;
|
|
172
|
+
}
|
|
173
|
+
type GovernanceEventType = "proposal:submitted" | "proposal:evaluating" | "proposal:decided" | "proposal:superseded" | "execution:completed" | "execution:failed" | "world:created" | "world:forked";
|
|
174
|
+
interface BaseGovernanceEvent<T extends GovernanceEventType> {
|
|
175
|
+
readonly type: T;
|
|
176
|
+
readonly timestamp: number;
|
|
177
|
+
}
|
|
178
|
+
interface ErrorInfo {
|
|
179
|
+
readonly summary: string;
|
|
180
|
+
readonly currentError?: ErrorValue;
|
|
181
|
+
readonly pendingRequirements?: readonly string[];
|
|
182
|
+
}
|
|
183
|
+
interface ProposalSubmittedEvent extends BaseGovernanceEvent<"proposal:submitted"> {
|
|
184
|
+
readonly proposalId: ProposalId;
|
|
185
|
+
readonly actorId: ActorId;
|
|
186
|
+
readonly baseWorld: WorldId;
|
|
187
|
+
readonly branchId: BranchId;
|
|
188
|
+
readonly intent: {
|
|
189
|
+
readonly type: string;
|
|
190
|
+
readonly intentId: string;
|
|
191
|
+
readonly input?: unknown;
|
|
192
|
+
};
|
|
193
|
+
readonly executionKey: ExecutionKey;
|
|
194
|
+
readonly epoch: number;
|
|
195
|
+
}
|
|
196
|
+
interface ProposalEvaluatingEvent extends BaseGovernanceEvent<"proposal:evaluating"> {
|
|
197
|
+
readonly proposalId: ProposalId;
|
|
198
|
+
}
|
|
199
|
+
interface ProposalDecidedEvent extends BaseGovernanceEvent<"proposal:decided"> {
|
|
200
|
+
readonly proposalId: ProposalId;
|
|
201
|
+
readonly decisionId: DecisionId;
|
|
202
|
+
readonly decision: "approved" | "rejected";
|
|
203
|
+
readonly reason?: string;
|
|
204
|
+
}
|
|
205
|
+
interface ProposalSupersededEvent extends BaseGovernanceEvent<"proposal:superseded"> {
|
|
206
|
+
readonly proposalId: ProposalId;
|
|
207
|
+
readonly currentEpoch: number;
|
|
208
|
+
readonly proposalEpoch: number;
|
|
209
|
+
readonly reason: SupersedeReason;
|
|
210
|
+
}
|
|
211
|
+
interface ExecutionCompletedEvent extends BaseGovernanceEvent<"execution:completed"> {
|
|
212
|
+
readonly proposalId: ProposalId;
|
|
213
|
+
readonly executionKey: ExecutionKey;
|
|
214
|
+
readonly resultWorld: WorldId;
|
|
215
|
+
}
|
|
216
|
+
interface ExecutionFailedEvent extends BaseGovernanceEvent<"execution:failed"> {
|
|
217
|
+
readonly proposalId: ProposalId;
|
|
218
|
+
readonly executionKey: ExecutionKey;
|
|
219
|
+
readonly resultWorld: WorldId;
|
|
220
|
+
readonly error: ErrorInfo;
|
|
221
|
+
}
|
|
222
|
+
interface WorldCreatedEvent extends BaseGovernanceEvent<"world:created"> {
|
|
223
|
+
readonly world: World;
|
|
224
|
+
readonly from: WorldId;
|
|
225
|
+
readonly proposalId: ProposalId;
|
|
226
|
+
readonly outcome: "completed" | "failed";
|
|
227
|
+
}
|
|
228
|
+
interface WorldForkedEvent extends BaseGovernanceEvent<"world:forked"> {
|
|
229
|
+
readonly branchId: BranchId;
|
|
230
|
+
readonly forkPoint: WorldId;
|
|
231
|
+
}
|
|
232
|
+
type GovernanceEvent = ProposalSubmittedEvent | ProposalEvaluatingEvent | ProposalDecidedEvent | ProposalSupersededEvent | ExecutionCompletedEvent | ExecutionFailedEvent | WorldCreatedEvent | WorldForkedEvent;
|
|
233
|
+
interface GovernanceEventSink {
|
|
234
|
+
emit(event: GovernanceEvent): void;
|
|
235
|
+
}
|
|
236
|
+
interface GovernanceEventDispatcher {
|
|
237
|
+
emitSealCompleted(governanceCommit: PreparedGovernanceCommit, lineageCommit: PreparedLineageCommit): void;
|
|
238
|
+
}
|
|
239
|
+
interface PreparedGovernanceCommit {
|
|
240
|
+
readonly proposal: Proposal;
|
|
241
|
+
readonly decisionRecord: DecisionRecord;
|
|
242
|
+
}
|
|
243
|
+
interface GovernanceStore {
|
|
244
|
+
putProposal(proposal: Proposal): Promise<void>;
|
|
245
|
+
getProposal(proposalId: ProposalId): Promise<Proposal | null>;
|
|
246
|
+
getProposalsByBranch(branchId: BranchId): Promise<readonly Proposal[]>;
|
|
247
|
+
getExecutionStageProposal(branchId: BranchId): Promise<Proposal | null>;
|
|
248
|
+
putDecisionRecord(record: DecisionRecord): Promise<void>;
|
|
249
|
+
getDecisionRecord(decisionId: DecisionId): Promise<DecisionRecord | null>;
|
|
250
|
+
putActorBinding(binding: ActorAuthorityBinding): Promise<void>;
|
|
251
|
+
getActorBinding(actorId: ActorId): Promise<ActorAuthorityBinding | null>;
|
|
252
|
+
getActorBindings(): Promise<readonly ActorAuthorityBinding[]>;
|
|
253
|
+
}
|
|
254
|
+
interface CreateProposalInput {
|
|
255
|
+
readonly proposalId?: ProposalId;
|
|
256
|
+
readonly baseWorld: WorldId;
|
|
257
|
+
readonly branchId: BranchId;
|
|
258
|
+
readonly actorId: ActorId;
|
|
259
|
+
readonly authorityId: AuthorityId;
|
|
260
|
+
readonly intent: Intent;
|
|
261
|
+
readonly executionKey: ExecutionKey;
|
|
262
|
+
readonly submittedAt: number;
|
|
263
|
+
readonly epoch: number;
|
|
264
|
+
}
|
|
265
|
+
interface PrepareAuthorityResultOptions {
|
|
266
|
+
readonly currentEpoch?: number;
|
|
267
|
+
readonly currentBranchHead?: WorldId;
|
|
268
|
+
readonly decisionId?: DecisionId;
|
|
269
|
+
readonly decidedAt: number;
|
|
270
|
+
}
|
|
271
|
+
interface PreparedAuthorityResult {
|
|
272
|
+
readonly proposal: Proposal;
|
|
273
|
+
readonly decisionRecord?: DecisionRecord;
|
|
274
|
+
readonly discarded: boolean;
|
|
275
|
+
}
|
|
276
|
+
interface GovernanceService {
|
|
277
|
+
createProposal(input: CreateProposalInput): Proposal;
|
|
278
|
+
prepareAuthorityResult(proposal: Proposal, response: Extract<AuthorityResponse, {
|
|
279
|
+
kind: "approved" | "rejected";
|
|
280
|
+
}>, options: PrepareAuthorityResultOptions): Promise<PreparedAuthorityResult>;
|
|
281
|
+
prepareSupersede(proposal: Proposal, reason: SupersedeReason): Proposal;
|
|
282
|
+
invalidateStaleIngress(branchId: BranchId, currentEpoch?: number): Promise<readonly Proposal[]>;
|
|
283
|
+
shouldDiscardAuthorityResult(proposal: Proposal, currentEpoch: number): boolean;
|
|
284
|
+
deriveOutcome(terminalSnapshot: Snapshot): "completed" | "failed";
|
|
285
|
+
finalize(executingProposal: Proposal, lineageCommit: PreparedLineageCommit, completedAt: number): Promise<PreparedGovernanceCommit>;
|
|
286
|
+
createProposalSubmittedEvent(proposal: Proposal, timestamp?: number): ProposalSubmittedEvent;
|
|
287
|
+
createProposalEvaluatingEvent(proposal: Proposal, timestamp?: number): ProposalEvaluatingEvent;
|
|
288
|
+
createProposalDecidedEvent(proposal: Proposal, decisionRecord: DecisionRecord, timestamp?: number): ProposalDecidedEvent;
|
|
289
|
+
createProposalSupersededEvent(proposal: Proposal, currentEpoch: number, timestamp?: number): ProposalSupersededEvent;
|
|
290
|
+
createExecutionCompletedEvent(proposal: Proposal, timestamp?: number): ExecutionCompletedEvent;
|
|
291
|
+
createExecutionFailedEvent(proposal: Proposal, error: ErrorInfo, timestamp?: number): ExecutionFailedEvent;
|
|
292
|
+
createWorldCreatedEvent(world: World, proposalId: ProposalId, from: WorldId, outcome: "completed" | "failed", timestamp?: number): WorldCreatedEvent;
|
|
293
|
+
createWorldForkedEvent(branchId: BranchId, forkPoint: WorldId, timestamp?: number): WorldForkedEvent;
|
|
294
|
+
}
|
|
295
|
+
declare function createProposalId(value?: string): ProposalId;
|
|
296
|
+
declare function createDecisionId(value?: string): DecisionId;
|
|
297
|
+
declare function createExecutionKey(proposalId: ProposalId, attempt?: number): ExecutionKey;
|
|
298
|
+
declare const defaultExecutionKeyPolicy: ExecutionKeyPolicy;
|
|
299
|
+
declare function createNoopGovernanceEventSink(): GovernanceEventSink;
|
|
300
|
+
declare function toHostIntent(intent: Intent | IntentInstance): Intent$1;
|
|
301
|
+
|
|
302
|
+
interface CreateIntentInstanceOptions {
|
|
303
|
+
readonly body: IntentBody;
|
|
304
|
+
readonly schemaHash: string;
|
|
305
|
+
readonly projectionId: string;
|
|
306
|
+
readonly source: SourceRef;
|
|
307
|
+
readonly actor: ActorRef;
|
|
308
|
+
readonly note?: string;
|
|
309
|
+
readonly intentId?: string;
|
|
310
|
+
}
|
|
311
|
+
declare function computeIntentKey(schemaHash: string, body: IntentBody): Promise<string>;
|
|
312
|
+
declare function createIntentInstance(options: CreateIntentInstanceOptions): Promise<IntentInstance>;
|
|
313
|
+
declare function createIntentInstanceSync(body: IntentBody, intentId: string, intentKey: string, origin: IntentOrigin): IntentInstance;
|
|
314
|
+
|
|
315
|
+
declare const INGRESS_STATUSES: readonly ["submitted", "evaluating"];
|
|
316
|
+
declare const EXECUTION_STAGE_STATUSES: readonly ["approved", "executing"];
|
|
317
|
+
declare const TERMINAL_STATUSES: readonly ["rejected", "completed", "failed", "superseded"];
|
|
318
|
+
declare const DECISION_TRANSITION_TARGETS: readonly ["approved", "rejected"];
|
|
319
|
+
declare function isIngressStatus(status: ProposalStatus): boolean;
|
|
320
|
+
declare function isExecutionStageStatus(status: ProposalStatus): boolean;
|
|
321
|
+
declare function isTerminalStatus(status: ProposalStatus): boolean;
|
|
322
|
+
declare function isValidTransition(from: ProposalStatus, to: ProposalStatus): boolean;
|
|
323
|
+
declare function getValidTransitions(status: ProposalStatus): ProposalStatus[];
|
|
324
|
+
declare function transitionCreatesDecisionRecord(from: ProposalStatus, to: ProposalStatus): boolean;
|
|
325
|
+
|
|
326
|
+
type InMemoryGovernanceStoreState = {
|
|
327
|
+
proposals: Map<ProposalId, Proposal>;
|
|
328
|
+
decisions: Map<DecisionId, DecisionRecord>;
|
|
329
|
+
actorBindings: Map<ActorId, ActorAuthorityBinding>;
|
|
330
|
+
};
|
|
331
|
+
declare class InMemoryGovernanceStore implements GovernanceStore {
|
|
332
|
+
private readonly proposals;
|
|
333
|
+
private readonly decisions;
|
|
334
|
+
private readonly actorBindings;
|
|
335
|
+
putProposal(proposal: Proposal): Promise<void>;
|
|
336
|
+
getProposal(proposalId: ProposalId): Promise<Proposal | null>;
|
|
337
|
+
getProposalsByBranch(branchId: BranchId): Promise<readonly Proposal[]>;
|
|
338
|
+
getExecutionStageProposal(branchId: BranchId): Promise<Proposal | null>;
|
|
339
|
+
putDecisionRecord(record: DecisionRecord): Promise<void>;
|
|
340
|
+
getDecisionRecord(decisionId: DecisionId): Promise<DecisionRecord | null>;
|
|
341
|
+
putActorBinding(binding: ActorAuthorityBinding): Promise<void>;
|
|
342
|
+
getActorBinding(actorId: ActorId): Promise<ActorAuthorityBinding | null>;
|
|
343
|
+
getActorBindings(): Promise<readonly ActorAuthorityBinding[]>;
|
|
344
|
+
snapshotState(): InMemoryGovernanceStoreState;
|
|
345
|
+
restoreState(state: InMemoryGovernanceStoreState): void;
|
|
346
|
+
}
|
|
347
|
+
declare function createInMemoryGovernanceStore(): InMemoryGovernanceStore;
|
|
348
|
+
|
|
349
|
+
interface GovernanceServiceOptions {
|
|
350
|
+
readonly lineageService?: Pick<LineageService, "getBranch">;
|
|
351
|
+
}
|
|
352
|
+
declare class DefaultGovernanceService implements GovernanceService {
|
|
353
|
+
private readonly store;
|
|
354
|
+
private readonly options;
|
|
355
|
+
constructor(store: GovernanceStore, options?: GovernanceServiceOptions);
|
|
356
|
+
createProposal(input: CreateProposalInput): Proposal;
|
|
357
|
+
prepareAuthorityResult(proposal: Proposal, response: Extract<AuthorityResponse, {
|
|
358
|
+
kind: "approved" | "rejected";
|
|
359
|
+
}>, options: PrepareAuthorityResultOptions): Promise<PreparedAuthorityResult>;
|
|
360
|
+
prepareSupersede(proposal: Proposal, reason: SupersedeReason): Proposal;
|
|
361
|
+
invalidateStaleIngress(branchId: string, currentEpoch?: number): Promise<readonly Proposal[]>;
|
|
362
|
+
shouldDiscardAuthorityResult(proposal: Proposal, currentEpoch: number): boolean;
|
|
363
|
+
deriveOutcome(terminalSnapshot: Snapshot): "completed" | "failed";
|
|
364
|
+
finalize(executingProposal: Proposal, lineageCommit: PreparedLineageCommit, completedAt: number): Promise<PreparedGovernanceCommit>;
|
|
365
|
+
createProposalSubmittedEvent(proposal: Proposal, timestamp?: number): ProposalSubmittedEvent;
|
|
366
|
+
createProposalEvaluatingEvent(proposal: Proposal, timestamp?: number): ProposalEvaluatingEvent;
|
|
367
|
+
createProposalDecidedEvent(proposal: Proposal, decisionRecord: DecisionRecord, timestamp?: number): ProposalDecidedEvent;
|
|
368
|
+
createProposalSupersededEvent(proposal: Proposal, currentEpoch: number, timestamp?: number): ProposalSupersededEvent;
|
|
369
|
+
createExecutionCompletedEvent(proposal: Proposal, timestamp?: number): ExecutionCompletedEvent;
|
|
370
|
+
createExecutionFailedEvent(proposal: Proposal, error: ErrorInfo, timestamp?: number): ExecutionFailedEvent;
|
|
371
|
+
createWorldCreatedEvent(world: World, proposalId: ProposalId, from: WorldId, outcome: "completed" | "failed", timestamp?: number): WorldCreatedEvent;
|
|
372
|
+
createWorldForkedEvent(branchId: BranchId, forkPoint: WorldId, timestamp?: number): WorldForkedEvent;
|
|
373
|
+
private resolveBranchInfo;
|
|
374
|
+
private assertBranchGateAvailable;
|
|
375
|
+
private transitionProposal;
|
|
376
|
+
}
|
|
377
|
+
declare function createGovernanceService(store: GovernanceStore, options?: GovernanceServiceOptions): DefaultGovernanceService;
|
|
378
|
+
|
|
379
|
+
interface CreateGovernanceEventDispatcherOptions {
|
|
380
|
+
readonly service: Pick<GovernanceService, "createExecutionCompletedEvent" | "createExecutionFailedEvent" | "createWorldCreatedEvent" | "createWorldForkedEvent">;
|
|
381
|
+
readonly sink?: GovernanceEventSink;
|
|
382
|
+
readonly now?: () => number;
|
|
383
|
+
}
|
|
384
|
+
declare function createGovernanceEventDispatcher(options: CreateGovernanceEventDispatcherOptions): GovernanceEventDispatcher;
|
|
385
|
+
|
|
386
|
+
interface AuthorityHandler {
|
|
387
|
+
evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
|
|
388
|
+
}
|
|
389
|
+
interface HITLDecisionCallback {
|
|
390
|
+
(proposalId: string, decision: "approved" | "rejected", reasoning?: string): void;
|
|
391
|
+
}
|
|
392
|
+
interface HITLPendingState {
|
|
393
|
+
proposalId: string;
|
|
394
|
+
proposal?: Proposal;
|
|
395
|
+
resolve: (response: AuthorityResponse) => void;
|
|
396
|
+
reject: (error: Error) => void;
|
|
397
|
+
timeoutId?: ReturnType<typeof setTimeout>;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
declare class AutoApproveHandler implements AuthorityHandler {
|
|
401
|
+
evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
|
|
402
|
+
}
|
|
403
|
+
declare function createAutoApproveHandler(): AutoApproveHandler;
|
|
404
|
+
|
|
405
|
+
type CustomConditionEvaluator = (proposal: Proposal, binding: ActorAuthorityBinding) => boolean;
|
|
406
|
+
declare class PolicyRulesHandler implements AuthorityHandler {
|
|
407
|
+
private readonly customEvaluators;
|
|
408
|
+
registerCustomEvaluator(name: string, evaluator: CustomConditionEvaluator): void;
|
|
409
|
+
evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
|
|
410
|
+
private evaluateCondition;
|
|
411
|
+
private matchPattern;
|
|
412
|
+
private applyDecision;
|
|
413
|
+
}
|
|
414
|
+
declare function createPolicyRulesHandler(): PolicyRulesHandler;
|
|
415
|
+
|
|
416
|
+
type HITLNotificationCallback = (proposalId: string, proposal: Proposal, binding: ActorAuthorityBinding) => void;
|
|
417
|
+
declare class HITLHandler implements AuthorityHandler {
|
|
418
|
+
private readonly pendingDecisions;
|
|
419
|
+
private readonly notificationCallbacks;
|
|
420
|
+
onPendingDecision(callback: HITLNotificationCallback): () => void;
|
|
421
|
+
evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
|
|
422
|
+
submitDecision(proposalId: string, decision: "approved" | "rejected", reasoning?: string, approvedScope?: IntentScope | null): void;
|
|
423
|
+
isPending(proposalId: string): boolean;
|
|
424
|
+
getPendingIds(): string[];
|
|
425
|
+
clearAllPending(): void;
|
|
426
|
+
}
|
|
427
|
+
declare function createHITLHandler(): HITLHandler;
|
|
428
|
+
|
|
429
|
+
type TribunalNotificationCallback = (proposalId: string, proposal: Proposal, members: readonly ActorRef[]) => void;
|
|
430
|
+
declare class TribunalHandler implements AuthorityHandler {
|
|
431
|
+
private readonly pendingTribunals;
|
|
432
|
+
private notificationCallback?;
|
|
433
|
+
onPendingTribunal(callback: TribunalNotificationCallback): void;
|
|
434
|
+
evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
|
|
435
|
+
submitVote(proposalId: string, voter: ActorRef, decision: "approve" | "reject" | "abstain", reasoning?: string): void;
|
|
436
|
+
isPending(proposalId: string): boolean;
|
|
437
|
+
getVotes(proposalId: string): Vote[];
|
|
438
|
+
getPendingIds(): string[];
|
|
439
|
+
clearAllPending(): void;
|
|
440
|
+
private checkQuorum;
|
|
441
|
+
}
|
|
442
|
+
declare function createTribunalHandler(): TribunalHandler;
|
|
443
|
+
|
|
444
|
+
declare class AuthorityEvaluator {
|
|
445
|
+
private readonly handlers;
|
|
446
|
+
private readonly autoHandler;
|
|
447
|
+
private readonly policyHandler;
|
|
448
|
+
private readonly hitlHandler;
|
|
449
|
+
private readonly tribunalHandler;
|
|
450
|
+
constructor();
|
|
451
|
+
evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
|
|
452
|
+
registerHandler(policyMode: string, handler: AuthorityHandler): void;
|
|
453
|
+
getAutoHandler(): AutoApproveHandler;
|
|
454
|
+
getPolicyHandler(): PolicyRulesHandler;
|
|
455
|
+
getHITLHandler(): HITLHandler;
|
|
456
|
+
getTribunalHandler(): TribunalHandler;
|
|
457
|
+
getAuthorityKind(policyMode: string): AuthorityKind | null;
|
|
458
|
+
submitHITLDecision(proposalId: string, decision: "approved" | "rejected", reasoning?: string, approvedScope?: IntentScope | null): void;
|
|
459
|
+
submitTribunalVote(proposalId: string, voter: {
|
|
460
|
+
actorId: string;
|
|
461
|
+
kind: "human" | "agent" | "system";
|
|
462
|
+
name?: string;
|
|
463
|
+
}, decision: "approve" | "reject" | "abstain", reasoning?: string): void;
|
|
464
|
+
hasPendingHITL(): boolean;
|
|
465
|
+
hasPendingTribunal(): boolean;
|
|
466
|
+
getPendingHITLIds(): string[];
|
|
467
|
+
getPendingTribunalIds(): string[];
|
|
468
|
+
clearAllPending(): void;
|
|
469
|
+
}
|
|
470
|
+
declare function createAuthorityEvaluator(): AuthorityEvaluator;
|
|
471
|
+
|
|
472
|
+
export { type ActorAuthorityBinding, type ActorId, type ActorKind, type ActorRef, AuthorityEvaluator, type AuthorityHandler, type AuthorityId, type AuthorityKind, type AuthorityPolicy, type AuthorityRef, type AuthorityResponse, AutoApproveHandler, type BaseGovernanceEvent, type CreateGovernanceEventDispatcherOptions, type CreateIntentInstanceOptions, type CreateProposalInput, type CustomConditionEvaluator, DECISION_TRANSITION_TARGETS, type DecisionId, type DecisionRecord, DefaultGovernanceService, EXECUTION_STAGE_STATUSES, type ErrorInfo, type ExecutionCompletedEvent, type ExecutionFailedEvent, type ExecutionKey, type ExecutionKeyContext, type ExecutionKeyPolicy, type FinalDecision, type GovernanceEvent, type GovernanceEventDispatcher, type GovernanceEventSink, type GovernanceEventType, type GovernanceService, type GovernanceStore, type HITLDecisionCallback, HITLHandler, type HITLNotificationCallback, type HITLPendingState, INGRESS_STATUSES, InMemoryGovernanceStore, type Intent, type IntentBody, type IntentInstance, type IntentOrigin, type IntentScope, type PolicyCondition, type PolicyRule, PolicyRulesHandler, type PrepareAuthorityResultOptions, type PreparedAuthorityResult, type PreparedGovernanceCommit, type Proposal, type ProposalDecidedEvent, type ProposalEvaluatingEvent, type ProposalId, type ProposalStatus, type ProposalSubmittedEvent, type ProposalSupersededEvent, type QuorumRule, type SourceKind, type SourceRef, type SupersedeReason, TERMINAL_STATUSES, TribunalHandler, type TribunalNotificationCallback, type Vote, type WaitingFor, type WorldCreatedEvent, type WorldForkedEvent, computeIntentKey, createAuthorityEvaluator, createAutoApproveHandler, createDecisionId, createExecutionKey, createGovernanceEventDispatcher, createGovernanceService, createHITLHandler, createInMemoryGovernanceStore, createIntentInstance, createIntentInstanceSync, createNoopGovernanceEventSink, createPolicyRulesHandler, createProposalId, createTribunalHandler, defaultExecutionKeyPolicy, getValidTransitions, isExecutionStageStatus, isIngressStatus, isTerminalStatus, isValidTransition, toHostIntent, transitionCreatesDecisionRecord };
|