@sentry/junior 0.313.0 → 0.315.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 (652) hide show
  1. package/dist/{channel-access-mt7K6dPh.js → adapter-context-BlSGE44V.js} +46 -7
  2. package/dist/{admin-Cyhb4TwZ.js → admin-5jUYY46p.js} +1 -1
  3. package/dist/agent-runner-C7GNLRB6.js +23438 -0
  4. package/dist/agent-update-delivery-BNEYQsAf.js +149 -0
  5. package/dist/api/schema.d.ts +9500 -2
  6. package/dist/api/schema.js +5 -7
  7. package/dist/api.d.ts +2 -3
  8. package/dist/api.js +1172 -371
  9. package/dist/{app-DA8-hCMj.d.ts → app-D_bAXRDe.d.ts} +312 -48
  10. package/dist/app.d.ts +2 -2
  11. package/dist/app.js +305 -184
  12. package/dist/change-record-Bqsa5ZXE.d.ts +175 -0
  13. package/dist/chat-core-engine-CxkwRpn9.js +123 -0
  14. package/dist/child-message--2G3Ft26.js +19 -0
  15. package/dist/cli/chat.d.ts +4 -1
  16. package/dist/cli/chat.js +40 -25
  17. package/dist/cli/check.js +4 -4
  18. package/dist/cli/main.js +2 -2
  19. package/dist/cli/plugins.js +4 -5
  20. package/dist/cli/run.d.ts +1 -1
  21. package/dist/cli/run.js +1 -1
  22. package/dist/cli/snapshot-create.js +2 -5
  23. package/dist/cli/upgrade.d.ts +1 -1
  24. package/dist/cli/upgrade.js +68 -97
  25. package/dist/{continue-in-slack-CxyFzdlF.js → continue-in-slack-BGKjIdFp.js} +3 -7
  26. package/dist/{conversation-feed-BEXLD3Me.js → conversation-feed-Sl8lKKmR.js} +22 -2
  27. package/dist/{conversation-turn-B35eu0uz.js → conversation-turn-BoLK9i6g.js} +514 -83
  28. package/dist/create-BOycVH9h.js +213 -0
  29. package/dist/{credential-sync-DWTOEQrm.js → credential-sync-Mn4OdkEh.js} +10 -18
  30. package/dist/db-BpxcYXfD.d.ts +2 -0
  31. package/dist/{credentialed-Dyv8b-lu.js → db-DXTOYRzR.js} +22220 -9334
  32. package/dist/deployment-CG3TchWh.js +51 -0
  33. package/dist/direct-url-BYgYfuIy.js +22 -0
  34. package/dist/engine-context-dyWlfNdD.js +1817 -0
  35. package/dist/{html-DidUcRhI.js → html-CfXEwl_h.js} +2 -7
  36. package/dist/instrumentation.js +3 -3
  37. package/dist/job-runner-CySgpi9v.js +1131 -0
  38. package/dist/{lineage-BXplQAVH.js → lineage-tRTOcrsL.js} +1 -2
  39. package/dist/{list-DyIyReSV.js → list-DXBz8SYL.js} +610 -173
  40. package/dist/local-server-CpnGhYml.js +276 -0
  41. package/dist/{logging-DNt-qOIO.js → logging-czs0nqLC.js} +2 -45
  42. package/dist/{turn-membership-DTR3SaKD.js → mailbox-turn-79Nv1JXv.js} +4153 -559
  43. package/dist/markers-CE0HMXWT.js +67 -0
  44. package/dist/{media-B0pZJ0bG.js → media-Cr9pGkzr.js} +701 -41
  45. package/dist/{message-Z5YKC-Af.js → message-BTox2Cmb.js} +25 -36
  46. package/dist/{model-input-BhPJYdSV.js → model-input-IRGa98V7.js} +3 -3
  47. package/dist/nitro.d.ts +8 -4
  48. package/dist/nitro.js +106 -24
  49. package/dist/{oauth-callback-server-ByvDdcdY.js → oauth-callback-server-NXK7AlBp.js} +2 -2
  50. package/dist/{oauth-relay-D-kK0yoN.js → oauth-relay-6NBPSpFE.js} +1 -1
  51. package/dist/{package-discovery-DD9vencX.js → package-discovery-BI6T_RkD.js} +50 -1
  52. package/dist/parent-result-Dg6P6roR.js +323 -0
  53. package/dist/people-Cegp1Iwq.js +81 -0
  54. package/dist/{plugins-Bkk0XRo2.js → plugins-BXMdNdyA.js} +1 -1
  55. package/dist/{conversation-privacy-BrMiDN61.js → proxy-path-Dc-0jXGi.js} +16 -2
  56. package/dist/{resolve-CWtBNSKP.js → resolve-BUFkmxkT.js} +229 -4
  57. package/dist/result-DfATzX77.js +337 -0
  58. package/dist/{runner-CsZ_VRxp.js → runner-CmKP3inb.js} +7 -8
  59. package/dist/{sandbox-egress-signals-FbCk1FkN.js → sandbox-egress-signals-DYo5BsM7.js} +1 -1
  60. package/dist/{schema-DojR2uCL.js → schema-DrBMdPmv.js} +197 -20
  61. package/dist/{service-account-CDYb9hfX.js → service-account-CxTX7nnR.js} +4 -5
  62. package/dist/{skills-B0jP4whm.js → skills-BlHUDj7k.js} +4 -4
  63. package/dist/{slack-conversation-unfurl-D26t9kBC.js → slack-conversation-unfurl-Dhe3lB1U.js} +6 -10
  64. package/dist/{spawn-BjljgExZ.js → spawn-CfvlFdfz.js} +8 -17
  65. package/dist/start-conversation-Uh8Sk1EF.js +162 -0
  66. package/dist/system-prompt-table-CDCYVwqN.js +1169 -0
  67. package/dist/{task-runner--Ke8KSMf.js → task-runner-DcdQJd9e.js} +163 -55
  68. package/dist/{thread-context-B8exINEe.js → thread-context-DF5uDcWN.js} +7 -9
  69. package/dist/topic-CRYYBYp-.js +7 -0
  70. package/dist/transcript-BHhJVY0P.js +410 -0
  71. package/dist/turn-session-routing-GtetHsdO.js +1309 -0
  72. package/dist/turn-wake-um5Ubd4m.js +152 -0
  73. package/dist/user-customization-B27StpVQ.js +9 -0
  74. package/dist/{validation-Ce0qbMlT.js → validation-CJyuOPD2.js} +1 -1
  75. package/dist/{version-DFh4n9nr.js → version-Bhe7RPIe.js} +1 -1
  76. package/dist/version.js +1 -1
  77. package/dist/virtual-module-BeKA_EII.js +12 -0
  78. package/dist/{worker-CDg9Lbpg.js → worker-D8PRgUqr.js} +3 -6
  79. package/migrations/20260711145847_initial/snapshot.json +2103 -0
  80. package/migrations/20260711145900_conversation_metrics/snapshot.json +135 -0
  81. package/migrations/20260712153649_conversation_message_search/snapshot.json +50 -0
  82. package/migrations/20260713040256_peaceful_scalphunter/snapshot.json +42 -0
  83. package/migrations/20260715174202_useful_magus/snapshot.json +42 -0
  84. package/migrations/20260715174203_conversation_events/snapshot.json +539 -0
  85. package/migrations/20260723042835_drop_legacy_conversation_messages/snapshot.json +9 -0
  86. package/migrations/20260723050612_thick_sugar_man/snapshot.json +120 -0
  87. package/migrations/20260727223822_sticky_rage/snapshot.json +274 -0
  88. package/migrations/20260728033158_slippery_harrier/snapshot.json +191 -0
  89. package/migrations/20260728040836_native_conversation_history/snapshot.json +9 -0
  90. package/migrations/20260728204900_sour_golden_guardian/snapshot.json +124 -0
  91. package/migrations/20260730233332_structured_conversation_events/snapshot.json +9 -0
  92. package/migrations/20260731164038_conversation_session_source/snapshot.json +42 -0
  93. package/migrations/20260801230336_source_visibility/snapshot.json +9 -0
  94. package/migrations/20260802023731_magical_ezekiel_stane/snapshot.json +266 -0
  95. package/migrations/20260804015843_neat_the_anarchist/snapshot.json +714 -0
  96. package/migrations/20260804165952_drop_paused_scheduled_tasks/snapshot.json +9 -0
  97. package/migrations/20260804225613_curvy_excalibur/snapshot.json +223 -0
  98. package/migrations/20260805174033_lowly_valkyrie/snapshot.json +344 -0
  99. package/migrations/20260805200301_restrict_task_execution_kinds/snapshot.json +36 -0
  100. package/migrations/20260806030729_first_warhawk/snapshot.json +690 -0
  101. package/migrations/20260807185200_task_execution_status/snapshot.json +92 -0
  102. package/migrations/20260808014743_task_title_columns/snapshot.json +68 -0
  103. package/migrations/20260809220421_misty_typhoid_mary/snapshot.json +191 -0
  104. package/migrations/20260811193709_mcp_credential_subject/snapshot.json +9 -0
  105. package/migrations/20260812032924_conversation_event_actor_and_participants/snapshot.json +393 -0
  106. package/migrations/20260812172418_attachment_storage/snapshot.json +341 -0
  107. package/migrations/20260813230732_artifacts/snapshot.json +349 -0
  108. package/migrations/20260814062905_dizzy_barracuda/snapshot.json +342 -0
  109. package/migrations/20260814231353_drop_workspace_repo_primary/snapshot.json +55 -0
  110. package/migrations/20260815030100_wild_phantom_reporter/snapshot.json +135 -0
  111. package/migrations/20260817082233_workspace_snapshots_table/snapshot.json +625 -0
  112. package/migrations/20260818160339_workspace_snapshot_active_build/snapshot.json +62 -0
  113. package/migrations/20260821180755_strong_randall/snapshot.json +42 -0
  114. package/migrations/20260823030308_workspace_snapshot_size_bytes/snapshot.json +62 -0
  115. package/migrations/20260824190313_complex_rage/snapshot.json +690 -0
  116. package/migrations/20260827233711_conversation_location/snapshot.json +42 -0
  117. package/migrations/20260901224306_event_task_status/snapshot.json +100 -0
  118. package/migrations/20260904153232_attachment_provider/snapshot.json +234 -0
  119. package/migrations/20260909111415_conversation_briefs/snapshot.json +364 -0
  120. package/migrations/20260910144928_automation_outcomes_backfill/snapshot.json +9 -0
  121. package/migrations/20260911184346_conversation_metrics/snapshot.json +226 -0
  122. package/migrations/20260921140842_scheduled_automation_channel_destinations/snapshot.json +9 -0
  123. package/migrations/20260922221709_event_automation_channel_destinations/snapshot.json +9 -0
  124. package/migrations/20261001113455_conversation_forks/snapshot.json +120 -0
  125. package/migrations/20261005161844_automation_versions/snapshot.json +150 -0
  126. package/migrations/20261006152043_user_timezone/snapshot.json +37 -0
  127. package/migrations/20261008200858_user_admin/snapshot.json +37 -0
  128. package/migrations/20261009145407_event_automation_status_reason/snapshot.json +42 -0
  129. package/migrations/20261013160816_agent_invocation_parent_mailbox/snapshot.json +93 -0
  130. package/migrations/20261013215020_agent_invocation_parent_tool_call/snapshot.json +42 -0
  131. package/migrations/20261014011138_agent_invocation_title/snapshot.json +42 -0
  132. package/migrations/20261014211942_conversation_stopped_at/snapshot.json +42 -0
  133. package/migrations/20261015012820_flowery_rage/snapshot.json +42 -0
  134. package/migrations/20261017000924_automations/snapshot.json +790 -0
  135. package/migrations/20261017134736_automation_runs/snapshot.json +474 -0
  136. package/migrations/20261017170250_drop_legacy_automation_tables/snapshot.json +397 -0
  137. package/migrations/20261018134754_automation_creator_identity/snapshot.json +130 -0
  138. package/migrations/20261023071954_automation_run_version/snapshot.json +79 -0
  139. package/migrations/20261025233137_identity_signed_in_at/snapshot.json +42 -0
  140. package/migrations/20261027234315_workspace_vcpus/snapshot.json +37 -0
  141. package/migrations/20261028124242_plugin_report_index/snapshot.json +68 -0
  142. package/migrations/20261028154230_agent_invocation_type/snapshot.json +42 -0
  143. package/migrations/20261030021803_any_resource_event_triggers/snapshot.json +42 -0
  144. package/migrations/20261030234309_user_customization/snapshot.json +37 -0
  145. package/migrations/20261031020656_review_items/snapshot.json +1078 -0
  146. package/migrations/20261031024151_review_item_dedupe_tenant/snapshot.json +62 -0
  147. package/migrations/20261031024246_review_item_slack_cards/snapshot.json +159 -0
  148. package/migrations/20261031155308_system_identity/snapshot.json +9 -0
  149. package/migrations/20261101193952_review_item_foreign_keys/snapshot.json +108 -0
  150. package/migrations/20261102172751_review_item_turn/snapshot.json +42 -0
  151. package/migrations/20261102221411_conversation_read_positions/snapshot.json +190 -0
  152. package/migrations/20261104085028_conversation_quick_question/snapshot.json +42 -0
  153. package/migrations/20261104145136_conversation_participant_pins/snapshot.json +42 -0
  154. package/migrations/20261104164429_conversation_detail_version/snapshot.json +42 -0
  155. package/migrations/20261104172055_conversation_auto_archive/snapshot.json +206 -0
  156. package/migrations/20261105005443_drop_agent_invocation_model_profile/snapshot.json +30 -0
  157. package/migrations/20261105043807_plugin_conversation_index/snapshot.json +76 -0
  158. package/migrations/20261105051837_conversation_event_author_index/snapshot.json +70 -0
  159. package/migrations/20261105182854_conversation_event_latest_message_indexes/snapshot.json +136 -0
  160. package/migrations/20261106011443_conversation_pin_position/snapshot.json +42 -0
  161. package/migrations/20261106095004_push_notifications/snapshot.json +308 -0
  162. package/migrations/20261106162740_conversation_kind/snapshot.json +88 -0
  163. package/migrations/20261107002001_read_position_backfill/snapshot.json +9 -0
  164. package/migrations/20261107025209_child_archived_at/snapshot.json +42 -0
  165. package/migrations/20261107035735_shared_archive/snapshot.json +67 -0
  166. package/migrations/20261107215055_child_location/snapshot.json +9 -0
  167. package/migrations/20261108191927_conversation_unsubscribe/snapshot.json +42 -0
  168. package/migrations/20261109021618_conversation_paused_status/snapshot.json +9 -0
  169. package/migrations/20261109111553_guardian_review_time_index/snapshot.json +54 -0
  170. package/migrations/20261109173130_conversation_participant_unsubscribed_index/snapshot.json +62 -0
  171. package/migrations/20261109182006_turn_metric_actor/snapshot.json +128 -0
  172. package/migrations/20261109202836_participant_root_actor_backfill/snapshot.json +9 -0
  173. package/migrations/20261109232640_conversation_delivery_paused_at/snapshot.json +42 -0
  174. package/migrations/20261110120937_web_linked_slack_identity_repair/snapshot.json +9 -0
  175. package/migrations/20261110175824_automation_task_kind/snapshot.json +145 -0
  176. package/migrations/20261110210242_conversation_kind_automation/snapshot.json +55 -0
  177. package/migrations/20261110222632_review_item_plugin_actions/snapshot.json +37 -0
  178. package/migrations/20261110225157_conversation_last_message_at/snapshot.json +42 -0
  179. package/migrations/20261111013351_automation_task_kind_repair/snapshot.json +9 -0
  180. package/migrations/20261111163126_drop_legacy_columns/snapshot.json +9 -0
  181. package/migrations/20261111170150_code_change_last_activity/snapshot.json +42 -0
  182. package/migrations/20261111191441_agent_invocation_fork/snapshot.json +42 -0
  183. package/migrations/20261112142841_code_change_draft/snapshot.json +37 -0
  184. package/migrations/20261112202901_attachment_uploads/snapshot.json +255 -0
  185. package/migrations/20261112220407_conversation_agent_config/snapshot.json +42 -0
  186. package/migrations/20261113081247_attachment_deferred_download/snapshot.json +52 -0
  187. package/migrations/20261113225551_conversation_embeddings/snapshot.json +203 -0
  188. package/migrations/20261114213238_user_preferences/snapshot.json +37 -0
  189. package/migrations/20261114222527_code_change_repository_state_index/snapshot.json +70 -0
  190. package/migrations/20261115172605_attachment_kinds/snapshot.json +244 -0
  191. package/migrations/20261115173004_attachment_url_fill/snapshot.json +9 -0
  192. package/migrations/20261115180216_attachment_url_index/snapshot.json +62 -0
  193. package/migrations/20261116103700_plan_items/snapshot.json +420 -0
  194. package/migrations/20261117100100_automation_creator_slack_index/snapshot.json +62 -0
  195. package/migrations/20261117132522_conversation_event_search/snapshot.json +396 -0
  196. package/migrations/20261117164007_automation_last_run/snapshot.json +108 -0
  197. package/migrations/20261117164047_automation_last_run_index/snapshot.json +54 -0
  198. package/migrations/20261117210444_money_micro_usd/snapshot.json +68 -0
  199. package/migrations/20261117210505_conversation_cost_micro_usd/snapshot.json +9 -0
  200. package/migrations/20261118081416_people_list_metric_index/snapshot.json +86 -0
  201. package/migrations/20261118095216_automation_rollout_repair/snapshot.json +9 -0
  202. package/migrations/20261118143948_cache_warming_history_reset/snapshot.json +9 -0
  203. package/migrations/20261119040651_artifact_visibility/snapshot.json +132 -0
  204. package/migrations/20261119040715_artifact_public_sha_index/snapshot.json +9 -0
  205. package/migrations/20261119052706_artifact_drop_public/snapshot.json +71 -0
  206. package/migrations/20261119053831_artifact_path/snapshot.json +114 -0
  207. package/migrations/20261119053844_artifact_path_index/snapshot.json +9 -0
  208. package/migrations/20261119091949_review_item_answered_index/snapshot.json +70 -0
  209. package/migrations/20261119100029_review_item_status_index/snapshot.json +54 -0
  210. package/migrations/20261119165607_brief_outcome_status/snapshot.json +42 -0
  211. package/migrations/20261119165622_brief_outcome_status_backfill/snapshot.json +9 -0
  212. package/migrations/20261119213716_brief_created_at_index/snapshot.json +62 -0
  213. package/migrations/20261119222456_slack_person_search_index/snapshot.json +50 -0
  214. package/migrations/20261119225522_code_change_size/snapshot.json +104 -0
  215. package/migrations/20261119232253_merge_conflict_notice_dismiss/snapshot.json +9 -0
  216. package/migrations/20261119235649_inbox_snoozes/snapshot.json +605 -0
  217. package/migrations/20261120093118_code_change_search_index/snapshot.json +89 -0
  218. package/migrations/20261120093452_review_item_owner/snapshot.json +314 -0
  219. package/migrations/20261120185654_review_item_owner_index/snapshot.json +62 -0
  220. package/migrations/20261120185754_memory_core_adoption/snapshot.json +1184 -0
  221. package/migrations/20261120185854_memory_core_indexes/snapshot.json +70 -0
  222. package/migrations/20261120235226_todos/snapshot.json +473 -0
  223. package/migrations/20261121082316_inbox_items/snapshot.json +2026 -0
  224. package/migrations/20261121175651_todo_changed_by_agent/snapshot.json +42 -0
  225. package/migrations/20261121183527_inbox_item_subject_title_parts/snapshot.json +42 -0
  226. package/migrations/20261121194143_inbox_snooze_wake_reason/snapshot.json +42 -0
  227. package/migrations/20261121222400_authorization_request_index/snapshot.json +62 -0
  228. package/migrations/20261121225908_conversation_metadata/snapshot.json +184 -0
  229. package/migrations/20261121225910_conversation_metadata_fill/snapshot.json +9 -0
  230. package/migrations/20261121225913_conversation_search_index/snapshot.json +50 -0
  231. package/migrations/20261122022900_inbox_item_legacy_automation_keys/snapshot.json +9 -0
  232. package/migrations/20261122024454_artifact_expiry/snapshot.json +37 -0
  233. package/migrations/20261122024455_artifact_permanent_sha_index/snapshot.json +62 -0
  234. package/migrations/20261122024457_artifact_drop_public_sha_index/snapshot.json +37 -0
  235. package/migrations/20261122024458_conversation_kind_lead/snapshot.json +55 -0
  236. package/migrations/20261122024459_conversation_lead_actor_index/snapshot.json +54 -0
  237. package/migrations/20261122071549_keep_legacy_archive_columns/snapshot.json +49 -0
  238. package/migrations/20261122191400_conversation_embeddings_fk_validate/snapshot.json +9 -0
  239. package/migrations/20261122204325_money_micro_usd_repair/migration.sql +99 -0
  240. package/migrations/20261122204325_money_micro_usd_repair/snapshot.json +9 -0
  241. package/migrations/20261122204326_agent_config_backfill/migration.sql +34 -0
  242. package/migrations/20261122204326_agent_config_backfill/snapshot.json +143 -0
  243. package/migrations/20261122221456_inbox_item_deliveries/migration.sql +15 -0
  244. package/migrations/20261122221456_inbox_item_deliveries/snapshot.json +301 -0
  245. package/migrations/20261123155735_pg_trgm/migration.sql +2 -0
  246. package/migrations/20261123155735_pg_trgm/snapshot.json +9 -0
  247. package/migrations/20261123155739_search_indexes/migration.sql +4 -0
  248. package/migrations/20261123155739_search_indexes/snapshot.json +167 -0
  249. package/migrations/20261123172647_drop_legacy_archive_columns/migration.sql +4 -0
  250. package/migrations/20261123172647_drop_legacy_archive_columns/snapshot.json +9 -0
  251. package/migrations/20261123192506_memory_prefix_index/migration.sql +1 -0
  252. package/migrations/20261123192506_memory_prefix_index/snapshot.json +69 -0
  253. package/migrations/20261123201740_todo_search_indexes/migration.sql +2 -0
  254. package/migrations/20261123201740_todo_search_indexes/snapshot.json +89 -0
  255. package/migrations/20261123211505_todo_inbox_items/migration.sql +4 -0
  256. package/migrations/20261123211505_todo_inbox_items/snapshot.json +38 -0
  257. package/migrations/20261123214917_drop_code_urls/migration.sql +2 -0
  258. package/migrations/20261123214917_drop_code_urls/snapshot.json +44 -0
  259. package/migrations/20261123224000_code_change_conversations_index/migration.sql +1 -0
  260. package/migrations/20261123224000_code_change_conversations_index/snapshot.json +54 -0
  261. package/migrations/20261124122023_drop_code_change_sizes/migration.sql +4 -0
  262. package/migrations/20261124122023_drop_code_change_sizes/snapshot.json +82 -0
  263. package/migrations/20261124142958_conversation_root_lookup_index/migration.sql +1 -0
  264. package/migrations/20261124142958_conversation_root_lookup_index/snapshot.json +62 -0
  265. package/migrations/20261124183352_legacy_brief_metadata_fill/migration.sql +26 -0
  266. package/migrations/20261124183352_legacy_brief_metadata_fill/snapshot.json +114 -0
  267. package/migrations/20261124202143_drizzle_v1_baseline/migration.sql +5 -0
  268. package/migrations/20261124202143_drizzle_v1_baseline/snapshot.json +2012 -0
  269. package/migrations/20261124221751_spaces/migration.sql +22 -0
  270. package/migrations/20261124221751_spaces/snapshot.json +436 -0
  271. package/migrations/20261124230319_conversation_metrics_utc_day_stats/migration.sql +11 -0
  272. package/migrations/20261124230319_conversation_metrics_utc_day_stats/snapshot.json +9 -0
  273. package/migrations/20261124234024_space_conversations/migration.sql +5 -0
  274. package/migrations/20261124234024_space_conversations/snapshot.json +103 -0
  275. package/migrations/20261124234026_space_conversations_index/migration.sql +1 -0
  276. package/migrations/20261124234026_space_conversations_index/snapshot.json +62 -0
  277. package/migrations/20261125012448_drop_lead_actor_index/migration.sql +3 -0
  278. package/migrations/20261125012448_drop_lead_actor_index/snapshot.json +36 -0
  279. package/migrations/20261125012452_space_lead_index/migration.sql +1 -0
  280. package/migrations/20261125012452_space_lead_index/snapshot.json +54 -0
  281. package/migrations/20261125043821_space_configurations/migration.sql +11 -0
  282. package/migrations/20261125043821_space_configurations/snapshot.json +194 -0
  283. package/migrations/20261125064854_agent_update_done_status/migration.sql +9 -0
  284. package/migrations/20261125064854_agent_update_done_status/snapshot.json +9 -0
  285. package/migrations/20261125073321_turn_engine_tables/migration.sql +75 -0
  286. package/migrations/20261125073321_turn_engine_tables/snapshot.json +1497 -0
  287. package/migrations/20261125073339_turn_inbox_one_source/migration.sql +5 -0
  288. package/migrations/20261125073339_turn_inbox_one_source/snapshot.json +9 -0
  289. package/migrations/20261125124506_versions_notify/migration.sql +27 -0
  290. package/migrations/20261125124506_versions_notify/snapshot.json +9 -0
  291. package/migrations/20261125140339_turn_group_key/migration.sql +14 -0
  292. package/migrations/20261125140339_turn_group_key/snapshot.json +75 -0
  293. package/migrations/20261125140343_turn_group_key_not_null/migration.sql +4 -0
  294. package/migrations/20261125140343_turn_group_key_not_null/snapshot.json +29 -0
  295. package/migrations/20261125142845_code_change_requesters/migration.sql +1 -0
  296. package/migrations/20261125142845_code_change_requesters/snapshot.json +42 -0
  297. package/migrations/20261125142846_code_change_requesters_index/migration.sql +1 -0
  298. package/migrations/20261125142846_code_change_requesters_index/snapshot.json +54 -0
  299. package/migrations/20261125143903_space_visibility/migration.sql +1 -0
  300. package/migrations/20261125143903_space_visibility/snapshot.json +37 -0
  301. package/migrations/20261125154848_merge_leaves/migration.sql +2 -0
  302. package/migrations/20261125154848_merge_leaves/snapshot.json +14 -0
  303. package/package.json +17 -25
  304. package/skills/design-automation-skill/SKILL.md +3 -4
  305. package/dist/actor-BsBdxDXQ.js +0 -208
  306. package/dist/adapter-CYAvJzZS.js +0 -259
  307. package/dist/adapter-context-CVsHoVSf.js +0 -43
  308. package/dist/agent-runner-B5y9MsT-.js +0 -11295
  309. package/dist/background-compaction-queue-iZXadLV3.js +0 -206
  310. package/dist/catalog-runtime-kkE3hvCX.js +0 -6
  311. package/dist/config-CWbwKj0j.js +0 -2331
  312. package/dist/db-DYGcXYl3.d.ts +0 -274
  313. package/dist/db-PwSRzWWn.js +0 -3607
  314. package/dist/executor-CgWyWfYz.js +0 -1858
  315. package/dist/fan-out-Cod-yEHG.js +0 -10
  316. package/dist/history-CYstOMKX.js +0 -577
  317. package/dist/ingest-B0AggUEC.js +0 -7931
  318. package/dist/install-2urLLXNt.js +0 -228
  319. package/dist/proxy-path-BHYoKZdq.js +0 -15
  320. package/dist/registry-POH4bZC4.js +0 -1686
  321. package/dist/request-deadline-BUiRYQYj.js +0 -24
  322. package/dist/rule-DAxQY-1h.js +0 -20
  323. package/dist/schema-DBf18QPS.d.ts +0 -9339
  324. package/dist/service-account-o15pZWcJ.js +0 -931
  325. package/dist/start-conversation-DbVujrwO.js +0 -755
  326. package/dist/state-BTawTCme.js +0 -161
  327. package/dist/statuses-BKwqCPhj.js +0 -69
  328. package/dist/store-CjXrp-Up.js +0 -492
  329. package/dist/task-queue-Cwlatjz3.js +0 -90
  330. package/dist/vercel-queue-q4z8w5QO.js +0 -349
  331. package/dist/warmup-D5hzqTcp.js +0 -12257
  332. package/migrations/meta/0000_snapshot.json +0 -946
  333. package/migrations/meta/0001_snapshot.json +0 -972
  334. package/migrations/meta/0002_snapshot.json +0 -987
  335. package/migrations/meta/0003_snapshot.json +0 -1035
  336. package/migrations/meta/0004_snapshot.json +0 -1041
  337. package/migrations/meta/0005_snapshot.json +0 -948
  338. package/migrations/meta/0006_snapshot.json +0 -948
  339. package/migrations/meta/0007_snapshot.json +0 -1013
  340. package/migrations/meta/0008_snapshot.json +0 -1076
  341. package/migrations/meta/0009_snapshot.json +0 -1146
  342. package/migrations/meta/0010_snapshot.json +0 -1190
  343. package/migrations/meta/0011_snapshot.json +0 -1195
  344. package/migrations/meta/0012_snapshot.json +0 -1244
  345. package/migrations/meta/0013_snapshot.json +0 -1250
  346. package/migrations/meta/0014_snapshot.json +0 -1201
  347. package/migrations/meta/0015_snapshot.json +0 -1360
  348. package/migrations/meta/0016_snapshot.json +0 -1617
  349. package/migrations/meta/0017_snapshot.json +0 -1666
  350. package/migrations/meta/0018_snapshot.json +0 -1756
  351. package/migrations/meta/0019_snapshot.json +0 -1904
  352. package/migrations/meta/0020_snapshot.json +0 -1848
  353. package/migrations/meta/0021_snapshot.json +0 -2176
  354. package/migrations/meta/0022_snapshot.json +0 -2186
  355. package/migrations/meta/0023_snapshot.json +0 -2198
  356. package/migrations/meta/0024_snapshot.json +0 -2275
  357. package/migrations/meta/0025_snapshot.json +0 -2275
  358. package/migrations/meta/0026_snapshot.json +0 -2424
  359. package/migrations/meta/0027_snapshot.json +0 -2554
  360. package/migrations/meta/0028_snapshot.json +0 -2685
  361. package/migrations/meta/0029_snapshot.json +0 -2709
  362. package/migrations/meta/0030_snapshot.json +0 -2799
  363. package/migrations/meta/0031_snapshot.json +0 -2823
  364. package/migrations/meta/0032_snapshot.json +0 -2892
  365. package/migrations/meta/0033_snapshot.json +0 -2914
  366. package/migrations/meta/0034_snapshot.json +0 -3038
  367. package/migrations/meta/0035_snapshot.json +0 -3048
  368. package/migrations/meta/0036_snapshot.json +0 -3186
  369. package/migrations/meta/0037_snapshot.json +0 -3192
  370. package/migrations/meta/0038_snapshot.json +0 -3323
  371. package/migrations/meta/0039_snapshot.json +0 -3368
  372. package/migrations/meta/0040_snapshot.json +0 -3516
  373. package/migrations/meta/0041_snapshot.json +0 -3516
  374. package/migrations/meta/0042_snapshot.json +0 -3610
  375. package/migrations/meta/0043_snapshot.json +0 -3610
  376. package/migrations/meta/0044_snapshot.json +0 -3473
  377. package/migrations/meta/0045_snapshot.json +0 -3503
  378. package/migrations/meta/0046_snapshot.json +0 -3707
  379. package/migrations/meta/0047_snapshot.json +0 -3713
  380. package/migrations/meta/0048_snapshot.json +0 -3720
  381. package/migrations/meta/0049_snapshot.json +0 -3581
  382. package/migrations/meta/0050_snapshot.json +0 -3753
  383. package/migrations/meta/0051_snapshot.json +0 -3759
  384. package/migrations/meta/0052_snapshot.json +0 -3765
  385. package/migrations/meta/0053_snapshot.json +0 -3771
  386. package/migrations/meta/0054_snapshot.json +0 -3777
  387. package/migrations/meta/0055_snapshot.json +0 -3948
  388. package/migrations/meta/0056_snapshot.json +0 -4280
  389. package/migrations/meta/0057_snapshot.json +0 -3618
  390. package/migrations/meta/0058_snapshot.json +0 -3598
  391. package/migrations/meta/0059_snapshot.json +0 -3619
  392. package/migrations/meta/0060_snapshot.json +0 -3465
  393. package/migrations/meta/0061_snapshot.json +0 -3471
  394. package/migrations/meta/0062_snapshot.json +0 -3499
  395. package/migrations/meta/0063_snapshot.json +0 -3505
  396. package/migrations/meta/0064_snapshot.json +0 -3505
  397. package/migrations/meta/0065_snapshot.json +0 -3511
  398. package/migrations/meta/0066_snapshot.json +0 -4099
  399. package/migrations/meta/0067_snapshot.json +0 -3921
  400. package/migrations/meta/0068_snapshot.json +0 -4176
  401. package/migrations/meta/0069_snapshot.json +0 -3979
  402. package/migrations/meta/0070_snapshot.json +0 -3997
  403. package/migrations/meta/0071_snapshot.json +0 -4003
  404. package/migrations/meta/0072_snapshot.json +0 -4064
  405. package/migrations/meta/0073_snapshot.json +0 -4070
  406. package/migrations/meta/0074_snapshot.json +0 -4076
  407. package/migrations/meta/0075_snapshot.json +0 -4083
  408. package/migrations/meta/0076_snapshot.json +0 -4147
  409. package/migrations/meta/0077_snapshot.json +0 -4141
  410. package/migrations/meta/0078_snapshot.json +0 -4175
  411. package/migrations/meta/0079_snapshot.json +0 -4203
  412. package/migrations/meta/0080_snapshot.json +0 -4265
  413. package/migrations/meta/0081_snapshot.json +0 -4271
  414. package/migrations/meta/0082_snapshot.json +0 -4373
  415. package/migrations/meta/0083_snapshot.json +0 -4388
  416. package/migrations/meta/0084_snapshot.json +0 -4388
  417. package/migrations/meta/0085_snapshot.json +0 -4394
  418. package/migrations/meta/0086_snapshot.json +0 -4366
  419. package/migrations/meta/0087_snapshot.json +0 -4366
  420. package/migrations/meta/0088_snapshot.json +0 -4372
  421. package/migrations/meta/0089_snapshot.json +0 -4372
  422. package/migrations/meta/0090_snapshot.json +0 -4388
  423. package/migrations/meta/0091_snapshot.json +0 -4410
  424. package/migrations/meta/0092_snapshot.json +0 -4446
  425. package/migrations/meta/0093_snapshot.json +0 -4446
  426. package/migrations/meta/0094_snapshot.json +0 -4452
  427. package/migrations/meta/0095_snapshot.json +0 -4452
  428. package/migrations/meta/0096_snapshot.json +0 -4490
  429. package/migrations/meta/0097_snapshot.json +0 -4490
  430. package/migrations/meta/0098_snapshot.json +0 -4490
  431. package/migrations/meta/0099_snapshot.json +0 -4496
  432. package/migrations/meta/0100_snapshot.json +0 -4496
  433. package/migrations/meta/0101_snapshot.json +0 -4496
  434. package/migrations/meta/0102_snapshot.json +0 -4502
  435. package/migrations/meta/0103_snapshot.json +0 -4509
  436. package/migrations/meta/0104_snapshot.json +0 -4516
  437. package/migrations/meta/0105_snapshot.json +0 -4611
  438. package/migrations/meta/0106_snapshot.json +0 -4617
  439. package/migrations/meta/0107_snapshot.json +0 -4617
  440. package/migrations/meta/0108_snapshot.json +0 -4688
  441. package/migrations/meta/0109_snapshot.json +0 -4925
  442. package/migrations/meta/0110_snapshot.json +0 -4952
  443. package/migrations/meta/0111_snapshot.json +0 -5011
  444. package/migrations/meta/0112_snapshot.json +0 -5011
  445. package/migrations/meta/0113_snapshot.json +0 -5033
  446. package/migrations/meta/0114_snapshot.json +0 -5203
  447. package/migrations/meta/0115_snapshot.json +0 -5225
  448. package/migrations/meta/0116_snapshot.json +0 -5388
  449. package/migrations/meta/0117_snapshot.json +0 -5413
  450. package/migrations/meta/0118_snapshot.json +0 -5428
  451. package/migrations/meta/0119_snapshot.json +0 -5441
  452. package/migrations/meta/0120_snapshot.json +0 -5441
  453. package/migrations/meta/0121_snapshot.json +0 -5481
  454. package/migrations/meta/0122_snapshot.json +0 -5481
  455. package/migrations/meta/0123_snapshot.json +0 -5481
  456. package/migrations/meta/0124_snapshot.json +0 -5516
  457. package/migrations/meta/0125_snapshot.json +0 -5516
  458. package/migrations/meta/0126_snapshot.json +0 -5488
  459. package/migrations/meta/0127_snapshot.json +0 -5519
  460. package/migrations/meta/0128_snapshot.json +0 -5519
  461. package/migrations/meta/0129_snapshot.json +0 -5547
  462. package/migrations/meta/0130_snapshot.json +0 -5563
  463. package/migrations/meta/0131_snapshot.json +0 -5569
  464. package/migrations/meta/0132_snapshot.json +0 -5569
  465. package/migrations/meta/0133_snapshot.json +0 -5590
  466. package/migrations/meta/0134_snapshot.json +0 -5606
  467. package/migrations/meta/0135_snapshot.json +0 -5624
  468. package/migrations/meta/0136_snapshot.json +0 -5624
  469. package/migrations/meta/0137_snapshot.json +0 -5864
  470. package/migrations/meta/0138_snapshot.json +0 -5894
  471. package/migrations/meta/0139_snapshot.json +0 -5898
  472. package/migrations/meta/0140_snapshot.json +0 -5919
  473. package/migrations/meta/0141_snapshot.json +0 -6429
  474. package/migrations/meta/0142_snapshot.json +0 -6457
  475. package/migrations/meta/0143_snapshot.json +0 -6434
  476. package/migrations/meta/0144_snapshot.json +0 -6434
  477. package/migrations/meta/0145_snapshot.json +0 -6440
  478. package/migrations/meta/0146_snapshot.json +0 -6446
  479. package/migrations/meta/0147_snapshot.json +0 -6452
  480. package/migrations/meta/0148_snapshot.json +0 -6474
  481. package/migrations/meta/0149_snapshot.json +0 -6490
  482. package/migrations/meta/0150_snapshot.json +0 -6490
  483. package/migrations/meta/0151_snapshot.json +0 -6505
  484. package/migrations/meta/0152_snapshot.json +0 -6505
  485. package/migrations/meta/0153_snapshot.json +0 -6511
  486. package/migrations/meta/0154_snapshot.json +0 -6533
  487. package/migrations/meta/0155_snapshot.json +0 -6511
  488. package/migrations/meta/0156_snapshot.json +0 -6511
  489. package/migrations/meta/0157_snapshot.json +0 -6527
  490. package/migrations/meta/0158_snapshot.json +0 -6515
  491. package/migrations/meta/0159_snapshot.json +0 -6515
  492. package/migrations/meta/_journal.json +0 -1126
  493. /package/migrations/{0000_initial.sql → 20260711145847_initial/migration.sql} +0 -0
  494. /package/migrations/{0001_conversation_metrics.sql → 20260711145900_conversation_metrics/migration.sql} +0 -0
  495. /package/migrations/{0002_conversation_message_search.sql → 20260712153649_conversation_message_search/migration.sql} +0 -0
  496. /package/migrations/{0003_peaceful_scalphunter.sql → 20260713040256_peaceful_scalphunter/migration.sql} +0 -0
  497. /package/migrations/{0004_useful_magus.sql → 20260715174202_useful_magus/migration.sql} +0 -0
  498. /package/migrations/{0005_conversation_events.sql → 20260715174203_conversation_events/migration.sql} +0 -0
  499. /package/migrations/{0006_drop_legacy_conversation_messages.sql → 20260723042835_drop_legacy_conversation_messages/migration.sql} +0 -0
  500. /package/migrations/{0007_thick_sugar_man.sql → 20260723050612_thick_sugar_man/migration.sql} +0 -0
  501. /package/migrations/{0008_sticky_rage.sql → 20260727223822_sticky_rage/migration.sql} +0 -0
  502. /package/migrations/{0009_slippery_harrier.sql → 20260728033158_slippery_harrier/migration.sql} +0 -0
  503. /package/migrations/{0010_native_conversation_history.sql → 20260728040836_native_conversation_history/migration.sql} +0 -0
  504. /package/migrations/{0011_sour_golden_guardian.sql → 20260728204900_sour_golden_guardian/migration.sql} +0 -0
  505. /package/migrations/{0012_structured_conversation_events.sql → 20260730233332_structured_conversation_events/migration.sql} +0 -0
  506. /package/migrations/{0013_conversation_session_source.sql → 20260731164038_conversation_session_source/migration.sql} +0 -0
  507. /package/migrations/{0014_source_visibility.sql → 20260801230336_source_visibility/migration.sql} +0 -0
  508. /package/migrations/{0015_magical_ezekiel_stane.sql → 20260802023731_magical_ezekiel_stane/migration.sql} +0 -0
  509. /package/migrations/{0016_neat_the_anarchist.sql → 20260804015843_neat_the_anarchist/migration.sql} +0 -0
  510. /package/migrations/{0017_drop_paused_scheduled_tasks.sql → 20260804165952_drop_paused_scheduled_tasks/migration.sql} +0 -0
  511. /package/migrations/{0018_curvy_excalibur.sql → 20260804225613_curvy_excalibur/migration.sql} +0 -0
  512. /package/migrations/{0019_lowly_valkyrie.sql → 20260805174033_lowly_valkyrie/migration.sql} +0 -0
  513. /package/migrations/{0020_restrict_task_execution_kinds.sql → 20260805200301_restrict_task_execution_kinds/migration.sql} +0 -0
  514. /package/migrations/{0021_first_warhawk.sql → 20260806030729_first_warhawk/migration.sql} +0 -0
  515. /package/migrations/{0022_task_execution_status.sql → 20260807185200_task_execution_status/migration.sql} +0 -0
  516. /package/migrations/{0023_task_title_columns.sql → 20260808014743_task_title_columns/migration.sql} +0 -0
  517. /package/migrations/{0024_misty_typhoid_mary.sql → 20260809220421_misty_typhoid_mary/migration.sql} +0 -0
  518. /package/migrations/{0025_mcp_credential_subject.sql → 20260811193709_mcp_credential_subject/migration.sql} +0 -0
  519. /package/migrations/{0026_conversation_event_actor_and_participants.sql → 20260812032924_conversation_event_actor_and_participants/migration.sql} +0 -0
  520. /package/migrations/{0027_attachment_storage.sql → 20260812172418_attachment_storage/migration.sql} +0 -0
  521. /package/migrations/{0028_artifacts.sql → 20260813230732_artifacts/migration.sql} +0 -0
  522. /package/migrations/{0029_dizzy_barracuda.sql → 20260814062905_dizzy_barracuda/migration.sql} +0 -0
  523. /package/migrations/{0030_drop_workspace_repo_primary.sql → 20260814231353_drop_workspace_repo_primary/migration.sql} +0 -0
  524. /package/migrations/{0031_wild_phantom_reporter.sql → 20260815030100_wild_phantom_reporter/migration.sql} +0 -0
  525. /package/migrations/{0032_workspace_snapshots_table.sql → 20260817082233_workspace_snapshots_table/migration.sql} +0 -0
  526. /package/migrations/{0033_workspace_snapshot_active_build.sql → 20260818160339_workspace_snapshot_active_build/migration.sql} +0 -0
  527. /package/migrations/{0034_strong_randall.sql → 20260821180755_strong_randall/migration.sql} +0 -0
  528. /package/migrations/{0035_workspace_snapshot_size_bytes.sql → 20260823030308_workspace_snapshot_size_bytes/migration.sql} +0 -0
  529. /package/migrations/{0036_complex_rage.sql → 20260824190313_complex_rage/migration.sql} +0 -0
  530. /package/migrations/{0037_conversation_location.sql → 20260827233711_conversation_location/migration.sql} +0 -0
  531. /package/migrations/{0038_event_task_status.sql → 20260901224306_event_task_status/migration.sql} +0 -0
  532. /package/migrations/{0039_attachment_provider.sql → 20260904153232_attachment_provider/migration.sql} +0 -0
  533. /package/migrations/{0040_conversation_briefs.sql → 20260909111415_conversation_briefs/migration.sql} +0 -0
  534. /package/migrations/{0041_automation_outcomes_backfill.sql → 20260910144928_automation_outcomes_backfill/migration.sql} +0 -0
  535. /package/migrations/{0042_conversation_metrics.sql → 20260911184346_conversation_metrics/migration.sql} +0 -0
  536. /package/migrations/{0043_scheduled_automation_channel_destinations.sql → 20260921140842_scheduled_automation_channel_destinations/migration.sql} +0 -0
  537. /package/migrations/{0044_event_automation_channel_destinations.sql → 20260922221709_event_automation_channel_destinations/migration.sql} +0 -0
  538. /package/migrations/{0045_conversation_forks.sql → 20261001113455_conversation_forks/migration.sql} +0 -0
  539. /package/migrations/{0046_automation_versions.sql → 20261005161844_automation_versions/migration.sql} +0 -0
  540. /package/migrations/{0047_user_timezone.sql → 20261006152043_user_timezone/migration.sql} +0 -0
  541. /package/migrations/{0048_user_admin.sql → 20261008200858_user_admin/migration.sql} +0 -0
  542. /package/migrations/{0049_event_automation_status_reason.sql → 20261009145407_event_automation_status_reason/migration.sql} +0 -0
  543. /package/migrations/{0050_agent_invocation_parent_mailbox.sql → 20261013160816_agent_invocation_parent_mailbox/migration.sql} +0 -0
  544. /package/migrations/{0051_agent_invocation_parent_tool_call.sql → 20261013215020_agent_invocation_parent_tool_call/migration.sql} +0 -0
  545. /package/migrations/{0052_agent_invocation_title.sql → 20261014011138_agent_invocation_title/migration.sql} +0 -0
  546. /package/migrations/{0053_conversation_stopped_at.sql → 20261014211942_conversation_stopped_at/migration.sql} +0 -0
  547. /package/migrations/{0054_flowery_rage.sql → 20261015012820_flowery_rage/migration.sql} +0 -0
  548. /package/migrations/{0055_automations.sql → 20261017000924_automations/migration.sql} +0 -0
  549. /package/migrations/{0056_automation_runs.sql → 20261017134736_automation_runs/migration.sql} +0 -0
  550. /package/migrations/{0057_drop_legacy_automation_tables.sql → 20261017170250_drop_legacy_automation_tables/migration.sql} +0 -0
  551. /package/migrations/{0058_automation_creator_identity.sql → 20261018134754_automation_creator_identity/migration.sql} +0 -0
  552. /package/migrations/{0059_automation_run_version.sql → 20261023071954_automation_run_version/migration.sql} +0 -0
  553. /package/migrations/{0060_identity_signed_in_at.sql → 20261025233137_identity_signed_in_at/migration.sql} +0 -0
  554. /package/migrations/{0061_workspace_vcpus.sql → 20261027234315_workspace_vcpus/migration.sql} +0 -0
  555. /package/migrations/{0062_plugin_report_index.sql → 20261028124242_plugin_report_index/migration.sql} +0 -0
  556. /package/migrations/{0063_agent_invocation_type.sql → 20261028154230_agent_invocation_type/migration.sql} +0 -0
  557. /package/migrations/{0064_any_resource_event_triggers.sql → 20261030021803_any_resource_event_triggers/migration.sql} +0 -0
  558. /package/migrations/{0065_user_customization.sql → 20261030234309_user_customization/migration.sql} +0 -0
  559. /package/migrations/{0066_review_items.sql → 20261031020656_review_items/migration.sql} +0 -0
  560. /package/migrations/{0067_review_item_dedupe_tenant.sql → 20261031024151_review_item_dedupe_tenant/migration.sql} +0 -0
  561. /package/migrations/{0068_review_item_slack_cards.sql → 20261031024246_review_item_slack_cards/migration.sql} +0 -0
  562. /package/migrations/{0069_system_identity.sql → 20261031155308_system_identity/migration.sql} +0 -0
  563. /package/migrations/{0070_review_item_foreign_keys.sql → 20261101193952_review_item_foreign_keys/migration.sql} +0 -0
  564. /package/migrations/{0071_review_item_turn.sql → 20261102172751_review_item_turn/migration.sql} +0 -0
  565. /package/migrations/{0072_conversation_read_positions.sql → 20261102221411_conversation_read_positions/migration.sql} +0 -0
  566. /package/migrations/{0073_conversation_quick_question.sql → 20261104085028_conversation_quick_question/migration.sql} +0 -0
  567. /package/migrations/{0074_conversation_participant_pins.sql → 20261104145136_conversation_participant_pins/migration.sql} +0 -0
  568. /package/migrations/{0075_conversation_detail_version.sql → 20261104164429_conversation_detail_version/migration.sql} +0 -0
  569. /package/migrations/{0076_conversation_auto_archive.sql → 20261104172055_conversation_auto_archive/migration.sql} +0 -0
  570. /package/migrations/{0077_drop_agent_invocation_model_profile.sql → 20261105005443_drop_agent_invocation_model_profile/migration.sql} +0 -0
  571. /package/migrations/{0078_plugin_conversation_index.sql → 20261105043807_plugin_conversation_index/migration.sql} +0 -0
  572. /package/migrations/{0079_conversation_event_author_index.sql → 20261105051837_conversation_event_author_index/migration.sql} +0 -0
  573. /package/migrations/{0080_conversation_event_latest_message_indexes.sql → 20261105182854_conversation_event_latest_message_indexes/migration.sql} +0 -0
  574. /package/migrations/{0081_conversation_pin_position.sql → 20261106011443_conversation_pin_position/migration.sql} +0 -0
  575. /package/migrations/{0082_push_notifications.sql → 20261106095004_push_notifications/migration.sql} +0 -0
  576. /package/migrations/{0083_conversation_kind.sql → 20261106162740_conversation_kind/migration.sql} +0 -0
  577. /package/migrations/{0084_read_position_backfill.sql → 20261107002001_read_position_backfill/migration.sql} +0 -0
  578. /package/migrations/{0085_child_archived_at.sql → 20261107025209_child_archived_at/migration.sql} +0 -0
  579. /package/migrations/{0086_shared_archive.sql → 20261107035735_shared_archive/migration.sql} +0 -0
  580. /package/migrations/{0087_child_location.sql → 20261107215055_child_location/migration.sql} +0 -0
  581. /package/migrations/{0088_conversation_unsubscribe.sql → 20261108191927_conversation_unsubscribe/migration.sql} +0 -0
  582. /package/migrations/{0089_conversation_paused_status.sql → 20261109021618_conversation_paused_status/migration.sql} +0 -0
  583. /package/migrations/{0090_guardian_review_time_index.sql → 20261109111553_guardian_review_time_index/migration.sql} +0 -0
  584. /package/migrations/{0091_conversation_participant_unsubscribed_index.sql → 20261109173130_conversation_participant_unsubscribed_index/migration.sql} +0 -0
  585. /package/migrations/{0092_turn_metric_actor.sql → 20261109182006_turn_metric_actor/migration.sql} +0 -0
  586. /package/migrations/{0093_participant_root_actor_backfill.sql → 20261109202836_participant_root_actor_backfill/migration.sql} +0 -0
  587. /package/migrations/{0094_conversation_delivery_paused_at.sql → 20261109232640_conversation_delivery_paused_at/migration.sql} +0 -0
  588. /package/migrations/{0095_web_linked_slack_identity_repair.sql → 20261110120937_web_linked_slack_identity_repair/migration.sql} +0 -0
  589. /package/migrations/{0096_automation_task_kind.sql → 20261110175824_automation_task_kind/migration.sql} +0 -0
  590. /package/migrations/{0097_conversation_kind_automation.sql → 20261110210242_conversation_kind_automation/migration.sql} +0 -0
  591. /package/migrations/{0098_review_item_plugin_actions.sql → 20261110222632_review_item_plugin_actions/migration.sql} +0 -0
  592. /package/migrations/{0099_conversation_last_message_at.sql → 20261110225157_conversation_last_message_at/migration.sql} +0 -0
  593. /package/migrations/{0100_automation_task_kind_repair.sql → 20261111013351_automation_task_kind_repair/migration.sql} +0 -0
  594. /package/migrations/{0101_drop_legacy_columns.sql → 20261111163126_drop_legacy_columns/migration.sql} +0 -0
  595. /package/migrations/{0102_code_change_last_activity.sql → 20261111170150_code_change_last_activity/migration.sql} +0 -0
  596. /package/migrations/{0103_agent_invocation_fork.sql → 20261111191441_agent_invocation_fork/migration.sql} +0 -0
  597. /package/migrations/{0104_code_change_draft.sql → 20261112142841_code_change_draft/migration.sql} +0 -0
  598. /package/migrations/{0105_attachment_uploads.sql → 20261112202901_attachment_uploads/migration.sql} +0 -0
  599. /package/migrations/{0106_conversation_agent_config.sql → 20261112220407_conversation_agent_config/migration.sql} +0 -0
  600. /package/migrations/{0107_attachment_deferred_download.sql → 20261113081247_attachment_deferred_download/migration.sql} +0 -0
  601. /package/migrations/{0108_conversation_embeddings.sql → 20261113225551_conversation_embeddings/migration.sql} +0 -0
  602. /package/migrations/{0109_user_preferences.sql → 20261114213238_user_preferences/migration.sql} +0 -0
  603. /package/migrations/{0110_code_change_repository_state_index.sql → 20261114222527_code_change_repository_state_index/migration.sql} +0 -0
  604. /package/migrations/{0111_attachment_kinds.sql → 20261115172605_attachment_kinds/migration.sql} +0 -0
  605. /package/migrations/{0112_attachment_url_fill.sql → 20261115173004_attachment_url_fill/migration.sql} +0 -0
  606. /package/migrations/{0113_attachment_url_index.sql → 20261115180216_attachment_url_index/migration.sql} +0 -0
  607. /package/migrations/{0114_plan_items.sql → 20261116103700_plan_items/migration.sql} +0 -0
  608. /package/migrations/{0115_automation_creator_slack_index.sql → 20261117100100_automation_creator_slack_index/migration.sql} +0 -0
  609. /package/migrations/{0116_conversation_event_search.sql → 20261117132522_conversation_event_search/migration.sql} +0 -0
  610. /package/migrations/{0117_automation_last_run.sql → 20261117164007_automation_last_run/migration.sql} +0 -0
  611. /package/migrations/{0118_automation_last_run_index.sql → 20261117164047_automation_last_run_index/migration.sql} +0 -0
  612. /package/migrations/{0119_money_micro_usd.sql → 20261117210444_money_micro_usd/migration.sql} +0 -0
  613. /package/migrations/{0120_conversation_cost_micro_usd.sql → 20261117210505_conversation_cost_micro_usd/migration.sql} +0 -0
  614. /package/migrations/{0121_people_list_metric_index.sql → 20261118081416_people_list_metric_index/migration.sql} +0 -0
  615. /package/migrations/{0122_automation_rollout_repair.sql → 20261118095216_automation_rollout_repair/migration.sql} +0 -0
  616. /package/migrations/{0123_cache_warming_history_reset.sql → 20261118143948_cache_warming_history_reset/migration.sql} +0 -0
  617. /package/migrations/{0124_artifact_visibility.sql → 20261119040651_artifact_visibility/migration.sql} +0 -0
  618. /package/migrations/{0125_artifact_public_sha_index.sql → 20261119040715_artifact_public_sha_index/migration.sql} +0 -0
  619. /package/migrations/{0126_artifact_drop_public.sql → 20261119052706_artifact_drop_public/migration.sql} +0 -0
  620. /package/migrations/{0127_artifact_path.sql → 20261119053831_artifact_path/migration.sql} +0 -0
  621. /package/migrations/{0128_artifact_path_index.sql → 20261119053844_artifact_path_index/migration.sql} +0 -0
  622. /package/migrations/{0129_review_item_answered_index.sql → 20261119091949_review_item_answered_index/migration.sql} +0 -0
  623. /package/migrations/{0130_review_item_status_index.sql → 20261119100029_review_item_status_index/migration.sql} +0 -0
  624. /package/migrations/{0131_brief_outcome_status.sql → 20261119165607_brief_outcome_status/migration.sql} +0 -0
  625. /package/migrations/{0132_brief_outcome_status_backfill.sql → 20261119165622_brief_outcome_status_backfill/migration.sql} +0 -0
  626. /package/migrations/{0133_brief_created_at_index.sql → 20261119213716_brief_created_at_index/migration.sql} +0 -0
  627. /package/migrations/{0134_slack_person_search_index.sql → 20261119222456_slack_person_search_index/migration.sql} +0 -0
  628. /package/migrations/{0135_code_change_size.sql → 20261119225522_code_change_size/migration.sql} +0 -0
  629. /package/migrations/{0136_merge_conflict_notice_dismiss.sql → 20261119232253_merge_conflict_notice_dismiss/migration.sql} +0 -0
  630. /package/migrations/{0137_inbox_snoozes.sql → 20261119235649_inbox_snoozes/migration.sql} +0 -0
  631. /package/migrations/{0138_code_change_search_index.sql → 20261120093118_code_change_search_index/migration.sql} +0 -0
  632. /package/migrations/{0139_review_item_owner.sql → 20261120093452_review_item_owner/migration.sql} +0 -0
  633. /package/migrations/{0140_review_item_owner_index.sql → 20261120185654_review_item_owner_index/migration.sql} +0 -0
  634. /package/migrations/{0141_memory_core_adoption.sql → 20261120185754_memory_core_adoption/migration.sql} +0 -0
  635. /package/migrations/{0142_memory_core_indexes.sql → 20261120185854_memory_core_indexes/migration.sql} +0 -0
  636. /package/migrations/{0143_todos.sql → 20261120235226_todos/migration.sql} +0 -0
  637. /package/migrations/{0144_inbox_items.sql → 20261121082316_inbox_items/migration.sql} +0 -0
  638. /package/migrations/{0145_todo_changed_by_agent.sql → 20261121175651_todo_changed_by_agent/migration.sql} +0 -0
  639. /package/migrations/{0146_inbox_item_subject_title_parts.sql → 20261121183527_inbox_item_subject_title_parts/migration.sql} +0 -0
  640. /package/migrations/{0147_inbox_snooze_wake_reason.sql → 20261121194143_inbox_snooze_wake_reason/migration.sql} +0 -0
  641. /package/migrations/{0148_authorization_request_index.sql → 20261121222400_authorization_request_index/migration.sql} +0 -0
  642. /package/migrations/{0149_conversation_metadata.sql → 20261121225908_conversation_metadata/migration.sql} +0 -0
  643. /package/migrations/{0150_conversation_metadata_fill.sql → 20261121225910_conversation_metadata_fill/migration.sql} +0 -0
  644. /package/migrations/{0151_conversation_search_index.sql → 20261121225913_conversation_search_index/migration.sql} +0 -0
  645. /package/migrations/{0152_inbox_item_legacy_automation_keys.sql → 20261122022900_inbox_item_legacy_automation_keys/migration.sql} +0 -0
  646. /package/migrations/{0153_artifact_expiry.sql → 20261122024454_artifact_expiry/migration.sql} +0 -0
  647. /package/migrations/{0154_artifact_permanent_sha_index.sql → 20261122024455_artifact_permanent_sha_index/migration.sql} +0 -0
  648. /package/migrations/{0155_artifact_drop_public_sha_index.sql → 20261122024457_artifact_drop_public_sha_index/migration.sql} +0 -0
  649. /package/migrations/{0156_conversation_kind_lead.sql → 20261122024458_conversation_kind_lead/migration.sql} +0 -0
  650. /package/migrations/{0157_conversation_lead_actor_index.sql → 20261122024459_conversation_lead_actor_index/migration.sql} +0 -0
  651. /package/migrations/{0158_keep_legacy_archive_columns.sql → 20261122071549_keep_legacy_archive_columns/migration.sql} +0 -0
  652. /package/migrations/{0159_conversation_embeddings_fk_validate.sql → 20261122191400_conversation_embeddings_fk_validate/migration.sql} +0 -0
