@buaa_smat/hometrans 26.0.4 → 26.0.5

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 (102) hide show
  1. package/agents/code-reviewer.md +2 -0
  2. package/agents/model-render-worker.md +1 -1
  3. package/i18n/agents/code-reviewer.md +2 -0
  4. package/i18n/agents/model-render-worker.md +1 -1
  5. package/i18n/skills/a2h-app-migrate/SKILL.md +51 -3
  6. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +140 -32
  7. package/i18n/skills/a2h-app-migrate/scripts/dag_graph.mjs +297 -0
  8. package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +134 -21
  9. package/i18n/skills/a2h-app-migrate/test/test_finalize.mjs +21 -4
  10. package/i18n/skills/a2h-app-migrate/test/test_image_probe.mjs +3 -3
  11. package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
  12. package/i18n/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +1 -1
  13. package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +12 -5
  14. package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +7 -8
  15. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -1
  16. package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +27 -15
  17. package/i18n/skills/a2h-batch-ui-align/SKILL.md +1 -1
  18. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +4 -0
  19. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +36 -0
  20. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +4 -0
  21. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +4 -0
  22. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +3 -3
  23. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +8 -0
  24. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_in_linear.ts +164 -0
  25. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/self_drawn_sheet.ts +105 -0
  26. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/staggered_lanes.ts +127 -0
  27. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/window_size_constant.ts +114 -0
  28. package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +4 -1
  29. package/i18n/skills/a2h-page-specgen/references/spec-example.md +35 -5
  30. package/i18n/skills/a2h-page-specgen/references/spec-template.md +4 -4
  31. package/i18n/skills/a2h-spec-generate/SKILL.md +3 -1
  32. package/i18n/skills/a2h-spec-generate/references/fusion-task-contract.md +15 -3
  33. package/i18n/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  34. package/i18n/skills/a2h-spec-generate/references/spec-sample-complex.md +16 -0
  35. package/i18n/skills/a2h-spec-generate/references/spec-sample-transfer.md +16 -0
  36. package/i18n/skills/a2h-spec-generate/references/spec-samples.md +5 -1
  37. package/i18n/skills/a2h-spec-generate/references/synthesis-rules.md +21 -1
  38. package/i18n/skills/a2h-spec-generate/references/worker-rules.md +25 -2
  39. package/i18n/skills/a2h-spec-generate/scripts/check_spec.ts +121 -6
  40. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +2 -1
  41. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +3 -0
  42. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +16 -2
  43. package/i18n/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +11 -2
  44. package/i18n/skills/a2h-spec-generate/test/check-spec.test.ts +35 -0
  45. package/package.json +1 -1
  46. package/skills/a2h-app-migrate/SKILL.md +53 -5
  47. package/skills/a2h-app-migrate/references/workflow.yaml +140 -32
  48. package/skills/a2h-app-migrate/scripts/assert_dag_complete.mjs +226 -0
  49. package/skills/a2h-app-migrate/scripts/dag_graph.mjs +297 -0
  50. package/skills/a2h-app-migrate/scripts/dag_process_executor.mjs +199 -0
  51. package/skills/a2h-app-migrate/scripts/dag_production_executor.mjs +897 -0
  52. package/skills/a2h-app-migrate/scripts/dag_runner.mjs +1767 -0
  53. package/skills/a2h-app-migrate/scripts/ledger.mjs +15 -2
  54. package/skills/a2h-app-migrate/scripts/lib-yaml-lite.mjs +8 -2
  55. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +3 -8
  56. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +134 -21
  57. package/skills/a2h-app-migrate/test/test_dag_complete.mjs +222 -0
  58. package/skills/a2h-app-migrate/test/test_dag_production.mjs +670 -0
  59. package/skills/a2h-app-migrate/test/test_dag_runner.mjs +423 -0
  60. package/skills/a2h-app-migrate/test/test_finalize.mjs +21 -4
  61. package/skills/a2h-app-migrate/test/test_image_probe.mjs +1 -1
  62. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +16 -1
  63. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +1 -1
  64. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +12 -5
  65. package/skills/a2h-arkts-logic-coder/SKILL.md +7 -8
  66. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -1
  67. package/skills/a2h-arkts-logic-coder/references/code-generation.md +27 -15
  68. package/skills/a2h-batch-ui-align/SKILL.md +1 -1
  69. package/skills/a2h-batch-ui-align/references/cards/widgets.md +4 -0
  70. package/skills/a2h-batch-ui-align/references/checker-rules.md +36 -0
  71. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +4 -0
  72. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +4 -0
  73. package/skills/a2h-batch-ui-align/references/step5-convert.md +3 -3
  74. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +49 -3
  75. package/skills/a2h-batch-ui-align/scripts/static_check/core/android.ts +36 -0
  76. package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +8 -0
  77. package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +8 -0
  78. package/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_in_linear.ts +164 -0
  79. package/skills/a2h-batch-ui-align/scripts/static_check/rules/self_drawn_sheet.ts +105 -0
  80. package/skills/a2h-batch-ui-align/scripts/static_check/rules/staggered_lanes.ts +127 -0
  81. package/skills/a2h-batch-ui-align/scripts/static_check/rules/window_size_constant.ts +114 -0
  82. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_coolmall_ds1123.test.mjs +433 -0
  83. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_overlay_in_linear.test.mjs +288 -0
  84. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +46 -0
  85. package/skills/a2h-page-specgen/references/scenario-authoring.md +4 -1
  86. package/skills/a2h-page-specgen/references/spec-example.md +35 -5
  87. package/skills/a2h-page-specgen/references/spec-template.md +4 -4
  88. package/skills/a2h-spec-generate/SKILL.md +3 -1
  89. package/skills/a2h-spec-generate/references/fusion-task-contract.md +15 -3
  90. package/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  91. package/skills/a2h-spec-generate/references/spec-sample-complex.md +16 -0
  92. package/skills/a2h-spec-generate/references/spec-sample-transfer.md +16 -0
  93. package/skills/a2h-spec-generate/references/spec-samples.md +5 -1
  94. package/skills/a2h-spec-generate/references/synthesis-rules.md +21 -1
  95. package/skills/a2h-spec-generate/references/worker-rules.md +25 -2
  96. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +3 -1
  97. package/skills/a2h-spec-generate/scripts/check_spec.ts +262 -6
  98. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +12 -2
  99. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +3 -0
  100. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +16 -2
  101. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +54 -3
  102. package/skills/a2h-spec-generate/test/check-spec.test.ts +247 -0
