@monkeyman520/pi-pretty-session0.1.0
Automatic session naming, title and description summarization, dynamic configuration, session metrics, and project context for Pi
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 Pretty Session
An independently installable Pi extension that automatically names sessions, summarizes a concise title and one-sentence description, supports dynamic configuration hot-reloading, displays live session metrics (start time, last updated time, context length), and collects project information to help you orient quickly.
Compatibility and resources
- Node.js >= 22.19.0; TypeScript ESM with a Rolldown build.
- Requires Pi's
setSessionName,appendEntry,sessionManager,getContextUsage,modelRegistry.complete,ui.setWidget/ui.setStatus/ui.custom,switchSession, and lifecycle hooks (session_start,agent_settled,session_compact,session_tree,session_info_changed,session_shutdown). Tested with Pi 1.5.0, Windows, Node 26.13.0. - One extension entry resource:
dist/index.js. Host*peers follow Pi's extension loading contract rather than claiming compatibility with every host version. - No dependency on
pi-auto-resume,pi-quota-keeper, or other sibling packages.
Install and use
After the package is available on npm, install it without a version pin:
pi install npm:@monkeyman520/pi-pretty-session
pi update npm:@monkeyman520/pi-pretty-session
Use pi update --extensions for all installed extensions. Pinned versions do not follow later releases. On a fresh launch after an update, Pi can show the bundled changelog under Extension Updates; the plugin does not poll for updates.
From the repository root, prepare the workspace and build before loading locally:
bun install --frozen-lockfile
bun run --cwd packages/pi-pretty-session build
pi -e ./packages/pi-pretty-session
# Or persist this local package:
pi install ./packages/pi-pretty-session
Runtime imports are Node built-ins and Pi-provided host modules (@earendil-works/pi-coding-agent, @earendil-works/pi-ai, @earendil-works/pi-tui, typebox). Prepare local development dependencies separately below when running static checks and unit tests.
User-facing behavior
- Automatic session naming & summarization:
- After the first completed conversation turn,
pi-pretty-sessionsummarizes the active branch into a concisetitleand a single-sentencedescription(default budgets:maxTitleLength: 40,maxDescriptionLength: 100), stripping Pi-expanded<skill>...</skill>blocks and leading/skill:...//.../$...command prefixes soSKILL.mdinstructions never pollute summaries. - When
useLlmis enabled (default) and a session or configured model is callable, it issues an isolated, tool-freectx.modelRegistry.complete()request using the configuredlanguage("auto"by default, or explicit tags like"zh-CN","en","ja") without mutating the foreground conversation transcript. When no model/credentials are available or the request fails, it falls back automatically to deterministic, language-aware local heuristic extraction from user prompts and touched file paths. - Duplicate titles in the same project/session directory are automatically disambiguated by reserving 22 characters before truncating the base title and appending a local
[YYYY-MM-DD HH:mm:ss]creation-time suffix. - The generated
titleis written viapi.setSessionName(title)(so Pi's built-in/resumepicker, footer, and terminal title show it immediately), while the full structured metadata (title,description, summary source, start/update timestamps, context token usage, and project summary) is persisted as apretty-sessioncustom entry viapi.appendEntry()without adding tokens to LLM context.
- After the first completed conversation turn,
- Title update policy, dynamic summary updates & manual-rename lock:
- By default (
titleUpdateMode: "once"),titleis set on the initial summary turn and preserved (retainingmanualLocked: falseand its originalllm/heuristicsource) while subsequent triggers—everyupdateEveryTurnscompleted turns, context growth bycontextDeltaTokens, or after/compact(summarizeOnCompact)—continue updatingdescriptionand session metrics without re-appending duplicate suffixes. SwitchtitleUpdateModeto"dynamic"(via config or/ps toggle title) to refresh titles on subsequent triggers as well, or run/ps summarizeto force-refresh bothtitleanddescription. - Manual renames (via
/name,/resumerename, or/ps rename) automatically lock the custom title against dynamic overwrite whileprotectManualNameis enabled (default). Run/ps unlockor/ps summarizeto resume or force title generation.
- By default (
- Live session metrics & project context:
- Displays a configurable TUI widget (
aboveEditororbelowEditor) and footer status bar entry showing the sessiontitle,description, start time, last update time, context length (tokens / contextWindow (%)), turn/message counts, and project info (project name and shortened path, Git branch, dirty file count, latest commit summary, detected manifestpackage.json/pyproject.toml/Cargo.toml/go.modname/version/scripts, and saved session count for the project).
- Displays a configurable TUI widget (
Commands
Pi dispatches built-in interactive commands (/resume, /session, /name) before extension commands, so this plugin exposes /pretty-session and its short alias /ps following the unified /<extension> <action> [other-args] convention with multi-token argument auto-completion (getArgumentCompletions):
/psor/ps browse [current|all]: Open the interactive TUI session & project browser (search sessions by title, description, project, or branch; pressEnterto switch sessions viactx.switchSession,Tabto toggle Current Project vs All Projects,Ctrl+Gto re-summarize,Ctrl+Rto rename,Ctrl+Wto toggle the widget,Ctrl+Sto open the TUI settings panel). In non-TUI modes (such as RPC), outputs the formatted session and project dashboard notification./ps status(or/ps info): Show the current session's title, description, start time, last update time, context length, project overview, and active configuration./ps project: Refresh and display detailed project information (path, Git branch/dirty count/latest commit, manifest details and scripts, project session count)./ps summarize(or/ps refresh): Immediately generate/refresh the session title and description (overriding any manual-name lock)./ps rename <title> [| <description>]: Set a custom session title (and optional description) and lock it against automatic overwrite./ps unlock: Clear the manual title lock so automatic dynamic updates can update the title again./ps list [current|all]: List saved sessions for the current project (orallprojects) with their descriptions, timestamps, and context metrics./ps config [reload | <key> [<value>]]: Open the interactiveSettingsListTUI configuration panel (when invoked with no<key>in TUI mode), force a reload from disk (reload), or dynamically view/update and persist a setting (for example/ps config titleUpdateMode dynamic,/ps config language zh-CN,/ps config updateEveryTurns 5,/ps config widgetPlacement belowEditor,/ps config model openai/gpt-4o-mini, or/ps config model default)./ps toggle <auto|llm|widget|status|lock|compact|title>: Toggle boolean settings (or switchtitleUpdateModebetweenonceanddynamicviatitle) at runtime without restarting Pi./ps help: Display command usage.
Configuration
Create or edit pi-pretty-session.json in Pi's agent directory (normally ~/.pi/agent; PI_CODING_AGENT_DIR is respected). Changes to pi-pretty-session.json are hot-reloaded automatically on file modification without restarting Pi or running /reload.
All fields are optional. Defaults:
{
"enabled": true,
"useLlm": true,
"titleUpdateMode": "once",
"language": "auto",
"updateEveryTurns": 3,
"contextDeltaTokens": 8000,
"summarizeOnCompact": true,
"protectManualName": true,
"showWidget": true,
"widgetPlacement": "aboveEditor",
"showStatus": true,
"maxTitleLength": 40,
"maxDescriptionLength": 100,
"summaryTimeoutMs": 15000
}
Optional model ("provider/modelId" or "modelId") overrides the active session model for summarization calls. Unknown fields or out-of-range values are rejected by TypeBox validation; if pi-pretty-session.json becomes malformed, the extension notifies the user and retains the previous safe configuration rather than crashing the session.
Permissions and risks
This extension runs with Pi's full operating-system process privileges:
- Filesystem access: Reads local project manifests (
package.json,pyproject.toml,Cargo.toml,go.mod), saved session JSONL files in Pi's session directory, andpi-pretty-session.jsonin Pi's agent directory. Writespi-pretty-session.jsonwhen updating settings via/ps configor/ps toggle, and appendssession_info/pretty-sessioncustom entries to the active session. - Process execution: Runs read-only
gitcommands (rev-parse,symbolic-ref,status --porcelain,log -1) with bounded timeouts in the session working directory. - Model/network usage: When
enabledanduseLlmare active, sends bounded conversation excerpts to the active or configured model viactx.modelRegistry.complete(), which can consume model tokens/quota. Set"useLlm": false(or run/ps toggle llm) for strictly local heuristic summarization.
Development and verification
Rolldown inlines the private support library where used. Pi SDKs and TypeBox remain host peers, and each plugin owns its state and lifecycle.
The shared library owns configuration-file and TUI/discovery mechanisms; this plugin retains its own schema, failure policy, actions, instances and resource cleanup.
Package-local configuration metadata supplies both command completions and panel presets; the TypeBox schema remains the validation authority, including valid non-preset values. Lifecycle regression tests verify factory inactivity, repeated-start cleanup, independent instances, and that late summaries cannot write metadata or rename sessions after tree navigation or shutdown.
The optional collection isolation matrix additionally exercises all seven plugin combinations in real Pi; it is development-only, not an installation or runtime dependency.
From the package directory after the root frozen install and build:
cd packages/pi-pretty-session
bun run typecheck
bun run check
bun run test
bun run smoke
TypeScript no-emit, Biome and Bun tests are separate from the Rolldown build and Pi smoke.
The smoke test requires an installed Pi binary. If pi is not directly executable (for example a Windows command shim), set PI_BINARY to the actual executable path. PowerShell example:
$env:PI_BINARY = 'C:\path\to\pi.exe'
bun run smoke
The smoke test copies only this package into a temporary directory without sibling plugins or inherited development node_modules, installs its declared production dependencies from the shipped archive/lockfile, initializes a temporary Git repository and package.json, configures an isolated Pi agent directory and a synthetic provider, and launches real Pi RPC. It verifies /pretty-session and /ps command registration, automatic LLM session naming and description generation after the first turn, start/update timestamps and context length reporting, project Git and manifest inspection, manual rename locking, dynamic pi-pretty-session.json hot-reloading (widgetPlacement: "belowEditor", updateEveryTurns: 1), explicit /ps summarize override, and clean shutdown. Expected output ends in PASS.