@manifesto-ai/sdk 3.18.1 → 5.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.
Files changed (40) hide show
  1. package/README.md +30 -14
  2. package/dist/chunk-DPFMD6LR.js +1 -0
  3. package/dist/chunk-OW22XF26.js +1 -0
  4. package/dist/chunk-TG2UPPZN.js +1 -0
  5. package/dist/compat/internal.d.ts +5 -84
  6. package/dist/effects.d.ts +2 -2
  7. package/dist/effects.js +1 -1
  8. package/dist/errors.d.ts +4 -0
  9. package/dist/extensions-types.d.ts +7 -5
  10. package/dist/extensions.js +1 -1
  11. package/dist/index.d.ts +13 -2
  12. package/dist/index.js +6 -6
  13. package/dist/manifest/compile-schema.d.ts +3 -1
  14. package/dist/manifest/create-manifesto.d.ts +2 -2
  15. package/dist/manifest/resolve-schema.d.ts +2 -2
  16. package/dist/manifest/shared.d.ts +3 -1
  17. package/dist/manifest.d.ts +1 -1
  18. package/dist/projection/snapshot-projection.d.ts +11 -13
  19. package/dist/provider.d.ts +12 -1
  20. package/dist/provider.js +1 -1
  21. package/dist/runtime/action-payload.d.ts +9 -0
  22. package/dist/runtime/admission-failure.d.ts +16 -0
  23. package/dist/runtime/admission.d.ts +6 -5
  24. package/dist/runtime/base-dispatch.d.ts +12 -10
  25. package/dist/runtime/base-runtime.d.ts +9 -2
  26. package/dist/runtime/context.d.ts +4 -0
  27. package/dist/runtime/facets.d.ts +13 -10
  28. package/dist/runtime/kernel-contract.d.ts +111 -0
  29. package/dist/runtime/kernel.d.ts +1 -1
  30. package/dist/runtime/publication.d.ts +3 -4
  31. package/dist/runtime/reports.d.ts +3 -3
  32. package/dist/runtime/simulation.d.ts +1 -1
  33. package/dist/runtime/state-store.d.ts +1 -1
  34. package/dist/types.d.ts +425 -45
  35. package/package.json +8 -8
  36. package/dist/chunk-BDIXNUQ3.js +0 -1
  37. package/dist/chunk-BSGOCNTO.js +0 -1
  38. package/dist/chunk-JM42OG2H.js +0 -1
  39. package/dist/manifest/system-get.d.ts +0 -4
  40. package/dist/runtime/events.d.ts +0 -7
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { ComputeStatus, DomainSchema, ExprNode, Intent, Patch, Requirement, TraceGraph } from "@manifesto-ai/core";
1
+ import type { ComputeStatus, DomainSchema, ErrorValue, ExprNode, Intent, JsonValue, Patch, Requirement, TraceGraph } from "@manifesto-ai/core";
2
+ export type { JsonValue } from "@manifesto-ai/core";
2
3
  import type { SchemaGraph as CompilerSchemaGraph, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind } from "@manifesto-ai/compiler";
3
- import type { CanonicalPlatformNamespaces, CanonicalSnapshot, Snapshot } from "./projection/snapshot-projection.js";
4
+ import type { CanonicalNamespaces, CanonicalSnapshot, Snapshot } from "./projection/snapshot-projection.js";
4
5
  type ActionFn = {
5
6
  bivarianceHack(...args: unknown[]): unknown;
6
7
  }["bivarianceHack"];
@@ -8,6 +9,7 @@ export type ManifestoDomainShape = {
8
9
  readonly actions: Record<string, ActionFn>;
9
10
  readonly state: Record<string, unknown>;
10
11
  readonly computed: Record<string, unknown>;
12
+ readonly context?: ExternalContext;
11
13
  };
