@niracler/encore 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/LICENSE +21 -0
- package/README.md +136 -2
- package/README.zh-CN.md +130 -0
- package/bin/encore.mjs +303 -0
- package/package.json +67 -3
- package/player/encore-player.css +734 -0
- package/player/encore-player.js +3494 -0
- package/schema/session.schema.json +193 -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 +413 -0
- package/src/common.mjs +343 -0
- package/src/detect.mjs +227 -0
- package/src/i18n.mjs +223 -0
- package/src/images.mjs +63 -0
- package/src/index.d.ts +244 -0
- package/src/index.mjs +232 -0
- package/src/markdown.mjs +173 -0
- package/src/player-assets.mjs +90 -0
- package/src/player-runtime.mjs +1327 -0
- package/src/redact.mjs +84 -0
- package/src/render.mjs +591 -0
- package/src/server.mjs +96 -0
- package/src/timeline.mjs +1167 -0
- package/src/workbuddy.mjs +47 -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,137 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./docs/hero-en.svg" alt="Encore — Curtain Call for AI Agents" width="100%">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://encore.niracler.com"><strong>Live Stage (encore.niracler.com) ↗</strong></a> ·
|
|
7
|
+
<a href="https://www.npmjs.com/package/@niracler/encore"><strong>npm ↗</strong></a> ·
|
|
8
|
+
<a href="./README.md"><strong>English</strong></a> ·
|
|
9
|
+
<a href="./README.zh-CN.md">简体中文</a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
**Encore** is the [`asciinema`](https://asciinema.org) for AI agent sessions. Instead of blurry screen recordings or flat Markdown dumps, it turns raw transcripts from **Codex**, **Claude Code**, **Claude.ai**, and **WorkBuddy** into an interactive, self-contained web stage.
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
<table>
|
|
17
|
+
<thead>
|
|
18
|
+
<tr>
|
|
19
|
+
<th width="33%" align="left">Stage Left · The Performance</th>
|
|
20
|
+
<th width="33%" align="left">Stage Right · Context X-Ray</th>
|
|
21
|
+
<th width="33%" align="left">Bottom · Milestone Timeline</th>
|
|
22
|
+
</tr>
|
|
23
|
+
</thead>
|
|
24
|
+
<tbody>
|
|
25
|
+
<tr>
|
|
26
|
+
<td valign="top">Typewriter prompt input, streaming Markdown replies, <code>12×</code> tool call shimmer, sub-agent dispatches, and inline <code>.webp</code> visual outputs.</td>
|
|
27
|
+
<td valign="top">Live <code>200k</code> / <code>1.0M</code> token gauge, 7-color bucket bar, auto-compaction headroom markers, and click-to-inspect raw payloads at any step.</td>
|
|
28
|
+
<td valign="top">Step-by-step scrubber pinned with visual keyframes (<code>🖼</code>), draft docs (<code>📄</code>), context compactions (<code>🗜</code>), and user turns (<code>💬</code>).</td>
|
|
29
|
+
</tr>
|
|
30
|
+
</tbody>
|
|
31
|
+
</table>
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 01 · Instant Curtain Call (Raw Cut)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# 1. Interactive picker — scans ~/.codex/sessions, ~/.claude/projects & ~/.workbuddy/projects
|
|
39
|
+
# Use ↑ / ↓ to select and ← / → to flip pages
|
|
40
|
+
npx @niracler/encore
|
|
41
|
+
|
|
42
|
+
# 2. Direct export — auto-detects .jsonl / .jsonl.zst / Claude.ai .json
|
|
43
|
+
npx @niracler/encore /path/to/rollout.jsonl -o ./replays/my-session
|
|
44
|
+
|
|
45
|
+
# 3. Edit ./replays/my-session/session.json and refresh the browser directly,
|
|
46
|
+
# or re-run on the folder to sync <title> and privacy checks:
|
|
47
|
+
npx @niracler/encore ./replays/my-session
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 02 · Director's Cut (Agent Curation)
|
|
53
|
+
|
|
54
|
+
Raw logs often contain 20+ repetitive screenshots, long opening prompts instead of a clear title, or internal project codenames that regex redaction cannot catch. Link [`skills/encore/SKILL.md`](./skills/encore/SKILL.md) into `.agents/skills/encore` (or `~/.codex/skills/encore` / `~/.claude/skills/encore`) and prompt your agent:
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
Use the encore skill to export my latest session and curate session.json for publishing.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- **Frame Pruning & Naming**: Visually inspects extracted `.webp` images, drops redundant screenshots, and writes concise milestone labels.
|
|
61
|
+
- **Title & Playbill Intro**: Writes a sharp `title` and a 1–3 sentence `description` summarizing the problem, pivot, and outcome.
|
|
62
|
+
- **Semantic Privacy Redaction**: Replaces internal codenames, colleague names, or private URLs with `(Internal context redacted)`.
|
|
63
|
+
- **Time-Window Trimming**: Cuts off-topic turns at the start or end of a session.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 03 · Anywhere on Stage (Zero-Dependency Embed)
|
|
68
|
+
|
|
69
|
+
Encore separates data (`session.json` + `.webp`), standalone player (`encore-player.js` + `encore-player.css`), and CLI (`encore`). Embed any replay into your blog or docs with three lines:
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<link rel="stylesheet" href="./encore-player.css">
|
|
73
|
+
<div data-encore-player src="./session.json" data-lang="en"></div>
|
|
74
|
+
<script src="./encore-player.js" defer></script>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
<details>
|
|
78
|
+
<summary><strong>CLI Options & <code>session.json</code> Reference</strong></summary>
|
|
79
|
+
|
|
80
|
+
### CLI Options
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
Usage:
|
|
84
|
+
encore Scan recent Codex, Claude Code & WorkBuddy sessions and pick one interactively
|
|
85
|
+
encore <log.jsonl | dir> [options] Build a standalone replay directory from a log or re-render an edited session.json
|
|
86
|
+
encore play <dir> [--port 4180] Start local preview server for an existing replay directory
|
|
87
|
+
|
|
88
|
+
Options:
|
|
89
|
+
-o, --out <dir> Output directory (default: ./replays/<session-slug>)
|
|
90
|
+
-l, --lang <zh|en|auto> Player UI language (default: auto; also toggleable in the topbar)
|
|
91
|
+
--title <text> Override session title
|
|
92
|
+
--desc <text> Set opening description shown before playback starts
|
|
93
|
+
--from <iso-time> Start time window filter (e.g. 2026-11-10T09:00)
|
|
94
|
+
--to <iso-time> End time window filter
|
|
95
|
+
--no-images Skip extracting embedded images to .webp
|
|
96
|
+
--image-width <px> Max width for extracted WebP frames (default: 960)
|
|
97
|
+
--clip <chars> Max chars per tool input/output (default: 1500/2000)
|
|
98
|
+
--conversation <id> Conversation UUID for multi-chat Claude.ai exports
|
|
99
|
+
--include-memory Include full cross-session MEMORY_SUMMARY / User CLAUDE.md text
|
|
100
|
+
--list List recent local sessions without interactive prompt
|
|
101
|
+
--serve Start local HTTP preview server after building
|
|
102
|
+
--no-serve Do not start local HTTP preview server
|
|
103
|
+
--no-open Do not automatically open browser when serving
|
|
104
|
+
-p, --port <number> Preview server port (default: 4180)
|
|
105
|
+
-v, --version Show version number
|
|
106
|
+
-h, --help Show help message
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `session.json` Schema
|
|
110
|
+
|
|
111
|
+
Formal JSON Schema: [`schema/session.schema.json`](./schema/session.schema.json) (`https://encore.niracler.com/schema/session.schema.json`) · TypeScript Definitions: [`src/index.d.ts`](./src/index.d.ts)
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"$schema": "https://encore.niracler.com/schema/session.schema.json",
|
|
116
|
+
"tool": "codex",
|
|
117
|
+
"model": "gpt-5.4",
|
|
118
|
+
"title": "Redesigning the 7-Stage Architecture Diagram",
|
|
119
|
+
"description": "Started with a cluttered layout, pivoted to a two-column grid after visual review, and exported the final SVG.",
|
|
120
|
+
"lang": "en",
|
|
121
|
+
"contextWindow": 258400,
|
|
122
|
+
"deliverables": [{ "title": "Final Diagram", "href": "./final-diagram.webp", "meta": "SVG / WebP · 1920×1080" }],
|
|
123
|
+
"frames": [{ "time": "2026-11-17T10:04:12.000Z", "img": "a1b2c3d4e5f6.webp", "who": "ai", "label": "Draft 1", "w": 960, "h": 540 }],
|
|
124
|
+
"items": [
|
|
125
|
+
{ "type": "user", "text": "...", "time": "..." },
|
|
126
|
+
{ "type": "tool", "name": "exec_command", "summary": "...", "stats": { "command": 1 }, "time": "..." },
|
|
127
|
+
{ "type": "compact", "seq": 1, "trigger": "auto", "preTokens": 210000, "postTokens": 42000, "time": "..." },
|
|
128
|
+
{ "type": "assistant", "text": "...", "time": "..." }
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
</details>
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
[MIT](./LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./docs/hero-zh.svg" alt="Encore — AI Agent 会话返场剧场" width="100%">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://encore.niracler.com"><strong>在线剧场 (encore.niracler.com) ↗</strong></a> ·
|
|
7
|
+
<a href="https://www.npmjs.com/package/@niracler/encore"><strong>npm ↗</strong></a> ·
|
|
8
|
+
<a href="./README.md">English</a> ·
|
|
9
|
+
<a href="./README.zh-CN.md"><strong>简体中文</strong></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
**Encore** 是面向 AI Agent 时代的 [`asciinema`](https://asciinema.org)。告别又糊又大的录屏视频与干瘪的 Markdown 聊天记录,将 **Codex**、**Claude Code**、**Claude.ai** 与 **WorkBuddy** 的原始会话日志,一键搬上可交互的独立网页舞台。
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
<table>
|
|
17
|
+
<thead>
|
|
18
|
+
<tr>
|
|
19
|
+
<th width="33%" align="left">左屏 · 舞台实况</th>
|
|
20
|
+
<th width="33%" align="left">右屏 · 上下文透视</th>
|
|
21
|
+
<th width="33%" align="left">底部 · 关键帧时间轴</th>
|
|
22
|
+
</tr>
|
|
23
|
+
</thead>
|
|
24
|
+
<tbody>
|
|
25
|
+
<tr>
|
|
26
|
+
<td valign="top">输入框打字上屏、Markdown 呼吸流式回复、<code>12×</code> 工具调用流光快切、子代理派发报告与 <code>.webp</code> 过程效果图演进。</td>
|
|
27
|
+
<td valign="top">实时显示 <code>200k</code> / <code>1.0M</code> 上下文水位、7 色分段进度条与压缩警戒线,点击任意色块或消息即可定格查看当时的原文载荷。</td>
|
|
28
|
+
<td valign="top">按步切分的进度条,自动钉出过程效果图(<code>🖼</code>)、中间文稿(<code>📄</code>)、上下文压缩(<code>🗜</code>)与提问节点(<code>💬</code>)。</td>
|
|
29
|
+
</tr>
|
|
30
|
+
</tbody>
|
|
31
|
+
</table>
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 01 · 即兴返场(生肉直出)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# 1. 交互式选片 —— 自动扫描 ~/.codex/sessions、~/.claude/projects 与 ~/.workbuddy/projects
|
|
39
|
+
# 按 ↑ / ↓ 选择会话,← / → 翻页
|
|
40
|
+
npx @niracler/encore
|
|
41
|
+
|
|
42
|
+
# 2. 指定日志直出 —— 自动识别 .jsonl / .jsonl.zst / Claude.ai .json
|
|
43
|
+
npx @niracler/encore /path/to/rollout.jsonl -o ./replays/my-session
|
|
44
|
+
|
|
45
|
+
# 3. 直接手改 ./replays/my-session/session.json 并刷新浏览器即可生效;
|
|
46
|
+
# 对目录重跑命令可同步更新 <title> 并重新执行隐私检查:
|
|
47
|
+
npx @niracler/encore ./replays/my-session
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 02 · 导演剪辑版(Agent 策展精修)
|
|
53
|
+
|
|
54
|
+
脚本一步导出的原始回放往往夹杂着几十张重复微调或报错截图,标题也只是第一句长提问。将 [`skills/encore/SKILL.md`](./skills/encore/SKILL.md) 放入 `.agents/skills/encore`(或 `~/.codex/skills/encore` / `~/.claude/skills/encore`),直接对 Agent 说:
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
用 encore 技能把我刚才那段对话导出并精修一下。
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- **看图筛片与命名**:多模态逐张检查 `.webp`,剔除报错图与重复微调图,为关键演进节点写好清晰的 `label`。
|
|
61
|
+
- **提炼标题与报幕导读**:在 `session.json` 顶层写出直奔主题的 `title` 与几十字的 `description` 开场脉络。
|
|
62
|
+
- **语义级隐私清理**:识别正则抓不到的内部代号、同事姓名或内网地址,替换为 `(涉及内部业务细节,已略去)`。
|
|
63
|
+
- **时间窗口切片**:掐掉会话首尾顺手聊的无关话题,只留完整讲好一件事的片段。
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 03 · 随处搭台(零依赖嵌入)
|
|
68
|
+
|
|
69
|
+
Encore 将数据(`session.json` + `.webp`)、纯前端播放器(`encore-player.js` + `encore-player.css`)与 CLI(`encore`)完全解耦。只需 3 行代码即可在任意博客或文档站搭起回放舞台:
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<link rel="stylesheet" href="./encore-player.css">
|
|
73
|
+
<div data-encore-player src="./session.json" data-lang="zh"></div>
|
|
74
|
+
<script src="./encore-player.js" defer></script>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
<details>
|
|
78
|
+
<summary><strong>CLI 参数与 <code>session.json</code> 结构速查</strong></summary>
|
|
79
|
+
|
|
80
|
+
### CLI 参数
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
用法:
|
|
84
|
+
encore 扫描本机最近的 Codex、Claude Code 与 WorkBuddy 会话,上下键选择导出
|
|
85
|
+
encore <log.jsonl | dir> [options] 从原始日志一步生成回放目录,或对已修改的目录重新同步
|
|
86
|
+
encore play <dir> [--port 4180] 启动本地预览服务
|
|
87
|
+
|
|
88
|
+
常用参数:
|
|
89
|
+
-o, --out <dir> 输出目录(默认:./replays/<会话短名>)
|
|
90
|
+
-l, --lang <zh|en|auto> 界面语言(默认:auto,网页右上角也可一键切换)
|
|
91
|
+
--title <text> 自定义回放标题
|
|
92
|
+
--desc <text> 自定义开场导读说明
|
|
93
|
+
--from <iso-time> 起始时间切片(如 2026-11-10T09:00)
|
|
94
|
+
--to <iso-time> 结束时间切片
|
|
95
|
+
--no-images 不提取内嵌图片
|
|
96
|
+
--include-memory 保留完整的跨会话 MEMORY_SUMMARY / 用户级 CLAUDE.md 原文(默认自动折叠脱敏)
|
|
97
|
+
--list 仅列出本机最近会话,不进入交互菜单
|
|
98
|
+
--no-serve 生成文件后直接退出,不启动本地预览服务
|
|
99
|
+
-v, --version 显示版本号
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `session.json` 核心字段
|
|
103
|
+
|
|
104
|
+
JSON Schema 规范:[`schema/session.schema.json`](./schema/session.schema.json)(`https://encore.niracler.com/schema/session.schema.json`)· TypeScript 类型声明:[`src/index.d.ts`](./src/index.d.ts)
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"$schema": "https://encore.niracler.com/schema/session.schema.json",
|
|
109
|
+
"tool": "codex",
|
|
110
|
+
"model": "gpt-5.4",
|
|
111
|
+
"title": "定下像素风和红发主角·课程海报视觉探索",
|
|
112
|
+
"description": "从信息过载的第一版草图出发,确立三阶段路线图,最终定版像素风课程海报。",
|
|
113
|
+
"lang": "zh",
|
|
114
|
+
"contextWindow": 258400,
|
|
115
|
+
"deliverables": [{ "title": "定版课程海报", "href": "./final-poster.webp", "meta": "WebP · 1920×1080" }],
|
|
116
|
+
"frames": [{ "time": "2026-11-17T10:04:12.000Z", "img": "a1b2c3d4e5f6.webp", "who": "ai", "label": "像素风草图", "w": 960, "h": 540 }],
|
|
117
|
+
"items": [
|
|
118
|
+
{ "type": "user", "text": "...", "time": "..." },
|
|
119
|
+
{ "type": "tool", "name": "exec_command", "summary": "...", "stats": { "command": 1 }, "time": "..." },
|
|
120
|
+
{ "type": "compact", "seq": 1, "trigger": "auto", "preTokens": 210000, "postTokens": 42000, "time": "..." },
|
|
121
|
+
{ "type": "assistant", "text": "...", "time": "..." }
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
</details>
|
|
127
|
+
|
|
128
|
+
## 开源协议
|
|
129
|
+
|
|
130
|
+
[MIT](./LICENSE)
|
package/bin/encore.mjs
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { on } from 'node:events'
|
|
4
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import { parseArgs } from 'node:util'
|
|
7
|
+
import readline from 'node:readline'
|
|
8
|
+
import { iterateRecentSessions } from '../src/detect.mjs'
|
|
9
|
+
import {
|
|
10
|
+
buildReplay,
|
|
11
|
+
rebuildReplayDir,
|
|
12
|
+
scanRecentSessions,
|
|
13
|
+
serveReplayDir,
|
|
14
|
+
} from '../src/index.mjs'
|
|
15
|
+
|
|
16
|
+
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json')
|
|
17
|
+
|
|
18
|
+
const HELP = `
|
|
19
|
+
encore (@niracler/encore) — Bring your AI agent sessions back on stage.
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
encore Scan recent Codex, Claude Code & WorkBuddy sessions and pick one interactively
|
|
23
|
+
encore <log.jsonl | dir> [options] Build a standalone replay directory from a log or re-render an edited session.json
|
|
24
|
+
encore play <dir> [--port 4180] Start local preview server for an existing replay directory
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
-o, --out <dir> Output directory (default: ./replays/<session-slug>)
|
|
28
|
+
-l, --lang <zh|en|auto> Player UI language (default: auto)
|
|
29
|
+
--title <text> Override session title
|
|
30
|
+
--desc <text> Set opening description shown before playback starts
|
|
31
|
+
--from <iso-time> Start time window filter (e.g. 2026-11-10T09:00)
|
|
32
|
+
--to <iso-time> End time window filter
|
|
33
|
+
--no-images Skip extracting embedded images to .webp
|
|
34
|
+
--image-width <px> Max width for extracted WebP frames (default: 960)
|
|
35
|
+
--clip <chars> Max chars per tool input/output (default: 1500/2000)
|
|
36
|
+
--conversation <id> Conversation UUID for multi-chat Claude.ai exports
|
|
37
|
+
--include-memory Include full cross-session MEMORY_SUMMARY / User CLAUDE.md text
|
|
38
|
+
--list List recent local sessions without interactive prompt
|
|
39
|
+
--serve Start local HTTP preview server after building
|
|
40
|
+
--no-serve Do not start local HTTP preview server
|
|
41
|
+
--no-open Do not automatically open browser when serving
|
|
42
|
+
-p, --port <number> Preview server port (default: 4180)
|
|
43
|
+
-v, --version Show version number
|
|
44
|
+
-h, --help Show this help message
|
|
45
|
+
`.trim()
|
|
46
|
+
|
|
47
|
+
function printBuildReport(result) {
|
|
48
|
+
const { mode, toolLabel, dir, sessionFile, session, leaks } = result
|
|
49
|
+
const relDir = relative(process.cwd(), dir) || '.'
|
|
50
|
+
const relSession = relative(process.cwd(), sessionFile) || 'session.json'
|
|
51
|
+
const count = type => (session.items || []).filter(item => item.type === type).length
|
|
52
|
+
const framesCount = (session.frames || []).length
|
|
53
|
+
const action = mode === 'rebuild' ? 'Re-rendered' : 'Generated'
|
|
54
|
+
|
|
55
|
+
console.log(`\n✨ ${action} replay in ${relDir}/`)
|
|
56
|
+
console.log(` Title : ${session.title}`)
|
|
57
|
+
console.log(` Agent : ${toolLabel}${session.model ? ` · ${session.model}` : ''}`)
|
|
58
|
+
console.log(` Steps : ${count('user')} prompts · ${count('assistant')} replies · ${count('tool')} tool calls${count('compact') ? ` · ${count('compact')} compactions` : ''}`)
|
|
59
|
+
if (framesCount) {
|
|
60
|
+
console.log(` Frames : ${framesCount} WebP image(s) in frames[] (edit ${relSession} to prune or rename labels)`)
|
|
61
|
+
}
|
|
62
|
+
console.log(` Files : index.html, session.json, encore-player.js, encore-player.css`)
|
|
63
|
+
|
|
64
|
+
if (leaks.length) {
|
|
65
|
+
console.log(`\n⚠️ Privacy check found ${leaks.length} potential sensitive snippet(s) (non-blocking — review in ${relSession}):`)
|
|
66
|
+
for (const leak of leaks.slice(0, 12)) {
|
|
67
|
+
console.log(` - ${leak.path} · ${leak.rule} · ${leak.match}`)
|
|
68
|
+
}
|
|
69
|
+
if (leaks.length > 12) {
|
|
70
|
+
console.log(` ... and ${leaks.length - 12} more`)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function truncateToColumns(str, maxCols) {
|
|
76
|
+
let width = 0
|
|
77
|
+
let out = ''
|
|
78
|
+
for (const ch of String(str)) {
|
|
79
|
+
const code = ch.codePointAt(0)
|
|
80
|
+
const w = code > 0x1f00 ? 2 : 1
|
|
81
|
+
if (width + w > maxCols - 1) return `${out}…`
|
|
82
|
+
out += ch
|
|
83
|
+
width += w
|
|
84
|
+
}
|
|
85
|
+
return out
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function pickRecentSessionInteractive() {
|
|
89
|
+
const pageSize = 10
|
|
90
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
91
|
+
const sessions = await scanRecentSessions({ limit: pageSize })
|
|
92
|
+
if (!sessions.length) {
|
|
93
|
+
console.log(HELP)
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
console.log('Recent local AI Agent sessions:\n')
|
|
97
|
+
sessions.forEach((s, idx) => {
|
|
98
|
+
console.log(` [${idx + 1}] ${s.timeLabel} · ${s.toolLabel.padEnd(11)} · ${s.preview}`)
|
|
99
|
+
console.log(` ${s.file} (${s.sizeKB} KB)`)
|
|
100
|
+
})
|
|
101
|
+
console.log('\nRun: encore <file-path> -o ./replays/my-session')
|
|
102
|
+
return null
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const history = iterateRecentSessions()
|
|
106
|
+
const sessions = []
|
|
107
|
+
let exhausted = false
|
|
108
|
+
let selected = 0
|
|
109
|
+
let renderedLines = 0
|
|
110
|
+
|
|
111
|
+
async function loadPage(start) {
|
|
112
|
+
while (!exhausted && sessions.length <= start + pageSize) {
|
|
113
|
+
const next = await history.next()
|
|
114
|
+
if (next.done) exhausted = true
|
|
115
|
+
else sessions.push(next.value)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
await loadPage(0)
|
|
120
|
+
if (!sessions.length) {
|
|
121
|
+
console.log(HELP)
|
|
122
|
+
return null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function renderMenu(start) {
|
|
126
|
+
if (renderedLines) {
|
|
127
|
+
readline.moveCursor(process.stdout, 0, -renderedLines)
|
|
128
|
+
readline.clearScreenDown(process.stdout)
|
|
129
|
+
}
|
|
130
|
+
const cols = Math.max(1, (process.stdout.columns || 80) - 2)
|
|
131
|
+
const page = sessions.slice(start, start + pageSize)
|
|
132
|
+
const last = exhausted && start + pageSize >= sessions.length
|
|
133
|
+
const heading = `Page ${start / pageSize + 1}${last ? ' (last)' : ''} · ←/→ page · ↑/↓ move · Enter select · q quit`
|
|
134
|
+
process.stdout.write(`${truncateToColumns(heading, cols)}\n\n`)
|
|
135
|
+
page.forEach((session, index) => {
|
|
136
|
+
const active = start + index === selected
|
|
137
|
+
const prefix = active ? ' ❯ ' : ' '
|
|
138
|
+
const num = String(index + 1).padStart(2, ' ')
|
|
139
|
+
const badge = `[${session.toolLabel}]`.padEnd(13, ' ')
|
|
140
|
+
const line = truncateToColumns(`${prefix}${num}. ${session.timeLabel} ${badge} ${session.preview} (${session.sizeKB} KB)`, cols)
|
|
141
|
+
process.stdout.write(`${active ? `\x1b[36m\x1b[1m${line}\x1b[0m` : line}\n`)
|
|
142
|
+
})
|
|
143
|
+
process.stdout.write('\n')
|
|
144
|
+
renderedLines = page.length + 3
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
readline.emitKeypressEvents(process.stdin)
|
|
148
|
+
const wasRaw = process.stdin.isRaw
|
|
149
|
+
process.stdin.setRawMode(true)
|
|
150
|
+
try {
|
|
151
|
+
let start = 0
|
|
152
|
+
renderMenu(start)
|
|
153
|
+
for await (const [str, key] of on(process.stdin, 'keypress')) {
|
|
154
|
+
if (key.name === 'q' || key.name === 'escape' || (key.ctrl && key.name === 'c')) {
|
|
155
|
+
return null
|
|
156
|
+
}
|
|
157
|
+
if (key.name === 'return' || key.name === 'enter') return sessions[selected]
|
|
158
|
+
if (key.name === 'left' || key.name === 'pageup') {
|
|
159
|
+
if (!start) continue
|
|
160
|
+
selected = start - pageSize
|
|
161
|
+
} else if (key.name === 'right' || key.name === 'pagedown') {
|
|
162
|
+
if (start + pageSize >= sessions.length) continue
|
|
163
|
+
selected = start + pageSize
|
|
164
|
+
} else if (key.name === 'up' || key.name === 'k') {
|
|
165
|
+
selected = Math.max(0, selected - 1)
|
|
166
|
+
} else if (key.name === 'down' || key.name === 'j') {
|
|
167
|
+
selected = Math.min(sessions.length - 1, selected + 1)
|
|
168
|
+
} else if (/^\d$/.test(str)) {
|
|
169
|
+
const index = start + (Number(str) || pageSize) - 1
|
|
170
|
+
if (index >= sessions.length) continue
|
|
171
|
+
selected = index
|
|
172
|
+
} else {
|
|
173
|
+
continue
|
|
174
|
+
}
|
|
175
|
+
start = Math.floor(selected / pageSize) * pageSize
|
|
176
|
+
await loadPage(start)
|
|
177
|
+
renderMenu(start)
|
|
178
|
+
}
|
|
179
|
+
} finally {
|
|
180
|
+
process.stdin.setRawMode(Boolean(wasRaw))
|
|
181
|
+
process.stdin.pause()
|
|
182
|
+
await history.return()
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function main() {
|
|
187
|
+
const rawArgs = process.argv.slice(2)
|
|
188
|
+
const hasNoImages = rawArgs.includes('--no-images')
|
|
189
|
+
const hasNoServe = rawArgs.includes('--no-serve')
|
|
190
|
+
const hasServe = rawArgs.includes('--serve')
|
|
191
|
+
const hasNoOpen = rawArgs.includes('--no-open')
|
|
192
|
+
const hasIncludeMemory = rawArgs.includes('--include-memory')
|
|
193
|
+
const filteredArgs = rawArgs.filter(a => !['--no-images', '--no-serve', '--serve', '--no-open', '--include-memory'].includes(a))
|
|
194
|
+
|
|
195
|
+
const { values, positionals } = parseArgs({
|
|
196
|
+
args: filteredArgs,
|
|
197
|
+
allowPositionals: true,
|
|
198
|
+
options: {
|
|
199
|
+
out: { type: 'string', short: 'o' },
|
|
200
|
+
lang: { type: 'string', short: 'l' },
|
|
201
|
+
title: { type: 'string' },
|
|
202
|
+
desc: { type: 'string' },
|
|
203
|
+
from: { type: 'string' },
|
|
204
|
+
to: { type: 'string' },
|
|
205
|
+
'image-width': { type: 'string' },
|
|
206
|
+
clip: { type: 'string' },
|
|
207
|
+
conversation: { type: 'string' },
|
|
208
|
+
list: { type: 'boolean' },
|
|
209
|
+
port: { type: 'string', short: 'p' },
|
|
210
|
+
force: { type: 'boolean' },
|
|
211
|
+
version: { type: 'boolean', short: 'v' },
|
|
212
|
+
help: { type: 'boolean', short: 'h' },
|
|
213
|
+
},
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
if (values.version) {
|
|
217
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
218
|
+
console.log(pkg.version || '0.1.0')
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (values.help) {
|
|
223
|
+
console.log(HELP)
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const port = values.port ? Number(values.port) : 4180
|
|
228
|
+
|
|
229
|
+
// Subcommand: `encore play <dir>` or `encore preview <dir>`
|
|
230
|
+
if (positionals[0] === 'play' || positionals[0] === 'preview') {
|
|
231
|
+
const targetDir = resolve(positionals[1] || '.')
|
|
232
|
+
const rebuilt = await rebuildReplayDir(targetDir, {
|
|
233
|
+
lang: values.lang,
|
|
234
|
+
title: values.title,
|
|
235
|
+
description: values.desc,
|
|
236
|
+
})
|
|
237
|
+
printBuildReport(rebuilt)
|
|
238
|
+
const { url } = await serveReplayDir(rebuilt.dir, { port, open: !hasNoOpen })
|
|
239
|
+
console.log(`\n🎬 Encore stage live at ${url} (Ctrl+C to stop)`)
|
|
240
|
+
console.log(` Tip: Edit ${relative(process.cwd(), rebuilt.sessionFile) || 'session.json'} and refresh the browser to see changes immediately.`)
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (values.list) {
|
|
245
|
+
const recent = await scanRecentSessions({ limit: 15 })
|
|
246
|
+
if (!recent.length) {
|
|
247
|
+
console.log('No recent Codex, Claude Code, or WorkBuddy sessions found in ~/.codex/sessions, ~/.claude/projects, or ~/.workbuddy/projects.')
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
console.log('Recent local AI Agent sessions:\n')
|
|
251
|
+
recent.forEach((s, idx) => {
|
|
252
|
+
console.log(` [${String(idx + 1).padStart(2, ' ')}] ${s.timeLabel} · ${s.toolLabel.padEnd(11)} · ${s.preview} (${s.sizeKB} KB)`)
|
|
253
|
+
console.log(` ${s.file}`)
|
|
254
|
+
})
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
let targets = positionals
|
|
259
|
+
if (targets[0] === 'build' || targets[0] === 'import') {
|
|
260
|
+
targets = targets.slice(1)
|
|
261
|
+
}
|
|
262
|
+
let explicitTool
|
|
263
|
+
if (['codex', 'claude-code', 'claude-ai', 'workbuddy'].includes(targets[0]) && targets.length > 1) {
|
|
264
|
+
explicitTool = targets[0]
|
|
265
|
+
targets = targets.slice(1)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (!targets.length) {
|
|
269
|
+
const picked = await pickRecentSessionInteractive()
|
|
270
|
+
if (!picked) return
|
|
271
|
+
targets = [picked.file]
|
|
272
|
+
explicitTool = picked.tool
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const result = await buildReplay(targets, {
|
|
276
|
+
tool: explicitTool,
|
|
277
|
+
outDir: values.out,
|
|
278
|
+
lang: values.lang || 'auto',
|
|
279
|
+
title: values.title,
|
|
280
|
+
description: values.desc,
|
|
281
|
+
from: values.from,
|
|
282
|
+
to: values.to,
|
|
283
|
+
images: !hasNoImages,
|
|
284
|
+
imageWidth: values['image-width'] ? Number(values['image-width']) : 960,
|
|
285
|
+
clip: values.clip ? Number(values.clip) : undefined,
|
|
286
|
+
conversation: values.conversation,
|
|
287
|
+
includeMemory: hasIncludeMemory,
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
printBuildReport(result)
|
|
291
|
+
|
|
292
|
+
const shouldServe = hasServe || (!hasNoServe && Boolean(process.stdin.isTTY && process.stdout.isTTY))
|
|
293
|
+
if (shouldServe) {
|
|
294
|
+
const { url } = await serveReplayDir(result.dir, { port, open: !hasNoOpen })
|
|
295
|
+
console.log(`\n🎬 Encore stage live at ${url} (Ctrl+C to stop)`)
|
|
296
|
+
console.log(` Tip: Edit ${relative(process.cwd(), result.sessionFile) || 'session.json'} and refresh the browser to see changes immediately.`)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
main().catch(err => {
|
|
301
|
+
console.error(`\n❌ Encore error: ${err.message || err}`)
|
|
302
|
+
process.exit(1)
|
|
303
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@niracler/encore",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A curtain call for your AI agent runs. Replay Codex, Claude Code, Claude.ai, and WorkBuddy sessions as an interactive web stage with a live context-window inspector.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/niracler/encore.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://encore.niracler.com",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/niracler/encore/issues"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"encore": "bin/encore.mjs"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./src/index.d.ts",
|
|
21
|
+
"default": "./src/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./player.js": "./player/encore-player.js",
|
|
24
|
+
"./player.css": "./player/encore-player.css",
|
|
25
|
+
"./session.schema.json": "./schema/session.schema.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"bin",
|
|
29
|
+
"src",
|
|
30
|
+
"player/encore-player.js",
|
|
31
|
+
"player/encore-player.css",
|
|
32
|
+
"schema",
|
|
33
|
+
"skills",
|
|
34
|
+
"README.md",
|
|
35
|
+
"README.zh-CN.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"keywords": [
|
|
39
|
+
"ai",
|
|
40
|
+
"agent",
|
|
41
|
+
"replay",
|
|
42
|
+
"session-player",
|
|
43
|
+
"codex",
|
|
44
|
+
"claude-code",
|
|
45
|
+
"workbuddy",
|
|
46
|
+
"context-engineering",
|
|
47
|
+
"asciinema"
|
|
48
|
+
],
|
|
49
|
+
"author": "niracler",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=20.10.0"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"sharp": "^0.35.5"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@playwright/test": "1.65.1"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build:player": "node -e \"import('./src/player-assets.mjs').then(m => m.buildStandalonePlayerJs())\"",
|
|
65
|
+
"build:site": "node scripts/build-site.mjs",
|
|
66
|
+
"pretest": "npm run build:player",
|
|
67
|
+
"release": "pnpm publish && git push origin main --follow-tags && gh release create \"v$(node -p \"require('./package.json').version\")\" --generate-notes",
|
|
68
|
+
"test": "node --test test/*.test.mjs"
|
|
69
|
+
}
|
|
6
70
|
}
|