@buaa_smat/hometrans 0.1.20 → 26.0.0-devecocli.3

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 (992) hide show
  1. package/LICENSE +21 -21
  2. package/agents/build-fixer.md +406 -0
  3. package/agents/code-reviewer.md +461 -496
  4. package/agents/model-render-worker.md +34 -0
  5. package/agents/model-worker.md +23 -0
  6. package/agents/specgen-worker.md +18 -0
  7. package/commands/hometrans.md +17 -0
  8. package/devecocli-plugin/common.ts +2203 -0
  9. package/devecocli-plugin/install.ts +61 -0
  10. package/devecocli-plugin/uninstall.ts +26 -0
  11. package/devecocli-plugin/update.ts +66 -0
  12. package/index.js +1418 -0
  13. package/package.json +81 -64
  14. package/platforms/atomcode/agents/build-fixer.frontmatter.md +6 -0
  15. package/platforms/atomcode/agents/code-reviewer.frontmatter.md +6 -0
  16. package/platforms/atomcode/agents/model-render-worker.frontmatter.md +6 -0
  17. package/platforms/atomcode/agents/model-worker.frontmatter.md +6 -0
  18. package/platforms/atomcode/agents/specgen-worker.frontmatter.md +6 -0
  19. package/platforms/deveco/agents/build-fixer.frontmatter.md +5 -0
  20. package/platforms/deveco/agents/code-reviewer.frontmatter.md +5 -0
  21. package/platforms/deveco/agents/model-render-worker.frontmatter.md +5 -0
  22. package/platforms/deveco/agents/model-worker.frontmatter.md +5 -0
  23. package/platforms/deveco/agents/specgen-worker.frontmatter.md +5 -0
  24. package/platforms/opencode/agents/build-fixer.frontmatter.md +5 -0
  25. package/platforms/opencode/agents/code-reviewer.frontmatter.md +5 -0
  26. package/platforms/opencode/agents/model-render-worker.frontmatter.md +5 -0
  27. package/platforms/opencode/agents/model-worker.frontmatter.md +5 -0
  28. package/platforms/opencode/agents/specgen-worker.frontmatter.md +5 -0
  29. package/plugin.jsonc +12 -0
  30. package/skills/a2h-app-migrate/SKILL.md +181 -0
  31. package/skills/a2h-app-migrate/references/config.example.json +27 -0
  32. package/skills/a2h-app-migrate/references/specs.example.json +19 -0
  33. package/skills/a2h-app-migrate/references/stage-map.md +33 -0
  34. package/skills/a2h-app-migrate/references/workflow.yaml +1600 -0
  35. package/skills/a2h-app-migrate/scripts/android_index.mjs +109 -0
  36. package/skills/a2h-app-migrate/scripts/check_arch_done.mjs +80 -0
  37. package/skills/a2h-app-migrate/scripts/check_module_docs_done.mjs +95 -0
  38. package/skills/a2h-app-migrate/scripts/check_signing.mjs +152 -0
  39. package/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +114 -0
  40. package/skills/a2h-app-migrate/scripts/check_spec_pipeline_done.mjs +277 -0
  41. package/skills/a2h-app-migrate/scripts/check_ui_batch_done.mjs +77 -0
  42. package/skills/a2h-app-migrate/scripts/check_utg_static_done.mjs +147 -0
  43. package/skills/a2h-app-migrate/scripts/cli_values.mjs +32 -0
  44. package/skills/a2h-app-migrate/scripts/env_preflight.mjs +1412 -0
  45. package/skills/a2h-app-migrate/scripts/human_review_gate.mjs +651 -0
  46. package/skills/a2h-app-migrate/scripts/infer_android_root.mjs +53 -0
  47. package/skills/a2h-app-migrate/scripts/json_io.mjs +35 -0
  48. package/skills/a2h-app-migrate/scripts/ledger.mjs +104 -0
  49. package/skills/a2h-app-migrate/scripts/lib-yaml-lite.mjs +288 -0
  50. package/skills/a2h-app-migrate/scripts/paths_preflight.mjs +881 -0
  51. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +205 -0
  52. package/skills/a2h-app-migrate/scripts/reuse_static_utg.mjs +121 -0
  53. package/skills/a2h-app-migrate/scripts/run_dir.mjs +212 -0
  54. package/skills/a2h-app-migrate/scripts/spec_layout.mjs +30 -0
  55. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +455 -0
  56. package/skills/a2h-app-migrate/test/test_android_index.mjs +80 -0
  57. package/skills/a2h-app-migrate/test/test_apk_preflight.mjs +63 -0
  58. package/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  59. package/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +92 -0
  60. package/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  61. package/skills/a2h-app-migrate/test/test_entry_guards.mjs +93 -0
  62. package/skills/a2h-app-migrate/test/test_env_requirements.mjs +544 -0
  63. package/skills/a2h-app-migrate/test/test_finalize.mjs +89 -0
  64. package/skills/a2h-app-migrate/test/test_gate_checkpoint.mjs +146 -0
  65. package/skills/a2h-app-migrate/test/test_hmos_fingerprint.mjs +68 -0
  66. package/skills/a2h-app-migrate/test/test_infer_android_root.mjs +91 -0
  67. package/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  68. package/skills/a2h-app-migrate/test/test_json_io.mjs +32 -0
  69. package/skills/a2h-app-migrate/test/test_leaf_questions.mjs +109 -0
  70. package/skills/a2h-app-migrate/test/test_module_docs_done.mjs +53 -0
  71. package/skills/a2h-app-migrate/test/test_parse_args.mjs +69 -0
  72. package/skills/a2h-app-migrate/test/test_preflight_report.mjs +93 -0
  73. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +144 -0
  74. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +100 -0
  75. package/skills/a2h-app-migrate/test/test_run_dir.mjs +315 -0
  76. package/skills/a2h-app-migrate/test/test_skill_doc.mjs +133 -0
  77. package/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +133 -0
  78. package/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +158 -0
  79. package/skills/a2h-app-migrate/test/test_spec_pipeline_done.mjs +181 -0
  80. package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  81. package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +53 -0
  82. package/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  83. package/skills/a2h-app-migrate/test/test_uniapp_preflight.mjs +83 -0
  84. package/skills/a2h-app-migrate/test/test_utg_dirs.mjs +39 -0
  85. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +168 -0
  86. package/skills/a2h-app-migrate/test/test_validate_races.mjs +50 -0
  87. package/skills/a2h-arch-generate/SKILL.md +375 -0
  88. package/skills/a2h-arch-generate/examples/reconcile-existing-project.md +107 -0
  89. package/skills/a2h-arch-generate/examples/simple-conversion-android.md +103 -0
  90. package/skills/a2h-arch-generate/examples/simple-conversion-backend.md +70 -0
  91. package/skills/a2h-arch-generate/examples/simple-conversion-uniapp.md +106 -0
  92. package/skills/{hmos-batch-ui-align/references/mvvm-v2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md → a2h-arch-generate/references/arkts-mvvm-v2.md} +1407 -1407
  93. package/skills/a2h-arch-generate/references/artifact-contracts.generate.md +120 -0
  94. package/skills/a2h-arch-generate/references/artifact-contracts.reconcile.md +123 -0
  95. package/skills/a2h-arch-generate/references/bpta-layered-architecture-design.md +88 -0
  96. package/skills/a2h-arch-generate/references/clustering-guidance.md +33 -0
  97. package/skills/a2h-arch-generate/references/database-schema-recovery.md +107 -0
  98. package/skills/a2h-arch-generate/references/existing-target-annotation.md +68 -0
  99. package/skills/a2h-arch-generate/references/harmony-project-inspection.md +150 -0
  100. package/skills/a2h-arch-generate/references/harmony-target-architecture.md +94 -0
  101. package/skills/a2h-arch-generate/references/homegraph-workflow.md +120 -0
  102. package/skills/a2h-arch-generate/references/module-evidence-subagent.md +45 -0
  103. package/skills/a2h-arch-generate/references/reconciliation-model.md +204 -0
  104. package/skills/a2h-arch-generate/references/scope-policy.md +28 -0
  105. package/skills/a2h-arch-generate/references/semantic-review.md +65 -0
  106. package/skills/a2h-arch-generate/references/source-baseline.md +93 -0
  107. package/skills/a2h-arch-generate/references/source-ecosystems.md +54 -0
  108. package/skills/a2h-arch-generate/references/transformation-model.md +78 -0
  109. package/skills/a2h-arch-generate/scripts/check_module_staleness.mjs +284 -0
  110. package/skills/a2h-arch-generate/scripts/cleanup_intermediates.mjs +260 -0
  111. package/skills/a2h-arch-generate/scripts/compute_processing_order.mjs +325 -0
  112. package/skills/a2h-arch-generate/scripts/create_project.mjs +149 -0
  113. package/skills/a2h-arch-generate/scripts/dump_core_facts.mjs +151 -0
  114. package/skills/a2h-arch-generate/scripts/extract_core_components.mjs +167 -0
  115. package/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +363 -0
  116. package/skills/a2h-arch-generate/scripts/generate_state.mjs +60 -0
  117. package/skills/a2h-arch-generate/scripts/inspect_and_route.mjs +326 -0
  118. package/skills/a2h-arch-generate/scripts/inspect_android_project.mjs +3739 -0
  119. package/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +800 -0
  120. package/skills/a2h-arch-generate/scripts/inspect_project.mjs +251 -0
  121. package/skills/a2h-arch-generate/scripts/inspect_uniapp_project.mjs +809 -0
  122. package/skills/a2h-arch-generate/scripts/lib/py_compat.mjs +1454 -0
  123. package/skills/a2h-arch-generate/scripts/module_create/create.mjs +136 -0
  124. package/skills/a2h-arch-generate/scripts/module_create/generate.mjs +636 -0
  125. package/skills/a2h-arch-generate/scripts/module_create/hap/build-profile.json5 +33 -0
  126. package/skills/a2h-arch-generate/scripts/module_create/hap/hvigorfile.ts +6 -0
  127. package/skills/a2h-arch-generate/scripts/module_create/hap/obfuscation-rules.txt +23 -0
  128. package/skills/a2h-arch-generate/scripts/module_create/hap/oh-package.json5 +10 -0
  129. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/applicationability/ApplicationAbility.ets +43 -0
  130. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +23 -0
  131. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/module.json5 +26 -0
  132. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/color.json +8 -0
  133. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/float.json +8 -0
  134. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/string.json +16 -0
  135. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/background.png +0 -0
  136. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/foreground.png +0 -0
  137. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/layered_image.json +7 -0
  138. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/startIcon.png +0 -0
  139. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/profile/main_pages.json +5 -0
  140. package/skills/a2h-arch-generate/scripts/module_create/hap/src/mock/mock-config.json5 +2 -0
  141. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/ets/test/Ability.test.ets +35 -0
  142. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/ets/test/List.test.ets +5 -0
  143. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/module.json5 +11 -0
  144. package/skills/a2h-arch-generate/scripts/module_create/hap/src/test/List.test.ets +5 -0
  145. package/skills/a2h-arch-generate/scripts/module_create/hap/src/test/LocalUnit.test.ets +33 -0
  146. package/skills/a2h-arch-generate/scripts/module_create/har/Index.ets +1 -0
  147. package/skills/a2h-arch-generate/scripts/module_create/har/build-profile.json5 +36 -0
  148. package/skills/a2h-arch-generate/scripts/module_create/har/hvigorfile.ts +6 -0
  149. package/skills/a2h-arch-generate/scripts/module_create/har/obfuscation-rules.txt +23 -0
  150. package/skills/a2h-arch-generate/scripts/module_create/har/oh-package.json5 +9 -0
  151. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +19 -0
  152. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/module.json5 +9 -0
  153. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/resources/base/element/float.json +8 -0
  154. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/resources/base/element/string.json +8 -0
  155. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/ets/test/Ability.test.ets +35 -0
  156. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/ets/test/List.test.ets +5 -0
  157. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/module.json5 +11 -0
  158. package/skills/a2h-arch-generate/scripts/module_create/har/src/test/List.test.ets +5 -0
  159. package/skills/a2h-arch-generate/scripts/module_create/har/src/test/LocalUnit.test.ets +33 -0
  160. package/skills/a2h-arch-generate/scripts/module_create/hsp/Index.ets +1 -0
  161. package/skills/a2h-arch-generate/scripts/module_create/hsp/build-profile.json5 +36 -0
  162. package/skills/a2h-arch-generate/scripts/module_create/hsp/consumer-rules.txt +0 -0
  163. package/skills/a2h-arch-generate/scripts/module_create/hsp/hvigorfile.ts +6 -0
  164. package/skills/a2h-arch-generate/scripts/module_create/hsp/obfuscation-rules.txt +23 -0
  165. package/skills/a2h-arch-generate/scripts/module_create/hsp/oh-package.json5 +10 -0
  166. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +20 -0
  167. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/utils/Calc.ets +3 -0
  168. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/module.json5 +12 -0
  169. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/element/float.json +8 -0
  170. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/element/string.json +8 -0
  171. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/profile/main_pages.json +5 -0
  172. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/ets/test/Ability.test.ets +35 -0
  173. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/ets/test/List.test.ets +5 -0
  174. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/module.json5 +11 -0
  175. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/test/List.test.ets +5 -0
  176. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/test/LocalUnit.test.ets +33 -0
  177. package/skills/a2h-arch-generate/scripts/module_create/testdata/reconcile-layer-PROJECT_DESIGN.md +47 -0
  178. package/skills/a2h-arch-generate/scripts/module_create/testdata/single-entry-PROJECT_DESIGN.md +15 -0
  179. package/skills/a2h-arch-generate/scripts/module_create/testdata/three-layer-PROJECT_DESIGN.md +36 -0
  180. package/skills/a2h-arch-generate/scripts/module_create/testdata/verification-report.md +150 -0
  181. package/skills/a2h-arch-generate/scripts/resolve_android_stores.mjs +529 -0
  182. package/skills/a2h-arch-generate/scripts/scaffold_project.mjs +230 -0
  183. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/build.gradle +11 -0
  184. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/AndroidManifest.xml +12 -0
  185. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/MainActivity.kt +8 -0
  186. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/NotesStore.kt +17 -0
  187. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/build.gradle +3 -0
  188. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/settings.gradle +1 -0
  189. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/AppScope/app.json5 +8 -0
  190. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/build-profile.json5 +14 -0
  191. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/build-profile.json5 +7 -0
  192. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/oh-package.json5 +1 -0
  193. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/src/main/ets/utils/Format.ets +3 -0
  194. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/build-profile.json5 +7 -0
  195. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/oh-package.json5 +1 -0
  196. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/src/main/ets/pages/Home.ets +3 -0
  197. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/build-profile.json5 +7 -0
  198. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/oh-package.json5 +1 -0
  199. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/src/main/ets/engine/SyncEngine.ets +3 -0
  200. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/hvigorfile.ts +1 -0
  201. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/oh-package.json5 +1 -0
  202. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/build-profile.json5 +7 -0
  203. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/oh-package.json5 +9 -0
  204. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/src/main/ets/pages/Index.ets +7 -0
  205. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/App.vue +10 -0
  206. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/manifest.json +6 -0
  207. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages/index/index.vue +16 -0
  208. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  209. package/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  210. package/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1122 -0
  211. package/skills/a2h-arch-generate/scripts/tests/test_cleanup.mjs +191 -0
  212. package/skills/a2h-arch-generate/scripts/tests/test_console_encoding.mjs +52 -0
  213. package/skills/a2h-arch-generate/scripts/tests/test_git_root.mjs +34 -0
  214. package/skills/a2h-arch-generate/scripts/tests/test_router.mjs +138 -0
  215. package/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +829 -0
  216. package/skills/a2h-arch-generate/scripts/validate_data_docs.mjs +937 -0
  217. package/skills/a2h-arch-generate/scripts/validate_homegraph_artifacts.mjs +542 -0
  218. package/skills/a2h-arch-generate/scripts/validate_incremental_docs.mjs +415 -0
  219. package/skills/a2h-arkts-logic-coder/SKILL.md +125 -0
  220. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +6 -0
  221. package/skills/a2h-arkts-logic-coder/references/code-generation.md +124 -0
  222. package/skills/a2h-arkts-logic-coder/scripts/check_module_scope.ts +224 -0
  223. package/skills/a2h-arkts-logic-coder/scripts/check_mvvm.ts +377 -0
  224. package/skills/a2h-arkts-logic-coder/scripts/stop_check_hook.ts +443 -0
  225. package/skills/a2h-arkts-logic-coder/scripts/test_check_scripts.ts +211 -0
  226. package/skills/a2h-arkts-logic-coder/scripts/test_worktree_compat.ts +81 -0
  227. package/skills/a2h-batch-ui-align/SKILL.md +321 -0
  228. package/skills/a2h-batch-ui-align/assets/ColorUtils.ets +81 -0
  229. package/skills/a2h-batch-ui-align/flowchart.html +271 -0
  230. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +572 -0
  231. package/skills/a2h-batch-ui-align/references/incremental-scope.md +139 -0
  232. package/skills/a2h-batch-ui-align/references/lottie-integration.md +43 -0
  233. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2535 -2533
  234. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +558 -555
  235. package/skills/{hmos-incremental-ui-align/references → a2h-batch-ui-align/references/mappings}/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
  236. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
  237. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
  238. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
  239. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
  240. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
  241. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
  242. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
  243. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
  244. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
  245. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
  246. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -911
  247. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
  248. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243 → a2h-batch-ui-align/references/mvvm}//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
  249. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +206 -206
  250. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Computed/350/243/205/351/245/260/345/231/250/357/274/232/350/256/241/347/256/227/345/261/236/346/200/247.md +373 -373
  251. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Event/350/243/205/351/245/260/345/231/250/357/274/232/350/247/204/350/214/203/347/273/204/344/273/266/350/276/223/345/207/272.md +158 -158
  252. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}/@Local/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/351/203/250/347/212/266/346/200/201.md +750 -750
  253. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Monitor/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/344/277/256/346/224/271/345/274/202/346/255/245/347/233/221/345/220/254.md +1704 -1704
  254. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@ObservedV2/350/243/205/351/245/260/345/231/250/345/222/214@Trace/350/243/205/351/245/260/345/231/250/357/274/232/347/261/273/345/261/236/346/200/247/345/217/230/345/214/226/350/247/202/346/265/213.md +1012 -1012
  255. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Once/350/243/205/351/245/260/345/231/250/357/274/232/345/210/235/345/247/213/345/214/226/345/220/214/346/255/245/344/270/200/346/254/241.md +164 -164
  256. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}/@Param/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md +840 -840
  257. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}/@Provider/350/243/205/351/245/260/345/231/250/345/222/214@Consumer/350/243/205/351/245/260/345/231/250/357/274/232/350/267/250/347/273/204/344/273/266/345/261/202/347/272/247/345/217/214/345/220/221/345/220/214/346/255/245.md +856 -856
  258. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/@Type/350/243/205/351/245/260/345/231/250/357/274/232/346/240/207/350/256/260/347/261/273/345/261/236/346/200/247/347/232/204/347/261/273/345/236/213.md +83 -83
  259. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}/AppStorageV2/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200UI/347/212/266/346/200/201/345/255/230/345/202/250.md +294 -294
  260. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md +1407 -1407
  261. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}/PersistenceV2/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +1220 -1220
  262. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +47 -47
  263. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mvvm-v2/_/350/243/205/351/245/260/345/231/250/351/200/237/346/237/245.md +133 -133
  264. package/skills/{hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2 → a2h-batch-ui-align/references/mvvm-v2}//347/212/266/346/200/201/347/256/241/347/220/206V1/345/220/221V2/350/277/201/347/247/273/344/270/216/346/267/267/347/224/250/346/214/207/345/257/274.md +840 -840
  265. package/skills/a2h-batch-ui-align/references/source-only-tier.md +32 -0
  266. package/skills/a2h-batch-ui-align/references/step3-capture.md +214 -0
  267. package/skills/a2h-batch-ui-align/references/step4-prepare.md +196 -0
  268. package/skills/a2h-batch-ui-align/references/step5-convert.md +205 -0
  269. package/skills/a2h-batch-ui-align/scripts/agent_cli.mjs +572 -0
  270. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/scripts/android_parse_fast.ts +246 -39
  271. package/skills/a2h-batch-ui-align/scripts/answers_check.mjs +86 -0
  272. package/skills/a2h-batch-ui-align/scripts/arkts_static_check.ts +3858 -0
  273. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +1675 -0
  274. package/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +79 -0
  275. package/skills/a2h-batch-ui-align/scripts/detach.mjs +258 -0
  276. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +1644 -0
  277. package/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +612 -0
  278. package/skills/a2h-batch-ui-align/scripts/group_commit.mjs +166 -0
  279. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +1627 -0
  280. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1869 -0
  281. package/skills/a2h-batch-ui-align/scripts/group_watch.mjs +696 -0
  282. package/skills/a2h-batch-ui-align/scripts/harmony_index.mjs +218 -0
  283. package/skills/a2h-batch-ui-align/scripts/host_env.mjs +208 -0
  284. package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +1229 -0
  285. package/skills/a2h-batch-ui-align/scripts/occlusion.mjs +141 -0
  286. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +1179 -0
  287. package/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +1036 -0
  288. package/skills/a2h-batch-ui-align/scripts/tests/agent_cli.test.mjs +217 -0
  289. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_align_tint.test.mjs +253 -0
  290. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_canvas_pct.test.mjs +312 -0
  291. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_fidelity.test.mjs +241 -0
  292. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +341 -0
  293. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_review_fixes.test.mjs +298 -0
  294. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  295. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_shell.test.mjs +91 -0
  296. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +445 -0
  297. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +356 -0
  298. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_scope.test.mjs +290 -0
  299. package/skills/a2h-batch-ui-align/scripts/tests/color_utils_asset.test.mjs +74 -0
  300. package/skills/a2h-batch-ui-align/scripts/tests/export_scroll_states.test.mjs +31 -0
  301. package/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +564 -0
  302. package/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  303. package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +126 -0
  304. package/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +241 -0
  305. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +1451 -0
  306. package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +215 -0
  307. package/skills/a2h-batch-ui-align/scripts/tests/harmony_index.test.mjs +95 -0
  308. package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +115 -0
  309. package/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +170 -0
  310. package/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  311. package/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +244 -0
  312. package/skills/a2h-batch-ui-align/scripts/tests/shell_contract.test.mjs +166 -0
  313. package/skills/a2h-batch-ui-align/scripts/tests/test_bfs_exit.ts +49 -0
  314. package/skills/a2h-batch-ui-align/scripts/tests/text_color_diff.test.mjs +219 -0
  315. package/skills/a2h-batch-ui-align/scripts/text_color_diff.mjs +470 -0
  316. package/skills/a2h-coldstart-smoke-gate/SKILL.md +57 -0
  317. package/skills/a2h-dashboard-render/SKILL.md +65 -0
  318. package/skills/a2h-dashboard-render/references/artifact-contract.jsonc +147 -0
  319. package/skills/a2h-dashboard-render/references/artifact-registry-spec.md +67 -0
  320. package/skills/a2h-dashboard-render/references/dashboard.config.example.json +19 -0
  321. package/skills/a2h-dashboard-render/references//347/234/213/346/235/277/350/257/264/346/230/216.md +83 -0
  322. package/skills/a2h-dashboard-render/scripts/artifact_contract.mjs +138 -0
  323. package/skills/a2h-dashboard-render/scripts/check-registry.mjs +87 -0
  324. package/skills/a2h-dashboard-render/scripts/dashboard.mjs +3215 -0
  325. package/skills/a2h-dashboard-render/scripts/device_capture.mjs +2010 -0
  326. package/skills/a2h-dashboard-render/scripts/page_capture.mjs +828 -0
  327. package/skills/a2h-dashboard-render/scripts/usage_readers.mjs +459 -0
  328. package/skills/a2h-dashboard-render/scripts/usage_worker.mjs +13 -0
  329. package/skills/a2h-dashboard-render/test/fixtures/page_capture/broken.xml +1 -0
  330. package/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  331. package/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  332. package/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  333. package/skills/a2h-dashboard-render/test/fixtures/page_capture/nested_scroll.xml +1 -0
  334. package/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +170 -0
  335. package/skills/a2h-dashboard-render/test/test_cli_check_registry.mjs +99 -0
  336. package/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +182 -0
  337. package/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +64 -0
  338. package/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1172 -0
  339. package/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +251 -0
  340. package/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  341. package/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  342. package/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +303 -0
  343. package/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  344. package/skills/a2h-dashboard-render/test/test_usage_readers.mjs +444 -0
  345. package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/SKILL.md +305 -293
  346. package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/arkts-strict-patterns.md +219 -219
  347. package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/known-patterns.md +157 -157
  348. package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/rdb-entity-pattern.md +131 -131
  349. package/skills/a2h-module-semantic-docs/SKILL.md +227 -0
  350. package/skills/a2h-module-semantic-docs/scripts/commit_module_state.mjs +168 -0
  351. package/skills/a2h-module-semantic-docs/scripts/lib/py_compat.mjs +688 -0
  352. package/skills/a2h-module-semantic-docs/scripts/scan_modules.mjs +1021 -0
  353. package/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  354. package/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  355. package/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  356. package/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  357. package/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  358. package/skills/a2h-resource-convert/SKILL.md +369 -0
  359. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/code-vector-icon-rules.md +335 -335
  360. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/conversion-rules.md +687 -676
  361. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/dependency-analysis-rules.md +410 -410
  362. package/skills/a2h-resource-convert/references/incremental-page-migration.md +251 -0
  363. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/lottie-conversion-rules.md +219 -219
  364. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/resource-mapping-rules.md +493 -482
  365. package/skills/a2h-resource-convert/references/step3_5-dependency-filter.md +54 -0
  366. package/skills/a2h-resource-convert/references/step4-qualifiers-and-values.md +142 -0
  367. package/skills/a2h-resource-convert/references/step4-resource-types.md +249 -0
  368. package/skills/a2h-resource-convert/references/step5-reference-resolution.md +154 -0
  369. package/skills/a2h-resource-convert/references/step7-report-template.md +217 -0
  370. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/xml-drawable-to-svg-rules.md +630 -592
  371. package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/a2h_resource_convert.ts +2529 -2163
  372. package/skills/a2h-resource-convert/scripts/a2h_resource_incremental.ts +1072 -0
  373. package/skills/a2h-resource-convert/scripts/app_identity.ts +947 -0
  374. package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/code_vector_icons.ts +607 -591
  375. package/skills/a2h-resource-convert/scripts/extract_page_resources.ts +989 -0
  376. package/skills/a2h-resource-convert/scripts/extract_project_resources.ts +1464 -0
  377. package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/svg_fidelity_check.ts +632 -632
  378. package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +182 -0
  379. package/skills/a2h-resource-convert/scripts/tests/app_identity.test.mjs +206 -0
  380. package/skills/a2h-spec-design/SKILL.md +336 -0
  381. package/skills/a2h-spec-design/scripts/inspect_spec_design_inputs.mjs +146 -0
  382. package/skills/a2h-spec-design/scripts/lib/py_compat.mjs +481 -0
  383. package/skills/a2h-spec-design/scripts/move_spec_technical_reference.mjs +159 -0
  384. package/skills/a2h-spec-design/scripts/resolve_module_design.mjs +102 -0
  385. package/skills/a2h-spec-design/scripts/validate_spec_design_output.mjs +285 -0
  386. package/skills/a2h-spec-design/test/golden/inspect_happy.json +20 -0
  387. package/skills/a2h-spec-design/test/golden/move_design.md +18 -0
  388. package/skills/a2h-spec-design/test/golden/move_design_crlf.md +18 -0
  389. package/skills/a2h-spec-design/test/golden/move_spec.md +7 -0
  390. package/skills/a2h-spec-design/test/golden/resolve_cases.json +36 -0
  391. package/skills/a2h-spec-design/test/golden/validate_issue_file.md +12 -0
  392. package/skills/a2h-spec-design/test/golden/validate_issues.json +57 -0
  393. package/skills/a2h-spec-design/test/test_spec_design_scripts.mjs +381 -0
  394. package/skills/a2h-spec-design-pipeline/SKILL.md +228 -0
  395. package/skills/a2h-spec-design-pipeline/package.json +4 -0
  396. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +63 -0
  397. package/skills/a2h-spec-design-pipeline/references/execution-model.md +69 -0
  398. package/skills/a2h-spec-design-pipeline/references/final-report-template.md +24 -0
  399. package/skills/a2h-spec-design-pipeline/references/initialization.md +57 -0
  400. package/skills/a2h-spec-design-pipeline/references/merge-queue.md +21 -0
  401. package/skills/a2h-spec-design-pipeline/references/scripts.md +27 -0
  402. package/skills/a2h-spec-design-pipeline/references/specs.example.json +19 -0
  403. package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +21 -0
  404. package/skills/a2h-spec-design-pipeline/scripts/atomic_write.ts +42 -0
  405. package/skills/a2h-spec-design-pipeline/scripts/audit_claims.ts +252 -0
  406. package/skills/a2h-spec-design-pipeline/scripts/branch_landed.ts +77 -0
  407. package/skills/a2h-spec-design-pipeline/scripts/deps_ready.ts +195 -0
  408. package/skills/a2h-spec-design-pipeline/scripts/ensure_wt_index.ts +651 -0
  409. package/skills/a2h-spec-design-pipeline/scripts/git_baseline.ts +124 -0
  410. package/skills/a2h-spec-design-pipeline/scripts/inflight.mjs +944 -0
  411. package/skills/a2h-spec-design-pipeline/scripts/lib/bgcli.mjs +95 -0
  412. package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +502 -0
  413. package/skills/a2h-spec-design-pipeline/scripts/plan_waves.ts +475 -0
  414. package/skills/a2h-spec-design-pipeline/scripts/reconcile.mjs +218 -0
  415. package/skills/a2h-spec-design-pipeline/scripts/resolve_wiring.ts +164 -0
  416. package/skills/a2h-spec-design-pipeline/scripts/test_atomic_write.ts +44 -0
  417. package/skills/a2h-spec-design-pipeline/scripts/test_audit_claims.ts +301 -0
  418. package/skills/a2h-spec-design-pipeline/scripts/test_bgcli.mjs +64 -0
  419. package/skills/a2h-spec-design-pipeline/scripts/test_branch_landed.ts +87 -0
  420. package/skills/a2h-spec-design-pipeline/scripts/test_deps_ready.ts +265 -0
  421. package/skills/a2h-spec-design-pipeline/scripts/test_ensure_wt_index.ts +675 -0
  422. package/skills/a2h-spec-design-pipeline/scripts/test_git_baseline.ts +105 -0
  423. package/skills/a2h-spec-design-pipeline/scripts/test_inflight.mjs +452 -0
  424. package/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +375 -0
  425. package/skills/a2h-spec-design-pipeline/scripts/test_plan_waves.ts +561 -0
  426. package/skills/a2h-spec-design-pipeline/scripts/test_reconcile.mjs +182 -0
  427. package/skills/a2h-spec-design-pipeline/scripts/test_resolve_wiring.ts +138 -0
  428. package/skills/a2h-spec-design-pipeline/scripts/test_watchdog.mjs +289 -0
  429. package/skills/a2h-spec-design-pipeline/scripts/watchdog.mjs +441 -0
  430. package/skills/a2h-spec-generate/SKILL.md +285 -0
  431. package/skills/a2h-spec-generate/package.json +9 -0
  432. package/skills/a2h-spec-generate/references/batch-mode.md +151 -0
  433. package/skills/a2h-spec-generate/references/delete-blast-radius.md +3 -0
  434. package/skills/a2h-spec-generate/references/fusion-task-contract.md +114 -0
  435. package/skills/a2h-spec-generate/references/input-formats.md +27 -0
  436. package/skills/a2h-spec-generate/references/library-evidence.md +3 -0
  437. package/skills/a2h-spec-generate/references/method-discipline.md +64 -0
  438. package/skills/a2h-spec-generate/references/optional-gates.json +45 -0
  439. package/skills/a2h-spec-generate/references/recall-guide.md +83 -0
  440. package/skills/a2h-spec-generate/references/recall-terse.md +3 -0
  441. package/skills/a2h-spec-generate/references/recall-uniapp.md +10 -0
  442. package/skills/a2h-spec-generate/references/requirement-scope.md +122 -0
  443. package/skills/a2h-spec-generate/references/review-checklist.md +21 -0
  444. package/skills/a2h-spec-generate/references/spec-sample-complex.md +80 -0
  445. package/skills/a2h-spec-generate/references/spec-sample-transfer.md +43 -0
  446. package/skills/a2h-spec-generate/references/spec-samples.md +65 -0
  447. package/skills/a2h-spec-generate/references/specs.schema.json +79 -0
  448. package/skills/a2h-spec-generate/references/synthesis-rules.md +143 -0
  449. package/skills/a2h-spec-generate/references/transfer-file.md +5 -0
  450. package/skills/a2h-spec-generate/references/transfer-socket.md +5 -0
  451. package/skills/a2h-spec-generate/references/worker-rules.md +126 -0
  452. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +514 -0
  453. package/skills/a2h-spec-generate/scripts/check_spec.ts +361 -0
  454. package/skills/a2h-spec-generate/scripts/collect-specs.mjs +470 -0
  455. package/skills/a2h-spec-generate/scripts/detect-project.mjs +271 -0
  456. package/skills/a2h-spec-generate/scripts/ensure-index.mjs +188 -0
  457. package/skills/a2h-spec-generate/scripts/feature-stem.mjs +150 -0
  458. package/skills/a2h-spec-generate/scripts/inspect-uniapp.mjs +733 -0
  459. package/skills/{hmos-spec-generate → a2h-spec-generate}/scripts/parse_requirements.ts +515 -515
  460. package/skills/a2h-spec-generate/scripts/prepare-facts.mjs +307 -0
  461. package/skills/a2h-spec-generate/scripts/publication-verdict.mjs +171 -0
  462. package/skills/a2h-spec-generate/scripts/publish-specs.mjs +280 -0
  463. package/skills/a2h-spec-generate/scripts/render-tasks.mjs +399 -0
  464. package/skills/a2h-spec-generate/scripts/report.mjs +132 -0
  465. package/skills/a2h-spec-generate/scripts/reqgen/assets/dashboard.html +149 -0
  466. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-api.js +49 -0
  467. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-code-view.js +140 -0
  468. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-format.js +16 -0
  469. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-handoff.js +42 -0
  470. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-splitters.js +78 -0
  471. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-state.js +47 -0
  472. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-tree.js +194 -0
  473. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-virtual-list.js +118 -0
  474. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.css +245 -0
  475. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.html +99 -0
  476. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.js +220 -0
  477. package/skills/a2h-spec-generate/scripts/reqgen/package-lock.json +47 -0
  478. package/skills/a2h-spec-generate/scripts/reqgen/package.json +23 -0
  479. package/skills/a2h-spec-generate/scripts/reqgen/src/agent-render/serve.ts +95 -0
  480. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/callback-call-sites.ts +82 -0
  481. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/area-ownership.ts +496 -0
  482. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +2217 -0
  483. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/callback-flow.ts +386 -0
  484. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +845 -0
  485. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/index.ts +24 -0
  486. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/index.ts +22 -0
  487. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +572 -0
  488. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +580 -0
  489. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +1270 -0
  490. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/index.ts +10 -0
  491. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/projection.ts +804 -0
  492. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/render-projection.ts +51 -0
  493. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/android-interaction-registry.ts +286 -0
  494. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/builder.ts +453 -0
  495. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/compose-api-registry.ts +526 -0
  496. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/index.ts +15 -0
  497. package/skills/a2h-spec-generate/scripts/reqgen/src/connector/index.ts +1 -0
  498. package/skills/a2h-spec-generate/scripts/reqgen/src/connector/utg-inbound.ts +763 -0
  499. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/area-graph.ts +383 -0
  500. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/artifact.ts +68 -0
  501. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/common.ts +88 -0
  502. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/diagnostic.ts +64 -0
  503. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/gap-audit.ts +113 -0
  504. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/index.ts +12 -0
  505. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/name-traceability.ts +108 -0
  506. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/raw-fact.ts +377 -0
  507. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/req-model.ts +238 -0
  508. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/run.ts +134 -0
  509. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/semantic-completeness.ts +35 -0
  510. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/source-facts.ts +48 -0
  511. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/utg.ts +133 -0
  512. package/skills/a2h-spec-generate/scripts/reqgen/src/core/output-guard.ts +42 -0
  513. package/skills/a2h-spec-generate/scripts/reqgen/src/core/stable-id.ts +118 -0
  514. package/skills/a2h-spec-generate/scripts/reqgen/src/cross-area-tally-cli.ts +179 -0
  515. package/skills/a2h-spec-generate/scripts/reqgen/src/dashboard-cli.ts +188 -0
  516. package/skills/a2h-spec-generate/scripts/reqgen/src/dump/dump.ts +1184 -0
  517. package/skills/a2h-spec-generate/scripts/reqgen/src/dump/index.ts +1 -0
  518. package/skills/a2h-spec-generate/scripts/reqgen/src/dump-cli.ts +373 -0
  519. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +1014 -0
  520. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-output.ts +32 -0
  521. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/schema.ts +142 -0
  522. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/selfcheck.ts +312 -0
  523. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/spec-bindings.ts +310 -0
  524. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +685 -0
  525. package/skills/a2h-spec-generate/scripts/reqgen/src/graph/paths.ts +575 -0
  526. package/skills/a2h-spec-generate/scripts/reqgen/src/homegraph-cli.ts +50 -0
  527. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/android-resource-resolver.ts +391 -0
  528. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/androidx-preference-contracts.ts +44 -0
  529. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +640 -0
  530. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/cross-area.ts +207 -0
  531. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/finalizer.ts +1297 -0
  532. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/identity.ts +186 -0
  533. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/index.ts +16 -0
  534. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/planner.ts +312 -0
  535. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/preference-enrichment.ts +793 -0
  536. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/raw-facts.ts +355 -0
  537. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/rules.ts +271 -0
  538. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/scanner.ts +666 -0
  539. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/schema.ts +365 -0
  540. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/stable-key.ts +144 -0
  541. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +301 -0
  542. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +923 -0
  543. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/uniapp-utg-adapter.ts +543 -0
  544. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/xml-adapter.ts +262 -0
  545. package/skills/a2h-spec-generate/scripts/reqgen/src/model/assemble.ts +2079 -0
  546. package/skills/a2h-spec-generate/scripts/reqgen/src/model/contracts.ts +157 -0
  547. package/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +809 -0
  548. package/skills/a2h-spec-generate/scripts/reqgen/src/model/index.ts +17 -0
  549. package/skills/a2h-spec-generate/scripts/reqgen/src/model/io.ts +165 -0
  550. package/skills/a2h-spec-generate/scripts/reqgen/src/model/prepare.ts +806 -0
  551. package/skills/a2h-spec-generate/scripts/reqgen/src/model/query.ts +360 -0
  552. package/skills/a2h-spec-generate/scripts/reqgen/src/model/seeds.ts +218 -0
  553. package/skills/a2h-spec-generate/scripts/reqgen/src/model/spec-bindings-sidecar.ts +240 -0
  554. package/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +359 -0
  555. package/skills/a2h-spec-generate/scripts/reqgen/src/model-cli.ts +500 -0
  556. package/skills/a2h-spec-generate/scripts/reqgen/src/pipeline/index.ts +7 -0
  557. package/skills/a2h-spec-generate/scripts/reqgen/src/pipeline/output.ts +307 -0
  558. package/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +172 -0
  559. package/skills/a2h-spec-generate/scripts/reqgen/src/source-cov/index.ts +1 -0
  560. package/skills/a2h-spec-generate/scripts/reqgen/src/source-cov/source-cov.ts +176 -0
  561. package/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1039 -0
  562. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/area-graph.ts +490 -0
  563. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/index.ts +23 -0
  564. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-model.ts +957 -0
  565. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +248 -0
  566. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/semantic-area-graph.ts +1600 -0
  567. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/types.ts +10 -0
  568. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/artifact-data.ts +201 -0
  569. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-api.ts +74 -0
  570. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-code-view.ts +180 -0
  571. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-format.ts +18 -0
  572. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-handoff.ts +55 -0
  573. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-splitters.ts +78 -0
  574. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-state.ts +66 -0
  575. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-tree.ts +232 -0
  576. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-virtual-list.ts +179 -0
  577. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz.ts +240 -0
  578. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/contracts.d.ts +86 -0
  579. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/index.ts +3 -0
  580. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/server.ts +239 -0
  581. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/source-project.ts +316 -0
  582. package/skills/a2h-spec-generate/scripts/reqgen/src/viz-cli.ts +200 -0
  583. package/skills/a2h-spec-generate/scripts/reqgen/test/control-fact-join.test.ts +50 -0
  584. package/skills/a2h-spec-generate/scripts/reqgen/test/control-name-uniapp.test.ts +75 -0
  585. package/skills/a2h-spec-generate/scripts/reqgen/test/cross-area-anchor.test.ts +256 -0
  586. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +576 -0
  587. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +290 -0
  588. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1323 -0
  589. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +574 -0
  590. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  591. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +831 -0
  592. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +548 -0
  593. package/skills/a2h-spec-generate/scripts/reqgen/test/model-cli-blockers.test.ts +117 -0
  594. package/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +396 -0
  595. package/skills/a2h-spec-generate/scripts/reqgen/test/model-seeds.test.ts +175 -0
  596. package/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +298 -0
  597. package/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  598. package/skills/a2h-spec-generate/scripts/reqgen/test/specgen-completeness.test.ts +286 -0
  599. package/skills/a2h-spec-generate/scripts/reqgen/test/stagem-stored-path.test.ts +25 -0
  600. package/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  601. package/skills/a2h-spec-generate/scripts/reqgen/tsconfig.json +16 -0
  602. package/skills/a2h-spec-generate/scripts/reqgen/tsconfig.viz-client.json +12 -0
  603. package/skills/{hmos-spec-generate → a2h-spec-generate}/template/REQ.txt +22 -22
  604. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +632 -0
  605. package/skills/a2h-spec-generate/test/check-spec.test.ts +200 -0
  606. package/skills/a2h-spec-generate/test/collect-specs.test.mjs +538 -0
  607. package/skills/a2h-spec-generate/test/detect-project.test.mjs +37 -0
  608. package/skills/a2h-spec-generate/test/ensure-index.test.mjs +45 -0
  609. package/skills/a2h-spec-generate/test/feature-stem.test.mjs +147 -0
  610. package/skills/a2h-spec-generate/test/fixtures/android/app/src/main/AndroidManifest.xml +3 -0
  611. package/skills/a2h-spec-generate/test/fixtures/android/build.gradle +3 -0
  612. package/skills/a2h-spec-generate/test/fixtures/android/settings.gradle +3 -0
  613. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/package.json +9 -0
  614. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/App.vue +8 -0
  615. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  616. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  617. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/main.ts +6 -0
  618. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/manifest.json +4 -0
  619. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  620. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  621. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  622. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  623. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/services/items.ts +3 -0
  624. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/tsconfig.json +8 -0
  625. package/skills/a2h-spec-generate/test/fixtures/unknown/README.txt +1 -0
  626. package/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  627. package/skills/a2h-spec-generate/test/publication-verdict.test.mjs +157 -0
  628. package/skills/a2h-spec-generate/test/publish-specs.test.mjs +282 -0
  629. package/skills/a2h-spec-generate/test/render-tasks.test.mjs +593 -0
  630. package/skills/a2h-utg-explorer/SKILL.md +120 -0
  631. package/skills/a2h-utg-explorer/assets/final_viewer.html +64 -0
  632. package/skills/a2h-utg-explorer/assets/u2.LICENSE +21 -0
  633. package/skills/a2h-utg-explorer/assets/u2.NOTICE +25 -0
  634. package/skills/a2h-utg-explorer/assets/u2.jar +0 -0
  635. package/skills/a2h-utg-explorer/references/architecture.md +270 -0
  636. package/skills/a2h-utg-explorer/references/protocol.md +9 -0
  637. package/skills/a2h-utg-explorer/scripts/app_settings.mjs +143 -0
  638. package/skills/a2h-utg-explorer/scripts/audit.mjs +167 -0
  639. package/skills/a2h-utg-explorer/scripts/close_phases.mjs +66 -0
  640. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +749 -0
  641. package/skills/a2h-utg-explorer/scripts/d_prereqs.mjs +597 -0
  642. package/skills/a2h-utg-explorer/scripts/device_health.mjs +227 -0
  643. package/skills/a2h-utg-explorer/scripts/direct_launch.mjs +276 -0
  644. package/skills/a2h-utg-explorer/scripts/evidence.mjs +108 -0
  645. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +428 -0
  646. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +89 -0
  647. package/skills/a2h-utg-explorer/scripts/plan.mjs +258 -0
  648. package/skills/a2h-utg-explorer/scripts/promote_dynamic.mjs +170 -0
  649. package/skills/a2h-utg-explorer/scripts/recover.mjs +467 -0
  650. package/skills/a2h-utg-explorer/scripts/recover_b.mjs +542 -0
  651. package/skills/a2h-utg-explorer/scripts/recover_d.mjs +369 -0
  652. package/skills/a2h-utg-explorer/scripts/rejudge.mjs +203 -0
  653. package/skills/a2h-utg-explorer/scripts/report.mjs +143 -0
  654. package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +844 -0
  655. package/skills/a2h-utg-explorer/scripts/run_device.mjs +137 -0
  656. package/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  657. package/skills/a2h-utg-explorer/scripts/tests/chain.test.mjs +45 -0
  658. package/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +243 -0
  659. package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +104 -0
  660. package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +223 -0
  661. package/skills/a2h-utg-explorer/scripts/tests/device_health.test.mjs +88 -0
  662. package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +187 -0
  663. package/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  664. package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +136 -0
  665. package/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  666. package/skills/a2h-utg-explorer/scripts/tests/first_round_phases.test.mjs +16 -0
  667. package/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +251 -0
  668. package/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +42 -0
  669. package/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +162 -0
  670. package/skills/a2h-utg-explorer/scripts/tests/node_coverage.test.mjs +193 -0
  671. package/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +204 -0
  672. package/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +355 -0
  673. package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  674. package/skills/a2h-utg-explorer/scripts/tests/recover.test.mjs +212 -0
  675. package/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  676. package/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +267 -0
  677. package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +213 -0
  678. package/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  679. package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +453 -0
  680. package/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +131 -0
  681. package/skills/a2h-utg-explorer/scripts/tests/scope.test.mjs +229 -0
  682. package/skills/a2h-utg-explorer/scripts/tests/scroll_sweep.test.mjs +336 -0
  683. package/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  684. package/skills/a2h-utg-explorer/scripts/tests/state_ambiguity.test.mjs +92 -0
  685. package/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  686. package/skills/a2h-utg-explorer/scripts/tests/u2_backend.test.mjs +346 -0
  687. package/skills/a2h-utg-explorer/scripts/tests/ui_state_anchors.test.mjs +112 -0
  688. package/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  689. package/skills/a2h-utg-explorer/scripts/tests/worklist_parts.test.mjs +24 -0
  690. package/skills/a2h-utg-explorer/scripts/utg_explorer/_device_io.mjs +244 -0
  691. package/skills/a2h-utg-explorer/scripts/utg_explorer/_py.mjs +2097 -0
  692. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +1231 -0
  693. package/skills/a2h-utg-explorer/scripts/utg_explorer/attest.mjs +63 -0
  694. package/skills/a2h-utg-explorer/scripts/utg_explorer/chain.mjs +63 -0
  695. package/skills/a2h-utg-explorer/scripts/utg_explorer/coverage.mjs +89 -0
  696. package/skills/a2h-utg-explorer/scripts/utg_explorer/device_lock.mjs +46 -0
  697. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +1200 -0
  698. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +1558 -0
  699. package/skills/a2h-utg-explorer/scripts/variant.mjs +75 -0
  700. package/skills/a2h-utg-explorer/scripts/worklist_parts.mjs +122 -0
  701. package/skills/a2h-utg-static/SKILL.md +361 -0
  702. package/skills/a2h-utg-static/config.json +19 -0
  703. package/skills/a2h-utg-static/references/extractors.md +217 -0
  704. package/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +248 -0
  705. package/skills/a2h-utg-static/references/view-interactions.md +215 -0
  706. package/skills/a2h-utg-static/scripts/_graph.mjs +361 -0
  707. package/skills/a2h-utg-static/scripts/_py.mjs +2177 -0
  708. package/skills/a2h-utg-static/scripts/_spawn.mjs +45 -0
  709. package/skills/a2h-utg-static/scripts/activity_nav.mjs +738 -0
  710. package/skills/a2h-utg-static/scripts/activity_widgets.mjs +254 -0
  711. package/skills/a2h-utg-static/scripts/adapter_nav.mjs +229 -0
  712. package/skills/a2h-utg-static/scripts/androidfragment_nav.mjs +208 -0
  713. package/skills/a2h-utg-static/scripts/assemble.mjs +2065 -0
  714. package/skills/a2h-utg-static/scripts/audit.mjs +268 -0
  715. package/skills/a2h-utg-static/scripts/carry_answers.mjs +201 -0
  716. package/skills/a2h-utg-static/scripts/click_paths.mjs +594 -0
  717. package/skills/a2h-utg-static/scripts/compose_body_text.mjs +226 -0
  718. package/skills/a2h-utg-static/scripts/compose_merge.mjs +263 -0
  719. package/skills/a2h-utg-static/scripts/compose_nav.mjs +1216 -0
  720. package/skills/a2h-utg-static/scripts/compose_navbar_nav.mjs +238 -0
  721. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +2760 -0
  722. package/skills/a2h-utg-static/scripts/compose_titles.mjs +365 -0
  723. package/skills/a2h-utg-static/scripts/compose_widgets.mjs +498 -0
  724. package/skills/a2h-utg-static/scripts/dialog_listener_nav.mjs +237 -0
  725. package/skills/a2h-utg-static/scripts/dialogshow_nav.mjs +308 -0
  726. package/skills/a2h-utg-static/scripts/fragfactory_nav.mjs +170 -0
  727. package/skills/a2h-utg-static/scripts/fragment_nav.mjs +1136 -0
  728. package/skills/a2h-utg-static/scripts/guard_subjects.mjs +162 -0
  729. package/skills/a2h-utg-static/scripts/hg_query.mjs +137 -0
  730. package/skills/a2h-utg-static/scripts/host_resolve.mjs +393 -0
  731. package/skills/a2h-utg-static/scripts/hybrid_bundle.mjs +165 -0
  732. package/skills/a2h-utg-static/scripts/hybrid_pages.mjs +713 -0
  733. package/skills/a2h-utg-static/scripts/hybrid_scope.mjs +660 -0
  734. package/skills/a2h-utg-static/scripts/interaction_sites.mjs +267 -0
  735. package/skills/a2h-utg-static/scripts/io_utils.mjs +59 -0
  736. package/skills/a2h-utg-static/scripts/label_resolve.mjs +864 -0
  737. package/skills/a2h-utg-static/scripts/launch_extras.mjs +91 -0
  738. package/skills/a2h-utg-static/scripts/layout_resolve.mjs +148 -0
  739. package/skills/a2h-utg-static/scripts/manifest.mjs +483 -0
  740. package/skills/a2h-utg-static/scripts/measure/measure_corpus.mjs +297 -0
  741. package/skills/a2h-utg-static/scripts/measure/measure_guards.mjs +98 -0
  742. package/skills/a2h-utg-static/scripts/media_browse_nav.mjs +356 -0
  743. package/skills/a2h-utg-static/scripts/menu_nav.mjs +603 -0
  744. package/skills/a2h-utg-static/scripts/navactions_nav.mjs +255 -0
  745. package/skills/a2h-utg-static/scripts/nl_hints.mjs +453 -0
  746. package/skills/a2h-utg-static/scripts/orphan_overlay_nav.mjs +89 -0
  747. package/skills/a2h-utg-static/scripts/phase_plan.mjs +108 -0
  748. package/skills/a2h-utg-static/scripts/phase_planner.mjs +119 -0
  749. package/skills/a2h-utg-static/scripts/plaindialog_nav.mjs +411 -0
  750. package/skills/a2h-utg-static/scripts/preference_nav.mjs +761 -0
  751. package/skills/a2h-utg-static/scripts/preference_widgets.mjs +142 -0
  752. package/skills/a2h-utg-static/scripts/presenter_nav.mjs +490 -0
  753. package/skills/a2h-utg-static/scripts/registry_nav.mjs +288 -0
  754. package/skills/a2h-utg-static/scripts/run_pipeline.mjs +870 -0
  755. package/skills/a2h-utg-static/scripts/scope_utils.mjs +430 -0
  756. package/skills/a2h-utg-static/scripts/screen_merge.mjs +287 -0
  757. package/skills/a2h-utg-static/scripts/screen_nav.mjs +279 -0
  758. package/skills/a2h-utg-static/scripts/single_host_nav.mjs +291 -0
  759. package/skills/a2h-utg-static/scripts/starter_nav.mjs +198 -0
  760. package/skills/a2h-utg-static/scripts/state_guard.mjs +579 -0
  761. package/skills/a2h-utg-static/scripts/static_prior.mjs +904 -0
  762. package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
  763. package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
  764. package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
  765. package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
  766. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  767. package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +90 -0
  768. package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
  769. package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
  770. package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
  771. package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  772. package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
  773. package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  774. package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  775. package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
  776. package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
  777. package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
  778. package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
  779. package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +284 -0
  780. package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
  781. package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
  782. package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
  783. package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
  784. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
  785. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
  786. package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  787. package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  788. package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
  789. package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
  790. package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
  791. package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
  792. package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
  793. package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
  794. package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
  795. package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
  796. package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
  797. package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
  798. package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +119 -0
  799. package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
  800. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  801. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  802. package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  803. package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  804. package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
  805. package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
  806. package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
  807. package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  808. package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  809. package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  810. package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
  811. package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
  812. package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
  813. package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
  814. package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
  815. package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
  816. package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  817. package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +33 -0
  818. package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  819. package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
  820. package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
  821. package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  822. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  823. package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
  824. package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  825. package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
  826. package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
  827. package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
  828. package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
  829. package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
  830. package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
  831. package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
  832. package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
  833. package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
  834. package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
  835. package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
  836. package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  837. package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  838. package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
  839. package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
  840. package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
  841. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
  842. package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
  843. package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
  844. package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  845. package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
  846. package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
  847. package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
  848. package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
  849. package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
  850. package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
  851. package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  852. package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  853. package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
  854. package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +58 -0
  855. package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
  856. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
  857. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  858. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
  859. package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
  860. package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  861. package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
  862. package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
  863. package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
  864. package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
  865. package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
  866. package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
  867. package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
  868. package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
  869. package/skills/a2h-utg-static/scripts/uniapp_nav.mjs +1119 -0
  870. package/skills/a2h-utg-static/scripts/uniapp_widgets.mjs +244 -0
  871. package/skills/a2h-utg-static/scripts/utg_html.mjs +721 -0
  872. package/skills/a2h-utg-static/scripts/view_interactions.mjs +799 -0
  873. package/skills/a2h-utg-static/scripts/view_widgets.mjs +512 -0
  874. package/skills/a2h-utg-static/scripts/viewpage_nav.mjs +589 -0
  875. package/skills/a2h-utg-static/scripts/vm_nav.mjs +422 -0
  876. package/skills/a2h-utg-static/scripts/window_nav.mjs +240 -0
  877. package/skills/a2h-utg-static/scripts/worklist_parts.mjs +154 -0
  878. package/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +769 -0
  879. package/skills/a2h-utg-static/tools/package.json +3 -0
  880. package/README.md +0 -445
  881. package/agents/logic-coder.md +0 -224
  882. package/agents/logic-context-builder.md +0 -212
  883. package/agents/scripts/hmos-precheck/backends/arkts.mjs +0 -567
  884. package/agents/scripts/hmos-precheck/backends/arkts_diff.mjs +0 -159
  885. package/agents/scripts/hmos-precheck/backends/arkts_project_rules.mjs +0 -398
  886. package/agents/scripts/hmos-precheck/backends/codelinter.mjs +0 -250
  887. package/agents/scripts/hmos-precheck/backends/project_integrity.mjs +0 -321
  888. package/agents/scripts/hmos-precheck/backends/static_precheck.mjs +0 -247
  889. package/agents/scripts/hmos-precheck/core/config.mjs +0 -184
  890. package/agents/scripts/hmos-precheck/core/diagnostic_scope.mjs +0 -20
  891. package/agents/scripts/hmos-precheck/core/process_adapter.mjs +0 -47
  892. package/agents/scripts/hmos-precheck/core/project_catalog.mjs +0 -50
  893. package/agents/scripts/hmos-precheck/core/result_projection.mjs +0 -147
  894. package/agents/scripts/hmos-precheck/core/scope_plan.mjs +0 -131
  895. package/agents/scripts/hmos-precheck/core/sdk_context.mjs +0 -67
  896. package/agents/scripts/hmos-precheck/docs/architecture.md +0 -37
  897. package/agents/scripts/hmos-precheck/docs/performance-optimization.md +0 -28
  898. package/agents/scripts/hmos-precheck/docs/upstream-reference.json +0 -19
  899. package/agents/scripts/hmos-precheck/docs/validation.md +0 -50
  900. package/agents/scripts/hmos-precheck/index.mjs +0 -17
  901. package/agents/scripts/hmos-precheck/invocation.mjs +0 -231
  902. package/agents/scripts/hmos-precheck/rules/rule_case_matrix.csv +0 -32
  903. package/agents/scripts/hmos-precheck/rules/rule_inventory.csv +0 -64
  904. package/agents/scripts/hmos-precheck/rules/rule_inventory.mjs +0 -59
  905. package/agents/scripts/hmos-precheck/rules/rule_policy.mjs +0 -54
  906. package/agents/scripts/platform_query.mjs +0 -626
  907. package/agents/scripts/platform_query.test.mjs +0 -422
  908. package/agents/self-test-fixer.md +0 -298
  909. package/agents/self-tester.md +0 -55
  910. package/agents/test-case-generation-generator.md +0 -317
  911. package/agents/test-case-generation-validator.md +0 -231
  912. package/dist/cli/config-store.js +0 -310
  913. package/dist/cli/config.js +0 -44
  914. package/dist/cli/env-vars.js +0 -127
  915. package/dist/cli/index.js +0 -56
  916. package/dist/cli/init.js +0 -1187
  917. package/dist/cli/uninstall.js +0 -427
  918. package/dist/utils/regex.js +0 -8
  919. package/env-requirements.json +0 -179
  920. package/resource/choose_editor.png +0 -0
  921. package/resource/convert_pipeline_process.svg +0 -103
  922. package/resource/project_architecture.svg +0 -122
  923. package/resource/set_environment.png +0 -0
  924. package/resource/set_multimodel.png +0 -0
  925. package/resource/set_sdk.png +0 -0
  926. package/resource/title_dark.png +0 -0
  927. package/skills/hmos-batch-ui-align/SKILL.md +0 -413
  928. package/skills/hmos-batch-ui-align/references/conversion-procedure.md +0 -661
  929. package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +0 -117
  930. package/skills/hmos-batch-ui-align/references/mvvm/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +0 -648
  931. package/skills/hmos-batch-ui-align/references/mvvm/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +0 -1183
  932. package/skills/hmos-batch-ui-align/references/mvvm/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +0 -576
  933. package/skills/hmos-batch-ui-align/references/mvvm/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +0 -297
  934. package/skills/hmos-batch-ui-align/references/mvvm/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +0 -395
  935. package/skills/hmos-batch-ui-align/references/mvvm/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +0 -903
  936. package/skills/hmos-batch-ui-align/references/mvvm/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +0 -1178
  937. package/skills/hmos-batch-ui-align/references/mvvm/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +0 -355
  938. package/skills/hmos-batch-ui-align/references/mvvm//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +0 -11
  939. package/skills/hmos-batch-ui-align/references/mvvm-v2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +0 -206
  940. package/skills/hmos-batch-ui-align/references/mvvm-v2/@Local/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/351/203/250/347/212/266/346/200/201.md +0 -750
  941. package/skills/hmos-batch-ui-align/references/mvvm-v2/@Param/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md +0 -840
  942. package/skills/hmos-batch-ui-align/references/mvvm-v2/@Provider/350/243/205/351/245/260/345/231/250/345/222/214@Consumer/350/243/205/351/245/260/345/231/250/357/274/232/350/267/250/347/273/204/344/273/266/345/261/202/347/272/247/345/217/214/345/220/221/345/220/214/346/255/245.md +0 -856
  943. package/skills/hmos-batch-ui-align/references/mvvm-v2/AppStorageV2/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200UI/347/212/266/346/200/201/345/255/230/345/202/250.md +0 -294
  944. package/skills/hmos-batch-ui-align/references/mvvm-v2/PersistenceV2/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +0 -1220
  945. package/skills/hmos-batch-ui-align/references/mvvm-v2//347/212/266/346/200/201/347/256/241/347/220/206V1/345/220/221V2/350/277/201/347/247/273/344/270/216/346/267/267/347/224/250/346/214/207/345/257/274.md +0 -840
  946. package/skills/hmos-batch-ui-align/scripts/arkts_static_check.ts +0 -1592
  947. package/skills/hmos-batch-ui-align/scripts/measure_pack.ts +0 -752
  948. package/skills/hmos-convert-pipeline/SKILL.md +0 -486
  949. package/skills/hmos-incremental-ui-align/README.md +0 -251
  950. package/skills/hmos-incremental-ui-align/SKILL.md +0 -375
  951. package/skills/hmos-incremental-ui-align/diff_analysis.md +0 -53
  952. package/skills/hmos-incremental-ui-align/page_align.md +0 -62
  953. package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +0 -38
  954. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +0 -2089
  955. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +0 -1033
  956. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +0 -106
  957. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217V1.md +0 -911
  958. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Computed/350/243/205/351/245/260/345/231/250/357/274/232/350/256/241/347/256/227/345/261/236/346/200/247.md +0 -373
  959. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Event/350/243/205/351/245/260/345/231/250/357/274/232/350/247/204/350/214/203/347/273/204/344/273/266/350/276/223/345/207/272.md +0 -158
  960. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Monitor/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/344/277/256/346/224/271/345/274/202/346/255/245/347/233/221/345/220/254.md +0 -1704
  961. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@ObservedV2/350/243/205/351/245/260/345/231/250/345/222/214@Trace/350/243/205/351/245/260/345/231/250/357/274/232/347/261/273/345/261/236/346/200/247/345/217/230/345/214/226/350/247/202/346/265/213.md +0 -1012
  962. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Once/350/243/205/351/245/260/345/231/250/357/274/232/345/210/235/345/247/213/345/214/226/345/220/214/346/255/245/344/270/200/346/254/241.md +0 -164
  963. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Type/350/243/205/351/245/260/345/231/250/357/274/232/346/240/207/350/256/260/347/261/273/345/261/236/346/200/247/347/232/204/347/261/273/345/236/213.md +0 -83
  964. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +0 -47
  965. package/skills/hmos-incremental-ui-align/references/State_Model_Template.md +0 -74
  966. package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +0 -34
  967. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +0 -2533
  968. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +0 -555
  969. package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.ts +0 -937
  970. package/skills/hmos-incremental-ui-align/scripts/extract_checklist.ts +0 -343
  971. package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +0 -76
  972. package/skills/hmos-incremental-ui-align/scripts/page_capture.ts +0 -977
  973. package/skills/hmos-incremental-ui-align/scripts/page_capture_burst.ts +0 -188
  974. package/skills/hmos-integration-test/README.md +0 -341
  975. package/skills/hmos-integration-test/SKILL.md +0 -464
  976. package/skills/hmos-integration-test/scripts/report-tool.ts +0 -791
  977. package/skills/hmos-integration-test/scripts/resolve-metadata-tool.ts +0 -125
  978. package/skills/hmos-integration-test/scripts/self-test-runner.ts +0 -756
  979. package/skills/hmos-integration-test/scripts/testcases-tool.ts +0 -239
  980. package/skills/hmos-resources-convert/SKILL.md +0 -891
  981. package/skills/hmos-spec-generate/SKILL.md +0 -404
  982. package/skills/hmos-test-case-generation/README.md +0 -241
  983. package/skills/hmos-test-case-generation/SKILL.md +0 -324
  984. package/skills/hmos-test-case-generation/references/contract.md +0 -315
  985. package/skills/hmos-test-case-generation/references/review-notes-template.md +0 -84
  986. package/skills/hmos-test-case-generation/references/ui-elements-schema.md +0 -142
  987. package/skills/hmos-test-case-generation/tools/convert_to_ui_elements.ts +0 -550
  988. package/skills/hmos-test-case-generation/tools/validate.ts +0 -1312
  989. package/tools/bfs-crawl/README.md +0 -73
  990. package/tools/bfs-crawl/android_viewtree_bfs_crawler.ts +0 -1662
  991. /package/{README.en.md → skills/a2h-arch-generate/scripts/module_create/har/consumer-rules.txt} +0 -0
  992. /package/skills/{hmos-spec-generate → a2h-spec-generate}/template/REQ.xlsx +0 -0