@@ -6,6 +6,27 @@ version: 2
6
6
  id: a2h-app-migrate
7
7
  skill_root_var: SKILLS_ROOT
8
8
 
9
+ # Deterministic Runner 的就绪节点排序;不构成额外依赖,也不启用并行调度。
10
+ serial_order:
11
+ - bootstrap
12
+ - discover.android_index
13
+ - boot.workspace
14
+ - discover.arch
15
+ - discover.utg_static
16
+ - review.arch
17
+ - discover.utg_snapshot
18
+ - discover.feature_scope
19
+ - ui.batch
20
+ - review.ui_batch
21
+ - enrich.spec_gen
22
+ - review.spec_gen
23
+ - enrich.module_docs
24
+ - barrier.l2_enrich
25
+ - adopt.signing
26
+ - adopt.specs_json
27
+ - logic.spec_pipeline
28
+ - logic.finalize
29
+
9
30
  policy:
10
31
  # 全图只有 ui.batch 一个 device:true 节点(Android 设备,adb),故"同时最多 1 台设备"目前由拓扑天然保证。
11
32
  # 鸿蒙侧冷启动冒烟(hdc)在 discover.arch G10 / ui.batch Step 6.3 / spec_pipeline 收尾各跑一次:
@@ -66,17 +87,18 @@ policy:
66
87
  failure_semantics: |
67
88
  hard_stop:节点失败 → 整条流水线停下,报告失败原因与续跑方式。
68
89
  hard_stop_unless_logic_skipped:同 hard_stop;但 SKIP_LOGIC 为真(或 profile 已 force_skip 逻辑链路)时视为 skipped。
69
- ledger:${LEDGER} 只追加、跨运行保留(profile=resume 靠它知道原运行的 profile 与各节点终态)。boot.workspace 记 run_start;
70
- **每个节点**到终态都记一行:node ${SKILLS_ROOT}/a2h-app-migrate/scripts/ledger.mjs --ledger ${LEDGER} --node <id>
71
- --status done|reused|skipped|failed [--reason <原因>](复用产物而跳过记 reused,按 skip_if / force_skip 跳过记 skipped)。
72
- **开始**真正执行一个节点前(skip / reuse 判定之后、第一个动作之前)先记 `ledger.mjs --ledger ${LEDGER} --node <id> --begin`;
73
- 终态那一行自动带 started_at / duration_s。终态一到就记,不要攒到后面一起补;只有 ledger 还不能写盘时才允许延后:
74
- bootstrap 在 boot.workspace 写 run_start 之后补记 done,必须带 --started-at <bootstrap 开始时的 ISO 时间>(开始时先记下来)。
75
- ui.batch / enrich.spec_gen / logic.spec_pipeline:记终态的**同一条** ledger.mjs 命令顺带写续跑摘要
76
- (ledger.mjs 调 write_resume_summary,status 就是这次写入的终态,run_at = 本轮 run_start.at),不要再单独跑一次:
77
- ui.batch → … --node ui.batch --status <s> --work ${WORK} --hmos ${HMOS}
78
- enrich.spec_gen → … --node enrich.spec_gen --status <s> --work ${WORK} --run-dir ${RUN_DIR}
79
- logic.spec_pipeline → … --node logic.spec_pipeline --status <s> --work ${WORK} --hmos ${HMOS}
90
+ ledger:${LEDGER} 只追加、跨运行保留(profile=resume 靠它知道原运行的 profile 与各节点终态)。boot.workspace 成功后由 Runner 提交 run_start;
91
+ **每个节点**到终态都由 Runner 通过 ledger.mjs 提交一行(等效参数:--ledger ${LEDGER} --node <id>
92
+ --status done|reused|skipped|failed [--reason <原因>];复用产物而跳过记 reused,按 skip_if / force_skip 跳过记 skipped)。
93
+ **开始**真正执行一个节点前(skip / reuse 判定之后、第一个动作之前)由 Runner 记等效于 `--node <id> --begin` 的开始记录;
94
+ 终态那一行自动带 started_at / duration_s。终态一到就记,不要攒到后面一起补。
95
+ 宿主与生产 executor 不得自行追加节点终态、run_start 或 run_end;bootstrap 的 done 也只在 run_start 之后由 Runner 提交(ledger 在它之前还不能写盘),并带开始时的 ISO 时间。
96
+ ui.batch / enrich.spec_gen / logic.spec_pipeline:记 ledger **之后立刻**(同一终态步骤内,
97
+ 终态已确定)跑 write_resume_summary.mjs,把刚写入 ledger 的 status 原样传给 --status,
98
+ 并带 --ledger ${LEDGER}(写入 run_at = 本轮 run_start.at,防误读上一轮):
99
+ ui.batch → --work ${WORK} --node ui.batch --hmos ${HMOS} --status <s> --ledger ${LEDGER}
100
+ enrich.spec_gen → --work ${WORK} --node enrich.spec_gen --run-dir ${RUN_DIR} --status <s> --ledger ${LEDGER}
101
+ logic.spec_pipeline → --work ${WORK} --node logic.spec_pipeline --hmos ${HMOS} --status <s> --ledger ${LEDGER}
80
102
  status=skipped → 写 ok:false 墓碑(不投影叶子里可能仍是上一轮的页数 / wave);
81
103
  done|failed|reused → 从叶子产物投影。写盘失败尽量改写墓碑,再失败则删掉旧文件。
82
104
  **禁止**挂在 after_run:那时尚未判 success,--status 还不知道;且 skip 路径根本不跑 after_run。
@@ -270,7 +292,8 @@ policy:
270
292
  scaffold_new(HMOS 不存在/为空/只剩 .git·.DS_Store·.hometrans;判空同 create_project,忽略这三项;.hometrans 是 HomeTrans 自己的记录,建壳时临时移开再放回)
271
293
  时 arch 必须先建壳,否则 boot.workspace / utg_static 会把目录写脏。处理:paths_preflight 非破坏探测;
272
294
  boot.workspace 在 ${SERIALIZE_DISCOVER} 时 needs discover.arch;utg_static 挂 boot.workspace。
273
- 于是 existing_project 与 scaffold_new 一致 → arch → utg_static(scaffold_new 中间多经 boot.workspace)。
295
+ 于是两模式都是 arch → utg_static。serial_order 把 boot.workspace 排在 arch 前:existing_project 时先跑它、
296
+ 先提交 run_start,arch 失败也有本轮 ledger;scaffold_new 时条件边仍让它等 arch 建壳(arch → boot.workspace → utg_static)。
274
297
  ⚠ validate_workflow 按最大并行(忽略 conditional_needs)做竞争检查。
