@xopcai/xopc 0.0.117 → 0.0.119

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 (590) hide show
  1. package/README.md +26 -24
  2. package/README.zh-CN.md +46 -42
  3. package/dist/browser-ext/manifest.json +1 -1
  4. package/dist/extensions/telegram/xopc.extension.json +1 -1
  5. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BBLhJ2C6.js → agent-avatar-dicebear-CU8J6zou.js} +1 -1
  6. package/dist/gateway/static/root/assets/agents-B0hkpLhP.js +2 -0
  7. package/dist/gateway/static/root/assets/app-management-settings-panel-B9vfYoEr.js +1 -0
  8. package/dist/gateway/static/root/assets/appearance-settings-ClOzIO24.js +1 -0
  9. package/dist/gateway/static/root/assets/{apps-page-DdDx0V4z.js → apps-page-DU0dz9Zo.js} +1 -1
  10. package/dist/gateway/static/root/assets/{archive-plugin-DZsVqMhU.js → archive-plugin-BkVIgZzA.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-CIol6JWX.js → attachment-load-CaCMWh1D.js} +1 -1
  12. package/dist/gateway/static/root/assets/automation-suggestion-card-DhGDpKP3.js +1 -0
  13. package/dist/gateway/static/root/assets/automations-page-CTedroVo.js +1 -0
  14. package/dist/gateway/static/root/assets/{binary-plugins-B3UauMfp.js → binary-plugins-B4TO_bsn.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-2HJoFchH.js → block-editor-DJRWwWNI.js} +6 -6
  16. package/dist/gateway/static/root/assets/browser-settings-page-FCDwOOBK.js +8 -0
  17. package/dist/gateway/static/root/assets/capability-presets-api-Befi89CL.js +1 -0
  18. package/dist/gateway/static/root/assets/capability-presets-settings-panel-_G8eb2vJ.js +1 -0
  19. package/dist/gateway/static/root/assets/channel-recipient-api-BNSuJb5f.js +1 -0
  20. package/dist/gateway/static/root/assets/channels-settings-C3d5JBJX.js +1 -0
  21. package/dist/gateway/static/root/assets/cn-BQ_8x0bT.js +1 -0
  22. package/dist/gateway/static/root/assets/connectors-page-yaUNvt5u.js +2 -0
  23. package/dist/gateway/static/root/assets/cron-expression-B3B1eqnr.js +2 -0
  24. package/dist/gateway/static/root/assets/dreaming-settings-DNrdg1Ve.js +1 -0
  25. package/dist/gateway/static/root/assets/{extension-debug-page-DX5WRE_t.js → extension-debug-page-DYh402XV.js} +1 -1
  26. package/dist/gateway/static/root/assets/{extension-page-Buah7Bw-.js → extension-page-Cr_TizrN.js} +1 -1
  27. package/dist/gateway/static/root/assets/{extension-settings-page-DuroLVnf.js → extension-settings-page-BU1KoKRj.js} +1 -1
  28. package/dist/gateway/static/root/assets/{fetch-B5zdl27C.js → fetch-Y7AEX4H3.js} +1 -1
  29. package/dist/gateway/static/root/assets/format-cron-label-arqgGlVV.js +1 -0
  30. package/dist/gateway/static/root/assets/{gateway-config-api-gT4ZhE7h.js → gateway-config-api-RbMmAOpX.js} +1 -1
  31. package/dist/gateway/static/root/assets/gateway-settings-C79wkXef.js +1 -0
  32. package/dist/gateway/static/root/assets/{gateway-startup-retry-B3kL8KGY.js → gateway-startup-retry-DiD_Tx4N.js} +1 -1
  33. package/dist/gateway/static/root/assets/goal-detail-page-9paXuHdo.js +1 -0
  34. package/dist/gateway/static/root/assets/{goals-config-api-AR-fVh0P.js → goals-config-api-DqxVi0p5.js} +1 -1
  35. package/dist/gateway/static/root/assets/{goals-page-Cpb21ezg.js → goals-page-CS0R-Af2.js} +2 -2
  36. package/dist/gateway/static/root/assets/goals-settings-CSuzZ8Ae.js +1 -0
  37. package/dist/gateway/static/root/assets/heartbeat-settings-DXPaYJm3.js +1 -0
  38. package/dist/gateway/static/root/assets/index-BoKafJIZ.js +191 -0
  39. package/dist/gateway/static/root/assets/index-CArhCcYn.css +1 -0
  40. package/dist/gateway/static/root/assets/keyboard-shortcuts-settings-Dvg53qnd.js +1 -0
  41. package/dist/gateway/static/root/assets/{logs-page-DefCgF4o.js → logs-page-DLXPcksQ.js} +2 -2
  42. package/dist/gateway/static/root/assets/{markdown-split-ChbR9LGO.js → markdown-split-CpHxbtWJ.js} +1 -1
  43. package/dist/gateway/static/root/assets/{media-plugins-B82oP80n.js → media-plugins-SFPQRSxq.js} +1 -1
  44. package/dist/gateway/static/root/assets/messages-CrDHEbss.js +3 -0
  45. package/dist/gateway/static/root/assets/models-hub-panel-BDF2iyRk.js +2 -0
  46. package/dist/gateway/static/root/assets/note-detail-page-CSb_hwig.js +2 -0
  47. package/dist/gateway/static/root/assets/{note-image-lightbox-CDknITM3.js → note-image-lightbox-BUYURRgn.js} +1 -1
  48. package/dist/gateway/static/root/assets/notes-page-BsIBSFyZ.js +1 -0
  49. package/dist/gateway/static/root/assets/{preview-open-alternatives-DV3xQsWB.js → preview-open-alternatives-BHz9iWYA.js} +1 -1
  50. package/dist/gateway/static/root/assets/remote-access-hub-CwzSovcS.js +1 -0
  51. package/dist/gateway/static/root/assets/{save-bar-controls-BODCXnvY.js → save-bar-controls-CefkOlRg.js} +1 -1
  52. package/dist/gateway/static/root/assets/schedule-field-CmTRoOcE.js +1 -0
  53. package/dist/gateway/static/root/assets/{schema-form-qtfEI6QM.js → schema-form-FMKv1vGu.js} +1 -1
  54. package/dist/gateway/static/root/assets/sessions-page-PHmX-NmA.js +1 -0
  55. package/dist/gateway/static/root/assets/settings-advanced-gate-BRAeKJN4.js +1 -0
  56. package/dist/gateway/static/root/assets/{settings-collapsible-section-BHZKjVcS.js → settings-collapsible-section-BouO6JTi.js} +1 -1
  57. package/dist/gateway/static/root/assets/{settings-form-section-5i35D-J1.js → settings-form-section-D-4lBl6X.js} +1 -1
  58. package/dist/gateway/static/root/assets/settings-page-KKrbFjy8.js +1 -0
  59. package/dist/gateway/static/root/assets/settings-page-layout-BJ4Gsef5.js +1 -0
  60. package/dist/gateway/static/root/assets/setup-status-panel-CrUjHPQo.js +1 -0
  61. package/dist/gateway/static/root/assets/{share-preview-page-B0H63tDv.js → share-preview-page-BDy2btRN.js} +1 -1
  62. package/dist/gateway/static/root/assets/shares-settings-B18OBmH5.js +1 -0
  63. package/dist/gateway/static/root/assets/skill-reload-api-C28-2uKQ.js +1 -0
  64. package/dist/gateway/static/root/assets/skills-page-Bm2ebkwl.js +2 -0
  65. package/dist/gateway/static/root/assets/system-settings-panel-CRngrlnZ.js +1 -0
  66. package/dist/gateway/static/root/assets/typed-models-lib-BltBc0b-.js +1 -0
  67. package/dist/gateway/static/root/assets/{use-channel-catalog-BCjP_VHb.js → use-channel-catalog-CjN-51e6.js} +1 -1
  68. package/dist/gateway/static/root/assets/user-profile-settings-panel-DJ1dKwZy.js +1 -0
  69. package/dist/gateway/static/root/assets/utils-B5M5-YvK.js +1 -0
  70. package/dist/gateway/static/root/assets/voice-api-key-field-CeEevm7z.js +1 -0
  71. package/dist/gateway/static/root/assets/{voice-player-store-BlF9V05n.js → voice-player-store-B7ykUlHM.js} +1 -1
  72. package/dist/gateway/static/root/assets/workflow-run-setup-panel-C4PzUQjB.js +3 -0
  73. package/dist/gateway/static/root/assets/workflows-page-BL84_-Ky.js +18 -0
  74. package/dist/gateway/static/root/index.html +6 -7
  75. package/dist/package.js +1 -1
  76. package/dist/src/agent/agent-manager.d.ts +4 -5
  77. package/dist/src/agent/agent-manager.js +6 -9
  78. package/dist/src/agent/agent-manager.js.map +1 -1
  79. package/dist/src/agent/agent-scope.js +0 -2
  80. package/dist/src/agent/agent-scope.js.map +1 -1
  81. package/dist/src/agent/background-review/prompts.d.ts +2 -2
  82. package/dist/src/agent/background-review/prompts.js +2 -2
  83. package/dist/src/agent/background-review/prompts.js.map +1 -1
  84. package/dist/src/agent/background-review/settings.d.ts +1 -1
  85. package/dist/src/agent/background-review/settings.js +7 -8
  86. package/dist/src/agent/background-review/settings.js.map +1 -1
  87. package/dist/src/agent/bootstrap/bootstrap-cache.d.ts +1 -0
  88. package/dist/src/agent/bootstrap/bootstrap-cache.js +4 -3
  89. package/dist/src/agent/bootstrap/bootstrap-cache.js.map +1 -1
  90. package/dist/src/agent/bootstrap/bootstrap-files.d.ts +4 -0
  91. package/dist/src/agent/bootstrap/bootstrap-files.js +4 -3
  92. package/dist/src/agent/bootstrap/bootstrap-files.js.map +1 -1
  93. package/dist/src/agent/bootstrap/filter-bootstrap-files.js +4 -2
  94. package/dist/src/agent/bootstrap/filter-bootstrap-files.js.map +1 -1
  95. package/dist/src/agent/bootstrap/load-bootstrap-files.d.ts +2 -1
  96. package/dist/src/agent/bootstrap/load-bootstrap-files.js +17 -16
  97. package/dist/src/agent/bootstrap/load-bootstrap-files.js.map +1 -1
  98. package/dist/src/agent/bootstrap/types.d.ts +1 -1
  99. package/dist/src/agent/context/workspace-templates/AGENTS.md +1 -1
  100. package/dist/src/agent/context/workspace.d.ts +4 -2
  101. package/dist/src/agent/context/workspace.js +5 -4
  102. package/dist/src/agent/context/workspace.js.map +1 -1
  103. package/dist/src/agent/embedded/run-for-session.js +106 -15
  104. package/dist/src/agent/embedded/run-for-session.js.map +1 -1
  105. package/dist/src/agent/fallback/candidates.d.ts +0 -8
  106. package/dist/src/agent/fallback/candidates.js +10 -11
  107. package/dist/src/agent/fallback/candidates.js.map +1 -1
  108. package/dist/src/agent/index.js +1 -1
  109. package/dist/src/agent/lifecycle/handlers/compaction.d.ts +1 -3
  110. package/dist/src/agent/lifecycle/handlers/compaction.js +1 -16
  111. package/dist/src/agent/lifecycle/handlers/compaction.js.map +1 -1
  112. package/dist/src/agent/lifecycle/progress.d.ts +0 -1
  113. package/dist/src/agent/lifecycle/progress.js +1 -6
  114. package/dist/src/agent/lifecycle/progress.js.map +1 -1
  115. package/dist/src/agent/lifecycle/timeout-wrapper.d.ts +1 -2
  116. package/dist/src/agent/lifecycle/timeout-wrapper.js +1 -7
  117. package/dist/src/agent/lifecycle/timeout-wrapper.js.map +1 -1
  118. package/dist/src/agent/memory/builtin-memory-store.d.ts +4 -2
  119. package/dist/src/agent/memory/builtin-memory-store.js +11 -6
  120. package/dist/src/agent/memory/builtin-memory-store.js.map +1 -1
  121. package/dist/src/agent/memory/builtin-provider.js +36 -7
  122. package/dist/src/agent/memory/builtin-provider.js.map +1 -1
  123. package/dist/src/agent/memory/candidate-extractor.d.ts +6 -0
  124. package/dist/src/agent/memory/candidate-extractor.js +60 -0
  125. package/dist/src/agent/memory/candidate-extractor.js.map +1 -0
  126. package/dist/src/agent/memory/manager.d.ts +2 -1
  127. package/dist/src/agent/memory/manager.js +27 -3
  128. package/dist/src/agent/memory/manager.js.map +1 -1
  129. package/dist/src/agent/memory/memory-config.js +3 -0
  130. package/dist/src/agent/memory/memory-config.js.map +1 -1
  131. package/dist/src/agent/memory/prefetch-coordinator.js.map +1 -1
  132. package/dist/src/agent/memory/types.d.ts +27 -4
  133. package/dist/src/agent/middleware/self-verify.d.ts +0 -1
  134. package/dist/src/agent/middleware/self-verify.js +0 -2
  135. package/dist/src/agent/middleware/self-verify.js.map +1 -1
  136. package/dist/src/agent/models/index.d.ts +1 -1
  137. package/dist/src/agent/models/manager.d.ts +4 -20
  138. package/dist/src/agent/models/manager.js +9 -126
  139. package/dist/src/agent/models/manager.js.map +1 -1
  140. package/dist/src/agent/orchestration/agent-orchestrator.d.ts +0 -4
  141. package/dist/src/agent/orchestration/agent-orchestrator.js +1 -9
  142. package/dist/src/agent/orchestration/agent-orchestrator.js.map +1 -1
  143. package/dist/src/agent/prompt/memory/index.d.ts +4 -2
  144. package/dist/src/agent/prompt/memory/index.js +18 -12
  145. package/dist/src/agent/prompt/memory/index.js.map +1 -1
  146. package/dist/src/agent/prompt/sections/memory-skills.js +1 -1
  147. package/dist/src/agent/prompt/sections/memory-skills.js.map +1 -1
  148. package/dist/src/agent/prompt/sections/tooling.js +2 -2
  149. package/dist/src/agent/prompt/sections/tooling.js.map +1 -1
  150. package/dist/src/agent/prompt/service-prompt-builder.d.ts +0 -1
  151. package/dist/src/agent/prompt/service-prompt-builder.js +4 -31
  152. package/dist/src/agent/prompt/service-prompt-builder.js.map +1 -1
  153. package/dist/src/agent/prompt/subagent-context.js +1 -1
  154. package/dist/src/agent/prompt/subagent-context.js.map +1 -1
  155. package/dist/src/agent/prompt/types.d.ts +1 -1
  156. package/dist/src/agent/reply/post-compaction-context.js +1 -3
  157. package/dist/src/agent/reply/post-compaction-context.js.map +1 -1
  158. package/dist/src/agent/reply/startup-context.js +1 -5
  159. package/dist/src/agent/reply/startup-context.js.map +1 -1
  160. package/dist/src/agent/service.d.ts +4 -12
  161. package/dist/src/agent/service.js +10 -48
  162. package/dist/src/agent/service.js.map +1 -1
  163. package/dist/src/agent/service.types.d.ts +2 -2
  164. package/dist/src/agent/session/session-config-service.d.ts +11 -11
  165. package/dist/src/agent/session/session-config-service.js +14 -14
  166. package/dist/src/agent/session/session-config-service.js.map +1 -1
  167. package/dist/src/agent/session/session-inspector.js +3 -2
  168. package/dist/src/agent/session/session-inspector.js.map +1 -1
  169. package/dist/src/agent/starter-agents.js +12 -12
  170. package/dist/src/agent/starter-agents.js.map +1 -1
  171. package/dist/src/agent/tools/automation-tool.d.ts +14 -0
  172. package/dist/src/agent/tools/automation-tool.js +102 -0
  173. package/dist/src/agent/tools/automation-tool.js.map +1 -0
  174. package/dist/src/agent/tools/curated-memory-tool.js +57 -2
  175. package/dist/src/agent/tools/curated-memory-tool.js.map +1 -1
  176. package/dist/src/agent/tools/delegate-tool.js +1 -1
  177. package/dist/src/agent/tools/delegate-tool.js.map +1 -1
  178. package/dist/src/agent/tools/factory.d.ts +3 -3
  179. package/dist/src/agent/tools/factory.js +2 -2
  180. package/dist/src/agent/tools/factory.js.map +1 -1
  181. package/dist/src/agent/tools/index.d.ts +1 -1
  182. package/dist/src/agent/tools/index.js +2 -2
  183. package/dist/src/agent/tools/web-extract.js +6 -8
  184. package/dist/src/agent/tools/web-extract.js.map +1 -1
  185. package/dist/src/agent-manifest/index.js +2 -2
  186. package/dist/src/agent-manifest/resolver.d.ts +4 -2
  187. package/dist/src/agent-manifest/resolver.js +6 -3
  188. package/dist/src/agent-manifest/resolver.js.map +1 -1
  189. package/dist/src/agent-manifest/schema.d.ts +238 -0
  190. package/dist/src/agent-manifest/schema.js +16 -5
  191. package/dist/src/agent-manifest/schema.js.map +1 -1
  192. package/dist/src/agent-manifest/validator.d.ts +3 -2
  193. package/dist/src/agent-manifest/validator.js +2 -1
  194. package/dist/src/agent-manifest/validator.js.map +1 -1
  195. package/dist/src/ai-assist/text-assist.d.ts +1 -1
  196. package/dist/src/ai-assist/text-assist.js +56 -0
  197. package/dist/src/ai-assist/text-assist.js.map +1 -1
  198. package/dist/src/auth/profiles/store.js.map +1 -1
  199. package/dist/src/automations/api/routes.d.ts +3 -0
  200. package/dist/src/automations/api/routes.js +193 -0
  201. package/dist/src/automations/api/routes.js.map +1 -0
  202. package/dist/src/automations/domain/index.d.ts +3 -0
  203. package/dist/src/automations/domain/index.js +3 -0
  204. package/dist/src/automations/domain/schedule.d.ts +4 -0
  205. package/dist/src/automations/domain/schedule.js +37 -0
  206. package/dist/src/automations/domain/schedule.js.map +1 -0
  207. package/dist/src/automations/domain/types.d.ts +160 -0
  208. package/dist/src/automations/domain/validation.d.ts +370 -0
  209. package/dist/src/automations/domain/validation.js +149 -0
  210. package/dist/src/automations/domain/validation.js.map +1 -0
  211. package/dist/src/automations/draft/automation-draft-prompt.d.ts +26 -0
  212. package/dist/src/automations/draft/automation-draft-prompt.js +127 -0
  213. package/dist/src/automations/draft/automation-draft-prompt.js.map +1 -0
  214. package/dist/src/automations/draft/automation-draft-service.d.ts +12 -0
  215. package/dist/src/automations/draft/automation-draft-service.js +135 -0
  216. package/dist/src/automations/draft/automation-draft-service.js.map +1 -0
  217. package/dist/src/automations/draft/automation-draft-validator.d.ts +99 -0
  218. package/dist/src/automations/draft/automation-draft-validator.js +105 -0
  219. package/dist/src/automations/draft/automation-draft-validator.js.map +1 -0
  220. package/dist/src/automations/draft/automation-draft.types.d.ts +40 -0
  221. package/dist/src/automations/draft/index.d.ts +3 -0
  222. package/dist/src/automations/draft/index.js +3 -0
  223. package/dist/src/automations/index.d.ts +3 -0
  224. package/dist/src/automations/index.js +8 -0
  225. package/dist/src/automations/product-events.d.ts +5 -0
  226. package/dist/src/automations/product-events.js +21 -0
  227. package/dist/src/automations/product-events.js.map +1 -0
  228. package/dist/src/automations/service/action-executor.d.ts +9 -0
  229. package/dist/src/automations/service/action-executor.js +157 -0
  230. package/dist/src/automations/service/action-executor.js.map +1 -0
  231. package/dist/src/automations/service/automation-service.d.ts +54 -0
  232. package/dist/src/automations/service/automation-service.js +404 -0
  233. package/dist/src/automations/service/automation-service.js.map +1 -0
  234. package/dist/src/automations/service/index.d.ts +2 -0
  235. package/dist/src/automations/service/index.js +3 -0
  236. package/dist/src/automations/storage/automation-repository.d.ts +6 -0
  237. package/dist/src/automations/storage/automation-repository.js +61 -0
  238. package/dist/src/automations/storage/automation-repository.js.map +1 -0
  239. package/dist/src/automations/storage/automation-run-repository.d.ts +17 -0
  240. package/dist/src/automations/storage/automation-run-repository.js +130 -0
  241. package/dist/src/automations/storage/automation-run-repository.js.map +1 -0
  242. package/dist/src/automations/storage/index.d.ts +2 -0
  243. package/dist/src/automations/storage/index.js +3 -0
  244. package/dist/src/channels/pipeline.d.ts +1 -1
  245. package/dist/src/channels/pipeline.js.map +1 -1
  246. package/dist/src/channels/plugin-types.d.ts +3 -0
  247. package/dist/src/chat-commands/agent-edit.js +0 -1
  248. package/dist/src/chat-commands/agent-edit.js.map +1 -1
  249. package/dist/src/chat-commands/builtins/model.js +2 -2
  250. package/dist/src/chat-commands/builtins/model.js.map +1 -1
  251. package/dist/src/chat-commands/builtins/thinking.js.map +1 -1
  252. package/dist/src/cli/command-catalog.js +0 -39
  253. package/dist/src/cli/command-catalog.js.map +1 -1
  254. package/dist/src/cli/command-loaders.js +0 -1
  255. package/dist/src/cli/command-loaders.js.map +1 -1
  256. package/dist/src/cli/command-manifest.d.ts +1 -1
  257. package/dist/src/cli/command-manifest.js +1 -5
  258. package/dist/src/cli/command-manifest.js.map +1 -1
  259. package/dist/src/cli/commands/agents.js +7 -6
  260. package/dist/src/cli/commands/agents.js.map +1 -1
  261. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  262. package/dist/src/cli/commands/doctor/checks/{cron-health.d.ts → migrations.d.ts} +1 -1
  263. package/dist/src/cli/commands/doctor/checks/migrations.js +40 -0
  264. package/dist/src/cli/commands/doctor/checks/migrations.js.map +1 -0
  265. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -0
  266. package/dist/src/cli/commands/doctor/checks/provider-auth.js.map +1 -1
  267. package/dist/src/cli/commands/doctor/checks/workspace-status.js +0 -1
  268. package/dist/src/cli/commands/doctor/checks/workspace-status.js.map +1 -1
  269. package/dist/src/cli/commands/doctor/flow.js +2 -2
  270. package/dist/src/cli/commands/doctor/flow.js.map +1 -1
  271. package/dist/src/cli/commands/gateway/call.js +2 -2
  272. package/dist/src/cli/commands/gateway/call.js.map +1 -1
  273. package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
  274. package/dist/src/cli/commands/gateway/run-foreground.js +4 -2
  275. package/dist/src/cli/commands/gateway/run-foreground.js.map +1 -1
  276. package/dist/src/cli/commands/init.js +33 -14
  277. package/dist/src/cli/commands/init.js.map +1 -1
  278. package/dist/src/cli/commands/models.js +13 -31
  279. package/dist/src/cli/commands/models.js.map +1 -1
  280. package/dist/src/cli/commands/onboard/model.js +17 -10
  281. package/dist/src/cli/commands/onboard/model.js.map +1 -1
  282. package/dist/src/cli/commands/onboard.js +2 -2
  283. package/dist/src/cli/commands/onboard.js.map +1 -1
  284. package/dist/src/cli/commands/tui.js +26 -4
  285. package/dist/src/cli/commands/tui.js.map +1 -1
  286. package/dist/src/cli/index.d.ts +1 -0
  287. package/dist/src/cli/index.js +10 -5
  288. package/dist/src/cli/index.js.map +1 -1
  289. package/dist/src/cli/registry.js +1 -1
  290. package/dist/src/cli/registry.js.map +1 -1
  291. package/dist/src/cli/templates.d.ts +1 -1
  292. package/dist/src/cli/templates.js +1 -11
  293. package/dist/src/cli/templates.js.map +1 -1
  294. package/dist/src/cli/utils/init-workspace-core.js +2 -0
  295. package/dist/src/cli/utils/init-workspace-core.js.map +1 -1
  296. package/dist/src/commands/agents.config.d.ts +9 -0
  297. package/dist/src/commands/agents.config.js +42 -12
  298. package/dist/src/commands/agents.config.js.map +1 -1
  299. package/dist/src/config/agent-profile.js +5 -3
  300. package/dist/src/config/agent-profile.js.map +1 -1
  301. package/dist/src/config/agent-typed-models.js +3 -5
  302. package/dist/src/config/agent-typed-models.js.map +1 -1
  303. package/dist/src/config/config-surface.d.ts +3 -0
  304. package/dist/src/config/index.d.ts +0 -1
  305. package/dist/src/config/index.js +3 -3
  306. package/dist/src/config/index.js.map +1 -1
  307. package/dist/src/config/paths.d.ts +8 -10
  308. package/dist/src/config/paths.js +16 -16
  309. package/dist/src/config/paths.js.map +1 -1
  310. package/dist/src/config/profile.js +0 -1
  311. package/dist/src/config/profile.js.map +1 -1
  312. package/dist/src/config/rules.js +0 -5
  313. package/dist/src/config/rules.js.map +1 -1
  314. package/dist/src/config/schema.d.ts +45 -44
  315. package/dist/src/config/schema.js +68 -52
  316. package/dist/src/config/schema.js.map +1 -1
  317. package/dist/src/config/web-patch.d.ts +0 -12
  318. package/dist/src/config/web-patch.js +2 -29
  319. package/dist/src/config/web-patch.js.map +1 -1
  320. package/dist/src/extensions/api.d.ts +2 -0
  321. package/dist/src/extensions/api.js +10 -0
  322. package/dist/src/extensions/api.js.map +1 -1
  323. package/dist/src/extensions/extension-registry-impl.d.ts +4 -1
  324. package/dist/src/extensions/extension-registry-impl.js +8 -0
  325. package/dist/src/extensions/extension-registry-impl.js.map +1 -1
  326. package/dist/src/extensions/loader.d.ts +3 -3
  327. package/dist/src/extensions/loader.js +3 -3
  328. package/dist/src/extensions/loader.js.map +1 -1
  329. package/dist/src/extensions/sdk/testing.d.ts +2 -0
  330. package/dist/src/extensions/sdk/testing.js +7 -0
  331. package/dist/src/extensions/sdk/testing.js.map +1 -1
  332. package/dist/src/extensions/types/core.d.ts +10 -1
  333. package/dist/src/extensions/types/index.d.ts +1 -1
  334. package/dist/src/extensions/types/{phase4.d.ts → registration.d.ts} +2 -2
  335. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  336. package/dist/src/gateway/agent-builtin-tools.js +1 -1
  337. package/dist/src/gateway/agent-builtin-tools.js.map +1 -1
  338. package/dist/src/gateway/agents-admin.d.ts +8 -0
  339. package/dist/src/gateway/agents-admin.js +63 -34
  340. package/dist/src/gateway/agents-admin.js.map +1 -1
  341. package/dist/src/gateway/capability-presets-admin.d.ts +1 -0
  342. package/dist/src/gateway/capability-presets-admin.js +19 -10
  343. package/dist/src/gateway/capability-presets-admin.js.map +1 -1
  344. package/dist/src/gateway/chat-stream/mapper.js +9 -2
  345. package/dist/src/gateway/chat-stream/mapper.js.map +1 -1
  346. package/dist/src/gateway/dreaming-automation-reconciler.d.ts +11 -0
  347. package/dist/src/gateway/dreaming-automation-reconciler.js +105 -0
  348. package/dist/src/gateway/dreaming-automation-reconciler.js.map +1 -0
  349. package/dist/src/gateway/global-defaults-admin.d.ts +36 -0
  350. package/dist/src/gateway/global-defaults-admin.js +146 -0
  351. package/dist/src/gateway/global-defaults-admin.js.map +1 -0
  352. package/dist/src/gateway/heartbeat/service.d.ts +0 -2
  353. package/dist/src/gateway/heartbeat/service.js +0 -7
  354. package/dist/src/gateway/heartbeat/service.js.map +1 -1
  355. package/dist/src/gateway/hono/lib/config-payload.d.ts +5 -6
  356. package/dist/src/gateway/hono/lib/config-payload.js +2 -2
  357. package/dist/src/gateway/hono/lib/config-payload.js.map +1 -1
  358. package/dist/src/gateway/hono/routes/agents.js +33 -1
  359. package/dist/src/gateway/hono/routes/agents.js.map +1 -1
  360. package/dist/src/gateway/hono/routes/commands-skills.js +4 -5
  361. package/dist/src/gateway/hono/routes/commands-skills.js.map +1 -1
  362. package/dist/src/gateway/hono/routes/config-patch/misc.d.ts +1 -1
  363. package/dist/src/gateway/hono/routes/config-patch/misc.js +12 -6
  364. package/dist/src/gateway/hono/routes/config-patch/misc.js.map +1 -1
  365. package/dist/src/gateway/hono/routes/dreaming.js +27 -37
  366. package/dist/src/gateway/hono/routes/dreaming.js.map +1 -1
  367. package/dist/src/gateway/hono/routes/global-defaults.d.ts +3 -0
  368. package/dist/src/gateway/hono/routes/global-defaults.js +61 -0
  369. package/dist/src/gateway/hono/routes/global-defaults.js.map +1 -0
  370. package/dist/src/gateway/hono/routes/home.d.ts +2 -2
  371. package/dist/src/gateway/hono/routes/home.js +34 -25
  372. package/dist/src/gateway/hono/routes/home.js.map +1 -1
  373. package/dist/src/gateway/hono/routes/lazy-bundles.js +21 -9
  374. package/dist/src/gateway/hono/routes/lazy-bundles.js.map +1 -1
  375. package/dist/src/gateway/hono/routes/memory.js +75 -4
  376. package/dist/src/gateway/hono/routes/memory.js.map +1 -1
  377. package/dist/src/gateway/hono/routes/migrations.d.ts +3 -0
  378. package/dist/src/gateway/hono/routes/migrations.js +35 -0
  379. package/dist/src/gateway/hono/routes/migrations.js.map +1 -0
  380. package/dist/src/gateway/hono/routes/models.js +1 -1
  381. package/dist/src/gateway/hono/routes/public-gateway.js +2 -1
  382. package/dist/src/gateway/hono/routes/public-gateway.js.map +1 -1
  383. package/dist/src/gateway/hono/routes/sessions.js +14 -0
  384. package/dist/src/gateway/hono/routes/sessions.js.map +1 -1
  385. package/dist/src/gateway/run-loop.js +2 -0
  386. package/dist/src/gateway/run-loop.js.map +1 -1
  387. package/dist/src/gateway/security/operator-scopes.js +5 -1
  388. package/dist/src/gateway/security/operator-scopes.js.map +1 -1
  389. package/dist/src/gateway/service/config-coordinator.d.ts +4 -4
  390. package/dist/src/gateway/service/config-coordinator.js +14 -8
  391. package/dist/src/gateway/service/config-coordinator.js.map +1 -1
  392. package/dist/src/gateway/service/marketplace-service.d.ts +4 -4
  393. package/dist/src/gateway/service/marketplace-service.js +11 -7
  394. package/dist/src/gateway/service/marketplace-service.js.map +1 -1
  395. package/dist/src/gateway/service/sessions-api.d.ts +2 -1
  396. package/dist/src/gateway/service/sessions-api.js +6 -1
  397. package/dist/src/gateway/service/sessions-api.js.map +1 -1
  398. package/dist/src/gateway/service.d.ts +7 -3
  399. package/dist/src/gateway/service.js +61 -27
  400. package/dist/src/gateway/service.js.map +1 -1
  401. package/dist/src/goals/goal-service.js +45 -4
  402. package/dist/src/goals/goal-service.js.map +1 -1
  403. package/dist/src/infra/update-restart.js +1 -1
  404. package/dist/src/migrations/config/default-capability-preset.d.ts +10 -0
  405. package/dist/src/migrations/config/default-capability-preset.js +135 -0
  406. package/dist/src/migrations/config/default-capability-preset.js.map +1 -0
  407. package/dist/src/migrations/index.d.ts +4 -0
  408. package/dist/src/migrations/index.js +4 -0
  409. package/dist/src/migrations/registry.d.ts +8 -0
  410. package/dist/src/migrations/registry.js +18 -0
  411. package/dist/src/migrations/registry.js.map +1 -0
  412. package/dist/src/migrations/runner.d.ts +17 -0
  413. package/dist/src/migrations/runner.js +191 -0
  414. package/dist/src/migrations/runner.js.map +1 -0
  415. package/dist/src/migrations/types.d.ts +34 -0
  416. package/dist/src/notes/service.js +27 -2
  417. package/dist/src/notes/service.js.map +1 -1
  418. package/dist/src/providers/index.d.ts +4 -5
  419. package/dist/src/providers/index.js +16 -16
  420. package/dist/src/providers/index.js.map +1 -1
  421. package/dist/src/providers/model-registry.d.ts +0 -1
  422. package/dist/src/providers/model-registry.js +0 -3
  423. package/dist/src/providers/model-registry.js.map +1 -1
  424. package/dist/src/routing/resolve-tui-session-key.d.ts +3 -0
  425. package/dist/src/routing/resolve-tui-session-key.js +14 -3
  426. package/dist/src/routing/resolve-tui-session-key.js.map +1 -1
  427. package/dist/src/session/session-workspace.js +2 -7
  428. package/dist/src/session/session-workspace.js.map +1 -1
  429. package/dist/src/session/store.js +0 -5
  430. package/dist/src/session/store.js.map +1 -1
  431. package/dist/src/session/transcript-outline.d.ts +47 -0
  432. package/dist/src/session/transcript-outline.js +481 -0
  433. package/dist/src/session/transcript-outline.js.map +1 -0
  434. package/dist/src/storage/sqlite/index.d.ts +1 -3
  435. package/dist/src/storage/sqlite/index.js +2 -4
  436. package/dist/src/storage/sqlite/memory-index-repository.d.ts +1 -0
  437. package/dist/src/storage/sqlite/memory-index-repository.js +15 -14
  438. package/dist/src/storage/sqlite/memory-index-repository.js.map +1 -1
  439. package/dist/src/storage/sqlite/memory-records-repository.d.ts +44 -1
  440. package/dist/src/storage/sqlite/memory-records-repository.js +164 -20
  441. package/dist/src/storage/sqlite/memory-records-repository.js.map +1 -1
  442. package/dist/src/storage/sqlite/migrations/014_memory_record_governance.sql +10 -0
  443. package/dist/src/storage/sqlite/migrations/015_memory_trace_feedback.sql +4 -0
  444. package/dist/src/storage/sqlite/migrations/016_automations.sql +47 -0
  445. package/dist/src/storage/sqlite/migrations/017_automation_run_events.sql +14 -0
  446. package/dist/src/storage/sqlite/migrations/018_automation_safety.sql +1 -0
  447. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  448. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  449. package/dist/src/storage/sqlite/migrations/runner.js.map +1 -1
  450. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  451. package/dist/src/storage/sqlite/schema.js +1 -1
  452. package/dist/src/storage/sqlite/schema.sql +56 -46
  453. package/dist/src/tui/backends/embedded-backend.d.ts +9 -0
  454. package/dist/src/tui/backends/embedded-backend.js +55 -27
  455. package/dist/src/tui/backends/embedded-backend.js.map +1 -1
  456. package/dist/src/tui/backends/gateway-sse-backend.d.ts +4 -0
  457. package/dist/src/tui/backends/gateway-sse-backend.js +30 -3
  458. package/dist/src/tui/backends/gateway-sse-backend.js.map +1 -1
  459. package/dist/src/tui/components/tui-header.d.ts +0 -1
  460. package/dist/src/tui/components/tui-header.js +3 -8
  461. package/dist/src/tui/components/tui-header.js.map +1 -1
  462. package/dist/src/tui/tui-backend.d.ts +4 -0
  463. package/dist/src/tui/tui-commands.d.ts +5 -0
  464. package/dist/src/tui/tui-commands.js +43 -0
  465. package/dist/src/tui/tui-commands.js.map +1 -1
  466. package/dist/src/tui/tui-startup-resources.js +2 -1
  467. package/dist/src/tui/tui-startup-resources.js.map +1 -1
  468. package/dist/src/tui/tui-startup-text.js +12 -12
  469. package/dist/src/tui/tui-startup-text.js.map +1 -1
  470. package/dist/src/tui/tui-transcript-tree.d.ts +1 -1
  471. package/dist/src/tui/tui-transcript-tree.js +17 -257
  472. package/dist/src/tui/tui-transcript-tree.js.map +1 -1
  473. package/dist/src/tui/tui-types.d.ts +2 -0
  474. package/dist/src/tui/tui-types.js.map +1 -1
  475. package/dist/src/tui/tui.js +11 -3
  476. package/dist/src/tui/tui.js.map +1 -1
  477. package/dist/src/workflows/domain/index.js +1 -1
  478. package/dist/src/workflows/domain/run.d.ts +7 -7
  479. package/dist/src/workflows/domain/run.js.map +1 -1
  480. package/dist/src/workflows/index.js +2 -2
  481. package/dist/src/workflows/service/workflow-run-service.d.ts +2 -0
  482. package/dist/src/workflows/service/workflow-run-service.js +31 -9
  483. package/dist/src/workflows/service/workflow-run-service.js.map +1 -1
  484. package/dist/src/workflows/service/workflow-run-service.types.d.ts +1 -1
  485. package/package.json +4 -2
  486. package/dist/gateway/static/root/assets/agents-C6xgagZd.js +0 -71
  487. package/dist/gateway/static/root/assets/app-management-settings-panel-CBpLONvG.js +0 -1
  488. package/dist/gateway/static/root/assets/appearance-settings-CGcc54yj.js +0 -1
  489. package/dist/gateway/static/root/assets/browser-settings-page-CUOO-PQk.js +0 -8
  490. package/dist/gateway/static/root/assets/capability-presets-api-XQoMTI0A.js +0 -1
  491. package/dist/gateway/static/root/assets/capability-presets-settings-panel-CfqF-kGr.js +0 -1
  492. package/dist/gateway/static/root/assets/channels-settings-BYyRzsex.js +0 -1
  493. package/dist/gateway/static/root/assets/cn-JdwAhgNB.js +0 -1
  494. package/dist/gateway/static/root/assets/connectors-page-DIvEz4NX.js +0 -2
  495. package/dist/gateway/static/root/assets/createLucideIcon-DPHK1VkS.js +0 -1
  496. package/dist/gateway/static/root/assets/cron-api-R41aQCX9.js +0 -1
  497. package/dist/gateway/static/root/assets/cron-dreaming-jobs-nCMWCf0p.js +0 -1
  498. package/dist/gateway/static/root/assets/cron-page-D97nFqQD.js +0 -3
  499. package/dist/gateway/static/root/assets/dreaming-settings-Bceaw1PG.js +0 -1
  500. package/dist/gateway/static/root/assets/format-cron-label-BsotZDO5.js +0 -2
  501. package/dist/gateway/static/root/assets/format-interval-label-Dn_QKIqb.js +0 -1
  502. package/dist/gateway/static/root/assets/gateway-settings-iISWAZRm.js +0 -1
  503. package/dist/gateway/static/root/assets/goal-detail-page-DCUROLMQ.js +0 -1
  504. package/dist/gateway/static/root/assets/goals-settings-CPAuFwoD.js +0 -1
  505. package/dist/gateway/static/root/assets/heartbeat-config-api-D7bKFEeO.js +0 -1
  506. package/dist/gateway/static/root/assets/heartbeat-settings-CC69vNx0.js +0 -1
  507. package/dist/gateway/static/root/assets/index-CwhK8qCh.js +0 -122
  508. package/dist/gateway/static/root/assets/index-CyfhARL-.css +0 -1
  509. package/dist/gateway/static/root/assets/interval-presets-0DtsnxE0.js +0 -1
  510. package/dist/gateway/static/root/assets/keyboard-shortcuts-settings-BPREtN8B.js +0 -1
  511. package/dist/gateway/static/root/assets/messages-Cf1O9JB0.js +0 -3
  512. package/dist/gateway/static/root/assets/models-hub-panel-DmKiIihT.js +0 -2
  513. package/dist/gateway/static/root/assets/note-detail-page-CxxfLRJZ.js +0 -2
  514. package/dist/gateway/static/root/assets/notes-page-X2slSx7V.js +0 -1
  515. package/dist/gateway/static/root/assets/remote-access-hub-BvmUWqgu.js +0 -1
  516. package/dist/gateway/static/root/assets/schedule-field-CgJSCD3B.js +0 -1
  517. package/dist/gateway/static/root/assets/sessions-page-B0yESuuL.js +0 -1
  518. package/dist/gateway/static/root/assets/settings-advanced-gate-q2M8RKOo.js +0 -1
  519. package/dist/gateway/static/root/assets/settings-page-CGozabLD.js +0 -1
  520. package/dist/gateway/static/root/assets/setup-status-panel-FoOSe6nU.js +0 -1
  521. package/dist/gateway/static/root/assets/shares-settings-Cy5zWyYQ.js +0 -1
  522. package/dist/gateway/static/root/assets/skill-reload-api-DaZNFro9.js +0 -1
  523. package/dist/gateway/static/root/assets/skills-page-CnwtUzvw.js +0 -2
  524. package/dist/gateway/static/root/assets/system-settings-panel-DXs2VmBt.js +0 -1
  525. package/dist/gateway/static/root/assets/typed-models-lib-4gPuydz_.js +0 -1
  526. package/dist/gateway/static/root/assets/voice-api-key-field-DvKiOglO.js +0 -1
  527. package/dist/gateway/static/root/assets/workflows-page-CAVZcONQ.js +0 -18
  528. package/dist/src/agent/context/workspace-templates/USER.md +0 -24
  529. package/dist/src/agent/fallback/error.d.ts +0 -22
  530. package/dist/src/agent/fallback/error.js +0 -32
  531. package/dist/src/agent/fallback/error.js.map +0 -1
  532. package/dist/src/agent/fallback/index.d.ts +0 -5
  533. package/dist/src/agent/fallback/index.js +0 -9
  534. package/dist/src/agent/fallback/index.js.map +0 -1
  535. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.d.ts +0 -29
  536. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.js +0 -76
  537. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.js.map +0 -1
  538. package/dist/src/agent/service/reconcile-dreaming-cron.d.ts +0 -6
  539. package/dist/src/agent/service/reconcile-dreaming-cron.js +0 -84
  540. package/dist/src/agent/service/reconcile-dreaming-cron.js.map +0 -1
  541. package/dist/src/agent/tools/cronjob-tool.d.ts +0 -29
  542. package/dist/src/agent/tools/cronjob-tool.js +0 -274
  543. package/dist/src/agent/tools/cronjob-tool.js.map +0 -1
  544. package/dist/src/cli/commands/cron-cli.d.ts +0 -2
  545. package/dist/src/cli/commands/cron-cli.js +0 -15
  546. package/dist/src/cli/commands/cron-cli.js.map +0 -1
  547. package/dist/src/cli/commands/cron.d.ts +0 -4
  548. package/dist/src/cli/commands/cron.js +0 -188
  549. package/dist/src/cli/commands/cron.js.map +0 -1
  550. package/dist/src/cli/commands/doctor/checks/cron-health.js +0 -35
  551. package/dist/src/cli/commands/doctor/checks/cron-health.js.map +0 -1
  552. package/dist/src/cron/execution-types.d.ts +0 -42
  553. package/dist/src/cron/executor.d.ts +0 -67
  554. package/dist/src/cron/executor.js +0 -669
  555. package/dist/src/cron/executor.js.map +0 -1
  556. package/dist/src/cron/index.d.ts +0 -7
  557. package/dist/src/cron/index.js +0 -7
  558. package/dist/src/cron/job-content.d.ts +0 -5
  559. package/dist/src/cron/job-content.js +0 -15
  560. package/dist/src/cron/job-content.js.map +0 -1
  561. package/dist/src/cron/run-log-store.d.ts +0 -12
  562. package/dist/src/cron/run-log-store.js +0 -58
  563. package/dist/src/cron/run-log-store.js.map +0 -1
  564. package/dist/src/cron/schedule.d.ts +0 -10
  565. package/dist/src/cron/schedule.js +0 -85
  566. package/dist/src/cron/schedule.js.map +0 -1
  567. package/dist/src/cron/service.d.ts +0 -58
  568. package/dist/src/cron/service.js +0 -419
  569. package/dist/src/cron/service.js.map +0 -1
  570. package/dist/src/cron/types.d.ts +0 -183
  571. package/dist/src/cron/validation.d.ts +0 -500
  572. package/dist/src/cron/validation.js +0 -192
  573. package/dist/src/cron/validation.js.map +0 -1
  574. package/dist/src/cron/workflow-run-completion.d.ts +0 -23
  575. package/dist/src/cron/workflow-run-completion.js +0 -72
  576. package/dist/src/cron/workflow-run-completion.js.map +0 -1
  577. package/dist/src/extensions/types/phase4.js +0 -1
  578. package/dist/src/gateway/hono/routes/cron.d.ts +0 -3
  579. package/dist/src/gateway/hono/routes/cron.js +0 -109
  580. package/dist/src/gateway/hono/routes/cron.js.map +0 -1
  581. package/dist/src/storage/sqlite/cron-job-repository.d.ts +0 -6
  582. package/dist/src/storage/sqlite/cron-job-repository.js +0 -70
  583. package/dist/src/storage/sqlite/cron-job-repository.js.map +0 -1
  584. package/dist/src/storage/sqlite/cron-run-repository.d.ts +0 -5
  585. package/dist/src/storage/sqlite/cron-run-repository.js +0 -96
  586. package/dist/src/storage/sqlite/cron-run-repository.js.map +0 -1
  587. /package/dist/src/{cron → automations/domain}/types.js +0 -0
  588. /package/dist/src/{config/defaults.d.ts → automations/draft/automation-draft.types.js} +0 -0
  589. /package/dist/src/{config/defaults.js → extensions/types/registration.js} +0 -0
  590. /package/dist/src/{cron/execution-types.js → migrations/types.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"goal-service.js","names":[],"sources":["../../../src/goals/goal-service.ts"],"sourcesContent":["import type { Config } from '../config/schema.js';\nimport { defaultMaxTurns } from '../agent/goals/state.js';\nimport { GoalStore } from './goal-store.js';\nimport type {\n CreateGoalInput,\n Goal,\n GoalChecklistAddedBy,\n GoalChecklistStatus,\n GoalContextAttachment,\n GoalJudgeDecision,\n GoalListQuery,\n GoalSource,\n GoalStatus,\n GoalUiLocale,\n GoalWithDetails,\n} from './types.js';\n\nfunction normalizeTitle(title: string): string {\n const t = title.trim();\n if (!t) throw new Error('Goal title is required');\n return t;\n}\n\nfunction toTerminalStatus(verdict: GoalJudgeDecision['verdict']): GoalStatus {\n if (verdict === 'done') return 'done';\n if (verdict === 'blocked') return 'blocked';\n if (verdict === 'needs_input') return 'needs_input';\n return 'active';\n}\n\nexport class GoalService {\n private readonly store: GoalStore;\n\n constructor(store = new GoalStore()) {\n this.store = store;\n }\n\n create(input: Omit<CreateGoalInput, 'maxTurns' | 'agentId'> & {\n maxTurns?: number;\n agentId?: string;\n config?: Config;\n }): Goal {\n const sessionKey = input.sessionKey;\n const cfg = input.config?.goals;\n return this.store.create({\n title: normalizeTitle(input.title),\n description: input.description,\n agentId: input.agentId ?? 'main',\n sessionKey,\n priority: input.priority,\n deadlineAt: input.deadlineAt,\n judgeModelRef: input.judgeModelRef ?? cfg?.judgeModelRef,\n maxTurns: input.maxTurns ?? defaultMaxTurns(cfg),\n uiLocale: input.uiLocale,\n source: input.source,\n });\n }\n\n get(goalId: string): GoalWithDetails | null {\n const goal = this.store.get(goalId);\n if (!goal) return null;\n return {\n ...goal,\n checklist: this.store.listChecklist(goalId),\n latestRun: this.store.listRuns(goalId, 1)[0],\n contextMessage: this.store.getContextMessage(goalId) ?? undefined,\n };\n }\n\n getActiveForSession(sessionKey: string): GoalWithDetails | null {\n const goal = this.store.getActiveForSession(sessionKey);\n return goal ? this.get(goal.id) : null;\n }\n\n list(query: GoalListQuery = {}): GoalWithDetails[] {\n return this.store.list(query).map((goal) => ({\n ...goal,\n checklist: this.store.listChecklist(goal.id),\n latestRun: this.store.listRuns(goal.id, 1)[0],\n contextMessage: this.store.getContextMessage(goal.id) ?? undefined,\n }));\n }\n\n setContextMessage(input: {\n goalId: string;\n text: string;\n attachments?: GoalContextAttachment[];\n }): GoalWithDetails | null {\n if (!this.store.get(input.goalId)) return null;\n this.store.setContextMessage(input);\n return this.get(input.goalId);\n }\n\n update(goalId: string, patch: Partial<Pick<\n Goal,\n | 'title'\n | 'description'\n | 'priority'\n | 'deadlineAt'\n | 'maxTurns'\n | 'judgeModelRef'\n | 'nextAction'\n | 'blockedReason'\n | 'activeSessionKey'\n | 'uiLocale'\n >>): GoalWithDetails | null {\n const normalized: typeof patch = { ...patch };\n if (typeof normalized.title === 'string') {\n normalized.title = normalizeTitle(normalized.title);\n }\n if (typeof normalized.description === 'string') {\n normalized.description = normalized.description.trim() || undefined;\n }\n if (typeof normalized.judgeModelRef === 'string') {\n normalized.judgeModelRef = normalized.judgeModelRef.trim() || undefined;\n }\n if (typeof normalized.nextAction === 'string') {\n normalized.nextAction = normalized.nextAction.trim() || undefined;\n }\n if (typeof normalized.blockedReason === 'string') {\n normalized.blockedReason = normalized.blockedReason.trim() || undefined;\n }\n if (typeof normalized.maxTurns === 'number') {\n normalized.maxTurns = Math.max(1, Math.min(500, Math.floor(normalized.maxTurns)));\n }\n const goal = this.store.update(goalId, normalized);\n return goal ? this.get(goal.id) : null;\n }\n\n setStatus(goalId: string, status: GoalStatus, opts?: { reason?: string }): GoalWithDetails | null {\n const now = Date.now();\n const goal = this.store.update(goalId, {\n status,\n completedAt: status === 'done' ? now : undefined,\n archivedAt: status === 'archived' ? now : undefined,\n blockedReason: status === 'blocked' || status === 'needs_input' ? opts?.reason : undefined,\n });\n return goal ? this.get(goal.id) : null;\n }\n\n pause(goalId: string, reason = 'user-paused'): GoalWithDetails | null {\n const goal = this.store.update(goalId, {\n status: 'paused',\n blockedReason: reason,\n completedAt: undefined,\n archivedAt: undefined,\n });\n return goal ? this.get(goal.id) : null;\n }\n\n resume(goalId: string): GoalWithDetails | null {\n const goal = this.store.update(goalId, {\n status: 'active',\n blockedReason: undefined,\n completedAt: undefined,\n archivedAt: undefined,\n turnsUsed: 0,\n });\n return goal ? this.get(goal.id) : null;\n }\n\n reopen(goalId: string): GoalWithDetails | null {\n const goal = this.store.update(goalId, {\n status: 'active',\n blockedReason: undefined,\n completedAt: undefined,\n archivedAt: undefined,\n turnsUsed: 0,\n });\n return goal ? this.get(goal.id) : null;\n }\n\n complete(goalId: string): GoalWithDetails | null {\n return this.setStatus(goalId, 'done');\n }\n\n archive(goalId: string): GoalWithDetails | null {\n return this.setStatus(goalId, 'archived');\n }\n\n unarchive(goalId: string): GoalWithDetails | null {\n const goal = this.store.update(goalId, {\n status: 'paused',\n archivedAt: undefined,\n completedAt: undefined,\n blockedReason: undefined,\n });\n return goal ? this.get(goal.id) : null;\n }\n\n attachSession(goalId: string, sessionKey: string): GoalWithDetails | null {\n const goal = this.store.update(goalId, { activeSessionKey: sessionKey });\n return goal ? this.get(goal.id) : null;\n }\n\n updateChecklist(goalId: string, op: {\n type: 'add';\n text: string;\n addedBy?: GoalChecklistAddedBy;\n } | {\n type: 'mark';\n itemId: string;\n status: GoalChecklistStatus;\n evidenceSummary?: string;\n } | {\n type: 'remove';\n itemId: string;\n } | {\n type: 'reset';\n }): GoalWithDetails | null {\n if (op.type === 'add') {\n const text = op.text.trim();\n if (!text) throw new Error('Checklist item text is required');\n this.store.addChecklistItem({ goalId, text, addedBy: op.addedBy ?? 'user' });\n } else if (op.type === 'mark') {\n this.store.updateChecklistItem(op.itemId, {\n status: op.status,\n evidenceSummary: op.evidenceSummary,\n });\n } else if (op.type === 'remove') {\n this.store.removeChecklistItem(op.itemId);\n } else {\n this.store.clearChecklist(goalId);\n }\n return this.get(goalId);\n }\n\n recordJudgeDecision(input: {\n goalId: string;\n sessionKey: string;\n source: GoalSource;\n decision: GoalJudgeDecision;\n }): GoalWithDetails | null {\n const goal = this.store.get(input.goalId);\n if (!goal) return null;\n const nextStatus = toTerminalStatus(input.decision.verdict);\n const turnsUsed = goal.turnsUsed + 1;\n const status = turnsUsed >= goal.maxTurns && nextStatus === 'active' ? 'paused' : nextStatus;\n const reason =\n status === 'paused' && turnsUsed >= goal.maxTurns\n ? `turn budget exhausted (${turnsUsed}/${goal.maxTurns})`\n : input.decision.reason;\n\n const run = this.store.appendRun({\n goalId: input.goalId,\n sessionKey: input.sessionKey,\n source: input.source,\n status: 'succeeded',\n finishedAt: Date.now(),\n verdict: input.decision.verdict,\n reason: input.decision.reason,\n nextAction: input.decision.nextAction,\n assistantPreview: input.decision.assistantPreview,\n checklistProgress: input.decision.checklistProgress,\n confidence: input.decision.confidence,\n missingEvidence: input.decision.missingEvidence,\n userQuestion: input.decision.userQuestion,\n completedChecklistItemIds: input.decision.completedChecklistItemIds,\n });\n\n this.store.update(input.goalId, {\n status,\n turnsUsed,\n currentRunId: run.id,\n nextAction: input.decision.nextAction,\n blockedReason: status === 'blocked' || status === 'needs_input' || status === 'paused' ? reason : undefined,\n completedAt: status === 'done' ? Date.now() : undefined,\n });\n\n return this.get(input.goalId);\n }\n\n syncPostTurnState(input: {\n goalId: string;\n sessionKey: string;\n source: GoalSource;\n status: GoalStatus;\n turnsUsed: number;\n maxTurns: number;\n reason?: string;\n nextAction?: string;\n assistantPreview?: string;\n verdict: 'continue' | 'done' | 'blocked' | 'needs_input' | 'decompose';\n confidence?: number;\n missingEvidence?: string[];\n userQuestion?: string;\n completedChecklistItemIds?: string[];\n checklist?: Array<{\n text: string;\n status: 'pending' | 'completed' | 'impossible';\n addedBy: 'user' | 'judge';\n addedAt?: number;\n completedAt?: number;\n evidenceSummary?: string;\n }>;\n }): GoalWithDetails | null {\n const goal = this.store.get(input.goalId);\n if (!goal) return null;\n if (input.checklist) {\n this.store.replaceChecklist(input.goalId, input.checklist);\n }\n const total = input.checklist?.length ?? this.store.listChecklist(input.goalId).length;\n const done = (input.checklist ?? this.store.listChecklist(input.goalId)).filter(\n (it) => it.status === 'completed' || it.status === 'impossible',\n ).length;\n const run = this.store.appendRun({\n goalId: input.goalId,\n sessionKey: input.sessionKey,\n source: input.source,\n status: 'succeeded',\n finishedAt: Date.now(),\n verdict: input.verdict,\n reason: input.reason,\n nextAction: input.nextAction,\n assistantPreview: input.assistantPreview,\n checklistProgress: total > 0 ? { done, total } : undefined,\n confidence: input.confidence,\n missingEvidence: input.missingEvidence,\n userQuestion: input.userQuestion,\n completedChecklistItemIds: input.completedChecklistItemIds,\n });\n for (const item of input.checklist ?? []) {\n if ((item.status === 'completed' || item.status === 'impossible') && item.evidenceSummary?.trim()) {\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: `Checklist evidence: ${item.text.slice(0, 80)}`,\n summary: item.evidenceSummary.trim(),\n });\n }\n }\n for (const missing of input.missingEvidence ?? []) {\n if (!missing.trim()) continue;\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: `Missing evidence: ${missing.slice(0, 80)}`,\n summary: missing,\n });\n }\n if (input.userQuestion?.trim()) {\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: 'User input requested',\n summary: input.userQuestion.trim(),\n });\n }\n this.store.update(input.goalId, {\n status: input.status,\n turnsUsed: input.turnsUsed,\n maxTurns: input.maxTurns,\n currentRunId: run.id,\n nextAction: input.nextAction,\n blockedReason:\n input.status === 'blocked' || input.status === 'needs_input' || input.status === 'paused'\n ? input.reason\n : undefined,\n completedAt: input.status === 'done' ? Date.now() : undefined,\n });\n return this.get(input.goalId);\n }\n\n listRuns(goalId: string, limit?: number) {\n return this.store.listRuns(goalId, limit);\n }\n\n listRunsForSession(sessionKey: string, limit?: number) {\n return this.store.listRunsForSession(sessionKey, limit);\n }\n\n listEvents(goalId: string, limit?: number) {\n return this.store.listEvents(goalId, limit);\n }\n\n addEvidence(input: Parameters<GoalStore['addEvidence']>[0]) {\n return this.store.addEvidence(input);\n }\n\n listEvidence(goalId: string, limit?: number) {\n return this.store.listEvidence(goalId, limit);\n }\n}\n\nexport function normalizeGoalUiLocale(raw: unknown): GoalUiLocale | undefined {\n return raw === 'en' || raw === 'zh' ? raw : undefined;\n}\n"],"mappings":";;;AAiBA,SAAS,eAAe,OAAuB;CAC7C,MAAM,IAAI,MAAM,MAAM;AACtB,KAAI,CAAC,EAAG,OAAM,IAAI,MAAM,yBAAyB;AACjD,QAAO;;AAGT,SAAS,iBAAiB,SAAmD;AAC3E,KAAI,YAAY,OAAQ,QAAO;AAC/B,KAAI,YAAY,UAAW,QAAO;AAClC,KAAI,YAAY,cAAe,QAAO;AACtC,QAAO;;AAGT,IAAa,cAAb,MAAyB;CACvB;CAEA,YAAY,QAAQ,IAAI,WAAW,EAAE;AACnC,OAAK,QAAQ;;CAGf,OAAO,OAIE;EACP,MAAM,aAAa,MAAM;EACzB,MAAM,MAAM,MAAM,QAAQ;AAC1B,SAAO,KAAK,MAAM,OAAO;GACvB,OAAO,eAAe,MAAM,MAAM;GAClC,aAAa,MAAM;GACnB,SAAS,MAAM,WAAW;GAC1B;GACA,UAAU,MAAM;GAChB,YAAY,MAAM;GAClB,eAAe,MAAM,iBAAiB,KAAK;GAC3C,UAAU,MAAM,YAAY,gBAAgB,IAAI;GAChD,UAAU,MAAM;GAChB,QAAQ,MAAM;GACf,CAAC;;CAGJ,IAAI,QAAwC;EAC1C,MAAM,OAAO,KAAK,MAAM,IAAI,OAAO;AACnC,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO;GACL,GAAG;GACH,WAAW,KAAK,MAAM,cAAc,OAAO;GAC3C,WAAW,KAAK,MAAM,SAAS,QAAQ,EAAE,CAAC;GAC1C,gBAAgB,KAAK,MAAM,kB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"sources":["../../../src/goals/goal-service.ts"],"sourcesContent":["import type { Config } from '../config/schema.js';\nimport { defaultMaxTurns } from '../agent/goals/state.js';\nimport { publishAutomationProductEvent } from '../automations/product-events.js';\nimport { GoalStore } from './goal-store.js';\nimport type {\n CreateGoalInput,\n Goal,\n GoalChecklistAddedBy,\n GoalChecklistStatus,\n GoalContextAttachment,\n GoalJudgeDecision,\n GoalListQuery,\n GoalSource,\n GoalStatus,\n GoalUiLocale,\n GoalWithDetails,\n} from './types.js';\n\nfunction normalizeTitle(title: string): string {\n const t = title.trim();\n if (!t) throw new Error('Goal title is required');\n return t;\n}\n\nfunction toTerminalStatus(verdict: GoalJudgeDecision['verdict']): GoalStatus {\n if (verdict === 'done') return 'done';\n if (verdict === 'blocked') return 'blocked';\n if (verdict === 'needs_input') return 'needs_input';\n return 'active';\n}\n\nfunction publishGoalEvent(\n type: 'goal.created' | 'goal.status_changed',\n goal: Goal,\n extra?: Record<string, unknown>,\n): void {\n publishAutomationProductEvent({\n type,\n source: 'goals',\n payload: {\n goalId: goal.id,\n title: goal.title,\n status: goal.status,\n priority: goal.priority,\n sessionKey: goal.activeSessionKey,\n agentId: goal.agentId,\n source: goal.source,\n ...extra,\n },\n });\n}\n\nfunction publishGoalStatusEvent(\n goal: Goal,\n previousStatus?: GoalStatus,\n reason?: string,\n): void {\n if (previousStatus === goal.status) return;\n publishGoalEvent('goal.status_changed', goal, {\n previousStatus,\n reason,\n });\n}\n\nexport class GoalService {\n private readonly store: GoalStore;\n\n constructor(store = new GoalStore()) {\n this.store = store;\n }\n\n create(input: Omit<CreateGoalInput, 'maxTurns' | 'agentId'> & {\n maxTurns?: number;\n agentId?: string;\n config?: Config;\n }): Goal {\n const sessionKey = input.sessionKey;\n const cfg = input.config?.goals;\n const goal = this.store.create({\n title: normalizeTitle(input.title),\n description: input.description,\n agentId: input.agentId ?? 'main',\n sessionKey,\n priority: input.priority,\n deadlineAt: input.deadlineAt,\n judgeModelRef: input.judgeModelRef ?? cfg?.judgeModelRef,\n maxTurns: input.maxTurns ?? defaultMaxTurns(cfg),\n uiLocale: input.uiLocale,\n source: input.source,\n });\n publishGoalEvent('goal.created', goal);\n return goal;\n }\n\n get(goalId: string): GoalWithDetails | null {\n const goal = this.store.get(goalId);\n if (!goal) return null;\n return {\n ...goal,\n checklist: this.store.listChecklist(goalId),\n latestRun: this.store.listRuns(goalId, 1)[0],\n contextMessage: this.store.getContextMessage(goalId) ?? undefined,\n };\n }\n\n getActiveForSession(sessionKey: string): GoalWithDetails | null {\n const goal = this.store.getActiveForSession(sessionKey);\n return goal ? this.get(goal.id) : null;\n }\n\n list(query: GoalListQuery = {}): GoalWithDetails[] {\n return this.store.list(query).map((goal) => ({\n ...goal,\n checklist: this.store.listChecklist(goal.id),\n latestRun: this.store.listRuns(goal.id, 1)[0],\n contextMessage: this.store.getContextMessage(goal.id) ?? undefined,\n }));\n }\n\n setContextMessage(input: {\n goalId: string;\n text: string;\n attachments?: GoalContextAttachment[];\n }): GoalWithDetails | null {\n if (!this.store.get(input.goalId)) return null;\n this.store.setContextMessage(input);\n return this.get(input.goalId);\n }\n\n update(goalId: string, patch: Partial<Pick<\n Goal,\n | 'title'\n | 'description'\n | 'priority'\n | 'deadlineAt'\n | 'maxTurns'\n | 'judgeModelRef'\n | 'nextAction'\n | 'blockedReason'\n | 'activeSessionKey'\n | 'uiLocale'\n >>): GoalWithDetails | null {\n const normalized: typeof patch = { ...patch };\n if (typeof normalized.title === 'string') {\n normalized.title = normalizeTitle(normalized.title);\n }\n if (typeof normalized.description === 'string') {\n normalized.description = normalized.description.trim() || undefined;\n }\n if (typeof normalized.judgeModelRef === 'string') {\n normalized.judgeModelRef = normalized.judgeModelRef.trim() || undefined;\n }\n if (typeof normalized.nextAction === 'string') {\n normalized.nextAction = normalized.nextAction.trim() || undefined;\n }\n if (typeof normalized.blockedReason === 'string') {\n normalized.blockedReason = normalized.blockedReason.trim() || undefined;\n }\n if (typeof normalized.maxTurns === 'number') {\n normalized.maxTurns = Math.max(1, Math.min(500, Math.floor(normalized.maxTurns)));\n }\n const goal = this.store.update(goalId, normalized);\n return goal ? this.get(goal.id) : null;\n }\n\n setStatus(goalId: string, status: GoalStatus, opts?: { reason?: string }): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const now = Date.now();\n const goal = this.store.update(goalId, {\n status,\n completedAt: status === 'done' ? now : undefined,\n archivedAt: status === 'archived' ? now : undefined,\n blockedReason: status === 'blocked' || status === 'needs_input' ? opts?.reason : undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status, opts?.reason);\n return goal ? this.get(goal.id) : null;\n }\n\n pause(goalId: string, reason = 'user-paused'): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'paused',\n blockedReason: reason,\n completedAt: undefined,\n archivedAt: undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status, reason);\n return goal ? this.get(goal.id) : null;\n }\n\n resume(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'active',\n blockedReason: undefined,\n completedAt: undefined,\n archivedAt: undefined,\n turnsUsed: 0,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n reopen(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'active',\n blockedReason: undefined,\n completedAt: undefined,\n archivedAt: undefined,\n turnsUsed: 0,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n complete(goalId: string): GoalWithDetails | null {\n return this.setStatus(goalId, 'done');\n }\n\n archive(goalId: string): GoalWithDetails | null {\n return this.setStatus(goalId, 'archived');\n }\n\n unarchive(goalId: string): GoalWithDetails | null {\n const previous = this.store.get(goalId);\n const goal = this.store.update(goalId, {\n status: 'paused',\n archivedAt: undefined,\n completedAt: undefined,\n blockedReason: undefined,\n });\n if (goal) publishGoalStatusEvent(goal, previous?.status);\n return goal ? this.get(goal.id) : null;\n }\n\n attachSession(goalId: string, sessionKey: string): GoalWithDetails | null {\n const goal = this.store.update(goalId, { activeSessionKey: sessionKey });\n return goal ? this.get(goal.id) : null;\n }\n\n updateChecklist(goalId: string, op: {\n type: 'add';\n text: string;\n addedBy?: GoalChecklistAddedBy;\n } | {\n type: 'mark';\n itemId: string;\n status: GoalChecklistStatus;\n evidenceSummary?: string;\n } | {\n type: 'remove';\n itemId: string;\n } | {\n type: 'reset';\n }): GoalWithDetails | null {\n if (op.type === 'add') {\n const text = op.text.trim();\n if (!text) throw new Error('Checklist item text is required');\n this.store.addChecklistItem({ goalId, text, addedBy: op.addedBy ?? 'user' });\n } else if (op.type === 'mark') {\n this.store.updateChecklistItem(op.itemId, {\n status: op.status,\n evidenceSummary: op.evidenceSummary,\n });\n } else if (op.type === 'remove') {\n this.store.removeChecklistItem(op.itemId);\n } else {\n this.store.clearChecklist(goalId);\n }\n return this.get(goalId);\n }\n\n recordJudgeDecision(input: {\n goalId: string;\n sessionKey: string;\n source: GoalSource;\n decision: GoalJudgeDecision;\n }): GoalWithDetails | null {\n const goal = this.store.get(input.goalId);\n if (!goal) return null;\n const previousStatus = goal.status;\n const nextStatus = toTerminalStatus(input.decision.verdict);\n const turnsUsed = goal.turnsUsed + 1;\n const status = turnsUsed >= goal.maxTurns && nextStatus === 'active' ? 'paused' : nextStatus;\n const reason =\n status === 'paused' && turnsUsed >= goal.maxTurns\n ? `turn budget exhausted (${turnsUsed}/${goal.maxTurns})`\n : input.decision.reason;\n\n const run = this.store.appendRun({\n goalId: input.goalId,\n sessionKey: input.sessionKey,\n source: input.source,\n status: 'succeeded',\n finishedAt: Date.now(),\n verdict: input.decision.verdict,\n reason: input.decision.reason,\n nextAction: input.decision.nextAction,\n assistantPreview: input.decision.assistantPreview,\n checklistProgress: input.decision.checklistProgress,\n confidence: input.decision.confidence,\n missingEvidence: input.decision.missingEvidence,\n userQuestion: input.decision.userQuestion,\n completedChecklistItemIds: input.decision.completedChecklistItemIds,\n });\n\n const updated = this.store.update(input.goalId, {\n status,\n turnsUsed,\n currentRunId: run.id,\n nextAction: input.decision.nextAction,\n blockedReason: status === 'blocked' || status === 'needs_input' || status === 'paused' ? reason : undefined,\n completedAt: status === 'done' ? Date.now() : undefined,\n });\n if (updated) publishGoalStatusEvent(updated, previousStatus, reason);\n\n return this.get(input.goalId);\n }\n\n syncPostTurnState(input: {\n goalId: string;\n sessionKey: string;\n source: GoalSource;\n status: GoalStatus;\n turnsUsed: number;\n maxTurns: number;\n reason?: string;\n nextAction?: string;\n assistantPreview?: string;\n verdict: 'continue' | 'done' | 'blocked' | 'needs_input' | 'decompose';\n confidence?: number;\n missingEvidence?: string[];\n userQuestion?: string;\n completedChecklistItemIds?: string[];\n checklist?: Array<{\n text: string;\n status: 'pending' | 'completed' | 'impossible';\n addedBy: 'user' | 'judge';\n addedAt?: number;\n completedAt?: number;\n evidenceSummary?: string;\n }>;\n }): GoalWithDetails | null {\n const goal = this.store.get(input.goalId);\n if (!goal) return null;\n const previousStatus = goal.status;\n if (input.checklist) {\n this.store.replaceChecklist(input.goalId, input.checklist);\n }\n const total = input.checklist?.length ?? this.store.listChecklist(input.goalId).length;\n const done = (input.checklist ?? this.store.listChecklist(input.goalId)).filter(\n (it) => it.status === 'completed' || it.status === 'impossible',\n ).length;\n const run = this.store.appendRun({\n goalId: input.goalId,\n sessionKey: input.sessionKey,\n source: input.source,\n status: 'succeeded',\n finishedAt: Date.now(),\n verdict: input.verdict,\n reason: input.reason,\n nextAction: input.nextAction,\n assistantPreview: input.assistantPreview,\n checklistProgress: total > 0 ? { done, total } : undefined,\n confidence: input.confidence,\n missingEvidence: input.missingEvidence,\n userQuestion: input.userQuestion,\n completedChecklistItemIds: input.completedChecklistItemIds,\n });\n for (const item of input.checklist ?? []) {\n if ((item.status === 'completed' || item.status === 'impossible') && item.evidenceSummary?.trim()) {\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: `Checklist evidence: ${item.text.slice(0, 80)}`,\n summary: item.evidenceSummary.trim(),\n });\n }\n }\n for (const missing of input.missingEvidence ?? []) {\n if (!missing.trim()) continue;\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: `Missing evidence: ${missing.slice(0, 80)}`,\n summary: missing,\n });\n }\n if (input.userQuestion?.trim()) {\n this.store.addEvidence({\n goalId: input.goalId,\n runId: run.id,\n kind: 'message',\n title: 'User input requested',\n summary: input.userQuestion.trim(),\n });\n }\n const updated = this.store.update(input.goalId, {\n status: input.status,\n turnsUsed: input.turnsUsed,\n maxTurns: input.maxTurns,\n currentRunId: run.id,\n nextAction: input.nextAction,\n blockedReason:\n input.status === 'blocked' || input.status === 'needs_input' || input.status === 'paused'\n ? input.reason\n : undefined,\n completedAt: input.status === 'done' ? Date.now() : undefined,\n });\n if (updated) publishGoalStatusEvent(updated, previousStatus, input.reason);\n return this.get(input.goalId);\n }\n\n listRuns(goalId: string, limit?: number) {\n return this.store.listRuns(goalId, limit);\n }\n\n listRunsForSession(sessionKey: string, limit?: number) {\n return this.store.listRunsForSession(sessionKey, limit);\n }\n\n listEvents(goalId: string, limit?: number) {\n return this.store.listEvents(goalId, limit);\n }\n\n addEvidence(input: Parameters<GoalStore['addEvidence']>[0]) {\n return this.store.addEvidence(input);\n }\n\n listEvidence(goalId: string, limit?: number) {\n return this.store.listEvidence(goalId, limit);\n }\n}\n\nexport function normalizeGoalUiLocale(raw: unknown): GoalUiLocale | undefined {\n return raw === 'en' || raw === 'zh' ? raw : undefined;\n}\n"],"mappings":";;;;AAkBA,SAAS,eAAe,OAAuB;CAC7C,MAAM,IAAI,MAAM,MAAM;AACtB,KAAI,CAAC,EAAG,OAAM,IAAI,MAAM,yBAAyB;AACjD,QAAO;;AAGT,SAAS,iBAAiB,SAAmD;AAC3E,KAAI,YAAY,OAAQ,QAAO;AAC/B,KAAI,YAAY,UAAW,QAAO;AAClC,KAAI,YAAY,c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SAAO,KAAK,IAAI,MAAM,OAAO;;CAG/B,SAAS,QAAgB,OAAgB;AACvC,SAAO,KAAK,MAAM,SAAS,QAAQ,MAAM;;CAG3C,mBAAmB,YAAoB,OAAgB;AACrD,SAAO,KAAK,MAAM,mBAAmB,YAAY,MAAM;;CAGzD,WAAW,QAAgB,OAAgB;AACzC,SAAO,KAAK,MAAM,WAAW,QAAQ,MAAM;;CAG7C,YAAY,OAAgD;AAC1D,SAAO,KAAK,MAAM,YAAY,MAAM;;CAGtC,aAAa,QAAgB,OAAgB;AAC3C,SAAO,KAAK,MAAM,aAAa,QAAQ,MAAM;;;AAIjD,SAAgB,sBAAsB,KAAwC;AAC5E,QAAO,QAAQ,QAAQ,QAAQ,OAAO,MAAM,KAAA"}
