@manifesto-ai/core 2.7.1 → 2.9.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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/core/action-availability.d.ts +27 -0
  3. package/dist/core/apply.d.ts +11 -0
  4. package/dist/core/compute.d.ts +16 -0
  5. package/dist/core/explain.d.ts +13 -0
  6. package/dist/core/index.d.ts +4 -0
  7. package/dist/core/system-delta.d.ts +8 -0
  8. package/dist/core/validate.d.ts +15 -0
  9. package/dist/core/validation-utils.d.ts +22 -0
  10. package/dist/errors.d.ts +29 -0
  11. package/dist/evaluator/computed.d.ts +13 -0
  12. package/dist/evaluator/context.d.ts +61 -0
  13. package/dist/evaluator/dag.d.ts +29 -0
  14. package/dist/evaluator/expr.d.ts +10 -0
  15. package/dist/evaluator/flow.d.ts +35 -0
  16. package/dist/evaluator/index.d.ts +5 -0
  17. package/dist/factories.d.ts +21 -0
  18. package/dist/index.d.ts +28 -1746
  19. package/dist/index.js +231 -212
  20. package/dist/index.js.map +1 -1
  21. package/dist/schema/action.d.ts +13 -0
  22. package/dist/schema/common.d.ts +36 -0
  23. package/dist/schema/computed.d.ts +22 -0
  24. package/dist/schema/defaults.d.ts +11 -0
  25. package/dist/schema/domain.d.ts +49 -0
  26. package/dist/schema/expr.d.ts +482 -0
  27. package/dist/schema/field.d.ts +47 -0
  28. package/dist/schema/flow.d.ts +108 -0
  29. package/dist/schema/host-context.d.ts +11 -0
  30. package/dist/schema/index.d.ts +14 -0
  31. package/dist/schema/patch.d.ts +105 -0
  32. package/dist/schema/result.d.ts +175 -0
  33. package/dist/schema/snapshot.d.ts +132 -0
  34. package/dist/schema/trace.d.ts +97 -0
  35. package/dist/schema/type-spec.d.ts +33 -0
  36. package/dist/utils/canonical.d.ts +37 -0
  37. package/dist/utils/hash.d.ts +54 -0
  38. package/dist/utils/index.d.ts +4 -0
  39. package/dist/utils/patch-path.d.ts +15 -0
  40. package/dist/utils/path.d.ts +41 -0
  41. package/package.json +4 -4
package/README.md CHANGED
@@ -186,7 +186,7 @@ Use Core directly when:
186
186
  - Testing domain logic in isolation
187
187
  - Building developer tools (debuggers, visualizers)
188
188
 
189
- For typical usage, see [`@manifesto-ai/sdk`](../sdk/) — the recommended entry point. For explicit governance, see [`@manifesto-ai/world`](../world/).
189
+ For typical usage, see [`@manifesto-ai/sdk`](../sdk/) — the recommended entry point. For explicit governance, see [`@manifesto-ai/lineage`](../lineage/) and [`@manifesto-ai/governance`](../governance/).
190
190
 
191
191
  ---
192
192
 
