|
| 1 | +/** |
| 2 | + * Shared tool-name classification constants (CL-6809). |
| 3 | + * |
| 4 | + * Three separate READ_TOOLS constants (director tool-sets, session compactor, |
| 5 | + * subagent thrash tracker) had drifted to different memberships under the |
| 6 | + * same name, and the permission classifier's auto-allow gate carried a fourth |
| 7 | + * (READ_ONLY_TOOLS) with no declared relationship to the others. Same name, |
| 8 | + * different meanings, one of them security-relevant. |
| 9 | + * |
| 10 | + * These are genuinely different concepts, not the same list typed four times: |
| 11 | + * - the director read surface (tool-sets.ts READ_TOOLS) is "everything a |
| 12 | + * read-only leaf may call", including run_shell and the web tools; |
| 13 | + * - the auto-allow gate is "never needs an approval prompt", a strict |
| 14 | + * subset (shell/web get their own, narrower auto-allow logic) plus |
| 15 | + * manage_tasks (side-effect-free, see classify.ts); |
| 16 | + * - compaction's re-read dedup and thrash's read tracking both care about |
| 17 | + * "read_file specifically, because its result is keyed by path" — this |
| 18 | + * one actually was the same set twice, so it is unified here. |
| 19 | + * Where the concepts differ, the sets stay separate but are derived from the |
| 20 | + * same base and named for what they mean, so a future difference reads as |
| 21 | + * intentional instead of drift. |
| 22 | + */ |
| 23 | + |
| 24 | +import { READ_TOOLS as DIRECTOR_READ_TOOLS } from "./directors/tool-sets.js"; |
| 25 | + |
| 26 | +/** |
| 27 | + * read_file: the one read tool whose result is keyed by path, so an older |
| 28 | + * result for the same path is safely superseded by a newer one. Shared by |
| 29 | + * compaction's re-read dedup and thrash's read-count bookkeeping — both are |
| 30 | + * asking the same question ("was this path already read?"). |
| 31 | + */ |
| 32 | +export const PATH_KEYED_READ_TOOLS: ReadonlySet<string> = new Set(["read_file"]); |
| 33 | + |
| 34 | +/** |
| 35 | + * grep / search_files: pattern-keyed query tools whose repeated identical |
| 36 | + * call reflects current workspace state, not stale history. This is the base |
| 37 | + * both compaction and thrash build on; each adds/omits list_dir for its own |
| 38 | + * reason (see compactor.ts's QUERY_TOOLS and thrash.ts's SEARCH_TOOLS). |
| 39 | + */ |
| 40 | +export const SEARCH_QUERY_TOOLS: ReadonlySet<string> = new Set(["grep", "search_files"]); |
| 41 | + |
| 42 | +/** |
| 43 | + * Tools that never need an approval prompt because they cannot change the |
| 44 | + * workspace: the director's read surface minus run_shell/web_fetch/web_search |
| 45 | + * (which get their own, narrower auto-allow rules — see |
| 46 | + * isAutoAllowedShellCommand and the webfetch/websearch permission classes), |
| 47 | + * plus manage_tasks (side-effect-free by the time the tool executes — see |
| 48 | + * classify.ts). SECURITY-RELEVANT: this gates auto-allow. A tool added here |
| 49 | + * is auto-approved everywhere; get it wrong in either direction deliberately, |
| 50 | + * not by accident. |
| 51 | + */ |
| 52 | +export const AUTO_ALLOW_READ_TOOLS: ReadonlySet<string> = new Set([ |
| 53 | + ...DIRECTOR_READ_TOOLS.filter( |
| 54 | + (tool) => tool !== "run_shell" && tool !== "web_fetch" && tool !== "web_search", |
| 55 | + ), |
| 56 | + "manage_tasks", |
| 57 | +]); |
0 commit comments