275
298
 
276
299
  ⚠ 静态 UTG 两个目录始终分开。discover.utg_static 写 ${UTG_DIR}(默认 ${WORK}/utg_static)。
@@ -442,6 +465,7 @@ vars:
442
465
  # enrich.spec_gen 开跑前由 run_dir.mjs 决定(未完成的 run 续跑沿用,否则新建)。
443
466
  # 用户显式给 run_dir= 时照用。<run-id> 仅为占位。
444
467
  RUN_DIR: { required: false, from: run_dir, default: "${WORK}/reqgen/<run-id>", set_by: "run_dir.mjs(指针 ${WORK}/reqgen/current.json)" }
468
+ RUN_DIR_GIVEN: { required: false, default: false, set_true_when: "用户显式传入 run_dir" }
445
469
  # discover.utg_static 的私有输出目录。**不要**设成 ${UI_UTG_DIR}。ui.batch 只复制进去,两个节点不写同一目录。
446
470
  UTG_DIR: { required: false, default: "${WORK}/utg_static" }
447
471
  # a2h-batch-ui-align 固定使用的 UTG 目录(复制目标,或 Step 3.1 重跑时的写入目录;Step 3.2 只读它),不可配置。
@@ -478,6 +502,9 @@ nodes:
478
502
  - id: bootstrap
479
503
  lane: boot
480
504
  type: local
505
+ runner:
506
+ action: production
507
+ kind: bootstrap
481
508
  user_facing:
482
509
  announce: fail_only
483
510
  name: 启动检查
@@ -499,7 +526,7 @@ nodes:
499
526
  # 会拿错目录去判,直接 hard_stop。也排在 probe 之前:PROFILE 要先换成原运行的 profile,
500
527
  # 后面的复用决策 / 预检都按它。
501
528
  - plan_resume:
502
- when: "${PROFILE} == resume 或 ${FROM_NODE} != bootstrap"
529
+ when: "${PROFILE} == 'resume' or ${FROM_NODE} != 'bootstrap'"
503
530
  script: "${SKILLS_ROOT}/a2h-app-migrate/scripts/resume_plan.mjs"
504
531
  runner: node
505
532
  args: "--workflow ${SKILLS_ROOT}/a2h-app-migrate/references/workflow.yaml --ledger ${LEDGER} --from-node ${FROM_NODE} [--base-profile ${RESUME_BASE_PROFILE} 仅当非空] --engine ${SPEC_ENGINE} --engine-given ${SPEC_ENGINE_GIVEN}"
@@ -782,7 +809,7 @@ nodes:
782
809
  # 环境读图探测(语义见 policy.image_read)。本轮不跑 ui.batch(REUSE_UI_BATCH)或 IMAGE_READ 已非 probe 时跳过。
783
810
  # 结论只用于 tip,**禁止**传给 ui.batch——叶子 Step 1 会再探测一次。
784
811
  - probe_image_read:
785
- skip_when: "${IMAGE_READ} != probe or ${REUSE_UI_BATCH} == true"
812
+ skip_when: "${IMAGE_READ} != 'probe' or ${REUSE_UI_BATCH} == true"
786
813
  steps: |
787
814
  1) node ${SKILLS_ROOT}/a2h-batch-ui-align/scripts/image_probe.mjs prepare --dir <PROBE_DIR>
788
815
  → stdout 一行 JSON {image, state, prompt}。(与 a2h-batch-ui-align Step 1 共用同一脚本;不传 --hp,结论只交给编排器 tip。)
@@ -818,6 +845,9 @@ nodes:
818
845
  - id: boot.workspace
819
846
  lane: boot
820
847
  type: local
848
+ runner:
849
+ action: production
850
+ kind: workspace
821
851
  user_facing:
822
852
  announce: fail_only
823
853
  name: 工作目录
@@ -846,7 +876,7 @@ nodes:
846
876
  script: "${SKILLS_ROOT}/a2h-app-migrate/scripts/write_resume_summary.mjs"
847
877
  runner: node
848
878
  args: "--work ${WORK} --clear-stale"
849
- when: "${FROM_NODE} == null or ${FROM_NODE} == '' or ${FROM_NODE} == bootstrap"
879
+ when: "${FROM_NODE} == null or ${FROM_NODE} == '' or ${FROM_NODE} == 'bootstrap'"
850
880
  exit_other: 继续
851
881
  success:
852
882
  - all:
@@ -860,6 +890,9 @@ nodes:
860
890
  - id: discover.android_index
861
891
  lane: discover
862
892
  type: local
893
+ runner:
894
+ action: production
895
+ kind: script
863
896
  user_facing:
864
897
  announce: fail_only
865
898
  name: 代码索引
@@ -884,6 +917,10 @@ nodes:
884
917
  - id: discover.utg_static
885
918
  lane: discover
886
919
  type: skill
920
+ runner:
921
+ action: production
922
+ kind: skill
923
+ reuse_if: "${REUSE_DISCOVER_UTG} == true"
887
924
  # 与 ui.batch Step 3.1 用同一个 Node 版(同一个 App 两条链路的页面节点 id 一致)。
888
925
  skill: a2h-utg-static
889
926
  user_facing:
@@ -893,14 +930,16 @@ nodes:
893
930
  done: "页面关系整理完了。页面 {nodes} 个,跳转 {edges} 条。没有缺项。后面写功能清单会用这份关系。"
894
931
  failed: "页面关系没整理完:{reason}。没有这份关系就不能写功能清单。"
895
932
  reused: "这轮没有重做页面关系,沿用上次整理的结果。"
896
- skipped: "这轮不写功能清单,所以没有整理页面关系。"
933
+ skipped: "这轮不重新写功能清单,所以没有整理页面关系。"
897
934
  dispatch: "primary_skill_inline"
898
935
  # 挂 boot.workspace:scaffold_new 的串行化经它传播,见 policy.parallel_rule。
899
936
  needs: [boot.workspace, discover.android_index]
900
937
  parallel_group: discover_par
901
938
  # 唯一消费者是 discover.utg_snapshot → enrich.spec_gen(UI 链路用自己的 ${UI_UTG_DIR})。spec 生成本轮不跑
902
939
  #(跳过 / 复用 / ui-only)时它只是挡在 review.arch 前面的关键路径,不要跑。
