Created
March 19, 2026 01:27
-
-
Save fayimora/71292fb127749589285de3f3fd83bc33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * oh-pi Auto Session Name Extension | |
| * | |
| * Automatically names sessions based on the first user message. | |
| */ | |
| import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; | |
| export default function (pi: ExtensionAPI) { | |
| let named = false; | |
| pi.on("session_start", async (_event, ctx) => { | |
| named = !!pi.getSessionName(); | |
| }); | |
| pi.on("agent_end", async (event) => { | |
| if (named) return; | |
| const userMsg = event.messages.find((m) => m.role === "user"); | |
| if (!userMsg) return; | |
| const text = typeof userMsg.content === "string" | |
| ? userMsg.content | |
| : userMsg.content.filter((b) => b.type === "text").map((b) => (b as { text: string }).text).join(" "); | |
| if (!text) return; | |
| const name = text.slice(0, 60).replace(/\n/g, " ").trim(); | |
| if (name) { | |
| pi.setSessionName(name); | |
| named = true; | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment