@nimbus-sh/worker 0.9.0 → 0.11.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 (286) hide show
  1. package/NOTICE.md +5 -0
  2. package/README.md +10 -0
  3. package/dist/_shared/session-router.d.ts +7 -0
  4. package/dist/_shared/session-router.d.ts.map +1 -1
  5. package/dist/_shared/session-router.js +7 -0
  6. package/dist/bindings/body.d.ts +6 -0
  7. package/dist/bindings/body.d.ts.map +1 -0
  8. package/dist/bindings/body.js +37 -0
  9. package/dist/bindings/kv.d.ts +0 -2
  10. package/dist/bindings/kv.d.ts.map +1 -1
  11. package/dist/bindings/kv.js +3 -42
  12. package/dist/bindings/r2.d.ts +0 -2
  13. package/dist/bindings/r2.d.ts.map +1 -1
  14. package/dist/bindings/r2.js +4 -44
  15. package/dist/esbuild-cli-artifact.generated.d.ts +18 -0
  16. package/dist/esbuild-cli-artifact.generated.d.ts.map +1 -0
  17. package/dist/esbuild-cli-artifact.generated.js +17 -0
  18. package/dist/esbuild-wasm-bundle.generated.d.ts +24 -24
  19. package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -1
  20. package/dist/esbuild-wasm-bundle.generated.js +24 -24
  21. package/dist/facets/cirrus-real.d.ts.map +1 -1
  22. package/dist/facets/cirrus-real.js +11 -6
  23. package/dist/facets/compose.d.ts +11 -7
  24. package/dist/facets/compose.d.ts.map +1 -1
  25. package/dist/facets/compose.js +8 -31
  26. package/dist/facets/data-plan.d.ts +79 -0
  27. package/dist/facets/data-plan.d.ts.map +1 -0
  28. package/dist/facets/data-plan.js +477 -0
  29. package/dist/facets/esbuild-bundle-pool.d.ts +1 -1
  30. package/dist/facets/esbuild-bundle-pool.js +3 -3
  31. package/dist/facets/esbuild-transform.d.ts +38 -8
  32. package/dist/facets/esbuild-transform.d.ts.map +1 -1
  33. package/dist/facets/esbuild-transform.js +219 -19
  34. package/dist/facets/exec-telemetry.d.ts +7 -3
  35. package/dist/facets/exec-telemetry.d.ts.map +1 -1
  36. package/dist/facets/manager.d.ts +198 -69
  37. package/dist/facets/manager.d.ts.map +1 -1
  38. package/dist/facets/manager.js +1276 -652
  39. package/dist/facets/opencode-staging.d.ts +0 -2
  40. package/dist/facets/opencode-staging.d.ts.map +1 -1
  41. package/dist/facets/opencode-staging.js +5 -11
  42. package/dist/facets/process.d.ts +4 -0
  43. package/dist/facets/process.d.ts.map +1 -1
  44. package/dist/facets/process.js +3 -0
  45. package/dist/facets/read-profile.d.ts +149 -0
  46. package/dist/facets/read-profile.d.ts.map +1 -0
  47. package/dist/facets/read-profile.js +483 -0
  48. package/dist/facets/real-vite-hmr.d.ts +2 -0
  49. package/dist/facets/real-vite-hmr.d.ts.map +1 -1
  50. package/dist/facets/real-vite-hmr.js +3 -2
  51. package/dist/facets/resident-identity.d.ts +0 -1
  52. package/dist/facets/resident-identity.d.ts.map +1 -1
  53. package/dist/facets/resident-identity.js +0 -3
  54. package/dist/facets/wasm-swap-registry.d.ts +34 -25
  55. package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
  56. package/dist/facets/wasm-swap-registry.js +62 -56
  57. package/dist/facets/ws-terminal.d.ts +4 -4
  58. package/dist/facets/ws-terminal.d.ts.map +1 -1
  59. package/dist/facets/ws-terminal.js +4 -5
  60. package/dist/git/commands.d.ts +33 -10
  61. package/dist/git/commands.d.ts.map +1 -1
  62. package/dist/git/commands.js +1891 -197
  63. package/dist/git/network-facet.d.ts +12 -2
  64. package/dist/git/network-facet.d.ts.map +1 -1
  65. package/dist/git/network-facet.js +69 -18
  66. package/dist/git/unified-diff.d.ts +74 -0
  67. package/dist/git/unified-diff.d.ts.map +1 -0
  68. package/dist/git/unified-diff.js +676 -0
  69. package/dist/git-bundle.generated.d.ts +7 -11
  70. package/dist/git-bundle.generated.d.ts.map +1 -1
  71. package/dist/git-bundle.generated.js +7 -11
  72. package/dist/hosted/commands.d.ts.map +1 -1
  73. package/dist/hosted/commands.js +64 -245
  74. package/dist/hosted/runtime.d.ts +22 -15
  75. package/dist/hosted/runtime.d.ts.map +1 -1
  76. package/dist/hosted/runtime.js +72 -14
  77. package/dist/hosted/services.d.ts +8 -1
  78. package/dist/hosted/services.d.ts.map +1 -1
  79. package/dist/hosted/services.js +12 -13
  80. package/dist/hosted/session.d.ts +165 -0
  81. package/dist/hosted/session.d.ts.map +1 -0
  82. package/dist/hosted/session.js +132 -0
  83. package/dist/loaders/generated-workers.d.ts +6 -3
  84. package/dist/loaders/generated-workers.d.ts.map +1 -1
  85. package/dist/loaders/generated-workers.js +8 -5
  86. package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
  87. package/dist/loaders/npm-resolve-preamble.js +0 -27
  88. package/dist/loaders/pre-bundle-preamble.d.ts +6 -3
  89. package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -1
  90. package/dist/loaders/pre-bundle-preamble.js +13 -8
  91. package/dist/node-shims-artifact.generated.d.ts +13 -4
  92. package/dist/node-shims-artifact.generated.d.ts.map +1 -1
  93. package/dist/node-shims-artifact.generated.js +16 -7
  94. package/dist/npm/bin-links.d.ts +3 -1
  95. package/dist/npm/bin-links.d.ts.map +1 -1
  96. package/dist/npm/bin-links.js +32 -8
  97. package/dist/npm/cache.d.ts +11 -1
  98. package/dist/npm/cache.d.ts.map +1 -1
  99. package/dist/npm/cache.js +21 -7
  100. package/dist/npm/install-batch-facet.d.ts +4 -2
  101. package/dist/npm/install-batch-facet.d.ts.map +1 -1
  102. package/dist/npm/install-batch-facet.js +32 -18
  103. package/dist/npm/installer.d.ts +23 -3
  104. package/dist/npm/installer.d.ts.map +1 -1
  105. package/dist/npm/installer.js +330 -131
  106. package/dist/npm/npx-install.d.ts +3 -1
  107. package/dist/npm/npx-install.d.ts.map +1 -1
  108. package/dist/npm/npx-install.js +4 -1
  109. package/dist/npm/package-lock.d.ts +32 -0
  110. package/dist/npm/package-lock.d.ts.map +1 -0
  111. package/dist/npm/package-lock.js +65 -0
  112. package/dist/npm/placement.d.ts +16 -0
  113. package/dist/npm/placement.d.ts.map +1 -0
  114. package/dist/npm/placement.js +33 -0
  115. package/dist/npm/pre-bundle-facet.d.ts +1 -30
  116. package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
  117. package/dist/npm/pre-bundle-facet.js +3 -5
  118. package/dist/npm/r2-cache.d.ts +12 -6
  119. package/dist/npm/r2-cache.d.ts.map +1 -1
  120. package/dist/npm/r2-cache.js +34 -16
  121. package/dist/npm/resolve-one-facet.d.ts +3 -0
  122. package/dist/npm/resolve-one-facet.d.ts.map +1 -1
  123. package/dist/npm/resolve-one-facet.js +15 -3
  124. package/dist/npm/resolver.d.ts +11 -13
  125. package/dist/npm/resolver.d.ts.map +1 -1
  126. package/dist/npm/resolver.js +12 -25
  127. package/dist/opencode-artifact.generated.js +2 -2
  128. package/dist/replica/routing.d.ts +2 -38
  129. package/dist/replica/routing.d.ts.map +1 -1
  130. package/dist/replica/routing.js +3 -55
  131. package/dist/router/index.d.ts.map +1 -1
  132. package/dist/router/index.js +15 -2
  133. package/dist/router/public-directory.d.ts +18 -0
  134. package/dist/router/public-directory.d.ts.map +1 -1
  135. package/dist/router/public-directory.js +1 -1
  136. package/dist/router/remote-api.d.ts +3 -1
  137. package/dist/router/remote-api.d.ts.map +1 -1
  138. package/dist/router/remote-api.js +42 -79
  139. package/dist/runtime/bash-repl.js +2 -2
  140. package/dist/runtime/bun-repl.d.ts.map +1 -1
  141. package/dist/runtime/bun-repl.js +2 -13
  142. package/dist/runtime/cpython-resident.d.ts.map +1 -1
  143. package/dist/runtime/cpython-resident.js +2 -10
  144. package/dist/runtime/esbuild-wasm-bytes.d.ts +37 -18
  145. package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
  146. package/dist/runtime/esbuild-wasm-bytes.js +66 -92
  147. package/dist/runtime/facet-loader-host.d.ts.map +1 -1
  148. package/dist/runtime/facet-loader-host.js +0 -7
  149. package/dist/runtime/git-bundle-artifact.d.ts +17 -0
  150. package/dist/runtime/git-bundle-artifact.d.ts.map +1 -0
  151. package/dist/runtime/git-bundle-artifact.js +25 -0
  152. package/dist/runtime/node-repl.d.ts.map +1 -1
  153. package/dist/runtime/node-repl.js +2 -13
  154. package/dist/runtime/node-shims-artifact.d.ts +22 -23
  155. package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
  156. package/dist/runtime/node-shims-artifact.js +48 -78
  157. package/dist/runtime/node-shims.d.ts.map +1 -1
  158. package/dist/runtime/node-shims.js +2358 -996
  159. package/dist/runtime/opencode-artifact.d.ts.map +1 -1
  160. package/dist/runtime/opencode-artifact.js +17 -53
  161. package/dist/runtime/opencode-facet-runner.d.ts +3 -6
  162. package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
  163. package/dist/runtime/opencode-facet-runner.js +45 -10
  164. package/dist/runtime/opentui-wasm-bytes.d.ts.map +1 -1
  165. package/dist/runtime/opentui-wasm-bytes.js +16 -49
  166. package/dist/runtime/package-manager.d.ts +0 -2
  167. package/dist/runtime/package-manager.d.ts.map +1 -1
  168. package/dist/runtime/package-manager.js +0 -3
  169. package/dist/runtime/python-repl.d.ts.map +1 -1
  170. package/dist/runtime/python-repl.js +4 -35
  171. package/dist/runtime/repl-session.d.ts +10 -0
  172. package/dist/runtime/repl-session.d.ts.map +1 -1
  173. package/dist/runtime/repl-session.js +7 -0
  174. package/dist/runtime/ruby-repl.d.ts.map +1 -1
  175. package/dist/runtime/ruby-repl.js +2 -2
  176. package/dist/runtime/ruby-resident.d.ts.map +1 -1
  177. package/dist/runtime/ruby-resident.js +41 -51
  178. package/dist/runtime/runtime-catalog.d.ts +10 -3
  179. package/dist/runtime/runtime-catalog.d.ts.map +1 -1
  180. package/dist/runtime/runtime-catalog.js +125 -15
  181. package/dist/runtime/sqlite-wasm-bytes.d.ts +4 -4
  182. package/dist/runtime/sqlite-wasm-bytes.d.ts.map +1 -1
  183. package/dist/runtime/sqlite-wasm-bytes.js +21 -57
  184. package/dist/runtime/staged-source.d.ts +67 -0
  185. package/dist/runtime/staged-source.d.ts.map +1 -0
  186. package/dist/runtime/staged-source.js +113 -0
  187. package/dist/runtime/wasi/preamble.d.ts +0 -22
  188. package/dist/runtime/wasi/preamble.d.ts.map +1 -1
  189. package/dist/runtime/wasi/preamble.js +98 -1425
  190. package/dist/runtime-catalog.generated.js +1 -1
  191. package/dist/session/agent.d.ts +14 -2
  192. package/dist/session/agent.d.ts.map +1 -1
  193. package/dist/session/agent.js +57 -19
  194. package/dist/session/ai.d.ts +0 -11
  195. package/dist/session/ai.d.ts.map +1 -1
  196. package/dist/session/ai.js +0 -4
  197. package/dist/session/fs-watch.d.ts +0 -11
  198. package/dist/session/fs-watch.d.ts.map +1 -1
  199. package/dist/session/fs-watch.js +0 -21
  200. package/dist/session/hibernation.d.ts +68 -2
  201. package/dist/session/hibernation.d.ts.map +1 -1
  202. package/dist/session/hibernation.js +95 -1
  203. package/dist/session/init-phases.d.ts +1 -2
  204. package/dist/session/init-phases.d.ts.map +1 -1
  205. package/dist/session/init-phases.js +1 -2
  206. package/dist/session/init.d.ts.map +1 -1
  207. package/dist/session/init.js +7 -20
  208. package/dist/session/keys.d.ts +0 -3
  209. package/dist/session/keys.d.ts.map +1 -1
  210. package/dist/session/keys.js +0 -3
  211. package/dist/session/legacy-reset.d.ts +11 -0
  212. package/dist/session/legacy-reset.d.ts.map +1 -0
  213. package/dist/session/legacy-reset.js +16 -0
  214. package/dist/session/nimbus-session.d.ts +50 -16
  215. package/dist/session/nimbus-session.d.ts.map +1 -1
  216. package/dist/session/nimbus-session.js +77 -71
  217. package/dist/session/npm-install-port.d.ts.map +1 -1
  218. package/dist/session/npm-install-port.js +2 -0
  219. package/dist/session/programmatic.d.ts +13 -18
  220. package/dist/session/programmatic.d.ts.map +1 -1
  221. package/dist/session/programmatic.js +53 -39
  222. package/dist/session/replica-routes.d.ts +2 -3
  223. package/dist/session/replica-routes.d.ts.map +1 -1
  224. package/dist/session/replica-routes.js +3 -10
  225. package/dist/session/routes.d.ts.map +1 -1
  226. package/dist/session/routes.js +11 -12
  227. package/dist/session/rpc.d.ts +108 -21
  228. package/dist/session/rpc.d.ts.map +1 -1
  229. package/dist/session/rpc.js +194 -39
  230. package/dist/session/start-real-vite.js +2 -2
  231. package/dist/session/state-store.d.ts +1 -17
  232. package/dist/session/state-store.d.ts.map +1 -1
  233. package/dist/session/state-store.js +3 -53
  234. package/dist/session/supervisor-op.d.ts +7 -0
  235. package/dist/session/supervisor-op.d.ts.map +1 -1
  236. package/dist/session/supervisor-op.js +6 -1
  237. package/dist/session/supervisor-rpc.d.ts +116 -19
  238. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  239. package/dist/session/supervisor-rpc.js +194 -84
  240. package/dist/session/vite-command.d.ts.map +1 -1
  241. package/dist/session/vite-command.js +17 -14
  242. package/dist/session/ws.d.ts.map +1 -1
  243. package/dist/session/ws.js +20 -8
  244. package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
  245. package/dist/shell/npm-bin-entrypoints.js +30 -5
  246. package/dist/vfs/facet-resident-limits.d.ts +33 -0
  247. package/dist/vfs/facet-resident-limits.d.ts.map +1 -0
  248. package/dist/vfs/facet-resident-limits.js +33 -0
  249. package/dist/vfs/facet-resident-store.d.ts +2 -10
  250. package/dist/vfs/facet-resident-store.d.ts.map +1 -1
  251. package/dist/vfs/facet-resident-store.js +1594 -219
  252. package/dist/workspace-host.d.ts +3 -1
  253. package/dist/workspace-host.d.ts.map +1 -1
  254. package/dist/workspace-host.js +2 -0
  255. package/dist/wrangler/nimbus-wrangler.d.ts +0 -2
  256. package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
  257. package/dist/wrangler/nimbus-wrangler.js +8 -22
  258. package/package.json +34 -7
  259. package/public/_assets/esbuild-0.24.2.js +2380 -0
  260. package/public/_assets/opencode/1.16.2/index-attach.js +2 -2
  261. package/public/_assets/runtime/esbuild-cli-c4fda380d52befc1.js +6892 -0
  262. package/public/_assets/runtime/git-de3e60c9f3ff006a.js +103 -0
  263. package/public/_assets/runtime/{node-shims-acaa037e6d26ec0d.js → node-shims-06565b121555c194.js} +2879 -992
  264. package/public/_assets/runtime/resident-store-6ffb1939c53d982f.js +2264 -0
  265. package/public/_assets/runtime/vfs-write-ledger-e501e8fc793bc2c1.js +889 -0
  266. package/scripts/build-opencode-attach-entry.mjs +51 -1
  267. package/scripts/bundle-esbuild-wasm.mjs +55 -39
  268. package/scripts/bundle-facet-workers.mjs +159 -10
  269. package/scripts/bundle-git.mjs +88 -27
  270. package/scripts/bundle-node-shims.mjs +72 -46
  271. package/scripts/bundle-runtime.mjs +18 -421
  272. package/scripts/cf-git-patch.mjs +137 -0
  273. package/scripts/patch-install-deps.mjs +49 -96
  274. package/scripts/runtime-specs.mjs +435 -0
  275. package/vendor/git-http.generated.d.ts +82 -0
  276. package/vendor/git-upstream.generated.d.ts +4378 -0
  277. package/vendor/git.LICENSE +7 -0
  278. package/vendor/git.generated.d.mts +21 -0
  279. package/vendor/git.generated.mjs +103 -0
  280. package/dist/replica/suspension.d.ts +0 -36
  281. package/dist/replica/suspension.d.ts.map +0 -1
  282. package/dist/replica/suspension.js +0 -49
  283. package/dist/runtime/static-server.d.ts +0 -3
  284. package/dist/runtime/static-server.d.ts.map +0 -1
  285. package/dist/runtime/static-server.js +0 -133
  286. package/scripts/clean-dist.mjs +0 -7