@@ -0,0 +1,1869 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * group_queue.mjs —— Work-queue scheduler for Step 5 group conversion: refill a slot the moment a group ends.
4
+ *
5
+ * Why not waves of `task` calls: a wave blocks the parent until its slowest agent
6
+ * returns, so every finished slot idles (measured: G014 done at 112 min, wave held
7
+ * to 166 min by G006). And a network error with no watchdog cost ~4 h idle.
8
+ *
9
+ * The parent dispatches every group as a BACKGROUND sub-agent of its own host
10
+ * (Claude Code `Agent`; opencode v2 `subagent`, opencode v1 / DevEco `task`, both with
11
+ * `background: true`). This
12
+ * script owns no process: it is the scheduling state machine the parent consults.
13
+ * `lease` says which units to dispatch now, `release` triages one that ended from
14
+ * disk (group_watch.triage), `reap` finds silent ones, and `wait` blocks until a
15
+ * disk signal says a slot can be refilled -- a group's report file appeared, an
16
+ * agent went silent, or a background job exited. Refill never depends on when the
17
+ * host delivers its completion notification.
18
+ *
19
+ * * ready = its real dependencies finished, every `after` group finished, no
20
+ * running group on the same non-null `lane` (nor a lower-stage one of that
21
+ * lane still unfinished), and <prompts>/<GID>.md exists. Real dependencies:
22
+ * stage 1 -> the stage-0 groups (with .hometrans/shell_contract.json and no
23
+ * --no-overlap-entry: only those it reuses a component from); stage 2 -> the
24
+ * stage-0 groups, its `reuse_from` leaders and its `template_groups` (the
25
+ * captured groups whose measurements it borrows). `--stage-barrier` restores
26
+ * "every lower stage finished". Measured (AntennaPod 10-08): 22 of 29 stage-2
27
+ * groups had no such dependency left at 15:55 but waited for the last stage-1
28
+ * group until 19:34, with 2-4 of 8 slots busy
29
+ * * the plan is re-read on every call: a re-run of build_conversion_set.mjs while
30
+ * the explorer is still going adds groups (pending), and a finished group
31
+ * whose tier went source-only -> captured is re-queued against the capture.
32
+ * While plan.exploring is true, a source-only group is held only while one of
33
+ * its nodes is in the explorer's <campaign>/capture_pending.json (written by
34
+ * run_cycle.mjs; no file = every source-only group held), and `wait` does not
35
+ * report idle even when nothing is ready
36
+ * * among ready groups, the ones others wait on and the larger ones go first
37
+ * * width (--width, default 6): measured on AntennaPod 10-14 (one gateway, 4.4k
38
+ * turns), per-agent output stayed ~50 tok/s up to 5 agents in flight and ~40 at
39
+ * 7-8, so aggregate throughput rose from ~160 tok/s at 3 to ~270 at 6. An
40
+ * earlier gateway capped total throughput instead (~1.3 turns/min); lower the
41
+ * width there
42
+ * * --max-agents (default 10) caps conversion agents PLUS the explorer's reviewers
43
+ * still at work (dispatched per .hometrans/work/reviewers.json, answers not complete;
44
+ * without that file, the incomplete answers files in capture_pending.json `reviews`):
45
+ * reviewers gate capture, so conversion gets the agents left over. Measured on
46
+ * AntennaPod 10-15 (glm gateway): aggregate output peaked at 8-11 agents and fell at 16+.
47
+ * --width defaults to --max-agents, so once capture ends conversion uses all of them
48
+ * (measured: 26 groups left after capture ran 6 at a time)
49
+ * * the plan never trails the captures: `lease` and `wait` re-run export_ui_info.mjs +
50
+ * build_conversion_set.mjs when the campaign's audit.json digest differs from the
51
+ * plan's (`refresh`), and a source-only group is not leased from a stale plan. A
52
+ * group whose tier changed waits for a prompt written after the change
53
+ * (`stale_prompts`); `owed` lists the prompts and measure packs the parent must write
54
+ * * backfill (--no-backfill turns it off): a slot no ready group can use goes to a
55
+ * source-only group held only for capture, fewest nodes left to capture first; one
56
+ * captured later is re-queued against the capture
57
+ * * an agent silent for the stall limit (--stall-min, default 20, scaled up with the
58
+ * agents in flight, see stallLimit; no heartbeat, no write) is reaped and resumed
59
+ * IN ITS OWN SESSION (same sessionID/task_id): opencode/DevEco have no cancel tool, so a
60
+ * fresh dispatch could leave two agents writing one file. A second stall of the
61
+ * same session fails the group
62
+ * * network failure -> resume the same session; empty report -> one fresh,
63
+ * narrowed redispatch; complete/partial -> `returned` for parent verification
64
+ * * family batching: ready groups with the same stage, `after` set and `reuse_from`
65
+ * families (no lane) go to ONE agent, up to --batch-groups / --batch-pages. Same
66
+ * shared components, conventions and host chain -- read once, converted in
67
+ * sequence. Each group is released as soon as its own report file exists, so its
68
+ * dependants start before the batch ends.
69
+ *
70
+ * node group_queue.mjs init <harmony_dir> --prompts <dir> [--width 6]
71
+ * node group_queue.mjs lease <harmony_dir> # units to dispatch now
72
+ * node group_queue.mjs message <harmony_dir> --unit G002+G003 # its stored message (read-only)
73
+ * node group_queue.mjs bind <harmony_dir> --unit G002+G003 --task <task id>
74
+ * node group_queue.mjs release <harmony_dir> --unit G002+G003 [--task <id>] [--stalled] [--error "..."]
75
+ * node group_queue.mjs reap <harmony_dir> # reported / silent units
76
+ * node group_queue.mjs review-bind <harmony_dir> --name <part> --answers <path> [--task <id>]
77
+ * node group_queue.mjs wait <harmony_dir> [--timeout-s 540] [--job run_cycle]
78
+ * node group_queue.mjs status <harmony_dir>
79
+ * node group_queue.mjs refresh <harmony_dir> [--force] # rebuild a plan behind the captures
80
+ * node group_queue.mjs verified <harmony_dir> --group G007
81
+ * node group_queue.mjs requeue <harmony_dir> --group G007 [--message "..."] [--resume | --fresh]
82
+ * node group_queue.mjs stop <harmony_dir>
83
+ *
84
+ * State: .hometrans/queue_state.json, written only by the parent through this
85
+ * script. Reports: .hometrans/queue_logs/<GID>.report.md, written by the agents.
86
+ *
87
+ * 组 id 作为 queue_state.json 的键,假定不是纯整数形式(JS 对象会把整数键排到前面)。
88
+ */
89
+
90
+ import * as fs from 'node:fs';
91
+ import * as path from 'node:path';
92
+ import { spawnSync } from 'node:child_process';
93
+ import { fileURLToPath, pathToFileURL } from 'node:url';
94
+ import * as ac from './agent_cli.mjs';
95
+ import * as answersCheck from './answers_check.mjs';
96
+ import * as detach from './detach.mjs';
97
+ import { captureDigest } from './export_ui_info.mjs';
98
+ import * as harmonyIndex from './harmony_index.mjs';
99
+ import * as gw from './group_watch.mjs';
100
+
101
+ const THIS_FILE = fileURLToPath(import.meta.url);
102
+
103
+ export const SUCCEEDED = new Set(['returned', 'verified', 'skipped']);
104
+ export const FINISHED = new Set([...SUCCEEDED, 'failed', 'blocked']);
105
+ export const MAX_ATTEMPTS = 3;
106
+ /** Default --stall-min; the effective limit never drops below group_watch FIRST_WRITE_MIN and grows with load (stallLimit). */
107
+ export const STALL_MIN = 20.0;
108
+ /**
109
+ * queue_state.json lock (group_watch._locked): every mutating command holds it, so parallel
110
+ * calls serialize (measured: four parallel `release` calls lost G006's update). A dead holder
111
+ * (its pid gone) is cleared at once; a live one is waited for up to 120 s.
112
+ */
113
+ const LOCK = { staleS: 600, waitS: 120, what: 'queue state' };
114
+ export const NARROW = 'Your previous attempt on this group ended without writing any file. '
115
+ + 'Write the anchor page file first (structure first, refine after), then the rest.';
116
+ export const NARROW_VERIFY = 'Your previous attempt on this group ended without its report. This group '
117
+ + 'writes no file of its own (its files belong to an earlier group): finish the '
118
+ + 'verification and write its report as below.';
119
+ /**
120
+ * Measured (AntennaPod 10-17): a resumed batch agent hand-deleted dispatch_log.json entries to
121
+ * fix what its own re-run of `dispatch` broke. Every launch and resume message carries this.
122
+ */
123
+ export const KEEP_OUT = 'Never edit files under .hometrans/ other than your report file and what the skill '
124
+ + 'scripts write themselves (never dispatch_log.json, queue_state.json, heartbeats/, dispatch/).';
125
+ export const RESUME = 'You were interrupted (network error or no progress). Continue exactly where you '
126
+ + 'stopped; do not redo files already written. When you (re)start a group with '
127
+ + '`group_watch.mjs dispatch`, run it with `--resume`. ' + KEEP_OUT;
128
+ export const REPORT_RULE = 'When a group is finished, write its full report (heading `## REPORT <GID>`, '
129
+ + 'Phase 5 evidence included) to its report file -- {reports} -- then continue. '
130
+ + 'Your final reply is ONE line: `DONE {gids}`, never the report itself.';
131
+ export const LAUNCH = 'Read the file {prompt} and follow it fully. It is your complete task '
132
+ + 'for conversion group {gid}. ' + KEEP_OUT + '\n';
133
+ export const LAUNCH_BATCH = 'You convert {n} sibling groups of one family, in this order: {gids}. Their prompts:\n'
134
+ + '{prompts}\n\n'
135
+ + 'Read all of them first. They share reuse sources, conventions and usually the host chain: '
136
+ + 'read each shared file ONCE and keep using it, do not re-read it per group.\n'
137
+ + 'Then ONE GROUP AT A TIME, in order: when you start a group run '
138
+ + '`node "{skill}/scripts/group_watch.mjs" dispatch "{hp}" --groups <GID>` (restarts its clock, '
139
+ + 'so its `check` verdicts apply to that group), convert it fully, run its Phase 5 rounds, '
140
+ + 'and write its report before starting the next group. If this session is resumed later, '
141
+ + 'add `--resume` to that command when you (re)start a group. '
142
+ + 'Every group keeps its own write set, contract and evidence; nothing is merged across groups. '
143
+ + KEEP_OUT + '\n';
144
+ export const RESUME_BATCH = ' Groups still to finish: {gids}. When you (re)start a group, run '
145
+ + '`node "{skill}/scripts/group_watch.mjs" dispatch "{hp}" --groups <GID> --resume` '
146
+ + '(always with --resume in this session: files you already wrote keep counting).';
147
+ /** The prompt the parent hands the sub-agent: identical for fresh and resume, the body is on disk. */
148
+ export const POINTER = 'Read the file {file} and follow it fully.';
149
+ export const RECAPTURED = 'This group was converted from source only; the explorer has since captured '
150
+ + 'it. Re-convert against the capture (measure packs now exist), keeping the '
151
+ + 'existing .ets files as the starting point, and report as usual.';
152
+
153
+ /** str.format 的具名占位符替换(只替换给出的键,值按字面插入)。 */
154
+ function fmt(tpl, vals) {
155
+ return tpl.replace(/\{(\w+)\}/g, (m, k) => (Object.hasOwn(vals, k) ? String(vals[k]) : m));
156
+ }
157
+
158
+ /** 可被测试替换的实现:rename(os.replace)、now(时钟)、digest(采集摘要)、run(子脚本)。 */
159
+ export const _impl = {
160
+ rename: (a, b) => fs.renameSync(a, b),
161
+ now: () => ac.now(),
162
+ digest: (campaign) => captureDigest(campaign),
163
+ run: (script, args) => spawnSync(process.execPath, [script, ...args.map(String)],
164
+ { encoding: 'utf8', timeout: 600000, maxBuffer: 1 << 26, windowsHide: true }),
165
+ };
166
+
167
+ export function _now() {
168
+ return _impl.now();
169
+ }
170
+
171
+ export function _meta(hp) {
172
+ return path.join(String(hp), '.hometrans');
173
+ }
174
+
175
+ function sleepSync(s) {
176
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, s * 1000);
177
+ }
178
+
179
+ /**
180
+ * Atomic replace. On Windows the replace fails with PermissionError while any reader
181
+ * (another `status`/`wait` call) has the file open, so retry briefly instead of dying.
182
+ */
183
+ export function _save(file, obj, tries = 20) {
184
+ const tmp = file + '.tmp';
185
+ ac.writeText(tmp, ac.pyDumps(obj, 1));
186
+ for (let i = 0; i < tries; i++) {
187
+ try {
188
+ _impl.rename(tmp, file);
189
+ return;
190
+ } catch (e) {
191
+ if (!['EPERM', 'EACCES', 'EBUSY'].includes(e?.code) || i === tries - 1) throw e;
192
+ sleepSync(0.1 * (i + 1));
193
+ }
194
+ }
195
+ }
196
+
197
+ export function loadState(hp) {
198
+ return gw._load(path.join(_meta(hp), 'queue_state.json'), null);
199
+ }
200
+
201
+ const isFile = (f) => {
202
+ try {
203
+ return fs.statSync(f).isFile();
204
+ } catch {
205
+ return false;
206
+ }
207
+ };
208
+
209
+ /** Every member page already `done` in batch_progress.json (an earlier run). */
210
+ export function _progressDone(hp, group) {
211
+ const pages = ac.get(ac.or(gw._load(path.join(_meta(hp), 'batch_progress.json'), {}), {}), 'pages', {});
212
+ const dirs = ac.or(ac.get(group, 'page_dirs'), []);
213
+ return dirs.length > 0 && dirs.every((d) => ac.get(ac.get(pages, d, {}), 'status') === 'done');
214
+ }
215
+
216
+ /**
217
+ * [groups Map, exploring] from conversion_set.json; the builder may be rewriting
218
+ * it right now, so a torn read keeps the previous plan. `exploring` is also true
219
+ * while the explorer says it is not finished (capture_pending.json `finished: false`),
220
+ * whatever flag the plan was built with: measured (AntennaPod 10-15), a plan built
221
+ * without `--exploring` let source-only groups convert while their pages were captured.
222
+ */
223
+ export function _plan(hp, fallback = null) {
224
+ let cs;
225
+ try {
226
+ cs = gw._load(path.join(gw._paths(hp)[2], 'conversion_set.json'), {});
227
+ } catch {
228
+ return fallback;
229
+ }
230
+ const plan = ac.or(ac.get(cs, 'plan', {}), {});
231
+ const groups = new Map();
232
+ for (const g of ac.get(plan, 'groups', [])) groups.set(g.id, g);
233
+ return groups.size ? [groups, ac.truthy(ac.get(plan, 'exploring')) || campaignRunning(hp)] : fallback;
234
+ }
235
+
236
+ /** The explorer has said it is still running (capture_pending.json `finished: false`). */
237
+ export function campaignRunning(hp) {
238
+ return ac.get(_captureDoc(hp) ?? {}, 'finished') === false;
239
+ }
240
+
241
+ const _manifest = (hp) => {
242
+ try {
243
+ return gw._load(path.join(gw._paths(hp)[2], 'export_manifest.json'), null);
244
+ } catch {
245
+ return null; // torn write
246
+ }
247
+ };
248
+
249
+ /**
250
+ * Is conversion_set.json behind the campaign? `stale` when the captures moved on since
251
+ * the plan was built (audit.json digest, see export_ui_info.captureDigest), or the plan's
252
+ * `exploring` flag disagrees with the explorer's `finished`. Unknown (no export yet, no
253
+ * campaign, torn read) is never stale.
254
+ */
255
+ export function planFreshness(hp) {
256
+ const man = _manifest(hp);
257
+ const campaign = ac.get(man ?? {}, 'campaign');
258
+ if (!ac.truthy(campaign)) return { stale: false, why: 'no export yet' };
259
+ let plan;
260
+ try {
261
+ plan = ac.get(gw._load(path.join(gw._paths(hp)[2], 'conversion_set.json'), {}) ?? {}, 'plan');
262
+ } catch {
263
+ return { stale: false, why: 'plan being rewritten' };
264
+ }
265
+ if (!ac.isDict(plan)) return { stale: false, why: 'no plan yet' };
266
+ const now = _impl.digest(campaign);
267
+ const doc = _captureDoc(hp);
268
+ const finished = ac.get(doc ?? {}, 'finished');
269
+ const why = [];
270
+ if (now !== null && now !== ac.get(plan, 'capture_digest', null)) {
271
+ why.push(`captures ${ac.get(plan, 'capture_digest', null) ?? 'unknown'} -> ${now}`);
272
+ }
273
+ if (finished === false && !ac.truthy(ac.get(plan, 'exploring'))) why.push('explorer running, plan not marked exploring');
274
+ if (finished === true && ac.truthy(ac.get(plan, 'exploring'))) why.push('explorer finished, plan still exploring');
275
+ return { stale: why.length > 0, why: why.join('; '), digest: now, finished: finished ?? null, campaign,
276
+ static_ws: ac.or(ac.get(ac.get(plan, 'built_from', {}) ?? {}, 'static_ws'), ac.get(man, 'static_ws')),
277
+ entry: ac.or(ac.get(ac.get(plan, 'built_from', {}) ?? {}, 'entry'), ac.get(plan, 'entry_node')),
278
+ // an incremental plan is rebuilt with its scope, or the refresh would plan the whole app
279
+ scope: ac.get(ac.get(plan, 'built_from', {}) ?? {}, 'scope', null) ?? null,
280
+ existing: ac.get(ac.get(plan, 'built_from', {}) ?? {}, 'existing', null) ?? null };
281
+ }
282
+
283
+ const _refreshMark = (hp) => path.join(_meta(hp), 'plan_refresh.json');
284
+ /** A failed refresh is retried for the same captures after this long (never on every poll). */
285
+ export const REFRESH_RETRY_S = 300;
286
+ /**
287
+ * plan_refresh.json lock: `lease` and `wait` may refresh at the same time, and export_ui_info
288
+ * clears and rewrites each page dir, so two runs corrupt each other. Held for both builders
289
+ * (up to 2 x 600 s); a second caller waits, then sees the plan fresh.
290
+ */
291
+ const REFRESH_LOCK = { staleS: 1500, waitS: 1500, what: 'plan refresh' };
292
+
293
+ /**
294
+ * Bring conversion_set.json up to the campaign: export_ui_info.mjs + build_conversion_set.mjs
295
+ * (`--exploring` while the explorer runs, its entry kept), the same commands Step 3.2 item 5
296
+ * runs. Called by `lease` and `wait`, so the plan never trails the captures by more than one
297
+ * poll. One refresh at a time (REFRESH_LOCK). A refresh that left the plan matching is not
298
+ * re-run for the same captures; a failed one is retried after REFRESH_RETRY_S (no busy loop);
299
+ * `force` retries at once. Returns what the parent still owes the new plan: prompts and measure packs.
300
+ */
301
+ export function refreshPlan(hp, { force = false } = {}) {
302
+ const f0 = planFreshness(hp);
303
+ if (!f0.stale && !force) return { refreshed: false, why: f0.why || 'fresh', ...owed(hp) };
304
+ fs.mkdirSync(_meta(hp), { recursive: true });
305
+ return gw._locked(_refreshMark(hp), () => _refreshPlan(hp, force), REFRESH_LOCK);
306
+ }
307
+
308
+ function _refreshPlan(hp, force) {
309
+ const f = planFreshness(hp); // again: another caller may have refreshed while this one waited
310
+ if (!f.stale && !force) return { refreshed: false, why: f.why || 'fresh', ...owed(hp) };
311
+ const mark = gw._load(_refreshMark(hp), null);
312
+ const key = `${f.digest}|${f.finished}`;
313
+ // one attempt per capture state: a build that still does not match is reported once; a
314
+ // failure is reported once and retried only after REFRESH_RETRY_S
315
+ const failed = ac.get(mark ?? {}, 'ok') === false;
316
+ const recent = _now() - (ac.get(mark ?? {}, 'at') ?? 0) < REFRESH_RETRY_S;
317
+ if (!force && ac.get(mark ?? {}, 'key') === key && (!failed || recent)) {
318
+ return { refreshed: false, ...(failed ? { error: ac.get(mark, 'error') } : {}),
319
+ why: `already refreshed for these captures (${failed ? 'failed' : 'ok'}): ${f.why}`, ...owed(hp) };
320
+ }
321
+ if (!ac.truthy(f.static_ws)) {
322
+ return { refreshed: false, why: 'no static workspace recorded: run export_ui_info.mjs --static-ws once', ...owed(hp) };
323
+ }
324
+ const here = path.dirname(THIS_FILE);
325
+ const uiInfo = gw._paths(hp)[2];
326
+ const steps = [
327
+ ['export_ui_info.mjs', f.campaign, '--static-ws', f.static_ws, '--out', uiInfo],
328
+ ['build_conversion_set.mjs', f.static_ws, '--ui-info', uiInfo,
329
+ ...(ac.truthy(f.entry) ? ['--entry', f.entry] : []), ...(f.finished === true ? [] : ['--exploring']),
330
+ ...(ac.truthy(f.scope) ? ['--scope', f.scope] : []), ...(ac.truthy(f.scope) && ac.truthy(f.existing) ? ['--existing', f.existing] : [])],
331
+ ];
332
+ const out = [];
333
+ let error = null;
334
+ for (const [script, ...args] of steps) {
335
+ const r = _impl.run(path.join(here, script), args);
336
+ out.push(`${script}: exit ${r.status}; ${String(r.stdout ?? '').trim().slice(-300)}`);
337
+ if (r.status !== 0) {
338
+ error = `${script} exit ${r.status}: ${String(r.stderr ?? '').trim().slice(-600)}`;
339
+ break;
340
+ }
341
+ }
342
+ _save(_refreshMark(hp), { key, ok: !error, error, at: _now(), why: f.why, out });
343
+ return { refreshed: !error, attempted: true, why: f.why, ...(error ? { error } : {}), out, ...owed(hp) };
344
+ }
345
+
346
+ /**
347
+ * Work the parent owes the plan before the queue can lease it: a prompt for a new group, a
348
+ * prompt rewritten after its group's tier changed (`stale_prompts`), and a measure pack for
349
+ * every captured page of a group still to convert.
350
+ */
351
+ export function owed(hp) {
352
+ const st = loadState(hp);
353
+ const p = _plan(hp, null);
354
+ if (!st || !p) return { prompts_missing: [], prompts_stale: [], measure_packs_missing: [] };
355
+ const [plan] = p;
356
+ const [, , uiInfo] = gw._paths(hp);
357
+ const open = [...plan.keys()].filter((g) => ['pending', 'queued'].includes(ac.get(st.groups[g] ?? {}, 'state')));
358
+ // A running group reads its packs while it works and is re-queued with them afterwards:
359
+ // a page captured under it needs its pack now (measured: 6 groups gained captured members
360
+ // mid-run and nothing listed their missing packs).
361
+ const running = [...plan.keys()].filter((g) => ac.get(st.groups[g] ?? {}, 'state') === 'running');
362
+ const packs = [];
363
+ for (const g of [...open, ...running]) {
364
+ for (const d of ac.or(ac.get(plan.get(g), 'page_dirs'), [])) {
365
+ if (isFile(path.join(uiInfo, d, 'screenshot.png')) && !isFile(path.join(uiInfo, d, 'measure_pack.json'))) packs.push(d);
366
+ }
367
+ }
368
+ return {
369
+ prompts_missing: open.filter((g) => !isFile(path.join(st.config.prompts, `${g}.md`))),
370
+ prompts_stale: open.filter((g) => _promptStale(st, g)),
371
+ prompts_invalid: Object.fromEntries(open.map((g) => [g, promptProblem(st, g)]).filter(([, w]) => w)),
372
+ // re-queued with RECAPTURED once released: rewrite their prompts for the new evidence
373
+ recaptured_running: running.filter((g) => ac.truthy(ac.get(st.groups[g], 'recaptured_while_running'))),
374
+ measure_packs_missing: [...new Set(packs)].sort(cmpStr),
375
+ };
376
+ }
377
+
378
+ const _mtime_ = (f) => {
379
+ try {
380
+ return fs.statSync(f).mtimeMs / 1000;
381
+ } catch {
382
+ return null;
383
+ }
384
+ };
385
+
386
+ /**
387
+ * Template placeholders of SKILL.md 5.2/5.3 that a written prompt must not still contain:
388
+ * an agent told to run `group_watch.mjs check … --group <GID>` heartbeats for no group and
389
+ * is reaped as stalled while it works (measured: 13 of 14 prompts; 2 groups reaped alive).
390
+ * Only the skill's own names: ArkTS samples in a prompt legitimately contain `${…}`.
391
+ */
392
+ export const PROMPT_PLACEHOLDERS = ['<GID>', '<GID…>', '<GID...>', '${harmony_project_dir}', '{harmony_project_dir}',
393
+ '<harmony_dir>', '${android_project_dir}', '{android_project_dir}', '<this skill>', '<prompts_dir>'];
394
+ /** Host Read tools truncate a file around 50 KB; a longer prompt is read in part (measured: 67.7 KB). */
395
+ export const PROMPT_MAX_BYTES = 48 * 1024;
396
+
397
+ /** Why group `gid`'s prompt cannot be handed out as written, or null (missing: reported elsewhere). */
398
+ export function promptProblem(st, gid) {
399
+ let text;
400
+ try {
401
+ text = fs.readFileSync(path.join(st.config.prompts, `${gid}.md`), 'utf8');
402
+ } catch {
403
+ return null;
404
+ }
405
+ const left = PROMPT_PLACEHOLDERS.filter((p) => text.includes(p));
406
+ if (left.length) return `unfilled placeholder ${left.join(', ')}: substitute the real values`;
407
+ const size = Buffer.byteLength(text, 'utf8');
408
+ if (size > PROMPT_MAX_BYTES) {
409
+ return `${Math.round(size / 1024)} KB > ${PROMPT_MAX_BYTES / 1024} KB: the agent's Read tool would truncate it; `
410
+ + 'reference the source pack and inputs by path instead of inlining them';
411
+ }
412
+ return null;
413
+ }
414
+
415
+ /** Its prompt predates the change of its tier: it was written for the old evidence. */
416
+ function _promptStale(st, gid) {
417
+ const t = ac.get(st.groups[gid] ?? {}, 'tier_changed_at');
418
+ const m = _mtime_(path.join(st.config.prompts, `${gid}.md`));
419
+ return ac.truthy(t) && m !== null && m < t;
420
+ }
421
+
422
+ function _row(hp, g) {
423
+ return { state: _progressDone(hp, g) ? 'skipped' : 'pending', attempts: 0, session: null, history: [],
424
+ tier: ac.get(g, 'tier', null), evidence: _evidence(g) };
425
+ }
426
+
427
+ /** The evidence a group's prompt is written for: its captured members and its page dirs. */
428
+ export function _evidence(g) {
429
+ const captured = ac.or(ac.get(g, 'members'), []).filter((m) => ac.get(m, 'tier') === 'captured')
430
+ .map((m) => String(m.node)).sort(cmpStr);
431
+ const dirs = [...ac.or(ac.get(g, 'page_dirs'), [])].map(String).sort(cmpStr);
432
+ return { captured, dirs };
433
+ }
434
+
435
+ /** The explorer's <campaign>/capture_pending.json (export_manifest.json's `campaign`); null = unknown. */
436
+ function _captureDoc(hp) {
437
+ if (!ac.truthy(hp)) return null;
438
+ try {
439
+ const [, , uiInfo] = gw._paths(hp);
440
+ const campaign = ac.get(gw._load(path.join(uiInfo, 'export_manifest.json'), {}) ?? {}, 'campaign');
441
+ if (!ac.truthy(campaign)) return null;
442
+ return gw._load(path.join(campaign, 'capture_pending.json'), null);
443
+ } catch {
444
+ return null; // torn write
445
+ }
446
+ }
447
+
448
+ /**
449
+ * Static node ids the explorer can still capture (Set), from <campaign>/capture_pending.json;
450
+ * the campaign is export_manifest.json's `campaign`. null = unknown: hold every source-only group.
451
+ */
452
+ export function capturePending(hp) {
453
+ const ids = ac.get(_captureDoc(hp) ?? {}, 'pending');
454
+ return Array.isArray(ids) ? new Set(ids) : null;
455
+ }
456
+
457
+ /** The parent's record of dispatched reviewers / skill agents: {<name>: {session, kind, answers, ...}}. */
458
+ export const _reviewersPath = (hp) => path.join(_meta(hp), 'work', 'reviewers.json');
459
+
460
+ /** reviewers.json as an object; null = no file (or not an object); a torn read retries briefly. */
461
+ function _reviewers(hp) {
462
+ for (let i = 0; i < 3; i++) {
463
+ try {
464
+ const doc = gw._load(_reviewersPath(hp), null);
465
+ return ac.isDict(doc) ? doc : null;
466
+ } catch {
467
+ sleepSync(0.05); // being rewritten
468
+ }
469
+ }
470
+ return null;
471
+ }
472
+
473
+ /**
474
+ * Explorer reviewers at work. They share the gateway with conversion agents, so they count
475
+ * against --max-agents (see freeSlots).
476
+ *
477
+ * Source: the reviewers the parent DISPATCHED, i.e. reviewers.json entries of kind `reviewer`
478
+ * (an entry without `kind` counts as one) with an `answers` path whose file is not complete yet
479
+ * (answers_check; an nl_hints part counts by completeness alone). `finished` is not consulted:
480
+ * a reviewer still running after the campaign ended still uses the gateway. Only when there is
481
+ * no reviewers.json, fall back to <campaign>/capture_pending.json `reviews` while the explorer
482
+ * runs. Measured (AntennaPod 10-17): `reviews`, rebuilt by run_cycle.mjs from `state.waiting`,
483
+ * listed 22 parts when 8 reviewers had been dispatched (conversion blocked 22 min) and 0 while
484
+ * run_cycle ran with 9 alive (19 agents in flight under max_agents 10).
485
+ */
486
+ export function activeReviews(hp) {
487
+ const recs = ac.truthy(hp) ? _reviewers(hp) : null;
488
+ if (recs) {
489
+ return Object.values(recs).filter((r) => ac.isDict(r) && (r.kind ?? 'reviewer') === 'reviewer'
490
+ && !ac.truthy(r.done) && ac.truthy(r.answers) && !_reviewConsumed(r.answers)
491
+ && !answersCheck.answersDone(r.answers).complete).length;
492
+ }
493
+ const doc = _captureDoc(hp);
494
+ if (!doc || ac.truthy(ac.get(doc, 'finished'))) return 0;
495
+ const files = ac.or(ac.get(doc, 'reviews'), []);
496
+ return files.filter((f) => !answersCheck.answersDone(f).complete).length;
497
+ }
498
+
499
+ /**
500
+ * A binding whose part was already consumed: its worklist part is gone (the explorer merged
501
+ * the parts, or re-extracted and re-split them) or the merged `<stem>_answers.json` is
502
+ * complete. Its answers file is then missing or renamed for good, so "not complete" would
503
+ * count it as at work forever. Measured: 7 consumed bindings held 7 of 10 slots with no
504
+ * reviewer alive.
505
+ */
506
+ function _reviewConsumed(answers) {
507
+ const wl = answersCheck.worklistFor(answers);
508
+ if (!wl) return false;
509
+ if (!fs.existsSync(wl)) return true;
510
+ const m = /^(.*)_answers\.part\d+\.json$/i.exec(path.basename(String(answers)));
511
+ if (!m) return false;
512
+ const merged = path.join(path.dirname(String(answers)), `${m[1]}_answers.json`);
513
+ return fs.existsSync(merged) && answersCheck.answersDone(merged).complete;
514
+ }
515
+
516
+ /** Mark a reviewer binding finished (its agent ended or was abandoned): it no longer counts. */
517
+ export function reviewUnbind(hp, name) {
518
+ if (!ac.truthy(name)) throw new ac.SystemExit('review-unbind requires --name');
519
+ const file = _reviewersPath(hp);
520
+ return gw._locked(file, () => {
521
+ const doc = gw._load(file, {});
522
+ if (!ac.isDict(doc) || !ac.isDict(doc[name])) throw new ac.SystemExit(`no reviewer binding named ${name}`);
523
+ doc[name] = { ...doc[name], done: true, done_at: _now() };
524
+ _save(file, doc);
525
+ return { unbound: name, reviews_running: activeReviews(hp) };
526
+ }, { ...LOCK, what: 'reviewers.json' });
527
+ }
528
+
529
+ /** Record (upsert) a dispatched reviewer in reviewers.json, so activeReviews counts it. Other fields are kept. */
530
+ export function reviewBind(hp, name, { answers, task = null, kind = 'reviewer' } = {}) {
531
+ if (!ac.truthy(name) || !ac.truthy(answers)) throw new ac.SystemExit('review-bind requires --name and --answers');
532
+ const file = _reviewersPath(hp);
533
+ return gw._locked(file, () => {
534
+ let doc;
535
+ try {
536
+ doc = gw._load(file, {});
537
+ } catch {
538
+ throw new ac.SystemExit(`${file} does not parse: fix it before binding more reviewers`);
539
+ }
540
+ if (!ac.isDict(doc)) doc = {};
541
+ const prev = ac.isDict(doc[name]) ? { ...doc[name] } : {};
542
+ delete prev.done; delete prev.done_at; // a re-bind is a new dispatch
543
+ const row = { ...prev, kind, answers: ac.resolvePath(answers), bound_at: _now() };
544
+ if (ac.truthy(task)) row.session = task;
545
+ doc[name] = row;
546
+ _save(file, doc);
547
+ return { bound: name, ...row, reviews_running: activeReviews(hp) };
548
+ }, { ...LOCK, what: 'reviewers.json' });
549
+ }
550
+
551
+ /**
552
+ * Effective stall limit, in minutes: max(--stall-min, FIRST_WRITE_MIN) * max(1, inflight / 8),
553
+ * inflight = running units + activeReviews. Agents heartbeat every ~10 tool calls; on a loaded
554
+ * gateway 10 calls take longer. Measured (AntennaPod 10-17): ~19 agents in flight, 4 healthy
555
+ * groups reaped at exactly 15.0 min. An explicit `stallMin` (tests, a deliberate override) is used as-is.
556
+ */
557
+ export function stallLimit(st, hp = null, stallMin = null) {
558
+ const inflight = runningUnits(st).size + activeReviews(hp ?? st.config.hp);
559
+ if (stallMin !== null && stallMin !== undefined) return { min: stallMin, inflight };
560
+ const base = Math.max(ac.get(st.config, 'stall_min', STALL_MIN) ?? STALL_MIN, gw.FIRST_WRITE_MIN);
561
+ return { min: ac.pyRound(base * Math.max(1, inflight / 8), 1), inflight };
562
+ }
563
+
564
+ /**
565
+ * Units that may start now: --width, less what runs, and never past --max-agents agents in
566
+ * flight counting explorer reviewers (they gate capture, so they come first). Measured
567
+ * (AntennaPod 10-15, one gateway): aggregate output peaked at 8-11 agents (~75 tok/s) and fell
568
+ * to ~45 at 16-19 (per agent 2.6 tok/s): 10 reviewers + 6 converters made both slower.
569
+ */
570
+ export function freeSlots(st, hp = null) {
571
+ const busy = runningUnits(st).size;
572
+ let free = st.width - busy;
573
+ const cap = ac.get(st.config, 'max_agents', 0);
574
+ if (cap > 0) free = Math.min(free, cap - activeReviews(hp ?? st.config.hp) - busy);
575
+ return Math.max(0, free);
576
+ }
577
+
578
+ const groupNodes = (g) => {
579
+ const ms = ac.or(ac.get(g, 'members'), []).map((m) => ac.get(m, 'node')).filter(ac.truthy);
580
+ return ms.length ? ms : [ac.get(g, 'anchor')].filter(ac.truthy);
581
+ };
582
+
583
+ /** A source-only group waits while exploring if the explorer may still capture one of its nodes. */
584
+ function _heldForCapture(g, exploring, pend) {
585
+ if (!exploring || ac.get(g, 'tier') !== 'source-only') return false;
586
+ return pend === null || groupNodes(g).some((n) => pend.has(n));
587
+ }
588
+
589
+ /** Fresh queue state over conversion_set.json's plan (options in snake_case, as the CLI flags). */
590
+ export function initState(hp, prompts, {
591
+ width = null, stall_min = STALL_MIN, batch_groups = 3, batch_pages = 8,
592
+ overlap_entry = true, stage_barrier = false, provides = true, max_agents = 10, backfill = true,
593
+ } = {}) {
594
+ // --max-agents is the real limit (reviewers included); width only caps conversion below it
595
+ width = width ?? (max_agents > 0 ? max_agents : 6);
596
+ const [, , uiInfo] = gw._paths(hp);
597
+ const groups = gw._groups(uiInfo);
598
+ if (!groups.size) throw new ac.SystemExit('conversion_set.json has no plan.groups');
599
+ const st = {
600
+ config: {
601
+ hp: ac.resolvePath(hp), prompts: ac.resolvePath(prompts), stall_min: stall_min ?? STALL_MIN, batch_groups, batch_pages,
602
+ // A follower waits for its family leader's shared component, not the whole leader group.
603
+ provides: ac.truthy(provides),
604
+ // Stage 1 starts beside the entry group when the shell is fixed in
605
+ // advance (shell_contract.mjs): Scheduling rule 1.
606
+ overlap_entry: ac.truthy(overlap_entry) && isFile(path.join(_meta(hp), 'shell_contract.json')),
607
+ stage_barrier: ac.truthy(stage_barrier),
608
+ max_agents: Math.max(0, max_agents ?? 0), backfill: ac.truthy(backfill),
609
+ },
610
+ width: Math.max(1, width), events: [], stopping: false, groups: {},
611
+ };
612
+ for (const [gid, g] of groups) {
613
+ st.groups[gid] = _row(hp, g);
614
+ }
615
+ return st;
616
+ }
617
+
618
+ const asMap = (plan) => (plan instanceof Map ? plan : new Map(Object.entries(plan)));
619
+ const cmpStr = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
620
+ const stage = (g) => ac.get(g, 'stage', 0);
621
+
622
+ const reuseLeaders = (g) => ac.or(ac.get(g, 'reuse_from'), []).map((r) => ac.get(r, 'from'));
623
+
624
+ /**
625
+ * Fold a rebuilt plan into the state: a new group is pending, a finished
626
+ * source-only group that is now captured is re-queued, a pending group that
627
+ * left the plan is dropped. Returns the changed ids.
628
+ */
629
+ export function syncPlan(hp, st, plan) {
630
+ plan = asMap(plan);
631
+ const changed = [];
632
+ for (const [gid, g] of plan) {
633
+ const s = st.groups[gid];
634
+ if (!s) {
635
+ st.groups[gid] = _row(hp, g);
636
+ _event(st, gid, 'added by a rebuilt plan');
637
+ changed.push(gid);
638
+ continue;
639
+ }
640
+ const was = ac.get(s, 'tier', null);
641
+ s.tier = ac.get(g, 'tier', null);
642
+ // Evidence is per member: a mixed group stays `captured` while one more member gets
643
+ // captured (or its page dir renumbered), so the group tier alone misses it.
644
+ const wasEv = ac.get(s, 'evidence', null);
645
+ const ev = _evidence(g);
646
+ s.evidence = ev;
647
+ const gained = wasEv !== null && ev.captured.some((m) => !wasEv.captured.includes(m));
648
+ const evChanged = wasEv !== null && (gained || ev.dirs.join('|') !== wasEv.dirs.join('|'));
649
+ // its prompt was written for the old evidence: `ready` waits for a newer one
650
+ if ((was !== null && was !== s.tier) || evChanged) s.tier_changed_at = _now();
651
+ // A running group cannot be redirected mid-flight: flag it, and re-queue it once released.
652
+ if (gained && s.state === 'running') {
653
+ s.recaptured_while_running = true;
654
+ _event(st, gid, `members captured while running: ${ev.captured.filter((m) => !wasEv.captured.includes(m)).join(', ')}`);
655
+ }
656
+ // the tier it was converted at (a backfilled source-only group may be captured while it runs)
657
+ const conv = ac.get(s, 'leased_tier', was);
658
+ const recaptured = (conv === 'source-only' && s.tier === 'captured') || gained || ac.truthy(s.recaptured_while_running);
659
+ if (recaptured && (SUCCEEDED.has(s.state) || s.state === 'failed')) {
660
+ // A stalled session may still be alive (opencode/DevEco cannot cancel it): the re-conversion
661
+ // resumes THAT session, as `requeue` does, instead of leasing a second writer on its files.
662
+ const alive = _stalledSession(s);
663
+ delete s.recaptured_while_running;
664
+ Object.assign(s, { state: 'queued', next_message: RECAPTURED, attempts: 0, narrowed: false });
665
+ delete s.next_session;
666
+ if (alive) s.next_session = s.session;
667
+ delete s.leased_tier;
668
+ _event(st, gid, 'recaptured: source-only -> captured, re-queued' + (alive ? ` (resume ${s.session}: it stalled)` : ''));
669
+ changed.push(gid);
670
+ }
671
+ }
672
+ for (const [gid, s] of Object.entries(st.groups)) {
673
+ if (!plan.has(gid) && (s.state === 'pending' || s.state === 'queued')) {
674
+ s.state = 'dropped';
675
+ _event(st, gid, 'dropped: no longer in the plan');
676
+ changed.push(gid);
677
+ }
678
+ }
679
+ return changed;
680
+ }
681
+
682
+ /** Groups this one waits for to have finished (Scheduling rules 1 and 6). */
683
+ export function _deps(st, plan, gid) {
684
+ plan = asMap(plan);
685
+ const g = plan.get(gid);
686
+ const c = st.config;
687
+ const lower = [...plan.keys()].filter((o) => stage(plan.get(o)) < stage(g));
688
+ let deps;
689
+ if (ac.truthy(ac.get(c, 'stage_barrier'))) {
690
+ deps = lower;
691
+ } else if (stage(g) === 1) {
692
+ deps = lower.filter((o) => stage(plan.get(o)) === 0);
693
+ if (ac.truthy(ac.get(c, 'overlap_entry'))) {
694
+ // The entry group's shell conventions are in shell_contract.json, so
695
+ // a stage-1 group no longer needs its files, only a component it
696
+ // reuses from it. Its lane still serialises any shared write.
697
+ const leaders = new Set(reuseLeaders(g));
698
+ deps = deps.filter((o) => leaders.has(o));
699
+ }
700
+ } else {
701
+ // Rule 6 where it matters: the conventions (stage 0), the shared
702
+ // component it builds on, and the measured pages it borrows values from.
703
+ const want = new Set([...reuseLeaders(g), ...ac.or(ac.get(g, 'template_groups'), [])]);
704
+ deps = lower.filter((o) => stage(plan.get(o)) === 0 || want.has(o));
705
+ }
706
+ const lane = ac.get(g, 'lane');
707
+ if (ac.truthy(lane)) { // a lane still converts in stage order
708
+ for (const o of lower) if (ac.get(plan.get(o), 'lane') === lane && !deps.includes(o)) deps.push(o);
709
+ }
710
+ return deps;
711
+ }
712
+
713
+ /**
714
+ * Families `gid` reuses from leader `o`, if `o` is only a component source for it
715
+ * (not its lane, not a stage-0 convention source, not a measurement source).
716
+ * Empty = `o` must finish as a whole.
717
+ */
718
+ export function _providable(st, plan, gid, o) {
719
+ plan = asMap(plan);
720
+ const c = st.config;
721
+ if (!ac.truthy(ac.get(c, 'provides')) || !ac.truthy(ac.get(c, 'hp'))) return [];
722
+ const g = plan.get(gid);
723
+ const lo = plan.get(o);
724
+ if (!g || !lo) return [];
725
+ const lane = ac.get(g, 'lane');
726
+ if (ac.truthy(lane) && ac.get(lo, 'lane') === lane) return [];
727
+ if (ac.or(ac.get(g, 'template_groups'), []).includes(o)) return [];
728
+ // stage 0 sets the conventions every later group cites, unless the shell contract fixed them
729
+ if (stage(lo) === 0 && stage(g) > 0 && !(stage(g) === 1 && ac.truthy(ac.get(c, 'overlap_entry')))) return [];
730
+ return [...new Set(ac.or(ac.get(g, 'reuse_from'), []).filter((r) => ac.get(r, 'from') === o)
731
+ .map((r) => ac.get(r, 'family')).filter(ac.truthy))];
732
+ }
733
+
734
+ /** `o` lets `gid` start: finished (dependency) / succeeded (`after`), or it provided every family `gid` reuses from it. */
735
+ export function _satisfied(st, plan, gid, o, okStates) {
736
+ if (okStates.has(ac.get(ac.get(st.groups, o, {}), 'state'))) return true;
737
+ const fams = _providable(st, plan, gid, o);
738
+ return fams.length > 0 && fams.every((f) => gw.provided(st.config.hp, o, f) !== null);
739
+ }
740
+
741
+ /**
742
+ * Dispatch order among ready units: a group others wait on first (it gates
743
+ * the most work), then the larger group (it sets the tail), then id.
744
+ */
745
+ export function priority(plan) {
746
+ plan = asMap(plan);
747
+ const waiters = new Map();
748
+ for (const [gid, g] of plan) {
749
+ const on = new Set([...ac.or(ac.get(g, 'after'), []), ...reuseLeaders(g),
750
+ ...ac.or(ac.get(g, 'template_groups'), [])]);
751
+ for (const o of on) if (plan.has(o) && o !== gid) waiters.set(o, (waiters.get(o) ?? 0) + 1);
752
+ }
753
+ return (a, b) => (waiters.get(b) ?? 0) - (waiters.get(a) ?? 0)
754
+ || ac.or(ac.get(plan.get(b), 'page_dirs'), []).length - ac.or(ac.get(plan.get(a), 'page_dirs'), []).length
755
+ || cmpStr(a, b);
756
+ }
757
+
758
+ /** Group ids that may start now, in id order (Scheduling rules, precomputed). plan: Map 或对象。 */
759
+ export function ready(st, plan, exploring = false) {
760
+ plan = asMap(plan);
761
+ const gs = st.groups;
762
+ const runningLanes = new Set(Object.entries(gs).filter(([g, s]) => s.state === 'running' && plan.has(g))
763
+ .map(([g]) => ac.get(plan.get(g), 'lane')));
764
+ const out = [];
765
+ const pend = exploring ? capturePending(st.config.hp) : null;
766
+ // a plan behind the captures may still call a captured page source-only
767
+ const stale = exploring && planFreshness(st.config.hp).stale;
768
+ for (const gid of [...plan.keys()].sort(cmpStr)) {
769
+ const s = gs[gid];
770
+ const g = plan.get(gid);
771
+ if (s.state !== 'pending' && s.state !== 'queued') continue;
772
+ // its tier is not final while the explorer may still capture it
773
+ if (_heldForCapture(g, exploring, pend)) continue;
774
+ if (stale && ac.get(g, 'tier') === 'source-only') continue;
775
+ if (!isFile(path.join(st.config.prompts, `${gid}.md`))) continue;
776
+ if (_promptStale(st, gid)) continue;
777
+ if (promptProblem(st, gid)) continue;
778
+ if (_deps(st, plan, gid).some((o) => !_satisfied(st, plan, gid, o, FINISHED))) continue;
779
+ if (ac.get(g, 'after', []).some((a) => !_satisfied(st, plan, gid, a, SUCCEEDED))) continue;
780
+ if (ac.truthy(ac.get(g, 'lane')) && runningLanes.has(g.lane)) continue;
781
+ // one lane per batch too: two ready groups on a lane would write the same files at once
782
+ if (ac.truthy(ac.get(g, 'lane'))) runningLanes.add(g.lane);
783
+ out.push(gid);
784
+ }
785
+ return out;
786
+ }
787
+
788
+ /**
789
+ * Source-only groups held only for capture that may fill slots nothing else can use: every
790
+ * other rule holds, the capture list is known, and the fewest nodes still to capture go first.
791
+ * One that gets captured later is re-queued against the capture (syncPlan), so the cost is a
792
+ * redo at most. Measured (AntennaPod 10-15): 48 held stage-2 groups left every slot idle for
793
+ * 76 min while D answers and D device phases ran.
794
+ */
795
+ export function backfill(st, plan, exploring = false) {
796
+ plan = asMap(plan);
797
+ if (!exploring || !ac.truthy(ac.get(st.config, 'backfill', false))) return [];
798
+ const pend = capturePending(st.config.hp);
799
+ if (pend === null || planFreshness(st.config.hp).stale) return [];
800
+ const held = new Set();
801
+ for (const gid of plan.keys()) {
802
+ const s = st.groups[gid];
803
+ if (s && (s.state === 'pending' || s.state === 'queued') && _heldForCapture(plan.get(gid), exploring, pend)) held.add(gid);
804
+ }
805
+ if (!held.size) return [];
806
+ const open = ready(st, plan, false).filter((g) => held.has(g));
807
+ const left = (g) => groupNodes(plan.get(g)).filter((n) => pend.has(n)).length;
808
+ return open.sort((a, b) => left(a) - left(b) || cmpStr(a, b));
809
+ }
810
+
811
+ /**
812
+ * Groups that may share one agent: same stage, same `after` leaders, same reuse
813
+ * families, no lane (a lane means a shared write -- those stay serial and alone).
814
+ * Python 返回元组;这里返回其 JSON 串,作为分桶键时等价(相等即同桶)。
815
+ */
816
+ export function batchKey(g) {
817
+ const fams = [...new Set(ac.or(ac.get(g, 'reuse_from'), []).map((r) => ac.get(r, 'family'))
818
+ .filter(ac.truthy))].sort(cmpStr);
819
+ if (!fams.length || ac.truthy(ac.get(g, 'lane'))) return null;
820
+ // one shared layout file is incidental (a common list row); a shared base class,
821
+ // pref-dialog family, or 2+ shared layouts means the same screen kind
822
+ const strong = fams.filter((f) => !f.startsWith('layout:'));
823
+ if (!strong.length && fams.length < 2) return null;
824
+ return JSON.stringify([stage(g), [...ac.or(ac.get(g, 'after'), [])].sort(cmpStr), fams]);
825
+ }
826
+
827
+ /** Split ready groups into dispatch units (lists of ids), in id order. */
828
+ export function units(st, plan, readyIds) {
829
+ plan = asMap(plan);
830
+ const c = st.config;
831
+ const gs = st.groups;
832
+ const maxG = Math.max(1, ac.get(c, 'batch_groups', 1));
833
+ const maxP = Math.max(1, ac.get(c, 'batch_pages', 1));
834
+ const out = [];
835
+ const used = new Set();
836
+ const bySession = new Map();
837
+ for (const gid of readyIds) { // a resumed batch stays one unit
838
+ const sess = ac.get(gs[gid], 'next_session');
839
+ if (ac.truthy(sess)) {
840
+ if (!bySession.has(sess)) bySession.set(sess, []);
841
+ bySession.get(sess).push(gid);
842
+ }
843
+ }
844
+ for (const ids of bySession.values()) {
845
+ out.push(ids);
846
+ ids.forEach((i) => used.add(i));
847
+ }
848
+ const buckets = new Map();
849
+ for (const gid of readyIds) {
850
+ if (used.has(gid)) continue;
851
+ const key = ac.truthy(ac.get(gs[gid], 'next_message')) ? null : batchKey(plan.get(gid));
852
+ if (key === null) out.push([gid]);
853
+ else {
854
+ if (!buckets.has(key)) buckets.set(key, []);
855
+ buckets.get(key).push(gid);
856
+ }
857
+ }
858
+ for (const ids of buckets.values()) { // first-fit, ids kept in order within a unit
859
+ const bins = [];
860
+ for (const gid of ids) {
861
+ const n = Math.max(1, ac.or(ac.get(plan.get(gid), 'page_dirs'), []).length);
862
+ const b = bins.find((x) => x[0].length < maxG && x[1] + n <= maxP);
863
+ if (b) {
864
+ b[0].push(gid);
865
+ b[1] += n;
866
+ } else bins.push([[gid], n]);
867
+ }
868
+ out.push(...bins.map((b) => b[0]));
869
+ }
870
+ // 按 priority 排:单元内取最靠前的成员;稳定排序
871
+ const cmp = priority(plan);
872
+ const head = (u) => [...u].sort(cmp)[0];
873
+ return out.map((u, i) => [u, i]).sort((x, y) => cmp(head(x[0]), head(y[0])) || x[1] - y[1]).map((x) => x[0]);
874
+ }
875
+
876
+ /**
877
+ * Why a pending/queued group is not ready, as short reasons (empty = ready). The same
878
+ * conditions as `ready`, spelled out so a stuck queue says what it waits for.
879
+ */
880
+ export function blockers(st, plan, gid, exploring = false) {
881
+ plan = asMap(plan);
882
+ const gs = st.groups;
883
+ const g = plan.get(gid);
884
+ const s = gs[gid];
885
+ if (!g || !s || (s.state !== 'pending' && s.state !== 'queued')) return [];
886
+ const out = [];
887
+ if (_heldForCapture(g, exploring, exploring ? capturePending(st.config.hp) : null)) {
888
+ out.push('source-only: held while the explorer may still capture it');
889
+ }
890
+ if (exploring && ac.get(g, 'tier') === 'source-only' && planFreshness(st.config.hp).stale) {
891
+ out.push('source-only: plan is behind the captures (group_queue.mjs refresh)');
892
+ }
893
+ if (!isFile(path.join(st.config.prompts, `${gid}.md`))) out.push('no prompt file');
894
+ else if (_promptStale(st, gid)) out.push(`prompt older than its tier change (now ${ac.get(s, 'tier')}): rewrite it`);
895
+ else if (promptProblem(st, gid)) out.push(`prompt: ${promptProblem(st, gid)}`);
896
+ const why = (o) => {
897
+ const x = ac.get(ac.get(gs, o, {}), 'state');
898
+ const fams = _providable(st, plan, gid, o).filter((f) => gw.provided(st.config.hp, o, f) === null);
899
+ return `${o} is ${x ?? 'unknown'}${fams.length ? ` (or provides ${fams.join(', ')})` : ''}`;
900
+ };
901
+ for (const o of _deps(st, plan, gid)) {
902
+ if (!_satisfied(st, plan, gid, o, FINISHED)) out.push(`dependency ${why(o)}`);
903
+ }
904
+ for (const a of ac.get(g, 'after', [])) {
905
+ if (!_satisfied(st, plan, gid, a, SUCCEEDED)) out.push(`after ${why(a)}`);
906
+ }
907
+ const lane = ac.get(g, 'lane');
908
+ if (ac.truthy(lane)) {
909
+ for (const [o, so] of Object.entries(gs)) {
910
+ if (o !== gid && so.state === 'running' && ac.get(plan.get(o) ?? {}, 'lane') === lane) out.push(`lane ${lane}: ${o} running`);
911
+ }
912
+ }
913
+ return out;
914
+ }
915
+
916
+ /**
917
+ * A group whose `after` leader failed, was dropped from the plan or does not exist has
918
+ * no shared component to compose: block it (visibly) instead of letting it wait forever.
919
+ */
920
+ export function blockOrphans(st, plan) {
921
+ const changed = [];
922
+ for (const [gid, g] of asMap(plan)) {
923
+ const s = st.groups[gid];
924
+ if (s && (s.state === 'pending' || s.state === 'queued') && orphanedBy(st, plan, gid).length) {
925
+ s.blocked_from = s.state;
926
+ s.state = 'blocked';
927
+ changed.push(gid);
928
+ }
929
+ }
930
+ return changed;
931
+ }
932
+
933
+ /** The `after` leaders that leave `gid` nothing to compose (see blockOrphans). */
934
+ export function orphanedBy(st, plan, gid) {
935
+ plan = asMap(plan);
936
+ return ac.get(plan.get(gid) ?? {}, 'after', []).filter((a) => {
937
+ const x = ac.get(ac.get(st.groups, a, {}), 'state');
938
+ if (!plan.has(a) || x === 'dropped' || x === null) return true;
939
+ // a leader that failed after providing the component still leaves it usable
940
+ return (x === 'failed' || x === 'blocked') && !_satisfied(st, plan, gid, a, SUCCEEDED);
941
+ });
942
+ }
943
+
944
+ /**
945
+ * A blocked group whose leaders are all back (requeued, running or succeeded) returns to the
946
+ * state it was blocked from. Measured gap: a follower blocked while its leader had failed stayed
947
+ * blocked after the parent requeued that leader and it succeeded, and the queue went idle without it.
948
+ */
949
+ export function unblock(st, plan) {
950
+ const changed = [];
951
+ for (const [gid, s] of Object.entries(st.groups)) {
952
+ if (s.state !== 'blocked' || !asMap(plan).has(gid) || orphanedBy(st, plan, gid).length) continue;
953
+ s.state = ac.or(ac.get(s, 'blocked_from'), 'pending');
954
+ delete s.blocked_from;
955
+ changed.push(gid);
956
+ }
957
+ return changed;
958
+ }
959
+
960
+ /** Unblock groups whose leaders are back, then block new orphans; each change is an event. */
961
+ export function _reblock(st, plan) {
962
+ for (let more = true; more;) {
963
+ const back = unblock(st, plan);
964
+ for (const gid of back) _event(st, gid, 'unblocked: its `after` leaders are back');
965
+ more = back.length > 0;
966
+ }
967
+ for (const gid of blockOrphans(st, plan)) _event(st, gid, 'blocked: an `after` leader failed');
968
+ }
969
+
970
+ export function _event(st, gid, text) {
971
+ st.events.push({ seq: st.events.length + 1, at: _now(), group: gid, text });
972
+ }
973
+
974
+ /** Map the ended agent onto the next action, from disk (group_watch.triage). */
975
+ export function classify(hp, gid, outcome, stalled) {
976
+ let text = (stalled ? 'stalled: no output; ' : '') + (outcome || '');
977
+ if (stalled) text += ' timeout';
978
+ return gw.triage(hp, [gid], { [gid]: text }).groups[0];
979
+ }
980
+
981
+ export function _reportPath(hp, gid) {
982
+ return path.join(_meta(hp), 'queue_logs', `${gid}.report.md`);
983
+ }
984
+
985
+ function _mtime(f) {
986
+ try {
987
+ return fs.statSync(f).mtimeMs / 1000;
988
+ } catch {
989
+ return null;
990
+ }
991
+ }
992
+
993
+ /**
994
+ * The time a report must postdate to count for the current attempt. A resume
995
+ * keeps its attempt's `attempt_at`, so a report written before the last
996
+ * release (already settled then) must not read as the resumed session's.
997
+ */
998
+ export function _reportSince(s) {
999
+ return Math.max(s.attempt_at ?? s.started_at ?? 0, ac.get(s, 'released_at') ?? 0);
1000
+ }
1001
+
1002
+ /** This attempt's report: the file exists, was written after the unit started, and carries its heading. */
1003
+ export function _report(hp, gid, since) {
1004
+ const f = _reportPath(hp, gid);
1005
+ const m = _mtime(f);
1006
+ if (m === null || (since && m + 1 < since)) return '';
1007
+ const text = fs.readFileSync(f, 'utf8');
1008
+ return text.includes(`## REPORT ${gid}`) ? text : '';
1009
+ }
1010
+
1011
+ /**
1012
+ * Families each of `ids` leads for groups still to convert: {gid: [family, ...]}.
1013
+ * Only families a follower may start on (see _providable) are listed.
1014
+ */
1015
+ export function _leads(st, plan, ids) {
1016
+ plan = asMap(plan);
1017
+ const out = {};
1018
+ for (const [fid, f] of plan) {
1019
+ const s = st.groups[fid];
1020
+ if (!s || !['pending', 'queued'].includes(s.state)) continue;
1021
+ for (const r of ac.or(ac.get(f, 'reuse_from'), [])) {
1022
+ const from = ac.get(r, 'from');
1023
+ if (!ids.includes(from) || !_providable(st, plan, fid, from).includes(r.family)) continue;
1024
+ out[from] = [...new Set([...(out[from] ?? []), r.family])].sort(cmpStr);
1025
+ }
1026
+ }
1027
+ return out;
1028
+ }
1029
+
1030
+ export const PROVIDE_RULE = 'You lead shared components other groups are waiting for: {leads}. Build each of them '
1031
+ + 'FIRST. The moment one is written and its exported interface (file path, exported names, '
1032
+ + 'parameter and @Param/@Prop types) is final, run `node "{skill}/scripts/group_watch.mjs" provide "{hp}" '
1033
+ + '--group <GID> --family "<family>" --files <its ETS-relative files, comma-separated>` -- its '
1034
+ + 'followers start then. After that, never change that interface; internal fixes are fine.';
1035
+
1036
+ /** The launch (or resume) message for a unit; every one carries the report rule. */
1037
+ export function _message(hp, st, ids, plan = null) {
1038
+ const gs = st.groups;
1039
+ const prompts = st.config.prompts;
1040
+ const first = gs[ids[0]];
1041
+ const skill = path.dirname(path.dirname(ac.resolvePath(THIS_FILE)));
1042
+ let rule = fmt(REPORT_RULE, {
1043
+ reports: ids.map((g) => `${g} -> ${_reportPath(hp, g)}`).join('; '), gids: ids.join(' '),
1044
+ });
1045
+ const leads = Object.entries(_leads(st, plan ?? _plan(hp, [new Map(), false])[0], ids));
1046
+ if (leads.length) {
1047
+ rule += '\n' + fmt(PROVIDE_RULE, {
1048
+ leads: leads.map(([g, fs_]) => `${g}: ${fs_.map((x) => `"${x}"`).join(', ')}`).join('; '), skill, hp: String(hp),
1049
+ });
1050
+ }
1051
+ if (ac.truthy(ac.get(first, 'next_session'))) { // resume: same session, short nudge
1052
+ let msg = ac.or(ac.get(first, 'next_message'), RESUME);
1053
+ if (!msg.includes(KEEP_OUT)) msg += ' ' + KEEP_OUT; // a parent's requeue --message replaces RESUME
1054
+ return msg + (ids.length > 1 ? fmt(RESUME_BATCH, { gids: ids.join(', '), skill, hp: String(hp) }) : '') + '\n' + rule;
1055
+ }
1056
+ const ctx = _contextBlock(hp, st, ids, plan ?? _plan(hp, [new Map(), false])[0]);
1057
+ if (ids.length === 1) {
1058
+ const msg = fmt(LAUNCH, { prompt: path.join(prompts, `${ids[0]}.md`), gid: ids[0] }) + rule;
1059
+ return msg + ctx + (ac.truthy(ac.get(first, 'next_message')) ? '\n\n' + first.next_message : '');
1060
+ }
1061
+ return fmt(LAUNCH_BATCH, {
1062
+ n: ids.length, gids: ids.join(', '), hp: String(hp),
1063
+ skill,
1064
+ prompts: ids.map((g) => `- ${g}: ${path.join(prompts, g + '.md')}`).join('\n'),
1065
+ }) + rule + ctx;
1066
+ }
1067
+
1068
+ /**
1069
+ * What a fresh agent would otherwise open files to learn: the interfaces of the code it builds
1070
+ * on (its reuse leaders' / `after` groups' / shell-contract files, and common/), and where the
1071
+ * full index of everything already written is. Measured (AntennaPod 10-15): conversion agents
1072
+ * read 550 .ets files they had not written, common/AppTheme.ets 41 times.
1073
+ */
1074
+ export function _contextBlock(hp, st, ids, plan) {
1075
+ plan = asMap(plan ?? new Map());
1076
+ const ets = gw._paths(hp)[1];
1077
+ if (!fs.existsSync(ets)) return '';
1078
+ const rels = new Set();
1079
+ for (const gid of ids) {
1080
+ const g = plan.get(gid) ?? {};
1081
+ const on = new Set([...ac.or(ac.get(g, 'after'), []), ...reuseLeaders(g)]);
1082
+ for (const o of on) {
1083
+ for (const f of ac.or(ac.get(st.groups[o] ?? {}, 'written'), [])) rels.add(String(f).replace(/\\/g, '/'));
1084
+ for (const fam of _providable(st, plan, gid, o)) {
1085
+ for (const f of ac.get(gw.provided(hp, o, fam) ?? {}, 'files', [])) rels.add(String(f).replace(/\\/g, '/'));
1086
+ }
1087
+ }
1088
+ }
1089
+ try {
1090
+ for (const e of fs.readdirSync(path.join(ets, 'common'))) if (e.endsWith('.ets')) rels.add(`common/${e}`);
1091
+ } catch { /* no common/ yet */ }
1092
+ let index = null;
1093
+ try {
1094
+ index = harmonyIndex.ensureIndex(hp);
1095
+ } catch { /* an unreadable file: the agent reads files as before */ }
1096
+ const { text, left } = harmonyIndex.entriesFor(ets, [...rels], undefined, (r) => gw.etsFile(hp, ets, r));
1097
+ if (!text && !index) return '';
1098
+ return '\n\n## Code you build on (interfaces, generated from the files — cite them as `<file>:<line>`)\n\n'
1099
+ + 'Call and compose these from what is listed; open one only to read its body.\n'
1100
+ + (text ? `\n${text}\n` : '')
1101
+ + (left.length ? `\nAlso relevant, not listed here for size: ${left.join(', ')}\n` : '')
1102
+ + (index ? `\nEvery other .ets already in the project: \`${index}\` (exports and parameters; read it once instead of opening components one by one).\n` : '');
1103
+ }
1104
+
1105
+ /** The unit key a running group was leased in (`G002+G003`, or its own id). */
1106
+ const _unitKey = (s, gid) => ac.or(ac.get(s, 'unit'), [gid]).join('+');
1107
+
1108
+ /** Running units, keyed `G002+G003`: a batch holds one slot while any member runs. */
1109
+ export function runningUnits(st) {
1110
+ const out = new Map();
1111
+ for (const [g, s] of Object.entries(st.groups)) {
1112
+ if (s.state !== 'running') continue;
1113
+ const ids = ac.or(ac.get(s, 'unit'), [g]);
1114
+ const key = ids.join('+');
1115
+ if (!out.has(key)) out.set(key, ids);
1116
+ }
1117
+ return out;
1118
+ }
1119
+
1120
+ export function summary(st, plan = null, exploring = false) {
1121
+ const counts = {};
1122
+ const gs = Object.entries(st.groups);
1123
+ for (const [, s] of gs) counts[s.state] = (counts[s.state] ?? 0) + 1;
1124
+ const busy = runningUnits(st);
1125
+ const running = {};
1126
+ for (const [key, ids] of busy) running[key] = ac.pyRound((_now() - st.groups[ids[0]].started_at) / 60, 1);
1127
+ const readyUnits = plan && plan.size && !st.stopping ? units(st, plan, ready(st, plan, exploring)).length : 0;
1128
+ const backfillUnits = plan && plan.size && !st.stopping && exploring ? units(st, plan, backfill(st, plan, exploring)).length : 0;
1129
+ const pend = gs.filter(([, s]) => s.state === 'pending' || s.state === 'queued').map(([g]) => g);
1130
+ return {
1131
+ counts, width: st.width, running, free_slots: freeSlots(st), ready_units: readyUnits,
1132
+ backfill_units: backfillUnits, reviews_running: activeReviews(st.config.hp),
1133
+ max_agents: ac.get(st.config, 'max_agents', 0),
1134
+ returned_unverified: gs.filter(([, s]) => s.state === 'returned').map(([g]) => g),
1135
+ failed: gs.filter(([, s]) => s.state === 'failed' || s.state === 'blocked').map(([g]) => g),
1136
+ missing_prompts: pend.filter((g) => !isFile(path.join(st.config.prompts, `${g}.md`))),
1137
+ // tier changed after the prompt was written (e.g. a page got captured): rewrite before lease
1138
+ stale_prompts: pend.filter((g) => _promptStale(st, g)),
1139
+ // written but unusable: a template placeholder left in, or too long to be read whole
1140
+ invalid_prompts: Object.fromEntries(pend.map((g) => [g, promptProblem(st, g)]).filter(([, w]) => w)),
1141
+ plan_stale: planFreshness(st.config.hp).stale,
1142
+ // While the explorer runs, more groups (and every source-only one) are
1143
+ // still to come: an empty ready list is a pause, not the end.
1144
+ idle: busy.size === 0 && (st.stopping || (!exploring && readyUnits === 0)),
1145
+ // Nothing runs and nothing can start, yet groups are still open: each says why.
1146
+ // Non-empty means the parent must act (write a prompt, re-plan), not move on.
1147
+ // A blocked group counts too: it never converts unless the parent requeues its leader.
1148
+ stuck: busy.size === 0 && readyUnits === 0 && !st.stopping && !exploring && plan && plan.size
1149
+ ? Object.fromEntries([
1150
+ ...pend.filter((g) => plan.has(g)).map((g) => [g, blockers(st, plan, g, exploring)]),
1151
+ ...gs.filter(([g, s]) => s.state === 'blocked' && plan.has(g)).map(([g]) => [g, orphanedBy(st, plan, g)
1152
+ .map((a) => `blocked: after ${a} is ${ac.get(st.groups[a] ?? {}, 'state') ?? 'not in the plan'} (requeue it)`)]),
1153
+ ]) : {},
1154
+ exploring, stopping: st.stopping,
1155
+ };
1156
+ }
1157
+
1158
+ /** Load the state and fold the current plan into it; a torn plan read changes nothing. */
1159
+ function _open(hp) {
1160
+ const st = loadState(hp);
1161
+ if (!ac.truthy(st)) throw new ac.SystemExit('no queue: run `group_queue.mjs init` first');
1162
+ const [plan, exploring] = _plan(hp, [new Map(), ac.get(st, 'exploring', false)]);
1163
+ if (plan.size) {
1164
+ syncPlan(hp, st, plan);
1165
+ _reblock(st, plan);
1166
+ }
1167
+ st.exploring = exploring;
1168
+ return [st, plan, exploring];
1169
+ }
1170
+
1171
+ const _statePath = (hp) => path.join(_meta(hp), 'queue_state.json');
1172
+
1173
+ /** Run a read-modify-write of queue_state.json under its lock (see LOCK). */
1174
+ export function _withState(hp, fn) {
1175
+ fs.mkdirSync(_meta(hp), { recursive: true });
1176
+ return gw._locked(_statePath(hp), fn, LOCK);
1177
+ }
1178
+
1179
+ /** Where `lease` stores a unit's full message; the sub-agent prompt only points at it. */
1180
+ export function _messagePath(hp, unit) {
1181
+ return path.join(_meta(hp), 'work', 'dispatch', `${unit}.md`);
1182
+ }
1183
+
1184
+ /** This attempt's report written after `since` (strictly: one read by an earlier release does not count). */
1185
+ function _reportAfter(hp, gid, since) {
1186
+ const m = _mtime(_reportPath(hp, gid));
1187
+ return m !== null && m > since ? _report(hp, gid, since) : '';
1188
+ }
1189
+
1190
+ /**
1191
+ * The units to dispatch now, each marked running. The parent starts one background agent per unit.
1192
+ *
1193
+ * Each unit's full message goes to .hometrans/work/dispatch/<unit>.md (`message_file`); `message`
1194
+ * is the one-line pointer the sub-agent gets, the same for a fresh launch and a resume (measured:
1195
+ * 10 inlined messages truncated in the parent's stdout). `Q message --unit` prints it again.
1196
+ *
1197
+ * A queued resume whose session wrote this attempt's report after its last release is not
1198
+ * dispatched: it is released from that report at once (`released_without_dispatch`). Measured
1199
+ * (AntennaPod 10-17): G002/G016/G020 waited 26 min to resume, then returned 13-29 s later.
1200
+ */
1201
+ export function lease(hp, width = null, { refresh = true } = {}) {
1202
+ // never lease against a plan that trails the captures (see refreshPlan); outside the state
1203
+ // lock (it may run two builders for minutes), under its own
1204
+ const rf = refresh ? refreshPlan(hp) : null;
1205
+ return _withState(hp, () => _lease(hp, width, rf));
1206
+ }
1207
+
1208
+ function _lease(hp, width, rf) {
1209
+ const [st, plan, exploring] = _open(hp);
1210
+ if (width) st.width = Math.max(1, width);
1211
+ const out = [];
1212
+ const settled = [];
1213
+ for (const [gid, s] of Object.entries(st.groups)) {
1214
+ if (s.state !== 'queued' || !ac.truthy(ac.get(s, 'next_session'))) continue;
1215
+ const report = _reportAfter(hp, gid, _reportSince(s));
1216
+ if (!report) continue;
1217
+ settled.push(_settle(hp, st, gid, { report }));
1218
+ _event(st, gid, 'its session had already reported: released without dispatch');
1219
+ }
1220
+ if (settled.length) _reblock(st, plan);
1221
+ if (!st.stopping && plan.size) {
1222
+ let free = freeSlots(st, hp);
1223
+ const main = units(st, plan, ready(st, plan, exploring));
1224
+ const pend = capturePending(hp);
1225
+ const left = (u) => Math.min(...u.map((g) => groupNodes(plan.get(g)).filter((n) => pend?.has(n)).length));
1226
+ // slots no ready group can use go to a source-only group held for capture (see backfill)
1227
+ const extra = free > main.length
1228
+ ? units(st, plan, backfill(st, plan, exploring)).sort((x, y) => left(x) - left(y)) : [];
1229
+ for (const [ids, isBackfill] of [...main.map((u) => [u, false]), ...extra.map((u) => [u, true])]) {
1230
+ if (free <= 0) break;
1231
+ const first = st.groups[ids[0]];
1232
+ const resumeTask = ac.get(first, 'next_session');
1233
+ // A fresh attempt may rebuild the component differently: withdraw what an earlier one provided.
1234
+ // A resume continues the same session, whose interface promise still holds.
1235
+ if (!resumeTask) for (const g of ids) gw.clearProvides(hp, g);
1236
+ const unit = ids.join('+');
1237
+ const file = _messagePath(hp, unit);
1238
+ fs.mkdirSync(path.dirname(file), { recursive: true });
1239
+ ac.writeText(file, _message(hp, st, ids, plan));
1240
+ const t = _now();
1241
+ for (const g of ids) {
1242
+ const s = st.groups[g];
1243
+ if (!resumeTask) {
1244
+ // A fresh session: the old one is retired, so its late notices are stale (release) and
1245
+ // a missed `bind` never resumes it; its stalls are not this session's ("stalled twice").
1246
+ if (ac.truthy(s.session)) (s.prev_sessions ??= []).push(s.session);
1247
+ s.session = null;
1248
+ s.stalls = 0;
1249
+ }
1250
+ s.attempts += 1;
1251
+ Object.assign(s, { state: 'running', started_at: t, unit: ids, leased_tier: ac.get(plan.get(g), 'tier', null) });
1252
+ if (!resumeTask || !s.attempt_at) s.attempt_at = t; // a resume keeps its attempt's start
1253
+ delete s.next_message;
1254
+ delete s.next_session;
1255
+ }
1256
+ gw.dispatch(hp, ids, null, { resume: !!resumeTask });
1257
+ const extra_ = (resumeTask ? ', resume ' + resumeTask : '') + (ids.length > 1 ? `, batch of ${ids.length}` : '')
1258
+ + (isBackfill ? ', backfill: source-only before capture ends' : '');
1259
+ _event(st, unit, `leased (attempt ${first.attempts}${extra_})`);
1260
+ out.push({ unit, groups: ids, resume_task: resumeTask || null,
1261
+ description: `${unit} 转换`, message: fmt(POINTER, { file }), message_file: file,
1262
+ ...(isBackfill ? { backfill: true } : {}) });
1263
+ free -= 1;
1264
+ }
1265
+ }
1266
+ _save(_statePath(hp), st);
1267
+ return { dispatch: out, ...(settled.length ? { released_without_dispatch: settled } : {}),
1268
+ ...(rf ? { plan_refresh: rf } : {}), summary: summary(st, plan, exploring) };
1269
+ }
1270
+
1271
+ /** The stored message of a running unit (`G002+G003`, or one of its group ids). Read-only. */
1272
+ export function message(hp, unit) {
1273
+ const st = loadState(hp);
1274
+ if (!ac.truthy(st)) throw new ac.SystemExit('no queue: run `group_queue.mjs init` first');
1275
+ const run = runningUnits(st);
1276
+ let key = run.has(unit) ? unit : null;
1277
+ if (key === null && ac.get(st.groups[unit] ?? {}, 'state') === 'running') {
1278
+ for (const [k, ids] of run) if (ids.includes(unit)) key = k;
1279
+ }
1280
+ if (key === null) {
1281
+ throw new ac.SystemExit(`${unit} is not a running unit (running: ${[...run.keys()].join(', ') || 'none'})`);
1282
+ }
1283
+ const file = _messagePath(hp, key);
1284
+ if (!isFile(file)) throw new ac.SystemExit(`no stored message for ${key}: ${file} (leased by an older group_queue.mjs?)`);
1285
+ return { unit: key, message_file: file, message: fmt(POINTER, { file }), content: fs.readFileSync(file, 'utf8') };
1286
+ }
1287
+
1288
+ /** Record the host's task / agent id of a unit, so a resume continues that same session. */
1289
+ export function bind(hp, unit, task) {
1290
+ return _withState(hp, () => {
1291
+ const st = loadState(hp);
1292
+ if (!ac.truthy(st)) throw new ac.SystemExit('no queue: run `group_queue.mjs init` first');
1293
+ for (const gid of unit.split('+')) {
1294
+ if (!Object.hasOwn(st.groups, gid)) throw new ac.SystemExit(`unknown group id: ${gid}`);
1295
+ st.groups[gid].session = task;
1296
+ }
1297
+ _save(_statePath(hp), st);
1298
+ return { bound: unit, task };
1299
+ });
1300
+ }
1301
+
1302
+ export const STALL_TWICE_HINT = 'Its session stalled twice. Do not requeue it fresh while that session may still '
1303
+ + 'be alive (opencode/DevEco cannot cancel it: two writers on one file). Resume it (`requeue` keeps its '
1304
+ + 'session by default) or wait for its completion notice, then decide.';
1305
+
1306
+ /**
1307
+ * Decide what happens to running group `gid` from disk (its report, its files): the body of
1308
+ * `release`, also used by `lease` for a queued resume whose session has already reported.
1309
+ * Returns release's row.
1310
+ */
1311
+ function _settle(hp, st, gid, { stalled = false, error = '', report = null } = {}) {
1312
+ const s = st.groups[gid];
1313
+ report = report ?? _report(hp, gid, _reportSince(s));
1314
+ // A group that wrote its report finished before any later error or stall of its agent.
1315
+ const outcome = report ? ac.cpSlice(report.slice(report.indexOf(`## REPORT ${gid}`)), 0, 300)
1316
+ : [error, ''].filter(Boolean).join(' | ');
1317
+ const isStall = stalled && !report;
1318
+ const row = classify(hp, gid, outcome, isStall);
1319
+ s.history.push({
1320
+ attempt: s.attempts, stalled: isStall, action: row.action, outcome: ac.cpSlice(outcome, -400),
1321
+ written: row.written, missing: row.missing, unit: ac.or(ac.get(s, 'unit'), [gid]),
1322
+ });
1323
+ s.written = row.written;
1324
+ s.missing = row.missing;
1325
+ s.last_text = ac.cpSlice(report || '', -500);
1326
+ s.released_at = _now();
1327
+ delete s.next_session; // set again below only when this release resumes it
1328
+ if (isStall) s.stalls = (ac.get(s, 'stalls') ?? 0) + 1;
1329
+ let next = null; // [message, resume session]
1330
+ if (isStall && s.stalls >= 2) {
1331
+ next = null; // resuming the same session stalled again: a human looks at it (row.needs)
1332
+ } else if ((row.action === 'retry' || row.action === 'resume') && s.attempts < MAX_ATTEMPTS) {
1333
+ // A stalled agent may still be alive (opencode/DevEco cannot cancel it): resuming its
1334
+ // own session queues behind it instead of starting a second writer.
1335
+ next = [RESUME, ac.or(ac.get(s, 'session'), null)];
1336
+ } else if (row.action === 'redispatch' && !ac.truthy(ac.get(s, 'narrowed'))) {
1337
+ s.narrowed = true;
1338
+ next = [ac.truthy(ac.get(row, 'verify_only')) ? NARROW_VERIFY : NARROW, null];
1339
+ }
1340
+ const out = { group: gid, action: row.action, state: row.state, written: row.written, missing: row.missing };
1341
+ if (next) {
1342
+ s.state = 'queued';
1343
+ s.next_message = next[0];
1344
+ if (ac.truthy(next[1])) s.next_session = next[1];
1345
+ // A stall with no bound session: the old agent must be stopped before a fresh one starts.
1346
+ if (isStall && !ac.truthy(next[1])) out.stop_first = true;
1347
+ _event(st, gid, `${row.action} -> requeued`);
1348
+ } else if (row.action === 'verify' || row.action === 'verify-then-resume') {
1349
+ s.state = 'returned';
1350
+ _event(st, gid, `returned (${row.state}; missing=${ac.pyRepr(row.missing)})`);
1351
+ } else {
1352
+ s.state = 'failed';
1353
+ const twice = isStall && s.stalls >= 2;
1354
+ if (twice) Object.assign(out, { needs: 'human', session: ac.get(s, 'session') ?? null, hint: STALL_TWICE_HINT });
1355
+ _event(st, gid, `failed after ${s.attempts} attempt(s): ${twice ? 'stalled twice' : row.action}`);
1356
+ }
1357
+ // Members got captured while it ran: what it returned was built on the old evidence.
1358
+ if (s.state === 'returned' && ac.truthy(ac.get(s, 'recaptured_while_running'))) {
1359
+ delete s.recaptured_while_running;
1360
+ Object.assign(s, { state: 'queued', next_message: RECAPTURED, attempts: 0, narrowed: false });
1361
+ s.tier_changed_at = _now();
1362
+ out.recaptured = true;
1363
+ _event(st, gid, 'released after members were captured while it ran: re-queued for the captures');
1364
+ }
1365
+ out.next = s.state;
1366
+ // Followers already built on what it provided: the parent re-checks them against the new version.
1367
+ const changed = gw.providedChanged(hp, gid);
1368
+ if (changed.length) out.provided_changed = changed;
1369
+ return out;
1370
+ }
1371
+
1372
+ /**
1373
+ * Triage the running members of `unit` (a unit key `G002+G003` or one group id) from
1374
+ * disk and decide what happens next. Call it when the agent ended (its notification),
1375
+ * when `reap` lists a group as reported (its own report is written, the batch goes
1376
+ * on), or with stalled=true for a silent one.
1377
+ *
1378
+ * task: the session the notice came from. A group bound to another session is left as it is
1379
+ * (`stale-notice`): measured (G027), an old session's completion notice released the group
1380
+ * while its newer session was still running.
1381
+ */
1382
+ export function release(hp, unit, { stalled = false, error = '', task = null } = {}) {
1383
+ return _withState(hp, () => {
1384
+ const [st, plan, exploring] = _open(hp);
1385
+ const rows = [];
1386
+ for (const gid of unit.split('+')) {
1387
+ const s = st.groups[gid];
1388
+ if (!s) throw new ac.SystemExit(`unknown group id: ${gid}`);
1389
+ if (s.state !== 'running') {
1390
+ rows.push({ group: gid, action: 'none', state: s.state }); // already released (e.g. reported early)
1391
+ continue;
1392
+ }
1393
+ // bound to another session, or the notice is from a session a fresh dispatch retired
1394
+ if (ac.truthy(task) && ((ac.truthy(s.session) && s.session !== task)
1395
+ || ac.or(ac.get(s, 'prev_sessions'), []).includes(task))) {
1396
+ rows.push({ group: gid, action: 'stale-notice', bound: s.session ?? null, task, state: s.state, next: s.state });
1397
+ continue;
1398
+ }
1399
+ // a batch key names the unit it was leased in: a member released early and re-leased in
1400
+ // another unit is that unit's fresh attempt, not this one's (a lone group id still releases it)
1401
+ if (unit.includes('+') && _unitKey(s, gid) !== unit) {
1402
+ rows.push({ group: gid, action: 'other-unit', unit: _unitKey(s, gid), state: s.state, next: s.state });
1403
+ continue;
1404
+ }
1405
+ rows.push(_settle(hp, st, gid, { stalled, error }));
1406
+ }
1407
+ _reblock(st, plan);
1408
+ _save(_statePath(hp), st);
1409
+ return { released: rows, summary: summary(st, plan, exploring) };
1410
+ });
1411
+ }
1412
+
1413
+ /**
1414
+ * Running groups whose report file exists (release them now, even mid-batch) and
1415
+ * running units with no sign of life for the stall limit (stop / resume them). The limit is
1416
+ * stallLimit: --stall-min (never below FIRST_WRITE_MIN) * max(1, inflight / 8). Read-only.
1417
+ */
1418
+ export function reap(hp, stallMin = null) {
1419
+ const st = loadState(hp);
1420
+ if (!ac.truthy(st)) throw new ac.SystemExit('no queue: run `group_queue.mjs init` first');
1421
+ const lim = stallLimit(st, hp, stallMin);
1422
+ const limit = lim.min * 60;
1423
+ const reported = [];
1424
+ const stalled = [];
1425
+ const t = _now();
1426
+ for (const [key, ids] of runningUnits(st)) {
1427
+ // only the members still running in THIS unit: one released early and re-leased elsewhere
1428
+ // is a fresh attempt of another unit, judged there
1429
+ const live = ids.filter((g) => st.groups[g].state === 'running' && _unitKey(st.groups[g], g) === key);
1430
+ if (!live.length) continue;
1431
+ for (const g of live) if (_report(hp, g, _reportSince(st.groups[g]))) reported.push(g);
1432
+ const acts = live.map((g) => gw.lastActivity(hp, g, [_reportPath(hp, g)]) ?? st.groups[g].started_at);
1433
+ const idle = t - Math.max(st.groups[live[0]].started_at, ...acts);
1434
+ if (idle >= limit && !live.every((g) => reported.includes(g))) {
1435
+ stalled.push({ unit: key, idle_min: ac.pyRound(idle / 60, 1), task: ac.get(st.groups[live[0]], 'session') });
1436
+ }
1437
+ }
1438
+ return { reported, stalled, stall_limit_min: lim.min, inflight: lim.inflight };
1439
+ }
1440
+
1441
+ /**
1442
+ * What an ended job printed last: its trailing JSON object (run_cycle's result), reduced to
1443
+ * what the parent acts on. Exit 0 does not mean the stage advanced: run_cycle exits 0 with a
1444
+ * failed merge recorded only in `waiting[].error` (measured: a merge refusal read as success).
1445
+ */
1446
+ export function _jobResult(log) {
1447
+ let text;
1448
+ try {
1449
+ text = fs.readFileSync(log, 'utf8');
1450
+ } catch {
1451
+ return {};
1452
+ }
1453
+ for (let i = text.lastIndexOf('{'); i >= 0; i = text.lastIndexOf('{', i - 1)) {
1454
+ if (i > 0 && text[i - 1] !== '\n' && text[i - 1] !== '\r') continue; // only a top-level object
1455
+ let doc;
1456
+ try {
1457
+ doc = JSON.parse(text.slice(i));
1458
+ } catch {
1459
+ continue;
1460
+ }
1461
+ if (!ac.isDict(doc)) return {};
1462
+ const errors = ac.or(ac.get(doc, 'waiting'), []).filter((w) => ac.isDict(w) && ac.truthy(w.error))
1463
+ .map((w) => ({ worklist: w.worklist, error: w.error }));
1464
+ const out = {};
1465
+ for (const k of ['finished', 'blocked_on', 'failed_phases']) if (k in doc) out[k] = doc[k];
1466
+ if (errors.length) out.errors = errors;
1467
+ return { result: out };
1468
+ }
1469
+ return {};
1470
+ }
1471
+
1472
+ /**
1473
+ * Answers files `wait` follows: the explicit --answers ones, plus every bound reviewer still at
1474
+ * work (not done, not consumed), so the parent need not pass one --answers per part. `since` is
1475
+ * the bind time, the silence clock of a reviewer that has not written its file yet.
1476
+ */
1477
+ export function watchedAnswers(hp, explicit = []) {
1478
+ const out = new Map();
1479
+ for (const a of explicit) out.set(ac.resolvePath(a), { answers: ac.resolvePath(a), since: null, explicit: true });
1480
+ const recs = _reviewers(hp) ?? {};
1481
+ for (const r of Object.values(recs)) {
1482
+ if (!ac.isDict(r) || (r.kind ?? 'reviewer') !== 'reviewer' || ac.truthy(r.done) || !ac.truthy(r.answers)) continue;
1483
+ if (_reviewConsumed(r.answers)) continue;
1484
+ const k = ac.resolvePath(r.answers);
1485
+ const prev = out.get(k);
1486
+ out.set(k, { answers: k, since: ac.get(r, 'bound_at', null), explicit: prev?.explicit ?? false });
1487
+ }
1488
+ return [...out.values()];
1489
+ }
1490
+
1491
+ /** `<jobs>/<name>.seen`: the ended_at of the exit a wait already reported (not .json: detach lists those as jobs). */
1492
+ const _seenFile = (hp, j) => path.join(detach._dir(hp), `${j}.seen`);
1493
+
1494
+ /** One exit of one run: a restart gets a new started_at (a lost run has no ended_at). */
1495
+ function _jobExitKey(hp, j) {
1496
+ try {
1497
+ const job = JSON.parse(fs.readFileSync(path.join(detach._dir(hp), `${j}.json`), 'utf8'));
1498
+ return `${job.started_at}:${job.ended_at ?? 'lost'}`;
1499
+ } catch {
1500
+ return null;
1501
+ }
1502
+ }
1503
+
1504
+ function _jobExitSeen(hp, j) {
1505
+ try {
1506
+ return fs.readFileSync(_seenFile(hp, j), 'utf8') === _jobExitKey(hp, j);
1507
+ } catch {
1508
+ return false;
1509
+ }
1510
+ }
1511
+
1512
+ function _markJobExitSeen(hp, j) {
1513
+ const k = _jobExitKey(hp, j);
1514
+ try {
1515
+ if (k !== null) fs.writeFileSync(_seenFile(hp, j), k);
1516
+ } catch { /* advisory: at worst the exit is reported again */ }
1517
+ }
1518
+
1519
+ /**
1520
+ * Block until a slot can be refilled or something needs the parent: a running group's
1521
+ * report appeared, a unit went silent, a background job (detach.mjs) left `running`,
1522
+ * a reviewer's answers file is complete or silent, or there is a free slot with a
1523
+ * ready unit. Returns at once when that is already true.
1524
+ */
1525
+ export async function wait(hp, { timeoutS = 540, pollS = 5, jobs = [], answers = [] } = {}) {
1526
+ const end = _now() + timeoutS;
1527
+ const answersCheck = await import('./answers_check.mjs');
1528
+ // bound reviewers whose answers are open now: one that completes during this wait is news
1529
+ const initiallyOpen = new Set(watchedAnswers(hp, [])
1530
+ .filter((w) => !answersCheck.answersDone(w.answers).complete).map((w) => w.answers));
1531
+ let lastRefresh = null;
1532
+ for (;;) {
1533
+ const reasons = [];
1534
+ // captures moved on: rebuild the plan now, not at the parent's next lease
1535
+ if (ac.truthy(loadState(hp)) && planFreshness(hp).stale) {
1536
+ const rf = refreshPlan(hp);
1537
+ // only a refresh run now is news; a remembered failure would turn wait into a busy loop
1538
+ if (rf.attempted) {
1539
+ lastRefresh = rf;
1540
+ reasons.push(rf.refreshed ? 'plan-refreshed' : 'plan-refresh-failed');
1541
+ }
1542
+ }
1543
+ const st = loadState(hp);
1544
+ const [plan, exploring] = _plan(hp, [new Map(), ac.get(st ?? {}, 'exploring', false)]);
1545
+ let r = { reported: [], stalled: [], stall_limit_min: STALL_MIN };
1546
+ if (ac.truthy(st)) {
1547
+ r = reap(hp);
1548
+ if (r.reported.length) reasons.push('reported');
1549
+ if (r.stalled.length) reasons.push('stalled');
1550
+ }
1551
+ const js = jobs.length ? detach.status(hp) : {};
1552
+ // a name with no job file (typo, not started yet) is no exit: it must not end the wait at once.
1553
+ // An exit is reported once: measured (Salt Player 10-18), `--job run_cycle` after an exit the
1554
+ // parent had already handled returned at once on every call until the parent dropped --job.
1555
+ const jobsDone = jobs.filter((j) => !['running', 'unknown'].includes(ac.get(ac.get(js, j, {}), 'state', 'unknown'))
1556
+ && !_jobExitSeen(hp, j));
1557
+ if (jobsDone.length) reasons.push('job');
1558
+ const watched = watchedAnswers(hp, answers);
1559
+ const ans = watched.map((w) => ({ ...answersCheck.answersDone(w.answers), since: w.since, explicit: w.explicit }));
1560
+ const limit = r.stall_limit_min * 60; // a reviewer is silent by the same load-scaled limit
1561
+ // explicit files report completion as before; a bound reviewer only when it completed during this wait
1562
+ const ansDone = ans.filter((a) => a.complete && (a.explicit || initiallyOpen.has(a.answers))).map((a) => a.answers);
1563
+ // no file yet: silent counted from its bind (measured: a reviewer that never wrote was never reported)
1564
+ const ansSilent = ans.filter((a) => {
1565
+ const last = Math.max(a.mtime ?? 0, a.since ?? 0);
1566
+ return !a.complete && last > 0 && _now() - last >= limit;
1567
+ }).map((a) => a.answers);
1568
+ if (ansDone.length) reasons.push('answers');
1569
+ if (ansSilent.length) reasons.push('answers-silent');
1570
+ const sum = ac.truthy(st) ? summary(st, plan, exploring) : null;
1571
+ if (sum && sum.free_slots > 0 && (sum.ready_units > 0 || sum.backfill_units > 0)) reasons.push('slots');
1572
+ if (sum && sum.idle) reasons.push('idle');
1573
+ if (reasons.length || _now() >= end) {
1574
+ for (const j of jobsDone) _markJobExitSeen(hp, j);
1575
+ return { reasons: reasons.length ? reasons : ['timeout'], reported: r.reported, stalled: r.stalled,
1576
+ stall_limit_min: r.stall_limit_min,
1577
+ jobs: Object.fromEntries(jobs.map((j) => {
1578
+ const row = ac.get(js, j, { state: 'unknown' });
1579
+ return [j, jobsDone.includes(j) ? { ...row, ..._jobResult(row.log) } : row];
1580
+ })),
1581
+ answers_complete: ansDone, answers_silent: ansSilent,
1582
+ ...(lastRefresh ? { plan_refresh: lastRefresh } : {}), summary: sum };
1583
+ }
1584
+ await ac.sleep(pollS);
1585
+ }
1586
+ }
1587
+
1588
+ export function status(hp) {
1589
+ const st = loadState(hp);
1590
+ if (!ac.truthy(st)) return { error: 'no queue' };
1591
+ const [plan, exploring] = _plan(hp, [new Map(), ac.get(st, 'exploring', false)]);
1592
+ return summary(st, plan, exploring);
1593
+ }
1594
+
1595
+ /** Its bound session stalled on its last release, or it failed after stalls: that session may still run. */
1596
+ function _stalledSession(s) {
1597
+ if (!ac.truthy(ac.get(s, 'session'))) return false;
1598
+ const last = ac.or(ac.get(s, 'history'), []).at(-1);
1599
+ return ac.truthy(ac.get(last ?? {}, 'stalled')) || (s.state === 'failed' && (ac.get(s, 'stalls') ?? 0) > 0);
1600
+ }
1601
+
1602
+ /**
1603
+ * Parent decisions: verified / requeue / stop.
1604
+ *
1605
+ * requeue: a group whose bound session stalled (see _stalledSession) resumes THAT session by
1606
+ * default -- it may still be alive (measured, AntennaPod 10-17: a fresh requeue left two sessions
1607
+ * writing the same files). `fresh` starts a new session anyway; the reply then carries
1608
+ * `stop_first: true` and a `warning`: the old session must have ended before the dispatch.
1609
+ * `resume` (kept for compatibility) resumes any bound session.
1610
+ */
1611
+ export function control(hp, cmd) {
1612
+ return _withState(hp, () => {
1613
+ const st = loadState(hp);
1614
+ if (!ac.truthy(st)) throw new ac.SystemExit('no queue: run `group_queue.mjs init` first');
1615
+ const gid = ac.get(cmd, 'group');
1616
+ const s = typeof gid === 'string' && Object.hasOwn(st.groups, gid) ? st.groups[gid] : null;
1617
+ const out = { done: cmd };
1618
+ if (cmd.op === 'stop') {
1619
+ st.stopping = true;
1620
+ _event(st, null, 'stop requested: no new leases');
1621
+ } else if (!s) {
1622
+ throw new ac.SystemExit(`unknown group id: ${gid}`);
1623
+ } else if (cmd.op === 'verified') {
1624
+ s.state = 'verified';
1625
+ } else if (cmd.op === 'requeue') {
1626
+ if (s.state === 'running') throw new ac.SystemExit(`${gid} is running: release it first`);
1627
+ const fresh = ac.truthy(ac.get(cmd, 'fresh'));
1628
+ const alive = _stalledSession(s);
1629
+ Object.assign(s, { state: 'queued', next_message: ac.get(cmd, 'message') });
1630
+ if (!fresh && ac.truthy(s.session) && (ac.truthy(ac.get(cmd, 'resume')) || alive)) {
1631
+ s.next_session = s.session;
1632
+ out.resume_task = s.session;
1633
+ } else {
1634
+ delete s.next_session;
1635
+ if (fresh && alive) {
1636
+ Object.assign(out, { stop_first: true, warning: `${gid}'s session ${s.session} stalled and may still be `
1637
+ + 'running: dispatch the fresh attempt only after that session has ended (its completion notice '
1638
+ + 'received; Claude Code: TaskStop it), or two agents write the same files.' });
1639
+ }
1640
+ }
1641
+ _event(st, gid, `requeued by parent${s.next_session ? ` (resume ${s.next_session})` : fresh ? ' (fresh)' : ''}`);
1642
+ }
1643
+ _save(_statePath(hp), st);
1644
+ return { ...out, state: s ? s.state : null };
1645
+ });
1646
+ }
1647
+
1648
+ /**
1649
+ * Create the queue state. Results of an earlier state are kept: returned / verified /
1650
+ * skipped stay, and a group left `running` by a parent session that ended is queued
1651
+ * to resume its own session (the host may or may not still know that task id).
1652
+ */
1653
+ export function init(hp, a) {
1654
+ return _withState(hp, () => _init(hp, a));
1655
+ }
1656
+
1657
+ /**
1658
+ * Signs, on disk, that another parent session is still driving this campaign: a running
1659
+ * group with recent activity, a background job (detach.mjs) still alive, a reviewer bound
1660
+ * recently whose answers are not complete. (Not a recent queue_state write: the same parent
1661
+ * legitimately re-inits after a re-plan.)
1662
+ * `init` turns every running group into "queued to resume", so a second parent re-initing a
1663
+ * live campaign dispatches each running group a second time (two writers on the same files).
1664
+ * Measured: a new session resumed a campaign whose first parent was still dispatching, and
1665
+ * rewrote its plan, prompts, progress and queue before it noticed.
1666
+ */
1667
+ export function liveCampaign(hp, old, windowMin = STALL_MIN) {
1668
+ const t = _now();
1669
+ const win = windowMin * 60;
1670
+ const why = [];
1671
+ for (const [gid, s] of Object.entries(ac.get(old ?? {}, 'groups', {}))) {
1672
+ if (s.state !== 'running') continue;
1673
+ const at = gw.lastActivity(hp, gid, [_reportPath(hp, gid)]) ?? s.started_at;
1674
+ if (at && t - at < win) why.push(`${gid} running, last activity ${ac.pyRound((t - at) / 60, 1)} min ago`);
1675
+ }
1676
+ for (const [name, j] of Object.entries(detach.status(hp))) {
1677
+ // a --service job (the fixture server) outlives every session by design: not a second parent
1678
+ if (j.state === 'running' && !j.service) why.push(`background job ${name} still running`);
1679
+ }
1680
+ const recs = _reviewers(hp) ?? {};
1681
+ for (const [name, r] of Object.entries(recs)) {
1682
+ if (!ac.isDict(r) || ac.truthy(r.done) || !ac.truthy(r.answers) || !r.bound_at || t - r.bound_at >= win) continue;
1683
+ if (!_reviewConsumed(r.answers) && !answersCheck.answersDone(r.answers).complete) {
1684
+ why.push(`reviewer ${name} bound ${ac.pyRound((t - r.bound_at) / 60, 1)} min ago, answers incomplete`);
1685
+ }
1686
+ }
1687
+ return why;
1688
+ }
1689
+
1690
+ function _init(hp, a) {
1691
+ const old = loadState(hp);
1692
+ if (ac.truthy(old) && !a.takeover) {
1693
+ const live = liveCampaign(hp, old);
1694
+ if (live.length) {
1695
+ throw new ac.SystemExit('another parent session may still be driving this campaign:\n - '
1696
+ + live.join('\n - ') + '\nDo not dispatch from this session. Ask the user: wait for that session '
1697
+ + '(monitor only), or stop it and re-run init with --takeover.');
1698
+ }
1699
+ }
1700
+ const st = initState(hp, a.prompts, {
1701
+ width: a.width, stall_min: a.stall_min, batch_groups: a.batch_groups, batch_pages: a.batch_pages,
1702
+ overlap_entry: !a.no_overlap_entry, stage_barrier: a.stage_barrier, provides: !a.no_provides,
1703
+ max_agents: a.max_agents ?? 10, backfill: !a.no_backfill,
1704
+ });
1705
+ const ets = gw._paths(hp)[1];
1706
+ if (!isFile(path.join(_meta(hp), 'batch_progress.json')) || !fs.existsSync(ets)) {
1707
+ // release triages a group from the files under this root: a wrong one judges every group empty
1708
+ throw new ac.SystemExit(`ETS root not found: ${ets} -- write batch_progress.json (with ui_module) first`);
1709
+ }
1710
+ if (ac.truthy(old)) {
1711
+ for (const [gid, s] of Object.entries(ac.get(old, 'groups', {}))) {
1712
+ if (!Object.hasOwn(st.groups, gid)) continue;
1713
+ if (['returned', 'verified', 'skipped'].includes(s.state)) st.groups[gid] = s;
1714
+ else if (s.state === 'running') {
1715
+ st.groups[gid] = { ...s, state: 'queued', next_message: RESUME };
1716
+ if (ac.truthy(s.session)) st.groups[gid].next_session = s.session;
1717
+ _event(st, gid, 'was running when the previous session ended: queued to resume');
1718
+ } else if (s.state === 'queued') {
1719
+ // its pending decision (resume THAT session, narrowed, recaptured) stands: a re-init to
1720
+ // change --width must not turn a resume of a possibly live session into a second writer
1721
+ st.groups[gid] = s;
1722
+ } else {
1723
+ // pending / failed / blocked / dropped start over, keeping who wrote it: a retired
1724
+ // session's late notice stays stale, and a session that stalled is resumed, not doubled
1725
+ const row = st.groups[gid];
1726
+ for (const k of ['session', 'prev_sessions', 'stalls', 'history']) if (s[k] !== undefined) row[k] = s[k];
1727
+ if (row.state !== 'skipped' && _stalledSession(s)) Object.assign(row, { state: 'queued', next_session: s.session, next_message: RESUME });
1728
+ }
1729
+ }
1730
+ }
1731
+ _save(_statePath(hp), st);
1732
+ return { initialized: true, groups: Object.keys(st.groups).length, width: st.width, summary: status(hp) };
1733
+ }
1734
+
1735
+ const DOC = `Scheduling state machine for Step 5 group conversion. The parent dispatches
1736
+ every unit as a background sub-agent of its own host; this script decides what to
1737
+ dispatch and what to do when one ends. It starts no process.
1738
+
1739
+ Why not waves of \`task\` calls: a wave blocks the parent until its slowest agent
1740
+ returns, so every finished slot idles (measured: G014 done at 112 min, wave held
1741
+ to 166 min by G006). Width defaults to 6: on the AntennaPod 10-14 gateway the
1742
+ per-agent rate held ~50 tok/s up to 5 agents (~40 at 7-8). A gateway that caps
1743
+ total throughput instead (~1.3 turns/min measured earlier) wants a lower --width.
1744
+
1745
+ * ready = real dependencies finished, every \`after\` group finished, no running
1746
+ group on the same non-null \`lane\`, and <prompts>/<GID>.md exists (see SKILL.md 5.3)
1747
+ * the plan is re-read on every call; while plan.exploring is true a source-only
1748
+ group is held while one of its nodes is in <campaign>/capture_pending.json
1749
+ (no file: all held), and the queue is never idle
1750
+ * among ready units, the ones others wait on and the larger ones go first
1751
+ * family batching: same stage, \`after\` set and reuse families (no lane) -> ONE
1752
+ agent, up to --batch-groups / --batch-pages; each group is released on its own
1753
+ report file, so its dependants start before the batch ends
1754
+ * network failure or stall -> resume the SAME session (bind its task id);
1755
+ empty report -> one fresh, narrowed redispatch; complete/partial -> returned
1756
+
1757
+ group_queue.mjs init <harmony_dir> --prompts <dir> [--width 6] [--stall-min 20]
1758
+ group_queue.mjs lease <harmony_dir> [--width N]
1759
+ group_queue.mjs message <harmony_dir> --unit G002+G003 # a running unit's stored message
1760
+ group_queue.mjs bind <harmony_dir> --unit G002+G003 --task <task id>
1761
+ group_queue.mjs release <harmony_dir> --unit G002+G003 [--task <id>] [--stalled] [--error "..."]
1762
+ group_queue.mjs reap <harmony_dir>
1763
+ group_queue.mjs review-bind <harmony_dir> --name <part> --answers <path> [--task <id>] [--kind reviewer]
1764
+ group_queue.mjs review-unbind <harmony_dir> --name <part> # the reviewer ended without its answers
1765
+ group_queue.mjs wait <harmony_dir> [--timeout-s 540] [--job run_cycle] [--answers <file>]
1766
+ group_queue.mjs status <harmony_dir>
1767
+ group_queue.mjs refresh <harmony_dir> [--force]
1768
+ group_queue.mjs verified <harmony_dir> --group G007
1769
+ group_queue.mjs requeue <harmony_dir> --group G007 [--message "..."] [--resume | --fresh]
1770
+ group_queue.mjs stop <harmony_dir>
1771
+
1772
+ lease writes each unit's full message to .hometrans/work/dispatch/<unit>.md and returns
1773
+ \`message\` = "Read the file <message_file> and follow it fully." -- the sub-agent prompt.
1774
+ A stall is --stall-min (default 20, never below group_watch's first-write limit) times
1775
+ max(1, inflight / 8), inflight = running units + reviewers at work (\`stall_limit_min\`).
1776
+ Reviewers at work = .hometrans/work/reviewers.json entries (review-bind) whose answers are
1777
+ not complete; without that file, capture_pending.json \`reviews\`.
1778
+ requeue of a group whose bound session stalled resumes that session unless --fresh.
1779
+ Every mutating call holds .hometrans/queue_state.json.lock.
1780
+
1781
+ State: .hometrans/queue_state.json. Reports: .hometrans/queue_logs/<GID>.report.md.
1782
+ `;
1783
+
1784
+ export async function main(argv = process.argv.slice(2)) {
1785
+ const { args: a, error } = ac.parseCli({
1786
+ prog: 'group_queue.mjs', description: DOC,
1787
+ positionals: [{ name: 'mode', choices: ['init', 'lease', 'message', 'bind', 'release', 'reap', 'wait', 'status',
1788
+ 'verified', 'requeue', 'stop', 'refresh', 'review-bind', 'review-unbind'] }, { name: 'harmony_dir' }],
1789
+ options: [
1790
+ { flags: ['--prompts'], help: 'dir with one <GID>.md prompt per group (init)' },
1791
+ { flags: ['--width'], type: 'int', default: null, help: 'concurrent conversion units (init default: --max-agents, else 6)' },
1792
+ { flags: ['--no-refresh'], action: 'store_true', help: 'lease: do not rebuild a plan that trails the captures first' },
1793
+ { flags: ['--force'], action: 'store_true', help: 'refresh: rebuild even when the plan looks current' },
1794
+ { flags: ['--stall-min'], type: 'float', default: STALL_MIN,
1795
+ help: 'init: no heartbeat/write this long = stalled (never below the first-write limit; scaled by inflight / 8)' },
1796
+ { flags: ['--batch-groups'], type: 'int', default: 3, help: 'max sibling groups per agent (1 = no family batching)' },
1797
+ { flags: ['--batch-pages'], type: 'int', default: 8, help: 'max pages per batched agent' },
1798
+ { flags: ['--no-overlap-entry'], action: 'store_true',
1799
+ help: 'stage 1 waits for the whole entry group even when shell_contract.json exists' },
1800
+ { flags: ['--stage-barrier'], action: 'store_true',
1801
+ help: 'a group waits for every lower-stage group, not only its real dependencies' },
1802
+ { flags: ['--no-provides'], action: 'store_true',
1803
+ help: "a follower waits for its family leader's whole group, not only its provided component" },
1804
+ { flags: ['--max-agents'], type: 'int', default: null,
1805
+ help: 'init: agents in flight incl. explorer reviewers (default 10; 0 = width only)' },
1806
+ { flags: ['--takeover'], action: 'store_true',
1807
+ help: 'init: re-init although another parent session looks live (only after it was stopped)' },
1808
+ { flags: ['--no-backfill'], action: 'store_true',
1809
+ help: 'init: never lease a source-only group before the explorer is done with its nodes' },
1810
+ { flags: ['--unit'], help: 'unit key G002+G003, or one group id (bind / release / message)' },
1811
+ { flags: ['--task'], help: "the host's task / agent id: bind, review-bind; release: the session the notice came from" },
1812
+ { flags: ['--name'], help: 'review-bind: the reviewer part, e.g. nl_hints_part3' },
1813
+ { flags: ['--kind'], default: 'reviewer', help: 'review-bind: reviewer (counts against --max-agents) or skill-agent' },
1814
+ { flags: ['--stalled'], action: 'store_true', help: 'release: the unit was reaped as silent' },
1815
+ { flags: ['--error'], default: '', help: "release: the agent's error text, if it failed" },
1816
+ { flags: ['--timeout-s'], type: 'float', default: 540 },
1817
+ { flags: ['--job'], action: 'append', default: [], help: 'wait: also return when this detach.mjs job ends' },
1818
+ { flags: ['--answers'], action: 'append', default: [],
1819
+ help: 'wait: also return when this answers file is complete; review-bind: the answers path of the part' },
1820
+ { flags: ['--group'] },
1821
+ { flags: ['--message'], help: 'extra instruction for a requeued group' },
1822
+ { flags: ['--resume'], action: 'store_true', help: 'requeue into the same session (default when it stalled)' },
1823
+ { flags: ['--fresh'], action: 'store_true',
1824
+ help: 'requeue as a new session even though its bound session stalled (stop/await that session first)' },
1825
+ ],
1826
+ }, argv);
1827
+ const hp = a.harmony_dir;
1828
+ let out;
1829
+ if (a.mode === 'init') {
1830
+ if (!a.prompts) error('init requires --prompts');
1831
+ out = init(hp, { ...a, width: a.width ?? null });
1832
+ } else if (a.mode === 'lease') {
1833
+ out = lease(hp, a.width, { refresh: !a.no_refresh });
1834
+ } else if (a.mode === 'refresh') {
1835
+ out = refreshPlan(hp, { force: a.force });
1836
+ } else if (a.mode === 'message') {
1837
+ if (!a.unit) error('message requires --unit');
1838
+ out = message(hp, a.unit);
1839
+ } else if (a.mode === 'review-unbind') {
1840
+ if (!a.name) error('review-unbind requires --name');
1841
+ out = reviewUnbind(hp, a.name);
1842
+ } else if (a.mode === 'review-bind') {
1843
+ if (!a.name || a.answers.length !== 1) error('review-bind requires --name and one --answers');
1844
+ out = reviewBind(hp, a.name, { answers: a.answers[0], task: a.task, kind: a.kind });
1845
+ } else if (a.mode === 'bind') {
1846
+ if (!a.unit || !a.task) error('bind requires --unit and --task');
1847
+ out = bind(hp, a.unit, a.task);
1848
+ } else if (a.mode === 'release') {
1849
+ if (!a.unit) error('release requires --unit');
1850
+ out = release(hp, a.unit, { stalled: a.stalled, error: a.error, task: a.task });
1851
+ } else if (a.mode === 'reap') {
1852
+ out = reap(hp);
1853
+ } else if (a.mode === 'wait') {
1854
+ out = await wait(hp, { timeoutS: a.timeout_s, jobs: a.job, answers: a.answers });
1855
+ } else if (a.mode === 'status') {
1856
+ out = status(hp);
1857
+ } else if (a.mode === 'stop') {
1858
+ out = control(hp, { op: 'stop' });
1859
+ } else {
1860
+ if (!a.group) error(`${a.mode} requires --group`);
1861
+ if (a.resume && a.fresh) error('requeue: --resume and --fresh exclude each other');
1862
+ out = control(hp, { op: a.mode, group: a.group, message: a.message, resume: a.resume, fresh: a.fresh });
1863
+ }
1864
+ ac.printJson(out, 1);
1865
+ }
1866
+
1867
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
1868
+ ac.runMain(main);
1869
+ }