wicked-crew 0.18.19 → 0.18.21

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 (700) hide show
  1. package/README.md +9 -6
  2. package/dist/api/ask-paths.d.ts +2 -0
  3. package/dist/api/ask-paths.d.ts.map +1 -1
  4. package/dist/api/ask-paths.js +6 -0
  5. package/dist/api/ask-paths.js.map +1 -1
  6. package/dist/api/auth.d.ts +7 -5
  7. package/dist/api/auth.d.ts.map +1 -1
  8. package/dist/api/auth.js +23 -9
  9. package/dist/api/auth.js.map +1 -1
  10. package/dist/api/capture.d.ts +5 -2
  11. package/dist/api/capture.d.ts.map +1 -1
  12. package/dist/api/capture.js +13 -10
  13. package/dist/api/capture.js.map +1 -1
  14. package/dist/api/chat-attachments.d.ts.map +1 -1
  15. package/dist/api/chat-attachments.js +69 -19
  16. package/dist/api/chat-attachments.js.map +1 -1
  17. package/dist/api/chat-citations.d.ts.map +1 -1
  18. package/dist/api/chat-citations.js +22 -0
  19. package/dist/api/chat-citations.js.map +1 -1
  20. package/dist/api/chat-context.d.ts +16 -1
  21. package/dist/api/chat-context.d.ts.map +1 -1
  22. package/dist/api/chat-context.js +75 -14
  23. package/dist/api/chat-context.js.map +1 -1
  24. package/dist/api/chat-freshness.js +2 -2
  25. package/dist/api/chat-freshness.js.map +1 -1
  26. package/dist/api/chat-history.d.ts +13 -0
  27. package/dist/api/chat-history.d.ts.map +1 -1
  28. package/dist/api/chat-history.js +25 -0
  29. package/dist/api/chat-history.js.map +1 -1
  30. package/dist/api/chat-jobs.d.ts +67 -6
  31. package/dist/api/chat-jobs.d.ts.map +1 -1
  32. package/dist/api/chat-jobs.js +243 -22
  33. package/dist/api/chat-jobs.js.map +1 -1
  34. package/dist/api/chat-proposals.d.ts +69 -6
  35. package/dist/api/chat-proposals.d.ts.map +1 -1
  36. package/dist/api/chat-proposals.js +310 -49
  37. package/dist/api/chat-proposals.js.map +1 -1
  38. package/dist/api/chat-requirements.d.ts.map +1 -1
  39. package/dist/api/chat-requirements.js +4 -1
  40. package/dist/api/chat-requirements.js.map +1 -1
  41. package/dist/api/chat-scope.d.ts +17 -9
  42. package/dist/api/chat-scope.d.ts.map +1 -1
  43. package/dist/api/chat-scope.js +55 -21
  44. package/dist/api/chat-scope.js.map +1 -1
  45. package/dist/api/cluster-status.d.ts +24 -12
  46. package/dist/api/cluster-status.d.ts.map +1 -1
  47. package/dist/api/cluster-status.js +82 -4
  48. package/dist/api/cluster-status.js.map +1 -1
  49. package/dist/api/codebase-archive.d.ts +4 -3
  50. package/dist/api/codebase-archive.d.ts.map +1 -1
  51. package/dist/api/codebase-archive.js +6 -5
  52. package/dist/api/codebase-archive.js.map +1 -1
  53. package/dist/api/delivery-cache.d.ts +2 -0
  54. package/dist/api/delivery-cache.d.ts.map +1 -1
  55. package/dist/api/delivery-cache.js +1 -2
  56. package/dist/api/delivery-cache.js.map +1 -1
  57. package/dist/api/delivery-index.d.ts +2 -2
  58. package/dist/api/delivery-index.d.ts.map +1 -1
  59. package/dist/api/delivery-index.js +1 -2
  60. package/dist/api/delivery-index.js.map +1 -1
  61. package/dist/api/eval-compare.d.ts +1 -1
  62. package/dist/api/eval-compare.js +1 -1
  63. package/dist/api/eval-sample.d.ts +7 -0
  64. package/dist/api/eval-sample.d.ts.map +1 -1
  65. package/dist/api/eval-sample.js +20 -0
  66. package/dist/api/eval-sample.js.map +1 -1
  67. package/dist/api/gate-cache.d.ts +1 -0
  68. package/dist/api/gate-cache.d.ts.map +1 -1
  69. package/dist/api/gate-cache.js +19 -6
  70. package/dist/api/gate-cache.js.map +1 -1
  71. package/dist/api/governance-steering.d.ts +17 -4
  72. package/dist/api/governance-steering.d.ts.map +1 -1
  73. package/dist/api/governance-steering.js +56 -7
  74. package/dist/api/governance-steering.js.map +1 -1
  75. package/dist/api/mcp.d.ts +12 -2
  76. package/dist/api/mcp.d.ts.map +1 -1
  77. package/dist/api/mcp.js +56 -12
  78. package/dist/api/mcp.js.map +1 -1
  79. package/dist/api/needs.d.ts +20 -0
  80. package/dist/api/needs.d.ts.map +1 -1
  81. package/dist/api/needs.js +120 -19
  82. package/dist/api/needs.js.map +1 -1
  83. package/dist/api/onboarding-capture.d.ts +21 -1
  84. package/dist/api/onboarding-capture.d.ts.map +1 -1
  85. package/dist/api/onboarding-capture.js +112 -8
  86. package/dist/api/onboarding-capture.js.map +1 -1
  87. package/dist/api/policy-landing.d.ts +36 -0
  88. package/dist/api/policy-landing.d.ts.map +1 -1
  89. package/dist/api/policy-landing.js +123 -4
  90. package/dist/api/policy-landing.js.map +1 -1
  91. package/dist/api/post-hoc-deliver.d.ts.map +1 -1
  92. package/dist/api/post-hoc-deliver.js +2 -1
  93. package/dist/api/post-hoc-deliver.js.map +1 -1
  94. package/dist/api/product.d.ts +1 -1
  95. package/dist/api/proposal-decisions.d.ts +44 -0
  96. package/dist/api/proposal-decisions.d.ts.map +1 -0
  97. package/dist/api/proposal-decisions.js +85 -0
  98. package/dist/api/proposal-decisions.js.map +1 -0
  99. package/dist/api/proposal-onboard.d.ts +38 -1
  100. package/dist/api/proposal-onboard.d.ts.map +1 -1
  101. package/dist/api/proposal-onboard.js +203 -14
  102. package/dist/api/proposal-onboard.js.map +1 -1
  103. package/dist/api/recording.d.ts +1 -1
  104. package/dist/api/recording.d.ts.map +1 -1
  105. package/dist/api/recording.js +4 -5
  106. package/dist/api/recording.js.map +1 -1
  107. package/dist/api/redeliver.d.ts.map +1 -1
  108. package/dist/api/redeliver.js +11 -7
  109. package/dist/api/redeliver.js.map +1 -1
  110. package/dist/api/repo-input.d.ts.map +1 -1
  111. package/dist/api/repo-input.js +5 -2
  112. package/dist/api/repo-input.js.map +1 -1
  113. package/dist/api/repo-origins.d.ts +24 -0
  114. package/dist/api/repo-origins.d.ts.map +1 -0
  115. package/dist/api/repo-origins.js +71 -0
  116. package/dist/api/repo-origins.js.map +1 -0
  117. package/dist/api/requirements.d.ts +37 -16
  118. package/dist/api/requirements.d.ts.map +1 -1
  119. package/dist/api/requirements.js +73 -2
  120. package/dist/api/requirements.js.map +1 -1
  121. package/dist/api/retry-index.d.ts +2 -0
  122. package/dist/api/retry-index.d.ts.map +1 -1
  123. package/dist/api/retry-index.js +16 -8
  124. package/dist/api/retry-index.js.map +1 -1
  125. package/dist/api/review-change.d.ts +5 -6
  126. package/dist/api/review-change.d.ts.map +1 -1
  127. package/dist/api/review-change.js +45 -8
  128. package/dist/api/review-change.js.map +1 -1
  129. package/dist/api/roster-standing.d.ts +2 -0
  130. package/dist/api/roster-standing.d.ts.map +1 -1
  131. package/dist/api/roster-standing.js +8 -1
  132. package/dist/api/roster-standing.js.map +1 -1
  133. package/dist/api/routes.d.ts +55 -12
  134. package/dist/api/routes.d.ts.map +1 -1
  135. package/dist/api/routes.js +961 -277
  136. package/dist/api/routes.js.map +1 -1
  137. package/dist/api/run-documents.d.ts +9 -1
  138. package/dist/api/run-documents.d.ts.map +1 -1
  139. package/dist/api/run-documents.js +63 -5
  140. package/dist/api/run-documents.js.map +1 -1
  141. package/dist/api/run-sources.d.ts +11 -1
  142. package/dist/api/run-sources.d.ts.map +1 -1
  143. package/dist/api/run-sources.js +26 -3
  144. package/dist/api/run-sources.js.map +1 -1
  145. package/dist/api/run-timing-index.d.ts +47 -0
  146. package/dist/api/run-timing-index.d.ts.map +1 -1
  147. package/dist/api/run-timing-index.js +196 -86
  148. package/dist/api/run-timing-index.js.map +1 -1
  149. package/dist/api/runtime-state.d.ts +6 -0
  150. package/dist/api/runtime-state.d.ts.map +1 -1
  151. package/dist/api/runtime-state.js +14 -3
  152. package/dist/api/runtime-state.js.map +1 -1
  153. package/dist/api/seat-agents.d.ts.map +1 -1
  154. package/dist/api/seat-agents.js +3 -3
  155. package/dist/api/seat-agents.js.map +1 -1
  156. package/dist/api/seat-container-login.d.ts +6 -2
  157. package/dist/api/seat-container-login.d.ts.map +1 -1
  158. package/dist/api/seat-container-login.js +17 -9
  159. package/dist/api/seat-container-login.js.map +1 -1
  160. package/dist/api/seat-governance.d.ts +3 -2
  161. package/dist/api/seat-governance.d.ts.map +1 -1
  162. package/dist/api/seat-governance.js +31 -9
  163. package/dist/api/seat-governance.js.map +1 -1
  164. package/dist/api/seat-standing.d.ts +8 -0
  165. package/dist/api/seat-standing.d.ts.map +1 -1
  166. package/dist/api/seat-standing.js +26 -1
  167. package/dist/api/seat-standing.js.map +1 -1
  168. package/dist/api/server.d.ts +7 -0
  169. package/dist/api/server.d.ts.map +1 -1
  170. package/dist/api/server.js +172 -59
  171. package/dist/api/server.js.map +1 -1
  172. package/dist/api/stall-watchdog.d.ts +6 -0
  173. package/dist/api/stall-watchdog.d.ts.map +1 -1
  174. package/dist/api/stall-watchdog.js +28 -0
  175. package/dist/api/stall-watchdog.js.map +1 -1
  176. package/dist/api/start-on-login.d.ts +4 -0
  177. package/dist/api/start-on-login.d.ts.map +1 -0
  178. package/dist/api/start-on-login.js +35 -0
  179. package/dist/api/start-on-login.js.map +1 -0
  180. package/dist/api/steering-landing.d.ts +33 -8
  181. package/dist/api/steering-landing.d.ts.map +1 -1
  182. package/dist/api/steering-landing.js +235 -51
  183. package/dist/api/steering-landing.js.map +1 -1
  184. package/dist/api/system-snapshot.d.ts +5 -0
  185. package/dist/api/system-snapshot.d.ts.map +1 -1
  186. package/dist/api/system-snapshot.js +22 -10
  187. package/dist/api/system-snapshot.js.map +1 -1
  188. package/dist/api/testing.d.ts +2 -2
  189. package/dist/api/ui-text.js +2 -2
  190. package/dist/api/ui-text.js.map +1 -1
  191. package/dist/api/worktree-sweep.d.ts +7 -3
  192. package/dist/api/worktree-sweep.d.ts.map +1 -1
  193. package/dist/api/worktree-sweep.js +10 -6
  194. package/dist/api/worktree-sweep.js.map +1 -1
  195. package/dist/apps/actions/api-action.js +5 -2
  196. package/dist/apps/actions/api-action.js.map +1 -1
  197. package/dist/apps/actions/write-path.d.ts +9 -0
  198. package/dist/apps/actions/write-path.d.ts.map +1 -1
  199. package/dist/apps/actions/write-path.js +17 -9
  200. package/dist/apps/actions/write-path.js.map +1 -1
  201. package/dist/apps/exec/executor.d.ts +8 -15
  202. package/dist/apps/exec/executor.d.ts.map +1 -1
  203. package/dist/apps/exec/executor.js +10 -3
  204. package/dist/apps/exec/executor.js.map +1 -1
  205. package/dist/apps/exec/recall.d.ts.map +1 -1
  206. package/dist/apps/exec/recall.js +4 -4
  207. package/dist/apps/exec/recall.js.map +1 -1
  208. package/dist/apps/exec/redescribe.d.ts +37 -0
  209. package/dist/apps/exec/redescribe.d.ts.map +1 -0
  210. package/dist/apps/exec/redescribe.js +86 -0
  211. package/dist/apps/exec/redescribe.js.map +1 -0
  212. package/dist/apps/exec/source-stage.d.ts +3 -1
  213. package/dist/apps/exec/source-stage.d.ts.map +1 -1
  214. package/dist/apps/exec/source-stage.js +13 -3
  215. package/dist/apps/exec/source-stage.js.map +1 -1
  216. package/dist/apps/exec/sources.d.ts +6 -0
  217. package/dist/apps/exec/sources.d.ts.map +1 -1
  218. package/dist/apps/exec/sources.js +8 -0
  219. package/dist/apps/exec/sources.js.map +1 -1
  220. package/dist/apps/git.js +2 -2
  221. package/dist/apps/git.js.map +1 -1
  222. package/dist/apps/publish/manifest.d.ts +8 -1
  223. package/dist/apps/publish/manifest.d.ts.map +1 -1
  224. package/dist/apps/publish/manifest.js +14 -3
  225. package/dist/apps/publish/manifest.js.map +1 -1
  226. package/dist/apps/publish/run.d.ts +15 -2
  227. package/dist/apps/publish/run.d.ts.map +1 -1
  228. package/dist/apps/publish/run.js +100 -17
  229. package/dist/apps/publish/run.js.map +1 -1
  230. package/dist/apps/routes.d.ts +3 -0
  231. package/dist/apps/routes.d.ts.map +1 -1
  232. package/dist/apps/routes.js +58 -2
  233. package/dist/apps/routes.js.map +1 -1
  234. package/dist/apps/store.d.ts +24 -3
  235. package/dist/apps/store.d.ts.map +1 -1
  236. package/dist/apps/store.js +26 -9
  237. package/dist/apps/store.js.map +1 -1
  238. package/dist/apps/turns.d.ts +25 -2
  239. package/dist/apps/turns.d.ts.map +1 -1
  240. package/dist/apps/turns.js +276 -11
  241. package/dist/apps/turns.js.map +1 -1
  242. package/dist/apps-server/Dockerfile +2 -2
  243. package/dist/apps-server/runners/sqlite-runner.mjs +67 -12
  244. package/dist/apps-server/server/lib/bundle/server.mjs +353 -159
  245. package/dist/cli/governance.d.ts +5 -2
  246. package/dist/cli/governance.d.ts.map +1 -1
  247. package/dist/cli/governance.js +8 -5
  248. package/dist/cli/governance.js.map +1 -1
  249. package/dist/cli/index.d.ts.map +1 -1
  250. package/dist/cli/index.js +6 -5
  251. package/dist/cli/index.js.map +1 -1
  252. package/dist/cli/service.d.ts +10 -6
  253. package/dist/cli/service.d.ts.map +1 -1
  254. package/dist/cli/service.js +39 -23
  255. package/dist/cli/service.js.map +1 -1
  256. package/dist/core/adapter.d.ts +61 -29
  257. package/dist/core/adapter.d.ts.map +1 -1
  258. package/dist/core/adapter.js +214 -83
  259. package/dist/core/adapter.js.map +1 -1
  260. package/dist/core/ado-deliver-helper.d.ts +2 -1
  261. package/dist/core/ado-deliver-helper.d.ts.map +1 -1
  262. package/dist/core/ado-deliver-helper.js +26 -1
  263. package/dist/core/ado-deliver-helper.js.map +1 -1
  264. package/dist/core/assurance.d.ts +45 -42
  265. package/dist/core/assurance.d.ts.map +1 -1
  266. package/dist/core/assurance.js +74 -67
  267. package/dist/core/assurance.js.map +1 -1
  268. package/dist/core/deliver-text.d.ts +14 -0
  269. package/dist/core/deliver-text.d.ts.map +1 -1
  270. package/dist/core/deliver-text.js +41 -2
  271. package/dist/core/deliver-text.js.map +1 -1
  272. package/dist/core/deliver.d.ts +66 -1
  273. package/dist/core/deliver.d.ts.map +1 -1
  274. package/dist/core/deliver.js +183 -10
  275. package/dist/core/deliver.js.map +1 -1
  276. package/dist/core/engine-roster.d.ts +2 -0
  277. package/dist/core/engine-roster.d.ts.map +1 -1
  278. package/dist/core/engine-roster.js +13 -0
  279. package/dist/core/engine-roster.js.map +1 -1
  280. package/dist/core/estate-mcp-client.d.ts +13 -14
  281. package/dist/core/estate-mcp-client.d.ts.map +1 -1
  282. package/dist/core/estate-mcp-client.js +49 -68
  283. package/dist/core/estate-mcp-client.js.map +1 -1
  284. package/dist/core/exec.d.ts +24 -0
  285. package/dist/core/exec.d.ts.map +1 -1
  286. package/dist/core/exec.js +45 -2
  287. package/dist/core/exec.js.map +1 -1
  288. package/dist/core/linked-issues.d.ts +13 -2
  289. package/dist/core/linked-issues.d.ts.map +1 -1
  290. package/dist/core/linked-issues.js +135 -4
  291. package/dist/core/linked-issues.js.map +1 -1
  292. package/dist/core/pr-checks-helper.d.ts +8 -4
  293. package/dist/core/pr-checks-helper.d.ts.map +1 -1
  294. package/dist/core/pr-checks-helper.js +39 -17
  295. package/dist/core/pr-checks-helper.js.map +1 -1
  296. package/dist/core/redeliver.js +2 -2
  297. package/dist/core/redeliver.js.map +1 -1
  298. package/dist/core/repo-clone.d.ts +64 -0
  299. package/dist/core/repo-clone.d.ts.map +1 -0
  300. package/dist/core/repo-clone.js +306 -0
  301. package/dist/core/repo-clone.js.map +1 -0
  302. package/dist/core/repoPaths.d.ts +2 -4
  303. package/dist/core/repoPaths.d.ts.map +1 -1
  304. package/dist/core/repoPaths.js +4 -6
  305. package/dist/core/repoPaths.js.map +1 -1
  306. package/dist/core/run-identity.d.ts.map +1 -1
  307. package/dist/core/run-identity.js +3 -0
  308. package/dist/core/run-identity.js.map +1 -1
  309. package/dist/core/run-read-lane.d.ts +30 -0
  310. package/dist/core/run-read-lane.d.ts.map +1 -0
  311. package/dist/core/run-read-lane.js +103 -0
  312. package/dist/core/run-read-lane.js.map +1 -0
  313. package/dist/core/types.d.ts +10 -0
  314. package/dist/core/types.d.ts.map +1 -1
  315. package/dist/core/types.js +2 -0
  316. package/dist/core/types.js.map +1 -1
  317. package/dist/core/walkthrough-root.d.ts.map +1 -1
  318. package/dist/core/walkthrough-root.js +3 -5
  319. package/dist/core/walkthrough-root.js.map +1 -1
  320. package/dist/core/wicked-home.d.ts +9 -0
  321. package/dist/core/wicked-home.d.ts.map +1 -0
  322. package/dist/core/wicked-home.js +25 -0
  323. package/dist/core/wicked-home.js.map +1 -0
  324. package/dist/decisions/consider.d.ts +2 -1
  325. package/dist/decisions/consider.d.ts.map +1 -1
  326. package/dist/decisions/consider.js +2 -2
  327. package/dist/decisions/consider.js.map +1 -1
  328. package/dist/decisions/land.d.ts +2 -0
  329. package/dist/decisions/land.d.ts.map +1 -1
  330. package/dist/decisions/land.js +16 -3
  331. package/dist/decisions/land.js.map +1 -1
  332. package/dist/decisions/rules-brief.d.ts +4 -1
  333. package/dist/decisions/rules-brief.d.ts.map +1 -1
  334. package/dist/decisions/rules-brief.js +3 -2
  335. package/dist/decisions/rules-brief.js.map +1 -1
  336. package/dist/editors/conformance-runtime.d.ts +0 -2
  337. package/dist/editors/conformance-runtime.d.ts.map +1 -1
  338. package/dist/editors/conformance-runtime.js +0 -4
  339. package/dist/editors/conformance-runtime.js.map +1 -1
  340. package/dist/editors/csp.d.ts +6 -0
  341. package/dist/editors/csp.d.ts.map +1 -1
  342. package/dist/editors/csp.js +10 -0
  343. package/dist/editors/csp.js.map +1 -1
  344. package/dist/editors/pack-install.d.ts +11 -15
  345. package/dist/editors/pack-install.d.ts.map +1 -1
  346. package/dist/editors/pack-install.js +52 -65
  347. package/dist/editors/pack-install.js.map +1 -1
  348. package/dist/editors/registry.d.ts +31 -13
  349. package/dist/editors/registry.d.ts.map +1 -1
  350. package/dist/editors/registry.js +51 -18
  351. package/dist/editors/registry.js.map +1 -1
  352. package/dist/editors/routes.d.ts +4 -2
  353. package/dist/editors/routes.d.ts.map +1 -1
  354. package/dist/editors/routes.js +23 -6
  355. package/dist/editors/routes.js.map +1 -1
  356. package/dist/editors/visuals.d.ts +4 -3
  357. package/dist/editors/visuals.d.ts.map +1 -1
  358. package/dist/editors/visuals.js +17 -7
  359. package/dist/editors/visuals.js.map +1 -1
  360. package/dist/evals/runner.js +1 -1
  361. package/dist/evals/runner.js.map +1 -1
  362. package/dist/evals/shape-corrections.js +1 -1
  363. package/dist/evals/shape-corrections.js.map +1 -1
  364. package/dist/evals/shape.d.ts +7 -1
  365. package/dist/evals/shape.d.ts.map +1 -1
  366. package/dist/evals/shape.js +26 -6
  367. package/dist/evals/shape.js.map +1 -1
  368. package/dist/evals/workflow.d.ts +16 -3
  369. package/dist/evals/workflow.d.ts.map +1 -1
  370. package/dist/evals/workflow.js +32 -6
  371. package/dist/evals/workflow.js.map +1 -1
  372. package/dist/governance/rule-revision.d.ts +7 -0
  373. package/dist/governance/rule-revision.d.ts.map +1 -0
  374. package/dist/governance/rule-revision.js +23 -0
  375. package/dist/governance/rule-revision.js.map +1 -0
  376. package/dist/insights/review-service.d.ts +26 -3
  377. package/dist/insights/review-service.d.ts.map +1 -1
  378. package/dist/insights/review-service.js +101 -11
  379. package/dist/insights/review-service.js.map +1 -1
  380. package/dist/insights/routes.d.ts +2 -1
  381. package/dist/insights/routes.d.ts.map +1 -1
  382. package/dist/insights/routes.js +19 -4
  383. package/dist/insights/routes.js.map +1 -1
  384. package/dist/insights/run-facts.d.ts +5 -0
  385. package/dist/insights/run-facts.d.ts.map +1 -1
  386. package/dist/insights/run-facts.js +15 -0
  387. package/dist/insights/run-facts.js.map +1 -1
  388. package/dist/insights/workflow.d.ts +2 -1
  389. package/dist/insights/workflow.d.ts.map +1 -1
  390. package/dist/insights/workflow.js +4 -4
  391. package/dist/insights/workflow.js.map +1 -1
  392. package/dist/inspect/service.d.ts +3 -2
  393. package/dist/inspect/service.d.ts.map +1 -1
  394. package/dist/inspect/service.js +4 -4
  395. package/dist/inspect/service.js.map +1 -1
  396. package/dist/interactive/bridge-pool.d.ts +2 -0
  397. package/dist/interactive/bridge-pool.d.ts.map +1 -1
  398. package/dist/interactive/bridge-pool.js +18 -8
  399. package/dist/interactive/bridge-pool.js.map +1 -1
  400. package/dist/interactive/chat-events.d.ts +3 -0
  401. package/dist/interactive/chat-events.d.ts.map +1 -1
  402. package/dist/interactive/chat-events.js +20 -5
  403. package/dist/interactive/chat-events.js.map +1 -1
  404. package/dist/interactive/doc-delete-routes.d.ts +1 -0
  405. package/dist/interactive/doc-delete-routes.d.ts.map +1 -1
  406. package/dist/interactive/doc-delete-routes.js +126 -123
  407. package/dist/interactive/doc-delete-routes.js.map +1 -1
  408. package/dist/interactive/draft-events.d.ts +11 -7
  409. package/dist/interactive/draft-events.d.ts.map +1 -1
  410. package/dist/interactive/draft-events.js +29 -22
  411. package/dist/interactive/draft-events.js.map +1 -1
  412. package/dist/interactive/draft-skill.d.ts +56 -3
  413. package/dist/interactive/draft-skill.d.ts.map +1 -1
  414. package/dist/interactive/draft-skill.js +129 -20
  415. package/dist/interactive/draft-skill.js.map +1 -1
  416. package/dist/interactive/landing-guard.d.ts +30 -5
  417. package/dist/interactive/landing-guard.d.ts.map +1 -1
  418. package/dist/interactive/landing-guard.js +121 -5
  419. package/dist/interactive/landing-guard.js.map +1 -1
  420. package/dist/interactive/proposal-create.d.ts +9 -11
  421. package/dist/interactive/proposal-create.d.ts.map +1 -1
  422. package/dist/interactive/proposal-create.js +28 -21
  423. package/dist/interactive/proposal-create.js.map +1 -1
  424. package/dist/interactive/proposal-refine.d.ts +4 -4
  425. package/dist/interactive/proposal-refine.d.ts.map +1 -1
  426. package/dist/interactive/proposal-refine.js +40 -7
  427. package/dist/interactive/proposal-refine.js.map +1 -1
  428. package/dist/interactive/proxy-routes.d.ts +10 -5
  429. package/dist/interactive/proxy-routes.d.ts.map +1 -1
  430. package/dist/interactive/proxy-routes.js +108 -11
  431. package/dist/interactive/proxy-routes.js.map +1 -1
  432. package/dist/interactive/review-events.js +1 -1
  433. package/dist/interactive/review-events.js.map +1 -1
  434. package/dist/interactive/run-units.d.ts.map +1 -1
  435. package/dist/interactive/run-units.js +3 -2
  436. package/dist/interactive/run-units.js.map +1 -1
  437. package/dist/interactive/source-packet.d.ts +13 -1
  438. package/dist/interactive/source-packet.d.ts.map +1 -1
  439. package/dist/interactive/source-packet.js +108 -34
  440. package/dist/interactive/source-packet.js.map +1 -1
  441. package/dist/knowledge/adapters/toolbox/memory.d.ts +2 -0
  442. package/dist/knowledge/adapters/toolbox/memory.d.ts.map +1 -0
  443. package/dist/knowledge/adapters/toolbox/memory.js +43 -0
  444. package/dist/knowledge/adapters/toolbox/memory.js.map +1 -0
  445. package/dist/knowledge/adapters/toolbox/supervisor.d.ts +30 -4
  446. package/dist/knowledge/adapters/toolbox/supervisor.d.ts.map +1 -1
  447. package/dist/knowledge/adapters/toolbox/supervisor.js +112 -28
  448. package/dist/knowledge/adapters/toolbox/supervisor.js.map +1 -1
  449. package/dist/knowledge/estate-write.d.ts +5 -0
  450. package/dist/knowledge/estate-write.d.ts.map +1 -1
  451. package/dist/knowledge/estate-write.js +7 -0
  452. package/dist/knowledge/estate-write.js.map +1 -1
  453. package/dist/knowledge/gate/gate.d.ts.map +1 -1
  454. package/dist/knowledge/gate/gate.js +4 -1
  455. package/dist/knowledge/gate/gate.js.map +1 -1
  456. package/dist/knowledge/gate/record.d.ts +15 -2
  457. package/dist/knowledge/gate/record.d.ts.map +1 -1
  458. package/dist/knowledge/gate/record.js +108 -29
  459. package/dist/knowledge/gate/record.js.map +1 -1
  460. package/dist/knowledge/projector.d.ts +60 -5
  461. package/dist/knowledge/projector.d.ts.map +1 -1
  462. package/dist/knowledge/projector.js +264 -21
  463. package/dist/knowledge/projector.js.map +1 -1
  464. package/dist/knowledge/registry/entry.d.ts +7 -0
  465. package/dist/knowledge/registry/entry.d.ts.map +1 -1
  466. package/dist/knowledge/registry/entry.js +4 -0
  467. package/dist/knowledge/registry/entry.js.map +1 -1
  468. package/dist/knowledge/shapes/map.d.ts.map +1 -1
  469. package/dist/knowledge/shapes/map.js +12 -2
  470. package/dist/knowledge/shapes/map.js.map +1 -1
  471. package/dist/knowledge/shapes/routes.d.ts +1 -1
  472. package/dist/knowledge/shapes/routes.d.ts.map +1 -1
  473. package/dist/knowledge/shapes/routes.js +42 -16
  474. package/dist/knowledge/shapes/routes.js.map +1 -1
  475. package/dist/knowledge/shapes/shapes.d.ts +60 -13
  476. package/dist/knowledge/shapes/shapes.d.ts.map +1 -1
  477. package/dist/knowledge/shapes/shapes.js +199 -31
  478. package/dist/knowledge/shapes/shapes.js.map +1 -1
  479. package/dist/knowledge/shapes/verified.d.ts.map +1 -1
  480. package/dist/knowledge/shapes/verified.js +3 -2
  481. package/dist/knowledge/shapes/verified.js.map +1 -1
  482. package/dist/knowledge/trackers/addresses.d.ts +27 -3
  483. package/dist/knowledge/trackers/addresses.d.ts.map +1 -1
  484. package/dist/knowledge/trackers/addresses.js +33 -5
  485. package/dist/knowledge/trackers/addresses.js.map +1 -1
  486. package/dist/knowledge/trackers/gate-pm.d.ts.map +1 -1
  487. package/dist/knowledge/trackers/gate-pm.js +4 -2
  488. package/dist/knowledge/trackers/gate-pm.js.map +1 -1
  489. package/dist/knowledge/trackers/projector.d.ts +3 -1
  490. package/dist/knowledge/trackers/projector.d.ts.map +1 -1
  491. package/dist/knowledge/trackers/projector.js +59 -8
  492. package/dist/knowledge/trackers/projector.js.map +1 -1
  493. package/dist/learn/scheduler.d.ts.map +1 -1
  494. package/dist/learn/scheduler.js +13 -3
  495. package/dist/learn/scheduler.js.map +1 -1
  496. package/dist/learnings/estate.d.ts.map +1 -1
  497. package/dist/learnings/estate.js +3 -14
  498. package/dist/learnings/estate.js.map +1 -1
  499. package/dist/learnings/extract.d.ts +9 -3
  500. package/dist/learnings/extract.d.ts.map +1 -1
  501. package/dist/learnings/extract.js +62 -4
  502. package/dist/learnings/extract.js.map +1 -1
  503. package/dist/learnings/replacement-lineage.d.ts +3 -2
  504. package/dist/learnings/replacement-lineage.d.ts.map +1 -1
  505. package/dist/learnings/replacement-lineage.js +7 -6
  506. package/dist/learnings/replacement-lineage.js.map +1 -1
  507. package/dist/learnings/service.d.ts +12 -2
  508. package/dist/learnings/service.d.ts.map +1 -1
  509. package/dist/learnings/service.js +30 -5
  510. package/dist/learnings/service.js.map +1 -1
  511. package/dist/mcp/broker.d.ts.map +1 -1
  512. package/dist/mcp/broker.js +19 -5
  513. package/dist/mcp/broker.js.map +1 -1
  514. package/dist/mcp/env.d.ts +12 -4
  515. package/dist/mcp/env.d.ts.map +1 -1
  516. package/dist/mcp/env.js +24 -4
  517. package/dist/mcp/env.js.map +1 -1
  518. package/dist/mcp/estate-relay.d.ts +3 -0
  519. package/dist/mcp/estate-relay.d.ts.map +1 -1
  520. package/dist/mcp/estate-relay.js +7 -6
  521. package/dist/mcp/estate-relay.js.map +1 -1
  522. package/dist/mcp/invoke.d.ts.map +1 -1
  523. package/dist/mcp/invoke.js +6 -5
  524. package/dist/mcp/invoke.js.map +1 -1
  525. package/dist/mcp/probe.d.ts +14 -1
  526. package/dist/mcp/probe.d.ts.map +1 -1
  527. package/dist/mcp/probe.js +55 -10
  528. package/dist/mcp/probe.js.map +1 -1
  529. package/dist/mcp/redact.d.ts +1 -1
  530. package/dist/mcp/redact.d.ts.map +1 -1
  531. package/dist/mcp/redact.js +61 -4
  532. package/dist/mcp/redact.js.map +1 -1
  533. package/dist/mcp/registry-store.d.ts +37 -0
  534. package/dist/mcp/registry-store.d.ts.map +1 -1
  535. package/dist/mcp/registry-store.js +43 -0
  536. package/dist/mcp/registry-store.js.map +1 -1
  537. package/dist/mcp/registry.d.ts +38 -6
  538. package/dist/mcp/registry.d.ts.map +1 -1
  539. package/dist/mcp/registry.js +145 -14
  540. package/dist/mcp/registry.js.map +1 -1
  541. package/dist/mcp/rest.js +4 -4
  542. package/dist/mcp/rest.js.map +1 -1
  543. package/dist/mcp/run-fence.d.ts +2 -0
  544. package/dist/mcp/run-fence.d.ts.map +1 -1
  545. package/dist/mcp/run-fence.js +9 -0
  546. package/dist/mcp/run-fence.js.map +1 -1
  547. package/dist/mcp/secrets.d.ts +1 -1
  548. package/dist/mcp/secrets.d.ts.map +1 -1
  549. package/dist/mcp/secrets.js +10 -11
  550. package/dist/mcp/secrets.js.map +1 -1
  551. package/dist/mcp/upstream-error.d.ts +6 -2
  552. package/dist/mcp/upstream-error.d.ts.map +1 -1
  553. package/dist/mcp/upstream-error.js +5 -1
  554. package/dist/mcp/upstream-error.js.map +1 -1
  555. package/dist/projects/graph.d.ts +15 -5
  556. package/dist/projects/graph.d.ts.map +1 -1
  557. package/dist/projects/graph.js +354 -26
  558. package/dist/projects/graph.js.map +1 -1
  559. package/dist/projects/repo-watch.d.ts +2 -2
  560. package/dist/projects/repo-watch.d.ts.map +1 -1
  561. package/dist/projects/repo-watch.js +26 -9
  562. package/dist/projects/repo-watch.js.map +1 -1
  563. package/dist/projects/routes.d.ts +9 -1
  564. package/dist/projects/routes.d.ts.map +1 -1
  565. package/dist/projects/routes.js +63 -6
  566. package/dist/projects/routes.js.map +1 -1
  567. package/dist/projects/state-home-preflight.d.ts +5 -0
  568. package/dist/projects/state-home-preflight.d.ts.map +1 -1
  569. package/dist/projects/state-home-preflight.js +48 -8
  570. package/dist/projects/state-home-preflight.js.map +1 -1
  571. package/dist/projects/state-home-registry.d.ts.map +1 -1
  572. package/dist/projects/state-home-registry.js +9 -0
  573. package/dist/projects/state-home-registry.js.map +1 -1
  574. package/dist/projects/state-home.d.ts +11 -0
  575. package/dist/projects/state-home.d.ts.map +1 -1
  576. package/dist/projects/state-home.js +14 -0
  577. package/dist/projects/state-home.js.map +1 -1
  578. package/dist/qe/author-workflow.d.ts +4 -0
  579. package/dist/qe/author-workflow.d.ts.map +1 -1
  580. package/dist/qe/author-workflow.js +4 -0
  581. package/dist/qe/author-workflow.js.map +1 -1
  582. package/dist/qe/test-sets.d.ts +5 -6
  583. package/dist/qe/test-sets.d.ts.map +1 -1
  584. package/dist/qe/test-sets.js +4 -3
  585. package/dist/qe/test-sets.js.map +1 -1
  586. package/dist/schedules/routes.d.ts +5 -0
  587. package/dist/schedules/routes.d.ts.map +1 -1
  588. package/dist/schedules/routes.js +32 -5
  589. package/dist/schedules/routes.js.map +1 -1
  590. package/dist/schedules/scheduler.d.ts +8 -1
  591. package/dist/schedules/scheduler.d.ts.map +1 -1
  592. package/dist/schedules/scheduler.js +10 -1
  593. package/dist/schedules/scheduler.js.map +1 -1
  594. package/dist/schedules/store.d.ts +7 -0
  595. package/dist/schedules/store.d.ts.map +1 -1
  596. package/dist/schedules/store.js +19 -4
  597. package/dist/schedules/store.js.map +1 -1
  598. package/dist/skills/plugin-source.js +4 -4
  599. package/dist/skills/plugin-source.js.map +1 -1
  600. package/dist/sources/ask.d.ts.map +1 -1
  601. package/dist/sources/ask.js +12 -12
  602. package/dist/sources/ask.js.map +1 -1
  603. package/dist/sources/dialer.d.ts +6 -1
  604. package/dist/sources/dialer.d.ts.map +1 -1
  605. package/dist/sources/dialer.js +53 -31
  606. package/dist/sources/dialer.js.map +1 -1
  607. package/dist/sources/drivers/mysql.d.ts +2 -0
  608. package/dist/sources/drivers/mysql.d.ts.map +1 -1
  609. package/dist/sources/drivers/mysql.js +18 -2
  610. package/dist/sources/drivers/mysql.js.map +1 -1
  611. package/dist/sources/drivers/postgres.d.ts +2 -0
  612. package/dist/sources/drivers/postgres.d.ts.map +1 -1
  613. package/dist/sources/drivers/postgres.js +10 -3
  614. package/dist/sources/drivers/postgres.js.map +1 -1
  615. package/dist/sources/drivers/sqlite.d.ts +33 -3
  616. package/dist/sources/drivers/sqlite.d.ts.map +1 -1
  617. package/dist/sources/drivers/sqlite.js +18 -6
  618. package/dist/sources/drivers/sqlite.js.map +1 -1
  619. package/dist/sources/drivers/types.d.ts +3 -1
  620. package/dist/sources/drivers/types.d.ts.map +1 -1
  621. package/dist/sources/drivers/types.js +3 -1
  622. package/dist/sources/drivers/types.js.map +1 -1
  623. package/dist/sources/routes.d.ts.map +1 -1
  624. package/dist/sources/routes.js +1 -0
  625. package/dist/sources/routes.js.map +1 -1
  626. package/dist/sources/uploads.d.ts +22 -15
  627. package/dist/sources/uploads.d.ts.map +1 -1
  628. package/dist/sources/uploads.js +124 -436
  629. package/dist/sources/uploads.js.map +1 -1
  630. package/dist/standing-orders/history.d.ts +5 -3
  631. package/dist/standing-orders/history.d.ts.map +1 -1
  632. package/dist/standing-orders/history.js +6 -2
  633. package/dist/standing-orders/history.js.map +1 -1
  634. package/dist/standing-orders/parse.d.ts +8 -0
  635. package/dist/standing-orders/parse.d.ts.map +1 -1
  636. package/dist/standing-orders/parse.js +52 -5
  637. package/dist/standing-orders/parse.js.map +1 -1
  638. package/dist/studio/apps-standalone/fixture.js +3 -3
  639. package/dist/studio/apps-standalone/runtime.js +1 -1
  640. package/dist/studio/assets/{KnowledgeGraph-DWw0I8RJ.js → KnowledgeGraph-yP4WsnST.js} +1 -1
  641. package/dist/studio/assets/index-DNaLjJ7M.css +32 -0
  642. package/dist/studio/assets/index-DW53FKuT.js +1114 -0
  643. package/dist/studio/editors/wicked-apps/editor.json +1 -1
  644. package/dist/studio/editors/wicked-apps/index.html +2 -2
  645. package/dist/studio/editors/wicked-deck/editor.json +1 -1
  646. package/dist/studio/editors/wicked-deck/index.html +2 -2
  647. package/dist/studio/editors/wicked-doc/editor.json +1 -1
  648. package/dist/studio/editors/wicked-doc/index.html +1 -1
  649. package/dist/studio/editors/wicked-insights/editor.json +1 -1
  650. package/dist/studio/editors/wicked-insights/index.html +1 -1
  651. package/dist/studio/editors/wicked-page/editor.json +1 -1
  652. package/dist/studio/editors/wicked-page/index.html +1 -1
  653. package/dist/studio/editors/wicked-video/editor.json +1 -1
  654. package/dist/studio/editors/wicked-video/index.html +1 -1
  655. package/dist/studio/index.html +2 -2
  656. package/dist/studio/testid-inventory.json +1589 -281
  657. package/dist/team/routes.d.ts +11 -1
  658. package/dist/team/routes.d.ts.map +1 -1
  659. package/dist/team/routes.js +8 -4
  660. package/dist/team/routes.js.map +1 -1
  661. package/dist/voice/tts.d.ts +12 -0
  662. package/dist/voice/tts.d.ts.map +1 -1
  663. package/dist/voice/tts.js +118 -28
  664. package/dist/voice/tts.js.map +1 -1
  665. package/dist/workflow-catalog/build-v2.d.ts +34 -0
  666. package/dist/workflow-catalog/build-v2.d.ts.map +1 -1
  667. package/dist/workflow-catalog/build-v2.js +131 -10
  668. package/dist/workflow-catalog/build-v2.js.map +1 -1
  669. package/dist/workflow-catalog/catalog-data-v2.d.ts +6 -2
  670. package/dist/workflow-catalog/catalog-data-v2.d.ts.map +1 -1
  671. package/dist/workflow-catalog/catalog-data-v2.js.map +1 -1
  672. package/dist/workflow-catalog/catalog-data.d.ts.map +1 -1
  673. package/dist/workflow-catalog/catalog-data.js +0 -2
  674. package/dist/workflow-catalog/catalog-data.js.map +1 -1
  675. package/dist/workflow-catalog/detect.d.ts +18 -3
  676. package/dist/workflow-catalog/detect.d.ts.map +1 -1
  677. package/dist/workflow-catalog/detect.js +43 -8
  678. package/dist/workflow-catalog/detect.js.map +1 -1
  679. package/dist/workflow-catalog/shape.d.ts +1 -1
  680. package/dist/working-doc/event-lines.d.ts +12 -2
  681. package/dist/working-doc/event-lines.d.ts.map +1 -1
  682. package/dist/working-doc/event-lines.js +62 -10
  683. package/dist/working-doc/event-lines.js.map +1 -1
  684. package/dist/working-doc/sections.d.ts +3 -0
  685. package/dist/working-doc/sections.d.ts.map +1 -1
  686. package/dist/working-doc/sections.js +5 -0
  687. package/dist/working-doc/sections.js.map +1 -1
  688. package/dist/working-doc/service.d.ts +23 -3
  689. package/dist/working-doc/service.d.ts.map +1 -1
  690. package/dist/working-doc/service.js +93 -54
  691. package/dist/working-doc/service.js.map +1 -1
  692. package/endpoint-manifest.json +148 -8
  693. package/evals/corpora/shape-v1.json +25 -1
  694. package/evals/corpora/shape-v1.seat-fixture.json +25 -1
  695. package/package.json +4 -4
  696. package/runners/sqlite-runner.mjs +67 -12
  697. package/runners/upload-parse.d.mts +13 -0
  698. package/runners/upload-parse.mjs +364 -0
  699. package/dist/studio/assets/index-C4Xj-zxa.css +0 -32
  700. package/dist/studio/assets/index-CrNY3d06.js +0 -1109