12
14
  export type BaseLaws = {
13
15
  readonly __baseLaws: true;
@@ -44,7 +46,7 @@ export type ComputedRef<TValue> = {
44
46
  readonly name: string;
45
47
  readonly _type?: TValue;
46
48
  };
47
- export type TypedMEL<T extends ManifestoDomainShape> = {
49
+ export type TypedDomainRefs<T extends ManifestoDomainShape> = {
48
50
  readonly actions: {
49
51
  readonly [K in keyof T["actions"]]: TypedActionRef<T, K>;
50
52
  };
@@ -55,11 +57,299 @@ export type TypedMEL<T extends ManifestoDomainShape> = {
55
57
  readonly [K in keyof T["computed"]]: ComputedRef<T["computed"][K]>;
56
58
  };
57
59
  };
60
+ /**
61
+ * @deprecated Use TypedDomainRefs. This compatibility alias is retained for
62
+ * older helper/provider code that still names the typed ref surface "MEL".
63
+ */
64
+ export type TypedMEL<T extends ManifestoDomainShape> = TypedDomainRefs<T>;
58
65
  export type ActionArgs<T extends ManifestoDomainShape, K extends keyof T["actions"]> = T["actions"][K] extends (...args: infer P) => unknown ? P : never;
66
+ export type RuntimeMode = "base" | "lineage" | "governance";
67
+ export type ActionName<T extends ManifestoDomainShape> = keyof T["actions"] & string;
68
+ type ActionInputFromArgs<TArgs extends readonly unknown[]> = TArgs extends readonly [] ? undefined : 2 extends TArgs["length"] ? Readonly<TArgs> : TArgs extends readonly [unknown, unknown, ...unknown[]] ? Readonly<TArgs> : TArgs[0];
69
+ export type ActionInput<T extends ManifestoDomainShape, K extends ActionName<T>> = ActionInputFromArgs<ActionArgs<T, K>>;
70
+ export type ProjectedSnapshot<T extends ManifestoDomainShape> = Snapshot<T["state"], T["computed"]>;
71
+ export type ExternalContext = Readonly<Record<string, JsonValue>>;
72
+ export type DomainExternalContext<T extends ManifestoDomainShape> = T extends {
73
+ readonly context: infer TContext extends ExternalContext;
74
+ } ? Readonly<TContext> : ExternalContext;
75
+ export type ContextUpdater<TContext extends ExternalContext = ExternalContext> = (current: Readonly<TContext>) => TContext;
76
+ export type PreviewDiagnosticsMode = "none" | "summary" | "trace";
77
+ export type SubmitReportMode = "none" | "summary" | "full";
78
+ export type ExecutionView<TContext extends ExternalContext = ExternalContext> = {
79
+ readonly context?: TContext;
80
+ readonly diagnostics?: PreviewDiagnosticsMode;
81
+ readonly report?: SubmitReportMode;
82
+ };
83
+ export type ActionAnnotation = Readonly<Record<string, unknown>>;
84
+ export type CreateManifestoOptions<TContext extends ExternalContext = ExternalContext> = {
85
+ readonly annotations?: Readonly<Record<string, ActionAnnotation>>;
86
+ readonly context?: TContext;
87
+ };
88
+ export type ActionParameterInfo = {
89
+ readonly name: string;
90
+ readonly required: boolean;
91
+ readonly type?: string;
92
+ readonly description?: string;
93
+ };
94
+ export type ActionInfo<Name extends string = string> = {
95
+ readonly name: Name;
96
+ readonly title?: string;
97
+ readonly description?: string;
98
+ readonly parameters: readonly ActionParameterInfo[];
99
+ readonly annotations?: ActionAnnotation;
100
+ };
101
+ /**
102
+ * Coarse admission-stage blocker riding on {@link AdmissionFailure}.
103
+ *
104
+ * Admission stays cheap: a Blocker says THAT a candidate is blocked and at
105
+ * which layer. To learn WHY in domain terms (the MEL expressions involved),
106
+ * re-query the explanation seam — that richer stage uses
107
+ * {@link ExplanationBlocker} (`DispatchBlocker`) on `IntentExplanation`.
108
+ */
109
+ export type Blocker = {
110
+ readonly path: ReadonlyArray<string | number>;
111
+ readonly code: string;
112
+ readonly message: string;
113
+ readonly detail?: Readonly<Record<string, unknown>>;
114
+ };
115
+ /**
116
+ * Stage-explicit name for {@link Blocker}: the admission-stage vocabulary.
117
+ */
118
+ export type AdmissionBlocker = Blocker;
119
+ export type AdmissionOk<Name extends string = string> = {
120
+ readonly ok: true;
121
+ readonly action: Name;
122
+ };
123
+ export type AdmissionFailure<Name extends string = string> = {
124
+ readonly ok: false;
125
+ readonly action: Name;
126
+ readonly layer: "availability" | "input" | "dispatchability";
127
+ readonly code: "ACTION_UNAVAILABLE" | "INVALID_INPUT" | "INTENT_NOT_DISPATCHABLE";
128
+ readonly message: string;
129
+ readonly blockers: readonly Blocker[];
130
+ };
131
+ export type Admission<Name extends string = string> = AdmissionOk<Name> | AdmissionFailure<Name>;
132
+ export type PathSegment = string | number;
133
+ export type ChangedPath = {
134
+ readonly path: readonly PathSegment[];
135
+ readonly kind: "set" | "unset" | "changed";
136
+ };
137
+ export type PreviewDiagnostics = {
138
+ readonly trace?: TraceGraph;
139
+ };
140
+ export type PreviewResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
141
+ readonly admitted: false;
142
+ readonly admission: AdmissionFailure<K>;
143
+ } | {
144
+ readonly admitted: true;
145
+ readonly status: "complete" | "pending" | "halted" | "error";
146
+ readonly before: ProjectedSnapshot<T>;
147
+ readonly after: ProjectedSnapshot<T>;
148
+ readonly changes: readonly ChangedPath[];
149
+ readonly requirements: readonly Requirement[];
150
+ readonly newAvailableActions?: readonly ActionInfo[];
151
+ readonly diagnostics?: PreviewDiagnostics;
152
+ readonly error?: ErrorValue | null;
153
+ };
154
+ export type ExecutionDetail = Readonly<Record<string, unknown>>;
155
+ export type ExecutionOutcome = {
156
+ readonly kind: "ok";
157
+ readonly detail?: ExecutionDetail;
158
+ } | {
159
+ readonly kind: "stop";
160
+ readonly reason: string;
161
+ readonly detail?: ExecutionDetail;
162
+ } | {
163
+ readonly kind: "fail";
164
+ readonly error: ErrorValue;
165
+ readonly detail?: ExecutionDetail;
166
+ };
167
+ export type BaseWriteReport = {
168
+ readonly mode: "base";
169
+ readonly action: string;
170
+ readonly changes: readonly ChangedPath[];
171
+ readonly requirements: readonly Requirement[];
172
+ readonly outcome: ExecutionOutcome;
173
+ readonly diagnostics?: ExecutionDiagnostics;
174
+ };
175
+ export type WorldRecord = {
176
+ readonly worldId: string;
177
+ readonly schemaHash: string;
178
+ readonly snapshotHash: string;
179
+ readonly parentWorldId: string | null;
180
+ readonly terminalStatus: "completed" | "failed";
181
+ };
182
+ export type LineageWriteReport = {
183
+ readonly mode: "lineage";
184
+ readonly action: string;
185
+ readonly worldId: string;
186
+ readonly branchId: string;
187
+ readonly headAdvanced: boolean;
188
+ readonly published: boolean;
189
+ readonly outcome: ExecutionOutcome;
190
+ readonly sealedSnapshotHash: string;
191
+ readonly changes: readonly ChangedPath[];
192
+ readonly requirements: readonly Requirement[];
193
+ readonly diagnostics?: ExecutionDiagnostics;
194
+ };
195
+ export type GovernanceSettlementReport = {
196
+ readonly mode: "governance";
197
+ readonly status: "settled";
198
+ readonly action: string;
199
+ readonly proposal: ProposalRef;
200
+ readonly baseWorldId: string;
201
+ readonly worldId: string;
202
+ readonly sealedSnapshotHash: string;
203
+ readonly published: boolean;
204
+ readonly outcome: ExecutionOutcome;
205
+ readonly changes: readonly ChangedPath[];
206
+ readonly requirements: readonly Requirement[];
207
+ } | {
208
+ readonly mode: "governance";
209
+ readonly status: "rejected" | "superseded" | "expired" | "cancelled";
210
+ readonly action: string;
211
+ readonly proposal: ProposalRef;
212
+ readonly decision?: DecisionRecord;
213
+ } | {
214
+ readonly mode: "governance";
215
+ readonly status: "settlement_failed";
216
+ readonly action: string;
217
+ readonly proposal?: ProposalRef;
218
+ readonly stage: "authority" | "runtime" | "settlement" | "persistence" | "observation";
219
+ readonly error: ErrorValue;
220
+ };
221
+ export type ProposalRef = string;
222
+ export type DecisionRecord = Readonly<Record<string, unknown>>;
223
+ export type BaseSubmissionResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
224
+ readonly ok: true;
225
+ readonly mode: "base";
226
+ readonly status: "settled";
227
+ readonly action: K;
228
+ readonly before: ProjectedSnapshot<T>;
229
+ readonly after: ProjectedSnapshot<T>;
230
+ readonly outcome: ExecutionOutcome;
231
+ readonly report?: BaseWriteReport;
232
+ } | {
233
+ readonly ok: false;
234
+ readonly mode: "base";
235
+ readonly action: K;
236
+ readonly admission: AdmissionFailure<K>;
237
+ };
238
+ export type LineageSubmissionResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
239
+ readonly ok: true;
240
+ readonly mode: "lineage";
241
+ readonly status: "settled";
242
+ readonly action: K;
243
+ readonly before: ProjectedSnapshot<T>;
244
+ readonly after: ProjectedSnapshot<T>;
245
+ readonly world: WorldRecord;
246
+ readonly outcome: ExecutionOutcome;
247
+ readonly report?: LineageWriteReport;
248
+ } | {
249
+ readonly ok: false;
250
+ readonly mode: "lineage";
251
+ readonly action: K;
252
+ readonly admission: AdmissionFailure<K>;
253
+ };
254
+ export type GovernanceSubmissionResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
255
+ readonly ok: true;
256
+ readonly mode: "governance";
257
+ readonly status: "pending";
258
+ readonly action: K;
259
+ readonly proposal: ProposalRef;
260
+ waitForSettlement(): Promise<GovernanceSettlementResult<T, K>>;
261
+ } | {
262
+ readonly ok: false;
263
+ readonly mode: "governance";
264
+ readonly action: K;
265
+ readonly admission: AdmissionFailure<K>;
266
+ };
267
+ export type GovernanceSettlementResult<T extends ManifestoDomainShape, K extends ActionName<T>> = {
268
+ readonly ok: true;
269
+ readonly mode: "governance";
270
+ readonly status: "settled";
271
+ readonly action: K;
272
+ readonly proposal: ProposalRef;
273
+ readonly world: WorldRecord;
274
+ readonly before: ProjectedSnapshot<T>;
275
+ readonly after: ProjectedSnapshot<T>;
276
+ readonly outcome: ExecutionOutcome;
277
+ readonly report?: GovernanceSettlementReport;
278
+ } | {
279
+ readonly ok: true;
280
+ readonly mode: "governance";
281
+ readonly status: "rejected" | "superseded" | "expired" | "cancelled";
282
+ readonly action: K;
283
+ readonly proposal: ProposalRef;
284
+ readonly decision?: DecisionRecord;
285
+ readonly report?: GovernanceSettlementReport;
286
+ } | {
287
+ readonly ok: false;
288
+ readonly mode: "governance";
289
+ readonly status: "settlement_failed";
290
+ readonly action: K;
291
+ readonly proposal: ProposalRef;
292
+ readonly error: ErrorValue;
293
+ readonly report?: GovernanceSettlementReport;
294
+ };
295
+ export type SubmissionResult<T extends ManifestoDomainShape, K extends ActionName<T>> = BaseSubmissionResult<T, K> | LineageSubmissionResult<T, K> | GovernanceSubmissionResult<T, K>;
296
+ export type SubmitResultFor<TMode extends RuntimeMode, T extends ManifestoDomainShape, K extends ActionName<T>> = TMode extends "base" ? BaseSubmissionResult<T, K> : TMode extends "lineage" ? LineageSubmissionResult<T, K> : TMode extends "governance" ? GovernanceSubmissionResult<T, K> : SubmissionResult<T, K>;
297
+ export type ActionHandle<T extends ManifestoDomainShape, K extends ActionName<T>, TMode extends RuntimeMode> = {
298
+ info(): ActionInfo<K>;
299
+ available(): boolean;
300
+ check(...args: ActionArgs<T, K>): Admission<K>;
301
+ preview(...args: ActionArgs<T, K>): PreviewResult<T, K>;
302
+ submit(...args: ActionArgs<T, K>): Promise<SubmitResultFor<TMode, T, K>>;
303
+ bind(...args: ActionArgs<T, K>): BoundAction<T, K, TMode>;
304
+ };
305
+ export type DynamicActionHandle<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
306
+ info(): ActionInfo<ActionName<T>>;
307
+ available(): boolean;
308
+ check(...args: unknown[]): Admission<ActionName<T>>;
309
+ preview(...args: unknown[]): PreviewResult<T, ActionName<T>>;
310
+ submit(...args: unknown[]): Promise<SubmitResultFor<TMode, T, ActionName<T>>>;
311
+ bind(...args: unknown[]): DynamicBoundAction<T, TMode>;
312
+ };
313
+ export type BoundAction<T extends ManifestoDomainShape, K extends ActionName<T>, TMode extends RuntimeMode> = {
314
+ readonly action: K;
315
+ readonly input: ActionInput<T, K>;
316
+ check(): Admission<K>;
317
+ preview(): PreviewResult<T, K>;
318
+ submit(): Promise<SubmitResultFor<TMode, T, K>>;
319
+ intent(): Intent | null;
320
+ };
321
+ export type DynamicBoundAction<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
322
+ readonly action: ActionName<T>;
323
+ readonly input: ActionInput<T, ActionName<T>>;
324
+ check(): Admission<ActionName<T>>;
325
+ preview(): PreviewResult<T, ActionName<T>>;
326
+ submit(): Promise<SubmitResultFor<TMode, T, ActionName<T>>>;
327
+ intent(): Intent | null;
328
+ };
329
+ export type ActionSurface<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
330
+ readonly [K in ActionName<T>]: ActionHandle<T, K, TMode>;
331
+ };
332
+ type PreciseActionName<T extends ManifestoDomainShape> = string extends ActionName<T> ? never : ActionName<T>;
333
+ export type GetAction<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
334
+ <K extends PreciseActionName<T>>(name: K): ActionHandle<T, K, TMode>;
335
+ (name: string): DynamicActionHandle<T, TMode> | undefined;
336
+ };
59
337
  export type ActionObjectBindingArgs<T extends ManifestoDomainShape, K extends keyof T["actions"]> = ActionArgs<T, K> extends [unknown, ...unknown[]] ? [params: Record<string, unknown>] : never;
