@chenmk/superflow 0.3.0 → 0.4.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.
Files changed (85) hide show
  1. package/README.md +20 -1
  2. package/README.zh-CN.md +16 -1
  3. package/assets/manifest.json +5 -4
  4. package/assets/prompts/superflow-design.md +3 -0
  5. package/assets/prompts/superflow-docs.md +4 -1
  6. package/assets/scripts/superflow-dependency-update-hook.sh +1 -1
  7. package/assets/scripts/superflow-managed-work-check.mjs +194 -0
  8. package/assets/scripts/superflow-managed-work-guard.sh +103 -0
  9. package/assets/skills/openspec-propose/SKILL.md +11 -0
  10. package/assets/skills/superflow-design/SKILL.md +18 -9
  11. package/assets/skills/superflow-docs/SKILL.md +16 -0
  12. package/assets/skills/superflow-pipeline/SKILL.md +46 -0
  13. package/assets/skills/superflow-pipeline/references/document-templates.md +8 -0
  14. package/assets/skills/superflow-pipeline/references/managed-work.md +58 -0
  15. package/assets/skills/superflow-pipeline/references/quality-gate.md +1 -0
  16. package/assets/skills/superflow-pipeline/references/superpower-technical-design-template.md +10 -0
  17. package/assets/skills/superflow-pipeline/scripts/superflow-archive.sh +1 -1
  18. package/assets/skills/superflow-pipeline/scripts/superflow-guard.sh +79 -9
  19. package/assets/skills-en/openspec-propose/SKILL.md +14 -0
  20. package/assets/skills-en/superflow-design/SKILL.md +18 -8
  21. package/assets/skills-en/superflow-docs/SKILL.md +16 -0
  22. package/assets/skills-en/superflow-pipeline/SKILL.md +48 -0
  23. package/assets/skills-en/superflow-pipeline/references/document-templates.md +5 -0
  24. package/assets/skills-en/superflow-pipeline/references/managed-work.md +34 -0
  25. package/assets/skills-en/superflow-pipeline/references/quality-gate.md +8 -0
  26. package/assets/skills-en/superflow-pipeline/references/superpower-technical-design-template.md +11 -0
  27. package/assets/skills-en/superflow-pipeline/scripts/superflow-archive.sh +1 -1
  28. package/assets/skills-en/superflow-pipeline/scripts/superflow-guard.sh +78 -9
  29. package/dist/app/cli.js +120 -102
  30. package/dist/app/cli.js.map +1 -1
  31. package/dist/app/commands/init.js +6 -2
  32. package/dist/app/commands/init.js.map +1 -1
  33. package/dist/app/commands/managed-service.js +5 -0
  34. package/dist/app/commands/managed-service.js.map +1 -0
  35. package/dist/app/commands/pipeline.js +123 -3
  36. package/dist/app/commands/pipeline.js.map +1 -1
  37. package/dist/app/commands/status.js +199 -77
  38. package/dist/app/commands/status.js.map +1 -1
  39. package/dist/app/commands/uninstall.js +5 -2
  40. package/dist/app/commands/uninstall.js.map +1 -1
  41. package/dist/app/commands/update.js +31 -6
  42. package/dist/app/commands/update.js.map +1 -1
  43. package/dist/domains/config/cli-help.js +103 -73
  44. package/dist/domains/config/cli-help.js.map +1 -1
  45. package/dist/domains/deps.js +2 -1
  46. package/dist/domains/deps.js.map +1 -1
  47. package/dist/domains/hook.js +71 -38
  48. package/dist/domains/hook.js.map +1 -1
  49. package/dist/domains/managed-work/contract.js +218 -0
  50. package/dist/domains/managed-work/contract.js.map +1 -0
  51. package/dist/domains/managed-work/i18n.js +12 -0
  52. package/dist/domains/managed-work/i18n.js.map +1 -0
  53. package/dist/domains/managed-work/input.js +111 -0
  54. package/dist/domains/managed-work/input.js.map +1 -0
  55. package/dist/domains/managed-work/journal.js +122 -0
  56. package/dist/domains/managed-work/journal.js.map +1 -0
  57. package/dist/domains/managed-work/lock.js +40 -0
  58. package/dist/domains/managed-work/lock.js.map +1 -0
  59. package/dist/domains/managed-work/notifications.js +53 -0
  60. package/dist/domains/managed-work/notifications.js.map +1 -0
  61. package/dist/domains/managed-work/paths.js +18 -0
  62. package/dist/domains/managed-work/paths.js.map +1 -0
  63. package/dist/domains/managed-work/prompts.js +218 -0
  64. package/dist/domains/managed-work/prompts.js.map +1 -0
  65. package/dist/domains/managed-work/runner.js +626 -0
  66. package/dist/domains/managed-work/runner.js.map +1 -0
  67. package/dist/domains/managed-work/schemas.js +85 -0
  68. package/dist/domains/managed-work/schemas.js.map +1 -0
  69. package/dist/domains/managed-work/service.js +121 -0
  70. package/dist/domains/managed-work/service.js.map +1 -0
  71. package/dist/domains/managed-work/state.js +90 -0
  72. package/dist/domains/managed-work/state.js.map +1 -0
  73. package/dist/domains/managed-work/storage.js +181 -0
  74. package/dist/domains/managed-work/storage.js.map +1 -0
  75. package/dist/domains/managed-work/types.js +16 -0
  76. package/dist/domains/managed-work/types.js.map +1 -0
  77. package/dist/domains/managed-work/wait.js +40 -0
  78. package/dist/domains/managed-work/wait.js.map +1 -0
  79. package/dist/platform/agent-process.js +308 -0
  80. package/dist/platform/agent-process.js.map +1 -0
  81. package/dist/platform/process-liveness.js +10 -0
  82. package/dist/platform/process-liveness.js.map +1 -0
  83. package/dist/platform/version-check.js +30 -9
  84. package/dist/platform/version-check.js.map +1 -1
  85. package/package.json +1 -1
