@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.
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/coding-tools/coding-tool-bash.d.ts +46 -0
- package/dist/coding-tools/coding-tool-bash.js +44 -0
- package/dist/coding-tools/coding-tool-extras.d.ts +35 -0
- package/dist/coding-tools/coding-tool-extras.js +56 -0
- package/dist/coding-tools/coding-tool-sandbox.d.ts +74 -0
- package/dist/coding-tools/coding-tool-sandbox.js +215 -0
- package/dist/coding-tools/coding-tool-support.d.ts +132 -0
- package/dist/coding-tools/coding-tool-support.js +159 -0
- package/dist/coding-tools/universal-coding-tools.d.ts +11 -0
- package/dist/coding-tools/universal-coding-tools.js +5 -0
- package/dist/command-interceptor/index.d.ts +55 -0
- package/dist/command-interceptor/index.js +60 -0
- package/dist/command-interceptor/shell.d.ts +36 -0
- package/dist/command-interceptor/shell.js +137 -0
- package/dist/command-safety/build.d.ts +19 -0
- package/dist/command-safety/build.js +47 -0
- package/dist/command-safety/guard.d.ts +32 -0
- package/dist/command-safety/guard.js +179 -0
- package/dist/command-safety/identifiers.d.ts +24 -0
- package/dist/command-safety/identifiers.js +20 -0
- package/dist/command-safety/index.d.ts +17 -0
- package/dist/command-safety/index.js +11 -0
- package/dist/command-safety/questions.d.ts +19 -0
- package/dist/command-safety/questions.js +60 -0
- package/dist/command-safety/row.d.ts +2 -0
- package/dist/command-safety/row.js +14 -0
- package/dist/command-safety/rule-scorer.d.ts +9 -0
- package/dist/command-safety/rule-scorer.js +391 -0
- package/dist/command-safety/shadow.d.ts +33 -0
- package/dist/command-safety/shadow.js +188 -0
- package/dist/command-safety/systemone-client.d.ts +16 -0
- package/dist/command-safety/systemone-client.js +92 -0
- package/dist/command-safety/tap.d.ts +37 -0
- package/dist/command-safety/tap.js +77 -0
- package/dist/command-safety/temp-only.d.ts +6 -0
- package/dist/command-safety/temp-only.js +215 -0
- package/dist/command-safety/tmp-write.d.ts +2 -0
- package/dist/command-safety/tmp-write.js +112 -0
- package/dist/command-safety/types.d.ts +185 -0
- package/dist/command-safety/types.js +21 -0
- package/dist/config/bash-approval.d.ts +33 -0
- package/dist/config/bash-approval.js +30 -0
- package/dist/config/catalog-overrides.d.ts +94 -0
- package/dist/config/catalog-overrides.js +7 -0
- package/dist/config/native-agent/index.d.ts +8 -0
- package/dist/config/native-agent/index.js +8 -0
- package/dist/config/schemas-sandbox.d.ts +31 -0
- package/dist/config/schemas-sandbox.js +45 -0
- package/dist/cost/core/index.d.ts +8 -0
- package/dist/cost/core/index.js +7 -0
- package/dist/cost/estimate.d.ts +34 -0
- package/dist/cost/estimate.js +65 -0
- package/dist/cost/model-spec.d.ts +28 -0
- package/dist/cost/model-spec.js +29 -0
- package/dist/cost/standard-types.d.ts +9 -0
- package/dist/cost/standard-types.js +1 -0
- package/dist/cost/usage-math.d.ts +18 -0
- package/dist/cost/usage-math.js +46 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +21 -0
- package/dist/infra/agent-logger.d.ts +22 -0
- package/dist/infra/agent-logger.js +19 -0
- package/dist/infra/credentials-config.d.ts +20 -0
- package/dist/infra/credentials-config.js +15 -0
- package/dist/infra/errors.d.ts +9 -0
- package/dist/infra/errors.js +11 -0
- package/dist/infra/index.d.ts +7 -0
- package/dist/infra/index.js +7 -0
- package/dist/infra/nax-error.d.ts +10 -0
- package/dist/infra/nax-error.js +16 -0
- package/dist/infra/spin-breaker/hash.d.ts +2 -0
- package/dist/infra/spin-breaker/hash.js +5 -0
- package/dist/infra/spin-breaker/index.d.ts +120 -0
- package/dist/infra/spin-breaker/index.js +340 -0
- package/dist/internal/agent-output-env.d.ts +44 -0
- package/dist/internal/agent-output-env.js +57 -0
- package/dist/internal/argv-exec.d.ts +58 -0
- package/dist/internal/argv-exec.js +224 -0
- package/dist/internal/bounded-io.d.ts +24 -0
- package/dist/internal/bounded-io.js +51 -0
- package/dist/internal/command-spec/index.d.ts +29 -0
- package/dist/internal/command-spec/index.js +36 -0
- package/dist/internal/describe-value-type.d.ts +8 -0
- package/dist/internal/describe-value-type.js +14 -0
- package/dist/internal/exec-framing.d.ts +18 -0
- package/dist/internal/exec-framing.js +22 -0
- package/dist/internal/file-lock.d.ts +91 -0
- package/dist/internal/file-lock.js +212 -0
- package/dist/internal/file-size.d.ts +2 -0
- package/dist/internal/file-size.js +12 -0
- package/dist/internal/git-add.d.ts +43 -0
- package/dist/internal/git-add.js +59 -0
- package/dist/internal/git-env.d.ts +59 -0
- package/dist/internal/git-env.js +93 -0
- package/dist/internal/git-exec.d.ts +58 -0
- package/dist/internal/git-exec.js +115 -0
- package/dist/internal/path-file-lock.d.ts +23 -0
- package/dist/internal/path-file-lock.js +25 -0
- package/dist/internal/process-alive.d.ts +42 -0
- package/dist/internal/process-alive.js +56 -0
- package/dist/internal/process-kill.d.ts +27 -0
- package/dist/internal/process-kill.js +54 -0
- package/dist/internal/realpath.d.ts +29 -0
- package/dist/internal/realpath.js +52 -0
- package/dist/internal/redact.d.ts +40 -0
- package/dist/internal/redact.js +161 -0
- package/dist/internal/shell-quote.d.ts +2 -0
- package/dist/internal/shell-quote.js +4 -0
- package/dist/internal/sort.d.ts +20 -0
- package/dist/internal/sort.js +20 -0
- package/dist/internal/strip-control-chars.d.ts +19 -0
- package/dist/internal/strip-control-chars.js +38 -0
- package/dist/internal/thenable.d.ts +10 -0
- package/dist/internal/thenable.js +15 -0
- package/dist/internal.d.ts +91 -0
- package/dist/internal.js +91 -0
- package/dist/native/adapter-deps.d.ts +46 -0
- package/dist/native/adapter-deps.js +43 -0
- package/dist/native/auth-types.d.ts +70 -0
- package/dist/native/auth-types.js +13 -0
- package/dist/native/auth.d.ts +133 -0
- package/dist/native/auth.js +362 -0
- package/dist/native/client.d.ts +50 -0
- package/dist/native/client.js +174 -0
- package/dist/native/complete.d.ts +33 -0
- package/dist/native/complete.js +88 -0
- package/dist/native/credentials/chained-store.d.ts +30 -0
- package/dist/native/credentials/chained-store.js +68 -0
- package/dist/native/credentials/change-guard.d.ts +51 -0
- package/dist/native/credentials/change-guard.js +136 -0
- package/dist/native/credentials/exec-source.d.ts +50 -0
- package/dist/native/credentials/exec-source.js +222 -0
- package/dist/native/credentials/fingerprint.d.ts +26 -0
- package/dist/native/credentials/fingerprint.js +174 -0
- package/dist/native/credentials/helper-process.d.ts +79 -0
- package/dist/native/credentials/helper-process.js +259 -0
- package/dist/native/credentials/helper-protocol.d.ts +36 -0
- package/dist/native/credentials/helper-protocol.js +79 -0
- package/dist/native/credentials/index.d.ts +60 -0
- package/dist/native/credentials/index.js +184 -0
- package/dist/native/errors.d.ts +34 -0
- package/dist/native/errors.js +109 -0
- package/dist/native/index.d.ts +25 -0
- package/dist/native/index.js +23 -0
- package/dist/native/model-resolver.d.ts +57 -0
- package/dist/native/model-resolver.js +73 -0
- package/dist/native/models.d.ts +116 -0
- package/dist/native/models.js +183 -0
- package/dist/native/session/ask-human.d.ts +15 -0
- package/dist/native/session/ask-human.js +22 -0
- package/dist/native/session/compaction.d.ts +94 -0
- package/dist/native/session/compaction.js +170 -0
- package/dist/native/session/handle-invalid-tool-call.d.ts +111 -0
- package/dist/native/session/handle-invalid-tool-call.js +159 -0
- package/dist/native/session/loop-events/cache-boundary.d.ts +11 -0
- package/dist/native/session/loop-events/cache-boundary.js +29 -0
- package/dist/native/session/loop-events/external-handler.d.ts +38 -0
- package/dist/native/session/loop-events/external-handler.js +193 -0
- package/dist/native/session/loop-events/index.d.ts +16 -0
- package/dist/native/session/loop-events/index.js +15 -0
- package/dist/native/session/loop-events/payload-guard.d.ts +9 -0
- package/dist/native/session/loop-events/payload-guard.js +31 -0
- package/dist/native/session/loop-events/registry.d.ts +84 -0
- package/dist/native/session/loop-events/registry.js +305 -0
- package/dist/native/session/loop-events/types.d.ts +251 -0
- package/dist/native/session/loop-events/types.js +14 -0
- package/dist/native/session/loop-handlers.d.ts +73 -0
- package/dist/native/session/loop-handlers.js +137 -0
- package/dist/native/session/nudge.d.ts +29 -0
- package/dist/native/session/nudge.js +35 -0
- package/dist/native/session/rate-provenance.d.ts +17 -0
- package/dist/native/session/rate-provenance.js +39 -0
- package/dist/native/session/session.d.ts +139 -0
- package/dist/native/session/session.js +208 -0
- package/dist/native/session/tool-input-exemplar.d.ts +2 -0
- package/dist/native/session/tool-input-exemplar.js +66 -0
- package/dist/native/session/tool-input-validation.d.ts +15 -0
- package/dist/native/session/tool-input-validation.js +146 -0
- package/dist/native/session/tool-mapping.d.ts +18 -0
- package/dist/native/session/tool-mapping.js +27 -0
- package/dist/native/session/tool-result.d.ts +37 -0
- package/dist/native/session/tool-result.js +25 -0
- package/dist/native/session/transcript-store.d.ts +77 -0
- package/dist/native/session/transcript-store.js +200 -0
- package/dist/native/session/truncation-handler.d.ts +47 -0
- package/dist/native/session/truncation-handler.js +83 -0
- package/dist/native/session/turn-accumulator.d.ts +45 -0
- package/dist/native/session/turn-accumulator.js +67 -0
- package/dist/native/session/turn-ask-human.d.ts +23 -0
- package/dist/native/session/turn-ask-human.js +41 -0
- package/dist/native/session/turn-compaction-step.d.ts +74 -0
- package/dist/native/session/turn-compaction-step.js +128 -0
- package/dist/native/session/turn-complete-step.d.ts +77 -0
- package/dist/native/session/turn-complete-step.js +159 -0
- package/dist/native/session/turn-end-event.d.ts +3 -0
- package/dist/native/session/turn-end-event.js +17 -0
- package/dist/native/session/turn-events.d.ts +63 -0
- package/dist/native/session/turn-events.js +48 -0
- package/dist/native/session/turn-loop-round-trip.d.ts +116 -0
- package/dist/native/session/turn-loop-round-trip.js +318 -0
- package/dist/native/session/turn-loop.d.ts +23 -0
- package/dist/native/session/turn-loop.js +250 -0
- package/dist/native/session/turn-result.d.ts +39 -0
- package/dist/native/session/turn-result.js +64 -0
- package/dist/native/session/turn-retry.d.ts +120 -0
- package/dist/native/session/turn-retry.js +182 -0
- package/dist/native/session/turn-tool-batch.d.ts +61 -0
- package/dist/native/session/turn-tool-batch.js +259 -0
- package/dist/native/session/turn-types.d.ts +164 -0
- package/dist/native/session/turn-types.js +36 -0
- package/dist/native/session-adapter.d.ts +56 -0
- package/dist/native/session-adapter.js +369 -0
- package/dist/native/session-affinity.d.ts +36 -0
- package/dist/native/session-affinity.js +43 -0
- package/dist/native/tier-providers.d.ts +18 -0
- package/dist/native/tier-providers.js +20 -0
- package/dist/permissions/approval-audit.d.ts +10 -0
- package/dist/permissions/approval-audit.js +22 -0
- package/dist/permissions/approvals-link.d.ts +20 -0
- package/dist/permissions/approvals-link.js +62 -0
- package/dist/permissions/approvals-store.d.ts +168 -0
- package/dist/permissions/approvals-store.js +259 -0
- package/dist/permissions/approvals-taint.d.ts +33 -0
- package/dist/permissions/approvals-taint.js +138 -0
- package/dist/permissions/ask-chain.d.ts +69 -0
- package/dist/permissions/ask-chain.js +32 -0
- package/dist/permissions/ask.d.ts +23 -0
- package/dist/permissions/ask.js +25 -0
- package/dist/permissions/bash-lex.d.ts +59 -0
- package/dist/permissions/bash-lex.js +279 -0
- package/dist/permissions/grammar.d.ts +12 -0
- package/dist/permissions/grammar.js +24 -0
- package/dist/permissions/index.d.ts +11 -0
- package/dist/permissions/index.js +9 -0
- package/dist/permissions/secret-spans.d.ts +19 -0
- package/dist/permissions/secret-spans.js +88 -0
- package/dist/permissions/types.d.ts +85 -0
- package/dist/permissions/types.js +1 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/node-glob.d.ts +3 -0
- package/dist/runtime/node-glob.js +83 -0
- package/dist/runtime/node-runtime.d.ts +3 -0
- package/dist/runtime/node-runtime.js +126 -0
- package/dist/runtime/slot.d.ts +11 -0
- package/dist/runtime/slot.js +17 -0
- package/dist/runtime/types.d.ts +51 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/which.d.ts +8 -0
- package/dist/runtime/which.js +32 -0
- package/dist/sandbox/argv-quote.d.ts +11 -0
- package/dist/sandbox/argv-quote.js +13 -0
- package/dist/sandbox/defaults.d.ts +27 -0
- package/dist/sandbox/defaults.js +47 -0
- package/dist/sandbox/git-guards.d.ts +64 -0
- package/dist/sandbox/git-guards.js +161 -0
- package/dist/sandbox/index.d.ts +11 -0
- package/dist/sandbox/index.js +10 -0
- package/dist/sandbox/launcher.d.ts +37 -0
- package/dist/sandbox/launcher.js +160 -0
- package/dist/sandbox/messages.d.ts +17 -0
- package/dist/sandbox/messages.js +46 -0
- package/dist/sandbox/policy-builder.d.ts +44 -0
- package/dist/sandbox/policy-builder.js +149 -0
- package/dist/sandbox/policy-inputs.d.ts +53 -0
- package/dist/sandbox/policy-inputs.js +76 -0
- package/dist/sandbox/probe.d.ts +8 -0
- package/dist/sandbox/probe.js +66 -0
- package/dist/sandbox/registry.d.ts +17 -0
- package/dist/sandbox/registry.js +57 -0
- package/dist/sandbox/session-tmp.d.ts +20 -0
- package/dist/sandbox/session-tmp.js +95 -0
- package/dist/sandbox/srt-backend.d.ts +21 -0
- package/dist/sandbox/srt-backend.js +99 -0
- package/dist/sandbox/types.d.ts +102 -0
- package/dist/sandbox/types.js +1 -0
- package/dist/session/adapter-failure.d.ts +60 -0
- package/dist/session/adapter-failure.js +11 -0
- package/dist/session/agent-stream-events.d.ts +103 -0
- package/dist/session/agent-stream-events.js +6 -0
- package/dist/session/interaction-handler.d.ts +53 -0
- package/dist/session/interaction-handler.js +2 -0
- package/dist/session/no-op-interaction-handler.d.ts +9 -0
- package/dist/session/no-op-interaction-handler.js +11 -0
- package/dist/session/protocol-types.d.ts +12 -0
- package/dist/session/protocol-types.js +1 -0
- package/dist/session/session-types.d.ts +456 -0
- package/dist/session/session-types.js +64 -0
- package/dist/session/tool-descriptor.d.ts +23 -0
- package/dist/session/tool-descriptor.js +5 -0
- package/dist/session/turn-deadline.d.ts +17 -0
- package/dist/session/turn-deadline.js +23 -0
- package/dist/tools/ask-request.d.ts +35 -0
- package/dist/tools/ask-request.js +57 -0
- package/dist/tools/bash-cwd.d.ts +82 -0
- package/dist/tools/bash-cwd.js +55 -0
- package/dist/tools/bash.d.ts +69 -0
- package/dist/tools/bash.js +283 -0
- package/dist/tools/delete.d.ts +57 -0
- package/dist/tools/delete.js +154 -0
- package/dist/tools/denial-redirect.d.ts +42 -0
- package/dist/tools/denial-redirect.js +266 -0
- package/dist/tools/deny-paths.d.ts +35 -0
- package/dist/tools/deny-paths.js +76 -0
- package/dist/tools/edit-region.d.ts +50 -0
- package/dist/tools/edit-region.js +90 -0
- package/dist/tools/edit.d.ts +25 -0
- package/dist/tools/edit.js +114 -0
- package/dist/tools/exec-allowlist-text.d.ts +18 -0
- package/dist/tools/exec-allowlist-text.js +24 -0
- package/dist/tools/exec-guard.d.ts +69 -0
- package/dist/tools/exec-guard.js +151 -0
- package/dist/tools/git-commit.d.ts +59 -0
- package/dist/tools/git-commit.js +220 -0
- package/dist/tools/git-flags/index.d.ts +10 -0
- package/dist/tools/git-flags/index.js +10 -0
- package/dist/tools/git.d.ts +88 -0
- package/dist/tools/git.js +397 -0
- package/dist/tools/glob.d.ts +29 -0
- package/dist/tools/glob.js +153 -0
- package/dist/tools/grep.d.ts +21 -0
- package/dist/tools/grep.js +162 -0
- package/dist/tools/index.d.ts +36 -0
- package/dist/tools/index.js +28 -0
- package/dist/tools/narrow-grants.d.ts +19 -0
- package/dist/tools/narrow-grants.js +54 -0
- package/dist/tools/nax-owned-writes.d.ts +135 -0
- package/dist/tools/nax-owned-writes.js +259 -0
- package/dist/tools/package-managers-table.d.ts +146 -0
- package/dist/tools/package-managers-table.js +325 -0
- package/dist/tools/package-managers-types.d.ts +36 -0
- package/dist/tools/package-managers-types.js +6 -0
- package/dist/tools/package-managers.d.ts +85 -0
- package/dist/tools/package-managers.js +391 -0
- package/dist/tools/path-list.d.ts +38 -0
- package/dist/tools/path-list.js +62 -0
- package/dist/tools/policy-bash-raw.d.ts +19 -0
- package/dist/tools/policy-bash-raw.js +210 -0
- package/dist/tools/policy-bash.d.ts +64 -0
- package/dist/tools/policy-bash.js +232 -0
- package/dist/tools/policy-command-branch.d.ts +32 -0
- package/dist/tools/policy-command-branch.js +63 -0
- package/dist/tools/policy-input.d.ts +2 -0
- package/dist/tools/policy-input.js +10 -0
- package/dist/tools/policy-match.d.ts +75 -0
- package/dist/tools/policy-match.js +117 -0
- package/dist/tools/policy-paths-branch.d.ts +97 -0
- package/dist/tools/policy-paths-branch.js +314 -0
- package/dist/tools/policy.d.ts +65 -0
- package/dist/tools/policy.js +232 -0
- package/dist/tools/protected-paths.d.ts +26 -0
- package/dist/tools/protected-paths.js +8 -0
- package/dist/tools/provider-adapt.d.ts +4 -0
- package/dist/tools/provider-adapt.js +32 -0
- package/dist/tools/provider-advertise.d.ts +39 -0
- package/dist/tools/provider-advertise.js +50 -0
- package/dist/tools/provider-grants.d.ts +36 -0
- package/dist/tools/provider-grants.js +72 -0
- package/dist/tools/provider-sanitize.d.ts +19 -0
- package/dist/tools/provider-sanitize.js +53 -0
- package/dist/tools/provider-types.d.ts +41 -0
- package/dist/tools/provider-types.js +26 -0
- package/dist/tools/read-continuation.d.ts +147 -0
- package/dist/tools/read-continuation.js +176 -0
- package/dist/tools/read-file.d.ts +32 -0
- package/dist/tools/read-file.js +85 -0
- package/dist/tools/read.d.ts +25 -0
- package/dist/tools/read.js +182 -0
- package/dist/tools/registry.d.ts +125 -0
- package/dist/tools/registry.js +67 -0
- package/dist/tools/request-capability.d.ts +13 -0
- package/dist/tools/request-capability.js +23 -0
- package/dist/tools/run-command-exec.d.ts +14 -0
- package/dist/tools/run-command-exec.js +161 -0
- package/dist/tools/run-command.d.ts +107 -0
- package/dist/tools/run-command.js +398 -0
- package/dist/tools/runtime-calltool.d.ts +146 -0
- package/dist/tools/runtime-calltool.js +223 -0
- package/dist/tools/runtime.d.ts +149 -0
- package/dist/tools/runtime.js +345 -0
- package/dist/tools/scratchpad.d.ts +20 -0
- package/dist/tools/scratchpad.js +197 -0
- package/dist/tools/spill.d.ts +81 -0
- package/dist/tools/spill.js +251 -0
- package/dist/tools/tool-audit.d.ts +171 -0
- package/dist/tools/tool-audit.js +183 -0
- package/dist/tools/truncate.d.ts +98 -0
- package/dist/tools/truncate.js +297 -0
- package/dist/tools/types.d.ts +145 -0
- package/dist/tools/types.js +24 -0
- package/dist/tools/verb-denial-argv-hint.d.ts +35 -0
- package/dist/tools/verb-denial-argv-hint.js +40 -0
- package/dist/tools/write.d.ts +9 -0
- package/dist/tools/write.js +45 -0
- package/package.json +54 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Pure usage arithmetic shared by the pricing core and nax's reporting helpers. */
|
|
2
|
+
import type { TokenUsage } from "./standard-types.ts";
|
|
3
|
+
/** Sum two TokenUsage values. Pure.
|
|
4
|
+
* A cache field is present on the result when either operand carries it or the
|
|
5
|
+
* sum is positive, preserving the zero-versus-absent distinction producers set. */
|
|
6
|
+
export declare function addTokenUsage(a: TokenUsage, b: TokenUsage): TokenUsage;
|
|
7
|
+
/**
|
|
8
|
+
* Tokens the provider counted as part of the prompt.
|
|
9
|
+
*
|
|
10
|
+
* Cache reads and writes are prompt tokens that the provider reports
|
|
11
|
+
* separately because it prices them differently — not tokens that were
|
|
12
|
+
* absent from the request. Any consumer asking "how big was the prompt"
|
|
13
|
+
* needs all three; `inputTokens` alone answers a different question and,
|
|
14
|
+
* under prompt caching, collapses to near zero (nax#1852).
|
|
15
|
+
*
|
|
16
|
+
* Output is deliberately excluded: this measures the prompt, not the call.
|
|
17
|
+
*/
|
|
18
|
+
export declare function inputClassTokens(usage: TokenUsage): number;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Coerce a token count to a finite number, falling back to 0. Defense in
|
|
2
|
+
* depth (BUG-10): upstream guards in parser.ts / token-mapper.ts should
|
|
3
|
+
* already keep non-numeric values out, but `addTokenUsage` is a cheap pure
|
|
4
|
+
* function reachable from multiple call sites, so it validates its own
|
|
5
|
+
* inputs rather than trusting the static TokenUsage type — a malformed
|
|
6
|
+
* operand (e.g. a stringified number) would otherwise trigger `+`'s string
|
|
7
|
+
* concatenation instead of numeric addition, and a genuinely non-numeric
|
|
8
|
+
* value would propagate NaN into the running total. */
|
|
9
|
+
function toFiniteTokenCount(value) {
|
|
10
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
11
|
+
}
|
|
12
|
+
/** Sum two TokenUsage values. Pure.
|
|
13
|
+
* A cache field is present on the result when either operand carries it or the
|
|
14
|
+
* sum is positive, preserving the zero-versus-absent distinction producers set. */
|
|
15
|
+
export function addTokenUsage(a, b) {
|
|
16
|
+
// BUG-58: apply the same finite-number guard to the cache fields as
|
|
17
|
+
// inputTokens/outputTokens above — `?? 0` alone only guards undefined/null,
|
|
18
|
+
// not a malformed non-numeric operand (e.g. a stringified number), which
|
|
19
|
+
// would otherwise hit `+`'s string-concatenation behavior here too.
|
|
20
|
+
const cacheRead = toFiniteTokenCount(a.cacheReadTokens ?? 0) + toFiniteTokenCount(b.cacheReadTokens ?? 0);
|
|
21
|
+
const cacheWrite = toFiniteTokenCount(a.cacheWriteTokens ?? 0) + toFiniteTokenCount(b.cacheWriteTokens ?? 0);
|
|
22
|
+
return {
|
|
23
|
+
inputTokens: toFiniteTokenCount(a.inputTokens) + toFiniteTokenCount(b.inputTokens),
|
|
24
|
+
outputTokens: toFiniteTokenCount(a.outputTokens) + toFiniteTokenCount(b.outputTokens),
|
|
25
|
+
...(cacheRead > 0 || a.cacheReadTokens !== undefined || b.cacheReadTokens !== undefined
|
|
26
|
+
? { cacheReadTokens: cacheRead }
|
|
27
|
+
: {}),
|
|
28
|
+
...(cacheWrite > 0 || a.cacheWriteTokens !== undefined || b.cacheWriteTokens !== undefined
|
|
29
|
+
? { cacheWriteTokens: cacheWrite }
|
|
30
|
+
: {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Tokens the provider counted as part of the prompt.
|
|
35
|
+
*
|
|
36
|
+
* Cache reads and writes are prompt tokens that the provider reports
|
|
37
|
+
* separately because it prices them differently — not tokens that were
|
|
38
|
+
* absent from the request. Any consumer asking "how big was the prompt"
|
|
39
|
+
* needs all three; `inputTokens` alone answers a different question and,
|
|
40
|
+
* under prompt caching, collapses to near zero (nax#1852).
|
|
41
|
+
*
|
|
42
|
+
* Output is deliberately excluded: this measures the prompt, not the call.
|
|
43
|
+
*/
|
|
44
|
+
export function inputClassTokens(usage) {
|
|
45
|
+
return usage.inputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0);
|
|
46
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nathapp/nax-agent public entry (S1 spec section 4.4, S2 spec section 5.3).
|
|
3
|
+
*
|
|
4
|
+
* Every export is named: nothing reaches this entry through `export *`. No "_"
|
|
5
|
+
* name belongs here; test seams and reset hooks live on ./internal. The built
|
|
6
|
+
* surface of both entries is pinned by api/nax-agent.api.txt (`bun run check:api`).
|
|
7
|
+
*
|
|
8
|
+
* Generated once by S2-7 from the previous `export *` barrels; maintained by hand.
|
|
9
|
+
*/
|
|
10
|
+
export { appendCommandSafetyRow, type BuildCommandShadowOptions, buildCommandShadow, buildRequest, type Classify, COMMAND_SAFETY_DIR, type CommandGuard, type CommandSafetyRow, type CommandShadow, type CommandShadowOptions, createCommandGuard, createCommandShadow, createSystemOneClient, detectTmpWrite, type ExecRun, type FinalOutcome, type GuardDecision, type GuardInput, HARM_OPTIONS, HARM_QUESTION_ID, type HarmOption, isTempOnly, type LedgerOutcome, type MechanicalVerdict, type ModelAnswers, type ModelResult, type Observation, openShadowTap, parseAnswer, QUESTION_IDS, QUESTION_SET_VERSION, type QuestionId, RULE_SET_VERSION, type RuleContext, type RuleResult, type ShadowCall, type ShadowTap, SYSTEMONE_MODEL_LABEL, type SystemOneClientOptions, type SystemOneQuestion, type SystemOneRequest, scoreGuard, scoreRules, shadowCacheKey, toMechanical, } from "#src/command-safety/index";
|
|
11
|
+
export { addTokenUsage, estimateCostUsd, inputClassTokens, type Pricing, type PricingRates, type PricingTier, priceCall, type TokenUsage, } from "#src/cost/core/index";
|
|
12
|
+
export { type ModelSpec, parseModelSpec, } from "#src/cost/model-spec";
|
|
13
|
+
export type { AgentLogger, CredentialAuthConfig, CredentialsConfig } from "#src/infra/index";
|
|
14
|
+
export { configureCredentials, setAgentLogger } from "#src/infra/index";
|
|
15
|
+
export { AuthCancelledError, type AuthEvent, type AuthInteraction, type AuthLink, type AuthMethod, type AuthOption, type AuthPrompt, type AuthResult, ambientShadows, anyAmbientCredential, authImportOutcomeLabel, credentialFilePath, DEFAULT_PI_AUTH_PATH, type ImportOutcome, importPiCredentials, listStoredProviders, MAX_RETAINED_TRANSCRIPTS, NATIVE_AGENT, type NativeCatalogOverrides, type NativeCompleteContext, type NativeCompleteOptions, type NativeCompleteResult, NativeSessionAdapter, NativeSessionUnsupportedError, type NativeTierConfig, nativeComplete, nativeTierProviders, naxCredentialStore, newSessionKey, providersWithoutCredentials, pruneRetainedTranscripts, type ResolveResult, type ResolveStatus, removeStoredProvider, resolveNativeId, runLogin, type StoredEntry, servedAuth, } from "#src/native/index";
|
|
16
|
+
export { type ApprovalAuditRow, type ApprovalEntry, type ApprovalsFile, type ApprovalsFileRead, type ApprovalsFileState, type ApprovalsTaint, ASK_CANCELLED_REASON, ASK_DENIED_REASON, ASK_NO_CHANNEL_REASON, ASK_TIMEOUT_REASON, ASK_UNAVAILABLE_REASON, ASK_UNSHOWABLE_REASON, type AskControl, type AskDecidedBy, type AskDecision, type AskLink, type AskLinkOutcome, type AskRequest, type AskResolver, type AskVerdict, appendApproval, appendApprovalAudit, approvalId, approvalsPath, type BashLexResult, type BashRedirect, type BashSegment, type BashSegmentSeparator, type BashToken, type ClearTaintOutcome, chainAskLinks, clearApprovalsTaint, createApprovalsLink, findApproval, findSecretSpans, headlessAskResolver, isForgeCapable, lexBashCommand, type MaskResult, maskForPrompt, type PrepareApprovalsStoreOptions, parseRuleList, parseToolExpression, prepareApprovalsStore, type RemovalDecision, type RemovalResult, type ResolvedPermissions, readApprovals, readApprovalsFile, readApprovalsFileDetailed, redactForRow, redactRowStrings, removeApprovals, type SecretSpan, taintApprovals, writeApprovalsFile, } from "#src/permissions/index";
|
|
17
|
+
export { type AgentGlobOptions, type AgentRuntime, type AgentSpawnOptions, type AgentSpawnResult, type AgentSpawnStdin, getAgentRuntime, nodeRuntime, setAgentRuntime, } from "#src/runtime/index";
|
|
18
|
+
export { buildSandboxPolicy, type CommandLauncher, type CommandLauncherOptions, createCommandLauncher, createSrtBackend, DISABLED_SANDBOX_STATE, defaultTempRoots, denialHintLine, type GitLayout, type LaunchRequest, type LaunchResult, type LaunchSpec, LIKELY_SANDBOX_DENIAL, listCredentialFiles, listGitGuardFiles, listNaxEntries, type ProbeResult, probeSandbox, probeSandboxOnce, quoteArgvForShell, rawBashRefusalReason, resetSandboxBackend, resolveGitLayout, runTempRoots, runTmpRoot, type SandboxBackend, type SandboxBackendName, type SandboxNetworkPolicy, type SandboxPolicy, type SandboxPolicyInput, type SandboxRecord, type SandboxState, type SandboxWrapRequest, sandboxBackendFor, sandboxSentence, sessionTmpDir, sessionTmpDirUnder, strayCommonDirTripwire, unsandboxedSentence, warnSandboxUnavailableOnce, } from "#src/sandbox/index";
|
|
19
|
+
export type { AdapterFailure } from "#src/session/adapter-failure";
|
|
20
|
+
export type { AgentAwaitingHumanEvent, AgentCallEndedEvent, AgentCallStartedEvent, AgentMessageUpdateEvent, AgentProcessUpdateEvent, AgentStreamEvent, AgentStreamEventBase, AgentThinkingUpdateEvent, AgentToolCallUpdateEvent, AgentUsageUpdateEvent, } from "#src/session/agent-stream-events";
|
|
21
|
+
export { type AdapterInteraction, type AdapterInteractionResponse, type InteractionHandler, NO_OP_INTERACTION_HANDLER, } from "#src/session/interaction-handler";
|
|
22
|
+
export type { ProtocolIds } from "#src/session/protocol-types";
|
|
23
|
+
export { type AgentSessionAdapter, type AuthStamp, type InteractionExchange, type InvalidToolCallDetail, type OpenSessionOpts, type SendTurnOpts, type SessionHandle, type SessionModel, SessionTurnError, type TrackedSpawnDeadlineOptions, type TurnResult, } from "#src/session/session-types";
|
|
24
|
+
export type { JSONSchema, ToolDescriptor, } from "#src/session/tool-descriptor";
|
|
25
|
+
export { createTurnDeadline, type TurnDeadline, } from "#src/session/turn-deadline";
|
|
26
|
+
export { adaptProviderTool, advertisedSchemaBytes, applyModelTruncationPolicy, BASH_TIMEOUT_MS, BASH_TOOL_NAME, buildCommitArgvs, buildGitArgv, buildGrepArgv, type CodingTool, type CodingToolName, type CodingToolOutcome, type CodingToolRuntime, classifyExec, compileToolPolicy, createBashTool, createCodingToolRuntime, createNoOpToolAuditSink, createRunCommandTool, createToolAuditSink, cutBufferToByteCap, DEFAULT_BASH_SHELL, DEFAULT_LOG_FORMAT, DEFAULT_LOG_MAX_COUNT, DEFAULT_TOOL_MAX_BYTES, DEFAULT_TOOL_MAX_FILE_BYTES, type DeclaredCommandRequest, type DeclaredCommandResult, type DeclaredCommandRunner, deleteTool, EXEC_TOOL_NAME, type ExecTarget, editTool, expandMcpRuleGrants, expandProviderGrants, flushOpenToolAuditSinks, GIT_ESCAPE_FLAGS, GIT_READ_VERBS, getCodingTool, gitCommitTool, gitExcludePathspecsOf, gitIgnorePatternsOf, gitTool, globTool, grepTool, isKnownManager, listCodingTools, MAX_PROVIDER_DESCRIPTION_BYTES, MAX_PROVIDER_SCHEMA_BYTES, MCP_RULE_TOOL, MODEL_MAX_BYTES, MODEL_MAX_LINE_CHARS, MODEL_MAX_LINES, type ModelTruncationOptions, mcpRuleAdmits, type NormalizeInput, type NormalizeResult, namespacedToolName, narrowGrants, normalizeExec, normalizeManagerBinary, type PolicyVerdict, PROVIDER_ID_RE, type ProtectedPathsPolicy, type ProviderGrantEntry, type ProviderKind, type ProviderTool, partitionMcpRules, partitionNaxOwnedPaths, providerAttachesTo, READ_CEILING, RESERVED_TOOL_NAMES, type ReadFileSliceOptions, type ReadFileSliceResult, type RegisteredSink, type ResolvedProviderTools, readFileSlice, readTool, registerBuiltinCodingTools, registerBuiltinTool, registerCodingTool, registerToolAuditSink, requestCapabilityTool, resolveProviderTools, resolveWithin, SCRATCHPAD_DIR, SPILL_DIR, type SpillRequest, sanitizeProviderTools, scratchpadListTool, scratchpadReadTool, scratchpadWriteTool, spillRelativePath, substituteCommand, substituteCommandSpec, type ToolAuditSink, type ToolCallContext, type ToolCallRecord, type ToolGrant, type ToolPatternNarrowing, type ToolPolicy, type ToolPolicyOptions, type ToolProvider, type ToolResult, type ToolRunContext, type ToolScope, type TruncateForModelOptions, type TruncationDirection, type TruncationResult, truncateForModel, truncationDirectionFor, unregisterToolAuditSink, validateProviderId, writeSpill, writeTool, } from "#src/tools/index";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nathapp/nax-agent public entry (S1 spec section 4.4, S2 spec section 5.3).
|
|
3
|
+
*
|
|
4
|
+
* Every export is named: nothing reaches this entry through `export *`. No "_"
|
|
5
|
+
* name belongs here; test seams and reset hooks live on ./internal. The built
|
|
6
|
+
* surface of both entries is pinned by api/nax-agent.api.txt (`bun run check:api`).
|
|
7
|
+
*
|
|
8
|
+
* Generated once by S2-7 from the previous `export *` barrels; maintained by hand.
|
|
9
|
+
*/
|
|
10
|
+
export { appendCommandSafetyRow, buildCommandShadow, buildRequest, COMMAND_SAFETY_DIR, createCommandGuard, createCommandShadow, createSystemOneClient, detectTmpWrite, HARM_OPTIONS, HARM_QUESTION_ID, isTempOnly, openShadowTap, parseAnswer, QUESTION_IDS, QUESTION_SET_VERSION, RULE_SET_VERSION, SYSTEMONE_MODEL_LABEL, scoreGuard, scoreRules, shadowCacheKey, toMechanical, } from "#src/command-safety/index";
|
|
11
|
+
export { addTokenUsage, estimateCostUsd, inputClassTokens, priceCall, } from "#src/cost/core/index";
|
|
12
|
+
export { parseModelSpec, } from "#src/cost/model-spec";
|
|
13
|
+
export { configureCredentials, setAgentLogger } from "#src/infra/index";
|
|
14
|
+
export { AuthCancelledError, ambientShadows, anyAmbientCredential, authImportOutcomeLabel, credentialFilePath, DEFAULT_PI_AUTH_PATH, importPiCredentials, listStoredProviders, MAX_RETAINED_TRANSCRIPTS, NATIVE_AGENT, NativeSessionAdapter, NativeSessionUnsupportedError, nativeComplete, nativeTierProviders, naxCredentialStore, newSessionKey, providersWithoutCredentials, pruneRetainedTranscripts, removeStoredProvider, resolveNativeId, runLogin, servedAuth, } from "#src/native/index";
|
|
15
|
+
export { ASK_CANCELLED_REASON, ASK_DENIED_REASON, ASK_NO_CHANNEL_REASON, ASK_TIMEOUT_REASON, ASK_UNAVAILABLE_REASON, ASK_UNSHOWABLE_REASON, appendApproval, appendApprovalAudit, approvalId, approvalsPath, chainAskLinks, clearApprovalsTaint, createApprovalsLink, findApproval, findSecretSpans, headlessAskResolver, isForgeCapable, lexBashCommand, maskForPrompt, parseRuleList, parseToolExpression, prepareApprovalsStore, readApprovals, readApprovalsFile, readApprovalsFileDetailed, redactForRow, redactRowStrings, removeApprovals, taintApprovals, writeApprovalsFile, } from "#src/permissions/index";
|
|
16
|
+
export { getAgentRuntime, nodeRuntime, setAgentRuntime, } from "#src/runtime/index";
|
|
17
|
+
export { buildSandboxPolicy, createCommandLauncher, createSrtBackend, DISABLED_SANDBOX_STATE, defaultTempRoots, denialHintLine, LIKELY_SANDBOX_DENIAL, listCredentialFiles, listGitGuardFiles, listNaxEntries, probeSandbox, probeSandboxOnce, quoteArgvForShell, rawBashRefusalReason, resetSandboxBackend, resolveGitLayout, runTempRoots, runTmpRoot, sandboxBackendFor, sandboxSentence, sessionTmpDir, sessionTmpDirUnder, strayCommonDirTripwire, unsandboxedSentence, warnSandboxUnavailableOnce, } from "#src/sandbox/index";
|
|
18
|
+
export { NO_OP_INTERACTION_HANDLER, } from "#src/session/interaction-handler";
|
|
19
|
+
export { SessionTurnError, } from "#src/session/session-types";
|
|
20
|
+
export { createTurnDeadline, } from "#src/session/turn-deadline";
|
|
21
|
+
export { adaptProviderTool, advertisedSchemaBytes, applyModelTruncationPolicy, BASH_TIMEOUT_MS, BASH_TOOL_NAME, buildCommitArgvs, buildGitArgv, buildGrepArgv, classifyExec, compileToolPolicy, createBashTool, createCodingToolRuntime, createNoOpToolAuditSink, createRunCommandTool, createToolAuditSink, cutBufferToByteCap, DEFAULT_BASH_SHELL, DEFAULT_LOG_FORMAT, DEFAULT_LOG_MAX_COUNT, DEFAULT_TOOL_MAX_BYTES, DEFAULT_TOOL_MAX_FILE_BYTES, deleteTool, EXEC_TOOL_NAME, editTool, expandMcpRuleGrants, expandProviderGrants, flushOpenToolAuditSinks, GIT_ESCAPE_FLAGS, GIT_READ_VERBS, getCodingTool, gitCommitTool, gitExcludePathspecsOf, gitIgnorePatternsOf, gitTool, globTool, grepTool, isKnownManager, listCodingTools, MAX_PROVIDER_DESCRIPTION_BYTES, MAX_PROVIDER_SCHEMA_BYTES, MCP_RULE_TOOL, MODEL_MAX_BYTES, MODEL_MAX_LINE_CHARS, MODEL_MAX_LINES, mcpRuleAdmits, namespacedToolName, narrowGrants, normalizeExec, normalizeManagerBinary, PROVIDER_ID_RE, partitionMcpRules, partitionNaxOwnedPaths, providerAttachesTo, READ_CEILING, RESERVED_TOOL_NAMES, readFileSlice, readTool, registerBuiltinCodingTools, registerBuiltinTool, registerCodingTool, registerToolAuditSink, requestCapabilityTool, resolveProviderTools, resolveWithin, SCRATCHPAD_DIR, SPILL_DIR, sanitizeProviderTools, scratchpadListTool, scratchpadReadTool, scratchpadWriteTool, spillRelativePath, substituteCommand, substituteCommandSpec, truncateForModel, truncationDirectionFor, unregisterToolAuditSink, validateProviderId, writeSpill, writeTool, } from "#src/tools/index";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The logger slot (spec R2). nax-agent logs through whatever logger the host
|
|
3
|
+
* installs; nax installs its own from `initLogger` and clears it in
|
|
4
|
+
* `resetLogger`.
|
|
5
|
+
*
|
|
6
|
+
* Unset semantics match nax's logger exactly: `getSafeLogger()` gives `null`
|
|
7
|
+
* (callers use `?.`), and `getLogger()` gives a silent no-op rather than
|
|
8
|
+
* throwing. nax's `getLogger()` returns a sink-less silent logger when
|
|
9
|
+
* uninitialised, so neither form has ever produced output before init.
|
|
10
|
+
*/
|
|
11
|
+
export interface AgentLogger {
|
|
12
|
+
error(stage: string, message: string, data?: Record<string, unknown>): void;
|
|
13
|
+
warn(stage: string, message: string, data?: Record<string, unknown>): void;
|
|
14
|
+
info(stage: string, message: string, data?: Record<string, unknown>): void;
|
|
15
|
+
debug(stage: string, message: string, data?: Record<string, unknown>): void;
|
|
16
|
+
}
|
|
17
|
+
/** Install (or, with `null`, clear) the process-wide logger. */
|
|
18
|
+
export declare function setAgentLogger(logger: AgentLogger | null): void;
|
|
19
|
+
/** The installed logger, or `null` when none is installed. */
|
|
20
|
+
export declare function getSafeLogger(): AgentLogger | null;
|
|
21
|
+
/** The installed logger, or a silent no-op when none is installed. Never throws. */
|
|
22
|
+
export declare function getLogger(): AgentLogger;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const noopLogger = {
|
|
2
|
+
error: () => { },
|
|
3
|
+
warn: () => { },
|
|
4
|
+
info: () => { },
|
|
5
|
+
debug: () => { },
|
|
6
|
+
};
|
|
7
|
+
let installed = null;
|
|
8
|
+
/** Install (or, with `null`, clear) the process-wide logger. */
|
|
9
|
+
export function setAgentLogger(logger) {
|
|
10
|
+
installed = logger;
|
|
11
|
+
}
|
|
12
|
+
/** The installed logger, or `null` when none is installed. */
|
|
13
|
+
export function getSafeLogger() {
|
|
14
|
+
return installed;
|
|
15
|
+
}
|
|
16
|
+
/** The installed logger, or a silent no-op when none is installed. Never throws. */
|
|
17
|
+
export function getLogger() {
|
|
18
|
+
return installed ?? noopLogger;
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Auth settings used by the native credential store. */
|
|
2
|
+
export interface CredentialAuthConfig {
|
|
3
|
+
readonly source: "file" | "exec";
|
|
4
|
+
readonly exec?: {
|
|
5
|
+
readonly command: readonly string[];
|
|
6
|
+
readonly timeoutMs: number;
|
|
7
|
+
};
|
|
8
|
+
readonly onChange: "warn" | "refuse";
|
|
9
|
+
}
|
|
10
|
+
/** Host functions the native credential store reads on demand. */
|
|
11
|
+
export interface CredentialsConfig {
|
|
12
|
+
/** The directory holding `credentials`, `config.json` and the fingerprint salt. Read per call. */
|
|
13
|
+
configDir(): string;
|
|
14
|
+
/** The auth section of the global config. Read per call. */
|
|
15
|
+
readAuthConfig(): Promise<CredentialAuthConfig>;
|
|
16
|
+
}
|
|
17
|
+
export declare function configureCredentials(config: CredentialsConfig): void;
|
|
18
|
+
export declare function credentialsConfig(): CredentialsConfig;
|
|
19
|
+
/** Clears the slot. Tests only. @internal */
|
|
20
|
+
export declare function _resetCredentialsConfig(): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NaxError } from "./nax-error.js";
|
|
2
|
+
let configured;
|
|
3
|
+
export function configureCredentials(config) {
|
|
4
|
+
configured = config;
|
|
5
|
+
}
|
|
6
|
+
export function credentialsConfig() {
|
|
7
|
+
if (configured === undefined) {
|
|
8
|
+
throw new NaxError("Credentials are not configured: call configureCredentials() before reading credentials", "CREDENTIALS_NOT_CONFIGURED", { stage: "credentials" });
|
|
9
|
+
}
|
|
10
|
+
return configured;
|
|
11
|
+
}
|
|
12
|
+
/** Clears the slot. Tests only. @internal */
|
|
13
|
+
export function _resetCredentialsConfig() {
|
|
14
|
+
configured = undefined;
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Extract error message from unknown error type.
|
|
6
|
+
*
|
|
7
|
+
* Handles both Error instances and non-Error values that can be thrown in JavaScript.
|
|
8
|
+
*/
|
|
9
|
+
export function errorMessage(err) {
|
|
10
|
+
return err instanceof Error ? err.message : String(err);
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nax-agent infrastructure (spec R2): the error base class and the process-wide
|
|
3
|
+
* slots nax fills. Imports nothing from nax.
|
|
4
|
+
*/
|
|
5
|
+
export { type AgentLogger, getLogger, getSafeLogger, setAgentLogger } from "./agent-logger.ts";
|
|
6
|
+
export { _resetCredentialsConfig, type CredentialAuthConfig, type CredentialsConfig, configureCredentials, credentialsConfig, } from "./credentials-config.ts";
|
|
7
|
+
export { NaxError } from "./nax-error.ts";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nax-agent infrastructure (spec R2): the error base class and the process-wide
|
|
3
|
+
* slots nax fills. Imports nothing from nax.
|
|
4
|
+
*/
|
|
5
|
+
export { getLogger, getSafeLogger, setAgentLogger } from "./agent-logger.js";
|
|
6
|
+
export { _resetCredentialsConfig, configureCredentials, credentialsConfig, } from "./credentials-config.js";
|
|
7
|
+
export { NaxError } from "./nax-error.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all nax errors. Lives in the move set (spec R2);
|
|
3
|
+
* `src/errors.ts` re-exports it so every `instanceof NaxError` check matches
|
|
4
|
+
* one class.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NaxError extends Error {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
9
|
+
constructor(message: string, code: string, context?: Record<string, unknown> | undefined);
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all nax errors. Lives in the move set (spec R2);
|
|
3
|
+
* `src/errors.ts` re-exports it so every `instanceof NaxError` check matches
|
|
4
|
+
* one class.
|
|
5
|
+
*/
|
|
6
|
+
export class NaxError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
context;
|
|
9
|
+
constructor(message, code, context) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.context = context;
|
|
13
|
+
this.name = "NaxError";
|
|
14
|
+
Error.captureStackTrace(this, this.constructor);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repetition breaker for an agent turn.
|
|
3
|
+
*
|
|
4
|
+
* A verifier session ran 36 minutes re-running the same PASSING scoped test
|
|
5
|
+
* 622 times, emitted no verdict, and was ended by an operator (nax#2013). Every
|
|
6
|
+
* call was fast and exited 0, so there was no timeout, no error rate and no
|
|
7
|
+
* failing gate to trip; what distinguished it was repetition without progress
|
|
8
|
+
* — 622 calls across 2 distinct argv shapes and no file writes.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately NOT a round-trip cap. That was removed twice on purpose
|
|
11
|
+
* (#1823/#1827/#1830, then #1819/#1820) and a session making 600 VARIED calls
|
|
12
|
+
* is working, not spinning. This counts only calls whose normalised shape was
|
|
13
|
+
* already seen.
|
|
14
|
+
*
|
|
15
|
+
* Transport-neutral and config-free by construction: it takes resolved
|
|
16
|
+
* settings, so `src/agents/native/` can consult it without reading NaxConfig
|
|
17
|
+
* (check:adapter-no-config-import).
|
|
18
|
+
*/
|
|
19
|
+
export interface ResolvedSpinBreakerSettings {
|
|
20
|
+
readonly enabled: boolean;
|
|
21
|
+
/** Repeats since the last new call before the first nudge. */
|
|
22
|
+
readonly nudgeAfterRepeats: number;
|
|
23
|
+
/** How many nudges to spend before the hard stop. */
|
|
24
|
+
readonly maxNudges: number;
|
|
25
|
+
/**
|
|
26
|
+
* Repeats since the last new call at which the turn ends, AND the raw
|
|
27
|
+
* per-key backstop. Overloaded: `stopAfterSameKeyRepeats` gates the
|
|
28
|
+
* consecutive-identical-result threshold, while the same key's raw
|
|
29
|
+
* cumulative count is separately capped here. That backstop is the only
|
|
30
|
+
* thing that bounds a call whose result changes every time (or never
|
|
31
|
+
* reaches `noteResult`), which the result axis cannot see.
|
|
32
|
+
*/
|
|
33
|
+
readonly stopAfterRepeats: number;
|
|
34
|
+
/** How many recent distinct keys count as "already seen". */
|
|
35
|
+
readonly recentKeyWindow: number;
|
|
36
|
+
/**
|
|
37
|
+
* Consecutive occurrences of the same call whose RESULT was unchanged at
|
|
38
|
+
* which the turn ends — the consecutive same-result run, NOT the raw
|
|
39
|
+
* per-key count (which `stopAfterRepeats` caps). This is the axis that
|
|
40
|
+
* closes the nax#2047 laundering hole (a different key firing between
|
|
41
|
+
* occurrences no longer resets the run) without killing a healthy
|
|
42
|
+
* edit -> re-run-test loop, whose result changes each iteration. `0`
|
|
43
|
+
* disables this axis.
|
|
44
|
+
*/
|
|
45
|
+
readonly stopAfterSameKeyRepeats: number;
|
|
46
|
+
/**
|
|
47
|
+
* nax#2017: seconds with no new call key after which a repeat run ends the turn, so a slow spin
|
|
48
|
+
* stops as fail-spin before the tool-call-only idle watchdog cancels it as fail-stale. 0 disables.
|
|
49
|
+
*/
|
|
50
|
+
readonly stopAfterNoProgressSeconds: number;
|
|
51
|
+
}
|
|
52
|
+
export declare const DEFAULT_SPIN_BREAKER_SETTINGS: ResolvedSpinBreakerSettings;
|
|
53
|
+
/** Why the breaker ended the turn. Kept exhaustive so telemetry is accurate. */
|
|
54
|
+
export type SpinStopReason = "repeat-run" | "same-key-cumulative" | "same-key-backstop" | "no-progress-time";
|
|
55
|
+
export type SpinVerdict = {
|
|
56
|
+
readonly action: "allow";
|
|
57
|
+
} | {
|
|
58
|
+
readonly action: "nudge";
|
|
59
|
+
readonly nudgeNumber: number;
|
|
60
|
+
readonly repeats: number;
|
|
61
|
+
readonly text: string;
|
|
62
|
+
} | {
|
|
63
|
+
readonly action: "stop";
|
|
64
|
+
readonly repeats: number;
|
|
65
|
+
readonly reason: SpinStopReason;
|
|
66
|
+
};
|
|
67
|
+
export interface SpinSummary {
|
|
68
|
+
readonly totalCalls: number;
|
|
69
|
+
/**
|
|
70
|
+
* Cache-misses against the bounded `recentKeyWindow`, i.e. how many times
|
|
71
|
+
* this session did something new. Equal to true key cardinality only while
|
|
72
|
+
* the session's distinct-key count stays within `recentKeyWindow` — once a
|
|
73
|
+
* key is evicted from the window, seeing it again counts as another new-key
|
|
74
|
+
* event, so this is NOT a reliable "unique calls this session made" count
|
|
75
|
+
* for a long session. Deliberately not backed by an unbounded Set: the
|
|
76
|
+
* window exists to bound memory, and "how many new things happened" is the
|
|
77
|
+
* more useful number for a spin diagnostic anyway.
|
|
78
|
+
*/
|
|
79
|
+
readonly newKeyEvents: number;
|
|
80
|
+
readonly maxRepeatRun: number;
|
|
81
|
+
/**
|
|
82
|
+
* Highest cumulative repeat count observed for a single key (nax#2047).
|
|
83
|
+
* Same windowing tradeoff as `newKeyEvents`: an evicted key loses its
|
|
84
|
+
* count, so this is the peak within the current window rather than a
|
|
85
|
+
* session-lifetime peak. The `maxRepeatRun` field above stays the
|
|
86
|
+
* instrument for #2013's 622-call varied verifier; this is the new
|
|
87
|
+
* instrument for the laundering hole — they answer different questions.
|
|
88
|
+
*/
|
|
89
|
+
readonly maxSameKeyRepeats: number;
|
|
90
|
+
readonly nudges: number;
|
|
91
|
+
}
|
|
92
|
+
export interface SpinBreaker {
|
|
93
|
+
observe(toolName: string, input: unknown): SpinVerdict;
|
|
94
|
+
/**
|
|
95
|
+
* Feed back what a call returned. `observe` runs pre-execution, so the
|
|
96
|
+
* result of occurrence N is only known when occurrence N+1 is judged —
|
|
97
|
+
* that one-call lag is intentional and harmless at these thresholds.
|
|
98
|
+
* A call that throws never reaches here (an error string is not a result),
|
|
99
|
+
* so it falls back to the raw backstop inside `observe`. A DENIED call
|
|
100
|
+
* does reach here (turn-loop feeds `answer.answer`): a stable denial is an
|
|
101
|
+
* unchanged result and is intended to count toward the same-result run.
|
|
102
|
+
*/
|
|
103
|
+
noteResult(toolName: string, input: unknown, resultText: string): void;
|
|
104
|
+
summary(): SpinSummary;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Answered to every outstanding call when the breaker first decides to end a
|
|
108
|
+
* turn (nax#2120). The stop used to break with the call unexecuted and
|
|
109
|
+
* unanswered, so the turn was classified `fail-spin` and retried on the
|
|
110
|
+
* timeout lane — a FRESH session at a reduced budget, discarding everything
|
|
111
|
+
* the turn had accumulated. One terminal round trip lets the model close out
|
|
112
|
+
* instead. NUDGE_ESCALATION's final warning is one step ahead of the hard
|
|
113
|
+
* end, not literally true: the first stop only warns (this notice) and only a
|
|
114
|
+
* further stop verdict ends the turn.
|
|
115
|
+
*/
|
|
116
|
+
export declare const SPIN_TERMINAL_NOTICE: string;
|
|
117
|
+
export declare function spinTerminalNotice(reason: SpinStopReason): string;
|
|
118
|
+
export declare function createSpinBreaker(settings: ResolvedSpinBreakerSettings, deps?: {
|
|
119
|
+
readonly now?: () => number;
|
|
120
|
+
}): SpinBreaker;
|