@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,1303 @@
1
+ import { collectionList } from "../collection-list.js";
2
+ import { registerVersionCommands, runSavedVersionRead } from "./version-commands.js";
3
+ import { registerMoveCommand } from "./move-command.js";
4
+ import { registerTransferCommand } from "./transfer-command.js";
5
+ import { registerRmCommand } from "./rm-command.js";
6
+ import { registerSuggestDiffCommand } from "./suggest-diff.js";
7
+ import { registerShareCommands } from "../share.js";
8
+ import { runNotesTextSelect } from "./select-command.js";
9
+ /**
10
+ * Notes v2 reads carry exact source, hashes and opaque write revisions on stdout.
11
+ * Patch uploads require the saved baseline; the backend owns parsing and RTC writes.
12
+ * Explicit --legacy retains the older body-only/ETag read and unified patch API.
13
+ * Exit codes: 1 arguments/auth/transport, 3 stale, 4 RTC unavailable, 5 invalid patch.
14
+ */
15
+ import { readFileSync } from "node:fs";
16
+ import { runMediaUpload } from "./media-commands.js";
17
+ import { runNotesLinger } from "./linger.js";
18
+ import { runDocumentRead, runDocumentPatch, readDocumentSnapshot, readStdinBytes, documentInsertion, documentEdits, submitDocumentPatch, printPatchReceipt, documentWriteError } from "./document.js";
19
+ import { characterDiff, NotePatchError, PATCH_LIMITS } from "./character-plan.js";
20
+ import { HttpError, requestJson, requestRaw } from "../client.js";
21
+ import { runNotesDelete, runNotesFind, runNotesInsert, runNotesReplace, runNotesGrep, runNotesSelect, runNotesToc, } from "./edit-commands.js";
22
+ import { runFilesCat, runFilesPreview, runFilesCopy, runFilesDownload, runFilesList, runFilesMove, runFilesRestore, runFilesRm, runFilesUpload, runFilesWrite, runFilesOperation, } from "./files-commands.js";
23
+ import { resolveCtx } from "../compat/ctx.js";
24
+ import { withConnFlags } from "../compat/flags.js";
25
+ import { requireNamespace } from "../compat/http.js";
26
+ import { emitJson, fail, renderTable } from "../helpers.js";
27
+ /** Distinct codes for the three refusals a caller acts on differently. */
28
+ const EXIT_STALE = 3;
29
+ const EXIT_BUSY = 4;
30
+ const EXIT_PATCH = 5;
31
+ // ─── context ──────────────────────────────────────────────────────────────────
32
+ /**
33
+ * Endpoint, credentials and namespace.
34
+ *
35
+ * Routed through `resolveCtx` — the same path the other ported groups take —
36
+ * so `--remote/--token/--debug` mean here what they mean everywhere else, and
37
+ * so a caller is not asked to log in twice for two halves of the same CLI.
38
+ */
39
+ export async function ctx(opts = {}) {
40
+ const c = resolveCtx(opts);
41
+ if (!c.token) {
42
+ fail("not authenticated — run 'dreamlake login' first");
43
+ return null;
44
+ }
45
+ const ns = await requireNamespace(c, opts.namespace);
46
+ if (!ns)
47
+ return null;
48
+ return { token: c.token, remote: c.remote, ns };
49
+ }
50
+ /** One path segment, encoded as one — a note name or an anchor is user text,
51
+ * and a `/` in either is a different request rather than a bad argument. */
52
+ export function seg(v) {
53
+ return encodeURIComponent(v);
54
+ }
55
+ /**
56
+ * Map a failure onto an exit code and a sentence worth reading.
57
+ *
58
+ * The three note-specific statuses each mean a different next step, and
59
+ * collapsing them into "request failed" would leave a script no way to tell
60
+ * "wait and retry" from "your copy is out of date".
61
+ */
62
+ export function report(err) {
63
+ if (err instanceof HttpError) {
64
+ const detail = err.body?.message ?? err.message;
65
+ if (err.status === 412) {
66
+ fail(`the note changed since you read it — re-read and redo the edit (${detail})`);
67
+ return EXIT_STALE;
68
+ }
69
+ if (err.status === 409 || err.status === 503) {
70
+ // Not "someone is editing" — a write normally goes INTO the live room
71
+ // and appears on their screens. This is the realtime service being
72
+ // unavailable, which is transient.
73
+ fail(`the realtime service is unavailable — try again shortly (${detail})`);
74
+ return EXIT_BUSY;
75
+ }
76
+ if (err.status === 422) {
77
+ fail(`the diff does not apply to the current body — re-read and regenerate it (${detail})`);
78
+ return EXIT_PATCH;
79
+ }
80
+ if (err.status === 401) {
81
+ fail("not authenticated — run 'dreamlake login' first");
82
+ return 1;
83
+ }
84
+ if (err.status === 403) {
85
+ fail("read-only access to this note — you may read it but not write it");
86
+ return 1;
87
+ }
88
+ if (err.status === 404) {
89
+ fail(detail || "not found");
90
+ return 1;
91
+ }
92
+ fail(detail || `request failed (${err.status})`);
93
+ return 1;
94
+ }
95
+ fail(err instanceof Error ? err.message : String(err));
96
+ return 1;
97
+ }
98
+ /**
99
+ * A note reference from the command line -> its id.
100
+ *
101
+ * Accepts an id or a slug. A slug is resolved through the listing rather than
102
+ * the server's `q` filter, because `q` matches the NAME and a note's slug is a
103
+ * separate field — matching on the wrong one would open a different note that
104
+ * happens to be titled similarly.
105
+ */
106
+ export async function resolveNote(c, ref) {
107
+ if (/^[a-f0-9]{24}$/i.test(ref))
108
+ return ref;
109
+ const res = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes?limit=200`, { token: c.token });
110
+ const hit = res.notes.find((n) => n.slug === ref || n.id === ref || n.name === ref);
111
+ if (!hit) {
112
+ fail(`no note '${ref}' in namespace '${c.ns}' — 'dreamlake notes list' shows what is there, ` +
113
+ `and an organization's notes need --namespace <slug>`);
114
+ return null;
115
+ }
116
+ return hit.id;
117
+ }
118
+ /** Body text from --file, --text, or stdin. Exactly one, so an empty write is
119
+ * always deliberate rather than the result of a forgotten flag. */
120
+ async function bodyFrom(opts, nativeSourceStdin = false) {
121
+ const given = [opts.file, opts.text].filter((v) => v !== undefined).length;
122
+ if (given > 1) {
123
+ fail("pass one of --file or --text, not both");
124
+ return null;
125
+ }
126
+ if (opts.text !== undefined)
127
+ return opts.text;
128
+ if (opts.file !== undefined) {
129
+ if (opts.file === "-")
130
+ return nativeSourceStdin ? new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(await readStdinBytes("body")) : readStdin();
131
+ try {
132
+ return nativeSourceStdin
133
+ ? new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(readFileSync(opts.file))
134
+ : readFileSync(opts.file, "utf-8");
135
+ }
136
+ catch (e) {
137
+ fail(`cannot read ${opts.file}: ${e instanceof Error ? e.message : String(e)}`);
138
+ return null;
139
+ }
140
+ }
141
+ if (process.stdin.isTTY) {
142
+ fail("nothing to write — pass --file <path>, --text <string>, or pipe on stdin");
143
+ return null;
144
+ }
145
+ return nativeSourceStdin ? new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(await readStdinBytes("body")) : readStdin();
146
+ }
147
+ /**
148
+ * Does this look like a unified diff?
149
+ *
150
+ * `write` takes a body and `patch` takes a diff, and they accept the same
151
+ * flags — so piping a diff into `write` stores the diff AS the note, silently
152
+ * and successfully. Cheap to notice, and the note that results is confusing
153
+ * enough that nobody would connect it back to the wrong verb.
154
+ */
155
+ function looksLikeDiff(text) {
156
+ return /^--- /m.test(text) && /^\+\+\+ /m.test(text) && /^@@ /m.test(text);
157
+ }
158
+ function readStdin() {
159
+ return new Promise((resolve, reject) => {
160
+ let buf = "";
161
+ process.stdin.setEncoding("utf-8");
162
+ process.stdin.on("data", (d) => (buf += d));
163
+ process.stdin.on("end", () => resolve(buf));
164
+ process.stdin.on("error", reject);
165
+ });
166
+ }
167
+ /**
168
+ * The validator to send.
169
+ *
170
+ * `--if-match` when given. Otherwise the note's current ETag, read now — which
171
+ * still guards the window between this read and the write a moment later, and
172
+ * is the difference between "refuses when it should" and "always overwrites".
173
+ * `--force` is the only way to send nothing.
174
+ */
175
+ async function validator(c, noteId, opts) {
176
+ if (opts.force)
177
+ return {};
178
+ if (opts.ifMatch)
179
+ return { "If-Match": opts.ifMatch };
180
+ const body = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(noteId)}/body`, { token: c.token });
181
+ return { "If-Match": body.etag };
182
+ }
183
+ // ─── commands ─────────────────────────────────────────────────────────────────
184
+ export function registerNotesCommand(program) {
185
+ const notes = program
186
+ .command("notes")
187
+ .alias("note")
188
+ .description("read and edit collaborative notes (search, sections, write, patch)");
189
+ registerShareCommands(notes, "notes");
190
+ registerVersionCommands(notes);
191
+ registerMoveCommand(notes);
192
+ registerTransferCommand(notes);
193
+ registerRmCommand(notes);
194
+ registerSuggestDiffCommand(notes);
195
+ // Same connection flags as the other ported groups, so --debug/--remote
196
+ // behave identically across the CLI.
197
+ const strict = (cmd) => withConnFlags(cmd.allowExcessArguments(false));
198
+ strict(notes.command("visit"))
199
+ .argument("<note>", "note id, slug or title")
200
+ .description("register agent presence once without reading content")
201
+ .option("--namespace <slug>", "note owner namespace")
202
+ .option("--intent <text>", "one short sentence of purpose, shown on your presence card")
203
+ .option("--json", "emit JSON")
204
+ .action(async (note, opts) => { process.exitCode = await runNotesVisit(note, opts); });
205
+ strict(notes.command("presence"))
206
+ .argument("<note>", "note id, slug or title")
207
+ .description("read who is present without joining the note")
208
+ .option("--namespace <slug>", "note owner namespace")
209
+ .option("--json", "emit JSON for programmatic consumers")
210
+ .action(async (note, opts) => { process.exitCode = await runNotesPresence(note, opts); });
211
+ strict(notes.command("projects"))
212
+ .argument("<note-id>", "stable Note ID")
213
+ .description("inspect current project filing and server-computed filing permissions (JSON)")
214
+ .requiredOption("--namespace <slug>", "the Note's owning namespace")
215
+ .action(async (id, opts) => { process.exitCode = await runNotesProjects(id, opts); });
216
+ // ── notes create ──
217
+ strict(notes.command("create"))
218
+ .argument("<name>", "the note's title")
219
+ .description("create a note, optionally with a body")
220
+ .option("--project <slug>", "file the new Note in this same-namespace project (repeatable)", (value, previous) => [...previous, value], [])
221
+ .option("--file <path>", "initial body from a file ('-' for stdin)")
222
+ .option("--text <string>", "initial body, inline")
223
+ .option("--public", "anyone can read it (default: private)")
224
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
225
+ .option("--json", "emit JSON")
226
+ .action(async (name, opts) => { process.exitCode = await runNotesCreate(name, opts); });
227
+ // ── notes list ──
228
+ strict(collectionList(notes, "list"))
229
+ .description("list notes in one namespace")
230
+ .option("--limit <n>", "page size", "50")
231
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
232
+ .option("--shared", "list notes other people shared with you, across namespaces")
233
+ .option("--json", "emit JSON")
234
+ .action(async (opts) => { process.exitCode = await runNotesList(opts); });
235
+ // ── notes search ──
236
+ strict(notes.command("search"))
237
+ .argument("<query>", "matched against note titles and bodies, case-insensitively")
238
+ .description("find notes by title or body text")
239
+ .option("--limit <n>", "page size", "50")
240
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
241
+ .option("--json", "emit JSON")
242
+ .action(async (query, opts) => { process.exitCode = await runNotesSearch(query, opts); });
243
+ // ── notes grep ──
244
+ strict(notes.command("grep"))
245
+ .argument("[query]", "literal text; punctuation matches itself")
246
+ .description("search every note you can see and print where each hit is")
247
+ .option("--regex <pattern>", "search by pattern instead of literal text")
248
+ .option("--flags <flags>", "regex flags: any of i, m, s, u")
249
+ .option("--case-sensitive", "match case (the default for --regex)")
250
+ .option("--no-case-sensitive", "ignore case (the default for a literal query)")
251
+ .option("--glob <pattern>", "only notes whose name matches, e.g. 'spec-*'")
252
+ .option("--note <ids>", "comma-separated note ids or slugs to search")
253
+ .option("-C, --context <n>", "lines of context either side")
254
+ .option("--limit <n>", "maximum number of hits", "50")
255
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
256
+ .option("--json", "emit JSON (each hit carries its etag and character range)")
257
+ .action(async (query, opts) => { process.exitCode = await runNotesGrep(query, opts); });
258
+ const media = notes.command("media").allowExcessArguments(false)
259
+ .description("image and video URLs accessible to anyone holding the URL");
260
+ strict(media.command("upload"))
261
+ .argument("<local>", "local image or video file")
262
+ .description("upload media and print its embeddable URL (anyone with the URL can read it)")
263
+ .option("--json", "emit url, contentType and sizeBytes as JSON")
264
+ .action(async (local, opts) => { process.exitCode = await runMediaUpload(local, opts); });
265
+ // ── notes files ──
266
+ //
267
+ // A sub-group rather than top-level commands: these act on a note's files,
268
+ // and `notes upload` would read as uploading the note.
269
+ const files = strict(notes.command("files")).description("files attached to a note");
270
+ strict(collectionList(files, "list"))
271
+ .argument("[glob]", "e.g. 'assets/*.png' or '**/*.json'")
272
+ .description("list the files attached to a note")
273
+ .option("--trashed", "list the trash instead of the live files")
274
+ .option("--content-type <type>", "only files stored with this exact type")
275
+ .option("--note <ref>", "the note: slug, id or exact title")
276
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
277
+ .option("--json", "emit JSON")
278
+ .option("--limit <n>", "how many files to show")
279
+ .option("--offset <n>", "skip this many first")
280
+ .action(async (glob, opts) => { process.exitCode = await runFilesList(glob, opts); });
281
+ strict(files.command("upload"))
282
+ .argument("<local>", "path to the local file")
283
+ .description("upload a file to a note (any bytes; nothing is decoded)")
284
+ .option("--path <path>", "where to put it in the note (default: the file's name)")
285
+ .option("--content-type <type>", "declare the type instead of letting it be inferred")
286
+ .option("--overwrite", "replace a file already at that path")
287
+ .option("--note <ref>", "the note: slug, id or exact title")
288
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
289
+ .option("--json", "emit JSON")
290
+ .action(async (local, opts) => { process.exitCode = await runFilesUpload(local, opts); });
291
+ strict(files.command("download"))
292
+ .argument("<file>", "file id or path within the note")
293
+ .description("download a file (exact bytes)")
294
+ .option("-o, --output <path>", "where to write it; '-' or omitted means stdout")
295
+ .option("--overwrite", "replace the local file if it exists")
296
+ .option("--note <ref>", "the note: slug, id or exact title")
297
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
298
+ .action(async (file, opts) => { process.exitCode = await runFilesDownload(file, opts); });
299
+ strict(files.command("cat"))
300
+ .argument("<file>", "file id or path within the note")
301
+ .description("print a text file; refuses a binary rather than mangling it")
302
+ .option("--note <ref>", "the note: slug, id or exact title")
303
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
304
+ .option("--json", "emit JSON (includes the etag)")
305
+ .action(async (file, opts) => { process.exitCode = await runFilesCat(file, opts); });
306
+ strict(files.command("write"))
307
+ .argument("<path>", "where to put it in the note")
308
+ .description("write a text file from --text or --file")
309
+ .option("--text <text>", "the contents")
310
+ .option("--file <path>", "read the contents from a local file")
311
+ .option("--content-type <type>", "declare the type")
312
+ .option("--idempotency-key <key>", "keep one original text/copy operation for recovery")
313
+ .option("--overwrite", "replace a file already at that path")
314
+ .option("--if-match <etag>", "only write if the file is still at this revision")
315
+ .option("--note <ref>", "the note: slug, id or exact title")
316
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
317
+ .option("--json", "emit JSON")
318
+ .action(async (p, opts) => { process.exitCode = await runFilesWrite(p, opts); });
319
+ strict(files.command("mv"))
320
+ .argument("<file>", "file id or path")
321
+ .argument("<to>", "new path within the note")
322
+ .description("move or rename (the id and the bytes do not change)")
323
+ .option("--overwrite", "replace a file already at the destination")
324
+ .option("--if-match <etag>", "only move if the file is still at this revision")
325
+ .option("--note <ref>", "the note: slug, id or exact title")
326
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
327
+ .option("--json", "emit JSON")
328
+ .action(async (file, to, opts) => { process.exitCode = await runFilesMove(file, to, opts); });
329
+ strict(files.command("cp"))
330
+ .argument("<file>", "file id or path")
331
+ .argument("<to>", "new path within the note")
332
+ .description("copy to another path (its own storage, not a share)")
333
+ .option("--idempotency-key <key>", "keep one original text/copy operation for recovery")
334
+ .option("--overwrite", "replace a file already at the destination")
335
+ .option("--note <ref>", "the note: slug, id or exact title")
336
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
337
+ .option("--json", "emit JSON")
338
+ .action(async (file, to, opts) => { process.exitCode = await runFilesCopy(file, to, opts); });
339
+ for (const [action, description] of [
340
+ ["status", "inspect an attachment operation"],
341
+ ["reconcile", "recover original staged bytes without reuploading"],
342
+ ["cancel", "cancel an operation only before upload authorization"],
343
+ ]) {
344
+ strict(files.command(action))
345
+ .argument("<operation>", "operation ID from the original response")
346
+ .description(description)
347
+ .option("--note <ref>", "the note: slug, id or exact title")
348
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
349
+ .option("--json", "emit JSON")
350
+ .action(async (operation, opts) => { process.exitCode = await runFilesOperation(action, operation, opts); });
351
+ }
352
+ strict(files.command("rm"))
353
+ .argument("<file>", "file id or path")
354
+ .description("move a file to the trash; --purge deletes the bytes for good")
355
+ .option("--purge", "delete the stored bytes — not recoverable")
356
+ .option("--if-match <etag>", "only delete if the file is still at this revision")
357
+ .option("--note <ref>", "the note: slug, id or exact title")
358
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
359
+ .option("--json", "emit JSON")
360
+ .action(async (file, opts) => { process.exitCode = await runFilesRm(file, opts); });
361
+ strict(files.command("restore"))
362
+ .argument("<file>", "file id")
363
+ .description("bring a file back from the trash")
364
+ .option("--path <path>", "restore it here instead of where it was")
365
+ .option("--note <ref>", "the note: slug, id or exact title")
366
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
367
+ .option("--json", "emit JSON")
368
+ .action(async (file, opts) => { process.exitCode = await runFilesRestore(file, opts); });
369
+ strict(files.command("preview"))
370
+ .argument("<file>", "file id or path within the note")
371
+ .description("print a link that renders this file")
372
+ .option("--share", "a link that opens without signing in, until revoked")
373
+ .option("--revoke", "withdraw the shared link; every copy stops working")
374
+ .option("--open", "open the link in a browser")
375
+ .option("--note <ref>", "the note: slug, id or exact title")
376
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
377
+ .option("--json", "emit JSON")
378
+ .action(async (file, opts) => { process.exitCode = await runFilesPreview(file, opts); });
379
+ // ── notes sections ──
380
+ strict(notes.command("sections"))
381
+ .argument("<note>", "note id, slug or name")
382
+ .description("list the addressable sections (a heading plus everything under it)")
383
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
384
+ .option("--json", "emit JSON")
385
+ .action(async (ref, opts) => { process.exitCode = await runNotesSections(ref, opts); });
386
+ // ── notes read ──
387
+ strict(notes.command("read"))
388
+ .option("--start-line <n>", "first line to read (1-based, inclusive)")
389
+ .option("--end-line <n>", "last line to read (1-based, inclusive)")
390
+ // Positional OR --note. The issue's examples use `--note`, matching the
391
+ // edit commands; the positional came first and scripts use it. Accepting
392
+ // one form and rejecting the other would make half the documented recipes
393
+ // fail on a flag rather than on anything real.
394
+ .argument("[note]", "note id, slug or name (or pass --note)")
395
+ .option("--note <ref>", "the note to read, as an alternative to the positional")
396
+ .description("read canonical source or a mapped HTML snapshot with its write revision")
397
+ .option("--linger", "stay present and stream batched diffs, presence and activity in the foreground")
398
+ .option("--debounce <duration>", "edit quiet period with --linger (default 2s; 250ms–5m)")
399
+ .option("--throttle <duration>", "minimum output interval with --linger (default 2s; 250ms–5m)")
400
+ .option("--intent <text>", "with --linger: one short sentence of purpose, shown on your presence card")
401
+ .option("--view <view>", "source (default), html with source attributes, or markdown with address hints")
402
+ .option("--version <version-id>", "read an immutable saved version instead of the live note")
403
+ .option("--at <revision>", "read a retained snapshot without advancing to the current revision")
404
+ .option("--toc", "read only the heading outline as mapped HTML")
405
+ .option("--tag <id>", "read one mapped HTML element by its exact id")
406
+ .option("--since <ref>", "return changes since a retained hash or time")
407
+ .option("--format <format>", "incremental format: diff (default) or inline-dff")
408
+ .option("--legacy", "use the previous body-only/etag interface")
409
+ .option("--section <anchor>", "print only this section")
410
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
411
+ .option("-n, --numbered", "prefix each line with its number, like `cat -n`")
412
+ .option("--json", "emit exact content, SHA-256 hash and opaque write revision")
413
+ .option("--if-match <etag>", "verify: fail unless the note is still at this revision")
414
+ .action(async (ref, opts) => { process.exitCode = await runNotesRead(ref, opts); });
415
+ // ── notes diff ──
416
+ strict(notes.command("diff"))
417
+ .argument("[note]", "note id, slug or name (or pass --note)")
418
+ .option("--note <ref>", "the note to compare, as an alternative to the positional")
419
+ .description("alias for read --since; does not advance an existing draft baseline")
420
+ .option("--format <format>", "diff (default) or inline-dff")
421
+ .option("--legacy", "use the previous diff/etag interface")
422
+ .requiredOption("--since <ref>", "retained content hash or time reference")
423
+ .option("--context <n>", "legacy unchanged context lines per hunk (0–100)")
424
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
425
+ .option("--json", "emit base/hash/revision and selected patch format")
426
+ .action(async (ref, opts) => { process.exitCode = await runNotesDiff(ref, opts); });
427
+ // ── notes write ──
428
+ strict(notes.command("write"))
429
+ .argument("<note>", "note id, slug or name")
430
+ .description("replace the whole body — or one section with --section")
431
+ .option("--section <anchor>", "replace only this section (heading included in the text)")
432
+ .option("--file <path>", "read the text from a file ('-' for stdin)")
433
+ .option("--text <string>", "the text, inline")
434
+ .option("--if-match <etag>", "only write if the note is still at this etag")
435
+ .option("--force", "retained legacy write without a precondition — overwrites concurrent edits")
436
+ .option("--legacy", "use the retained ETag/body replacement write")
437
+ .option("--base-revision <revision>", "compare the target body to this original retained source snapshot")
438
+ .option("--exact", "require the original revision to remain current")
439
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
440
+ .option("--json", "emit JSON")
441
+ .option("--dry-run", "show the write that would be sent, and send nothing")
442
+ .action(async (ref, opts) => { process.exitCode = await runNotesWrite(ref, opts); });
443
+ // ── notes append ──
444
+ strict(notes.command("append"))
445
+ .argument("<note>", "note id, slug or name")
446
+ .description("add text to the end of the body")
447
+ .option("--file <path>", "read the text from a file ('-' for stdin)")
448
+ .option("--text <string>", "the text, inline")
449
+ .option("--force", "retained legacy append without a precondition")
450
+ .option("--legacy", "use the retained ETag/body replacement append")
451
+ .option("--base-revision <revision>", "append against this original retained source snapshot")
452
+ .option("--exact", "require the original revision to remain current")
453
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
454
+ .option("--json", "emit JSON")
455
+ .option("--dry-run", "show the write that would be sent, and send nothing")
456
+ .action(async (ref, opts) => { process.exitCode = await runNotesAppend(ref, opts); });
457
+ // ── notes patch ──
458
+ strict(notes.command("patch"))
459
+ .argument("<note>", "note id, slug or name")
460
+ .description("apply a source patch to its original RTC identities; merge by default, exact revision checks opt-in")
461
+ .option("--format <format>", "inline-dff (default) or diff")
462
+ .option("--legacy", "use the previous unified diff/etag interface")
463
+ .option("--file <path>", "read the diff from a file ('-' for stdin)")
464
+ .option("--diff <string>", "the diff, inline")
465
+ .option("--exact", "require the current note to match the original revision for this request")
466
+ .option("--base-revision <revision>", "original saved snapshot used to validate source and RTC identities")
467
+ .option("--if-match <revision>", "compatibility exact-mode token; must match --base-revision when both are given")
468
+ .option("--force", "legacy only: apply without a precondition")
469
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
470
+ .option("--json", "emit JSON")
471
+ .option("--dry-run", "show the write that would be sent, and send nothing")
472
+ .action(async (ref, opts) => { process.exitCode = await runNotesPatch(ref, opts); });
473
+ // ── notes add-section ──
474
+ strict(notes.command("add-section"))
475
+ .argument("<note>", "note id, slug or name")
476
+ .description("add a section (default: at the end) — pairs with rm-section")
477
+ .option("--before <anchor>", "place it before this section")
478
+ .option("--after <anchor>", "place it after this section and its subsections")
479
+ .option("--file <path>", "the section text from a file ('-' for stdin)")
480
+ .option("--text <string>", "the section text, inline")
481
+ .option("--if-match <etag>", "only insert if the note is still at this etag")
482
+ .option("--force", "insert without a precondition")
483
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
484
+ .option("--json", "emit JSON")
485
+ .option("--dry-run", "show the write that would be sent, and send nothing")
486
+ .action(async (ref, opts) => { process.exitCode = await runNotesAddSection(ref, opts); });
487
+ // ── notes rm-section ──
488
+ // ── Editing: locate, then change, as one conditional write ──────────────
489
+ // Query stays the first positional argument, matching `search` above;
490
+ // `--text` is the replacement. The SDK puts the replacement first — a
491
+ // deliberate difference, documented, because reversing either one would
492
+ // break the reading habit its own users already have.
493
+ strict(notes.command("find"))
494
+ .description("find text in a note — literal by default, --regex for patterns")
495
+ .argument("[query]", "literal text to find")
496
+ .option("--note <ref>", "the note: slug, id or exact title")
497
+ .option("--regex <pattern>", "search with a JavaScript regular expression")
498
+ .option("--flags <flags>", "regex flags: i, m, s, u (not g — see --all)")
499
+ .option("--limit <n>", "stop after this many matches")
500
+ .option("--json", "emit matches with the source revision")
501
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
502
+ .action(async (query, opts) => { process.exitCode = await runNotesFind(query, opts); });
503
+ strict(notes.command("toc"))
504
+ .description("the note's outline, with line and character ranges")
505
+ .option("--note <ref>", "the note: slug, id or exact title")
506
+ .option("--html", "parse as HTML rather than Markdown")
507
+ .option("--json", "emit entries with the source revision")
508
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
509
+ .action(async (opts) => { process.exitCode = await runNotesToc(opts); });
510
+ strict(notes.command("replace"))
511
+ .description("replace text; one match required unless --all or --count")
512
+ .argument("[query]", "literal text to replace")
513
+ .option("--note <ref>", "the note: slug, id or exact title")
514
+ .option("--text <text>", "the replacement")
515
+ .option("--selector <css>", "scope the query to one HTML element")
516
+ .option("--regex <pattern>", "match with a JavaScript regular expression")
517
+ .option("--flags <flags>", "regex flags: i, m, s, u")
518
+ .option("--line <n|n:m>", "replace whole lines (1-based, inclusive)")
519
+ .option("--ind <n|n:m>", "replace a character range (0-based code points, end-exclusive)")
520
+ .option("--count <n>", "require exactly this many matches")
521
+ .option("--all", "replace every match")
522
+ .option("--if-match <etag>", "quoted ETag from notes read --legacy --json (not an rtc: revision)")
523
+ .option("--force", "retained legacy replacement without a precondition")
524
+ .option("--legacy", "use the retained ETag/body replacement replace")
525
+ .option("--base-revision <revision>", "target this original retained source snapshot")
526
+ .option("--exact", "require the original revision to remain current")
527
+ .option("--dry-run", "print what would be written and stop")
528
+ .option("--json", "emit the new revision")
529
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
530
+ .option("--html <markup>", "with --selector: replace the element's contents with markup (not escaped)")
531
+ .action(async (query, opts) => { process.exitCode = await runNotesReplace(query, opts); });
532
+ strict(notes.command("insert"))
533
+ .description("insert text at a line or character position")
534
+ .option("--note <ref>", "the note: slug, id or exact title")
535
+ .option("--text <text>", "what to insert")
536
+ .option("--line <n>", "insert before this line (1-based)")
537
+ .option("--ind <n>", "insert at this character position (0-based code points)")
538
+ .option("--if-match <etag>", "quoted ETag from notes read --legacy --json (not an rtc: revision)")
539
+ .option("--force", "retained legacy replacement without a precondition")
540
+ .option("--legacy", "use the retained ETag/body replacement insert")
541
+ .option("--base-revision <revision>", "place text in this original retained source snapshot")
542
+ .option("--exact", "require the original revision to remain current")
543
+ .option("--dry-run", "print what would be written and stop")
544
+ .option("--json", "emit the new revision")
545
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
546
+ .option("--selector <css>", "insert relative to this element instead of a line")
547
+ .option("--position <where>", "with --selector: before | after | prepend | append", "append")
548
+ .action(async (opts) => { process.exitCode = await runNotesInsert(opts); });
549
+ strict(notes.command("delete"))
550
+ .description("remove text; one match required unless --all or --count")
551
+ .argument("[query]", "literal text to remove")
552
+ .option("--note <ref>", "the note: slug, id or exact title")
553
+ .option("--selector <css>", "scope the query to one HTML element")
554
+ .option("--regex <pattern>", "match with a JavaScript regular expression")
555
+ .option("--flags <flags>", "regex flags: i, m, s, u")
556
+ .option("--line <n|n:m>", "remove whole lines (1-based, inclusive)")
557
+ .option("--ind <n|n:m>", "remove a character range (0-based code points)")
558
+ .option("--count <n>", "require exactly this many matches")
559
+ .option("--all", "remove every match")
560
+ .option("--if-match <etag>", "quoted ETag from notes read --legacy --json (not an rtc: revision)")
561
+ .option("--force", "retained legacy replacement without a precondition")
562
+ .option("--legacy", "use the retained ETag/body replacement delete")
563
+ .option("--base-revision <revision>", "target this original retained source snapshot")
564
+ .option("--exact", "require the original revision to remain current")
565
+ .option("--dry-run", "print what would be written and stop")
566
+ .option("--json", "emit the new revision")
567
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
568
+ .action(async (query, opts) => { process.exitCode = await runNotesDelete(query, opts); });
569
+ strict(notes.command("select"))
570
+ .description("publish an agent selection with --text, or report one HTML element by CSS")
571
+ .argument("[css]", "a CSS selector matching exactly one element (lookup only)")
572
+ .option("--text <literal>", "select exact canonical source text visibly as the agent")
573
+ .option("--section <anchor>", "match only inside this section (requires --text)")
574
+ .option("-o, --occurrence <n>", "occurrence within scope: 1 is first, -1 is last, -2 is second-last")
575
+ .option("--hash <sha256>", "require this current source hash before publishing")
576
+ .option("--note <ref>", "the note: slug, id or exact title")
577
+ .option("--json", "emit the selection receipt, or CSS element with source revision")
578
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
579
+ .action(async (css, opts) => {
580
+ if (opts.text !== undefined || !css || opts.section !== undefined || opts.occurrence !== undefined || opts.hash !== undefined) {
581
+ process.exitCode = await runNotesTextSelect(css, opts);
582
+ }
583
+ else {
584
+ process.exitCode = await runNotesSelect(css, opts);
585
+ }
586
+ });
587
+ strict(notes.command("rm-section"))
588
+ .argument("<note>", "note id, slug or name")
589
+ .argument("<anchor>", "the section to remove, and everything under it")
590
+ .description("remove a section and everything under it")
591
+ .option("--if-match <etag>", "only remove if the note is still at this etag")
592
+ .option("--force", "remove without a precondition")
593
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
594
+ .option("--json", "emit JSON")
595
+ .option("--dry-run", "show the write that would be sent, and send nothing")
596
+ .action(async (ref, anchor, opts) => { process.exitCode = await runNotesRmSection(ref, anchor, opts); });
597
+ }
598
+ // ─── implementations ──────────────────────────────────────────────────────────
599
+ export async function runNotesList(opts) {
600
+ const c = await ctx(opts);
601
+ if (!c)
602
+ return 1;
603
+ try {
604
+ const rows = opts.shared
605
+ ? (await requestJson(c.remote, "/me/notes/shared", { token: c.token })).notes
606
+ : (await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes?limit=${encodeURIComponent(opts.limit ?? "50")}`, { token: c.token })).notes;
607
+ if (opts.json)
608
+ return emitJson({ notes: rows }), 0;
609
+ if (rows.length === 0) {
610
+ // Name the namespace. Without a --namespace the default is your PERSONAL
611
+ // one, and an org's notes live somewhere else entirely — a bare "no
612
+ // notes" reads as "there are none" when it means "none here".
613
+ process.stdout.write(opts.shared
614
+ ? "no notes shared with you\n"
615
+ : `no notes in '${c.ns}'\n an organization's notes are in its own namespace — ` +
616
+ `'dreamlake org list' shows yours, then --namespace <slug>\n`);
617
+ return 0;
618
+ }
619
+ process.stdout.write(opts.shared
620
+ ? renderTable(rows.map((n) => ({
621
+ NOTE: n.name || "untitled",
622
+ NAMESPACE: n.namespaceSlug ?? "",
623
+ "SHARED BY": n.owner?.name ?? "",
624
+ ID: n.id,
625
+ })), ["NOTE", "NAMESPACE", "SHARED BY", "ID"])
626
+ : renderTable(rows.map((n) => ({
627
+ NOTE: n.name || "untitled",
628
+ SLUG: n.slug,
629
+ UPDATED: n.updatedAt?.slice(0, 10) ?? "",
630
+ ID: n.id,
631
+ })), ["NOTE", "SLUG", "UPDATED", "ID"]));
632
+ return 0;
633
+ }
634
+ catch (e) {
635
+ return report(e);
636
+ }
637
+ }
638
+ export async function runNotesSearch(query, opts) {
639
+ const c = await ctx(opts);
640
+ if (!c)
641
+ return 1;
642
+ try {
643
+ const res = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes?q=${seg(query)}&limit=${encodeURIComponent(opts.limit ?? "50")}`, { token: c.token });
644
+ if (opts.json)
645
+ return emitJson(res), 0;
646
+ if (res.notes.length === 0) {
647
+ // Name both the query and the namespace: an empty result should read as
648
+ // "not in these notes", and the reader should be able to tell that the
649
+ // search was scoped somewhere they may not have meant.
650
+ process.stdout.write(`no note in '${c.ns}' has '${query}' in its title or body\n` +
651
+ ` other namespaces are searched separately — 'dreamlake org list', then --namespace <slug>\n`);
652
+ return 0;
653
+ }
654
+ process.stdout.write(renderTable(res.notes.map((n) => ({
655
+ NOTE: n.name || "untitled",
656
+ SLUG: n.slug,
657
+ UPDATED: n.updatedAt?.slice(0, 10) ?? "",
658
+ ID: n.id,
659
+ })), ["NOTE", "SLUG", "UPDATED", "ID"]));
660
+ // Where inside each note it matched. Without this a caller has to read the
661
+ // whole note to find the part it was looking for — which is the work the
662
+ // section commands exist to remove.
663
+ for (const n of res.notes) {
664
+ if (!n.matches?.length)
665
+ continue;
666
+ process.stdout.write(`\n${n.slug}\n`);
667
+ for (const m of n.matches) {
668
+ process.stdout.write(` ${m.anchor} ${m.snippet}\n`);
669
+ }
670
+ }
671
+ return 0;
672
+ }
673
+ catch (e) {
674
+ return report(e);
675
+ }
676
+ }
677
+ export async function runNotesSections(ref, opts) {
678
+ const c = await ctx(opts);
679
+ if (!c)
680
+ return 1;
681
+ try {
682
+ const id = await resolveNote(c, ref);
683
+ if (!id)
684
+ return 1;
685
+ const res = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(id)}/sections`, { token: c.token });
686
+ if (opts.json)
687
+ return emitJson(res), 0;
688
+ if (res.sections.length === 0) {
689
+ process.stdout.write("no sections — the note is empty\n");
690
+ return 0;
691
+ }
692
+ process.stdout.write(renderTable(res.sections.map((s) => ({
693
+ ANCHOR: s.anchor,
694
+ LEVEL: String(s.level),
695
+ // Indent by level so the outline reads as one.
696
+ TITLE: `${" ".repeat(Math.max(0, s.level - 1))}${s.title || "(preamble)"}`,
697
+ CHARS: String(s.end - s.start),
698
+ })), ["ANCHOR", "LEVEL", "TITLE", "CHARS"]));
699
+ return 0;
700
+ }
701
+ catch (e) {
702
+ return report(e);
703
+ }
704
+ }
705
+ async function runLegacyNotesRead(ref, opts) {
706
+ const target = ref ?? opts.note;
707
+ if (!target) {
708
+ fail("say which note: a note id, slug or name, or --note <ref>");
709
+ return 1;
710
+ }
711
+ if (ref && opts.note && ref !== opts.note) {
712
+ // Two different notes named in one command. Picking either would edit
713
+ // something the caller did not ask for.
714
+ fail(`two notes given: '${ref}' and --note '${opts.note}' — give one`);
715
+ return 1;
716
+ }
717
+ const c = await ctx(opts);
718
+ if (!c)
719
+ return 1;
720
+ try {
721
+ const id = await resolveNote(c, target);
722
+ if (!id)
723
+ return 1;
724
+ const range = new URLSearchParams();
725
+ if (opts.startLine !== undefined)
726
+ range.set("startLine", opts.startLine);
727
+ if (opts.endLine !== undefined)
728
+ range.set("endLine", opts.endLine);
729
+ const qs = range.toString();
730
+ const path = opts.section
731
+ ? `/namespaces/${seg(c.ns)}/notes/${seg(id)}/sections/${seg(opts.section)}`
732
+ : `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body${qs ? `?${qs}` : ""}`;
733
+ const res = await requestJson(c.remote, path, {
734
+ token: c.token,
735
+ });
736
+ // A verification read: used after a write to check the surrounding source
737
+ // survived. Without the guard it reads whatever is there NOW, the check
738
+ // passes, and what it checked is somebody else's document.
739
+ if (opts.ifMatch && res.etag !== opts.ifMatch) {
740
+ fail(`note is at ${res.etag}, not ${opts.ifMatch} — it changed since that revision`);
741
+ return EXIT_STALE;
742
+ }
743
+ if (opts.json)
744
+ return emitJson(res), 0;
745
+ // Body only, no decoration: this is meant to be redirected into a file or
746
+ // piped into something else. `--numbered` is the exception, and it has to
747
+ // be asked for precisely because it makes the output no longer the body.
748
+ if (opts.numbered) {
749
+ // Numbers come from the response, not from counting output lines: with a
750
+ // range, output line 1 is not document line 1, and numbering it as such
751
+ // would send an agent to edit the wrong line.
752
+ const first = res.startLine ?? 1;
753
+ const lines = res.text.split("\n");
754
+ // A trailing newline produces a final empty element that is not a line.
755
+ if (lines.length && lines[lines.length - 1] === "")
756
+ lines.pop();
757
+ const width = String(first + lines.length - 1).length;
758
+ for (let i = 0; i < lines.length; i++) {
759
+ process.stdout.write(`${String(first + i).padStart(width)}\t${lines[i]}\n`);
760
+ }
761
+ }
762
+ else {
763
+ process.stdout.write(res.text);
764
+ }
765
+ // The one exception, and it goes to STDERR so it cannot end up in the
766
+ // file: a partial read that looks complete is how a caller rewrites a
767
+ // fragment and posts it back as the whole body.
768
+ if (res.truncated) {
769
+ const r = res;
770
+ process.stderr.write(`note: showing lines through ${r.endLine} of ${r.totalLines} — this is not the whole note\n`);
771
+ }
772
+ return 0;
773
+ }
774
+ catch (e) {
775
+ return report(e);
776
+ }
777
+ }
778
+ /**
779
+ * `--dry-run`: show the write that would be sent, and send nothing.
780
+ *
781
+ * Uniformly "the request", not "the resulting document". For the commands that
782
+ * compute the edit locally those are the same thing; for the ones the server
783
+ * applies (append, patch, sections) the CLI does not know the result, and
784
+ * computing it here would be a second implementation of the server's rules
785
+ * that could disagree with it — a preview that lies is worse than no preview.
786
+ *
787
+ * Goes to stdout so it can be diffed or saved; the precondition is included
788
+ * because "which revision would this have been written against" is the other
789
+ * half of what a reviewer needs.
790
+ */
791
+ function previewWrite(opts, req) {
792
+ if (opts.json) {
793
+ emitJson({ dryRun: true, ...req });
794
+ return 0;
795
+ }
796
+ const pre = req.headers["If-Match"] ?? "(none — would overwrite unconditionally)";
797
+ process.stderr.write(`would ${req.method} ${req.path}\n if-match ${pre}\n`);
798
+ const body = req.payload;
799
+ const text = typeof body?.text === "string" ? body.text
800
+ : typeof body?.diff === "string" ? body.diff
801
+ : JSON.stringify(body, null, 2);
802
+ process.stdout.write(text.endsWith("\n") ? text : text + "\n");
803
+ return 0;
804
+ }
805
+ export async function runNotesWrite(ref, opts) {
806
+ // Section write remains its explicitly selected retained interface, not a
807
+ // modern whole-body write with an inferred or silently changed target.
808
+ const compatibility = opts.section !== undefined || opts.legacy || opts.force || opts.ifMatch !== undefined;
809
+ if (compatibility) {
810
+ if (opts.baseRevision !== undefined || opts.exact) {
811
+ fail("--section/--legacy/--force/--if-match cannot combine with --base-revision or --exact");
812
+ return 1;
813
+ }
814
+ return runLegacyNotesWrite(ref, opts);
815
+ }
816
+ if (opts.baseRevision !== undefined && (!opts.baseRevision.trim() || opts.baseRevision === "*" || /[\r\n]/.test(opts.baseRevision))) {
817
+ fail("--base-revision requires the original retained revision");
818
+ return 1;
819
+ }
820
+ let text;
821
+ try {
822
+ text = await bodyFrom(opts, true);
823
+ }
824
+ catch (error) {
825
+ return report(error);
826
+ }
827
+ if (text === null)
828
+ return 1;
829
+ const c = await ctx(opts);
830
+ if (!c)
831
+ return 1;
832
+ if (looksLikeDiff(text))
833
+ process.stderr.write("⚠ this looks like a unified diff — 'dreamlake notes patch' applies one; 'write' stores it as the body\n");
834
+ try {
835
+ const id = await resolveNote(c, ref);
836
+ if (!id)
837
+ return 1;
838
+ const source = await readDocumentSnapshot(c, id, opts.baseRevision);
839
+ const edits = characterDiff(source.content, text);
840
+ const payload = documentEdits(source, edits.map(edit => ({ start: edit.start, end: edit.end, text: edit.replacementText })), opts.exact);
841
+ if (edits.length > PATCH_LIMITS.maxEdits || Buffer.byteLength(payload.patch, "utf8") > PATCH_LIMITS.maxPatchBytes) {
842
+ throw new NotePatchError("Generated source patch exceeds the edit/byte limit", "LIMIT_EXCEEDED");
843
+ }
844
+ if (opts.dryRun) {
845
+ const path = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`;
846
+ if (opts.json)
847
+ emitJson({ dryRun: true, method: "PATCH", path, headers: {}, payload, text, ...(!payload.patch ? { noChange: true } : {}) });
848
+ else {
849
+ process.stderr.write(`would ${payload.patch || opts.exact ? "PATCH" : "not change"} ${path}\n mode ${payload.mode}\n base-revision ${source.revision}\n`);
850
+ process.stdout.write(text.endsWith("\n") ? text : text + "\n");
851
+ }
852
+ return 0;
853
+ }
854
+ if (!payload.patch && !opts.exact) {
855
+ if (opts.json)
856
+ emitJson({ note: id, hash: source.hash, revision: source.revision, noChange: true });
857
+ else
858
+ process.stdout.write(`note: ${id}\nhash: ${source.hash}\nrevision: ${source.revision}\nno change\n`);
859
+ return 0;
860
+ }
861
+ printPatchReceipt(await submitDocumentPatch(c, id, payload), opts.json);
862
+ return 0;
863
+ }
864
+ catch (error) {
865
+ if (error instanceof NotePatchError) {
866
+ fail(`${error.code}: ${error.message}; keep the original baseline and draft`);
867
+ return 5;
868
+ }
869
+ return documentWriteError(error);
870
+ }
871
+ }
872
+ async function runLegacyNotesWrite(ref, opts) {
873
+ const c = await ctx(opts);
874
+ if (!c)
875
+ return 1;
876
+ const text = await bodyFrom(opts);
877
+ if (text === null)
878
+ return 1;
879
+ if (looksLikeDiff(text)) {
880
+ // A warning, not a refusal: a note ABOUT diffs is a real thing to write.
881
+ //
882
+ // On stderr, and not through helpers' `warn`, which prints to stdout —
883
+ // that would land inside `--json` output and break anything parsing it.
884
+ process.stderr.write("⚠ this looks like a unified diff — 'dreamlake notes patch' applies one; " +
885
+ "'write' stores it as the body\n");
886
+ }
887
+ try {
888
+ const id = await resolveNote(c, ref);
889
+ if (!id)
890
+ return 1;
891
+ const headers = await validator(c, id, opts);
892
+ // No line range here on purpose: a PUT replaces the whole body, and an
893
+ // option that looked like "write these lines" would delete the rest.
894
+ const path = opts.section
895
+ ? `/namespaces/${seg(c.ns)}/notes/${seg(id)}/sections/${seg(opts.section)}`
896
+ : `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`;
897
+ if (opts.dryRun) {
898
+ return previewWrite(opts, { method: "PUT", path, payload: { text }, headers });
899
+ }
900
+ const res = await requestJson(c.remote, path, {
901
+ method: "PUT",
902
+ json: { text },
903
+ headers,
904
+ token: c.token,
905
+ });
906
+ if (opts.json)
907
+ return emitJson(res), 0;
908
+ process.stdout.write(`✓ wrote ${opts.section ? `section '${opts.section}' of ` : ""}${ref} (${res.sizeBytes} bytes)\n etag ${res.etag}\n`);
909
+ return 0;
910
+ }
911
+ catch (e) {
912
+ return report(e);
913
+ }
914
+ }
915
+ /** Compare a retained read/edit ref without choosing or advancing a baseline. */
916
+ async function runLegacyNotesDiff(ref, opts) {
917
+ const target = ref ?? opts.note;
918
+ if (!target || (ref && opts.note && ref !== opts.note)) {
919
+ fail("give one note id, slug or name, either positionally or with --note");
920
+ return 1;
921
+ }
922
+ if (!opts.since || !/^(?:[a-f0-9]{64}|"[a-f0-9]{64}")$/.test(opts.since)) {
923
+ fail("--since must be the SHA-256 etag returned by a read or successful edit");
924
+ return 1;
925
+ }
926
+ const context = opts.context ?? "3";
927
+ if (!/^\d+$/.test(context) || Number(context) > 100) {
928
+ fail("--context must be an integer between 0 and 100");
929
+ return 1;
930
+ }
931
+ const c = await ctx(opts);
932
+ if (!c)
933
+ return 1;
934
+ try {
935
+ const id = await resolveNote(c, target);
936
+ if (!id)
937
+ return 1;
938
+ const query = new URLSearchParams({ since: opts.since, context });
939
+ const result = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(id)}/diff?${query}`, { token: c.token });
940
+ if (opts.json)
941
+ return emitJson(result), 0;
942
+ process.stdout.write(result.diff);
943
+ process.stderr.write(`etag ${result.etag}\n`);
944
+ return 0;
945
+ }
946
+ catch (e) {
947
+ return report(e);
948
+ }
949
+ }
950
+ async function runLegacyNotesPatch(ref, opts) {
951
+ const c = await ctx(opts);
952
+ if (!c)
953
+ return 1;
954
+ const diff = await bodyFrom({ file: opts.file, text: opts.diff });
955
+ if (diff === null)
956
+ return 1;
957
+ if (!diff.trim()) {
958
+ fail("the diff is empty");
959
+ return 1;
960
+ }
961
+ try {
962
+ const id = await resolveNote(c, ref);
963
+ if (!id)
964
+ return 1;
965
+ const headers = await validator(c, id, opts);
966
+ const path = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`;
967
+ if (opts.dryRun)
968
+ return previewWrite(opts, { method: "PATCH", path, payload: { diff }, headers });
969
+ const res = await requestJson(c.remote, path, { method: "PATCH", json: { diff }, headers, token: c.token });
970
+ if (opts.json)
971
+ return emitJson(res), 0;
972
+ process.stdout.write(`✓ patched ${ref} (${res.sizeBytes} bytes)\n etag ${res.etag}\n`);
973
+ return 0;
974
+ }
975
+ catch (e) {
976
+ return report(e);
977
+ }
978
+ }
979
+ export async function runNotesAppend(ref, opts) {
980
+ if (opts.legacy || opts.force) {
981
+ if (opts.baseRevision !== undefined || opts.exact) {
982
+ fail("--legacy/--force cannot combine with --base-revision or --exact");
983
+ return 1;
984
+ }
985
+ return runLegacyNotesAppend(ref, opts);
986
+ }
987
+ if (opts.baseRevision !== undefined && (!opts.baseRevision.trim() || opts.baseRevision === "*" || /[\r\n]/.test(opts.baseRevision))) {
988
+ fail("--base-revision requires the original retained revision");
989
+ return 1;
990
+ }
991
+ const c = await ctx(opts);
992
+ if (!c)
993
+ return 1;
994
+ const addition = await bodyFrom(opts);
995
+ if (addition === null)
996
+ return 1;
997
+ try {
998
+ const id = await resolveNote(c, ref);
999
+ if (!id)
1000
+ return 1;
1001
+ const current = await readDocumentSnapshot(c, id, opts.baseRevision);
1002
+ const suffix = (current.content && !current.content.endsWith("\n") ? "\n" : "") + addition;
1003
+ const mode = opts.exact ? "exact" : "merge";
1004
+ const headers = {};
1005
+ const path = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`;
1006
+ const payload = documentInsertion(current, Array.from(current.content).length, suffix, opts.exact);
1007
+ if (opts.dryRun) {
1008
+ if (opts.json)
1009
+ emitJson({ dryRun: true, method: "PATCH", path, headers, payload, ...(suffix ? {} : { noChange: true }) });
1010
+ else {
1011
+ process.stderr.write(`would ${suffix ? "PATCH" : "not change"} ${path}\n mode ${mode}\n base-revision ${current.revision}\n`);
1012
+ const preview = current.content + suffix;
1013
+ process.stdout.write(preview.endsWith("\n") ? preview : preview + "\n");
1014
+ }
1015
+ return 0;
1016
+ }
1017
+ if (!suffix) {
1018
+ if (opts.json)
1019
+ emitJson({ note: id, hash: current.hash, revision: current.revision, noChange: true });
1020
+ else
1021
+ process.stdout.write(`note: ${id}\nhash: ${current.hash}\nrevision: ${current.revision}\nno change\n`);
1022
+ return 0;
1023
+ }
1024
+ printPatchReceipt(await submitDocumentPatch(c, id, payload), opts.json);
1025
+ return 0;
1026
+ }
1027
+ catch (error) {
1028
+ return documentWriteError(error);
1029
+ }
1030
+ }
1031
+ async function runLegacyNotesAppend(ref, opts) {
1032
+ const c = await ctx(opts);
1033
+ if (!c)
1034
+ return 1;
1035
+ const addition = await bodyFrom(opts);
1036
+ if (addition === null)
1037
+ return 1;
1038
+ try {
1039
+ const id = await resolveNote(c, ref);
1040
+ if (!id)
1041
+ return 1;
1042
+ // Read and write in one command, but still conditionally: the ETag from
1043
+ // this read guards the write, so two appends racing cannot lose one.
1044
+ const current = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`, { token: c.token });
1045
+ const base = current.text && !current.text.endsWith("\n") ? current.text + "\n" : current.text;
1046
+ const path = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`;
1047
+ const headers = opts.force ? {} : { "If-Match": current.etag };
1048
+ // This one CAN show the result: the append is computed here, from a body
1049
+ // it just read.
1050
+ if (opts.dryRun) {
1051
+ return previewWrite(opts, { method: "PUT", path, payload: { text: base + addition }, headers });
1052
+ }
1053
+ const res = await requestJson(c.remote, path, { method: "PUT", json: { text: base + addition }, headers, token: c.token });
1054
+ if (opts.json)
1055
+ return emitJson(res), 0;
1056
+ process.stdout.write(`✓ appended to ${ref} (${res.sizeBytes} bytes)\n etag ${res.etag}\n`);
1057
+ return 0;
1058
+ }
1059
+ catch (e) {
1060
+ return report(e);
1061
+ }
1062
+ }
1063
+ export async function runNotesCreate(name, opts) {
1064
+ const c = await ctx(opts);
1065
+ if (!c)
1066
+ return 1;
1067
+ // Only when one was offered: an empty note is a legitimate thing to create,
1068
+ // so absence must not be read as "waiting on stdin".
1069
+ const wants = opts.file !== undefined || opts.text !== undefined;
1070
+ const body = wants ? await bodyFrom(opts) : "";
1071
+ if (body === null)
1072
+ return 1;
1073
+ try {
1074
+ const created = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes`, {
1075
+ method: "POST",
1076
+ json: { name, visibility: opts.public ? "public" : "private", ...(opts.project?.length ? { projects: [...new Set(opts.project)] } : {}) },
1077
+ token: c.token,
1078
+ });
1079
+ const id = created.note.id;
1080
+ let etag;
1081
+ if (body) {
1082
+ // Unconditional: the note is one request old and there is nothing yet
1083
+ // for anyone else to have changed.
1084
+ const w = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`, { method: "PUT", json: { text: body }, token: c.token });
1085
+ etag = w.etag;
1086
+ }
1087
+ if (opts.json)
1088
+ return emitJson({ ...created.note, etag }), 0;
1089
+ // The slug can differ from the title — duplicates take a suffix — so print
1090
+ // what was actually created rather than what was asked for.
1091
+ process.stdout.write(`✓ created ${created.note.slug}\n id ${id}\n`);
1092
+ return 0;
1093
+ }
1094
+ catch (e) {
1095
+ return report(e);
1096
+ }
1097
+ }
1098
+ export async function runNotesAddSection(ref, opts) {
1099
+ if (opts.before && opts.after) {
1100
+ fail("pass --before or --after, not both");
1101
+ return 1;
1102
+ }
1103
+ const c = await ctx(opts);
1104
+ if (!c)
1105
+ return 1;
1106
+ const text = await bodyFrom(opts);
1107
+ if (text === null)
1108
+ return 1;
1109
+ try {
1110
+ const id = await resolveNote(c, ref);
1111
+ if (!id)
1112
+ return 1;
1113
+ const headers = await validator(c, id, opts);
1114
+ const sectionPath = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/sections`;
1115
+ const payload = {
1116
+ text,
1117
+ ...(opts.before ? { before: opts.before } : {}),
1118
+ ...(opts.after ? { after: opts.after } : {}),
1119
+ };
1120
+ if (opts.dryRun) {
1121
+ return previewWrite(opts, { method: "POST", path: sectionPath, payload, headers });
1122
+ }
1123
+ const res = await requestJson(c.remote, sectionPath, {
1124
+ method: "POST",
1125
+ json: {
1126
+ text,
1127
+ ...(opts.before ? { before: opts.before } : {}),
1128
+ ...(opts.after ? { after: opts.after } : {}),
1129
+ },
1130
+ headers,
1131
+ token: c.token,
1132
+ });
1133
+ if (opts.json)
1134
+ return emitJson(res), 0;
1135
+ // Show the outline back: the new anchor is only knowable afterwards, since
1136
+ // a duplicate title takes the next free suffix.
1137
+ process.stdout.write(`✓ inserted into ${ref}\n etag ${res.etag}\n`);
1138
+ if (res.sections?.length) {
1139
+ process.stdout.write(renderTable(res.sections.map((s) => ({
1140
+ ANCHOR: s.anchor,
1141
+ LEVEL: String(s.level),
1142
+ TITLE: `${" ".repeat(Math.max(0, s.level - 1))}${s.title || "(preamble)"}`,
1143
+ })), ["ANCHOR", "LEVEL", "TITLE"]));
1144
+ }
1145
+ return 0;
1146
+ }
1147
+ catch (e) {
1148
+ return report(e);
1149
+ }
1150
+ }
1151
+ export async function runNotesRmSection(ref, anchor, opts) {
1152
+ const c = await ctx(opts);
1153
+ if (!c)
1154
+ return 1;
1155
+ try {
1156
+ const id = await resolveNote(c, ref);
1157
+ if (!id)
1158
+ return 1;
1159
+ const headers = await validator(c, id, opts);
1160
+ const anchorPath = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/sections/${seg(anchor)}`;
1161
+ if (opts.dryRun) {
1162
+ return previewWrite(opts, { method: "DELETE", path: anchorPath, payload: { anchor }, headers });
1163
+ }
1164
+ const res = await requestJson(c.remote, anchorPath, { method: "DELETE", headers, token: c.token });
1165
+ if (opts.json)
1166
+ return emitJson(res), 0;
1167
+ // Say the subtree went too — someone expecting only the heading to go
1168
+ // should find that out here, not from the note afterwards.
1169
+ process.stdout.write(`✓ removed '${anchor}' and everything under it from ${ref}\n etag ${res.etag}\n`);
1170
+ return 0;
1171
+ }
1172
+ catch (e) {
1173
+ return report(e);
1174
+ }
1175
+ }
1176
+ /** Explicit compatibility keeps legacy body-only output and ETag semantics available. */
1177
+ export async function runNotesRead(ref, opts) {
1178
+ if (opts.version !== undefined)
1179
+ return runSavedVersionRead(ref, opts);
1180
+ if (opts.linger)
1181
+ return runNotesLinger(ref, opts);
1182
+ if (opts.debounce !== undefined || opts.throttle !== undefined || opts.intent !== undefined) {
1183
+ fail('--debounce/--throttle/--intent require --linger');
1184
+ return 1;
1185
+ }
1186
+ if (opts.legacy && (opts.at || opts.toc || opts.tag)) {
1187
+ fail("--at/--toc/--tag require v2 reads");
1188
+ return 1;
1189
+ }
1190
+ if (opts.legacy && opts.view !== undefined && opts.view !== "source") {
1191
+ fail("--view html requires the v2 read contract; remove --legacy");
1192
+ return 1;
1193
+ }
1194
+ if (opts.legacy && (opts.since !== undefined || opts.format !== undefined)) {
1195
+ fail("--since/--format require the v2 read contract");
1196
+ return 1;
1197
+ }
1198
+ return opts.legacy ? runLegacyNotesRead(ref, opts) : runDocumentRead(ref, opts);
1199
+ }
1200
+ export async function runNotesDiff(ref, opts) {
1201
+ if (opts.legacy && opts.format !== undefined) {
1202
+ fail("--format requires the v2 diff contract");
1203
+ return 1;
1204
+ }
1205
+ if (opts.legacy)
1206
+ return runLegacyNotesDiff(ref, opts);
1207
+ if (opts.context !== undefined) {
1208
+ fail("--context requires --legacy");
1209
+ return 1;
1210
+ }
1211
+ if (!opts.since) {
1212
+ fail("--since is required");
1213
+ return 1;
1214
+ }
1215
+ return runDocumentRead(ref, opts);
1216
+ }
1217
+ export async function runNotesPatch(ref, opts) {
1218
+ if (opts.legacy && (opts.baseRevision !== undefined || opts.exact)) {
1219
+ fail("--base-revision/--exact require the v2 patch contract");
1220
+ return 1;
1221
+ }
1222
+ if (opts.legacy && opts.format !== undefined) {
1223
+ fail("--format requires the v2 patch contract");
1224
+ return 1;
1225
+ }
1226
+ return opts.legacy ? runLegacyNotesPatch(ref, opts) : runDocumentPatch(ref, opts);
1227
+ }
1228
+ /** Reading the roster never registers presence or maintains a session. */
1229
+ export async function runNotesPresence(ref, opts) {
1230
+ const c = await ctx(opts);
1231
+ if (!c)
1232
+ return 1;
1233
+ try {
1234
+ const id = await resolveNote(c, ref);
1235
+ if (!id)
1236
+ return 1;
1237
+ const response = await requestRaw(`${c.remote}/namespaces/${seg(c.ns)}/notes/${seg(id)}/presence?format=${opts.json ? 'json' : 'text'}`, { token: c.token, timeoutMs: 30000, followRedirects: false });
1238
+ if (opts.json)
1239
+ emitJson(await response.json());
1240
+ else {
1241
+ const text = await response.text();
1242
+ process.stdout.write(text + (text.endsWith('\n') ? '' : '\n'));
1243
+ }
1244
+ return 0;
1245
+ }
1246
+ catch (error) {
1247
+ return report(error);
1248
+ }
1249
+ }
1250
+ /** The agent's self-reported purpose, validated before any presence request.
1251
+ * undefined means the flag was not given — the server then preserves intent. */
1252
+ export function presenceIntent(value) {
1253
+ if (value === undefined)
1254
+ return undefined;
1255
+ const summary = value.trim();
1256
+ if (!summary || Array.from(summary).length > 280)
1257
+ throw new Error('--intent requires 1–280 characters of plain text (one short sentence of purpose)');
1258
+ return { summary };
1259
+ }
1260
+ /** One-shot participation; linger owns its own maintained lease. */
1261
+ export async function runNotesVisit(ref, opts) {
1262
+ if (!process.env.DREAMLAKE_AGENT_ID) {
1263
+ fail('set DREAMLAKE_AGENT_ID to a stable task-session ID');
1264
+ return 1;
1265
+ }
1266
+ const c = await ctx(opts);
1267
+ if (!c)
1268
+ return 1;
1269
+ try {
1270
+ const intent = presenceIntent(opts.intent);
1271
+ const id = await resolveNote(c, ref);
1272
+ if (!id)
1273
+ return 1;
1274
+ const result = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes/${seg(id)}/presence`, { method: 'POST', token: c.token, json: { action: 'join', ...(intent ? { intent } : {}) } });
1275
+ if (opts.json)
1276
+ emitJson(result);
1277
+ else
1278
+ process.stdout.write('Visit registered; presence expires automatically.\n');
1279
+ return 0;
1280
+ }
1281
+ catch (error) {
1282
+ return report(error);
1283
+ }
1284
+ }
1285
+ /** Metadata only: no body read, RTC activation, mount, or ownership mutation. */
1286
+ export async function runNotesProjects(id, opts) {
1287
+ try {
1288
+ if (!/^[a-f0-9]{24}$/i.test(id) || !opts.namespace?.trim())
1289
+ throw new Error('Use a stable Note ID and explicit --namespace');
1290
+ const c = await ctx(opts);
1291
+ if (!c)
1292
+ return 1;
1293
+ const result = await requestJson(c.remote, `/namespaces/${seg(c.ns)}/resources/note/${seg(id)}/projects`, { token: c.token, redirect: 'error' });
1294
+ if (!result || !Array.isArray(result.projects) || !Number.isSafeInteger(result.total) || result.total < 0) {
1295
+ throw new Error('Invalid filing response; current affiliations remain unknown');
1296
+ }
1297
+ emitJson(result);
1298
+ return 0;
1299
+ }
1300
+ catch (e) {
1301
+ return report(e);
1302
+ }
1303
+ }