@dreamlake/dreamlake-cli 0.88.0 → 0.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (535) hide show
  1. package/dist/api/access.d.ts +83 -0
  2. package/dist/api/access.js +77 -0
  3. package/dist/api/agent.d.ts +156 -0
  4. package/dist/api/agent.js +111 -0
  5. package/dist/api/browser.d.ts +90 -0
  6. package/dist/api/browser.js +102 -0
  7. package/dist/api/client.d.ts +53 -0
  8. package/dist/api/client.js +102 -0
  9. package/dist/api/common.d.ts +28 -0
  10. package/dist/api/common.js +16 -0
  11. package/dist/api/content.d.ts +195 -0
  12. package/dist/api/content.js +147 -0
  13. package/dist/api/execution.d.ts +84 -0
  14. package/dist/api/execution.js +73 -0
  15. package/dist/api/http.d.ts +19 -0
  16. package/dist/api/http.js +66 -0
  17. package/dist/api/index.d.ts +2330 -0
  18. package/dist/api/index.js +114 -0
  19. package/dist/api/infra.d.ts +2 -0
  20. package/dist/api/infra.js +2 -0
  21. package/dist/api/jobs.d.ts +2 -0
  22. package/dist/api/jobs.js +2 -0
  23. package/dist/api/layout.d.ts +2 -0
  24. package/dist/api/layout.js +2 -0
  25. package/dist/api/library-edit.d.ts +3 -0
  26. package/dist/api/library-edit.js +3 -0
  27. package/dist/api/library-manifest.d.ts +2 -0
  28. package/dist/api/library-manifest.js +2 -0
  29. package/dist/api/note-character-plan.d.ts +2 -0
  30. package/dist/api/note-character-plan.js +2 -0
  31. package/dist/api/note-editing.d.ts +2 -0
  32. package/dist/api/note-editing.js +2 -0
  33. package/dist/api/note-edits.d.ts +21 -0
  34. package/dist/api/note-edits.js +10 -0
  35. package/dist/api/note-events.d.ts +5 -0
  36. package/dist/api/note-events.js +11 -0
  37. package/dist/api/note-files.d.ts +75 -0
  38. package/dist/api/note-files.js +65 -0
  39. package/dist/api/note-html-read.d.ts +2 -0
  40. package/dist/api/note-html-read.js +2 -0
  41. package/dist/api/note-html.d.ts +2 -0
  42. package/dist/api/note-html.js +2 -0
  43. package/dist/api/note-toc.d.ts +2 -0
  44. package/dist/api/note-toc.js +2 -0
  45. package/dist/api/notes.d.ts +304 -0
  46. package/dist/api/notes.js +181 -0
  47. package/dist/api/open-resources.d.ts +27 -0
  48. package/dist/api/open-resources.js +102 -0
  49. package/dist/api/ownership.d.ts +12 -0
  50. package/dist/api/ownership.js +24 -0
  51. package/dist/api/platform.d.ts +83 -0
  52. package/dist/api/platform.js +56 -0
  53. package/dist/api/presigned-transfer.d.ts +2 -0
  54. package/dist/api/presigned-transfer.js +2 -0
  55. package/dist/api/registered-runs.d.ts +48 -0
  56. package/dist/api/registered-runs.js +33 -0
  57. package/dist/api/sessions.d.ts +299 -0
  58. package/dist/api/sessions.js +105 -0
  59. package/dist/api/storage.d.ts +46 -0
  60. package/dist/api/storage.js +34 -0
  61. package/dist/api/streams.d.ts +18 -0
  62. package/dist/api/streams.js +70 -0
  63. package/dist/api/vault.d.ts +93 -0
  64. package/dist/api/vault.js +79 -0
  65. package/dist/api/workspace.d.ts +180 -0
  66. package/dist/api/workspace.js +146 -0
  67. package/dist/cli/agent-identity.d.ts +4 -0
  68. package/dist/cli/agent-identity.js +21 -0
  69. package/dist/cli/agents/identity.d.ts +50 -0
  70. package/dist/cli/agents/identity.js +105 -0
  71. package/dist/cli/agents/index.d.ts +31 -0
  72. package/dist/cli/agents/index.js +580 -0
  73. package/dist/cli/agents/manage.d.ts +43 -0
  74. package/dist/cli/agents/manage.js +376 -0
  75. package/dist/cli/agents/spec.d.ts +104 -0
  76. package/dist/cli/agents/spec.js +280 -0
  77. package/dist/cli/agents/web.d.ts +7 -0
  78. package/dist/cli/agents/web.js +109 -0
  79. package/dist/cli/artifact/incremental.d.ts +21 -0
  80. package/dist/cli/artifact/incremental.js +80 -0
  81. package/dist/cli/artifact/index.d.ts +52 -0
  82. package/dist/cli/artifact/index.js +405 -0
  83. package/dist/cli/artifact/meta.d.ts +69 -0
  84. package/dist/cli/artifact/meta.js +189 -0
  85. package/dist/cli/auth/commands.d.ts +29 -0
  86. package/dist/cli/auth/commands.js +327 -0
  87. package/dist/cli/auth/constants.d.ts +13 -0
  88. package/dist/cli/auth/constants.js +18 -0
  89. package/dist/cli/auth/credentials.d.ts +37 -0
  90. package/dist/cli/auth/credentials.js +155 -0
  91. package/dist/cli/auth/device-flow.d.ts +32 -0
  92. package/dist/cli/auth/device-flow.js +154 -0
  93. package/dist/cli/auth/device-secret.d.ts +6 -0
  94. package/dist/cli/auth/device-secret.js +26 -0
  95. package/dist/cli/auth/machine.d.ts +15 -0
  96. package/dist/cli/auth/machine.js +126 -0
  97. package/dist/cli/auth/materialized.d.ts +32 -0
  98. package/dist/cli/auth/materialized.js +102 -0
  99. package/dist/cli/auth/migrate.d.ts +10 -0
  100. package/dist/cli/auth/migrate.js +75 -0
  101. package/dist/cli/client.d.ts +102 -0
  102. package/dist/cli/client.js +206 -0
  103. package/dist/cli/collection-list.d.ts +3 -0
  104. package/dist/cli/collection-list.js +25 -0
  105. package/dist/cli/compat/ctx.d.ts +26 -0
  106. package/dist/cli/compat/ctx.js +76 -0
  107. package/dist/cli/compat/dreamdb-wasm-embedded.d.ts +2 -0
  108. package/dist/cli/compat/dreamdb-wasm-embedded.js +8 -0
  109. package/dist/cli/compat/dreamdb-wasm.d.ts +1 -0
  110. package/dist/cli/compat/dreamdb-wasm.js +26 -0
  111. package/dist/cli/compat/dreamdb.d.ts +112 -0
  112. package/dist/cli/compat/dreamdb.js +219 -0
  113. package/dist/cli/compat/flags.d.ts +2 -0
  114. package/dist/cli/compat/flags.js +13 -0
  115. package/dist/cli/compat/http.d.ts +23 -0
  116. package/dist/cli/compat/http.js +137 -0
  117. package/dist/cli/compat/presignedTransfer.d.ts +139 -0
  118. package/dist/cli/compat/presignedTransfer.js +580 -0
  119. package/dist/cli/compat/s3-backend.d.ts +73 -0
  120. package/dist/cli/compat/s3-backend.js +132 -0
  121. package/dist/cli/config.d.ts +22 -0
  122. package/dist/cli/config.js +96 -0
  123. package/dist/cli/connection/dto.d.ts +159 -0
  124. package/dist/cli/connection/dto.js +497 -0
  125. package/dist/cli/connection/index.d.ts +50 -0
  126. package/dist/cli/connection/index.js +413 -0
  127. package/dist/cli/connection/oauth.d.ts +23 -0
  128. package/dist/cli/connection/oauth.js +290 -0
  129. package/dist/cli/connection/write.d.ts +47 -0
  130. package/dist/cli/connection/write.js +573 -0
  131. package/dist/cli/create/index.d.ts +19 -0
  132. package/dist/cli/create/index.js +209 -0
  133. package/dist/cli/declare/index.d.ts +29 -0
  134. package/dist/cli/declare/index.js +304 -0
  135. package/dist/cli/delete/index.d.ts +18 -0
  136. package/dist/cli/delete/index.js +232 -0
  137. package/dist/cli/download/index.d.ts +9 -0
  138. package/dist/cli/download/index.js +128 -0
  139. package/dist/cli/env/compose.d.ts +88 -0
  140. package/dist/cli/env/compose.js +402 -0
  141. package/dist/cli/env/index.d.ts +176 -0
  142. package/dist/cli/env/index.js +1011 -0
  143. package/dist/cli/experiments/index.d.ts +11 -0
  144. package/dist/cli/experiments/index.js +168 -0
  145. package/dist/cli/glob.d.ts +1 -0
  146. package/dist/cli/glob.js +45 -0
  147. package/dist/cli/graphql-helpers.d.ts +23 -0
  148. package/dist/cli/graphql-helpers.js +42 -0
  149. package/dist/cli/graphql.d.ts +10 -0
  150. package/dist/cli/graphql.js +47 -0
  151. package/dist/cli/help-examples.generated.d.ts +1 -0
  152. package/dist/cli/help-examples.generated.js +192 -0
  153. package/dist/cli/helpers.d.ts +8 -0
  154. package/dist/cli/helpers.js +106 -0
  155. package/dist/cli/hosts/api.d.ts +29 -0
  156. package/dist/cli/hosts/api.js +54 -0
  157. package/dist/cli/hosts/bootstrap-source.d.ts +1 -0
  158. package/dist/cli/hosts/bootstrap-source.js +2 -0
  159. package/dist/cli/hosts/catalog.d.ts +26 -0
  160. package/dist/cli/hosts/catalog.js +55 -0
  161. package/dist/cli/hosts/config.d.ts +45 -0
  162. package/dist/cli/hosts/config.js +179 -0
  163. package/dist/cli/hosts/credentials.d.ts +19 -0
  164. package/dist/cli/hosts/credentials.js +173 -0
  165. package/dist/cli/hosts/enroll.d.ts +17 -0
  166. package/dist/cli/hosts/enroll.js +109 -0
  167. package/dist/cli/hosts/enrollments.d.ts +25 -0
  168. package/dist/cli/hosts/enrollments.js +54 -0
  169. package/dist/cli/hosts/index.d.ts +6 -0
  170. package/dist/cli/hosts/index.js +279 -0
  171. package/dist/cli/hosts/inventory.d.ts +40 -0
  172. package/dist/cli/hosts/inventory.js +91 -0
  173. package/dist/cli/hosts/lifecycle.d.ts +15 -0
  174. package/dist/cli/hosts/lifecycle.js +108 -0
  175. package/dist/cli/hosts/metrics-source.d.ts +12 -0
  176. package/dist/cli/hosts/metrics-source.js +89 -0
  177. package/dist/cli/hosts/observations.d.ts +39 -0
  178. package/dist/cli/hosts/observations.js +102 -0
  179. package/dist/cli/hosts/remote.d.ts +5 -0
  180. package/dist/cli/hosts/remote.js +66 -0
  181. package/dist/cli/hosts/ssh.d.ts +63 -0
  182. package/dist/cli/hosts/ssh.js +276 -0
  183. package/dist/cli/index.d.ts +1 -0
  184. package/dist/cli/index.js +288 -0
  185. package/dist/cli/infra/api.d.ts +95 -0
  186. package/dist/cli/infra/api.js +291 -0
  187. package/dist/cli/infra/index.d.ts +5 -0
  188. package/dist/cli/infra/index.js +102 -0
  189. package/dist/cli/infra/move.d.ts +15 -0
  190. package/dist/cli/infra/move.js +123 -0
  191. package/dist/cli/infra/transfer.d.ts +15 -0
  192. package/dist/cli/infra/transfer.js +280 -0
  193. package/dist/cli/jobs/api.d.ts +69 -0
  194. package/dist/cli/jobs/api.js +121 -0
  195. package/dist/cli/jobs/index.d.ts +5 -0
  196. package/dist/cli/jobs/index.js +140 -0
  197. package/dist/cli/lakeshore/index.d.ts +98 -0
  198. package/dist/cli/lakeshore/index.js +502 -0
  199. package/dist/cli/launch/index.d.ts +43 -0
  200. package/dist/cli/launch/index.js +270 -0
  201. package/dist/cli/layout/index.d.ts +2 -0
  202. package/dist/cli/layout/index.js +44 -0
  203. package/dist/cli/layout/transport.d.ts +12 -0
  204. package/dist/cli/layout/transport.js +70 -0
  205. package/dist/cli/library/add.d.ts +60 -0
  206. package/dist/cli/library/add.js +348 -0
  207. package/dist/cli/library/cache.d.ts +26 -0
  208. package/dist/cli/library/cache.js +88 -0
  209. package/dist/cli/library/config.d.ts +75 -0
  210. package/dist/cli/library/config.js +198 -0
  211. package/dist/cli/library/digest.d.ts +5 -0
  212. package/dist/cli/library/digest.js +19 -0
  213. package/dist/cli/library/discover.d.ts +87 -0
  214. package/dist/cli/library/discover.js +534 -0
  215. package/dist/cli/library/freshness.d.ts +35 -0
  216. package/dist/cli/library/freshness.js +109 -0
  217. package/dist/cli/library/generation.d.ts +35 -0
  218. package/dist/cli/library/generation.js +211 -0
  219. package/dist/cli/library/index.d.ts +2 -0
  220. package/dist/cli/library/index.js +36 -0
  221. package/dist/cli/library/info.d.ts +69 -0
  222. package/dist/cli/library/info.js +311 -0
  223. package/dist/cli/library/list.d.ts +33 -0
  224. package/dist/cli/library/list.js +86 -0
  225. package/dist/cli/library/manifest.d.ts +81 -0
  226. package/dist/cli/library/manifest.js +200 -0
  227. package/dist/cli/library/manifestCache.d.ts +45 -0
  228. package/dist/cli/library/manifestCache.js +169 -0
  229. package/dist/cli/library/pull.d.ts +30 -0
  230. package/dist/cli/library/pull.js +438 -0
  231. package/dist/cli/library/push.d.ts +72 -0
  232. package/dist/cli/library/push.js +642 -0
  233. package/dist/cli/library/rm.d.ts +31 -0
  234. package/dist/cli/library/rm.js +200 -0
  235. package/dist/cli/library/search.d.ts +18 -0
  236. package/dist/cli/library/search.js +181 -0
  237. package/dist/cli/library/stat.d.ts +15 -0
  238. package/dist/cli/library/stat.js +127 -0
  239. package/dist/cli/library/tools.d.ts +104 -0
  240. package/dist/cli/library/tools.js +163 -0
  241. package/dist/cli/library/wire.d.ts +47 -0
  242. package/dist/cli/library/wire.js +120 -0
  243. package/dist/cli/list/index.d.ts +26 -0
  244. package/dist/cli/list/index.js +256 -0
  245. package/dist/cli/notes/character-plan.d.ts +22 -0
  246. package/dist/cli/notes/character-plan.js +232 -0
  247. package/dist/cli/notes/document.d.ts +73 -0
  248. package/dist/cli/notes/document.js +306 -0
  249. package/dist/cli/notes/edit-commands.d.ts +106 -0
  250. package/dist/cli/notes/edit-commands.js +623 -0
  251. package/dist/cli/notes/editing.d.ts +81 -0
  252. package/dist/cli/notes/editing.js +305 -0
  253. package/dist/cli/notes/events.d.ts +36 -0
  254. package/dist/cli/notes/events.js +54 -0
  255. package/dist/cli/notes/files-commands.d.ts +120 -0
  256. package/dist/cli/notes/files-commands.js +554 -0
  257. package/dist/cli/notes/html-read.d.ts +9 -0
  258. package/dist/cli/notes/html-read.js +90 -0
  259. package/dist/cli/notes/html.d.ts +73 -0
  260. package/dist/cli/notes/html.js +381 -0
  261. package/dist/cli/notes/index.d.ts +123 -0
  262. package/dist/cli/notes/index.js +1303 -0
  263. package/dist/cli/notes/linger.d.ts +59 -0
  264. package/dist/cli/notes/linger.js +339 -0
  265. package/dist/cli/notes/media-commands.d.ts +5 -0
  266. package/dist/cli/notes/media-commands.js +51 -0
  267. package/dist/cli/notes/move-command.d.ts +83 -0
  268. package/dist/cli/notes/move-command.js +259 -0
  269. package/dist/cli/notes/rm-command.d.ts +22 -0
  270. package/dist/cli/notes/rm-command.js +110 -0
  271. package/dist/cli/notes/select-command.d.ts +12 -0
  272. package/dist/cli/notes/select-command.js +84 -0
  273. package/dist/cli/notes/suggest-diff.d.ts +56 -0
  274. package/dist/cli/notes/suggest-diff.js +311 -0
  275. package/dist/cli/notes/toc.d.ts +38 -0
  276. package/dist/cli/notes/toc.js +144 -0
  277. package/dist/cli/notes/transfer-command.d.ts +6 -0
  278. package/dist/cli/notes/transfer-command.js +9 -0
  279. package/dist/cli/notes/version-commands.d.ts +19 -0
  280. package/dist/cli/notes/version-commands.js +178 -0
  281. package/dist/cli/nymph/index.d.ts +74 -0
  282. package/dist/cli/nymph/index.js +349 -0
  283. package/dist/cli/org/index.d.ts +34 -0
  284. package/dist/cli/org/index.js +341 -0
  285. package/dist/cli/ownership/index.d.ts +12 -0
  286. package/dist/cli/ownership/index.js +122 -0
  287. package/dist/cli/ownership/metadata-transfer.d.ts +20 -0
  288. package/dist/cli/ownership/metadata-transfer.js +159 -0
  289. package/dist/cli/page/index.d.ts +58 -0
  290. package/dist/cli/page/index.js +387 -0
  291. package/dist/cli/pipeline/index.d.ts +69 -0
  292. package/dist/cli/pipeline/index.js +604 -0
  293. package/dist/cli/progress.d.ts +60 -0
  294. package/dist/cli/progress.js +276 -0
  295. package/dist/cli/project/attachments.d.ts +10 -0
  296. package/dist/cli/project/attachments.js +39 -0
  297. package/dist/cli/project/grants.d.ts +10 -0
  298. package/dist/cli/project/grants.js +39 -0
  299. package/dist/cli/project/index.d.ts +8 -0
  300. package/dist/cli/project/index.js +92 -0
  301. package/dist/cli/project/move.d.ts +57 -0
  302. package/dist/cli/project/move.js +242 -0
  303. package/dist/cli/project/output.d.ts +2 -0
  304. package/dist/cli/project/output.js +29 -0
  305. package/dist/cli/project/stream.d.ts +55 -0
  306. package/dist/cli/project/stream.js +207 -0
  307. package/dist/cli/project/transfer-preview.d.ts +8 -0
  308. package/dist/cli/project/transfer-preview.js +10 -0
  309. package/dist/cli/prompt.d.ts +1 -0
  310. package/dist/cli/prompt.js +17 -0
  311. package/dist/cli/provider/dreamdir.d.ts +52 -0
  312. package/dist/cli/provider/dreamdir.js +138 -0
  313. package/dist/cli/provider/index.d.ts +4 -0
  314. package/dist/cli/provider/index.js +419 -0
  315. package/dist/cli/provider/jump-worker.d.ts +9 -0
  316. package/dist/cli/provider/jump-worker.js +141 -0
  317. package/dist/cli/provider/lifecycle.d.ts +149 -0
  318. package/dist/cli/provider/lifecycle.js +1390 -0
  319. package/dist/cli/provider/machine.d.ts +17 -0
  320. package/dist/cli/provider/machine.js +116 -0
  321. package/dist/cli/provider/ssh.d.ts +105 -0
  322. package/dist/cli/provider/ssh.js +305 -0
  323. package/dist/cli/provider/terraform.d.ts +140 -0
  324. package/dist/cli/provider/terraform.js +288 -0
  325. package/dist/cli/providers/index.d.ts +18 -0
  326. package/dist/cli/providers/index.js +422 -0
  327. package/dist/cli/python.d.ts +61 -0
  328. package/dist/cli/python.js +255 -0
  329. package/dist/cli/queues/index.d.ts +33 -0
  330. package/dist/cli/queues/index.js +248 -0
  331. package/dist/cli/queues/slurm.d.ts +10 -0
  332. package/dist/cli/queues/slurm.js +134 -0
  333. package/dist/cli/resources.d.ts +72 -0
  334. package/dist/cli/resources.js +137 -0
  335. package/dist/cli/run/index.d.ts +15 -0
  336. package/dist/cli/run/index.js +163 -0
  337. package/dist/cli/run/input.d.ts +34 -0
  338. package/dist/cli/run/input.js +135 -0
  339. package/dist/cli/run/recovery.d.ts +2 -0
  340. package/dist/cli/run/recovery.js +18 -0
  341. package/dist/cli/run/setup.d.ts +3 -0
  342. package/dist/cli/run/setup.js +62 -0
  343. package/dist/cli/runconfig/index.d.ts +12 -0
  344. package/dist/cli/runconfig/index.js +130 -0
  345. package/dist/cli/runnable/index.d.ts +35 -0
  346. package/dist/cli/runnable/index.js +575 -0
  347. package/dist/cli/runnable/path.d.ts +115 -0
  348. package/dist/cli/runnable/path.js +288 -0
  349. package/dist/cli/runnable/run.d.ts +91 -0
  350. package/dist/cli/runnable/run.js +239 -0
  351. package/dist/cli/runnable/upload.d.ts +43 -0
  352. package/dist/cli/runnable/upload.js +342 -0
  353. package/dist/cli/runnable/worker.d.ts +1 -0
  354. package/dist/cli/runnable/worker.js +44 -0
  355. package/dist/cli/schemas/workflow-spec.schema.json +335 -0
  356. package/dist/cli/self-update/index.d.ts +5 -0
  357. package/dist/cli/self-update/index.js +107 -0
  358. package/dist/cli/self-update/install.d.ts +60 -0
  359. package/dist/cli/self-update/install.js +428 -0
  360. package/dist/cli/self-update/paths.d.ts +40 -0
  361. package/dist/cli/self-update/paths.js +87 -0
  362. package/dist/cli/self-update/releases.d.ts +41 -0
  363. package/dist/cli/self-update/releases.js +153 -0
  364. package/dist/cli/self-update/settings.d.ts +16 -0
  365. package/dist/cli/self-update/settings.js +68 -0
  366. package/dist/cli/self-update/update.d.ts +18 -0
  367. package/dist/cli/self-update/update.js +241 -0
  368. package/dist/cli/service-accounts/index.d.ts +3 -0
  369. package/dist/cli/service-accounts/index.js +149 -0
  370. package/dist/cli/session-affiliation.d.ts +26 -0
  371. package/dist/cli/session-affiliation.js +135 -0
  372. package/dist/cli/sessions/affiliation.d.ts +8 -0
  373. package/dist/cli/sessions/affiliation.js +66 -0
  374. package/dist/cli/sessions/api.d.ts +55 -0
  375. package/dist/cli/sessions/api.js +88 -0
  376. package/dist/cli/sessions/control.d.ts +6 -0
  377. package/dist/cli/sessions/control.js +159 -0
  378. package/dist/cli/sessions/conversation.d.ts +15 -0
  379. package/dist/cli/sessions/conversation.js +118 -0
  380. package/dist/cli/sessions/index.d.ts +2 -0
  381. package/dist/cli/sessions/index.js +209 -0
  382. package/dist/cli/sessions/managed.d.ts +39 -0
  383. package/dist/cli/sessions/managed.js +63 -0
  384. package/dist/cli/sessions/redaction.d.ts +2 -0
  385. package/dist/cli/sessions/redaction.js +11 -0
  386. package/dist/cli/sessions/runner/exec.d.ts +108 -0
  387. package/dist/cli/sessions/runner/exec.js +335 -0
  388. package/dist/cli/sessions/runner/journal.d.ts +26 -0
  389. package/dist/cli/sessions/runner/journal.js +49 -0
  390. package/dist/cli/sessions/runner/native.d.ts +48 -0
  391. package/dist/cli/sessions/runner/native.js +170 -0
  392. package/dist/cli/sessions/runner/pod.d.ts +30 -0
  393. package/dist/cli/sessions/runner/pod.js +129 -0
  394. package/dist/cli/sessions/runner/serve.d.ts +85 -0
  395. package/dist/cli/sessions/runner/serve.js +558 -0
  396. package/dist/cli/sessions/sync.d.ts +47 -0
  397. package/dist/cli/sessions/sync.js +80 -0
  398. package/dist/cli/sessions/transport.d.ts +14 -0
  399. package/dist/cli/sessions/transport.js +116 -0
  400. package/dist/cli/share.d.ts +15 -0
  401. package/dist/cli/share.js +139 -0
  402. package/dist/cli/skill/catalog.d.ts +141 -0
  403. package/dist/cli/skill/catalog.js +442 -0
  404. package/dist/cli/skill/files.d.ts +89 -0
  405. package/dist/cli/skill/files.js +264 -0
  406. package/dist/cli/skill/index.d.ts +268 -0
  407. package/dist/cli/skill/index.js +1216 -0
  408. package/dist/cli/skill/manifest.d.ts +30 -0
  409. package/dist/cli/skill/manifest.js +101 -0
  410. package/dist/cli/skill/prefs.d.ts +9 -0
  411. package/dist/cli/skill/prefs.js +32 -0
  412. package/dist/cli/skill/reminders.d.ts +15 -0
  413. package/dist/cli/skill/reminders.js +105 -0
  414. package/dist/cli/skill/tar.d.ts +17 -0
  415. package/dist/cli/skill/tar.js +195 -0
  416. package/dist/cli/snapshot/index.d.ts +24 -0
  417. package/dist/cli/snapshot/index.js +146 -0
  418. package/dist/cli/source/access.d.ts +45 -0
  419. package/dist/cli/source/access.js +563 -0
  420. package/dist/cli/source/control.d.ts +103 -0
  421. package/dist/cli/source/control.js +546 -0
  422. package/dist/cli/source/delete.d.ts +89 -0
  423. package/dist/cli/source/delete.js +463 -0
  424. package/dist/cli/source/index.d.ts +288 -0
  425. package/dist/cli/source/index.js +1348 -0
  426. package/dist/cli/source/share.d.ts +65 -0
  427. package/dist/cli/source/share.js +530 -0
  428. package/dist/cli/source/upload.d.ts +62 -0
  429. package/dist/cli/source/upload.js +258 -0
  430. package/dist/cli/source/write.d.ts +77 -0
  431. package/dist/cli/source/write.js +335 -0
  432. package/dist/cli/spawn.d.ts +28 -0
  433. package/dist/cli/spawn.js +81 -0
  434. package/dist/cli/target.d.ts +22 -0
  435. package/dist/cli/target.js +85 -0
  436. package/dist/cli/tasks/index.d.ts +38 -0
  437. package/dist/cli/tasks/index.js +365 -0
  438. package/dist/cli/team/index.d.ts +37 -0
  439. package/dist/cli/team/index.js +407 -0
  440. package/dist/cli/telemetry.d.ts +23 -0
  441. package/dist/cli/telemetry.js +262 -0
  442. package/dist/cli/telemetryJournal.d.ts +26 -0
  443. package/dist/cli/telemetryJournal.js +104 -0
  444. package/dist/cli/update/index.d.ts +21 -0
  445. package/dist/cli/update/index.js +284 -0
  446. package/dist/cli/upload/index.d.ts +11 -0
  447. package/dist/cli/upload/index.js +261 -0
  448. package/dist/cli/upload/kinds.d.ts +10 -0
  449. package/dist/cli/upload/kinds.js +85 -0
  450. package/dist/cli/upload/multipart.d.ts +21 -0
  451. package/dist/cli/upload/multipart.js +248 -0
  452. package/dist/cli/vault/affected-preview.d.ts +15 -0
  453. package/dist/cli/vault/affected-preview.js +38 -0
  454. package/dist/cli/vault/cloud.d.ts +55 -0
  455. package/dist/cli/vault/cloud.js +287 -0
  456. package/dist/cli/vault/format.d.ts +18 -0
  457. package/dist/cli/vault/format.js +104 -0
  458. package/dist/cli/vault/hostCredentials.d.ts +21 -0
  459. package/dist/cli/vault/hostCredentials.js +71 -0
  460. package/dist/cli/vault/hostSupersessions.d.ts +18 -0
  461. package/dist/cli/vault/hostSupersessions.js +68 -0
  462. package/dist/cli/vault/import.d.ts +3 -0
  463. package/dist/cli/vault/import.js +79 -0
  464. package/dist/cli/vault/index.d.ts +14 -0
  465. package/dist/cli/vault/index.js +225 -0
  466. package/dist/cli/vault/keys.d.ts +5 -0
  467. package/dist/cli/vault/keys.js +165 -0
  468. package/dist/cli/vault/kms.d.ts +6 -0
  469. package/dist/cli/vault/kms.js +169 -0
  470. package/dist/cli/vault/list.d.ts +13 -0
  471. package/dist/cli/vault/list.js +60 -0
  472. package/dist/cli/vault/listView.d.ts +21 -0
  473. package/dist/cli/vault/listView.js +123 -0
  474. package/dist/cli/vault/managementMetadata.d.ts +2 -0
  475. package/dist/cli/vault/managementMetadata.js +23 -0
  476. package/dist/cli/vault/mutations.d.ts +8 -0
  477. package/dist/cli/vault/mutations.js +151 -0
  478. package/dist/cli/vault/otp.d.ts +6 -0
  479. package/dist/cli/vault/otp.js +62 -0
  480. package/dist/cli/vault/otpIntent.d.ts +23 -0
  481. package/dist/cli/vault/otpIntent.js +76 -0
  482. package/dist/cli/vault/passImport.d.ts +25 -0
  483. package/dist/cli/vault/passImport.js +129 -0
  484. package/dist/cli/vault/passOtp.d.ts +51 -0
  485. package/dist/cli/vault/passOtp.js +101 -0
  486. package/dist/cli/vault/passStore.d.ts +26 -0
  487. package/dist/cli/vault/passStore.js +134 -0
  488. package/dist/cli/vault/passwordCommand.d.ts +39 -0
  489. package/dist/cli/vault/passwordCommand.js +101 -0
  490. package/dist/cli/vault/passwordProbe.d.ts +27 -0
  491. package/dist/cli/vault/passwordProbe.js +282 -0
  492. package/dist/cli/vault/passwordRotation.d.ts +9 -0
  493. package/dist/cli/vault/passwordRotation.js +273 -0
  494. package/dist/cli/vault/rotationApi.d.ts +13 -0
  495. package/dist/cli/vault/rotationApi.js +58 -0
  496. package/dist/cli/vault/rotationCommand.d.ts +2 -0
  497. package/dist/cli/vault/rotationCommand.js +75 -0
  498. package/dist/cli/vault/rotationEngine.d.ts +19 -0
  499. package/dist/cli/vault/rotationEngine.js +65 -0
  500. package/dist/cli/vault/rotationHelperSource.d.ts +2 -0
  501. package/dist/cli/vault/rotationHelperSource.js +3 -0
  502. package/dist/cli/vault/rotationInput.d.ts +11 -0
  503. package/dist/cli/vault/rotationInput.js +48 -0
  504. package/dist/cli/vault/rotationJournal.d.ts +16 -0
  505. package/dist/cli/vault/rotationJournal.js +183 -0
  506. package/dist/cli/vault/rotationKeys.d.ts +4 -0
  507. package/dist/cli/vault/rotationKeys.js +48 -0
  508. package/dist/cli/vault/rotationPrepare.d.ts +17 -0
  509. package/dist/cli/vault/rotationPrepare.js +108 -0
  510. package/dist/cli/vault/rotationRemote.d.ts +33 -0
  511. package/dist/cli/vault/rotationRemote.js +156 -0
  512. package/dist/cli/vault/rotationState.d.ts +42 -0
  513. package/dist/cli/vault/rotationState.js +115 -0
  514. package/dist/cli/vault/rotationTransport.d.ts +18 -0
  515. package/dist/cli/vault/rotationTransport.js +71 -0
  516. package/dist/cli/vault/sshSource.d.ts +18 -0
  517. package/dist/cli/vault/sshSource.js +196 -0
  518. package/dist/cli/vault/sshSync.d.ts +17 -0
  519. package/dist/cli/vault/sshSync.js +224 -0
  520. package/dist/cli/vault/sshTransfer.d.ts +22 -0
  521. package/dist/cli/vault/sshTransfer.js +140 -0
  522. package/dist/cli/vault/terraformState.d.ts +66 -0
  523. package/dist/cli/vault/terraformState.js +252 -0
  524. package/dist/cli/vault/terraformStateCommand.d.ts +2 -0
  525. package/dist/cli/vault/terraformStateCommand.js +61 -0
  526. package/dist/cli/vault/tree.d.ts +43 -0
  527. package/dist/cli/vault/tree.js +292 -0
  528. package/dist/cli/version.d.ts +1 -0
  529. package/dist/cli/version.js +9 -0
  530. package/dist/cli/workflow/index.d.ts +76 -0
  531. package/dist/cli/workflow/index.js +826 -0
  532. package/dist/cli/workflow/validate.d.ts +19 -0
  533. package/dist/cli/workflow/validate.js +353 -0
  534. package/dist/package.json +1 -0
  535. package/package.json +28 -10
