@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,456 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-protocol types — the shapes exchanged across the openSession / sendTurn /
|
|
3
|
+
* closeSession boundary, split out of types.ts under the file-size ratchet (#1702).
|
|
4
|
+
*
|
|
5
|
+
* Nothing here imports back into types.ts, so the split adds no import cycle:
|
|
6
|
+
* the dependency runs one way. `types.ts` stayed in nax
|
|
7
|
+
* (`packages/nax/src/agents/types.ts`) and reaches this module through the
|
|
8
|
+
* `@nathapp/nax-agent` entry. It re-exports a *selected subset* — the session
|
|
9
|
+
* protocol's public contract — so existing `@/agents/types` import sites keep
|
|
10
|
+
* working; a consumer of anything outside that subset (`AuthStamp`,
|
|
11
|
+
* `InvalidToolCallDetail`) imports it from `@nathapp/nax-agent` directly.
|
|
12
|
+
*/
|
|
13
|
+
import type { Pricing, PricingRates, TokenUsage } from "#src/cost/standard-types";
|
|
14
|
+
import type { ResolvedPermissions } from "#src/permissions/index";
|
|
15
|
+
import type { ProtocolIds } from "#src/session/protocol-types";
|
|
16
|
+
import type { AdapterFailure } from "./adapter-failure.ts";
|
|
17
|
+
import type { ToolDescriptor } from "./tool-descriptor.ts";
|
|
18
|
+
/**
|
|
19
|
+
* Identity of the credential that served a call (US-002).
|
|
20
|
+
*
|
|
21
|
+
* Deliberately carries no secret: `fingerprint` is the keyed digest, and
|
|
22
|
+
* `source` / `account` say where the credential came from without exposing it.
|
|
23
|
+
* Declared here — once — so every consumer imports one definition rather than
|
|
24
|
+
* re-spelling the shape.
|
|
25
|
+
*/
|
|
26
|
+
export interface AuthStamp {
|
|
27
|
+
/** Keyed credential digest (see `fingerprint.ts`). Not comparable across machines. */
|
|
28
|
+
fingerprint: string;
|
|
29
|
+
/** Where the credential was read from. */
|
|
30
|
+
source: "file" | "exec";
|
|
31
|
+
/** Account label the source reported, when it reports one. */
|
|
32
|
+
account?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The model a session runs on, in the contract's own vocabulary (S1 spec section
|
|
36
|
+
* 4.2, port 2). nax builds it from its config `ModelDef` with `toSessionModel`
|
|
37
|
+
* (`packages/nax/src/agents/session-model-mapping.ts`); `pricing` is already
|
|
38
|
+
* converted to the standard rate card, so the session never sees config field
|
|
39
|
+
* names.
|
|
40
|
+
*/
|
|
41
|
+
export interface SessionModel {
|
|
42
|
+
readonly provider: string;
|
|
43
|
+
readonly model: string;
|
|
44
|
+
/** Explicit rate override; absent means "price from the catalog". */
|
|
45
|
+
readonly pricing?: Pricing;
|
|
46
|
+
/** Overrides the catalog context window for compaction maths only (nax#1848). */
|
|
47
|
+
readonly contextWindow?: number;
|
|
48
|
+
/** Extra environment for transports that spawn a process (ACP). */
|
|
49
|
+
readonly env?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
/** trackedSpawn hard deadlines (ms) — teardown vs startup, resolved from config.agent.acp (#1583). */
|
|
52
|
+
export interface TrackedSpawnDeadlineOptions {
|
|
53
|
+
trackedSpawnDeadlineMs?: number;
|
|
54
|
+
trackedSpawnStartupDeadlineMs?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Opaque handle to an open agent session returned by openSession().
|
|
58
|
+
* ACP adapter stores protocol state here; callers above the adapter boundary
|
|
59
|
+
* only see the id, agentName, and optional protocolIds.
|
|
60
|
+
*/
|
|
61
|
+
export interface SessionHandle {
|
|
62
|
+
/** Protocol-agnostic session identifier (equals the ACP session name). */
|
|
63
|
+
readonly id: string;
|
|
64
|
+
/** Agent name this session was opened for. */
|
|
65
|
+
readonly agentName: string;
|
|
66
|
+
/**
|
|
67
|
+
* Session role, opaque to the adapter. nax writes a canonical role; read it
|
|
68
|
+
* through `knownSessionRole`.
|
|
69
|
+
*/
|
|
70
|
+
readonly role?: string;
|
|
71
|
+
/** Protocol-specific IDs for SessionManager correlation. */
|
|
72
|
+
readonly protocolIds?: ProtocolIds;
|
|
73
|
+
/**
|
|
74
|
+
* Model this session was opened with. Recorded on every turn's cost row so
|
|
75
|
+
* spend is attributable to a model (#1433) — before this, cost rows carried
|
|
76
|
+
* the literal string "unknown". Attribution, and the session's endpoint identity: `decideReuse`
|
|
77
|
+
* (session/endpoint-identity.ts) compares it to decide whether a re-open under
|
|
78
|
+
* the same session name may serve this handle, and the native adapter's
|
|
79
|
+
* `sendTurn` dispatches from it. Do not branch on it for anything else.
|
|
80
|
+
*/
|
|
81
|
+
readonly modelDef?: SessionModel;
|
|
82
|
+
/** Tier `modelDef` resolved from, when it came from one. Attribution only. */
|
|
83
|
+
readonly modelTier?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Options for openSession() — protocol-agnostic surface + ACP-specific pass-throughs. */
|
|
86
|
+
export interface OpenSessionOpts extends TrackedSpawnDeadlineOptions {
|
|
87
|
+
agentName: string;
|
|
88
|
+
workdir: string;
|
|
89
|
+
/** Pre-resolved permissions from AgentManager. */
|
|
90
|
+
resolvedPermissions: ResolvedPermissions;
|
|
91
|
+
/** The model to open with. nax builds it with `toSessionModel`. */
|
|
92
|
+
modelDef: SessionModel;
|
|
93
|
+
/** Tier the model resolved from, when applicable. Attribution only (#1433). */
|
|
94
|
+
modelTier?: string;
|
|
95
|
+
/** ACP: maximum session duration in seconds. */
|
|
96
|
+
timeoutSeconds: number;
|
|
97
|
+
/** ACP: acpx --prompt-retries value (default 0 — opt-in). */
|
|
98
|
+
promptRetries?: number;
|
|
99
|
+
/** Fired once the session is physically established, before the first prompt. */
|
|
100
|
+
onSessionEstablished?: (protocolIds: ProtocolIds, sessionName: string) => void;
|
|
101
|
+
/** PID registration callback for crash-recovery bookkeeping. */
|
|
102
|
+
onPidSpawned?: (pid: number) => void;
|
|
103
|
+
/**
|
|
104
|
+
* PID unregistration callback. Called when an acpx subprocess associated with this
|
|
105
|
+
* session exits naturally — keeps PidRegistry from accumulating dead PIDs.
|
|
106
|
+
*/
|
|
107
|
+
onPidExited?: (pid: number) => void;
|
|
108
|
+
/** Abort signal — if already aborted, openSession rejects immediately. */
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
/**
|
|
111
|
+
* When true, the session name is expected to already exist in the adapter's
|
|
112
|
+
* store. The adapter should prefer resuming over creating a fresh session.
|
|
113
|
+
* Set by SessionManager.openSession when a descriptor is found.
|
|
114
|
+
*/
|
|
115
|
+
resume?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Generic per-call lifecycle hook — invoked by the adapter when a physical
|
|
118
|
+
* agent invocation begins, with a stable `callId` and an opaque cancel
|
|
119
|
+
* function. The wiring layer uses this to register `cancel` in any per-call
|
|
120
|
+
* cancellation registry it owns (e.g. the idle watchdog). The adapter does
|
|
121
|
+
* not know what the consumer does with the cancel handle. Depopulation of
|
|
122
|
+
* any registry happens via the `agent.call_ended` event on the stream bus.
|
|
123
|
+
*/
|
|
124
|
+
onActiveCall?: (callId: string, cancel: () => Promise<void>) => void;
|
|
125
|
+
/**
|
|
126
|
+
* Stream activity callback forwarded from NaxRuntime.agentStreamEvents.
|
|
127
|
+
* The adapter passes this to the underlying AcpClient so prompt-level events
|
|
128
|
+
* (call_started, message_update, call_ended, etc.) are emitted on the runtime
|
|
129
|
+
* bus. Required for the idle watchdog to track calls.
|
|
130
|
+
*/
|
|
131
|
+
onStreamActivity?: (event: import("#src/session/agent-stream-events").AgentStreamEvent) => void;
|
|
132
|
+
/**
|
|
133
|
+
* Native: directory the session's transcript file lives in. Supplied by
|
|
134
|
+
* SessionManager because the adapter cannot derive it — openSession runs
|
|
135
|
+
* before the SessionDescriptor exists (manager.ts:472 vs :492), and no
|
|
136
|
+
* scratch dir reaches the adapter otherwise. ACP ignores it.
|
|
137
|
+
*/
|
|
138
|
+
transcriptDir?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Native: identity that owns this session's transcript — the op invocation's
|
|
141
|
+
* `scopeId ?? callId`. Stable across the retries and hops of one invocation,
|
|
142
|
+
* different for every new stage entry, run and process, which is exactly the
|
|
143
|
+
* boundary transcript resumption must respect (nax#1877). ACP ignores it.
|
|
144
|
+
*/
|
|
145
|
+
transcriptOwner?: string;
|
|
146
|
+
/**
|
|
147
|
+
* Native: resolved compaction settings. A resolved primitive, never NaxConfig —
|
|
148
|
+
* src/agents/native/ must not read config (check:adapter-no-config-import).
|
|
149
|
+
*/
|
|
150
|
+
compaction?: import("#src/native/session/compaction").ResolvedCompaction;
|
|
151
|
+
/**
|
|
152
|
+
* Native: resolved transport-fault retry settings (nax#1870), threaded the
|
|
153
|
+
* same way as `compaction` — a resolved primitive, never NaxConfig. ACP
|
|
154
|
+
* ignores it; acpx has its own knob (`promptRetries`).
|
|
155
|
+
*/
|
|
156
|
+
transportRetry?: import("#src/native/session/turn-retry").TurnRetryConfig;
|
|
157
|
+
/**
|
|
158
|
+
* Native: resolved repetition-breaker settings (nax#2013), threaded the same
|
|
159
|
+
* way as `compaction` and `transportRetry` — a resolved primitive, never
|
|
160
|
+
* NaxConfig. ACP ignores it; its loop is bounded by `maxInteractions`.
|
|
161
|
+
*/
|
|
162
|
+
spinBreaker?: import("#src/infra/spin-breaker/index").ResolvedSpinBreakerSettings;
|
|
163
|
+
}
|
|
164
|
+
/** Options for sendTurn(). */
|
|
165
|
+
export interface SendTurnOpts {
|
|
166
|
+
/** Unified callback for context-tool calls and agent questions. */
|
|
167
|
+
interactionHandler: import("./interaction-handler.ts").InteractionHandler;
|
|
168
|
+
/** Native-only in-process loop-event registrations for this turn. ACP ignores this. */
|
|
169
|
+
loopEvents?: import("#src/native/session/loop-events/index").LoopEventRegistry;
|
|
170
|
+
/**
|
|
171
|
+
* Native: the run's plugin-contributed loop handlers (US-003), attached by
|
|
172
|
+
* `SessionManager.sendPrompt`. The adapter forwards them into the turn's
|
|
173
|
+
* deps, where `registerBuiltinLoopHandlers` installs them between the
|
|
174
|
+
* built-ins. ACP ignores this.
|
|
175
|
+
*/
|
|
176
|
+
loopHandlers?: import("#src/native/session/loop-events/index").LoopHandlerSet;
|
|
177
|
+
/**
|
|
178
|
+
* Native: the read-only facts every plugin handler is handed (US-003). ACP
|
|
179
|
+
* ignores this.
|
|
180
|
+
*/
|
|
181
|
+
loopHandlerContext?: import("#src/native/session/loop-events/index").LoopHandlerContext;
|
|
182
|
+
/** Abort signal for mid-turn cancellation. */
|
|
183
|
+
signal?: AbortSignal;
|
|
184
|
+
/**
|
|
185
|
+
* Human/context interaction budget for this turn, from
|
|
186
|
+
* `agent.maxInteractionTurns` (default: 10).
|
|
187
|
+
*
|
|
188
|
+
* NOT an agent round-trip cap, and the two transports spend it on
|
|
189
|
+
* different things — see each adapter's read site. It was called
|
|
190
|
+
* `maxTurns` until issue #1829, which is how issue #1820 happened: the
|
|
191
|
+
* native loop spent the Q&A budget as its round-trip cap and truncated
|
|
192
|
+
* real work at 10.
|
|
193
|
+
*/
|
|
194
|
+
maxInteractions?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Native: pull-tool catalogue for this turn, sent as structured tool
|
|
197
|
+
* definitions. Under ACP the same catalogue is rendered into the prompt
|
|
198
|
+
* instead, so that path ignores this.
|
|
199
|
+
*/
|
|
200
|
+
contextPullTools?: readonly ToolDescriptor[];
|
|
201
|
+
/** Coding tools advertised to the model this turn (already policy-filtered). */
|
|
202
|
+
codingTools?: readonly import("#src/tools/index").CodingTool[];
|
|
203
|
+
/**
|
|
204
|
+
* Identity for THIS turn, minted by `runAsSession` before the turn runs.
|
|
205
|
+
*
|
|
206
|
+
* One turn is one cost row, so this is the field that selects a single row —
|
|
207
|
+
* `callId` spans retries and hops and cannot. Minted ahead of `sendPrompt`
|
|
208
|
+
* precisely so tool calls made during the turn can carry it.
|
|
209
|
+
*/
|
|
210
|
+
turnId?: string;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* A single mid-turn interactive Q&A exchange between the agent and a human
|
|
214
|
+
* operator (routed via the interaction plugin), captured for the prompt-audit
|
|
215
|
+
* trail (issue #1226).
|
|
216
|
+
*/
|
|
217
|
+
export interface InteractionExchange {
|
|
218
|
+
/** Internal round-trip index (1-based) at which the question was asked. */
|
|
219
|
+
readonly turnIndex: number;
|
|
220
|
+
/** The agent's question text, as surfaced to the operator. */
|
|
221
|
+
readonly question: string;
|
|
222
|
+
/** The operator's verbatim reply (or the configured fallback on timeout). */
|
|
223
|
+
readonly reply: string;
|
|
224
|
+
}
|
|
225
|
+
export interface TurnResult {
|
|
226
|
+
/** Final assistant output from the last ACP response. */
|
|
227
|
+
output: string;
|
|
228
|
+
/** Accumulated token usage across all turns. */
|
|
229
|
+
tokenUsage: TokenUsage;
|
|
230
|
+
/** Estimated cost from token usage × pricing rates (always present). */
|
|
231
|
+
estimatedCostUsd: number;
|
|
232
|
+
/** Exact cost reported by wire protocol (when available). */
|
|
233
|
+
exactCostUsd?: number;
|
|
234
|
+
/** Number of session.prompt() calls made. */
|
|
235
|
+
internalRoundTrips: number;
|
|
236
|
+
/**
|
|
237
|
+
* Which rate card priced this turn (US-003, first half of #1817).
|
|
238
|
+
* `"catalog-rates"` means nax-ai's catalog; `"config-override"` means an
|
|
239
|
+
* explicit `modelDef.pricing` won wholesale; `"fallback-rates"` means the
|
|
240
|
+
* generic $3/$15-per-1M card applied because nothing more specific
|
|
241
|
+
* resolved. Set by adapters that resolve a rate card — native (US-003)
|
|
242
|
+
* and ACP, which stamps its card's branch on every result (US-002).
|
|
243
|
+
* Absent only when the adapter resolved no card.
|
|
244
|
+
*/
|
|
245
|
+
pricingSource?: "catalog-rates" | "config-override" | "fallback-rates";
|
|
246
|
+
/**
|
|
247
|
+
* The per-1M rates that priced this turn — US-002. Stamped from
|
|
248
|
+
* `priceCall(usage, rates).resolvedRates` so the cost row can record the
|
|
249
|
+
* same numbers whose arithmetic reproduces `estimatedCostUsd`. ACP
|
|
250
|
+
* present only when nonzero usage let pricing run; absent on a zeroed
|
|
251
|
+
* accumulator so "priced" and "did not price" stay distinguishable.
|
|
252
|
+
*/
|
|
253
|
+
rates?: PricingRates;
|
|
254
|
+
/** US-006: identity of the credential that served this turn. Absent for ACP turns. */
|
|
255
|
+
auth?: AuthStamp;
|
|
256
|
+
/**
|
|
257
|
+
* Mid-turn human-in-the-loop Q&A exchanges captured during the session turn
|
|
258
|
+
* (issue #1226). Each entry pairs the agent's question with the operator's
|
|
259
|
+
* verbatim reply and the internal round-trip index at which it occurred.
|
|
260
|
+
* Omitted when no interactive question was answered — context-tool round-trips
|
|
261
|
+
* are NOT recorded here. Surfaced onto DispatchEvent and the prompt audit trail.
|
|
262
|
+
*/
|
|
263
|
+
interactions?: readonly InteractionExchange[];
|
|
264
|
+
/**
|
|
265
|
+
* Coding tools advertised to this turn, and the ones the model actually
|
|
266
|
+
* invoked. Present only when coding tools were advertised, so "absent" and
|
|
267
|
+
* "advertised but unused" stay distinguishable — the review guards treat
|
|
268
|
+
* those two cases differently.
|
|
269
|
+
*
|
|
270
|
+
* A turn-observed fact surfaced to the wiring layer, like `interactions`.
|
|
271
|
+
*/
|
|
272
|
+
codingToolUse?: {
|
|
273
|
+
readonly advertised: number;
|
|
274
|
+
readonly called: readonly string[];
|
|
275
|
+
};
|
|
276
|
+
/** Protocol-specific IDs for prompt-audit correlation. */
|
|
277
|
+
protocolIds?: ProtocolIds;
|
|
278
|
+
/**
|
|
279
|
+
* Set when the hop body synthesises a failure (e.g. empty output) rather than
|
|
280
|
+
* receiving a real adapter error. Propagated through buildHopCallback into
|
|
281
|
+
* AgentResult.adapterFailure so the manager's swap/retry policy sees the correct
|
|
282
|
+
* outcome (e.g. `fail-stale` on empty output).
|
|
283
|
+
*/
|
|
284
|
+
adapterFailure?: AdapterFailure;
|
|
285
|
+
/**
|
|
286
|
+
* Transport fact: `sendTurn()` returned because its wall-clock timeout
|
|
287
|
+
* elapsed. The adapter never classifies _why_ — the wiring layer (callOp
|
|
288
|
+
* via turn-failure-classification) maps empty timed-out output to the
|
|
289
|
+
* `fail-timeout` policy outcome. Absent or false when the turn completed
|
|
290
|
+
* normally or was aborted.
|
|
291
|
+
*/
|
|
292
|
+
timedOut?: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Transport fact: the loop returned while the model still had tool calls
|
|
295
|
+
* pending — it asked for work that was never executed and never answered.
|
|
296
|
+
*
|
|
297
|
+
* Defined by the condition, not by enumerating exits, so its meaning is
|
|
298
|
+
* stable as the exits change: today the round-trip cap, the whole-turn
|
|
299
|
+
* deadline and an abort can all produce it; once the cap is removed only the
|
|
300
|
+
* deadline and abort can. Like `timedOut`, the adapter never classifies WHY —
|
|
301
|
+
* the wiring layer does (see operations/turn-failure-classification.ts).
|
|
302
|
+
*/
|
|
303
|
+
turnIncomplete?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Transport fact: the loop returned because the spin breaker stopped it —
|
|
306
|
+
* the model kept issuing calls whose shape it had already issued, with no
|
|
307
|
+
* new work between them (nax#2013).
|
|
308
|
+
*
|
|
309
|
+
* Like `timedOut` and `turnIncomplete`, the adapter never classifies WHY; the
|
|
310
|
+
* wiring layer maps it to the `fail-spin` policy outcome
|
|
311
|
+
* (operations/call-hop-output.ts). A spin-stopped turn also sets
|
|
312
|
+
* `turnIncomplete`, since work the model asked for was left unexecuted.
|
|
313
|
+
*/
|
|
314
|
+
spinStopped?: true;
|
|
315
|
+
/**
|
|
316
|
+
* Transport fact: the loop returned because three identical invalid tool
|
|
317
|
+
* calls — same tool, same `stableStringify`'d input — repeated in this turn
|
|
318
|
+
* (nax#2047, Task 4). A malformed shape is a stronger signal than spin
|
|
319
|
+
* repetition: it is never going to recover by being issued again.
|
|
320
|
+
*
|
|
321
|
+
* A sibling flag rather than a value of `spinStopped` because the
|
|
322
|
+
* classification channels are distinct (the wiring layer maps each to a
|
|
323
|
+
* different policy outcome). Like `spinStopped`, a budget-stopped turn also
|
|
324
|
+
* sets `turnIncomplete`, since the third call was left unexecuted.
|
|
325
|
+
*/
|
|
326
|
+
invalidCallBudgetExceeded?: true;
|
|
327
|
+
/**
|
|
328
|
+
* The call that tripped the invalid-call budget, present exactly when
|
|
329
|
+
* `invalidCallBudgetExceeded` is (nax#2200). Carried so the wiring layer can
|
|
330
|
+
* classify the halt as `fail-invalid-tool-call` and the retry prompt can name
|
|
331
|
+
* the rejected tool and property instead of reporting a timeout.
|
|
332
|
+
*/
|
|
333
|
+
invalidToolCall?: InvalidToolCallDetail;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* A tool call the native loop rejected against the tool's own input schema
|
|
337
|
+
* (nax#2047, surfaced by nax#2200): the validator's violation plus the tool it
|
|
338
|
+
* was raised against. Every field is model-facing text for the retry prompt.
|
|
339
|
+
*/
|
|
340
|
+
export interface InvalidToolCallDetail {
|
|
341
|
+
/** The tool the model called. */
|
|
342
|
+
readonly tool: string;
|
|
343
|
+
/** The offending top-level property. */
|
|
344
|
+
readonly property: string;
|
|
345
|
+
/** What the schema expects, e.g. "array", "one of: a, b", "present". */
|
|
346
|
+
readonly expected: string;
|
|
347
|
+
/** What the model sent, e.g. "a string", "absent". */
|
|
348
|
+
readonly actual: string;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Throwable form of TurnResult. Surfaced by `sendTurn()` when the underlying
|
|
352
|
+
* session ended with `stopReason === "error"`. Carries `cancelled: true`
|
|
353
|
+
* when the failure was caused by an external cancel (`cancelActivePrompt()`),
|
|
354
|
+
* so the wiring layer (SessionManager) can classify it as `fail-stale`
|
|
355
|
+
* without the adapter naming a policy outcome.
|
|
356
|
+
*/
|
|
357
|
+
export declare class SessionTurnError extends Error {
|
|
358
|
+
readonly cancelled: boolean;
|
|
359
|
+
readonly retryable: boolean;
|
|
360
|
+
/**
|
|
361
|
+
* BUG-57: token usage accumulated across all turns of the sendTurn() call,
|
|
362
|
+
* including the turn that ended in stopReason:"error" (e.g. a mid-flight
|
|
363
|
+
* cancel). Callers that catch SessionTurnError (build-hop-callback.ts,
|
|
364
|
+
* session-run-hop.ts) must read cost/tokens from here instead of
|
|
365
|
+
* hardcoding zero — tokens already burned before the failure are real
|
|
366
|
+
* spend and must not be dropped from cost accounting.
|
|
367
|
+
*/
|
|
368
|
+
readonly tokenUsage?: TokenUsage | undefined;
|
|
369
|
+
readonly estimatedCostUsd?: number | undefined;
|
|
370
|
+
readonly exactCostUsd?: number | undefined;
|
|
371
|
+
/**
|
|
372
|
+
* US-002: which rate card priced the failed turn's accumulated spend.
|
|
373
|
+
* Set by the ACP adapter (`rateCard.source` — `"catalog-rates"` |
|
|
374
|
+
* `"fallback-rates"`); the native adapter's protocol-fault path does not
|
|
375
|
+
* set it, so the field is optional and absent there.
|
|
376
|
+
*/
|
|
377
|
+
readonly pricingSource?: "catalog-rates" | "fallback-rates" | undefined;
|
|
378
|
+
/**
|
|
379
|
+
* nax#1840: the native path throws exactly one class per turn failure, so
|
|
380
|
+
* classification (normally read off SessionFailureError.adapterFailure)
|
|
381
|
+
* and cost (read off this class) cannot both be carried unless one class
|
|
382
|
+
* carries both. Left undefined by the ACP path, which still throws
|
|
383
|
+
* SessionFailureError for its own classified faults — this field only
|
|
384
|
+
* ever gets set by native's sendTurn.
|
|
385
|
+
*/
|
|
386
|
+
readonly adapterFailure?: AdapterFailure | undefined;
|
|
387
|
+
constructor(message: string, cancelled: boolean, retryable?: boolean,
|
|
388
|
+
/**
|
|
389
|
+
* BUG-57: token usage accumulated across all turns of the sendTurn() call,
|
|
390
|
+
* including the turn that ended in stopReason:"error" (e.g. a mid-flight
|
|
391
|
+
* cancel). Callers that catch SessionTurnError (build-hop-callback.ts,
|
|
392
|
+
* session-run-hop.ts) must read cost/tokens from here instead of
|
|
393
|
+
* hardcoding zero — tokens already burned before the failure are real
|
|
394
|
+
* spend and must not be dropped from cost accounting.
|
|
395
|
+
*/
|
|
396
|
+
tokenUsage?: TokenUsage | undefined, estimatedCostUsd?: number | undefined, exactCostUsd?: number | undefined,
|
|
397
|
+
/**
|
|
398
|
+
* US-002: which rate card priced the failed turn's accumulated spend.
|
|
399
|
+
* Set by the ACP adapter (`rateCard.source` — `"catalog-rates"` |
|
|
400
|
+
* `"fallback-rates"`); the native adapter's protocol-fault path does not
|
|
401
|
+
* set it, so the field is optional and absent there.
|
|
402
|
+
*/
|
|
403
|
+
pricingSource?: "catalog-rates" | "fallback-rates" | undefined,
|
|
404
|
+
/**
|
|
405
|
+
* nax#1840: the native path throws exactly one class per turn failure, so
|
|
406
|
+
* classification (normally read off SessionFailureError.adapterFailure)
|
|
407
|
+
* and cost (read off this class) cannot both be carried unless one class
|
|
408
|
+
* carries both. Left undefined by the ACP path, which still throws
|
|
409
|
+
* SessionFailureError for its own classified faults — this field only
|
|
410
|
+
* ever gets set by native's sendTurn.
|
|
411
|
+
*/
|
|
412
|
+
adapterFailure?: AdapterFailure | undefined);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* The session half of an agent adapter: the surface a session runtime needs
|
|
416
|
+
* (S1 spec section 4.2, port 2). nax's `AgentAdapter` extends it with the
|
|
417
|
+
* process-description members and one-shot `complete()`.
|
|
418
|
+
*/
|
|
419
|
+
export interface AgentSessionAdapter {
|
|
420
|
+
/**
|
|
421
|
+
* Probe whether the agent has usable credentials (env var, ping, etc.).
|
|
422
|
+
* Optional — adapters that do not implement it are treated as always credentialed.
|
|
423
|
+
* Used by AgentManager.validateCredentials() at run start.
|
|
424
|
+
*/
|
|
425
|
+
hasCredentials?(): Promise<boolean>;
|
|
426
|
+
/**
|
|
427
|
+
* Open a new (or resume an existing) physical agent session.
|
|
428
|
+
* Returns an opaque SessionHandle carrying all state needed for subsequent
|
|
429
|
+
* sendTurn() and closeSession() calls.
|
|
430
|
+
*/
|
|
431
|
+
openSession(name: string, opts: OpenSessionOpts): Promise<SessionHandle>;
|
|
432
|
+
/**
|
|
433
|
+
* Send one or more turns to an open session and return the accumulated result.
|
|
434
|
+
* Handles context-tool and question interactions via opts.interactionHandler.
|
|
435
|
+
*/
|
|
436
|
+
sendTurn(handle: SessionHandle, prompt: string, opts: SendTurnOpts): Promise<TurnResult>;
|
|
437
|
+
/** Close the physical session and its underlying transport client. Best-effort — errors are swallowed. */
|
|
438
|
+
closeSession(handle: SessionHandle): Promise<void>;
|
|
439
|
+
/**
|
|
440
|
+
* Close a session the process no longer holds a live handle for, addressing it by
|
|
441
|
+
* id and workdir rather than by SessionHandle. Distinct from closeSession(): that
|
|
442
|
+
* one closes an open in-process session, this one reconnects to the agent to close
|
|
443
|
+
* a session left behind — the path run teardown takes
|
|
444
|
+
* (src/execution/session-manager-runtime.ts).
|
|
445
|
+
*
|
|
446
|
+
* Optional because out-of-process teardown is not something every adapter can offer;
|
|
447
|
+
* callers treat its absence as "nothing to close" and must invoke it best-effort.
|
|
448
|
+
* Declared here rather than reached through a cast: it was undeclared until #1702,
|
|
449
|
+
* so teardown had to assert its way to it and the two methods' handle types
|
|
450
|
+
* (SessionHandle vs id string) disagreed invisibly.
|
|
451
|
+
*/
|
|
452
|
+
closePhysicalSession?(handle: string, workdir: string, options?: {
|
|
453
|
+
force?: boolean;
|
|
454
|
+
signal?: AbortSignal;
|
|
455
|
+
}): Promise<void>;
|
|
456
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-protocol types — the shapes exchanged across the openSession / sendTurn /
|
|
3
|
+
* closeSession boundary, split out of types.ts under the file-size ratchet (#1702).
|
|
4
|
+
*
|
|
5
|
+
* Nothing here imports back into types.ts, so the split adds no import cycle:
|
|
6
|
+
* the dependency runs one way. `types.ts` stayed in nax
|
|
7
|
+
* (`packages/nax/src/agents/types.ts`) and reaches this module through the
|
|
8
|
+
* `@nathapp/nax-agent` entry. It re-exports a *selected subset* — the session
|
|
9
|
+
* protocol's public contract — so existing `@/agents/types` import sites keep
|
|
10
|
+
* working; a consumer of anything outside that subset (`AuthStamp`,
|
|
11
|
+
* `InvalidToolCallDetail`) imports it from `@nathapp/nax-agent` directly.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Throwable form of TurnResult. Surfaced by `sendTurn()` when the underlying
|
|
15
|
+
* session ended with `stopReason === "error"`. Carries `cancelled: true`
|
|
16
|
+
* when the failure was caused by an external cancel (`cancelActivePrompt()`),
|
|
17
|
+
* so the wiring layer (SessionManager) can classify it as `fail-stale`
|
|
18
|
+
* without the adapter naming a policy outcome.
|
|
19
|
+
*/
|
|
20
|
+
export class SessionTurnError extends Error {
|
|
21
|
+
cancelled;
|
|
22
|
+
retryable;
|
|
23
|
+
tokenUsage;
|
|
24
|
+
estimatedCostUsd;
|
|
25
|
+
exactCostUsd;
|
|
26
|
+
pricingSource;
|
|
27
|
+
adapterFailure;
|
|
28
|
+
constructor(message, cancelled, retryable = false,
|
|
29
|
+
/**
|
|
30
|
+
* BUG-57: token usage accumulated across all turns of the sendTurn() call,
|
|
31
|
+
* including the turn that ended in stopReason:"error" (e.g. a mid-flight
|
|
32
|
+
* cancel). Callers that catch SessionTurnError (build-hop-callback.ts,
|
|
33
|
+
* session-run-hop.ts) must read cost/tokens from here instead of
|
|
34
|
+
* hardcoding zero — tokens already burned before the failure are real
|
|
35
|
+
* spend and must not be dropped from cost accounting.
|
|
36
|
+
*/
|
|
37
|
+
tokenUsage, estimatedCostUsd, exactCostUsd,
|
|
38
|
+
/**
|
|
39
|
+
* US-002: which rate card priced the failed turn's accumulated spend.
|
|
40
|
+
* Set by the ACP adapter (`rateCard.source` — `"catalog-rates"` |
|
|
41
|
+
* `"fallback-rates"`); the native adapter's protocol-fault path does not
|
|
42
|
+
* set it, so the field is optional and absent there.
|
|
43
|
+
*/
|
|
44
|
+
pricingSource,
|
|
45
|
+
/**
|
|
46
|
+
* nax#1840: the native path throws exactly one class per turn failure, so
|
|
47
|
+
* classification (normally read off SessionFailureError.adapterFailure)
|
|
48
|
+
* and cost (read off this class) cannot both be carried unless one class
|
|
49
|
+
* carries both. Left undefined by the ACP path, which still throws
|
|
50
|
+
* SessionFailureError for its own classified faults — this field only
|
|
51
|
+
* ever gets set by native's sendTurn.
|
|
52
|
+
*/
|
|
53
|
+
adapterFailure) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.cancelled = cancelled;
|
|
56
|
+
this.retryable = retryable;
|
|
57
|
+
this.tokenUsage = tokenUsage;
|
|
58
|
+
this.estimatedCostUsd = estimatedCostUsd;
|
|
59
|
+
this.exactCostUsd = exactCostUsd;
|
|
60
|
+
this.pricingSource = pricingSource;
|
|
61
|
+
this.adapterFailure = adapterFailure;
|
|
62
|
+
this.name = "SessionTurnError";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pull-tool descriptor shapes shared by the context engine and the agent
|
|
3
|
+
* contract (S1 spec section 4.2, port 2); `context/engine` re-exports them.
|
|
4
|
+
*/
|
|
5
|
+
/** Minimal JSON Schema type alias — no external library required. */
|
|
6
|
+
export type JSONSchema = Record<string, unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* Descriptor for a pull tool registered with the agent session (Phase 4+).
|
|
9
|
+
* The orchestrator returns these alongside push markdown; agent adapters
|
|
10
|
+
* register them as callable tools on the session.
|
|
11
|
+
*/
|
|
12
|
+
export interface ToolDescriptor {
|
|
13
|
+
/** Tool identifier exposed to the agent (e.g. "query_neighbor") */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Human-readable description shown to the agent */
|
|
16
|
+
description: string;
|
|
17
|
+
/** JSON Schema for the tool's input arguments */
|
|
18
|
+
inputSchema: JSONSchema;
|
|
19
|
+
/** Maximum calls allowed per agent session before the tool errors */
|
|
20
|
+
maxCallsPerSession: number;
|
|
21
|
+
/** Maximum tokens returned per call (response is truncated to this ceiling) */
|
|
22
|
+
maxTokensPerCall: number;
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A whole-turn wall-clock budget, shared by both transports.
|
|
3
|
+
*
|
|
4
|
+
* `timeoutSeconds` has always meant "per agent coding session"
|
|
5
|
+
* (config-descriptions.ts, execution.sessionTimeoutSeconds, default 3600) and
|
|
6
|
+
* acpx spends it that way. Native spent it per LLM call instead, so a turn's
|
|
7
|
+
* real bound was `round-trip cap x timeoutSeconds` — a product nobody
|
|
8
|
+
* intended. This type exists so one budget can be created once per turn and
|
|
9
|
+
* consulted by every round-trip inside it.
|
|
10
|
+
*/
|
|
11
|
+
export interface TurnDeadline {
|
|
12
|
+
/** Milliseconds left, clamped at 0. `undefined` when the turn is unbounded. */
|
|
13
|
+
remainingMs(): number | undefined;
|
|
14
|
+
/** True once the budget is spent. Always false for an unbounded turn. */
|
|
15
|
+
expired(): boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function createTurnDeadline(timeoutSeconds: number | undefined, now?: () => number): TurnDeadline;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A whole-turn wall-clock budget, shared by both transports.
|
|
3
|
+
*
|
|
4
|
+
* `timeoutSeconds` has always meant "per agent coding session"
|
|
5
|
+
* (config-descriptions.ts, execution.sessionTimeoutSeconds, default 3600) and
|
|
6
|
+
* acpx spends it that way. Native spent it per LLM call instead, so a turn's
|
|
7
|
+
* real bound was `round-trip cap x timeoutSeconds` — a product nobody
|
|
8
|
+
* intended. This type exists so one budget can be created once per turn and
|
|
9
|
+
* consulted by every round-trip inside it.
|
|
10
|
+
*/
|
|
11
|
+
const UNBOUNDED = {
|
|
12
|
+
remainingMs: () => undefined,
|
|
13
|
+
expired: () => false,
|
|
14
|
+
};
|
|
15
|
+
export function createTurnDeadline(timeoutSeconds, now = Date.now) {
|
|
16
|
+
if (timeoutSeconds === undefined)
|
|
17
|
+
return UNBOUNDED;
|
|
18
|
+
const endsAt = now() + timeoutSeconds * 1000;
|
|
19
|
+
return {
|
|
20
|
+
remainingMs: () => Math.max(0, endsAt - now()),
|
|
21
|
+
expired: () => now() >= endsAt,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one-line call description an AskResolver receives, and the reason a
|
|
3
|
+
* `denied:ask` ledger row carries.
|
|
4
|
+
*
|
|
5
|
+
* Summaries are outbound to a human, so they are masked through
|
|
6
|
+
* `maskForPrompt` before they leave the process; a secret that cannot be
|
|
7
|
+
* shown safely withholds the arguments entirely (`unshowable`, review #9).
|
|
8
|
+
*/
|
|
9
|
+
import { type AskVerdict } from "#src/permissions/index";
|
|
10
|
+
import type { ToolScope } from "./types.ts";
|
|
11
|
+
/** Ceiling for the one-line call description an AskResolver receives. */
|
|
12
|
+
export declare const MAX_ASK_SUMMARY_CHARS = 200;
|
|
13
|
+
export interface AskSummary {
|
|
14
|
+
readonly summary: string;
|
|
15
|
+
/** True when a secret in the arguments could hide shell syntax if masked (review #9). */
|
|
16
|
+
readonly unshowable: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One human-readable line describing the call an `ask` rule matched.
|
|
20
|
+
*
|
|
21
|
+
* Built from the scope's DECLARED fields rather than from `JSON.stringify` of
|
|
22
|
+
* the whole input: the input carries a tool's full payload -- file contents on
|
|
23
|
+
* a Write, a commit message, whatever a provider tool takes -- and an
|
|
24
|
+
* AskResolver is by definition an outbound channel to a human. A summary is
|
|
25
|
+
* what approval needs; the payload is what the audit sink already holds.
|
|
26
|
+
*/
|
|
27
|
+
export declare function askSummary(tool: string, scope: ToolScope, input: Record<string, unknown>): AskSummary;
|
|
28
|
+
/**
|
|
29
|
+
* The reason a `denied:ask` ledger row carries, chosen by WHO refused.
|
|
30
|
+
*
|
|
31
|
+
* One constant for every ask denial asserted "no approval channel is
|
|
32
|
+
* configured" even when a human answered (deny) or nobody answered in time
|
|
33
|
+
* (timeout). Those are materially different facts; see ASK_*_REASON.
|
|
34
|
+
*/
|
|
35
|
+
export declare function askDenyReason(decidedBy: AskVerdict["decidedBy"]): string;
|