@xfey/tutti 0.1.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 (564) hide show
  1. package/README.md +50 -0
  2. package/dist/approvals/index.d.ts +3 -0
  3. package/dist/approvals/index.js +3 -0
  4. package/dist/approvals/manager.d.ts +47 -0
  5. package/dist/approvals/manager.js +180 -0
  6. package/dist/approvals/projections.d.ts +34 -0
  7. package/dist/approvals/projections.js +444 -0
  8. package/dist/artifacts/index.d.ts +4 -0
  9. package/dist/artifacts/index.js +4 -0
  10. package/dist/artifacts/manifest.d.ts +48 -0
  11. package/dist/artifacts/manifest.js +334 -0
  12. package/dist/artifacts/preview-runtime.d.ts +97 -0
  13. package/dist/artifacts/preview-runtime.js +585 -0
  14. package/dist/artifacts/static-preview.d.ts +17 -0
  15. package/dist/artifacts/static-preview.js +180 -0
  16. package/dist/chat-assistant/index.d.ts +66 -0
  17. package/dist/chat-assistant/index.js +268 -0
  18. package/dist/checks/index.d.ts +47 -0
  19. package/dist/checks/index.js +169 -0
  20. package/dist/collaboration-state/clarification-messages.d.ts +8 -0
  21. package/dist/collaboration-state/clarification-messages.js +180 -0
  22. package/dist/collaboration-state/clarification-records.d.ts +27 -0
  23. package/dist/collaboration-state/clarification-records.js +266 -0
  24. package/dist/collaboration-state/clarification-round-writes.d.ts +14 -0
  25. package/dist/collaboration-state/clarification-round-writes.js +58 -0
  26. package/dist/collaboration-state/clarification-rounds.d.ts +19 -0
  27. package/dist/collaboration-state/clarification-rounds.js +347 -0
  28. package/dist/collaboration-state/clarification-successors.d.ts +8 -0
  29. package/dist/collaboration-state/clarification-successors.js +318 -0
  30. package/dist/collaboration-state/execution-status.d.ts +3 -0
  31. package/dist/collaboration-state/execution-status.js +8 -0
  32. package/dist/collaboration-state/index.d.ts +17 -0
  33. package/dist/collaboration-state/index.js +16 -0
  34. package/dist/collaboration-state/messages.d.ts +25 -0
  35. package/dist/collaboration-state/messages.js +371 -0
  36. package/dist/collaboration-state/read-state.d.ts +7 -0
  37. package/dist/collaboration-state/read-state.js +136 -0
  38. package/dist/collaboration-state/recovery.d.ts +6 -0
  39. package/dist/collaboration-state/recovery.js +125 -0
  40. package/dist/collaboration-state/run-recording.d.ts +5 -0
  41. package/dist/collaboration-state/run-recording.js +216 -0
  42. package/dist/collaboration-state/run-results.d.ts +12 -0
  43. package/dist/collaboration-state/run-results.js +202 -0
  44. package/dist/collaboration-state/scratchpad-source-state.d.ts +46 -0
  45. package/dist/collaboration-state/scratchpad-source-state.js +207 -0
  46. package/dist/collaboration-state/scratchpad.d.ts +8 -0
  47. package/dist/collaboration-state/scratchpad.js +84 -0
  48. package/dist/collaboration-state/serialization.d.ts +16 -0
  49. package/dist/collaboration-state/serialization.js +71 -0
  50. package/dist/collaboration-state/storage-types.d.ts +136 -0
  51. package/dist/collaboration-state/storage-types.js +2 -0
  52. package/dist/collaboration-state/task-details.d.ts +5 -0
  53. package/dist/collaboration-state/task-details.js +25 -0
  54. package/dist/collaboration-state/types.d.ts +289 -0
  55. package/dist/collaboration-state/types.js +2 -0
  56. package/dist/collaboration-state/worklist.d.ts +11 -0
  57. package/dist/collaboration-state/worklist.js +286 -0
  58. package/dist/control-plane/clarification-commands.d.ts +34 -0
  59. package/dist/control-plane/clarification-commands.js +106 -0
  60. package/dist/control-plane/command-recovery.d.ts +3 -0
  61. package/dist/control-plane/command-recovery.js +79 -0
  62. package/dist/control-plane/context-sync.d.ts +47 -0
  63. package/dist/control-plane/context-sync.js +207 -0
  64. package/dist/control-plane/event-publishers.d.ts +24 -0
  65. package/dist/control-plane/event-publishers.js +192 -0
  66. package/dist/control-plane/execution-status.d.ts +13 -0
  67. package/dist/control-plane/execution-status.js +130 -0
  68. package/dist/control-plane/follow-up-context.d.ts +27 -0
  69. package/dist/control-plane/follow-up-context.js +93 -0
  70. package/dist/control-plane/follow-up-output.d.ts +53 -0
  71. package/dist/control-plane/follow-up-output.js +141 -0
  72. package/dist/control-plane/follow-up-run.d.ts +22 -0
  73. package/dist/control-plane/follow-up-run.js +90 -0
  74. package/dist/control-plane/follow-up-start.d.ts +26 -0
  75. package/dist/control-plane/follow-up-start.js +101 -0
  76. package/dist/control-plane/formatters.d.ts +12 -0
  77. package/dist/control-plane/formatters.js +47 -0
  78. package/dist/control-plane/index.d.ts +62 -0
  79. package/dist/control-plane/index.js +416 -0
  80. package/dist/control-plane/invalidations.d.ts +12 -0
  81. package/dist/control-plane/invalidations.js +67 -0
  82. package/dist/control-plane/procedure-logging.d.ts +11 -0
  83. package/dist/control-plane/procedure-logging.js +95 -0
  84. package/dist/control-plane/project-brief-refresh.d.ts +31 -0
  85. package/dist/control-plane/project-brief-refresh.js +105 -0
  86. package/dist/control-plane/project-context-bootstrap.d.ts +39 -0
  87. package/dist/control-plane/project-context-bootstrap.js +107 -0
  88. package/dist/control-plane/reference-summary-refresh.d.ts +22 -0
  89. package/dist/control-plane/reference-summary-refresh.js +344 -0
  90. package/dist/control-plane/run-lineage.d.ts +8 -0
  91. package/dist/control-plane/run-lineage.js +13 -0
  92. package/dist/control-plane/run-result-recording.d.ts +46 -0
  93. package/dist/control-plane/run-result-recording.js +81 -0
  94. package/dist/control-plane/run-scheduler.d.ts +35 -0
  95. package/dist/control-plane/run-scheduler.js +110 -0
  96. package/dist/control-plane/run-start.d.ts +30 -0
  97. package/dist/control-plane/run-start.js +167 -0
  98. package/dist/control-plane/scratchpad-auto-refresh.d.ts +32 -0
  99. package/dist/control-plane/scratchpad-auto-refresh.js +150 -0
  100. package/dist/control-plane/scratchpad-refresh-start.d.ts +60 -0
  101. package/dist/control-plane/scratchpad-refresh-start.js +240 -0
  102. package/dist/control-plane/scratchpad-refresh.d.ts +29 -0
  103. package/dist/control-plane/scratchpad-refresh.js +55 -0
  104. package/dist/control-plane/scratchpad-source-messages.d.ts +10 -0
  105. package/dist/control-plane/scratchpad-source-messages.js +131 -0
  106. package/dist/control-plane/startup-recovery.d.ts +19 -0
  107. package/dist/control-plane/startup-recovery.js +113 -0
  108. package/dist/control-plane/task-compile-continuation.d.ts +25 -0
  109. package/dist/control-plane/task-compile-continuation.js +127 -0
  110. package/dist/control-plane/task-compile-output.d.ts +29 -0
  111. package/dist/control-plane/task-compile-output.js +122 -0
  112. package/dist/control-plane/task-compile-start.d.ts +43 -0
  113. package/dist/control-plane/task-compile-start.js +280 -0
  114. package/dist/control-plane/task-proposal.d.ts +3 -0
  115. package/dist/control-plane/task-proposal.js +37 -0
  116. package/dist/control-plane/types.d.ts +155 -0
  117. package/dist/control-plane/types.js +2 -0
  118. package/dist/control-plane/workflows/index.d.ts +4 -0
  119. package/dist/control-plane/workflows/index.js +4 -0
  120. package/dist/control-plane/workflows/openai.d.ts +34 -0
  121. package/dist/control-plane/workflows/openai.js +411 -0
  122. package/dist/control-plane/workflows/structured-output-schemas.d.ts +9 -0
  123. package/dist/control-plane/workflows/structured-output-schemas.js +289 -0
  124. package/dist/control-plane/workflows/structured-output-validators.d.ts +15 -0
  125. package/dist/control-plane/workflows/structured-output-validators.js +295 -0
  126. package/dist/control-plane/workflows/structured-output.d.ts +3 -0
  127. package/dist/control-plane/workflows/structured-output.js +3 -0
  128. package/dist/control-plane/workflows/types.d.ts +274 -0
  129. package/dist/control-plane/workflows/types.js +2 -0
  130. package/dist/control-plane/worklist-terminal-feedback.d.ts +15 -0
  131. package/dist/control-plane/worklist-terminal-feedback.js +135 -0
  132. package/dist/index.d.ts +2 -0
  133. package/dist/index.js +32 -0
  134. package/dist/procedure-engine/index.d.ts +56 -0
  135. package/dist/procedure-engine/index.js +163 -0
  136. package/dist/project-brief/index.d.ts +4 -0
  137. package/dist/project-brief/index.js +3 -0
  138. package/dist/project-brief/repository.d.ts +5 -0
  139. package/dist/project-brief/repository.js +97 -0
  140. package/dist/project-brief/source.d.ts +8 -0
  141. package/dist/project-brief/source.js +75 -0
  142. package/dist/project-brief/types.d.ts +40 -0
  143. package/dist/project-brief/types.js +2 -0
  144. package/dist/project-docs/context.d.ts +34 -0
  145. package/dist/project-docs/context.js +86 -0
  146. package/dist/project-timeline/index.d.ts +20 -0
  147. package/dist/project-timeline/index.js +100 -0
  148. package/dist/prompt-templates/index.d.ts +13 -0
  149. package/dist/prompt-templates/index.js +86 -0
  150. package/dist/provider-usage/index.d.ts +37 -0
  151. package/dist/provider-usage/index.js +227 -0
  152. package/dist/providers/index.d.ts +2 -0
  153. package/dist/providers/index.js +2 -0
  154. package/dist/providers/openai/app-server/json-rpc.d.ts +71 -0
  155. package/dist/providers/openai/app-server/json-rpc.js +298 -0
  156. package/dist/providers/openai/app-server/permission-profile.d.ts +64 -0
  157. package/dist/providers/openai/app-server/permission-profile.js +67 -0
  158. package/dist/providers/openai/app-server/provider-config.d.ts +10 -0
  159. package/dist/providers/openai/app-server/provider-config.js +39 -0
  160. package/dist/providers/openai/app-server/read-only-procedure.d.ts +68 -0
  161. package/dist/providers/openai/app-server/read-only-procedure.js +293 -0
  162. package/dist/providers/openai/app-server/runtime-helpers.d.ts +20 -0
  163. package/dist/providers/openai/app-server/runtime-helpers.js +151 -0
  164. package/dist/providers/openai/app-server/skills.d.ts +82 -0
  165. package/dist/providers/openai/app-server/skills.js +222 -0
  166. package/dist/providers/openai/app-server/smoke-cli.d.ts +2 -0
  167. package/dist/providers/openai/app-server/smoke-cli.js +42 -0
  168. package/dist/providers/openai/app-server/smoke-helpers.d.ts +19 -0
  169. package/dist/providers/openai/app-server/smoke-helpers.js +125 -0
  170. package/dist/providers/openai/app-server/smoke-provider-input.d.ts +6 -0
  171. package/dist/providers/openai/app-server/smoke-provider-input.js +20 -0
  172. package/dist/providers/openai/app-server/smoke-types.d.ts +49 -0
  173. package/dist/providers/openai/app-server/smoke-types.js +20 -0
  174. package/dist/providers/openai/app-server/smoke.d.ts +9 -0
  175. package/dist/providers/openai/app-server/smoke.js +157 -0
  176. package/dist/providers/openai/app-server/workspace-write-run.d.ts +87 -0
  177. package/dist/providers/openai/app-server/workspace-write-run.js +379 -0
  178. package/dist/providers/openai/chat-assistant.d.ts +34 -0
  179. package/dist/providers/openai/chat-assistant.js +72 -0
  180. package/dist/providers/openai/codex-app-server.d.ts +126 -0
  181. package/dist/providers/openai/codex-app-server.js +147 -0
  182. package/dist/providers/openai/credential-store.d.ts +31 -0
  183. package/dist/providers/openai/credential-store.js +143 -0
  184. package/dist/providers/openai/credential-validation.d.ts +45 -0
  185. package/dist/providers/openai/credential-validation.js +190 -0
  186. package/dist/providers/openai/index.d.ts +13 -0
  187. package/dist/providers/openai/index.js +13 -0
  188. package/dist/providers/openai/machine-local-files.d.ts +19 -0
  189. package/dist/providers/openai/machine-local-files.js +55 -0
  190. package/dist/providers/openai/model-config.d.ts +4 -0
  191. package/dist/providers/openai/model-config.js +4 -0
  192. package/dist/providers/openai/provider-config-errors.d.ts +6 -0
  193. package/dist/providers/openai/provider-config-errors.js +13 -0
  194. package/dist/providers/openai/provider-config-shape.d.ts +3 -0
  195. package/dist/providers/openai/provider-config-shape.js +108 -0
  196. package/dist/providers/openai/provider-config-toml.d.ts +13 -0
  197. package/dist/providers/openai/provider-config-toml.js +113 -0
  198. package/dist/providers/openai/provider-config.d.ts +73 -0
  199. package/dist/providers/openai/provider-config.js +117 -0
  200. package/dist/providers/openai/provider-setup.d.ts +31 -0
  201. package/dist/providers/openai/provider-setup.js +88 -0
  202. package/dist/providers/openai/sdk-procedure-runner.d.ts +70 -0
  203. package/dist/providers/openai/sdk-procedure-runner.js +123 -0
  204. package/dist/providers/openai/token-usage.d.ts +11 -0
  205. package/dist/providers/openai/token-usage.js +90 -0
  206. package/dist/run-engine/index.d.ts +61 -0
  207. package/dist/run-engine/index.js +140 -0
  208. package/dist/run-pipeline/candidate-diff.d.ts +3 -0
  209. package/dist/run-pipeline/candidate-diff.js +10 -0
  210. package/dist/run-pipeline/openai.d.ts +41 -0
  211. package/dist/run-pipeline/openai.js +548 -0
  212. package/dist/run-pipeline/promotion-reconcile.d.ts +13 -0
  213. package/dist/run-pipeline/promotion-reconcile.js +138 -0
  214. package/dist/run-pipeline/result-projections.d.ts +39 -0
  215. package/dist/run-pipeline/result-projections.js +115 -0
  216. package/dist/run-pipeline/task-run-invocation.d.ts +6 -0
  217. package/dist/run-pipeline/task-run-invocation.js +130 -0
  218. package/dist/run-pipeline/task-run-output.d.ts +38 -0
  219. package/dist/run-pipeline/task-run-output.js +146 -0
  220. package/dist/server-shell/cli/args.d.ts +7 -0
  221. package/dist/server-shell/cli/args.js +30 -0
  222. package/dist/server-shell/cli/cli.d.ts +3 -0
  223. package/dist/server-shell/cli/cli.js +57 -0
  224. package/dist/server-shell/cli/errors.d.ts +9 -0
  225. package/dist/server-shell/cli/errors.js +53 -0
  226. package/dist/server-shell/cli/git-bootstrap.d.ts +24 -0
  227. package/dist/server-shell/cli/git-bootstrap.js +246 -0
  228. package/dist/server-shell/cli/host-lifecycle.d.ts +45 -0
  229. package/dist/server-shell/cli/host-lifecycle.js +298 -0
  230. package/dist/server-shell/cli/host-relay-status.d.ts +6 -0
  231. package/dist/server-shell/cli/host-relay-status.js +43 -0
  232. package/dist/server-shell/cli/host-runtime-endpoint.d.ts +22 -0
  233. package/dist/server-shell/cli/host-runtime-endpoint.js +120 -0
  234. package/dist/server-shell/cli/host-server-runtime.d.ts +30 -0
  235. package/dist/server-shell/cli/host-server-runtime.js +432 -0
  236. package/dist/server-shell/cli/index.d.ts +8 -0
  237. package/dist/server-shell/cli/index.js +8 -0
  238. package/dist/server-shell/cli/launch.d.ts +45 -0
  239. package/dist/server-shell/cli/launch.js +115 -0
  240. package/dist/server-shell/cli/machine-local.d.ts +69 -0
  241. package/dist/server-shell/cli/machine-local.js +223 -0
  242. package/dist/server-shell/cli/project-identity.d.ts +20 -0
  243. package/dist/server-shell/cli/project-identity.js +87 -0
  244. package/dist/server-shell/cli/relay-registration.d.ts +31 -0
  245. package/dist/server-shell/cli/relay-registration.js +61 -0
  246. package/dist/server-shell/command-idempotency/index.d.ts +44 -0
  247. package/dist/server-shell/command-idempotency/index.js +155 -0
  248. package/dist/server-shell/dev-runner/cli.d.ts +2 -0
  249. package/dist/server-shell/dev-runner/cli.js +10 -0
  250. package/dist/server-shell/dev-runner/config.d.ts +38 -0
  251. package/dist/server-shell/dev-runner/config.js +277 -0
  252. package/dist/server-shell/dev-runner/host-cli.d.ts +2 -0
  253. package/dist/server-shell/dev-runner/host-cli.js +22 -0
  254. package/dist/server-shell/dev-runner/index.d.ts +3 -0
  255. package/dist/server-shell/dev-runner/index.js +3 -0
  256. package/dist/server-shell/dev-runner/runner.d.ts +30 -0
  257. package/dist/server-shell/dev-runner/runner.js +236 -0
  258. package/dist/server-shell/http/create-server.d.ts +18 -0
  259. package/dist/server-shell/http/create-server.js +51 -0
  260. package/dist/server-shell/http/host-tunnel.d.ts +15 -0
  261. package/dist/server-shell/http/host-tunnel.js +154 -0
  262. package/dist/server-shell/http/logger.d.ts +7 -0
  263. package/dist/server-shell/http/logger.js +19 -0
  264. package/dist/server-shell/http/routes/agent-context-auth.d.ts +41 -0
  265. package/dist/server-shell/http/routes/agent-context-auth.js +73 -0
  266. package/dist/server-shell/http/routes/agent-context-errors.d.ts +6 -0
  267. package/dist/server-shell/http/routes/agent-context-errors.js +9 -0
  268. package/dist/server-shell/http/routes/agent-context-messages-routes.d.ts +4 -0
  269. package/dist/server-shell/http/routes/agent-context-messages-routes.js +74 -0
  270. package/dist/server-shell/http/routes/agent-context-project-doc-routes.d.ts +4 -0
  271. package/dist/server-shell/http/routes/agent-context-project-doc-routes.js +86 -0
  272. package/dist/server-shell/http/routes/agent-context-project-docs.d.ts +40 -0
  273. package/dist/server-shell/http/routes/agent-context-project-docs.js +98 -0
  274. package/dist/server-shell/http/routes/agent-context-query.d.ts +31 -0
  275. package/dist/server-shell/http/routes/agent-context-query.js +72 -0
  276. package/dist/server-shell/http/routes/agent-context-reference-routes.d.ts +4 -0
  277. package/dist/server-shell/http/routes/agent-context-reference-routes.js +82 -0
  278. package/dist/server-shell/http/routes/agent-context-references.d.ts +21 -0
  279. package/dist/server-shell/http/routes/agent-context-references.js +85 -0
  280. package/dist/server-shell/http/routes/agent-context-shared.d.ts +34 -0
  281. package/dist/server-shell/http/routes/agent-context-shared.js +44 -0
  282. package/dist/server-shell/http/routes/agent-context-skills-routes.d.ts +4 -0
  283. package/dist/server-shell/http/routes/agent-context-skills-routes.js +85 -0
  284. package/dist/server-shell/http/routes/agent-context-workspace-routes.d.ts +4 -0
  285. package/dist/server-shell/http/routes/agent-context-workspace-routes.js +130 -0
  286. package/dist/server-shell/http/routes/agent-context.d.ts +8 -0
  287. package/dist/server-shell/http/routes/agent-context.js +16 -0
  288. package/dist/server-shell/http/routes/health.d.ts +7 -0
  289. package/dist/server-shell/http/routes/health.js +41 -0
  290. package/dist/server-shell/http/routes/local-control.d.ts +40 -0
  291. package/dist/server-shell/http/routes/local-control.js +260 -0
  292. package/dist/server-shell/http/routes/project-api/approval-routes.d.ts +4 -0
  293. package/dist/server-shell/http/routes/project-api/approval-routes.js +64 -0
  294. package/dist/server-shell/http/routes/project-api/artifacts-routes.d.ts +8 -0
  295. package/dist/server-shell/http/routes/project-api/artifacts-routes.js +166 -0
  296. package/dist/server-shell/http/routes/project-api/clarification-routes.d.ts +4 -0
  297. package/dist/server-shell/http/routes/project-api/clarification-routes.js +150 -0
  298. package/dist/server-shell/http/routes/project-api/constants.d.ts +3 -0
  299. package/dist/server-shell/http/routes/project-api/constants.js +3 -0
  300. package/dist/server-shell/http/routes/project-api/errors.d.ts +26 -0
  301. package/dist/server-shell/http/routes/project-api/errors.js +41 -0
  302. package/dist/server-shell/http/routes/project-api/events-stream.d.ts +11 -0
  303. package/dist/server-shell/http/routes/project-api/events-stream.js +55 -0
  304. package/dist/server-shell/http/routes/project-api/execution-routes.d.ts +4 -0
  305. package/dist/server-shell/http/routes/project-api/execution-routes.js +92 -0
  306. package/dist/server-shell/http/routes/project-api/headers.d.ts +2 -0
  307. package/dist/server-shell/http/routes/project-api/headers.js +7 -0
  308. package/dist/server-shell/http/routes/project-api/invalidations.d.ts +10 -0
  309. package/dist/server-shell/http/routes/project-api/invalidations.js +57 -0
  310. package/dist/server-shell/http/routes/project-api/messages-routes.d.ts +8 -0
  311. package/dist/server-shell/http/routes/project-api/messages-routes.js +80 -0
  312. package/dist/server-shell/http/routes/project-api/openapi-approval-routes.d.ts +128 -0
  313. package/dist/server-shell/http/routes/project-api/openapi-approval-routes.js +32 -0
  314. package/dist/server-shell/http/routes/project-api/openapi-artifacts-routes.d.ts +51 -0
  315. package/dist/server-shell/http/routes/project-api/openapi-artifacts-routes.js +56 -0
  316. package/dist/server-shell/http/routes/project-api/openapi-collaboration-routes.d.ts +466 -0
  317. package/dist/server-shell/http/routes/project-api/openapi-collaboration-routes.js +165 -0
  318. package/dist/server-shell/http/routes/project-api/openapi-diagnostic-routes.d.ts +16 -0
  319. package/dist/server-shell/http/routes/project-api/openapi-diagnostic-routes.js +17 -0
  320. package/dist/server-shell/http/routes/project-api/openapi-execution-routes.d.ts +215 -0
  321. package/dist/server-shell/http/routes/project-api/openapi-execution-routes.js +75 -0
  322. package/dist/server-shell/http/routes/project-api/openapi-path-parameters.d.ts +9 -0
  323. package/dist/server-shell/http/routes/project-api/openapi-path-parameters.js +18 -0
  324. package/dist/server-shell/http/routes/project-api/openapi-skills-routes.d.ts +60 -0
  325. package/dist/server-shell/http/routes/project-api/openapi-skills-routes.js +51 -0
  326. package/dist/server-shell/http/routes/project-api/openapi-timeline-routes.d.ts +115 -0
  327. package/dist/server-shell/http/routes/project-api/openapi-timeline-routes.js +17 -0
  328. package/dist/server-shell/http/routes/project-api/openapi-viewer-routes.d.ts +323 -0
  329. package/dist/server-shell/http/routes/project-api/openapi-viewer-routes.js +120 -0
  330. package/dist/server-shell/http/routes/project-api/openapi-workspace-routes.d.ts +1317 -0
  331. package/dist/server-shell/http/routes/project-api/openapi-workspace-routes.js +95 -0
  332. package/dist/server-shell/http/routes/project-api/openapi.d.ts +2457 -0
  333. package/dist/server-shell/http/routes/project-api/openapi.js +30 -0
  334. package/dist/server-shell/http/routes/project-api/payload-validation.d.ts +6 -0
  335. package/dist/server-shell/http/routes/project-api/payload-validation.js +36 -0
  336. package/dist/server-shell/http/routes/project-api/project-docs-helpers.d.ts +9 -0
  337. package/dist/server-shell/http/routes/project-api/project-docs-helpers.js +17 -0
  338. package/dist/server-shell/http/routes/project-api/project-docs-routes.d.ts +8 -0
  339. package/dist/server-shell/http/routes/project-api/project-docs-routes.js +151 -0
  340. package/dist/server-shell/http/routes/project-api/project-timeline-projection.d.ts +8 -0
  341. package/dist/server-shell/http/routes/project-api/project-timeline-projection.js +658 -0
  342. package/dist/server-shell/http/routes/project-api/project-timeline-routes.d.ts +4 -0
  343. package/dist/server-shell/http/routes/project-api/project-timeline-routes.js +23 -0
  344. package/dist/server-shell/http/routes/project-api/read-state-routes.d.ts +8 -0
  345. package/dist/server-shell/http/routes/project-api/read-state-routes.js +82 -0
  346. package/dist/server-shell/http/routes/project-api/reference-files-routes.d.ts +8 -0
  347. package/dist/server-shell/http/routes/project-api/reference-files-routes.js +184 -0
  348. package/dist/server-shell/http/routes/project-api/reference-files.d.ts +17 -0
  349. package/dist/server-shell/http/routes/project-api/reference-files.js +212 -0
  350. package/dist/server-shell/http/routes/project-api/repo-projection.d.ts +3 -0
  351. package/dist/server-shell/http/routes/project-api/repo-projection.js +58 -0
  352. package/dist/server-shell/http/routes/project-api/schemas.d.ts +1351 -0
  353. package/dist/server-shell/http/routes/project-api/schemas.js +441 -0
  354. package/dist/server-shell/http/routes/project-api/session-requirements.d.ts +10 -0
  355. package/dist/server-shell/http/routes/project-api/session-requirements.js +60 -0
  356. package/dist/server-shell/http/routes/project-api/skills-helpers.d.ts +7 -0
  357. package/dist/server-shell/http/routes/project-api/skills-helpers.js +48 -0
  358. package/dist/server-shell/http/routes/project-api/skills-routes.d.ts +8 -0
  359. package/dist/server-shell/http/routes/project-api/skills-routes.js +185 -0
  360. package/dist/server-shell/http/routes/project-api/staged-uploads.d.ts +14 -0
  361. package/dist/server-shell/http/routes/project-api/staged-uploads.js +149 -0
  362. package/dist/server-shell/http/routes/project-api/system-routes.d.ts +8 -0
  363. package/dist/server-shell/http/routes/project-api/system-routes.js +141 -0
  364. package/dist/server-shell/http/routes/project-api/types.d.ts +137 -0
  365. package/dist/server-shell/http/routes/project-api/types.js +2 -0
  366. package/dist/server-shell/http/routes/project-api/viewer-projections.d.ts +17 -0
  367. package/dist/server-shell/http/routes/project-api/viewer-projections.js +102 -0
  368. package/dist/server-shell/http/routes/project-api/viewer-routes.d.ts +4 -0
  369. package/dist/server-shell/http/routes/project-api/viewer-routes.js +100 -0
  370. package/dist/server-shell/http/routes/project-api/workflow-routes.d.ts +4 -0
  371. package/dist/server-shell/http/routes/project-api/workflow-routes.js +85 -0
  372. package/dist/server-shell/http/routes/project-api/workspace-projections.d.ts +5 -0
  373. package/dist/server-shell/http/routes/project-api/workspace-projections.js +103 -0
  374. package/dist/server-shell/http/routes/project-api.d.ts +8 -0
  375. package/dist/server-shell/http/routes/project-api.js +34 -0
  376. package/dist/server-shell/http/sse-replay-buffer.d.ts +54 -0
  377. package/dist/server-shell/http/sse-replay-buffer.js +110 -0
  378. package/dist/server-shell/http/sse.d.ts +12 -0
  379. package/dist/server-shell/http/sse.js +22 -0
  380. package/dist/server-shell/http/static-web.d.ts +6 -0
  381. package/dist/server-shell/http/static-web.js +52 -0
  382. package/dist/server-shell/http/validation.d.ts +13 -0
  383. package/dist/server-shell/http/validation.js +136 -0
  384. package/dist/server-shell/http/workspace-events.d.ts +38 -0
  385. package/dist/server-shell/http/workspace-events.js +98 -0
  386. package/dist/server-shell/session/relay-session-context.d.ts +25 -0
  387. package/dist/server-shell/session/relay-session-context.js +49 -0
  388. package/dist/server-shell/smoke/e2e-client.d.ts +59 -0
  389. package/dist/server-shell/smoke/e2e-client.js +304 -0
  390. package/dist/server-shell/smoke/index.d.ts +2 -0
  391. package/dist/server-shell/smoke/index.js +2 -0
  392. package/dist/skills/constants.d.ts +8 -0
  393. package/dist/skills/constants.js +9 -0
  394. package/dist/skills/errors.d.ts +6 -0
  395. package/dist/skills/errors.js +9 -0
  396. package/dist/skills/index.d.ts +41 -0
  397. package/dist/skills/index.js +171 -0
  398. package/dist/skills/metadata.d.ts +8 -0
  399. package/dist/skills/metadata.js +80 -0
  400. package/dist/skills/zip-import.d.ts +18 -0
  401. package/dist/skills/zip-import.js +241 -0
  402. package/dist/store/command-recovery.d.ts +26 -0
  403. package/dist/store/command-recovery.js +71 -0
  404. package/dist/store/index.d.ts +6 -0
  405. package/dist/store/index.js +6 -0
  406. package/dist/store/lifecycle.d.ts +23 -0
  407. package/dist/store/lifecycle.js +53 -0
  408. package/dist/store/metadata.d.ts +18 -0
  409. package/dist/store/metadata.js +30 -0
  410. package/dist/store/migrations.d.ts +20 -0
  411. package/dist/store/migrations.js +76 -0
  412. package/dist/store/sqlite.d.ts +11 -0
  413. package/dist/store/sqlite.js +21 -0
  414. package/dist/workspace-ops/constants.d.ts +15 -0
  415. package/dist/workspace-ops/constants.js +20 -0
  416. package/dist/workspace-ops/errors.d.ts +8 -0
  417. package/dist/workspace-ops/errors.js +33 -0
  418. package/dist/workspace-ops/git.d.ts +13 -0
  419. package/dist/workspace-ops/git.js +53 -0
  420. package/dist/workspace-ops/index.d.ts +11 -0
  421. package/dist/workspace-ops/index.js +9 -0
  422. package/dist/workspace-ops/mainline.d.ts +2 -0
  423. package/dist/workspace-ops/mainline.js +16 -0
  424. package/dist/workspace-ops/project-doc-templates.d.ts +12 -0
  425. package/dist/workspace-ops/project-doc-templates.js +180 -0
  426. package/dist/workspace-ops/project-docs.d.ts +7 -0
  427. package/dist/workspace-ops/project-docs.js +156 -0
  428. package/dist/workspace-ops/reference-files.d.ts +3 -0
  429. package/dist/workspace-ops/reference-files.js +137 -0
  430. package/dist/workspace-ops/reference-metadata.d.ts +13 -0
  431. package/dist/workspace-ops/reference-metadata.js +86 -0
  432. package/dist/workspace-ops/reference-summaries.d.ts +17 -0
  433. package/dist/workspace-ops/reference-summaries.js +298 -0
  434. package/dist/workspace-ops/run-workspaces.d.ts +18 -0
  435. package/dist/workspace-ops/run-workspaces.js +271 -0
  436. package/dist/workspace-ops/types.d.ts +219 -0
  437. package/dist/workspace-ops/types.js +2 -0
  438. package/dist/workspace-ops/viewer-file.d.ts +4 -0
  439. package/dist/workspace-ops/viewer-file.js +207 -0
  440. package/dist/workspace-ops/viewer-git.d.ts +20 -0
  441. package/dist/workspace-ops/viewer-git.js +111 -0
  442. package/dist/workspace-ops/viewer-paths.d.ts +3 -0
  443. package/dist/workspace-ops/viewer-paths.js +13 -0
  444. package/dist/workspace-ops/viewer-tree.d.ts +9 -0
  445. package/dist/workspace-ops/viewer-tree.js +144 -0
  446. package/dist/workspace-ops/viewer.d.ts +5 -0
  447. package/dist/workspace-ops/viewer.js +5 -0
  448. package/migrations/0001_init.sql +674 -0
  449. package/migrations/0002_allow_sealed_round_successor_note.sql +14 -0
  450. package/migrations/0003_drop_scratchpad_source_message_refs.sql +1 -0
  451. package/migrations/0004_read_state.sql +109 -0
  452. package/migrations/0005_provider_usage.sql +15 -0
  453. package/migrations/0006_scratchpad_source_state.sql +29 -0
  454. package/migrations/0007_workspace_signal_read_state_scopes.sql +74 -0
  455. package/migrations/0008_provider_usage_anchors.sql +32 -0
  456. package/migrations/0009_project_timeline_events.sql +33 -0
  457. package/migrations/0010_project_brief.sql +13 -0
  458. package/migrations/0011_message_author_avatar.sql +5 -0
  459. package/migrations/README.md +44 -0
  460. package/node_modules/@tutti/relay-client/dist/host-control.d.ts +164 -0
  461. package/node_modules/@tutti/relay-client/dist/host-control.js +284 -0
  462. package/node_modules/@tutti/relay-client/dist/index.d.ts +3 -0
  463. package/node_modules/@tutti/relay-client/dist/index.js +3 -0
  464. package/node_modules/@tutti/relay-client/dist/tunnel-frames.d.ts +8 -0
  465. package/node_modules/@tutti/relay-client/dist/tunnel-frames.js +124 -0
  466. package/node_modules/@tutti/relay-client/dist/tunnel-types.d.ts +61 -0
  467. package/node_modules/@tutti/relay-client/dist/tunnel-types.js +2 -0
  468. package/node_modules/@tutti/relay-client/dist/tunnel.d.ts +4 -0
  469. package/node_modules/@tutti/relay-client/dist/tunnel.js +144 -0
  470. package/node_modules/@tutti/relay-client/package.json +18 -0
  471. package/node_modules/@tutti/shared/dist/domain/index.d.ts +59 -0
  472. package/node_modules/@tutti/shared/dist/domain/index.js +37 -0
  473. package/node_modules/@tutti/shared/dist/ids/index.d.ts +85 -0
  474. package/node_modules/@tutti/shared/dist/ids/index.js +88 -0
  475. package/node_modules/@tutti/shared/dist/index.d.ts +6 -0
  476. package/node_modules/@tutti/shared/dist/index.js +6 -0
  477. package/node_modules/@tutti/shared/dist/schemas/api/approvals.d.ts +307 -0
  478. package/node_modules/@tutti/shared/dist/schemas/api/approvals.js +110 -0
  479. package/node_modules/@tutti/shared/dist/schemas/api/artifacts.d.ts +173 -0
  480. package/node_modules/@tutti/shared/dist/schemas/api/artifacts.js +107 -0
  481. package/node_modules/@tutti/shared/dist/schemas/api/clarifications.d.ts +704 -0
  482. package/node_modules/@tutti/shared/dist/schemas/api/clarifications.js +224 -0
  483. package/node_modules/@tutti/shared/dist/schemas/api/index.d.ts +18 -0
  484. package/node_modules/@tutti/shared/dist/schemas/api/index.js +17 -0
  485. package/node_modules/@tutti/shared/dist/schemas/api/messages.d.ts +370 -0
  486. package/node_modules/@tutti/shared/dist/schemas/api/messages.js +134 -0
  487. package/node_modules/@tutti/shared/dist/schemas/api/openapi.d.ts +32 -0
  488. package/node_modules/@tutti/shared/dist/schemas/api/openapi.js +100 -0
  489. package/node_modules/@tutti/shared/dist/schemas/api/primitives.d.ts +109 -0
  490. package/node_modules/@tutti/shared/dist/schemas/api/primitives.js +174 -0
  491. package/node_modules/@tutti/shared/dist/schemas/api/project-timeline.d.ts +149 -0
  492. package/node_modules/@tutti/shared/dist/schemas/api/project-timeline.js +44 -0
  493. package/node_modules/@tutti/shared/dist/schemas/api/provider-config.d.ts +21 -0
  494. package/node_modules/@tutti/shared/dist/schemas/api/provider-config.js +33 -0
  495. package/node_modules/@tutti/shared/dist/schemas/api/provider-usage.d.ts +87 -0
  496. package/node_modules/@tutti/shared/dist/schemas/api/provider-usage.js +48 -0
  497. package/node_modules/@tutti/shared/dist/schemas/api/read-state.d.ts +89 -0
  498. package/node_modules/@tutti/shared/dist/schemas/api/read-state.js +39 -0
  499. package/node_modules/@tutti/shared/dist/schemas/api/runtime-events.d.ts +484 -0
  500. package/node_modules/@tutti/shared/dist/schemas/api/runtime-events.js +185 -0
  501. package/node_modules/@tutti/shared/dist/schemas/api/skills.d.ts +88 -0
  502. package/node_modules/@tutti/shared/dist/schemas/api/skills.js +71 -0
  503. package/node_modules/@tutti/shared/dist/schemas/api/types.d.ts +253 -0
  504. package/node_modules/@tutti/shared/dist/schemas/api/types.js +2 -0
  505. package/node_modules/@tutti/shared/dist/schemas/api/uploads.d.ts +103 -0
  506. package/node_modules/@tutti/shared/dist/schemas/api/uploads.js +78 -0
  507. package/node_modules/@tutti/shared/dist/schemas/api/viewer-reference.d.ts +484 -0
  508. package/node_modules/@tutti/shared/dist/schemas/api/viewer-reference.js +267 -0
  509. package/node_modules/@tutti/shared/dist/schemas/api/work-items.d.ts +264 -0
  510. package/node_modules/@tutti/shared/dist/schemas/api/work-items.js +196 -0
  511. package/node_modules/@tutti/shared/dist/schemas/api/workspace-commands.d.ts +179 -0
  512. package/node_modules/@tutti/shared/dist/schemas/api/workspace-commands.js +137 -0
  513. package/node_modules/@tutti/shared/dist/schemas/domain/index.d.ts +31 -0
  514. package/node_modules/@tutti/shared/dist/schemas/domain/index.js +49 -0
  515. package/node_modules/@tutti/shared/dist/schemas/internal/index.d.ts +46 -0
  516. package/node_modules/@tutti/shared/dist/schemas/internal/index.js +46 -0
  517. package/node_modules/@tutti/shared/dist/utils/command-idempotency/index.d.ts +40 -0
  518. package/node_modules/@tutti/shared/dist/utils/command-idempotency/index.js +100 -0
  519. package/node_modules/@tutti/shared/dist/utils/index.d.ts +5 -0
  520. package/node_modules/@tutti/shared/dist/utils/index.js +5 -0
  521. package/node_modules/@tutti/shared/dist/utils/logging/index.d.ts +34 -0
  522. package/node_modules/@tutti/shared/dist/utils/logging/index.js +130 -0
  523. package/node_modules/@tutti/shared/dist/utils/path-policy/index.d.ts +13 -0
  524. package/node_modules/@tutti/shared/dist/utils/path-policy/index.js +80 -0
  525. package/node_modules/@tutti/shared/dist/utils/redaction/index.d.ts +19 -0
  526. package/node_modules/@tutti/shared/dist/utils/redaction/index.js +158 -0
  527. package/node_modules/@tutti/shared/package.json +63 -0
  528. package/package.json +47 -0
  529. package/prompts/README.md +36 -0
  530. package/prompts/chat-assistant.md +43 -0
  531. package/prompts/codex/README.md +13 -0
  532. package/prompts/codex/no-write-smoke.md +35 -0
  533. package/prompts/procedures/README.md +38 -0
  534. package/prompts/procedures/context-sync.md +66 -0
  535. package/prompts/procedures/follow-up-check.md +83 -0
  536. package/prompts/procedures/project-brief-refresh.md +79 -0
  537. package/prompts/procedures/project-context-bootstrap.md +58 -0
  538. package/prompts/procedures/reference-file-summary.md +49 -0
  539. package/prompts/procedures/scratchpad-refresh.md +83 -0
  540. package/prompts/procedures/task-compile.md +116 -0
  541. package/prompts/prompt-flow-experiment-plan.md +203 -0
  542. package/prompts/prompt-flow-map.md +478 -0
  543. package/prompts/runs/README.md +17 -0
  544. package/prompts/runs/task-continuation.md +148 -0
  545. package/prompts/runs/task-retry.md +153 -0
  546. package/prompts/runs/task-run.md +135 -0
  547. package/prompts/skills/README.md +25 -0
  548. package/prompts/skills/read-main-chat/README.md +8 -0
  549. package/prompts/skills/read-main-chat/SKILL.md +18 -0
  550. package/prompts/skills/read-project-docs/README.md +13 -0
  551. package/prompts/skills/read-project-docs/SKILL.md +42 -0
  552. package/prompts/skills/read-references/README.md +9 -0
  553. package/prompts/skills/read-references/SKILL.md +26 -0
  554. package/prompts/skills/read-scratchpad/README.md +8 -0
  555. package/prompts/skills/read-scratchpad/SKILL.md +16 -0
  556. package/prompts/skills/read-user-skills/README.md +7 -0
  557. package/prompts/skills/read-user-skills/SKILL.md +22 -0
  558. package/prompts/skills/read-worklist/README.md +9 -0
  559. package/prompts/skills/read-worklist/SKILL.md +20 -0
  560. package/web/assets/Tutti-B7gEyTp1.png +0 -0
  561. package/web/assets/Tutti-square-BqFU7F0D.png +0 -0
  562. package/web/assets/index-CWkBgHap.js +29 -0
  563. package/web/assets/index-D8xJY8Gr.css +1 -0
  564. package/web/index.html +13 -0
