@superblocksteam/vite-plugin-file-sync 2.0.183 → 2.0.185-next.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 (366) hide show
  1. package/dist/agent-tool-executor/claude-file-tools.d.ts +10 -72
  2. package/dist/agent-tool-executor/claude-file-tools.d.ts.map +1 -1
  3. package/dist/agent-tool-executor/claude-sandbox.d.ts +1 -15
  4. package/dist/agent-tool-executor/claude-sandbox.d.ts.map +1 -1
  5. package/dist/agent-tool-executor/claude-shell.d.ts +4 -36
  6. package/dist/agent-tool-executor/claude-shell.d.ts.map +1 -1
  7. package/dist/agent-tool-executor/claude-tool-server.js +2 -2
  8. package/dist/agent-tool-executor/claude-tool-server.js.map +1 -1
  9. package/dist/agent-tool-executor/codex-exec-server.d.ts.map +1 -1
  10. package/dist/agent-tool-executor/codex-exec-server.js +6 -4
  11. package/dist/agent-tool-executor/codex-exec-server.js.map +1 -1
  12. package/dist/agent-tool-executor/codex-execution-policy.js +2 -2
  13. package/dist/agent-tool-executor/codex-execution-policy.js.map +1 -1
  14. package/dist/agent-tool-executor/native-draft-service.d.ts +5 -2
  15. package/dist/agent-tool-executor/native-draft-service.d.ts.map +1 -1
  16. package/dist/agent-tool-executor/native-tool-environment.js +1 -1
  17. package/dist/agent-tool-executor/native-tool-environment.js.map +1 -1
  18. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts +2 -0
  19. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
  20. package/dist/ai-service/agent/prompts/build-base-system-prompt.js +9 -2
  21. package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
  22. package/dist/ai-service/agent/tools/apis/analysis.d.ts.map +1 -1
  23. package/dist/ai-service/agent/tools/apis/analysis.js +36 -67
  24. package/dist/ai-service/agent/tools/apis/analysis.js.map +1 -1
  25. package/dist/ai-service/agent/tools/apis/api-executor.d.ts +1 -0
  26. package/dist/ai-service/agent/tools/apis/api-executor.d.ts.map +1 -1
  27. package/dist/ai-service/agent/tools/apis/api-executor.js +1 -0
  28. package/dist/ai-service/agent/tools/apis/api-executor.js.map +1 -1
  29. package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.d.ts +2 -0
  30. package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.d.ts.map +1 -1
  31. package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.js +1 -0
  32. package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.js.map +1 -1
  33. package/dist/ai-service/agent/tools/apis/test-api.d.ts +22 -1
  34. package/dist/ai-service/agent/tools/apis/test-api.d.ts.map +1 -1
  35. package/dist/ai-service/agent/tools/apis/test-api.js +115 -65
  36. package/dist/ai-service/agent/tools/apis/test-api.js.map +1 -1
  37. package/dist/ai-service/agent/tools/branching/branch-tools.d.ts +2 -2
  38. package/dist/ai-service/agent/tools/branching/branch-tools.d.ts.map +1 -1
  39. package/dist/ai-service/agent/tools/branching/branch-tools.js +1 -1
  40. package/dist/ai-service/agent/tools/branching/branch-tools.js.map +1 -1
  41. package/dist/ai-service/agent/tools/build-copy-utils.d.ts +13 -44
  42. package/dist/ai-service/agent/tools/build-copy-utils.d.ts.map +1 -1
  43. package/dist/ai-service/agent/tools/build-debug.d.ts +1 -1
  44. package/dist/ai-service/agent/tools/build-debug.d.ts.map +1 -1
  45. package/dist/ai-service/agent/tools/build-delete-file.d.ts +1 -0
  46. package/dist/ai-service/agent/tools/build-delete-file.d.ts.map +1 -1
  47. package/dist/ai-service/agent/tools/build-delete-file.js +3 -0
  48. package/dist/ai-service/agent/tools/build-delete-file.js.map +1 -1
  49. package/dist/ai-service/agent/tools/build-edit-file.d.ts +2 -0
  50. package/dist/ai-service/agent/tools/build-edit-file.d.ts.map +1 -1
  51. package/dist/ai-service/agent/tools/build-edit-file.js +7 -0
  52. package/dist/ai-service/agent/tools/build-edit-file.js.map +1 -1
  53. package/dist/ai-service/agent/tools/build-install-packages.d.ts.map +1 -1
  54. package/dist/ai-service/agent/tools/build-install-packages.js +5 -1
  55. package/dist/ai-service/agent/tools/build-install-packages.js.map +1 -1
  56. package/dist/ai-service/agent/tools/build-list-files.d.ts +1 -1
  57. package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts +1 -0
  58. package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts.map +1 -1
  59. package/dist/ai-service/agent/tools/build-multi-edit-file.js +3 -0
  60. package/dist/ai-service/agent/tools/build-multi-edit-file.js.map +1 -1
  61. package/dist/ai-service/agent/tools/build-navigate-preview.js +2 -2
  62. package/dist/ai-service/agent/tools/build-navigate-preview.js.map +1 -1
  63. package/dist/ai-service/agent/tools/build-write-file.d.ts +1 -0
  64. package/dist/ai-service/agent/tools/build-write-file.d.ts.map +1 -1
  65. package/dist/ai-service/agent/tools/build-write-file.js +3 -0
  66. package/dist/ai-service/agent/tools/build-write-file.js.map +1 -1
  67. package/dist/ai-service/agent/tools/clear-error-cache.d.ts +1 -1
  68. package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts +39 -185
  69. package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts.map +1 -1
  70. package/dist/ai-service/agent/tools/databases/dev-database-tasks.js +35 -13
  71. package/dist/ai-service/agent/tools/databases/dev-database-tasks.js.map +1 -1
  72. package/dist/ai-service/agent/tools/databases/dev-database-tools.d.ts +2 -2
  73. package/dist/ai-service/agent/tools/get-security-findings.d.ts +1 -1
  74. package/dist/ai-service/agent/tools/integrations/execute-request.d.ts +71 -268
  75. package/dist/ai-service/agent/tools/integrations/execute-request.d.ts.map +1 -1
  76. package/dist/ai-service/agent/tools/integrations/execute-request.js +20 -11
  77. package/dist/ai-service/agent/tools/integrations/execute-request.js.map +1 -1
  78. package/dist/ai-service/agent/tools/integrations/index.d.ts +1 -1
  79. package/dist/ai-service/agent/tools/integrations/index.d.ts.map +1 -1
  80. package/dist/ai-service/agent/tools/integrations/index.js +1 -1
  81. package/dist/ai-service/agent/tools/integrations/index.js.map +1 -1
  82. package/dist/ai-service/agent/tools/integrations/integration-setup.d.ts +2 -2
  83. package/dist/ai-service/agent/tools/integrations/integration-setup.js +3 -3
  84. package/dist/ai-service/agent/tools/integrations/integration-setup.js.map +1 -1
  85. package/dist/ai-service/agent/tools/integrations/internal.d.ts +14 -2
  86. package/dist/ai-service/agent/tools/integrations/internal.d.ts.map +1 -1
  87. package/dist/ai-service/agent/tools/integrations/internal.js +5 -2
  88. package/dist/ai-service/agent/tools/integrations/internal.js.map +1 -1
  89. package/dist/ai-service/agent/tools/project-agent-feedback.d.ts +17 -0
  90. package/dist/ai-service/agent/tools/project-agent-feedback.d.ts.map +1 -0
  91. package/dist/ai-service/agent/tools/project-agent-feedback.js +87 -0
  92. package/dist/ai-service/agent/tools/project-agent-feedback.js.map +1 -0
  93. package/dist/ai-service/agent/tools/report-security-findings.d.ts +25 -112
  94. package/dist/ai-service/agent/tools/report-security-findings.d.ts.map +1 -1
  95. package/dist/ai-service/agent/tools.d.ts.map +1 -1
  96. package/dist/ai-service/agent/tools.js +1 -0
  97. package/dist/ai-service/agent/tools.js.map +1 -1
  98. package/dist/ai-service/agent/tools2/access-control.d.ts +6 -0
  99. package/dist/ai-service/agent/tools2/access-control.d.ts.map +1 -1
  100. package/dist/ai-service/agent/tools2/access-control.js +16 -10
  101. package/dist/ai-service/agent/tools2/access-control.js.map +1 -1
  102. package/dist/ai-service/agent/tools2/registry.d.ts +4 -2
  103. package/dist/ai-service/agent/tools2/registry.d.ts.map +1 -1
  104. package/dist/ai-service/agent/tools2/registry.js +21 -9
  105. package/dist/ai-service/agent/tools2/registry.js.map +1 -1
  106. package/dist/ai-service/agent/tools2/tool-execution-scope.d.ts +10 -0
  107. package/dist/ai-service/agent/tools2/tool-execution-scope.d.ts.map +1 -0
  108. package/dist/ai-service/agent/tools2/tool-execution-scope.js +21 -0
  109. package/dist/ai-service/agent/tools2/tool-execution-scope.js.map +1 -0
  110. package/dist/ai-service/agent/tools2/tools/end-test-run.d.ts +1 -1
  111. package/dist/ai-service/agent/tools2/tools/list-tasks.d.ts +1 -1
  112. package/dist/ai-service/agent/tools2/types.d.ts +1 -1
  113. package/dist/ai-service/agent/tools2/types.d.ts.map +1 -1
  114. package/dist/ai-service/agent/tools2/types.js.map +1 -1
  115. package/dist/ai-service/app-interface/invalid-lockfile-error.d.ts +11 -0
  116. package/dist/ai-service/app-interface/invalid-lockfile-error.d.ts.map +1 -0
  117. package/dist/ai-service/app-interface/invalid-lockfile-error.js +27 -0
  118. package/dist/ai-service/app-interface/invalid-lockfile-error.js.map +1 -0
  119. package/dist/ai-service/app-interface/npm-lockfile-sources.d.ts +13 -0
  120. package/dist/ai-service/app-interface/npm-lockfile-sources.d.ts.map +1 -0
  121. package/dist/ai-service/app-interface/npm-lockfile-sources.js +129 -0
  122. package/dist/ai-service/app-interface/npm-lockfile-sources.js.map +1 -0
  123. package/dist/ai-service/app-interface/npm-registry.d.ts +20 -10
  124. package/dist/ai-service/app-interface/npm-registry.d.ts.map +1 -1
  125. package/dist/ai-service/app-interface/npm-registry.js +109 -73
  126. package/dist/ai-service/app-interface/npm-registry.js.map +1 -1
  127. package/dist/ai-service/app-interface/registry-lockfile-preparer.d.ts +46 -0
  128. package/dist/ai-service/app-interface/registry-lockfile-preparer.d.ts.map +1 -0
  129. package/dist/ai-service/app-interface/registry-lockfile-preparer.js +88 -0
  130. package/dist/ai-service/app-interface/registry-lockfile-preparer.js.map +1 -0
  131. package/dist/ai-service/app-interface/shell.d.ts +14 -4
  132. package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
  133. package/dist/ai-service/app-interface/shell.js +45 -30
  134. package/dist/ai-service/app-interface/shell.js.map +1 -1
  135. package/dist/ai-service/attachments/validate-prompt-attachments.d.ts.map +1 -1
  136. package/dist/ai-service/attachments/validate-prompt-attachments.js +12 -2
  137. package/dist/ai-service/attachments/validate-prompt-attachments.js.map +1 -1
  138. package/dist/ai-service/builder-binding-error.d.ts +5 -0
  139. package/dist/ai-service/builder-binding-error.d.ts.map +1 -0
  140. package/dist/ai-service/builder-binding-error.js +8 -0
  141. package/dist/ai-service/builder-binding-error.js.map +1 -0
  142. package/dist/ai-service/builder-conversation.d.ts +71 -6
  143. package/dist/ai-service/builder-conversation.d.ts.map +1 -1
  144. package/dist/ai-service/builder-conversation.js +549 -83
  145. package/dist/ai-service/builder-conversation.js.map +1 -1
  146. package/dist/ai-service/builder-core-prompt.d.ts +3 -3
  147. package/dist/ai-service/builder-core-prompt.d.ts.map +1 -1
  148. package/dist/ai-service/builder-core-prompt.js +22 -34
  149. package/dist/ai-service/builder-core-prompt.js.map +1 -1
  150. package/dist/ai-service/builder-runtime-auth.d.ts.map +1 -1
  151. package/dist/ai-service/builder-runtime-auth.js +6 -2
  152. package/dist/ai-service/builder-runtime-auth.js.map +1 -1
  153. package/dist/ai-service/builder-runtime.d.ts +105 -240
  154. package/dist/ai-service/builder-runtime.d.ts.map +1 -1
  155. package/dist/ai-service/builder-runtime.js +391 -77
  156. package/dist/ai-service/builder-runtime.js.map +1 -1
  157. package/dist/ai-service/builder-session-store.d.ts +1 -7
  158. package/dist/ai-service/builder-session-store.d.ts.map +1 -1
  159. package/dist/ai-service/builder-session-store.js +1 -1
  160. package/dist/ai-service/builder-session-store.js.map +1 -1
  161. package/dist/ai-service/builder-tool-callbacks.d.ts +19 -0
  162. package/dist/ai-service/builder-tool-callbacks.d.ts.map +1 -1
  163. package/dist/ai-service/builder-tool-callbacks.js +151 -31
  164. package/dist/ai-service/builder-tool-callbacks.js.map +1 -1
  165. package/dist/ai-service/builder-tools.d.ts +28 -5
  166. package/dist/ai-service/builder-tools.d.ts.map +1 -1
  167. package/dist/ai-service/builder-tools.js +214 -45
  168. package/dist/ai-service/builder-tools.js.map +1 -1
  169. package/dist/ai-service/builder-workspace.d.ts +1 -0
  170. package/dist/ai-service/builder-workspace.d.ts.map +1 -1
  171. package/dist/ai-service/builder-workspace.js +15 -6
  172. package/dist/ai-service/builder-workspace.js.map +1 -1
  173. package/dist/ai-service/chat/chat-session-store.d.ts +2 -2
  174. package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
  175. package/dist/ai-service/chat/chat-session-store.js +25 -8
  176. package/dist/ai-service/chat/chat-session-store.js.map +1 -1
  177. package/dist/ai-service/demo-agents/handlers.d.ts +11 -24
  178. package/dist/ai-service/demo-agents/handlers.d.ts.map +1 -1
  179. package/dist/ai-service/demo-agents/handlers.js +19 -30
  180. package/dist/ai-service/demo-agents/handlers.js.map +1 -1
  181. package/dist/ai-service/demo-agents/load-agents.d.ts +9 -2
  182. package/dist/ai-service/demo-agents/load-agents.d.ts.map +1 -1
  183. package/dist/ai-service/demo-agents/load-agents.js +50 -49
  184. package/dist/ai-service/demo-agents/load-agents.js.map +1 -1
  185. package/dist/ai-service/demo-agents/run-agent.d.ts.map +1 -1
  186. package/dist/ai-service/demo-agents/run-agent.js +50 -5
  187. package/dist/ai-service/demo-agents/run-agent.js.map +1 -1
  188. package/dist/ai-service/demo-agents/system-prompt.d.ts +6 -5
  189. package/dist/ai-service/demo-agents/system-prompt.d.ts.map +1 -1
  190. package/dist/ai-service/demo-agents/system-prompt.js +18 -26
  191. package/dist/ai-service/demo-agents/system-prompt.js.map +1 -1
  192. package/dist/ai-service/demo-agents/types.d.ts +9 -56
  193. package/dist/ai-service/demo-agents/types.d.ts.map +1 -1
  194. package/dist/ai-service/demo-agents/types.js +0 -7
  195. package/dist/ai-service/demo-agents/types.js.map +1 -1
  196. package/dist/ai-service/dev-database-file-sync.d.ts +2 -1
  197. package/dist/ai-service/dev-database-file-sync.d.ts.map +1 -1
  198. package/dist/ai-service/dev-database-file-sync.js.map +1 -1
  199. package/dist/ai-service/features.d.ts +20 -8
  200. package/dist/ai-service/features.d.ts.map +1 -1
  201. package/dist/ai-service/index.d.ts +107 -15
  202. package/dist/ai-service/index.d.ts.map +1 -1
  203. package/dist/ai-service/index.js +588 -139
  204. package/dist/ai-service/index.js.map +1 -1
  205. package/dist/ai-service/judge/tools/playwright-action.d.ts +5 -5
  206. package/dist/ai-service/judge/tools/playwright-action.d.ts.map +1 -1
  207. package/dist/ai-service/judge/tools/playwright-action.js +4 -1
  208. package/dist/ai-service/judge/tools/playwright-action.js.map +1 -1
  209. package/dist/ai-service/llm/context-v2/context-metrics.js +2 -2
  210. package/dist/ai-service/llm/context-v2/storage/event-types.d.ts +45 -110
  211. package/dist/ai-service/llm/context-v2/storage/event-types.d.ts.map +1 -1
  212. package/dist/ai-service/llm/context-v2/storage/event-types.js +3 -3
  213. package/dist/ai-service/llm/context-v2/storage/event-types.js.map +1 -1
  214. package/dist/ai-service/llm/interaction/adapters/vercel.d.ts.map +1 -1
  215. package/dist/ai-service/llm/interaction/adapters/vercel.js +6 -1
  216. package/dist/ai-service/llm/interaction/adapters/vercel.js.map +1 -1
  217. package/dist/ai-service/mcp/adapter/json-schema-to-zod.d.ts.map +1 -1
  218. package/dist/ai-service/mcp/adapter/json-schema-to-zod.js.map +1 -1
  219. package/dist/ai-service/mcp/embedded-playwright-mcp-server.d.ts +2 -0
  220. package/dist/ai-service/mcp/embedded-playwright-mcp-server.d.ts.map +1 -1
  221. package/dist/ai-service/mcp/embedded-playwright-mcp-server.js +28 -0
  222. package/dist/ai-service/mcp/embedded-playwright-mcp-server.js.map +1 -1
  223. package/dist/ai-service/mcp/playwright-server.d.ts +2 -0
  224. package/dist/ai-service/mcp/playwright-server.d.ts.map +1 -1
  225. package/dist/ai-service/mcp/playwright-server.js +1 -0
  226. package/dist/ai-service/mcp/playwright-server.js.map +1 -1
  227. package/dist/ai-service/migration-prompt-gating.d.ts +2 -0
  228. package/dist/ai-service/migration-prompt-gating.d.ts.map +1 -1
  229. package/dist/ai-service/migration-prompt-gating.js +3 -0
  230. package/dist/ai-service/migration-prompt-gating.js.map +1 -1
  231. package/dist/ai-service/native-turn-failure.d.ts +13 -0
  232. package/dist/ai-service/native-turn-failure.d.ts.map +1 -1
  233. package/dist/ai-service/native-turn-failure.js +46 -1
  234. package/dist/ai-service/native-turn-failure.js.map +1 -1
  235. package/dist/ai-service/prompt-builder-service/types.d.ts +3 -1
  236. package/dist/ai-service/prompt-builder-service/types.d.ts.map +1 -1
  237. package/dist/ai-service/security/vulnerability-triage.d.ts +12 -30
  238. package/dist/ai-service/security/vulnerability-triage.d.ts.map +1 -1
  239. package/dist/ai-service/skills/system/_registry.generated.d.ts.map +1 -1
  240. package/dist/ai-service/skills/system/_registry.generated.js +6 -0
  241. package/dist/ai-service/skills/system/_registry.generated.js.map +1 -1
  242. package/dist/ai-service/skills/system/project-agents/references/errors.generated.d.ts +2 -0
  243. package/dist/ai-service/skills/system/project-agents/references/errors.generated.d.ts.map +1 -0
  244. package/dist/ai-service/skills/system/project-agents/references/errors.generated.js +26 -0
  245. package/dist/ai-service/skills/system/project-agents/references/errors.generated.js.map +1 -0
  246. package/dist/ai-service/skills/system/project-agents/references/fields.generated.d.ts +2 -0
  247. package/dist/ai-service/skills/system/project-agents/references/fields.generated.d.ts.map +1 -0
  248. package/dist/ai-service/skills/system/project-agents/references/fields.generated.js +55 -0
  249. package/dist/ai-service/skills/system/project-agents/references/fields.generated.js.map +1 -0
  250. package/dist/ai-service/skills/system/project-agents/skill.generated.d.ts +2 -0
  251. package/dist/ai-service/skills/system/project-agents/skill.generated.d.ts.map +1 -0
  252. package/dist/ai-service/skills/system/project-agents/skill.generated.js +74 -0
  253. package/dist/ai-service/skills/system/project-agents/skill.generated.js.map +1 -0
  254. package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
  255. package/dist/ai-service/state-machine/handlers/llm-generating.js +10 -7
  256. package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
  257. package/dist/ai-service/state-machine/helpers/prompt-failure.d.ts +8 -0
  258. package/dist/ai-service/state-machine/helpers/prompt-failure.d.ts.map +1 -1
  259. package/dist/ai-service/state-machine/helpers/prompt-failure.js +25 -8
  260. package/dist/ai-service/state-machine/helpers/prompt-failure.js.map +1 -1
  261. package/dist/ai-service/state-machine/helpers/prompt-request-metrics.d.ts +4 -0
  262. package/dist/ai-service/state-machine/helpers/prompt-request-metrics.d.ts.map +1 -1
  263. package/dist/ai-service/state-machine/helpers/prompt-request-metrics.js +4 -0
  264. package/dist/ai-service/state-machine/helpers/prompt-request-metrics.js.map +1 -1
  265. package/dist/ai-service/state-machine/helpers/stable-peer.d.ts +2 -0
  266. package/dist/ai-service/state-machine/helpers/stable-peer.d.ts.map +1 -1
  267. package/dist/ai-service/state-machine/helpers/stable-peer.js +9 -2
  268. package/dist/ai-service/state-machine/helpers/stable-peer.js.map +1 -1
  269. package/dist/ai-service/tasks/task-store.d.ts.map +1 -1
  270. package/dist/ai-service/tasks/task-store.js +1 -1
  271. package/dist/ai-service/tasks/task-store.js.map +1 -1
  272. package/dist/ai-service/tasks/types.d.ts +5 -1
  273. package/dist/ai-service/tasks/types.d.ts.map +1 -1
  274. package/dist/ai-service/tool-input-schema.d.ts +14 -0
  275. package/dist/ai-service/tool-input-schema.d.ts.map +1 -0
  276. package/dist/ai-service/tool-input-schema.js +23 -0
  277. package/dist/ai-service/tool-input-schema.js.map +1 -0
  278. package/dist/ai-service/util/inference-jwt.d.ts +5 -0
  279. package/dist/ai-service/util/inference-jwt.d.ts.map +1 -1
  280. package/dist/ai-service/util/inference-jwt.js +17 -0
  281. package/dist/ai-service/util/inference-jwt.js.map +1 -1
  282. package/dist/ai-service/workspace-mirror.d.ts +2 -0
  283. package/dist/ai-service/workspace-mirror.d.ts.map +1 -1
  284. package/dist/ai-service/workspace-mirror.js +21 -0
  285. package/dist/ai-service/workspace-mirror.js.map +1 -1
  286. package/dist/ai-service/workspace-package-registry.d.ts +3 -0
  287. package/dist/ai-service/workspace-package-registry.d.ts.map +1 -0
  288. package/dist/ai-service/workspace-package-registry.js +87 -0
  289. package/dist/ai-service/workspace-package-registry.js.map +1 -0
  290. package/dist/ai-service/workspace-package-state.d.ts +12 -0
  291. package/dist/ai-service/workspace-package-state.d.ts.map +1 -0
  292. package/dist/ai-service/workspace-package-state.js +47 -0
  293. package/dist/ai-service/workspace-package-state.js.map +1 -0
  294. package/dist/ai-service/workspace-packages.d.ts +234 -0
  295. package/dist/ai-service/workspace-packages.d.ts.map +1 -0
  296. package/dist/ai-service/workspace-packages.js +466 -0
  297. package/dist/ai-service/workspace-packages.js.map +1 -0
  298. package/dist/dev-server-ws-smoke-client.d.ts.map +1 -1
  299. package/dist/dev-server-ws-smoke-client.js +1 -0
  300. package/dist/dev-server-ws-smoke-client.js.map +1 -1
  301. package/dist/file-sync-vite-plugin.d.ts +3 -1
  302. package/dist/file-sync-vite-plugin.d.ts.map +1 -1
  303. package/dist/file-sync-vite-plugin.js +28 -11
  304. package/dist/file-sync-vite-plugin.js.map +1 -1
  305. package/dist/file-system-manager.d.ts.map +1 -1
  306. package/dist/file-system-manager.js +11 -13
  307. package/dist/file-system-manager.js.map +1 -1
  308. package/dist/import-check.d.ts +16 -0
  309. package/dist/import-check.d.ts.map +1 -0
  310. package/dist/import-check.js +23 -0
  311. package/dist/import-check.js.map +1 -0
  312. package/dist/index.d.ts +5 -3
  313. package/dist/index.d.ts.map +1 -1
  314. package/dist/index.js +2 -1
  315. package/dist/index.js.map +1 -1
  316. package/dist/lock-service/branch-metrics.d.ts +1 -1
  317. package/dist/lock-service/branch-metrics.d.ts.map +1 -1
  318. package/dist/lock-service/branch-metrics.js.map +1 -1
  319. package/dist/lock-service/index.d.ts +51 -0
  320. package/dist/lock-service/index.d.ts.map +1 -1
  321. package/dist/lock-service/index.js +176 -0
  322. package/dist/lock-service/index.js.map +1 -1
  323. package/dist/plugin-options.d.ts +9 -1
  324. package/dist/plugin-options.d.ts.map +1 -1
  325. package/dist/plugin-options.js.map +1 -1
  326. package/dist/policy-gate-runner.d.ts +1 -9
  327. package/dist/policy-gate-runner.d.ts.map +1 -1
  328. package/dist/project-agent-update.d.ts +44 -0
  329. package/dist/project-agent-update.d.ts.map +1 -0
  330. package/dist/project-agent-update.js +125 -0
  331. package/dist/project-agent-update.js.map +1 -0
  332. package/dist/project-agents.d.ts +31 -0
  333. package/dist/project-agents.d.ts.map +1 -0
  334. package/dist/project-agents.js +50 -0
  335. package/dist/project-agents.js.map +1 -0
  336. package/dist/project-manifest.d.ts +8 -108
  337. package/dist/project-manifest.d.ts.map +1 -1
  338. package/dist/project-manifest.js +28 -115
  339. package/dist/project-manifest.js.map +1 -1
  340. package/dist/server-rpc/index.d.ts +6 -0
  341. package/dist/server-rpc/index.d.ts.map +1 -1
  342. package/dist/server-rpc/index.js +13 -1
  343. package/dist/server-rpc/index.js.map +1 -1
  344. package/dist/socket-manager.d.ts +3 -1
  345. package/dist/socket-manager.d.ts.map +1 -1
  346. package/dist/socket-manager.js +122 -72
  347. package/dist/socket-manager.js.map +1 -1
  348. package/dist/sync-service/draft-mutation.d.ts +6 -2
  349. package/dist/sync-service/draft-mutation.d.ts.map +1 -1
  350. package/dist/sync-service/draft-mutation.js +20 -33
  351. package/dist/sync-service/draft-mutation.js.map +1 -1
  352. package/dist/sync-service/index.d.ts +6 -6
  353. package/dist/sync-service/index.d.ts.map +1 -1
  354. package/dist/sync-service/index.js +29 -61
  355. package/dist/sync-service/index.js.map +1 -1
  356. package/dist/workspace-sync-methods.d.ts +5 -20
  357. package/dist/workspace-sync-methods.d.ts.map +1 -1
  358. package/package.json +17 -13
  359. package/dist/project-agent-tools.d.ts +0 -23
  360. package/dist/project-agent-tools.d.ts.map +0 -1
  361. package/dist/project-agent-tools.js +0 -73
  362. package/dist/project-agent-tools.js.map +0 -1
  363. package/dist/sync-service/native-draft-session.d.ts +0 -3
  364. package/dist/sync-service/native-draft-session.d.ts.map +0 -1
  365. package/dist/sync-service/native-draft-session.js +0 -4
  366. package/dist/sync-service/native-draft-session.js.map +0 -1
