synabun 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +1 -1
  3. package/docs/whatsapp.md +52 -20
  4. package/hooks/claude-code/pre-websearch.mjs +4 -1
  5. package/hooks/claude-code/prompt-submit.mjs +7 -0
  6. package/lib/mcp-build.js +519 -0
  7. package/lib/mcp-dist.js +10 -4
  8. package/lib/release-scan.mjs +23 -10
  9. package/lib/server-supervisor.js +7 -1
  10. package/lib/virustotal.mjs +146 -40
  11. package/mcp-server/dist/http.d.ts +57 -0
  12. package/mcp-server/dist/http.d.ts.map +1 -1
  13. package/mcp-server/dist/http.js +128 -18
  14. package/mcp-server/dist/http.js.map +1 -1
  15. package/mcp-server/dist/index.d.ts.map +1 -1
  16. package/mcp-server/dist/index.js +14 -9
  17. package/mcp-server/dist/index.js.map +1 -1
  18. package/mcp-server/dist/services/browser-route-flow.d.ts +119 -0
  19. package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -0
  20. package/mcp-server/dist/services/browser-route-flow.js +340 -0
  21. package/mcp-server/dist/services/browser-route-flow.js.map +1 -0
  22. package/mcp-server/dist/services/desktop-client.js +2 -2
  23. package/mcp-server/dist/services/desktop-client.js.map +1 -1
  24. package/mcp-server/dist/services/embedding-service.d.ts.map +1 -1
  25. package/mcp-server/dist/services/embedding-service.js +2 -1
  26. package/mcp-server/dist/services/embedding-service.js.map +1 -1
  27. package/mcp-server/dist/services/identity.d.ts +66 -3
  28. package/mcp-server/dist/services/identity.d.ts.map +1 -1
  29. package/mcp-server/dist/services/identity.js +61 -4
  30. package/mcp-server/dist/services/identity.js.map +1 -1
  31. package/mcp-server/dist/services/neural-interface.d.ts +133 -1
  32. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  33. package/mcp-server/dist/services/neural-interface.js +630 -64
  34. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  35. package/mcp-server/dist/services/tool-catalog.js +2 -2
  36. package/mcp-server/dist/services/tool-catalog.js.map +1 -1
  37. package/mcp-server/dist/tools/agents.d.ts +3 -2
  38. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  39. package/mcp-server/dist/tools/agents.js +6 -4
  40. package/mcp-server/dist/tools/agents.js.map +1 -1
  41. package/mcp-server/dist/tools/bluesky.d.ts +20 -7
  42. package/mcp-server/dist/tools/bluesky.d.ts.map +1 -1
  43. package/mcp-server/dist/tools/bluesky.js +147 -45
  44. package/mcp-server/dist/tools/bluesky.js.map +1 -1
  45. package/mcp-server/dist/tools/browser-advanced.d.ts +13 -2
  46. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  47. package/mcp-server/dist/tools/browser-advanced.js +153 -18
  48. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  49. package/mcp-server/dist/tools/browser-cheatsheet.d.ts +2 -0
  50. package/mcp-server/dist/tools/browser-cheatsheet.d.ts.map +1 -1
  51. package/mcp-server/dist/tools/browser-cheatsheet.js +3 -0
  52. package/mcp-server/dist/tools/browser-cheatsheet.js.map +1 -1
  53. package/mcp-server/dist/tools/browser-navigate.d.ts +3 -3
  54. package/mcp-server/dist/tools/browser-navigate.d.ts.map +1 -1
  55. package/mcp-server/dist/tools/browser-navigate.js +19 -16
  56. package/mcp-server/dist/tools/browser-navigate.js.map +1 -1
  57. package/mcp-server/dist/tools/browser-observe.d.ts +2 -1
  58. package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
  59. package/mcp-server/dist/tools/browser-observe.js +61 -20
  60. package/mcp-server/dist/tools/browser-observe.js.map +1 -1
  61. package/mcp-server/dist/tools/morelogin.d.ts +13 -3
  62. package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
  63. package/mcp-server/dist/tools/morelogin.js +82 -19
  64. package/mcp-server/dist/tools/morelogin.js.map +1 -1
  65. package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
  66. package/mcp-server/dist/tools/youtube/helpers.d.ts +1 -0
  67. package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
  68. package/mcp-server/dist/tools/youtube/helpers.js +1 -1
  69. package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
  70. package/mcp-server/dist/tools/youtube/upload.d.ts.map +1 -1
  71. package/mcp-server/dist/tools/youtube/upload.js +225 -88
  72. package/mcp-server/dist/tools/youtube/upload.js.map +1 -1
  73. package/mcp-server/package-lock.json +2 -2
  74. package/mcp-server/package.json +1 -1
  75. package/mcp-server/src/http.ts +135 -17
  76. package/mcp-server/src/index.ts +15 -9
  77. package/mcp-server/src/services/browser-route-flow.ts +403 -0
  78. package/mcp-server/src/services/desktop-client.ts +2 -2
  79. package/mcp-server/src/services/embedding-service.ts +2 -1
  80. package/mcp-server/src/services/identity.ts +80 -4
  81. package/mcp-server/src/services/neural-interface.ts +648 -73
  82. package/mcp-server/src/services/tool-catalog.ts +2 -2
  83. package/mcp-server/src/tools/agents.ts +8 -4
  84. package/mcp-server/src/tools/bluesky.ts +164 -51
  85. package/mcp-server/src/tools/browser-advanced.ts +142 -17
  86. package/mcp-server/src/tools/browser-cheatsheet.ts +3 -0
  87. package/mcp-server/src/tools/browser-navigate.ts +19 -16
  88. package/mcp-server/src/tools/browser-observe.ts +62 -20
  89. package/mcp-server/src/tools/morelogin.ts +82 -19
  90. package/mcp-server/src/tools/youtube/helpers.ts +2 -2
  91. package/mcp-server/src/tools/youtube/upload.ts +218 -99
  92. package/neural-interface/i18n/en.json +655 -123
  93. package/neural-interface/i18n/pt-BR.json +542 -10
  94. package/neural-interface/lib/assistant-api.js +90 -23
  95. package/neural-interface/lib/assistant-brains/claude.js +5 -0
  96. package/neural-interface/lib/assistant-catalog.js +134 -3
  97. package/neural-interface/lib/assistant-dispatch.js +97 -1
  98. package/neural-interface/lib/assistant-persona.js +15 -7
  99. package/neural-interface/lib/assistant-router.js +6 -4
  100. package/neural-interface/lib/assistant-runtime.js +18 -1
  101. package/neural-interface/lib/assistant-task-prompt.js +5 -0
  102. package/neural-interface/lib/assistant-tools.js +10 -1
  103. package/neural-interface/lib/automation-approval.js +249 -0
  104. package/neural-interface/lib/automation-browser-owner-access.js +82 -0
  105. package/neural-interface/lib/backup-service.js +16 -1
  106. package/neural-interface/lib/browser-automation-routes.js +84 -0
  107. package/neural-interface/lib/browser-background-tab.js +72 -3
  108. package/neural-interface/lib/browser-execution.js +16 -3
  109. package/neural-interface/lib/browser-extraction.js +106 -45
  110. package/neural-interface/lib/browser-owner.js +48 -0
  111. package/neural-interface/lib/browser-profile-choices.js +143 -0
  112. package/neural-interface/lib/browser-profiles.js +142 -0
  113. package/neural-interface/lib/browser-session-close.js +84 -0
  114. package/neural-interface/lib/browser-start-handoff.js +202 -0
  115. package/neural-interface/lib/browser-tab-recovery.js +153 -0
  116. package/neural-interface/lib/browser-tool-policy.js +23 -4
  117. package/neural-interface/lib/browser-wedge-retire.js +64 -0
  118. package/neural-interface/lib/chromium-on-device-model.js +67 -0
  119. package/neural-interface/lib/claude-agent-bridge.js +43 -5
  120. package/neural-interface/lib/claude-background-hold.js +239 -0
  121. package/neural-interface/lib/claude-model-catalog.js +12 -0
  122. package/neural-interface/lib/effort-levels.js +28 -2
  123. package/neural-interface/lib/exec-loop-command.js +8 -0
  124. package/neural-interface/lib/http-guards.js +11 -6
  125. package/neural-interface/lib/local-profile-proxy.js +362 -0
  126. package/neural-interface/lib/local-profiles.js +929 -0
  127. package/neural-interface/lib/loop-logger.js +31 -5
  128. package/neural-interface/lib/maritaca/api.js +179 -0
  129. package/neural-interface/lib/maritaca/attachments.js +44 -0
  130. package/neural-interface/lib/maritaca/client.js +362 -0
  131. package/neural-interface/lib/maritaca/key-store.js +122 -0
  132. package/neural-interface/lib/maritaca/models.js +181 -0
  133. package/neural-interface/lib/maritaca/modes.js +39 -0
  134. package/neural-interface/lib/maritaca/opencode-proxy.js +236 -0
  135. package/neural-interface/lib/maritaca/opencode-stream.js +345 -0
  136. package/neural-interface/lib/maritaca/opencode.js +218 -0
  137. package/neural-interface/lib/maritaca/panel-bridge.js +273 -0
  138. package/neural-interface/lib/maritaca/sessions.js +198 -0
  139. package/neural-interface/lib/mcp-external-servers.js +37 -10
  140. package/neural-interface/lib/morelogin-agent-profiles.js +149 -0
  141. package/neural-interface/lib/morelogin.js +278 -14
  142. package/neural-interface/lib/native-loop-providers.js +124 -11
  143. package/neural-interface/lib/native-loop-runtime.js +112 -11
  144. package/neural-interface/lib/owner-authority.js +137 -43
  145. package/neural-interface/lib/page-session.js +111 -27
  146. package/neural-interface/lib/peer-identity.js +263 -43
  147. package/neural-interface/lib/provider-panel-api-key-auth.js +7 -2
  148. package/neural-interface/lib/pty-host/core.js +36 -0
  149. package/neural-interface/lib/pty-host/protocol.js +2 -0
  150. package/neural-interface/lib/request-gate.js +2 -0
  151. package/neural-interface/lib/skills/api-v2.js +13 -2
  152. package/neural-interface/lib/skills/creation-api.js +3 -1
  153. package/neural-interface/lib/skills/evals-api.js +5 -1
  154. package/neural-interface/lib/social-write-pacing.js +151 -0
  155. package/neural-interface/lib/system-activity.js +1 -1
  156. package/neural-interface/lib/terminal-token-redaction.js +293 -0
  157. package/neural-interface/lib/terminal-tokens.js +436 -0
  158. package/neural-interface/lib/worker-mcp-channel.js +45 -10
  159. package/neural-interface/package-lock.json +3 -2
  160. package/neural-interface/package.json +2 -1
  161. package/neural-interface/public/assets/mascot/README.md +11 -0
  162. package/neural-interface/public/assets/mascot/ask.gif +0 -0
  163. package/neural-interface/public/assets/mascot/ask.png +0 -0
  164. package/neural-interface/public/assets/mascot/blocked.gif +0 -0
  165. package/neural-interface/public/assets/mascot/blocked.png +0 -0
  166. package/neural-interface/public/assets/mascot/budget.gif +0 -0
  167. package/neural-interface/public/assets/mascot/budget.png +0 -0
  168. package/neural-interface/public/assets/mascot/computer.gif +0 -0
  169. package/neural-interface/public/assets/mascot/computer.png +0 -0
  170. package/neural-interface/public/assets/mascot/edit.gif +0 -0
  171. package/neural-interface/public/assets/mascot/edit.png +0 -0
  172. package/neural-interface/public/assets/mascot/error.gif +0 -0
  173. package/neural-interface/public/assets/mascot/error.png +0 -0
  174. package/neural-interface/public/assets/mascot/hover-attention.gif +0 -0
  175. package/neural-interface/public/assets/mascot/hover-attention.png +0 -0
  176. package/neural-interface/public/assets/mascot/idle-hero.gif +0 -0
  177. package/neural-interface/public/assets/mascot/idle-hero.png +0 -0
  178. package/neural-interface/public/assets/mascot/idle.gif +0 -0
  179. package/neural-interface/public/assets/mascot/idle.png +0 -0
  180. package/neural-interface/public/assets/mascot/manifest.json +254 -0
  181. package/neural-interface/public/assets/mascot/mcp.gif +0 -0
  182. package/neural-interface/public/assets/mascot/mcp.png +0 -0
  183. package/neural-interface/public/assets/mascot/memory.gif +0 -0
  184. package/neural-interface/public/assets/mascot/memory.png +0 -0
  185. package/neural-interface/public/assets/mascot/offline.gif +0 -0
  186. package/neural-interface/public/assets/mascot/offline.png +0 -0
  187. package/neural-interface/public/assets/mascot/pick.gif +0 -0
  188. package/neural-interface/public/assets/mascot/pick.png +0 -0
  189. package/neural-interface/public/assets/mascot/plan.gif +0 -0
  190. package/neural-interface/public/assets/mascot/plan.png +0 -0
  191. package/neural-interface/public/assets/mascot/present.gif +0 -0
  192. package/neural-interface/public/assets/mascot/present.png +0 -0
  193. package/neural-interface/public/assets/mascot/project.gif +0 -0
  194. package/neural-interface/public/assets/mascot/project.png +0 -0
  195. package/neural-interface/public/assets/mascot/read.gif +0 -0
  196. package/neural-interface/public/assets/mascot/read.png +0 -0
  197. package/neural-interface/public/assets/mascot/runs.gif +0 -0
  198. package/neural-interface/public/assets/mascot/runs.png +0 -0
  199. package/neural-interface/public/assets/mascot/scenes/automation.gif +0 -0
  200. package/neural-interface/public/assets/mascot/scenes/automation.png +0 -0
  201. package/neural-interface/public/assets/mascot/scenes/browser.gif +0 -0
  202. package/neural-interface/public/assets/mascot/scenes/browser.png +0 -0
  203. package/neural-interface/public/assets/mascot/scenes/code.gif +0 -0
  204. package/neural-interface/public/assets/mascot/scenes/code.png +0 -0
  205. package/neural-interface/public/assets/mascot/scenes/complex.gif +0 -0
  206. package/neural-interface/public/assets/mascot/scenes/complex.png +0 -0
  207. package/neural-interface/public/assets/mascot/scenes/computer.gif +0 -0
  208. package/neural-interface/public/assets/mascot/scenes/computer.png +0 -0
  209. package/neural-interface/public/assets/mascot/scenes/design.gif +0 -0
  210. package/neural-interface/public/assets/mascot/scenes/design.png +0 -0
  211. package/neural-interface/public/assets/mascot/scenes/edit.gif +0 -0
  212. package/neural-interface/public/assets/mascot/scenes/edit.png +0 -0
  213. package/neural-interface/public/assets/mascot/scenes/generic.gif +0 -0
  214. package/neural-interface/public/assets/mascot/scenes/generic.png +0 -0
  215. package/neural-interface/public/assets/mascot/scenes/image_gen.gif +0 -0
  216. package/neural-interface/public/assets/mascot/scenes/image_gen.png +0 -0
  217. package/neural-interface/public/assets/mascot/scenes/manifest.json +173 -0
  218. package/neural-interface/public/assets/mascot/scenes/memory.gif +0 -0
  219. package/neural-interface/public/assets/mascot/scenes/memory.png +0 -0
  220. package/neural-interface/public/assets/mascot/scenes/quick.gif +0 -0
  221. package/neural-interface/public/assets/mascot/scenes/quick.png +0 -0
  222. package/neural-interface/public/assets/mascot/scenes/read.gif +0 -0
  223. package/neural-interface/public/assets/mascot/scenes/read.png +0 -0
  224. package/neural-interface/public/assets/mascot/scenes/research.gif +0 -0
  225. package/neural-interface/public/assets/mascot/scenes/research.png +0 -0
  226. package/neural-interface/public/assets/mascot/scenes/review.gif +0 -0
  227. package/neural-interface/public/assets/mascot/scenes/review.png +0 -0
  228. package/neural-interface/public/assets/mascot/scenes/search.gif +0 -0
  229. package/neural-interface/public/assets/mascot/scenes/search.png +0 -0
  230. package/neural-interface/public/assets/mascot/scenes/shell.gif +0 -0
  231. package/neural-interface/public/assets/mascot/scenes/shell.png +0 -0
  232. package/neural-interface/public/assets/mascot/scenes/thinking.gif +0 -0
  233. package/neural-interface/public/assets/mascot/scenes/thinking.png +0 -0
  234. package/neural-interface/public/assets/mascot/scenes/video_gen.gif +0 -0
  235. package/neural-interface/public/assets/mascot/scenes/video_gen.png +0 -0
  236. package/neural-interface/public/assets/mascot/scenes/web.gif +0 -0
  237. package/neural-interface/public/assets/mascot/scenes/web.png +0 -0
  238. package/neural-interface/public/assets/mascot/search.gif +0 -0
  239. package/neural-interface/public/assets/mascot/search.png +0 -0
  240. package/neural-interface/public/assets/mascot/shell.gif +0 -0
  241. package/neural-interface/public/assets/mascot/shell.png +0 -0
  242. package/neural-interface/public/assets/mascot/skill.gif +0 -0
  243. package/neural-interface/public/assets/mascot/skill.png +0 -0
  244. package/neural-interface/public/assets/mascot/sleep.gif +0 -0
  245. package/neural-interface/public/assets/mascot/sleep.png +0 -0
  246. package/neural-interface/public/assets/mascot/subagent.gif +0 -0
  247. package/neural-interface/public/assets/mascot/subagent.png +0 -0
  248. package/neural-interface/public/assets/mascot/success.gif +0 -0
  249. package/neural-interface/public/assets/mascot/success.png +0 -0
  250. package/neural-interface/public/assets/mascot/think.gif +0 -0
  251. package/neural-interface/public/assets/mascot/think.png +0 -0
  252. package/neural-interface/public/assets/mascot/wait.gif +0 -0
  253. package/neural-interface/public/assets/mascot/wait.png +0 -0
  254. package/neural-interface/public/assets/mascot/watch.gif +0 -0
  255. package/neural-interface/public/assets/mascot/watch.png +0 -0
  256. package/neural-interface/public/assets/mascot/web.gif +0 -0
  257. package/neural-interface/public/assets/mascot/web.png +0 -0
  258. package/neural-interface/public/onboarding.html +14 -1
  259. package/neural-interface/public/shared/agent-runtime-options.js +49 -8
  260. package/neural-interface/public/shared/agy/agy-panel.js +2 -2
  261. package/neural-interface/public/shared/agy/agy-render.js +41 -1
  262. package/neural-interface/public/shared/agy/agy-styles.js +5 -0
  263. package/neural-interface/public/shared/api.js +5 -4
  264. package/neural-interface/public/shared/assistant/asst-ask-styles.js +8 -8
  265. package/neural-interface/public/shared/assistant/asst-ask.js +1 -1
  266. package/neural-interface/public/shared/assistant/asst-brain-picker.js +99 -9
  267. package/neural-interface/public/shared/assistant/asst-computer.js +47 -2
  268. package/neural-interface/public/shared/assistant/asst-control.js +1 -1
  269. package/neural-interface/public/shared/assistant/asst-limit-wait.js +7 -5
  270. package/neural-interface/public/shared/assistant/asst-panel.js +13 -5
  271. package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -4
  272. package/neural-interface/public/shared/assistant/asst-render.js +16 -10
  273. package/neural-interface/public/shared/assistant/asst-route-models.js +64 -4
  274. package/neural-interface/public/shared/assistant/asst-route.js +24 -7
  275. package/neural-interface/public/shared/assistant/asst-routes-editor.js +154 -39
  276. package/neural-interface/public/shared/assistant/asst-run-stage.js +3 -3
  277. package/neural-interface/public/shared/assistant/asst-scene-styles.js +8 -111
  278. package/neural-interface/public/shared/assistant/asst-scenes.js +46 -318
  279. package/neural-interface/public/shared/assistant/asst-sidepanel.js +2 -2
  280. package/neural-interface/public/shared/assistant/asst-state.js +72 -2
  281. package/neural-interface/public/shared/assistant/asst-styles.js +60 -15
  282. package/neural-interface/public/shared/automation-approval-view.js +75 -0
  283. package/neural-interface/public/shared/cdx/cdx-panel.js +2 -2
  284. package/neural-interface/public/shared/cdx/cdx-render.js +73 -7
  285. package/neural-interface/public/shared/cdx/cdx-tabs.js +3 -3
  286. package/neural-interface/public/shared/context-menu-model.js +2 -0
  287. package/neural-interface/public/shared/cp/cp-agents.js +8 -0
  288. package/neural-interface/public/shared/cp/cp-permissions.js +6 -2
  289. package/neural-interface/public/shared/cp/cp-rehydrate.js +25 -1
  290. package/neural-interface/public/shared/cp/cp-tasks-model.js +33 -0
  291. package/neural-interface/public/shared/editor/editor-panel-logic.js +10 -0
  292. package/neural-interface/public/shared/editor/editor-panel.js +10 -2
  293. package/neural-interface/public/shared/html-shell.js +30 -22
  294. package/neural-interface/public/shared/judgments-log-origins.js +29 -0
  295. package/neural-interface/public/shared/morelogin-profile-choices.js +107 -0
  296. package/neural-interface/public/shared/morelogin-profile-field.js +186 -0
  297. package/neural-interface/public/shared/mtc/mtc-client.js +181 -0
  298. package/neural-interface/public/shared/mtc/mtc-compose.js +40 -0
  299. package/neural-interface/public/shared/mtc/mtc-copy.js +253 -0
  300. package/neural-interface/public/shared/mtc/mtc-logic.js +478 -0
  301. package/neural-interface/public/shared/mtc/mtc-panel.js +1354 -0
  302. package/neural-interface/public/shared/mtc/mtc-render.js +172 -0
  303. package/neural-interface/public/shared/mtc/mtc-styles.js +437 -0
  304. package/neural-interface/public/shared/ocp-v2/ocp-v2-automation-ownership.js +23 -0
  305. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +13 -0
  306. package/neural-interface/public/shared/ocp-v2/ocp-v2-icons.js +3 -1
  307. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +10 -4
  308. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +6 -86
  309. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +5 -2
  310. package/neural-interface/public/shared/owner-access.js +134 -0
  311. package/neural-interface/public/shared/owner-authority-view.js +92 -0
  312. package/neural-interface/public/shared/page-session.js +143 -14
  313. package/neural-interface/public/shared/poll-backoff.js +59 -0
  314. package/neural-interface/public/shared/provider-icons.js +3 -0
  315. package/neural-interface/public/shared/schedules-view.js +7 -0
  316. package/neural-interface/public/shared/server-back.js +50 -0
  317. package/neural-interface/public/shared/settings/settings-browser-owner-access.js +72 -0
  318. package/neural-interface/public/shared/settings/settings-data.js +7 -1
  319. package/neural-interface/public/shared/settings/settings-ia.js +3 -1
  320. package/neural-interface/public/shared/settings/settings-kit.js +11 -3
  321. package/neural-interface/public/shared/settings/settings-local-profiles.js +153 -0
  322. package/neural-interface/public/shared/settings/settings-maritaca-opencode.js +105 -0
  323. package/neural-interface/public/shared/settings/settings-shell.js +7 -0
  324. package/neural-interface/public/shared/shown-children.js +72 -0
  325. package/neural-interface/public/shared/sidepanel-session-status.js +16 -2
  326. package/neural-interface/public/shared/state.js +1 -1
  327. package/neural-interface/public/shared/static-bg-state.js +22 -0
  328. package/neural-interface/public/shared/styles.css +457 -164
  329. package/neural-interface/public/shared/synabun-mascot-assets.js +67 -0
  330. package/neural-interface/public/shared/synabun-mascot.js +136 -12
  331. package/neural-interface/public/shared/synabun-ticker.js +3 -0
  332. package/neural-interface/public/shared/synabun-tools.js +173 -0
  333. package/neural-interface/public/shared/tool-heartbeat.js +43 -0
  334. package/neural-interface/public/shared/tool-list-picker.js +3 -1
  335. package/neural-interface/public/shared/tool-list-view.js +23 -4
  336. package/neural-interface/public/shared/topright-overflow-logic.js +1 -0
  337. package/neural-interface/public/shared/ui-automation-approval.js +188 -0
  338. package/neural-interface/public/shared/ui-automation-studio.js +138 -91
  339. package/neural-interface/public/shared/ui-claude-panel.js +209 -31
  340. package/neural-interface/public/shared/ui-judgments.js +37 -10
  341. package/neural-interface/public/shared/ui-maritaca-panel.js +15 -0
  342. package/neural-interface/public/shared/ui-navbar.js +23 -0
  343. package/neural-interface/public/shared/ui-owner-access.js +191 -0
  344. package/neural-interface/public/shared/ui-owner-authority.js +162 -0
  345. package/neural-interface/public/shared/ui-panels.js +3 -1
  346. package/neural-interface/public/shared/ui-schedules-studio.js +118 -17
  347. package/neural-interface/public/shared/ui-scroll-follow.js +3 -0
  348. package/neural-interface/public/shared/ui-sessions.js +45 -16
  349. package/neural-interface/public/shared/ui-settings.js +676 -42
  350. package/neural-interface/public/shared/ui-sidepanel-session-entry.js +8 -2
  351. package/neural-interface/public/shared/ui-sidepanel-sessions.js +3 -3
  352. package/neural-interface/public/shared/ui-sidepanel-tray.js +24 -0
  353. package/neural-interface/public/shared/ui-sidepanel-windows.js +1 -1
  354. package/neural-interface/public/shared/ui-terminal.js +15 -7
  355. package/neural-interface/public/shared/ui-tutorial-preview.js +4 -0
  356. package/neural-interface/public/shared/ui-update.js +3 -0
  357. package/neural-interface/public/shared/ui-whiteboard.js +4 -0
  358. package/neural-interface/public/shared/window-keys.js +38 -0
  359. package/neural-interface/scripts/build-mascot-assets.mjs +30 -0
  360. package/neural-interface/server.js +2903 -359
  361. package/npm-shrinkwrap.json +5 -17
  362. package/package.json +5 -6
  363. package/postinstall.js +38 -39
  364. package/setup.js +33 -31
  365. package/skills/synabun/modules/changelog.md +14 -0
