@paraharness/sqlite 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -2
  3. package/dist/builders/compaction-config-builder.d.ts +66 -0
  4. package/dist/builders/compaction-config-builder.d.ts.map +1 -0
  5. package/dist/builders/compaction-config-builder.js +2 -0
  6. package/dist/builders/compaction-config-builder.js.map +1 -0
  7. package/dist/builders/create-compaction-config-builder.d.ts +14 -0
  8. package/dist/builders/create-compaction-config-builder.d.ts.map +1 -0
  9. package/dist/builders/create-compaction-config-builder.js +66 -0
  10. package/dist/builders/create-compaction-config-builder.js.map +1 -0
  11. package/dist/builders/create-sqlite-global-rules-builder.d.ts +15 -0
  12. package/dist/builders/create-sqlite-global-rules-builder.d.ts.map +1 -0
  13. package/dist/builders/create-sqlite-global-rules-builder.js +30 -0
  14. package/dist/builders/create-sqlite-global-rules-builder.js.map +1 -0
  15. package/dist/builders/create-sqlite-ledger-builder.d.ts +15 -0
  16. package/dist/builders/create-sqlite-ledger-builder.d.ts.map +1 -0
  17. package/dist/builders/create-sqlite-ledger-builder.js +31 -0
  18. package/dist/builders/create-sqlite-ledger-builder.js.map +1 -0
  19. package/dist/builders/create-sqlite-lessons-builder.d.ts +12 -0
  20. package/dist/builders/create-sqlite-lessons-builder.d.ts.map +1 -0
  21. package/dist/builders/create-sqlite-lessons-builder.js +23 -0
  22. package/dist/builders/create-sqlite-lessons-builder.js.map +1 -0
  23. package/dist/builders/create-sqlite-topology-builder.d.ts +12 -0
  24. package/dist/builders/create-sqlite-topology-builder.d.ts.map +1 -0
  25. package/dist/builders/create-sqlite-topology-builder.js +23 -0
  26. package/dist/builders/create-sqlite-topology-builder.js.map +1 -0
  27. package/dist/builders/internal/compaction-config-builder-state.d.ts +16 -0
  28. package/dist/builders/internal/compaction-config-builder-state.d.ts.map +1 -0
  29. package/dist/builders/internal/compaction-config-builder-state.js +2 -0
  30. package/dist/builders/internal/compaction-config-builder-state.js.map +1 -0
  31. package/dist/builders/sqlite-global-rules-builder.d.ts +17 -0
  32. package/dist/builders/sqlite-global-rules-builder.d.ts.map +1 -0
  33. package/dist/builders/sqlite-global-rules-builder.js +2 -0
  34. package/dist/builders/sqlite-global-rules-builder.js.map +1 -0
  35. package/dist/builders/sqlite-ledger-builder.d.ts +21 -0
  36. package/dist/builders/sqlite-ledger-builder.d.ts.map +1 -0
  37. package/dist/builders/sqlite-ledger-builder.js +2 -0
  38. package/dist/builders/sqlite-ledger-builder.js.map +1 -0
  39. package/dist/builders/sqlite-lessons-builder.d.ts +18 -0
  40. package/dist/builders/sqlite-lessons-builder.d.ts.map +1 -0
  41. package/dist/builders/sqlite-lessons-builder.js +2 -0
  42. package/dist/builders/sqlite-lessons-builder.js.map +1 -0
  43. package/dist/builders/sqlite-namespace-contract.d.ts +64 -0
  44. package/dist/builders/sqlite-namespace-contract.d.ts.map +1 -0
  45. package/dist/builders/sqlite-namespace-contract.js +2 -0
  46. package/dist/builders/sqlite-namespace-contract.js.map +1 -0
  47. package/dist/builders/sqlite-namespace.d.ts +9 -0
  48. package/dist/builders/sqlite-namespace.d.ts.map +1 -0
  49. package/dist/builders/sqlite-namespace.js +17 -0
  50. package/dist/builders/sqlite-namespace.js.map +1 -0
  51. package/dist/builders/sqlite-topology-builder.d.ts +18 -0
  52. package/dist/builders/sqlite-topology-builder.d.ts.map +1 -0
  53. package/dist/builders/sqlite-topology-builder.js +2 -0
  54. package/dist/builders/sqlite-topology-builder.js.map +1 -0
  55. package/dist/ddl/internal/open-sqlite-connection.d.ts +24 -0
  56. package/dist/ddl/internal/open-sqlite-connection.d.ts.map +1 -0
  57. package/dist/ddl/internal/open-sqlite-connection.js +65 -0
  58. package/dist/ddl/internal/open-sqlite-connection.js.map +1 -0
  59. package/dist/ddl/sqlite-schema.constants.d.ts +21 -0
  60. package/dist/ddl/sqlite-schema.constants.d.ts.map +1 -0
  61. package/dist/ddl/sqlite-schema.constants.js +134 -0
  62. package/dist/ddl/sqlite-schema.constants.js.map +1 -0
  63. package/dist/executors/create-sqlite-executors.d.ts +11 -0
  64. package/dist/executors/create-sqlite-executors.d.ts.map +1 -0
  65. package/dist/executors/create-sqlite-executors.js +38 -0
  66. package/dist/executors/create-sqlite-executors.js.map +1 -0
  67. package/dist/executors/sqlite-executors.constants.d.ts +9 -0
  68. package/dist/executors/sqlite-executors.constants.d.ts.map +1 -0
  69. package/dist/executors/sqlite-executors.constants.js +9 -0
  70. package/dist/executors/sqlite-executors.constants.js.map +1 -0
  71. package/dist/executors/sqlite-rules-source-executor.d.ts +15 -0
  72. package/dist/executors/sqlite-rules-source-executor.d.ts.map +1 -0
  73. package/dist/executors/sqlite-rules-source-executor.js +47 -0
  74. package/dist/executors/sqlite-rules-source-executor.js.map +1 -0
  75. package/dist/index.d.ts +23 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +16 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/stores/internal/admit-lesson-params.d.ts +16 -0
  80. package/dist/stores/internal/admit-lesson-params.d.ts.map +1 -0
  81. package/dist/stores/internal/admit-lesson-params.js +2 -0
  82. package/dist/stores/internal/admit-lesson-params.js.map +1 -0
  83. package/dist/stores/internal/compute-normalized-relevance.d.ts +47 -0
  84. package/dist/stores/internal/compute-normalized-relevance.d.ts.map +1 -0
  85. package/dist/stores/internal/compute-normalized-relevance.js +63 -0
  86. package/dist/stores/internal/compute-normalized-relevance.js.map +1 -0
  87. package/dist/stores/internal/mark-frame-tombstone-params.d.ts +16 -0
  88. package/dist/stores/internal/mark-frame-tombstone-params.d.ts.map +1 -0
  89. package/dist/stores/internal/mark-frame-tombstone-params.js +2 -0
  90. package/dist/stores/internal/mark-frame-tombstone-params.js.map +1 -0
  91. package/dist/stores/internal/record-terminal-receipt-params.d.ts +16 -0
  92. package/dist/stores/internal/record-terminal-receipt-params.d.ts.map +1 -0
  93. package/dist/stores/internal/record-terminal-receipt-params.js +2 -0
  94. package/dist/stores/internal/record-terminal-receipt-params.js.map +1 -0
  95. package/dist/stores/internal/sqlite-ledger-compaction-ops.d.ts +14 -0
  96. package/dist/stores/internal/sqlite-ledger-compaction-ops.d.ts.map +1 -0
  97. package/dist/stores/internal/sqlite-ledger-compaction-ops.js +29 -0
  98. package/dist/stores/internal/sqlite-ledger-compaction-ops.js.map +1 -0
  99. package/dist/stores/internal/sqlite-ledger-fork-operations.d.ts +33 -0
  100. package/dist/stores/internal/sqlite-ledger-fork-operations.d.ts.map +1 -0
  101. package/dist/stores/internal/sqlite-ledger-fork-operations.js +44 -0
  102. package/dist/stores/internal/sqlite-ledger-fork-operations.js.map +1 -0
  103. package/dist/stores/internal/sqlite-ledger-frame-operations.d.ts +24 -0
  104. package/dist/stores/internal/sqlite-ledger-frame-operations.d.ts.map +1 -0
  105. package/dist/stores/internal/sqlite-ledger-frame-operations.js +40 -0
  106. package/dist/stores/internal/sqlite-ledger-frame-operations.js.map +1 -0
  107. package/dist/stores/internal/sqlite-ledger-frame-ops.d.ts +50 -0
  108. package/dist/stores/internal/sqlite-ledger-frame-ops.d.ts.map +1 -0
  109. package/dist/stores/internal/sqlite-ledger-frame-ops.js +90 -0
  110. package/dist/stores/internal/sqlite-ledger-frame-ops.js.map +1 -0
  111. package/dist/stores/internal/sqlite-ledger-plan-and-fork-ops.d.ts +59 -0
  112. package/dist/stores/internal/sqlite-ledger-plan-and-fork-ops.d.ts.map +1 -0
  113. package/dist/stores/internal/sqlite-ledger-plan-and-fork-ops.js +90 -0
  114. package/dist/stores/internal/sqlite-ledger-plan-and-fork-ops.js.map +1 -0
  115. package/dist/stores/internal/sqlite-ledger-plan-operations.d.ts +40 -0
  116. package/dist/stores/internal/sqlite-ledger-plan-operations.d.ts.map +1 -0
  117. package/dist/stores/internal/sqlite-ledger-plan-operations.js +39 -0
  118. package/dist/stores/internal/sqlite-ledger-plan-operations.js.map +1 -0
  119. package/dist/stores/internal/sqlite-ledger-run-operations.d.ts +41 -0
  120. package/dist/stores/internal/sqlite-ledger-run-operations.d.ts.map +1 -0
  121. package/dist/stores/internal/sqlite-ledger-run-operations.js +89 -0
  122. package/dist/stores/internal/sqlite-ledger-run-operations.js.map +1 -0
  123. package/dist/stores/internal/sqlite-ledger-run-ops.d.ts +58 -0
  124. package/dist/stores/internal/sqlite-ledger-run-ops.d.ts.map +1 -0
  125. package/dist/stores/internal/sqlite-ledger-run-ops.js +80 -0
  126. package/dist/stores/internal/sqlite-ledger-run-ops.js.map +1 -0
  127. package/dist/stores/internal/sqlite-ledger-step-operations.d.ts +28 -0
  128. package/dist/stores/internal/sqlite-ledger-step-operations.d.ts.map +1 -0
  129. package/dist/stores/internal/sqlite-ledger-step-operations.js +53 -0
  130. package/dist/stores/internal/sqlite-ledger-step-operations.js.map +1 -0
  131. package/dist/stores/internal/sqlite-ledger-step-ops.d.ts +47 -0
  132. package/dist/stores/internal/sqlite-ledger-step-ops.d.ts.map +1 -0
  133. package/dist/stores/internal/sqlite-ledger-step-ops.js +89 -0
  134. package/dist/stores/internal/sqlite-ledger-step-ops.js.map +1 -0
  135. package/dist/stores/internal/sqlite-lesson-ops.d.ts +100 -0
  136. package/dist/stores/internal/sqlite-lesson-ops.d.ts.map +1 -0
  137. package/dist/stores/internal/sqlite-lesson-ops.js +178 -0
  138. package/dist/stores/internal/sqlite-lesson-ops.js.map +1 -0
  139. package/dist/stores/internal/sqlite-lesson-row.d.ts +28 -0
  140. package/dist/stores/internal/sqlite-lesson-row.d.ts.map +1 -0
  141. package/dist/stores/internal/sqlite-lesson-row.js +2 -0
  142. package/dist/stores/internal/sqlite-lesson-row.js.map +1 -0
  143. package/dist/stores/internal/sqlite-overlay-step-mutation-entry.d.ts +21 -0
  144. package/dist/stores/internal/sqlite-overlay-step-mutation-entry.d.ts.map +1 -0
  145. package/dist/stores/internal/sqlite-overlay-step-mutation-entry.js +2 -0
  146. package/dist/stores/internal/sqlite-overlay-step-mutation-entry.js.map +1 -0
  147. package/dist/stores/internal/sqlite-run-row.d.ts +36 -0
  148. package/dist/stores/internal/sqlite-run-row.d.ts.map +1 -0
  149. package/dist/stores/internal/sqlite-run-row.js +2 -0
  150. package/dist/stores/internal/sqlite-run-row.js.map +1 -0
  151. package/dist/stores/internal/sqlite-step-row.d.ts +32 -0
  152. package/dist/stores/internal/sqlite-step-row.d.ts.map +1 -0
  153. package/dist/stores/internal/sqlite-step-row.js +2 -0
  154. package/dist/stores/internal/sqlite-step-row.js.map +1 -0
  155. package/dist/stores/internal/sqlite-suspended-fork-row.d.ts +22 -0
  156. package/dist/stores/internal/sqlite-suspended-fork-row.d.ts.map +1 -0
  157. package/dist/stores/internal/sqlite-suspended-fork-row.js +2 -0
  158. package/dist/stores/internal/sqlite-suspended-fork-row.js.map +1 -0
  159. package/dist/stores/internal/sqlite-topology-base-row.d.ts +18 -0
  160. package/dist/stores/internal/sqlite-topology-base-row.d.ts.map +1 -0
  161. package/dist/stores/internal/sqlite-topology-base-row.js +2 -0
  162. package/dist/stores/internal/sqlite-topology-base-row.js.map +1 -0
  163. package/dist/stores/internal/sqlite-topology-commit-ops.d.ts +37 -0
  164. package/dist/stores/internal/sqlite-topology-commit-ops.d.ts.map +1 -0
  165. package/dist/stores/internal/sqlite-topology-commit-ops.js +58 -0
  166. package/dist/stores/internal/sqlite-topology-commit-ops.js.map +1 -0
  167. package/dist/stores/internal/sqlite-topology-overlay-commit.d.ts +25 -0
  168. package/dist/stores/internal/sqlite-topology-overlay-commit.d.ts.map +1 -0
  169. package/dist/stores/internal/sqlite-topology-overlay-commit.js +51 -0
  170. package/dist/stores/internal/sqlite-topology-overlay-commit.js.map +1 -0
  171. package/dist/stores/internal/sqlite-topology-overlay-ops.d.ts +61 -0
  172. package/dist/stores/internal/sqlite-topology-overlay-ops.d.ts.map +1 -0
  173. package/dist/stores/internal/sqlite-topology-overlay-ops.js +156 -0
  174. package/dist/stores/internal/sqlite-topology-overlay-ops.js.map +1 -0
  175. package/dist/stores/internal/sqlite-topology-overlay-row.d.ts +40 -0
  176. package/dist/stores/internal/sqlite-topology-overlay-row.d.ts.map +1 -0
  177. package/dist/stores/internal/sqlite-topology-overlay-row.js +2 -0
  178. package/dist/stores/internal/sqlite-topology-overlay-row.js.map +1 -0
  179. package/dist/stores/internal/sqlite-topology-overlay-sync.d.ts +72 -0
  180. package/dist/stores/internal/sqlite-topology-overlay-sync.d.ts.map +1 -0
  181. package/dist/stores/internal/sqlite-topology-overlay-sync.js +116 -0
  182. package/dist/stores/internal/sqlite-topology-overlay-sync.js.map +1 -0
  183. package/dist/stores/internal/sqlite-wire-frame-row.d.ts +26 -0
  184. package/dist/stores/internal/sqlite-wire-frame-row.d.ts.map +1 -0
  185. package/dist/stores/internal/sqlite-wire-frame-row.js +2 -0
  186. package/dist/stores/internal/sqlite-wire-frame-row.js.map +1 -0
  187. package/dist/stores/internal/three-way-merge-contract.d.ts +25 -0
  188. package/dist/stores/internal/three-way-merge-contract.d.ts.map +1 -0
  189. package/dist/stores/internal/three-way-merge-contract.js +76 -0
  190. package/dist/stores/internal/three-way-merge-contract.js.map +1 -0
  191. package/dist/stores/internal/update-continuation-stack-params.d.ts +17 -0
  192. package/dist/stores/internal/update-continuation-stack-params.d.ts.map +1 -0
  193. package/dist/stores/internal/update-continuation-stack-params.js +2 -0
  194. package/dist/stores/internal/update-continuation-stack-params.js.map +1 -0
  195. package/dist/stores/internal/update-contract-in-overlay-params.d.ts +16 -0
  196. package/dist/stores/internal/update-contract-in-overlay-params.d.ts.map +1 -0
  197. package/dist/stores/internal/update-contract-in-overlay-params.js +2 -0
  198. package/dist/stores/internal/update-contract-in-overlay-params.js.map +1 -0
  199. package/dist/stores/internal/validate-lane-dag.d.ts +59 -0
  200. package/dist/stores/internal/validate-lane-dag.d.ts.map +1 -0
  201. package/dist/stores/internal/validate-lane-dag.js +117 -0
  202. package/dist/stores/internal/validate-lane-dag.js.map +1 -0
  203. package/dist/stores/sqlite-ledger-store.d.ts +222 -0
  204. package/dist/stores/sqlite-ledger-store.d.ts.map +1 -0
  205. package/dist/stores/sqlite-ledger-store.js +295 -0
  206. package/dist/stores/sqlite-ledger-store.js.map +1 -0
  207. package/dist/stores/sqlite-lesson-store.d.ts +96 -0
  208. package/dist/stores/sqlite-lesson-store.d.ts.map +1 -0
  209. package/dist/stores/sqlite-lesson-store.js +121 -0
  210. package/dist/stores/sqlite-lesson-store.js.map +1 -0
  211. package/dist/stores/sqlite-topology-store.d.ts +112 -0
  212. package/dist/stores/sqlite-topology-store.d.ts.map +1 -0
  213. package/dist/stores/sqlite-topology-store.js +137 -0
  214. package/dist/stores/sqlite-topology-store.js.map +1 -0
  215. package/package.json +70 -3
