@takboo/dsh-coopanion 0.4.7 → 0.4.9

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 (419) hide show
  1. package/README.md +20 -10
  2. package/desktop/display-controller.cjs +21 -0
  3. package/desktop/main.cjs +58 -42
  4. package/desktop/preload.cjs +2 -0
  5. package/desktop/test-display-probe.cjs +13 -0
  6. package/desktop/tray-state.cjs +12 -6
  7. package/dist/bridge.js +57 -20
  8. package/dist/bridge.js.map +3 -3
  9. package/dist/client.js +479 -18
  10. package/dist/index.js +777 -88
  11. package/dist/index.js.map +4 -4
  12. package/dist/model.js +71 -4
  13. package/dist/model.js.map +3 -3
  14. package/docs/daily-rhythm-contract.md +29 -0
  15. package/docs/desktop-recovery-contract.md +17 -0
  16. package/docs/evidence/m1/README.md +68 -0
  17. package/docs/evidence/m1/goal-host-0.2.0-rc.2.json +918 -0
  18. package/docs/evidence/m1/goal-host-0.2.1-alpha.1.json +918 -0
  19. package/docs/evidence/m1/install-0.2.0-rc.2.json +24 -0
  20. package/docs/evidence/m1/install-0.2.1-alpha.1.json +24 -0
  21. package/docs/evidence/m1/package-verification.json +7 -0
  22. package/docs/evidence/m1/runtime-lock-0.2.0-rc.2.json.gz +0 -0
  23. package/docs/evidence/m1/runtime-lock-0.2.1-alpha.1.json.gz +0 -0
  24. package/docs/evidence/m1/validation.json +94 -0
  25. package/docs/evidence/m2/README.md +77 -0
  26. package/docs/evidence/m2/controller-0.2.0-rc.2.json +1632 -0
  27. package/docs/evidence/m2/controller-0.2.1-alpha.1.json +1925 -0
  28. package/docs/evidence/m2/controller-probe.mjs +52 -0
  29. package/docs/evidence/m2/goal-host-0.2.0-rc.2.json +918 -0
  30. package/docs/evidence/m2/goal-host-0.2.1-alpha.1.json +918 -0
  31. package/docs/evidence/m2/install-0.2.0-rc.2.json +27 -0
  32. package/docs/evidence/m2/install-0.2.1-alpha.1.json +27 -0
  33. package/docs/evidence/m2/notification-host-0.2.0-rc.2.json +182 -0
  34. package/docs/evidence/m2/notification-host-0.2.1-alpha.1.json +182 -0
  35. package/docs/evidence/m2/notification-integration-0.2.0-rc.2.json +108 -0
  36. package/docs/evidence/m2/notification-integration-0.2.1-alpha.1.json +108 -0
  37. package/docs/evidence/m2/notification-source-0.2.0-rc.2.json +17 -0
  38. package/docs/evidence/m2/notification-source-0.2.1-alpha.1.json +17 -0
  39. package/docs/evidence/m2/package-source-content.json +18 -0
  40. package/docs/evidence/m2/package-verification.json +7 -0
  41. package/docs/evidence/m2/release-notes.md +12 -0
  42. package/docs/evidence/m2/runtime-lock-0.2.0-rc.2.json.gz +0 -0
  43. package/docs/evidence/m2/runtime-lock-0.2.1-alpha.1.json.gz +0 -0
  44. package/docs/evidence/m2/session-host-0.2.0-rc.2.json +3181 -0
  45. package/docs/evidence/m2/session-host-0.2.1-alpha.1.json +3767 -0
  46. package/docs/evidence/m2/session-native-0.2.0-rc.2.json +1161 -0
  47. package/docs/evidence/m2/session-native-0.2.1-alpha.1.json +1523 -0
  48. package/docs/evidence/m2/validation.json +187 -0
  49. package/docs/evidence/m3/README.md +64 -0
  50. package/docs/evidence/m3/build.log.gz +0 -0
  51. package/docs/evidence/m3/character-pack.log.gz +0 -0
  52. package/docs/evidence/m3/ci.log.gz +0 -0
  53. package/docs/evidence/m3/desktop-recovery-0.2.0-rc.2.json +392 -0
  54. package/docs/evidence/m3/desktop-recovery-0.2.1-alpha.1.json +394 -0
  55. package/docs/evidence/m3/desktop-recovery.json +615 -0
  56. package/docs/evidence/m3/desktop.log.gz +0 -0
  57. package/docs/evidence/m3/electron-setup.log.gz +0 -0
  58. package/docs/evidence/m3/goal-host-0.2.0-rc.2.json +918 -0
  59. package/docs/evidence/m3/goal-host-0.2.1-alpha.1.json +918 -0
  60. package/docs/evidence/m3/inbox-ui.log.gz +0 -0
  61. package/docs/evidence/m3/install-0.2.0-rc.2.json +28 -0
  62. package/docs/evidence/m3/install-0.2.1-alpha.1.json +28 -0
  63. package/docs/evidence/m3/install-alpha.log.gz +0 -0
  64. package/docs/evidence/m3/install-rc.log.gz +0 -0
  65. package/docs/evidence/m3/metadata.log.gz +0 -0
  66. package/docs/evidence/m3/notification-host-0.2.0-rc.2.json +182 -0
  67. package/docs/evidence/m3/notification-host-0.2.1-alpha.1.json +182 -0
  68. package/docs/evidence/m3/notification-integration-0.2.0-rc.2.json +108 -0
  69. package/docs/evidence/m3/notification-integration-0.2.1-alpha.1.json +108 -0
  70. package/docs/evidence/m3/notification-source-0.2.0-rc.2.json +17 -0
  71. package/docs/evidence/m3/notification-source-0.2.1-alpha.1.json +17 -0
  72. package/docs/evidence/m3/notification-ui.log.gz +0 -0
  73. package/docs/evidence/m3/package-source-content.json +3070 -0
  74. package/docs/evidence/m3/package-verification.json +7 -0
  75. package/docs/evidence/m3/package.log.gz +0 -0
  76. package/docs/evidence/m3/release-notes.md +12 -0
  77. package/docs/evidence/m3/runtime-lock-0.2.0-rc.2.json.gz +0 -0
  78. package/docs/evidence/m3/runtime-lock-0.2.1-alpha.1.json.gz +0 -0
  79. package/docs/evidence/m3/session-host-0.2.0-rc.2.json +3181 -0
  80. package/docs/evidence/m3/session-host-0.2.1-alpha.1.json +3767 -0
  81. package/docs/evidence/m3/session-native-0.2.0-rc.2.json +1131 -0
  82. package/docs/evidence/m3/session-native-0.2.1-alpha.1.json +1424 -0
  83. package/docs/evidence/m3/test.log.gz +0 -0
  84. package/docs/evidence/m3/typecheck.log.gz +0 -0
  85. package/docs/evidence/m3/ui.log.gz +0 -0
  86. package/docs/evidence/m3/validation.json +306 -0
  87. package/docs/evidence/m4/README.md +61 -0
  88. package/docs/evidence/m4/build.log.gz +0 -0
  89. package/docs/evidence/m4/character-pack.log.gz +0 -0
  90. package/docs/evidence/m4/ci.log.gz +0 -0
  91. package/docs/evidence/m4/desktop-recovery-0.2.0-rc.2.json +392 -0
  92. package/docs/evidence/m4/desktop-recovery-0.2.1-alpha.1.json +392 -0
  93. package/docs/evidence/m4/desktop-recovery.json +615 -0
  94. package/docs/evidence/m4/desktop.log.gz +0 -0
  95. package/docs/evidence/m4/electron-setup.log.gz +0 -0
  96. package/docs/evidence/m4/goal-host-0.2.0-rc.2.json +918 -0
  97. package/docs/evidence/m4/goal-host-0.2.1-alpha.1.json +918 -0
  98. package/docs/evidence/m4/inbox-ui.log.gz +0 -0
  99. package/docs/evidence/m4/install-0.2.0-rc.2.json +28 -0
  100. package/docs/evidence/m4/install-0.2.1-alpha.1.json +28 -0
  101. package/docs/evidence/m4/install-alpha.log.gz +0 -0
  102. package/docs/evidence/m4/install-rc.log.gz +0 -0
  103. package/docs/evidence/m4/metadata.log.gz +0 -0
  104. package/docs/evidence/m4/notification-host-0.2.0-rc.2.json +182 -0
  105. package/docs/evidence/m4/notification-host-0.2.1-alpha.1.json +182 -0
  106. package/docs/evidence/m4/notification-integration-0.2.0-rc.2.json +108 -0
  107. package/docs/evidence/m4/notification-integration-0.2.1-alpha.1.json +108 -0
  108. package/docs/evidence/m4/notification-source-0.2.0-rc.2.json +17 -0
  109. package/docs/evidence/m4/notification-source-0.2.1-alpha.1.json +17 -0
  110. package/docs/evidence/m4/notification-ui.log.gz +0 -0
  111. package/docs/evidence/m4/package-check.log.gz +0 -0
  112. package/docs/evidence/m4/package-negative-check.json +8 -0
  113. package/docs/evidence/m4/package-source-content.json +2638 -0
  114. package/docs/evidence/m4/package-verification.json +7 -0
  115. package/docs/evidence/m4/package.log.gz +0 -0
  116. package/docs/evidence/m4/release-notes.md +12 -0
  117. package/docs/evidence/m4/runtime-lock-0.2.0-rc.2.json.gz +0 -0
  118. package/docs/evidence/m4/runtime-lock-0.2.1-alpha.1.json.gz +0 -0
  119. package/docs/evidence/m4/session-host-0.2.0-rc.2.json +3181 -0
  120. package/docs/evidence/m4/session-host-0.2.1-alpha.1.json +3767 -0
  121. package/docs/evidence/m4/session-native-0.2.0-rc.2.json +1161 -0
  122. package/docs/evidence/m4/session-native-0.2.1-alpha.1.json +1454 -0
  123. package/docs/evidence/m4/test.log.gz +0 -0
  124. package/docs/evidence/m4/text-scale-chat-en-US.png +0 -0
  125. package/docs/evidence/m4/text-scale-chat-zh-CN.png +0 -0
  126. package/docs/evidence/m4/text-scale-en-US-240-1.25.png +0 -0
  127. package/docs/evidence/m4/text-scale-en-US-240-1.5.png +0 -0
  128. package/docs/evidence/m4/text-scale-en-US-240-1.png +0 -0
  129. package/docs/evidence/m4/text-scale-en-US-90-1.25.png +0 -0
  130. package/docs/evidence/m4/text-scale-en-US-90-1.5.png +0 -0
  131. package/docs/evidence/m4/text-scale-en-US-90-1.png +0 -0
  132. package/docs/evidence/m4/text-scale-en-US.json +50 -0
  133. package/docs/evidence/m4/text-scale-inbox-en-US.png +0 -0
  134. package/docs/evidence/m4/text-scale-inbox-zh-CN.png +0 -0
  135. package/docs/evidence/m4/text-scale-installed-0.2.0-rc.2.json +95 -0
  136. package/docs/evidence/m4/text-scale-installed-0.2.0-rc.2.png +0 -0
  137. package/docs/evidence/m4/text-scale-installed-0.2.1-alpha.1.json +95 -0
  138. package/docs/evidence/m4/text-scale-installed-0.2.1-alpha.1.png +0 -0
  139. package/docs/evidence/m4/text-scale-native.json +166 -0
  140. package/docs/evidence/m4/text-scale-native.png +0 -0
  141. package/docs/evidence/m4/text-scale-zh-CN-240-1.25.png +0 -0
  142. package/docs/evidence/m4/text-scale-zh-CN-240-1.5.png +0 -0
  143. package/docs/evidence/m4/text-scale-zh-CN-240-1.png +0 -0
  144. package/docs/evidence/m4/text-scale-zh-CN-90-1.25.png +0 -0
  145. package/docs/evidence/m4/text-scale-zh-CN-90-1.5.png +0 -0
  146. package/docs/evidence/m4/text-scale-zh-CN-90-1.png +0 -0
  147. package/docs/evidence/m4/text-scale-zh-CN.json +50 -0
  148. package/docs/evidence/m4/toolchain.log.gz +0 -0
  149. package/docs/evidence/m4/typecheck.log.gz +0 -0
  150. package/docs/evidence/m4/ui.log.gz +0 -0
  151. package/docs/evidence/m4/validation.json +407 -0
  152. package/docs/evidence/m5/README.md +87 -0
  153. package/docs/evidence/m5/active-drag-fixed.json +27 -0
  154. package/docs/evidence/m5/active-drag-fixed.log.gz +0 -0
  155. package/docs/evidence/m5/active-drag-reproduction.json +27 -0
  156. package/docs/evidence/m5/baseline-reproduction.json +88 -0
  157. package/docs/evidence/m5/build.log.gz +0 -0
  158. package/docs/evidence/m5/character-pack.log.gz +0 -0
  159. package/docs/evidence/m5/ci.log.gz +0 -0
  160. package/docs/evidence/m5/desktop-recovery-0.2.0-rc.2.json +394 -0
  161. package/docs/evidence/m5/desktop-recovery-0.2.1-alpha.1.json +392 -0
  162. package/docs/evidence/m5/desktop-recovery.json +615 -0
  163. package/docs/evidence/m5/desktop.log.gz +0 -0
  164. package/docs/evidence/m5/electron-setup.log.gz +0 -0
  165. package/docs/evidence/m5/evidence-identity.json +138 -0
  166. package/docs/evidence/m5/goal-host-0.2.0-rc.2.json +918 -0
  167. package/docs/evidence/m5/goal-host-0.2.1-alpha.1.json +918 -0
  168. package/docs/evidence/m5/inbox-ui.log.gz +0 -0
  169. package/docs/evidence/m5/install-0.2.0-rc.2.json +28 -0
  170. package/docs/evidence/m5/install-0.2.0-rc.2.log.gz +0 -0
  171. package/docs/evidence/m5/install-0.2.1-alpha.1.json +28 -0
  172. package/docs/evidence/m5/install-0.2.1-alpha.1.log.gz +0 -0
  173. package/docs/evidence/m5/metadata.log.gz +0 -0
  174. package/docs/evidence/m5/multi-display-installed-0.2.0-rc.2.json +557 -0
  175. package/docs/evidence/m5/multi-display-installed-0.2.1-alpha.1.json +557 -0
  176. package/docs/evidence/m5/multi-display-native.json +518 -0
  177. package/docs/evidence/m5/multi-display-native.png +0 -0
  178. package/docs/evidence/m5/multi-display-reader.png +0 -0
  179. package/docs/evidence/m5/multi-display-ui.json +133 -0
  180. package/docs/evidence/m5/native-input-failure.json +9 -0
  181. package/docs/evidence/m5/native-input-failure.redacted.log.gz +0 -0
  182. package/docs/evidence/m5/native-input-startup-loop.json +2197 -0
  183. package/docs/evidence/m5/native-input-startup-loop.log.gz +0 -0
  184. package/docs/evidence/m5/native-input-startup-loop.mjs.txt +23 -0
  185. package/docs/evidence/m5/native-pet.png +0 -0
  186. package/docs/evidence/m5/notification-host-0.2.0-rc.2.json +182 -0
  187. package/docs/evidence/m5/notification-host-0.2.1-alpha.1.json +182 -0
  188. package/docs/evidence/m5/notification-integration-0.2.0-rc.2.json +108 -0
  189. package/docs/evidence/m5/notification-integration-0.2.1-alpha.1.json +108 -0
  190. package/docs/evidence/m5/notification-source-0.2.0-rc.2.json +17 -0
  191. package/docs/evidence/m5/notification-source-0.2.1-alpha.1.json +17 -0
  192. package/docs/evidence/m5/notification-ui.log.gz +0 -0
  193. package/docs/evidence/m5/pack.log.gz +0 -0
  194. package/docs/evidence/m5/package-negative-check.json +8 -0
  195. package/docs/evidence/m5/package-source-content.json +2946 -0
  196. package/docs/evidence/m5/package-verification.json +7 -0
  197. package/docs/evidence/m5/package.log.gz +0 -0
  198. package/docs/evidence/m5/previous-milestones.json +36 -0
  199. package/docs/evidence/m5/release-notes.md +12 -0
  200. package/docs/evidence/m5/reproduce-active-drag.mjs +32 -0
  201. package/docs/evidence/m5/reproduce-baseline.mjs +23 -0
  202. package/docs/evidence/m5/runtime-lock-0.2.0-rc.2.json.gz +0 -0
  203. package/docs/evidence/m5/runtime-lock-0.2.1-alpha.1.json.gz +0 -0
  204. package/docs/evidence/m5/session-host-0.2.0-rc.2.json +3181 -0
  205. package/docs/evidence/m5/session-host-0.2.1-alpha.1.json +3767 -0
  206. package/docs/evidence/m5/session-native-0.2.0-rc.2.json +1131 -0
  207. package/docs/evidence/m5/session-native-0.2.1-alpha.1.json +1523 -0
  208. package/docs/evidence/m5/test.log.gz +0 -0
  209. package/docs/evidence/m5/text-scale-chat-en-US.png +0 -0
  210. package/docs/evidence/m5/text-scale-chat-zh-CN.png +0 -0
  211. package/docs/evidence/m5/text-scale-en-US-240-1.25.png +0 -0
  212. package/docs/evidence/m5/text-scale-en-US-240-1.5.png +0 -0
  213. package/docs/evidence/m5/text-scale-en-US-240-1.png +0 -0
  214. package/docs/evidence/m5/text-scale-en-US-90-1.25.png +0 -0
  215. package/docs/evidence/m5/text-scale-en-US-90-1.5.png +0 -0
  216. package/docs/evidence/m5/text-scale-en-US-90-1.png +0 -0
  217. package/docs/evidence/m5/text-scale-en-US.json +50 -0
  218. package/docs/evidence/m5/text-scale-inbox-en-US.png +0 -0
  219. package/docs/evidence/m5/text-scale-inbox-zh-CN.png +0 -0
  220. package/docs/evidence/m5/text-scale-installed-0.2.0-rc.2.json +629 -0
  221. package/docs/evidence/m5/text-scale-installed-0.2.0-rc.2.png +0 -0
  222. package/docs/evidence/m5/text-scale-installed-0.2.1-alpha.1.json +629 -0
  223. package/docs/evidence/m5/text-scale-installed-0.2.1-alpha.1.png +0 -0
  224. package/docs/evidence/m5/text-scale-native.json +1234 -0
  225. package/docs/evidence/m5/text-scale-native.png +0 -0
  226. package/docs/evidence/m5/text-scale-zh-CN-240-1.25.png +0 -0
  227. package/docs/evidence/m5/text-scale-zh-CN-240-1.5.png +0 -0
  228. package/docs/evidence/m5/text-scale-zh-CN-240-1.png +0 -0
  229. package/docs/evidence/m5/text-scale-zh-CN-90-1.25.png +0 -0
  230. package/docs/evidence/m5/text-scale-zh-CN-90-1.5.png +0 -0
  231. package/docs/evidence/m5/text-scale-zh-CN-90-1.png +0 -0
  232. package/docs/evidence/m5/text-scale-zh-CN.json +50 -0
  233. package/docs/evidence/m5/toolchain.log.gz +0 -0
  234. package/docs/evidence/m5/typecheck.log.gz +0 -0
  235. package/docs/evidence/m5/ui.log.gz +0 -0
  236. package/docs/evidence/m5/validation.json +542 -0
  237. package/docs/evidence/m6/README.md +110 -0
  238. package/docs/evidence/m6/baseline-identity.json +10 -0
  239. package/docs/evidence/m6/build.log.gz +0 -0
  240. package/docs/evidence/m6/character-pack.log.gz +0 -0
  241. package/docs/evidence/m6/daily-rhythm-installed-0.2.0-rc.2.json +14 -0
  242. package/docs/evidence/m6/daily-rhythm-installed-0.2.1-alpha.1.json +14 -0
  243. package/docs/evidence/m6/daily-rhythm-native.json +147 -0
  244. package/docs/evidence/m6/daily-rhythm-native.png +0 -0
  245. package/docs/evidence/m6/daily-rhythm-ui.json +119 -0
  246. package/docs/evidence/m6/daily-rhythm-ui.png +0 -0
  247. package/docs/evidence/m6/desktop-recovery-0.2.0-rc.2.json +403 -0
  248. package/docs/evidence/m6/desktop-recovery-0.2.1-alpha.1.json +403 -0
  249. package/docs/evidence/m6/desktop-recovery.json +615 -0
  250. package/docs/evidence/m6/desktop.log.gz +0 -0
  251. package/docs/evidence/m6/electron.log.gz +0 -0
  252. package/docs/evidence/m6/evidence-identity.json +151 -0
  253. package/docs/evidence/m6/goal-host-0.2.0-rc.2.json +918 -0
  254. package/docs/evidence/m6/goal-host-0.2.1-alpha.1.json +918 -0
  255. package/docs/evidence/m6/idle-baseline-controlled.json.gz +0 -0
  256. package/docs/evidence/m6/idle-baseline-controlled.log.gz +0 -0
  257. package/docs/evidence/m6/idle-baseline.json +7850 -0
  258. package/docs/evidence/m6/idle-day.json.gz +0 -0
  259. package/docs/evidence/m6/idle-day.log.gz +0 -0
  260. package/docs/evidence/m6/idle-night.json.gz +0 -0
  261. package/docs/evidence/m6/idle-night.log.gz +0 -0
  262. package/docs/evidence/m6/idle-off.json.gz +0 -0
  263. package/docs/evidence/m6/idle-off.log.gz +0 -0
  264. package/docs/evidence/m6/inbox-ui.log.gz +0 -0
  265. package/docs/evidence/m6/install-0.2.0-rc.2.json +28 -0
  266. package/docs/evidence/m6/install-0.2.0-rc.2.log.gz +0 -0
  267. package/docs/evidence/m6/install-0.2.1-alpha.1.json +28 -0
  268. package/docs/evidence/m6/install-0.2.1-alpha.1.log.gz +0 -0
  269. package/docs/evidence/m6/measure-isolated.mjs +42 -0
  270. package/docs/evidence/m6/metadata.log.gz +0 -0
  271. package/docs/evidence/m6/multi-display-installed-0.2.0-rc.2.json +557 -0
  272. package/docs/evidence/m6/multi-display-installed-0.2.1-alpha.1.json +557 -0
  273. package/docs/evidence/m6/multi-display-native.json +518 -0
  274. package/docs/evidence/m6/multi-display-native.png +0 -0
  275. package/docs/evidence/m6/multi-display-reader.png +0 -0
  276. package/docs/evidence/m6/multi-display-ui.json +133 -0
  277. package/docs/evidence/m6/native-pet.png +0 -0
  278. package/docs/evidence/m6/notification-host-0.2.0-rc.2.json +182 -0
  279. package/docs/evidence/m6/notification-host-0.2.1-alpha.1.json +182 -0
  280. package/docs/evidence/m6/notification-integration-0.2.0-rc.2.json +108 -0
  281. package/docs/evidence/m6/notification-integration-0.2.1-alpha.1.json +108 -0
  282. package/docs/evidence/m6/notification-source-0.2.0-rc.2.json +17 -0
  283. package/docs/evidence/m6/notification-source-0.2.1-alpha.1.json +17 -0
  284. package/docs/evidence/m6/notification-ui.log.gz +0 -0
  285. package/docs/evidence/m6/npm-ci.log.gz +0 -0
  286. package/docs/evidence/m6/pack.log.gz +0 -0
  287. package/docs/evidence/m6/package-negative-check.json +7 -0
  288. package/docs/evidence/m6/package-source-content.json +3310 -0
  289. package/docs/evidence/m6/package-verification.json +7 -0
  290. package/docs/evidence/m6/package.log.gz +0 -0
  291. package/docs/evidence/m6/previous-milestones.json +45 -0
  292. package/docs/evidence/m6/release-notes.md +12 -0
  293. package/docs/evidence/m6/resource-budget.json +12 -0
  294. package/docs/evidence/m6/resource-comparison.json +228 -0
  295. package/docs/evidence/m6/runtime-lock-0.2.0-rc.2.json.gz +0 -0
  296. package/docs/evidence/m6/runtime-lock-0.2.1-alpha.1.json.gz +0 -0
  297. package/docs/evidence/m6/session-host-0.2.0-rc.2.json +3181 -0
  298. package/docs/evidence/m6/session-host-0.2.1-alpha.1.json +3767 -0
  299. package/docs/evidence/m6/session-native-0.2.0-rc.2.json +1230 -0
  300. package/docs/evidence/m6/session-native-0.2.1-alpha.1.json +1424 -0
  301. package/docs/evidence/m6/settings-0.2.0-rc.2.png +0 -0
  302. package/docs/evidence/m6/settings-0.2.1-alpha.1.png +0 -0
  303. package/docs/evidence/m6/settings-dark-0.2.0-rc.2.png +0 -0
  304. package/docs/evidence/m6/settings-dark-0.2.1-alpha.1.png +0 -0
  305. package/docs/evidence/m6/settings-en-0.2.0-rc.2.png +0 -0
  306. package/docs/evidence/m6/settings-en-0.2.1-alpha.1.png +0 -0
  307. package/docs/evidence/m6/settings-system-en-US-0.2.0-rc.2.png +0 -0
  308. package/docs/evidence/m6/settings-system-en-US-0.2.1-alpha.1.png +0 -0
  309. package/docs/evidence/m6/settings-system-zh-CN-0.2.0-rc.2.png +0 -0
  310. package/docs/evidence/m6/settings-system-zh-CN-0.2.1-alpha.1.png +0 -0
  311. package/docs/evidence/m6/test.log.gz +0 -0
  312. package/docs/evidence/m6/text-scale-chat-en-US.png +0 -0
  313. package/docs/evidence/m6/text-scale-chat-zh-CN.png +0 -0
  314. package/docs/evidence/m6/text-scale-en-US-240-1.25.png +0 -0
  315. package/docs/evidence/m6/text-scale-en-US-240-1.5.png +0 -0
  316. package/docs/evidence/m6/text-scale-en-US-240-1.png +0 -0
  317. package/docs/evidence/m6/text-scale-en-US-90-1.25.png +0 -0
  318. package/docs/evidence/m6/text-scale-en-US-90-1.5.png +0 -0
  319. package/docs/evidence/m6/text-scale-en-US-90-1.png +0 -0
  320. package/docs/evidence/m6/text-scale-en-US.json +50 -0
  321. package/docs/evidence/m6/text-scale-inbox-en-US.png +0 -0
  322. package/docs/evidence/m6/text-scale-inbox-zh-CN.png +0 -0
  323. package/docs/evidence/m6/text-scale-installed-0.2.0-rc.2.json +629 -0
  324. package/docs/evidence/m6/text-scale-installed-0.2.0-rc.2.png +0 -0
  325. package/docs/evidence/m6/text-scale-installed-0.2.1-alpha.1.json +629 -0
  326. package/docs/evidence/m6/text-scale-installed-0.2.1-alpha.1.png +0 -0
  327. package/docs/evidence/m6/text-scale-native.json +1234 -0
  328. package/docs/evidence/m6/text-scale-native.png +0 -0
  329. package/docs/evidence/m6/text-scale-zh-CN-240-1.25.png +0 -0
  330. package/docs/evidence/m6/text-scale-zh-CN-240-1.5.png +0 -0
  331. package/docs/evidence/m6/text-scale-zh-CN-240-1.png +0 -0
  332. package/docs/evidence/m6/text-scale-zh-CN-90-1.25.png +0 -0
  333. package/docs/evidence/m6/text-scale-zh-CN-90-1.5.png +0 -0
  334. package/docs/evidence/m6/text-scale-zh-CN-90-1.png +0 -0
  335. package/docs/evidence/m6/text-scale-zh-CN.json +50 -0
  336. package/docs/evidence/m6/toolchain.log.gz +0 -0
  337. package/docs/evidence/m6/typecheck.log.gz +0 -0
  338. package/docs/evidence/m6/ui.log.gz +0 -0
  339. package/docs/evidence/m6/validation.json +852 -0
  340. package/docs/multi-display-contract.md +29 -0
  341. package/docs/notification-contract.md +25 -1
  342. package/docs/release-notes.md +30 -0
  343. package/docs/releasing.md +2 -0
  344. package/docs/roadmap.md +184 -0
  345. package/docs/session-chat-contract.md +44 -0
  346. package/docs/text-readability-contract.md +28 -0
  347. package/npm-shrinkwrap.json +32 -11
  348. package/package.json +20 -10
  349. package/scripts/check-package.mjs +5 -2
  350. package/scripts/measure-idle.mjs +76 -0
  351. package/src/bridge.ts +42 -20
  352. package/src/chat.ts +72 -0
  353. package/src/client/Settings.tsx +13 -4
  354. package/src/client/index.ts +21 -3
  355. package/src/client/locale-sync.ts +34 -0
  356. package/src/client/locales.ts +8 -2
  357. package/src/client/notification-copy.ts +5 -4
  358. package/src/client/settings.css +2 -0
  359. package/src/completion.ts +66 -0
  360. package/src/controls.ts +90 -28
  361. package/src/desktop-lifecycle.ts +10 -0
  362. package/src/index.ts +70 -27
  363. package/src/model.ts +21 -6
  364. package/src/notification-broker.ts +14 -7
  365. package/src/notification-contract.ts +4 -2
  366. package/tests/bridge.test.ts +123 -2
  367. package/tests/chat.test.ts +61 -0
  368. package/tests/completion.test.ts +110 -0
  369. package/tests/controls.test.ts +132 -2
  370. package/tests/daily-rhythm-native.mjs +51 -0
  371. package/tests/daily-rhythm-ui.mjs +166 -0
  372. package/tests/daily-rhythm.test.js +83 -0
  373. package/tests/desktop.mjs +96 -7
  374. package/tests/display-geometry.test.js +55 -0
  375. package/tests/fixtures/desktop-recovery.ts +3 -0
  376. package/tests/fixtures/goal-host.mjs +104 -0
  377. package/tests/fixtures/host.mjs +40 -1
  378. package/tests/fixtures/session-host.mjs +119 -0
  379. package/tests/goal-host-contract.mjs +53 -0
  380. package/tests/helpers/daily-rhythm.mjs +34 -0
  381. package/tests/helpers/desktop-recovery.mjs +25 -0
  382. package/tests/helpers/installed-notifications.mjs +1 -1
  383. package/tests/helpers/multi-display-native.mjs +19 -0
  384. package/tests/helpers/native-pointer.mjs +37 -9
  385. package/tests/helpers/text-scale-native.mjs +34 -0
  386. package/tests/inbox-ui.mjs +2 -1
  387. package/tests/install.mjs +144 -3
  388. package/tests/locale-client.mjs +25 -0
  389. package/tests/locale-sync.test.ts +36 -0
  390. package/tests/locale-ui.mjs +79 -0
  391. package/tests/model.test.ts +15 -4
  392. package/tests/multi-display-native.mjs +91 -0
  393. package/tests/multi-display-ui.mjs +95 -0
  394. package/tests/notification-broker.test.ts +1 -1
  395. package/tests/notification-client.test.ts +8 -1
  396. package/tests/notification-integration.test.ts +50 -2
  397. package/tests/notification-ui.mjs +18 -0
  398. package/tests/plugin.test.ts +84 -13
  399. package/tests/presentation.test.js +27 -1
  400. package/tests/session-host-contract.mjs +53 -0
  401. package/tests/session-recovery.test.ts +20 -0
  402. package/tests/session-replies-ui.mjs +73 -1
  403. package/tests/text-scale-ui.mjs +113 -0
  404. package/tests/text-scale.test.ts +7 -0
  405. package/tests/ui.mjs +3 -1
  406. package/web/chat-contract.d.ts +4 -0
  407. package/web/chat-contract.js +14 -0
  408. package/web/daily-rhythm.d.ts +6 -0
  409. package/web/daily-rhythm.js +38 -0
  410. package/web/display-geometry.js +30 -0
  411. package/web/index.html +42 -42
  412. package/web/locale.d.ts +8 -0
  413. package/web/locale.js +106 -0
  414. package/web/notification-ui.js +6 -5
  415. package/web/pet.js +238 -83
  416. package/web/session-ui.js +32 -2
  417. package/web/style.css +79 -59
  418. package/web/text-scale.d.ts +4 -0
  419. package/web/text-scale.js +6 -0
