synabun 2.4.1 → 2.4.3

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 (345) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +46 -6
  4. package/lib/data-home-files.js +4 -2
  5. package/lib/first-launch-protection.js +8 -2
  6. package/lib/release-npm-ci.mjs +23 -1
  7. package/lib/update-snapshot.js +11 -4
  8. package/mcp-server/dist/http.d.ts.map +1 -1
  9. package/mcp-server/dist/http.js +25 -2
  10. package/mcp-server/dist/http.js.map +1 -1
  11. package/mcp-server/dist/index.d.ts.map +1 -1
  12. package/mcp-server/dist/index.js +62 -17
  13. package/mcp-server/dist/index.js.map +1 -1
  14. package/mcp-server/dist/services/browser-bench.d.ts +22 -22
  15. package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
  16. package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
  17. package/mcp-server/dist/services/memory-maintenance.js +34 -45
  18. package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
  19. package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
  20. package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
  21. package/mcp-server/dist/services/memory-migration-copy.js +467 -0
  22. package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
  23. package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
  24. package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
  25. package/mcp-server/dist/services/memory-migration-worker.js +60 -0
  26. package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
  27. package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
  28. package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
  29. package/mcp-server/dist/services/memory-retrieval.js +188 -40
  30. package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
  31. package/mcp-server/dist/services/memory-schema.d.ts +58 -2
  32. package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
  33. package/mcp-server/dist/services/memory-schema.js +190 -13
  34. package/mcp-server/dist/services/memory-schema.js.map +1 -1
  35. package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
  36. package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
  37. package/mcp-server/dist/services/memory-sessions.js +56 -20
  38. package/mcp-server/dist/services/memory-sessions.js.map +1 -1
  39. package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
  40. package/mcp-server/dist/services/memory-verification.js +8 -5
  41. package/mcp-server/dist/services/memory-verification.js.map +1 -1
  42. package/mcp-server/dist/services/neural-interface.d.ts +5 -0
  43. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  44. package/mcp-server/dist/services/neural-interface.js +19 -2
  45. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  46. package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
  47. package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
  48. package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
  49. package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
  50. package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
  51. package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
  52. package/mcp-server/dist/services/retrieval-reader.js +145 -0
  53. package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
  54. package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
  55. package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
  56. package/mcp-server/dist/services/sqlite-write.js +94 -0
  57. package/mcp-server/dist/services/sqlite-write.js.map +1 -0
  58. package/mcp-server/dist/services/sqlite.d.ts +39 -0
  59. package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
  60. package/mcp-server/dist/services/sqlite.js +249 -8
  61. package/mcp-server/dist/services/sqlite.js.map +1 -1
  62. package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
  63. package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
  64. package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
  65. package/mcp-server/dist/services/typesafe-config.js +32 -10
  66. package/mcp-server/dist/services/typesafe-config.js.map +1 -1
  67. package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
  68. package/mcp-server/dist/services/typesafe.js +9 -7
  69. package/mcp-server/dist/services/typesafe.js.map +1 -1
  70. package/mcp-server/dist/services/vector-cache.d.ts +32 -0
  71. package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
  72. package/mcp-server/dist/services/vector-cache.js +161 -8
  73. package/mcp-server/dist/services/vector-cache.js.map +1 -1
  74. package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
  75. package/mcp-server/dist/tools/agents.d.ts +11 -7
  76. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  77. package/mcp-server/dist/tools/agents.js +27 -9
  78. package/mcp-server/dist/tools/agents.js.map +1 -1
  79. package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
  80. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  81. package/mcp-server/dist/tools/browser-advanced.js +10 -3
  82. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  83. package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
  84. package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
  85. package/mcp-server/dist/tools/browser-extension-setup.js +29 -0
  86. package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
  87. package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
  88. package/mcp-server/dist/tools/browser-interact.js +6 -1
  89. package/mcp-server/dist/tools/browser-interact.js.map +1 -1
  90. package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
  91. package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
  92. package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
  93. package/mcp-server/package-lock.json +5 -5
  94. package/mcp-server/package.json +1 -1
  95. package/mcp-server/src/http.ts +20 -2
  96. package/mcp-server/src/index.ts +59 -17
  97. package/mcp-server/src/services/memory-maintenance.ts +31 -28
  98. package/mcp-server/src/services/memory-migration-copy.ts +419 -0
  99. package/mcp-server/src/services/memory-migration-worker.ts +55 -0
  100. package/mcp-server/src/services/memory-retrieval.ts +173 -32
  101. package/mcp-server/src/services/memory-schema.ts +194 -12
  102. package/mcp-server/src/services/memory-sessions.ts +54 -21
  103. package/mcp-server/src/services/memory-verification.ts +7 -4
  104. package/mcp-server/src/services/neural-interface.ts +22 -2
  105. package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
  106. package/mcp-server/src/services/retrieval-reader.ts +131 -0
  107. package/mcp-server/src/services/sqlite-write.ts +60 -0
  108. package/mcp-server/src/services/sqlite.ts +246 -8
  109. package/mcp-server/src/services/typesafe-config.ts +25 -6
  110. package/mcp-server/src/services/typesafe.ts +9 -7
  111. package/mcp-server/src/services/vector-cache.ts +154 -9
  112. package/mcp-server/src/tools/agents.ts +26 -9
  113. package/mcp-server/src/tools/browser-advanced.ts +10 -3
  114. package/mcp-server/src/tools/browser-extension-setup.ts +36 -0
  115. package/mcp-server/src/tools/browser-interact.ts +5 -1
  116. package/neural-interface/i18n/en.json +313 -2
  117. package/neural-interface/i18n/pt-BR.json +321 -10
  118. package/neural-interface/lib/agents/split.js +32 -4
  119. package/neural-interface/lib/assistant-api.js +52 -8
  120. package/neural-interface/lib/assistant-brains/claude.js +2 -0
  121. package/neural-interface/lib/assistant-brains/opencode.js +121 -7
  122. package/neural-interface/lib/assistant-catalog.js +2 -2
  123. package/neural-interface/lib/assistant-config.js +0 -7
  124. package/neural-interface/lib/assistant-dispatch.js +281 -95
  125. package/neural-interface/lib/assistant-envelope.js +40 -0
  126. package/neural-interface/lib/assistant-persona.js +16 -4
  127. package/neural-interface/lib/assistant-pricing.js +65 -14
  128. package/neural-interface/lib/assistant-router.js +131 -47
  129. package/neural-interface/lib/assistant-run-wait.js +45 -28
  130. package/neural-interface/lib/assistant-runtime.js +133 -42
  131. package/neural-interface/lib/backup-contents.js +158 -0
  132. package/neural-interface/lib/backup-crypto-io.js +330 -0
  133. package/neural-interface/lib/backup-crypto-worker.js +130 -0
  134. package/neural-interface/lib/backup-crypto.js +525 -0
  135. package/neural-interface/lib/backup-download.js +268 -0
  136. package/neural-interface/lib/backup-encryption.js +318 -0
  137. package/neural-interface/lib/backup-groups.js +287 -0
  138. package/neural-interface/lib/backup-restore-session.js +176 -0
  139. package/neural-interface/lib/backup-restore-stage.js +60 -0
  140. package/neural-interface/lib/backup-service.js +788 -233
  141. package/neural-interface/lib/backup-zip-reader.js +30 -18
  142. package/neural-interface/lib/backup-zip-writer.js +34 -10
  143. package/neural-interface/lib/browser-extension-adapter.js +89 -15
  144. package/neural-interface/lib/browser-extension-archive.js +149 -0
  145. package/neural-interface/lib/browser-extension-bridge.js +24 -10
  146. package/neural-interface/lib/browser-extension-folder.js +596 -76
  147. package/neural-interface/lib/browser-extension-package.js +200 -0
  148. package/neural-interface/lib/browser-extension-pin.js +84 -0
  149. package/neural-interface/lib/browser-extension-pin.json +33 -0
  150. package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +91 -6
  151. package/neural-interface/lib/browser-extension-setup.js +105 -18
  152. package/neural-interface/lib/claude-agent-bridge.js +1 -0
  153. package/neural-interface/lib/claude-session-cleanup.js +5 -1
  154. package/neural-interface/lib/cli-install.js +23 -3
  155. package/neural-interface/lib/cli-update-planner.js +171 -9
  156. package/neural-interface/lib/client-diagnostics.js +42 -0
  157. package/neural-interface/lib/confined-fs.js +7 -2
  158. package/neural-interface/lib/coordination/README.md +8 -2
  159. package/neural-interface/lib/coordination/contract.js +161 -0
  160. package/neural-interface/lib/coordination/database.js +999 -0
  161. package/neural-interface/lib/coordination/operations.js +436 -0
  162. package/neural-interface/lib/coordination/service.js +68 -537
  163. package/neural-interface/lib/coordination/storage-worker.js +101 -0
  164. package/neural-interface/lib/coordination/store.js +219 -1111
  165. package/neural-interface/lib/db.js +70 -32
  166. package/neural-interface/lib/health-count.js +37 -0
  167. package/neural-interface/lib/loop-stall.js +139 -0
  168. package/neural-interface/lib/maritaca/client.js +2 -2
  169. package/neural-interface/lib/maritaca/models.js +12 -17
  170. package/neural-interface/lib/maritaca/opencode.js +4 -2
  171. package/neural-interface/lib/memory-api.js +9 -1
  172. package/neural-interface/lib/memory-session-capture.js +42 -10
  173. package/neural-interface/lib/memory-store-gate.js +313 -0
  174. package/neural-interface/lib/memory-store-migrate.js +65 -0
  175. package/neural-interface/lib/memory-timers.js +7 -7
  176. package/neural-interface/lib/native-loop-providers.js +23 -17
  177. package/neural-interface/lib/native-loop-runtime.js +48 -9
  178. package/neural-interface/lib/opencode-build-preflight.js +18 -1
  179. package/neural-interface/lib/opencode-native-boundary.js +69 -8
  180. package/neural-interface/lib/opencode-provider-view.js +14 -3
  181. package/neural-interface/lib/opencode-shell-read.js +107 -0
  182. package/neural-interface/lib/opencode-stop-failures.js +40 -0
  183. package/neural-interface/lib/opencode-turn-release.js +173 -0
  184. package/neural-interface/lib/opencode-v2-client.js +4 -1
  185. package/neural-interface/lib/opencode-v2-ws-requests.js +65 -1
  186. package/neural-interface/lib/opencode2-client.js +343 -7
  187. package/neural-interface/lib/opencode2-translate.js +161 -4
  188. package/neural-interface/lib/recall-impact.js +122 -0
  189. package/neural-interface/lib/scratch-evidence.js +420 -0
  190. package/neural-interface/lib/scratch-process-guard.js +139 -0
  191. package/neural-interface/lib/scratch-references.js +279 -0
  192. package/neural-interface/lib/scratch-retention-core.js +385 -0
  193. package/neural-interface/lib/scratch-retention-worker.js +37 -0
  194. package/neural-interface/lib/scratch-retention.js +151 -0
  195. package/neural-interface/lib/session-cache-builder.js +31 -43
  196. package/neural-interface/lib/session-cache-worker.js +157 -0
  197. package/neural-interface/lib/session-indexer.js +28 -21
  198. package/neural-interface/lib/session-search-index.js +85 -0
  199. package/neural-interface/lib/skills/creation.js +1 -1
  200. package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
  201. package/neural-interface/lib/style-guide/store.js +43 -3
  202. package/neural-interface/lib/system-restore.js +50 -0
  203. package/neural-interface/lib/teams/api.js +15 -6
  204. package/neural-interface/lib/teams/claims.js +67 -31
  205. package/neural-interface/lib/teams/index.js +7 -7
  206. package/neural-interface/lib/teams/integration.js +40 -40
  207. package/neural-interface/lib/teams/landing.js +6 -6
  208. package/neural-interface/lib/teams/recovery.js +24 -23
  209. package/neural-interface/lib/teams/scheduler.js +194 -95
  210. package/neural-interface/lib/teams/state.js +14 -14
  211. package/neural-interface/lib/teams/worktrees.js +27 -27
  212. package/neural-interface/lib/terminal-token-redaction.js +83 -0
  213. package/neural-interface/lib/whatsapp/bridge.js +54 -7
  214. package/neural-interface/lib/worker-confinement.js +47 -2
  215. package/neural-interface/lib/worker-mcp-channel.js +2 -0
  216. package/neural-interface/lib/worker-resume.js +5 -0
  217. package/neural-interface/lib/worker-stop.js +86 -0
  218. package/neural-interface/package-lock.json +5 -5
  219. package/neural-interface/package.json +1 -1
  220. package/neural-interface/public/extension-setup.html +5 -2
  221. package/neural-interface/public/index.html +233 -24
  222. package/neural-interface/public/onboarding.html +259 -34
  223. package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
  224. package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
  225. package/neural-interface/public/shared/agy/agy-options.js +11 -0
  226. package/neural-interface/public/shared/agy/agy-panel.js +67 -20
  227. package/neural-interface/public/shared/agy/agy-styles.js +14 -12
  228. package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
  229. package/neural-interface/public/shared/api.js +1 -1
  230. package/neural-interface/public/shared/assistant/asst-api.js +28 -3
  231. package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
  232. package/neural-interface/public/shared/assistant/asst-control.js +2 -0
  233. package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
  234. package/neural-interface/public/shared/assistant/asst-panel.js +87 -3
  235. package/neural-interface/public/shared/assistant/asst-rack-styles.js +27 -0
  236. package/neural-interface/public/shared/assistant/asst-render.js +243 -44
  237. package/neural-interface/public/shared/assistant/asst-route.js +100 -21
  238. package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
  239. package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
  240. package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
  241. package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
  242. package/neural-interface/public/shared/assistant/asst-state.js +11 -0
  243. package/neural-interface/public/shared/assistant/asst-styles.js +11 -23
  244. package/neural-interface/public/shared/assistant/route-identity.js +2 -1
  245. package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
  246. package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
  247. package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
  248. package/neural-interface/public/shared/cdx/cdx-tabs.js +54 -9
  249. package/neural-interface/public/shared/client-diagnostics.js +94 -0
  250. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  251. package/neural-interface/public/shared/cp/cp-styles.js +1 -1
  252. package/neural-interface/public/shared/effort-i18n.js +118 -0
  253. package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
  254. package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
  255. package/neural-interface/public/shared/html-shell.js +4 -52
  256. package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
  257. package/neural-interface/public/shared/memory-store-wait.js +52 -0
  258. package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
  259. package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
  260. package/neural-interface/public/shared/mtc/mtc-panel.js +25 -3
  261. package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
  262. package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
  263. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
  264. package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
  265. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
  266. package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
  267. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +152 -8
  268. package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
  269. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +53 -4
  270. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +52 -6
  271. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +22 -2
  272. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
  273. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
  274. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
  275. package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
  276. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +67 -93
  277. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
  278. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
  279. package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
  280. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
  281. package/neural-interface/public/shared/output-format.js +294 -0
  282. package/neural-interface/public/shared/provider-icons.js +6 -0
  283. package/neural-interface/public/shared/schedules-view.js +2 -1
  284. package/neural-interface/public/shared/server-presence.js +77 -0
  285. package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
  286. package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
  287. package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
  288. package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
  289. package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
  290. package/neural-interface/public/shared/settings/settings-ia.js +1 -1
  291. package/neural-interface/public/shared/shell-stop-view.js +83 -0
  292. package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
  293. package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
  294. package/neural-interface/public/shared/studio-attention.js +6 -0
  295. package/neural-interface/public/shared/styles.css +341 -437
  296. package/neural-interface/public/shared/tour/tour-actor.js +14 -3
  297. package/neural-interface/public/shared/transcript-rows.js +28 -3
  298. package/neural-interface/public/shared/tray-auto-close.js +49 -6
  299. package/neural-interface/public/shared/ui-agents.js +1 -2
  300. package/neural-interface/public/shared/ui-automation-studio.js +168 -108
  301. package/neural-interface/public/shared/ui-claude-panel.js +62 -65
  302. package/neural-interface/public/shared/ui-loading.js +124 -17
  303. package/neural-interface/public/shared/ui-native-loop-router.js +52 -0
  304. package/neural-interface/public/shared/ui-navbar.js +2 -1
  305. package/neural-interface/public/shared/ui-output.js +533 -0
  306. package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
  307. package/neural-interface/public/shared/ui-scroll-follow.js +101 -6
  308. package/neural-interface/public/shared/ui-sessions.js +2 -2
  309. package/neural-interface/public/shared/ui-settings-entry.js +18 -0
  310. package/neural-interface/public/shared/ui-settings.js +224 -65
  311. package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
  312. package/neural-interface/public/shared/ui-tooltip.js +16 -0
  313. package/neural-interface/public/shared/ui-tutorial.js +5 -6
  314. package/neural-interface/public/shared/ui-worker-end.js +27 -8
  315. package/neural-interface/public/shared/worker-end.js +9 -4
  316. package/neural-interface/public/variant/2d/main.js +5 -0
  317. package/neural-interface/public/variant/3d/app.js +10 -0
  318. package/neural-interface/public/variant/3d/main.js +5 -1
  319. package/neural-interface/scripts/scratch-retention.mjs +20 -0
  320. package/neural-interface/server.js +725 -173
  321. package/npm-shrinkwrap.json +5 -5
  322. package/package.json +1 -2
  323. package/scripts/restore-data-home-from-backup.mjs +175 -8
  324. package/setup.js +18 -4
  325. package/browser-extension/content.js +0 -189
  326. package/browser-extension/engine.js +0 -508
  327. package/browser-extension/icons/icon-128.png +0 -0
  328. package/browser-extension/icons/icon-16.png +0 -0
  329. package/browser-extension/icons/icon-32.png +0 -0
  330. package/browser-extension/icons/icon-48.png +0 -0
  331. package/browser-extension/icons/status-off-16.png +0 -0
  332. package/browser-extension/icons/status-off-32.png +0 -0
  333. package/browser-extension/icons/status-off-48.png +0 -0
  334. package/browser-extension/icons/status-on-16.png +0 -0
  335. package/browser-extension/icons/status-on-32.png +0 -0
  336. package/browser-extension/icons/status-on-48.png +0 -0
  337. package/browser-extension/manifest.json +0 -56
  338. package/browser-extension/popup-strings.js +0 -250
  339. package/browser-extension/popup-view.js +0 -151
  340. package/browser-extension/popup.css +0 -166
  341. package/browser-extension/popup.html +0 -108
  342. package/browser-extension/popup.js +0 -359
  343. package/browser-extension/service-worker.js +0 -275
  344. package/browser-extension/setup-content.js +0 -36
  345. package/browser-extension/tokens.css +0 -326
