# inspect-session

Adopt this skill: https://proskills.md/skills/other/leonis03-pitfall-harness-agent-skills-inspect-session

Page: https://proskills.md/skills/other/leonis03-pitfall-harness-agent-skills-inspect-session
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: agent/skills/inspect-session/SKILL.md
size: 5175
sha: 3849b2484c403bd0b20733c598d38611c7ae6de5
upstream: https://github.com/leonis03/pitfall-harness/blob/main/agent/skills/inspect-session/SKILL.md

````text
---
name: inspect-session
description: Inspect, audit, and analyze coding agent conversation transcripts (Claude Code JSONL, Antigravity/Gemini). Use when the user asks to check what files an agent modified, review Git commits and commands run in a past session, inspect conversation timelines, compare branched DAG forks, search past interactions, or export structured Markdown reports.
---

# Inspect Session

审查、诊断与结构化分析 AI 编程智能体（Claude Code、Antigravity / Gemini CLI）的历史会话记录。

专为回答「**这个会话改了哪些文件？**」、「**对 Git 仓库执行了哪些操作？**」、「**会话分叉后两条路径各自做了什么？**」以及「**将会话导出为整洁的 Markdown 报告**」等场景设计。

---

## 快速使用 (Quick Start)

所有命令均使用系统规范的 Python 运行时执行：

> **路径**：下面的命令统一写 `~/.agents/skills/inspect-session/`。装在别处也能用，换成实际位置即可：`~/.claude/skills/inspect-session/`、`~/.gemini/config/skills/inspect-session/`，或相对本 SKILL.md 的路径，三处有一处存在就行。

```bash
# 1. 会话总览（统计、角色轮次、工具调用分布、分支拓扑）
PYTHONUNBUFFERED=1 uv run --python 3.10 python ~/.agents/skills/inspect-session/scripts/inspect.py <JSONL_PATH>

# 2. 文件变更与 Git 变更审计（核心：回答会话修改了什么）
PYTHONUNBUFFERED=1 uv run --python 3.10 python ~/.agents/skills/inspect-session/scripts/inspect.py <JSONL_PATH> --changes

# 3. 详细 Git 操作审计（查看所有 git commit, push, diff, status）
PYTHONUNBUFFERED=1 uv run --python 3.10 python ~/.agents/skills/inspect-session/scripts/inspect.py <JSONL_PATH> --git

# 4. 对话时间线流（按时间查看用户输入与模型回应）
PYTHONUNBUFFERED=1 uv run --python 3.10 python ~/.agents/skills/inspect-session/scripts/inspect.py <JSONL_PATH> --timeline

# 5. 错误与失败审计（定位所有抛错工具与退出码）
PYTHONUNBUFFERED=1 uv run --python 3.10 python ~/.agents/skills/inspect-session/scripts/inspect.py <JSONL_PATH> --errors

# 6. 会话内关键词搜索
PYTHONUNBUFFERED=1 uv run --python 3.10 python ~/.agents/skills/inspect-session/scripts/inspect.py <JSONL_PATH> --search "关键词"

# 7. 导出结构化 Markdown 审计报告
PYTHONUNBUFFERED=1 uv run --python 3.10 python ~/.agents/skills/inspect-session/scripts/inspect.py <JSONL_PATH> --export-md /path/to/report.md
```

---

## 核心功能与使用场景

### 1. 变更审计 (`--changes` / `--git`)
当用户询问类似「*这个会话对我的项目改了什么？*」、「*刚才 Claude 提交代码了吗？*」时使用：
- **`--changes`**：自动归纳被创建或编辑的文件列表（包含操作行号、修改行数增减对比 `+X/-Y`、执行成功与否），并附带执行的 Git 命令汇总。
- **`--git`**：逐条列出所有 Git 操作（commit 信息、操作意图说明、原始命令、终端输出预览、退出状态）。

### 2. 分支深度感知与分支对比 (`--diff-branches` / `--branch`)
在 Claude Code 会话因 retry 或并发 resume 发生 DAG 分叉（多分支）时：
- **`--diff-branches 1 2`**：精准定位分叉点（Fork Point），并对比分支 1 和分支 2 在分叉之后：
  - 各自执行了哪些独特的工具调用与文件改动
  - 各自进行了哪些独特的用户对话
  - 辅助用户在运行 `trim-branch` 剪枝前，直观确认应该保留哪一条分支。
- **`--branch N`**：约束任何审计视图（`--summary`, `--changes`, `--timeline` 等），仅沿着第 N 条最深分支的血统链（Leaf -> Root）进行回溯分析。

### 3. 会话时间线 (`--timeline`)
按时间先后顺序展示会话演进：
- `--user-only`：只看用户的 Prompt 轨迹。
- `--tools-only`：只看工具执行流水。
- `--full`：展开完整消息文本（不进行 100 字符省略截断）。
- `--limit N`：限制展示条数。