@@ -2,24 +2,31 @@ import { randomUUID } from "node:crypto";
2
2
  import { setTimeout as delay } from "node:timers/promises";
3
3
  import { metrics } from "@opentelemetry/api";
4
4
  import { z } from "zod";
5
- import { AiGenerationState, AiMode, promptCostTokensFrom, } from "@superblocksteam/library-shared/types";
6
- import { getAiQuotaPaywallReasonFromMessage, } from "@superblocksteam/shared";
5
+ import { AiGenerationState, AiMode, AiToolExecutionErrorCode, promptCostTokensFrom, } from "@superblocksteam/library-shared/types";
6
+ import { getAiQuotaPaywallReasonFromMessage, isChatChangedElsewhereError, PromptFailureShownInChatError, } from "@superblocksteam/shared";
7
+ import { getErrorMeta, getLogger } from "../util/logger.js";
7
8
  import { getToolErrorMessage } from "./agent/tool-message-utils.js";
9
+ import { BuilderBindingChangedError } from "./builder-binding-error.js";
8
10
  import { BuilderContextUsageSnapshot } from "./builder-context-usage.js";
9
11
  import { BuilderFailureNotice } from "./builder-failure-notice.js";
12
+ import { BuilderInferenceAuthError } from "./builder-inference-auth.js";
10
13
  import { BuilderSessionStore } from "./builder-session-store.js";
