@aibyzero/cm-workflow 0.16.7 → 0.16.9
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/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +37 -0
- package/README.md +39 -3
- package/VERSION +1 -1
- package/assets/readme/workflow-recovery-detailed.png +0 -0
- package/assets/readme/workflow-stages-detailed.png +0 -0
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +61 -4
- package/docs/next-steps.md +8 -2
- package/docs/user-guide.md +204 -0
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-admission.mjs +3 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +138 -26
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +142 -21
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-core.mjs +26 -4
- package/runtime/js/cm-ai/durable-runner-state.mjs +951 -43
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/execution-store.mjs +4 -2
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +11 -4
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +86 -17
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +44 -9
- package/runtime/js/cm-ai/host-session.mjs +47 -7
- package/runtime/js/cm-ai/host-tool-bridge.mjs +55 -6
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +112 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-dispatch-limits.mjs +18 -0
- package/runtime/js/cm-ai/review-package.mjs +10 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +29 -6
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +636 -65
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/cause-package.mjs +37 -8
- package/runtime/js/cm-fix/diagnosis.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +356 -187
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/investigation.mjs +25 -9
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +15 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- package/runtime/js/cm-prd/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +79 -9
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-run.mjs +26 -0
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +312 -0
- package/runtime/js/notify.mjs +492 -0
- package/runtime/js/policy-binding-compat.mjs +54 -0
- package/runtime/model-efficiency.md +17 -0
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +70 -2
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +96 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +55 -10
- package/scripts/cm-ai-batch-drive.test.mjs +65 -0
- package/scripts/cm-ai-batch-host.mjs +132 -13
- package/scripts/cm-ai-batch-host.test.mjs +255 -7
- package/scripts/cm-ai-batch-run-fixture.mjs +499 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +38 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +189 -22
- package/scripts/cm-ai-batch-run.test.mjs +22 -334
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +104 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +153 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +4 -3
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive.mjs +68 -23
- package/scripts/cm-ai-drive.test.mjs +37 -2
- package/scripts/cm-ai-fix-run-delivery.test.mjs +138 -0
- package/scripts/cm-ai-host-cli-workflow.test.mjs +271 -0
- package/scripts/cm-ai-host-fixture.mjs +268 -0
- package/scripts/cm-ai-host-protected.test.mjs +251 -0
- package/scripts/cm-ai-host.mjs +28 -16
- package/scripts/cm-ai-host.test.mjs +17 -759
- package/scripts/cm-ai-light-modules.test.mjs +57 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-project-qa-gate.test.mjs +71 -4
- package/scripts/cm-ai-protected-scope.test.mjs +7 -3
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +78 -11
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +127 -8
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +475 -0
- package/scripts/cm-ai-review-failure.test.mjs +124 -13
- package/scripts/cm-ai-review-timeout.test.mjs +188 -10
- package/scripts/cm-ai-run.mjs +15 -6
- package/scripts/cm-ai-supersede.test.mjs +486 -41
- package/scripts/cm-check-drive-files.mjs +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +18 -2
- package/scripts/cm-external-model-recovery.test.mjs +29 -3
- package/scripts/cm-fix-abandon.test.mjs +249 -10
- package/scripts/cm-fix-cause-package.test.mjs +33 -0
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +34 -8
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-rediagnosis.test.mjs +71 -4
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +35 -0
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +143 -10
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-log-event.mjs +49 -12
- package/scripts/cm-notify-command.test.mjs +900 -0
- package/scripts/cm-notify-read-drift.test.mjs +205 -0
- package/scripts/cm-notify.mjs +469 -0
- package/scripts/cm-notify.test.mjs +685 -0
- package/scripts/cm-patrol.mjs +83 -0
- package/scripts/cm-patrol.test.mjs +161 -0
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- package/scripts/cm-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/cm-token-report.mjs +497 -0
- package/scripts/cm-token-report.test.mjs +346 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/policy-binding-compat.test.mjs +99 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/SKILL.md +7 -3
- package/skills/cm-ai/references/N6-qa-eval.md +2 -2
- package/skills/cm-ai/references/js-host-modes.md +90 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +136 -0
- package/skills/cm-ai/references/js-host-recovery.md +311 -0
- package/skills/cm-ai/references/js-host.md +76 -331
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +2 -0
- package/skills/cm-fix/references/js-host.md +56 -10
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +16 -3
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/SKILL.md +2 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
package/docs/user-guide.md
CHANGED
|
@@ -240,6 +240,25 @@ python3 /path/to/cm-workflow/scripts/cm-usage-report.py --last 10
|
|
|
240
240
|
Token 或费用;同时区分 success/error/blocked/cancelled。已经 claim 但没有有效完成事件的
|
|
241
241
|
调用会单列为 `unresolved`,不计入调用、结果或 Token。需要机器读取时追加 `--json`。
|
|
242
242
|
|
|
243
|
+
### 按运行/步骤看 Claude 与 Codex 会话的 token 用量(只读)
|
|
244
|
+
|
|
245
|
+
`cm-usage-report.py` 只覆盖适配器写进日志的用量;想看本机 Claude Code 和 Codex CLI 会话
|
|
246
|
+
实际烧了多少,用 `cm-token-report.mjs`(Node,无依赖):
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
node /path/to/cm-workflow/scripts/cm-token-report.mjs \
|
|
250
|
+
--project /你的项目根目录 --specs /你的项目根目录/specs [--since 2026-10-01T00:00:00Z] [--json]
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
它只读 `~/.claude/projects/*` 和 `~/.codex/sessions/*` 里的时间戳、模型、用量数字、工作目录
|
|
254
|
+
和会话 id(不读消息正文、工具入参或结果),按 `运行日志.jsonl` 里的运行/步骤时间窗口,把每次调用
|
|
255
|
+
归到 工作流 → 步骤(develop / review / qa / check / prd-analysis / fix-diagnose / other),
|
|
256
|
+
窗口之外记为「未归属」;`--specs` 可用逗号传多个目录。输出含:未缓存输入、缓存写入、缓存读取、
|
|
257
|
+
输出、一个「加权合计」(权重是假定比例,默认 1 / 1.25 / 0.1 / 5,可用 `--weights in=1,cw=1.25,cr=0.1,out=5`
|
|
258
|
+
改;不是价格)、最重的 10 次调用,以及数据质量说明(按 message.id 去重数、跳过项、不确定归属数)。
|
|
259
|
+
归属按时间窗口而不是按会话,并行运行或你在别的会话里干活时会有误差,报告里会标出;缺失的数字不估算。
|
|
260
|
+
只读指定 specs 目录下的运行日志;Codex 会话只按首行 cwd 判断是否属于该项目。
|
|
261
|
+
|
|
243
262
|
项目角色使用 `adapter: openai-compatible` 时,CM 可在真实 HTTP 响应边界自动记录上述
|
|
244
263
|
数据。启动 Codex/Claude 前显式配置本次调用环境(密钥不要写进项目文件):
|
|
245
264
|
|
|
@@ -500,6 +519,191 @@ $cm-ai ~/projects/my-app-specs ~/code/my-app
|
|
|
500
519
|
- **外部行为不变,只整理结构** → `$cm-refactor`;
|
|
501
520
|
- **用户可见行为、接口或业务规则要变化** → `$cm-prd --change`。
|
|
502
521
|
|
|
522
|
+
## 卡住时提醒到手机(可选)
|
|
523
|
+
|
|
524
|
+
流程停下来要人处理时,CM 会运行 `notify.json` 里指定的一条本机命令,由它把提醒推到手机。
|
|
525
|
+
最省事的是用 `/cm:notify`(Codex:`$cm-notify`)在 Bark(iOS)和 pushplus(微信)之间切换,见下文「用 /cm:notify 配置」;也可以手动配置自己的命令。
|
|
526
|
+
CM 不保存、不显示任何 token;密钥只在你自己填写的本机文件里。
|
|
527
|
+
默认关闭:没有配置文件就什么都不做。
|
|
528
|
+
|
|
529
|
+
**什么时候提醒**
|
|
530
|
+
|
|
531
|
+
- 驾驶员(`scripts/*-drive.mjs`)一步结束后停在需要人的状态:blocked、unknown、次数用完、`requiresUser`,或驾驶员自己拒绝继续。
|
|
532
|
+
- 整个流程结束(如 `run_done`)时提醒一次,告诉你跑完了。
|
|
533
|
+
- 宿主向会话提问(`host_request`,如 qa_browser、develop、fix_diagnose)后,超过 `waitMinutes` 分钟没有应答,每个提问只提醒一次。
|
|
534
|
+
- 宿主一步做完后一直开着,手上没有进行中的操作,会话却超过 `idleMinutes` 分钟没发下一步,提醒一次:上一步停在要人处理的状态时标题是「在等你」,否则是「疑似空转」。只读的 `status` 查询不算下一步。驾驶员一步结束就关宿主,不会触发这一条。
|
|
535
|
+
- 宿主进程已经没了(被杀、崩溃、机器重启)却没收尾:宿主自己的计时器随它消失;驾驶员还在时会报一次「宿主异常退出」;驾驶员也不在了,就没人自动发现,要你手动跑一次只读巡检 `scripts/cm-patrol.mjs` 才报,见下文「手动核对宿主是否还在」。
|
|
536
|
+
- 正常推进和只读的 `status` 查询不提醒。
|
|
537
|
+
|
|
538
|
+
提醒只是通知。CM 不会因此自动继续、替你应答或授予任何权限。
|
|
539
|
+
|
|
540
|
+
**应答期限(与提醒无关)**:宿主向会话提的每个问题都有期限,到期就停止等待,不会无限挂着。
|
|
541
|
+
期限由环境变量 `CM_HOST_ANSWER_TIMEOUT_MINUTES` 设定(整数 1–60,默认 30 分钟),宿主启动时读取,不写进运行存档、不影响指纹,恢复运行时可以换值。
|
|
542
|
+
要先跑项目命令的提问(`check`、`verification_precheck`、`init_verify`、`check_runtime`、`qa_logic`、`qa_browser`)固定等满 60 分钟。
|
|
543
|
+
cm-ai、批次和 cm-fix 的提问本来就有自己的计时(最长 60 分钟),这里只作 61 分钟的兜底,不会提前打断它们。
|
|
544
|
+
到期后才到的应答一律拒收(`host_response_late`),宿主在 stderr 写一行 `{"diagnostic":"host_response_late",...}`。
|
|
545
|
+
|
|
546
|
+
**提醒的边界(先看清再依赖它)**
|
|
547
|
+
|
|
548
|
+
- 每条提醒只尝试发一次。推送失败(断网、推送服务出错)只在 `notify.log` 记一行,不重试、不补发。
|
|
549
|
+
- 计时器长在宿主或驾驶员进程里。宿主还开着时,等待应答和空转提醒会自动发,不需要你在会话里;宿主退出后它的计时器就没了,驾驶员还在时只会报一次「宿主异常退出」。电脑关机或睡眠时谁都不发;醒来后按墙上时间算,可能迟到或误报一次。
|
|
550
|
+
- 没有独立常驻的监督进程。相关进程退出后,CM 不会自动重启监督;要等你回到会话或下一次运行才会再有提醒。
|
|
551
|
+
- 会话自己派出去的子代理、后台命令和等待脚本,宿主看不见;它们卡住或被工具时限停掉,不会直接触发这里的提醒(只有当它们导致宿主的提问没人应答时,才会间接触发「等待会话应答」)。减少这类空转靠派发纪律(见 `skills/cm-ai/references/js-host.md`「启动前」第 7 项)。
|
|
552
|
+
- 流程结果里的「已发送」只表示提醒命令已经启动,不表示送达。
|
|
553
|
+
|
|
554
|
+
**用 /cm:notify 配置(推荐)**
|
|
555
|
+
|
|
556
|
+
暂不支持 Windows:在 Windows 上切换、`test`(含演练模式)和发送器本身(含 `--check`)都会以退出码 2 拒绝,提示「/cm:notify 暂不支持 Windows:密钥文件权限核对尚未在 Windows 实机验证」;查看只显示渠道和密钥文件是否存在,不读取密钥内容(渠道文件也按同样的安全方式读:不跟随符号链接、限制大小、核对是同一个文件);`off` 和只读的 `preview` 照常可用。两个入口一启动就先做这项拒绝,在这之前不访问文件。需要在 Windows 上推送,可先按下文「手动配置」用自己的命令。
|
|
557
|
+
|
|
558
|
+
插件要求 Node 24.14 及以上。`/cm:notify` 与托管发送器本身不检查版本号,只检查 Node 是否提供 `import.meta.main`:没有它就直接以退出码 3 结束并说明原因,不会什么都不做就返回成功;有它但低于 24.14 的 Node 不会被拦下,属于不受支持的用法。
|
|
559
|
+
|
|
560
|
+
同一时刻只开一个渠道。下面的文件都在 `~/.cm-workflow/`(设置了 `CM_WORKFLOW_HOME` 时在那个目录):
|
|
561
|
+
|
|
562
|
+
| 文件 | 内容 |
|
|
563
|
+
| --- | --- |
|
|
564
|
+
| `notify-channel.conf` | `CHANNEL=bark` 或 `CHANNEL=pushplus`,由命令维护 |
|
|
565
|
+
| `bark.env` | `BARK_KEY=`(必填),`BARK_SERVER=`(可选,默认 `https://api.day.app`,只能是不带路径的 https 地址) |
|
|
566
|
+
| `pushplus.env` | `PUSHPLUS_TOKEN=` |
|
|
567
|
+
| `notify/cm-notify-send.mjs` | 托管发送器,切换时从插件复制过来 |
|
|
568
|
+
|
|
569
|
+
- `/cm:notify`:只读查看。显示当前渠道、发送命令类型、文案是「默认」还是「自定义」,以及两个渠道各自是「未填写(文件不存在)」「未填写」「格式不对」「已填写,可解析」中的哪一种;不显示密钥的值,也不写任何文件。
|
|
570
|
+
- `/cm:notify bark`、`/cm:notify pushplus`:目标渠道的密钥文件能解析才切换;否则所有已有文件都不改,并告诉你要填哪个文件第几行。文件不存在时会新建一个权限 600 的空模板,里面有中文说明。
|
|
571
|
+
- Bark 的 Key 是 App 首页示例地址里 `api.day.app/` 后面那一段,不是 App 里 64 位十六进制的 Device Token。
|
|
572
|
+
- `/cm:notify test`:用当前渠道真的发一条测试推送,走的就是 `notify.json` 里的同一条命令(检查和运行用的是同一次读到的内容,运行时去掉 `NODE_OPTIONS`)。当前渠道密钥没填好时拒绝(演练模式除外,见下)。命令的输出一律不读、不转述,只按退出码报告:0 已被推送服务接受(不代表已送达)、2 配置或密钥问题、3 网络失败或超时、4 服务端拒绝,其他为未知。测试推送不受去重和限流影响,也不计数;只在 `notify.log` 记一行结果。带 `CM_NOTIFY_DRY_RUN=1` 时不运行任何命令,也不读取、不检查密钥文件(是否填好请用 `/cm:notify` 查看),只按 `notify-channel.conf` 生成脱敏请求给你看(只适用于 bark / pushplus)。
|
|
573
|
+
- 切换要改三个文件(发送器、`notify-channel.conf`、`notify.json`)。中途写失败时,已写的会按内存里的原内容改回,改名备份的原配置也会改回原名;不另存任何副本。改不回的会逐个列出路径,并写明原内容还在哪里(例如仍在 `notify.json.bak-时间`)或已不在磁盘上,不会报成功。关闭时移动文件失败同样会说清现在的状态和备份位置。
|
|
574
|
+
- `/cm:notify preview`:只读预览。按当前 `notify.json` 的文案,用固定的示例字段打印六种提醒(卡住、等待应答、疑似空转、在等你、宿主退出、流程结束)各自的标题和正文;不运行发送命令、不读密钥、不写任何文件。
|
|
575
|
+
- 查看、`preview`、`test` 和切换读 `notify.json`(切换时还有 `notify.off.json`)一律走同一个安全读取:不跟随符号链接、必须是普通文件、不超过 64 KiB、打开后核对是同一个文件。不符合时不读它的内容,查看写明「不是普通文件(可能是符号链接)」或「超过 64 KiB」,切换拒绝且不改任何文件。
|
|
576
|
+
- 运行时自己发提醒前读 `notify.json` 也走这条边界(同一套检查的同步实现,有对照测试保证两份不偏离):符号链接、目录、命名管道、超过 64 KiB 的文件一律不读,提醒关闭,`notify.log` 记一行 `off invalid_config unreadable_not_regular_file` 或 `unreadable_too_large`,不报错;不会等待命名管道的写入方,但它仍是同步文件读写,在很慢的文件系统上没有时间上限。平台限制:Windows 上 libuv 把 `O_NOFOLLOW`、`O_NONBLOCK` 定义为 0,那里的打开没有对应的保护(先 lstat 检查、打开后核对是同一个文件仍然有效)。
|
|
577
|
+
- 切换会把 `notify.json` 重新排版并写入新的发送命令,文件可能变大;改写后超过 64 KiB 时拒绝切换,原有文件都不动,请先精简(如缩短 `text`、删掉不用的字段)。
|
|
578
|
+
- `/cm:notify off`:把 `notify.json` 移到 `notify.off.json`,渠道设置和密钥文件都保留;再切换一次渠道就恢复,原来的 `waitMinutes`、`text` 等字段照旧(切换渠道同样保留它们)。
|
|
579
|
+
- 密钥文件你自己用编辑器填,不要贴进对话。文件按纯数据解析:只认 `名字=值`,可带 `export `、成对引号、空行和 `#` 注释;未知或重复的行整份拒绝。文件必须是你自己的普通文件、权限 600(`chmod 600 文件`)。读内容前会确认打开的文件与检查时路径指向的是同一个文件(设备号、文件号都相同),中途被换掉就拒绝。
|
|
580
|
+
|
|
581
|
+
切换时写入的发送命令是「当前这个 node 的绝对路径 + `notify/cm-notify-send.mjs`」。发送器放在插件目录之外,插件重装、升级不会让路径失效。
|
|
582
|
+
node 被移动或升级到别的目录后,旧路径会失效(`notify.log` 记 `failed spawn_enoent`,查看时也会提示),再执行一次 `/cm:notify <当前渠道>` 就修复;插件升级后查看提示发送器版本不同时,同样这样更新。
|
|
583
|
+
|
|
584
|
+
托管发送器的行为:
|
|
585
|
+
|
|
586
|
+
- 同一个进程直接发 HTTPS,不调 curl 等子进程;不跟随重定向;始终校验证书(`NODE_TLS_REJECT_UNAUTHORIZED` 不起作用)。
|
|
587
|
+
- 只有 HTTP 200 且返回 JSON 里的 `code` 是数字 200 才算成功。失败不重试:超时的请求可能已经送达。
|
|
588
|
+
- 总期限 12 秒,从发送器脚本开始执行算起(Node 自身启动、加载脚本的时间不计入,这部分由 CM 的 15 秒强制结束兜底),读标准输入、读配置和请求都在里面。脚本第一件事就记下起点并设好计时器,在这之前不访问文件系统;到点直接以退出码 3 结束;读文件是异步的,计时器不会被挡住。另外每读一个文件前、发请求前、以及每个返回 0 的出口前(包括 `--check` 和演练模式)都按单调时钟再核对一次,时间已用完就不发、不返回 0,而是退出码 3;请求已被接受但已超时的,也按 3 报(可能已送达)。
|
|
589
|
+
- 退出码:0 成功;2 配置或密钥问题;3 网络失败或超时(意外错误也按 3,只写固定提示);4 服务端拒绝或回应不对。失败信息只写 HTTP 状态和 `code` 的类型,不写服务端返回的值。
|
|
590
|
+
- 代理:Node 24.5 及以上读取 `HTTPS_PROXY` / `NO_PROXY`(走 CONNECT 隧道);更老的 Node 不走代理、直接连接。变量要在运行 CM 流程的环境里设置。
|
|
591
|
+
- `CM_NOTIFY_DRY_RUN=1`:不读密钥、不联网,只打印脱敏后的请求;`/cm:notify test` 带上它可以先演练。
|
|
592
|
+
|
|
593
|
+
只有 `command` 恰好是 `["<node 的绝对路径>", "<目录>/notify/cm-notify-send.mjs"]`(程序名是 `node` 或 `node.exe`)才算托管发送器。
|
|
594
|
+
其他任何写法都算你自己配置的命令,查看时标为「自定义命令」,切换会拒绝;确认要换成托管发送器时加 `--replace-custom`,原文件会改名为 `notify.json.bak-时间` 作为备份(是改名不是复制,原文件的权限跟着走;从 `notify.off.json` 恢复时则改名为 `notify.off.json.bak-时间`)。
|
|
595
|
+
早期的本机脚本 `~/.cm-workflow/cm-notify.py`(`command` 恰好只有这一项)读的是同一组文件,查看时标为「旧版本机脚本」。下次切换渠道会自动把 `notify.json` 改名备份并换成托管发送器,已填的密钥继续可用,脚本本身不动。
|
|
596
|
+
|
|
597
|
+
**手动配置(自定义命令)**
|
|
598
|
+
|
|
599
|
+
在 `~/.cm-workflow/notify.json`(设置了 `CM_WORKFLOW_HOME` 时放在那个目录)写:
|
|
600
|
+
|
|
601
|
+
```json
|
|
602
|
+
{"version": 1, "command": ["/absolute/path/to/my-notify.sh"], "waitMinutes": 10}
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
- `command`:要运行的程序和参数,第一项必须是绝对路径;不经过 shell。
|
|
606
|
+
- `waitMinutes`:等待会话应答多久后提醒,默认 10。
|
|
607
|
+
- `checkWaitMinutes`:宿主请求「跑检查」(`check`、`verification_precheck`、`init_verify`)时,会话要先跑完项目的检查命令(如 xcodebuild、测试套件),正常就要几十分钟,所以这三类提问只看这个门槛,默认 45;其他提问仍看 `waitMinutes`。
|
|
608
|
+
- `idleMinutes`:宿主一步做完后等下一步多久算空转,默认 45。真实项目里正常的开发加检查一段常见 45~60 分钟,但那时宿主手上有进行中的操作,不计入。
|
|
609
|
+
- `text`:可选,自定义提醒文案,见下文「自定义文案」。
|
|
610
|
+
- 文件格式不对时,功能关闭,只在 `notify.log` 记一行,不往流程输出里打印。只有 `text` 写错时例外:提醒照常发送,改用默认文案。
|
|
611
|
+
|
|
612
|
+
命令通过环境变量 `CM_NOTIFY_TITLE`(不超过 60 字)、`CM_NOTIFY_BODY`(不超过 500 字)拿到内容。
|
|
613
|
+
标准输入还会收到一行同样内容的 JSON。
|
|
614
|
+
命令在后台独立运行,流程不等它结束;15 秒内没结束会被终止。
|
|
615
|
+
|
|
616
|
+
**消息长什么样**
|
|
617
|
+
|
|
618
|
+
下面是默认文案,可在 `notify.json` 的 `text` 里改(见下文「自定义文案」);空的字段整行省略。要人处理(卡住、等待应答、空转、宿主退出)时:
|
|
619
|
+
|
|
620
|
+
```text
|
|
621
|
+
CM cm-fix 需要人处理 · demo-app
|
|
622
|
+
下一步:核对 reason 后恢复原运行
|
|
623
|
+
项目:demo-app
|
|
624
|
+
流程:cm-fix
|
|
625
|
+
任务:T-001
|
|
626
|
+
阶段:blocked
|
|
627
|
+
原因:checks_not_passed
|
|
628
|
+
时间:16:00
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
流程结束时只写项目、任务和时间:
|
|
632
|
+
|
|
633
|
+
```text
|
|
634
|
+
CM cm-ai 流程已结束 · demo-app
|
|
635
|
+
项目:demo-app
|
|
636
|
+
任务:T-003
|
|
637
|
+
时间:16:00
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
第一行是标题,其余是正文。时间是本机时区(遵循 `TZ` 环境变量)的 24 小时制「时:分」。运行编号默认不进正文,仍在标准输入那行 JSON 的 `runId` 字段里。
|
|
641
|
+
|
|
642
|
+
**自定义文案(可选)**
|
|
643
|
+
|
|
644
|
+
在 `notify.json` 里加一个 `text`,只写想改的部分,其余沿用默认:
|
|
645
|
+
|
|
646
|
+
```json
|
|
647
|
+
{"version": 1, "command": ["..."],
|
|
648
|
+
"text": {
|
|
649
|
+
"titlePrefix": "【CM】",
|
|
650
|
+
"headlines": {"default": "卡住了", "done": "跑完了"},
|
|
651
|
+
"fields": {"default": ["nextAction", "task", "code", "runId", "time"]},
|
|
652
|
+
"labels": {"code": "卡在", "runId": "运行"}
|
|
653
|
+
}}
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
- `titlePrefix`:标题开头,默认 `CM`;写空字符串就不要前缀。标题仍是「前缀 流程 标题词 · 项目」。
|
|
657
|
+
- `headlines`:各事件的标题词。键只能是 `done`(流程已结束)、`waiting`(等待会话应答)、`idle`(疑似空转)、`idle_waiting`(在等你)、`dead`(宿主已退出未收尾)、`default`(其他要人处理的情况,默认「需要人处理」)。
|
|
658
|
+
- `fields`:正文显示哪些字段、按什么顺序。`default` 用于要人处理的提醒,`done` 用于流程结束;每项是不重复、至少一个的字段名列表。
|
|
659
|
+
- `labels`:字段前的名字。
|
|
660
|
+
- 字段名只能是 `project`(项目)、`workflow`(流程)、`runId`(运行)、`task`(任务)、`stage`(阶段)、`code`(原因)、`nextAction`(下一步)、`time`(时间)。不支持模板、占位符或表达式。
|
|
661
|
+
- 自定义的字符串先删掉所有 Unicode 格式字符(文字方向控制符 U+202A–202E、U+2066–2069、U+200E/200F、U+061C,零宽字符 U+200B–200D、U+2060、U+FEFF,软连字符等),防止倒序或隐藏文字;换行等控制字符换成空格;然后从 `/`、`~/`、盘符加 `:\` 或 `:/`、`\\` 开始,到下一个空白、引号或 `,。;;、))` 为止的部分一律换成 `<路径>`,不管前面贴着什么字符(所以 `CI/CD` 会变成 `CI<路径>`,自定义文字里别用斜杠);前缀最多 16 个字、标题词 24 个、标签 12 个,超出截断。整条标题 60 字、正文 500 字的上限不变。
|
|
662
|
+
- `text` 写错(键名拼错、字段名不认识、类型不对、去掉上述字符后没有可见的文字、数字、标点或符号;前缀只有写成 `""` 才表示不要前缀)时,提醒不会被关掉,整份 `text` 不生效、改用默认文案,`notify.log` 记一行 `default_text text_config <原因>`;`/cm:notify` 查看会写「文案:默认(notify.json 里的 text 无效:<原因>…)」。
|
|
663
|
+
- 改完先跑 `/cm:notify preview` 看效果,不会发出任何推送。
|
|
664
|
+
|
|
665
|
+
**限流与日志**
|
|
666
|
+
|
|
667
|
+
- 同一件事 6 小时内只提醒一次;所有提醒合计每分钟最多 4 条、24 小时最多 150 条。
|
|
668
|
+
- 计数记在 `notify-state.json`;发送失败或被限流只在 `notify.log` 追加一行,不影响流程结果和退出码。
|
|
669
|
+
|
|
670
|
+
**隐私**
|
|
671
|
+
|
|
672
|
+
消息只含项目目录名、流程、运行编号、任务、阶段、原因代码和下一步提示。
|
|
673
|
+
不含文件内容、日志、diff、审查意见、环境变量或项目目录以外的路径(绝对路径会被替换成 `<路径>`;字段值里紧贴在英文字母、数字或 `_ . ~ -` 后面的斜杠不当作路径开头,例如 `a/b`、`v1.2/x` 原样保留)。
|
|
674
|
+
这些文字会经过你选的推送服务,对方能看到;介意的话不要启用。
|
|
675
|
+
|
|
676
|
+
**手动核对宿主是否还在**
|
|
677
|
+
|
|
678
|
+
宿主自己的计时器管不到宿主已经死掉的情况。配置了提醒后,每个 JSONL 宿主会在 `~/.cm-workflow/hosts/` 登记一个小文件(进程号、流程、运行、任务、阶段;启动和每次回复时更新,结束时删除)。怀疑有宿主没收尾时,手动跑一次只读巡检:
|
|
679
|
+
|
|
680
|
+
```bash
|
|
681
|
+
node "{CM_WORKFLOW_ROOT}/scripts/cm-patrol.mjs" --report
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
- `--report` 以 JSON 输出各类登记的数量(活着、已退出、过期、格式不对)和最近 48 小时内已退出宿主的详情,不提醒、不删文件。
|
|
685
|
+
- 不带 `--report` 时,登记在最近 48 小时内、进程却已不在的宿主会合并成一条提醒,发出后删掉这些登记;活着的、超过 48 小时的和格式不对的登记不动;被限流或提醒未启用时不删,下次再报。
|
|
686
|
+
- 它只读登记和「进程是否存在」,不读日志、不读项目文件;会写的只有提醒本身的去重/限流记录和删除已报告的登记。
|
|
687
|
+
- CM 不提供定时跑它的配置,也不建议配常驻定时器:定时扫描管不到会话自己派出去的任务,关机和睡眠时也照样没人在。
|
|
688
|
+
|
|
689
|
+
**示例脚本(归你自己所有,不随 CM 安装)**
|
|
690
|
+
|
|
691
|
+
下面是一个通用写法:从本机私有文件读 token,用 curl 发出去。地址和字段请换成你的推送服务要求的样子。
|
|
692
|
+
|
|
693
|
+
```sh
|
|
694
|
+
#!/bin/sh
|
|
695
|
+
# ~/.cm-workflow/my-notify.sh —— 自己维护,chmod 700
|
|
696
|
+
set -eu
|
|
697
|
+
. "$HOME/.cm-workflow/my-push.env" # 里面写 PUSH_TOKEN=...,chmod 600,不要提交到任何仓库
|
|
698
|
+
export PUSH_TOKEN # 下面的 node 子进程要读到它
|
|
699
|
+
payload=$(node -e 'process.stdout.write(JSON.stringify({token:process.env.PUSH_TOKEN,
|
|
700
|
+
title:process.env.CM_NOTIFY_TITLE,content:process.env.CM_NOTIFY_BODY}))')
|
|
701
|
+
curl -fsS --max-time 10 -H 'Content-Type: application/json' -d "$payload" \
|
|
702
|
+
https://push.example.com/send >/dev/null
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
脚本只在需要时读取 token,不打印它;CM 也不会把 token 写进日志。
|
|
706
|
+
|
|
503
707
|
## 可复制的最小清单
|
|
504
708
|
|
|
505
709
|
```text
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aibyzero/cm-workflow",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.9",
|
|
4
4
|
"description": "Spec-driven business development workflow for Pi, Codex, and Claude Code",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"./skills/cm-fix",
|
|
49
49
|
"./skills/cm-idea",
|
|
50
50
|
"./skills/cm-init",
|
|
51
|
+
"./skills/cm-notify",
|
|
51
52
|
"./skills/cm-prd",
|
|
52
53
|
"./skills/cm-refactor",
|
|
53
54
|
"./skills/cm-runtime",
|
|
@@ -23,7 +23,16 @@ const API_ERROR_CLASSES = Object.freeze({authentication_failed:'reviewer_auth_fa
|
|
|
23
23
|
export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
24
24
|
let session = null, stage = 'init', value, noticeCount = 0, thinkingCount = 0, rejectedAttempts = 0;
|
|
25
25
|
const pendingTools = new Map(), toolIds = new Set();
|
|
26
|
-
const reject = code
|
|
26
|
+
const reject = (code, detail = null) => {
|
|
27
|
+
stage = 'failed'; throw Object.assign(new Error(code), {code, ...(detail ? {detail} : {})});
|
|
28
|
+
};
|
|
29
|
+
// Body-free summary of the message that broke the review boundary: which
|
|
30
|
+
// check (k), message type (m), block type (b), tool name (t), is_error (e).
|
|
31
|
+
// Never the text, input or result content.
|
|
32
|
+
const summary = (k, m, block = null, tool = null, isError = null) => ({k, m,
|
|
33
|
+
b: typeof block?.type === 'string' && /^[A-Za-z_]{1,32}$/.test(block.type) ? block.type : null,
|
|
34
|
+
t: typeof tool === 'string' && /^[A-Za-z0-9_.:-]{1,64}$/.test(tool) ? tool : null,
|
|
35
|
+
e: typeof isError === 'boolean' ? isError : null});
|
|
27
36
|
return Object.freeze({
|
|
28
37
|
accept(message) {
|
|
29
38
|
if (!message || typeof message !== 'object' || Array.isArray(message)) reject('invalid_event');
|
|
@@ -88,17 +97,22 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
|
88
97
|
if (message.parent_tool_use_id !== null || message.error != null
|
|
89
98
|
|| message.message?.role !== 'assistant') reject('unexpected_assistant');
|
|
90
99
|
const content = message.message.content;
|
|
91
|
-
if (!Array.isArray(content) || content.length === 0)
|
|
100
|
+
if (!Array.isArray(content) || content.length === 0) {
|
|
101
|
+
reject('unexpected_tool_or_content', summary('empty_content', 'assistant'));
|
|
102
|
+
}
|
|
92
103
|
let substantive = false;
|
|
93
104
|
for (const block of content) {
|
|
94
105
|
if (['thinking','redacted_thinking'].includes(block?.type)) continue;
|
|
95
106
|
substantive = true;
|
|
96
107
|
if (block?.type === 'text' && typeof block.text === 'string') continue;
|
|
97
108
|
if (block?.type !== 'tool_use' || typeof block.id !== 'string' || !block.id.trim()
|
|
98
|
-
||
|
|
99
|
-
reject('unexpected_tool_or_content');
|
|
109
|
+
|| typeof block.name !== 'string' || !block.name.trim()) {
|
|
110
|
+
reject('unexpected_tool_or_content', summary('block_type', 'assistant', block, block?.name));
|
|
111
|
+
}
|
|
112
|
+
if (toolIds.has(block.id)) reject('unexpected_tool_or_content', summary('duplicate_tool_id', 'assistant', block, block.name));
|
|
113
|
+
if (block.name !== 'StructuredOutput' && ++rejectedAttempts > 16) {
|
|
114
|
+
reject('unexpected_tool_or_content', summary('tool_attempt_limit', 'assistant', block, block.name));
|
|
100
115
|
}
|
|
101
|
-
if (block.name !== 'StructuredOutput' && ++rejectedAttempts > 16) reject('unexpected_tool_or_content');
|
|
102
116
|
toolIds.add(block.id);
|
|
103
117
|
pendingTools.set(block.id, block.name);
|
|
104
118
|
}
|
|
@@ -108,13 +122,35 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
|
108
122
|
}
|
|
109
123
|
if (message.type === 'user') {
|
|
110
124
|
const content = message.message?.content;
|
|
125
|
+
// CLI 2.1.x injects its own user-role reminders (isSynthetic: true, one
|
|
126
|
+
// short text block; e.g. that StructuredOutput must be called, or that
|
|
127
|
+
// the previous response had no visible output). The model cannot author
|
|
128
|
+
// user messages. Such a reminder carries no verdict and runs nothing:
|
|
129
|
+
// count it as a notice and ignore its body. Anything else from the user
|
|
130
|
+
// role must be a tool_result; with a tool still pending nothing may be
|
|
131
|
+
// injected between call and result.
|
|
132
|
+
if (message.isSynthetic === true) {
|
|
133
|
+
if (message.parent_tool_use_id !== null || message.message?.role !== 'user'
|
|
134
|
+
|| !Array.isArray(content) || content.length !== 1 || content[0]?.type !== 'text'
|
|
135
|
+
|| typeof content[0].text !== 'string' || Buffer.byteLength(content[0].text, 'utf8') > 1024
|
|
136
|
+
|| pendingTools.size !== 0) {
|
|
137
|
+
reject('unexpected_tool_or_content', summary('user_content', 'user', content?.[0]));
|
|
138
|
+
}
|
|
139
|
+
if (noticeCount >= 32) reject('unexpected_event');
|
|
140
|
+
noticeCount++;
|
|
141
|
+
try { if (typeof onNotice === 'function') onNotice({kind:'claude_system_notice', subtype:'synthetic_user'}); } catch {}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
111
144
|
if (message.message?.role !== 'user' || !Array.isArray(content) || content.length === 0) {
|
|
112
|
-
reject('unexpected_tool_or_content');
|
|
145
|
+
reject('unexpected_tool_or_content', summary('user_content', 'user'));
|
|
113
146
|
}
|
|
114
147
|
for (const block of content) {
|
|
115
|
-
if (block?.type !== 'tool_result'
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
if (block?.type !== 'tool_result') reject('unexpected_tool_or_content', summary('user_content', 'user', block));
|
|
149
|
+
if (!pendingTools.has(block.tool_use_id)) reject('unexpected_tool_or_content', summary('unknown_tool_result', 'user', block));
|
|
150
|
+
const name = pendingTools.get(block.tool_use_id);
|
|
151
|
+
if (name !== 'StructuredOutput' && block.is_error !== true) {
|
|
152
|
+
// A successful non-StructuredOutput tool is a real boundary break.
|
|
153
|
+
reject('unexpected_tool_or_content', summary('tool_result_not_error', 'user', block, name, block.is_error));
|
|
118
154
|
}
|
|
119
155
|
pendingTools.delete(block.tool_use_id);
|
|
120
156
|
}
|
|
@@ -124,10 +160,10 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
|
124
160
|
if (message.subtype !== 'success' || message.is_error !== false) reject('provider_failed');
|
|
125
161
|
if (stage !== 'result' || pendingTools.size !== 0 || !Number.isInteger(message.num_turns)
|
|
126
162
|
|| message.num_turns < 1 || message.num_turns > 20) reject('unexpected_result');
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
163
|
+
// The verdict is only ever the CLI's structured_output object. Prose in
|
|
164
|
+
// `result` is never parsed as one: a reviewer that answered in text after
|
|
165
|
+
// a reminder has not answered.
|
|
166
|
+
value = message.structured_output;
|
|
131
167
|
if (!value || typeof value !== 'object' || Array.isArray(value)) reject('invalid_output_json');
|
|
132
168
|
stage = 'done';
|
|
133
169
|
onEvent({event:'item.completed', item_type:'agent_message'});
|
|
@@ -49,7 +49,9 @@ export function inspectCmAiQaTaskContext({specsDir,codeProject,feature,taskId,fe
|
|
|
49
49
|
// Plan construction happens before task completion; decisions still bind a completed task.
|
|
50
50
|
if(!selected||(taskId!==undefined&&!selected.some(task=>task.id===taskId&&task.completed&&!task.dropped)))fail('qa_not_ready');
|
|
51
51
|
const pending=selected.filter(task=>!task.completed&&!task.dropped).length;
|
|
52
|
-
|
|
52
|
+
// The feature's [DROPPED] task ids: N6 does not plan a case bound only to them.
|
|
53
|
+
const dropped=selected.filter(task=>task.dropped).map(task=>task.id);
|
|
54
|
+
return frozen({completed,pendingFeatures,pending,dropped,mergeEligible:pending===1&&admission.nextTask?.feature===feature});
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
// Admission's public feature summary stops at the selected feature. Count all
|