pi-edit-last-message

Pi extension that adds /last to restore the most recent user message into the editor

Package details

extension

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" and entry.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 }), then ctx.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:

  1. Send hello, receive any assistant response, run /last; editor contains hello.
  2. Send multiline prompt, run /last; exact line breaks remain.
  3. If current leaf is after assistant/tool output, /last still finds latest user message.
  4. /last does not submit automatically.
  5. /last does not restore assistant/tool/system/custom messages.
  6. No user message case shows No previous user message found. and does not crash.
  7. Image-only latest user message shows warning.

Related work

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