### 4. 故障排查 (`--errors`)
快速过滤出会话中所有失败的操作：
- 失败的 Bash 命令（非零退出码）
- Hook 拦截警告（如 PreToolUse 守卫拦截）
- 文件编辑失败、权限拒绝或找不到目标内容错误

### 5. 格式兼容性
脚本原生自动识别两类格式，无需显式指定参数：
- **Claude Code 格式**：`~/.claude/projects/.../*.jsonl`（包含 `parentUuid` DAG 拓扑、`ai-title`、`tool_use`、`tool_result`）
- **Antigravity / Gemini 格式**：`~/.gemini/antigravity-cli/brain/.../transcript.jsonl`（包含 `step_index`、`PLANNER_RESPONSE`、`run_command` 等）

---

## 与其他会话技能的分工与联动

- **`inspect-session`**（本技能）：**单会话行为审计与内容解析器**。在已知会话文件路径的前提下，完成零依赖的单会话透视（Git 操作账单、文件修改记录、分支差异对比、导出 Markdown）。
- **`trim-branch`**：会话分支裁剪：切除 DAG 拓扑分叉，安全抽取单个分支，并覆写原文件。
- **`cass`**：**全局跨会话搜索引擎**。跨 23+ 种 Agent 检索全局历史、关键词找过去的解决方案。
````

## File: agent/skills/inspect-session/scripts/inspect.py
size: 36421
sha: 5a5a348860ac7cc7d8c56b50dd5e44a03651642a
upstream: https://github.com/leonis03/pitfall-harness/blob/main/agent/skills/inspect-session/scripts/inspect.py

Content is not inlined in the catalog. Read the upstream file: https://github.com/leonis03/pitfall-harness/blob/main/agent/skills/inspect-session/scripts/inspect.py

## File: README.md
upstream: https://github.com/leonis03/pitfall-harness/blob/main/README.md

````text
# pitfall-harness

*English · [中文](README.zh.md)*

