feat: delegate external read-only tools to auto-review

This commit is contained in:
云服务部-叶林立
2026-08-19 16:48:45 +08:00
parent 3507f85363
commit 9b2ec36a2d
8 changed files with 30 additions and 26 deletions
@@ -8,12 +8,14 @@
* verdict — it never turns a `defer`/`deny` into an `allow`.
*
* The excluded set is the whole `path` surface plus `external_directory`, with
* one bundle-maintained exception: the built-in `read` tool may accept a link's
* `allow` for an external-directory ask. Mutating tools, bash, extension tools,
* and unknown tools remain capped to the terminal human authority. A finer
* secret-shaped-`path` exclusion remains deferred; `path` stays fully excluded.
* one bundle-maintained exception: built-in read-only path tools may accept a
* link's `allow` for an external-directory ask. Mutating tools, bash, extension
* tools, and unknown tools remain capped to the terminal human authority. A
* finer secret-shaped-`path` exclusion remains deferred; `path` stays fully
* excluded.
*/
import { READ_ONLY_PATH_BEARING_TOOLS } from "#src/access-intent/path-surfaces";
import type { Authorizer } from "./authorizer";
import type { PromptPermissionDetails } from "./permission-prompter";
@@ -23,9 +25,6 @@ export const DELEGATION_EXCLUDED_SURFACES: ReadonlySet<string> = new Set([
"path",
]);
/** Read-only external-directory access explicitly delegable in my-pi. */
const DELEGABLE_EXTERNAL_DIRECTORY_TOOLS: ReadonlySet<string> = new Set(["read"]);
/**
* Wrap a link's `authorize` so an `allow` on an excluded surface is capped to
* `defer`. All other verdicts, and `allow`s on non-excluded surfaces, pass
@@ -47,8 +46,8 @@ export function encloseInDelegationEnvelope(
/**
* Whether an allow verdict exceeds the delegation envelope. The gate-computed
* surface is authoritative. `path` remains fully excluded; external-directory
* access is excluded unless it comes from the built-in `read` tool. Unknown
* surfaces fail safe to the terminal authority.
* access is excluded unless it comes from a built-in read-only path tool.
* Unknown surfaces fail safe to the terminal authority.
*/
function isExcludedSurface(details: PromptPermissionDetails): boolean {
const surface = details.accessIntent?.surface ?? details.surface ?? undefined;
@@ -58,7 +57,7 @@ function isExcludedSurface(details: PromptPermissionDetails): boolean {
if (surface === "external_directory") {
return !(
details.toolName !== undefined &&
DELEGABLE_EXTERNAL_DIRECTORY_TOOLS.has(details.toolName)
READ_ONLY_PATH_BEARING_TOOLS.has(details.toolName)
);
}
return DELEGATION_EXCLUDED_SURFACES.has(surface);