session-archaeologist 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,183 +1,232 @@
1
1
  # Session Archaeologist
2
2
 
3
- **从对话回到执行证据。**
3
+ **Let your AI look up what it actually did.**
4
4
 
5
- 中文 | [English](README.en.md)
5
+ [中文](README.zh-CN.md) | English · [npm](https://www.npmjs.com/package/session-archaeologist)
6
6
 
7
- Session Archaeologist 是面向用户与 AI Agent 的本地会话历史查询工具。它读取 **OpenCode、Codex 和 Claude Code** 的原始记录,帮助你找回上下文压缩前仍保存在历史中的命令、工具参数、执行结果和决策背景。
7
+ How did we solve that problem last time? Which command worked? What failed? Where is the tool output from before context compaction?
8
8
 
9
- 先看用户与 Agent 的直接对话,再按需深入某次回复前的工具调用,最后读取单次调用的原始结果。CLI 与 stdio MCP 共用查询核心,Windows 下以单个 Go 二进制运行。
9
+ **Session Archaeologist makes local OpenCode, Codex, and Claude Code histories queryable and traceable.** Inspect them directly in your terminal, or connect through MCP so your working agent can consult earlier sessions as needed.
10
10
 
11
- ## 功能
11
+ ```text
12
+ User–assistant conversation → Calls behind a reply → Original inputs and results
13
+ Understand the work Locate the action Check the evidence
14
+ ```
12
15
 
13
- - **多来源、多会话**:一次选择多个会话,支持混合三种 Agent 的历史。
14
- - **逐层取证**:直接对话 → 回复或用户请求关联的调用 → 原始输入与结果。
15
- - **搜索与定位**:关键词、正则、工具名、路径和状态过滤,以及事件上下文。
16
- - **执行概览**:每轮请求的工具分布、记录中的错误、退出码及结构化文件操作。
17
- - **来源追溯**:保留会话 ID、原始消息及数据库或 JSONL 来源位置。
18
- - **大结果续读**:字符预算、分页和哈希校验续读,按需获取完整原文。
19
- - **MCP 接入**:14 个工具,返回可直接继续调用的 MCP 动作。
20
- - **有界缓存**:精简元数据目录、按需读取正文、容量回收及过期清理。
16
+ Start with a few exchanges and drill down to the commands and results that matter. Long sessions can be read in manageable pieces.
21
17
 
22
- 工具保留原始历史,无需额外数据库、索引服务或模型 API。历史中的命令只作为证据读取。
18
+ ## When would you use it?
23
19
 
24
- ## npm 安装
20
+ - **Resume earlier work:** recover the investigation and implementation process after switching windows, changing agents, or going through context compaction.
21
+ - **Find a working approach:** locate earlier commands, configuration changes, and edits, then check their actual results.
22
+ - **Review failed attempts:** search errors and inspect surrounding events to understand what was tried and where it went wrong.
23
+ - **Connect work across sessions:** investigate several agents' histories together to support work summaries, handoffs, and later decisions with original records.
25
24
 
26
- 从本地打包文件安装(将路径替换为实际文件):
25
+ For example, after connecting MCP, ask your agent:
27
26
 
28
- ```powershell
29
- npm install -g ./dist/session-archaeologist-0.1.0.tgz
27
+ > Review this Codex session. Start with the user–assistant conversation, locate the final approach, and inspect earlier tool calls as needed. List key commands, failed attempts, and validation results, with source references.
28
+
29
+ The tool retrieves records; the agent interprets and summarizes them. The query tool itself needs no model API.
30
+
31
+ ## Why use it?
32
+
33
+ | Feature | What you get |
34
+ | --- | --- |
35
+ | **Conversation first, details on demand** | Understand requirements and conclusions before pulling tool details into context. |
36
+ | **Original evidence** | Check actual arguments, outputs, errors, and exit codes to establish what happened. |
37
+ | **Three providers in one query** | Select OpenCode, Codex, and Claude Code sessions together when work spans several agents. |
38
+ | **Built for agents** | 15 MCP tools with source locations and follow-up actions for continued investigation. |
39
+ | **Local reads, preserved history** | Read original databases or JSONL files without uploading history or deploying an extra service. |
40
+ | **On-demand loading and bounded caching** | Read complete bodies when needed; reclaim metadata caches through capacity limits, expiry, and manual cleanup. |
41
+ | **Ready to run after installation** | The npm package bundles six platform builds; no Go toolchain or original agent CLI is needed. |
42
+
43
+ ## Install with one command
44
+
45
+ Requires **Node.js 20 or later**. Supports **Windows, Linux, and macOS on x64 / arm64**.
46
+
47
+ ```sh
48
+ npm install -g session-archaeologist
30
49
  sa --help
31
- sa conversation "codex resume UUID" "claude --resume UUID"
32
- sa mcp
33
50
  ```
34
51
 
35
- 需要 **Node.js 20 或更新版本**。npm 包内包含 Windows、Linux、macOS 的 x64/arm64 预编译二进制,安装时无需 Go 或额外下载。命令别名为 `sa` 和 `session-archaeologist`。
52
+ `sa` and `session-archaeologist` are two command names for the same tool. Native binaries are included in the package, with no separate binary download during installation.
36
53
 
37
- 维护者生成安装包:
54
+ **New in 0.2.0:** session discovery, MCP registration, diagnostics, and version information. These additions require a 0.2.0 build; the previously published 0.1.0 does not include them. A locally packaged build can be installed with `npm install -g ./dist/session-archaeologist-0.2.0.tgz` before registry publication.
38
55
 
39
- ```powershell
40
- npm run build
41
- npm test
42
- npm pack --pack-destination dist
56
+ Installation makes the commands available. Register MCP explicitly for your client:
57
+
58
+ ```sh
59
+ sa --version
60
+ sa doctor --check-mcp
61
+ sa mcp install --client codex
43
62
  ```
44
63
 
45
- 打包前会自动重新构建六个平台版本,需要 Go 1.25 或更新版本。包内容由 `package.json` 的白名单控制,排除源码、测试、会话历史和本地缓存。当前提供本地 `.tgz` 安装包,npm registry 发布需另行执行。
64
+ Also supported: `--client claude` and `--client opencode`. Installation defaults to user scope; add `--scope project --project PATH` for a project. Use `--dry-run` to preview or `sa mcp uninstall --client codex` to remove the registration. Existing configuration is backed up before changes. Reload your client's MCP connection afterward.
46
65
 
47
- ## 从源码构建独立二进制
66
+ See the [0.2.0 onboarding guide, in Chinese](docs/ONBOARDING.md) for paths, configuration formats and diagnostic behavior. Registry installation alone keeps client configuration unchanged.
48
67
 
49
- 需要 **Go 1.25 或更新版本**。首次构建需要下载依赖。
68
+ ## Try it: inspect an earlier session
50
69
 
51
- ```powershell
52
- $env:CGO_ENABLED = '0'
53
- go build -trimpath -o bin/sa.exe ./cmd/sa
70
+ If you do not remember the session ID, find it first:
71
+
72
+ ```sh
73
+ sa sessions --recent 20
74
+ sa discover --provider codex --project PATH --recent 20
75
+ sa discover --query "regression"
54
76
  ```
55
77
 
56
- 构建后运行仅需 `sa.exe`,无需安装 Go、Node、Python 或对应 Agent CLI。
78
+ Discovery returns recent sessions with project paths, short title previews and ready-to-use read actions. MCP exposes the same operation as `sa_discover`. Title search uses bounded previews; use `search` on selected sessions for full-record searches.
57
79
 
58
- ## 快速开始
80
+ ### 1. Give it your session's resume command
59
81
 
60
- 将示例中的 `SESSION_ID`、`UUID` 和路径替换为实际值。可直接传入熟悉的恢复命令,也可使用 `-s` 选择会话:
82
+ Quote the resume command you already have and pass it as a query argument:
61
83
 
62
- ```powershell
63
- .\bin\sa.exe sessions "opencode -s ses_SESSION_ID" "codex resume UUID" "claude --resume UUID"
64
- .\bin\sa.exe conversation "opencode -s ses_SESSION_ID" "codex resume UUID" "claude --resume UUID" --limit 20
65
- .\bin\sa.exe conversation -s codex:UUID -s claude:UUID
84
+ ```sh
85
+ sa conversation "codex resume UUID"
86
+ sa conversation "claude --resume UUID"
87
+ sa conversation "opencode -s ses_SESSION_ID"
66
88
  ```
67
89
 
68
- 会话按选择顺序展示,重复选择会去重。每项保留所属会话,跨会话关系由使用者依据证据判断。
90
+ Replace `UUID` and `ses_SESSION_ID` with actual session IDs. Resume commands identify the history to read; the tool reads the underlying records directly.
69
91
 
70
- 从对话结果复制回复条目的 `id`,或用户请求的消息 ID,深入工具调用:
92
+ The first view contains direct user–assistant dialogue and compaction markers. Tool output is available for the next step. Results are JSON, suitable for scripts and agents.
71
93
 
72
- ```powershell
73
- .\bin\sa.exe calls -s codex:UUID --reply REPLY_ID
74
- .\bin\sa.exe calls -s codex:UUID --user USER_MESSAGE_ID
75
- .\bin\sa.exe result -s codex:UUID --call CALL_ID --view output
76
- .\bin\sa.exe result -s codex:UUID --call CALL_ID --view raw --budget 0
94
+ ### 2. Find a reply and inspect the calls behind it
95
+
96
+ Copy a reply entry's `id` from the conversation, then a call's `id` from the call list:
97
+
98
+ ```sh
99
+ sa calls -s codex:UUID --reply REPLY_ID
100
+ sa result -s codex:UUID --call CALL_ID --view output
77
101
  ```
78
102
 
79
- `--user` 覆盖整轮请求,包括尚无回复的调用;`calls --all` 查看全部调用。默认调用列表只展示输入预览;`result` 默认读取原始记录,`--view input` 或 `output` 聚焦具体字段。
103
+ Follow a final answer back to the operations and tool results behind it. To inspect an entire user request, use `--user USER_MESSAGE_ID`; `--all` lists every call.
80
104
 
81
- ```powershell
82
- .\bin\sa.exe search -s codex:UUID --in output --query 'error'
83
- .\bin\sa.exe overview -s codex:UUID
84
- .\bin\sa.exe context -s codex:UUID --at CALL_ID --before 3 --after 3
85
- .\bin\sa.exe coverage -s codex:UUID
105
+ ### 3. Search directly or start with an overview
106
+
107
+ ```sh
108
+ sa search -s codex:UUID --in output --query "error"
109
+ sa overview -s codex:UUID
110
+ sa context -s codex:UUID --at CALL_ID --before 3 --after 3
86
111
  ```
87
112
 
88
- ## 导入并复用多个会话
113
+ `overview` shows recorded execution facts for each request. `context` reveals events around a selected call or message.
89
114
 
90
- `import` 解析并校验来源,保存包含会话 ID 和来源路径的 JSON 清单:
115
+ ## Investigate several sessions together
91
116
 
92
- ```powershell
93
- .\bin\sa.exe import "opencode -s ses_SESSION_ID" "codex resume UUID" "claude --resume UUID" --out sessions.json
94
- .\bin\sa.exe conversation --manifest sessions.json
95
- .\bin\sa.exe search --manifest sessions.json --in output --query 'error'
117
+ Mix several providers in one query. These three resume commands select three histories:
118
+
119
+ ```sh
120
+ sa conversation "opencode -s ses_SESSION_ID" "codex resume UUID" "claude --resume UUID"
96
121
  ```
97
122
 
98
- 也可直接选择原生 JSONL 文件:
123
+ Save a frequently used selection as a manifest:
99
124
 
100
- ```powershell
101
- .\bin\sa.exe import --source 'D:\histories\codex.jsonl' --source 'D:\histories\claude.jsonl' --out sessions.json
125
+ ```sh
126
+ sa import "codex resume UUID" "claude --resume UUID" --out sessions.json
127
+ sa conversation --manifest sessions.json
128
+ sa search --manifest sessions.json --in output --query "error"
102
129
  ```
103
130
 
104
- 清单保存引用,原始历史继续留在原处。`--manifest` 和 `--source` 均可重复传入。
131
+ Manifests store session and source-path references; original history stays in place. You can also select native Codex / Claude Code JSONL files with `--source PATH`.
132
+
133
+ ## Let your agent investigate: MCP setup
105
134
 
106
- ## 接入 MCP
135
+ After global npm installation, add a **stdio** service through your client's MCP configuration. These examples use the `mcpServers` JSON structure; configuration locations and formats depend on the client.
107
136
 
108
- 在支持 stdio MCP 的客户端中添加配置,将二进制路径替换为实际路径:
137
+ **Windows:**
109
138
 
110
139
  ```json
111
140
  {
112
141
  "mcpServers": {
113
142
  "session-archaeologist": {
114
- "command": "D:\\tools\\sa.exe",
115
- "args": ["mcp"]
143
+ "command": "cmd",
144
+ "args": ["/c", "sa", "mcp"]
116
145
  }
117
146
  }
118
147
  }
119
148
  ```
120
149
 
121
- 如需预选会话,将 args 设为 `["mcp", "--manifest", "D:\\histories\\sessions.json"]`。Agent 也可在工具参数的 `sessions` 数组中传入多个完整恢复命令或会话标识。
150
+ **Linux / macOS:**
122
151
 
123
- 推荐调用顺序:`sa_sessions` → `sa_conversation` → `sa_calls` → `sa_result`。续读动作包含 `tool` 与 `arguments`,可直接继续调用。每次调用使用显式选择或服务启动时的默认选择。
152
+ ```json
153
+ {
154
+ "mcpServers": {
155
+ "session-archaeologist": {
156
+ "command": "sa",
157
+ "args": ["mcp"]
158
+ }
159
+ }
160
+ }
161
+ ```
124
162
 
125
- 详见 [MCP 接入说明](docs/MCP.md) 和 [客户端配置模板](examples/mcp-config.json)。
163
+ The client process must have Node and global npm commands on its PATH. For a standalone binary, configure its absolute path directly with args `["mcp"]`.
126
164
 
127
- 通过 npm 全局安装后,可使用 [npm MCP 配置](examples/mcp-config.npm.json)。Windows 客户端若需通过命令解释器启动 npm shim,使用 [Windows npm MCP 配置](examples/mcp-config.npm.windows.json):`cmd /c sa mcp`。MCP 客户端需能在 PATH 中找到 Node 和全局 npm 命令。
165
+ Reload the client's MCP connection, then ask the agent to call `sa_sessions` or `sa_conversation` with the sessions to investigate. For example, arguments to `sa_conversation`:
128
166
 
129
- ## 命令与工具
167
+ ```json
168
+ {
169
+ "sessions": ["codex resume UUID", "claude --resume UUID"],
170
+ "limit": 20
171
+ }
172
+ ```
130
173
 
131
- | CLI | MCP | 用途 |
132
- | --- | --- | --- |
133
- | `sessions` | `sa_sessions` | 会话信息、记录数量与未归属调用 |
134
- | `conversation` | `sa_conversation` | 直接对话及压缩标记 |
135
- | `calls` | `sa_calls` | 按回复、用户请求或全部范围查看调用 |
136
- | `result` | `sa_result` | 原始工具调用及关联结果 |
137
- | `message` | `sa_message` | 原始消息记录 |
138
- | `search` | `sa_search` | 消息与工具输入、输出搜索 |
139
- | `overview` | `sa_overview` | 每轮请求的执行事实概览 |
140
- | `context` | `sa_context` | 锚点前后的事件 |
141
- | `coverage` | `sa_coverage` | 来源边界、压缩及相关资源 |
142
- | `files` | `sa_files` | 结构化记录中的文件操作 |
143
- | `import` | `sa_import` | 校验来源并返回清单;CLI 支持 `--out` 保存 |
144
- | `cache status/prune/clear` | `sa_cache_status/prune/clear` | 缓存检查、回收与清空 |
145
-
146
- ## 来源与覆盖范围
147
-
148
- | 来源 | 默认位置 | 覆盖参数 |
149
- | --- | --- | --- |
150
- | OpenCode | `%USERPROFILE%\.local\share\opencode\opencode.db`,支持 `XDG_DATA_HOME` | `--db PATH` |
151
- | Codex | `CODEX_HOME` 或 `%USERPROFILE%\.codex` 下的 `sessions`、`archived_sessions` | `--codex-home PATH` |
152
- | Claude Code | `CLAUDE_CONFIG_DIR` 或 `%USERPROFILE%\.claude` 下的 `projects` | `--claude-home PATH` |
174
+ The agent can follow `sa_conversation` → `sa_calls` → `sa_result`, or use search, surrounding events, and coverage reports. Results include follow-up `tool` and `arguments` values for continued reads.
153
175
 
154
- OpenCode 当前支持 `session_v2`、`session_message` 和 `session_part` 格式;Codex 与 Claude Code 读取原生 JSONL。通过 `--source` 指定文件,或通过 `--source-map provider:UUID=PATH` 覆盖已选来源的路径。
176
+ To preselect an investigation scope, start with `mcp --manifest PATH`. See the [MCP guide, in Chinese](docs/MCP.md), plus configuration examples for [Windows npm](examples/mcp-config.npm.windows.json), [Linux/macOS npm](examples/mcp-config.npm.json), and a [standalone binary](examples/mcp-config.json).
155
177
 
156
- 结果以原始记录保留的证据为准:已有截断、缺失和压缩边界会保留或在覆盖报告中说明。Claude Code 子 Agent sidecar 当前列入覆盖清单,尚待自动展开。文件操作提取基于结构化工具参数;任意 shell 脚本的实际文件变更仍需核对结果。
178
+ ## Long records, original content, and caching
157
179
 
158
- ## 输出与缓存
180
+ Default responses contain up to **16000 JSON characters**, with up to **50 items** per list page. Follow returned actions for more content; continuation hashes detect changes to the evidence. When you need a complete response in one read:
159
181
 
160
- 数据输出为 JSON,当前 `schema_version` 为 `0.2`。默认每次最多返回 **16000 个 JSON 字符**、列表最多 **50 项**。`--budget 0` 请求无限预算,`--limit 0` 在预算内尽量返回全部条目。后续内容使用返回的续读动作读取;哈希变化时重新开始读取。
182
+ ```sh
183
+ sa result -s codex:UUID --call CALL_ID --view raw --budget 0
184
+ ```
161
185
 
162
- 缓存保存精简元数据目录,完整工具正文按需从来源读取。默认限制:磁盘 **128 MiB**、内存编码目录 **16 MiB**、单条解码 **8 MiB**、最多 **256 条**、闲置 **7 天**过期。这些是缓存上限,查询和解析仍有临时内存开销。
186
+ Complete reads are limited to what the original history retained. Existing truncation, missing records, and compaction boundaries are preserved or described in `coverage`. Claude Code subagent sidecars are currently listed in coverage and await automatic expansion.
163
187
 
164
- ```powershell
165
- .\bin\sa.exe cache status
166
- .\bin\sa.exe cache prune
167
- .\bin\sa.exe cache clear
168
- .\bin\sa.exe conversation -s codex:UUID --cache off --profile
188
+ The cache stores compact metadata catalogues. Defaults are **128 MiB** of disk cache, **16 MiB** of encoded in-memory catalogues, **256 entries**, and **7 days** of idle expiry. Parsing and query results require additional temporary memory.
189
+
190
+ ```sh
191
+ sa cache status
192
+ sa cache prune
193
+ sa cache clear
169
194
  ```
170
195
 
171
- 清理仅处理本工具管理的缓存文件。MCP 长期运行时复用有界缓存,并串行执行查询与清理以控制峰值内存。
196
+ Cleanup affects only cache files managed by this tool. Use `--cache off` to disable query caching and `--profile` for loading diagnostics.
172
197
 
173
- ## 文档与验证
198
+ ## Find the command you need
174
199
 
175
- - [代码目录与开发说明](docs/DEVELOPMENT.md)
176
- - [CLI 参数、用法与当前边界](docs/CLI.md)
177
- - [MCP 接入与调用约定](docs/MCP.md)
178
- - [MCP 客户端配置模板](examples/mcp-config.json)
200
+ | I want to… | CLI command | MCP tool |
201
+ | --- | --- | --- |
202
+ | Find sessions without knowing their IDs | `discover` | `sa_discover` |
203
+ | Confirm which sessions are selected | `sessions` | `sa_sessions` |
204
+ | Read the user–assistant conversation | `conversation` | `sa_conversation` |
205
+ | Inspect actions behind a reply | `calls` | `sa_calls` |
206
+ | Check an original tool result | `result` | `sa_result` |
207
+ | Read an original message | `message` | `sa_message` |
208
+ | Search commands, errors, or outputs | `search` | `sa_search` |
209
+ | Get an overview of a request | `overview` | `sa_overview` |
210
+ | See events around an anchor | `context` | `sa_context` |
211
+ | Check coverage and missing sources | `coverage` | `sa_coverage` |
212
+ | Inspect structured file operations | `files` | `sa_files` |
213
+ | Reuse a selection of sessions | `import` | `sa_import` |
214
+ | Inspect or clean the cache | `cache status/prune/clear` | `sa_cache_status/prune/clear` |
215
+
216
+ ## Documentation and development
217
+
218
+ - [0.2.0 onboarding, MCP registration and diagnostics — Chinese](docs/ONBOARDING.md)
219
+ - [Full CLI options, source locations, and compatibility — Chinese](docs/CLI.md)
220
+ - [MCP setup and calling conventions — Chinese](docs/MCP.md)
221
+ - [Source layout, builds, and development](docs/DEVELOPMENT.md)
222
+
223
+ Source builds require **Go 1.25+**. For example, in Windows PowerShell:
179
224
 
180
225
  ```powershell
226
+ $env:CGO_ENABLED = '0'
227
+ go build -trimpath -o bin/sa.exe ./cmd/sa
181
228
  go test ./...
182
229
  go vet ./...
183
230
  ```
231
+
232
+ Standalone binaries run without Node. Maintainers can build and validate the npm package with `npm run build`, `npm test`, and `npm pack --pack-destination dist`.
@@ -0,0 +1,232 @@
1
+ # Session Archaeologist
2
+
3
+ **让 AI 查回它做过的事。**
4
+
5
+ 中文 | [English](README.md) · [npm](https://www.npmjs.com/package/session-archaeologist)
6
+
7
+ 上次那个问题是怎么解决的?运行过什么命令?哪次尝试失败了?上下文压缩后,关键工具输出还在哪里?
8
+
9
+ **Session Archaeologist 把 OpenCode、Codex 和 Claude Code 的本地会话历史,变成可查询、可追溯的执行记录。** 你可以在终端直接查,也可以通过 MCP,让正在工作的 Agent 按需查阅旧会话。
10
+
11
+ ```text
12
+ 用户与 Agent 的对话 → 某次回复前的工具调用 → 原始参数与结果
13
+ 先了解经过 再定位操作 最后核对证据
14
+ ```
15
+
16
+ 从几句对话开始,逐层找到真正需要的命令和结果。长会话也可以分段读取。
17
+
18
+ ## 什么时候用它?
19
+
20
+ - **接着做之前的工作**:换了窗口、换了 Agent,或经历多轮上下文压缩后,查回先前的调查与实现过程。
21
+ - **找回有效做法**:定位曾经成功的命令、配置和修改步骤,核对当时实际返回的结果。
22
+ - **复盘失败尝试**:搜索报错,查看前后事件,了解试过哪些方法、哪里出了问题。
23
+ - **跨会话整理经验**:同时读取多个 Agent 的会话,为工作总结、交接说明和后续决策提供原始依据。
24
+
25
+ 例如,接入 MCP 后,你可以让 Agent:
26
+
27
+ > 帮我回顾这个 Codex 会话。先看用户和助手的对话,找到最终方案,再按需查看之前的工具调用。列出关键命令、失败尝试和验证结果,并附上来源。
28
+
29
+ 工具负责取回记录,Agent 负责理解和总结;查询工具本身无需模型 API。
30
+
31
+ ## 它有什么优势?
32
+
33
+ | 特点 | 对你有什么用 |
34
+ | --- | --- |
35
+ | **先对话,再深入** | 先理解需求与结论,感兴趣时再看工具细节,减少无关日志进入上下文。 |
36
+ | **回到原始证据** | 查看实际参数、输出、错误和退出码,核对当时到底发生了什么。 |
37
+ | **三种来源一起查** | OpenCode、Codex、Claude Code 会话可混合选择,方便复盘分散在不同 Agent 中的工作。 |
38
+ | **适合 Agent 使用** | 15 个 MCP 工具,带来源定位与后续读取动作,方便持续追查。 |
39
+ | **本地读取,保留历史** | 无需上传历史或部署额外服务;工具直接读取原始数据库或 JSONL。 |
40
+ | **按需加载,有界缓存** | 完整正文需要时才读,元数据缓存支持容量回收、过期及手动清理。 |
41
+ | **安装即可运行** | npm 包内附带六个平台版本,无需安装 Go 或对应的 Agent CLI。 |
42
+
43
+ ## 安装:一条命令
44
+
45
+ 需要 **Node.js 20 或更新版本**,支持 **Windows、Linux、macOS 的 x64 / arm64**。
46
+
47
+ ```sh
48
+ npm install -g session-archaeologist
49
+ sa --help
50
+ ```
51
+
52
+ `sa` 和 `session-archaeologist` 是同一个工具的两个命令名称。安装时直接使用包内的预编译程序,无需额外下载原生二进制。
53
+
54
+ **0.2.0 新增:** 会话发现、MCP 注册、环境诊断和版本信息。这些功能需要 0.2.0 构建;此前发布的 0.1.0 尚未包含。正式发布前,可用 `npm install -g ./dist/session-archaeologist-0.2.0.tgz` 安装本地打包版本。
55
+
56
+ 安装后,用命令显式注册到目标 MCP 客户端:
57
+
58
+ ```sh
59
+ sa --version
60
+ sa doctor --check-mcp
61
+ sa mcp install --client codex
62
+ ```
63
+
64
+ 也支持 `--client claude` 和 `--client opencode`。默认安装到用户作用域;项目级使用 `--scope project --project PATH`。`--dry-run` 可预览修改,`sa mcp uninstall --client codex` 可卸载注册。修改前会备份已有配置,完成后重新加载客户端 MCP 连接。
65
+
66
+ 配置位置、格式与诊断行为详见 [0.2.0 上手说明](docs/ONBOARDING.md)。单独执行 npm 安装保持客户端配置原样。
67
+
68
+ ## 先用一次:查看一个旧会话
69
+
70
+ 不记得 session ID?先查最近会话:
71
+
72
+ ```sh
73
+ sa sessions --recent 20
74
+ sa discover --provider codex --project PATH --recent 20
75
+ sa discover --query "regression"
76
+ ```
77
+
78
+ 发现结果包含项目路径、短标题预览及可直接使用的读取动作,MCP 对应 `sa_discover`。标题查询基于有限预览;选定会话后,可用 `search` 搜索完整记录。
79
+
80
+ ### 1. 把恢复会话的命令交给它
81
+
82
+ 将你已有的恢复命令放在引号中,作为查询参数:
83
+
84
+ ```sh
85
+ sa conversation "codex resume UUID"
86
+ sa conversation "claude --resume UUID"
87
+ sa conversation "opencode -s ses_SESSION_ID"
88
+ ```
89
+
90
+ 把 `UUID`、`ses_SESSION_ID` 替换成真实会话 ID。恢复命令在这里用于定位历史,工具直接读取对应记录。
91
+
92
+ 默认先展示用户与 Agent 的直接对话及压缩标记,工具输出留待下一步查看。结果为 JSON,适合脚本和 Agent 使用。
93
+
94
+ ### 2. 找到感兴趣的回复,查看之前的调用
95
+
96
+ 从对话中复制回复条目的 `id`,再从调用列表中复制调用的 `id`:
97
+
98
+ ```sh
99
+ sa calls -s codex:UUID --reply REPLY_ID
100
+ sa result -s codex:UUID --call CALL_ID --view output
101
+ ```
102
+
103
+ 这样就能从“Agent 最后说了什么”,追到“它做过哪些操作、工具返回了什么”。如果想查看整个用户请求期间的调用,使用 `--user USER_MESSAGE_ID`;`--all` 可查看全部调用。
104
+
105
+ ### 3. 直接搜索,或先看执行概览
106
+
107
+ ```sh
108
+ sa search -s codex:UUID --in output --query "error"
109
+ sa overview -s codex:UUID
110
+ sa context -s codex:UUID --at CALL_ID --before 3 --after 3
111
+ ```
112
+
113
+ `overview` 展示各轮请求的执行概况;`context` 帮你查看某次调用或消息前后的事件。
114
+
115
+ ## 多个会话,一起查
116
+
117
+ 同一次查询可以混合多个来源。下面三条恢复命令会被选入同一查询:
118
+
119
+ ```sh
120
+ sa conversation "opencode -s ses_SESSION_ID" "codex resume UUID" "claude --resume UUID"
121
+ ```
122
+
123
+ 经常使用同一组会话,可以保存为清单:
124
+
125
+ ```sh
126
+ sa import "codex resume UUID" "claude --resume UUID" --out sessions.json
127
+ sa conversation --manifest sessions.json
128
+ sa search --manifest sessions.json --in output --query "error"
129
+ ```
130
+
131
+ 清单保存会话和来源路径的引用,原始历史继续留在原处。也支持用 `--source PATH` 直接选择 Codex / Claude Code 的 JSONL 文件。
132
+
133
+ ## 让 Agent 自己查:接入 MCP
134
+
135
+ 完成 npm 全局安装后,在客户端的 MCP 配置入口添加一个 **stdio** 服务。以下为采用 `mcpServers` JSON 结构的客户端示例;具体配置文件和格式由客户端决定。
136
+
137
+ **Windows:**
138
+
139
+ ```json
140
+ {
141
+ "mcpServers": {
142
+ "session-archaeologist": {
143
+ "command": "cmd",
144
+ "args": ["/c", "sa", "mcp"]
145
+ }
146
+ }
147
+ }
148
+ ```
149
+
150
+ **Linux / macOS:**
151
+
152
+ ```json
153
+ {
154
+ "mcpServers": {
155
+ "session-archaeologist": {
156
+ "command": "sa",
157
+ "args": ["mcp"]
158
+ }
159
+ }
160
+ }
161
+ ```
162
+
163
+ 客户端进程的 PATH 需要包含 Node 和全局 npm 命令。若使用独立二进制,则直接配置程序的绝对路径,args 为 `["mcp"]`。
164
+
165
+ 重新加载客户端的 MCP 服务后,让 Agent 调用 `sa_sessions` 或 `sa_conversation`,并传入你要调查的会话。例如,`sa_conversation` 的参数:
166
+
167
+ ```json
168
+ {
169
+ "sessions": ["codex resume UUID", "claude --resume UUID"],
170
+ "limit": 20
171
+ }
172
+ ```
173
+
174
+ Agent 可以按 `sa_conversation` → `sa_calls` → `sa_result` 逐层读取,也可以使用搜索、事件上下文和覆盖报告。结果中会提供下一步可调用的 `tool` 与 `arguments`。
175
+
176
+ 想固定调查范围,可将启动参数改为 `mcp --manifest PATH`。完整说明见 [MCP 文档](docs/MCP.md),另提供 [Windows npm 配置](examples/mcp-config.npm.windows.json)、[Linux/macOS npm 配置](examples/mcp-config.npm.json) 和 [独立二进制配置](examples/mcp-config.json)。
177
+
178
+ ## 长记录、原文与缓存
179
+
180
+ 默认每次返回最多 **16000 个 JSON 字符**、列表最多 **50 项**。更多内容通过结果中的续读动作获取,续读时使用哈希校验检测证据是否变化。确实需要一次完整返回时:
181
+
182
+ ```sh
183
+ sa result -s codex:UUID --call CALL_ID --view raw --budget 0
184
+ ```
185
+
186
+ 完整读取仍以原始历史实际保存的内容为准。源记录中已有的截断、缺失和压缩边界会保留或在 `coverage` 中说明。Claude Code 子 Agent sidecar 当前列入覆盖清单,尚待自动展开。
187
+
188
+ 缓存只保存精简元数据目录。默认磁盘上限 **128 MiB**、内存编码目录上限 **16 MiB**,最多 **256 条**、闲置 **7 天**过期;解析与查询结果另有临时内存开销。
189
+
190
+ ```sh
191
+ sa cache status
192
+ sa cache prune
193
+ sa cache clear
194
+ ```
195
+
196
+ 清理仅处理本工具管理的缓存文件。`--cache off` 可禁用查询缓存,`--profile` 可查看加载诊断。
197
+
198
+ ## 按需求查命令
199
+
200
+ | 我想…… | CLI 命令 | MCP 工具 |
201
+ | --- | --- | --- |
202
+ | 不知道 ID,先找会话 | `discover` | `sa_discover` |
203
+ | 确认选中了哪些会话 | `sessions` | `sa_sessions` |
204
+ | 看用户与 Agent 的对话 | `conversation` | `sa_conversation` |
205
+ | 看回复背后的操作 | `calls` | `sa_calls` |
206
+ | 核对工具的原始结果 | `result` | `sa_result` |
207
+ | 读取原始消息 | `message` | `sa_message` |
208
+ | 搜索命令、报错或输出 | `search` | `sa_search` |
209
+ | 快速了解一轮工作 | `overview` | `sa_overview` |
210
+ | 看某条事件的前后经过 | `context` | `sa_context` |
211
+ | 检查记录范围和缺失来源 | `coverage` | `sa_coverage` |
212
+ | 查看结构化文件操作 | `files` | `sa_files` |
213
+ | 复用一组会话 | `import` | `sa_import` |
214
+ | 检查或清理缓存 | `cache status/prune/clear` | `sa_cache_status/prune/clear` |
215
+
216
+ ## 文档与开发
217
+
218
+ - [0.2.0 上手、MCP 注册与环境诊断](docs/ONBOARDING.md)
219
+ - [CLI 详细参数、来源位置和兼容范围](docs/CLI.md)
220
+ - [MCP 接入与调用约定](docs/MCP.md)
221
+ - [代码目录、构建与开发说明](docs/DEVELOPMENT.md)
222
+
223
+ 源码构建需要 **Go 1.25+**;以 Windows PowerShell 为例:
224
+
225
+ ```powershell
226
+ $env:CGO_ENABLED = '0'
227
+ go build -trimpath -o bin/sa.exe ./cmd/sa
228
+ go test ./...
229
+ go vet ./...
230
+ ```
231
+
232
+ 独立二进制运行时无需 Node。维护者可用 `npm run build`、`npm test` 和 `npm pack --pack-destination dist` 构建并验证 npm 包。
package/docs/CLI.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # CLI 使用说明(输出协议 0.2)
2
2
 
3
+ 0.2.0 新增 `--version`、`doctor [--check-mcp]`、`discover`、不带 ID 的 `sessions` 发现,以及 `mcp install/uninstall --client codex|claude|opencode`。使用与配置位置见 [上手说明](ONBOARDING.md)。版本号和输出 schema 独立:二进制版本为发布版本或 `dev`,输出 schema 仍为 `0.2`。
4
+
3
5
  Windows / Go / 单二进制,读取本机 OpenCode、Codex 和 Claude Code 原始历史。OpenCode 支持 `session_v2`、`session_message` 以及 `session_part` 中的 assistant parts;旧版 `session` / `message` / `part` 格式尚未支持。Codex 和 Claude Code 读取原生 JSONL 文件,无需安装或启动对应 CLI。通过 `sa mcp` 启动 stdio MCP,详见 [MCP 接入](MCP.md)。
4
6
 
5
7
  推荐调查顺序:`conversation` 找请求和回复 → `overview` 看执行概览 → `search` 定位证据 → 按返回的 `read` / `context` 参数深入 → `coverage` 核对尚未展开的来源。所有数据响应带 `schema_version: "0.2"`、字符预算和必要的续读参数。
@@ -5,6 +5,10 @@ cmd/sa/ Executable entry, process signals, exit diagnostics
5
5
  internal/app/ CLI and MCP adapters, shared query execution
6
6
  app.go Public application entry
7
7
  cli_options.go CLI parsing and option validation
8
+ discover.go Session discovery responses and follow-up actions
9
+ doctor.go Read-only diagnostics and optional stdio self-test
10
+ mcp_config.go Client configuration registration, backup and removal
11
+ version.go Build version, independent from response schema
8
12
  cli_sources.go Source selection, manifest import and saving
9
13
  cli_cache.go Cache configuration, management and profiling
10
14
  query.go Request execution and source snapshot lifetime
@@ -60,3 +64,10 @@ Provider-specific parsing belongs in `internal/history`; cache ownership and
60
64
  eviction belong in `internal/cache`. Application code assembles query results and
61
65
  transport-specific continuation actions. Original source records remain the
62
66
  authority for evidence bodies.
67
+
68
+ Release builds inject `package.json`'s version into `internal/app.Version` using
69
+ Go linker flags. Direct source builds default to `dev`; the MCP implementation
70
+ version uses the same value, while `schema_version` stays independent. Client
71
+ configuration editing is tested against temporary fixtures rather than the
72
+ developer's actual configurations. See [onboarding](ONBOARDING.md) for supported
73
+ client formats, scope locations, and discovery preview limits.
package/docs/MCP.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # MCP 接入
2
2
 
3
+ 0.2.0 提供 `sa mcp install --client codex|claude|opencode`、项目/用户作用域、dry-run、备份与卸载,以及 `sa doctor --check-mcp`。详见 [上手说明](ONBOARDING.md)。新增的 `sa_discover` 可在不知道会话 ID 时查找会话;当前共 15 个工具。`sa mcp` 本身继续启动 stdio 服务。
4
+
3
5
  `sa.exe mcp` 启动 stdio MCP 服务。标准输出仅用于协议,诊断输出到标准错误。客户端退出或关闭输入后服务结束。使用官方 Go MCP SDK 处理协议协商、取消和连接生命周期。
4
6
 
5
7
  通用客户端配置(替换二进制路径):
@@ -0,0 +1,80 @@
1
+ # 0.2.0:安装、找会话与诊断
2
+
3
+ 本页对应当前源码及本地构建的 0.2.0。发布到 npm 前,registry 上的 0.1.0 保持原有功能。先用 `sa --version` 确认实际运行版本;源码直接构建时显示 `dev`,npm 发布构建会注入 package.json 中的版本。
4
+
5
+ ## 一键注册 MCP
6
+
7
+ ```sh
8
+ sa mcp install --client codex
9
+ sa mcp install --client claude
10
+ sa mcp install --client opencode
11
+ ```
12
+
13
+ 默认修改用户级配置。项目级配置可使用:
14
+
15
+ ```sh
16
+ sa mcp install --client codex --scope project --project PATH
17
+ sa mcp install --client claude --scope project --project PATH
18
+ sa mcp install --client opencode --scope project --project PATH
19
+ ```
20
+
21
+ | 客户端 | 用户级位置 | 项目级位置 |
22
+ | --- | --- | --- |
23
+ | Codex | `CODEX_HOME/config.toml`,默认 `~/.codex/config.toml` | `.codex/config.toml` |
24
+ | Claude Code | `~/.claude.json`;设置 `CLAUDE_CONFIG_DIR` 时使用该目录内 `.claude.json` | `.mcp.json` |
25
+ | OpenCode | `XDG_CONFIG_HOME/opencode/opencode.jsonc`,默认 `~/.config/opencode/`;优先已有 jsonc/json 文件 | `opencode.jsonc` 或已有 `opencode.json` |
26
+
27
+ `--config PATH` 可显式指定目标文件。安装程序直接注册当前运行的原生二进制绝对路径;通过 npm 安装时就是包内对应平台的二进制。升级或移动安装位置后,可重复执行 install 刷新路径。
28
+
29
+ ```sh
30
+ sa mcp install --client codex --dry-run
31
+ sa mcp uninstall --client codex
32
+ ```
33
+
34
+ dry-run 返回目标、启动命令和是否变化,保持配置及目录原样。实际修改前生成 `.sa-backup-时间戳` 备份,只增加或移除本工具的服务项。重复安装相同内容或重复卸载会返回 `changed:false`。已有配置语法错误时先修复语法。备份可能包含原配置中的凭据,文件按私有权限创建。
35
+
36
+ JSONC 编辑保留其他字段和注释;TOML 编辑保留其他表与文本。本工具已有注册项中的额外参数如 env 会保留。内联或根部 dotted TOML 服务配置需要先转换成标准 `[mcp_servers.session-archaeologist]` 表。
37
+
38
+ OpenCode 的 `--opencode-format auto` 保留已有 MCP 形状;新配置默认使用当前官方 `mcp.servers` 结构。旧版本可显式使用 `--opencode-format v1`,生成 `mcp.<name>` 与 `enabled:true`;`v2` 使用 `mcp.servers.<name>`。若手动切换格式,先按原格式卸载,再按新格式安装。
39
+
40
+ 配置完成后,重新加载客户端的 MCP 连接。客户端自身的项目可信与 MCP 审批规则仍适用;注册配置和客户端已加载该配置是两个独立状态。
41
+
42
+ ## 不记得 session ID?先找
43
+
44
+ ```sh
45
+ sa sessions --recent 20
46
+ sa discover --provider codex --project PATH --recent 20
47
+ sa discover --query "regression"
48
+ ```
49
+
50
+ `sessions` 不传 ID 时进入发现模式;传入 ID 时保留原有详情查询。`discover` 明确执行发现。结果按修改时间倒序排列,包含 provider、session_id、项目路径、短标题及可执行的 read 动作。
51
+
52
+ `--project` 匹配指定目录及其子目录。`--query` 对标题预览和 ID 做大小写不敏感匹配;原生 JSONL 的预览最多来自开头 64 KiB,这不是完整历史全文检索。需要全文时,在选定会话后使用 `search`。
53
+
54
+ 每个 read 动作携带选定的原始来源路径,可以直接用于后续 conversation 查询。来源缺失或格式异常以 warnings 说明;空列表也可能表示筛选条件没有匹配项。子 Agent sidecar 不混入顶层会话列表。
55
+
56
+ MCP 对应工具为 `sa_discover`;`sa_sessions` 在没有任何显式或启动时默认选择时也会发现会话:
57
+
58
+ ```json
59
+ {"provider":"codex","project":"D:/project","recent":20}
60
+ ```
61
+
62
+ ## 检查环境
63
+
64
+ ```sh
65
+ sa --version
66
+ sa doctor
67
+ sa doctor --check-mcp
68
+ sa doctor --client codex --scope project --project PATH
69
+ ```
70
+
71
+ doctor 检查来源位置与权限、OpenCode 所需表结构、缓存状态及所选作用域的 MCP 配置语法和注册状态。缺少未使用的来源属于正常情况。`--check-mcp` 额外启动当前二进制,执行真实 stdio 握手、工具列表查询和连接关闭;它不代表目标客户端已加载或批准该服务。
72
+
73
+ 诊断为 JSON,包含 `ok`、`readable_sources` 和逐项 `checks`;脚本可以读取 `ok` 判断环境状态。诊断过程成功执行时退出码为 0,具体环境问题反映在 `ok:false` 及 checks 中。诊断输出不打印历史正文或完整客户端配置。
74
+
75
+ ## 配置格式依据
76
+
77
+ - [Codex MCP 配置](https://developers.openai.com/codex/mcp)
78
+ - [Claude Code MCP 作用域](https://code.claude.com/docs/en/mcp)
79
+ - [OpenCode MCP 配置](https://opencode.ai/docs/mcp-servers/)
80
+ - [OpenCode 配置位置](https://opencode.ai/docs/config/)
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,37 +1,38 @@
1
- {
2
- "name": "session-archaeologist",
3
- "version": "0.1.0",
4
- "description": "Inspect original OpenCode, Codex and Claude Code histories through CLI and stdio MCP",
5
- "license": "UNLICENSED",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/autorun886/Session-Archaeologist.git"
9
- },
10
- "homepage": "https://github.com/autorun886/Session-Archaeologist#readme",
11
- "bugs": "https://github.com/autorun886/Session-Archaeologist/issues",
12
- "keywords": ["mcp", "cli", "opencode", "codex", "claude-code", "session-history"],
13
- "engines": {"node": ">=20"},
14
- "os": ["win32", "linux", "darwin"],
15
- "cpu": ["x64", "arm64"],
16
- "bin": {
17
- "sa": "npm/cli.cjs",
18
- "session-archaeologist": "npm/cli.cjs"
19
- },
20
- "files": [
21
- "npm/cli.cjs",
22
- "npm/install.cjs",
23
- "npm/prebuilds/",
24
- "README.md",
25
- "README.en.md",
26
- "docs/CLI.md",
27
- "docs/MCP.md",
28
- "docs/DEVELOPMENT.md",
29
- "examples/"
30
- ],
31
- "scripts": {
32
- "install": "node npm/install.cjs",
33
- "build": "node npm/build.cjs",
34
- "test": "node --test npm/test/*.test.cjs",
35
- "prepack": "npm run build"
36
- }
37
- }
1
+ {
2
+ "name": "session-archaeologist",
3
+ "version": "0.2.0",
4
+ "description": "Inspect original OpenCode, Codex and Claude Code histories through CLI and stdio MCP",
5
+ "license": "UNLICENSED",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/autorun886/Session-Archaeologist.git"
9
+ },
10
+ "homepage": "https://github.com/autorun886/Session-Archaeologist#readme",
11
+ "bugs": "https://github.com/autorun886/Session-Archaeologist/issues",
12
+ "keywords": ["mcp", "cli", "opencode", "codex", "claude-code", "session-history"],
13
+ "engines": {"node": ">=20"},
14
+ "os": ["win32", "linux", "darwin"],
15
+ "cpu": ["x64", "arm64"],
16
+ "bin": {
17
+ "sa": "npm/cli.cjs",
18
+ "session-archaeologist": "npm/cli.cjs"
19
+ },
20
+ "files": [
21
+ "npm/cli.cjs",
22
+ "npm/install.cjs",
23
+ "npm/prebuilds/",
24
+ "README.md",
25
+ "README.zh-CN.md",
26
+ "docs/CLI.md",
27
+ "docs/MCP.md",
28
+ "docs/DEVELOPMENT.md",
29
+ "docs/ONBOARDING.md",
30
+ "examples/"
31
+ ],
32
+ "scripts": {
33
+ "install": "node npm/install.cjs",
34
+ "build": "node npm/build.cjs",
35
+ "test": "node --test npm/test/*.test.cjs",
36
+ "prepack": "npm run build"
37
+ }
38
+ }
package/README.en.md DELETED
@@ -1,183 +0,0 @@
1
- # Session Archaeologist
2
-
3
- **From conversation to execution evidence.**
4
-
5
- [中文](README.md) | English
6
-
7
- Session Archaeologist is a local session-history tool for people and AI agents. It reads original **OpenCode, Codex, and Claude Code** records to retrieve commands, tool arguments, execution results, and decision context still retained in history before context compaction.
8
-
9
- Start with the direct user–assistant conversation, inspect calls behind a selected reply, then read individual original results as needed. The CLI and stdio MCP server share one query engine, packaged as a standalone Go binary for Windows.
10
-
11
- ## Features
12
-
13
- - **Multiple providers and sessions:** query several sessions together, including mixed providers.
14
- - **Progressive inspection:** conversation → calls associated with a reply or user request → original inputs and results.
15
- - **Search and navigation:** keywords, regular expressions, tool names, paths, status filters, and neighboring events.
16
- - **Execution overviews:** per-request tool counts, recorded errors, exit codes, and structured file operations.
17
- - **Source references:** session IDs, original messages, and SQLite or JSONL source locations.
18
- - **Resumable large results:** character budgets, pagination, and hash-checked continuation reads.
19
- - **MCP integration:** 14 tools with native follow-up tool actions.
20
- - **Bounded caching:** compact metadata catalogues, on-demand body reads, capacity eviction, and expiry.
21
-
22
- The tool preserves original history and requires no separate database, indexing service, or model API. Commands found in history are treated as evidence.
23
-
24
- ## Install with npm
25
-
26
- Install the local package archive, replacing the path as needed:
27
-
28
- ```powershell
29
- npm install -g ./dist/session-archaeologist-0.1.0.tgz
30
- sa --help
31
- sa conversation "codex resume UUID" "claude --resume UUID"
32
- sa mcp
33
- ```
34
-
35
- Requires **Node.js 20 or later**. The package includes prebuilt x64/arm64 binaries for Windows, Linux, and macOS. Installation requires no Go toolchain or additional downloads. Both `sa` and `session-archaeologist` are available as commands.
36
-
37
- To build the package as a maintainer:
38
-
39
- ```powershell
40
- npm run build
41
- npm test
42
- npm pack --pack-destination dist
43
- ```
44
-
45
- The prepack hook rebuilds all six targets and requires Go 1.25 or later. The package file allowlist excludes source code, tests, session histories, and local caches. Distribution currently uses the local `.tgz` archive; publishing to the npm registry is a separate action.
46
-
47
- ## Build a standalone binary from source
48
-
49
- Requires **Go 1.25 or later**. The first build downloads dependencies.
50
-
51
- ```powershell
52
- $env:CGO_ENABLED = '0'
53
- go build -trimpath -o bin/sa.exe ./cmd/sa
54
- ```
55
-
56
- After building, only `sa.exe` is needed at runtime. Go, Node, Python, and the original agent CLIs are not required.
57
-
58
- ## Quick start
59
-
60
- Replace `SESSION_ID`, `UUID`, and paths with actual values. Pass familiar resume commands directly, or select sessions with `-s`:
61
-
62
- ```powershell
63
- .\bin\sa.exe sessions "opencode -s ses_SESSION_ID" "codex resume UUID" "claude --resume UUID"
64
- .\bin\sa.exe conversation "opencode -s ses_SESSION_ID" "codex resume UUID" "claude --resume UUID" --limit 20
65
- .\bin\sa.exe conversation -s codex:UUID -s claude:UUID
66
- ```
67
-
68
- Session order follows selection order, with duplicate selections removed. Each item retains its session identity; investigators establish cross-session relationships from evidence.
69
-
70
- Copy a reply entry's `id`, or a user message ID, from the conversation to inspect calls:
71
-
72
- ```powershell
73
- .\bin\sa.exe calls -s codex:UUID --reply REPLY_ID
74
- .\bin\sa.exe calls -s codex:UUID --user USER_MESSAGE_ID
75
- .\bin\sa.exe result -s codex:UUID --call CALL_ID --view output
76
- .\bin\sa.exe result -s codex:UUID --call CALL_ID --view raw --budget 0
77
- ```
78
-
79
- `--user` covers the entire request, including calls without a subsequent reply. Use `calls --all` for every call. Call lists show input previews by default. `result` defaults to original records; `--view input` or `output` focuses the read.
80
-
81
- ```powershell
82
- .\bin\sa.exe search -s codex:UUID --in output --query 'error'
83
- .\bin\sa.exe overview -s codex:UUID
84
- .\bin\sa.exe context -s codex:UUID --at CALL_ID --before 3 --after 3
85
- .\bin\sa.exe coverage -s codex:UUID
86
- ```
87
-
88
- ## Import and reuse multiple sessions
89
-
90
- `import` resolves and validates sources, then saves a JSON manifest containing session IDs and source paths:
91
-
92
- ```powershell
93
- .\bin\sa.exe import "opencode -s ses_SESSION_ID" "codex resume UUID" "claude --resume UUID" --out sessions.json
94
- .\bin\sa.exe conversation --manifest sessions.json
95
- .\bin\sa.exe search --manifest sessions.json --in output --query 'error'
96
- ```
97
-
98
- You can also select native JSONL files directly:
99
-
100
- ```powershell
101
- .\bin\sa.exe import --source 'D:\histories\codex.jsonl' --source 'D:\histories\claude.jsonl' --out sessions.json
102
- ```
103
-
104
- Manifests store references; original history stays in place. Both `--manifest` and `--source` are repeatable.
105
-
106
- ## Connect through MCP
107
-
108
- Add this configuration to a client supporting stdio MCP, replacing the binary path:
109
-
110
- ```json
111
- {
112
- "mcpServers": {
113
- "session-archaeologist": {
114
- "command": "D:\\tools\\sa.exe",
115
- "args": ["mcp"]
116
- }
117
- }
118
- }
119
- ```
120
-
121
- To preselect sessions, use args `["mcp", "--manifest", "D:\\histories\\sessions.json"]`. Agents can also pass several complete resume commands or session selectors in the `sessions` array of tool arguments.
122
-
123
- Recommended sequence: `sa_sessions` → `sa_conversation` → `sa_calls` → `sa_result`. Returned continuation actions contain `tool` and `arguments`, ready for the next call. Each call uses its explicit selection or the server's startup defaults.
124
-
125
- See the [MCP guide, in Chinese](docs/MCP.md) and the [client configuration template](examples/mcp-config.json).
126
-
127
- After installing globally with npm, use the [npm MCP configuration](examples/mcp-config.npm.json). Windows clients that need a command interpreter for npm shims can use the [Windows npm MCP configuration](examples/mcp-config.npm.windows.json): `cmd /c sa mcp`. The MCP client's PATH must include Node and global npm commands.
128
-
129
- ## Commands and tools
130
-
131
- | CLI | MCP | Purpose |
132
- | --- | --- | --- |
133
- | `sessions` | `sa_sessions` | Session metadata, record counts, and unassigned calls |
134
- | `conversation` | `sa_conversation` | Direct dialogue and compaction markers |
135
- | `calls` | `sa_calls` | Calls scoped by reply, user request, or all calls |
136
- | `result` | `sa_result` | Original tool call and linked results |
137
- | `message` | `sa_message` | Original message record |
138
- | `search` | `sa_search` | Search messages and tool inputs or outputs |
139
- | `overview` | `sa_overview` | Recorded execution facts for each request |
140
- | `context` | `sa_context` | Events surrounding an anchor |
141
- | `coverage` | `sa_coverage` | Source boundaries, compaction, and related resources |
142
- | `files` | `sa_files` | File operations from structured records |
143
- | `import` | `sa_import` | Validate sources and return a manifest; CLI supports saving with `--out` |
144
- | `cache status/prune/clear` | `sa_cache_status/prune/clear` | Inspect, prune, or clear the cache |
145
-
146
- ## Sources and coverage
147
-
148
- | Provider | Default location | Override |
149
- | --- | --- | --- |
150
- | OpenCode | `%USERPROFILE%\.local\share\opencode\opencode.db`; honors `XDG_DATA_HOME` | `--db PATH` |
151
- | Codex | `sessions` and `archived_sessions` under `CODEX_HOME` or `%USERPROFILE%\.codex` | `--codex-home PATH` |
152
- | Claude Code | `projects` under `CLAUDE_CONFIG_DIR` or `%USERPROFILE%\.claude` | `--claude-home PATH` |
153
-
154
- OpenCode currently supports the `session_v2`, `session_message`, and `session_part` formats. Codex and Claude Code use native JSONL files. Select files with `--source`, or override an already selected source path with `--source-map provider:UUID=PATH`.
155
-
156
- Evidence is limited to what the original records retain. Existing truncation, missing records, and compaction boundaries are preserved or reported in coverage. Claude Code subagent sidecars are currently listed in coverage and await automatic expansion. File-operation extraction uses structured tool arguments; actual changes made by arbitrary shell scripts require inspecting their results.
157
-
158
- ## Output and cache
159
-
160
- Data output is JSON with `schema_version: "0.2"`. Defaults are **16000 JSON characters** per response and **50 items** per list page. `--budget 0` requests unlimited output; `--limit 0` requests all items that fit the budget. Follow returned continuation actions for more content. Restart the read if evidence hashes change.
161
-
162
- The cache stores compact metadata catalogues; complete tool bodies are read from their sources on demand. Defaults: **128 MiB** disk, **16 MiB** encoded in-memory catalogues, **8 MiB** decoded per entry, **256 entries**, and **7 days** of idle expiry. These are cache limits; parsing and query results also require temporary memory.
163
-
164
- ```powershell
165
- .\bin\sa.exe cache status
166
- .\bin\sa.exe cache prune
167
- .\bin\sa.exe cache clear
168
- .\bin\sa.exe conversation -s codex:UUID --cache off --profile
169
- ```
170
-
171
- Cleanup operates only on cache files managed by this tool. A persistent MCP process reuses the bounded cache and serializes queries and cleanup to control peak memory.
172
-
173
- ## Documentation and validation
174
-
175
- - [Source layout and development guide](docs/DEVELOPMENT.md)
176
- - [CLI options, examples, and current limits — Chinese](docs/CLI.md)
177
- - [MCP setup and calling conventions — Chinese](docs/MCP.md)
178
- - [MCP client configuration template](examples/mcp-config.json)
179
-
180
- ```powershell
181
- go test ./...
182
- go vet ./...
183
- ```