60
338
  export type CreateIntentArgs<T extends ManifestoDomainShape, K extends keyof T["actions"]> = ActionArgs<T, K> | ActionObjectBindingArgs<T, K>;
61
- export type Selector<T, R> = (snapshot: Snapshot<T>) => R;
339
+ export type Selector<TState, R, TComputed = Record<string, unknown>> = (snapshot: Snapshot<TState, TComputed>) => R;
62
340
  export type Unsubscribe = () => void;
341
+ export type ProjectedReadHandle<TValue, TRef> = {
342
+ readonly name: string;
343
+ readonly ref: TRef;
344
+ value(): TValue;
345
+ observe(listener: (next: TValue, prev: TValue) => void): Unsubscribe;
346
+ };
347
+ export type StateReadSurface<T extends ManifestoDomainShape> = {
348
+ readonly [K in keyof T["state"]]: ProjectedReadHandle<T["state"][K], FieldRef<T["state"][K]>>;
349
+ };
350
+ export type ComputedReadSurface<T extends ManifestoDomainShape> = {
351
+ readonly [K in keyof T["computed"]]: ProjectedReadHandle<T["computed"][K], ComputedRef<T["computed"][K]>>;
352
+ };
63
353
  declare const MANIFESTO_INTENT_BRAND: unique symbol;
