pi-double-esc
v1.0.1
Published
Prevent accidental Escape from aborting the LLM — requires double-press to interrupt while streaming
Maintainers
Readme
⏏️ pi-double-esc
Prevent accidental Escape aborts in pi
Require a second Escape press within 500ms to confirm any abort action.
What It Does
When the LLM is streaming a response:
- First Escape press: Shows an
esc again to aborthint on the editor border — does not abort - Second Escape within the debounce window: Actually aborts the streaming response
- If the debounce window expires, the hint clears and escape resets
When the LLM is not streaming, Escape works normally (immediate) — no debounce applied. Autocomplete dismissal always works on a single Escape.
Installation
Option 1: Install via pi package (Recommended)
Install directly from GitHub as a pi package:
pi install https://github.com/monotykamary/pi-double-esc@mainOr add to your settings.json:
{
"packages": [
"https://github.com/monotykamary/pi-double-esc@main"
]
}Option 2: Global Installation
Copy the extension to pi's global extensions directory:
cp double-esc.ts ~/.pi/agent/extensions/Option 3: Project-Local Installation
Copy to your project's .pi/extensions/ directory:
mkdir -p .pi/extensions
cp double-esc.ts .pi/extensions/Option 4: Quick Test
pi -e ./double-esc.tsConfiguration
Set the PI_DOUBLE_ESC_MS environment variable to change the debounce timeout (default: 1500ms):
PI_DOUBLE_ESC_MS=2000 piHow It Works
The extension replaces pi's editor component with a CustomEditor subclass that intercepts Escape key presses:
- On each
session_start,ctx.ui.setEditorComponent()installs the custom editor - The editor uses
ctx.isIdle()(which reflects!session.isStreaming) to detect streaming state - While streaming, the first Escape shows a visual hint and starts a debounce timer
- A second Escape within the window calls
super.handleInput(data)to perform the actual abort - Any other keypress or timeout expiry dismisses the hint
The debounce logic lives in src/double-esc-logic.ts as pure functions for testability.
Development
npm install # install dev dependencies
npm test # run tests
npm run typecheck # type check
npm run lint:dead # check for unused exportsLicense
MIT