@@ -55,20 +55,20 @@ const PAGE = 500;
55
55
  export function createTeamState({ store, log = () => {} } = {}) {
56
56
  if (!store || typeof store.journal?.write !== 'function') throw new TeamError('STORE_REQUIRED', 'The teams modules need a coordination store (lib/coordination/store.js).');
57
57
 
58
- function entriesOf(teamId) {
58
+ async function entriesOf(teamId) {
59
59
  const out = [];
60
60
  let afterId = 0;
61
61
  for (;;) {
62
- const page = store.journal.read({ teamId, afterId, limit: PAGE });
62
+ const page = await store.journal.read({ teamId, afterId, limit: PAGE });
63
63
  out.push(...page);
64
64
  if (page.length < PAGE) return out;
65
65
  afterId = page[page.length - 1].id;
66
66
  }
67
67
  }
68
68
 
69
- function announce(entry) {
69
+ async function announce(entry) {
70
70
  try {
71
- store.append({
71
+ await store.append({
72
72
  id: `team:${entry.teamId}:journal:${entry.id}`,
73
73
  teamId: entry.teamId,
74
74
  runId: entry.runId || null,
@@ -86,8 +86,8 @@ export function createTeamState({ store, log = () => {} } = {}) {
86
86
  * projectPath: string, baseCommit: string, baseBranch: string|null, testCommand: any, integration: object,
87
87
  * removed: boolean, slices: Record<string, object>, [key: string]: any }}
88
88
  */
89
- function record(teamId) {
90
- const entries = entriesOf(teamId);
89
+ async function record(teamId) {
90
+ const entries = await entriesOf(teamId);
91
91
  if (!entries.length) return null;
92
92
  const team = {};
93
93
  const slices = {};
@@ -136,23 +136,23 @@ export function createTeamState({ store, log = () => {} } = {}) {
136
136
  }
137
137
 
138
138
  /** Record that a team is in a state now, with what this step changes. */
139
- function writeTeam(teamId, state, data = {}) {
140
- const entry = store.journal.write({ teamId, state, data });
141
- announce(entry);
139
+ async function writeTeam(teamId, state, data = {}) {
140
+ const entry = await store.journal.write({ teamId, state, data });
141
+ await announce(entry);
142
142
  return entry;
143
143
  }
144
144
 
145
145
  /** Record that a slice is in a state now, with what this step changes. */
146
- function writeSlice(teamId, sliceId, state, data = {}, runId = null) {
146
+ async function writeSlice(teamId, sliceId, state, data = {}, runId = null, claimGlobs = null) {
147
147
  if (sliceId === INTEGRATION_SLICE_ID) throw new TeamError('RESERVED_SLICE', '"integration" is the team\'s integration worktree, not a slice.');
148
- const entry = store.journal.write({ teamId, sliceId, state, runId, data });
149
- announce(entry);
148
+ const entry = await store.journal.write({ teamId, sliceId, state, runId, data, ...(claimGlobs?.length ? { claimGlobs } : {}) });
149
+ await announce(entry);
150
150
  return entry;
151
151
  }
152
152
 
153
153
  /** Every team the journal knows (its own newest entry), oldest team first; `states` narrows it. */
154
- function teams({ states = null } = {}) {
155
- return store.journal.teams(states ? { states } : {});
154
+ async function teams({ states = null } = {}) {
155
+ return await store.journal.teams(states ? { states } : {});
156
156
  }
157
157
 
158
158
  return { record, writeTeam, writeSlice, teams, entriesOf };
@@ -29,7 +29,7 @@
29
29
  // system can clone. Changing dependencies (lockfiles, and with them the manifests) is the lockfile-owner slice's.
30
30
 
31
31
  import { execFile } from 'node:child_process';
32
- import { appendFileSync, constants as FS, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, rmdirSync, statfsSync } from 'node:fs';
32
+ import { appendFileSync, constants as FS, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmdirSync, statfsSync } from 'node:fs';
33
33
  import { copyFile, cp, rm } from 'node:fs/promises';
34
34
  import { dirname, isAbsolute, join, posix, resolve } from 'node:path';
35
35
  import { promisify } from 'node:util';
@@ -303,7 +303,7 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
303
303
  async function unmake(plan, made) {
304
304
  for (const piece of made) {
305
305
  await git(['worktree', 'remove', '--force', piece.path], { cwd: plan.projectPath });
306
- if (present(piece.path)) rmSync(piece.path, { recursive: true, force: true });
306
+ if (present(piece.path)) await rm(piece.path, { recursive: true, force: true });
307
307
  if (piece.madeBranch && await commitOf(git, plan.projectPath, `refs/heads/${piece.branch}`) === plan.baseCommit) await git(['branch', '-D', piece.branch], { cwd: plan.projectPath });
308
308
  }
309
309
  await git(['worktree', 'prune'], { cwd: plan.projectPath });
@@ -356,7 +356,7 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
356
356
  if (command === false) return refuse('INVALID_TEST_COMMAND', 'testCommand is a command line (text) or a list of arguments.');
357
357
 
358
358
  return locks.run(repoKey(plan.projectPath), async () => {
359
- if (state.record(plan.teamId)) return refuse('TEAM_EXISTS', `A team named "${plan.teamId}" is already recorded. Pick another team id, or remove that team first.`, { existing: [{ kind: 'journal', teamId: plan.teamId }] });
359
+ if (await state.record(plan.teamId)) return refuse('TEAM_EXISTS', `A team named "${plan.teamId}" is already recorded. Pick another team id, or remove that team first.`, { existing: [{ kind: 'journal', teamId: plan.teamId }] });
360
360
  const existing = await collisions(plan);
361
361
  if (existing.length) {
362
362
  const what = existing.map((each) => each.path || each.branch).join(', ');
@@ -364,38 +364,38 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
364
364
  }
365
365
  const excluded = await ensureWorktreesExcluded(git, plan.projectPath);
366
366
  const pieces = planPieces(plan);
367
- state.writeTeam(plan.teamId, 'creating', {
367
+ await state.writeTeam(plan.teamId, 'creating', {
368
368
  plan: pieces.team, baseBranch: repo.branch, headAtCreate: repo.head, testCommand: command, createdBy: typeof createdBy === 'string' ? createdBy : null,
369
369
  integration: { head: plan.baseCommit, lastGood: plan.baseCommit, tests: null },
370
370
  });
371
371
  for (const piece of pieces.slices) {
372
- state.writeSlice(plan.teamId, piece.id, 'planned', { task: piece.task });
373
- state.writeSlice(plan.teamId, piece.id, 'pending', { ownedPaths: piece.ownedPaths, ...placeOf(plan, piece.id), startCommit: plan.baseCommit });
372
+ await state.writeSlice(plan.teamId, piece.id, 'planned', { task: piece.task });
373
+ await state.writeSlice(plan.teamId, piece.id, 'pending', { ownedPaths: piece.ownedPaths, ...placeOf(plan, piece.id), startCommit: plan.baseCommit });
374
374
  }
375
375
  const built = await materialize(plan);
376
376
  if (!built.ok) {
377
377
  await unmake(plan, built.made);
378
- state.writeTeam(plan.teamId, 'failed', { error: built.failed, failedAt: now() });
378
+ await state.writeTeam(plan.teamId, 'failed', { error: built.failed, failedAt: now() });
379
379
  return refuse('WORKTREE_FAILED', `The worktree of "${built.failed.sliceId}" could not be made: ${built.failed.error}. Nothing of the team is left.`, { failed: built.failed });
380
380
  }
381
381
  const prepared = await runSetup(plan, plan.readOnly ? null : setup === undefined ? defaultSetup : setup);
382
- state.writeTeam(plan.teamId, 'planned', { worktrees: built.made.map(({ sliceId, path, branch }) => ({ sliceId, path, branch })) });
383
- return { ok: true, team: state.record(plan.teamId), setup: prepared, excluded };
382
+ await state.writeTeam(plan.teamId, 'planned', { worktrees: built.made.map(({ sliceId, path, branch }) => ({ sliceId, path, branch })) });
383
+ return { ok: true, team: await state.record(plan.teamId), setup: prepared, excluded };
384
384
  });
385
385
  }
386
386
 
387
387
  /** A team's record (lib/teams/state.js), or null. */
388
- const get = (teamId) => (isTeamSlug(teamId) ? state.record(teamId) : null);
388
+ const get = async (teamId) => (isTeamSlug(teamId) ? await state.record(teamId) : null);
389
389
 
390
390
  /**
391
391
  * The teams the journal knows, oldest first.
392
392
  * @param {{ projectPath?: string, states?: string[], includeRemoved?: boolean }} [query]
393
393
  */
394
- function list({ projectPath = null, states = null, includeRemoved = true } = {}) {
394
+ async function list({ projectPath = null, states = null, includeRemoved = true } = {}) {
395
395
  const wanted = projectPath ? realOf(projectPath) : null;
396
396
  const out = [];
397
- for (const entry of state.teams(states ? { states } : {})) {
398
- const record = state.record(entry.teamId);
397
+ for (const entry of await state.teams(states ? { states } : {})) {
398
+ const record = await state.record(entry.teamId);
399
399
  if (!record) continue;
400
400
  if (wanted && realOf(record.projectPath) !== wanted) continue;
401
401
  if (!includeRemoved && record.removed) continue;
@@ -436,7 +436,7 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
436
436
  * integration branch, uncommitted files, last commit), the integration branch, and the user's branch.
437
437
  */
438
438
  async function inspect(teamId) {
439
- const record = get(teamId);
439
+ const record = await get(teamId);
440
440
  if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
441
441
  const registered = isDirectory(record.projectPath) ? await listWorktrees(git, record.projectPath) : [];
442
442
  const integration = record.plan.readOnly ? {} : await pieceInfo(record, INTEGRATION_SLICE_ID, registered);
@@ -477,7 +477,7 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
477
477
  * @returns {Promise<{ ok: true, sliceId: string, worktree: string, branch: string, startCommit: string, rework: boolean } | { ok: false, code: string }>}
478
478
  */
479
479
  async function startSlice(teamId, sliceId, { runId = null } = {}) {
480
- const record = get(teamId);
480
+ const record = await get(teamId);
481
481
  if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
482
482
  const slice = planSlice(record, sliceId);
483
483
  if (!slice) return refuse('SLICE_NOT_FOUND', `Team "${teamId}" has no slice "${sliceId}".`);
@@ -504,15 +504,15 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
504
504
  }
505
505
  startCommit = await commitOf(git, path, 'HEAD') || head;
506
506
  }
507
- state.writeSlice(teamId, sliceId, 'running', { startCommit, startedAt: now(), ...(rework ? { rework: true } : {}) }, runId);
508
- if (record.state === 'planned' || record.state === 'ready') state.writeTeam(teamId, 'running', {});
507
+ await state.writeSlice(teamId, sliceId, 'running', { startCommit, startedAt: now(), ...(rework ? { rework: true } : {}) }, runId);
508
+ if (record.state === 'planned' || record.state === 'ready') await state.writeTeam(teamId, 'running', {});
509
509
  return { ok: true, sliceId, worktree: path, branch, startCommit, rework };
510
510
  });
511
511
  }
512
512
 
513
513
  /** A read-only worker has ended. Preserve any changed checkout or commit, including ignored files. */
514
514
  async function finishReadOnlySlice(teamId, sliceId, { failed = false } = {}) {
515
- const record = get(teamId);
515
+ const record = await get(teamId);
516
516
  if (!record?.plan.readOnly) return refuse('TEAM_NOT_READ_ONLY', 'This operation is for read-only workers.');
517
517
  if (!planSlice(record, sliceId)) return refuse('SLICE_NOT_FOUND', `Unknown slice ${sliceId}.`);
518
518
  return locks.run(repoKey(record.projectPath), async () => {
@@ -536,12 +536,12 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
536
536
  }
537
537
  }
538
538
  const cleanup = { removed: !kept, kept, path: info.path, branch: info.branch };
539
- state.writeSlice(teamId, sliceId, failed ? 'failed' : 'completed', { cleanup, endedAt: now() });
540
- const fresh = get(teamId);
539
+ await state.writeSlice(teamId, sliceId, failed ? 'failed' : 'completed', { cleanup, endedAt: now() });
540
+ const fresh = await get(teamId);
541
541
  const ended = fresh.plan.slices.every(s => fresh.slices[s.id]?.cleanup);
542
542
  if (ended) {
543
543
  const clean = fresh.plan.slices.every(s => fresh.slices[s.id]?.cleanup.removed);
544
- state.writeTeam(teamId, 'completed', { removed: clean });
544
+ await state.writeTeam(teamId, 'completed', { removed: clean });
545
545
  if (clean) { try { rmdirSync(join(worktreesRoot(record.projectPath), teamId)); } catch {} }
546
546
  }
547
547
  return { ok: true, ...cleanup };
@@ -555,7 +555,7 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
555
555
  * @returns {Promise<{ ok: true, complete: boolean, removed: object[], kept: object[] } | { ok: false, code: string }>}
556
556
  */
557
557
  async function remove(teamId, { discard = false, force = false, guarded = false, checkOnly = false } = {}) {
558
- const record = get(teamId);
558
+ const record = await get(teamId);
559
559
  if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
560
560
  if (guarded && record.plan.readOnly) return refuse('TEAM_NOT_LANDED', 'Read-only teams cannot land.', { checks: [{ name: 'landed', ok: false, detail: 'Read-only team' }] });
561
561
  if (record.plan.readOnly) {
@@ -659,7 +659,7 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
659
659
  const pruned = await git(['worktree', 'prune'], { cwd: record.projectPath });
660
660
  if (!pruned.ok) throw new Error(`Cleanup prune failed: ${gitSaid(pruned)}`);
661
661
  try { rmdirSync(join(worktreesRoot(record.projectPath), teamId)); } catch (error) { if (error.code !== 'ENOENT' && error.code !== 'ENOTEMPTY') throw error; }
662
- state.writeTeam(teamId, 'merged', { removed: true, removal: { at: now(), force: false, removed, kept: [] } });
662
+ await state.writeTeam(teamId, 'merged', { removed: true, removal: { at: now(), force: false, removed, kept: [] } });
663
663
  return { ok: true, complete: true, removed, checks };
664
664
  }
665
665
  const registered = await listWorktrees(git, record.projectPath);
@@ -698,7 +698,7 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
698
698
  const gone = await git(['worktree', 'remove', '--force', info.path], { cwd: record.projectPath });
699
699
  if (!gone.ok && present(info.path)) {
700
700
  if (info.registered) { kept.push({ sliceId, path: info.path, branch: info.branch, head: info.head, reason: 'worktree_not_removed', error: gitSaid(gone) }); continue; }
701
- rmSync(info.path, { recursive: true, force: true });
701
+ await rm(info.path, { recursive: true, force: true });
702
702
  }
703
703
  }
704
704
  await git(['worktree', 'prune'], { cwd: record.projectPath });
@@ -712,11 +712,11 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
712
712
  let folderRemoved = false;
713
713
  try { rmdirSync(folder); folderRemoved = true; } catch { folderRemoved = !present(folder); }
714
714
  const complete = kept.length === 0;
715
- state.writeTeam(teamId, landed ? 'merged' : 'cancelled', {
715
+ await state.writeTeam(teamId, landed ? 'merged' : 'cancelled', {
716
716
  removed: complete, removal: { at: now(), discard: !landed, force: !!force, removed, kept },
717
717
  });
718
718
  for (const slice of record.plan.slices) {
719
- if (!landed && removed.some((each) => each.sliceId === slice.id) && sliceState(record, slice.id) !== 'integrated') state.writeSlice(teamId, slice.id, 'cancelled', { discarded: true });
719
+ if (!landed && removed.some((each) => each.sliceId === slice.id) && sliceState(record, slice.id) !== 'integrated') await state.writeSlice(teamId, slice.id, 'cancelled', { discarded: true });
720
720
  }
721
721
  return { ok: true, complete, landed, removed, kept, folderRemoved };
722
722
  });
@@ -738,7 +738,7 @@ export function createTeamWorktrees({ state, git, locks, setup: defaultSetup = n
738
738
  let names = [];
739
739
  try { names = readdirSync(root); } catch { names = []; }
740
740
  for (const name of names) {
741
- if (!isTeamSlug(name) || !state.record(name)) continue;
741
+ if (!isTeamSlug(name) || !await state.record(name)) continue;
742
742
  try { rmdirSync(join(root, name)); folders.push(join(root, name)); } catch { /* not empty: a team's worktrees are in it */ }
743
743
  }
744
744
  return { ok: result.ok, pruned: stale, folders, ...(result.ok ? {} : { error: gitSaid(result) }) };
@@ -179,6 +179,89 @@ export function containsTokenText(text) {
179
179
  return typeof text === 'string' && text.length >= 40 && secretIntervals(text, knownForms).length > 0;
180
180
  }
181
181
 
182
+ /**
183
+ * For a text read in pages by position (a command's output file, where no stream is kept between two reads): how many
184
+ * characters at the end of `text` could still become a token or a known form once the next page follows (a token's
185
+ * beginning, the beginning of a known form). 0 when the page can go out whole. A reader holds that end back and
186
+ * starts its next page there, so no page boundary ever cuts a secret in two that each half would pass unmasked.
187
+ */
188
+ export function partialSecretTail(text) {
189
+ if (typeof text !== 'string' || !text) return 0;
190
+ let start = text.length;
191
+ const tail = PARTIAL_TAIL_RE.exec(text);
192
+ if (tail) start = Math.min(start, tail.index);
193
+ for (const form of knownForms) {
194
+ const from = Math.max(0, text.length - (form.length - 1));
195
+ for (let i = from; i < start; i++) {
196
+ if (text.charCodeAt(i) !== form.charCodeAt(0) || !form.startsWith(text.slice(i))) continue;
197
+ start = i;
198
+ break;
199
+ }
200
+ }
201
+ return text.length - start;
202
+ }
203
+
204
+ /** How many characters before a page a reader passes to scrubPageText: more than the longest form of a secret. */
205
+ export const PAGE_CONTEXT_CHARS = 128;
206
+
207
+ /**
208
+ * One page of a text read by position, scrubbed. `before`: the characters right before the page, so a secret the
209
+ * page starts in the middle of is still recognised and its rest masked (a reader that opens on the end of a long
210
+ * output starts wherever that falls). `final`: nothing follows this page, so a marked beginning at its end (a token
211
+ * the output was cut in) is masked too. Only the page comes back.
212
+ */
213
+ export function scrubPageText(text, { before = '', final = false } = {}) {
214
+ if (typeof text !== 'string' || !text) return '';
215
+ const context = typeof before === 'string' ? before.slice(-PAGE_CONTEXT_CHARS) : '';
216
+ const whole = context + text;
217
+ const found = secretIntervals(whole, knownForms);
218
+ if (final) {
219
+ const tail = PARTIAL_TAIL_RE.exec(whole);
220
+ if (tail && MARKED_PARTIAL_RE.test(tail[0])) found.push([tail.index, whole.length]);
221
+ }
222
+ const intervals = mergeIntervals(found);
223
+ return intervals.length ? render(whole, context.length, whole.length, intervals) : text;
224
+ }
225
+
226
+ /**
227
+ * One page of a text read by position, with what lies on both sides of it, scrubbed so that the pages a reader joins
228
+ * never hold a secret whole: the masked stretches are found on the complete window (`before` + `text` + `after`)
229
+ * first, and only then is the page cut, so a secret that ends at the page's end is masked whole whatever follows it,
230
+ * and a secret that crosses the page's end is either masked here through its end or left for the next page (which
231
+ * starts with it), never split into two halves that each pass. `before`: the characters right before the page;
232
+ * `after`: the characters right after it (as many as were read; at least PAGE_CONTEXT_CHARS unless the text ends
233
+ * there); `final`: nothing will ever follow `after` (a marked beginning at the very end is masked); otherwise an end
234
+ * of the window that could still become a secret, when it reaches back into the page, is held for the next page.
235
+ * → `{ text, consumed, held }`: the scrubbed page, how many characters of `text` + `after` it covers (the next page
236
+ * starts there), and whether its end was held back because it could still become a secret.
237
+ */
238
+ export function scrubOutputWindow(text, { before = '', after = '', final = false } = {}) {
239
+ const page = typeof text === 'string' ? text : '';
240
+ const context = typeof before === 'string' ? before.slice(-PAGE_CONTEXT_CHARS) : '';
241
+ const ahead = typeof after === 'string' ? after : '';
242
+ const whole = context + page + ahead;
243
+ const start = context.length;
244
+ let end = start + page.length;
245
+ if (!page) return { text: '', consumed: 0, held: false };
246
+ const found = secretIntervals(whole, knownForms);
247
+ let held = false;
248
+ if (final) {
249
+ const tail = PARTIAL_TAIL_RE.exec(whole);
250
+ if (tail && MARKED_PARTIAL_RE.test(tail[0])) found.push([tail.index, whole.length]);
251
+ } else {
252
+ const keep = partialSecretTail(whole);
253
+ if (keep > 0 && whole.length - keep < end) { end = Math.max(start, whole.length - keep); held = true; }
254
+ }
255
+ const intervals = mergeIntervals(found);
256
+ for (const [a, b] of intervals) {
257
+ if (a >= end || b <= end) continue;
258
+ // A secret across the cut: the page ends before it, or (when the page starts inside it) runs through its end.
259
+ if (a > start) { end = a; } else { end = b; held = false; }
260
+ }
261
+ const out = intervals.length ? render(whole, start, end, intervals) : whole.slice(start, end);
262
+ return { text: out, consumed: end - start, held };
263
+ }
264
+
182
265
  /**
183
266
  * `value` with every token-shaped string replaced, at any depth of plain objects and arrays (the events, results and
184
267
  * messages SynaBun passes on). Copy on write: what holds no token is returned as it is (the same reference), and so is
@@ -57,6 +57,7 @@
57
57
  // composition are injected (Packages A and C); nothing here knows a phone number.
58
58
 
59
59
  import { assistantEventKey } from '../../public/shared/assistant/asst-state.js';
60
+ import { abandonedPrograms } from '../../public/shared/shell-stop-view.js';
60
61
  import { stripFollowups } from '../../public/shared/assistant/asst-followups.js';
61
62
  import { brainCapsLevel, defaultRemotePolicyRegistry, effectiveLevel, remoteBrainNotice } from '../remote-policy.js';
62
63
  import { brainSignature, resolveBrainChoice } from './brain.js';
@@ -136,7 +137,39 @@ const ROUTE_DONE_PHASES = new Set(['decided', 'auto', 'expired', 'declined', 'ca
136
137
  const WORKER_MOVED_ON_NOTE = 'The user did not approve this on WhatsApp (they moved on to something else). Do not retry it: continue without it, or report it as blocked.';
137
138
  const CLARIFY_DONE_PHASES = new Set(['answered', 'declined', 'chat', 'cancelled', 'expired']);
138
139
  // Computer control was stopped at the Mac (Esc, the corner, the Stop button): one line to the phone.
139
- export const MAC_STOP_TEXT = 'Computer control was stopped on your Mac: I am no longer controlling it.';
140
+ /**
141
+ * Why a Stop could not end a command, as the phone is told it: one generic reason from what the client recorded
142
+ * (lib/opencode2-client.js removeShell: OpenCode's own message with its HTTP status, or a network error). OpenCode's
143
+ * words never leave the machine: they can quote the command line.
144
+ */
145
+ export function phoneStopReason(shells) {
146
+ const said = (Array.isArray(shells) ? shells : []).map((shell) => String(shell?.reason || '')).join(' ');
147
+ if (/\bHTTP 5\d\d\b/.test(said)) return 'OpenCode answered with an error';
148
+ if (/\bHTTP 4\d\d\b/.test(said)) return 'OpenCode refused';
149
+ if (/ECONN|ETIMEDOUT|EHOSTUNREACH|ENOTFOUND|EPIPE|socket|fetch failed|could not be reached|timed? ?out/i.test(said)) return 'OpenCode could not be reached';
150
+ return 'OpenCode did not confirm the end';
151
+ }
152
+
153
+ const programList = (names) => (Array.isArray(names) ? names : []).slice(0, 5).map((name) => (name === 'command' ? 'a command' : `\`${name}\``)).join(', ');
154
+
155
+ /**
156
+ * The reply to /stop: what was cancelled (the session's runs and the queue) in every case, then what the turn's Stop
157
+ * did. `turnStop`: `{ failed: [program], reason }` (the turn goes on: the next /stop of that turn stops anyway) or
158
+ * `{ abandoned: [program] }` (it stopped anyway; the command may still run). Programs by name only.
159
+ */
160
+ export function phoneStopReply(cancelled, turnStop = null) {
161
+ const n = Math.max(0, Number(cancelled) || 0);
162
+ const tasks = `${n} task${n === 1 ? '' : 's'}`;
163
+ if (turnStop?.failed) {
164
+ const what = programList(turnStop.failed) || 'a command';
165
+ const one = turnStop.failed.length <= 1;
166
+ return `${n ? `Cancelled ${tasks}, but could not` : 'Could not'} end ${what} on your computer (${turnStop.reason || 'OpenCode did not confirm the end'}). ${one ? 'It is' : 'They are'} still running, so the current reply goes on. Send /stop again to stop anyway: ${one ? 'it' : 'they'} may keep running on the computer, and SynaBun will keep trying to end ${one ? 'it' : 'them'}.`;
167
+ }
168
+ const left = turnStop?.abandoned?.length ? ` ${programList(turnStop.abandoned)} may still be running on your computer: SynaBun keeps trying to end ${turnStop.abandoned.length === 1 ? 'it' : 'them'} in the background.` : '';
169
+ return `Stopped. Cancelled ${tasks}.${left}`;
170
+ }
171
+
172
+ export const MAC_STOP_TEXT ='Computer control was stopped on your Mac: I am no longer controlling it.';
140
173
  const usd = (value) => `$${(Number(value) || 0).toFixed(2)}`;
141
174
  const hhmm = (ms) => new Date(ms).toTimeString().slice(0, 5);
142
175
  const monthDay = (ms) => new Date(ms).toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
@@ -1071,9 +1104,8 @@ export function createWhatsAppBridge({
1071
1104
  // what waited behind it) is not acted on, as /stop clears what already waits in line.
1072
1105
  state.stoppedAt = Math.max(state.stoppedAt, tsMs(message.ts, now()));
1073
1106
  state.stopLateNoted = false;
1074
- const { stoppedRuns, clearedQueue } = await stopEverything({ reason: 'phone' });
1075
- const n = stoppedRuns + clearedQueue;
1076
- await say(`Stopped. Cancelled ${n} task${n === 1 ? '' : 's'}.`, { maxChunks: 1 });
1107
+ const { stoppedRuns, clearedQueue, turnStop } = await stopEverything({ reason: 'phone' });
1108
+ await say(phoneStopReply(stoppedRuns + clearedQueue, turnStop), { maxChunks: 1 });
1077
1109
  return;
1078
1110
  }
1079
1111
  case 'new':
@@ -1124,12 +1156,27 @@ export function createWhatsAppBridge({
1124
1156
  let stoppedRuns = 0;
1125
1157
  const turn = id ? state.turns.get(id) : null;
1126
1158
  if (turn) turn.stoppedByPhone = reason === 'phone';
1127
- if (rt && id) { try { await rt.stopTurn?.(id, { origin: 'whatsapp' }); } catch {} }
1159
+ // A Stop that could not end a command in the background (OpenCode): the turn goes on, and the phone is told. The
1160
+ // phone has no "Stop anyway" button, so the next /stop of the same turn is one (forceAfterFailures: 1, counted by
1161
+ // the runtime per turn); a stop of the service's never leaves a turn behind. What the phone hears of it is the
1162
+ // program's name and a generic reason only (phoneStopReply): never a command line or OpenCode's own words.
1163
+ let turnStop = null;
1164
+ if (rt && id) {
1165
+ try {
1166
+ const r = await rt.stopTurn?.(id, { origin: 'whatsapp', ...(reason !== 'phone' ? { force: true } : { forceAfterFailures: 1 }) });
1167
+ if (r && r.ok === false && Array.isArray(r.shells)) turnStop = { failed: abandonedPrograms(r.shells), reason: phoneStopReason(r.shells) };
1168
+ else if (r?.abandoned?.length) turnStop = { abandoned: abandonedPrograms(r.abandoned) };
1169
+ // A stop of the service's (no phone to tell): the Assistant panels of the session hear it from the runtime
1170
+ // (stop_abandoned), and the log keeps it.
1171
+ if (reason !== 'phone' && turnStop?.abandoned) log('whatsapp:bridge', `session ${id}: stopped anyway; ${turnStop.abandoned.join(', ')} may still be running (SynaBun keeps trying to end it)`);
1172
+ } catch {}
1173
+ }
1128
1174
  const d = dispatcher();
1129
1175
  if (d?.list && d?.stop && id) {
1130
1176
  let runs = [];
1131
1177
  try { runs = d.list({ assistantSessionId: id, activeOnly: true }) || []; } catch { runs = []; }
1132
- for (const run of runs) { try { await d.stop(run.runId, 'user'); stoppedRuns += 1; } catch {} }
1178
+ const stopProvenance = { actor: reason === 'phone' ? 'whatsapp_user' : 'whatsapp_service', action: 'stop' };
1179
+ for (const run of runs) { try { await d.stop(run.runId, reason === 'phone' ? 'user' : 'whatsapp_service', stopProvenance); stoppedRuns += 1; } catch {} }
1133
1180
  }
1134
1181
  for (const card of [...state.cards.values()]) {
1135
1182
  if (card.sessionId !== id) continue;
@@ -1146,7 +1193,7 @@ export function createWhatsAppBridge({
1146
1193
  const cleared = state.queue.splice(0, state.queue.length);
1147
1194
  for (const job of cleared) react(job.sourceIds, 'stopped');
1148
1195
  persistBridgeState();
1149
- return { stoppedRuns, clearedQueue: cleared.length };
1196
+ return { stoppedRuns, clearedQueue: cleared.length, turnStop };
1150
1197
  }
1151
1198
  function pause(by = 'desktop') {
1152
1199
  state.paused = true;
@@ -1453,9 +1453,54 @@ export function confinementEvent(decision, { tool, confinement, provider = null
1453
1453
  };
1454
1454
  }
1455
1455
 
1456
- /** One line for a transcript tail. */
1456
+ // A denial in a failed command's output. The bare word "sandbox" is not one (a test file can be named that).
1457
+ const CODEX_DENIAL = /operation not permitted|permission denied|read-only file system|EPERM|EACCES|EROFS|sandbox[^\n]{0,60}\b(?:den(?:y|ied)|refus\w*|block\w*|not allowed)|\b(?:den(?:y|ied)|refus\w*|block\w*|not allowed)\b[^\n]{0,60}sandbox/i;
1458
+
1459
+ /**
1460
+ * What a guarded Codex run records about a command that already finished (item.completed command_execution), or
1461
+ * null. SynaBun has no check before a Codex command runs, so this never reuses a decision's reason, which is written
1462
+ * for a real pre-execution refusal ("so it did not run"). Actions: `noted` (enforce: it ran, the heuristic objected,
1463
+ * the sandbox is the boundary), `warned` (warn: the same), `refused` (the sandbox denied an operation; the process
1464
+ * did start).
1465
+ */
1466
+ export function codexCommandEvent(item, confinement) {
1467
+ const command = typeof item?.command === 'string' ? item.command : Array.isArray(item?.command) ? item.command.join(' ') : '';
1468
+ if (!command) return null;
1469
+ const decision = workerShellDecision(command, confinement);
1470
+ const denied = Number(item.exit_code) !== 0 && CODEX_DENIAL.test(String(item.aggregated_output || item.output || ''));
1471
+ if (!decision && !denied) return null;
1472
+ const exit = Number.isInteger(item.exit_code) ? item.exit_code : null;
1473
+ const shown = `Command: ${command.slice(0, 160)}`;
1474
+ let action;
1475
+ let reason;
1476
+ if (denied) {
1477
+ action = 'refused';
1478
+ const scope = !confinement.enforced ? 'Warn mode does not change Codex\'s own sandbox.'
1479
+ : confinement.capability === 'read-only' ? 'This run (capability read-only) writes nothing, the temp folder included.'
1480
+ : `This run (capability ${confinement.capability}) writes inside ${confinement.writable.join(', ')} only.`;
1481
+ reason = `Codex's sandbox refused an operation${exit === null ? '' : `; the command started and exited ${exit}`}. ${scope} ${shown}`;
1482
+ } else {
1483
+ const ran = exit === null ? 'Codex finished the command without an exit code.' : `The command ran (exit ${exit}).`;
1484
+ action = confinement.enforced ? 'noted' : 'warned';
1485
+ reason = confinement.enforced
1486
+ ? `${ran} SynaBun's shell check flagged it afterwards and could not stop it: on Codex the sandbox is the boundary. ${shown}`
1487
+ : `${ran} Warn mode: SynaBun's shell check flagged it afterwards and stopped nothing. ${shown}`;
1488
+ }
1489
+ return {
1490
+ type: 'synabun.confinement',
1491
+ action,
1492
+ capability: confinement.capability,
1493
+ tool: 'shell',
1494
+ rule: decision?.rule || 'sandbox',
1495
+ reason,
1496
+ ...(decision?.target ? { target: decision.target } : {}),
1497
+ provider: 'codex',
1498
+ };
1499
+ }
1500
+
1501
+ /** One line for a transcript tail. `noted` is a command that already ran: never "refused". */
1457
1502
  export function describeConfinementEvent(event) {
1458
- const verb = event?.action === 'warned' ? 'guard warning' : 'refused';
1503
+ const verb = event?.action === 'warned' ? 'guard warning' : event?.action === 'noted' ? 'guard note' : 'refused';
1459
1504
  return `${verb}: ${event?.tool || 'tool'}${event?.target ? ` → ${event.target}` : ''} (${event?.rule || 'rule'}) ${String(event?.reason || '').slice(0, 200)}`;
1460
1505
  }
1461
1506
 
@@ -33,6 +33,7 @@ import express from 'express';
33
33
  import net from 'node:net';
34
34
  import { randomUUID } from 'node:crypto';
35
35
  import { isAutomationBrowserRoute } from './browser-automation-routes.js';
36
+ import { markActivity } from './loop-stall.js';
36
37
 
37
38
  // The only Neural-Interface API a sandboxed worker's stdio MCP child (OpenCode) may reach through the channel: the
38
39
  // browser routes its browser tools call over HTTP to NEURAL_INTERFACE_URL, exactly (lib/browser-automation-routes.js:
@@ -160,6 +161,7 @@ export function createWorkerMcpChannel({ createMcpRoutes, mainPort = null, fetch
160
161
  });
161
162
  // Everything the channel serves is under /w/:token/mcp; the run is pinned from the token and authority is stripped.
162
163
  app.use('/w/:token/mcp', (req, res, next) => {
164
+ markActivity('mcp:worker-request');
163
165
  const runId = tokenToRun.get(String(req.params.token || ''));
164
166
  if (!runId) return res.status(404).json({ jsonrpc: '2.0', error: { code: -32001, message: 'Unknown worker channel' }, id: null });
165
167
  req.headers['x-synabun-terminal'] = runId; // the worker's identity is its own run, never what it claims
@@ -88,6 +88,11 @@ export function resumeRefusal(entry, { now = Date.now(), workLeftMs = Infinity,
88
88
  return null;
89
89
  }
90
90
 
91
+ /** The CLI refused to resume because it saved no conversation under that session id (a run cut off very early). */
92
+ export function isMissingConversationError(error) {
93
+ return /No conversation found with session ID/i.test(String(error?.message || error || ''));
94
+ }
95
+
91
96
  /** Whether `path` is `root` or inside it (both resolved; a missing path is compared as written). */
92
97
  export function isInside(path, root) {
93
98
  if (!path || !root) return false;
@@ -0,0 +1,86 @@
1
+ // Who asked a run to stop, and whether that request may end a run a server restart suspended.
2
+ // The request guards identify the caller. The page may describe its control, but neither its JSON nor a legacy reason
3
+ // string identifies a person: `reason: 'user'` is recorded only for a control a person operates (personAskedToStop).
4
+
5
+ const PERSON_PAGE_ACTIONS = new Set(['stop', 'tab_close']);
6
+
7
+ export function pageStopProvenance(action, verified) {
8
+ return {
9
+ actor: verified ? 'page' : 'unknown',
10
+ action: ['stop', 'tab_close', 'tray_auto_close'].includes(action) ? action : 'unknown',
11
+ };
12
+ }
13
+
14
+ export function assistantStopProvenance(caller, action) {
15
+ if (caller.credentialed) {
16
+ return { actor: 'assistant', action: 'agent_stop', assistantSessionId: caller.assistantSessionId };
17
+ }
18
+ return pageStopProvenance(action, caller.verifiedPage);
19
+ }
20
+
21
+ // What SynaBun itself ends a run for. A reason that is not here names no caller: it is recorded as unknown.
22
+ const SYSTEM_STOPS = Object.freeze({
23
+ server_restart: ['server', 'shutdown'],
24
+ server_shutdown: ['server', 'shutdown'],
25
+ resume_failed: ['server', 'resume_failed'],
26
+ state_removed: ['server', 'state_file'],
27
+ state_inactive: ['server', 'state_file'],
28
+ time_cap: ['limit', 'time_cap'],
29
+ max_turns: ['limit', 'max_turns'],
30
+ idle_timeout: ['limit', 'idle_timeout'],
31
+ budget_cap: ['budget', 'budget_cap'],
32
+ session_budget_cap: ['budget', 'session_budget_cap'],
33
+ budget_share: ['budget', 'budget_share'],
34
+ budget_unpriced: ['budget', 'budget_unpriced'],
35
+ assistant: ['assistant', 'stop'],
36
+ complete: ['assistant', 'agent_complete'],
37
+ remote_policy: ['policy', 'remote_policy'],
38
+ desktop_stop: ['desktop', 'stop_control'],
39
+ team_replaced: ['team', 'replace'],
40
+ team_discarded: ['team', 'discard'],
41
+ cancelled: ['system', 'cancelled'],
42
+ whatsapp_service: ['whatsapp_service', 'stop'],
43
+ });
44
+
45
+ /** The actor and action of a stop SynaBun made for `reason`, or null when the reason names no caller. */
46
+ export function systemStopProvenance(reason) {
47
+ const known = Object.hasOwn(SYSTEM_STOPS, String(reason)) ? SYSTEM_STOPS[reason] : null;
48
+ return known ? { actor: known[0], action: known[1] } : null;
49
+ }
50
+
51
+ /** What is recorded for a stop: the proven caller, else what `reason` says, else unknown; always with its time. */
52
+ export function stampStopProvenance(reason, provenance, at) {
53
+ const base = provenance || systemStopProvenance(reason) || { actor: 'unknown', action: String(reason || 'unknown').slice(0, 64) };
54
+ return { ...base, at: base.at || at };
55
+ }
56
+
57
+ /** A person operated the control: the owner's page (Stop, a tab's X) or the owner's phone. */
58
+ export function personAskedToStop(provenance) {
59
+ if (provenance?.actor === 'whatsapp_user') return provenance.action === 'stop';
60
+ return provenance?.actor === 'page' && PERSON_PAGE_ACTIONS.has(provenance.action);
61
+ }
62
+
63
+ /** The reason a stop through a page or by a run itself is recorded under. */
64
+ export function callerStopReason(provenance) {
65
+ if (personAskedToStop(provenance)) return 'user';
66
+ if (provenance?.actor === 'automation' && provenance.action === 'self_stop') return 'self_stop';
67
+ if (provenance?.action === 'tray_auto_close') return 'tray_auto_close';
68
+ return 'unknown';
69
+ }
70
+
71
+ /**
72
+ * Whether this request may end a run suspended for a server restart. That run has no process, so it cannot stop
73
+ * itself: an exit hook of its old CLI, an unidentified caller, a page that names no control, the tray's timer and the
74
+ * shutdown itself never end it. A person, the Assistant and a limit or policy of SynaBun's do.
75
+ */
76
+ export function mayEndSuspendedRun(provenance) {
77
+ if (!provenance) return false;
78
+ if (['unknown', 'automation', 'server'].includes(provenance.actor)) return false;
79
+ if (provenance.actor === 'page') return PERSON_PAGE_ACTIONS.has(provenance.action);
80
+ return true;
81
+ }
82
+
83
+ /** The reason a run ended by a server shutdown is recorded under, whatever the shutdown was called. */
84
+ export function shutdownStopReason(reason) {
85
+ return reason === 'restart' || reason === 'server_restart' ? 'server_restart' : 'server_shutdown';
86
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "neural-memory-interface",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "neural-memory-interface",
9
- "version": "2.4.1",
9
+ "version": "2.4.3",
10
10
  "hasInstallScript": true,
11
11
  "license": "Apache-2.0",
12
12
  "dependencies": {
@@ -2966,9 +2966,9 @@
2966
2966
  "license": "MIT"
2967
2967
  },
2968
2968
  "node_modules/body-parser": {
2969
- "version": "1.20.8",
2970
- "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.8.tgz",
2971
- "integrity": "sha512-JNcyFQ64OiijEkPzUBTCe+hyPXUD/3LEldGQ6iF5LR1w00mx9o7xtDWHXBY2iItjdCFGoilOLNQbH943ut7pHA==",
2969
+ "version": "1.20.9",
2970
+ "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.9.tgz",
2971
+ "integrity": "sha512-FISIQxV5u91Y9gvuFq3q/tA/qTqLJn3AhRcEvyozyhJTh5OBFFtv827AdHU7Rbyct4r+Ba1/99oFa1Y3yuFsdw==",
2972
2972
  "license": "MIT",
2973
2973
  "dependencies": {
2974
2974
  "bytes": "~3.1.2",