@@ -0,0 +1,371 @@
1
+ import { createMessageId } from "@tutti/shared/ids";
2
+ import { clampLimit, decodeCursor, messageCursor, nowIso, parseJson, stringifyJson, } from "./serialization.js";
3
+ import { recordReadNotificationEvent } from "./read-state.js";
4
+ function readClarificationCardForMessage(db, messageId) {
5
+ const row = db
6
+ .prepare(`
7
+ SELECT
8
+ clarification_rounds.*,
9
+ clarification_threads.current_round_id AS thread_current_round_id
10
+ FROM clarification_rounds
11
+ JOIN clarification_threads
12
+ ON clarification_threads.id = clarification_rounds.clarification_thread_id
13
+ WHERE clarification_rounds.card_message_id = ?
14
+ `)
15
+ .get(messageId);
16
+ if (row === undefined) {
17
+ return undefined;
18
+ }
19
+ const requestPayload = parseJson(row.request_payload_json, {
20
+ summary: "",
21
+ request: "",
22
+ });
23
+ const card = {
24
+ thread_id: row.clarification_thread_id,
25
+ round_id: row.id,
26
+ summary: requestPayload.summary,
27
+ status: row.status,
28
+ is_current_round: row.thread_current_round_id === row.id,
29
+ };
30
+ if (requestPayload.title !== undefined) {
31
+ card.title = requestPayload.title;
32
+ }
33
+ return card;
34
+ }
35
+ export function mapMessageRow(row, db) {
36
+ const author = {
37
+ kind: row.author_kind,
38
+ };
39
+ if (row.author_ref !== null) {
40
+ author.ref = row.author_ref;
41
+ }
42
+ if (row.author_display_name !== null) {
43
+ author.display_name = row.author_display_name;
44
+ }
45
+ if (row.author_avatar_json !== null) {
46
+ const avatar = parseJson(row.author_avatar_json, undefined);
47
+ if (avatar !== undefined) {
48
+ author.avatar = avatar;
49
+ }
50
+ }
51
+ const message = {
52
+ id: row.id,
53
+ scope: row.scope_kind === "main_chat"
54
+ ? { kind: "main_chat" }
55
+ : {
56
+ kind: "clarification_round",
57
+ clarification_round_ref: row.clarification_round_id ?? "",
58
+ },
59
+ author,
60
+ message_kind: row.message_kind,
61
+ body: row.body,
62
+ created_at: row.created_at,
63
+ };
64
+ if (row.refs_json !== null) {
65
+ message.refs = parseJson(row.refs_json, {});
66
+ }
67
+ if (db !== undefined && row.message_kind === "clarification_card") {
68
+ const clarificationCard = readClarificationCardForMessage(db, row.id);
69
+ if (clarificationCard !== undefined) {
70
+ message.clarification_card = clarificationCard;
71
+ }
72
+ }
73
+ return message;
74
+ }
75
+ export function createMainChatMessage(db, input) {
76
+ const now = (input.now ?? (() => new Date()))().toISOString();
77
+ const id = createMessageId();
78
+ db.prepare(`
79
+ INSERT INTO messages (
80
+ id,
81
+ scope_kind,
82
+ author_kind,
83
+ author_ref,
84
+ author_display_name,
85
+ author_avatar_json,
86
+ message_kind,
87
+ body,
88
+ refs_json,
89
+ created_at
90
+ )
91
+ VALUES (?, 'main_chat', ?, ?, ?, ?, 'user_text', ?, ?, ?)
92
+ `).run(id, input.author.kind, input.author.ref ?? null, input.author.display_name ?? null, input.author.avatar === undefined ? null : stringifyJson(input.author.avatar), input.body, input.refs === undefined ? null : stringifyJson(input.refs), now);
93
+ recordReadNotificationEvent(db, {
94
+ scope: "chat",
95
+ source_kind: "message",
96
+ source_ref: id,
97
+ actor: {
98
+ kind: input.author.kind,
99
+ ...(input.author.ref === undefined ? {} : { ref: input.author.ref }),
100
+ },
101
+ occurred_at: now,
102
+ });
103
+ const message = {
104
+ id,
105
+ scope: { kind: "main_chat" },
106
+ author: input.author,
107
+ message_kind: "user_text",
108
+ body: input.body,
109
+ created_at: now,
110
+ };
111
+ if (input.refs !== undefined) {
112
+ message.refs = input.refs;
113
+ }
114
+ return message;
115
+ }
116
+ export function createMainChatSystemMessage(db, input) {
117
+ const createdAt = nowIso(input.now);
118
+ const id = createMessageId();
119
+ db.prepare(`
120
+ INSERT INTO messages (
121
+ id,
122
+ scope_kind,
123
+ author_kind,
124
+ message_kind,
125
+ body,
126
+ refs_json,
127
+ created_at
128
+ )
129
+ VALUES (?, 'main_chat', 'system', 'system_notice', ?, ?, ?)
130
+ `).run(id, input.body, input.refs === undefined ? null : stringifyJson(input.refs), createdAt);
131
+ recordReadNotificationEvent(db, {
132
+ scope: "chat",
133
+ source_kind: "message",
134
+ source_ref: id,
135
+ actor: { kind: "system" },
136
+ occurred_at: createdAt,
137
+ });
138
+ const message = {
139
+ id,
140
+ scope: { kind: "main_chat" },
141
+ author: { kind: "system" },
142
+ message_kind: "system_notice",
143
+ body: input.body,
144
+ created_at: createdAt,
145
+ };
146
+ if (input.refs !== undefined) {
147
+ message.refs = input.refs;
148
+ }
149
+ return message;
150
+ }
151
+ export function createMainChatAgentMessage(db, input) {
152
+ const createdAt = nowIso(input.now);
153
+ const id = createMessageId();
154
+ db.prepare(`
155
+ INSERT INTO messages (
156
+ id,
157
+ scope_kind,
158
+ author_kind,
159
+ author_ref,
160
+ author_display_name,
161
+ message_kind,
162
+ body,
163
+ refs_json,
164
+ created_at
165
+ )
166
+ VALUES (?, 'main_chat', 'agent', 'tutti', 'Tutti', 'agent_text', ?, ?, ?)
167
+ `).run(id, input.body, input.refs === undefined ? null : stringifyJson(input.refs), createdAt);
168
+ recordReadNotificationEvent(db, {
169
+ scope: "chat",
170
+ source_kind: "message",
171
+ source_ref: id,
172
+ actor: { kind: "agent", ref: "tutti" },
173
+ occurred_at: createdAt,
174
+ });
175
+ const message = {
176
+ id,
177
+ scope: { kind: "main_chat" },
178
+ author: { kind: "agent", ref: "tutti", display_name: "Tutti" },
179
+ message_kind: "agent_text",
180
+ body: input.body,
181
+ created_at: createdAt,
182
+ };
183
+ if (input.refs !== undefined) {
184
+ message.refs = input.refs;
185
+ }
186
+ return message;
187
+ }
188
+ export function readMessageProjectionById(db, messageId) {
189
+ const row = db
190
+ .prepare(`
191
+ SELECT *
192
+ FROM messages
193
+ WHERE id = ?
194
+ `)
195
+ .get(messageId);
196
+ return row === undefined ? null : mapMessageRow(row, db);
197
+ }
198
+ export function hasMainChatWorklistFeedbackMessage(db, feedbackKey) {
199
+ const row = db
200
+ .prepare(`
201
+ SELECT 1 AS exists_flag
202
+ FROM messages
203
+ WHERE scope_kind = 'main_chat'
204
+ AND json_extract(refs_json, '$.worklist_feedback.feedback_key') = ?
205
+ LIMIT 1
206
+ `)
207
+ .get(feedbackKey);
208
+ return row !== undefined;
209
+ }
210
+ export function readCompletedWorklistFeedbackTaskIds(db) {
211
+ const rows = db
212
+ .prepare(`
213
+ SELECT refs_json
214
+ FROM messages
215
+ WHERE scope_kind = 'main_chat'
216
+ AND refs_json IS NOT NULL
217
+ AND json_extract(refs_json, '$.worklist_feedback.status') = 'completed'
218
+ `)
219
+ .all();
220
+ const taskIds = new Set();
221
+ for (const row of rows) {
222
+ const refs = parseJson(row.refs_json, {});
223
+ const feedback = refs.worklist_feedback;
224
+ if (feedback?.status !== "completed" ||
225
+ feedback.reason !== "all_tasks_done" ||
226
+ !Array.isArray(feedback.items)) {
227
+ continue;
228
+ }
229
+ for (const item of feedback.items) {
230
+ if (typeof item === "object" &&
231
+ item !== null &&
232
+ !Array.isArray(item) &&
233
+ item.status === "done" &&
234
+ typeof item.task_id === "string") {
235
+ taskIds.add(item.task_id);
236
+ }
237
+ }
238
+ }
239
+ return taskIds;
240
+ }
241
+ export function readMainChatMessageWindow(db, options = {}) {
242
+ const limit = clampLimit(options.limit);
243
+ const before = decodeCursor(options.before);
244
+ const after = decodeCursor(options.after);
245
+ if (before !== null && after !== null) {
246
+ throw new Error("before and after cursors cannot be used together");
247
+ }
248
+ let rows;
249
+ let hasOlder = false;
250
+ let hasNewer = false;
251
+ if (before !== null) {
252
+ rows = db
253
+ .prepare(`
254
+ SELECT *
255
+ FROM messages
256
+ WHERE scope_kind = 'main_chat'
257
+ AND (created_at < ? OR (created_at = ? AND id < ?))
258
+ ORDER BY created_at DESC, id DESC
259
+ LIMIT ?
260
+ `)
261
+ .all(before.created_at, before.created_at, before.id, limit + 1);
262
+ hasOlder = rows.length > limit;
263
+ hasNewer = true;
264
+ rows = rows.slice(0, limit).reverse();
265
+ }
266
+ else if (after !== null) {
267
+ rows = db
268
+ .prepare(`
269
+ SELECT *
270
+ FROM messages
271
+ WHERE scope_kind = 'main_chat'
272
+ AND (created_at > ? OR (created_at = ? AND id > ?))
273
+ ORDER BY created_at ASC, id ASC
274
+ LIMIT ?
275
+ `)
276
+ .all(after.created_at, after.created_at, after.id, limit + 1);
277
+ hasNewer = rows.length > limit;
278
+ hasOlder = true;
279
+ rows = rows.slice(0, limit);
280
+ }
281
+ else if (options.anchor === "start") {
282
+ rows = db
283
+ .prepare(`
284
+ SELECT *
285
+ FROM messages
286
+ WHERE scope_kind = 'main_chat'
287
+ ORDER BY created_at ASC, id ASC
288
+ LIMIT ?
289
+ `)
290
+ .all(limit + 1);
291
+ hasNewer = rows.length > limit;
292
+ rows = rows.slice(0, limit);
293
+ }
294
+ else {
295
+ rows = db
296
+ .prepare(`
297
+ SELECT *
298
+ FROM messages
299
+ WHERE scope_kind = 'main_chat'
300
+ ORDER BY created_at DESC, id DESC
301
+ LIMIT ?
302
+ `)
303
+ .all(limit + 1);
304
+ hasOlder = rows.length > limit;
305
+ rows = rows.slice(0, limit).reverse();
306
+ }
307
+ const items = rows.map((row) => mapMessageRow(row, db));
308
+ const first = items[0];
309
+ const last = items.at(-1);
310
+ const window = {
311
+ has_older: hasOlder,
312
+ has_newer: hasNewer,
313
+ limit,
314
+ };
315
+ if (hasOlder && first !== undefined) {
316
+ window.older_cursor = messageCursor(first);
317
+ }
318
+ if (hasNewer && last !== undefined) {
319
+ window.newer_cursor = messageCursor(last);
320
+ }
321
+ return { items, window };
322
+ }
323
+ export function readMainChatMessagesAfter(db, options) {
324
+ const limit = clampLimit(options.limit);
325
+ const rows = db
326
+ .prepare(`
327
+ SELECT *
328
+ FROM messages
329
+ WHERE scope_kind = 'main_chat'
330
+ AND created_at > ?
331
+ ORDER BY created_at ASC, id ASC
332
+ LIMIT ?
333
+ `)
334
+ .all(options.after_created_at, limit);
335
+ return rows.map((row) => mapMessageRow(row, db));
336
+ }
337
+ export function readMainChatMessagesAfterCursor(db, options) {
338
+ const limit = clampLimit(options.limit);
339
+ const rows = db
340
+ .prepare(`
341
+ SELECT *
342
+ FROM messages
343
+ WHERE scope_kind = 'main_chat'
344
+ AND (
345
+ created_at > ?
346
+ OR (created_at = ? AND id > ?)
347
+ )
348
+ ORDER BY created_at ASC, id ASC
349
+ LIMIT ?
350
+ `)
351
+ .all(options.after_created_at, options.after_created_at, options.after_id, limit);
352
+ return rows.map((row) => mapMessageRow(row, db));
353
+ }
354
+ export function readMainChatMessagesBeforeCursor(db, options) {
355
+ const limit = clampLimit(options.limit);
356
+ const rows = db
357
+ .prepare(`
358
+ SELECT *
359
+ FROM messages
360
+ WHERE scope_kind = 'main_chat'
361
+ AND (
362
+ created_at < ?
363
+ OR (created_at = ? AND id < ?)
364
+ )
365
+ ORDER BY created_at DESC, id DESC
366
+ LIMIT ?
367
+ `)
368
+ .all(options.before_created_at, options.before_created_at, options.before_id, limit);
369
+ return rows.reverse().map((row) => mapMessageRow(row, db));
370
+ }
371
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1,7 @@
1
+ import type { ReadStateSummaryProjection } from "@tutti/shared/schemas/api";
2
+ import type { SqliteDatabase } from "../store/index.js";
3
+ import type { MarkReadStateScopeInput, MarkReadStateScopeResult, ReadReadStateSummaryInput, RecordReadNotificationEventInput } from "./types.js";
4
+ export declare function recordReadNotificationEvent(db: SqliteDatabase, input: RecordReadNotificationEventInput): number;
5
+ export declare function readReadStateSummary(db: SqliteDatabase, input: ReadReadStateSummaryInput): ReadStateSummaryProjection;
6
+ export declare function markReadStateScope(db: SqliteDatabase, input: MarkReadStateScopeInput): MarkReadStateScopeResult;
7
+ //# sourceMappingURL=read-state.d.ts.map
@@ -0,0 +1,136 @@
1
+ import { nowIso } from "./serialization.js";
2
+ const READ_STATE_SCOPES = [
3
+ "chat",
4
+ "worklist",
5
+ "references",
6
+ "skills",
7
+ ];
8
+ function latestEventForScope(db, scope) {
9
+ return (db
10
+ .prepare(`
11
+ SELECT event_cursor, occurred_at
12
+ FROM read_notification_events
13
+ WHERE scope = ?
14
+ ORDER BY event_cursor DESC
15
+ LIMIT 1
16
+ `)
17
+ .get(scope) ?? null);
18
+ }
19
+ function readCursorRow(db, accountRef, scope) {
20
+ return (db
21
+ .prepare(`
22
+ SELECT *
23
+ FROM read_state_cursors
24
+ WHERE account_ref = ?
25
+ AND scope = ?
26
+ `)
27
+ .get(accountRef, scope) ?? null);
28
+ }
29
+ function fallbackReadCursorForSession(db, scope, sessionCreatedAt) {
30
+ return (db
31
+ .prepare(`
32
+ SELECT MAX(event_cursor) AS read_event_cursor
33
+ FROM read_notification_events
34
+ WHERE scope = ?
35
+ AND occurred_at <= ?
36
+ `)
37
+ .get(scope, sessionCreatedAt)?.read_event_cursor ?? 0);
38
+ }
39
+ function hasUnreadEvents(input) {
40
+ const row = input.db
41
+ .prepare(`
42
+ SELECT 1 AS found
43
+ FROM read_notification_events
44
+ WHERE scope = ?
45
+ AND event_cursor > ?
46
+ AND NOT (
47
+ scope = 'chat'
48
+ AND actor_kind = 'human'
49
+ AND actor_ref = ?
50
+ )
51
+ LIMIT 1
52
+ `)
53
+ .get(input.scope, input.read_event_cursor, input.account_ref);
54
+ return row !== undefined;
55
+ }
56
+ function readEffectiveCursor(input) {
57
+ const row = readCursorRow(input.db, input.account_ref, input.scope);
58
+ if (row !== null) {
59
+ return row.read_event_cursor;
60
+ }
61
+ return fallbackReadCursorForSession(input.db, input.scope, input.session_created_at);
62
+ }
63
+ export function recordReadNotificationEvent(db, input) {
64
+ const createdAt = input.created_at ?? input.occurred_at;
65
+ const result = db
66
+ .prepare(`
67
+ INSERT INTO read_notification_events (
68
+ scope,
69
+ source_kind,
70
+ source_ref,
71
+ actor_kind,
72
+ actor_ref,
73
+ occurred_at,
74
+ created_at
75
+ )
76
+ VALUES (?, ?, ?, ?, ?, ?, ?)
77
+ `)
78
+ .run(input.scope, input.source_kind, input.source_ref, input.actor?.kind ?? null, input.actor?.ref ?? null, input.occurred_at, createdAt);
79
+ return Number(result.lastInsertRowid);
80
+ }
81
+ export function readReadStateSummary(db, input) {
82
+ const generatedAt = nowIso(input.now);
83
+ const scopes = Object.fromEntries(READ_STATE_SCOPES.map((scope) => {
84
+ const latest = latestEventForScope(db, scope);
85
+ const latestCursor = latest?.event_cursor ?? 0;
86
+ const readCursor = Math.min(readEffectiveCursor({
87
+ db,
88
+ account_ref: input.account_ref,
89
+ scope,
90
+ session_created_at: input.session_created_at,
91
+ }), latestCursor);
92
+ const projection = {
93
+ scope,
94
+ latest_event_cursor: latestCursor,
95
+ read_event_cursor: readCursor,
96
+ has_unread: hasUnreadEvents({
97
+ db,
98
+ scope,
99
+ account_ref: input.account_ref,
100
+ read_event_cursor: readCursor,
101
+ }),
102
+ };
103
+ if (latest !== null) {
104
+ projection.updated_at = latest.occurred_at;
105
+ }
106
+ return [scope, projection];
107
+ }));
108
+ return {
109
+ generated_at: generatedAt,
110
+ scopes,
111
+ };
112
+ }
113
+ export function markReadStateScope(db, input) {
114
+ const updatedAt = nowIso(input.now);
115
+ const latestCursor = latestEventForScope(db, input.scope)?.event_cursor ?? 0;
116
+ const requestedCursor = input.up_to_event_cursor ?? latestCursor;
117
+ const readCursor = Math.min(Math.max(Math.trunc(requestedCursor), 0), latestCursor);
118
+ db.prepare(`
119
+ INSERT INTO read_state_cursors (
120
+ account_ref,
121
+ scope,
122
+ read_event_cursor,
123
+ read_at,
124
+ updated_at
125
+ )
126
+ VALUES (?, ?, ?, ?, ?)
127
+ ON CONFLICT(account_ref, scope) DO UPDATE SET
128
+ read_event_cursor = max(read_state_cursors.read_event_cursor, excluded.read_event_cursor),
129
+ read_at = excluded.read_at,
130
+ updated_at = excluded.updated_at
131
+ `).run(input.account_ref, input.scope, readCursor, updatedAt, updatedAt);
132
+ return {
133
+ read_state: readReadStateSummary(db, input),
134
+ };
135
+ }
136
+ //# sourceMappingURL=read-state.js.map
@@ -0,0 +1,6 @@
1
+ import { type SqliteDatabase } from "../store/index.js";
2
+ import type { RecoverStaleRunningTasksResult } from "./types.js";
3
+ export declare function recoverStaleRunningTasksAsFailed(db: SqliteDatabase, input?: {
4
+ now?: () => Date;
5
+ }): RecoverStaleRunningTasksResult;
6
+ //# sourceMappingURL=recovery.d.ts.map
@@ -0,0 +1,125 @@
1
+ import { createEventRef, createRunResultId, } from "@tutti/shared/ids";
2
+ import { withHostStoreTransaction } from "../store/index.js";
3
+ import { nowIso, parseJson, stringifyJson } from "./serialization.js";
4
+ import { mapRunResultRow } from "./run-results.js";
5
+ import { readTaskDetailProjection } from "./task-details.js";
6
+ import { readTaskProjection } from "./worklist.js";
7
+ import { recordReadNotificationEvent } from "./read-state.js";
8
+ function inferRecoveryRunLineage(tx, taskRow) {
9
+ if (taskRow.latest_run_result_id === null) {
10
+ return { attempt: 1, kind: "initial" };
11
+ }
12
+ const latestRunResult = tx
13
+ .prepare("SELECT * FROM run_results WHERE id = ?")
14
+ .get(taskRow.latest_run_result_id);
15
+ if (latestRunResult === undefined) {
16
+ return { attempt: 1, kind: "initial" };
17
+ }
18
+ const parentLineage = parseJson(latestRunResult.run_lineage_json, {
19
+ attempt: 1,
20
+ kind: "initial",
21
+ });
22
+ const runKind = latestRunResult.result_kind === "needs_human" ? "continuation" : "retry";
23
+ return {
24
+ attempt: parentLineage.attempt + 1,
25
+ kind: runKind,
26
+ parent_activity_ref: latestRunResult.activity_ref,
27
+ root_activity_ref: parentLineage.root_activity_ref ?? latestRunResult.activity_ref,
28
+ };
29
+ }
30
+ export function recoverStaleRunningTasksAsFailed(db, input = {}) {
31
+ return withHostStoreTransaction(db, (tx) => {
32
+ const recoveredAt = nowIso(input.now);
33
+ const staleTasks = tx
34
+ .prepare(`
35
+ SELECT *
36
+ FROM tasks
37
+ WHERE status = 'running'
38
+ AND current_activity_ref IS NOT NULL
39
+ ORDER BY updated_at ASC, id ASC
40
+ `)
41
+ .all();
42
+ const recoveredRuns = [];
43
+ for (const taskRow of staleTasks) {
44
+ const activityRef = taskRow.current_activity_ref;
45
+ const runResultId = createRunResultId();
46
+ const sourceEventRef = createEventRef();
47
+ const runLineage = inferRecoveryRunLineage(tx, taskRow);
48
+ const resultJson = {
49
+ result_kind: "failed",
50
+ summary: "Run was interrupted by host restart and marked failed during startup recovery.",
51
+ error_code: "run_interrupted_by_restart",
52
+ retryable: true,
53
+ promotion: {
54
+ status: "not_attempted",
55
+ reason_code: "startup_recovery_interrupted",
56
+ summary: "Run did not reach promotion before the host process stopped.",
57
+ },
58
+ };
59
+ const detailResult = {
60
+ latest_run_result_id: runResultId,
61
+ result_kind: "failed",
62
+ run_lineage: runLineage,
63
+ summary: resultJson.summary,
64
+ error_code: resultJson.error_code,
65
+ retryable: resultJson.retryable,
66
+ promotion: resultJson.promotion,
67
+ updated_at: recoveredAt,
68
+ };
69
+ tx.prepare(`
70
+ INSERT INTO run_results (
71
+ id,
72
+ activity_ref,
73
+ task_id,
74
+ source_event_ref,
75
+ run_lineage_json,
76
+ result_kind,
77
+ result_json,
78
+ created_at
79
+ )
80
+ VALUES (?, ?, ?, ?, ?, 'failed', ?, ?)
81
+ `).run(runResultId, activityRef, taskRow.id, sourceEventRef, stringifyJson(runLineage), stringifyJson(resultJson), recoveredAt);
82
+ tx.prepare(`
83
+ UPDATE tasks
84
+ SET status = 'failed',
85
+ current_activity_ref = NULL,
86
+ latest_run_result_id = ?,
87
+ updated_at = ?
88
+ WHERE id = ?
89
+ AND status = 'running'
90
+ `).run(runResultId, recoveredAt, taskRow.id);
91
+ tx.prepare(`
92
+ UPDATE task_details
93
+ SET result_json = ?,
94
+ frozen_contract_since_activity_ref = COALESCE(
95
+ frozen_contract_since_activity_ref,
96
+ ?
97
+ ),
98
+ updated_at = ?
99
+ WHERE task_id = ?
100
+ `).run(stringifyJson(detailResult), activityRef, recoveredAt, taskRow.id);
101
+ recordReadNotificationEvent(tx, {
102
+ scope: "worklist",
103
+ source_kind: "startup_recovery",
104
+ source_ref: runResultId,
105
+ occurred_at: recoveredAt,
106
+ });
107
+ const runResultRow = tx
108
+ .prepare("SELECT * FROM run_results WHERE id = ?")
109
+ .get(runResultId);
110
+ const task = readTaskProjection(tx, taskRow.id);
111
+ const taskDetail = readTaskDetailProjection(tx, taskRow.id);
112
+ if (runResultRow === undefined || task === null || taskDetail === null) {
113
+ throw new Error("Startup recovery did not produce readable task projections");
114
+ }
115
+ recoveredRuns.push({
116
+ activity_ref: activityRef,
117
+ run_result: mapRunResultRow(runResultRow),
118
+ task,
119
+ task_detail: taskDetail,
120
+ });
121
+ }
122
+ return { recovered_runs: recoveredRuns };
123
+ });
124
+ }
125
+ //# sourceMappingURL=recovery.js.map
@@ -0,0 +1,5 @@
1
+ import { type SqliteDatabase } from "../store/index.js";
2
+ import type { RecordRunNeedsHumanResultInput, RecordRunNeedsHumanResultResult, RecordRunResultInput, RecordRunResultResult } from "./types.js";
3
+ export declare function recordRunResult(db: SqliteDatabase, input: RecordRunResultInput): RecordRunResultResult;
4
+ export declare function recordRunNeedsHumanResult(db: SqliteDatabase, input: RecordRunNeedsHumanResultInput): RecordRunNeedsHumanResultResult;
5
+ //# sourceMappingURL=run-recording.d.ts.map