903
- skip_if: "${REUSE_DISCOVER_UTG} == true or ${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE} or ${REUSE_SPEC_GENERATE} == true or ${PROFILE} == ui-only"
940
+ # REUSE_SPEC_GENERATE 是消费者的复用(不是本节点的),所以写在 skip_if;条件须与 discover.utg_snapshot 的 when 保持一致。
941
+ # validate_workflow.mjs 的 CROSS_NODE_REUSE_IN_SKIP_IF 为它单独放行;本节点自己的复用只在 runner.reuse_if。
942
+ skip_if: "${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE} or ${REUSE_SPEC_GENERATE} == true or ${PROFILE} == 'ui-only'"
904
943
  reads: { android_index: "${ANDROID}/.homegraph/" }
905
944
  writes: { workspace: "${UTG_DIR}/", utg: "${UTG_DIR}/utg.json", click_paths: "${UTG_DIR}/click_paths.json" }
906
945
  # 驱动器的退出码不可信:stage 失败照样 exit 0;只看文件存在会被上一轮残留的 Phase B 产物骗过;
@@ -979,6 +1018,10 @@ nodes:
979
1018
  - id: discover.arch
980
1019
  lane: discover
981
1020
  type: skill
1021
+ runner:
1022
+ action: production
1023
+ kind: skill
1024
+ reuse_if: "${REUSE_DISCOVER_ARCH} == true"
982
1025
  skill: a2h-arch-generate
983
1026
  user_facing:
984
1027
  announce: always
@@ -992,7 +1035,7 @@ nodes:
992
1035
  needs: [bootstrap, discover.android_index]
993
1036
  parallel_group: discover_par
994
1037
  dispatch: "primary_skill_inline"
995
- skip_if: "${REUSE_DISCOVER_ARCH} == true or ${SKIP_DISCOVER_ARCH}"
1038
+ skip_if: "${SKIP_DISCOVER_ARCH}"
996
1039
  # 真正执行前清闸门 checkpoint(生命周期见 policy.human_interaction)。
997
1040
  before_run:
998
1041
  - clear_gate_checkpoint:
@@ -1049,6 +1092,13 @@ nodes:
1049
1092
  - id: review.arch
1050
1093
  lane: discover
1051
1094
  type: adopt
1095
+ runner:
1096
+ action: production
1097
+ kind: gate
1098
+ gate: arch
1099
+ checkpoint: "${CHECKPOINT_DIR}/arch-reviewed.ok"
1100
+ rewind_to: discover.arch
1101
+ rewind_clear_vars: [REUSE_DISCOVER_ARCH]
1052
1102
  needs: [discover.arch, discover.utg_static]
1053
1103
  also_needs_group: discover_par
1054
1104
  human_gate: true
@@ -1087,6 +1137,9 @@ nodes:
1087
1137
  - id: discover.utg_snapshot
1088
1138
  lane: discover
1089
1139
  type: local
1140
+ runner:
1141
+ action: production
1142
+ kind: snapshot
1090
1143
  needs: [review.arch]
1091
1144
  summary: 把 ${UTG_DIR} 冻结为 ${UTG_SNAPSHOT},供 enrich.spec_gen 只读
1092
1145
  user_facing:
@@ -1113,14 +1166,14 @@ nodes:
1113
1166
  script: "${SKILLS_ROOT}/a2h-app-migrate/scripts/ensure_utg_snapshot.mjs"
1114
1167
  runner: node
1115
1168
  args: "--from ${UTG_DIR} --to ${UTG_SNAPSHOT}"
1116
- when: "not (${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE} or ${REUSE_SPEC_GENERATE} == true or ${PROFILE} == ui-only)"
1169
+ when: "not (${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE} or ${REUSE_SPEC_GENERATE} == true or ${PROFILE} == 'ui-only')"
1117
1170
  exit_nonzero: hard_stop
1118
1171
  success:
1119
1172
  - any:
1120
1173
  - all:
1121
1174
  - file_exists: "${UTG_SNAPSHOT}/utg.json"
1122
1175
  - file_exists: "${UTG_SNAPSHOT}/click_paths.json"
1123
- - when: "${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE} or ${REUSE_SPEC_GENERATE} == true or ${PROFILE} == ui-only"
1176
+ - when: "${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE} or ${REUSE_SPEC_GENERATE} == true or ${PROFILE} == 'ui-only'"
1124
1177
  on_fail: hard_stop
1125
1178
 
1126
1179
  # 功能级增量范围(hometrans-incremental.html「功能级增量」F-8):输入不是页面清单时,在界面转换之前把它解析成
@@ -1128,6 +1181,7 @@ nodes:
1128
1181
  - id: discover.feature_scope
1129
1182
  lane: discover
1130
1183
  type: local
1184
+ runner: { action: production, kind: host_action }
1131
1185
  needs: [discover.utg_snapshot]
1132
1186
  summary: 把功能描述 / 需求文档 / Android 版本差异 / 已确认的范围文件解析成功能级 scope.json(v2)
1133
1187
  user_facing:
@@ -1147,6 +1201,10 @@ nodes:
1147
1201
  - script_exit_0: { runner: node, script: "${SKILLS_ROOT}/a2h-app-migrate/scripts/scope_model.mjs", args: "check ${HMOS}/.hometrans/incremental/scope.json --existing ${HMOS}/.hometrans/incremental/existing.json --ledger ${HMOS}/.hometrans/migration_manifest.json" }
1148
1202
  - when: "${FEATURE_SCOPE} == false"
1149
1203
  - skipped: true
1204
+ actions:
1205
+ - host_action:
1206
+ action: discover_feature_scope
1207
+ reason: 按 invoke 解析并确认增量范围;auto 下由宿主自行定案,interactive 下按 F5 等用户确认
1150
1208
  invoke: |
1151
1209
  上下文预算、上下文窗口、token 余量、会话变长或即将压缩,都不是结束理由(policy.context_budget)。
1152
1210
  先判定输入(按这个顺序,命中即停):
@@ -1176,6 +1234,11 @@ nodes:
1176
1234
  - id: enrich.spec_gen
1177
1235
  lane: enrich
1178
1236
  type: skill
1237
+ runner:
1238
+ action: production
1239
+ kind: skill
1240
+ reuse_if: "${REUSE_SPEC_GENERATE} == true"
1241
+ after_terminal: resume_summary
1179
1242
  skill: ${SPEC_ENGINE} → skill_by_engine
1180
1243
  skill_by_engine: { spec-generate: a2h-spec-generate, page-specgen: a2h-page-specgen }
1181
1244
  user_facing:
