nx-kv 0.48.2 → 0.50.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 (309) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +103 -216
  3. package/assets/groups.json +1 -1
  4. package/assets/kv-get/SKILL.md +1 -1
  5. package/assets/kv-get/references/localget.md +2 -2
  6. package/assets/kv-get/references/timegoal-workflow.md +3 -3
  7. package/assets/kv-get/references/timegoal.md +1 -1
  8. package/assets/kv-get/references/wait-workflow.md +2 -3
  9. package/assets/kv-get/references/waitloop.md +3 -3
  10. package/assets/kv-repo/SKILL.md +1 -1
  11. package/assets/kv-submit/SKILL.md +3 -3
  12. package/assets/nx-kv/SKILL.md +111 -76
  13. package/assets/nx-kv/references/agent-workflow.md +58 -47
  14. package/assets/nx-kv/references/localtask-commands.md +179 -0
  15. package/package.json +3 -4
  16. package/src/core/attachmentdb/bodies.ts +193 -0
  17. package/src/core/attachmentdb/docs.ts +158 -33
  18. package/src/core/attachmentdb/ids.ts +27 -1
  19. package/src/core/attachmentdb/mdfile.ts +249 -0
  20. package/src/core/attachmentdb/query.ts +14 -1
  21. package/src/core/attachmentdb/resources.ts +28 -2
  22. package/src/core/attachmentdb.ts +27 -0
  23. package/src/core/config.ts +13 -133
  24. package/src/core/db/bootstrap.ts +5 -5
  25. package/src/core/db/import-json/refs.ts +27 -13
  26. package/src/core/db/migrations/index.ts +9 -0
  27. package/src/core/db/migrations/v2-data.ts +4 -4
  28. package/src/core/db/migrations/v5.sql +100 -0
  29. package/src/core/db/migrations/v6-data.ts +261 -0
  30. package/src/core/db/migrations/v6.sql +67 -0
  31. package/src/core/db/migrations/v7.sql +8 -0
  32. package/src/core/db/seed-templates.ts +3 -1
  33. package/src/core/db/version.ts +12 -1
  34. package/src/core/filekind.ts +95 -0
  35. package/src/core/instruction-template.ts +6 -4
  36. package/src/core/localatt.ts +3 -6
  37. package/src/core/paths.ts +11 -1
  38. package/src/index.ts +0 -2
  39. package/src/modules/docs/actions/_manifest.generated.ts +18 -0
  40. package/src/modules/docs/actions/doc-attach.ts +2 -1
  41. package/src/modules/docs/actions/doc-link-file.ts +28 -0
  42. package/src/modules/docs/actions/doc-mdfile.ts +28 -0
  43. package/src/modules/docs/actions/doc-mdfiles.ts +29 -0
  44. package/src/modules/docs/actions/doc-ref.ts +36 -0
  45. package/src/modules/docs/actions/doc-unbind.ts +34 -0
  46. package/src/modules/docs/actions/doc-update.ts +3 -2
  47. package/src/modules/docs/actions/docs-bind.ts +1 -1
  48. package/src/modules/docs/actions/docs-bindings.ts +108 -0
  49. package/src/modules/docs/actions/docs-notebind.ts +1 -1
  50. package/src/modules/docs/attach.ts +16 -3
  51. package/src/modules/docs/bound-docs.ts +74 -0
  52. package/src/modules/docs/docref.ts +18 -3
  53. package/src/modules/docs/knowledge-md.ts +51 -0
  54. package/src/modules/docs/knowledge.ts +112 -112
  55. package/src/modules/docs/links.ts +7 -1
  56. package/src/modules/docs/mdfile.ts +24 -0
  57. package/src/modules/docs/paths.ts +6 -9
  58. package/src/modules/docs/ref-sync.ts +166 -0
  59. package/src/modules/docs/refs.ts +16 -5
  60. package/src/modules/docs/render.ts +33 -15
  61. package/src/modules/docs/seed.ts +1 -1
  62. package/src/modules/docs/service.ts +300 -30
  63. package/src/modules/docs/store.ts +147 -74
  64. package/src/modules/file/actions/_manifest.generated.ts +0 -9
  65. package/src/modules/file/actions/file-content.ts +3 -4
  66. package/src/modules/file/actions/file-get.ts +2 -3
  67. package/src/modules/file/actions/file-upload.ts +1 -4
  68. package/src/modules/file/service.ts +52 -253
  69. package/src/modules/localtask/action-render.ts +5 -5
  70. package/src/modules/localtask/actions/_manifest.generated.ts +0 -6
  71. package/src/modules/localtask/actions/localtask-attach.ts +4 -2
  72. package/src/modules/localtask/actions/localtask-cancelMany.ts +1 -1
  73. package/src/modules/localtask/actions/localtask-closeMany.ts +4 -3
  74. package/src/modules/localtask/actions/localtask-get.ts +1 -1
  75. package/src/modules/localtask/repo/tasks.ts +12 -6
  76. package/src/modules/localtask/service.ts +0 -2
  77. package/src/modules/localtask/task-ops.ts +4 -4
  78. package/src/modules/localtask/task-remove.ts +33 -16
  79. package/src/modules/localtask/task-templates.ts +2 -3
  80. package/src/modules/localtask/task-view.ts +2 -2
  81. package/src/modules/repos/actions/_manifest.generated.ts +0 -3
  82. package/src/modules/repos/actions/repo-update.ts +2 -4
  83. package/src/modules/repos/cli/render.ts +0 -15
  84. package/src/modules/repos/service/bind-topics.ts +8 -18
  85. package/src/modules/repos/service.ts +1 -1
  86. package/src/modules/repos/transfer/export.ts +4 -1
  87. package/src/modules/setting/actions/setting-set.ts +0 -2
  88. package/src/modules/setting/service.ts +6 -25
  89. package/src/modules/system/actions/bootstrap.ts +2 -31
  90. package/src/modules/system/actions/health.ts +4 -31
  91. package/src/modules/system/routes.ts +1 -1
  92. package/src/modules/tasktool/attach-resource.ts +68 -42
  93. package/src/modules/tasktool/attach-template.ts +73 -54
  94. package/src/modules/tasktool/attach.ts +98 -71
  95. package/src/modules/tasktool/delivery-template.ts +14 -4
  96. package/src/modules/tasktool/doc-inline.ts +63 -29
  97. package/src/modules/tasktool/get.ts +1 -1
  98. package/src/modules/tasktool/groupctx.ts +19 -11
  99. package/src/modules/tasktool/plugins/waitgoal-config.ts +24 -55
  100. package/src/modules/tasktool/plugins/waitgoal.ts +0 -2
  101. package/src/modules/tasktool/preview.ts +2 -3
  102. package/src/modules/tasktool/wait.ts +6 -9
  103. package/src/runtime/cli.ts +3 -15
  104. package/src/runtime/container.ts +1 -5
  105. package/src/runtime/help.ts +1 -4
  106. package/src/runtime/registry.ts +0 -6
  107. package/src/shared/prompt-blocks.ts +37 -33
  108. package/src/shared/task-status.ts +3 -3
  109. package/src/web/frontend/App.tsx +3 -3
  110. package/src/web/frontend/api/cli-tree.json +115 -608
  111. package/src/web/frontend/api/client.generated.ts +88 -401
  112. package/src/web/frontend/components/Introduction/index.tsx +26 -14
  113. package/src/web/frontend/components/Introduction/rail.tsx +28 -3
  114. package/src/web/frontend/components/Introduction/style.css +3 -33
  115. package/src/web/frontend/components/Introduction/use-intro.ts +0 -80
  116. package/src/web/frontend/components/{cloud → attach}/upload.ts +7 -20
  117. package/src/web/frontend/components/bindings/bind-tags.tsx +183 -0
  118. package/src/web/frontend/components/doc/doc-head.tsx +29 -26
  119. package/src/web/frontend/components/icons.tsx +0 -1
  120. package/src/web/frontend/components/layout/crumbs.ts +0 -2
  121. package/src/web/frontend/components/md/ack-rail.tsx +10 -142
  122. package/src/web/frontend/components/md/attach-area.tsx +64 -9
  123. package/src/web/frontend/components/md/attach-common.ts +8 -3
  124. package/src/web/frontend/components/md/attach-modal.tsx +22 -17
  125. package/src/web/frontend/components/md/attach-picker.tsx +2 -2
  126. package/src/web/frontend/components/md/attachments.ts +2 -3
  127. package/src/web/frontend/components/popup/dismiss.ts +1 -1
  128. package/src/web/frontend/components/repos/get-loop-modal.tsx +20 -207
  129. package/src/web/frontend/components/sidebar/index.tsx +32 -6
  130. package/src/web/frontend/components/sidebar/model.ts +71 -0
  131. package/src/web/frontend/components/sidebar/task-children.tsx +41 -20
  132. package/src/web/frontend/components/status-tag/model.ts +1 -1
  133. package/src/web/frontend/components/task-panel/index.tsx +4 -1
  134. package/src/web/frontend/components/task-panel/task-row.tsx +2 -2
  135. package/src/web/frontend/components/tool-acts/modules.ts +0 -3
  136. package/src/web/frontend/components/use-rail-drag.ts +177 -0
  137. package/src/web/frontend/modules/board/ack-rail-pos.ts +17 -7
  138. package/src/web/frontend/modules/board/board-view.ts +2 -2
  139. package/src/web/frontend/modules/board/task-search.ts +81 -0
  140. package/src/web/frontend/modules/md/attach-mention.ts +6 -1
  141. package/src/web/frontend/modules/md/doc-bus.ts +22 -0
  142. package/src/web/frontend/modules/md/md-render.ts +9 -2
  143. package/src/web/frontend/modules/md/styles/chrome.css +25 -0
  144. package/src/web/frontend/modules/md/styles/docs.css +32 -21
  145. package/src/web/frontend/modules/md/styles/shell.css +1 -10
  146. package/src/web/frontend/page/dir/api.ts +7 -0
  147. package/src/web/frontend/page/dir/index.tsx +24 -58
  148. package/src/web/frontend/page/dir/landing.tsx +85 -72
  149. package/src/web/frontend/page/dir/task-actions.ts +17 -5
  150. package/src/web/frontend/page/dir/task-dock-panel.tsx +87 -2
  151. package/src/web/frontend/page/dir/task-dock.ts +21 -10
  152. package/src/web/frontend/page/dir/task-goal.ts +2 -2
  153. package/src/web/frontend/page/dir/task-status-bar.tsx +14 -1
  154. package/src/web/frontend/page/dir/task.tsx +5 -3
  155. package/src/web/frontend/page/doc/api.ts +71 -5
  156. package/src/web/frontend/page/doc/bindings.tsx +240 -0
  157. package/src/web/frontend/page/doc/doc-dock.tsx +159 -0
  158. package/src/web/frontend/page/doc/index.tsx +131 -212
  159. package/src/web/frontend/page/doc/use-wiki-nav.ts +101 -0
  160. package/src/web/frontend/page/group/index.tsx +61 -87
  161. package/src/web/frontend/page/overview/index.tsx +1 -2
  162. package/src/web/frontend/page/refs/api.ts +60 -8
  163. package/src/web/frontend/page/refs/index.tsx +177 -90
  164. package/src/web/frontend/page/refs/style.css +45 -2
  165. package/src/web/frontend/page/repos/doc-search-modal.tsx +7 -0
  166. package/src/web/frontend/page/repos/index.tsx +21 -60
  167. package/src/web/frontend/page/repos/repo-table.tsx +85 -77
  168. package/src/web/frontend/page/settings/index.tsx +3 -27
  169. package/src/web/frontend/page/settings/prompt-template-params.ts +18 -28
  170. package/src/web/frontend/panels.tsx +52 -6
  171. package/src/web/frontend/registry.ts +1 -2
  172. package/src/web/frontend/routes/index.ts +1 -2
  173. package/src/web/frontend/routes/static.ts +2 -3
  174. package/src/web/frontend/store.tsx +1 -8
  175. package/src/web/frontend/style.css +1 -0
  176. package/src/web/frontend/styles/base.css +0 -17
  177. package/src/web/frontend/styles/bindings.css +75 -0
  178. package/src/web/frontend/styles/buttons-cards.css +0 -72
  179. package/src/web/frontend/styles/repos-admin.css +7 -5
  180. package/src/web/frontend/styles-v2/dir.css +1 -9
  181. package/src/web/frontend/styles-v2/shell.css +0 -2
  182. package/src/web/frontend/styles-v2/sidebar.css +12 -0
  183. package/src/web/frontend/styles-v2/views.css +22 -102
  184. package/src/web/frontend/workspace/areas.ts +0 -2
  185. package/src/web/public/assets/Introduction-CohW6Xit.js +6 -0
  186. package/src/web/public/assets/Introduction-Iuxssa-b.css +1 -0
  187. package/src/web/public/assets/app-context-BgpTewyA.js +1 -0
  188. package/src/web/public/assets/{bar-B52NTf_v.js → bar-C2mfoqmj.js} +1 -1
  189. package/src/web/public/assets/{board-view-DABoVkaA.js → board-view-aAIEbSQi.js} +1 -1
  190. package/src/web/public/assets/button-xyR2UROd.js +1 -0
  191. package/src/web/public/assets/composer-launch-eTktHT_f.js +1 -0
  192. package/src/web/public/assets/{composer-panel-DpiU2h50.js → composer-panel-C0OOIXxz.js} +1 -1
  193. package/src/web/public/assets/dag-Gm4RcvEg.js +1 -0
  194. package/src/web/public/assets/dir-PjuMRbWo.js +3 -0
  195. package/src/web/public/assets/group-D94y_Lq6.js +1 -0
  196. package/src/web/public/assets/index-CBJKsJU3.css +1 -0
  197. package/src/web/public/assets/index-Crxdmsux.js +2 -0
  198. package/src/web/public/assets/md-history-CU_1I6ht.js +39 -0
  199. package/src/web/public/assets/{md-parse-b6GY5eBl.js → md-parse-CLyUaUto.js} +1 -1
  200. package/src/web/public/assets/{member-picker-B5I7KuOR.js → member-picker-XT12VRe6.js} +1 -1
  201. package/src/web/public/assets/model-CWJ8_2dN.js +2 -0
  202. package/src/web/public/assets/{overview-B3kHI66i.js → overview-BQm8BLCG.js} +1 -1
  203. package/src/web/public/assets/{progress-CdhFz0Lz.js → progress-CNam3Wuj.js} +2 -2
  204. package/src/web/public/assets/refs-C5idWnUj.css +1 -0
  205. package/src/web/public/assets/refs-ClETk1cj.js +2 -0
  206. package/src/web/public/assets/repos-BioGejZo.js +14 -0
  207. package/src/web/public/assets/route-crumb-Fc68LcQ4.js +1 -0
  208. package/src/web/public/assets/settings-BIzumXLD.js +8 -0
  209. package/src/web/public/assets/status-tag-CBFf_-ae.js +1 -0
  210. package/src/web/public/assets/task-CGmO3I2y.js +11 -0
  211. package/src/web/public/assets/task-row-DRBa11tf.js +1 -0
  212. package/src/web/public/assets/{task-status-DSrx0i66.js → task-status-BHF-y9Aq.js} +2 -1
  213. package/src/web/public/assets/{task-utils-_JAWRAz6.js → task-utils-DjODjVdc.js} +2 -2
  214. package/src/web/public/assets/{templates-CbRyW3PJ.js → templates-j8EzXHXf.js} +1 -1
  215. package/src/web/public/assets/ui-Y0aL-bGk.js +1 -0
  216. package/src/web/public/assets/use-rail-drag-DNfz4Gcx.js +1 -0
  217. package/src/web/public/assets/{workspace-4tw7trV7.js → workspace-D_G-B3TX.js} +4 -4
  218. package/src/web/public/index.html +9 -9
  219. package/assets/nx-kv/references/todo-commands.md +0 -269
  220. package/src/core/attachstore.ts +0 -360
  221. package/src/core/fileapi.ts +0 -267
  222. package/src/core/kvapi.ts +0 -237
  223. package/src/modules/auth/actions/_manifest.generated.ts +0 -26
  224. package/src/modules/auth/actions/auth-login.ts +0 -31
  225. package/src/modules/auth/actions/auth-logout.ts +0 -33
  226. package/src/modules/auth/actions/auth-me.ts +0 -33
  227. package/src/modules/auth/actions/auth-status.ts +0 -41
  228. package/src/modules/auth/index.ts +0 -24
  229. package/src/modules/auth/support.ts +0 -28
  230. package/src/modules/file/actions/file-list.ts +0 -31
  231. package/src/modules/file/actions/file-remove.ts +0 -31
  232. package/src/modules/file/actions/file-sync.ts +0 -33
  233. package/src/modules/localtask/actions/localtask-importRemote.ts +0 -51
  234. package/src/modules/localtask/actions/task-move.ts +0 -67
  235. package/src/modules/localtask/move-prims.ts +0 -170
  236. package/src/modules/localtask/move.ts +0 -174
  237. package/src/modules/localtask/remote-import.ts +0 -159
  238. package/src/modules/repos/actions/repo-ref-backfill.ts +0 -33
  239. package/src/modules/repos/ref-backfill.ts +0 -219
  240. package/src/modules/todo/actions/_manifest.generated.ts +0 -89
  241. package/src/modules/todo/actions/group-add.ts +0 -34
  242. package/src/modules/todo/actions/group-current.ts +0 -36
  243. package/src/modules/todo/actions/group-get.ts +0 -43
  244. package/src/modules/todo/actions/group-list.ts +0 -41
  245. package/src/modules/todo/actions/group-members.ts +0 -41
  246. package/src/modules/todo/actions/group-remove.ts +0 -44
  247. package/src/modules/todo/actions/group-update.ts +0 -37
  248. package/src/modules/todo/actions/group-use.ts +0 -43
  249. package/src/modules/todo/actions/prompt-get.ts +0 -31
  250. package/src/modules/todo/actions/prompt-remove.ts +0 -31
  251. package/src/modules/todo/actions/prompt-set.ts +0 -32
  252. package/src/modules/todo/actions/todo-add.ts +0 -34
  253. package/src/modules/todo/actions/todo-archive.ts +0 -33
  254. package/src/modules/todo/actions/todo-attach.ts +0 -37
  255. package/src/modules/todo/actions/todo-attachments.ts +0 -33
  256. package/src/modules/todo/actions/todo-done.ts +0 -33
  257. package/src/modules/todo/actions/todo-freeze.ts +0 -32
  258. package/src/modules/todo/actions/todo-get.ts +0 -33
  259. package/src/modules/todo/actions/todo-list.ts +0 -32
  260. package/src/modules/todo/actions/todo-remove.ts +0 -32
  261. package/src/modules/todo/actions/todo-unfreeze.ts +0 -34
  262. package/src/modules/todo/actions/todo-update.ts +0 -42
  263. package/src/modules/todo/actions/topic-add.ts +0 -31
  264. package/src/modules/todo/actions/topic-list.ts +0 -35
  265. package/src/modules/todo/actions/topic-remove.ts +0 -36
  266. package/src/modules/todo/attachments.ts +0 -194
  267. package/src/modules/todo/group.ts +0 -207
  268. package/src/modules/todo/index.ts +0 -26
  269. package/src/modules/todo/locate.ts +0 -103
  270. package/src/modules/todo/service.ts +0 -476
  271. package/src/modules/todo/store.ts +0 -176
  272. package/src/modules/todo/support.ts +0 -93
  273. package/src/web/frontend/components/Introduction/docs-modal.tsx +0 -338
  274. package/src/web/frontend/components/cloud/editor.tsx +0 -254
  275. package/src/web/frontend/components/cloud/group-popup.tsx +0 -198
  276. package/src/web/frontend/components/cloud/markdown.tsx +0 -60
  277. package/src/web/frontend/components/migrate/dialog.tsx +0 -120
  278. package/src/web/frontend/components/migrate/undo.tsx +0 -73
  279. package/src/web/frontend/components/migrate/use-move.ts +0 -137
  280. package/src/web/frontend/page/cloud/api.ts +0 -99
  281. package/src/web/frontend/page/cloud/index.tsx +0 -516
  282. package/src/web/frontend/page/dir/deleted-panel.tsx +0 -77
  283. package/src/web/public/assets/Introduction-BcPrmROW.css +0 -1
  284. package/src/web/public/assets/Introduction-Du_dycft.js +0 -6
  285. package/src/web/public/assets/app-context-BASCGAA-.js +0 -1
  286. package/src/web/public/assets/cloud-Droja_aT.js +0 -3
  287. package/src/web/public/assets/composer-launch-mK9Nr6mZ.js +0 -1
  288. package/src/web/public/assets/dag-Ca-wjIxQ.js +0 -1
  289. package/src/web/public/assets/deleted-panel-K9GgfR8t.js +0 -1
  290. package/src/web/public/assets/dir-DacRpcBt.js +0 -5
  291. package/src/web/public/assets/frontmatter-CLLxCmTv.js +0 -2
  292. package/src/web/public/assets/group-TPuU-QVc.js +0 -2
  293. package/src/web/public/assets/index-BkLkooKe.js +0 -2
  294. package/src/web/public/assets/index-DP3qBv1o.css +0 -1
  295. package/src/web/public/assets/md-history-0GBWw4qr.js +0 -39
  296. package/src/web/public/assets/model-Bn2fG6CC.js +0 -2
  297. package/src/web/public/assets/prompt-blocks-BovFd039.js +0 -8
  298. package/src/web/public/assets/refs-BDxfuH6R.js +0 -1
  299. package/src/web/public/assets/refs-CY4i7PoC.css +0 -1
  300. package/src/web/public/assets/repos-C8jRM7wS.js +0 -15
  301. package/src/web/public/assets/repos-ZPiaK93i.css +0 -1
  302. package/src/web/public/assets/route-crumb-QvahotvN.js +0 -1
  303. package/src/web/public/assets/settings-BBcdGLTc.js +0 -1
  304. package/src/web/public/assets/status-tag-BheHByek.js +0 -1
  305. package/src/web/public/assets/task-CUkQaLBZ.js +0 -11
  306. package/src/web/public/assets/tool-bar-BAmT-BI-.js +0 -1
  307. package/src/web/public/assets/upload-BcMhRsMn.js +0 -1
  308. /package/src/web/public/assets/{prompt-blocks-DA4lNJeC.css → button-DA4lNJeC.css} +0 -0
  309. /package/src/web/public/assets/{tool-bar-1h2zairf.css → use-rail-drag-1h2zairf.css} +0 -0
