Skip to content

feat: support native disallowedTools session filters - #232

Merged
xxchan merged 2 commits into
mainfrom
feat/disallowed-tools
Oct 8, 2026
Merged

xxchan merged 2 commits into
mainfrom
feat/disallowed-tools

Conversation

@xxchan

@xxchan xxchan commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Hosts can now disable selected tools with SessionOptions.disallowedTools through each runtime's native deny channel. Runtimes without a verified native deny channel refuse nonempty lists with UnsupportedOptionError. Empty lists add no restriction, and callers pass the option again when resuming.

  • Claude and Pi use native tool filters; unmatched names are accepted silently and disable nothing. Claude also ignores wrong-case names such as bash instead of Bash. Cursor forwards SDK names/groups on create and resume; its native validation becomes the common option error.
  • Codex supports qualified MCP tool names through session disabled_tools, preserving the user's existing filters and other configuration. Built-ins and ambiguous names refuse. Antigravity accepts its canonical built-in filter names; MCP, client and unknown names refuse.
  • Grok, Kimi and OpenCode refuse nonempty lists because the verified native paths cannot apply the requested denial without replacing user configuration or weakening the guarantee. OAR does not construct an allowlist or suppress tool events.

The runtime pages and dated native audit document name vocabularies, resume semantics, group scope and limits. This controls tool selection; it is not an operating-system sandbox.

Validation: full check (1025 tests plus mock behavior), build, and all four behavior backends. Real Claude 2.1.293, Pi SDK 1.0.4, Codex 0.161.0 and Antigravity 1.3.0 against scripted providers verify the actual outgoing tool sets on create/resume, unrelated tools and existing user filters. Claude/Pi native regressions also pin unknown names leaving the baseline tool set unchanged. A real Cursor SDK 1.0.36/backend probe verifies shell/MCP removal while read remains available, including resume. Unit regressions cover mixed-list refusal, native option validation, and Codex config/read credentials staying out of records and session overrides on both create and resume. Reproducible commands and evidence are in experiments/disallowed-tools-2026-10-08.md.

Closes #225.

@xxchan
xxchan merged commit 4ab122e into main Oct 8, 2026
13 checks passed
@xxchan
xxchan deleted the feat/disallowed-tools branch October 8, 2026 08:02
@xxchan xxchan mentioned this pull request Oct 8, 2026
xxchan added a commit that referenced this pull request Oct 8, 2026
Release OAR and CLI 0.41.0. This PR changes only the two package version
fields.

