@nathapp/nax-agent 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 (398) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +21 -0
  3. package/README.md +49 -0
  4. package/dist/coding-tools/coding-tool-bash.d.ts +46 -0
  5. package/dist/coding-tools/coding-tool-bash.js +44 -0
  6. package/dist/coding-tools/coding-tool-extras.d.ts +35 -0
  7. package/dist/coding-tools/coding-tool-extras.js +56 -0
  8. package/dist/coding-tools/coding-tool-sandbox.d.ts +74 -0
  9. package/dist/coding-tools/coding-tool-sandbox.js +215 -0
  10. package/dist/coding-tools/coding-tool-support.d.ts +132 -0
  11. package/dist/coding-tools/coding-tool-support.js +159 -0
  12. package/dist/coding-tools/universal-coding-tools.d.ts +11 -0
  13. package/dist/coding-tools/universal-coding-tools.js +5 -0
  14. package/dist/command-interceptor/index.d.ts +55 -0
  15. package/dist/command-interceptor/index.js +60 -0
  16. package/dist/command-interceptor/shell.d.ts +36 -0
  17. package/dist/command-interceptor/shell.js +137 -0
  18. package/dist/command-safety/build.d.ts +19 -0
  19. package/dist/command-safety/build.js +47 -0
  20. package/dist/command-safety/guard.d.ts +32 -0
  21. package/dist/command-safety/guard.js +179 -0
  22. package/dist/command-safety/identifiers.d.ts +24 -0
  23. package/dist/command-safety/identifiers.js +20 -0
  24. package/dist/command-safety/index.d.ts +17 -0
  25. package/dist/command-safety/index.js +11 -0
  26. package/dist/command-safety/questions.d.ts +19 -0
  27. package/dist/command-safety/questions.js +60 -0
  28. package/dist/command-safety/row.d.ts +2 -0
  29. package/dist/command-safety/row.js +14 -0
  30. package/dist/command-safety/rule-scorer.d.ts +9 -0
  31. package/dist/command-safety/rule-scorer.js +391 -0
  32. package/dist/command-safety/shadow.d.ts +33 -0
  33. package/dist/command-safety/shadow.js +188 -0
  34. package/dist/command-safety/systemone-client.d.ts +16 -0
  35. package/dist/command-safety/systemone-client.js +92 -0
  36. package/dist/command-safety/tap.d.ts +37 -0
  37. package/dist/command-safety/tap.js +77 -0
  38. package/dist/command-safety/temp-only.d.ts +6 -0
  39. package/dist/command-safety/temp-only.js +215 -0
  40. package/dist/command-safety/tmp-write.d.ts +2 -0
  41. package/dist/command-safety/tmp-write.js +112 -0
  42. package/dist/command-safety/types.d.ts +185 -0
  43. package/dist/command-safety/types.js +21 -0
  44. package/dist/config/bash-approval.d.ts +33 -0
  45. package/dist/config/bash-approval.js +30 -0
  46. package/dist/config/catalog-overrides.d.ts +94 -0
  47. package/dist/config/catalog-overrides.js +7 -0
  48. package/dist/config/native-agent/index.d.ts +8 -0
  49. package/dist/config/native-agent/index.js +8 -0
  50. package/dist/config/schemas-sandbox.d.ts +31 -0
  51. package/dist/config/schemas-sandbox.js +45 -0
  52. package/dist/cost/core/index.d.ts +8 -0
  53. package/dist/cost/core/index.js +7 -0
  54. package/dist/cost/estimate.d.ts +34 -0
  55. package/dist/cost/estimate.js +65 -0
  56. package/dist/cost/model-spec.d.ts +28 -0
  57. package/dist/cost/model-spec.js +29 -0
  58. package/dist/cost/standard-types.d.ts +9 -0
  59. package/dist/cost/standard-types.js +1 -0
  60. package/dist/cost/usage-math.d.ts +18 -0
  61. package/dist/cost/usage-math.js +46 -0
  62. package/dist/index.d.ts +26 -0
  63. package/dist/index.js +21 -0
  64. package/dist/infra/agent-logger.d.ts +22 -0
  65. package/dist/infra/agent-logger.js +19 -0
  66. package/dist/infra/credentials-config.d.ts +20 -0
  67. package/dist/infra/credentials-config.js +15 -0
  68. package/dist/infra/errors.d.ts +9 -0
  69. package/dist/infra/errors.js +11 -0
  70. package/dist/infra/index.d.ts +7 -0
  71. package/dist/infra/index.js +7 -0
  72. package/dist/infra/nax-error.d.ts +10 -0
  73. package/dist/infra/nax-error.js +16 -0
  74. package/dist/infra/spin-breaker/hash.d.ts +2 -0
  75. package/dist/infra/spin-breaker/hash.js +5 -0
  76. package/dist/infra/spin-breaker/index.d.ts +120 -0
  77. package/dist/infra/spin-breaker/index.js +340 -0
  78. package/dist/internal/agent-output-env.d.ts +44 -0
  79. package/dist/internal/agent-output-env.js +57 -0
  80. package/dist/internal/argv-exec.d.ts +58 -0
  81. package/dist/internal/argv-exec.js +224 -0
  82. package/dist/internal/bounded-io.d.ts +24 -0
  83. package/dist/internal/bounded-io.js +51 -0
  84. package/dist/internal/command-spec/index.d.ts +29 -0
  85. package/dist/internal/command-spec/index.js +36 -0
  86. package/dist/internal/describe-value-type.d.ts +8 -0
  87. package/dist/internal/describe-value-type.js +14 -0
  88. package/dist/internal/exec-framing.d.ts +18 -0
  89. package/dist/internal/exec-framing.js +22 -0
  90. package/dist/internal/file-lock.d.ts +91 -0
  91. package/dist/internal/file-lock.js +212 -0
  92. package/dist/internal/file-size.d.ts +2 -0
  93. package/dist/internal/file-size.js +12 -0
  94. package/dist/internal/git-add.d.ts +43 -0
  95. package/dist/internal/git-add.js +59 -0
  96. package/dist/internal/git-env.d.ts +59 -0
  97. package/dist/internal/git-env.js +93 -0
  98. package/dist/internal/git-exec.d.ts +58 -0
  99. package/dist/internal/git-exec.js +115 -0
  100. package/dist/internal/path-file-lock.d.ts +23 -0
  101. package/dist/internal/path-file-lock.js +25 -0
  102. package/dist/internal/process-alive.d.ts +42 -0
  103. package/dist/internal/process-alive.js +56 -0
  104. package/dist/internal/process-kill.d.ts +27 -0
  105. package/dist/internal/process-kill.js +54 -0
  106. package/dist/internal/realpath.d.ts +29 -0
  107. package/dist/internal/realpath.js +52 -0
  108. package/dist/internal/redact.d.ts +40 -0
  109. package/dist/internal/redact.js +161 -0
  110. package/dist/internal/shell-quote.d.ts +2 -0
  111. package/dist/internal/shell-quote.js +4 -0
  112. package/dist/internal/sort.d.ts +20 -0
  113. package/dist/internal/sort.js +20 -0
  114. package/dist/internal/strip-control-chars.d.ts +19 -0
  115. package/dist/internal/strip-control-chars.js +38 -0
  116. package/dist/internal/thenable.d.ts +10 -0
  117. package/dist/internal/thenable.js +15 -0
  118. package/dist/internal.d.ts +91 -0
  119. package/dist/internal.js +91 -0
  120. package/dist/native/adapter-deps.d.ts +46 -0
  121. package/dist/native/adapter-deps.js +43 -0
  122. package/dist/native/auth-types.d.ts +70 -0
  123. package/dist/native/auth-types.js +13 -0
  124. package/dist/native/auth.d.ts +133 -0
  125. package/dist/native/auth.js +362 -0
  126. package/dist/native/client.d.ts +50 -0
  127. package/dist/native/client.js +174 -0
  128. package/dist/native/complete.d.ts +33 -0
  129. package/dist/native/complete.js +88 -0
  130. package/dist/native/credentials/chained-store.d.ts +30 -0
  131. package/dist/native/credentials/chained-store.js +68 -0
  132. package/dist/native/credentials/change-guard.d.ts +51 -0
  133. package/dist/native/credentials/change-guard.js +136 -0
  134. package/dist/native/credentials/exec-source.d.ts +50 -0
  135. package/dist/native/credentials/exec-source.js +222 -0
  136. package/dist/native/credentials/fingerprint.d.ts +26 -0
  137. package/dist/native/credentials/fingerprint.js +174 -0
  138. package/dist/native/credentials/helper-process.d.ts +79 -0
  139. package/dist/native/credentials/helper-process.js +259 -0
  140. package/dist/native/credentials/helper-protocol.d.ts +36 -0
  141. package/dist/native/credentials/helper-protocol.js +79 -0
  142. package/dist/native/credentials/index.d.ts +60 -0
  143. package/dist/native/credentials/index.js +184 -0
  144. package/dist/native/errors.d.ts +34 -0
  145. package/dist/native/errors.js +109 -0
  146. package/dist/native/index.d.ts +25 -0
  147. package/dist/native/index.js +23 -0
  148. package/dist/native/model-resolver.d.ts +57 -0
  149. package/dist/native/model-resolver.js +73 -0
  150. package/dist/native/models.d.ts +116 -0
  151. package/dist/native/models.js +183 -0
  152. package/dist/native/session/ask-human.d.ts +15 -0
  153. package/dist/native/session/ask-human.js +22 -0
  154. package/dist/native/session/compaction.d.ts +94 -0
  155. package/dist/native/session/compaction.js +170 -0
  156. package/dist/native/session/handle-invalid-tool-call.d.ts +111 -0
  157. package/dist/native/session/handle-invalid-tool-call.js +159 -0
  158. package/dist/native/session/loop-events/cache-boundary.d.ts +11 -0
  159. package/dist/native/session/loop-events/cache-boundary.js +29 -0
  160. package/dist/native/session/loop-events/external-handler.d.ts +38 -0
  161. package/dist/native/session/loop-events/external-handler.js +193 -0
  162. package/dist/native/session/loop-events/index.d.ts +16 -0
  163. package/dist/native/session/loop-events/index.js +15 -0
  164. package/dist/native/session/loop-events/payload-guard.d.ts +9 -0
  165. package/dist/native/session/loop-events/payload-guard.js +31 -0
  166. package/dist/native/session/loop-events/registry.d.ts +84 -0
  167. package/dist/native/session/loop-events/registry.js +305 -0
  168. package/dist/native/session/loop-events/types.d.ts +251 -0
  169. package/dist/native/session/loop-events/types.js +14 -0
  170. package/dist/native/session/loop-handlers.d.ts +73 -0
  171. package/dist/native/session/loop-handlers.js +137 -0
  172. package/dist/native/session/nudge.d.ts +29 -0
  173. package/dist/native/session/nudge.js +35 -0
  174. package/dist/native/session/rate-provenance.d.ts +17 -0
  175. package/dist/native/session/rate-provenance.js +39 -0
  176. package/dist/native/session/session.d.ts +139 -0
  177. package/dist/native/session/session.js +208 -0
  178. package/dist/native/session/tool-input-exemplar.d.ts +2 -0
  179. package/dist/native/session/tool-input-exemplar.js +66 -0
  180. package/dist/native/session/tool-input-validation.d.ts +15 -0
  181. package/dist/native/session/tool-input-validation.js +146 -0
  182. package/dist/native/session/tool-mapping.d.ts +18 -0
  183. package/dist/native/session/tool-mapping.js +27 -0
  184. package/dist/native/session/tool-result.d.ts +37 -0
  185. package/dist/native/session/tool-result.js +25 -0
  186. package/dist/native/session/transcript-store.d.ts +77 -0
  187. package/dist/native/session/transcript-store.js +200 -0
  188. package/dist/native/session/truncation-handler.d.ts +47 -0
  189. package/dist/native/session/truncation-handler.js +83 -0
  190. package/dist/native/session/turn-accumulator.d.ts +45 -0
  191. package/dist/native/session/turn-accumulator.js +67 -0
  192. package/dist/native/session/turn-ask-human.d.ts +23 -0
  193. package/dist/native/session/turn-ask-human.js +41 -0
  194. package/dist/native/session/turn-compaction-step.d.ts +74 -0
  195. package/dist/native/session/turn-compaction-step.js +128 -0
  196. package/dist/native/session/turn-complete-step.d.ts +77 -0
  197. package/dist/native/session/turn-complete-step.js +159 -0
  198. package/dist/native/session/turn-end-event.d.ts +3 -0
  199. package/dist/native/session/turn-end-event.js +17 -0
  200. package/dist/native/session/turn-events.d.ts +63 -0
  201. package/dist/native/session/turn-events.js +48 -0
  202. package/dist/native/session/turn-loop-round-trip.d.ts +116 -0
  203. package/dist/native/session/turn-loop-round-trip.js +318 -0
  204. package/dist/native/session/turn-loop.d.ts +23 -0
  205. package/dist/native/session/turn-loop.js +250 -0
  206. package/dist/native/session/turn-result.d.ts +39 -0
  207. package/dist/native/session/turn-result.js +64 -0
  208. package/dist/native/session/turn-retry.d.ts +120 -0
  209. package/dist/native/session/turn-retry.js +182 -0
  210. package/dist/native/session/turn-tool-batch.d.ts +61 -0
  211. package/dist/native/session/turn-tool-batch.js +259 -0
  212. package/dist/native/session/turn-types.d.ts +164 -0
  213. package/dist/native/session/turn-types.js +36 -0
  214. package/dist/native/session-adapter.d.ts +56 -0
  215. package/dist/native/session-adapter.js +369 -0
  216. package/dist/native/session-affinity.d.ts +36 -0
  217. package/dist/native/session-affinity.js +43 -0
  218. package/dist/native/tier-providers.d.ts +18 -0
  219. package/dist/native/tier-providers.js +20 -0
  220. package/dist/permissions/approval-audit.d.ts +10 -0
  221. package/dist/permissions/approval-audit.js +22 -0
  222. package/dist/permissions/approvals-link.d.ts +20 -0
  223. package/dist/permissions/approvals-link.js +62 -0
  224. package/dist/permissions/approvals-store.d.ts +168 -0
  225. package/dist/permissions/approvals-store.js +259 -0
  226. package/dist/permissions/approvals-taint.d.ts +33 -0
  227. package/dist/permissions/approvals-taint.js +138 -0
  228. package/dist/permissions/ask-chain.d.ts +69 -0
  229. package/dist/permissions/ask-chain.js +32 -0
  230. package/dist/permissions/ask.d.ts +23 -0
  231. package/dist/permissions/ask.js +25 -0
  232. package/dist/permissions/bash-lex.d.ts +59 -0
  233. package/dist/permissions/bash-lex.js +279 -0
  234. package/dist/permissions/grammar.d.ts +12 -0
  235. package/dist/permissions/grammar.js +24 -0
  236. package/dist/permissions/index.d.ts +11 -0
  237. package/dist/permissions/index.js +9 -0
  238. package/dist/permissions/secret-spans.d.ts +19 -0
  239. package/dist/permissions/secret-spans.js +88 -0
  240. package/dist/permissions/types.d.ts +85 -0
  241. package/dist/permissions/types.js +1 -0
  242. package/dist/runtime/index.d.ts +3 -0
  243. package/dist/runtime/index.js +2 -0
  244. package/dist/runtime/node-glob.d.ts +3 -0
  245. package/dist/runtime/node-glob.js +83 -0
  246. package/dist/runtime/node-runtime.d.ts +3 -0
  247. package/dist/runtime/node-runtime.js +126 -0
  248. package/dist/runtime/slot.d.ts +11 -0
  249. package/dist/runtime/slot.js +17 -0
  250. package/dist/runtime/types.d.ts +51 -0
  251. package/dist/runtime/types.js +1 -0
  252. package/dist/runtime/which.d.ts +8 -0
  253. package/dist/runtime/which.js +32 -0
  254. package/dist/sandbox/argv-quote.d.ts +11 -0
  255. package/dist/sandbox/argv-quote.js +13 -0
  256. package/dist/sandbox/defaults.d.ts +27 -0
  257. package/dist/sandbox/defaults.js +47 -0
  258. package/dist/sandbox/git-guards.d.ts +64 -0
  259. package/dist/sandbox/git-guards.js +161 -0
  260. package/dist/sandbox/index.d.ts +11 -0
  261. package/dist/sandbox/index.js +10 -0
  262. package/dist/sandbox/launcher.d.ts +37 -0
  263. package/dist/sandbox/launcher.js +160 -0
  264. package/dist/sandbox/messages.d.ts +17 -0
  265. package/dist/sandbox/messages.js +46 -0
  266. package/dist/sandbox/policy-builder.d.ts +44 -0
  267. package/dist/sandbox/policy-builder.js +149 -0
  268. package/dist/sandbox/policy-inputs.d.ts +53 -0
  269. package/dist/sandbox/policy-inputs.js +76 -0
  270. package/dist/sandbox/probe.d.ts +8 -0
  271. package/dist/sandbox/probe.js +66 -0
  272. package/dist/sandbox/registry.d.ts +17 -0
  273. package/dist/sandbox/registry.js +57 -0
  274. package/dist/sandbox/session-tmp.d.ts +20 -0
  275. package/dist/sandbox/session-tmp.js +95 -0
  276. package/dist/sandbox/srt-backend.d.ts +21 -0
  277. package/dist/sandbox/srt-backend.js +99 -0
  278. package/dist/sandbox/types.d.ts +102 -0
  279. package/dist/sandbox/types.js +1 -0
  280. package/dist/session/adapter-failure.d.ts +60 -0
  281. package/dist/session/adapter-failure.js +11 -0
  282. package/dist/session/agent-stream-events.d.ts +103 -0
  283. package/dist/session/agent-stream-events.js +6 -0
  284. package/dist/session/interaction-handler.d.ts +53 -0
  285. package/dist/session/interaction-handler.js +2 -0
  286. package/dist/session/no-op-interaction-handler.d.ts +9 -0
  287. package/dist/session/no-op-interaction-handler.js +11 -0
  288. package/dist/session/protocol-types.d.ts +12 -0
  289. package/dist/session/protocol-types.js +1 -0
  290. package/dist/session/session-types.d.ts +456 -0
  291. package/dist/session/session-types.js +64 -0
  292. package/dist/session/tool-descriptor.d.ts +23 -0
  293. package/dist/session/tool-descriptor.js +5 -0
  294. package/dist/session/turn-deadline.d.ts +17 -0
  295. package/dist/session/turn-deadline.js +23 -0
  296. package/dist/tools/ask-request.d.ts +35 -0
  297. package/dist/tools/ask-request.js +57 -0
  298. package/dist/tools/bash-cwd.d.ts +82 -0
  299. package/dist/tools/bash-cwd.js +55 -0
  300. package/dist/tools/bash.d.ts +69 -0
  301. package/dist/tools/bash.js +283 -0
  302. package/dist/tools/delete.d.ts +57 -0
  303. package/dist/tools/delete.js +154 -0
  304. package/dist/tools/denial-redirect.d.ts +42 -0
  305. package/dist/tools/denial-redirect.js +266 -0
  306. package/dist/tools/deny-paths.d.ts +35 -0
  307. package/dist/tools/deny-paths.js +76 -0
  308. package/dist/tools/edit-region.d.ts +50 -0
  309. package/dist/tools/edit-region.js +90 -0
  310. package/dist/tools/edit.d.ts +25 -0
  311. package/dist/tools/edit.js +114 -0
  312. package/dist/tools/exec-allowlist-text.d.ts +18 -0
  313. package/dist/tools/exec-allowlist-text.js +24 -0
  314. package/dist/tools/exec-guard.d.ts +69 -0
  315. package/dist/tools/exec-guard.js +151 -0
  316. package/dist/tools/git-commit.d.ts +59 -0
  317. package/dist/tools/git-commit.js +220 -0
  318. package/dist/tools/git-flags/index.d.ts +10 -0
  319. package/dist/tools/git-flags/index.js +10 -0
  320. package/dist/tools/git.d.ts +88 -0
  321. package/dist/tools/git.js +397 -0
  322. package/dist/tools/glob.d.ts +29 -0
  323. package/dist/tools/glob.js +153 -0
  324. package/dist/tools/grep.d.ts +21 -0
  325. package/dist/tools/grep.js +162 -0
  326. package/dist/tools/index.d.ts +36 -0
  327. package/dist/tools/index.js +28 -0
  328. package/dist/tools/narrow-grants.d.ts +19 -0
  329. package/dist/tools/narrow-grants.js +54 -0
  330. package/dist/tools/nax-owned-writes.d.ts +135 -0
  331. package/dist/tools/nax-owned-writes.js +259 -0
  332. package/dist/tools/package-managers-table.d.ts +146 -0
  333. package/dist/tools/package-managers-table.js +325 -0
  334. package/dist/tools/package-managers-types.d.ts +36 -0
  335. package/dist/tools/package-managers-types.js +6 -0
  336. package/dist/tools/package-managers.d.ts +85 -0
  337. package/dist/tools/package-managers.js +391 -0
  338. package/dist/tools/path-list.d.ts +38 -0
  339. package/dist/tools/path-list.js +62 -0
  340. package/dist/tools/policy-bash-raw.d.ts +19 -0
  341. package/dist/tools/policy-bash-raw.js +210 -0
  342. package/dist/tools/policy-bash.d.ts +64 -0
  343. package/dist/tools/policy-bash.js +232 -0
  344. package/dist/tools/policy-command-branch.d.ts +32 -0
  345. package/dist/tools/policy-command-branch.js +63 -0
  346. package/dist/tools/policy-input.d.ts +2 -0
  347. package/dist/tools/policy-input.js +10 -0
  348. package/dist/tools/policy-match.d.ts +75 -0
  349. package/dist/tools/policy-match.js +117 -0
  350. package/dist/tools/policy-paths-branch.d.ts +97 -0
  351. package/dist/tools/policy-paths-branch.js +314 -0
  352. package/dist/tools/policy.d.ts +65 -0
  353. package/dist/tools/policy.js +232 -0
  354. package/dist/tools/protected-paths.d.ts +26 -0
  355. package/dist/tools/protected-paths.js +8 -0
  356. package/dist/tools/provider-adapt.d.ts +4 -0
  357. package/dist/tools/provider-adapt.js +32 -0
  358. package/dist/tools/provider-advertise.d.ts +39 -0
  359. package/dist/tools/provider-advertise.js +50 -0
  360. package/dist/tools/provider-grants.d.ts +36 -0
  361. package/dist/tools/provider-grants.js +72 -0
  362. package/dist/tools/provider-sanitize.d.ts +19 -0
  363. package/dist/tools/provider-sanitize.js +53 -0
  364. package/dist/tools/provider-types.d.ts +41 -0
  365. package/dist/tools/provider-types.js +26 -0
  366. package/dist/tools/read-continuation.d.ts +147 -0
  367. package/dist/tools/read-continuation.js +176 -0
  368. package/dist/tools/read-file.d.ts +32 -0
  369. package/dist/tools/read-file.js +85 -0
  370. package/dist/tools/read.d.ts +25 -0
  371. package/dist/tools/read.js +182 -0
  372. package/dist/tools/registry.d.ts +125 -0
  373. package/dist/tools/registry.js +67 -0
  374. package/dist/tools/request-capability.d.ts +13 -0
  375. package/dist/tools/request-capability.js +23 -0
  376. package/dist/tools/run-command-exec.d.ts +14 -0
  377. package/dist/tools/run-command-exec.js +161 -0
  378. package/dist/tools/run-command.d.ts +107 -0
  379. package/dist/tools/run-command.js +398 -0
  380. package/dist/tools/runtime-calltool.d.ts +146 -0
  381. package/dist/tools/runtime-calltool.js +223 -0
  382. package/dist/tools/runtime.d.ts +149 -0
  383. package/dist/tools/runtime.js +345 -0
  384. package/dist/tools/scratchpad.d.ts +20 -0
  385. package/dist/tools/scratchpad.js +197 -0
  386. package/dist/tools/spill.d.ts +81 -0
  387. package/dist/tools/spill.js +251 -0
  388. package/dist/tools/tool-audit.d.ts +171 -0
  389. package/dist/tools/tool-audit.js +183 -0
  390. package/dist/tools/truncate.d.ts +98 -0
  391. package/dist/tools/truncate.js +297 -0
  392. package/dist/tools/types.d.ts +145 -0
  393. package/dist/tools/types.js +24 -0
  394. package/dist/tools/verb-denial-argv-hint.d.ts +35 -0
  395. package/dist/tools/verb-denial-argv-hint.js +40 -0
  396. package/dist/tools/write.d.ts +9 -0
  397. package/dist/tools/write.js +45 -0
  398. package/package.json +54 -0
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The handlers the seam carries today (nax#2151, US-002, US-003). Installed in
3
+ * order: the two built-in `before_tool` handlers — invalid-call repair and the
4
+ * spin breaker — then every plugin entry the turn supplied, then the built-in
5
+ * `after_tool` truncation. The first two were inline branches in `turn-loop.ts`
6
+ * before the seam; they are ordinary registrations now, and the order they
7
+ * register in is the order the loop consulted them before.
8
+ *
9
+ * The plugin entries sit BETWEEN the built-ins on purpose (US-003): a call the
10
+ * repair already blocked or the breaker already terminated never reaches a
11
+ * plugin handler (`dispatchBeforeTool` returns on the first block/terminate),
12
+ * while a plugin `before_tool` handler still judges the call the tool would
13
+ * actually receive, after null-optional repair. Truncation registers LAST among
14
+ * `after_tool` handlers, which is the position the loop's hardcoded call held:
15
+ * it shapes whatever the plugin `after_tool` entries produced, before the
16
+ * result is built.
17
+ *
18
+ * All of them are PER-TURN — the invalid-call budget, the spin reprieve, the
19
+ * plugin set with its context and signal, and the session whose spill root
20
+ * truncation resolves all reset or are re-supplied with the turn — but they are
21
+ * installed ONCE per registry, with the per-turn state swapped underneath them.
22
+ * Registering a fresh set every turn would accumulate handlers on a registry a
23
+ * caller reuses across turns, each set still closing over the turn that created
24
+ * it: a later turn would be judged by an earlier turn's budget, the shared
25
+ * breaker would be advanced once per installed pair — halving every threshold
26
+ * it is supposed to enforce — and a plugin handler would run once per turn
27
+ * installed instead of once per dispatch.
28
+ *
29
+ * The wrapped plugin entries read the current turn through `state` rather than
30
+ * from whatever was in scope at install time, so a repointed registry hands
31
+ * them the new context and the new signal.
32
+ */
33
+ import { type SpinBreaker } from "#src/infra/spin-breaker/index";
34
+ import { type InvalidCallBudget } from "./handle-invalid-tool-call.ts";
35
+ import { type LoopEventRegistry, type LoopHandlerContext, type LoopHandlerSet } from "./loop-events/index.ts";
36
+ export interface BuiltinLoopHandlerDeps {
37
+ /**
38
+ * The session the handlers run for. Truncation resolves its spill root
39
+ * against it; read through `state.current` at dispatch like every other
40
+ * per-turn dep, so a repointed registry never keeps a stale session.
41
+ */
42
+ readonly sessionName: string;
43
+ /** Per-turn invalid-call budget. The loop reads `exceeded` for the halt. */
44
+ readonly budget: InvalidCallBudget;
45
+ /** Absent disables the breaker, exactly as `TurnDeps.spinBreaker` does. */
46
+ readonly spinBreaker?: SpinBreaker;
47
+ /**
48
+ * Called when the breaker stops the batch (nax#2120). The loop spends one
49
+ * terminal round trip on that stop, so it is the loop — not the handler —
50
+ * that records what the stop means for the turn.
51
+ */
52
+ readonly onSpinStop: () => void;
53
+ /**
54
+ * The run's plugin-contributed handlers (US-003), staged by
55
+ * `PluginRegistry.getLoopHandlers()` and forwarded per turn by the adapter.
56
+ * Absent or empty is the normal case: the built-ins are then the whole
57
+ * chain.
58
+ */
59
+ readonly loopHandlers?: LoopHandlerSet;
60
+ /**
61
+ * The read-only facts a plugin handler is handed at dispatch. Read through
62
+ * `state.current` like every other per-turn dep, so a repointed registry
63
+ * never keeps an earlier turn's context.
64
+ */
65
+ readonly loopHandlerContext?: LoopHandlerContext;
66
+ /**
67
+ * The turn's abort signal (US-003), handed to each wrapped plugin entry so
68
+ * an abort lands on a pending plugin handler. Read-only: a plugin handler
69
+ * gets no way to abort the turn.
70
+ */
71
+ readonly signal?: AbortSignal;
72
+ }
73
+ export declare function registerBuiltinLoopHandlers(registry: LoopEventRegistry, deps: BuiltinLoopHandlerDeps): void;
@@ -0,0 +1,137 @@
1
+ /**
2
+ * The handlers the seam carries today (nax#2151, US-002, US-003). Installed in
3
+ * order: the two built-in `before_tool` handlers — invalid-call repair and the
4
+ * spin breaker — then every plugin entry the turn supplied, then the built-in
5
+ * `after_tool` truncation. The first two were inline branches in `turn-loop.ts`
6
+ * before the seam; they are ordinary registrations now, and the order they
7
+ * register in is the order the loop consulted them before.
8
+ *
9
+ * The plugin entries sit BETWEEN the built-ins on purpose (US-003): a call the
10
+ * repair already blocked or the breaker already terminated never reaches a
11
+ * plugin handler (`dispatchBeforeTool` returns on the first block/terminate),
12
+ * while a plugin `before_tool` handler still judges the call the tool would
13
+ * actually receive, after null-optional repair. Truncation registers LAST among
14
+ * `after_tool` handlers, which is the position the loop's hardcoded call held:
15
+ * it shapes whatever the plugin `after_tool` entries produced, before the
16
+ * result is built.
17
+ *
18
+ * All of them are PER-TURN — the invalid-call budget, the spin reprieve, the
19
+ * plugin set with its context and signal, and the session whose spill root
20
+ * truncation resolves all reset or are re-supplied with the turn — but they are
21
+ * installed ONCE per registry, with the per-turn state swapped underneath them.
22
+ * Registering a fresh set every turn would accumulate handlers on a registry a
23
+ * caller reuses across turns, each set still closing over the turn that created
24
+ * it: a later turn would be judged by an earlier turn's budget, the shared
25
+ * breaker would be advanced once per installed pair — halving every threshold
26
+ * it is supposed to enforce — and a plugin handler would run once per turn
27
+ * installed instead of once per dispatch.
28
+ *
29
+ * The wrapped plugin entries read the current turn through `state` rather than
30
+ * from whatever was in scope at install time, so a repointed registry hands
31
+ * them the new context and the new signal.
32
+ */
33
+ import { spinTerminalNotice } from "#src/infra/spin-breaker/index";
34
+ import { normalizeNullOptionals } from "./handle-invalid-tool-call.js";
35
+ import { wrapExternalHandler, } from "./loop-events/index.js";
36
+ import { createTruncationHandler } from "./truncation-handler.js";
37
+ /** A signal that is never aborted, standing in when a turn supplied none. */
38
+ const NEVER_ABORTED = new AbortController().signal;
39
+ /**
40
+ * The context handed to a plugin handler. A caller that supplies handlers is
41
+ * expected to supply the context with them, but a handler must never be handed
42
+ * `undefined`: the fact it scopes itself by is the session's own name, which
43
+ * nax always knows.
44
+ */
45
+ function contextFor(state) {
46
+ return state.current.loopHandlerContext ?? { sessionName: state.current.sessionName };
47
+ }
48
+ /**
49
+ * A live view of the turn's signal. The wrapped plugin entries are installed
50
+ * once per registry, while the signal is repointed with the rest of the
51
+ * per-turn state, so the view reads `state.current.signal` when the wrapper
52
+ * subscribes instead of capturing whatever was in scope at install time.
53
+ *
54
+ * `raceSettlement` subscribes and unsubscribes and nothing else, so those two
55
+ * methods are the whole surface this view has to answer.
56
+ */
57
+ function turnSignalView(state) {
58
+ const current = () => state.current.signal ?? NEVER_ABORTED;
59
+ return {
60
+ addEventListener: (...args) => current().addEventListener(...args),
61
+ removeEventListener: (...args) => current().removeEventListener(...args),
62
+ };
63
+ }
64
+ /**
65
+ * One entry per registry the built-ins are installed on, so a second call for
66
+ * the same registry is a repoint rather than a second pair. Weak, so the
67
+ * loop's own per-turn registry takes its state with it when the turn ends.
68
+ */
69
+ const turnStateByRegistry = new WeakMap();
70
+ export function registerBuiltinLoopHandlers(registry, deps) {
71
+ const installed = turnStateByRegistry.get(registry);
72
+ if (installed !== undefined) {
73
+ installed.current = deps;
74
+ return;
75
+ }
76
+ const state = { current: deps };
77
+ turnStateByRegistry.set(registry, state);
78
+ // Registered first, which is the pre-seam order: a malformed call is refused
79
+ // before the spin breaker counts it. The empty string produced no rejected
80
+ // keys, so counting a malformed call as spin evidence is how nax#2047's 69
81
+ // identical bad calls stayed invisible.
82
+ registry.register("before_tool", ({ call, tools }) => repairInvalidCall(state, call, tools));
83
+ registry.register("before_tool", ({ call }) => observeSpin(state, call));
84
+ // US-003: the plugin entries go between the built-in pair above and the
85
+ // built-in truncation below, so a call a built-in already refused is never
86
+ // offered to a plugin — `dispatchBeforeTool` returns on the first
87
+ // block/terminate — while a plugin `before_tool` handler still judges the
88
+ // repaired call. Each handler and its context are read through `state`, so
89
+ // the entries installed here are the same ones a repointed registry
90
+ // dispatches, with the turn's own facts.
91
+ for (const entry of deps.loopHandlers ?? []) {
92
+ registry.register(entry.event, wrapExternalHandler(entry, () => contextFor(state), turnSignalView(state)));
93
+ }
94
+ // Registered LAST among after_tool handlers, which is the pre-seam position:
95
+ // the loop's hardcoded truncation call ran after the dispatcher, so it shaped
96
+ // whatever the handlers produced. The handler is rebuilt per dispatch so the
97
+ // session name is read through `state.current` — the same lifetime the other
98
+ // per-turn deps use — rather than frozen at install time.
99
+ registry.register("after_tool", (payload) => createTruncationHandler(state.current.sessionName)(payload));
100
+ }
101
+ function repairInvalidCall(state, call, tools) {
102
+ const invalid = state.current.budget.observe(call, tools);
103
+ if (invalid === undefined) {
104
+ // nax#2200: a `null` optional property validated as absent, so the tool
105
+ // must receive it absent too — the rewrite is what the loop runs and
106
+ // records. No `null` to drop leaves the success path untouched.
107
+ const normalized = normalizeNullOptionals(call, tools);
108
+ return normalized === undefined ? { kind: "allow" } : { kind: "allow", input: normalized };
109
+ }
110
+ if (invalid.kind === "stopped") {
111
+ // A tripped budget ends the batch with NO tool-result — "a result nobody
112
+ // reads only grows the transcript" (nax#2047 Task 4). None of the four
113
+ // outcome kinds can express that (each of them answers the call), so the
114
+ // loop reads the halt from `budget.exceeded` and breaks before applying
115
+ // this outcome.
116
+ return { kind: "allow" };
117
+ }
118
+ // Repaired, not executed: the loop records the model's input minus the
119
+ // rejected property on the assistant message, and answers with the error
120
+ // text, which carries the exemplar (nax#2200).
121
+ return { kind: "block", content: invalid.content, isError: true, input: invalid.input };
122
+ }
123
+ function observeSpin(state, call) {
124
+ const { budget, spinBreaker, onSpinStop } = state.current;
125
+ // The budget halt wins: the turn ends without executing this call, so
126
+ // letting the breaker count it would record a call that never ran.
127
+ if (budget.exceeded)
128
+ return { kind: "allow" };
129
+ const verdict = spinBreaker?.observe(call.name, call.input) ?? { action: "allow" };
130
+ if (verdict.action === "stop") {
131
+ onSpinStop();
132
+ return { kind: "terminate", content: spinTerminalNotice(verdict.reason), isError: true };
133
+ }
134
+ if (verdict.action === "nudge")
135
+ return { kind: "nudge", text: verdict.text };
136
+ return { kind: "allow" };
137
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The spin-breaker nudge's text composition and its cost against the
3
+ * model-facing byte ceiling.
4
+ *
5
+ * These live together because they are one decision seen from two sides: how
6
+ * the nudge is joined to a tool result, and how many bytes that join spends.
7
+ * `truncateNativeToolResult` reserves what `nudgeOverheadBytes` reports so the
8
+ * prefix fits INSIDE `MODEL_MAX_BYTES` instead of pushing the result past it —
9
+ * splitting the two across modules is what lets the separator change without
10
+ * the reservation following it.
11
+ */
12
+ /**
13
+ * `nudge` prefixes the eventual result rather than replacing it: the model
14
+ * needs the real output to act on, plus the notice that it is repeating itself
15
+ * (nax#2120). The handler's text leads, because a handler that says "begin with
16
+ * this" must be able to.
17
+ */
18
+ export declare function withNudge(nudgeText: string | undefined, content: string): string;
19
+ /**
20
+ * What `withNudge` will add, in the bytes the ceiling is measured in. The
21
+ * truncation chokepoint reserves this so the prefix fits inside
22
+ * `MODEL_MAX_BYTES` rather than on top of it.
23
+ *
24
+ * The nudge text is harness-authored and short by construction (`nudgeText()`
25
+ * in src/runtime/spin-breaker), so the reservation never consumes the whole
26
+ * budget in practice; `truncateNativeToolResult` floors the remainder at zero
27
+ * regardless.
28
+ */
29
+ export declare function nudgeOverheadBytes(nudgeText: string): number;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The spin-breaker nudge's text composition and its cost against the
3
+ * model-facing byte ceiling.
4
+ *
5
+ * These live together because they are one decision seen from two sides: how
6
+ * the nudge is joined to a tool result, and how many bytes that join spends.
7
+ * `truncateNativeToolResult` reserves what `nudgeOverheadBytes` reports so the
8
+ * prefix fits INSIDE `MODEL_MAX_BYTES` instead of pushing the result past it —
9
+ * splitting the two across modules is what lets the separator change without
10
+ * the reservation following it.
11
+ */
12
+ /** Joins the nudge to the result it prefixes. Counted by `nudgeOverheadBytes`. */
13
+ const NUDGE_SEPARATOR = "\n\n---\n\n";
14
+ /**
15
+ * `nudge` prefixes the eventual result rather than replacing it: the model
16
+ * needs the real output to act on, plus the notice that it is repeating itself
17
+ * (nax#2120). The handler's text leads, because a handler that says "begin with
18
+ * this" must be able to.
19
+ */
20
+ export function withNudge(nudgeText, content) {
21
+ return nudgeText === undefined ? content : `${nudgeText}${NUDGE_SEPARATOR}${content}`;
22
+ }
23
+ /**
24
+ * What `withNudge` will add, in the bytes the ceiling is measured in. The
25
+ * truncation chokepoint reserves this so the prefix fits inside
26
+ * `MODEL_MAX_BYTES` rather than on top of it.
27
+ *
28
+ * The nudge text is harness-authored and short by construction (`nudgeText()`
29
+ * in src/runtime/spin-breaker), so the reservation never consumes the whole
30
+ * budget in practice; `truncateNativeToolResult` floors the remainder at zero
31
+ * regardless.
32
+ */
33
+ export function nudgeOverheadBytes(nudgeText) {
34
+ return Buffer.byteLength(nudgeText, "utf8") + Buffer.byteLength(NUDGE_SEPARATOR, "utf8");
35
+ }
@@ -0,0 +1,17 @@
1
+ import type { PricingRates, TokenUsage } from "#src/cost/standard-types";
2
+ interface RateTotals {
3
+ inputTokens: number;
4
+ outputTokens: number;
5
+ cacheReadTokens: number;
6
+ cacheCreationTokens: number;
7
+ inputCostPerMillionTokens: number;
8
+ outputCostPerMillionTokens: number;
9
+ cacheReadCostPerMillionTokens: number;
10
+ cacheCreationCostPerMillionTokens: number;
11
+ latestRates?: PricingRates;
12
+ complete: boolean;
13
+ }
14
+ export declare function createRateTotals(): RateTotals;
15
+ export declare function addRateTotals(totals: RateTotals, usage: TokenUsage, rates: PricingRates | undefined): void;
16
+ export declare function aggregateRates(totals: RateTotals): PricingRates | undefined;
17
+ export {};
@@ -0,0 +1,39 @@
1
+ export function createRateTotals() {
2
+ return {
3
+ inputTokens: 0,
4
+ outputTokens: 0,
5
+ cacheReadTokens: 0,
6
+ cacheCreationTokens: 0,
7
+ inputCostPerMillionTokens: 0,
8
+ outputCostPerMillionTokens: 0,
9
+ cacheReadCostPerMillionTokens: 0,
10
+ cacheCreationCostPerMillionTokens: 0,
11
+ complete: true,
12
+ };
13
+ }
14
+ export function addRateTotals(totals, usage, rates) {
15
+ if (rates === undefined) {
16
+ totals.complete = false;
17
+ return;
18
+ }
19
+ totals.inputTokens += usage.inputTokens;
20
+ totals.outputTokens += usage.outputTokens;
21
+ totals.cacheReadTokens += usage.cacheReadTokens ?? 0;
22
+ totals.cacheCreationTokens += usage.cacheWriteTokens ?? 0;
23
+ totals.inputCostPerMillionTokens += usage.inputTokens * rates.input;
24
+ totals.outputCostPerMillionTokens += usage.outputTokens * rates.output;
25
+ totals.cacheReadCostPerMillionTokens += (usage.cacheReadTokens ?? 0) * rates.cacheRead;
26
+ totals.cacheCreationCostPerMillionTokens += (usage.cacheWriteTokens ?? 0) * rates.cacheWrite;
27
+ totals.latestRates = rates;
28
+ }
29
+ export function aggregateRates(totals) {
30
+ if (!totals.complete || totals.latestRates === undefined)
31
+ return undefined;
32
+ const weightedRate = (tokens, rateTotal, fallback) => tokens === 0 ? fallback : rateTotal / tokens;
33
+ return {
34
+ input: weightedRate(totals.inputTokens, totals.inputCostPerMillionTokens, totals.latestRates.input),
35
+ output: weightedRate(totals.outputTokens, totals.outputCostPerMillionTokens, totals.latestRates.output),
36
+ cacheRead: weightedRate(totals.cacheReadTokens, totals.cacheReadCostPerMillionTokens, totals.latestRates.cacheRead),
37
+ cacheWrite: weightedRate(totals.cacheCreationTokens, totals.cacheCreationCostPerMillionTokens, totals.latestRates.cacheWrite),
38
+ };
39
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Native session lifecycle.
3
+ *
4
+ * There is no subprocess and no backend that remembers, so opening a session
5
+ * establishes nothing — it records where the conversation will be kept. ADR-027
6
+ * section 10 predicted exactly this shape: "openSession and closeSession become
7
+ * either no-ops or transcript-file handles".
8
+ */
9
+ import { type SpinBreaker } from "#src/infra/spin-breaker/index";
10
+ import type { AgentStreamEvent } from "#src/session/agent-stream-events";
11
+ import type { OpenSessionOpts, SessionHandle } from "#src/session/session-types";
12
+ import type { ResolvedCompaction } from "./compaction.ts";
13
+ import type { TurnRetryConfig } from "./turn-retry.ts";
14
+ /**
15
+ * Session name -> transcript directory, so sendTurn and close can find it.
16
+ *
17
+ * Cleared by every close path — `closeNativeSession` (in-process) and the
18
+ * adapter's `closePhysicalSession` (run teardown, which only has the name) —
19
+ * through the shared `clearNativeSessionState`. A caller that opens a session
20
+ * and never closes it (e.g. an early return, or a thrown error between open and
21
+ * close) still leaks an entry for the lifetime of the process. Harmless in
22
+ * practice (it is a small in-memory map keyed by session name, not a handle
23
+ * to a real resource), but worth knowing when debugging a growing map.
24
+ */
25
+ export declare const nativeTranscriptDirs: Map<string, string>;
26
+ /**
27
+ * Session name -> the root whose `.nax/scratchpad/` holds this session's
28
+ * spill files (US-003).
29
+ *
30
+ * Recorded from the session's `workdir` at open — the same root the coding
31
+ * tools are confined to — so a spilled body is reachable through
32
+ * `ScratchpadRead` with the relative path the truncation marker names. Same
33
+ * lifecycle as the maps above: set on open, cleared on close.
34
+ */
35
+ export declare const nativeSessionScratchpadRoots: Map<string, string>;
36
+ /**
37
+ * Session name -> timeoutSeconds, so sendTurn can bound each `complete()`
38
+ * call with a deadline (whole-branch review finding 4). Same lifecycle as
39
+ * `nativeTranscriptDirs` — populated on open, cleared on close only.
40
+ */
41
+ export declare const nativeSessionTimeouts: Map<string, number>;
42
+ /**
43
+ * Session name -> the runtime hooks handed to openSession. SessionManager
44
+ * passes both (manager.ts, openSession) and the native adapter previously
45
+ * ignored them, which is why the idle watchdog never covered native. Same
46
+ * lifecycle as `nativeTranscriptDirs`: set on open, cleared on close only.
47
+ */
48
+ export declare const nativeSessionStreamHooks: Map<string, {
49
+ onStreamActivity?: (event: AgentStreamEvent) => void;
50
+ onActiveCall?: (callId: string, cancel: () => Promise<void>) => void;
51
+ }>;
52
+ /**
53
+ * Session names whose most recent turn failed.
54
+ *
55
+ * `AgentAdapter.closeSession(handle)` carries no failure signal, so the close
56
+ * cannot tell a finished session from a broken one and passed `failed: false`
57
+ * for both -- deleting the transcript of exactly the session whose history the
58
+ * retry needs and a human would read (nax#1838). Rather than widen the adapter
59
+ * interface for one transport, the turn records what it knows here and the
60
+ * close reads it. Same lifecycle as the maps above: written per turn, cleared
61
+ * on close.
62
+ *
63
+ * A later successful turn clears the mark. "Failed" describes the session's
64
+ * current state, not whether it ever stumbled -- a session that recovered and
65
+ * finished is still cleaned up.
66
+ */
67
+ export declare const nativeSessionFailed: Set<string>;
68
+ /**
69
+ * Session name -> the identity that owns this session's transcript (nax#1877).
70
+ *
71
+ * Read by `runNativeTurn` on both the load and the save, so a transcript left
72
+ * behind by an abandoned invocation of the same deterministic session name is
73
+ * recognised as foreign rather than silently resumed. Same lifecycle as the
74
+ * maps above: set on open, cleared on close.
75
+ */
76
+ export declare const nativeSessionTranscriptOwners: Map<string, string>;
77
+ /** Session name -> resolved compaction settings. Same lifecycle as the maps above. */
78
+ export declare const nativeSessionCompaction: Map<string, ResolvedCompaction>;
79
+ /**
80
+ * Session name -> resolved transport-fault retry settings (nax#1870). Same
81
+ * lifecycle as the maps above: set on open, cleared on close.
82
+ */
83
+ export declare const nativeSessionTransportRetry: Map<string, TurnRetryConfig>;
84
+ /**
85
+ * Session name -> live `SpinBreaker` instance (nax#2013, lifetime extended in
86
+ * nax#2047). Constructed once at open so the cumulative counter survives
87
+ * across `runNativeTurn` calls — a fix round that opens a new turn on the
88
+ * same `handle.id` must inherit the prior turn's evidence rather than start
89
+ * fresh. Same lifecycle as `nativeSessionTransportRetry`: set on open, cleared
90
+ * on close.
91
+ */
92
+ export declare const nativeSessionSpinBreaker: Map<string, SpinBreaker>;
93
+ /**
94
+ * Session name -> the last round trip's reported input tokens and the index it
95
+ * covers, so the next estimate can anchor on a real number.
96
+ *
97
+ * In-memory rather than persisted because runNativeTurn reloads the transcript
98
+ * from disk on EVERY turn: without this the second turn of every session would
99
+ * be estimated from scratch. A process restart still loses it, which is the case
100
+ * the reactive backstop covers.
101
+ *
102
+ * `model` is the transcript model identity the anchor was measured under
103
+ * (P3 spec 8.3(d)); read it through `sessionAnchorFor`, never directly.
104
+ */
105
+ export interface SessionAnchor {
106
+ readonly promptTokens: number;
107
+ readonly anchorIndex: number;
108
+ readonly model?: string;
109
+ }
110
+ export declare const nativeSessionLastUsage: Map<string, SessionAnchor>;
111
+ /**
112
+ * The persisted anchor a turn on `model` may use. Prefix stability is a
113
+ * property of (model, prefix) (P3 spec 3.3): an anchor measured under a
114
+ * different model indexes history the transcript store refused (spec 8.3(c)),
115
+ * so it is dropped here rather than mis-sizing the next compaction decision.
116
+ * An entry or a turn with no model makes no claim — the store's own rule.
117
+ */
118
+ export declare function sessionAnchorFor(sessionName: string, model: string | undefined): SessionAnchor | undefined;
119
+ /** Records how the session's latest turn ended, for `closeNativeSession`. */
120
+ export declare function markNativeTurnOutcome(sessionName: string, failed: boolean): void;
121
+ export declare function openNativeSession(name: string, opts: OpenSessionOpts): Promise<SessionHandle>;
122
+ /**
123
+ * Clear every module-level entry for one session name.
124
+ *
125
+ * Extracted so both close paths share one source of truth. `closeNativeSession`
126
+ * has a `SessionHandle`; the adapter's `closePhysicalSession` gets only the
127
+ * handle string that run teardown carries (`descriptor.handle`). The two are
128
+ * the same string — every map is keyed by the session name, and `SessionHandle.id`
129
+ * is that name — but the signatures are not interchangeable, so this helper is
130
+ * string-keyed rather than reconstructed into a synthetic handle.
131
+ */
132
+ export declare function clearNativeSessionState(sessionName: string): void;
133
+ /**
134
+ * Kept on failure, deleted on success. Every Phase B op is lifetime "fresh", so
135
+ * the transcript survives exactly when it is worth reading. The kept-on-failure
136
+ * set is otherwise unbounded, so a failed close also prunes the feature's
137
+ * `sessions/` directory down to `MAX_RETAINED_TRANSCRIPTS` (ADR-028 section 3).
138
+ */
139
+ export declare function closeNativeSession(handle: SessionHandle, failed?: boolean): Promise<void>;