@ljwei-stak/dsh-model-route-bot 0.0.0-stage → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. package/.dsh-plugin/bot-product.mjs +127 -0
  2. package/.dsh-plugin/client.js +35145 -0
  3. package/.dsh-plugin/index.mjs +9 -0
  4. package/.dsh-plugin/official-tools-remote-service.mjs +281 -0
  5. package/.dsh-plugin/router-core.mjs +2779 -0
  6. package/.dsh-plugin/shared/adaptive-feedback.mjs +272 -0
  7. package/.dsh-plugin/shared/assignment-solver.mjs +286 -0
  8. package/.dsh-plugin/shared/attention.mjs +79 -0
  9. package/.dsh-plugin/shared/budget-reservations.mjs +287 -0
  10. package/.dsh-plugin/shared/capability-union.mjs +32 -0
  11. package/.dsh-plugin/shared/cli-profiles.mjs +70 -0
  12. package/.dsh-plugin/shared/cli-terminal-protocol.mjs +152 -0
  13. package/.dsh-plugin/shared/cli-terminal.mjs +697 -0
  14. package/.dsh-plugin/shared/dynamic-data-view.mjs +120 -0
  15. package/.dsh-plugin/shared/dynamic-data.mjs +372 -0
  16. package/.dsh-plugin/shared/execution-accounting.mjs +61 -0
  17. package/.dsh-plugin/shared/execution-lifecycle.mjs +169 -0
  18. package/.dsh-plugin/shared/harness-plan.mjs +199 -0
  19. package/.dsh-plugin/shared/latest-versions.mjs +232 -0
  20. package/.dsh-plugin/shared/ledgers.mjs +87 -0
  21. package/.dsh-plugin/shared/legacy-policy.mjs +56 -0
  22. package/.dsh-plugin/shared/library-tools.mjs +69 -0
  23. package/.dsh-plugin/shared/livebench.mjs +301 -0
  24. package/.dsh-plugin/shared/manual-plan.mjs +143 -0
  25. package/.dsh-plugin/shared/model-profiles.mjs +148 -0
  26. package/.dsh-plugin/shared/npm-attestation.mjs +319 -0
  27. package/.dsh-plugin/shared/official-team-runtime.mjs +623 -0
  28. package/.dsh-plugin/shared/official-tool-executor.mjs +1321 -0
  29. package/.dsh-plugin/shared/official-tool-registry.mjs +577 -0
  30. package/.dsh-plugin/shared/official-tools-remote.mjs +352 -0
  31. package/.dsh-plugin/shared/official-tools-runtime.mjs +1745 -0
  32. package/.dsh-plugin/shared/package-assignments.mjs +71 -0
  33. package/.dsh-plugin/shared/quality-gates.mjs +169 -0
  34. package/.dsh-plugin/shared/read-only-guard.mjs +41 -0
  35. package/.dsh-plugin/shared/reasoning-execution.mjs +92 -0
  36. package/.dsh-plugin/shared/router-state.mjs +431 -0
  37. package/.dsh-plugin/shared/router.mjs +1209 -0
  38. package/.dsh-plugin/shared/routing-evidence.mjs +720 -0
  39. package/.dsh-plugin/shared/routing-presets.mjs +49 -0
  40. package/.dsh-plugin/shared/run-jobs.mjs +169 -0
  41. package/.dsh-plugin/shared/run-ledger.mjs +588 -0
  42. package/.dsh-plugin/shared/security-boundaries.mjs +54 -0
  43. package/.dsh-plugin/shared/subscription-billing.mjs +340 -0
  44. package/.dsh-plugin/shared/subscription-usage.mjs +210 -0
  45. package/.dsh-plugin/shared/task-executors.mjs +1555 -0
  46. package/.dsh-plugin/shared/tool-health.mjs +357 -0
  47. package/.dsh-plugin/shared/tool-install-preferences.mjs +390 -0
  48. package/.dsh-plugin/shared/tool-prerequisites.mjs +70 -0
  49. package/.dsh-plugin/shared/tui-executor.mjs +110 -0
  50. package/.dsh-plugin/shared/vendor-mimo-grok-adapter.mjs +351 -0
  51. package/.dsh-plugin/shared/vendor-minimax-adapter.mjs +247 -0
  52. package/.dsh-plugin/shared/version-order.mjs +30 -0
  53. package/.dsh-plugin/shared/zcode-bundle.mjs +93 -0
  54. package/.dsh-plugin/shared/zcode-installer.mjs +274 -0
  55. package/.dsh-plugin/shared/zcode-npm-shims.mjs +140 -0
  56. package/.dsh-plugin/shared/zcode-npm.mjs +177 -0
  57. package/CHANGELOG.md +456 -0
  58. package/LICENSE +21 -0
  59. package/README.i18n.yaml +4 -0
  60. package/README.md +301 -2
  61. package/README.zh.md +302 -0
  62. package/apps/integration-client/README.md +30 -0
  63. package/apps/integration-client/api.mjs +24 -0
  64. package/apps/integration-client/binding-editor.jsx +118 -0
  65. package/apps/integration-client/bot-attention.mjs +94 -0
  66. package/apps/integration-client/desktop-bridge.mjs +23 -0
  67. package/apps/integration-client/desktop-pane.jsx +209 -0
  68. package/apps/integration-client/desktop-stream.mjs +88 -0
  69. package/apps/integration-client/index.jsx +56 -0
  70. package/apps/integration-client/library-panel.jsx +139 -0
  71. package/apps/integration-client/pairing.mjs +113 -0
  72. package/apps/integration-client/panels.jsx +850 -0
  73. package/apps/integration-client/product.css +290 -0
  74. package/apps/integration-client/routine-recorder.mjs +97 -0
  75. package/apps/integration-client/routines-panel.jsx +126 -0
  76. package/apps/integration-client/ui-icons.jsx +32 -0
  77. package/cordis.patch.yml +17 -0
  78. package/deploy/remote-agent/Dockerfile +10 -0
  79. package/deploy/remote-agent/README.md +36 -0
  80. package/deploy/remote-agent/install-linux.sh +22 -0
  81. package/deploy/remote-agent/install-windows.ps1 +43 -0
  82. package/deploy/remote-agent/remote-agent.service.example +22 -0
  83. package/docs/INSTALLATION_GUIDE.zh.md +150 -0
  84. package/docs/MANUAL_TASK_ASSIGNMENT.zh.md +46 -0
  85. package/docs/ROUTING_ADAPTIVE_LEARNING.zh.md +153 -0
  86. package/docs/ROUTING_ALGORITHM_OPTIMIZATION.zh.md +91 -0
  87. package/docs/ROUTING_DERIVATION_EXPERIMENTS.zh.md +684 -0
  88. package/docs/ROUTING_LIVEBENCH_DATA_SEARCH.zh.md +74 -0
  89. package/docs/ROUTING_LIVEBENCH_VALIDATION.zh.md +154 -0
  90. package/docs/ROUTING_MATURITY.zh.md +76 -0
  91. package/docs/ROUTING_RESEARCH.zh.md +59 -0
  92. package/docs/ROUTING_SELFTEST_STEPS.zh.md +192 -0
  93. package/docs/WORKBENCH_USER_GUIDE.zh.md +293 -0
  94. package/docs/archive/MIGRATION.md +53 -0
  95. package/docs/archive/README.md +21 -0
  96. package/docs/assets/candidate-pruning.svg +80 -0
  97. package/docs/assets/desktop-official-tools-0.9.0.png +0 -0
  98. package/docs/assets/router-only-0.12.0.png +0 -0
  99. package/docs/assets/routing-workflow.svg +96 -0
  100. package/docs/assets/workbench-budget-reservations.png +0 -0
  101. package/docs/assets/workbench-run-progress.png +0 -0
  102. package/docs/assets/workbench-run-timeout.png +0 -0
  103. package/docs/assets/workbench-subscription-usage.png +0 -0
  104. package/docs/assets/workbench-task-preview.jpg +0 -0
  105. package/docs/assets/workbench-usage.svg +119 -0
  106. package/docs/releases/0.20.0-validation.md +26 -0
  107. package/docs/releases/0.22.0-validation.md +28 -0
  108. package/docs/releases/0.23.0-validation.md +30 -0
  109. package/docs/releases/0.23.1-validation.md +23 -0
  110. package/docs/releases/0.24.0-validation.md +41 -0
  111. package/docs/releases/0.25.0-validation.md +41 -0
  112. package/docs/releases/0.25.1-validation.md +36 -0
  113. package/docs/releases/0.25.2-validation.md +48 -0
  114. package/docs/releases/0.25.3-validation.md +50 -0
  115. package/docs/releases/0.25.4-validation.md +41 -0
  116. package/docs/releases/0.25.5-validation.md +40 -0
  117. package/docs/releases/0.26.0-preview.0-validation.md +23 -0
  118. package/docs/releases/0.26.0-preview.1-f-difference.json +6845 -0
  119. package/docs/releases/0.26.0-preview.1-f-difference.md +85 -0
  120. package/docs/releases/0.26.0-preview.1-validation.md +103 -0
  121. package/docs/releases/0.63.0-validation.md +51 -0
  122. package/modules/bot-runtime/README.md +123 -0
  123. package/modules/bot-runtime/SOURCE.json +2591 -0
  124. package/modules/bot-runtime/index.mjs +81 -0
  125. package/modules/bot-runtime/policy-scope.mjs +15 -0
  126. package/modules/bot-runtime/product-overlay/OVERLAY.json +58 -0
  127. package/modules/bot-runtime/product-overlay/README.md +55 -0
  128. package/modules/bot-runtime/product-overlay/base/src/client/details-drawer.js +310 -0
  129. package/modules/bot-runtime/product-overlay/base/src/client/index.js +1120 -0
  130. package/modules/bot-runtime/product-overlay/base/src/client/sidebar.js +1130 -0
  131. package/modules/bot-runtime/product-overlay/base/src/host/schedules.js +154 -0
  132. package/modules/bot-runtime/product-overlay/base/src/host/tools.js +1105 -0
  133. package/modules/bot-runtime/product-overlay/files/src/client/desktop-pane.js +181 -0
  134. package/modules/bot-runtime/product-overlay/patches/src/client/details-drawer.js.patch +37 -0
  135. package/modules/bot-runtime/product-overlay/patches/src/client/index.js.patch +11 -0
  136. package/modules/bot-runtime/product-overlay/patches/src/client/sidebar.js.patch +10 -0
  137. package/modules/bot-runtime/product-overlay/patches/src/host/schedules.js.patch +17 -0
  138. package/modules/bot-runtime/product-overlay/patches/src/host/tools.js.patch +11 -0
  139. package/modules/bot-runtime/read-model.mjs +102 -0
  140. package/modules/bot-runtime/schedule-compat.mjs +25 -0
  141. package/modules/bot-runtime/vendor/ds-bot/LICENSE +201 -0
  142. package/modules/bot-runtime/vendor/ds-bot/README.md +258 -0
  143. package/modules/bot-runtime/vendor/ds-bot/UPSTREAM_LICENSE +201 -0
  144. package/modules/bot-runtime/vendor/ds-bot/UPSTREAM_NOTICE +135 -0
  145. package/modules/bot-runtime/vendor/ds-bot/cordis.patch.yml +19 -0
  146. package/modules/bot-runtime/vendor/ds-bot/index.js +82 -0
  147. package/modules/bot-runtime/vendor/ds-bot/office.js +8889 -0
  148. package/modules/bot-runtime/vendor/ds-bot/package.json +73 -0
  149. package/modules/bot-runtime/vendor/ds-bot/src/client/about.js +160 -0
  150. package/modules/bot-runtime/vendor/ds-bot/src/client/activity-row.js +195 -0
  151. package/modules/bot-runtime/vendor/ds-bot/src/client/api.js +42 -0
  152. package/modules/bot-runtime/vendor/ds-bot/src/client/approval-notices.js +36 -0
  153. package/modules/bot-runtime/vendor/ds-bot/src/client/at-menu.js +115 -0
  154. package/modules/bot-runtime/vendor/ds-bot/src/client/avatar-library.js +159 -0
  155. package/modules/bot-runtime/vendor/ds-bot/src/client/bot-browsers.js +642 -0
  156. package/modules/bot-runtime/vendor/ds-bot/src/client/bot-draft.js +25 -0
  157. package/modules/bot-runtime/vendor/ds-bot/src/client/bot-settings.js +294 -0
  158. package/modules/bot-runtime/vendor/ds-bot/src/client/browser-overlap.js +4 -0
  159. package/modules/bot-runtime/vendor/ds-bot/src/client/browser-pane.js +869 -0
  160. package/modules/bot-runtime/vendor/ds-bot/src/client/browser-settings.js +129 -0
  161. package/modules/bot-runtime/vendor/ds-bot/src/client/btw-model.js +266 -0
  162. package/modules/bot-runtime/vendor/ds-bot/src/client/btw.js +105 -0
  163. package/modules/bot-runtime/vendor/ds-bot/src/client/capability-settings.js +166 -0
  164. package/modules/bot-runtime/vendor/ds-bot/src/client/card-hold.js +18 -0
  165. package/modules/bot-runtime/vendor/ds-bot/src/client/cell-empty.js +38 -0
  166. package/modules/bot-runtime/vendor/ds-bot/src/client/cells.js +1149 -0
  167. package/modules/bot-runtime/vendor/ds-bot/src/client/characters.js +136 -0
  168. package/modules/bot-runtime/vendor/ds-bot/src/client/composer.js +218 -0
  169. package/modules/bot-runtime/vendor/ds-bot/src/client/connectors.js +66 -0
  170. package/modules/bot-runtime/vendor/ds-bot/src/client/context-menu.js +97 -0
  171. package/modules/bot-runtime/vendor/ds-bot/src/client/create-bot.js +107 -0
  172. package/modules/bot-runtime/vendor/ds-bot/src/client/desktop-pane.js +181 -0
  173. package/modules/bot-runtime/vendor/ds-bot/src/client/details-drawer.js +312 -0
  174. package/modules/bot-runtime/vendor/ds-bot/src/client/diagnostics.js +93 -0
  175. package/modules/bot-runtime/vendor/ds-bot/src/client/dsh-offer.js +14 -0
  176. package/modules/bot-runtime/vendor/ds-bot/src/client/dsh-primitives.js +3 -0
  177. package/modules/bot-runtime/vendor/ds-bot/src/client/enter-key.js +20 -0
  178. package/modules/bot-runtime/vendor/ds-bot/src/client/enter-steer.js +37 -0
  179. package/modules/bot-runtime/vendor/ds-bot/src/client/exchange.js +75 -0
  180. package/modules/bot-runtime/vendor/ds-bot/src/client/feedback.js +183 -0
  181. package/modules/bot-runtime/vendor/ds-bot/src/client/fold.js +154 -0
  182. package/modules/bot-runtime/vendor/ds-bot/src/client/folder-menu.js +112 -0
  183. package/modules/bot-runtime/vendor/ds-bot/src/client/frame-layout.js +90 -0
  184. package/modules/bot-runtime/vendor/ds-bot/src/client/frame-watch.js +109 -0
  185. package/modules/bot-runtime/vendor/ds-bot/src/client/goal.js +403 -0
  186. package/modules/bot-runtime/vendor/ds-bot/src/client/group-settings.js +180 -0
  187. package/modules/bot-runtime/vendor/ds-bot/src/client/handoff-card.js +132 -0
  188. package/modules/bot-runtime/vendor/ds-bot/src/client/header-navigation.js +36 -0
  189. package/modules/bot-runtime/vendor/ds-bot/src/client/header.js +244 -0
  190. package/modules/bot-runtime/vendor/ds-bot/src/client/i18n.js +1324 -0
  191. package/modules/bot-runtime/vendor/ds-bot/src/client/icons.js +105 -0
  192. package/modules/bot-runtime/vendor/ds-bot/src/client/index.js +1120 -0
  193. package/modules/bot-runtime/vendor/ds-bot/src/client/inks.js +27 -0
  194. package/modules/bot-runtime/vendor/ds-bot/src/client/kept-private.js +26 -0
  195. package/modules/bot-runtime/vendor/ds-bot/src/client/learning-card-model.js +66 -0
  196. package/modules/bot-runtime/vendor/ds-bot/src/client/learning-card.js +202 -0
  197. package/modules/bot-runtime/vendor/ds-bot/src/client/mark.js +170 -0
  198. package/modules/bot-runtime/vendor/ds-bot/src/client/member-status.js +254 -0
  199. package/modules/bot-runtime/vendor/ds-bot/src/client/memory-panel.js +373 -0
  200. package/modules/bot-runtime/vendor/ds-bot/src/client/model-menu.js +371 -0
  201. package/modules/bot-runtime/vendor/ds-bot/src/client/motion.js +245 -0
  202. package/modules/bot-runtime/vendor/ds-bot/src/client/new-chat.js +181 -0
  203. package/modules/bot-runtime/vendor/ds-bot/src/client/open-listed.js +27 -0
  204. package/modules/bot-runtime/vendor/ds-bot/src/client/overlay-hooks.js +31 -0
  205. package/modules/bot-runtime/vendor/ds-bot/src/client/overlays.js +70 -0
  206. package/modules/bot-runtime/vendor/ds-bot/src/client/palette.js +141 -0
  207. package/modules/bot-runtime/vendor/ds-bot/src/client/permission-picker.js +47 -0
  208. package/modules/bot-runtime/vendor/ds-bot/src/client/providers-page.js +196 -0
  209. package/modules/bot-runtime/vendor/ds-bot/src/client/questions.js +233 -0
  210. package/modules/bot-runtime/vendor/ds-bot/src/client/read-page.js +335 -0
  211. package/modules/bot-runtime/vendor/ds-bot/src/client/right-panel.js +49 -0
  212. package/modules/bot-runtime/vendor/ds-bot/src/client/schedules.js +290 -0
  213. package/modules/bot-runtime/vendor/ds-bot/src/client/secret-card.js +363 -0
  214. package/modules/bot-runtime/vendor/ds-bot/src/client/settings.js +310 -0
  215. package/modules/bot-runtime/vendor/ds-bot/src/client/shared-map.js +65 -0
  216. package/modules/bot-runtime/vendor/ds-bot/src/client/side-chat.js +157 -0
  217. package/modules/bot-runtime/vendor/ds-bot/src/client/side-model.js +171 -0
  218. package/modules/bot-runtime/vendor/ds-bot/src/client/sidebar.js +1131 -0
  219. package/modules/bot-runtime/vendor/ds-bot/src/client/sources.js +68 -0
  220. package/modules/bot-runtime/vendor/ds-bot/src/client/speech.js +162 -0
  221. package/modules/bot-runtime/vendor/ds-bot/src/client/storage.js +72 -0
  222. package/modules/bot-runtime/vendor/ds-bot/src/client/styles.js +1324 -0
  223. package/modules/bot-runtime/vendor/ds-bot/src/client/surface.js +94 -0
  224. package/modules/bot-runtime/vendor/ds-bot/src/client/team-actions.js +218 -0
  225. package/modules/bot-runtime/vendor/ds-bot/src/client/text.js +291 -0
  226. package/modules/bot-runtime/vendor/ds-bot/src/client/themes.js +128 -0
  227. package/modules/bot-runtime/vendor/ds-bot/src/client/turn-error.js +260 -0
  228. package/modules/bot-runtime/vendor/ds-bot/src/client/turn-reasoning.js +38 -0
  229. package/modules/bot-runtime/vendor/ds-bot/src/client/usage-data.js +159 -0
  230. package/modules/bot-runtime/vendor/ds-bot/src/client/usage-page.js +760 -0
  231. package/modules/bot-runtime/vendor/ds-bot/src/client/user-message.js +139 -0
  232. package/modules/bot-runtime/vendor/ds-bot/src/client/voice.js +300 -0
  233. package/modules/bot-runtime/vendor/ds-bot/src/client/widget-cell.js +138 -0
  234. package/modules/bot-runtime/vendor/ds-bot/src/host/agents.js +129 -0
  235. package/modules/bot-runtime/vendor/ds-bot/src/host/approvals.js +69 -0
  236. package/modules/bot-runtime/vendor/ds-bot/src/host/avatar-library.js +131 -0
  237. package/modules/bot-runtime/vendor/ds-bot/src/host/avatar.js +107 -0
  238. package/modules/bot-runtime/vendor/ds-bot/src/host/browser/gate.js +3 -0
  239. package/modules/bot-runtime/vendor/ds-bot/src/host/browser/loop.js +95 -0
  240. package/modules/bot-runtime/vendor/ds-bot/src/host/browser/mount.js +177 -0
  241. package/modules/bot-runtime/vendor/ds-bot/src/host/browser/refs.js +151 -0
  242. package/modules/bot-runtime/vendor/ds-bot/src/host/browser/script.js +38 -0
  243. package/modules/bot-runtime/vendor/ds-bot/src/host/browser/session-model.js +205 -0
  244. package/modules/bot-runtime/vendor/ds-bot/src/host/browser/session.js +765 -0
  245. package/modules/bot-runtime/vendor/ds-bot/src/host/browser/task.js +64 -0
  246. package/modules/bot-runtime/vendor/ds-bot/src/host/browser-plugins.js +174 -0
  247. package/modules/bot-runtime/vendor/ds-bot/src/host/browser.js +287 -0
  248. package/modules/bot-runtime/vendor/ds-bot/src/host/btw.js +372 -0
  249. package/modules/bot-runtime/vendor/ds-bot/src/host/capabilities.js +542 -0
  250. package/modules/bot-runtime/vendor/ds-bot/src/host/channel.js +647 -0
  251. package/modules/bot-runtime/vendor/ds-bot/src/host/chat-index.js +293 -0
  252. package/modules/bot-runtime/vendor/ds-bot/src/host/connectors.js +169 -0
  253. package/modules/bot-runtime/vendor/ds-bot/src/host/constants.js +96 -0
  254. package/modules/bot-runtime/vendor/ds-bot/src/host/delivery.js +171 -0
  255. package/modules/bot-runtime/vendor/ds-bot/src/host/diagnostics.js +257 -0
  256. package/modules/bot-runtime/vendor/ds-bot/src/host/dsh-update.js +172 -0
  257. package/modules/bot-runtime/vendor/ds-bot/src/host/feed.js +115 -0
  258. package/modules/bot-runtime/vendor/ds-bot/src/host/files.js +27 -0
  259. package/modules/bot-runtime/vendor/ds-bot/src/host/folders.js +230 -0
  260. package/modules/bot-runtime/vendor/ds-bot/src/host/goal-skills.js +48 -0
  261. package/modules/bot-runtime/vendor/ds-bot/src/host/goals.js +812 -0
  262. package/modules/bot-runtime/vendor/ds-bot/src/host/groups.js +1466 -0
  263. package/modules/bot-runtime/vendor/ds-bot/src/host/handoffs.js +330 -0
  264. package/modules/bot-runtime/vendor/ds-bot/src/host/home-lock.js +98 -0
  265. package/modules/bot-runtime/vendor/ds-bot/src/host/images.js +212 -0
  266. package/modules/bot-runtime/vendor/ds-bot/src/host/learning.js +781 -0
  267. package/modules/bot-runtime/vendor/ds-bot/src/host/links.js +39 -0
  268. package/modules/bot-runtime/vendor/ds-bot/src/host/memory-pending.js +95 -0
  269. package/modules/bot-runtime/vendor/ds-bot/src/host/memory.js +2050 -0
  270. package/modules/bot-runtime/vendor/ds-bot/src/host/models.js +314 -0
  271. package/modules/bot-runtime/vendor/ds-bot/src/host/office-skills.js +78 -0
  272. package/modules/bot-runtime/vendor/ds-bot/src/host/parts.js +1473 -0
  273. package/modules/bot-runtime/vendor/ds-bot/src/host/permissions.js +117 -0
  274. package/modules/bot-runtime/vendor/ds-bot/src/host/privacy.js +368 -0
  275. package/modules/bot-runtime/vendor/ds-bot/src/host/prompt.js +73 -0
  276. package/modules/bot-runtime/vendor/ds-bot/src/host/providers.js +226 -0
  277. package/modules/bot-runtime/vendor/ds-bot/src/host/requests.js +141 -0
  278. package/modules/bot-runtime/vendor/ds-bot/src/host/resume.js +445 -0
  279. package/modules/bot-runtime/vendor/ds-bot/src/host/roster.js +776 -0
  280. package/modules/bot-runtime/vendor/ds-bot/src/host/schedules.js +156 -0
  281. package/modules/bot-runtime/vendor/ds-bot/src/host/secrets.js +586 -0
  282. package/modules/bot-runtime/vendor/ds-bot/src/host/side.js +406 -0
  283. package/modules/bot-runtime/vendor/ds-bot/src/host/skills/goal-grill/SKILL.md +37 -0
  284. package/modules/bot-runtime/vendor/ds-bot/src/host/steer.js +265 -0
  285. package/modules/bot-runtime/vendor/ds-bot/src/host/steward.js +165 -0
  286. package/modules/bot-runtime/vendor/ds-bot/src/host/store.js +512 -0
  287. package/modules/bot-runtime/vendor/ds-bot/src/host/text.js +49 -0
  288. package/modules/bot-runtime/vendor/ds-bot/src/host/thinking.js +55 -0
  289. package/modules/bot-runtime/vendor/ds-bot/src/host/time-context.js +46 -0
  290. package/modules/bot-runtime/vendor/ds-bot/src/host/tools.js +1105 -0
  291. package/modules/bot-runtime/vendor/ds-bot/src/host/turns.js +1126 -0
  292. package/modules/bot-runtime/vendor/ds-bot/src/host/update.js +315 -0
  293. package/modules/bot-runtime/vendor/ds-bot/src/host/usage.js +653 -0
  294. package/modules/bot-runtime/vendor/ds-bot/src/office/check.js +329 -0
  295. package/modules/bot-runtime/vendor/ds-bot/src/office/cli.js +193 -0
  296. package/modules/bot-runtime/vendor/ds-bot/src/office/docx.js +644 -0
  297. package/modules/bot-runtime/vendor/ds-bot/src/office/package.js +238 -0
  298. package/modules/bot-runtime/vendor/ds-bot/src/office/png.js +183 -0
  299. package/modules/bot-runtime/vendor/ds-bot/src/office/pptx.js +408 -0
  300. package/modules/bot-runtime/vendor/ds-bot/src/office/skills/office/SKILL.md +18 -0
  301. package/modules/bot-runtime/vendor/ds-bot/src/office/skills/office-tools/SKILL.md +41 -0
  302. package/modules/bot-runtime/vendor/ds-bot/src/office/xlsx.js +119 -0
  303. package/modules/bot-runtime/vendor/ds-bot/src/office/xml.js +128 -0
  304. package/modules/bot-runtime/vendor/ds-bot/src/office/zip.js +146 -0
  305. package/modules/bot-runtime/vendor/ds-bot/src/shared/group-replies.js +69 -0
  306. package/modules/bot-runtime/vendor/ds-bot/src/shared/mentions.js +72 -0
  307. package/modules/bot-runtime/vendor/ds-bot/test/harness-resolve.mjs +48 -0
  308. package/modules/bot-runtime/vendor/ds-bot/web-search.js +775 -0
  309. package/modules/bot-runtime/web-search.mjs +3 -0
  310. package/modules/independent-runtime/index.mjs +62 -0
  311. package/modules/independent-runtime/remote-tools.mjs +51 -0
  312. package/modules/independent-runtime/workspace-tools.mjs +96 -0
  313. package/native/windows-desktop/DesktopLease.cs +128 -0
  314. package/native/windows-desktop/DesktopStream.cs +161 -0
  315. package/native/windows-desktop/FullDesktop.cs +76 -0
  316. package/native/windows-desktop/ProcessJob.cs +172 -0
  317. package/native/windows-desktop/Program.cs +272 -0
  318. package/native/windows-desktop/README.md +11 -0
  319. package/native/windows-desktop/build.ps1 +22 -0
  320. package/package.json +519 -4
  321. package/packages/capability-broker/README.md +41 -0
  322. package/packages/capability-broker/src/authority.mjs +162 -0
  323. package/packages/capability-broker/src/cli-bootstrap.mjs +122 -0
  324. package/packages/capability-broker/src/cli-stdio-bridge.mjs +69 -0
  325. package/packages/capability-broker/src/managed-bridge.mjs +107 -0
  326. package/packages/capability-broker/src/stdio-bridge.mjs +57 -0
  327. package/packages/cli-runtime/README.md +41 -0
  328. package/packages/cli-runtime/src/agent-codex-runtime.mjs +64 -0
  329. package/packages/cli-runtime/src/codex-runtime.mjs +21 -0
  330. package/packages/cli-runtime/src/codex-session-core.mjs +202 -0
  331. package/packages/cli-runtime/src/contracts.mjs +59 -0
  332. package/packages/cli-runtime/src/native-peer.ps1 +311 -0
  333. package/packages/cli-runtime/src/native-peer.py +222 -0
  334. package/packages/cli-runtime/src/native-process.mjs +117 -0
  335. package/packages/cli-runtime/src/native-terminal-peer.ps1 +267 -0
  336. package/packages/cli-runtime/src/native-terminal.mjs +499 -0
  337. package/packages/cli-runtime/src/profile-policy.mjs +28 -0
  338. package/packages/model-router-plugin/README.md +34 -0
  339. package/packages/model-router-plugin/README.zh.md +34 -0
  340. package/packages/model-router-plugin/cordis.patch.yml +4 -0
  341. package/packages/model-router-plugin/package.json +59 -0
  342. package/packages/orchestration/README.md +146 -0
  343. package/packages/orchestration/src/bot-budget.mjs +100 -0
  344. package/packages/orchestration/src/bot-handoff.mjs +88 -0
  345. package/packages/orchestration/src/bot-library.mjs +195 -0
  346. package/packages/orchestration/src/bot-loop-bridge.mjs +102 -0
  347. package/packages/orchestration/src/bot-loop.mjs +84 -0
  348. package/packages/orchestration/src/bot-policy.mjs +94 -0
  349. package/packages/orchestration/src/bot-roles.mjs +63 -0
  350. package/packages/orchestration/src/bot-routine-store.mjs +194 -0
  351. package/packages/orchestration/src/bot-routine.mjs +195 -0
  352. package/packages/orchestration/src/bot-routing-candidates.mjs +140 -0
  353. package/packages/orchestration/src/bot-routing-dispatch.mjs +402 -0
  354. package/packages/orchestration/src/bot-routing-mode.mjs +108 -0
  355. package/packages/orchestration/src/bot-routing-runtime.mjs +360 -0
  356. package/packages/orchestration/src/bot-routing-service.mjs +232 -0
  357. package/packages/orchestration/src/bot-routing-settings.mjs +34 -0
  358. package/packages/orchestration/src/bot-routing-tools.mjs +89 -0
  359. package/packages/orchestration/src/bot-routing.mjs +106 -0
  360. package/packages/orchestration/src/bot-runtime-assembly.mjs +128 -0
  361. package/packages/orchestration/src/bot-runtime-config.mjs +41 -0
  362. package/packages/orchestration/src/bot-runtime-dispatch.mjs +51 -0
  363. package/packages/orchestration/src/bot-runtime-switch.mjs +97 -0
  364. package/packages/orchestration/src/bot-session-store.mjs +120 -0
  365. package/packages/orchestration/src/bot-settings.mjs +341 -0
  366. package/packages/orchestration/src/cli-execution.mjs +180 -0
  367. package/packages/orchestration/src/deferred-router-state.mjs +19 -0
  368. package/packages/orchestration/src/desktop-actions.mjs +60 -0
  369. package/packages/orchestration/src/desktop-contract.mjs +99 -0
  370. package/packages/orchestration/src/desktop-sessions.mjs +93 -0
  371. package/packages/orchestration/src/ds-lifecycle.mjs +189 -0
  372. package/packages/orchestration/src/ds-workspace-privacy.mjs +21 -0
  373. package/packages/orchestration/src/funded-router-state.mjs +63 -0
  374. package/packages/orchestration/src/funding-accounts.mjs +63 -0
  375. package/packages/orchestration/src/funding-admission.mjs +39 -0
  376. package/packages/orchestration/src/funding-projection.mjs +124 -0
  377. package/packages/orchestration/src/machine-heartbeat.mjs +35 -0
  378. package/packages/orchestration/src/machine-secrets.mjs +37 -0
  379. package/packages/orchestration/src/migration-atomic-rename.mjs +16 -0
  380. package/packages/orchestration/src/migration-attestation-verifier.mjs +621 -0
  381. package/packages/orchestration/src/migration-commit-orchestration.mjs +1193 -0
  382. package/packages/orchestration/src/migration-configuration-commit.mjs +217 -0
  383. package/packages/orchestration/src/migration-data-archive.mjs +128 -0
  384. package/packages/orchestration/src/migration-domain-audit.mjs +245 -0
  385. package/packages/orchestration/src/migration-domain-evidence.mjs +409 -0
  386. package/packages/orchestration/src/migration-domain-inventory.mjs +78 -0
  387. package/packages/orchestration/src/migration-fence.mjs +278 -0
  388. package/packages/orchestration/src/migration-file-stability.mjs +19 -0
  389. package/packages/orchestration/src/migration-financial-audit.mjs +147 -0
  390. package/packages/orchestration/src/migration-ledger-export.mjs +159 -0
  391. package/packages/orchestration/src/migration-linux-quarantine.mjs +83 -0
  392. package/packages/orchestration/src/migration-linux-quarantine.py +184 -0
  393. package/packages/orchestration/src/migration-os-quarantine.mjs +99 -0
  394. package/packages/orchestration/src/migration-private-files.mjs +52 -0
  395. package/packages/orchestration/src/migration-provider-selection.mjs +242 -0
  396. package/packages/orchestration/src/migration-recovery-audit.mjs +359 -0
  397. package/packages/orchestration/src/migration-remote-client-quarantine.mjs +80 -0
  398. package/packages/orchestration/src/migration-remote-file-reconciliation.mjs +72 -0
  399. package/packages/orchestration/src/migration-remote-operation-drain.mjs +35 -0
  400. package/packages/orchestration/src/migration-restore.mjs +146 -0
  401. package/packages/orchestration/src/migration-rollback-readiness.mjs +114 -0
  402. package/packages/orchestration/src/migration-rollback-rehearsal.mjs +135 -0
  403. package/packages/orchestration/src/migration-session-decoder.mjs +108 -0
  404. package/packages/orchestration/src/migration-session-reader.mjs +60 -0
  405. package/packages/orchestration/src/migration-snapshot.mjs +142 -0
  406. package/packages/orchestration/src/migration-startup-gate.mjs +29 -0
  407. package/packages/orchestration/src/migration-supporting-domains.mjs +141 -0
  408. package/packages/orchestration/src/migration-systemd-quarantine.mjs +132 -0
  409. package/packages/orchestration/src/migration-windows-launcher-quarantine.mjs +86 -0
  410. package/packages/orchestration/src/migration-workspace-audit.mjs +69 -0
  411. package/packages/orchestration/src/migration-writer-inventory.mjs +167 -0
  412. package/packages/orchestration/src/model-accounting.mjs +198 -0
  413. package/packages/orchestration/src/model-receipt.mjs +46 -0
  414. package/packages/orchestration/src/mr-read-backend.mjs +110 -0
  415. package/packages/orchestration/src/pair-main-machine.mjs +20 -0
  416. package/packages/orchestration/src/principals.mjs +56 -0
  417. package/packages/orchestration/src/product-composition.mjs +967 -0
  418. package/packages/orchestration/src/product-funding.mjs +13 -0
  419. package/packages/orchestration/src/profile-migration-plan.mjs +521 -0
  420. package/packages/orchestration/src/remote-cli-execution.mjs +187 -0
  421. package/packages/orchestration/src/remote-command-execution.mjs +83 -0
  422. package/packages/orchestration/src/remote-computer-tools.mjs +234 -0
  423. package/packages/orchestration/src/remote-execution.mjs +65 -0
  424. package/packages/orchestration/src/remote-machines.mjs +316 -0
  425. package/packages/orchestration/src/routine-execution.mjs +130 -0
  426. package/packages/orchestration/src/routine-session.mjs +158 -0
  427. package/packages/orchestration/src/sqlite-router-state.mjs +254 -0
  428. package/packages/orchestration/src/task-admission.mjs +39 -0
  429. package/packages/orchestration/src/task-contract.mjs +223 -0
  430. package/packages/orchestration/src/task-journal.mjs +548 -0
  431. package/packages/orchestration/src/task-service.mjs +266 -0
  432. package/packages/orchestration/src/task-stage.mjs +14 -0
  433. package/packages/orchestration/src/task-tools.mjs +27 -0
  434. package/remote-computer-agent/README.md +29 -0
  435. package/remote-computer-agent/build.mjs +16 -0
  436. package/remote-computer-agent/dist/cli-stdio-bridge.mjs +251 -0
  437. package/remote-computer-agent/dist/cli-stdio-bridge.mjs.map +7 -0
  438. package/remote-computer-agent/dist/cli.mjs +4473 -0
  439. package/remote-computer-agent/dist/cli.mjs.map +7 -0
  440. package/remote-computer-agent/dist/index.mjs +4489 -0
  441. package/remote-computer-agent/dist/index.mjs.map +7 -0
  442. package/remote-computer-agent/dist/native-peer.ps1 +311 -0
  443. package/remote-computer-agent/dist/native-peer.py +222 -0
  444. package/remote-computer-agent/launch-agent.ps1 +9 -0
  445. package/remote-computer-agent/package-lock.json +618 -0
  446. package/remote-computer-agent/package.json +27 -0
  447. package/remote-computer-agent/setup.ps1 +170 -0
  448. package/remote-computer-agent/src/agent.ts +308 -0
  449. package/remote-computer-agent/src/auth-throttle.ts +45 -0
  450. package/remote-computer-agent/src/browser.ts +71 -0
  451. package/remote-computer-agent/src/cli-task.ts +115 -0
  452. package/remote-computer-agent/src/cli.ts +25 -0
  453. package/remote-computer-agent/src/client.ts +11 -0
  454. package/remote-computer-agent/src/container-command.ts +166 -0
  455. package/remote-computer-agent/src/container-supervisor.mjs +32 -0
  456. package/remote-computer-agent/src/container-task-contract.ts +583 -0
  457. package/remote-computer-agent/src/desktop-session.ts +240 -0
  458. package/remote-computer-agent/src/desktop.ts +98 -0
  459. package/remote-computer-agent/src/index.ts +12 -0
  460. package/remote-computer-agent/src/pinned-write.ts +462 -0
  461. package/remote-computer-agent/src/protocol.ts +25 -0
  462. package/remote-computer-agent/src/scope.ts +92 -0
  463. package/remote-computer-agent/src/store.ts +101 -0
  464. package/remote-computer-agent/src/transport.ts +89 -0
  465. package/remote-computer-agent/src/workspace-admission.ts +181 -0
  466. package/remote-computer-agent/src/workspace-generation.ts +51 -0
  467. package/remote-computer-agent/src/workspace-identity.ts +126 -0
  468. package/remote-computer-agent/start.cmd +3 -0
