pi-double-esc

Prevent accidental Escape from aborting the LLM — requires double-press to interrupt while streaming

Packages

Package details

extension

Install pi-double-esc from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-double-esc
Package
pi-double-esc
Version
1.0.1
Published
Jun 15, 2026
Downloads
not available
Author
monotykamary
License
MIT
Types
extension
Size
10.5 KB
Dependencies
0 dependencies · 0 peers
Pi manifest JSON
{
  "extensions": [
    "./double-esc.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

⏏️ pi-double-esc

Prevent accidental Escape aborts in pi

Require a second Escape press within 500ms to confirm any abort action.

pi extension license


What It Does

When the LLM is streaming a response:

  • First Escape press: Shows an esc again to abort hint 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@main

Or 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.ts

Configuration

Set the PI_DOUBLE_ESC_MS environment variable to change the debounce timeout (default: 1500ms):

PI_DOUBLE_ESC_MS=2000 pi

How It Works

The extension replaces pi's editor component with a CustomEditor subclass that intercepts Escape key presses:

  1. On each session_start, ctx.ui.setEditorComponent() installs the custom editor
  2. The editor uses ctx.isIdle() (which reflects !session.isStreaming) to detect streaming state
  3. While streaming, the first Escape shows a visual hint and starts a debounce timer
  4. A second Escape within the window calls super.handleInput(data) to perform the actual abort
  5. 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 exports

License

MIT