Skip to content

Repository files navigation

📖 pi-atelier 实战指南 — 从零教会你使用 pi-atelier 扩展生态,包含完整示例和最佳实践。

English | 程序中文文档

pi-session-analyzer

源码仓库 | npm

Session search and analysis for pi — search historical sessions, reconstruct timelines, audit behavior, and generate takeover reports.

Why You Need It

pi generates rich session logs (JSONL), but they're scattered across directories and hard to navigate. When you need to:

  • Find what you did last week
  • Continue work from a previous session
  • Check who modified a file and why
  • Audit an agent session for rule violations

...you'd have to manually dig through JSONL files. pi-session-analyzer gives the AI structured access to every session pi has ever run.

How It Works

┌─── session_search ──────────────────────────────┐
│ │
│ grep ──→ 全文搜索所有会话(支持正则) │
│ file ──→ 查找修改过特定文件的会话 │
│ list ──→ 列出最近 N 个会话 │
│ │
└──────────────────────┬───────────────────────────┘
│
▼ 找到 sessionId
┌─── session_analyze ─────────────────────────────┐
│ │
│ summary ──→ 元信息 + 摘要(首次分析首选) │
│ entries ──→ 条目列表(支持 grep + 分页) │
│ timeline ─→ 时间线(自动标注 [B1][B2] 分支) │
│ chain ────→ 子代理调用链追踪 │
│ audit ────→ 规则违规检查 │
│ digest ───→ user/assistant 对话序列 │
│ branches ─→ 并行分支分析(/tree 产生) │
│ takeover ─→ 5 维接手报告 │
│ raw ──────→ 原始 JSONL 数据 │
│ │
└──────────────────────────────────────────────────┘

Installation

pi install git:github.com/catlain/pi-session-analyzer

Prerequisite: pi must be installed.

Tools

session_search

ParameterTypeRequiredDefaultDescription
action"grep" | "file" | "list"Search mode
querystringgrep/fileKeyword (grep) or file path (file)
limitnumber20Max results
editOnlybooleanfalsegrep mode: only search edit/write operations

Examples:

session_search(action: "grep", query: "roadmap")
session_search(action: "file", query: "src/index.ts")
session_search(action: "list", limit: 10)
session_search(action: "grep", query: "error", editOnly: true)

session_analyze

ParameterTypeRequiredDefaultDescription
sessionIdstringSession ID (supports prefix match)
actionenumSee action table below
limitnumber20Max entries
offsetnumberStart position (0-based, entries mode)
grepstringKeyword filter (entries mode, supports regex)
compactbooleanfalseCompact output (entries mode)
rangestringEntry range, e.g. '5-10' or 'last:5' (entries mode)
indexnumberShow Nth entry with context (entries mode)
rawIndexnumberJump to raw index after filtering (entries mode)
toolNamestringFilter by tool name, supports * wildcard and `
filestringFilter by file path, supports * wildcard and `

Action reference:

ActionOutputBest for
summaryMetadata + abstractFirst look at a session
entriesFiltered entry listFinding specific events
timelineChronological with branch labelsUnderstanding session flow
chainSub-agent call traceDebugging sub-agent workflows
auditRule violationsChecking agent behavior
digestUser/assistant conversationReading what happened
branchesPer-branch analysisAnalyzing /tree forks
takeover5-dimension handoff reportContinuing from a past session
rawRaw JSONL entriesLow-level debugging

Examples:

session_analyze(sessionId: "abc123", action: "summary")
session_analyze(sessionId: "abc123", action: "entries", grep: "error|fail")
session_analyze(sessionId: "abc123", action: "takeover")
session_analyze(sessionId: "abc", action: "entries", range: "last:5")
session_analyze(sessionId: "abc", action: "entries", toolName: "edit|write")
session_analyze(sessionId: "abc", action: "entries", file: "*.test.ts")
session_analyze(sessionId: "abc", action: "entries", offset: 0, limit: 10) # pagination

Storage

Session data is stored in pi's data directory:

DataLocation
Session JSONL files~/.local/share/pi-coding-agent/sessions/
Per-session entries{sessionId}.jsonl
Session ID matchingPrefix match — pass abc to match abc123def...

Use Cases

ScenarioWorkflow
"What did I do last week?"listsummarydigest
"Who changed this file?"file(query: "path/to/file")timeline
"Continue where I left off"takeover → get 5-dimension handoff (intent, files, steps, next steps, decisions)
"Why did this break?"entries(grep: "error")audit
"What did the sub-agent do?"chain → trace sub-agent execution

Best Practices

✅ Recommended

  • Always start with summary — it's fast and gives you the full picture before drilling in
  • Use grep filter in entries mode to find specific events without loading everything
  • Use prefix match for sessionId — no need to type the full ID
  • For large sessions (>100 entries), use offset + limit for pagination instead of loading all at once
  • Use takeover when switching machines or resuming work the next day

❌ Not Recommended

  • Don't use raw for large sessions — use entries with pagination instead
  • Don't confuse session_search actions (grep/file/list) with session_analyze actions — they're different tools
  • Don't skip summary and go straight to raw — you'll waste context on irrelevant data

Limitations

LimitationDetail
Read-onlyCannot modify session data, only analyze it
No real-time streamingAnalyzes completed sessions only
Prefix match ambiguityShort prefixes may match multiple sessions
Audit rules are staticCustom audit rules require code changes

Architecture

pi-session-analyzer/
├── index.ts # Entry: register session_search + session_analyze tools
├── core.ts # Session resolution, JSONL reader, types
├── core-visible.ts # Visible sub-agent file resolution
├── search.ts # list + grep implementation
├── search-file.ts # file search (find sessions editing specific files)
├── search-utils.ts # Shared search helpers
├── analyze.ts # summary/entries/timeline/chain/raw/branches
├── digest.ts # User/assistant conversation extraction
├── audit.ts # Rule violation checker
├── audit-rules.ts # Audit rule definitions
├── audit-types.ts # Audit-specific types
├── takeover.ts # Takeover tool entry point
├── takeover-core.ts # 5-dimension takeover report logic
├── tests/ # Unit tests
└── package.json

Dependencies:

  • @pi-atelier/shared-utils (bundled) — truncatedResult for large outputs
  • @earendil-works/pi-coding-agent — ExtensionAPI (peer)

License

MIT

About

Session search and analysis extension for pi-coding-agent — historical session grep, timeline, audit, and takeover reports

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages