ronds_ai 0.1.28 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -174,54 +174,49 @@ Codex 输出示例:
174
174
 
175
175
  ### `analyze`
176
176
 
177
- 从 Claude Code 的会话 transcript 生成一次性会话摘要:
177
+ 接收 Claude Code 的逐轮 Hook 事件,并异步上报用户 Prompt 与 Skill 调用:
178
178
 
179
179
  ```bash
180
180
  ronds_ai analyze claude
181
181
  ```
182
182
 
183
- 该命令仅用于 `SessionEnd` Hook,会由 `hooks deploy` 自动安装(project 或 user scope,未用 `--tool` 排除 claude 时)。它只上报:
184
-
185
- - 会话起止时间与有效用户轮数
186
- - Skill 名称及调用次数
187
- - 首轮输入的最多 150 个字符预览
188
- - repo、branch、worker_id 和 Git 身份
189
-
190
- 扫描采用流式 JSONL 读取,内存不会随 transcript 大小增长,不上传逐轮内容或代码。
183
+ 该命令由 `hooks deploy` 自动安装到 `UserPromptSubmit` 和 `PostToolUse:Skill`(project 或 user scope,未用 `--tool` 排除 claude 时)。它上报:
191
184
 
192
- 每次 Hook 调用仅生成一条会话级结构化快照;网络失败时写入有界队列,后续 Hook 最多补发少量旧快照。内部部署仅保留用户、会话、项目目录等必要定位字段。
193
-
194
- 运行期间只写一个轻量 active 标记,结束时一次性转换为 `~/.ronds_ai/analyze/` 下的待补传 spool。网络失败不会影响 Hook 主流程,并按 5、15、60 分钟退避补传;平台按 `diagnostic_event_id` 幂等去重。可选配置:
185
+ - 每轮完整用户 Prompt(不采集 Assistant 回复)
186
+ - Skill 名称以及 `slash_command` / `tool_use` 来源
187
+ - Session ID、发生时间
188
+ - repo、branch、worker_id 和 Git 身份
195
189
 
196
- - `ANALYZE_DIAGNOSTICS_URL`:覆盖诊断事件上报地址
197
- - `ANALYZE_DIAGNOSTICS_TOKEN`:诊断入口的 Bearer Token
198
- - `ANALYZE_DIAGNOSTICS_TIMEOUT_MS`:单次补传超时,默认 `400`
199
-
200
- 会话入口地址默认为本机 API,也可按部署环境覆盖:
190
+ Hook 不读取或扫描 transcript 内容,只在本地原子写入 `~/.ronds_ai/ai-usage-events/` 有界事件队列,然后唤醒独立后台进程批量上传。网络失败按指数退避重试,不阻塞 Claude Code;中心端按 `event_id` 幂等处理。
201
191
 
202
- - `AI_USAGE_SESSIONS_URL`:会话摘要 API 地址
192
+ 事件入口地址默认为本机 API,也可按部署环境覆盖:
193
+
194
+ - `AI_USAGE_EVENTS_URL`:逐轮事件批量 API 地址
203
195
 
204
196
  `hooks deploy` 会自动把以下条目写入 Claude Code 的 hooks 配置:
205
197
 
206
198
  ```json
207
199
  {
208
200
  "hooks": {
209
- "Stop": [
201
+ "UserPromptSubmit": [
210
202
  {
211
203
  "hooks": [
212
204
  {
213
205
  "type": "command",
214
- "command": "npx ronds_ai@latest analyze claude"
206
+ "command": "npx ronds_ai@latest analyze claude",
207
+ "async": true
215
208
  }
216
209
  ]
217
210
  }
218
211
  ],
219
- "SessionEnd": [
220
- {
221
- "hooks": [
222
- {
223
- "type": "command",
224
- "command": "npx ronds_ai@latest analyze claude"
212
+ "PostToolUse": [
213
+ {
214
+ "matcher": "Skill",
215
+ "hooks": [
216
+ {
217
+ "type": "command",
218
+ "command": "npx ronds_ai@latest analyze claude",
219
+ "async": true
225
220
  }
226
221
  ]
227
222
  }
@@ -230,7 +225,7 @@ ronds_ai analyze claude
230
225
  }
231
226
  ```
232
227
 
233
- Node.js 低于 20 或安装时使用了 `--omit=optional` 时,只有 `analyze` 会返回明确错误;`record` 等其他命令仍可运行。Hook payload 或上传处理失败时,`analyze` 保持 fail-open 并把诊断信息写入本地日志。
228
+ 升级到 schema v6 时会清理本工具管理的旧 `Stop` / `SessionEnd` analyze Hook,同时保留用户自定义 Hook。Hook payload 或本地入队失败时,`analyze` 保持 fail-open。
234
229
 
235
230
  ### `doctor`
236
231
 
@@ -266,7 +261,7 @@ npx ronds_ai@latest doctor hermes
266
261
  - 关键配置文件是否存在
267
262
  - 今天的最近错误日志内容
268
263
 
