@xopcai/xopc 0.0.110 → 0.0.112

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 (583) hide show
  1. package/README.md +46 -4
  2. package/README.zh-CN.md +46 -4
  3. package/dist/browser-ext/manifest.json +1 -1
  4. package/dist/extensions/feishu/src/outbound/media-load.js +1 -1
  5. package/dist/extensions/feishu/src/workflow-progress.js +1 -1
  6. package/dist/extensions/telegram/src/adapters/streaming-adapter.js +1 -1
  7. package/dist/extensions/telegram/src/inbound-processor.js +1 -1
  8. package/dist/extensions/telegram/src/plugin.js +1 -1
  9. package/dist/extensions/telegram/src/routing-integration.js +2 -2
  10. package/dist/extensions/telegram/src/update-offset-store.js +1 -1
  11. package/dist/extensions/telegram/src/workflow-progress.js +1 -1
  12. package/dist/extensions/telegram/xopc.extension.json +1 -1
  13. package/dist/extensions/weixin/src/api/api.js +2 -2
  14. package/dist/extensions/weixin/src/auth/accounts.js +1 -1
  15. package/dist/extensions/weixin/src/cdn/upload.js +1 -1
  16. package/dist/extensions/weixin/src/media/data-url.js +1 -1
  17. package/dist/extensions/weixin/src/messaging/debug-mode.js +1 -1
  18. package/dist/extensions/weixin/src/messaging/inbound.js +1 -1
  19. package/dist/extensions/weixin/src/messaging/process-message.js +1 -1
  20. package/dist/extensions/weixin/src/plugin.js +1 -1
  21. package/dist/extensions/weixin/src/storage/sync-buf.js +1 -1
  22. package/dist/extensions/weixin/src/workflow-progress.js +1 -1
  23. package/dist/gateway/static/root/apple-touch-icon.png +0 -0
  24. package/dist/gateway/static/root/assets/Combination-BzaXOLd9.js +41 -0
  25. package/dist/gateway/static/root/assets/agent-avatar-dicebear-EhRp-ZMa.js +1 -0
  26. package/dist/gateway/static/root/assets/agent-browser-settings-page-H4foVCiS.js +6 -0
  27. package/dist/gateway/static/root/assets/agent-defaults-tabbed-page-DDNw2oNU.js +1 -0
  28. package/dist/gateway/static/root/assets/agents-E_X2kzS1.js +71 -0
  29. package/dist/gateway/static/root/assets/app-management-settings-panel-BIy7KEsM.js +1 -0
  30. package/dist/gateway/static/root/assets/appearance-settings-DGQG8NwA.js +1 -0
  31. package/dist/gateway/static/root/assets/apps-page-BZLvInLr.js +1 -0
  32. package/dist/gateway/static/root/assets/archive-plugin-uuQPupqx.js +1 -0
  33. package/dist/gateway/static/root/assets/attachment-load-DBkv0cAv.js +2 -0
  34. package/dist/gateway/static/root/assets/{attachment-preview-renderer-CybMSIoS.js → attachment-preview-renderer-DonnL2dL.js} +1 -1
  35. package/dist/gateway/static/root/assets/binary-plugins-DxxN_VAR.js +2 -0
  36. package/dist/gateway/static/root/assets/block-editor-CwnUlRmO.js +180 -0
  37. package/dist/gateway/static/root/assets/channels-settings-BHvUKlzw.js +1 -0
  38. package/dist/gateway/static/root/assets/cn-JdwAhgNB.js +1 -0
  39. package/dist/gateway/static/root/assets/code-editor-dZTY2dRW.js +1 -0
  40. package/dist/gateway/static/root/assets/config-api-BD-NcD5d.js +3 -0
  41. package/dist/gateway/static/root/assets/config-reload-event-Bjh2zoKp.js +1 -0
  42. package/dist/gateway/static/root/assets/connectors-settings-VBzXcEXL.js +2 -0
  43. package/dist/gateway/static/root/assets/cron-api-C5DoipZA.js +1 -0
  44. package/dist/gateway/static/root/assets/cron-dreaming-jobs-nCMWCf0p.js +1 -0
  45. package/dist/gateway/static/root/assets/cron-page-BLTpdm34.js +3 -0
  46. package/dist/gateway/static/root/assets/dist-By6Rh2ee.js +1 -0
  47. package/dist/gateway/static/root/assets/dist-CkobR7mk.js +1 -0
  48. package/dist/gateway/static/root/assets/dist-DokQNVMQ.js +1 -0
  49. package/dist/gateway/static/root/assets/dreaming-scene-BHMRVEUS.js +4585 -0
  50. package/dist/gateway/static/root/assets/dreaming-settings-DSVhXTPq.js +1 -0
  51. package/dist/gateway/static/root/assets/extension-debug-page-BDHA9o_e.js +1 -0
  52. package/dist/gateway/static/root/assets/{extension-page-W1wiG38F.js → extension-page-DmDLVSPE.js} +1 -1
  53. package/dist/gateway/static/root/assets/extension-settings-page-1124aHw_.js +1 -0
  54. package/dist/gateway/static/root/assets/fetch-DOe56Wmy.js +1 -0
  55. package/dist/gateway/static/root/assets/format-cron-label-BsotZDO5.js +2 -0
  56. package/dist/gateway/static/root/assets/format-interval-label-tsMSvBSR.js +1 -0
  57. package/dist/gateway/static/root/assets/gateway-config-api-CsD4FC9D.js +1 -0
  58. package/dist/gateway/static/root/assets/gateway-settings-HQ8FBhY2.js +1 -0
  59. package/dist/gateway/static/root/assets/gateway-startup-retry-C1zg7pH3.js +1 -0
  60. package/dist/gateway/static/root/assets/goal-detail-page-BG3Onph0.js +1 -0
  61. package/dist/gateway/static/root/assets/goals-page-DgeKn8zL.js +2 -0
  62. package/dist/gateway/static/root/assets/goals-settings-B5nI6lgz.js +1 -0
  63. package/dist/gateway/static/root/assets/heartbeat-config-api-CIv42nJD.js +1 -0
  64. package/dist/gateway/static/root/assets/heartbeat-settings-DFcVuJ3M.js +1 -0
  65. package/dist/gateway/static/root/assets/html-workspace-editor-CQLWDiwE.js +1 -0
  66. package/dist/gateway/static/root/assets/index-5A_ZaABy.css +1 -0
  67. package/dist/gateway/static/root/assets/index-BTmbp2AU.js +121 -0
  68. package/dist/gateway/static/root/assets/interval-presets-DGP3S7OB.js +1 -0
  69. package/dist/gateway/static/root/assets/keyboard-shortcuts-settings-fETaDYQP.js +1 -0
  70. package/dist/gateway/static/root/assets/locale-store-DjbfSsfA.js +1 -0
  71. package/dist/gateway/static/root/assets/logs-page-B1-b27lK.js +2 -0
  72. package/dist/gateway/static/root/assets/markdown-editor-AssmZFx4.js +2 -0
  73. package/dist/gateway/static/root/assets/markdown-split-CgeBJMOD.js +1 -0
  74. package/dist/gateway/static/root/assets/media-plugins-C30GzlV2.js +1 -0
  75. package/dist/gateway/static/root/assets/mermaid-render-BbqDc_LQ.js +134 -0
  76. package/dist/gateway/static/root/assets/messages-BUUfPaZ9.js +3 -0
  77. package/dist/gateway/static/root/assets/middleware-Pd0e8Igk.js +1 -0
  78. package/dist/gateway/static/root/assets/models-hub-panel-DPcTS1-u.js +2 -0
  79. package/dist/gateway/static/root/assets/note-detail-page-xeGb4owe.js +2 -0
  80. package/dist/gateway/static/root/assets/note-image-lightbox-t1g0qZYh.js +1 -0
  81. package/dist/gateway/static/root/assets/note-time-hm6JO_Wi.js +1 -0
  82. package/dist/gateway/static/root/assets/notes-page-C_TdnKBe.js +1 -0
  83. package/dist/gateway/static/root/assets/preview-open-alternatives-DeWp9x5g.js +1 -0
  84. package/dist/gateway/static/root/assets/remote-access-hub-BtkPmJIN.js +1 -0
  85. package/dist/gateway/static/root/assets/save-bar-controls-BOaAOJI3.js +1 -0
  86. package/dist/gateway/static/root/assets/schedule-field-BLWLKqgw.js +1 -0
  87. package/dist/gateway/static/root/assets/schema-form-plqRFYT8.js +1 -0
  88. package/dist/gateway/static/root/assets/sessions-page-DOUjxzJm.js +1 -0
  89. package/dist/gateway/static/root/assets/settings-advanced-gate-qK_bnTrw.js +1 -0
  90. package/dist/gateway/static/root/assets/settings-collapsible-section-BP5zRrDI.js +1 -0
  91. package/dist/gateway/static/root/assets/settings-form-section-Bv8MZplG.js +1 -0
  92. package/dist/gateway/static/root/assets/settings-page-DmDfE1ww.js +1 -0
  93. package/dist/gateway/static/root/assets/setup-status-panel-BEFwNcIZ.js +1 -0
  94. package/dist/gateway/static/root/assets/share-preview-page-4OX1YCgp.js +2 -0
  95. package/dist/gateway/static/root/assets/shares-settings-CbKmJZot.js +1 -0
  96. package/dist/gateway/static/root/assets/skill-reload-api-YdtnUHtK.js +1 -0
  97. package/dist/gateway/static/root/assets/skills-page-DwW1IzQ0.js +2 -0
  98. package/dist/gateway/static/root/assets/system-settings-panel-CGy4f_s2.js +1 -0
  99. package/dist/gateway/static/root/assets/theme-store-CD2wtgZV.js +1 -0
  100. package/dist/gateway/static/root/assets/use-agent-defaults-form-BMuMvzl_.js +1 -0
  101. package/dist/gateway/static/root/assets/use-blob-object-url-D4BFuzZB.js +1 -0
  102. package/dist/gateway/static/root/assets/use-channel-catalog-CjGHnDvN.js +1 -0
  103. package/dist/gateway/static/root/assets/use-settings-tab-guard-BMMFa0oA.js +1 -0
  104. package/dist/gateway/static/root/assets/vendor-codemirror-CNP1wPe7.js +45 -0
  105. package/dist/gateway/static/root/assets/voice-api-key-field-DnRbhMNq.js +1 -0
  106. package/dist/gateway/static/root/assets/voice-player-store-D5vzWwls.js +1 -0
  107. package/dist/gateway/static/root/assets/{workflow-page.utils-EYg_xBQS.js → workflow-page.utils-tjGpRVnw.js} +1 -1
  108. package/dist/gateway/static/root/assets/workflows-page-DqqHKGj2.js +18 -0
  109. package/dist/gateway/static/root/favicon-16x16.png +0 -0
  110. package/dist/gateway/static/root/favicon-32x32.png +0 -0
  111. package/dist/gateway/static/root/favicon.ico +0 -0
  112. package/dist/gateway/static/root/favicon.svg +14 -12
  113. package/dist/gateway/static/root/index.html +18 -15
  114. package/dist/package.js +1 -1
  115. package/dist/src/agent/agent-manager.d.ts +28 -2
  116. package/dist/src/agent/agent-manager.js +82 -11
  117. package/dist/src/agent/agent-manager.js.map +1 -1
  118. package/dist/src/agent/agent-scope.js +1 -1
  119. package/dist/src/agent/bootstrap/load-bootstrap-files.js +1 -1
  120. package/dist/src/agent/context/workspace-seed.js +2 -2
  121. package/dist/src/agent/context/workspace-state.js +1 -1
  122. package/dist/src/agent/context/workspace.js +1 -1
  123. package/dist/src/agent/goals/checklist-judge.d.ts +5 -0
  124. package/dist/src/agent/goals/checklist-judge.js +26 -2
  125. package/dist/src/agent/goals/checklist-judge.js.map +1 -1
  126. package/dist/src/agent/goals/evaluate-turn.d.ts +5 -1
  127. package/dist/src/agent/goals/evaluate-turn.js +29 -3
  128. package/dist/src/agent/goals/evaluate-turn.js.map +1 -1
  129. package/dist/src/agent/goals/goal-locale.d.ts +0 -2
  130. package/dist/src/agent/goals/goal-locale.js +3 -16
  131. package/dist/src/agent/goals/goal-locale.js.map +1 -1
  132. package/dist/src/agent/goals/persistent-goal-service.d.ts +9 -0
  133. package/dist/src/agent/goals/persistent-goal-service.js +3 -2
  134. package/dist/src/agent/goals/persistent-goal-service.js.map +1 -1
  135. package/dist/src/agent/goals/post-turn.d.ts +7 -0
  136. package/dist/src/agent/goals/post-turn.js +70 -25
  137. package/dist/src/agent/goals/post-turn.js.map +1 -1
  138. package/dist/src/agent/goals/state.d.ts +0 -5
  139. package/dist/src/agent/goals/state.js +1 -96
  140. package/dist/src/agent/goals/state.js.map +1 -1
  141. package/dist/src/agent/image/load-image-media.js +2 -2
  142. package/dist/src/agent/ipc/inbox.js +3 -3
  143. package/dist/src/agent/ipc/socket.js +1 -1
  144. package/dist/src/agent/mcp/bundle-mcp-materialize.js +1 -1
  145. package/dist/src/agent/mcp/bundle-mcp-runtime.js +1 -1
  146. package/dist/src/agent/mcp/mcp-transport-config.js +1 -1
  147. package/dist/src/agent/mcp/mcp-transport.js +1 -1
  148. package/dist/src/agent/memory/builtin-memory-store.js +1 -1
  149. package/dist/src/agent/memory/dreaming/deep-promotion.js +1 -1
  150. package/dist/src/agent/memory/dreaming/events.js +1 -1
  151. package/dist/src/agent/memory/dreaming/last-run.js +1 -1
  152. package/dist/src/agent/memory/dreaming/light-sweep.js +1 -1
  153. package/dist/src/agent/memory/dreaming/preview.js +1 -1
  154. package/dist/src/agent/memory/dreaming/rem-patterns.js +1 -1
  155. package/dist/src/agent/memory/dreaming/short-term-store.js +1 -1
  156. package/dist/src/agent/memory/dreaming/utils.js +1 -1
  157. package/dist/src/agent/memory/memory-flush.js +1 -1
  158. package/dist/src/agent/memory/plugin-discovery.js +1 -1
  159. package/dist/src/agent/messaging/command-handler.d.ts +7 -0
  160. package/dist/src/agent/messaging/command-handler.js +11 -2
  161. package/dist/src/agent/messaging/command-handler.js.map +1 -1
  162. package/dist/src/agent/models/manager.js +1 -1
  163. package/dist/src/agent/prompt/memory/index.js +1 -1
  164. package/dist/src/agent/prompt/service-prompt-builder.js +2 -2
  165. package/dist/src/agent/reply/post-compaction-context.js +1 -1
  166. package/dist/src/agent/reply/workspace-boundary-read.js +1 -1
  167. package/dist/src/agent/sandbox/path-policy.js +2 -2
  168. package/dist/src/agent/service/direct-turn-helpers.d.ts +2 -0
  169. package/dist/src/agent/service/direct-turn-helpers.js +3 -2
  170. package/dist/src/agent/service/direct-turn-helpers.js.map +1 -1
  171. package/dist/src/agent/service/process-direct-streaming.js +10 -1
  172. package/dist/src/agent/service/process-direct-streaming.js.map +1 -1
  173. package/dist/src/agent/service/reconcile-dreaming-cron.js +8 -5
  174. package/dist/src/agent/service/reconcile-dreaming-cron.js.map +1 -1
  175. package/dist/src/agent/service.d.ts +2 -1
  176. package/dist/src/agent/service.js +30 -6
  177. package/dist/src/agent/service.js.map +1 -1
  178. package/dist/src/agent/service.types.d.ts +12 -0
  179. package/dist/src/agent/session/session-config-service.d.ts +8 -0
  180. package/dist/src/agent/session/session-config-service.js +20 -0
  181. package/dist/src/agent/session/session-config-service.js.map +1 -1
  182. package/dist/src/agent/session/session-inspector.js +1 -1
  183. package/dist/src/agent/skills/config.js +2 -2
  184. package/dist/src/agent/skills/filesystem-watcher.d.ts +19 -0
  185. package/dist/src/agent/skills/filesystem-watcher.js +182 -0
  186. package/dist/src/agent/skills/filesystem-watcher.js.map +1 -0
  187. package/dist/src/agent/skills/hub-hash.js +2 -2
  188. package/dist/src/agent/skills/hub-lock.js +1 -1
  189. package/dist/src/agent/skills/hub-pull.js +30 -36
  190. package/dist/src/agent/skills/hub-pull.js.map +1 -1
  191. package/dist/src/agent/skills/index.js +82 -38
  192. package/dist/src/agent/skills/index.js.map +1 -1
  193. package/dist/src/agent/skills/installer.js +2 -2
  194. package/dist/src/agent/skills/managed-store.d.ts +19 -0
  195. package/dist/src/agent/skills/managed-store.js +97 -38
  196. package/dist/src/agent/skills/managed-store.js.map +1 -1
  197. package/dist/src/agent/skills/skill-manage-ops.js +1 -1
  198. package/dist/src/agent/skills/skill-manager.d.ts +16 -6
  199. package/dist/src/agent/skills/skill-manager.js +79 -24
  200. package/dist/src/agent/skills/skill-manager.js.map +1 -1
  201. package/dist/src/agent/skills/skill-view-path.js +1 -1
  202. package/dist/src/agent/skills/test-framework.js +1 -1
  203. package/dist/src/agent/skills/types.d.ts +11 -0
  204. package/dist/src/agent/skills/watcher.js +1 -1
  205. package/dist/src/agent/starter-agents.js +1 -1
  206. package/dist/src/agent/tools/cronjob-tool.d.ts +8 -3
  207. package/dist/src/agent/tools/cronjob-tool.js +82 -24
  208. package/dist/src/agent/tools/cronjob-tool.js.map +1 -1
  209. package/dist/src/agent/tools/dreaming-tool.js +1 -1
  210. package/dist/src/agent/tools/edit.d.ts +2 -0
  211. package/dist/src/agent/tools/edit.js +10 -0
  212. package/dist/src/agent/tools/edit.js.map +1 -1
  213. package/dist/src/agent/tools/factory.js +17 -4
  214. package/dist/src/agent/tools/factory.js.map +1 -1
  215. package/dist/src/agent/tools/find.js +1 -1
  216. package/dist/src/agent/tools/goal-evidence-recorder.d.ts +6 -0
  217. package/dist/src/agent/tools/goal-evidence-recorder.js +34 -0
  218. package/dist/src/agent/tools/goal-evidence-recorder.js.map +1 -0
  219. package/dist/src/agent/tools/goal-tool.d.ts +19 -0
  220. package/dist/src/agent/tools/goal-tool.js +101 -0
  221. package/dist/src/agent/tools/goal-tool.js.map +1 -0
  222. package/dist/src/agent/tools/grep.js +1 -1
  223. package/dist/src/agent/tools/image-generate-tool.js +1 -1
  224. package/dist/src/agent/tools/index.d.ts +1 -0
  225. package/dist/src/agent/tools/index.js +2 -1
  226. package/dist/src/agent/tools/shell.d.ts +2 -0
  227. package/dist/src/agent/tools/shell.js +17 -2
  228. package/dist/src/agent/tools/shell.js.map +1 -1
  229. package/dist/src/agent/tools/skill-manage-tool.js +1 -1
  230. package/dist/src/agent/tools/workflow-tool.d.ts +1 -0
  231. package/dist/src/agent/tools/workflow-tool.js +11 -3
  232. package/dist/src/agent/tools/workflow-tool.js.map +1 -1
  233. package/dist/src/agent/tools/write.d.ts +2 -0
  234. package/dist/src/agent/tools/write.js +11 -0
  235. package/dist/src/agent/tools/write.js.map +1 -1
  236. package/dist/src/agent/workflow/catalog.js +1 -1
  237. package/dist/src/agent/workspace-runtime/registry.d.ts +5 -0
  238. package/dist/src/agent/workspace-runtime/registry.js +7 -0
  239. package/dist/src/agent/workspace-runtime/registry.js.map +1 -1
  240. package/dist/src/ai-assist/text-assist.d.ts +39 -0
  241. package/dist/src/ai-assist/text-assist.js +234 -0
  242. package/dist/src/ai-assist/text-assist.js.map +1 -0
  243. package/dist/src/auth/credentials.js +2 -2
  244. package/dist/src/auth/profiles/store.js +2 -2
  245. package/dist/src/auth/sync-provider-auth.js +1 -1
  246. package/dist/src/browser/cache-dir-policy.js +1 -1
  247. package/dist/src/browser/cdp-local-launcher.js +2 -2
  248. package/dist/src/browser/providers/browser-ext-install.js +4 -4
  249. package/dist/src/browser/providers/cloakbrowser.js +5 -5
  250. package/dist/src/browser/providers/playwright-doctor.js +1 -1
  251. package/dist/src/browser/stealth.js +1 -1
  252. package/dist/src/channels/attachments/inbound-persist.d.ts +7 -0
  253. package/dist/src/channels/attachments/inbound-persist.js +20 -2
  254. package/dist/src/channels/attachments/inbound-persist.js.map +1 -1
  255. package/dist/src/channels/outbound/persist-store.js +1 -1
  256. package/dist/src/channels/pairing/allow-from-file.js +1 -1
  257. package/dist/src/channels/pairing/pairing-store.js +2 -2
  258. package/dist/src/chat-commands/agent-edit.js +2 -2
  259. package/dist/src/chat-commands/builtins/config.js +3 -3
  260. package/dist/src/chat-commands/builtins/goal.d.ts +1 -1
  261. package/dist/src/chat-commands/builtins/goal.js +55 -97
  262. package/dist/src/chat-commands/builtins/goal.js.map +1 -1
  263. package/dist/src/chat-commands/builtins/subgoal.d.ts +1 -1
  264. package/dist/src/chat-commands/builtins/subgoal.js +49 -108
  265. package/dist/src/chat-commands/builtins/subgoal.js.map +1 -1
  266. package/dist/src/chat-commands/builtins/system.js +11 -4
  267. package/dist/src/chat-commands/builtins/system.js.map +1 -1
  268. package/dist/src/chat-commands/builtins/workflow.js +132 -8
  269. package/dist/src/chat-commands/builtins/workflow.js.map +1 -1
  270. package/dist/src/chat-commands/context.d.ts +6 -0
  271. package/dist/src/chat-commands/context.js +12 -0
  272. package/dist/src/chat-commands/context.js.map +1 -1
  273. package/dist/src/chat-commands/types.d.ts +7 -0
  274. package/dist/src/cli/command-catalog.js +43 -0
  275. package/dist/src/cli/command-catalog.js.map +1 -1
  276. package/dist/src/cli/command-loaders.js +1 -0
  277. package/dist/src/cli/command-loaders.js.map +1 -1
  278. package/dist/src/cli/command-manifest.js +4 -0
  279. package/dist/src/cli/command-manifest.js.map +1 -1
  280. package/dist/src/cli/commands/config.js +1 -1
  281. package/dist/src/cli/commands/cron.js +55 -16
  282. package/dist/src/cli/commands/cron.js.map +1 -1
  283. package/dist/src/cli/commands/doctor/checks/config-health.js +1 -1
  284. package/dist/src/cli/commands/doctor/checks/cron-health.js +2 -83
  285. package/dist/src/cli/commands/doctor/checks/cron-health.js.map +1 -1
  286. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  287. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
  288. package/dist/src/cli/commands/doctor/checks/state-integrity.js +1 -1
  289. package/dist/src/cli/commands/doctor/checks/workspace-status.js +1 -1
  290. package/dist/src/cli/commands/extension-create.js +1 -1
  291. package/dist/src/cli/commands/extension-dev.js +2 -2
  292. package/dist/src/cli/commands/extension-marketplace.js +2 -2
  293. package/dist/src/cli/commands/extension-pack.js +2 -2
  294. package/dist/src/cli/commands/extension.js +3 -3
  295. package/dist/src/cli/commands/gateway/logs.js +1 -1
  296. package/dist/src/cli/commands/goal.d.ts +4 -0
  297. package/dist/src/cli/commands/goal.js +213 -0
  298. package/dist/src/cli/commands/goal.js.map +1 -0
  299. package/dist/src/cli/commands/image.js +1 -1
  300. package/dist/src/cli/commands/init.js +2 -2
  301. package/dist/src/cli/commands/models.js +1 -1
  302. package/dist/src/cli/commands/onboard.js +11 -5
  303. package/dist/src/cli/commands/onboard.js.map +1 -1
  304. package/dist/src/cli/commands/skills-test.js +1 -1
  305. package/dist/src/cli/templates.js +1 -1
  306. package/dist/src/cli/utils/gateway-client.js +1 -1
  307. package/dist/src/cli/utils/init-workspace-core.js +2 -2
  308. package/dist/src/config/agent-profile.js +1 -1
  309. package/dist/src/config/agent-typed-models.js +1 -1
  310. package/dist/src/config/gateway-bind.js +1 -1
  311. package/dist/src/config/index.js +8 -8
  312. package/dist/src/config/loader.js +4 -4
  313. package/dist/src/config/models-json.js +2 -2
  314. package/dist/src/config/paths-state.js +1 -1
  315. package/dist/src/config/paths.js +1 -1
  316. package/dist/src/config/profile.js +1 -1
  317. package/dist/src/config/reload.js +1 -1
  318. package/dist/src/config/schema.d.ts +115 -2
  319. package/dist/src/config/schema.js +63 -7
  320. package/dist/src/config/schema.js.map +1 -1
  321. package/dist/src/config/web-patch.d.ts +14 -1
  322. package/dist/src/config/web-patch.js +45 -8
  323. package/dist/src/config/web-patch.js.map +1 -1
  324. package/dist/src/config/workspace-path.js +1 -1
  325. package/dist/src/cron/executor.d.ts +2 -0
  326. package/dist/src/cron/executor.js +126 -70
  327. package/dist/src/cron/executor.js.map +1 -1
  328. package/dist/src/cron/index.d.ts +1 -1
  329. package/dist/src/cron/index.js +3 -3
  330. package/dist/src/cron/job-content.js +1 -0
  331. package/dist/src/cron/job-content.js.map +1 -1
  332. package/dist/src/cron/run-log-store.d.ts +1 -0
  333. package/dist/src/cron/run-log-store.js +4 -2
  334. package/dist/src/cron/run-log-store.js.map +1 -1
  335. package/dist/src/cron/schedule.d.ts +10 -0
  336. package/dist/src/cron/schedule.js +85 -0
  337. package/dist/src/cron/schedule.js.map +1 -0
  338. package/dist/src/cron/service.d.ts +34 -77
  339. package/dist/src/cron/service.js +327 -264
  340. package/dist/src/cron/service.js.map +1 -1
  341. package/dist/src/cron/types.d.ts +97 -49
  342. package/dist/src/cron/validation.d.ts +374 -86
  343. package/dist/src/cron/validation.js +156 -129
  344. package/dist/src/cron/validation.js.map +1 -1
  345. package/dist/src/cron/workflow-run-completion.js +1 -1
  346. package/dist/src/daemon/constants.js +1 -1
  347. package/dist/src/daemon/install-plan.js +2 -2
  348. package/dist/src/daemon/launchd.js +2 -2
  349. package/dist/src/daemon/schtasks.js +2 -2
  350. package/dist/src/daemon/systemd.js +2 -2
  351. package/dist/src/extensions/bundle-mcp.js +1 -1
  352. package/dist/src/extensions/discover-extensions.js +2 -2
  353. package/dist/src/extensions/health.js +1 -1
  354. package/dist/src/extensions/install.js +2 -2
  355. package/dist/src/extensions/loader.js +2 -2
  356. package/dist/src/extensions/lockfile.js +3 -3
  357. package/dist/src/extensions/security.js +1 -1
  358. package/dist/src/extensions/update.js +2 -2
  359. package/dist/src/gateway/agents-admin.js +2 -2
  360. package/dist/src/gateway/chat-stream/mapper.d.ts +1 -0
  361. package/dist/src/gateway/chat-stream/mapper.js +6 -2
  362. package/dist/src/gateway/chat-stream/mapper.js.map +1 -1
  363. package/dist/src/gateway/chat-stream/protocol.d.ts +2 -0
  364. package/dist/src/gateway/file-path-classifier.js +2 -2
  365. package/dist/src/gateway/hono/lib/config-payload.d.ts +14 -1
  366. package/dist/src/gateway/hono/lib/config-payload.js +1 -1
  367. package/dist/src/gateway/hono/lib/extension-store.js +2 -2
  368. package/dist/src/gateway/hono/lib/static-ui.js +2 -2
  369. package/dist/src/gateway/hono/oauth-async.js +1 -1
  370. package/dist/src/gateway/hono/routes/agents.js +1 -1
  371. package/dist/src/gateway/hono/routes/ai-assist.d.ts +3 -0
  372. package/dist/src/gateway/hono/routes/ai-assist.js +66 -0
  373. package/dist/src/gateway/hono/routes/ai-assist.js.map +1 -0
  374. package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
  375. package/dist/src/gateway/hono/routes/commands-skills.js +7 -0
  376. package/dist/src/gateway/hono/routes/commands-skills.js.map +1 -1
  377. package/dist/src/gateway/hono/routes/config-patch/misc.js +1 -1
  378. package/dist/src/gateway/hono/routes/cron.js +24 -5
  379. package/dist/src/gateway/hono/routes/cron.js.map +1 -1
  380. package/dist/src/gateway/hono/routes/dreaming.js +1 -1
  381. package/dist/src/gateway/hono/routes/goals.d.ts +1 -1
  382. package/dist/src/gateway/hono/routes/goals.js +670 -173
  383. package/dist/src/gateway/hono/routes/goals.js.map +1 -1
  384. package/dist/src/gateway/hono/routes/home.d.ts +5 -0
  385. package/dist/src/gateway/hono/routes/home.js +90 -3
  386. package/dist/src/gateway/hono/routes/home.js.map +1 -1
  387. package/dist/src/gateway/hono/routes/host-fs.js +2 -2
  388. package/dist/src/gateway/hono/routes/lazy-bundles.js +8 -0
  389. package/dist/src/gateway/hono/routes/lazy-bundles.js.map +1 -1
  390. package/dist/src/gateway/hono/routes/models.js +1 -1
  391. package/dist/src/gateway/hono/routes/notes.js +20 -14
  392. package/dist/src/gateway/hono/routes/notes.js.map +1 -1
  393. package/dist/src/gateway/hono/routes/shares.js +1 -1
  394. package/dist/src/gateway/hono/routes/workflows.js +8 -4
  395. package/dist/src/gateway/hono/routes/workflows.js.map +1 -1
  396. package/dist/src/gateway/hono/routes/workspace.js +2 -2
  397. package/dist/src/gateway/hono/sse.js.map +1 -1
  398. package/dist/src/gateway/lock.js +3 -3
  399. package/dist/src/gateway/ports.js +1 -1
  400. package/dist/src/gateway/service/agent-runner.d.ts +2 -0
  401. package/dist/src/gateway/service/agent-runner.js +8 -4
  402. package/dist/src/gateway/service/agent-runner.js.map +1 -1
  403. package/dist/src/gateway/service/config-coordinator.js +1 -1
  404. package/dist/src/gateway/service/marketplace-service.d.ts +22 -10
  405. package/dist/src/gateway/service/marketplace-service.js +46 -5
  406. package/dist/src/gateway/service/marketplace-service.js.map +1 -1
  407. package/dist/src/gateway/service/run-gateway-agent.d.ts +3 -0
  408. package/dist/src/gateway/service/run-gateway-agent.js.map +1 -1
  409. package/dist/src/gateway/service.d.ts +8 -0
  410. package/dist/src/gateway/service.js +79 -6
  411. package/dist/src/gateway/service.js.map +1 -1
  412. package/dist/src/gateway/workspace-fs-file-list.js +1 -1
  413. package/dist/src/goals/goal-notifications.d.ts +29 -0
  414. package/dist/src/goals/goal-notifications.js +154 -0
  415. package/dist/src/goals/goal-notifications.js.map +1 -0
  416. package/dist/src/goals/goal-queue-store.d.ts +16 -0
  417. package/dist/src/goals/goal-queue-store.js +131 -0
  418. package/dist/src/goals/goal-queue-store.js.map +1 -0
  419. package/dist/src/goals/goal-queue-types.d.ts +31 -0
  420. package/dist/src/goals/goal-queue-types.js +1 -0
  421. package/dist/src/goals/goal-runner.d.ts +17 -0
  422. package/dist/src/goals/goal-runner.js +127 -0
  423. package/dist/src/goals/goal-runner.js.map +1 -0
  424. package/dist/src/goals/goal-service.d.ts +77 -0
  425. package/dist/src/goals/goal-service.js +261 -0
  426. package/dist/src/goals/goal-service.js.map +1 -0
  427. package/dist/src/goals/goal-store.d.ts +38 -0
  428. package/dist/src/goals/goal-store.js +404 -0
  429. package/dist/src/goals/goal-store.js.map +1 -0
  430. package/dist/src/goals/goal-workflow-judge.d.ts +13 -0
  431. package/dist/src/goals/goal-workflow-judge.js +147 -0
  432. package/dist/src/goals/goal-workflow-judge.js.map +1 -0
  433. package/dist/src/goals/index.d.ts +10 -0
  434. package/dist/src/goals/index.js +7 -0
  435. package/dist/src/goals/types.d.ts +119 -0
  436. package/dist/src/goals/types.js +1 -0
  437. package/dist/src/i18n/goals-bundle.js +1 -1
  438. package/dist/src/i18n/index.js +1 -1
  439. package/dist/src/i18n/share-tool-bundle.js +2 -2
  440. package/dist/src/infra/brew.js +1 -1
  441. package/dist/src/infra/package-json.js +1 -1
  442. package/dist/src/infra/package-update-steps.js +1 -1
  443. package/dist/src/infra/path-env.js +2 -2
  444. package/dist/src/infra/restart.js +1 -1
  445. package/dist/src/infra/stable-node-path.js +1 -1
  446. package/dist/src/infra/update-check.js +1 -1
  447. package/dist/src/infra/update-global.js +1 -1
  448. package/dist/src/infra/update-lock.js +2 -2
  449. package/dist/src/infra/update-restart.js +1 -1
  450. package/dist/src/infra/update-runner.js +1 -1
  451. package/dist/src/infra/update-startup.js +1 -1
  452. package/dist/src/infra/write-file-atomic.js +2 -2
  453. package/dist/src/media/store.js +1 -1
  454. package/dist/src/notes/agent-context.js +1 -1
  455. package/dist/src/notes/service.js +1 -1
  456. package/dist/src/notes/store.js +2 -2
  457. package/dist/src/project-trust/trust-store.js +2 -2
  458. package/dist/src/providers/auth-runtime/auth-profile-store.js +1 -1
  459. package/dist/src/providers/index.js +1 -1
  460. package/dist/src/providers/model-registry.js +4 -4
  461. package/dist/src/session/init-session-turn.js +2 -2
  462. package/dist/src/session/resolve-session.js +3 -3
  463. package/dist/src/session/session-title.js +2 -2
  464. package/dist/src/session/store.js +1 -1
  465. package/dist/src/share/share-auto.js +2 -2
  466. package/dist/src/share/share-store.js +3 -3
  467. package/dist/src/share/share-thumbnail.js +2 -2
  468. package/dist/src/share/share-zip.js +1 -1
  469. package/dist/src/share/site-share-store.js +3 -3
  470. package/dist/src/share/site-static-serve.js +1 -1
  471. package/dist/src/storage/sqlite/connection.js +1 -1
  472. package/dist/src/storage/sqlite/cron-job-repository.d.ts +6 -0
  473. package/dist/src/storage/sqlite/cron-job-repository.js +70 -0
  474. package/dist/src/storage/sqlite/cron-job-repository.js.map +1 -0
  475. package/dist/src/storage/sqlite/cron-run-repository.js +0 -1
  476. package/dist/src/storage/sqlite/cron-run-repository.js.map +1 -1
  477. package/dist/src/storage/sqlite/index.d.ts +1 -0
  478. package/dist/src/storage/sqlite/index.js +2 -1
  479. package/dist/src/storage/sqlite/memory-index-repository.js +2 -2
  480. package/dist/src/storage/sqlite/migrations/006_add_goals.sql +108 -0
  481. package/dist/src/storage/sqlite/migrations/007_goal_run_judge_schema.sql +4 -0
  482. package/dist/src/storage/sqlite/migrations/008_goal_queue_workflow_runs.sql +53 -0
  483. package/dist/src/storage/sqlite/migrations/009_cron_jobs.sql +24 -0
  484. package/dist/src/storage/sqlite/migrations/discover.js +1 -1
  485. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  486. package/dist/src/storage/sqlite/migrations/runner.js +4 -4
  487. package/dist/src/storage/sqlite/migrations/runner.js.map +1 -1
  488. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  489. package/dist/src/storage/sqlite/schema.js +2 -2
  490. package/dist/src/storage/sqlite/schema.sql +188 -0
  491. package/dist/src/tui/clipboard-image.js +3 -3
  492. package/dist/src/tui/extension-host/load-extensions.js +1 -1
  493. package/dist/src/tui/theme-manager.js +1 -1
  494. package/dist/src/tui/tui-command-formatters.js +4 -4
  495. package/dist/src/tui/tui-commands.js +2 -2
  496. package/dist/src/tui/tui-keybindings-file.js +1 -1
  497. package/dist/src/tui/tui-scoped-models.js +2 -2
  498. package/dist/src/tui/tui-settings.js +1 -1
  499. package/dist/src/tui/tui-startup-resources.js +1 -1
  500. package/dist/src/tui/tui.js +6 -6
  501. package/dist/src/tunnel/frpc-binary.js +4 -4
  502. package/dist/src/tunnel/frpc-config.js +1 -1
  503. package/dist/src/tunnel/frpc-extract.js +1 -1
  504. package/dist/src/tunnel/tunnel-state.js +1 -1
  505. package/dist/src/utils/logger/audit.js +1 -1
  506. package/dist/src/utils/logger/log-store.js +1 -1
  507. package/dist/src/utils/logger/rotation.js +1 -1
  508. package/dist/src/utils/logger/stats.d.ts +1 -1
  509. package/dist/src/utils/logger/streams.js +1 -1
  510. package/dist/src/voice/tts/audio.js +1 -1
  511. package/dist/src/voice/tts/providers/edge-speech.js +2 -2
  512. package/dist/src/workflows/domain/run.d.ts +1 -0
  513. package/dist/src/workflows/domain/run.js.map +1 -1
  514. package/dist/src/workflows/draft/workflow-draft-service.js +1 -1
  515. package/dist/src/workflows/engine/projector.js +23 -14
  516. package/dist/src/workflows/engine/projector.js.map +1 -1
  517. package/dist/src/workflows/engine/workflow-engine.d.ts +1 -0
  518. package/dist/src/workflows/engine/workflow-engine.js +36 -0
  519. package/dist/src/workflows/engine/workflow-engine.js.map +1 -1
  520. package/dist/src/workflows/index.js +1 -1
  521. package/dist/src/workflows/service/workflow-run-service.d.ts +1 -0
  522. package/dist/src/workflows/service/workflow-run-service.js +7 -3
  523. package/dist/src/workflows/service/workflow-run-service.js.map +1 -1
  524. package/dist/src/workflows/service/workflow-run-service.types.d.ts +1 -0
  525. package/dist/src/workflows/service/workflow-session-bridge.js +8 -1
  526. package/dist/src/workflows/service/workflow-session-bridge.js.map +1 -1
  527. package/dist/src/workflows/store/event-store.js +1 -1
  528. package/dist/src/workflows/store/run-index-store.d.ts +8 -0
  529. package/dist/src/workflows/store/run-index-store.js +58 -0
  530. package/dist/src/workflows/store/run-index-store.js.map +1 -0
  531. package/dist/src/workflows/store/run-store.d.ts +2 -0
  532. package/dist/src/workflows/store/run-store.js +15 -22
  533. package/dist/src/workflows/store/run-store.js.map +1 -1
  534. package/package.json +10 -5
  535. package/dist/gateway/static/root/assets/Combination-HAlzriaz.js +0 -41
  536. package/dist/gateway/static/root/assets/agents-CFFioJCI.js +0 -78
  537. package/dist/gateway/static/root/assets/apps-page-BYDmkbzG.js +0 -1
  538. package/dist/gateway/static/root/assets/channels-settings-CsbDaMvd.js +0 -1
  539. package/dist/gateway/static/root/assets/circle-check-C23XjkUj.js +0 -1
  540. package/dist/gateway/static/root/assets/copy-Dv6d4Dvw.js +0 -1
  541. package/dist/gateway/static/root/assets/cron-page-Apk-7p4p.js +0 -1
  542. package/dist/gateway/static/root/assets/dist-DmGDgpy2.js +0 -1
  543. package/dist/gateway/static/root/assets/extension-debug-page-pxFC-tUa.js +0 -1
  544. package/dist/gateway/static/root/assets/extension-settings-page-COXSv6xP.js +0 -1
  545. package/dist/gateway/static/root/assets/fetch-CFdKBnE6.js +0 -1
  546. package/dist/gateway/static/root/assets/gateway-startup-retry-DdngdObI.js +0 -1
  547. package/dist/gateway/static/root/assets/heartbeat-config-api-DcmAMYmN.js +0 -1
  548. package/dist/gateway/static/root/assets/index-C_2yKRJX.js +0 -4845
  549. package/dist/gateway/static/root/assets/index-DI5_GsZt.css +0 -1
  550. package/dist/gateway/static/root/assets/logs-page-DvTWUOzd.js +0 -2
  551. package/dist/gateway/static/root/assets/note-detail-page-CZbdugWZ.js +0 -180
  552. package/dist/gateway/static/root/assets/note-time-RdyBZxj3.js +0 -1
  553. package/dist/gateway/static/root/assets/notes-page-mEAwy3e1.js +0 -1
  554. package/dist/gateway/static/root/assets/schema-form-DEvdni_r.js +0 -1
  555. package/dist/gateway/static/root/assets/sessions-page-BsgffzV4.js +0 -1
  556. package/dist/gateway/static/root/assets/settings-advanced-gate-t6v8Dwb8.js +0 -2
  557. package/dist/gateway/static/root/assets/settings-form-section-BoYYZmJG.js +0 -1
  558. package/dist/gateway/static/root/assets/settings-page-ClIthYF8.js +0 -3
  559. package/dist/gateway/static/root/assets/share-preview-page-Dd9et7KD.js +0 -2
  560. package/dist/gateway/static/root/assets/skills-page-DEXtxyfQ.js +0 -2
  561. package/dist/gateway/static/root/assets/theme-store-BZozwAeK.js +0 -1
  562. package/dist/gateway/static/root/assets/url-DQRqHuL-.js +0 -3
  563. package/dist/gateway/static/root/assets/vendor-codemirror-DYoKfS8f.js +0 -45
  564. package/dist/gateway/static/root/assets/voice-api-key-field-CNrKzQrf.js +0 -1
  565. package/dist/gateway/static/root/assets/workflows-page-EMZkzJNN.js +0 -18
  566. package/dist/gateway/static/root/favicon-16.png +0 -0
  567. package/dist/gateway/static/root/favicon-32.png +0 -0
  568. package/dist/src/agent/goals/checklist-user.d.ts +0 -24
  569. package/dist/src/agent/goals/checklist-user.js +0 -92
  570. package/dist/src/agent/goals/checklist-user.js.map +0 -1
  571. package/dist/src/agent/goals/goal-run-store.d.ts +0 -19
  572. package/dist/src/agent/goals/goal-run-store.js +0 -138
  573. package/dist/src/agent/goals/goal-run-store.js.map +0 -1
  574. package/dist/src/agent/goals/goal-run-types.d.ts +0 -28
  575. package/dist/src/agent/goals/goal-run-types.js +0 -6
  576. package/dist/src/agent/goals/goal-run-types.js.map +0 -1
  577. package/dist/src/agent/goals/patch-from-user-action.d.ts +0 -20
  578. package/dist/src/agent/goals/patch-from-user-action.js +0 -103
  579. package/dist/src/agent/goals/patch-from-user-action.js.map +0 -1
  580. package/dist/src/cron/persistence.d.ts +0 -62
  581. package/dist/src/cron/persistence.js +0 -188
  582. package/dist/src/cron/persistence.js.map +0 -1
  583. /package/dist/gateway/static/root/assets/{note-detail-page-D4ZIVQbk.css → block-editor-D4ZIVQbk.css} +0 -0
