session-archaeologist 0.0.0-stage → 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 +232 -3
- package/README.zh-CN.md +232 -0
- package/docs/CLI.md +316 -0
- package/docs/DEVELOPMENT.md +73 -0
- package/docs/MCP.md +68 -0
- package/docs/ONBOARDING.md +80 -0
- package/examples/mcp-config.json +8 -0
- package/examples/mcp-config.npm.json +8 -0
- package/examples/mcp-config.npm.windows.json +8 -0
- package/npm/cli.cjs +53 -0
- package/npm/install.cjs +8 -0
- package/npm/prebuilds/darwin-arm64/sa +0 -0
- package/npm/prebuilds/darwin-x64/sa +0 -0
- package/npm/prebuilds/linux-arm64/sa +0 -0
- package/npm/prebuilds/linux-x64/sa +0 -0
- package/npm/prebuilds/win32-arm64/sa.exe +0 -0
- package/npm/prebuilds/win32-x64/sa.exe +0 -0
- package/package.json +38 -6
package/README.md
CHANGED
|
@@ -1,3 +1,232 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Session Archaeologist
|
|
2
|
+
|
|
3
|
+
**Let your AI look up what it actually did.**
|
|
4
|
+
|
|
5
|
+
[中文](README.zh-CN.md) | English · [npm](https://www.npmjs.com/package/session-archaeologist)
|
|
6
|
+
|
|
7
|
+
How did we solve that problem last time? Which command worked? What failed? Where is the tool output from before context compaction?
|
|
8
|
+
|
|
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
|
+
|
|
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
|
+
```
|
|
15
|
+
|
|
16
|
+
Start with a few exchanges and drill down to the commands and results that matter. Long sessions can be read in manageable pieces.
|
|
17
|
+
|
|
18
|
+
## When would you use it?
|
|
19
|
+
|
|
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.
|
|
24
|
+
|
|
25
|
+
For example, after connecting MCP, ask your agent:
|
|
26
|
+
|
|
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
|
|
49
|
+
sa --help
|
|
50
|
+
```
|
|
51
|
+
|
|
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.
|
|
53
|
+
|
|
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.
|
|
55
|
+
|
|
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
|
|
62
|
+
```
|
|
63
|
+
|
|
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.
|
|
65
|
+
|
|
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.
|
|
67
|
+
|
|
68
|
+
## Try it: inspect an earlier session
|
|
69
|
+
|
|
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"
|
|
76
|
+
```
|
|
77
|
+
|
|
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.
|
|
79
|
+
|
|
80
|
+
### 1. Give it your session's resume command
|
|
81
|
+
|
|
82
|
+
Quote the resume command you already have and pass it as a query argument:
|
|
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
|
+
Replace `UUID` and `ses_SESSION_ID` with actual session IDs. Resume commands identify the history to read; the tool reads the underlying records directly.
|
|
91
|
+
|
|
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.
|
|
93
|
+
|
|
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
|
|
101
|
+
```
|
|
102
|
+
|
|
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.
|
|
104
|
+
|
|
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
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`overview` shows recorded execution facts for each request. `context` reveals events around a selected call or message.
|
|
114
|
+
|
|
115
|
+
## Investigate several sessions together
|
|
116
|
+
|
|
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"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Save a frequently used selection as a manifest:
|
|
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
|
+
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
|
|
134
|
+
|
|
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.
|
|
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
|
+
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"]`.
|
|
164
|
+
|
|
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`:
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"sessions": ["codex resume UUID", "claude --resume UUID"],
|
|
170
|
+
"limit": 20
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
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.
|
|
175
|
+
|
|
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).
|
|
177
|
+
|
|
178
|
+
## Long records, original content, and caching
|
|
179
|
+
|
|
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:
|
|
181
|
+
|
|
182
|
+
```sh
|
|
183
|
+
sa result -s codex:UUID --call CALL_ID --view raw --budget 0
|
|
184
|
+
```
|
|
185
|
+
|
|
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.
|
|
187
|
+
|
|
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
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Cleanup affects only cache files managed by this tool. Use `--cache off` to disable query caching and `--profile` for loading diagnostics.
|
|
197
|
+
|
|
198
|
+
## Find the command you need
|
|
199
|
+
|
|
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:
|
|
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
|
+
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`.
|
package/README.zh-CN.md
ADDED
|
@@ -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
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# CLI 使用说明(输出协议 0.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
|
+
|
|
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)。
|
|
6
|
+
|
|
7
|
+
推荐调查顺序:`conversation` 找请求和回复 → `overview` 看执行概览 → `search` 定位证据 → 按返回的 `read` / `context` 参数深入 → `coverage` 核对尚未展开的来源。所有数据响应带 `schema_version: "0.2"`、字符预算和必要的续读参数。
|
|
8
|
+
|
|
9
|
+
## 构建
|
|
10
|
+
|
|
11
|
+
需要 Go 1.25 或更新版本;首次构建需要下载依赖。
|
|
12
|
+
|
|
13
|
+
```powershell
|
|
14
|
+
$env:CGO_ENABLED = '0'
|
|
15
|
+
go build -trimpath -o bin/sa.exe ./cmd/sa
|
|
16
|
+
go test ./...
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
运行时仅需 `sa.exe`,无需安装 Go、Node、Python 或 OpenCode CLI。
|
|
20
|
+
|
|
21
|
+
## 多会话输入
|
|
22
|
+
|
|
23
|
+
三种来源可以在一次命令中混合选择,既接受带引号的完整命令,也接受展开的命令参数;这些内容仅用于选择历史,不会执行 resume 命令。
|
|
24
|
+
|
|
25
|
+
```powershell
|
|
26
|
+
.\bin\sa.exe sessions "opencode -s ses_df8f7b99dffeLV0uggVvGMVhPB" "codex resume 01a21ce6-0190-7353-921d-a18d7234db89" "claude --resume f7cc32fa-57aa-4888-9d36-5f4c92ddecfe"
|
|
27
|
+
.\bin\sa.exe conversation codex resume 01a21ce6-0190-7353-921d-a18d7234db89 claude --resume f7cc32fa-57aa-4888-9d36-5f4c92ddecfe
|
|
28
|
+
.\bin\sa.exe conversation -s codex:01a21ce6-0190-7353-921d-a18d7234db89 -s claude:f7cc32fa-57aa-4888-9d36-5f4c92ddecfe
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
OpenCode 的规范 session ID 保持 `ses_...`;另外两种来源使用 `codex:UUID`、`claude:UUID`,避免跨来源 UUID 冲突。也接受裸 UUID,但它必须在本机查找中只命中一个来源。重复选择去重并保留输入顺序;结果不合并成推断的跨会话时间线。
|
|
32
|
+
|
|
33
|
+
### 保存和重用会话清单
|
|
34
|
+
|
|
35
|
+
```powershell
|
|
36
|
+
.\bin\sa.exe import "codex resume 01a21ce6-0190-7353-921d-a18d7234db89" "claude --resume f7cc32fa-57aa-4888-9d36-5f4c92ddecfe" --out sessions.json
|
|
37
|
+
.\bin\sa.exe conversation --manifest sessions.json
|
|
38
|
+
.\bin\sa.exe overview --manifest sessions.json
|
|
39
|
+
.\bin\sa.exe search --manifest sessions.json --in output --query '报错关键词'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`import` 解析并校验来源;`--out` 保存完整 JSON 清单,不传则输出解析结果。清单记录 provider、session ID 和原始 JSONL 路径;有 OpenCode 时还保存原始数据库路径。它不复制、搬移或改写会话正文,也不生成新的历史数据库。输出要求 `.json`,并防止覆盖所选原始记录。
|
|
43
|
+
|
|
44
|
+
`--manifest` 可重复传入,清单路径中的相对源文件路径按清单所在目录解析;也可与其他 session 选择合并。所有查询命令均可复用清单。来源移动后可重新导入,或使用 `--source-map provider:UUID=PATH` 覆盖已选来源路径。
|
|
45
|
+
|
|
46
|
+
### 直接选择 JSONL 文件和自定义根目录
|
|
47
|
+
|
|
48
|
+
```powershell
|
|
49
|
+
.\bin\sa.exe import --source 'D:\histories\codex.jsonl' --source 'D:\histories\claude.jsonl' --out selected.json
|
|
50
|
+
.\bin\sa.exe conversation --source 'D:\histories\codex.jsonl' --source 'D:\histories\claude.jsonl'
|
|
51
|
+
.\bin\sa.exe sessions "codex resume UUID" --codex-home 'D:\codex-data'
|
|
52
|
+
.\bin\sa.exe sessions "claude --resume UUID" --claude-home 'D:\claude-data'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- Codex 默认根目录为 `CODEX_HOME`,未设置时使用 `%USERPROFILE%\.codex`,查找 `sessions` 和 `archived_sessions` 下对应的 rollout JSONL。
|
|
56
|
+
- Claude Code 默认根目录为 `CLAUDE_CONFIG_DIR`,未设置时使用 `%USERPROFILE%\.claude`,查找 `projects` 下对应的 session JSONL。
|
|
57
|
+
- `--source` 可重复传入,依据原始元数据识别来源和 session ID;同一 provider/ID 对应多个不同文件时报告冲突。
|
|
58
|
+
- `--source-map codex:UUID=PATH` 或 `--source-map claude:UUID=PATH` 只覆盖已选来源,不额外选择会话;其优先级高于清单中的路径。
|
|
59
|
+
- 一次查询使用一个 OpenCode 数据库;只选择 Codex/Claude 时不打开 OpenCode 数据库。
|
|
60
|
+
|
|
61
|
+
### 原生记录的关联与证据
|
|
62
|
+
|
|
63
|
+
Codex 通过 `call_id` 关联 `function_call` / `custom_tool_call` 和对应输出;Claude Code 通过 `tool_use_id` 关联 `tool_use` 与 `tool_result`。工具结果容器中的 user 记录不作为新的用户请求。Claude 的调用归属会核对 `parentUuid` 祖先链,缺失父记录会出现在覆盖报告中;不将不同分支的调用强行归给同一回复。
|
|
64
|
+
|
|
65
|
+
`result` 的默认 raw 视图对这两种来源返回 `format: "linked_original_records"` 包装:`call`、`results` 保留完整原生 JSONL 记录,另带调用和结果的来源定位。`--view input` / `output` 提供聚焦视图。Codex 的 JSON 字符串 arguments 会解码为结构化 input;字面原始 arguments 仍保留在 raw 中。
|
|
66
|
+
|
|
67
|
+
JSONL 的 `source` 包含 provider、文件、物理行号、字节范围和 JSON Pointer。消息优先使用原生 UUID/ID;没有 ID 的事件使用行号 ID。可继续用 `message --message ID` 读取单条原始记录。所有消息都按物理记录顺序展示,分支关系以原始父链和覆盖提示保留。
|
|
68
|
+
|
|
69
|
+
首轮读取建立精简行索引,后续复用有容量限制的目录缓存,按字节位置读取需要的行。支持超过 64 KiB 的行、UTF-8 BOM、CRLF 和正常的尾部追加。尚未写完的末行在覆盖报告中标记,不当作完整证据;中间损坏的行会明确报告位置。截断、替换或同长度改写期间的查询会提示重试。索引缓存不包含完整调用正文或结果。
|
|
70
|
+
|
|
71
|
+
压缩记录保留为 compaction 标记,摘要可从原始消息读取;不把摘要当作已缺失的原文。Claude 子代理 sidecar 文件只列入覆盖清单,尚未自动展开。编排工具(例如 `exec`)以历史中实际记录的外层调用为单位,不执行或推断脚本中的嵌套调用。
|
|
72
|
+
|
|
73
|
+
以下是原有的 OpenCode 简写形式:
|
|
74
|
+
|
|
75
|
+
下列三种形式等价。传入的 `opencode` 字符串只用于提取 session ID,程序不会启动 OpenCode。
|
|
76
|
+
|
|
77
|
+
```powershell
|
|
78
|
+
.\bin\sa.exe sessions -s ses_df8f7b99dffeLV0uggVvGMVhPB -s ses_de5452448ffeBYcD9bjiuq65yE
|
|
79
|
+
.\bin\sa.exe sessions opencode -s ses_df8f7b99dffeLV0uggVvGMVhPB opencode -s ses_de5452448ffeBYcD9bjiuq65yE
|
|
80
|
+
.\bin\sa.exe sessions "opencode -s ses_df8f7b99dffeLV0uggVvGMVhPB" "opencode -s ses_de5452448ffeBYcD9bjiuq65yE"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
重复 session ID 自动去重,保持输入顺序。每个结果都包含 session ID;多会话的列表按输入会话顺序连接,各会话内部按原始 `seq` 排列,不推断跨会话因果关系。
|
|
84
|
+
|
|
85
|
+
默认数据库路径为 `%USERPROFILE%\.local\share\opencode\opencode.db`;设置 `XDG_DATA_HOME` 时使用其下的 `opencode/opencode.db`。使用 `--db PATH` 可指定其他数据库。数据库以 `mode=ro` 和 `query_only` 打开,并在同一个读事务中读取多个会话,保留对 WAL 中已提交记录的可见性。
|
|
86
|
+
|
|
87
|
+
## 执行概览与事件上下文
|
|
88
|
+
|
|
89
|
+
```powershell
|
|
90
|
+
.\bin\sa.exe overview -s SESSION_ID
|
|
91
|
+
.\bin\sa.exe overview -s SESSION_ID --user USER_MESSAGE_ID
|
|
92
|
+
.\bin\sa.exe overview -s SESSION_ID --reply REPLY_ID
|
|
93
|
+
.\bin\sa.exe files -s SESSION_ID --user USER_MESSAGE_ID
|
|
94
|
+
.\bin\sa.exe calls -s SESSION_ID --user USER_MESSAGE_ID --failed
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`overview` 默认每个用户请求一项,分别统计工具分布、工具错误、非零退出、源结果截断、未归属调用和压缩事件,并保留最多 5 个值得查看的调用和 5 个文件操作样例。`inspect_failures`、`inspect_files` 提供完整列表的可执行参数。`files` 的范围是结构化工具参数:read/write/edit 的明确路径,以及 apply_patch 的 Add/Update/Delete File 指令;不推断任意 shell 命令实际改动了哪些文件。
|
|
98
|
+
|
|
99
|
+
`--failed` 按记录的工具错误或非零退出过滤。它不表示识别了所有实验失败:脚本可能以 0 退出,但输出显示目标进程重启。工具不生成成功/失败结论。
|
|
100
|
+
|
|
101
|
+
```powershell
|
|
102
|
+
.\bin\sa.exe context -s SESSION_ID --at CALL_ID --before 5 --after 5
|
|
103
|
+
.\bin\sa.exe context -s SESSION_ID --at MESSAGE_ID --before 2 --after 2
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`context` 按原始消息 seq 和 part 顺序返回事件预览。精确 event ID / 原始调用 ID 锚定单个事件;message ID 锚定该消息全部 parts。`window` 给出锚点、在该会话完整时间线中的起止位置和事件总数。分页的 `offset` 则相对这个窗口。窗口可以跨压缩节点,但始终属于一个会话;多会话同 ID 命中时需要缩小选择。
|
|
107
|
+
|
|
108
|
+
reasoning 仅显示记录存在的标记,长文本和工具参数只显示预览;原始消息仍由 `message` 读取。`before/after` 的计量单位是事件,包括内部事件标记,不是仅工具调用。
|
|
109
|
+
|
|
110
|
+
## 逐层查看
|
|
111
|
+
|
|
112
|
+
### 1. 直接对话
|
|
113
|
+
|
|
114
|
+
```powershell
|
|
115
|
+
.\bin\sa.exe conversation -s ses_df8f7b99dffeLV0uggVvGMVhPB -s ses_de5452448ffeBYcD9bjiuq65yE --limit 20
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
返回用户文本、assistant 对外文本和压缩标记,不展示 reasoning、工具结果、内部 synthetic 消息。每条 assistant 文本有独立 `id`、`message_id`、`call_count` 和 `source`。默认不展开调用 ID 数组;使用 `--call-ids` 可以恢复 `call_ids`。
|
|
119
|
+
|
|
120
|
+
用户条目提供 `turn_call_count` 和 `unanswered_call_count`:即使该请求被下一条用户消息打断、没有直接回复,也能发现期间发生的执行。assistant 条目中的 `call_count` 只计入它前面的调用区间;用户条目中的 `call_count` 为 0,应使用 `turn_call_count` 查看整轮数量。
|
|
121
|
+
|
|
122
|
+
压缩标记保留 `status`。读取其原始记录可查看压缩摘要和错误;此前的原始消息仍从历史表查询,不通过摘要重建。
|
|
123
|
+
|
|
124
|
+
### 2. 回复前的调用
|
|
125
|
+
|
|
126
|
+
从对话输出复制 assistant 条目的 `id`:
|
|
127
|
+
|
|
128
|
+
```powershell
|
|
129
|
+
.\bin\sa.exe calls -s SESSION_ID --reply 'MESSAGE_ID@PART_INDEX'
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
返回工具名、输入预览、状态和来源定位,不附带结果正文。预览优先选择 command/path 等字段,最多 240 个 Unicode 字符;`input_included` 表示完整参数是否包含在列表中,`preview_truncated` 只表示预览文本是否被截断,`input_characters` 是原始输入 JSON 的字符数。使用 `--full-input` 获取完整列表参数,也可通过 `result --view input` 单独读取一次调用的完整参数。同一条 assistant 消息可能依次包含“文本 → 调用 → 文本”,因此以 part 顺序界定区间:某条文本关联上一个对话文本之后、当前文本之前发生的工具调用。
|
|
133
|
+
|
|
134
|
+
原记录存在时还会显示 `exit_code` 和 `result_truncated`。`status=completed` 仅表示工具调用完成;退出码 0 也不代表实验目标达成,应继续核对结果正文。`--status STATUS` 按工具记录状态过滤。
|
|
135
|
+
|
|
136
|
+
工具后面若没有出现直接回复,调用保持未归属状态;新用户请求开始时关闭前一个执行区间,避免调用跨请求串线。`sessions` 返回 `unassigned_calls` 数量,以下命令可以查看全部调用,包括未归属项:
|
|
137
|
+
|
|
138
|
+
```powershell
|
|
139
|
+
.\bin\sa.exe calls -s SESSION_ID --all --tool bash --limit 20
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
按用户消息 ID 查询这一轮的全部调用,包括被后续消息打断、没有直接回复的调用:
|
|
143
|
+
|
|
144
|
+
```powershell
|
|
145
|
+
.\bin\sa.exe calls -s SESSION_ID --user USER_MESSAGE_ID
|
|
146
|
+
.\bin\sa.exe calls -s SESSION_ID --user USER_MESSAGE_ID --full-input
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`--reply` 也接受原始 message ID,但若该消息包含多条直接文本,会提示使用精确条目 ID。
|
|
150
|
+
|
|
151
|
+
### 3. 原始结果
|
|
152
|
+
|
|
153
|
+
```powershell
|
|
154
|
+
.\bin\sa.exe result -s SESSION_ID --call 'MESSAGE_ID@PART_INDEX'
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`raw` 视图读取完整工具 part,包含原始输入、输出、错误、状态、metadata 和子代理相关字段;响应受字符预算限制,需要时分段。也接受原始工具调用 ID。选择器在多个会话中命中多条记录时会报告歧义,应缩小到单个 session。
|
|
158
|
+
|
|
159
|
+
当参数包含很长的脚本、补丁或文件正文时,单独查看结果可避免重复读取输入:
|
|
160
|
+
|
|
161
|
+
```powershell
|
|
162
|
+
.\bin\sa.exe result -s SESSION_ID --call CALL_ID --view output
|
|
163
|
+
.\bin\sa.exe result -s SESSION_ID --call CALL_ID --view input
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`--view output` 返回解码后的 `text`、原始 metadata 和工具状态;保留各文本块、`state.output` 和 `state.error`,不混入参数或 JSON 字段名。`has_nontext_content=true` 表示另有图片等非文本块,应回到 raw 视图获取完整结构。`--start` / `--length` 此时按解码文本的 Unicode 字符位置分段,`next_start` 可继续读取。`--view input` 返回输入 JSON。各视图均保留明确的来源定位,不做敏感字段脱敏。
|
|
167
|
+
|
|
168
|
+
长结果自动按预算分段,也可以显式指定原始 JSON 文本的 Unicode 字符位置:
|
|
169
|
+
|
|
170
|
+
```powershell
|
|
171
|
+
.\bin\sa.exe result -s SESSION_ID --call CALL_ID --start 0 --length 4000
|
|
172
|
+
# 下一次使用 next_start;片段在 raw_text 中,各段拼接后得到原始 JSON。
|
|
173
|
+
.\bin\sa.exe result -s SESSION_ID --call CALL_ID --budget 0
|
|
174
|
+
# budget 0 关闭输出预算;不指定 length 时返回完整内容。
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
读取任意原始消息(包括压缩摘要、工具所在消息、synthetic、system、错误):
|
|
178
|
+
|
|
179
|
+
```powershell
|
|
180
|
+
.\bin\sa.exe message -s SESSION_ID --message MESSAGE_ID
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## 搜索
|
|
184
|
+
|
|
185
|
+
```powershell
|
|
186
|
+
.\bin\sa.exe search -s SESSION_ID --query '报错关键词'
|
|
187
|
+
.\bin\sa.exe search -s SESSION_ID --query 'timeout|failed' --regex
|
|
188
|
+
.\bin\sa.exe search -s SESSION_ID --query 'trace' --tool bash
|
|
189
|
+
.\bin\sa.exe search -s SESSION_ID --query 'error' --type tool
|
|
190
|
+
.\bin\sa.exe search -s SESSION_ID --query '结果' --type assistant --path 'D:\项目'
|
|
191
|
+
.\bin\sa.exe search -s SESSION_ID --query 'completed' --type compaction
|
|
192
|
+
.\bin\sa.exe search -s SESSION_ID --reply REPLY_ID --in output --query 'TransportError'
|
|
193
|
+
.\bin\sa.exe search -s SESSION_ID --user USER_MESSAGE_ID --in output --query 'error|failed' --regex
|
|
194
|
+
.\bin\sa.exe search -s SESSION_ID --in input --query '脚本名'
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
默认搜索原始消息中的 JSON 键和解码后的字符串值,忽略大小写,支持中文与 Windows 路径。`--case-sensitive` 开启大小写敏感匹配。`--tool` 或 `--type tool` 将搜索对象切换为工具 part,覆盖输入和结果;`--tool` 是精确名称匹配。`--path` 是区分大小写的字面子串过滤,不做文件系统路径规范化。命中返回短片段与原始定位,使用 `message` 或 `result` 获取全文。
|
|
198
|
+
|
|
199
|
+
`--in input|output|all` 限定工具搜索字段,避免命令参数、脚本正文与执行结果互相干扰。`output` 搜索文本输出和错误,不搜索 metadata 或非文本块;默认 `all` 保留完整 part 搜索。`--reply` / `--user` 限定调用区间,二者互斥,并隐含工具搜索;命中会带上 `reply_id`、`user_id`、工具名、记录状态和 `match_field`。`--path` 仍在完整调用上过滤,因此可同时按输入路径过滤、只在输出中匹配关键词。限定工具搜索时,应省略 `--type` 或使用 `--type tool`。
|
|
200
|
+
|
|
201
|
+
每条命中现在提供 `match_count` 和 `matches`,默认展示前 3 处匹配。每处匹配带 Unicode 字符坐标 `start/end`、上下文片段,以及可直接调用的 `read` 参数;记录还带 `context` 参数查看前后事件。`total` 统计命中的记录数,`match_count` 统计该记录内的匹配数。
|
|
202
|
+
|
|
203
|
+
高密度匹配只保留有界的位置前缀,避免为巨大输出中的每个重复字符分配坐标数组。`match_count_is_lower_bound: true` 表示 `match_count` 是已确认的数量下界;未出现该标记时为完整计数。仍可通过 `more_matches` 继续深入,或细化查询。
|
|
204
|
+
|
|
205
|
+
```powershell
|
|
206
|
+
.\bin\sa.exe search -s SESSION_ID --call CALL_ID --in output --query 'error|failed' --regex --matches 3
|
|
207
|
+
.\bin\sa.exe search -s SESSION_ID --call CALL_ID --in output --query 'error|failed' --regex --matches 3 --match-offset 3
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`--matches` 范围为 1–100;记录内仍有匹配时提供 `next_match_offset` 和 `more_matches`。按这个参数继续读取,避免只查看首个匹配。`--match-offset` 要求用 `--call` 或 `--message` 固定一条原始记录。`read` 的坐标域与视图一致:output 使用解码输出,input 使用 `input-text`,完整 part/消息使用 `search` 视图。后两者是包含 JSON 键与解码字符串的派生文本;原始 JSON 保留在 raw/input 视图。
|
|
211
|
+
|
|
212
|
+
## 调查覆盖与来源边界
|
|
213
|
+
|
|
214
|
+
```powershell
|
|
215
|
+
.\bin\sa.exe coverage -s SESSION_ID -s ANOTHER_SESSION_ID
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`summaries` 提供所选会话的源记录数量、首末 seq、压缩数、源结果截断数、未归属调用、关联会话、非文本块、用户附件和 blob 引用数量。分页 `items` 列出具体来源:父子/fork 会话、任务表和工具 metadata 中明确的 session 引用、metadata 中明确的外部输出路径、截断调用、非文本内容等。
|
|
219
|
+
|
|
220
|
+
- 关联会话的 `selected` 仅表示本次查询已选入该来源,`exists` 表示数据库里是否存在;存在的来源带 `inspect` 参数,可显式深入。
|
|
221
|
+
- 外部输出文件、用户附件和 blob 内容没有自动打开;在任意正文中提到的路径或 session ID 不会被推断成关联。
|
|
222
|
+
- `read_tracking: "not_tracked"`:程序不记录 Agent 实际读过哪些响应,也不将加载到内存视为调查完成。
|
|
223
|
+
- `historical_completeness` 为 unknown:当前记录不足以证明历史从未删除或遗漏。seq 间隙也不构成删除证据。
|
|
224
|
+
- 普通响应中的 `coverage` 是整个所选来源的库存提示,范围可能大于当前 `--reply` / `--user` 查询;通过其中的 `inspect` 展开完整报告。
|
|
225
|
+
- 按原始 message/part ID 精确读取单条证据时会跳过整个目录加载,此时 `coverage.counts_evaluated` 为 false,不把未计算的库存误报为零;可通过 `inspect` 单独核对覆盖情况。
|
|
226
|
+
|
|
227
|
+
## 加载与缓存
|
|
228
|
+
|
|
229
|
+
OpenCode 的单条 `message` 和 `MESSAGE_ID@PART_INDEX` 形式的 `result` 直接读取对应源记录,不先扫描整段历史;原始工具调用 ID 需要先通过目录映射定位。Codex/Claude 首次建立 JSONL 索引,之后按来源字节范围读取原文。对话先分页,再按需读取所选文本;`calls --full-input` 仅加载当前页的输入参数。概览、上下文和文件操作使用精简目录。搜索逐条读取原文,通常只保留当前页的命中详情;`--limit 0` 则允许保留全部命中详情。
|
|
230
|
+
|
|
231
|
+
目录缓存只包含消息/事件定位、调用状态、参数摘要、最多 240 字符的对话预览、结构化文件操作和覆盖库存引用,不存储完整工具输出、完整脚本输入或完整长对话。证据正文始终从原始数据库读取。
|
|
232
|
+
|
|
233
|
+
默认缓存目录为 `%LOCALAPPDATA%\SessionArchaeologist\cache`,可通过 `SA_CACHE_DIR` 环境变量或 `--cache-dir PATH` 覆盖。首次写入时初始化专用目录;已有非空目录必须带有本工具的所有权标记。
|
|
234
|
+
|
|
235
|
+
| 限制 | 默认值 | 计量方式 |
|
|
236
|
+
|---|---|---|
|
|
237
|
+
| 磁盘缓存 | 128 MiB | 本工具缓存条目的实际压缩字节数 |
|
|
238
|
+
| 内存 LRU | 16 MiB | 编码后的未压缩目录字节数;也限制条目数量 |
|
|
239
|
+
| 单条目录 | 8 MiB | 解压后的上限;超大目录直接跳过缓存 |
|
|
240
|
+
| 条目数量 | 256 | 每个数据库/session 只保留一个当前目录文件 |
|
|
241
|
+
| 闲置过期 | 168 小时 | 按最后访问时间,在下一次维护时清除 |
|
|
242
|
+
|
|
243
|
+
缓存边界与整个进程内存不同:解析/解压、待写缓存、查询结果和单条源记录仍有临时内存开销。单次查询待写目录的总量也被限制在一个条目上限以内,超过时跳过多余写入。冷加载的峰值还与最大单条消息(含其独立 parts)相关,尚未实现单条巨大 JSON 内部的流式解析。
|
|
244
|
+
|
|
245
|
+
```powershell
|
|
246
|
+
.\bin\sa.exe conversation -s SESSION_ID --cache off
|
|
247
|
+
.\bin\sa.exe overview -s SESSION_ID --cache-dir 'D:\sa-cache' --cache-max-mb 64
|
|
248
|
+
.\bin\sa.exe overview -s SESSION_ID --cache-memory-mb 8 --cache-entry-mb 4 --cache-ttl-hours 72 --cache-max-entries 100
|
|
249
|
+
.\bin\sa.exe overview -s SESSION_ID --profile
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`--cache off` 完全关闭查询的缓存读写;`--cache-memory-mb 0` 只关闭进程内 LRU,磁盘缓存仍可使用。生成的续读和证据跳转参数会保留缓存配置。CLI 进程退出时释放内存缓存;目录管理器支持在长生命周期调用方中复用。
|
|
253
|
+
|
|
254
|
+
缓存失效检测覆盖源路径、大小、修改时间和文件头/尾;OpenCode 还包括 WAL,并在读快照前后验证。数据库变化时采取保守失效策略,包括其他 session 的写入;不依赖 session 的更新时间字段,也不逐字节计算整个数据库的哈希。OpenCode 的源读取与正文展开共享只读事务,输出开始前释放;JSONL 固定打开时的文件长度,按原有前缀读取。目录更新覆盖原来的缓存文件,不积累旧 generation。三种来源共享同一组缓存容量限制。
|
|
255
|
+
|
|
256
|
+
缓存文件带格式版本、大小约束和 SHA-256 校验,采用同目录临时文件加重命名发布;损坏、不兼容、权限错误或缓存写入竞争会回退原始读取。缓存不是证据副本,也不是历史完整性的证明。
|
|
257
|
+
|
|
258
|
+
### 查看与清理
|
|
259
|
+
|
|
260
|
+
```powershell
|
|
261
|
+
.\bin\sa.exe cache status
|
|
262
|
+
.\bin\sa.exe cache prune
|
|
263
|
+
.\bin\sa.exe cache clear
|
|
264
|
+
.\bin\sa.exe cache prune --cache-dir 'D:\sa-cache' --cache-max-mb 64
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
- 这些命令不需要 session 或原始数据库。`status` 不创建缓存目录,报告实际条目、字节数、临时文件和限制。
|
|
268
|
+
- 查询开始及写入时自动维护:清理过期项、遗留临时文件和超大文件,按最近访问顺序淘汰;触及容量/数量上限时回收至约 75%,减少频繁淘汰。
|
|
269
|
+
- `prune` 立即执行维护并报告回收字节;`clear` 清除本工具拥有的缓存条目及本进程 LRU,保留所有权标记和锁文件。
|
|
270
|
+
- 维护使用操作系统文件锁,进程退出即释放,不依赖容易遗留的锁租约。并发查询可跳过缓存写入;显式维护遇到忙锁会报告重试。
|
|
271
|
+
- 清理只删除专用目录内符合本工具命名规则的普通文件,不递归遍历子目录,不跟随符号链接,也不清理原始历史或目录内的其他文件。目录扫描按批次进行,并限制保留的淘汰候选数量。
|
|
272
|
+
|
|
273
|
+
`--profile` 向 stderr 输出 JSON 诊断,包括加载模式、原文传入 Go 的字节数、解析消息数、目录缓存命中、跳过的超大条目、回收字节和分配量;stdout 仍是正常数据响应。`source_bytes_to_go` 计量正文/文本的传入量,不代表磁盘物理 I/O。初次建立目录有解析和压缩开销,收益主要出现在重复调查。
|
|
274
|
+
|
|
275
|
+
本机一次三次运行中位数测量(包含 Windows 进程启动,32 MiB 合成历史):
|
|
276
|
+
|
|
277
|
+
| 查询 | 优化前 | 新版冷加载 | 新版重复查询 |
|
|
278
|
+
|---|---:|---:|---:|
|
|
279
|
+
| 浏览对话 | 802 ms | 888 ms | 184 ms |
|
|
280
|
+
| 读取单条结果 | 788 ms | 150 ms | 145 ms |
|
|
281
|
+
|
|
282
|
+
重复浏览时原文传入量为 0;单条结果只读取约 256 KiB 的对应消息。测量随机器和历史结构变化,不是延迟保证。
|
|
283
|
+
|
|
284
|
+
## 输出与分页
|
|
285
|
+
|
|
286
|
+
- 数据输出为 JSON,带 `schema_version: "0.2"`。错误以 JSON 写入 stderr,失败退出码为 1;`evidence_changed` 表示续读期间内容发生变化。
|
|
287
|
+
- 列表返回 `items`、`total`、`offset`、`next_offset`。
|
|
288
|
+
- 默认每页 50 项;使用 `--offset N --limit N` 翻页,`--limit 0` 关闭条数限制。
|
|
289
|
+
- 所有数据响应默认限制为 **16000 个 Unicode 字符**,包含 JSON 结构、缩进、转义和末尾换行;这不是 token 估算。`--budget N` 可调整,最小非零值为 2048,`--budget 0` 返回不受预算限制的响应。
|
|
290
|
+
- `budget` 给出上限、实际输出字符数和是否因预算缩减;`--limit 0` 只关闭条数限制,字符预算仍然生效。
|
|
291
|
+
- 列表优先缩小整条记录的数量,`next_offset` 指向下一条;单条长对话文本会提供 `text_start`、`text_total_characters`、`text_next_start` 和校验哈希。通过 `continuation` 续读即可,无需手动推算。
|
|
292
|
+
- `result` / `message` 可使用 `--start` / `--length` 限定字符范围,`partial` 标记当前响应只覆盖原文的一部分。预算自动减小本次长度时也会更新 `next_start`。
|
|
293
|
+
- 列表和原文分段在顶层提供 `continuation.command` 和 `continuation.args`;记录内的后续搜索匹配使用 `more_matches`。这是参数数组,不是拼接的 shell 命令。续读期间原文哈希变化会报告错误,应重新开始读取;列表跨命令没有冻结快照。
|
|
294
|
+
- 若单条记录含超大 metadata 或复杂非文本结构,会显式使用 `format: "json_fragment"`。按 continuation 读取并拼接各段 `text`,再解析 JSON;该降级保持内容完整,并校验响应哈希。
|
|
295
|
+
- `--full-input` 或 `--call-ids` 单条过大时,会明确标记预算导致的省略,并给出 `read_input` / `read_calls`;完整源数据仍可分段读取。
|
|
296
|
+
- `source` 包含数据库绝对路径、表、session ID、message ID、原始 seq 和 JSON Pointer;独立 part 行使用 `part_ordinal` 定位。
|
|
297
|
+
- 调用/回复条目使用 `MESSAGE_ID@PART_INDEX`。ID 随原始消息和 part 位置保持稳定;跨 fork 会话可能重复,引用时应携带 session ID。
|
|
298
|
+
|
|
299
|
+
PowerShell 中可以直接执行返回的参数数组:
|
|
300
|
+
|
|
301
|
+
```powershell
|
|
302
|
+
$r = .\bin\sa.exe conversation -s SESSION_ID --budget 6000 | ConvertFrom-Json
|
|
303
|
+
if ($r.continuation) {
|
|
304
|
+
$nextArgs = @($r.continuation.args)
|
|
305
|
+
& $r.continuation.command @nextArgs
|
|
306
|
+
}
|
|
307
|
+
# search 的 matches[n].read、context、more_matches 和 coverage 的 inspect 同理。
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## 第一版边界
|
|
311
|
+
|
|
312
|
+
程序只整理现有证据,不调用模型生成结论。保留全部敏感字段。没有创建新的证据数据库或持久搜索索引;可选的精简目录缓存可以随时清理重建。
|
|
313
|
+
|
|
314
|
+
如果 OpenCode 当时已截断或清理某条工具结果,返回的就是历史中现存的内容和相关 metadata;不会把摘要当作缺失的原文。引用的外部输出文件、附件、blob、子代理会话和 fork 来源尚未自动展开,可从原始结果取得相关标识,再显式传入相应 session。源数据库被移动或消息内容被重写后,来源定位也可能变化。
|
|
315
|
+
|
|
316
|
+
当前已使用目录缓存、按页展开和原文逐条扫描;尚未实现单条巨大 JSON 内部的流式解析、跨进程持久读快照或追加记录的增量目录更新。
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Development layout
|
|
2
|
+
|
|
3
|
+
```text
|
|
4
|
+
cmd/sa/ Executable entry, process signals, exit diagnostics
|
|
5
|
+
internal/app/ CLI and MCP adapters, shared query execution
|
|
6
|
+
app.go Public application entry
|
|
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
|
|
12
|
+
cli_sources.go Source selection, manifest import and saving
|
|
13
|
+
cli_cache.go Cache configuration, management and profiling
|
|
14
|
+
query.go Request execution and source snapshot lifetime
|
|
15
|
+
search.go Search and match navigation
|
|
16
|
+
evidence.go Pagination, original evidence and decoded text
|
|
17
|
+
inspect.go Call previews and focused output views
|
|
18
|
+
actions.go CLI/MCP follow-up actions
|
|
19
|
+
response.go Response budgets and continuation shaping
|
|
20
|
+
mcp.go MCP registration, handlers and request scheduling
|
|
21
|
+
mcp_options.go MCP schemas and parameter adaptation
|
|
22
|
+
errors.go Shared structured error representation
|
|
23
|
+
internal/history/ Provider readers, source references and relationships
|
|
24
|
+
internal/cache/ Bounded metadata cache and platform-specific locking
|
|
25
|
+
docs/ Usage and development documentation
|
|
26
|
+
examples/ Client configuration examples
|
|
27
|
+
npm/ Node launcher, cross-platform package build and tests
|
|
28
|
+
prebuilds/ Generated native binaries, excluded from Git
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Tests live next to the implementation they exercise. The root directory holds
|
|
32
|
+
module configuration and the bilingual README files. Build output in `bin/` and
|
|
33
|
+
local validation artifacts in `.build/` are ignored by Git.
|
|
34
|
+
|
|
35
|
+
The npm package has no runtime npm dependencies. Its prepack hook cross-compiles
|
|
36
|
+
six binaries; installation uses the bundled binary without an install-time
|
|
37
|
+
download. Node inherits the native process streams and forwards arguments and
|
|
38
|
+
signals, keeping MCP stdout free of wrapper output. A local-only install hook sets
|
|
39
|
+
Unix executable permissions when an archive was produced on Windows. The launcher
|
|
40
|
+
also repairs permissions when install scripts were skipped and the file is writable.
|
|
41
|
+
|
|
42
|
+
```powershell
|
|
43
|
+
npm run build
|
|
44
|
+
npm test
|
|
45
|
+
npm pack --pack-destination dist
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Build and verify
|
|
49
|
+
|
|
50
|
+
```powershell
|
|
51
|
+
$env:CGO_ENABLED = '0'
|
|
52
|
+
go build -trimpath -o bin/sa.exe ./cmd/sa
|
|
53
|
+
go test ./...
|
|
54
|
+
go vet ./...
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`cmd/sa` imports only the application's public entry and diagnostic formatter.
|
|
58
|
+
CLI and MCP both execute validated options through `execute`. An MCP process
|
|
59
|
+
passes its shared cache manager explicitly; context carries cancellation and
|
|
60
|
+
deadlines. Each query opens and closes its own source snapshot before returning
|
|
61
|
+
output to a potentially slow consumer.
|
|
62
|
+
|
|
63
|
+
Provider-specific parsing belongs in `internal/history`; cache ownership and
|
|
64
|
+
eviction belong in `internal/cache`. Application code assembles query results and
|
|
65
|
+
transport-specific continuation actions. Original source records remain the
|
|
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
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# MCP 接入
|
|
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
|
+
|
|
5
|
+
`sa.exe mcp` 启动 stdio MCP 服务。标准输出仅用于协议,诊断输出到标准错误。客户端退出或关闭输入后服务结束。使用官方 Go MCP SDK 处理协议协商、取消和连接生命周期。
|
|
6
|
+
|
|
7
|
+
通用客户端配置(替换二进制路径):
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"mcpServers": {
|
|
12
|
+
"session-archaeologist": {
|
|
13
|
+
"command": "D:\\reverse\\Session-Archaeologist\\bin\\sa.exe",
|
|
14
|
+
"args": ["mcp"]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
也可以在 args 中追加 `--manifest PATH`,或重复 `-s SESSION` 预选多个会话。支持现有 CLI 的 `--db`、`--source`、`--source-map`、`--codex-home`、`--claude-home` 和缓存限制参数。服务启动时不要求选定会话;工具参数可以覆盖选择。
|
|
21
|
+
|
|
22
|
+
## Agent 查询顺序
|
|
23
|
+
|
|
24
|
+
1. `sa_sessions` 确认来源和会话范围。
|
|
25
|
+
2. `sa_conversation` 先读取用户与 Agent 的直接对话。
|
|
26
|
+
3. `sa_calls` 传入 `reply` 或 `user` 深入某次回复前的工具调用;`all:true` 查看所有调用。
|
|
27
|
+
4. `sa_result` 传入 `call` 读取原始调用及关联结果。`view:"output"` 聚焦输出,默认 raw 保留原记录。
|
|
28
|
+
|
|
29
|
+
例如:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"sessions": [
|
|
34
|
+
"opencode -s ses_df8f7b99dffeLV0uggVvGMVhPB",
|
|
35
|
+
"codex resume 01a21ce6-0190-7353-921d-a18d7234db89",
|
|
36
|
+
"claude --resume f7cc32fa-57aa-4888-9d36-5f4c92ddecfe"
|
|
37
|
+
],
|
|
38
|
+
"limit": 20
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
将此对象作为 `sa_conversation` 参数即可混合查询。各次调用独立,省略 sessions 时使用启动参数;服务没有隐式的“当前会话”。显式传入 sessions/source/manifest 会替换启动时的选择。来源路径通过 source_map 数组覆盖,格式 `codex:UUID=C:\\path\\history.jsonl`。
|
|
43
|
+
|
|
44
|
+
其他工具:`sa_message` 原始消息、`sa_search` 搜索、`sa_context` 周边事件、`sa_overview` 执行事实概览、`sa_files` 文件操作、`sa_coverage` 覆盖边界。`sa_import` 验证多个来源并返回 manifest 内容,保留原历史。
|
|
45
|
+
|
|
46
|
+
## 分页与完整结果
|
|
47
|
+
|
|
48
|
+
默认返回最多 16000 个 JSON 字符。列表默认 50 项;limit=0 表示在预算内尽量返回。budget=0 明确请求无限预算,适合确实需要完整大结果的场景。
|
|
49
|
+
|
|
50
|
+
结果中的 continuation、read、inspect 等动作统一为:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{"tool":"sa_result","arguments":{"sessions":["codex:UUID"],"call":"CALL_ID","start":4000,"expect_hash":"SHA256"},"reason":"..."}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
直接调用 tool 并完整复制 arguments。哈希验证用于检测续读期间证据变化;`evidence_changed` 时从头读取。默认不会把历史中的命令当成待执行指令。原始记录中已有的截断和缺失会保留,coverage 说明范围。
|
|
57
|
+
|
|
58
|
+
每次成功查询同时返回 structuredContent 和等价 JSON 文本;预算针对证据 JSON,MCP 外层封装和双份表示有额外开销。查询错误设置 isError=true;参数与证据错误信息可供 Agent 修正下一次调用。
|
|
59
|
+
|
|
60
|
+
## 长期运行与缓存
|
|
61
|
+
|
|
62
|
+
同一服务复用有容量上限的元数据缓存,每个请求重新建立来源读取快照,结束后释放文件和数据库读取。证据查询及缓存清理串行执行,以控制峰值内存并防止 clear 与正在读取的请求竞争。单次实际查询默认超时两分钟,客户端取消会传递到查询上下文。
|
|
63
|
+
|
|
64
|
+
默认磁盘上限 128 MiB、内存编码目录上限 16 MiB、单条解码上限 8 MiB、最多 256 条、闲置七天过期。读取前及写入时维护缓存,超过容量会回收;不缓存完整工具正文。
|
|
65
|
+
|
|
66
|
+
`sa_cache_status`、`sa_cache_prune`、`sa_cache_clear` 接受空对象参数。清理仅处理本工具管理的缓存文件,保留原始会话。启动参数 `--cache off` 禁用查询缓存;缓存管理工具仍可显式清理目录。
|
|
67
|
+
|
|
68
|
+
协议实现依赖 [官方 Go MCP SDK](https://github.com/modelcontextprotocol/go-sdk)。服务只提供本地 stdio,不启动 HTTP 监听。
|
|
@@ -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/)
|
package/npm/cli.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { spawn } = require('node:child_process');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
|
|
8
|
+
function binaryPath(platform = process.platform, arch = process.arch) {
|
|
9
|
+
if (!['win32', 'linux', 'darwin'].includes(platform) || !['x64', 'arm64'].includes(arch)) {
|
|
10
|
+
throw new Error(`Unsupported platform: ${platform}/${arch}. Supported: Windows, Linux and macOS on x64 or arm64.`);
|
|
11
|
+
}
|
|
12
|
+
const name = platform === 'win32' ? 'sa.exe' : 'sa';
|
|
13
|
+
return path.join(__dirname, 'prebuilds', `${platform}-${arch}`, name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function main() {
|
|
17
|
+
let executable;
|
|
18
|
+
try {
|
|
19
|
+
executable = binaryPath();
|
|
20
|
+
// Packages built on Windows may lack Unix executable mode bits.
|
|
21
|
+
if (process.platform !== 'win32') {
|
|
22
|
+
try { fs.accessSync(executable, fs.constants.X_OK); }
|
|
23
|
+
catch { fs.chmodSync(executable, 0o755); }
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(`session-archaeologist: ${error.message}`);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Inherit all streams, including MCP's protocol-only stdout. Never use a shell.
|
|
32
|
+
const child = spawn(executable, process.argv.slice(2), { stdio: 'inherit', windowsHide: true });
|
|
33
|
+
const forward = (signal) => { if (!child.killed) child.kill(signal); };
|
|
34
|
+
const onInterrupt = () => forward('SIGINT');
|
|
35
|
+
const onTerminate = () => forward('SIGTERM');
|
|
36
|
+
process.on('SIGINT', onInterrupt);
|
|
37
|
+
process.on('SIGTERM', onTerminate);
|
|
38
|
+
const cleanup = () => {
|
|
39
|
+
process.off('SIGINT', onInterrupt);
|
|
40
|
+
process.off('SIGTERM', onTerminate);
|
|
41
|
+
};
|
|
42
|
+
child.once('error', (error) => {
|
|
43
|
+
console.error(`session-archaeologist: failed to start ${executable}: ${error.message}`);
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
});
|
|
46
|
+
child.once('close', (code, signal) => {
|
|
47
|
+
cleanup();
|
|
48
|
+
process.exitCode = code ?? (signal === 'SIGINT' ? 130 : signal === 'SIGTERM' ? 143 : 1);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (require.main === module) main();
|
|
53
|
+
module.exports = { binaryPath };
|
package/npm/install.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const { binaryPath } = require('./cli.cjs');
|
|
5
|
+
|
|
6
|
+
// npm archives produced on Windows omit Unix executable bits. Set them during
|
|
7
|
+
// installation so a later user can run even a root-owned global installation.
|
|
8
|
+
if (process.platform !== 'win32') fs.chmodSync(binaryPath(), 0o755);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "session-archaeologist",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
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
|
+
}
|