@manifesto-ai/governance 0.1.1 → 3.1.1

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/README.md CHANGED
@@ -1,52 +1,73 @@
1
1
  # @manifesto-ai/governance
2
2
 
3
- > Split-native governance protocol for legitimacy, authority, and proposal lifecycle.
3
+ > Decorator runtime for legitimacy, approval, and governed execution.
4
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.
5
+ `@manifesto-ai/governance` is the package that turns a composable manifesto into a governed world. Its canonical public entry is `withGovernance(manifesto, config)`.
6
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.
7
+ > **Current Contract Note:** The truthful current package contract is [docs/governance-SPEC-v3.0.0-draft.md](docs/governance-SPEC-v3.0.0-draft.md). The v2.0.0 governance spec remains as the historical service-first baseline.
8
8
 
9
- ## What This Package Owns
9
+ ## Canonical Runtime Path
10
+
11
+ ```ts
12
+ import { createManifesto } from "@manifesto-ai/sdk";
13
+ import { createInMemoryLineageStore, withLineage } from "@manifesto-ai/lineage";
14
+ import { withGovernance } from "@manifesto-ai/governance";
15
+
16
+ const governed = withGovernance(
17
+ withLineage(createManifesto<CounterDomain>(schema, effects), {
18
+ store: createInMemoryLineageStore(),
19
+ }),
20
+ {
21
+ bindings,
22
+ execution: {
23
+ projectionId: "counter",
24
+ deriveActor(intent) {
25
+ return { actorId: "agent:demo", kind: "agent" };
26
+ },
27
+ deriveSource(intent) {
28
+ return { kind: "agent", eventId: intent.intentId };
29
+ },
30
+ },
31
+ },
32
+ ).activate();
10
33
 
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 });
34
+ const proposal = await governed.proposeAsync(
35
+ governed.createIntent(governed.MEL.actions.increment),
36
+ );
44
37
  ```
45
38
 
39
+ ## What This Package Owns
40
+
41
+ - `withGovernance()` and the activated `GovernanceInstance`
42
+ - proposal lifecycle and authority evaluation
43
+ - pending human/tribunal resolution through `approve()` / `reject()`
44
+ - governance decision records and post-commit governance events
45
+ - low-level governance stores, services, authority handlers, and intent-instance helpers
46
+
47
+ ## What Changes After Governance Activation
48
+
49
+ - direct `dispatchAsync` and `commitAsync` no longer exist
50
+ - the canonical state-change path becomes `proposeAsync() -> approve()/reject()`
51
+ - lineage must be composed before governance activation
52
+ - visible snapshots publish only after approved execution seals successfully
53
+
54
+ ## Low-Level Surface Still Available
55
+
56
+ The service-first exports remain public for lower-level tooling and protocol tests:
57
+
58
+ - `createGovernanceService()`
59
+ - `createGovernanceEventDispatcher()`
60
+ - `createInMemoryGovernanceStore()`
61
+ - `createAuthorityEvaluator()`
62
+ - authority handlers and lifecycle types
63
+
64
+ Those are no longer the canonical application entry story.
65
+
46
66
  ## Docs
47
67
 
48
68
  - [Docs Landing](docs/README.md)
49
69
  - [Governance Guide](docs/GUIDE.md)
50
- - [Governance Specification](docs/governance-SPEC-2.0.0v.md)
70
+ - [Governance Specification](docs/governance-SPEC-v3.0.0-draft.md)
71
+ - [Historical v2 Baseline](docs/governance-SPEC-2.0.0v.md)
51
72
  - [Historical v1 Baseline](docs/governance-SPEC-1.0.0v.md)
52
73
  - [VERSION-INDEX](docs/VERSION-INDEX.md)
