@deksden-com/dd-flow-cli 0.9.0-beta.14 → 0.9.0-beta.141

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 (493) hide show
  1. package/CHANGELOG.md +740 -0
  2. package/README.md +143 -1
  3. package/dist/build-info.json +8 -8
  4. package/dist/cli/argument-values.js +38 -0
  5. package/dist/cli/command-inputs.js +376 -0
  6. package/dist/cli/command-metadata.js +197 -0
  7. package/dist/cli/command-option-descriptions.js +191 -0
  8. package/dist/cli/completion-cli.js +70 -0
  9. package/dist/cli/completion.js +57 -0
  10. package/dist/cli/error-output.js +52 -0
  11. package/dist/cli/executor-onboarding.js +76 -0
  12. package/dist/cli/flows.js +29 -0
  13. package/dist/cli/harnesses.js +84 -0
  14. package/dist/cli/help.js +328 -18
  15. package/dist/cli/hook-ingress.js +78 -0
  16. package/dist/cli/input-preparation.js +165 -0
  17. package/dist/cli/memory-flow-admission.js +44 -0
  18. package/dist/cli/memory-init-invocation.js +78 -0
  19. package/dist/cli/memory-init.js +240 -0
  20. package/dist/cli/memory-storage-admission.js +53 -0
  21. package/dist/cli/models.js +39 -0
  22. package/dist/cli/native-hook-ingress.js +80 -0
  23. package/dist/cli/operator-profiles.js +61 -0
  24. package/dist/cli/output-options.js +35 -0
  25. package/dist/cli/response-file.js +71 -0
  26. package/dist/cli/run-cli.js +1689 -545
  27. package/dist/cli/runtime-maintenance-diagnostics.js +46 -0
  28. package/dist/cli/runtime-maintenance-ingress.js +52 -0
  29. package/dist/cli/runtime-process.js +153 -0
  30. package/dist/cli/setup.js +149 -0
  31. package/dist/cli.js +71 -2
  32. package/dist/domain/stage-catalog.js +1 -1
  33. package/dist/domain/stage-handler-identities.js +20 -0
  34. package/dist/harness-runtime/DD-ZCODE.md +112 -0
  35. package/dist/harness-runtime/OPENCODE-LICENSE.txt +24 -0
  36. package/dist/harness-runtime/bin/dd-agy.mjs +56 -0
  37. package/dist/harness-runtime/bin/dd-codex.mjs +27 -0
  38. package/dist/harness-runtime/bin/dd-droid.mjs +34 -0
  39. package/dist/harness-runtime/bin/dd-grok.mjs +40 -0
  40. package/dist/harness-runtime/bin/dd-opencode.mjs +22 -0
  41. package/dist/harness-runtime/bin/dd-zcode.mjs +87 -0
  42. package/dist/harness-runtime/lib/adapter-timeouts.d.mts +5 -0
  43. package/dist/harness-runtime/lib/adapter-timeouts.mjs +34 -0
  44. package/dist/harness-runtime/lib/agy-hooks.d.mts +1 -0
  45. package/dist/harness-runtime/lib/agy-hooks.mjs +9 -0
  46. package/dist/harness-runtime/lib/daemon-observation.d.mts +2 -0
  47. package/dist/harness-runtime/lib/daemon-observation.mjs +163 -0
  48. package/dist/harness-runtime/lib/daemon-operations.d.mts +1 -0
  49. package/dist/harness-runtime/lib/daemon-operations.mjs +371 -0
  50. package/dist/harness-runtime/lib/dd-agy-daemon.d.mts +6 -0
  51. package/dist/harness-runtime/lib/dd-agy-daemon.mjs +728 -0
  52. package/dist/harness-runtime/lib/dd-agy.mjs +70 -0
  53. package/dist/harness-runtime/lib/dd-codex-daemon.d.mts +1 -0
  54. package/dist/harness-runtime/lib/dd-codex-daemon.mjs +196 -0
  55. package/dist/harness-runtime/lib/dd-codex.d.mts +1 -0
  56. package/dist/harness-runtime/lib/dd-codex.mjs +817 -0
  57. package/dist/harness-runtime/lib/dd-droid-daemon.mjs +140 -0
  58. package/dist/harness-runtime/lib/dd-droid.mjs +584 -0
  59. package/dist/harness-runtime/lib/dd-grok-daemon.mjs +498 -0
  60. package/dist/harness-runtime/lib/dd-grok.mjs +177 -0
  61. package/dist/harness-runtime/lib/dd-opencode-daemon.mjs +557 -0
  62. package/dist/harness-runtime/lib/dd-opencode.mjs +363 -0
  63. package/dist/harness-runtime/lib/dd-zcode-daemon.mjs +751 -0
  64. package/dist/harness-runtime/lib/dd-zcode.mjs +1145 -0
  65. package/dist/harness-runtime/lib/delegation-instructions.d.mts +14 -0
  66. package/dist/harness-runtime/lib/delegation-instructions.mjs +157 -0
  67. package/dist/harness-runtime/lib/dispatch-fence.mjs +14 -0
  68. package/dist/harness-runtime/lib/driver-recovery.mjs +139 -0
  69. package/dist/harness-runtime/lib/droid-observation.mjs +66 -0
  70. package/dist/harness-runtime/lib/lease-renewal.d.mts +8 -0
  71. package/dist/harness-runtime/lib/lease-renewal.mjs +37 -0
  72. package/dist/harness-runtime/lib/lifecycle-command.d.mts +20 -0
  73. package/dist/harness-runtime/lib/lifecycle-command.mjs +273 -0
  74. package/dist/harness-runtime/lib/lifecycle-contract.d.mts +10 -0
  75. package/dist/harness-runtime/lib/lifecycle-contract.mjs +19 -0
  76. package/dist/harness-runtime/lib/managed-daemon.d.mts +16 -0
  77. package/dist/harness-runtime/lib/managed-daemon.mjs +683 -0
  78. package/dist/harness-runtime/lib/managed-flow-env.mjs +15 -0
  79. package/dist/harness-runtime/lib/model-observations.mjs +101 -0
  80. package/dist/harness-runtime/lib/native-children.d.mts +16 -0
  81. package/dist/harness-runtime/lib/native-children.mjs +113 -0
  82. package/dist/harness-runtime/lib/native-hook-command.d.mts +7 -0
  83. package/dist/harness-runtime/lib/native-hook-command.mjs +251 -0
  84. package/dist/harness-runtime/lib/native-request-proof.d.mts +2 -0
  85. package/dist/harness-runtime/lib/native-request-proof.mjs +65 -0
  86. package/dist/harness-runtime/lib/native-streams.mjs +45 -0
  87. package/dist/harness-runtime/lib/observation-clock.d.mts +18 -0
  88. package/dist/harness-runtime/lib/observation-clock.mjs +92 -0
  89. package/dist/harness-runtime/lib/opencode-plugin.mjs +85 -0
  90. package/dist/harness-runtime/lib/operation-context.mjs +5 -0
  91. package/dist/harness-runtime/lib/operation-errors.d.mts +16 -0
  92. package/dist/harness-runtime/lib/operation-errors.mjs +127 -0
  93. package/dist/harness-runtime/lib/operation-progress.d.mts +7 -0
  94. package/dist/harness-runtime/lib/operation-progress.mjs +114 -0
  95. package/dist/harness-runtime/lib/process-json.d.mts +5 -0
  96. package/dist/harness-runtime/lib/process-json.mjs +201 -0
  97. package/dist/harness-runtime/lib/process-snapshot.mjs +10 -0
  98. package/dist/harness-runtime/lib/provider-overload-policy.d.mts +13 -0
  99. package/dist/harness-runtime/lib/provider-overload-policy.mjs +138 -0
  100. package/dist/harness-runtime/lib/runner-events.mjs +200 -0
  101. package/dist/harness-runtime/lib/runner-lock.mjs +42 -0
  102. package/dist/harness-runtime/lib/session-settlement.mjs +30 -0
  103. package/dist/harness-runtime/lib/setup-progress.d.mts +9 -0
  104. package/dist/harness-runtime/lib/setup-progress.mjs +51 -0
  105. package/dist/harness-runtime/lib/tool-observations.d.mts +21 -0
  106. package/dist/harness-runtime/lib/tool-observations.mjs +228 -0
  107. package/dist/harness-runtime/lib/zcode-usage.mjs +55 -0
  108. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-1y4a697q.js +81 -0
  109. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-2ny4vxct.js +92 -0
  110. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-6mptkzbc.js +0 -0
  111. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-7x67cf1q.js +52 -0
  112. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-9rqn6x4v.js +16 -0
  113. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-9vdz0zwn.js +1661 -0
  114. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ecs5ftka.js +1466 -0
  115. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-frbwqjmf.js +145 -0
  116. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-gne7h7mq.js +50 -0
  117. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-gx9wnkzr.js +105 -0
  118. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-m2eywc8w.js +0 -0
  119. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-nwcpakzx.js +12 -0
  120. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-q4g3afnw.js +623 -0
  121. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-qav6mfdz.js +0 -0
  122. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-sxt88q69.js +12 -0
  123. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-t1xa31vm.js +39 -0
  124. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ve4aws36.js +103 -0
  125. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vmytr4q8.js +4 -0
  126. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vt9jbch8.js +36 -0
  127. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-vyas3vgt.js +0 -0
  128. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-wjyeq25y.js +30 -0
  129. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-xgnj2w4v.js +20 -0
  130. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-y2etg5bs.js +9 -0
  131. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-ydhz1zrh.js +238 -0
  132. package/dist/harness-runtime/vendor/opencode-client/chunks/service-probe-z6qdwcsf.js +62 -0
  133. package/dist/harness-runtime/vendor/opencode-client/contract.d.ts +1 -0
  134. package/dist/harness-runtime/vendor/opencode-client/contract.js +12 -0
  135. package/dist/harness-runtime/vendor/opencode-client/effect/api/api.d.ts +2806 -0
  136. package/dist/harness-runtime/vendor/opencode-client/effect/api/api.js +0 -0
  137. package/dist/harness-runtime/vendor/opencode-client/effect/api.d.ts +4 -0
  138. package/dist/harness-runtime/vendor/opencode-client/effect/api.js +0 -0
  139. package/dist/harness-runtime/vendor/opencode-client/effect/client.d.ts +2530 -0
  140. package/dist/harness-runtime/vendor/opencode-client/effect/client.js +15 -0
  141. package/dist/harness-runtime/vendor/opencode-client/effect/generated/client-error.d.ts +7 -0
  142. package/dist/harness-runtime/vendor/opencode-client/effect/generated/client-error.js +6 -0
  143. package/dist/harness-runtime/vendor/opencode-client/effect/generated/client.d.ts +2529 -0
  144. package/dist/harness-runtime/vendor/opencode-client/effect/generated/client.js +8 -0
  145. package/dist/harness-runtime/vendor/opencode-client/effect/generated/index.d.ts +2 -0
  146. package/dist/harness-runtime/vendor/opencode-client/effect/generated/index.js +12 -0
  147. package/dist/harness-runtime/vendor/opencode-client/effect/index.d.ts +35 -0
  148. package/dist/harness-runtime/vendor/opencode-client/effect/index.js +75 -0
  149. package/dist/harness-runtime/vendor/opencode-client/effect/rpc.d.ts +20 -0
  150. package/dist/harness-runtime/vendor/opencode-client/effect/rpc.js +11 -0
  151. package/dist/harness-runtime/vendor/opencode-client/effect/service.d.ts +90 -0
  152. package/dist/harness-runtime/vendor/opencode-client/effect/service.js +187 -0
  153. package/dist/harness-runtime/vendor/opencode-client/package.json +84 -0
  154. package/dist/harness-runtime/vendor/opencode-client/promise/api.d.ts +21 -0
  155. package/dist/harness-runtime/vendor/opencode-client/promise/api.js +0 -0
  156. package/dist/harness-runtime/vendor/opencode-client/promise/client.d.ts +252 -0
  157. package/dist/harness-runtime/vendor/opencode-client/promise/client.js +14 -0
  158. package/dist/harness-runtime/vendor/opencode-client/promise/generated/client-error.d.ts +8 -0
  159. package/dist/harness-runtime/vendor/opencode-client/promise/generated/client-error.js +6 -0
  160. package/dist/harness-runtime/vendor/opencode-client/promise/generated/client.d.ts +259 -0
  161. package/dist/harness-runtime/vendor/opencode-client/promise/generated/client.js +7 -0
  162. package/dist/harness-runtime/vendor/opencode-client/promise/generated/index.d.ts +3 -0
  163. package/dist/harness-runtime/vendor/opencode-client/promise/generated/index.js +79 -0
  164. package/dist/harness-runtime/vendor/opencode-client/promise/generated/types.d.ts +8932 -0
  165. package/dist/harness-runtime/vendor/opencode-client/promise/generated/types.js +70 -0
  166. package/dist/harness-runtime/vendor/opencode-client/promise/index.d.ts +6 -0
  167. package/dist/harness-runtime/vendor/opencode-client/promise/index.js +83 -0
  168. package/dist/harness-runtime/vendor/opencode-client/promise/rpc.d.ts +32 -0
  169. package/dist/harness-runtime/vendor/opencode-client/promise/rpc.js +7 -0
  170. package/dist/harness-runtime/vendor/opencode-client/promise/service.d.ts +24 -0
  171. package/dist/harness-runtime/vendor/opencode-client/promise/service.js +187 -0
  172. package/dist/harness-runtime/vendor/opencode-client/pty-handoff.d.ts +12 -0
  173. package/dist/harness-runtime/vendor/opencode-client/pty-handoff.js +14 -0
  174. package/dist/harness-runtime/vendor/opencode-client/rpc-runtime.d.ts +20 -0
  175. package/dist/harness-runtime/vendor/opencode-client/rpc-runtime.js +14 -0
  176. package/dist/harness-runtime/vendor/opencode-client/service-contender.d.ts +37 -0
  177. package/dist/harness-runtime/vendor/opencode-client/service-contender.js +10 -0
  178. package/dist/harness-runtime/vendor/opencode-client/service-probe.d.ts +70 -0
  179. package/dist/harness-runtime/vendor/opencode-client/service-probe.js +16 -0
  180. package/dist/harness-runtime/vendor/opencode-client/service-timing.d.ts +12 -0
  181. package/dist/harness-runtime/vendor/opencode-client/service-timing.js +10 -0
  182. package/dist/harness-runtime/vendor/opencode-client/service-version.d.ts +2 -0
  183. package/dist/harness-runtime/vendor/opencode-client/service-version.js +6 -0
  184. package/dist/harness-runtime/vendor/opencode-client/service.d.ts +52 -0
  185. package/dist/harness-runtime/vendor/opencode-client/service.js +1 -0
  186. package/dist/harness-runtime/vendor/opencode-client/shared-events.d.ts +11 -0
  187. package/dist/harness-runtime/vendor/opencode-client/shared-events.js +8 -0
  188. package/dist/harness-runtime/vendor/opencode-client/solid/connection.d.ts +37 -0
  189. package/dist/harness-runtime/vendor/opencode-client/solid/connection.js +10 -0
  190. package/dist/harness-runtime/vendor/opencode-client/solid/data.d.ts +211 -0
  191. package/dist/harness-runtime/vendor/opencode-client/solid/data.js +18 -0
  192. package/dist/harness-runtime/vendor/opencode-client/solid/index.d.ts +3 -0
  193. package/dist/harness-runtime/vendor/opencode-client/solid/index.js +32 -0
  194. package/dist/harness-runtime/vendor/opencode-client/solid/pty.d.ts +22 -0
  195. package/dist/harness-runtime/vendor/opencode-client/solid/pty.js +8 -0
  196. package/dist/harness-runtime/vendor/opencode-plugin.mjs +3 -0
  197. package/dist/protocol/local-files.js +18 -9
  198. package/dist/runtime/context.js +8 -4
  199. package/dist/schemas/agent-profile.schema.json +1 -1
  200. package/dist/schemas/code-review-result.schema.json +1 -1
  201. package/dist/schemas/code-verification.schema.json +7 -5
  202. package/dist/schemas/code-work-batch.schema.json +2 -2
  203. package/dist/schemas/discovery-result.schema.json +184 -0
  204. package/dist/schemas/execution-bundle.schema.json +205 -0
  205. package/dist/schemas/execution-settings.schema.json +162 -0
  206. package/dist/schemas/flow-descriptor.schema.json +54 -0
  207. package/dist/schemas/flow-run.schema.json +28 -0
  208. package/dist/schemas/harness-catalog.schema.json +80 -0
  209. package/dist/schemas/mb-init-compose-result.schema.json +457 -0
  210. package/dist/schemas/mb-init-discover-result.schema.json +500 -0
  211. package/dist/schemas/mb-init-finish-result.schema.json +422 -0
  212. package/dist/schemas/mb-init-preflight-result.schema.json +367 -0
  213. package/dist/schemas/mb-init-review-result.schema.json +396 -0
  214. package/dist/schemas/mb-init-verify-result.schema.json +391 -0
  215. package/dist/schemas/memory-bootstrap-receipt-v2.schema.json +67 -0
  216. package/dist/schemas/memory-bootstrap-receipt.schema.json +354 -0
  217. package/dist/schemas/memory-composition-work-result.schema.json +38 -0
  218. package/dist/schemas/memory-repair-work-result.schema.json +49 -0
  219. package/dist/schemas/memory-review-correction-plan.schema.json +30 -0
  220. package/dist/schemas/memory-review-work-result.schema.json +43 -0
  221. package/dist/schemas/model-catalog.schema.json +153 -0
  222. package/dist/schemas/plan-review-decision.schema.json +3 -3
  223. package/dist/schemas/plan-review-result.schema.json +2 -2
  224. package/dist/schemas/profile-settings.schema.json +122 -0
  225. package/dist/schemas/release-manifest.schema.json +291 -0
  226. package/dist/schemas/run-control-receipt.schema.json +118 -0
  227. package/dist/schemas/run-control-request.schema.json +36 -0
  228. package/dist/schemas/run-engine-binding.schema.json +1 -1
  229. package/dist/schemas/vnext-protocol-plan.schema.json +2 -2
  230. package/dist/services/branch-context.js +3 -3
  231. package/dist/services/canon.js +11 -8
  232. package/dist/services/check-runner-evidence.js +250 -0
  233. package/dist/services/cleanup.js +133 -40
  234. package/dist/services/cli-operation-classifier.js +25 -62
  235. package/dist/services/cli-upgrade-allowlist.js +27 -0
  236. package/dist/services/code-checks.js +1168 -107
  237. package/dist/services/codex-hook-delivery.js +32 -0
  238. package/dist/services/command-context.js +80 -0
  239. package/dist/services/compatibility-preflight.js +13 -3
  240. package/dist/services/config.js +11 -8
  241. package/dist/services/continuation-outcome.js +20 -0
  242. package/dist/services/controller-child-capacity.js +13 -0
  243. package/dist/services/controller-child-observer.js +115 -0
  244. package/dist/services/controller-execution.js +88 -0
  245. package/dist/services/controller-fanout.js +202 -0
  246. package/dist/services/dashboard.js +143 -58
  247. package/dist/services/descriptor-coordinator-session.js +35 -0
  248. package/dist/services/descriptor-root-work.js +53 -0
  249. package/dist/services/descriptor-run-settlement.js +105 -0
  250. package/dist/services/descriptor-run-start.js +449 -0
  251. package/dist/services/descriptor-stage-coordinator.js +197 -0
  252. package/dist/services/descriptor-stage-settlement.js +222 -0
  253. package/dist/services/descriptor-stage-start.js +139 -0
  254. package/dist/services/discovery/agy-discovery.js +2 -0
  255. package/dist/services/discovery/codex-discovery.js +2 -0
  256. package/dist/services/discovery/droid-discovery.js +2 -0
  257. package/dist/services/discovery/grok-discovery.js +2 -0
  258. package/dist/services/discovery/opencode-discovery.js +2 -0
  259. package/dist/services/discovery/static.js +31 -0
  260. package/dist/services/discovery/zcode-discovery.js +2 -0
  261. package/dist/services/engines.js +294 -153
  262. package/dist/services/eval-snapshots.js +1215 -116
  263. package/dist/services/execution-bundles.js +263 -0
  264. package/dist/services/execution-policy.js +185 -0
  265. package/dist/services/executor-onboarding.js +56 -0
  266. package/dist/services/external-work-launch.js +308 -0
  267. package/dist/services/flow-catalog.js +21 -0
  268. package/dist/services/flow-descriptors.js +82 -0
  269. package/dist/services/frozen-engine.js +250 -0
  270. package/dist/services/generic-execution.js +164 -0
  271. package/dist/services/harness-adapter.js +355 -36
  272. package/dist/services/harness-config.js +2 -0
  273. package/dist/services/harness-discovery.js +29 -0
  274. package/dist/services/harness-doctor.js +75 -0
  275. package/dist/services/harness-probe-effects.js +51 -0
  276. package/dist/services/harness-version-probe.js +100 -0
  277. package/dist/services/hooks.js +771 -325
  278. package/dist/services/hybrid-contracts.js +483 -0
  279. package/dist/services/ids.js +29 -1
  280. package/dist/services/installation-lock.js +95 -0
  281. package/dist/services/installed-flow-source.js +183 -0
  282. package/dist/services/lanes.js +78 -65
  283. package/dist/services/lifecycle-command.js +1 -288
  284. package/dist/services/lifecycle-contract.js +1 -0
  285. package/dist/services/lifecycle-invocations.js +2007 -0
  286. package/dist/services/managed-daemon-binding.js +38 -0
  287. package/dist/services/managed-lease-monitor.js +133 -0
  288. package/dist/services/managed-processes.js +475 -55
  289. package/dist/services/memory-accepted-composition.js +77 -0
  290. package/dist/services/memory-baseline-preservation.js +65 -0
  291. package/dist/services/memory-completed-correction-wave.js +320 -0
  292. package/dist/services/memory-compose-handler.js +258 -0
  293. package/dist/services/memory-composition-acceptance.js +199 -0
  294. package/dist/services/memory-composition-graph.js +134 -0
  295. package/dist/services/memory-composition-registration.js +146 -0
  296. package/dist/services/memory-composition-work-custody.js +151 -0
  297. package/dist/services/memory-composition-work-results.js +96 -0
  298. package/dist/services/memory-corrected-review-acceptance.js +129 -0
  299. package/dist/services/memory-corrected-review-batch.js +30 -0
  300. package/dist/services/memory-corrected-review-findings.js +106 -0
  301. package/dist/services/memory-corrected-review-inputs.js +210 -0
  302. package/dist/services/memory-corrected-review-projection.js +78 -0
  303. package/dist/services/memory-corrected-review-receipt.js +170 -0
  304. package/dist/services/memory-corrected-review-registration.js +191 -0
  305. package/dist/services/memory-correction-check-receipt.js +219 -0
  306. package/dist/services/memory-correction-input-owner.js +6 -0
  307. package/dist/services/memory-discover-handler.js +104 -0
  308. package/dist/services/memory-finish-evidence.js +435 -0
  309. package/dist/services/memory-finish-handler.js +215 -0
  310. package/dist/services/memory-finish-integration.js +280 -0
  311. package/dist/services/memory-finish-readiness.js +122 -0
  312. package/dist/services/memory-git-integration.js +151 -0
  313. package/dist/services/memory-historical-corrected-review.js +206 -0
  314. package/dist/services/memory-historical-original-review.js +130 -0
  315. package/dist/services/memory-historical-repair-registration.js +99 -0
  316. package/dist/services/memory-historical-second-review.js +128 -0
  317. package/dist/services/memory-init-bootstrap-readiness.js +210 -0
  318. package/dist/services/memory-init-contexts.js +89 -0
  319. package/dist/services/memory-init-controller-start.js +84 -0
  320. package/dist/services/memory-init-engine-release.js +223 -0
  321. package/dist/services/memory-init-git-policy.js +136 -0
  322. package/dist/services/memory-init-lint-capability.js +185 -0
  323. package/dist/services/memory-init-native-capacity.js +296 -0
  324. package/dist/services/memory-init-preflight.js +330 -0
  325. package/dist/services/memory-init-project-bootstrap.js +599 -0
  326. package/dist/services/memory-init-request-candidate.js +157 -0
  327. package/dist/services/memory-init-request-input.js +66 -0
  328. package/dist/services/memory-init-resource-storage.js +125 -0
  329. package/dist/services/memory-init-run-allocation.js +81 -0
  330. package/dist/services/memory-init-run-bundle.js +98 -0
  331. package/dist/services/memory-init-start.js +181 -0
  332. package/dist/services/memory-init-startup-custody.js +80 -0
  333. package/dist/services/memory-init-startup-input.js +240 -0
  334. package/dist/services/memory-init-storage.js +81 -0
  335. package/dist/services/memory-init-stores.js +359 -0
  336. package/dist/services/memory-init-worktrunk-capability.js +178 -0
  337. package/dist/services/memory-layer-publication.js +611 -0
  338. package/dist/services/memory-layer.js +156 -0
  339. package/dist/services/memory-lint-config.js +85 -0
  340. package/dist/services/memory-native-review-copy.js +165 -0
  341. package/dist/services/memory-normal-flow-entry.js +75 -0
  342. package/dist/services/memory-ordinary-defaults.js +112 -0
  343. package/dist/services/memory-preflight-bootstrap-custody.js +115 -0
  344. package/dist/services/memory-preflight-handler.js +259 -0
  345. package/dist/services/memory-repair-current-view.js +299 -0
  346. package/dist/services/memory-repair-document-delta.js +451 -0
  347. package/dist/services/memory-repair-history.js +491 -0
  348. package/dist/services/memory-repair-physical-binding.js +312 -0
  349. package/dist/services/memory-repair-publication-files.js +152 -0
  350. package/dist/services/memory-repair-publication-intent.js +27 -0
  351. package/dist/services/memory-repair-publication-plan.js +160 -0
  352. package/dist/services/memory-repair-publication-source.js +225 -0
  353. package/dist/services/memory-repair-publication.js +794 -0
  354. package/dist/services/memory-repair-registration.js +239 -0
  355. package/dist/services/memory-repair-work-baseline.js +413 -0
  356. package/dist/services/memory-repair-work-completion.js +97 -0
  357. package/dist/services/memory-repair-work-custody.js +73 -0
  358. package/dist/services/memory-repair-work-results.js +89 -0
  359. package/dist/services/memory-repair-workspace.js +252 -0
  360. package/dist/services/memory-repair-writer-copy.js +735 -0
  361. package/dist/services/memory-result-binding.js +173 -0
  362. package/dist/services/memory-retained-review-authority.js +129 -0
  363. package/dist/services/memory-retained-review-results.js +70 -0
  364. package/dist/services/memory-retained-second-baseline.js +102 -0
  365. package/dist/services/memory-retained-second-repairs.js +156 -0
  366. package/dist/services/memory-review-acceptance.js +214 -0
  367. package/dist/services/memory-review-correction-plan.js +171 -0
  368. package/dist/services/memory-review-handler.js +585 -0
  369. package/dist/services/memory-review-inputs.js +200 -0
  370. package/dist/services/memory-review-receipt.js +180 -0
  371. package/dist/services/memory-review-registration.js +108 -0
  372. package/dist/services/memory-review-work-custody.js +124 -0
  373. package/dist/services/memory-review-work-input.js +72 -0
  374. package/dist/services/memory-review-work-results.js +73 -0
  375. package/dist/services/memory-second-corrected-review-inputs.js +165 -0
  376. package/dist/services/memory-second-correction-plan.js +76 -0
  377. package/dist/services/memory-second-repair-baseline.js +91 -0
  378. package/dist/services/memory-second-repair-launch.js +614 -0
  379. package/dist/services/memory-second-repair-registration.js +88 -0
  380. package/dist/services/memory-second-repair-source.js +187 -0
  381. package/dist/services/memory-second-review-acceptance.js +115 -0
  382. package/dist/services/memory-source-observations.js +117 -0
  383. package/dist/services/memory-stage-dispatch.js +28 -0
  384. package/dist/services/memory-stage-results.js +199 -0
  385. package/dist/services/memory-verification-acceptance.js +135 -0
  386. package/dist/services/memory-verification-checks.js +252 -0
  387. package/dist/services/memory-verification-receipt.js +159 -0
  388. package/dist/services/memory-verify-handler.js +135 -0
  389. package/dist/services/memory-work-result-preparation.js +63 -0
  390. package/dist/services/merge-queue.js +228 -149
  391. package/dist/services/merge-server.js +161 -35
  392. package/dist/services/migrations.js +37 -16
  393. package/dist/services/model-catalog.js +109 -0
  394. package/dist/services/model-discovery.js +46 -0
  395. package/dist/services/native-daemon-history.js +49 -0
  396. package/dist/services/native-session-control.js +39 -0
  397. package/dist/services/operator-profiles.js +236 -0
  398. package/dist/services/plan-runtime.js +26 -11
  399. package/dist/services/plans.js +28 -25
  400. package/dist/services/projects.js +37 -17
  401. package/dist/services/prompts.js +28 -17
  402. package/dist/services/protocols.js +163 -87
  403. package/dist/services/provider-capacity.js +385 -0
  404. package/dist/services/recovery-observation-budget.js +121 -0
  405. package/dist/services/recovery-snapshot-database.js +560 -0
  406. package/dist/services/release-archive-producer.js +52 -0
  407. package/dist/services/release-archive.js +143 -0
  408. package/dist/services/release-cache.js +142 -0
  409. package/dist/services/release-compatibility.js +18 -0
  410. package/dist/services/release-download.js +67 -0
  411. package/dist/services/release-envelope.js +104 -0
  412. package/dist/services/release-manifest.js +45 -0
  413. package/dist/services/release-payload.js +114 -0
  414. package/dist/services/release-producer.js +63 -0
  415. package/dist/services/release-provenance.js +160 -0
  416. package/dist/services/release-registry.js +66 -0
  417. package/dist/services/release-source.js +194 -0
  418. package/dist/services/repair-intents.js +42 -0
  419. package/dist/services/review-copy.js +165 -0
  420. package/dist/services/review-deferral.js +23 -0
  421. package/dist/services/run-control-receipt.js +56 -0
  422. package/dist/services/run-control-worker.js +411 -0
  423. package/dist/services/run-control.js +1056 -0
  424. package/dist/services/run-controller-adapter.js +399 -0
  425. package/dist/services/run-controller-capture.js +186 -0
  426. package/dist/services/run-controller-process.js +208 -0
  427. package/dist/services/run-controller-recovery.js +289 -0
  428. package/dist/services/run-controller-state.js +97 -0
  429. package/dist/services/run-controller.js +1205 -0
  430. package/dist/services/run-engine-bindings.js +1 -1
  431. package/dist/services/run-fork.js +147 -0
  432. package/dist/services/run-health.js +149 -0
  433. package/dist/services/run-observations.js +152 -0
  434. package/dist/services/run-projection.js +22 -64
  435. package/dist/services/run-recovery-guard.js +77 -0
  436. package/dist/services/run-recovery-runtime.js +112 -0
  437. package/dist/services/run-recovery.js +489 -0
  438. package/dist/services/run-start-custody.js +177 -0
  439. package/dist/services/runs.js +1019 -247
  440. package/dist/services/runtime-budget.js +430 -0
  441. package/dist/services/runtime-command.js +43 -0
  442. package/dist/services/runtime-scope-capture.js +52 -0
  443. package/dist/services/runtime-scope-control.js +468 -0
  444. package/dist/services/runtime-scope-resume.js +599 -0
  445. package/dist/services/runtime-scope-stop.js +210 -0
  446. package/dist/services/runtime-scope-worker.js +287 -0
  447. package/dist/services/runtime-service.js +96 -0
  448. package/dist/services/schema-validation.js +10 -8
  449. package/dist/services/scope-writer-cleanup.js +27 -0
  450. package/dist/services/sessions.js +35 -69
  451. package/dist/services/setup.js +377 -0
  452. package/dist/services/stage-blocker.js +17 -7
  453. package/dist/services/stage-context.js +193 -19
  454. package/dist/services/stage-handlers.js +74 -0
  455. package/dist/services/stage-lifecycle.js +152 -116
  456. package/dist/services/stage-pause.js +89 -75
  457. package/dist/services/stage-report-renderer.js +234 -6
  458. package/dist/services/stage-work-graph.js +52 -0
  459. package/dist/services/tooling.js +41 -30
  460. package/dist/services/usage.js +49 -101
  461. package/dist/services/verification-matrix.js +375 -0
  462. package/dist/services/vnext-code-review.js +223 -88
  463. package/dist/services/vnext-code.js +327 -226
  464. package/dist/services/vnext-contracts.js +10 -1
  465. package/dist/services/vnext-execution-profile.js +80 -5
  466. package/dist/services/vnext-fanout.js +311 -19
  467. package/dist/services/vnext-merge.js +332 -111
  468. package/dist/services/vnext-plan-review.js +279 -127
  469. package/dist/services/vnext-plan.js +228 -104
  470. package/dist/services/vnext-protocolize.js +531 -95
  471. package/dist/services/vnext-specify.js +119 -81
  472. package/dist/services/vnext-workspace-policy.js +7 -2
  473. package/dist/services/work-registry.js +1627 -199
  474. package/dist/services/workspace-bootstrap.js +52 -15
  475. package/dist/services/workspace-files.js +85 -0
  476. package/dist/services/worktrees.js +105 -48
  477. package/dist/shared/entity-references.js +8 -0
  478. package/dist/shared/errors.js +27 -0
  479. package/dist/storage/agent-output.js +26 -0
  480. package/dist/storage/database.js +891 -39
  481. package/dist/storage/foreign-key-transaction.js +39 -0
  482. package/dist/storage/immutable-input.js +45 -0
  483. package/dist/storage/import-guard.js +102 -0
  484. package/dist/storage/native-cleanup.js +52 -0
  485. package/dist/storage/paths.js +17 -4
  486. package/dist/storage/projection-lock.js +73 -0
  487. package/dist/storage/work-references.js +23 -0
  488. package/dist/storage/writer-contract.js +89 -0
  489. package/dist/storage/writer-migration.js +85 -0
  490. package/package.json +43 -13
  491. package/tools/create-canon-release.mjs +33 -0
  492. package/tools/produce-hybrid-release.mjs +41 -0
  493. package/tools/repair-paused-run-status.mjs +84 -0
