Delete page "Session-Format.-.md"

Virgil 2026-02-19 16:56:49 +00:00
parent d1f15cce3e
commit b1b28f236f

@ -1,151 +0,0 @@
# Session Format
Claude Code writes session transcripts as JSONL (JSON Lines) files, one JSON object per line. Each line is a `rawEntry` containing a type, timestamp, session ID, and a message payload.
## JSONL Line Structure
```json
{
"type": "assistant",
"timestamp": "2026-02-19T10:30:00.123Z",
"sessionId": "abc123de-f456-7890-abcd-ef1234567890",
"message": {
"role": "assistant",
"content": [...]
}
}
```
### Top-Level Fields
| Field | Type | Description |
|-------|------|-------------|
| `type` | string | Entry type: `"assistant"`, `"user"` |
| `timestamp` | string | RFC3339Nano timestamp |
| `sessionId` | string | UUID identifying the conversation |
| `message` | object | Contains `role` and `content` array |
## Event Types
The parser (`ParseTranscript`) converts raw JSONL entries into structured `Event` objects with these types:
### `tool_use`
A tool invocation by the assistant, paired with its result from the user entry. The parser correlates `tool_use` blocks (in assistant messages) with `tool_result` blocks (in user messages) using the `tool_use_id` field.
```go
Event{
Type: "tool_use",
Tool: "Bash", // Tool name
ToolID: "toolu_abc123", // Correlation ID
Input: "git status", // Extracted from tool-specific input
Output: "On branch main", // From tool_result content
Duration: 1200ms, // Time between tool_use and tool_result
Success: true, // Inverse of is_error flag
}
```
### `assistant`
A text response from Claude (non-tool content blocks).
```go
Event{
Type: "assistant",
Input: "I'll help you fix that bug...", // Truncated to 500 chars
}
```
### `user`
A message from the user (text content blocks, not tool results).
```go
Event{
Type: "user",
Input: "Fix the failing test in parser.go", // Truncated to 500 chars
}
```
## Tool-Specific Input Extraction
The `extractToolInput` function parses each tool's JSON input into a human-readable string. This is what populates `Event.Input`:
| Tool | Input Format | Example |
|------|-------------|---------|
| **Bash** | `command` + ` # description` (if present) | `git status # Show working tree status` |
| **Read** | `file_path` | `/src/main.go` |
| **Edit** | `file_path (edit)` | `/src/main.go (edit)` |
| **Write** | `file_path (N bytes)` | `/src/main.go (1024 bytes)` |
| **Grep** | `/pattern/ in path` | `/TODO/ in ./src` |
| **Glob** | `pattern` | `**/*.go` |
| **Task** | `[subagent_type] description` | `[code] Refactor the auth module` |
### Input JSON Shapes
Each tool has a typed input struct for extraction:
```go
// Bash
{"command": "git status", "description": "Show tree status", "timeout": 120000}
// Read
{"file_path": "/src/main.go", "offset": 0, "limit": 2000}
// Edit
{"file_path": "/src/main.go", "old_string": "foo", "new_string": "bar"}
// Write
{"file_path": "/src/main.go", "content": "package main..."}
// Grep
{"pattern": "TODO", "path": "./src"}
// Glob
{"pattern": "**/*.go", "path": "./src"}
// Task (sub-agent)
{"prompt": "...", "description": "Refactor auth", "subagent_type": "code"}
```
For unrecognised tools, the parser falls back to listing the JSON keys alphabetically.
## Content Block Types
Within each message's `content` array, blocks have these types:
| Block Type | Found In | Description |
|-----------|----------|-------------|
| `text` | assistant, user | Plain text message |
| `tool_use` | assistant | Tool invocation with `name`, `id`, and `input` |
| `tool_result` | user | Tool response with `tool_use_id`, `content`, and optional `is_error` |
## Search
The `Search` function scans all `.jsonl` files in a directory and returns matches:
```go
results, err := session.Search("~/.claude/projects/myproject/", "migration")
for _, r := range results {
fmt.Printf("[%s] %s: %s
", r.SessionID[:8], r.Tool, r.Match)
}
```
`SearchResult` contains:
```go
type SearchResult struct {
SessionID string
Timestamp time.Time
Tool string
Match string // The Input (or truncated Output) that matched
}
```
Search is case-insensitive and only matches `tool_use` events, checking both `Input` and `Output` fields.
## Related
- [[Home]] — Package overview and installation
- [[Rendering]] — HTML and MP4 output generation