@@ -0,0 +1,6 @@
1
+ import type { ActorAuthorityBinding, AuthorityResponse, Proposal } from "../types.js";
2
+ import type { AuthorityHandler } from "./types.js";
3
+ export declare class AutoApproveHandler implements AuthorityHandler {
4
+ evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
5
+ }
6
+ export declare function createAutoApproveHandler(): AutoApproveHandler;
@@ -0,0 +1,33 @@
1
+ import type { ActorAuthorityBinding, AuthorityKind, AuthorityResponse, IntentScope, Proposal } from "../types.js";
2
+ import type { AuthorityHandler } from "./types.js";
3
+ import { AutoApproveHandler } from "./auto.js";
4
+ import { HITLHandler } from "./hitl.js";
5
+ import { PolicyRulesHandler } from "./policy.js";
6
+ import { TribunalHandler } from "./tribunal.js";
7
+ export declare class AuthorityEvaluator {
8
+ private readonly handlers;
9
+ private readonly autoHandler;
10
+ private readonly policyHandler;
11
+ private readonly hitlHandler;
12
+ private readonly tribunalHandler;
13
+ constructor();
14
+ evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
15
+ registerHandler(policyMode: string, handler: AuthorityHandler): void;
16
+ getAutoHandler(): AutoApproveHandler;
17
+ getPolicyHandler(): PolicyRulesHandler;
18
+ getHITLHandler(): HITLHandler;
19
+ getTribunalHandler(): TribunalHandler;
20
+ getAuthorityKind(policyMode: string): AuthorityKind | null;
21
+ submitHITLDecision(proposalId: string, decision: "approved" | "rejected", reasoning?: string, approvedScope?: IntentScope | null): void;
22
+ submitTribunalVote(proposalId: string, voter: {
23
+ actorId: string;
24
+ kind: "human" | "agent" | "system";
25
+ name?: string;
26
+ }, decision: "approve" | "reject" | "abstain", reasoning?: string): void;
27
+ hasPendingHITL(): boolean;
28
+ hasPendingTribunal(): boolean;
29
+ getPendingHITLIds(): string[];
30
+ getPendingTribunalIds(): string[];
31
+ clearAllPending(): void;
32
+ }
33
+ export declare function createAuthorityEvaluator(): AuthorityEvaluator;
@@ -0,0 +1,14 @@
1
+ import type { ActorAuthorityBinding, AuthorityResponse, IntentScope, Proposal } from "../types.js";
2
+ import type { AuthorityHandler } from "./types.js";
3
+ export type HITLNotificationCallback = (proposalId: string, proposal: Proposal, binding: ActorAuthorityBinding) => void;
4
+ export declare class HITLHandler implements AuthorityHandler {
5
+ private readonly pendingDecisions;
6
+ private readonly notificationCallbacks;
7
+ onPendingDecision(callback: HITLNotificationCallback): () => void;
8
+ evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
9
+ submitDecision(proposalId: string, decision: "approved" | "rejected", reasoning?: string, approvedScope?: IntentScope | null): void;
10
+ isPending(proposalId: string): boolean;
11
+ getPendingIds(): string[];
12
+ clearAllPending(): void;
13
+ }
14
+ export declare function createHITLHandler(): HITLHandler;
@@ -0,0 +1,12 @@
1
+ import type { ActorAuthorityBinding, AuthorityResponse, Proposal } from "../types.js";
2
+ import type { AuthorityHandler } from "./types.js";
3
+ export type CustomConditionEvaluator = (proposal: Proposal, binding: ActorAuthorityBinding) => boolean;
4
+ export declare class PolicyRulesHandler implements AuthorityHandler {
5
+ private readonly customEvaluators;
6
+ registerCustomEvaluator(name: string, evaluator: CustomConditionEvaluator): void;
7
+ evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
8
+ private evaluateCondition;
9
+ private matchPattern;
10
+ private applyDecision;
11
+ }
12
+ export declare function createPolicyRulesHandler(): PolicyRulesHandler;
@@ -0,0 +1,16 @@
1
+ import type { ActorAuthorityBinding, ActorRef, AuthorityResponse, Proposal, Vote } from "../types.js";
2
+ import type { AuthorityHandler } from "./types.js";
3
+ export type TribunalNotificationCallback = (proposalId: string, proposal: Proposal, members: readonly ActorRef[]) => void;
4
+ export declare class TribunalHandler implements AuthorityHandler {
5
+ private readonly pendingTribunals;
6
+ private notificationCallback?;
7
+ onPendingTribunal(callback: TribunalNotificationCallback): void;
8
+ evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
9
+ submitVote(proposalId: string, voter: ActorRef, decision: "approve" | "reject" | "abstain", reasoning?: string): void;
10
+ isPending(proposalId: string): boolean;
11
+ getVotes(proposalId: string): Vote[];
12
+ getPendingIds(): string[];
13
+ clearAllPending(): void;
14
+ private checkQuorum;
15
+ }
16
+ export declare function createTribunalHandler(): TribunalHandler;
@@ -0,0 +1,14 @@
1
+ import type { ActorAuthorityBinding, AuthorityResponse, Proposal } from "../types.js";
2
+ export interface AuthorityHandler {
3
+ evaluate(proposal: Proposal, binding: ActorAuthorityBinding): Promise<AuthorityResponse>;
4
+ }
5
+ export interface HITLDecisionCallback {
6
+ (proposalId: string, decision: "approved" | "rejected", reasoning?: string): void;
7
+ }
8
+ export interface HITLPendingState {
9
+ proposalId: string;
10
+ proposal?: Proposal;
11
+ resolve: (response: AuthorityResponse) => void;
12
+ reject: (error: Error) => void;
13
+ timeoutId?: ReturnType<typeof setTimeout>;
14
+ }
@@ -0,0 +1,7 @@
1
+ import { type GovernanceEventDispatcher, type GovernanceEventSink, type GovernanceService } from "./types.js";
2
+ export interface CreateGovernanceEventDispatcherOptions {
3
+ readonly service: Pick<GovernanceService, "createExecutionCompletedEvent" | "createExecutionFailedEvent" | "createWorldCreatedEvent" | "createWorldForkedEvent">;
4
+ readonly sink?: GovernanceEventSink;
5
+ readonly now?: () => number;
6
+ }
7
+ export declare function createGovernanceEventDispatcher(options: CreateGovernanceEventDispatcherOptions): GovernanceEventDispatcher;