@namzu/cli 41.2.2 → 42.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (487) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/dist/bin-main.d.ts.map +1 -1
  3. package/dist/bin.js +1 -1
  4. package/dist/chunks/{acp-5RFAFTQU.js → acp-ADQ2PRAY.js} +48 -48
  5. package/dist/chunks/{activity-command-XLF5EAM5.js → activity-command-JROQLBPA.js} +14 -15
  6. package/dist/chunks/activity-command-JROQLBPA.js.map +6 -0
  7. package/dist/chunks/{add-Z6Y5DOCM.js → add-ILLLF6YP.js} +25 -25
  8. package/dist/chunks/{agent-U4NFC4DT.js → agent-YQI5KOPV.js} +34 -35
  9. package/dist/chunks/agent-session-3MUZCWQ4.js +58 -0
  10. package/dist/chunks/{archive-P47MRHE2.js → archive-55KJKGJB.js} +11 -11
  11. package/dist/chunks/{bin-main-B3QOTIEH.js → bin-main-332F5KRZ.js} +13 -6
  12. package/dist/chunks/{bin-main-B3QOTIEH.js.map → bin-main-332F5KRZ.js.map} +1 -1
  13. package/dist/chunks/{browser-QN24UC7K.js → browser-C6AOJ3CH.js} +6 -6
  14. package/dist/chunks/{chat-HRORSJPH.js → chat-45H5F3KI.js} +16 -16
  15. package/dist/chunks/{chunk-TU46IHIV.js → chunk-23NRJ2RC.js} +5 -5
  16. package/dist/chunks/chunk-27R3OTVS.js +14 -0
  17. package/dist/chunks/chunk-27R3OTVS.js.map +6 -0
  18. package/dist/chunks/{chunk-LFI6O7WL.js → chunk-2OVZNENW.js} +43 -2
  19. package/dist/chunks/chunk-2OVZNENW.js.map +6 -0
  20. package/dist/chunks/{chunk-CEIYJWZ2.js → chunk-35VTE7V5.js} +2 -2
  21. package/dist/chunks/chunk-3F3V2PB7.js +56 -0
  22. package/dist/chunks/chunk-3F3V2PB7.js.map +6 -0
  23. package/dist/chunks/{chunk-72CFHDKQ.js → chunk-3LNTQLQ4.js} +14 -14
  24. package/dist/chunks/{chunk-NTPBXJMK.js → chunk-4IIEEOCA.js} +66 -6
  25. package/dist/chunks/chunk-4IIEEOCA.js.map +6 -0
  26. package/dist/chunks/{chunk-WBTXYSAB.js → chunk-4NO5XFK2.js} +2 -2
  27. package/dist/chunks/chunk-4TS6ZPOZ.js +363 -0
  28. package/dist/chunks/chunk-4TS6ZPOZ.js.map +6 -0
  29. package/dist/chunks/{chunk-UEXQA2UW.js → chunk-5XWMKWQQ.js} +65 -5
  30. package/dist/chunks/chunk-5XWMKWQQ.js.map +6 -0
  31. package/dist/chunks/{chunk-4SP6H34B.js → chunk-6GBZAUYW.js} +2 -2
  32. package/dist/chunks/{chunk-L2GZVP5H.js → chunk-6LVWHXT6.js} +10 -15
  33. package/dist/chunks/chunk-6LVWHXT6.js.map +6 -0
  34. package/dist/chunks/{chunk-2UPDDG7V.js → chunk-6PNBIMWH.js} +3 -3
  35. package/dist/chunks/{chunk-25XPE4N6.js → chunk-6S4R2USK.js} +3 -3
  36. package/dist/chunks/{chunk-4WWLRVYU.js → chunk-7E3V7NNN.js} +1282 -523
  37. package/dist/chunks/chunk-7E3V7NNN.js.map +6 -0
  38. package/dist/chunks/{chunk-VCKNYZYH.js → chunk-A3AF5WXZ.js} +6 -6
  39. package/dist/chunks/{chunk-G34P5PIK.js → chunk-A4CKLHKM.js} +4 -4
  40. package/dist/chunks/{chunk-Y5QV6NZK.js → chunk-AZPS37AQ.js} +2 -2
  41. package/dist/chunks/{chunk-2UYBHC3L.js → chunk-BDLDDNNO.js} +37 -6
  42. package/dist/chunks/chunk-BDLDDNNO.js.map +6 -0
  43. package/dist/chunks/{chunk-WJ7XYOSE.js → chunk-BRKD6FMO.js} +2 -2
  44. package/dist/chunks/{chunk-I55BEPVH.js → chunk-CW2N2QS2.js} +4 -4
  45. package/dist/chunks/{chunk-2VQ475KY.js → chunk-DLL2FPUY.js} +2 -2
  46. package/dist/chunks/{chunk-CIIMESY2.js → chunk-ESZ7X37S.js} +4 -4
  47. package/dist/chunks/{chunk-CAPC66Q6.js → chunk-EWSIGY2A.js} +4 -4
  48. package/dist/chunks/{chunk-JEULHVUH.js → chunk-F6WVRMVY.js} +864 -283
  49. package/dist/chunks/chunk-F6WVRMVY.js.map +6 -0
  50. package/dist/chunks/{chunk-CM2I2L4G.js → chunk-FMEGRBJP.js} +2 -2
  51. package/dist/chunks/{chunk-JKXCLMMZ.js → chunk-FSKJ3EZC.js} +2 -2
  52. package/dist/chunks/chunk-G5RAECIB.js +144 -0
  53. package/dist/chunks/chunk-G5RAECIB.js.map +6 -0
  54. package/dist/chunks/{chunk-C2IABASE.js → chunk-GOGBOZKO.js} +666 -27
  55. package/dist/chunks/chunk-GOGBOZKO.js.map +6 -0
  56. package/dist/chunks/chunk-HO2ZUI5Y.js +1189 -0
  57. package/dist/chunks/chunk-HO2ZUI5Y.js.map +6 -0
  58. package/dist/chunks/{chunk-2QXVOSJM.js → chunk-HOIDWHGC.js} +6 -6
  59. package/dist/chunks/{chunk-U2AVT6OB.js → chunk-HOY7BUGW.js} +3 -3
  60. package/dist/chunks/{chunk-WKGECHMV.js → chunk-HQZ3GBQI.js} +7 -7
  61. package/dist/chunks/{chunk-Z7DJAGBK.js → chunk-HXAWIWOZ.js} +2 -2
  62. package/dist/chunks/{chunk-CT23IU3D.js → chunk-IQQ6TY4W.js} +3 -3
  63. package/dist/chunks/{chunk-SEVUBJMR.js → chunk-J4IES4SO.js} +5 -5
  64. package/dist/chunks/{chunk-SEVUBJMR.js.map → chunk-J4IES4SO.js.map} +1 -1
  65. package/dist/chunks/{chunk-QNFMVN4D.js → chunk-JD2HLKFO.js} +2 -2
  66. package/dist/chunks/chunk-JHDNGNQT.js +95 -0
  67. package/dist/chunks/chunk-JHDNGNQT.js.map +6 -0
  68. package/dist/chunks/{chunk-H6B6AROX.js → chunk-JQIBPPOL.js} +69 -46
  69. package/dist/chunks/chunk-JQIBPPOL.js.map +6 -0
  70. package/dist/chunks/{chunk-ZDEFWEEI.js → chunk-JXT47VT6.js} +113 -35
  71. package/dist/chunks/chunk-JXT47VT6.js.map +6 -0
  72. package/dist/chunks/{chunk-LVDRURI4.js → chunk-K6LLMOB2.js} +2 -2
  73. package/dist/chunks/{chunk-EUBCYTOK.js → chunk-KONYGNG6.js} +152 -3
  74. package/dist/chunks/chunk-KONYGNG6.js.map +6 -0
  75. package/dist/chunks/{chunk-BHR2CNBZ.js → chunk-L3QW53QL.js} +223 -247
  76. package/dist/chunks/chunk-L3QW53QL.js.map +6 -0
  77. package/dist/chunks/{chunk-2HDIUUMX.js → chunk-M46GKTOI.js} +2 -2
  78. package/dist/chunks/{chunk-RKSYVIQX.js → chunk-N3C5X6BW.js} +6 -6
  79. package/dist/chunks/chunk-N4OY22M2.js +256 -0
  80. package/dist/chunks/chunk-N4OY22M2.js.map +6 -0
  81. package/dist/chunks/{chunk-E7FQPIJB.js → chunk-N56FVHCU.js} +26 -2
  82. package/dist/chunks/chunk-N56FVHCU.js.map +6 -0
  83. package/dist/chunks/chunk-PCUMISO3.js +92 -0
  84. package/dist/chunks/chunk-PCUMISO3.js.map +6 -0
  85. package/dist/chunks/{chunk-3RC4ATZI.js → chunk-QRGO6R2O.js} +12 -6
  86. package/dist/chunks/chunk-QRGO6R2O.js.map +6 -0
  87. package/dist/chunks/{chunk-37DRD4QM.js → chunk-QT6KYBCC.js} +3 -3
  88. package/dist/chunks/{chunk-QZYTSINZ.js → chunk-QUELENQP.js} +4 -4
  89. package/dist/chunks/{chunk-ZQRO6GGZ.js → chunk-QWBR6FBY.js} +89 -20
  90. package/dist/chunks/chunk-QWBR6FBY.js.map +6 -0
  91. package/dist/chunks/{chunk-7B5YTYHY.js → chunk-R2LYGFCI.js} +4 -4
  92. package/dist/chunks/{chunk-BNMFWLWH.js → chunk-RGVJHSMU.js} +5 -5
  93. package/dist/chunks/{chunk-YYX7O3T2.js → chunk-RVSVVL6O.js} +3 -3
  94. package/dist/chunks/{chunk-A6J2VJL5.js → chunk-S4KDR6G5.js} +53 -6
  95. package/dist/chunks/chunk-S4KDR6G5.js.map +6 -0
  96. package/dist/chunks/chunk-SIG7WHBU.js +78 -0
  97. package/dist/chunks/chunk-SIG7WHBU.js.map +6 -0
  98. package/dist/chunks/{chunk-RM4XZZL3.js → chunk-SIWZZF4M.js} +15 -15
  99. package/dist/chunks/{chunk-J67SASGK.js → chunk-SNC5D5UG.js} +18 -18
  100. package/dist/chunks/{chunk-CLADMV2E.js → chunk-SRYIMLOK.js} +2 -2
  101. package/dist/chunks/{chunk-3OP32UHN.js → chunk-TW5BCDA5.js} +3 -3
  102. package/dist/chunks/{chunk-5XJC5G7N.js → chunk-URJ7TITR.js} +8 -8
  103. package/dist/chunks/{chunk-4SBUXWX3.js → chunk-W2PJ6ZHY.js} +12 -47
  104. package/dist/chunks/chunk-W2PJ6ZHY.js.map +6 -0
  105. package/dist/chunks/{chunk-ZMZR4UTZ.js → chunk-WHOSI6UQ.js} +2 -2
  106. package/dist/chunks/{chunk-ANUGFVZI.js → chunk-XCMCPWMB.js} +4 -4
  107. package/dist/chunks/{chunk-VALR7WUL.js → chunk-XGVCAMNT.js} +2 -2
  108. package/dist/chunks/{chunk-DHV3KMEC.js → chunk-XMOKHCPV.js} +116 -40
  109. package/dist/chunks/chunk-XMOKHCPV.js.map +6 -0
  110. package/dist/chunks/{chunk-34L6FTQV.js → chunk-XXUL6HHM.js} +2 -2
  111. package/dist/chunks/{chunk-PKBHQFT6.js → chunk-Y2DZ27P6.js} +4 -4
  112. package/dist/chunks/{chunk-WN7YMX22.js → chunk-Y3I7AAD6.js} +4 -4
  113. package/dist/chunks/{chunk-UM4ECTUS.js → chunk-Y74CPWYC.js} +13 -13
  114. package/dist/chunks/chunk-YM4DUQ3P.js +59 -0
  115. package/dist/chunks/chunk-YM4DUQ3P.js.map +6 -0
  116. package/dist/chunks/{chunk-DQKQKNDY.js → chunk-YP7AINGL.js} +9 -9
  117. package/dist/chunks/{chunk-ZGBKTT7X.js → chunk-YPHXWFKQ.js} +2 -2
  118. package/dist/chunks/{chunk-OFNGIO53.js → chunk-YVIM3MXU.js} +2 -2
  119. package/dist/chunks/{cli-runtime-7GSPWSYW.js → cli-runtime-HW6GQKC6.js} +23 -20
  120. package/dist/chunks/cli-runtime-HW6GQKC6.js.map +6 -0
  121. package/dist/chunks/{commands-LU5AOF65.js → commands-JZT6JJY5.js} +5 -5
  122. package/dist/chunks/{crash-report-YDSO3QZP.js → crash-report-TWMWHNKY.js} +9 -7
  123. package/dist/chunks/{dist-7JBTU4ZA.js → dist-4EGZFRWY.js} +12 -2
  124. package/dist/chunks/dist-4EGZFRWY.js.map +6 -0
  125. package/dist/chunks/{dist-SLWBMTWO.js → dist-6ORFQIRV.js} +7 -2
  126. package/dist/chunks/{dist-SLWBMTWO.js.map → dist-6ORFQIRV.js.map} +1 -1
  127. package/dist/chunks/{dist-FI4O2BO3.js → dist-AZ5T257L.js} +22 -2
  128. package/dist/chunks/dist-AZ5T257L.js.map +6 -0
  129. package/dist/chunks/{dist-BJMHCL2F.js → dist-CLKFY67B.js} +8 -4
  130. package/dist/chunks/{dist-BJMHCL2F.js.map → dist-CLKFY67B.js.map} +1 -1
  131. package/dist/chunks/{dist-JWX7FPMB.js → dist-K5JIOWIQ.js} +8 -3
  132. package/dist/chunks/dist-K5JIOWIQ.js.map +6 -0
  133. package/dist/chunks/{dist-7PFXZB32.js → dist-MVLQAON2.js} +12 -2
  134. package/dist/chunks/{dist-7PFXZB32.js.map → dist-MVLQAON2.js.map} +1 -1
  135. package/dist/chunks/{dist-47WGWXP5.js → dist-POSMI3PI.js} +18 -4
  136. package/dist/chunks/{dist-47WGWXP5.js.map → dist-POSMI3PI.js.map} +1 -1
  137. package/dist/chunks/{doctor-ZK3CTBDR.js → doctor-UVZBNUNF.js} +15 -9
  138. package/dist/chunks/{drain-CVQW35OB.js → drain-27E6XUNK.js} +11 -10
  139. package/dist/chunks/drain-27E6XUNK.js.map +6 -0
  140. package/dist/chunks/{eval-PBRDQ7GI.js → eval-NRRIWDET.js} +2 -2
  141. package/dist/chunks/{exec-ZVOPAVQC.js → exec-KX46LZ36.js} +159 -62
  142. package/dist/chunks/exec-KX46LZ36.js.map +6 -0
  143. package/dist/chunks/{home-QPIQIIAR.js → home-RT2I6VTQ.js} +3 -3
  144. package/dist/chunks/{host-queries-UUG7LHPF.js → host-queries-ZXGOA6ZL.js} +23 -17
  145. package/dist/chunks/host-queries-ZXGOA6ZL.js.map +6 -0
  146. package/dist/chunks/install-LVQAT4QP.js +15 -0
  147. package/dist/chunks/{learn-AILV7XYA.js → learn-5KKZ4ZFX.js} +15 -14
  148. package/dist/chunks/learn-5KKZ4ZFX.js.map +6 -0
  149. package/dist/chunks/{learn-builtin-I2RMG7OE.js → learn-builtin-MSUF4MEJ.js} +18 -17
  150. package/dist/chunks/learn-builtin-MSUF4MEJ.js.map +6 -0
  151. package/dist/chunks/{lifecycle-ZZ5HDP6F.js → lifecycle-TZU6D46R.js} +29 -30
  152. package/dist/chunks/{list-TMHSX32S.js → list-QCWNMQED.js} +23 -23
  153. package/dist/chunks/live-V7HRF5KR.js +34 -0
  154. package/dist/chunks/{login-VUIOQEA2.js → login-QFP3PIXG.js} +8 -8
  155. package/dist/chunks/{logs-QQTFNNSW.js → logs-XTXMS4JF.js} +4 -4
  156. package/dist/chunks/{mcp-6H3YELN6.js → mcp-WQFJJ4NO.js} +81 -23
  157. package/dist/chunks/mcp-WQFJJ4NO.js.map +6 -0
  158. package/dist/chunks/{message-command-IQTT76ZY.js → message-command-QVNUJN47.js} +40 -41
  159. package/dist/chunks/message-command-QVNUJN47.js.map +6 -0
  160. package/dist/chunks/{operator-tools-ISZGHK3F.js → operator-tools-2OYRNPCH.js} +14 -14
  161. package/dist/chunks/{output-schema-63NLKBRY.js → output-schema-ETVPLUXE.js} +3 -3
  162. package/dist/chunks/{pal-RAIDDDNH.js → pal-BYFZCLE2.js} +12 -13
  163. package/dist/chunks/pal-BYFZCLE2.js.map +6 -0
  164. package/dist/chunks/plain-report-73WHPLHX.js +146 -0
  165. package/dist/chunks/plain-report-73WHPLHX.js.map +6 -0
  166. package/dist/chunks/{providers-N2UXL3XT.js → providers-KP5JHTTK.js} +6 -6
  167. package/dist/chunks/{resident-CWT62J2M.js → resident-BROBTK35.js} +35 -32
  168. package/dist/chunks/resident-BROBTK35.js.map +6 -0
  169. package/dist/chunks/resume-7V44GSEU.js +23 -0
  170. package/dist/chunks/{resume-command-DNNLB5SK.js → resume-command-OKJ2MJPB.js} +4 -4
  171. package/dist/chunks/{schedule-6N33GN2Z.js → schedule-TVR3FE32.js} +8 -8
  172. package/dist/chunks/{service-77ZFLYDC.js → service-6A3TOQKV.js} +35 -36
  173. package/dist/chunks/service-6A3TOQKV.js.map +6 -0
  174. package/dist/chunks/session-step-N4GHA2YE.js +33 -0
  175. package/dist/chunks/{skills-SAIXOU7Z.js → skills-WXYSPDKL.js} +9 -8
  176. package/dist/chunks/skills-WXYSPDKL.js.map +6 -0
  177. package/dist/chunks/start-check-BUCN5MCU.js +12 -0
  178. package/dist/chunks/{state-J4NZZP7B.js → state-PVAVIXHK.js} +3 -3
  179. package/dist/chunks/{store-QLG76DQG.js → store-D3XUEEAF.js} +6 -6
  180. package/dist/chunks/store-D3XUEEAF.js.map +6 -0
  181. package/dist/chunks/{store-YRVVPTUX.js → store-NB3KR4XA.js} +15 -11
  182. package/dist/chunks/store-NB3KR4XA.js.map +6 -0
  183. package/dist/chunks/{store-2JQLHCG4.js → store-O3KC2PPZ.js} +4 -4
  184. package/dist/chunks/store-O3KC2PPZ.js.map +6 -0
  185. package/dist/chunks/{tui-77L5I5EV.js → tui-2XOSCALL.js} +788 -217
  186. package/dist/chunks/tui-2XOSCALL.js.map +6 -0
  187. package/dist/chunks/undici-LWANNIOV.js +26906 -0
  188. package/dist/chunks/undici-LWANNIOV.js.map +6 -0
  189. package/dist/chunks/upgrade-FY5ULZQF.js +456 -0
  190. package/dist/chunks/upgrade-FY5ULZQF.js.map +6 -0
  191. package/dist/chunks/{worktree-5ETUFJAC.js → worktree-MVW62U5G.js} +13 -13
  192. package/dist/cli-runtime.d.ts +1 -0
  193. package/dist/cli-runtime.d.ts.map +1 -1
  194. package/dist/cli.d.ts.map +1 -1
  195. package/dist/commands/append-system.d.ts +19 -0
  196. package/dist/commands/append-system.d.ts.map +1 -0
  197. package/dist/commands/desktop-host.d.ts +6 -0
  198. package/dist/commands/desktop-host.d.ts.map +1 -1
  199. package/dist/commands/doctor.d.ts.map +1 -1
  200. package/dist/commands/exec-flags.d.ts +33 -0
  201. package/dist/commands/exec-flags.d.ts.map +1 -1
  202. package/dist/commands/exec-json.d.ts +6 -0
  203. package/dist/commands/exec-json.d.ts.map +1 -1
  204. package/dist/commands/exec.d.ts +4 -2
  205. package/dist/commands/exec.d.ts.map +1 -1
  206. package/dist/commands/host-queries.d.ts.map +1 -1
  207. package/dist/commands/mcp.d.ts.map +1 -1
  208. package/dist/commands/resident-flags.d.ts.map +1 -1
  209. package/dist/commands/run-flags.d.ts +32 -0
  210. package/dist/commands/run-flags.d.ts.map +1 -0
  211. package/dist/commands/upgrade.d.ts +23 -25
  212. package/dist/commands/upgrade.d.ts.map +1 -1
  213. package/dist/config/load.d.ts +20 -1
  214. package/dist/config/load.d.ts.map +1 -1
  215. package/dist/config/schema.d.ts +36 -1
  216. package/dist/config/schema.d.ts.map +1 -1
  217. package/dist/config/turn-guards.d.ts +3 -0
  218. package/dist/config/turn-guards.d.ts.map +1 -1
  219. package/dist/context/instruction-glob.d.ts +5 -0
  220. package/dist/context/instruction-glob.d.ts.map +1 -0
  221. package/dist/context/instruction-scope.d.ts +78 -0
  222. package/dist/context/instruction-scope.d.ts.map +1 -0
  223. package/dist/context/project-tracker.d.ts +10 -1
  224. package/dist/context/project-tracker.d.ts.map +1 -1
  225. package/dist/context/project.d.ts +46 -2
  226. package/dist/context/project.d.ts.map +1 -1
  227. package/dist/context/runtime-message.d.ts +8 -1
  228. package/dist/context/runtime-message.d.ts.map +1 -1
  229. package/dist/doctor/checks/cache-lifetime.d.ts +19 -0
  230. package/dist/doctor/checks/cache-lifetime.d.ts.map +1 -0
  231. package/dist/doctor/checks/index.d.ts +3 -1
  232. package/dist/doctor/checks/index.d.ts.map +1 -1
  233. package/dist/doctor/checks/network.d.ts +15 -0
  234. package/dist/doctor/checks/network.d.ts.map +1 -0
  235. package/dist/doctor/checks/updates.d.ts +6 -0
  236. package/dist/doctor/checks/updates.d.ts.map +1 -0
  237. package/dist/doctor/live.d.ts +15 -0
  238. package/dist/doctor/live.d.ts.map +1 -0
  239. package/dist/doctor/plain-report.d.ts +19 -0
  240. package/dist/doctor/plain-report.d.ts.map +1 -0
  241. package/dist/index.js +38 -32
  242. package/dist/integrations/auto-update/apply.d.ts +193 -0
  243. package/dist/integrations/auto-update/apply.d.ts.map +1 -0
  244. package/dist/integrations/auto-update/download.d.ts +35 -0
  245. package/dist/integrations/auto-update/download.d.ts.map +1 -0
  246. package/dist/integrations/auto-update/install-kind.d.ts +55 -0
  247. package/dist/integrations/auto-update/install-kind.d.ts.map +1 -0
  248. package/dist/integrations/auto-update/installed-version.d.ts +3 -0
  249. package/dist/integrations/auto-update/installed-version.d.ts.map +1 -0
  250. package/dist/integrations/auto-update/policy.d.ts +28 -0
  251. package/dist/integrations/auto-update/policy.d.ts.map +1 -0
  252. package/dist/integrations/auto-update/start-check.d.ts +21 -0
  253. package/dist/integrations/auto-update/start-check.d.ts.map +1 -0
  254. package/dist/integrations/auto-update/start.d.ts +25 -0
  255. package/dist/integrations/auto-update/start.d.ts.map +1 -0
  256. package/dist/integrations/auto-update/state.d.ts +109 -0
  257. package/dist/integrations/auto-update/state.d.ts.map +1 -0
  258. package/dist/integrations/auto-update/status.d.ts +37 -0
  259. package/dist/integrations/auto-update/status.d.ts.map +1 -0
  260. package/dist/integrations/auto-update/updater.d.ts +79 -0
  261. package/dist/integrations/auto-update/updater.d.ts.map +1 -0
  262. package/dist/integrations/mcp/project-approval.d.ts +41 -0
  263. package/dist/integrations/mcp/project-approval.d.ts.map +1 -0
  264. package/dist/integrations/mcp/shared-file.d.ts +36 -0
  265. package/dist/integrations/mcp/shared-file.d.ts.map +1 -0
  266. package/dist/integrations/npm-global.d.ts +40 -0
  267. package/dist/integrations/npm-global.d.ts.map +1 -0
  268. package/dist/integrations/plugins/hook-host.d.ts +18 -0
  269. package/dist/integrations/plugins/hook-host.d.ts.map +1 -0
  270. package/dist/integrations/plugins/runtime.d.ts +4 -2
  271. package/dist/integrations/plugins/runtime.d.ts.map +1 -1
  272. package/dist/integrations/providers/fallback-flag.d.ts +29 -0
  273. package/dist/integrations/providers/fallback-flag.d.ts.map +1 -0
  274. package/dist/integrations/providers/prompt-cache-ttl.d.ts +3 -0
  275. package/dist/integrations/providers/prompt-cache-ttl.d.ts.map +1 -1
  276. package/dist/integrations/resident/runner-worker.js +32 -25
  277. package/dist/integrations/resident/runner-worker.js.map +1 -1
  278. package/dist/integrations/sessions/conversation-search.d.ts +1 -1
  279. package/dist/integrations/sessions/conversation-search.d.ts.map +1 -1
  280. package/dist/integrations/sessions/store.d.ts +23 -0
  281. package/dist/integrations/sessions/store.d.ts.map +1 -1
  282. package/dist/integrations/subagents/runtime.d.ts +8 -2
  283. package/dist/integrations/subagents/runtime.d.ts.map +1 -1
  284. package/dist/integrations/trust/folder-grants.d.ts +12 -1
  285. package/dist/integrations/trust/folder-grants.d.ts.map +1 -1
  286. package/dist/integrations/updates.d.ts +15 -1
  287. package/dist/integrations/updates.d.ts.map +1 -1
  288. package/dist/network/install.d.ts +38 -0
  289. package/dist/network/install.d.ts.map +1 -0
  290. package/dist/network/settings.d.ts +50 -0
  291. package/dist/network/settings.d.ts.map +1 -0
  292. package/dist/pals/agent-session.d.ts.map +1 -1
  293. package/dist/permissions/mode.d.ts +3 -1
  294. package/dist/permissions/mode.d.ts.map +1 -1
  295. package/dist/permissions/read-only-gate.d.ts +28 -0
  296. package/dist/permissions/read-only-gate.d.ts.map +1 -0
  297. package/dist/permissions/sandbox-shell.d.ts +37 -0
  298. package/dist/permissions/sandbox-shell.d.ts.map +1 -0
  299. package/dist/permissions/tool-flags.d.ts +36 -0
  300. package/dist/permissions/tool-flags.d.ts.map +1 -0
  301. package/dist/plan/approval.d.ts +1 -0
  302. package/dist/plan/approval.d.ts.map +1 -1
  303. package/dist/plan/enter-plan-mode-tool.d.ts +28 -0
  304. package/dist/plan/enter-plan-mode-tool.d.ts.map +1 -0
  305. package/dist/plan/plan-file.d.ts +8 -0
  306. package/dist/plan/plan-file.d.ts.map +1 -1
  307. package/dist/reminders/task-nudge.d.ts +9 -1
  308. package/dist/reminders/task-nudge.d.ts.map +1 -1
  309. package/dist/skills/store.d.ts +6 -0
  310. package/dist/skills/store.d.ts.map +1 -1
  311. package/dist/tui/App.d.ts +1 -1
  312. package/dist/tui/App.d.ts.map +1 -1
  313. package/dist/tui/Checklist.d.ts +2 -0
  314. package/dist/tui/Checklist.d.ts.map +1 -1
  315. package/dist/tui/Composer.d.ts +7 -1
  316. package/dist/tui/Composer.d.ts.map +1 -1
  317. package/dist/tui/ContextGridRow.d.ts.map +1 -1
  318. package/dist/tui/LiveActivity.d.ts +2 -0
  319. package/dist/tui/LiveActivity.d.ts.map +1 -1
  320. package/dist/tui/ResumePicker.d.ts +10 -1
  321. package/dist/tui/ResumePicker.d.ts.map +1 -1
  322. package/dist/tui/StatusBar.d.ts +7 -1
  323. package/dist/tui/StatusBar.d.ts.map +1 -1
  324. package/dist/tui/TrustPrompt.d.ts +2 -0
  325. package/dist/tui/TrustPrompt.d.ts.map +1 -1
  326. package/dist/tui/agent.d.ts +31 -1
  327. package/dist/tui/agent.d.ts.map +1 -1
  328. package/dist/tui/capability-notice.d.ts +11 -1
  329. package/dist/tui/capability-notice.d.ts.map +1 -1
  330. package/dist/tui/context-grid.d.ts +7 -0
  331. package/dist/tui/context-grid.d.ts.map +1 -1
  332. package/dist/tui/context-usage.d.ts +4 -0
  333. package/dist/tui/context-usage.d.ts.map +1 -1
  334. package/dist/tui/conversation-in-use.d.ts +18 -0
  335. package/dist/tui/conversation-in-use.d.ts.map +1 -0
  336. package/dist/tui/foreground-handoff.d.ts +15 -0
  337. package/dist/tui/foreground-handoff.d.ts.map +1 -0
  338. package/dist/tui/launch-settings.d.ts +6 -3
  339. package/dist/tui/launch-settings.d.ts.map +1 -1
  340. package/dist/tui/pause-auto-resume.d.ts +33 -0
  341. package/dist/tui/pause-auto-resume.d.ts.map +1 -0
  342. package/dist/tui/permission-review.d.ts.map +1 -1
  343. package/dist/tui/plain-interruption.d.ts +8 -0
  344. package/dist/tui/plain-interruption.d.ts.map +1 -1
  345. package/dist/tui/restored-rows.d.ts +4 -0
  346. package/dist/tui/restored-rows.d.ts.map +1 -1
  347. package/dist/tui/resume-picker-state.d.ts +40 -0
  348. package/dist/tui/resume-picker-state.d.ts.map +1 -0
  349. package/dist/tui/slashCommands.d.ts +12 -1
  350. package/dist/tui/slashCommands.d.ts.map +1 -1
  351. package/dist/tui/system-rows.d.ts +3 -0
  352. package/dist/tui/system-rows.d.ts.map +1 -1
  353. package/dist/tui/tidy-tool-output.d.ts +2 -0
  354. package/dist/tui/tidy-tool-output.d.ts.map +1 -1
  355. package/dist/tui/turn-interruption.d.ts +2 -0
  356. package/dist/tui/turn-interruption.d.ts.map +1 -1
  357. package/dist/tui/types.d.ts +10 -1
  358. package/dist/tui/types.d.ts.map +1 -1
  359. package/dist/tui/update-notice.d.ts +13 -0
  360. package/dist/tui/update-notice.d.ts.map +1 -1
  361. package/dist/tui/working-label.d.ts +9 -0
  362. package/dist/tui/working-label.d.ts.map +1 -0
  363. package/dist/tui/zen-free-refusal.d.ts +12 -0
  364. package/dist/tui/zen-free-refusal.d.ts.map +1 -1
  365. package/dist/user-commands/store.d.ts +30 -1
  366. package/dist/user-commands/store.d.ts.map +1 -1
  367. package/package.json +11 -10
  368. package/dist/chunks/activity-command-XLF5EAM5.js.map +0 -6
  369. package/dist/chunks/agent-session-LHOJDS75.js +0 -59
  370. package/dist/chunks/chunk-2UYBHC3L.js.map +0 -6
  371. package/dist/chunks/chunk-3RC4ATZI.js.map +0 -6
  372. package/dist/chunks/chunk-4SBUXWX3.js.map +0 -6
  373. package/dist/chunks/chunk-4WWLRVYU.js.map +0 -6
  374. package/dist/chunks/chunk-A6J2VJL5.js.map +0 -6
  375. package/dist/chunks/chunk-BHR2CNBZ.js.map +0 -6
  376. package/dist/chunks/chunk-C2IABASE.js.map +0 -6
  377. package/dist/chunks/chunk-D2M5K6UY.js +0 -440
  378. package/dist/chunks/chunk-D2M5K6UY.js.map +0 -6
  379. package/dist/chunks/chunk-DHV3KMEC.js.map +0 -6
  380. package/dist/chunks/chunk-E7FQPIJB.js.map +0 -6
  381. package/dist/chunks/chunk-EUBCYTOK.js.map +0 -6
  382. package/dist/chunks/chunk-H6B6AROX.js.map +0 -6
  383. package/dist/chunks/chunk-JEULHVUH.js.map +0 -6
  384. package/dist/chunks/chunk-L2GZVP5H.js.map +0 -6
  385. package/dist/chunks/chunk-LFI6O7WL.js.map +0 -6
  386. package/dist/chunks/chunk-NTPBXJMK.js.map +0 -6
  387. package/dist/chunks/chunk-O2B3B2TM.js +0 -138
  388. package/dist/chunks/chunk-O2B3B2TM.js.map +0 -6
  389. package/dist/chunks/chunk-UEXQA2UW.js.map +0 -6
  390. package/dist/chunks/chunk-XSCT3DLE.js +0 -161
  391. package/dist/chunks/chunk-XSCT3DLE.js.map +0 -6
  392. package/dist/chunks/chunk-ZDEFWEEI.js.map +0 -6
  393. package/dist/chunks/chunk-ZQRO6GGZ.js.map +0 -6
  394. package/dist/chunks/cli-runtime-7GSPWSYW.js.map +0 -6
  395. package/dist/chunks/dist-7JBTU4ZA.js.map +0 -6
  396. package/dist/chunks/dist-FI4O2BO3.js.map +0 -6
  397. package/dist/chunks/dist-JWX7FPMB.js.map +0 -6
  398. package/dist/chunks/drain-CVQW35OB.js.map +0 -6
  399. package/dist/chunks/exec-ZVOPAVQC.js.map +0 -6
  400. package/dist/chunks/host-queries-UUG7LHPF.js.map +0 -6
  401. package/dist/chunks/learn-AILV7XYA.js.map +0 -6
  402. package/dist/chunks/learn-builtin-I2RMG7OE.js.map +0 -6
  403. package/dist/chunks/mcp-6H3YELN6.js.map +0 -6
  404. package/dist/chunks/message-command-IQTT76ZY.js.map +0 -6
  405. package/dist/chunks/pal-RAIDDDNH.js.map +0 -6
  406. package/dist/chunks/resident-CWT62J2M.js.map +0 -6
  407. package/dist/chunks/resume-PKATLA4S.js +0 -23
  408. package/dist/chunks/service-77ZFLYDC.js.map +0 -6
  409. package/dist/chunks/session-step-I5DFTYDV.js +0 -30
  410. package/dist/chunks/skills-SAIXOU7Z.js.map +0 -6
  411. package/dist/chunks/tui-77L5I5EV.js.map +0 -6
  412. package/dist/chunks/upgrade-ZTG65H5Q.js +0 -315
  413. package/dist/chunks/upgrade-ZTG65H5Q.js.map +0 -6
  414. /package/dist/chunks/{acp-5RFAFTQU.js.map → acp-ADQ2PRAY.js.map} +0 -0
  415. /package/dist/chunks/{add-Z6Y5DOCM.js.map → add-ILLLF6YP.js.map} +0 -0
  416. /package/dist/chunks/{agent-U4NFC4DT.js.map → agent-YQI5KOPV.js.map} +0 -0
  417. /package/dist/chunks/{agent-session-LHOJDS75.js.map → agent-session-3MUZCWQ4.js.map} +0 -0
  418. /package/dist/chunks/{archive-P47MRHE2.js.map → archive-55KJKGJB.js.map} +0 -0
  419. /package/dist/chunks/{browser-QN24UC7K.js.map → browser-C6AOJ3CH.js.map} +0 -0
  420. /package/dist/chunks/{chat-HRORSJPH.js.map → chat-45H5F3KI.js.map} +0 -0
  421. /package/dist/chunks/{chunk-TU46IHIV.js.map → chunk-23NRJ2RC.js.map} +0 -0
  422. /package/dist/chunks/{chunk-CEIYJWZ2.js.map → chunk-35VTE7V5.js.map} +0 -0
  423. /package/dist/chunks/{chunk-72CFHDKQ.js.map → chunk-3LNTQLQ4.js.map} +0 -0
  424. /package/dist/chunks/{chunk-WBTXYSAB.js.map → chunk-4NO5XFK2.js.map} +0 -0
  425. /package/dist/chunks/{chunk-4SP6H34B.js.map → chunk-6GBZAUYW.js.map} +0 -0
  426. /package/dist/chunks/{chunk-2UPDDG7V.js.map → chunk-6PNBIMWH.js.map} +0 -0
  427. /package/dist/chunks/{chunk-25XPE4N6.js.map → chunk-6S4R2USK.js.map} +0 -0
  428. /package/dist/chunks/{chunk-VCKNYZYH.js.map → chunk-A3AF5WXZ.js.map} +0 -0
  429. /package/dist/chunks/{chunk-G34P5PIK.js.map → chunk-A4CKLHKM.js.map} +0 -0
  430. /package/dist/chunks/{chunk-Y5QV6NZK.js.map → chunk-AZPS37AQ.js.map} +0 -0
  431. /package/dist/chunks/{chunk-WJ7XYOSE.js.map → chunk-BRKD6FMO.js.map} +0 -0
  432. /package/dist/chunks/{chunk-I55BEPVH.js.map → chunk-CW2N2QS2.js.map} +0 -0
  433. /package/dist/chunks/{chunk-2VQ475KY.js.map → chunk-DLL2FPUY.js.map} +0 -0
  434. /package/dist/chunks/{chunk-CIIMESY2.js.map → chunk-ESZ7X37S.js.map} +0 -0
  435. /package/dist/chunks/{chunk-CAPC66Q6.js.map → chunk-EWSIGY2A.js.map} +0 -0
  436. /package/dist/chunks/{chunk-CM2I2L4G.js.map → chunk-FMEGRBJP.js.map} +0 -0
  437. /package/dist/chunks/{chunk-JKXCLMMZ.js.map → chunk-FSKJ3EZC.js.map} +0 -0
  438. /package/dist/chunks/{chunk-2QXVOSJM.js.map → chunk-HOIDWHGC.js.map} +0 -0
  439. /package/dist/chunks/{chunk-U2AVT6OB.js.map → chunk-HOY7BUGW.js.map} +0 -0
  440. /package/dist/chunks/{chunk-WKGECHMV.js.map → chunk-HQZ3GBQI.js.map} +0 -0
  441. /package/dist/chunks/{chunk-Z7DJAGBK.js.map → chunk-HXAWIWOZ.js.map} +0 -0
  442. /package/dist/chunks/{chunk-CT23IU3D.js.map → chunk-IQQ6TY4W.js.map} +0 -0
  443. /package/dist/chunks/{chunk-QNFMVN4D.js.map → chunk-JD2HLKFO.js.map} +0 -0
  444. /package/dist/chunks/{chunk-LVDRURI4.js.map → chunk-K6LLMOB2.js.map} +0 -0
  445. /package/dist/chunks/{chunk-2HDIUUMX.js.map → chunk-M46GKTOI.js.map} +0 -0
  446. /package/dist/chunks/{chunk-RKSYVIQX.js.map → chunk-N3C5X6BW.js.map} +0 -0
  447. /package/dist/chunks/{chunk-37DRD4QM.js.map → chunk-QT6KYBCC.js.map} +0 -0
  448. /package/dist/chunks/{chunk-QZYTSINZ.js.map → chunk-QUELENQP.js.map} +0 -0
  449. /package/dist/chunks/{chunk-7B5YTYHY.js.map → chunk-R2LYGFCI.js.map} +0 -0
  450. /package/dist/chunks/{chunk-BNMFWLWH.js.map → chunk-RGVJHSMU.js.map} +0 -0
  451. /package/dist/chunks/{chunk-YYX7O3T2.js.map → chunk-RVSVVL6O.js.map} +0 -0
  452. /package/dist/chunks/{chunk-RM4XZZL3.js.map → chunk-SIWZZF4M.js.map} +0 -0
  453. /package/dist/chunks/{chunk-J67SASGK.js.map → chunk-SNC5D5UG.js.map} +0 -0
  454. /package/dist/chunks/{chunk-CLADMV2E.js.map → chunk-SRYIMLOK.js.map} +0 -0
  455. /package/dist/chunks/{chunk-3OP32UHN.js.map → chunk-TW5BCDA5.js.map} +0 -0
  456. /package/dist/chunks/{chunk-5XJC5G7N.js.map → chunk-URJ7TITR.js.map} +0 -0
  457. /package/dist/chunks/{chunk-ZMZR4UTZ.js.map → chunk-WHOSI6UQ.js.map} +0 -0
  458. /package/dist/chunks/{chunk-ANUGFVZI.js.map → chunk-XCMCPWMB.js.map} +0 -0
  459. /package/dist/chunks/{chunk-VALR7WUL.js.map → chunk-XGVCAMNT.js.map} +0 -0
  460. /package/dist/chunks/{chunk-34L6FTQV.js.map → chunk-XXUL6HHM.js.map} +0 -0
  461. /package/dist/chunks/{chunk-PKBHQFT6.js.map → chunk-Y2DZ27P6.js.map} +0 -0
  462. /package/dist/chunks/{chunk-WN7YMX22.js.map → chunk-Y3I7AAD6.js.map} +0 -0
  463. /package/dist/chunks/{chunk-UM4ECTUS.js.map → chunk-Y74CPWYC.js.map} +0 -0
  464. /package/dist/chunks/{chunk-DQKQKNDY.js.map → chunk-YP7AINGL.js.map} +0 -0
  465. /package/dist/chunks/{chunk-ZGBKTT7X.js.map → chunk-YPHXWFKQ.js.map} +0 -0
  466. /package/dist/chunks/{chunk-OFNGIO53.js.map → chunk-YVIM3MXU.js.map} +0 -0
  467. /package/dist/chunks/{commands-LU5AOF65.js.map → commands-JZT6JJY5.js.map} +0 -0
  468. /package/dist/chunks/{crash-report-YDSO3QZP.js.map → crash-report-TWMWHNKY.js.map} +0 -0
  469. /package/dist/chunks/{doctor-ZK3CTBDR.js.map → doctor-UVZBNUNF.js.map} +0 -0
  470. /package/dist/chunks/{eval-PBRDQ7GI.js.map → eval-NRRIWDET.js.map} +0 -0
  471. /package/dist/chunks/{home-QPIQIIAR.js.map → home-RT2I6VTQ.js.map} +0 -0
  472. /package/dist/chunks/{lifecycle-ZZ5HDP6F.js.map → install-LVQAT4QP.js.map} +0 -0
  473. /package/dist/chunks/{login-VUIOQEA2.js.map → lifecycle-TZU6D46R.js.map} +0 -0
  474. /package/dist/chunks/{list-TMHSX32S.js.map → list-QCWNMQED.js.map} +0 -0
  475. /package/dist/chunks/{output-schema-63NLKBRY.js.map → live-V7HRF5KR.js.map} +0 -0
  476. /package/dist/chunks/{providers-N2UXL3XT.js.map → login-QFP3PIXG.js.map} +0 -0
  477. /package/dist/chunks/{logs-QQTFNNSW.js.map → logs-XTXMS4JF.js.map} +0 -0
  478. /package/dist/chunks/{operator-tools-ISZGHK3F.js.map → operator-tools-2OYRNPCH.js.map} +0 -0
  479. /package/dist/chunks/{resume-PKATLA4S.js.map → output-schema-ETVPLUXE.js.map} +0 -0
  480. /package/dist/chunks/{resume-command-DNNLB5SK.js.map → providers-KP5JHTTK.js.map} +0 -0
  481. /package/dist/chunks/{session-step-I5DFTYDV.js.map → resume-7V44GSEU.js.map} +0 -0
  482. /package/dist/chunks/{store-2JQLHCG4.js.map → resume-command-OKJ2MJPB.js.map} +0 -0
  483. /package/dist/chunks/{schedule-6N33GN2Z.js.map → schedule-TVR3FE32.js.map} +0 -0
  484. /package/dist/chunks/{store-QLG76DQG.js.map → session-step-N4GHA2YE.js.map} +0 -0
  485. /package/dist/chunks/{store-YRVVPTUX.js.map → start-check-BUCN5MCU.js.map} +0 -0
  486. /package/dist/chunks/{state-J4NZZP7B.js.map → state-PVAVIXHK.js.map} +0 -0
  487. /package/dist/chunks/{worktree-5ETUFJAC.js.map → worktree-MVW62U5G.js.map} +0 -0