package/dist/index.js CHANGED
@@ -1,6 +1,57 @@
1
1
  // src/index.ts
2
2
  import { randomUUID as randomUUID2 } from "node:crypto";
3
- import { SessionId } from "@deepseek-ai/dsh-session";
3
+ import { SessionId as SessionId2 } from "@deepseek-ai/dsh-session";
4
+
5
+ // src/completion.ts
6
+ import { applyGoalProjection, goalProjectionDefinition } from "@deepseek-ai/dsh-goal";
7
+ var reply = { category: "reply", mood: "idle", text: "\u672C\u8F6E\u56DE\u590D\u5DF2\u751F\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002" };
8
+ var CompletionTracker = class {
9
+ state = goalProjectionDefinition.init();
10
+ turn = 0;
11
+ open = false;
12
+ ended = -1;
13
+ startSeq = -1;
14
+ completeSeq = -1;
15
+ announced = "";
16
+ consume(event) {
17
+ if (event.type === "goal/change" || event.type === "user/message" && event.data.source.kind === "goal") {
18
+ this.state = applyGoalProjection(this.state, event);
19
+ if (event.type === "goal/change" && !this.state.failure) {
20
+ if (event.data.operation === "complete") this.completeSeq = event.seq;
21
+ if (!this.open || event.data.operation === "clear") {
22
+ if (["complete", "block", "pause"].includes(event.data.operation)) return this.decision(event.seq);
23
+ if (event.data.operation === "clear") return { ...reply, text: "\u51C6\u5907\u597D\u4E86\uFF0C\u968F\u65F6\u53EB\u6211\u3002", silent: true, clear: true };
24
+ return { ...this.decision(event.seq), text: "\u76EE\u6807\u72B6\u6001\u5DF2\u66F4\u65B0\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002", silent: true };
25
+ }
26
+ }
27
+ }
28
+ if (event.type === "turn/start" && event.data.turn > this.turn && event.data.turn > this.ended) {
29
+ this.turn = event.data.turn;
30
+ this.open = true;
31
+ this.startSeq = event.seq;
32
+ }
33
+ if (event.type !== "turn/end" || event.data.turn < this.turn || event.data.turn <= this.ended) return;
34
+ this.turn = event.data.turn;
35
+ this.ended = event.data.turn;
36
+ this.open = false;
37
+ if (event.data.reason.kind !== "completed") return;
38
+ return this.decision(event.seq);
39
+ }
40
+ decision(seq) {
41
+ const current = this.state.failure ? null : this.state.current;
42
+ if (!current) return { ...reply };
43
+ const goal = { id: current.goal.id, revision: current.goal.revision, round: current.roundsStarted };
44
+ if (current.goal.phase === "active") return { category: "goal-progress", mood: "idle", text: "\u672C\u8F6E\u56DE\u590D\u5DF2\u751F\u6210\uFF0C\u76EE\u6807\u4ECD\u5728\u8FDB\u884C\u4E2D\u3002", goal };
45
+ if (current.goal.phase === "paused") return { category: "stopped", mood: "idle", text: "\u76EE\u6807\u5DF2\u6682\u505C\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002", goal };
46
+ if (current.goal.phase === "blocked") return { category: "blocked", mood: "waiting", text: "\u76EE\u6807\u9047\u5230\u963B\u788D\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002", goal };
47
+ const identity = JSON.stringify([goal.id, goal.revision]);
48
+ if (this.completeSeq >= this.startSeq && this.completeSeq <= seq && this.announced !== identity) {
49
+ this.announced = identity;
50
+ return { category: "completed", mood: "happy", text: "\u76EE\u6807\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002", goal };
51
+ }
52
+ return { ...reply };
53
+ }
54
+ };
4
55
 
