@paradigma-inc/flywheel 0.1.111 → 0.1.134

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 (628) hide show
  1. package/README.md +79 -13
  2. package/package.json +14 -6
  3. package/skills/flywheel/SKILL.md +9 -6
  4. package/skills/flywheel/example-workflows/organizing-exploring-and-iterating-on-a-research-topic.md +38 -46
  5. package/skills/flywheel/example-workflows/reproducing-papers-on-a-budget.md +34 -36
  6. package/skills/flywheel/getting-started/flywheel-quickstart.md +2 -5
  7. package/skills/flywheel/getting-started/flywheel-tutorial-overview.md +1 -1
  8. package/skills/flywheel/references/INTERFACES.md +2 -2
  9. package/skills/flywheel/references/experiment-design-protocol.md +32 -25
  10. package/skills/flywheel/references/flywheel-cli-tool-map.md +120 -76
  11. package/skills/flywheel/references/flywheel-mcp-tool-map.md +42 -32
  12. package/skills/flywheel/setting-up-flywheel/claude-code-cli-installation.md +1 -1
  13. package/skills/flywheel/setting-up-flywheel/codex-cli-installation.md +1 -1
  14. package/skills/flywheel/setting-up-flywheel/how-can-i-get-an-authorized-client_id-for-the-oauth-flow.md +12 -4
  15. package/skills/flywheel/setting-up-flywheel/installation-overview.md +2 -6
  16. package/skills/flywheel/setting-up-flywheel/other-hosts-installation.md +53 -26
  17. package/skills/flywheel/setting-up-flywheel/updating-flywheel-mcp.md +34 -11
  18. package/skills/flywheel-auto/SKILL.md +40 -23
  19. package/skills/flywheel-auto/evals/evals.json +1 -1
  20. package/skills/flywheel-auto/references/INTERFACES.md +2 -2
  21. package/skills/flywheel-auto/references/experiment-design-protocol.md +31 -23
  22. package/skills/flywheel-auto/references/flywheel-cli-tool-map.md +172 -127
  23. package/skills/flywheel-auto/references/flywheel-mcp-tool-map.md +22 -24
  24. package/skills/flywheel-lookahead/SKILL.md +47 -28
  25. package/skills/flywheel-lookahead/agents/openai.yaml +1 -1
  26. package/skills/flywheel-lookahead/evals/evals.json +6 -6
  27. package/skills/flywheel-lookahead/references/INTERFACES.md +2 -2
  28. package/skills/flywheel-lookahead/references/flywheel-cli-tool-map.md +172 -127
  29. package/skills/flywheel-lookahead/references/flywheel-mcp-tool-map.md +22 -24
  30. package/skills/flywheel-prove/SKILL.md +2 -2
  31. package/skills/flywheel-prove/references/workflow.md +21 -2
  32. package/skills/flywheel-reproduce/SKILL.md +39 -19
  33. package/skills/flywheel-reproduce/evals/evals.json +1 -1
  34. package/skills/flywheel-reproduce/references/INTERFACES.md +2 -2
  35. package/skills/flywheel-reproduce/references/experiment-design-protocol.md +31 -23
  36. package/skills/flywheel-reproduce/references/flywheel-cli-tool-map.md +172 -127
  37. package/skills/flywheel-reproduce/references/flywheel-mcp-tool-map.md +22 -24
  38. package/skills/flywheel-to-graph/SKILL.md +37 -17
  39. package/skills/flywheel-to-graph/references/INTERFACES.md +2 -2
  40. package/skills/flywheel-to-graph/references/flywheel-cli-tool-map.md +172 -127
  41. package/skills/flywheel-to-graph/references/flywheel-mcp-tool-map.md +22 -24
  42. package/skills/flywheel-tree/references/workflow.md +6 -37
  43. package/src/cli.mjs +1145 -1141
  44. package/src/mcp-writer.mjs +413 -435
  45. package/src/public-command-metadata.mjs +28 -5
  46. package/src/runtime/delegate.mjs +2 -19
  47. package/src/runtime/required-runtime-commands.json +83 -28
  48. package/src/runtime/runtime-config.mjs +39 -60
  49. package/src/runtime/vendor/flywheel-cli-dist/auth/credentials.js +330 -0
  50. package/src/runtime/vendor/flywheel-cli-dist/auth/credentials.js.map +1 -0
  51. package/src/runtime/vendor/flywheel-cli-dist/auth/login.js +90 -139
  52. package/src/runtime/vendor/flywheel-cli-dist/auth/login.js.map +1 -1
  53. package/src/runtime/vendor/flywheel-cli-dist/auth/profiles.js +1 -1
  54. package/src/runtime/vendor/flywheel-cli-dist/auth/profiles.js.map +1 -1
  55. package/src/runtime/vendor/flywheel-cli-dist/auth/secure-write.js +116 -0
  56. package/src/runtime/vendor/flywheel-cli-dist/auth/secure-write.js.map +1 -0
  57. package/src/runtime/vendor/flywheel-cli-dist/commands/_browser-handoff.js +36 -14
  58. package/src/runtime/vendor/flywheel-cli-dist/commands/_browser-handoff.js.map +1 -1
  59. package/src/runtime/vendor/flywheel-cli-dist/commands/_open-url.js +15 -6
  60. package/src/runtime/vendor/flywheel-cli-dist/commands/_open-url.js.map +1 -1
  61. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-test-users-create.js +256 -0
  62. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-test-users-create.js.map +1 -0
  63. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-test-users-delete.js +11 -0
  64. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-test-users-delete.js.map +1 -0
  65. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-test-users-login.js +84 -0
  66. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-test-users-login.js.map +1 -0
  67. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-test-users-revoke-api-key.js +17 -0
  68. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-test-users-revoke-api-key.js.map +1 -0
  69. package/src/runtime/vendor/flywheel-cli-dist/commands/aliases.js +3 -7
  70. package/src/runtime/vendor/flywheel-cli-dist/commands/aliases.js.map +1 -1
  71. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-credentials-clear.js +12 -0
  72. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-credentials-clear.js.map +1 -0
  73. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-credentials-set.js +29 -0
  74. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-credentials-set.js.map +1 -0
  75. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-login.js +12 -0
  76. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-login.js.map +1 -1
  77. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-status.js +46 -10
  78. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-status.js.map +1 -1
  79. package/src/runtime/vendor/flywheel-cli-dist/commands/env.js +17 -40
  80. package/src/runtime/vendor/flywheel-cli-dist/commands/env.js.map +1 -1
  81. package/src/runtime/vendor/flywheel-cli-dist/commands/graph-operation-resources.js +305 -0
  82. package/src/runtime/vendor/flywheel-cli-dist/commands/graph-operation-resources.js.map +1 -0
  83. package/src/runtime/vendor/flywheel-cli-dist/commands/graph-operation-support.js +72 -0
  84. package/src/runtime/vendor/flywheel-cli-dist/commands/graph-operation-support.js.map +1 -0
  85. package/src/runtime/vendor/flywheel-cli-dist/commands/graph-operation.js +286 -0
  86. package/src/runtime/vendor/flywheel-cli-dist/commands/graph-operation.js.map +1 -0
  87. package/src/runtime/vendor/flywheel-cli-dist/commands/help-metadata.js +30 -5
  88. package/src/runtime/vendor/flywheel-cli-dist/commands/help-metadata.js.map +1 -1
  89. package/src/runtime/vendor/flywheel-cli-dist/commands/help.js +27 -12
  90. package/src/runtime/vendor/flywheel-cli-dist/commands/help.js.map +1 -1
  91. package/src/runtime/vendor/flywheel-cli-dist/commands/hosted-commit-replay.js +284 -0
  92. package/src/runtime/vendor/flywheel-cli-dist/commands/hosted-commit-replay.js.map +1 -0
  93. package/src/runtime/vendor/flywheel-cli-dist/commands/hosted-graph.js +169 -0
  94. package/src/runtime/vendor/flywheel-cli-dist/commands/hosted-graph.js.map +1 -0
  95. package/src/runtime/vendor/flywheel-cli-dist/commands/hosted-lineage-list.js +13 -0
  96. package/src/runtime/vendor/flywheel-cli-dist/commands/hosted-lineage-list.js.map +1 -0
  97. package/src/runtime/vendor/flywheel-cli-dist/commands/hosted-repository-snapshot.js +227 -0
  98. package/src/runtime/vendor/flywheel-cli-dist/commands/hosted-repository-snapshot.js.map +1 -0
  99. package/src/runtime/vendor/flywheel-cli-dist/commands/index.js +239 -263
  100. package/src/runtime/vendor/flywheel-cli-dist/commands/index.js.map +1 -1
  101. package/src/runtime/vendor/flywheel-cli-dist/commands/node-create-schema.js +25 -0
  102. package/src/runtime/vendor/flywheel-cli-dist/commands/node-create-schema.js.map +1 -0
  103. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-list.js +11 -9
  104. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-list.js.map +1 -1
  105. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-set.js +38 -45
  106. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-set.js.map +1 -1
  107. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-show.js +14 -17
  108. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-show.js.map +1 -1
  109. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-unset.js +13 -8
  110. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-unset.js.map +1 -1
  111. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/admin.js +237 -66
  112. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/admin.js.map +1 -1
  113. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/auth.js +9 -9
  114. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/auth.js.map +1 -1
  115. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/hosted.js +76 -0
  116. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/hosted.js.map +1 -0
  117. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/lifecycle.js +4 -138
  118. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/lifecycle.js.map +1 -1
  119. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/profile.js +8 -13
  120. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/profile.js.map +1 -1
  121. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/repository.js +362 -0
  122. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/repository.js.map +1 -0
  123. package/src/runtime/vendor/flywheel-cli-dist/commands/registry.js +45 -183
  124. package/src/runtime/vendor/flywheel-cli-dist/commands/registry.js.map +1 -1
  125. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-edit.js +47 -0
  126. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-edit.js.map +1 -0
  127. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-operation.js +181 -0
  128. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-operation.js.map +1 -0
  129. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-output.js +163 -0
  130. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-output.js.map +1 -0
  131. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-projection.js +79 -0
  132. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-projection.js.map +1 -0
  133. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-selection.js +80 -0
  134. package/src/runtime/vendor/flywheel-cli-dist/commands/repository-selection.js.map +1 -0
  135. package/src/runtime/vendor/flywheel-cli-dist/commands/retired-command-names.js +78 -0
  136. package/src/runtime/vendor/flywheel-cli-dist/commands/retired-command-names.js.map +1 -0
  137. package/src/runtime/vendor/flywheel-cli-dist/commands/types.js.map +1 -1
  138. package/src/runtime/vendor/flywheel-cli-dist/commands/usage-spec.js +3 -2
  139. package/src/runtime/vendor/flywheel-cli-dist/commands/usage-spec.js.map +1 -1
  140. package/src/runtime/vendor/flywheel-cli-dist/config/index.js +5 -0
  141. package/src/runtime/vendor/flywheel-cli-dist/config/index.js.map +1 -0
  142. package/src/runtime/vendor/flywheel-cli-dist/config/io.js +139 -0
  143. package/src/runtime/vendor/flywheel-cli-dist/config/io.js.map +1 -0
  144. package/src/runtime/vendor/flywheel-cli-dist/config/migration.js +299 -0
  145. package/src/runtime/vendor/flywheel-cli-dist/config/migration.js.map +1 -0
  146. package/src/runtime/vendor/flywheel-cli-dist/config/model.js +214 -0
  147. package/src/runtime/vendor/flywheel-cli-dist/config/model.js.map +1 -0
  148. package/src/runtime/vendor/flywheel-cli-dist/config/path.js +30 -0
  149. package/src/runtime/vendor/flywheel-cli-dist/config/path.js.map +1 -0
  150. package/src/runtime/vendor/flywheel-cli-dist/credential-output.js +29 -0
  151. package/src/runtime/vendor/flywheel-cli-dist/credential-output.js.map +1 -0
  152. package/src/runtime/vendor/flywheel-cli-dist/errors.js +1 -16
  153. package/src/runtime/vendor/flywheel-cli-dist/errors.js.map +1 -1
  154. package/src/runtime/vendor/flywheel-cli-dist/generatedProductTelemetryContract.js +3 -3
  155. package/src/runtime/vendor/flywheel-cli-dist/generatedProductTelemetryContract.js.map +1 -1
  156. package/src/runtime/vendor/flywheel-cli-dist/grammar/globals.js +19 -9
  157. package/src/runtime/vendor/flywheel-cli-dist/grammar/globals.js.map +1 -1
  158. package/src/runtime/vendor/flywheel-cli-dist/grammar/parse.js +33 -4
  159. package/src/runtime/vendor/flywheel-cli-dist/grammar/parse.js.map +1 -1
  160. package/src/runtime/vendor/flywheel-cli-dist/http/client.js +322 -302
  161. package/src/runtime/vendor/flywheel-cli-dist/http/client.js.map +1 -1
  162. package/src/runtime/vendor/flywheel-cli-dist/http/debug.js +1 -21
  163. package/src/runtime/vendor/flywheel-cli-dist/http/debug.js.map +1 -1
  164. package/src/runtime/vendor/flywheel-cli-dist/http/retry.js +1 -0
  165. package/src/runtime/vendor/flywheel-cli-dist/http/retry.js.map +1 -1
  166. package/src/runtime/vendor/flywheel-cli-dist/local/adapter.js +244 -0
  167. package/src/runtime/vendor/flywheel-cli-dist/local/adapter.js.map +1 -0
  168. package/src/runtime/vendor/flywheel-cli-dist/local/domain/errors.js +7 -0
  169. package/src/runtime/vendor/flywheel-cli-dist/local/domain/errors.js.map +1 -0
  170. package/src/runtime/vendor/flywheel-cli-dist/local/domain/history.js +35 -0
  171. package/src/runtime/vendor/flywheel-cli-dist/local/domain/history.js.map +1 -0
  172. package/src/runtime/vendor/flywheel-cli-dist/local/domain/invariants.js +42 -0
  173. package/src/runtime/vendor/flywheel-cli-dist/local/domain/invariants.js.map +1 -0
  174. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/artifact-properties.js +179 -0
  175. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/artifact-properties.js.map +1 -0
  176. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/commits.js +152 -0
  177. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/commits.js.map +1 -0
  178. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/constants.js +71 -0
  179. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/constants.js.map +1 -0
  180. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/encoding.js +73 -0
  181. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/encoding.js.map +1 -0
  182. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/imported-artifact-properties.js +82 -0
  183. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/imported-artifact-properties.js.map +1 -0
  184. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/operations.js +345 -0
  185. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/operations.js.map +1 -0
  186. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/tags.js +57 -0
  187. package/src/runtime/vendor/flywheel-cli-dist/local/domain/models/tags.js.map +1 -0
  188. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/conflicts.js +149 -0
  189. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/conflicts.js.map +1 -0
  190. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/context.js +115 -0
  191. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/context.js.map +1 -0
  192. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/keys.js +44 -0
  193. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/keys.js.map +1 -0
  194. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/pull.js +159 -0
  195. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/pull.js.map +1 -0
  196. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/replay.js +346 -0
  197. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/replay.js.map +1 -0
  198. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/resolve.js +37 -0
  199. package/src/runtime/vendor/flywheel-cli-dist/local/domain/rebase/resolve.js.map +1 -0
  200. package/src/runtime/vendor/flywheel-cli-dist/local/domain/revert/inverses.js +203 -0
  201. package/src/runtime/vendor/flywheel-cli-dist/local/domain/revert/inverses.js.map +1 -0
  202. package/src/runtime/vendor/flywheel-cli-dist/local/domain/revert/plan.js +207 -0
  203. package/src/runtime/vendor/flywheel-cli-dist/local/domain/revert/plan.js.map +1 -0
  204. package/src/runtime/vendor/flywheel-cli-dist/local/domain/revert/tag-inverses.js +109 -0
  205. package/src/runtime/vendor/flywheel-cli-dist/local/domain/revert/tag-inverses.js.map +1 -0
  206. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/commit.js +61 -0
  207. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/commit.js.map +1 -0
  208. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/projection.js +46 -0
  209. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/projection.js.map +1 -0
  210. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/revert.js +203 -0
  211. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/revert.js.map +1 -0
  212. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/staging.js +44 -0
  213. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/staging.js.map +1 -0
  214. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/writes.js +188 -0
  215. package/src/runtime/vendor/flywheel-cli-dist/local/domain/service/writes.js.map +1 -0
  216. package/src/runtime/vendor/flywheel-cli-dist/local/domain/sync/cursors.js +54 -0
  217. package/src/runtime/vendor/flywheel-cli-dist/local/domain/sync/cursors.js.map +1 -0
  218. package/src/runtime/vendor/flywheel-cli-dist/local/domain/sync/local-pull.js +25 -0
  219. package/src/runtime/vendor/flywheel-cli-dist/local/domain/sync/local-pull.js.map +1 -0
  220. package/src/runtime/vendor/flywheel-cli-dist/local/domain/sync-models.js +2 -0
  221. package/src/runtime/vendor/flywheel-cli-dist/local/domain/sync-models.js.map +1 -0
  222. package/src/runtime/vendor/flywheel-cli-dist/local/fs/native.js +7 -0
  223. package/src/runtime/vendor/flywheel-cli-dist/local/fs/native.js.map +1 -0
  224. package/src/runtime/vendor/flywheel-cli-dist/local/fs/state.js +129 -0
  225. package/src/runtime/vendor/flywheel-cli-dist/local/fs/state.js.map +1 -0
  226. package/src/runtime/vendor/flywheel-cli-dist/local/fs/writer-lock.js +277 -0
  227. package/src/runtime/vendor/flywheel-cli-dist/local/fs/writer-lock.js.map +1 -0
  228. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/bootstrap.js +183 -0
  229. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/bootstrap.js.map +1 -0
  230. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/context.js +2 -0
  231. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/context.js.map +1 -0
  232. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/dispatch.js +121 -0
  233. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/dispatch.js.map +1 -0
  234. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/doctor.js +16 -0
  235. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/doctor.js.map +1 -0
  236. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/identity.js +72 -0
  237. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/identity.js.map +1 -0
  238. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/conflicts.js +59 -0
  239. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/conflicts.js.map +1 -0
  240. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/core.js +125 -0
  241. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/core.js.map +1 -0
  242. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/history.js +129 -0
  243. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/history.js.map +1 -0
  244. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/index.js +31 -0
  245. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/index.js.map +1 -0
  246. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/maintenance.js +49 -0
  247. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/maintenance.js.map +1 -0
  248. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/projections.js +30 -0
  249. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/projections.js.map +1 -0
  250. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/shared.js +12 -0
  251. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/operations/shared.js.map +1 -0
  252. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/platform.js +18 -0
  253. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/platform.js.map +1 -0
  254. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/projection.js +125 -0
  255. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/projection.js.map +1 -0
  256. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/clone.js +37 -0
  257. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/clone.js.map +1 -0
  258. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/pull.js +44 -0
  259. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/pull.js.map +1 -0
  260. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/purge.js +58 -0
  261. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/purge.js.map +1 -0
  262. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/push.js +118 -0
  263. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/push.js.map +1 -0
  264. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/transport.js +277 -0
  265. package/src/runtime/vendor/flywheel-cli-dist/local/runtime/remote/transport.js.map +1 -0
  266. package/src/runtime/vendor/flywheel-cli-dist/local/store/apply.js +132 -0
  267. package/src/runtime/vendor/flywheel-cli-dist/local/store/apply.js.map +1 -0
  268. package/src/runtime/vendor/flywheel-cli-dist/local/store/backup/archive.js +372 -0
  269. package/src/runtime/vendor/flywheel-cli-dist/local/store/backup/archive.js.map +1 -0
  270. package/src/runtime/vendor/flywheel-cli-dist/local/store/backup/backup.js +210 -0
  271. package/src/runtime/vendor/flywheel-cli-dist/local/store/backup/backup.js.map +1 -0
  272. package/src/runtime/vendor/flywheel-cli-dist/local/store/backup/restore.js +278 -0
  273. package/src/runtime/vendor/flywheel-cli-dist/local/store/backup/restore.js.map +1 -0
  274. package/src/runtime/vendor/flywheel-cli-dist/local/store/backup/retained-directory.js +192 -0
  275. package/src/runtime/vendor/flywheel-cli-dist/local/store/backup/retained-directory.js.map +1 -0
  276. package/src/runtime/vendor/flywheel-cli-dist/local/store/commits.js +114 -0
  277. package/src/runtime/vendor/flywheel-cli-dist/local/store/commits.js.map +1 -0
  278. package/src/runtime/vendor/flywheel-cli-dist/local/store/contract.js +65 -0
  279. package/src/runtime/vendor/flywheel-cli-dist/local/store/contract.js.map +1 -0
  280. package/src/runtime/vendor/flywheel-cli-dist/local/store/diagnostics-worker.js +145 -0
  281. package/src/runtime/vendor/flywheel-cli-dist/local/store/diagnostics-worker.js.map +1 -0
  282. package/src/runtime/vendor/flywheel-cli-dist/local/store/diagnostics.js +218 -0
  283. package/src/runtime/vendor/flywheel-cli-dist/local/store/diagnostics.js.map +1 -0
  284. package/src/runtime/vendor/flywheel-cli-dist/local/store/gc.js +71 -0
  285. package/src/runtime/vendor/flywheel-cli-dist/local/store/gc.js.map +1 -0
  286. package/src/runtime/vendor/flywheel-cli-dist/local/store/history-validation.js +298 -0
  287. package/src/runtime/vendor/flywheel-cli-dist/local/store/history-validation.js.map +1 -0
  288. package/src/runtime/vendor/flywheel-cli-dist/local/store/latest-values.js +121 -0
  289. package/src/runtime/vendor/flywheel-cli-dist/local/store/latest-values.js.map +1 -0
  290. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrate.js +69 -0
  291. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrate.js.map +1 -0
  292. package/src/runtime/vendor/flywheel-cli-dist/local/store/migration/provenance.js +49 -0
  293. package/src/runtime/vendor/flywheel-cli-dist/local/store/migration/provenance.js.map +1 -0
  294. package/src/runtime/vendor/flywheel-cli-dist/local/store/migration/steps.js +424 -0
  295. package/src/runtime/vendor/flywheel-cli-dist/local/store/migration/steps.js.map +1 -0
  296. package/src/runtime/vendor/flywheel-cli-dist/local/store/migration/versions.js +10 -0
  297. package/src/runtime/vendor/flywheel-cli-dist/local/store/migration/versions.js.map +1 -0
  298. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrations/001_initial.sql +319 -0
  299. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrations/002_staged_latest_values.sql +8 -0
  300. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrations/003_remove_cli_editing_lease.sql +21 -0
  301. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrations/004_hosted_association.sql +7 -0
  302. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrations/005_artifact_properties.sql +68 -0
  303. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrations.js +12 -0
  304. package/src/runtime/vendor/flywheel-cli-dist/local/store/migrations.js.map +1 -0
  305. package/src/runtime/vendor/flywheel-cli-dist/local/store/objects.js +410 -0
  306. package/src/runtime/vendor/flywheel-cli-dist/local/store/objects.js.map +1 -0
  307. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/apply.js +77 -0
  308. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/apply.js.map +1 -0
  309. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/artifacts.js +240 -0
  310. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/artifacts.js.map +1 -0
  311. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/nodes.js +127 -0
  312. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/nodes.js.map +1 -0
  313. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/relations.js +107 -0
  314. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/relations.js.map +1 -0
  315. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/rules.js +80 -0
  316. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/rules.js.map +1 -0
  317. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/tags.js +219 -0
  318. package/src/runtime/vendor/flywheel-cli-dist/local/store/projection/tags.js.map +1 -0
  319. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/hosted.js +164 -0
  320. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/hosted.js.map +1 -0
  321. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/read.js +20 -0
  322. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/read.js.map +1 -0
  323. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/replace.js +41 -0
  324. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/replace.js.map +1 -0
  325. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/schema.js +22 -0
  326. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/schema.js.map +1 -0
  327. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/validate.js +188 -0
  328. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot/validate.js.map +1 -0
  329. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot.js +5 -0
  330. package/src/runtime/vendor/flywheel-cli-dist/local/store/snapshot.js.map +1 -0
  331. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/connection.js +214 -0
  332. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/connection.js.map +1 -0
  333. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/errors.js +4 -0
  334. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/errors.js.map +1 -0
  335. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/rows.js +44 -0
  336. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/rows.js.map +1 -0
  337. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/schema.js +38 -0
  338. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/schema.js.map +1 -0
  339. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/store.js +284 -0
  340. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/store.js.map +1 -0
  341. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/verify.js +133 -0
  342. package/src/runtime/vendor/flywheel-cli-dist/local/store/sqlite/verify.js.map +1 -0
  343. package/src/runtime/vendor/flywheel-cli-dist/local/store/sync-commits.js +98 -0
  344. package/src/runtime/vendor/flywheel-cli-dist/local/store/sync-commits.js.map +1 -0
  345. package/src/runtime/vendor/flywheel-cli-dist/local/store/sync.js +161 -0
  346. package/src/runtime/vendor/flywheel-cli-dist/local/store/sync.js.map +1 -0
  347. package/src/runtime/vendor/flywheel-cli-dist/local/store/workspace-state.js +97 -0
  348. package/src/runtime/vendor/flywheel-cli-dist/local/store/workspace-state.js.map +1 -0
  349. package/src/runtime/vendor/flywheel-cli-dist/local/store/workspace.js +69 -0
  350. package/src/runtime/vendor/flywheel-cli-dist/local/store/workspace.js.map +1 -0
  351. package/src/runtime/vendor/flywheel-cli-dist/main.js +651 -376
  352. package/src/runtime/vendor/flywheel-cli-dist/main.js.map +1 -1
  353. package/src/runtime/vendor/flywheel-cli-dist/output/format.js +18 -11
  354. package/src/runtime/vendor/flywheel-cli-dist/output/format.js.map +1 -1
  355. package/src/runtime/vendor/flywheel-cli-dist/prebuilds/darwin-arm64/node.napi.node +0 -0
  356. package/src/runtime/vendor/flywheel-cli-dist/prebuilds/darwin-x64/node.napi.node +0 -0
  357. package/src/runtime/vendor/flywheel-cli-dist/prebuilds/linux-arm64/node.napi.glibc.node +0 -0
  358. package/src/runtime/vendor/flywheel-cli-dist/prebuilds/linux-arm64/node.napi.musl.node +0 -0
  359. package/src/runtime/vendor/flywheel-cli-dist/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  360. package/src/runtime/vendor/flywheel-cli-dist/prebuilds/linux-x64/node.napi.musl.node +0 -0
  361. package/src/runtime/vendor/manifest.json +252 -254
  362. package/src/setup/command.mjs +5 -0
  363. package/src/setup/io/patchers/json.mjs +1 -1
  364. package/src/setup/io/patchers/toml.mjs +3 -1
  365. package/src/setup/io/patchers/yaml.mjs +1 -1
  366. package/src/setup/modes/cli.mjs +76 -7
  367. package/src/setup/modes/mcp-command.mjs +802 -793
  368. package/src/setup/modes/mcp.mjs +7 -3
  369. package/src/setup/shared/prior-mode-detect.mjs +18 -21
  370. package/src/setup/test-seams.mjs +25 -0
  371. package/src/setup-auth.mjs +76 -10
  372. package/src/toml-lines.mjs +52 -0
  373. package/src/unified-cli.mjs +31 -16
  374. package/skills/flywheel-llm-proof-paper/scripts/__pycache__/check_paper.cpython-312.pyc +0 -0
  375. package/src/runtime/vendor/flywheel-cli-dist/auth/active-key-id.d.ts +0 -1
  376. package/src/runtime/vendor/flywheel-cli-dist/auth/baseurl.d.ts +0 -35
  377. package/src/runtime/vendor/flywheel-cli-dist/auth/config.d.ts +0 -34
  378. package/src/runtime/vendor/flywheel-cli-dist/auth/config.js +0 -92
  379. package/src/runtime/vendor/flywheel-cli-dist/auth/config.js.map +0 -1
  380. package/src/runtime/vendor/flywheel-cli-dist/auth/fingerprint.d.ts +0 -5
  381. package/src/runtime/vendor/flywheel-cli-dist/auth/keychain.d.ts +0 -4
  382. package/src/runtime/vendor/flywheel-cli-dist/auth/keychain.js +0 -31
  383. package/src/runtime/vendor/flywheel-cli-dist/auth/keychain.js.map +0 -1
  384. package/src/runtime/vendor/flywheel-cli-dist/auth/login.d.ts +0 -24
  385. package/src/runtime/vendor/flywheel-cli-dist/auth/profile.d.ts +0 -15
  386. package/src/runtime/vendor/flywheel-cli-dist/auth/profile.js +0 -150
  387. package/src/runtime/vendor/flywheel-cli-dist/auth/profile.js.map +0 -1
  388. package/src/runtime/vendor/flywheel-cli-dist/auth/profiles.d.ts +0 -27
  389. package/src/runtime/vendor/flywheel-cli-dist/commands/_admin-auth.d.ts +0 -27
  390. package/src/runtime/vendor/flywheel-cli-dist/commands/_artifacts-upload-helpers.d.ts +0 -32
  391. package/src/runtime/vendor/flywheel-cli-dist/commands/_artifacts-upload-helpers.js +0 -213
  392. package/src/runtime/vendor/flywheel-cli-dist/commands/_artifacts-upload-helpers.js.map +0 -1
  393. package/src/runtime/vendor/flywheel-cli-dist/commands/_browser-handoff.d.ts +0 -21
  394. package/src/runtime/vendor/flywheel-cli-dist/commands/_open-url.d.ts +0 -2
  395. package/src/runtime/vendor/flywheel-cli-dist/commands/_secret-param.d.ts +0 -7
  396. package/src/runtime/vendor/flywheel-cli-dist/commands/_stream-file-out.d.ts +0 -39
  397. package/src/runtime/vendor/flywheel-cli-dist/commands/_stream-writer.d.ts +0 -34
  398. package/src/runtime/vendor/flywheel-cli-dist/commands/_wait-polling.d.ts +0 -50
  399. package/src/runtime/vendor/flywheel-cli-dist/commands/account-detach.d.ts +0 -2
  400. package/src/runtime/vendor/flywheel-cli-dist/commands/account-emails-add.d.ts +0 -2
  401. package/src/runtime/vendor/flywheel-cli-dist/commands/account-emails-remove.d.ts +0 -2
  402. package/src/runtime/vendor/flywheel-cli-dist/commands/account-emails-set-primary.d.ts +0 -2
  403. package/src/runtime/vendor/flywheel-cli-dist/commands/account-get.d.ts +0 -2
  404. package/src/runtime/vendor/flywheel-cli-dist/commands/account-merge-preview.d.ts +0 -2
  405. package/src/runtime/vendor/flywheel-cli-dist/commands/account-merge-proof.d.ts +0 -2
  406. package/src/runtime/vendor/flywheel-cli-dist/commands/account-merge.d.ts +0 -2
  407. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-compute-policy-get.d.ts +0 -2
  408. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-compute-policy-set.d.ts +0 -2
  409. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-graphs-export-stream.d.ts +0 -2
  410. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-graphs-export.d.ts +0 -2
  411. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-graphs-list.d.ts +0 -4
  412. package/src/runtime/vendor/flywheel-cli-dist/commands/admin-nodes-audit-list.d.ts +0 -2
  413. package/src/runtime/vendor/flywheel-cli-dist/commands/aliases.d.ts +0 -13
  414. package/src/runtime/vendor/flywheel-cli-dist/commands/api-keys-create.d.ts +0 -2
  415. package/src/runtime/vendor/flywheel-cli-dist/commands/api-keys-delete.d.ts +0 -2
  416. package/src/runtime/vendor/flywheel-cli-dist/commands/api-keys-list.d.ts +0 -18
  417. package/src/runtime/vendor/flywheel-cli-dist/commands/api-keys-rotate.d.ts +0 -2
  418. package/src/runtime/vendor/flywheel-cli-dist/commands/approval-sessions-expire.d.ts +0 -2
  419. package/src/runtime/vendor/flywheel-cli-dist/commands/approval-sessions-heartbeat.d.ts +0 -2
  420. package/src/runtime/vendor/flywheel-cli-dist/commands/approval-sessions-list.d.ts +0 -2
  421. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-delete-bulk.d.ts +0 -2
  422. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-delete-bulk.js +0 -22
  423. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-delete-bulk.js.map +0 -1
  424. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-delete.d.ts +0 -2
  425. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-delete.js +0 -8
  426. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-delete.js.map +0 -1
  427. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-get.d.ts +0 -2
  428. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-list.d.ts +0 -2
  429. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-note-set.d.ts +0 -2
  430. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-note-set.js +0 -9
  431. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-note-set.js.map +0 -1
  432. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload-finalize.d.ts +0 -2
  433. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload-finalize.js +0 -7
  434. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload-finalize.js.map +0 -1
  435. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload-prepare.d.ts +0 -2
  436. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload-prepare.js +0 -15
  437. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload-prepare.js.map +0 -1
  438. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload.d.ts +0 -2
  439. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload.js +0 -5
  440. package/src/runtime/vendor/flywheel-cli-dist/commands/artifacts-upload.js.map +0 -1
  441. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-keychain-clear.d.ts +0 -2
  442. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-keychain-clear.js +0 -8
  443. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-keychain-clear.js.map +0 -1
  444. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-keychain-set.d.ts +0 -2
  445. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-keychain-set.js +0 -30
  446. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-keychain-set.js.map +0 -1
  447. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-login.d.ts +0 -2
  448. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-mode.d.ts +0 -4
  449. package/src/runtime/vendor/flywheel-cli-dist/commands/auth-status.d.ts +0 -2
  450. package/src/runtime/vendor/flywheel-cli-dist/commands/blobs-get.d.ts +0 -2
  451. package/src/runtime/vendor/flywheel-cli-dist/commands/campaign-budgets-create.d.ts +0 -2
  452. package/src/runtime/vendor/flywheel-cli-dist/commands/campaign-budgets-list.d.ts +0 -1
  453. package/src/runtime/vendor/flywheel-cli-dist/commands/campaign-budgets-revoke.d.ts +0 -1
  454. package/src/runtime/vendor/flywheel-cli-dist/commands/campaign-budgets-update.d.ts +0 -2
  455. package/src/runtime/vendor/flywheel-cli-dist/commands/campaign-snapshot.d.ts +0 -1
  456. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-acquire.d.ts +0 -2
  457. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-budgets.d.ts +0 -2
  458. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-connection.d.ts +0 -2
  459. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-funding.d.ts +0 -2
  460. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-grants-list.d.ts +0 -2
  461. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-grants-request-approval.d.ts +0 -2
  462. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-options.d.ts +0 -2
  463. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-release-all.d.ts +0 -2
  464. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-release.d.ts +0 -2
  465. package/src/runtime/vendor/flywheel-cli-dist/commands/compute-status.d.ts +0 -2
  466. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-balance.d.ts +0 -1
  467. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-billing-portal.d.ts +0 -2
  468. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-purchase.d.ts +0 -2
  469. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-referral-claim.d.ts +0 -2
  470. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-referral.d.ts +0 -1
  471. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-subscribe.d.ts +0 -2
  472. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-subscription.d.ts +0 -1
  473. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-transactions.d.ts +0 -2
  474. package/src/runtime/vendor/flywheel-cli-dist/commands/credits-usage.d.ts +0 -2
  475. package/src/runtime/vendor/flywheel-cli-dist/commands/destructive-confirmation.d.ts +0 -2
  476. package/src/runtime/vendor/flywheel-cli-dist/commands/enums.d.ts +0 -22
  477. package/src/runtime/vendor/flywheel-cli-dist/commands/env.d.ts +0 -8
  478. package/src/runtime/vendor/flywheel-cli-dist/commands/executions-launch.d.ts +0 -2
  479. package/src/runtime/vendor/flywheel-cli-dist/commands/executions-list.d.ts +0 -1
  480. package/src/runtime/vendor/flywheel-cli-dist/commands/executions-terminate.d.ts +0 -2
  481. package/src/runtime/vendor/flywheel-cli-dist/commands/export-history.d.ts +0 -2
  482. package/src/runtime/vendor/flywheel-cli-dist/commands/export-subgraph.d.ts +0 -2
  483. package/src/runtime/vendor/flywheel-cli-dist/commands/export-summary-pdf.d.ts +0 -2
  484. package/src/runtime/vendor/flywheel-cli-dist/commands/export-summary-render-pdf.d.ts +0 -2
  485. package/src/runtime/vendor/flywheel-cli-dist/commands/export-summary-stream.d.ts +0 -2
  486. package/src/runtime/vendor/flywheel-cli-dist/commands/export-summary.d.ts +0 -2
  487. package/src/runtime/vendor/flywheel-cli-dist/commands/feedback-create.d.ts +0 -2
  488. package/src/runtime/vendor/flywheel-cli-dist/commands/files-list.d.ts +0 -2
  489. package/src/runtime/vendor/flywheel-cli-dist/commands/github-disconnect.d.ts +0 -1
  490. package/src/runtime/vendor/flywheel-cli-dist/commands/github-link.d.ts +0 -2
  491. package/src/runtime/vendor/flywheel-cli-dist/commands/github-refresh-repos.d.ts +0 -1
  492. package/src/runtime/vendor/flywheel-cli-dist/commands/github-status.d.ts +0 -1
  493. package/src/runtime/vendor/flywheel-cli-dist/commands/graph-get.d.ts +0 -2
  494. package/src/runtime/vendor/flywheel-cli-dist/commands/handler-factory.d.ts +0 -22
  495. package/src/runtime/vendor/flywheel-cli-dist/commands/help-format.d.ts +0 -31
  496. package/src/runtime/vendor/flywheel-cli-dist/commands/help-metadata.d.ts +0 -36
  497. package/src/runtime/vendor/flywheel-cli-dist/commands/help.d.ts +0 -17
  498. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-create.d.ts +0 -2
  499. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-delete.d.ts +0 -1
  500. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-list.d.ts +0 -2
  501. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-runs-list.d.ts +0 -2
  502. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-secrets-create.d.ts +0 -2
  503. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-secrets-delete.d.ts +0 -1
  504. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-secrets-list.d.ts +0 -1
  505. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-secrets-update.d.ts +0 -2
  506. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-set-enabled.d.ts +0 -2
  507. package/src/runtime/vendor/flywheel-cli-dist/commands/hooks-update.d.ts +0 -2
  508. package/src/runtime/vendor/flywheel-cli-dist/commands/import-subgraph.d.ts +0 -2
  509. package/src/runtime/vendor/flywheel-cli-dist/commands/index.d.ts +0 -23
  510. package/src/runtime/vendor/flywheel-cli-dist/commands/integrations-huggingface-remove.d.ts +0 -1
  511. package/src/runtime/vendor/flywheel-cli-dist/commands/integrations-huggingface-set.d.ts +0 -2
  512. package/src/runtime/vendor/flywheel-cli-dist/commands/integrations-status.d.ts +0 -1
  513. package/src/runtime/vendor/flywheel-cli-dist/commands/integrations-wandb-remove.d.ts +0 -1
  514. package/src/runtime/vendor/flywheel-cli-dist/commands/integrations-wandb-set.d.ts +0 -2
  515. package/src/runtime/vendor/flywheel-cli-dist/commands/machines-list.d.ts +0 -1
  516. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-add-parent.d.ts +0 -2
  517. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-add-parent.js +0 -15
  518. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-add-parent.js.map +0 -1
  519. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-branch.d.ts +0 -2
  520. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-branch.js +0 -10
  521. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-branch.js.map +0 -1
  522. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-children.d.ts +0 -2
  523. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-children.js +0 -8
  524. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-children.js.map +0 -1
  525. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-commit-new.d.ts +0 -2
  526. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-commit-new.js +0 -6
  527. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-commit-new.js.map +0 -1
  528. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-commit.d.ts +0 -2
  529. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-commit.js +0 -7
  530. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-commit.js.map +0 -1
  531. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-create.d.ts +0 -2
  532. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-create.js +0 -6
  533. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-create.js.map +0 -1
  534. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-delete-bulk.d.ts +0 -2
  535. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-delete-bulk.js +0 -16
  536. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-delete-bulk.js.map +0 -1
  537. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-delete.d.ts +0 -2
  538. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-delete.js +0 -11
  539. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-delete.js.map +0 -1
  540. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-files.d.ts +0 -1
  541. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-get.d.ts +0 -2
  542. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-list.d.ts +0 -2
  543. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-merge.d.ts +0 -2
  544. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-merge.js +0 -33
  545. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-merge.js.map +0 -1
  546. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-parents.d.ts +0 -2
  547. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-parents.js +0 -8
  548. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-parents.js.map +0 -1
  549. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-remove-parent.d.ts +0 -2
  550. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-remove-parent.js +0 -15
  551. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-remove-parent.js.map +0 -1
  552. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-render-ancestry.d.ts +0 -2
  553. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-render-summary.d.ts +0 -2
  554. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-render-tree.d.ts +0 -2
  555. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-resolve-slug.d.ts +0 -2
  556. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-sharing-get.d.ts +0 -1
  557. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-sharing-set-bulk.d.ts +0 -2
  558. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-sharing-set.d.ts +0 -2
  559. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-sharing-summaries.d.ts +0 -2
  560. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-stage-lease-acquire.d.ts +0 -2
  561. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-stage-lease-heartbeat.d.ts +0 -2
  562. package/src/runtime/vendor/flywheel-cli-dist/commands/nodes-stage-lease-release.d.ts +0 -2
  563. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-list.d.ts +0 -2
  564. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-set.d.ts +0 -2
  565. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-show.d.ts +0 -2
  566. package/src/runtime/vendor/flywheel-cli-dist/commands/profile-unset.d.ts +0 -2
  567. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/account.d.ts +0 -2
  568. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/admin.d.ts +0 -8
  569. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/api-keys.d.ts +0 -2
  570. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/approval.d.ts +0 -2
  571. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/artifacts.d.ts +0 -2
  572. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/artifacts.js +0 -140
  573. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/artifacts.js.map +0 -1
  574. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/auth.d.ts +0 -2
  575. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/budgets.d.ts +0 -2
  576. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/compute.d.ts +0 -2
  577. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/credits.d.ts +0 -2
  578. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/env.d.ts +0 -2
  579. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/executions.d.ts +0 -2
  580. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/export.d.ts +0 -2
  581. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/github.d.ts +0 -2
  582. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/graph.d.ts +0 -2
  583. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/hooks.d.ts +0 -2
  584. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/integrations.d.ts +0 -2
  585. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/lifecycle.d.ts +0 -2
  586. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/profile.d.ts +0 -2
  587. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/resources.d.ts +0 -2
  588. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/sharing.d.ts +0 -2
  589. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/tagging.d.ts +0 -2
  590. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/tagging.js +0 -98
  591. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/tagging.js.map +0 -1
  592. package/src/runtime/vendor/flywheel-cli-dist/commands/registry/updates.d.ts +0 -2
  593. package/src/runtime/vendor/flywheel-cli-dist/commands/registry.d.ts +0 -27
  594. package/src/runtime/vendor/flywheel-cli-dist/commands/remote-artifacts-refresh.d.ts +0 -2
  595. package/src/runtime/vendor/flywheel-cli-dist/commands/remote-artifacts-resolve.d.ts +0 -2
  596. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-assign.d.ts +0 -2
  597. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-assign.js +0 -25
  598. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-assign.js.map +0 -1
  599. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-create.d.ts +0 -2
  600. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-create.js +0 -25
  601. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-create.js.map +0 -1
  602. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-delete.d.ts +0 -2
  603. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-delete.js +0 -11
  604. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-delete.js.map +0 -1
  605. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-update.d.ts +0 -2
  606. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-update.js +0 -28
  607. package/src/runtime/vendor/flywheel-cli-dist/commands/tags-update.js.map +0 -1
  608. package/src/runtime/vendor/flywheel-cli-dist/commands/types.d.ts +0 -30
  609. package/src/runtime/vendor/flywheel-cli-dist/commands/updates-hide-all-active.d.ts +0 -1
  610. package/src/runtime/vendor/flywheel-cli-dist/commands/updates-hide.d.ts +0 -2
  611. package/src/runtime/vendor/flywheel-cli-dist/commands/updates-list.d.ts +0 -2
  612. package/src/runtime/vendor/flywheel-cli-dist/commands/usage-spec.d.ts +0 -6
  613. package/src/runtime/vendor/flywheel-cli-dist/commands/utils.d.ts +0 -11
  614. package/src/runtime/vendor/flywheel-cli-dist/errors.d.ts +0 -86
  615. package/src/runtime/vendor/flywheel-cli-dist/exit-codes.d.ts +0 -8
  616. package/src/runtime/vendor/flywheel-cli-dist/generatedFeedbackContract.d.ts +0 -41
  617. package/src/runtime/vendor/flywheel-cli-dist/generatedProductTelemetryContract.d.ts +0 -13
  618. package/src/runtime/vendor/flywheel-cli-dist/grammar/globals.d.ts +0 -26
  619. package/src/runtime/vendor/flywheel-cli-dist/grammar/parse.d.ts +0 -17
  620. package/src/runtime/vendor/flywheel-cli-dist/http/client.d.ts +0 -91
  621. package/src/runtime/vendor/flywheel-cli-dist/http/debug.d.ts +0 -5
  622. package/src/runtime/vendor/flywheel-cli-dist/http/poll.d.ts +0 -18
  623. package/src/runtime/vendor/flywheel-cli-dist/http/retry.d.ts +0 -30
  624. package/src/runtime/vendor/flywheel-cli-dist/main.d.ts +0 -33
  625. package/src/runtime/vendor/flywheel-cli-dist/output/format.d.ts +0 -9
  626. package/src/runtime/vendor/flywheel-cli-dist/runtime-entry.d.ts +0 -1
  627. package/src/runtime/vendor/flywheel-cli-dist/version.d.ts +0 -3
  628. package/src/secure-write.mjs +0 -43