@@ -2,8 +2,8 @@ import { createLogger } from "../utils/logger/index.js";
2
2
  import { init_logger } from "../utils/logger.js";
3
3
  import { init_paths, resolveConfigPath } from "../config/paths.js";
4
4
  import { init_loader, loadConfig } from "../config/loader.js";
5
- import { isRestartEnabled } from "../config/commands.flags.js";
6
5
  import { resolveGatewayService } from "../daemon/service.js";
6
+ import { isRestartEnabled } from "../config/commands.flags.js";
7
7
  import { authorizeGatewaySigusr1Restart, writeGatewayRestartIntentSync } from "./restart.js";
8
8
  import { findVerifiedGatewayListenerPidsOnPortSync, signalVerifiedGatewayPidSync } from "./gateway-processes.js";
9
9
  //#region src/infra/update-restart.ts
@@ -0,0 +1,10 @@
1
+ import { type CapabilityPreset } from '../../agent-manifest/schema.js';
2
+ import { type Config } from '../../config/schema.js';
3
+ import type { Migration } from '../types.js';
4
+ export declare const DEFAULT_CAPABILITY_PRESET_MIGRATION_ID = "2026-07-ensure-default-capability-preset";
5
+ export declare function createDefaultCapabilityPreset(): CapabilityPreset;
6
+ export declare function ensureDefaultCapabilityPresetInitialized(config: Config): {
7
+ config: Config;
8
+ changed: boolean;
9
+ };
10
+ export declare const defaultCapabilityPresetMigration: Migration;
@@ -0,0 +1,135 @@
1
+ import { CapabilityPresetSchema, DEFAULT_CAPABILITY_PRESET_ID, init_schema } from "../../agent-manifest/schema.js";
2
+ import { ConfigSchema, init_schema as init_schema$1 } from "../../config/schema.js";
3
+ import { existsSync, readFileSync } from "node:fs";
4
+ //#region src/migrations/config/default-capability-preset.ts
5
+ init_schema();
6
+ init_schema$1();
7
+ const DEFAULT_CAPABILITY_PRESET_MIGRATION_ID = "2026-07-ensure-default-capability-preset";
8
+ function createDefaultCapabilityPreset() {
9
+ return {
10
+ id: DEFAULT_CAPABILITY_PRESET_ID,
11
+ name: "Global defaults",
12
+ description: "Default capabilities inherited by every agent.",
13
+ version: 1,
14
+ models: {
15
+ defaultRole: "deep",
16
+ roles: {}
17
+ }
18
+ };
19
+ }
20
+ function ensureDefaultCapabilityPresetInitialized(config) {
21
+ const agents = config.agents;
22
+ const capabilityPresets = { ...agents.capabilityPresets ?? {} };
23
+ let changed = false;
24
+ if (!capabilityPresets["default"]) {
25
+ capabilityPresets[DEFAULT_CAPABILITY_PRESET_ID] = createDefaultCapabilityPreset();
26
+ changed = true;
27
+ }
28
+ const defaultPreset = agents.defaultPreset?.trim() || "default";
29
+ if (defaultPreset !== agents.defaultPreset) changed = true;
30
+ if (!changed) return {
31
+ config,
32
+ changed: false
33
+ };
34
+ return {
35
+ config: ConfigSchema.parse({
36
+ ...config,
37
+ agents: {
38
+ ...agents,
39
+ defaultPreset,
40
+ capabilityPresets
41
+ }
42
+ }),
43
+ changed: true
44
+ };
45
+ }
46
+ function planned(message, details) {
47
+ return {
48
+ id: DEFAULT_CAPABILITY_PRESET_MIGRATION_ID,
49
+ title: "Initialize global default capability preset",
50
+ kind: "config",
51
+ safety: "auto",
52
+ status: "planned",
53
+ message,
54
+ details
55
+ };
56
+ }
57
+ function conflict(message, details) {
58
+ return {
59
+ id: DEFAULT_CAPABILITY_PRESET_MIGRATION_ID,
60
+ title: "Initialize global default capability preset",
61
+ kind: "config",
62
+ safety: "manual",
63
+ status: "conflict",
64
+ message,
65
+ details
66
+ };
67
+ }
68
+ function readRawConfigObject(configPath) {
69
+ if (!existsSync(configPath)) return null;
70
+ const raw = readFileSync(configPath, "utf8");
71
+ const parsed = JSON.parse(raw);
72
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("Config root must be an object");
73
+ return parsed;
74
+ }
75
+ const defaultCapabilityPresetMigration = {
76
+ id: DEFAULT_CAPABILITY_PRESET_MIGRATION_ID,
77
+ kind: "config",
78
+ safety: "auto",
79
+ detect(ctx) {
80
+ const raw = readRawConfigObject(ctx.configPath);
81
+ if (!raw) return null;
82
+ const rawAgents = raw.agents;
83
+ if (rawAgents !== void 0 && (rawAgents === null || typeof rawAgents !== "object" || Array.isArray(rawAgents))) return conflict("agents config is not an object; cannot initialize global defaults automatically.");
84
+ const agents = rawAgents ?? {};
85
+ const rawPresets = agents.capabilityPresets;
86
+ if (rawPresets !== void 0 && (rawPresets === null || typeof rawPresets !== "object" || Array.isArray(rawPresets))) return conflict("agents.capabilityPresets is not an object; cannot initialize global defaults automatically.");
87
+ const existingDefault = (rawPresets ?? {})[DEFAULT_CAPABILITY_PRESET_ID];
88
+ if (existingDefault !== void 0) {
89
+ const parsedPreset = CapabilityPresetSchema.safeParse(existingDefault);
90
+ if (!parsedPreset.success) return conflict("Existing default capability preset is invalid; please repair it manually.", { issues: parsedPreset.error.issues.slice(0, 5).map((issue) => ({
91
+ path: issue.path.join("."),
92
+ message: issue.message
93
+ })) });
94
+ }
95
+ const needsDefaultPresetPointer = typeof agents.defaultPreset !== "string" || agents.defaultPreset.trim().length === 0;
96
+ const needsDefaultPresetObject = existingDefault === void 0;
97
+ if (!needsDefaultPresetPointer && !needsDefaultPresetObject) return null;
98
+ return planned("Global default capability preset is missing and will be initialized.", {
99
+ addDefaultPresetPointer: needsDefaultPresetPointer,
100
+ addDefaultPresetObject: needsDefaultPresetObject
101
+ });
102
+ },
103
+ apply(ctx) {
104
+ const detected = this.detect(ctx);
105
+ if (!detected) return {
106
+ id: this.id,
107
+ title: "Initialize global default capability preset",
108
+ kind: "config",
109
+ safety: "auto",
110
+ status: "not_needed",
111
+ message: "Global default capability preset is already initialized."
112
+ };
113
+ if (detected.status === "conflict") return detected;
114
+ const raw = readRawConfigObject(ctx.configPath);
115
+ const ensured = ensureDefaultCapabilityPresetInitialized(ConfigSchema.parse(raw ?? void 0));
116
+ if (!ensured.changed) return {
117
+ ...detected,
118
+ status: "not_needed",
119
+ message: "Global default capability preset is already initialized."
120
+ };
121
+ return {
122
+ ...detected,
123
+ status: "applied",
124
+ message: "Initialized global default capability preset.",
125
+ details: {
126
+ ...detected.details,
127
+ config: ensured.config
128
+ }
129
+ };
130
+ }
131
+ };
132
+ //#endregion
133
+ export { DEFAULT_CAPABILITY_PRESET_MIGRATION_ID, createDefaultCapabilityPreset, defaultCapabilityPresetMigration, ensureDefaultCapabilityPresetInitialized };
134
+
135
+ //# sourceMappingURL=default-capability-preset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-capability-preset.js","names":[],"sources":["../../../../src/migrations/config/default-capability-preset.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\n\nimport {\n CapabilityPresetSchema,\n DEFAULT_CAPABILITY_PRESET_ID,\n type CapabilityPreset,\n} from '../../agent-manifest/schema.js';\nimport { ConfigSchema, type Config } from '../../config/schema.js';\nimport type { Migration, MigrationContext, MigrationPlanItem } from '../types.js';\n\nexport const DEFAULT_CAPABILITY_PRESET_MIGRATION_ID = '2026-07-ensure-default-capability-preset';\n\nexport function createDefaultCapabilityPreset(): CapabilityPreset {\n return {\n id: DEFAULT_CAPABILITY_PRESET_ID,\n name: 'Global defaults',\n description: 'Default capabilities inherited by every agent.',\n version: 1,\n models: {\n defaultRole: 'deep',\n roles: {},\n },\n };\n}\n\nexport function ensureDefaultCapabilityPresetInitialized(config: Config): { config: Config; changed: boolean } {\n const agents = config.agents;\n const capabilityPresets = { ...(agents.capabilityPresets ?? {}) };\n let changed = false;\n\n if (!capabilityPresets[DEFAULT_CAPABILITY_PRESET_ID]) {\n capabilityPresets[DEFAULT_CAPABILITY_PRESET_ID] = createDefaultCapabilityPreset();\n changed = true;\n }\n\n const defaultPreset = agents.defaultPreset?.trim() || DEFAULT_CAPABILITY_PRESET_ID;\n if (defaultPreset !== agents.defaultPreset) {\n changed = true;\n }\n\n if (!changed) return { config, changed: false };\n\n return {\n config: ConfigSchema.parse({\n ...config,\n agents: {\n ...agents,\n defaultPreset,\n capabilityPresets,\n },\n }),\n changed: true,\n };\n}\n\nfunction planned(message: string, details?: Record<string, unknown>): MigrationPlanItem {\n return {\n id: DEFAULT_CAPABILITY_PRESET_MIGRATION_ID,\n title: 'Initialize global default capability preset',\n kind: 'config',\n safety: 'auto',\n status: 'planned',\n message,\n details,\n };\n}\n\nfunction conflict(message: string, details?: Record<string, unknown>): MigrationPlanItem {\n return {\n id: DEFAULT_CAPABILITY_PRESET_MIGRATION_ID,\n title: 'Initialize global default capability preset',\n kind: 'config',\n safety: 'manual',\n status: 'conflict',\n message,\n details,\n };\n}\n\nfunction readRawConfigObject(configPath: string): Record<string, unknown> | null {\n if (!existsSync(configPath)) return null;\n const raw = readFileSync(configPath, 'utf8');\n const parsed = JSON.parse(raw) as unknown;\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new Error('Config root must be an object');\n }\n return parsed as Record<string, unknown>;\n}\n\nexport const defaultCapabilityPresetMigration: Migration = {\n id: DEFAULT_CAPABILITY_PRESET_MIGRATION_ID,\n kind: 'config',\n safety: 'auto',\n\n detect(ctx: MigrationContext): MigrationPlanItem | null {\n const raw = readRawConfigObject(ctx.configPath);\n if (!raw) return null;\n\n const rawAgents = raw.agents;\n if (rawAgents !== undefined && (rawAgents === null || typeof rawAgents !== 'object' || Array.isArray(rawAgents))) {\n return conflict('agents config is not an object; cannot initialize global defaults automatically.');\n }\n\n const agents = (rawAgents ?? {}) as Record<string, unknown>;\n const rawPresets = agents.capabilityPresets;\n if (rawPresets !== undefined && (rawPresets === null || typeof rawPresets !== 'object' || Array.isArray(rawPresets))) {\n return conflict('agents.capabilityPresets is not an object; cannot initialize global defaults automatically.');\n }\n\n const presets = (rawPresets ?? {}) as Record<string, unknown>;\n const existingDefault = presets[DEFAULT_CAPABILITY_PRESET_ID];\n if (existingDefault !== undefined) {\n const parsedPreset = CapabilityPresetSchema.safeParse(existingDefault);\n if (!parsedPreset.success) {\n return conflict('Existing default capability preset is invalid; please repair it manually.', {\n issues: parsedPreset.error.issues.slice(0, 5).map((issue) => ({\n path: issue.path.join('.'),\n message: issue.message,\n })),\n });\n }\n }\n\n const needsDefaultPresetPointer = typeof agents.defaultPreset !== 'string' || agents.defaultPreset.trim().length === 0;\n const needsDefaultPresetObject = existingDefault === undefined;\n if (!needsDefaultPresetPointer && !needsDefaultPresetObject) return null;\n\n return planned('Global default capability preset is missing and will be initialized.', {\n addDefaultPresetPointer: needsDefaultPresetPointer,\n addDefaultPresetObject: needsDefaultPresetObject,\n });\n },\n\n apply(ctx: MigrationContext): MigrationPlanItem {\n const detected = this.detect(ctx);\n if (!detected) {\n return {\n id: this.id,\n title: 'Initialize global default capability preset',\n kind: 'config',\n safety: 'auto',\n status: 'not_needed',\n message: 'Global default capability preset is already initialized.',\n };\n }\n if (detected.status === 'conflict') return detected;\n\n const raw = readRawConfigObject(ctx.configPath);\n const parsed = ConfigSchema.parse(raw ?? undefined);\n const ensured = ensureDefaultCapabilityPresetInitialized(parsed);\n if (!ensured.changed) {\n return { ...detected, status: 'not_needed', message: 'Global default capability preset is already initialized.' };\n }\n\n return {\n ...detected,\n status: 'applied',\n message: 'Initialized global default capability preset.',\n details: { ...detected.details, config: ensured.config },\n };\n },\n};\n"],"mappings":";;;;aAMwC;eAC2B;AAGnE,MAAa,yCAAyC;AAEtD,SAAgB,gCAAkD;AAChE,QAAO;EACL,IAAI;EACJ,MAAM;EACN,aAAa;EACb,SAAS;EACT,QAAQ;GACN,aAAa;GACb,OAAO,EAAE;GACV;EACF;;AAGH,SAAgB,yCAAyC,QAA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js';
3
+ export * from './registry.js';
4
+ export * from './config/default-capability-preset.js';
@@ -0,0 +1,4 @@
1
+ import { listRegisteredMigrations, registerMigration, unregisterMigrationsForSource } from "./registry.js";
2
+ import { DEFAULT_CAPABILITY_PRESET_MIGRATION_ID, createDefaultCapabilityPreset, defaultCapabilityPresetMigration, ensureDefaultCapabilityPresetInitialized } from "./config/default-capability-preset.js";
3
+ import { CORE_MIGRATIONS, applyMigrations, detectMigrations, runBootstrapMigrationsSync } from "./runner.js";
4
+ export { CORE_MIGRATIONS, DEFAULT_CAPABILITY_PRESET_MIGRATION_ID, applyMigrations, createDefaultCapabilityPreset, defaultCapabilityPresetMigration, detectMigrations, ensureDefaultCapabilityPresetInitialized, listRegisteredMigrations, registerMigration, runBootstrapMigrationsSync, unregisterMigrationsForSource };
@@ -0,0 +1,8 @@
1
+ import type { Migration } from './types.js';
2
+ export type RegisteredMigration = {
3
+ source: string;
4
+ migration: Migration;
5
+ };
6
+ export declare function registerMigration(source: string, migration: Migration): void;
7
+ export declare function unregisterMigrationsForSource(source: string): void;
8
+ export declare function listRegisteredMigrations(): RegisteredMigration[];
@@ -0,0 +1,18 @@
1
+ //#region src/migrations/registry.ts
2
+ const registeredMigrations = /* @__PURE__ */ new Map();
3
+ function registerMigration(source, migration) {
4
+ registeredMigrations.set(`${source}:${migration.id}`, {
5
+ source,
6
+ migration
7
+ });
8
+ }
9
+ function unregisterMigrationsForSource(source) {
10
+ for (const [key, value] of registeredMigrations.entries()) if (value.source === source) registeredMigrations.delete(key);
11
+ }
12
+ function listRegisteredMigrations() {
13
+ return [...registeredMigrations.values()];
14
+ }
15
+ //#endregion
16
+ export { listRegisteredMigrations, registerMigration, unregisterMigrationsForSource };
17
+
18
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../../../src/migrations/registry.ts"],"sourcesContent":["import type { Migration } from './types.js';\n\nexport type RegisteredMigration = {\n source: string;\n migration: Migration;\n};\n\nconst registeredMigrations = new Map<string, RegisteredMigration>();\n\nexport function registerMigration(source: string, migration: Migration): void {\n registeredMigrations.set(`${source}:${migration.id}`, { source, migration });\n}\n\nexport function unregisterMigrationsForSource(source: string): void {\n for (const [key, value] of registeredMigrations.entries()) {\n if (value.source === source) registeredMigrations.delete(key);\n }\n}\n\nexport function listRegisteredMigrations(): RegisteredMigration[] {\n return [...registeredMigrations.values()];\n}\n"],"mappings":";AAOA,MAAM,uCAAuB,IAAI,KAAkC;AAEnE,SAAgB,kBAAkB,QAAgB,WAA4B;AAC5E,sBAAqB,IAAI,GAAG,OAAO,GAAG,UAAU,MAAM;EAAE;EAAQ;EAAW,CAAC;;AAG9E,SAAgB,8BAA8B,QAAsB;AAClE,MAAK,MAAM,CAAC,KAAK,UAAU,qBAAqB,SAAS,CACvD,KAAI,MAAM,WAAW,OAAQ,sBAAqB,OAAO,IAAI;;AAIjE,SAAgB,2BAAkD;AAChE,QAAO,CAAC,GAAG,qBAAqB,QAAQ,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Migration, MigrationPlanItem } from './types.js';
2
+ export declare const CORE_MIGRATIONS: readonly Migration[];
3
+ export type MigrationApplyMode = 'auto-safe' | 'doctor-fix' | 'manual';
4
+ export interface MigrationApplyResult {
5
+ items: MigrationPlanItem[];
6
+ changed: boolean;
7
+ }
8
+ export declare function detectMigrations(configPath: string, options?: {
9
+ stateDir?: string;
10
+ }): MigrationPlanItem[];
11
+ export declare function applyMigrations(configPath: string, options?: {
12
+ stateDir?: string;
13
+ mode?: MigrationApplyMode;
14
+ }): MigrationApplyResult;
15
+ export declare function runBootstrapMigrationsSync(configPath: string, options?: {
16
+ stateDir?: string;
17
+ }): MigrationApplyResult;
@@ -0,0 +1,191 @@
1
+ import { ConfigSchema, init_schema } from "../config/schema.js";
2
+ import { createLogger } from "../utils/logger/index.js";
3
+ import { init_logger } from "../utils/logger.js";
4
+ import { listRegisteredMigrations } from "./registry.js";
5
+ import { defaultCapabilityPresetMigration } from "./config/default-capability-preset.js";
6
+ import { dirname, join } from "node:path";
7
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
8
+ //#region src/migrations/runner.ts
9
+ init_schema();
10
+ init_logger();
11
+ const log = createLogger("Migrations");
12
+ const MIGRATION_LEDGER_FILENAME = "migrations.json";
13
+ const CONFIG_BACKUP_COUNT = 10;
14
+ const CORE_MIGRATIONS = [...[defaultCapabilityPresetMigration]];
15
+ function listAllMigrations() {
16
+ return [...CORE_MIGRATIONS, ...listRegisteredMigrations().map((entry) => entry.migration)];
17
+ }
18
+ function publicItem(item) {
19
+ if (!item.details || !Object.hasOwn(item.details, "config")) return item;
20
+ const { config: _config, ...details } = item.details;
21
+ return {
22
+ ...item,
23
+ details
24
+ };
25
+ }
26
+ function makeContext(configPath, stateDir) {
27
+ return {
28
+ configPath,
29
+ stateDir: stateDir ?? dirname(configPath),
30
+ now: /* @__PURE__ */ new Date()
31
+ };
32
+ }
33
+ function rotateConfigBackupsSync(configPath) {
34
+ const backupBase = `${configPath}.bak`;
35
+ for (let index = CONFIG_BACKUP_COUNT - 1; index >= 1; index--) {
36
+ const source = index === 1 ? backupBase : `${backupBase}.${index - 1}`;
37
+ const target = `${backupBase}.${index}`;
38
+ if (existsSync(source)) try {
39
+ renameSync(source, target);
40
+ } catch {}
41
+ }
42
+ }
43
+ function writeConfigWithBackupSync(configPath, config) {
44
+ const validated = ConfigSchema.parse(config);
45
+ mkdirSync(dirname(configPath), { recursive: true });
46
+ if (existsSync(configPath)) {
47
+ rotateConfigBackupsSync(configPath);
48
+ try {
49
+ writeFileSync(`${configPath}.bak`, readFileSync(configPath, "utf8"), "utf8");
50
+ } catch {}
51
+ }
52
+ const tmp = `${configPath}.tmp-${process.pid}-${Date.now()}`;
53
+ writeFileSync(tmp, `${JSON.stringify(validated, null, 2)}\n`, "utf8");
54
+ renameSync(tmp, configPath);
55
+ }
56
+ function resolveLedgerPath(ctx) {
57
+ if (!ctx.stateDir) return null;
58
+ return join(ctx.stateDir, MIGRATION_LEDGER_FILENAME);
59
+ }
60
+ function readLedger(ctx) {
61
+ const ledgerPath = resolveLedgerPath(ctx);
62
+ if (!ledgerPath || !existsSync(ledgerPath)) return {
63
+ version: 1,
64
+ runs: []
65
+ };
66
+ try {
67
+ const parsed = JSON.parse(readFileSync(ledgerPath, "utf8"));
68
+ if (parsed.version === 1 && Array.isArray(parsed.runs)) return {
69
+ version: 1,
70
+ runs: parsed.runs
71
+ };
72
+ } catch {}
73
+ return {
74
+ version: 1,
75
+ runs: []
76
+ };
77
+ }
78
+ function appendLedgerRun(ctx, item) {
79
+ const ledgerPath = resolveLedgerPath(ctx);
80
+ if (!ledgerPath) return;
81
+ try {
82
+ const ledger = readLedger(ctx);
83
+ ledger.runs.push({
84
+ id: item.id,
85
+ status: item.status,
86
+ appliedAt: (ctx.now ?? /* @__PURE__ */ new Date()).toISOString(),
87
+ message: item.message
88
+ });
89
+ mkdirSync(dirname(ledgerPath), { recursive: true });
90
+ writeFileSync(ledgerPath, `${JSON.stringify(ledger, null, 2)}\n`, "utf8");
91
+ } catch (err) {
92
+ const em = err instanceof Error ? err.message : String(err);
93
+ log.warn({
94
+ err,
95
+ errorMessage: em,
96
+ path: ledgerPath
97
+ }, `Failed to write migration ledger: ${em}`);
98
+ }
99
+ }
100
+ function shouldApply(item, mode) {
101
+ if (item.status !== "planned") return false;
102
+ if (mode === "manual") return true;
103
+ return item.safety === "auto";
104
+ }
105
+ function detectMigrations(configPath, options = {}) {
106
+ const ctx = makeContext(configPath, options.stateDir);
107
+ const items = [];
108
+ for (const migration of listAllMigrations()) try {
109
+ const item = migration.detect(ctx);
110
+ if (item) items.push(publicItem(item));
111
+ } catch (err) {
112
+ const em = err instanceof Error ? err.message : String(err);
113
+ items.push({
114
+ id: migration.id,
115
+ title: migration.id,
116
+ kind: migration.kind,
117
+ safety: migration.safety,
118
+ status: "error",
119
+ message: `Migration detection failed: ${em}`
120
+ });
121
+ }
122
+ return items;
123
+ }
124
+ function applyMigrations(configPath, options = {}) {
125
+ const ctx = makeContext(configPath, options.stateDir);
126
+ const mode = options.mode ?? "auto-safe";
127
+ const results = [];
128
+ let changed = false;
129
+ for (const migration of listAllMigrations()) {
130
+ let detected;
131
+ try {
132
+ detected = migration.detect(ctx);
133
+ } catch (err) {
134
+ const em = err instanceof Error ? err.message : String(err);
135
+ results.push({
136
+ id: migration.id,
137
+ title: migration.id,
138
+ kind: migration.kind,
139
+ safety: migration.safety,
140
+ status: "error",
141
+ message: `Migration detection failed: ${em}`
142
+ });
143
+ continue;
144
+ }
145
+ if (!detected) continue;
146
+ if (!shouldApply(detected, mode)) {
147
+ results.push(publicItem(detected));
148
+ continue;
149
+ }
150
+ try {
151
+ const applied = migration.apply(ctx);
152
+ const nextConfig = applied.details?.config;
153
+ if (applied.status === "applied" && nextConfig) {
154
+ writeConfigWithBackupSync(configPath, ConfigSchema.parse(nextConfig));
155
+ changed = true;
156
+ appendLedgerRun(ctx, applied);
157
+ }
158
+ results.push(publicItem(applied));
159
+ } catch (err) {
160
+ const em = err instanceof Error ? err.message : String(err);
161
+ results.push({
162
+ ...detected,
163
+ status: "error",
164
+ message: `Migration apply failed: ${em}`
165
+ });
166
+ }
167
+ }
168
+ return {
169
+ items: results,
170
+ changed
171
+ };
172
+ }
173
+ function runBootstrapMigrationsSync(configPath, options = {}) {
174
+ if (!existsSync(configPath)) return {
175
+ items: [],
176
+ changed: false
177
+ };
178
+ const result = applyMigrations(configPath, {
179
+ ...options,
180
+ mode: "auto-safe"
181
+ });
182
+ if (result.changed) log.info({
183
+ configPath,
184
+ count: result.items.filter((item) => item.status === "applied").length
185
+ }, "Applied bootstrap migrations");
186
+ return result;
187
+ }
188
+ //#endregion
189
+ export { CORE_MIGRATIONS, applyMigrations, detectMigrations, runBootstrapMigrationsSync };
190
+
191
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","names":[],"sources":["../../../src/migrations/runner.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\n\nimport { ConfigSchema, type Config } from '../config/schema.js';\nimport { createLogger } from '../utils/logger.js';\nimport { defaultCapabilityPresetMigration } from './config/default-capability-preset.js';\nimport { listRegisteredMigrations } from './registry.js';\nimport type { Migration, MigrationContext, MigrationLedger, MigrationPlanItem } from './types.js';\n\nconst log = createLogger('Migrations');\nconst MIGRATION_LEDGER_FILENAME = 'migrations.json';\nconst CONFIG_BACKUP_COUNT = 10;\n\nconst CONFIG_MIGRATIONS: readonly Migration[] = [defaultCapabilityPresetMigration];\nexport const CORE_MIGRATIONS: readonly Migration[] = [...CONFIG_MIGRATIONS];\n\nfunction listAllMigrations(): Migration[] {\n return [...CORE_MIGRATIONS, ...listRegisteredMigrations().map((entry) => entry.migration)];\n}\n\nexport type MigrationApplyMode = 'auto-safe' | 'doctor-fix' | 'manual';\n\nexport interface MigrationApplyResult {\n items: MigrationPlanItem[];\n changed: boolean;\n}\n\nfunction publicItem(item: MigrationPlanItem): MigrationPlanItem {\n if (!item.details || !Object.hasOwn(item.details, 'config')) return item;\n const { config: _config, ...details } = item.details;\n return { ...item, details };\n}\n\nfunction makeContext(configPath: string, stateDir?: string): MigrationContext {\n return { configPath, stateDir: stateDir ?? dirname(configPath), now: new Date() };\n}\n\nfunction rotateConfigBackupsSync(configPath: string): void {\n const backupBase = `${configPath}.bak`;\n for (let index = CONFIG_BACKUP_COUNT - 1; index >= 1; index--) {\n const source = index === 1 ? backupBase : `${backupBase}.${index - 1}`;\n const target = `${backupBase}.${index}`;\n if (existsSync(source)) {\n try { renameSync(source, target); } catch { /* best effort */ }\n }\n }\n}\n\nfunction writeConfigWithBackupSync(configPath: string, config: Config): void {\n const validated = ConfigSchema.parse(config);\n mkdirSync(dirname(configPath), { recursive: true });\n if (existsSync(configPath)) {\n rotateConfigBackupsSync(configPath);\n try {\n writeFileSync(`${configPath}.bak`, readFileSync(configPath, 'utf8'), 'utf8');\n } catch {\n // best-effort backup; atomic write below still proceeds\n }\n }\n const tmp = `${configPath}.tmp-${process.pid}-${Date.now()}`;\n writeFileSync(tmp, `${JSON.stringify(validated, null, 2)}\\n`, 'utf8');\n renameSync(tmp, configPath);\n}\n\nfunction resolveLedgerPath(ctx: MigrationContext): string | null {\n if (!ctx.stateDir) return null;\n return join(ctx.stateDir, MIGRATION_LEDGER_FILENAME);\n}\n\nfunction readLedger(ctx: MigrationContext): MigrationLedger {\n const ledgerPath = resolveLedgerPath(ctx);\n if (!ledgerPath || !existsSync(ledgerPath)) return { version: 1, runs: [] };\n try {\n const parsed = JSON.parse(readFileSync(ledgerPath, 'utf8')) as Partial<MigrationLedger>;\n if (parsed.version === 1 && Array.isArray(parsed.runs)) {\n return { version: 1, runs: parsed.runs as MigrationLedger['runs'] };\n }\n } catch {\n // Corrupt migration ledgers should never block runtime startup.\n }\n return { version: 1, runs: [] };\n}\n\nfunction appendLedgerRun(ctx: MigrationContext, item: MigrationPlanItem): void {\n const ledgerPath = resolveLedgerPath(ctx);\n if (!ledgerPath) return;\n try {\n const ledger = readLedger(ctx);\n ledger.runs.push({\n id: item.id,\n status: item.status,\n appliedAt: (ctx.now ?? new Date()).toISOString(),\n message: item.message,\n });\n mkdirSync(dirname(ledgerPath), { recursive: true });\n writeFileSync(ledgerPath, `${JSON.stringify(ledger, null, 2)}\\n`, 'utf8');\n } catch (err) {\n const em = err instanceof Error ? err.message : String(err);\n log.warn({ err, errorMessage: em, path: ledgerPath }, `Failed to write migration ledger: ${em}`);\n }\n}\n\nfunction shouldApply(item: MigrationPlanItem, mode: MigrationApplyMode): boolean {\n if (item.status !== 'planned') return false;\n if (mode === 'manual') return true;\n return item.safety === 'auto';\n}\n\nexport function detectMigrations(configPath: string, options: { stateDir?: string } = {}): MigrationPlanItem[] {\n const ctx = makeContext(configPath, options.stateDir);\n const items: MigrationPlanItem[] = [];\n for (const migration of listAllMigrations()) {\n try {\n const item = migration.detect(ctx);\n if (item) items.push(publicItem(item));\n } catch (err) {\n const em = err instanceof Error ? err.message : String(err);\n items.push({\n id: migration.id,\n title: migration.id,\n kind: migration.kind,\n safety: migration.safety,\n status: 'error',\n message: `Migration detection failed: ${em}`,\n });\n }\n }\n return items;\n}\n\nexport function applyMigrations(\n configPath: string,\n options: { stateDir?: string; mode?: MigrationApplyMode } = {},\n): MigrationApplyResult {\n const ctx = makeContext(configPath, options.stateDir);\n const mode = options.mode ?? 'auto-safe';\n const results: MigrationPlanItem[] = [];\n let changed = false;\n\n for (const migration of listAllMigrations()) {\n let detected: MigrationPlanItem | null;\n try {\n detected = migration.detect(ctx);\n } catch (err) {\n const em = err instanceof Error ? err.message : String(err);\n results.push({\n id: migration.id,\n title: migration.id,\n kind: migration.kind,\n safety: migration.safety,\n status: 'error',\n message: `Migration detection failed: ${em}`,\n });\n continue;\n }\n\n if (!detected) continue;\n if (!shouldApply(detected, mode)) {\n results.push(publicItem(detected));\n continue;\n }\n\n try {\n const applied = migration.apply(ctx);\n const nextConfig = applied.details?.config;\n if (applied.status === 'applied' && nextConfig) {\n writeConfigWithBackupSync(configPath, ConfigSchema.parse(nextConfig));\n changed = true;\n appendLedgerRun(ctx, applied);\n }\n results.push(publicItem(applied));\n } catch (err) {\n const em = err instanceof Error ? err.message : String(err);\n results.push({\n ...detected,\n status: 'error',\n message: `Migration apply failed: ${em}`,\n });\n }\n }\n\n return { items: results, changed };\n}\n\nexport function runBootstrapMigrationsSync(configPath: string, options: { stateDir?: string } = {}): MigrationApplyResult {\n if (!existsSync(configPath)) return { items: [], changed: false };\n const result = applyMigrations(configPath, { ...options, mode: 'auto-safe' });\n if (result.changed) {\n log.info({ configPath, count: result.items.filter((item) => item.status === 'applied').length }, 'Applied bootstrap migrations');\n }\n return result;\n}\n"],"mappings":";;;;;;;;aAGgE;aACd;AAKlD,MAAM,MAAM,aAAa,aAAa;AACtC,MAAM,4BAA4B;AAClC,MAAM,sBAAsB;AAG5B,MAAa,kBAAwC,CAAC,GA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,QAAQ;IACR,SAAS,2BAA2B;IACrC,CAAC;;;AAIN,QAAO;EAAE,OAAO;EAAS;EAAS;;AAGpC,SAAgB,2BAA2B,YAAoB,UAAiC,EAAE,EAAwB;AACxH,KAAI,CAAC,WAAW,WAAW,CAAE,QAAO;EAAE,OAAO,EAAE;EAAE,SAAS;EAAO;CACjE,MAAM,SAAS,gBAAgB,YAAY;EAAE,GAAG;EAAS,MAAM;EAAa,CAAC;AAC7E,KAAI,OAAO,QACT,KAAI,KAAK;EAAE;EAAY,OAAO,OAAO,MAAM,QAAQ,SAAS,KAAK,WAAW,UAAU,CAAC;EAAQ,EAAE,+BAA+B;AAElI,QAAO"}
@@ -0,0 +1,34 @@
1
+ export type MigrationKind = 'config' | 'state' | 'sqlite' | 'extension';
2
+ export type MigrationSafety = 'auto' | 'manual' | 'blocked';
3
+ export type MigrationStatus = 'not_needed' | 'planned' | 'applied' | 'skipped' | 'conflict' | 'error';
4
+ export interface MigrationPlanItem {
5
+ id: string;
6
+ title: string;
7
+ kind: MigrationKind;
8
+ safety: MigrationSafety;
9
+ status: MigrationStatus;
10
+ message: string;
11
+ details?: Record<string, unknown>;
12
+ }
13
+ export interface MigrationContext {
14
+ configPath: string;
15
+ stateDir?: string;
16
+ now?: Date;
17
+ }
18
+ export interface Migration {
19
+ id: string;
20
+ kind: MigrationKind;
21
+ safety: MigrationSafety;
22
+ detect(ctx: MigrationContext): MigrationPlanItem | null;
23
+ apply(ctx: MigrationContext): MigrationPlanItem;
24
+ }
25
+ export interface MigrationLedgerRun {
26
+ id: string;
27
+ status: MigrationStatus;
28
+ appliedAt: string;
29
+ message: string;
30
+ }
31
+ export interface MigrationLedger {
32
+ version: 1;
33
+ runs: MigrationLedgerRun[];
34
+ }