@corbet-labs/ccht 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/LICENSE +307 -0
  2. package/LICENSE.md +25 -0
  3. package/LICENSES/GPL-3.0-only.txt +232 -0
  4. package/LICENSES/LGPL-3.0-only.txt +304 -0
  5. package/LICENSES/dependencies/agent-client-protocol-2.1.0/LICENSE +191 -0
  6. package/LICENSES/dependencies/agent-client-protocol-derive-2.1.0/LICENSE +191 -0
  7. package/LICENSES/dependencies/agent-client-protocol-schema-1.7.0/LICENSE +190 -0
  8. package/LICENSES/dependencies/android_system_properties-0.1.6/LICENSE-APACHE +13 -0
  9. package/LICENSES/dependencies/android_system_properties-0.1.6/LICENSE-MIT +20 -0
  10. package/LICENSES/dependencies/anyhow-1.0.104/LICENSE-APACHE +176 -0
  11. package/LICENSES/dependencies/anyhow-1.0.104/LICENSE-MIT +23 -0
  12. package/LICENSES/dependencies/async-channel-2.5.0/LICENSE-APACHE +201 -0
  13. package/LICENSES/dependencies/async-channel-2.5.0/LICENSE-MIT +23 -0
  14. package/LICENSES/dependencies/async-io-2.6.0/LICENSE-APACHE +201 -0
  15. package/LICENSES/dependencies/async-io-2.6.0/LICENSE-MIT +23 -0
  16. package/LICENSES/dependencies/async-lock-3.4.2/LICENSE-APACHE +201 -0
  17. package/LICENSES/dependencies/async-lock-3.4.2/LICENSE-MIT +23 -0
  18. package/LICENSES/dependencies/async-process-2.5.0/LICENSE-APACHE +201 -0
  19. package/LICENSES/dependencies/async-process-2.5.0/LICENSE-MIT +23 -0
  20. package/LICENSES/dependencies/async-signal-0.2.14/LICENSE-APACHE +201 -0
  21. package/LICENSES/dependencies/async-signal-0.2.14/LICENSE-MIT +23 -0
  22. package/LICENSES/dependencies/async-task-4.7.1/LICENSE-APACHE +201 -0
  23. package/LICENSES/dependencies/async-task-4.7.1/LICENSE-MIT +23 -0
  24. package/LICENSES/dependencies/atomic-waker-1.1.2/LICENSE-APACHE +201 -0
  25. package/LICENSES/dependencies/atomic-waker-1.1.2/LICENSE-MIT +23 -0
  26. package/LICENSES/dependencies/atomic-waker-1.1.2/LICENSE-THIRD-PARTY +45 -0
  27. package/LICENSES/dependencies/autocfg-1.5.1/LICENSE-APACHE +201 -0
  28. package/LICENSES/dependencies/autocfg-1.5.1/LICENSE-MIT +25 -0
  29. package/LICENSES/dependencies/base64-0.22.1/LICENSE-APACHE +201 -0
  30. package/LICENSES/dependencies/base64-0.22.1/LICENSE-MIT +21 -0
  31. package/LICENSES/dependencies/base64-0.23.1/LICENSE-APACHE +201 -0
  32. package/LICENSES/dependencies/base64-0.23.1/LICENSE-MIT +21 -0
  33. package/LICENSES/dependencies/bitflags-1.3.2/LICENSE-APACHE +201 -0
  34. package/LICENSES/dependencies/bitflags-1.3.2/LICENSE-MIT +25 -0
  35. package/LICENSES/dependencies/bitflags-2.13.2/LICENSE-APACHE +201 -0
  36. package/LICENSES/dependencies/bitflags-2.13.2/LICENSE-MIT +25 -0
  37. package/LICENSES/dependencies/blocking-1.7.0/LICENSE-APACHE +201 -0
  38. package/LICENSES/dependencies/blocking-1.7.0/LICENSE-MIT +23 -0
  39. package/LICENSES/dependencies/bs58-0.5.1/LICENSE-APACHE +201 -0
  40. package/LICENSES/dependencies/bs58-0.5.1/LICENSE-MIT +20 -0
  41. package/LICENSES/dependencies/bumpalo-3.20.3/LICENSE-APACHE +201 -0
  42. package/LICENSES/dependencies/bumpalo-3.20.3/LICENSE-MIT +25 -0
  43. package/LICENSES/dependencies/cc-1.4.5/LICENSE-APACHE +201 -0
  44. package/LICENSES/dependencies/cc-1.4.5/LICENSE-MIT +25 -0
  45. package/LICENSES/dependencies/cfg-if-1.0.4/LICENSE-APACHE +201 -0
  46. package/LICENSES/dependencies/cfg-if-1.0.4/LICENSE-MIT +25 -0
  47. package/LICENSES/dependencies/chrono-0.4.45/LICENSE.txt +240 -0
  48. package/LICENSES/dependencies/concurrent-queue-2.5.0/LICENSE-APACHE +201 -0
  49. package/LICENSES/dependencies/concurrent-queue-2.5.0/LICENSE-MIT +23 -0
  50. package/LICENSES/dependencies/convert_case-0.10.0/LICENSE +21 -0
  51. package/LICENSES/dependencies/core-foundation-sys-0.8.7/LICENSE-APACHE +201 -0
  52. package/LICENSES/dependencies/core-foundation-sys-0.8.7/LICENSE-MIT +25 -0
  53. package/LICENSES/dependencies/crossbeam-deque-0.8.8/LICENSE-APACHE +201 -0
  54. package/LICENSES/dependencies/crossbeam-deque-0.8.8/LICENSE-MIT +27 -0
  55. package/LICENSES/dependencies/crossbeam-epoch-0.9.21/LICENSE-APACHE +201 -0
  56. package/LICENSES/dependencies/crossbeam-epoch-0.9.21/LICENSE-MIT +27 -0
  57. package/LICENSES/dependencies/crossbeam-utils-0.8.23/LICENSE-APACHE +201 -0
  58. package/LICENSES/dependencies/crossbeam-utils-0.8.23/LICENSE-MIT +27 -0
  59. package/LICENSES/dependencies/darling-0.24.1/LICENSE +21 -0
  60. package/LICENSES/dependencies/darling_core-0.24.1/LICENSE +21 -0
  61. package/LICENSES/dependencies/darling_macro-0.24.1/LICENSE +21 -0
  62. package/LICENSES/dependencies/defmt-1.1.1/LICENSE-APACHE +201 -0
  63. package/LICENSES/dependencies/defmt-1.1.1/LICENSE-MIT +25 -0
  64. package/LICENSES/dependencies/defmt-macros-1.1.1/LICENSE-APACHE +201 -0
  65. package/LICENSES/dependencies/defmt-macros-1.1.1/LICENSE-MIT +25 -0
  66. package/LICENSES/dependencies/defmt-parser-1.0.0/LICENSE-APACHE +201 -0
  67. package/LICENSES/dependencies/defmt-parser-1.0.0/LICENSE-MIT +25 -0
  68. package/LICENSES/dependencies/deranged-0.5.8/LICENSE-Apache +202 -0
  69. package/LICENSES/dependencies/deranged-0.5.8/LICENSE-MIT +19 -0
  70. package/LICENSES/dependencies/derive_more-2.1.1/LICENSE +21 -0
  71. package/LICENSES/dependencies/derive_more-impl-2.1.1/LICENSE +21 -0
  72. package/LICENSES/dependencies/dyn-clone-1.0.20/LICENSE-APACHE +176 -0
  73. package/LICENSES/dependencies/dyn-clone-1.0.20/LICENSE-MIT +23 -0
  74. package/LICENSES/dependencies/either-1.18.0/LICENSE-APACHE +201 -0
  75. package/LICENSES/dependencies/either-1.18.0/LICENSE-MIT +25 -0
  76. package/LICENSES/dependencies/equivalent-1.0.2/LICENSE-APACHE +201 -0
  77. package/LICENSES/dependencies/equivalent-1.0.2/LICENSE-MIT +25 -0
  78. package/LICENSES/dependencies/errno-0.3.14/LICENSE-APACHE +201 -0
  79. package/LICENSES/dependencies/errno-0.3.14/LICENSE-MIT +25 -0
  80. package/LICENSES/dependencies/event-listener-5.4.2/LICENSE-APACHE +201 -0
  81. package/LICENSES/dependencies/event-listener-5.4.2/LICENSE-MIT +23 -0
  82. package/LICENSES/dependencies/event-listener-strategy-0.5.4/LICENSE-APACHE +201 -0
  83. package/LICENSES/dependencies/event-listener-strategy-0.5.4/LICENSE-MIT +23 -0
  84. package/LICENSES/dependencies/fallible-iterator-0.3.0/LICENSE-APACHE +202 -0
  85. package/LICENSES/dependencies/fallible-iterator-0.3.0/LICENSE-MIT +19 -0
  86. package/LICENSES/dependencies/fastrand-2.5.0/LICENSE-APACHE +201 -0
  87. package/LICENSES/dependencies/fastrand-2.5.0/LICENSE-MIT +23 -0
  88. package/LICENSES/dependencies/find-msvc-tools-0.1.12/LICENSE-APACHE +201 -0
  89. package/LICENSES/dependencies/find-msvc-tools-0.1.12/LICENSE-MIT +25 -0
  90. package/LICENSES/dependencies/fixedbitset-0.5.7/LICENSE-APACHE +201 -0
  91. package/LICENSES/dependencies/fixedbitset-0.5.7/LICENSE-MIT +25 -0
  92. package/LICENSES/dependencies/foldhash-0.2.0/LICENSE +19 -0
  93. package/LICENSES/dependencies/futures-0.3.34/LICENSE-APACHE +202 -0
  94. package/LICENSES/dependencies/futures-0.3.34/LICENSE-MIT +26 -0
  95. package/LICENSES/dependencies/futures-channel-0.3.34/LICENSE-APACHE +202 -0
  96. package/LICENSES/dependencies/futures-channel-0.3.34/LICENSE-MIT +26 -0
  97. package/LICENSES/dependencies/futures-concurrency-7.7.1/LICENSE-APACHE +190 -0
  98. package/LICENSES/dependencies/futures-concurrency-7.7.1/LICENSE-MIT +21 -0
  99. package/LICENSES/dependencies/futures-core-0.3.34/LICENSE-APACHE +202 -0
  100. package/LICENSES/dependencies/futures-core-0.3.34/LICENSE-MIT +26 -0
  101. package/LICENSES/dependencies/futures-executor-0.3.34/LICENSE-APACHE +202 -0
  102. package/LICENSES/dependencies/futures-executor-0.3.34/LICENSE-MIT +26 -0
  103. package/LICENSES/dependencies/futures-io-0.3.34/LICENSE-APACHE +202 -0
  104. package/LICENSES/dependencies/futures-io-0.3.34/LICENSE-MIT +26 -0
  105. package/LICENSES/dependencies/futures-lite-2.6.1/LICENSE-APACHE +201 -0
  106. package/LICENSES/dependencies/futures-lite-2.6.1/LICENSE-MIT +23 -0
  107. package/LICENSES/dependencies/futures-lite-2.6.1/LICENSE-THIRD-PARTY +45 -0
  108. package/LICENSES/dependencies/futures-macro-0.3.34/LICENSE-APACHE +202 -0
  109. package/LICENSES/dependencies/futures-macro-0.3.34/LICENSE-MIT +26 -0
  110. package/LICENSES/dependencies/futures-sink-0.3.34/LICENSE-APACHE +202 -0
  111. package/LICENSES/dependencies/futures-sink-0.3.34/LICENSE-MIT +26 -0
  112. package/LICENSES/dependencies/futures-task-0.3.34/LICENSE-APACHE +202 -0
  113. package/LICENSES/dependencies/futures-task-0.3.34/LICENSE-MIT +26 -0
  114. package/LICENSES/dependencies/futures-util-0.3.34/LICENSE-APACHE +202 -0
  115. package/LICENSES/dependencies/futures-util-0.3.34/LICENSE-MIT +26 -0
  116. package/LICENSES/dependencies/getrandom-0.4.3/LICENSE-APACHE +201 -0
  117. package/LICENSES/dependencies/getrandom-0.4.3/LICENSE-MIT +26 -0
  118. package/LICENSES/dependencies/gimli-0.32.3/LICENSE-APACHE +201 -0
  119. package/LICENSES/dependencies/gimli-0.32.3/LICENSE-MIT +25 -0
  120. package/LICENSES/dependencies/hashbrown-0.12.3/LICENSE-APACHE +201 -0
  121. package/LICENSES/dependencies/hashbrown-0.12.3/LICENSE-MIT +25 -0
  122. package/LICENSES/dependencies/hashbrown-0.16.1/LICENSE-APACHE +201 -0
  123. package/LICENSES/dependencies/hashbrown-0.16.1/LICENSE-MIT +25 -0
  124. package/LICENSES/dependencies/hashbrown-0.17.1/LICENSE-APACHE +201 -0
  125. package/LICENSES/dependencies/hashbrown-0.17.1/LICENSE-MIT +25 -0
  126. package/LICENSES/dependencies/heck-0.5.0/LICENSE-APACHE +201 -0
  127. package/LICENSES/dependencies/heck-0.5.0/LICENSE-MIT +25 -0
  128. package/LICENSES/dependencies/hermit-abi-0.5.3/LICENSE-APACHE +201 -0
  129. package/LICENSES/dependencies/hermit-abi-0.5.3/LICENSE-MIT +23 -0
  130. package/LICENSES/dependencies/hex-0.4.3/LICENSE-APACHE +202 -0
  131. package/LICENSES/dependencies/hex-0.4.3/LICENSE-MIT +20 -0
  132. package/LICENSES/dependencies/iana-time-zone-0.1.65/LICENSE-APACHE +201 -0
  133. package/LICENSES/dependencies/iana-time-zone-0.1.65/LICENSE-MIT +25 -0
  134. package/LICENSES/dependencies/iana-time-zone-haiku-0.1.2/LICENSE-APACHE +201 -0
  135. package/LICENSES/dependencies/iana-time-zone-haiku-0.1.2/LICENSE-MIT +25 -0
  136. package/LICENSES/dependencies/id-arena-2.3.0/LICENSE-APACHE +201 -0
  137. package/LICENSES/dependencies/id-arena-2.3.0/LICENSE-MIT +25 -0
  138. package/LICENSES/dependencies/ident_case-1.0.1/LICENSE +19 -0
  139. package/LICENSES/dependencies/indexmap-1.9.3/LICENSE-APACHE +201 -0
  140. package/LICENSES/dependencies/indexmap-1.9.3/LICENSE-MIT +25 -0
  141. package/LICENSES/dependencies/indexmap-2.14.2/LICENSE-APACHE +201 -0
  142. package/LICENSES/dependencies/indexmap-2.14.2/LICENSE-MIT +25 -0
  143. package/LICENSES/dependencies/itoa-1.0.18/LICENSE-APACHE +176 -0
  144. package/LICENSES/dependencies/itoa-1.0.18/LICENSE-MIT +23 -0
  145. package/LICENSES/dependencies/jiff-0.2.35/COPYING +3 -0
  146. package/LICENSES/dependencies/jiff-0.2.35/LICENSE-MIT +21 -0
  147. package/LICENSES/dependencies/jiff-0.2.35/UNLICENSE +24 -0
  148. package/LICENSES/dependencies/jiff-core-0.1.0/COPYING +3 -0
  149. package/LICENSES/dependencies/jiff-core-0.1.0/LICENSE-MIT +21 -0
  150. package/LICENSES/dependencies/jiff-core-0.1.0/UNLICENSE +24 -0
  151. package/LICENSES/dependencies/jiff-static-0.2.35/COPYING +3 -0
  152. package/LICENSES/dependencies/jiff-static-0.2.35/LICENSE-MIT +21 -0
  153. package/LICENSES/dependencies/jiff-static-0.2.35/UNLICENSE +24 -0
  154. package/LICENSES/dependencies/jiff-tzdb-0.1.8/COPYING +3 -0
  155. package/LICENSES/dependencies/jiff-tzdb-0.1.8/LICENSE-MIT +21 -0
  156. package/LICENSES/dependencies/jiff-tzdb-0.1.8/UNLICENSE +24 -0
  157. package/LICENSES/dependencies/jiff-tzdb-platform-0.1.3/COPYING +3 -0
  158. package/LICENSES/dependencies/jiff-tzdb-platform-0.1.3/LICENSE-MIT +21 -0
  159. package/LICENSES/dependencies/jiff-tzdb-platform-0.1.3/UNLICENSE +24 -0
  160. package/LICENSES/dependencies/js-sys-0.3.105/LICENSE-APACHE +201 -0
  161. package/LICENSES/dependencies/js-sys-0.3.105/LICENSE-MIT +25 -0
  162. package/LICENSES/dependencies/leb128-0.2.7/LICENSE-APACHE +201 -0
  163. package/LICENSES/dependencies/leb128-0.2.7/LICENSE-MIT +25 -0
  164. package/LICENSES/dependencies/leb128fmt-0.1.0/LICENSE-APACHE +201 -0
  165. package/LICENSES/dependencies/leb128fmt-0.1.0/LICENSE-MIT +23 -0
  166. package/LICENSES/dependencies/libc-0.2.189/LICENSE-APACHE +176 -0
  167. package/LICENSES/dependencies/libc-0.2.189/LICENSE-MIT +25 -0
  168. package/LICENSES/dependencies/linux-raw-sys-0.12.1/COPYRIGHT +29 -0
  169. package/LICENSES/dependencies/linux-raw-sys-0.12.1/LICENSE-APACHE +201 -0
  170. package/LICENSES/dependencies/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  171. package/LICENSES/dependencies/linux-raw-sys-0.12.1/LICENSE-MIT +23 -0
  172. package/LICENSES/dependencies/log-0.4.34/LICENSE-APACHE +201 -0
  173. package/LICENSES/dependencies/log-0.4.34/LICENSE-MIT +25 -0
  174. package/LICENSES/dependencies/memchr-2.8.3/COPYING +3 -0
  175. package/LICENSES/dependencies/memchr-2.8.3/LICENSE-MIT +21 -0
  176. package/LICENSES/dependencies/memchr-2.8.3/UNLICENSE +24 -0
  177. package/LICENSES/dependencies/mio-1.2.3/LICENSE +19 -0
  178. package/LICENSES/dependencies/num-conv-0.2.2/LICENSE-Apache +177 -0
  179. package/LICENSES/dependencies/num-conv-0.2.2/LICENSE-MIT +19 -0
  180. package/LICENSES/dependencies/num-traits-0.2.19/LICENSE-APACHE +201 -0
  181. package/LICENSES/dependencies/num-traits-0.2.19/LICENSE-MIT +25 -0
  182. package/LICENSES/dependencies/once_cell-1.21.4/LICENSE-APACHE +201 -0
  183. package/LICENSES/dependencies/once_cell-1.21.4/LICENSE-MIT +23 -0
  184. package/LICENSES/dependencies/parking-2.2.1/LICENSE-APACHE +201 -0
  185. package/LICENSES/dependencies/parking-2.2.1/LICENSE-MIT +23 -0
  186. package/LICENSES/dependencies/parking-2.2.1/LICENSE-THIRD-PARTY +9 -0
  187. package/LICENSES/dependencies/pin-project-1.1.13/LICENSE-APACHE +177 -0
  188. package/LICENSES/dependencies/pin-project-1.1.13/LICENSE-MIT +23 -0
  189. package/LICENSES/dependencies/pin-project-internal-1.1.13/LICENSE-APACHE +177 -0
  190. package/LICENSES/dependencies/pin-project-internal-1.1.13/LICENSE-MIT +23 -0
  191. package/LICENSES/dependencies/pin-project-lite-0.2.17/LICENSE-APACHE +177 -0
  192. package/LICENSES/dependencies/pin-project-lite-0.2.17/LICENSE-MIT +23 -0
  193. package/LICENSES/dependencies/piper-0.2.5/LICENSE-APACHE +201 -0
  194. package/LICENSES/dependencies/piper-0.2.5/LICENSE-MIT +23 -0
  195. package/LICENSES/dependencies/polling-3.11.0/LICENSE-APACHE +201 -0
  196. package/LICENSES/dependencies/polling-3.11.0/LICENSE-MIT +23 -0
  197. package/LICENSES/dependencies/portable-atomic-1.15.0/LICENSE-APACHE +177 -0
  198. package/LICENSES/dependencies/portable-atomic-1.15.0/LICENSE-MIT +23 -0
  199. package/LICENSES/dependencies/portable-atomic-util-0.2.8/LICENSE-APACHE +177 -0
  200. package/LICENSES/dependencies/portable-atomic-util-0.2.8/LICENSE-MIT +23 -0
  201. package/LICENSES/dependencies/powerfmt-0.2.0/LICENSE-Apache +202 -0
  202. package/LICENSES/dependencies/powerfmt-0.2.0/LICENSE-MIT +19 -0
  203. package/LICENSES/dependencies/proc-macro2-1.0.107/LICENSE-APACHE +176 -0
  204. package/LICENSES/dependencies/proc-macro2-1.0.107/LICENSE-MIT +23 -0
  205. package/LICENSES/dependencies/quote-1.0.47/LICENSE-APACHE +176 -0
  206. package/LICENSES/dependencies/quote-1.0.47/LICENSE-MIT +23 -0
  207. package/LICENSES/dependencies/r-efi-6.0.0/AUTHORS +75 -0
  208. package/LICENSES/dependencies/rayon-1.12.0/LICENSE-APACHE +201 -0
  209. package/LICENSES/dependencies/rayon-1.12.0/LICENSE-MIT +25 -0
  210. package/LICENSES/dependencies/rayon-core-1.13.0/LICENSE-APACHE +201 -0
  211. package/LICENSES/dependencies/rayon-core-1.13.0/LICENSE-MIT +25 -0
  212. package/LICENSES/dependencies/ref-cast-1.0.27/LICENSE-APACHE +176 -0
  213. package/LICENSES/dependencies/ref-cast-1.0.27/LICENSE-MIT +23 -0
  214. package/LICENSES/dependencies/ref-cast-impl-1.0.27/LICENSE-APACHE +176 -0
  215. package/LICENSES/dependencies/ref-cast-impl-1.0.27/LICENSE-MIT +23 -0
  216. package/LICENSES/dependencies/rustc-demangle-0.1.28/LICENSE-APACHE +201 -0
  217. package/LICENSES/dependencies/rustc-demangle-0.1.28/LICENSE-MIT +25 -0
  218. package/LICENSES/dependencies/rustc-hash-2.1.3/LICENSE-APACHE +176 -0
  219. package/LICENSES/dependencies/rustc-hash-2.1.3/LICENSE-MIT +23 -0
  220. package/LICENSES/dependencies/rustc_version-0.4.1/LICENSE-APACHE +201 -0
  221. package/LICENSES/dependencies/rustc_version-0.4.1/LICENSE-MIT +25 -0
  222. package/LICENSES/dependencies/rustix-1.1.4/COPYRIGHT +29 -0
  223. package/LICENSES/dependencies/rustix-1.1.4/LICENSE-APACHE +201 -0
  224. package/LICENSES/dependencies/rustix-1.1.4/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  225. package/LICENSES/dependencies/rustix-1.1.4/LICENSE-MIT +23 -0
  226. package/LICENSES/dependencies/rustversion-1.0.23/LICENSE-APACHE +176 -0
  227. package/LICENSES/dependencies/rustversion-1.0.23/LICENSE-MIT +23 -0
  228. package/LICENSES/dependencies/schemars-0.9.0/LICENSE +21 -0
  229. package/LICENSES/dependencies/schemars-1.2.2/LICENSE +21 -0
  230. package/LICENSES/dependencies/schemars_derive-1.2.2/LICENSE +21 -0
  231. package/LICENSES/dependencies/semver-1.0.28/LICENSE-APACHE +176 -0
  232. package/LICENSES/dependencies/semver-1.0.28/LICENSE-MIT +23 -0
  233. package/LICENSES/dependencies/serde-1.0.229/LICENSE-APACHE +176 -0
  234. package/LICENSES/dependencies/serde-1.0.229/LICENSE-MIT +23 -0
  235. package/LICENSES/dependencies/serde_core-1.0.229/LICENSE-APACHE +176 -0
  236. package/LICENSES/dependencies/serde_core-1.0.229/LICENSE-MIT +23 -0
  237. package/LICENSES/dependencies/serde_derive-1.0.229/LICENSE-APACHE +176 -0
  238. package/LICENSES/dependencies/serde_derive-1.0.229/LICENSE-MIT +23 -0
  239. package/LICENSES/dependencies/serde_derive_internals-0.30.0/LICENSE-APACHE +176 -0
  240. package/LICENSES/dependencies/serde_derive_internals-0.30.0/LICENSE-MIT +23 -0
  241. package/LICENSES/dependencies/serde_json-1.0.151/LICENSE-APACHE +176 -0
  242. package/LICENSES/dependencies/serde_json-1.0.151/LICENSE-MIT +23 -0
  243. package/LICENSES/dependencies/serde_with-3.23.0/LICENSE-APACHE +201 -0
  244. package/LICENSES/dependencies/serde_with-3.23.0/LICENSE-MIT +25 -0
  245. package/LICENSES/dependencies/serde_with_macros-3.23.0/LICENSE-APACHE +201 -0
  246. package/LICENSES/dependencies/serde_with_macros-3.23.0/LICENSE-MIT +25 -0
  247. package/LICENSES/dependencies/shell-words-1.1.1/LICENSE-APACHE +201 -0
  248. package/LICENSES/dependencies/shell-words-1.1.1/LICENSE-MIT +25 -0
  249. package/LICENSES/dependencies/shlex-2.0.1/LICENSE-APACHE +13 -0
  250. package/LICENSES/dependencies/shlex-2.0.1/LICENSE-MIT +21 -0
  251. package/LICENSES/dependencies/signal-hook-registry-1.4.8/LICENSE-APACHE +201 -0
  252. package/LICENSES/dependencies/signal-hook-registry-1.4.8/LICENSE-MIT +25 -0
  253. package/LICENSES/dependencies/slab-0.4.12/LICENSE +25 -0
  254. package/LICENSES/dependencies/smallvec-1.16.0/LICENSE-APACHE +201 -0
  255. package/LICENSES/dependencies/smallvec-1.16.0/LICENSE-MIT +25 -0
  256. package/LICENSES/dependencies/socket2-0.6.5/LICENSE-APACHE +201 -0
  257. package/LICENSES/dependencies/socket2-0.6.5/LICENSE-MIT +25 -0
  258. package/LICENSES/dependencies/stable_deref_trait-1.2.1/LICENSE-APACHE +201 -0
  259. package/LICENSES/dependencies/stable_deref_trait-1.2.1/LICENSE-MIT +25 -0
  260. package/LICENSES/dependencies/strsim-0.11.1/LICENSE +23 -0
  261. package/LICENSES/dependencies/strum-0.28.0/LICENSE +21 -0
  262. package/LICENSES/dependencies/strum_macros-0.28.0/LICENSE +21 -0
  263. package/LICENSES/dependencies/syn-2.0.119/LICENSE-APACHE +176 -0
  264. package/LICENSES/dependencies/syn-2.0.119/LICENSE-MIT +23 -0
  265. package/LICENSES/dependencies/syn-3.0.5/LICENSE-APACHE +176 -0
  266. package/LICENSES/dependencies/syn-3.0.5/LICENSE-MIT +23 -0
  267. package/LICENSES/dependencies/thiserror-2.0.20/LICENSE-APACHE +176 -0
  268. package/LICENSES/dependencies/thiserror-2.0.20/LICENSE-MIT +23 -0
  269. package/LICENSES/dependencies/thiserror-impl-2.0.20/LICENSE-APACHE +176 -0
  270. package/LICENSES/dependencies/thiserror-impl-2.0.20/LICENSE-MIT +23 -0
  271. package/LICENSES/dependencies/time-0.3.55/LICENSE-Apache +177 -0
  272. package/LICENSES/dependencies/time-0.3.55/LICENSE-MIT +19 -0
  273. package/LICENSES/dependencies/time-core-0.1.9/LICENSE-Apache +177 -0
  274. package/LICENSES/dependencies/time-core-0.1.9/LICENSE-MIT +19 -0
  275. package/LICENSES/dependencies/time-macros-0.2.32/LICENSE-Apache +177 -0
  276. package/LICENSES/dependencies/time-macros-0.2.32/LICENSE-MIT +19 -0
  277. package/LICENSES/dependencies/tinyvec-1.13.2/LICENSE-APACHE.md +202 -0
  278. package/LICENSES/dependencies/tinyvec-1.13.2/LICENSE-MIT.md +5 -0
  279. package/LICENSES/dependencies/tinyvec-1.13.2/LICENSE-ZLIB.md +11 -0
  280. package/LICENSES/dependencies/tinyvec_macros-0.1.1/LICENSE-APACHE.md +202 -0
  281. package/LICENSES/dependencies/tinyvec_macros-0.1.1/LICENSE-MIT.md +21 -0
  282. package/LICENSES/dependencies/tinyvec_macros-0.1.1/LICENSE-ZLIB.md +20 -0
  283. package/LICENSES/dependencies/tokio-1.53.1/LICENSE +21 -0
  284. package/LICENSES/dependencies/tokio-macros-2.7.2/LICENSE +22 -0
  285. package/LICENSES/dependencies/tracing-0.1.44/LICENSE +25 -0
  286. package/LICENSES/dependencies/tracing-attributes-0.1.31/LICENSE +25 -0
  287. package/LICENSES/dependencies/tracing-core-0.1.36/LICENSE +25 -0
  288. package/LICENSES/dependencies/unicode-ident-1.0.24/LICENSE-APACHE +176 -0
  289. package/LICENSES/dependencies/unicode-ident-1.0.24/LICENSE-MIT +23 -0
  290. package/LICENSES/dependencies/unicode-ident-1.0.24/LICENSE-UNICODE +39 -0
  291. package/LICENSES/dependencies/unicode-segmentation-1.13.3/COPYRIGHT +7 -0
  292. package/LICENSES/dependencies/unicode-segmentation-1.13.3/LICENSE-APACHE +201 -0
  293. package/LICENSES/dependencies/unicode-segmentation-1.13.3/LICENSE-MIT +25 -0
  294. package/LICENSES/dependencies/unicode-xid-0.2.6/COPYRIGHT +7 -0
  295. package/LICENSES/dependencies/unicode-xid-0.2.6/LICENSE-APACHE +201 -0
  296. package/LICENSES/dependencies/unicode-xid-0.2.6/LICENSE-MIT +25 -0
  297. package/LICENSES/dependencies/uuid-1.26.1/LICENSE-APACHE +201 -0
  298. package/LICENSES/dependencies/uuid-1.26.1/LICENSE-MIT +26 -0
  299. package/LICENSES/dependencies/walrus-0.26.5/LICENSE-APACHE +201 -0
  300. package/LICENSES/dependencies/walrus-0.26.5/LICENSE-MIT +25 -0
  301. package/LICENSES/dependencies/walrus-macro-0.26.0/LICENSE-APACHE +201 -0
  302. package/LICENSES/dependencies/walrus-macro-0.26.0/LICENSE-MIT +25 -0
  303. package/LICENSES/dependencies/wasi-0.11.1+wasi-snapshot-preview1/LICENSE-APACHE +201 -0
  304. package/LICENSES/dependencies/wasi-0.11.1+wasi-snapshot-preview1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  305. package/LICENSES/dependencies/wasi-0.11.1+wasi-snapshot-preview1/LICENSE-MIT +23 -0
  306. package/LICENSES/dependencies/wasm-bindgen-0.2.128/LICENSE-APACHE +201 -0
  307. package/LICENSES/dependencies/wasm-bindgen-0.2.128/LICENSE-MIT +25 -0
  308. package/LICENSES/dependencies/wasm-bindgen-cli-support-0.2.128/LICENSE-APACHE +201 -0
  309. package/LICENSES/dependencies/wasm-bindgen-cli-support-0.2.128/LICENSE-MIT +25 -0
  310. package/LICENSES/dependencies/wasm-bindgen-macro-0.2.128/LICENSE-APACHE +201 -0
  311. package/LICENSES/dependencies/wasm-bindgen-macro-0.2.128/LICENSE-MIT +25 -0
  312. package/LICENSES/dependencies/wasm-bindgen-macro-support-0.2.128/LICENSE-APACHE +201 -0
  313. package/LICENSES/dependencies/wasm-bindgen-macro-support-0.2.128/LICENSE-MIT +25 -0
  314. package/LICENSES/dependencies/wasm-bindgen-shared-0.2.128/LICENSE-APACHE +201 -0
  315. package/LICENSES/dependencies/wasm-bindgen-shared-0.2.128/LICENSE-MIT +25 -0
  316. package/LICENSES/dependencies/wasm-encoder-0.245.1/LICENSE-APACHE +201 -0
  317. package/LICENSES/dependencies/wasm-encoder-0.245.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  318. package/LICENSES/dependencies/wasm-encoder-0.245.1/LICENSE-MIT +23 -0
  319. package/LICENSES/dependencies/wasmparser-0.245.1/LICENSE-APACHE +201 -0
  320. package/LICENSES/dependencies/wasmparser-0.245.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  321. package/LICENSES/dependencies/wasmparser-0.245.1/LICENSE-MIT +23 -0
  322. package/LICENSES/dependencies/windows-core-0.62.2/license-apache-2.0 +201 -0
  323. package/LICENSES/dependencies/windows-core-0.62.2/license-mit +21 -0
  324. package/LICENSES/dependencies/windows-implement-0.60.2/license-apache-2.0 +201 -0
  325. package/LICENSES/dependencies/windows-implement-0.60.2/license-mit +21 -0
  326. package/LICENSES/dependencies/windows-interface-0.59.3/license-apache-2.0 +201 -0
  327. package/LICENSES/dependencies/windows-interface-0.59.3/license-mit +21 -0
  328. package/LICENSES/dependencies/windows-link-0.2.1/license-apache-2.0 +201 -0
  329. package/LICENSES/dependencies/windows-link-0.2.1/license-mit +21 -0
  330. package/LICENSES/dependencies/windows-result-0.4.1/license-apache-2.0 +201 -0
  331. package/LICENSES/dependencies/windows-result-0.4.1/license-mit +21 -0
  332. package/LICENSES/dependencies/windows-strings-0.5.1/license-apache-2.0 +201 -0
  333. package/LICENSES/dependencies/windows-strings-0.5.1/license-mit +21 -0
  334. package/LICENSES/dependencies/windows-sys-0.61.2/license-apache-2.0 +201 -0
  335. package/LICENSES/dependencies/windows-sys-0.61.2/license-mit +21 -0
  336. package/LICENSES/dependencies/zmij-1.0.23/LICENSE-MIT +23 -0
  337. package/README.md +185 -0
  338. package/THIRD-PARTY.md +45 -0
  339. package/index.d.ts +47 -0
  340. package/index.js +28 -0
  341. package/package.json +36 -0
  342. package/source/.cargo/config.toml +5 -0
  343. package/source/.ci/upstream-notices/PROVENANCE.json +198 -0
  344. package/source/.ci/upstream-notices/agent-client-protocol-2.1.0/LICENSE +191 -0
  345. package/source/.ci/upstream-notices/agent-client-protocol-derive-2.1.0/LICENSE +191 -0
  346. package/source/.ci/upstream-notices/agent-client-protocol-schema-1.7.0/LICENSE +190 -0
  347. package/source/.ci/upstream-notices/defmt-parser-1.0.0/LICENSE-APACHE +201 -0
  348. package/source/.ci/upstream-notices/defmt-parser-1.0.0/LICENSE-MIT +25 -0
  349. package/source/.ci/upstream-notices/r-efi-6.0.0/AUTHORS +75 -0
  350. package/source/.ci/upstream-notices/wasm-encoder-0.245.1/LICENSE-APACHE +201 -0
  351. package/source/.ci/upstream-notices/wasm-encoder-0.245.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  352. package/source/.ci/upstream-notices/wasm-encoder-0.245.1/LICENSE-MIT +23 -0
  353. package/source/.ci/upstream-notices/wasmparser-0.245.1/LICENSE-APACHE +201 -0
  354. package/source/.ci/upstream-notices/wasmparser-0.245.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  355. package/source/.ci/upstream-notices/wasmparser-0.245.1/LICENSE-MIT +23 -0
  356. package/source/.ci/wasm-bundle/Cargo.toml +10 -0
  357. package/source/.ci/wasm-bundle/src/main.rs +17 -0
  358. package/source/CHANGELOG.md +11 -0
  359. package/source/Cargo.lock +1622 -0
  360. package/source/Cargo.toml +48 -0
  361. package/source/LICENSE +307 -0
  362. package/source/LICENSE.md +25 -0
  363. package/source/LICENSES/GPL-3.0-only.txt +232 -0
  364. package/source/LICENSES/LGPL-3.0-only.txt +304 -0
  365. package/source/README.md +185 -0
  366. package/source/THIRD-PARTY.md +45 -0
  367. package/source/dependencies.tar.gz +0 -0
  368. package/source/examples/native.rs +45 -0
  369. package/source/src/conversation.rs +557 -0
  370. package/source/src/lib.rs +27 -0
  371. package/source/src/native/client.rs +417 -0
  372. package/source/src/native/fixture.py +104 -0
  373. package/source/src/native/mod.rs +249 -0
  374. package/source/src/native/session.rs +541 -0
  375. package/source/src/native/tests.rs +427 -0
  376. package/source/src/web.rs +35 -0
  377. package/wasm/ccht.d.ts +60 -0
  378. package/wasm/ccht.js +275 -0
  379. package/wasm/ccht_bg.wasm +0 -0
  380. package/wasm/ccht_bg.wasm.d.ts +13 -0