@@ -0,0 +1,599 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { createHash } from "node:crypto";
4
+ import semver from "semver";
5
+ import { AppError, errorRecord } from "../shared/errors.js";
6
+ import { hybridDigest } from "./hybrid-contracts.js";
7
+ import { FrozenGenericExecution } from "./generic-execution.js";
8
+ import { PreparedMemoryInitTarget } from "./memory-init-preflight.js";
9
+ import { PreparedMemoryInitRuntimeStorage } from "./memory-init-storage.js";
10
+ import { PreparedMemoryLayer } from "./memory-layer.js";
11
+ import { publishMemoryInitDraftIdentity, readRetainedMemoryLayer, restorePublishedMemoryLayer } from "./memory-layer-publication.js";
12
+ import { PreparedProjectRegistration, registerPreparedProject } from "./projects.js";
13
+ import { resolveHarnessCommand } from "./harness-config.js";
14
+ import { readBoundedReleaseFile } from "./release-source.js";
15
+ import { appendAudit } from "./audit.js";
16
+ import { PreparedMemoryInitLintCapability, isMemoryInitLintCapabilityFacts } from "./memory-init-lint-capability.js";
17
+ import { PreparedMemoryInitWorktrunkCapability, isMemoryInitWorktrunkCapabilityFacts } from "./memory-init-worktrunk-capability.js";
18
+ import { PreparedMemoryInitResourceStorage, isMemoryInitResourceStorageFacts } from "./memory-init-resource-storage.js";
19
+ import { AdmittedFrozenEngine } from "./frozen-engine.js";
20
+ import { resourceHome } from "./managed-processes.js";
21
+ import { readSetupStatus } from "./setup.js";
22
+ import { readMemoryInitGitPolicy } from "./memory-init-git-policy.js";
23
+ const intentEvent = "memory.init_project_bootstrap_intent", receiptEvent = "memory.init_project_bootstrap";
24
+ const digest = (value) => createHash("sha256").update(value).digest("hex");
25
+ function refuse(reason, effect = "no_effect") {
26
+ throw new AppError("memory_init_project_bootstrap_invalid", "Project bootstrap cannot proceed without its exact request custody", 1, { reason, effect, next_action: "reconcile_exact_request" });
27
+ }
28
+ function row(context, scope, event) {
29
+ if (!scope || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,95}$/.test(scope.requestId)
30
+ || !path.isAbsolute(scope.projectRoot) || !path.isAbsolute(scope.workspaceRoot)
31
+ || Object.keys(scope).some(key => !["requestId", "projectRoot", "workspaceRoot"].includes(key)))
32
+ refuse("invalid_request_scope");
33
+ const rows = context.db.all("SELECT id, project_id, payload_json FROM audit_events WHERE event_type = ? AND json_extract(payload_json, '$.scope.requestId') = ? AND json_extract(payload_json, '$.scope.projectRoot') = ? AND json_extract(payload_json, '$.scope.workspaceRoot') = ? LIMIT 2", [event, scope.requestId, scope.projectRoot, scope.workspaceRoot]);
34
+ if (rows.length > 1)
35
+ refuse("ambiguous_request_custody");
36
+ const selected = rows[0];
37
+ if (!selected)
38
+ return null;
39
+ try {
40
+ if (Buffer.byteLength(selected.payload_json) > 1024 * 1024)
41
+ refuse("unbounded_request_custody");
42
+ return { ...selected, value: JSON.parse(selected.payload_json) };
43
+ }
44
+ catch (error) {
45
+ if (error instanceof AppError)
46
+ throw error;
47
+ return refuse("invalid_request_custody");
48
+ }
49
+ }
50
+ /** SQL-only prepublication release selection. Current setup defaults are not a
51
+ * restart source, and old draft receipts do not fabricate this missing proof.
52
+ */
53
+ export function readMemoryInitReleaseSelection(context, scope) {
54
+ const retained = row(context, scope, "memory.init_release_selection");
55
+ if (!retained)
56
+ return null;
57
+ const value = retained.value;
58
+ if (value.schema_id !== "dd-flow/memory-init-release-selection@1" || hybridDigest(value.scope) !== hybridDigest(scope)
59
+ || Object.keys(value).sort().join() !== "bootstrap_identity,execution_sha256,installation_manifest_base64,installation_manifest_sha256,pack_sha256,schema_id,scope"
60
+ || [value.bootstrap_identity, value.execution_sha256, value.pack_sha256, value.installation_manifest_sha256].some(sha => typeof sha !== "string" || !/^[a-f0-9]{64}$/.test(sha))
61
+ || typeof value.installation_manifest_base64 !== "string" || value.installation_manifest_base64.length > 1024 * 1024)
62
+ refuse("release_selection_custody_changed");
63
+ const bytes = Buffer.from(value.installation_manifest_base64, "base64");
64
+ if (!bytes.length || bytes.toString("base64") !== value.installation_manifest_base64
65
+ || digest(bytes) !== value.installation_manifest_sha256)
66
+ refuse("release_selection_custody_changed");
67
+ return structuredClone(value);
68
+ }
69
+ function readIntent(context, scope) {
70
+ const selected = row(context, scope, intentEvent);
71
+ if (!selected)
72
+ return null;
73
+ const value = selected.value;
74
+ if (!["dd-flow/memory-init-project-bootstrap-intent@1", "dd-flow/memory-init-project-bootstrap-intent@2", "dd-flow/memory-init-project-bootstrap-intent@3", "dd-flow/memory-init-project-bootstrap-intent@4"].includes(value.schema_id) || hybridDigest(value.scope) !== hybridDigest(scope)
75
+ || !/^[a-f0-9]{64}$/.test(value.identity) || !["prepared", "registered"].includes(value.status)
76
+ || Object.keys(value).some(key => !["schema_id", "scope", "identity", "expected_project", "status", "receipt_sha256", "lint_capability", "worktrunk_capability", "resource_storage"].includes(key))
77
+ || (value.schema_id !== "dd-flow/memory-init-project-bootstrap-intent@1" ? !isMemoryInitLintCapabilityFacts(value.lint_capability) : value.lint_capability !== undefined)
78
+ || (["dd-flow/memory-init-project-bootstrap-intent@3", "dd-flow/memory-init-project-bootstrap-intent@4"].includes(value.schema_id) ? !isMemoryInitWorktrunkCapabilityFacts(value.worktrunk_capability) : value.worktrunk_capability !== undefined)
79
+ || (value.schema_id === "dd-flow/memory-init-project-bootstrap-intent@4" ? !isMemoryInitResourceStorageFacts(value.resource_storage) : value.resource_storage !== undefined)
80
+ || value.expected_project !== null && (!value.expected_project || typeof value.expected_project.id !== "string"
81
+ || value.expected_project.root !== scope.projectRoot || value.expected_project.status !== "active"
82
+ || Object.keys(value.expected_project).some(key => !["id", "root", "status"].includes(key)))
83
+ || (value.status === "prepared" ? value.receipt_sha256 !== null : typeof value.receipt_sha256 !== "string" || !/^[a-f0-9]{64}$/.test(value.receipt_sha256)))
84
+ refuse("invalid_request_intent");
85
+ return { ...selected, intent: value };
86
+ }
87
+ /** One consistent SQL snapshot of historical custody, not current files/readiness. */
88
+ export function readMemoryInitProjectBootstrap(context, scope) {
89
+ return context.db.readSnapshot(() => readProjectBootstrapSnapshot(context, scope));
90
+ }
91
+ function readProjectBootstrapSnapshot(context, scope) {
92
+ const intent = readIntent(context, scope), selected = row(context, scope, receiptEvent);
93
+ if (!intent) {
94
+ if (selected)
95
+ refuse("bootstrap_intent_missing");
96
+ return null;
97
+ }
98
+ if (intent.intent.status === "prepared") {
99
+ if (selected)
100
+ refuse("uncommitted_bootstrap_receipt");
101
+ return null;
102
+ }
103
+ if (!selected)
104
+ refuse("bootstrap_receipt_missing");
105
+ const payload = selected.value, receipt = payload.receipt;
106
+ if (!receipt || !["dd-flow/memory-init-project-bootstrap@1", "dd-flow/memory-init-project-bootstrap@2", "dd-flow/memory-init-project-bootstrap@3", "dd-flow/memory-init-project-bootstrap@4"].includes(receipt.schema_id) || hybridDigest(receipt.scope) !== hybridDigest(scope)
107
+ || Object.keys(payload).some(key => !["scope", "identity", "sha256", "receipt"].includes(key))
108
+ || Object.keys(receipt).some(key => !["schema_id", "scope", "identity", "project_id", "target_sha256", "layer_sha256", "execution_sha256", "storage_sha256", "layer_publication_sha256", "draft_identity_sha256", "lint_capability_sha256", "worktrunk_capability_sha256", "resource_storage_sha256", "semantic_status", "created_at"].includes(key))
109
+ || intent.intent.schema_id !== receipt.schema_id.replace("project-bootstrap@", "project-bootstrap-intent@")
110
+ || (receipt.schema_id !== "dd-flow/memory-init-project-bootstrap@1" ? receipt.lint_capability_sha256 !== hybridDigest(intent.intent.lint_capability) : receipt.lint_capability_sha256 !== undefined)
111
+ || (["dd-flow/memory-init-project-bootstrap@3", "dd-flow/memory-init-project-bootstrap@4"].includes(receipt.schema_id) ? receipt.worktrunk_capability_sha256 !== hybridDigest(intent.intent.worktrunk_capability) : receipt.worktrunk_capability_sha256 !== undefined)
112
+ || (receipt.schema_id === "dd-flow/memory-init-project-bootstrap@4" ? receipt.resource_storage_sha256 !== hybridDigest(intent.intent.resource_storage) : receipt.resource_storage_sha256 !== undefined)
113
+ || typeof receipt.project_id !== "string" || !receipt.project_id
114
+ || receipt.identity !== intent.intent.identity || payload.identity !== receipt.identity || payload.sha256 !== hybridDigest(receipt)
115
+ || payload.sha256 !== intent.intent.receipt_sha256 || selected.project_id !== receipt.project_id
116
+ || receipt.semantic_status !== "draft_not_accepted" || typeof receipt.created_at !== "string" || !Number.isFinite(Date.parse(receipt.created_at))
117
+ || [receipt.target_sha256, receipt.layer_sha256, receipt.execution_sha256, receipt.storage_sha256,
118
+ receipt.layer_publication_sha256, receipt.draft_identity_sha256].some(value => typeof value !== "string" || !/^[a-f0-9]{64}$/.test(value)))
119
+ refuse("bootstrap_receipt_changed");
120
+ if (!context.db.get("SELECT 1 FROM projects WHERE id = ? AND root = ?", [receipt.project_id, scope.projectRoot]))
121
+ refuse("registered_project_identity_changed");
122
+ return { receipt: structuredClone(receipt), sha256: payload.sha256 };
123
+ }
124
+ /** Independent SQL proof lookup; historical v1 never gains new qualification. */
125
+ export function readMemoryInitProjectBootstrapLintCapability(context, scope) {
126
+ const registered = readMemoryInitProjectBootstrap(context, scope);
127
+ if (!registered || registered.receipt.schema_id === "dd-flow/memory-init-project-bootstrap@1")
128
+ return null;
129
+ const facts = readIntent(context, scope)?.intent.lint_capability;
130
+ if (!isMemoryInitLintCapabilityFacts(facts) || hybridDigest(facts) !== registered.receipt.lint_capability_sha256)
131
+ refuse("lint_capability_custody_changed");
132
+ return { facts: structuredClone(facts), sha256: registered.receipt.lint_capability_sha256 };
133
+ }
134
+ /** Independently retained functional proof; historical @1/@2 never gain it. */
135
+ export function readMemoryInitProjectBootstrapWorktrunkCapability(context, scope) {
136
+ const registered = readMemoryInitProjectBootstrap(context, scope);
137
+ if (!registered || !["dd-flow/memory-init-project-bootstrap@3", "dd-flow/memory-init-project-bootstrap@4"].includes(registered.receipt.schema_id))
138
+ return null;
139
+ const facts = readIntent(context, scope)?.intent.worktrunk_capability;
140
+ if (!isMemoryInitWorktrunkCapabilityFacts(facts) || hybridDigest(facts) !== registered.receipt.worktrunk_capability_sha256)
141
+ refuse("worktrunk_capability_custody_changed");
142
+ return { facts: structuredClone(facts), sha256: registered.receipt.worktrunk_capability_sha256 };
143
+ }
144
+ /** Independent retained storage proof; historical @1/@2/@3 never gain it. */
145
+ export function readMemoryInitProjectBootstrapResourceStorage(context, scope) {
146
+ const registered = readMemoryInitProjectBootstrap(context, scope);
147
+ if (!registered || registered.receipt.schema_id !== "dd-flow/memory-init-project-bootstrap@4")
148
+ return null;
149
+ const facts = readIntent(context, scope)?.intent.resource_storage;
150
+ if (!isMemoryInitResourceStorageFacts(facts) || hybridDigest(facts) !== registered.receipt.resource_storage_sha256)
151
+ refuse("resource_storage_custody_changed");
152
+ return { facts: structuredClone(facts), sha256: registered.receipt.resource_storage_sha256 };
153
+ }
154
+ /** Historical registration alone cannot attest engine-bound draft bootstrap. */
155
+ export function readMemoryInitProjectBootstrapEngineAdmission(context, scope) {
156
+ return context.db.readSnapshot(() => {
157
+ const accepted = row(context, scope, "memory.init_engine_bootstrap");
158
+ if (!accepted) {
159
+ if (row(context, scope, "memory.init_engine_admission")?.value.status === "accepted")
160
+ refuse("engine_bootstrap_custody_missing");
161
+ return null;
162
+ }
163
+ const registered = readMemoryInitProjectBootstrap(context, scope), admission = row(context, scope, "memory.init_engine_admission");
164
+ if (!registered || !admission)
165
+ refuse("engine_bootstrap_custody_missing");
166
+ const value = admission.value, proof = value.proof;
167
+ const policyBound = value.schema_id === "dd-flow/memory-init-engine-admission@2";
168
+ const policy = policyBound ? readMemoryInitGitPolicy(context, scope) : null;
169
+ const policyBinding = policyBound ? { git_policy_sha256: value.git_policy_sha256 } : {};
170
+ if (policyBound && (!policy || policy.target_sha256 !== registered.receipt.target_sha256
171
+ || hybridDigest(policy) !== value.git_policy_sha256))
172
+ refuse("git_policy_custody_changed");
173
+ if (Object.keys(value).sort().join() !== (policyBound
174
+ ? "acceptance_sha256,bootstrap_identity,execution_sha256,git_policy_sha256,identity,proof,schema_id,scope,status"
175
+ : "acceptance_sha256,bootstrap_identity,execution_sha256,identity,proof,schema_id,scope,status")
176
+ || value.status !== "accepted" || value.acceptance_sha256 !== hybridDigest(accepted.value)
177
+ || !["dd-flow/memory-init-engine-admission@1", "dd-flow/memory-init-engine-admission@2"].includes(value.schema_id) || hybridDigest(value.scope) !== hybridDigest(scope)
178
+ || value.bootstrap_identity !== registered.receipt.identity || value.execution_sha256 !== registered.receipt.execution_sha256
179
+ || !proof || Object.keys(proof).sort().join() !== "engine_manifest_sha256,engine_sha256,facts,sha256"
180
+ || !proof.facts || typeof proof.facts !== "object" || Array.isArray(proof.facts)
181
+ || [proof.engine_manifest_sha256, proof.engine_sha256, proof.sha256].some(hash => typeof hash !== "string" || !/^[a-f0-9]{64}$/.test(hash))
182
+ || hybridDigest(proof.facts) !== proof.sha256
183
+ || value.identity !== hybridDigest({ scope, bootstrap_identity: value.bootstrap_identity, execution_sha256: value.execution_sha256, proof, ...policyBinding }))
184
+ refuse("engine_admission_custody_changed");
185
+ const expected = { schema_id: "dd-flow/memory-init-engine-bootstrap@1", scope,
186
+ admission_identity: value.identity, bootstrap_sha256: registered.sha256, project_id: registered.receipt.project_id };
187
+ if (accepted.project_id !== registered.receipt.project_id || hybridDigest(accepted.value) !== hybridDigest(expected))
188
+ refuse("engine_bootstrap_custody_changed");
189
+ return { identity: value.identity, proof: structuredClone(proof), bootstrap_sha256: registered.sha256,
190
+ ...(policyBound ? { git_policy_sha256: value.git_policy_sha256 } : {}) };
191
+ });
192
+ }
193
+ function project(context, root) {
194
+ return context.db.get("SELECT id, root, status FROM projects WHERE root = ?", [root]) ?? null;
195
+ }
196
+ /** Static selected command/permission admission, usable before runtime stores.
197
+ * No diagnostic, provider process or credential read is performed. Bootstrap
198
+ * still captures and revalidates these same command identities independently. */
199
+ export function prepareMemoryInitHarnessCommands(context, execution) {
200
+ return execution.snapshot().profiles.map(({ id, profile }) => {
201
+ if (profile.permission !== "allow")
202
+ refuse("profile_permission_denied");
203
+ const inspect = (kind) => {
204
+ try {
205
+ const configured = resolveHarnessCommand(context.ddFlowHome, profile.harness, kind), resolved = fs.realpathSync(configured);
206
+ fs.accessSync(resolved, fs.constants.X_OK);
207
+ return { configured, resolved, sha256: digest(readBoundedReleaseFile(resolved, 256 * 1024 * 1024)) };
208
+ }
209
+ catch {
210
+ return refuse(`harness_command_unavailable:${profile.harness}:${kind}`);
211
+ }
212
+ };
213
+ return { profile_id: id, harness: profile.harness, adapter: inspect("adapter"), runtime: inspect("runtime") };
214
+ });
215
+ }
216
+ /** Productive project/draft registration, not a complete memory-bootstrap-receipt.
217
+ * Static command availability, frozen permission/routes, declared mb-lint minimum
218
+ * and executing run-store admission are checked before project effects. Selected
219
+ * mb-lint also passes isolated JSON/YAML/required-field/link behavior probes.
220
+ * Worktrunk passes an isolated actual Git-worktree creation probe before project
221
+ * effects. The executing CLI also admits the selected existing shared registry
222
+ * without initialization/migration. Frozen-engine/provider readiness and
223
+ * productive workspace custody still precede public dispatch.
224
+ */
225
+ export class PreparedMemoryInitProjectBootstrap {
226
+ identity;
227
+ #scope;
228
+ #target;
229
+ #layer;
230
+ #execution;
231
+ #storage;
232
+ #project;
233
+ #commands;
234
+ #lint;
235
+ #worktrunk;
236
+ #resource;
237
+ #installationManifestBase64;
238
+ constructor(context, target, layer, execution, storage) {
239
+ const facts = target.facts();
240
+ this.#scope = { requestId: facts.request_id, projectRoot: facts.project_root, workspaceRoot: facts.workspace_root };
241
+ this.#target = target;
242
+ this.#layer = layer;
243
+ this.#execution = execution;
244
+ this.#storage = storage;
245
+ const retainedSelection = readMemoryInitReleaseSelection(context, this.#scope);
246
+ if (retainedSelection) {
247
+ if (retainedSelection.installation_manifest_sha256 !== layer.installationSha256)
248
+ refuse("bootstrap_installation_changed");
249
+ this.#installationManifestBase64 = retainedSelection.installation_manifest_base64;
250
+ }
251
+ else {
252
+ // Historical draft registration remains resumable without a current setup
253
+ // selection. Only productive readiness requires retained release proof.
254
+ const selection = readSetupStatus(context.ddFlowHome);
255
+ this.#installationManifestBase64 = selection.installation_readiness === "installed"
256
+ && selection.installation?.manifest_sha256 === layer.installationSha256 ? selection.installation.manifest_bytes_base64 : null;
257
+ }
258
+ this.#project = PreparedProjectRegistration.prepare({ root: facts.project_root });
259
+ this.#resource = PreparedMemoryInitResourceStorage.prepare(context);
260
+ this.#commands = prepareMemoryInitHarnessCommands(context, execution);
261
+ this.#lint = PreparedMemoryInitLintCapability.prepare(target, context.env);
262
+ this.#worktrunk = PreparedMemoryInitWorktrunkCapability.prepare(target, context.env);
263
+ this.identity = hybridDigest({ scope: this.#scope, target: target.sha256, layer: layer.sha256,
264
+ execution: execution.sha256, storage: storage.sha256, resource: this.#resource.sha256, commands: this.#commands, lint: this.#lint.sha256, worktrunk: this.#worktrunk.sha256 });
265
+ Object.freeze(this);
266
+ }
267
+ /** Copied prepared release material; only the request owner may retain it.
268
+ * This is not engine, storage, provider or RUN readiness. */
269
+ releaseSelection() {
270
+ if (!this.#installationManifestBase64)
271
+ refuse("selected_release_manifest_unavailable");
272
+ return structuredClone({ schema_id: "dd-flow/memory-init-release-selection@1", scope: this.#scope,
273
+ bootstrap_identity: this.identity, execution_sha256: this.#execution.sha256, pack_sha256: this.#layer.packSha256,
274
+ installation_manifest_sha256: this.#layer.installationSha256, installation_manifest_base64: this.#installationManifestBase64 });
275
+ }
276
+ retainReadinessSelection(context) {
277
+ const value = this.releaseSelection();
278
+ context.db.writeTransaction(() => {
279
+ this.#storage.assertCompatibility(context);
280
+ const retained = readMemoryInitReleaseSelection(context, this.#scope);
281
+ if (retained) {
282
+ if (hybridDigest(retained) !== hybridDigest(value))
283
+ refuse("release_selection_custody_changed");
284
+ return;
285
+ }
286
+ if (readMemoryInitProjectBootstrap(context, this.#scope))
287
+ refuse("historical_bootstrap_has_no_release_selection");
288
+ appendAudit(context, { eventType: "memory.init_release_selection", payload: value });
289
+ }, "memoryInit.retainReleaseSelection");
290
+ }
291
+ static prepare(context, input) {
292
+ if (!(input.target instanceof PreparedMemoryInitTarget) || !(input.layer instanceof PreparedMemoryLayer)
293
+ || !(input.execution instanceof FrozenGenericExecution))
294
+ refuse("unprepared_bootstrap_input");
295
+ const facts = input.target.facts(), scope = input.execution.snapshot().scope;
296
+ if (input.execution.settings.flow_id !== "mb-init" || scope.requestId !== facts.request_id
297
+ || scope.projectRoot !== facts.project_root || scope.workspace !== facts.workspace_root)
298
+ refuse("foreign_execution_scope");
299
+ const current = project(context, facts.project_root);
300
+ if (current && current.status !== "active")
301
+ refuse("project_not_active");
302
+ let minimum;
303
+ try {
304
+ const compatibility = JSON.parse(input.layer.files().get("dd-flow/compatibility.json").toString("utf8"));
305
+ if (typeof compatibility.mb_lint?.min_version !== "string")
306
+ refuse("mb_lint_minimum_not_admitted");
307
+ minimum = compatibility.mb_lint.min_version;
308
+ }
309
+ catch {
310
+ return refuse("mb_lint_minimum_not_admitted");
311
+ }
312
+ if (!facts.tool_probes || !semver.valid(minimum) || !semver.valid(facts.tool_probes["mb-lint"].version)
313
+ || semver.lt(facts.tool_probes["mb-lint"].version, minimum))
314
+ refuse("mb_lint_minimum_not_admitted");
315
+ const prepared = new PreparedMemoryInitProjectBootstrap(context, input.target, input.layer, input.execution, PreparedMemoryInitRuntimeStorage.prepare(context));
316
+ const intent = readIntent(context, prepared.#scope);
317
+ if (intent && intent.intent.identity !== prepared.identity)
318
+ refuse("request_identity_changed");
319
+ if (intent && hybridDigest(intent.intent.lint_capability) !== prepared.#lint.sha256)
320
+ refuse("lint_capability_custody_changed");
321
+ if (intent && hybridDigest(intent.intent.worktrunk_capability) !== prepared.#worktrunk.sha256)
322
+ refuse("worktrunk_capability_custody_changed");
323
+ if (intent && hybridDigest(intent.intent.resource_storage) !== prepared.#resource.sha256)
324
+ refuse("resource_storage_custody_changed");
325
+ if (row(context, prepared.#scope, receiptEvent))
326
+ readMemoryInitProjectBootstrap(context, prepared.#scope);
327
+ if (!intent && fs.existsSync(path.join(facts.workspace_root, ".memory-bank")))
328
+ refuse("bootstrap_intent_missing");
329
+ prepared.revalidatePhysical(context, false);
330
+ return prepared;
331
+ }
332
+ /** Reconstruct an accepted bootstrap from request-local custody only. No
333
+ * cached caller target, current global installation or publication fallback
334
+ * can supply lost evidence. Tool/storage/command admission is repeated before
335
+ * returning; readiness still requires the independently selected engine.
336
+ */
337
+ static restore(context, execution) {
338
+ if (!(execution instanceof FrozenGenericExecution) || execution.settings.flow_id !== "mb-init")
339
+ refuse("unprepared_bootstrap_execution");
340
+ const frozen = execution.snapshot(), scope = { requestId: frozen.scope.requestId,
341
+ projectRoot: frozen.scope.projectRoot, workspaceRoot: frozen.scope.workspace };
342
+ const retained = context.db.readSnapshot(() => {
343
+ const registered = readMemoryInitProjectBootstrap(context, scope), selection = readMemoryInitReleaseSelection(context, scope);
344
+ if (!registered || registered.receipt.schema_id !== "dd-flow/memory-init-project-bootstrap@4" || !selection
345
+ || registered.receipt.execution_sha256 !== execution.sha256 || selection.execution_sha256 !== execution.sha256
346
+ || selection.bootstrap_identity !== registered.receipt.identity)
347
+ refuse("accepted_bootstrap_required");
348
+ return { registered, selection };
349
+ });
350
+ const restored = restorePublishedMemoryLayer(context.ddFlowHome, { ...scope,
351
+ targetSha256: retained.registered.receipt.target_sha256, layerSha256: retained.registered.receipt.layer_sha256,
352
+ installationSha256: retained.selection.installation_manifest_sha256 }, retained.registered.receipt.layer_publication_sha256, context.env, retained.registered.receipt.draft_identity_sha256);
353
+ if (restored.layer.packSha256 !== retained.selection.pack_sha256)
354
+ refuse("retained_pack_changed");
355
+ return PreparedMemoryInitProjectBootstrap.prepare(context, { target: restored.target, layer: restored.layer, execution });
356
+ }
357
+ revalidatePhysical(context, qualifyTools = true) {
358
+ const facts = this.#target.facts();
359
+ if (fs.existsSync(path.join(facts.workspace_root, ".memory-bank"))) {
360
+ const retained = readRetainedMemoryLayer(context.ddFlowHome, { projectRoot: facts.project_root,
361
+ workspaceRoot: facts.workspace_root, requestId: facts.request_id, targetSha256: this.#target.sha256,
362
+ layerSha256: this.#layer.sha256, installationSha256: this.#layer.installationSha256 });
363
+ if (retained.sha256 !== this.#layer.sha256)
364
+ refuse("retained_layer_changed");
365
+ PreparedMemoryInitTarget.revalidateOwnedPublication(facts, this.#target.sha256, context.env);
366
+ }
367
+ else
368
+ this.#target.revalidate();
369
+ if (hybridDigest(prepareMemoryInitHarnessCommands(context, this.#execution)) !== hybridDigest(this.#commands))
370
+ refuse("harness_commands_changed");
371
+ this.#resource.revalidate(context);
372
+ if (qualifyTools) {
373
+ this.#lint.revalidate(this.#target, context.env);
374
+ this.#worktrunk.revalidate(this.#target, context.env);
375
+ }
376
+ }
377
+ /** Independently observed input for the productive bootstrap receipt. This
378
+ * does not launch a provider or promote account/model access from unknown.
379
+ * Callers cannot replace the target, execution, release or accepted proof.
380
+ */
381
+ prepareReadiness(context, engine) {
382
+ if (!(engine instanceof AdmittedFrozenEngine))
383
+ refuse("selected_engine_not_admitted");
384
+ this.revalidatePhysical(context, false);
385
+ this.#storage.assertCompatibility(context);
386
+ const registered = readMemoryInitProjectBootstrap(context, this.#scope);
387
+ const accepted = readMemoryInitProjectBootstrapEngineAdmission(context, this.#scope);
388
+ const release = readMemoryInitReleaseSelection(context, this.#scope);
389
+ if (!registered || registered.receipt.identity !== this.identity || !accepted
390
+ || accepted.bootstrap_sha256 !== registered.sha256 || !release
391
+ || release.bootstrap_identity !== this.identity || release.execution_sha256 !== this.#execution.sha256
392
+ || release.pack_sha256 !== this.#layer.packSha256 || release.installation_manifest_sha256 !== this.#layer.installationSha256
393
+ || release.installation_manifest_base64 !== this.#installationManifestBase64)
394
+ refuse("accepted_engine_bootstrap_required");
395
+ const proof = engine.admitMemoryInitStorage(context.ddFlowHome, resourceHome(context));
396
+ if (hybridDigest(proof) !== hybridDigest(accepted.proof))
397
+ refuse("engine_storage_changed_after_bootstrap");
398
+ const manifest = engine.manifest(), installation = JSON.parse(Buffer.from(release.installation_manifest_base64, "base64").toString("utf8"));
399
+ if (installation.engine.package !== manifest.package_name
400
+ || installation.engine.version !== manifest.package_version)
401
+ refuse("readiness_installation_changed");
402
+ // Read exactly the admitted installed inventory, not a repository scan. A
403
+ // completed journal alone cannot qualify deleted/replaced installed files.
404
+ const memoryRoot = path.join(this.#scope.workspaceRoot, ".memory-bank"), rootOwner = fs.lstatSync(memoryRoot);
405
+ const marker = path.join(memoryRoot, ".dd-flow-layer-owner.json");
406
+ const publicationBytes = readBoundedReleaseFile(marker, 1024 * 1024);
407
+ const publication = JSON.parse(publicationBytes.toString("utf8"));
408
+ if (!rootOwner.isDirectory() || fs.lstatSync(marker).nlink !== 1
409
+ || digest(publicationBytes) !== registered.receipt.layer_publication_sha256
410
+ || publication.root_device !== rootOwner.dev || publication.root_inode !== rootOwner.ino)
411
+ refuse("readiness_layer_owner_changed");
412
+ for (const [logical, bytes] of this.#layer.files()) {
413
+ const file = path.join(this.#scope.workspaceRoot, ".memory-bank", logical);
414
+ let parent = path.join(this.#scope.workspaceRoot, ".memory-bank");
415
+ if (!fs.lstatSync(parent).isDirectory())
416
+ refuse("readiness_layer_changed");
417
+ for (const segment of logical.split("/").slice(0, -1)) {
418
+ parent = path.join(parent, segment);
419
+ if (!fs.lstatSync(parent).isDirectory())
420
+ refuse("readiness_layer_changed");
421
+ }
422
+ if (fs.lstatSync(file).nlink !== 1 || !readBoundedReleaseFile(file, 1024 * 1024).equals(bytes))
423
+ refuse("readiness_layer_changed");
424
+ }
425
+ return { scope: { ...this.#scope }, target: this.#target.facts(), execution_sha256: this.#execution.sha256,
426
+ pack_sha256: this.#layer.packSha256, installation_manifest_sha256: this.#layer.installationSha256,
427
+ installation_manifest_base64: release.installation_manifest_base64,
428
+ engine_manifest_base64: engine.manifestBytes().toString("base64"),
429
+ ...(accepted.git_policy_sha256 ? { git_policy_sha256: accepted.git_policy_sha256 } : {}), registered, accepted };
430
+ }
431
+ /** Productive engine-bound path. Historical draft receipts do not acquire this
432
+ * qualification: the independent gate must exist before project publication.
433
+ * This still does not assert provider or final normal-flow readiness.
434
+ */
435
+ applyWithEngine(context, engine, onCheckpoint) {
436
+ if (!(engine instanceof AdmittedFrozenEngine))
437
+ refuse("selected_engine_not_admitted");
438
+ const event = "memory.init_engine_admission";
439
+ // Old admission remains historical; a new request must freeze explicit
440
+ // policy before its first storage/bootstrap effect, never infer it here.
441
+ const legacy = row(context, this.#scope, event)?.value.schema_id === "dd-flow/memory-init-engine-admission@1";
442
+ const policy = legacy ? null : readMemoryInitGitPolicy(context, this.#scope);
443
+ if (!legacy && (!policy || policy.target_sha256 !== this.#target.sha256))
444
+ refuse("explicit_git_policy_required");
445
+ const policyBinding = policy ? { git_policy_sha256: hybridDigest(policy) } : {};
446
+ const proof = engine.admitMemoryInitStorage(context.ddFlowHome, resourceHome(context));
447
+ const identity = hybridDigest({ scope: this.#scope, bootstrap_identity: this.identity, execution_sha256: this.#execution.sha256, proof, ...policyBinding });
448
+ const expected = { schema_id: legacy ? "dd-flow/memory-init-engine-admission@1" : "dd-flow/memory-init-engine-admission@2", scope: this.#scope,
449
+ bootstrap_identity: this.identity, execution_sha256: this.#execution.sha256, identity, proof, ...policyBinding, status: "prepared", acceptance_sha256: null };
450
+ const assertReceipt = () => {
451
+ if (policy && hybridDigest(readMemoryInitGitPolicy(context, this.#scope)) !== policyBinding.git_policy_sha256)
452
+ refuse("git_policy_custody_changed");
453
+ const prior = row(context, this.#scope, event);
454
+ if (!prior || !["prepared", "accepted"].includes(prior.value.status)
455
+ || (prior.value.status === "prepared" ? prior.value.acceptance_sha256 !== null : typeof prior.value.acceptance_sha256 !== "string" || !/^[a-f0-9]{64}$/.test(prior.value.acceptance_sha256))
456
+ || hybridDigest({ ...prior.value, status: "prepared", acceptance_sha256: null }) !== hybridDigest(expected))
457
+ refuse("engine_admission_custody_changed");
458
+ return prior;
459
+ };
460
+ const revalidate = () => {
461
+ if (hybridDigest(engine.admitMemoryInitStorage(context.ddFlowHome, resourceHome(context))) !== hybridDigest(proof))
462
+ refuse("engine_storage_changed_after_preparation");
463
+ assertReceipt();
464
+ };
465
+ const alreadyPublished = fs.existsSync(path.join(this.#scope.workspaceRoot, ".memory-bank"));
466
+ context.db.writeTransaction(() => {
467
+ this.#storage.assertCompatibility(context);
468
+ const prior = row(context, this.#scope, event);
469
+ if (prior) {
470
+ assertReceipt();
471
+ return;
472
+ }
473
+ if (readMemoryInitProjectBootstrap(context, this.#scope))
474
+ refuse("historical_bootstrap_has_no_engine_admission");
475
+ // Existing draft intent is allowed only before any publication; do not
476
+ // retroactively qualify already installed bytes from the legacy path.
477
+ if (alreadyPublished)
478
+ refuse("engine_admission_after_publication");
479
+ appendAudit(context, { eventType: event, payload: expected });
480
+ }, "memoryInit.engineAdmission");
481
+ try {
482
+ this.retainReadinessSelection(context);
483
+ revalidate();
484
+ const registered = this.apply(context, phase => {
485
+ onCheckpoint?.(phase);
486
+ revalidate();
487
+ });
488
+ revalidate();
489
+ const acceptance = { schema_id: "dd-flow/memory-init-engine-bootstrap@1", scope: this.#scope,
490
+ admission_identity: identity, bootstrap_sha256: registered.sha256, project_id: registered.receipt.project_id };
491
+ context.db.writeTransaction(() => {
492
+ const admission = assertReceipt();
493
+ if (readMemoryInitProjectBootstrap(context, this.#scope)?.sha256 !== registered.sha256)
494
+ refuse("bootstrap_custody_changed");
495
+ const prior = row(context, this.#scope, "memory.init_engine_bootstrap");
496
+ if (prior) {
497
+ if (admission.value.status !== "accepted" || admission.value.acceptance_sha256 !== hybridDigest(acceptance) || hybridDigest(prior.value) !== hybridDigest(acceptance))
498
+ refuse("engine_bootstrap_custody_changed");
499
+ return;
500
+ }
501
+ if (admission.value.status === "accepted")
502
+ refuse("engine_bootstrap_custody_missing");
503
+ appendAudit(context, { projectId: registered.receipt.project_id, eventType: "memory.init_engine_bootstrap", payload: acceptance });
504
+ const updated = context.db.run("UPDATE audit_events SET payload_json=? WHERE id=? AND payload_json=?", [JSON.stringify({ ...admission.value, status: "accepted", acceptance_sha256: hybridDigest(acceptance) }), admission.id, admission.payload_json]);
505
+ if (updated.changes !== 1)
506
+ refuse("engine_admission_custody_changed");
507
+ }, "memoryInit.acceptEngineBootstrap");
508
+ return { ...registered, engine_admission_identity: identity };
509
+ }
510
+ catch (error) {
511
+ throw new AppError("memory_init_engine_bootstrap_failed", "Engine-bound bootstrap retained an incomplete request outcome", 1, { reason: error instanceof AppError ? error.details.reason ?? error.code : "engine_bootstrap_operation_failed",
512
+ effect: "partial", next_action: "reconcile_exact_request", cause: errorRecord(error) });
513
+ }
514
+ }
515
+ apply(context, onCheckpoint) {
516
+ const completed = readMemoryInitProjectBootstrap(context, this.#scope);
517
+ if (completed) {
518
+ if (completed.receipt.identity !== this.identity || project(context, this.#scope.projectRoot)?.status !== "active")
519
+ refuse("request_identity_changed");
520
+ return { ...completed, changed: false };
521
+ }
522
+ this.revalidatePhysical(context);
523
+ const fresh = !fs.existsSync(path.join(this.#scope.workspaceRoot, ".memory-bank"));
524
+ let retained = false;
525
+ try {
526
+ const intent = context.db.writeTransaction(() => {
527
+ this.#storage.assertCompatibility(context);
528
+ const prior = readIntent(context, this.#scope);
529
+ if (prior) {
530
+ if (prior.intent.identity !== this.identity)
531
+ refuse("request_identity_changed");
532
+ if (hybridDigest(prior.intent.lint_capability) !== this.#lint.sha256)
533
+ refuse("lint_capability_custody_changed");
534
+ if (hybridDigest(prior.intent.worktrunk_capability) !== this.#worktrunk.sha256)
535
+ refuse("worktrunk_capability_custody_changed");
536
+ if (hybridDigest(prior.intent.resource_storage) !== this.#resource.sha256)
537
+ refuse("resource_storage_custody_changed");
538
+ return prior.intent;
539
+ }
540
+ if (!fresh)
541
+ refuse("bootstrap_intent_missing");
542
+ const expected = project(context, this.#scope.projectRoot);
543
+ if (expected && expected.status !== "active")
544
+ refuse("project_not_active");
545
+ const value = { schema_id: "dd-flow/memory-init-project-bootstrap-intent@4", scope: this.#scope,
546
+ identity: this.identity, expected_project: expected, status: "prepared", receipt_sha256: null, lint_capability: this.#lint.facts(), worktrunk_capability: this.#worktrunk.facts(), resource_storage: this.#resource.facts() };
547
+ appendAudit(context, { eventType: intentEvent, payload: value });
548
+ return value;
549
+ }, "memoryInit.projectBootstrapIntent");
550
+ retained = true;
551
+ onCheckpoint?.("intent_retained");
552
+ this.revalidatePhysical(context);
553
+ const drafts = publishMemoryInitDraftIdentity(context.ddFlowHome, this.#target, this.#layer, context.env);
554
+ onCheckpoint?.("drafts_published");
555
+ this.revalidatePhysical(context);
556
+ const result = context.db.writeTransaction(() => {
557
+ this.#storage.assertCompatibility(context);
558
+ const replay = readMemoryInitProjectBootstrap(context, this.#scope);
559
+ if (replay) {
560
+ if (replay.receipt.identity !== this.identity)
561
+ refuse("request_identity_changed");
562
+ return { ...replay, changed: false };
563
+ }
564
+ const current = readIntent(context, this.#scope);
565
+ if (!current || hybridDigest(current.intent) !== hybridDigest(intent))
566
+ refuse("request_intent_changed");
567
+ const existing = project(context, this.#scope.projectRoot);
568
+ if (hybridDigest(existing) !== hybridDigest(intent.expected_project))
569
+ refuse("project_identity_changed");
570
+ if (!existing)
571
+ registerPreparedProject(context, this.#project);
572
+ const registered = project(context, this.#scope.projectRoot);
573
+ if (!registered || registered.status !== "active")
574
+ refuse("project_registration_failed");
575
+ const receipt = { schema_id: "dd-flow/memory-init-project-bootstrap@4",
576
+ scope: this.#scope, identity: this.identity, project_id: registered.id, target_sha256: this.#target.sha256,
577
+ layer_sha256: this.#layer.sha256, execution_sha256: this.#execution.sha256, storage_sha256: this.#storage.sha256,
578
+ layer_publication_sha256: drafts.receipt.layer_publication_sha256, draft_identity_sha256: drafts.sha256,
579
+ lint_capability_sha256: this.#lint.sha256,
580
+ worktrunk_capability_sha256: this.#worktrunk.sha256,
581
+ resource_storage_sha256: this.#resource.sha256,
582
+ semantic_status: "draft_not_accepted", created_at: context.now() };
583
+ const sha256 = hybridDigest(receipt);
584
+ appendAudit(context, { projectId: registered.id, eventType: receiptEvent, payload: { scope: this.#scope, identity: this.identity, sha256, receipt } });
585
+ context.db.run("UPDATE audit_events SET payload_json = ? WHERE id = ? AND payload_json = ?", [JSON.stringify({ ...intent, status: "registered", receipt_sha256: sha256 }), current.id, current.payload_json]);
586
+ const accepted = readMemoryInitProjectBootstrap(context, this.#scope);
587
+ if (!accepted)
588
+ refuse("bootstrap_receipt_not_committed");
589
+ return { ...accepted, changed: true };
590
+ }, "memoryInit.registerProjectBootstrap");
591
+ onCheckpoint?.("registered");
592
+ return result;
593
+ }
594
+ catch (error) {
595
+ throw new AppError("memory_init_project_bootstrap_failed", "Project bootstrap retained an incomplete request outcome", 1, { reason: error instanceof AppError ? error.details?.reason ?? error.code : "bootstrap_operation_failed",
596
+ effect: retained ? "partial" : "no_effect", next_action: "reconcile_exact_request", cause: errorRecord(error) });
597
+ }
598
+ }
599
+ }