dodo-mcp 1.0.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 (447) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +425 -0
  3. package/dist/auth/adapter.js +43 -0
  4. package/dist/auth/adapter.js.map +1 -0
  5. package/dist/auth/clientDeletion.js +45 -0
  6. package/dist/auth/clientDeletion.js.map +1 -0
  7. package/dist/auth/clients.js +55 -0
  8. package/dist/auth/clients.js.map +1 -0
  9. package/dist/auth/constants.js +10 -0
  10. package/dist/auth/constants.js.map +1 -0
  11. package/dist/auth/interactions.js +184 -0
  12. package/dist/auth/interactions.js.map +1 -0
  13. package/dist/auth/keys.js +56 -0
  14. package/dist/auth/keys.js.map +1 -0
  15. package/dist/auth/provider.js +131 -0
  16. package/dist/auth/provider.js.map +1 -0
  17. package/dist/auth/verifier.js +74 -0
  18. package/dist/auth/verifier.js.map +1 -0
  19. package/dist/cli/kill.js +124 -0
  20. package/dist/cli/kill.js.map +1 -0
  21. package/dist/cli/main.js +1393 -0
  22. package/dist/cli/main.js.map +1 -0
  23. package/dist/cli/menu.js +127 -0
  24. package/dist/cli/menu.js.map +1 -0
  25. package/dist/cli/terminal.js +30 -0
  26. package/dist/cli/terminal.js.map +1 -0
  27. package/dist/config/globalConfig.js +144 -0
  28. package/dist/config/globalConfig.js.map +1 -0
  29. package/dist/config/limits.js +42 -0
  30. package/dist/config/limits.js.map +1 -0
  31. package/dist/config/paths.js +94 -0
  32. package/dist/config/paths.js.map +1 -0
  33. package/dist/config/projectConfig.js +63 -0
  34. package/dist/config/projectConfig.js.map +1 -0
  35. package/dist/config/stateImport.js +306 -0
  36. package/dist/config/stateImport.js.map +1 -0
  37. package/dist/config/tunnelConfig.js +23 -0
  38. package/dist/config/tunnelConfig.js.map +1 -0
  39. package/dist/errors.js +82 -0
  40. package/dist/errors.js.map +1 -0
  41. package/dist/evaluation/contracts.js +86 -0
  42. package/dist/evaluation/contracts.js.map +1 -0
  43. package/dist/evaluation/dodoBench.js +69 -0
  44. package/dist/evaluation/dodoBench.js.map +1 -0
  45. package/dist/index.js +26 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/ipc/authentication.js +117 -0
  48. package/dist/ipc/authentication.js.map +1 -0
  49. package/dist/ipc/client.js +86 -0
  50. package/dist/ipc/client.js.map +1 -0
  51. package/dist/ipc/installationClient.js +83 -0
  52. package/dist/ipc/installationClient.js.map +1 -0
  53. package/dist/ipc/ownerControl.js +46 -0
  54. package/dist/ipc/ownerControl.js.map +1 -0
  55. package/dist/ipc/protocol.js +2 -0
  56. package/dist/ipc/protocol.js.map +1 -0
  57. package/dist/ipc/server.js +108 -0
  58. package/dist/ipc/server.js.map +1 -0
  59. package/dist/platform/execResolve.js +64 -0
  60. package/dist/platform/execResolve.js.map +1 -0
  61. package/dist/platform/fileIdentity.js +26 -0
  62. package/dist/platform/fileIdentity.js.map +1 -0
  63. package/dist/platform/fsRetry.js +22 -0
  64. package/dist/platform/fsRetry.js.map +1 -0
  65. package/dist/platform/pathPolicy.js +29 -0
  66. package/dist/platform/pathPolicy.js.map +1 -0
  67. package/dist/platform/privateFs.js +116 -0
  68. package/dist/platform/privateFs.js.map +1 -0
  69. package/dist/platform/processTree.js +31 -0
  70. package/dist/platform/processTree.js.map +1 -0
  71. package/dist/platform/shell.js +74 -0
  72. package/dist/platform/shell.js.map +1 -0
  73. package/dist/platform/speech.js +94 -0
  74. package/dist/platform/speech.js.map +1 -0
  75. package/dist/platform/system.js +28 -0
  76. package/dist/platform/system.js.map +1 -0
  77. package/dist/platform/windowsSandbox.js +129 -0
  78. package/dist/platform/windowsSandbox.js.map +1 -0
  79. package/dist/projects/federation.js +312 -0
  80. package/dist/projects/federation.js.map +1 -0
  81. package/dist/projects/registry.js +291 -0
  82. package/dist/projects/registry.js.map +1 -0
  83. package/dist/security/accessMode.js +19 -0
  84. package/dist/security/accessMode.js.map +1 -0
  85. package/dist/security/approvals.js +56 -0
  86. package/dist/security/approvals.js.map +1 -0
  87. package/dist/security/env.js +57 -0
  88. package/dist/security/env.js.map +1 -0
  89. package/dist/security/mutationQueue.js +78 -0
  90. package/dist/security/mutationQueue.js.map +1 -0
  91. package/dist/security/policy.js +22 -0
  92. package/dist/security/policy.js.map +1 -0
  93. package/dist/security/projectAuthority.js +22 -0
  94. package/dist/security/projectAuthority.js.map +1 -0
  95. package/dist/security/redact.js +30 -0
  96. package/dist/security/redact.js.map +1 -0
  97. package/dist/server/aiAdmin.js +201 -0
  98. package/dist/server/aiAdmin.js.map +1 -0
  99. package/dist/server/appServer.js +461 -0
  100. package/dist/server/appServer.js.map +1 -0
  101. package/dist/server/bootstrap.js +185 -0
  102. package/dist/server/bootstrap.js.map +1 -0
  103. package/dist/server/configUi/app.css +347 -0
  104. package/dist/server/configUi/app.js +958 -0
  105. package/dist/server/configUi/index.html +379 -0
  106. package/dist/server/configUi/ui/alerts.js +92 -0
  107. package/dist/server/configUi/ui/dom.js +19 -0
  108. package/dist/server/configUi/ui/tooltips.js +115 -0
  109. package/dist/server/configUi/vendor/VERSION.txt +1 -0
  110. package/dist/server/configUi/vendor/sweetalert2.min.css +1 -0
  111. package/dist/server/configUi/vendor/sweetalert2.min.js +5 -0
  112. package/dist/server/configUi/workbench.css +62 -0
  113. package/dist/server/configUi/workbench.js +394 -0
  114. package/dist/server/installationRuntime.js +155 -0
  115. package/dist/server/installationRuntime.js.map +1 -0
  116. package/dist/server/instructions.js +17 -0
  117. package/dist/server/instructions.js.map +1 -0
  118. package/dist/server/ipcDispatch.js +225 -0
  119. package/dist/server/ipcDispatch.js.map +1 -0
  120. package/dist/server/localConfig.js +561 -0
  121. package/dist/server/localConfig.js.map +1 -0
  122. package/dist/server/optionalServices.js +30 -0
  123. package/dist/server/optionalServices.js.map +1 -0
  124. package/dist/server/projectLease.js +46 -0
  125. package/dist/server/projectLease.js.map +1 -0
  126. package/dist/server/stdioServer.js +75 -0
  127. package/dist/server/stdioServer.js.map +1 -0
  128. package/dist/server/version.js +13 -0
  129. package/dist/server/version.js.map +1 -0
  130. package/dist/server/workspaceHost.js +194 -0
  131. package/dist/server/workspaceHost.js.map +1 -0
  132. package/dist/services/agent/agentService.js +598 -0
  133. package/dist/services/agent/agentService.js.map +1 -0
  134. package/dist/services/agent/contracts.js +102 -0
  135. package/dist/services/agent/contracts.js.map +1 -0
  136. package/dist/services/ai/adapters.js +287 -0
  137. package/dist/services/ai/adapters.js.map +1 -0
  138. package/dist/services/ai/contracts.js +39 -0
  139. package/dist/services/ai/contracts.js.map +1 -0
  140. package/dist/services/ai/credentials.js +77 -0
  141. package/dist/services/ai/credentials.js.map +1 -0
  142. package/dist/services/ai/network.js +113 -0
  143. package/dist/services/ai/network.js.map +1 -0
  144. package/dist/services/ai/settings.js +178 -0
  145. package/dist/services/ai/settings.js.map +1 -0
  146. package/dist/services/ai/subagents.js +468 -0
  147. package/dist/services/ai/subagents.js.map +1 -0
  148. package/dist/services/assistance/analysis.js +352 -0
  149. package/dist/services/assistance/analysis.js.map +1 -0
  150. package/dist/services/assistance/contracts.js +54 -0
  151. package/dist/services/assistance/contracts.js.map +1 -0
  152. package/dist/services/assistance/verification.js +274 -0
  153. package/dist/services/assistance/verification.js.map +1 -0
  154. package/dist/services/brain/brainParser.js +97 -0
  155. package/dist/services/brain/brainParser.js.map +1 -0
  156. package/dist/services/brain/brainService.js +733 -0
  157. package/dist/services/brain/brainService.js.map +1 -0
  158. package/dist/services/brain/brainWorker.js +212 -0
  159. package/dist/services/brain/brainWorker.js.map +1 -0
  160. package/dist/services/brain/contracts.js +154 -0
  161. package/dist/services/brain/contracts.js.map +1 -0
  162. package/dist/services/brain/protocol.js +2 -0
  163. package/dist/services/brain/protocol.js.map +1 -0
  164. package/dist/services/changes/applier.js +544 -0
  165. package/dist/services/changes/applier.js.map +1 -0
  166. package/dist/services/changes/contentBudget.js +11 -0
  167. package/dist/services/changes/contentBudget.js.map +1 -0
  168. package/dist/services/changes/planner.js +284 -0
  169. package/dist/services/changes/planner.js.map +1 -0
  170. package/dist/services/changes/types.js +3 -0
  171. package/dist/services/changes/types.js.map +1 -0
  172. package/dist/services/context/contextEngine.js +746 -0
  173. package/dist/services/context/contextEngine.js.map +1 -0
  174. package/dist/services/context/contracts.js +88 -0
  175. package/dist/services/context/contracts.js.map +1 -0
  176. package/dist/services/desktop/desktopPolicy.js +76 -0
  177. package/dist/services/desktop/desktopPolicy.js.map +1 -0
  178. package/dist/services/desktop/desktopService.js +130 -0
  179. package/dist/services/desktop/desktopService.js.map +1 -0
  180. package/dist/services/desktop/nativeBackend.js +174 -0
  181. package/dist/services/desktop/nativeBackend.js.map +1 -0
  182. package/dist/services/desktop/protocol.js +32 -0
  183. package/dist/services/desktop/protocol.js.map +1 -0
  184. package/dist/services/files/readService.js +136 -0
  185. package/dist/services/files/readService.js.map +1 -0
  186. package/dist/services/git/gitService.js +369 -0
  187. package/dist/services/git/gitService.js.map +1 -0
  188. package/dist/services/intelligence/intelService.js +136 -0
  189. package/dist/services/intelligence/intelService.js.map +1 -0
  190. package/dist/services/intelligence/protocol.js +2 -0
  191. package/dist/services/intelligence/protocol.js.map +1 -0
  192. package/dist/services/intelligence/tsWorker.js +419 -0
  193. package/dist/services/intelligence/tsWorker.js.map +1 -0
  194. package/dist/services/jobs/commandInput.js +34 -0
  195. package/dist/services/jobs/commandInput.js.map +1 -0
  196. package/dist/services/jobs/jobManager.js +398 -0
  197. package/dist/services/jobs/jobManager.js.map +1 -0
  198. package/dist/services/jobs/sandbox.js +156 -0
  199. package/dist/services/jobs/sandbox.js.map +1 -0
  200. package/dist/services/jobs/sandboxWiring.js +37 -0
  201. package/dist/services/jobs/sandboxWiring.js.map +1 -0
  202. package/dist/services/jobs/spool.js +112 -0
  203. package/dist/services/jobs/spool.js.map +1 -0
  204. package/dist/services/jobs/windowsSandboxChild.js +24 -0
  205. package/dist/services/jobs/windowsSandboxChild.js.map +1 -0
  206. package/dist/services/jobs/windowsSandboxWorker.js +155 -0
  207. package/dist/services/jobs/windowsSandboxWorker.js.map +1 -0
  208. package/dist/services/lsp/documentUri.js +16 -0
  209. package/dist/services/lsp/documentUri.js.map +1 -0
  210. package/dist/services/lsp/jsonrpc.js +382 -0
  211. package/dist/services/lsp/jsonrpc.js.map +1 -0
  212. package/dist/services/lsp/lspService.js +1051 -0
  213. package/dist/services/lsp/lspService.js.map +1 -0
  214. package/dist/services/memory/contracts.js +94 -0
  215. package/dist/services/memory/contracts.js.map +1 -0
  216. package/dist/services/memory/memoryService.js +683 -0
  217. package/dist/services/memory/memoryService.js.map +1 -0
  218. package/dist/services/multimodal/browserService.js +407 -0
  219. package/dist/services/multimodal/browserService.js.map +1 -0
  220. package/dist/services/multimodal/byteRange.js +31 -0
  221. package/dist/services/multimodal/byteRange.js.map +1 -0
  222. package/dist/services/multimodal/contracts.js +59 -0
  223. package/dist/services/multimodal/contracts.js.map +1 -0
  224. package/dist/services/multimodal/gameService.js +95 -0
  225. package/dist/services/multimodal/gameService.js.map +1 -0
  226. package/dist/services/multimodal/images.js +107 -0
  227. package/dist/services/multimodal/images.js.map +1 -0
  228. package/dist/services/multimodal/mediaService.js +279 -0
  229. package/dist/services/multimodal/mediaService.js.map +1 -0
  230. package/dist/services/multimodal/mediaWorker.js +143 -0
  231. package/dist/services/multimodal/mediaWorker.js.map +1 -0
  232. package/dist/services/multimodal/multimodalService.js +51 -0
  233. package/dist/services/multimodal/multimodalService.js.map +1 -0
  234. package/dist/services/multimodal/network.js +69 -0
  235. package/dist/services/multimodal/network.js.map +1 -0
  236. package/dist/services/multimodal/operations.js +40 -0
  237. package/dist/services/multimodal/operations.js.map +1 -0
  238. package/dist/services/multimodal/storage.js +160 -0
  239. package/dist/services/multimodal/storage.js.map +1 -0
  240. package/dist/services/multimodal/workflowService.js +179 -0
  241. package/dist/services/multimodal/workflowService.js.map +1 -0
  242. package/dist/services/overview.js +284 -0
  243. package/dist/services/overview.js.map +1 -0
  244. package/dist/services/resources/casStore.js +304 -0
  245. package/dist/services/resources/casStore.js.map +1 -0
  246. package/dist/services/resources/contracts.js +75 -0
  247. package/dist/services/resources/contracts.js.map +1 -0
  248. package/dist/services/resources/mime.js +77 -0
  249. package/dist/services/resources/mime.js.map +1 -0
  250. package/dist/services/resources/providerRegistry.js +22 -0
  251. package/dist/services/resources/providerRegistry.js.map +1 -0
  252. package/dist/services/resources/providers.js +120 -0
  253. package/dist/services/resources/providers.js.map +1 -0
  254. package/dist/services/resources/resourceService.js +282 -0
  255. package/dist/services/resources/resourceService.js.map +1 -0
  256. package/dist/services/runtime/contracts.js +65 -0
  257. package/dist/services/runtime/contracts.js.map +1 -0
  258. package/dist/services/runtime/runtimeService.js +364 -0
  259. package/dist/services/runtime/runtimeService.js.map +1 -0
  260. package/dist/services/schedules/scheduleService.js +198 -0
  261. package/dist/services/schedules/scheduleService.js.map +1 -0
  262. package/dist/services/search/searchService.js +434 -0
  263. package/dist/services/search/searchService.js.map +1 -0
  264. package/dist/services/search/searchWorker.js +58 -0
  265. package/dist/services/search/searchWorker.js.map +1 -0
  266. package/dist/setup/componentProbes.js +259 -0
  267. package/dist/setup/componentProbes.js.map +1 -0
  268. package/dist/setup/download.js +139 -0
  269. package/dist/setup/download.js.map +1 -0
  270. package/dist/setup/managedTools.js +118 -0
  271. package/dist/setup/managedTools.js.map +1 -0
  272. package/dist/setup/sandboxProbe.js +172 -0
  273. package/dist/setup/sandboxProbe.js.map +1 -0
  274. package/dist/setup/setup.js +522 -0
  275. package/dist/setup/setup.js.map +1 -0
  276. package/dist/setup/windowsChromiumAcl.js +56 -0
  277. package/dist/setup/windowsChromiumAcl.js.map +1 -0
  278. package/dist/setup/windowsSandboxInstall.js +94 -0
  279. package/dist/setup/windowsSandboxInstall.js.map +1 -0
  280. package/dist/setup/windowsSpeechInstall.js +86 -0
  281. package/dist/setup/windowsSpeechInstall.js.map +1 -0
  282. package/dist/store/db.js +711 -0
  283. package/dist/store/db.js.map +1 -0
  284. package/dist/store/scopeEncoding.js +15 -0
  285. package/dist/store/scopeEncoding.js.map +1 -0
  286. package/dist/store/store.js +467 -0
  287. package/dist/store/store.js.map +1 -0
  288. package/dist/tools/agentRuntimeTools.js +216 -0
  289. package/dist/tools/agentRuntimeTools.js.map +1 -0
  290. package/dist/tools/agentTools.js +317 -0
  291. package/dist/tools/agentTools.js.map +1 -0
  292. package/dist/tools/assistanceTools.js +126 -0
  293. package/dist/tools/assistanceTools.js.map +1 -0
  294. package/dist/tools/brainTools.js +130 -0
  295. package/dist/tools/brainTools.js.map +1 -0
  296. package/dist/tools/catalog.js +30 -0
  297. package/dist/tools/catalog.js.map +1 -0
  298. package/dist/tools/changeTools.js +188 -0
  299. package/dist/tools/changeTools.js.map +1 -0
  300. package/dist/tools/context.js +243 -0
  301. package/dist/tools/context.js.map +1 -0
  302. package/dist/tools/contextTools.js +57 -0
  303. package/dist/tools/contextTools.js.map +1 -0
  304. package/dist/tools/coreCatalog.js +82 -0
  305. package/dist/tools/coreCatalog.js.map +1 -0
  306. package/dist/tools/desktopTools.js +41 -0
  307. package/dist/tools/desktopTools.js.map +1 -0
  308. package/dist/tools/directTools.js +273 -0
  309. package/dist/tools/directTools.js.map +1 -0
  310. package/dist/tools/envelope.js +71 -0
  311. package/dist/tools/envelope.js.map +1 -0
  312. package/dist/tools/extraTools.js +298 -0
  313. package/dist/tools/extraTools.js.map +1 -0
  314. package/dist/tools/gitTools.js +93 -0
  315. package/dist/tools/gitTools.js.map +1 -0
  316. package/dist/tools/jobTools.js +454 -0
  317. package/dist/tools/jobTools.js.map +1 -0
  318. package/dist/tools/memoryTools.js +102 -0
  319. package/dist/tools/memoryTools.js.map +1 -0
  320. package/dist/tools/metaTools.js +153 -0
  321. package/dist/tools/metaTools.js.map +1 -0
  322. package/dist/tools/multimodalTools.js +262 -0
  323. package/dist/tools/multimodalTools.js.map +1 -0
  324. package/dist/tools/projectTools.js +261 -0
  325. package/dist/tools/projectTools.js.map +1 -0
  326. package/dist/tools/resourceTools.js +81 -0
  327. package/dist/tools/resourceTools.js.map +1 -0
  328. package/dist/tools/runtimeTools.js +137 -0
  329. package/dist/tools/runtimeTools.js.map +1 -0
  330. package/dist/tools/scheduleTools.js +10 -0
  331. package/dist/tools/scheduleTools.js.map +1 -0
  332. package/dist/tools/semanticTools.js +141 -0
  333. package/dist/tools/semanticTools.js.map +1 -0
  334. package/dist/tools/subagentTools.js +32 -0
  335. package/dist/tools/subagentTools.js.map +1 -0
  336. package/dist/tools/surface.js +644 -0
  337. package/dist/tools/surface.js.map +1 -0
  338. package/dist/tunnel/control.js +113 -0
  339. package/dist/tunnel/control.js.map +1 -0
  340. package/dist/tunnel/credentials.js +392 -0
  341. package/dist/tunnel/credentials.js.map +1 -0
  342. package/dist/tunnel/log.js +84 -0
  343. package/dist/tunnel/log.js.map +1 -0
  344. package/dist/tunnel/runtime.js +55 -0
  345. package/dist/tunnel/runtime.js.map +1 -0
  346. package/dist/tunnel/supervisor.js +280 -0
  347. package/dist/tunnel/supervisor.js.map +1 -0
  348. package/dist/util/bytes.js +53 -0
  349. package/dist/util/bytes.js.map +1 -0
  350. package/dist/util/hash.js +53 -0
  351. package/dist/util/hash.js.map +1 -0
  352. package/dist/workspace/fs.js +305 -0
  353. package/dist/workspace/fs.js.map +1 -0
  354. package/dist/workspace/identity.js +17 -0
  355. package/dist/workspace/identity.js.map +1 -0
  356. package/dist/workspace/ignores.js +173 -0
  357. package/dist/workspace/ignores.js.map +1 -0
  358. package/dist/workspace/root.js +59 -0
  359. package/dist/workspace/root.js.map +1 -0
  360. package/docs/AGENT_RUNTIME.md +154 -0
  361. package/docs/AI_PROVIDERS.md +110 -0
  362. package/docs/ARCHITECTURE.md +331 -0
  363. package/docs/ASSISTANCE.md +31 -0
  364. package/docs/AUTH.md +59 -0
  365. package/docs/BRAIN.md +92 -0
  366. package/docs/COMPATIBILITY.md +92 -0
  367. package/docs/CONFIRMATION.md +13 -0
  368. package/docs/CONTEXT.md +87 -0
  369. package/docs/DESKTOP.md +35 -0
  370. package/docs/EVALUATION.md +86 -0
  371. package/docs/LARGE_INPUTS.md +21 -0
  372. package/docs/LSP.md +21 -0
  373. package/docs/MANUAL_ACCEPTANCE.md +283 -0
  374. package/docs/MEMORY.md +128 -0
  375. package/docs/MULTIMODAL.md +32 -0
  376. package/docs/PROJECTS.md +146 -0
  377. package/docs/RELEASE_1.0.0.md +111 -0
  378. package/docs/RELEASE_NOTES.md +92 -0
  379. package/docs/RESOURCES.md +83 -0
  380. package/docs/RUNTIME.md +125 -0
  381. package/docs/SCHEDULES.md +23 -0
  382. package/docs/SECURITY.md +250 -0
  383. package/docs/TEST_REPORT.md +312 -0
  384. package/docs/TUNNEL.md +86 -0
  385. package/docs/WEB_CLIENTS.md +43 -0
  386. package/docs/WINDOWS.md +79 -0
  387. package/docs/adr/001-one-process-one-workspace.md +22 -0
  388. package/docs/adr/002-external-tunnel.md +19 -0
  389. package/docs/adr/003-sdk-v2-legacy-stateless.md +20 -0
  390. package/docs/adr/004-embedded-oauth-provider.md +19 -0
  391. package/docs/adr/005-static-client-baseline.md +19 -0
  392. package/docs/adr/006-guarded-fs-explicit-exec.md +16 -0
  393. package/docs/adr/007-preview-hash-journal.md +18 -0
  394. package/docs/adr/008-ts-js-semantics-first.md +17 -0
  395. package/docs/adr/009-jobs-polling.md +18 -0
  396. package/docs/adr/010-sqlite-better-sqlite3.md +18 -0
  397. package/docs/adr/011-env-example-secure-default.md +19 -0
  398. package/docs/adr/012-workspace-scope-grant.md +24 -0
  399. package/docs/adr/013-loopback-proxy-trust.md +18 -0
  400. package/docs/adr/014-direct-coding-tier.md +48 -0
  401. package/docs/adr/015-coding-agent-parity.md +56 -0
  402. package/docs/adr/016-oidc-openid-consent.md +15 -0
  403. package/docs/adr/017-installation-identity-local-config.md +44 -0
  404. package/docs/adr/018-access-scope-encoding.md +11 -0
  405. package/docs/adr/019-runtime-workspace-switch.md +59 -0
  406. package/docs/adr/020-desktop-access.md +50 -0
  407. package/docs/adr/021-persistent-desktop-consent.md +39 -0
  408. package/docs/adr/022-owner-kill-preserves-login.md +30 -0
  409. package/docs/adr/023-large-coding-inputs.md +49 -0
  410. package/docs/adr/024-usage-rounds-and-schedules.md +72 -0
  411. package/docs/adr/025-owner-chat-whitelist.md +53 -0
  412. package/docs/adr/026-remove-conversation-confirmation.md +35 -0
  413. package/docs/adr/027-workspace-client-list.md +20 -0
  414. package/docs/adr/028-owner-client-deletion.md +25 -0
  415. package/docs/adr/029-compact-tool-surface.md +121 -0
  416. package/docs/adr/030-windows-native-candidate.md +71 -0
  417. package/docs/adr/031-owner-selected-tunnel-supervision.md +13 -0
  418. package/docs/adr/032-owner-project-registry.md +43 -0
  419. package/docs/adr/033-read-only-project-federation.md +61 -0
  420. package/docs/adr/034-universal-resource-cas.md +60 -0
  421. package/docs/adr/035-project-brain-incremental-index.md +51 -0
  422. package/docs/adr/036-context-engine-evidence.md +53 -0
  423. package/docs/adr/037-owner-reviewed-memory.md +46 -0
  424. package/docs/adr/038-runtime-intelligence.md +46 -0
  425. package/docs/adr/039-advanced-agent-runtime.md +57 -0
  426. package/docs/adr/040-dodobench-release-gate.md +43 -0
  427. package/docs/adr/041-local-macos-docker-linux-gates.md +32 -0
  428. package/docs/adr/042-project-directory-generation-identity.md +36 -0
  429. package/docs/adr/043-trusted-self-hosted-platform-gates.md +38 -0
  430. package/docs/adr/044-global-launcher-and-cli-menu.md +43 -0
  431. package/docs/adr/045-ai-providers-multiproject.md +56 -0
  432. package/docs/adr/046-personal-access-mode.md +32 -0
  433. package/docs/adr/README.md +64 -0
  434. package/examples/.dodo.json.example +20 -0
  435. package/examples/cloudflared.yml +23 -0
  436. package/examples/reverse-proxy-fixture.mjs +37 -0
  437. package/native/desktop-linux.py +387 -0
  438. package/native/desktop-windows.cs +180 -0
  439. package/native/desktop.swift +212 -0
  440. package/package.json +145 -0
  441. package/schemas/global-config.schema.json +497 -0
  442. package/schemas/project-config.schema.json +75 -0
  443. package/schemas/tools.compact.json +3236 -0
  444. package/schemas/tools.hybrid.json +8194 -0
  445. package/schemas/tools.json +34518 -0
  446. package/scripts/guard-publish.mjs +12 -0
  447. package/scripts/setup-multimodal.mjs +70 -0
