codex-snapshots 0.1.0 → 0.1.1

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.
Files changed (51) hide show
  1. package/README.md +101 -6
  2. package/bin/codex-snapshot.mjs +1 -6326
  3. package/deploy/aliyun/README.md +311 -0
  4. package/deploy/aliyun/backup-share-data.sh +109 -0
  5. package/deploy/aliyun/check-ecs-status.sh +149 -0
  6. package/deploy/aliyun/codex-snapshot-share.env.example +29 -0
  7. package/deploy/aliyun/codex-snapshot-share.service +26 -0
  8. package/deploy/aliyun/configure-github-pages-api.sh +141 -0
  9. package/deploy/aliyun/configure-local-publisher.sh +197 -0
  10. package/deploy/aliyun/deploy-to-ecs.sh +669 -0
  11. package/deploy/aliyun/deploy.env.example +52 -0
  12. package/deploy/aliyun/doctor.mjs +398 -0
  13. package/deploy/aliyun/install-share-api.sh +252 -0
  14. package/deploy/aliyun/install-system-deps.sh +84 -0
  15. package/deploy/aliyun/nginx-codex-snapshots.bootstrap.conf +34 -0
  16. package/deploy/aliyun/nginx-codex-snapshots.conf +52 -0
  17. package/deploy/aliyun/preflight.mjs +321 -0
  18. package/deploy/aliyun/restore-share-data.sh +141 -0
  19. package/deploy/aliyun/verify-public-share.mjs +404 -0
  20. package/dist/cli/codex-snapshot.mjs +2654 -0
  21. package/dist/core/privacy.js +81 -0
  22. package/dist/core/snapshot.js +1 -0
  23. package/dist/renderers/markdown.mjs +81 -0
  24. package/dist/renderers/transcript.js +195 -0
  25. package/dist/server/http.js +10 -0
  26. package/dist/server/local-security.js +66 -0
  27. package/dist/server/local-viewer-app.mjs +1670 -0
  28. package/dist/server/local-viewer.mjs +210 -0
  29. package/dist/server/share-api.mjs +1149 -0
  30. package/dist/server/share-store.js +136 -0
  31. package/dist/shared/sanitize.js +126 -0
  32. package/dist/shared/transcript.js +1 -0
  33. package/dist/sources/index.mjs +2 -0
  34. package/dist/sources/local-history.mjs +2221 -0
  35. package/package.json +42 -14
  36. package/scripts/build-site.mjs +71 -0
  37. package/scripts/launch-agent.mjs +19 -227
  38. package/scripts/serve-site.mjs +2 -2
  39. package/scripts/test-aliyun-deploy-config.sh +230 -0
  40. package/scripts/test-share-api.mjs +967 -0
  41. package/scripts/test-site-config.mjs +100 -0
  42. package/scripts/test-static-site.mjs +403 -0
  43. package/scripts/write-site-config.mjs +161 -0
  44. package/server/share-api.mjs +1 -771
  45. package/site/assets/config.js +3 -0
  46. package/site/assets/share.js +43 -106
  47. package/site/assets/site.css +3 -605
  48. package/site/assets/site.js +15 -92
  49. package/site/favicon.svg +7 -0
  50. package/site/index.html +3 -83
  51. package/site/share/index.html +3 -8
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ## 快速开始
10
10
 
11
- 不需要克隆仓库,可以直接通过 npm 临时运行:
11
+ 临时审阅适合偶尔查看一次会话快照,不需要克隆仓库,可以直接通过已发布的 npm 包启动本地查看器。命令运行期间 4321 端口可用,关闭终端或停止进程后服务就会结束:
12
12
 
13
13
  ```bash
14
14
  npx codex-snapshots@latest serve --port 4321
@@ -16,19 +16,28 @@ npx codex-snapshots@latest serve --port 4321
16
16
 
17
17
  打开 <http://127.0.0.1:4321/>。
18
18
 
19
- 也可以全局安装:
19
+ 也可以全局安装 npm 包后手动启动:
20
20
 
21
21
  ```bash
