feat: auto-generate session title after the first completed run - #644
Open
looluo wants to merge 4 commits into
Open
feat: auto-generate session title after the first completed run#644looluo wants to merge 4 commits into
looluo wants to merge 4 commits into
Conversation
Wire the existing title generation into the server-side onAgentRunComplete hook: when a regular session's run settles and the session has no name, generate and persist one. Named sessions are never overwritten, so this succeeds at most once per session; failures retry on the next completed run. A globalThis-scoped in-flight guard is shared with the manual /auto-name route to prevent concurrent shadow agents (manual requests now get a clear 409 instead of racing).
Add ~/.pi/agent/pi-web.json (atomic writes, unknown fields preserved) holding autoSessionTitle, defaulting to enabled. A missing file means enabled; a malformed file fail-closes the automatic hook; a wrong-typed field falls back to the default. The setting is read at run-completion time so toggling needs no session reload.
Emit a synthetic session_named event from the wrapper once a title is persisted. useAgentSession handles it during the idle-stream grace window and forwards to AppShell, which refreshes the sidebar and syncs the selected session name without remounting the chat. Pure metadata: the event never touches streaming state.
Expose the autoSessionTitle preference through GET/PUT /api/auto-title-settings (same request guards as the other settings routes) and a ConfigSwitch in the settings panel's general section. The stored file is the single source of truth; no browser-side preference that the server-side hook could not see.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Auto-generate session title after the first completed run
Today session titles are manual-only (top-bar "Generate title" button). This PR adds automatic titling: when a regular session's agent run settles and the session has no name, a title is generated with the session's own model and persisted.
Design
onAgentRunCompletehook inAgentSessionWrapper, so background sessions, closed tabs, and multi-tab setups all behave identically — no browser needs to be watching. Subagent wrappers suppress this callback entirely.lib/session-title.ts(shadow agent, session model, 90s timeout, no tool execution)./auto-nameroute; a manual click during automatic generation gets an explicit 409 instead of racing two shadow agents.session_namedevent is emitted over the existing per-session SSE stream (typically still inside the 30s idle grace window) so open tabs refresh the sidebar immediately.~/.pi/agent/pi-web.json→autoSessionTitle, defaulttrue; atomic writes preserve unknown fields. Missing file = enabled; malformed file fail-closes the hook; the field is read at run-completion time so toggling takes effect without reloading sessions. Toggle lives in Settings → General (GET/PUT /api/sessions/settings).Commits
feat: auto-generate session title after agent run completes— hook + shared guardfeat: gate automatic session titles behind a pi-web setting— config modulefeat: broadcast automatic session titles over the event stream—session_namedSSE eventfeat: add automatic session title toggle to general settings— API route + UITests
Unit tests for the trigger condition (named/dead/disabled/generate-once/retry-after-failure), the lock's exclusivity, the settings module (defaults, fail-close, field-type fallback, unknown-field preservation, round-trips), the settings route validation, and source-inspection assertions for the hook wiring, lock sharing, and event pipeline — matching this repo's existing test conventions.