@@ -0,0 +1,541 @@
1
+ use std::collections::BTreeMap;
2
+ use std::sync::atomic::{AtomicU64, Ordering};
3
+ use std::sync::{Arc, Mutex};
4
+
5
+ use agent_client_protocol::util::MatchDispatch;
6
+ use agent_client_protocol::{ActiveSession, Agent, Dispatch, Responder, SessionMessage};
7
+ use tokio::sync::{mpsc, oneshot, watch};
8
+ use tokio::task::JoinHandle;
9
+ use tokio::time::{Instant, interval, timeout};
10
+
11
+ use crate::acp::{
12
+ CancelNotification, CloseSessionRequest, ContentBlock, PromptRequest, PromptResponse,
13
+ RequestPermissionOutcome, RequestPermissionRequest, RequestPermissionResponse, SessionId,
14
+ SessionNotification, StopReason,
15
+ };
16
+ use crate::{Event, Prompt, SessionEvent};
17
+
18
+ use super::client::{ClientLease, ClientState};
19
+ use super::{NativeError, PermissionDecision, PermissionPolicy, Result, lock};
20
+
21
+ static NEXT_PERMISSION: AtomicU64 = AtomicU64::new(1);
22
+
23
+ /// A native session and its single ordered event stream.
24
+ ///
25
+ /// Take the receiver once, then retain a handle while consuming it. A cloned
26
+ /// handle keeps the session alive independently of this value.
27
+ pub struct NativeSession {
28
+ handle: SessionHandle,
29
+ events: Option<mpsc::Receiver<SessionEvent>>,
30
+ }
31
+
32
+ /// Cloneable, thread-safe control of a native conversation.
33
+ #[derive(Clone)]
34
+ pub struct SessionHandle {
35
+ lease: Arc<SessionLease>,
36
+ }
37
+
38
+ struct SessionLease {
39
+ state: Arc<SessionState>,
40
+ commands: mpsc::Sender<PromptCommand>,
41
+ client: Arc<ClientLease>,
42
+ }
43
+
44
+ struct SessionState {
45
+ id: SessionId,
46
+ client: Arc<ClientState>,
47
+ connection: agent_client_protocol::ConnectionTo<Agent>,
48
+ turn: Mutex<TurnState>,
49
+ activity: watch::Sender<bool>,
50
+ closed: watch::Sender<bool>,
51
+ failure: Mutex<Option<NativeError>>,
52
+ events: Mutex<Option<mpsc::Sender<SessionEvent>>>,
53
+ permissions: Mutex<BTreeMap<String, PendingPermission>>,
54
+ task: Mutex<Option<JoinHandle<()>>>,
55
+ }
56
+
57
+ #[derive(Default)]
58
+ struct TurnState {
59
+ reserved: Option<String>,
60
+ current: Option<String>,
61
+ cancelled: bool,
62
+ }
63
+
64
+ struct PendingPermission {
65
+ request: RequestPermissionRequest,
66
+ responder: Responder<RequestPermissionResponse>,
67
+ expires: Instant,
68
+ }
69
+
70
+ struct PromptCommand {
71
+ prompt: Prompt,
72
+ result: oneshot::Sender<Result<StopReason>>,
73
+ }
74
+
75
+ struct PromptGuard(Option<(Arc<SessionState>, String)>);
76
+
77
+ impl Drop for PromptGuard {
78
+ fn drop(&mut self) {
79
+ let Some((state, request_id)) = &self.0 else {
80
+ return;
81
+ };
82
+ // Release the turn lock before cleanup takes it again.
83
+ let active = lock(&state.turn).reserved.as_ref() == Some(request_id);
84
+ if active {
85
+ // Abandoning a prompt cannot leave unattended agent work running.
86
+ state.close(NativeError::Closed, true);
87
+ }
88
+ }
89
+ }
90
+
91
+ impl Drop for SessionLease {
92
+ fn drop(&mut self) {
93
+ let active = lock(&self.state.turn).reserved.is_some();
94
+ self.state.close(NativeError::Closed, active);
95
+ }
96
+ }
97
+
98
+ impl SessionState {
99
+ fn is_closed(&self) -> bool {
100
+ *self.closed.borrow() || self.client.is_closed()
101
+ }
102
+
103
+ fn error(&self) -> NativeError {
104
+ lock(&self.failure)
105
+ .clone()
106
+ .unwrap_or_else(|| self.client.error())
107
+ }
108
+
109
+ fn emit(&self, event: Event) -> Result<()> {
110
+ let request_id = lock(&self.turn).current.clone();
111
+ let result = lock(&self.events)
112
+ .as_ref()
113
+ .ok_or(NativeError::Closed)?
114
+ .try_send(SessionEvent { request_id, event });
115
+ match result {
116
+ Ok(()) => Ok(()),
117
+ Err(mpsc::error::TrySendError::Full(_)) => {
118
+ self.close(NativeError::EventBufferFull, true);
119
+ Err(NativeError::EventBufferFull)
120
+ }
121
+ Err(mpsc::error::TrySendError::Closed(_)) => {
122
+ self.close(NativeError::Closed, true);
123
+ Err(NativeError::Closed)
124
+ }
125
+ }
126
+ }
127
+
128
+ fn deny_permissions(&self) {
129
+ for (_, pending) in std::mem::take(&mut *lock(&self.permissions)) {
130
+ let _ = pending.responder.respond(RequestPermissionResponse::new(
131
+ RequestPermissionOutcome::Cancelled,
132
+ ));
133
+ }
134
+ }
135
+
136
+ fn close(&self, error: NativeError, stop_connection: bool) {
137
+ if !*self.closed.borrow() {
138
+ *lock(&self.failure) = Some(error.clone());
139
+ let _ = self
140
+ .connection
141
+ .send_notification(CancelNotification::new(self.id.clone()));
142
+ self.deny_permissions();
143
+ let request_id = lock(&self.turn).current.clone();
144
+ if let Some(events) = lock(&self.events).take()
145
+ && (request_id.is_some() || error != NativeError::Closed)
146
+ {
147
+ let _ = events.try_send(SessionEvent {
148
+ request_id,
149
+ event: Event::Error {
150
+ code: error.code().into(),
151
+ message: error.to_string(),
152
+ },
153
+ });
154
+ }
155
+ self.closed.send_replace(true);
156
+ self.activity.send_replace(false);
157
+ if let Some(task) = lock(&self.task).as_ref() {
158
+ task.abort();
159
+ }
160
+ }
161
+ if stop_connection {
162
+ self.client.abort();
163
+ }
164
+ }
165
+
166
+ fn finish(&self, outcome: &Result<StopReason>) -> Result<()> {
167
+ self.deny_permissions();
168
+ let event = match outcome {
169
+ Ok(stop_reason) => Event::Completed {
170
+ stop_reason: *stop_reason,
171
+ },
172
+ Err(error) => Event::Error {
173
+ code: error.code().into(),
174
+ message: error.to_string(),
175
+ },
176
+ };
177
+ self.emit(event)?;
178
+ *lock(&self.turn) = TurnState::default();
179
+ self.activity.send_replace(false);
180
+ Ok(())
181
+ }
182
+ }
183
+
184
+ impl NativeSession {
185
+ pub(super) fn start(
186
+ client: Arc<ClientLease>,
187
+ session: ActiveSession<'static, Agent>,
188
+ ) -> Result<Self> {
189
+ let (events_tx, events_rx) = mpsc::channel(client.options.event_capacity);
190
+ let (commands_tx, commands_rx) = mpsc::channel(1);
191
+ let (activity, _) = watch::channel(false);
192
+ let (closed, _) = watch::channel(false);
193
+ let state = Arc::new(SessionState {
194
+ id: session.session_id().clone(),
195
+ client: client.state.clone(),
196
+ connection: session.connection().clone(),
197
+ turn: Mutex::new(TurnState::default()),
198
+ activity,
199
+ closed,
200
+ failure: Mutex::new(None),
201
+ events: Mutex::new(Some(events_tx)),
202
+ permissions: Mutex::new(BTreeMap::new()),
203
+ task: Mutex::new(None),
204
+ });
205
+ let worker_state = state.clone();
206
+ let options = client.options.clone();
207
+ let task = tokio::spawn(async move {
208
+ if let Err(error) =
209
+ run_session(session, commands_rx, worker_state.clone(), options).await
210
+ {
211
+ worker_state.close(error, true);
212
+ }
213
+ });
214
+ *lock(&state.task) = Some(task);
215
+ Ok(Self {
216
+ handle: SessionHandle {
217
+ lease: Arc::new(SessionLease {
218
+ state,
219
+ commands: commands_tx,
220
+ client,
221
+ }),
222
+ },
223
+ events: Some(events_rx),
224
+ })
225
+ }
226
+
227
+ /// Clone the control handle; it can be used while the receiver is polled elsewhere.
228
+ pub fn handle(&self) -> SessionHandle {
229
+ self.handle.clone()
230
+ }
231
+
232
+ /// Take the sole stream, including any history queued during session restoration.
233
+ pub fn take_events(&mut self) -> Result<mpsc::Receiver<SessionEvent>> {
234
+ self.events.take().ok_or(NativeError::EventsTaken)
235
+ }
236
+ }
237
+
238
+ impl SessionHandle {
239
+ /// The agent-owned session identifier, suitable for explicit load or resume.
240
+ pub fn id(&self) -> &str {
241
+ self.lease.state.id.0.as_ref()
242
+ }
243
+
244
+ /// Send one prompt and await its terminal result while events stream independently.
245
+ ///
246
+ /// A concurrent prompt fails with `Busy`. Dropping this future after submission
247
+ /// closes the connection, ensuring the abandoned turn cannot keep running.
248
+ pub async fn prompt(&self, prompt: Prompt) -> Result<StopReason> {
249
+ let state = &self.lease.state;
250
+ if state.is_closed() {
251
+ return Err(state.error());
252
+ }
253
+ if prompt.request_id.is_empty() || prompt.content.is_empty() {
254
+ return Err(NativeError::InvalidOptions(
255
+ "a prompt needs a request id and content",
256
+ ));
257
+ }
258
+ let capabilities = &self
259
+ .lease
260
+ .client
261
+ .info
262
+ .agent_capabilities
263
+ .prompt_capabilities;
264
+ for content in &prompt.content {
265
+ match content {
266
+ ContentBlock::Text(_) | ContentBlock::ResourceLink(_) => {}
267
+ ContentBlock::Image(_) if capabilities.image => {}
268
+ ContentBlock::Audio(_) if capabilities.audio => {}
269
+ ContentBlock::Resource(_) if capabilities.embedded_context => {}
270
+ _ => return Err(NativeError::Unsupported("the requested prompt content")),
271
+ }
272
+ }
273
+ {
274
+ let mut turn = lock(&state.turn);
275
+ if turn.reserved.is_some() {
276
+ return Err(NativeError::Busy);
277
+ }
278
+ turn.reserved = Some(prompt.request_id.clone());
279
+ turn.cancelled = false;
280
+ state.activity.send_replace(true);
281
+ }
282
+ let mut guard = PromptGuard(Some((state.clone(), prompt.request_id.clone())));
283
+ let (result_tx, result_rx) = oneshot::channel();
284
+ self.lease
285
+ .commands
286
+ .send(PromptCommand {
287
+ prompt,
288
+ result: result_tx,
289
+ })
290
+ .await
291
+ .map_err(|_| state.error())?;
292
+ let mut closed = state.closed.subscribe();
293
+ let mut connection_closed = state.client.closed.subscribe();
294
+ let result = timeout(self.lease.client.options.prompt_timeout, async {
295
+ if state.is_closed() {
296
+ return Err(state.error());
297
+ }
298
+ tokio::select! {
299
+ result = result_rx => result.unwrap_or_else(|_| Err(state.error())),
300
+ _ = closed.changed() => Err(state.error()),
301
+ _ = connection_closed.changed() => Err(state.error()),
302
+ }
303
+ })
304
+ .await;
305
+ match result {
306
+ Ok(outcome) => {
307
+ guard.0 = None;
308
+ outcome
309
+ }
310
+ Err(_) => {
311
+ state.close(NativeError::Timeout, true);
312
+ guard.0 = None;
313
+ Err(NativeError::Timeout)
314
+ }
315
+ }
316
+ }
317
+
318
+ /// Request cancellation and wait a bounded time for the active turn to finish.
319
+ ///
320
+ /// If the agent ignores cancellation, the SDK connection is closed. This also
321
+ /// closes other sessions sharing that agent process.
322
+ pub async fn cancel(&self) -> Result<()> {
323
+ let state = &self.lease.state;
324
+ if state.is_closed() {
325
+ return Err(state.error());
326
+ }
327
+ {
328
+ let mut turn = lock(&state.turn);
329
+ if turn.reserved.is_none() {
330
+ return Ok(());
331
+ }
332
+ turn.cancelled = true;
333
+ }
334
+ state.deny_permissions();
335
+ state
336
+ .connection
337
+ .send_notification(CancelNotification::new(state.id.clone()))?;
338
+ let mut activity = state.activity.subscribe();
339
+ if timeout(self.lease.client.options.shutdown_timeout, async {
340
+ while *activity.borrow_and_update() {
341
+ if activity.changed().await.is_err() {
342
+ break;
343
+ }
344
+ }
345
+ })
346
+ .await
347
+ .is_err()
348
+ {
349
+ state.close(NativeError::Timeout, true);
350
+ return Err(NativeError::Timeout);
351
+ }
352
+ if state.is_closed() {
353
+ Err(state.error())
354
+ } else {
355
+ Ok(())
356
+ }
357
+ }
358
+
359
+ /// Answer one pending permission request using an option the agent offered.
360
+ ///
361
+ /// Invalid selections leave the request pending so the application can correct
362
+ /// its response. Expired or previously answered requests fail explicitly.
363
+ pub async fn respond_permission(
364
+ &self,
365
+ request_id: &str,
366
+ decision: PermissionDecision,
367
+ ) -> Result<()> {
368
+ let state = &self.lease.state;
369
+ if state.is_closed() {
370
+ return Err(state.error());
371
+ }
372
+ let pending = {
373
+ let mut permissions = lock(&state.permissions);
374
+ let pending = permissions
375
+ .get(request_id)
376
+ .ok_or(NativeError::UnknownPermission)?;
377
+ if pending.expires <= Instant::now() || pending.responder.cancellation().is_cancelled()
378
+ {
379
+ return Err(NativeError::UnknownPermission);
380
+ }
381
+ match &decision {
382
+ RequestPermissionOutcome::Cancelled => {}
383
+ RequestPermissionOutcome::Selected(selected)
384
+ if pending
385
+ .request
386
+ .options
387
+ .iter()
388
+ .any(|option| option.option_id == selected.option_id) => {}
389
+ _ => return Err(NativeError::InvalidPermissionOption),
390
+ }
391
+ permissions
392
+ .remove(request_id)
393
+ .ok_or(NativeError::UnknownPermission)?
394
+ };
395
+ pending
396
+ .responder
397
+ .respond(RequestPermissionResponse::new(decision))?;
398
+ Ok(())
399
+ }
400
+
401
+ /// Cancel work, detach local routing, and close the remote session when supported.
402
+ ///
403
+ /// Without `session/close`, persisted agent history remains available for an
404
+ /// explicit future load; this method never claims to delete remote history.
405
+ pub async fn close(&self) -> Result<()> {
406
+ let state = &self.lease.state;
407
+ if state.is_closed() {
408
+ return Ok(());
409
+ }
410
+ self.cancel().await?;
411
+ if self
412
+ .lease
413
+ .client
414
+ .info
415
+ .agent_capabilities
416
+ .session_capabilities
417
+ .close
418
+ .is_some()
419
+ {
420
+ let response = timeout(
421
+ self.lease.client.options.shutdown_timeout,
422
+ state
423
+ .connection
424
+ .send_request(CloseSessionRequest::new(state.id.clone()))
425
+ .block_task(),
426
+ )
427
+ .await;
428
+ match response {
429
+ Ok(Ok(_)) => {}
430
+ Ok(Err(error)) => {
431
+ state.close(error.clone().into(), false);
432
+ return Err(error.into());
433
+ }
434
+ Err(_) => {
435
+ state.close(NativeError::Timeout, true);
436
+ return Err(NativeError::Timeout);
437
+ }
438
+ }
439
+ }
440
+ state.close(NativeError::Closed, false);
441
+ Ok(())
442
+ }
443
+ }
444
+
445
+ async fn run_session(
446
+ mut session: ActiveSession<'static, Agent>,
447
+ mut commands: mpsc::Receiver<PromptCommand>,
448
+ state: Arc<SessionState>,
449
+ options: super::NativeOptions,
450
+ ) -> Result<()> {
451
+ let (completion_tx, mut completion_rx) = mpsc::unbounded_channel::<Result<StopReason>>();
452
+ let mut active: Option<oneshot::Sender<Result<StopReason>>> = None;
453
+ let mut closed = state.closed.subscribe();
454
+ let mut connection_closed = state.client.closed.subscribe();
455
+ let mut expiry = interval(
456
+ options
457
+ .permission_timeout
458
+ .min(std::time::Duration::from_secs(1)),
459
+ );
460
+ loop {
461
+ if state.is_closed() {
462
+ return Err(state.error());
463
+ }
464
+ tokio::select! {
465
+ biased;
466
+ _ = closed.changed() => return Ok(()),
467
+ _ = connection_closed.changed() => return Err(state.client.error()),
468
+ message = session.read_update() => {
469
+ match message? {
470
+ SessionMessage::SessionMessage(dispatch) => {
471
+ MatchDispatch::new(dispatch)
472
+ .if_notification(async |notification: SessionNotification| {
473
+ state.emit(Event::Update { update: notification.update })
474
+ .map_err(|_| agent_client_protocol::Error::internal_error())
475
+ }).await
476
+ .if_request(async |request: RequestPermissionRequest, responder| {
477
+ if options.permissions == PermissionPolicy::Deny
478
+ || lock(&state.turn).cancelled
479
+ || lock(&state.permissions).len() >= options.event_capacity
480
+ {
481
+ return responder.respond(RequestPermissionResponse::new(RequestPermissionOutcome::Cancelled));
482
+ }
483
+ let request_id = format!("permission-{}", NEXT_PERMISSION.fetch_add(1, Ordering::Relaxed));
484
+ lock(&state.permissions).insert(request_id.clone(), PendingPermission {
485
+ request: request.clone(), responder,
486
+ expires: Instant::now() + options.permission_timeout,
487
+ });
488
+ state.emit(Event::Permission { request_id, request })
489
+ .map_err(|_| agent_client_protocol::Error::internal_error())
490
+ }).await
491
+ .otherwise(async |dispatch| {
492
+ match dispatch {
493
+ Dispatch::Request(_, responder) => responder.respond_with_result(Err(agent_client_protocol::Error::method_not_found())),
494
+ _ => Ok(()),
495
+ }
496
+ }).await?;
497
+ }
498
+ SessionMessage::StopReason(stop_reason) => {
499
+ let _ = completion_tx.send(Ok(stop_reason));
500
+ }
501
+ _ => return Err(NativeError::Unsupported("the received SDK session event")),
502
+ }
503
+ }
504
+ Some(outcome) = completion_rx.recv(), if active.is_some() => {
505
+ state.finish(&outcome)?;
506
+ if let Some(result) = active.take() { let _ = result.send(outcome); }
507
+ }
508
+ Some(command) = commands.recv(), if active.is_none() => {
509
+ {
510
+ let mut turn = lock(&state.turn);
511
+ turn.current = Some(command.prompt.request_id.clone());
512
+ }
513
+ if lock(&state.turn).cancelled || command.result.is_closed() {
514
+ let outcome = Ok(StopReason::Cancelled);
515
+ state.finish(&outcome)?;
516
+ let _ = command.result.send(outcome);
517
+ continue;
518
+ }
519
+ active = Some(command.result);
520
+ let tx = completion_tx.clone();
521
+ session.connection().send_request(PromptRequest::new(state.id.clone(), command.prompt.content))
522
+ .on_receiving_result(async move |result: std::result::Result<PromptResponse, agent_client_protocol::Error>| {
523
+ // Earlier notifications are already on ActiveSession's queue.
524
+ // The biased reader drains them before publishing completion.
525
+ let _ = tx.send(result.map(|response| response.stop_reason).map_err(NativeError::from));
526
+ Ok(())
527
+ })?;
528
+ }
529
+ _ = expiry.tick() => {
530
+ let expired: Vec<_> = lock(&state.permissions).iter()
531
+ .filter(|(_, pending)| pending.expires <= Instant::now() || pending.responder.cancellation().is_cancelled())
532
+ .map(|(id, _)| id.clone()).collect();
533
+ for id in expired {
534
+ if let Some(pending) = lock(&state.permissions).remove(&id) {
535
+ let _ = pending.responder.respond(RequestPermissionResponse::new(RequestPermissionOutcome::Cancelled));
536
+ }
537
+ }
538
+ }
539
+ }
540
+ }
541
+ }