@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,60 @@
1
+ /**
2
+ * The credential store, and the one place that reads its file directly.
3
+ *
4
+ * This directory is the only place in src/ permitted to import nax-ai
5
+ * (packages/repo-tooling/scripts/check-nax-ai-imports.ts).
6
+ *
7
+ * The store is memoised like client.ts's client: createFileCredentialStore
8
+ * holds a cross-process lock, and two instances over one path would each take
9
+ * it, turning a read-modify-write into a contended wait for no reason.
10
+ *
11
+ * US-004 assembles the chain the run reads through — the change guard (US-002)
12
+ * around the chained store (exec helper first, file second) — and exports
13
+ * `servedAuth` so a cost row can name the account a call was billed to. Its
14
+ * callers (client.ts:84, auth.ts:121/:204/:238) are synchronous and
15
+ * the configured auth reader is async, so the chain is built on the first
16
+ * read/modify/delete and reused for the rest of the process.
17
+ */
18
+ import { type ProviderId } from "@nathapp/nax-ai";
19
+ import type { AuthStamp } from "#src/session/session-types";
20
+ import { type GuardedCredentialStore } from "./change-guard.ts";
21
+ export type { GuardedCredentialStore } from "./change-guard.ts";
22
+ /** One credential's public facts. Deliberately carries no key. */
23
+ export interface StoredEntry {
24
+ providerId: string;
25
+ kind: "api-key" | "oauth";
26
+ expires?: number;
27
+ }
28
+ export declare function credentialFilePath(): string;
29
+ export declare function naxCredentialStore(): GuardedCredentialStore;
30
+ /**
31
+ * Clears the memo. Tests only. Dropping it drops the assembled chain with it —
32
+ * the guard, its exec source and the file store it wraps — and the salt memo
33
+ * the fingerprints are keyed by.
34
+ */
35
+ export declare function _resetCredentialStore(): void;
36
+ /**
37
+ * What the memoised store last observed for `providerId` — the identity a
38
+ * successful call was billed to. `undefined` until that provider has been read.
39
+ */
40
+ export declare function servedAuth(providerId: ProviderId): AuthStamp | undefined;
41
+ /**
42
+ * Is the run configured to take credentials from an exec helper?
43
+ *
44
+ * Asked by `NativeAgentAdapter.hasCredentials`, which cannot list a helper's
45
+ * providers: with `auth.source: "exec"` an empty credential file must not be
46
+ * read as "no credentials", and asking the helper there would spawn it before
47
+ * the run has any reason to. Read straight from the global config rather than
48
+ * from the store's assembly, because this is answered before the store is ever
49
+ * read.
50
+ */
51
+ export declare function authSourceIsExec(): Promise<boolean>;
52
+ /**
53
+ * Enumerate the store by reading its file.
54
+ *
55
+ * CredentialStore is read/modify/delete by design and has no list, and this is
56
+ * the only consumer that needs one. A parse failure throws rather than
57
+ * reporting an empty store: reporting empty would look exactly like "you have
58
+ * no credentials" for a file that is merely damaged.
59
+ */
60
+ export declare function readStoredEntries(): Promise<StoredEntry[]>;
@@ -0,0 +1,184 @@
1
+ /**
2
+ * The credential store, and the one place that reads its file directly.
3
+ *
4
+ * This directory is the only place in src/ permitted to import nax-ai
5
+ * (packages/repo-tooling/scripts/check-nax-ai-imports.ts).
6
+ *
7
+ * The store is memoised like client.ts's client: createFileCredentialStore
8
+ * holds a cross-process lock, and two instances over one path would each take
9
+ * it, turning a read-modify-write into a contended wait for no reason.
10
+ *
11
+ * US-004 assembles the chain the run reads through — the change guard (US-002)
12
+ * around the chained store (exec helper first, file second) — and exports
13
+ * `servedAuth` so a cost row can name the account a call was billed to. Its
14
+ * callers (client.ts:84, auth.ts:121/:204/:238) are synchronous and
15
+ * the configured auth reader is async, so the chain is built on the first
16
+ * read/modify/delete and reused for the rest of the process.
17
+ */
18
+ import { readFile } from "node:fs/promises";
19
+ import { join } from "node:path";
20
+ import { createFileCredentialStore } from "@nathapp/nax-ai";
21
+ import { credentialsConfig, NaxError } from "#src/infra/index";
22
+ import { createChainedCredentialStore } from "./chained-store.js";
23
+ import { createChangeGuard } from "./change-guard.js";
24
+ import { createExecCredentialSource } from "./exec-source.js";
25
+ import { _resetFingerprintSalt } from "./fingerprint.js";
26
+ export function credentialFilePath() {
27
+ return join(credentialsConfig().configDir(), "credentials");
28
+ }
29
+ /**
30
+ * Build the chain from the global auth config: a chained store either around
31
+ * the exec helper (when `auth.source` is "exec") or around the file store
32
+ * alone, wrapped in the change guard the run reports and refuses through.
33
+ *
34
+ * The guard's `describe` reports what the chain decided — which source served
35
+ * the provider and, for a helper lease, the account label that source reported.
36
+ * The account travels beside `read`, not through it: `StoredCredential` has no
37
+ * field for it.
38
+ */
39
+ async function assembleStore() {
40
+ const file = createFileCredentialStore({ path: credentialFilePath() });
41
+ const auth = await credentialsConfig().readAuthConfig();
42
+ const exec = auth.source === "exec" && auth.exec !== undefined
43
+ ? createExecCredentialSource({ command: auth.exec.command, timeoutMs: auth.exec.timeoutMs })
44
+ : undefined;
45
+ const chained = createChainedCredentialStore(exec === undefined ? { file } : { exec, file });
46
+ return createChangeGuard(chained, {
47
+ onChange: auth.onChange,
48
+ describe: (providerId) => {
49
+ const source = chained.sourceOf(providerId);
50
+ if (source === undefined)
51
+ return undefined;
52
+ const account = chained.accountOf(providerId);
53
+ return account === undefined ? { source } : { source, account };
54
+ },
55
+ });
56
+ }
57
+ /**
58
+ * The store handed out by `naxCredentialStore()`, with its chain deferred.
59
+ *
60
+ * Deferred because the factory must be synchronous, and kept once built because
61
+ * the exec source holds leases and the file store holds a cross-process lock: a
62
+ * `config.json` rewritten in the same directory is not re-read until
63
+ * `_resetCredentialStore()`.
64
+ */
65
+ function lazyStore() {
66
+ let inner;
67
+ let pending;
68
+ function resolved() {
69
+ if (inner !== undefined)
70
+ return Promise.resolve(inner);
71
+ if (pending === undefined) {
72
+ // Dropped on failure, like a failed catalog build in client.ts: a
73
+ // transient read must not poison every later call in the process. `inner`
74
+ // is what `servedAuth` reads, so it is set as soon as the chain exists.
75
+ pending = assembleStore()
76
+ .then((guard) => {
77
+ inner = guard;
78
+ return guard;
79
+ })
80
+ .catch((err) => {
81
+ pending = undefined;
82
+ throw err;
83
+ });
84
+ }
85
+ return pending;
86
+ }
87
+ return {
88
+ read: async (providerId) => (await resolved()).read(providerId),
89
+ modify: async (providerId, fn) => (await resolved()).modify(providerId, fn),
90
+ delete: async (providerId) => (await resolved()).delete(providerId),
91
+ // Synchronous by contract, and there is nothing to report until the chain
92
+ // has built itself — which only a read, modify or delete does.
93
+ servedAuth: (providerId) => inner?.servedAuth(providerId),
94
+ };
95
+ }
96
+ /**
97
+ * The store the run reads credentials through, keyed per credential-file path
98
+ * and global config path: a store pinned to a stale path would write outside
99
+ * the temp dir a test isolated it into.
100
+ */
101
+ let memo;
102
+ function storeKey() {
103
+ const dir = credentialsConfig().configDir();
104
+ return `${join(dir, "credentials")}\u0000${join(dir, "config.json")}`;
105
+ }
106
+ export function naxCredentialStore() {
107
+ const key = storeKey();
108
+ if (memo === undefined || memo.key !== key) {
109
+ memo = { key, store: lazyStore() };
110
+ }
111
+ return memo.store;
112
+ }
113
+ /**
114
+ * Clears the memo. Tests only. Dropping it drops the assembled chain with it —
115
+ * the guard, its exec source and the file store it wraps — and the salt memo
116
+ * the fingerprints are keyed by.
117
+ */
118
+ export function _resetCredentialStore() {
119
+ memo = undefined;
120
+ _resetFingerprintSalt();
121
+ }
122
+ /**
123
+ * What the memoised store last observed for `providerId` — the identity a
124
+ * successful call was billed to. `undefined` until that provider has been read.
125
+ */
126
+ export function servedAuth(providerId) {
127
+ return naxCredentialStore().servedAuth(providerId);
128
+ }
129
+ /**
130
+ * Is the run configured to take credentials from an exec helper?
131
+ *
132
+ * Asked by `NativeAgentAdapter.hasCredentials`, which cannot list a helper's
133
+ * providers: with `auth.source: "exec"` an empty credential file must not be
134
+ * read as "no credentials", and asking the helper there would spawn it before
135
+ * the run has any reason to. Read straight from the global config rather than
136
+ * from the store's assembly, because this is answered before the store is ever
137
+ * read.
138
+ */
139
+ export async function authSourceIsExec() {
140
+ return (await credentialsConfig().readAuthConfig()).source === "exec";
141
+ }
142
+ /**
143
+ * Enumerate the store by reading its file.
144
+ *
145
+ * CredentialStore is read/modify/delete by design and has no list, and this is
146
+ * the only consumer that needs one. A parse failure throws rather than
147
+ * reporting an empty store: reporting empty would look exactly like "you have
148
+ * no credentials" for a file that is merely damaged.
149
+ */
150
+ export async function readStoredEntries() {
151
+ const path = credentialFilePath();
152
+ let raw;
153
+ try {
154
+ raw = await readFile(path, "utf8");
155
+ }
156
+ catch (error) {
157
+ if (error.code === "ENOENT")
158
+ return [];
159
+ throw error;
160
+ }
161
+ let parsed;
162
+ try {
163
+ parsed = JSON.parse(raw);
164
+ }
165
+ catch {
166
+ throw new NaxError(`The credential file at ${path} could not be parsed. Refusing to read it.`, "CREDENTIAL_FILE_UNREADABLE", { stage: "credentials", path });
167
+ }
168
+ const credentials = parsed?.credentials;
169
+ if (credentials === undefined ||
170
+ credentials === null ||
171
+ typeof credentials !== "object" ||
172
+ Array.isArray(credentials)) {
173
+ throw new NaxError(`The credential file at ${path} could not be parsed as a credential store.`, "CREDENTIAL_FILE_UNREADABLE", { stage: "credentials", path });
174
+ }
175
+ return Object.entries(credentials)
176
+ .map(([providerId, value]) => {
177
+ const kind = value?.kind === "oauth" ? "oauth" : "api-key";
178
+ const entry = { providerId, kind };
179
+ if (kind === "oauth" && typeof value?.expires === "number")
180
+ entry.expires = value.expires;
181
+ return entry;
182
+ })
183
+ .sort((a, b) => (a.providerId < b.providerId ? -1 : a.providerId > b.providerId ? 1 : 0));
184
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * nax-ai's typed error kinds mapped to nax's failure taxonomy.
3
+ *
4
+ * nax-ai returns a discriminated kind, so nothing here parses a message. The
5
+ * acpx path has to (parseAgentError); this one must not start.
6
+ *
7
+ * `category` is an observability tag only: swap behaviour comes from
8
+ * `failurePolicyFor(outcome)` in `src/agents/retry/failure-policy.ts`, which
9
+ * keys on `outcome` and never reads `category`. A kind filed under "quality" is
10
+ * not automatically terminal for the op — `decideSwap` consults the policy table.
11
+ */
12
+ import { NaxError } from "#src/infra/index";
13
+ import type { AdapterFailure } from "#src/session/adapter-failure";
14
+ /** Finds a known credential-store fault without following an unbounded cause chain. */
15
+ export declare function credentialFaultCode(protocolError: NativeProtocolError): string | undefined;
16
+ /** The shape this module reads off a nax-ai protocol fault. Structural, never the class. */
17
+ export interface NativeProtocolError {
18
+ readonly kind: string;
19
+ /** Seconds, when the provider signalled one. */
20
+ readonly retryAfter?: number;
21
+ readonly cause?: unknown;
22
+ }
23
+ /**
24
+ * An unrecognised kind degrades to unknown rather than throwing: a new nax-ai
25
+ * kind should downgrade one call, not crash the run.
26
+ *
27
+ * Takes the whole protocol error, not the bare kind: `retryAfter` is the
28
+ * provider's own recovery time and the retry layers need it. FAILURES is a
29
+ * frozen shared table, so the entry is copied rather than assigned onto.
30
+ */
31
+ export declare function toAdapterFailure(protocolError: NativeProtocolError): AdapterFailure;
32
+ export declare class NativeSessionUnsupportedError extends NaxError {
33
+ constructor(method: string);
34
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * nax-ai's typed error kinds mapped to nax's failure taxonomy.
3
+ *
4
+ * nax-ai returns a discriminated kind, so nothing here parses a message. The
5
+ * acpx path has to (parseAgentError); this one must not start.
6
+ *
7
+ * `category` is an observability tag only: swap behaviour comes from
8
+ * `failurePolicyFor(outcome)` in `src/agents/retry/failure-policy.ts`, which
9
+ * keys on `outcome` and never reads `category`. A kind filed under "quality" is
10
+ * not automatically terminal for the op — `decideSwap` consults the policy table.
11
+ */
12
+ import { NaxError } from "#src/infra/index";
13
+ const FAILURES = Object.freeze({
14
+ "rate-limit": {
15
+ message: "nax-ai rate limit exceeded",
16
+ category: "availability",
17
+ outcome: "fail-rate-limit",
18
+ retriable: true,
19
+ },
20
+ auth: {
21
+ message: "nax-ai authentication failed",
22
+ category: "availability",
23
+ outcome: "fail-auth",
24
+ retriable: false,
25
+ },
26
+ overloaded: {
27
+ message: "nax-ai service overloaded",
28
+ category: "availability",
29
+ outcome: "fail-service-down",
30
+ retriable: true,
31
+ },
32
+ // nax-ai already retried transport faults before the first event. Reaching
33
+ // here means the retries were exhausted, so the service is unreachable.
34
+ transport: {
35
+ message: "nax-ai transport retries exhausted; service unreachable",
36
+ category: "availability",
37
+ outcome: "fail-service-down",
38
+ retriable: true,
39
+ },
40
+ // Our request is malformed. A different agent would build the same one.
41
+ "bad-request": {
42
+ message: "request malformed; another agent would build the same one",
43
+ category: "quality",
44
+ outcome: "fail-adapter-error",
45
+ retriable: false,
46
+ },
47
+ // The prompt outgrew the model's window. Filed as "availability" on purpose,
48
+ // even though nothing is down: the request was well-formed, and the thing
49
+ // that could not serve it is this model's window. Another agent's window may
50
+ // be larger, so the swap is worth attempting -- which "quality" would refuse.
51
+ // Not retriable: the same agent would rebuild the same oversized request.
52
+ // Until the native turn loop can compact (nax#1832), the swap is the only
53
+ // recovery there is.
54
+ "context-overflow": {
55
+ message: "prompt exceeded the model's context window; another agent's window may be larger",
56
+ category: "availability",
57
+ outcome: "fail-adapter-error",
58
+ retriable: false,
59
+ },
60
+ unknown: {
61
+ message: "unrecognised nax-ai error kind",
62
+ category: "quality",
63
+ outcome: "fail-unknown",
64
+ retriable: false,
65
+ },
66
+ });
67
+ const UNKNOWN = FAILURES.unknown;
68
+ const CREDENTIAL_FAULT_CODES = new Set([
69
+ "CREDENTIAL_HELPER_FAILED",
70
+ "CREDENTIAL_HELPER_INVALID",
71
+ "CREDENTIAL_CHANGED",
72
+ "CREDENTIAL_FILE_UNREADABLE",
73
+ ]);
74
+ const MAX_CREDENTIAL_CAUSE_LINKS = 8;
75
+ /** Finds a known credential-store fault without following an unbounded cause chain. */
76
+ export function credentialFaultCode(protocolError) {
77
+ let current = protocolError.cause;
78
+ const seen = new Set();
79
+ for (let link = 0; link < MAX_CREDENTIAL_CAUSE_LINKS; link += 1) {
80
+ if (typeof current !== "object" || current === null || seen.has(current))
81
+ return undefined;
82
+ seen.add(current);
83
+ if (current instanceof NaxError && CREDENTIAL_FAULT_CODES.has(current.code))
84
+ return current.code;
85
+ current = "cause" in current ? current.cause : undefined;
86
+ }
87
+ return undefined;
88
+ }
89
+ /**
90
+ * An unrecognised kind degrades to unknown rather than throwing: a new nax-ai
91
+ * kind should downgrade one call, not crash the run.
92
+ *
93
+ * Takes the whole protocol error, not the bare kind: `retryAfter` is the
94
+ * provider's own recovery time and the retry layers need it. FAILURES is a
95
+ * frozen shared table, so the entry is copied rather than assigned onto.
96
+ */
97
+ export function toAdapterFailure(protocolError) {
98
+ const credentialCode = credentialFaultCode(protocolError);
99
+ const base = credentialCode === undefined
100
+ ? (FAILURES[protocolError.kind] ?? UNKNOWN)
101
+ : { ...FAILURES.auth, message: `Credential authentication failed: ${credentialCode}` };
102
+ return protocolError.retryAfter === undefined ? base : { ...base, retryAfterSeconds: protocolError.retryAfter };
103
+ }
104
+ export class NativeSessionUnsupportedError extends NaxError {
105
+ constructor(method) {
106
+ super(`The native agent cannot ${method}: it is one-shot until Phase B adds session support. Use an acpx agent for session work.`, "NATIVE_SESSION_UNSUPPORTED", { stage: "session", method });
107
+ this.name = "NativeSessionUnsupportedError";
108
+ }
109
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The native LLM path: nax's own client, in-process, over @nathapp/nax-ai.
3
+ *
4
+ * This directory is the only place in src/ permitted to import nax-ai
5
+ * (packages/repo-tooling/scripts/check-nax-ai-imports.ts). nax composes it into its AgentAdapter in
6
+ * `src/agents/native-agent/`, so the wire library stays replaceable.
7
+ *
8
+ * The barrel re-exports only; it owns no values. NATIVE_AGENT lives in
9
+ * models.ts (a leaf) so session-adapter.ts can import it without a cycle back
10
+ * through this file — `check:import-cycles` runs against a baseline and a new
11
+ * cycle fails it.
12
+ */
13
+ export { _adapterDeps } from "./adapter-deps.ts";
14
+ export { AuthCancelledError, ambientShadows, anyAmbientCredential, authImportOutcomeLabel, DEFAULT_PI_AUTH_PATH, type ImportOutcome, importPiCredentials, listStoredProviders, providersWithoutCredentials, removeStoredProvider, runLogin, } from "./auth.ts";
15
+ export type { AuthEvent, AuthInteraction, AuthLink, AuthMethod, AuthOption, AuthPrompt, AuthResult, } from "./auth-types.ts";
16
+ export type { NativeCatalogOverrides } from "./client.ts";
17
+ export { type NativeCompleteContext, type NativeCompleteOptions, type NativeCompleteResult, nativeComplete, } from "./complete.ts";
18
+ export { credentialFilePath, naxCredentialStore, type StoredEntry, servedAuth } from "./credentials/index.ts";
19
+ export { NativeSessionUnsupportedError } from "./errors.ts";
20
+ export { type ResolveResult, type ResolveStatus, resolveNativeId, } from "./model-resolver.ts";
21
+ export { NATIVE_AGENT } from "./models.ts";
22
+ export { MAX_RETAINED_TRANSCRIPTS, pruneRetainedTranscripts, } from "./session/transcript-store.ts";
23
+ export { NativeSessionAdapter } from "./session-adapter.ts";
24
+ export { newSessionKey } from "./session-affinity.ts";
25
+ export { type NativeTierConfig, nativeTierProviders } from "./tier-providers.ts";
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The native LLM path: nax's own client, in-process, over @nathapp/nax-ai.
3
+ *
4
+ * This directory is the only place in src/ permitted to import nax-ai
5
+ * (packages/repo-tooling/scripts/check-nax-ai-imports.ts). nax composes it into its AgentAdapter in
6
+ * `src/agents/native-agent/`, so the wire library stays replaceable.
7
+ *
8
+ * The barrel re-exports only; it owns no values. NATIVE_AGENT lives in
9
+ * models.ts (a leaf) so session-adapter.ts can import it without a cycle back
10
+ * through this file — `check:import-cycles` runs against a baseline and a new
11
+ * cycle fails it.
12
+ */
13
+ export { _adapterDeps } from "./adapter-deps.js";
14
+ export { AuthCancelledError, ambientShadows, anyAmbientCredential, authImportOutcomeLabel, DEFAULT_PI_AUTH_PATH, importPiCredentials, listStoredProviders, providersWithoutCredentials, removeStoredProvider, runLogin, } from "./auth.js";
15
+ export { nativeComplete, } from "./complete.js";
16
+ export { credentialFilePath, naxCredentialStore, servedAuth } from "./credentials/index.js";
17
+ export { NativeSessionUnsupportedError } from "./errors.js";
18
+ export { resolveNativeId, } from "./model-resolver.js";
19
+ export { NATIVE_AGENT } from "./models.js";
20
+ export { MAX_RETAINED_TRANSCRIPTS, pruneRetainedTranscripts, } from "./session/transcript-store.js";
21
+ export { NativeSessionAdapter } from "./session-adapter.js";
22
+ export { newSessionKey } from "./session-affinity.js";
23
+ export { nativeTierProviders } from "./tier-providers.js";
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Native model resolver — owns the local catalog lookup for native ids.
3
+ *
4
+ * Precheck must not import nax-ai directly (packages/repo-tooling/scripts/check-nax-ai-imports.ts),
5
+ * so the resolver sits next to the rest of the native path. Production callers
6
+ * go through `resolveNativeId` (which uses the cached nax-ai client); tests
7
+ * bypass the function entirely and stub `_modelResolutionDeps` in
8
+ * `src/precheck/checks-model-resolution.ts` to drive specific outcomes without
9
+ * loading the bundled catalog.
10
+ *
11
+ * Three states the resolver reports:
12
+ * - "resolved": id resolves in the catalog (optionally with override data)
13
+ * - "unresolved": id is provider-qualified but absent from the catalog and
14
+ * not declared under agent.native.catalogOverrides
15
+ * - "error": the catalog itself failed to load (network, schema, …)
16
+ *
17
+ * The third state is a warning, not a blocker — a transient catalog miss
18
+ * should not stop a run, but it must be surfaced loudly enough to prevent the
19
+ * adversarial-review parse error the story exists to fix.
20
+ */
21
+ import type { ProviderCatalogOverride } from "#src/config/catalog-overrides";
22
+ export type ResolveStatus = "resolved" | "unresolved" | "error";
23
+ export interface ResolveResult {
24
+ status: ResolveStatus;
25
+ /**
26
+ * When `status === "resolved"` and the matched entry declared pricing /
27
+ * contextWindow, the resolved values. The precheck check uses the PRESENCE
28
+ * of these fields to decide whether a literal pin dropped tier-configured
29
+ * overrides — the actual numbers do not need to flow through.
30
+ */
31
+ hasPricing?: boolean;
32
+ hasContextWindow?: boolean;
33
+ }
34
+ /**
35
+ * Production resolver. Builds the cached client once per override set, then
36
+ * calls `client.model(provider, model)` for every native id the precheck
37
+ * walker hands it. The bundled catalog loads once per process via
38
+ * `getNativeClient` (cached) so repeated calls amortise to a single load.
39
+ *
40
+ * Status mapping:
41
+ * - "resolved": id resolves from the override-aware `client.model()` call
42
+ * - "error": `getNativeClient(overrides)` rejected (catalog load
43
+ * failed — network, schema, …). AC6 requires the check
44
+ * to surface this as a warning, not a blocker, because
45
+ * a transient catalog miss should not stop a run.
46
+ * - "unresolved": client built successfully but `client.model()` rejected
47
+ * for this (provider, model) pair — id absent from the
48
+ * catalog. The check emits a blocker at that site
49
+ * (AC1/AC2), because the bundled snapshot not knowing
50
+ * an id is the failure mode `nax#1983` exists to catch.
51
+ *
52
+ * The two catch arms are split so the resolver honours the AC6 contract;
53
+ * a single `try { … } catch { "unresolved" }` would collapse the catalog
54
+ * load failure into a per-id blocker and leave the "error" handlers in
55
+ * `checkModelResolution` permanently dead code.
56
+ */
57
+ export declare function resolveNativeId(provider: string, model: string, overrides: readonly ProviderCatalogOverride[]): Promise<ResolveResult>;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Native model resolver — owns the local catalog lookup for native ids.
3
+ *
4
+ * Precheck must not import nax-ai directly (packages/repo-tooling/scripts/check-nax-ai-imports.ts),
5
+ * so the resolver sits next to the rest of the native path. Production callers
6
+ * go through `resolveNativeId` (which uses the cached nax-ai client); tests
7
+ * bypass the function entirely and stub `_modelResolutionDeps` in
8
+ * `src/precheck/checks-model-resolution.ts` to drive specific outcomes without
9
+ * loading the bundled catalog.
10
+ *
11
+ * Three states the resolver reports:
12
+ * - "resolved": id resolves in the catalog (optionally with override data)
13
+ * - "unresolved": id is provider-qualified but absent from the catalog and
14
+ * not declared under agent.native.catalogOverrides
15
+ * - "error": the catalog itself failed to load (network, schema, …)
16
+ *
17
+ * The third state is a warning, not a blocker — a transient catalog miss
18
+ * should not stop a run, but it must be surfaced loudly enough to prevent the
19
+ * adversarial-review parse error the story exists to fix.
20
+ */
21
+ import { getNativeClient } from "./client.js";
22
+ /**
23
+ * Production resolver. Builds the cached client once per override set, then
24
+ * calls `client.model(provider, model)` for every native id the precheck
25
+ * walker hands it. The bundled catalog loads once per process via
26
+ * `getNativeClient` (cached) so repeated calls amortise to a single load.
27
+ *
28
+ * Status mapping:
29
+ * - "resolved": id resolves from the override-aware `client.model()` call
30
+ * - "error": `getNativeClient(overrides)` rejected (catalog load
31
+ * failed — network, schema, …). AC6 requires the check
32
+ * to surface this as a warning, not a blocker, because
33
+ * a transient catalog miss should not stop a run.
34
+ * - "unresolved": client built successfully but `client.model()` rejected
35
+ * for this (provider, model) pair — id absent from the
36
+ * catalog. The check emits a blocker at that site
37
+ * (AC1/AC2), because the bundled snapshot not knowing
38
+ * an id is the failure mode `nax#1983` exists to catch.
39
+ *
40
+ * The two catch arms are split so the resolver honours the AC6 contract;
41
+ * a single `try { … } catch { "unresolved" }` would collapse the catalog
42
+ * load failure into a per-id blocker and leave the "error" handlers in
43
+ * `checkModelResolution` permanently dead code.
44
+ */
45
+ export async function resolveNativeId(provider, model, overrides) {
46
+ // The native client's `Client` type comes from nax-ai; we declare the
47
+ // variable as `unknown` to keep the file free of nax-ai type imports
48
+ // (packages/repo-tooling/scripts/check-nax-ai-imports.ts forbids it). The single property we
49
+ // touch (`model(provider, model)`) is what we actually need.
50
+ let client;
51
+ try {
52
+ // Catalog load failure — the bundled snapshot itself is unavailable
53
+ // (network, schema mismatch, …). Distinct from "id not in catalog":
54
+ // the resolver never got far enough to look anything up.
55
+ client = await getNativeClient(overrides);
56
+ }
57
+ catch {
58
+ return { status: "error" };
59
+ }
60
+ try {
61
+ const resolved = await client.model(provider, model);
62
+ return {
63
+ status: "resolved",
64
+ hasPricing: resolved.pricing !== undefined,
65
+ hasContextWindow: resolved.contextWindow !== undefined,
66
+ };
67
+ }
68
+ catch {
69
+ // Client built successfully but this (provider, model) is not in the
70
+ // catalog. Per AC1/AC2 the check emits a blocker at this site.
71
+ return { status: "unresolved" };
72
+ }
73
+ }