Pi History Ingest — Session Mining
You are extracting knowledge from the user's Pi coding agent sessions and distilling it into the Obsidian wiki. Pi sessions are stored as structured JSONL with a tree layout — your job is to follow the active branch, extract durable knowledge, and compile it.
This skill can be invoked directly or via the
router (
).
Before You Start
- Resolve config — follow the Config Resolution Protocol in (walk up CWD for → → prompt setup). This gives and (defaults to )
- Read at the vault root to check what has already been ingested
- Read at the vault root to understand what the wiki already contains
Ingest Modes
Append Mode (default)
Check
for each source file. Only process:
- Files not in the manifest (new sessions)
- Files whose modification time is newer than in the manifest
Use this mode for regular syncs.
Full Mode
Process everything regardless of manifest. Use after
or if the user explicitly asks for a full re-ingest.
Pi Data Layout
Pi stores sessions under
(or the path set by
PI_CODING_AGENT_SESSION_DIR
).
~/.pi/agent/sessions/
├── --<cwd-path>--/ # Working directory with / replaced by -
│ └── <timestamp>_<uuid>.jsonl # Session JSONL file
└── ...
The session filename contains an ISO timestamp and UUID. The parent directory encodes the working directory where the session was created.
Session JSONL Format
Each
file is a sequence of JSON objects. The first line is always a
header; subsequent lines are tree entries with
and
.
Key entry types:
| Purpose | Ingest? |
|---|
| Header with , , , | Metadata only |
| Conversation turn (, , , , etc.) | Primary source |
| Display name set via | For session title |
| Context compaction summary | High signal |
| Summary when switching branches via | High signal |
| Model switch event | Skip |
| Thinking level change | Skip |
| Extension state (not in LLM context) | Skip |
| Extension-injected message | Context only |
| User bookmark/label | Skip |
Message roles inside entries
- — user input; is string or
(TextContent \| ImageContent)[]
- — assistant response; is
(TextContent \| ThinkingContent \| ToolCall)[]
- — tool execution result; is
(TextContent \| ImageContent)[]
- — bash command + output; , ,
- — branch switch summary; string
- — compaction summary; string
Key data sources ranked by value
- entries ( + ) — full conversation transcripts; rich but noisy
- entries — pre-synthesized summaries of older context; gold
- entries — summaries of abandoned branches; good signal
- entries — concrete commands run; useful for workflow patterns
- entries — session name for topic inference
Skip
,
,
(extension state), and
entries.
Step 1: Survey and Compute Delta
Scan
and compare against
:
bash
# List all session files
find ~/.pi/agent/sessions -name "*.jsonl" -type f
# Or with custom path
find "$PI_HISTORY_PATH" -name "*.jsonl" -type f
Build an inventory. For each session file, record:
- — absolute path
- — decoded from parent directory name ( → )
- — from the latest entry (if any)
- — file mtime
- — presence in
Classify each file:
- New — not in manifest
- Modified — in manifest but file is newer than
- Unchanged — already ingested and unchanged
Report a concise delta summary before deep parsing:
"Found N Pi sessions across K projects. Delta: X new, Y modified."
Step 2: Parse Session JSONL
For each selected session file, read it line by line. Because sessions use a tree structure, build the active branch first:
- Parse all entries into a map by
- Find the current leaf (the entry with no children, or the last entry)
- Walk chain from leaf to root to get the active path
- Reverse the path so it's chronological
Extraction rules
From the active path, extract:
- header — , , (if forked)
- — field for session title/topic inference
- entries with — extract text (skip images)
- entries with — extract content blocks; skip blocks (noise); note blocks (they reveal what the agent actually did)
- entries with — summarize outcomes, not full output
- entries with — extract command + exit code; recurring commands reveal build/test/deploy workflows
- entries — read verbatim; it's already distilled
- entries — read verbatim; captures abandoned approaches
Skip / noise filters
- content blocks — internal reasoning, not durable knowledge
- Image content blocks — skip unless the user explicitly asks for image transcription
- Raw tool outputs longer than 500 chars — summarize the outcome
- Token accounting ( fields) — metadata only
- Repeated plan echoes or status updates
Critical privacy filter
Session logs can include injected instructions, tool payloads, and sensitive text. Do not ingest verbatim.
- Remove API keys, tokens, passwords, credentials
- Redact private identifiers unless relevant and user-approved
- Summarize bash outputs that contain paths, environment variables, or secrets
- Do not quote raw arguments verbatim if they contain sensitive data
Step 3: Cluster by Topic
Do not create one wiki page per session.
- Group knowledge by stable topic across many sessions
- Split mixed sessions into separate themes
- Merge recurring patterns across dates and projects
- Use the from the session header to infer project scope
- Use as a topic hint when available
Step 4: Distill into Wiki Pages
Route extracted knowledge using existing wiki conventions:
- Project-specific architecture/process →
- General concepts →
- Recurring techniques/debug playbooks →
- Tools/services/frameworks →
- Cross-session patterns →
For each impacted project, create/update
projects/<name>/<name>.md
.
Writing rules
- Distill knowledge, not chronology
- Avoid "on date X we discussed..." unless date context is essential
- Add frontmatter on each new/updated page (1–2 sentences, ≤ 200 chars)
- Add confidence and lifecycle fields to every new page:
yaml
base_confidence: 0.42
lifecycle: draft
lifecycle_changed: <ISO date today>
Leave unchanged on update.
- Add provenance markers:
- when directly grounded in explicit session content (compaction/branch summaries, explicit assistant statements)
- when synthesizing patterns across multiple sessions or inferring from tool calls
- when sessions conflict or a compaction summary contradicts later turns
- Add/update frontmatter mix for each changed page
Mark provenance per the convention in
:
- and entries are pre-distilled — treat as mostly
- Conversation distillation is mostly — you're synthesizing from dialogue
- Use when the user changed their mind across sessions or when compaction summaries disagree with later conversation turns
Step 5: Update Manifest, Log, and Index
Update
For each processed source file:
- , ,
- :
- : inferred project name from decoded
- ,
Add/update a top-level summary block:
json
{
"pi": {
"source_path": "~/.pi/agent/sessions/",
"last_ingested": "TIMESTAMP",
"sessions_ingested": 12,
"sessions_total": 40,
"pages_created": 5,
"pages_updated": 12
}
}
Update special files
- [TIMESTAMP] PI_HISTORY_INGEST sessions=N pages_updated=X pages_created=Y mode=append|full
— Read
$OBSIDIAN_VAULT_PATH/hot.md
(create from the template in
if missing). Update
Recent Activity with a one-line summary — e.g. "Ingested 12 Pi sessions across 3 projects; surfaced patterns in CLI tooling and API design." Keep the last 3 operations. Update
timestamp.
Privacy and Compliance
- Distill and synthesize; avoid raw transcript dumps
- Default to redaction for anything that looks sensitive
- Ask the user before storing personal or sensitive details
- Keep references to other people minimal and purpose-bound
Reference
See
references/pi-data-format.md
for field-level parsing notes and extraction guidance.
QMD Refresh After Vault Writes
QMD is a search index, not the source of truth. If
is empty or unset, skip this step. Run it only after this skill has written or rewritten vault markdown. If QMD refresh fails, do not roll back the vault changes; report the QMD status separately.
Use
if set; otherwise use
.
If the output says vectors are needed or embeddings may be stale, run:
Verify the collection with either:
bash
${QMD_CLI:-qmd} ls "$QMD_WIKI_COLLECTION"
or, when a specific page path is known:
bash
${QMD_CLI:-qmd} get "qmd://$QMD_WIKI_COLLECTION/<page>.md" -l 5
Record one of:
QMD refreshed: update + embed + verified
QMD refreshed: update only + verified
QMD skipped: QMD_WIKI_COLLECTION unset
QMD skipped: qmd CLI unavailable
QMD failed: <short error summary>