22
22
  npm install -g codex-snapshots
23
23
  codex-snapshot serve --port 4321
24
24
  ```
25
25
 
26
+ 如果需要在 macOS 登录后自动保持查看器可用,全局安装 npm 包后可以注册为用户级 LaunchAgent。安装完成后服务会在后台监听 4321,直到你卸载 daemon 或停止服务:
27
+
28
+ ```bash
29
+ npm install -g codex-snapshots
30
+ codex-snapshot daemon install
31
+ codex-snapshot daemon status
32
+ ```
33
+
26
34
  要求 Node.js 18 或更高版本。
27
35
 
28
36
  ## 从源码运行
29
37
 
30
38
  ```bash
31
39
  pnpm install
40
+ pnpm build
32
41
  pnpm dev
33
42
  ```
34
43
 
@@ -37,10 +46,11 @@ pnpm dev
37
46
  如果想在本地预览公开静态网站:
38
47
 
39
48
  ```bash
49
+ pnpm build:site
40
50
  pnpm site:dev
41
51
  ```
42
52
 
43
- 打开 <http://127.0.0.1:4323/>。
53
+ 打开 <http://127.0.0.1:4322/>。
44
54
 
45
55
  ## 命令行
46
56
 
@@ -75,7 +85,7 @@ pnpm snapshot record-trae --port 4732
75
85
 
76
86
  ## 云端分享服务
77
87
 
78
- 启动可选的分享 API:
88
+ 启动可选的分享 API。未配置 GitHub OAuth 时,可以继续用本地/兼容模式的分享 token
79
89
 
80
90
  ```bash
81
91
  SNAPSHOT_SHARE_TOKEN=change-me codex-snapshot-share
@@ -94,7 +104,29 @@ npx -p codex-snapshots@latest codex-snapshot-share
94
104
  SNAPSHOT_SHARE_TOKEN=change-me pnpm share:server
95
105
  ```
96
106
 
97
- 发布已脱敏的快照:
107
+ 生产公网分享建议改用 GitHub OAuth。先在 GitHub OAuth App 中配置 callback URL:
108
+
109
+ ```text
110
+ https://your-share-api.example.com/api/auth/github/callback
111
+ ```
112
+
113
+ 然后启动分享 API:
114
+
115
+ ```bash
116
+ SNAPSHOT_GITHUB_CLIENT_ID=your-client-id \
117
+ SNAPSHOT_GITHUB_CLIENT_SECRET=your-client-secret \
118
+ SNAPSHOT_SESSION_SECRET="$(openssl rand -base64 48)" \
119
+ SNAPSHOT_GITHUB_OWNER_LOGIN=your-github-login \
120
+ SNAPSHOT_SHARE_SITE_URL=https://ffffhx.github.io/codex-snapshots/ \
121
+ SNAPSHOT_SHARE_PUBLIC_API_URL=https://your-share-api.example.com \
122
+ SNAPSHOT_SHARE_VIEWER_PATH=/share/ \
123
+ SNAPSHOT_SHARE_ALLOW_ANONYMOUS=false \
124
+ codex-snapshot-share
125
+ ```
126
+
127
+ 配置 GitHub OAuth 后,发布和删除都需要 GitHub 登录:发布记录会保存发布者 GitHub 账号,站长账号可以删除任何分享,其他用户只能删除自己发布的分享。旧的 `SNAPSHOT_SHARE_TOKEN` 只在未启用 GitHub OAuth 时默认生效。
128
+
129
+ 兼容模式下也可以从命令行发布已脱敏的快照:
98
130
 
99
131
  ```bash
100
132
  SNAPSHOT_SHARE_TOKEN=change-me \
@@ -105,9 +137,72 @@ codex-snapshot publish <session-id> \
105
137
 
106
138
  服务端默认把分享内容保存在 `.codex-snapshots/shares.json`。如果需要使用其他路径,可以配置 `SNAPSHOT_SHARE_DATA_FILE`。
107
139
 