@@ -0,0 +1,1131 @@
1
+ import { $i as getVercelConversationWorkQueue, $u as deliverWatch, Ad as sleep, Bn as invalidateReadySnapshot, Bu as workspaceSnapshotFinishedEvent, Er as buildSandboxEgressNetworkPolicy, Hn as setWorkspaceSnapshot, Kn as isStale, Nn as getWorkspace, Qd as getStateAdapter, Un as setWorkspaceSnapshotBuild, V as slackMention, Vn as loadSnapshotsForProfile, Wn as create, Yn as getSandboxProvider, a as getDb, aa as QUEUE_SIGNATURE_MAX_AGE_MS, bn as getTurnRequestDeadline, bu as juniorConversations, ca as getQueueProvider, ed as findMatchingWatches, fr as isWorkspaceSnapshotNotReadyError, ip as withLock, nd as isQuietEvent, nf as credentialContextForActor, oa as signQueueMessage, or as isAbortError, q as createPluginHookRunner, qd as ToolInputError, rp as fenceLock, sa as verifyQueueMessage, ur as WorkspaceSnapshotNotReadyError, vi as SANDBOX_RUNTIME, xu as juniorSpaceConfigurations, yr as createSandboxEgressCredentialToken } from "./db-DXTOYRzR.js";
2
+ import { h as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC } from "./package-discovery-BI6T_RkD.js";
3
+ import { M as SANDBOX_WORKSPACE_ROOT, k as SANDBOX_REPOS_ROOT } from "./transcript-BHhJVY0P.js";
4
+ import { m as logInfo, p as logException } from "./logging-czs0nqLC.js";
5
+ import { cn as isValidTimeZone, sn as getZonedDateTimeParts } from "./media-Cr9pGkzr.js";
6
+ import { H as resolveEventAuthor, aa as configValueSchema, ia as validateConfigValue, j as enqueueEventNotification, k as addQuietEventNote, ra as validateConfigKey } from "./mailbox-turn-79Nv1JXv.js";
7
+ import { B as zodToolDefinition, H as juniorToolOutputSchema, z as zodTool } from "./turn-session-routing-GtetHsdO.js";
8
+ import { t as resolveEventMentions } from "./people-Cegp1Iwq.js";
9
+ import { i as postinstall, r as dependencies, s as getSandboxResources } from "./resolve-BUFkmxkT.js";
10
+ import * as z from "zod";
11
+ import path from "node:path";
12
+ import { createHash, randomUUID } from "node:crypto";
13
+ import { eventSchema } from "@sentry/junior-plugin-api";
14
+ import { and, asc, eq, sql } from "drizzle-orm";
15
+ import { alias } from "drizzle-orm/pg-core";
16
+ import { structuredPatch } from "diff";
17
+ // src/chat/spaces/configuration.ts
18
+ /**
19
+ * Configuration of a Space: the same keys that a Slack channel sets, such as
20
+ * a default repository. A value applies to every Conversation in the Space.
21
+ * It wins over the Slack channel's value and the install default, and an
22
+ * explicit target in a request wins over it.
23
+ */
24
+ const rootConversation = alias(juniorConversations, "space_config_root");
25
+ /** List the configuration of a Space, by key. */
26
+ async function listSpaceConfiguration(spaceId) {
27
+ return (await getDb().select({
28
+ key: juniorSpaceConfigurations.key,
29
+ value: juniorSpaceConfigurations.value,
30
+ updatedAt: juniorSpaceConfigurations.updatedAt
31
+ }).from(juniorSpaceConfigurations).where(eq(juniorSpaceConfigurations.spaceId, spaceId)).orderBy(asc(juniorSpaceConfigurations.key))).map((row) => ({
32
+ ...row,
33
+ value: configValueSchema.parse(JSON.parse(row.value))
34
+ }));
35
+ }
36
+ /**
37
+ * Set one configuration value of a Space. Returns an error message when the
38
+ * key or the value is not allowed, such as a secret.
39
+ */
40
+ async function setSpaceConfiguration(args) {
41
+ const error = validateConfigKey(args.key) ?? validateConfigValue(args.value);
42
+ if (error) return error;
43
+ const values = {
44
+ value: JSON.stringify(args.value),
45
+ updatedAt: /* @__PURE__ */ new Date(),
46
+ updatedByUserId: args.updatedByUserId
47
+ };
48
+ await getDb().insert(juniorSpaceConfigurations).values({
49
+ spaceId: args.spaceId,
50
+ key: args.key,
51
+ ...values
52
+ }).onConflictDoUpdate({
53
+ target: [juniorSpaceConfigurations.spaceId, juniorSpaceConfigurations.key],
54
+ set: values
55
+ });
56
+ }
57
+ /** Remove one configuration value of a Space. */
58
+ async function unsetSpaceConfiguration(spaceId, key) {
59
+ await getDb().delete(juniorSpaceConfigurations).where(and(eq(juniorSpaceConfigurations.spaceId, spaceId), eq(juniorSpaceConfigurations.key, key)));
60
+ }
61
+ /**
62
+ * Return the configuration of the Space that a Conversation's root is in. A
63
+ * child is in the Space of its root. A Conversation outside a Space has none.
64
+ */
65
+ async function readConversationSpaceConfiguration(conversationId) {
66
+ const rows = await getDb().select({
67
+ key: juniorSpaceConfigurations.key,
68
+ value: juniorSpaceConfigurations.value
69
+ }).from(juniorConversations).innerJoin(rootConversation, eq(rootConversation.conversationId, sql`coalesce(${juniorConversations.rootConversationId}, ${juniorConversations.conversationId})`)).innerJoin(juniorSpaceConfigurations, eq(juniorSpaceConfigurations.spaceId, rootConversation.spaceId)).where(eq(juniorConversations.conversationId, conversationId));
70
+ return Object.fromEntries(rows.map((row) => [row.key, configValueSchema.parse(JSON.parse(row.value))]));
71
+ }
72
+ // src/chat/sandbox/file-utils.ts
73
+ /** Normalize model-supplied numeric knobs before they reach filesystem tools. */
74
+ function positiveInteger(value) {
75
+ if (typeof value !== "number" || !Number.isFinite(value)) return;
76
+ const integer = Math.floor(value);
77
+ return integer > 0 ? integer : void 0;
78
+ }
79
+ /** Compare and slice text in one line-ending space while preserving callers' output rules. */
80
+ function normalizeToLf(value) {
81
+ return value.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
82
+ }
83
+ /** Detect model-facing missing paths without swallowing sandbox lifecycle/API failures. */
84
+ function isMissingPathError(error) {
85
+ if (!error || typeof error !== "object") return false;
86
+ const candidate = error;
87
+ if (candidate.code === "ENOENT") return true;
88
+ return typeof candidate.message === "string" && candidate.message.startsWith("File not found:");
89
+ }
90
+ const SANDBOX_FILE_ROOTS = [SANDBOX_WORKSPACE_ROOT, "/tmp"];
91
+ /** Keep sandbox filesystem tools scoped to the workspace root and /tmp. */
92
+ function resolveWorkspacePath(input, fallback = ".") {
93
+ const requested = (input ?? "").trim() || fallback;
94
+ const absolute = requested.startsWith("/") ? requested : path.posix.join(SANDBOX_WORKSPACE_ROOT, requested);
95
+ const normalized = path.posix.normalize(absolute);
96
+ if (!SANDBOX_FILE_ROOTS.some((root) => normalized === root || normalized.startsWith(`${root}/`))) throw new ToolInputError(`Path must stay within ${SANDBOX_FILE_ROOTS.join(" or ")}: ${requested}`);
97
+ return normalized;
98
+ }
99
+ // src/chat/tool-support/text-edits.ts
100
+ const MAX_DIFF_LINE_CHARS = 4e3;
101
+ /** Preserve a text artifact's dominant line-ending style across rewrites. */
102
+ function detectLineEnding(value) {
103
+ return value.includes("\r\n") ? "\r\n" : "\n";
104
+ }
105
+ /** Restore normalized LF content to the caller's original line-ending style. */
106
+ function restoreLineEndings(value, lineEnding) {
107
+ return lineEnding === "\r\n" ? value.replace(/\n/g, "\r\n") : value;
108
+ }
109
+ /** Keep UTF-8 BOM handling out of exact edit matching. */
110
+ function stripBom(value) {
111
+ return value.startsWith("") ? {
112
+ bom: "",
113
+ text: value.slice(1)
114
+ } : {
115
+ bom: "",
116
+ text: value
117
+ };
118
+ }
119
+ function countOccurrences(content, target) {
120
+ let count = 0;
121
+ let start = 0;
122
+ while (target.length > 0) {
123
+ const index = content.indexOf(target, start);
124
+ if (index === -1) break;
125
+ count += 1;
126
+ start = index + target.length;
127
+ }
128
+ return count;
129
+ }
130
+ function firstChangedLine(oldLines, newLines) {
131
+ const count = Math.max(oldLines.length, newLines.length);
132
+ for (let index = 0; index < count; index += 1) if (oldLines[index] !== newLines[index]) return index + 1;
133
+ }
134
+ /**
135
+ * Accept common exact-edit argument variants, such as the camelCase keys that
136
+ * models often send, before schema validation.
137
+ */
138
+ function prepareTextReplacementArguments(input) {
139
+ if (!input || typeof input !== "object") return input;
140
+ const raw = { ...input };
141
+ if (typeof raw["edits"] === "string") try {
142
+ raw["edits"] = JSON.parse(raw["edits"]);
143
+ } catch {
144
+ return raw;
145
+ }
146
+ const edits = Array.isArray(raw["edits"]) ? Array.from(raw["edits"]) : [];
147
+ const oldText = raw["old_text"] ?? raw["oldText"];
148
+ const newText = raw["new_text"] ?? raw["newText"];
149
+ if (typeof oldText === "string" && typeof newText === "string") edits.push({
150
+ old_text: oldText,
151
+ new_text: newText
152
+ });
153
+ if (edits.length > 0) raw["edits"] = edits.map((edit) => {
154
+ if (!edit || typeof edit !== "object") return edit;
155
+ const record = edit;
156
+ const { oldText, newText, ...rest } = record;
157
+ return {
158
+ ...rest,
159
+ old_text: record["old_text"] ?? oldText,
160
+ new_text: record["new_text"] ?? newText
161
+ };
162
+ });
163
+ delete raw["oldText"];
164
+ delete raw["old_text"];
165
+ delete raw["newText"];
166
+ delete raw["new_text"];
167
+ return raw;
168
+ }
169
+ /** Build a small line-oriented diff that gives agents enough context to review edits. */
170
+ function buildCompactDiff(oldContent, newContent) {
171
+ const oldLines = oldContent.split("\n");
172
+ const newLines = newContent.split("\n");
173
+ const { hunks } = structuredPatch("", "", oldContent, newContent, void 0, void 0, { context: 3 });
174
+ const width = String(Math.max(oldLines.length, newLines.length)).length;
175
+ const output = [];
176
+ let lineTruncated = false;
177
+ const pushLine = (line) => {
178
+ if (line.length > MAX_DIFF_LINE_CHARS) {
179
+ line = `${line.slice(0, MAX_DIFF_LINE_CHARS)}... [line truncated]`;
180
+ lineTruncated = true;
181
+ }
182
+ output.push(line);
183
+ };
184
+ let nextLine = 1;
185
+ for (const hunk of hunks) {
186
+ if (hunk.newStart > nextLine) pushLine(` ${"".padStart(width)} ...`);
187
+ let oldLine = hunk.oldStart;
188
+ let newLine = hunk.newStart;
189
+ for (const line of hunk.lines) {
190
+ const prefix = line[0];
191
+ if (prefix === "\\") {
192
+ pushLine(line);
193
+ continue;
194
+ }
195
+ pushLine(`${prefix}${String(prefix === "-" ? oldLine : newLine).padStart(width)} ${line.slice(1)}`);
196
+ if (prefix !== "+") oldLine += 1;
197
+ if (prefix !== "-") newLine += 1;
198
+ }
199
+ nextLine = newLine;
200
+ }
201
+ const newLineCount = newContent ? newLines.length - (newContent.endsWith("\n") ? 1 : 0) : 0;
202
+ if (hunks.length > 0 && nextLine <= newLineCount) pushLine(` ${"".padStart(width)} ...`);
203
+ return {
204
+ diff: output.join("\n"),
205
+ firstChangedLine: firstChangedLine(oldLines, newLines),
206
+ truncated: lineTruncated
207
+ };
208
+ }
209
+ /** Apply exact replacements to normalized text after validating uniqueness and overlap. */
210
+ function validateAndApplyTextEdits(content, edits, targetName) {
211
+ if (!Array.isArray(edits) || edits.length === 0) throw new ToolInputError(`${targetName} requires at least one edit.`);
212
+ const normalizedEdits = edits.map((edit, index) => {
213
+ if (typeof edit.old_text !== "string" || edit.old_text.length === 0) throw new ToolInputError(`edits[${index}].old_text must not be empty in ${targetName}.`);
214
+ if (typeof edit.new_text !== "string") throw new ToolInputError(`edits[${index}].new_text must be a string in ${targetName}.`);
215
+ return {
216
+ oldText: normalizeToLf(edit.old_text),
217
+ newText: normalizeToLf(edit.new_text)
218
+ };
219
+ });
220
+ const matchedEdits = [];
221
+ for (const [index, edit] of normalizedEdits.entries()) {
222
+ const matchIndex = content.indexOf(edit.oldText);
223
+ if (matchIndex === -1) throw new ToolInputError(`Could not find edits[${index}] in ${targetName}. old_text must match exactly including whitespace and newlines.`);
224
+ const occurrences = countOccurrences(content, edit.oldText);
225
+ if (occurrences > 1) throw new ToolInputError(`Found ${occurrences} occurrences of edits[${index}] in ${targetName}. Each old_text must be unique. Add surrounding text to old_text so that it matches once.`);
226
+ matchedEdits.push({
227
+ editIndex: index,
228
+ matchIndex,
229
+ matchLength: edit.oldText.length,
230
+ newText: edit.newText
231
+ });
232
+ }
233
+ matchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);
234
+ for (const [index, current] of matchedEdits.entries()) {
235
+ const previous = matchedEdits[index - 1];
236
+ if (!previous) continue;
237
+ if (previous.matchIndex + previous.matchLength > current.matchIndex) throw new ToolInputError(`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${targetName}. Merge overlapping replacements into one edit.`);
238
+ }
239
+ let newContent = content;
240
+ for (const edit of [...matchedEdits].reverse()) newContent = newContent.slice(0, edit.matchIndex) + edit.newText + newContent.slice(edit.matchIndex + edit.matchLength);
241
+ if (newContent === content) throw new ToolInputError(`No changes made to ${targetName}. Set new_text to text that differs from old_text, or remove that edit.`);
242
+ return {
243
+ baseContent: content,
244
+ newContent
245
+ };
246
+ }
247
+ // src/chat/tools/sandbox/bash.ts
248
+ const bashToolDefinition = zodToolDefinition({
249
+ annotations: {
250
+ destructiveHint: true,
251
+ idempotentHint: false,
252
+ openWorldHint: false,
253
+ readOnlyHint: false
254
+ },
255
+ approvalMode: "auto",
256
+ description: "Run a bash command inside the isolated sandbox workspace. Use this for repository inspection/execution tasks that need shell access. Do not use for network-sensitive or destructive actions unless explicitly required.",
257
+ inputSchema: z.object({
258
+ command: z.string().min(1).describe("Bash command to run inside the sandbox."),
259
+ cwd: z.string().min(1).describe("Optional working directory for this command only.").optional(),
260
+ timeout_ms: z.coerce.number().int().min(1e3).describe("Optional command timeout in milliseconds. Use for commands that may hang.").optional()
261
+ }),
262
+ outputSchema: juniorToolOutputSchema,
263
+ executionMode: "sequential"
264
+ });
265
+ /** Create the sandbox shell tool definition exposed to the agent. */
266
+ function createBashTool() {
267
+ return zodTool({
268
+ ...bashToolDefinition,
269
+ execute: async () => {
270
+ throw new Error("bash can only run when sandbox execution is enabled.");
271
+ }
272
+ });
273
+ }
274
+ // src/chat/tools/sandbox/edit-file.ts
275
+ /** Accept common edit argument variants before Pi validates the canonical schema. */
276
+ function prepareEditFileArguments(input) {
277
+ return prepareTextReplacementArguments(input);
278
+ }
279
+ const editReplacementSchema = z.object({
280
+ old_text: z.string().min(1).describe("Exact text to replace. It must be unique in the original file and must not overlap another edit."),
281
+ new_text: z.string().describe("Replacement text for this edit.")
282
+ });
283
+ const editFileToolDefinition = zodToolDefinition({
284
+ annotations: {
285
+ destructiveHint: true,
286
+ idempotentHint: true,
287
+ openWorldHint: false,
288
+ readOnlyHint: false
289
+ },
290
+ description: "Edit one sandbox workspace file with exact text replacements. Use for precise changes to existing files; prefer this over writeFile for targeted changes. Returns a diff. Multiple changes to the same file: use one edits[] call.",
291
+ prepareArguments: prepareEditFileArguments,
292
+ executionMode: "sequential",
293
+ inputSchema: z.object({
294
+ path: z.string().min(1).describe("Path to edit in the sandbox workspace."),
295
+ edits: z.array(editReplacementSchema).min(1).describe("Exact replacements matched against the original file, not incrementally.")
296
+ }),
297
+ outputSchema: juniorToolOutputSchema
298
+ });
299
+ /** Create the sandbox edit tool definition exposed to the agent. */
300
+ function createEditFileTool() {
301
+ return zodTool({
302
+ ...editFileToolDefinition,
303
+ execute: async () => {
304
+ throw new Error("editFile can only run when sandbox execution is enabled.");
305
+ }
306
+ });
307
+ }
308
+ // src/chat/tools/sandbox/read-file.ts
309
+ const readFileToolDefinition = zodToolDefinition({
310
+ description: "Read a bounded line range from a file in the sandbox workspace. Use when you need exact file contents to verify facts or make edits safely. Use bash (rg, find, ls) for broad discovery.",
311
+ annotations: {
312
+ destructiveHint: false,
313
+ idempotentHint: true,
314
+ openWorldHint: false,
315
+ readOnlyHint: true
316
+ },
317
+ inputSchema: z.object({
318
+ path: z.string().min(1).describe("Path to the file in the sandbox workspace."),
319
+ offset: z.coerce.number().int().min(1).describe("1-indexed line number to start reading from.").optional(),
320
+ limit: z.coerce.number().int().min(1).describe("Maximum number of lines to read. Defaults to 1000.").optional()
321
+ }),
322
+ outputSchema: juniorToolOutputSchema
323
+ });
324
+ /** Create the sandbox read tool definition exposed to the agent. */
325
+ function createReadFileTool() {
326
+ return zodTool({
327
+ ...readFileToolDefinition,
328
+ execute: async () => {
329
+ throw new Error("readFile can only run when sandbox execution is enabled.");
330
+ }
331
+ });
332
+ }
333
+ // src/chat/tools/sandbox/write-file.ts
334
+ const writeFileToolDefinition = zodToolDefinition({
335
+ annotations: {
336
+ destructiveHint: true,
337
+ idempotentHint: true,
338
+ openWorldHint: false,
339
+ readOnlyHint: false
340
+ },
341
+ description: "Write UTF-8 content to a file in the sandbox workspace. Use for intentional file creation or deliberate full-file replacement after validation; use editFile instead for targeted changes to existing files. Do not use for exploratory analysis-only turns.",
342
+ executionMode: "sequential",
343
+ inputSchema: z.object({
344
+ path: z.string().min(1).describe("Path to write in the sandbox workspace."),
345
+ content: z.string().describe("UTF-8 file content to write.")
346
+ }),
347
+ outputSchema: juniorToolOutputSchema
348
+ });
349
+ /** Create the sandbox full-file write tool definition exposed to the agent. */
350
+ function createWriteFileTool() {
351
+ return zodTool({
352
+ ...writeFileToolDefinition,
353
+ execute: async () => {
354
+ throw new Error("writeFile can only run when sandbox execution is enabled.");
355
+ }
356
+ });
357
+ }
358
+ // src/chat/tools/system-time.ts
359
+ const systemTimeInputSchema = z.object({ timezone: z.string().trim().min(1).optional().describe("Optional IANA timezone, for example America/Los_Angeles. When set, iso_local and timezone_offset_minutes are for that zone.") });
360
+ const systemTimeOutputSchema = juniorToolOutputSchema.extend({
361
+ unix_ms: z.number().describe("Current time in epoch milliseconds, for millisecond inputs."),
362
+ iso_utc: z.string(),
363
+ iso_local: z.string(),
364
+ timezone: z.string().nullable(),
365
+ timezone_offset_minutes: z.number()
366
+ });
367
+ const systemTimeToolDefinition = zodToolDefinition({
368
+ description: "Return current system time in UTC and optional local IANA timezone formats. Use when the user asks for current time/date context. Pass timezone when the answer should be in a known IANA zone such as America/Los_Angeles.",
369
+ annotations: {
370
+ destructiveHint: false,
371
+ idempotentHint: true,
372
+ openWorldHint: false,
373
+ readOnlyHint: true
374
+ },
375
+ inputSchema: systemTimeInputSchema,
376
+ outputSchema: systemTimeOutputSchema,
377
+ privateTraceResult: (result) => ({
378
+ unix_ms: result.unix_ms,
379
+ iso_utc: result.iso_utc,
380
+ iso_local: result.iso_local,
381
+ timezone: result.timezone,
382
+ timezone_offset_minutes: result.timezone_offset_minutes
383
+ })
384
+ });
385
+ /**
386
+ * Current-time lookup for turn answers.
387
+ *
388
+ * Accept an optional IANA timezone so remembered local-time preferences can be
389
+ * answered without shelling out to bash for conversion.
390
+ */
391
+ function createSystemTimeTool() {
392
+ return zodTool({
393
+ ...systemTimeToolDefinition,
394
+ execute: async (input) => {
395
+ const now = /* @__PURE__ */ new Date();
396
+ const timezone = input.timezone?.trim() || null;
397
+ if (timezone) {
398
+ if (!isValidTimeZone(timezone)) throw new ToolInputError("timezone must be a valid IANA time zone.");
399
+ const parts = getZonedDateTimeParts(now.getTime(), timezone);
400
+ const isoLocal = [
401
+ String(parts.year).padStart(4, "0"),
402
+ String(parts.month).padStart(2, "0"),
403
+ String(parts.day).padStart(2, "0")
404
+ ].join("-") + "T" + [
405
+ String(parts.hour).padStart(2, "0"),
406
+ String(parts.minute).padStart(2, "0"),
407
+ String(parts.second).padStart(2, "0")
408
+ ].join(":");
409
+ return {
410
+ unix_ms: now.getTime(),
411
+ iso_utc: now.toISOString(),
412
+ iso_local: isoLocal,
413
+ timezone,
414
+ timezone_offset_minutes: getTimeZoneOffsetMinutes(now.getTime(), timezone)
415
+ };
416
+ }
417
+ return {
418
+ unix_ms: now.getTime(),
419
+ iso_utc: now.toISOString(),
420
+ iso_local: (/* @__PURE__ */ new Date(now.getTime() - now.getTimezoneOffset() * 6e4)).toISOString().replace("Z", ""),
421
+ timezone: null,
422
+ timezone_offset_minutes: now.getTimezoneOffset()
423
+ };
424
+ }
425
+ });
426
+ }
427
+ function getTimeZoneOffsetMinutes(timestampMs, timezone) {
428
+ const parts = getZonedDateTimeParts(timestampMs, timezone);
429
+ const asUtcMs = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
430
+ return Math.round((timestampMs - asUtcMs) / 6e4);
431
+ }
432
+ // src/chat/events/ingest.ts
433
+ /** Match a normalized event and enqueue notifications into conversations. */
434
+ async function ingestEvent(input, options) {
435
+ const event = eventSchema.parse(input);
436
+ const nowMs = options.nowMs ?? Date.now();
437
+ const subscriptions = await findMatchingWatches({
438
+ data: event.data,
439
+ eventType: event.eventType,
440
+ nowMs,
441
+ namespace: event.namespace,
442
+ identifier: event.identifier,
443
+ state: options.state
444
+ });
445
+ if (subscriptions.length === 0) return { enqueued: 0 };
446
+ const author = await resolveEventAuthor(event);
447
+ if (author.status === "untrusted") logInfo("event.author.untrusted", {
448
+ "app.event.event_type": event.eventType,
449
+ "app.event.namespace": event.namespace,
450
+ "app.event.author.reason": author.reason
451
+ });
452
+ let people = [];
453
+ if (options.slackTeamId && event.people?.length) try {
454
+ people = await resolveEventMentions(event.people, options.slackTeamId);
455
+ } catch (error) {
456
+ logException(error, "event.people.resolve.failed", {
457
+ "app.event.event_type": event.eventType,
458
+ "app.event.namespace": event.namespace
459
+ });
460
+ }
461
+ const doneBy = author.status === "trusted" && author.actor ? {
462
+ mention: slackMention(author.actor.userId),
463
+ handle: author.handle
464
+ } : void 0;
465
+ const turnConversations = /* @__PURE__ */ new Set();
466
+ const ordered = [...subscriptions].sort((left, right) => Number(isQuietEvent(left, event.eventType)) - Number(isQuietEvent(right, event.eventType)));
467
+ let enqueued = 0;
468
+ const errors = [];
469
+ const waitDeadlineMs = Date.now() + 1e4;
470
+ for (const subscription of ordered) {
471
+ let quiet = false;
472
+ try {
473
+ if (await deliverWatch({
474
+ data: event.data,
475
+ eventType: event.eventType,
476
+ namespace: event.namespace,
477
+ identifier: event.identifier,
478
+ terminal: event.terminal,
479
+ nowMs,
480
+ state: options.state,
481
+ subscription,
482
+ waitDeadlineMs,
483
+ deliver: async (current) => {
484
+ if (options.admit && !await options.admit(current)) return false;
485
+ if (isQuietEvent(current, event.eventType)) {
486
+ quiet = true;
487
+ if (!turnConversations.has(current.conversationId)) await addQuietEventNote({
488
+ event,
489
+ subscription: current
490
+ });
491
+ return true;
492
+ }
493
+ const result = await enqueueEventNotification({
494
+ author,
495
+ doneBy,
496
+ event,
497
+ people,
498
+ queue: options.queue,
499
+ state: options.state,
500
+ subscription: current
501
+ });
502
+ if (result.status === "held") return false;
503
+ turnConversations.add(current.conversationId);
504
+ return result.status === "appended";
505
+ }
506
+ }) && !quiet) enqueued += 1;
507
+ } catch (error) {
508
+ errors.push(error);
509
+ }
510
+ }
511
+ if (errors.length > 0) throw new AggregateError(errors, "Failed to deliver one or more watches");
512
+ return { enqueued };
513
+ }
514
+ // src/chat/sandbox/prepare-workspace.ts
515
+ const WORKSPACE_SETUP_FAILURE_OUTPUT_MAX_CHARS = 7e3;
516
+ const WORKSPACE_SETUP_FAILURE_TRUNCATION_MARKER = "[earlier setup output truncated]\n";
517
+ const WORKSPACE_SETUP_NODE_OPTIONS = "--max-old-space-size=4096";
518
+ /** Prepare repositories before a Workspace setup script starts. */
519
+ async function prepareWorkspaceRepositories(params) {
520
+ const { sandbox, workspace, signal } = params;
521
+ signal?.throwIfAborted();
522
+ await params.applyNetworkPolicy(sandbox);
523
+ const finalize = await params.prepareRepositories?.(sandbox, workspace, signal);
524
+ if (params.removeCredentialRoute) await sandbox.update({ networkPolicy: "allow-all" });
525
+ await finalize?.();
526
+ }
527
+ /** Return bounded setup output for a Workspace failure. */
528
+ function workspaceSetupFailureDetail(input) {
529
+ const output = [input.stdout.trim() ? `stdout:\n${input.stdout.trim()}` : "", input.stderr.trim() ? `stderr:\n${input.stderr.trim()}` : ""].filter(Boolean).join("\n\n");
530
+ if (!output) return `exit ${input.exitCode}`;
531
+ if (output.length <= WORKSPACE_SETUP_FAILURE_OUTPUT_MAX_CHARS) return output;
532
+ return `${WORKSPACE_SETUP_FAILURE_TRUNCATION_MARKER}${output.slice(-6967)}`;
533
+ }
534
+ /** Build the env vars shared by every Workspace setup command. */
535
+ function workspaceSetupEnv() {
536
+ return {
537
+ JUNIOR_REPOS_ROOT: SANDBOX_REPOS_ROOT,
538
+ JUNIOR_WORKSPACE_ROOT: SANDBOX_WORKSPACE_ROOT,
539
+ NODE_OPTIONS: WORKSPACE_SETUP_NODE_OPTIONS
540
+ };
541
+ }
542
+ /** Build the command for one Workspace setup script. */
543
+ function workspaceSetupCommand(workspace) {
544
+ return {
545
+ cmd: "bash",
546
+ args: [
547
+ "-euo",
548
+ "pipefail",
549
+ "-c",
550
+ workspace.setupScript
551
+ ],
552
+ cwd: SANDBOX_WORKSPACE_ROOT,
553
+ env: workspaceSetupEnv()
554
+ };
555
+ }
556
+ /** Build a restart-safe command for one Workspace snapshot setup script. */
557
+ function workspaceSnapshotSetupCommand(workspace, buildId) {
558
+ const stateRoot = `/tmp/junior-snapshot-build-${buildId}`;
559
+ return {
560
+ cmd: "bash",
561
+ args: [
562
+ "-euo",
563
+ "pipefail",
564
+ "-c",
565
+ [
566
+ `mkdir -p "${stateRoot}"`,
567
+ `exec 9>"${stateRoot}/lock"`,
568
+ "flock 9",
569
+ `if test -f "${stateRoot}/exit"; then exit "$(cat "${stateRoot}/exit")"; fi`,
570
+ "set +e",
571
+ "bash -euo pipefail -c \"$1\"",
572
+ "status=$?",
573
+ `printf '%s\\n' "$status" > "${stateRoot}/exit"`,
574
+ "exit \"$status\""
575
+ ].join("\n"),
576
+ "junior-setup",
577
+ workspace.setupScript
578
+ ],
579
+ cwd: SANDBOX_WORKSPACE_ROOT,
580
+ env: workspaceSetupEnv()
581
+ };
582
+ }
583
+ /** Prepare repositories and setup state before a Workspace snapshot is captured. */
584
+ async function prepareWorkspaceSnapshot(params) {
585
+ const { sandbox, workspace, signal } = params;
586
+ await prepareWorkspaceRepositories(params);
587
+ if (!workspace.setupScript.trim()) return;
588
+ const result = await sandbox.runCommand({
589
+ ...workspaceSetupCommand(workspace),
590
+ signal
591
+ });
592
+ if (result.exitCode !== 0) throw new Error(`Workspace setup failed: ${workspaceSetupFailureDetail(result)}`);
593
+ }
594
+ // src/chat/sandbox/snapshot/workspace.ts
595
+ const BUILD_TIMEOUT_MS = 36e5;
596
+ const BUILD_TIMEOUT_ERROR = "Workspace snapshot build timed out after 1 hour";
597
+ const BUILD_LOCK_TTL_MS = 12e4;
598
+ const BUILD_LOCK_PREFIX = "junior:workspace_snapshot_start";
599
+ const WAIT_POLL_MS = 5e3;
600
+ const TRANSIENT_API_RETRY_MS = 2e3;
601
+ const BUILD_COMMAND_TIMEOUT_MS = 6e5;
602
+ const BUILD_COMMAND_TIMEOUT_ERROR = "Workspace snapshot build phase timed out after 10 minutes";
603
+ const COMMAND_STATUS_POLL_TIMEOUT_MS = 1e3;
604
+ /** Leave time to save the build state before this request ends. */
605
+ const STOP_BUFFER_MS = 4e4;
606
+ /** Keep the build open when a request stops or the provider has a short failure. */
607
+ function isCancelOrTransient(error) {
608
+ return isAbortError(error) || getSandboxProvider().errors.isTransient(error);
609
+ }
610
+ function buildLockKey(profileHash) {
611
+ return `${BUILD_LOCK_PREFIX}:${profileHash}`;
612
+ }
613
+ function builderName() {
614
+ return `junior-ws-${randomUUID()}`;
615
+ }
616
+ async function snapshotFromSql(workspaceId, value, staleSnapshotId) {
617
+ const { ready } = await loadSnapshotsForProfile(getDb(), workspaceId, value.hash);
618
+ if (!ready) return null;
619
+ if (ready.id === staleSnapshotId || isStale(value, ready.generatedAt.getTime())) {
620
+ const ownerName = await invalidateReadySnapshot({
621
+ workspaceId,
622
+ profileHash: value.hash,
623
+ snapshotId: ready.id
624
+ });
625
+ try {
626
+ await deleteBuilder(ownerName);
627
+ } catch (error) {
628
+ logException(error, "sandbox.workspace_snapshot.builder.delete_failed", { "app.workspace.id": workspaceId });
629
+ }
630
+ return null;
631
+ }
632
+ return {
633
+ snapshotId: ready.id,
634
+ profileHash: ready.profileHash,
635
+ dependencyCount: value.dependencyCount,
636
+ cacheHit: true,
637
+ resolveOutcome: "cache_hit",
638
+ createdAtMs: ready.generatedAt.getTime(),
639
+ buildDurationMs: ready.buildDurationMs
640
+ };
641
+ }
642
+ /** Return a build only when it has enough saved state to continue. */
643
+ function activeBuild(build) {
644
+ if (!build || build.status !== "building" || !build.sandboxName) return null;
645
+ return build;
646
+ }
647
+ async function deleteBuilder(sandboxName) {
648
+ if (!sandboxName) return;
649
+ await getSandboxProvider().deleteWorkspaceSnapshotBuilders([sandboxName]);
650
+ }
651
+ function workspaceDeletedError(workspace) {
652
+ return /* @__PURE__ */ new Error(`Workspace ${workspace.name} was deleted while its snapshot was building`);
653
+ }
654
+ function requireBuildWrite(written, workspace) {
655
+ if (!written) throw new Error(`Workspace ${workspace.name} snapshot build lost SQL ownership`);
656
+ }
657
+ /** Save a build failure, then delete its Sandbox. */
658
+ async function markFailed(workspace, build, error, beforeWrite) {
659
+ try {
660
+ await beforeWrite();
661
+ requireBuildWrite(await setWorkspaceSnapshotBuild(workspace.id, {
662
+ ...build,
663
+ status: "failed",
664
+ error: error instanceof Error ? error.message : String(error)
665
+ }), workspace);
666
+ } catch (persistError) {
667
+ logException(persistError, "sandbox.workspace_snapshot.failure_persist_failed", { "app.workspace.id": workspace.id });
668
+ return;
669
+ }
670
+ try {
671
+ await deleteBuilder(build.sandboxName);
672
+ } catch (cleanupError) {
673
+ logException(cleanupError, "sandbox.workspace_snapshot.builder.delete_failed", { "app.workspace.id": workspace.id });
674
+ }
675
+ }
676
+ /** Stop a build after one hour. */
677
+ async function requireRemainingBuildTime(workspace, build, beforeWrite) {
678
+ const remainingMs = build.startedAt.getTime() + BUILD_TIMEOUT_MS - Date.now();
679
+ if (remainingMs > 0) return remainingMs;
680
+ await markFailed(workspace, build, BUILD_TIMEOUT_ERROR, beforeWrite);
681
+ throw new Error(BUILD_TIMEOUT_ERROR);
682
+ }
683
+ /** Save the snapshot when its setup command ends. */
684
+ async function finishBuild(workspace, value, signal, beforeWrite) {
685
+ const { build: loaded } = await loadSnapshotsForProfile(getDb(), workspace.id, value.hash);
686
+ const build = activeBuild(loaded);
687
+ if (!build?.commandId || !build.sandboxName) return null;
688
+ try {
689
+ await requireRemainingBuildTime(workspace, build, beforeWrite);
690
+ const builder = await getSandboxProvider().getWorkspaceSnapshotBuilder(build.sandboxName, signal);
691
+ const command = await builder.getCommand(build.commandId, { signal });
692
+ const pollSignal = AbortSignal.timeout(COMMAND_STATUS_POLL_TIMEOUT_MS);
693
+ const waitSignal = signal ? AbortSignal.any([signal, pollSignal]) : pollSignal;
694
+ let finished;
695
+ try {
696
+ finished = await command.wait({ signal: waitSignal });
697
+ } catch (error) {
698
+ if (pollSignal.aborted && !signal?.aborted) return null;
699
+ throw error;
700
+ }
701
+ if (finished.exitCode !== 0) {
702
+ const [stdout, stderr] = await Promise.all([finished.stdout({ signal }), finished.stderr({ signal })]);
703
+ const detail = workspaceSetupFailureDetail({
704
+ exitCode: finished.exitCode,
705
+ stdout,
706
+ stderr
707
+ });
708
+ throw new Error(`Workspace ${workspace.name} snapshot setup failed: ${detail}`);
709
+ }
710
+ await requireRemainingBuildTime(workspace, build, beforeWrite);
711
+ const snapshot = await builder.snapshot({ signal });
712
+ await requireRemainingBuildTime(workspace, build, beforeWrite);
713
+ const createdAtMs = Date.now();
714
+ const buildDurationMs = Math.max(0, createdAtMs - build.startedAt.getTime());
715
+ const sizeBytes = typeof snapshot.sizeBytes === "number" && Number.isFinite(snapshot.sizeBytes) && snapshot.sizeBytes >= 0 ? snapshot.sizeBytes : null;
716
+ await beforeWrite();
717
+ const result = await setWorkspaceSnapshot(workspace.id, {
718
+ id: snapshot.snapshotId,
719
+ generatedAt: new Date(createdAtMs),
720
+ buildDurationMs,
721
+ sizeBytes,
722
+ profileHash: value.hash
723
+ }, { buildId: build.id });
724
+ requireBuildWrite(result.written, workspace);
725
+ try {
726
+ await getSandboxProvider().deleteWorkspaceSnapshotBuilders(result.replacedBuilderNames);
727
+ } catch (error) {
728
+ logException(error, "sandbox.workspace_snapshot.builder.delete_failed", {
729
+ "app.workspace.id": workspace.id,
730
+ "app.sandbox.snapshot.builder_count": result.replacedBuilderNames.length
731
+ });
732
+ }
733
+ return {
734
+ snapshotId: snapshot.snapshotId,
735
+ profileHash: value.hash,
736
+ dependencyCount: value.dependencyCount,
737
+ cacheHit: false,
738
+ resolveOutcome: "rebuilt",
739
+ rebuildReason: "cache_miss",
740
+ createdAtMs,
741
+ buildDurationMs
742
+ };
743
+ } catch (error) {
744
+ if (error instanceof Error && error.message === BUILD_TIMEOUT_ERROR) throw error;
745
+ if (isCancelOrTransient(error)) throw error;
746
+ await markFailed(workspace, build, error, beforeWrite);
747
+ throw error;
748
+ }
749
+ }
750
+ /** Create the Sandbox and save its name. */
751
+ async function startBuild(params) {
752
+ const { workspace, value, signal } = params;
753
+ const resources = getSandboxResources(workspace);
754
+ const name = builderName();
755
+ const buildId = randomUUID();
756
+ const startedAt = /* @__PURE__ */ new Date();
757
+ try {
758
+ await getSandboxProvider().createWorkspaceSnapshotBuilder({
759
+ name,
760
+ runtime: params.runtime,
761
+ timeoutMs: BUILD_TIMEOUT_MS,
762
+ signal,
763
+ ...resources ? { resources } : void 0
764
+ });
765
+ await params.beforeWrite();
766
+ if (!await setWorkspaceSnapshotBuild(workspace.id, {
767
+ id: buildId,
768
+ status: "building",
769
+ phase: "created",
770
+ profileHash: value.hash,
771
+ startedAt,
772
+ sandboxName: name,
773
+ commandId: null,
774
+ error: null
775
+ }, {
776
+ insertIfMissing: true,
777
+ expectedRecipe: workspace
778
+ })) {
779
+ try {
780
+ await deleteBuilder(name);
781
+ } catch (cleanupError) {
782
+ logException(cleanupError, "sandbox.workspace_snapshot.builder.delete_failed", { "app.workspace.id": workspace.id });
783
+ }
784
+ return;
785
+ }
786
+ } catch (error) {
787
+ try {
788
+ if (!isCancelOrTransient(error)) try {
789
+ await params.beforeWrite();
790
+ await setWorkspaceSnapshotBuild(workspace.id, {
791
+ id: buildId,
792
+ status: "failed",
793
+ phase: "created",
794
+ profileHash: value.hash,
795
+ startedAt,
796
+ sandboxName: name,
797
+ commandId: null,
798
+ error: error instanceof Error ? error.message : String(error)
799
+ }, {
800
+ insertIfMissing: true,
801
+ expectedRecipe: workspace
802
+ });
803
+ } catch {}
804
+ } finally {
805
+ try {
806
+ await deleteBuilder(name);
807
+ } catch (cleanupError) {
808
+ logException(cleanupError, "sandbox.workspace_snapshot.builder.delete_failed", { "app.workspace.id": workspace.id });
809
+ }
810
+ }
811
+ throw error;
812
+ }
813
+ }
814
+ /** Complete one saved setup step in the build Sandbox. */
815
+ async function continueBuild(params) {
816
+ const { build: loaded } = await loadSnapshotsForProfile(getDb(), params.workspace.id, params.value.hash);
817
+ const build = activeBuild(loaded);
818
+ if (!build?.sandboxName || build.commandId) return;
819
+ const remainingMs = await requireRemainingBuildTime(params.workspace, build, params.beforeWrite);
820
+ const commandTimeoutMs = Math.min(remainingMs, BUILD_COMMAND_TIMEOUT_MS);
821
+ const phaseTimeoutSignal = AbortSignal.timeout(commandTimeoutMs);
822
+ const phaseSignal = params.signal ? AbortSignal.any([params.signal, phaseTimeoutSignal]) : phaseTimeoutSignal;
823
+ try {
824
+ const builder = await getSandboxProvider().getWorkspaceSnapshotBuilder(build.sandboxName, phaseSignal);
825
+ const session = builder.session();
826
+ if (build.phase === "created") {
827
+ await dependencies(session, params.value.dependencies, phaseSignal, commandTimeoutMs);
828
+ await postinstall(session, params.value.postinstall, phaseSignal, commandTimeoutMs);
829
+ await requireRemainingBuildTime(params.workspace, build, params.beforeWrite);
830
+ await params.beforeWrite();
831
+ requireBuildWrite(await setWorkspaceSnapshotBuild(params.workspace.id, {
832
+ ...build,
833
+ phase: "dependencies_installed"
834
+ }), params.workspace);
835
+ return;
836
+ }
837
+ if (build.phase === "dependencies_installed") {
838
+ await prepareWorkspaceRepositories({
839
+ sandbox: session,
840
+ workspace: params.workspace,
841
+ signal: phaseSignal,
842
+ applyNetworkPolicy: params.applyNetworkPolicy,
843
+ prepareRepositories: params.prepareRepositories,
844
+ removeCredentialRoute: params.removeCredentialRoute
845
+ });
846
+ await requireRemainingBuildTime(params.workspace, build, params.beforeWrite);
847
+ await params.beforeWrite();
848
+ requireBuildWrite(await setWorkspaceSnapshotBuild(params.workspace.id, {
849
+ ...build,
850
+ phase: "repositories_prepared"
851
+ }), params.workspace);
852
+ return;
853
+ }
854
+ await params.beforeWrite();
855
+ const commandId = await builder.startDetachedCommand({
856
+ ...workspaceSnapshotSetupCommand(params.workspace, build.id),
857
+ timeoutMs: remainingMs,
858
+ signal: phaseSignal
859
+ });
860
+ await params.beforeWrite();
861
+ requireBuildWrite(await setWorkspaceSnapshotBuild(params.workspace.id, {
862
+ ...build,
863
+ commandId,
864
+ error: null
865
+ }), params.workspace);
866
+ } catch (error) {
867
+ if (phaseTimeoutSignal.aborted && !params.signal?.aborted) {
868
+ const timeoutError = new Error(BUILD_COMMAND_TIMEOUT_ERROR, { cause: error });
869
+ await markFailed(params.workspace, build, timeoutError, params.beforeWrite);
870
+ throw timeoutError;
871
+ }
872
+ if (error instanceof Error && error.message === BUILD_TIMEOUT_ERROR) throw error;
873
+ if (isCancelOrTransient(error)) throw error;
874
+ await markFailed(params.workspace, build, error, params.beforeWrite);
875
+ throw error;
876
+ }
877
+ }
878
+ /** Use a ready snapshot or complete one saved build step. */
879
+ async function advanceWorkspaceSnapshot(params) {
880
+ const value = create(params.runtime, params.workspace);
881
+ if (!value) throw new Error(`Workspace ${params.workspace.name} has no snapshot profile`);
882
+ const sqlCached = await snapshotFromSql(params.workspace.id, value, params.staleSnapshotId);
883
+ if (sqlCached) return sqlCached;
884
+ const state = getStateAdapter();
885
+ await state.connect();
886
+ const locked = await withLock(state, buildLockKey(value.hash), async (lock) => {
887
+ const workspace = await getWorkspace(getDb(), params.workspace.id);
888
+ if (!workspace) throw workspaceDeletedError(params.workspace);
889
+ const lockedValue = create(params.runtime, workspace) ?? value;
890
+ if (lockedValue.hash !== value.hash) return null;
891
+ const beforeWrite = async () => {
892
+ await fenceLock(state, lock, BUILD_LOCK_TTL_MS);
893
+ };
894
+ const sqlInsideLock = await snapshotFromSql(workspace.id, lockedValue, params.staleSnapshotId);
895
+ if (sqlInsideLock) return sqlInsideLock;
896
+ const finished = await finishBuild(workspace, lockedValue, params.signal, beforeWrite);
897
+ if (finished) return finished;
898
+ const { build: loaded } = await loadSnapshotsForProfile(getDb(), workspace.id, lockedValue.hash);
899
+ const build = activeBuild(loaded);
900
+ if (build && !build.commandId) await continueBuild({
901
+ ...params,
902
+ workspace,
903
+ value: lockedValue,
904
+ beforeWrite
905
+ });
906
+ else if (!build) {
907
+ if (loaded?.sandboxName) try {
908
+ await deleteBuilder(loaded.sandboxName);
909
+ } catch (cleanupError) {
910
+ logException(cleanupError, "sandbox.workspace_snapshot.builder.delete_failed", { "app.workspace.id": workspace.id });
911
+ }
912
+ await startBuild({
913
+ workspace,
914
+ value: lockedValue,
915
+ runtime: params.runtime,
916
+ signal: params.signal,
917
+ beforeWrite
918
+ });
919
+ }
920
+ return null;
921
+ }, {
922
+ ttlMs: BUILD_LOCK_TTL_MS,
923
+ keepAlive: true
924
+ });
925
+ return locked.acquired ? locked.value ?? null : null;
926
+ }
927
+ /** Check whether this request must stop soon. */
928
+ function shouldStopForTimeLimit(shouldStop) {
929
+ if (shouldStop?.()) return true;
930
+ const deadlineAtMs = getTurnRequestDeadline()?.deadlineAtMs;
931
+ return deadlineAtMs !== void 0 && Date.now() >= deadlineAtMs - STOP_BUFFER_MS;
932
+ }
933
+ /** Return the ready snapshot or report that the Workspace must build one. */
934
+ async function requireReadyWorkspaceSnapshot(params) {
935
+ const value = create(params.runtime, params.workspace);
936
+ if (!value) throw new Error(`Workspace ${params.workspace.name} has no snapshot profile`);
937
+ const snapshot = await snapshotFromSql(params.workspace.id, value, params.staleSnapshotId);
938
+ if (!snapshot) throw new WorkspaceSnapshotNotReadyError(params.workspace.name);
939
+ return snapshot;
940
+ }
941
+ /**
942
+ * Continue a Workspace snapshot build from its saved state.
943
+ * The full build can run for up to one hour.
944
+ */
945
+ async function resolveWorkspaceSnapshot(params) {
946
+ let advanced = false;
947
+ for (;;) {
948
+ params.signal?.throwIfAborted();
949
+ const workspace = await getWorkspace(getDb(), params.workspace.id);
950
+ if (!workspace) throw workspaceDeletedError(params.workspace);
951
+ const current = {
952
+ ...params,
953
+ workspace
954
+ };
955
+ if (advanced && shouldStopForTimeLimit(current.shouldStop)) throw new WorkspaceSnapshotNotReadyError(workspace.name);
956
+ let snapshot;
957
+ try {
958
+ snapshot = await advanceWorkspaceSnapshot(current);
959
+ } catch (error) {
960
+ if (!getSandboxProvider().errors.isTransient(error)) throw error;
961
+ advanced = true;
962
+ if (shouldStopForTimeLimit(current.shouldStop)) throw new WorkspaceSnapshotNotReadyError(workspace.name);
963
+ await sleep(TRANSIENT_API_RETRY_MS, params.signal);
964
+ continue;
965
+ }
966
+ advanced = true;
967
+ if (snapshot) return snapshot;
968
+ if (shouldStopForTimeLimit(current.shouldStop)) throw new WorkspaceSnapshotNotReadyError(workspace.name);
969
+ await sleep(WAIT_POLL_MS, params.signal);
970
+ }
971
+ }
972
+ // src/chat/sandbox/snapshot/job-queue.ts
973
+ /** Send Workspace snapshot build messages. */
974
+ const workspaceSnapshotJobSign = {
975
+ context: "junior.workspace_snapshot_queue.v1",
976
+ schema: z.object({
977
+ workspaceId: z.string().uuid(),
978
+ profileHash: z.string().min(1)
979
+ }).strict(),
980
+ signatureVersion: "v1",
981
+ parts: (message) => [message.workspaceId, message.profileHash]
982
+ };
983
+ function jobId(message) {
984
+ return `workspace-snapshot_${createHash("sha256").update(message.workspaceId).update("\0").update(message.profileHash).digest("hex").slice(0, 32)}`;
985
+ }
986
+ /** Sign a Workspace snapshot job for tests and local checks. */
987
+ function signWorkspaceSnapshotJobMessage(message, nowMs = Date.now()) {
988
+ return signQueueMessage(workspaceSnapshotJobSign, message, nowMs);
989
+ }
990
+ /** Check that a recent queue message came from Junior. */
991
+ function verifyWorkspaceSnapshotJobMessage(value, nowMs = Date.now()) {
992
+ return verifyQueueMessage(workspaceSnapshotJobSign, value, nowMs);
993
+ }
994
+ async function send(message, idempotencyKey) {
995
+ const options = { retentionSeconds: QUEUE_SIGNATURE_MAX_AGE_MS / 1e3 };
996
+ if (idempotencyKey) options.idempotencyKey = idempotencyKey;
997
+ await getQueueProvider().send(WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, signWorkspaceSnapshotJobMessage(message), options);
998
+ }
999
+ /** Send a job unless the same Workspace build already has one. */
1000
+ async function sendWorkspaceSnapshotJob(message) {
1001
+ await send(message, jobId(message));
1002
+ }
1003
+ /** Send the next job for a Workspace build that is still running. */
1004
+ async function sendNextWorkspaceSnapshotJob(message) {
1005
+ await send(message);
1006
+ }
1007
+ // src/chat/sandbox/snapshot/job-runner.ts
1008
+ /** Build Workspace snapshots in a background job. */
1009
+ const SNAPSHOT_BUILD_SYSTEM_ACTOR = {
1010
+ platform: "system",
1011
+ name: "workspace-snapshot"
1012
+ };
1013
+ /** Leave time to send the next job before this request ends. */
1014
+ const JOB_STOP_BUFFER_MS = 4e4;
1015
+ async function publishFinishedEvent(input) {
1016
+ await ingestEvent(workspaceSnapshotFinishedEvent(input), { queue: getVercelConversationWorkQueue() });
1017
+ }
1018
+ function createSnapshotBuildHelpers() {
1019
+ const credentials = credentialContextForActor(SNAPSHOT_BUILD_SYSTEM_ACTOR);
1020
+ const pluginHooks = createPluginHookRunner();
1021
+ const applyNetworkPolicy = async (sandbox) => {
1022
+ const networkPolicy = buildSandboxEgressNetworkPolicy({ credentialToken: createSandboxEgressCredentialToken({
1023
+ credentials,
1024
+ egressId: sandbox.sessionId,
1025
+ ttlMs: 36e5
1026
+ }) });
1027
+ await sandbox.update({ networkPolicy });
1028
+ return networkPolicy;
1029
+ };
1030
+ const prepareRepositories = async (sandbox, target, signal) => await pluginHooks.prepareWorkspace(sandbox, target.repos, signal);
1031
+ return {
1032
+ applyNetworkPolicy,
1033
+ prepareRepositories
1034
+ };
1035
+ }
1036
+ function shouldStopJob() {
1037
+ const deadlineAtMs = getTurnRequestDeadline()?.deadlineAtMs;
1038
+ return deadlineAtMs !== void 0 && Date.now() >= deadlineAtMs - JOB_STOP_BUFFER_MS;
1039
+ }
1040
+ /** Run a snapshot build and send another job if it needs more time. */
1041
+ async function processWorkspaceSnapshotJob(message, options = {}) {
1042
+ const workspace = await getWorkspace(getDb(), message.workspaceId);
1043
+ if (!workspace) {
1044
+ logInfo("workspace.snapshot.job.workspace_missing", { "app.workspace.id": message.workspaceId });
1045
+ await publishFinishedEvent({
1046
+ workspaceId: message.workspaceId,
1047
+ resultId: message.profileHash,
1048
+ status: "failed"
1049
+ });
1050
+ return;
1051
+ }
1052
+ const value = create(SANDBOX_RUNTIME, workspace);
1053
+ if (!value || value.hash !== message.profileHash) {
1054
+ logInfo("workspace.snapshot.job.profile_mismatch", {
1055
+ "app.workspace.id": workspace.id,
1056
+ "app.workspace.snapshot.profile_hash": message.profileHash
1057
+ });
1058
+ return;
1059
+ }
1060
+ const before = await loadSnapshotsForProfile(getDb(), workspace.id, value.hash);
1061
+ if (before.ready) {
1062
+ await publishFinishedEvent({
1063
+ workspaceId: workspace.id,
1064
+ resultId: before.ready.id,
1065
+ status: "ready"
1066
+ });
1067
+ return;
1068
+ }
1069
+ const { applyNetworkPolicy, prepareRepositories } = createSnapshotBuildHelpers();
1070
+ try {
1071
+ await resolveWorkspaceSnapshot({
1072
+ workspace,
1073
+ runtime: SANDBOX_RUNTIME,
1074
+ signal: options.signal,
1075
+ shouldStop: shouldStopJob,
1076
+ applyNetworkPolicy,
1077
+ prepareRepositories,
1078
+ removeCredentialRoute: true
1079
+ });
1080
+ } catch (error) {
1081
+ if (isWorkspaceSnapshotNotReadyError(error)) {
1082
+ await sendNextWorkspaceSnapshotJob(message);
1083
+ return;
1084
+ }
1085
+ const afterFailure = await loadSnapshotsForProfile(getDb(), workspace.id, value.hash);
1086
+ if (afterFailure.build?.status === "failed") {
1087
+ await publishFinishedEvent({
1088
+ workspaceId: workspace.id,
1089
+ resultId: afterFailure.build.id,
1090
+ status: "failed",
1091
+ error: afterFailure.build.error
1092
+ });
1093
+ return;
1094
+ }
1095
+ throw error;
1096
+ }
1097
+ const after = await loadSnapshotsForProfile(getDb(), workspace.id, value.hash);
1098
+ if (after.ready) {
1099
+ await publishFinishedEvent({
1100
+ workspaceId: workspace.id,
1101
+ resultId: after.ready.id,
1102
+ status: "ready"
1103
+ });
1104
+ return;
1105
+ }
1106
+ if (after.build?.status === "failed") {
1107
+ await publishFinishedEvent({
1108
+ workspaceId: workspace.id,
1109
+ resultId: after.build.id,
1110
+ status: "failed",
1111
+ error: after.build.error
1112
+ });
1113
+ return;
1114
+ }
1115
+ await sendNextWorkspaceSnapshotJob(message);
1116
+ }
1117
+ /** Start a snapshot build when no ready snapshot exists. */
1118
+ async function ensureWorkspaceSnapshotBuild(input) {
1119
+ const value = create(SANDBOX_RUNTIME, input.workspace);
1120
+ if (!value) throw new Error(`Workspace ${input.workspace.name} has no snapshot profile`);
1121
+ const current = await loadSnapshotsForProfile(getDb(), input.workspace.id, value.hash);
1122
+ if (current.ready) return "ready";
1123
+ const message = {
1124
+ workspaceId: input.workspace.id,
1125
+ profileHash: value.hash
1126
+ };
1127
+ if (input.sendAgain || current.build) await sendNextWorkspaceSnapshotJob(message);
1128
+ else await sendWorkspaceSnapshotJob(message);
1129
+ return "building";
1130
+ }
1131
+ export { unsetSpaceConfiguration as A, isMissingPathError as C, listSpaceConfiguration as D, resolveWorkspacePath as E, readConversationSpaceConfiguration as O, validateAndApplyTextEdits as S, positiveInteger as T, buildCompactDiff as _, prepareWorkspaceSnapshot as a, restoreLineEndings as b, systemTimeToolDefinition as c, createReadFileTool as d, readFileToolDefinition as f, createBashTool as g, bashToolDefinition as h, requireReadyWorkspaceSnapshot as i, setSpaceConfiguration as k, createWriteFileTool as l, editFileToolDefinition as m, processWorkspaceSnapshotJob as n, ingestEvent as o, createEditFileTool as p, verifyWorkspaceSnapshotJobMessage as r, createSystemTimeTool as s, ensureWorkspaceSnapshotBuild as t, writeFileToolDefinition as u, detectLineEnding as v, normalizeToLf as w, stripBom as x, prepareTextReplacementArguments as y };