@@ -2688,7 +2688,7 @@ Command timed out before completion.`:`${e.output}${t}
2688
2688
 
2689
2689
  Command exited with code ${e.exitCode}.`},Uws=e=>e.cause instanceof Error&&e.cause.message==="Timed out",Kws=_y.make({description:`Execute one shell command string with the host user's filesystem, process, and network authority. The active Location is the default working directory. Relative workdir values resolve from that Location. External workdir values require external_directory approval; best-effort command-argument path warnings are advisory only. Timeout values are milliseconds (default: ${VCe}; maximum: ${$Ce}). Uses the configured shell when set; otherwise uses /bin/sh on POSIX and COMSPEC or cmd.exe on Windows.`,parameters:nPr,success:Gws,toModelOutput:({output:e})=>[f0({type:"text",text:Wws(e)})]}),Qws=e=>e.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)??[],Yws=e=>e.replace(/^(['"])(.*)\1$/,"$2"),Jws=(e,t)=>{let r=new Set;for(let n of Qws(e)){let s=Yws(n).replace(/[;,|&]+$/,"");if(!rut.isAbsolute(s))continue;let a=Wr.resolve(s);Wr.contains(t,a)||r.add(Wr.resolve(rut.dirname(a)))}return[...r]},Xws=Tt.effectDiscard(M.gen(function*(){let e=yield*k0.Service,t=yield*fx.Service,r=yield*hc.Service,n=yield*Hv.Service,s=yield*Zh.Service;yield*e.contribute(a=>a.set(uut,{tool:Kws,execute:({parameters:o,sessionID:l,call:c,assertPermission:u})=>M.gen(function*(){let d=yield*t.resolve({path:o.workdir??".",kind:"directory"}),f=d.target.externalDirectory;f&&(yield*u(fx.externalDirectoryPermission(f)));let p=Jws(o.command,d.target.canonical).map(E=>`Command argument references external directory ${rut.join(E,"*").replaceAll("\\","/")}. Bash runs with host-user filesystem, process, and network authority; this scan is advisory only.`);yield*u({action:uut,resources:[o.command],save:[o.command]});let m=yield*t.revalidate(d);if(!m.exists||m.type!=="Directory")throw Error(`Working directory is not a directory: ${m.canonical}`);let g=yield*s.entries(),y=Object.assign({},...g.flatMap(E=>E.type==="document"?[E.info]:[])).shell??Hws(),v=bl.make(o.command,[],{cwd:m.canonical,shell:y,stdin:"ignore",detached:process.platform!=="win32",forceKillAfter:Fo.seconds(3)}),b=o.timeout??VCe,_=yield*r.run(v,{timeout:Fo.millis(b),maxOutputBytes:cut,maxErrorBytes:cut}).pipe(M.catchTag("AppProcessError",E=>Uws(E)?M.succeed(void 0):M.fail(E)));if(!_)return{command:o.command,cwd:m.canonical,output:`Command exceeded timeout of ${b} ms. Retry with a larger timeout if the command is expected to take longer.`,truncated:!1,timedOut:!0,...p.length?{warnings:p}:{}};let A=Vws(_.stdout.toString("utf8"),_.stderr.toString("utf8")),w=zws(_.stdoutTruncated,_.stderrTruncated),S=yield*n.truncate({sessionID:l,toolCallID:c.id,content:w?`${A}