@@ -424,6 +424,13 @@ export function createAssistantDispatcher({
424
424
  localPortRange = null,
425
425
  toolListOptions = () => ({}),
426
426
  acquireLoopBrowserAndTab = null,
427
+ // A run's own MoreLogin profile (agent_dispatch morelogin_profile). resolveBrowserProfile(ref) → { envId, name } for
428
+ // an id or a name MoreLogin lists (it throws with status / code for an unknown, ambiguous or Firefox-type one);
429
+ // pinBrowserProfile(runId, envId, name) makes it the run's pin before its tab is acquired (server.js
430
+ // pinRunMoreLoginProfile: the pin a schedule's run is launched with). Without them a dispatch that names a
431
+ // profile is refused, never started in the default browser.
432
+ resolveBrowserProfile = null,
433
+ pinBrowserProfile = null,
427
434
  releaseSharedBrowserTab = async () => {},
428
435
  reconcileKeepAwake = () => {},
429
436
  memory = null,
@@ -766,6 +773,32 @@ export function createAssistantDispatcher({
766
773
  notifyWaiters(entry.runId, reason);
767
774
  }
768
775
 
776
+ // ── browser route (a run's browser moved while it works) ───────────────────
777
+ /**
778
+ * The worker's browser session or tab changed while the run lives: SynaBun recovered a lost one, or the worker
779
+ * opened a new one with browser_session create (server.js noteAutomationBrowserRoute). The run record names the
780
+ * route it uses now, so agent_status and the panel never show the dead one. Like markDelivered, persisted WITHOUT a
781
+ * version bump or a waiter wake-up (a route change is not news a waiting brain must stop for); the panel gets the
782
+ * view. Returns false for an unknown, ended or browser-less run.
783
+ */
784
+ function noteBrowserRoute(runId, { browserSessionId = null, browserTabId = null, reason = 'recovered' } = {}) {
785
+ const entry = entries.get(runId);
786
+ if (!entry || !entry.usesBrowser || !ACTIVE_STATES.has(entry.state) || !browserSessionId) return false;
787
+ const sessionId = String(browserSessionId);
788
+ const tabId = browserTabId ? String(browserTabId) : null;
789
+ if (entry.browserSessionId === sessionId && (entry.browserTabId || null) === tabId) return true;
790
+ const was = entry.browserSessionId ? `${entry.browserSessionId}${entry.browserTabId ? ` tab ${entry.browserTabId}` : ''}` : 'none';
791
+ entry.browserSessionId = sessionId;
792
+ entry.browserTabId = tabId;
793
+ if (!Array.isArray(entry.notes)) entry.notes = [];
794
+ entry.notes.push(`browser ${reason === 'created' ? 'replaced by the worker (browser_session create)' : 'recovered by SynaBun'}: session ${sessionId}${tabId ? ` tab ${tabId}` : ''} (was ${was})`);
795
+ persist();
796
+ const payload = { type: 'assistant:dispatch', reason: 'browser_route', run: view(entry) };
797
+ try { broadcastSync(payload); } catch {}
798
+ for (const listener of listeners) { try { listener(payload); } catch {} }
799
+ return true;
800
+ }
801
+
769
802
  // ── delivery (what the owning brain already read) ──────────────────────────
770
803
  /**
771
804
  * High-water mark of the run results a brain has read (agent_wait,
@@ -893,6 +926,11 @@ export function createAssistantDispatcher({
893
926
  const usesBrowser = spec.usesBrowser === true || selection.groups.some(isBrowserGroup);
894
927
  const usesComputer = spec.usesComputer === true || spec.usesComputer === 'true';
895
928
  const tags = Array.isArray(spec.tags) ? spec.tags.map((tag) => String(tag).trim()).filter(Boolean).slice(0, 10) : [];
929
+ // The worker's own MoreLogin profile (resolved in dispatch(): withBrowserProfile) is for its browser tab.
930
+ const moreloginEnvId = spec.moreloginEnvId ? String(spec.moreloginEnvId) : null;
931
+ if (moreloginEnvId && !usesBrowser) {
932
+ throw new DispatchError('BROWSER_PROFILE_WITHOUT_BROWSER', 'morelogin_profile names the MoreLogin profile of the worker\'s browser tab: pass uses_browser: true with it, or leave it out.', { status: 400 });
933
+ }
896
934
  if ((usesBrowser || usesComputer) && capability === 'full' && !tags.includes('user-authorized-full')) {
897
935
  throw new DispatchError('QUARANTINE_VIOLATION', `${usesComputer ? 'Computer-use' : 'Browser-reading'} runs must use capability "read-only" or "workspace" unless tagged "user-authorized-full" by explicit user request.`);
898
936
  }
@@ -1007,6 +1045,7 @@ export function createAssistantDispatcher({
1007
1045
  idempotencyKey: spec.idempotencyKey || spec.idempotency_key ? String(spec.idempotencyKey || spec.idempotency_key).slice(0, 200) : null,
1008
1046
  queueIfBusy: spec.queueIfBusy !== false,
1009
1047
  requestedBrowserSessionId: spec.browserSessionId || null,
1048
+ moreloginEnvId, moreloginEnvName: moreloginEnvId && spec.moreloginEnvName ? String(spec.moreloginEnvName) : null,
1010
1049
  };
1011
1050
  }
1012
1051
 
@@ -1285,6 +1324,7 @@ export function createAssistantDispatcher({
1285
1324
  maxMinutes: spec.maxMinutes, budgetUsd: spec.budgetUsd ?? null, freeModel: spec.freeModel === true, idleTimeoutMs: spec.idleTimeoutMs, maxTurns: spec.maxTurns,
1286
1325
  outputSchema: spec.outputSchema, focus: spec.focus, workflowId: spec.workflowId, parentRunId: spec.parentRunId,
1287
1326
  idempotencyKey: spec.idempotencyKey, requestedBrowserSessionId: spec.requestedBrowserSessionId,
1327
+ moreloginEnvId: spec.moreloginEnvId || null, moreloginEnvName: spec.moreloginEnvName || null,
1288
1328
  modelInfo: spec.modelInfo || null, modelContextWindow: spec.modelContextWindow || null, pricingModel: spec.pricingModel || spec.model || null,
1289
1329
  };
1290
1330
  }
@@ -1352,6 +1392,54 @@ export function createAssistantDispatcher({
1352
1392
  * `brief`: a brief carried over from an earlier run (escalation, retry); never from a request body.
1353
1393
  * `notes`: what the caller changed in the spec (a planning brain's read-only clamp), for the run's notes.
1354
1394
  */
1395
+ /**
1396
+ * `rawSpec` with the MoreLogin profile it names resolved: `moreloginProfile` / `morelogin_profile` (an id or a name)
1397
+ * or `moreloginEnvId` become `moreloginEnvId` + `moreloginEnvName` of a Chrome-type profile MoreLogin lists. A spec
1398
+ * that names none is returned as it is. An unknown, ambiguous or Firefox-type profile is refused (the resolver's own
1399
+ * message and code), as is any profile on a server that cannot pin one.
1400
+ */
1401
+ async function withBrowserProfile(rawSpec) {
1402
+ const named = rawSpec.moreloginProfile ?? rawSpec.morelogin_profile ?? null;
1403
+ const id = rawSpec.moreloginEnvId ?? rawSpec.morelogin_env_id ?? null;
1404
+ const has = (value) => value !== null && value !== undefined && String(value).trim() !== '';
1405
+ const { moreloginProfile: _a, morelogin_profile: _b, morelogin_env_id: _c, moreloginEnvId: _d, moreloginEnvName: _e, ...rest } = rawSpec;
1406
+ if (!has(named) && !has(id)) return rest;
1407
+ if (typeof resolveBrowserProfile !== 'function' || typeof pinBrowserProfile !== 'function') {
1408
+ throw new DispatchError('BROWSER_PROFILE_UNSUPPORTED', 'This server cannot give a worker a MoreLogin profile of its own; the run was not started in the default browser instead.', { status: 400 });
1409
+ }
1410
+ let found;
1411
+ try {
1412
+ found = await resolveBrowserProfile(has(id) ? { envId: String(id).trim(), ...(has(named) ? { name: String(named).trim() } : {}) } : { profile: String(named).trim() });
1413
+ } catch (error) {
1414
+ throw new DispatchError(error?.code || 'BROWSER_PROFILE_UNAVAILABLE', `${error?.message || error} The run was not started (never in another profile or browser).`, { status: error?.status || 400 });
1415
+ }
1416
+ return { ...rest, moreloginEnvId: found.envId, moreloginEnvName: found.name || null };
1417
+ }
1418
+
1419
+ /** The run's own MoreLogin profile becomes its pin, before its browser tab is acquired (a start, a resume). */
1420
+ function pinEntryBrowserProfile(entry) {
1421
+ if (!entry?.usesBrowser || !entry.moreloginEnvId || typeof pinBrowserProfile !== 'function') return;
1422
+ pinBrowserProfile(entry.runId, entry.moreloginEnvId, entry.moreloginEnvName || null);
1423
+ }
1424
+
1425
+ /**
1426
+ * A worker chose a MoreLogin profile for itself mid-run (the morelogin tool's "use", server.js
1427
+ * chooseSessionMoreLoginProfile): its record follows, so a resume after a restart pins the same one. `profile`:
1428
+ * { envId, name }, or null for the default browser. Returns false for an unknown or browser-less run.
1429
+ */
1430
+ function noteBrowserProfile(runId, profile) {
1431
+ const entry = entries.get(runId);
1432
+ if (!entry || !entry.usesBrowser) return false;
1433
+ const envId = profile?.envId ? String(profile.envId) : null;
1434
+ if ((entry.moreloginEnvId || null) === envId) return true;
1435
+ entry.moreloginEnvId = envId;
1436
+ entry.moreloginEnvName = envId && profile?.name ? String(profile.name) : null;
1437
+ if (!Array.isArray(entry.notes)) entry.notes = [];
1438
+ entry.notes.push(`browser profile chosen by the worker: ${envId ? `MoreLogin profile ${entry.moreloginEnvName ? `"${entry.moreloginEnvName}" (${envId})` : envId}` : 'the default browser'}`);
1439
+ persist();
1440
+ return true;
1441
+ }
1442
+
1355
1443
  async function dispatch(rawSpec = {}, { assistantSessionId = null, origin = 'assistant', brief: carried = null, notes: callerNotes = null } = {}) {
1356
1444
  const sessionId = assistantSessionId ? String(assistantSessionId) : null;
1357
1445
  const idempotencyKey = rawSpec.idempotencyKey || rawSpec.idempotency_key ? String(rawSpec.idempotencyKey || rawSpec.idempotency_key).slice(0, 200) : null;
@@ -1366,6 +1454,9 @@ export function createAssistantDispatcher({
1366
1454
  refuseSessionOver(sessionId);
1367
1455
  // "true" (a string) is computer use too: normalizeSpec reads it so, and so must the gate.
1368
1456
  rawSpec = { ...rawSpec, usesComputer: rawSpec.usesComputer === true || rawSpec.usesComputer === 'true' };
1457
+ // The MoreLogin profile it names for the worker's browser tab, as MoreLogin lists it (refused here when it cannot
1458
+ // be used, before a route card or a queue slot).
1459
+ rawSpec = await withBrowserProfile(rawSpec);
1369
1460
  // A design dispatch's defaults fill what it leaves out, before any clamp; any dispatch's own browser
1370
1461
  // settings must agree before a route card is shown (normalizeSpec re-checks the final target, provider included).
1371
1462
  rawSpec = withClassDefaults(rawSpec, knownClass(rawSpec.taskClass));
@@ -1661,6 +1752,7 @@ export function createAssistantDispatcher({
1661
1752
  tools: entry.tools?.some(item => item.startsWith('mcp:')) ? retainExternalRefs(entry.toolsRequested ?? dispatchTools({}).items, entry.tools) : entry.toolsRequested ?? undefined, capability: entry.capability,
1662
1753
  permissionPolicy: entry.permissionPolicy,
1663
1754
  usesBrowser: entry.usesBrowser, usesComputer: entry.usesComputer, maxMinutes: entry.maxMinutes, budgetUsd: entry.budgetUsd,
1755
+ ...(entry.moreloginEnvId ? { moreloginEnvId: entry.moreloginEnvId, moreloginEnvName: entry.moreloginEnvName || null } : {}),
1664
1756
  outputSchema: entry.outputSchema, taskClass: entry.taskClass || null,
1665
1757
  }, { assistantSessionId: entry.assistantSessionId, origin: 'ui', brief: entry.brief || null });
1666
1758
  const child = entries.get(result?.run?.runId);
@@ -1839,6 +1931,7 @@ export function createAssistantDispatcher({
1839
1931
  let browserSessionId = null;
1840
1932
  let browserTabId = null;
1841
1933
  if (entry.usesBrowser && typeof acquireLoopBrowserAndTab === 'function') {
1934
+ pinEntryBrowserProfile(entry);
1842
1935
  const acq = await acquireLoopBrowserAndTab({ requestedBrowserSessionId: entry.requestedBrowserSessionId, terminalSessionId: entry.runId, logTag: 'assistant:browser' });
1843
1936
  if (acq?.error) {
1844
1937
  entry.state = 'failed'; entry.completionReason = 'browser_unavailable'; entry.finishedAt = iso(now()); entry.notes.push(acq.error);
@@ -1931,6 +2024,8 @@ export function createAssistantDispatcher({
1931
2024
  active: true, task: entry.task, context: entry.context, totalIterations: 1, currentIteration: 0,
1932
2025
  maxMinutes: entry.maxMinutes, startedAt, lastIterationAt: null, retries: 0, pending: false,
1933
2026
  terminalSessionId: entry.runId, usesBrowser: entry.usesBrowser, usesComputer: !!entry.usesComputer, browserSessionId, browserTabId,
2027
+ // The run's own MoreLogin profile (server.js runMoreLoginPin reads it back from the state file).
2028
+ ...(entry.usesBrowser && entry.moreloginEnvId ? { moreloginEnvId: entry.moreloginEnvId, moreloginEnvName: entry.moreloginEnvName || null } : {}),
1934
2029
  profile: entry.provider, provider: entry.provider, agent: entry.agent || null,
1935
2030
  model: entry.model, modelContextWindow: entry.modelContextWindow || null, effort: entry.effort, tools: entry.tools,
1936
2031
  codexAccountId: entry.codexAccountId, codexHome: entry.provider === 'codex' ? (entryCodexHome(entry)) : null,
@@ -3331,6 +3426,7 @@ export function createAssistantDispatcher({
3331
3426
  let browserSessionId = null;
3332
3427
  let browserTabId = null;
3333
3428
  if (entry.usesBrowser && typeof acquireLoopBrowserAndTab === 'function') {
3429
+ pinEntryBrowserProfile(entry);
3334
3430
  const acq = await acquireLoopBrowserAndTab({ requestedBrowserSessionId: entry.requestedBrowserSessionId, terminalSessionId: entry.runId, logTag: 'assistant:browser' }).catch((error) => ({ error: error?.message || String(error) }));
3335
3431
  if (acq?.error) return notResumed(entry, `no browser tab: ${acq.error}`);
3336
3432
  browserSessionId = acq.browserSessionId || null;
@@ -3970,7 +4066,7 @@ export function createAssistantDispatcher({
3970
4066
  respondPermission, subscribe, shutdown, limits, suspendForShutdown,
3971
4067
  sessionBudget, checkSession, refreshLimits, providerSpend, coverFollowUp, budget,
3972
4068
  resolveRoute, declineRoute, heldRouteRefusal, escalate,
3973
- markDelivered, deliveryState,
4069
+ markDelivered, deliveryState, noteBrowserRoute, noteBrowserProfile,
3974
4070
  remove, removeFinished,
3975
4071
  mediaFile,
3976
4072
  accountInUse: (provider, accountId) => activeEntries((e) => e.provider === provider && e.accountId === accountId).length > 0,
@@ -11,7 +11,7 @@ import { workerToolsLine } from './assistant-tools.js';
11
11
  // Route-mode changes after the brain started arrive as `[SynaBun Router]` lines,
12
12
  // budget changes as `[SynaBun Budget]` lines.
13
13
 
14
- import { formatModelLine } from './assistant-catalog.js';
14
+ import { formatModelLine, isMaritacaOpenCodeId } from './assistant-catalog.js';
15
15
  import { hasRouteAccounts, routeAccountText } from './assistant-route-accounts.js';
16
16
  import { browserPolicyText } from './browser-tool-policy.js';
17
17
  import { TESTS_HEADER, reportsUntested, testDensityPersonaLine } from './assistant-test-density.js';
@@ -84,6 +84,7 @@ export function toolNames(toolPrefix = 'mcp__SynaBun__') {
84
84
  remember: `${p}remember`, recall: `${p}recall`, reflect: `${p}reflect`, choice: `${p}choice`, loop: `${p}loop`,
85
85
  computer: `${p}computer`, computerApps: `${p}computer_apps`, computerAx: `${p}computer_ax`, computerStatus: `${p}computer_status`,
86
86
  browserNavigate: `${p}browser_navigate`, browserSnapshot: `${p}browser_snapshot`, browserScreenshot: `${p}browser_screenshot`, browserConsole: `${p}browser_console`,
87
+ browserSession: `${p}browser_session`,
87
88
  whatsappSendFile: `${p}whatsapp_send_file`,
88
89
  skill: `${p}skill`,
89
90
  };
@@ -100,11 +101,18 @@ function sheetLines(sheet, { opencodeTotal = null } = {}) {
100
101
  const lines = [];
101
102
  const labels = { 'claude-code': 'claude-code', codex: 'codex (ChatGPT plan billing)', opencode: 'opencode (providerID/modelID)', antigravity: 'antigravity (Google sign-in; unpriced: tokens, not prices)' };
102
103
  for (const provider of ['claude-code', 'codex', 'opencode', 'antigravity']) {
103
- const rows = sheet[provider] || [];
104
- if (!rows.length) continue;
105
- const suffix = provider === 'opencode' && opencodeTotal ? `, ${opencodeTotal} connected models — agent_catalog provider "opencode" search "…" lists more` : '';
106
- lines.push(` - ${labels[provider]}${suffix}:`);
107
- for (const row of rows) lines.push(` - ${formatModelLine(row)}`);
104
+ // Maritaca's OpenCode rows get a provider line of their own, after OpenCode's.
105
+ const rows = (sheet[provider] || []).filter((row) => provider !== 'opencode' || !isMaritacaOpenCodeId(row?.id));
106
+ if (rows.length) {
107
+ const suffix = provider === 'opencode' && opencodeTotal ? `, ${opencodeTotal} connected models — agent_catalog provider "opencode" search "…" lists more` : '';
108
+ lines.push(` - ${labels[provider]}${suffix}:`);
109
+ for (const row of rows) lines.push(` - ${formatModelLine(row)}`);
110
+ }
111
+ if (provider !== 'opencode') continue;
112
+ const maritaca = (sheet.opencode || []).filter((row) => isMaritacaOpenCodeId(row?.id));
113
+ if (!maritaca.length) continue;
114
+ lines.push(' - maritaca (Sabiá models; they run through OpenCode: provider "opencode", model "maritaca/<id>"):');
115
+ for (const row of maritaca) lines.push(` - ${formatModelLine(row)}`);
108
116
  }
109
117
  return lines;
110
118
  }
@@ -417,7 +425,7 @@ export function buildAssistantPersona({
417
425
  '3. Project: pick the registered project whose path contains the files in question; if the user names one, use it; if truly ambiguous, ask.',
418
426
  '4. Accounts: account_id \"auto\" chooses the signed-in subscription with most usage left (API keys excluded); agent_catalog includes each account’s usage. Limited pinned/default accounts fall back within the provider, with corrections; all limited selects the soonest reset. A direct route needing another account runs on a worker because conversation histories belong to their account. An approved route’s concrete account stays binding unless it becomes limited before dispatch. An approved route’s account is binding and overrides dispatch account_id. Without an applied saved route, a Claude Code worker runs under the account_id you name, else the user\'s Claude worker account (agent_catalog `claudeWorkerAccount`; null = Default); a Codex worker the same way with `codexWorkerAccount`. Each account uses its own mode (its Claude or ChatGPT subscription, or its API key). Never name a signed-out account: dispatch refuses it with ACCOUNT_SIGNED_OUT; tell the user to sign it in instead. Codex cannot run with permission_policy "ask"; use "restricted" for a sandbox.',
419
427
  '5. Browser/social growth work: capability read-only or workspace (never full), the platform group in tools (for example browser_facebook), fully autonomous with rails; never spend money. Long periodic work: create a loop or schedule instead of chaining follow-ups.',
420
- '6. Pages: a worker that must look at any page, public or localhost (visual QA included), gets uses_browser:true with capability workspace or read-only; SynaBun adds the browser group and its own tab. Never tell a worker to use Playwright, Chrome or another browser. A worker that finishes blocked with "needs the SynaBun browser" is dispatched again with uses_browser:true, not escalated.',
428
+ '6. Pages: a worker that must look at any page, public or localhost (visual QA included), gets uses_browser:true with capability workspace or read-only; SynaBun adds the browser group and its own tab. Never tell a worker to use Playwright, Chrome or another browser. A worker that finishes blocked with "needs the SynaBun browser" is dispatched again with uses_browser:true, not escalated. A task for a MoreLogin profile other than the default (a second account, "in P-4") gets morelogin_profile with that profile\'s name or id: the worker\'s tab opens there, next to runs in the default or other profiles. Only a profile the owner allowed agents to choose works (the morelogin tool\'s "list" says which; none until the owner switches one on): on MORELOGIN_PROFILE_NOT_ALLOWED tell the user to switch that profile on in Settings → Connected tools → MoreLogin → MoreLogin profiles, and do not dispatch the task into another profile. Never change the default AI browser for one task.',
421
429
  'A worker that finishes blocked with "needs SynaBun tools: <ids>" is dispatched again with those ids added to tools, not escalated.',
422
430
  '7. Computer work for a worker: uses_computer:true on a vision-capable model; one at a time.',
423
431
  '8. Title every dispatch in ≤ 6 words; put everything the worker needs in task + context.',
@@ -34,7 +34,7 @@
34
34
  import { randomBytes } from 'node:crypto';
35
35
  import { CATALOG_PROVIDERS, TIERS, defaultIsHidden, defaultModelRow, findModel, hiddenModelId, priceText, providerAllHidden, providerEmpty, rowIsHidden, rowMakes } from './assistant-catalog.js';
36
36
  import { effectiveRouting, normalizeRouteMode } from './assistant-config.js';
37
- import { normalizeEffort } from './effort-levels.js';
37
+ import { EFFORT_OFF, normalizeEffort } from './effort-levels.js';
38
38
  import { hasRouteAccounts, routeAccountText } from './assistant-route-accounts.js';
39
39
  import { chooseUsageAccount } from './account-usage.js';
40
40
  import { PROVIDER_LABELS, coversWork, dryProviders, isFreePrice, isUnpricedProvider, listPriceOf, rowOf } from './assistant-budget-split.js';
@@ -302,8 +302,10 @@ function preferenceTarget(pref, brain, catalog = null, { dispatchOnly = false }
302
302
  export function routeText(target) {
303
303
  if (!target) return 'none';
304
304
  const where = target.kind === 'direct' ? `here${target.model ? ` on ${target.model}` : ''}` : `${target.provider}/${target.model || 'default'}`;
305
- return `${where}${target.effort ? ` (${target.effort})` : ''}`;
305
+ return `${where}${target.effort ? ` (${effortWord(target.effort)})` : ''}`;
306
306
  }
307
+ /** An effort as people read it: `none` is thinking off. */
308
+ export function effortWord(effort) { return String(effort || '').toLowerCase() === EFFORT_OFF ? 'thinking off' : String(effort || ''); }
307
309
 
308
310
  /** Cheapest vision-capable model, same provider first. */
309
311
  function visionFallback(catalog, provider, { brain = {}, routing = {} } = {}) {
@@ -673,7 +675,7 @@ function optionFor(id, rawTarget, badge, { catalog, brain, brainInfo, needsVisio
673
675
  const target = effortChecked(rawTarget, catalog);
674
676
  const d = describeTarget(target, { catalog, brain, brainInfo });
675
677
  const here = target.kind === 'direct';
676
- const label = here ? `Do it here with ${d.label}` : `${providerLabel(target.provider)} · ${d.label}${target.effort ? ` · ${target.effort}` : ''}`;
678
+ const label = here ? `Do it here with ${d.label}` : `${providerLabel(target.provider)} · ${d.label}${target.effort ? ` · ${effortWord(target.effort)}` : ''}`;
677
679
  // Design: only a confirmed vision: true on an available row; other vision work: a confirmed false is disabled, unknown is a warning.
678
680
  const fit = visionOnly ? designFit(catalog, target, { brain, brainInfo }) : 'ok';
679
681
  const option = {
@@ -1327,7 +1329,7 @@ export function createAssistantRouter({
1327
1329
  // on another account: the card names it as a worker and says why, never "Do it here".
1328
1330
  if (option.kind === 'dispatch' && option.accountKind === 'direct') {
1329
1331
  const described = describeTarget(option, { catalog: cat, brain, brainInfo });
1330
- option.label = `${providerLabel(option.provider)} · ${described?.label || option.model || 'default'}${option.effort ? ` · ${option.effort}` : ''}`;
1332
+ option.label = `${providerLabel(option.provider)} · ${described?.label || option.model || 'default'}${option.effort ? ` · ${effortWord(option.effort)}` : ''}`;
1331
1333
  option.warning = option.accountCorrection?.message || WORKER_FOR_ACCOUNT_TEXT;
1332
1334
  }
1333
1335
  }
@@ -40,6 +40,7 @@ import { browserToolDenial } from './browser-tool-policy.js';
40
40
  import { browserPolicyRoots } from './browser-policy-roots.js';
41
41
  import { stripFollowups } from '../public/shared/assistant/asst-followups.js';
42
42
  import { readJsonStrict } from './rulesets/fs-safe.js';
43
+ import { redactTerminalSecrets } from './terminal-token-redaction.js';
43
44
 
44
45
  export const BRAIN_PROVIDERS = new Set(['claude-code', 'codex', 'opencode', 'antigravity']);
45
46
  // Every tab is called SynaBun; the session title (the history list) comes from
@@ -93,6 +94,8 @@ export const REMOTE_ASK_EXEMPT = new Set([
93
94
  */
94
95
  export const BRAIN_CREDENTIAL_RE = /^sbb_[A-Za-z0-9_-]{43}$/;
95
96
  export function mintBrainCredential() { return `sbb_${randomBytes(32).toString('base64url')}`; }
97
+ /** The brains whose SynaBun MCP names the session id as its pin (the Claude CLI's header, agy's environment). */
98
+ const BRAIN_PIN_PROVIDERS = new Set(['claude-code', 'antigravity']);
96
99
  // An OpenCode brain of a remote session reaches the web through these on its own
97
100
  // (no SynaBun browser, no approval): the gate plugin refuses them.
98
101
  const REMOTE_OPENCODE_WEB_TOOLS = new Set(['webfetch', 'websearch', 'codesearch']);
@@ -277,6 +280,10 @@ export function createAssistantRuntime({
277
280
  phoneAuthority = null,
278
281
  // The Admin sandbox setting (lib/agent-sandbox-setting.js): global, shown in every session view.
279
282
  adminSandbox = null,
283
+ // The server's terminal tokens (lib/terminal-tokens.js): a Claude Code or Antigravity brain names its session id in
284
+ // X-Synabun-Terminal, and that id is proven by the brain's launch credential (bind), never by a second secret;
285
+ // revoked when the brain goes. (Codex and OpenCode brains name a pin server.js binds where it starts their process.)
286
+ terminalTokens = null,
280
287
  } = {}) {
281
288
  if (!dataDir) throw new Error('createAssistantRuntime requires dataDir');
282
289
  const normalizeSessionBrain = (input, defaults, options) => normalizeBrain(input, defaults, { ...options, ...toolListOptions() });
@@ -1338,6 +1345,9 @@ export function createAssistantRuntime({
1338
1345
  }
1339
1346
  function onBrainPacket(live, packet) {
1340
1347
  if (!packet || typeof packet !== 'object') return;
1348
+ // What a brain says reaches sockets, the transcript and observers only scrubbed of SynaBun's run secrets: its own
1349
+ // launch credential or a worker's terminal token an agent printed (lib/terminal-token-redaction.js).
1350
+ packet = redactTerminalSecrets(packet);
1341
1351
  const id = live.record.id;
1342
1352
  if (packet.type === 'event') {
1343
1353
  const event = packet.event || {};
@@ -2100,6 +2110,9 @@ export function createAssistantRuntime({
2100
2110
  // (lib/skills/api-v2.js principalOf) take it; whatsapp_send_file takes it and then only the active WhatsApp
2101
2111
  // conversation's session (lib/whatsapp/service.js sendFile).
2102
2112
  live.brainCredential = mintBrainCredential();
2113
+ // The brain's own pin (its session id, for the brains that name it) is proven by this same credential: its MCP
2114
+ // presents it with X-Synabun-Terminal, and a process that only names the session gets nothing (lib/terminal-tokens.js).
2115
+ if (BRAIN_PIN_PROVIDERS.has(brain.provider)) { try { terminalTokens?.bind?.(live.record.id, live.brainCredential); } catch { /* the brain starts; its pin stays as it was */ } }
2103
2116
  const cliCap = brain.provider === 'claude-code' ? brainCliCap(live) : null;
2104
2117
  const deps = {
2105
2118
  ClaudeSession, sdkVersion, PACKAGE_ROOT, handleCodexSkinWebSocket, ensureIsolatedServe, stopIsolatedServe, setupOpencodeSidepanelConfig,
@@ -2196,8 +2209,9 @@ export function createAssistantRuntime({
2196
2209
  if (identity.providerThreadId) live.record.providerThreadId = identity.providerThreadId;
2197
2210
  } catch {}
2198
2211
  live.brain = null;
2199
- // Its credential dies with it: a file send presenting it is refused from here on.
2212
+ // Its credential dies with it: a file send presenting it is refused from here on, and so is its pin.
2200
2213
  live.brainCredential = null;
2214
+ if (BRAIN_PIN_PROVIDERS.has(live.brainProvider)) { try { terminalTokens?.revoke?.(live.record.id); } catch { /* the disposal goes on */ } }
2201
2215
  if (live.brainProvider === 'codex') pollCodex(live, { force: true });
2202
2216
  // No further turn will book them: a Claude brain's provisional tokens are booked as an estimate,
2203
2217
  // any other brain's go (Codex was just polled, OpenCode settled at its turn's end).
@@ -2958,6 +2972,9 @@ export function createAssistantRuntime({
2958
2972
  const input = { ...base, ...patch.brain, model: patch.brain.model || base.model };
2959
2973
  if (patch.brain.mcpProfile !== undefined) throw Object.assign(new Error('Use tools: [group ids].'), { code: 'MCP_PROFILE_REMOVED', status: 400 });
2960
2974
  let next = normalizeSessionBrain(input, base, { catalog: catalog?.peek?.() || null });
2975
+ // An effort the panel cleared (its Auto row: `effort: null`) is the model's default. normalizeBrain
2976
+ // would fall back to the one before it, and Off (`none`, no thinking) or a level would stay on.
2977
+ if (Object.hasOwn(patch.brain, 'effort') && (patch.brain.effort === null || patch.brain.effort === '')) next = { ...next, effort: null };
2961
2978
  next = await resolveAutoAccount(next);
2962
2979
  const modelChanged = next.model !== live.record.brain.model || next.provider !== live.record.brain.provider;
2963
2980
  if (modelChanged) next = (await enabledBrain(next)).brain;
@@ -74,6 +74,11 @@ export function browserEnforcementBlock(state = {}) {
74
74
  'This automation REQUIRES the SynaBun internal browser.',
75
75
  state.browserSessionId ? `YOUR BROWSER SESSION: ${state.browserSessionId}` : '',
76
76
  state.browserTabId ? `YOUR BROWSER TAB: ${state.browserTabId}` : '',
77
+ // A run started in a MoreLogin profile of its own (a schedule's, a dispatch's morelogin_profile): said, so the
78
+ // worker neither looks for the account in the default profile nor tries to switch to where it already is.
79
+ state.moreloginEnvId
80
+ ? `YOUR BROWSER PROFILE: MoreLogin profile ${state.moreloginEnvName ? `"${state.moreloginEnvName}" (${state.moreloginEnvId})` : state.moreloginEnvId}. This run was started in it: your browser tools already work there, not in the default profile. Stay in it unless the task names another one. If a browser call is refused because this profile is not on the owner's list of profiles agents may choose, the owner took it off: stop and report that; never continue in another profile.`
81
+ : '',
77
82
  state.browserSessionId
78
83
  ? `Pass sessionId: "${state.browserSessionId}"${state.browserTabId ? ` and tabId: "${state.browserTabId}"` : ''} to EVERY browser tool call. Omitting them can hijack another run's browser.`
79
84
  : '',
@@ -46,6 +46,15 @@ export function dispatchInput(body) {
46
46
  return { ...body };
47
47
  }
48
48
 
49
+ // A row only an unchecked provider might hold is not offered as available.
50
+ function serverRefText(row, unchecked) {
51
+ if (!unchecked.size) return row.ref;
52
+ const elsewhere = Object.entries(row.providers || {}).some(([provider, value]) => !unchecked.has(provider) && value === 'deliverable');
53
+ return elsewhere ? row.ref : `${row.ref} (not checked)`;
54
+ }
55
+
49
56
  export function workerToolsLine(catalog = toolCatalogView()) {
50
- return `SynaBun tools for workers: pass tools: [group ids] on agent_dispatch. Always there: ${catalog.alwaysOnTools.join(', ')}. With no tools a worker gets ${catalog.default.join(', ')}. Groups: ${catalog.groups.map(group => `${group.id} (${group.count})`).join(' · ')}. Host effect: ${Object.entries(catalog.effect).map(([host, effect]) => `${host}: ${effect}`).join(', ')}. Strict hosts load exactly those groups; Claude Code and Codex always reach every SynaBun tool on demand and the list only sets their focus. Never assume a Claude Code or Codex worker lacks a group you left out. Your MCP servers: name them as mcp:<name> in tools (or mcp:* for all allowed servers). Every unnamed external server is off for that worker on Claude Code, Codex, OpenCode and Antigravity. Available server refs: ${(catalog.servers || []).filter(row => row.selectable !== false).map(row => row.ref).join(', ') || 'none listed'}.`;
57
+ const unchecked = new Set((catalog.externalServerErrors || []).map(error => error.provider || 'unknown provider'));
58
+ const notChecked = unchecked.size ? ` MCP servers not checked for ${[...unchecked].join(', ')}: that provider's MCP configuration could not be read, so its servers are not listed as available and a dispatch to it naming an mcp: ref is refused until the configuration is fixed (its models are unaffected).` : '';
59
+ return `SynaBun tools for workers: pass tools: [group ids] on agent_dispatch. Always there: ${catalog.alwaysOnTools.join(', ')}. With no tools a worker gets ${catalog.default.join(', ')}. Groups: ${catalog.groups.map(group => `${group.id} (${group.count})`).join(' · ')}. Host effect: ${Object.entries(catalog.effect).map(([host, effect]) => `${host}: ${effect}`).join(', ')}. Strict hosts load exactly those groups; Claude Code and Codex always reach every SynaBun tool on demand and the list only sets their focus. Never assume a Claude Code or Codex worker lacks a group you left out. Your MCP servers: name them as mcp:<name> in tools (or mcp:* for all allowed servers). Every unnamed external server is off for that worker on Claude Code, Codex, OpenCode and Antigravity. Available server refs: ${(catalog.servers || []).filter(row => row.selectable !== false).map(row => serverRefText(row, unchecked)).join(', ') || 'none listed'}.${notChecked}`;
51
60
  }
@@ -0,0 +1,249 @@
1
+ // ── The owner's approval of what an agent changed (re-review of 2026-11-11, finding 3) ──
2
+ //
3
+ // A schedule an agent created or last changed (`taskBy: 'agent'`) and a template an agent created or changed
4
+ // (`editedBy: 'agent'`) are held to the owner's list of profiles agents may choose (lib/morelogin-agent-profiles.js
5
+ // scheduleProfileAuthority). Until 2026-11-11 an owner's save took the mark away when it carried certain fields, and the
6
+ // Schedules editor sent them by itself, so opening a marked schedule to rename it cleared the mark although the owner
7
+ // reviewed nothing. The owner's decision: no save ever clears a mark; an explicit approve action does, from the owner's
8
+ // page only, tied to the exact content the owner was shown.
9
+ //
10
+ // How:
11
+ // • The server builds the review (what will actually run and where) from the stored records: scheduleReview /
12
+ // templateReview. It shows the effective instructions (the template's task and context, every day theme's text,
13
+ // the two numbers a launch reads from `overrides`) and the account (the MoreLogin profile the run uses, by name,
14
+ // or the default browser of Settings → Browser), who chose that profile, and whether it is on the owner's list.
15
+ // • Its digest (reviewDigest) is a SHA-256 over the stored fields a launch reads for that content, never over the
16
+ // display text: the schedule's template, day themes, overrides, group, own profile, the marks; the template's task
17
+ // and context; the group's profile; the default browser. Anything an agent (or anybody) changes there after the
18
+ // review was served changes the digest, and the approve request, which carries the digest it was shown, is refused
19
+ // (409 REVIEW_CHANGED). Nothing about the request's own words is trusted: the server recomputes.
20
+ // • Approving a schedule clears its mark and, in the same act, the mark of its template (one flow for the owner).
21
+ // When the profile is the schedule's own, the owner approving "runs in <profile>" is the owner choosing that
22
+ // profile, so `moreloginEnvBy` becomes 'owner'. A group's profile chosen by an agent is the group's: approving one
23
+ // schedule never makes it the owner's for the group's other schedules (the review says so).
24
+ // • Any later change by an agent marks the record again (server.js markScheduleTaskAuthor / markTemplateAuthor).
25
+ // • Restored and imported records come in marked (`unreviewedFrom`: 'restore' / 'import'), because a file is data: no
26
+ // field in it can say "the owner approved this". markRecordsUnreviewed only adds marks, never removes one.
27
+ //
28
+ // DOM-free, no imports but node:crypto. Unit-tested in tests/automation-approval.test.mjs.
29
+
30
+ import { createHash } from 'node:crypto';
31
+
32
+ /** The version of the digest's input; bump it when the fields change, so an old review can never match. */
33
+ export const APPROVAL_DIGEST_VERSION = 'ap1';
34
+ /** The refusal codes of the approve routes. */
35
+ export const REVIEW_CHANGED = 'REVIEW_CHANGED';
36
+ export const NOTHING_TO_APPROVE = 'NOTHING_TO_APPROVE';
37
+ /** Where a mark came from when it was not an agent's own change (display only; authority reads `taskBy` / `editedBy`). */
38
+ export const UNREVIEWED_SOURCES = Object.freeze(['import', 'restore']);
39
+
40
+ const str = (value) => (value === null || value === undefined ? null : String(value));
41
+ const weekdayOrder = ['1', '2', '3', '4', '5', '6', '0'];
42
+
43
+ /** JSON with object keys sorted at every level, so equal content always hashes equally. */
44
+ export function canonicalJson(value) {
45
+ if (Array.isArray(value)) return `[${value.map((item) => canonicalJson(item === undefined ? null : item)).join(',')}]`;
46
+ if (value && typeof value === 'object') {
47
+ const keys = Object.keys(value).filter((key) => value[key] !== undefined).sort();
48
+ return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(',')}}`;
49
+ }
50
+ return JSON.stringify(value === undefined ? null : value);
51
+ }
52
+
53
+ /** The day themes as a launch reads them: weekday → contextOverride text (empty entries left out). */
54
+ function themeTexts(dayThemes) {
55
+ const out = [];
56
+ if (!dayThemes || typeof dayThemes !== 'object') return out;
57
+ for (const day of weekdayOrder) {
58
+ const entry = dayThemes[day];
59
+ if (!entry) continue;
60
+ const text = typeof entry === 'string' ? entry : (typeof entry.contextOverride === 'string' ? entry.contextOverride : '');
61
+ out.push({ day: Number(day), text, label: typeof entry === 'object' && typeof entry.theme === 'string' ? entry.theme : null });
62
+ }
63
+ return out;
64
+ }
65
+
66
+ /** The stored template fields that decide its instructions (and its mark). */
67
+ function templateCore(template) {
68
+ if (!template) return null;
69
+ return {
70
+ id: str(template.id), name: str(template.name), task: str(template.task), context: str(template.context),
71
+ usesBrowser: template.usesBrowser === undefined ? null : !!template.usesBrowser,
72
+ editedBy: template.editedBy === 'agent' ? 'agent' : null, unreviewedFrom: str(template.unreviewedFrom),
73
+ };
74
+ }
75
+
76
+ /** The stored schedule fields that decide what it runs and where (and its mark). */
77
+ function scheduleCore(schedule) {
78
+ return {
79
+ id: str(schedule.id), templateId: str(schedule.templateId), dayThemes: schedule.dayThemes ?? null,
80
+ overrides: schedule.overrides ?? null, groupId: str(schedule.groupId),
81
+ moreloginEnvId: str(schedule.moreloginEnvId), moreloginEnvBy: str(schedule.moreloginEnvBy),
82
+ usesBrowser: schedule.usesBrowser === undefined ? null : !!schedule.usesBrowser,
83
+ taskBy: schedule.taskBy === 'agent' ? 'agent' : null, unreviewedFrom: str(schedule.unreviewedFrom),
84
+ };
85
+ }
86
+
87
+ /** The group fields a schedule's run reads for its account. */
88
+ function groupCore(group) {
89
+ if (!group) return null;
90
+ return {
91
+ id: str(group.id), moreloginEnvId: str(group.moreloginEnvId), moreloginEnvBy: str(group.moreloginEnvBy),
92
+ usesBrowser: group.usesBrowser === undefined ? null : !!group.usesBrowser,
93
+ };
94
+ }
95
+
96
+ /** The default browser of Settings → Browser, as far as the account goes. */
97
+ function defaultCore(browserDefault) {
98
+ const mode = ['attach', 'morelogin'].includes(browserDefault?.connectMode) ? browserDefault.connectMode : 'mirror';
99
+ return { connectMode: mode, moreloginEnvId: mode === 'morelogin' ? str(browserDefault?.moreloginEnvId) : null };
100
+ }
101
+
102
+ /** The digest of a review's input (hex SHA-256 of the canonical JSON, prefixed by APPROVAL_DIGEST_VERSION). */
103
+ export function reviewDigest(input) {
104
+ return `${APPROVAL_DIGEST_VERSION}:${createHash('sha256').update(canonicalJson({ v: APPROVAL_DIGEST_VERSION, ...input })).digest('hex')}`;
105
+ }
106
+
107
+ /** Whether `a` and `b` are the same digest (a string compare that takes the same time whatever matches). */
108
+ export function sameDigest(a, b) {
109
+ if (typeof a !== 'string' || typeof b !== 'string') return false;
110
+ const x = Buffer.from(String(a ?? ''));
111
+ const y = Buffer.from(String(b ?? ''));
112
+ if (x.length !== y.length || !x.length) return false;
113
+ let diff = 0;
114
+ for (let i = 0; i < x.length; i++) diff |= x[i] ^ y[i];
115
+ return diff === 0;
116
+ }
117
+
118
+ /** Whether a record carries a mark the approve action is for. */
119
+ export const scheduleMarked = (schedule) => schedule?.taskBy === 'agent';
120
+ export const templateMarked = (template) => template?.editedBy === 'agent';
121
+
122
+ /**
123
+ * The account a schedule's run uses: its own profile, else its group's, else the default browser.
124
+ * @param {{ allowed?: (envId: string) => boolean, profileName?: (envId: string) => string|null }} o
125
+ */
126
+ function accountOf(schedule, group, browserDefault, { allowed = () => false, profileName = () => null } = {}) {
127
+ const holder = schedule.moreloginEnvId ? schedule : (group?.moreloginEnvId ? group : null);
128
+ if (holder) {
129
+ const envId = String(holder.moreloginEnvId);
130
+ return {
131
+ kind: 'morelogin', envId, name: holder.moreloginEnvName || profileName(envId) || null,
132
+ source: holder === schedule ? 'schedule' : 'group', groupName: holder === schedule ? null : (group?.name || null),
133
+ chosenBy: holder.moreloginEnvBy === 'owner' ? 'owner' : 'agent', onList: allowed(envId) === true,
134
+ };
135
+ }
136
+ const def = defaultCore(browserDefault);
137
+ return {
138
+ kind: 'default', connectMode: def.connectMode, envId: def.moreloginEnvId,
139
+ name: def.moreloginEnvId ? (profileName(def.moreloginEnvId) || null) : null, source: 'default', chosenBy: 'owner', onList: null,
140
+ };
141
+ }
142
+
143
+ /**
144
+ * Where a marked schedule stands now, for the flag in its list and editor:
145
+ * 'no-profile' — it runs in the default browser (the owner's choice), the mark changes nothing today;
146
+ * 'on-list' — it runs in a profile on the owner's list, as today, mark or not;
147
+ * 'blocked' — it runs in a profile off the list, and its runs are refused until the owner approves it;
148
+ * 'clear' — nothing is marked.
149
+ */
150
+ export function approvalCase({ marked, account }) {
151
+ if (!marked) return 'clear';
152
+ if (!account || account.kind !== 'morelogin') return 'no-profile';
153
+ return account.onList ? 'on-list' : 'blocked';
154
+ }
155
+
156
+ /**
157
+ * The review of a schedule: what will run and where, and the digest the approve request must carry.
158
+ * @param {{ schedule: object, template?: object|null, group?: object|null, browserDefault?: object,
159
+ * allowed?: (envId: string) => boolean, profileName?: (envId: string) => string|null }} o
160
+ */
161
+ export function scheduleReview({ schedule, template = null, group = null, browserDefault = {}, allowed, profileName } = {}) {
162
+ if (!schedule) return null;
163
+ const account = accountOf(schedule, group, browserDefault, { allowed, profileName });
164
+ const marks = {
165
+ schedule: scheduleMarked(schedule), template: templateMarked(template),
166
+ scheduleFrom: scheduleMarked(schedule) ? (UNREVIEWED_SOURCES.includes(schedule.unreviewedFrom) ? schedule.unreviewedFrom : 'agent') : null,
167
+ templateFrom: templateMarked(template) ? (UNREVIEWED_SOURCES.includes(template.unreviewedFrom) ? template.unreviewedFrom : 'agent') : null,
168
+ };
169
+ const overrides = schedule.overrides && typeof schedule.overrides === 'object' ? schedule.overrides : {};
170
+ const digest = reviewDigest({
171
+ kind: 'schedule', schedule: scheduleCore(schedule), template: templateCore(template), group: groupCore(group),
172
+ browserDefault: account.kind === 'default' ? defaultCore(browserDefault) : null,
173
+ });
174
+ // After approval: the schedule's own profile becomes the owner's choice; a group's stays whoever chose it.
175
+ const ownerAfter = account.kind !== 'morelogin' || account.source === 'schedule' || account.chosenBy === 'owner';
176
+ return {
177
+ kind: 'schedule', id: str(schedule.id), name: str(schedule.name), digest,
178
+ marks, needsApproval: marks.schedule || marks.template,
179
+ case: approvalCase({ marked: marks.schedule || marks.template, account }),
180
+ instructions: {
181
+ templateId: str(schedule.templateId), templateName: template ? str(template.name) : null, templateMissing: !template,
182
+ task: template ? str(template.task) : null, context: template ? str(template.context) : null,
183
+ dayThemes: themeTexts(schedule.dayThemes),
184
+ iterations: overrides.iterations ?? null, maxMinutes: overrides.maxMinutes ?? null,
185
+ },
186
+ account,
187
+ afterApproval: account.kind !== 'morelogin' ? 'default' : (ownerAfter ? 'owner' : 'list'),
188
+ };
189
+ }
190
+
191
+ /**
192
+ * The review of a template: its instructions, and which schedules run it (with their accounts, for display).
193
+ * @param {{ template: object, schedules?: object[], groups?: object[], browserDefault?: object, allowed?, profileName? }} o
194
+ */
195
+ export function templateReview({ template, schedules = [], groups = [], browserDefault = {}, allowed, profileName } = {}) {
196
+ if (!template) return null;
197
+ const marked = templateMarked(template);
198
+ const usedBy = schedules.filter((s) => s && s.templateId === template.id).map((s) => {
199
+ const group = s.groupId ? groups.find((g) => g.id === s.groupId) || null : null;
200
+ return { id: str(s.id), name: str(s.name), marked: scheduleMarked(s), account: accountOf(s, group, browserDefault, { allowed, profileName }) };
201
+ });
202
+ return {
203
+ kind: 'template', id: str(template.id), name: str(template.name),
204
+ digest: reviewDigest({ kind: 'template', template: templateCore(template) }),
205
+ marks: { template: marked, templateFrom: marked ? (UNREVIEWED_SOURCES.includes(template.unreviewedFrom) ? template.unreviewedFrom : 'agent') : null },
206
+ needsApproval: marked,
207
+ instructions: { task: str(template.task), context: str(template.context) },
208
+ usedBy,
209
+ };
210
+ }
211
+
212
+ /** Takes the marks away (the approve action's write). Returns the record. */
213
+ export function clearScheduleMark(schedule, { ownProfileToOwner = false } = {}) {
214
+ delete schedule.taskBy;
215
+ delete schedule.unreviewedFrom;
216
+ if (ownProfileToOwner && schedule.moreloginEnvId) schedule.moreloginEnvBy = 'owner';
217
+ return schedule;
218
+ }
219
+ export function clearTemplateMark(template) {
220
+ delete template.editedBy;
221
+ delete template.unreviewedFrom;
222
+ return template;
223
+ }
224
+
225
+ /**
226
+ * Marks every record of a restored or imported file unreviewed (finding 2: an archive is data, nothing in it may say
227
+ * "the owner approved this"). Only adds marks: a record already marked keeps its mark. A schedule's own profile is
228
+ * kept, but who chose it is not believed: `moreloginEnvBy: 'owner'` from a file becomes 'agent' until approved.
229
+ * @param {unknown} data the parsed file: an array of records, or { templates } / { schedules, groups }
230
+ * @param {'templates'|'schedules'} kind
231
+ * @param {'import'|'restore'} source
232
+ * @returns {{ data: unknown, marked: number }}
233
+ */
234
+ export function markRecordsUnreviewed(data, kind, source = 'restore') {
235
+ let marked = 0;
236
+ const field = kind === 'templates' ? 'editedBy' : 'taskBy';
237
+ const mark = (record) => {
238
+ if (!record || typeof record !== 'object' || Array.isArray(record)) return;
239
+ if (record[field] !== 'agent') { record[field] = 'agent'; record.unreviewedFrom = source; marked++; }
240
+ if (kind === 'schedules' && record.moreloginEnvId && record.moreloginEnvBy === 'owner') record.moreloginEnvBy = 'agent';
241
+ };
242
+ const rows = Array.isArray(data) ? data : (data && typeof data === 'object' ? data[kind] : null);
243
+ if (Array.isArray(rows)) rows.forEach(mark);
244
+ if (kind === 'schedules' && data && typeof data === 'object' && !Array.isArray(data) && Array.isArray(data.groups)) {
245
+ // A group's profile in a file was not chosen in front of this server either.
246
+ for (const group of data.groups) if (group && typeof group === 'object' && group.moreloginEnvId && group.moreloginEnvBy === 'owner') group.moreloginEnvBy = 'agent';
247
+ }
248
+ return { data, marked };
249
+ }