@@ -1190,7 +1253,7 @@ nodes:
1190
1253
  parallel_group: post_utg
1191
1254
  dispatch: "primary_skill_inline"
1192
1255
  needs: [discover.utg_snapshot, discover.feature_scope]
1193
- skip_if: "${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE} or ${REUSE_SPEC_GENERATE} == true"
1256
+ skip_if: "${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE}"
1194
1257
  # 真正执行前清闸门 checkpoint(生命周期见 policy.human_interaction)。
1195
1258
  before_run:
1196
1259
  - clear_gate_checkpoint:
@@ -1367,6 +1430,13 @@ nodes:
1367
1430
  - id: review.spec_gen
1368
1431
  lane: adopt
1369
1432
  type: adopt
1433
+ runner:
1434
+ action: production
1435
+ kind: gate
1436
+ gate: spec_gen
1437
+ checkpoint: "${CHECKPOINT_DIR}/spec-gen-reviewed.ok"
1438
+ rewind_to: enrich.spec_gen
1439
+ rewind_clear_vars: [REUSE_SPEC_GENERATE]
1370
1440
  needs: [enrich.spec_gen]
1371
1441
  skip_if: "${SKIP_LOGIC} or ${SKIP_SPEC_GENERATE}"
1372
1442
  human_gate: true
@@ -1406,6 +1476,11 @@ nodes:
1406
1476
  - id: ui.batch
1407
1477
  lane: enrich
1408
1478
  type: skill
1479
+ runner:
1480
+ action: production
1481
+ kind: skill
1482
+ reuse_if: "${REUSE_UI_BATCH} == true"
1483
+ after_terminal: resume_summary
1409
1484
  skill: a2h-batch-ui-align
1410
1485
  user_facing:
1411
1486
  announce: always
@@ -1418,8 +1493,8 @@ nodes:
1418
1493
  dispatch: "primary_skill_inline"
1419
1494
  needs: [discover.utg_snapshot, discover.arch, discover.feature_scope]
1420
1495
  also_needs_group: discover_par
1421
- # 功能级范围里一个页面都没有(只有无界面逻辑)时界面转换无事可做
1422
- skip_if: "${REUSE_UI_BATCH} == true or (${PROFILE} == incremental and ${FEATURE_SCOPE} == true and ${SCOPE_PAGES} == 0)"
1496
+ # 功能级范围里一个页面都没有(只有无界面逻辑)时界面转换无事可做;REUSE_UI_BATCH 只由 runner.reuse_if 消费。
1497
+ skip_if: "${PROFILE} == incremental and ${FEATURE_SCOPE} == true and ${SCOPE_PAGES} == 0"
1423
1498
  # 真正执行前清闸门 checkpoint(生命周期见 policy.human_interaction)。
1424
1499
  before_run:
1425
1500
  - clear_gate_checkpoint:
@@ -1461,7 +1536,7 @@ nodes:
1461
1536
  # 禁止传 image_read=(policy.image_read):由 a2h-batch-ui-align Step 1 自行探测并写入 host_caps.json
1462
1537
  [reuse_static_workspace=${UTG_DIR} 仅当本轮 discover.utg_static 实际跑过]
1463
1538
  # 下列任一为真则本轮没跑,**不要传**这个参数,Step 3.1 自己跑:
1464
- # ${REUSE_DISCOVER_UTG} / ${SKIP_LOGIC} / ${SKIP_SPEC_GENERATE} / ${REUSE_SPEC_GENERATE} == true / ${PROFILE} == ui-only
1539
+ # ${REUSE_DISCOVER_UTG} / ${SKIP_LOGIC} / ${SKIP_SPEC_GENERATE} / ${REUSE_SPEC_GENERATE} == true / ${PROFILE} == 'ui-only'
1465
1540
  [takeover_allowed=true 仅当 本次 migrate 已经跑过一次 ui.batch:本轮 ledger 里 ui.batch 记了 failed,或 review.ui_batch 选了「重跑」]
1466
1541
  【无人值守约定(policy.leaf_questions)】
1467
1542
  · Step 2 a2h-resource-convert 的应用模块就是上面传入的 app_module(与 spec 链路同一个),不要问用户;
@@ -1548,6 +1623,13 @@ nodes:
1548
1623
  - id: review.ui_batch
1549
1624
  lane: enrich
1550
1625
  type: adopt
1626
+ runner:
1627
+ action: production
1628
+ kind: gate
1629
+ gate: ui_batch
1630
+ checkpoint: "${CHECKPOINT_DIR}/ui-batch-reviewed.ok"
1631
+ rewind_to: ui.batch
1632
+ rewind_clear_vars: [REUSE_UI_BATCH]
1551
1633
  needs: [ui.batch]
1552
1634
  human_gate: true
1553
1635
  user_facing:
@@ -1617,6 +1699,10 @@ nodes:
1617
1699
  - id: enrich.module_docs
1618
1700
  lane: enrich
1619
1701
  type: skill
1702
+ runner:
1703
+ action: production
1704
+ kind: skill
1705
+ reuse_if: "${REUSE_MODULE_DOCS} == true"
1620
1706
  skill: a2h-module-semantic-docs
1621
1707
  user_facing:
1622
1708
  announce: always
@@ -1631,7 +1717,7 @@ nodes:
1631
1717
  # (needs 仍只挂 ui.batch;开跑顺序见 policy.parallel_rule / schedule_hint)。
1632
1718
  needs: [discover.arch, ui.batch]
1633
1719
  dispatch: "primary_skill_inline"
1634
- skip_if: "${SKIP_MODULE_DOCS} or ${REUSE_MODULE_DOCS} == true"
1720
+ skip_if: "${SKIP_MODULE_DOCS}"
1635
1721
  # 状态文件跨运行保留(它是 --incremental preserve 的增量基线,不能删),只看存在会被上一轮冒充成功。
1636
1722
  # 开跑前记下时间,success 要求状态文件不早于它。
1637
1723
  before_run:
@@ -1682,6 +1768,9 @@ nodes:
1682
1768
  - id: barrier.l2_enrich
1683
1769
  lane: enrich
1684
1770
  type: local
1771
+ runner:
1772
+ action: production
1773
+ kind: barrier
1685
1774
  # ui 侧等 review.ui_batch(已蕴含 ui.batch;force_skip 时该 need 以 skipped 终态满足)。
1686
1775
  # spec 侧仍等 enrich.spec_gen(review.spec_gen 在 adopt 前另卡,可在本屏障之外单独收尾)。