@@ -0,0 +1,59 @@
1
+ import type { MutateLanePlanRequest, SuspendedForkRecord } from '@paraharness/core';
2
+ import type Database from 'better-sqlite3';
3
+ /**
4
+ * Optional filter criteria for querying unresolved suspended forks in `getSuspendedForks`.
5
+ */
6
+ export interface GetSuspendedForksOptions {
7
+ /** Optional list of logical `forkId` or monotonic `suspendedForkId` values to match. */
8
+ readonly forkIds?: readonly string[];
9
+ /** Optional parent `stepExecId` that spawned the suspended fork. */
10
+ readonly parentStepExecId?: string;
11
+ }
12
+ /**
13
+ * Atomically chains spawned prerequisite items and validates DAG acyclicity and `maxPrerequisiteDepth`.
14
+ *
15
+ * Enforces linear prerequisite stacking ($T_{\text{prevTip}} \leftarrow T_1 \leftarrow \dots \leftarrow T_k \leftarrow T_{\text{parent}}$)
16
+ * and rejects cycles or depth violations before mutating `harness_lane_items` and `harness_runs`.
17
+ *
18
+ * @param {Database.Database} db - Active SQLite database handle.
19
+ * @param {MutateLanePlanRequest} req - Lane plan mutation request.
20
+ *
21
+ * @returns {void} Returns nothing once the DAG mutation is committed.
22
+ */
23
+ export declare function mutateLanePlanInSqlite(db: Database.Database, req: MutateLanePlanRequest): void;
24
+ /**
25
+ * Persists a `SuspendedForkRecord` in `harness_suspended_forks`.
26
+ *
27
+ * Stores the monotonic `${forkId}#${suspensionEpoch}` identifier and full continuation stack.
28
+ *
29
+ * @param {Database.Database} db - Active SQLite database handle.
30
+ * @param {SuspendedForkRecord} record - Suspended fork snapshot to persist.
31
+ *
32
+ * @returns {void} Returns nothing once the suspension record is saved.
33
+ */
34
+ export declare function recordForkSuspensionInSqlite(db: Database.Database, record: SuspendedForkRecord): void;
35
+ /**
36
+ * Queries unresolved (`resolution_status IS NULL`) suspended forks for `runId`.
37
+ *
38
+ * Supports optional filtering by `forkIds` (matching `forkId` or `suspendedForkId`) and `parentStepExecId`.
39
+ *
40
+ * @param {Database.Database} db - Active SQLite database handle.
41
+ * @param {string} runId - Enclosing flow run identifier.
42
+ * @param {GetSuspendedForksOptions} [opts] - Optional filter criteria.
43
+ *
44
+ * @returns {readonly SuspendedForkRecord[]} Matching unresolved suspended fork records.
45
+ */
46
+ export declare function getSuspendedForksFromSqlite(db: Database.Database, runId: string, opts?: GetSuspendedForksOptions): readonly SuspendedForkRecord[];
47
+ /**
48
+ * Marks `suspendedForkId` and any earlier unresolved epochs `${forkId}#1 .. ${forkId}#${epoch}` as resolved.
49
+ *
50
+ * Guarantees recursive epoch resolution safety (`SPEC.md` §3.7.2) so prior epochs never remain open.
51
+ *
52
+ * @param {Database.Database} db - Active SQLite database handle.
53
+ * @param {string} suspendedForkId - Monotonic `${forkId}#${suspensionEpoch}` identifier.
54
+ * @param {'RESUMED' | 'ABORTED'} status - Target resolution status.
55
+ *
56
+ * @returns {void} Returns nothing once the epoch resolution is committed.
57
+ */
58
+ export declare function resolveSuspendedForkInSqlite(db: Database.Database, suspendedForkId: string, status: 'RESUMED' | 'ABORTED'): void;
59
+ //# sourceMappingURL=sqlite-ledger-plan-and-fork-ops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-plan-and-fork-ops.d.ts","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-plan-and-fork-ops.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAY3C;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,wFAAwF;IACxF,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,oEAAoE;IACpE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,qBAAqB,GAAG,IAAI,CAsB9F;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,MAAM,EAAE,mBAAmB,GAC1B,IAAI,CAWN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,wBAAwB,GAC9B,SAAS,mBAAmB,EAAE,CAchC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,SAAS,GAAG,SAAS,GAC5B,IAAI,CAwBN"}
@@ -0,0 +1,90 @@
1
+ import { matchesSuspendedForkFilter, parseSuspendedForkCoordinates, } from './sqlite-ledger-fork-operations.js';
2
+ import { upsertParentLaneItemInSqlite, upsertSpawnedLaneItemsInSqlite, } from './sqlite-ledger-plan-operations.js';
3
+ import { buildChainedLaneDependencies } from './validate-lane-dag.js';
4
+ /**
5
+ * Atomically chains spawned prerequisite items and validates DAG acyclicity and `maxPrerequisiteDepth`.
6
+ *
7
+ * Enforces linear prerequisite stacking ($T_{\text{prevTip}} \leftarrow T_1 \leftarrow \dots \leftarrow T_k \leftarrow T_{\text{parent}}$)
8
+ * and rejects cycles or depth violations before mutating `harness_lane_items` and `harness_runs`.
9
+ *
10
+ * @param {Database.Database} db - Active SQLite database handle.
11
+ * @param {MutateLanePlanRequest} req - Lane plan mutation request.
12
+ *
13
+ * @returns {void} Returns nothing once the DAG mutation is committed.
14
+ */
15
+ export function mutateLanePlanInSqlite(db, req) {
16
+ const existingRows = db
17
+ .prepare('SELECT item_key, depends_on_json, latest_spawned_tip_key FROM harness_lane_items WHERE lane_id = ?')
18
+ .all(req.laneId);
19
+ const { depsByItem, rollingTip, nextParentDeps } = buildChainedLaneDependencies(existingRows, req);
20
+ upsertSpawnedLaneItemsInSqlite(db, req, depsByItem);
21
+ upsertParentLaneItemInSqlite({
22
+ db,
23
+ req,
24
+ nextParentDeps,
25
+ rollingTip,
26
+ now: new Date().toISOString(),
27
+ });
28
+ }
29
+ /**
30
+ * Persists a `SuspendedForkRecord` in `harness_suspended_forks`.
31
+ *
32
+ * Stores the monotonic `${forkId}#${suspensionEpoch}` identifier and full continuation stack.
33
+ *
34
+ * @param {Database.Database} db - Active SQLite database handle.
35
+ * @param {SuspendedForkRecord} record - Suspended fork snapshot to persist.
36
+ *
37
+ * @returns {void} Returns nothing once the suspension record is saved.
38
+ */
39
+ export function recordForkSuspensionInSqlite(db, record) {
40
+ db.prepare('INSERT OR REPLACE INTO harness_suspended_forks (suspended_fork_id, fork_id, suspension_epoch, run_id, parent_step_exec_id, record_json, resolution_status) VALUES (?, ?, ?, ?, ?, ?, NULL)').run(record.suspendedForkId, record.forkId, record.suspensionEpoch, record.runId, record.parentStepExecId, JSON.stringify(record));
41
+ }
42
+ /**
43
+ * Queries unresolved (`resolution_status IS NULL`) suspended forks for `runId`.
44
+ *
45
+ * Supports optional filtering by `forkIds` (matching `forkId` or `suspendedForkId`) and `parentStepExecId`.
46
+ *
47
+ * @param {Database.Database} db - Active SQLite database handle.
48
+ * @param {string} runId - Enclosing flow run identifier.
49
+ * @param {GetSuspendedForksOptions} [opts] - Optional filter criteria.
50
+ *
51
+ * @returns {readonly SuspendedForkRecord[]} Matching unresolved suspended fork records.
52
+ */
53
+ export function getSuspendedForksFromSqlite(db, runId, opts) {
54
+ const rows = db
55
+ .prepare('SELECT * FROM harness_suspended_forks WHERE run_id = ? AND resolution_status IS NULL ORDER BY suspension_epoch ASC, suspended_fork_id ASC')
56
+ .all(runId);
57
+ const forkIdSet = opts?.forkIds !== undefined ? new Set(opts.forkIds) : undefined;
58
+ const records = [];
59
+ for (const row of rows) {
60
+ if (matchesSuspendedForkFilter(row, forkIdSet, opts?.parentStepExecId)) {
61
+ records.push(Object.freeze(JSON.parse(row.record_json)));
62
+ }
63
+ }
64
+ return Object.freeze(records);
65
+ }
66
+ /**
67
+ * Marks `suspendedForkId` and any earlier unresolved epochs `${forkId}#1 .. ${forkId}#${epoch}` as resolved.
68
+ *
69
+ * Guarantees recursive epoch resolution safety (`SPEC.md` §3.7.2) so prior epochs never remain open.
70
+ *
71
+ * @param {Database.Database} db - Active SQLite database handle.
72
+ * @param {string} suspendedForkId - Monotonic `${forkId}#${suspensionEpoch}` identifier.
73
+ * @param {'RESUMED' | 'ABORTED'} status - Target resolution status.
74
+ *
75
+ * @returns {void} Returns nothing once the epoch resolution is committed.
76
+ */
77
+ export function resolveSuspendedForkInSqlite(db, suspendedForkId, status) {
78
+ const target = db
79
+ .prepare('SELECT run_id, fork_id, suspension_epoch FROM harness_suspended_forks WHERE suspended_fork_id = ?')
80
+ .get(suspendedForkId);
81
+ if (target !== undefined) {
82
+ db.prepare('UPDATE harness_suspended_forks SET resolution_status = ? WHERE run_id = ? AND fork_id = ? AND suspension_epoch <= ? AND resolution_status IS NULL').run(status, target.run_id, target.fork_id, target.suspension_epoch);
83
+ return;
84
+ }
85
+ const parsed = parseSuspendedForkCoordinates(suspendedForkId);
86
+ if (parsed !== undefined) {
87
+ db.prepare('UPDATE harness_suspended_forks SET resolution_status = ? WHERE fork_id = ? AND suspension_epoch <= ? AND resolution_status IS NULL').run(status, parsed.forkId, parsed.epoch);
88
+ }
89
+ }
90
+ //# sourceMappingURL=sqlite-ledger-plan-and-fork-ops.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-plan-and-fork-ops.js","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-plan-and-fork-ops.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAYtE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CAAC,EAAqB,EAAE,GAA0B;IACtF,MAAM,YAAY,GAAG,EAAE;SACpB,OAAO,CACN,oGAAoG,CACrG;SACA,GAAG,CAAC,GAAG,CAAC,MAAM,CAIf,CAAC;IACH,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,4BAA4B,CAC7E,YAAY,EACZ,GAAG,CACJ,CAAC;IACF,8BAA8B,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;IACpD,4BAA4B,CAAC;QAC3B,EAAE;QACF,GAAG;QACH,cAAc;QACd,UAAU;QACV,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAC9B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,4BAA4B,CAC1C,EAAqB,EACrB,MAA2B;IAE3B,EAAE,CAAC,OAAO,CACR,4LAA4L,CAC7L,CAAC,GAAG,CACH,MAAM,CAAC,eAAe,EACtB,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,eAAe,EACtB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,gBAAgB,EACvB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CACvB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,2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G,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { MutateLanePlanRequest } from '@paraharness/core';
2
+ import type Database from 'better-sqlite3';
3
+ /**
4
+ * Parameters for persisting a parent item's updated prerequisite chain and rolling spawned tip in SQLite.
5
+ */
6
+ export interface UpsertParentLaneItemSqliteParams {
7
+ /** Active SQLite database handle. */
8
+ readonly db: Database.Database;
9
+ /** Original lane plan mutation request. */
10
+ readonly req: MutateLanePlanRequest;
11
+ /** Updated prerequisite list for `req.parentItemKey`. */
12
+ readonly nextParentDeps: readonly string[];
13
+ /** Newly chained prerequisite tip item key, if any. */
14
+ readonly rollingTip: string | undefined;
15
+ /** ISO-8601 timestamp string for `updated_at`. */
16
+ readonly now: string;
17
+ }
18
+ /**
19
+ * Persists all newly spawned prerequisite items and their `'QUEUED'` run placeholders in SQLite.
20
+ *
21
+ * Updates `depends_on_json` on both `harness_lane_items` and `harness_runs` for each spawned item.
22
+ *
23
+ * @param {Database.Database} db - Active SQLite database handle.
24
+ * @param {MutateLanePlanRequest} req - Lane plan mutation request.
25
+ * @param {ReadonlyMap<string, readonly string[]>} depsByItem - Validated dependency adjacency map.
26
+ *
27
+ * @returns {void} Returns nothing once all spawned items are persisted.
28
+ */
29
+ export declare function upsertSpawnedLaneItemsInSqlite(db: Database.Database, req: MutateLanePlanRequest, depsByItem: ReadonlyMap<string, readonly string[]>): void;
30
+ /**
31
+ * Persists the parent work item's updated `depends_on_json` and `latest_spawned_tip_key` in SQLite.
32
+ *
33
+ * Synchronizes both `harness_lane_items` and `harness_runs` for `params.req.parentRunId`.
34
+ *
35
+ * @param {UpsertParentLaneItemSqliteParams} params - Parent lane item update parameters.
36
+ *
37
+ * @returns {void} Returns nothing once the parent item and run dependencies are updated.
38
+ */
39
+ export declare function upsertParentLaneItemInSqlite(params: UpsertParentLaneItemSqliteParams): void;
40
+ //# sourceMappingURL=sqlite-ledger-plan-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-plan-operations.d.ts","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-plan-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C,qCAAqC;IACrC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC;IAC/B,2CAA2C;IAC3C,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAC;IACpC,yDAAyD;IACzD,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,uDAAuD;IACvD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,kDAAkD;IAClD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAC5C,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,GAAG,EAAE,qBAAqB,EAC1B,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,GACjD,IAAI,CA4BN;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,gCAAgC,GAAG,IAAI,CAgB3F"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Persists all newly spawned prerequisite items and their `'QUEUED'` run placeholders in SQLite.
3
+ *
4
+ * Updates `depends_on_json` on both `harness_lane_items` and `harness_runs` for each spawned item.
5
+ *
6
+ * @param {Database.Database} db - Active SQLite database handle.
7
+ * @param {MutateLanePlanRequest} req - Lane plan mutation request.
8
+ * @param {ReadonlyMap<string, readonly string[]>} depsByItem - Validated dependency adjacency map.
9
+ *
10
+ * @returns {void} Returns nothing once all spawned items are persisted.
11
+ */
12
+ export function upsertSpawnedLaneItemsInSqlite(db, req, depsByItem) {
13
+ const now = new Date().toISOString();
14
+ for (const spawnedTask of req.spawnedItems ?? []) {
15
+ const taskDepsJson = JSON.stringify(depsByItem.get(spawnedTask.itemKey) ?? []);
16
+ db.prepare('INSERT OR REPLACE INTO harness_lane_items (lane_id, item_key, input_json, depends_on_json, priority, latest_spawned_tip_key) VALUES (?, ?, ?, ?, ?, NULL)').run(req.laneId, spawnedTask.itemKey, spawnedTask.inputJson, taskDepsJson, spawnedTask.priority);
17
+ db.prepare("INSERT OR IGNORE INTO harness_runs (run_id, lane_id, item_key, status, current_step_id, input_json, depends_on_json, priority, updated_at) VALUES (?, ?, ?, 'QUEUED', NULL, ?, ?, ?, ?)").run(spawnedTask.itemKey, req.laneId, spawnedTask.itemKey, spawnedTask.inputJson, taskDepsJson, spawnedTask.priority, now);
18
+ db.prepare('UPDATE harness_runs SET depends_on_json = ?, updated_at = ? WHERE lane_id = ? AND item_key = ?').run(taskDepsJson, now, req.laneId, spawnedTask.itemKey);
19
+ }
20
+ }
21
+ /**
22
+ * Persists the parent work item's updated `depends_on_json` and `latest_spawned_tip_key` in SQLite.
23
+ *
24
+ * Synchronizes both `harness_lane_items` and `harness_runs` for `params.req.parentRunId`.
25
+ *
26
+ * @param {UpsertParentLaneItemSqliteParams} params - Parent lane item update parameters.
27
+ *
28
+ * @returns {void} Returns nothing once the parent item and run dependencies are updated.
29
+ */
30
+ export function upsertParentLaneItemInSqlite(params) {
31
+ const parentDepsJson = JSON.stringify(params.nextParentDeps);
32
+ params.db
33
+ .prepare("INSERT OR REPLACE INTO harness_lane_items (lane_id, item_key, input_json, depends_on_json, priority, latest_spawned_tip_key) VALUES (?, ?, COALESCE((SELECT input_json FROM harness_runs WHERE run_id = ?), '{}'), ?, 'normal', ?)")
34
+ .run(params.req.laneId, params.req.parentItemKey, params.req.parentRunId, parentDepsJson, params.rollingTip ?? null);
35
+ params.db
36
+ .prepare('UPDATE harness_runs SET depends_on_json = ?, updated_at = ? WHERE run_id = ?')
37
+ .run(parentDepsJson, params.now, params.req.parentRunId);
38
+ }
39
+ //# sourceMappingURL=sqlite-ledger-plan-operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-plan-operations.js","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-plan-operations.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,8BAA8B,CAC5C,EAAqB,EACrB,GAA0B,EAC1B,UAAkD;IAElD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACrC,KAAK,MAAM,WAAW,IAAI,GAAG,CAAC,YAAY,IAAI,EAAE,EAAE,CAAC;QACjD,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/E,EAAE,CAAC,OAAO,CACR,2JAA2J,CAC5J,CAAC,GAAG,CACH,GAAG,CAAC,MAAM,EACV,WAAW,CAAC,OAAO,EACnB,WAAW,CAAC,SAAS,EACrB,YAAY,EACZ,WAAW,CAAC,QAAQ,CACrB,CAAC;QACF,EAAE,CAAC,OAAO,CACR,yLAAyL,CAC1L,CAAC,GAAG,CACH,WAAW,CAAC,OAAO,EACnB,GAAG,CAAC,MAAM,EACV,WAAW,CAAC,OAAO,EACnB,WAAW,CAAC,SAAS,EACrB,YAAY,EACZ,WAAW,CAAC,QAAQ,EACpB,GAAG,CACJ,CAAC;QACF,EAAE,CAAC,OAAO,CACR,gGAAgG,CACjG,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,4BAA4B,CAAC,MAAwC;IACnF,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAC7D,MAAM,CAAC,EAAE;SACN,OAAO,CACN,oOAAoO,CACrO;SACA,GAAG,CACF,MAAM,CAAC,GAAG,CAAC,MAAM,EACjB,MAAM,CAAC,GAAG,CAAC,aAAa,EACxB,MAAM,CAAC,GAAG,CAAC,WAAW,EACtB,cAAc,EACd,MAAM,CAAC,UAAU,IAAI,IAAI,CAC1B,CAAC;IACJ,MAAM,CAAC,EAAE;SACN,OAAO,CAAC,8EAA8E,CAAC;SACvF,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { CreateOrResumeRunInput, CreateOrResumeRunResult } from '@paraharness/core';
2
+ import type Database from 'better-sqlite3';
3
+ import type { SqliteRunRow } from './sqlite-run-row.js';
4
+ /**
5
+ * Loads completed step outputs (`stepId -> outputJson`) for `runId` from `harness_step_executions`.
6
+ *
7
+ * Queries completed step executions in ascending `seq_id` order so the latest completed execution
8
+ * of each `stepId` populates the returned map without dynamic `Object.entries` allocations.
9
+ *
10
+ * @param {Database.Database} db - Active SQLite database handle.
11
+ * @param {string} runId - Enclosing flow run identifier.
12
+ *
13
+ * @returns {Map<string, string>} Map of completed `stepId` to serialized `outputJson`.
14
+ */
15
+ export declare function loadCompletedStepOutputsFromSqlite(db: Database.Database, runId: string): Map<string, string>;
16
+ /**
17
+ * Inserts a newly initialized flow run row (`status: 'RUNNING'`) and ensures its lane item exists.
18
+ *
19
+ * Replaces any stale `'QUEUED'` placeholder run for the same `(laneId, itemKey)` and pins
20
+ * `compiledPrefixesJson` at run creation time (`SPEC.md` §2.7).
21
+ *
22
+ * @param {Database.Database} db - Active SQLite database handle.
23
+ * @param {CreateOrResumeRunInput} run - Run initialization request payload.
24
+ * @param {string} now - ISO-8601 timestamp string for `updated_at`.
25
+ *
26
+ * @returns {CreateOrResumeRunResult} Newly initialized run state with empty completed step outputs.
27
+ */
28
+ export declare function insertInitialSqliteRun(db: Database.Database, run: CreateOrResumeRunInput, now: string): CreateOrResumeRunResult;
29
+ /**
30
+ * Resumes an existing flow run row in `harness_runs`, preserving its pinned `compiled_prefixes_json`.
31
+ *
32
+ * Updates `cost_usd` and `approved_max_cost_usd` if provided and loads completed step outputs.
33
+ *
34
+ * @param {Database.Database} db - Active SQLite database handle.
35
+ * @param {SqliteRunRow} existing - Existing persisted run row.
36
+ * @param {CreateOrResumeRunInput} run - Resume request payload.
37
+ *
38
+ * @returns {CreateOrResumeRunResult} Resumed run state and completed step outputs.
39
+ */
40
+ export declare function resumeExistingSqliteRun(db: Database.Database, existing: SqliteRunRow, run: CreateOrResumeRunInput): CreateOrResumeRunResult;
41
+ //# sourceMappingURL=sqlite-ledger-run-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-run-operations.d.ts","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-run-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;;;;;GAUG;AACH,wBAAgB,kCAAkC,CAChD,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,KAAK,EAAE,MAAM,GACZ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,GAAG,EAAE,sBAAsB,EAC3B,GAAG,EAAE,MAAM,GACV,uBAAuB,CAwCzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,QAAQ,EAAE,YAAY,EACtB,GAAG,EAAE,sBAAsB,GAC1B,uBAAuB,CAqBzB"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Loads completed step outputs (`stepId -> outputJson`) for `runId` from `harness_step_executions`.
3
+ *
4
+ * Queries completed step executions in ascending `seq_id` order so the latest completed execution
5
+ * of each `stepId` populates the returned map without dynamic `Object.entries` allocations.
6
+ *
7
+ * @param {Database.Database} db - Active SQLite database handle.
8
+ * @param {string} runId - Enclosing flow run identifier.
9
+ *
10
+ * @returns {Map<string, string>} Map of completed `stepId` to serialized `outputJson`.
11
+ */
12
+ export function loadCompletedStepOutputsFromSqlite(db, runId) {
13
+ const rows = db
14
+ .prepare("SELECT step_id, output_json FROM harness_step_executions WHERE run_id = ? AND status = 'COMPLETED' ORDER BY seq_id ASC")
15
+ .all(runId);
16
+ const completedOutputs = new Map();
17
+ for (const row of rows) {
18
+ if (row.output_json !== null) {
19
+ completedOutputs.set(row.step_id, row.output_json);
20
+ }
21
+ }
22
+ return completedOutputs;
23
+ }
24
+ /**
25
+ * Inserts a newly initialized flow run row (`status: 'RUNNING'`) and ensures its lane item exists.
26
+ *
27
+ * Replaces any stale `'QUEUED'` placeholder run for the same `(laneId, itemKey)` and pins
28
+ * `compiledPrefixesJson` at run creation time (`SPEC.md` §2.7).
29
+ *
30
+ * @param {Database.Database} db - Active SQLite database handle.
31
+ * @param {CreateOrResumeRunInput} run - Run initialization request payload.
32
+ * @param {string} now - ISO-8601 timestamp string for `updated_at`.
33
+ *
34
+ * @returns {CreateOrResumeRunResult} Newly initialized run state with empty completed step outputs.
35
+ */
36
+ export function insertInitialSqliteRun(db, run, now) {
37
+ const laneItem = db
38
+ .prepare('SELECT depends_on_json FROM harness_lane_items WHERE lane_id = ? AND item_key = ?')
39
+ .get(run.laneId, run.itemKey);
40
+ const depsJson = laneItem?.depends_on_json ?? '[]';
41
+ const prefixesJson = run.compiledPrefixesJson !== undefined ? JSON.stringify(run.compiledPrefixesJson) : null;
42
+ db.prepare("DELETE FROM harness_runs WHERE lane_id = ? AND item_key = ? AND status = 'QUEUED' AND run_id != ?").run(run.laneId, run.itemKey, run.runId);
43
+ db.prepare("INSERT INTO harness_runs (run_id, lane_id, item_key, status, current_step_id, input_json, rewind_pending_to_step_id, compiled_prefixes_json, cost_usd, approved_max_cost_usd, completed_step_outputs_json, depends_on_json, updated_at) VALUES (?, ?, ?, 'RUNNING', NULL, ?, NULL, ?, ?, ?, '{}', ?, ?)").run(run.runId, run.laneId, run.itemKey, run.inputJson, prefixesJson, run.costUsd ?? 0, run.approvedMaxCostUsd ?? null, depsJson, now);
44
+ db.prepare("INSERT OR IGNORE INTO harness_lane_items (lane_id, item_key, input_json, depends_on_json, priority) VALUES (?, ?, ?, ?, 'normal')").run(run.laneId, run.itemKey, run.inputJson, depsJson);
45
+ const pinned = prefixesJson !== null
46
+ ? Object.freeze(JSON.parse(prefixesJson))
47
+ : undefined;
48
+ return Object.freeze({
49
+ status: 'RUNNING',
50
+ currentStepId: null,
51
+ inputJson: run.inputJson,
52
+ rewindPendingToStepId: undefined,
53
+ compiledPrefixesJson: pinned,
54
+ costUsd: run.costUsd ?? 0,
55
+ approvedMaxCostUsd: run.approvedMaxCostUsd,
56
+ completedStepOutputsJson: new Map(),
57
+ });
58
+ }
59
+ /**
60
+ * Resumes an existing flow run row in `harness_runs`, preserving its pinned `compiled_prefixes_json`.
61
+ *
62
+ * Updates `cost_usd` and `approved_max_cost_usd` if provided and loads completed step outputs.
63
+ *
64
+ * @param {Database.Database} db - Active SQLite database handle.
65
+ * @param {SqliteRunRow} existing - Existing persisted run row.
66
+ * @param {CreateOrResumeRunInput} run - Resume request payload.
67
+ *
68
+ * @returns {CreateOrResumeRunResult} Resumed run state and completed step outputs.
69
+ */
70
+ export function resumeExistingSqliteRun(db, existing, run) {
71
+ const nextCostUsd = run.costUsd ?? existing.cost_usd;
72
+ const nextApprovedMax = run.approvedMaxCostUsd ?? existing.approved_max_cost_usd ?? undefined;
73
+ const now = new Date().toISOString();
74
+ db.prepare('UPDATE harness_runs SET cost_usd = ?, approved_max_cost_usd = ?, updated_at = ? WHERE run_id = ?').run(nextCostUsd, nextApprovedMax ?? null, now, run.runId);
75
+ const pinned = existing.compiled_prefixes_json !== null
76
+ ? Object.freeze(JSON.parse(existing.compiled_prefixes_json))
77
+ : undefined;
78
+ return Object.freeze({
79
+ status: existing.status,
80
+ currentStepId: existing.current_step_id,
81
+ inputJson: existing.input_json,
82
+ rewindPendingToStepId: existing.rewind_pending_to_step_id ?? undefined,
83
+ compiledPrefixesJson: pinned,
84
+ costUsd: nextCostUsd,
85
+ approvedMaxCostUsd: nextApprovedMax,
86
+ completedStepOutputsJson: loadCompletedStepOutputsFromSqlite(db, run.runId),
87
+ });
88
+ }
89
+ //# sourceMappingURL=sqlite-ledger-run-operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-run-operations.js","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-run-operations.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kCAAkC,CAChD,EAAqB,EACrB,KAAa;IAEb,MAAM,IAAI,GAAG,EAAE;SACZ,OAAO,CACN,wHAAwH,CACzH;SACA,GAAG,CAAC,KAAK,CAGV,CAAC;IACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;YAC7B,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CACpC,EAAqB,EACrB,GAA2B,EAC3B,GAAW;IAEX,MAAM,QAAQ,GAAG,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put, CreateOrResumeRunResult, RunTerminalReceiptRecord } from '@paraharness/core';
2
+ import type Database from 'better-sqlite3';
3
+ import type { RecordTerminalReceiptParams } from './record-terminal-receipt-params.js';
4
+ /**
5
+ * Parameters for updating a run's serialized flow input payload and optional pending rewind target step ID.
6
+ */
7
+ export interface UpdateRunInputParams {
8
+ /** Serialized JSON flow input payload. */
9
+ readonly inputJson: string;
10
+ /** Optional target step ID when a rewind is pending, or `null` to clear. */
11
+ readonly rewindPendingToStepId?: string | null;
12
+ }
13
+ /**
14
+ * Inserts a new flow run row (`status: 'RUNNING'`) or returns the existing run's persisted state.
15
+ *
16
+ * Pins `compiledPrefixesJson` at initial run creation so subsequent resume calls never overwrite it.
17
+ *
18
+ * @param {Database.Database} db - Active SQLite database handle.
19
+ * @param {CreateOrResumeRunInput} run - Run initialization or resume request payload.
20
+ *
21
+ * @returns {CreateOrResumeRunResult} Persisted run status, pinned prefixes, and completed step outputs.
22
+ */
23
+ export declare function createOrResumeRunInSqlite(db: Database.Database, run: CreateOrResumeRunInput): CreateOrResumeRunResult;
24
+ /**
25
+ * Updates `input_json` and optional `rewind_pending_to_step_id` for `runId` in `harness_runs`.
26
+ *
27
+ * Used during `.replaceWith()` step promotion and `.onSignal().rewindTo()` transitions.
28
+ *
29
+ * @param {Database.Database} db - Active SQLite database handle.
30
+ * @param {string} runId - Target flow run identifier.
31
+ * @param {UpdateRunInputParams} update - Updated input JSON and rewind target.
32
+ *
33
+ * @returns {void} Returns nothing once the update is committed.
34
+ */
35
+ export declare function updateRunInputInSqlite(db: Database.Database, runId: string, update: UpdateRunInputParams): void;
36
+ /**
37
+ * Persists a terminal run receipt in `harness_terminal_receipts` and marks the run terminal in `harness_runs`.
38
+ *
39
+ * Enables dependent runs to inspect prerequisite terminal receipts during `syncRoot` wakeup.
40
+ *
41
+ * @param {Database.Database} db - Active SQLite database handle.
42
+ * @param {RecordTerminalReceiptParams} params - Terminal receipt parameters.
43
+ *
44
+ * @returns {void} Returns nothing once the receipt is persisted.
45
+ */
46
+ export declare function recordRunTerminalReceiptInSqlite(db: Database.Database, params: RecordTerminalReceiptParams): void;
47
+ /**
48
+ * Queries terminal run receipts keyed by `itemKey` from `harness_terminal_receipts`.
49
+ *
50
+ * Returns a map of `itemKey -> RunTerminalReceiptRecord` for all matching items.
51
+ *
52
+ * @param {Database.Database} db - Active SQLite database handle.
53
+ * @param {readonly string[]} itemKeys - Work item keys to look up.
54
+ *
55
+ * @returns {ReadonlyMap<string, RunTerminalReceiptRecord>} Map of `itemKey` to terminal receipt record.
56
+ */
57
+ export declare function getRunTerminalReceiptsFromSqlite(db: Database.Database, itemKeys: readonly string[]): ReadonlyMap<string, RunTerminalReceiptRecord>;
58
+ //# sourceMappingURL=sqlite-ledger-run-ops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-run-ops.d.ts","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-run-ops.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAOvF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChD;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,GAAG,EAAE,sBAAsB,GAC1B,uBAAuB,CAQzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,oBAAoB,GAC3B,IAAI,CAaN;AAED;;;;;;;;;GASG;AACH,wBAAgB,gCAAgC,CAC9C,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,MAAM,EAAE,2BAA2B,GAClC,IAAI,CAoBN;AAED;;;;;;;;;GASG;AACH,wBAAgB,gCAAgC,CAC9C,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,QAAQ,EAAE,SAAS,MAAM,EAAE,GAC1B,WAAW,CAAC,MAAM,EAAE,wBAAwB,CAAC,CA0B/C"}
@@ -0,0 +1,80 @@
1
+ import { insertInitialSqliteRun, resumeExistingSqliteRun, } from './sqlite-ledger-run-operations.js';
2
+ /**
3
+ * Inserts a new flow run row (`status: 'RUNNING'`) or returns the existing run's persisted state.
4
+ *
5
+ * Pins `compiledPrefixesJson` at initial run creation so subsequent resume calls never overwrite it.
6
+ *
7
+ * @param {Database.Database} db - Active SQLite database handle.
8
+ * @param {CreateOrResumeRunInput} run - Run initialization or resume request payload.
9
+ *
10
+ * @returns {CreateOrResumeRunResult} Persisted run status, pinned prefixes, and completed step outputs.
11
+ */
12
+ export function createOrResumeRunInSqlite(db, run) {
13
+ const existing = db
14
+ .prepare('SELECT * FROM harness_runs WHERE run_id = ?')
15
+ .get(run.runId);
16
+ if (existing === undefined) {
17
+ return insertInitialSqliteRun(db, run, new Date().toISOString());
18
+ }
19
+ return resumeExistingSqliteRun(db, existing, run);
20
+ }
21
+ /**
22
+ * Updates `input_json` and optional `rewind_pending_to_step_id` for `runId` in `harness_runs`.
23
+ *
24
+ * Used during `.replaceWith()` step promotion and `.onSignal().rewindTo()` transitions.
25
+ *
26
+ * @param {Database.Database} db - Active SQLite database handle.
27
+ * @param {string} runId - Target flow run identifier.
28
+ * @param {UpdateRunInputParams} update - Updated input JSON and rewind target.
29
+ *
30
+ * @returns {void} Returns nothing once the update is committed.
31
+ */
32
+ export function updateRunInputInSqlite(db, runId, update) {
33
+ const now = new Date().toISOString();
34
+ if (update.rewindPendingToStepId !== undefined) {
35
+ db.prepare('UPDATE harness_runs SET input_json = ?, rewind_pending_to_step_id = ?, updated_at = ? WHERE run_id = ?').run(update.inputJson, update.rewindPendingToStepId, now, runId);
36
+ return;
37
+ }
38
+ db.prepare('UPDATE harness_runs SET input_json = ?, updated_at = ? WHERE run_id = ?').run(update.inputJson, now, runId);
39
+ }
40
+ /**
41
+ * Persists a terminal run receipt in `harness_terminal_receipts` and marks the run terminal in `harness_runs`.
42
+ *
43
+ * Enables dependent runs to inspect prerequisite terminal receipts during `syncRoot` wakeup.
44
+ *
45
+ * @param {Database.Database} db - Active SQLite database handle.
46
+ * @param {RecordTerminalReceiptParams} params - Terminal receipt parameters.
47
+ *
48
+ * @returns {void} Returns nothing once the receipt is persisted.
49
+ */
50
+ export function recordRunTerminalReceiptInSqlite(db, params) {
51
+ const now = new Date().toISOString();
52
+ db.prepare('INSERT OR REPLACE INTO harness_terminal_receipts (item_key, run_id, terminal_state, scope_receipt_json, recorded_at) VALUES (?, ?, ?, ?, ?)').run(params.itemKey, params.runId, params.terminalState, params.scopeReceiptJson ?? null, now);
53
+ db.prepare('UPDATE harness_runs SET status = ?, terminal_state = ?, scope_receipt_json = ?, updated_at = ? WHERE run_id = ?').run(params.terminalState, params.terminalState, params.scopeReceiptJson ?? null, now, params.runId);
54
+ }
55
+ /**
56
+ * Queries terminal run receipts keyed by `itemKey` from `harness_terminal_receipts`.
57
+ *
58
+ * Returns a map of `itemKey -> RunTerminalReceiptRecord` for all matching items.
59
+ *
60
+ * @param {Database.Database} db - Active SQLite database handle.
61
+ * @param {readonly string[]} itemKeys - Work item keys to look up.
62
+ *
63
+ * @returns {ReadonlyMap<string, RunTerminalReceiptRecord>} Map of `itemKey` to terminal receipt record.
64
+ */
65
+ export function getRunTerminalReceiptsFromSqlite(db, itemKeys) {
66
+ const receipts = new Map();
67
+ const stmt = db.prepare('SELECT item_key, run_id, terminal_state, scope_receipt_json FROM harness_terminal_receipts WHERE item_key = ?');
68
+ for (const itemKey of itemKeys) {
69
+ const row = stmt.get(itemKey);
70
+ if (row !== undefined) {
71
+ receipts.set(row.item_key, Object.freeze({
72
+ runId: row.run_id,
73
+ terminalState: row.terminal_state,
74
+ scopeReceiptJson: row.scope_receipt_json ?? undefined,
75
+ }));
76
+ }
77
+ }
78
+ return receipts;
79
+ }
80
+ //# sourceMappingURL=sqlite-ledger-run-ops.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-run-ops.js","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-run-ops.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,mCAAmC,CAAC;AAa3C;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CACvC,EAAqB,EACrB,GAA2B;IAE3B,MAAM,QAAQ,GAAG,EAAE;SAChB,OAAO,CAAC,6CAA6C,CAAC;SACtD,GAAG,CAAC,GAAG,CAAC,KAAK,CAA6B,CAAC;IAC9C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,sBAAsB,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,uBAAuB,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CACpC,EAAqB,EACrB,KAAa,EACb,MAA4B;IAE5B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACrC,IAAI,MAAM,CAAC,qBAAqB,KAAK,SAAS,EAAE,CAAC;QAC/C,EAAE,CAAC,OAAO,CACR,wGAAwG,CACzG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,qBAAqB,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAClE,OAAO;IACT,CAAC;IACD,EAAE,CAAC,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ACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { InterruptedStepBootRecord } from '@paraharness/core';
2
+ import type { SqliteRunRow } from './sqlite-run-row.js';
3
+ import type { SqliteStepRow } from './sqlite-step-row.js';
4
+ /**
5
+ * Computes the next parent run status following a step lifecycle status transition.
6
+ *
7
+ * Transitions the parent run to `'SUSPENDED'` or `'RUNNING'` when the step enters those states,
8
+ * preserving `currentRunStatus` otherwise.
9
+ *
10
+ * @param {string} stepTransitionStatus - Newly recorded step status.
11
+ * @param {string} currentRunStatus - Current status of the enclosing flow run.
12
+ *
13
+ * @returns {string} Updated flow run status string.
14
+ */
15
+ export declare function resolveRunStatusAfterStepTransition(stepTransitionStatus: string, currentRunStatus: string): string;
16
+ /**
17
+ * Maps a non-terminal `SqliteRunRow` and its latest `SqliteStepRow` into an `InterruptedStepBootRecord`.
18
+ *
19
+ * Populates active step checkpoints and parsed `ContinuationFrame[]` only when the latest step
20
+ * is in `'RUNNING'` or `'SUSPENDED'` state.
21
+ *
22
+ * @param {SqliteRunRow} runRow - Non-terminal flow run row.
23
+ * @param {SqliteStepRow | undefined} stepRow - Latest step execution row for `runRow.run_id`, if any.
24
+ *
25
+ * @returns {InterruptedStepBootRecord} Frozen boot recovery record.
26
+ */
27
+ export declare function mapInterruptedBootRecordFromSqlite(runRow: SqliteRunRow, stepRow: SqliteStepRow | undefined): InterruptedStepBootRecord;
28
+ //# sourceMappingURL=sqlite-ledger-step-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-ledger-step-operations.d.ts","sourceRoot":"","sources":["../../../src/stores/internal/sqlite-ledger-step-operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,mCAAmC,CACjD,oBAAoB,EAAE,MAAM,EAC5B,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAQR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,aAAa,GAAG,SAAS,GACjC,yBAAyB,CAqB3B"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Computes the next parent run status following a step lifecycle status transition.
3
+ *
4
+ * Transitions the parent run to `'SUSPENDED'` or `'RUNNING'` when the step enters those states,
5
+ * preserving `currentRunStatus` otherwise.
6
+ *
7
+ * @param {string} stepTransitionStatus - Newly recorded step status.
8
+ * @param {string} currentRunStatus - Current status of the enclosing flow run.
9
+ *
10
+ * @returns {string} Updated flow run status string.
11
+ */
12
+ export function resolveRunStatusAfterStepTransition(stepTransitionStatus, currentRunStatus) {
13
+ if (stepTransitionStatus === 'SUSPENDED') {
14
+ return 'SUSPENDED';
15
+ }
16
+ if (stepTransitionStatus === 'RUNNING') {
17
+ return 'RUNNING';
18
+ }
19
+ return currentRunStatus;
20
+ }
21
+ /**
22
+ * Maps a non-terminal `SqliteRunRow` and its latest `SqliteStepRow` into an `InterruptedStepBootRecord`.
23
+ *
24
+ * Populates active step checkpoints and parsed `ContinuationFrame[]` only when the latest step
25
+ * is in `'RUNNING'` or `'SUSPENDED'` state.
26
+ *
27
+ * @param {SqliteRunRow} runRow - Non-terminal flow run row.
28
+ * @param {SqliteStepRow | undefined} stepRow - Latest step execution row for `runRow.run_id`, if any.
29
+ *
30
+ * @returns {InterruptedStepBootRecord} Frozen boot recovery record.
31
+ */
32
+ export function mapInterruptedBootRecordFromSqlite(runRow, stepRow) {
33
+ const isActiveStep = stepRow !== undefined && (stepRow.status === 'RUNNING' || stepRow.status === 'SUSPENDED');
34
+ const stack = isActiveStep
35
+ ? JSON.parse(stepRow.continuation_stack_json)
36
+ : [];
37
+ const dependsOn = JSON.parse(runRow.depends_on_json);
38
+ return Object.freeze({
39
+ runId: runRow.run_id,
40
+ laneId: runRow.lane_id,
41
+ itemKey: runRow.item_key,
42
+ inputJson: runRow.input_json,
43
+ status: runRow.status,
44
+ dependsOn: Object.freeze(dependsOn),
45
+ stepExecId: isActiveStep ? stepRow.step_exec_id : null,
46
+ stepId: isActiveStep ? stepRow.step_id : null,
47
+ executableId: isActiveStep ? (stepRow.executable_id ?? undefined) : undefined,
48
+ baseScopeCheckpoint: isActiveStep ? (stepRow.base_scope_checkpoint ?? undefined) : undefined,
49
+ headScopeCheckpoint: isActiveStep ? (stepRow.head_scope_checkpoint ?? undefined) : undefined,
50
+ continuationStack: Object.freeze(stack),
51
+ });
52
+ }
53
+ //# sourceMappingURL=sqlite-ledger-step-operations.js.map