mixdog 1.4.2 → 1.4.4

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 (474) hide show
  1. package/package.json +2 -2
  2. package/scripts/build-shipped-history.mjs +15 -5
  3. package/scripts/gate-local.mjs +65 -19
  4. package/scripts/graph-parity.mjs +8 -3
  5. package/scripts/lib/gate-scheduler.mjs +2 -1
  6. package/scripts/lib/run-node-tests.mjs +17 -5
  7. package/scripts/lib/test-failure-summary.mjs +1 -8
  8. package/scripts/lib/test-spawn-ledger.mjs +33 -2
  9. package/scripts/post-release-check.mjs +26 -16
  10. package/scripts/provider-pingpong-live.mjs +1 -1
  11. package/scripts/prune-embedding-runtime.mjs +3 -1
  12. package/scripts/release-paths.mjs +7 -1
  13. package/src/defaults/shipped-history.json +24 -0
  14. package/src/defaults/skills/computer-use/SKILL.md +14 -3
  15. package/src/defaults/skills/memory-management/SKILL.md +10 -5
  16. package/src/defaults/skills/setup/SKILL.md +2 -2
  17. package/src/defaults/skills/setup/references/actions.md +17 -4
  18. package/src/defaults/skills/setup/references/surfaces.md +3 -0
  19. package/src/defaults/skills/setup-guide/SKILL.md +6 -1
  20. package/src/lib/instruction-text.cjs +36 -0
  21. package/src/lib/rules-builder.cjs +34 -20
  22. package/src/orchestration/balanced.md +23 -0
  23. package/src/orchestration/focused.md +22 -0
  24. package/src/orchestration/none.md +5 -0
  25. package/src/orchestration/swarm.md +24 -0
  26. package/src/rules/agent-mode/AGENT_MODE.md +3 -1
  27. package/src/rules/agent-mode/MIXY.md +5 -3
  28. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/session-prep.mjs +3 -3
  29. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +0 -1
  30. package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +4 -2
  31. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +0 -9
  32. package/src/runtime/agent/orchestrator/agent-runtime/heartbeat-completion.mjs +2 -2
  33. package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +67 -0
  34. package/src/runtime/agent/orchestrator/agent-trace-format.mjs +1 -0
  35. package/src/runtime/agent/orchestrator/context/role-instructions.mjs +4 -4
  36. package/src/runtime/agent/orchestrator/mcp/agent-connectors.mjs +3 -1
  37. package/src/runtime/agent/orchestrator/mcp/child-tree.mjs +199 -46
  38. package/src/runtime/agent/orchestrator/mcp/client-config.mjs +3 -5
  39. package/src/runtime/agent/orchestrator/mcp/client-transport.mjs +9 -3
  40. package/src/runtime/agent/orchestrator/mcp/client.mjs +3 -5
  41. package/src/runtime/agent/orchestrator/mcp/oauth-client.mjs +1 -1
  42. package/src/runtime/agent/orchestrator/mcp/oauth-credentials.mjs +8 -2
  43. package/src/runtime/agent/orchestrator/mcp/oauth-probe.mjs +1 -1
  44. package/src/runtime/agent/orchestrator/mcp/oauth-provider.mjs +14 -0
  45. package/src/runtime/agent/orchestrator/mcp/oauth.mjs +1 -1
  46. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +2 -1
  47. package/src/runtime/agent/orchestrator/providers/anthropic-api-request.mjs +11 -1
  48. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +1 -1
  49. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-start.mjs +4 -0
  50. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-stop.mjs +3 -3
  51. package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +2 -0
  52. package/src/runtime/agent/orchestrator/providers/anthropic-turn-result.mjs +2 -0
  53. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +2 -0
  54. package/src/runtime/agent/orchestrator/providers/codex-client-meta.mjs +1 -1
  55. package/src/runtime/agent/orchestrator/providers/custom-provider-config.mjs +121 -9
  56. package/src/runtime/agent/orchestrator/providers/custom-provider.mjs +4 -1
  57. package/src/runtime/agent/orchestrator/providers/gemini-thinking.mjs +2 -2
  58. package/src/runtime/agent/orchestrator/providers/lib/generation-window.mjs +9 -0
  59. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +9 -1
  60. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +2 -0
  61. package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +5 -0
  62. package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +3 -0
  63. package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +6 -6
  64. package/src/runtime/agent/orchestrator/providers/openai-compat-responses-head-parity.json +2784 -2872
  65. package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +10 -1
  66. package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +5 -8
  67. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events.mjs +3 -0
  68. package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +2 -0
  69. package/src/runtime/agent/orchestrator/providers/openai-responses-payload-parity.fixture.json +288 -300
  70. package/src/runtime/agent/orchestrator/providers/openai-ws-response-state.mjs +9 -2
  71. package/src/runtime/agent/orchestrator/providers/openrouter-provider-routing.mjs +28 -0
  72. package/src/runtime/agent/orchestrator/providers/openrouter.mjs +4 -1
  73. package/src/runtime/agent/orchestrator/providers/registry.mjs +30 -25
  74. package/src/runtime/agent/orchestrator/providers/vertex-ai.mjs +10 -1
  75. package/src/runtime/agent/orchestrator/providers/xai-tool-search-head-parity.json +10 -30
  76. package/src/runtime/agent/orchestrator/runtime-core/ask-user-result.mjs +66 -0
  77. package/src/runtime/agent/orchestrator/runtime-core/builtin-features.mjs +30 -0
  78. package/src/runtime/agent/orchestrator/runtime-core/config-helpers.mjs +0 -11
  79. package/src/runtime/agent/orchestrator/runtime-core/deferred-tool-availability.mjs +8 -0
  80. package/src/runtime/agent/orchestrator/runtime-core/deferred-tool-delta.mjs +17 -3
  81. package/src/runtime/agent/orchestrator/runtime-core/goal-control.mjs +47 -27
  82. package/src/runtime/agent/orchestrator/runtime-core/goal-deadlines.mjs +141 -10
  83. package/src/runtime/agent/orchestrator/runtime-core/goal-mutations.mjs +26 -63
  84. package/src/runtime/agent/orchestrator/runtime-core/goal-reminder.mjs +28 -3
  85. package/src/runtime/agent/orchestrator/runtime-core/goal-runtime.mjs +36 -11
  86. package/src/runtime/agent/orchestrator/runtime-core/goal-state.mjs +88 -56
  87. package/src/runtime/agent/orchestrator/runtime-core/goal-storage.mjs +4 -1
  88. package/src/runtime/agent/orchestrator/runtime-core/goal-store.mjs +51 -32
  89. package/src/runtime/agent/orchestrator/runtime-core/goal-text.mjs +45 -145
  90. package/src/runtime/agent/orchestrator/runtime-core/goal-tool-defs.mjs +15 -98
  91. package/src/runtime/agent/orchestrator/runtime-core/goal-tool-exec.mjs +32 -99
  92. package/src/runtime/agent/orchestrator/runtime-core/goal-turns.mjs +23 -78
  93. package/src/runtime/agent/orchestrator/runtime-core/orchestration.mjs +69 -48
  94. package/src/runtime/agent/orchestrator/runtime-core/todo-list.mjs +367 -0
  95. package/src/runtime/agent/orchestrator/runtime-core/todo-tool-defs.mjs +47 -0
  96. package/src/runtime/agent/orchestrator/runtime-core/tool-availability.mjs +155 -0
  97. package/src/runtime/agent/orchestrator/runtime-core/tool-catalog-data.mjs +9 -0
  98. package/src/runtime/agent/orchestrator/runtime-core/tool-catalog.mjs +119 -35
  99. package/src/runtime/agent/orchestrator/runtime-core/tool-defs.mjs +1 -1
  100. package/src/runtime/agent/orchestrator/runtime-core/workflow/context.mjs +1 -1
  101. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +28 -22
  102. package/src/runtime/agent/orchestrator/session/agent-pool-progress.mjs +30 -0
  103. package/src/runtime/agent/orchestrator/session/attachment-preflight.mjs +1 -1
  104. package/src/runtime/agent/orchestrator/session/cache-warm.mjs +2 -2
  105. package/src/runtime/agent/orchestrator/session/catalog-db/index.mjs +2 -2
  106. package/src/runtime/agent/orchestrator/session/catalog-db/schema.mjs +1 -1
  107. package/src/runtime/agent/orchestrator/session/compact/execution-tail.mjs +1 -1
  108. package/src/runtime/agent/orchestrator/session/compact/runner.mjs +3 -0
  109. package/src/runtime/agent/orchestrator/session/compact/summary-route.mjs +1 -1
  110. package/src/runtime/agent/orchestrator/session/context-utils.mjs +8 -12
  111. package/src/runtime/agent/orchestrator/session/conversation-import/claude.mjs +1 -1
  112. package/src/runtime/agent/orchestrator/session/conversation-import/codex.mjs +1 -1
  113. package/src/runtime/agent/orchestrator/session/conversation-import/convert.mjs +1 -1
  114. package/src/runtime/agent/orchestrator/session/conversation-import/imported-session.mjs +7 -3
  115. package/src/runtime/agent/orchestrator/session/human-gate/held-message.mjs +1 -1
  116. package/src/runtime/agent/orchestrator/session/human-gate/requests.mjs +1 -2
  117. package/src/runtime/agent/orchestrator/session/human-gate/run-policy.mjs +1 -1
  118. package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +1 -1
  119. package/src/runtime/agent/orchestrator/session/loop/completion-guards.mjs +11 -1
  120. package/src/runtime/agent/orchestrator/session/loop/context-overflow.mjs +1 -1
  121. package/src/runtime/agent/orchestrator/session/loop/loop-state.mjs +8 -1
  122. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/todo-check.mjs +196 -0
  123. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn.mjs +116 -50
  124. package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +8 -1
  125. package/src/runtime/agent/orchestrator/session/loop/provider-tool-exclusions.mjs +1 -1
  126. package/src/runtime/agent/orchestrator/session/loop/route-fallback.mjs +1 -1
  127. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +3 -1
  128. package/src/runtime/agent/orchestrator/session/loop/stored-tool-args.mjs +5 -6
  129. package/src/runtime/agent/orchestrator/session/loop/tool-exec/before-hook.mjs +6 -1
  130. package/src/runtime/agent/orchestrator/session/loop/tool-exec/dispatch.mjs +16 -2
  131. package/src/runtime/agent/orchestrator/session/loop/turn-report.mjs +35 -0
  132. package/src/runtime/agent/orchestrator/session/loop/usage.mjs +1 -1
  133. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +57 -26
  134. package/src/runtime/agent/orchestrator/session/manager/ask-turn-auto-effort.mjs +9 -7
  135. package/src/runtime/agent/orchestrator/session/manager/ask-turn-execute.mjs +21 -3
  136. package/src/runtime/agent/orchestrator/session/manager/ask-turn-failure.mjs +27 -11
  137. package/src/runtime/agent/orchestrator/session/manager/ask-turn-open.mjs +37 -34
  138. package/src/runtime/agent/orchestrator/session/manager/ask-turn-prepare.mjs +15 -0
  139. package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +25 -15
  140. package/src/runtime/agent/orchestrator/session/manager/ask-turn-state.mjs +79 -24
  141. package/src/runtime/agent/orchestrator/session/manager/ask-turn-steering-drain.mjs +3 -0
  142. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +12 -1
  143. package/src/runtime/agent/orchestrator/session/manager/context-meta.mjs +1 -1
  144. package/src/runtime/agent/orchestrator/session/manager/idle-cleanup.mjs +6 -1
  145. package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +9 -1
  146. package/src/runtime/agent/orchestrator/session/manager/pending-spool-path.mjs +2 -2
  147. package/src/runtime/agent/orchestrator/session/manager/pending-spool-shard.mjs +1 -1
  148. package/src/runtime/agent/orchestrator/session/manager/prompt-settings.mjs +598 -0
  149. package/src/runtime/agent/orchestrator/session/manager/prompt-utils.mjs +19 -0
  150. package/src/runtime/agent/orchestrator/session/manager/rules-cache.mjs +19 -10
  151. package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +8 -1
  152. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +5 -0
  153. package/src/runtime/agent/orchestrator/session/manager/session-fallback-title.mjs +1 -1
  154. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +31 -0
  155. package/src/runtime/agent/orchestrator/session/manager/session-lock.mjs +31 -0
  156. package/src/runtime/agent/orchestrator/session/manager/session-prompt-composition.mjs +42 -6
  157. package/src/runtime/agent/orchestrator/session/manager/session-record.mjs +2 -0
  158. package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +11 -1
  159. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-context.mjs +8 -9
  160. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +339 -88
  161. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-recovery.mjs +135 -11
  162. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +377 -104
  163. package/src/runtime/agent/orchestrator/session/manager/turn-durability.mjs +144 -0
  164. package/src/runtime/agent/orchestrator/session/manager/turn-interruption.mjs +1 -1
  165. package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +4 -0
  166. package/src/runtime/agent/orchestrator/session/manager.mjs +6 -0
  167. package/src/runtime/agent/orchestrator/session/mixy-name.mjs +1 -1
  168. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +8 -1
  169. package/src/runtime/agent/orchestrator/session/save-session-worker.mjs +5 -1
  170. package/src/runtime/agent/orchestrator/session/store/canonical-reader.mjs +1 -1
  171. package/src/runtime/agent/orchestrator/session/store/liveness-veto.mjs +2 -2
  172. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +23 -2
  173. package/src/runtime/agent/orchestrator/session/store/sweep/sub-agent-retention.mjs +3 -3
  174. package/src/runtime/agent/orchestrator/session/store/transcript-durability.mjs +88 -0
  175. package/src/runtime/agent/orchestrator/session/store-agent-worker-rows.mjs +5 -0
  176. package/src/runtime/agent/orchestrator/session/store-summary-log.mjs +1 -1
  177. package/src/runtime/agent/orchestrator/session/store-transcript-projection.mjs +14 -5
  178. package/src/runtime/agent/orchestrator/session/store-transcript-worker.mjs +2 -2
  179. package/src/runtime/agent/orchestrator/session/store.mjs +17 -6
  180. package/src/runtime/agent/orchestrator/session/synthetic-user-envelope.mjs +7 -1
  181. package/src/runtime/agent/orchestrator/session/tail-reminder-rules.mjs +9 -1
  182. package/src/runtime/agent/orchestrator/session/transcript-restore/agent-envelope.mjs +1 -1
  183. package/src/runtime/agent/orchestrator/session/transcript-restore/restore.mjs +3 -1
  184. package/src/runtime/agent/orchestrator/session/transcript-restore/user-text.mjs +2 -2
  185. package/src/runtime/agent/orchestrator/stall-policy.mjs +3 -5
  186. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/backgrounded-result.mjs +4 -1
  187. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/misuse-guard.mjs +21 -3
  188. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/result-format.mjs +1 -1
  189. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/worktree-add-guard.mjs +77 -0
  190. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +0 -1
  191. package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +7 -3
  192. package/src/runtime/agent/orchestrator/tools/builtin/git-worktree-tool.mjs +27 -9
  193. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +2 -2
  194. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-output-silence.mjs +64 -0
  195. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +20 -6
  196. package/src/runtime/agent/orchestrator/tools/builtin/read-range-index.mjs +1 -1
  197. package/src/runtime/agent/orchestrator/tools/builtin/read-single-fast-paths.mjs +0 -1
  198. package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +0 -10
  199. package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +1 -2
  200. package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +12 -1
  201. package/src/runtime/agent/orchestrator/tools/builtin.mjs +1 -24
  202. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/child-kill.mjs +4 -3
  203. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary.mjs +1 -2
  204. package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +1 -1
  205. package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +2 -2
  206. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +4 -5
  207. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +3 -4
  208. package/src/runtime/agent/orchestrator/tools/code-graph.mjs +4 -22
  209. package/src/runtime/agent/orchestrator/tools/lib/shell-descendants.mjs +2 -2
  210. package/src/runtime/agent/orchestrator/tools/lib/shell-run-state.mjs +1 -1
  211. package/src/runtime/agent/orchestrator/tools/shell-command.mjs +0 -4
  212. package/src/runtime/agent/orchestrator/tools/shell-policy.mjs +0 -1
  213. package/src/runtime/attachments/attachment-reference.mjs +1 -1
  214. package/src/runtime/attachments/pdf-extract.mjs +1 -1
  215. package/src/runtime/attachments/store.d.mts +1 -0
  216. package/src/runtime/attachments/store.mjs +2 -2
  217. package/src/runtime/channels/lib/config-reload-watch.mjs +42 -0
  218. package/src/runtime/channels/lib/owned-runtime/config-reload.mjs +29 -9
  219. package/src/runtime/channels/lib/routines-db.mjs +35 -0
  220. package/src/runtime/channels/lib/scheduler.mjs +33 -0
  221. package/src/runtime/channels/lib/schedules-db.mjs +15 -4
  222. package/src/runtime/channels/lib/webhook/session-dispatch.mjs +4 -1
  223. package/src/runtime/channels/lib/webhooks-db.mjs +13 -3
  224. package/src/runtime/channels/lib/whisper-server.mjs +12 -12
  225. package/src/runtime/channels/lib/worker-main.mjs +9 -31
  226. package/src/runtime/computer-bridge/action-schema.mjs +2 -2
  227. package/src/runtime/computer-bridge/core-actions.mjs +16 -2
  228. package/src/runtime/computer-bridge/linux-readiness.mjs +10 -14
  229. package/src/runtime/computer-bridge/result-canonical.mjs +6 -0
  230. package/src/runtime/connectors/connector-accounts-mcp.mjs +169 -33
  231. package/src/runtime/connectors/gmail-app-password.mjs +2 -2
  232. package/src/runtime/connectors/google-mcp.mjs +1 -1
  233. package/src/runtime/effort-judge/judge-client.mjs +2 -2
  234. package/src/runtime/effort-judge/judge-input.mjs +4 -4
  235. package/src/runtime/explore/explorer.mjs +0 -5
  236. package/src/runtime/explore/tool.mjs +3 -3
  237. package/src/runtime/local-provider/hardware.mjs +1 -1
  238. package/src/runtime/media/adapters/codex-image.mjs +3 -3
  239. package/src/runtime/media/adapters/gemini-video.mjs +1 -1
  240. package/src/runtime/media/media-usage.mjs +1 -1
  241. package/src/runtime/media/store.mjs +1 -1
  242. package/src/runtime/memory/index.mjs +11 -1
  243. package/src/runtime/memory/lib/embedding-reindex.mjs +27 -0
  244. package/src/runtime/memory/lib/memory-embed.mjs +83 -14
  245. package/src/runtime/memory/lib/memory-process-lock.mjs +159 -36
  246. package/src/runtime/memory/lib/memory-text-utils.mjs +6 -1
  247. package/src/runtime/memory/lib/memory.mjs +17 -0
  248. package/src/runtime/memory/lib/pg/process.mjs +1 -1
  249. package/src/runtime/memory/lib/pg/supervisor.mjs +16 -96
  250. package/src/runtime/memory/lib/recall-hybrid/hybrid-sql.mjs +12 -3
  251. package/src/runtime/memory/tool-defs.mjs +1 -1
  252. package/src/runtime/office/authoring/docx-html-runner.mjs +1 -1
  253. package/src/runtime/office/authoring/pptx-author-action.mjs +1 -1
  254. package/src/runtime/office/authoring/xlsx-html-build.mjs +1 -1
  255. package/src/runtime/office/authoring/xlsx-html-runner.mjs +1 -1
  256. package/src/runtime/office/capabilities.mjs +1 -1
  257. package/src/runtime/office/core/office-core.mjs +1 -1
  258. package/src/runtime/office/design/content-model.mjs +3 -3
  259. package/src/runtime/office/design/docx/design-docx/section.mjs +6 -6
  260. package/src/runtime/office/design/xlsx/design-xlsx-components.mjs +1 -1
  261. package/src/runtime/office/design/xlsx/design-xlsx.mjs +1 -1
  262. package/src/runtime/office/pdf/ocr-engine.mjs +1 -1
  263. package/src/runtime/office/pdf/pdf-writer.mjs +4 -4
  264. package/src/runtime/office/portable/portable-docx-operations.mjs +2 -2
  265. package/src/runtime/office/portable/portable-soffice.mjs +8 -6
  266. package/src/runtime/office/portable/xlsx-contract.mjs +1 -1
  267. package/src/runtime/shared/atomic-file.d.mts +8 -0
  268. package/src/runtime/shared/background-tasks.mjs +22 -4
  269. package/src/runtime/shared/background-wait.mjs +66 -0
  270. package/src/runtime/shared/child-guardian.mjs +17 -7
  271. package/src/runtime/shared/config.mjs +313 -16
  272. package/src/runtime/shared/connector-catalog.d.mts +4 -5
  273. package/src/runtime/shared/connector-catalog.mjs +11 -1
  274. package/src/runtime/shared/file-lock.mjs +8 -3
  275. package/src/runtime/shared/git-runner.mjs +7 -2
  276. package/src/runtime/shared/idle-gc.mjs +30 -7
  277. package/src/runtime/shared/llm/http-agent.mjs +8 -5
  278. package/src/runtime/shared/llm/system-proxy.mjs +2 -1
  279. package/src/runtime/shared/llm/usage-accounting.mjs +110 -19
  280. package/src/runtime/shared/llm/usage-context.mjs +1 -1
  281. package/src/runtime/shared/llm/usage-ledger-quota.mjs +33 -12
  282. package/src/runtime/shared/llm/usage-ledger-requests.mjs +183 -0
  283. package/src/runtime/shared/llm/usage-ledger-rollup.mjs +90 -10
  284. package/src/runtime/shared/llm/usage-ledger-worker.mjs +2 -0
  285. package/src/runtime/shared/llm/usage-ledger.mjs +60 -1
  286. package/src/runtime/shared/llm/usage-request-status.mjs +48 -0
  287. package/src/runtime/shared/llm/usage-rollup.mjs +48 -0
  288. package/src/runtime/shared/maintenance-schedule.mjs +109 -0
  289. package/src/runtime/shared/process-runner.mjs +8 -4
  290. package/src/runtime/shared/routine-trigger.d.mts +13 -0
  291. package/src/runtime/shared/routine-trigger.mjs +34 -0
  292. package/src/runtime/shared/run-child.d.mts +2 -1
  293. package/src/runtime/shared/run-child.mjs +70 -18
  294. package/src/runtime/shared/session-scratch.mjs +14 -2
  295. package/src/runtime/shared/shipped-definitions.mjs +7 -1
  296. package/src/runtime/shared/tool-card-model.golden.json +3 -12
  297. package/src/runtime/shared/tool-execution-contract.mjs +2 -0
  298. package/src/runtime/shared/tool-result-summary.mjs +1 -1
  299. package/src/runtime/shared/tool-work-units.mjs +31 -6
  300. package/src/runtime/shared/turn-snapshot.mjs +26 -4
  301. package/src/runtime/shared/turn-worktree-snapshot.mjs +6 -11
  302. package/src/runtime/shared/worker-requests.mjs +17 -3
  303. package/src/runtime/shared/worktrees/branch-management.mjs +1 -5
  304. package/src/runtime/shared/worktrees/contract.mjs +16 -6
  305. package/src/runtime/shared/worktrees/dependencies.mjs +127 -89
  306. package/src/runtime/shared/worktrees/disk.mjs +79 -2
  307. package/src/runtime/shared/worktrees/git.mjs +44 -11
  308. package/src/runtime/shared/worktrees/include.mjs +6 -4
  309. package/src/runtime/shared/worktrees/maintenance.mjs +422 -30
  310. package/src/runtime/shared/worktrees/manager.mjs +772 -75
  311. package/src/runtime/shared/worktrees/settings.mjs +33 -7
  312. package/src/runtime/shared/worktrees/test-support.mjs +5 -1
  313. package/src/runtime/shared/worktrees/worker-snapshots.mjs +82 -0
  314. package/src/runtime/tidy/process.mjs +2 -1
  315. package/src/runtime/web-search/index.mjs +3 -22
  316. package/src/runtime/web-search/lib/web-tools.mjs +2 -2
  317. package/src/runtime/web-search/tool-defs.mjs +17 -26
  318. package/src/session-runtime/agent-home-delivery.mjs +76 -8
  319. package/src/session-runtime/agent-profile-changes.mjs +55 -4
  320. package/src/session-runtime/agent-task-sessions.mjs +63 -22
  321. package/src/session-runtime/boot/apis.mjs +42 -4
  322. package/src/session-runtime/boot/begin.mjs +2 -0
  323. package/src/session-runtime/boot/config.mjs +10 -1
  324. package/src/session-runtime/boot/facade.mjs +1 -0
  325. package/src/session-runtime/boot/providers.mjs +70 -3
  326. package/src/session-runtime/boot/session.mjs +2 -0
  327. package/src/session-runtime/boot/tools.mjs +75 -25
  328. package/src/session-runtime/channel-config-api.mjs +1 -0
  329. package/src/session-runtime/config-change-effects.mjs +179 -0
  330. package/src/session-runtime/config-lifecycle/config-writers.mjs +1 -0
  331. package/src/session-runtime/config-lifecycle.mjs +160 -24
  332. package/src/session-runtime/conversation-import/discovery.mjs +86 -7
  333. package/src/session-runtime/conversation-import/service.mjs +3 -2
  334. package/src/session-runtime/goal-facade-api.mjs +49 -3
  335. package/src/session-runtime/internal-tool-executor/ask-user-tool.mjs +5 -57
  336. package/src/session-runtime/internal-tool-executor/bridge-tools.mjs +3 -2
  337. package/src/session-runtime/internal-tool-executor/feature-tools.mjs +3 -11
  338. package/src/session-runtime/internal-tool-executor/workspace-tools.mjs +18 -4
  339. package/src/session-runtime/internal-tool-executor.mjs +12 -19
  340. package/src/session-runtime/lifecycle/cold-heir.mjs +7 -0
  341. package/src/session-runtime/lifecycle/memory-ingest.mjs +3 -3
  342. package/src/session-runtime/lifecycle/session-switch/session-delete.mjs +53 -5
  343. package/src/session-runtime/lifecycle/session-switch.mjs +13 -2
  344. package/src/session-runtime/lifecycle/teardown/session-close.mjs +4 -4
  345. package/src/session-runtime/lifecycle-api.mjs +1 -0
  346. package/src/session-runtime/mcp-glue/server-catalog.mjs +14 -3
  347. package/src/session-runtime/mcp-glue/server-connection.mjs +34 -8
  348. package/src/session-runtime/model-route/route-persist.mjs +12 -4
  349. package/src/session-runtime/model-route/set-route.mjs +40 -7
  350. package/src/session-runtime/native-web-search/routes.mjs +3 -3
  351. package/src/session-runtime/provider-auth/refresh.mjs +6 -3
  352. package/src/session-runtime/provider-auth/setup.mjs +1 -1
  353. package/src/session-runtime/provider-models/row-hydration.mjs +2 -0
  354. package/src/session-runtime/provider-readiness.mjs +53 -4
  355. package/src/session-runtime/resource-api.mjs +1 -1
  356. package/src/session-runtime/resource-extension-sync.mjs +4 -8
  357. package/src/session-runtime/resource-mcp-connector-accounts.mjs +5 -1
  358. package/src/session-runtime/resource-mcp-secrets.mjs +3 -3
  359. package/src/session-runtime/resource-plugins-api.mjs +4 -0
  360. package/src/session-runtime/routine-executor.mjs +152 -0
  361. package/src/session-runtime/routine-home-turn.mjs +46 -5
  362. package/src/session-runtime/routine-owner.mjs +9 -3
  363. package/src/session-runtime/runtime-facade.mjs +5 -0
  364. package/src/session-runtime/runtime-feature-gates.mjs +2 -11
  365. package/src/session-runtime/schedule-session-run.mjs +1 -0
  366. package/src/session-runtime/services/agent-task-status.mjs +29 -1
  367. package/src/session-runtime/services/agent-tool/job-task-reconcile.mjs +6 -1
  368. package/src/session-runtime/services/agent-tool/job-views/session-progress.mjs +10 -0
  369. package/src/session-runtime/services/agent-tool/render.mjs +6 -1
  370. package/src/session-runtime/services/agent-tool/send-flow.mjs +110 -6
  371. package/src/session-runtime/services/agent-tool/spawn-flow/job-start.mjs +12 -0
  372. package/src/session-runtime/services/agent-tool/spawn-flow/spawn-plan.mjs +5 -0
  373. package/src/session-runtime/services/agent-tool/spawn-flow/spawn-run.mjs +24 -6
  374. package/src/session-runtime/services/agent-tool.mjs +51 -1
  375. package/src/session-runtime/services/channel-admin.mjs +62 -3
  376. package/src/session-runtime/services/hook-bus/command-handler.mjs +7 -11
  377. package/src/session-runtime/services/plugin-admin.mjs +50 -7
  378. package/src/session-runtime/services/provider-admin.mjs +5 -0
  379. package/src/session-runtime/services/seeds.mjs +7 -0
  380. package/src/session-runtime/services/usage-stats-model.mjs +32 -11
  381. package/src/session-runtime/session-create/materialize.mjs +4 -2
  382. package/src/session-runtime/session-create/session-options.mjs +2 -0
  383. package/src/session-runtime/settings-builtin-tools-api.mjs +1 -9
  384. package/src/session-runtime/setup-tool/agent-settings-actions.mjs +1 -1
  385. package/src/session-runtime/setup-tool/connector-widen-approval.mjs +1 -1
  386. package/src/session-runtime/setup-tool/executor.mjs +9 -2
  387. package/src/session-runtime/setup-tool/extended-actions.mjs +3 -1
  388. package/src/session-runtime/setup-tool/settings-contract.mjs +30 -2
  389. package/src/session-runtime/setup-tool/tool-defs.mjs +26 -1
  390. package/src/session-runtime/tool-policy/agent-profile-fold.mjs +40 -43
  391. package/src/session-runtime/tool-policy/mode-switch.mjs +1 -1
  392. package/src/session-runtime/tool-policy/policy-stage.mjs +106 -8
  393. package/src/session-runtime/tool-policy/workflow-overlay.mjs +2 -1
  394. package/src/session-runtime/tool-policy-refresh.mjs +182 -5
  395. package/src/session-runtime/tool-surface.mjs +38 -1
  396. package/src/session-runtime/turn/agent-ops.mjs +10 -2
  397. package/src/session-runtime/turn/session-ops.mjs +2 -0
  398. package/src/session-runtime/turn/turn-run/turn-prepare.mjs +5 -0
  399. package/src/session-runtime/turn/turn-run.mjs +1 -1
  400. package/src/session-runtime/usage-stats-api.mjs +117 -1
  401. package/src/session-runtime/webhook-session-run.mjs +2 -0
  402. package/src/session-runtime/workflow-agents-api/agent-connectors.mjs +37 -33
  403. package/src/session-runtime/workflow-agents-api/agent-editor.mjs +183 -23
  404. package/src/session-runtime/workflow-agents-api/agent-route.mjs +3 -10
  405. package/src/session-runtime/workflow-agents-api/instruction-files.mjs +165 -0
  406. package/src/session-runtime/workflow-agents-api/style-and-mode.mjs +5 -4
  407. package/src/session-runtime/workflow-agents-api/workflow-packs.mjs +2 -3
  408. package/src/session-runtime/workflow-agents-api.mjs +2 -0
  409. package/src/session-runtime/workspace/project-branches.mjs +1 -1
  410. package/src/session-runtime/workspace/session-view.mjs +1 -1
  411. package/src/session-runtime/workspace/transitions.mjs +20 -4
  412. package/src/session-runtime/workspace/worktree-maintenance.mjs +126 -6
  413. package/src/session-runtime/workspace/worktree-setup.mjs +13 -1
  414. package/src/session-runtime/workspace/worktree-tool.mjs +16 -0
  415. package/src/standalone/daemon-agent-control.mjs +25 -8
  416. package/src/standalone/daemon-desktop-runtime.mjs +6 -2
  417. package/src/standalone/daemon-lag-profiler.mjs +7 -7
  418. package/src/standalone/daemon.mjs +54 -2
  419. package/src/standalone/local-session-runtime.mjs +16 -0
  420. package/src/standalone/session-client/daemon-unavailable.mjs +1 -1
  421. package/src/standalone/session-protocol.mjs +12 -0
  422. package/src/standalone/session-service/agent-route-follow.mjs +23 -20
  423. package/src/standalone/session-service/agent-tree/agent-turns.mjs +18 -6
  424. package/src/standalone/session-service/quota-resume.mjs +9 -0
  425. package/src/standalone/session-service/retention/busy.mjs +3 -2
  426. package/src/standalone/session-service/session-calls/session-action.mjs +51 -1
  427. package/src/standalone/session-service/session-calls/session-turns.mjs +37 -18
  428. package/src/standalone/session-service/session-calls/turn-gate.mjs +34 -0
  429. package/src/standalone/session-service/session-calls.mjs +2 -1
  430. package/src/tui/App.jsx +8 -0
  431. package/src/tui/app/clipboard.mjs +1 -1
  432. package/src/tui/app/create-app-pickers.mjs +2 -0
  433. package/src/tui/app/doctor.mjs +2 -2
  434. package/src/tui/app/model-picker/model-footer.mjs +1 -1
  435. package/src/tui/app/model-picker/provider-models-list.mjs +7 -3
  436. package/src/tui/app/model-picker/route-selection/fast-parameters.mjs +23 -3
  437. package/src/tui/app/model-picker/route-selection.mjs +1 -0
  438. package/src/tui/app/panel-signature.mjs +1 -1
  439. package/src/tui/app/settings-picker.mjs +53 -8
  440. package/src/tui/app/shell-layout/row-budgets.mjs +2 -2
  441. package/src/tui/app/slash-commands.mjs +1 -1
  442. package/src/tui/app/slash-dispatch/route-commands.mjs +1 -1
  443. package/src/tui/app/slash-dispatch/session-commands.mjs +1 -1
  444. package/src/tui/app/use-prompt-queue-history.mjs +2 -2
  445. package/src/tui/app/use-transcript-activity.mjs +1 -1
  446. package/src/tui/app/use-transcript-window/geometry.mjs +1 -1
  447. package/src/tui/components/prompt-input/escape-policy.d.mts +0 -1
  448. package/src/tui/components/prompt-input/escape-policy.mjs +1 -1
  449. package/src/tui/components/question-panel-model.mjs +4 -4
  450. package/src/tui/components/tool-execution/standard-card.jsx +3 -4
  451. package/src/tui/components/user-message-skills.mjs +1 -1
  452. package/src/tui/dist/index.mjs +350 -37
  453. package/src/tui/markdown/render-ansi.mjs +1 -1
  454. package/src/tui/session/agent-job-feed/notification-router.mjs +10 -0
  455. package/src/tui/session/agent-job-feed.mjs +2 -0
  456. package/src/tui/session/context-state.mjs +3 -0
  457. package/src/tui/session/quota-resume.mjs +1 -1
  458. package/src/tui/session/session-api/integrations.mjs +3 -0
  459. package/src/tui/session/session-api/lifecycle/dispose.mjs +1 -0
  460. package/src/tui/session/session-api/lifecycle/session-reset.mjs +7 -0
  461. package/src/tui/session/session-api/routes-agent-definitions.mjs +5 -0
  462. package/src/tui/session/session-api/worktree.mjs +13 -1
  463. package/src/tui/session/session-flow/drain.mjs +11 -14
  464. package/src/tui/session/tool-approval-settle.mjs +24 -4
  465. package/src/tui/session/tool-approval.mjs +35 -10
  466. package/src/tui/session/tool-card-results/grouped-result.mjs +2 -2
  467. package/src/tui/session/turn-quiet.mjs +1 -1
  468. package/src/tui/session/turn.mjs +3 -0
  469. package/src/tui/session/worktree-setup-notice.mjs +1 -1
  470. package/src/tui/spinner-meta.mjs +3 -3
  471. package/src/tui/spinner-verbs.mjs +2 -2
  472. package/src/defaults/skills/goal-management/SKILL.md +0 -169
  473. package/src/runtime/agent/orchestrator/runtime-core/goal-tasks.mjs +0 -156
  474. package/src/session-runtime/goal-tasks.mjs +0 -1
