Editor comment watch mode for pi-coding-agent.
pi-watcher watches files in the current pi working directory for explicit AI!, AI?, and AI. comments. When you save a file with an actionable marker, it sends a focused prompt into the active pi session.
# Install globally
pi install git:github.com/vedang/pi-watcher
# Or install for only the current project
pi install -l git:github.com/vedang/pi-watcherNo --watch flag is needed. If the extension is installed and config does not disable it, watcher starts automatically when pi starts in an interactive working directory. In no-UI print mode, status and manual scan work, but live watching does not auto-start.
-
Start pi from your project root.
-
Add a comment in your editor:
function label(value: string | null) { return value.trim(); // handle null AI! }
-
Save the file.
-
pi receives a user message with file path, line number, and surrounding snippet.
-
For
AI!, pi should make focused edits. After the agent turn ends,pi-watcherremoves the handled trigger comments by default.
Supported line-comment prefixes: #, //, --, and semicolon comments such as ; or ;;;.
// AI! edit this code
// explain this branch AI?
// AI. context anchor onlyMarkers are case-insensitive (ai!, AI?, Ai.) and may appear at the normalized comment start or at the end of a comment after whitespace. OpenAI, -ai!, some-ai?, and bare AI are ignored.
Marker behavior:
AI!: edit request. Prompt tells pi to use normal read/edit/write tools; watcher removes handled trigger comment blocks after the run.AI?: question. Prompt tells pi to answer without editing unless comment explicitly asks for edits; watcher removes handled question comments after the run.AI.: context anchor. Included with next actionableAI!orAI?batch, but does not trigger a turn alone.
/watcher status show watcher state, config paths, queue, last trigger
/watcher config show effective config paths and values
/watcher start enable watcher in project config and start now
/watcher stop disable watcher in project config and stop now
/watcher scan scan roots now for AI comments
/watcher clear clear pending queue and processed marker ledger
/watcher retry retry last processed/suppressed marker batch
/watcher global start|stop update global config
/watcher project start|stop update project config
Bare /watcher start and /watcher stop write project config at <cwd>/.pi/extensions/pi-watcher.json.
The footer status shows watcher on, watcher off, watcher queued, or watcher dispatching. In UI mode, a small widget also shows queued marker count and last trigger.
Config precedence:
- defaults
- global config:
~/.pi/agent/pi-watcher.json - project config:
<cwd>/.pi/extensions/pi-watcher.json
Project config wins over global config.
Default config:
{
"enabled": true,
"scanOnStart": true,
"roots": ["."],
"include": ["**/*"],
"ignore": [
"**/.git/**",
"**/.jj/**",
"**/.pi/**",
"**/.agents/**",
"**/node_modules/**",
"**/dist/**",
"**/build/**",
"**/.cache/**"
],
"maxFileBytes": 1048576,
"debounceMs": 300,
"contextLines": 12,
"maxPromptBytes": 60000,
"marker": "AI",
"removeHandledActionComments": true,
"removeContextAnchorsInActionBlock": false,
"busyPolicy": "queue_until_idle"
}Example project override:
{
"enabled": true,
"roots": ["src", "tests"],
"ignore": ["**/fixtures/**"],
"contextLines": 8
}After pi dispatches an actionable marker, pi-watcher remembers the normalized comment intent and, by default, removes handled AI!/AI? trigger comment blocks when the agent turn ends. Inline trigger comments are stripped while preserving code before the comment. AI. context anchors are preserved unless removeContextAnchorsInActionBlock is enabled.
If cleanup is disabled or pi leaves the same AI! or AI? comment in place, the watcher suppresses repeat dispatches. Change the comment text or run /watcher retry to dispatch it again.
- Only explicit
AI!andAI?comments trigger turns. - Large files over
maxFileBytes, likely binary files, ignored directories, and paths outside configured roots are skipped. - The parser handles common line-comment syntax, not every language-specific edge case.
- Prompts are capped by
maxPromptBytes; if a batch is too large, pi may need to read files directly. - Keep secrets out of marked snippets. Saved comments and surrounding context are sent to the active pi session.
make init
make doctor
make test
make check
make formatLocal extension smoke test:
pi --no-extensions --no-skills --no-prompt-templates --no-context-files --no-session -e ./src/index.ts -p "/watcher status"