@@ -576,6 +576,503 @@ var asWorkspaceId = makeIdParser("workspace");
576
576
  var asSummaryId = makeIdParser("summary");
577
577
  var asDeliverableId = makeIdParser("deliverable");
578
578
 
579
+ // ../sdk/dist/types/provider/errors.js
580
+ function shouldRetryHeader(link6) {
581
+ const headers = link6.headers;
582
+ if (!headers || typeof headers !== "object")
583
+ return void 0;
584
+ const raw = typeof headers.get === "function" ? headers.get("x-should-retry") : headers["x-should-retry"];
585
+ return typeof raw === "string" && raw.trim().toLowerCase() === "false" ? false : void 0;
586
+ }
587
+ __name(shouldRetryHeader, "shouldRetryHeader");
588
+ function declaredRetryable(err) {
589
+ for (const link6 of causeChain(err)) {
590
+ const declared = link6.retryable;
591
+ if (typeof declared === "boolean")
592
+ return declared;
593
+ if (shouldRetryHeader(link6) === false)
594
+ return false;
595
+ }
596
+ return void 0;
597
+ }
598
+ __name(declaredRetryable, "declaredRetryable");
599
+ var RETRYABLE = /* @__PURE__ */ new Set([
600
+ "rate_limit",
601
+ "overloaded",
602
+ "server_error",
603
+ "timeout",
604
+ "network"
605
+ ]);
606
+ var ProviderError = class extends Error {
607
+ static {
608
+ __name(this, "ProviderError");
609
+ }
610
+ code;
611
+ providerId;
612
+ status;
613
+ retryAfterMs;
614
+ retryable;
615
+ constructor(init) {
616
+ super(init.message, init.cause !== void 0 ? { cause: init.cause } : void 0);
617
+ this.name = "ProviderError";
618
+ this.code = init.code;
619
+ this.providerId = init.providerId;
620
+ this.status = init.status;
621
+ this.retryAfterMs = init.retryAfterMs;
622
+ this.retryable = init.retryable ?? RETRYABLE.has(init.code);
623
+ }
624
+ };
625
+ function isProviderError(err) {
626
+ return err instanceof ProviderError;
627
+ }
628
+ __name(isProviderError, "isProviderError");
629
+ function isAbortError(err) {
630
+ if (err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError")) {
631
+ return true;
632
+ }
633
+ const name2 = err?.name;
634
+ return name2 === "AbortError";
635
+ }
636
+ __name(isAbortError, "isAbortError");
637
+ function* causeChain(err) {
638
+ const seen = /* @__PURE__ */ new Set();
639
+ let current = err;
640
+ while (current !== null && typeof current === "object" && !seen.has(current)) {
641
+ seen.add(current);
642
+ yield current;
643
+ current = current.cause;
644
+ }
645
+ }
646
+ __name(causeChain, "causeChain");
647
+ function readStatus(err) {
648
+ for (const link6 of causeChain(err)) {
649
+ const e = link6;
650
+ for (const candidate of [
651
+ e.status,
652
+ e.statusCode,
653
+ e.response?.status,
654
+ e.$metadata?.httpStatusCode
655
+ ]) {
656
+ if (typeof candidate === "number" && Number.isFinite(candidate))
657
+ return candidate;
658
+ }
659
+ }
660
+ return void 0;
661
+ }
662
+ __name(readStatus, "readStatus");
663
+ function readRetryAfterMs(err, now) {
664
+ for (const link6 of causeChain(err)) {
665
+ const headers = link6.headers;
666
+ if (!headers)
667
+ continue;
668
+ let raw;
669
+ if (typeof headers.get === "function") {
670
+ raw = headers.get("retry-after") ?? void 0;
671
+ } else if (typeof headers === "object") {
672
+ const bag = headers;
673
+ const value = bag["retry-after"] ?? bag["Retry-After"];
674
+ if (typeof value === "string" || typeof value === "number")
675
+ raw = String(value);
676
+ }
677
+ if (raw === void 0)
678
+ continue;
679
+ const seconds = Number(raw);
680
+ if (Number.isFinite(seconds) && seconds >= 0)
681
+ return Math.round(seconds * 1e3);
682
+ const at = Date.parse(raw);
683
+ if (Number.isFinite(at))
684
+ return Math.max(0, at - now);
685
+ }
686
+ return void 0;
687
+ }
688
+ __name(readRetryAfterMs, "readRetryAfterMs");
689
+ function readErrnoCode(err) {
690
+ for (const link6 of causeChain(err)) {
691
+ if (typeof link6.code === "string")
692
+ return link6.code;
693
+ }
694
+ return void 0;
695
+ }
696
+ __name(readErrnoCode, "readErrnoCode");
697
+ function chainMessages(err) {
698
+ const out = [];
699
+ for (const link6 of causeChain(err)) {
700
+ if (typeof link6.message === "string" && link6.message.length > 0)
701
+ out.push(link6.message);
702
+ }
703
+ return out;
704
+ }
705
+ __name(chainMessages, "chainMessages");
706
+ function readOutputOverflow(err) {
707
+ const pattern = /input length and `?max_tokens`? exceed context limit: (\d+) \+ (\d+) > (\d+)/i;
708
+ for (const message of chainMessages(err)) {
709
+ const match2 = pattern.exec(message);
710
+ if (!match2)
711
+ continue;
712
+ const inputTokens = Number.parseInt(match2[1] ?? "", 10);
713
+ const maxTokens = Number.parseInt(match2[2] ?? "", 10);
714
+ const contextLimit = Number.parseInt(match2[3] ?? "", 10);
715
+ if (![inputTokens, maxTokens, contextLimit].every(Number.isFinite))
716
+ continue;
717
+ return { inputTokens, maxTokens, contextLimit };
718
+ }
719
+ return void 0;
720
+ }
721
+ __name(readOutputOverflow, "readOutputOverflow");
722
+ function isUndiciTermination(err) {
723
+ for (const link6 of causeChain(err)) {
724
+ if (link6 instanceof TypeError && link6.message === "terminated")
725
+ return true;
726
+ }
727
+ return false;
728
+ }
729
+ __name(isUndiciTermination, "isUndiciTermination");
730
+ var TRANSPORT_CAUSES = /* @__PURE__ */ new Set([
731
+ "proxy_auth_required",
732
+ "proxy_refused",
733
+ "untrusted_certificate"
734
+ ]);
735
+ var UNTRUSTED_CERTIFICATE_CODES = /* @__PURE__ */ new Set([
736
+ "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
737
+ "UNABLE_TO_GET_ISSUER_CERT",
738
+ "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
739
+ "SELF_SIGNED_CERT_IN_CHAIN",
740
+ "DEPTH_ZERO_SELF_SIGNED_CERT",
741
+ "CERT_UNTRUSTED",
742
+ "CERT_CHAIN_TOO_LONG"
743
+ ]);
744
+ function readTransportCause(err) {
745
+ for (const link6 of causeChain(err)) {
746
+ if (typeof link6.transport === "string" && TRANSPORT_CAUSES.has(link6.transport)) {
747
+ return link6.transport;
748
+ }
749
+ if (typeof link6.code === "string" && UNTRUSTED_CERTIFICATE_CODES.has(link6.code)) {
750
+ return "untrusted_certificate";
751
+ }
752
+ const tunnel = typeof link6.message === "string" ? /Proxy response \((\d{3})\) !== 200 when HTTP Tunneling/.exec(link6.message) : null;
753
+ if (tunnel)
754
+ return tunnel[1] === "407" ? "proxy_auth_required" : "proxy_refused";
755
+ }
756
+ return void 0;
757
+ }
758
+ __name(readTransportCause, "readTransportCause");
759
+ var NETWORK_ERRNOS = /* @__PURE__ */ new Set([
760
+ "ECONNRESET",
761
+ "ECONNREFUSED",
762
+ "ECONNABORTED",
763
+ "EPIPE",
764
+ "EHOSTUNREACH",
765
+ "ENETUNREACH",
766
+ "ENOTFOUND",
767
+ "EAI_AGAIN",
768
+ "ENETDOWN",
769
+ "EHOSTDOWN",
770
+ "ERR_PROXY_TUNNEL",
771
+ "EPROTO",
772
+ "UND_ERR_SOCKET",
773
+ "UND_ERR_CLOSED",
774
+ "UND_ERR_CONNECT_TIMEOUT",
775
+ "UND_ERR_RESPONSE_STATUS_CODE"
776
+ ]);
777
+ var CERTIFICATE_ERRNOS = /* @__PURE__ */ new Set([
778
+ "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
779
+ "UNABLE_TO_GET_ISSUER_CERT",
780
+ "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
781
+ "CERT_HAS_EXPIRED",
782
+ "CERT_NOT_YET_VALID",
783
+ "CERT_UNTRUSTED",
784
+ "CERT_REVOKED",
785
+ "DEPTH_ZERO_SELF_SIGNED_CERT",
786
+ "SELF_SIGNED_CERT_IN_CHAIN",
787
+ "ERR_TLS_CERT_ALTNAME_INVALID",
788
+ "HOSTNAME_MISMATCH"
789
+ ]);
790
+ function readCertificateFailure(err) {
791
+ for (const link6 of causeChain(err)) {
792
+ if (typeof link6.code === "string" && CERTIFICATE_ERRNOS.has(link6.code))
793
+ return link6.code;
794
+ }
795
+ return void 0;
796
+ }
797
+ __name(readCertificateFailure, "readCertificateFailure");
798
+ function isTransientTransportCode(code) {
799
+ return code.startsWith("ERR_SSL_") || code.startsWith("ERR_TLS_") && !CERTIFICATE_ERRNOS.has(code);
800
+ }
801
+ __name(isTransientTransportCode, "isTransientTransportCode");
802
+ var TIMEOUT_ERRNOS = /* @__PURE__ */ new Set([
803
+ "ETIMEDOUT",
804
+ "ESOCKETTIMEDOUT",
805
+ "UND_ERR_HEADERS_TIMEOUT",
806
+ "UND_ERR_BODY_TIMEOUT"
807
+ ]);
808
+ function codeFromStatus(status) {
809
+ if (status === 429)
810
+ return "rate_limit";
811
+ if (status === 401 || status === 403)
812
+ return "auth";
813
+ if (status === 404)
814
+ return "not_found";
815
+ if (status === 408)
816
+ return "timeout";
817
+ if (status === 529 || status === 503)
818
+ return "overloaded";
819
+ if (status >= 500)
820
+ return "server_error";
821
+ if (status >= 400)
822
+ return "invalid_request";
823
+ return "unknown";
824
+ }
825
+ __name(codeFromStatus, "codeFromStatus");
826
+ function overflowWordingAllowed(status) {
827
+ return status === void 0 || status === 400 || status === 413;
828
+ }
829
+ __name(overflowWordingAllowed, "overflowWordingAllowed");
830
+ var CONTEXT_WINDOW_OVERFLOW = /(?:exceed\w*|too (?:long|large|big)|larger than|longer than|over the|beyond|maximum|overflow\w*)\b[^.]{0,60}context window|context window[^.]{0,60}\b(?:exceed\w*|too (?:long|large|big)|larger than|longer than|over the|beyond|maximum|overflow\w*)/i;
831
+ function codeFromMessage(message, status) {
832
+ const m = message.toLowerCase();
833
+ if (m.includes("context length") || m.includes("context_length") || m.includes("maximum context") || m.includes("too many tokens") || m.includes("prompt is too long") || // Real wordings that missed every phrase above and so classified as
834
+ // a plain invalid request — which is not retryable, and which the
835
+ // overflow rescue tests for by exact equality. The turn died holding
836
+ // the remedy.
837
+ m.includes("too long for") || // Known wordings: `context window` and
838
+ // `input length and max_tokens exceed context limit` matchers).
839
+ // Only where the status cannot say otherwise: a 429, 5xx or 401 that
840
+ // mentions the window is still a rate limit, a server fault or an auth
841
+ // failure, and must keep its retry and fallback behaviour.
842
+ overflowWordingAllowed(status) && (CONTEXT_WINDOW_OVERFLOW.test(message) || m.includes("exceed context limit")) || m.includes("maximum length") || m.includes("exceeds the maximum") || m.includes("input is too large") || m.includes("too large for")) {
843
+ return "context_length_exceeded";
844
+ }
845
+ if (m.includes("rate limit") || m.includes("rate_limit") || m.includes("too many requests")) {
846
+ return "rate_limit";
847
+ }
848
+ if (m.includes("overloaded"))
849
+ return "overloaded";
850
+ if (m.includes("content filter") || m.includes("content_filter") || m.includes("content policy")) {
851
+ return "content_filter";
852
+ }
853
+ if (m.includes("timed out") || m.includes("timeout"))
854
+ return "timeout";
855
+ if (m.includes("unauthorized") || m.includes("invalid api key") || m.includes("authentication")) {
856
+ return "auth";
857
+ }
858
+ return void 0;
859
+ }
860
+ __name(codeFromMessage, "codeFromMessage");
861
+ var STRUCTURAL_CODES = {
862
+ context_length_exceeded: "context_length_exceeded",
863
+ context_window_exceeded: "context_length_exceeded",
864
+ max_tokens_exceeded: "context_length_exceeded",
865
+ string_above_max_length: "context_length_exceeded",
866
+ rate_limit_exceeded: "rate_limit",
867
+ rate_limit_error: "rate_limit",
868
+ insufficient_quota: "rate_limit",
869
+ overloaded_error: "overloaded",
870
+ content_filter: "content_filter",
871
+ content_policy_violation: "content_filter",
872
+ invalid_api_key: "auth",
873
+ authentication_error: "auth",
874
+ permission_error: "auth",
875
+ model_not_found: "not_found"
876
+ };
877
+ function codeFromStructure(err) {
878
+ for (const link6 of causeChain(err)) {
879
+ for (const field2 of [link6.code, link6.type, link6.error?.type]) {
880
+ if (typeof field2 !== "string")
881
+ continue;
882
+ const mapped = STRUCTURAL_CODES[field2.toLowerCase()];
883
+ if (mapped)
884
+ return mapped;
885
+ }
886
+ }
887
+ return void 0;
888
+ }
889
+ __name(codeFromStructure, "codeFromStructure");
890
+ var KIND_TO_CODE = {
891
+ throttle: { code: "rate_limit", retryable: true },
892
+ network: { code: "network", retryable: true },
893
+ server: { code: "server_error", retryable: true },
894
+ auth: { code: "auth", retryable: false },
895
+ context_overflow: { code: "context_length_exceeded", retryable: false },
896
+ bad_request: { code: "invalid_request", retryable: false }
897
+ };
898
+ function classifyFromProviderRequestError(err, providerId, now) {
899
+ if (!(err instanceof Error) || err.name !== "ProviderRequestError")
900
+ return void 0;
901
+ const candidate = err;
902
+ if (typeof candidate.kind !== "string")
903
+ return void 0;
904
+ const mapped = KIND_TO_CODE[candidate.kind];
905
+ if (!mapped)
906
+ return void 0;
907
+ const retryAfterMs = typeof candidate.retryAfterMs === "number" ? candidate.retryAfterMs : readRetryAfterMs(err, now);
908
+ return new ProviderError({
909
+ code: mapped.code,
910
+ message: err.message,
911
+ // The provider saying "do not resend" beats the kind's own verdict.
912
+ retryable: candidate.shouldRetry === false ? false : mapped.retryable,
913
+ cause: err,
914
+ ...typeof candidate.providerId === "string" ? { providerId: candidate.providerId } : providerId !== void 0 ? { providerId } : {},
915
+ ...typeof candidate.status === "number" ? { status: candidate.status } : {},
916
+ ...retryAfterMs !== void 0 ? { retryAfterMs } : {}
917
+ });
918
+ }
919
+ __name(classifyFromProviderRequestError, "classifyFromProviderRequestError");
920
+ function classifyProviderError(err, providerId, now = Date.now()) {
921
+ if (isProviderError(err))
922
+ return err;
923
+ const fromKind = classifyFromProviderRequestError(err, providerId, now);
924
+ if (fromKind)
925
+ return fromKind;
926
+ const message = err instanceof Error ? err.message : String(err);
927
+ const status = readStatus(err);
928
+ const errno = readErrnoCode(err);
929
+ const retryAfterMs = readRetryAfterMs(err, now);
930
+ const messages = chainMessages(err);
931
+ const fromMessage = messages.map((m) => codeFromMessage(m, status)).find((code) => code !== void 0);
932
+ const declared = declaredRetryable(err);
933
+ const structural = codeFromStructure(err);
934
+ if (structural !== void 0) {
935
+ return new ProviderError({
936
+ code: structural,
937
+ message,
938
+ providerId,
939
+ ...status !== void 0 ? { status } : {},
940
+ ...retryAfterMs !== void 0 ? { retryAfterMs } : {},
941
+ ...declared !== void 0 ? { retryable: declared } : {},
942
+ cause: err
943
+ });
944
+ }
945
+ if (readTransportCause(err) !== void 0) {
946
+ return new ProviderError({
947
+ code: "network",
948
+ message,
949
+ providerId,
950
+ retryable: false,
951
+ cause: err
952
+ });
953
+ }
954
+ if (messages.some((m) => codeFromMessage(m, status) === "context_length_exceeded")) {
955
+ return new ProviderError({
956
+ code: "context_length_exceeded",
957
+ message,
958
+ providerId,
959
+ status,
960
+ ...declared !== void 0 ? { retryable: declared } : {},
961
+ cause: err
962
+ });
963
+ }
964
+ if (status !== void 0) {
965
+ return new ProviderError({
966
+ code: codeFromStatus(status),
967
+ message,
968
+ providerId,
969
+ status,
970
+ retryAfterMs,
971
+ ...declared !== void 0 ? { retryable: declared } : {},
972
+ cause: err
973
+ });
974
+ }
975
+ if (errno !== void 0) {
976
+ const certificate = readCertificateFailure(err);
977
+ if (certificate !== void 0) {
978
+ return new ProviderError({
979
+ code: "network",
980
+ message,
981
+ providerId,
982
+ retryable: false,
983
+ cause: err
984
+ });
985
+ }
986
+ if (TIMEOUT_ERRNOS.has(errno)) {
987
+ return new ProviderError({
988
+ code: "timeout",
989
+ message,
990
+ providerId,
991
+ retryable: declared,
992
+ cause: err
993
+ });
994
+ }
995
+ if (NETWORK_ERRNOS.has(errno) || isTransientTransportCode(errno)) {
996
+ return new ProviderError({
997
+ code: "network",
998
+ message,
999
+ providerId,
1000
+ retryable: declared,
1001
+ cause: err
1002
+ });
1003
+ }
1004
+ }
1005
+ if (err instanceof TypeError && /fetch|network/i.test(message) || isUndiciTermination(err)) {
1006
+ return new ProviderError({
1007
+ code: "network",
1008
+ message,
1009
+ providerId,
1010
+ retryable: declared,
1011
+ cause: err
1012
+ });
1013
+ }
1014
+ return new ProviderError({
1015
+ code: fromMessage ?? "unknown",
1016
+ message,
1017
+ providerId,
1018
+ retryAfterMs,
1019
+ retryable: declared,
1020
+ cause: err
1021
+ });
1022
+ }
1023
+ __name(classifyProviderError, "classifyProviderError");
1024
+
1025
+ // ../sdk/dist/types/errors/index.js
1026
+ var RETRYABLE2 = /* @__PURE__ */ new Set(["storage_error"]);
1027
+ var NamzuError = class extends Error {
1028
+ static {
1029
+ __name(this, "NamzuError");
1030
+ }
1031
+ code;
1032
+ details;
1033
+ retryable;
1034
+ constructor(init) {
1035
+ super(init.message, init.cause !== void 0 ? { cause: init.cause } : void 0);
1036
+ this.name = "NamzuError";
1037
+ this.code = init.code;
1038
+ this.details = init.details;
1039
+ this.retryable = init.retryable ?? RETRYABLE2.has(init.code);
1040
+ }
1041
+ };
1042
+ function isNamzuError(err) {
1043
+ return err instanceof NamzuError;
1044
+ }
1045
+ __name(isNamzuError, "isNamzuError");
1046
+ function toPlatformError(err) {
1047
+ if (isNamzuError(err)) {
1048
+ return {
1049
+ code: err.code,
1050
+ message: err.message,
1051
+ ...err.details ? { details: err.details } : {},
1052
+ retryable: err.retryable
1053
+ };
1054
+ }
1055
+ const providerFailure = err instanceof ProviderError ? err : err instanceof Error && err.name === "ProviderRequestError" ? classifyProviderError(err) : void 0;
1056
+ if (providerFailure) {
1057
+ return {
1058
+ code: "provider_error",
1059
+ message: providerFailure.message,
1060
+ details: {
1061
+ providerCode: providerFailure.code,
1062
+ ...providerFailure.providerId !== void 0 ? { providerId: providerFailure.providerId } : {},
1063
+ ...providerFailure.status !== void 0 ? { status: providerFailure.status } : {},
1064
+ ...providerFailure.retryAfterMs !== void 0 ? { retryAfterMs: providerFailure.retryAfterMs } : {}
1065
+ },
1066
+ retryable: providerFailure.retryable
1067
+ };
1068
+ }
1069
+ if (err instanceof Error) {
1070
+ return { code: "unknown", message: err.message, retryable: false };
1071
+ }
1072
+ return { code: "unknown", message: String(err), retryable: false };
1073
+ }
1074
+ __name(toPlatformError, "toPlatformError");
1075
+
579
1076
  // ../sdk/dist/tools/command-shell.js