**Behavior change for claude** (#233, closes #226)
- claude now runs with `--include-partial-messages`, so text and
thinking show up while they are generated.
- `text_delta` and readable `reasoning` from claude are now streamed
pieces, as they already were for codex and pi, instead of whole blocks.
A completed block does not repeat what was already streamed. Tool calls
still start once, with their complete input.
- Every native `stream_event` is recorded as a frame, so a claude
session produces many more, smaller records. Hosts that store records
should budget for this. For display, `events(observer, { coalesceText:
true })` merges the pieces.
- `stallOf` counts streamed tool arguments as activity, so a long
generation is no longer mistaken for silence.
- `reasoning` events gain an optional `messageId`; coalescing keeps
reasoning from different messages apart.
- Background Task children still report complete blocks only: claude
sends no stream events for them.

**New** (#232, closes #225)
- `SessionOptions.disallowedTools`: runtime-native tool names to disable
through each runtime's own deny channel, on new and resumed sessions.
Give the list again on resume. Omitted or empty adds no restriction. OAR
never builds an allowlist and never hides tool events.
- claude: `--disallowed-tools`, for example `Bash` or
`mcp__server__tool`. Unknown or wrong-case names (`bash`) are accepted
silently and disable nothing.
- pi: the SDK's `excludeTools`. Unmatched names are accepted silently
and disable nothing.
- cursor: the SDK's `disallowedTools`, including the groups `shell` and
`mcp`. Unknown names refuse with `UnsupportedOptionError`. Native
subagents have their own toolset; deny `task` to stop them.
- codex: only qualified MCP names `mcp__server__tool` on one
unambiguously named configured or session server, through
`disabled_tools`. Existing denials are kept. Built-in names refuse.
- antigravity: its canonical built-in filter names only. MCP, client
tools and unknown names refuse.
- grok, kimi, opencode: any non-empty list refuses
(`refusedSessionOptions.disallowedTools`).
- This selects tools. It is not a sandbox: another allowed tool may do
the same work.

Validation: all 13 checks passed on #232's final head (`7cb1eda`) and
#233's final head (`db79401`), and each merged tree equals its CI tree.
After this PR passes CI and merges, tag its exact squash commit as
`v0.41.0` to trigger npm trusted publishing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: exe.dev user <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
xxchan added a commit that referenced this pull request Oct 8, 2026
Closes #227 (second step; the evidence matrix was #230).

## What changes

**Contract (additive)**
- `FailureClass` gains `model_unavailable`, `input_too_large`,
`rate_limited` and `billing`.
- A failed `TurnOutcome` gets two optional fields, set only where the
runtime says them:
  - `credential`: `"missing" | "rejected"`;
  - `status`: the provider's HTTP status.
- New `RuntimeFailureError { failure, credential?, status?, reason }`.
`session()` rejects with it when the open fails for one of these causes:
  - ACP -32000 on initialize, authenticate, new or resume → `auth`;
  - a -32602 answer to the model call → `model_unavailable`;
  - cursor's `AuthenticationError` → `auth`, `rejected`;
  - a pi model oar doesn't find → `model_unavailable`.
- `observe`:
- `failureAdvice(failure)` returns `{ retry: "now" | "later" | "no",
userAction }`;
- `failureText(failure, runtimeName, credential?)` covers the new
classes.

**Mapping.** Each adapter reads the runtime's own category first, then
the provider error body (`code`, then `type`), then the HTTP status.
Matching words is each adapter's documented last resort.

| runtime | reads |
|---|---|
| claude | `assistant.error`, then `api_error_status` /
`terminal_reason`; the 400 spend limit by its words |
| codex | `codexErrorInfo`, including the transport variants'
`httpStatusCode`; for `other`, the code in the provider's JSON body |
| pi | `errorMessage`: the status prefix and the JSON body; pi-ai's
`isContextOverflow` |
| grok | -32003 → `rate_limited`; for -32603, the final
`retry_state.error_type` |
| ACP | -32000 → `auth` (no `credential`); opencode by its words |

- Values a runtime declares but no run produced stay unmapped and are
documented.
- An OpenAI 429 whose code names a quota or a balance is `quota` /
`billing`; only a bare 429 is `rate_limited`.

**Fixed misclassifications (each now covered by a test)**
- claude: "Credit balance is too low" was `unknown`, now `billing`. An
oversized context was `unknown`, now `input_too_large`.
- codex: `serverOverloaded` was `unknown`, now `overloaded`.
`contextWindowExceeded` was `unknown`, now `input_too_large`.

**Docs**
- runtime-matrix: the mapping rules, the oar column of each table, the
known ambiguities, the vendor tests.
- conversation.md: `failureText` with `credential`, and `failureAdvice`.
- README; the claude, grok, cursor and kimi pages (kimi now links
MoonshotAI/kimi-code#1865); roadmap.

## Behavior changes worth a release note
- `FailureClass` has four new members: a host's exhaustive `switch` over
it stops compiling until it handles them.
- A 429 that names no quota or balance is now `rate_limited`; it was
`quota`.
- `failureText("auth", name)` without a credential now reads "could not
authenticate". It used to read "is not signed in", which was wrong for a
refused API key (the Raft complaint in #227).
- Some opens now reject with `RuntimeFailureError` (still an `Error`,
with the same message; its `reason` reads the message and the agent's
error is its `cause`, both redacted like the message when the session
carries credential-bearing `mcpServers`) where they rejected with the
raw `RequestError` or a plain `Error`:
  - an ACP agent that requires auth;
  - a -32602 model answer;
  - cursor's refused key;
  - a pi model oar doesn't find.
- A grok -32603 reason now includes its `data` text (the provider's
answer), not only "Internal error".

## Tests
- Unit tests for every mapping, built on the observed facts:
`tests/failure-mapping.test.ts` and `tests/failure-class.test.ts`
(shared rules, `failureAdvice`).
- A claude projection test for the wiring, and updated display-text
tests.
- Vendor tests, one per mapped cell:
- `sea-trial/vendor/failure-classes.vendor.test.ts` runs in CI against
the real binaries (claude 10 cells, codex 13, pi 11).
- `sea-trial/vendor/failure-classes-acp.vendor.test.ts` runs locally
like the other ACP vendor tests: grok 5, kimi 3, opencode 4, antigravity
3. It also pins kimi's and antigravity's completed-looking failures.
- Two existing vendor snapshots gained `status: 400`.
- `pnpm run check` is green (1127 tests, mock 19/19). After the rebase
onto main (#232, #233), the claude/codex/pi vendor suites pass locally,
and so do the four ACP suites.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: exe.dev user <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
xxchan pushed a commit that referenced this pull request Oct 8, 2026
…d resume without the list

Inspection of SessionOptions.disallowedTools (#232). The vendor tests only
checked which tools reach the provider. Two facts a host relies on were not
pinned, and the contract comment left one out:

- A model that calls a denied tool anyway gets the runtime's refusal, not
  the tool: claude ("No such tool available"), pi ("Tool ... not found"),
  codex ("unsupported call", no tool event), antigravity (nothing run).
  Each runtime's vendor test now scripts that call and checks nothing ran.
- A resume that omits the list has no restriction on claude, pi and codex,
  but antigravity keeps its saved filter (runtime-matrix.md already said
  so). The tests pin both; the SessionOptions comment now names the
  exception.

cursor.md: @cursor/sdk 1.0.37 still leaves the backgrounded shell timer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
xxchan added a commit that referenced this pull request Oct 8, 2026
…d resume without the list (#245)

Daily inspection, round 7. Target: `SessionOptions.disallowedTools`
(#232). Approach: try to falsify "a denied tool cannot run", and compare
the same contract across runtimes.

## What I checked (real runtimes against a scripted provider)

1. **A model that calls a denied tool anyway.** #232's vendor tests
check only which tools are *offered* to the provider. A host disabling
`Bash` also relies on a hallucinated or injected call to it not running.
Scripted calls to the denied tools give:
- claude 2.1.293: `No such tool available: Bash. Bash is disabled for
this session, in subagents as well as here.` The tool result is
`failed`, and no file is written. The same happens for a denied MCP
tool, with or without tool search.
- pi SDK 1.0.4: `Tool bash not found` and `Tool mcp__blocked__echo not
found`.
- codex 0.161: `unsupported call: mcp__blocked…` goes back to the model,
and OAR records no tool event. The allowed tool in the same response
runs.
- antigravity 1.3.0: `run_command` is not run (no file is written) and
there is no tool event.

   **Holds on all four.** The vendor tests now pin it.
2. **Resuming with the list omitted.** On claude, pi and codex the
denied tool is offered again. On antigravity the saved filter stays.
runtime-matrix.md and antigravity.md already say this. The
`SessionOptions.disallowedTools` comment only said "Omitted or empty
means no additional restriction", so it now names the exception. The
vendor tests pin both behaviors.

A refuter (`oar run codex`, given the claim and the evidence) reported
NOT REFUTED. It noted that the checked-in tests never covered the
omitted-list resume, which this PR adds.

## Also
- cursor.md: `@cursor/sdk` 1.0.37 (published 2026-10-07) still skips
`clearTimeout` for a backgrounded shell call (`464.js`). The forum
report (cursor topic 173928) has no new reply since Cursor reproduced
it.

## Changes
- `sea-trial/vendor/disallowed-tools.vendor.test.ts` (claude and pi in
CI), `disallowed-tools-codex.vendor.test.ts` (CI) and
`disallowed-tools-antigravity.vendor.test.ts` (local): each gets one new
test, a denied call is refused plus the omitted-list resume.
- `contracts/session-options.ts`: the comment names the antigravity
exception.
- `docs/spec/runtime-matrix.md#disallowed-tools`: the refusal each
runtime gives.
- `docs/runtimes/cursor.md`: SDK 1.0.37 check.

`pnpm run check` passes. All four vendor files pass locally (claude, pi
and codex again after rebasing onto e953b43).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: exe.dev user <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SessionOptions.disallowedTools: deny named tools through each runtime's native channel, refused where none exists

2 participants