64
354
  export type TypedIntent<T extends ManifestoDomainShape, K extends keyof T["actions"] = keyof T["actions"]> = Intent & {
65
355
  readonly [MANIFESTO_INTENT_BRAND]: {
@@ -68,7 +358,7 @@ export type TypedIntent<T extends ManifestoDomainShape, K extends keyof T["actio
68
358
  };
69
359
  };
70
360
  export type TypedCreateIntent<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => TypedIntent<T, K>;
71
- export type TypedDispatchAsync<T extends ManifestoDomainShape> = (intent: TypedIntent<T>) => Promise<Snapshot<T["state"]>>;
361
+ export type TypedDispatchAsync<T extends ManifestoDomainShape> = (intent: TypedIntent<T>) => Promise<ProjectedSnapshot<T>>;
72
362
  export type TypedCommitAsync<T extends ManifestoDomainShape> = TypedDispatchAsync<T>;
73
363
  export type SchemaGraphNodeRef = TypedActionRef<ManifestoDomainShape> | FieldRef<unknown> | ComputedRef<unknown>;
74
364
  export type SchemaGraph = CompilerSchemaGraph & {
@@ -78,8 +368,8 @@ export type SchemaGraph = CompilerSchemaGraph & {
78
368
  traceDown(nodeId: SchemaGraphNodeId): SchemaGraph;
79
369
  };
80
370
  export type SimulateResult<T extends ManifestoDomainShape = ManifestoDomainShape> = {
81
- readonly snapshot: Snapshot<T["state"]>;
82
- readonly changedPaths: readonly string[];
371
+ readonly snapshot: ProjectedSnapshot<T>;
372
+ readonly changedPaths: readonly ChangedPath[];
83
373
  readonly newAvailableActions: readonly (keyof T["actions"])[];
84
374
  readonly requirements: readonly Requirement[];
85
375
  readonly status: ComputeStatus;
@@ -116,22 +406,24 @@ export type AvailableActionDelta<T extends ManifestoDomainShape = ManifestoDomai
116
406
  readonly unlocked: readonly (keyof T["actions"])[];
117
407
  readonly locked: readonly (keyof T["actions"])[];
118
408
  };
119
- export type ProjectedDiff<T extends ManifestoDomainShape = ManifestoDomainShape> = {
120
- readonly beforeSnapshot: Snapshot<T["state"]>;
121
- readonly afterSnapshot: Snapshot<T["state"]>;
122
- readonly changedPaths: readonly string[];
409
+ export type DispatchProjectedDiff<T extends ManifestoDomainShape = ManifestoDomainShape> = {
410
+ readonly beforeSnapshot: ProjectedSnapshot<T>;
411
+ readonly afterSnapshot: ProjectedSnapshot<T>;
412
+ readonly changedPaths: readonly ChangedPath[];
123
413
  readonly availability: AvailableActionDelta<T>;
124
414
  };
125
- export type CanonicalOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
415
+ export type DispatchCanonicalOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
126
416
  readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
127
417
  readonly afterCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
128
418
  readonly pendingRequirements: readonly Requirement[];
129
419
  readonly status: CanonicalSnapshot<T["state"]>["system"]["status"];
130
420
  };
131
- export type ExecutionOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
132
- readonly projected: ProjectedDiff<T>;
133
- readonly canonical: CanonicalOutcome<T>;
421
+ export type DispatchExecutionOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = {
422
+ readonly projected: DispatchProjectedDiff<T>;
423
+ readonly canonical: DispatchCanonicalOutcome<T>;
134
424
  };
425
+ export type ProjectedDiff<T extends ManifestoDomainShape = ManifestoDomainShape> = DispatchProjectedDiff<T>;
426
+ export type CanonicalOutcome<T extends ManifestoDomainShape = ManifestoDomainShape> = DispatchCanonicalOutcome<T>;
135
427
  export type ExecutionFailureInfo = {
136
428
  readonly message: string;
137
429
  readonly code?: string;
@@ -148,7 +440,7 @@ export type DispatchReport<T extends ManifestoDomainShape = ManifestoDomainShape
148
440
  readonly kind: "admitted";
149
441
  readonly actionName: keyof T["actions"] & string;
150
442
  };
151
- readonly outcome: ExecutionOutcome<T>;
443
+ readonly outcome: DispatchExecutionOutcome<T>;
152
444
  readonly diagnostics?: ExecutionDiagnostics;
153
445
  } | {
154
446
  readonly kind: "rejected";
@@ -156,7 +448,7 @@ export type DispatchReport<T extends ManifestoDomainShape = ManifestoDomainShape
156
448
  readonly admission: Extract<IntentAdmission<T>, {
157
449
  readonly kind: "blocked";
158
450
  }>;
159
- readonly beforeSnapshot: Snapshot<T["state"]>;
451
+ readonly beforeSnapshot: ProjectedSnapshot<T>;
160
452
  readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
161
453
  readonly rejection: {
162
454
  readonly code: "ACTION_UNAVAILABLE" | "INTENT_NOT_DISPATCHABLE" | "INVALID_INPUT";
@@ -169,12 +461,12 @@ export type DispatchReport<T extends ManifestoDomainShape = ManifestoDomainShape
169
461
  readonly kind: "admitted";
170
462
  readonly actionName: keyof T["actions"] & string;
171
463
  };
172
- readonly beforeSnapshot: Snapshot<T["state"]>;
464
+ readonly beforeSnapshot: ProjectedSnapshot<T>;
173
465
  readonly beforeCanonicalSnapshot: CanonicalSnapshot<T["state"]>;
174
466
  readonly error: ExecutionFailureInfo;
175
467
  readonly published: boolean;
176
468
  readonly diagnostics?: ExecutionDiagnostics;
177
- readonly outcome?: ExecutionOutcome<T>;
469
+ readonly outcome?: DispatchExecutionOutcome<T>;
178
470
  };
179
471
  export type IntentExplanation<T extends ManifestoDomainShape = ManifestoDomainShape> = {
180
472
  readonly kind: "blocked";
@@ -196,61 +488,147 @@ export type IntentExplanation<T extends ManifestoDomainShape = ManifestoDomainSh
196
488
  readonly status: ComputeStatus;
197
489
  readonly requirements: readonly Requirement[];
198
490
  readonly canonicalSnapshot: CanonicalSnapshot<T["state"]>;
199
- readonly snapshot: Snapshot<T["state"]>;
491
+ readonly snapshot: ProjectedSnapshot<T>;
200
492
  readonly newAvailableActions: readonly (keyof T["actions"])[];
201
- readonly changedPaths: readonly string[];
493
+ readonly changedPaths: readonly ChangedPath[];
202
494
  };
203
495
  export type TypedSimulate<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => SimulateResult<T>;
204
496
  export type TypedSimulateIntent<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(intent: TypedIntent<T, K>) => SimulateResult<T>;
205
- export type TypedSubscribe<T extends ManifestoDomainShape> = <R>(selector: Selector<T["state"], R>, listener: (value: R) => void) => Unsubscribe;
497
+ export type TypedSubscribe<T extends ManifestoDomainShape> = <R>(selector: Selector<T["state"], R, T["computed"]>, listener: (value: R) => void) => Unsubscribe;
206
498
  export type TypedActionMetadata<T extends ManifestoDomainShape, K extends keyof T["actions"] = keyof T["actions"]> = {
207
499
  readonly name: K;
208
500
  readonly params: readonly string[];
501
+ readonly publicArity: number;
502
+ readonly requiredArity: number;
209
503
  readonly input: DomainSchema["actions"][string]["input"];
504
+ readonly inputType?: DomainSchema["actions"][string]["inputType"];
210
505
  readonly description: string | undefined;
506
+ readonly annotations?: ActionAnnotation;
211
507
  readonly hasDispatchableGate: boolean;
212
508
  };
213
509
  export type TypedGetActionMetadata<T extends ManifestoDomainShape> = {
214
510
  (): readonly TypedActionMetadata<T>[];
215
511
  <K extends keyof T["actions"]>(name: K): TypedActionMetadata<T, K>;
216
512
  };
513
+ /**
514
+ * Rich explanation-stage blocker riding on `IntentExplanation`.
515
+ *
516
+ * Carries the MEL expression behind the block. This is the upgrade target
517
+ * when a UI showing "why is this blocked" needs more than the coarse
518
+ * admission-stage {@link Blocker}: re-query the explanation seam to move
519
+ * from one vocabulary to the other.
520
+ */
217
521
  export type DispatchBlocker = {
218
522
  readonly layer: "available" | "dispatchable";
219
523
  readonly expression: ExprNode;
220
524
  readonly evaluatedResult: unknown;
221
525
  readonly description?: string;
222
526
  };
527
+ /**
528
+ * Stage-explicit name for {@link DispatchBlocker}: the explanation-stage
529
+ * vocabulary.
530
+ */
531
+ export type ExplanationBlocker = DispatchBlocker;
223
532
  export type TypedIsIntentDispatchable<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => boolean;
224
533
  export type TypedGetIntentBlockers<T extends ManifestoDomainShape> = <K extends keyof T["actions"]>(action: TypedActionRef<T, K>, ...args: CreateIntentArgs<T, K>) => readonly DispatchBlocker[];
225
- export interface ManifestoEventMap<T extends ManifestoDomainShape> {
226
- "dispatch:completed": {
227
- readonly intentId: string;
228
- readonly intent: TypedIntent<T>;
229
- readonly snapshot: Snapshot<T["state"]>;
534
+ export type SubmissionEventBase = {
535
+ readonly action: string;
536
+ readonly mode: RuntimeMode;
537
+ readonly intentId?: string;
538
+ readonly schemaHash: string;
539
+ readonly snapshotVersion?: number;
540
+ };
541
+ export type ProposalEventBase = {
542
+ readonly proposal: ProposalRef;
543
+ readonly action: string;
544
+ readonly schemaHash: string;
545
+ };
546
+ export type ManifestoEventPayloadMap = {
547
+ readonly "submission:admitted": SubmissionEventBase & {
548
+ readonly admission: AdmissionOk;
230
549
  };
231
- "dispatch:rejected": {
232
- readonly intentId: string;
233
- readonly intent: TypedIntent<T>;
234
- readonly code: "ACTION_UNAVAILABLE" | "INTENT_NOT_DISPATCHABLE" | "INVALID_INPUT";
235
- readonly reason: string;
550
+ readonly "submission:rejected": SubmissionEventBase & {
551
+ readonly admission: AdmissionFailure;
236
552
  };
237
- "dispatch:failed": {
238
- readonly intentId: string;
239
- readonly intent: TypedIntent<T>;
240
- readonly error: Error;
241
- readonly snapshot?: Snapshot<T["state"]>;
553
+ readonly "submission:submitted": SubmissionEventBase;
554
+ readonly "submission:pending": SubmissionEventBase & {
555
+ readonly mode: "governance";
556
+ readonly proposal: ProposalRef;
242
557
  };
243
- }
244
- export type ManifestoEvent = "dispatch:completed" | "dispatch:rejected" | "dispatch:failed";
245
- export type ManifestoEventPayload<T extends ManifestoDomainShape> = ManifestoEventMap<T>[ManifestoEvent];
246
- export type TypedOn<T extends ManifestoDomainShape> = <K extends ManifestoEvent>(event: K, handler: (payload: ManifestoEventMap<T>[K]) => void) => Unsubscribe;
558
+ readonly "submission:settled": SubmissionEventBase & {
559
+ readonly mode: "base" | "lineage" | "governance";
560
+ readonly outcome: ExecutionOutcome;
561
+ readonly proposal?: ProposalRef;
562
+ readonly worldId?: string;
563
+ };
564
+ readonly "submission:failed": SubmissionEventBase & {
565
+ readonly stage: "runtime" | "settlement";
566
+ readonly error: ErrorValue;
567
+ readonly proposal?: ProposalRef;
568
+ };
569
+ readonly "proposal:created": ProposalEventBase;
570
+ readonly "proposal:decided": ProposalEventBase & {
571
+ readonly decision: DecisionRecord;
572
+ };
573
+ readonly "proposal:superseded": ProposalEventBase & {
574
+ readonly supersededBy?: ProposalRef;
575
+ };
576
+ readonly "proposal:expired": ProposalEventBase & {
577
+ readonly reason?: string;
578
+ };
579
+ readonly "proposal:cancelled": ProposalEventBase & {
580
+ readonly reason?: string;
581
+ };
582
+ };
583
+ export type ManifestoEventName = keyof ManifestoEventPayloadMap;
584
+ export type ManifestoEventPayload<Event extends ManifestoEventName> = ManifestoEventPayloadMap[Event];
585
+ export type ManifestoEvent = ManifestoEventName;
586
+ export type TypedOn<_T extends ManifestoDomainShape> = <K extends ManifestoEvent>(event: K, handler: (payload: ManifestoEventPayloadMap[K]) => void) => Unsubscribe;
587
+ export type ObserveSurface<T extends ManifestoDomainShape> = {
588
+ state<S>(selector: (snapshot: ProjectedSnapshot<T>) => S, listener: (next: S, prev: S) => void): Unsubscribe;
589
+ event<Event extends ManifestoEventName>(event: Event, listener: (payload: ManifestoEventPayload<Event>) => void): Unsubscribe;
590
+ };
591
+ export type InspectSurface<T extends ManifestoDomainShape> = {
592
+ graph(): SchemaGraph;
593
+ canonicalSnapshot(): CanonicalSnapshot<T["state"]>;
594
+ action<Name extends ActionName<T>>(name: Name): ActionInfo<Name>;
595
+ availableActions(): readonly ActionInfo<ActionName<T>>[];
596
+ schemaHash(): string;
597
+ };
598
+ export type BaseManifestoApp<T extends ManifestoDomainShape, TMode extends RuntimeMode> = {
599
+ readonly action: ActionSurface<T, TMode>;
600
+ readonly state: StateReadSurface<T>;
601
+ readonly computed: ComputedReadSurface<T>;
602
+ readonly observe: ObserveSurface<T>;
603
+ readonly inspect: InspectSurface<T>;
604
+ snapshot(): ProjectedSnapshot<T>;
605
+ getAction: GetAction<T, TMode>;
606
+ context(): DomainExternalContext<T>;
607
+ injectContext(context: DomainExternalContext<T>): void;
608
+ updateContext(updater: ContextUpdater<DomainExternalContext<T>>): DomainExternalContext<T>;
609
+ with(view: ExecutionView<DomainExternalContext<T>>): ManifestoApp<T, TMode>;
610
+ dispose(): void;
611
+ };
612
+ export type GovernanceSettlementSurface<T extends ManifestoDomainShape> = {
613
+ waitForSettlement(ref: ProposalRef): Promise<GovernanceSettlementResult<T, ActionName<T>>>;
614
+ };
615
+ type EmptySurface = Record<never, never>;
616
+ export type ManifestoApp<T extends ManifestoDomainShape, TMode extends RuntimeMode> = BaseManifestoApp<T, TMode> & ([TMode] extends ["governance"] ? GovernanceSettlementSurface<T> : EmptySurface);
617
+ /**
618
+ * v3-era intent-centric instance shape, retired from the public surface by
619
+ * the v5 activation-first design. It is intentionally NOT exported from the
620
+ * package entrypoints; it remains only as the internal compat seam's view.
621
+ *
622
+ * @deprecated Scheduled for removal in the next major release together with
623
+ * the deprecated DispatchReport / IntentAdmission result types.
624
+ */
247
625
  export type ManifestoBaseInstance<T extends ManifestoDomainShape> = {
248
626
  readonly createIntent: TypedCreateIntent<T>;
249
627
  readonly dispatchAsync: TypedDispatchAsync<T>;
250
628
  readonly dispatchAsyncWithReport: (intent: TypedIntent<T>) => Promise<DispatchReport<T>>;
251
629
  readonly subscribe: TypedSubscribe<T>;
252
630
  readonly on: TypedOn<T>;
253
- readonly getSnapshot: () => Snapshot<T["state"]>;
631
+ readonly getSnapshot: () => ProjectedSnapshot<T>;
254
632
  readonly getCanonicalSnapshot: () => CanonicalSnapshot<T["state"]>;
255
633
  readonly getAvailableActions: () => readonly (keyof T["actions"])[];
256
634
  readonly isIntentDispatchable: TypedIsIntentDispatchable<T>;
@@ -263,14 +641,16 @@ export type ManifestoBaseInstance<T extends ManifestoDomainShape> = {
263
641
  readonly getSchemaGraph: () => SchemaGraph;
264
642
  readonly simulate: TypedSimulate<T>;
265
643
  readonly simulateIntent: TypedSimulateIntent<T>;
644
+ readonly refs: TypedDomainRefs<T>;
645
+ /** @deprecated Use refs. */
266
646
  readonly MEL: TypedMEL<T>;
267
647
  readonly schema: DomainSchema;
268
648
  readonly dispose: () => void;
269
649
  };
270
- export type ManifestoLegalityRuntime<T extends ManifestoDomainShape> = Pick<ManifestoBaseInstance<T>, "createIntent" | "whyNot" | "simulate" | "simulateIntent" | "MEL">;
650
+ export type ManifestoLegalityRuntime<T extends ManifestoDomainShape> = Pick<ManifestoBaseInstance<T>, "createIntent" | "whyNot" | "simulate" | "simulateIntent" | "refs" | "MEL">;
271
651
  export type ManifestoDispatchRuntime<T extends ManifestoDomainShape> = Pick<ManifestoBaseInstance<T>, "dispatchAsync" | "dispatchAsyncWithReport">;
272
652
  export interface ManifestoRuntimeByLaws<T extends ManifestoDomainShape> {
273
- readonly base: ManifestoBaseInstance<T>;
653
+ readonly base: ManifestoApp<T, "base">;
274
654
  }
275
655
  export interface ManifestoDecoratedRuntimeByLaws<T extends ManifestoDomainShape> {
276
656
  }
@@ -280,7 +660,7 @@ export type ActivatedInstance<T extends ManifestoDomainShape, Laws> = Laws exten
280
660
  } ? Runtime : never : Laws extends LineageLaws ? ResolvedManifestoRuntimeByLaws<T> extends {
281
661
  readonly lineage: infer Runtime;
282
662
  } ? Runtime : never : ManifestoRuntimeByLaws<T>["base"];
283
- export type { CanonicalPlatformNamespaces, CanonicalSnapshot, Snapshot, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, };
663
+ export type { CanonicalNamespaces, CanonicalSnapshot, Snapshot, SchemaGraphEdge, SchemaGraphEdgeRelation, SchemaGraphNode, SchemaGraphNodeId, SchemaGraphNodeKind, };
284
664
  export type ComposableManifesto<T extends ManifestoDomainShape, Laws extends BaseLaws = BaseComposableLaws> = {
285
665
  readonly _laws: Laws;
286
666
  readonly schema: DomainSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifesto-ai/sdk",
3
- "version": "3.18.1",
3
+ "version": "5.1.0",
4
4
  "description": "Manifesto SDK - Activation-first public API for the base runtime",
5
5
  "author": "eggplantiny <eggplantiny@gmail.com>",
6
6
  "license": "MIT",
@@ -47,9 +47,9 @@
47
47
  "dist"
48
48
  ],
49
49
  "dependencies": {
50
- "@manifesto-ai/compiler": "3.9.0",
51
- "@manifesto-ai/host": "2.9.1",
52
- "@manifesto-ai/core": "2.13.0"
50
+ "@manifesto-ai/compiler": "5.0.1",
51
+ "@manifesto-ai/host": "5.0.1",
52
+ "@manifesto-ai/core": "5.1.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "typescript": "^5.9.3",
@@ -60,10 +60,10 @@
60
60
  "build": "rm -rf dist && tsup && tsc -p tsconfig.build.json --emitDeclarationOnly --declarationMap false --outDir dist",
61
61
  "dev": "tsc --watch",
62
62
  "clean": "rm -rf dist",
63
- "lint": "echo 'lint not configured'",
63
+ "lint": "node ../../node_modules/@biomejs/biome/bin/biome check src",
64
64
  "test": "pnpm run test:runtime && pnpm run test:types",
65
- "test:runtime": "node ../../node_modules/vitest/vitest.mjs run",
66
- "test:types": "node ../../node_modules/typescript/bin/tsc -p tsconfig.types.json --noEmit",
67
- "test:coverage": "node ../../node_modules/vitest/vitest.mjs run --coverage"
65
+ "test:runtime": "node ../../scripts/run-vitest.mjs run",
66
+ "test:types": "node ../../scripts/run-tsc.mjs -p tsconfig.types.json --noEmit",
67
+ "test:coverage": "node ../../scripts/run-vitest.mjs run --coverage"
68
68
  }
69
69
  }
@@ -1 +0,0 @@
1
- var n=class extends Error{code;constructor(e,o,d){super(o,d),this.name="ManifestoError",this.code=e}},s=class extends n{effectType;constructor(e){super("RESERVED_EFFECT",`Effect type "${e}" is reserved and cannot be overridden`),this.name="ReservedEffectError",this.effectType=e}},t=class extends n{diagnostics;constructor(e,o){super("COMPILE_ERROR",o),this.name="CompileError",this.diagnostics=e}},a=class extends n{constructor(){super("DISPOSED","Cannot use a disposed Manifesto runtime"),this.name="DisposedError"}},i=class extends n{constructor(){super("ALREADY_ACTIVATED","ComposableManifesto.activate() may only be called once"),this.name="AlreadyActivatedError"}};export{n as a,s as b,t as c,a as d,i as e};