Plan: tools allowed by rule live in one table, and every registered tool is classified
Closes: #941. Relates to: #136, #310, #565 (tools that fell through one at a time). Branch: fix/codemode-allowed-by-rule. Status: Done (2026-11-27) — tools allowed by rule are one table; codemode and three others joined it
Context
Ruled by the operator (2026-11-27): fix this structurally, not with one more copied line; all four unruled tools below go in the table. What the tree says today, by reading:
-
packages/pi-modes/modes.jsongives auto, plan and manual apermissionmap each (yolo has none). 26 tools carry a one-rule map in each of the three: 78 entries, 77 of them{"*": "allow"}. The one difference ismsg_post, which plan denies. -
A tool with no rule in a mode reaches the judge stage (
GATE_STAGESinpackages/pi-modes/authorize.ts: "rule allow" needs a rule). Four tools the distribution loads have none: pi’scodemodeandtool_search, and pi-subagents'get_subagent_resultandsteer_subagent. -
For a helper the ask is forwarded to the lead’s session carrying the tool’s name as its value, so the judge sees no input, defers, and the step lands in
/pendingas «codemode: codemode» (#941 has the counts). -
A call a tool makes through
ctx.executeTool(), which is how a codemode script calls tools, goes "through argument validation and thetool_callandtool_resulthandlers like model-issued calls", and a blocked one comes back as an error result (node_modules/@earendil-works/pi-coding-agent/docs/extensions.md, "Calling Other Tools"). The permission system and the guards gate ontool_call, so each call inside a script is gated on its own. -
Nothing checks that a registered tool has a rule.
remember(#136),forget(#310) andcounteach got a test of their own after falling through (packages/pi-modes/test/mode-policy.test.ts, "deterministic instruments are not judge questions";test/judge-wiring-callback.test.ts, "the package’s own tools never reach the judge"). -
The shared-list pattern exists:
safetyValveis one top-level list thatapplySharedValve(packages/pi-modes/config.ts) fills into each mode’s judge when the final config is validated.validateModesConfig(raw, source, { resolveValve: false })leaves it unresolved for the baseline thatloadModesConfigmerges an overlay over, so an overlay’s list is the one resolved. Every top-level key is listed inTOP_LEVEL_KEYS, which a test holds equal tomodes.adoc’s summary table (`tools/lib/test/public-surface.test.mjs). -
The tools our packages register are already inventoried from source:
toolsIn(shippedSources(root))intools/lib/public-surface.mjs.packages/pi/test/web-tools.test.tsreads the tools pi-web-access registers through pi’sDefaultResourceLoaderand holds them equal to a list.
Design
The table and the fold
ModesConfig gains allowedByRule?: string[] (added to TOP_LEVEL_KEYS): the tools allowed by rule in every mode that has rules. modes.json lists 30 names there, after safetyValve:
count, monitor, monitor_stop, monitor_list, monitor_restore, job, job_stop, job_list, msg_channels, msg_subscribe, msg_handle, msg_post, msg_read, pending_withdraw, generate_image, remember, forget, yield, get_search_content, fetch_content, web_enable, web_search, source_check, enter_plan_mode, exit_plan_mode, ask, and the four new ones: codemode, get_subagent_result, steer_subagent, tool_search.
The 77 {"": "allow"} entries leave the three modes. Plan keeps "msg_post": {"": "deny"}.
A new applySharedAllows(config) in config.ts, beside applySharedValve: for each mode with a permission map and each listed tool, a tool with no rules in that mode gets {"": "allow"}; a tool whose own rules there do not say what is gains "": "allow" beside them; a tool whose own rules set is left as the mode wrote it. validateModesConfig’s option is renamed `resolveShared and governs both lists: the final config is applySharedAllows(applySharedValve(cfg)), the baseline pass resolves neither. The option has three callers, all renamed: its definition and loadModesConfig in config.ts, and tools/lib/test/stage.test.mjs ("is an overlay pi-modes accepts, merged as pi-modes merges one"), which is untyped and would otherwise pass an option nothing reads. So an overlay’s allowedByRule replaces the shipped list, as its safetyValve does, and an overlay’s rule for a tool in a mode stands.
Tools that are never allowed by name
config.ts exports DECIDED_BY_INPUT: bash, powershell, read, write, edit, grep, find, ls, path, path_read, path_write, external_directory, external_directory_read, external_directory_write. Their asks are decided by the command or the path they carry. The config check refuses any of them in allowedByRule, naming it ("is decided by its command or path, never by name"): the shipped bash and read maps, and auto’s and manual’s write and edit, set no *, so listing one would allow everything no pattern names.
Classifying every registered tool
config.ts exports DECIDED_ELSEWHERE, a record of tool to reason, holding subagent ("the delegation gate answers every spawn"), and unruledTools(config, names): for each mode with rules, each name that has no rules in the resolved mode, is not in DECIDED_BY_INPUT, is not a key of DECIDED_ELSEWHERE and does not start mcp__ (an operator’s own servers), as { mode, tool }. Three tests hold it empty over every tool the distribution loads; see Tests.
Scope
-
config.ts,modes.json, the renamed option’s caller intools/lib/test/stage.test.mjs, the tests below, the docs and the CHANGELOG, on the branch; validate and consumer-sim; the MR. -
At approval, a follow-up issue is filed for the other half of the cause, which this plan does not touch: a forwarded ask does carry the tool’s input, as the "input" entry of its payload’s evidence, cut at 200 characters by the permission system, and pi-modes'
normalizeAsknever reads it. Any unruled tool a helper calls (an MCP tool) still reaches the judge blind.
Not in this plan: reading that forwarded input; whether a helper may delegate; any judge prompt.
Tests
| Category | Test | Pins |
|---|---|---|
contract |
|
the copies are gone and nothing lost its allow |
contract |
same file, new, on a small config: a mode’s own |
the fold |
contract |
same file, new: |
a path or a command is never allowed by name |
contract |
|
the rename reached the untyped caller |
contract |
same file as the rows above, beside "overlay safetyValve reaches the merged config": an overlay’s |
the overlay |
regression |
|
#941’s case |
contract |
|
the four |
contract |
|
a tool a package registers is classified |
contract |
|
a bundled extension’s tool is classified, and a renamed or added one fails |
contract |
new |
a call made inside another tool is gated like a direct one, on the pinned pi |
Mutants, each to fail its test: codemode removed from the list; the fold overwriting a mode’s own * rule; the check accepting bash; a tool name added to the inventory’s input with no classification. Coverage bars hold (pi-modes 97/90).
Risks
| Risk | Mode | Mitigation |
|---|---|---|
A tool decided by its input is listed and every command or path no pattern names is allowed |
fail-closed |
the config check refuses each |
The fold overrides a rule a mode wrote (plan’s |
fail-open |
the fold never changes a |
Removing the copies drops an allow, and a tool starts going to the judge |
loud |
the contract test over all 30 tools in three modes |
|
fail-closed |
each call a script makes fires |
An overlay adds a tool to the list |
silent |
the operator’s own file, as |
A tool pi itself adds is not seen by the tests (the two built-ins are a literal list) |
silent |
it has no rule, so its calls go to the judge as today; the list is re-read when pi is bumped |
The subagents shim does not load alone through the loader in a unit test |
loud |
the test fails; its three names are then read from pi-subagents' source as |
Delivery
-
Canonical page:
docs/modules/ROOT/pages/modes.adoc: a row forallowedByRulein the top-level table, and the "Mode rules" paragraph rewritten around the table (what it holds, that a mode’s own rule wins, which tools can never be listed, what an unlisted tool does). -
CHANGELOG.adoc== Unreleased: a Fixed entry (a helper’s codemode call no longer waits on the human) and a Changed entry (the table). -
This plan committed as
docs/modules/ROOT/pages/plans/tools-allowed-by-rule.adoc, listed indocs/modules/ROOT/nav.adoc; Status In progress at start, Done at the merge. -
Validate and consumer-sim before the push; the MR (
Closes #941) merged with squash off; the merge SHA on the issue. pi-modes takes a bump at the next release.