pi-edit-last-message
Pi extension that adds /last to restore the most recent user message into the editor
Package details
Install pi-edit-last-message from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-edit-last-message- Package
pi-edit-last-message- Version
0.2.0- Published
- Apr 30, 2026
- Downloads
- not available
- Author
- artriy
- License
- MIT
- Types
- extension
- Size
- 8.8 KB
- Dependencies
- 0 dependencies ยท 1 peer
Pi manifest JSON
{
"extensions": [
"./extensions"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-edit-last-message
Pi extension package adding /last to restore the most recent user-authored text message into the editor for editing and resubmission.
Behavior
- Scans
ctx.sessionManager.getBranch()only, so it targets the current active branch. - Uses only entries where
entry.type === "message"andentry.message.role === "user". - Ignores assistant, tool, bash, custom, summary, label, and metadata entries.
- Preserves stored text exactly, including multiline prompts.
- Does not submit anything automatically.
- Uses fast same-session restore when the message has a parent:
ctx.navigateTree(parentId, { summarize: false }), thenctx.ui.setEditorText(text). - Falls back to Pi's public fork restore only when the latest user message is the first/root message, because public
navigateTree()has no "before root" target.
No private session APIs are used.
If no prior user message exists, /last shows:
No previous user message found.
If the latest user message has images but no text, /last warns that text-only restore is not possible and does not fall back to older messages.
Install
From npm:
pi install npm:pi-edit-last-message
Then inside Pi:
/reload
/last
From GitHub:
pi install https://github.com/artriy/pi-edit-last-message
Then inside Pi:
/reload
/last
Local development
npm install
npm run check
pi -e ./extensions/edit-last-message.ts
Manual acceptance checks:
- Send
hello, receive any assistant response, run/last; editor containshello. - Send multiline prompt, run
/last; exact line breaks remain. - If current leaf is after assistant/tool output,
/laststill finds latest user message. /lastdoes not submit automatically./lastdoes not restore assistant/tool/system/custom messages.- No user message case shows
No previous user message found.and does not crash. - Image-only latest user message shows warning.
Related work
pi-copy-user-messageโ reference package for current-branch latest-user-message scanning and text extraction patterns.pi-edit-session-in-placeโ broader in-place picker/editor for earlier user messages.
This package keeps narrower scope: /last only, using same-session restoration when Pi's public APIs allow it.
Security
Pi packages execute code with your user permissions. Review source before installing any third-party Pi package.
License
MIT