@manifesto-ai/lineage 3.1.2 → 3.3.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/README.md CHANGED
@@ -11,8 +11,9 @@
11
11
  - `withLineage(createManifesto(...), config).activate()`
12
12
  - lineage-aware `commitAsync` that seals before publication
13
13
  - restore, head, branch, and world queries on the activated runtime
14
+ - `getWorldSnapshot(worldId)` for stored sealed snapshot lookup
14
15
  - `getLineage()` for DAG inspection on the activated runtime
15
- - sealing substrate and the internal provider surface
16
+ - sealing substrate and the provider surface
16
17
  - deterministic world identity, branch semantics, and restore normalization
17
18
 
18
19
  ## Canonical Path
@@ -38,7 +39,7 @@ if (head) {
38
39
 
39
40
  ## Low-Level Usage
40
41
 
41
- Use `@manifesto-ai/lineage/internal` when you need `LineageService`, `LineageStore`, prepared commits, or custom persistence without the activated runtime wrapper.
42
+ Use `@manifesto-ai/lineage/provider` when you need `LineageService`, `LineageStore`, prepared commits, or custom persistence without the activated runtime wrapper.
42
43
 
43
44
  ## Docs
44
45
 
@@ -1,9 +1,3 @@
1
- // src/internal.ts
2
- import {
3
- DisposedError,
4
- ManifestoError
5
- } from "@manifesto-ai/sdk";
6
-
7
1
  // src/invariants.ts
8
2
  function assertLineage(condition, message) {
9
3
  if (!condition) {
@@ -16,6 +10,270 @@ function cloneValue(value) {
16
10
  return structuredClone(value);
17
11
  }
18
12
 
13
+ // src/store/in-memory-lineage-store.ts
14
+ function cloneBranch(branch) {
15
+ return cloneValue(branch);
16
+ }
17
+ function sortAttempts(attempts) {
18
+ return [...attempts].sort((left, right) => {
19
+ if (left.createdAt !== right.createdAt) {
20
+ return left.createdAt - right.createdAt;
21
+ }
22
+ if (left.attemptId === right.attemptId) {
23
+ return 0;
24
+ }
25
+ return left.attemptId < right.attemptId ? -1 : 1;
26
+ }).map((attempt) => cloneValue(attempt));
27
+ }
28
+ var InMemoryLineageStore = class {
29
+ worlds = /* @__PURE__ */ new Map();
30
+ snapshots = /* @__PURE__ */ new Map();
31
+ hashInputs = /* @__PURE__ */ new Map();
32
+ edges = /* @__PURE__ */ new Map();
33
+ edgesByWorld = /* @__PURE__ */ new Map();
34
+ attempts = /* @__PURE__ */ new Map();
35
+ attemptsByWorld = /* @__PURE__ */ new Map();
36
+ attemptsByBranch = /* @__PURE__ */ new Map();
37
+ branches = /* @__PURE__ */ new Map();
38
+ activeBranchId = null;
39
+ async putWorld(world) {
40
+ this.worlds.set(world.worldId, cloneValue(world));
41
+ }
42
+ async getWorld(worldId) {
43
+ return cloneValue(this.worlds.get(worldId) ?? null);
44
+ }
45
+ async putSnapshot(worldId, snapshot) {
46
+ this.snapshots.set(worldId, cloneValue(snapshot));
47
+ }
48
+ async getSnapshot(worldId) {
49
+ return cloneValue(this.snapshots.get(worldId) ?? null);
50
+ }
51
+ async putAttempt(attempt) {
52
+ this.attempts.set(attempt.attemptId, cloneValue(attempt));
53
+ this.indexAttempt(this.attemptsByWorld, attempt.worldId, attempt.attemptId);
54
+ this.indexAttempt(this.attemptsByBranch, attempt.branchId, attempt.attemptId);
55
+ }
56
+ async getAttempts(worldId) {
57
+ const attemptIds = this.attemptsByWorld.get(worldId) ?? [];
58
+ return sortAttempts(
59
+ attemptIds.map((attemptId) => this.attempts.get(attemptId)).filter((attempt) => attempt != null)
60
+ );
61
+ }
62
+ async getAttemptsByBranch(branchId) {
63
+ const attemptIds = this.attemptsByBranch.get(branchId) ?? [];
64
+ return sortAttempts(
65
+ attemptIds.map((attemptId) => this.attempts.get(attemptId)).filter((attempt) => attempt != null)
66
+ );
67
+ }
68
+ async putHashInput(snapshotHash, input) {
69
+ this.hashInputs.set(snapshotHash, cloneValue(input));
70
+ }
71
+ async getHashInput(snapshotHash) {
72
+ return cloneValue(this.hashInputs.get(snapshotHash) ?? null);
73
+ }
74
+ async putEdge(edge) {
75
+ this.edges.set(edge.edgeId, cloneValue(edge));
76
+ this.indexEdge(edge.from, edge.edgeId);
77
+ this.indexEdge(edge.to, edge.edgeId);
78
+ }
79
+ async getEdges(worldId) {
80
+ const edgeIds = [...this.edgesByWorld.get(worldId) ?? /* @__PURE__ */ new Set()].sort();
81
+ return edgeIds.map((edgeId) => this.edges.get(edgeId)).filter((edge) => edge != null).map((edge) => cloneValue(edge));
82
+ }
83
+ async getBranchHead(branchId) {
84
+ return this.branches.get(branchId)?.head ?? null;
85
+ }
86
+ async getBranchTip(branchId) {
87
+ return this.branches.get(branchId)?.tip ?? null;
88
+ }
89
+ async getBranchEpoch(branchId) {
90
+ const branch = this.branches.get(branchId);
91
+ assertLineage(branch != null, `LIN-EPOCH-6 violation: unknown branch ${branchId}`);
92
+ return branch.epoch;
93
+ }
94
+ async mutateBranch(mutation) {
95
+ const branch = this.branches.get(mutation.branchId);
96
+ assertLineage(branch != null, `LIN-STORE-4 violation: unknown branch ${mutation.branchId}`);
97
+ assertLineage(
98
+ branch.head === mutation.expectedHead && branch.tip === mutation.expectedTip && branch.epoch === mutation.expectedEpoch,
99
+ `LIN-STORE-4 violation: branch ${mutation.branchId} CAS mismatch`
100
+ );
101
+ this.branches.set(mutation.branchId, {
102
+ ...branch,
103
+ head: mutation.nextHead,
104
+ tip: mutation.nextTip,
105
+ headAdvancedAt: mutation.headAdvancedAt ?? branch.headAdvancedAt,
106
+ epoch: mutation.nextEpoch
107
+ });
108
+ }
109
+ async putBranch(branch) {
110
+ this.branches.set(branch.id, cloneBranch(branch));
111
+ }
112
+ async getBranches() {
113
+ return [...this.branches.values()].sort((left, right) => {
114
+ if (left.createdAt !== right.createdAt) {
115
+ return left.createdAt - right.createdAt;
116
+ }
117
+ if (left.id === right.id) {
118
+ return 0;
119
+ }
120
+ return left.id < right.id ? -1 : 1;
121
+ }).map((branch) => cloneBranch(branch));
122
+ }
123
+ async getActiveBranchId() {
124
+ return this.activeBranchId;
125
+ }
126
+ async switchActiveBranch(sourceBranchId, targetBranchId) {
127
+ assertLineage(sourceBranchId !== targetBranchId, "LIN-SWITCH-5 violation: self-switch is not allowed");
128
+ assertLineage(this.activeBranchId === sourceBranchId, "LIN-SWITCH-1 violation: source branch is not active");
129
+ const sourceBranch = this.branches.get(sourceBranchId);
130
+ const targetBranch = this.branches.get(targetBranchId);
131
+ assertLineage(sourceBranch != null, `LIN-SWITCH-3 violation: missing source branch ${sourceBranchId}`);
132
+ assertLineage(targetBranch != null, `LIN-SWITCH-3 violation: missing target branch ${targetBranchId}`);
133
+ this.branches.set(sourceBranchId, {
134
+ ...sourceBranch,
135
+ epoch: sourceBranch.epoch + 1
136
+ });
137
+ this.activeBranchId = targetBranchId;
138
+ }
139
+ async commitPrepared(prepared) {
140
+ const nextBranches = new Map(this.branches);
141
+ let nextActiveBranchId = this.activeBranchId;
142
+ if (prepared.branchChange.kind === "bootstrap") {
143
+ assertLineage(nextBranches.size === 0, "LIN-GENESIS-3 violation: genesis requires an empty branch store");
144
+ assertLineage(
145
+ nextActiveBranchId == null,
146
+ "LIN-GENESIS-3 violation: active branch must be empty before genesis bootstrap"
147
+ );
148
+ assertLineage(
149
+ !nextBranches.has(prepared.branchChange.branch.id),
150
+ `LIN-GENESIS-3 violation: branch ${prepared.branchChange.branch.id} already exists`
151
+ );
152
+ nextBranches.set(prepared.branchChange.branch.id, cloneBranch(prepared.branchChange.branch));
153
+ nextActiveBranchId = prepared.branchChange.activeBranchId;
154
+ } else {
155
+ const branch = nextBranches.get(prepared.branchChange.branchId);
156
+ assertLineage(
157
+ branch != null,
158
+ `LIN-STORE-7 violation: missing branch ${prepared.branchChange.branchId} for prepared commit`
159
+ );
160
+ assertLineage(
161
+ branch.head === prepared.branchChange.expectedHead && branch.tip === prepared.branchChange.expectedTip && branch.epoch === prepared.branchChange.expectedEpoch,
162
+ `LIN-STORE-4 violation: branch ${prepared.branchChange.branchId} CAS mismatch`
163
+ );
164
+ nextBranches.set(prepared.branchChange.branchId, {
165
+ ...branch,
166
+ head: prepared.branchChange.nextHead,
167
+ tip: prepared.branchChange.nextTip,
168
+ headAdvancedAt: prepared.branchChange.headAdvancedAt ?? branch.headAdvancedAt,
169
+ epoch: prepared.branchChange.nextEpoch
170
+ });
171
+ }
172
+ const existingWorld = this.worlds.get(prepared.worldId) ?? null;
173
+ const reused = existingWorld != null;
174
+ if (reused) {
175
+ assertLineage(
176
+ existingWorld.parentWorldId === prepared.world.parentWorldId,
177
+ `LIN-STORE-9 violation: world ${prepared.worldId} exists with a different parent`
178
+ );
179
+ if (prepared.kind === "next") {
180
+ assertLineage(
181
+ this.edges.has(prepared.edge.edgeId),
182
+ `LIN-STORE-9 violation: reuse world ${prepared.worldId} is missing edge ${prepared.edge.edgeId}`
183
+ );
184
+ }
185
+ } else {
186
+ await this.putWorld(prepared.world);
187
+ await this.putSnapshot(prepared.worldId, prepared.terminalSnapshot);
188
+ await this.putHashInput?.(prepared.world.snapshotHash, prepared.hashInput);
189
+ if (prepared.kind === "next") {
190
+ await this.putEdge(prepared.edge);
191
+ }
192
+ }
193
+ await this.putAttempt({
194
+ ...prepared.attempt,
195
+ reused
196
+ });
197
+ this.branches.clear();
198
+ for (const [branchId, branch] of nextBranches) {
199
+ this.branches.set(branchId, cloneBranch(branch));
200
+ }
201
+ this.activeBranchId = nextActiveBranchId;
202
+ }
203
+ listWorlds() {
204
+ return [...this.worlds.values()].map((world) => cloneValue(world));
205
+ }
206
+ listEdges() {
207
+ return [...this.edges.values()].map((edge) => cloneValue(edge));
208
+ }
209
+ snapshotState() {
210
+ return {
211
+ worlds: cloneValue(this.worlds),
212
+ snapshots: cloneValue(this.snapshots),
213
+ hashInputs: cloneValue(this.hashInputs),
214
+ edges: cloneValue(this.edges),
215
+ edgesByWorld: cloneValue(this.edgesByWorld),
216
+ attempts: cloneValue(this.attempts),
217
+ attemptsByWorld: cloneValue(this.attemptsByWorld),
218
+ attemptsByBranch: cloneValue(this.attemptsByBranch),
219
+ branches: cloneValue(this.branches),
220
+ activeBranchId: this.activeBranchId
221
+ };
222
+ }
223
+ restoreState(state) {
224
+ this.worlds.clear();
225
+ for (const [worldId, world] of state.worlds) {
226
+ this.worlds.set(worldId, cloneValue(world));
227
+ }
228
+ this.snapshots.clear();
229
+ for (const [worldId, snapshot] of state.snapshots) {
230
+ this.snapshots.set(worldId, cloneValue(snapshot));
231
+ }
232
+ this.hashInputs.clear();
233
+ for (const [snapshotHash, input] of state.hashInputs) {
234
+ this.hashInputs.set(snapshotHash, cloneValue(input));
235
+ }
236
+ this.edges.clear();
237
+ for (const [edgeId, edge] of state.edges) {
238
+ this.edges.set(edgeId, cloneValue(edge));
239
+ }
240
+ this.edgesByWorld.clear();
241
+ for (const [worldId, edgeIds] of state.edgesByWorld) {
242
+ this.edgesByWorld.set(worldId, new Set(edgeIds));
243
+ }
244
+ this.attempts.clear();
245
+ for (const [attemptId, attempt] of state.attempts) {
246
+ this.attempts.set(attemptId, cloneValue(attempt));
247
+ }
248
+ this.attemptsByWorld.clear();
249
+ for (const [worldId, attemptIds] of state.attemptsByWorld) {
250
+ this.attemptsByWorld.set(worldId, [...attemptIds]);
251
+ }
252
+ this.attemptsByBranch.clear();
253
+ for (const [branchId, attemptIds] of state.attemptsByBranch) {
254
+ this.attemptsByBranch.set(branchId, [...attemptIds]);
255
+ }
256
+ this.branches.clear();
257
+ for (const [branchId, branch] of state.branches) {
258
+ this.branches.set(branchId, cloneBranch(branch));
259
+ }
260
+ this.activeBranchId = state.activeBranchId;
261
+ }
262
+ indexEdge(worldId, edgeId) {
263
+ const current = this.edgesByWorld.get(worldId) ?? /* @__PURE__ */ new Set();
264
+ current.add(edgeId);
265
+ this.edgesByWorld.set(worldId, current);
266
+ }
267
+ indexAttempt(index, key, attemptId) {
268
+ const current = index.get(key) ?? [];
269
+ current.push(attemptId);
270
+ index.set(key, current);
271
+ }
272
+ };
273
+ function createInMemoryLineageStore() {
274
+ return new InMemoryLineageStore();
275
+ }
276
+
19
277
  // src/query.ts
20
278
  function toBranchInfo(entry) {
21
279
  return {
@@ -492,6 +750,10 @@ function createLineageService(store) {
492
750
  }
493
751
 
494
752
  // src/internal.ts
753
+ import {
754
+ DisposedError,
755
+ ManifestoError
756
+ } from "@manifesto-ai/sdk";
495
757
  var LINEAGE_DECORATION = /* @__PURE__ */ Symbol("manifesto-lineage.decoration");
496
758
  function attachLineageDecoration(manifesto, decoration) {
497
759
  Object.defineProperty(manifesto, LINEAGE_DECORATION, {
@@ -636,6 +898,11 @@ function createLineageRuntimeController(kernel, service, config) {
636
898
  await ensureReady();
637
899
  return service.getWorld(worldId);
638
900
  }
901
+ async function getWorldSnapshot(worldId) {
902
+ await ensureReady();
903
+ const snapshot = await service.getSnapshot(worldId);
904
+ return snapshot;
905
+ }
639
906
  async function getLineage() {
640
907
  await ensureReady();
641
908
  return service.getLineage();
@@ -741,6 +1008,7 @@ function createLineageRuntimeController(kernel, service, config) {
741
1008
  ensureReady,
742
1009
  sealIntent,
743
1010
  getWorld,
1011
+ getWorldSnapshot,
744
1012
  getLineage,
745
1013
  getLatestHead,
746
1014
  getHeads,
@@ -758,13 +1026,12 @@ function toError(error) {
758
1026
  }
759
1027
 
760
1028
  export {
761
- assertLineage,
762
- cloneValue,
1029
+ InMemoryLineageStore,
1030
+ createInMemoryLineageStore,
763
1031
  DefaultLineageService,
764
1032
  createLineageService,
765
- LINEAGE_DECORATION,
766
1033
  attachLineageDecoration,
767
1034
  getLineageDecoration,
768
1035
  createLineageRuntimeController
769
1036
  };
770
- //# sourceMappingURL=chunk-STH2THPH.js.map
1037
+ //# sourceMappingURL=chunk-GECVH4P4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/invariants.ts","../src/internal/clone.ts","../src/store/in-memory-lineage-store.ts","../src/query.ts","../src/hash.ts","../src/records.ts","../src/service/lineage-service.ts","../src/internal.ts"],"sourcesContent":["export function assertLineage(condition: unknown, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n","export function cloneValue<T>(value: T): T {\n return structuredClone(value);\n}\n","import { assertLineage } from \"../invariants.js\";\nimport { cloneValue } from \"../internal/clone.js\";\nimport type {\n BranchId,\n LineageStore,\n PersistedBranchEntry,\n PreparedBranchMutation,\n PreparedLineageCommit,\n SealAttempt,\n Snapshot,\n SnapshotHashInput,\n World,\n WorldEdge,\n WorldId,\n} from \"../types.js\";\n\nfunction cloneBranch(branch: PersistedBranchEntry): PersistedBranchEntry {\n return cloneValue(branch);\n}\n\nfunction sortAttempts(attempts: readonly SealAttempt[]): readonly SealAttempt[] {\n return [...attempts]\n .sort((left, right) => {\n if (left.createdAt !== right.createdAt) {\n return left.createdAt - right.createdAt;\n }\n if (left.attemptId === right.attemptId) {\n return 0;\n }\n return left.attemptId < right.attemptId ? -1 : 1;\n })\n .map((attempt) => cloneValue(attempt));\n}\n\ntype InMemoryLineageStoreState = {\n worlds: Map<WorldId, World>;\n snapshots: Map<WorldId, Snapshot>;\n hashInputs: Map<string, SnapshotHashInput>;\n edges: Map<string, WorldEdge>;\n edgesByWorld: Map<WorldId, Set<string>>;\n attempts: Map<string, SealAttempt>;\n attemptsByWorld: Map<WorldId, string[]>;\n attemptsByBranch: Map<BranchId, string[]>;\n branches: Map<BranchId, PersistedBranchEntry>;\n activeBranchId: BranchId | null;\n};\n\nexport class InMemoryLineageStore implements LineageStore {\n private readonly worlds = new Map<WorldId, World>();\n private readonly snapshots = new Map<WorldId, Snapshot>();\n private readonly hashInputs = new Map<string, SnapshotHashInput>();\n private readonly edges = new Map<string, WorldEdge>();\n private readonly edgesByWorld = new Map<WorldId, Set<string>>();\n private readonly attempts = new Map<string, SealAttempt>();\n private readonly attemptsByWorld = new Map<WorldId, string[]>();\n private readonly attemptsByBranch = new Map<BranchId, string[]>();\n private readonly branches = new Map<BranchId, PersistedBranchEntry>();\n private activeBranchId: BranchId | null = null;\n\n async putWorld(world: World): Promise<void> {\n this.worlds.set(world.worldId, cloneValue(world));\n }\n\n async getWorld(worldId: WorldId): Promise<World | null> {\n return cloneValue(this.worlds.get(worldId) ?? null);\n }\n\n async putSnapshot(worldId: WorldId, snapshot: Snapshot): Promise<void> {\n this.snapshots.set(worldId, cloneValue(snapshot));\n }\n\n async getSnapshot(worldId: WorldId): Promise<Snapshot | null> {\n return cloneValue(this.snapshots.get(worldId) ?? null);\n }\n\n async putAttempt(attempt: SealAttempt): Promise<void> {\n this.attempts.set(attempt.attemptId, cloneValue(attempt));\n this.indexAttempt(this.attemptsByWorld, attempt.worldId, attempt.attemptId);\n this.indexAttempt(this.attemptsByBranch, attempt.branchId, attempt.attemptId);\n }\n\n async getAttempts(worldId: WorldId): Promise<readonly SealAttempt[]> {\n const attemptIds = this.attemptsByWorld.get(worldId) ?? [];\n return sortAttempts(\n attemptIds\n .map((attemptId) => this.attempts.get(attemptId))\n .filter((attempt): attempt is SealAttempt => attempt != null)\n );\n }\n\n async getAttemptsByBranch(branchId: BranchId): Promise<readonly SealAttempt[]> {\n const attemptIds = this.attemptsByBranch.get(branchId) ?? [];\n return sortAttempts(\n attemptIds\n .map((attemptId) => this.attempts.get(attemptId))\n .filter((attempt): attempt is SealAttempt => attempt != null)\n );\n }\n\n async putHashInput(snapshotHash: string, input: SnapshotHashInput): Promise<void> {\n this.hashInputs.set(snapshotHash, cloneValue(input));\n }\n\n async getHashInput(snapshotHash: string): Promise<SnapshotHashInput | null> {\n return cloneValue(this.hashInputs.get(snapshotHash) ?? null);\n }\n\n async putEdge(edge: WorldEdge): Promise<void> {\n this.edges.set(edge.edgeId, cloneValue(edge));\n this.indexEdge(edge.from, edge.edgeId);\n this.indexEdge(edge.to, edge.edgeId);\n }\n\n async getEdges(worldId: WorldId): Promise<readonly WorldEdge[]> {\n const edgeIds = [...(this.edgesByWorld.get(worldId) ?? new Set<string>())].sort();\n return edgeIds\n .map((edgeId) => this.edges.get(edgeId))\n .filter((edge): edge is WorldEdge => edge != null)\n .map((edge) => cloneValue(edge));\n }\n\n async getBranchHead(branchId: BranchId): Promise<WorldId | null> {\n return this.branches.get(branchId)?.head ?? null;\n }\n\n async getBranchTip(branchId: BranchId): Promise<WorldId | null> {\n return this.branches.get(branchId)?.tip ?? null;\n }\n\n async getBranchEpoch(branchId: BranchId): Promise<number> {\n const branch = this.branches.get(branchId);\n assertLineage(branch != null, `LIN-EPOCH-6 violation: unknown branch ${branchId}`);\n return branch.epoch;\n }\n\n async mutateBranch(mutation: PreparedBranchMutation): Promise<void> {\n const branch = this.branches.get(mutation.branchId);\n assertLineage(branch != null, `LIN-STORE-4 violation: unknown branch ${mutation.branchId}`);\n assertLineage(\n branch.head === mutation.expectedHead\n && branch.tip === mutation.expectedTip\n && branch.epoch === mutation.expectedEpoch,\n `LIN-STORE-4 violation: branch ${mutation.branchId} CAS mismatch`\n );\n\n this.branches.set(mutation.branchId, {\n ...branch,\n head: mutation.nextHead,\n tip: mutation.nextTip,\n headAdvancedAt: mutation.headAdvancedAt ?? branch.headAdvancedAt,\n epoch: mutation.nextEpoch,\n });\n }\n\n async putBranch(branch: PersistedBranchEntry): Promise<void> {\n this.branches.set(branch.id, cloneBranch(branch));\n }\n\n async getBranches(): Promise<readonly PersistedBranchEntry[]> {\n return [...this.branches.values()]\n .sort((left, right) => {\n if (left.createdAt !== right.createdAt) {\n return left.createdAt - right.createdAt;\n }\n if (left.id === right.id) {\n return 0;\n }\n return left.id < right.id ? -1 : 1;\n })\n .map((branch) => cloneBranch(branch));\n }\n\n async getActiveBranchId(): Promise<BranchId | null> {\n return this.activeBranchId;\n }\n\n async switchActiveBranch(\n sourceBranchId: BranchId,\n targetBranchId: BranchId\n ): Promise<void> {\n assertLineage(sourceBranchId !== targetBranchId, \"LIN-SWITCH-5 violation: self-switch is not allowed\");\n assertLineage(this.activeBranchId === sourceBranchId, \"LIN-SWITCH-1 violation: source branch is not active\");\n\n const sourceBranch = this.branches.get(sourceBranchId);\n const targetBranch = this.branches.get(targetBranchId);\n assertLineage(sourceBranch != null, `LIN-SWITCH-3 violation: missing source branch ${sourceBranchId}`);\n assertLineage(targetBranch != null, `LIN-SWITCH-3 violation: missing target branch ${targetBranchId}`);\n\n this.branches.set(sourceBranchId, {\n ...sourceBranch,\n epoch: sourceBranch.epoch + 1,\n });\n this.activeBranchId = targetBranchId;\n }\n\n async commitPrepared(prepared: PreparedLineageCommit): Promise<void> {\n const nextBranches = new Map(this.branches);\n let nextActiveBranchId = this.activeBranchId;\n\n if (prepared.branchChange.kind === \"bootstrap\") {\n assertLineage(nextBranches.size === 0, \"LIN-GENESIS-3 violation: genesis requires an empty branch store\");\n assertLineage(\n nextActiveBranchId == null,\n \"LIN-GENESIS-3 violation: active branch must be empty before genesis bootstrap\"\n );\n assertLineage(\n !nextBranches.has(prepared.branchChange.branch.id),\n `LIN-GENESIS-3 violation: branch ${prepared.branchChange.branch.id} already exists`\n );\n nextBranches.set(prepared.branchChange.branch.id, cloneBranch(prepared.branchChange.branch));\n nextActiveBranchId = prepared.branchChange.activeBranchId;\n } else {\n const branch = nextBranches.get(prepared.branchChange.branchId);\n assertLineage(\n branch != null,\n `LIN-STORE-7 violation: missing branch ${prepared.branchChange.branchId} for prepared commit`\n );\n assertLineage(\n branch.head === prepared.branchChange.expectedHead\n && branch.tip === prepared.branchChange.expectedTip\n && branch.epoch === prepared.branchChange.expectedEpoch,\n `LIN-STORE-4 violation: branch ${prepared.branchChange.branchId} CAS mismatch`\n );\n nextBranches.set(prepared.branchChange.branchId, {\n ...branch,\n head: prepared.branchChange.nextHead,\n tip: prepared.branchChange.nextTip,\n headAdvancedAt: prepared.branchChange.headAdvancedAt ?? branch.headAdvancedAt,\n epoch: prepared.branchChange.nextEpoch,\n });\n }\n\n const existingWorld = this.worlds.get(prepared.worldId) ?? null;\n const reused = existingWorld != null;\n\n if (reused) {\n assertLineage(\n existingWorld.parentWorldId === prepared.world.parentWorldId,\n `LIN-STORE-9 violation: world ${prepared.worldId} exists with a different parent`\n );\n if (prepared.kind === \"next\") {\n assertLineage(\n this.edges.has(prepared.edge.edgeId),\n `LIN-STORE-9 violation: reuse world ${prepared.worldId} is missing edge ${prepared.edge.edgeId}`\n );\n }\n } else {\n await this.putWorld(prepared.world);\n await this.putSnapshot(prepared.worldId, prepared.terminalSnapshot);\n await this.putHashInput?.(prepared.world.snapshotHash, prepared.hashInput);\n\n if (prepared.kind === \"next\") {\n await this.putEdge(prepared.edge);\n }\n }\n\n await this.putAttempt({\n ...prepared.attempt,\n reused,\n });\n\n this.branches.clear();\n for (const [branchId, branch] of nextBranches) {\n this.branches.set(branchId, cloneBranch(branch));\n }\n this.activeBranchId = nextActiveBranchId;\n }\n\n listWorlds(): readonly World[] {\n return [...this.worlds.values()].map((world) => cloneValue(world));\n }\n\n listEdges(): readonly WorldEdge[] {\n return [...this.edges.values()].map((edge) => cloneValue(edge));\n }\n\n snapshotState(): InMemoryLineageStoreState {\n return {\n worlds: cloneValue(this.worlds),\n snapshots: cloneValue(this.snapshots),\n hashInputs: cloneValue(this.hashInputs),\n edges: cloneValue(this.edges),\n edgesByWorld: cloneValue(this.edgesByWorld),\n attempts: cloneValue(this.attempts),\n attemptsByWorld: cloneValue(this.attemptsByWorld),\n attemptsByBranch: cloneValue(this.attemptsByBranch),\n branches: cloneValue(this.branches),\n activeBranchId: this.activeBranchId,\n };\n }\n\n restoreState(state: InMemoryLineageStoreState): void {\n this.worlds.clear();\n for (const [worldId, world] of state.worlds) {\n this.worlds.set(worldId, cloneValue(world));\n }\n\n this.snapshots.clear();\n for (const [worldId, snapshot] of state.snapshots) {\n this.snapshots.set(worldId, cloneValue(snapshot));\n }\n\n this.hashInputs.clear();\n for (const [snapshotHash, input] of state.hashInputs) {\n this.hashInputs.set(snapshotHash, cloneValue(input));\n }\n\n this.edges.clear();\n for (const [edgeId, edge] of state.edges) {\n this.edges.set(edgeId, cloneValue(edge));\n }\n\n this.edgesByWorld.clear();\n for (const [worldId, edgeIds] of state.edgesByWorld) {\n this.edgesByWorld.set(worldId, new Set(edgeIds));\n }\n\n this.attempts.clear();\n for (const [attemptId, attempt] of state.attempts) {\n this.attempts.set(attemptId, cloneValue(attempt));\n }\n\n this.attemptsByWorld.clear();\n for (const [worldId, attemptIds] of state.attemptsByWorld) {\n this.attemptsByWorld.set(worldId, [...attemptIds]);\n }\n\n this.attemptsByBranch.clear();\n for (const [branchId, attemptIds] of state.attemptsByBranch) {\n this.attemptsByBranch.set(branchId, [...attemptIds]);\n }\n\n this.branches.clear();\n for (const [branchId, branch] of state.branches) {\n this.branches.set(branchId, cloneBranch(branch));\n }\n\n this.activeBranchId = state.activeBranchId;\n }\n\n private indexEdge(worldId: WorldId, edgeId: string): void {\n const current = this.edgesByWorld.get(worldId) ?? new Set<string>();\n current.add(edgeId);\n this.edgesByWorld.set(worldId, current);\n }\n\n private indexAttempt(index: Map<string, string[]>, key: string, attemptId: string): void {\n const current = index.get(key) ?? [];\n current.push(attemptId);\n index.set(key, current);\n }\n}\n\nexport function createInMemoryLineageStore(): InMemoryLineageStore {\n return new InMemoryLineageStore();\n}\n","import { assertLineage } from \"./invariants.js\";\nimport { cloneValue } from \"./internal/clone.js\";\nimport type {\n BranchInfo,\n LineageStore,\n PersistedBranchEntry,\n Snapshot,\n World,\n WorldEdge,\n WorldHead,\n WorldId,\n WorldLineage,\n} from \"./types.js\";\n\ntype EnumerableLineageStore = LineageStore & {\n listWorlds?(): readonly World[];\n listEdges?(): readonly WorldEdge[];\n};\n\nexport function toBranchInfo(entry: PersistedBranchEntry): BranchInfo {\n return {\n id: entry.id,\n name: entry.name,\n head: entry.head,\n tip: entry.tip,\n headAdvancedAt: entry.headAdvancedAt,\n epoch: entry.epoch,\n schemaHash: entry.schemaHash,\n createdAt: entry.createdAt,\n };\n}\n\nexport function toWorldHead(branch: PersistedBranchEntry, world: World): WorldHead {\n return {\n worldId: world.worldId,\n branchId: branch.id,\n branchName: branch.name,\n createdAt: branch.headAdvancedAt,\n schemaHash: branch.schemaHash,\n };\n}\n\nexport function getBranchById(\n branches: readonly PersistedBranchEntry[],\n branchId: string\n): PersistedBranchEntry | null {\n return branches.find((branch) => branch.id === branchId) ?? null;\n}\n\nexport async function getHeadsFromStore(\n store: LineageStore\n): Promise<readonly WorldHead[]> {\n const branches = await store.getBranches();\n\n return Promise.all(branches.map(async (branch) => {\n const world = await store.getWorld(branch.head);\n assertLineage(world != null, `LIN-HEAD-6 violation: missing head world ${branch.head} for branch ${branch.id}`);\n assertLineage(\n world.terminalStatus === \"completed\",\n `LIN-HEAD-3 violation: head world ${branch.head} for branch ${branch.id} must be completed`\n );\n return toWorldHead(branch, world);\n }));\n}\n\nexport function selectLatestHead(heads: readonly WorldHead[]): WorldHead | null {\n if (heads.length === 0) {\n return null;\n }\n\n const sorted = [...heads].sort((left, right) => {\n if (left.createdAt !== right.createdAt) {\n return right.createdAt - left.createdAt;\n }\n if (left.worldId !== right.worldId) {\n return left.worldId < right.worldId ? -1 : 1;\n }\n if (left.branchId === right.branchId) {\n return 0;\n }\n return left.branchId < right.branchId ? -1 : 1;\n });\n\n return sorted[0];\n}\n\nfunction normalizePlatformData(data: Record<string, unknown> | null | undefined): Record<string, unknown> {\n const normalized: Record<string, unknown> = {};\n const source = data ?? {};\n\n for (const [key, value] of Object.entries(source)) {\n if (!key.startsWith(\"$\")) {\n normalized[key] = cloneValue(value);\n continue;\n }\n\n normalized[key] = {};\n }\n\n normalized.$host = {};\n normalized.$mel = { guards: { intent: {} } };\n return normalized;\n}\n\nexport async function restoreSnapshot(\n store: LineageStore,\n worldId: WorldId\n): Promise<Snapshot> {\n const snapshot = await store.getSnapshot(worldId);\n assertLineage(snapshot != null, `LIN-RESUME-2 violation: missing snapshot for world ${worldId}`);\n\n return {\n data: normalizePlatformData(snapshot.data as Record<string, unknown>),\n computed: cloneValue(snapshot.computed),\n system: {\n status: snapshot.system.status,\n lastError: cloneValue(snapshot.system.lastError),\n pendingRequirements: cloneValue(snapshot.system.pendingRequirements),\n currentAction: null,\n },\n input: null,\n meta: {\n version: snapshot.meta.version,\n timestamp: 0,\n randomSeed: \"\",\n schemaHash: snapshot.meta.schemaHash,\n },\n };\n}\n\nexport async function buildWorldLineage(store: LineageStore): Promise<WorldLineage> {\n const enumerable = store as EnumerableLineageStore;\n const worlds = enumerable.listWorlds?.() ?? await collectWorldsFromBranches(store);\n const edges = enumerable.listEdges?.() ?? await collectEdgesFromWorlds(store, worlds);\n\n assertLineage(worlds.length > 0, \"LIN-RESUME-1 violation: lineage is empty\");\n\n const incoming = new Set(edges.map((edge) => edge.to));\n const genesisCandidates = worlds\n .filter((world) => !incoming.has(world.worldId))\n .sort((left, right) => {\n if (left.worldId === right.worldId) {\n return 0;\n }\n return left.worldId < right.worldId ? -1 : 1;\n });\n\n const genesis = genesisCandidates[0]?.worldId ?? worlds[0].worldId;\n\n return {\n genesis,\n worlds: new Map(worlds.map((world) => [world.worldId, cloneValue(world)])),\n edges: new Map(edges.map((edge) => [edge.edgeId, cloneValue(edge)])),\n };\n}\n\nasync function collectWorldsFromBranches(store: LineageStore): Promise<readonly World[]> {\n const worlds = new Map<WorldId, World>();\n const queue = (await store.getBranches()).flatMap((branch) => [branch.head, branch.tip]);\n\n while (queue.length > 0) {\n const nextWorldId = queue.pop()!;\n if (worlds.has(nextWorldId)) {\n continue;\n }\n\n const world = await store.getWorld(nextWorldId);\n if (world == null) {\n continue;\n }\n worlds.set(nextWorldId, world);\n\n if (world.parentWorldId != null && !worlds.has(world.parentWorldId)) {\n queue.push(world.parentWorldId);\n }\n }\n\n return [...worlds.values()];\n}\n\nasync function collectEdgesFromWorlds(\n store: LineageStore,\n worlds: readonly World[]\n): Promise<readonly WorldEdge[]> {\n const edges = new Map<string, WorldEdge>();\n\n for (const world of worlds) {\n for (const edge of await store.getEdges(world.worldId)) {\n edges.set(edge.edgeId, edge);\n }\n }\n\n return [...edges.values()];\n}\n","import type { ErrorValue, Requirement, Snapshot } from \"@manifesto-ai/core\";\nimport { sha256Sync, toJcs } from \"@manifesto-ai/core\";\nimport { assertLineage } from \"./invariants.js\";\nimport type {\n CurrentErrorSignature,\n SnapshotHashInput,\n TerminalStatus,\n WorldId,\n} from \"./types.js\";\n\nconst PLATFORM_NAMESPACE_PREFIX = \"$\";\n\nexport function computeHash(value: unknown): string {\n return sha256Sync(toJcs(value));\n}\n\nexport function isPlatformNamespace(key: string): boolean {\n return key.startsWith(PLATFORM_NAMESPACE_PREFIX);\n}\n\nexport function stripPlatformNamespaces(data: Record<string, unknown> | null | undefined): Record<string, unknown> {\n if (data == null) {\n return {};\n }\n\n const keys = Object.keys(data);\n if (!keys.some(isPlatformNamespace)) {\n return data;\n }\n\n const stripped: Record<string, unknown> = {};\n for (const key of keys) {\n if (!isPlatformNamespace(key)) {\n stripped[key] = data[key];\n }\n }\n return stripped;\n}\n\nexport function deriveTerminalStatus(snapshot: Snapshot): TerminalStatus {\n if (snapshot.system.pendingRequirements.length > 0) {\n return \"failed\";\n }\n if (snapshot.system.lastError != null) {\n return \"failed\";\n }\n return \"completed\";\n}\n\nfunction normalizeDeterministicValue(value: unknown): unknown {\n if (value === null) {\n return null;\n }\n\n switch (typeof value) {\n case \"string\":\n case \"boolean\":\n return value;\n case \"number\":\n return Number.isFinite(value) ? value : null;\n case \"bigint\":\n case \"function\":\n case \"symbol\":\n case \"undefined\":\n return undefined;\n case \"object\":\n if (Array.isArray(value)) {\n return value\n .map((item) => normalizeDeterministicValue(item))\n .filter((item) => item !== undefined);\n }\n\n return normalizeContext(value as Record<string, unknown>);\n default:\n return undefined;\n }\n}\n\nexport function normalizeContext(ctx: Record<string, unknown>): Record<string, unknown> | undefined {\n const normalized: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(ctx)) {\n const nextValue = normalizeDeterministicValue(value);\n if (nextValue !== undefined) {\n normalized[key] = nextValue;\n }\n }\n\n return Object.keys(normalized).length > 0 ? normalized : undefined;\n}\n\nexport function toCurrentErrorSignature(error: ErrorValue): CurrentErrorSignature {\n return {\n code: error.code,\n source: {\n actionId: error.source.actionId,\n nodePath: error.source.nodePath,\n },\n };\n}\n\nexport function computePendingDigest(pendingRequirements: readonly Requirement[]): string {\n if (pendingRequirements.length === 0) {\n return \"empty\";\n }\n\n const pendingIds = pendingRequirements.map((requirement) => requirement.id).sort();\n return computeHash({ pendingIds });\n}\n\nexport function createSnapshotHashInput(snapshot: Snapshot): SnapshotHashInput {\n return {\n data: stripPlatformNamespaces(snapshot.data as Record<string, unknown>),\n system: {\n terminalStatus: deriveTerminalStatus(snapshot),\n currentError: snapshot.system.lastError == null\n ? null\n : toCurrentErrorSignature(snapshot.system.lastError),\n pendingDigest: computePendingDigest(snapshot.system.pendingRequirements),\n },\n };\n}\n\nexport function computeSnapshotHash(snapshot: Snapshot): string {\n return computeHash(createSnapshotHashInput(snapshot));\n}\n\nexport function computeWorldId(\n schemaHash: string,\n snapshotHash: string,\n parentWorldId: WorldId | null\n): WorldId {\n return computeHash({ schemaHash, snapshotHash, parentWorldId });\n}\n\nexport function computeBranchId(branchName: string, worldId: WorldId): string {\n return computeHash({\n kind: \"genesis-branch\",\n branchName,\n worldId,\n });\n}\n\nexport function computeEdgeId(from: WorldId, to: WorldId): string {\n assertLineage(from !== to, \"LIN-COLLISION-2 violation: edge must not be a self-loop\");\n return computeHash({ from, to });\n}\n","import { assertLineage } from \"./invariants.js\";\nimport {\n computeBranchId,\n computeEdgeId,\n computeHash,\n computeSnapshotHash,\n computeWorldId,\n createSnapshotHashInput,\n deriveTerminalStatus,\n} from \"./hash.js\";\nimport type {\n BranchId,\n PersistedBranchEntry,\n SealAttempt,\n SealGenesisInput,\n SealNextInput,\n Snapshot,\n SnapshotHashInput,\n World,\n WorldEdge,\n WorldId,\n} from \"./types.js\";\n\nexport interface WorldRecordResult {\n readonly world: World;\n readonly hashInput: SnapshotHashInput;\n readonly worldId: WorldId;\n}\n\nexport function createWorldRecord(\n schemaHash: string,\n terminalSnapshot: Snapshot,\n parentWorldId: WorldId | null\n): WorldRecordResult {\n assertLineage(\n schemaHash === terminalSnapshot.meta.schemaHash,\n `LIN-SCHEMA-1 violation: provided schemaHash (${schemaHash}) does not match snapshot.meta.schemaHash (${terminalSnapshot.meta.schemaHash})`\n );\n\n const terminalStatus = deriveTerminalStatus(terminalSnapshot);\n const hashInput = createSnapshotHashInput(terminalSnapshot);\n const snapshotHash = computeSnapshotHash(terminalSnapshot);\n const worldId = computeWorldId(schemaHash, snapshotHash, parentWorldId);\n\n return {\n worldId,\n hashInput,\n world: {\n worldId,\n schemaHash,\n snapshotHash,\n parentWorldId,\n terminalStatus,\n },\n };\n}\n\nexport function createWorldEdge(from: WorldId, to: WorldId): WorldEdge {\n return {\n edgeId: computeEdgeId(from, to),\n from,\n to,\n };\n}\n\nexport function createGenesisBranchEntry(input: SealGenesisInput, worldId: WorldId): PersistedBranchEntry {\n const branchName = input.branchName ?? \"main\";\n const branchId: BranchId = computeBranchId(branchName, worldId);\n\n return {\n id: branchId,\n name: branchName,\n head: worldId,\n tip: worldId,\n headAdvancedAt: input.createdAt,\n epoch: 0,\n schemaHash: input.schemaHash,\n createdAt: input.createdAt,\n };\n}\n\nexport function createSealGenesisAttempt(\n branchId: BranchId,\n worldId: WorldId,\n input: SealGenesisInput\n): SealAttempt {\n return {\n attemptId: computeHash({ worldId, branchId, createdAt: input.createdAt }),\n worldId,\n branchId,\n baseWorldId: null,\n parentWorldId: null,\n proposalRef: input.proposalRef,\n createdAt: input.createdAt,\n traceRef: input.traceRef,\n reused: false,\n };\n}\n\nexport function createSealNextAttempt(\n branchId: BranchId,\n worldId: WorldId,\n parentWorldId: WorldId,\n input: SealNextInput\n): SealAttempt {\n return {\n attemptId: computeHash({ worldId, branchId, createdAt: input.createdAt }),\n worldId,\n branchId,\n baseWorldId: input.baseWorldId,\n parentWorldId,\n proposalRef: input.proposalRef,\n decisionRef: input.decisionRef,\n createdAt: input.createdAt,\n traceRef: input.traceRef,\n patchDelta: input.patchDelta,\n reused: false,\n };\n}\n","import { assertLineage } from \"../invariants.js\";\nimport {\n buildWorldLineage,\n getBranchById,\n getHeadsFromStore,\n restoreSnapshot,\n selectLatestHead,\n toBranchInfo,\n} from \"../query.js\";\nimport {\n createGenesisBranchEntry,\n createSealGenesisAttempt,\n createSealNextAttempt,\n createWorldEdge,\n createWorldRecord,\n} from \"../records.js\";\nimport { computeHash } from \"../hash.js\";\nimport type {\n BranchId,\n BranchInfo,\n BranchSwitchResult,\n LineageService,\n LineageStore,\n PersistedBranchEntry,\n SealGenesisInput,\n SealNextInput,\n Snapshot,\n World,\n WorldHead,\n WorldId,\n WorldLineage,\n} from \"../types.js\";\n\nexport class DefaultLineageService implements LineageService {\n public constructor(private readonly store: LineageStore) {}\n\n async prepareSealGenesis(input: SealGenesisInput) {\n assertLineage(\n (await this.store.getBranches()).length === 0,\n \"LIN-GENESIS-3 violation: genesis requires empty branch state\"\n );\n\n const record = createWorldRecord(\n input.schemaHash,\n input.terminalSnapshot,\n null\n );\n\n assertLineage(\n record.world.terminalStatus === \"completed\",\n \"LIN-GENESIS-1 violation: genesis snapshot must derive terminalStatus 'completed'\"\n );\n assertLineage(\n (await this.store.getWorld(record.worldId)) == null,\n `LIN-COLLISION-3 violation: genesis world ${record.worldId} already exists`\n );\n\n const branch = createGenesisBranchEntry(input, record.worldId);\n\n return {\n kind: \"genesis\" as const,\n branchId: branch.id,\n worldId: record.worldId,\n world: record.world,\n terminalSnapshot: input.terminalSnapshot,\n hashInput: record.hashInput,\n attempt: createSealGenesisAttempt(branch.id, record.worldId, input),\n terminalStatus: \"completed\" as const,\n edge: null,\n branchChange: {\n kind: \"bootstrap\" as const,\n branch,\n activeBranchId: branch.id,\n },\n };\n }\n\n async prepareSealNext(input: SealNextInput) {\n const branchHead = await this.store.getBranchHead(input.branchId);\n assertLineage(branchHead != null, `LIN-BRANCH-SEAL-2 violation: unknown branch ${input.branchId}`);\n assertLineage(\n branchHead === input.baseWorldId,\n `LIN-BRANCH-SEAL-2 violation: branch ${input.branchId} head ${branchHead} does not match baseWorldId ${input.baseWorldId}`\n );\n\n const branchTip = await this.store.getBranchTip(input.branchId);\n assertLineage(branchTip != null, `LIN-EPOCH-5 violation: branch ${input.branchId} tip is not set`);\n\n const baseWorld = await this.store.getWorld(input.baseWorldId);\n assertLineage(baseWorld != null, `LIN-BASE-1 violation: base world ${input.baseWorldId} does not exist`);\n assertLineage(\n baseWorld.schemaHash === input.schemaHash,\n `LIN-BASE-4 violation: base world schemaHash ${baseWorld.schemaHash} does not match input ${input.schemaHash}`\n );\n assertLineage(\n baseWorld.terminalStatus !== \"failed\",\n `LIN-BASE-3 violation: failed base world ${input.baseWorldId} cannot be used as base`\n );\n\n const baseSnapshot = await this.store.getSnapshot(input.baseWorldId);\n assertLineage(baseSnapshot != null, `LIN-PERSIST-BASE-1 violation: missing snapshot for base world ${input.baseWorldId}`);\n assertLineage(\n baseSnapshot.system.pendingRequirements.length === 0,\n `LIN-BASE-2 violation: base world ${input.baseWorldId} has pending requirements`\n );\n\n if (input.patchDelta != null) {\n assertLineage(\n input.patchDelta._patchFormat === 2,\n \"LIN-PERSIST-PATCH-2 violation: only _patchFormat: 2 is supported\"\n );\n }\n\n const record = createWorldRecord(\n input.schemaHash,\n input.terminalSnapshot,\n branchTip\n );\n\n const expectedEpoch = await this.store.getBranchEpoch(input.branchId);\n const headAdvanced = record.world.terminalStatus === \"completed\";\n const forkCreated = (await this.store.getEdges(branchTip))\n .some((candidate) => candidate.from === branchTip);\n const edge = createWorldEdge(branchTip, record.worldId);\n\n return {\n kind: \"next\" as const,\n branchId: input.branchId,\n worldId: record.worldId,\n world: record.world,\n terminalSnapshot: input.terminalSnapshot,\n hashInput: record.hashInput,\n attempt: createSealNextAttempt(input.branchId, record.worldId, branchTip, input),\n terminalStatus: record.world.terminalStatus,\n edge,\n forkCreated,\n branchChange: {\n kind: \"advance\" as const,\n branchId: input.branchId,\n expectedHead: input.baseWorldId,\n nextHead: headAdvanced ? record.worldId : input.baseWorldId,\n headAdvanced,\n expectedTip: branchTip,\n nextTip: record.worldId,\n headAdvancedAt: headAdvanced ? input.createdAt : null,\n expectedEpoch,\n nextEpoch: headAdvanced ? expectedEpoch + 1 : expectedEpoch,\n },\n };\n }\n\n async commitPrepared(\n prepared: Parameters<LineageService[\"commitPrepared\"]>[0]\n ): Promise<void> {\n await this.store.commitPrepared(prepared);\n }\n\n async createBranch(name: string, headWorldId: WorldId): Promise<BranchId> {\n const world = await this.store.getWorld(headWorldId);\n assertLineage(world != null, `LIN-BRANCH-CREATE-1 violation: head world ${headWorldId} does not exist`);\n assertLineage(\n world.terminalStatus === \"completed\",\n `LIN-BRANCH-CREATE-2 violation: head world ${headWorldId} must be completed`\n );\n\n const branches = await this.store.getBranches();\n const branchId = computeHash({ kind: \"branch\", name, headWorldId, ordinal: branches.length });\n const branchCreatedAt = branches.reduce((latest, branch) => {\n return Math.max(latest, branch.createdAt, branch.headAdvancedAt);\n }, 0) + 1;\n\n const branch: PersistedBranchEntry = {\n id: branchId,\n name,\n head: headWorldId,\n tip: headWorldId,\n headAdvancedAt: branchCreatedAt,\n epoch: 0,\n schemaHash: world.schemaHash,\n createdAt: branchCreatedAt,\n };\n\n await this.store.putBranch(branch);\n return branchId;\n }\n\n async getBranch(branchId: BranchId): Promise<BranchInfo | null> {\n const branch = getBranchById(await this.store.getBranches(), branchId);\n return branch ? toBranchInfo(branch) : null;\n }\n\n async getBranches(): Promise<readonly BranchInfo[]> {\n return (await this.store.getBranches()).map(toBranchInfo);\n }\n\n async getActiveBranch(): Promise<BranchInfo> {\n const activeBranchId = await this.store.getActiveBranchId();\n assertLineage(activeBranchId != null, \"LIN-BRANCH-PERSIST-3 violation: active branch is not set\");\n const branch = await this.getBranch(activeBranchId);\n assertLineage(branch != null, `LIN-BRANCH-PERSIST-1 violation: missing active branch ${activeBranchId}`);\n return branch;\n }\n\n async switchActiveBranch(\n targetBranchId: BranchId\n ): Promise<BranchSwitchResult> {\n const previousBranchId = await this.store.getActiveBranchId();\n assertLineage(previousBranchId != null, \"LIN-SWITCH-1 violation: active branch is not set\");\n await this.store.switchActiveBranch(previousBranchId, targetBranchId);\n return {\n previousBranchId,\n targetBranchId,\n sourceBranchEpochAfter: await this.store.getBranchEpoch(previousBranchId),\n };\n }\n\n async getWorld(worldId: WorldId): Promise<World | null> {\n return this.store.getWorld(worldId);\n }\n\n async getSnapshot(worldId: WorldId): Promise<Snapshot | null> {\n return this.store.getSnapshot(worldId);\n }\n\n async getAttempts(worldId: WorldId) {\n return this.store.getAttempts(worldId);\n }\n\n async getAttemptsByBranch(branchId: BranchId) {\n return this.store.getAttemptsByBranch(branchId);\n }\n\n async getLineage(): Promise<WorldLineage> {\n return buildWorldLineage(this.store);\n }\n\n async getHeads(): Promise<readonly WorldHead[]> {\n return getHeadsFromStore(this.store);\n }\n\n async getLatestHead(): Promise<WorldHead | null> {\n return selectLatestHead(await this.getHeads());\n }\n\n async restore(worldId: WorldId): Promise<Snapshot> {\n return restoreSnapshot(this.store, worldId);\n }\n}\n\nexport function createLineageService(store: LineageStore): LineageService {\n return new DefaultLineageService(store);\n}\n","import {\n DisposedError,\n ManifestoError,\n type BaseLaws,\n type ComposableManifesto,\n type LineageLaws,\n type ManifestoDomainShape,\n type Snapshot,\n type TypedIntent,\n} from \"@manifesto-ai/sdk\";\nimport type { HostDispatchOptions, RuntimeKernel } from \"@manifesto-ai/sdk/provider\";\n\nimport type { LineageConfig } from \"./runtime-types.js\";\nimport type {\n BranchId,\n BranchInfo,\n BranchSwitchResult,\n LineageService,\n PreparedNextCommit,\n World,\n WorldHead,\n WorldId,\n WorldLineage,\n} from \"./types.js\";\n\nexport type {\n ArtifactRef,\n BranchId,\n BranchInfo,\n BranchSwitchResult,\n LineageService,\n LineageStore,\n PreparedLineageCommit,\n SealAttempt,\n World,\n WorldId,\n} from \"./types.js\";\nexport {\n DefaultLineageService,\n createLineageService,\n} from \"./service/lineage-service.js\";\n\nexport const LINEAGE_DECORATION = Symbol(\"manifesto-lineage.decoration\");\n\nexport type ResolvedLineageConfig = LineageConfig & {\n readonly service: LineageService;\n};\n\nexport type LineageDecoration = {\n readonly service: LineageService;\n readonly config: ResolvedLineageConfig;\n};\n\nexport type InternalLineageComposableManifesto<\n T extends ManifestoDomainShape,\n Laws extends BaseLaws,\n> = ComposableManifesto<T, Laws & LineageLaws> & {\n readonly [LINEAGE_DECORATION]: LineageDecoration;\n};\n\nexport type SealIntentOptions = {\n readonly proposalRef?: string;\n readonly decisionRef?: string;\n readonly executionKey?: HostDispatchOptions[\"key\"];\n readonly publishOnCompleted?: boolean;\n readonly assumeEnqueued?: boolean;\n};\n\nexport type SealedIntentResult<T extends ManifestoDomainShape> = {\n readonly intent: TypedIntent<T>;\n readonly hostResult: Awaited<ReturnType<RuntimeKernel<T>[\"executeHost\"]>>;\n readonly preparedCommit: PreparedNextCommit;\n readonly publishedSnapshot?: Snapshot<T[\"state\"]>;\n};\n\nexport interface LineageRuntimeController<T extends ManifestoDomainShape> {\n ensureReady(): Promise<void>;\n sealIntent(\n intent: TypedIntent<T>,\n options?: SealIntentOptions,\n ): Promise<SealedIntentResult<T>>;\n getWorld(worldId: WorldId): Promise<World | null>;\n getWorldSnapshot(worldId: WorldId): Promise<Snapshot<T[\"state\"]> | null>;\n getLineage(): Promise<WorldLineage>;\n getLatestHead(): Promise<WorldHead | null>;\n getHeads(): Promise<readonly WorldHead[]>;\n getBranches(): Promise<readonly BranchInfo[]>;\n getActiveBranch(): Promise<BranchInfo>;\n getCurrentBranchId(): Promise<BranchId>;\n getCurrentCompletedWorldId(): Promise<WorldId>;\n restore(worldId: WorldId): Promise<void>;\n switchActiveBranch(branchId: BranchId): Promise<BranchSwitchResult>;\n createBranch(name: string, fromWorldId?: WorldId): Promise<BranchId>;\n}\n\nexport function attachLineageDecoration<\n T extends ManifestoDomainShape,\n Laws extends BaseLaws,\n>(\n manifesto: ComposableManifesto<T, Laws & LineageLaws>,\n decoration: LineageDecoration,\n): InternalLineageComposableManifesto<T, Laws> {\n Object.defineProperty(manifesto, LINEAGE_DECORATION, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: decoration,\n });\n\n return manifesto as InternalLineageComposableManifesto<T, Laws>;\n}\n\nexport function getLineageDecoration<\n T extends ManifestoDomainShape,\n Laws extends BaseLaws,\n>(\n manifesto: ComposableManifesto<T, Laws>,\n): LineageDecoration | null {\n const internal = manifesto as Partial<InternalLineageComposableManifesto<T, Laws>>;\n return internal[LINEAGE_DECORATION] ?? null;\n}\n\nexport function createLineageRuntimeController<T extends ManifestoDomainShape>(\n kernel: RuntimeKernel<T>,\n service: LineageService,\n config: ResolvedLineageConfig,\n): LineageRuntimeController<T> {\n let readiness: Promise<void> | null = null;\n let currentBranchId: string | null = null;\n let currentCompletedWorldId: WorldId | null = null;\n\n async function ensureReady(): Promise<void> {\n if (readiness) {\n return readiness;\n }\n\n readiness = bootstrapLineage().catch((error) => {\n readiness = null;\n throw error;\n });\n\n return readiness;\n }\n\n async function bootstrapLineage(): Promise<void> {\n const branches = await service.getBranches();\n if (branches.length === 0) {\n if (config.branchId) {\n throw new ManifestoError(\n \"LINEAGE_BRANCH_NOT_FOUND\",\n `Configured branch \"${config.branchId}\" does not exist in the lineage store`,\n );\n }\n\n const genesisSnapshot = kernel.getVisibleCoreSnapshot();\n const prepared = await service.prepareSealGenesis({\n schemaHash: kernel.schema.hash,\n terminalSnapshot: genesisSnapshot,\n createdAt: genesisSnapshot.meta.timestamp,\n });\n await service.commitPrepared(prepared);\n currentBranchId = prepared.branchId;\n currentCompletedWorldId = prepared.worldId;\n return;\n }\n\n const branch = await bindInitialBranch(config.branchId);\n currentBranchId = branch.id;\n currentCompletedWorldId = branch.head;\n const restored = await service.restore(branch.head);\n kernel.setVisibleSnapshot(restored, { notify: false });\n }\n\n async function bindInitialBranch(branchId?: string): Promise<BranchInfo> {\n if (!branchId) {\n return service.getActiveBranch();\n }\n\n const branch = await service.getBranch(branchId);\n if (!branch) {\n throw new ManifestoError(\n \"LINEAGE_BRANCH_NOT_FOUND\",\n `Configured branch \"${branchId}\" does not exist in the lineage store`,\n );\n }\n\n const activeBranch = await service.getActiveBranch();\n if (activeBranch.id !== branch.id) {\n await service.switchActiveBranch(branch.id);\n }\n\n return branch;\n }\n\n async function sealIntent(\n intent: TypedIntent<T>,\n options?: SealIntentOptions,\n ): Promise<SealedIntentResult<T>> {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n const enrichedIntent = kernel.ensureIntentId(intent);\n\n const runSeal = async () => {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await ensureReady();\n\n if (!kernel.isActionAvailable(enrichedIntent.type as keyof T[\"actions\"])) {\n return kernel.rejectUnavailable(enrichedIntent);\n }\n\n let result: Awaited<ReturnType<RuntimeKernel<T>[\"executeHost\"]>>;\n try {\n result = await kernel.executeHost(\n enrichedIntent,\n options?.executionKey !== undefined\n ? { key: options.executionKey }\n : undefined,\n );\n } catch (error) {\n kernel.restoreVisibleSnapshot();\n throw toError(error);\n }\n\n if (!currentBranchId || !currentCompletedWorldId) {\n kernel.restoreVisibleSnapshot();\n throw new ManifestoError(\n \"LINEAGE_STATE_ERROR\",\n \"Lineage runtime has no active branch continuity after bootstrap\",\n );\n }\n\n let prepared: PreparedNextCommit;\n try {\n prepared = await service.prepareSealNext({\n schemaHash: kernel.schema.hash,\n baseWorldId: currentCompletedWorldId,\n branchId: currentBranchId,\n terminalSnapshot: result.snapshot,\n createdAt: result.snapshot.meta.timestamp,\n ...(options?.proposalRef ? { proposalRef: options.proposalRef } : {}),\n ...(options?.decisionRef ? { decisionRef: options.decisionRef } : {}),\n });\n await service.commitPrepared(prepared);\n } catch (error) {\n kernel.restoreVisibleSnapshot();\n throw toError(error);\n }\n\n if (prepared.branchChange.headAdvanced) {\n currentCompletedWorldId = prepared.worldId;\n }\n\n if (prepared.branchChange.headAdvanced && options?.publishOnCompleted !== false) {\n return {\n intent: enrichedIntent,\n hostResult: result,\n preparedCommit: prepared,\n publishedSnapshot: kernel.setVisibleSnapshot(result.snapshot),\n };\n }\n\n kernel.restoreVisibleSnapshot();\n return {\n intent: enrichedIntent,\n hostResult: result,\n preparedCommit: prepared,\n };\n };\n\n if (options?.assumeEnqueued) {\n return runSeal();\n }\n\n return kernel.enqueue(runSeal);\n }\n\n async function getWorld(worldId: WorldId): Promise<World | null> {\n await ensureReady();\n return service.getWorld(worldId);\n }\n\n async function getWorldSnapshot(worldId: WorldId): Promise<Snapshot<T[\"state\"]> | null> {\n await ensureReady();\n const snapshot = await service.getSnapshot(worldId);\n return snapshot as Snapshot<T[\"state\"]> | null;\n }\n\n async function getLineage(): Promise<WorldLineage> {\n await ensureReady();\n return service.getLineage();\n }\n\n async function getLatestHead(): Promise<WorldHead | null> {\n await ensureReady();\n return service.getLatestHead();\n }\n\n async function getHeads(): Promise<readonly WorldHead[]> {\n await ensureReady();\n return service.getHeads();\n }\n\n async function getBranches(): Promise<readonly BranchInfo[]> {\n await ensureReady();\n return service.getBranches();\n }\n\n async function getActiveBranch(): Promise<BranchInfo> {\n await ensureReady();\n if (currentBranchId) {\n const branch = await service.getBranch(currentBranchId);\n if (branch) {\n return branch;\n }\n }\n return service.getActiveBranch();\n }\n\n async function getCurrentBranchId(): Promise<BranchId> {\n return (await getActiveBranch()).id;\n }\n\n async function getCurrentCompletedWorldId(): Promise<WorldId> {\n await ensureReady();\n if (!currentCompletedWorldId) {\n throw new ManifestoError(\n \"LINEAGE_STATE_ERROR\",\n \"Lineage runtime has no completed world continuity\",\n );\n }\n return currentCompletedWorldId;\n }\n\n async function restore(worldId: WorldId): Promise<void> {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await kernel.enqueue(async () => {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await ensureReady();\n const restored = await service.restore(worldId);\n kernel.setVisibleSnapshot(restored);\n currentCompletedWorldId = worldId;\n\n const branches = await service.getBranches();\n const matchingBranch = branches.find((branch) => branch.head === worldId);\n if (matchingBranch) {\n currentBranchId = matchingBranch.id;\n }\n });\n }\n\n async function switchActiveBranch(branchId: string): Promise<BranchSwitchResult> {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n return kernel.enqueue(async () => {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await ensureReady();\n const result = await service.switchActiveBranch(branchId);\n const branch = await service.getBranch(branchId);\n\n if (!branch) {\n throw new ManifestoError(\n \"LINEAGE_BRANCH_NOT_FOUND\",\n `Cannot switch to unknown branch \"${branchId}\"`,\n );\n }\n\n const restored = await service.restore(branch.head);\n kernel.setVisibleSnapshot(restored);\n currentBranchId = branch.id;\n currentCompletedWorldId = branch.head;\n return result;\n });\n }\n\n async function createBranch(name: string, fromWorldId?: WorldId): Promise<BranchId> {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n return kernel.enqueue(async () => {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await ensureReady();\n const headWorldId = fromWorldId ?? currentCompletedWorldId;\n if (!headWorldId) {\n throw new ManifestoError(\n \"LINEAGE_STATE_ERROR\",\n \"Cannot create a branch before lineage continuity is bootstrapped\",\n );\n }\n\n return service.createBranch(name, headWorldId);\n });\n }\n\n return {\n ensureReady,\n sealIntent,\n getWorld,\n getWorldSnapshot,\n getLineage,\n getLatestHead,\n getHeads,\n getBranches,\n getActiveBranch,\n getCurrentBranchId,\n getCurrentCompletedWorldId,\n restore,\n switchActiveBranch,\n createBranch,\n };\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error\n ? error\n : new Error(String(error));\n}\n"],"mappings":";AAAO,SAAS,cAAc,WAAoB,SAAoC;AACpF,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACF;;;ACJO,SAAS,WAAc,OAAa;AACzC,SAAO,gBAAgB,KAAK;AAC9B;;;ACcA,SAAS,YAAY,QAAoD;AACvE,SAAO,WAAW,MAAM;AAC1B;AAEA,SAAS,aAAa,UAA0D;AAC9E,SAAO,CAAC,GAAG,QAAQ,EAChB,KAAK,CAAC,MAAM,UAAU;AACrB,QAAI,KAAK,cAAc,MAAM,WAAW;AACtC,aAAO,KAAK,YAAY,MAAM;AAAA,IAChC;AACA,QAAI,KAAK,cAAc,MAAM,WAAW;AACtC,aAAO;AAAA,IACT;AACA,WAAO,KAAK,YAAY,MAAM,YAAY,KAAK;AAAA,EACjD,CAAC,E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AAO,iBAAiB,QACpB,QACA,IAAI,MAAM,OAAO,KAAK,CAAC;AAC7B;","names":["branch"]}
package/dist/index.js CHANGED
@@ -1,274 +1,10 @@
1
1
  import {
2
- assertLineage,
2
+ InMemoryLineageStore,
3
3
  attachLineageDecoration,
4
- cloneValue,
4
+ createInMemoryLineageStore,
5
5
  createLineageRuntimeController,
6
6
  createLineageService
7
- } from "./chunk-STH2THPH.js";
8
-
9
- // src/store/in-memory-lineage-store.ts
10
- function cloneBranch(branch) {
11
- return cloneValue(branch);
12
- }
13
- function sortAttempts(attempts) {
14
- return [...attempts].sort((left, right) => {
15
- if (left.createdAt !== right.createdAt) {
16
- return left.createdAt - right.createdAt;
17
- }
18
- if (left.attemptId === right.attemptId) {
19
- return 0;
20
- }
21
- return left.attemptId < right.attemptId ? -1 : 1;
22
- }).map((attempt) => cloneValue(attempt));
23
- }
24
- var InMemoryLineageStore = class {
25
- worlds = /* @__PURE__ */ new Map();
26
- snapshots = /* @__PURE__ */ new Map();
27
- hashInputs = /* @__PURE__ */ new Map();
28
- edges = /* @__PURE__ */ new Map();
29
- edgesByWorld = /* @__PURE__ */ new Map();
30
- attempts = /* @__PURE__ */ new Map();
31
- attemptsByWorld = /* @__PURE__ */ new Map();
32
- attemptsByBranch = /* @__PURE__ */ new Map();
33
- branches = /* @__PURE__ */ new Map();
34
- activeBranchId = null;
35
- async putWorld(world) {
36
- this.worlds.set(world.worldId, cloneValue(world));
37
- }
38
- async getWorld(worldId) {
39
- return cloneValue(this.worlds.get(worldId) ?? null);
40
- }
41
- async putSnapshot(worldId, snapshot) {
42
- this.snapshots.set(worldId, cloneValue(snapshot));
43
- }
44
- async getSnapshot(worldId) {
45
- return cloneValue(this.snapshots.get(worldId) ?? null);
46
- }
47
- async putAttempt(attempt) {
48
- this.attempts.set(attempt.attemptId, cloneValue(attempt));
49
- this.indexAttempt(this.attemptsByWorld, attempt.worldId, attempt.attemptId);
50
- this.indexAttempt(this.attemptsByBranch, attempt.branchId, attempt.attemptId);
51
- }
52
- async getAttempts(worldId) {
53
- const attemptIds = this.attemptsByWorld.get(worldId) ?? [];
54
- return sortAttempts(
55
- attemptIds.map((attemptId) => this.attempts.get(attemptId)).filter((attempt) => attempt != null)
56
- );
57
- }
58
- async getAttemptsByBranch(branchId) {
59
- const attemptIds = this.attemptsByBranch.get(branchId) ?? [];
60
- return sortAttempts(
61
- attemptIds.map((attemptId) => this.attempts.get(attemptId)).filter((attempt) => attempt != null)
62
- );
63
- }
64
- async putHashInput(snapshotHash, input) {
65
- this.hashInputs.set(snapshotHash, cloneValue(input));
66
- }
67
- async getHashInput(snapshotHash) {
68
- return cloneValue(this.hashInputs.get(snapshotHash) ?? null);
69
- }
70
- async putEdge(edge) {
71
- this.edges.set(edge.edgeId, cloneValue(edge));
72
- this.indexEdge(edge.from, edge.edgeId);
73
- this.indexEdge(edge.to, edge.edgeId);
74
- }
75
- async getEdges(worldId) {
76
- const edgeIds = [...this.edgesByWorld.get(worldId) ?? /* @__PURE__ */ new Set()].sort();
77
- return edgeIds.map((edgeId) => this.edges.get(edgeId)).filter((edge) => edge != null).map((edge) => cloneValue(edge));
78
- }
79
- async getBranchHead(branchId) {
80
- return this.branches.get(branchId)?.head ?? null;
81
- }
82
- async getBranchTip(branchId) {
83
- return this.branches.get(branchId)?.tip ?? null;
84
- }
85
- async getBranchEpoch(branchId) {
86
- const branch = this.branches.get(branchId);
87
- assertLineage(branch != null, `LIN-EPOCH-6 violation: unknown branch ${branchId}`);
88
- return branch.epoch;
89
- }
90
- async mutateBranch(mutation) {
91
- const branch = this.branches.get(mutation.branchId);
92
- assertLineage(branch != null, `LIN-STORE-4 violation: unknown branch ${mutation.branchId}`);
93
- assertLineage(
94
- branch.head === mutation.expectedHead && branch.tip === mutation.expectedTip && branch.epoch === mutation.expectedEpoch,
95
- `LIN-STORE-4 violation: branch ${mutation.branchId} CAS mismatch`
96
- );
97
- this.branches.set(mutation.branchId, {
98
- ...branch,
99
- head: mutation.nextHead,
100
- tip: mutation.nextTip,
101
- headAdvancedAt: mutation.headAdvancedAt ?? branch.headAdvancedAt,
102
- epoch: mutation.nextEpoch
103
- });
104
- }
105
- async putBranch(branch) {
106
- this.branches.set(branch.id, cloneBranch(branch));
107
- }
108
- async getBranches() {
109
- return [...this.branches.values()].sort((left, right) => {
110
- if (left.createdAt !== right.createdAt) {
111
- return left.createdAt - right.createdAt;
112
- }
113
- if (left.id === right.id) {
114
- return 0;
115
- }
116
- return left.id < right.id ? -1 : 1;
117
- }).map((branch) => cloneBranch(branch));
118
- }
119
- async getActiveBranchId() {
120
- return this.activeBranchId;
121
- }
122
- async switchActiveBranch(sourceBranchId, targetBranchId) {
123
- assertLineage(sourceBranchId !== targetBranchId, "LIN-SWITCH-5 violation: self-switch is not allowed");
124
- assertLineage(this.activeBranchId === sourceBranchId, "LIN-SWITCH-1 violation: source branch is not active");
125
- const sourceBranch = this.branches.get(sourceBranchId);
126
- const targetBranch = this.branches.get(targetBranchId);
127
- assertLineage(sourceBranch != null, `LIN-SWITCH-3 violation: missing source branch ${sourceBranchId}`);
128
- assertLineage(targetBranch != null, `LIN-SWITCH-3 violation: missing target branch ${targetBranchId}`);
129
- this.branches.set(sourceBranchId, {
130
- ...sourceBranch,
131
- epoch: sourceBranch.epoch + 1
132
- });
133
- this.activeBranchId = targetBranchId;
134
- }
135
- async commitPrepared(prepared) {
136
- const nextBranches = new Map(this.branches);
137
- let nextActiveBranchId = this.activeBranchId;
138
- if (prepared.branchChange.kind === "bootstrap") {
139
- assertLineage(nextBranches.size === 0, "LIN-GENESIS-3 violation: genesis requires an empty branch store");
140
- assertLineage(
141
- nextActiveBranchId == null,
142
- "LIN-GENESIS-3 violation: active branch must be empty before genesis bootstrap"
143
- );
144
- assertLineage(
145
- !nextBranches.has(prepared.branchChange.branch.id),
146
- `LIN-GENESIS-3 violation: branch ${prepared.branchChange.branch.id} already exists`
147
- );
148
- nextBranches.set(prepared.branchChange.branch.id, cloneBranch(prepared.branchChange.branch));
149
- nextActiveBranchId = prepared.branchChange.activeBranchId;
150
- } else {
151
- const branch = nextBranches.get(prepared.branchChange.branchId);
152
- assertLineage(
153
- branch != null,
154
- `LIN-STORE-7 violation: missing branch ${prepared.branchChange.branchId} for prepared commit`
155
- );
156
- assertLineage(
157
- branch.head === prepared.branchChange.expectedHead && branch.tip === prepared.branchChange.expectedTip && branch.epoch === prepared.branchChange.expectedEpoch,
158
- `LIN-STORE-4 violation: branch ${prepared.branchChange.branchId} CAS mismatch`
159
- );
160
- nextBranches.set(prepared.branchChange.branchId, {
161
- ...branch,
162
- head: prepared.branchChange.nextHead,
163
- tip: prepared.branchChange.nextTip,
164
- headAdvancedAt: prepared.branchChange.headAdvancedAt ?? branch.headAdvancedAt,
165
- epoch: prepared.branchChange.nextEpoch
166
- });
167
- }
168
- const existingWorld = this.worlds.get(prepared.worldId) ?? null;
169
- const reused = existingWorld != null;
170
- if (reused) {
171
- assertLineage(
172
- existingWorld.parentWorldId === prepared.world.parentWorldId,
173
- `LIN-STORE-9 violation: world ${prepared.worldId} exists with a different parent`
174
- );
175
- if (prepared.kind === "next") {
176
- assertLineage(
177
- this.edges.has(prepared.edge.edgeId),
178
- `LIN-STORE-9 violation: reuse world ${prepared.worldId} is missing edge ${prepared.edge.edgeId}`
179
- );
180
- }
181
- } else {
182
- await this.putWorld(prepared.world);
183
- await this.putSnapshot(prepared.worldId, prepared.terminalSnapshot);
184
- await this.putHashInput?.(prepared.world.snapshotHash, prepared.hashInput);
185
- if (prepared.kind === "next") {
186
- await this.putEdge(prepared.edge);
187
- }
188
- }
189
- await this.putAttempt({
190
- ...prepared.attempt,
191
- reused
192
- });
193
- this.branches.clear();
194
- for (const [branchId, branch] of nextBranches) {
195
- this.branches.set(branchId, cloneBranch(branch));
196
- }
197
- this.activeBranchId = nextActiveBranchId;
198
- }
199
- listWorlds() {
200
- return [...this.worlds.values()].map((world) => cloneValue(world));
201
- }
202
- listEdges() {
203
- return [...this.edges.values()].map((edge) => cloneValue(edge));
204
- }
205
- snapshotState() {
206
- return {
207
- worlds: cloneValue(this.worlds),
208
- snapshots: cloneValue(this.snapshots),
209
- hashInputs: cloneValue(this.hashInputs),
210
- edges: cloneValue(this.edges),
211
- edgesByWorld: cloneValue(this.edgesByWorld),
212
- attempts: cloneValue(this.attempts),
213
- attemptsByWorld: cloneValue(this.attemptsByWorld),
214
- attemptsByBranch: cloneValue(this.attemptsByBranch),
215
- branches: cloneValue(this.branches),
216
- activeBranchId: this.activeBranchId
217
- };
218
- }
219
- restoreState(state) {
220
- this.worlds.clear();
221
- for (const [worldId, world] of state.worlds) {
222
- this.worlds.set(worldId, cloneValue(world));
223
- }
224
- this.snapshots.clear();
225
- for (const [worldId, snapshot] of state.snapshots) {
226
- this.snapshots.set(worldId, cloneValue(snapshot));
227
- }
228
- this.hashInputs.clear();
229
- for (const [snapshotHash, input] of state.hashInputs) {
230
- this.hashInputs.set(snapshotHash, cloneValue(input));
231
- }
232
- this.edges.clear();
233
- for (const [edgeId, edge] of state.edges) {
234
- this.edges.set(edgeId, cloneValue(edge));
235
- }
236
- this.edgesByWorld.clear();
237
- for (const [worldId, edgeIds] of state.edgesByWorld) {
238
- this.edgesByWorld.set(worldId, new Set(edgeIds));
239
- }
240
- this.attempts.clear();
241
- for (const [attemptId, attempt] of state.attempts) {
242
- this.attempts.set(attemptId, cloneValue(attempt));
243
- }
244
- this.attemptsByWorld.clear();
245
- for (const [worldId, attemptIds] of state.attemptsByWorld) {
246
- this.attemptsByWorld.set(worldId, [...attemptIds]);
247
- }
248
- this.attemptsByBranch.clear();
249
- for (const [branchId, attemptIds] of state.attemptsByBranch) {
250
- this.attemptsByBranch.set(branchId, [...attemptIds]);
251
- }
252
- this.branches.clear();
253
- for (const [branchId, branch] of state.branches) {
254
- this.branches.set(branchId, cloneBranch(branch));
255
- }
256
- this.activeBranchId = state.activeBranchId;
257
- }
258
- indexEdge(worldId, edgeId) {
259
- const current = this.edgesByWorld.get(worldId) ?? /* @__PURE__ */ new Set();
260
- current.add(edgeId);
261
- this.edgesByWorld.set(worldId, current);
262
- }
263
- indexAttempt(index, key, attemptId) {
264
- const current = index.get(key) ?? [];
265
- current.push(attemptId);
266
- index.set(key, current);
267
- }
268
- };
269
- function createInMemoryLineageStore() {
270
- return new InMemoryLineageStore();
271
- }
7
+ } from "./chunk-GECVH4P4.js";
272
8
 
273
9
  // src/with-lineage.ts
274
10
  import {
@@ -280,7 +16,7 @@ import {
280
16
  attachRuntimeKernelFactory,
281
17
  getActivationState,
282
18
  getRuntimeKernelFactory
283
- } from "@manifesto-ai/sdk/internal";
19
+ } from "@manifesto-ai/sdk/provider";
284
20
  var LINEAGE_LAWS = Object.freeze({ __lineageLaws: true });
285
21
  function withLineage(manifesto, config) {
286
22
  assertComposableNotActivated(manifesto);
@@ -381,6 +117,7 @@ function activateLineageRuntime(kernel, service, config) {
381
117
  dispose: kernel.dispose,
382
118
  restore: controller.restore,
383
119
  getWorld: controller.getWorld,
120
+ getWorldSnapshot: controller.getWorldSnapshot,
384
121
  getLineage: controller.getLineage,
385
122
  getLatestHead: controller.getLatestHead,
386
123
  getHeads: controller.getHeads,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/store/in-memory-lineage-store.ts","../src/with-lineage.ts"],"sourcesContent":["import { assertLineage } from \"../invariants.js\";\nimport { cloneValue } from \"../internal/clone.js\";\nimport type {\n BranchId,\n LineageStore,\n PersistedBranchEntry,\n PreparedBranchMutation,\n PreparedLineageCommit,\n SealAttempt,\n Snapshot,\n SnapshotHashInput,\n World,\n WorldEdge,\n WorldId,\n} from \"../types.js\";\n\nfunction cloneBranch(branch: PersistedBranchEntry): PersistedBranchEntry {\n return cloneValue(branch);\n}\n\nfunction sortAttempts(attempts: readonly SealAttempt[]): readonly SealAttempt[] {\n return [...attempts]\n .sort((left, right) => {\n if (left.createdAt !== right.createdAt) {\n return left.createdAt - right.createdAt;\n }\n if (left.attemptId === right.attemptId) {\n return 0;\n }\n return left.attemptId < right.attemptId ? -1 : 1;\n })\n .map((attempt) => cloneValue(attempt));\n}\n\ntype InMemoryLineageStoreState = {\n worlds: Map<WorldId, World>;\n snapshots: Map<WorldId, Snapshot>;\n hashInputs: Map<string, SnapshotHashInput>;\n edges: Map<string, WorldEdge>;\n edgesByWorld: Map<WorldId, Set<string>>;\n attempts: Map<string, SealAttempt>;\n attemptsByWorld: Map<WorldId, string[]>;\n attemptsByBranch: Map<BranchId, string[]>;\n branches: Map<BranchId, PersistedBranchEntry>;\n activeBranchId: BranchId | null;\n};\n\nexport class InMemoryLineageStore implements LineageStore {\n private readonly worlds = new Map<WorldId, World>();\n private readonly snapshots = new Map<WorldId, Snapshot>();\n private readonly hashInputs = new Map<string, SnapshotHashInput>();\n private readonly edges = new Map<string, WorldEdge>();\n private readonly edgesByWorld = new Map<WorldId, Set<string>>();\n private readonly attempts = new Map<string, SealAttempt>();\n private readonly attemptsByWorld = new Map<WorldId, string[]>();\n private readonly attemptsByBranch = new Map<BranchId, string[]>();\n private readonly branches = new Map<BranchId, PersistedBranchEntry>();\n private activeBranchId: BranchId | null = null;\n\n async putWorld(world: World): Promise<void> {\n this.worlds.set(world.worldId, cloneValue(world));\n }\n\n async getWorld(worldId: WorldId): Promise<World | null> {\n return cloneValue(this.worlds.get(worldId) ?? null);\n }\n\n async putSnapshot(worldId: WorldId, snapshot: Snapshot): Promise<void> {\n this.snapshots.set(worldId, cloneValue(snapshot));\n }\n\n async getSnapshot(worldId: WorldId): Promise<Snapshot | null> {\n return cloneValue(this.snapshots.get(worldId) ?? null);\n }\n\n async putAttempt(attempt: SealAttempt): Promise<void> {\n this.attempts.set(attempt.attemptId, cloneValue(attempt));\n this.indexAttempt(this.attemptsByWorld, attempt.worldId, attempt.attemptId);\n this.indexAttempt(this.attemptsByBranch, attempt.branchId, attempt.attemptId);\n }\n\n async getAttempts(worldId: WorldId): Promise<readonly SealAttempt[]> {\n const attemptIds = this.attemptsByWorld.get(worldId) ?? [];\n return sortAttempts(\n attemptIds\n .map((attemptId) => this.attempts.get(attemptId))\n .filter((attempt): attempt is SealAttempt => attempt != null)\n );\n }\n\n async getAttemptsByBranch(branchId: BranchId): Promise<readonly SealAttempt[]> {\n const attemptIds = this.attemptsByBranch.get(branchId) ?? [];\n return sortAttempts(\n attemptIds\n .map((attemptId) => this.attempts.get(attemptId))\n .filter((attempt): attempt is SealAttempt => attempt != null)\n );\n }\n\n async putHashInput(snapshotHash: string, input: SnapshotHashInput): Promise<void> {\n this.hashInputs.set(snapshotHash, cloneValue(input));\n }\n\n async getHashInput(snapshotHash: string): Promise<SnapshotHashInput | null> {\n return cloneValue(this.hashInputs.get(snapshotHash) ?? null);\n }\n\n async putEdge(edge: WorldEdge): Promise<void> {\n this.edges.set(edge.edgeId, cloneValue(edge));\n this.indexEdge(edge.from, edge.edgeId);\n this.indexEdge(edge.to, edge.edgeId);\n }\n\n async getEdges(worldId: WorldId): Promise<readonly WorldEdge[]> {\n const edgeIds = [...(this.edgesByWorld.get(worldId) ?? new Set<string>())].sort();\n return edgeIds\n .map((edgeId) => this.edges.get(edgeId))\n .filter((edge): edge is WorldEdge => edge != null)\n .map((edge) => cloneValue(edge));\n }\n\n async getBranchHead(branchId: BranchId): Promise<WorldId | null> {\n return this.branches.get(branchId)?.head ?? null;\n }\n\n async getBranchTip(branchId: BranchId): Promise<WorldId | null> {\n return this.branches.get(branchId)?.tip ?? null;\n }\n\n async getBranchEpoch(branchId: BranchId): Promise<number> {\n const branch = this.branches.get(branchId);\n assertLineage(branch != null, `LIN-EPOCH-6 violation: unknown branch ${branchId}`);\n return branch.epoch;\n }\n\n async mutateBranch(mutation: PreparedBranchMutation): Promise<void> {\n const branch = this.branches.get(mutation.branchId);\n assertLineage(branch != null, `LIN-STORE-4 violation: unknown branch ${mutation.branchId}`);\n assertLineage(\n branch.head === mutation.expectedHead\n && branch.tip === mutation.expectedTip\n && branch.epoch === mutation.expectedEpoch,\n `LIN-STORE-4 violation: branch ${mutation.branchId} CAS mismatch`\n );\n\n this.branches.set(mutation.branchId, {\n ...branch,\n head: mutation.nextHead,\n tip: mutation.nextTip,\n headAdvancedAt: mutation.headAdvancedAt ?? branch.headAdvancedAt,\n epoch: mutation.nextEpoch,\n });\n }\n\n async putBranch(branch: PersistedBranchEntry): Promise<void> {\n this.branches.set(branch.id, cloneBranch(branch));\n }\n\n async getBranches(): Promise<readonly PersistedBranchEntry[]> {\n return [...this.branches.values()]\n .sort((left, right) => {\n if (left.createdAt !== right.createdAt) {\n return left.createdAt - right.createdAt;\n }\n if (left.id === right.id) {\n return 0;\n }\n return left.id < right.id ? -1 : 1;\n })\n .map((branch) => cloneBranch(branch));\n }\n\n async getActiveBranchId(): Promise<BranchId | null> {\n return this.activeBranchId;\n }\n\n async switchActiveBranch(\n sourceBranchId: BranchId,\n targetBranchId: BranchId\n ): Promise<void> {\n assertLineage(sourceBranchId !== targetBranchId, \"LIN-SWITCH-5 violation: self-switch is not allowed\");\n assertLineage(this.activeBranchId === sourceBranchId, \"LIN-SWITCH-1 violation: source branch is not active\");\n\n const sourceBranch = this.branches.get(sourceBranchId);\n const targetBranch = this.branches.get(targetBranchId);\n assertLineage(sourceBranch != null, `LIN-SWITCH-3 violation: missing source branch ${sourceBranchId}`);\n assertLineage(targetBranch != null, `LIN-SWITCH-3 violation: missing target branch ${targetBranchId}`);\n\n this.branches.set(sourceBranchId, {\n ...sourceBranch,\n epoch: sourceBranch.epoch + 1,\n });\n this.activeBranchId = targetBranchId;\n }\n\n async commitPrepared(prepared: PreparedLineageCommit): Promise<void> {\n const nextBranches = new Map(this.branches);\n let nextActiveBranchId = this.activeBranchId;\n\n if (prepared.branchChange.kind === \"bootstrap\") {\n assertLineage(nextBranches.size === 0, \"LIN-GENESIS-3 violation: genesis requires an empty branch store\");\n assertLineage(\n nextActiveBranchId == null,\n \"LIN-GENESIS-3 violation: active branch must be empty before genesis bootstrap\"\n );\n assertLineage(\n !nextBranches.has(prepared.branchChange.branch.id),\n `LIN-GENESIS-3 violation: branch ${prepared.branchChange.branch.id} already exists`\n );\n nextBranches.set(prepared.branchChange.branch.id, cloneBranch(prepared.branchChange.branch));\n nextActiveBranchId = prepared.branchChange.activeBranchId;\n } else {\n const branch = nextBranches.get(prepared.branchChange.branchId);\n assertLineage(\n branch != null,\n `LIN-STORE-7 violation: missing branch ${prepared.branchChange.branchId} for prepared commit`\n );\n assertLineage(\n branch.head === prepared.branchChange.expectedHead\n && branch.tip === prepared.branchChange.expectedTip\n && branch.epoch === prepared.branchChange.expectedEpoch,\n `LIN-STORE-4 violation: branch ${prepared.branchChange.branchId} CAS mismatch`\n );\n nextBranches.set(prepared.branchChange.branchId, {\n ...branch,\n head: prepared.branchChange.nextHead,\n tip: prepared.branchChange.nextTip,\n headAdvancedAt: prepared.branchChange.headAdvancedAt ?? branch.headAdvancedAt,\n epoch: prepared.branchChange.nextEpoch,\n });\n }\n\n const existingWorld = this.worlds.get(prepared.worldId) ?? null;\n const reused = existingWorld != null;\n\n if (reused) {\n assertLineage(\n existingWorld.parentWorldId === prepared.world.parentWorldId,\n `LIN-STORE-9 violation: world ${prepared.worldId} exists with a different parent`\n );\n if (prepared.kind === \"next\") {\n assertLineage(\n this.edges.has(prepared.edge.edgeId),\n `LIN-STORE-9 violation: reuse world ${prepared.worldId} is missing edge ${prepared.edge.edgeId}`\n );\n }\n } else {\n await this.putWorld(prepared.world);\n await this.putSnapshot(prepared.worldId, prepared.terminalSnapshot);\n await this.putHashInput?.(prepared.world.snapshotHash, prepared.hashInput);\n\n if (prepared.kind === \"next\") {\n await this.putEdge(prepared.edge);\n }\n }\n\n await this.putAttempt({\n ...prepared.attempt,\n reused,\n });\n\n this.branches.clear();\n for (const [branchId, branch] of nextBranches) {\n this.branches.set(branchId, cloneBranch(branch));\n }\n this.activeBranchId = nextActiveBranchId;\n }\n\n listWorlds(): readonly World[] {\n return [...this.worlds.values()].map((world) => cloneValue(world));\n }\n\n listEdges(): readonly WorldEdge[] {\n return [...this.edges.values()].map((edge) => cloneValue(edge));\n }\n\n snapshotState(): InMemoryLineageStoreState {\n return {\n worlds: cloneValue(this.worlds),\n snapshots: cloneValue(this.snapshots),\n hashInputs: cloneValue(this.hashInputs),\n edges: cloneValue(this.edges),\n edgesByWorld: cloneValue(this.edgesByWorld),\n attempts: cloneValue(this.attempts),\n attemptsByWorld: cloneValue(this.attemptsByWorld),\n attemptsByBranch: cloneValue(this.attemptsByBranch),\n branches: cloneValue(this.branches),\n activeBranchId: this.activeBranchId,\n };\n }\n\n restoreState(state: InMemoryLineageStoreState): void {\n this.worlds.clear();\n for (const [worldId, world] of state.worlds) {\n this.worlds.set(worldId, cloneValue(world));\n }\n\n this.snapshots.clear();\n for (const [worldId, snapshot] of state.snapshots) {\n this.snapshots.set(worldId, cloneValue(snapshot));\n }\n\n this.hashInputs.clear();\n for (const [snapshotHash, input] of state.hashInputs) {\n this.hashInputs.set(snapshotHash, cloneValue(input));\n }\n\n this.edges.clear();\n for (const [edgeId, edge] of state.edges) {\n this.edges.set(edgeId, cloneValue(edge));\n }\n\n this.edgesByWorld.clear();\n for (const [worldId, edgeIds] of state.edgesByWorld) {\n this.edgesByWorld.set(worldId, new Set(edgeIds));\n }\n\n this.attempts.clear();\n for (const [attemptId, attempt] of state.attempts) {\n this.attempts.set(attemptId, cloneValue(attempt));\n }\n\n this.attemptsByWorld.clear();\n for (const [worldId, attemptIds] of state.attemptsByWorld) {\n this.attemptsByWorld.set(worldId, [...attemptIds]);\n }\n\n this.attemptsByBranch.clear();\n for (const [branchId, attemptIds] of state.attemptsByBranch) {\n this.attemptsByBranch.set(branchId, [...attemptIds]);\n }\n\n this.branches.clear();\n for (const [branchId, branch] of state.branches) {\n this.branches.set(branchId, cloneBranch(branch));\n }\n\n this.activeBranchId = state.activeBranchId;\n }\n\n private indexEdge(worldId: WorldId, edgeId: string): void {\n const current = this.edgesByWorld.get(worldId) ?? new Set<string>();\n current.add(edgeId);\n this.edgesByWorld.set(worldId, current);\n }\n\n private indexAttempt(index: Map<string, string[]>, key: string, attemptId: string): void {\n const current = index.get(key) ?? [];\n current.push(attemptId);\n index.set(key, current);\n }\n}\n\nexport function createInMemoryLineageStore(): InMemoryLineageStore {\n return new InMemoryLineageStore();\n}\n","import type {\n ComposableManifesto,\n LineageLaws,\n ManifestoDomainShape,\n} from \"@manifesto-ai/sdk\";\nimport {\n ManifestoError,\n} from \"@manifesto-ai/sdk\";\nimport {\n activateComposable,\n assertComposableNotActivated,\n attachRuntimeKernelFactory,\n getActivationState,\n getRuntimeKernelFactory,\n type RuntimeKernel,\n} from \"@manifesto-ai/sdk/internal\";\n\nimport { createLineageService } from \"./service/lineage-service.js\";\nimport type {\n BaseComposableManifesto,\n LineageComposableManifesto,\n LineageComposableLaws,\n LineageConfig,\n LineageInstance,\n} from \"./runtime-types.js\";\nimport {\n attachLineageDecoration,\n createLineageRuntimeController,\n type ResolvedLineageConfig,\n} from \"./internal.js\";\n\nconst LINEAGE_LAWS: LineageLaws = Object.freeze({ __lineageLaws: true });\n\nexport function withLineage<\n T extends ManifestoDomainShape,\n>(\n manifesto: BaseComposableManifesto<T>,\n config: LineageConfig,\n): LineageComposableManifesto<T> {\n assertComposableNotActivated(manifesto);\n\n const resolvedConfig = resolveLineageConfig(config);\n const { service } = resolvedConfig;\n const createKernel = getRuntimeKernelFactory(manifesto);\n const activationState = getActivationState(manifesto);\n\n const decorated: LineageComposableManifesto<T> = {\n _laws: Object.freeze({\n ...manifesto._laws,\n ...LINEAGE_LAWS,\n }) as LineageComposableLaws,\n schema: manifesto.schema,\n activate() {\n activateComposable(\n decorated as unknown as ComposableManifesto<T, LineageComposableLaws>,\n );\n return activateLineageRuntime<T>(createKernel(), service, resolvedConfig);\n },\n };\n\n attachRuntimeKernelFactory(\n decorated as unknown as ComposableManifesto<T, LineageComposableLaws>,\n createKernel,\n activationState,\n );\n\n return attachLineageDecoration(\n decorated as unknown as ComposableManifesto<T, LineageComposableLaws>,\n {\n service,\n config: resolvedConfig,\n },\n ) as unknown as LineageComposableManifesto<T>;\n}\n\nfunction resolveLineageConfig(config: LineageConfig): ResolvedLineageConfig {\n if (!config || typeof config !== \"object\") {\n throw new ManifestoError(\n \"LINEAGE_CONFIG_REQUIRED\",\n \"withLineage() requires a config object with either service or store\",\n );\n }\n\n if (\"service\" in config && config.service) {\n return Object.freeze({\n ...config,\n service: config.service,\n });\n }\n\n if (\"store\" in config && config.store) {\n return Object.freeze({\n ...config,\n service: createLineageService(config.store),\n });\n }\n\n throw new ManifestoError(\n \"LINEAGE_CONFIG_REQUIRED\",\n \"withLineage() requires a config object with either service or store\",\n );\n}\n\nfunction activateLineageRuntime<T extends ManifestoDomainShape>(\n kernel: RuntimeKernel<T>,\n service: ResolvedLineageConfig[\"service\"],\n config: ResolvedLineageConfig,\n): LineageInstance<T> {\n const controller = createLineageRuntimeController(kernel, service, config);\n\n async function commitAsync(intent: Parameters<LineageInstance<T>[\"commitAsync\"]>[0]) {\n const sealed = await controller\n .sealIntent(intent, { publishOnCompleted: true })\n .catch((error) => {\n const failure = toError(error);\n if (!isActionUnavailable(failure)) {\n kernel.emitEvent(\"dispatch:failed\", {\n intentId: intent.intentId ?? \"\",\n intent,\n error: failure,\n });\n }\n throw failure;\n });\n\n if (sealed.preparedCommit.branchChange.headAdvanced && sealed.publishedSnapshot) {\n kernel.emitEvent(\"dispatch:completed\", {\n intentId: sealed.intent.intentId ?? \"\",\n intent: sealed.intent,\n snapshot: sealed.publishedSnapshot,\n });\n return sealed.publishedSnapshot;\n }\n\n const failure = toCommitFailure(sealed.hostResult.error);\n kernel.emitEvent(\"dispatch:failed\", {\n intentId: sealed.intent.intentId ?? \"\",\n intent: sealed.intent,\n error: failure,\n });\n throw failure;\n }\n\n return {\n createIntent: kernel.createIntent,\n commitAsync,\n subscribe: kernel.subscribe,\n on: kernel.on,\n getSnapshot: kernel.getSnapshot,\n getAvailableActions: kernel.getAvailableActions,\n isActionAvailable: kernel.isActionAvailable,\n MEL: kernel.MEL,\n schema: kernel.schema,\n dispose: kernel.dispose,\n restore: controller.restore,\n getWorld: controller.getWorld,\n getLineage: controller.getLineage,\n getLatestHead: controller.getLatestHead,\n getHeads: controller.getHeads,\n getBranches: controller.getBranches,\n getActiveBranch: controller.getActiveBranch,\n switchActiveBranch: controller.switchActiveBranch,\n createBranch: controller.createBranch,\n };\n}\n\nfunction toCommitFailure(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n\n return new ManifestoError(\n \"LINEAGE_COMMIT_FAILED\",\n \"Commit did not produce a completed lineage head\",\n );\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error\n ? error\n : new Error(String(error));\n}\n\nfunction isActionUnavailable(error: Error): boolean {\n return \"code\" in error\n && typeof error.code === \"string\"\n && error.code === \"ACTION_UNAVAILABLE\";\n}\n"],"mappings":";;;;;;;;;AAgBA,SAAS,YAAY,QAAoD;AACvE,SAAO,WAAW,MAAM;AAC1B;AAEA,SAAS,aAAa,UAA0D;AAC9E,SAAO,CAAC,GAAG,QAAQ,EAChB,KAAK,CAAC,MAAM,UAAU;AACrB,QAAI,KAAK,cAAc,MAAM,WAAW;AACtC,aAAO,KAAK,YAAY,MAAM;AAAA,IAChC;AACA,QAAI,KAAK,cAAc,MAAM,WAAW;AACtC,aAAO;AAAA,IACT;AACA,WAAO,KAAK,YAAY,MAAM,YAAY,KAAK;AAAA,EACjD,CAAC,EACA,IAAI,CAAC,YAAY,WAAW,OAAO,CAAC;AACzC;AAeO,IAAM,uBAAN,MAAmD;AAAA,EACvC,SAAS,oBAAI,IAAoB;AAAA,EACjC,YAAY,oBAAI,IAAuB;AAAA,EACvC,aAAa,oBAAI,IAA+B;AAAA,EAChD,QAAQ,oBAAI,IAAuB;AAAA,EACnC,eAAe,oBAAI,IAA0B;AAAA,EAC7C,WAAW,oBAAI,IAAyB;AAAA,EACxC,kBAAkB,oBAAI,IAAuB;AAAA,EAC7C,mBAAmB,oBAAI,IAAwB;AAAA,EAC/C,WAAW,oBAAI,IAAoC;AAAA,EAC5D,iBAAkC;AAAA,EAE1C,MAAM,S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IACf,SAAS,OAAO;AAAA,IAChB,SAAS,WAAW;AAAA,IACpB,UAAU,WAAW;AAAA,IACrB,YAAY,WAAW;AAAA,IACvB,eAAe,WAAW;AAAA,IAC1B,UAAU,WAAW;AAAA,IACrB,aAAa,WAAW;AAAA,IACxB,iBAAiB,WAAW;AAAA,IAC5B,oBAAoB,WAAW;AAAA,IAC/B,cAAc,WAAW;AAAA,EAC3B;AACF;AAEA,SAAS,gBAAgB,OAAuB;AAC9C,MAAI,iBAAiB,OAAO;AAC1B,WAAO;AAAA,EACT;AAEA,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,QAAQ,OAAuB;AACtC,SAAO,iBAAiB,QACpB,QACA,IAAI,MAAM,OAAO,KAAK,CAAC;AAC7B;AAEA,SAAS,oBAAoB,OAAuB;AAClD,SAAO,UAAU,SACZ,OAAO,MAAM,SAAS,YACtB,MAAM,SAAS;AACtB;","names":["failure"]}
1
+ {"version":3,"sources":["../src/with-lineage.ts"],"sourcesContent":["import type {\n ComposableManifesto,\n LineageLaws,\n ManifestoDomainShape,\n} from \"@manifesto-ai/sdk\";\nimport {\n ManifestoError,\n} from \"@manifesto-ai/sdk\";\nimport {\n activateComposable,\n assertComposableNotActivated,\n attachRuntimeKernelFactory,\n getActivationState,\n getRuntimeKernelFactory,\n type RuntimeKernel,\n} from \"@manifesto-ai/sdk/provider\";\n\nimport { createLineageService } from \"./service/lineage-service.js\";\nimport type {\n BaseComposableManifesto,\n LineageComposableManifesto,\n LineageComposableLaws,\n LineageConfig,\n LineageInstance,\n} from \"./runtime-types.js\";\nimport {\n attachLineageDecoration,\n createLineageRuntimeController,\n type ResolvedLineageConfig,\n} from \"./internal.js\";\n\nconst LINEAGE_LAWS: LineageLaws = Object.freeze({ __lineageLaws: true });\n\nexport function withLineage<\n T extends ManifestoDomainShape,\n>(\n manifesto: BaseComposableManifesto<T>,\n config: LineageConfig,\n): LineageComposableManifesto<T> {\n assertComposableNotActivated(manifesto);\n\n const resolvedConfig = resolveLineageConfig(config);\n const { service } = resolvedConfig;\n const createKernel = getRuntimeKernelFactory(manifesto);\n const activationState = getActivationState(manifesto);\n\n const decorated: LineageComposableManifesto<T> = {\n _laws: Object.freeze({\n ...manifesto._laws,\n ...LINEAGE_LAWS,\n }) as LineageComposableLaws,\n schema: manifesto.schema,\n activate() {\n activateComposable(\n decorated as unknown as ComposableManifesto<T, LineageComposableLaws>,\n );\n return activateLineageRuntime<T>(createKernel(), service, resolvedConfig);\n },\n };\n\n attachRuntimeKernelFactory(\n decorated as unknown as ComposableManifesto<T, LineageComposableLaws>,\n createKernel,\n activationState,\n );\n\n return attachLineageDecoration(\n decorated as unknown as ComposableManifesto<T, LineageComposableLaws>,\n {\n service,\n config: resolvedConfig,\n },\n ) as unknown as LineageComposableManifesto<T>;\n}\n\nfunction resolveLineageConfig(config: LineageConfig): ResolvedLineageConfig {\n if (!config || typeof config !== \"object\") {\n throw new ManifestoError(\n \"LINEAGE_CONFIG_REQUIRED\",\n \"withLineage() requires a config object with either service or store\",\n );\n }\n\n if (\"service\" in config && config.service) {\n return Object.freeze({\n ...config,\n service: config.service,\n });\n }\n\n if (\"store\" in config && config.store) {\n return Object.freeze({\n ...config,\n service: createLineageService(config.store),\n });\n }\n\n throw new ManifestoError(\n \"LINEAGE_CONFIG_REQUIRED\",\n \"withLineage() requires a config object with either service or store\",\n );\n}\n\nfunction activateLineageRuntime<T extends ManifestoDomainShape>(\n kernel: RuntimeKernel<T>,\n service: ResolvedLineageConfig[\"service\"],\n config: ResolvedLineageConfig,\n): LineageInstance<T> {\n const controller = createLineageRuntimeController(kernel, service, config);\n\n async function commitAsync(intent: Parameters<LineageInstance<T>[\"commitAsync\"]>[0]) {\n const sealed = await controller\n .sealIntent(intent, { publishOnCompleted: true })\n .catch((error) => {\n const failure = toError(error);\n if (!isActionUnavailable(failure)) {\n kernel.emitEvent(\"dispatch:failed\", {\n intentId: intent.intentId ?? \"\",\n intent,\n error: failure,\n });\n }\n throw failure;\n });\n\n if (sealed.preparedCommit.branchChange.headAdvanced && sealed.publishedSnapshot) {\n kernel.emitEvent(\"dispatch:completed\", {\n intentId: sealed.intent.intentId ?? \"\",\n intent: sealed.intent,\n snapshot: sealed.publishedSnapshot,\n });\n return sealed.publishedSnapshot;\n }\n\n const failure = toCommitFailure(sealed.hostResult.error);\n kernel.emitEvent(\"dispatch:failed\", {\n intentId: sealed.intent.intentId ?? \"\",\n intent: sealed.intent,\n error: failure,\n });\n throw failure;\n }\n\n return {\n createIntent: kernel.createIntent,\n commitAsync,\n subscribe: kernel.subscribe,\n on: kernel.on,\n getSnapshot: kernel.getSnapshot,\n getAvailableActions: kernel.getAvailableActions,\n isActionAvailable: kernel.isActionAvailable,\n MEL: kernel.MEL,\n schema: kernel.schema,\n dispose: kernel.dispose,\n restore: controller.restore,\n getWorld: controller.getWorld,\n getWorldSnapshot: controller.getWorldSnapshot,\n getLineage: controller.getLineage,\n getLatestHead: controller.getLatestHead,\n getHeads: controller.getHeads,\n getBranches: controller.getBranches,\n getActiveBranch: controller.getActiveBranch,\n switchActiveBranch: controller.switchActiveBranch,\n createBranch: controller.createBranch,\n };\n}\n\nfunction toCommitFailure(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n\n return new ManifestoError(\n \"LINEAGE_COMMIT_FAILED\",\n \"Commit did not produce a completed lineage head\",\n );\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error\n ? error\n : new Error(String(error));\n}\n\nfunction isActionUnavailable(error: Error): boolean {\n return \"code\" in error\n && typeof error.code === \"string\"\n && error.code === \"ACTION_UNAVAILABLE\";\n}\n"],"mappings":";;;;;;;;;AAKA;AAAA,EACE;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAgBP,IAAM,eAA4B,OAAO,OAAO,EAAE,eAAe,KAAK,CAAC;AAEhE,SAAS,YAGd,WACA,QAC+B;AAC/B,+BAA6B,SA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S,QAAQ,OAAuB;AACtC,SAAO,iBAAiB,QACpB,QACA,IAAI,MAAM,OAAO,KAAK,CAAC;AAC7B;AAEA,SAAS,oBAAoB,OAAuB;AAClD,SAAO,UAAU,SACZ,OAAO,MAAM,SAAS,YACtB,MAAM,SAAS;AACtB;","names":["failure"]}
@@ -1,6 +1,5 @@
1
- import { type BaseLaws, type ComposableManifesto, type LineageLaws, type ManifestoDomainShape, type Snapshot } from "@manifesto-ai/sdk";
2
- import type { HostDispatchOptions, RuntimeKernel } from "@manifesto-ai/sdk/internal";
3
- import type { Intent } from "@manifesto-ai/core";
1
+ import { type BaseLaws, type ComposableManifesto, type LineageLaws, type ManifestoDomainShape, type Snapshot, type TypedIntent } from "@manifesto-ai/sdk";
2
+ import type { HostDispatchOptions, RuntimeKernel } from "@manifesto-ai/sdk/provider";
4
3
  import type { LineageConfig } from "./runtime-types.js";
5
4
  import type { BranchId, BranchInfo, BranchSwitchResult, LineageService, PreparedNextCommit, World, WorldHead, WorldId, WorldLineage } from "./types.js";
6
5
  export type { ArtifactRef, BranchId, BranchInfo, BranchSwitchResult, LineageService, LineageStore, PreparedLineageCommit, SealAttempt, World, WorldId, } from "./types.js";
@@ -24,15 +23,16 @@ export type SealIntentOptions = {
24
23
  readonly assumeEnqueued?: boolean;
25
24
  };
26
25
  export type SealedIntentResult<T extends ManifestoDomainShape> = {
27
- readonly intent: Intent;
26
+ readonly intent: TypedIntent<T>;
28
27
  readonly hostResult: Awaited<ReturnType<RuntimeKernel<T>["executeHost"]>>;
29
28
  readonly preparedCommit: PreparedNextCommit;
30
29
  readonly publishedSnapshot?: Snapshot<T["state"]>;
31
30
  };
32
31
  export interface LineageRuntimeController<T extends ManifestoDomainShape> {
33
32
  ensureReady(): Promise<void>;
34
- sealIntent(intent: Intent, options?: SealIntentOptions): Promise<SealedIntentResult<T>>;
33
+ sealIntent(intent: TypedIntent<T>, options?: SealIntentOptions): Promise<SealedIntentResult<T>>;
35
34
  getWorld(worldId: WorldId): Promise<World | null>;
35
+ getWorldSnapshot(worldId: WorldId): Promise<Snapshot<T["state"]> | null>;
36
36
  getLineage(): Promise<WorldLineage>;
37
37
  getLatestHead(): Promise<WorldHead | null>;
38
38
  getHeads(): Promise<readonly WorldHead[]>;
@@ -0,0 +1,5 @@
1
+ export type { AttemptId, BranchId, BranchInfo, BranchSwitchResult, LineageService, LineageStore, PersistedPatchDeltaV2, PreparedBranchBootstrap, PreparedBranchChange, PreparedBranchMutation, PreparedGenesisCommit, PreparedLineageCommit, PreparedLineageRecords, PreparedNextCommit, ProvenanceRef, SealAttempt, SealGenesisInput, SealNextInput, SnapshotHashInput, World, WorldEdge, WorldHead, WorldId, WorldLineage, } from "./types.js";
2
+ export type { LineageDecoration, LineageRuntimeController, ResolvedLineageConfig, SealedIntentResult, SealIntentOptions, } from "./internal.js";
3
+ export { attachLineageDecoration, createLineageRuntimeController, getLineageDecoration, } from "./internal.js";
4
+ export { DefaultLineageService, createLineageService, } from "./service/lineage-service.js";
5
+ export { InMemoryLineageStore, createInMemoryLineageStore } from "./store/in-memory-lineage-store.js";
@@ -1,17 +1,19 @@
1
1
  import {
2
2
  DefaultLineageService,
3
- LINEAGE_DECORATION,
3
+ InMemoryLineageStore,
4
4
  attachLineageDecoration,
5
+ createInMemoryLineageStore,
5
6
  createLineageRuntimeController,
6
7
  createLineageService,
7
8
  getLineageDecoration
8
- } from "./chunk-STH2THPH.js";
9
+ } from "./chunk-GECVH4P4.js";
9
10
  export {
10
11
  DefaultLineageService,
11
- LINEAGE_DECORATION,
12
+ InMemoryLineageStore,
12
13
  attachLineageDecoration,
14
+ createInMemoryLineageStore,
13
15
  createLineageRuntimeController,
14
16
  createLineageService,
15
17
  getLineageDecoration
16
18
  };
17
- //# sourceMappingURL=internal.js.map
19
+ //# sourceMappingURL=provider.js.map
@@ -1,4 +1,4 @@
1
- import type { BaseLaws, ComposableManifesto, LineageLaws, ManifestoBaseInstance, ManifestoDomainShape, TypedDispatchAsync } from "@manifesto-ai/sdk";
1
+ import type { BaseLaws, ComposableManifesto, LineageLaws, ManifestoBaseInstance, ManifestoDomainShape, Snapshot, TypedDispatchAsync } from "@manifesto-ai/sdk";
2
2
  import type { BranchId, BranchInfo, BranchSwitchResult, LineageService, LineageStore, World, WorldHead, WorldId, WorldLineage } from "./types.js";
3
3
  export type LineageConfig = {
4
4
  readonly service: LineageService;
@@ -19,6 +19,7 @@ export type LineageInstance<T extends ManifestoDomainShape> = Omit<ManifestoBase
19
19
  readonly commitAsync: TypedCommitAsync<T>;
20
20
  readonly restore: (worldId: WorldId) => Promise<void>;
21
21
  readonly getWorld: (worldId: WorldId) => Promise<World | null>;
22
+ readonly getWorldSnapshot: (worldId: WorldId) => Promise<Snapshot<T["state"]> | null>;
22
23
  readonly getLineage: () => Promise<WorldLineage>;
23
24
  readonly getLatestHead: () => Promise<WorldHead | null>;
24
25
  readonly getHeads: () => Promise<readonly WorldHead[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifesto-ai/lineage",
3
- "version": "3.1.2",
3
+ "version": "3.3.0",
4
4
  "description": "Manifesto Lineage - decorator runtime for seal-aware continuity, history, and restore",
5
5
  "author": "eggplantiny <eggplantiny@gmail.com>",
6
6
  "license": "MIT",
@@ -28,32 +28,34 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "import": "./dist/index.js"
30
30
  },
31
- "./internal": {
32
- "types": "./dist/internal.d.ts",
33
- "import": "./dist/internal.js"
31
+ "./provider": {
32
+ "types": "./dist/provider.d.ts",
33
+ "import": "./dist/provider.js"
34
34
  }
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@manifesto-ai/core": "^2.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "@manifesto-ai/sdk": "3.1.2"
40
+ "@manifesto-ai/sdk": "3.3.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "typescript": "^5.9.3",
44
44
  "vite": "^8.0.3",
45
45
  "vitest": "^4.1.2",
46
- "@manifesto-ai/core": "2.8.0",
47
- "@manifesto-ai/cts-kit": "0.1.0"
46
+ "@manifesto-ai/cts-kit": "0.1.0",
47
+ "@manifesto-ai/core": "2.8.0"
48
48
  },
49
49
  "files": [
50
50
  "dist"
51
51
  ],
52
52
  "scripts": {
53
- "build": "rm -rf dist && tsup && tsc -p tsconfig.build.json --emitDeclarationOnly --declarationMap false --outDir dist",
53
+ "build": "rm -rf dist && tsup && tsc -p tsconfig.build.json --emitDeclarationOnly --declarationMap false --outDir dist && node ../../scripts/check-public-surface.mjs packages/lineage",
54
54
  "clean": "rm -rf dist",
55
55
  "lint": "echo 'lint not configured'",
56
- "test": "vitest run",
56
+ "test": "pnpm run test:runtime && pnpm run test:types",
57
+ "test:runtime": "vitest run",
58
+ "test:types": "tsc -p tsconfig.types.json --noEmit",
57
59
  "test:coverage": "vitest run --coverage",
58
60
  "test:watch": "vitest"
59
61
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internal.ts","../src/invariants.ts","../src/internal/clone.ts","../src/query.ts","../src/hash.ts","../src/records.ts","../src/service/lineage-service.ts"],"sourcesContent":["import {\n DisposedError,\n ManifestoError,\n type BaseLaws,\n type ComposableManifesto,\n type LineageLaws,\n type ManifestoDomainShape,\n type Snapshot,\n} from \"@manifesto-ai/sdk\";\nimport type { HostDispatchOptions, RuntimeKernel } from \"@manifesto-ai/sdk/internal\";\nimport type { Intent } from \"@manifesto-ai/core\";\n\nimport type { LineageConfig } from \"./runtime-types.js\";\nimport type {\n BranchId,\n BranchInfo,\n BranchSwitchResult,\n LineageService,\n PreparedNextCommit,\n World,\n WorldHead,\n WorldId,\n WorldLineage,\n} from \"./types.js\";\n\nexport type {\n ArtifactRef,\n BranchId,\n BranchInfo,\n BranchSwitchResult,\n LineageService,\n LineageStore,\n PreparedLineageCommit,\n SealAttempt,\n World,\n WorldId,\n} from \"./types.js\";\nexport {\n DefaultLineageService,\n createLineageService,\n} from \"./service/lineage-service.js\";\n\nexport const LINEAGE_DECORATION = Symbol(\"manifesto-lineage.decoration\");\n\nexport type ResolvedLineageConfig = LineageConfig & {\n readonly service: LineageService;\n};\n\nexport type LineageDecoration = {\n readonly service: LineageService;\n readonly config: ResolvedLineageConfig;\n};\n\nexport type InternalLineageComposableManifesto<\n T extends ManifestoDomainShape,\n Laws extends BaseLaws,\n> = ComposableManifesto<T, Laws & LineageLaws> & {\n readonly [LINEAGE_DECORATION]: LineageDecoration;\n};\n\nexport type SealIntentOptions = {\n readonly proposalRef?: string;\n readonly decisionRef?: string;\n readonly executionKey?: HostDispatchOptions[\"key\"];\n readonly publishOnCompleted?: boolean;\n readonly assumeEnqueued?: boolean;\n};\n\nexport type SealedIntentResult<T extends ManifestoDomainShape> = {\n readonly intent: Intent;\n readonly hostResult: Awaited<ReturnType<RuntimeKernel<T>[\"executeHost\"]>>;\n readonly preparedCommit: PreparedNextCommit;\n readonly publishedSnapshot?: Snapshot<T[\"state\"]>;\n};\n\nexport interface LineageRuntimeController<T extends ManifestoDomainShape> {\n ensureReady(): Promise<void>;\n sealIntent(\n intent: Intent,\n options?: SealIntentOptions,\n ): Promise<SealedIntentResult<T>>;\n getWorld(worldId: WorldId): Promise<World | null>;\n getLineage(): Promise<WorldLineage>;\n getLatestHead(): Promise<WorldHead | null>;\n getHeads(): Promise<readonly WorldHead[]>;\n getBranches(): Promise<readonly BranchInfo[]>;\n getActiveBranch(): Promise<BranchInfo>;\n getCurrentBranchId(): Promise<BranchId>;\n getCurrentCompletedWorldId(): Promise<WorldId>;\n restore(worldId: WorldId): Promise<void>;\n switchActiveBranch(branchId: BranchId): Promise<BranchSwitchResult>;\n createBranch(name: string, fromWorldId?: WorldId): Promise<BranchId>;\n}\n\nexport function attachLineageDecoration<\n T extends ManifestoDomainShape,\n Laws extends BaseLaws,\n>(\n manifesto: ComposableManifesto<T, Laws & LineageLaws>,\n decoration: LineageDecoration,\n): InternalLineageComposableManifesto<T, Laws> {\n Object.defineProperty(manifesto, LINEAGE_DECORATION, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: decoration,\n });\n\n return manifesto as InternalLineageComposableManifesto<T, Laws>;\n}\n\nexport function getLineageDecoration<\n T extends ManifestoDomainShape,\n Laws extends BaseLaws,\n>(\n manifesto: ComposableManifesto<T, Laws>,\n): LineageDecoration | null {\n const internal = manifesto as Partial<InternalLineageComposableManifesto<T, Laws>>;\n return internal[LINEAGE_DECORATION] ?? null;\n}\n\nexport function createLineageRuntimeController<T extends ManifestoDomainShape>(\n kernel: RuntimeKernel<T>,\n service: LineageService,\n config: ResolvedLineageConfig,\n): LineageRuntimeController<T> {\n let readiness: Promise<void> | null = null;\n let currentBranchId: string | null = null;\n let currentCompletedWorldId: WorldId | null = null;\n\n async function ensureReady(): Promise<void> {\n if (readiness) {\n return readiness;\n }\n\n readiness = bootstrapLineage().catch((error) => {\n readiness = null;\n throw error;\n });\n\n return readiness;\n }\n\n async function bootstrapLineage(): Promise<void> {\n const branches = await service.getBranches();\n if (branches.length === 0) {\n if (config.branchId) {\n throw new ManifestoError(\n \"LINEAGE_BRANCH_NOT_FOUND\",\n `Configured branch \"${config.branchId}\" does not exist in the lineage store`,\n );\n }\n\n const genesisSnapshot = kernel.getVisibleCoreSnapshot();\n const prepared = await service.prepareSealGenesis({\n schemaHash: kernel.schema.hash,\n terminalSnapshot: genesisSnapshot,\n createdAt: genesisSnapshot.meta.timestamp,\n });\n await service.commitPrepared(prepared);\n currentBranchId = prepared.branchId;\n currentCompletedWorldId = prepared.worldId;\n return;\n }\n\n const branch = await bindInitialBranch(config.branchId);\n currentBranchId = branch.id;\n currentCompletedWorldId = branch.head;\n const restored = await service.restore(branch.head);\n kernel.setVisibleSnapshot(restored, { notify: false });\n }\n\n async function bindInitialBranch(branchId?: string): Promise<BranchInfo> {\n if (!branchId) {\n return service.getActiveBranch();\n }\n\n const branch = await service.getBranch(branchId);\n if (!branch) {\n throw new ManifestoError(\n \"LINEAGE_BRANCH_NOT_FOUND\",\n `Configured branch \"${branchId}\" does not exist in the lineage store`,\n );\n }\n\n const activeBranch = await service.getActiveBranch();\n if (activeBranch.id !== branch.id) {\n await service.switchActiveBranch(branch.id);\n }\n\n return branch;\n }\n\n async function sealIntent(\n intent: Intent,\n options?: SealIntentOptions,\n ): Promise<SealedIntentResult<T>> {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n const enrichedIntent = kernel.ensureIntentId(intent);\n\n const runSeal = async () => {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await ensureReady();\n\n if (!kernel.isActionAvailable(enrichedIntent.type as keyof T[\"actions\"])) {\n return kernel.rejectUnavailable(enrichedIntent);\n }\n\n let result: Awaited<ReturnType<RuntimeKernel<T>[\"executeHost\"]>>;\n try {\n result = await kernel.executeHost(\n enrichedIntent,\n options?.executionKey !== undefined\n ? { key: options.executionKey }\n : undefined,\n );\n } catch (error) {\n kernel.restoreVisibleSnapshot();\n throw toError(error);\n }\n\n if (!currentBranchId || !currentCompletedWorldId) {\n kernel.restoreVisibleSnapshot();\n throw new ManifestoError(\n \"LINEAGE_STATE_ERROR\",\n \"Lineage runtime has no active branch continuity after bootstrap\",\n );\n }\n\n let prepared: PreparedNextCommit;\n try {\n prepared = await service.prepareSealNext({\n schemaHash: kernel.schema.hash,\n baseWorldId: currentCompletedWorldId,\n branchId: currentBranchId,\n terminalSnapshot: result.snapshot,\n createdAt: result.snapshot.meta.timestamp,\n ...(options?.proposalRef ? { proposalRef: options.proposalRef } : {}),\n ...(options?.decisionRef ? { decisionRef: options.decisionRef } : {}),\n });\n await service.commitPrepared(prepared);\n } catch (error) {\n kernel.restoreVisibleSnapshot();\n throw toError(error);\n }\n\n if (prepared.branchChange.headAdvanced) {\n currentCompletedWorldId = prepared.worldId;\n }\n\n if (prepared.branchChange.headAdvanced && options?.publishOnCompleted !== false) {\n return {\n intent: enrichedIntent,\n hostResult: result,\n preparedCommit: prepared,\n publishedSnapshot: kernel.setVisibleSnapshot(result.snapshot),\n };\n }\n\n kernel.restoreVisibleSnapshot();\n return {\n intent: enrichedIntent,\n hostResult: result,\n preparedCommit: prepared,\n };\n };\n\n if (options?.assumeEnqueued) {\n return runSeal();\n }\n\n return kernel.enqueue(runSeal);\n }\n\n async function getWorld(worldId: WorldId): Promise<World | null> {\n await ensureReady();\n return service.getWorld(worldId);\n }\n\n async function getLineage(): Promise<WorldLineage> {\n await ensureReady();\n return service.getLineage();\n }\n\n async function getLatestHead(): Promise<WorldHead | null> {\n await ensureReady();\n return service.getLatestHead();\n }\n\n async function getHeads(): Promise<readonly WorldHead[]> {\n await ensureReady();\n return service.getHeads();\n }\n\n async function getBranches(): Promise<readonly BranchInfo[]> {\n await ensureReady();\n return service.getBranches();\n }\n\n async function getActiveBranch(): Promise<BranchInfo> {\n await ensureReady();\n if (currentBranchId) {\n const branch = await service.getBranch(currentBranchId);\n if (branch) {\n return branch;\n }\n }\n return service.getActiveBranch();\n }\n\n async function getCurrentBranchId(): Promise<BranchId> {\n return (await getActiveBranch()).id;\n }\n\n async function getCurrentCompletedWorldId(): Promise<WorldId> {\n await ensureReady();\n if (!currentCompletedWorldId) {\n throw new ManifestoError(\n \"LINEAGE_STATE_ERROR\",\n \"Lineage runtime has no completed world continuity\",\n );\n }\n return currentCompletedWorldId;\n }\n\n async function restore(worldId: WorldId): Promise<void> {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await kernel.enqueue(async () => {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await ensureReady();\n const restored = await service.restore(worldId);\n kernel.setVisibleSnapshot(restored);\n currentCompletedWorldId = worldId;\n\n const branches = await service.getBranches();\n const matchingBranch = branches.find((branch) => branch.head === worldId);\n if (matchingBranch) {\n currentBranchId = matchingBranch.id;\n }\n });\n }\n\n async function switchActiveBranch(branchId: string): Promise<BranchSwitchResult> {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n return kernel.enqueue(async () => {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await ensureReady();\n const result = await service.switchActiveBranch(branchId);\n const branch = await service.getBranch(branchId);\n\n if (!branch) {\n throw new ManifestoError(\n \"LINEAGE_BRANCH_NOT_FOUND\",\n `Cannot switch to unknown branch \"${branchId}\"`,\n );\n }\n\n const restored = await service.restore(branch.head);\n kernel.setVisibleSnapshot(restored);\n currentBranchId = branch.id;\n currentCompletedWorldId = branch.head;\n return result;\n });\n }\n\n async function createBranch(name: string, fromWorldId?: WorldId): Promise<BranchId> {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n return kernel.enqueue(async () => {\n if (kernel.isDisposed()) {\n throw new DisposedError();\n }\n\n await ensureReady();\n const headWorldId = fromWorldId ?? currentCompletedWorldId;\n if (!headWorldId) {\n throw new ManifestoError(\n \"LINEAGE_STATE_ERROR\",\n \"Cannot create a branch before lineage continuity is bootstrapped\",\n );\n }\n\n return service.createBranch(name, headWorldId);\n });\n }\n\n return {\n ensureReady,\n sealIntent,\n getWorld,\n getLineage,\n getLatestHead,\n getHeads,\n getBranches,\n getActiveBranch,\n getCurrentBranchId,\n getCurrentCompletedWorldId,\n restore,\n switchActiveBranch,\n createBranch,\n };\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error\n ? error\n : new Error(String(error));\n}\n","export function assertLineage(condition: unknown, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n","export function cloneValue<T>(value: T): T {\n return structuredClone(value);\n}\n","import { assertLineage } from \"./invariants.js\";\nimport { cloneValue } from \"./internal/clone.js\";\nimport type {\n BranchInfo,\n LineageStore,\n PersistedBranchEntry,\n Snapshot,\n World,\n WorldEdge,\n WorldHead,\n WorldId,\n WorldLineage,\n} from \"./types.js\";\n\ntype EnumerableLineageStore = LineageStore & {\n listWorlds?(): readonly World[];\n listEdges?(): readonly WorldEdge[];\n};\n\nexport function toBranchInfo(entry: PersistedBranchEntry): BranchInfo {\n return {\n id: entry.id,\n name: entry.name,\n head: entry.head,\n tip: entry.tip,\n headAdvancedAt: entry.headAdvancedAt,\n epoch: entry.epoch,\n schemaHash: entry.schemaHash,\n createdAt: entry.createdAt,\n };\n}\n\nexport function toWorldHead(branch: PersistedBranchEntry, world: World): WorldHead {\n return {\n worldId: world.worldId,\n branchId: branch.id,\n branchName: branch.name,\n createdAt: branch.headAdvancedAt,\n schemaHash: branch.schemaHash,\n };\n}\n\nexport function getBranchById(\n branches: readonly PersistedBranchEntry[],\n branchId: string\n): PersistedBranchEntry | null {\n return branches.find((branch) => branch.id === branchId) ?? null;\n}\n\nexport async function getHeadsFromStore(\n store: LineageStore\n): Promise<readonly WorldHead[]> {\n const branches = await store.getBranches();\n\n return Promise.all(branches.map(async (branch) => {\n const world = await store.getWorld(branch.head);\n assertLineage(world != null, `LIN-HEAD-6 violation: missing head world ${branch.head} for branch ${branch.id}`);\n assertLineage(\n world.terminalStatus === \"completed\",\n `LIN-HEAD-3 violation: head world ${branch.head} for branch ${branch.id} must be completed`\n );\n return toWorldHead(branch, world);\n }));\n}\n\nexport function selectLatestHead(heads: readonly WorldHead[]): WorldHead | null {\n if (heads.length === 0) {\n return null;\n }\n\n const sorted = [...heads].sort((left, right) => {\n if (left.createdAt !== right.createdAt) {\n return right.createdAt - left.createdAt;\n }\n if (left.worldId !== right.worldId) {\n return left.worldId < right.worldId ? -1 : 1;\n }\n if (left.branchId === right.branchId) {\n return 0;\n }\n return left.branchId < right.branchId ? -1 : 1;\n });\n\n return sorted[0];\n}\n\nfunction normalizePlatformData(data: Record<string, unknown> | null | undefined): Record<string, unknown> {\n const normalized: Record<string, unknown> = {};\n const source = data ?? {};\n\n for (const [key, value] of Object.entries(source)) {\n if (!key.startsWith(\"$\")) {\n normalized[key] = cloneValue(value);\n continue;\n }\n\n normalized[key] = {};\n }\n\n normalized.$host = {};\n normalized.$mel = { guards: { intent: {} } };\n return normalized;\n}\n\nexport async function restoreSnapshot(\n store: LineageStore,\n worldId: WorldId\n): Promise<Snapshot> {\n const snapshot = await store.getSnapshot(worldId);\n assertLineage(snapshot != null, `LIN-RESUME-2 violation: missing snapshot for world ${worldId}`);\n\n return {\n data: normalizePlatformData(snapshot.data as Record<string, unknown>),\n computed: cloneValue(snapshot.computed),\n system: {\n status: snapshot.system.status,\n lastError: cloneValue(snapshot.system.lastError),\n pendingRequirements: cloneValue(snapshot.system.pendingRequirements),\n currentAction: null,\n },\n input: null,\n meta: {\n version: snapshot.meta.version,\n timestamp: 0,\n randomSeed: \"\",\n schemaHash: snapshot.meta.schemaHash,\n },\n };\n}\n\nexport async function buildWorldLineage(store: LineageStore): Promise<WorldLineage> {\n const enumerable = store as EnumerableLineageStore;\n const worlds = enumerable.listWorlds?.() ?? await collectWorldsFromBranches(store);\n const edges = enumerable.listEdges?.() ?? await collectEdgesFromWorlds(store, worlds);\n\n assertLineage(worlds.length > 0, \"LIN-RESUME-1 violation: lineage is empty\");\n\n const incoming = new Set(edges.map((edge) => edge.to));\n const genesisCandidates = worlds\n .filter((world) => !incoming.has(world.worldId))\n .sort((left, right) => {\n if (left.worldId === right.worldId) {\n return 0;\n }\n return left.worldId < right.worldId ? -1 : 1;\n });\n\n const genesis = genesisCandidates[0]?.worldId ?? worlds[0].worldId;\n\n return {\n genesis,\n worlds: new Map(worlds.map((world) => [world.worldId, cloneValue(world)])),\n edges: new Map(edges.map((edge) => [edge.edgeId, cloneValue(edge)])),\n };\n}\n\nasync function collectWorldsFromBranches(store: LineageStore): Promise<readonly World[]> {\n const worlds = new Map<WorldId, World>();\n const queue = (await store.getBranches()).flatMap((branch) => [branch.head, branch.tip]);\n\n while (queue.length > 0) {\n const nextWorldId = queue.pop()!;\n if (worlds.has(nextWorldId)) {\n continue;\n }\n\n const world = await store.getWorld(nextWorldId);\n if (world == null) {\n continue;\n }\n worlds.set(nextWorldId, world);\n\n if (world.parentWorldId != null && !worlds.has(world.parentWorldId)) {\n queue.push(world.parentWorldId);\n }\n }\n\n return [...worlds.values()];\n}\n\nasync function collectEdgesFromWorlds(\n store: LineageStore,\n worlds: readonly World[]\n): Promise<readonly WorldEdge[]> {\n const edges = new Map<string, WorldEdge>();\n\n for (const world of worlds) {\n for (const edge of await store.getEdges(world.worldId)) {\n edges.set(edge.edgeId, edge);\n }\n }\n\n return [...edges.values()];\n}\n","import type { ErrorValue, Requirement, Snapshot } from \"@manifesto-ai/core\";\nimport { sha256Sync, toJcs } from \"@manifesto-ai/core\";\nimport { assertLineage } from \"./invariants.js\";\nimport type {\n CurrentErrorSignature,\n SnapshotHashInput,\n TerminalStatus,\n WorldId,\n} from \"./types.js\";\n\nconst PLATFORM_NAMESPACE_PREFIX = \"$\";\n\nexport function computeHash(value: unknown): string {\n return sha256Sync(toJcs(value));\n}\n\nexport function isPlatformNamespace(key: string): boolean {\n return key.startsWith(PLATFORM_NAMESPACE_PREFIX);\n}\n\nexport function stripPlatformNamespaces(data: Record<string, unknown> | null | undefined): Record<string, unknown> {\n if (data == null) {\n return {};\n }\n\n const keys = Object.keys(data);\n if (!keys.some(isPlatformNamespace)) {\n return data;\n }\n\n const stripped: Record<string, unknown> = {};\n for (const key of keys) {\n if (!isPlatformNamespace(key)) {\n stripped[key] = data[key];\n }\n }\n return stripped;\n}\n\nexport function deriveTerminalStatus(snapshot: Snapshot): TerminalStatus {\n if (snapshot.system.pendingRequirements.length > 0) {\n return \"failed\";\n }\n if (snapshot.system.lastError != null) {\n return \"failed\";\n }\n return \"completed\";\n}\n\nfunction normalizeDeterministicValue(value: unknown): unknown {\n if (value === null) {\n return null;\n }\n\n switch (typeof value) {\n case \"string\":\n case \"boolean\":\n return value;\n case \"number\":\n return Number.isFinite(value) ? value : null;\n case \"bigint\":\n case \"function\":\n case \"symbol\":\n case \"undefined\":\n return undefined;\n case \"object\":\n if (Array.isArray(value)) {\n return value\n .map((item) => normalizeDeterministicValue(item))\n .filter((item) => item !== undefined);\n }\n\n return normalizeContext(value as Record<string, unknown>);\n default:\n return undefined;\n }\n}\n\nexport function normalizeContext(ctx: Record<string, unknown>): Record<string, unknown> | undefined {\n const normalized: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(ctx)) {\n const nextValue = normalizeDeterministicValue(value);\n if (nextValue !== undefined) {\n normalized[key] = nextValue;\n }\n }\n\n return Object.keys(normalized).length > 0 ? normalized : undefined;\n}\n\nexport function toCurrentErrorSignature(error: ErrorValue): CurrentErrorSignature {\n return {\n code: error.code,\n source: {\n actionId: error.source.actionId,\n nodePath: error.source.nodePath,\n },\n };\n}\n\nexport function computePendingDigest(pendingRequirements: readonly Requirement[]): string {\n if (pendingRequirements.length === 0) {\n return \"empty\";\n }\n\n const pendingIds = pendingRequirements.map((requirement) => requirement.id).sort();\n return computeHash({ pendingIds });\n}\n\nexport function createSnapshotHashInput(snapshot: Snapshot): SnapshotHashInput {\n return {\n data: stripPlatformNamespaces(snapshot.data as Record<string, unknown>),\n system: {\n terminalStatus: deriveTerminalStatus(snapshot),\n currentError: snapshot.system.lastError == null\n ? null\n : toCurrentErrorSignature(snapshot.system.lastError),\n pendingDigest: computePendingDigest(snapshot.system.pendingRequirements),\n },\n };\n}\n\nexport function computeSnapshotHash(snapshot: Snapshot): string {\n return computeHash(createSnapshotHashInput(snapshot));\n}\n\nexport function computeWorldId(\n schemaHash: string,\n snapshotHash: string,\n parentWorldId: WorldId | null\n): WorldId {\n return computeHash({ schemaHash, snapshotHash, parentWorldId });\n}\n\nexport function computeBranchId(branchName: string, worldId: WorldId): string {\n return computeHash({\n kind: \"genesis-branch\",\n branchName,\n worldId,\n });\n}\n\nexport function computeEdgeId(from: WorldId, to: WorldId): string {\n assertLineage(from !== to, \"LIN-COLLISION-2 violation: edge must not be a self-loop\");\n return computeHash({ from, to });\n}\n","import { assertLineage } from \"./invariants.js\";\nimport {\n computeBranchId,\n computeEdgeId,\n computeHash,\n computeSnapshotHash,\n computeWorldId,\n createSnapshotHashInput,\n deriveTerminalStatus,\n} from \"./hash.js\";\nimport type {\n BranchId,\n PersistedBranchEntry,\n SealAttempt,\n SealGenesisInput,\n SealNextInput,\n Snapshot,\n SnapshotHashInput,\n World,\n WorldEdge,\n WorldId,\n} from \"./types.js\";\n\nexport interface WorldRecordResult {\n readonly world: World;\n readonly hashInput: SnapshotHashInput;\n readonly worldId: WorldId;\n}\n\nexport function createWorldRecord(\n schemaHash: string,\n terminalSnapshot: Snapshot,\n parentWorldId: WorldId | null\n): WorldRecordResult {\n assertLineage(\n schemaHash === terminalSnapshot.meta.schemaHash,\n `LIN-SCHEMA-1 violation: provided schemaHash (${schemaHash}) does not match snapshot.meta.schemaHash (${terminalSnapshot.meta.schemaHash})`\n );\n\n const terminalStatus = deriveTerminalStatus(terminalSnapshot);\n const hashInput = createSnapshotHashInput(terminalSnapshot);\n const snapshotHash = computeSnapshotHash(terminalSnapshot);\n const worldId = computeWorldId(schemaHash, snapshotHash, parentWorldId);\n\n return {\n worldId,\n hashInput,\n world: {\n worldId,\n schemaHash,\n snapshotHash,\n parentWorldId,\n terminalStatus,\n },\n };\n}\n\nexport function createWorldEdge(from: WorldId, to: WorldId): WorldEdge {\n return {\n edgeId: computeEdgeId(from, to),\n from,\n to,\n };\n}\n\nexport function createGenesisBranchEntry(input: SealGenesisInput, worldId: WorldId): PersistedBranchEntry {\n const branchName = input.branchName ?? \"main\";\n const branchId: BranchId = computeBranchId(branchName, worldId);\n\n return {\n id: branchId,\n name: branchName,\n head: worldId,\n tip: worldId,\n headAdvancedAt: input.createdAt,\n epoch: 0,\n schemaHash: input.schemaHash,\n createdAt: input.createdAt,\n };\n}\n\nexport function createSealGenesisAttempt(\n branchId: BranchId,\n worldId: WorldId,\n input: SealGenesisInput\n): SealAttempt {\n return {\n attemptId: computeHash({ worldId, branchId, createdAt: input.createdAt }),\n worldId,\n branchId,\n baseWorldId: null,\n parentWorldId: null,\n proposalRef: input.proposalRef,\n createdAt: input.createdAt,\n traceRef: input.traceRef,\n reused: false,\n };\n}\n\nexport function createSealNextAttempt(\n branchId: BranchId,\n worldId: WorldId,\n parentWorldId: WorldId,\n input: SealNextInput\n): SealAttempt {\n return {\n attemptId: computeHash({ worldId, branchId, createdAt: input.createdAt }),\n worldId,\n branchId,\n baseWorldId: input.baseWorldId,\n parentWorldId,\n proposalRef: input.proposalRef,\n decisionRef: input.decisionRef,\n createdAt: input.createdAt,\n traceRef: input.traceRef,\n patchDelta: input.patchDelta,\n reused: false,\n };\n}\n","import { assertLineage } from \"../invariants.js\";\nimport {\n buildWorldLineage,\n getBranchById,\n getHeadsFromStore,\n restoreSnapshot,\n selectLatestHead,\n toBranchInfo,\n} from \"../query.js\";\nimport {\n createGenesisBranchEntry,\n createSealGenesisAttempt,\n createSealNextAttempt,\n createWorldEdge,\n createWorldRecord,\n} from \"../records.js\";\nimport { computeHash } from \"../hash.js\";\nimport type {\n BranchId,\n BranchInfo,\n BranchSwitchResult,\n LineageService,\n LineageStore,\n PersistedBranchEntry,\n SealGenesisInput,\n SealNextInput,\n Snapshot,\n World,\n WorldHead,\n WorldId,\n WorldLineage,\n} from \"../types.js\";\n\nexport class DefaultLineageService implements LineageService {\n public constructor(private readonly store: LineageStore) {}\n\n async prepareSealGenesis(input: SealGenesisInput) {\n assertLineage(\n (await this.store.getBranches()).length === 0,\n \"LIN-GENESIS-3 violation: genesis requires empty branch state\"\n );\n\n const record = createWorldRecord(\n input.schemaHash,\n input.terminalSnapshot,\n null\n );\n\n assertLineage(\n record.world.terminalStatus === \"completed\",\n \"LIN-GENESIS-1 violation: genesis snapshot must derive terminalStatus 'completed'\"\n );\n assertLineage(\n (await this.store.getWorld(record.worldId)) == null,\n `LIN-COLLISION-3 violation: genesis world ${record.worldId} already exists`\n );\n\n const branch = createGenesisBranchEntry(input, record.worldId);\n\n return {\n kind: \"genesis\" as const,\n branchId: branch.id,\n worldId: record.worldId,\n world: record.world,\n terminalSnapshot: input.terminalSnapshot,\n hashInput: record.hashInput,\n attempt: createSealGenesisAttempt(branch.id, record.worldId, input),\n terminalStatus: \"completed\" as const,\n edge: null,\n branchChange: {\n kind: \"bootstrap\" as const,\n branch,\n activeBranchId: branch.id,\n },\n };\n }\n\n async prepareSealNext(input: SealNextInput) {\n const branchHead = await this.store.getBranchHead(input.branchId);\n assertLineage(branchHead != null, `LIN-BRANCH-SEAL-2 violation: unknown branch ${input.branchId}`);\n assertLineage(\n branchHead === input.baseWorldId,\n `LIN-BRANCH-SEAL-2 violation: branch ${input.branchId} head ${branchHead} does not match baseWorldId ${input.baseWorldId}`\n );\n\n const branchTip = await this.store.getBranchTip(input.branchId);\n assertLineage(branchTip != null, `LIN-EPOCH-5 violation: branch ${input.branchId} tip is not set`);\n\n const baseWorld = await this.store.getWorld(input.baseWorldId);\n assertLineage(baseWorld != null, `LIN-BASE-1 violation: base world ${input.baseWorldId} does not exist`);\n assertLineage(\n baseWorld.schemaHash === input.schemaHash,\n `LIN-BASE-4 violation: base world schemaHash ${baseWorld.schemaHash} does not match input ${input.schemaHash}`\n );\n assertLineage(\n baseWorld.terminalStatus !== \"failed\",\n `LIN-BASE-3 violation: failed base world ${input.baseWorldId} cannot be used as base`\n );\n\n const baseSnapshot = await this.store.getSnapshot(input.baseWorldId);\n assertLineage(baseSnapshot != null, `LIN-PERSIST-BASE-1 violation: missing snapshot for base world ${input.baseWorldId}`);\n assertLineage(\n baseSnapshot.system.pendingRequirements.length === 0,\n `LIN-BASE-2 violation: base world ${input.baseWorldId} has pending requirements`\n );\n\n if (input.patchDelta != null) {\n assertLineage(\n input.patchDelta._patchFormat === 2,\n \"LIN-PERSIST-PATCH-2 violation: only _patchFormat: 2 is supported\"\n );\n }\n\n const record = createWorldRecord(\n input.schemaHash,\n input.terminalSnapshot,\n branchTip\n );\n\n const expectedEpoch = await this.store.getBranchEpoch(input.branchId);\n const headAdvanced = record.world.terminalStatus === \"completed\";\n const forkCreated = (await this.store.getEdges(branchTip))\n .some((candidate) => candidate.from === branchTip);\n const edge = createWorldEdge(branchTip, record.worldId);\n\n return {\n kind: \"next\" as const,\n branchId: input.branchId,\n worldId: record.worldId,\n world: record.world,\n terminalSnapshot: input.terminalSnapshot,\n hashInput: record.hashInput,\n attempt: createSealNextAttempt(input.branchId, record.worldId, branchTip, input),\n terminalStatus: record.world.terminalStatus,\n edge,\n forkCreated,\n branchChange: {\n kind: \"advance\" as const,\n branchId: input.branchId,\n expectedHead: input.baseWorldId,\n nextHead: headAdvanced ? record.worldId : input.baseWorldId,\n headAdvanced,\n expectedTip: branchTip,\n nextTip: record.worldId,\n headAdvancedAt: headAdvanced ? input.createdAt : null,\n expectedEpoch,\n nextEpoch: headAdvanced ? expectedEpoch + 1 : expectedEpoch,\n },\n };\n }\n\n async commitPrepared(\n prepared: Parameters<LineageService[\"commitPrepared\"]>[0]\n ): Promise<void> {\n await this.store.commitPrepared(prepared);\n }\n\n async createBranch(name: string, headWorldId: WorldId): Promise<BranchId> {\n const world = await this.store.getWorld(headWorldId);\n assertLineage(world != null, `LIN-BRANCH-CREATE-1 violation: head world ${headWorldId} does not exist`);\n assertLineage(\n world.terminalStatus === \"completed\",\n `LIN-BRANCH-CREATE-2 violation: head world ${headWorldId} must be completed`\n );\n\n const branches = await this.store.getBranches();\n const branchId = computeHash({ kind: \"branch\", name, headWorldId, ordinal: branches.length });\n const branchCreatedAt = branches.reduce((latest, branch) => {\n return Math.max(latest, branch.createdAt, branch.headAdvancedAt);\n }, 0) + 1;\n\n const branch: PersistedBranchEntry = {\n id: branchId,\n name,\n head: headWorldId,\n tip: headWorldId,\n headAdvancedAt: branchCreatedAt,\n epoch: 0,\n schemaHash: world.schemaHash,\n createdAt: branchCreatedAt,\n };\n\n await this.store.putBranch(branch);\n return branchId;\n }\n\n async getBranch(branchId: BranchId): Promise<BranchInfo | null> {\n const branch = getBranchById(await this.store.getBranches(), branchId);\n return branch ? toBranchInfo(branch) : null;\n }\n\n async getBranches(): Promise<readonly BranchInfo[]> {\n return (await this.store.getBranches()).map(toBranchInfo);\n }\n\n async getActiveBranch(): Promise<BranchInfo> {\n const activeBranchId = await this.store.getActiveBranchId();\n assertLineage(activeBranchId != null, \"LIN-BRANCH-PERSIST-3 violation: active branch is not set\");\n const branch = await this.getBranch(activeBranchId);\n assertLineage(branch != null, `LIN-BRANCH-PERSIST-1 violation: missing active branch ${activeBranchId}`);\n return branch;\n }\n\n async switchActiveBranch(\n targetBranchId: BranchId\n ): Promise<BranchSwitchResult> {\n const previousBranchId = await this.store.getActiveBranchId();\n assertLineage(previousBranchId != null, \"LIN-SWITCH-1 violation: active branch is not set\");\n await this.store.switchActiveBranch(previousBranchId, targetBranchId);\n return {\n previousBranchId,\n targetBranchId,\n sourceBranchEpochAfter: await this.store.getBranchEpoch(previousBranchId),\n };\n }\n\n async getWorld(worldId: WorldId): Promise<World | null> {\n return this.store.getWorld(worldId);\n }\n\n async getSnapshot(worldId: WorldId): Promise<Snapshot | null> {\n return this.store.getSnapshot(worldId);\n }\n\n async getAttempts(worldId: WorldId) {\n return this.store.getAttempts(worldId);\n }\n\n async getAttemptsByBranch(branchId: BranchId) {\n return this.store.getAttemptsByBranch(branchId);\n }\n\n async getLineage(): Promise<WorldLineage> {\n return buildWorldLineage(this.store);\n }\n\n async getHeads(): Promise<readonly WorldHead[]> {\n return getHeadsFromStore(this.store);\n }\n\n async getLatestHead(): Promise<WorldHead | null> {\n return selectLatestHead(await this.getHeads());\n }\n\n async restore(worldId: WorldId): Promise<Snapshot> {\n return restoreSnapshot(this.store, worldId);\n }\n}\n\nexport function createLineageService(store: LineageStore): LineageService {\n return new DefaultLineageService(store);\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAMK;;;ACRA,SAAS,cAAc,WAAoB,SAAoC;AACpF,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACF;;;ACJO,SAAS,WAAc,OAAa;AACzC,SAAO,gBAAgB,KAAK;AAC9B;;;ACiBO,SAAS,aAAa,OAAyC;AACpE,SAAO;AAAA,IACL,IAAI,MAAM;AAAA,IACV,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,KAAK,MAAM;AAAA,IACX,gBAAgB,MAAM;AAAA,IACtB,OAAO,MAAM;AAAA,IACb,YAAY,MA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