@@ -0,0 +1,315 @@
1
+ // Updates: compare this package's version with the newest release where it was
2
+ // installed from (the npm registry, or a GitHub tag for a versioned git install)
3
+ // and, when the user asks, reinstall it through DSH's plugin manager. A new version
4
+ // runs from the next DSH start. A linked or local checkout is never offered one.
5
+ import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
6
+ import { join } from 'node:path'
7
+
8
+ const PKG = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8'))
9
+ export const OFFICIAL_REGISTRY = 'https://registry.npmjs.org/'
10
+ export const MIRROR_REGISTRY = 'https://registry.npmmirror.com/'
11
+ // Every window that opens asks; within this long the last answer stands.
12
+ export const CHECK_TTL_MS = 10 * 60_000
13
+ export const FETCH_TIMEOUT_MS = 8000
14
+ // The first check waits until the host has settled its own start.
15
+ const STARTUP_DELAY_MS = 15_000
16
+ const VERSION = /^v?(\d+\.\d+\.\d+(?:-[\w.]+)?)(?:\+[\w.]+)?$/
17
+
18
+ /** A release version without its `v` and build metadata, or null. */
19
+ export const cleanVersion = value => VERSION.exec(String(value ?? '').trim())?.[1] ?? null
20
+
21
+ /** Whether version `a` is newer than `b` (semver order, prereleases before their release). */
22
+ export function newer(a, b) {
23
+ const parse = (value) => {
24
+ const [core, pre] = (cleanVersion(value) ?? '0.0.0').split(/-(.*)/s)
25
+ return { nums: core.split('.').map(Number), pre: pre ?? null }
26
+ }
27
+ const x = parse(a)
28
+ const y = parse(b)
29
+ for (let index = 0; index < 3; index++) if (x.nums[index] !== y.nums[index]) return x.nums[index] > y.nums[index]
30
+ if (x.pre === y.pre) return false
31
+ if (x.pre === null) return true
32
+ if (y.pre === null) return false
33
+ return x.pre.localeCompare(y.pre, 'en', { numeric: true }) > 0
34
+ }
35
+
36
+ /**
37
+ * How the profile installed this package, from the plugin manager's `source` spec:
38
+ * `registry` (name@range), `git` (with `owner`, `repo`, the version `ref` and the
39
+ * other fragment parts when it pins a GitHub tag), `path` (link:, file: or a folder),
40
+ * `tarball`, or `unknown`.
41
+ */
42
+ export function sourceOf(spec) {
43
+ const text = typeof spec === 'string' ? spec.trim() : ''
44
+ if (text === '') return { kind: 'unknown' }
45
+ if (/^(link|file):/i.test(text) || /^([a-z]:[\\/]|[\\/]|~|\.)/i.test(text)) return { kind: 'path' }
46
+ const github = /^(?:github:|git\+https:\/\/github\.com\/|https:\/\/github\.com\/|git@github\.com:)?([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:#(.*))?$/i.exec(text)
47
+ const gitLike = /^(git\+|git:|git@|github:|gitlab:|bitbucket:)/i.test(text) || /\.git(#|$)/i.test(text)
48
+ if (github && (gitLike || !text.startsWith('@'))) {
49
+ const parts = (github[3] ?? '').split('&').filter(Boolean)
50
+ const ref = parts.find(part => !part.includes(':')) ?? ''
51
+ return {
52
+ kind: 'git', owner: github[1], repo: github[2],
53
+ ...(cleanVersion(ref) ? { ref } : {}),
54
+ rest: parts.filter(part => part !== ref),
55
+ }
56
+ }
57
+ if (gitLike) return { kind: 'git' }
58
+ if (/^https?:/i.test(text)) return { kind: 'tarball' }
59
+ return { kind: 'registry' }
60
+ }
61
+
62
+ const normalizeRegistry = url => `${String(url).trim().replace(/\/+$/, '')}/`
63
+ export const encodeName = name => (name.startsWith('@') ? `@${encodeURIComponent(name.slice(1))}` : encodeURIComponent(name))
64
+
65
+ export const fetchJson = async (url, headers = {}) => {
66
+ const response = await fetch(url, { headers: { accept: 'application/json', ...headers }, signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) })
67
+ if (!response.ok) throw new Error(`${url} answered ${response.status}`)
68
+ return response.json()
69
+ }
70
+
71
+ // The registries the plugin manager installs from, in its order: its configured
72
+ // first one (else pnpm's own), then the fallbacks, unless that first one is private.
73
+ export async function registryPlan(config, manager) {
74
+ if (typeof config.updateRegistry === 'string' && config.updateRegistry !== '') return [normalizeRegistry(config.updateRegistry)]
75
+ const configured = await Promise.resolve(manager?.registries?.()).catch(() => null)
76
+ if (!configured) return [OFFICIAL_REGISTRY, MIRROR_REGISTRY]
77
+ const fallbacks = (configured.fallbackRegistries ?? []).map(normalizeRegistry)
78
+ const own = configured.resolved ? normalizeRegistry(configured.resolved) : null
79
+ const first = configured.registry ? normalizeRegistry(configured.registry) : own ?? OFFICIAL_REGISTRY
80
+ const isPublic = first === OFFICIAL_REGISTRY || fallbacks.includes(first)
81
+ return isPublic ? [...new Set([first, ...fallbacks])] : [first]
82
+ }
83
+
84
+ // The plugin manager's `source` for this package; DSH releases before it reported
85
+ // one leave the profile's own dependency entry to say the same.
86
+ export async function installSpecOf(ctx) {
87
+ const manager = ctx.get?.('pluginManager')
88
+ const bundles = await Promise.resolve(manager?.listBundles?.()).catch(() => null)
89
+ const own = Array.isArray(bundles) ? bundles.find(bundle => bundle.name === PKG.name) : undefined
90
+ if (typeof own?.source === 'string') return own.source
91
+ const dir = ctx.get?.('profileContext')?.dir
92
+ if (typeof dir !== 'string') return undefined
93
+ try {
94
+ return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).dependencies?.[PKG.name]
95
+ } catch { return undefined }
96
+ }
97
+
98
+ // The public repository the releases live in, for tags and the "what's new" link.
99
+ export const repoSlug = () =>
100
+ /github\.com[/:]([\w.-]+\/[\w.-]+?)(?:\.git)?$/i.exec(String(PKG.repository?.url ?? PKG.repository ?? ''))?.[1] ?? null
101
+
102
+ const repoUrl = () => {
103
+ const repo = repoSlug()
104
+ return repo ? `https://github.com/${repo}` : null
105
+ }
106
+ const releasesUrl = () => {
107
+ const repo = repoUrl()
108
+ return repo ? `${repo}/releases` : (PKG.homepage ?? null)
109
+ }
110
+
111
+ export const STARS_TTL_MS = 60 * 60_000
112
+
113
+ export function install(rt) {
114
+ const { ctx, config } = rt
115
+ const enabled = config.updateCheck !== false
116
+ const manager = () => ctx.get?.('pluginManager')
117
+
118
+ const status = {
119
+ name: PKG.name, current: PKG.version, latest: null, source: 'unknown', notesUrl: releasesUrl(),
120
+ checkedAt: 0, phase: 'idle', installed: null, error: null,
121
+ }
122
+ // Where the newest version was found, and the spec that installs it.
123
+ let target = null
124
+ let checking = null
125
+
126
+ // A remove-and-install update under hot reload drops this host with its bundle;
127
+ // a note in the data folder carries the result to the start that follows it.
128
+ const markerPath = typeof rt.home === 'string' ? join(rt.home, 'update.json') : null
129
+ if (markerPath !== null && existsSync(markerPath)) {
130
+ let marker = null
131
+ try {
132
+ marker = JSON.parse(readFileSync(markerPath, 'utf8'))
133
+ } catch (error) {
134
+ rt.warn('ds-bot: could not read the update note: %s', error?.message ?? error)
135
+ }
136
+ if (marker === null) {
137
+ try { unlinkSync(markerPath) } catch { /* gone is what we want */ }
138
+ } else if (marker.to === PKG.version) {
139
+ Object.assign(status, { phase: 'updated', installed: PKG.version })
140
+ try { unlinkSync(markerPath) } catch { /* gone is what we want */ }
141
+ } else if (typeof marker.error === 'string' || marker.from !== PKG.version) {
142
+ rt.warn('ds-bot: the update to %s did not finish: %s', marker.to ?? 'a newer version', typeof marker.error === 'string' ? marker.error.slice(0, 600) : 'the install did not complete')
143
+ try { unlinkSync(markerPath) } catch { /* gone is what we want */ }
144
+ }
145
+ // A clean note on the version that wrote it stays: a reload can still be
146
+ // running the old modules (the hoisted profile layout keeps one path), and
147
+ // the next start that runs the new code reports the update then.
148
+ }
149
+
150
+ const view = () => ({
151
+ name: status.name, current: status.current, latest: status.latest, source: status.source, notesUrl: status.notesUrl,
152
+ repoUrl: repoUrl(), enabled,
153
+ checkedAt: status.checkedAt, phase: status.phase, installed: status.installed, error: status.error,
154
+ available: status.phase !== 'installed' && status.phase !== 'updated' && target !== null && status.latest !== null && newer(status.latest, status.current),
155
+ })
156
+
157
+ // Asked only while the About page is open, so a closed page never calls GitHub.
158
+ // A failed answer keeps the last count and is asked again next time.
159
+ let stars = { count: null, at: 0 }
160
+ let starring = null
161
+ async function repoStars() {
162
+ const repo = repoSlug()
163
+ if (repo === null) return null
164
+ if (Date.now() - stars.at < STARS_TTL_MS) return stars.count
165
+ starring ??= fetchJson(`https://api.github.com/repos/${repo}`, { 'user-agent': `${PKG.name}/${PKG.version}` })
166
+ .then((info) => { if (Number.isInteger(info?.stargazers_count)) stars = { count: info.stargazers_count, at: Date.now() } })
167
+ .catch(error => rt.warn('ds-bot: star count failed: %s', error?.message ?? error))
168
+ .finally(() => { starring = null })
169
+ await starring
170
+ return stars.count
171
+ }
172
+
173
+ async function newestFromRegistry() {
174
+ for (const registry of await registryPlan(config, manager())) {
175
+ try {
176
+ const version = cleanVersion((await fetchJson(`${registry}${encodeName(PKG.name)}/latest`)).version)
177
+ if (version) return { version, spec: `${PKG.name}@${version}`, registry }
178
+ } catch { /* unreachable, or no copy there yet: ask the next one */ }
179
+ }
180
+ return null
181
+ }
182
+
183
+ async function newestFromGitHub(source) {
184
+ if (!source.ref) return null
185
+ const release = await fetchJson(`https://api.github.com/repos/${source.owner}/${source.repo}/releases/latest`, { 'user-agent': `${PKG.name}/${PKG.version}` })
186
+ const version = cleanVersion(release?.tag_name)
187
+ if (!version) return null
188
+ // The API answers through redirects, so the release's html_url names the
189
+ // repository's current address; the install moves to it.
190
+ const current = /^https:\/\/github\.com\/([\w.-]+)\/([\w.-]+)\/releases\//.exec(release.html_url ?? '')
191
+ const [owner, repo] = current ? [current[1], current[2]] : [source.owner, source.repo]
192
+ const fragment = [release.tag_name, ...source.rest].join('&')
193
+ return { version, spec: `github:${owner}/${repo}#${fragment}` }
194
+ }
195
+
196
+ async function runCheck() {
197
+ // The desktop app updates as a whole, with this package inside it.
198
+ const source = process.env.DS_BOT_APP === '1' ? { kind: 'app' } : sourceOf(await installSpecOf(ctx))
199
+ status.source = source.kind
200
+ let found = null
201
+ try {
202
+ if (source.kind === 'registry') found = await newestFromRegistry()
203
+ else if (source.kind === 'git') found = await newestFromGitHub(source)
204
+ } catch (error) {
205
+ rt.warn('ds-bot: update check failed: %s', error?.message ?? error)
206
+ }
207
+ status.checkedAt = Date.now()
208
+ // Nothing found now (a linked checkout, a moved tag, an unreachable registry)
209
+ // retires the version a check before it found; offering it would install over
210
+ // a source that never updates.
211
+ if (found === null) {
212
+ status.latest = null
213
+ target = null
214
+ return
215
+ }
216
+ status.latest = found.version
217
+ target = newer(found.version, status.current) ? found : null
218
+ }
219
+
220
+ /** Ask where the package came from for its newest version; a fresh check ignores the last answer. */
221
+ async function check({ fresh = false } = {}) {
222
+ if (!enabled) return view()
223
+ if (checking) return checking
224
+ if (!fresh && Date.now() - status.checkedAt < CHECK_TTL_MS) return view()
225
+ checking = runCheck().finally(() => { checking = null })
226
+ await checking
227
+ return view()
228
+ }
229
+
230
+ /** Start reinstalling the newest version; the answer comes back through `check`. */
231
+ function start() {
232
+ if (status.phase === 'installing') return view()
233
+ if (target === null) throw new Error('No DS Bot update is available')
234
+ const service = manager()
235
+ if (typeof service?.installBundle !== 'function') throw new Error('The DSH plugin manager is not available in this profile')
236
+ const chosen = target
237
+ Object.assign(status, { phase: 'installing', error: null })
238
+ const options = chosen.registry ? { registry: chosen.registry } : {}
239
+ // Removing this bundle disposes our context before the promise answers, so the
240
+ // continuation uses plain fs for the note and a guarded logger.
241
+ const note = (template, ...args) => { try { rt.warn(template, ...args) } catch { /* our context is disposed */ } }
242
+ const mark = (error) => {
243
+ if (markerPath === null) return
244
+ try {
245
+ writeFileSync(markerPath, JSON.stringify({
246
+ from: PKG.version, to: chosen.version, spec: chosen.spec, startedAt: new Date().toISOString(),
247
+ ...(error === undefined ? {} : { error: String(error).slice(0, 600) }),
248
+ }))
249
+ } catch { /* a note that cannot be written just is not there */ }
250
+ }
251
+ // A refused removal leaves this version running, with nothing for a later start to report.
252
+ const unmark = () => { if (markerPath !== null) try { unlinkSync(markerPath) } catch { /* already gone */ } }
253
+ void Promise.resolve(service.installBundle(chosen.spec, options))
254
+ .then(async (result) => {
255
+ if (result?.error?.code !== 'already-installed') return result
256
+ // With HMR the plugin manager refuses to install a package the profile already
257
+ // depends on: remove the bundle (which unloads this host) and install it again.
258
+ if (typeof service.removeBundle !== 'function') return { error: { code: 'not-removable' } }
259
+ // Asked before removal drops this host: the spec that puts the old version
260
+ // back. A registry spec is a range that can resolve to the failed release
261
+ // again, so pin the version that is actually running.
262
+ const oldSpec = await Promise.resolve(installSpecOf(ctx)).catch(() => undefined)
263
+ const previous = typeof oldSpec === 'string' && sourceOf(oldSpec).kind === 'registry' ? `${PKG.name}@${PKG.version}` : oldSpec
264
+ mark()
265
+ const removed = await Promise.resolve(service.removeBundle(PKG.name)).catch((error) => { unmark(); throw error })
266
+ if (removed?.error) {
267
+ unmark()
268
+ return { error: removed.error }
269
+ }
270
+ // The bundle is gone now; a failed install leaves no DS Bot unless the old one goes back.
271
+ const restore = async (failed) => {
272
+ if (typeof previous !== 'string' || previous === '') return failed
273
+ const back = await Promise.resolve(service.installBundle(previous, sourceOf(previous).kind === 'registry' && chosen.registry ? { registry: chosen.registry } : {})).catch(error => ({ error: { code: error?.message ?? 'restore failed' } }))
274
+ if (back?.error) {
275
+ note('ds-bot: could not reinstall %s after the failed update: %s', previous, back.error.diagnostic ?? back.error.code)
276
+ return failed
277
+ }
278
+ return `${failed}; ${previous} was reinstalled`
279
+ }
280
+ try {
281
+ const again = await service.installBundle(chosen.spec, options)
282
+ // A failure also arrives as an application state with no error; the
283
+ // result check below rejects every one of those, so restore sees the
284
+ // same failures it does.
285
+ if (again?.error || !['applied', 'restart-required'].includes(again?.application)) mark(await restore(again?.error?.diagnostic ?? again?.error?.code ?? `install ${again?.application ?? 'failed'}`))
286
+ return again
287
+ } catch (error) {
288
+ mark(await restore(error?.message ?? String(error)))
289
+ throw error
290
+ }
291
+ })
292
+ .then((result) => {
293
+ if (result?.error || !['applied', 'restart-required'].includes(result?.application)) {
294
+ throw new Error(result?.error?.diagnostic ?? result?.error?.code ?? `install ${result?.application ?? 'failed'}`)
295
+ }
296
+ Object.assign(status, { phase: 'installed', installed: cleanVersion(result.version) ?? chosen.version })
297
+ })
298
+ .catch((error) => {
299
+ note('ds-bot: update to %s failed: %s', chosen.spec, error?.message ?? error)
300
+ Object.assign(status, { phase: 'failed', error: String(error?.message ?? error).slice(0, 600) })
301
+ })
302
+ return view()
303
+ }
304
+
305
+ if (enabled) {
306
+ ctx.effect(() => {
307
+ const timer = setTimeout(() => { void check() }, STARTUP_DELAY_MS)
308
+ // A pending first check never keeps the process alive.
309
+ timer.unref?.()
310
+ return () => clearTimeout(timer)
311
+ }, 'ds-bot: update check')
312
+ }
313
+
314
+ Object.assign(rt, { updateCheck: check, updateStart: start, updateView: view, repoStars })
315
+ }