269
- `doctor analyze` 还会检查 Node.js 版本、用户级 `SessionEnd` Hook、工号和 Git 用户身份,以及本地待补传会话数量。它只做只读探测,不会发送会话数据。
264
+ `doctor analyze` 还会检查 Node.js 版本、用户级 `UserPromptSubmit` / `PostToolUse:Skill` Hook、旧 Stop 残留、工号、Git 用户身份及本地待上传事件数量。它只做只读探测,不会发送事件。
270
265
 
271
266
  Claude 会检查:
272
267
 
@@ -305,14 +300,14 @@ npx ronds_ai@latest hooks deploy --scope user
305
300
  默认 scope 为 `project`(项目级部署),行为:
306
301
 
307
302
  - 写入或更新 `.cursor/hooks.json`
308
- - 写入或更新 `.claude/settings.json`(`PostToolUse` 的 `record claude` 采集 hook,以及 `SessionEnd` 的 `analyze claude` 会话摘要 hook)
303
+ - 写入或更新 `.claude/settings.json`(代码采集 Hook,以及异步的 `UserPromptSubmit` / `PostToolUse:Skill` analyze Hook)
309
304
  - 清理项目内旧版 Cursor、Claude、Codex hook 脚本
310
305
  - 跳过 Codex 项目级配置部署,并在输出中说明原因
311
306
 
312
307
  `--scope user`(用户级部署),行为:
313
308
 
314
309
  - 写入或更新用户级 Cursor hook 配置
315
- - 写入或更新用户级 Claude hook 配置(同上:`record claude` 采集 hook + `analyze claude` 会话摘要 hook)
310
+ - 写入或更新用户级 Claude hook 配置(同上,并清理本工具管理的旧 Stop / SessionEnd analyze Hook)
316
311
  - 写入或更新系统级 `requirements.toml`(Windows: `C:\ProgramData\OpenAI\Codex\requirements.toml`,Linux / macOS: `/etc/codex/requirements.toml`),包含 `[features] hooks = true`、`[hooks]` 托管目录配置以及 `PostToolUse` 的 `apply_patch` hook
317
312
  - 清理用户目录中的旧版 hook 脚本文件
318
313
 
@@ -373,7 +368,7 @@ RONDS_AI_DISABLE_HOOKS_AUTO_SYNC=1
373
368
  注意:
374
369
 
375
370
  - auto-sync 只维护**用户级** hooks,不影响项目级配置
376
- - auto-sync 会同步维护用户级 Claude 的 `analyze claude` 会话摘要 hook
371
+ - auto-sync 会同步维护用户级 Claude 的 schema v6 逐轮事件 Hook
377
372
  - 后台同步失败时,错误记录到 `~/.ronds_ai/hooks_auto_sync_error.log`,不污染当前命令输出
378
373
  - 首次安装 hooks 仍建议执行 `ronds_ai hooks deploy --scope user`
379
374
 
package/bin/ronds_ai.js CHANGED
@@ -264,19 +264,27 @@ async function runSkillsCommand(args) {
264
264
  process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
265
265
  }
266
266
 
267
- /**
268
- * 内部命令分发。当前只支持 hooks auto-sync。
269
- */
270
- async function runInternalCommand(args) {
271
- const [subcommand, ...subargs] = args;
272
-
273
- if (subcommand === 'hooks' && subargs[0] === 'auto-sync') {
274
- runHooksAutoSync();
275
- return;
276
- }
277
-
278
- throw new Error('Unsupported internal command');
279
- }
267
+ /**
268
+ * 内部命令分发:hooks auto-sync 与 events flush。
269
+ */
270
+ async function runInternalCommand(args) {
271
+ const [subcommand, ...subargs] = args;
272
+
273
+ if (subcommand === 'hooks' && subargs[0] === 'auto-sync') {
274
+ runHooksAutoSync();
275
+ return;
276
+ }
277
+
278
+ if (subcommand === 'events' && subargs[0] === 'flush') {
279
+ const { runFlushWithLock } = require('../lib/ai_usage_events');
280
+ const { getAnalyzeConfig } = require('../lib/analyze_config');
281
+ const config = getAnalyzeConfig(process.cwd());
282
+ await runFlushWithLock(undefined, config.eventsUrl);
283
+ return;
284
+ }
285
+
286
+ throw new Error('Unsupported internal command');
287
+ }
280
288
 
281
289
  async function run() {
282
290
  const [, , command, ...args] = process.argv;
@@ -301,7 +309,7 @@ async function run() {
301
309
  throw new Error(`Unsupported analyze tool: ${source || ''}`);
302
310
  }
303
311
 
304
- // analyze 主要挂在 Stop,每轮生成增量会话快照;使用 Node 16 原生 API。
312
+ // analyze 挂在 UserPromptSubmit 与 PostToolUse(Skill),只写本地事件队列;使用 Node 16 原生 API。
305
313
  const { runClaudeAnalyze } = require('../lib/analyze_claude');
306
314
  await runClaudeAnalyze();
307
315
  return;