2690
2690
 
2691
- ${w}`:A});return{command:o.command,cwd:m.canonical,exitCode:_.exitCode,output:S.content,truncated:S.truncated||_.stdoutTruncated||_.stderrTruncated,...p.length?{warnings:p}:{},..._.stdoutTruncated?{stdoutTruncated:!0}:{},..._.stderrTruncated?{stderrTruncated:!0}:{},...S.truncated&&!_.stdoutTruncated&&!_.stderrTruncated?{resource:S.resource}:{}}}).pipe(M.catchCause(d=>M.fail(new Gu({message:`Unable to execute command: ${o.command}`,error:Dn.squash(d)}))))}))})),dut={};Ft(dut,{toModelOutput:()=>uPr,name:()=>sPr,layer:()=>dEs,Success:()=>lPr,Parameters:()=>aPr,ApplyPatchTool:()=>dut,Applied:()=>oPr});qoe={};Ft(qoe,{parse:()=>Zws,joinBom:()=>tEs,derive:()=>eEs,Patch:()=>qoe});sEs=(e,t)=>e===t,aEs=(e,t)=>e.trimEnd()===t.trimEnd(),oEs=(e,t)=>e.trim()===t.trim(),lEs=(e,t)=>RRr(e.trim())===RRr(t.trim()),RRr=e=>e.replace(/[‘’‚‛]/g,"'").replace(/[“”„‟]/g,'"').replace(/[‐‑‒–—―]/g,"-").replace(/…/g,"...").replace(/ /g," "),put=e=>e.startsWith("\uFEFF")?{bom:!0,text:e.slice(1)}:{bom:!1,text:e},uEs=e=>e.match(/^(?:cat\s+)?<<['"]?(\w+)['"]?\s*\n([\s\S]*?)\n\1\s*$/)?.[2]??e,sPr="apply_patch",aPr=T.Struct({patchText:T.String.annotate({description:"The full patch text describing add, update, and delete operations"})}),oPr=T.Struct({type:T.Literals(["add","update","delete"]),resource:T.String,target:T.String}),lPr=T.Struct({applied:T.Array(oPr)}),uPr=e=>["Applied patch sequentially:",...e.applied.map(t=>`${t.type==="add"?"A":t.type==="delete"?"D":"M"} ${t.resource}`)].join(`
2691
+ ${w}`:A});return{command:o.command,cwd:m.canonical,exitCode:_.exitCode,output:S.content,truncated:S.truncated||_.stdoutTruncated||_.stderrTruncated,...p.length?{warnings:p}:{},..._.stdoutTruncated?{stdoutTruncated:!0}:{},..._.stderrTruncated?{stderrTruncated:!0}:{},...S.truncated&&!_.stdoutTruncated&&!_.stderrTruncated?{resource:S.resource}:{}}}).pipe(M.catchCause(d=>M.fail(new Gu({message:`Unable to execute command: ${o.command}`,error:Dn.squash(d)}))))}))})),dut={};Ft(dut,{toModelOutput:()=>uPr,name:()=>sPr,layer:()=>dEs,Success:()=>lPr,Parameters:()=>aPr,ApplyPatchTool:()=>dut,Applied:()=>oPr});qoe={};Ft(qoe,{parse:()=>Zws,joinBom:()=>tEs,derive:()=>eEs,Patch:()=>qoe});sEs=(e,t)=>e===t,aEs=(e,t)=>e.trimEnd()===t.trimEnd(),oEs=(e,t)=>e.trim()===t.trim(),lEs=(e,t)=>RRr(e.trim())===RRr(t.trim()),RRr=e=>e.replace(/[\u2018\u2019\u201a\u201b]/g,"'").replace(/[\u201c\u201d\u201e\u201f]/g,'"').replace(/[\u2010\u2011\u2012\u2013\u2014\u2015]/g,"-").replace(/\u2026/g,"...").replace(/\u00a0/g," "),put=e=>e.startsWith("\uFEFF")?{bom:!0,text:e.slice(1)}:{bom:!1,text:e},uEs=e=>e.match(/^(?:cat\s+)?<<['"]?(\w+)['"]?\s*\n([\s\S]*?)\n\1\s*$/)?.[2]??e,sPr="apply_patch",aPr=T.Struct({patchText:T.String.annotate({description:"The full patch text describing add, update, and delete operations"})}),oPr=T.Struct({type:T.Literals(["add","update","delete"]),resource:T.String,target:T.String}),lPr=T.Struct({applied:T.Array(oPr)}),uPr=e=>["Applied patch sequentially:",...e.applied.map(t=>`${t.type==="add"?"A":t.type==="delete"?"D":"M"} ${t.resource}`)].join(`
2692
2692
  `),cEs=_y.make({description:"Apply one patch containing add, update, and delete file operations. All targets are resolved and approved before target contents are read. Operations apply sequentially; if a later operation fails, earlier operations remain applied and the failure reports them explicitly. Moves and atomic rollback are not supported yet.",parameters:aPr,success:lPr,toModelOutput:({output:e})=>[f0({type:"text",text:uPr(e)})]}),dEs=Tt.effectDiscard(M.gen(function*(){let e=yield*k0.Service,t=yield*fx.Service,r=yield*G6.Service,n=yield*Wr.Service;yield*e.contribute(s=>s.set(sPr,{tool:cEs,execute:({parameters:a,assertPermission:o})=>{let l=[],c=(u,d)=>{let f=l.length===0?`Unable to apply patch at ${u}`:`Patch partially applied before failing at ${u}. Applied: ${l.map(p=>p.resource).join(", ")}`;return new Gu({message:f,error:d})};return M.gen(function*(){if(!a.patchText.trim())return yield*new Gu({message:"patchText is required"});let u=yield*M.try({try:()=>qoe.parse(a.patchText),catch:m=>new Gu({message:`apply_patch verification failed: ${String(m)}`})});if(u.length===0)return yield*new Gu({message:"patch rejected: empty patch"});if(u.find(m=>m.type==="update"&&m.movePath!==void 0))return yield*new Gu({message:"apply_patch moves are not supported yet"});let d=[];for(let m of u)d.push({hunk:m,plan:yield*t.resolve({path:m.path,kind:"file"})});let f=new Map;for(let{plan:m}of d){let g=m.target.externalDirectory;g&&f.set(g.resource,g)}for(let m of f.values())yield*o(fx.externalDirectoryPermission(m));yield*o({action:"edit",resources:[...new Set(d.map(({plan:m})=>m.target.resource))],save:["*"]});let p=[];for(let{hunk:m,plan:g}of d){if(m.type==="add"){if((yield*t.revalidate(g)).exists)return yield*c(m.path,Error("Target file already exists"));p.push({type:m.type,hunk:m,plan:g});continue}let y=yield*t.revalidate(g);if(!y.exists||y.type!=="File")return yield*c(m.path,Error("Target file does not exist"));if(m.type==="delete"){p.push({type:m.type,hunk:m,plan:g});continue}let v=yield*n.readFile(y.canonical),b=qoe.derive(m.path,m.chunks,new TextDecoder("utf-8",{ignoreBOM:!0}).decode(v));p.push({type:m.type,hunk:m,plan:g,source:v,content:qoe.joinBom(b.content,b.bom)})}return yield*M.uninterruptible(M.forEach(p,m=>M.gen(function*(){if(m.type==="add"){let y=yield*r.create({plan:m.plan,content:m.hunk.contents.endsWith(`
