← Catalog

pi-tools-switch

Pi extension for built-in tools management and prefix-caching-friendly tool gating

Extension

Install

Install with PiG

pig install npm:pi-tools-switch

Install with Pi

pi install npm:pi-tools-switch
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "prompts": [
    "./prompts"
  ],
  "extensions": [
    "./extension/index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 1.0.0 (README.md). PiG does not review it.

pi-tools-switch

English | 简体中文

A Pi Coding Agent extension package that manages the availability of eight built-in tools and provides prefix-caching-friendly tool gating through prompt-template commands or custom text triggers — including a built-in Plan Mode for read-only exploration and planning.

Features

1. Built-in Tool Management

Toggle the eight built-in Pi tools on and off without affecting external tools:

LetterTool
Rread
Wwrite
Eedit
Bbash
Ppowershell
Ffind
Ggrep
Lls

Status bar format: [RWEBPFGL]. A disabled tool shows - in its slot.

Note: Toggling tool availability changes the active tool set, which may invalidate the LLM's prefix cache. The tool gating feature below is designed to be prefix-caching-friendly and does not affect prefix cache validity.

2. Tool Gating Modes

Activate a persistent gating mode by typing a configured trigger prefix. While active, the mode restricts which tools the agent may call. The mode stays active across turns until you explicitly exit it.

Built-in mode:

  • /plan-mode — read-only exploration and planning. Allows writing Markdown plans under .agents/plans/.

You can also define custom gating modes with their own triggers, allowed tools, and allowed write directories.

Installation

Install as a Pi package.

# From npm
pi install npm:pi-tools-switch

# From this GitHub repository
pi install git:github.com/gszj2018/pi-tools-switch

Usage

Slash Commands

CommandDescription
/ptsw-statusShow active and gating status for all built-in and external tools.
/ptsw-builtin [tool]Toggle one built-in tool, or open the tool menu without arguments.
/ptsw-preset [name]Apply a preset, or open the preset menu without arguments.
/ptsw-mode [name]Show mode details, or list modes and exit triggers without arguments.
  • [tool] and [name] are optional and support Tab completion. Tool toggling accepts one name only; /ptsw-status takes no arguments.
  • Menus support TUI and RPC; choose Exit or press Esc to close them. Without UI, argument-free tool/preset commands only notify the current status or preset list; visible output is not guaranteed. Calls with arguments still work directly.
  • Mode queries do not switch modes. Presets preserve external tools and are not saved as defaults.

Prompt Templates

This extension also ships with two prompt templates. Type / followed by the template name in the editor to invoke them:

TemplateDescription
/plan-modeEnter plan mode (read-only exploration + write plans under .agents/plans/).
/normal-modeExit the active gating mode.

Built-in Presets

PresetTools enabledStatus bar
readread[R-------]
exploreread, find, grep, ls[R----FGL]
defaultread, write, edit, bash[RWEB----]
fullread, write, edit, bash, find, grep, ls[RWEB-FGL]

Presets do not include powershell. Use /ptsw-builtin powershell to toggle it, or define a custom preset if you need it.

Plan Mode

Plan Mode is the built-in gating mode for read-only exploration and planning.

How the user enters and exits:

  • Enter: type /plan-mode.
  • Exit: type /normal-mode (the default exit trigger), or activate another gating mode.
  • The mode persists across turns until one of the exit paths above is used.

What the agent can do in Plan Mode:

  • Use read-only tools: read, find, grep, ls.
  • Write Markdown plan documents under .agents/plans/.
  • All other tools, including bash and external tools, are blocked.

Can the agent exit Plan Mode on its own?

No. When the plan is complete, the agent outputs the full plan and waits for your next instructions. Only you can exit the mode.

Configuration

Create ~/.pi/agent/tools-switch.json (or <agentDir>/tools-switch.json if you have customized PI_CODING_AGENT_DIR) to customize presets, subagent detection, and gating modes. The file is loaded once when the extension starts.

{
  "presets": {
    "review": ["read", "grep", "ls"]
  },
  "subagentEnvVars": ["MY_SUBAGENT_FLAG"],
  "gatingModes": {
    "test": {
      "trigger": ["/test-mode"],
      "allowTools": ["read", "bash"],
      "allowWriteDir": ["tests"]
    }
  },
  "gatingExitTrigger": ["/normal-mode"]
}

See schemas/tools-switch.schema.json for the full JSON Schema.

Configuration Fields

FieldTypeDescription
presetsobjectUser-defined tool presets. Names follow [a-z][a-z0-9_-]*. Values are arrays of tool names.
subagentEnvVarsstring[]Extra environment variables that indicate a subagent context, in addition to built-in ones.
gatingModesobjectUser-defined gating modes. Keys are mode names. Same-name modes override built-in modes.
gatingExitTriggerstring[]Prefixes that exit the active gating mode. Empty or omitted falls back to "/normal-mode". Non-empty fully overrides it.

Gating Mode Fields

FieldTypeDescription
triggerstring[]Input prefixes that activate the mode. Any one matching the raw input activates it.
allowToolsstring[]Tools explicitly allowed while the mode is active. These bypass all other restrictions.
allowWriteDirstring[]Directories where write/edit are allowed. Empty or undefined blocks all write/edit.

Tool Interception Order

When a gating mode is active, tool calls are evaluated in this order:

  1. Read-only tools: read, find, grep, ls — allowed.
  2. Tools listed in allowTools — allowed.
  3. write / edit — allowed only if the target path is strictly inside one of the allowWriteDir directories.
  4. All other tools, including bash and external tools — blocked.

Note: If write or edit is listed in allowTools, it is fully allowed and skips the directory check.

Status Bar

Two independent status indicators are shown:

  • Tools status: [RWEBPFGL] — shows which built-in tools are currently active.
  • Gating status: [M: plan], [M: -], or [M: last => active] — shows the active gating mode.

Status is refreshed on session_start, turn_start, agent_settled, and whenever tools or modes change.

Subagent Behavior

When a subagent context is detected (via common environment variables such as PI_IS_SUBAGENT, PI_SUBAGENT_CHILD, etc.), the extension remains completely silent: it does not register tools, commands, events, or prompts.

Note: This extension detects subagents only when they are implemented as child processes that inherit environment variables. In-process subagent implementations are not detected.

You can extend the list of subagent-detecting environment variables via the subagentEnvVars configuration field.

Development

# Install dependencies
npm install

# Run tests
npm test

# Type-check
npm run typecheck

To load the extension and prompt templates locally for development without packaging, run pi from the repository root:

pi -e ./extension/index.ts --prompt-template ./prompts

The project is written in TypeScript and uses the Node.js built-in test runner.

Project Structure

pi-tools-switch/
├── extension/
│   ├── index.ts              # Extension entry point
│   ├── config.ts             # Configuration loading and normalization
│   ├── builtin-tools.ts      # Built-in tool management, presets, status bar
│   ├── tool-gating.ts        # Tool gating engine
│   ├── tool-status.ts        # /ptsw-status command
│   ├── subagent-support.ts   # Subagent detection
│   └── utils*.ts             # Shared helpers
├── prompts/
│   ├── plan-mode.md          # /plan-mode prompt template
│   └── normal-mode.md        # /normal-mode prompt template
├── schemas/
│   └── tools-switch.schema.json
└── tests/                    # Unit and integration tests

License

MIT