@@ -1,224 +1,721 @@
1
- import { PERSISTENT_GOAL_CUSTOM_KEY, defaultMaxTurns, mergeCustomDataPatch, readPersistentGoal, serializePersistentGoal } from "../../../agent/goals/state.js";
2
- import { applyPersistentGoalUserAction } from "../../../agent/goals/patch-from-user-action.js";
3
- import { applyChecklistUserMutation } from "../../../agent/goals/checklist-user.js";
4
- import { mergePersistentGoalUiLocale, normalizeGoalUiLocale } from "../../../agent/goals/goal-locale.js";
5
- import { listGoalRuns } from "../../../agent/goals/goal-run-store.js";
1
+ import { buildSessionKey, init_session_key, sanitizeSegment } from "../../../routing/session-key.js";
2
+ import { getDefaultAgentId, init_resolve_route } from "../../../routing/resolve-route.js";
3
+ import { createWorkflowCatalog } from "../../../agent/workflow/catalog.js";
4
+ import { GoalService, normalizeGoalUiLocale } from "../../../goals/goal-service.js";
5
+ import "../../../goals/index.js";
6
6
  //#region src/gateway/hono/routes/goals.ts
7
- function isGoalAction(x) {
8
- return x === "pause" || x === "resume" || x === "clear" || x === "restart";
7
+ init_session_key();
8
+ init_resolve_route();
9
+ function parseLimit(raw, fallback = 50) {
10
+ if (!raw) return fallback;
11
+ const n = Number.parseInt(raw, 10);
12
+ return Number.isFinite(n) ? Math.min(500, Math.max(1, n)) : fallback;
9
13
  }
10
- /** Webchat persistent `/goal` REST API. */
14
+ function parseStatuses(raw) {
15
+ if (!raw?.trim()) return void 0;
16
+ const statuses = raw.split(",").map((s) => s.trim()).filter((s) => s === "active" || s === "paused" || s === "blocked" || s === "needs_input" || s === "done" || s === "archived");
17
+ return statuses.length ? statuses : void 0;
18
+ }
19
+ function parseBodyGoalStatus(raw) {
20
+ return raw === "active" || raw === "paused" || raw === "blocked" || raw === "needs_input" || raw === "done" || raw === "archived" ? raw : null;
21
+ }
22
+ function parsePriority(raw) {
23
+ return raw === "low" || raw === "normal" || raw === "high" ? raw : void 0;
24
+ }
25
+ const STOP_WORDS = new Set([
26
+ "a",
27
+ "an",
28
+ "and",
29
+ "are",
30
+ "as",
31
+ "for",
32
+ "in",
33
+ "is",
34
+ "of",
35
+ "on",
36
+ "or",
37
+ "the",
38
+ "to",
39
+ "with",
40
+ "一个",
41
+ "这个",
42
+ "需要",
43
+ "进行",
44
+ "推进"
45
+ ]);
46
+ function tokenizeForWorkflowMatch(text) {
47
+ return (text.toLowerCase().match(/[\p{L}\p{N}_-]+/gu) ?? []).map((token) => token.trim()).filter((token) => token.length >= 2 && !STOP_WORDS.has(token));
48
+ }
49
+ function goalSearchText(goal) {
50
+ return [
51
+ goal.title,
52
+ goal.description,
53
+ goal.nextAction,
54
+ goal.blockedReason,
55
+ ...goal.checklist.map((item) => `${item.text} ${item.evidenceSummary ?? ""}`)
56
+ ].filter(Boolean).join("\n");
57
+ }
58
+ function buildGoalWorkflowSuggestions(params) {
59
+ const goalTokens = new Set(tokenizeForWorkflowMatch(goalSearchText(params.goal)));
60
+ const runsByDefinition = /* @__PURE__ */ new Map();
61
+ for (const run of params.workflowRuns) {
62
+ const list = runsByDefinition.get(run.definitionId) ?? [];
63
+ list.push(run);
64
+ runsByDefinition.set(run.definitionId, list);
65
+ }
66
+ const suggestions = [];
67
+ for (const entry of createWorkflowCatalog().list()) {
68
+ const candidateText = [
69
+ entry.name,
70
+ entry.title,
71
+ entry.description,
72
+ entry.whenToUse,
73
+ ...entry.tags ?? []
74
+ ].filter(Boolean).join("\n");
75
+ const candidateTokens = new Set(tokenizeForWorkflowMatch(candidateText));
76
+ const matched = [...goalTokens].filter((token) => candidateTokens.has(token));
77
+ const relatedRuns = runsByDefinition.get(entry.name) ?? [];
78
+ const terminalRuns = relatedRuns.filter((run) => run.status !== "queued" && run.status !== "running");
79
+ const succeededRuns = terminalRuns.filter((run) => run.status === "succeeded");
80
+ const successRate = terminalRuns.length ? succeededRuns.length / terminalRuns.length : void 0;
81
+ const lastRun = relatedRuns.toSorted((left, right) => right.createdAtMs - left.createdAtMs)[0];
82
+ let score = matched.length * 8;
83
+ if (entry.tags?.some((tag) => goalTokens.has(tag.toLowerCase()))) score += 8;
84
+ if (entry.whenToUse && matched.length > 0) score += 4;
85
+ if (successRate != null) score += Math.round(successRate * 10);
86
+ if (lastRun?.status === "succeeded") score += 4;
87
+ if (lastRun?.status === "failed" || lastRun?.status === "timeout") score -= 3;
88
+ if (score <= 0) score = entry.source === "builtin" ? 1 : 0;
89
+ const reasons = [];
90
+ if (matched.length) reasons.push(`matches ${matched.slice(0, 4).join(", ")}`);
91
+ if (successRate != null) reasons.push(`${Math.round(successRate * 100)}% success rate`);
92
+ if (lastRun) reasons.push(`last run ${lastRun.status}`);
93
+ if (!reasons.length && entry.whenToUse) reasons.push("general workflow fit");
94
+ if (score > 0) suggestions.push({
95
+ definitionId: entry.name,
96
+ name: entry.name,
97
+ title: entry.title || entry.name,
98
+ description: entry.description,
99
+ score,
100
+ reasons,
101
+ tags: entry.tags ?? [],
102
+ successRate,
103
+ lastRunStatus: lastRun?.status
104
+ });
105
+ }
106
+ return suggestions.sort((left, right) => right.score - left.score || left.name.localeCompare(right.name)).slice(0, 5);
107
+ }
108
+ function buildGoalActivities(input) {
109
+ const activities = [];
110
+ for (const item of input.queue.filter((queueItem) => queueItem.goalId === input.goalId)) activities.push({
111
+ id: `queue:${item.id}`,
112
+ kind: "queue",
113
+ status: item.status,
114
+ title: "Goal queued",
115
+ summary: item.lastError || item.message || void 0,
116
+ createdAt: item.finishedAt ?? item.startedAt ?? item.nextRunAt ?? item.enqueuedAt,
117
+ link: item.sessionKey ? {
118
+ type: "chat",
119
+ value: item.sessionKey
120
+ } : void 0,
121
+ data: item
122
+ });
123
+ for (const run of input.runs) activities.push({
124
+ id: `goal_run:${run.id}`,
125
+ kind: "goal_run",
126
+ status: run.verdict ?? run.status,
127
+ title: "Goal run judged",
128
+ summary: run.reason || run.assistantPreview || run.nextAction,
129
+ createdAt: run.finishedAt ?? run.startedAt,
130
+ data: run
131
+ });
132
+ for (const run of input.workflowRuns) activities.push({
133
+ id: `workflow_run:${run.id}`,
134
+ kind: "workflow_run",
135
+ status: run.status,
136
+ title: run.title || run.definitionId,
137
+ summary: run.definitionId,
138
+ createdAt: run.completedAtMs ?? run.startedAtMs ?? run.createdAtMs,
139
+ link: {
140
+ type: "workflow_run",
141
+ value: run.id
142
+ },
143
+ data: run
144
+ });
145
+ for (const event of input.events) activities.push({
146
+ id: `event:${event.id}`,
147
+ kind: "event",
148
+ status: event.kind,
149
+ title: event.kind,
150
+ summary: event.message,
151
+ createdAt: event.createdAt,
152
+ data: event
153
+ });
154
+ for (const item of input.evidence) activities.push({
155
+ id: `evidence:${item.id}`,
156
+ kind: "evidence",
157
+ status: item.kind,
158
+ title: item.title,
159
+ summary: item.summary || item.uri,
160
+ createdAt: item.createdAt,
161
+ data: item
162
+ });
163
+ return activities.sort((left, right) => right.createdAt - left.createdAt).slice(0, input.limit);
164
+ }
165
+ function abortActiveWebchatRunForGoal(deps, goal) {
166
+ const sessionKey = goal.activeSessionKey?.trim();
167
+ if (!sessionKey) return {};
168
+ const runId = deps.service.getActiveWebchatRunId(sessionKey);
169
+ if (!runId) return {};
170
+ return {
171
+ abortedRunId: runId,
172
+ aborted: deps.service.abortAgentRun(runId)
173
+ };
174
+ }
175
+ /** First-class Goal API. Sessions are execution context; goals are durable product objects. */
11
176
  function registerGoalsRoutes(authenticated, deps) {
12
- const sm = deps.service.sessionIndexInstance;
177
+ const goals = new GoalService();
13
178
  const cfg = () => deps.service.currentConfig;
14
- authenticated.get("/api/goals/webchat", async (c) => {
179
+ const workflowRunService = deps.service.createWorkflowRunService();
180
+ authenticated.get("/api/goals/current", async (c) => {
15
181
  const sessionKey = c.req.query("sessionKey")?.trim();
16
182
  if (!sessionKey) return c.json({
17
183
  ok: false,
18
184
  error: "Missing sessionKey"
19
185
  }, 400);
20
- const uiLocale = normalizeGoalUiLocale(c.req.query("uiLocale"));
21
- let m = await sm.getSessionMetadata(sessionKey);
22
- if (uiLocale && m) {
23
- const merged = mergePersistentGoalUiLocale(m.customData, uiLocale);
24
- if (merged !== m.customData) {
25
- await sm.updateSessionMetadata(sessionKey, { customData: merged });
26
- m = await sm.getSessionMetadata(sessionKey);
27
- }
28
- }
29
- const goal = readPersistentGoal(m?.customData);
30
186
  return c.json({
31
187
  ok: true,
32
- sessionKey,
33
- persistentGoal: goal
188
+ goal: goals.getActiveForSession(sessionKey)
34
189
  });
35
190
  });
36
- authenticated.get("/api/goals/webchat/runs", async (c) => {
37
- const sessionKey = c.req.query("sessionKey")?.trim();
38
- if (!sessionKey) return c.json({
191
+ authenticated.get("/api/goals", async (c) => {
192
+ const status = parseStatuses(c.req.query("status"));
193
+ const agentId = c.req.query("agentId")?.trim() || void 0;
194
+ const sessionKey = c.req.query("sessionKey")?.trim() || void 0;
195
+ const limit = parseLimit(c.req.query("limit"));
196
+ const offsetRaw = c.req.query("offset")?.trim();
197
+ const offset = offsetRaw ? Math.max(0, Number.parseInt(offsetRaw, 10) || 0) : 0;
198
+ return c.json({
199
+ ok: true,
200
+ goals: goals.list({
201
+ status,
202
+ agentId,
203
+ sessionKey,
204
+ limit,
205
+ offset
206
+ })
207
+ });
208
+ });
209
+ authenticated.get("/api/goals/queue", async (c) => {
210
+ return c.json({
211
+ ok: true,
212
+ queue: deps.service.getGoalQueueSnapshot()
213
+ });
214
+ });
215
+ authenticated.post("/api/goals", async (c) => {
216
+ const body = await c.req.json().catch(() => ({}));
217
+ const title = typeof body.title === "string" ? body.title.trim() : "";
218
+ if (!title) return c.json({
39
219
  ok: false,
40
- error: "Missing sessionKey"
220
+ error: "Missing title"
41
221
  }, 400);
42
- const limitRaw = c.req.query("limit")?.trim();
43
- let limit = 50;
44
- if (limitRaw) {
45
- const n = Number.parseInt(limitRaw, 10);
46
- if (Number.isFinite(n)) limit = Math.min(500, Math.max(1, n));
47
- }
48
- const runs = await listGoalRuns(cfg(), sessionKey, { limit });
222
+ const sessionKey = typeof body.sessionKey === "string" && body.sessionKey.trim() ? body.sessionKey.trim() : void 0;
223
+ const agentId = typeof body.agentId === "string" && body.agentId.trim() ? body.agentId.trim() : sessionKey ? void 0 : getDefaultAgentId(cfg());
224
+ const maxTurns = typeof body.maxTurns === "number" && Number.isFinite(body.maxTurns) ? Math.max(1, Math.min(500, Math.floor(body.maxTurns))) : void 0;
225
+ const goal = goals.create({
226
+ title,
227
+ description: typeof body.description === "string" ? body.description : void 0,
228
+ sessionKey,
229
+ agentId,
230
+ priority: body.priority === "low" || body.priority === "high" ? body.priority : "normal",
231
+ deadlineAt: typeof body.deadlineAt === "number" && Number.isFinite(body.deadlineAt) ? body.deadlineAt : void 0,
232
+ judgeModelRef: typeof body.judgeModelRef === "string" ? body.judgeModelRef : void 0,
233
+ maxTurns,
234
+ uiLocale: normalizeGoalUiLocale(body.uiLocale),
235
+ source: body.source === "cli" || body.source === "cron" || body.source === "workflow" || body.source === "channel" || body.source === "api" ? body.source : "chat",
236
+ config: cfg()
237
+ });
238
+ if (sessionKey) deps.service.enqueueWebchatPersistentGoalKickoff(sessionKey, title);
239
+ return c.json({
240
+ ok: true,
241
+ goal: goals.get(goal.id)
242
+ });
243
+ });
244
+ authenticated.get("/api/goals/:goalId/workflow-runs", async (c) => {
245
+ const goalId = c.req.param("goalId");
246
+ const goal = goals.get(goalId);
247
+ if (!goal) return c.json({
248
+ ok: false,
249
+ error: "Goal not found"
250
+ }, 404);
251
+ const runs = await workflowRunService.createRunStore(goal.agentId || getDefaultAgentId(cfg())).listRunSummariesForGoal(goalId, parseLimit(c.req.query("limit")));
49
252
  return c.json({
50
253
  ok: true,
51
- sessionKey,
52
254
  runs
53
255
  });
54
256
  });
55
- authenticated.post("/api/goals/webchat", async (c) => {
257
+ authenticated.post("/api/goals/:goalId/workflows/run", async (c) => {
258
+ const goalId = c.req.param("goalId");
259
+ const goal = goals.get(goalId);
260
+ if (!goal) return c.json({
261
+ ok: false,
262
+ error: "Goal not found"
263
+ }, 404);
264
+ if (goal.status === "done" || goal.status === "archived") return c.json({
265
+ ok: false,
266
+ error: `Goal is ${goal.status}`
267
+ }, 409);
56
268
  const body = await c.req.json().catch(() => ({}));
57
- const sessionKey = typeof body.sessionKey === "string" ? body.sessionKey.trim() : "";
58
- if (!sessionKey) return c.json({
269
+ const definitionId = typeof body.definitionId === "string" ? body.definitionId.trim() : "";
270
+ if (!definitionId) return c.json({
59
271
  ok: false,
60
- error: "Missing sessionKey"
272
+ error: "Missing definitionId"
61
273
  }, 400);
62
- const goalsSlice = cfg().goals;
63
- const actionRaw = body.action ?? (body.clear === true ? "clear" : void 0);
64
- if (isGoalAction(actionRaw)) {
65
- const meta = await sm.getSessionMetadata(sessionKey);
66
- if (!meta) return c.json({
67
- ok: false,
68
- error: "Session not found"
69
- }, 404);
70
- const applied = applyPersistentGoalUserAction(meta.customData, actionRaw, goalsSlice);
71
- if (applied.kind === "error") return c.json({
72
- ok: false,
73
- error: applied.error
74
- }, 400);
75
- if (applied.kind === "noop") {
76
- const persistentGoal = readPersistentGoal(meta.customData);
77
- return c.json({
78
- ok: true,
79
- sessionKey,
80
- noop: true,
81
- message: applied.message,
82
- persistentGoal
83
- });
84
- }
85
- const uiLocale = normalizeGoalUiLocale(body.uiLocale);
86
- const customData = uiLocale != null ? mergePersistentGoalUiLocale(applied.customData, uiLocale) ?? applied.customData : applied.customData;
87
- await sm.updateSessionMetadata(sessionKey, { customData });
88
- const persistentGoal = readPersistentGoal((await sm.getSessionMetadata(sessionKey))?.customData);
89
- if (applied.kickoff) deps.service.enqueueWebchatPersistentGoalKickoff(sessionKey, applied.kickoff);
274
+ try {
275
+ createWorkflowCatalog().load(definitionId);
276
+ } catch {
90
277
  return c.json({
91
- ok: true,
92
- sessionKey,
93
- action: actionRaw,
94
- persistentGoal
95
- });
96
- }
97
- if (body.clear === true) {
98
- const meta = await sm.getSessionMetadata(sessionKey);
99
- if (!meta) return c.json({
100
278
  ok: false,
101
- error: "Session not found"
279
+ error: "Workflow definition not found"
102
280
  }, 404);
103
- const base = { ...meta.customData };
104
- delete base[PERSISTENT_GOAL_CUSTOM_KEY];
105
- await sm.updateSessionMetadata(sessionKey, { customData: base });
281
+ }
282
+ const result = await workflowRunService.startWorkflowRun({
283
+ agentId: goal.agentId || getDefaultAgentId(cfg()),
284
+ definitionId,
285
+ goalId,
286
+ goal: typeof body.goal === "string" && body.goal.trim() ? body.goal.trim() : goal.nextAction || goal.title,
287
+ input: body.input ?? {
288
+ goal: goal.title,
289
+ description: goal.description,
290
+ nextAction: goal.nextAction,
291
+ checklist: goal.checklist.map((item) => ({
292
+ text: item.text,
293
+ status: item.status,
294
+ evidenceSummary: item.evidenceSummary
295
+ }))
296
+ },
297
+ parentSessionKey: goal.activeSessionKey,
298
+ source: { kind: "webui" },
299
+ concurrency: typeof body.concurrency === "number" ? body.concurrency : void 0,
300
+ maxSubagents: typeof body.maxSubagents === "number" ? body.maxSubagents : void 0
301
+ });
302
+ if (result.ok === false) return c.json({
303
+ ok: false,
304
+ error: result.message,
305
+ code: result.code
306
+ }, result.httpStatus);
307
+ return c.json({
308
+ ok: true,
309
+ runId: result.runId,
310
+ sessionKey: result.sessionKey
311
+ }, 202);
312
+ });
313
+ authenticated.get("/api/goals/:goalId/activity", async (c) => {
314
+ const goalId = c.req.param("goalId");
315
+ const goal = goals.get(goalId);
316
+ if (!goal) return c.json({
317
+ ok: false,
318
+ error: "Goal not found"
319
+ }, 404);
320
+ const limit = parseLimit(c.req.query("limit"), 100);
321
+ const workflowRuns = await workflowRunService.createRunStore(goal.agentId || getDefaultAgentId(cfg())).listRunSummariesForGoal(goalId, limit);
322
+ const activities = buildGoalActivities({
323
+ goalId,
324
+ queue: deps.service.getGoalQueueSnapshot(),
325
+ runs: goals.listRuns(goalId, limit),
326
+ workflowRuns,
327
+ events: goals.listEvents(goalId, limit),
328
+ evidence: goals.listEvidence(goalId, limit),
329
+ limit
330
+ });
331
+ return c.json({
332
+ ok: true,
333
+ activities
334
+ });
335
+ });
336
+ authenticated.get("/api/goals/:goalId/workflow-suggestions", async (c) => {
337
+ const goalId = c.req.param("goalId");
338
+ const goal = goals.get(goalId);
339
+ if (!goal) return c.json({
340
+ ok: false,
341
+ error: "Goal not found"
342
+ }, 404);
343
+ const workflowRuns = await workflowRunService.createRunStore(goal.agentId || getDefaultAgentId(cfg())).listRunSummaries(500);
344
+ return c.json({
345
+ ok: true,
346
+ suggestions: buildGoalWorkflowSuggestions({
347
+ goal,
348
+ workflowRuns
349
+ })
350
+ });
351
+ });
352
+ authenticated.get("/api/goals/:goalId", async (c) => {
353
+ const goal = goals.get(c.req.param("goalId"));
354
+ if (!goal) return c.json({
355
+ ok: false,
356
+ error: "Goal not found"
357
+ }, 404);
358
+ return c.json({
359
+ ok: true,
360
+ goal
361
+ });
362
+ });
363
+ authenticated.patch("/api/goals/:goalId", async (c) => {
364
+ const goalId = c.req.param("goalId");
365
+ const body = await c.req.json().catch(() => ({}));
366
+ const status = parseBodyGoalStatus(body.status);
367
+ let goal = goals.get(goalId);
368
+ if (!goal) return c.json({
369
+ ok: false,
370
+ error: "Goal not found"
371
+ }, 404);
372
+ const patch = {};
373
+ if (typeof body.title === "string") patch.title = body.title;
374
+ if ("description" in body) patch.description = typeof body.description === "string" ? body.description : void 0;
375
+ const priority = parsePriority(body.priority);
376
+ if (priority) patch.priority = priority;
377
+ if ("deadlineAt" in body) patch.deadlineAt = typeof body.deadlineAt === "number" && Number.isFinite(body.deadlineAt) ? body.deadlineAt : void 0;
378
+ if (typeof body.maxTurns === "number" && Number.isFinite(body.maxTurns)) patch.maxTurns = body.maxTurns;
379
+ if ("judgeModelRef" in body) patch.judgeModelRef = typeof body.judgeModelRef === "string" ? body.judgeModelRef : void 0;
380
+ if ("nextAction" in body) patch.nextAction = typeof body.nextAction === "string" ? body.nextAction : void 0;
381
+ if ("blockedReason" in body) patch.blockedReason = typeof body.blockedReason === "string" ? body.blockedReason : void 0;
382
+ const locale = normalizeGoalUiLocale(body.uiLocale);
383
+ if (locale) patch.uiLocale = locale;
384
+ if (Object.keys(patch).length > 0) goal = goals.update(goalId, patch);
385
+ if (status) {
386
+ const previousStatus = goal?.status;
387
+ goal = goals.setStatus(goalId, status, { reason: typeof body.reason === "string" ? body.reason : void 0 });
388
+ const abortResult = goal && status === "archived" ? abortActiveWebchatRunForGoal(deps, goal) : {};
389
+ if (goal && previousStatus !== goal.status) deps.service.emit("goal.status.updated", {
390
+ goalId,
391
+ previousStatus,
392
+ status: goal.status,
393
+ goal
394
+ });
106
395
  return c.json({
107
396
  ok: true,
108
- sessionKey,
109
- cleared: true
397
+ goal,
398
+ ...abortResult
110
399
  });
111
400
  }
112
- const goalText = typeof body.goalText === "string" ? body.goalText.trim() : "";
113
- if (!goalText) return c.json({
401
+ return c.json({
402
+ ok: true,
403
+ goal
404
+ });
405
+ });
406
+ authenticated.post("/api/goals/:goalId/continue", async (c) => {
407
+ const goalId = c.req.param("goalId");
408
+ const body = await c.req.json().catch(() => ({}));
409
+ const goal = goals.get(goalId);
410
+ if (!goal) return c.json({
114
411
  ok: false,
115
- error: "Missing goalText (or set clear:true)"
116
- }, 400);
117
- const meta = await sm.getSessionMetadata(sessionKey);
118
- if (!meta) return c.json({
119
- ok: false,
120
- error: "Session not found"
121
- }, 404);
122
- const maxTurns = typeof body.maxTurns === "number" && Number.isFinite(body.maxTurns) ? Math.max(1, Math.min(500, Math.floor(body.maxTurns))) : defaultMaxTurns(cfg().goals);
123
- const judgeModelRef = typeof body.judgeModelRef === "string" && body.judgeModelRef.trim() ? body.judgeModelRef.trim() : typeof cfg().goals?.judgeModelRef === "string" ? cfg().goals.judgeModelRef.trim() : void 0;
124
- const uiLocale = normalizeGoalUiLocale(body.uiLocale);
125
- const next = {
126
- goal: goalText,
127
- status: "active",
128
- turnsUsed: 0,
129
- maxTurns,
130
- createdAt: Date.now(),
131
- lastTurnAt: 0,
132
- decomposed: false,
133
- consecutiveParseFailures: 0,
134
- ...judgeModelRef ? { judgeModelRef } : {},
135
- ...uiLocale ? { uiLocale } : {}
136
- };
137
- const customData = mergeCustomDataPatch({ ...meta.customData }, { [PERSISTENT_GOAL_CUSTOM_KEY]: serializePersistentGoal(next) });
138
- await sm.updateSessionMetadata(sessionKey, { customData });
139
- const persistentGoal = readPersistentGoal((await sm.getSessionMetadata(sessionKey))?.customData);
140
- deps.service.enqueueWebchatPersistentGoalKickoff(sessionKey, goalText);
412
+ error: "Goal not found"
413
+ }, 404);
414
+ let sessionKey = typeof body.sessionKey === "string" && body.sessionKey.trim() ? body.sessionKey.trim() : goal.activeSessionKey;
415
+ if (!sessionKey) {
416
+ sessionKey = buildSessionKey({
417
+ agentId: goal.agentId || getDefaultAgentId(cfg()),
418
+ source: "webchat",
419
+ accountId: "default",
420
+ peerKind: "direct",
421
+ peerId: `goal-${sanitizeSegment(goal.id) || Date.now()}`
422
+ });
423
+ await deps.service.sessionIndexInstance.saveMessages(sessionKey, []);
424
+ goals.attachSession(goalId, sessionKey);
425
+ }
426
+ const queued = deps.service.enqueueGoalRun(goalId, {
427
+ message: typeof body.message === "string" ? body.message : void 0,
428
+ maxRetries: typeof body.maxRetries === "number" && Number.isFinite(body.maxRetries) ? body.maxRetries : void 0,
429
+ source: "api"
430
+ });
431
+ const nextGoal = goals.get(goalId);
141
432
  return c.json({
142
433
  ok: true,
434
+ goal: nextGoal,
143
435
  sessionKey,
144
- persistentGoal
436
+ queued
437
+ });
438
+ });
439
+ authenticated.post("/api/goals/:goalId/enqueue", async (c) => {
440
+ const goalId = c.req.param("goalId");
441
+ const body = await c.req.json().catch(() => ({}));
442
+ if (!goals.get(goalId)) return c.json({
443
+ ok: false,
444
+ error: "Goal not found"
445
+ }, 404);
446
+ const item = deps.service.enqueueGoalRun(goalId, {
447
+ message: typeof body.message === "string" ? body.message : void 0,
448
+ maxRetries: typeof body.maxRetries === "number" && Number.isFinite(body.maxRetries) ? body.maxRetries : void 0,
449
+ source: "api"
450
+ });
451
+ return c.json({
452
+ ok: true,
453
+ item
454
+ });
455
+ });
456
+ authenticated.post("/api/goals/:goalId/pause", async (c) => {
457
+ const body = await c.req.json().catch(() => ({}));
458
+ const before = goals.get(c.req.param("goalId"));
459
+ const goal = goals.pause(c.req.param("goalId"), typeof body.reason === "string" && body.reason.trim() ? body.reason.trim() : "user-paused");
460
+ if (!goal) return c.json({
461
+ ok: false,
462
+ error: "Goal not found"
463
+ }, 404);
464
+ if (before?.status !== goal.status) deps.service.emit("goal.status.updated", {
465
+ goalId: goal.id,
466
+ previousStatus: before?.status,
467
+ status: goal.status,
468
+ goal
469
+ });
470
+ return c.json({
471
+ ok: true,
472
+ goal
473
+ });
474
+ });
475
+ authenticated.post("/api/goals/:goalId/resume", async (c) => {
476
+ const before = goals.get(c.req.param("goalId"));
477
+ const goal = goals.resume(c.req.param("goalId"));
478
+ if (!goal) return c.json({
479
+ ok: false,
480
+ error: "Goal not found"
481
+ }, 404);
482
+ if (before?.status !== goal.status) deps.service.emit("goal.status.updated", {
483
+ goalId: goal.id,
484
+ previousStatus: before?.status,
485
+ status: goal.status,
486
+ goal
487
+ });
488
+ return c.json({
489
+ ok: true,
490
+ goal
491
+ });
492
+ });
493
+ authenticated.post("/api/goals/:goalId/reopen", async (c) => {
494
+ const before = goals.get(c.req.param("goalId"));
495
+ const goal = goals.reopen(c.req.param("goalId"));
496
+ if (!goal) return c.json({
497
+ ok: false,
498
+ error: "Goal not found"
499
+ }, 404);
500
+ if (before?.status !== goal.status) deps.service.emit("goal.status.updated", {
501
+ goalId: goal.id,
502
+ previousStatus: before?.status,
503
+ status: goal.status,
504
+ goal
505
+ });
506
+ return c.json({
507
+ ok: true,
508
+ goal
509
+ });
510
+ });
511
+ authenticated.post("/api/goals/:goalId/complete", async (c) => {
512
+ const before = goals.get(c.req.param("goalId"));
513
+ const goal = goals.complete(c.req.param("goalId"));
514
+ if (!goal) return c.json({
515
+ ok: false,
516
+ error: "Goal not found"
517
+ }, 404);
518
+ if (before?.status !== goal.status) deps.service.emit("goal.status.updated", {
519
+ goalId: goal.id,
520
+ previousStatus: before?.status,
521
+ status: goal.status,
522
+ goal
523
+ });
524
+ return c.json({
525
+ ok: true,
526
+ goal
145
527
  });
146
528
  });
147
- /** Checklist CRUD for standing goals (`/subgoal` parity for webchat). */
148
- authenticated.post("/api/goals/webchat/checklist", async (c) => {
529
+ authenticated.post("/api/goals/:goalId/archive", async (c) => {
530
+ const before = goals.get(c.req.param("goalId"));
531
+ const goal = goals.archive(c.req.param("goalId"));
532
+ if (!goal) return c.json({
533
+ ok: false,
534
+ error: "Goal not found"
535
+ }, 404);
536
+ const abortResult = abortActiveWebchatRunForGoal(deps, goal);
537
+ if (before?.status !== goal.status) deps.service.emit("goal.status.updated", {
538
+ goalId: goal.id,
539
+ previousStatus: before?.status,
540
+ status: goal.status,
541
+ goal
542
+ });
543
+ return c.json({
544
+ ok: true,
545
+ goal,
546
+ ...abortResult
547
+ });
548
+ });
549
+ authenticated.post("/api/goals/:goalId/unarchive", async (c) => {
550
+ const before = goals.get(c.req.param("goalId"));
551
+ const goal = goals.unarchive(c.req.param("goalId"));
552
+ if (!goal) return c.json({
553
+ ok: false,
554
+ error: "Goal not found"
555
+ }, 404);
556
+ if (before?.status !== goal.status) deps.service.emit("goal.status.updated", {
557
+ goalId: goal.id,
558
+ previousStatus: before?.status,
559
+ status: goal.status,
560
+ goal
561
+ });
562
+ return c.json({
563
+ ok: true,
564
+ goal
565
+ });
566
+ });
567
+ authenticated.post("/api/goals/:goalId/attach", async (c) => {
568
+ const goalId = c.req.param("goalId");
149
569
  const body = await c.req.json().catch(() => ({}));
150
570
  const sessionKey = typeof body.sessionKey === "string" ? body.sessionKey.trim() : "";
151
571
  if (!sessionKey) return c.json({
152
572
  ok: false,
153
573
  error: "Missing sessionKey"
154
574
  }, 400);
155
- const op = typeof body.op === "string" ? body.op.trim().toLowerCase() : "";
156
- const meta = await sm.getSessionMetadata(sessionKey);
157
- if (!meta) return c.json({
158
- ok: false,
159
- error: "Session not found"
160
- }, 404);
161
- let mutation = null;
162
- if (op === "reset") mutation = applyChecklistUserMutation(meta.customData, { type: "reset" });
163
- else if (op === "add") {
164
- const text = typeof body.text === "string" ? body.text : "";
165
- mutation = applyChecklistUserMutation(meta.customData, {
166
- type: "add",
167
- text
168
- });
169
- } else if (op === "remove") {
170
- const index = typeof body.index === "number" && Number.isFinite(body.index) ? Math.floor(body.index) : void 0;
171
- if (index === void 0 || index < 1) return c.json({
172
- ok: false,
173
- error: "Missing or invalid index (1-based)"
174
- }, 400);
175
- mutation = applyChecklistUserMutation(meta.customData, {
176
- type: "remove",
177
- index1Based: index
178
- });
179
- } else if (op === "mark") {
180
- const index = typeof body.index === "number" && Number.isFinite(body.index) ? Math.floor(body.index) : void 0;
181
- const status = typeof body.status === "string" ? body.status.trim().toLowerCase() : "";
182
- if (index === void 0 || index < 1) return c.json({
183
- ok: false,
184
- error: "Missing or invalid index (1-based)"
185
- }, 400);
186
- if (status !== "pending" && status !== "completed" && status !== "impossible") return c.json({
187
- ok: false,
188
- error: "status must be pending, completed, or impossible"
189
- }, 400);
190
- mutation = applyChecklistUserMutation(meta.customData, {
191
- type: "mark",
192
- index1Based: index,
193
- status
194
- });
195
- } else return c.json({
575
+ const goal = goals.attachSession(goalId, sessionKey);
576
+ if (!goal) return c.json({
196
577
  ok: false,
197
- error: "Invalid op (add|remove|mark|reset)"
578
+ error: "Goal not found"
579
+ }, 404);
580
+ return c.json({
581
+ ok: true,
582
+ goal
583
+ });
584
+ });
585
+ authenticated.post("/api/goals/:goalId/detach", async (c) => {
586
+ const goal = goals.update(c.req.param("goalId"), { activeSessionKey: void 0 });
587
+ if (!goal) return c.json({
588
+ ok: false,
589
+ error: "Goal not found"
590
+ }, 404);
591
+ return c.json({
592
+ ok: true,
593
+ goal
594
+ });
595
+ });
596
+ authenticated.get("/api/goals/:goalId/runs", async (c) => {
597
+ const goalId = c.req.param("goalId");
598
+ if (!goals.get(goalId)) return c.json({
599
+ ok: false,
600
+ error: "Goal not found"
601
+ }, 404);
602
+ return c.json({
603
+ ok: true,
604
+ runs: goals.listRuns(goalId, parseLimit(c.req.query("limit")))
605
+ });
606
+ });
607
+ authenticated.get("/api/goals/:goalId/events", async (c) => {
608
+ const goalId = c.req.param("goalId");
609
+ if (!goals.get(goalId)) return c.json({
610
+ ok: false,
611
+ error: "Goal not found"
612
+ }, 404);
613
+ return c.json({
614
+ ok: true,
615
+ events: goals.listEvents(goalId, parseLimit(c.req.query("limit"), 100))
616
+ });
617
+ });
618
+ authenticated.get("/api/goals/:goalId/evidence", async (c) => {
619
+ const goalId = c.req.param("goalId");
620
+ if (!goals.get(goalId)) return c.json({
621
+ ok: false,
622
+ error: "Goal not found"
623
+ }, 404);
624
+ return c.json({
625
+ ok: true,
626
+ evidence: goals.listEvidence(goalId, parseLimit(c.req.query("limit"), 100))
627
+ });
628
+ });
629
+ authenticated.post("/api/goals/:goalId/evidence", async (c) => {
630
+ const goalId = c.req.param("goalId");
631
+ if (!goals.get(goalId)) return c.json({
632
+ ok: false,
633
+ error: "Goal not found"
634
+ }, 404);
635
+ const body = await c.req.json().catch(() => ({}));
636
+ const title = typeof body.title === "string" ? body.title.trim() : "";
637
+ const kind = body.kind;
638
+ if (!title) return c.json({
639
+ ok: false,
640
+ error: "Missing title"
198
641
  }, 400);
199
- if (mutation.kind === "error") return c.json({
642
+ if (kind !== "file" && kind !== "diff" && kind !== "command" && kind !== "test" && kind !== "link" && kind !== "message" && kind !== "artifact") return c.json({
200
643
  ok: false,
201
- error: mutation.error
644
+ error: "Invalid evidence kind"
202
645
  }, 400);
203
- if (mutation.kind === "noop") {
204
- const persistentGoal = readPersistentGoal(meta.customData);
205
- return c.json({
206
- ok: true,
207
- sessionKey,
208
- noop: true,
209
- message: mutation.message,
210
- persistentGoal
211
- });
212
- }
213
- const uiLocale = normalizeGoalUiLocale(body.uiLocale);
214
- const customData = uiLocale != null ? mergePersistentGoalUiLocale(mutation.customData, uiLocale) ?? mutation.customData : mutation.customData;
215
- await sm.updateSessionMetadata(sessionKey, { customData });
216
- const persistentGoal = readPersistentGoal((await sm.getSessionMetadata(sessionKey))?.customData);
646
+ const evidence = goals.addEvidence({
647
+ goalId,
648
+ runId: typeof body.runId === "string" ? body.runId : void 0,
649
+ kind,
650
+ title,
651
+ summary: typeof body.summary === "string" ? body.summary : void 0,
652
+ uri: typeof body.uri === "string" ? body.uri : void 0,
653
+ data: body.data
654
+ });
217
655
  return c.json({
218
656
  ok: true,
219
- sessionKey,
220
- op,
221
- persistentGoal
657
+ evidence
658
+ });
659
+ });
660
+ authenticated.post("/api/goals/:goalId/checklist", async (c) => {
661
+ const goalId = c.req.param("goalId");
662
+ if (!goals.get(goalId)) return c.json({
663
+ ok: false,
664
+ error: "Goal not found"
665
+ }, 404);
666
+ const body = await c.req.json().catch(() => ({}));
667
+ const text = typeof body.text === "string" ? body.text.trim() : "";
668
+ if (!text) return c.json({
669
+ ok: false,
670
+ error: "Missing text"
671
+ }, 400);
672
+ const goal = goals.updateChecklist(goalId, {
673
+ type: "add",
674
+ text,
675
+ addedBy: "user"
676
+ });
677
+ return c.json({
678
+ ok: true,
679
+ goal
680
+ });
681
+ });
682
+ authenticated.patch("/api/goals/:goalId/checklist/:itemId", async (c) => {
683
+ const goalId = c.req.param("goalId");
684
+ const itemId = c.req.param("itemId");
685
+ if (!goals.get(goalId)) return c.json({
686
+ ok: false,
687
+ error: "Goal not found"
688
+ }, 404);
689
+ const body = await c.req.json().catch(() => ({}));
690
+ const status = body.status;
691
+ if (status !== "pending" && status !== "completed" && status !== "impossible") return c.json({
692
+ ok: false,
693
+ error: "Invalid checklist status"
694
+ }, 400);
695
+ const goal = goals.updateChecklist(goalId, {
696
+ type: "mark",
697
+ itemId,
698
+ status,
699
+ evidenceSummary: typeof body.evidenceSummary === "string" ? body.evidenceSummary : void 0
700
+ });
701
+ return c.json({
702
+ ok: true,
703
+ goal
704
+ });
705
+ });
706
+ authenticated.delete("/api/goals/:goalId/checklist/:itemId", async (c) => {
707
+ const goalId = c.req.param("goalId");
708
+ if (!goals.get(goalId)) return c.json({
709
+ ok: false,
710
+ error: "Goal not found"
711
+ }, 404);
712
+ const goal = goals.updateChecklist(goalId, {
713
+ type: "remove",
714
+ itemId: c.req.param("itemId")
715
+ });
716
+ return c.json({
717
+ ok: true,
718
+ goal
222
719
  });
223
720
  });
224
721
  }