5
56
  // src/notification-broker.ts
6
57
  import { randomUUID } from "node:crypto";
@@ -22,7 +73,8 @@ var noticeSchema = z.object({
22
73
  turn: counter,
23
74
  seq: counter,
24
75
  time: counter,
25
- category: z.enum(["completed", "approval", "question", "error", "stopped", "interrupted", "blocked", "max-tokens"]),
76
+ category: z.enum(["reply", "goal-progress", "completed", "approval", "question", "error", "stopped", "interrupted", "blocked", "max-tokens"]),
77
+ goal: z.object({ id, revision: counter.positive(), round: counter }).strict().optional(),
26
78
  stage: z.enum(["initial", "reminder"]),
27
79
  title: z.string().max(256),
28
80
  body: z.string().max(2048),
@@ -55,12 +107,15 @@ var interactionSchema = z.object({
55
107
  automaticReminders: z.number().int().min(0).max(1)
56
108
  }).strict();
57
109
  var runtimeSchema = z.object({
58
- phase: z.enum(["stopped", "starting", "running", "stopping", "error"]),
110
+ phase: z.enum(["stopped", "starting", "running", "stopping", "recovering", "error"]),
59
111
  generation: counter,
60
112
  visibilityRevision: counter,
61
113
  visible: z.boolean(),
62
114
  suspended: z.boolean(),
63
- error: z.string().max(600).optional()
115
+ error: z.string().max(600).optional(),
116
+ desiredVisible: z.boolean().optional(),
117
+ recoveryAttempt: counter.max(3).optional(),
118
+ retryAt: counter.optional()
64
119
  }).strict();
65
120
  var deliveryClaimSchema = z.object({
66
121
  token: id,
@@ -99,7 +154,9 @@ var realClock = {
99
154
  clearTimeout: (timer) => clearTimeout(timer)
100
155
  };
101
156
  var title = {
102
- completed: "\u4EFB\u52A1\u5B8C\u6210",
157
+ reply: "\u672C\u8F6E\u56DE\u590D\u5DF2\u751F\u6210",
158
+ "goal-progress": "\u76EE\u6807\u4ECD\u5728\u8FDB\u884C\u4E2D",
159
+ completed: "\u76EE\u6807\u5DF2\u5B8C\u6210",
103
160
  approval: "\u7B49\u4F60\u786E\u8BA4",
104
161
  question: "\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60",
105
162
  error: "\u9700\u8981\u5173\u6CE8",
@@ -109,7 +166,9 @@ var title = {
109
166
  "max-tokens": "\u8F93\u51FA\u8FBE\u5230\u4E0A\u9650"
110
167
  };
111
168
  var body = {
112
- completed: "\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002",
169
+ reply: "\u672C\u8F6E\u56DE\u590D\u5DF2\u751F\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002",
170
+ "goal-progress": "\u672C\u8F6E\u56DE\u590D\u5DF2\u751F\u6210\uFF0C\u76EE\u6807\u4ECD\u5728\u8FDB\u884C\u4E2D\u3002",
171
+ completed: "\u76EE\u6807\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002",
113
172
  approval: "\u4E0B\u4E00\u6B65\u9700\u8981\u4F60\u786E\u8BA4\u3002",
114
173
  question: "\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60\u3002",
115
174
  error: "\u4EFB\u52A1\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u966A\u4F60\u56DE\u53BB\u770B\u770B\u3002",
@@ -194,7 +253,7 @@ var NotificationBroker = class {
194
253
  let state = this.sources.get(session.id);
195
254
  if (!state) {
196
255
  if (this.sources.size >= 100) this.remove(this.sources.keys().next().value);
197
- state = { seq: -1, turn: 0, finalText: "", calls: /* @__PURE__ */ new Map(), label: session.header.cwd?.split(/[\\/]/).filter(Boolean).at(-1) ?? "\u4F1A\u8BDD" };
256
+ state = { completion: new CompletionTracker(), ended: -1, seq: -1, turn: 0, finalText: "", calls: /* @__PURE__ */ new Map(), label: session.header.cwd?.split(/[\\/]/).filter(Boolean).at(-1) ?? "\u4F1A\u8BDD" };
198
257
  this.sources.set(session.id, state);
199
258
  }
200
259
  return state;
@@ -203,20 +262,25 @@ var NotificationBroker = class {
203
262
  const source = this.source(session);
204
263
  if (event.seq <= source.seq) return;
205
264
  source.seq = event.seq;
265
+ const completion = source.completion.consume(event);
266
+ if (event.type === "goal/change" && completion && !completion.silent && live) {
267
+ this.enqueue({ ...this.notice(session.id, source.turn, event.seq, event.time, completion.category, completion.text), goal: completion.goal });
268
+ }
206
269
  if (event.type === "approval/decided") {
207
270
  this.settle(interactionId(session.id, "approval", event.data.id));
208
271
  return;
209
272
  }
210
273
  if (event.type === "user/message") {
211
- const reply = event.data.source;
212
- if (reply.kind === "user-question-reply" && reply.callId) {
213
- this.settle(interactionId(session.id, "question", reply.callId));
274
+ const reply2 = event.data.source;
275
+ if (reply2.kind === "user-question-reply" && reply2.callId) {
276
+ this.settle(interactionId(session.id, "question", reply2.callId));
214
277
  return;
215
278
  }
216
279
  }
217
280
  if ("turn" in event.data && event.data.turn !== void 0 && event.data.turn < source.turn) return;
218
281
  switch (event.type) {
219
282
  case "turn/start":
283
+ if (event.data.turn <= source.ended) break;
220
284
  source.turn = event.data.turn;
221
285
  source.finalText = "";
222
286
  break;
@@ -233,10 +297,12 @@ var NotificationBroker = class {
233
297
  this.open(session.id, "approval", event.data.id, source.turn, event.seq, event.time, `${event.data.toolName}: ${event.data.reason ?? body.approval}`, false, live);
234
298
  break;
235
299
  case "turn/end": {
300
+ if (event.data.turn <= source.ended) break;
301
+ source.ended = event.data.turn;
236
302
  source.turn = event.data.turn;
237
303
  if (event.data.reason.kind === "forked") break;
238
- const category = event.data.reason.kind === "aborted" ? "stopped" : event.data.reason.kind;
239
- if (live) this.enqueue(this.notice(session.id, source.turn, event.seq, event.time, category, source.finalText && category === "completed" ? source.finalText : body[category]));
304
+ const category = completion?.category ?? (event.data.reason.kind === "aborted" ? "stopped" : event.data.reason.kind);
305
+ if (live) this.enqueue({ ...this.notice(session.id, source.turn, event.seq, event.time, category, source.finalText && event.data.reason.kind === "completed" ? source.finalText : completion?.text ?? body[category]), ...completion?.goal ? { goal: completion.goal } : {} });
240
306
  source.finalText = "";
241
307
  for (const r of this.requests.values()) if (r.sessionId === session.id && r.kind === "approval" && r.turn <= source.turn) this.settle(r.id);
242
308
  break;
@@ -502,8 +568,97 @@ var NotificationBroker = class {
502
568
  }
503
569
  };
504
570
 
571
+ // src/chat.ts
572
+ import { SessionId } from "@deepseek-ai/dsh-session";
573
+
574
+ // web/chat-contract.js
575
+ function chatRequest(value) {
576
+ if (!value || value.type !== "chat" || Object.keys(value).some((k) => !["type", "sessionId", "requestId", "text", "clientTimeZone"].includes(k))) return;
577
+ if (typeof value.sessionId !== "string" || !value.sessionId || value.sessionId.length > 512 || typeof value.requestId !== "string" || !/^[A-Za-z0-9:_-]{1,128}$/.test(value.requestId)) return;
578
+ if (typeof value.text !== "string" || !value.text.trim() || value.text.length > 2e3 || typeof value.clientTimeZone !== "string" || value.clientTimeZone.length > 100) return;
579
+ try {
580
+ const clientTimeZone = new Intl.DateTimeFormat("en", { timeZone: value.clientTimeZone }).resolvedOptions().timeZone;
581
+ return { type: "chat", sessionId: value.sessionId, requestId: value.requestId, text: value.text.trim(), clientTimeZone };
582
+ } catch {
583
+ return;
584
+ }
585
+ }
586
+
587
+ // src/chat.ts
588
+ var ChatSubmission = class {
589
+ constructor(ctx) {
590
+ this.ctx = ctx;
591
+ }
592
+ tails = /* @__PURE__ */ new Map();
593
+ requests = /* @__PURE__ */ new Map();
594
+ async submit(value, signal) {
595
+ const input = chatRequest(value);
596
+ if (!input) return;
597
+ const identity = JSON.stringify(input);
598
+ const result = (status, code) => status === "accepted" ? { type: "chat-result", sessionId: input.sessionId, requestId: input.requestId, status } : { type: "chat-result", sessionId: input.sessionId, requestId: input.requestId, status, code };
599
+ if (this.requests.has(input.requestId) && this.requests.get(input.requestId) !== identity) return result("failed", "coopanion/request-conflict");
600
+ this.requests.set(input.requestId, identity);
601
+ if (this.requests.size > 512) this.requests.delete(this.requests.keys().next().value);
602
+ const previous = this.tails.get(input.sessionId) ?? Promise.resolve();
603
+ const task = previous.catch(() => {
604
+ }).then(async () => {
605
+ try {
606
+ await this.admit(input, signal);
607
+ return result("accepted");
608
+ } catch (error) {
609
+ const code = signal.aborted ? "gateway/cancelled" : chatErrorCode(error);
610
+ return result("failed", code);
611
+ }
612
+ });
613
+ this.tails.set(input.sessionId, task);
614
+ try {
615
+ return await task;
616
+ } finally {
617
+ if (this.tails.get(input.sessionId) === task) this.tails.delete(input.sessionId);
618
+ }
619
+ }
620
+ async admit(input, signal) {
621
+ const reject = (code) => {
622
+ throw Object.assign(new Error(code), { code });
623
+ };
624
+ signal.throwIfAborted();
625
+ const controller = this.ctx.get("sessionController"), query = this.ctx.get("sessionQuery");
626
+ if (!controller || !query) reject("coopanion/service-unavailable");
627
+ const observed = await query.observeSession(SessionId(input.sessionId), { signal });
628
+ try {
629
+ if (observed.header.id !== input.sessionId || !observed.header.cwd) reject("session/not-found");
630
+ if (observed.header.origin === "subagent") reject("session/subagent-owned");
631
+ const messages = observed.events.flatMap((event) => event.type === "user/message" ? [event.data] : event.type === "agent/inbox/spliced" ? event.data.inserted : []);
632
+ const matches = messages.filter((message) => message.source.kind === "user" && "rpcId" in message.source && message.source.rpcId === input.requestId);
633
+ if (matches.length) {
634
+ if (matches.some((message) => JSON.stringify(message.content) !== JSON.stringify([{ type: "text", text: input.text }]) || !("clientTimeZone" in message.source) || message.source.clientTimeZone !== input.clientTimeZone)) reject("coopanion/request-conflict");
635
+ return;
636
+ }
637
+ const catalog = await controller.modelCatalog();
638
+ const selected = observed.projections?.values.modelSelection?.next ?? catalog.default;
639
+ if (!catalog.groups.some((group) => group.id === selected.provider && group.models.some((model) => model.id === selected.model))) reject("session/model-unavailable");
640
+ } finally {
641
+ observed[Symbol.dispose]();
642
+ }
643
+ signal.throwIfAborted();
644
+ const receipt = await controller.prompt({ sessionId: SessionId(input.sessionId), requestId: input.requestId, mode: "queue", content: [{ type: "text", text: input.text }], clientTimeZone: input.clientTimeZone }, signal);
645
+ if (receipt.accepted !== true) reject("coopanion/no-receipt");
646
+ }
647
+ };
648
+ function chatErrorCode(error) {
649
+ let current = error;
650
+ for (let depth = 0; depth < 8 && current && typeof current === "object"; depth++) {
651
+ const value = current;
652
+ if (value.code === "EACCES" || value.code === "EPERM") return "gateway/forbidden";
653
+ current = value.cause;
654
+ }
655
+ const code = error?.code;
656
+ if (code === "SESSION_QUERY_SESSION_NOT_FOUND") return "session/not-found";
657
+ if (code === "SESSION_QUERY_ABORTED") return "gateway/cancelled";
658
+ return typeof code === "string" ? code : "coopanion/unavailable";
659
+ }
660
+
505
661
  // src/index.ts
506
- import { createUserMessage } from "@deepseek-ai/dsh-llm";
507
662
  import z2 from "@deepseek-ai/schemastery";
508
663
 
509
664
  // src/bridge.ts
@@ -511,39 +666,59 @@ import { spawn } from "node:child_process";
511
666
  import { createRequire } from "node:module";
512
667
  import { fileURLToPath } from "node:url";
513
668
  import { EventEmitter } from "node:events";
669
+
670
+ // src/desktop-lifecycle.ts
671
+ var NativeStartError = class extends Error {
672
+ constructor(message, recoverable) {
673
+ super(message);
674
+ this.recoverable = recoverable;
675
+ this.name = "NativeStartError";
676
+ }
677
+ };
678
+
679
+ // src/bridge.ts
514
680
  var ElectronBridge = class extends EventEmitter {
515
681
  child;
516
682
  latest;
683
+ latestOptions;
517
684
  resultKey;
518
685
  closing = false;
519
686
  generation = 0;
520
687
  visibilityRevision = 0;
521
688
  nativeVisible = false;
522
689
  suspended = false;
690
+ screenLocked = false;
691
+ systemAsleep = false;
523
692
  lastNotificationState;
524
693
  async start(options, lifetime) {
525
- if (this.child) throw new Error("Desktop pet is already running");
694
+ if (this.child) throw new NativeStartError("Desktop pet is already running", false);
526
695
  if (lifetime?.signal.aborted) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
696
+ this.latestOptions = { ...options };
527
697
  this.closing = false;
528
698
  this.generation = lifetime?.generation ?? this.generation + 1;
529
699
  this.visibilityRevision = 0;
530
700
  this.nativeVisible = false;
531
- this.suspended = false;
532
- if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new Error("\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002");
533
- const executable = options.electronPath ?? createRequire(import.meta.url)("electron");
534
- const env = { ...process.env, DSH_PET_GENERATION: String(this.generation) };
701
+ if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new NativeStartError("\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002", false);
702
+ let executable;
703
+ try {
704
+ executable = options.electronPath ?? createRequire(import.meta.url)("electron");
705
+ } catch (error) {
706
+ throw new NativeStartError(String(error).slice(0, 600), false);
707
+ }
708
+ const env = { ...process.env, DSH_PET_GENERATION: String(this.generation), DSH_PET_VISIBLE: lifetime?.visible === false ? "0" : "1", DSH_PET_SCREEN_LOCKED: this.screenLocked ? "1" : "0", DSH_PET_SYSTEM_ASLEEP: this.systemAsleep ? "1" : "0" };
535
709
  delete env.ELECTRON_RUN_AS_NODE;
536
710
  const args = [fileURLToPath(new URL("../desktop/main.cjs", import.meta.url))];
537
711
  if (env.DSH_PET_TEST_NO_SANDBOX === "1") args.unshift("--no-sandbox");
538
712
  const child = spawn(executable, args, { env, stdio: ["ignore", "pipe", "pipe", "ipc"] });
539
713
  const generation = this.generation;
540
714
  this.child = child;
541
- let diagnostic = "";
715
+ let diagnostic = "", userClosed = false;
542
716
  child.stderr?.on("data", (data) => {
543
717
  diagnostic = (diagnostic + data.toString()).slice(-4e3);
544
718
  });
545
719
  child.on("message", (message) => {
546
- if (this.child !== child || !isRecord(message)) return;
720
+ if (this.child !== child || this.closing || lifetime?.signal.aborted || !isRecord(message)) return;
721
+ if (message.type === "closed") userClosed = true;
547
722
  if (message.type === "action") this.emit("action", message.action);
548
723
  if (message.type === "tray-state") this.emit("tray-state", message.state);
549
724
  if (message.type === "tray-icon") this.emit("tray-icon", message);
@@ -551,17 +726,23 @@ var ElectronBridge = class extends EventEmitter {
551
726
  this.visibilityRevision = message.visibilityRevision;
552
727
  this.nativeVisible = message.visible;
553
728
  this.suspended = message.suspended === true;
554
- this.emit("lifecycle", { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended });
729
+ if (typeof message.screenLocked === "boolean") this.screenLocked = message.screenLocked;
730
+ if (typeof message.systemAsleep === "boolean") this.systemAsleep = message.systemAsleep;
731
+ this.emit("lifecycle", { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended, ...typeof message.desiredVisible === "boolean" ? { desiredVisible: message.desiredVisible } : {} });
555
732
  }
556
733
  });
557
734
  child.once("exit", (code, signal) => {
558
735
  if (this.child !== child) return;
559
736
  this.child = void 0;
560
737
  this.nativeVisible = false;
561
- const error = !this.closing && (code !== 0 || signal) ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code})` : void 0;
562
- this.emit("lifecycle", { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, ...error ? { error } : {} });
738
+ const unexpected = !this.closing && !userClosed && !lifetime?.signal.aborted;
739
+ const error = unexpected ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code}): ${diagnostic}`.slice(0, 600) : void 0;
740
+ this.emit("lifecycle", { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, unexpected, ...error ? { error } : {} });
563
741
  if (error) this.emit("failure", new Error(error));
564
742
  });
743
+ child.on("error", (error) => {
744
+ if (this.child === child && !this.closing && !lifetime?.signal.aborted) this.emit("failure", error);
745
+ });
565
746
  await new Promise((resolve, reject) => {
566
747
  let done = false;
567
748
  const finish = (error) => {
@@ -578,25 +759,27 @@ var ElectronBridge = class extends EventEmitter {
578
759
  } else resolve();
579
760
  };
580
761
  const ready2 = (message) => {
762
+ if (isRecord(message) && message.type === "startup-error" && this.child === child && typeof message.error === "string") {
763
+ finish(new NativeStartError(message.error.slice(0, 600), message.recoverable === true));
764
+ return;
765
+ }
581
766
  if (isRecord(message) && message.type === "ready" && this.child === child && !lifetime?.signal.aborted) {
582
- this.send({ type: "init", options, snapshot: this.latest && desktopSnapshot(this.latest, true) });
767
+ this.resultKey = void 0;
768
+ this.send({ type: "init", options: { ...this.latestOptions, locale: this.latestOptions?.locale ?? null }, baseline: true, snapshot: this.latest && desktopSnapshot(this.latest, true) });
583
769
  if (this.lastNotificationState) this.notificationState(this.lastNotificationState);
584
770
  finish();
585
771
  }
586
772
  };
587
- const failed = (error) => finish(error);
588
- const exited = (code, signal) => finish(new Error(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`));
773
+ const failed = (error) => finish(new NativeStartError(error.message.slice(0, 600), error.code === "EAGAIN" || error.code === "ENOMEM"));
774
+ const exited = (code, signal) => finish(new NativeStartError(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`.slice(0, 600), true));
589
775
  const aborted = () => finish(new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88"));
590
- const timer = setTimeout(() => finish(new Error(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`)), 2e4);
776
+ const timer = setTimeout(() => finish(new NativeStartError(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`.slice(0, 600), true)), 2e4);
591
777
  child.on("message", ready2);
592
778
  child.once("error", failed);
593
779
  child.once("exit", exited);
594
780
  lifetime?.signal.addEventListener("abort", aborted, { once: true });
595
781
  if (lifetime?.signal.aborted) aborted();
596
782
  });
597
- child.on("error", (error) => {
598
- if (this.child === child && !this.closing) this.emit("failure", error);
599
- });
600
783
  }
601
784
  update(snapshot) {
602
785
  this.latest = snapshot;
@@ -619,14 +802,21 @@ var ElectronBridge = class extends EventEmitter {
619
802
  this.send({ type: "notice", notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision });
620
803
  return true;
621
804
  }
805
+ chatResult(receipt) {
806
+ this.send(receipt);
807
+ }
622
808
  onAction(listener) {
623
809
  this.on("action", listener);
624
810
  }
625
811
  removeAction(listener) {
626
812
  this.off("action", listener);
627
813
  }
814
+ // JSON IPC omits undefined. An explicit null lets a cleared Harness
815
+ // preference restore the renderer's automatic language instead of retaining
816
+ // its previous locale during a merged configuration update.
628
817
  configure(options) {
629
- this.send({ type: "configure", options });
818
+ this.latestOptions = { ...options };
819
+ this.send({ type: "configure", options: { ...options, locale: options.locale ?? null } });
630
820
  }
631
821
  control(command) {
632
822
  this.send({ type: "control", command });
@@ -641,8 +831,9 @@ var ElectronBridge = class extends EventEmitter {
641
831
  this.off("lifecycle", listener);
642
832
  }
643
833
  send(message) {
644
- if (this.child?.connected) this.child.send(message, (error) => {
645
- if (error && !this.closing) this.emit("failure", error);
834
+ const child = this.child;
835
+ if (child?.connected && !this.closing) child.send(message, (error) => {
836
+ if (error && this.child === child && !this.closing) this.emit("failure", error);
646
837
  });
647
838
  }
648
839
  async dispose() {
@@ -710,7 +901,7 @@ var PetModel = class {
710
901
  const project = session.header.cwd ? basename(session.header.cwd) : "\u672A\u6307\u5B9A\u9879\u76EE";
711
902
  item = { id: session.id, label: project, project, cwd: session.header.cwd ?? "", prompt: "", createdAt: session.header.createdAt, updatedAt: session.header.createdAt, mood: "idle", text: ready, reply: "", replyId: "", unread: 0, revision: 0, active: false, streaming: false, speechId: "" };
712
903
  this.sessions.set(session.id, item);
713
- this.tasks.set(session.id, { seq: -1, turn: 0, active: false, tools: /* @__PURE__ */ new Map(), approvals: /* @__PURE__ */ new Set(), questions: /* @__PURE__ */ new Set(), requests: /* @__PURE__ */ new Set(), celebrateUntil: 0 });
904
+ this.tasks.set(session.id, { completion: new CompletionTracker(), ended: -1, seq: -1, turn: 0, active: false, tools: /* @__PURE__ */ new Map(), approvals: /* @__PURE__ */ new Set(), questions: /* @__PURE__ */ new Set(), requests: /* @__PURE__ */ new Set(), celebrateUntil: 0 });
714
905
  this.selected ??= session.id;
715
906
  for (const event of session.snapshotEvents?.() ?? []) this.describe(item, event);
716
907
  }
@@ -810,6 +1001,7 @@ var PetModel = class {
810
1001
  task.celebrateUntil = 0;
811
1002
  const item = this.sessions.get(id2);
812
1003
  if (!task.active && item.mood === "happy") {
1004
+ delete item.completion;
813
1005
  this.present(item, "idle", ready);
814
1006
  changed = true;
815
1007
  }
@@ -826,9 +1018,19 @@ var PetModel = class {
826
1018
  if (event.seq <= task.seq) return;
827
1019
  task.seq = event.seq;
828
1020
  this.describe(item, event);
1021
+ const completion = task.completion.consume(event);
1022
+ if (event.type === "goal/change" && completion && live) {
1023
+ if (!completion.silent || !task.active) this.present(item, completion.mood, completion.text);
1024
+ if (completion.clear) delete item.completion;
1025
+ else item.completion = completion.category;
1026
+ task.celebrateUntil = completion.mood === "happy" ? this.now() + 2500 : 0;
1027
+ return completion.silent ? void 0 : { title: `${item.label} \xB7 ${completion.text}`, body: completion.text, sessionId: item.id, kind: "task", category: completion.category, goal: completion.goal };
1028
+ }
829
1029
  if ("turn" in event.data && event.data.turn < task.turn) return;
830
1030
  switch (event.type) {
831
1031
  case "turn/start":
1032
+ if (event.data.turn <= task.ended) return;
1033
+ delete item.completion;
832
1034
  task.turn = event.data.turn;
833
1035
  task.active = true;
834
1036
  task.tools.clear();
@@ -881,6 +1083,8 @@ var PetModel = class {
881
1083
  this.approvalSettled(item.id, event.data.id);
882
1084
  break;
883
1085
  case "turn/end": {
1086
+ if (event.data.turn <= task.ended) return;
1087
+ task.ended = event.data.turn;
884
1088
  task.turn = event.data.turn;
885
1089
  task.active = false;
886
1090
  task.tools.clear();
@@ -905,9 +1109,11 @@ var PetModel = class {
905
1109
  }
906
1110
  }
907
1111
  task.finalText = void 0;
908
- this.present(item, live ? "happy" : "idle", live ? text || "\u4EFB\u52A1\u5B8C\u6210" : ready);
909
- task.celebrateUntil = live ? this.now() + 2500 : 0;
910
- return live ? { title: `${item.label} \xB7 \u4EFB\u52A1\u5B8C\u6210`, body: text.slice(0, 180) || "\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002", sessionId: item.id, kind: "task" } : void 0;
1112
+ const outcome = completion;
1113
+ item.completion = outcome.category;
1114
+ this.present(item, live ? outcome.mood : "idle", live ? outcome.text : ready);
1115
+ task.celebrateUntil = live && outcome.mood === "happy" ? this.now() + 2500 : 0;
1116
+ return live ? { title: `${item.label} \xB7 ${outcome.text}`, body: text.slice(0, 180) || outcome.text, sessionId: item.id, kind: "task", category: outcome.category, goal: outcome.goal } : void 0;
911
1117
  }
912
1118
  case "error":
913
1119
  this.present(item, "error", "\u4EFB\u52A1\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u8BF7\u56DE\u5230 Harness \u67E5\u770B\u8BE6\u60C5\u3002");
@@ -957,6 +1163,7 @@ var PetModel = class {
957
1163
  task.questions = new Set(pending.filter((value) => value.kind === "question").map((value) => value.id));
958
1164
  const item = this.sessions.get(id2);
959
1165
  if (pending.length) {
1166
+ delete item.completion;
960
1167
  task.celebrateUntil = 0;
961
1168
  this.present(item, "waiting", pending.some((value) => value.kind === "question") ? "\u6709\u4E2A\u95EE\u9898\u60F3\u95EE\u4F60\uFF0C\u8BF7\u56DE\u5230 Harness \u770B\u770B\u3002" : "\u4E0B\u4E00\u6B65\u9700\u8981\u4F60\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230 Harness\u3002");
962
1169
  } else if (wasPending && !task.approvals.size && item.mood === "waiting") {
@@ -1007,16 +1214,37 @@ var PetControls = class {
1007
1214
  this.limits = limits;
1008
1215
  bridge.onLifecycle?.(this.changed);
1009
1216
  }
1010
- state = { phase: "stopped", visible: false, generation: 0, visibilityRevision: 0, suspended: false };
1217
+ state = { phase: "stopped", visible: false, desiredVisible: true, recoveryAttempt: 0, generation: 0, visibilityRevision: 0, suspended: false };
1011
1218
  queue = Promise.resolve();
1012
1219
  disposed = false;
1013
1220
  startup;
1221
+ startupExit;
1222
+ retry;
1223
+ stable;
1224
+ epoch = 0;
1225
+ wanted = false;
1226
+ cleanupBlocked = false;
1014
1227
  listeners = /* @__PURE__ */ new Set();
1015
1228
  changed = (event) => {
1016
1229
  if (this.disposed || event.generation !== this.state.generation || !Number.isSafeInteger(event.visibilityRevision) || event.visibilityRevision < this.state.visibilityRevision) return;
1017
1230
  if (event.visibilityRevision === this.state.visibilityRevision && event.visible !== this.state.visible) return;
1018
- if (this.state.phase === "stopping" || (this.state.phase === "stopped" || this.state.phase === "error") && event.running) return;
1019
- this.set({ ...this.state, phase: event.error ? "error" : event.running ? this.state.phase === "starting" ? "starting" : "running" : "stopped", visible: event.running && event.visible, visibilityRevision: event.visibilityRevision, suspended: event.suspended ?? false, ...event.error ? { error: event.error.slice(0, 600) } : {} });
1231
+ if (this.state.phase !== "starting" && this.state.phase !== "running") return;
1232
+ const starting = this.state.phase === "starting", wasSuspended = this.state.suspended;
1233
+ this.set({ ...this.state, phase: event.running ? starting ? "starting" : "running" : starting ? "starting" : "stopped", visible: event.running && event.visible, visibilityRevision: event.visibilityRevision, suspended: event.suspended ?? false, desiredVisible: starting ? this.state.desiredVisible : event.desiredVisible ?? this.state.desiredVisible, ...event.error ? { error: event.error.slice(0, 600) } : {} });
1234
+ if (!event.running) {
1235
+ this.clearStable();
1236
+ if (starting) {
1237
+ this.startupExit = new NativeStartError(event.error ?? "\u684C\u5BA0\u542F\u52A8\u671F\u95F4\u9000\u51FA", event.unexpected === true);
1238
+ this.startup?.abort();
1239
+ }
1240
+ if (!starting) {
1241
+ if (!event.unexpected) this.wanted = false;
1242
+ else {
1243
+ const epoch = this.epoch;
1244
+ void this.enqueue(() => this.failed(event.error ?? "\u684C\u5BA0\u8FDB\u7A0B\u610F\u5916\u9000\u51FA", true, epoch));
1245
+ }
1246
+ }
1247
+ } else if (!starting && wasSuspended !== this.state.suspended) this.armStable();
1020
1248
  };
1021
1249
  status() {
1022
1250
  return { ...this.state };
@@ -1034,39 +1262,50 @@ var PetControls = class {
1034
1262
  this.bridge.configure?.(this.options());
1035
1263
  }
1036
1264
  command(command) {
1037
- if (command === "stop" || command === "restart") this.startup?.abort();
1265
+ if (command === "hide") this.set({ ...this.state, desiredVisible: false });
1266
+ else if (command === "start" || command === "show" || command === "characters") this.set({ ...this.state, desiredVisible: true });
1267
+ if (command === "stop" || command === "restart" || command !== "hide" && this.state.phase !== "starting" && this.state.phase !== "running") {
1268
+ this.wanted = command !== "stop";
1269
+ this.epoch++;
1270
+ this.clearRetry();
1271
+ if (command === "stop" || command === "restart") {
1272
+ this.startup?.abort();
1273
+ this.clearStable();
1274
+ }
1275
+ }
1276
+ const epoch = this.epoch;
1038
1277
  return this.enqueue(async () => {
1039
1278
  if (this.disposed) throw new Error("\u684C\u5BA0\u63D2\u4EF6\u5DF2\u505C\u7528");
1279
+ if (epoch !== this.epoch) return this.status();
1040
1280
  try {
1281
+ let launched = false;
1041
1282
  if (command === "stop" || command === "restart") {
1042
- this.set({ ...this.state, phase: "stopping", visible: false, suspended: false });
1283
+ this.set({ ...this.state, phase: "stopping", visible: false, suspended: false, retryAt: void 0, error: void 0 });
1043
1284
  await this.cleanup();
1044
1285
  this.set({ ...this.state, phase: "stopped", visible: false, suspended: false });
1045
1286
  }
1046
1287
  if (command !== "stop" && command !== "hide" && this.state.phase !== "running") {
1047
- const startup = new AbortController();
1048
- this.startup = startup;
1049
- this.set({ phase: "starting", visible: false, generation: this.state.generation + 1, visibilityRevision: 0, suspended: false });
1050
- await this.withDeadline(this.bridge.start(this.options(), { signal: startup.signal, generation: this.state.generation }), this.limits.startTimeoutMs ?? 25e3, "\u684C\u5BA0\u542F\u52A8\u8D85\u65F6", startup.signal);
1051
- if (startup.signal.aborted || this.disposed) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
1052
- this.startup = void 0;
1053
- this.set({ ...this.state, phase: "running" });
1288
+ if (this.cleanupBlocked) await this.cleanup();
1289
+ this.set({ ...this.state, recoveryAttempt: 0, retryAt: void 0 });
1290
+ await this.launch(epoch);
1291
+ launched = true;
1054
1292
  }
1055
- if (this.state.phase === "running") this.bridge.control?.(command === "characters" ? "characters" : command === "hide" ? "hide" : "show");
1293
+ if (this.state.phase === "running" && epoch === this.epoch && (!launched || command === "characters")) this.bridge.control?.(command === "characters" ? "characters" : this.state.desiredVisible ? "show" : "hide");
1056
1294
  return this.status();
1057
1295
  } catch (error) {
1058
- this.startup?.abort();
1059
- this.startup = void 0;
1060
- const cleanup = await this.cleanup().then(() => "", (failure) => `\uFF1B\u6E05\u7406\u5931\u8D25\uFF1A${this.message(failure)}`);
1061
- this.set({ ...this.state, phase: "error", visible: false, suspended: false, error: (this.message(error) + cleanup).slice(0, 600) });
1296
+ await this.failed(error, error instanceof NativeStartError && error.recoverable, epoch);
1062
1297
  return this.status();
1063
1298
  }
1064
1299
  });
1065
1300
  }
1066
1301
  async dispose() {
1067
1302
  this.disposed = true;
1303
+ this.wanted = false;
1304
+ this.epoch++;
1305
+ this.clearRetry();
1306
+ this.clearStable();
1068
1307
  this.startup?.abort();
1069
- this.set({ ...this.state, phase: "stopping", visible: false, suspended: false });
1308
+ this.set({ ...this.state, phase: "stopping", visible: false, suspended: false, retryAt: void 0, error: void 0 });
1070
1309
  await this.enqueue(async () => {
1071
1310
  this.bridge.removeLifecycle?.(this.changed);
1072
1311
  const failure = await this.cleanup().then(() => void 0, (error) => this.message(error));
@@ -1074,13 +1313,77 @@ var PetControls = class {
1074
1313
  this.listeners.clear();
1075
1314
  });
1076
1315
  }
1316
+ async launch(epoch) {
1317
+ if (this.disposed || !this.wanted || epoch !== this.epoch) return;
1318
+ const startup = new AbortController();
1319
+ this.startup = startup;
1320
+ this.startupExit = void 0;
1321
+ this.set({ ...this.state, phase: "starting", error: void 0, retryAt: void 0, visible: false, generation: this.state.generation + 1, visibilityRevision: 0, suspended: false });
1322
+ try {
1323
+ await this.withDeadline(this.bridge.start(this.options(), { signal: startup.signal, generation: this.state.generation, visible: this.state.desiredVisible }), this.limits.startTimeoutMs ?? 25e3, "\u684C\u5BA0\u542F\u52A8\u8D85\u65F6", startup.signal, true);
1324
+ } catch (error) {
1325
+ throw this.startupExit ?? error;
1326
+ }
1327
+ if (startup.signal.aborted || this.disposed || epoch !== this.epoch) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
1328
+ this.startup = void 0;
1329
+ this.set({ ...this.state, phase: "running" });
1330
+ this.armStable();
1331
+ this.bridge.control?.(this.state.desiredVisible ? "show" : "hide");
1332
+ }
1333
+ async failed(error, recoverable, epoch) {
1334
+ this.startup?.abort();
1335
+ this.startup = void 0;
1336
+ this.clearStable();
1337
+ const cleanup = await this.cleanup().then(() => "", (failure) => `\uFF1B\u6E05\u7406\u5931\u8D25\uFF1A${this.message(failure).slice(0, 580)}`);
1338
+ if (this.disposed || epoch !== this.epoch) return;
1339
+ const diagnostic = this.message(error).slice(0, 600 - cleanup.length) + cleanup;
1340
+ const attempt = this.state.recoveryAttempt ?? 0;
1341
+ if (!this.wanted || !recoverable || cleanup || attempt >= 3) {
1342
+ this.set({ ...this.state, phase: "error", visible: false, suspended: false, retryAt: void 0, error: diagnostic });
1343
+ return;
1344
+ }
1345
+ const delay = (this.limits.retryDelaysMs ?? [1e3, 3e3, 1e4])[attempt];
1346
+ this.set({ ...this.state, phase: "recovering", visible: false, suspended: false, recoveryAttempt: attempt + 1, retryAt: Date.now() + delay, error: diagnostic });
1347
+ this.retry = setTimeout(() => {
1348
+ this.retry = void 0;
1349
+ void this.enqueue(async () => {
1350
+ if (this.disposed || !this.wanted || epoch !== this.epoch) return;
1351
+ try {
1352
+ await this.launch(epoch);
1353
+ } catch (failure) {
1354
+ await this.failed(failure, failure instanceof NativeStartError && failure.recoverable, epoch);
1355
+ }
1356
+ });
1357
+ }, delay);
1358
+ this.retry.unref?.();
1359
+ }
1360
+ clearRetry() {
1361
+ clearTimeout(this.retry);
1362
+ this.retry = void 0;
1363
+ }
1364
+ clearStable() {
1365
+ clearTimeout(this.stable);
1366
+ this.stable = void 0;
1367
+ }
1368
+ armStable() {
1369
+ this.clearStable();
1370
+ if (this.state.suspended) return;
1371
+ const generation = this.state.generation;
1372
+ this.stable = setTimeout(() => {
1373
+ this.stable = void 0;
1374
+ if (!this.disposed && this.state.phase === "running" && generation === this.state.generation) this.set({ ...this.state, recoveryAttempt: 0 });
1375
+ }, this.limits.stableMs ?? 6e4);
1376
+ this.stable.unref?.();
1377
+ }
1077
1378
  message(error) {
1078
1379
  return String(error instanceof Error ? error.message : error).slice(0, 600);
1079
1380
  }
1080
- cleanup() {
1081
- return this.withDeadline(Promise.resolve().then(() => this.bridge.dispose()), this.limits.cleanupTimeoutMs ?? 5e3, "\u684C\u5BA0\u6E05\u7406\u8D85\u65F6");
1381
+ async cleanup() {
1382
+ this.cleanupBlocked = true;
1383
+ await this.withDeadline(Promise.resolve().then(() => this.bridge.dispose()), this.limits.cleanupTimeoutMs ?? 5e3, "\u684C\u5BA0\u6E05\u7406\u8D85\u65F6");
1384
+ this.cleanupBlocked = false;
1082
1385
  }
1083
- withDeadline(task, delay, message, signal) {
1386
+ withDeadline(task, delay, message, signal, recoverable = false) {
1084
1387
  return new Promise((resolve, reject) => {
1085
1388
  let done = false;
1086
1389
  const finish = (error, value) => {
@@ -1092,7 +1395,7 @@ var PetControls = class {
1092
1395
  else resolve(value);
1093
1396
  };
1094
1397
  const aborted = () => finish(new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88"));
1095
- const timer = setTimeout(() => finish(new Error(message)), delay);
1398
+ const timer = setTimeout(() => finish(new NativeStartError(message, recoverable)), delay);
1096
1399
  signal?.addEventListener("abort", aborted, { once: true });
1097
1400
  if (signal?.aborted) aborted();
1098
1401
  task.then((value) => finish(void 0, value), (error) => finish(error));
@@ -1116,11 +1419,351 @@ var PetControls = class {
1116
1419
 
1117
1420
  // src/index.ts
1118
1421
  import { z as wire } from "zod";
1422
+
1423
+ // web/locale.js
1424
+ function petLanguage(locale = "en") {
1425
+ return /^zh(?:-|$)/i.test(locale) ? "zh" : "en";
1426
+ }
1427
+ var zh = {
1428
+ defaultName: "DeepSeek \u5927\u80A5\u9C7C",
1429
+ title: "DeepSeek \u5927\u80A5\u9C7C \xB7 Harness",
1430
+ words: { neutral: "\u5E73\u9759", happy: "\u5F00\u5FC3", wink: "\u7728\u773C", love: "\u559C\u6B22", shy: "\u5BB3\u7F9E", surprised: "\u60CA\u8BB6", angry: "\u751F\u6C14", sad: "\u96BE\u8FC7", sleepy: "\u72AF\u56F0", thinking: "\u601D\u8003", smug: "\u5F97\u610F", pout: "\u561F\u5634", worried: "\u62C5\u5FC3", determined: "\u8BA4\u771F", flustered: "\u614C\u5F20", scared: "\u5BB3\u6015", excited: "\u671F\u5F85", cry: "\u5927\u54ED", confused: "\u7591\u60D1", stand: "\u7AD9\u8D77", jump: "\u8DF3", hop: "\u5C0F\u8DF3", look: "\u5F20\u671B", turn: "\u8F6C\u8EAB", nod: "\u70B9\u5934", shake: "\u6447\u5934", spin: "\u8F6C\u5708", sit: "\u5750\u4E0B", sleep: "\u7761\u89C9", dizzy: "\u6655", walk: "\u6563\u6B65", run: "\u8DD1", wave: "\u62DB\u624B", bow: "\u97A0\u8EAC", shiver: "\u53D1\u6296", flap: "\u6251\u817E", dance: "\u8DF3\u821E" },
1431
+ settingFailed: "\u8BBE\u7F6E\u672A\u80FD\u4FDD\u5B58",
1432
+ settingFailedBody: "\u8BF7\u56DE\u5230 Harness \u68C0\u67E5\u63D2\u4EF6\u8BBE\u7F6E\u3002",
1433
+ sessionUnavailable: "\u4F1A\u8BDD\u5C1A\u672A\u5C31\u7EEA",
1434
+ sessionUnavailableBody: "\u8BF7\u5148\u56DE\u5230 Harness \u6253\u5F00\u8FD9\u4E2A\u4F1A\u8BDD\uFF0C\u7136\u540E\u518D\u53D1\u9001\u6D88\u606F\u3002",
1435
+ messageFailed: "\u6D88\u606F\u672A\u80FD\u53D1\u9001",
1436
+ messageFailedBody: "\u8BF7\u56DE\u5230 Harness \u68C0\u67E5\u4F1A\u8BDD\u72B6\u6001\u3002",
1437
+ replyBody: "\u672C\u8F6E\u56DE\u590D\u5DF2\u751F\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002",
1438
+ progressBody: "\u672C\u8F6E\u56DE\u590D\u5DF2\u751F\u6210\uFF0C\u76EE\u6807\u4ECD\u5728\u8FDB\u884C\u4E2D\u3002",
1439
+ completeBody: "\u76EE\u6807\u5DF2\u5B8C\u6210\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002",
1440
+ goalPausedBody: "\u76EE\u6807\u5DF2\u6682\u505C\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002",
1441
+ goalBlockedBody: "\u76EE\u6807\u9047\u5230\u963B\u788D\uFF0C\u56DE\u5230\u4F1A\u8BDD\u67E5\u770B\u3002",
1442
+ stoppedBody: "\u5148\u505C\u5728\u8FD9\u91CC\uFF0C\u968F\u65F6\u7EE7\u7EED\u3002",
1443
+ interruptedBody: "\u8FD9\u6BB5\u4EFB\u52A1\u4E2D\u65AD\u4E86\uFF0C\u966A\u4F60\u56DE\u53BB\u770B\u770B\u3002",
1444
+ demoTitle: "\u5DE5\u4F5C\u7684\u65F6\u5019\uFF0C\n\u5927\u80A5\u9C7C\u966A\u7740\u3002",
1445
+ demoIntro: "\u4F4F\u5728\u684C\u9762\u4E0A\u7684 DeepSeek \u5927\u80A5\u9C7C\u3002\n\u70B9\u70B9\u5979\u3001\u62D6\u7740\u5979\u8D70\uFF0C\u6216\u548C\u5979\u8BF4\u53E5\u8BDD\u3002",
1446
+ demoStatus: "\u6D4F\u89C8\u5668\u6F14\u793A \xB7 \u6A21\u62DF Harness \u4E8B\u4EF6",
1447
+ demoHint: "\u684C\u9762\u63D2\u4EF6\u4F1A\u8BA2\u9605\u771F\u5B9E\u4EFB\u52A1\uFF0C\u65E0\u9700\u53E6\u586B API Key\u3002",
1448
+ demoButtons: { thinking: "\u601D\u8003", talking: "\u56DE\u590D", working: "\u5DE5\u4F5C", waiting: "\u7B49\u4F60\u786E\u8BA4", happy: "\u4EFB\u52A1\u5B8C\u6210", error: "\u9047\u5230\u95EE\u9898", idle: "\u7A7A\u95F2", long: "\u957F\u56DE\u590D", background: "\u540E\u53F0\u5B8C\u6210" },
1449
+ demoSession: "\u6F14\u793A\u4F1A\u8BDD",
1450
+ demoOther: "\u53E6\u4E00\u4E2A\u60F3\u6CD5",
1451
+ demoPrompt: "\u8BA9\u89D2\u8272\u5728\u601D\u8003\u4E0E\u56DE\u590D\u65F6\u505A\u51FA\u5BF9\u5E94\u7684\u52A8\u4F5C",
1452
+ demoOtherPrompt: "\u91CD\u505A\u89D2\u8272\u83DC\u5355\u4E0E\u4F1A\u8BDD\u9009\u62E9\uFF0C\u8BA9\u5B83\u66F4\u50CF\u4F19\u4F34",
1453
+ demoTexts: { thinking: "\u8BA9\u6211\u60F3\u4E00\u60F3\uFF0C\u600E\u6837\u628A\u8FD9\u4E2A\u529F\u80FD\u505A\u597D\u2026", talking: "\u6211\u60F3\u5230\u4E86\u3002\u8BA9\u601D\u8003\u3001\u8BF4\u8BDD\u4E0E\u5DE5\u4F5C\u5404\u6709\u81EA\u5DF1\u7684\u52A8\u4F5C\uFF0C\u5C31\u80FD\u4E00\u773C\u770B\u51FA\u8FD9\u6BB5\u5BF9\u8BDD\u5728\u505A\u4EC0\u4E48\u3002", working: "\u6B63\u5728\u770B\u6587\u4EF6 \xB7 src/index.ts", waiting: "\u4E0B\u4E00\u6B65\u9700\u8981\u4F60\u786E\u8BA4\u3002\u771F\u5B9E\u63D2\u4EF6\u4F1A\u5F15\u5BFC\u4F60\u56DE\u5230 Harness\u3002", happy: "\u4EFB\u52A1\u5B8C\u6210\u5566\uFF01\u8981\u4E0D\u8981\u4F11\u606F\u4E00\u4E0B\uFF1F\u{1F433}", error: "\u4EFB\u52A1\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u8BF7\u56DE\u5230 Harness \u67E5\u770B\u8BE6\u60C5\u3002" },
1454
+ demoLong: "\u52A8\u753B\u3001\u6C14\u6CE1\u548C\u4F1A\u8BDD\u7684\u5C55\u793A\u5DF2\u7ECF\u5206\u5F00\u4E86\u3002\n\n" + "\u601D\u8003\u548C\u5DE5\u5177\u8C03\u7528\u7531\u52A8\u4F5C\u8868\u8FBE\uFF0C\u6700\u7EC8\u56DE\u590D\u53EF\u4EE5\u5C55\u5F00\u9605\u8BFB\u3002\u957F\u5185\u5BB9\u4F1A\u5B8C\u6574\u4FDD\u7559\uFF0C\u4E0D\u4F1A\u5728\u4E00\u5343\u4E8C\u767E\u5B57\u5904\u622A\u65AD\u3002\n\n".repeat(35) + "\u6700\u540E\u4E00\u53E5\uFF1A\u8FD9\u4EFD\u56DE\u590D\u5B8C\u6574\u5730\u4FDD\u7559\u4E0B\u6765\u4E86\u3002",
1455
+ demoBackground: "\u540E\u53F0\u4F1A\u8BDD\u5DF2\u7ECF\u5B8C\u6210\uFF0C\u8FD9\u662F\u5B83\u7684\u6700\u7EC8\u56DE\u590D\u3002",
1456
+ demoReply: (text) => `\u6536\u5230\u300C${text}\u300D\uFF01\u8FD9\u662F\u6F14\u793A\u56DE\u590D\u3002\u771F\u5B9E\u63D2\u4EF6\u4F1A\u4F7F\u7528 Harness \u7684\u6A21\u578B\u3002`,
1457
+ labels: { idle: "\u5728\u8FD9\u91CC\u966A\u4F60", thinking: "\u6B63\u5728\u601D\u8003", talking: "\u6B63\u5728\u56DE\u590D", working: "\u6B63\u5728\u5FD9", waiting: "\u7B49\u4F60\u786E\u8BA4", happy: "\u5B8C\u6210\u5566", error: "\u9700\u8981\u5173\u6CE8", sleeping: "\u4F11\u606F\u4E2D" },
1458
+ stage: "\u684C\u5BA0\u6D3B\u52A8\u533A\u57DF",
1459
+ dismiss: "\u6536\u8D77\u6C14\u6CE1",
1460
+ reveal: "\u7ACB\u5373\u663E\u793A",
1461
+ expand: "\u5C55\u5F00\u5B8C\u6574\u56DE\u590D \u2197",
1462
+ back: "\u56DE\u5230\u4F1A\u8BDD \u2197",
1463
+ readerClose: "\u6536\u8D77\u5B8C\u6574\u56DE\u590D",
1464
+ conversationsCaption: "\u4E00\u8D77\u5DE5\u4F5C\u7684\u7247\u6BB5",
1465
+ conversationsTitle: "\u8FD9\u6B21\uFF0C\u966A\u54EA\u4E00\u6BB5\uFF1F",
1466
+ conversationsClose: "\u6536\u8D77\u5BF9\u8BDD\u6C14\u6CE1",
1467
+ conversationsIntro: "\u56FA\u5B9A\u966A\u7740\u4F60\u9009\u7684\u8FD9\u6BB5\u3002\u540E\u53F0\u7EE7\u7EED\u5DE5\u4F5C\uFF0C\u56DE\u590D\u7559\u5728\u8FD9\u91CC\uFF0C\u9047\u5230\u8981\u7D27\u4E8B\u5C31\u53EB\u4F60\u3002",
1468
+ all: "\u5168\u90E8",
1469
+ pending: "\u5F85\u67E5\u770B",
1470
+ searchPlaceholder: "\u627E\u63D0\u95EE\u3001\u9879\u76EE\u6216\u7F16\u53F7\u2026",
1471
+ searchLabel: "\u641C\u7D22\u4F1A\u8BDD",
1472
+ switchConversation: "\u5207\u6362\u5F53\u524D\u5BF9\u8BDD",
1473
+ openCurrent: "\u6253\u5F00\u5F53\u524D\u4F1A\u8BDD \u2197",
1474
+ chatTitle: "\u6211\u5728\uFF0C\u6162\u6162\u8BF4\u3002",
1475
+ chatClose: "\u5173\u95ED\u804A\u5929",
1476
+ changeConversation: "\u6362\u4E00\u6BB5 \u203A",
1477
+ readFull: "\u8BFB\u5B8C\u6574\u56DE\u590D \u2197",
1478
+ interact: "\u548C\u89D2\u8272\u4E92\u52A8",
1479
+ wave: "\u6253\u4E2A\u62DB\u547C",
1480
+ cheer: "\u7ED9\u6211\u6253\u6C14",
1481
+ messagePlaceholder: "\u63A5\u7740\u8FD9\u6BB5\u5BF9\u8BDD\u8BF4\u70B9\u4EC0\u4E48\u2026",
1482
+ messageLabel: "\u6D88\u606F",
1483
+ sendHint: "\u2318 / Ctrl + Enter \u53D1\u9001",
1484
+ send: "\u634E\u7ED9\u8FD9\u6BB5\u5BF9\u8BDD \u2197",
1485
+ retrySend: "\u91CD\u8BD5\u53D1\u9001 \u2197",
1486
+ sending: "\u53D1\u9001\u4E2D\u2026",
1487
+ sendAccepted: "\u5DF2\u8FDB\u5165\u8FD9\u6BB5\u4F1A\u8BDD\u7684\u6536\u4EF6\u961F\u5217\u3002\u56DE\u590D\u5C06\u7EE7\u7EED\u663E\u793A\u5728\u8FD9\u91CC\u3002",
1488
+ sendFailure: (code) => `\u53D1\u9001\u672A\u786E\u8BA4\uFF1A${chatFailure(code, "zh")}\u3002\u8349\u7A3F\u5DF2\u4FDD\u7559\uFF0C\u53EF\u91CD\u8BD5\u3002`,
1489
+ companion: "\u684C\u4E0A\u7684\u5C0F\u4F19\u4F34",
1490
+ menuClose: "\u6536\u8D77\u4F19\u4F34\u83DC\u5355",
1491
+ appearance: "\u6362\u4E2A\u6A21\u6837",
1492
+ appearanceHint: "\u89D2\u8272 \xB7 \u914D\u8272 \xB7 \u52A8\u4F5C",
1493
+ say: "\u8BF4\u53E5\u8BDD",
1494
+ sayHint: "\u63A5\u7740\u4F60\u7684\u4F1A\u8BDD\u804A",
1495
+ roam: "\u6563\u6563\u6B65",
1496
+ roamHint: "\u81EA\u5728\u8D70\u52A8",
1497
+ sleep: "\u6B47\u4E00\u4F1A",
1498
+ sleepHint: "\u5FD9\u8D77\u6765\u4F1A\u9192",
1499
+ notices: "\u63D0\u9192\u6211",
1500
+ noticesHint: "\u8981\u7D27\u4E8B\u4E0D\u6F0F\u6389",
1501
+ sound: "\u5C0F\u5C0F\u58F0",
1502
+ soundHint: "\u52A8\u4F5C\u4E0E\u8BF4\u8BDD\u97F3\u6548",
1503
+ hide: "\u6682\u65F6\u85CF\u8D77\u6765",
1504
+ source: "\u6E90\u7801 \xB7 AGPL \u2197",
1505
+ sourceHint: "\u4E0B\u8F7D\u5F53\u524D\u7248\u672C\u5B8C\u6574\u5BF9\u5E94\u6E90\u7801",
1506
+ characters: "\u89D2\u8272\u4E0E\u52A8\u753B",
1507
+ charactersClose: "\u5173\u95ED\u89D2\u8272\u9762\u677F",
1508
+ selectCharacter: "\u9009\u62E9\u89D2\u8272",
1509
+ character: "\u89D2\u8272",
1510
+ outfit: "\u914D\u8272 / \u6362\u88C5",
1511
+ characterScheme: "\u89D2\u8272\u914D\u8272",
1512
+ preview: "\u89D2\u8272\u52A8\u753B\u9884\u89C8",
1513
+ previewAction: "\u9884\u89C8\u52A8\u4F5C",
1514
+ play: "\u64AD\u653E\u52A8\u4F5C",
1515
+ useCharacter: "\u4F7F\u7528\u89D2\u8272",
1516
+ import: "\u5BFC\u5165\u89D2\u8272\u5305",
1517
+ remove: "\u5220\u9664",
1518
+ characterHint: "\u652F\u6301 Coopanion API 2 ZIP \u89D2\u8272\u5305\uFF1B\u89D2\u8272\u548C\u914D\u8272\u4F1A\u5728\u91CD\u542F\u540E\u4FDD\u7559\u3002",
1519
+ using: "\u6B63\u5728\u4F7F\u7528",
1520
+ useScheme: "\u4F7F\u7528\u8FD9\u4E2A\u914D\u8272",
1521
+ useOutfit: "\u4F7F\u7528\u8FD9\u4E2A\u642D\u914D",
1522
+ customOutfit: "\u81EA\u5B9A\u4E49\u642D\u914D",
1523
+ defaultScheme: "\u9ED8\u8BA4",
1524
+ imported: "\u5DF2\u5BFC\u5165\u3002\u9884\u89C8\u6EE1\u610F\u540E\u70B9\u51FB\u4F7F\u7528\u89D2\u8272\u3002",
1525
+ switched: "\u5DF2\u5207\u6362\uFF0C\u91CD\u542F\u540E\u4F1A\u4FDD\u7559\u8FD9\u4E2A\u89D2\u8272\u548C\u914D\u8272\u3002",
1526
+ removed: "\u5DF2\u5220\u9664\u672C\u5730\u89D2\u8272\u5305\u3002",
1527
+ packTooLarge: "\u89D2\u8272\u5305\u4E0D\u80FD\u8D85\u8FC7 128 MiB",
1528
+ noSession: "\u8FD8\u6CA1\u6709\u5BF9\u8BDD",
1529
+ noConversation: "\u8FD8\u6CA1\u6709\u4F1A\u8BDD",
1530
+ session: "\u4F1A\u8BDD",
1531
+ sessionReply: "\u4F1A\u8BDD\u56DE\u590D",
1532
+ focused: "\u5173\u6CE8",
1533
+ unread: "1 \u4EFD\u672A\u8BFB",
1534
+ notOpen: "\u672A\u6253\u5F00",
1535
+ connected: "\u6709\u4F1A\u8BDD\u76F8\u4F34",
1536
+ emptySearch: "\u6CA1\u627E\u5230\u8FD9\u6BB5\u5BF9\u8BDD\u3002\u8BD5\u8BD5\u63D0\u95EE\u91CC\u7684\u8BCD\u6216\u9879\u76EE\u540D\uFF1F",
1537
+ emptyPending: "\u90FD\u770B\u8FC7\u5566\uFF0C\u5B89\u5FC3\u505A\u624B\u8FB9\u7684\u4E8B\u3002",
1538
+ emptySessions: "\u8FD8\u6CA1\u6709\u53EF\u7528\u7684\u5BF9\u8BDD\u3002\u5148\u5728 Harness \u4E2D\u6253\u5F00\u4E00\u6BB5\u5BF9\u8BDD\uFF0C\u6211\u5C31\u80FD\u542C\u89C1\u5B83\u3002",
1539
+ noChat: "\u5148\u5728 Harness \u4E2D\u6253\u5F00\u4E00\u6BB5\u5BF9\u8BDD\uFF0C\u5C31\u53EF\u4EE5\u4ECE\u8FD9\u91CC\u548C\u6211\u8BF4\u8BDD\u3002",
1540
+ unavailableChat: "\u4F1A\u8BDD\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u5728 Harness \u4E2D\u68C0\u67E5\u3002",
1541
+ sleepBusy: "\u6B63\u5728\u5FD9\uFF0C\u5B8C\u6210\u540E\u518D\u4F11\u606F",
1542
+ sleepWake: "\u6709\u65B0\u7684\u4EFB\u52A1\u4F1A\u81EA\u52A8\u9192\u6765",
1543
+ issueError: "\u4EFB\u52A1\u9047\u5230\u4E86\u95EE\u9898\uFF0C\u8BF7\u56DE\u5230 Harness \u67E5\u770B\u8BE6\u60C5\u3002",
1544
+ issueWaiting: "\u4EFB\u52A1\u6682\u65F6\u505C\u4E0B\u4E86\uFF0C\u8BF7\u56DE\u5230 Harness \u770B\u770B\u3002",
1545
+ timeUnknown: "\u65F6\u95F4\u672A\u8BB0\u5F55",
1546
+ petLabel: (name2) => `${name2}\uFF0C\u70B9\u51FB\u4E92\u52A8\uFF0C\u53CC\u51FB\u804A\u5929\uFF0C\u53F3\u952E\u83DC\u5355\uFF0C\u62D6\u52A8\u79FB\u52A8`,
1547
+ finalReply: (name2) => `${name2}\u7684\u6700\u7EC8\u56DE\u590D`,
1548
+ recent: (text) => `\u6700\u8FD1\uFF1A${text}`,
1549
+ chatTarget: (label) => `\u5F53\u524D\u5BF9\u8BDD\uFF1A${label}\u3002\u70B9\u51FB\u5207\u6362`,
1550
+ chatHelp: (label) => `\u6D88\u606F\u4EA4\u7ED9\u300C${label}\u300D\uFF0C\u5B8C\u6210\u540E\u53EA\u5C55\u793A\u6700\u7EC8\u56DE\u590D\u3002`,
1551
+ activity: (busy, unread) => `${busy} \u6BB5\u8FDB\u884C\u4E2D \xB7 ${unread} \u4EFD\u672A\u8BFB\u56DE\u590D`,
1552
+ authorCredit: (author, credits, license) => `\u4F5C\u8005\uFF1A${author} \xB7 ${credits} \xB7 \u8BB8\u53EF\uFF1A${license}`,
1553
+ unknownAuthor: "\u672A\u6CE8\u660E",
1554
+ builtinLicense: "\u4EE3\u7801 AGPL-3.0-or-later\uFF1B\u7D20\u6750\u89C1\u6743\u5229\u58F0\u660E",
1555
+ authorLicense: "\u7531\u89D2\u8272\u4F5C\u8005\u6CE8\u660E",
1556
+ operationError: (detail) => `\u64CD\u4F5C\u672A\u5B8C\u6210\uFF1A${detail}`,
1557
+ bodyError: (detail) => `\u89D2\u8272\u8FD0\u884C\u5931\u8D25\uFF1A${detail}`,
1558
+ builtinError: (detail) => `\u65E0\u6CD5\u52A0\u8F7D\u5185\u7F6E\u89D2\u8272\uFF1A${detail}`,
1559
+ previewError: (detail) => `\u9884\u89C8\u5931\u8D25\uFF1A${detail}`,
1560
+ restoreError: (detail) => `\u5DF2\u6062\u590D\u5185\u7F6E\u5927\u80A5\u9C7C\uFF1A${detail}`,
1561
+ loadError: (detail) => `\u89D2\u8272\u52A0\u8F7D\u5931\u8D25\uFF1A${detail}`,
1562
+ trayDisplay: "\u79FB\u5230\u663E\u793A\u5668",
1563
+ display: "\u663E\u793A\u5668",
1564
+ trayOpen: "\u56DE\u5230\u5F53\u524D\u4F1A\u8BDD",
1565
+ traySwitch: "\u5207\u6362\u966A\u4F34\u4F1A\u8BDD",
1566
+ trayChat: "\u8BF4\u53E5\u8BDD",
1567
+ trayCharacters: "\u89D2\u8272\u4E0E\u914D\u8272",
1568
+ trayRoam: "\u81EA\u5728\u8D70\u52A8",
1569
+ traySleep: "\u4F11\u606F\u4E00\u4E0B\uFF08\u65B0\u4EFB\u52A1\u4F1A\u5524\u9192\uFF09",
1570
+ trayNotices: "\u4EFB\u52A1\u63D0\u9192",
1571
+ traySound: "\u52A8\u4F5C\u4E0E\u8BF4\u8BDD\u97F3\u6548",
1572
+ trayShow: "\u663E\u793A\u4F19\u4F34",
1573
+ trayQuit: "\u5173\u95ED\u684C\u5BA0",
1574
+ trayNeeds: " \xB7 \u9700\u8981\u4F60",
1575
+ trayUnread: (n) => ` \xB7 ${n} \u4EFD\u672A\u8BFB`,
1576
+ trayPending: (unread, pending) => `\u5F85\u67E5\u770B \xB7 ${unread} \u4EFD\u56DE\u590D \xB7 ${pending} \u6BB5\u9700\u8981\u4F60`,
1577
+ trayTooltip: (name2, mood, label, busy, pending, unread) => `${name2} \xB7 ${mood}
1578
+ \u5173\u6CE8\uFF1A${label}
1579
+ ${busy} \u6BB5\u8FDB\u884C\u4E2D \xB7 ${pending} \u6BB5\u9700\u8981\u4F60 \xB7 ${unread} \u4EFD\u672A\u8BFB\u56DE\u590D`
1580
+ };
1581
+ var en = {
1582
+ defaultName: "DeepSeek Whale",
1583
+ title: "DeepSeek Whale \xB7 Harness",
1584
+ words: { neutral: "Neutral", happy: "Happy", wink: "Wink", love: "Love", shy: "Shy", surprised: "Surprised", angry: "Angry", sad: "Sad", sleepy: "Sleepy", thinking: "Thinking", smug: "Smug", pout: "Pout", worried: "Worried", determined: "Determined", flustered: "Flustered", scared: "Scared", excited: "Excited", cry: "Cry", confused: "Confused", stand: "Stand", jump: "Jump", hop: "Hop", look: "Look around", turn: "Turn", nod: "Nod", shake: "Shake head", spin: "Spin", sit: "Sit", sleep: "Sleep", dizzy: "Dizzy", walk: "Walk", run: "Run", wave: "Wave", bow: "Bow", shiver: "Shiver", flap: "Flap", dance: "Dance" },
1585
+ settingFailed: "Settings were not saved",
1586
+ settingFailedBody: "Open Harness to check the plugin settings.",
1587
+ sessionUnavailable: "Conversation not ready",
1588
+ sessionUnavailableBody: "Open this conversation in Harness before sending a message.",
1589
+ messageFailed: "Message was not sent",
1590
+ messageFailedBody: "Open Harness to check the conversation state.",
1591
+ replyBody: "This turn\u2019s reply is ready. Open the conversation to read it.",
1592
+ progressBody: "This turn\u2019s reply is ready. The goal is still in progress.",
1593
+ completeBody: "Goal completed. Open the conversation to read it.",
1594
+ goalPausedBody: "The goal is paused. Open the conversation for details.",
1595
+ goalBlockedBody: "The goal is blocked. Open the conversation for details.",
1596
+ stoppedBody: "Paused here. Continue whenever you are ready.",
1597
+ interruptedBody: "This task was interrupted. Open the conversation to check it.",
1598
+ demoTitle: "While you work,\nWhale keeps you company.",
1599
+ demoIntro: "Your DeepSeek Whale desktop companion.\nSay hello, drag her around, or continue a conversation.",
1600
+ demoStatus: "Browser demo \xB7 Simulated Harness events",
1601
+ demoHint: "The desktop plugin follows real tasks. No extra API key is needed.",
1602
+ demoButtons: { thinking: "Think", talking: "Reply", working: "Work", waiting: "Approval", happy: "Finished", error: "Error", idle: "Idle", long: "Long reply", background: "Background reply" },
1603
+ demoSession: "Demo conversation",
1604
+ demoOther: "Another idea",
1605
+ demoPrompt: "Match the character\u2019s actions to thinking and replying",
1606
+ demoOtherPrompt: "Make the character menu and conversation picker feel like a companion",
1607
+ demoTexts: { thinking: "Let me think about how to do this\u2026", talking: "Thinking, replying and working each have their own actions, so you can see what this conversation is doing.", working: "Reading files \xB7 src/index.ts", waiting: "The next step needs your approval. The installed plugin opens Harness.", happy: "Finished! Shall we take a rest? \u{1F433}", error: "This task needs attention. Open Harness for details." },
1608
+ demoLong: "Animation, bubbles and conversations are presented separately.\n\n" + "Actions show thinking and tool use. Final replies open in full and remain complete, including long content.\n\n".repeat(35) + "The complete reply has been preserved.",
1609
+ demoBackground: "The background conversation finished. Here is its final reply.",
1610
+ demoReply: (text) => `Received \u201C${text}\u201D! This is a demo reply. The installed plugin uses the Harness model.`,
1611
+ labels: { idle: "Here for you", thinking: "Thinking", talking: "Replying", working: "Working", waiting: "Waiting for you", happy: "Finished", error: "Needs attention", sleeping: "Resting" },
1612
+ stage: "Desktop pet activity area",
1613
+ dismiss: "Dismiss bubble",
1614
+ reveal: "Show now",
1615
+ expand: "Read full reply \u2197",
1616
+ back: "Back to conversation \u2197",
1617
+ readerClose: "Close full reply",
1618
+ conversationsCaption: "Working together",
1619
+ conversationsTitle: "Which conversation shall we join?",
1620
+ conversationsClose: "Close conversations",
1621
+ conversationsIntro: "Stay with the conversation you choose. Background work continues, replies stay here, and important requests get your attention.",
1622
+ all: "All",
1623
+ pending: "Inbox",
1624
+ searchPlaceholder: "Find a prompt, project or ID\u2026",
1625
+ searchLabel: "Search conversations",
1626
+ switchConversation: "Switch current conversation",
1627
+ openCurrent: "Open current conversation \u2197",
1628
+ chatTitle: "I\u2019m here. Take your time.",
1629
+ chatClose: "Close chat",
1630
+ changeConversation: "Switch \u203A",
1631
+ readFull: "Read full reply \u2197",
1632
+ interact: "Interact with the character",
1633
+ wave: "Say hello",
1634
+ cheer: "Cheer me on",
1635
+ messagePlaceholder: "Continue this conversation\u2026",
1636
+ messageLabel: "Message",
1637
+ sendHint: "\u2318 / Ctrl + Enter to send",
1638
+ send: "Send to this conversation \u2197",
1639
+ retrySend: "Retry send \u2197",
1640
+ sending: "Sending\u2026",
1641
+ sendAccepted: "Accepted into this conversation\u2019s inbox. Replies will appear here.",
1642
+ sendFailure: (code) => `Send unconfirmed: ${chatFailure(code, "en")}. Draft kept; you can retry.`,
1643
+ companion: "Your desktop companion",
1644
+ menuClose: "Close companion menu",
1645
+ appearance: "Change appearance",
1646
+ appearanceHint: "Character \xB7 Colours \xB7 Actions",
1647
+ say: "Say something",
1648
+ sayHint: "Continue your conversation",
1649
+ roam: "Take a walk",
1650
+ roamHint: "Roam freely",
1651
+ sleep: "Take a rest",
1652
+ sleepHint: "Wake when work starts",
1653
+ notices: "Keep me posted",
1654
+ noticesHint: "Remember important requests",
1655
+ sound: "A little sound",
1656
+ soundHint: "Action and reply sounds",
1657
+ hide: "Hide for now",
1658
+ source: "Source \xB7 AGPL \u2197",
1659
+ sourceHint: "Download the complete source for this version",
1660
+ characters: "Characters and animation",
1661
+ charactersClose: "Close character panel",
1662
+ selectCharacter: "Select character",
1663
+ character: "Character",
1664
+ outfit: "Colours / Outfit",
1665
+ characterScheme: "Character colours",
1666
+ preview: "Character animation preview",
1667
+ previewAction: "Preview action",
1668
+ play: "Play action",
1669
+ useCharacter: "Use character",
1670
+ import: "Import character pack",
1671
+ remove: "Delete",
1672
+ characterHint: "Coopanion API 2 ZIP packs. Characters and colours survive restarts.",
1673
+ using: "In use",
1674
+ useScheme: "Use these colours",
1675
+ useOutfit: "Use this outfit",
1676
+ customOutfit: "Custom outfit",
1677
+ defaultScheme: "Default",
1678
+ imported: "Imported. Preview the character, then choose Use character.",
1679
+ switched: "Changed. This character and its colours will survive restarts.",
1680
+ removed: "Local character pack deleted.",
1681
+ packTooLarge: "Character packs cannot exceed 128 MiB",
1682
+ noSession: "No conversation yet",
1683
+ noConversation: "No conversation yet",
1684
+ session: "Conversation",
1685
+ sessionReply: "Conversation reply",
1686
+ focused: "Focused",
1687
+ unread: "1 unread reply",
1688
+ notOpen: "Not open",
1689
+ connected: "Conversation connected",
1690
+ emptySearch: "No matching conversation. Try a word from the prompt or project name.",
1691
+ emptyPending: "All read. Carry on with your work.",
1692
+ emptySessions: "No conversation is available. Open one in Harness to get started.",
1693
+ noChat: "Open a conversation in Harness to chat here.",
1694
+ unavailableChat: "The conversation service is unavailable. Check Harness.",
1695
+ sleepBusy: "Working now. Rest when it is done.",
1696
+ sleepWake: "Wake automatically when new work starts.",
1697
+ issueError: "The task needs attention. Open Harness for details.",
1698
+ issueWaiting: "The task paused. Open Harness to check the next step.",
1699
+ timeUnknown: "Time not recorded",
1700
+ petLabel: (name2) => `${name2}, click to interact, double-click to chat, right-click for the menu, drag to move`,
1701
+ finalReply: (name2) => `Final reply from ${name2}`,
1702
+ recent: (text) => `Recent: ${text}`,
1703
+ chatTarget: (label) => `Current conversation: ${label}. Click to switch`,
1704
+ chatHelp: (label) => `Send to \u201C${label}\u201D. Each turn\u2019s full reply is kept here.`,
1705
+ activity: (busy, unread) => `${busy} active \xB7 ${unread} unread replies`,
1706
+ authorCredit: (author, credits, license) => `Author: ${author} \xB7 ${credits} \xB7 License: ${license}`,
1707
+ unknownAuthor: "Not specified",
1708
+ builtinLicense: "Code: AGPL-3.0-or-later; see artwork rights notice",
1709
+ authorLicense: "Specified by the character author",
1710
+ operationError: (detail) => `Operation failed: ${detail}`,
1711
+ bodyError: (detail) => `Character runtime failed: ${detail}`,
1712
+ builtinError: (detail) => `Cannot load the built-in character: ${detail}`,
1713
+ previewError: (detail) => `Preview failed: ${detail}`,
1714
+ restoreError: (detail) => `Built-in Whale restored: ${detail}`,
1715
+ loadError: (detail) => `Character failed to load: ${detail}`,
1716
+ trayDisplay: "Move to display",
1717
+ display: "Display",
1718
+ trayOpen: "Open current conversation",
1719
+ traySwitch: "Choose companion conversation",
1720
+ trayChat: "Say something",
1721
+ trayCharacters: "Characters and colours",
1722
+ trayRoam: "Roam freely",
1723
+ traySleep: "Rest (new work wakes the pet)",
1724
+ trayNotices: "Task reminders",
1725
+ traySound: "Action and reply sounds",
1726
+ trayShow: "Show companion",
1727
+ trayQuit: "Close desktop pet",
1728
+ trayNeeds: " \xB7 Needs attention",
1729
+ trayUnread: (n) => ` \xB7 ${n} unread`,
1730
+ trayPending: (unread, pending) => `Inbox \xB7 ${unread} replies \xB7 ${pending} need attention`,
1731
+ trayTooltip: (name2, mood, label, busy, pending, unread) => `${name2} \xB7 ${mood}
1732
+ Focused: ${label}
1733
+ ${busy} active \xB7 ${pending} need attention \xB7 ${unread} unread replies`
1734
+ };
1735
+ function chatFailure(code, language) {
1736
+ const reasons = {
1737
+ "session/not-found": ["\u4F1A\u8BDD\u4E0D\u5B58\u5728\u6216\u5DF2\u5220\u9664", "conversation missing or deleted"],
1738
+ "session/writer-held": ["\u4F1A\u8BDD\u6B63\u7531\u5176\u4ED6\u8FDB\u7A0B\u5360\u7528", "conversation held by another writer"],
1739
+ "session/subagent-owned": ["\u5B50\u4EE3\u7406\u4F1A\u8BDD\u4E0D\u80FD\u76F4\u63A5\u7EED\u63A5", "subagent conversation cannot be continued here"],
1740
+ "session/model-unavailable": ["\u4F1A\u8BDD\u6CA1\u6709\u53EF\u7528\u6A21\u578B", "no available model for this conversation"],
1741
+ "session/provider-credentials-unavailable": ["\u4F1A\u8BDD\u7684\u6A21\u578B\u51ED\u636E\u4E0D\u53EF\u7528", "model credentials unavailable"],
1742
+ "gateway/forbidden": ["\u6CA1\u6709\u6B64\u4F1A\u8BDD\u7684\u64CD\u4F5C\u6743\u9650", "permission denied"],
1743
+ "gateway/cancelled": ["\u63D0\u4EA4\u5DF2\u53D6\u6D88", "submission cancelled"],
1744
+ "coopanion/service-unavailable": ["\u4F1A\u8BDD\u670D\u52A1\u7F3A\u5931", "conversation service unavailable"],
1745
+ "coopanion/request-conflict": ["\u8BF7\u6C42\u8EAB\u4EFD\u4E0E\u539F\u6D88\u606F\u4E0D\u4E00\u81F4", "request identity conflicts with the original message"],
1746
+ "coopanion/no-receipt": ["\u672A\u6536\u5230\u63A5\u53D7\u56DE\u6267\uFF0C\u91CD\u8BD5\u4F1A\u590D\u7528\u539F\u8BF7\u6C42\u8EAB\u4EFD", "no acceptance receipt; retry uses the same request identity"],
1747
+ "session/agent-busy": ["\u4F1A\u8BDD\u6682\u65F6\u4E0D\u80FD\u63A5\u6536\u6D88\u606F", "conversation cannot accept the message now"]
1748
+ };
1749
+ return reasons[code]?.[language === "zh" ? 0 : 1] ?? (language === "zh" ? `\u4F1A\u8BDD\u6682\u4E0D\u53EF\u7528 (${code ?? "unknown"})` : `conversation unavailable (${code ?? "unknown"})`);
1750
+ }
1751
+
1752
+ // web/text-scale.js
1753
+ var TEXT_SCALES = Object.freeze([1, 1.25, 1.5]);
1754
+ var DEFAULT_TEXT_SCALE = 1;
1755
+
1756
+ // web/daily-rhythm.js
1757
+ var DEFAULT_DAILY_RHYTHM = false;
1758
+
1759
+ // src/index.ts
1119
1760
  var name = "dsh-coopanion";
1120
1761
  var inject = ["agents"];
1121
1762
  var Config = z2.object({
1122
1763
  size: z2.number().min(90).max(240).default(180).volatile(),
1764
+ textScale: z2.union(TEXT_SCALES.map((value) => z2.const(value))).default(DEFAULT_TEXT_SCALE).volatile(),
1123
1765
  roam: z2.boolean().default(true).volatile(),
1766
+ dailyRhythm: z2.boolean().default(DEFAULT_DAILY_RHYTHM).volatile(),
1124
1767
  notifications: z2.boolean().default(true).volatile(),
1125
1768
  systemNotifications: z2.boolean().default(false).volatile(),
1126
1769
  reminders: z2.boolean().default(true).volatile(),
@@ -1137,19 +1780,49 @@ async function apply(ctx, config) {
1137
1780
  }
1138
1781
  async function mountPet(ctx, options, bridge) {
1139
1782
  const model = new PetModel();
1783
+ const chat = new ChatSubmission(ctx);
1784
+ const chatLifetime = new AbortController();
1785
+ ctx.effect(() => () => chatLifetime.abort());
1140
1786
  const preferences = {};
1141
1787
  let savePreference;
1142
1788
  ctx.inject(["settings"], (child) => {
1143
1789
  savePreference = (field, value) => child.settings.mutate("dsh-coopanion", [{ op: "set", path: [field], value }]);
1144
1790
  });
1145
- const currentOptions = () => ({ size: options.size.get(), roam: options.roam.get(), notifications: options.notifications.get(), bubbleDurationMs: options.bubbleDurationMs.get(), systemNotifications: options.systemNotifications.get(), reminders: options.reminders.get(), reminderDelayMs: options.reminderDelayMs.get(), electronPath: options.electronPath, locale, ...preferences });
1791
+ const currentOptions = () => ({ size: options.size.get(), textScale: options.textScale.get(), roam: options.roam.get(), dailyRhythm: options.dailyRhythm.get(), notifications: options.notifications.get(), bubbleDurationMs: options.bubbleDurationMs.get(), systemNotifications: options.systemNotifications.get(), reminders: options.reminders.get(), reminderDelayMs: options.reminderDelayMs.get(), electronPath: options.electronPath, locale, ...preferences });
1146
1792
  const controls = new PetControls(bridge, currentOptions);
1147
- let locale = "zh";
1793
+ let locale;
1794
+ let clientLocale;
1795
+ let dedicatedLocale = false;
1796
+ let storedLocale;
1797
+ const syncLocale = () => {
1798
+ const preference = storedLocale?.();
1799
+ const next = preference ? petLanguage(preference) : clientLocale;
1800
+ if (next === locale) return;
1801
+ locale = next;
1802
+ controls.configure();
1803
+ };
1804
+ const adoptClientLocale = (value) => {
1805
+ clientLocale = petLanguage(value);
1806
+ syncLocale();
1807
+ };
1808
+ ctx.inject(["settings"], (child) => {
1809
+ const read = () => {
1810
+ const value = child.settings.describe({ redactSecrets: true }).find((entry) => entry.ns === "locale")?.value;
1811
+ const preference = isRecord(value) && typeof value.preference === "string" ? value.preference.toLowerCase() : void 0;
1812
+ return preference === "zh" || preference === "en" ? preference : void 0;
1813
+ };
1814
+ storedLocale = read;
1815
+ child.effect(() => () => {
1816
+ if (storedLocale === read) storedLocale = void 0;
1817
+ });
1818
+ syncLocale();
1819
+ });
1148
1820
  let navigation;
1149
1821
  ctx.provide("coopanion", controls);
1150
1822
  const update = () => {
1151
- const snapshot = model.snapshot(), live = new Set(ctx.agents.list().map((agent) => agent.session.id));
1152
- bridge.update({ ...snapshot, sessions: snapshot.sessions.map((session) => ({ ...session, chatAvailable: live.has(session.id) })) });
1823
+ const snapshot = model.snapshot();
1824
+ const available = !!ctx.get("sessionController") && !!ctx.get("sessionQuery");
1825
+ bridge.update({ ...snapshot, sessions: snapshot.sessions.map((session) => ({ ...session, chatAvailable: available })) });
1153
1826
  };
1154
1827
  let mounted = false;
1155
1828
  const notificationPrefs = () => notificationPreferencesSchema.parse({ notifications: currentOptions().notifications, systemNotifications: options.systemNotifications.get(), reminders: options.reminders.get(), reminderDelayMs: options.reminderDelayMs.get() });
@@ -1186,7 +1859,7 @@ async function mountPet(ctx, options, bridge) {
1186
1859
  let testSource;
1187
1860
  ctx.inject(["sessions", "sessionController"], (child) => {
1188
1861
  let source;
1189
- const create = () => source ??= child.sessionController.create({ sessionId: SessionId(`coopanion-notification-test-${randomUUID2()}`), cwd: process.cwd() }).then((value) => {
1862
+ const create = () => source ??= child.sessionController.create({ sessionId: SessionId2(`coopanion-notification-test-${randomUUID2()}`), cwd: process.cwd() }).then((value) => {
1190
1863
  const session = child.sessions.get(value.sessionId);
1191
1864
  if (!session) throw new Error("Notification test source unavailable");
1192
1865
  return session;
@@ -1213,12 +1886,18 @@ async function mountPet(ctx, options, bridge) {
1213
1886
  if (ns === "dsh-coopanion") {
1214
1887
  broker.preferences(notificationPrefs());
1215
1888
  controls.configure();
1216
- }
1889
+ } else if (ns === "locale") syncLocale();
1217
1890
  });
1218
1891
  ctx.inject(["connection"], (child) => {
1219
1892
  const dispatch = async (endpoint, payload, signal) => {
1220
1893
  try {
1221
1894
  if (signal.aborted) throw new Error("\u8BF7\u6C42\u5DF2\u53D6\u6D88");
1895
+ if (endpoint === "locale") {
1896
+ const input = wire.object({ locale: wire.enum(["zh", "en"]) }).strict().parse(payload);
1897
+ dedicatedLocale = true;
1898
+ adoptClientLocale(input.locale);
1899
+ return { ok: true, value: { locale } };
1900
+ }
1222
1901
  if (endpoint === "status") {
1223
1902
  wire.object({}).strict().parse(payload);
1224
1903
  return { ok: true, value: controls.status() };
@@ -1231,10 +1910,7 @@ async function mountPet(ctx, options, bridge) {
1231
1910
  }
1232
1911
  if (endpoint === "notification-state") {
1233
1912
  const input = notificationRequests.state.parse(payload);
1234
- if (input.locale && input.locale !== locale) {
1235
- locale = input.locale;
1236
- controls.configure();
1237
- }
1913
+ if (input.locale && !dedicatedLocale) adoptClientLocale(input.locale);
1238
1914
  return { ok: true, value: broker.snapshot() };
1239
1915
  }
1240
1916
  if (endpoint === "notification-claim") {
@@ -1260,7 +1936,7 @@ async function mountPet(ctx, options, bridge) {
1260
1936
  session.append("turn/start", { turn: turn + 1 });
1261
1937
  session.append("turn/end", { turn: turn + 1, reason: { kind: "completed" } });
1262
1938
  const event = session.snapshotEvents().at(-1);
1263
- const claim = broker.claim(input.clientId, input.generation, noticeId(session.id, turn + 1, event.seq, "completed", "initial"));
1939
+ const claim = broker.claim(input.clientId, input.generation, noticeId(session.id, turn + 1, event.seq, "reply", "initial"));
1264
1940
  if (!claim) throw new Error("\u6D4B\u8BD5\u901A\u77E5\u672A\u80FD\u9886\u53D6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
1265
1941
  return { ok: true, value: claim };
1266
1942
  }
@@ -1271,7 +1947,7 @@ async function mountPet(ctx, options, bridge) {
1271
1947
  return { ok: false, error: { code: "coopanion/rejected", message: String(error instanceof Error ? error.message : error).slice(0, 600), details: {} } };
1272
1948
  }
1273
1949
  };
1274
- for (const endpoint of ["status", "control", "navigation", ...notificationEndpoints]) {
1950
+ for (const endpoint of ["status", "control", "navigation", "locale", ...notificationEndpoints]) {
1275
1951
  child.effect(() => child.connection.fetch.register({
1276
1952
  path: `/api/coopanion/${endpoint}`,
1277
1953
  methods: ["POST"],
@@ -1297,6 +1973,30 @@ async function mountPet(ctx, options, bridge) {
1297
1973
  update();
1298
1974
  });
1299
1975
  for (const agent of ctx.agents.list()) restoreSession(agent.session, agent.status === "running");
1976
+ ctx.inject(["sessionController", "sessionQuery"], (child) => {
1977
+ const lifetime = new AbortController();
1978
+ child.effect(() => () => lifetime.abort());
1979
+ void (async () => {
1980
+ const { items } = await child.sessionController.list({}, lifetime.signal);
1981
+ for (const item of items.filter((item2) => item2.origin !== "subagent").slice(0, 100)) {
1982
+ if (lifetime.signal.aborted) return;
1983
+ const observed = await child.sessionQuery.observeSession(item.sessionId, { signal: lifetime.signal });
1984
+ try {
1985
+ const source = { id: observed.header.id, header: observed.header, snapshotEvents: () => observed.events };
1986
+ model.restore(source);
1987
+ broker.restore(source, observed.projections?.values.userQuestions);
1988
+ if (!ctx.agents.list().some((agent) => agent.session.id === item.sessionId && agent.status === "running")) model.idle(item.sessionId);
1989
+ } finally {
1990
+ observed[Symbol.dispose]();
1991
+ }
1992
+ }
1993
+ syncNotifications();
1994
+ update();
1995
+ })().catch((error) => {
1996
+ if (!lifetime.signal.aborted) child.logger.warn(`Desktop pet history unavailable: ${String(error).slice(0, 300)}`);
1997
+ });
1998
+ update();
1999
+ });
1300
2000
  ctx.on("session/created", (session) => {
1301
2001
  restoreSession(session);
1302
2002
  syncNotifications();
@@ -1334,7 +2034,8 @@ async function mountPet(ctx, options, bridge) {
1334
2034
  });
1335
2035
  ctx.on("session/disposed", (session) => {
1336
2036
  broker.remove(session.id);
1337
- model.remove(session.id);
2037
+ model.idle(session.id);
2038
+ model.detached(session.id);
1338
2039
  update();
1339
2040
  });
1340
2041
  ctx.inject(["userQuestions"], (child) => {
@@ -1398,23 +2099,11 @@ async function mountPet(ctx, options, bridge) {
1398
2099
  update();
1399
2100
  return;
1400
2101
  }
1401
- if (action.type !== "chat" || typeof action.text !== "string" || typeof action.sessionId !== "string") return;
1402
- const text = action.text.trim();
1403
- if (!text || text.length > 2e3 || !model.select(action.sessionId)) return;
1404
- const id2 = model.snapshot().sessionId;
1405
- const agent = ctx.agents.list().find((agent2) => agent2.session.id === id2);
1406
- if (!agent || agent.session.header.origin === "subagent") {
1407
- bridge.notify({ title: "\u4F1A\u8BDD\u5C1A\u672A\u5C31\u7EEA", body: "\u8BF7\u5148\u56DE\u5230 Harness \u6253\u5F00\u8FD9\u4E2A\u4F1A\u8BDD\uFF0C\u7136\u540E\u518D\u53D1\u9001\u6D88\u606F\u3002", sessionId: action.sessionId });
1408
- update();
1409
- return;
1410
- }
1411
- try {
1412
- ctx.agents.withInitiator(agent, () => agent.followup(createUserMessage({ content: [{ type: "text", text }], source: { kind: "user" } })));
2102
+ if (action.type !== "chat") return;
2103
+ void chat.submit(action, chatLifetime.signal).then((receipt) => {
2104
+ if (receipt) bridge.chatResult?.(receipt);
1413
2105
  update();
1414
- } catch (error) {
1415
- bridge.notify({ title: "\u6D88\u606F\u672A\u80FD\u53D1\u9001", body: "\u8BF7\u56DE\u5230 Harness \u68C0\u67E5\u4F1A\u8BDD\u72B6\u6001\u3002", sessionId: action.sessionId });
1416
- ctx.logger.warn(`Desktop pet chat failed: ${String(error)}`);
1417
- }
2106
+ });
1418
2107
  };
1419
2108
  ctx.effect(() => {
1420
2109
  bridge.onAction(onAction);