@@ -0,0 +1,232 @@
1
+ export const PATCH_LIMITS = Object.freeze({
2
+ maxSourceCodePoints: 1_000_000,
3
+ maxPatchBytes: 8_000_000,
4
+ maxHunks: 10_000,
5
+ maxEdits: 10_000,
6
+ maxDiffCells: 4_000_000,
7
+ maxTraceCells: 250_000,
8
+ });
9
+ export class NotePatchError extends Error {
10
+ code;
11
+ constructor(message, code = 'INVALID_PATCH') {
12
+ super(message);
13
+ this.code = code;
14
+ this.name = 'NotePatchError';
15
+ }
16
+ }
17
+ function invalid(message) { throw new NotePatchError(message); }
18
+ function limit(condition, message) {
19
+ if (condition)
20
+ throw new NotePatchError(message, 'LIMIT_EXCEEDED');
21
+ }
22
+ function checkText(text) {
23
+ if (typeof text !== 'string')
24
+ invalid('Source must be a string');
25
+ limit(text.length > PATCH_LIMITS.maxSourceCodePoints * 2, 'Source too large');
26
+ // Lone surrogates cannot round-trip through UTF-8 hashes or RTC wire encoding.
27
+ if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(text))
28
+ invalid('Unpaired Unicode surrogate');
29
+ }
30
+ function points(text) {
31
+ checkText(text);
32
+ const result = Array.from(text);
33
+ limit(result.length > PATCH_LIMITS.maxSourceCodePoints, 'Source too large');
34
+ return result;
35
+ }
36
+ export function characterDiff(base, target, offset = 0, budget = { cells: 0 }) {
37
+ const a = points(base), b = points(target);
38
+ let prefix = 0;
39
+ while (prefix < a.length && prefix < b.length && a[prefix] === b[prefix])
40
+ prefix++;
41
+ let aEnd = a.length, bEnd = b.length;
42
+ while (aEnd > prefix && bEnd > prefix && a[aEnd - 1] === b[bEnd - 1]) {
43
+ aEnd--;
44
+ bEnd--;
45
+ }
46
+ const n = aEnd - prefix, m = bEnd - prefix;
47
+ if (!n && !m)
48
+ return [];
49
+ if (!n || !m)
50
+ return [{ start: offset + prefix, end: offset + aEnd, expectedText: a.slice(prefix, aEnd).join(''), replacementText: b.slice(prefix, bEnd).join('') }];
51
+ if ((n + 1) * (m + 1) > PATCH_LIMITS.maxDiffCells - budget.cells) {
52
+ const left = a.slice(prefix, aEnd), right = b.slice(prefix, bEnd);
53
+ try {
54
+ return sparseCharacterDiff(left, right, offset + prefix, budget);
55
+ }
56
+ catch (error) {
57
+ if (!(error instanceof NotePatchError) || error.message !== 'Character alignment trace limit exceeded')
58
+ throw error;
59
+ return packedCharacterDiff(left, right, offset + prefix, budget);
60
+ }
61
+ }
62
+ budget.cells += (n + 1) * (m + 1);
63
+ limit(budget.cells > PATCH_LIMITS.maxDiffCells, 'Character alignment work limit exceeded');
64
+ const width = m + 1, table = new Uint32Array((n + 1) * width);
65
+ for (let i = n - 1; i >= 0; i--)
66
+ for (let j = m - 1; j >= 0; j--) {
67
+ table[i * width + j] = a[prefix + i] === b[prefix + j]
68
+ ? 1 + table[(i + 1) * width + j + 1]
69
+ : Math.max(table[(i + 1) * width + j], table[i * width + j + 1]);
70
+ }
71
+ const edits = [];
72
+ let i = 0, j = 0, active;
73
+ const flush = () => { if (active) {
74
+ edits.push(active);
75
+ active = undefined;
76
+ } };
77
+ while (i < n || j < m) {
78
+ if (i < n && j < m && a[prefix + i] === b[prefix + j]) {
79
+ flush();
80
+ i++;
81
+ j++;
82
+ continue;
83
+ }
84
+ active ??= { start: offset + prefix + i, end: offset + prefix + i, expectedText: '', replacementText: '' };
85
+ if (i < n && (j === m || table[(i + 1) * width + j] >= table[i * width + j + 1])) {
86
+ active.expectedText += a[prefix + i++];
87
+ active.end++;
88
+ }
89
+ else
90
+ active.replacementText += b[prefix + j++];
91
+ }
92
+ flush();
93
+ limit(edits.length > PATCH_LIMITS.maxEdits, 'Too many edits');
94
+ return edits;
95
+ }
96
+ /** Exact suffix LCS rows, packed into bits, for dense regions that exhaust Myers
97
+ * history. A bit marks an increase between adjacent LCS columns. Trace capacity
98
+ * counts retained 64-bit words; work counts each primitive's affected words.
99
+ * Reconstruction uses the same equality-first/deletion-first rules as the table.
100
+ */
101
+ function packedCharacterDiff(a, b, offset, budget) {
102
+ const words = Math.ceil(b.length / 64);
103
+ const alphabet = new Set(b);
104
+ // Include masks, all suffix rows, and temporary vectors before allocating them.
105
+ limit((a.length + 1 + alphabet.size + 10) * words > PATCH_LIMITS.maxTraceCells, 'Character alignment trace limit exceeded');
106
+ const spend = (cells) => limit((budget.cells += cells) > PATCH_LIMITS.maxDiffCells, 'Character alignment work limit exceeded');
107
+ const masks = new Map();
108
+ for (let j = 0; j < b.length; j++) {
109
+ spend(words * 2);
110
+ masks.set(b[j], (masks.get(b[j]) ?? 0n) | (1n << BigInt(b.length - 1 - j)));
111
+ }
112
+ const rows = new Array(a.length + 1);
113
+ rows[a.length] = 0n;
114
+ for (let i = a.length - 1; i >= 0; i--) {
115
+ spend(words * 7);
116
+ const previous = rows[i + 1], matches = previous | (masks.get(a[i]) ?? 0n);
117
+ rows[i] = matches & ~(matches - ((previous << 1n) | 1n));
118
+ }
119
+ const rank = (row, length) => {
120
+ // Hexadecimal chunks avoid a per-bit scan or an unbounded popcount loop.
121
+ spend(Math.ceil(length / 64) * 3);
122
+ const hex = (row & ((1n << BigInt(length)) - 1n)).toString(16);
123
+ let count = 0;
124
+ for (let end = hex.length; end > 0; end -= 8) {
125
+ spend(1);
126
+ let value = Number.parseInt(hex.slice(Math.max(0, end - 8), end), 16);
127
+ value -= (value >>> 1) & 0x55555555;
128
+ value = (value & 0x33333333) + ((value >>> 2) & 0x33333333);
129
+ count += (((value + (value >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
130
+ }
131
+ return count;
132
+ };
133
+ const edits = [];
134
+ let i = 0, j = 0, remaining = rank(rows[0], b.length), active;
135
+ const flush = () => { if (active) {
136
+ edits.push(active);
137
+ active = undefined;
138
+ } };
139
+ while (i < a.length || j < b.length) {
140
+ spend(1);
141
+ if (i < a.length && j < b.length && a[i] === b[j]) {
142
+ flush();
143
+ i++;
144
+ j++;
145
+ remaining--;
146
+ continue;
147
+ }
148
+ active ??= { start: offset + i, end: offset + i, expectedText: '', replacementText: '' };
149
+ if (i < a.length && (j === b.length || rank(rows[i + 1], b.length - j) === remaining)) {
150
+ active.expectedText += a[i++];
151
+ active.end++;
152
+ }
153
+ else
154
+ active.replacementText += b[j++];
155
+ }
156
+ flush();
157
+ limit(edits.length > PATCH_LIMITS.maxEdits, 'Too many edits');
158
+ return edits;
159
+ }
160
+ /** Bounded Myers frontier for long sparse changes; no coarse replacement fallback. */
161
+ function sparseCharacterDiff(a, b, offset, budget) {
162
+ const frontier = new Map([[1, 0]]);
163
+ const trace = [];
164
+ let traceCells = 0;
165
+ const spend = () => limit(++budget.cells > PATCH_LIMITS.maxDiffCells, 'Character alignment work limit exceeded');
166
+ for (let distance = 0; distance <= a.length + b.length; distance++) {
167
+ traceCells += frontier.size;
168
+ limit(traceCells > PATCH_LIMITS.maxTraceCells, 'Character alignment trace limit exceeded');
169
+ trace.push(new Map(frontier));
170
+ for (let diagonal = -distance; diagonal <= distance; diagonal += 2) {
171
+ spend();
172
+ const left = frontier.get(diagonal - 1) ?? -Infinity;
173
+ const right = frontier.get(diagonal + 1) ?? -Infinity;
174
+ let x = diagonal === -distance || (diagonal !== distance && left < right) ? right : left + 1;
175
+ let y = x - diagonal;
176
+ while (x < a.length && y < b.length && a[x] === b[y]) {
177
+ spend();
178
+ x++;
179
+ y++;
180
+ }
181
+ frontier.set(diagonal, x);
182
+ if (x < a.length || y < b.length)
183
+ continue;
184
+ const reversed = [];
185
+ for (let d = distance; d >= 0; d--) {
186
+ const prior = trace[d], k = x - y;
187
+ const previousK = k === -d || (k !== d && (prior.get(k - 1) ?? -Infinity) < (prior.get(k + 1) ?? -Infinity)) ? k + 1 : k - 1;
188
+ const previousX = prior.get(previousK) ?? 0, previousY = previousX - previousK;
189
+ while (x > previousX && y > previousY) {
190
+ reversed.push('equal');
191
+ x--;
192
+ y--;
193
+ }
194
+ if (d > 0) {
195
+ if (x === previousX) {
196
+ reversed.push('insert');
197
+ y--;
198
+ }
199
+ else {
200
+ reversed.push('delete');
201
+ x--;
202
+ }
203
+ }
204
+ }
205
+ const edits = [];
206
+ let i = 0, j = 0, active;
207
+ const flush = () => { if (active) {
208
+ edits.push(active);
209
+ active = undefined;
210
+ } };
211
+ for (const step of reversed.reverse()) {
212
+ if (step === 'equal') {
213
+ flush();
214
+ i++;
215
+ j++;
216
+ continue;
217
+ }
218
+ active ??= { start: offset + i, end: offset + i, expectedText: '', replacementText: '' };
219
+ if (step === 'delete') {
220
+ active.expectedText += a[i++];
221
+ active.end++;
222
+ }
223
+ else
224
+ active.replacementText += b[j++];
225
+ }
226
+ flush();
227
+ limit(edits.length > PATCH_LIMITS.maxEdits, 'Too many edits');
228
+ return edits;
229
+ }
230
+ }
231
+ return invalid('Character alignment failed');
232
+ }
@@ -0,0 +1,73 @@
1
+ import { ctx, type ConnOpts } from "./index.js";
2
+ export interface DocumentReadOptions extends ConnOpts {
3
+ at?: string;
4
+ toc?: boolean;
5
+ tag?: string;
6
+ version?: string;
7
+ linger?: boolean;
8
+ debounce?: string;
9
+ throttle?: string;
10
+ intent?: string;
11
+ view?: string;
12
+ note?: string;
13
+ since?: string;
14
+ format?: string;
15
+ ifMatch?: string;
16
+ json?: boolean;
17
+ legacy?: boolean;
18
+ section?: string;
19
+ startLine?: string;
20
+ endLine?: string;
21
+ numbered?: boolean;
22
+ }
23
+ export interface DocumentPatchOptions extends ConnOpts {
24
+ file?: string;
25
+ diff?: string;
26
+ format?: string;
27
+ baseRevision?: string;
28
+ ifMatch?: string;
29
+ exact?: boolean;
30
+ force?: boolean;
31
+ json?: boolean;
32
+ dryRun?: boolean;
33
+ legacy?: boolean;
34
+ }
35
+ interface Tokens {
36
+ note: string;
37
+ hash: string;
38
+ revision: string;
39
+ }
40
+ interface PatchReceipt extends Tokens {
41
+ mode: "merge" | "exact";
42
+ baseRevision: string;
43
+ }
44
+ export declare function tokens(result: Tokens, note: string): void;
45
+ type DocumentContext = NonNullable<Awaited<ReturnType<typeof ctx>>>;
46
+ export interface SourceSnapshot extends Tokens {
47
+ content: string;
48
+ }
49
+ export declare function readDocumentSnapshot(c: DocumentContext, id: string, at?: string): Promise<SourceSnapshot>;
50
+ export interface DocumentPatchPayload {
51
+ format: "inline-dff" | "diff";
52
+ patch: string;
53
+ baseRevision: string;
54
+ mode: "merge" | "exact";
55
+ }
56
+ export interface SourceEdit {
57
+ start: number;
58
+ end: number;
59
+ text: string;
60
+ }
61
+ /** Exact original-source spans, with untouched gaps omitted from the PATCH. */
62
+ export declare function documentEdits(source: SourceSnapshot, edits: SourceEdit[], exact?: boolean): DocumentPatchPayload;
63
+ /** One literal insertion at an original-source Unicode code-point boundary. */
64
+ export declare function documentInsertion(source: SourceSnapshot, at: number, text: string, exact?: boolean): DocumentPatchPayload;
65
+ /** Shared submission owns receipt validation; input preparation stays with each editor. */
66
+ export declare function submitDocumentPatch(c: DocumentContext, id: string, payload: DocumentPatchPayload, headers?: Record<string, string>): Promise<PatchReceipt>;
67
+ export declare function printPatchReceipt(result: PatchReceipt, json?: boolean): void;
68
+ export declare function documentWriteError(error: unknown): number;
69
+ export declare function runDocumentRead(ref: string | undefined, opts: DocumentReadOptions): Promise<number>;
70
+ /** Shared native fd-0 transport; callers choose decoding and empty-input semantics. */
71
+ export declare function readStdinBytes(label?: string): Promise<Buffer>;
72
+ export declare function runDocumentPatch(ref: string, opts: DocumentPatchOptions): Promise<number>;
73
+ export {};
@@ -0,0 +1,306 @@
1
+ import { validateHtmlSnapshot, annotatedMarkdown } from "./html-read.js";
2
+ /** V2 transports exact source and opaque revisions; the backend owns patch parsing. */
3
+ import { createHash } from "node:crypto";
4
+ import { readFileSync, fstatSync } from "node:fs";
5
+ import { HttpError, requestJson, requestRaw } from "../client.js";
6
+ import { emitJson, fail } from "../helpers.js";
7
+ import { ctx, report, resolveNote, seg } from "./index.js";
8
+ function format(value) {
9
+ if (value !== undefined && value !== "inline-dff" && value !== "diff")
10
+ throw new Error("--format must be inline-dff or diff");
11
+ return value ?? "inline-dff";
12
+ }
13
+ export function tokens(result, note) {
14
+ if (!result || result.note !== note || !/^sha256:[a-f0-9]{64}$/.test(result.hash)
15
+ || typeof result.revision !== "string" || !result.revision || /[\r\n]/.test(result.revision)) {
16
+ throw new Error("server did not return the Notes v2 contract; upgrade the server or explicitly use --legacy");
17
+ }
18
+ }
19
+ function printTokens(result) {
20
+ return `note: ${result.note}\nhash: ${result.hash}\nrevision: ${result.revision}\n`;
21
+ }
22
+ export async function readDocumentSnapshot(c, id, at) {
23
+ const query = new URLSearchParams({ contract: "v2" });
24
+ if (at !== undefined)
25
+ query.set("at", at);
26
+ const result = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body?${query}`, { token: c.token, redirect: "error" });
27
+ tokens(result, id);
28
+ if (at !== undefined && result.revision !== at)
29
+ throw new Error("server did not return the requested pinned revision");
30
+ validateSourceHash(result);
31
+ return result;
32
+ }
33
+ function validateSourceHash(result) {
34
+ if (typeof result.content !== "string" || `sha256:${createHash("sha256").update(result.content, "utf8").digest("hex")}` !== result.hash) {
35
+ throw new Error("source does not match the returned hash");
36
+ }
37
+ }
38
+ function inlineLiteral(text) {
39
+ return text.replace(/[\\\n\r\t\[\]{}+\-]/g, char => char === "\n" ? "\\n" : char === "\r" ? "\\r" : char === "\t" ? "\\t" : `\\${char}`);
40
+ }
41
+ /** Exact original-source spans, with untouched gaps omitted from the PATCH. */
42
+ export function documentEdits(source, edits, exact = false) {
43
+ const points = Array.from(source.content);
44
+ let lastEnd = 0, lastStart = -1;
45
+ const hunks = [];
46
+ for (const edit of edits) {
47
+ if (!Number.isSafeInteger(edit.start) || !Number.isSafeInteger(edit.end) || edit.start < lastEnd
48
+ || edit.start <= lastStart || edit.end < edit.start || edit.end > points.length) {
49
+ throw new Error("Edit spans must be ordered and disjoint within the original source");
50
+ }
51
+ lastStart = edit.start;
52
+ lastEnd = edit.end;
53
+ const old = points.slice(edit.start, edit.end).join("");
54
+ if (old === edit.text)
55
+ continue;
56
+ hunks.push(`@@ chars ${edit.start}:${edit.end} @@\n~ ${old ? `[-${inlineLiteral(old)}-]` : ""}${edit.text ? `{+${inlineLiteral(edit.text)}+}` : ""}\n`);
57
+ }
58
+ return { format: "inline-dff", patch: hunks.join(""), baseRevision: source.revision, mode: exact ? "exact" : "merge" };
59
+ }
60
+ /** One literal insertion at an original-source Unicode code-point boundary. */
61
+ export function documentInsertion(source, at, text, exact = false) {
62
+ return documentEdits(source, [{ start: at, end: at, text }], exact);
63
+ }
64
+ class DocumentWriteUnknownError extends Error {
65
+ }
66
+ /** Shared submission owns receipt validation; input preparation stays with each editor. */
67
+ export async function submitDocumentPatch(c, id, payload, headers = {}) {
68
+ let result;
69
+ try {
70
+ result = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`, {
71
+ token: c.token, method: "PATCH", headers, json: payload, redirect: "error",
72
+ });
73
+ }
74
+ catch (error) {
75
+ if (error instanceof HttpError && [400, 401, 403, 404, 409, 412, 413, 415, 422, 503].includes(error.status))
76
+ throw error;
77
+ throw new DocumentWriteUnknownError("Notes write outcome unknown; keep the original baseline and draft, inspect the note before resubmitting");
78
+ }
79
+ try {
80
+ tokens(result, id);
81
+ if (result.mode !== payload.mode || result.baseRevision !== payload.baseRevision)
82
+ throw new Error("inconsistent receipt");
83
+ }
84
+ catch {
85
+ throw new DocumentWriteUnknownError("Notes write outcome unknown: invalid receipt; keep the original baseline and draft, inspect the note before resubmitting");
86
+ }
87
+ return result;
88
+ }
89
+ export function printPatchReceipt(result, json) {
90
+ if (json)
91
+ emitJson(result);
92
+ else
93
+ process.stdout.write(`${printTokens(result)}mode: ${result.mode}\nbaseRevision: ${result.baseRevision}\n`);
94
+ }
95
+ /** Current API proof only. Human text and unknown marker versions cannot
96
+ * prove whether a requested native edit reached RTC. */
97
+ function baselinePatchNotSubmitted(error) {
98
+ if (error.status !== 503)
99
+ return false;
100
+ try {
101
+ const body = JSON.parse(error.body);
102
+ if (!body || typeof body !== "object" || Array.isArray(body))
103
+ return false;
104
+ const envelope = body, marker = envelope.mutation;
105
+ if (envelope.error !== "rtc_unavailable" || !marker || typeof marker !== "object" || Array.isArray(marker))
106
+ return false;
107
+ const value = marker;
108
+ return Object.keys(value).length === 3 && value.apiVersion === 1 && value.started === false && value.phase === "baseline_read";
109
+ }
110
+ catch {
111
+ return false;
112
+ }
113
+ }
114
+ export function documentWriteError(error) {
115
+ if (error instanceof HttpError && baselinePatchNotSubmitted(error)) {
116
+ fail("patch not submitted: the requested edit did not start because its baseline is unavailable; preserve the original baseline and draft");
117
+ return 1;
118
+ }
119
+ if (error instanceof DocumentWriteUnknownError) {
120
+ fail(error.message);
121
+ return 4;
122
+ }
123
+ if (error instanceof HttpError && [409, 412, 422, 503].includes(error.status)) {
124
+ const reason = error.status === 412 ? "the original revision or RTC identities are no longer valid for this request"
125
+ : error.status === 422 ? "the patch was rejected; inspect the server explanation and preserve the original snapshot and draft"
126
+ : "the realtime acknowledgment is unavailable; the result may be ambiguous";
127
+ fail(`${reason}; keep the original baseline and draft, inspect the note before resubmitting (${error.message})`);
128
+ return error.status === 412 ? 3 : error.status === 422 ? 5 : 4;
129
+ }
130
+ return report(error);
131
+ }
132
+ export async function runDocumentRead(ref, opts) {
133
+ try {
134
+ opts = { ...opts, view: opts.view ?? (opts.toc || opts.section || opts.tag ? "html" : "source") };
135
+ if (opts.view !== undefined && opts.view !== "source" && opts.view !== "html" && opts.view !== "markdown")
136
+ throw new Error("--view must be source, html or markdown");
137
+ if ((opts.view === "html" || opts.view === "markdown") && (opts.since !== undefined || opts.format !== undefined || opts.json || opts.legacy))
138
+ throw new Error("--view html/markdown is a snapshot view; do not combine --since, --format, --json or --legacy");
139
+ if (opts.ifMatch !== undefined && (!opts.ifMatch.trim() || opts.ifMatch === "*" || /[\r\n]/.test(opts.ifMatch)))
140
+ throw new Error("--if-match requires an exact saved revision");
141
+ const selectedFormat = format(opts.format ?? "diff");
142
+ const target = ref ?? opts.note;
143
+ if (!target || (ref && opts.note && ref !== opts.note))
144
+ throw new Error("give one note id, slug or name");
145
+ if ((opts.at !== undefined && (!opts.at.trim() || opts.at === "*" || /[\r\n]/.test(opts.at))))
146
+ throw new Error("--at requires an exact retained revision");
147
+ if (opts.at && (opts.since !== undefined || opts.ifMatch !== undefined))
148
+ throw new Error("--at cannot combine with --since or --if-match");
149
+ if ([opts.toc, opts.section, opts.tag].filter(Boolean).length > 1)
150
+ throw new Error("choose --toc, --section or --tag");
151
+ if ((opts.toc || opts.section !== undefined || opts.tag !== undefined) && opts.view !== "html" && opts.view !== "markdown")
152
+ throw new Error("--toc/--section/--tag require --view html or markdown");
153
+ if (opts.startLine !== undefined || opts.endLine !== undefined || opts.numbered) {
154
+ throw new Error("partial and numbered reads require --legacy; v2 returns exact complete source");
155
+ }
156
+ const c = await ctx(opts);
157
+ if (!c)
158
+ return 1;
159
+ const id = await resolveNote(c, target);
160
+ if (!id)
161
+ return 1;
162
+ const query = new URLSearchParams({ contract: "v2" });
163
+ if (opts.at)
164
+ query.set("at", opts.at);
165
+ if (opts.view === "html" || opts.view === "markdown") {
166
+ if (opts.section !== undefined)
167
+ query.set("section", opts.section);
168
+ if (opts.tag)
169
+ query.set("tag", opts.tag);
170
+ if (opts.toc)
171
+ query.set("toc", "true");
172
+ query.set("view", "html");
173
+ query.set("contentFormat", "literal-markdown");
174
+ const url = `${c.remote.replace(/\/+$/, "")}/namespaces/${seg(c.ns)}/notes/${seg(id)}/body?${query}`;
175
+ const response = await requestRaw(url, { token: c.token, timeoutMs: 30000, followRedirects: false,
176
+ headers: { Accept: "text/html", ...(opts.ifMatch ? { "If-Match": opts.ifMatch } : {}) } });
177
+ if (!/^text\/(?:html|plain)(?:;|$)/i.test(response.headers.get("content-type") ?? ""))
178
+ throw new Error("server did not return Notes HTML; upgrade the server");
179
+ const bytes = new Uint8Array(await response.arrayBuffer());
180
+ const html = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
181
+ const snapshot = validateHtmlSnapshot(html, id, { section: opts.section, toc: opts.toc, tag: opts.tag });
182
+ if (opts.at && snapshot.revision !== opts.at)
183
+ throw new Error("server did not return the requested pinned revision");
184
+ if (opts.ifMatch && snapshot.revision !== opts.ifMatch) {
185
+ fail("note changed since the acknowledged revision; keep the original draft and baseline");
186
+ return 3;
187
+ }
188
+ process.stdout.write(opts.view === "markdown" ? annotatedMarkdown(html) : bytes);
189
+ return 0;
190
+ }
191
+ if (opts.since !== undefined) {
192
+ query.set("since", opts.since);
193
+ query.set("format", selectedFormat);
194
+ }
195
+ const result = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body?${query}`, {
196
+ token: c.token, headers: opts.ifMatch ? { "If-Match": opts.ifMatch } : {},
197
+ });
198
+ tokens(result, id);
199
+ if (opts.at && result.revision !== opts.at)
200
+ throw new Error("server did not return the requested pinned revision");
201
+ if (opts.ifMatch && result.revision !== opts.ifMatch) {
202
+ fail("note changed since the acknowledged revision; keep the original draft and baseline");
203
+ return 3;
204
+ }
205
+ if (opts.since !== undefined) {
206
+ if (result.format !== selectedFormat || typeof result.patch !== "string" || !/^sha256:[a-f0-9]{64}$/.test(result.base ?? ""))
207
+ throw new Error("invalid incremental Notes v2 response");
208
+ }
209
+ else {
210
+ validateSourceHash(result);
211
+ }
212
+ if (opts.json)
213
+ emitJson(result);
214
+ else if (opts.since !== undefined) {
215
+ process.stdout.write(`note: ${result.note}\nformat: ${result.format}\nbase: ${result.base}\nhash: ${result.hash}\nrevision: ${result.revision}\nunit: unicode-code-point\n${result.since ? `since: ${result.since}\n` : ""}\n${result.patch}`);
216
+ }
217
+ else
218
+ process.stdout.write(`${printTokens(result)}\n${result.content}`);
219
+ return 0;
220
+ }
221
+ catch (error) {
222
+ return report(error);
223
+ }
224
+ }
225
+ /** An explicit input conflicts with a pipe or redirected regular file, including empty input. */
226
+ function redirectedInput() {
227
+ if (process.stdin.isTTY)
228
+ return false;
229
+ const stat = fstatSync(0);
230
+ return stat.isFIFO() || stat.isFile() || stat.isSocket();
231
+ }
232
+ async function patchInput(opts) {
233
+ if (opts.file !== undefined && opts.diff !== undefined)
234
+ throw new Error("choose stdin, --file, or --diff; do not combine them");
235
+ if ((opts.file !== undefined && opts.file !== "-") || opts.diff !== undefined) {
236
+ if (redirectedInput())
237
+ throw new Error("explicit patch input conflicts with redirected stdin");
238
+ const bytes = opts.diff !== undefined ? Buffer.from(opts.diff, "utf8") : readFileSync(opts.file);
239
+ if (bytes.length > 8_000_000)
240
+ throw new Error("patch exceeds 8000000 bytes");
241
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
242
+ }
243
+ if (process.stdin.isTTY)
244
+ throw new Error("provide a quoted multiline here-document, pipe, or --file; interactive stdin is not accepted");
245
+ return new TextDecoder("utf-8", { fatal: true }).decode(await readStdinBytes());
246
+ }
247
+ /** Shared native fd-0 transport; callers choose decoding and empty-input semantics. */
248
+ export async function readStdinBytes(label = "patch") {
249
+ const chunks = [];
250
+ let size = 0;
251
+ // Bun's Node-compatible stdin iterator can yield nothing for a redirected
252
+ // regular file in the compiled CLI. Use its native fd-0 stream there.
253
+ const bun = globalThis.Bun;
254
+ const input = bun ? bun.stdin.stream() : process.stdin;
255
+ for await (const chunk of input) {
256
+ const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
257
+ size += bytes.length;
258
+ if (size > 8_000_000)
259
+ throw new Error(`${label} exceeds 8000000 bytes`);
260
+ chunks.push(bytes);
261
+ }
262
+ return Buffer.concat(chunks);
263
+ }
264
+ export async function runDocumentPatch(ref, opts) {
265
+ try {
266
+ const selectedFormat = format(opts.format);
267
+ if (opts.force)
268
+ throw new Error("v2 patch does not need --force; omit --exact and --if-match for a merge patch");
269
+ const baseRevision = opts.baseRevision ?? opts.ifMatch;
270
+ if (!baseRevision?.trim() || baseRevision === "*" || /[\r\n]/.test(baseRevision)) {
271
+ throw new Error("v2 patch requires the original saved baseline revision; keep the original draft and baseline");
272
+ }
273
+ if (opts.ifMatch !== undefined && (!opts.ifMatch.trim() || opts.ifMatch === "*" || /[\r\n]/.test(opts.ifMatch))) {
274
+ throw new Error("--if-match must be an explicit saved revision");
275
+ }
276
+ if (opts.baseRevision !== undefined && opts.ifMatch !== undefined && opts.baseRevision !== opts.ifMatch) {
277
+ throw new Error("--base-revision and --if-match must identify the same original snapshot");
278
+ }
279
+ const patch = await patchInput(opts);
280
+ if (!patch.trim())
281
+ throw new Error("patch input is empty; no edit was sent. Check stdin or pass --file with the patch path");
282
+ const c = await ctx(opts);
283
+ if (!c)
284
+ return 1;
285
+ const id = await resolveNote(c, ref);
286
+ if (!id)
287
+ return 1;
288
+ const path = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`;
289
+ const headers = opts.ifMatch === undefined ? {} : { "If-Match": opts.ifMatch };
290
+ const mode = opts.exact || opts.ifMatch !== undefined ? "exact" : "merge";
291
+ const payload = { format: selectedFormat, patch, baseRevision, mode };
292
+ if (opts.dryRun) {
293
+ if (opts.json)
294
+ emitJson({ dryRun: true, method: "PATCH", path, headers, payload });
295
+ else
296
+ process.stdout.write(`method: PATCH\npath: ${path}\nmode: ${mode}\nbase-revision: ${baseRevision}\n${opts.ifMatch === undefined ? "" : `if-match: ${opts.ifMatch}\n`}format: ${selectedFormat}\n\n${patch}`);
297
+ return 0;
298
+ }
299
+ const result = await submitDocumentPatch(c, id, payload, headers);
300
+ printPatchReceipt(result, opts.json);
301
+ return 0;
302
+ }
303
+ catch (error) {
304
+ return documentWriteError(error);
305
+ }
306
+ }