@signalridge/pi-code-actions1.2.7
Pick code blocks or inline snippets from recent assistant messages to copy or insert.
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-code-actions
/code to pick code blocks (```) or inline code from recent assistant messages and then copy or insert them. Helpful for retrieving commands and filepaths mentioned by Pi.
/code opens a menu you can type to search. You can hit enter to copy the snippet, or right arrow to insert it in the command line.
Install
pi install npm:@signalridge/pi-code-actions
pi install npm:@signalridge/pi-code-actions
Then filter to just this extension in ~/.pi/agent/settings.json:
{
"packages": [
{
"source": "npm:@signalridge/pi-code-actions",
"extensions": ["index.ts"]
}
]
}
Usage
- Command:
/code - Optional args:
allto scan all assistant messages in the current branch (default: all)blocksto hide inline snippets (default: inline + fenced blocks)limit=50to cap the number of snippets returned (default: 200)copy,insert, orrunto choose an action up front- a number to pick a specific snippet (1-based)
Examples:
/code/code blocks/code copy/code all/code limit=50/code run 2
Actions
- Copy: puts the snippet on your clipboard using a private temporary file that is removed afterward
- Insert: appends the snippet to the TUI input editor. RPC cannot read or append to the client draft, so insertion requires confirmation before replacing the entire draft
- Run: executes the complete snippet with
bash -lcon POSIX orpowershell -NoProfile -Commandon Windows (asks for confirmation), in the working directory captured before confirmation. Output and the shell's exit code are displayed after cleanup.
/code run is a user-confirmed full-shell action, not an agent tool call. Tool-call permission rules and plan-mode tool restrictions do not intercept it. Confirmation is not a sandbox: review the entire snippet, and use copy/insert instead when execution is forbidden by your policy.
Notes
- Pending dialogs, clipboard utilities, and running snippets are cancelled on pre-switch, pre-fork, pre-tree, session start, committed tree, and shutdown events. A pre-navigation event cancels the interaction even if navigation is later vetoed; this does not provide an atomic post-veto transition.
- At pre-navigation boundaries, custom TUI panes close synchronously, restoring their captured draft before navigation can write a new one.
- Snippet subprocesses are owned locally, not delegated to a background extension. On POSIX, a detached supervisor holds a private process group alive through a 250 ms TERM grace period, then KILLs the group; this also cleans up background children after normal shell exit. Signals never target Pi's/ancestor shells' group or a previously reaped leader. Cleanup waits are bounded (up to two 1-second waits for exit/output closure). On Windows, the live supervisor anchors
taskkill /PID /T /F, with a 1-second taskkill deadline and direct-parent fallback; this is best-effort tree cleanup, not a Windows Job Object guarantee. - When Pi runs under Bun (including compiled standalone builds), snippet supervision requires a Node.js executable named
nodeonPATH; a missing executable reports a failed run. Node-hosted Pi reuses its Node executable. The supervisor must signal readiness within 5 seconds; stalled startup (for example, inheritedNODE_OPTIONS=--inspect-brk=0) or disconnected IPC fails the run and triggers owned cleanup. This startup deadline does not limit snippet execution after readiness. Runtime/security options and the snippet environment are inherited unchanged. - This is lifecycle cleanup, not containment: processes that deliberately create a new session/group, detached Windows processes, an externally killed supervisor, or abrupt termination of Pi can evade cleanup. Keep long-lived services outside
/code run. - Snippet output captures the first 64 KiB of stdout and stderr independently (128 KiB combined, plus small per-stream loss notices). Both pipes continue draining after overflow, without retaining further data. UTF-8 is decoded independently per stream, and a character cut at the capture boundary is dropped rather than replaced. Decoded output is also byte-bounded, including invalid UTF-8 replacement expansion. Only an overflowing stream gets a truncation notice; discarded output is not saved elsewhere. Ordinary output and exit codes are unchanged.
- Only assistant messages are scanned.
- Inline code uses single backticks. Code blocks use triple backticks.
- Inline snippets are filtered to path-like content:
~/...,./..., paths with 2+ slashes, or files with extensions. Useblocksto show only code blocks.
Changelog
See CHANGELOG.md.