1687
1776
  # 不在此再跑 --assert-ready:闸门本身 exit=1 已足够拦住 interactive 路径。
@@ -1704,6 +1793,10 @@ nodes:
1704
1793
  - id: adopt.signing
1705
1794
  lane: adopt
1706
1795
  type: local
1796
+ runner:
1797
+ action: production
1798
+ kind: host_action
1799
+ reuse_if: "${REUSE_LOGIC_PIPELINE} == true"
1707
1800
  user_facing:
1708
1801
  announce: always
1709
1802
  name: 签名
@@ -1712,7 +1805,7 @@ nodes:
1712
1805
  failed: "签名还没配好:{reason}。"
1713
1806
  skipped: "这轮不写业务逻辑,没有检查签名。"
1714
1807
  needs: [barrier.l2_enrich]
1715
- skip_if: "${SKIP_LOGIC} or ${SKIP_LOGIC_PIPELINE} or ${REUSE_LOGIC_PIPELINE} == true"
1808
+ skip_if: "${SKIP_LOGIC} or ${SKIP_LOGIC_PIPELINE}"
1716
1809
  writes: { build_profile: "${HMOS}/build-profile.json5" }
1717
1810
  success:
1718
1811
  - any:
@@ -1757,6 +1850,9 @@ nodes:
1757
1850
  - id: adopt.specs_json
1758
1851
  lane: adopt
1759
1852
  type: adopt
1853
+ runner:
1854
+ action: production
1855
+ kind: adopt_specs
1760
1856
  user_facing:
1761
1857
  announce: fail_only
1762
1858
  name: 采用规格清单
@@ -1784,6 +1880,11 @@ nodes:
1784
1880
  - id: logic.spec_pipeline
1785
1881
  lane: logic
1786
1882
  type: skill
1883
+ runner:
1884
+ action: production
1885
+ kind: skill
1886
+ reuse_if: "${REUSE_LOGIC_PIPELINE} == true"
1887
+ after_terminal: resume_summary
1787
1888
  skill: a2h-spec-design-pipeline
1788
1889
  user_facing:
1789
1890
  announce: always
@@ -1798,7 +1899,7 @@ nodes:
1798
1899
  # 本节点前后都没有可并行的节点(needs adopt.specs_json,后继只有 logic.finalize),Task 换不来并行。
1799
1900
  dispatch: primary_skill_inline
1800
1901
  needs: [adopt.specs_json, adopt.signing]
1801
- skip_if: "${SKIP_LOGIC} or ${SKIP_LOGIC_PIPELINE} or ${REUSE_LOGIC_PIPELINE} == true"
1902
+ skip_if: "${SKIP_LOGIC} or ${SKIP_LOGIC_PIPELINE}"
1802
1903
  # 本节点**真正执行**前:仅硬指纹不一致(exit 4)或全失败(exit 3)才归档。
1803
1904
  # exit 4:specs.json 内容 / 硬路径与本轮不一致 → 不归档的话 pipeline I1 也会中止,之后每轮卡死。
1804
1905
  # exit 3:全部 group failed → 原样续跑只会重跑冒烟 + Finalization;重试必须新开一轮。
@@ -1871,6 +1972,9 @@ nodes:
1871
1972
  - id: logic.finalize
1872
1973
  lane: finalize
1873
1974
  type: local
1975
+ runner:
1976
+ action: production
1977
+ kind: host_action
1874
1978
  needs: [logic.spec_pipeline]
1875
1979
  summary: 汇总报告 + 最终构建兜底
1876
1980
  user_facing:
@@ -1879,11 +1983,13 @@ nodes:
1879
1983
  doing: "正在汇总这轮迁移结果。需要时会再编译一次鸿蒙工程。"
1880
1984
  done: "这轮迁移的报告已经写好,文件是工作区里的 logic-convert-report.md。编译结论、界面转换和功能清单都写在这份报告里。"
1881
1985
  failed: "收尾报告没写完:{reason}。"
1986
+ success:
1987
+ - file_exists: "${LOGIC_REPORT}"
1882
1988
  invoke: |
1883
- 对用户呈现按 policy.user_facing:开跑发 user_facing.doing,写完发 user_facing.done,写不成发 user_facing.failed。
1884
- 报告正文仍按下面 1–4 步写全。阶段名用各自的 user_facing.name(界面转换、功能清单、模块介绍、业务逻辑、签名),不写节点 id。
1989
+ 对用户呈现按 policy.user_facing:开跑发 user_facing.doing;Runner 完成节点终态和 run_end 后才发 user_facing.done,写不成发 user_facing.failed。
1990
+ 报告正文按下面 1–3 步写全,返回协议按第 4 步执行。阶段名用各自的 user_facing.name(界面转换、功能清单、模块介绍、业务逻辑、签名),不写节点 id。
1885
1991
  1. 最终构建兜底——只在需要时跑,且不得在工作区留下未提交改动
1886
- 0. logic.spec_pipeline 本轮被 skip(${SKIP_LOGIC} / ${SKIP_LOGIC_PIPELINE} / ${REUSE_LOGIC_PIPELINE} == true / ${PROFILE} == ui-only)→
1992
+ 0. logic.spec_pipeline 本轮被 skip(${SKIP_LOGIC} / ${SKIP_LOGIC_PIPELINE} / ${REUSE_LOGIC_PIPELINE} == true / ${PROFILE} == 'ui-only')→
1887
1993
  **不构建、不提交**:本轮没有逻辑改动可兜底(UI 链路 ui.batch 自己构建过);复用时构建早已在
1888
1994
  产出它的那一轮完成。报告写"这轮没有写业务逻辑,没有再编译。",直接进入第 2 步。