@@ -0,0 +1,59 @@
1
+ import { z } from 'zod';
2
+ import { DesktopActionSchema } from '../desktop/protocol.js';
3
+ export const Id = z.string().regex(/^[a-z]+_[a-z0-9]{8,64}$/).max(100);
4
+ export const Path = z.string().min(1).max(1024);
5
+ export const Hash = z.string().regex(/^sha256:[a-f0-9]{64}$/);
6
+ export const Key = z.string().min(8).max(128);
7
+ export const Crop = z.object({ left: z.number().int().min(0).max(20000), top: z.number().int().min(0).max(20000), width: z.number().int().min(1).max(20000), height: z.number().int().min(1).max(20000) }).strict();
8
+ export const AssetInfo = z.object({ assetId: Id, kind: z.enum(['image', 'audio', 'transcript']), mimeType: z.string(), bytes: z.number().int().nonnegative(), sha256: Hash, createdAt: z.number(), expiresAt: z.number(), timeSec: z.number().nonnegative().optional(), endSec: z.number().nonnegative().optional() });
9
+ export const Segment = z.object({ startSec: z.number().nonnegative(), endSec: z.number().nonnegative(), text: z.string().max(4000) }).strict().refine(s => s.endSec >= s.startSec, 'end must follow start');
10
+ export const Transcript = z.object({ source: z.enum(['whisper.cpp', 'sidecar_subtitles']), language: z.string(), mediaId: Id, startSec: z.number(), endSec: z.number(), segments: z.array(Segment).max(10000), truncated: z.boolean() });
11
+ export const BrowserAction = z.discriminatedUnion('kind', [
12
+ z.object({ kind: z.literal('click'), selector: z.string().min(1).max(500) }).strict(),
13
+ z.object({ kind: z.literal('fill'), selector: z.string().min(1).max(500), text: z.string().max(4000) }).strict(),
14
+ z.object({ kind: z.literal('press'), selector: z.string().min(1).max(500), key: z.enum(['Enter', 'Tab', 'Escape', 'Space', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Backspace']) }).strict(),
15
+ z.object({ kind: z.literal('select'), selector: z.string().min(1).max(500), value: z.string().max(500) }).strict(),
16
+ z.object({ kind: z.literal('scroll'), deltaY: z.number().int().min(-2000).max(2000) }).strict(),
17
+ z.object({ kind: z.literal('media'), selector: z.string().min(1).max(500), control: z.enum(['play', 'pause', 'seek', 'mute']), timeSec: z.number().min(0).max(86400).optional() }).strict(),
18
+ z.object({ kind: z.literal('navigate'), url: z.string().min(1).max(2048) }).strict(),
19
+ ]);
20
+ export const GameAction = z.discriminatedUnion('kind', [
21
+ z.object({ kind: z.literal('wait'), durationMs: z.number().int().min(0).max(2000).default(200) }).strict(),
22
+ z.object({ kind: z.literal('keys'), keys: z.array(z.string().regex(/^(?:[a-z0-9]|ArrowUp|ArrowDown|ArrowLeft|ArrowRight|Space|Enter|Escape)$/)).min(1).max(4), holdMs: z.number().int().min(0).max(500).default(0) }).strict(),
23
+ z.object({ kind: z.literal('click'), x: z.number().min(0).max(2000), y: z.number().min(0).max(2000) }).strict(),
24
+ ]);
25
+ export const WorkflowStep = z.object({
26
+ instruction: z.string().min(1).max(1000),
27
+ expectedBefore: z.string().min(1).max(300), expectedAfter: z.string().max(300).default(''),
28
+ action: z.discriminatedUnion('target', [
29
+ z.object({ target: z.literal('browser'), action: BrowserAction }).strict(),
30
+ z.object({ target: z.literal('desktop'), action: DesktopActionSchema }).strict(),
31
+ z.object({ target: z.literal('manual') }).strict(),
32
+ ]),
33
+ evidence: z.array(z.object({ source: z.enum(['observation', 'media', 'user_note']), reference: z.string().max(150), timeSec: z.number().nonnegative().optional() }).strict()).max(5).default([]),
34
+ }).strict();
35
+ export const Workflow = z.object({ name: z.string().min(1).max(100), goal: z.string().min(1).max(1500), tags: z.array(z.string().min(1).max(40)).max(10).default([]), steps: z.array(WorkflowStep).min(1).max(30) }).strict();
36
+ export const WorkflowRecord = Workflow.extend({ workflowId: Id, revision: Hash, createdAt: z.number(), updatedAt: z.number(), provenance: z.literal('client_authored_untrusted_steps_not_permissions') });
37
+ export const WorkerSpec = z.object({
38
+ operation: z.enum(['probe', 'frames', 'audio', 'transcribe', 'speak']),
39
+ input: z.string(), directory: z.string(), ffmpeg: z.string(), ffprobe: z.string(),
40
+ whisper: z.string().optional(), model: z.string().optional(), say: z.string().optional(),
41
+ speechProgram: z.string().optional(), speechKind: z.enum(['macos-say', 'windows-sapi', 'espeak-ng']).optional(),
42
+ startSec: z.number().min(0).max(86400), durationSec: z.number().positive().max(600),
43
+ times: z.array(z.number().min(0).max(86400)).max(8), maxEdge: z.number().int().min(320).max(1600),
44
+ language: z.string().regex(/^(auto|[a-z]{2,3})$/), voice: z.string().max(80).optional(),
45
+ }).strict();
46
+ export const WorkerResult = z.object({
47
+ operation: WorkerSpec.shape.operation,
48
+ metadata: z.object({ durationSec: z.number().nonnegative().nullable(), streams: z.array(z.object({ type: z.string(), codec: z.string(), width: z.number().optional(), height: z.number().optional() })).max(20) }).optional(),
49
+ files: z.array(z.object({ name: z.string().regex(/^out-[0-9]+\.(?:jpg|wav|json)$/), kind: AssetInfo.shape.kind, mimeType: z.string(), timeSec: z.number().optional(), endSec: z.number().optional() })).max(10),
50
+ notes: z.array(z.string().max(500)).max(10),
51
+ }).strict();
52
+ export const MediaJobResult = z.object({ jobId: z.string(), mediaId: Id.nullable(), operation: WorkerSpec.shape.operation, status: z.string(), exitCode: z.number().nullable(), sandboxed: z.string().nullable(), assets: z.array(AssetInfo), metadata: WorkerResult.shape.metadata, notes: z.array(z.string()), error: z.string().nullable() });
53
+ export const ImageView = z.object({ width: z.number(), height: z.number(), sourceWidth: z.number(), sourceHeight: z.number(), crop: Crop.nullable(), scaleX: z.number(), scaleY: z.number(), sourceOffsetX: z.number(), sourceOffsetY: z.number() });
54
+ export const ScreenFrame = z.object({ observationId: Id, windowId: z.number(), appId: z.string(), pid: z.number(), snapshotId: z.string(), expiresAt: z.number(), capturedAt: z.number(), asset: AssetInfo, view: ImageView,
55
+ difference: z.object({ comparable: z.boolean(), changedFraction: z.number().nullable(), note: z.string() }).nullable(),
56
+ });
57
+ export const PlaybackState = z.object({ selector: z.string(), currentTime: z.number().nonnegative(), duration: z.number().nonnegative().nullable(), paused: z.boolean(), readyState: z.number().int().min(0).max(4), errorCode: z.number().int().nullable() });
58
+ export const BrowserObservation = z.object({ sessionId: Id, observationId: Id, url: z.string(), title: z.string(), text: z.string(), elements: z.array(z.object({ selector: z.string(), tag: z.string(), role: z.string(), name: z.string(), disabled: z.boolean(), type: z.string() })).max(100), truncated: z.boolean(), media: z.array(PlaybackState).max(8).default([]), expiresAt: z.number(), asset: AssetInfo, console: z.array(z.string()).max(30), network: z.array(z.string()).max(30), note: z.string() });
59
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../../src/services/multimodal/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC9C,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,C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E,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC"}
@@ -0,0 +1,95 @@
1
+ import { DodoError } from '../../errors.js';
2
+ import { newId } from '../../util/hash.js';
3
+ import { DesktopActionSchema } from '../desktop/protocol.js';
4
+ import { MediaStorage, actorKey } from './storage.js';
5
+ import { ScreenService } from './images.js';
6
+ import { BrowserService } from './browserService.js';
7
+ export class GameService {
8
+ storage;
9
+ screen;
10
+ browser;
11
+ games = new Map();
12
+ constructor(storage, screen, browser) {
13
+ this.storage = storage;
14
+ this.screen = screen;
15
+ this.browser = browser;
16
+ }
17
+ get(actor, id) { this.storage.check(); const g = this.games.get(id); if (!g || g.owner !== actorKey(actor) || g.expiresAt < Date.now())
18
+ throw new DodoError('NOT_FOUND', 'unknown/expired game session'); return g; }
19
+ async open(actor, opts, check) {
20
+ if ((opts.browserId === undefined) === (opts.windowId === undefined))
21
+ throw new DodoError('INVALID_INPUT', 'select exactly one browserId or permitted desktop windowId');
22
+ if (this.games.size >= 8)
23
+ throw new DodoError('RESOURCE_LIMIT', 'game session limit reached');
24
+ const game = { id: newId('game'), owner: actorKey(actor), observationId: '', steps: 0, expiresAt: Date.now() + 900000, busy: false, ...(opts.browserId ? { browserId: opts.browserId } : {}), ...(opts.windowId ? { windowId: opts.windowId } : {}) };
25
+ this.games.set(game.id, game);
26
+ try {
27
+ return await this.observe(actor, game.id, check);
28
+ }
29
+ catch (err) {
30
+ this.games.delete(game.id);
31
+ throw err;
32
+ }
33
+ }
34
+ async observe(actor, id, check) {
35
+ const g = this.get(actor, id);
36
+ if (g.busy)
37
+ throw new DodoError('RESOURCE_LIMIT', 'game session busy');
38
+ const observation = g.browserId ? await this.browser.observe(actor, g.browserId) : (await this.screen.observe(actor, { windowId: g.windowId, maxEdge: 1280, count: 1, intervalMs: 0 }, check)).frames[0];
39
+ g.observationId = observation.observationId;
40
+ return { gameId: g.id, steps: g.steps, expiresAt: g.expiresAt, mode: g.browserId ? 'isolated_browser' : 'permitted_desktop', observation,
41
+ note: 'The client model chooses moves. No background autoplay or win/score claim. Browser key holds are bounded; native desktop uses existing discrete actions only.' };
42
+ }
43
+ async step(actor, id, observationId, action, check, gate) {
44
+ const g = this.get(actor, id);
45
+ if (g.busy)
46
+ throw new DodoError('RESOURCE_LIMIT', 'game session busy');
47
+ if (g.observationId !== observationId)
48
+ throw new DodoError('STALE_WORKSPACE', 'use the latest game observation');
49
+ if (g.steps >= 1000)
50
+ throw new DodoError('RESOURCE_LIMIT', 'session move budget reached; open a new reviewed session');
51
+ if (!g.browserId && action.kind === 'keys' && (action.keys.length !== 1 || action.holdMs !== 0))
52
+ throw new DodoError('NOT_SUPPORTED', 'desktop games support one discrete key per step; simultaneous/held keys are available only in isolated browser games');
53
+ g.busy = true;
54
+ let dispatched = false;
55
+ try {
56
+ if (g.browserId) {
57
+ gate();
58
+ const observation = await this.browser.gameStep(actor, g.browserId, observationId, action, check);
59
+ g.steps++;
60
+ g.observationId = observation.observationId;
61
+ return { gameId: id, steps: g.steps, observation, note: 'Input dispatched and an after-frame captured; outcome must be evaluated by the client model.' };
62
+ }
63
+ const frame = this.screen.frame(actor, observationId);
64
+ check();
65
+ if (action.kind === 'wait')
66
+ await new Promise(resolve => setTimeout(resolve, action.durationMs));
67
+ else {
68
+ const names = { ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right', Space: 'space', Enter: 'enter', Escape: 'escape' };
69
+ const native = DesktopActionSchema.parse(action.kind === 'click' ? { kind: 'click', x: action.x, y: action.y } : { kind: 'key', key: names[action.keys[0]] ?? action.keys[0], modifiers: [] });
70
+ await this.storage.services.desktop.action(frame.snapshotId, native, `game-${g.id}-${g.steps}-${observationId}`, actor, policy => { check(); gate(policy); });
71
+ dispatched = true;
72
+ }
73
+ check();
74
+ const observation = (await this.screen.observe(actor, { windowId: g.windowId, maxEdge: 1280, count: 1, intervalMs: 0 }, check)).frames[0];
75
+ g.steps++;
76
+ g.observationId = observation.observationId;
77
+ return { gameId: id, steps: g.steps, observation, note: 'Existing desktop snapshot/foreground/permission checks enforced. This is a discrete move, not low-latency continuous control.' };
78
+ }
79
+ catch (err) {
80
+ // Once input was posted, a failed after-observation must never make the step retryable.
81
+ if (dispatched)
82
+ throw new DodoError('RECOVERY_REQUIRED', 'game input was posted but its outcome could not be observed; inspect before another move');
83
+ throw err;
84
+ }
85
+ finally {
86
+ g.busy = false;
87
+ }
88
+ }
89
+ closeSession(actor, id) { this.get(actor, id); this.games.delete(id); return { closed: true, gameId: id }; }
90
+ sweep() { for (const [id, game] of this.games)
91
+ if (!game.busy && game.expiresAt <= Date.now())
92
+ this.games.delete(id); }
93
+ close() { this.games.clear(); }
94
+ }
95
+ //# sourceMappingURL=gameService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gameService.js","sourceRoot":"","sources":["../../../src/services/multimodal/gameService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,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IAAI,UAAU;gBAAE,MAAM,IAAI,SAAS,CAAC,mBAAmB,EAAE,0FAA0F,CAAC,CAAC;YACrJ,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC;QAAC,CAAC;IAC/B,CAAC;IACD,YAAY,CAAC,KAAY,EAAE,EAAU,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3H,KAAK,KAAK,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK;QAAE,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;YAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvH,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAChC"}
@@ -0,0 +1,107 @@
1
+ import sharp from 'sharp';
2
+ import { DodoError } from '../../errors.js';
3
+ import { digestOf, newId } from '../../util/hash.js';
4
+ import { MediaStorage, actorKey } from './storage.js';
5
+ import { ScreenFrame } from './contracts.js';
6
+ const OPTIONS = { limitInputPixels: 40_000_000, failOn: 'warning' };
7
+ export async function imageView(bytes, maxEdge, crop) {
8
+ if (bytes.length > 16 * 1024 * 1024)
9
+ throw new DodoError('FILE_TOO_LARGE', 'image input exceeds 16 MiB');
10
+ const image = sharp(bytes, OPTIONS);
11
+ const metadata = await image.metadata();
12
+ if (!['jpeg', 'png', 'webp', 'gif'].includes(metadata.format ?? '') || !metadata.width || !metadata.height)
13
+ throw new DodoError('UNSUPPORTED_ENCODING', 'use PNG/JPEG/WebP/GIF; animated files use the first frame');
14
+ const width = metadata.width, height = metadata.height;
15
+ if (crop && (crop.left + crop.width > width || crop.top + crop.height > height))
16
+ throw new DodoError('INVALID_INPUT', 'crop is outside source image pixels');
17
+ if (crop)
18
+ image.extract(crop);
19
+ // No super-resolution claims. Pixel geometry remains explicit for subsequent actions.
20
+ const converted = await image.resize({ width: maxEdge, height: maxEdge, fit: 'inside', withoutEnlargement: !crop }).jpeg({ quality: 80 }).toBuffer({ resolveWithObject: true });
21
+ return { bytes: converted.data, view: { width: converted.info.width, height: converted.info.height, sourceWidth: width, sourceHeight: height, crop: crop ?? null,
22
+ scaleX: (crop?.width ?? width) / converted.info.width, scaleY: (crop?.height ?? height) / converted.info.height, sourceOffsetX: crop?.left ?? 0, sourceOffsetY: crop?.top ?? 0 } };
23
+ }
24
+ export async function imageDifference(before, after) {
25
+ const normalize = (b) => sharp(b, OPTIONS).resize(64, 64, { fit: 'fill' }).removeAlpha().toColourspace('srgb').raw().toBuffer();
26
+ const [a, b] = await Promise.all([normalize(before), normalize(after)]);
27
+ let changed = 0;
28
+ for (let i = 0; i < Math.min(a.length, b.length); i += 3)
29
+ if (Math.max(Math.abs(a[i] - b[i]), Math.abs(a[i + 1] - b[i + 1]), Math.abs(a[i + 2] - b[i + 2])) > 24)
30
+ changed++;
31
+ return changed / 4096;
32
+ }
33
+ export class ScreenService {
34
+ storage;
35
+ frames = new Map();
36
+ busy = false;
37
+ constructor(storage) {
38
+ this.storage = storage;
39
+ }
40
+ sweep() { for (const [id, f] of this.frames)
41
+ if (f.frame.expiresAt <= Date.now())
42
+ this.frames.delete(id); }
43
+ frame(actor, id) {
44
+ this.storage.check();
45
+ this.sweep();
46
+ const value = this.frames.get(id);
47
+ if (!value || value.owner !== actorKey(actor))
48
+ throw new DodoError('NOT_FOUND', 'screen observation expired or belongs to another client');
49
+ this.storage.get(actor, value.frame.asset.assetId);
50
+ return value.frame;
51
+ }
52
+ async observe(actor, opts, check) {
53
+ this.storage.check();
54
+ if (this.busy)
55
+ throw new DodoError('RESOURCE_LIMIT', 'screen observation already in progress');
56
+ if ((opts.count - 1) * opts.intervalMs > 3000)
57
+ throw new DodoError('RESOURCE_LIMIT', 'screen sample burst is limited to 3 seconds');
58
+ this.busy = true;
59
+ try {
60
+ const out = [];
61
+ let previous = opts.previousId;
62
+ for (let i = 0; i < opts.count; i++) {
63
+ if (i)
64
+ await new Promise(resolve => setTimeout(resolve, opts.intervalMs));
65
+ this.storage.check();
66
+ check();
67
+ const desktop = this.storage.services.desktop, policy = desktop.policy(), policyDigest = digestOf(policy);
68
+ const captured = await desktop.capture(opts.windowId, opts.maxEdge, false, actor);
69
+ check();
70
+ const raw = Buffer.from(captured.image, 'base64'), converted = await imageView(raw, opts.maxEdge, opts.crop);
71
+ const expiresAt = Math.min(captured.data.expiresAt, Date.now() + 30000);
72
+ const guard = () => { this.storage.check(); const now = desktop.policy(); if (now.mode === 'off' || digestOf(now) !== policyDigest || expiresAt <= Date.now())
73
+ throw new DodoError('FORBIDDEN', 'desktop permission/snapshot changed; capture again'); };
74
+ const key = digestOf({ windowId: captured.data.windowId, pid: captured.data.pid, appId: captured.data.appId, bounds: captured.data.bounds, view: converted.view });
75
+ let difference = null;
76
+ if (previous) {
77
+ this.frame(actor, previous);
78
+ const prior = this.frames.get(previous);
79
+ const comparable = prior.comparisonKey === key;
80
+ difference = { comparable, changedFraction: comparable ? await imageDifference(this.storage.get(actor, prior.frame.asset.assetId).bytes, converted.bytes) : null,
81
+ note: comparable ? 'Fraction of changed cells on a 64x64 RGB grid; pixel difference is not semantic understanding or task success.' : 'Window identity/geometry/crop changed; images are not comparable.' };
82
+ }
83
+ guard();
84
+ const asset = this.storage.put(actor, 'image', 'image/jpeg', converted.bytes, { ttlMs: Math.max(1, expiresAt - Date.now()), guard });
85
+ const frame = { observationId: newId('obs'), windowId: captured.data.windowId, appId: captured.data.appId, pid: captured.data.pid, snapshotId: captured.data.snapshotId, expiresAt, capturedAt: Date.now(), asset, view: converted.view, difference };
86
+ this.sweep();
87
+ if (this.frames.size >= 32)
88
+ this.frames.delete(this.frames.keys().next().value);
89
+ this.frames.set(frame.observationId, { frame, owner: actorKey(actor), comparisonKey: key, policyDigest });
90
+ out.push(frame);
91
+ previous = frame.observationId;
92
+ }
93
+ return { frames: out, note: 'Images are returned to the client model. This is an explicit bounded burst, not continuous background surveillance. Crop coordinates map back using view.scale/offset; desktop_action uses original snapshot image coordinates.' };
94
+ }
95
+ finally {
96
+ this.busy = false;
97
+ }
98
+ }
99
+ async readFile(actor, file, maxEdge, crop) {
100
+ const input = this.storage.services.wfs.readFileBytes(file, Math.min(this.storage.services.limits.readFileBytes, 16 * 1024 * 1024));
101
+ const image = await imageView(input.bytes, maxEdge, crop);
102
+ const guard = () => { const p = this.storage.services.wfs.resolve(input.rel); this.storage.services.wfs.assertRegularFileForDirectAccess(p); };
103
+ return { asset: this.storage.put(actor, 'image', 'image/jpeg', image.bytes, { guard }), view: image.view };
104
+ }
105
+ close() { this.frames.clear(); }
106
+ }
107
+ //# sourceMappingURL=images.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"images.js","sourceRoot":"","sources":["../../../src/services/multimodal/images.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAc,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAqC,MAAM,gBAAgB,CAAC;AAGhF,MAAM,OAAO,GAAG,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,SAAkB,EAAE,CAAC;AAC7E,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAa,EAAE,OAAe,EAAE,IAAe;IAC7E,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,GAA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AAC,IAAI,EAAE,CAAC;IAC7G,CAAC;IACD,KAAK,KAAW,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CACvC"}
@@ -0,0 +1,279 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { DodoError } from '../../errors.js';
5
+ import { newId } from '../../util/hash.js';
6
+ import { resolveTrustedExecutable } from '../../platform/execResolve.js';
7
+ import { findSpeechEngine } from '../../platform/speech.js';
8
+ import { MediaStorage, actorKey } from './storage.js';
9
+ import { WorkerSpec, WorkerResult, Transcript } from './contracts.js';
10
+ export function parseSubtitles(text) {
11
+ const lines = text.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n').split('\n');
12
+ const result = [];
13
+ const seconds = (value) => { const numbers = value.replace(',', '.').split(':').map(Number); return numbers.reduce((a, v) => a * 60 + v, 0); };
14
+ const timestamp = /((?:\d{1,3}:)?\d{2}:\d{2}[.,]\d{3})\s+-->\s+((?:\d{1,3}:)?\d{2}:\d{2}[.,]\d{3})/;
15
+ for (let i = 0; i < lines.length; i++) {
16
+ const match = timestamp.exec(lines[i]);
17
+ if (!match)
18
+ continue;
19
+ const startSec = seconds(match[1]), endSec = seconds(match[2]);
20
+ const content = [];
21
+ while (++i < lines.length && lines[i].trim() !== '')
22
+ content.push(lines[i]);
23
+ if (!Number.isFinite(startSec) || !Number.isFinite(endSec) || startSec < 0 || endSec < startSec || endSec > 86400)
24
+ throw new DodoError('INVALID_INPUT', 'invalid subtitle timestamps');
25
+ result.push({ startSec, endSec, text: content.join('\n').replace(/<[^>]*>/g, '').slice(0, 4000) });
26
+ if (result.length > 10000)
27
+ throw new DodoError('RESOURCE_LIMIT', 'subtitle cue limit exceeded');
28
+ }
29
+ if (!result.length)
30
+ throw new DodoError('INVALID_INPUT', 'no valid SRT/WebVTT cues found');
31
+ return result.sort((a, b) => a.startSec - b.startSec);
32
+ }
33
+ export class MediaService {
34
+ storage;
35
+ sources = new Map();
36
+ jobs = new Map();
37
+ pendingOpens = 0;
38
+ constructor(storage) {
39
+ this.storage = storage;
40
+ }
41
+ program(name) { try {
42
+ return resolveTrustedExecutable(name, this.storage.services.wfs.root, { allowBatch: false });
43
+ }
44
+ catch {
45
+ return null;
46
+ } }
47
+ capabilities() {
48
+ const defaultModel = path.join(this.storage.configDir, 'models', 'ggml-tiny.bin');
49
+ return { ffmpeg: this.program('ffmpeg') !== null, ffprobe: this.program('ffprobe') !== null, whisper: this.program('whisper-cli') !== null || this.program('whisper-cpp') !== null,
50
+ defaultModelPresent: this.modelExists(defaultModel), modelLocation: 'DODO config directory/models/ggml-tiny.bin, or a guarded workspace modelFile', speechSynthesis: findSpeechEngine(this.storage.services.wfs.root) !== undefined,
51
+ limits: { sourceBytes: 512 * 1024 * 1024, cachedSourceBytes: 1024 * 1024 * 1024, framesPerCall: 8, audioSeconds: 120, transcriptionSeconds: 600 },
52
+ notes: ['No automatic model download or microphone/system audio capture.', 'Tools operate on local workspace media and synthesized speech. Cloud analysis depends on the connected client.'] };
53
+ }
54
+ modelExists(file) { try {
55
+ const st = fs.lstatSync(file);
56
+ return st.isFile() && !st.isSymbolicLink() && st.nlink === 1 && st.size > 1000000 && st.size <= 512 * 1024 * 1024;
57
+ }
58
+ catch {
59
+ return false;
60
+ } }
61
+ requireProgram(name) { const result = this.program(name); if (!result)
62
+ throw new DodoError('NOT_SUPPORTED', `${name} is not on the trusted PATH; install the local media dependency first`); return result; }
63
+ source(actor, id) {
64
+ this.storage.check();
65
+ const result = this.sources.get(id);
66
+ if (!result || result.owner !== actorKey(actor) || result.expiresAt < Date.now())
67
+ throw new DodoError('NOT_FOUND', 'unknown/expired media source for this client');
68
+ this.storage.services.wfs.resolve(result.sourcePath, { allowMissing: true });
69
+ return result;
70
+ }
71
+ launch(actor, operation, mediaId, input, extras = {}) {
72
+ this.storage.check();
73
+ if (this.jobs.size >= 32)
74
+ throw new DodoError('RESOURCE_LIMIT', 'media job limit reached; close completed media handles');
75
+ const ffmpeg = this.requireProgram('ffmpeg'), ffprobe = this.requireProgram('ffprobe');
76
+ const workerUrls = [new URL('./mediaWorker.js', import.meta.url), new URL('../../../dist/services/multimodal/mediaWorker.js', import.meta.url)];
77
+ const worker = workerUrls.map(url => fileURLToPath(url)).find(p => fs.existsSync(p));
78
+ if (!worker)
79
+ throw new DodoError('NOT_SUPPORTED', 'media worker is not built; run npm run build');
80
+ const directory = this.storage.directory();
81
+ try {
82
+ const spec = WorkerSpec.parse({ operation, input, directory, ffmpeg, ffprobe, startSec: 0, durationSec: 30, times: [], maxEdge: 1280, language: 'auto', ...extras });
83
+ const specFile = path.join(directory, 'spec.json');
84
+ fs.writeFileSync(specFile, JSON.stringify(spec), { mode: 0o600, flag: 'wx' });
85
+ const s = this.storage.services;
86
+ const job = s.jobs.start({ workspaceId: s.workspaceId, epoch: s.epoch, principal: actor.grantId, kind: 'exec', program: 'node', args: [worker, specFile], cwdRel: '.', timeoutMs: operation === 'transcribe' ? 600000 : 180000, stdin: false, network: false });
87
+ this.jobs.set(job.jobId, { owner: actorKey(actor), mediaId, directory, operation, sandboxed: job.sandboxed, notes: [], expiresAt: Date.now() + 1800000 });
88
+ return job.jobId;
89
+ }
90
+ catch (err) {
91
+ this.storage.removeDirectory(directory);
92
+ throw err;
93
+ }
94
+ }
95
+ async open(actor, file, waitMs) {
96
+ this.storage.check();
97
+ this.requireProgram('ffprobe');
98
+ this.requireProgram('ffmpeg');
99
+ if (this.sources.size + this.pendingOpens >= 8)
100
+ throw new DodoError('RESOURCE_LIMIT', 'at most eight open media sources');
101
+ this.pendingOpens++;
102
+ const directory = this.storage.directory();
103
+ let source;
104
+ try {
105
+ const copied = await this.storage.copySource(file, directory);
106
+ source = { id: newId('media'), owner: actorKey(actor), directory, ...copied, expiresAt: Date.now() + 1800000 };
107
+ this.sources.set(source.id, source);
108
+ const jobId = this.launch(actor, 'probe', source.id, source.path);
109
+ await this.storage.services.jobs.waitForExit(jobId, waitMs);
110
+ return { mediaId: source.id, sourcePath: source.sourcePath, sourceHash: source.hash, bytes: source.size, expiresAt: source.expiresAt, job: this.report(actor, jobId) };
111
+ }
112
+ catch (err) {
113
+ if (source) {
114
+ this.sources.delete(source.id);
115
+ this.storage.releaseSource(source.size);
116
+ }
117
+ this.storage.removeDirectory(directory);
118
+ throw err;
119
+ }
120
+ finally {
121
+ this.pendingOpens--;
122
+ }
123
+ }
124
+ async extract(actor, id, kind, opts) {
125
+ const source = this.source(actor, id);
126
+ if (kind === 'frames' && !opts.times.length)
127
+ throw new DodoError('INVALID_INPUT', 'frames requires explicit timestamps');
128
+ if (kind === 'audio' && opts.durationSec > 120)
129
+ throw new DodoError('RESOURCE_LIMIT', 'audio excerpt cap is 120 seconds');
130
+ const jobId = this.launch(actor, kind, source.id, source.path, { times: opts.times, startSec: opts.startSec, durationSec: opts.durationSec, maxEdge: opts.maxEdge });
131
+ await this.storage.services.jobs.waitForExit(jobId, opts.waitMs);
132
+ return this.report(actor, jobId);
133
+ }
134
+ async transcribe(actor, id, opts) {
135
+ const source = this.source(actor, id);
136
+ const whisper = this.program('whisper-cli') ?? this.program('whisper-cpp');
137
+ if (!whisper)
138
+ throw new DodoError('NOT_SUPPORTED', 'install whisper.cpp (whisper-cli/whisper-cpp) on the trusted PATH');
139
+ let model = path.join(this.storage.configDir, 'models', 'ggml-tiny.bin');
140
+ if (opts.modelFile) {
141
+ const resolved = this.storage.services.wfs.resolve(opts.modelFile);
142
+ this.storage.services.wfs.assertRegularFileForDirectAccess(resolved);
143
+ model = resolved.abs;
144
+ }
145
+ else {
146
+ const parent = path.dirname(model);
147
+ try {
148
+ if (fs.lstatSync(parent).isSymbolicLink())
149
+ throw new DodoError('PATH_DENIED', 'model directory must not be a symlink');
150
+ }
151
+ catch (err) {
152
+ if (err instanceof DodoError)
153
+ throw err;
154
+ }
155
+ }
156
+ if (!this.modelExists(model))
157
+ throw new DodoError('NOT_SUPPORTED', 'local GGML Whisper model missing or invalid; supply modelFile or install models/ggml-tiny.bin in the DODO config directory');
158
+ const jobId = this.launch(actor, 'transcribe', source.id, source.path, { whisper, model, startSec: opts.startSec, durationSec: opts.durationSec, language: opts.language });
159
+ await this.storage.services.jobs.waitForExit(jobId, opts.waitMs);
160
+ return this.report(actor, jobId);
161
+ }
162
+ async synthesize(actor, text, voice, waitMs) {
163
+ const speech = findSpeechEngine(this.storage.services.wfs.root);
164
+ if (!speech)
165
+ throw new DodoError('NOT_SUPPORTED', 'no working local speech engine or voice; run dodo setup');
166
+ this.requireProgram('ffmpeg');
167
+ this.requireProgram('ffprobe');
168
+ const directory = this.storage.directory(), input = path.join(directory, 'speech.txt');
169
+ // Disable embedded speech directives; never put private input text in argv or job logs.
170
+ fs.writeFileSync(input, text.replace(/\[\[/g, '[ ['), { flag: 'wx', mode: 0o600 });
171
+ let jobId;
172
+ try {
173
+ jobId = this.launch(actor, 'speak', null, input, { speechProgram: speech.program, speechKind: speech.kind, ...(voice ? { voice } : {}) });
174
+ }
175
+ catch (err) {
176
+ this.storage.removeDirectory(directory);
177
+ throw err;
178
+ }
179
+ this.jobs.get(jobId).inputDirectory = directory;
180
+ await this.storage.services.jobs.waitForExit(jobId, waitMs);
181
+ return this.report(actor, jobId);
182
+ }
183
+ report(actor, jobId) {
184
+ this.storage.check();
185
+ const record = this.jobs.get(jobId);
186
+ if (!record || record.owner !== actorKey(actor) || record.expiresAt < Date.now())
187
+ throw new DodoError('NOT_FOUND', 'unknown media job for this client');
188
+ if (record.mediaId)
189
+ this.source(actor, record.mediaId);
190
+ const job = this.storage.services.jobs.getJobChecked(jobId, this.storage.services.workspaceId);
191
+ let error = null;
192
+ if (job.status === 'exited' && job.exitCode === 0 && record.assets === undefined) {
193
+ try {
194
+ const result = WorkerResult.parse(JSON.parse(this.storage.resultFile(record.directory, 'result.json', 65536).toString('utf8')));
195
+ if (result.operation !== record.operation)
196
+ throw new Error('operation mismatch');
197
+ const assets = [];
198
+ for (const output of result.files) {
199
+ let bytes = this.storage.resultFile(record.directory, output.name);
200
+ if (output.kind === 'transcript')
201
+ bytes = Buffer.from(JSON.stringify(Transcript.parse({ ...JSON.parse(bytes.toString('utf8')), mediaId: record.mediaId })));
202
+ const guard = record.mediaId ? () => { this.source(actor, record.mediaId); } : undefined;
203
+ assets.push(this.storage.put(actor, output.kind, output.mimeType, bytes, { ...(output.timeSec !== undefined ? { timeSec: output.timeSec } : {}), ...(output.endSec !== undefined ? { endSec: output.endSec } : {}), ...(guard ? { guard } : {}) }));
204
+ }
205
+ record.assets = assets;
206
+ record.metadata = result.metadata;
207
+ record.notes = result.notes;
208
+ this.storage.removeDirectory(record.directory);
209
+ if (record.inputDirectory)
210
+ this.storage.removeDirectory(record.inputDirectory);
211
+ }
212
+ catch (err) {
213
+ error = `Output unavailable/invalid: ${err instanceof DodoError ? err.code : 'INVALID_OUTPUT'}. Inspect the original job log; do not assume the media was read.`;
214
+ }
215
+ }
216
+ else if (job.status !== 'running' && !(job.status === 'exited' && job.exitCode === 0))
217
+ error = 'Media processor did not complete successfully; inspect job_output. No automatic retry or sandbox downgrade.';
218
+ return { jobId, mediaId: record.mediaId, operation: record.operation, status: error ? 'failed' : job.status, exitCode: job.exitCode, sandboxed: record.sandboxed, assets: record.assets ?? [], ...(record.metadata ? { metadata: record.metadata } : {}), notes: record.notes, error };
219
+ }
220
+ subtitles(actor, id, file, language) {
221
+ this.source(actor, id);
222
+ const input = this.storage.services.wfs.readTextFile(file, Math.min(this.storage.services.limits.readFileBytes, 2 * 1024 * 1024));
223
+ const segments = parseSubtitles(input.text), transcript = Transcript.parse({ source: 'sidecar_subtitles', language, mediaId: id, startSec: segments[0].startSec, endSec: Math.max(...segments.map(s => s.endSec)), segments, truncated: false });
224
+ return this.storage.put(actor, 'transcript', 'application/json', Buffer.from(JSON.stringify(transcript)), { guard: () => { this.source(actor, id); this.storage.services.wfs.resolve(file, { allowMissing: true }); } });
225
+ }
226
+ search(actor, assetId, query, limit) {
227
+ const asset = this.storage.get(actor, assetId);
228
+ if (asset.meta.kind !== 'transcript')
229
+ throw new DodoError('INVALID_INPUT', 'search needs a transcript asset');
230
+ const transcript = Transcript.parse(JSON.parse(asset.bytes.toString('utf8'))), terms = query.toLowerCase().trim().split(/\s+/).filter(Boolean);
231
+ const matches = transcript.segments.filter(s => terms.every(t => s.text.toLowerCase().includes(t)));
232
+ return { mediaId: transcript.mediaId, source: transcript.source, matches: matches.slice(0, limit), totalMatches: matches.length, truncated: matches.length > limit, note: 'Literal transcript search only. No visual scene understanding is claimed for unsampled frames.' };
233
+ }
234
+ async closeSource(actor, id) {
235
+ const source = this.source(actor, id), jobs = [...this.jobs].filter(([, j]) => j.mediaId === id);
236
+ for (const [jobId] of jobs) {
237
+ this.storage.services.jobs.cancel(jobId, this.storage.services.workspaceId, 100);
238
+ await this.storage.services.jobs.waitForExit(jobId, 1000);
239
+ }
240
+ for (const [jobId, job] of jobs) {
241
+ this.storage.removeDirectory(job.directory);
242
+ this.jobs.delete(jobId);
243
+ }
244
+ this.sources.delete(id);
245
+ this.storage.releaseSource(source.size);
246
+ this.storage.removeDirectory(source.directory);
247
+ return { closed: true, mediaId: id };
248
+ }
249
+ async sweep() {
250
+ const expiredSources = [...this.sources.values()].filter(s => s.expiresAt <= Date.now());
251
+ const expiredIds = new Set(expiredSources.map(s => s.id));
252
+ for (const [id, job] of this.jobs)
253
+ if (job.expiresAt <= Date.now() || (job.mediaId !== null && expiredIds.has(job.mediaId))) {
254
+ this.storage.services.jobs.cancel(id, this.storage.services.workspaceId, 100);
255
+ await this.storage.services.jobs.waitForExit(id, 2000);
256
+ this.storage.removeDirectory(job.directory);
257
+ if (job.inputDirectory)
258
+ this.storage.removeDirectory(job.inputDirectory);
259
+ this.jobs.delete(id);
260
+ }
261
+ for (const source of expiredSources) {
262
+ this.sources.delete(source.id);
263
+ this.storage.releaseSource(source.size);
264
+ this.storage.removeDirectory(source.directory);
265
+ }
266
+ }
267
+ async close() {
268
+ for (const [jobId] of this.jobs) {
269
+ try {
270
+ this.storage.services.jobs.cancel(jobId, this.storage.services.workspaceId, 100);
271
+ }
272
+ catch { /* already finished */ }
273
+ }
274
+ await Promise.all([...this.jobs.keys()].map(id => this.storage.services.jobs.waitForExit(id, 2000).catch(() => undefined)));
275
+ this.jobs.clear();
276
+ this.sources.clear();
277
+ }
278
+ }
279
+ //# sourceMappingURL=mediaService.js.map