@@ -1,24 +0,0 @@
1
- // auth 模块(模板形态):只做装配——模块元信息 + 从 action 清单建实例。
2
- //
3
- // action 清单由 `pnpm gen:actions` 扫 actions/ 目录生成(actions/_manifest.generated.ts),
4
- // 本文件**不手工列举** action 类——加一条 action = 新建一个文件 + 跑一次生成。
5
- import { ModuleBase } from '../../runtime/types/module.js';
6
- import { zodActionsOf, type ZodBoundAction } from '../../runtime/action-decorator.js';
7
- import { container, type Container } from '../../runtime/container.js';
8
- import { ACTIONS } from './actions/_manifest.generated.js';
9
-
10
- export class AuthModule extends ModuleBase {
11
- override readonly id = 'auth';
12
- override readonly title = "认证(登录态)";
13
- override readonly order = 10;
14
-
15
- override readonly actions: readonly ZodBoundAction[];
16
-
17
- constructor(c: Container = container) {
18
- super();
19
- this.actions = ACTIONS.flatMap((Cls) => zodActionsOf(c.create(Cls)));
20
- }
21
- }
22
-
23
- export const authModule = new AuthModule();
24
- export default authModule;
@@ -1,28 +0,0 @@
1
- // auth 模块的辅助函数/常量(legacy 形态里与 action 表同文件,迁来时一并搬到这里)。
2
- //
3
- // 参数与返回值暂用宽松类型(迁移期),服务层类型化推进时逐个收紧。
4
- import { updateConfig } from '../../core/config.js';
5
- import { login as apiLogin } from '../../core/kvapi.js';
6
- import { askHidden } from '../../core/prompt.js';
7
- import { badInput } from '../../core/errors.js';
8
-
9
- export async function doLogin(ctx: any) {
10
- const email: any = String(ctx.email || '').trim();
11
- if (!email) throw badInput('邮箱不能为空');
12
-
13
- // 密码来源优先级:--password(脚本用)> 交互式隐藏输入
14
- let password: any = ctx.password;
15
- if (!password) {
16
- password = await askHidden(`请输入 ${email} 的密码: `);
17
- }
18
- if (!password) throw badInput('密码不能为空');
19
-
20
- const { token, userId } = await apiLogin(email, password, { baseUrl: ctx.baseUrl });
21
- await updateConfig({
22
- token,
23
- userId,
24
- email,
25
- ...(ctx.baseUrl ? { baseUrl: ctx.baseUrl } : {}),
26
- });
27
- return { email, userId, tokenSaved: true };
28
- }
@@ -1,31 +0,0 @@
1
- // file.list —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import * as serviceNs from '../service.js';
8
- const service: any = serviceNs;
9
-
10
- /** file.list 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
- const input = z.object({
12
- group: z.number().optional().describe("工作空间 id(默认取当前)"),
13
- limit: z.number().default(100),
14
- offset: z.number().default(0),
15
- });
16
-
17
- export class FileListAction extends ActionBase<typeof input> {
18
- @action({
19
- id: 'file.list',
20
- cli: ['file', 'list'],
21
- http: ['GET', '/api/file'],
22
- summary: '列出当前用户空间的附件(含本地已同步路径)',
23
- input,
24
- render: (d: any) => service.renderFileList(d),
25
- })
26
- override async run(ctx: ActionInput<this['_input']>) {
27
-
28
- return service.listFilesAction(ctx);
29
-
30
- }
31
- }
@@ -1,31 +0,0 @@
1
- // file.remove —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import * as serviceNs from '../service.js';
8
- const service: any = serviceNs;
9
-
10
- /** file.remove 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
- const input = z.object({
12
- fileId: z.string(),
13
- group: z.number().optional().describe("工作空间 id(默认取当前)"),
14
- });
15
-
16
- export class FileRemoveAction extends ActionBase<typeof input> {
17
- @action({
18
- id: 'file.remove',
19
- cli: ['file', 'remove'],
20
- http: ['DELETE', '/api/file/item'],
21
- summary: '删除附件(后端软删;本地副本要清用 file sync --prune)',
22
- args: ['fileId'],
23
- input,
24
- render: (d: any) => service.renderRemove(d),
25
- })
26
- override async run(ctx: ActionInput<this['_input']>) {
27
-
28
- return service.removeFileAction(ctx.fileId, { group: ctx.group });
29
-
30
- }
31
- }
@@ -1,33 +0,0 @@
1
- // file.sync —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import * as serviceNs from '../service.js';
8
- const service: any = serviceNs;
9
-
10
- /** file.sync 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
- const input = z.object({
12
- ids: z.array(z.string()).optional().describe("只同步这些 fileId(逗号分隔)"),
13
- dir: z.string().optional().describe("本地目录(默认 ~/.nx-kv/attachments/<工作空间>/)"),
14
- prune: z.boolean().optional().describe("删掉本地已不在后端的文件(仅全量同步时生效)"),
15
- dryRun: z.boolean().optional().describe("只列出将下载什么,不落盘"),
16
- group: z.number().optional().describe("工作空间 id(默认取当前)"),
17
- });
18
-
19
- export class FileSyncAction extends ActionBase<typeof input> {
20
- @action({
21
- id: 'file.sync',
22
- cli: ['file', 'sync'],
23
- http: ['POST', '/api/file/sync'],
24
- summary: '把附件同步到本机(默认全部;--ids 只同步指定附件)——为了不再依赖网络读附件',
25
- input,
26
- render: (d: any) => service.renderSync(d),
27
- })
28
- override async run(ctx: ActionInput<this['_input']>) {
29
-
30
- return service.syncFilesAction(ctx);
31
-
32
- }
33
- }
@@ -1,51 +0,0 @@
1
- // localtask.importRemote —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import * as serviceNs from '../service.js';
8
- const service: any = serviceNs;
9
-
10
- /** localtask.importRemote 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
- const input = z.object({
12
- ref: z.array(z.string()).optional().describe("远程任务内容(整串,可给多次)"),
13
- cwd: z.string().optional(),
14
- global: z.boolean().optional().describe("导入到全局共享池(--cwd 被忽略)"),
15
- topic: z.string().optional().describe("远程主题(消歧用)"),
16
- pick: z.number().optional().describe("同内容多条时的编号(消歧用)"),
17
- });
18
-
19
- export class LocaltaskImportRemoteAction extends ActionBase<typeof input> {
20
- @action({
21
- id: 'localtask.importRemote',
22
- cli: ['localtask', 'import-remote'],
23
- http: ['POST', '/api/localtasks/import-remote'],
24
- summary: '从远程清单(KV 后端)导入任务到本地队列:按内容定位远程那条 → 落进本地队列 → 远程那条标记为已完成(note 写明被哪个队列领走)',
25
- input,
26
- render: (d: any) => {
27
- const lines: any = [d.message];
28
- for (const r of d.results || []) {
29
- if (r.error) lines.push(` ✗ ${r.ref} —— ${r.error}`);
30
- else lines.push(` ✓ ${r.ref} → 本地「${r.localTopic}」#${r.localId}${r.remoteDone ? '(远程已标记完成)' : '(远程未标记完成)'}`);
31
- }
32
- return lines.join('\n');
33
- },
34
- })
35
- override async run(ctx: ActionInput<this['_input']>) {
36
-
37
- return service.importRemoteTasks({
38
- // ref(CLI 的 --ref,可给多次)与 refs(面板发的列表)**都传过去**。
39
- // 注意:refs 不在 schema 里,zod parse 会剥掉未声明键——它恒为 undefined
40
- //(#177 类型化后暴露;CLI/生成的 client 都只发已声明键,行为不受影响)。
41
- // 想启用面板直发列表,就把 refs 声明进 schema,而不是靠透传。
42
- ref: ctx.ref,
43
- refs: (ctx as Record<string, unknown>).refs,
44
- cwd: ctx.cwd,
45
- global: ctx.global,
46
- topic: ctx.topic,
47
- pick: ctx.pick,
48
- });
49
-
50
- }
51
- }
@@ -1,67 +0,0 @@
1
- // task.move —— 由 .tool/migrate-module.mjs 从 legacy 形态迁来(模板形态:一条 action 一个文件)。
2
- //
3
- // 契约(zod schema)就声明在本文件里——入参类型由基类泛型模板封装;本文件只做「声明 + 实现」,业务在服务层。
4
- import { action } from '../../../runtime/action-decorator.js';
5
- import { z } from 'zod';
6
- import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
7
- import * as moveNs from '../move.js';
8
- const move: any = moveNs;
9
-
10
- /** task.move 的入参契约(CLI 与 HTTP 共用同一份)。 */
11
- const input = z.object({
12
- from: z.enum(["local", "cloud"]).optional().describe("迁移源"),
13
- to: z.enum(["local", "cloud"]).optional().describe("迁移目标"),
14
- id: z.number().optional().describe("本机任务编号(from=local 时必填)"),
15
- cwd: z.string().optional(),
16
- key: z.string().optional(),
17
- topic: z.string().optional().describe("云端主题(= 目录名;from=cloud 必填,to=cloud 缺省用目录名)"),
18
- text: z.string().optional().describe("云端任务内容(from=cloud 时按内容定位)"),
19
- pick: z.number().optional().describe("云端同内容多条时的编号(消歧)"),
20
- merge: z.boolean().optional().describe("目标端已有同内容时合并到已有条目(不新增)"),
21
- group: z.number().optional().describe("云端工作空间 id(默认取当前)"),
22
- undo: z.boolean().optional().describe("撤销一次迁移(配合 --target-id 与原 move 参数)"),
23
- 'target-id': z.number().optional().describe("撤销用:迁移时返回的 targetId"),
24
- 'tombstone-id': z.number().optional().describe("撤销 local→cloud 时可显式指定本机迁出条目编号(缺省用 --id)"),
25
- });
26
-
27
- export class TaskMoveAction extends ActionBase<typeof input> {
28
- @action({
29
- id: 'task.move',
30
- cli: ['task', 'move'],
31
- http: ['POST', '/api/task/move'],
32
- summary: '在本机队列与云端清单之间迁移任务(先写目标端、成功才改源端;--undo 按返回的 target-id 精确撤销)',
33
- input,
34
- render: (d: any) => {
35
- if (d.undone) {
36
- return d.from === 'local'
37
- ? `已撤销: 云端「${d.topic}」的条目已删除,本机「${d.dirName}」#${d.tombstoneId} 回到待领取`
38
- : `已撤销: 本机「${d.dirName}」#${d.targetId} 已移除,云端「${d.topic}」已恢复`;
39
- }
40
- const head: any =
41
- d.from === 'local'
42
- ? `本机「${d.dirName}」#${d.tombstoneId} → 云端「${d.topic}」(${d.merged ? `合并到已有条目 #${d.targetId}` : `新待办 #${d.targetId}`})`
43
- : `云端「${d.topic}」 → 本机「${d.dirName}」(待领取首位 #${d.targetId})`;
44
- const tail: any = d.from === 'local' ? `\n原位置留有迁出记录(可在面板跳转/移除;task move --undo 撤销)` : '';
45
- return head + (d.dupCount ? `\n(目标端原有 ${d.dupCount} 条同内容)` : '') + tail;
46
- },
47
- })
48
- override async run(ctx: ActionInput<this['_input']>) {
49
-
50
- return move.moveTask({
51
- from: ctx.from,
52
- to: ctx.to,
53
- id: ctx.id,
54
- cwd: ctx.cwd,
55
- key: ctx.key,
56
- topic: ctx.topic,
57
- text: ctx.text,
58
- pick: ctx.pick,
59
- merge: ctx.merge,
60
- group: ctx.group,
61
- undo: ctx.undo,
62
- 'target-id': ctx['target-id'],
63
- 'tombstone-id': ctx['tombstone-id'],
64
- });
65
-
66
- }
67
- }
@@ -1,170 +0,0 @@
1
- // (#54 自 service.js 拆出)迁移原语(task move / 云端迁移编排用):只读定位、
2
- // 迁出 tombstone(目标端写成功后才调用)、撤销迁出、云端回插待领取首位。
3
- //
4
- // T03:写入走 repo 的窄方法。「回到待领取首位」「插到待领取首位」都落在
5
- // ext_task_order 的头部 —— 与 JSON 时代 splice(0) 等价,seq 一个不动。
6
- import { badInput } from '../../core/errors.js';
7
- import { normalizeCwd, resolveTaskKey } from './paths.js';
8
- import { normalizeText } from './store-io.js';
9
- import { openLocaltaskStore as openStore, topics as topicsRepo, tasks as tasksRepo, txw as tx } from './repo/index.js';
10
- import { normalizeTask } from './task-view.js';
11
- // ─── 迁移原语(task move 用;store 封装不外泄)─────────────────────
12
- //
13
- // 迁移的原子性在外层 move.js 编排(先写目标端、成功才改源端),
14
- // 这里只提供最小读写原语,保证清单/历史/原子性都走同一条管线。
15
-
16
- /** 任务寻址入参(--cwd/--key + --id)。 */
17
- export interface TaskAddressInput {
18
- cwd?: string;
19
- key?: string;
20
- id?: number | string;
21
- }
22
-
23
- /** getTopicTask / insertTaskAtTop 的出站形状(insertTaskAtTop 额外带 status)。
24
- * cwd 可缺省:clearTaskMigrated 的 not_migrated 分支原样不返回 cwd(与原 .js 一致)。 */
25
- export interface TopicTaskResult {
26
- status?: string;
27
- task: Record<string, any>;
28
- key: string;
29
- cwd?: string;
30
- name: string;
31
- }
32
-
33
- /** markTaskMigrated / clearTaskMigrated 的出站形状。 */
34
- export interface MigrateResult extends TopicTaskResult {
35
- status: string;
36
- restored?: boolean;
37
- reason?: string;
38
- }
39
-
40
- /** 只读定位一条本机任务(不落写)。返回 {task, name, key, cwd} 或抛 notFound。 */
41
- export async function getTopicTask({ cwd: rawCwd, key: rawKey, id }: TaskAddressInput = {}): Promise<TopicTaskResult> {
42
- const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
43
- const want = Number(id);
44
- if (!Number.isFinite(want) || want <= 0) throw badInput('缺少参数 --id <任务编号>');
45
- openStore();
46
- const t = topicsRepo.getTopic(key);
47
- const raw = t && t.tasks.find((x: any) => Number(x.id) === want);
48
- if (!raw) {
49
- const { notFound } = await import('../../core/errors.js');
50
- throw notFound(`主题「${t ? t.name : key}」里没有 #${want} 任务`);
51
- }
52
- return { task: normalizeTask(raw), key, cwd: t.cwd || '', name: t.name || key };
53
- }
54
-
55
- /** markTaskMigrated 的入参(migratedTo tombstone 必须带 side:"cloud")。 */
56
- export interface MarkMigratedInput extends TaskAddressInput {
57
- migratedTo?: { side?: string; topic?: string; targetId?: number | string; at?: string };
58
- }
59
-
60
- /** 给本机任务打迁出标记(tombstone)。只在目标端已写成功后调用。 */
61
- export async function markTaskMigrated({ cwd: rawCwd, key: rawKey, id, migratedTo }: MarkMigratedInput = {}): Promise<MigrateResult> {
62
- const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
63
- const want = Number(id);
64
- if (!Number.isFinite(want) || want <= 0) throw badInput('缺少参数 --id <任务编号>');
65
- if (!migratedTo || migratedTo.side !== 'cloud') throw badInput('migratedTo 必须是 {side:"cloud", topic, targetId, at}');
66
- openStore();
67
- const t = topicsRepo.getTopic(key)!;
68
- const raw = t && t.tasks.find((x: any) => Number(x.id) === want);
69
- if (!raw) {
70
- const { notFound } = await import('../../core/errors.js');
71
- throw notFound(`主题「${t.name || key}」里没有 #${want} 任务`);
72
- }
73
- // 只有「待领取」能迁出:已领取(在干)与已交付(终态)都不该被搬走
74
- if (raw.status !== 'pending') {
75
- const { conflict } = await import('../../core/errors.js');
76
- throw conflict(`主题「${t.name}」#${want} 不是待领取(已领取/已交付),不能再迁移`);
77
- }
78
- const next = tx(() => {
79
- const out = tasksRepo.updateTask(t.id, want, {
80
- migratedTo: {
81
- side: 'cloud',
82
- topic: String(migratedTo!.topic || ''),
83
- targetId: Number(migratedTo!.targetId) || 0,
84
- at: String(migratedTo!.at || new Date().toISOString().replace('T', ' ').slice(0, 19)),
85
- },
86
- });
87
- topicsRepo.updateTopic(key, { bumpRevision: true });
88
- return out;
89
- });
90
- return { status: 'ok', key, cwd: t.cwd || '', name: t.name, task: normalizeTask(next) };
91
- }
92
-
93
- /** clearTaskMigrated 的选项(toTop = 是否回到待领取首位)。 */
94
- export interface ClearMigratedInput extends TaskAddressInput {
95
- toTop?: boolean;
96
- }
97
-
98
- /** 撤销迁出:清掉 migratedTo 标记,任务回到待领取首位。 */
99
- export async function clearTaskMigrated({ cwd: rawCwd, key: rawKey, id, toTop = true }: ClearMigratedInput = {}): Promise<MigrateResult> {
100
- const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
101
- const want = Number(id);
102
- if (!Number.isFinite(want) || want <= 0) throw badInput('缺少参数 --id <任务编号>');
103
- openStore();
104
- const t = topicsRepo.getTopic(key)!;
105
- const raw = t && t.tasks.find((x: any) => Number(x.id) === want);
106
- if (!raw) {
107
- const { notFound } = await import('../../core/errors.js');
108
- throw notFound(`主题「${t ? t.name : key}」里没有 #${want} 任务`);
109
- }
110
- if (!raw.migratedTo) {
111
- return { status: 'ok', restored: false, reason: 'not_migrated', key, name: t.name, task: normalizeTask(raw) };
112
- }
113
- const next = tx(() => {
114
- const out = tasksRepo.updateTask(t.id, want, { migratedTo: null });
115
- if (toTop) {
116
- // 回到待领取首位:迁出时它占着优先级位置,撤销应原样归还
117
- topicsRepo.mutateOrder(key, (order) => {
118
- const list = [...order];
119
- for (const s of t.tasks.map((x: any) => x.id)) if (!list.includes(Number(s))) list.push(Number(s));
120
- const at = list.indexOf(want);
121
- if (at >= 0) list.splice(at, 1);
122
- list.unshift(want);
123
- return list;
124
- });
125
- }
126
- topicsRepo.updateTopic(key, { bumpRevision: true });
127
- return out;
128
- });
129
- return { status: 'ok', restored: true, key, cwd: t.cwd || '', name: t.name, task: normalizeTask(next) };
130
- }
131
-
132
- /** insertTaskAtTop 的入参。 */
133
- export interface InsertTaskAtTopInput {
134
- cwd?: string;
135
- key?: string;
136
- text?: string;
137
- from?: string;
138
- }
139
-
140
- /**
141
- * 云端 → 本机:把一条任务插到本机主题队列的**待领取首位**(不打扰 waiter——
142
- * 迁移是「排进队列」,不是「回填给正在等的 agent」,语义必须分开)。
143
- * 返回 {task, name, key, cwd}。
144
- */
145
- export async function insertTaskAtTop({ cwd: rawCwd, key: rawKey, text, from = 'cloud' }: InsertTaskAtTopInput = {}): Promise<TopicTaskResult> {
146
- const body = normalizeText(text);
147
- const key = resolveTaskKey({ key: rawKey, cwd: rawCwd });
148
- const { cwd } = normalizeCwd(rawCwd);
149
- openStore();
150
- const res = tx(() => {
151
- const topic = topicsRepo.ensureTopic(key, { cwd });
152
- const { task } = tasksRepo.insertTask(topic.id, {
153
- text: body,
154
- status: 'pending',
155
- from,
156
- createdAt: new Date().toISOString().replace('T', ' ').slice(0, 19),
157
- });
158
- topicsRepo.mutateOrder(key, (order) => {
159
- const list = [...order];
160
- const at = list.indexOf(task.id);
161
- if (at >= 0) list.splice(at, 1);
162
- list.unshift(task.id);
163
- return list;
164
- });
165
- topicsRepo.updateTopic(key, { bumpRevision: true });
166
- return task;
167
- });
168
- const t = topicsRepo.getTopic(key)!;
169
- return { status: 'ok', key, cwd: t.cwd || cwd, name: t.name, task: normalizeTask(res) };
170
- }
@@ -1,174 +0,0 @@
1
- // task move —— 本机队列 ⇄ 云端清单的任务迁移(原型设计稿 §5 / §7.3)。
2
- //
3
- // 心智模型:本机队列 = 这台机器的 agent 队列;云端清单 = 跨机器共享的工作空间。
4
- // 同一目录的任务可以在两侧之间迁移。原子性规则:**先写目标端、成功才改源端**——
5
- // 目标端写失败(未登录、网络故障)直接抛错,源端一字不动、不产生迁出记录;
6
- // 成功后才在本机条目上打 migratedTo(tombstone)。撤销按返回的 targetId 精确删,
7
- // **不按文本匹配**(同内容 ×N 时按文本删会误伤)。
8
- //
9
- // 本文件只做编排;store 读写原语在 ./service.js,云端读写复用 todo 服务。
10
- // 跨模块依赖刻意走**动态导入**:迁移不是启动路径,localtask 的启动不应拖上 todo
11
- // (分层约束也要求模块之间不静态互依)。
12
- import { badInput, notFound, conflict } from '../../core/errors.js';
13
- import * as local from './service.js';
14
-
15
- /** moveTask 的入参(HTTP/CLI body 原样 → any;云端读写可注入 _cloud)。 */
16
- export type MoveTaskInput = any;
17
-
18
- /** moveTask 的出站形状(两个方向 + 撤销,字段见函数体)。 */
19
- export type MoveTaskResult = Record<string, any>;
20
-
21
- const SIDES = new Set(['local', 'cloud']);
22
-
23
- let todoMod: any = null;
24
- async function cloudTodo(): Promise<any> {
25
- todoMod ||= await import('../todo/service.js');
26
- return todoMod;
27
- }
28
-
29
- // 云端读写可注入(单测用;HTTP/CLI 路径不传该字段——action run 显式挑选字段,
30
- // body 里的多余键到不了这里)。缺省走真实 todo 服务。
31
- async function cloudOf(p: MoveTaskInput): Promise<any> {
32
- if (p && p._cloud) return p._cloud;
33
- return cloudTodo();
34
- }
35
-
36
- function assertSides(from: string, to: string): void {
37
- if (!SIDES.has(from)) throw badInput('--from 只能是 local | cloud');
38
- if (!SIDES.has(to)) throw badInput('--to 只能是 local | cloud');
39
- if (from === to) throw badInput('--from 与 --to 不能相同(迁移要有方向)');
40
- }
41
-
42
- /** 迁移一条任务。参数见 localtask/index.js 的 task.move 声明。 */
43
- export async function moveTask(p: MoveTaskInput = {}): Promise<MoveTaskResult> {
44
- const from = String(p.from || '');
45
- const to = String(p.to || '');
46
- if (p.undo) return undoMove(p);
47
- assertSides(from, to);
48
- if (from === 'local') return moveToCloud(p);
49
- return moveToLocal(p);
50
- }
51
-
52
- // ─── 本机 → 云端 ──────────────────────────────────────────────────
53
-
54
- async function moveToCloud(p: MoveTaskInput = {}): Promise<MoveTaskResult> {
55
- const { cwd, key, id, topic, merge = false, group } = p;
56
- const cloud = await cloudOf(p);
57
- const loc = await local.getTopicTask({ cwd, key, id });
58
- const t = loc.task;
59
- if (t.migratedTo) {
60
- throw conflict(`#${t.id} 已迁移到云端「${t.migratedTo.topic}」(撤销请用 task move --undo)`);
61
- }
62
- if (t.status !== 'pending') throw conflict(`#${t.id} 不是待领取(已领取/已交付),不能再迁移`);
63
- if (t.deletedAt) throw conflict(`#${t.id} 已被删除,先恢复再迁移`);
64
-
65
- const cloudTopic = String(topic || '').trim() || loc.name; // 默认用目录名
66
- const all = await cloud.loadAll(group); // 未登录在这里抛 → 源端不动 ✓
67
- const dups = all.open.filter((x: any) => x.text === t.text && x.topic === cloudTopic);
68
-
69
- let targetId: number;
70
- let merged = false;
71
- if (merge && dups.length) {
72
- targetId = dups[0]!.id;
73
- merged = true;
74
- } else {
75
- const added = await cloud.addTodo({ topic: cloudTopic, text: t.text, groupId: group, from: 'local' });
76
- targetId = added.id;
77
- }
78
-
79
- // 目标端已写成功 → 才给源端打迁出标记
80
- const marked = await local.markTaskMigrated({
81
- key: loc.key,
82
- id: t.id,
83
- migratedTo: { side: 'cloud', topic: cloudTopic, targetId, at: local.stampNow() },
84
- });
85
- return {
86
- from: 'local',
87
- to: 'cloud',
88
- dirName: loc.name,
89
- topic: cloudTopic,
90
- text: t.text,
91
- targetId,
92
- tombstoneId: t.id,
93
- merged,
94
- dupCount: dups.length,
95
- movedAt: marked.task.migratedTo.at,
96
- };
97
- }
98
-
99
- // ─── 云端 → 本机 ──────────────────────────────────────────────────
100
-
101
- async function moveToLocal(p: MoveTaskInput = {}): Promise<MoveTaskResult> {
102
- const { topic, text, pick, cwd, key, group } = p;
103
- const cloud = await cloudOf(p);
104
- const body = String(text || '').trim();
105
- if (!body) throw badInput('--text 必填(云端任务按内容定位,不按 id——id 会被复用)');
106
- const t = String(topic || '').trim();
107
- if (!t) throw badInput('--topic 必填(云端主题 = 目录名)');
108
- if (!cwd && !key) throw badInput('需要 --cwd <目标目录> 或 --key <主题 key>(迁到哪个本机队列)');
109
-
110
- const all = await cloud.loadAll(group); // 未登录在这里抛 → 本机不动 ✓
111
- const hits: Array<{ task: any; index: number }> = [];
112
- all.open.forEach((task: any, index: number) => {
113
- if (task.text === body && task.topic === t) hits.push({ task, index });
114
- });
115
- if (!hits.length) {
116
- const where = t ? `主题「${t}」` : '';
117
- throw notFound(`云端待办${where}里没有这条任务: ${body.slice(0, 60)}`);
118
- }
119
- if (hits.length > 1 && (pick === undefined || pick === null)) {
120
- throw conflict(
121
- `云端待办有 ${hits.length} 条同内容任务,用 --pick <编号> 消歧`,
122
- { candidates: hits.map((h, i) => ({ pick: i, id: h.task.id, createdAt: h.task.createdAt, from: h.task.from || '' })) }
123
- );
124
- }
125
- const hit = hits[Math.min(Math.max(0, Number(pick) || 0), hits.length - 1)]!;
126
-
127
- // 先写目标端(本机待领取首位),成功才删云端那条
128
- const ins = await local.insertTaskAtTop({ cwd, key, text: hit.task.text, from: 'cloud' });
129
- await cloud.removeOpenById(hit.task.id, { groupId: group });
130
- return {
131
- from: 'cloud',
132
- to: 'local',
133
- dirName: ins.name,
134
- topic: t,
135
- text: hit.task.text,
136
- targetId: ins.task.id,
137
- tombstoneId: null,
138
- cloudTaskId: hit.task.id,
139
- movedAt: local.stampNow(),
140
- };
141
- }
142
-
143
- // ─── 撤销 ────────────────────────────────────────────────────────
144
- //
145
- // 传入**原 move 的同组参数** + --undo + --target-id(move 返回的 targetId)。
146
- // 撤销不是"再来一次反向 move"——它按精确 id 回退,不触发新的确认/消歧。
147
-
148
- async function undoMove(p: MoveTaskInput): Promise<MoveTaskResult> {
149
- const { from, to, 'target-id': targetId, merged = false, cwd, key, id, topic, text, group } = p;
150
- const cloud = await cloudOf(p);
151
- assertSides(from, to);
152
- const wantTarget = Number(targetId);
153
- if (!Number.isFinite(wantTarget) || wantTarget <= 0) {
154
- throw badInput('撤销需要 --target-id <迁移时返回的 targetId>');
155
- }
156
-
157
- if (from === 'local') {
158
- // local → cloud 的撤销:删掉云端那条(合并过的没新增,只清标记),清本机 tombstone
159
- if (!merged) await cloud.removeOpenById(wantTarget, { groupId: group });
160
- const cleared = await local.clearTaskMigrated({ cwd, key, id });
161
- if (!cleared.restored) {
162
- throw conflict('这条任务没有迁出记录,无从撤销');
163
- }
164
- return { undone: true, from, to, targetId: wantTarget, tombstoneId: cleared.task.id, dirName: cleared.name, text: cleared.task.text };
165
- }
166
-
167
- // cloud → local 的撤销:删掉本机那条(必须还没被领取),云端原样加回
168
- const rm = await local.removeTask({ cwd, key, id: wantTarget, purge: true });
169
- // removeTask 两条返回路径都带 removed(purge / 软删各一条),断言非空
170
- const body = String(text || '').trim() || rm.removed!.text;
171
- const cloudTopic = String(topic || '').trim() || rm.name;
172
- const added = await cloud.addTodo({ topic: cloudTopic, text: body, groupId: group });
173
- return { undone: true, from, to, targetId: wantTarget, cloudId: added.id, dirName: rm.name, text: body };
174
- }