Pitfalls met while setting up machines for AI coding agents -- each with its symptom, its root
cause, and how that cause was proven. The configs are the fish; the debugging method is the
rod. It all comes from one person's several machines, driven mainly by Claude Code and the
Antigravity CLI, with networking through a local proxy. The skills are also published on their
own, ready to install: [pitfall-harness-skills](https://github.com/Leonis03/pitfall-harness-skills).

---

## Philosophy: The Agent as System Operator & Closed-Loop Distillation

This project treats the AI agent as a real-world **system operator**. Humans define goals in natural language, prompting the agent to conduct empirical, vibe-driven exploration in live OS and development environments. Once an operational path succeeds, findings are solidified into verifiable, reproducible, and deployable Markdown, configs, scripts, and skills, ensuring future agents never have to re-explore from scratch.

```text
Natural language goal → Agent directly operates live system & executes commands → Observe symptoms → Pinpoint & empirically prove root causes → Working config/procedure → Solidify into configs, scripts, READMEs, skills, & checklists → Future agents reproduce via deterministic knowledge.

One-off Agent Exploration
            ↓
        Experience
            ↓
   Structured Conclusions
      ↙     ↓      ↘
  Config  README   Skill
      ↘     ↓      ↙
  Executable Specifications
            ↓
    Future Agent Reuse
```

### Documentation Audience & Language Conventions

Markdown files in this repository are strictly divided by audience:
- **Agent-Facing**: Written in the format most natural, context-dense, and unambiguous for LLMs -- **English**.
- **Human-Facing**: Chinese versions serve as human reference, produced via **direct translation** sufficient for human comprehension.
- **English First**: When editing or authoring documentation, **always write the agent-facing English version first**, then directly translate it into Chinese. The former "Chinese canonical first" requirement is eliminated.

---

| Environment | Where |
| :--- | :--- |
| Windows 11 + WSL2 (Ubuntu 24.04; Fedora 44 was tried and abandoned) | [`wsl/`](wsl/) · [`windows/`](windows/) |
| Windows 11 + a Linux distribution on the same machine (dual boot) | [`os-install/`](os-install/) |
| Native Linux desktop (Linux Mint 22; Fedora 44 / KDE was tried and abandoned) | [`linux-desktop/`](linux-desktop/) |
| The four-layer bash / zsh config both of the above share | [`shell/`](shell/) |
| Android (Termux root chroot, Honor tablet Linux Lab) | the `android-chroot-debian` and three sibling skills under [`agent/skills/`](agent/skills/) |
| Rented cloud GPUs (DeepLN) | [`agent/skills/deepln-setup/`](agent/skills/deepln-setup/) · [`gpu-cuda-checks/`](agent/skills/gpu-cuda-checks/) |

> **AI agents: read [`AGENTS.md`](AGENTS.md) first** -- the directory map, a "to do X, edit
> these files" table, the files that must change together, and the pre-commit checks.

Two kinds of content live here: **config files you can deploy as-is**, and **conclusions left
behind by debugging** -- the latter is usually worth more than the config itself, because it
records *why* things are the way they are.

> **Fedora 44 was tried and abandoned -- in WSL and on the desktop.** For a while day-to-day WSL
> work moved to a Fedora 44 distro next to **Ubuntu 24.04**, and the desktop's SSD ran Fedora 44
> with KDE Plasma on Wayland. Both were given up in 2026-11; Ubuntu 24.04 is the WSL reference.
> What was measured in the meantime stays as a record: the WSL comparison, split into what is
> avoidable and what is not, in [`wsl/distro-differences.md`](wsl/distro-differences.md), and the
> desktop in [`linux-desktop/fedora/`](linux-desktop/fedora/).
>
> Most references to Ubuntu elsewhere in these docs hold; where they do not, the difference is
> recorded in `wsl/distro-differences.md`.

> Every path, username, machine identifier, port and timestamp is redacted (`$HOME`,
> `<your-linux-user>`, `<your-windows-user>`, `<vm-1>`, `<proxy-port>`, `<ssh-port>`, `<t-created>`), and email
> addresses are written as `your-old-email@example.com`. Substitute your own before
> deploying.
>
> The `<t-...>` tokens under `wsl/storage/forensics/` are **stable** placeholders: the same token means
> the same instant wherever it appears, so timestamp columns can still be compared across
> forensic blocks. Intervals between events are spelled out in prose.

---

## Start here

| What you want | Where |
| :--- | :--- |
| **Rebuild the WSL environment on a new Windows machine** | [`wsl/setup/`](wsl/setup/) -- the rebuild guide; you can hand the whole file to an agent |
| **Configure a freshly installed Windows LTSC machine** | [`windows/setup/`](windows/setup/) -- the same shape, for the Windows side |
| **Install a second OS next to Windows and keep both clocks in agreement** | [`os-install/`](os-install/) -- the contracts that cross the install boundary; today: the RTC/UTC clock contract of a dual boot |
| Rebuild on a native Linux desktop | [`linux-desktop/`](linux-desktop/), with the shell config from [`shell/`](shell/) |
| **Provision a freshly installed Linux machine** | [`linux-bootstrap/`](linux-bootstrap/) -- the machine-agnostic bootstrap script, and the shell histories it was mined from |
| Set up Git and GitHub (including the privacy email) | [`git-github/`](git-github/) |
| Set up Claude Code | [`agent/claude-code/`](agent/claude-code/) |
| Find a ready-made skill, or sync skills to this machine | [`agent/skills/`](agent/skills/) -- deploy with `tools/sync-skills.sh`, not `cp` |
| Look up one specific trap | See the pitfall index below |
| Have an AI agent change something in this repo | [`AGENTS.md`](AGENTS.md) -- the agent-facing entry point |
| Understand the writing and publishing rules here | [`conventions.md`](conventions.md) -- ASCII boundaries, naming, `tmp/`, the pre-publish gate, the two-repo sync |
| Understand the placeholder scheme: no real usernames in the repo, yet everything resolves on deploy | [`redaction.md`](redaction.md) -- the three classes of value and the two pipelines |

---

## Layout

Every top-level directory except `tmp/` and `.github/` has a `README.md` index. Where a directory has a `files/`
subdirectory, `files/` holds the deployable originals and everything else is documentation.

### [`shell/`](shell/) -- four-layer bash / zsh config (shared by WSL and native Linux)

`~/.zshenv` -> `~/.shell_wslfn` -> `~/.shell_common` <- `~/.zshrc` / `~/.bashrc`. The README
explains the split and its three hard rules (the shared file holds only what is valid in both
shells, `conda init` is never shared, functions instead of aliases); the originals are in
`files/`. The WSL-only interop functions skip themselves on native Linux via a `/proc/version`
check.

### [`wsl/`](wsl/) -- WSL2

| Directory | Contents |
| :--- | :--- |
| [`setup/`](wsl/setup/) | **The rebuild guide.** `.wslconfig`, `/etc/wsl.conf`, fstab, the binfmt and `/mnt/wsl` guards, apt mirrors, toolchain. `files/` holds the WSL-only originals |
| [`distro-differences.md`](wsl/distro-differences.md) | How Ubuntu 24.04 and Fedora 44 differ |
| [`gui-ime/`](wsl/gui-ime/) | WSLg GUI apps and the fcitx5 Chinese input method |
| [`uninstall-cleanup.md`](wsl/uninstall-cleanup.md) | Removing one distro or WSL entirely, residue, verification, reinstall |
| [`storage/`](wsl/storage/) | Moving a distro off the system drive, pnpm/npm disk cleanup; `forensics/` holds the raw evidence from one `E_ACCESSDENIED` failure |

The core idea is **`appendWindowsPath=false` plus explicit function bridging**: do not inject
Windows' several hundred PATH entries -- wrap only the handful of `.exe`s you actually need in
shell functions.

### [`windows/`](windows/) -- the Windows side

[`setup/`](windows/setup/) (the LTSC setup runbook; hand the whole file to a
````