2693
2693
  `)||m.hunk.contents===""?m.hunk.contents:`${m.hunk.contents}
2694
2694
  `});l.push({type:m.type,resource:y.resource,target:y.target});return}if(m.type==="delete"){let y=yield*r.remove({plan:m.plan});l.push({type:m.type,resource:y.resource,target:y.target});return}let g=yield*r.writeIfUnchanged({plan:m.plan,expected:m.source,content:m.content});l.push({type:m.type,resource:g.resource,target:g.target})}).pipe(M.catchCause(g=>M.fail(c(m.hunk.path,Dn.squash(g))))),{discard:!0})),{applied:l}}).pipe(M.catchCause(u=>{let d=Dn.squash(u);return M.fail(d instanceof Gu?d:c("patch",d))}))}}))})),fut={};Ft(fut,{toModelOutput:()=>fPr,name:()=>cPr,layer:()=>vEs,Success:()=>pPr,Parameters:()=>dPr,EditTool:()=>fut});cPr="edit",dPr=T.Struct({path:T.String.annotate({description:"File path to edit. Relative paths resolve within the active Location. Absolute paths inside that Location are accepted; external absolute paths require external_directory approval. Named project references are read-oriented and are not accepted."}),oldString:T.String.annotate({description:"Exact text to replace"}),newString:T.String.annotate({description:"Replacement text, which must differ from oldString"}),replaceAll:T.Boolean.pipe(T.optional).annotate({description:"Replace all exact occurrences of oldString (default false)"})}),pPr=T.Struct({operation:T.Literal("write"),target:T.String,resource:T.String,existed:T.Boolean,replacements:T.Number}),hut=e=>e.replaceAll(`\r