1889
1995
  (spec-design-pipeline 的 W0 要求主干干净:**任何**未提交改动都直接停止;只有 Mid-flight 重入时、脏文件全是
@@ -1900,7 +2006,7 @@ nodes:
1900
2006
  · ${HMOS} 不是 git 仓库 → 照常运行修复但不提交,报告注明。
1901
2007
  c. 报告写一行编译结论,用这句人话里的一种:业务逻辑那一步已经编译通过 / 编译通过 / 修复后编译通过(附 commit hash)/ 编译仍未通过 / 工作区有未提交改动,没有编译。
1902
2008
  2. 报告里加「业务逻辑」一节,先按 logic.spec_pipeline 本轮的处置分三种:
1903
- · 跳过(${SKIP_LOGIC} 或 ${SKIP_LOGIC_PIPELINE} 或 ${PROFILE} == ui-only)→ **不读** spec_pipeline_state.json / design_map.md /
2009
+ · 跳过(${SKIP_LOGIC} 或 ${SKIP_LOGIC_PIPELINE} 或 ${PROFILE} == 'ui-only')→ **不读** spec_pipeline_state.json / design_map.md /
1904
2010
  claim_audit.json:那是之前某一轮留下的,不是本轮结果。报告写"这轮没有写业务逻辑。";
1905
2011
  state 文件存在时只加一句"有一份更早的进度记录,不是这轮的结果,没有写进本报告"。
1906
2012
  · 复用(${REUSE_LOGIC_PIPELINE} == true)→ 照常读取(探测 7 已核对它属于本轮输入),
@@ -1940,7 +2046,9 @@ nodes:
1940
2046
  node ${SKILLS_ROOT}/a2h-app-migrate/scripts/scope_report.mjs --hmos ${HMOS} --scope-json ${SCOPE_JSON}
1941
2047
  --specs-json ${SPECS_JSON} --android ${ANDROID} --utg <同上的页面图> --work ${WORK} --lang zh
1942
2048
  它永不失败本节点;缺哪份输入就少哪部分。
1943
- 5. 只返回 ok|fail 与报告路径。
2049
+ 5. 报告落盘后只返回 ok|fail 与报告路径。不要自行追加 logic.finalize 终态或 run_end:
2050
+ Runner 先核对报告并提交唯一的 logic.finalize done,再执行全 DAG 完成度硬闸门并写唯一 run_end。
2051
+ assert 非零或证据不完整时由 Runner 阻止发证;宿主不得把阶段报告冒充完成证书。
1944
2052
 
1945
2053
  schedule_hint:
1946
2054
  # discover_par 条件并行与 scaffold_new 串行退化见 policy.parallel_rule,这里不重复。
@@ -0,0 +1,226 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Assert that the current run in stage-ledger.jsonl has reached a DAG-wide terminal state.
4
+ *
5
+ * node assert_dag_complete.mjs --workflow <workflow.yaml> --ledger <stage-ledger.jsonl> --profile <full|ui-only>
6
+ * [--require-complete] [--write-run-end] [--logic-report <path>] [--state <spec_pipeline_state.json>]
7
+ *
8
+ * Without --require-complete, an incomplete DAG is reported on stdout but exits 0 for diagnostics. --require-complete
9
+ * turns an incomplete DAG into exit 1. --write-run-end implies --require-complete and appends one run_end record after
10
+ * all checks pass; repeated calls are idempotent. A soft_continue failure produces completed_with_failures, not success.
11
+ *
12
+ * Exit codes: 0 complete (or diagnostic mode); 1 incomplete; 2 invalid ledger/completion evidence; 3 hard-stop failure.
13
+ */
14
+ import fs from "node:fs";
15
+ import path from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+
18
+ import { checkStateFile } from "./check_spec_pipeline_done.mjs";
19
+ import { buildGraph } from "./dag_graph.mjs";
20
+ import { appendLedger, NODE_STATUSES, readLedger } from "./ledger.mjs";
21
+ import yaml from "./lib-yaml-lite.mjs";
22
+ import { parseArgs } from "./paths_preflight.mjs";
23
+
24
+ const SOFT_CONTINUE = "soft_continue";
25
+
26
+ function result(code, summary) {
27
+ return { code, summary: { ok: code === 0, complete: code === 0, can_final: code === 0, ...summary } };
28
+ }
29
+
30
+ function lastRunStart(records) {
31
+ for (let i = records.length - 1; i >= 0; i--) {
32
+ if (records[i].event === "run_start") return { record: records[i], index: i };
33
+ }
34
+ return null;
35
+ }
36
+
37
+ function defaultPaths(ledger) {
38
+ const work = path.dirname(path.resolve(ledger));
39
+ const hometrans = path.dirname(work);
40
+ return {
41
+ logicReport: path.join(work, "logic-convert-report.md"),
42
+ state: path.join(hometrans, "spec_pipeline_state.json"),
43
+ };
44
+ }
45
+
46
+ /** Pure DAG/ledger evaluation, except for the two read-only artifact checks at the final boundary. */
47
+ export function evaluateDag(doc, records, { profile, logicReport, state } = {}) {
48
+ const start = lastRunStart(records);
49
+ if (!start) return result(2, { status: "invalid", error: "ledger has no run_start record" });
50
+ if (!profile || !doc.profiles?.[profile] || profile === "resume") {
51
+ return result(2, { status: "invalid", error: `--profile must name a concrete workflow profile, got ${profile || "(empty)"}` });
52
+ }
53
+ if (start.record.profile !== profile) {
54
+ return result(2, {
55
+ status: "invalid",
56
+ error: `current run uses profile ${start.record.profile || "(empty)"}, not ${profile}`,
57
+ });
58
+ }
59
+
60
+ const runId = start.record.run_id || start.record.at || `run-${start.index}`;
61
+ const runRecords = records.slice(start.index + 1);
62
+ const runEnds = runRecords.filter((record) => record.event === "run_end");
63
+ if (runEnds.length > 1) return result(2, { status: "invalid", run_id: runId, error: "current run has multiple run_end records" });
64
+ if (runEnds.length === 1 && runRecords[runRecords.length - 1] !== runEnds[0]) {
65
+ return result(2, { status: "invalid", run_id: runId, error: "run_end is stale: later records exist in the same run" });
66
+ }
67
+ if (runEnds[0]?.run_id && runEnds[0].run_id !== runId) {
68
+ return result(2, { status: "invalid", run_id: runId, error: "run_end belongs to a different run_id" });
69
+ }
70
+
71
+ const graph = buildGraph(doc, { profile });
72
+ const { nodes, byId, activeIds } = graph;
73
+ const activeNodes = nodes.filter((node) => activeIds.has(node.id));
74
+ const statuses = new Map();
75
+ const invalid = [];
76
+
77
+ for (const record of runRecords) {
78
+ if (record.event !== "node") continue;
79
+ if (!byId.has(record.node)) {
80
+ invalid.push({ node: record.node, reason: "unknown workflow node" });
81
+ continue;
82
+ }
83
+ if (!activeIds.has(record.node)) continue;
84
+ if (!NODE_STATUSES.includes(record.status)) {
85
+ invalid.push({ node: record.node, status: record.status, reason: "non-terminal or unknown status" });
86
+ continue;
87
+ }
88
+ statuses.set(record.node, record);
89
+ }
90
+
91
+ for (const node of activeNodes) {
92
+ const record = statuses.get(node.id);
93
+ if (!record) continue;
94
+ if ((record.status === "skipped" || record.status === "reused") && !node.skip_if && !(record.status === "reused" && node.runner?.reuse_if)) {
95
+ const failurePolicy = doc.fail_matrix?.[node.id] || node.on_fail;
96
+ const policySkip = record.status === "skipped" && failurePolicy === "hard_stop_unless_logic_skipped";
97
+ if (!policySkip) invalid.push({ node: node.id, status: record.status, reason: "node has no skip_if/reuse contract" });
98
+ }
99
+ if (record.status === "failed" && !String(record.reason || "").trim()) {
100
+ invalid.push({ node: node.id, status: record.status, reason: "failed status requires failure evidence in reason" });
101
+ }
102
+ }
103
+ if (invalid.length) return result(2, { status: "invalid", run_id: runId, invalid });
104
+
105
+ const failedHard = activeNodes
106
+ .filter((node) => statuses.get(node.id)?.status === "failed" && (doc.fail_matrix?.[node.id] || node.on_fail) !== SOFT_CONTINUE)
107
+ .map((node) => ({ node: node.id, reason: statuses.get(node.id).reason }));
108
+ const missing = activeNodes.filter((node) => !statuses.has(node.id)).map((node) => node.id);
109
+ if (failedHard.length) {
110
+ return result(3, { status: "failed", run_id: runId, failed_hard: failedHard, missing, next_nodes: [] });
111
+ }
112
+
113
+ const nextNodes = activeNodes
114
+ .filter((node) => !statuses.has(node.id))
115
+ .filter((node) => [...(graph.parents[node.id] || [])].every((id) => !activeIds.has(id) || statuses.has(id)))
116
+ .map((node) => node.id);
117
+ if (missing.length) {
118
+ return result(1, { status: "running", run_id: runId, missing, next_nodes: nextNodes });
119
+ }
120
+
121
+ const finalize = statuses.get("logic.finalize");
122
+ if (activeIds.has("logic.finalize") && finalize?.status !== "done") {
123
+ return result(1, {
124
+ status: "running",
125
+ run_id: runId,
126
+ missing: [],
127
+ unfinished: ["logic.finalize"],
128
+ next_nodes: ["logic.finalize"],
129
+ reason: "logic.finalize must be done; a failed report cannot certify DAG completion",
130
+ });
131
+ }
132
+
133
+ const logic = statuses.get("logic.spec_pipeline");
134
+ if (logic && (logic.status === "done" || logic.status === "reused")) {
135
+ if (!state) return result(2, { status: "invalid", run_id: runId, error: "logic pipeline state path is required" });
136
+ const check = checkStateFile(state);
137
+ if (check.code !== 0) {
138
+ return result(2, {
139
+ status: "invalid",
140
+ run_id: runId,
141
+ error: "logic.spec_pipeline is marked complete but its state does not pass check_spec_pipeline_done.mjs",
142
+ logic_pipeline_check: check.summary,
143
+ });
144
+ }
145
+ }
146
+
147
+ if (finalize?.status === "done") {
148
+ if (!logicReport || !fs.existsSync(logicReport) || !fs.statSync(logicReport).isFile()) {
149
+ return result(2, {
150
+ status: "invalid",
151
+ run_id: runId,
152
+ error: `logic.finalize is done but the report does not exist: ${logicReport || "(not provided)"}`,
153
+ });
154
+ }
155
+ }
156
+
157
+ const failedSoft = activeNodes
158
+ .filter((node) => statuses.get(node.id)?.status === "failed")
159
+ .map((node) => ({ node: node.id, reason: statuses.get(node.id).reason }));
160
+ const status = failedSoft.length ? "completed_with_failures" : "completed";
161
+ if (runEnds[0] && runEnds[0].status !== status) {
162
+ return result(2, {
163
+ status: "invalid",
164
+ run_id: runId,
165
+ error: `run_end status ${runEnds[0].status || "(empty)"} does not match ${status}`,
166
+ });
167
+ }
168
+ return result(0, {
169
+ status,
170
+ success: failedSoft.length === 0,
171
+ run_id: runId,
172
+ failed_soft: failedSoft,
173
+ missing: [],
174
+ next_nodes: [],
175
+ run_end: runEnds[0] || null,
176
+ });
177
+ }
178
+
179
+ function main() {
180
+ const args = parseArgs(process.argv.slice(2), {
181
+ required: ["workflow", "ledger", "profile"],
182
+ defaults: { logicReport: "", state: "" },
183
+ flags: ["requireComplete", "writeRunEnd"],
184
+ });
185
+ const doc = yaml.load(fs.readFileSync(args.workflow, "utf8"));
186
+ const defaults = defaultPaths(args.ledger);
187
+ const records = readLedger(args.ledger);
188
+ const evaluated = evaluateDag(doc, records, {
189
+ profile: args.profile,
190
+ logicReport: args.logicReport || defaults.logicReport,
191
+ state: args.state || defaults.state,
192
+ });
193
+ const requireComplete = args.requireComplete || args.writeRunEnd;
194
+ if (args.writeRunEnd && evaluated.code === 0 && !evaluated.summary.run_end) {
195
+ const runEnd = {
196
+ event: "run_end",
197
+ run_id: evaluated.summary.run_id,
198
+ status: evaluated.summary.status,
199
+ failed_nodes: evaluated.summary.failed_soft.map((failure) => failure.node),
200
+ };
201
+ appendLedger(args.ledger, runEnd);
202
+ evaluated.summary.run_end = runEnd;
203
+ }
204
+ process.stdout.write(JSON.stringify(evaluated.summary) + "\n");
205
+ return evaluated.code === 1 && !requireComplete ? 0 : evaluated.code;
206
+ }
207
+
208
+ function canonicalScriptPath(p) {
209
+ let out;
210
+ try {
211
+ out = fs.realpathSync.native(p);
212
+ } catch {
213
+ out = path.resolve(p);
214
+ }
215
+ return process.platform === "win32" ? out.toLowerCase() : out;
216
+ }
217
+
218
+ const isDirect = process.argv[1] && canonicalScriptPath(process.argv[1]) === canonicalScriptPath(fileURLToPath(import.meta.url));
219
+ if (isDirect) {
220
+ try {
221
+ process.exit(main());
222
+ } catch (err) {
223
+ process.stderr.write(String(err?.message || err) + "\n");
224
+ process.exit(2);
225
+ }
226
+ }