@graelo/pi-defer-modal
Defer modal dialogs while the user is typing to prevent interruption
Package details
Install @graelo/pi-defer-modal from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@graelo/pi-defer-modal- Package
@graelo/pi-defer-modal- Version
0.1.0- Published
- Jul 4, 2026
- Downloads
- not available
- Author
- graelo
- License
- MIT
- Types
- extension
- Size
- 21.7 KB
- Dependencies
- 0 dependencies · 0 peers
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-defer-modal
A Pi extension that defers modal dialogs while you're typing, preventing interruptions to your workflow.
Problem
When extensions display modal dialogs (using ctx.ui.select(), ctx.ui.confirm(), or ctx.ui.input()), these modals grab keyboard focus immediately. If you're in the middle of typing a message, the modal interrupts your typing — keystrokes land in the modal instead of the editor, breaking your train of thought.
Solution
This extension intercepts modal calls from any extension and defers them until you pause typing or submit your input. The tool calls stay blocked (as they should), but the UI presentation is delayed until you're ready.
Features
- Non-interrupting modals: Modals wait until you pause typing before appearing
- Configurable modal types: Choose which modal types to defer (select, confirm, input)
- Adjustable timing: Configure how long to wait after your last keystroke
- Safety ceiling: Maximum deferral time prevents tools from hanging indefinitely
- Status indicator: Optional visual indicator when modals are being deferred
- Works with any extension: Transparently intercepts modals from all extensions
Installation
From npm (recommended)
pnpm add pi-defer-modal
Manual installation
- Clone or download this repository
- Place the
pi-defer-modaldirectory in one of Pi's extension locations:- Project-local:
.pi/extensions/pi-defer-modal/ - Global:
~/.pi/agent/extensions/pi-defer-modal/
- Project-local:
Configuration
Create a config.json file in the extension directory:
{
"enabled": true,
"modalTypes": ["select", "confirm", "input"],
"quietMs": 1500,
"maxDeferMs": 30000,
"showStatusIndicator": true,
"statusText": "⏸ modal pending — pause to review"
}
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | false |
Enable or disable modal deferral |
modalTypes |
string[] | ["select", "confirm", "input"] |
Which modal types to defer |
quietMs |
number | 1500 |
Milliseconds of inactivity before showing deferred modals |
maxDeferMs |
number | 30000 |
Maximum time to defer a modal (prevents hanging) |
showStatusIndicator |
boolean | true |
Show a status indicator when modals are deferred |
statusText |
string | "⏸ modal pending — pause to review" |
Text to show in the status indicator |
Configuration Locations
The extension checks for configuration in these locations (in order of priority):
- Project-local:
.pi/extensions/pi-defer-modal/config.json - Global:
~/.pi/agent/extensions/pi-defer-modal/config.json
Commands
/defer-modal-toggle
Toggle modal deferral on or off.
/defer-modal-toggle
/defer-modal-config
Show the current configuration.
/defer-modal-config
/defer-modal-reload
Reload configuration from file (useful after editing config.json).
/defer-modal-reload
How It Works
- Typing Tracking: The extension subscribes to
ctx.ui.onTerminalInputto track when you type - Modal Interception: It wraps the UI methods (
select,confirm,input) to intercept modal calls - Deferral Logic: When a modal is called, if you're actively typing, the extension waits until:
- You pause typing for
quietMsmilliseconds, OR - You submit your input (press Enter), OR
- The maximum deferral time (
maxDeferMs) elapses
- You pause typing for
- Status Indicator: While waiting, an optional status message shows that modals are pending
Example Usage
With this extension enabled:
- You start typing a command:
git commit -m "fix: ... - An extension (like pi-permission-system) tries to show a permission modal
- Instead of interrupting you, the modal waits
- You finish typing and pause for 1.5 seconds (default
quietMs) - The permission modal appears, ready for your input
Compatibility
- Works with Pi v0.2.0 and later
- Compatible with all extensions that use standard UI modal methods
- No changes required to existing extensions
Development
# Install dependencies
pnpm install
# Type check
pnpm run check
# Build
pnpm run build
License
MIT