140
+ 公开列表接口会返回最近发布的分享摘要,不包含完整会话内容:
141
+
142
+ ```bash
143
+ curl http://127.0.0.1:8787/api/snapshots
144
+ ```
145
+
146
+ 兼容模式下删除已发布的分享快照需要同一个分享 token:
147
+
148
+ ```bash
149
+ curl -X DELETE \
150
+ -H "Authorization: Bearer change-me" \
151
+ http://127.0.0.1:8787/api/snapshots/snap_...
152
+ ```
153
+
154
+ 官网首页会使用同一个分享 API 地址展示“公开 Session”卡片列表。启用 GitHub OAuth 后,首页会显示 GitHub 登录状态,并只给站长或分享发布者显示删除入口。
155
+
156
+ 如果要让发布的 Session 出现在公开官网上,需要把分享 API 部署到公网,并让 GitHub Pages 默认读取这个公网 API。`127.0.0.1` 只对本机可见,不能作为公开分享地址。
157
+
158
+ 公网分享服务至少需要配置:
159
+
160
+ ```bash
161
+ SNAPSHOT_SHARE_SITE_URL=https://ffffhx.github.io/codex-snapshots/ \
162
+ SNAPSHOT_SHARE_PUBLIC_API_URL=https://your-share-api.example.com \
163
+ SNAPSHOT_SHARE_VIEWER_PATH=/share/ \
164
+ codex-snapshot-share
165
+ ```
166
+
167
+ 然后在 GitHub 仓库变量中设置:
168
+
169
+ ```text
170
+ CODEX_SNAPSHOTS_PUBLIC_API_URL=https://your-share-api.example.com
171
+ ```
172
+
173
+ Pages 部署时会写入 `site/assets/config.js`,官网首页和 `/share/` 页面会默认读取这个公网 API。发布时本地查看器也需要指向同一个公网 API,可以写入本地发布配置:
174
+
175
+ ```bash
176
+ SNAPSHOT_SHARE_API_URL=https://your-share-api.example.com \
177
+ SNAPSHOT_SHARE_SITE_URL=https://ffffhx.github.io/codex-snapshots/ \
178
+ deploy/aliyun/configure-local-publisher.sh
179
+ ```
180
+
181
+ 这个配置会写入 `~/.codex-snapshots-agent.json`。之后直接启动本地查看器即可:
182
+
183
+ ```bash
184
+ codex-snapshot serve --port 4321
185
+ ```
186
+
187
+ 本地查看器里的“发布分享”按钮会先检查公网分享 API 的 GitHub 登录态;没有登录时会跳转到 GitHub 登录,登录后浏览器带着 session cookie 直接发布脱敏快照。页面发布状态会显示当前目标 API,方便确认没有仍然指向 `127.0.0.1`。
188
+ 公开官网如果没有配置 `CODEX_SNAPSHOTS_PUBLIC_API_URL`,会显示“公开分享 API 尚未配置”,不会回退请求访问者自己的 `127.0.0.1`。
189
+ Pages workflow 会校验 `CODEX_SNAPSHOTS_PUBLIC_API_URL`,拒绝 localhost、示例域名、内网 IP 和非 http/https 地址。
190
+
191
+ 阿里云 ECS 的 systemd、Nginx、SSH 部署脚本、部署前检查脚本、公网验证脚本、GitHub Pages 配置脚本和本地发布配置脚本见 [`deploy/aliyun`](deploy/aliyun/README.md)。
192
+
108
193
  ## macOS LaunchAgent
109
194
 
110
- 从源码运行时,可以把本地查看器安装为用户级 LaunchAgent:
195
+ 全局安装 npm 包后,可以把本地查看器安装为用户级 LaunchAgent:
196
+
197
+ ```bash
198
+ npm install -g codex-snapshots
199
+ codex-snapshot daemon install
200
+ codex-snapshot daemon status
201
+ codex-snapshot daemon logs
202
+ codex-snapshot daemon uninstall
203
+ ```
204
+
205
+ 从源码运行时,也可以使用对应的 pnpm 脚本:
111
206
 
112
207
  ```bash
113
208
  pnpm snapshot:install-daemon