@@ -0,0 +1,58 @@
1
+ # 托管任务执行规则
2
+
3
+ ## 入口
4
+
5
+ 托管任务属于 `superflow-pipeline` 内建能力。用户只需说“用 Superflow 托管完成”并给出
6
+ implementation prompt、change 目录或简单任务,不需要知道内部 Skill 名和 CLI 参数。
7
+ 简单任务生成最小合同;SDD 任务冻结 Superflow 已生成的 implementation prompt,不以
8
+ `tasks.md` 代替执行 Prompt。
9
+
10
+ ## 角色
11
+
12
+ - 当前主 Agent:提交任务、查看结果、向用户汇总并申请 Git 批准。
13
+ - 监督 Agent:固定会话、只读检查、生成结构化问题和整改要求。
14
+ - 执行 Agent:固定会话、唯一写入者、实现并完成验证。
15
+ - 后台服务:状态、预算、队列、会话恢复和证据的唯一写入者。
16
+
17
+ ## 必须通过 CLI
18
+
19
+ 不要由聊天中的 Agent 手工启动另一 CLI。调用:
20
+
21
+ ```bash
22
+ superflow pipeline "<implementation-prompt|change-dir|task>" --managed --project "<root>" \
23
+ --supervisor <codex|claude> --executor <claude|codex> --language <zh|en>
24
+ ```
25
+
26
+ 查看:
27
+
28
+ ```bash
29
+ superflow status <root>
30
+ ```
31
+
32
+ 托管命令默认启动独立后台服务并监听本地事件账本,直到任务进入交付、阻塞或预算耗尽等
33
+ 终态。监听进程退出不影响后台任务。命令返回后,当前 Agent 读取任务报告并在原会话汇总。
34
+
35
+ ## 硬门槛
36
+
37
+ - 5/7/12 调用上限由状态机先占用后调用,Prompt 无权上调。
38
+ - 语言写入冻结合同;执行 Prompt、账本、报告、通知、错误和恢复轮次始终使用同一语言。
39
+ - 每次启动和恢复都重新校验冻结合同哈希、不可覆盖权限及 5/7/12 硬上限;磁盘文件被
40
+ 改写时按失败关闭,不能继续调用 Agent。
41
+ - change 目录必须通过 `.sdd/state.yaml` 的 `implementation_prompt` 定位执行入口;
42
+ `tasks.md` 仅作清单。Prompt 原文复制为托管快照并冻结 SHA-256,执行和评审使用同一份。
43
+ - 两个 session ID 必须落盘,禁止 `--last` / `--continue` 猜测。
44
+ - `.superflow/tasks/<task-id>/runs/<run-id>/progress.jsonl` 是追加式事实账本。
45
+ - 执行角色禁止修改托管目录、Git 提交/推送、发布、生产写入、跳过沙箱。
46
+ - 监督角色禁止修改目标文件。
47
+ - Agent 非零退出、非法 JSON、缺 session ID、工作区在检查期间变化都不能判通过。
48
+ - 工程和 SDD 任务至少提供构建、测试、启动/真实调用中的两类成功命令证据;只编译或
49
+ 只跑单元测试不能进入正式检查。
50
+ - 最终通过前运行 `superflow-managed-work-check.mjs <root> <task-id>`。
51
+ - 完整性脚本必须先通过,后台才允许写入唯一的 `run.delivery_ready` 事件;脚本失败时
52
+ 转入等待人工处理,不得留下“已可交付”的假证据。
53
+ - 通过后只进入等待 Git 批准,不能自动提交。
54
+
55
+ ## 恢复
56
+
57
+ 后台异常后读取任务合同、事件账本、运行状态、最近检查结果和两个 session ID。恢复原
58
+ 会话并从最后确认动作继续。监督会话丢失可在完整接管后显式重建;执行会话丢失默认暂停。
@@ -65,6 +65,7 @@
65
65
  | 47 | **金额精度边界** | **涉及金额、费用、优惠、抵扣、退款、分账、支付、发票、余额、电费、服务费、套餐结算、比例分摊、明细分配、对账或财务展示时强制** | Superpowers 技术详设包含 `Money Precision Boundary` 及金额恒等式、权威总额、独立计算项、差额反推项与公式、计算态来源、中间精度、舍入边界、scale/rounding mode、分配/对账规则、禁止提前舍入点和测试证据;存在加法恒等式且总额是真源时,最后一个组成项必须由权威总额减去其余组成项合计得到,禁止所有组成项分别计算和舍入后重建总额;测试必须覆盖半分、尾差或多明细分配场景 |