580
1077
  import { execFileSync as execFileSync2, spawn as nodeSpawn } from "node:child_process";
581
1078
  import { randomUUID } from "node:crypto";
@@ -6685,6 +7182,74 @@ var BackgroundJobRegistry = class {
6685
7182
  monitorListeners = /* @__PURE__ */ new Set();
6686
7183
  outputWaiters = 0;
6687
7184
  outputWaitersByOwner = /* @__PURE__ */ new Map();
7185
+ foreground = /* @__PURE__ */ new Map();
7186
+ foregroundListeners = /* @__PURE__ */ new Set();
7187
+ foregroundSeq = 0;
7188
+ /**
7189
+ * A foreground command a tool is waiting on, offered for hand-over: while it
7190
+ * is registered, {@link backgroundForeground} can move it to a job. The tool
7191
+ * registers once the command has run long enough that moving it is worth
7192
+ * offering, and unregisters (the returned function) when the call settles.
7193
+ * `background` returns whether the command was taken over.
7194
+ */
7195
+ registerForeground(owner, entry) {
7196
+ const id3 = `fg-${++this.foregroundSeq}`;
7197
+ this.foreground.set(id3, {
7198
+ id: id3,
7199
+ owner,
7200
+ command: entry.command,
7201
+ startedAt: Date.now(),
7202
+ background: entry.background
7203
+ });
7204
+ this.announceForeground(owner);
7205
+ return () => {
7206
+ if (this.foreground.delete(id3))
7207
+ this.announceForeground(owner);
7208
+ };
7209
+ }
7210
+ /** Foreground commands of one owner that can be moved to the background, oldest first. */
7211
+ foregroundCommands(owner) {
7212
+ return [...this.foreground.values()].filter((entry) => entry.owner === owner).map(({ id: id3, command, startedAt }) => ({ id: id3, owner, command, startedAt }));
7213
+ }
7214
+ /**
7215
+ * Move every foreground command of `owner` to the background. Returns how
7216
+ * many were taken over; a command that ended or could not be taken over
7217
+ * keeps its own outcome and is not counted.
7218
+ */
7219
+ backgroundForeground(owner, reason2) {
7220
+ let moved = 0;
7221
+ for (const entry of [...this.foreground.values()]) {
7222
+ if (entry.owner !== owner)
7223
+ continue;
7224
+ let taken = false;
7225
+ try {
7226
+ taken = entry.background(reason2);
7227
+ } catch {
7228
+ }
7229
+ if (taken) {
7230
+ moved += 1;
7231
+ this.foreground.delete(entry.id);
7232
+ }
7233
+ }
7234
+ if (moved > 0)
7235
+ this.announceForeground(owner);
7236
+ return moved;
7237
+ }
7238
+ /** Be told when the set of hand-over-able foreground commands of any owner changes. */
7239
+ onForegroundChange(listener) {
7240
+ this.foregroundListeners.add(listener);
7241
+ return () => {
7242
+ this.foregroundListeners.delete(listener);
7243
+ };
7244
+ }
7245
+ announceForeground(owner) {
7246
+ for (const listener of this.foregroundListeners) {
7247
+ try {
7248
+ listener(owner);
7249
+ } catch {
7250
+ }
7251
+ }
7252
+ }
6688
7253
  /**
6689
7254
  * Be told when a job ends, whoever owns it. A job outlives the call that
6690
7255
  * started it, so the one thing the model could not do was learn that it
@@ -7387,6 +7952,9 @@ function bindOwner(registry, owner, defaults2 = {}) {
7387
7952
  hostOutput: true,
7388
7953
  ...params.initialOutput ? { initialOutput: params.initialOutput } : {}
7389
7954
  }), "adopt"),
7955
+ // The owner is bound here, so a tool can offer its own waiting command and
7956
+ // no other turn's.
7957
+ registerForeground: /* @__PURE__ */ __name((entry) => registry.registerForeground(owner, entry), "registerForeground"),
7390
7958
  get: /* @__PURE__ */ __name((id3) => mine(id3), "get"),
7391
7959
  awaitStarted: /* @__PURE__ */ __name((id3) => {
7392
7960
  mine(id3);
@@ -9149,426 +9717,6 @@ import { link, mkdir, unlink as unlink2, writeFile as writeFile2 } from "node:fs
9149
9717
  import { dirname, join as join3 } from "node:path";
9150
9718
  import { isDeepStrictEqual } from "node:util";
9151
9719
 
9152
- // ../sdk/dist/types/provider/errors.js
9153
- function shouldRetryHeader(link6) {
9154
- const headers = link6.headers;
9155
- if (!headers || typeof headers !== "object")
9156
- return void 0;
9157
- const raw = typeof headers.get === "function" ? headers.get("x-should-retry") : headers["x-should-retry"];
9158
- return typeof raw === "string" && raw.trim().toLowerCase() === "false" ? false : void 0;
9159
- }
9160
- __name(shouldRetryHeader, "shouldRetryHeader");
9161
- function declaredRetryable(err) {
9162
- for (const link6 of causeChain(err)) {
9163
- const declared = link6.retryable;
9164
- if (typeof declared === "boolean")
9165
- return declared;
9166
- if (shouldRetryHeader(link6) === false)
9167
- return false;
9168
- }
9169
- return void 0;
9170
- }
9171
- __name(declaredRetryable, "declaredRetryable");
9172
- var RETRYABLE = /* @__PURE__ */ new Set([
9173
- "rate_limit",
9174
- "overloaded",
9175
- "server_error",
9176
- "timeout",
9177
- "network"
9178
- ]);
9179
- var ProviderError = class extends Error {
9180
- static {
9181
- __name(this, "ProviderError");
9182
- }
9183
- code;
9184
- providerId;
9185
- status;
9186
- retryAfterMs;
9187
- retryable;
9188
- constructor(init) {
9189
- super(init.message, init.cause !== void 0 ? { cause: init.cause } : void 0);
9190
- this.name = "ProviderError";
9191
- this.code = init.code;
9192
- this.providerId = init.providerId;
9193
- this.status = init.status;
9194
- this.retryAfterMs = init.retryAfterMs;
9195
- this.retryable = init.retryable ?? RETRYABLE.has(init.code);
9196
- }
9197
- };
9198
- function isProviderError(err) {
9199
- return err instanceof ProviderError;
9200
- }
9201
- __name(isProviderError, "isProviderError");
9202
- function isAbortError(err) {
9203
- if (err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError")) {
9204
- return true;
9205
- }
9206
- const name2 = err?.name;
9207
- return name2 === "AbortError";
9208
- }
9209
- __name(isAbortError, "isAbortError");
9210
- function* causeChain(err) {
9211
- const seen = /* @__PURE__ */ new Set();
9212
- let current = err;
9213
- while (current !== null && typeof current === "object" && !seen.has(current)) {
9214
- seen.add(current);
9215
- yield current;
9216
- current = current.cause;
9217
- }
9218
- }
9219
- __name(causeChain, "causeChain");
9220
- function readStatus(err) {
9221
- for (const link6 of causeChain(err)) {
9222
- const e = link6;
9223
- for (const candidate of [
9224
- e.status,
9225
- e.statusCode,
9226
- e.response?.status,
9227
- e.$metadata?.httpStatusCode
9228
- ]) {
9229
- if (typeof candidate === "number" && Number.isFinite(candidate))
9230
- return candidate;
9231
- }
9232
- }
9233
- return void 0;
9234
- }
9235
- __name(readStatus, "readStatus");
9236
- function readRetryAfterMs(err, now) {
9237
- for (const link6 of causeChain(err)) {
9238
- const headers = link6.headers;
9239
- if (!headers)
9240
- continue;
9241
- let raw;
9242
- if (typeof headers.get === "function") {
9243
- raw = headers.get("retry-after") ?? void 0;
9244
- } else if (typeof headers === "object") {
9245
- const bag = headers;
9246
- const value = bag["retry-after"] ?? bag["Retry-After"];
9247
- if (typeof value === "string" || typeof value === "number")
9248
- raw = String(value);
9249
- }
9250
- if (raw === void 0)
9251
- continue;
9252
- const seconds = Number(raw);
9253
- if (Number.isFinite(seconds) && seconds >= 0)
9254
- return Math.round(seconds * 1e3);
9255
- const at = Date.parse(raw);
9256
- if (Number.isFinite(at))
9257
- return Math.max(0, at - now);
9258
- }
9259
- return void 0;
9260
- }
9261
- __name(readRetryAfterMs, "readRetryAfterMs");
9262
- function readErrnoCode(err) {
9263
- for (const link6 of causeChain(err)) {
9264
- if (typeof link6.code === "string")
9265
- return link6.code;
9266
- }
9267
- return void 0;
9268
- }
9269
- __name(readErrnoCode, "readErrnoCode");
9270
- function chainMessages(err) {
9271
- const out = [];
9272
- for (const link6 of causeChain(err)) {
9273
- if (typeof link6.message === "string" && link6.message.length > 0)
9274
- out.push(link6.message);
9275
- }
9276
- return out;
9277
- }
9278
- __name(chainMessages, "chainMessages");
9279
- function readOutputOverflow(err) {
9280
- const pattern = /input length and `?max_tokens`? exceed context limit: (\d+) \+ (\d+) > (\d+)/i;
9281
- for (const message of chainMessages(err)) {
9282
- const match2 = pattern.exec(message);
9283
- if (!match2)
9284
- continue;
9285
- const inputTokens = Number.parseInt(match2[1] ?? "", 10);
9286
- const maxTokens = Number.parseInt(match2[2] ?? "", 10);
9287
- const contextLimit = Number.parseInt(match2[3] ?? "", 10);
9288
- if (![inputTokens, maxTokens, contextLimit].every(Number.isFinite))
9289
- continue;
9290
- return { inputTokens, maxTokens, contextLimit };
9291
- }
9292
- return void 0;
9293
- }
9294
- __name(readOutputOverflow, "readOutputOverflow");
9295
- function isUndiciTermination(err) {
9296
- for (const link6 of causeChain(err)) {
9297
- if (link6 instanceof TypeError && link6.message === "terminated")
9298
- return true;
9299
- }
9300
- return false;
9301
- }
9302
- __name(isUndiciTermination, "isUndiciTermination");
9303
- var NETWORK_ERRNOS = /* @__PURE__ */ new Set([
9304
- "ECONNRESET",
9305
- "ECONNREFUSED",
9306
- "ECONNABORTED",
9307
- "EPIPE",
9308
- "EHOSTUNREACH",
9309
- "ENETUNREACH",
9310
- "ENOTFOUND",
9311
- "EAI_AGAIN",
9312
- "EPROTO",
9313
- "UND_ERR_SOCKET",
9314
- "UND_ERR_CONNECT_TIMEOUT",
9315
- "UND_ERR_RESPONSE_STATUS_CODE"
9316
- ]);
9317
- var TIMEOUT_ERRNOS = /* @__PURE__ */ new Set([
9318
- "ETIMEDOUT",
9319
- "ESOCKETTIMEDOUT",
9320
- "UND_ERR_HEADERS_TIMEOUT",
9321
- "UND_ERR_BODY_TIMEOUT"
9322
- ]);
9323
- function codeFromStatus(status) {
9324
- if (status === 429)
9325
- return "rate_limit";
9326
- if (status === 401 || status === 403)
9327
- return "auth";
9328
- if (status === 404)
9329
- return "not_found";
9330
- if (status === 408)
9331
- return "timeout";
9332
- if (status === 529 || status === 503)
9333
- return "overloaded";
9334
- if (status >= 500)
9335
- return "server_error";
9336
- if (status >= 400)
9337
- return "invalid_request";
9338
- return "unknown";
9339
- }
9340
- __name(codeFromStatus, "codeFromStatus");
9341
- function overflowWordingAllowed(status) {
9342
- return status === void 0 || status === 400 || status === 413;
9343
- }
9344
- __name(overflowWordingAllowed, "overflowWordingAllowed");
9345
- var CONTEXT_WINDOW_OVERFLOW = /(?:exceed\w*|too (?:long|large|big)|larger than|longer than|over the|beyond|maximum|overflow\w*)\b[^.]{0,60}context window|context window[^.]{0,60}\b(?:exceed\w*|too (?:long|large|big)|larger than|longer than|over the|beyond|maximum|overflow\w*)/i;
9346
- function codeFromMessage(message, status) {
9347
- const m = message.toLowerCase();
9348
- if (m.includes("context length") || m.includes("context_length") || m.includes("maximum context") || m.includes("too many tokens") || m.includes("prompt is too long") || // Real wordings that missed every phrase above and so classified as
9349
- // a plain invalid request — which is not retryable, and which the
9350
- // overflow rescue tests for by exact equality. The turn died holding
9351
- // the remedy.
9352
- m.includes("too long for") || // Known wordings: `context window` and
9353
- // `input length and max_tokens exceed context limit` matchers).
9354
- // Only where the status cannot say otherwise: a 429, 5xx or 401 that
9355
- // mentions the window is still a rate limit, a server fault or an auth
9356
- // failure, and must keep its retry and fallback behaviour.
9357
- overflowWordingAllowed(status) && (CONTEXT_WINDOW_OVERFLOW.test(message) || m.includes("exceed context limit")) || m.includes("maximum length") || m.includes("exceeds the maximum") || m.includes("input is too large") || m.includes("too large for")) {
9358
- return "context_length_exceeded";
9359
- }
9360
- if (m.includes("rate limit") || m.includes("rate_limit") || m.includes("too many requests")) {
9361
- return "rate_limit";
9362
- }
9363
- if (m.includes("overloaded"))
9364
- return "overloaded";
9365
- if (m.includes("content filter") || m.includes("content_filter") || m.includes("content policy")) {
9366
- return "content_filter";
9367
- }
9368
- if (m.includes("timed out") || m.includes("timeout"))
9369
- return "timeout";
9370
- if (m.includes("unauthorized") || m.includes("invalid api key") || m.includes("authentication")) {
9371
- return "auth";
9372
- }
9373
- return void 0;
9374
- }
9375
- __name(codeFromMessage, "codeFromMessage");
9376
- var STRUCTURAL_CODES = {
9377
- context_length_exceeded: "context_length_exceeded",
9378
- context_window_exceeded: "context_length_exceeded",
9379
- max_tokens_exceeded: "context_length_exceeded",
9380
- string_above_max_length: "context_length_exceeded",
9381
- rate_limit_exceeded: "rate_limit",
9382
- rate_limit_error: "rate_limit",
9383
- insufficient_quota: "rate_limit",
9384
- overloaded_error: "overloaded",
9385
- content_filter: "content_filter",
9386
- content_policy_violation: "content_filter",
9387
- invalid_api_key: "auth",
9388
- authentication_error: "auth",
9389
- permission_error: "auth",
9390
- model_not_found: "not_found"
9391
- };
9392
- function codeFromStructure(err) {
9393
- for (const link6 of causeChain(err)) {
9394
- for (const field2 of [link6.code, link6.type, link6.error?.type]) {
9395
- if (typeof field2 !== "string")
9396
- continue;
9397
- const mapped = STRUCTURAL_CODES[field2.toLowerCase()];
9398
- if (mapped)
9399
- return mapped;
9400
- }
9401
- }
9402
- return void 0;
9403
- }
9404
- __name(codeFromStructure, "codeFromStructure");
9405
- var KIND_TO_CODE = {
9406
- throttle: { code: "rate_limit", retryable: true },
9407
- network: { code: "network", retryable: true },
9408
- server: { code: "server_error", retryable: true },
9409
- auth: { code: "auth", retryable: false },
9410
- context_overflow: { code: "context_length_exceeded", retryable: false },
9411
- bad_request: { code: "invalid_request", retryable: false }
9412
- };
9413
- function classifyFromProviderRequestError(err, providerId, now) {
9414
- if (!(err instanceof Error) || err.name !== "ProviderRequestError")
9415
- return void 0;
9416
- const candidate = err;
9417
- if (typeof candidate.kind !== "string")
9418
- return void 0;
9419
- const mapped = KIND_TO_CODE[candidate.kind];
9420
- if (!mapped)
9421
- return void 0;
9422
- const retryAfterMs = typeof candidate.retryAfterMs === "number" ? candidate.retryAfterMs : readRetryAfterMs(err, now);
9423
- return new ProviderError({
9424
- code: mapped.code,
9425
- message: err.message,
9426
- // The provider saying "do not resend" beats the kind's own verdict.
9427
- retryable: candidate.shouldRetry === false ? false : mapped.retryable,
9428
- cause: err,
9429
- ...typeof candidate.providerId === "string" ? { providerId: candidate.providerId } : providerId !== void 0 ? { providerId } : {},
9430
- ...typeof candidate.status === "number" ? { status: candidate.status } : {},
9431
- ...retryAfterMs !== void 0 ? { retryAfterMs } : {}
9432
- });
9433
- }
9434
- __name(classifyFromProviderRequestError, "classifyFromProviderRequestError");
9435
- function classifyProviderError(err, providerId, now = Date.now()) {
9436
- if (isProviderError(err))
9437
- return err;
9438
- const fromKind = classifyFromProviderRequestError(err, providerId, now);
9439
- if (fromKind)
9440
- return fromKind;
9441
- const message = err instanceof Error ? err.message : String(err);
9442
- const status = readStatus(err);
9443
- const errno = readErrnoCode(err);
9444
- const retryAfterMs = readRetryAfterMs(err, now);
9445
- const messages = chainMessages(err);
9446
- const fromMessage = messages.map((m) => codeFromMessage(m, status)).find((code) => code !== void 0);
9447
- const declared = declaredRetryable(err);
9448
- const structural = codeFromStructure(err);
9449
- if (structural !== void 0) {
9450
- return new ProviderError({
9451
- code: structural,
9452
- message,
9453
- providerId,
9454
- ...status !== void 0 ? { status } : {},
9455
- ...retryAfterMs !== void 0 ? { retryAfterMs } : {},
9456
- ...declared !== void 0 ? { retryable: declared } : {},
9457
- cause: err
9458
- });
9459
- }
9460
- if (messages.some((m) => codeFromMessage(m, status) === "context_length_exceeded")) {
9461
- return new ProviderError({
9462
- code: "context_length_exceeded",
9463
- message,
9464
- providerId,
9465
- status,
9466
- ...declared !== void 0 ? { retryable: declared } : {},
9467
- cause: err
9468
- });
9469
- }
9470
- if (status !== void 0) {
9471
- return new ProviderError({
9472
- code: codeFromStatus(status),
9473
- message,
9474
- providerId,
9475
- status,
9476
- retryAfterMs,
9477
- ...declared !== void 0 ? { retryable: declared } : {},
9478
- cause: err
9479
- });
9480
- }
9481
- if (errno !== void 0) {
9482
- if (TIMEOUT_ERRNOS.has(errno)) {
9483
- return new ProviderError({
9484
- code: "timeout",
9485
- message,
9486
- providerId,
9487
- retryable: declared,
9488
- cause: err
9489
- });
9490
- }
9491
- if (NETWORK_ERRNOS.has(errno)) {
9492
- return new ProviderError({
9493
- code: "network",
9494
- message,
9495
- providerId,
9496
- retryable: declared,
9497
- cause: err
9498
- });
9499
- }
9500
- }
9501
- if (err instanceof TypeError && /fetch|network/i.test(message) || isUndiciTermination(err)) {
9502
- return new ProviderError({
9503
- code: "network",
9504
- message,
9505
- providerId,
9506
- retryable: declared,
9507
- cause: err
9508
- });
9509
- }
9510
- return new ProviderError({
9511
- code: fromMessage ?? "unknown",
9512
- message,
9513
- providerId,
9514
- retryAfterMs,
9515
- retryable: declared,
9516
- cause: err
9517
- });
9518
- }
9519
- __name(classifyProviderError, "classifyProviderError");
9520
-
9521
- // ../sdk/dist/types/errors/index.js
9522
- var RETRYABLE2 = /* @__PURE__ */ new Set(["storage_error"]);
9523
- var NamzuError = class extends Error {
9524
- static {
9525
- __name(this, "NamzuError");
9526
- }
9527
- code;
9528
- details;
9529
- retryable;
9530
- constructor(init) {
9531
- super(init.message, init.cause !== void 0 ? { cause: init.cause } : void 0);
9532
- this.name = "NamzuError";
9533
- this.code = init.code;
9534
- this.details = init.details;
9535
- this.retryable = init.retryable ?? RETRYABLE2.has(init.code);
9536
- }
9537
- };
9538
- function isNamzuError(err) {
9539
- return err instanceof NamzuError;
9540
- }
9541
- __name(isNamzuError, "isNamzuError");
9542
- function toPlatformError(err) {
9543
- if (isNamzuError(err)) {
9544
- return {
9545
- code: err.code,
9546
- message: err.message,
9547
- ...err.details ? { details: err.details } : {},
9548
- retryable: err.retryable
9549
- };
9550
- }
9551
- const providerFailure = err instanceof ProviderError ? err : err instanceof Error && err.name === "ProviderRequestError" ? classifyProviderError(err) : void 0;
9552
- if (providerFailure) {
9553
- return {
9554
- code: "provider_error",
9555
- message: providerFailure.message,
9556
- details: {
9557
- providerCode: providerFailure.code,
9558
- ...providerFailure.providerId !== void 0 ? { providerId: providerFailure.providerId } : {},
9559
- ...providerFailure.status !== void 0 ? { status: providerFailure.status } : {},
9560
- ...providerFailure.retryAfterMs !== void 0 ? { retryAfterMs: providerFailure.retryAfterMs } : {}
9561
- },
9562
- retryable: providerFailure.retryable
9563
- };
9564
- }
9565
- if (err instanceof Error) {
9566
- return { code: "unknown", message: err.message, retryable: false };
9567
- }
9568
- return { code: "unknown", message: String(err), retryable: false };
9569
- }
9570
- __name(toPlatformError, "toPlatformError");
9571
-
9572
9720
  // ../sdk/dist/utils/atomic-write.js
9573
9721
  import { randomBytes as randomBytes3 } from "node:crypto";
9574
9722
  import { open, rename, unlink, writeFile } from "node:fs/promises";
@@ -15925,6 +16073,8 @@ var ProviderRequestError = class extends Error {
15925
16073
  detail;
15926
16074
  /** The provider's `x-should-retry` verdict, when it sent one; see {@link ProviderRequestErrorInit.shouldRetry}. */
15927
16075
  shouldRetry;
16076
+ /** The part of the network path the request tripped on, when known; see {@link ProviderRequestErrorInit.transport}. */
16077
+ transport;
15928
16078
  constructor(init) {
15929
16079
  super(buildProviderErrorMessage(init));
15930
16080
  this.name = "ProviderRequestError";
@@ -15941,6 +16091,8 @@ var ProviderRequestError = class extends Error {
15941
16091
  this.detail = init.detail;
15942
16092
  if (init.shouldRetry !== void 0)
15943
16093
  this.shouldRetry = init.shouldRetry;
16094
+ if (init.transport !== void 0)
16095
+ this.transport = init.transport;
15944
16096
  }
15945
16097
  };
15946
16098
  var DETAIL_MAX = 400;
@@ -16211,8 +16363,11 @@ function providerVendorError(input) {
16211
16363
  const exactProviderCode = providerCode(error);
16212
16364
  const name2 = error instanceof Error ? error.name : "";
16213
16365
  const message = error instanceof Error ? error.message : "";
16366
+ const transport = readTransportCause(error);
16214
16367
  let kind;
16215
- if (/ThrottlingException|TooManyRequests|ServiceQuotaExceeded/i.test(name2)) {
16368
+ if (transport !== void 0) {
16369
+ kind = "network";
16370
+ } else if (/ThrottlingException|TooManyRequests|ServiceQuotaExceeded/i.test(name2)) {
16216
16371
  kind = "throttle";
16217
16372
  } else if (/AccessDenied|Unauthorized|Forbidden|Authentication/i.test(name2)) {
16218
16373
  kind = "auth";
@@ -16230,7 +16385,8 @@ function providerVendorError(input) {
16230
16385
  kind = vendorTypeKind(message) ?? "network";
16231
16386
  }
16232
16387
  const retryAfterMs = parseRetryAfterMs(input.retryAfter ?? vendorRetryAfter(error), input.now ?? Date.now());
16233
- const shouldRetry = parseShouldRetry(vendorHeader(error, ["x-should-retry"]));
16388
+ const certificate = status === void 0 ? readCertificateFailure(error) : void 0;
16389
+ const shouldRetry = transport !== void 0 || certificate !== void 0 ? false : parseShouldRetry(vendorHeader(error, ["x-should-retry"]));
16234
16390
  const fields2 = error;
16235
16391
  const detail = carriesBody(message) ? vendorDetail(message) : structuredVendorDetail({
16236
16392
  message,
@@ -16242,11 +16398,12 @@ function providerVendorError(input) {
16242
16398
  return new ProviderRequestError({
16243
16399
  kind,
16244
16400
  providerId: input.providerId,
16245
- ...exactProviderCode !== void 0 ? { providerCode: exactProviderCode } : {},
16401
+ ...certificate !== void 0 ? { providerCode: certificate } : exactProviderCode !== void 0 ? { providerCode: exactProviderCode } : {},
16246
16402
  ...status !== void 0 ? { status } : {},
16247
16403
  ...retryAfterMs !== void 0 ? { retryAfterMs } : {},
16248
16404
  ...detail !== void 0 ? { detail } : {},
16249
- ...shouldRetry !== void 0 ? { shouldRetry } : {}
16405
+ ...shouldRetry !== void 0 ? { shouldRetry } : {},
16406
+ ...transport !== void 0 ? { transport } : {}
16250
16407
  });
16251
16408
  }
16252
16409
  __name(providerVendorError, "providerVendorError");
@@ -24539,7 +24696,33 @@ function createFileReadTracker() {
24539
24696
  }
24540
24697
  }
24541
24698
  __name(observe, "observe");
24699
+ const windows = /* @__PURE__ */ new Map();
24700
+ const MAX_WINDOWS_PER_FILE = 6;
24701
+ const MAX_WINDOWED_FILES = 512;
24542
24702
  return {
24703
+ recordReadWindow(key5, window2, entry) {
24704
+ let forFile = windows.get(key5);
24705
+ if (forFile)
24706
+ windows.delete(key5);
24707
+ else
24708
+ forFile = /* @__PURE__ */ new Map();
24709
+ forFile.delete(window2);
24710
+ forFile.set(window2, entry);
24711
+ while (forFile.size > MAX_WINDOWS_PER_FILE) {
24712
+ const oldest = forFile.keys().next().value;
24713
+ if (oldest === void 0)
24714
+ break;
24715
+ forFile.delete(oldest);
24716
+ }
24717
+ windows.set(key5, forFile);
24718
+ while (windows.size > MAX_WINDOWED_FILES) {
24719
+ const oldest = windows.keys().next().value;
24720
+ if (oldest === void 0)
24721
+ break;
24722
+ windows.delete(oldest);
24723
+ }
24724
+ },
24725
+ readWindow: /* @__PURE__ */ __name((key5, window2) => windows.get(key5)?.get(window2), "readWindow"),
24543
24726
  recordRead: observe,
24544
24727
  recordFullRead(key5, content, callId, renderedFingerprint) {
24545
24728
  observe(key5, content);
@@ -27215,7 +27398,10 @@ var ReadFileTool = defineTool({
27215
27398
  if (!capped2.ok)
27216
27399
  return refusedRead(input.path, buffer2.length, capped2.message, true);
27217
27400
  const rendered2 = capped2.rendered;
27218
- recordObservedRead(context2, input.path, content2, rendered2);
27401
+ const unchanged2 = unchangedRead(context2, input.path, input, content2, buffer2.length);
27402
+ if (unchanged2)
27403
+ return unchanged2;
27404
+ recordObservedRead(context2, input.path, content2, rendered2, input);
27219
27405
  return {
27220
27406
  success: true,
27221
27407
  output: rendered2.output,
@@ -27261,7 +27447,10 @@ var ReadFileTool = defineTool({
27261
27447
  if (!capped.ok)
27262
27448
  return refusedRead(filePath, buffer.length, capped.message, false);
27263
27449
  const rendered = capped.rendered;
27264
- recordObservedRead(context2, filePath, content, rendered);
27450
+ const unchanged = retained === void 0 ? unchangedRead(context2, filePath, input, content, buffer.length) : void 0;
27451
+ if (unchanged)
27452
+ return unchanged;
27453
+ recordObservedRead(context2, filePath, content, rendered, input);
27265
27454
  return {
27266
27455
  success: true,
27267
27456
  output: rendered.output,
@@ -27316,17 +27505,47 @@ function readFacts(path2, buffer, content, rendered) {
27316
27505
  };
27317
27506
  }
27318
27507
  __name(readFacts, "readFacts");
27319
- function recordObservedRead(context2, key5, content, rendered) {
27508
+ function recordObservedRead(context2, key5, content, rendered, input) {
27320
27509
  const tracker = context2.fileReadTracker;
27321
27510
  if (!tracker)
27322
27511
  return;
27323
27512
  if (!rendered.partial && tracker.recordFullRead && context2.toolUseId) {
27324
27513
  tracker.recordFullRead(key5, content, context2.toolUseId, fingerprintContent(rendered.output));
27325
- return;
27514
+ } else {
27515
+ tracker.recordRead(key5, content);
27516
+ }
27517
+ if (tracker.recordReadWindow && context2.toolUseId) {
27518
+ tracker.recordReadWindow(key5, windowKey(input), {
27519
+ callId: context2.toolUseId,
27520
+ renderedFingerprint: fingerprintContent(rendered.output),
27521
+ contentFingerprint: fingerprintContent(content)
27522
+ });
27326
27523
  }
27327
- tracker.recordRead(key5, content);
27328
27524
  }
27329
27525
  __name(recordObservedRead, "recordObservedRead");
27526
+ function windowKey(input) {
27527
+ const range = input.readRange;
27528
+ const lines = range ? `r${range[0]}-${range[1]}` : `o${input.offset ?? 0}l${input.limit === void 0 ? "all" : input.limit}`;
27529
+ return input.allow_large === true ? `${lines}+large` : lines;
27530
+ }
27531
+ __name(windowKey, "windowKey");
27532
+ function unchangedRead(context2, key5, input, content, bytes) {
27533
+ const tracker = context2.fileReadTracker;
27534
+ if (!tracker?.readWindow || !context2.receiptVisible)
27535
+ return void 0;
27536
+ const earlier = tracker.readWindow(key5, windowKey(input));
27537
+ if (!earlier || earlier.contentFingerprint !== fingerprintContent(content))
27538
+ return void 0;
27539
+ if (!context2.receiptVisible(earlier.callId, earlier.renderedFingerprint))
27540
+ return void 0;
27541
+ return {
27542
+ success: true,
27543
+ output: "Unchanged since your earlier read of the same lines. That result is still current; use it instead of reading again.",
27544
+ data: { path: key5, unchanged: true },
27545
+ facts: { kind: "read", path: key5, bytes, unchanged: true }
27546
+ };
27547
+ }
27548
+ __name(unchangedRead, "unchangedRead");
27330
27549
  function describeStructuredBinaryRead(path2, buffer) {
27331
27550
  const ext2 = extname2(path2).toLowerCase();
27332
27551
  const image = buffer.subarray(0, 8).equals(Buffer.from("89504e470d0a1a0a", "hex")) ? "PNG" : buffer[0] === 255 && buffer[1] === 216 ? "JPEG" : buffer.toString("ascii", 0, 4) === "RIFF" && buffer.toString("ascii", 8, 12) === "WEBP" ? "WebP" : null;
@@ -30100,7 +30319,16 @@ function validateToolCallIds(messages) {
30100
30319
  }
30101
30320
  }
30102
30321
  __name(validateToolCallIds, "validateToolCallIds");
30103
- function unknownOutcomeResult(call2, assistant) {
30322
+ function unknownOutcomeResult(call2, assistant, neverRan) {
30323
+ if (neverRan) {
30324
+ return {
30325
+ role: CONSTANTS.TOOL_ROLE,
30326
+ toolCallId: call2.id,
30327
+ isError: true,
30328
+ content: `The \`${call2.function.name}\` call did not run: the session ended before it started (it may have been waiting for the user's approval, which was never given). Nothing was changed. If it is still needed, call it again.`,
30329
+ ...assistant.timestamp !== void 0 ? { timestamp: assistant.timestamp } : {}
30330
+ };
30331
+ }
30104
30332
  return {
30105
30333
  role: CONSTANTS.TOOL_ROLE,
30106
30334
  toolCallId: call2.id,
@@ -30110,12 +30338,13 @@ function unknownOutcomeResult(call2, assistant) {
30110
30338
  };
30111
30339
  }
30112
30340
  __name(unknownOutcomeResult, "unknownOutcomeResult");
30113
- function repairToolMessageHistory(messages) {
30341
+ function repairToolMessageHistory(messages, options = {}) {
30114
30342
  validateToolCallIds(messages);
30115
30343
  const repaired = [];
30116
30344
  let duplicateToolResultsRemoved = 0;
30117
30345
  let orphanedToolResultsRemoved = 0;
30118
30346
  let syntheticToolResultsInserted = 0;
30347
+ let neverRanToolResultsInserted = 0;
30119
30348
  let index = 0;
30120
30349
  while (index < messages.length) {
30121
30350
  const message = messages[index];
@@ -30165,8 +30394,11 @@ function repairToolMessageHistory(messages) {
30165
30394
  for (const call2 of calls) {
30166
30395
  if (answered.has(call2.id))
30167
30396
  continue;
30168
- repaired.push(unknownOutcomeResult(call2, assistant));
30397
+ const neverRan = options.neverRan?.has(call2.id) === true;
30398
+ repaired.push(unknownOutcomeResult(call2, assistant, neverRan));
30169
30399
  syntheticToolResultsInserted++;
30400
+ if (neverRan)
30401
+ neverRanToolResultsInserted++;
30170
30402
  }
30171
30403
  index = resultEnd;
30172
30404
  }
@@ -30175,7 +30407,8 @@ function repairToolMessageHistory(messages) {
30175
30407
  report: {
30176
30408
  duplicateToolResultsRemoved,
30177
30409
  orphanedToolResultsRemoved,
30178
- syntheticToolResultsInserted
30410
+ syntheticToolResultsInserted,
30411
+ ...neverRanToolResultsInserted > 0 ? { neverRanToolResultsInserted } : {}
30179
30412
  }
30180
30413
  };
30181
30414
  }
@@ -30280,6 +30513,9 @@ var SECTION_HEADERS = {
30280
30513
  };
30281
30514
 
30282
30515
  // ../sdk/dist/compaction/manager.js
30516
+ var MAX_RESTORABLE_SKILLS = 8;
30517
+ var MAX_RESTORABLE_FILES = 12;
30518
+ var MAX_RESTORABLE_CHARS = 24e3;
30283
30519
  var MAX_PINS = 40;
30284
30520
  var MAX_PIN_CHARS = 600;
30285
30521
  function truncateStateText(text10, max) {
@@ -30293,6 +30529,10 @@ function truncateStateText(text10, max) {
30293
30529
  return `${head2}${marker}`;
30294
30530
  }
30295
30531
  __name(truncateStateText, "truncateStateText");
30532
+ function normalizeRestorablePath(path2) {
30533
+ return path2.trim().replace(/^\.\//, "");
30534
+ }
30535
+ __name(normalizeRestorablePath, "normalizeRestorablePath");
30296
30536
  function createEmptyState() {
30297
30537
  return {
30298
30538
  task: "",
@@ -30359,6 +30599,52 @@ var WorkingStateManager = class {
30359
30599
  this.state.files.set(path2, { path: path2, actions: [action] });
30360
30600
  }
30361
30601
  }
30602
+ restorableState() {
30603
+ if (!this.state.restorable)
30604
+ this.state.restorable = { skills: [], files: [] };
30605
+ return this.state.restorable;
30606
+ }
30607
+ /**
30608
+ * Remember a skill's instructions so a compaction can put them back.
30609
+ * `append` adds a later page of a skill that arrives in pages.
30610
+ */
30611
+ recordSkillBody(name2, body, append = false) {
30612
+ const key5 = name2.trim();
30613
+ if (key5.length === 0 || body.trim().length === 0)
30614
+ return;
30615
+ const restorable = this.restorableState();
30616
+ const index = restorable.skills.findIndex((skill) => skill.name === key5);
30617
+ const previous = index >= 0 ? restorable.skills[index] : void 0;
30618
+ const joined3 = append && previous ? `${previous.body}${body}` : body;
30619
+ if (index >= 0)
30620
+ restorable.skills.splice(index, 1);
30621
+ restorable.skills.push({ name: key5, body: joined3.slice(0, MAX_RESTORABLE_CHARS) });
30622
+ while (restorable.skills.length > MAX_RESTORABLE_SKILLS)
30623
+ restorable.skills.shift();
30624
+ }
30625
+ /** Remember what a read returned so a compaction can put it back. */
30626
+ recordFileText(path2, text10) {
30627
+ const key5 = normalizeRestorablePath(path2);
30628
+ if (key5.length === 0 || text10.trim().length === 0)
30629
+ return;
30630
+ const restorable = this.restorableState();
30631
+ const index = restorable.files.findIndex((file) => file.path === key5);
30632
+ if (index >= 0)
30633
+ restorable.files.splice(index, 1);
30634
+ restorable.files.push({ path: key5, text: text10.slice(0, MAX_RESTORABLE_CHARS) });
30635
+ while (restorable.files.length > MAX_RESTORABLE_FILES)
30636
+ restorable.files.shift();
30637
+ }
30638
+ /** A file that was changed after it was read no longer has a body worth restoring. */
30639
+ forgetFileText(path2) {
30640
+ const files = this.state.restorable?.files;
30641
+ if (!files)
30642
+ return;
30643
+ const key5 = normalizeRestorablePath(path2);
30644
+ const index = files.findIndex((file) => file.path === key5);
30645
+ if (index >= 0)
30646
+ files.splice(index, 1);
30647
+ }
30362
30648
  addDecision(decision2) {
30363
30649
  this.pushWithEviction("decisions", this.state.decisions, decision2, this.config.maxListSize);
30364
30650
  }
@@ -30798,7 +31084,13 @@ function snapshotWorkingState(manager) {
30798
31084
  toolResults: [...state.toolResults],
30799
31085
  userRequirements: [...state.userRequirements],
30800
31086
  assistantNotes: [...state.assistantNotes],
30801
- evicted: { ...state.evicted }
31087
+ evicted: { ...state.evicted },
31088
+ ...state.restorable ? {
31089
+ restorable: {
31090
+ skills: state.restorable.skills.map((skill) => ({ ...skill })),
31091
+ files: state.restorable.files.map((file) => ({ ...file }))
31092
+ }
31093
+ } : {}
30802
31094
  };
30803
31095
  }
30804
31096
  __name(snapshotWorkingState, "snapshotWorkingState");
@@ -30816,7 +31108,13 @@ function restoreWorkingState(snapshot, config) {
30816
31108
  toolResults: [...snapshot.toolResults],
30817
31109
  userRequirements: [...snapshot.userRequirements],
30818
31110
  assistantNotes: [...snapshot.assistantNotes],
30819
- evicted: { ...snapshot.evicted }
31111
+ evicted: { ...snapshot.evicted },
31112
+ ...snapshot.restorable ? {
31113
+ restorable: {
31114
+ skills: snapshot.restorable.skills.map((skill) => ({ ...skill })),
31115
+ files: snapshot.restorable.files.map((file) => ({ ...file }))
31116
+ }
31117
+ } : {}
30820
31118
  };
30821
31119
  manager.replaceState(state);
30822
31120
  return manager;
@@ -33068,10 +33366,12 @@ function factsOf(err) {
33068
33366
  const message = err instanceof Error ? err.message : String(err);
33069
33367
  const providerFailure = err instanceof ProviderError ? err : err instanceof Error && err.name === "ProviderRequestError" ? classifyProviderError(err) : void 0;
33070
33368
  if (providerFailure) {
33369
+ const transport = readTransportCause(providerFailure);
33071
33370
  return {
33072
33371
  code: providerFailure.code,
33073
33372
  message,
33074
33373
  name: providerFailure.name,
33374
+ ...transport !== void 0 ? { transport } : {},
33075
33375
  ...providerFailure.status !== void 0 ? { status: providerFailure.status } : {},
33076
33376
  ...providerFailure.retryAfterMs !== void 0 ? { retryAfterMs: providerFailure.retryAfterMs } : {},
33077
33377
  ...hint !== void 0 ? { hint } : {}
@@ -33124,7 +33424,7 @@ var DEFAULT_ERROR_RULES = [
33124
33424
  id: "provider.rate_limit",
33125
33425
  when: /* @__PURE__ */ __name((facts) => facts.code === "rate_limit" || facts.status === 429, "when"),
33126
33426
  message: "The provider is rate limiting this turn.",
33127
- hint: "Respect the provider retry delay when reported. Lower concurrency, or wait for the quota window to reset before resuming."
33427
+ hint: "Wait for the provider retry delay when reported, or for the quota window to reset, before resuming. When the wait is long, continue on another model or provider."
33128
33428
  },
33129
33429
  {
33130
33430
  id: "provider.context_overflow",
@@ -33138,6 +33438,26 @@ var DEFAULT_ERROR_RULES = [
33138
33438
  message: "The provider is failing on its own side.",
33139
33439
  hint: "Nothing in the turn is wrong. Resume from the last checkpoint once the provider recovers."
33140
33440
  },
33441
+ {
33442
+ // Before the general network rule: a proxy that wants a sign-in and a
33443
+ // certificate nobody trusts each have a fix the general advice does not name.
33444
+ id: "provider.proxy_auth",
33445
+ when: /* @__PURE__ */ __name((facts) => facts.transport === "proxy_auth_required", "when"),
33446
+ message: "The network proxy asked for a sign-in before it would pass the request on.",
33447
+ hint: "Put the proxy user name and password in the proxy address (for example HTTPS_PROXY=http://user:password@host:port), or ask whoever runs the proxy for access."
33448
+ },
33449
+ {
33450
+ id: "provider.proxy_refused",
33451
+ when: /* @__PURE__ */ __name((facts) => facts.transport === "proxy_refused", "when"),
33452
+ message: "The network proxy refused to pass the request on.",
33453
+ hint: "Check the proxy address and the NO_PROXY list, and ask whoever runs the proxy whether this host is allowed to reach the provider."
33454
+ },
33455
+ {
33456
+ id: "provider.untrusted_certificate",
33457
+ when: /* @__PURE__ */ __name((facts) => facts.transport === "untrusted_certificate", "when"),
33458
+ message: "The connection was refused because its certificate is not trusted.",
33459
+ hint: "If a proxy or firewall inspects encrypted traffic, set NODE_EXTRA_CA_CERTS to the file holding its certificate authority and start again."
33460
+ },
33141
33461
  {
33142
33462
  id: "provider.network",
33143
33463
  when: /* @__PURE__ */ __name((facts) => facts.code === "network" || facts.code === "timeout", "when"),
@@ -34705,7 +35025,7 @@ __name(isTerminalAgentTaskState, "isTerminalAgentTaskState");
34705
35025
  // ../sdk/dist/scheduler/completion-inbox.js
34706
35026
  var UNOWNED_BUFFER_LIMIT = 32;
34707
35027
  var OWNED_WORK_DISPLAY_LIMIT = 16;
34708
- var OWNED_WORK_GUIDANCE = "Each task gives its id (taskId), its state, how its turn ended (turnStatus), why it stopped (stopReason), and whether its result has reached this conversation (resultDelivery: delivered-to-history, or not-delivered). Result delivery is not proof that you answered the original request. Answer the latest operator message and complete the requested synthesis of available results unless the operator cancelled or changed that request. Reuse delivered results when sufficient; do not relaunch completed work. If a delivered result is no longer visible, retrieve it by task ID. A terminal state with a non-end_turn stop reason is not successful task completion. Do not repeat a synthesis already given.";
35028
+ var OWNED_WORK_GUIDANCE = "Each task gives its id (taskId), its state, how its turn ended (turnStatus), why it stopped (stopReason), and whether its result has reached this conversation (resultDelivery: delivered-to-history, or not-delivered). Result delivery is not proof that you answered the original request. Answer the latest operator message and complete the requested synthesis of available results unless the operator cancelled or changed that request. Reuse delivered results when sufficient; do not relaunch completed work. If a delivered result is no longer visible, retrieve it by task ID. A terminal state with a non-end_turn stop reason is not successful task completion. Results reach you and not the user, so before you end a reply check that the result of every finished task has been reported to the user, once. Do not repeat a synthesis already given.";
34709
35029
  function recordedOwnedTaskIds(entries2) {
34710
35030
  const ids = /* @__PURE__ */ new Set();
34711
35031
  for (const entry of entries2) {
@@ -35293,7 +35613,7 @@ ${partial.content}`;
35293
35613
  ${lines.join("\n")}
35294
35614
  </task-notification>`;
35295
35615
  });
35296
- const preamble = handles.length === 1 ? "A task you launched has finished. This is its result \u2014 you were not waiting on it, so it arrives here rather than as a tool result." : `${handles.length} tasks you launched have finished. These are their results \u2014 you were not waiting on them, so they arrive here rather than as tool results.`;
35616
+ const preamble = handles.length === 1 ? "A task you launched has finished. This is its result \u2014 you were not waiting on it, so it arrives here rather than as a tool result. The user has not seen it; tell them what it found in your next message." : `${handles.length} tasks you launched have finished. These are their results \u2014 you were not waiting on them, so they arrive here rather than as tool results. The user has not seen them; tell them what each found in your next message.`;
35297
35617
  return `${preamble}
35298
35618
 
35299
35619
  ${blocks.join("\n\n")}`;
@@ -36765,6 +37085,107 @@ function createSlidingWindowReducer(options = {}) {
36765
37085
  }
36766
37086
  __name(createSlidingWindowReducer, "createSlidingWindowReducer");
36767
37087
 
37088
+ // ../sdk/dist/compaction/restore.js
37089
+ import { resolve as resolvePath } from "node:path";
37090
+ var RESTORE_MAX_SKILLS = 8;
37091
+ var RESTORE_SKILL_TOKENS = 5e3;
37092
+ var RESTORE_SKILLS_TOTAL_TOKENS = 25e3;
37093
+ var RESTORE_MAX_FILES = 5;
37094
+ var RESTORE_FILE_TOKENS = 5e3;
37095
+ var RESTORE_FILES_TOTAL_TOKENS = 5e4;
37096
+ var RESTORE_FILES_WINDOW_SHARE = 0.1;
37097
+ var RESTORE_SKILLS_WINDOW_SHARE = 0.05;
37098
+ var CUT_MARKER = "\n\u2026 [cut to fit the restore budget]";
37099
+ var SKILL_CONTINUATION = /\n\n\[More skill instructions remain\.[^\]]*\]/g;
37100
+ function isInstructionPath(path2) {
37101
+ const normal = path2.replace(/\\/g, "/");
37102
+ const name2 = normal.slice(normal.lastIndexOf("/") + 1);
37103
+ return name2 === "AGENTS.md" || name2 === "AGENTS.local.md" || normal.includes("/.namzu/rules/");
37104
+ }
37105
+ __name(isInstructionPath, "isInstructionPath");
37106
+ function resolveAgainst(path2, workingDirectory) {
37107
+ return workingDirectory ? resolvePath(workingDirectory, path2) : path2;
37108
+ }
37109
+ __name(resolveAgainst, "resolveAgainst");
37110
+ function isPlanPath(path2) {
37111
+ return /(^|\/)plans\/plan\.md$/.test(path2.replace(/\\/g, "/"));
37112
+ }
37113
+ __name(isPlanPath, "isPlanPath");
37114
+ function recordRestorable(manager, call2) {
37115
+ const input = typeof call2.input === "object" && call2.input !== null ? call2.input : void 0;
37116
+ if (!input)
37117
+ return;
37118
+ if (call2.toolName === "skill") {
37119
+ if (!call2.success || typeof input.name !== "string")
37120
+ return;
37121
+ manager.recordSkillBody(input.name, call2.output.replace(SKILL_CONTINUATION, ""), typeof input.cursor === "string" && input.cursor.length > 0);
37122
+ return;
37123
+ }
37124
+ if (call2.toolName === "read") {
37125
+ const path2 = typeof input.path === "string" ? input.path : void 0;
37126
+ if (!path2 || !call2.success || call2.unchanged)
37127
+ return;
37128
+ manager.recordFileText(resolveAgainst(path2, call2.workingDirectory), call2.output);
37129
+ return;
37130
+ }
37131
+ if (call2.toolName === "write" || call2.toolName === "edit") {
37132
+ const path2 = typeof input.path === "string" ? input.path : void 0;
37133
+ if (path2 && call2.success)
37134
+ manager.forgetFileText(resolveAgainst(path2, call2.workingDirectory));
37135
+ }
37136
+ }
37137
+ __name(recordRestorable, "recordRestorable");
37138
+ function fit(text10, tokens) {
37139
+ const room = tokens * CHARS_PER_TOKEN;
37140
+ return text10.length <= room ? text10 : `${text10.slice(0, Math.max(0, room - CUT_MARKER.length))}${CUT_MARKER}`;
37141
+ }
37142
+ __name(fit, "fit");
37143
+ function renderRestoredContext(state, options = {}) {
37144
+ const window2 = options.contextWindowTokens;
37145
+ const skillsTotal = window2 === void 0 ? RESTORE_SKILLS_TOTAL_TOKENS : Math.min(RESTORE_SKILLS_TOTAL_TOKENS, Math.floor(window2 * RESTORE_SKILLS_WINDOW_SHARE));
37146
+ const filesTotal = window2 === void 0 ? RESTORE_FILES_TOTAL_TOKENS : Math.min(RESTORE_FILES_TOTAL_TOKENS, Math.floor(window2 * RESTORE_FILES_WINDOW_SHARE));
37147
+ const sections = [];
37148
+ let skillBudget = skillsTotal;
37149
+ const skills = [...state.restorable?.skills ?? []].reverse();
37150
+ for (const skill of skills) {
37151
+ if (sections.length >= RESTORE_MAX_SKILLS || skillBudget <= 0)
37152
+ break;
37153
+ const body = fit(skill.body, Math.min(RESTORE_SKILL_TOKENS, skillBudget));
37154
+ skillBudget -= Math.ceil(body.length / CHARS_PER_TOKEN);
37155
+ sections.push(`### Skill: ${skill.name}
37156
+
37157
+ ${body}`);
37158
+ }
37159
+ let fileBudget = filesTotal;
37160
+ let files = 0;
37161
+ const candidates = [...state.restorable?.files ?? []].reverse();
37162
+ for (const file of candidates) {
37163
+ if (files >= RESTORE_MAX_FILES || fileBudget <= 0)
37164
+ break;
37165
+ if (isInstructionPath(file.path) || isPlanPath(file.path))
37166
+ continue;
37167
+ const text10 = fit(file.text, Math.min(RESTORE_FILE_TOKENS, fileBudget));
37168
+ fileBudget -= Math.ceil(text10.length / CHARS_PER_TOKEN);
37169
+ files += 1;
37170
+ sections.push(`### File: ${file.path}
37171
+
37172
+ ${text10}`);
37173
+ }
37174
+ const note = options.hostNote?.trim();
37175
+ if (note)
37176
+ sections.push(note);
37177
+ if (sections.length === 0)
37178
+ return void 0;
37179
+ return [
37180
+ "## Restored after compaction",
37181
+ "",
37182
+ "These were loaded or read earlier in this conversation and are put back here so you can keep using them. A file below may have changed on disk since it was read; read it again before you rely on it for an edit.",
37183
+ "",
37184
+ sections.join("\n\n")
37185
+ ].join("\n");
37186
+ }
37187
+ __name(renderRestoredContext, "renderRestoredContext");
37188
+
36768
37189
  // ../sdk/dist/compaction/verifier.js
36769
37190
  var VERIFICATION_PROMPT = `You are a context compaction verifier. You are given a structured state summary extracted from a conversation, plus a truncated excerpt of the older conversation that was summarized.
36770
37191
 
@@ -37927,6 +38348,23 @@ async function runCompactionCheckInner(ctx, pass, options) {
37927
38348
  } else {
37928
38349
  compactedContent = serializeState(manager.getState());
37929
38350
  }
38351
+ let hostNote;
38352
+ try {
38353
+ hostNote = await ctx.postCompactionContext?.();
38354
+ } catch (error) {
38355
+ ctx.log.warn("The host note for a compaction could not be read \u2014 leaving it out", {
38356
+ [NAMZU.TURN_ID]: ctx.recorder.turnId,
38357
+ "exception.message": error instanceof Error ? error.message : String(error)
38358
+ });
38359
+ }
38360
+ const restored = renderRestoredContext(manager.getState(), {
38361
+ contextWindowTokens: budget,
38362
+ ...hostNote ? { hostNote } : {}
38363
+ });
38364
+ if (restored)
38365
+ compactedContent = `${compactedContent}
38366
+
38367
+ ${restored}`;
37930
38368
  const mounted = new Set(ctx.tools?.listNames?.() ?? []);
37931
38369
  const compactionMessage = buildCompactionMessage(compactedContent, mounted.has("search_conversation") && mounted.has("read_conversation") ? COMPACTION_RECOVERY_NOTE : void 0);
37932
38370
  const preservedSystem = systemMessages.filter((m) => !isCompactionMessage(typeof m.content === "string" ? m.content : null) || m.retain === true);
@@ -39654,16 +40092,18 @@ function unreadableToolInputMessage(toolName, error, tool) {
39654
40092
  hint(tool?.malformedInputHint?.trim() ? tool.malformedInputHint : tool?.validationErrorHint);
39655
40093
  } else {
39656
40094
  const contextWindow = error.finishReason === "length" && error.finishDetail === "context_window";
39657
- const cause = contextWindow ? "the response filled the model's context window" : error.finishReason === "length" ? "the response reached its output token limit" : error.finishReason === "content_filter" ? "the provider's content filter stopped the response" : "the response stream ended";
40095
+ const cause = contextWindow ? "the response filled the model's context window" : error.finishReason === "length" ? "the response reached its output token limit" : error.finishReason === "content_filter" ? "the provider's content filter stopped the response" : "the connection dropped";
39658
40096
  parts.push(`Error: The call to "${toolName}" was cut off: ${cause} after ${error.length} characters of its arguments, before they were complete. The tool was NOT executed.`);
39659
40097
  const unseen = error.finishReason === "length" && !contextWindow ? unseenOutput(error) : void 0;
39660
40098
  if (unseen) {
39661
40099
  parts.push(unseen, "Send the call again after less reasoning, or split the work into smaller steps that each need less of it.");
39662
40100
  } else if (error.finishReason === "length" && !contextWindow && error.length < error.precedingLength) {
39663
40101
  parts.push(`${error.precedingLength} of the ${error.precedingLength + error.length} characters the response streamed came before this call, so send the call again with less before it in the same response.`);
39664
- } else if (error.finishReason !== "content_filter") {
40102
+ } else if (error.finishReason === "length") {
39665
40103
  parts.push(sizeAdvice(tool?.largeStringArguments, error) ?? "Send the call again.");
39666
40104
  hint(tool?.truncatedInputHint);
40105
+ } else if (error.finishReason !== "content_filter") {
40106
+ parts.push("Nothing was wrong with the call. Send the same call again, unchanged.");
39667
40107
  }
39668
40108
  }
39669
40109
  return parts.join(" ");
@@ -39744,7 +40184,7 @@ function recordFileEvidence(current, recorded) {
39744
40184
  const gone = [...held3.keys()].filter((path2) => !now.has(path2));
39745
40185
  if (changed.length === 0 && gone.length === 0)
39746
40186
  return;
39747
- const lead = recorded.length === 0 ? `${FILE_EVIDENCE_HEADING}: ${FILE_EVIDENCE_GUIDANCE}` : `${FILE_EVIDENCE_HEADING}, changed since the last entry. An entry for a path replaces the earlier entries for that path.`;
40187
+ const lead = recorded.length === 0 ? `${FILE_EVIDENCE_HEADING}: ${FILE_EVIDENCE_GUIDANCE}` : `${FILE_EVIDENCE_HEADING}, changed since the last entry; \`bodyInCall\` and \`observedFingerprint\` read as before. An entry for a path replaces the earlier entries for that path.`;
39748
40188
  return [
39749
40189
  lead,
39750
40190
  ...gone.length > 0 ? [`${NO_LONGER_HOLDS}${JSON.stringify(gone)}`] : [],
@@ -40234,6 +40674,7 @@ var ToolExecutor = class {
40234
40674
  emitEvent;
40235
40675
  log;
40236
40676
  workingStateManager;
40677
+ historyView;
40237
40678
  probes;
40238
40679
  parentSpan;
40239
40680
  toolCallBudget;
@@ -40261,6 +40702,26 @@ var ToolExecutor = class {
40261
40702
  setWorkingStateManager(manager) {
40262
40703
  this.workingStateManager = manager;
40263
40704
  }
40705
+ /**
40706
+ * Read the conversation the model is shown, as it is now. Lets a tool ask
40707
+ * whether an earlier receipt is still there (see `ToolContext.receiptVisible`)
40708
+ * without being handed the history.
40709
+ */
40710
+ setHistoryView(view) {
40711
+ this.historyView = view;
40712
+ }
40713
+ receiptVisible = /* @__PURE__ */ __name((callId, renderedFingerprint) => {
40714
+ const history = this.historyView?.();
40715
+ if (!history)
40716
+ return false;
40717
+ for (let index = history.length - 1; index >= 0; index -= 1) {
40718
+ const message = history[index];
40719
+ if (message?.role !== "tool" || message.toolCallId !== callId)
40720
+ continue;
40721
+ return typeof message.content === "string" && message.isError !== true && fingerprintContent(message.content) === renderedFingerprint;
40722
+ }
40723
+ return false;
40724
+ }, "receiptVisible");
40264
40725
  setSandbox(sandbox) {
40265
40726
  this.config = { ...this.config, sandbox };
40266
40727
  this.sandboxGate = void 0;
@@ -41355,6 +41816,7 @@ var ToolExecutor = class {
41355
41816
  dispatchTool: /* @__PURE__ */ __name((name2, input, options) => this.dispatchNested(name2, input, context2, recordObservation, void 0, options), "dispatchTool"),
41356
41817
  sandbox: this.config.sandbox,
41357
41818
  fileReadTracker: this.fileReadTracker,
41819
+ receiptVisible: this.receiptVisible,
41358
41820
  ...this.config.codeAnalysis ? { codeAnalysis: this.config.codeAnalysis } : {},
41359
41821
  // Bound to this turn, once. Binding here rather than passing the
41360
41822
  // owner from the tool is what makes the scoping structural: there
@@ -41619,6 +42081,14 @@ ${note}`;
41619
42081
  const visibleInputFailure = !result.success && !postOverride && !this.config.abortSignal.aborted ? inputFailure : void 0;
41620
42082
  if (this.workingStateManager) {
41621
42083
  extractFromToolResult(this.workingStateManager, toolName, output, effectiveIsError);
42084
+ recordRestorable(this.workingStateManager, {
42085
+ toolName,
42086
+ input,
42087
+ output: typeof modelContent === "string" ? modelContent : output,
42088
+ success: !effectiveIsError,
42089
+ unchanged: result.facts?.kind === "read" && result.facts.unchanged === true,
42090
+ workingDirectory: this.config.workingDirectory
42091
+ });
41622
42092
  for (const pin of this.config.abortSignal.aborted ? [] : result.workingState ?? []) {
41623
42093
  this.workingStateManager.pin(pin.key, pin.text, toolName);
41624
42094
  }
@@ -45473,7 +45943,7 @@ async function* streamProviderTurn(provider, params, emitEvent, drainPending, tu
45473
45943
  };
45474
45944
  let streamedLength = 0;
45475
45945
  const toolBuckets = /* @__PURE__ */ new Map();
45476
- const toolIndexer = new ToolCallIndexer();
45946
+ let toolIndexer = new ToolCallIndexer();
45477
45947
  let lastOutputCall;
45478
45948
  async function* announceToolCall(bucket) {
45479
45949
  if (bucket.started || !bucket.id || !bucket.name)
@@ -45527,6 +45997,28 @@ async function* streamProviderTurn(provider, params, emitEvent, drainPending, tu
45527
45997
  onAbort = /* @__PURE__ */ __name(() => reject2(signal.reason), "onAbort");
45528
45998
  signal.addEventListener("abort", onAbort, { once: true });
45529
45999
  }) : void 0;
46000
+ const discardAttempt = /* @__PURE__ */ __name(() => {
46001
+ toolBuckets.clear();
46002
+ toolIndexer = new ToolCallIndexer();
46003
+ framingViolated = false;
46004
+ text10 = new StreamTextAccumulator();
46005
+ reasoningBuckets.clear();
46006
+ citations.length = 0;
46007
+ replayState = void 0;
46008
+ id3 = "";
46009
+ finishReason = "stop";
46010
+ reportedFinishReason = void 0;
46011
+ finishDetail = void 0;
46012
+ streamedLength = 0;
46013
+ lastOutputCall = void 0;
46014
+ usage = {
46015
+ promptTokens: 0,
46016
+ completionTokens: 0,
46017
+ totalTokens: 0,
46018
+ cachedTokens: 0,
46019
+ cacheWriteTokens: 0
46020
+ };
46021
+ }, "discardAttempt");
45530
46022
  try {
45531
46023
  for (; ; ) {
45532
46024
  const next = it.next();
@@ -45551,25 +46043,8 @@ async function* streamProviderTurn(provider, params, emitEvent, drainPending, tu
45551
46043
  ...chunk.retry.restart ? { restart: true } : {}
45552
46044
  });
45553
46045
  yield* drainPending();
45554
- if (chunk.retry.restart) {
45555
- text10 = new StreamTextAccumulator();
45556
- reasoningBuckets.clear();
45557
- citations.length = 0;
45558
- replayState = void 0;
45559
- id3 = "";
45560
- finishReason = "stop";
45561
- reportedFinishReason = void 0;
45562
- finishDetail = void 0;
45563
- streamedLength = 0;
45564
- lastOutputCall = void 0;
45565
- usage = {
45566
- promptTokens: 0,
45567
- completionTokens: 0,
45568
- totalTokens: 0,
45569
- cachedTokens: 0,
45570
- cacheWriteTokens: 0
45571
- };
45572
- }
46046
+ if (chunk.retry.restart)
46047
+ discardAttempt();
45573
46048
  continue;
45574
46049
  }
45575
46050
  if (chunk.fallback) {
@@ -45585,9 +46060,12 @@ async function* streamProviderTurn(provider, params, emitEvent, drainPending, tu
45585
46060
  ...chunk.fallback.toModel !== void 0 ? { toModel: chunk.fallback.toModel } : {},
45586
46061
  code: chunk.fallback.code,
45587
46062
  ...chunk.fallback.status !== void 0 ? { status: chunk.fallback.status } : {},
45588
- reason: chunk.fallback.reason
46063
+ reason: chunk.fallback.reason,
46064
+ ...chunk.fallback.restart ? { restart: true } : {}
45589
46065
  });
45590
46066
  yield* drainPending();
46067
+ if (chunk.fallback.restart)
46068
+ discardAttempt();
45591
46069
  continue;
45592
46070
  }
45593
46071
  if (chunk.error) {
@@ -45931,7 +46409,8 @@ async function* streamProviderTurn(provider, params, emitEvent, drainPending, tu
45931
46409
  }
45932
46410
  } : {}
45933
46411
  }));
45934
- const recoveredToolInputFromStreamError = streamError !== void 0 && !framingViolated && toolCalls.some((tc) => tc.id && tc.function.name);
46412
+ const cutByConnection = streamError !== void 0 && streamCause !== void 0 && classifyProviderError(streamCause).retryable;
46413
+ const recoveredToolInputFromStreamError = streamError !== void 0 && !framingViolated && toolCalls.some((tc) => tc.id && tc.function.name && (!cutByConnection || !tc.metadata?.inputError));
45935
46414
  const effectiveFinishReason = recoveredToolInputFromStreamError ? "tool_calls" : finishReason;
45936
46415
  if (recoveredToolInputFromStreamError) {
45937
46416
  log.warn("provider stream failed after tool input; surfacing tool call to executor", {
@@ -47913,6 +48392,11 @@ function isOutputChunk(chunk) {
47913
48392
  return Boolean(content || toolCalls?.length || toolCallEnd || reasoning !== void 0 || citation !== void 0 || hostedTool !== void 0 || chunk.textParts !== void 0);
47914
48393
  }
47915
48394
  __name(isOutputChunk, "isOutputChunk");
48395
+ function isVoidable(chunk) {
48396
+ const { content, toolCallEnd, citation, hostedTool, textPart } = chunk.delta;
48397
+ return !(content || toolCallEnd || citation !== void 0 || hostedTool !== void 0 || textPart !== void 0 || chunk.textParts !== void 0 || chunk.finishReason !== void 0);
48398
+ }
48399
+ __name(isVoidable, "isVoidable");
47916
48400
  function memberReasoningEffortLevels(member, requestModel, thinking) {
47917
48401
  const model = member.model ?? requestModel;
47918
48402
  if (member.provider.reasoningEffortLevelsFor) {
@@ -47988,10 +48472,18 @@ function withProviderFallback(members, options = {}) {
47988
48472
  assertNativeStructuredOutputSupported(member.provider, request);
47989
48473
  assertHostedWebSearchSupported(member.provider, request);
47990
48474
  let produced = false;
48475
+ let fragments = false;
47991
48476
  try {
47992
48477
  for await (const chunk of member.provider.chatStream(request)) {
47993
- if (isOutputChunk(chunk))
47994
- produced = true;
48478
+ if (chunk.retry?.restart) {
48479
+ produced = false;
48480
+ fragments = false;
48481
+ } else if (isOutputChunk(chunk)) {
48482
+ if (isVoidable(chunk))
48483
+ fragments = true;
48484
+ else
48485
+ produced = true;
48486
+ }
47995
48487
  yield chunk;
47996
48488
  }
47997
48489
  return;
@@ -48026,13 +48518,16 @@ function withProviderFallback(members, options = {}) {
48026
48518
  fallback: {
48027
48519
  fromIndex: cursor - 1,
48028
48520
  fromProviderId: member.provider.id,
48029
- ...member.model !== void 0 ? { fromModel: member.model } : {},
48521
+ // The model this member was asked for, which for the head of the chain
48522
+ // (declared without one) is the request's own.
48523
+ ...targetModel ? { fromModel: targetModel } : {},
48030
48524
  toIndex: cursor,
48031
48525
  toProviderId: to.provider.id,
48032
48526
  ...to.model !== void 0 ? { toModel: to.model } : {},
48033
48527
  code: classified.code,
48034
48528
  ...classified.status !== void 0 ? { status: classified.status } : {},
48035
- reason: classified.message
48529
+ reason: classified.message,
48530
+ ...fragments ? { restart: true } : {}
48036
48531
  }
48037
48532
  };
48038
48533
  }
@@ -48120,6 +48615,7 @@ function withProviderRetry(provider, options = {}) {
48120
48615
  for (let attempt = 0; ; attempt++) {
48121
48616
  let produced = false;
48122
48617
  let reasoned = false;
48618
+ let printed = false;
48123
48619
  let acted = false;
48124
48620
  try {
48125
48621
  for await (const chunk of provider.chatStream(params)) {
@@ -48130,9 +48626,11 @@ function withProviderRetry(provider, options = {}) {
48130
48626
  else
48131
48627
  produced = true;
48132
48628
  }
48133
- if (chunk.delta.toolCalls?.length || chunk.delta.toolCallEnd || chunk.delta.hostedTool) {
48134
- acted = true;
48629
+ if (chunk.delta.content || chunk.delta.textPart !== void 0 || chunk.textParts !== void 0 || chunk.delta.citation !== void 0) {
48630
+ printed = true;
48135
48631
  }
48632
+ if (chunk.delta.toolCallEnd || chunk.delta.hostedTool || chunk.finishReason)
48633
+ acted = true;
48136
48634
  if (isErrorOnly && !produced && attempt < config.maxRetries) {
48137
48635
  throw new Error(chunk.error);
48138
48636
  }
@@ -48146,7 +48644,7 @@ function withProviderRetry(provider, options = {}) {
48146
48644
  throw err;
48147
48645
  const classified = classifyProviderError(err, provider.id);
48148
48646
  const exhausted = attempt >= config.maxRetries;
48149
- const restartable = produced && config.retryMidStream === true && !acted || !produced && reasoned;
48647
+ const restartable = produced && !acted && (config.retryMidStream === true || !printed) || !produced && reasoned;
48150
48648
  if (produced && !restartable || !classified.retryable || exhausted) {
48151
48649
  log?.warn("Provider call failed", {
48152
48650
  [GENAI.SYSTEM]: provider.id,
@@ -48432,6 +48930,38 @@ function createSessionApprovalPolicy(options) {
48432
48930
  }
48433
48931
  __name(createSessionApprovalPolicy, "createSessionApprovalPolicy");
48434
48932
 
48933
+ // ../sdk/dist/runtime/query/calls-that-never-started.js
48934
+ async function readCallsThatNeverStarted(log) {
48935
+ const started = /* @__PURE__ */ new Set();
48936
+ const journaled = /* @__PURE__ */ new Set();
48937
+ const callsOfTurn = /* @__PURE__ */ new Map();
48938
+ for await (const entry of log.read()) {
48939
+ const record3 = entry.record;
48940
+ if (record3.type === "tool_review_requested") {
48941
+ journaled.add(record3.turnId);
48942
+ } else if (record3.type === "tool_executing") {
48943
+ journaled.add(record3.turnId);
48944
+ started.add(record3.toolUseId);
48945
+ } else if (record3.type === "message") {
48946
+ const content = record3.content;
48947
+ if (content?.role !== "assistant" || !content.toolCalls)
48948
+ continue;
48949
+ const ids = callsOfTurn.get(record3.turnId) ?? [];
48950
+ for (const call2 of content.toolCalls)
48951
+ ids.push(call2.id);
48952
+ callsOfTurn.set(record3.turnId, ids);
48953
+ }
48954
+ }
48955
+ const never = /* @__PURE__ */ new Set();
48956
+ for (const turnId6 of journaled) {
48957
+ for (const id3 of callsOfTurn.get(turnId6) ?? [])
48958
+ if (!started.has(id3))
48959
+ never.add(id3);
48960
+ }
48961
+ return never;
48962
+ }
48963
+ __name(readCallsThatNeverStarted, "readCallsThatNeverStarted");
48964
+
48435
48965
  // ../sdk/dist/runtime/query/context.js
48436
48966
  import { join as join14 } from "node:path";
48437
48967
 
@@ -51792,7 +52322,13 @@ async function prepareTurn(params) {
51792
52322
  pinCompaction: true
51793
52323
  })
51794
52324
  ]);
51795
- const initialRepair = params.resumeFromCheckpoint ? { messages: projectedInitialMessages, report: void 0 } : repairToolMessageHistory(projectedInitialMessages);
52325
+ let initialRepair = params.resumeFromCheckpoint ? { messages: projectedInitialMessages, report: void 0 } : repairToolMessageHistory(projectedInitialMessages);
52326
+ if (initialRepair.report && initialRepair.report.syntheticToolResultsInserted > 0) {
52327
+ const neverRan = await readCallsThatNeverStarted(storage.log);
52328
+ if (neverRan.size > 0) {
52329
+ initialRepair = repairToolMessageHistory(projectedInitialMessages, { neverRan });
52330
+ }
52331
+ }
51796
52332
  const initialMessages = initialRepair.messages;
51797
52333
  if (initialRepair.report && toolHistoryRepairChanged(initialRepair.report)) {
51798
52334
  pendingHistoryRepairs.push({
@@ -52789,6 +53325,7 @@ async function* query(params) {
52789
53325
  } : void 0;
52790
53326
  let workingStateManager;
52791
53327
  const compactionConfig = params.compactionConfig ? CompactionConfigSchema.parse(params.compactionConfig) : void 0;
53328
+ toolExecutor.setHistoryView(() => ctx.recorder.messages);
52792
53329
  if (compactionConfig && compactionConfig.strategy !== "disabled") {
52793
53330
  workingStateManager = new WorkingStateManager(compactionConfig);
52794
53331
  toolExecutor.setWorkingStateManager(workingStateManager);
@@ -52918,6 +53455,7 @@ async function* query(params) {
52918
53455
  ...params.resumeFromCheckpoint ? { resumedInput: queuedForThisRun } : {},
52919
53456
  ...params.waitForInbound ? { waitForInbound: params.waitForInbound } : {},
52920
53457
  ...params.projectInstructionContext ? { projectInstructionContext: params.projectInstructionContext } : {},
53458
+ ...params.postCompactionContext ? { postCompactionContext: params.postCompactionContext } : {},
52921
53459
  ...providerContextWindow !== void 0 ? { providerContextWindow } : {},
52922
53460
  resolveModelContextWindow: /* @__PURE__ */ __name(async (model) => {
52923
53461
  if (!modelContextWindows.has(model)) {
@@ -55317,9 +55855,21 @@ function splice(preservedSystem, summaryBody, retainedOlder, recentMessages, rec
55317
55855
  return { messages: [...preservedSystem, summary2, ...retainedOlder, ...recentMessages], summary: summary2 };
55318
55856
  }
55319
55857
  __name(splice, "splice");
55858
+ function withRestoredContext(body, manager, input) {
55859
+ const window2 = resolveContextWindow(input.contextWindowTokens ?? input.config.contextWindowTokens, input.model);
55860
+ const restored = renderRestoredContext(manager.getState(), {
55861
+ contextWindowTokens: window2.tokens,
55862
+ ...input.restoreNote ? { hostNote: input.restoreNote } : {}
55863
+ });
55864
+ return restored ? `${body}
55865
+
55866
+ ${restored}` : body;
55867
+ }
55868
+ __name(withRestoredContext, "withRestoredContext");
55320
55869
  function populateWorkingState(manager, messages, config) {
55321
55870
  let firstUser = true;
55322
55871
  const toolNames = /* @__PURE__ */ new Map();
55872
+ const toolInputs = /* @__PURE__ */ new Map();
55323
55873
  for (const message of messages) {
55324
55874
  switch (message.role) {
55325
55875
  case "user":
@@ -55333,12 +55883,25 @@ function populateWorkingState(manager, messages, config) {
55333
55883
  extractFromAssistantMessage(manager, message.content, config);
55334
55884
  for (const call2 of message.toolCalls ?? []) {
55335
55885
  toolNames.set(call2.id, call2.function.name);
55886
+ try {
55887
+ toolInputs.set(call2.id, JSON.parse(call2.function.arguments));
55888
+ } catch {
55889
+ }
55336
55890
  extractFromToolCall(manager, call2.function.name, call2.function.arguments);
55337
55891
  }
55338
55892
  break;
55339
- case "tool":
55340
- extractFromToolResult(manager, toolNames.get(message.toolCallId) ?? "tool", toolResultToText(message.content), message.isError === true);
55893
+ case "tool": {
55894
+ const toolName = toolNames.get(message.toolCallId) ?? "tool";
55895
+ const text10 = toolResultToText(message.content);
55896
+ extractFromToolResult(manager, toolName, text10, message.isError === true);
55897
+ recordRestorable(manager, {
55898
+ toolName,
55899
+ input: toolInputs.get(message.toolCallId),
55900
+ output: text10,
55901
+ success: message.isError !== true
55902
+ });
55341
55903
  break;
55904
+ }
55342
55905
  case "system":
55343
55906
  break;
55344
55907
  }
@@ -55375,7 +55938,7 @@ async function compactNow(input) {
55375
55938
  streamIdleTimeoutMs: input.streamIdleTimeoutMs,
55376
55939
  instructions: input.instructions
55377
55940
  });
55378
- const { messages, summary: summary2 } = splice(preservedSystem, body, retainedOlder, plan.recentMessages, input.recoveryNote);
55941
+ const { messages, summary: summary2 } = splice(preservedSystem, withRestoredContext(body, manager, input), retainedOlder, plan.recentMessages, input.recoveryNote);
55379
55942
  return publishManualCompaction(input, {
55380
55943
  messages,
55381
55944
  shed: input.messages.length - messages.length,
@@ -55424,7 +55987,10 @@ async function compactRegion(input) {
55424
55987
  streamIdleTimeoutMs: input.streamIdleTimeoutMs,
55425
55988
  instructions: input.instructions
55426
55989
  });
55427
- const summary2 = { ...buildCompactionMessage(body, input.recoveryNote), retain: true };
55990
+ const summary2 = {
55991
+ ...buildCompactionMessage(withRestoredContext(body, manager, input), input.recoveryNote),
55992
+ retain: true
55993
+ };
55428
55994
  const out = [...messages.slice(0, start), summary2, ...retainedSelected, ...messages.slice(end)];
55429
55995
  const dangling = findDanglingMessages(out);
55430
55996
  if (!dangling.isValid) {
@@ -63714,7 +64280,7 @@ async function resolveMcpEra(input) {
63714
64280
  __name(resolveMcpEra, "resolveMcpEra");
63715
64281
 
63716
64282
  // ../sdk/dist/version.js
63717
- var VERSION2 = "56.2.0";
64283
+ var VERSION2 = "57.0.0";
63718
64284
 
63719
64285
  // ../sdk/dist/connector/mcp/client.js
63720
64286
  var MAX_LIST_PAGES = 100;
@@ -67387,11 +67953,12 @@ var CODING_AGENT_WORKING_DOCTRINE = `## How you work
67387
67953
  - Never change git configuration or other persistent settings without asking: not \`user.name\` or \`user.email\`, hooks, remotes, credential helpers, or any \`git config\` (local or global), nor a shell profile or a tool's own config file. If a commit fails because no identity is set, stop and tell the user the command to set one; do not invent one.
67388
67954
 
67389
67955
  ### Keeping the user informed
67390
- - Before a batch of tool calls, say in one short line what you are about to do and why. When you have been working for a while without saying anything, say in a few words where you are, then continue. One line, not a paragraph; the tool rows on screen already show the details.
67956
+ - Before your first tool call, say in one short line what you are about to do and why. While you work, add a one-line update when you find something, change direction or hit a blocker, and after a long stretch without one, say in a few words where you are, then continue. Brief is good and silence is not; the tool rows on screen already show the details.
67391
67957
  - Keep the final reply short and specific: what changed, what was verified, what is left.`;
67392
67958
  var CODING_AGENT_DELEGATION_DOCTRINE = `### Planning and delegating
67393
- - For work that is multi-step \u2014 several files, several distinct stages, anything you would write a checklist for \u2014 open a task list with \`task_create\` and keep it current with \`task_update\`, marking each step done when it is done rather than at the end. Skip it for a single inspect-edit-test cycle: the list is for the user to follow, and a list of one item tells them nothing.
67959
+ - For work of three or more steps \u2014 several files, several distinct stages, anything you would write a checklist for \u2014 open a task list with \`task_create\` and keep it current with \`task_update\`, marking each step done when it is done rather than at the end. Skip it for a single inspect-edit-test cycle or a two-step job: the list is for the user to follow, and a list of one or two items tells them nothing.
67394
67960
  - When the \`Agent\` tool is available, delegate independent work through it and give each delegation a short, specific description; the user watches those descriptions, not the prompts. Brief each sub-agent with four things: the objective; what is out of bounds; which tools and sources to use; and the shape of the reply you want, such as a short summary with a file path for anything long. It starts with none of your context and returns what you ask for.
67961
+ - When delegated agents finish, tell the user what each one found in your next message. Their results reach you and not the user, so a result you do not pass on stays unseen.
67395
67962
  - Delegate lookups \u2014 where something is defined, which files reference it, how a module works \u2014 with \`subagent_type: "explore"\`: it has reading and searching tools only and never interrupts the user for permission. Reserve the default sub-agent for work that changes files or runs commands.`;
67396
67963
  var PLAN_MODE_DOCTRINE = `## Plan mode
67397
67964
 
@@ -73816,6 +74383,7 @@ var configRoutes = {
73816
74383
  inboundMessages: "query",
73817
74384
  durableInbound: "query",
73818
74385
  projectInstructionContext: "query",
74386
+ postCompactionContext: "query",
73819
74387
  allowedTools: "special",
73820
74388
  toolResultGuardrails: "query",
73821
74389
  deniedTools: "special",
@@ -74513,6 +75081,18 @@ var EXPLORE_AGENT_PROMPT = [
74513
75081
  "End with a concise answer the parent can act on; do not ask the parent questions."
74514
75082
  ].join("\n");
74515
75083
 
75084
+ // ../sdk/dist/agents/plan.js
75085
+ var PLAN_AGENT_ID = "plan";
75086
+ var PLAN_AGENT_DESCRIPTION = "A read-only sub-agent that studies the code and returns a step plan with the files it touches and the risks.";
75087
+ var PLAN_AGENT_PROMPT = [
75088
+ "You are a read-only sub-agent dispatched to plan a change: you study the code and return a plan, never the change itself.",
75089
+ "You cannot see the parent conversation \u2014 work only from the prompt you were given.",
75090
+ "You have reading and searching tools only. You cannot edit, write or run commands, and you must not describe a change as made.",
75091
+ "Read first: find the code the change touches, the patterns it should follow and the tests that cover it. Prefer what the code already does over a design of your own.",
75092
+ "Return the plan in this shape: a one-paragraph approach; numbered steps in the order to do them, each naming the files it changes; the files to read or change first, as paths with line numbers where it helps; the risks and open questions, including what could break and how to check it.",
75093
+ "Say plainly what you could not determine. End with the plan; do not ask the parent questions."
75094
+ ].join("\n");
75095
+
74516
75096
  // ../sdk/dist/registry/agent/definitions.js
74517
75097
  var AgentRegistry = class extends ManagedRegistry {
74518
75098
  static {
@@ -75697,8 +76277,11 @@ function runShellHook(entry, input, signal) {
75697
76277
  const timeoutMs = Math.min(MAX_SHELL_HOOK_TIMEOUT_MS, Math.max(1, entry.timeoutMs ?? DEFAULT_SHELL_HOOK_TIMEOUT_MS));
75698
76278
  const payload = JSON.stringify({
75699
76279
  event: input.event,
76280
+ hook_event_name: PASCAL_EVENT_NAMES[input.event] ?? input.event,
75700
76281
  cwd: input.cwd,
75701
76282
  session_id: input.sessionId,
76283
+ ...input.transcriptPath !== void 0 ? { transcript_path: input.transcriptPath } : {},
76284
+ ...input.permissionMode !== void 0 ? { permission_mode: input.permissionMode } : {},
75702
76285
  ...input.turnId !== void 0 ? { turn_id: input.turnId } : {},
75703
76286
  ...input.parentSessionId !== void 0 ? { parent_session_id: input.parentSessionId } : {},
75704
76287
  ...input.parentTurnId !== void 0 ? { parent_turn_id: input.parentTurnId } : {},
@@ -75706,7 +76289,7 @@ function runShellHook(entry, input, signal) {
75706
76289
  ...input.compaction !== void 0 ? { compaction: input.compaction } : {},
75707
76290
  ...input.toolName !== void 0 ? { tool_name: input.toolName } : {},
75708
76291
  ...input.toolInput !== void 0 ? { tool_input: input.toolInput } : {},
75709
- ...input.toolResult !== void 0 ? { tool_result: input.toolResult } : {},
76292
+ ...input.toolResult !== void 0 ? { tool_result: input.toolResult, tool_response: input.toolResult } : {},
75710
76293
  ...input.event === "post_tool_use_failure" && input.toolResult?.error !== void 0 ? { error: input.toolResult.error } : {},
75711
76294
  ...input.notification !== void 0 ? {
75712
76295
  notification_type: input.notification.type,
@@ -75928,7 +76511,7 @@ function readShellHookJson(event, stdout) {
75928
76511
  reading.permission = { decision: decision2, ...why ? { reason: why } : {} };
75929
76512
  } else if (decision2 !== "defer") {
75930
76513
  return {
75931
- invalid: '`permissionDecision` must be "allow", "deny" or "ask"'
76514
+ invalid: '`permissionDecision` must be "allow", "deny", "ask" or "defer"'
75932
76515
  };
75933
76516
  }
75934
76517
  }
@@ -76128,6 +76711,8 @@ function createShellHook(event, entry, options) {
76128
76711
  }
76129
76712
  if (entry.once === true)
76130
76713
  spent = true;
76714
+ const transcriptPath = options.transcriptPath?.(String(context2.sessionId));
76715
+ const permissionMode = options.permissionMode?.();
76131
76716
  const outcome = await runShellHook(entry, {
76132
76717
  event,
76133
76718
  cwd: options.cwd,
@@ -76147,7 +76732,9 @@ function createShellHook(event, entry, options) {
76147
76732
  }
76148
76733
  } : {},
76149
76734
  ...context2.notification !== void 0 ? { notification: context2.notification } : {},
76150
- ...context2.stopHookActive === true ? { stopHookActive: true } : {}
76735
+ ...context2.stopHookActive === true ? { stopHookActive: true } : {},
76736
+ ...transcriptPath !== void 0 ? { transcriptPath } : {},
76737
+ ...permissionMode !== void 0 ? { permissionMode } : {}
76151
76738
  }, context2.signal);
76152
76739
  return shellHookVerdict(event, entry, outcome, log);
76153
76740
  }, "handler")
@@ -80783,6 +81370,125 @@ var LocalSandboxProvider = class {
80783
81370
  }
80784
81371
  };
80785
81372
 
81373
+ // ../sdk/dist/authorization/presets.js
81374
+ function defaultSandboxedGateConfig() {
81375
+ return {
81376
+ enabled: true,
81377
+ allowReadOnlyTools: true,
81378
+ // See the shell preset below for what this closes: the read-only
81379
+ // allowance asks whether a claim is trustworthy, never what channel
81380
+ // the call travels over.
81381
+ allowReadOnlyExcludeCategories: ["network"],
81382
+ denyDangerousPatterns: true,
81383
+ logDecisions: false,
81384
+ rules: [{ type: "allow_by_category", categories: ["filesystem", "analysis", "custom"] }]
81385
+ };
81386
+ }
81387
+ __name(defaultSandboxedGateConfig, "defaultSandboxedGateConfig");
81388
+ function defaultSandboxedShellGateConfig() {
81389
+ return {
81390
+ enabled: true,
81391
+ allowReadOnlyTools: true,
81392
+ // The docblock above says a `network` tool goes to review, and without
81393
+ // this it did not: `allow_read_only` is appended last as a default for
81394
+ // tools nobody wrote a rule about, and it resolved purely through
81395
+ // `isTrustedReadOnly` — which asks whether the read-only CLAIM is
81396
+ // trustworthy and never what the tool reaches. A read-only network
81397
+ // call matched the default and was approved without review, in the
81398
+ // preset whose own documentation said it would not be.
81399
+ allowReadOnlyExcludeCategories: ["network"],
81400
+ denyDangerousPatterns: true,
81401
+ logDecisions: false,
81402
+ rules: [
81403
+ { type: "allow_by_category", categories: ["filesystem", "shell", "analysis", "custom"] }
81404
+ ]
81405
+ };
81406
+ }
81407
+ __name(defaultSandboxedShellGateConfig, "defaultSandboxedShellGateConfig");
81408
+
81409
+ // ../sdk/dist/authorization/permission-presets.js
81410
+ var UnsupportedPermissionPresetError = class extends Error {
81411
+ static {
81412
+ __name(this, "UnsupportedPermissionPresetError");
81413
+ }
81414
+ details;
81415
+ constructor(details) {
81416
+ super(`The "${details.preset}" preset requires ${details.required.join(", ")} isolation; this sandbox does not enforce ${details.missing.join(", ")}.`);
81417
+ this.name = "UnsupportedPermissionPresetError";
81418
+ this.details = details;
81419
+ }
81420
+ };
81421
+ var SUPERVISED_PRESET = {
81422
+ name: "supervised",
81423
+ description: "Every tool call goes to a human. Assumes nothing about the sandbox.",
81424
+ gate: {
81425
+ enabled: true,
81426
+ // `false`, and that is the whole preset. Read-only auto-approval is
81427
+ // the one allowance whose safety does not depend on the sandbox — it
81428
+ // depends on a tool telling the truth about itself, which is the
81429
+ // claim `isTrustedReadOnly` exists because it cannot always take at
81430
+ // face value.
81431
+ allowReadOnlyTools: false,
81432
+ denyDangerousPatterns: true,
81433
+ logDecisions: false,
81434
+ rules: [{ type: "deny_dangerous_patterns" }]
81435
+ },
81436
+ requiresIsolation: [],
81437
+ expectsApprovalPolicy: "host"
81438
+ };
81439
+ var SANDBOXED_PRESET = {
81440
+ name: "sandboxed",
81441
+ description: "In-sandbox file mutation auto-approves; shell and network calls go to a human. Requires a sandbox that confines the filesystem.",
81442
+ gate: defaultSandboxedGateConfig(),
81443
+ requiresIsolation: ["filesystem"],
81444
+ expectsApprovalPolicy: "host"
81445
+ };
81446
+ var SANDBOXED_SHELL_PRESET = {
81447
+ name: "sandboxed-shell",
81448
+ description: "Shell as well as file mutation auto-approves inside the sandbox; network calls go to a human. Requires filesystem and process isolation.",
81449
+ gate: defaultSandboxedShellGateConfig(),
81450
+ requiresIsolation: ["filesystem", "process"],
81451
+ expectsApprovalPolicy: "host"
81452
+ };
81453
+ var UNATTENDED_PRESET = {
81454
+ name: "unattended",
81455
+ description: "Everything auto-approves. The sandbox is the only boundary, so it must enforce all three controls.",
81456
+ gate: {
81457
+ ...defaultSandboxedShellGateConfig(),
81458
+ allowReadOnlyTools: true,
81459
+ // Network too, which is exactly what the `network` isolation
81460
+ // requirement below is paying for. The sandboxed presets leave
81461
+ // network to a human precisely because they do not require that
81462
+ // control; this one requires it, so it can spend it.
81463
+ rules: [
81464
+ {
81465
+ type: "allow_by_category",
81466
+ categories: ["filesystem", "shell", "analysis", "custom", "network"]
81467
+ }
81468
+ ]
81469
+ },
81470
+ requiresIsolation: ["filesystem", "network", "process"],
81471
+ expectsApprovalPolicy: AUTO_APPROVE_POLICY_NAME
81472
+ };
81473
+ var PERMISSION_PRESETS = {
81474
+ [SUPERVISED_PRESET.name]: SUPERVISED_PRESET,
81475
+ [SANDBOXED_PRESET.name]: SANDBOXED_PRESET,
81476
+ [SANDBOXED_SHELL_PRESET.name]: SANDBOXED_SHELL_PRESET,
81477
+ [UNATTENDED_PRESET.name]: UNATTENDED_PRESET
81478
+ };
81479
+ function resolvePermissionPreset(preset, isolation) {
81480
+ const missing = preset.requiresIsolation.filter((control) => !isolation[control]);
81481
+ if (missing.length > 0) {
81482
+ throw new UnsupportedPermissionPresetError({
81483
+ preset: preset.name,
81484
+ required: preset.requiresIsolation,
81485
+ missing
81486
+ });
81487
+ }
81488
+ return preset.gate;
81489
+ }
81490
+ __name(resolvePermissionPreset, "resolvePermissionPreset");
81491
+
80786
81492
  // ../sdk/dist/session/workspace/registry.js
80787
81493
  var WorkspaceBackendRegistry = class {
80788
81494
  static {
@@ -89462,6 +90168,12 @@ function movedToBackgroundMessage(jobId, timeoutMs) {
89462
90168
  return `Command did not complete within its ${seconds}s timeout and was moved to the background as job ${jobId}; it was not stopped. You will be told when it ends. Its output so far is above.`;
89463
90169
  }
89464
90170
  __name(movedToBackgroundMessage, "movedToBackgroundMessage");
90171
+ var FOREGROUND_HANDOFF_AFTER_MS = 2e3;
90172
+ function handedOffMessage(jobId, reason2) {
90173
+ const why = reason2 === "user" ? "at the person's request" : reason2 === "message" ? "so a message from the person could reach you" : "because the person interrupted the turn";
90174
+ return `Command was moved to the background as job ${jobId} ${why}; it was not stopped. You will be told when it ends. Its output so far is above.`;
90175
+ }
90176
+ __name(handedOffMessage, "handedOffMessage");
89465
90177
  var inputSchema7 = external_exports.object({
89466
90178
  command: external_exports.string().min(1).transform((command) => isWindowsBash(hostCommandShell()) ? rewriteWindowsNullRedirect(command) : command).describe("The bash command to execute. Required, non-empty. Single command per call (use `&&` / `;` chaining for compound commands). Large file content belongs in `write` (see its description), not in a heredoc."),
89467
90179
  timeout: external_exports.preprocess((v) => typeof v === "string" ? Number(v) : v, external_exports.number().positive().default(DEFAULT_BASH_TIMEOUT_MS).transform((ms) => Math.min(ms, MAX_BASH_TIMEOUT_MS))).describe(`Command timeout in milliseconds. Default: ${DEFAULT_BASH_TIMEOUT_MS}, maximum: ${MAX_BASH_TIMEOUT_MS}. For work that legitimately runs longer than the maximum, set run_in_background and await it with \`wait_for_job\`, rather than holding the turn open. A foreground command still running when the timeout elapses is moved to a background job (and reported as such) instead of being stopped, where the host has background jobs.`),
@@ -89656,40 +90368,54 @@ ${stderr}`));
89656
90368
  }));
89657
90369
  }, "onClose");
89658
90370
  child.once("close", onClose);
89659
- const deadline = setTimeout(() => {
89660
- if (options.onTimeout && !closed && cause === void 0) {
89661
- let jobId;
89662
- try {
89663
- jobId = options.onTimeout({
89664
- child,
89665
- initialOutput: ["stdout", "stderr"].map((stream) => ({ stream, text: decodeCapture(stream) })).filter((part2) => part2.text !== "")
89666
- });
89667
- } catch {
89668
- }
89669
- if (jobId !== void 0) {
89670
- closed = true;
89671
- disposeAbort?.();
89672
- child.stdout?.off("data", onStdout);
89673
- child.stderr?.off("data", onStderr);
89674
- child.off("close", onClose);
89675
- child.off("error", onError);
89676
- child.off("spawn", onSpawn);
89677
- resolve30({
89678
- backgroundedJobId: jobId,
89679
- stdout: decodeCapture("stdout"),
89680
- stderr: decodeCapture("stderr")
89681
- });
89682
- return;
89683
- }
90371
+ const takeOver = /* @__PURE__ */ __name((reason2) => {
90372
+ const adopter = reason2 === "timeout" ? options.onTimeout : options.adopt ?? options.onTimeout;
90373
+ if (!adopter || closed || cause !== void 0)
90374
+ return false;
90375
+ let jobId;
90376
+ try {
90377
+ jobId = adopter({
90378
+ child,
90379
+ initialOutput: ["stdout", "stderr"].map((stream) => ({ stream, text: decodeCapture(stream) })).filter((part2) => part2.text !== "")
90380
+ });
90381
+ } catch {
89684
90382
  }
90383
+ if (jobId === void 0)
90384
+ return false;
90385
+ closed = true;
90386
+ disposeAbort?.();
90387
+ clearTimeout(deadline);
90388
+ child.stdout?.off("data", onStdout);
90389
+ child.stderr?.off("data", onStderr);
90390
+ child.off("close", onClose);
90391
+ child.off("error", onError);
90392
+ child.off("spawn", onSpawn);
90393
+ resolve30({
90394
+ backgroundedJobId: jobId,
90395
+ backgroundedBy: reason2,
90396
+ stdout: decodeCapture("stdout"),
90397
+ stderr: decodeCapture("stderr")
90398
+ });
90399
+ return true;
90400
+ }, "takeOver");
90401
+ const deadline = setTimeout(() => {
90402
+ if (takeOver("timeout"))
90403
+ return;
89685
90404
  cancel("timeout");
89686
90405
  }, options.timeout);
89687
90406
  deadline.unref?.();
89688
90407
  if (options.signal) {
89689
- disposeAbort = subscribeToAbort(options.signal, () => cancel("caller"));
89690
- if (options.signal.aborted)
90408
+ const signal = options.signal;
90409
+ const onAbort = /* @__PURE__ */ __name(() => {
90410
+ if (options.adoptOnInterrupt === true && cancelCauseOf(signal.reason) === "user" && takeOver("interrupt"))
90411
+ return;
89691
90412
  cancel("caller");
90413
+ }, "onAbort");
90414
+ disposeAbort = subscribeToAbort(signal, onAbort);
90415
+ if (signal.aborted)
90416
+ onAbort();
89692
90417
  }
90418
+ options.onRunning?.({ background: /* @__PURE__ */ __name((reason2) => takeOver(reason2), "background") });
89693
90419
  });
89694
90420
  }
89695
90421
  __name(execHostShell, "execHostShell");
@@ -89876,38 +90602,58 @@ ${result.stderr}` : "",
89876
90602
  }
89877
90603
  const inherited = scrubInheritedEnv();
89878
90604
  const adopt = context2.backgroundJobs?.adopt?.bind(context2.backgroundJobs);
89879
- const canMoveToBackground = adopt !== void 0 && context2.sandbox === void 0 && !backgroundTasksDisabled() && !startsWithSleep(input.command);
90605
+ const canHandOff = adopt !== void 0 && context2.sandbox === void 0 && !backgroundTasksDisabled();
90606
+ const canMoveOnTimeout = canHandOff && !startsWithSleep(input.command);
90607
+ const adoptRunning = /* @__PURE__ */ __name((running) => adopt?.({
90608
+ command: input.command,
90609
+ child: running.child,
90610
+ workingDirectory: context2.workingDirectory,
90611
+ initialOutput: running.initialOutput
90612
+ }).id, "adoptRunning");
90613
+ let offerTimer;
90614
+ let withdrawOffer;
90615
+ const offer = context2.backgroundJobs?.registerForeground?.bind(context2.backgroundJobs);
89880
90616
  try {
89881
- const { stdout, stderr, stdoutBytes, stderrBytes, backgroundedJobId } = await execHostShell(input.command, {
90617
+ const { stdout, stderr, stdoutBytes, stderrBytes, backgroundedJobId, backgroundedBy } = await execHostShell(input.command, {
89882
90618
  cwd: context2.workingDirectory,
89883
90619
  timeout: input.timeout,
89884
90620
  env: { ...inherited.env, ...context2.env },
89885
90621
  maxBuffer: DEFAULT_BASH_MAX_BUFFER_BYTES,
89886
90622
  signal: context2.abortSignal,
89887
90623
  onOutput,
89888
- ...canMoveToBackground ? {
89889
- onTimeout: /* @__PURE__ */ __name(({ child, initialOutput }) => adopt({
89890
- command: input.command,
89891
- child,
89892
- workingDirectory: context2.workingDirectory,
89893
- initialOutput
89894
- }).id, "onTimeout")
90624
+ ...canMoveOnTimeout ? { onTimeout: adoptRunning } : {},
90625
+ ...canHandOff ? {
90626
+ adopt: adoptRunning,
90627
+ adoptOnInterrupt: true,
90628
+ ...offer ? {
90629
+ onRunning: /* @__PURE__ */ __name((control) => {
90630
+ offerTimer = setTimeout(() => {
90631
+ withdrawOffer = offer({
90632
+ command: input.command,
90633
+ background: /* @__PURE__ */ __name((reason2) => control.background(reason2), "background")
90634
+ });
90635
+ }, FOREGROUND_HANDOFF_AFTER_MS);
90636
+ offerTimer.unref?.();
90637
+ }, "onRunning")
90638
+ } : {}
89895
90639
  } : {}
89896
90640
  });
89897
90641
  if (backgroundedJobId !== void 0) {
90642
+ const timedOut = backgroundedBy === "timeout";
89898
90643
  return {
89899
90644
  success: true,
89900
90645
  output: [
89901
90646
  formatShellOutput(stdout, stderr),
89902
- movedToBackgroundMessage(backgroundedJobId, input.timeout)
90647
+ timedOut || backgroundedBy === void 0 ? movedToBackgroundMessage(backgroundedJobId, input.timeout) : handedOffMessage(backgroundedJobId, backgroundedBy)
89903
90648
  ].filter(Boolean).join("\n\n"),
89904
90649
  data: {
89905
90650
  jobId: backgroundedJobId,
89906
90651
  background: true,
89907
- timedOut: true,
89908
- movedToBackground: true
90652
+ ...timedOut || backgroundedBy === void 0 ? { timedOut: true } : {},
90653
+ movedToBackground: true,
90654
+ ...backgroundedBy ? { backgroundedBy } : {}
89909
90655
  },
89910
- facts: { kind: "command", command: input.command, background: true }
90656
+ facts: { kind: "command", command: input.command, background: true, continued: true }
89911
90657
  };
89912
90658
  }
89913
90659
  return {
@@ -89970,6 +90716,10 @@ ${result.stderr}` : "",
89970
90716
  ...failure2.stderrBytes !== void 0 ? { stderrBytes: failure2.stderrBytes } : {}
89971
90717
  })
89972
90718
  };
90719
+ } finally {
90720
+ if (offerTimer !== void 0)
90721
+ clearTimeout(offerTimer);
90722
+ withdrawOffer?.();
89973
90723
  }
89974
90724
  }
89975
90725
  });
@@ -96315,7 +97065,8 @@ function admitToolFacts(value) {
96315
97065
  timedOut: flag(value.timedOut),
96316
97066
  signal: text9(value.signal),
96317
97067
  binary: isRecord4(value.binary) && count6(value.binary.bytes) !== void 0 ? { bytes: count6(value.binary.bytes) } : void 0,
96318
- background: flag(value.background)
97068
+ background: flag(value.background),
97069
+ continued: flag(value.continued)
96319
97070
  });
96320
97071
  case "read": {
96321
97072
  const path2 = text9(value.path);
@@ -96511,6 +97262,8 @@ export {
96511
97262
  asCheckpointId,
96512
97263
  asProjectId,
96513
97264
  asTopicId,
97265
+ isNamzuError,
97266
+ toPlatformError,
96514
97267
  createHarnessSession,
96515
97268
  windowsShellNotice,
96516
97269
  installedCommandShellForDialect,
@@ -96709,6 +97462,9 @@ export {
96709
97462
  EXPLORE_AGENT_ID,
96710
97463
  EXPLORE_AGENT_DESCRIPTION,
96711
97464
  EXPLORE_AGENT_PROMPT,
97465
+ PLAN_AGENT_ID,
97466
+ PLAN_AGENT_DESCRIPTION,
97467
+ PLAN_AGENT_PROMPT,
96712
97468
  DiskTaskStore,
96713
97469
  DiskMemoryStore,
96714
97470
  MarkdownMemoryStore,
@@ -96747,6 +97503,9 @@ export {
96747
97503
  LocalSandboxProvider,
96748
97504
  ServerStdioTransport,
96749
97505
  ACPServer,
97506
+ UnsupportedPermissionPresetError,
97507
+ SANDBOXED_SHELL_PRESET,
97508
+ resolvePermissionPreset,
96750
97509
  WorkspaceBackendRegistry,
96751
97510
  GitWorktreeDriver,
96752
97511
  SessionSummaryMaterializer,
@@ -96840,4 +97599,4 @@ export {
96840
97599
  buildResidentToolEvidenceTools,
96841
97600
  createPalMessagingTools
96842
97601
  };
96843
- //# sourceMappingURL=chunk-4WWLRVYU.js.map
97602
+ //# sourceMappingURL=chunk-7E3V7NNN.js.map