@@ -3775,7 +3775,7 @@ gh pr create --title "the pr title" --body-file pr-body.txt`,parameterDescriptio
3775
3775
  `);s.length>0&&s[s.length-1]===""&&s.pop();let a=D6s(s,e,t),o=O6s(s,a);(o.length===0||o[o.length-1]!=="")&&o.push("");let l=xj(o.join(`
3776
3776
  `)),c=l.text;return{unified_diff:R6s(n.text,c),content:c,bom:n.bom||l.bom}}function D6s(e,t,r){let n=[],s=0;for(let a of r){if(a.change_context){let u=Spt(e,[a.change_context],s);if(u===-1)throw Error(`Failed to find context '${a.change_context}' in ${t}`);s=u+1}if(a.old_lines.length===0){let u=e.length>0&&e[e.length-1]===""?e.length-1:e.length;n.push([u,0,a.new_lines]);continue}let{old_lines:o,new_lines:l}=a,c=Spt(e,o,s,a.is_end_of_file);if(c===-1&&o.length>0&&o[o.length-1]===""&&(o=o.slice(0,-1),l.length>0&&l[l.length-1]===""&&(l=l.slice(0,-1)),c=Spt(e,o,s,a.is_end_of_file)),c!==-1)n.push([c,o.length,l]),s=c+o.length;else throw Error(`Failed to find expected lines in ${t}:
3777
3777
  ${a.old_lines.join(`
3778
- `)}`)}return n.sort((a,o)=>a[0]-o[0]),n}function O6s(e,t){let r=[...e];for(let n=t.length-1;n>=0;n--){let[s,a,o]=t[n];r.splice(s,a);for(let l=0;l<o.length;l++)r.splice(s+l,0,o[l])}return r}function YFr(e){return e.replace(/[‘’‚‛]/g,"'").replace(/[“”„‟]/g,'"').replace(/[‐‑‒–—―]/g,"-").replace(/…/g,"...").replace(/ /g," ")}function nDe(e,t,r,n,s){if(s){let a=e.length-t.length;if(a>=r){let o=!0;for(let l=0;l<t.length;l++)if(!n(e[a+l],t[l])){o=!1;break}if(o)return a}}for(let a=r;a<=e.length-t.length;a++){let o=!0;for(let l=0;l<t.length;l++)if(!n(e[a+l],t[l])){o=!1;break}if(o)return a}return-1}function Spt(e,t,r,n=!1){if(t.length===0)return-1;let s=nDe(e,t,r,(l,c)=>l===c,n);if(s!==-1)return s;let a=nDe(e,t,r,(l,c)=>l.trimEnd()===c.trimEnd(),n);if(a!==-1)return a;let o=nDe(e,t,r,(l,c)=>l.trim()===c.trim(),n);return o!==-1?o:nDe(e,t,r,(l,c)=>YFr(l.trim())===YFr(c.trim()),n)}function R6s(e,t){let r=e.split(`
3778
+ `)}`)}return n.sort((a,o)=>a[0]-o[0]),n}function O6s(e,t){let r=[...e];for(let n=t.length-1;n>=0;n--){let[s,a,o]=t[n];r.splice(s,a);for(let l=0;l<o.length;l++)r.splice(s+l,0,o[l])}return r}function YFr(e){return e.replace(/[\u2018\u2019\u201a\u201b]/g,"'").replace(/[\u201c\u201d\u201e\u201f]/g,'"').replace(/[\u2010\u2011\u2012\u2013\u2014\u2015]/g,"-").replace(/\u2026/g,"...").replace(/\u00a0/g," ")}function nDe(e,t,r,n,s){if(s){let a=e.length-t.length;if(a>=r){let o=!0;for(let l=0;l<t.length;l++)if(!n(e[a+l],t[l])){o=!1;break}if(o)return a}}for(let a=r;a<=e.length-t.length;a++){let o=!0;for(let l=0;l<t.length;l++)if(!n(e[a+l],t[l])){o=!1;break}if(o)return a}return-1}function Spt(e,t,r,n=!1){if(t.length===0)return-1;let s=nDe(e,t,r,(l,c)=>l===c,n);if(s!==-1)return s;let a=nDe(e,t,r,(l,c)=>l.trimEnd()===c.trimEnd(),n);if(a!==-1)return a;let o=nDe(e,t,r,(l,c)=>l.trim()===c.trim(),n);return o!==-1?o:nDe(e,t,r,(l,c)=>YFr(l.trim())===YFr(c.trim()),n)}function R6s(e,t){let r=e.split(`
3779
3779
  `),n=t.split(`
3780
3780
  `),s=`@@ -1 +1 @@
3781
3781
  `,a=Math.max(r.length,n.length),o=!1;for(let l=0;l<a;l++){let c=r[l]||"",u=n[l]||"";c!==u?(c&&(s+=`-${c}