66
66
  | 48 | **外部集成配置与部署合同** | **涉及第三方平台/工具、SDK、MQ/Kafka、回调、支付渠道、云服务或其他外部集成时强制** | api.md、sdd-quality-gate.md、Superpowers 技术详设和实现 prompt 包含 `外部集成配置与部署合同` / `External Integration Configuration And Deployment Contract`;列出 endpoint、应用/租户/项目 ID、Topic/Tag/Consumer Group、namespace、webhook、ACL/role、开关、超时和凭据引用在本地/测试/生产的来源与创建方式,以及注入方式、运行 owner、创建 owner/时点、就绪证据、回滚、密钥处理和阻塞项;环境相关值不得只硬编码在注解/常量/业务代码;测试自动创建、历史资源或本地启动成功不能证明生产就绪,缺少生产创建证据必须阻塞发布 |
67
67
  | 49 | **并发与幂等归属** | **涉及并发、批量下发/开通/续费、重复提交/回调/消费或重复外部调用时强制** | sdd-quality-gate.md、Superpowers 技术详设和实现 prompt 包含 `Concurrency And Idempotency Ownership` / `并发与幂等归属`;明确业务幂等键、应用层原子占用 owner、短事务边界、PENDING/SUCCESS/FAILED 状态流转、重试复用原业务编码、外部调用边界和不确定结果对账;唯一索引不作为默认方案,只能在自然唯一、历史数据、NULL/软删除和冲突处理合同明确后作为可选兜底;测试覆盖并发、重复和重试 |
68
+ | 50 | **复杂度减法评审** | **完整 workflow 的 docs/design 阶段强制** | `design.md` 与 Superpowers 技术详设包含 `复杂度减法评审`,逐项记录现有能力/复用证据、必要性、最简实现、删除/拒绝项和证据/阻塞;统计新增表、字段、API、Service/组件、缓存、异步/MQ/事件、定时任务和兼容层;能扩展现有模块、由字段推导或用单事务同步闭环时不得另建平行实现;`sdd-quality-gate.md` 必须给出 PASS/BLOCKED 结论,只有 PASS/通过才能离开 docs/design,存在无证据抽象或未决更简方案时阻塞 |
68
69
 
69
70
  ### 文档完整性强制检查(新增,全部项目必做)
70
71
 
@@ -35,6 +35,16 @@ canonical_sources:
35
35
  | -------------------- | --------------- | ---------------- | ------------------------- | ------------- | ------ |
36
36
  | <R1/S1> | `<file>:<line>` | <observed fact> | <implementation approach> | <files> | <risk> |
37
37
 
38
+ ## 复杂度减法评审
39
+
40
+ | 设计项 | 现有能力/复用证据 | 是否必要 | 最简实现 | 删除/拒绝项 | 证据/阻塞 |
41
+ | ------ | ----------------- | -------- | -------- | ----------- | --------- |
42
+ | `<表/API/Service/组件/同步机制>` | `<现有源码/API/表/依赖>` | `保留/删除/阻塞` | `<最小闭环实现>` | `<不新增的平行抽象/缓存/异步/兼容层>` | `<锚点或阻塞>` |
43
+
44
+ 新增项统计:表 0;字段 0;API 0;Service/组件 0;缓存 0;MQ/事件 0;定时任务 0;兼容层 0。按实际设计替换数量,不适用时保留 0。优先扩展
45
+ 现有模块;可安全推导的状态不重复持久化;单事务同步可闭环时不引入异步、补偿或
46
+ 缓存。每个保留项都要说明更简单方案为何不能满足合同,没有证据则删除。
47
+
38
48
  ## Architecture Boundary And Call Direction
39
49
 
40
50
  Use this whenever the change crosses repositories, services, SDKs, MQ,
@@ -131,7 +131,7 @@ GUARD="$SCRIPT_DIR/superflow-guard.sh"
131
131
  VALIDATE="$SCRIPT_DIR/superflow-yaml-validate.sh"
132
132
  CHANGE_DIR="$(cd "$CHANGE_DIR" && pwd)"
133
133
  CHANGE_NAME="$(basename "$CHANGE_DIR")"
134
- PROJECT_ROOT="$(cd "$CHANGE_DIR/../.." && pwd)"
134
+ PROJECT_ROOT="$(cd "$CHANGE_DIR/../../.." && pwd)"
135
135
  ARCHIVE_ROOT="$PROJECT_ROOT/openspec/changes/archive"
136
136
  ARCHIVE_NAME="$CHANGE_NAME"
137
137
 
@@ -24,6 +24,7 @@ VALIDATE="$SCRIPT_DIR/superflow-yaml-validate.sh"
24
24
  CHANGE_DIR="${1:-}"
25
25
  PHASE="${2:-}"
26
26
  MODE="${3:-}"
27
+ CHANGE_DIR_INPUT="${CHANGE_DIR%/}"
27
28
 