@@ -4,22 +4,26 @@
4
4
  * `<state home>/mcp/snapshots/<sha256>.sqlite` — outside any git repo (an app repo holds only the
5
5
  * digest) and inside the state-home entry workers are fenced out of.
6
6
  *
7
- * - CSV/XLSX: parsed here (no third-party parser), header detected (a first row that looks like data
8
- * becomes `col_1…`), column types inferred (INTEGER, REAL, TEXT), written to a new SQLite file.
7
+ * - CSV/XLSX: parsed in the killable runner child (crew#1289), header detected (a first row that
8
+ * looks like data becomes `col_1…`), types inferred (INTEGER, REAL, TEXT), written to a SQLite file.
9
9
  * The first 20 rows are returned for the PERSON's sheet only (the route never gives them to an agent).
10
10
  * - XLSX is a zip: entries are inflated with a hard output cap, so a file that expands past 200 MB is
11
11
  * refused before it is held (a zip bomb). Zip64, encryption and unknown methods are refused.
12
- * - `.sqlite`: refused if it holds a view, a trigger or a virtual table (§5.1), inspected in the
13
- * snapshot runner's child process, never in the daemon.
12
+ * - `.sqlite`: refused if it holds a view or a trigger (§5.1), inspected in the snapshot runner's child
13
+ * process, never in the daemon. A virtual table (a full-text index, an R-tree) is dropped from crew's copy
14
+ * with its shadow tables, in the same child, and the result names it (crew#1731); one whose module this
15
+ * SQLite lacks cannot be dropped, and the file is refused naming it. Every copy is then rewritten with
16
+ * VACUUM INTO, so no snapshot keeps the file's free pages (crew#1787).
17
+ * - A crash mid-upload leaves its `.tmp-*` files behind: each upload starts a sweep (one at a time, never awaited) that
18
+ * removes the ones older than {@link STALE_TMP_MS} and not a live upload's (crew#1724).
14
19
  * - Limits: 50 MB file, 200 MB after decompression, 1,000,000 rows, 200 columns, 30 s to parse.
15
20
  */
16
21
  import { createHash, randomUUID } from 'node:crypto';
17
- import { chmod, mkdir, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
22
+ import { chmod, mkdir, readdir, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
18
23
  import { homedir } from 'node:os';
19
24
  import { basename, dirname, join, resolve } from 'node:path';
20
- import { inflateRawSync } from 'node:zlib';
21
25
  import { mcpStateDir } from '../mcp/registry-store.js';
22
- import { sqliteCreate, sqliteInspect } from './drivers/sqlite.js';
26
+ import { isRunnerFailure, sqliteIngest, sqliteInspect, sqliteStrip } from './drivers/sqlite.js';
23
27
  import { SourceQueryError } from './drivers/types.js';
24
28
  export const UPLOAD_LIMITS = Object.freeze({
25
29
  fileBytes: 50 * 1024 * 1024,
@@ -52,417 +56,60 @@ export function snapshotPath(digest, dir = snapshotDir()) {
52
56
  throw new UploadError('bad_digest', 'a snapshot digest is 64 hex characters');
53
57
  return join(dir, `${digest}.sqlite`);
54
58
  }
55
- // ── CSV ──────────────────────────────────────────────────────────────────────────────────────
56
- function detectDelimiter(text) {
57
- // The first record, with quoted fields taken out (a quoted field may hold any delimiter).
58
- let first = '';
59
- let quoted = false;
60
- for (let i = 0; i < text.length && i < 1_000_000; i++) {
61
- const c = text[i];
62
- if (c === '"')
63
- quoted = !quoted;
64
- else if (!quoted && (c === '\n' || c === '\r'))
65
- break;
66
- else if (!quoted)
67
- first += c;
68
- }
69
- const counts = [',', ';', '\t'].map((d) => [d, first.split(d).length]);
70
- return counts.sort((a, b) => b[1] - a[1])[0]?.[0] ?? ',';
71
- }
72
- /** RFC 4180 rows (quoted fields, doubled quotes, CRLF or LF), bounded by the limits. */
73
- export function parseCsv(text, deadline) {
74
- const d = detectDelimiter(text);
75
- const rows = [];
76
- let row = [];
77
- let field = '';
78
- let i = 0;
79
- let quoted = false;
80
- const n = text.length;
81
- const endRow = () => {
82
- row.push(field);
83
- field = '';
84
- if (!(row.length === 1 && row[0] === '')) {
85
- if (row.length > UPLOAD_LIMITS.columns)
86
- throw new UploadError('too_many_columns', `the file has more than ${UPLOAD_LIMITS.columns} columns`);
87
- rows.push(row);
88
- if (rows.length > UPLOAD_LIMITS.rows + 1)
89
- throw new UploadError('too_many_rows', `the file has more than ${UPLOAD_LIMITS.rows} rows`);
90
- if (rows.length % 10_000 === 0 && Date.now() > deadline)
91
- throw new UploadError('too_slow', `the file took more than ${UPLOAD_LIMITS.parseMs / 1000} s to parse`);
92
- }
93
- row = [];
94
- };
95
- while (i < n) {
96
- if ((i & 0xffff) === 0 && Date.now() > deadline)
97
- throw new UploadError('too_slow', `the file took more than ${UPLOAD_LIMITS.parseMs / 1000} s to parse`);
98
- const c = text[i];
99
- if (quoted) {
100
- if (c === '"') {
101
- if (text[i + 1] === '"') {
102
- field += '"';
103
- i += 2;
104
- continue;
105
- }
106
- quoted = false;
107
- i++;
108
- continue;
109
- }
110
- field += c;
111
- i++;
112
- continue;
113
- }
114
- if (c === '"' && field === '') {
115
- quoted = true;
116
- i++;
117
- continue;
118
- }
119
- if (c === d) {
120
- row.push(field);
121
- field = '';
122
- if (row.length > UPLOAD_LIMITS.columns)
123
- throw new UploadError('too_many_columns', `the file has more than ${UPLOAD_LIMITS.columns} columns`);
124
- i++;
125
- continue;
126
- }
127
- if (c === '\r' && text[i + 1] === '\n') {
128
- endRow();
129
- i += 2;
130
- continue;
131
- }
132
- if (c === '\n' || c === '\r') {
133
- endRow();
134
- i++;
135
- continue;
136
- }
137
- field += c;
138
- i++;
139
- }
140
- if (quoted)
141
- throw new UploadError('bad_csv', 'the file ends inside a quoted field');
142
- if (field !== '' || row.length > 0)
143
- endRow();
144
- return rows;
145
- }
146
- function zipEntries(buf) {
147
- const min = Math.max(0, buf.length - 65_557);
148
- let eocd = -1;
149
- for (let i = buf.length - 22; i >= min; i--) {
150
- if (buf.readUInt32LE(i) === 0x06054b50) {
151
- eocd = i;
152
- break;
153
- }
154
- }
155
- if (eocd < 0)
156
- throw new UploadError('bad_xlsx', 'the file is not an XLSX workbook (no zip directory)');
157
- const count = buf.readUInt16LE(eocd + 10);
158
- const cdSize = buf.readUInt32LE(eocd + 12);
159
- const cdOffset = buf.readUInt32LE(eocd + 16);
160
- if (count === 0xffff || cdOffset === 0xffffffff || cdSize === 0xffffffff)
161
- throw new UploadError('bad_xlsx', 'zip64 workbooks are not supported');
162
- if (cdOffset + cdSize > buf.length)
163
- throw new UploadError('bad_xlsx', 'the zip directory points past the end of the file');
164
- const out = [];
165
- let p = cdOffset;
166
- for (let k = 0; k < count; k++) {
167
- if (p + 46 > buf.length || buf.readUInt32LE(p) !== 0x02014b50)
168
- throw new UploadError('bad_xlsx', 'a damaged zip directory');
169
- const flags = buf.readUInt16LE(p + 8);
170
- const method = buf.readUInt16LE(p + 10);
171
- const compressedSize = buf.readUInt32LE(p + 20);
172
- const size = buf.readUInt32LE(p + 24);
173
- const nameLen = buf.readUInt16LE(p + 28);
174
- const extraLen = buf.readUInt16LE(p + 30);
175
- const commentLen = buf.readUInt16LE(p + 32);
176
- const localOffset = buf.readUInt32LE(p + 42);
177
- const name = buf.subarray(p + 46, p + 46 + nameLen).toString('utf8');
178
- out.push({ name, method, flags, compressedSize, size, localOffset });
179
- p += 46 + nameLen + extraLen + commentLen;
180
- }
181
- return out;
182
- }
183
- class ZipReader {
184
- buf;
185
- entries;
186
- expanded = 0;
187
- constructor(buf, entries) {
188
- this.buf = buf;
189
- this.entries = entries;
190
- }
191
- has(name) {
192
- return this.entries.some((e) => e.name === name);
193
- }
194
- /** One entry's bytes, inflated with the remaining expansion budget as a HARD cap. */
195
- read(name) {
196
- const e = this.entries.find((x) => x.name === name);
197
- if (e === undefined)
198
- throw new UploadError('bad_xlsx', `the workbook has no ${name}`);
199
- if ((e.flags & 0x1) !== 0)
200
- throw new UploadError('bad_xlsx', 'encrypted workbooks are not supported');
201
- const p = e.localOffset;
202
- if (p + 30 > this.buf.length || this.buf.readUInt32LE(p) !== 0x04034b50)
203
- throw new UploadError('bad_xlsx', 'a damaged zip entry');
204
- const start = p + 30 + this.buf.readUInt16LE(p + 26) + this.buf.readUInt16LE(p + 28);
205
- const data = this.buf.subarray(start, start + e.compressedSize);
206
- const budget = UPLOAD_LIMITS.expandedBytes - this.expanded;
207
- if (e.size > budget)
208
- throw new UploadError('too_large', `the workbook expands past ${UPLOAD_LIMITS.expandedBytes / (1024 * 1024)} MB`);
209
- let bytes;
210
- if (e.method === 0)
211
- bytes = Buffer.from(data);
212
- else if (e.method === 8) {
213
- try {
214
- bytes = inflateRawSync(data, { maxOutputLength: Math.max(1, budget) });
215
- }
216
- catch (err) {
217
- const code = err.code;
218
- if (code === 'ERR_BUFFER_TOO_LARGE' || /buffer|too large|maxOutputLength/i.test(String(err.message))) {
219
- throw new UploadError('too_large', `the workbook expands past ${UPLOAD_LIMITS.expandedBytes / (1024 * 1024)} MB`);
220
- }
221
- throw new UploadError('bad_xlsx', `a zip entry could not be inflated: ${err.message}`);
222
- }
223
- }
224
- else
225
- throw new UploadError('bad_xlsx', `zip method ${e.method} is not supported`);
226
- this.expanded += bytes.length;
227
- if (this.expanded > UPLOAD_LIMITS.expandedBytes)
228
- throw new UploadError('too_large', `the workbook expands past ${UPLOAD_LIMITS.expandedBytes / (1024 * 1024)} MB`);
229
- return bytes.toString('utf8');
230
- }
231
- }
232
- function xmlText(s) {
233
- return s
234
- .replace(/&#x([0-9a-fA-F]+);/g, (_m, h) => String.fromCodePoint(parseInt(h, 16)))
235
- .replace(/&#(\d+);/g, (_m, d) => String.fromCodePoint(Number(d)))
236
- .replace(/&lt;/g, '<')
237
- .replace(/&gt;/g, '>')
238
- .replace(/&quot;/g, '"')
239
- .replace(/&apos;/g, "'")
240
- .replace(/&amp;/g, '&');
241
- }
242
- function attr(tag, name) {
243
- const m = new RegExp(`\\s${name}="([^"]*)"`).exec(tag);
244
- return m === null ? null : xmlText(m[1]);
245
- }
246
- function colIndex(ref) {
247
- const letters = /^([A-Z]+)/.exec(ref)?.[1] ?? 'A';
248
- let n = 0;
249
- for (const ch of letters)
250
- n = n * 26 + (ch.charCodeAt(0) - 64);
251
- return n - 1;
252
- }
253
- function* elements(xml, tag, withHead = false) {
254
- const open = `<${tag}`;
255
- const close = `</${tag}>`;
256
- let at = 0;
257
- for (;;) {
258
- let i = xml.indexOf(open, at);
259
- while (i >= 0 && !/[\s>/]/.test(xml[i + open.length] ?? ''))
260
- i = xml.indexOf(open, i + 1);
261
- if (i < 0)
262
- return;
263
- const headEnd = xml.indexOf('>', i);
264
- if (headEnd < 0)
265
- return;
266
- const head = xml.slice(i, headEnd + 1);
267
- if (head.endsWith('/>')) {
268
- yield withHead ? { head, body: '' } : '';
269
- at = headEnd + 1;
270
- continue;
271
- }
272
- const end = xml.indexOf(close, headEnd + 1);
273
- if (end < 0)
274
- return;
275
- const body = xml.slice(headEnd + 1, end);
276
- yield withHead ? { head, body } : body;
277
- at = end + close.length;
278
- }
279
- }
280
- /** The concatenated text of every `<t>` in a fragment (a shared string's runs, an inline string). */
281
- function texts(fragment) {
282
- let out = '';
283
- for (const t of elements(fragment, 't'))
284
- out += xmlText(t);
285
- return out;
286
- }
287
- /** The first sheet of an XLSX workbook as rows of strings. */
288
- export function parseXlsx(buf, deadline) {
289
- const zip = new ZipReader(buf, zipEntries(buf));
290
- const workbook = zip.read('xl/workbook.xml');
291
- const sheetTag = /<sheet\b[^>]*>/.exec(workbook)?.[0];
292
- if (sheetTag === undefined)
293
- throw new UploadError('bad_xlsx', 'the workbook has no sheet');
294
- const rid = attr(sheetTag, 'r:id');
295
- const rels = zip.read('xl/_rels/workbook.xml.rels');
296
- let target = 'worksheets/sheet1.xml';
297
- for (const m of rels.matchAll(/<Relationship\b[^>]*>/g))
298
- if (attr(m[0], 'Id') === rid)
299
- target = attr(m[0], 'Target') ?? target;
300
- const sheetPath = target.startsWith('/') ? target.slice(1) : `xl/${target.replace(/^\.\//, '')}`;
301
- // Every scan below is linear (indexOf from a moving cursor, never a lazy regex over the rest of the
302
- // text), so a hostile sheet of unclosed tags costs one pass, not one pass per tag.
303
- const shared = [];
304
- if (zip.has('xl/sharedStrings.xml')) {
305
- const sst = zip.read('xl/sharedStrings.xml');
306
- let sharedBytes = 0;
307
- for (const si of elements(sst, 'si')) {
308
- if ((shared.length & 0x3ff) === 0)
309
- within(deadline);
310
- const t = texts(si);
311
- sharedBytes += t.length;
312
- if (sharedBytes > UPLOAD_LIMITS.expandedBytes)
313
- throw new UploadError('too_large', `the workbook's strings expand past ${UPLOAD_LIMITS.expandedBytes / (1024 * 1024)} MB`);
314
- shared.push(t);
315
- }
316
- }
317
- const sheet = zip.read(sheetPath);
318
- const rows = [];
319
- // Shared strings are referenced, not copied: count what the cells hold once resolved, so a small
320
- // sheet repeating one large string cannot become a snapshot far past the expansion limit.
321
- let cellBytes = 0;
322
- let cells = 0;
323
- for (const rowXml of elements(sheet, 'row')) {
324
- const row = [];
325
- for (const cell of elements(rowXml, 'c', true)) {
326
- // Every cell counts toward the deadline, so one row of a million cells cannot outrun it.
327
- if ((++cells & 0xfff) === 0)
328
- within(deadline);
329
- const ref = attr(cell.head, 'r');
330
- const t = attr(cell.head, 't');
331
- const inner = cell.body;
332
- const vStart = inner.indexOf('<v>');
333
- const vEnd = vStart < 0 ? -1 : inner.indexOf('</v>', vStart + 3);
334
- const v = vStart < 0 || vEnd < 0 ? undefined : inner.slice(vStart + 3, vEnd);
335
- let value = '';
336
- if (t === 's')
337
- value = shared[Number(v)] ?? '';
338
- else if (t === 'inlineStr')
339
- value = texts(inner);
340
- else if (t === 'b')
341
- value = v === '1' ? 'true' : 'false';
342
- else if (v !== undefined)
343
- value = xmlText(v);
344
- const idx = ref === null ? row.length : colIndex(ref);
345
- if (idx >= UPLOAD_LIMITS.columns)
346
- throw new UploadError('too_many_columns', `the sheet has more than ${UPLOAD_LIMITS.columns} columns`);
347
- while (row.length < idx)
348
- row.push('');
349
- row[idx] = value;
350
- cellBytes += value.length;
351
- if (cellBytes > UPLOAD_LIMITS.expandedBytes)
352
- throw new UploadError('too_large', `the sheet's values expand past ${UPLOAD_LIMITS.expandedBytes / (1024 * 1024)} MB`);
353
- }
354
- if (row.length > 0 && row.some((c) => c !== ''))
355
- rows.push(row);
356
- if (rows.length > UPLOAD_LIMITS.rows + 1)
357
- throw new UploadError('too_many_rows', `the sheet has more than ${UPLOAD_LIMITS.rows} rows`);
358
- if (rows.length % 1_000 === 0)
359
- within(deadline);
360
- }
361
- within(deadline);
362
- return rows;
363
- }
364
- // ── Rows → a SQLite snapshot ─────────────────────────────────────────────────────────────────
365
- const NUMBER = /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
366
- const DATEISH = /^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
367
59
  /**
368
- * Whether to take the first row as the header. Without the person's choice it must look like one AND
369
- * differ in shape from the data under it (some column whose first cell is a word while its values
370
- * are numbers or dates): an all-text first row could be a record — a name, an email — and column
371
- * names are structure an agent sees. A human's explicit choice (`header=yes|no`) wins.
60
+ * (crew#1724) A `.tmp-*` file in the snapshot store older than this is left by an upload that never finished (the daemon
61
+ * died mid-upload). Twice the upload's deadline: a live upload's files are younger than its deadline, and the margin
62
+ * covers the steps after its last check (storing the snapshot, the cleanup).
63
+ */
64
+ export const STALE_TMP_MS = 2 * UPLOAD_LIMITS.parseMs;
65
+ /** The temporary files an upload writes in the store: its bytes, the snapshot being built and its journals. */
66
+ const TMP_FILE_RE = /^\.tmp-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.(?:upload|sqlite(?:-vacuum)?(?:-journal|-wal|-shm)?)$/;
67
+ /** A `.sqlite` temp's sidecars: its journals, and the rewrite of a stripped copy (`-vacuum`) with its journal. */
68
+ const TMP_SIDECARS = ['-journal', '-wal', '-shm', '-vacuum', '-vacuum-journal'];
69
+ /**
70
+ * The temporary files of the uploads this process is running (codex r1): never swept, however long one has stalled. Only
71
+ * one daemon writes a state home's snapshot store, so these are all the live ones.
372
72
  */
373
- export function detectHeader(rows, choice) {
374
- if (choice !== null)
375
- return choice === 'yes';
376
- const first = rows[0] ?? [];
377
- if (!looksLikeHeader(first) || rows.length < 2)
378
- return false;
379
- const body = rows.slice(1, 201);
380
- return first.some((_c, i) => {
381
- const values = body.map((r) => (r[i] ?? '').trim()).filter((v) => v !== '');
382
- return values.length > 0 && values.every((v) => NUMBER.test(v) || DATEISH.test(v) || /^(true|false)$/i.test(v));
73
+ const liveTmp = new Set();
74
+ /** The sweep running now, if one is: uploads that start while it runs start none of their own (codex r2). */
75
+ let sweeping = null;
76
+ /** Start a sweep of `dir` unless one runs; never awaited by an upload, so it never spends an upload's deadline. */
77
+ function startSweep(dir) {
78
+ if (sweeping !== null)
79
+ return;
80
+ sweeping = sweepStale(dir).finally(() => {
81
+ sweeping = null;
383
82
  });
384
83
  }
84
+ /** TESTS ONLY: resolves once the sweep running now (if any) has finished. */
85
+ export async function sweepSettled() {
86
+ await sweeping;
87
+ }
385
88
  /**
386
- * A column name as people write one: a letter or `_` first, then letters, digits, spaces and a little
387
- * punctuation (`Amount (USD)`, `Q3 %`, `order-id`), at most 64 characters. No `@`, `.`, `:` or `/`:
388
- * an email address, a domain, a URL or a time is a value, never a name.
89
+ * Remove the store's stale `.tmp-*` files (crew#1724), never a live upload's. Housekeeping: a failure is never the
90
+ * upload's. `now`: TESTS ONLY.
389
91
  */
390
- const NAME_LIKE = /^[\p{L}_][\p{L}\p{N}\p{Zs}_\-()%#&]{0,63}$/u;
391
- /** A first row looks like a header when every cell is a distinct column name, none of them data-like. */
392
- export function looksLikeHeader(first) {
393
- if (first.length === 0)
394
- return false;
395
- const seen = new Set();
396
- for (const raw of first) {
397
- const cell = raw.trim();
398
- if (cell === '' || NUMBER.test(cell) || DATEISH.test(cell) || /^(true|false)$/i.test(cell) || !NAME_LIKE.test(cell))
399
- return false;
400
- const k = cell.toLowerCase();
401
- if (seen.has(k))
402
- return false;
403
- seen.add(k);
92
+ export async function sweepStale(dir, now = Date.now()) {
93
+ let names;
94
+ try {
95
+ names = await readdir(dir);
404
96
  }
405
- return true;
406
- }
407
- function columnNames(first, width, header) {
408
- const names = [];
409
- const taken = new Set(); // SQLite compares names case-insensitively
410
- for (let i = 0; i < width; i++) {
411
- let n = header ? (first[i] ?? '').trim().replace(/\s+/g, ' ').slice(0, 56) : '';
412
- if (n === '')
413
- n = `col_${i + 1}`;
414
- let unique = n;
415
- for (let k = 2; taken.has(unique.toLowerCase()); k++)
416
- unique = `${n}_${k}`;
417
- taken.add(unique.toLowerCase());
418
- names.push(unique);
97
+ catch {
98
+ return;
419
99
  }
420
- return names;
421
- }
422
- const INT64_MIN = -(2n ** 63n);
423
- const INT64_MAX = 2n ** 63n - 1n;
424
- function isInt64(v) {
425
- if (!/^[+-]?\d{1,20}$/.test(v))
426
- return false;
427
- const b = BigInt(v);
428
- return b >= INT64_MIN && b <= INT64_MAX;
429
- }
430
- /** INTEGER (stored exactly, as a 64-bit integer), REAL, or TEXT; an integer past int64 makes the column TEXT. */
431
- function inferType(values, deadline) {
432
- let t = null;
433
- let n = 0;
434
- for (const raw of values) {
435
- if ((++n & 0xffff) === 0)
436
- within(deadline);
437
- const v = raw.trim();
438
- if (v === '')
100
+ for (const n of names) {
101
+ if (!TMP_FILE_RE.test(n))
439
102
  continue;
440
- if (/^[+-]?\d+$/.test(v)) {
441
- if (!isInt64(v))
442
- return 'TEXT';
443
- t = t ?? 'INTEGER';
103
+ const p = join(dir, n);
104
+ if (liveTmp.has(p.replace(/(?:-vacuum)?(?:-journal|-wal|-shm)?$/, '')))
105
+ continue;
106
+ try {
107
+ if (now - (await stat(p)).mtimeMs > STALE_TMP_MS)
108
+ await rm(p, { force: true });
109
+ }
110
+ catch {
111
+ // gone already, or not ours to judge now
444
112
  }
445
- else if (NUMBER.test(v) && Number.isFinite(Number(v)))
446
- t = t === 'TEXT' ? 'TEXT' : 'REAL';
447
- else
448
- return 'TEXT';
449
- }
450
- return t ?? 'TEXT';
451
- }
452
- function tableNameFor(filename) {
453
- const base = filename.replace(/^.*[\\/]/, '').replace(/\.[^.]+$/, '').toLowerCase().replace(/[^a-z0-9_]+/g, '_').replace(/^_+|_+$/g, '');
454
- return /^[a-z_]/.test(base) && base.length > 0 ? base.slice(0, 63) : `data${base === '' ? '' : `_${base}`}`.slice(0, 63);
455
- }
456
- /** Write the rows as a new SQLite file at `tmp`, in the snapshot runner (the daemon loads no SQLite library). */
457
- async function writeRowsSnapshot(tmp, table, names, types, rows, deadline) {
458
- within(deadline);
459
- try {
460
- await sqliteCreate(tmp, table, names, types, rows, Math.max(1, deadline - Date.now()));
461
- }
462
- catch (err) {
463
- if (err instanceof SourceQueryError && err.errorClass === 'timeout')
464
- throw tooSlow();
465
- throw unavailable(err) ?? err;
466
113
  }
467
114
  }
468
115
  async function store(tmp, dir) {
@@ -503,7 +150,8 @@ function sqliteAvailable() {
503
150
  }
504
151
  /** The runner's own refusal on a runtime without the authorizer or defensive mode, as the upload's. */
505
152
  function unavailable(err) {
506
- return err instanceof SourceQueryError && /need Node\.js 24\.12/.test(err.message) ? new UploadError('sqlite_unavailable', UNAVAILABLE) : null;
153
+ const message = typeof err === 'string' ? err : err instanceof SourceQueryError ? err.message : '';
154
+ return /need Node\.js 24\.12/.test(message) ? new UploadError('sqlite_unavailable', UNAVAILABLE) : null;
507
155
  }
508
156
  const UNAVAILABLE = 'uploads need Node.js 24.12, 25.1 or later (its built-in SQLite, with the authorizer and defensive mode)';
509
157
  /** `p` with every symlink of its longest existing prefix resolved (the rest does not exist yet). */
@@ -578,17 +226,47 @@ export async function ingestUpload(filename, data, opts = {}) {
578
226
  throw err;
579
227
  });
580
228
  const tmp = join(dir, `.tmp-${randomUUID()}.sqlite`);
229
+ const input = join(dir, `.tmp-${randomUUID()}.upload`);
581
230
  const kind = kindOf(filename, data);
231
+ liveTmp.add(tmp);
232
+ liveTmp.add(input);
233
+ startSweep(dir);
582
234
  try {
583
235
  if (kind === 'sqlite') {
584
236
  if (data.subarray(0, 16).toString('latin1') !== 'SQLite format 3\0')
585
237
  throw new UploadError('bad_sqlite', 'the file is not a SQLite database');
586
238
  await writeFile(tmp, data, { mode: 0o600 });
587
- const inspected = await inspectWithin(tmp, deadline);
588
- const bad = inspected.objects.filter((o) => (o.type !== 'table' && o.type !== 'index') || o.virtual);
589
- if (bad.length > 0) {
590
- throw new UploadError('sqlite_code', `an uploaded .sqlite may hold only tables and indexes; it holds ${bad.map((o) => `${o.virtual ? 'the virtual table' : `the ${o.type}`} ${o.name}`).join(', ')}`);
239
+ let inspected = await inspectWithin(tmp, deadline);
240
+ const code = inspected.objects.filter((o) => o.type !== 'table' && o.type !== 'index');
241
+ if (code.length > 0) {
242
+ throw new UploadError('sqlite_code', `an uploaded .sqlite may hold only tables and indexes; it holds ${code.map((o) => `the ${o.type} ${o.name}`).join(', ')}`);
243
+ }
244
+ // (crew#1731) Virtual tables are dropped from this copy (their shadow tables go with them), then the copy is
245
+ // inspected again: what is left must be plain tables and indexes.
246
+ const dropped = inspected.objects.filter((o) => o.virtual).map((o) => o.name);
247
+ // Every table that belonged to them: one that outlives the drop (a declaration rewritten so the module's destroy
248
+ // skips it) is refused, never kept as a plain table (codex r1).
249
+ const theirs = new Set([...dropped, ...inspected.objects.filter((o) => o.shadow).map((o) => o.name)]);
250
+ // (crew#1787) Every copy is rewritten (VACUUM INTO, in the runner's child), virtual tables or not, so the snapshot
251
+ // holds live pages only: rows or tables the person deleted before the upload never ride in its free pages (or in
252
+ // an image a publish copies it into). A plain file's snapshot is therefore not its bytes, and its digest differs.
253
+ within(deadline);
254
+ let failed;
255
+ try {
256
+ failed = (await sqliteStrip(tmp, `${tmp}-vacuum`, dropped, Math.max(1, deadline - Date.now()))).failed;
591
257
  }
258
+ catch (err) {
259
+ if (err instanceof SourceQueryError && err.errorClass === 'timeout')
260
+ throw tooSlow();
261
+ throw unavailable(err) ?? err;
262
+ }
263
+ if (failed.length > 0) {
264
+ throw new UploadError('sqlite_code', `an uploaded .sqlite may hold only tables and indexes, and crew could not drop ${failed.map((f) => `the virtual table ${f.name} (${f.error})`).join(', ')} from its copy; drop ${failed.length === 1 ? 'it' : 'them'} from a copy of the file (DROP TABLE <name>) and upload that`);
265
+ }
266
+ inspected = await inspectWithin(tmp, deadline);
267
+ const left = inspected.objects.filter((o) => (o.type !== 'table' && o.type !== 'index') || o.virtual || o.shadow || theirs.has(o.name));
268
+ if (left.length > 0)
269
+ throw new UploadError('sqlite_code', `an uploaded .sqlite may hold only tables and indexes; after its virtual tables were dropped it still holds ${left.map((o) => o.name).join(', ')}`);
592
270
  if (inspected.generated.length > 0)
593
271
  throw new UploadError('sqlite_code', `an uploaded .sqlite may not hold generated or hidden columns; it holds ${inspected.generated.join(', ')}`);
594
272
  const total = inspected.catalog.relations.reduce((a, r) => a + (r.rowEstimate ?? 0), 0);
@@ -597,40 +275,50 @@ export async function ingestUpload(filename, data, opts = {}) {
597
275
  if (inspected.catalog.relations.some((r) => r.columns.length > UPLOAD_LIMITS.columns))
598
276
  throw new UploadError('too_many_columns', `a table has more than ${UPLOAD_LIMITS.columns} columns`);
599
277
  const s = await store(tmp, dir);
600
- return { digest: s.digest, bytes: s.bytes, kind, table: null, header: null, sample: [], catalog: (await inspectWithin(s.path, deadline)).catalog };
278
+ return { digest: s.digest, bytes: s.bytes, kind, table: null, header: null, sample: [], dropped, catalog: (await inspectWithin(s.path, deadline)).catalog };
279
+ }
280
+ await writeFile(input, data, { mode: 0o600 });
281
+ within(deadline);
282
+ let ingested;
283
+ try {
284
+ ingested = await sqliteIngest(tmp, input, kind, filename, opts.header ?? null, UPLOAD_LIMITS, Math.max(1, deadline - Date.now()));
285
+ }
286
+ catch (err) {
287
+ if (err instanceof SourceQueryError && err.errorClass === 'timeout')
288
+ throw tooSlow();
289
+ // Only the child's own failure is the file's; a runner that could not start or answered too much passes
290
+ // through as before (crew#1721 coord r1).
291
+ if (isRunnerFailure(err))
292
+ throw unavailable(err) ?? new UploadError('unreadable', 'crew could not read the file (its parser failed)');
293
+ throw unavailable(err) ?? err;
294
+ }
295
+ if (!ingested.ok) {
296
+ if (ingested.refused === true)
297
+ throw new UploadError(ingested.code, ingested.error);
298
+ throw unavailable(ingested.error) ?? new UploadError('unreadable', 'crew could not read the file (its parser failed)');
601
299
  }
602
- const rows = kind === 'xlsx'
603
- ? parseXlsx(data, deadline)
604
- : parseCsv(data.toString('utf8').replace(/^/, ''), deadline);
605
- if (rows.length === 0)
606
- throw new UploadError('empty', 'the file has no rows');
607
- const first = rows[0];
608
- const header = detectHeader(rows, opts.header ?? null);
609
- const width = rows.reduce((w, r) => Math.max(w, r.length), 0);
610
- const names = columnNames(first, width, header);
611
- const body = header ? rows.slice(1) : rows;
612
- if (body.length > UPLOAD_LIMITS.rows)
613
- throw new UploadError('too_many_rows', `the file has more than ${UPLOAD_LIMITS.rows} rows`);
614
- const types = names.map((_n, i) => inferType((function* () {
615
- for (const r of body)
616
- yield r[i] ?? '';
617
- })(), deadline));
618
- const table = tableNameFor(filename);
619
- await writeRowsSnapshot(tmp, table, names, types, body, deadline);
620
300
  const s = await store(tmp, dir);
621
301
  return {
622
302
  digest: s.digest,
623
303
  bytes: s.bytes,
624
304
  kind,
625
- table,
626
- header: { detected: header, columns: names },
627
- sample: body.slice(0, UPLOAD_LIMITS.sampleRows).map((r) => names.map((_n, i) => r[i] ?? '')),
305
+ table: ingested.table,
306
+ header: ingested.header,
307
+ sample: ingested.sample,
308
+ dropped: [],
628
309
  catalog: (await inspectWithin(s.path, deadline)).catalog,
629
310
  };
630
311
  }
631
312
  finally {
632
313
  // The file and any journal a runner ended mid-transaction left beside it.
633
- await Promise.all(['', '-journal', '-wal', '-shm'].map((s) => rm(`${tmp}${s}`, { force: true })));
314
+ try {
315
+ await Promise.all([rm(input, { force: true }), ...['', ...TMP_SIDECARS].map((s) => rm(`${tmp}${s}`, { force: true }))]);
316
+ }
317
+ finally {
318
+ // Not live any more even if a removal failed: the next sweep takes what is left (codex r2).
319
+ liveTmp.delete(tmp);
320
+ liveTmp.delete(input);
321
+ }
634
322
  }
635
323
  }
636
324
  //# sourceMappingURL=uploads.js.map