@@ -136,6 +136,23 @@ function refreshSessionFallbacks(deps, session) {
136
136
  deps.mgr.updateSessionRoute?.(session.id, fields, { session });
137
137
  }
138
138
 
139
+ /** The route fields a model pick held for the next turn keeps on its session. */
140
+ function heldRoutePick(route) {
141
+ const pick = {
142
+ provider: route.provider,
143
+ model: route.model,
144
+ ...(route.preset ? { preset: route.preset } : {}),
145
+ ...(route.effort !== undefined ? { effort: route.effort } : {}),
146
+ fast: route.fast === true,
147
+ ...(route.autoEffort === false ? { autoEffort: false } : {}),
148
+ ...(route.modelParameters ? { modelParameters: route.modelParameters } : {}),
149
+ ...(route.contextPercent !== undefined ? { contextPercent: route.contextPercent } : {}),
150
+ ...(route.contextTokens ? { contextTokens: route.contextTokens } : {}),
151
+ ...(route.selectedContextWindow ? { selectedContextWindow: route.selectedContextWindow } : {}),
152
+ };
153
+ return pick;
154
+ }
155
+
139
156
  /** Rewrite the addressed empty session to the route it was asked to run on. */
140
157
  function updateSessionInPlace(deps, session, updateOptions) {
141
158
  const { getRoute, getSession, setSession, mgr, statusRoutes } = deps;
@@ -386,9 +403,16 @@ export function createSetRoute(deps, persist) {
386
403
  const session = getSession();
387
404
  if (options.deferUntilNextTurn === true) {
388
405
  pending = session?.id ? { generation: lease.token } : null;
406
+ // Held on the session too (saved like a pending workflow switch), so a
407
+ // restart before the next turn still applies it.
408
+ if (session?.id) {
409
+ session.pendingRoute = heldRoutePick(getRoute());
410
+ deps.persistSession?.(session);
411
+ }
389
412
  return getRoute();
390
413
  }
391
414
  pending = null;
415
+ if (session?.pendingRoute) delete session.pendingRoute;
392
416
  // A session the user has already talked in or compacted keeps its route
393
417
  // unless the selection was addressed to it. A current session with no
394
418
  // model reply, no compaction summary and no in-flight first turn — empty,
@@ -436,21 +460,30 @@ export function createSetRoute(deps, persist) {
436
460
  return getRoute();
437
461
  }
438
462
  setRoute.applyPendingRoute = () => {
439
- if (!pending) return null;
440
- const selection = pending;
441
- if (selection.generation !== getSessionGeneration()) {
463
+ const session = getSession();
464
+ const held = session?.pendingRoute;
465
+ if (session && held) delete session.pendingRoute;
466
+ if (pending) {
467
+ const selection = pending;
442
468
  pending = null;
469
+ if (selection.generation !== getSessionGeneration()) return null;
470
+ // The live route is the latest selection: effort/Fast tuned after the
471
+ // deferred model choice replace it.
472
+ } else if (held?.provider && held.model) {
473
+ // Held by an earlier process (a restart in between): the saved pick
474
+ // becomes the live route again.
475
+ deps.setRouteState(deps.resolveRoute(deps.getConfig(), held));
476
+ } else {
443
477
  return null;
444
478
  }
445
- // The live route is the latest selection: effort/Fast tuned after the
446
- // deferred model choice replace it, so no snapshot is kept.
447
- const modelSwitch = switchSessionInPlace(deps, getSession());
479
+ const modelSwitch = switchSessionInPlace(deps, session);
448
480
  invalidateContextStatusCache();
449
- pending = null;
450
481
  return modelSwitch;
451
482
  };
452
483
  setRoute.clearPendingRoute = () => {
453
484
  pending = null;
485
+ const session = getSession();
486
+ if (session?.pendingRoute) delete session.pendingRoute;
454
487
  };
455
488
  return setRoute;
456
489
  }
@@ -46,9 +46,9 @@ export function createWebSearchRouteCandidates({
46
46
  await awaitKeychainPrewarm();
47
47
  const cfg = ensureFullConfig();
48
48
  // An unset webSearchRoute IS the default ("follow the Main Model") — the
49
- // sidebar has always presented it that way. Materialize it here instead of
50
- // treating a missing key as "not configured", which used to fail the search
51
- // before the Main Model was ever consulted.
49
+ // sidebar presents it that way. Materialize it here instead of treating a
50
+ // missing key as "not configured", which would fail the search before the
51
+ // Main Model is consulted.
52
52
  const webSearchRoute = webSearchRouteOrDefault(cfg.webSearchRoute, getWebSearchRoute());
53
53
  setWebSearchRoute(webSearchRoute);
54
54
  const candidates = [];
@@ -3,7 +3,7 @@
3
3
  import { resetProviderAdmissionCooldowns } from '../../runtime/agent/orchestrator/providers/admission-scheduler.mjs';
4
4
 
5
5
  export function createAuthRefresh({
6
- reloadFullConfig,
6
+ applyConfigChange,
7
7
  invalidateProviderCaches,
8
8
  warmProviderModelCache,
9
9
  refreshProviderCatalogs,
@@ -42,14 +42,17 @@ export function createAuthRefresh({
42
42
  warmProviderModelCache();
43
43
  }
44
44
 
45
+ // The change step (reload + effects keyed by the config/secret change) runs
46
+ // here at once rather than on the notification that follows, so this
47
+ // runtime's notification finds the change already applied.
45
48
  function afterCredentialChange() {
46
- reloadFullConfig();
49
+ applyConfigChange();
47
50
  adoptCredentials();
48
51
  }
49
52
 
50
53
  /** Usage-dashboard credentials affect no admission lane or catalog. */
51
54
  function afterUsageAuthChange() {
52
- reloadFullConfig();
55
+ applyConfigChange();
53
56
  invalidateProviderCaches();
54
57
  }
55
58
 
@@ -48,7 +48,7 @@ export function createSetupApi({
48
48
  return cachedProviderSetup({ force: force || options?.recheckKeychain === true });
49
49
  }
50
50
  // An unforced read never blocks: the authoritative setup waits on the OS
51
- // keychain, which can take seconds on a cold start and used to stall the
51
+ // keychain, which can take seconds on a cold start and would stall the
52
52
  // whole settings sweep behind it. Serve
53
53
  // the no-secrets snapshot until the real one is cached — flagged, so the
54
54
  // caller shows "checking" instead of a wrong "not connected" — and let the
@@ -14,6 +14,7 @@ import {
14
14
  effortConfigurationMode,
15
15
  } from '../../runtime/agent/orchestrator/providers/effort-configuration.mjs';
16
16
  import { getProvider } from '../../runtime/agent/orchestrator/providers/registry.mjs';
17
+ import { OPENROUTER_SORT_OPTION } from '../../runtime/agent/orchestrator/providers/openrouter-provider-routing.mjs';
17
18
  import { providerAvailable } from '../../runtime/agent/orchestrator/providers/provider-availability.mjs';
18
19
  import {
19
20
  DAYBREAK_PARAMETER_OPTION,
@@ -42,6 +43,7 @@ export function hydrateProviderModelRow(cfg, row) {
42
43
  const addedOptions = [
43
44
  ...(row.provider === DAYBREAK_PROVIDER && daybreakBlueSupported(row) ? [DAYBREAK_PARAMETER_OPTION] : []),
44
45
  ...(fastCapable && ultrafastCapableFor(row.provider, row) ? [ULTRAFAST_SPEED_OPTION] : []),
46
+ ...(row.provider === 'openrouter' ? [OPENROUTER_SORT_OPTION] : []),
45
47
  ];
46
48
  const modelParameterOptions = addedOptions.length
47
49
  ? [...existingOptions.filter((option) => !addedOptions.some((added) => added.id === option?.id)), ...addedOptions]
@@ -51,6 +51,13 @@ export function createProviderReadiness({ rt, keychain, getReg, getWarmProviderM
51
51
  const providerModelCaches = { ...emptyModelCaches(), providerModelsLoadSeq: 0 };
52
52
  const providerUsageCaches = emptyUsageCaches();
53
53
  const providerInitPromises = new Map();
54
+ // Whether this runtime has started its providers: a rebuild after a change
55
+ // follows it, a failed initialization (whose gate is dropped) included.
56
+ let providersStarted = false;
57
+ // Advances whenever the init gates are cleared (a provider config or
58
+ // credential change): an initialization registered before it is superseded
59
+ // and never writes the shared registry.
60
+ let providerInitGeneration = 0;
54
61
 
55
62
  function invalidateProviderCaches(options = {}) {
56
63
  // Auth/account/config changes alter what providers list: the process-wide
@@ -59,7 +66,10 @@ export function createProviderReadiness({ rt, keychain, getReg, getWarmProviderM
59
66
  Object.assign(providerModelCaches, emptyModelCaches());
60
67
  providerModelCaches.providerModelsLoadSeq += 1;
61
68
  Object.assign(providerUsageCaches, emptyUsageCaches());
62
- if (options.preserveProviderInit !== true) providerInitPromises.clear();
69
+ if (options.preserveProviderInit !== true) {
70
+ providerInitPromises.clear();
71
+ providerInitGeneration += 1;
72
+ }
63
73
  modelMetaByRoute.clear();
64
74
  }
65
75
 
@@ -67,19 +77,44 @@ export function createProviderReadiness({ rt, keychain, getReg, getWarmProviderM
67
77
  // absent (provider setup, init gates) is stale.
68
78
  keychain.onKeychainRecovered?.(() => invalidateProviderCaches());
69
79
 
70
- async function ensureProvidersReady(providerConfig = rt.config.providers || {}) {
80
+ // The one edit a caller makes to the provider config it passes is turning a
81
+ // route's provider on (ensureProviderEnabled); those providers, judged
82
+ // against the runtime's config when the request was made.
83
+ function forcedProviders(requested, base) {
84
+ return Object.keys(requested || {}).filter(
85
+ (name) => requested[name]?.enabled === true && base?.[name]?.enabled !== true
86
+ );
87
+ }
88
+
89
+ // Waits for the keychain, then initializes the registry with
90
+ // `providerConfig` unless a change superseded it meanwhile: a superseded
91
+ // request is replayed on the latest config (with the providers it turned on),
92
+ // so the latest config always wins.
93
+ async function initializeProviders(providerConfig) {
94
+ const generation = providerInitGeneration;
95
+ const forced = forcedProviders(providerConfig, rt.config.providers);
71
96
  await awaitKeychainPrewarm();
72
97
  if (rt.closeRequested) throw new Error('runtime is closing');
98
+ if (generation === providerInitGeneration) return getReg().initProviders(providerConfig);
99
+ const latest = { ...(rt.config.providers || {}) };
100
+ for (const name of forced) latest[name] = { ...(latest[name] || {}), enabled: true };
101
+ return ensureProvidersReady(latest);
102
+ }
103
+
104
+ async function ensureProvidersReady(providerConfig = rt.config.providers || {}) {
105
+ if (rt.closeRequested) throw new Error('runtime is closing');
106
+ providersStarted = true;
73
107
  const initKey = providerInitCacheKey(providerConfig);
74
108
  // Provider initialization is idempotent for one normalized config. Keep
75
109
  // the fulfilled promise, not only the in-flight one: session resume used
76
110
  // to rerun registry/keychain setup on every click even though neither the
77
111
  // provider config nor the registry had changed. Auth/config mutations call
78
112
  // invalidateProviderCaches(), which clears this gate and preserves the
79
- // existing refresh semantics.
113
+ // existing refresh semantics. Registered before any await, so a change
114
+ // applied while it waits on the keychain sees (and supersedes) it.
80
115
  let providerInitPromise = providerInitPromises.get(initKey);
81
116
  if (!providerInitPromise) {
82
- providerInitPromise = Promise.resolve().then(() => getReg().initProviders(providerConfig));
117
+ providerInitPromise = initializeProviders(providerConfig);
83
118
  providerInitPromises.set(initKey, providerInitPromise);
84
119
  }
85
120
  let result;
@@ -125,9 +160,23 @@ export function createProviderReadiness({ rt, keychain, getReg, getWarmProviderM
125
160
  return result;
126
161
  }
127
162
 
163
+ // Provider config or secrets changed: drop everything keyed to the old ones
164
+ // and, when this runtime had initialized providers, rebuild the shared
165
+ // registry from its reloaded config now, so no runtime's stale copy is the
166
+ // last one to have initialized it. Rejects when that rebuild failed.
167
+ function reinitProviders() {
168
+ invalidateProviderCaches();
169
+ if (!providersStarted || rt.closeRequested) return Promise.resolve();
170
+ return ensureProvidersReady().catch((error) => {
171
+ bootProfile('providers:reinit-failed', { error: error?.message || String(error) });
172
+ throw error;
173
+ });
174
+ }
175
+
128
176
  return {
129
177
  awaitKeychainPrewarm,
130
178
  invalidateProviderCaches,
179
+ reinitProviders,
131
180
  ensureProvidersReady,
132
181
  modelMetaByRoute,
133
182
  providerModelCaches,
@@ -31,7 +31,7 @@ export function createResourceApi(deps) {
31
31
  throw new Error(`extension scope kind must be one of ${EXTENSION_SCOPE_KINDS.join(', ')}`);
32
32
  }
33
33
  // A connector is on in every project unless a project switches it off
34
- // (setProjectConnectorEnabled); "only in this project" no longer exists.
34
+ // (setProjectConnectorEnabled); there is no "only in this project" scope.
35
35
  if (scopeKind === 'mcp') {
36
36
  throw new Error('MCP servers are switched off per project in Project settings (setProjectConnectorEnabled)');
37
37
  }
@@ -7,7 +7,6 @@ export function createExtensionSync({
7
7
  connectConfiguredMcp,
8
8
  cancelMcpLogin,
9
9
  invalidatePreSessionToolSurface,
10
- refreshEmptySessionToolPolicy,
11
10
  reloadFullConfig,
12
11
  invalidateSkills,
13
12
  }) {
@@ -19,14 +18,11 @@ export function createExtensionSync({
19
18
  // session.
20
19
  const mcpToggleChains = new Map(); // name -> { desired, running }
21
20
 
22
- async function refreshSurface(kind) {
21
+ // The invalidation moves the surface generation: an empty session rebuilds
22
+ // at its next turn start (reconcileTurnSettings); MCP has its own
23
+ // first-turn/late-tool reconciliation against the live connection registry.
24
+ async function refreshSurface() {
23
25
  invalidatePreSessionToolSurface();
24
- // Existing conversations retain their stable prompt/session identity.
25
- // Empty sessions can safely rebuild their policy in place; MCP has its own
26
- // first-turn/late-tool reconciliation against the live connection registry.
27
- if ((kind === 'skills' || kind === 'plugins') && typeof refreshEmptySessionToolPolicy === 'function') {
28
- await refreshEmptySessionToolPolicy();
29
- }
30
26
  }
31
27
 
32
28
  // Apply per-server MCP changes in order, then reconcile: a configured server
@@ -80,7 +80,9 @@ export function createConnectorAccountEdits({
80
80
  throw nameTakenError(servers, name);
81
81
  }
82
82
  const accountName = serverName ? freeName(servers, name) : name;
83
- const account = connectorAccountEntry(accountName, accountCfg);
83
+ // A fresh identity: a conversation that used a removed account of this
84
+ // name never takes this one for it (connector-accounts-mcp.mjs).
85
+ const account = { ...connectorAccountEntry(accountName, accountCfg), id: randomUUID() };
84
86
  // A sign-in is stored per exact URL: another account signing in at the
85
87
  // same URL gets its own key, so the two never share tokens.
86
88
  const asServer = connectorAccountServer({ connector }, account);
@@ -141,6 +143,8 @@ export function createConnectorAccountEdits({
141
143
  entry.name === account.name
142
144
  ? {
143
145
  ...connectorAccountEntry(account.name, next),
146
+ // An edit keeps the account's identity.
147
+ ...(entry.id ? { id: entry.id } : {}),
144
148
  ...(connectorAccountEnabled(entry) ? {} : { enabled: false }),
145
149
  }
146
150
  : entry
@@ -6,7 +6,7 @@ import {
6
6
  gmailAppPasswordValue,
7
7
  connectorAccountServers,
8
8
  } from '../runtime/shared/connector-catalog.mjs';
9
- import { forgetConnectorAccountHealth, retireConnectorAccount } from '../runtime/connectors/connector-accounts-mcp.mjs';
9
+ import { forgetConnectorAccountHealth } from '../runtime/connectors/connector-accounts-mcp.mjs';
10
10
  import { oauthCredentialOf } from './resource-mcp-servers.mjs';
11
11
 
12
12
  /** Every config `servers` connects with, a multi-account server's accounts
@@ -73,13 +73,13 @@ export function createMcpServerSecrets({
73
73
  await forgetUnusedGmailAppPassword(gmailAppPasswordAccount(cfg));
74
74
  if (!cfg?.url || !cfg.oauthClientId) return;
75
75
  const servers = expandedConfigs(resolveConfiguredMcpCatalog().servers);
76
- if (!servers.some((other) => other.url === cfg.url && other.oauthClientId)) await saveOAuthClientSecret(cfg.url, '');
76
+ if (!servers.some((other) => other.url === cfg.url && other.oauthClientId))
77
+ await saveOAuthClientSecret(cfg.url, '');
77
78
  };
78
79
  // A removed account keeps no sign-in another configured server or account
79
80
  // does not share: `{ signIn, revoked }` as removeMcpServer reports it.
80
81
  const releaseAccount = async (accountCfg) => {
81
82
  forgetConnectorAccountHealth(accountCfg.name);
82
- retireConnectorAccount(accountCfg.connector, accountCfg.name);
83
83
  const address = gmailAppPasswordAccount(accountCfg);
84
84
  if (address) {
85
85
  const forgotten = await forgetUnusedGmailAppPassword(address);
@@ -29,6 +29,7 @@ export function createPluginsResourceApi({ deps, sync, decorate }) {
29
29
  pluginsStatus,
30
30
  resolveMcpCatalog = () => ({ adoption: null }),
31
31
  flushSkillsSave,
32
+ invalidateSkills,
32
33
  } = deps;
33
34
  const pluginData = () => cfgMod.getPluginData?.();
34
35
 
@@ -59,6 +60,9 @@ export function createPluginsResourceApi({ deps, sync, decorate }) {
59
60
  return { plugin, status: pluginsStatus() };
60
61
  },
61
62
  async updatePlugin(plugin = {}) {
63
+ // Windows refuses to rename a directory holding an open recursive
64
+ // skill watch, so drop the watchers before the root is swapped.
65
+ invalidateSkills?.();
62
66
  const updated = registryUpdatePlugin(pluginKey(plugin), { dataDir: pluginData() });
63
67
  await adoptPluginServerCopies();
64
68
  await sync.reconcilePluginsAndAnnounce();
@@ -0,0 +1,152 @@
1
+ /**
2
+ * A routine (schedule or webhook) may name an executor: a workflow sub-agent
3
+ * (Worker, …) on its own configured route. Each fire is then carried out by
4
+ * that sub-agent first, headless and to its end, and only its final report
5
+ * goes to the owner bot's home thread, which relays it (routine-home-turn.mjs).
6
+ * No executor = the bot does the work itself, as before.
7
+ *
8
+ * The executor is a delegatable workflow agent: never a bot (contact agent) or
9
+ * Mixy, never one that is unknown or turned off — refused when the routine is
10
+ * saved (assertRoutineExecutor) and again when it fires (a sub-agent that
11
+ * disappeared or was turned off since fails the fire; nothing falls back).
12
+ *
13
+ * The run is unattended like the bot's own routine turn: it is created under a
14
+ * session id marked as that routine's run (held-requests.mjs markUnattendedRun)
15
+ * so the sub-agent's record carries the run stamp (human-gate/delegation.mjs):
16
+ * it never asks, payments and permanent deletes are refused
17
+ * (human-gate/run-policy.mjs). A sub-agent session has no `agent`, `session`
18
+ * or `ask_user` tool (AGENT_WORKER_DENIED_TOOLS), so it can start no task
19
+ * session and ask nobody.
20
+ */
21
+ import { randomUUID } from 'node:crypto';
22
+ import { MIXY_AGENT_ID } from '../runtime/agent/orchestrator/session/agent-home.mjs';
23
+ import {
24
+ BUILTIN_SLOT_AGENT_IDS,
25
+ normalizeWorkflowId,
26
+ } from '../runtime/agent/orchestrator/runtime-core/workflow-ids.mjs';
27
+ import { storeInlineDocumentPart, storeInlineImagePart } from '../runtime/attachments/store.mjs';
28
+ import { MIXY_BOT_ID } from '../runtime/shared/agent-store.mjs';
29
+ import { automationPromptContent } from '../runtime/shared/automation-attachments.mjs';
30
+ import { routineExecutorHeader } from '../runtime/shared/routine-trigger.mjs';
31
+ import { scheduleOwnerAgentId } from './agent-home-delivery.mjs';
32
+ import { markUnattendedRun } from './held-requests.mjs';
33
+
34
+ /** `routineExecutorProblem` codes and the error each one raises. */
35
+ export const ROUTINE_EXECUTOR_PROBLEMS = Object.freeze({
36
+ unknown: (id) => `executor agent "${id}" is not an available sub-agent: pick one from the workflow agents`,
37
+ 'not-agent': (id) =>
38
+ `executor agent "${id}" is a bot, not a workflow sub-agent: pick a sub-agent such as Worker, or leave it unset`,
39
+ disabled: (id) => `executor agent "${id}" is turned off: turn it on in the workflow agents or pick another`,
40
+ });
41
+
42
+ /** The stored form of an executor id: lower-cased with dashes; null for none. */
43
+ export function normalizeExecutorAgentId(value) {
44
+ const text = typeof value === 'string' ? value.trim() : '';
45
+ return text ? normalizeWorkflowId(text, text.toLowerCase()) : null;
46
+ }
47
+
48
+ async function defaultProbe(id) {
49
+ const [{ workflowHelpers }, { getPluginData, loadConfig }, { isAgentDisabled, isContactAgentId }] = await Promise.all(
50
+ [
51
+ import('./boot/shared.mjs'),
52
+ import('../runtime/agent/orchestrator/config.mjs'),
53
+ import('../runtime/shared/agent-route-config.mjs'),
54
+ ]
55
+ );
56
+ const dataDir = getPluginData();
57
+ // The fresh scan: an agent made a moment ago counts.
58
+ const listed = workflowHelpers.listCustomAgentIds(dataDir).includes(id) && !BUILTIN_SLOT_AGENT_IDS.has(id);
59
+ const definition = listed ? workflowHelpers.loadAgentDefinition(dataDir, id) : null;
60
+ return {
61
+ listed: Boolean(definition),
62
+ contact: Boolean(definition) && isContactAgentId(id, definition.kind),
63
+ disabled: isAgentDisabled(loadConfig({ secrets: false }), id),
64
+ };
65
+ }
66
+
67
+ /** Why `id` (normalized) cannot execute a routine: a ROUTINE_EXECUTOR_PROBLEMS
68
+ * code, '' when it can. `probe(id)` → `{ listed, contact, disabled }`. */
69
+ export async function routineExecutorProblem(id, probe = defaultProbe) {
70
+ if (id === MIXY_AGENT_ID || id === MIXY_BOT_ID) return 'not-agent';
71
+ const facts = await probe(id);
72
+ if (!facts.listed) return 'unknown';
73
+ if (facts.contact) return 'not-agent';
74
+ return facts.disabled ? 'disabled' : '';
75
+ }
76
+
77
+ /** The executor id to store for a save's `executorAgentId` (null/empty = none),
78
+ * or the error naming why it cannot be one. */
79
+ export async function assertRoutineExecutor(value, probe = defaultProbe) {
80
+ if (value == null) return null;
81
+ if (typeof value !== 'string') throw new Error('executorAgentId must be a sub-agent id (a string) or null');
82
+ const id = normalizeExecutorAgentId(value);
83
+ if (!id) return null;
84
+ const problem = await routineExecutorProblem(id, probe);
85
+ if (problem) throw new Error(ROUTINE_EXECUTOR_PROBLEMS[problem](id));
86
+ return id;
87
+ }
88
+
89
+ /** An inline image/PDF/Office part as the stored reference part a sub-agent's
90
+ * prompt may carry (handoff-attachments.mjs admits references only). */
91
+ const referencePart = (part) => (part.type === 'image' ? storeInlineImagePart(part) : storeInlineDocumentPart(part));
92
+
93
+ /**
94
+ * Carry out one fire of routine `name` with sub-agent `agentId` and resolve its
95
+ * final report (trimmed text). `prompt` is the routine's instructions (plus a
96
+ * webhook's fenced payload); `ownerAgentId` the bot whose run it is. Rejects
97
+ * when the executor is no longer valid, fails, is cancelled, or `signal` aborts.
98
+ */
99
+ export async function runRoutineExecutor(
100
+ {
101
+ agentId,
102
+ kind,
103
+ name,
104
+ ownerAgentId = null,
105
+ prompt,
106
+ // The trusted part of `prompt` (the routine's instructions): the only text
107
+ // the executor's skills are selected from, never a webhook payload.
108
+ skillSelection = '',
109
+ attachments = null,
110
+ cwd = null,
111
+ signal = null,
112
+ },
113
+ { surface, probe = defaultProbe } = {}
114
+ ) {
115
+ const problem = await routineExecutorProblem(agentId, probe);
116
+ if (problem) throw new Error(`${kind} "${name}" cannot run: ${ROUTINE_EXECUTOR_PROBLEMS[problem](agentId)}`);
117
+ if (typeof surface?.runAgent !== 'function') throw new Error('routine run: the agent service is not running');
118
+ const header = routineExecutorHeader({ kind, name, project: cwd ? String(cwd) : '' });
119
+ const content = automationPromptContent(`${header}\n\n${prompt}`, attachments);
120
+ const parts = Array.isArray(content) ? content : [{ type: 'text', text: content }];
121
+ const attachmentParts = parts.slice(1).map(referencePart).filter(Boolean);
122
+ // The id the executor is created under: marked as this routine's unattended
123
+ // run for as long as it works (its record keeps the run stamp afterwards).
124
+ const parentSessionId = `routine_exec_${randomUUID()}`;
125
+ const unmark = markUnattendedRun(parentSessionId, {
126
+ kind,
127
+ agentId: scheduleOwnerAgentId({ ownerAgentId }),
128
+ name,
129
+ });
130
+ try {
131
+ const result = await surface.runAgent(
132
+ {
133
+ agent: agentId,
134
+ prompt: parts[0].text,
135
+ skillSelection: String(skillSelection ?? ''),
136
+ ...(cwd ? { cwd: String(cwd) } : {}),
137
+ ...(attachmentParts.length ? { attachmentParts } : {}),
138
+ },
139
+ { callerSessionId: parentSessionId },
140
+ { signal }
141
+ );
142
+ return String(result?.content ?? '').trim();
143
+ } catch (error) {
144
+ // The caller's own cancellation stays as it is.
145
+ if (signal?.aborted) throw error;
146
+ throw new Error(`${kind} "${name}": executor agent "${agentId}" failed: ${error?.message || error}`, {
147
+ cause: error,
148
+ });
149
+ } finally {
150
+ unmark();
151
+ }
152
+ }
@@ -14,7 +14,10 @@
14
14
  * (outbound actions are allowed within the bot's permissions; payments and
15
15
  * permanent deletes are refused, human-gate/run-policy.mjs). Resolves with the
16
16
  * reply once the turn ends; rejects when the turn fails, is cancelled, or the
17
- * caller's `signal` aborts (which also aborts the turn once it runs). A
17
+ * caller's `signal` aborts (which also aborts the turn once it runs). With an
18
+ * `executorAgentId` the fire is first carried out by that sub-agent
19
+ * (routine-executor.mjs) and the turn holds only its final report, which the
20
+ * bot relays; the quiet marker as the report wakes nobody and resolves it. A
18
21
  * heartbeat turn past its wall-clock cap is aborted and resolves with no reply
19
22
  * (`timedOut`).
20
23
  */
@@ -25,12 +28,16 @@ import { automationPromptContent } from '../runtime/shared/automation-attachment
25
28
  import { ROUTINE_LIMITS } from '../runtime/shared/routine-limits.mjs';
26
29
  import {
27
30
  HEARTBEAT_TURN_LIMITS,
31
+ ROUTINE_QUIET,
28
32
  isHeartbeatSession,
33
+ isRoutineQuietReply,
29
34
  normalizeRoutineTrigger,
35
+ routineRelayHeader,
30
36
  routineTriggerHeader,
31
37
  } from '../runtime/shared/routine-trigger.mjs';
32
38
  import { agentHomeLiveSurface, scheduleOwnerAgentId } from './agent-home-delivery.mjs';
33
39
  import { markUnattendedRun, unattendedRunOf } from './held-requests.mjs';
40
+ import { runRoutineExecutor } from './routine-executor.mjs';
34
41
 
35
42
  // Routine turns waiting or running per home thread.
36
43
  const waiting = new Map();
@@ -72,6 +79,9 @@ export async function runRoutineTurn(
72
79
  // thread and the routine trigger header.
73
80
  sessionId = null,
74
81
  header = null,
82
+ // A workflow sub-agent that carries the fire out first (routine-executor.mjs):
83
+ // the bot's turn then holds only its final report, for the bot to relay.
84
+ executorAgentId = null,
75
85
  },
76
86
  {
77
87
  surface = agentHomeLiveSurface(),
@@ -79,9 +89,10 @@ export async function runRoutineTurn(
79
89
  limit = ROUTINE_LIMITS.homeQueueLimit,
80
90
  log = (line) => process.stderr.write(`mixdog routines: ${line}\n`),
81
91
  timers = globalThis,
92
+ executor = runRoutineExecutor,
82
93
  } = {}
83
94
  ) {
84
- const body = String(prompt || '').trim();
95
+ let body = String(prompt || '').trim();
85
96
  if (!body) throw new Error(`${kind} "${name}" has no instructions`);
86
97
  if (signal?.aborted) throw abortError(signal);
87
98
  if (typeof surface?.submit !== 'function') throw new Error('routine run: the session service is not running');
@@ -91,12 +102,42 @@ export async function runRoutineTurn(
91
102
  if (!home || home.closed === true) {
92
103
  throw new Error(`the bot "${agentId}" has no chat yet: open it once in the app`);
93
104
  }
105
+ let opening = header || routineTriggerHeader({ kind, name, project: cwd ? String(cwd) : '' });
106
+ let selection = String(skillSelection ?? body);
107
+ let turnAttachments = attachments;
108
+ if (executorAgentId) {
109
+ const report = String(
110
+ (await executor(
111
+ {
112
+ agentId: executorAgentId,
113
+ kind,
114
+ name,
115
+ ownerAgentId: agentId,
116
+ prompt: body,
117
+ skillSelection: selection,
118
+ attachments,
119
+ cwd,
120
+ signal,
121
+ },
122
+ { surface }
123
+ )) ?? ''
124
+ ).trim();
125
+ if (signal?.aborted) throw abortError(signal);
126
+ if (!report) throw new Error(`${kind} "${name}": executor agent "${executorAgentId}" returned no report`);
127
+ // Nothing to tell: the bot is not woken.
128
+ if (isRoutineQuietReply(report)) return { sessionId: homeId, result: ROUTINE_QUIET };
129
+ // The bot only relays the report: it is derived from whatever the executor
130
+ // read (a webhook's payload included), so it selects no skill.
131
+ body = report;
132
+ opening = routineRelayHeader({ kind, name, executor: executorAgentId, project: cwd ? String(cwd) : '' });
133
+ selection = '';
134
+ turnAttachments = null;
135
+ }
94
136
  const queued = waiting.get(homeId) || 0;
95
137
  if (queued >= limit) throw new Error(`${limit} routine runs already wait in this bot's chat`);
96
138
  waiting.set(homeId, queued + 1);
97
139
  const trigger = normalizeRoutineTrigger({ kind, name, event });
98
- const opening = header || routineTriggerHeader({ kind, name, project: cwd ? String(cwd) : '' });
99
- const content = automationPromptContent(`${opening}\n\n${body}`, attachments);
140
+ const content = automationPromptContent(`${opening}\n\n${body}`, turnAttachments);
100
141
  return new Promise((resolve, reject) => {
101
142
  let started = false;
102
143
  let aborted = false;
@@ -150,7 +191,7 @@ export async function runRoutineTurn(
150
191
  restorable: false,
151
192
  // Esc ends this fire; it is never put back in the queue.
152
193
  abortDiscardOnAbort: true,
153
- skillSelection: String(skillSelection ?? body),
194
+ skillSelection: selection,
154
195
  transcriptMeta: { routineTrigger: trigger },
155
196
  onCommitted: () => {
156
197
  if (started) return;
@@ -2,8 +2,10 @@
2
2
  * Routines are bot-based: a schedule or webhook runs in its owner bot's home
3
3
  * thread (routine-home-turn.mjs) and nowhere else. An owner that does not
4
4
  * exist — Mixy before the representative bot was created, a bot archived or
5
- * deleted — makes the routine paused: it does not fire, the lists show why,
6
- * and a new routine cannot name it.
5
+ * deleted — makes the routine paused: it does not fire and a new routine
6
+ * cannot name it. An archived bot's routines are also hidden from the lists
7
+ * and come back, untouched, when it is restored; deleting it for good deletes
8
+ * them (agent-editor.mjs). The lists show why any other one is paused.
7
9
  */
8
10
  import { MIXY_AGENT_ID } from '../runtime/agent/orchestrator/session/agent-home.mjs';
9
11
  import { mixyExists } from '../runtime/shared/mixy-presence.mjs';
@@ -12,6 +14,7 @@ import { scheduleOwnerAgentId } from './agent-home-delivery.mjs';
12
14
  /** `ownerProblem` codes and the error each one raises. */
13
15
  export const ROUTINE_OWNER_PROBLEMS = Object.freeze({
14
16
  'no-mixy': 'Create the representative bot first.',
17
+ 'owner-archived': 'The bot that owns this routine is deleted (in Archived). Restore it, or pick another bot.',
15
18
  'owner-deleted': 'The bot that owns this routine no longer exists. Pick another bot.',
16
19
  });
17
20
 
@@ -56,6 +59,7 @@ async function defaultProbe() {
56
59
  return {
57
60
  mixyExists: (ownsRoutine) => readMixyExists(null, { ownsRoutine }),
58
61
  presence: (agentId) => api.agentDefinitionPresence([agentId])[agentId],
62
+ archived: (agentId) => Boolean(api.archivedAgentIdentities([agentId])[agentId]),
59
63
  };
60
64
  }
61
65
 
@@ -69,7 +73,9 @@ export async function routineOwnerProblem(ownerAgentId, probe = null, { stored =
69
73
  const owner = scheduleOwnerAgentId({ ownerAgentId });
70
74
  const check = probe || (await defaultProbe());
71
75
  if (owner === MIXY_AGENT_ID) return (await check.mixyExists(stored)) ? '' : 'no-mixy';
72
- return check.presence(owner) === 'deleted' ? 'owner-deleted' : '';
76
+ if (check.presence(owner) !== 'deleted') return '';
77
+ // Archived (restorable): its routines wait, hidden, for the restore.
78
+ return check.archived?.(owner) ? 'owner-archived' : 'owner-deleted';
73
79
  }
74
80
 
75
81
  /** Rejects with the owner's problem; resolves when it can own a routine. */