feat: add pi coding agent session monitoring (--agent pi|claude|all)#8
Merged
nahime0 merged 15 commits intoillegalstudio:mainfrom Mar 10, 2026
Merged
feat: add pi coding agent session monitoring (--agent pi|claude|all)#8nahime0 merged 15 commits intoillegalstudio:mainfrom
nahime0 merged 15 commits intoillegalstudio:mainfrom
Conversation
Single-pass parser that reads pi's tree-structured JSONL format and produces claude.Session structs. Handles: - Session header (CWD, version) - Model changes (tracks latest model) - User/assistant message counting - Cost and token accumulation from usage objects - Tool call tracking with name normalization (snake_case → PascalCase) - Status detection (thinking, waiting, executing tool, processing result) - File write tracking (write/edit tools) - Compaction detection - Recent messages and tool calls - Plain string and array content formats 14 tests covering all behaviors.
Scans pi session directories, reuses claude.IsWorktree() for git worktree detection, and decodes pi's directory name encoding as CWD fallback. 6 tests: dir path, name decoding, synthetic discovery, fallback CWD, empty dir, nonexistent dir.
- Added WatchDirs() to SessionProvider interface - PiProvider discovers pi coding agent sessions - MultiProvider merges sessions from multiple providers, gracefully handling individual provider failures - Updated LiveProvider and demo.Provider for new interface 5 tests covering merge, error handling, watcher delegation, directory aggregation, and refresh interval selection.
Refactored NewProjectWatcher to accept variadic directory list. SessionManager.StartWatcher now passes provider.WatchDirs(). Enables watching both ~/.claude/projects/ and ~/.pi/agent/sessions/ simultaneously. 4 tests: multi-dir events, no dirs, nonexistent skipped, all nonexistent.
Added snake_case tool names (bash, read, write, edit, web_search, subagent, lsp, find, process) as fallback mappings in ToolActivity() for pi coding agent. 2 test functions covering all Claude and pi tool names.
Refactored NewModel and api.New to accept SessionProvider instead of demoMode bool. Provider selection now happens in main.go based on --agent flag: - claude: Claude Code only (LiveProvider) - pi: pi coding agent only (PiProvider) - all: both via MultiProvider (default) Updated usage text and tray service to support provider injection.
Added Agent field to Session struct ('claude' or 'pi').
Pi sessions display a π prefix in the session list and
an 'Agent' row in the detail panel for identification
when monitoring multiple agents simultaneously.
Verifies DiscoverSessions against actual ~/.pi/agent/sessions files. Skips gracefully when pi is not installed. Confirms all discovered sessions have Agent='pi' set correctly. Found 867 sessions in 1.36s on test machine.
Added rate estimates for Gemini, GPT-4, GPT-4o, and GPT-5 model families. Pi sessions may use multiple providers, so cost estimation now covers a broader range of models. 6 tests: Claude tiers, relative pricing, Gemini, GPT-4/4o, EffectiveCost direct vs fallback.
Documented --agent flag, multi-agent monitoring, pi session discovery, π prefix indicator, and architecture changes. Added v0.5 roadmap section for multi-agent support.
Pi stores session display names inline in JSONL via /name command. These are now extracted during parsing and auto- populated into the SessionNames system without overwriting user-set names from the TUI rename feature. Added Name field to claude.Session struct. 4 new tests: parse session_info, latest wins, auto-populate on reload, user names preserved.
Move Session, SessionStatus, ToolCall, and ConversationMessage from internal/claude to internal/model so that both claude and pi parsers depend on a neutral package instead of pi importing claude for types.
Member
|
@vdemeester Based on your work, I've updated some logic for the tray and the api components. I've also extracted types into a new package. I've tried some real-world usage with pi (which I wasn't familiar with, thanks for the discovery!) and it works fine. I'll leave the PR in draft. Feel free to mark it as ready for review whenever you're happy with it, and I'll merge it. |
Contributor
Author
|
ah nice, thanks @nahime0 ! I think we can go ahead with it then 👼🏼 |
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.
Summary
Adds support for monitoring pi coding agent sessions alongside Claude Code sessions. Pi sessions are discovered from
~/.pi/agent/sessions/, parsed from their tree-structured JSONL format, and merged into the existing session list.New
--agentflagPi sessions are marked with a π prefix in the session list and show an "Agent" row in the detail panel.
Architecture
The key design decision is reusing
claude.Sessionas the shared session struct. The pi parser reads pi's JSONL and producesclaude.Sessionobjects, so zero changes were needed incore/,ui/,api/, ortray/for session rendering.New package:
internal/pi/types.go— Pi JSONL entry type definitionsjsonl.go— Single-pass parser (pi JSONL →claude.Session)process.go— Session discovery from~/.pi/agent/sessions/Provider pattern
PiProvider— discovers pi sessionsMultiProvider— merges sessions from multiple providers, gracefully handles individual failuresWatchDirs()added toSessionProviderinterface — providers declare which directories to watchOther changes
NewProjectWatcher(dirs...)— refactored to accept variadic directories (was hardcoded to~/.claude/projects/)ToolActivity()— added pi snake_case tool name mappings as safety netEstimateCost()— added Gemini and GPT model family ratesSession.Agentfield — identifies which agent produced each sessionSession.Namefield — pi's/namecommand writessession_infoentries; auto-populated intoSessionNameswithout overwriting user-set namesNewModel()andapi.New()now acceptSessionProviderinstead ofdemoMode boolTesting
49 tests, all passing:
internal/pi/internal/core/internal/api/Integration test discovers 867 real pi sessions in ~1.3s.
Performance note
Discovery reads all JSONL files on each cycle. For 869 pi sessions (130MB) this takes ~1.5s. This is comparable to Claude Code discovery (7s for 1783 files) and is a pre-existing pattern — both could benefit from mtime-based skipping or caching in a future optimization PR.
Files changed
internal/pi/internal/core/andinternal/pi/