@niracler/encore 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/LICENSE +21 -0
- package/README.md +157 -2
- package/README.zh-CN.md +115 -0
- package/bin/encore.mjs +282 -0
- package/package.json +55 -4
- package/player/encore-player.css +734 -0
- package/player/encore-player.js +3388 -0
- package/skills/encore/SKILL.md +80 -0
- package/src/claude-ai.mjs +69 -0
- package/src/claude-code.mjs +389 -0
- package/src/codex.mjs +396 -0
- package/src/common.mjs +333 -0
- package/src/detect.mjs +199 -0
- package/src/i18n.mjs +223 -0
- package/src/images.mjs +63 -0
- package/src/index.mjs +229 -0
- package/src/markdown.mjs +173 -0
- package/src/player-assets.mjs +90 -0
- package/src/player-runtime.mjs +1306 -0
- package/src/redact.mjs +84 -0
- package/src/render.mjs +578 -0
- package/src/server.mjs +96 -0
- package/src/timeline.mjs +1095 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 niracler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,158 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Encore
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Bring your AI agent sessions back on stage.**
|
|
4
|
+
*Like [`asciinema`](https://asciinema.org), but for AI Agent sessions (`Codex`, `Claude Code`, `Claude.ai`).*
|
|
5
|
+
|
|
6
|
+
[English](./README.md) · [简体中文](./README.zh-CN.md)
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Why Encore?
|
|
13
|
+
|
|
14
|
+
Screen recordings of AI coding or design sessions are blurry, bulky, and unsearchable. Plain Markdown chat exports strip away everything that actually matters in an agentic workflow: **what was inside the context window, which tools and sub-agents ran, how visual artifacts evolved step by step, and when context compaction fired.**
|
|
15
|
+
|
|
16
|
+
**Encore** turns raw session logs from **OpenAI Codex**, **Claude Code**, and **Claude.ai** into an interactive, self-contained web stage:
|
|
17
|
+
|
|
18
|
+
| Stage Area | What It Shows |
|
|
19
|
+
| :--- | :--- |
|
|
20
|
+
| **Left · Conversation & Artifact Stage** | Typewriter prompt composer, soft-breathing Markdown reply streaming, live tool call shimmer (`1.0×` / `12×` / `0.8×`), sub-agent dispatches & reports, inline `.webp` visual outputs, intermediate Markdown drafts, and audio/video deliverables. |
|
|
21
|
+
| **Right · Live Context Window Inspector** | Real-time token gauge (`200k` / `1.0M`), 7-color stacked bar (`System Prompt`, `Tool Schemas & MCP`, `User Messages`, `Memory & Rules`, `Skills`, `Assistant`, `Tool Outputs`), auto-compaction headroom markers, and drill-down payload inspection for every step. |
|
|
22
|
+
| **Bottom · Segmented Milestone Timeline** | Interactive step segments with pinned visual frames (`🖼`), draft documents (`📄`), context compactions (`🗜`), and user turns (`💬`). |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Architecture (Inspired by `asciinema`)
|
|
27
|
+
|
|
28
|
+
Encore separates data, player, and CLI into three clean layers:
|
|
29
|
+
|
|
30
|
+
1. **Data Format (`session.json` + `.webp`)**: A self-contained, human-editable JSON file (analogous to `.cast` in `asciinema`) holding metadata (`title`, `description`, `deliverables`), visual milestone `frames`, initial context mounts, and normalized conversation `items`.
|
|
31
|
+
2. **Standalone Player (`encore-player.js` + `encore-player.css`)**: Zero-dependency drop-in browser player. Any HTML page can embed a replay with a single tag:
|
|
32
|
+
```html
|
|
33
|
+
<link rel="stylesheet" href="./encore-player.css">
|
|
34
|
+
<div data-encore-player src="./session.json" data-lang="en"></div>
|
|
35
|
+
<script src="./encore-player.js" defer></script>
|
|
36
|
+
```
|
|
37
|
+
3. **CLI (`encore`)**: Auto-detects `Codex`, `Claude Code`, and `Claude.ai` logs, extracts embedded images into `.webp`, redacts local paths & secrets, writes the static replay folder, and serves a live local preview.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 30-Second Quick Start (Raw Cut)
|
|
42
|
+
|
|
43
|
+
### 1. Pick from your recent local sessions
|
|
44
|
+
|
|
45
|
+
Run `encore` with no arguments to scan `~/.codex/sessions` and `~/.claude/projects` and pick a recent session with `↑` / `↓`:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx @niracler/encore
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 2. Convert a specific log file directly
|
|
52
|
+
|
|
53
|
+
Pass any `.jsonl` (or `.jsonl.zst` / Claude `.json` export) and Encore will auto-detect the format, extract embedded screenshots to `.webp`, mask sensitive strings, and launch a local preview:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx @niracler/encore /path/to/rollout.jsonl -o ./replays/my-session
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 3. Edit `session.json` & refresh
|
|
60
|
+
|
|
61
|
+
Because `index.html` loads `./session.json` dynamically, **any edit you make to `session.json` (changing `title`, adding `description`, renaming or deleting `frames`) appears immediately when you refresh the browser.**
|
|
62
|
+
|
|
63
|
+
You can also re-run `encore` on an existing replay directory to sync `<title>` in `index.html` and re-run the privacy leak check:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx @niracler/encore ./replays/my-session
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Agent Curation Workflow (Director's Cut)
|
|
72
|
+
|
|
73
|
+
Raw agent logs often contain 20+ repetitive screenshots, long first prompts instead of a clear title, or internal project names that regex redaction cannot catch.
|
|
74
|
+
|
|
75
|
+
Encore ships with an all-in-one Agent Skill at [`skills/encore/SKILL.md`](./skills/encore/SKILL.md). Install or link it into `.agents/skills/encore` (or `~/.codex/skills/encore` / `~/.claude/skills/encore`) and ask your agent:
|
|
76
|
+
|
|
77
|
+
> *"Use the `encore` skill to export my latest session and curate `session.json` for publishing."*
|
|
78
|
+
|
|
79
|
+
The skill guides the agent through four curation steps:
|
|
80
|
+
1. **Visual Frame Pruning & Naming**: Visually inspects every extracted `.webp` image, deletes broken or redundant screenshots from `frames[]`, and writes concise narrative labels (e.g. `"V1 wireframe"`, `"Final dark-mode layout"`).
|
|
81
|
+
2. **Title & Opening Story Intro**: Writes a punchy `title` and a 1–3 sentence `description` explaining the problem, mid-session pivot, and outcome without fluff.
|
|
82
|
+
3. **Semantic Privacy Cleanup**: Scans `items[]` for internal codenames, colleague names, or sensitive business logic and replaces them with `(Internal context redacted)`.
|
|
83
|
+
4. **Time-Window Trimming**: Cuts unrelated off-topic turns at the start or end of a session.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## `session.json` Schema Reference
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"tool": "codex",
|
|
92
|
+
"model": "gpt-5.4",
|
|
93
|
+
"title": "Redesigning the 7-Stage Architecture Diagram",
|
|
94
|
+
"description": "Started with a cluttered layout, pivoted to a two-column grid after visual review, and exported the final SVG.",
|
|
95
|
+
"lang": "en",
|
|
96
|
+
"started": "2026-11-17T10:00:00.000Z",
|
|
97
|
+
"ended": "2026-11-17T10:18:30.000Z",
|
|
98
|
+
"contextWindow": 258400,
|
|
99
|
+
"deliverables": [
|
|
100
|
+
{
|
|
101
|
+
"title": "Final Architecture Diagram",
|
|
102
|
+
"href": "./final-diagram.webp",
|
|
103
|
+
"meta": "SVG / WebP · 1920×1080"
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"frames": [
|
|
107
|
+
{
|
|
108
|
+
"time": "2026-11-17T10:04:12.000Z",
|
|
109
|
+
"img": "a1b2c3d4e5f6.webp",
|
|
110
|
+
"who": "ai",
|
|
111
|
+
"label": "Draft 1: Overcrowded labels",
|
|
112
|
+
"w": 960,
|
|
113
|
+
"h": 540
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"items": [
|
|
117
|
+
{ "type": "user", "text": "...", "time": "..." },
|
|
118
|
+
{ "type": "tool", "name": "exec_command", "summary": "...", "stats": { "command": 1 }, "time": "..." },
|
|
119
|
+
{ "type": "compact", "seq": 1, "trigger": "auto", "preTokens": 210000, "postTokens": 42000, "time": "..." },
|
|
120
|
+
{ "type": "assistant", "text": "...", "time": "..." }
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## CLI Options
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
Usage:
|
|
131
|
+
encore Scan recent Codex & Claude Code sessions and pick one interactively
|
|
132
|
+
encore <log.jsonl | dir> [options] Build a standalone replay directory from a log or re-render an edited session.json
|
|
133
|
+
encore play <dir> [--port 4180] Start local preview server for an existing replay directory
|
|
134
|
+
|
|
135
|
+
Options:
|
|
136
|
+
-o, --out <dir> Output directory (default: ./replays/<session-slug>)
|
|
137
|
+
-l, --lang <zh|en|auto> Player UI language (default: auto; also toggleable in the topbar)
|
|
138
|
+
--title <text> Override session title
|
|
139
|
+
--desc <text> Set opening description shown before playback starts
|
|
140
|
+
--from <iso-time> Start time window filter (e.g. 2026-11-10T09:00)
|
|
141
|
+
--to <iso-time> End time window filter
|
|
142
|
+
--no-images Skip extracting embedded images to .webp
|
|
143
|
+
--image-width <px> Max width for extracted WebP frames (default: 960)
|
|
144
|
+
--clip <chars> Max chars per tool input/output (default: 1500/2000)
|
|
145
|
+
--conversation <id> Conversation UUID for multi-chat Claude.ai exports
|
|
146
|
+
--include-memory Include full cross-session MEMORY_SUMMARY / User CLAUDE.md text
|
|
147
|
+
--list List recent local sessions without interactive prompt
|
|
148
|
+
--serve Start local HTTP preview server after building
|
|
149
|
+
--no-serve Do not start local HTTP preview server
|
|
150
|
+
--no-open Do not automatically open browser when serving
|
|
151
|
+
-p, --port <number> Preview server port (default: 4180)
|
|
152
|
+
-v, --version Show version number
|
|
153
|
+
-h, --help Show help message
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
[MIT](./LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Encore
|
|
2
|
+
|
|
3
|
+
**Bring your AI agent sessions back on stage.**
|
|
4
|
+
*把 AI Agent 的工作现场搬回舞台再演一场 —— AI Agent 时代的 [`asciinema`](https://asciinema.org)(支持 `Codex`、`Claude Code`、`Claude.ai`)。*
|
|
5
|
+
|
|
6
|
+
[English](./README.md) · [简体中文](./README.zh-CN.md)
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 它是干什么的?
|
|
13
|
+
|
|
14
|
+
把 AI 编程或设计过程录成视频又糊又大,而导出成普通 Markdown 聊天记录又会丢掉 Agent 工作流里最精彩的部分:**每一轮上下文窗口(Context Window)里到底塞了什么、调用了哪些工具与子代理、中间视觉稿是怎么一版版演进出来的,以及什么时候触发了上下文压缩(Compaction)。**
|
|
15
|
+
|
|
16
|
+
**Encore** 将 **OpenAI Codex**、**Claude Code** 和 **Claude.ai** 的原始会话日志一键转换为可交互的独立网页剧场:
|
|
17
|
+
|
|
18
|
+
| 舞台区域 | 还原内容 |
|
|
19
|
+
| :--- | :--- |
|
|
20
|
+
| **左屏 · 对话流与作品演进** | 底部输入框打字上屏、Agent 回复呼吸感流式输出、工具调用流光快切(`1.0×` / `12×` / `0.8×`)、子任务派发与报告弹窗、内嵌 `.webp` 过程效果图、Markdown 中间草稿与音视频交付物。 |
|
|
21
|
+
| **右屏 · Context 实时透视面板** | 实时显示上下文窗口水位(`200k` / `1.0M`)、7 色分段进度条(系统提示词、工具定义、用户消息、注入规则、技能、助手回复、工具输出)、自动压缩警戒线,点击任意消息或色块即可定格查看当时的原文载荷。 |
|
|
22
|
+
| **底部 · 关键帧章节时间轴** | 按步骤切分的时间轴,自动钉出过程效果图(`🖼`)、中间文稿(`📄`)、上下文压缩(`🗜`)与提问轮次(`💬`)。 |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 三层解耦架构(致敬 `asciinema`)
|
|
27
|
+
|
|
28
|
+
1. **标准数据格式(`session.json` + `.webp`)**:全量自包含、可直接手改的 JSON 文件(类比 `asciinema` 的 `.cast`),内含标题(`title`)、开场导读(`description`)、最终交付物(`deliverables`)、过程图片关键帧(`frames`)与对话记录(`items`)。
|
|
29
|
+
2. **独立播放器(`encore-player.js` + `encore-player.css`)**:零外部依赖的纯前端组件。生成的 `index.html` 极其干净,要在个人博客或文档站嵌入回放,只需一行标签:
|
|
30
|
+
```html
|
|
31
|
+
<link rel="stylesheet" href="./encore-player.css">
|
|
32
|
+
<div data-encore-player src="./session.json" data-lang="zh"></div>
|
|
33
|
+
<script src="./encore-player.js" defer></script>
|
|
34
|
+
```
|
|
35
|
+
3. **CLI 转换与预览工具(`encore`)**:自动识别日志来源、默认导出 `.webp` 图片、自动脱敏本机路径与密钥(非阻塞告警)、生成静态目录并启动本地预览服务。
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 30 秒上手(生肉直出)
|
|
40
|
+
|
|
41
|
+
### 1. 免找文件:直接扫描本机最近对话
|
|
42
|
+
|
|
43
|
+
在终端直接运行 `npx @niracler/encore`(不带参数),工具会自动扫描 `~/.codex/sessions` 和 `~/.claude/projects` 下最近的对话,显示时间与首句提问,按 `↑` / `↓` 挑一条回车即可导出并打开预览:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx @niracler/encore
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. 指定日志文件一步直出
|
|
50
|
+
|
|
51
|
+
无需手动指定是哪家工具的日志,`encore` 会自动识别文件内容:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx @niracler/encore /path/to/rollout.jsonl -o ./replays/my-session
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 3. 改 `session.json` 实时生效
|
|
58
|
+
|
|
59
|
+
由于 `index.html` 动态读取同目录的 `./session.json`,**你在编辑器里修改 `session.json` 的标题、开场导读或删减图片后,直接刷新浏览器就能看到最新效果,无需重新编译。**
|
|
60
|
+
|
|
61
|
+
如果需要同步更新 `index.html` 的 `<title>` 标签或重新运行隐私脱敏检查,对目录再跑一次命令即可:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npx @niracler/encore ./replays/my-session
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Agent 精修工作流(熟肉策展)
|
|
70
|
+
|
|
71
|
+
脚本一步直出的「生肉」回放里,往往夹杂着二三十张重复微调或报错的截图,标题也只是第一句长提问。
|
|
72
|
+
|
|
73
|
+
仓库内置了配套的精修 Skill:[`skills/encore/SKILL.md`](./skills/encore/SKILL.md)。将它放入 `.agents/skills/encore`(或全局 `~/.codex/skills/encore` / `~/.claude/skills/encore`)后,直接对 Agent 说:
|
|
74
|
+
|
|
75
|
+
> 「用 `encore` 技能把我刚才那段对话导出并精修一下。」
|
|
76
|
+
|
|
77
|
+
Agent 会自动完成 4 件事:
|
|
78
|
+
1. **逐张看图筛废片与起名**:用多模态看图检查导出目录里的 `.webp`,删掉报错图与重复图,只留关键演进节点,并补写清晰的 `label`(如 `"第一张草图:信息过载"`、`"终稿:定版海报"`)。
|
|
79
|
+
2. **提炼短标题与故事导读**:去掉空洞套话,在 `session.json` 顶层写出直奔主题的 `title` 与几十宇的 `description` 开场脉络。
|
|
80
|
+
3. **语义级隐私与噪音清理**:识别正则抓不到的业务代号、同事姓名或内部地址,替换为 `(涉及内部业务细节,已略去)`。
|
|
81
|
+
4. **掐头去尾(时间切片)**:切掉会话首尾顺手聊的无关话题,只保留完整讲好一件事的片段。
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## `session.json` 字段速查与 CLI 参数
|
|
86
|
+
|
|
87
|
+
- `title`:页面顶部标题与浏览器标签名(自动取日志标题或首句提问摘要,可直接手改)。
|
|
88
|
+
- `description`:点击播放前在空白舞台中央展示的开场导读。
|
|
89
|
+
- `lang`:界面默认语言(`"zh"` 或 `"en"`,也可点击网页右上角按钮随时切换中英文)。
|
|
90
|
+
- `frames`:过程图片数组 `[{ time, img, who, label, w, h }]`,删掉不需要的项即可从时间轴和对话流中移除该图。
|
|
91
|
+
- `deliverables`:会话结束时展示的最终成果列表 `[{ title, href, meta, cover }]`。
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
用法:
|
|
95
|
+
encore 扫描本机最近的 Codex 与 Claude Code 会话,上下键选择导出
|
|
96
|
+
encore <log.jsonl | dir> [options] 从原始日志一步生成回放目录,或对已修改的目录重新同步
|
|
97
|
+
encore play <dir> [--port 4180] 启动本地预览服务
|
|
98
|
+
|
|
99
|
+
常用参数:
|
|
100
|
+
-o, --out <dir> 输出目录(默认:./replays/<会话短名>)
|
|
101
|
+
-l, --lang <zh|en|auto> 界面语言(默认:auto,网页右上角也可一键切换)
|
|
102
|
+
--title <text> 自定义回放标题
|
|
103
|
+
--desc <text> 自定义开场导读说明
|
|
104
|
+
--from <iso-time> 起始时间切片(如 2026-11-10T09:00)
|
|
105
|
+
--to <iso-time> 结束时间切片
|
|
106
|
+
--no-images 不提取内嵌图片
|
|
107
|
+
--include-memory 保留完整的跨会话 MEMORY_SUMMARY / 用户级 CLAUDE.md 原文(默认自动折叠脱敏)
|
|
108
|
+
--list 仅列出本机最近会话,不进入交互菜单
|
|
109
|
+
--no-serve 生成文件后直接退出,不启动本地预览服务
|
|
110
|
+
-v, --version 显示版本号
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 开源协议
|
|
114
|
+
|
|
115
|
+
[MIT](./LICENSE)
|
package/bin/encore.mjs
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { parseArgs } from 'node:util'
|
|
6
|
+
import readline from 'node:readline'
|
|
7
|
+
import {
|
|
8
|
+
buildReplay,
|
|
9
|
+
rebuildReplayDir,
|
|
10
|
+
scanRecentSessions,
|
|
11
|
+
serveReplayDir,
|
|
12
|
+
} from '../src/index.mjs'
|
|
13
|
+
|
|
14
|
+
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json')
|
|
15
|
+
|
|
16
|
+
const HELP = `
|
|
17
|
+
encore (@niracler/encore) — Bring your AI agent sessions back on stage.
|
|
18
|
+
|
|
19
|
+
Usage:
|
|
20
|
+
encore Scan recent Codex & Claude Code sessions and pick one interactively
|
|
21
|
+
encore <log.jsonl | dir> [options] Build a standalone replay directory from a log or re-render an edited session.json
|
|
22
|
+
encore play <dir> [--port 4180] Start local preview server for an existing replay directory
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
-o, --out <dir> Output directory (default: ./replays/<session-slug>)
|
|
26
|
+
-l, --lang <zh|en|auto> Player UI language (default: auto)
|
|
27
|
+
--title <text> Override session title
|
|
28
|
+
--desc <text> Set opening description shown before playback starts
|
|
29
|
+
--from <iso-time> Start time window filter (e.g. 2026-11-10T09:00)
|
|
30
|
+
--to <iso-time> End time window filter
|
|
31
|
+
--no-images Skip extracting embedded images to .webp
|
|
32
|
+
--image-width <px> Max width for extracted WebP frames (default: 960)
|
|
33
|
+
--clip <chars> Max chars per tool input/output (default: 1500/2000)
|
|
34
|
+
--conversation <id> Conversation UUID for multi-chat Claude.ai exports
|
|
35
|
+
--include-memory Include full cross-session MEMORY_SUMMARY / User CLAUDE.md text
|
|
36
|
+
--list List recent local sessions without interactive prompt
|
|
37
|
+
--serve Start local HTTP preview server after building
|
|
38
|
+
--no-serve Do not start local HTTP preview server
|
|
39
|
+
--no-open Do not automatically open browser when serving
|
|
40
|
+
-p, --port <number> Preview server port (default: 4180)
|
|
41
|
+
-v, --version Show version number
|
|
42
|
+
-h, --help Show this help message
|
|
43
|
+
`.trim()
|
|
44
|
+
|
|
45
|
+
function printBuildReport(result) {
|
|
46
|
+
const { mode, toolLabel, dir, sessionFile, session, leaks } = result
|
|
47
|
+
const relDir = relative(process.cwd(), dir) || '.'
|
|
48
|
+
const relSession = relative(process.cwd(), sessionFile) || 'session.json'
|
|
49
|
+
const count = type => (session.items || []).filter(item => item.type === type).length
|
|
50
|
+
const framesCount = (session.frames || []).length
|
|
51
|
+
const action = mode === 'rebuild' ? 'Re-rendered' : 'Generated'
|
|
52
|
+
|
|
53
|
+
console.log(`\n✨ ${action} replay in ${relDir}/`)
|
|
54
|
+
console.log(` Title : ${session.title}`)
|
|
55
|
+
console.log(` Agent : ${toolLabel}${session.model ? ` · ${session.model}` : ''}`)
|
|
56
|
+
console.log(` Steps : ${count('user')} prompts · ${count('assistant')} replies · ${count('tool')} tool calls${count('compact') ? ` · ${count('compact')} compactions` : ''}`)
|
|
57
|
+
if (framesCount) {
|
|
58
|
+
console.log(` Frames : ${framesCount} WebP image(s) in frames[] (edit ${relSession} to prune or rename labels)`)
|
|
59
|
+
}
|
|
60
|
+
console.log(` Files : index.html, session.json, encore-player.js, encore-player.css`)
|
|
61
|
+
|
|
62
|
+
if (leaks.length) {
|
|
63
|
+
console.log(`\n⚠️ Privacy check found ${leaks.length} potential sensitive snippet(s) (non-blocking — review in ${relSession}):`)
|
|
64
|
+
for (const leak of leaks.slice(0, 12)) {
|
|
65
|
+
console.log(` - ${leak.path} · ${leak.rule} · ${leak.match}`)
|
|
66
|
+
}
|
|
67
|
+
if (leaks.length > 12) {
|
|
68
|
+
console.log(` ... and ${leaks.length - 12} more`)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function truncateToColumns(str, maxCols) {
|
|
74
|
+
let width = 0
|
|
75
|
+
let out = ''
|
|
76
|
+
for (const ch of String(str)) {
|
|
77
|
+
const code = ch.codePointAt(0)
|
|
78
|
+
const w = code > 0x1f00 ? 2 : 1
|
|
79
|
+
if (width + w > maxCols - 1) return `${out}…`
|
|
80
|
+
out += ch
|
|
81
|
+
width += w
|
|
82
|
+
}
|
|
83
|
+
return out
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function pickRecentSessionInteractive(sessions) {
|
|
87
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
88
|
+
console.log('Recent local AI Agent sessions:\n')
|
|
89
|
+
sessions.forEach((s, idx) => {
|
|
90
|
+
console.log(` [${idx + 1}] ${s.timeLabel} · ${s.toolLabel.padEnd(11)} · ${s.preview}`)
|
|
91
|
+
console.log(` ${s.file} (${s.sizeKB} KB)`)
|
|
92
|
+
})
|
|
93
|
+
console.log('\nRun: encore <file-path> -o ./replays/my-session')
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return new Promise(resolvePromise => {
|
|
98
|
+
let selected = 0
|
|
99
|
+
const total = sessions.length
|
|
100
|
+
|
|
101
|
+
const renderMenu = (firstRender = false) => {
|
|
102
|
+
if (!firstRender) {
|
|
103
|
+
readline.moveCursor(process.stdout, 0, -(total + 3))
|
|
104
|
+
readline.clearScreenDown(process.stdout)
|
|
105
|
+
}
|
|
106
|
+
const cols = Math.max(40, (process.stdout.columns || 80) - 2)
|
|
107
|
+
process.stdout.write(`${truncateToColumns('🎭 Pick a recent AI Agent session to bring back on stage (↑/↓ to move, Enter to select, q to quit):', cols)}\n\n`)
|
|
108
|
+
sessions.forEach((s, idx) => {
|
|
109
|
+
const active = idx === selected
|
|
110
|
+
const prefix = active ? ' ❯ ' : ' '
|
|
111
|
+
const num = String(idx + 1).padStart(2, ' ')
|
|
112
|
+
const badge = `[${s.toolLabel}]`.padEnd(13, ' ')
|
|
113
|
+
const line = truncateToColumns(`${prefix}${num}. ${s.timeLabel} ${badge} ${s.preview} (${s.sizeKB} KB)`, cols)
|
|
114
|
+
process.stdout.write(`${active ? `\x1b[36m\x1b[1m${line}\x1b[0m` : line}\n`)
|
|
115
|
+
})
|
|
116
|
+
process.stdout.write('\n')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
renderMenu(true)
|
|
120
|
+
readline.emitKeypressEvents(process.stdin)
|
|
121
|
+
const wasRaw = process.stdin.isRaw
|
|
122
|
+
process.stdin.setRawMode(true)
|
|
123
|
+
process.stdin.resume()
|
|
124
|
+
|
|
125
|
+
const cleanup = () => {
|
|
126
|
+
process.stdin.removeListener('keypress', onKeypress)
|
|
127
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(Boolean(wasRaw))
|
|
128
|
+
process.stdin.pause()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const onKeypress = (str, key) => {
|
|
132
|
+
if (!key) return
|
|
133
|
+
if (key.name === 'q' || key.name === 'escape' || (key.ctrl && key.name === 'c')) {
|
|
134
|
+
cleanup()
|
|
135
|
+
resolvePromise(null)
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
if (key.name === 'up' || key.name === 'k') {
|
|
139
|
+
selected = (selected - 1 + total) % total
|
|
140
|
+
renderMenu(false)
|
|
141
|
+
} else if (key.name === 'down' || key.name === 'j') {
|
|
142
|
+
selected = (selected + 1) % total
|
|
143
|
+
renderMenu(false)
|
|
144
|
+
} else if (key.name === 'return' || key.name === 'enter') {
|
|
145
|
+
cleanup()
|
|
146
|
+
resolvePromise(sessions[selected])
|
|
147
|
+
} else if (str && /^[1-9]$/.test(str)) {
|
|
148
|
+
const idx = Number(str) - 1
|
|
149
|
+
if (idx < total) {
|
|
150
|
+
selected = idx
|
|
151
|
+
renderMenu(false)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
process.stdin.on('keypress', onKeypress)
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function main() {
|
|
161
|
+
const rawArgs = process.argv.slice(2)
|
|
162
|
+
const hasNoImages = rawArgs.includes('--no-images')
|
|
163
|
+
const hasNoServe = rawArgs.includes('--no-serve')
|
|
164
|
+
const hasServe = rawArgs.includes('--serve')
|
|
165
|
+
const hasNoOpen = rawArgs.includes('--no-open')
|
|
166
|
+
const hasIncludeMemory = rawArgs.includes('--include-memory')
|
|
167
|
+
const filteredArgs = rawArgs.filter(a => !['--no-images', '--no-serve', '--serve', '--no-open', '--include-memory'].includes(a))
|
|
168
|
+
|
|
169
|
+
const { values, positionals } = parseArgs({
|
|
170
|
+
args: filteredArgs,
|
|
171
|
+
allowPositionals: true,
|
|
172
|
+
options: {
|
|
173
|
+
out: { type: 'string', short: 'o' },
|
|
174
|
+
lang: { type: 'string', short: 'l' },
|
|
175
|
+
title: { type: 'string' },
|
|
176
|
+
desc: { type: 'string' },
|
|
177
|
+
from: { type: 'string' },
|
|
178
|
+
to: { type: 'string' },
|
|
179
|
+
'image-width': { type: 'string' },
|
|
180
|
+
clip: { type: 'string' },
|
|
181
|
+
conversation: { type: 'string' },
|
|
182
|
+
list: { type: 'boolean' },
|
|
183
|
+
port: { type: 'string', short: 'p' },
|
|
184
|
+
force: { type: 'boolean' },
|
|
185
|
+
version: { type: 'boolean', short: 'v' },
|
|
186
|
+
help: { type: 'boolean', short: 'h' },
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
if (values.version) {
|
|
191
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
192
|
+
console.log(pkg.version || '0.1.0')
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (values.help) {
|
|
197
|
+
console.log(HELP)
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const port = values.port ? Number(values.port) : 4180
|
|
202
|
+
|
|
203
|
+
// Subcommand: `encore play <dir>` or `encore preview <dir>`
|
|
204
|
+
if (positionals[0] === 'play' || positionals[0] === 'preview') {
|
|
205
|
+
const targetDir = resolve(positionals[1] || '.')
|
|
206
|
+
const rebuilt = await rebuildReplayDir(targetDir, {
|
|
207
|
+
lang: values.lang,
|
|
208
|
+
title: values.title,
|
|
209
|
+
description: values.desc,
|
|
210
|
+
})
|
|
211
|
+
printBuildReport(rebuilt)
|
|
212
|
+
const { url } = await serveReplayDir(rebuilt.dir, { port, open: !hasNoOpen })
|
|
213
|
+
console.log(`\n🎬 Encore stage live at ${url} (Ctrl+C to stop)`)
|
|
214
|
+
console.log(` Tip: Edit ${relative(process.cwd(), rebuilt.sessionFile) || 'session.json'} and refresh the browser to see changes immediately.`)
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (values.list) {
|
|
219
|
+
const recent = await scanRecentSessions({ limit: 15 })
|
|
220
|
+
if (!recent.length) {
|
|
221
|
+
console.log('No recent Codex or Claude Code sessions found in ~/.codex/sessions or ~/.claude/projects.')
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
console.log('Recent local AI Agent sessions:\n')
|
|
225
|
+
recent.forEach((s, idx) => {
|
|
226
|
+
console.log(` [${String(idx + 1).padStart(2, ' ')}] ${s.timeLabel} · ${s.toolLabel.padEnd(11)} · ${s.preview} (${s.sizeKB} KB)`)
|
|
227
|
+
console.log(` ${s.file}`)
|
|
228
|
+
})
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let targets = positionals
|
|
233
|
+
if (targets[0] === 'build' || targets[0] === 'import') {
|
|
234
|
+
targets = targets.slice(1)
|
|
235
|
+
}
|
|
236
|
+
let explicitTool
|
|
237
|
+
if (['codex', 'claude-code', 'claude-ai'].includes(targets[0]) && targets.length > 1) {
|
|
238
|
+
explicitTool = targets[0]
|
|
239
|
+
targets = targets.slice(1)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!targets.length) {
|
|
243
|
+
const recent = await scanRecentSessions({ limit: 10 })
|
|
244
|
+
if (!recent.length) {
|
|
245
|
+
console.log(HELP)
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
const picked = await pickRecentSessionInteractive(recent)
|
|
249
|
+
if (!picked) return
|
|
250
|
+
targets = [picked.file]
|
|
251
|
+
explicitTool = picked.tool
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const result = await buildReplay(targets, {
|
|
255
|
+
tool: explicitTool,
|
|
256
|
+
outDir: values.out,
|
|
257
|
+
lang: values.lang || 'auto',
|
|
258
|
+
title: values.title,
|
|
259
|
+
description: values.desc,
|
|
260
|
+
from: values.from,
|
|
261
|
+
to: values.to,
|
|
262
|
+
images: !hasNoImages,
|
|
263
|
+
imageWidth: values['image-width'] ? Number(values['image-width']) : 960,
|
|
264
|
+
clip: values.clip ? Number(values.clip) : undefined,
|
|
265
|
+
conversation: values.conversation,
|
|
266
|
+
includeMemory: hasIncludeMemory,
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
printBuildReport(result)
|
|
270
|
+
|
|
271
|
+
const shouldServe = hasServe || (!hasNoServe && Boolean(process.stdin.isTTY && process.stdout.isTTY))
|
|
272
|
+
if (shouldServe) {
|
|
273
|
+
const { url } = await serveReplayDir(result.dir, { port, open: !hasNoOpen })
|
|
274
|
+
console.log(`\n🎬 Encore stage live at ${url} (Ctrl+C to stop)`)
|
|
275
|
+
console.log(` Tip: Edit ${relative(process.cwd(), result.sessionFile) || 'session.json'} and refresh the browser to see changes immediately.`)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
main().catch(err => {
|
|
280
|
+
console.error(`\n❌ Encore error: ${err.message || err}`)
|
|
281
|
+
process.exit(1)
|
|
282
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@niracler/encore",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Bring your AI agent sessions back on stage — like asciinema, but for AI agents (Codex, Claude Code, Claude).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/niracler/encore.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/niracler/encore#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/niracler/encore/issues"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"encore": "bin/encore.mjs"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./src/index.mjs",
|
|
19
|
+
"./player.js": "./player/encore-player.js",
|
|
20
|
+
"./player.css": "./player/encore-player.css"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"bin",
|
|
24
|
+
"src",
|
|
25
|
+
"player",
|
|
26
|
+
"skills",
|
|
27
|
+
"README.md",
|
|
28
|
+
"README.zh-CN.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build:player": "node -e \"import('./src/player-assets.mjs').then(m => m.buildStandalonePlayerJs())\"",
|
|
33
|
+
"prepack": "npm run build:player",
|
|
34
|
+
"test": "node --test test/*.test.mjs"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"ai",
|
|
38
|
+
"agent",
|
|
39
|
+
"replay",
|
|
40
|
+
"session-player",
|
|
41
|
+
"codex",
|
|
42
|
+
"claude-code",
|
|
43
|
+
"context-engineering",
|
|
44
|
+
"asciinema"
|
|
45
|
+
],
|
|
46
|
+
"author": "niracler",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=20.0.0"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"sharp": "^0.35.5"
|
|
56
|
+
}
|
|
57
|
+
}
|