@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,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search file contents, preferring ripgrep and falling back to grep.
|
|
3
|
+
*
|
|
4
|
+
* Both branches spawn a subprocess, so this tool is NOT evidence that the
|
|
5
|
+
* default tool set is in-process — it is not. What makes it safe is the same
|
|
6
|
+
* property that makes Git safe: a fixed binary, an argv nax constructs
|
|
7
|
+
* entirely, and no shell, so the model supplies data and never a command.
|
|
8
|
+
*
|
|
9
|
+
* The two binaries take different flags, so the argv builder is per-binary
|
|
10
|
+
* rather than shared, and the fallback is tested explicitly: a machine without
|
|
11
|
+
* ripgrep must produce the same matches, not a silent empty result.
|
|
12
|
+
*/
|
|
13
|
+
import { drainBounded } from "#src/internal/bounded-io";
|
|
14
|
+
import { runtimeSpawn } from "#src/runtime/index";
|
|
15
|
+
import { which } from "#src/runtime/which";
|
|
16
|
+
import { cutToByteCap, READ_CEILING } from "./truncate.js";
|
|
17
|
+
const GREP_TIMEOUT_MS = 15_000;
|
|
18
|
+
/** @internal */
|
|
19
|
+
const REGEX_METACHARACTERS = /[.*+?^${}()|[\]\\]/;
|
|
20
|
+
/**
|
|
21
|
+
* Returns true when the pattern contains at least one regex metacharacter.
|
|
22
|
+
* Used to disclose to callers that their search was performed literally.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
function containsRegexMetacharacter(pattern) {
|
|
26
|
+
return REGEX_METACHARACTERS.test(pattern);
|
|
27
|
+
}
|
|
28
|
+
/** @internal Injectable for tests — exercises the fallback without uninstalling ripgrep. */
|
|
29
|
+
export const _grepDeps = {
|
|
30
|
+
which: (name) => which(name),
|
|
31
|
+
spawn: runtimeSpawn,
|
|
32
|
+
};
|
|
33
|
+
export function buildGrepArgv(binary, pattern, path, patternType = "literal") {
|
|
34
|
+
const target = path ?? ".";
|
|
35
|
+
// `--` terminates flag parsing on both branches, in both modes: a pattern
|
|
36
|
+
// beginning with "-" is then data, not an option. Neither binary is ever
|
|
37
|
+
// handed a shell string.
|
|
38
|
+
if (binary === "rg") {
|
|
39
|
+
// rg's own default IS regex (its "fixed-strings" flag is what disables
|
|
40
|
+
// it), so the regex branch simply omits the flag rather than adding one.
|
|
41
|
+
const flags = patternType === "literal"
|
|
42
|
+
? ["--fixed-strings", "--line-number", "--no-heading", "--color", "never"]
|
|
43
|
+
: ["--line-number", "--no-heading", "--color", "never"];
|
|
44
|
+
return ["rg", ...flags, "--", pattern, target];
|
|
45
|
+
}
|
|
46
|
+
// grep has no "regex" default to fall back to: -F is fixed-strings, and the
|
|
47
|
+
// nearest equivalent to rg's regex syntax is -E (POSIX ERE, e.g. `a+`, `a|b`
|
|
48
|
+
// with no backslash), not grep's default BRE.
|
|
49
|
+
const modeFlag = patternType === "literal" ? "-F" : "-E";
|
|
50
|
+
return ["grep", "-r", "-n", modeFlag, "--", pattern, target];
|
|
51
|
+
}
|
|
52
|
+
export const grepTool = {
|
|
53
|
+
name: "Grep",
|
|
54
|
+
description: "Search repository file contents for a literal string or a regular expression. Returns 'path:line:text' rows relative to the repository root when no subdirectory target is supplied, absolute when one is (rg prints the target as given). Defaults to a literal (fixed-string) search; set pattern_type to \"regex\" to interpret the pattern as a regular expression (ripgrep syntax, e.g. `foo|bar`, `\\d+`; on a machine without ripgrep the pattern falls back to POSIX ERE, which the result discloses).",
|
|
55
|
+
inputSchema: {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: {
|
|
58
|
+
pattern: {
|
|
59
|
+
type: "string",
|
|
60
|
+
description: 'String to search for. Interpreted literally unless pattern_type is "regex", in which case it is a regular expression.',
|
|
61
|
+
},
|
|
62
|
+
path: { type: "string", description: "Optional subdirectory, relative to the repository root" },
|
|
63
|
+
pattern_type: {
|
|
64
|
+
type: "string",
|
|
65
|
+
enum: ["literal", "regex"],
|
|
66
|
+
default: "literal",
|
|
67
|
+
description: '"literal" (default) matches pattern as a fixed string; "regex" interprets it as a regex.',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ["pattern"],
|
|
71
|
+
},
|
|
72
|
+
// The optional `path` is path-bearing and is gated exactly like Read's: the
|
|
73
|
+
// policy resolves it through resolveWithin, denying escapes as breaches.
|
|
74
|
+
// `pattern` is not a path and needs no path gating.
|
|
75
|
+
scope: { pathFields: ["path"] },
|
|
76
|
+
async run(input, ctx) {
|
|
77
|
+
const pattern = input.pattern;
|
|
78
|
+
if (typeof pattern !== "string")
|
|
79
|
+
return { content: "pattern must be a string", isError: true };
|
|
80
|
+
const patternType = input.pattern_type;
|
|
81
|
+
if (patternType !== undefined && patternType !== "literal" && patternType !== "regex") {
|
|
82
|
+
return { content: 'pattern_type must be "literal" or "regex"', isError: true };
|
|
83
|
+
}
|
|
84
|
+
const mode = patternType === "regex" ? "regex" : "literal";
|
|
85
|
+
const binary = _grepDeps.which("rg") ? "rg" : _grepDeps.which("grep") ? "grep" : null;
|
|
86
|
+
if (binary === null) {
|
|
87
|
+
return { content: "neither ripgrep nor grep is available on this machine", isError: true };
|
|
88
|
+
}
|
|
89
|
+
const [target] = ctx.resolvedPaths;
|
|
90
|
+
// The I/O ceiling, not the model-facing cap: `maxBytes` shapes what the
|
|
91
|
+
// model is told and belongs to the session's truncation policy, while this
|
|
92
|
+
// bound only keeps a search whose result is enormous from being buffered
|
|
93
|
+
// without limit. Bounding both the drain and the returned body at the same
|
|
94
|
+
// value is what lets a result in (maxBytes, readCeiling) reach that policy
|
|
95
|
+
// whole, and it is why the ceiling is a tool-layer constant.
|
|
96
|
+
const ioCeiling = ctx.readCeiling ?? READ_CEILING;
|
|
97
|
+
// nax-git-env-allow: not git: rg/grep search argv
|
|
98
|
+
const proc = _grepDeps.spawn(buildGrepArgv(binary, pattern, target, mode), {
|
|
99
|
+
cwd: ctx.root,
|
|
100
|
+
stdout: "pipe",
|
|
101
|
+
stderr: "pipe",
|
|
102
|
+
});
|
|
103
|
+
const timer = setTimeout(() => {
|
|
104
|
+
try {
|
|
105
|
+
proc.kill("SIGKILL");
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// already exited
|
|
109
|
+
}
|
|
110
|
+
}, GREP_TIMEOUT_MS);
|
|
111
|
+
// Drain concurrently: a large result set fills the pipe buffer and would
|
|
112
|
+
// otherwise block the process before it can exit. Bounded, because the
|
|
113
|
+
// result is truncated to the same ceiling anyway -- a search matching a
|
|
114
|
+
// generated file could otherwise buffer far more than is ever returned,
|
|
115
|
+
// limited only by how much the binary emits before the timeout fires.
|
|
116
|
+
const stdoutText = drainBounded(proc.stdout, ioCeiling).catch(() => "");
|
|
117
|
+
const stderrText = drainBounded(proc.stderr, ioCeiling).catch(() => "");
|
|
118
|
+
const exitCode = await proc.exited;
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
const stdout = await stdoutText;
|
|
121
|
+
// Two independent caveats, either of which means the search the caller
|
|
122
|
+
// asked for is not quite the search that ran.
|
|
123
|
+
//
|
|
124
|
+
// 1. The literal disclosure fires whenever the search was literal AND the
|
|
125
|
+
// pattern contained a metacharacter a regex would have treated
|
|
126
|
+
// specially -- regardless of whether it matched. #1876 only covered the
|
|
127
|
+
// zero-match case; a literal match on a pattern like "foo.bar" is the
|
|
128
|
+
// WORSE case (#1922): the caller has positive evidence and no cue that
|
|
129
|
+
// "." was never a wildcard, so a real regex match was never attempted.
|
|
130
|
+
//
|
|
131
|
+
// 2. The dialect note fires when regex mode ran through the grep fallback.
|
|
132
|
+
// ripgrep's Rust regex and POSIX ERE are NOT the same language: `\d`,
|
|
133
|
+
// `\w` and `\b` are unsupported in ERE, and whether they degrade to a
|
|
134
|
+
// literal or to something else differs BY PLATFORM (GNU grep treats
|
|
135
|
+
// `\d` as `d`; the BSD grep on macOS matches a digit). Silently
|
|
136
|
+
// returning a different answer depending on which binary the machine
|
|
137
|
+
// happens to have is exactly the failure this file's header forbids of
|
|
138
|
+
// the fallback, so the divergence is disclosed rather than hidden.
|
|
139
|
+
const notes = [];
|
|
140
|
+
if (mode === "literal" && containsRegexMetacharacter(pattern)) {
|
|
141
|
+
notes.push("The search was performed literally and regex metacharacters were not interpreted.");
|
|
142
|
+
}
|
|
143
|
+
if (mode === "regex" && binary === "grep") {
|
|
144
|
+
notes.push("ripgrep is not installed here, so the pattern was matched with POSIX ERE via grep: escapes such as \\d, \\w and \\b are NOT supported — use [0-9], [A-Za-z0-9_] and similar instead.");
|
|
145
|
+
}
|
|
146
|
+
const caveat = notes.join(" ");
|
|
147
|
+
// Both binaries exit 1 for "no matches" — a normal outcome, not a failure.
|
|
148
|
+
if (exitCode === 1 && stdout.trim() === "") {
|
|
149
|
+
const base = `no matches for "${pattern}"`;
|
|
150
|
+
return { content: caveat === "" ? base : `${base}. ${caveat}` };
|
|
151
|
+
}
|
|
152
|
+
if (exitCode !== 0 && stdout.trim() === "") {
|
|
153
|
+
return { content: (await stderrText).trim() || `${binary} exited ${exitCode}`, isError: true };
|
|
154
|
+
}
|
|
155
|
+
// The caveat leads rather than trails, and the tool's own bound is applied
|
|
156
|
+
// to the whole body: appended after the cap it both overran the ceiling and
|
|
157
|
+
// was the first thing lost on a result large enough to need the cue most.
|
|
158
|
+
const matches = stdout.trimEnd();
|
|
159
|
+
const body = caveat === "" ? matches : `${caveat}\n\n${matches}`;
|
|
160
|
+
return { content: cutToByteCap(body, ioCeiling) };
|
|
161
|
+
},
|
|
162
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { _bashToolDeps, BASH_TIMEOUT_MS, createBashTool, DEFAULT_BASH_SHELL } from "./bash.ts";
|
|
2
|
+
export { deleteTool } from "./delete.ts";
|
|
3
|
+
export { _editDeps, editTool } from "./edit.ts";
|
|
4
|
+
export { buildGitArgv, DEFAULT_LOG_FORMAT, DEFAULT_LOG_MAX_COUNT, GIT_ESCAPE_FLAGS, GIT_READ_VERBS, gitTool, } from "./git.ts";
|
|
5
|
+
export { buildCommitArgvs, gitCommitTool, partitionNaxOwnedPaths } from "./git-commit.ts";
|
|
6
|
+
export { _globDeps, globTool } from "./glob.ts";
|
|
7
|
+
export { _grepDeps, buildGrepArgv, grepTool } from "./grep.ts";
|
|
8
|
+
export { narrowGrants, type ToolPatternNarrowing } from "./narrow-grants.ts";
|
|
9
|
+
export type { ExecTarget, NormalizeInput, NormalizeResult } from "./package-managers.ts";
|
|
10
|
+
export { classifyExec, isKnownManager, normalizeExec, normalizeManagerBinary } from "./package-managers.ts";
|
|
11
|
+
export type { ToolPolicyOptions } from "./policy.ts";
|
|
12
|
+
export { compileToolPolicy, resolveWithin } from "./policy.ts";
|
|
13
|
+
export type { ProtectedPathsPolicy } from "./protected-paths.ts";
|
|
14
|
+
export { gitExcludePathspecsOf, gitIgnorePatternsOf } from "./protected-paths.ts";
|
|
15
|
+
export * from "./provider-adapt.ts";
|
|
16
|
+
export * from "./provider-advertise.ts";
|
|
17
|
+
export * from "./provider-grants.ts";
|
|
18
|
+
export * from "./provider-sanitize.ts";
|
|
19
|
+
export * from "./provider-types.ts";
|
|
20
|
+
export { readTool } from "./read.ts";
|
|
21
|
+
export { type ReadFileSliceOptions, type ReadFileSliceResult, readFileSlice } from "./read-file.ts";
|
|
22
|
+
export type { CodingTool, ToolResult, ToolRunContext } from "./registry.ts";
|
|
23
|
+
export { _resetRegistryForTest, getCodingTool, listCodingTools, RESERVED_TOOL_NAMES, registerBuiltinTool, registerCodingTool, } from "./registry.ts";
|
|
24
|
+
export { requestCapabilityTool } from "./request-capability.ts";
|
|
25
|
+
export type { DeclaredCommandRequest, DeclaredCommandResult, DeclaredCommandRunner } from "./run-command.ts";
|
|
26
|
+
export { createRunCommandTool, substituteCommand, substituteCommandSpec } from "./run-command.ts";
|
|
27
|
+
export type { CodingToolOutcome, CodingToolRuntime, ToolCallContext } from "./runtime.ts";
|
|
28
|
+
export { _codingToolDeps, _resetBuiltinsForTest, createCodingToolRuntime, DEFAULT_TOOL_MAX_BYTES, DEFAULT_TOOL_MAX_FILE_BYTES, registerBuiltinCodingTools, } from "./runtime.ts";
|
|
29
|
+
export { SCRATCHPAD_DIR, scratchpadListTool, scratchpadReadTool, scratchpadWriteTool } from "./scratchpad.ts";
|
|
30
|
+
export { _spillDeps, applyModelTruncationPolicy, type ModelTruncationOptions, SPILL_DIR, type SpillRequest, spillRelativePath, writeSpill, } from "./spill.ts";
|
|
31
|
+
export type { RegisteredSink, ToolAuditSink, ToolCallRecord } from "./tool-audit.ts";
|
|
32
|
+
export { createNoOpToolAuditSink, createToolAuditSink, flushOpenToolAuditSinks, registerToolAuditSink, unregisterToolAuditSink, } from "./tool-audit.ts";
|
|
33
|
+
export { cutBufferToByteCap, MODEL_MAX_BYTES, MODEL_MAX_LINE_CHARS, MODEL_MAX_LINES, READ_CEILING, type TruncateForModelOptions, type TruncationDirection, type TruncationResult, truncateForModel, truncationDirectionFor, } from "./truncate.ts";
|
|
34
|
+
export type { CodingToolName, PolicyVerdict, ToolGrant, ToolPolicy, ToolScope } from "./types.ts";
|
|
35
|
+
export { BASH_TOOL_NAME, EXEC_TOOL_NAME } from "./types.ts";
|
|
36
|
+
export { writeTool } from "./write.ts";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { _bashToolDeps, BASH_TIMEOUT_MS, createBashTool, DEFAULT_BASH_SHELL } from "./bash.js";
|
|
2
|
+
export { deleteTool } from "./delete.js";
|
|
3
|
+
export { _editDeps, editTool } from "./edit.js";
|
|
4
|
+
export { buildGitArgv, DEFAULT_LOG_FORMAT, DEFAULT_LOG_MAX_COUNT, GIT_ESCAPE_FLAGS, GIT_READ_VERBS, gitTool, } from "./git.js";
|
|
5
|
+
export { buildCommitArgvs, gitCommitTool, partitionNaxOwnedPaths } from "./git-commit.js";
|
|
6
|
+
export { _globDeps, globTool } from "./glob.js";
|
|
7
|
+
export { _grepDeps, buildGrepArgv, grepTool } from "./grep.js";
|
|
8
|
+
export { narrowGrants } from "./narrow-grants.js";
|
|
9
|
+
export { classifyExec, isKnownManager, normalizeExec, normalizeManagerBinary } from "./package-managers.js";
|
|
10
|
+
export { compileToolPolicy, resolveWithin } from "./policy.js";
|
|
11
|
+
export { gitExcludePathspecsOf, gitIgnorePatternsOf } from "./protected-paths.js";
|
|
12
|
+
export * from "./provider-adapt.js";
|
|
13
|
+
export * from "./provider-advertise.js";
|
|
14
|
+
export * from "./provider-grants.js";
|
|
15
|
+
export * from "./provider-sanitize.js";
|
|
16
|
+
export * from "./provider-types.js";
|
|
17
|
+
export { readTool } from "./read.js";
|
|
18
|
+
export { readFileSlice } from "./read-file.js";
|
|
19
|
+
export { _resetRegistryForTest, getCodingTool, listCodingTools, RESERVED_TOOL_NAMES, registerBuiltinTool, registerCodingTool, } from "./registry.js";
|
|
20
|
+
export { requestCapabilityTool } from "./request-capability.js";
|
|
21
|
+
export { createRunCommandTool, substituteCommand, substituteCommandSpec } from "./run-command.js";
|
|
22
|
+
export { _codingToolDeps, _resetBuiltinsForTest, createCodingToolRuntime, DEFAULT_TOOL_MAX_BYTES, DEFAULT_TOOL_MAX_FILE_BYTES, registerBuiltinCodingTools, } from "./runtime.js";
|
|
23
|
+
export { SCRATCHPAD_DIR, scratchpadListTool, scratchpadReadTool, scratchpadWriteTool } from "./scratchpad.js";
|
|
24
|
+
export { _spillDeps, applyModelTruncationPolicy, SPILL_DIR, spillRelativePath, writeSpill, } from "./spill.js";
|
|
25
|
+
export { createNoOpToolAuditSink, createToolAuditSink, flushOpenToolAuditSinks, registerToolAuditSink, unregisterToolAuditSink, } from "./tool-audit.js";
|
|
26
|
+
export { cutBufferToByteCap, MODEL_MAX_BYTES, MODEL_MAX_LINE_CHARS, MODEL_MAX_LINES, READ_CEILING, truncateForModel, truncationDirectionFor, } from "./truncate.js";
|
|
27
|
+
export { BASH_TOOL_NAME, EXEC_TOOL_NAME } from "./types.js";
|
|
28
|
+
export { writeTool } from "./write.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrowing a grant an operation inherits.
|
|
3
|
+
*
|
|
4
|
+
* `CodingToolRuntime.advertised()` intersects tool NAMES against the policy's
|
|
5
|
+
* grants, so an op declaring `Write` under the `unrestricted` profile received
|
|
6
|
+
* that profile's `["*"]` — there was no way to say "this role may write, but
|
|
7
|
+
* only this one file" (nax#2013).
|
|
8
|
+
*
|
|
9
|
+
* Narrowing only. `resolvePermissions` remains the single permission authority
|
|
10
|
+
* (CLAUDE.md, Permission Resolution): a tool the profile did not grant has no
|
|
11
|
+
* grant here to narrow, so nothing in this module can widen access.
|
|
12
|
+
*
|
|
13
|
+
* Glob-set intersection is undecidable in general, so the rule is structural
|
|
14
|
+
* rather than semantic — see each branch below.
|
|
15
|
+
*/
|
|
16
|
+
import type { CodingToolName, ToolGrant } from "./types.ts";
|
|
17
|
+
/** Per-tool path globs an operation asks to be held to. */
|
|
18
|
+
export type ToolPatternNarrowing = Partial<Record<CodingToolName, readonly string[]>>;
|
|
19
|
+
export declare function narrowGrants(grants: readonly ToolGrant[], narrowing: ToolPatternNarrowing | undefined): readonly ToolGrant[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrowing a grant an operation inherits.
|
|
3
|
+
*
|
|
4
|
+
* `CodingToolRuntime.advertised()` intersects tool NAMES against the policy's
|
|
5
|
+
* grants, so an op declaring `Write` under the `unrestricted` profile received
|
|
6
|
+
* that profile's `["*"]` — there was no way to say "this role may write, but
|
|
7
|
+
* only this one file" (nax#2013).
|
|
8
|
+
*
|
|
9
|
+
* Narrowing only. `resolvePermissions` remains the single permission authority
|
|
10
|
+
* (CLAUDE.md, Permission Resolution): a tool the profile did not grant has no
|
|
11
|
+
* grant here to narrow, so nothing in this module can widen access.
|
|
12
|
+
*
|
|
13
|
+
* Glob-set intersection is undecidable in general, so the rule is structural
|
|
14
|
+
* rather than semantic — see each branch below.
|
|
15
|
+
*/
|
|
16
|
+
import { getSafeLogger } from "#src/infra/index";
|
|
17
|
+
const UNCONDITIONAL = "*";
|
|
18
|
+
export function narrowGrants(grants, narrowing) {
|
|
19
|
+
if (narrowing === undefined || Object.keys(narrowing).length === 0)
|
|
20
|
+
return grants;
|
|
21
|
+
// Indexed through a Map rather than `narrowing[grant.tool]`: `ToolGrant.tool`
|
|
22
|
+
// is a plain string (third parties register their own names) while the
|
|
23
|
+
// op-facing type is keyed on CodingToolName so a typo in an op is a compile
|
|
24
|
+
// error. Object.entries bridges the two without a cast.
|
|
25
|
+
const wanted = new Map(Object.entries(narrowing).filter((entry) => entry[1] !== undefined));
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const grant of grants) {
|
|
28
|
+
const requested = wanted.get(grant.tool);
|
|
29
|
+
if (requested === undefined || requested.length === 0) {
|
|
30
|
+
out.push(grant);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
// An unconditional grant is wider than any concrete list, so the op's
|
|
34
|
+
// patterns are unambiguously a narrowing of it.
|
|
35
|
+
if (grant.patterns.includes(UNCONDITIONAL)) {
|
|
36
|
+
out.push({ tool: grant.tool, patterns: [...requested] });
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
// A scoped grant already names specific globs. Comparing two globs for
|
|
40
|
+
// containment is undecidable, so admit only the ones the grant's author
|
|
41
|
+
// wrote verbatim — which is what a scoped profile intending this writes.
|
|
42
|
+
const admitted = requested.filter((pattern) => grant.patterns.includes(pattern));
|
|
43
|
+
if (admitted.length === 0) {
|
|
44
|
+
getSafeLogger()?.warn("tools", "[policy] op narrowing excluded by the scoped grant — tool withheld", {
|
|
45
|
+
tool: grant.tool,
|
|
46
|
+
requested: [...requested],
|
|
47
|
+
granted: [...grant.patterns],
|
|
48
|
+
});
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
out.push({ tool: grant.tool, patterns: admitted });
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which paths nax refuses to let an agent touch, and to which tools.
|
|
3
|
+
*
|
|
4
|
+
* A separate file rather than an addition to src/tools/policy.ts, for the same
|
|
5
|
+
* reason src/tools/deny-paths.ts is one: that file carries the containment
|
|
6
|
+
* seam and sits at the project's file-size ratchet, while this is a narrower
|
|
7
|
+
* concern -- it has nothing to do with resolving or containing a path, only
|
|
8
|
+
* with refusing one containment would otherwise allow.
|
|
9
|
+
*
|
|
10
|
+
* Segment-exact, never a prefix or substring match: `.naxignore`,
|
|
11
|
+
* `docs/nax/config.json` and `.nax/mono/api/notes.md` are ordinary paths a
|
|
12
|
+
* tool must still reach.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The one top-level `.nax/` entry agents may write freely: the scratchpad.
|
|
16
|
+
* Must equal the last segment of SCRATCHPAD_DIR (pinned by a test; importing
|
|
17
|
+
* it here would close a scratchpad -> policy -> nax-owned-writes cycle).
|
|
18
|
+
*/
|
|
19
|
+
export declare const NAX_SCRATCHPAD_ENTRY = "scratchpad";
|
|
20
|
+
/**
|
|
21
|
+
* Entries nax loads as human-authored input. The sandbox denies these even
|
|
22
|
+
* when absent, so an agent cannot create one: a new `.nax/rules/x.md` would be
|
|
23
|
+
* injected into every later session's prompt, and `hooks.json` / `plugins/`
|
|
24
|
+
* run unsandboxed on the next `nax run`. `templates/` and `prompts/` are where
|
|
25
|
+
* `prompts.overrides` points. nax creates none of them mid-run (CLI only).
|
|
26
|
+
*/
|
|
27
|
+
export declare const NAX_ALWAYS_DENIED_ENTRIES: readonly string[];
|
|
28
|
+
/**
|
|
29
|
+
* Top-level `.nax/` entries a human opened for agent writes by listing them in
|
|
30
|
+
* `execution.sandbox.filesystem.allowWrite` (nax#2260). Only an exact entry
|
|
31
|
+
* counts -- `.nax/rules`, never `.nax/rules/a.md` -- and never the scratchpad
|
|
32
|
+
* (always open) or a NAX_NEVER_OPT_IN entry. Relative entries resolve against
|
|
33
|
+
* `root`, as the sandbox's own write roots do.
|
|
34
|
+
*/
|
|
35
|
+
export declare function naxWriteOptIns(root: string, allowWrite: readonly string[]): ReadonlySet<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Is `resolved` one of nax's own CONFIG files, relative to `root`?
|
|
38
|
+
*
|
|
39
|
+
* `.nax/config.json`, and `.nax/mono/<package>/config.json` in a monorepo.
|
|
40
|
+
*
|
|
41
|
+
* Why these at all: `quality.commands` and `acceptance.command` are run by key
|
|
42
|
+
* through a shell and never pass the permission gate -- they are trusted
|
|
43
|
+
* because a HUMAN wrote them. That trust rests entirely on a model being
|
|
44
|
+
* unable to write them. An agent holding `Write` under the default
|
|
45
|
+
* `unrestricted` profile could otherwise add a quality command and receive an
|
|
46
|
+
* ungated shell on the next run, routing around every `Bash(...)` rule, the
|
|
47
|
+
* lexer's construct refusals and containment itself.
|
|
48
|
+
*
|
|
49
|
+
* Refused to EVERY tool, reads included -- this is the pre-existing behaviour
|
|
50
|
+
* and it is deliberate.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isNaxConfigFile(root: string, resolved: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The path-bearing tools that MUTATE. Read, Grep, Glob and Git are read-only
|
|
55
|
+
* and are deliberately absent: an agent legitimately reads its own PRD, and
|
|
56
|
+
* refusing that would break ordinary work to close one hole.
|
|
57
|
+
*
|
|
58
|
+
* Bash and Exec are absent because they carry no path fields -- a shell
|
|
59
|
+
* redirect into `.nax/` is gated by the human-authored `Bash(...)` rules and
|
|
60
|
+
* the lexer, which is a different seam from this one.
|
|
61
|
+
*/
|
|
62
|
+
export declare const NAX_OWNED_WRITE_TOOLS: ReadonlySet<string>;
|
|
63
|
+
/**
|
|
64
|
+
* nax's run-control files at the root: the command channel an agent could
|
|
65
|
+
* otherwise use to PAUSE, ABORT or SKIP stories without writing any code.
|
|
66
|
+
*
|
|
67
|
+
* `.queue.txt.processing` is the atomic-rename target the queue handler reads
|
|
68
|
+
* from (src/execution/queue-handler.ts), so guarding only `.queue.txt` would
|
|
69
|
+
* leave the same hole one rename downstream.
|
|
70
|
+
*/
|
|
71
|
+
export declare const QUEUE_CONTROL_FILES: ReadonlySet<string>;
|
|
72
|
+
/**
|
|
73
|
+
* The kinds of nax-owned path the raw Bash screen refuses by name.
|
|
74
|
+
* `"config"` is produced by the lexical `isNaxConfigFile` pass, never by
|
|
75
|
+
* `naxOwnedKind` -- see that function.
|
|
76
|
+
*/
|
|
77
|
+
export type NaxOwnedKind = "prd" | "queue" | "config";
|
|
78
|
+
/**
|
|
79
|
+
* Is this path one nax owns the writes to, independent of WHICH tool is asking?
|
|
80
|
+
*
|
|
81
|
+
* `naxOwnedWriteRefusal` answers the same question for the four file-writing
|
|
82
|
+
* tools and returns prose. This predicate is the tool-agnostic half, extracted
|
|
83
|
+
* so the `raw` bash screen (ADR-030) can consult exactly the same path set
|
|
84
|
+
* without being in `NAX_OWNED_WRITE_TOOLS`. One definition, two callers.
|
|
85
|
+
*
|
|
86
|
+
* @param rel - Path relative to the permitted root, `/`-joined.
|
|
87
|
+
*/
|
|
88
|
+
export declare function isNaxOwnedWritePath(rel: string): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Which kind of nax-owned write path `rel` is, or undefined when it is not one.
|
|
91
|
+
*
|
|
92
|
+
* `/`-joined and root-relative, like `isNaxOwnedWritePath`. Never returns
|
|
93
|
+
* `"config"` -- nax config files are recognised by the lexical
|
|
94
|
+
* `isNaxConfigFile` pass, which callers (`protectedHit` in policy-bash-raw.ts)
|
|
95
|
+
* run FIRST. Keeping the two apart is what lets the raw screen name the kind it
|
|
96
|
+
* matched without duplicating the config rule here.
|
|
97
|
+
*/
|
|
98
|
+
export declare function naxOwnedKind(rel: string): "prd" | "queue" | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Refusal text for a Bash command that names (verb "names") or redirects into
|
|
101
|
+
* (verb "redirects into") a nax-owned file.
|
|
102
|
+
*
|
|
103
|
+
* Kind-specific on purpose. The previous screen returned one modification-only
|
|
104
|
+
* sentence for every kind, which read as "you cannot WRITE this" -- so an agent
|
|
105
|
+
* that only wanted to READ a PRD retried a command it will never be allowed to
|
|
106
|
+
* run. Each branch now says what the file IS and what the agent can do instead.
|
|
107
|
+
*
|
|
108
|
+
* The text never spells `.nax/features/` literally: `src/tools/` is covered by
|
|
109
|
+
* the `check:feature-dir-ssot` gate, so the PRD branch names the token the agent
|
|
110
|
+
* used (`hit`) rather than the tree layout.
|
|
111
|
+
*
|
|
112
|
+
* US-002: `opts.sandboxWrapped` (an available launcher) swaps only the PRD
|
|
113
|
+
* sentence -- reading through Bash is then allowed, writing still is not.
|
|
114
|
+
* `config` and `queue` are unchanged in both modes.
|
|
115
|
+
*/
|
|
116
|
+
export declare function naxOwnedBashRefusal(tool: string, kind: NaxOwnedKind, hit: string, verb: "names" | "redirects into", opts?: {
|
|
117
|
+
sandboxWrapped?: boolean;
|
|
118
|
+
}): string;
|
|
119
|
+
/**
|
|
120
|
+
* Why `tool` may not touch `rel`, or `undefined` when it may.
|
|
121
|
+
*
|
|
122
|
+
* `rel` MUST be the canonical, posix-separated, root-relative spelling the
|
|
123
|
+
* policy itself derived -- never the caller's own. Matching the caller's
|
|
124
|
+
* spelling means this guard and the policy that approved the call are reading
|
|
125
|
+
* different strings, and every alternate spelling ("./x", "a/../x") walks past
|
|
126
|
+
* the guard. Same rule, and the same reason, as `matchesDenyPaths`.
|
|
127
|
+
*
|
|
128
|
+
* The PRD defines the acceptance criteria the story is judged against. An
|
|
129
|
+
* agent that can rewrite it can pass any review without writing any code,
|
|
130
|
+
* which defeats the review layer without touching a config file.
|
|
131
|
+
*
|
|
132
|
+
* The queue file is the other half of the same concern: it is the run-control
|
|
133
|
+
* channel, and a write there can pause, abort or skip stories outright.
|
|
134
|
+
*/
|
|
135
|
+
export declare function naxOwnedWriteRefusal(tool: string, rel: string, exemptRel?: string, optIns?: ReadonlySet<string>): string | undefined;
|