28
29
  [[ -n "$CHANGE_DIR" && -n "$PHASE" ]] || {
29
30
  usage
@@ -35,6 +36,25 @@ MODE="${3:-}"
35
36
  CHANGE_DIR="$(cd "$CHANGE_DIR" && pwd)"
36
37
  issues=()
37
38
 
39
+ require_canonical_change_layout() {
40
+ local suffix
41
+
42
+ if [[ -L "$CHANGE_DIR_INPUT" ]]; then
43
+ issues+=("symlinked OpenSpec change directory is forbidden; keep one physical openspec/changes/<change-name> directory")
44
+ fi
45
+
46
+ [[ "$CHANGE_DIR" == */openspec/changes/* ]] || return 0
47
+ suffix="${CHANGE_DIR#*/openspec/changes/}"
48
+ case "$suffix" in
49
+ archive/*|*/embedded-changes/*) return 0 ;;
50
+ esac
51
+ if [[ "$suffix" == */* ]]; then
52
+ issues+=("non-canonical OpenSpec change directory: encode the version in <change-name> and use openspec/changes/<change-name>")
53
+ fi
54
+ }
55
+
56
+ require_canonical_change_layout
57
+
38
58
  require_file() {
39
59
  local path="$1"
40
60
  [[ -f "$CHANGE_DIR/$path" ]] || issues+=("missing file: $path")
@@ -313,15 +333,30 @@ change_has_external_enum_risk() {
313
333
  "$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
314
334
  }
315
335
 
336
+ change_contract_docs_without_complexity_budget() {
337
+ local path
338
+ for path in proposal.md api.md design.md tests.md spec.md; do
339
+ [[ -f "$CHANGE_DIR/$path" ]] || continue
340
+ sed -E '/新增项统计|复杂度预算|New-item counts|Complexity budget/d' \
341
+ "$CHANGE_DIR/$path"
342
+ done
343
+ if [[ -d "$CHANGE_DIR/specs" ]]; then
344
+ find "$CHANGE_DIR/specs" -path '*/spec.md' -type f \
345
+ -exec sed -E '/新增项统计|复杂度预算|New-item counts|Complexity budget/d' {} +
346
+ fi
347
+ }
348
+
349
+ change_all_docs_without_complexity_budget() {
350
+ find "$CHANGE_DIR" -maxdepth 2 -name '*.md' -type f \
351
+ -exec sed -E '/新增项统计|复杂度预算|New-item counts|Complexity budget/d' {} +
352
+ }
353
+
316
354
  change_has_external_config_risk() {
317
- grep -RIEiq \
355
+ local content
356
+ content="$(change_contract_docs_without_complexity_budget)"
357
+ grep -Eiq \
318
358
  '第三方|外部平台|外部工具|外部集成|third[- ]party|external (platform|tool|integration|system)|SDK|MQ|Kafka|RocketMQ|TDMQ|callback|回调|webhook|支付渠道|payment gateway|cloud service|云服务' \
319
- "$CHANGE_DIR/proposal.md" \
320
- "$CHANGE_DIR/api.md" \
321
- "$CHANGE_DIR/design.md" \
322
- "$CHANGE_DIR/tests.md" \
323
- "$CHANGE_DIR/spec.md" \
324
- "$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
359
+ <<< "$content"
325
360
  }
326
361
 
327
362
  change_has_concurrency_idempotency_risk() {
@@ -358,9 +393,11 @@ change_has_fx_precision_risk() {
358
393
  }
359
394
 
360
395
  change_has_architecture_boundary_risk() {
361
- grep -RIEiq \
396
+ local content
397
+ content="$(change_all_docs_without_complexity_budget)"
398
+ grep -Eiq \
362
399
  '跨仓|跨服务|sibling|SDK|MQ|topic|consumer|scheduler|定时|device|设备|callback|回调|third[- ]party|第三方|mini[- ]program|小程序|gateway|网关|adapter|适配|protocol|协议|interconnect|互联互通|调用链|入口|出口' \
363
- "$CHANGE_DIR"/*.md "$CHANGE_DIR"/**/*.md 2>/dev/null
400
+ <<< "$content"
364
401
  }
365
402
 
366
403
  first_prompt_rel() {
@@ -482,6 +519,29 @@ require_money_precision_evidence() {
482
519
  fi
483
520
  }
484
521
 
522
+ require_minimal_design_review() {
523
+ local path="$1"
524
+ local label="$2"
525
+ require_grep '复杂度减法评审|反过度设计评审|Minimal Design Review|Complexity Reduction Review' "$path" "$label"
526
+ require_grep '复用|reuse|existing capability|existing module' "$path" "$label reuse evidence"
527
+ require_grep '最简|最小实现|simplest|minimum design|minimal implementation' "$path" "$label simplest implementation"
528
+ require_grep '删除|拒绝|不新增|移出范围|removed|rejected|do not add|out of scope' "$path" "$label removed or rejected complexity"
529
+ require_grep '新增项统计|复杂度预算|New-item counts|Complexity budget' "$path" "$label complexity budget"
530
+ require_grep '表|table' "$path" "$label table count"
531
+ require_grep '字段|field' "$path" "$label field count"
532
+ require_grep 'API' "$path" "$label API count"
533
+ require_grep 'Service|服务|组件|service|component' "$path" "$label service/component count"
534
+ require_grep '缓存|cache' "$path" "$label cache count"
535
+ require_grep 'MQ|事件|异步|event|async' "$path" "$label async/event count"
536
+ require_grep '定时任务|scheduled job|scheduler' "$path" "$label scheduled-job count"
537
+ require_grep '兼容层|compatibility layer' "$path" "$label compatibility-layer count"
538
+ }
539
+
540
+ require_minimal_design_pass() {
541
+ local path="$1"
542
+ require_grep '(复杂度减法评审|反过度设计评审|Minimal Design Review|Complexity Reduction Review).*(PASS|通过)|(PASS|通过).*(复杂度减法评审|反过度设计评审|Minimal Design Review|Complexity Reduction Review)' "$path" "complexity reduction review PASS verdict"
543
+ }
544
+
485
545
  transition_event=""
486
546
 
487
547
  if [[ -x "$VALIDATE" && -f "$CHANGE_DIR/.sdd/state.yaml" ]]; then
@@ -511,6 +571,12 @@ case "$PHASE" in
511
571
  require_grep 'RED|红绿|GREEN' tests.md "RED/GREEN test contract"
512
572
  require_grep 'curl|Postman|Newman|pytest|RestAssured|自动化命令' tests.md "interface automation command"
513
573
  require_grep 'handoff_hash|sdd-context|上下文包|防漂移' sdd-quality-gate.md "handoff/context-drift gate"
574
+ workflow="$(state_get workflow)"
575
+ if [[ "$workflow" == "full" ]]; then
576
+ require_minimal_design_review design.md "complexity reduction review"
577
+ require_grep '复杂度减法评审|反过度设计评审|Minimal Design Review|Complexity Reduction Review' sdd-quality-gate.md "complexity reduction quality gate"
578
+ require_minimal_design_pass sdd-quality-gate.md
579
+ fi
514
580
  if change_has_external_enum_risk; then
515
581
  require_external_enum_contract api.md "external enum binding contract"
516
582
  require_external_enum_contract sdd-quality-gate.md "external enum binding quality gate"
@@ -546,6 +612,9 @@ case "$PHASE" in
546
612
  require_hash_recorded
547
613
  workflow="$(state_get workflow)"
548
614
  if [[ "$workflow" == "full" ]]; then
615
+ require_minimal_design_review design.md "complexity reduction review"
616
+ require_grep '复杂度减法评审|反过度设计评审|Minimal Design Review|Complexity Reduction Review' sdd-quality-gate.md "complexity reduction quality gate"
617
+ require_minimal_design_pass sdd-quality-gate.md
549
618
  require_optional_state_path technical_design "technical_design"
550
619
  technical_design_rel="$(state_get technical_design)"
551
620
  if [[ -n "${technical_design_rel:-}" && "$technical_design_rel" != "null" ]]; then
@@ -569,6 +638,7 @@ case "$PHASE" in
569
638
  if change_has_money_precision_risk; then
570
639
  require_money_precision_contract "$technical_design_rel" "money precision boundary"
571
640
  fi
641
+ require_minimal_design_review "$technical_design_rel" "technical design minimal design review"
572
642
  fi
573
643
  fi
574
644
  require_grep 'Superpowers Technical Design Handoff|Superpower 技术详设|technical_design|源码级 HOW' design.md "Superpowers technical design handoff"
@@ -22,6 +22,20 @@ When ready to implement, run /opsx:apply
22
22
 
23
23
  **Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
24
24
 
25
+ ### Canonical OpenSpec Change Directory (Blocking)
26
+
27
+ - A change must have exactly one physical directory:
28
+ `openspec/changes/<name>/`.
29
+ - Encode the release version in `<name>`. For example, an account-permission
30
+ change for `v1.1.1` must use `v1-1-1-account-permission-optimization`.
31
+ - Do not create nested version directories such as
32
+ `openspec/changes/v1.1.1/<feature>/`.
33
+ - Do not create a flat symlink, copied directory, or second canonical document
34
+ tree to work around OpenSpec CLI discovery.
35
+ - Creation, status, validation, and apply must use the same `<name>` in
36
+ `openspec new change`, `openspec status --change`, and
37
+ `openspec validate <name> --strict`.
38
+
25
39
  **Steps**
26
40
 
27
41
  1. **If no clear input provided, ask what they want to build**
@@ -46,7 +46,17 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
46
46
  4. Write:
47
47
  `docs/superpowers/specs/YYYY-MM-DD-<change-id>-technical-design.md`
48
48
  using `../superflow-pipeline/references/superpower-technical-design-template.md`.
49
- 5. For cross-repository, service-to-service, SDK, MQ, scheduler, device,
49
+ 5. Complete `Minimal Design Review` before expanding source-level HOW. For
50
+ every new table, field, API, service/component, abstraction, cache,
51
+ async/MQ/event flow, scheduled job, or compatibility layer, prove existing
52
+ reuse options, necessity, and why the simplest direct implementation is
53
+ insufficient. Prefer one owner, one write path, one transaction, and
54
+ set-based operations when they satisfy the contract. Remove speculative
55
+ extension points, duplicate DTO/API layers, derivable persistence,
56
+ premature caches, and async compensation without measured need. Record
57
+ retained and removed counts; unresolved simpler alternatives keep the
58
+ design blocked.
59
+ 6. For cross-repository, service-to-service, SDK, MQ, scheduler, device,
50
60
  callback, third-party, mini-program, gateway, or adapter changes, include
51
61
  `Architecture Boundary And Call Direction`. Prove owner module, call
52
62
  direction, existing entry/exit points, proposed entry/exit points, evidence
@@ -54,7 +64,7 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
54
64
  adapter/protocol translator/device gateway into a business-entry
55
65
  orchestrator, stop and return to `$superflow-docs` unless the OpenSpec/SDD
56
66
  contract explicitly grants that ownership with approval evidence.
57
- 6. For third-party platforms/tools, SDKs, MQ/Kafka, callbacks, payment
67
+ 7. For third-party platforms/tools, SDKs, MQ/Kafka, callbacks, payment
58
68
  gateways, cloud services, or other external integrations, include
59
69
  `External Integration Configuration And Deployment Contract`. Inventory
60
70
  every endpoint, app/tenant/project ID, Topic, Tag, Consumer Group,
@@ -66,7 +76,7 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
66
76
  auto-creation or pre-existing resources must not be treated as proof that
67
77
  production will provision them. Missing production provisioning evidence
68
78
  blocks design completion.
69
- 7. For concurrent requests, batch issue/activation/renewal, duplicate callbacks,
79
+ 8. For concurrent requests, batch issue/activation/renewal, duplicate callbacks,
70
80
  duplicate consumption, or repeated external delivery, include
71
81
  `Concurrency And Idempotency Ownership`. Use a stable business idempotency
72
82
  key and an application-layer atomic claim in a short transaction; persist
@@ -76,10 +86,10 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
76
86
  optional fallback with proven natural uniqueness, historical cleanup,
77
87
  NULL/soft-delete semantics, and a conflict contract. Check-then-insert,
78
88
  process-local locks, and random IDs alone are blocked.
79
- 8. For field/status/enum/sync changes, include `Field And Status Reverse
89
+ 9. For field/status/enum/sync changes, include `Field And Status Reverse
80
90
  Impact` and prove writers, readers, filters, derived sync paths, consumers,
81
91
  and tests. Direct setter-only design is blocked.
82
- 9. For amount, fee, discount, deduction, refund, sharing, payment, invoice,
92
+ 10. For amount, fee, discount, deduction, refund, sharing, payment, invoice,
83
93
  balance, electricity fee, service fee, package settlement, proration,
84
94
  allocation, reconciliation, or financial display changes,
85
95
  include `Money Precision Boundary`. Prove calculation-state fields,
@@ -98,12 +108,12 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
98
108
  level and policy source, deterministic residual strategy with stable
99
109
  tie-breaker, and positive/zero/negative evidence. For FX changes, freeze the
100
110
  directional rate metadata and one canonical conversion path.
101
- 10. Record state:
111
+ 11. Record state:
102
112
  ```bash
103
113
  ../superflow-pipeline/scripts/superflow-state.sh set <change-dir> technical_design docs/superpowers/specs/YYYY-MM-DD-<change-id>-technical-design.md
104
114
  ../superflow-pipeline/scripts/superflow-state.sh set <change-dir> design_doc design.md
105
115
  ```
106
- 11. Update `design.md` with `Superpowers Technical Design Handoff`, update
116
+ 12. Update `design.md` with `Superpowers Technical Design Handoff`, update
107
117
  `sdd-quality-gate.md` with the technical design path and hash, then run
108
118
  `../superflow-pipeline/scripts/superflow-handoff.sh <change-dir> --refresh`.
109
119
  If the guard reports a stale or missing hash, record the printed hash in
@@ -111,7 +121,7 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
111
121
  `--refresh` again. Do not set `design_doc` to the Superpowers document;
112
122
  `design_doc` is the OpenSpec/SDD contract design, while `technical_design`
113
123
  is the Superpowers HOW document.
114
- 12. Run:
124
+ 13. Run:
115
125
  ```bash
116
126
  ../superflow-pipeline/scripts/superflow-yaml-validate.sh <change-dir>
117
127
  ../superflow-pipeline/scripts/superflow-guard.sh <change-dir> design --apply
@@ -103,6 +103,17 @@ For complex requirements, verify these before writing docs:
103
103
  chain, no-fallback/no-guessing boundary, and pre-coding agent self-check. If
104
104
  any gate is missing from `design.md`, `tests.md`, or quality gate, stop and
105
105
  complete the docs first.
106
+ - For full workflow changes, `design.md` must include a `Minimal Design Review`
107
+ before docs freeze. Inventory every proposed table, field, API,
108
+ service/component, cache, async/MQ/event flow, scheduled job, compatibility
109
+ layer, and abstraction. Record existing reuse evidence, necessity, the
110
+ simplest implementation, removed/rejected complexity, and blockers.
111
+ Prefer extending current modules and synchronous transactions. Do not keep a
112
+ layer only for hypothetical future flexibility; remove it without evidence.
113
+ - `sdd-quality-gate.md` must record the minimal-design verdict as `PASS` or
114
+ `BLOCKED`; only `PASS` may leave docs/design. Missing reuse evidence, parallel APIs/models, redundant persisted
115
+ fields, speculative cache/async/compensation, or an unresolved simpler option
116
+ blocks docs completion.
106
117
  - `design.md` stays the OpenSpec/SDD design contract: requirement mapping,
107
118
  API/DB/field semantics, source facts, real-entry call chain, no-fallback
108
119
  boundary, risks, and acceptance hooks. It must not try to own all source-level
@@ -251,6 +262,11 @@ Use references only as needed:
251
262
  the relationship judgment as `confirmed/partially confirmed/unknown` when a bug fix hinges on
252
263
  existing data or call-chain behavior.
253
264
  - `design.md` must reference the frozen `api.md` fields and errors.
265
+ - `design.md` must include `Minimal Design Review` with:
266
+ `Design item | Existing capability/reuse evidence | Necessary? | Simplest implementation | Removed/rejected complexity | Evidence/blocker`.
267
+ Count new tables, fields, APIs, services/components, caches, async flows,
268
+ jobs, and compatibility layers. A zero count is valid and preferred when
269
+ existing capabilities close the contract.
254
270
  - `design.md` must include a "Field Semantic Contract" table for every risky field:
255
271
  `Field | Source table/DTO/event | Real semantics | Target field | Target semantics | Equivalent? |
256
272
  Evidence anchor | Forbidden usage | Unknowns/owner`.
@@ -19,6 +19,38 @@ other:
19
19
  - Handoff files and state files are the memory boundary. Do not rely on chat
20
20
  memory after compaction.
21
21
 
22
+ ## Managed Work And Dual-Agent Closure
23
+
24
+ When the user says to use Superflow for managed delivery and provides an
25
+ implementation prompt, change directory, or direct task, use built-in managed
26
+ mode. Do not require the user to name `superflow-pipeline`, roles, or CLI flags:
27
+
28
+ ```bash
29
+ superflow pipeline "<implementation prompt, change directory, or direct task>" --managed --project "<project root>" \
30
+ --supervisor codex --executor claude --language en
31
+ ```
32
+
33
+ Swap the roles when Claude is the current entry agent. The command always uses
34
+ the independent background service while following the local task journal to a
35
+ terminal state, then the current agent reads the report and summarizes in the
36
+ same conversation. Losing the follower does not stop the task. Read
37
+ `references/managed-work.md` before dispatch. Do not spawn the peer CLI by hand.
38
+
39
+ Hard gates:
40
+
41
+ - Persist one supervisor session and one executor session per task; resume exact IDs.
42
+ - Task contract, event journal, review results, and evidence are authoritative.
43
+ - Maximum 5 reviews, 7 executor calls, and 12 total agent calls.
44
+ - Revalidate the frozen contract and hard limits on every start or resume. Engineering work cannot enter review with only one verification category.
45
+ - Resolve a change directory through `.sdd/state.yaml` `implementation_prompt`, reject `tasks.md` as an execution entry, and freeze one prompt snapshot plus SHA-256 for both agents.
46
+ - Supervisor is read-only; executor cannot edit `.superflow/tasks` or commit/push/publish.
47
+ - A passing run stops at `awaiting_git_approval`; Git requires the user's approval.
48
+ - Use `superflow status <project-root>` instead of model polling.
49
+ - `superflow-managed-work-check.mjs` must pass before delivery-ready status.
50
+ - Record the single delivery-ready event only after the integrity script passes.
51
+ - After the managed command returns a terminal state, read the task report and summarize it to the user instead of returning only a task ID.
52
+ - Freeze the selected language into the task contract. Executor and reviewer prompts, resumed rounds, journals, reports, notifications, and errors must inherit that language without switching mid-run.
53
+
22
54
  ## Phase Order
23
55
 
24
56
  Always route work through this order unless the task is explicitly a tweak or
@@ -79,6 +111,22 @@ When the router selects embedded deep clarification, follow these rules inside
79
111
 
80
112
  ## Required Artifacts
81
113
 
114
+ ### Canonical OpenSpec Change Directory (Blocking)
115
+
116
+ - Superflow must use the OpenSpec CLI single-level layout:
117
+ `openspec/changes/<change-name>/`.
118
+ - The release version belongs in the change name, not an intermediate
119
+ directory. Encode `v1.1.1` as `v1-1-1-<feature-slug>` and never create
120
+ `changes/v1.1.1/<feature-slug>/`.
121
+ - Keep exactly one physical directory for each change. Do not create a
122
+ compatibility symlink, copied directory, or second canonical document tree.
123
+ - Run `openspec new change <change-name>` first, then reuse that same physical
124
+ directory for status, instructions, strict validation, state, handoff, and
125
+ every Superflow guard.
126
+ - If a nested version directory or symlinked change is found, stop document
127
+ generation, migrate it to one flat physical directory, and rerun
128
+ `openspec validate <change-name> --strict`.
129
+
82
130
  For a full change, the docs phase must create or refresh:
83
131
 
84
132
  - proposal.md
@@ -22,6 +22,11 @@
22
22
  - Source-of-truth contracts
23
23
  - Architecture boundary
24
24
  - Data model
25
+ - Minimal Design Review: reuse evidence, necessity, simplest implementation,
26
+ removed/rejected complexity, and blockers
27
+ - Count every new table, field, API, service, cache, async flow, scheduled job,
28
+ and compatibility layer; remove items without evidence
29
+ - New-item counts: tables 0; fields 0; APIs 0; services/components 0; caches 0; MQ/events 0; scheduled jobs 0; compatibility layers 0. Replace each count.
25
30
  - Field semantics
26
31
  - Write/read loop
27
32
  - No-fallback decisions
@@ -0,0 +1,34 @@
1
+ # Managed Work Rules
2
+
3
+ Managed work is built into `superflow-pipeline`. The user only says to use
4
+ Superflow and provides an implementation prompt, change directory, or direct
5
+ task. Direct tasks receive a minimal contract. SDD work freezes the generated
6
+ implementation prompt and never substitutes `tasks.md` for the execution prompt.
7
+
8
+ Always dispatch through:
9
+
10
+ ```bash
11
+ superflow pipeline "<implementation-prompt|change-dir|task>" --managed --project "<root>" \
12
+ --supervisor <codex|claude> --executor <claude|codex> --language <en|zh>
13
+ ```
14
+
15
+ The command always starts the independent background service and follows the
16
+ local event journal to a terminal state. Losing the follower does not stop the
17
+ task. After return, the current agent reads the report and summarizes it in the
18
+ original conversation.
19
+
20
+ Hard gates:
21
+
22
+ - Claim the 5/7/12 budgets before an Agent call.
23
+ - Freeze the selected language into the contract; prompts, journals, reports, notifications, errors, and resumed rounds must use that same language.
24
+ - Revalidate the frozen contract hash, non-overridable permissions, and 5/7/12 hard limits on every start and resume. Fail closed if persisted contract data changed.
25
+ - Resolve change directories through `.sdd/state.yaml` `implementation_prompt`; treat `tasks.md` as a checklist only. Copy the prompt into a managed snapshot and freeze its SHA-256 for both agents.
26
+ - Persist and resume exact supervisor and executor session IDs.
27
+ - Treat `progress.jsonl`, the task contract, review results, and evidence as truth.
28
+ - Executor cannot edit managed state or commit, push, publish, deploy, or bypass sandbox.
29
+ - Supervisor cannot modify target files.
30
+ - Non-zero exits, invalid JSON, missing session IDs, and review-time workspace drift block pass.
31
+ - Engineering and SDD tasks need successful command evidence from at least two categories among build, test, and runtime/real invocation. Compile-only or unit-test-only delivery cannot enter formal review.
32
+ - Run `superflow-managed-work-check.mjs <root> <task-id>` before delivery-ready.
33
+ - Append the single `run.delivery_ready` event only after the integrity script passes. On failure, require human attention without leaving false delivery-ready evidence.
34
+ - A passing run waits for explicit Git approval.
@@ -9,10 +9,18 @@
9
9
  - Handoff files exist and hash is current.
10
10
  - design.md records OpenSpec/SDD as WHAT and Superpowers as HOW.
11
11
  - sdd-quality-gate.md records guard command and result.
12
+ - design.md and sdd-quality-gate.md include a Minimal Design Review with reuse
13
+ evidence, necessity, simplest implementation, removed/rejected complexity,
14
+ counts of new tables/fields/APIs/services/caches/async flows/jobs/compatibility
15
+ layers, and a PASS/BLOCKED verdict. Only PASS may leave docs/design.
12
16
 
13
17
  ## Design Gate
14
18
 
15
19
  - Technical design exists for full workflow.
20
+ - Technical design repeats the Minimal Design Review at source level. It extends
21
+ existing modules first and rejects speculative abstractions, parallel APIs or
22
+ models, derivable persistence, premature caches, and async compensation when
23
+ a direct synchronous design satisfies the contract.
16
24
  - Field/status reverse impact matrix exists when risky fields or states change.
17
25
  - Architecture boundary and call-direction matrix exists for cross-service or
18
26
  external flows.
@@ -35,6 +35,17 @@ canonical_sources:
35
35
  |---|---|---|---|---|---|
36
36
  | <R1/S1> | `<file>:<line>` | <observed fact> | <implementation approach> | <files> | <risk> |
37
37
 
38
+ ## Minimal Design Review
39
+
40
+ | Design item | Existing capability/reuse evidence | Necessary? | Simplest implementation | Removed/rejected complexity | Evidence/blocker |
41
+ | ----------- | ---------------------------------- | ---------- | ----------------------- | --------------------------- | ---------------- |
42
+ | `<table/API/service/component/sync>` | `<existing source/API/table/dependency>` | `keep/remove/blocked` | `<minimum implementation>` | `<no parallel abstraction/cache/async/compat layer>` | `<anchor or blocker>` |
43
+
44
+ New-item counts: tables 0; fields 0; APIs 0; services/components 0; caches 0; MQ/events 0; scheduled jobs 0; compatibility layers 0. Replace each count with the actual design total. Extend existing modules first. Do not persist values
45
+ that can be derived safely, and do not add async compensation or caching when a
46
+ single synchronous transaction closes the contract. Every retained item must
47
+ explain why a simpler option fails; remove it when there is no evidence.
48
+
38
49
  ## Architecture Boundary And Call Direction
39
50
 
40
51
  Use this whenever the change crosses repositories, services, SDKs, MQ,
@@ -131,7 +131,7 @@ GUARD="$SCRIPT_DIR/superflow-guard.sh"
131
131
  VALIDATE="$SCRIPT_DIR/superflow-yaml-validate.sh"
132
132
  CHANGE_DIR="$(cd "$CHANGE_DIR" && pwd)"
133
133
  CHANGE_NAME="$(basename "$CHANGE_DIR")"
134
- PROJECT_ROOT="$(cd "$CHANGE_DIR/../.." && pwd)"
134
+ PROJECT_ROOT="$(cd "$CHANGE_DIR/../../.." && pwd)"
135
135
  ARCHIVE_ROOT="$PROJECT_ROOT/openspec/changes/archive"
136
136
  ARCHIVE_NAME="$CHANGE_NAME"
137
137