@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,185 @@
1
+ /**
2
+ * P5 command-safety shadow: shared types.
3
+ *
4
+ * Spec: docs/superpowers/specs/2026-09-23-p5-command-safety-shadow-design.md.
5
+ * Observational only — except for the optional flag-for-review guard (US-003),
6
+ * which is also declared here: the shadow's row is a fact on disk, the
7
+ * guard's decision is a flag the caller routes. Nothing else typed here can
8
+ * change a verdict, delay a call or fail a call; the types exist so the row
9
+ * a later decision reads is exact.
10
+ */
11
+ import type { CallIdentifiers } from "./identifiers.ts";
12
+ /** The six harm categories. Also the ids of the six `noul` questions. */
13
+ export declare const QUESTION_IDS: readonly ["deletes_data", "discards_work", "outside_project", "system_change", "network_send", "privilege"];
14
+ export type QuestionId = (typeof QUESTION_IDS)[number];
15
+ /** Options of the single `harm` choice question: `none` plus every category. */
16
+ export declare const HARM_OPTIONS: readonly ["none", "deletes_data", "discards_work", "outside_project", "system_change", "network_send", "privilege"];
17
+ export type HarmOption = (typeof HARM_OPTIONS)[number];
18
+ /** The mechanical policy verdict, as recorded (never re-decided) by the shadow. */
19
+ export interface MechanicalVerdict {
20
+ readonly verdict: "allow" | "ask" | "deny";
21
+ readonly breach: boolean;
22
+ readonly rule?: string;
23
+ }
24
+ /** The tool-audit ledger outcome of the call. */
25
+ export type LedgerOutcome = "ok" | "error" | "denied" | "denied:ask";
26
+ export interface FinalOutcome {
27
+ readonly ledger: LedgerOutcome;
28
+ readonly decidedBy?: string;
29
+ }
30
+ export interface ModelAnswers {
31
+ /** P(option) for the harm choice. */
32
+ readonly harm: Readonly<Record<HarmOption, number>>;
33
+ /** P(yes) per noul question. */
34
+ readonly noul: Readonly<Record<QuestionId, number>>;
35
+ }
36
+ export type ModelResult = {
37
+ readonly status: "answered";
38
+ readonly answers: ModelAnswers;
39
+ readonly model?: string;
40
+ readonly decisionId?: string;
41
+ readonly latencyMs: number;
42
+ } | {
43
+ readonly status: "blocked";
44
+ readonly decisionId?: string;
45
+ readonly latencyMs: number;
46
+ } | {
47
+ readonly status: "oversize";
48
+ readonly latencyMs: number;
49
+ } | {
50
+ readonly status: "unavailable";
51
+ readonly error: string;
52
+ readonly latencyMs?: number;
53
+ };
54
+ /** One agent-authored command, as observed right after `policy.check`. */
55
+ export interface Observation extends CallIdentifiers {
56
+ readonly command: string;
57
+ readonly identity: "Bash" | "Exec";
58
+ /** Exec only: the argv verbatim. `command` is it joined with single spaces. */
59
+ readonly argv?: readonly string[];
60
+ readonly stage: string;
61
+ readonly storyId?: string;
62
+ readonly mechanical: MechanicalVerdict;
63
+ /**
64
+ * Bash only: the directory the command starts in (the policy root). An
65
+ * Exec call's cwd is chosen by the tool, so it arrives with `ExecRun`.
66
+ */
67
+ readonly cwd?: string;
68
+ }
69
+ /** Exec only: what the tool actually ran, known once it has run. */
70
+ export interface ExecRun {
71
+ /** The argv after normalization. */
72
+ readonly executed: readonly string[];
73
+ /**
74
+ * The directory it ran in (the package dir or the repo root). The Exec
75
+ * branch always sets it; optional because `audit` is shared with tools
76
+ * (Bash, Git) that report `executed` without a cwd.
77
+ */
78
+ readonly cwd?: string;
79
+ }
80
+ /** Per-story shadow. Every method is total: it never throws. */
81
+ export interface CommandShadow {
82
+ observe(key: string, obs: Observation): void;
83
+ /**
84
+ * Attach the ledger outcome and, for an Exec call, what actually ran. `run`
85
+ * is omitted for every other identity and whenever the call never ran.
86
+ */
87
+ settle(key: string, outcome: FinalOutcome, run?: ExecRun): void;
88
+ /** Resolves within one timeout; afterwards every pending row has been written. */
89
+ drain(): Promise<void>;
90
+ /**
91
+ * Opt-in flag-for-review guard (US-003). When present, `assess` shares the
92
+ * shadow's rule baseline and classifier cache — the guard never
93
+ * re-classifies and never rejects, so absence is the safe default.
94
+ */
95
+ readonly guard?: CommandGuard;
96
+ }
97
+ /** The guard's total assessment input. Mirrors `Observation` minus the fields the guard does not need. */
98
+ export interface GuardInput {
99
+ /** The policy identity's command string; Exec passes `argv.join(" ")`. */
100
+ readonly command: string;
101
+ /** The policy root, used to score the rules and judge the temp-only exemption. */
102
+ readonly cwd?: string;
103
+ /** The session's sandbox confines temp writes (#2285). */
104
+ readonly tempConfined: boolean;
105
+ }
106
+ /** A flagged command: what the guard wants reviewed, and why. */
107
+ export interface GuardDecision {
108
+ readonly flagged: boolean;
109
+ /** 0..1, the composite score behind the flag. */
110
+ readonly score: number;
111
+ /** The threshold the guard was configured with. Carried on every decision. */
112
+ readonly threshold: number;
113
+ /** Which contributor named the verdict. */
114
+ readonly basis: "model" | "rules" | "temp-only";
115
+ /**
116
+ * The dominant category behind the flag, when one is known.
117
+ *
118
+ * Absent for an unflagged decision and for a `blocked` model with no rule
119
+ * hit. Under the temp-only exemption, `outside_project` is skipped even
120
+ * when the rules alone would have named it.
121
+ */
122
+ readonly category?: QuestionId;
123
+ }
124
+ /**
125
+ * The guard exposes only the total assessment the shadow shares. It never
126
+ * rejects: every method resolves; nothing here can stop a command on its
127
+ * own (master plan D4a).
128
+ */
129
+ export interface CommandGuard {
130
+ readonly threshold: number;
131
+ /** Total: never rejects. */
132
+ assess(input: GuardInput): Promise<GuardDecision>;
133
+ }
134
+ export interface RuleResult {
135
+ readonly version: number;
136
+ readonly hits: Readonly<Record<QuestionId, boolean>>;
137
+ readonly error?: string;
138
+ }
139
+ /** One line of `<outputDir>/command-safety/<runId>.jsonl` (spec 7.3). */
140
+ export interface CommandSafetyRow extends CallIdentifiers {
141
+ readonly at: string;
142
+ readonly runId: string;
143
+ readonly storyId?: string;
144
+ readonly stage: string;
145
+ readonly identity: "Bash" | "Exec";
146
+ readonly command: string;
147
+ readonly argv?: readonly string[];
148
+ /**
149
+ * Exec only: the argv the Exec tool executed (after normalization); absent
150
+ * when the call did not run. Distinct from `argv`, which is the model's
151
+ * requested argv — and the text `command` is classified on.
152
+ */
153
+ readonly executed?: readonly string[];
154
+ /**
155
+ * The directory the command starts in: the policy root for Bash, the
156
+ * directory the tool ran it in for Exec (absent when it did not run).
157
+ * Recorded for labelling only; it is not part of the model's state.
158
+ */
159
+ readonly cwd?: string;
160
+ readonly mechanical: MechanicalVerdict;
161
+ readonly outcome: {
162
+ readonly ledger: LedgerOutcome | "unsettled";
163
+ readonly decidedBy?: string;
164
+ };
165
+ readonly rules: RuleResult;
166
+ /**
167
+ * Observable, never-decided signals recorded beside the row (US-005).
168
+ * `tmpWrite` is true when the command writes to a literal `/tmp` or
169
+ * `/private/tmp` path outside nax's own `/tmp/nax-*` run directories. It is
170
+ * recorded only: not a `QuestionId`, not in `rules.hits`, and it changes no
171
+ * verdict.
172
+ */
173
+ readonly signals: {
174
+ readonly tmpWrite: boolean;
175
+ };
176
+ readonly model: {
177
+ readonly status: ModelResult["status"] | "cached";
178
+ readonly questionSetVersion: number;
179
+ readonly answers?: ModelAnswers;
180
+ readonly model?: string;
181
+ readonly decisionId?: string;
182
+ readonly latencyMs?: number;
183
+ readonly error?: string;
184
+ };
185
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * P5 command-safety shadow: shared types.
3
+ *
4
+ * Spec: docs/superpowers/specs/2026-09-23-p5-command-safety-shadow-design.md.
5
+ * Observational only — except for the optional flag-for-review guard (US-003),
6
+ * which is also declared here: the shadow's row is a fact on disk, the
7
+ * guard's decision is a flag the caller routes. Nothing else typed here can
8
+ * change a verdict, delay a call or fail a call; the types exist so the row
9
+ * a later decision reads is exact.
10
+ */
11
+ /** The six harm categories. Also the ids of the six `noul` questions. */
12
+ export const QUESTION_IDS = [
13
+ "deletes_data",
14
+ "discards_work",
15
+ "outside_project",
16
+ "system_change",
17
+ "network_send",
18
+ "privilege",
19
+ ];
20
+ /** Options of the single `harm` choice question: `none` plus every category. */
21
+ export const HARM_OPTIONS = ["none", ...QUESTION_IDS];
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The `bashApproval` mode axis (ADR-030).
3
+ *
4
+ * Named `raw | gated | escalate` rather than `unrestricted | ...` on purpose:
5
+ * `unrestricted` already names a permission PROFILE
6
+ * (`src/config/permissions.ts:17`), and a mode value colliding with a profile
7
+ * name is a config foot-gun. Profiles answer "which tools is this stage
8
+ * granted"; the mode answers "how is a bash command string adjudicated".
9
+ */
10
+ import { z } from "zod";
11
+ export declare const BashApprovalModeSchema: z.ZodEnum<{
12
+ escalate: "escalate";
13
+ gated: "gated";
14
+ raw: "raw";
15
+ }>;
16
+ export type BashApprovalMode = z.infer<typeof BashApprovalModeSchema>;
17
+ /**
18
+ * BUG-20 — derived from the schema, never hand-written at a second site. The
19
+ * `execution` default literal in `schemas.ts` must reference THIS constant:
20
+ * zod does not re-parse a `.default()` value, so a literal there drifts from
21
+ * the field's own default the moment either changes.
22
+ */
23
+ export declare const DEFAULT_BASH_APPROVAL_MODE: BashApprovalMode;
24
+ /**
25
+ * `bashApprovalOps` (ADR-030): the named surface of mode resolution.
26
+ *
27
+ * Deliberately a pure function, not an async provider chain. The human
28
+ * resolver is the existing `AskResolver`, which the `ask` tier already reaches
29
+ * (`src/tools/runtime.ts:378`); a second chain would duplicate it. A future
30
+ * model-based classifier attaches at the POST-ALLOW seam in `runtime.ts`
31
+ * instead, narrowing allow → ask, which is a different insertion point.
32
+ */
33
+ export declare function resolveBashApproval(global: BashApprovalMode | undefined, perStage: BashApprovalMode | undefined): BashApprovalMode;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The `bashApproval` mode axis (ADR-030).
3
+ *
4
+ * Named `raw | gated | escalate` rather than `unrestricted | ...` on purpose:
5
+ * `unrestricted` already names a permission PROFILE
6
+ * (`src/config/permissions.ts:17`), and a mode value colliding with a profile
7
+ * name is a config foot-gun. Profiles answer "which tools is this stage
8
+ * granted"; the mode answers "how is a bash command string adjudicated".
9
+ */
10
+ import { z } from "zod";
11
+ export const BashApprovalModeSchema = z.enum(["raw", "gated", "escalate"]);
12
+ /**
13
+ * BUG-20 — derived from the schema, never hand-written at a second site. The
14
+ * `execution` default literal in `schemas.ts` must reference THIS constant:
15
+ * zod does not re-parse a `.default()` value, so a literal there drifts from
16
+ * the field's own default the moment either changes.
17
+ */
18
+ export const DEFAULT_BASH_APPROVAL_MODE = BashApprovalModeSchema.parse("raw");
19
+ /**
20
+ * `bashApprovalOps` (ADR-030): the named surface of mode resolution.
21
+ *
22
+ * Deliberately a pure function, not an async provider chain. The human
23
+ * resolver is the existing `AskResolver`, which the `ask` tier already reaches
24
+ * (`src/tools/runtime.ts:378`); a second chain would duplicate it. A future
25
+ * model-based classifier attaches at the POST-ALLOW seam in `runtime.ts`
26
+ * instead, narrowing allow → ask, which is a different insertion point.
27
+ */
28
+ export function resolveBashApproval(global, perStage) {
29
+ return perStage ?? global ?? DEFAULT_BASH_APPROVAL_MODE;
30
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Catalog-override and thinking-level types: the config shapes the native
3
+ * agent reads (S1 spec section 4.2, port 4). Pure types with no imports, so
4
+ * they move into nax-agent unchanged; `schema-types.ts` re-exports them for
5
+ * nax's config schema.
6
+ */
7
+ /**
8
+ * Reasoning levels the catalog may declare, mirrored from nax-ai's
9
+ * `ThinkingLevel` union (nax#1982). nax-ai cannot be imported here
10
+ * (`packages/repo-tooling/scripts/check-nax-ai-imports.ts`), so the union is hand-mirrored;
11
+ * `test/unit/agents/native/models.test.ts` pins it against
12
+ * `THINKING_LEVELS` in `src/agents/native/models.ts`, which is itself a
13
+ * compile-time-exhaustive `Record<ThinkingLevel, true>` over the nax-ai
14
+ * union.
15
+ */
16
+ export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
17
+ /**
18
+ * Rates for a catalog override, in the CATALOG's vocabulary (`input`,
19
+ * `output`, `cacheRead`, `cacheWrite`, per 1M tokens) — not `ConfigPricing`'s
20
+ * `*Per1M` names. This block describes the simulated catalog entry, so it
21
+ * speaks the catalog's language; `ModelDef.pricing` remains the cost-math
22
+ * override in nax's own vocabulary.
23
+ */
24
+ export interface CatalogPricing {
25
+ input: number;
26
+ output: number;
27
+ cacheRead: number;
28
+ cacheWrite: number;
29
+ }
30
+ /**
31
+ * nax#2191: OpenRouter-compatible provider routing, mirrored from nax-ai
32
+ * 0.1.15's `OpenRouterRouting`. Snake_case on purpose — keys are wire field
33
+ * names and pass through unmapped. The protocol-side rejection (non-
34
+ * `openai-completions` protocols, empty declaration) is nax-ai's, owned in
35
+ * `providers/override-model.ts`'s `assertOverrideModelRouting`.
36
+ *
37
+ * `sort: "latency"` / `"throughput"` pair with `quantizations` in the typical
38
+ * case: OpenRouter's default routing for a slug is overwhelmingly a single
39
+ * quantization from a single endpoint, and a sort change may otherwise pick
40
+ * a lower-precision endpoint that the call site never intended (the issue's
41
+ * own note). The schema does not enforce the pairing — that is UX clutter
42
+ * for an opt-in override — but `docs/guides/configuration.md` and the config
43
+ * description should call it out.
44
+ */
45
+ export interface OpenRouterRouting {
46
+ allow_fallbacks?: boolean;
47
+ require_parameters?: boolean;
48
+ data_collection?: "deny" | "allow";
49
+ zdr?: boolean;
50
+ order?: readonly string[];
51
+ only?: readonly string[];
52
+ ignore?: readonly string[];
53
+ quantizations?: readonly string[];
54
+ sort?: "price" | "throughput" | "latency";
55
+ }
56
+ /**
57
+ * One complete catalog entry for a model the bundled pi-ai snapshot does not
58
+ * know. Complete, not a patch: nax-ai's `normaliseCatalog` replaces any
59
+ * same-id entry wholesale and lazily creates the provider bucket, so nothing
60
+ * here may be left to the bundled value.
61
+ */
62
+ export interface CatalogModelOverride {
63
+ id: string;
64
+ /** nax-ai protocol id, e.g. "openai-completions" or "anthropic-messages". */
65
+ protocol: string;
66
+ contextWindow: number;
67
+ /**
68
+ * Output ceiling. Optional: when absent, nax-ai inherits the ceiling of the
69
+ * bundled sibling it synthesises the override from, which can be smaller
70
+ * than the newer model's real one (nax-ai 0.1.11, nax#1982).
71
+ */
72
+ maxTokens?: number;
73
+ supportsTools: boolean;
74
+ thinkingLevels: ThinkingLevel[];
75
+ pricing: CatalogPricing;
76
+ /**
77
+ * nax#2191: OpenRouter-compatible provider routing forwarded verbatim to
78
+ * nax-ai's `ResolvedModel.openRouterRouting`. Reaches the wire only on
79
+ * `protocol: "openai-completions"` (nax-ai `assertOverrideModelRouting`).
80
+ */
81
+ openRouterRouting?: OpenRouterRouting;
82
+ }
83
+ /** Provider-scoped catalog overrides — maps 1:1 onto nax-ai's `ProviderOverride[]`. */
84
+ export interface ProviderCatalogOverride {
85
+ provider: string;
86
+ /**
87
+ * Provider-wide endpoint redirect (nax#2019). Applies to the whole provider,
88
+ * not to `models` individually, despite sitting alongside a model list.
89
+ */
90
+ baseUrl?: string;
91
+ /** Provider-wide extra request headers (nax#2019). May carry credentials. */
92
+ headers?: Record<string, string>;
93
+ models: CatalogModelOverride[];
94
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Catalog-override and thinking-level types: the config shapes the native
3
+ * agent reads (S1 spec section 4.2, port 4). Pure types with no imports, so
4
+ * they move into nax-agent unchanged; `schema-types.ts` re-exports them for
5
+ * nax's config schema.
6
+ */
7
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The agent name that routes to the in-process native adapter.
3
+ *
4
+ * Its own nested barrel so the nax-agent move set can import the value
5
+ * (`@/config/native-agent`) without loading the config barrel (S1 spec
6
+ * section 4.2, port 4). `agent-defaults.ts` re-exports it for config.
7
+ */
8
+ export declare const NATIVE_AGENT_NAME = "native";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The agent name that routes to the in-process native adapter.
3
+ *
4
+ * Its own nested barrel so the nax-agent move set can import the value
5
+ * (`@/config/native-agent`) without loading the config barrel (S1 spec
6
+ * section 4.2, port 4). `agent-defaults.ts` re-exports it for config.
7
+ */
8
+ export const NATIVE_AGENT_NAME = "native";
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `execution.sandbox` (P4, ADR-030 amendment): the OS sandbox around
3
+ * agent-authored Bash and RunCommand Exec commands.
4
+ *
5
+ * Nested objects use `.prefault({})`, not `.default({})`: in zod 4 a
6
+ * `.default()` value short-circuits parsing, so `{ filesystem: {} }` would
7
+ * yield `filesystem: {}` with no `allowWrite`.
8
+ */
9
+ import { z } from "zod";
10
+ /**
11
+ * Glob metacharacters. srt on Linux silently DROPS a policy entry containing
12
+ * any of them (spec F1), so every sandbox path must be literal.
13
+ */
14
+ export declare const SANDBOX_GLOB_CHARS: RegExp;
15
+ export declare const SandboxConfigSchema: z.ZodObject<{
16
+ enabled: z.ZodDefault<z.ZodBoolean>;
17
+ backend: z.ZodDefault<z.ZodEnum<{
18
+ srt: "srt";
19
+ }>>;
20
+ filesystem: z.ZodPrefault<z.ZodObject<{
21
+ allowWrite: z.ZodDefault<z.ZodArray<z.ZodString>>;
22
+ denyRead: z.ZodDefault<z.ZodArray<z.ZodString>>;
23
+ allowSharedTmp: z.ZodDefault<z.ZodBoolean>;
24
+ }, z.core.$strip>>;
25
+ network: z.ZodPrefault<z.ZodObject<{
26
+ allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
27
+ }, z.core.$strip>>;
28
+ }, z.core.$strip>;
29
+ export type SandboxConfig = z.infer<typeof SandboxConfigSchema>;
30
+ /** BUG-20: derived, never hand-written at a second site. */
31
+ export declare const DEFAULT_SANDBOX_CONFIG: SandboxConfig;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `execution.sandbox` (P4, ADR-030 amendment): the OS sandbox around
3
+ * agent-authored Bash and RunCommand Exec commands.
4
+ *
5
+ * Nested objects use `.prefault({})`, not `.default({})`: in zod 4 a
6
+ * `.default()` value short-circuits parsing, so `{ filesystem: {} }` would
7
+ * yield `filesystem: {}` with no `allowWrite`.
8
+ */
9
+ import { z } from "zod";
10
+ /**
11
+ * Glob metacharacters. srt on Linux silently DROPS a policy entry containing
12
+ * any of them (spec F1), so every sandbox path must be literal.
13
+ */
14
+ export const SANDBOX_GLOB_CHARS = /[*?[\]{}]/;
15
+ const literalPath = z
16
+ .string()
17
+ .refine((p) => !SANDBOX_GLOB_CHARS.test(p), "sandbox paths must be literal: no * ? [ ] { } (spec F1)");
18
+ export const SandboxConfigSchema = z.object({
19
+ /** On by default since the P4 exit runs (spec S1); `raw` bash refuses when enabled but unavailable. */
20
+ enabled: z.boolean().default(true),
21
+ /** One backend today; the interface admits a container backend later. */
22
+ backend: z.enum(["srt"]).default("srt"),
23
+ filesystem: z
24
+ .object({
25
+ /** Extra write roots, "~" expanded, relative paths resolved against the story root. */
26
+ allowWrite: z.array(literalPath).default([]),
27
+ /** Extra read denies, "~" expanded. */
28
+ denyRead: z.array(literalPath).default([]),
29
+ /**
30
+ * US-002: grant the shared temp roots (`os.tmpdir()`, `/tmp`) as well as
31
+ * the run's own temp root. Off by default — a sandboxed command writes
32
+ * temp files under `$TMPDIR` and nowhere else.
33
+ */
34
+ allowSharedTmp: z.boolean().default(false),
35
+ })
36
+ .prefault({}),
37
+ network: z
38
+ .object({
39
+ /** absent = unrestricted (spec S2); [] = no network; a list = allow-list. */
40
+ allowedDomains: z.array(z.string()).optional(),
41
+ })
42
+ .prefault({}),
43
+ });
44
+ /** BUG-20: derived, never hand-written at a second site. */
45
+ export const DEFAULT_SANDBOX_CONFIG = SandboxConfigSchema.parse({});
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The cost core that moves into nax-agent (spec R4, section 5.2): pricing math
3
+ * over nax-ai's usage and pricing types. nax-only cost code (rate-card policy,
4
+ * catalog lookup, reporting helpers) stays behind `@/agents/cost`.
5
+ */
6
+ export { estimateCostUsd, priceCall } from "../estimate.ts";
7
+ export type { Pricing, PricingRates, PricingTier, TokenUsage } from "../standard-types.ts";
8
+ export { addTokenUsage, inputClassTokens } from "../usage-math.ts";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The cost core that moves into nax-agent (spec R4, section 5.2): pricing math
3
+ * over nax-ai's usage and pricing types. nax-only cost code (rate-card policy,
4
+ * catalog lookup, reporting helpers) stays behind `@/agents/cost`.
5
+ */
6
+ export { estimateCostUsd, priceCall } from "../estimate.js";
7
+ export { addTokenUsage, inputClassTokens } from "../usage-math.js";
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Tier-aware USD cost estimator.
3
+ *
4
+ * Relocated from `src/agents/native/models.ts` per US-001 so both the ACP and
5
+ * native paths share one implementation. Behaviour matches the previous
6
+ * native version:
7
+ * - `cacheReadPer1M` / `cacheCreationPer1M` fall back to `inputPer1M` when
8
+ * absent.
9
+ * - Tier selection: the highest `inputTokensAbove` whose threshold is strictly
10
+ * less than the total input-class usage wins for the WHOLE request; ties
11
+ * resolve to the higher threshold (the array is taken in declaration
12
+ * order, so the last tier whose threshold is exceeded is the winner).
13
+ * - What counts toward the threshold: input + cacheRead + cacheCreation.
14
+ *
15
+ * `inputClassTokens` is re-exported from here so callers using
16
+ * `@/agents/cost` get the helper without reaching into `./calculate`.
17
+ */
18
+ import type { Pricing, PricingRates, TokenUsage } from "./standard-types.ts";
19
+ import { inputClassTokens } from "./usage-math.ts";
20
+ /**
21
+ * `inputClassTokens` is re-exported from here so callers using
22
+ * `estimateCostUsd` can size the prompt with the same definition tier
23
+ * selection uses.
24
+ */
25
+ export { inputClassTokens };
26
+ /**
27
+ * Price one call. `costUsd` and `resolvedRates` come from one tier selection,
28
+ * so recorded rates always reproduce the recorded cost.
29
+ */
30
+ export declare function priceCall(usage: TokenUsage, rates: Pricing): {
31
+ costUsd: number;
32
+ resolvedRates: PricingRates;
33
+ };
34
+ export declare function estimateCostUsd(usage: TokenUsage, rates: Pricing): number;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Tier-aware USD cost estimator.
3
+ *
4
+ * Relocated from `src/agents/native/models.ts` per US-001 so both the ACP and
5
+ * native paths share one implementation. Behaviour matches the previous
6
+ * native version:
7
+ * - `cacheReadPer1M` / `cacheCreationPer1M` fall back to `inputPer1M` when
8
+ * absent.
9
+ * - Tier selection: the highest `inputTokensAbove` whose threshold is strictly
10
+ * less than the total input-class usage wins for the WHOLE request; ties
11
+ * resolve to the higher threshold (the array is taken in declaration
12
+ * order, so the last tier whose threshold is exceeded is the winner).
13
+ * - What counts toward the threshold: input + cacheRead + cacheCreation.
14
+ *
15
+ * `inputClassTokens` is re-exported from here so callers using
16
+ * `@/agents/cost` get the helper without reaching into `./calculate`.
17
+ */
18
+ import { inputClassTokens } from "./usage-math.js";
19
+ /**
20
+ * `inputClassTokens` is re-exported from here so callers using
21
+ * `estimateCostUsd` can size the prompt with the same definition tier
22
+ * selection uses.
23
+ */
24
+ export { inputClassTokens };
25
+ /** The greatest `inputTokensAbove` the request's input-class total exceeds wins, for the whole request. */
26
+ function selectRates(rates, totalInputClassTokens) {
27
+ let winner = rates;
28
+ if (rates.tiers !== undefined) {
29
+ let bestThreshold = Number.NEGATIVE_INFINITY;
30
+ for (const tier of rates.tiers) {
31
+ if (totalInputClassTokens > tier.inputTokensAbove && tier.inputTokensAbove > bestThreshold) {
32
+ winner = tier;
33
+ bestThreshold = tier.inputTokensAbove;
34
+ }
35
+ }
36
+ }
37
+ return winner;
38
+ }
39
+ function resolveRates(rates, totalInputClassTokens) {
40
+ const effective = selectRates(rates, totalInputClassTokens);
41
+ return {
42
+ input: effective.input,
43
+ output: effective.output,
44
+ cacheRead: effective.cacheRead ?? effective.input,
45
+ cacheWrite: effective.cacheWrite ?? effective.input,
46
+ };
47
+ }
48
+ /**
49
+ * Price one call. `costUsd` and `resolvedRates` come from one tier selection,
50
+ * so recorded rates always reproduce the recorded cost.
51
+ */
52
+ export function priceCall(usage, rates) {
53
+ const resolvedRates = resolveRates(rates, inputClassTokens(usage));
54
+ const inputCost = (usage.inputTokens / 1_000_000) * resolvedRates.input;
55
+ const outputCost = (usage.outputTokens / 1_000_000) * resolvedRates.output;
56
+ const cacheReadCost = ((usage.cacheReadTokens ?? 0) / 1_000_000) * resolvedRates.cacheRead;
57
+ const cacheWriteCost = ((usage.cacheWriteTokens ?? 0) / 1_000_000) * resolvedRates.cacheWrite;
58
+ return {
59
+ costUsd: inputCost + outputCost + cacheReadCost + cacheWriteCost,
60
+ resolvedRates,
61
+ };
62
+ }
63
+ export function estimateCostUsd(usage, rates) {
64
+ return priceCall(usage, rates).costUsd;
65
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Model spec parsing.
3
+ *
4
+ * nax profiles name models with a trailing reasoning-effort suffix, e.g.
5
+ * "gpt-5.6-luna[high]". This is a nax-level convention, not an artifact of any
6
+ * one transport: both agent transports consume it, each decomposing it before
7
+ * the value reaches its own destination.
8
+ *
9
+ * - The ACP path decomposes it before the bare model id reaches acpx. The
10
+ * suffix form mirrors codex-acp's legacy session/set_model identifier
11
+ * format; acpx 0.13+ selects models through the config-option channel
12
+ * instead, where the id is bare and effort is a sibling option
13
+ * (reasoning_effort).
14
+ * - The native path decomposes it before the bare model id reaches
15
+ * `client.model()`, and forwards the effort as a `thinking` level on the
16
+ * request (see `src/agents/native/models.ts`).
17
+ *
18
+ * Only a well-formed trailing [..] is treated as a suffix. Anything else is passed
19
+ * through as a model id so a profile typo surfaces as the adapter's own
20
+ * unadvertised-model error rather than a silent rewrite.
21
+ */
22
+ export interface ModelSpec {
23
+ /** Model id with any effort suffix removed. Safe to pass to acpx as --model. */
24
+ readonly model: string;
25
+ /** Reasoning effort from the suffix, when one was present. */
26
+ readonly effort?: string;
27
+ }
28
+ export declare function parseModelSpec(raw: string): ModelSpec;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Model spec parsing.
3
+ *
4
+ * nax profiles name models with a trailing reasoning-effort suffix, e.g.
5
+ * "gpt-5.6-luna[high]". This is a nax-level convention, not an artifact of any
6
+ * one transport: both agent transports consume it, each decomposing it before
7
+ * the value reaches its own destination.
8
+ *
9
+ * - The ACP path decomposes it before the bare model id reaches acpx. The
10
+ * suffix form mirrors codex-acp's legacy session/set_model identifier
11
+ * format; acpx 0.13+ selects models through the config-option channel
12
+ * instead, where the id is bare and effort is a sibling option
13
+ * (reasoning_effort).
14
+ * - The native path decomposes it before the bare model id reaches
15
+ * `client.model()`, and forwards the effort as a `thinking` level on the
16
+ * request (see `src/agents/native/models.ts`).
17
+ *
18
+ * Only a well-formed trailing [..] is treated as a suffix. Anything else is passed
19
+ * through as a model id so a profile typo surfaces as the adapter's own
20
+ * unadvertised-model error rather than a silent rewrite.
21
+ */
22
+ /** Matches "<model>[<effort>]" where neither part contains a bracket. */
23
+ const EFFORT_SUFFIX = /^([^[\]]+)\[([^[\]]+)\]$/;
24
+ export function parseModelSpec(raw) {
25
+ const match = EFFORT_SUFFIX.exec(raw);
26
+ if (!match)
27
+ return { model: raw };
28
+ return { model: match[1], effort: match[2] };
29
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The one usage and rate vocabulary (S1 spec, ruling R3): nax-ai's types.
3
+ *
4
+ * Staging re-export for S1-1. Code outside src/agents/native and
5
+ * src/agents/catalog takes these types from here, so check-nax-ai-imports
6
+ * keeps a single allow-listed file. In S1-5 this becomes a re-export in
7
+ * packages/nax-agent and the allow-list entry is removed.
8
+ */
9
+ export type { Pricing, PricingRates, PricingTier, TokenUsage } from "@nathapp/nax-ai";
@@ -0,0 +1 @@
1
+ export {};