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