@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,223 @@
1
+ /**
2
+ * `callTool`'s branch bodies, extracted from `runtime.ts` for the A13
3
+ * complexity drain (docs/plans/STATUS-complexity-drain.md).
4
+ *
5
+ * Each helper is one free function taking a single options object; the
6
+ * closure-bound collaborators (`logCall`, `runTool`, the session-wide
7
+ * `signal`) arrive BY REFERENCE and are read at call time, so the
8
+ * `_codingToolDeps` seam stays defined in `runtime.ts` exactly as the barrel
9
+ * (`src/tools/index.ts`) re-exports it. This file imports `runtime.ts`
10
+ * TYPE-ONLY — a runtime import would cycle back to the factory.
11
+ *
12
+ * One asymmetry is preserved on purpose: the denial-path breach warn below and the
13
+ * rejected-guard warn (US-004) call the module-level `getSafeLogger` import
14
+ * directly, while the ledger `log` in `runtime.ts` reads
15
+ * `_codingToolDeps.getLogger()`. Both behaved that way before the extraction;
16
+ * the seam stub in the mirror suites has never covered either warn.
17
+ */
18
+ import { randomUUID } from "node:crypto";
19
+ import { openShadowTap } from "#src/command-safety/index";
20
+ import { errorMessage } from "#src/infra/errors";
21
+ import { getSafeLogger } from "#src/infra/index";
22
+ import { ASK_CANCELLED_REASON } from "#src/permissions/index";
23
+ import { askDenyReason, askSummary } from "./ask-request.js";
24
+ import { redirectForArgv, redirectForCommand, redirectForVerb } from "./denial-redirect.js";
25
+ import { BASH_TOOL_NAME, EXEC_TOOL_NAME } from "./types.js";
26
+ /**
27
+ * A call carrying the tool's declared argv field (RunCommand's `Exec`
28
+ * branch) is checked, and ledgered, under the `Exec` identity rather
29
+ * than the tool's own name. Left as `name`, an `Exec(...)` grant would
30
+ * never be consulted — the call would run under RunCommand's own grant
31
+ * (often a wildcard for its declared commands), making the allowlist
32
+ * decorative. The tool's registered name is unaffected; this changes
33
+ * only which identity the policy and ledger see for THIS call.
34
+ */
35
+ export function resolvePolicyIdentity(name, tool, input) {
36
+ const argvField = tool.scope.argvField;
37
+ const hasArgv = argvField !== undefined && input[argvField] !== undefined;
38
+ const policyIdentity = hasArgv ? EXEC_TOOL_NAME : name;
39
+ return { policyIdentity, argvField, hasArgv };
40
+ }
41
+ /**
42
+ * P5: observe the command now (not awaited), settled from the caller's
43
+ * logCall below. Undefined whenever the runtime has no shadow configured.
44
+ */
45
+ export function openCallShadowTap(p) {
46
+ if (p.shadow === undefined)
47
+ return undefined;
48
+ return openShadowTap(p.shadow, {
49
+ key: randomUUID(),
50
+ identity: p.identity,
51
+ command: p.tool.scope.commandField === undefined ? undefined : p.input[p.tool.scope.commandField],
52
+ argv: p.hasArgv && p.argvField !== undefined ? p.input[p.argvField] : undefined,
53
+ root: p.root,
54
+ verdict: p.verdict,
55
+ stage: p.stage ?? "unknown",
56
+ ...(p.storyId !== undefined ? { storyId: p.storyId } : {}),
57
+ ...(p.callId !== undefined ? { callId: p.callId } : {}),
58
+ ...(p.scopeId !== undefined ? { scopeId: p.scopeId } : {}),
59
+ ...(p.context?.turnId !== undefined ? { turnId: p.context.turnId } : {}),
60
+ ...(p.context?.roundTrips !== undefined ? { roundTrips: p.context.roundTrips } : {}),
61
+ ...(p.context?.toolCallId !== undefined ? { toolCallId: p.context.toolCallId } : {}),
62
+ });
63
+ }
64
+ /**
65
+ * The command string the guard assesses, or undefined for an identity the
66
+ * guard does not cover. `Bash` reports its `command` field; `Exec` — the
67
+ * identity a `RunCommand` call carrying `argv` resolves to — reports the argv
68
+ * joined with single spaces, exactly the string the shadow observes and
69
+ * classifies. Any other identity (and a malformed command / argv) is not
70
+ * guarded; the policy has already refused that input.
71
+ */
72
+ function guardCommand(p) {
73
+ if (p.identity === BASH_TOOL_NAME) {
74
+ const field = p.tool.scope.commandField;
75
+ const value = field === undefined ? undefined : p.input[field];
76
+ return typeof value === "string" ? value : undefined;
77
+ }
78
+ if (p.identity !== EXEC_TOOL_NAME || p.argvField === undefined)
79
+ return undefined;
80
+ const argv = p.input[p.argvField];
81
+ if (!Array.isArray(argv) || !argv.every((a) => typeof a === "string"))
82
+ return undefined;
83
+ return argv.join(" ");
84
+ }
85
+ /**
86
+ * US-004: the guard's flag-for-review route for an ALLOWED command.
87
+ *
88
+ * Returns the ask-shaped denial the flagged call routes through
89
+ * `resolveAskOutcome`, and undefined in every other case — no guard
90
+ * configured, an identity other than `Bash`/`Exec`, or an unflagged
91
+ * assessment — so the caller runs the tool exactly as it did before the guard
92
+ * existed. The guard is total by contract (US-003); a rejection, or a resolved
93
+ * decision the type does not actually hold, means that contract broke, so the
94
+ * call runs unguarded rather than being refused, and the failure is logged once
95
+ * per broken call.
96
+ */
97
+ export async function resolveGuardDenial(p) {
98
+ const { guard } = p;
99
+ if (guard === undefined)
100
+ return undefined;
101
+ const command = guardCommand(p);
102
+ if (command === undefined)
103
+ return undefined;
104
+ // The whole decision — the assessment AND reading its fields — sits inside
105
+ // the fail-open try: the guard is total by contract, so anything that
106
+ // escapes here means the contract broke, including a resolved decision whose
107
+ // `score`/`threshold` is not the number the type promises. Both fail the
108
+ // same way: the call runs unguarded rather than erroring out of callTool.
109
+ try {
110
+ const decision = await guard.assess({ command, cwd: p.root, tempConfined: p.tempConfined });
111
+ if (!decision.flagged)
112
+ return undefined;
113
+ const { category, score, threshold } = decision;
114
+ return {
115
+ allowed: false,
116
+ outcome: "ask",
117
+ breach: false,
118
+ rule: "command-safety",
119
+ reason: `flagged for review by command safety: ${category ?? "blocked"} (score ${score.toFixed(2)} >= ${threshold})`,
120
+ resolvedPaths: p.resolvedPaths,
121
+ };
122
+ }
123
+ catch (err) {
124
+ getSafeLogger()?.warn("command-safety", "Command-safety guard failed; the call runs unguarded", {
125
+ error: errorMessage(err),
126
+ });
127
+ return undefined;
128
+ }
129
+ }
130
+ /**
131
+ * The ask branch: a call the policy gates matched an ask rule, so an
132
+ * AskResolver decides. US-003: build the AskControl from the per-call
133
+ * context. The turn's abort signal is forwarded verbatim, and onWaiting is
134
+ * wired so the resolver can tell the turn loop a human prompt is pending.
135
+ */
136
+ export async function resolveAskOutcome(p) {
137
+ const { context, input, tool, verdict } = p;
138
+ const callSignal = context?.signal ?? p.runtimeSignal;
139
+ const askControl = {
140
+ ...(callSignal !== undefined ? { signal: callSignal } : {}),
141
+ ...(context?.onWaiting !== undefined ? { onWaiting: context.onWaiting } : {}),
142
+ };
143
+ const ask = askSummary(p.identity, tool.scope, input);
144
+ let askVerdict;
145
+ try {
146
+ askVerdict = await p.askResolver.resolve({
147
+ tool: p.identity,
148
+ stage: p.stage ?? "unknown",
149
+ rule: verdict.rule ?? verdict.reason,
150
+ ...(verdict.rule !== undefined ? { matchedRule: verdict.rule } : {}),
151
+ summary: ask.summary,
152
+ ...(ask.unshowable ? { unshowable: true } : {}),
153
+ ...(typeof input[tool.scope.commandField ?? ""] === "string"
154
+ ? { command: input[tool.scope.commandField] }
155
+ : {}),
156
+ root: p.root,
157
+ reason: verdict.reason,
158
+ ...(p.storyId !== undefined ? { storyId: p.storyId } : {}),
159
+ }, askControl);
160
+ }
161
+ catch (err) {
162
+ const content = errorMessage(err);
163
+ p.logCall(p.identity, "error", content.length, input, context, false, content);
164
+ return { kind: "error", content };
165
+ }
166
+ const approval = {
167
+ decidedBy: askVerdict.decidedBy,
168
+ remembered: false,
169
+ latencyMs: askVerdict.latencyMs,
170
+ };
171
+ if (askVerdict.decision === "allow") {
172
+ // US-003 AC11: recheck the turn signal AFTER the resolver returned
173
+ // allow. A resolver that approves after the turn has been cancelled
174
+ // would otherwise race ahead and execute the tool; we deny instead
175
+ // with the same cancelled reason, so the agent never sees a tool
176
+ // result from a turn that has already ended.
177
+ if (callSignal?.aborted === true) {
178
+ const reason = `${verdict.reason} -- ${ASK_CANCELLED_REASON}`;
179
+ p.logCall(p.identity, "denied:ask", reason.length, input, context, false, reason, undefined, {
180
+ approval,
181
+ });
182
+ return { kind: "denied", reason, breach: false };
183
+ }
184
+ return p.runTool(tool, input, verdict.resolvedPaths ?? [], approval);
185
+ }
186
+ const reason = `${verdict.reason} -- ${askDenyReason(askVerdict.decidedBy)}`;
187
+ p.logCall(p.identity, "denied:ask", reason.length, input, context, false, reason, undefined, { approval });
188
+ return { kind: "denied", reason, breach: false };
189
+ }
190
+ /**
191
+ * The deny branch: a final policy refusal, sharpened where possible with a
192
+ * redirect naming an advertised tool that serves the call's intent.
193
+ */
194
+ export function resolveDenialOutcome(p) {
195
+ const { input, context, verdict } = p;
196
+ if (verdict.breach) {
197
+ // In band so an unattended run survives one bad path guess, but loud:
198
+ // a path escaping the root can indicate prompt injection.
199
+ getSafeLogger()?.warn("tools", "[policy] path resolved outside the permitted root", {
200
+ tool: p.identity,
201
+ reason: verdict.reason,
202
+ root: p.root,
203
+ });
204
+ }
205
+ const commandField = p.tool.scope.commandField;
206
+ const rawCommand = commandField === undefined ? undefined : input[commandField];
207
+ const rawArgv = p.argvField === undefined ? undefined : input[p.argvField];
208
+ const verbField = p.tool.scope.verbField;
209
+ const rawVerb = verbField === undefined ? undefined : input[verbField];
210
+ const declared = p.declaredCommands ?? new Set();
211
+ // An argv call and a verb call deny through different policy branches;
212
+ // before #1971 only the first could reach a redirect at all.
213
+ const extra = typeof rawCommand === "string"
214
+ ? redirectForCommand(rawCommand, p.advertisedNames, declared)
215
+ : Array.isArray(rawArgv)
216
+ ? redirectForArgv(rawArgv, p.advertisedNames, declared)
217
+ : typeof rawVerb === "string"
218
+ ? redirectForVerb(p.name, rawVerb, p.advertisedNames, declared)
219
+ : undefined;
220
+ const reason = extra === undefined ? verdict.reason : `${verdict.reason} -- ${extra}`;
221
+ p.logCall(p.identity, "denied", reason.length, input, context, verdict.breach, reason);
222
+ return { kind: "denied", reason, breach: verdict.breach };
223
+ }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Pairs the compiled policy with the tool registry and answers one call.
3
+ *
4
+ * nax-permission-mode-allow: consumes grants resolved by resolvePermissions;
5
+ * makes no permission decision of its own.
6
+ *
7
+ * The three outcomes are kept structurally distinct. Reusing one channel for a
8
+ * refusal and a crash would make a denied permission look like a recoverable
9
+ * tool error, which ADR-029 section 5 forbids.
10
+ */
11
+ import type { CommandInterceptor } from "#src/command-interceptor/index";
12
+ import type { CommandShadow } from "#src/command-safety/index";
13
+ import { getSafeLogger } from "#src/infra/index";
14
+ import { type AskResolver } from "#src/permissions/index";
15
+ import type { ProtectedPathsPolicy } from "./protected-paths.ts";
16
+ import { type CodingTool } from "./registry.ts";
17
+ import { type ToolAuditSink } from "./tool-audit.ts";
18
+ import type { ToolPolicy } from "./types.ts";
19
+ /** Per-call output ceiling, mirroring ToolDescriptor.maxTokensPerCall in spirit. */
20
+ export declare const DEFAULT_TOOL_MAX_BYTES = 40000;
21
+ /**
22
+ * Largest file a tool will read whole or write at all.
23
+ *
24
+ * Distinct from DEFAULT_TOOL_MAX_BYTES because they answer different questions:
25
+ * that one is how much the model may be told, this one is how much file a tool
26
+ * will handle. Edit must read and rewrite a file entirely, so it cannot use the
27
+ * output ceiling without refusing ordinary source files.
28
+ *
29
+ * Generous on purpose. Nothing an LLM legitimately edits approaches it, and a
30
+ * limit that fires during normal work would be worked around rather than
31
+ * respected.
32
+ */
33
+ export declare const DEFAULT_TOOL_MAX_FILE_BYTES = 2000000;
34
+ export type CodingToolOutcome = {
35
+ readonly kind: "ok" | "error";
36
+ readonly content: string;
37
+ /** Records the final model-facing content when shaping was deferred. */
38
+ readonly finalizeAudit?: (content: string) => void;
39
+ } | {
40
+ readonly kind: "denied";
41
+ readonly reason: string;
42
+ readonly breach: boolean;
43
+ };
44
+ /** Injectable logger seam, mirroring _pullToolsDeps.getLogger. */
45
+ export declare const _codingToolDeps: {
46
+ getLogger: typeof getSafeLogger;
47
+ };
48
+ /** Per-call context. Identity fields are recorded on the audit ledger. */
49
+ export interface ToolCallContext {
50
+ readonly turnId?: string;
51
+ readonly roundTrips?: number;
52
+ readonly toolCallId?: string;
53
+ /** Return the full result so a downstream model-facing chokepoint can shape it. */
54
+ readonly deferModelTruncation?: boolean;
55
+ /**
56
+ * US-002: the turn's abort signal, forwarded from the native coding-tool
57
+ * request. `runTool` copies it onto the `ToolRunContext` so the tool can
58
+ * stop in-flight work (Bash/Exec SIGKILL their process group) when the
59
+ * turn is cancelled, exactly as the runtime-level `signal` does when no
60
+ * per-call signal is present.
61
+ */
62
+ readonly signal?: AbortSignal;
63
+ /**
64
+ * US-002: notifies the runtime's caller (and through it the turn loop)
65
+ * that this tool is about to WAIT on something external, so an idle
66
+ * watchdog does not time it out. Forwarded from the native coding-tool
67
+ * request; tools that wait on a human call it before blocking.
68
+ */
69
+ readonly onWaiting?: () => void;
70
+ }
71
+ export interface CodingToolRuntime {
72
+ /** Op declaration intersected with policy grants. Both can only narrow. */
73
+ advertised(declared: readonly string[]): readonly CodingTool[];
74
+ callTool(name: string, input: Record<string, unknown>, context?: ToolCallContext): Promise<CodingToolOutcome>;
75
+ }
76
+ /** Idempotent: the registry is process-global, the runtime is per-session. */
77
+ export declare function registerBuiltinCodingTools(): void;
78
+ /** @internal Test-only: pairs with _resetRegistryForTest. */
79
+ export declare function _resetBuiltinsForTest(): void;
80
+ export declare function createCodingToolRuntime(opts: {
81
+ policy: ToolPolicy;
82
+ maxBytes?: number;
83
+ maxFileBytes?: number;
84
+ /**
85
+ * Tool-layer I/O bound. Defaults to `READ_CEILING` when absent — tools
86
+ * bound their reads to this ceiling before any model-facing truncation
87
+ * policy runs. Distinct from `maxBytes` (model-facing) and `maxFileBytes`
88
+ * (whole-file Edit/Write cap).
89
+ */
90
+ readCeiling?: number;
91
+ /**
92
+ * Aborts in-flight tool work (US-001). Bash and RunCommand's argv branch
93
+ * forward it to their launcher / runArgv call, which SIGKILLs the process
94
+ * group. Optional so existing callers compile unchanged.
95
+ */
96
+ signal?: AbortSignal;
97
+ storyId?: string;
98
+ callId?: string;
99
+ scopeId?: string;
100
+ sink?: ToolAuditSink;
101
+ extraTools?: readonly CodingTool[];
102
+ /**
103
+ * Advertised provider tool name -> owning provider id. Lets the ledger carry
104
+ * the provider explicitly instead of splitting the namespaced name apart.
105
+ */
106
+ providerIdByTool?: ReadonlyMap<string, string>;
107
+ /** Declared command names, so a denial can name `testScoped` only when the project has one. */
108
+ declaredCommands?: ReadonlySet<string>;
109
+ /**
110
+ * Repo-configurable glob denylist (nax#1972, `execution.denyPaths`),
111
+ * forwarded verbatim into every ToolRunContext this runtime builds. See
112
+ * src/tools/deny-paths.ts for the matching semantics; today only Delete
113
+ * consults it.
114
+ */
115
+ denyPaths?: readonly string[];
116
+ /**
117
+ * Answers an `ask` verdict (spec R1/R6). Defaults to the headless resolver,
118
+ * which always denies: an unattended run has no human to approve. A runtime
119
+ * capability, not config — injected where the runtime is created.
120
+ */
121
+ askResolver?: AskResolver;
122
+ /**
123
+ * PipelineStage this runtime serves, carried verbatim into every
124
+ * `AskRequest`. A resolver decides on the stage as much as on the tool --
125
+ * "yes during rectification, no during review" is the first policy anyone
126
+ * writes -- so it is threaded in rather than defaulted at the call site.
127
+ */
128
+ pipelineStage?: string;
129
+ /**
130
+ * P5 shadow classifier (spec 2026-09-23-p5-command-safety-shadow-design.md).
131
+ * The shadow itself is observational: it never changes a verdict, delays or
132
+ * fails a call. Its optional `guard` (US-004) is the one exception the
133
+ * master plan allows (D4a) — a flag-for-review guardrail, never an
134
+ * auto-approver: a flagged ALLOWED `Bash`/`Exec` call is routed through the
135
+ * existing ask channel, which decides.
136
+ */
137
+ commandShadow?: CommandShadow;
138
+ /**
139
+ * US-004: whether the session's sandbox confines temp writes to this run's
140
+ * own temp root (#2285). Forwarded to the guard's temp-only exemption;
141
+ * absent reads as false, the shared-temp posture every pre-US-002 launcher
142
+ * has. Derived from `isTempConfined(launcher)` in coding-tool-support.
143
+ */
144
+ tempConfined?: boolean;
145
+ /** Port 7: placed on every ToolRunContext this runtime builds. */
146
+ interceptor?: CommandInterceptor;
147
+ /** Port 6: placed on every ToolRunContext this runtime builds. */
148
+ protectedPaths?: ProtectedPathsPolicy;
149
+ }): CodingToolRuntime;