11
14
  import { BuilderSubagents } from "./builder-subagents.js";
12
- import { AnotherQuestionPendingError, } from "./builder-tools.js";
15
+ import { BuilderTurnCancelled } from "./builder-tool-callbacks.js";
16
+ import { AnotherQuestionPendingError, UserWaitExpiredError, } from "./builder-tools.js";
13
17
  import { RetrySchedule } from "./llm/stream/retry-schedule.js";
14
18
  import { NativeCallbackOrder } from "./native-callback-order.js";
15
19
  import { NativeTurnFailure } from "./native-turn-failure.js";
16
20
  import { RequestDeduplicator } from "./request-deduplicator.js";
17
21
  import { paywallStopAdvice } from "./state-machine/helpers/prompt-failure.js";
22
+ import { isPeerUnavailableError } from "./state-machine/helpers/stable-peer.js";
18
23
  const toolErrorOutputSchema = z.union([
19
24
  z.string(),
20
25
  z.object({ message: z.string(), fileName: z.string().optional() }),
21
26
  z.object({ error: z.string(), fileName: z.string().optional() }),
22
27
  ]);
28
+ const MAX_REMEMBERED_FAILURES = 200;
29
+ const SETUP_FAILURE_MESSAGE = "The native builder could not start this request. Send your prompt again.";
23
30
  export class BuilderConversation {
24
31
  deps;
25
32
  /** One initial invocation and at most one retry before submission. */
@@ -43,7 +50,23 @@ export class BuilderConversation {
43
50
  description: "Native builder turns re-run after failing before they produced anything",
44
51
  unit: "1",
45
52
  });