@@ -0,0 +1,278 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { existsSync, lstatSync, mkdirSync } from "node:fs";
3
+ import { DatabaseSync } from "node:sqlite";
4
+ import { basename, dirname, join, resolve } from "node:path";
5
+ import { close, fstat, fsync, listDirectory, mkdirAt, openDirectoryAt, renameExchangeAt, renameNoReplaceAt, renameReplaceAt, rmdirAt, statAt, unlinkAt, } from "../../fs/native.js";
6
+ import { replaceClientIdAtVersion, validateRepositoryAtVersion } from "../migration/steps.js";
7
+ import { reachableObjectDigestsIn } from "../gc.js";
8
+ import { RepositoryBackupError, extractArchive, verifyArchive } from "./archive.js";
9
+ import { RetainedPrivateDirectory } from "./retained-directory.js";
10
+ const DIRECTORY_TYPE = 0o040000;
11
+ const FILE_TYPE_MASK = 0o170000;
12
+ const PRIVATE_DIRECTORY_MODE = 0o700;
13
+ function restoreError(code, cause) {
14
+ return new RepositoryBackupError(code, cause === undefined ? undefined : { cause });
15
+ }
16
+ function sameIdentity(left, right) {
17
+ return left.dev === right.dev && left.ino === right.ino;
18
+ }
19
+ function isDirectory(stat) {
20
+ return (stat.mode & FILE_TYPE_MASK) === DIRECTORY_TYPE;
21
+ }
22
+ function relativePath(value, fallback) {
23
+ const path = value ?? fallback;
24
+ if (path.length === 0 || path.startsWith("/") || path.split("/").some(part => part === "." || part === ".." || part.length === 0)) {
25
+ throw restoreError("repository_restore_target_invalid");
26
+ }
27
+ return path;
28
+ }
29
+ function targetIdentity(parentFd, targetName) {
30
+ try {
31
+ const entry = statAt(parentFd, targetName);
32
+ if (!isDirectory(entry))
33
+ throw restoreError("repository_restore_target_invalid");
34
+ let targetFd = -1;
35
+ try {
36
+ targetFd = openDirectoryAt(parentFd, targetName);
37
+ if (!sameIdentity(fstat(targetFd), entry) || listDirectory(targetFd).length !== 0) {
38
+ throw restoreError("repository_restore_target_not_empty");
39
+ }
40
+ return entry;
41
+ }
42
+ finally {
43
+ if (targetFd >= 0)
44
+ close(targetFd);
45
+ }
46
+ }
47
+ catch (error) {
48
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
49
+ return undefined;
50
+ throw error;
51
+ }
52
+ }
53
+ function sameManifestObjects(manifest, digests) {
54
+ return JSON.stringify(manifest.objects.map(entry => entry.digest).sort()) === JSON.stringify([...digests].sort());
55
+ }
56
+ function reachableObjectDigests(databasePath, repositoryId) {
57
+ let database;
58
+ try {
59
+ database = new DatabaseSync(databasePath, { allowExtension: false, defensive: true, readOnly: true });
60
+ return reachableObjectDigestsIn(database, repositoryId).map(digest => digest.slice("sha256:".length));
61
+ }
62
+ catch (error) {
63
+ throw restoreError("repository_restore_database_invalid", error);
64
+ }
65
+ finally {
66
+ database?.close();
67
+ }
68
+ }
69
+ function validateExtractedDatabase(path, manifest) {
70
+ try {
71
+ validateRepositoryAtVersion(path, manifest.repositoryId, manifest.repositoryUserVersion);
72
+ if (!sameManifestObjects(manifest, reachableObjectDigests(path, manifest.repositoryId))) {
73
+ throw restoreError("repository_restore_database_invalid");
74
+ }
75
+ }
76
+ catch (error) {
77
+ if (error instanceof RepositoryBackupError)
78
+ throw error;
79
+ throw restoreError("repository_restore_database_invalid", error);
80
+ }
81
+ }
82
+ function openDirectoryAtOrCreate(parentFd, name) {
83
+ try {
84
+ mkdirAt(parentFd, name, PRIVATE_DIRECTORY_MODE);
85
+ }
86
+ catch (error) {
87
+ if (!(typeof error === "object" && error !== null && "code" in error && error.code === "EEXIST"))
88
+ throw error;
89
+ }
90
+ const directory = openDirectoryAt(parentFd, name);
91
+ if (!isDirectory(fstat(directory))) {
92
+ close(directory);
93
+ throw restoreError("repository_restore_target_invalid");
94
+ }
95
+ return directory;
96
+ }
97
+ function moveIntoLayout(staging, sourceName, destination) {
98
+ const parts = destination.split("/");
99
+ if (parts.length === 1 && parts[0] === sourceName)
100
+ return;
101
+ const directories = [];
102
+ let parentFd = staging.fd;
103
+ try {
104
+ for (const name of parts.slice(0, -1)) {
105
+ parentFd = openDirectoryAtOrCreate(parentFd, name);
106
+ directories.push(parentFd);
107
+ }
108
+ renameReplaceAt(staging.fd, sourceName, parentFd, parts.at(-1));
109
+ for (let index = directories.length - 1; index >= 0; index -= 1)
110
+ fsync(directories[index]);
111
+ }
112
+ finally {
113
+ for (let index = directories.length - 1; index >= 0; index -= 1)
114
+ close(directories[index]);
115
+ }
116
+ }
117
+ function closeDirectory(fd) {
118
+ if (fd >= 0)
119
+ close(fd);
120
+ }
121
+ /** Restores a verified archive without acquiring the outer bootstrap or writer lock. */
122
+ export async function restoreRepositoryArchive(archivePath, targetPath, options = {}) {
123
+ const archive = resolve(archivePath);
124
+ const target = resolve(targetPath);
125
+ const databaseRelativePath = relativePath(options.databaseRelativePath, "db.sqlite");
126
+ const objectsRelativePath = relativePath(options.objectsRelativePath, "objects");
127
+ if (!existsSync(archive) || lstatSync(archive).isSymbolicLink())
128
+ throw restoreError("repository_restore_archive_invalid");
129
+ if (existsSync(target) && (!lstatSync(target).isDirectory() || lstatSync(target).isSymbolicLink())) {
130
+ throw restoreError("repository_restore_target_invalid");
131
+ }
132
+ try {
133
+ mkdirSync(dirname(target), { recursive: true, mode: PRIVATE_DIRECTORY_MODE });
134
+ if (lstatSync(dirname(target)).isSymbolicLink())
135
+ throw restoreError("repository_restore_target_invalid");
136
+ }
137
+ catch (error) {
138
+ if (error instanceof RepositoryBackupError)
139
+ throw error;
140
+ throw restoreError("repository_restore_target_invalid", error);
141
+ }
142
+ const manifest = await verifyArchive(archive);
143
+ if (options.expectedRepositoryId !== undefined && manifest.repositoryId !== options.expectedRepositoryId) {
144
+ throw restoreError("repository_restore_repository_mismatch");
145
+ }
146
+ const staging = RetainedPrivateDirectory.create(dirname(target), ".flywheel-restore-");
147
+ try {
148
+ const targetName = basename(target);
149
+ const previousTarget = targetIdentity(staging.parentFd, targetName);
150
+ await extractArchive(archive, staging.path, manifest);
151
+ const databasePath = join(staging.path, "db.sqlite");
152
+ validateExtractedDatabase(databasePath, manifest);
153
+ const clientId = randomUUID();
154
+ replaceClientIdAtVersion(databasePath, manifest.repositoryId, clientId, manifest.repositoryUserVersion);
155
+ moveIntoLayout(staging, "db.sqlite", databaseRelativePath);
156
+ moveIntoLayout(staging, "objects", objectsRelativePath);
157
+ await options.prepareExtractedRepository?.(staging.path);
158
+ fsync(staging.fd);
159
+ staging.assertCurrent("repository_restore_staging_replaced");
160
+ const current = targetIdentity(staging.parentFd, targetName);
161
+ if (current === undefined && previousTarget !== undefined || current !== undefined && previousTarget === undefined ||
162
+ current !== undefined && previousTarget !== undefined && !sameIdentity(current, previousTarget)) {
163
+ throw restoreError("repository_restore_target_replaced");
164
+ }
165
+ if (previousTarget === undefined) {
166
+ renameNoReplaceAt(staging.parentFd, staging.name, staging.parentFd, targetName);
167
+ }
168
+ else {
169
+ renameExchangeAt(staging.parentFd, staging.name, staging.parentFd, targetName);
170
+ const oldTarget = statAt(staging.parentFd, staging.name);
171
+ if (!sameIdentity(oldTarget, previousTarget))
172
+ throw restoreError("repository_restore_target_replaced");
173
+ try {
174
+ rmdirAt(staging.parentFd, staging.name);
175
+ }
176
+ catch (error) {
177
+ try {
178
+ if (!sameIdentity(statAt(staging.parentFd, staging.name), previousTarget))
179
+ throw restoreError("repository_restore_target_replaced");
180
+ renameExchangeAt(staging.parentFd, staging.name, staging.parentFd, targetName);
181
+ if (!sameIdentity(statAt(staging.parentFd, targetName), previousTarget))
182
+ throw restoreError("repository_restore_rollback_failed");
183
+ if (!sameIdentity(statAt(staging.parentFd, staging.name), fstat(staging.fd)))
184
+ throw restoreError("repository_restore_rollback_failed");
185
+ }
186
+ catch (rollbackError) {
187
+ throw restoreError("repository_restore_rollback_failed", rollbackError);
188
+ }
189
+ if (typeof error === "object" && error !== null && "code" in error && (error.code === "EEXIST" || error.code === "ENOTEMPTY")) {
190
+ throw restoreError("repository_restore_target_not_empty", error);
191
+ }
192
+ throw restoreError("repository_restore_activation_failed", error);
193
+ }
194
+ }
195
+ fsync(staging.parentFd);
196
+ staging.assertParentCurrent("repository_restore_target_parent_replaced");
197
+ staging.transfer();
198
+ return { path: target, repositoryId: manifest.repositoryId, clientId };
199
+ }
200
+ finally {
201
+ staging.finish();
202
+ }
203
+ }
204
+ export async function restoreRepositoryForMigration(archivePath, state, options) {
205
+ const manifest = await verifyArchive(archivePath);
206
+ if (manifest.repositoryId !== options.expectedRepositoryId)
207
+ throw restoreError("repository_restore_repository_mismatch");
208
+ const staging = RetainedPrivateDirectory.create(state.statePath, ".flywheel-migration-restore-");
209
+ try {
210
+ await extractArchive(archivePath, staging.path, manifest);
211
+ staging.assertCurrent("repository_restore_staging_replaced");
212
+ options.validateSnapshot(join(staging.path, "db.sqlite"), options.expectedRepositoryId);
213
+ state.assertValid();
214
+ for (const suffix of ["-wal", "-shm"]) {
215
+ try {
216
+ unlinkAt(state.stateFd, `db.sqlite${suffix}`);
217
+ }
218
+ catch (error) {
219
+ if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT"))
220
+ throw error;
221
+ }
222
+ }
223
+ let rollbackFd = -1;
224
+ let movedDatabase = false;
225
+ let movedObjects = false;
226
+ let installedDatabase = false;
227
+ let installedObjects = false;
228
+ try {
229
+ mkdirAt(staging.fd, "rollback", PRIVATE_DIRECTORY_MODE);
230
+ rollbackFd = openDirectoryAt(staging.fd, "rollback");
231
+ renameReplaceAt(state.stateFd, "db.sqlite", rollbackFd, "db.sqlite");
232
+ movedDatabase = true;
233
+ try {
234
+ renameReplaceAt(state.stateFd, "objects", rollbackFd, "objects");
235
+ movedObjects = true;
236
+ }
237
+ catch (error) {
238
+ if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT"))
239
+ throw error;
240
+ }
241
+ renameReplaceAt(staging.fd, "db.sqlite", state.stateFd, "db.sqlite");
242
+ installedDatabase = true;
243
+ renameReplaceAt(staging.fd, "objects", state.stateFd, "objects");
244
+ installedObjects = true;
245
+ fsync(state.stateFd);
246
+ options.validateSnapshot(join(state.statePath, "db.sqlite"), options.expectedRepositoryId);
247
+ state.assertValid();
248
+ }
249
+ catch (error) {
250
+ try {
251
+ if (installedObjects)
252
+ renameReplaceAt(state.stateFd, "objects", staging.fd, "failed-objects");
253
+ if (installedDatabase)
254
+ renameReplaceAt(state.stateFd, "db.sqlite", staging.fd, "failed-db.sqlite");
255
+ if (movedDatabase)
256
+ renameReplaceAt(rollbackFd, "db.sqlite", state.stateFd, "db.sqlite");
257
+ if (movedObjects)
258
+ renameReplaceAt(rollbackFd, "objects", state.stateFd, "objects");
259
+ if (movedDatabase)
260
+ fsync(state.stateFd);
261
+ if (movedDatabase)
262
+ options.validateSnapshot(join(state.statePath, "db.sqlite"), options.expectedRepositoryId);
263
+ state.assertValid();
264
+ }
265
+ catch (rollbackError) {
266
+ throw restoreError("repository_restore_rollback_failed", rollbackError);
267
+ }
268
+ throw restoreError("repository_restore_activation_failed", error);
269
+ }
270
+ finally {
271
+ closeDirectory(rollbackFd);
272
+ }
273
+ }
274
+ finally {
275
+ staging.finish();
276
+ }
277
+ }
278
+ //# sourceMappingURL=restore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restore.js","sourceRoot":"","sources":["../../../../src/local/store/backup/restore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,aAAa,EACb,OAAO,EACP,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,OAAO,EACP,MAAM,EACN,QAAQ,GAET,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,aAAa,EAAiC,MAAM,cAAc,CAAC;AACnH,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,cAAc,GAAG,QAAQ,CAAC;AAChC,MAAM,cAAc,GAAG,QAAQ,CAAC;AAChC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAcrC,SAAS,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e,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gBACnF,IAAI,aAAa;oBAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACxC,IAAI,aAAa;oBAAE,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;gBAC9G,KAAK,CAAC,WAAW,EAAE,CAAC;YACtB,CAAC;YAAC,OAAO,aAAa,EAAE,CAAC;gBACvB,MAAM,YAAY,CAAC,oCAAoC,EAAE,aAAa,CAAC,CAAC;YAC1E,CAAC;YACD,MAAM,YAAY,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QACpE,CAAC;gBAAS,CAAC;YACT,cAAc,CAAC,UAAU,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,MAAM,EAAE,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,192 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { basename, resolve } from "node:path";
3
+ import { close, fstat, fsync, listDirectory, mkdirAt, openDirectory, openDirectoryAt, rmdirAt, statAt, unlinkAt, } from "../../fs/native.js";
4
+ import { RepositoryBackupError } from "./archive.js";
5
+ const DIRECTORY_TYPE = 0o040000;
6
+ const FILE_TYPE_MASK = 0o170000;
7
+ const PRIVATE_DIRECTORY_MODE = 0o700;
8
+ function sameIdentity(left, right) {
9
+ return left.dev === right.dev && left.ino === right.ino;
10
+ }
11
+ function isDirectory(stat) {
12
+ return (stat.mode & FILE_TYPE_MASK) === DIRECTORY_TYPE;
13
+ }
14
+ function backupError(code, cause) {
15
+ return new RepositoryBackupError(code, cause === undefined ? undefined : { cause });
16
+ }
17
+ /** A private directory pinned to the parent and child directory entries that created it. */
18
+ export class RetainedPrivateDirectory {
19
+ parentPath;
20
+ path;
21
+ parentFd;
22
+ fd;
23
+ name;
24
+ #parentIdentity;
25
+ #identity;
26
+ #transferred = false;
27
+ constructor(parentPath, parentFd, name, fd) {
28
+ this.parentPath = parentPath;
29
+ this.parentFd = parentFd;
30
+ this.name = name;
31
+ this.fd = fd;
32
+ this.path = `${parentPath}/${name}`;
33
+ this.#parentIdentity = fstat(parentFd);
34
+ this.#identity = fstat(fd);
35
+ this.assertCurrent("repository_backup_staging_replaced");
36
+ }
37
+ static create(parentPath, prefix) {
38
+ const absoluteParent = resolve(parentPath);
39
+ let parentFd = -1;
40
+ let directoryFd = -1;
41
+ try {
42
+ parentFd = openDirectory(absoluteParent);
43
+ for (let attempt = 0; attempt < 16; attempt += 1) {
44
+ const name = `${prefix}${randomUUID().replaceAll("-", "")}`;
45
+ try {
46
+ mkdirAt(parentFd, name, PRIVATE_DIRECTORY_MODE);
47
+ }
48
+ catch (error) {
49
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "EEXIST")
50
+ continue;
51
+ throw error;
52
+ }
53
+ try {
54
+ directoryFd = openDirectoryAt(parentFd, name);
55
+ return new RetainedPrivateDirectory(absoluteParent, parentFd, name, directoryFd);
56
+ }
57
+ catch (error) {
58
+ if (directoryFd >= 0)
59
+ close(directoryFd);
60
+ directoryFd = -1;
61
+ try {
62
+ rmdirAt(parentFd, name);
63
+ }
64
+ catch {
65
+ // The original retained-directory failure is more useful to callers.
66
+ }
67
+ throw error;
68
+ }
69
+ }
70
+ throw backupError("repository_backup_staging_name_collision");
71
+ }
72
+ catch (error) {
73
+ if (directoryFd >= 0)
74
+ close(directoryFd);
75
+ if (parentFd >= 0)
76
+ close(parentFd);
77
+ if (error instanceof RepositoryBackupError)
78
+ throw error;
79
+ throw backupError("repository_backup_location_unsupported", error);
80
+ }
81
+ }
82
+ assertCurrent(errorCode) {
83
+ try {
84
+ this.assertParentCurrent(errorCode);
85
+ this.#assertRetainedIdentity(errorCode);
86
+ }
87
+ catch (error) {
88
+ if (error instanceof RepositoryBackupError)
89
+ throw error;
90
+ throw backupError(errorCode, error);
91
+ }
92
+ }
93
+ #assertRetainedIdentity(errorCode) {
94
+ const entry = statAt(this.parentFd, this.name);
95
+ const opened = fstat(this.fd);
96
+ if (!sameIdentity(fstat(this.parentFd), this.#parentIdentity) ||
97
+ !isDirectory(entry) || !sameIdentity(entry, this.#identity) ||
98
+ !isDirectory(opened) || !sameIdentity(opened, this.#identity)) {
99
+ throw backupError(errorCode);
100
+ }
101
+ }
102
+ assertParentCurrent(errorCode) {
103
+ let currentParentFd = -1;
104
+ try {
105
+ currentParentFd = openDirectory(this.parentPath);
106
+ const current = fstat(currentParentFd);
107
+ if (!isDirectory(current) || !sameIdentity(current, this.#parentIdentity) ||
108
+ !sameIdentity(fstat(this.parentFd), this.#parentIdentity)) {
109
+ throw backupError(errorCode);
110
+ }
111
+ }
112
+ catch (error) {
113
+ if (error instanceof RepositoryBackupError)
114
+ throw error;
115
+ throw backupError(errorCode, error);
116
+ }
117
+ finally {
118
+ if (currentParentFd >= 0)
119
+ close(currentParentFd);
120
+ }
121
+ }
122
+ transfer() {
123
+ this.#transferred = true;
124
+ }
125
+ #removeContents(directoryFd) {
126
+ for (const name of listDirectory(directoryFd)) {
127
+ this.#assertRetainedIdentity("repository_backup_staging_replaced");
128
+ const entry = statAt(directoryFd, name);
129
+ if (!isDirectory(entry)) {
130
+ unlinkAt(directoryFd, name);
131
+ continue;
132
+ }
133
+ const childFd = openDirectoryAt(directoryFd, name);
134
+ try {
135
+ if (!sameIdentity(entry, fstat(childFd)))
136
+ throw backupError("repository_backup_staging_replaced");
137
+ this.#removeContents(childFd);
138
+ if (!sameIdentity(entry, statAt(directoryFd, name)))
139
+ throw backupError("repository_backup_staging_replaced");
140
+ rmdirAt(directoryFd, name);
141
+ }
142
+ finally {
143
+ close(childFd);
144
+ }
145
+ }
146
+ }
147
+ finish() {
148
+ let failure;
149
+ if (!this.#transferred) {
150
+ try {
151
+ this.assertParentCurrent("repository_backup_location_replaced");
152
+ }
153
+ catch (error) {
154
+ failure = error;
155
+ }
156
+ try {
157
+ this.#assertRetainedIdentity("repository_backup_staging_replaced");
158
+ this.#removeContents(this.fd);
159
+ this.#assertRetainedIdentity("repository_backup_staging_replaced");
160
+ rmdirAt(this.parentFd, this.name);
161
+ fsync(this.parentFd);
162
+ this.assertParentCurrent("repository_backup_location_replaced");
163
+ }
164
+ catch (error) {
165
+ if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")) {
166
+ failure ??= error;
167
+ }
168
+ }
169
+ }
170
+ try {
171
+ close(this.fd);
172
+ }
173
+ catch (error) {
174
+ failure ??= error;
175
+ }
176
+ try {
177
+ close(this.parentFd);
178
+ }
179
+ catch (error) {
180
+ failure ??= error;
181
+ }
182
+ if (failure !== undefined)
183
+ throw failure;
184
+ }
185
+ }
186
+ export function destinationName(path) {
187
+ const name = basename(path);
188
+ if (name.length === 0 || name === "." || name === "..")
189
+ throw backupError("repository_backup_location_unsupported");
190
+ return name;
191
+ }
192
+ //# sourceMappingURL=retained-directory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retained-directory.js","sourceRoot":"","sources":["../../../../src/local/store/backup/retained-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,aAAa,EACb,OAAO,EACP,aAAa,EACb,eAAe,EACf,OAAO,EACP,MAAM,EAEN,QAAQ,GACT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,cAAc,GAAG,QAAQ,CAAC;AAChC,MAAM,cAAc,GAAG,QAAQ,CAAC;AAChC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAErC,SAAS,YAAY,CAAC,IAAoB,EAAE,KAAqB;IAC/D,OAAO,IAAI,CAAC,GAAG,KAAK,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ACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,KAAK,CAAC;QACpB,CAAC;QACD,IAAI,CAAC;YACH,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,KAAK,CAAC;QACpB,CAAC;QACD,IAAI,OAAO,KAAK,SAAS;YAAE,MAAM,OAAO,CAAC;IAC3C,CAAC;CACF;AAED,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI;QAAE,MAAM,WAAW,CAAC,wCAAwC,CAAC,CAAC;IACpH,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,114 @@
1
+ import { RepositoryCommit } from "../domain/models/commits.js";
2
+ import { isDigest } from "../domain/models/constants.js";
3
+ import { canonicalBytes, parseRepositoryJson } from "../domain/models/encoding.js";
4
+ import { RepositoryContractError } from "../domain/errors.js";
5
+ import { LatestValueWrite } from "./contract.js";
6
+ import { RepositoryStoreError } from "./sqlite/errors.js";
7
+ import { getRow, runSql } from "./sqlite/rows.js";
8
+ export function workspaceHeadIn(database, repositoryId) {
9
+ const row = getRow(database.prepare("SELECT workspace_head_commit_id FROM repository_heads WHERE repository_id = ?"), repositoryId);
10
+ if (row === undefined || row.workspace_head_commit_id === null)
11
+ return null;
12
+ if (!isDigest(row.workspace_head_commit_id))
13
+ throw new RepositoryStoreError("repository workspace is corrupt");
14
+ return row.workspace_head_commit_id;
15
+ }
16
+ function storedCommit(commitId, raw) {
17
+ if (!isDigest(commitId) || !(raw instanceof Uint8Array))
18
+ throw new RepositoryStoreError("stored commit is corrupt");
19
+ try {
20
+ return RepositoryCommit.fromCanonicalBytes(commitId, raw);
21
+ }
22
+ catch (error) {
23
+ if (!(error instanceof RepositoryContractError))
24
+ throw error;
25
+ throw new RepositoryStoreError("stored commit is corrupt", { cause: error });
26
+ }
27
+ }
28
+ export function loadCommitByOperationId(database, repositoryId, operationId) {
29
+ const row = getRow(database.prepare("SELECT commits.commit_id, commits.canonical_bytes FROM repository_operations AS operations " +
30
+ "JOIN repository_commits AS commits ON commits.repository_id = operations.repository_id " +
31
+ "AND commits.commit_id = operations.commit_id WHERE operations.repository_id = ? AND operations.operation_id = ?"), repositoryId, operationId);
32
+ if (row === undefined)
33
+ return null;
34
+ const commit = storedCommit(row.commit_id, row.canonical_bytes);
35
+ if (commit.repositoryId !== repositoryId || !commit.operations.some(operation => operation.operationId === operationId)) {
36
+ throw new RepositoryStoreError("stored operation identity is corrupt");
37
+ }
38
+ return commit;
39
+ }
40
+ export function listCommitsIn(database, repositoryId, atHead, afterCommitId, limit) {
41
+ if (!Number.isInteger(limit) || limit < 1 || limit > 256)
42
+ throw new RepositoryStoreError("commit page limit is unsafe");
43
+ if (afterCommitId !== null && !isDigest(afterCommitId))
44
+ throw new RepositoryStoreError("commit continuation is invalid");
45
+ if (atHead !== workspaceHeadIn(database, repositoryId))
46
+ throw new RepositoryStoreError("repository snapshot changed");
47
+ let current = atHead;
48
+ let afterReached = afterCommitId === null;
49
+ const seen = new Set();
50
+ const commits = [];
51
+ while (current !== null) {
52
+ if (seen.has(current))
53
+ throw new RepositoryStoreError("stored commit history is cyclic");
54
+ seen.add(current);
55
+ const row = getRow(database.prepare("SELECT canonical_bytes FROM repository_commits WHERE repository_id = ? AND commit_id = ?"), repositoryId, current);
56
+ if (row === undefined)
57
+ throw new RepositoryStoreError("stored commit parent is missing or cross-repository");
58
+ const commit = storedCommit(current, row.canonical_bytes);
59
+ if (commit.repositoryId !== repositoryId)
60
+ throw new RepositoryStoreError("stored commit is cross-repository");
61
+ if (afterReached) {
62
+ if (commits.length === limit)
63
+ return { commits, nextCommitId: commits[commits.length - 1].commitId };
64
+ commits.push(commit);
65
+ }
66
+ else if (commit.commitId === afterCommitId)
67
+ afterReached = true;
68
+ current = commit.parentCommitId;
69
+ }
70
+ if (!afterReached)
71
+ throw new RepositoryStoreError("commit continuation is outside reachable history");
72
+ return { commits, nextCommitId: null };
73
+ }
74
+ export function commitLatestValues(raw) {
75
+ try {
76
+ if (!(raw instanceof Uint8Array))
77
+ throw new TypeError("latest-value group must be bytes");
78
+ const decoded = parseRepositoryJson(new TextDecoder("utf-8", { fatal: true }).decode(raw));
79
+ if (!Array.isArray(decoded))
80
+ throw new TypeError("latest-value group must be an array");
81
+ const writes = decoded.map(LatestValueWrite.fromMapping);
82
+ if (!canonicalBytes(decoded).equals(raw))
83
+ throw new Error("latest-value group must be canonical");
84
+ return writes;
85
+ }
86
+ catch (error) {
87
+ // The persisted group is an external boundary; reject invalid UTF-8, JSON, fields, or digests together.
88
+ throw new RepositoryStoreError("repository commit latest values are corrupt", { cause: error });
89
+ }
90
+ }
91
+ export function canonicalLatestGroup(rawWrites) {
92
+ try {
93
+ return canonicalBytes(rawWrites.map(raw => LatestValueWrite.fromCanonicalBytes(raw).toMapping()));
94
+ }
95
+ catch (error) {
96
+ throw new RepositoryStoreError("repository sync latest values are invalid", { cause: error });
97
+ }
98
+ }
99
+ export function persistCommit(database, commit, latestValueWrites, receivedAt) {
100
+ runSql(database.prepare(`
101
+ INSERT INTO repository_commits (
102
+ repository_id, commit_id, canonical_bytes, latest_values_bytes, committed_at
103
+ ) VALUES (?, ?, ?, ?, ?)
104
+ `), commit.repositoryId, commit.commitId, commit.canonicalBytes, canonicalLatestGroup(latestValueWrites), receivedAt);
105
+ if (commit.parentCommitId !== null) {
106
+ runSql(database.prepare("INSERT INTO repository_commit_parents VALUES (?, ?, ?, 0)"), commit.repositoryId, commit.commitId, commit.parentCommitId);
107
+ }
108
+ for (const [position, operation] of commit.operations.entries()) {
109
+ if (operation.repositoryId !== commit.repositoryId)
110
+ throw new RepositoryStoreError("cross-repository operation");
111
+ runSql(database.prepare("INSERT INTO repository_operations VALUES (?, ?, ?, ?, ?)"), commit.repositoryId, commit.commitId, operation.operationId, position, operation.canonicalBytes);
112
+ }
113
+ }
114
+ //# sourceMappingURL=commits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commits.js","sourceRoot":"","sources":["../../../src/local/store/commits.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAmB,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,UAAU,eAAe,CAAC,QAAsB,EAAE,YAAoB;IAC1E,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,+EAA+E,CAAC,EAAE,YAAY,CAAC,CAAC;IACpI,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,wBAAwB,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC5E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,wBAAwB,CAAC;QAAE,MAAM,IAAI,oBAAoB,CAAC,iCAAiC,CAAC,CAAC;IAC/G,OAAO,GAAG,CAAC,wBAAwB,CAAC;AACtC,CAAC;AAED,SAAS,YAAY,CAAC,QAAiB,EAAE,GAAY;IACnD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,YAAY,UAAU,CAAC;QAAE,MAAM,IAAI,oBAAoB,CAAC,0BAA0B,CAAC,CAAC;IACpH,IAAI,CAAC;QACH,OAAO,gBAAgB,CAAC,kB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