@@ -0,0 +1,27 @@
1
+ import type { DomainSchema } from "../schema/domain.js";
2
+ import type { Snapshot } from "../schema/snapshot.js";
3
+ type ActionAvailabilityErrorCode = "UNKNOWN_ACTION" | "INTERNAL_ERROR" | "TYPE_MISMATCH";
4
+ export type ActionAvailabilityEvaluation = {
5
+ kind: "ok";
6
+ available: boolean;
7
+ } | {
8
+ kind: "error";
9
+ code: ActionAvailabilityErrorCode;
10
+ message: string;
11
+ };
12
+ /**
13
+ * Evaluate an action's availability expression without re-entry semantics.
14
+ *
15
+ * This is the shared evaluator used by compute() initial invocation checks and
16
+ * the public availability query API.
17
+ */
18
+ export declare function evaluateActionAvailability(schema: DomainSchema, snapshot: Snapshot, actionName: string, timestamp?: number): ActionAvailabilityEvaluation;
19
+ /**
20
+ * Check whether an action is available for a new invocation.
21
+ */
22
+ export declare function isActionAvailable(schema: DomainSchema, snapshot: Snapshot, actionName: string): boolean;
23
+ /**
24
+ * Return all currently dispatchable actions in schema key order.
25
+ */
26
+ export declare function getAvailableActions(schema: DomainSchema, snapshot: Snapshot): readonly string[];
27
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { DomainSchema } from "../schema/domain.js";
2
+ import type { Snapshot } from "../schema/snapshot.js";
3
+ import type { Patch } from "../schema/patch.js";
4
+ import type { HostContext } from "../schema/host-context.js";
5
+ /**
6
+ * Apply patches to snapshot.data and recompute computed values.
7
+ *
8
+ * Patch targets are rooted at snapshot.data only.
9
+ * System transitions are handled by applySystemDelta().
10
+ */
11
+ export declare function apply(schema: DomainSchema, snapshot: Snapshot, patches: readonly Patch[], context: HostContext): Snapshot;
@@ -0,0 +1,16 @@
1
+ import type { DomainSchema } from "../schema/domain.js";
2
+ import type { Snapshot } from "../schema/snapshot.js";
3
+ import type { Intent } from "../schema/patch.js";
4
+ import type { ComputeResult } from "../schema/result.js";
5
+ import type { HostContext } from "../schema/host-context.js";
6
+ /**
7
+ * Compute the result of dispatching an intent (synchronous).
8
+ *
9
+ * This is the canonical computation path. Each call is independent -
10
+ * there is no suspended context.
11
+ */
12
+ export declare function computeSync(schema: DomainSchema, snapshot: Snapshot, intent: Intent, context: HostContext): ComputeResult;
13
+ /**
14
+ * Compute the result of dispatching an intent (async wrapper).
15
+ */
16
+ export declare function compute(schema: DomainSchema, snapshot: Snapshot, intent: Intent, context: HostContext): Promise<ComputeResult>;
@@ -0,0 +1,13 @@
1
+ import type { DomainSchema } from "../schema/domain.js";
2
+ import type { Snapshot } from "../schema/snapshot.js";
3
+ import type { SemanticPath } from "../schema/common.js";
4
+ import type { ExplainResult } from "../schema/result.js";
5
+ /**
6
+ * Explain why a value is what it is
7
+ *
8
+ * @param schema - The domain schema
9
+ * @param snapshot - Current snapshot state
10
+ * @param path - The path to explain
11
+ * @returns ExplainResult with value, trace, and dependencies
12
+ */
13
+ export declare function explain(schema: DomainSchema, snapshot: Snapshot, path: SemanticPath): ExplainResult;
@@ -0,0 +1,4 @@
1
+ export { validate } from "./validate.js";
2
+ export { apply } from "./apply.js";
3
+ export { compute, computeSync } from "./compute.js";
4
+ export { explain } from "./explain.js";
@@ -0,0 +1,8 @@
1
+ import type { Snapshot } from "../schema/snapshot.js";
2
+ import type { SystemDelta } from "../schema/result.js";
3
+ /**
4
+ * Apply a declarative system transition to a snapshot.
5
+ *
6
+ * This function is pure, deterministic, and total.
7
+ */
8
+ export declare function applySystemDelta(snapshot: Snapshot, delta: SystemDelta): Snapshot;
@@ -0,0 +1,15 @@
1
+ import type { ValidationResult } from "../schema/result.js";
2
+ /**
3
+ * Validate a domain schema
4
+ *
5
+ * Validation rules:
6
+ * - V-001: All paths in ComputedSpec.deps MUST exist
7
+ * - V-002: ComputedSpec dependency graph MUST be acyclic
8
+ * - V-003: All paths in ExprNode.get MUST exist
9
+ * - V-004: All `call` references in FlowSpec MUST exist
10
+ * - V-005: FlowSpec `call` graph MUST be acyclic
11
+ * - V-006: ActionSpec.available expression MUST return boolean (runtime check)
12
+ * - V-007: ActionSpec.input MUST be valid FieldSpec (Zod handles this)
13
+ * - V-008: Schema hash MUST match canonical hash
14
+ */
15
+ export declare function validate(schema: unknown): ValidationResult;
@@ -0,0 +1,22 @@
1
+ import type { ExprNode } from "../schema/expr.js";
2
+ import type { FlowNode } from "../schema/flow.js";
3
+ import type { FieldSpec, StateSpec } from "../schema/field.js";
4
+ import type { ComputedSpec } from "../schema/computed.js";
5
+ import type { PatchSegment } from "../schema/patch.js";
6
+ export declare function isValidSchemaId(id: string): boolean;
7
+ export declare function isValidSemver(version: string): boolean;
8
+ export declare function collectGetPathsFromExpr(expr: ExprNode): string[];
9
+ export declare function collectGetPathsFromFlow(flow: FlowNode): string[];
10
+ export declare function pathExistsInStateSpec(state: StateSpec, path: string): boolean;
11
+ export declare function pathExistsInComputedSpec(computed: ComputedSpec, path: string): boolean;
12
+ export declare function pathExistsInFieldSpec(spec: FieldSpec, path: string): boolean;
13
+ export declare function pathExistsInFieldSpecSegments(spec: FieldSpec, segments: readonly PatchSegment[]): boolean;
14
+ export declare function validateValueAgainstFieldSpec(value: unknown, spec: FieldSpec, options?: {
15
+ allowPartial?: boolean;
16
+ allowUndefined?: boolean;
17
+ }): {
18
+ ok: boolean;
19
+ message?: string;
20
+ };
21
+ export declare function getFieldSpecAtPath(spec: FieldSpec, path: string): FieldSpec | null;
22
+ export declare function getFieldSpecAtSegments(spec: FieldSpec, segments: readonly PatchSegment[]): FieldSpec | null;
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+ import type { ErrorValue } from "./schema/snapshot.js";
3
+ /**
4
+ * Core error codes
5
+ */
6
+ export declare const CoreErrorCode: z.ZodEnum<{
7
+ VALIDATION_ERROR: "VALIDATION_ERROR";
8
+ PATH_NOT_FOUND: "PATH_NOT_FOUND";
9
+ TYPE_MISMATCH: "TYPE_MISMATCH";
10
+ DIVISION_BY_ZERO: "DIVISION_BY_ZERO";
11
+ INDEX_OUT_OF_BOUNDS: "INDEX_OUT_OF_BOUNDS";
12
+ UNKNOWN_ACTION: "UNKNOWN_ACTION";
13
+ ACTION_UNAVAILABLE: "ACTION_UNAVAILABLE";
14
+ INVALID_INPUT: "INVALID_INPUT";
15
+ CYCLIC_DEPENDENCY: "CYCLIC_DEPENDENCY";
16
+ UNKNOWN_FLOW: "UNKNOWN_FLOW";
17
+ CYCLIC_CALL: "CYCLIC_CALL";
18
+ UNKNOWN_EFFECT: "UNKNOWN_EFFECT";
19
+ INTERNAL_ERROR: "INTERNAL_ERROR";
20
+ }>;
21
+ export type CoreErrorCode = z.infer<typeof CoreErrorCode>;
22
+ /**
23
+ * Create an error value (errors are values, not exceptions)
24
+ */
25
+ export declare function createError(code: CoreErrorCode, message: string, actionId: string, nodePath: string, timestamp: number, context?: Record<string, unknown>): ErrorValue;
26
+ /**
27
+ * Check if a value is an ErrorValue
28
+ */
29
+ export declare function isErrorValue(value: unknown): value is ErrorValue;
@@ -0,0 +1,13 @@
1
+ import type { DomainSchema } from "../schema/domain.js";
2
+ import type { Snapshot } from "../schema/snapshot.js";
3
+ import type { SemanticPath, Result } from "../schema/common.js";
4
+ import type { ErrorValue } from "../schema/snapshot.js";
5
+ /**
6
+ * Evaluate all computed values for a snapshot
7
+ * Returns the computed values record or an error
8
+ */
9
+ export declare function evaluateComputed(schema: DomainSchema, snapshot: Snapshot): Result<Record<SemanticPath, unknown>, ErrorValue>;
10
+ /**
11
+ * Evaluate a single computed value
12
+ */
13
+ export declare function evaluateSingleComputed(schema: DomainSchema, snapshot: Snapshot, path: SemanticPath): Result<unknown, ErrorValue>;
@@ -0,0 +1,61 @@
1
+ import type { Snapshot } from "../schema/snapshot.js";
2
+ import type { DomainSchema } from "../schema/domain.js";
3
+ import { type TraceContext } from "../schema/trace.js";
4
+ /**
5
+ * Evaluation context for expressions and flows
6
+ */
7
+ export type EvalContext = {
8
+ /**
9
+ * Current snapshot state
10
+ */
11
+ readonly snapshot: Snapshot;
12
+ /**
13
+ * Domain schema
14
+ */
15
+ readonly schema: DomainSchema;
16
+ /**
17
+ * Current action being processed (if any)
18
+ */
19
+ readonly currentAction: string | null;
20
+ /**
21
+ * Current node path in the flow (for tracing)
22
+ */
23
+ readonly nodePath: string;
24
+ /**
25
+ * Intent ID for the current intent (for re-entry safety)
26
+ */
27
+ readonly intentId?: string;
28
+ /**
29
+ * UUID generator counter (for deterministic UUID generation)
30
+ */
31
+ uuidCounter?: number;
32
+ /**
33
+ * Trace context for deterministic trace ID generation
34
+ */
35
+ readonly trace: TraceContext;
36
+ /**
37
+ * Collection context variables (for filter, map, find, etc.)
38
+ */
39
+ readonly $item?: unknown;
40
+ readonly $index?: number;
41
+ readonly $array?: unknown[];
42
+ };
43
+ /**
44
+ * Create a new evaluation context
45
+ *
46
+ * @param timestampOrTrace - Required timestamp or TraceContext for deterministic tracing.
47
+ * MUST be provided by Host via HostContext.now to ensure determinism.
48
+ */
49
+ export declare function createContext(snapshot: Snapshot, schema: DomainSchema, currentAction: string | null, nodePath: string, intentId: string | undefined, timestampOrTrace: number | TraceContext): EvalContext;
50
+ /**
51
+ * Create context with collection variables for filter/map/find/etc.
52
+ */
53
+ export declare function withCollectionContext(ctx: EvalContext, item: unknown, index: number, array: unknown[]): EvalContext;
54
+ /**
55
+ * Update context with new snapshot
56
+ */
57
+ export declare function withSnapshot(ctx: EvalContext, snapshot: Snapshot): EvalContext;
58
+ /**
59
+ * Update context with new node path
60
+ */
61
+ export declare function withNodePath(ctx: EvalContext, nodePath: string): EvalContext;
@@ -0,0 +1,29 @@
1
+ import type { ComputedSpec } from "../schema/computed.js";
2
+ import type { SemanticPath } from "../schema/common.js";
3
+ import type { Result } from "../schema/common.js";
4
+ import type { ValidationError } from "../schema/result.js";
5
+ /**
6
+ * Dependency graph for computed values
7
+ */
8
+ export type DependencyGraph = {
9
+ readonly nodes: readonly SemanticPath[];
10
+ readonly edges: ReadonlyMap<SemanticPath, readonly SemanticPath[]>;
11
+ };
12
+ /**
13
+ * Build a dependency graph from ComputedSpec
14
+ */
15
+ export declare function buildDependencyGraph(computed: ComputedSpec): DependencyGraph;
16
+ /**
17
+ * Topological sort using Kahn's algorithm
18
+ * Returns sorted order or error if cycles detected
19
+ */
20
+ export declare function topologicalSort(graph: DependencyGraph): Result<SemanticPath[], ValidationError>;
21
+ /**
22
+ * Detect cycles in the dependency graph
23
+ * Returns array of cycle paths or null if no cycles
24
+ */
25
+ export declare function detectCycles(graph: DependencyGraph): SemanticPath[][] | null;
26
+ /**
27
+ * Get all dependencies (transitive) for a given node
28
+ */
29
+ export declare function getTransitiveDeps(graph: DependencyGraph, node: SemanticPath): Set<SemanticPath>;
@@ -0,0 +1,10 @@
1
+ import type { ExprNode } from "../schema/expr.js";
2
+ import type { ErrorValue } from "../schema/snapshot.js";
3
+ import type { Result } from "../schema/common.js";
4
+ import { type EvalContext } from "./context.js";
5
+ export type ExprResult = Result<unknown, ErrorValue>;
6
+ /**
7
+ * Evaluate an expression node
8
+ * All expressions are pure and total (always return a value or error)
9
+ */
10
+ export declare function evaluateExpr(expr: ExprNode, ctx: EvalContext): ExprResult;
@@ -0,0 +1,35 @@
1
+ import type { FlowNode } from "../schema/flow.js";
2
+ import type { Snapshot, Requirement, ErrorValue } from "../schema/snapshot.js";
3
+ import type { Patch } from "../schema/patch.js";
4
+ import type { TraceNode } from "../schema/trace.js";
5
+ import { type EvalContext } from "./context.js";
6
+ /**
7
+ * Flow execution status
8
+ */
9
+ export type FlowStatus = "running" | "complete" | "pending" | "halted" | "error";
10
+ /**
11
+ * Flow execution state
12
+ */
13
+ export type FlowState = {
14
+ readonly snapshot: Snapshot;
15
+ readonly status: FlowStatus;
16
+ readonly patches: readonly Patch[];
17
+ readonly requirements: readonly Requirement[];
18
+ readonly error: ErrorValue | null;
19
+ };
20
+ /**
21
+ * Flow evaluation result
22
+ */
23
+ export type FlowResult = {
24
+ readonly state: FlowState;
25
+ readonly trace: TraceNode;
26
+ };
27
+ /**
28
+ * Create initial flow state
29
+ */
30
+ export declare function createFlowState(snapshot: Snapshot): FlowState;
31
+ /**
32
+ * Evaluate a flow node
33
+ */
34
+ export declare function evaluateFlowSync(flow: FlowNode, ctx: EvalContext, state: FlowState, nodePath: string): FlowResult;
35
+ export declare function evaluateFlow(flow: FlowNode, ctx: EvalContext, state: FlowState, nodePath: string): Promise<FlowResult>;
@@ -0,0 +1,5 @@
1
+ export * from "./context.js";
2
+ export * from "./expr.js";
3
+ export * from "./flow.js";
4
+ export * from "./dag.js";
5
+ export * from "./computed.js";
@@ -0,0 +1,21 @@
1
+ import type { Snapshot } from "./schema/snapshot.js";
2
+ import type { Intent } from "./schema/patch.js";
3
+ import type { HostContext } from "./schema/host-context.js";
4
+ /**
5
+ * Create a new snapshot with initial data
6
+ *
7
+ * @param data - Initial domain data
8
+ * @param schemaHash - Hash of the schema this snapshot conforms to
9
+ * @returns New snapshot
10
+ */
11
+ export declare function createSnapshot<T>(data: T, schemaHash: string, context: HostContext): Snapshot;
12
+ /**
13
+ * Create an intent
14
+ *
15
+ * @param type - Action type
16
+ * @param input - Action input (optional)
17
+ * @param intentId - Unique identifier for this processing attempt (optional, auto-generated if not provided)
18
+ * @returns Intent
19
+ */
20
+ export declare function createIntent(type: string, intentId: string): Intent;
21
+ export declare function createIntent(type: string, input: unknown, intentId: string): Intent;