53
+ /**
54
+ * Under the runtime's 10-minute callback deadline, which stops the whole
55
+ * turn. Users who are present answer within about a minute.
56
+ */
57
+ static USER_WAIT_LIMIT_MS = 7 * 60_000;
58
+ static MAX_EXPIRED_PERMISSIONS = 32;
59
+ userWaits = metrics
60
+ .getMeter("superblocks.ai_service")
61
+ .createHistogram("superblocks.ai_service.builder_user_wait.duration", {
62
+ description: "How long native builder turns waited on the user for a permission or question, by how the wait ended",
63
+ unit: "s",
64
+ });
65
+ /** Permission requests withdrawn unanswered, so a late answer is not an error. */
66
+ expiredPermissions = new Set();
46
67
  requests = new RequestDeduplicator();
68
+ /** Prompts whose turn failed after their message was saved, so a re-send gets the same refusal. */
69
+ failedRequests = new Map();
47
70
  sessions;
48
71
  /** Each failed turn's classification; see `classify`. */
49
72
  classifications = new WeakMap();
@@ -81,8 +104,12 @@ export class BuilderConversation {
81
104
  }
82
105
  async start(request, attachments = []) {
83
106
  request = { ...request, requestId: request.requestId ?? randomUUID() };
84
- if (request.requestId && this.requests.has(request.requestId))
107
+ if (request.requestId && this.requests.has(request.requestId)) {
108
+ const failure = this.failedRequests.get(request.requestId);
109
+ if (failure)
110
+ throw failure;
85
111
  return this.generationId;
112
+ }
86
113
  const pendingQuestion = this.pendingQuestion;
87
114
  if (request.responseMetadata?.type === "multi_choice_response" &&
88
115
  pendingQuestion?.message.id !==
@@ -106,7 +133,9 @@ export class BuilderConversation {
106
133
  throw new Error("Invalid native question answer");
107
134
  return typeof choice === "string" ? choice : choice.text;
108
135
  });
109
- if (request.prompt.trim())
136
+ // The editor sends a pick's own text as its prompt, so the prompt is an
137
+ // answer only when nothing was picked.
138
+ if (!answers.length && request.prompt.trim())
110
139
  answers.push(request.prompt.trim());
111
140
  if (!answers.length)
112
141
  throw new Error("An answer is required");
@@ -149,10 +178,12 @@ export class BuilderConversation {
149
178
  const turn = {
150
179
  id: randomUUID(),
151
180
  prompt: request.prompt,
181
+ request,
152
182
  controller: new AbortController(),
153
183
  completion: Promise.resolve(),
154
184
  events: Promise.resolve(),
155
- calls: new Set(),
185
+ unrecorded: [],
186
+ calls: new Map(),
156
187
  results: new Set(),
157
188
  plans: new Set(),
158
189
  subagents: new BuilderSubagents((task) => this.push(() => this.deps.peer.call.aiPushTaskStatus(task))),
@@ -165,7 +196,6 @@ export class BuilderConversation {
165
196
  state: AiGenerationState.GENERATING,
166
197
  generationId: turn.id,
167
198
  };
168
- let userPublished = false;
169
199
  try {
170
200
  const prepared = await this.deps.prepare(request, turn.controller.signal, turn.id);
171
201
  turn.controller.signal.throwIfAborted();
@@ -183,8 +213,8 @@ export class BuilderConversation {
183
213
  };
184
214
  await this.sessions.set(scope, session);
185
215
  }
186
- await this.publishUser(request);
187
- userPublished = true;
216
+ turn.conversationId = session.conversationId;
217
+ await this.publishTurnUser(turn);
188
218
  await this.publishState(AiGenerationState.GENERATING, turn.id);
189
219
  const { context, ...tools } = await this.deps.tools.prepare({
190
220
  conversationId: session.conversationId,
@@ -196,8 +226,8 @@ export class BuilderConversation {
196
226
  refreshInference: prepared.refreshInference,
197
227
  }),
198
228
  peer: this.deps.peer,
199
- requestPermission: (permission) => this.requestPermission(permission),
200
- askUser: (message, signal) => this.askUser(turn, message, signal),
229
+ requestPermission: (permission, signal) => this.requestPermission(permission, signal),
230
+ askUser: (message, signal, options) => this.askUser(turn, message, signal, options),
201
231
  });
202
232
  turn.controller.signal.throwIfAborted();
203
233
  turn.completion = this.run(turn, {
@@ -231,14 +261,21 @@ export class BuilderConversation {
231
261
  prompt: [context, request.prompt].filter(Boolean).join("\n\n"),
232
262
  signal: turn.controller.signal,
233
263
  onEvent: (event) => {
234
- if (this.turn !== turn || turn.controller.signal.aborted)
264
+ // After a cancel, only a workspace turn's finish counts: it names
265
+ // the checkpoint the turn end committed even so.
266
+ const committed = event.type === "finish" && event.workspace;
267
+ if (this.turn !== turn ||
268
+ (turn.controller.signal.aborted && !committed))
235
269
  return;
236
270
  if (event.type !== "session" && event.type !== "finish")
237
271
  turn.progressed = true;
238
272
  turn.events = turn.events
239
273
  .then(async () => {
240
- if (turn.controller.signal.aborted)
274
+ if (turn.controller.signal.aborted) {
275
+ if (committed)
276
+ await prepared.onWorkspaceFinish?.(committed);
241
277
  return;
278
+ }
242
279
  if (event.type === "session") {
243
280
  if (prepared.saveSession)
244
281
  await this.persistSession(turn, prepared.saveSession(event.sessionId));
@@ -269,21 +306,128 @@ export class BuilderConversation {
269
306
  ? getAiQuotaPaywallReasonFromMessage(error.message)
270
307
  : undefined;
271
308
  if (paywallReason && !turn.controller.signal.aborted) {
272
- if (!userPublished)
273
- await this.publishUser(request);
274
- await this.publish({
275
- role: "assistant",
276
- type: "text",
277
- content: paywallStopAdvice(paywallReason),
278
- });
309
+ // The turn still ends as a paywall stop when its advice cannot be
310
+ // saved: the editor opens the paywall from the generation state.
311
+ try {
312
+ await this.publishTurnUser(turn);
313
+ await this.publish({
314
+ role: "assistant",
315
+ type: "text",
316
+ content: paywallStopAdvice(paywallReason),
317
+ });
318
+ }
319
+ catch (publishError) {
320
+ this.deps.onError?.(publishError);
321
+ }
279
322
  await this.settle(turn, error, paywallReason);
280
323
  return turn.id;
281
324
  }
325
+ let shown;
326
+ if (turn.controller.signal.aborted) {
327
+ // A cancel during setup saves the prompt in cancel(); a stopped turn keeps it.
328
+ await turn.userSaving?.catch(() => { });
329
+ if (turn.userPublished)
330
+ shown = new PromptFailureShownInChatError("Builder turn cancelled", {
331
+ cause: error,
332
+ });
333
+ }
334
+ else {
335
+ shown = await this.showSetupFailure(turn, error);
336
+ }
337
+ if (request.requestId) {
338
+ if (turn.userPublished)
339
+ this.rememberFailure(request.requestId, shown ?? toError(error));
340
+ else
341
+ this.requests.forget(request.requestId);
342
+ }
343
+ await this.settle(turn, error);
344
+ throw shown ?? error;
345
+ }
346
+ }
347
+ rememberFailure(requestId, error) {
348
+ this.failedRequests.set(requestId, error);
349
+ if (this.failedRequests.size > MAX_REMEMBERED_FAILURES) {
350
+ const oldest = this.failedRequests.keys().next().value;
351
+ if (oldest !== undefined)
352
+ this.failedRequests.delete(oldest);
353
+ }
354
+ }
355
+ /**
356
+ * Saves a prompt refused before its turn, without the attachments it was
357
+ * refused for: saved attachments are restored on every later turn.
358
+ */
359
+ async rejectPrompt(request, error) {
360
+ const original = toError(error);
361
+ const { message } = original;
362
+ const type = request.responseMetadata?.type;
363
+ // A busy conversation would put the rows inside the running turn's output.
364
+ if (this.isBusy ||
365
+ type === "multi_choice_response" ||
366
+ type === "tool_permission_response")
367
+ return original;
368
+ const shown = new PromptFailureShownInChatError(message, { cause: error });
369
+ if (request.requestId && !this.requests.markIfNew(request.requestId))
370
+ return this.failedRequests.get(request.requestId) ?? shown;
371
+ try {
372
+ await this.publishUser({
373
+ ...request,
374
+ ...(request.promptContext && {
375
+ promptContext: { ...request.promptContext, attachments: undefined },
376
+ }),
377
+ });
378
+ await this.publish({
379
+ role: "assistant",
380
+ type: "error",
381
+ content: message,
382
+ });
383
+ if (request.requestId)
384
+ this.rememberFailure(request.requestId, shown);
385
+ return shown;
386
+ }
387
+ catch (persistError) {
388
+ this.deps.onError?.(persistError, undefined, {
389
+ "builder.request.id": request.requestId,
390
+ "builder.prompt_failure.path": "rejected_prompt",
391
+ "builder.prompt_failure.cause": message,
392
+ });
282
393
  if (request.requestId)
283
394
  this.requests.forget(request.requestId);
284
- await this.settle(turn, error);
395
+ return original;
396
+ }
397
+ }
398
+ /** Concurrent callers share one write; the turn counts as published once it lands. */
399
+ publishTurnUser(turn) {
400
+ turn.userSaving ??= this.publishUser(turn.request).then(() => {
401
+ turn.userPublished = true;
402
+ }, (error) => {
403
+ turn.userSaving = undefined;
285
404
  throw error;
405
+ });
406
+ return turn.userSaving;
407
+ }
408
+ async showSetupFailure(turn, error) {
409
+ if (error instanceof BuilderBindingChangedError ||
410
+ error instanceof BuilderInferenceAuthError ||
411
+ isChatChangedElsewhereError(error))
412
+ return undefined;
413
+ const { message } = toError(error);
414
+ try {
415
+ await this.publishTurnUser(turn);
416
+ await this.publish({
417
+ role: "assistant",
418
+ type: "error",
419
+ content: SETUP_FAILURE_MESSAGE,
420
+ });
421
+ }
422
+ catch (persistError) {
423
+ this.deps.onError?.(persistError, undefined, {
424
+ "builder.request.id": turn.request.requestId,
425
+ "builder.prompt_failure.path": "setup_failure",
426
+ "builder.prompt_failure.cause": message,
427
+ });
428
+ return undefined;
286
429
  }
430
+ return new PromptFailureShownInChatError(message, { cause: error });
287
431
  }
288
432
  async persistSession(turn, saved) {
289
433
  const signal = turn.controller.signal;
@@ -306,27 +450,51 @@ export class BuilderConversation {
306
450
  }
307
451
  async run(turn, invocation) {
308
452
  let failure;
453
+ let invokeFailed = false;
309
454
  let paywallReason;
310
455
  try {
311
456
  await this.invoke(turn, invocation);
312
457
  }
313
458
  catch (error) {
314
459
  failure = error;
315
- if (!turn.controller.signal.aborted) {
316
- paywallReason = (await this.reportFailure(turn, error)).paywallReason;
317
- }
460
+ invokeFailed = true;
318
461
  }
319
462
  finally {
463
+ // The chat order is the turn's text, then its checkpoint card, then any
464
+ // error: the latest message must be the error for its Retry button to
465
+ // survive a reload.
320
466
  try {
321
- await this.deps.afterRun?.({ events: () => turn.events });
467
+ await turn.events;
468
+ await this.flushText(turn);
322
469
  }
323
470
  catch (error) {
324
471
  failure ??= error;
325
472
  this.deps.onError?.(error);
326
473
  }
474
+ // Before the checkpoint and the CANCELLED state, so they land in order;
475
+ // apart from the flush so a failed flush cannot leave rows spinning.
476
+ if (turn.stopped)
477
+ await this.interruptOpenCalls(turn);
478
+ try {
479
+ const after = await this.deps.afterRun?.({
480
+ events: () => turn.events,
481
+ });
482
+ turn.checkpointed = Boolean(after?.checkpointId);
483
+ }
484
+ catch (error) {
485
+ failure ??= error;
486
+ this.deps.onError?.(error);
487
+ }
488
+ if (invokeFailed && !turn.controller.signal.aborted) {
489
+ try {
490
+ paywallReason = (await this.reportFailure(turn, failure))
491
+ .paywallReason;
492
+ }
493
+ catch (error) {
494
+ this.deps.onError?.(error);
495
+ }
496
+ }
327
497
  try {
328
- await turn.events;
329
- await this.flushText(turn);
330
498
  await this.deps.chat.flushPendingPushes();
331
499
  }
332
500
  catch (error) {
@@ -334,6 +502,9 @@ export class BuilderConversation {
334
502
  this.deps.onError?.(error);
335
503
  }
336
504
  this.clearPermission(new DOMException("Builder turn ended", "AbortError"));
505
+ // A Stop that landed after the check above, while the cleanup ran.
506
+ if (turn.stopped)
507
+ await this.interruptOpenCalls(turn);
337
508
  await this.settle(turn, failure, paywallReason);
338
509
  }
339
510
  }
@@ -448,18 +619,56 @@ export class BuilderConversation {
448
619
  const turn = this.turn;
449
620
  if (!turn)
450
621
  return;
622
+ const settingUp = !turn.userPublished;
451
623
  turn.stopped = true;
452
- turn.controller.abort(new DOMException("Builder turn cancelled", "AbortError"));
624
+ turn.controller.abort(new BuilderTurnCancelled());
453
625
  this.clearPermission(turn.controller.signal.reason);
626
+ // Saved before settling so a reset or the next prompt lands after it.
627
+ if (settingUp)
628
+ await this.publishTurnUser(turn).catch((error) => this.deps.onError?.(error, undefined, {
629
+ "builder.request.id": turn.request.requestId,
630
+ "builder.prompt_failure.path": "cancel_during_setup",
631
+ }));
454
632
  await turn.completion;
455
633
  await this.settle(turn, turn.controller.signal.reason);
456
634
  }
635
+ /**
636
+ * A stopped turn's calls that never reported a result read as interrupted,
637
+ * not as done. The id matches the session-restart reconcile's row.
638
+ */
639
+ async interruptOpenCalls(turn) {
640
+ for (const [toolCallId, toolName] of turn.calls) {
641
+ if (turn.results.has(toolCallId))
642
+ continue;
643
+ turn.results.add(toolCallId);
644
+ await this.publish({
645
+ role: "assistant",
646
+ type: "tool-error",
647
+ id: `interrupted-${toolCallId}`,
648
+ toolCallId,
649
+ toolName,
650
+ error: "Stopped before this step reported a result.",
651
+ errorCode: AiToolExecutionErrorCode.INTERRUPTED,
652
+ content: "",
653
+ }).catch((error) => this.deps.onError?.(error));
654
+ }
655
+ }
457
656
  async settle(turn, failure, paywallReason) {
458
657
  if (turn.settled)
459
658
  return;
460
659
  turn.settled = true;
461
660
  const cancelled = turn.stopped === true;
462
- const error = failure === undefined ? turn.controller.signal.reason : failure;
661
+ let error = failure === undefined ? turn.controller.signal.reason : failure;
662
+ // A worker row the turn could not close fails the turn, as a transcript
663
+ // that could not be saved does; it is reported, not rethrown, because
664
+ // the turn still has to end.
665
+ try {
666
+ await turn.subagents.failRunning();
667
+ }
668
+ catch (cleanupError) {
669
+ error ??= cleanupError;
670
+ this.deps.onError?.(cleanupError);
671
+ }
463
672
  const failed = error !== undefined;
464
673
  if (turn.retryScheduled)
465
674
  this.retryOutcomes.add(1, {
@@ -469,14 +678,22 @@ export class BuilderConversation {
469
678
  ? "failed"
470
679
  : "recovered",
471
680
  });
472
- await turn.subagents.failRunning();
473
- if (this.turn === turn) {
474
- this.turn = undefined;
475
- await this.publishState(failed || cancelled
476
- ? AiGenerationState.CANCELLED
477
- : AiGenerationState.COMPLETED, turn.id, failed && !cancelled && !paywallReason, paywallReason);
681
+ try {
682
+ if (this.turn === turn) {
683
+ this.turn = undefined;
684
+ // COMPLETED means the turn changed the app, as it does for Clark,
685
+ // whose turns without a draft end IDLE. The editor plays its
686
+ // completion sound on it.
687
+ await this.publishState(failed || cancelled
688
+ ? AiGenerationState.CANCELLED
689
+ : turn.checkpointed
690
+ ? AiGenerationState.COMPLETED
691
+ : AiGenerationState.IDLE, turn.id, failed && !cancelled && !paywallReason, paywallReason);
692
+ }
693
+ }
694
+ finally {
695
+ this.deps.onSettled(turn.id, error, cancelled, paywallReason);
478
696
  }
479
- this.deps.onSettled(turn.id, error, cancelled);
480
697
  }
481
698
  waitForCompletion() {
482
699
  return this.completion;
@@ -494,18 +711,42 @@ export class BuilderConversation {
494
711
  };
495
712
  await this.push(() => this.deps.peer.call.aiSetGenerationState(this.snapshot));
496
713
  }
497
- async requestPermission(request) {
714
+ async requestPermission(request, signal) {
498
715
  const turn = this.turn;
499
716
  if (!turn || turn.controller.signal.aborted)
500
717
  throw new DOMException("Builder turn ended", "AbortError");
718
+ signal?.throwIfAborted();
719
+ if (turn.userWaitExpired)
720
+ throw this.refuseAfterExpiry(turn, "permission", request.toolCallId);
501
721
  if (this.pendingPermission)
502
722
  throw new Error("A tool permission request is already pending");
503
723
  const result = new Promise((resolve, reject) => {
504
724
  this.pendingPermission = { request, resolve, reject };
505
725
  });
506
726
  void result.catch(() => { });
727
+ this.timeUserWait("permission", true, result, (approved) => approved ? "approved" : "denied");
728
+ const startedAt = performance.now();
729
+ this.expireAfter(result, () => this.expirePermission(turn, request, startedAt));
730
+ if (signal) {
731
+ // The call was cancelled, as by the runtime: take the card down with it.
732
+ const withdraw = () => void this.withdrawPermission(turn, request, signal.reason).catch((error) => this.deps.onError?.(error));
733
+ signal.addEventListener("abort", withdraw, { once: true });
734
+ void result
735
+ .finally(() => signal.removeEventListener("abort", withdraw))
736
+ .catch(() => { });
737
+ }
738
+ // The call can give up while these run; a withdrawn card stays down.
739
+ const withdrawn = () => this.pendingPermission?.request !== request;
507
740
  await this.flushText(turn);
741
+ if (withdrawn())
742
+ return result;
508
743
  await this.publishState(AiGenerationState.AWAITING_USER_INPUT, turn.id);
744
+ if (withdrawn()) {
745
+ // The withdrawal's GENERATING may have landed before this update.
746
+ if (this.generatingAgain(turn))
747
+ await this.publishState(AiGenerationState.GENERATING, turn.id).catch(() => { });
748
+ return result;
749
+ }
509
750
  await this.deliverPermission(request);
510
751
  return result;
511
752
  }
@@ -513,6 +754,16 @@ export class BuilderConversation {
513
754
  if (response.requestId && this.requests.has(response.requestId))
514
755
  return;
515
756
  const pending = this.pendingPermission;
757
+ if (pending?.request.toolCallId !== response.messageId &&
758
+ this.expiredPermissions.has(response.messageId)) {
759
+ getLogger().info("[builder-conversation] Ignored an answer to a permission request withdrawn unanswered", {
760
+ conversationId: this.turn?.conversationId,
761
+ turnId: this.turn?.id,
762
+ toolCallId: response.messageId,
763
+ approved: response.approved,
764
+ });
765
+ return;
766
+ }
516
767
  if (!pending || pending.request.toolCallId !== response.messageId)
517
768
  throw new Error("No matching pending tool permission");
518
769
  if (!this.turn || this.turn.controller.signal.aborted)
@@ -538,7 +789,14 @@ export class BuilderConversation {
538
789
  await this.push(() => this.deps.peer.call.aiClearToolPermission());
539
790
  if (this.pendingQuestion)
540
791
  await this.push(() => this.deps.peer.call.aiPushMessage(this.pendingQuestion.message));
792
+ // History does not have these yet, so the reconnected browser gets them in
793
+ // order; a copy, since the reply can turn final and record them meanwhile.
794
+ for (const record of [...(this.turn?.unrecorded ?? [])])
795
+ await this.push(() => this.deps.peer.call.aiPushMessage(record));
541
796
  const text = this.turn?.text;
797
+ // The full text below already carries what was still waiting to go out.
798
+ if (this.turn)
799
+ this.turn.unsent = undefined;
542
800
  if (text)
543
801
  await this.push(() => this.deps.peer.call.aiPushMessage({
544
802
  id: text.id,
@@ -555,7 +813,93 @@ export class BuilderConversation {
555
813
  return;
556
814
  await this.push(() => this.deps.peer.call.aiPushContextUsed(snapshot));
557
815
  }
558
- async askUser(turn, message, signal) {
816
+ get userWaitLimitMs() {
817
+ return this.deps.userWaitLimitMs ?? BuilderConversation.USER_WAIT_LIMIT_MS;
818
+ }
819
+ /** Records how long a wait on the user lasted and how it ended, once it settles. */
820
+ timeUserWait(kind, expires, result, outcome) {
821
+ const startedAt = performance.now();
822
+ const record = (ended) => this.userWaits.record((performance.now() - startedAt) / 1000, {
823
+ "wait.kind": kind,
824
+ "wait.expires": expires,
825
+ "wait.outcome": ended,
826
+ });
827
+ result.then((value) => record(outcome(value)), (error) => record(error instanceof UserWaitExpiredError ? "expired" : "ended"));
828
+ }
829
+ /** Runs `withdraw` if `result` has not settled within the wait limit. */
830
+ expireAfter(result, withdraw) {
831
+ const timer = setTimeout(() => {
832
+ withdraw().catch((error) => this.deps.onError?.(error));
833
+ }, this.userWaitLimitMs);
834
+ timer.unref?.();
835
+ const clear = () => clearTimeout(timer);
836
+ result.then(clear, clear);
837
+ }
838
+ /** The error for a wait refused, unshown, because an earlier one in the turn went unanswered. */
839
+ refuseAfterExpiry(turn, kind, id) {
840
+ getLogger().info(`[builder-conversation] Refused a ${kind} without showing it because an earlier one in the turn went unanswered`, { conversationId: turn.conversationId, turnId: turn.id, id });
841
+ return new UserWaitExpiredError(this.userWaitLimitMs, { shown: false });
842
+ }
843
+ logExpiry(turn, kind, id, startedAt) {
844
+ getLogger().info(`[builder-conversation] Withdrew a ${kind} the user did not answer in time`, {
845
+ conversationId: turn.conversationId,
846
+ turnId: turn.id,
847
+ id,
848
+ waitedMs: Math.round(performance.now() - startedAt),
849
+ });
850
+ }
851
+ async expirePermission(turn, request, startedAt) {
852
+ const pending = this.pendingPermission;
853
+ if (pending?.request !== request || pending.responding)
854
+ return;
855
+ turn.userWaitExpired = true;
856
+ this.logExpiry(turn, "permission", request.toolCallId, startedAt);
857
+ await this.withdrawPermission(turn, request, new UserWaitExpiredError(this.userWaitLimitMs));
858
+ }
859
+ /** Takes an unanswered permission card down; a late answer to it is ignored. */
860
+ async withdrawPermission(turn, request, reason) {
861
+ const pending = this.pendingPermission;
862
+ if (pending?.request !== request || pending.responding)
863
+ return;
864
+ this.pendingPermission = undefined;
865
+ this.expiredPermissions.add(request.toolCallId);
866
+ if (this.expiredPermissions.size > BuilderConversation.MAX_EXPIRED_PERMISSIONS) {
867
+ const [oldest] = this.expiredPermissions;
868
+ if (oldest !== undefined)
869
+ this.expiredPermissions.delete(oldest);
870
+ }
871
+ try {
872
+ await this.push(() => this.deps.peer.call.aiClearToolPermission());
873
+ if (this.generatingAgain(turn))
874
+ await this.publishState(AiGenerationState.GENERATING, turn.id);
875
+ }
876
+ finally {
877
+ pending.reject(reason);
878
+ }
879
+ }
880
+ /** Whether the turn may go back to GENERATING: still live, with nothing awaiting the user. */
881
+ generatingAgain(turn) {
882
+ return (this.turn === turn &&
883
+ !turn.controller.signal.aborted &&
884
+ !this.pendingPermission &&
885
+ !this.pendingQuestion);
886
+ }
887
+ async expireQuestion(turn, message, startedAt) {
888
+ const pending = this.pendingQuestion;
889
+ if (pending?.message !== message || pending.responding)
890
+ return;
891
+ this.pendingQuestion = undefined;
892
+ turn.userWaitExpired = true;
893
+ this.logExpiry(turn, "question", message.id, startedAt);
894
+ try {
895
+ if (this.turn === turn && !turn.controller.signal.aborted)
896
+ await this.publishState(AiGenerationState.GENERATING, turn.id);
897
+ }
898
+ finally {
899
+ pending.reject(new UserWaitExpiredError(this.userWaitLimitMs));
900
+ }
901
+ }
902
+ async askUser(turn, message, signal, options = {}) {
559
903
  // The check and the pendingQuestion assignment below are separated by
560
904
  // awaits. That is safe only because every tool that can ask (the
561
905
  // integration setup banner tools and __runtime_user_input) runs through
@@ -563,6 +907,8 @@ export class BuilderConversation {
563
907
  // questions race here.
564
908
  if (this.pendingQuestion)
565
909
  throw new AnotherQuestionPendingError();
910
+ if (options.expire && turn.userWaitExpired)
911
+ throw this.refuseAfterExpiry(turn, "question", message.id);
566
912
  await turn.events;
567
913
  signal.throwIfAborted();
568
914
  await this.flushText(turn);
@@ -571,6 +917,10 @@ export class BuilderConversation {
571
917
  this.pendingQuestion = { message, resolve, reject };
572
918
  });
573
919
  void result.catch(() => { });
920
+ this.timeUserWait("question", options.expire === true, result, () => "answered");
921
+ const startedAt = performance.now();
922
+ if (options.expire)
923
+ this.expireAfter(result, () => this.expireQuestion(turn, message, startedAt));
574
924
  await this.publishState(AiGenerationState.AWAITING_USER_INPUT, turn.id);
575
925
  signal.throwIfAborted();
576
926
  await this.publish(message);
@@ -579,19 +929,22 @@ export class BuilderConversation {
579
929
  async event(turn, event) {
580
930
  switch (event.type) {
581
931
  case "callback-ready":
582
- await this.flushText(turn);
932
+ await this.endText(turn);
583
933
  turn.callbacks.arrive(event.id);
584
934
  break;
585
935
  case "text-delta": {
936
+ if (event.discard) {
937
+ await this.discardText(turn, event.discard);
938
+ break;
939
+ }
586
940
  turn.text ??= { id: randomUUID(), value: "" };
587
941
  turn.text.value += event.text;
588
- await this.push(() => this.deps.peer.call.aiPushMessage({
589
- id: randomUUID(),
590
- role: "assistant",
591
- type: "text-delta",
592
- textBlockId: turn.text.id,
593
- content: event.text,
594
- }));
942
+ turn.unsent ??= { id: turn.text.id, value: "" };
943
+ turn.unsent.value += event.text;
944
+ // Not awaited: later deltas join `unsent` while this push is in flight.
945
+ turn.sending ??= this.sendText(turn).finally(() => {
946
+ turn.sending = undefined;
947
+ });
595
948
  break;
596
949
  }
597
950
  case "plan":
@@ -615,8 +968,12 @@ export class BuilderConversation {
615
968
  await turn.subagents.track(event.toolCallId, event.input);
616
969
  return;
617
970
  }
618
- turn.calls.add(event.toolCallId);
619
- await this.flushText(turn);
971
+ turn.calls.set(event.toolCallId, event.toolName);
972
+ // The root reaches its own tool call only after its reply message is complete.
973
+ if (event.parentToolCallId)
974
+ await this.endText(turn);
975
+ else
976
+ await this.flushText(turn);
620
977
  if (BuilderSubagents.reports(event.toolName))
621
978
  await turn.subagents.track(event.toolCallId, event.input);
622
979
  await this.publish({
@@ -630,13 +987,13 @@ export class BuilderConversation {
630
987
  }),
631
988
  content: "",
632
989
  id: event.toolCallId,
633
- });
990
+ }, turn);
634
991
  break;
635
992
  case "tool-result":
636
993
  if (turn.results.has(event.toolCallId))
637
994
  return;
638
995
  turn.results.add(event.toolCallId);
639
- await this.flushText(turn);
996
+ await this.endText(turn);
640
997
  if (BuilderSubagents.reports(event.toolName))
641
998
  await turn.subagents.finish(event.toolCallId, event.output, event.isError === true);
642
999
  await this.publish(event.isError
@@ -655,7 +1012,7 @@ export class BuilderConversation {
655
1012
  toolName: event.toolName,
656
1013
  output: event.output,
657
1014
  content: "",
658
- });
1015
+ }, turn);
659
1016
  break;
660
1017
  case "finish":
661
1018
  if (turn.usageRecorded)
@@ -698,18 +1055,95 @@ export class BuilderConversation {
698
1055
  break;
699
1056
  }
700
1057
  }
701
- async flushText(turn) {
702
- const text = turn.text;
703
- if (!text)
1058
+ /** Pushes `unsent` text until none is left, one push in flight at a time. */
1059
+ async sendText(turn) {
1060
+ // No abort check: text handled before a cancel still belongs in the
1061
+ // sidebar, and once the turn is aborted push() no longer waits for the
1062
+ // browser, so the remainder goes out at once.
1063
+ while (turn.unsent) {
1064
+ const { id, value } = turn.unsent;
1065
+ turn.unsent = undefined;
1066
+ await this.push(() => this.deps.peer.call.aiPushMessage({
1067
+ id: randomUUID(),
1068
+ role: "assistant",
1069
+ type: "text-delta",
1070
+ textBlockId: id,
1071
+ content: value,
1072
+ }));
1073
+ }
1074
+ }
1075
+ /**
1076
+ * Hides the last `length` characters of reply text, which the harness
1077
+ * abandoned when it retried, as the AI SDK path does. The browser hides
1078
+ * whole blocks, so the earlier text of the oldest block reached is sent
1079
+ * again as a new one.
1080
+ */
1081
+ async discardText(turn, length) {
1082
+ await this.holdText(turn);
1083
+ const discarded = [];
1084
+ let kept = "";
1085
+ let remaining = length;
1086
+ for (let index = turn.unrecorded.length - 1; index >= 0 && remaining > 0; index--) {
1087
+ const record = turn.unrecorded[index];
1088
+ if (record?.type !== "text")
1089
+ continue;
1090
+ turn.unrecorded.splice(index, 1);
1091
+ discarded.unshift(record.id ?? "");
1092
+ kept = record.content.slice(0, Math.max(0, record.content.length - remaining));
1093
+ remaining -= record.content.length;
1094
+ }
1095
+ if (discarded.length === 0)
704
1096
  return;
1097
+ // Before the notice: any message after it marks the retry succeeded.
1098
+ if (kept) {
1099
+ await this.event(turn, { type: "text-delta", text: kept });
1100
+ await this.holdText(turn);
1101
+ }
1102
+ await this.publish({
1103
+ role: "system",
1104
+ type: "retry_notification",
1105
+ content: "",
1106
+ retryType: "same_provider",
1107
+ streamId: turn.id,
1108
+ discardedTextBlockIds: discarded,
1109
+ }, turn);
1110
+ }
1111
+ /** Ends the current text block without recording it, since a retry may still abandon it. */
1112
+ async holdText(turn) {
1113
+ // Streamed text reaches the browser before whatever follows it.
1114
+ await turn.sending;
1115
+ const text = turn.text;
705
1116
  turn.text = undefined;
706
- await this.deps.chat.recordAssistant({
707
- id: text.id,
708
- role: "assistant",
709
- type: "text",
710
- textBlockId: text.id,
711
- content: text.value,
712
- });
1117
+ if (text)
1118
+ turn.unrecorded.push({
1119
+ id: text.id,
1120
+ role: "assistant",
1121
+ type: "text",
1122
+ textBlockId: text.id,
1123
+ content: text.value,
1124
+ });
1125
+ }
1126
+ /**
1127
+ * Ends the current text block. Only Codex can abandon reply text on a
1128
+ * retry, so another harness's text is recorded at once.
1129
+ */
1130
+ async endText(turn) {
1131
+ if (this.deps.runtime.harness === "codex")
1132
+ await this.holdText(turn);
1133
+ else
1134
+ await this.flushText(turn);
1135
+ }
1136
+ /** Ends the current text block and records every held row in order, now that the reply is final. */
1137
+ async flushText(turn) {
1138
+ await this.holdText(turn);
1139
+ // One failed write must not cost the rows after it their place in history.
1140
+ let failure;
1141
+ for (const record of turn.unrecorded.splice(0))
1142
+ await this.deps.chat.recordAssistant(record).catch((error) => {
1143
+ failure ??= { error };
1144
+ });
1145
+ if (failure)
1146
+ throw failure.error;
713
1147
  }
714
1148
  toolError(output) {
715
1149
  const parsed = toolErrorOutputSchema.safeParse(output);
@@ -725,13 +1159,18 @@ export class BuilderConversation {
725
1159
  const suffix = fileName ? ` (${fileName.slice(0, 256)})` : "";
726
1160
  return (getToolErrorMessage(message).slice(0, 4_000 - suffix.length) + suffix).toWellFormed();
727
1161
  }
728
- async publish(message) {
1162
+ async publish(message, turn) {
729
1163
  const payload = {
730
1164
  ...message,
731
1165
  id: message.id ?? randomUUID(),
732
1166
  timestamp: message.timestamp ?? Date.now(),
733
1167
  };
734
- await this.deps.chat.recordAssistant(payload);
1168
+ // A row after held reply text waits for it, so history keeps the browser's order.
1169
+ const unrecorded = turn?.unrecorded;
1170
+ if (unrecorded?.length)
1171
+ unrecorded.push(payload);
1172
+ else
1173
+ await this.deps.chat.recordAssistant(payload);
735
1174
  await this.push(() => this.deps.peer.call.aiPushMessage(payload));
736
1175
  }
737
1176
  userAttachments(request) {
@@ -817,35 +1256,52 @@ export class BuilderConversation {
817
1256
  "item/commandExecution/requestApproval",
818
1257
  "item/fileChange/requestApproval",
819
1258
  ]),
820
- params: z.record(z.unknown()),
1259
+ params: z.record(z.string(), z.unknown()),
821
1260
  }),
822
1261
  execute: async ({ method, params }, options) => {
823
1262
  if (request.mode === AiMode.PLAN)
824
1263
  return { decision: "decline" };
825
- const approved = await this.requestPermission({
826
- toolCallId: options.toolCallId,
827
- toolName: method === "item/fileChange/requestApproval"
828
- ? "apply_patch"
829
- : typeof params.toolName === "string"
830
- ? params.toolName
831
- : "exec_command",
832
- input: params,
833
- formattedInput: {
834
- targets: [
835
- typeof params.command === "string"
836
- ? params.command
837
- : "Native builder action",
838
- ],
839
- },
840
- permissions: [],
841
- });
1264
+ let approved;
1265
+ try {
1266
+ approved = await this.requestPermission({
1267
+ toolCallId: options.toolCallId,
1268
+ toolName: method === "item/fileChange/requestApproval"
1269
+ ? "apply_patch"
1270
+ : typeof params.toolName === "string"
1271
+ ? params.toolName
1272
+ : "exec_command",
1273
+ input: params,
1274
+ formattedInput: {
1275
+ targets: [
1276
+ typeof params.command === "string"
1277
+ ? params.command
1278
+ : "Native builder action",
1279
+ ],
1280
+ },
1281
+ permissions: [],
1282
+ }, options.abortSignal);
1283
+ }
1284
+ catch (error) {
1285
+ if (!(error instanceof UserWaitExpiredError))
1286
+ throw error;
1287
+ // Codex approvals carry no reason; a decline lets the turn go on
1288
+ // where cancel would end it.
1289
+ getLogger().info("[builder-conversation] Declined a Codex approval the user did not answer", {
1290
+ conversationId: this.turn?.conversationId,
1291
+ turnId: this.turn?.id,
1292
+ toolCallId: options.toolCallId,
1293
+ method,
1294
+ shown: error.shown,
1295
+ });
1296
+ return { decision: "decline" };
1297
+ }
842
1298
  return { decision: approved ? "accept" : "decline" };
843
1299
  },
844
1300
  },
845
1301
  __runtime_user_input: {
846
1302
  inputSchema: z.object({
847
1303
  method: z.enum(["item/tool/requestUserInput"]),
848
- afterEventId: z.string().uuid().optional(),
1304
+ afterEventId: z.guid().optional(),
849
1305
  params: z
850
1306
  .object({
851
1307
  questions: z
@@ -898,7 +1354,14 @@ export class BuilderConversation {
898
1354
  const signal = this.turn?.controller.signal;
899
1355
  const sent = Promise.resolve()
900
1356
  .then(send)
901
- .catch((error) => this.deps.onError?.(error));
1357
+ .catch((error) => {
1358
+ // A dropped editor connection is not a builder failure, and replay()
1359
+ // restores the chat once the editor is back. Clark logs it the same way.
1360
+ if (isPeerUnavailableError(error))
1361
+ getLogger().info("[builder-conversation] Push dropped because the editor peer disconnected or was replaced", getErrorMeta(error));
1362
+ else
1363
+ this.deps.onError?.(error);
1364
+ });
902
1365
  if (!signal || signal.aborted) {
903
1366
  void sent;
904
1367
  return;
@@ -920,4 +1383,7 @@ export class BuilderConversation {
920
1383
  }
921
1384
  }
922
1385
  }
1386
+ function toError(error) {
1387
+ return error instanceof Error ? error : new Error(String(error));
1388
+ }
923
1389
  //# sourceMappingURL=builder-conversation.js.map