@buaa_smat/hometrans 0.1.20 → 26.0.0-devecocli.2

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 (981) hide show
  1. package/agents/build-fixer.md +406 -0
  2. package/agents/code-reviewer.md +461 -496
  3. package/agents/model-render-worker.md +34 -0
  4. package/agents/model-worker.md +23 -0
  5. package/agents/specgen-worker.md +18 -0
  6. package/commands/hometrans.md +17 -0
  7. package/devecocli-plugin/common.ts +2203 -0
  8. package/devecocli-plugin/install.ts +61 -0
  9. package/devecocli-plugin/uninstall.ts +26 -0
  10. package/devecocli-plugin/update.ts +66 -0
  11. package/index.js +1418 -0
  12. package/package.json +81 -64
  13. package/platforms/atomcode/agents/build-fixer.frontmatter.md +6 -0
  14. package/platforms/atomcode/agents/code-reviewer.frontmatter.md +6 -0
  15. package/platforms/atomcode/agents/model-render-worker.frontmatter.md +6 -0
  16. package/platforms/atomcode/agents/model-worker.frontmatter.md +6 -0
  17. package/platforms/atomcode/agents/specgen-worker.frontmatter.md +6 -0
  18. package/platforms/deveco/agents/build-fixer.frontmatter.md +5 -0
  19. package/platforms/deveco/agents/code-reviewer.frontmatter.md +5 -0
  20. package/platforms/deveco/agents/model-render-worker.frontmatter.md +5 -0
  21. package/platforms/deveco/agents/model-worker.frontmatter.md +5 -0
  22. package/platforms/deveco/agents/specgen-worker.frontmatter.md +5 -0
  23. package/platforms/opencode/agents/build-fixer.frontmatter.md +5 -0
  24. package/platforms/opencode/agents/code-reviewer.frontmatter.md +5 -0
  25. package/platforms/opencode/agents/model-render-worker.frontmatter.md +5 -0
  26. package/platforms/opencode/agents/model-worker.frontmatter.md +5 -0
  27. package/platforms/opencode/agents/specgen-worker.frontmatter.md +5 -0
  28. package/plugin.jsonc +12 -0
  29. package/skills/a2h-app-migrate/SKILL.md +181 -0
  30. package/skills/a2h-app-migrate/references/config.example.json +27 -0
  31. package/skills/a2h-app-migrate/references/specs.example.json +19 -0
  32. package/skills/a2h-app-migrate/references/stage-map.md +33 -0
  33. package/skills/a2h-app-migrate/references/workflow.yaml +1600 -0
  34. package/skills/a2h-app-migrate/scripts/android_index.mjs +109 -0
  35. package/skills/a2h-app-migrate/scripts/check_arch_done.mjs +80 -0
  36. package/skills/a2h-app-migrate/scripts/check_module_docs_done.mjs +95 -0
  37. package/skills/a2h-app-migrate/scripts/check_signing.mjs +152 -0
  38. package/skills/a2h-app-migrate/scripts/check_spec_gen_done.mjs +114 -0
  39. package/skills/a2h-app-migrate/scripts/check_spec_pipeline_done.mjs +277 -0
  40. package/skills/a2h-app-migrate/scripts/check_ui_batch_done.mjs +77 -0
  41. package/skills/a2h-app-migrate/scripts/check_utg_static_done.mjs +147 -0
  42. package/skills/a2h-app-migrate/scripts/cli_values.mjs +32 -0
  43. package/skills/a2h-app-migrate/scripts/env_preflight.mjs +1388 -0
  44. package/skills/a2h-app-migrate/scripts/human_review_gate.mjs +651 -0
  45. package/skills/a2h-app-migrate/scripts/infer_android_root.mjs +53 -0
  46. package/skills/a2h-app-migrate/scripts/json_io.mjs +35 -0
  47. package/skills/a2h-app-migrate/scripts/ledger.mjs +104 -0
  48. package/skills/a2h-app-migrate/scripts/lib-yaml-lite.mjs +288 -0
  49. package/skills/a2h-app-migrate/scripts/paths_preflight.mjs +713 -0
  50. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +205 -0
  51. package/skills/a2h-app-migrate/scripts/reuse_static_utg.mjs +121 -0
  52. package/skills/a2h-app-migrate/scripts/run_dir.mjs +212 -0
  53. package/skills/a2h-app-migrate/scripts/spec_layout.mjs +30 -0
  54. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +455 -0
  55. package/skills/a2h-app-migrate/test/test_android_index.mjs +80 -0
  56. package/skills/a2h-app-migrate/test/test_apk_preflight.mjs +63 -0
  57. package/skills/a2h-app-migrate/test/test_arch_done.mjs +54 -0
  58. package/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +92 -0
  59. package/skills/a2h-app-migrate/test/test_config_example.mjs +42 -0
  60. package/skills/a2h-app-migrate/test/test_entry_guards.mjs +93 -0
  61. package/skills/a2h-app-migrate/test/test_env_requirements.mjs +505 -0
  62. package/skills/a2h-app-migrate/test/test_finalize.mjs +89 -0
  63. package/skills/a2h-app-migrate/test/test_gate_checkpoint.mjs +146 -0
  64. package/skills/a2h-app-migrate/test/test_hmos_fingerprint.mjs +68 -0
  65. package/skills/a2h-app-migrate/test/test_infer_android_root.mjs +91 -0
  66. package/skills/a2h-app-migrate/test/test_interaction.mjs +122 -0
  67. package/skills/a2h-app-migrate/test/test_json_io.mjs +32 -0
  68. package/skills/a2h-app-migrate/test/test_leaf_questions.mjs +109 -0
  69. package/skills/a2h-app-migrate/test/test_module_docs_done.mjs +53 -0
  70. package/skills/a2h-app-migrate/test/test_parse_args.mjs +69 -0
  71. package/skills/a2h-app-migrate/test/test_preflight_report.mjs +83 -0
  72. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +144 -0
  73. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +100 -0
  74. package/skills/a2h-app-migrate/test/test_run_dir.mjs +315 -0
  75. package/skills/a2h-app-migrate/test/test_skill_doc.mjs +133 -0
  76. package/skills/a2h-app-migrate/test/test_spec_gen_done.mjs +133 -0
  77. package/skills/a2h-app-migrate/test/test_spec_gen_gate.mjs +158 -0
  78. package/skills/a2h-app-migrate/test/test_spec_pipeline_done.mjs +181 -0
  79. package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +76 -0
  80. package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +53 -0
  81. package/skills/a2h-app-migrate/test/test_ui_batch_gate.mjs +226 -0
  82. package/skills/a2h-app-migrate/test/test_utg_dirs.mjs +39 -0
  83. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +168 -0
  84. package/skills/a2h-app-migrate/test/test_validate_races.mjs +50 -0
  85. package/skills/a2h-arch-generate/SKILL.md +375 -0
  86. package/skills/a2h-arch-generate/examples/reconcile-existing-project.md +107 -0
  87. package/skills/a2h-arch-generate/examples/simple-conversion-android.md +103 -0
  88. package/skills/a2h-arch-generate/examples/simple-conversion-backend.md +70 -0
  89. package/skills/a2h-arch-generate/examples/simple-conversion-uniapp.md +106 -0
  90. package/skills/a2h-arch-generate/references/artifact-contracts.generate.md +120 -0
  91. package/skills/a2h-arch-generate/references/artifact-contracts.reconcile.md +123 -0
  92. package/skills/a2h-arch-generate/references/bpta-layered-architecture-design.md +88 -0
  93. package/skills/a2h-arch-generate/references/clustering-guidance.md +33 -0
  94. package/skills/a2h-arch-generate/references/database-schema-recovery.md +107 -0
  95. package/skills/a2h-arch-generate/references/existing-target-annotation.md +68 -0
  96. package/skills/a2h-arch-generate/references/harmony-project-inspection.md +150 -0
  97. package/skills/a2h-arch-generate/references/harmony-target-architecture.md +94 -0
  98. package/skills/a2h-arch-generate/references/homegraph-workflow.md +120 -0
  99. package/skills/a2h-arch-generate/references/module-evidence-subagent.md +45 -0
  100. package/skills/a2h-arch-generate/references/reconciliation-model.md +204 -0
  101. package/skills/a2h-arch-generate/references/scope-policy.md +28 -0
  102. package/skills/a2h-arch-generate/references/semantic-review.md +65 -0
  103. package/skills/a2h-arch-generate/references/source-baseline.md +93 -0
  104. package/skills/a2h-arch-generate/references/source-ecosystems.md +54 -0
  105. package/skills/a2h-arch-generate/references/transformation-model.md +78 -0
  106. package/skills/a2h-arch-generate/scripts/check_module_staleness.mjs +284 -0
  107. package/skills/a2h-arch-generate/scripts/cleanup_intermediates.mjs +260 -0
  108. package/skills/a2h-arch-generate/scripts/compute_processing_order.mjs +325 -0
  109. package/skills/a2h-arch-generate/scripts/create_project.mjs +149 -0
  110. package/skills/a2h-arch-generate/scripts/dump_core_facts.mjs +151 -0
  111. package/skills/a2h-arch-generate/scripts/extract_core_components.mjs +167 -0
  112. package/skills/a2h-arch-generate/scripts/generate_source_baseline.mjs +363 -0
  113. package/skills/a2h-arch-generate/scripts/generate_state.mjs +60 -0
  114. package/skills/a2h-arch-generate/scripts/inspect_and_route.mjs +326 -0
  115. package/skills/a2h-arch-generate/scripts/inspect_android_project.mjs +3739 -0
  116. package/skills/a2h-arch-generate/scripts/inspect_harmony_target.mjs +800 -0
  117. package/skills/a2h-arch-generate/scripts/inspect_project.mjs +251 -0
  118. package/skills/a2h-arch-generate/scripts/inspect_uniapp_project.mjs +809 -0
  119. package/skills/a2h-arch-generate/scripts/lib/py_compat.mjs +1454 -0
  120. package/skills/a2h-arch-generate/scripts/module_create/create.mjs +136 -0
  121. package/skills/a2h-arch-generate/scripts/module_create/generate.mjs +636 -0
  122. package/skills/a2h-arch-generate/scripts/module_create/hap/build-profile.json5 +33 -0
  123. package/skills/a2h-arch-generate/scripts/module_create/hap/hvigorfile.ts +6 -0
  124. package/skills/a2h-arch-generate/scripts/module_create/hap/obfuscation-rules.txt +23 -0
  125. package/skills/a2h-arch-generate/scripts/module_create/hap/oh-package.json5 +10 -0
  126. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/applicationability/ApplicationAbility.ets +43 -0
  127. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +23 -0
  128. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/module.json5 +26 -0
  129. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/color.json +8 -0
  130. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/float.json +8 -0
  131. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/element/string.json +16 -0
  132. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/background.png +0 -0
  133. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/foreground.png +0 -0
  134. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/layered_image.json +7 -0
  135. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/media/startIcon.png +0 -0
  136. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/resources/base/profile/main_pages.json +5 -0
  137. package/skills/a2h-arch-generate/scripts/module_create/hap/src/mock/mock-config.json5 +2 -0
  138. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/ets/test/Ability.test.ets +35 -0
  139. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/ets/test/List.test.ets +5 -0
  140. package/skills/a2h-arch-generate/scripts/module_create/hap/src/ohosTest/module.json5 +11 -0
  141. package/skills/a2h-arch-generate/scripts/module_create/hap/src/test/List.test.ets +5 -0
  142. package/skills/a2h-arch-generate/scripts/module_create/hap/src/test/LocalUnit.test.ets +33 -0
  143. package/skills/a2h-arch-generate/scripts/module_create/har/Index.ets +1 -0
  144. package/skills/a2h-arch-generate/scripts/module_create/har/build-profile.json5 +36 -0
  145. package/skills/a2h-arch-generate/scripts/module_create/har/hvigorfile.ts +6 -0
  146. package/skills/a2h-arch-generate/scripts/module_create/har/obfuscation-rules.txt +23 -0
  147. package/skills/a2h-arch-generate/scripts/module_create/har/oh-package.json5 +9 -0
  148. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +19 -0
  149. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/module.json5 +9 -0
  150. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/resources/base/element/float.json +8 -0
  151. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/resources/base/element/string.json +8 -0
  152. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/ets/test/Ability.test.ets +35 -0
  153. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/ets/test/List.test.ets +5 -0
  154. package/skills/a2h-arch-generate/scripts/module_create/har/src/ohosTest/module.json5 +11 -0
  155. package/skills/a2h-arch-generate/scripts/module_create/har/src/test/List.test.ets +5 -0
  156. package/skills/a2h-arch-generate/scripts/module_create/har/src/test/LocalUnit.test.ets +33 -0
  157. package/skills/a2h-arch-generate/scripts/module_create/hsp/Index.ets +1 -0
  158. package/skills/a2h-arch-generate/scripts/module_create/hsp/build-profile.json5 +36 -0
  159. package/skills/a2h-arch-generate/scripts/module_create/hsp/consumer-rules.txt +0 -0
  160. package/skills/a2h-arch-generate/scripts/module_create/hsp/hvigorfile.ts +6 -0
  161. package/skills/a2h-arch-generate/scripts/module_create/hsp/obfuscation-rules.txt +23 -0
  162. package/skills/a2h-arch-generate/scripts/module_create/hsp/oh-package.json5 +10 -0
  163. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +20 -0
  164. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/utils/Calc.ets +3 -0
  165. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/module.json5 +12 -0
  166. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/element/float.json +8 -0
  167. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/element/string.json +8 -0
  168. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/resources/base/profile/main_pages.json +5 -0
  169. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/ets/test/Ability.test.ets +35 -0
  170. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/ets/test/List.test.ets +5 -0
  171. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/ohosTest/module.json5 +11 -0
  172. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/test/List.test.ets +5 -0
  173. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/test/LocalUnit.test.ets +33 -0
  174. package/skills/a2h-arch-generate/scripts/module_create/testdata/reconcile-layer-PROJECT_DESIGN.md +47 -0
  175. package/skills/a2h-arch-generate/scripts/module_create/testdata/single-entry-PROJECT_DESIGN.md +15 -0
  176. package/skills/a2h-arch-generate/scripts/module_create/testdata/three-layer-PROJECT_DESIGN.md +36 -0
  177. package/skills/a2h-arch-generate/scripts/module_create/testdata/verification-report.md +150 -0
  178. package/skills/a2h-arch-generate/scripts/resolve_android_stores.mjs +529 -0
  179. package/skills/a2h-arch-generate/scripts/scaffold_project.mjs +230 -0
  180. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/build.gradle +11 -0
  181. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/AndroidManifest.xml +12 -0
  182. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/MainActivity.kt +8 -0
  183. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/app/src/main/java/com/example/notes/NotesStore.kt +17 -0
  184. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/build.gradle +3 -0
  185. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/android_source/settings.gradle +1 -0
  186. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/AppScope/app.json5 +8 -0
  187. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/build-profile.json5 +14 -0
  188. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/build-profile.json5 +7 -0
  189. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/oh-package.json5 +1 -0
  190. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/common/utils/src/main/ets/utils/Format.ets +3 -0
  191. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/build-profile.json5 +7 -0
  192. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/oh-package.json5 +1 -0
  193. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/home/src/main/ets/pages/Home.ets +3 -0
  194. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/build-profile.json5 +7 -0
  195. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/oh-package.json5 +1 -0
  196. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/features/sync/src/main/ets/engine/SyncEngine.ets +3 -0
  197. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/hvigorfile.ts +1 -0
  198. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/oh-package.json5 +1 -0
  199. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/build-profile.json5 +7 -0
  200. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/oh-package.json5 +9 -0
  201. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/harmony_target/products/app/src/main/ets/pages/Index.ets +7 -0
  202. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/App.vue +10 -0
  203. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/manifest.json +6 -0
  204. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages/index/index.vue +16 -0
  205. package/skills/a2h-arch-generate/scripts/tests/e2e/fixtures/uniapp_source/pages.json +5 -0
  206. package/skills/a2h-arch-generate/scripts/tests/e2e/run_e2e.mjs +548 -0
  207. package/skills/a2h-arch-generate/scripts/tests/run_tests.mjs +1122 -0
  208. package/skills/a2h-arch-generate/scripts/tests/test_cleanup.mjs +191 -0
  209. package/skills/a2h-arch-generate/scripts/tests/test_console_encoding.mjs +52 -0
  210. package/skills/a2h-arch-generate/scripts/tests/test_git_root.mjs +34 -0
  211. package/skills/a2h-arch-generate/scripts/tests/test_router.mjs +138 -0
  212. package/skills/a2h-arch-generate/scripts/validate_architecture_docs.mjs +829 -0
  213. package/skills/a2h-arch-generate/scripts/validate_data_docs.mjs +937 -0
  214. package/skills/a2h-arch-generate/scripts/validate_homegraph_artifacts.mjs +542 -0
  215. package/skills/a2h-arch-generate/scripts/validate_incremental_docs.mjs +415 -0
  216. package/skills/a2h-arkts-logic-coder/SKILL.md +125 -0
  217. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +6 -0
  218. package/skills/a2h-arkts-logic-coder/references/code-generation.md +124 -0
  219. package/skills/a2h-arkts-logic-coder/scripts/check_module_scope.ts +224 -0
  220. package/skills/a2h-arkts-logic-coder/scripts/check_mvvm.ts +377 -0
  221. package/skills/a2h-arkts-logic-coder/scripts/stop_check_hook.ts +443 -0
  222. package/skills/a2h-arkts-logic-coder/scripts/test_check_scripts.ts +211 -0
  223. package/skills/a2h-arkts-logic-coder/scripts/test_worktree_compat.ts +81 -0
  224. package/skills/a2h-batch-ui-align/SKILL.md +309 -0
  225. package/skills/a2h-batch-ui-align/assets/ColorUtils.ets +81 -0
  226. package/skills/a2h-batch-ui-align/flowchart.html +271 -0
  227. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/conversion-procedure.md +523 -661
  228. package/skills/a2h-batch-ui-align/references/incremental-scope.md +139 -0
  229. package/skills/a2h-batch-ui-align/references/lottie-integration.md +43 -0
  230. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +8 -8
  231. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +3 -0
  232. package/skills/a2h-batch-ui-align/references/source-only-tier.md +32 -0
  233. package/skills/a2h-batch-ui-align/references/step3-capture.md +211 -0
  234. package/skills/a2h-batch-ui-align/references/step4-prepare.md +192 -0
  235. package/skills/a2h-batch-ui-align/references/step5-convert.md +202 -0
  236. package/skills/a2h-batch-ui-align/scripts/agent_cli.mjs +572 -0
  237. package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/scripts/android_parse_fast.ts +246 -39
  238. package/skills/a2h-batch-ui-align/scripts/answers_check.mjs +86 -0
  239. package/skills/a2h-batch-ui-align/scripts/arkts_static_check.ts +2689 -0
  240. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +1656 -0
  241. package/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +79 -0
  242. package/skills/a2h-batch-ui-align/scripts/detach.mjs +258 -0
  243. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +1524 -0
  244. package/skills/a2h-batch-ui-align/scripts/generate_pages_json.mjs +612 -0
  245. package/skills/a2h-batch-ui-align/scripts/group_commit.mjs +166 -0
  246. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +1437 -0
  247. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1869 -0
  248. package/skills/a2h-batch-ui-align/scripts/group_watch.mjs +696 -0
  249. package/skills/a2h-batch-ui-align/scripts/harmony_index.mjs +218 -0
  250. package/skills/a2h-batch-ui-align/scripts/host_env.mjs +208 -0
  251. package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +1229 -0
  252. package/skills/a2h-batch-ui-align/scripts/occlusion.mjs +141 -0
  253. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +1124 -0
  254. package/skills/a2h-batch-ui-align/scripts/shell_contract.mjs +996 -0
  255. package/skills/a2h-batch-ui-align/scripts/tests/agent_cli.test.mjs +217 -0
  256. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_align_tint.test.mjs +253 -0
  257. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rules.test.mjs +365 -0
  258. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_shell.test.mjs +72 -0
  259. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +353 -0
  260. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +345 -0
  261. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_scope.test.mjs +290 -0
  262. package/skills/a2h-batch-ui-align/scripts/tests/color_utils_asset.test.mjs +74 -0
  263. package/skills/a2h-batch-ui-align/scripts/tests/export_ui_info.test.mjs +507 -0
  264. package/skills/a2h-batch-ui-align/scripts/tests/generate_pages_json.test.mjs +123 -0
  265. package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +126 -0
  266. package/skills/a2h-batch-ui-align/scripts/tests/group_pack.test.mjs +189 -0
  267. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +1451 -0
  268. package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +215 -0
  269. package/skills/a2h-batch-ui-align/scripts/tests/harmony_index.test.mjs +95 -0
  270. package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +115 -0
  271. package/skills/a2h-batch-ui-align/scripts/tests/measure_pack.test.mjs +170 -0
  272. package/skills/a2h-batch-ui-align/scripts/tests/occlusion.test.mjs +102 -0
  273. package/skills/a2h-batch-ui-align/scripts/tests/phase5_check.test.mjs +244 -0
  274. package/skills/a2h-batch-ui-align/scripts/tests/shell_contract.test.mjs +130 -0
  275. package/skills/a2h-batch-ui-align/scripts/tests/test_bfs_exit.ts +49 -0
  276. package/skills/a2h-coldstart-smoke-gate/SKILL.md +57 -0
  277. package/skills/a2h-dashboard-render/SKILL.md +65 -0
  278. package/skills/a2h-dashboard-render/references/artifact-contract.jsonc +147 -0
  279. package/skills/a2h-dashboard-render/references/artifact-registry-spec.md +67 -0
  280. package/skills/a2h-dashboard-render/references/dashboard.config.example.json +19 -0
  281. package/skills/a2h-dashboard-render/references//347/234/213/346/235/277/350/257/264/346/230/216.md +83 -0
  282. package/skills/a2h-dashboard-render/scripts/artifact_contract.mjs +138 -0
  283. package/skills/a2h-dashboard-render/scripts/check-registry.mjs +87 -0
  284. package/skills/a2h-dashboard-render/scripts/dashboard.mjs +3215 -0
  285. package/skills/a2h-dashboard-render/scripts/device_capture.mjs +2010 -0
  286. package/skills/a2h-dashboard-render/scripts/page_capture.mjs +828 -0
  287. package/skills/a2h-dashboard-render/scripts/usage_readers.mjs +459 -0
  288. package/skills/a2h-dashboard-render/scripts/usage_worker.mjs +13 -0
  289. package/skills/a2h-dashboard-render/test/fixtures/page_capture/broken.xml +1 -0
  290. package/skills/a2h-dashboard-render/test/fixtures/page_capture/expected.json +156 -0
  291. package/skills/a2h-dashboard-render/test/fixtures/page_capture/hmos.json +1 -0
  292. package/skills/a2h-dashboard-render/test/fixtures/page_capture/list.xml +1 -0
  293. package/skills/a2h-dashboard-render/test/fixtures/page_capture/nested_scroll.xml +1 -0
  294. package/skills/a2h-dashboard-render/test/test_artifact_contract.mjs +170 -0
  295. package/skills/a2h-dashboard-render/test/test_cli_check_registry.mjs +99 -0
  296. package/skills/a2h-dashboard-render/test/test_dashboard_architecture.mjs +182 -0
  297. package/skills/a2h-dashboard-render/test/test_dashboard_build.mjs +64 -0
  298. package/skills/a2h-dashboard-render/test/test_dashboard_node.mjs +1172 -0
  299. package/skills/a2h-dashboard-render/test/test_dashboard_spec_pipeline.mjs +251 -0
  300. package/skills/a2h-dashboard-render/test/test_dashboard_ui_pipeline.mjs +81 -0
  301. package/skills/a2h-dashboard-render/test/test_device_capture_env.mjs +115 -0
  302. package/skills/a2h-dashboard-render/test/test_device_capture_policy.mjs +303 -0
  303. package/skills/a2h-dashboard-render/test/test_page_capture.mjs +147 -0
  304. package/skills/a2h-dashboard-render/test/test_usage_readers.mjs +444 -0
  305. package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/SKILL.md +305 -293
  306. package/skills/a2h-module-semantic-docs/SKILL.md +227 -0
  307. package/skills/a2h-module-semantic-docs/scripts/commit_module_state.mjs +168 -0
  308. package/skills/a2h-module-semantic-docs/scripts/lib/py_compat.mjs +688 -0
  309. package/skills/a2h-module-semantic-docs/scripts/scan_modules.mjs +1021 -0
  310. package/skills/a2h-module-semantic-docs/test/golden/module_structure.json +187 -0
  311. package/skills/a2h-module-semantic-docs/test/golden/module_understanding.json +351 -0
  312. package/skills/a2h-module-semantic-docs/test/golden/module_update_plan.json +495 -0
  313. package/skills/a2h-module-semantic-docs/test/golden/project_directory_structure.json +157 -0
  314. package/skills/a2h-module-semantic-docs/test/test_scan_and_commit.mjs +388 -0
  315. package/skills/a2h-resource-convert/SKILL.md +369 -0
  316. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/code-vector-icon-rules.md +4 -4
  317. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/conversion-rules.md +16 -5
  318. package/skills/a2h-resource-convert/references/incremental-page-migration.md +251 -0
  319. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/lottie-conversion-rules.md +17 -17
  320. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/resource-mapping-rules.md +15 -4
  321. package/skills/a2h-resource-convert/references/step3_5-dependency-filter.md +54 -0
  322. package/skills/a2h-resource-convert/references/step4-qualifiers-and-values.md +142 -0
  323. package/skills/a2h-resource-convert/references/step4-resource-types.md +249 -0
  324. package/skills/a2h-resource-convert/references/step5-reference-resolution.md +154 -0
  325. package/skills/a2h-resource-convert/references/step7-report-template.md +217 -0
  326. package/skills/{hmos-resources-convert → a2h-resource-convert}/references/xml-drawable-to-svg-rules.md +38 -0
  327. package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/a2h_resource_convert.ts +456 -90
  328. package/skills/a2h-resource-convert/scripts/a2h_resource_incremental.ts +1072 -0
  329. package/skills/a2h-resource-convert/scripts/app_identity.ts +947 -0
  330. package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/code_vector_icons.ts +19 -3
  331. package/skills/a2h-resource-convert/scripts/extract_page_resources.ts +989 -0
  332. package/skills/a2h-resource-convert/scripts/extract_project_resources.ts +1464 -0
  333. package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +182 -0
  334. package/skills/a2h-resource-convert/scripts/tests/app_identity.test.mjs +206 -0
  335. package/skills/a2h-spec-design/SKILL.md +336 -0
  336. package/skills/a2h-spec-design/scripts/inspect_spec_design_inputs.mjs +146 -0
  337. package/skills/a2h-spec-design/scripts/lib/py_compat.mjs +481 -0
  338. package/skills/a2h-spec-design/scripts/move_spec_technical_reference.mjs +159 -0
  339. package/skills/a2h-spec-design/scripts/resolve_module_design.mjs +102 -0
  340. package/skills/a2h-spec-design/scripts/validate_spec_design_output.mjs +285 -0
  341. package/skills/a2h-spec-design/test/golden/inspect_happy.json +20 -0
  342. package/skills/a2h-spec-design/test/golden/move_design.md +18 -0
  343. package/skills/a2h-spec-design/test/golden/move_design_crlf.md +18 -0
  344. package/skills/a2h-spec-design/test/golden/move_spec.md +7 -0
  345. package/skills/a2h-spec-design/test/golden/resolve_cases.json +36 -0
  346. package/skills/a2h-spec-design/test/golden/validate_issue_file.md +12 -0
  347. package/skills/a2h-spec-design/test/golden/validate_issues.json +57 -0
  348. package/skills/a2h-spec-design/test/test_spec_design_scripts.mjs +381 -0
  349. package/skills/a2h-spec-design-pipeline/SKILL.md +228 -0
  350. package/skills/a2h-spec-design-pipeline/package.json +4 -0
  351. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +63 -0
  352. package/skills/a2h-spec-design-pipeline/references/execution-model.md +69 -0
  353. package/skills/a2h-spec-design-pipeline/references/final-report-template.md +24 -0
  354. package/skills/a2h-spec-design-pipeline/references/initialization.md +57 -0
  355. package/skills/a2h-spec-design-pipeline/references/merge-queue.md +21 -0
  356. package/skills/a2h-spec-design-pipeline/references/scripts.md +27 -0
  357. package/skills/a2h-spec-design-pipeline/references/specs.example.json +19 -0
  358. package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +21 -0
  359. package/skills/a2h-spec-design-pipeline/scripts/atomic_write.ts +42 -0
  360. package/skills/a2h-spec-design-pipeline/scripts/audit_claims.ts +252 -0
  361. package/skills/a2h-spec-design-pipeline/scripts/branch_landed.ts +77 -0
  362. package/skills/a2h-spec-design-pipeline/scripts/deps_ready.ts +195 -0
  363. package/skills/a2h-spec-design-pipeline/scripts/ensure_wt_index.ts +651 -0
  364. package/skills/a2h-spec-design-pipeline/scripts/git_baseline.ts +124 -0
  365. package/skills/a2h-spec-design-pipeline/scripts/inflight.mjs +944 -0
  366. package/skills/a2h-spec-design-pipeline/scripts/lib/bgcli.mjs +95 -0
  367. package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +502 -0
  368. package/skills/a2h-spec-design-pipeline/scripts/plan_waves.ts +475 -0
  369. package/skills/a2h-spec-design-pipeline/scripts/reconcile.mjs +218 -0
  370. package/skills/a2h-spec-design-pipeline/scripts/resolve_wiring.ts +164 -0
  371. package/skills/a2h-spec-design-pipeline/scripts/test_atomic_write.ts +44 -0
  372. package/skills/a2h-spec-design-pipeline/scripts/test_audit_claims.ts +301 -0
  373. package/skills/a2h-spec-design-pipeline/scripts/test_bgcli.mjs +64 -0
  374. package/skills/a2h-spec-design-pipeline/scripts/test_branch_landed.ts +87 -0
  375. package/skills/a2h-spec-design-pipeline/scripts/test_deps_ready.ts +265 -0
  376. package/skills/a2h-spec-design-pipeline/scripts/test_ensure_wt_index.ts +675 -0
  377. package/skills/a2h-spec-design-pipeline/scripts/test_git_baseline.ts +105 -0
  378. package/skills/a2h-spec-design-pipeline/scripts/test_inflight.mjs +452 -0
  379. package/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +375 -0
  380. package/skills/a2h-spec-design-pipeline/scripts/test_plan_waves.ts +561 -0
  381. package/skills/a2h-spec-design-pipeline/scripts/test_reconcile.mjs +182 -0
  382. package/skills/a2h-spec-design-pipeline/scripts/test_resolve_wiring.ts +138 -0
  383. package/skills/a2h-spec-design-pipeline/scripts/test_watchdog.mjs +289 -0
  384. package/skills/a2h-spec-design-pipeline/scripts/watchdog.mjs +441 -0
  385. package/skills/a2h-spec-generate/SKILL.md +285 -0
  386. package/skills/a2h-spec-generate/package.json +9 -0
  387. package/skills/a2h-spec-generate/references/batch-mode.md +151 -0
  388. package/skills/a2h-spec-generate/references/delete-blast-radius.md +3 -0
  389. package/skills/a2h-spec-generate/references/fusion-task-contract.md +114 -0
  390. package/skills/a2h-spec-generate/references/input-formats.md +27 -0
  391. package/skills/a2h-spec-generate/references/library-evidence.md +3 -0
  392. package/skills/a2h-spec-generate/references/method-discipline.md +64 -0
  393. package/skills/a2h-spec-generate/references/optional-gates.json +45 -0
  394. package/skills/a2h-spec-generate/references/recall-guide.md +83 -0
  395. package/skills/a2h-spec-generate/references/recall-terse.md +3 -0
  396. package/skills/a2h-spec-generate/references/recall-uniapp.md +10 -0
  397. package/skills/a2h-spec-generate/references/requirement-scope.md +122 -0
  398. package/skills/a2h-spec-generate/references/review-checklist.md +21 -0
  399. package/skills/a2h-spec-generate/references/spec-sample-complex.md +80 -0
  400. package/skills/a2h-spec-generate/references/spec-sample-transfer.md +43 -0
  401. package/skills/a2h-spec-generate/references/spec-samples.md +65 -0
  402. package/skills/a2h-spec-generate/references/specs.schema.json +79 -0
  403. package/skills/a2h-spec-generate/references/synthesis-rules.md +143 -0
  404. package/skills/a2h-spec-generate/references/transfer-file.md +5 -0
  405. package/skills/a2h-spec-generate/references/transfer-socket.md +5 -0
  406. package/skills/a2h-spec-generate/references/worker-rules.md +126 -0
  407. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +514 -0
  408. package/skills/a2h-spec-generate/scripts/check_spec.ts +361 -0
  409. package/skills/a2h-spec-generate/scripts/collect-specs.mjs +470 -0
  410. package/skills/a2h-spec-generate/scripts/detect-project.mjs +271 -0
  411. package/skills/a2h-spec-generate/scripts/ensure-index.mjs +188 -0
  412. package/skills/a2h-spec-generate/scripts/feature-stem.mjs +150 -0
  413. package/skills/a2h-spec-generate/scripts/inspect-uniapp.mjs +733 -0
  414. package/skills/{hmos-spec-generate → a2h-spec-generate}/scripts/parse_requirements.ts +1 -1
  415. package/skills/a2h-spec-generate/scripts/prepare-facts.mjs +307 -0
  416. package/skills/a2h-spec-generate/scripts/publication-verdict.mjs +171 -0
  417. package/skills/a2h-spec-generate/scripts/publish-specs.mjs +280 -0
  418. package/skills/a2h-spec-generate/scripts/render-tasks.mjs +399 -0
  419. package/skills/a2h-spec-generate/scripts/report.mjs +132 -0
  420. package/skills/a2h-spec-generate/scripts/reqgen/assets/dashboard.html +149 -0
  421. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-api.js +49 -0
  422. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-code-view.js +140 -0
  423. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-format.js +16 -0
  424. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-handoff.js +42 -0
  425. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-splitters.js +78 -0
  426. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-state.js +47 -0
  427. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-tree.js +194 -0
  428. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz-virtual-list.js +118 -0
  429. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.css +245 -0
  430. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.html +99 -0
  431. package/skills/a2h-spec-generate/scripts/reqgen/assets/viz.js +220 -0
  432. package/skills/a2h-spec-generate/scripts/reqgen/package-lock.json +47 -0
  433. package/skills/a2h-spec-generate/scripts/reqgen/package.json +23 -0
  434. package/skills/a2h-spec-generate/scripts/reqgen/src/agent-render/serve.ts +95 -0
  435. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/callback-call-sites.ts +82 -0
  436. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/area-ownership.ts +496 -0
  437. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/build.ts +2217 -0
  438. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/callback-flow.ts +386 -0
  439. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/component-variants.ts +845 -0
  440. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/graph/index.ts +24 -0
  441. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/index.ts +22 -0
  442. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/policy.ts +572 -0
  443. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/names/traceability.ts +580 -0
  444. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/build.ts +1270 -0
  445. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/index.ts +10 -0
  446. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/projection.ts +804 -0
  447. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/req-model/render-projection.ts +51 -0
  448. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/android-interaction-registry.ts +286 -0
  449. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/builder.ts +453 -0
  450. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/compose-api-registry.ts +526 -0
  451. package/skills/a2h-spec-generate/scripts/reqgen/src/analysis/source-facts/index.ts +15 -0
  452. package/skills/a2h-spec-generate/scripts/reqgen/src/connector/index.ts +1 -0
  453. package/skills/a2h-spec-generate/scripts/reqgen/src/connector/utg-inbound.ts +763 -0
  454. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/area-graph.ts +383 -0
  455. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/artifact.ts +68 -0
  456. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/common.ts +88 -0
  457. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/diagnostic.ts +64 -0
  458. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/gap-audit.ts +113 -0
  459. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/index.ts +12 -0
  460. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/name-traceability.ts +108 -0
  461. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/raw-fact.ts +377 -0
  462. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/req-model.ts +238 -0
  463. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/run.ts +134 -0
  464. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/semantic-completeness.ts +35 -0
  465. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/source-facts.ts +48 -0
  466. package/skills/a2h-spec-generate/scripts/reqgen/src/contracts/utg.ts +133 -0
  467. package/skills/a2h-spec-generate/scripts/reqgen/src/core/output-guard.ts +42 -0
  468. package/skills/a2h-spec-generate/scripts/reqgen/src/core/stable-id.ts +118 -0
  469. package/skills/a2h-spec-generate/scripts/reqgen/src/cross-area-tally-cli.ts +179 -0
  470. package/skills/a2h-spec-generate/scripts/reqgen/src/dashboard-cli.ts +188 -0
  471. package/skills/a2h-spec-generate/scripts/reqgen/src/dump/dump.ts +1184 -0
  472. package/skills/a2h-spec-generate/scripts/reqgen/src/dump/index.ts +1 -0
  473. package/skills/a2h-spec-generate/scripts/reqgen/src/dump-cli.ts +373 -0
  474. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-facts.ts +1014 -0
  475. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/area-output.ts +32 -0
  476. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/schema.ts +142 -0
  477. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/selfcheck.ts +312 -0
  478. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/spec-bindings.ts +310 -0
  479. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +685 -0
  480. package/skills/a2h-spec-generate/scripts/reqgen/src/graph/paths.ts +575 -0
  481. package/skills/a2h-spec-generate/scripts/reqgen/src/homegraph-cli.ts +50 -0
  482. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/android-resource-resolver.ts +391 -0
  483. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/androidx-preference-contracts.ts +44 -0
  484. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/contracts.ts +640 -0
  485. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/cross-area.ts +207 -0
  486. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/finalizer.ts +1297 -0
  487. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/identity.ts +186 -0
  488. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/index.ts +16 -0
  489. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/planner.ts +312 -0
  490. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/preference-enrichment.ts +793 -0
  491. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/raw-facts.ts +355 -0
  492. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/rules.ts +271 -0
  493. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/scanner.ts +666 -0
  494. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/schema.ts +365 -0
  495. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/stable-key.ts +144 -0
  496. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/task-contract.ts +301 -0
  497. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/tree-sitter-adapter.ts +923 -0
  498. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/uniapp-utg-adapter.ts +543 -0
  499. package/skills/a2h-spec-generate/scripts/reqgen/src/interaction-analysis/xml-adapter.ts +262 -0
  500. package/skills/a2h-spec-generate/scripts/reqgen/src/model/assemble.ts +2079 -0
  501. package/skills/a2h-spec-generate/scripts/reqgen/src/model/contracts.ts +157 -0
  502. package/skills/a2h-spec-generate/scripts/reqgen/src/model/finalize.ts +809 -0
  503. package/skills/a2h-spec-generate/scripts/reqgen/src/model/index.ts +17 -0
  504. package/skills/a2h-spec-generate/scripts/reqgen/src/model/io.ts +165 -0
  505. package/skills/a2h-spec-generate/scripts/reqgen/src/model/prepare.ts +806 -0
  506. package/skills/a2h-spec-generate/scripts/reqgen/src/model/query.ts +360 -0
  507. package/skills/a2h-spec-generate/scripts/reqgen/src/model/seeds.ts +218 -0
  508. package/skills/a2h-spec-generate/scripts/reqgen/src/model/spec-bindings-sidecar.ts +240 -0
  509. package/skills/a2h-spec-generate/scripts/reqgen/src/model/task.ts +359 -0
  510. package/skills/a2h-spec-generate/scripts/reqgen/src/model-cli.ts +500 -0
  511. package/skills/a2h-spec-generate/scripts/reqgen/src/pipeline/index.ts +7 -0
  512. package/skills/a2h-spec-generate/scripts/reqgen/src/pipeline/output.ts +307 -0
  513. package/skills/a2h-spec-generate/scripts/reqgen/src/requirement-scope.ts +172 -0
  514. package/skills/a2h-spec-generate/scripts/reqgen/src/source-cov/index.ts +1 -0
  515. package/skills/a2h-spec-generate/scripts/reqgen/src/source-cov/source-cov.ts +176 -0
  516. package/skills/a2h-spec-generate/scripts/reqgen/src/source-index/homegraph.ts +1039 -0
  517. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/area-graph.ts +490 -0
  518. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/index.ts +23 -0
  519. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-model.ts +957 -0
  520. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/req-text.ts +248 -0
  521. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/semantic-area-graph.ts +1600 -0
  522. package/skills/a2h-spec-generate/scripts/reqgen/src/validation/types.ts +10 -0
  523. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/artifact-data.ts +201 -0
  524. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-api.ts +74 -0
  525. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-code-view.ts +180 -0
  526. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-format.ts +18 -0
  527. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-handoff.ts +55 -0
  528. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-splitters.ts +78 -0
  529. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-state.ts +66 -0
  530. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-tree.ts +232 -0
  531. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz-virtual-list.ts +179 -0
  532. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/client/viz.ts +240 -0
  533. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/contracts.d.ts +86 -0
  534. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/index.ts +3 -0
  535. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/server.ts +239 -0
  536. package/skills/a2h-spec-generate/scripts/reqgen/src/viz/source-project.ts +316 -0
  537. package/skills/a2h-spec-generate/scripts/reqgen/src/viz-cli.ts +200 -0
  538. package/skills/a2h-spec-generate/scripts/reqgen/test/control-fact-join.test.ts +50 -0
  539. package/skills/a2h-spec-generate/scripts/reqgen/test/control-name-uniapp.test.ts +75 -0
  540. package/skills/a2h-spec-generate/scripts/reqgen/test/cross-area-anchor.test.ts +256 -0
  541. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-area-facts.test.ts +576 -0
  542. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-contract.test.ts +290 -0
  543. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-finalize.test.ts +1323 -0
  544. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-prepare.test.ts +574 -0
  545. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-scope.test.ts +339 -0
  546. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-selfcheck.test.ts +831 -0
  547. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +548 -0
  548. package/skills/a2h-spec-generate/scripts/reqgen/test/model-cli-blockers.test.ts +117 -0
  549. package/skills/a2h-spec-generate/scripts/reqgen/test/model-scope.test.ts +396 -0
  550. package/skills/a2h-spec-generate/scripts/reqgen/test/model-seeds.test.ts +175 -0
  551. package/skills/a2h-spec-generate/scripts/reqgen/test/model-task-contract.test.ts +298 -0
  552. package/skills/a2h-spec-generate/scripts/reqgen/test/model-v4.test.ts +1061 -0
  553. package/skills/a2h-spec-generate/scripts/reqgen/test/specgen-completeness.test.ts +286 -0
  554. package/skills/a2h-spec-generate/scripts/reqgen/test/stagem-stored-path.test.ts +25 -0
  555. package/skills/a2h-spec-generate/scripts/reqgen/test/uniapp-scanner.test.ts +159 -0
  556. package/skills/a2h-spec-generate/scripts/reqgen/tsconfig.json +16 -0
  557. package/skills/a2h-spec-generate/scripts/reqgen/tsconfig.viz-client.json +12 -0
  558. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +632 -0
  559. package/skills/a2h-spec-generate/test/check-spec.test.ts +200 -0
  560. package/skills/a2h-spec-generate/test/collect-specs.test.mjs +538 -0
  561. package/skills/a2h-spec-generate/test/detect-project.test.mjs +37 -0
  562. package/skills/a2h-spec-generate/test/ensure-index.test.mjs +45 -0
  563. package/skills/a2h-spec-generate/test/feature-stem.test.mjs +147 -0
  564. package/skills/a2h-spec-generate/test/fixtures/android/app/src/main/AndroidManifest.xml +3 -0
  565. package/skills/a2h-spec-generate/test/fixtures/android/build.gradle +3 -0
  566. package/skills/a2h-spec-generate/test/fixtures/android/settings.gradle +3 -0
  567. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/package.json +9 -0
  568. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/App.vue +8 -0
  569. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/components/MyCard.vue +9 -0
  570. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/feature/editor/index.vue +1 -0
  571. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/main.ts +6 -0
  572. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/manifest.json +4 -0
  573. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/detail/index.vue +1 -0
  574. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/home/index.vue +33 -0
  575. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages/settings/index.vue +1 -0
  576. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/pages.json +23 -0
  577. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/src/services/items.ts +3 -0
  578. package/skills/a2h-spec-generate/test/fixtures/uniapp-src/tsconfig.json +8 -0
  579. package/skills/a2h-spec-generate/test/fixtures/unknown/README.txt +1 -0
  580. package/skills/a2h-spec-generate/test/inspect-uniapp.test.mjs +54 -0
  581. package/skills/a2h-spec-generate/test/publication-verdict.test.mjs +157 -0
  582. package/skills/a2h-spec-generate/test/publish-specs.test.mjs +282 -0
  583. package/skills/a2h-spec-generate/test/render-tasks.test.mjs +593 -0
  584. package/skills/a2h-utg-explorer/SKILL.md +120 -0
  585. package/skills/a2h-utg-explorer/assets/final_viewer.html +64 -0
  586. package/skills/a2h-utg-explorer/assets/u2.LICENSE +21 -0
  587. package/skills/a2h-utg-explorer/assets/u2.NOTICE +25 -0
  588. package/skills/a2h-utg-explorer/assets/u2.jar +0 -0
  589. package/skills/a2h-utg-explorer/references/architecture.md +270 -0
  590. package/skills/a2h-utg-explorer/references/protocol.md +9 -0
  591. package/skills/a2h-utg-explorer/scripts/app_settings.mjs +143 -0
  592. package/skills/a2h-utg-explorer/scripts/audit.mjs +167 -0
  593. package/skills/a2h-utg-explorer/scripts/close_phases.mjs +66 -0
  594. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +749 -0
  595. package/skills/a2h-utg-explorer/scripts/d_prereqs.mjs +597 -0
  596. package/skills/a2h-utg-explorer/scripts/device_health.mjs +227 -0
  597. package/skills/a2h-utg-explorer/scripts/direct_launch.mjs +276 -0
  598. package/skills/a2h-utg-explorer/scripts/evidence.mjs +108 -0
  599. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +376 -0
  600. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +89 -0
  601. package/skills/a2h-utg-explorer/scripts/plan.mjs +258 -0
  602. package/skills/a2h-utg-explorer/scripts/promote_dynamic.mjs +170 -0
  603. package/skills/a2h-utg-explorer/scripts/recover.mjs +467 -0
  604. package/skills/a2h-utg-explorer/scripts/recover_b.mjs +542 -0
  605. package/skills/a2h-utg-explorer/scripts/recover_d.mjs +302 -0
  606. package/skills/a2h-utg-explorer/scripts/rejudge.mjs +203 -0
  607. package/skills/a2h-utg-explorer/scripts/report.mjs +143 -0
  608. package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +831 -0
  609. package/skills/a2h-utg-explorer/scripts/run_device.mjs +137 -0
  610. package/skills/a2h-utg-explorer/scripts/tests/attest.test.mjs +66 -0
  611. package/skills/a2h-utg-explorer/scripts/tests/chain.test.mjs +45 -0
  612. package/skills/a2h-utg-explorer/scripts/tests/compose_identity.test.mjs +207 -0
  613. package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +104 -0
  614. package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +223 -0
  615. package/skills/a2h-utg-explorer/scripts/tests/device_health.test.mjs +88 -0
  616. package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +187 -0
  617. package/skills/a2h-utg-explorer/scripts/tests/direct_launch.test.mjs +130 -0
  618. package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +136 -0
  619. package/skills/a2h-utg-explorer/scripts/tests/final_utg.test.mjs +135 -0
  620. package/skills/a2h-utg-explorer/scripts/tests/first_round_phases.test.mjs +16 -0
  621. package/skills/a2h-utg-explorer/scripts/tests/generalization_fixes.test.mjs +251 -0
  622. package/skills/a2h-utg-explorer/scripts/tests/hint_check.test.mjs +42 -0
  623. package/skills/a2h-utg-explorer/scripts/tests/interruptions.test.mjs +162 -0
  624. package/skills/a2h-utg-explorer/scripts/tests/node_coverage.test.mjs +193 -0
  625. package/skills/a2h-utg-explorer/scripts/tests/overflow_prefix.test.mjs +204 -0
  626. package/skills/a2h-utg-explorer/scripts/tests/page_identity_tiers.test.mjs +355 -0
  627. package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +240 -0
  628. package/skills/a2h-utg-explorer/scripts/tests/recover.test.mjs +212 -0
  629. package/skills/a2h-utg-explorer/scripts/tests/recover_b.test.mjs +173 -0
  630. package/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +207 -0
  631. package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +213 -0
  632. package/skills/a2h-utg-explorer/scripts/tests/robustness_fixes.test.mjs +345 -0
  633. package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +453 -0
  634. package/skills/a2h-utg-explorer/scripts/tests/runner_capabilities.test.mjs +131 -0
  635. package/skills/a2h-utg-explorer/scripts/tests/scope.test.mjs +229 -0
  636. package/skills/a2h-utg-explorer/scripts/tests/scroll_sweep.test.mjs +321 -0
  637. package/skills/a2h-utg-explorer/scripts/tests/semantics.test.mjs +102 -0
  638. package/skills/a2h-utg-explorer/scripts/tests/twin_opener.test.mjs +119 -0
  639. package/skills/a2h-utg-explorer/scripts/tests/u2_backend.test.mjs +346 -0
  640. package/skills/a2h-utg-explorer/scripts/tests/ui_state_anchors.test.mjs +112 -0
  641. package/skills/a2h-utg-explorer/scripts/tests/variant_strings.test.mjs +63 -0
  642. package/skills/a2h-utg-explorer/scripts/tests/worklist_parts.test.mjs +24 -0
  643. package/skills/a2h-utg-explorer/scripts/utg_explorer/_device_io.mjs +244 -0
  644. package/skills/a2h-utg-explorer/scripts/utg_explorer/_py.mjs +2097 -0
  645. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +1213 -0
  646. package/skills/a2h-utg-explorer/scripts/utg_explorer/attest.mjs +63 -0
  647. package/skills/a2h-utg-explorer/scripts/utg_explorer/chain.mjs +63 -0
  648. package/skills/a2h-utg-explorer/scripts/utg_explorer/coverage.mjs +89 -0
  649. package/skills/a2h-utg-explorer/scripts/utg_explorer/device_lock.mjs +46 -0
  650. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +1136 -0
  651. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +1513 -0
  652. package/skills/a2h-utg-explorer/scripts/variant.mjs +75 -0
  653. package/skills/a2h-utg-explorer/scripts/worklist_parts.mjs +122 -0
  654. package/skills/a2h-utg-static/SKILL.md +361 -0
  655. package/skills/a2h-utg-static/config.json +19 -0
  656. package/skills/a2h-utg-static/references/extractors.md +217 -0
  657. package/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +248 -0
  658. package/skills/a2h-utg-static/references/view-interactions.md +215 -0
  659. package/skills/a2h-utg-static/scripts/_graph.mjs +361 -0
  660. package/skills/a2h-utg-static/scripts/_py.mjs +2177 -0
  661. package/skills/a2h-utg-static/scripts/_spawn.mjs +45 -0
  662. package/skills/a2h-utg-static/scripts/activity_nav.mjs +738 -0
  663. package/skills/a2h-utg-static/scripts/activity_widgets.mjs +254 -0
  664. package/skills/a2h-utg-static/scripts/adapter_nav.mjs +229 -0
  665. package/skills/a2h-utg-static/scripts/androidfragment_nav.mjs +208 -0
  666. package/skills/a2h-utg-static/scripts/assemble.mjs +2065 -0
  667. package/skills/a2h-utg-static/scripts/audit.mjs +268 -0
  668. package/skills/a2h-utg-static/scripts/carry_answers.mjs +201 -0
  669. package/skills/a2h-utg-static/scripts/click_paths.mjs +594 -0
  670. package/skills/a2h-utg-static/scripts/compose_body_text.mjs +172 -0
  671. package/skills/a2h-utg-static/scripts/compose_merge.mjs +263 -0
  672. package/skills/a2h-utg-static/scripts/compose_nav.mjs +1216 -0
  673. package/skills/a2h-utg-static/scripts/compose_navbar_nav.mjs +238 -0
  674. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +2760 -0
  675. package/skills/a2h-utg-static/scripts/compose_titles.mjs +365 -0
  676. package/skills/a2h-utg-static/scripts/compose_widgets.mjs +498 -0
  677. package/skills/a2h-utg-static/scripts/dialog_listener_nav.mjs +237 -0
  678. package/skills/a2h-utg-static/scripts/dialogshow_nav.mjs +308 -0
  679. package/skills/a2h-utg-static/scripts/fragfactory_nav.mjs +170 -0
  680. package/skills/a2h-utg-static/scripts/fragment_nav.mjs +1136 -0
  681. package/skills/a2h-utg-static/scripts/guard_subjects.mjs +162 -0
  682. package/skills/a2h-utg-static/scripts/hg_query.mjs +137 -0
  683. package/skills/a2h-utg-static/scripts/host_resolve.mjs +393 -0
  684. package/skills/a2h-utg-static/scripts/hybrid_bundle.mjs +165 -0
  685. package/skills/a2h-utg-static/scripts/hybrid_pages.mjs +713 -0
  686. package/skills/a2h-utg-static/scripts/hybrid_scope.mjs +660 -0
  687. package/skills/a2h-utg-static/scripts/interaction_sites.mjs +267 -0
  688. package/skills/a2h-utg-static/scripts/io_utils.mjs +59 -0
  689. package/skills/a2h-utg-static/scripts/label_resolve.mjs +864 -0
  690. package/skills/a2h-utg-static/scripts/launch_extras.mjs +91 -0
  691. package/skills/a2h-utg-static/scripts/layout_resolve.mjs +148 -0
  692. package/skills/a2h-utg-static/scripts/manifest.mjs +483 -0
  693. package/skills/a2h-utg-static/scripts/measure/measure_corpus.mjs +297 -0
  694. package/skills/a2h-utg-static/scripts/measure/measure_guards.mjs +98 -0
  695. package/skills/a2h-utg-static/scripts/media_browse_nav.mjs +356 -0
  696. package/skills/a2h-utg-static/scripts/menu_nav.mjs +603 -0
  697. package/skills/a2h-utg-static/scripts/navactions_nav.mjs +255 -0
  698. package/skills/a2h-utg-static/scripts/nl_hints.mjs +453 -0
  699. package/skills/a2h-utg-static/scripts/orphan_overlay_nav.mjs +89 -0
  700. package/skills/a2h-utg-static/scripts/phase_plan.mjs +108 -0
  701. package/skills/a2h-utg-static/scripts/phase_planner.mjs +119 -0
  702. package/skills/a2h-utg-static/scripts/plaindialog_nav.mjs +411 -0
  703. package/skills/a2h-utg-static/scripts/preference_nav.mjs +761 -0
  704. package/skills/a2h-utg-static/scripts/preference_widgets.mjs +142 -0
  705. package/skills/a2h-utg-static/scripts/presenter_nav.mjs +490 -0
  706. package/skills/a2h-utg-static/scripts/registry_nav.mjs +288 -0
  707. package/skills/a2h-utg-static/scripts/run_pipeline.mjs +870 -0
  708. package/skills/a2h-utg-static/scripts/scope_utils.mjs +430 -0
  709. package/skills/a2h-utg-static/scripts/screen_merge.mjs +287 -0
  710. package/skills/a2h-utg-static/scripts/screen_nav.mjs +279 -0
  711. package/skills/a2h-utg-static/scripts/single_host_nav.mjs +291 -0
  712. package/skills/a2h-utg-static/scripts/starter_nav.mjs +198 -0
  713. package/skills/a2h-utg-static/scripts/state_guard.mjs +579 -0
  714. package/skills/a2h-utg-static/scripts/static_prior.mjs +904 -0
  715. package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
  716. package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
  717. package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
  718. package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
  719. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  720. package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +90 -0
  721. package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
  722. package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
  723. package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
  724. package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  725. package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
  726. package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  727. package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  728. package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
  729. package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
  730. package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
  731. package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
  732. package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +267 -0
  733. package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
  734. package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
  735. package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
  736. package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
  737. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
  738. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
  739. package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  740. package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  741. package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
  742. package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
  743. package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
  744. package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
  745. package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
  746. package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
  747. package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
  748. package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
  749. package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
  750. package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
  751. package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +119 -0
  752. package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
  753. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  754. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  755. package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  756. package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  757. package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
  758. package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
  759. package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
  760. package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  761. package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  762. package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  763. package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
  764. package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
  765. package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
  766. package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
  767. package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
  768. package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
  769. package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  770. package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +33 -0
  771. package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  772. package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
  773. package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
  774. package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  775. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  776. package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
  777. package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  778. package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
  779. package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
  780. package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
  781. package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
  782. package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
  783. package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
  784. package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
  785. package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
  786. package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
  787. package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
  788. package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
  789. package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  790. package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  791. package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
  792. package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
  793. package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
  794. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
  795. package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
  796. package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
  797. package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  798. package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
  799. package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
  800. package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
  801. package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
  802. package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
  803. package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
  804. package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  805. package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  806. package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
  807. package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +58 -0
  808. package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
  809. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
  810. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  811. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
  812. package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
  813. package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  814. package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
  815. package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
  816. package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
  817. package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +273 -0
  818. package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
  819. package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
  820. package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
  821. package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
  822. package/skills/a2h-utg-static/scripts/uniapp_nav.mjs +1119 -0
  823. package/skills/a2h-utg-static/scripts/uniapp_widgets.mjs +244 -0
  824. package/skills/a2h-utg-static/scripts/utg_html.mjs +721 -0
  825. package/skills/a2h-utg-static/scripts/view_interactions.mjs +799 -0
  826. package/skills/a2h-utg-static/scripts/view_widgets.mjs +512 -0
  827. package/skills/a2h-utg-static/scripts/viewpage_nav.mjs +485 -0
  828. package/skills/a2h-utg-static/scripts/vm_nav.mjs +422 -0
  829. package/skills/a2h-utg-static/scripts/window_nav.mjs +240 -0
  830. package/skills/a2h-utg-static/scripts/worklist_parts.mjs +154 -0
  831. package/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +769 -0
  832. package/skills/a2h-utg-static/tools/package.json +3 -0
  833. package/README.md +0 -445
  834. package/agents/logic-coder.md +0 -224
  835. package/agents/logic-context-builder.md +0 -212
  836. package/agents/scripts/hmos-precheck/backends/arkts.mjs +0 -567
  837. package/agents/scripts/hmos-precheck/backends/arkts_diff.mjs +0 -159
  838. package/agents/scripts/hmos-precheck/backends/arkts_project_rules.mjs +0 -398
  839. package/agents/scripts/hmos-precheck/backends/codelinter.mjs +0 -250
  840. package/agents/scripts/hmos-precheck/backends/project_integrity.mjs +0 -321
  841. package/agents/scripts/hmos-precheck/backends/static_precheck.mjs +0 -247
  842. package/agents/scripts/hmos-precheck/core/config.mjs +0 -184
  843. package/agents/scripts/hmos-precheck/core/diagnostic_scope.mjs +0 -20
  844. package/agents/scripts/hmos-precheck/core/process_adapter.mjs +0 -47
  845. package/agents/scripts/hmos-precheck/core/project_catalog.mjs +0 -50
  846. package/agents/scripts/hmos-precheck/core/result_projection.mjs +0 -147
  847. package/agents/scripts/hmos-precheck/core/scope_plan.mjs +0 -131
  848. package/agents/scripts/hmos-precheck/core/sdk_context.mjs +0 -67
  849. package/agents/scripts/hmos-precheck/docs/architecture.md +0 -37
  850. package/agents/scripts/hmos-precheck/docs/performance-optimization.md +0 -28
  851. package/agents/scripts/hmos-precheck/docs/upstream-reference.json +0 -19
  852. package/agents/scripts/hmos-precheck/docs/validation.md +0 -50
  853. package/agents/scripts/hmos-precheck/index.mjs +0 -17
  854. package/agents/scripts/hmos-precheck/invocation.mjs +0 -231
  855. package/agents/scripts/hmos-precheck/rules/rule_case_matrix.csv +0 -32
  856. package/agents/scripts/hmos-precheck/rules/rule_inventory.csv +0 -64
  857. package/agents/scripts/hmos-precheck/rules/rule_inventory.mjs +0 -59
  858. package/agents/scripts/hmos-precheck/rules/rule_policy.mjs +0 -54
  859. package/agents/scripts/platform_query.mjs +0 -626
  860. package/agents/scripts/platform_query.test.mjs +0 -422
  861. package/agents/self-test-fixer.md +0 -298
  862. package/agents/self-tester.md +0 -55
  863. package/agents/test-case-generation-generator.md +0 -317
  864. package/agents/test-case-generation-validator.md +0 -231
  865. package/dist/cli/config-store.js +0 -310
  866. package/dist/cli/config.js +0 -44
  867. package/dist/cli/env-vars.js +0 -127
  868. package/dist/cli/index.js +0 -56
  869. package/dist/cli/init.js +0 -1187
  870. package/dist/cli/uninstall.js +0 -427
  871. package/dist/utils/regex.js +0 -8
  872. package/env-requirements.json +0 -179
  873. package/resource/choose_editor.png +0 -0
  874. package/resource/convert_pipeline_process.svg +0 -103
  875. package/resource/project_architecture.svg +0 -122
  876. package/resource/set_environment.png +0 -0
  877. package/resource/set_multimodel.png +0 -0
  878. package/resource/set_sdk.png +0 -0
  879. package/resource/title_dark.png +0 -0
  880. package/skills/hmos-batch-ui-align/SKILL.md +0 -413
  881. package/skills/hmos-batch-ui-align/scripts/arkts_static_check.ts +0 -1592
  882. package/skills/hmos-batch-ui-align/scripts/measure_pack.ts +0 -752
  883. package/skills/hmos-convert-pipeline/SKILL.md +0 -486
  884. package/skills/hmos-incremental-ui-align/README.md +0 -251
  885. package/skills/hmos-incremental-ui-align/SKILL.md +0 -375
  886. package/skills/hmos-incremental-ui-align/diff_analysis.md +0 -53
  887. package/skills/hmos-incremental-ui-align/page_align.md +0 -62
  888. package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +0 -38
  889. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@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
  890. 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
  891. 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
  892. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@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
  893. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@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
  894. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@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
  895. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@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
  896. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/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
  897. 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
  898. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/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
  899. 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
  900. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/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
  901. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243//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
  902. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +0 -206
  903. 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
  904. 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
  905. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@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
  906. 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
  907. 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
  908. 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
  909. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@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
  910. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@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
  911. 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
  912. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/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
  913. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/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
  914. 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
  915. package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2//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
  916. package/skills/hmos-incremental-ui-align/references/State_Model_Template.md +0 -74
  917. package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +0 -34
  918. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +0 -2533
  919. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +0 -555
  920. package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +0 -117
  921. package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.ts +0 -937
  922. package/skills/hmos-incremental-ui-align/scripts/extract_checklist.ts +0 -343
  923. package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +0 -76
  924. package/skills/hmos-incremental-ui-align/scripts/page_capture.ts +0 -977
  925. package/skills/hmos-incremental-ui-align/scripts/page_capture_burst.ts +0 -188
  926. package/skills/hmos-integration-test/README.md +0 -341
  927. package/skills/hmos-integration-test/SKILL.md +0 -464
  928. package/skills/hmos-integration-test/scripts/report-tool.ts +0 -791
  929. package/skills/hmos-integration-test/scripts/resolve-metadata-tool.ts +0 -125
  930. package/skills/hmos-integration-test/scripts/self-test-runner.ts +0 -756
  931. package/skills/hmos-integration-test/scripts/testcases-tool.ts +0 -239
  932. package/skills/hmos-resources-convert/SKILL.md +0 -891
  933. package/skills/hmos-spec-generate/SKILL.md +0 -404
  934. package/skills/hmos-test-case-generation/README.md +0 -241
  935. package/skills/hmos-test-case-generation/SKILL.md +0 -324
  936. package/skills/hmos-test-case-generation/references/contract.md +0 -315
  937. package/skills/hmos-test-case-generation/references/review-notes-template.md +0 -84
  938. package/skills/hmos-test-case-generation/references/ui-elements-schema.md +0 -142
  939. package/skills/hmos-test-case-generation/tools/convert_to_ui_elements.ts +0 -550
  940. package/skills/hmos-test-case-generation/tools/validate.ts +0 -1312
  941. package/tools/bfs-crawl/README.md +0 -73
  942. package/tools/bfs-crawl/android_viewtree_bfs_crawler.ts +0 -1662
  943. /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} +0 -0
  944. /package/{README.en.md → skills/a2h-arch-generate/scripts/module_create/har/consumer-rules.txt} +0 -0
  945. /package/skills/{hmos-batch-ui-align → a2h-batch-ui-align}/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +0 -0
  946. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  947. /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" +0 -0
  948. /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" +0 -0
  949. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  950. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  951. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  952. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  953. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  954. /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" +0 -0
  955. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  956. /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" +0 -0
  957. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  958. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  959. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  960. /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" +0 -0
  961. /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" +0 -0
  962. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  963. /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" +0 -0
  964. /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" +0 -0
  965. /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" +0 -0
  966. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  967. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  968. /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" +0 -0
  969. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  970. /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" +0 -0
  971. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  972. /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" +0 -0
  973. /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" +0 -0
  974. /package/skills/{hmos-batch-ui-align → 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" +0 -0
  975. /package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/arkts-strict-patterns.md +0 -0
  976. /package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/known-patterns.md +0 -0
  977. /package/skills/{hmos-fix-build-errors → a2h-fix-build-errors}/references/rdb-entity-pattern.md +0 -0
  978. /package/skills/{hmos-resources-convert → a2h-resource-convert}/references/dependency-analysis-rules.md +0 -0
  979. /package/skills/{hmos-resources-convert → a2h-resource-convert}/scripts/svg_fidelity_check.ts +0 -0
  980. /package/skills/{hmos-spec-generate → a2h-spec-generate}/template/REQ.txt +0 -0
  981. /package/skills/{hmos-spec-generate → a2h-spec-generate}/template/REQ.xlsx +0 -0
@@ -0,0 +1,2177 @@
1
+ /**
2
+ * _py.mjs — the ONE shared Python-compat layer of the a2h-utg-explorer Node port.
3
+ * Node >= 22.18, ESM, `node:` builtins only. Every behaviour here mirrors CPython 3.13
4
+ * as used by the original scripts; outputs (JSON text, file bytes, error strings) must
5
+ * stay byte-identical with the Python version.
6
+ *
7
+ * Conventions for ported code:
8
+ * Python dict -> plain object (string keys; insertion order is kept even for
9
+ * integer-like keys when built with jsonLoads/dset), or Map for non-str keys.
10
+ * Dicts keyed by tuples -> Map keyed by tupleKey(...parts).
11
+ * Python set -> Set (strings/numbers); tuple -> array.
12
+ * Python float that is serialised -> PyFloat (asFloat(x)); arithmetic uses valueOf().
13
+ * keyword args -> trailing options object with the ORIGINAL snake_case names.
14
+ *
15
+ * Exports (one line each below at the definition):
16
+ * IS_WIN EOL PyFloat asFloat isFloat floatRepr fmtFixed pyRound pyInt toInt toFloat
17
+ * jsonLoads jsonDumps keysOf dset KEY_ORDER JSONDecodeError
18
+ * pyType truthy or get mget pyEq pyIn pyLen cmpStr pyCmp sortedBy sortedStr pyMax
19
+ * strRepr pyRepr reprTuple pyStr errStr
20
+ * SP pyStrip pyLstrip pyRstrip splitlines pySplit pyRsplit cpLen cpSlice takeCodePoints strHead strTail
21
+ * W WC B NB pyRe reSearch reMatch reFullmatch reFindall reSub reEscape
22
+ * tupleKey dictFromkeys counter
23
+ * readBytes readText writeText appendText decodeReplace atomicWriteText namedTemporaryFile
24
+ * pathStr pJoin pParts pName pSuffix pStem pParent pParents pKey pOrder pEq pResolve pAbsolute
25
+ * pIsFile pIsDir pExists pMkdir pRelativeTo pIsRelativeTo pIterdir pGlob listDirNames
26
+ * Element XmlParseError etParse etFromString
27
+ * time sleep monotonic sha256Hex md5Hex sha256File md5File uuid4 uuid4Hex gettempdir which
28
+ * shlexQuote shlexSplit nfkc htmlEscape
29
+ * TimeoutExpired subprocessRun pidAlive
30
+ * pyPrint pyPrintErr ArgumentParser ArgumentError SUPPRESS textwrapWrap
31
+ */
32
+
33
+ import * as fs from 'node:fs';
34
+ import * as path from 'node:path';
35
+ import * as os from 'node:os';
36
+ import * as crypto from 'node:crypto';
37
+ import { spawnSync } from 'node:child_process';
38
+
39
+ /** True on Windows (text-mode files and stdout translate "\n" -> "\r\n"). */
40
+ export const IS_WIN = process.platform === 'win32';
41
+ /** Line terminator Python's text-mode stdout/files write for "\n". */
42
+ export const EOL = IS_WIN ? '\r\n' : '\n';
43
+
44
+ // ------------------------------------------------------------------ numbers
45
+
46
+ /** A Python float value (keeps `1.0` serialising as `1.0`, not `1`). */
47
+ export class PyFloat {
48
+ constructor(value) { this.value = Number(value); }
49
+ valueOf() { return this.value; }
50
+ toString() { return floatRepr(this.value, false); }
51
+ toJSON() { return this.value; }
52
+ }
53
+
54
+ /** Wrap a JS number as a Python float (for values Python holds as float). */
55
+ export function asFloat(x) { return x instanceof PyFloat ? x : new PyFloat(Number(x)); }
56
+
57
+ /** True when `v` is a Python float (PyFloat or a non-integral JS number). */
58
+ export function isFloat(v) { return v instanceof PyFloat || (typeof v === 'number' && !Number.isInteger(v)); }
59
+
60
+ /** repr(float) (json=false) or json.dumps(float) (json=true): shortest round-trip, 1.0, 1e-07, 1e+16. */
61
+ export function floatRepr(x, json = false) {
62
+ if (!Number.isFinite(x)) {
63
+ if (Number.isNaN(x)) { return json ? 'NaN' : 'nan'; }
64
+ return x > 0 ? (json ? 'Infinity' : 'inf') : (json ? '-Infinity' : '-inf');
65
+ }
66
+ if (x === 0) { return Object.is(x, -0) ? '-0.0' : '0.0'; }
67
+ const [m, e] = Math.abs(x).toExponential().split('e');
68
+ const digits = m.replace('.', '');
69
+ const exp = Number(e);
70
+ let s;
71
+ if (exp >= -4 && exp < 16) {
72
+ if (exp >= 0) {
73
+ const ip = digits.slice(0, exp + 1).padEnd(exp + 1, '0');
74
+ s = ip + '.' + (digits.slice(exp + 1) || '0');
75
+ } else {
76
+ s = '0.' + '0'.repeat(-exp - 1) + digits;
77
+ }
78
+ } else {
79
+ s = digits[0] + (digits.length > 1 ? '.' + digits.slice(1) : '') + 'e' + (exp < 0 ? '-' : '+') +
80
+ String(Math.abs(exp)).padStart(2, '0');
81
+ }
82
+ return (x < 0 ? '-' : '') + s;
83
+ }
84
+
85
+ /** Exact decimal expansion of a finite double: [sign, digitString, pointPosFromRight]. */
86
+ function exactDecimal(x) {
87
+ const dv = new DataView(new ArrayBuffer(8));
88
+ dv.setFloat64(0, x);
89
+ const hi = dv.getUint32(0); const lo = dv.getUint32(4);
90
+ const neg = (hi >>> 31) === 1;
91
+ const ex = (hi >>> 20) & 0x7ff;
92
+ let mant = (BigInt(hi & 0xfffff) << 32n) | BigInt(lo);
93
+ let e;
94
+ if (ex === 0) { e = -1074; } else { mant |= 1n << 52n; e = ex - 1075; }
95
+ if (e >= 0) { return [neg, (mant << BigInt(e)).toString(), 0]; }
96
+ return [neg, (mant * 5n ** BigInt(-e)).toString(), -e];
97
+ }
98
+
99
+ /** '%.{d}f' % x — correctly rounded, ties-to-even on the exact binary value (Python, not JS toFixed). */
100
+ export function fmtFixed(x, d = 6) {
101
+ x = Number(x);
102
+ if (Number.isNaN(x)) { return 'nan'; }
103
+ if (!Number.isFinite(x)) { return x > 0 ? 'inf' : '-inf'; }
104
+ const [neg, digs, point] = exactDecimal(x);
105
+ let intDigits; let frac;
106
+ if (point === 0) { intDigits = digs; frac = ''; } else {
107
+ const padded = digs.padStart(point + 1, '0');
108
+ intDigits = padded.slice(0, padded.length - point); frac = padded.slice(padded.length - point);
109
+ }
110
+ let keep = BigInt(intDigits + frac.slice(0, d).padEnd(d, '0'));
111
+ const rest = frac.slice(d);
112
+ if (rest.length) {
113
+ const first = rest.charCodeAt(0) - 48;
114
+ const tail = /[1-9]/.test(rest.slice(1));
115
+ if (first > 5 || (first === 5 && (tail || (keep & 1n) === 1n))) { keep += 1n; }
116
+ }
117
+ let s = keep.toString().padStart(d + 1, '0');
118
+ if (d > 0) { s = s.slice(0, s.length - d) + '.' + s.slice(s.length - d); }
119
+ return (neg ? '-' : '') + s;
120
+ }
121
+
122
+ /** round(x, n) for a float (correctly rounded, ties-to-even); returns a JS number. */
123
+ export function pyRound(x, n = 0) {
124
+ return Number(fmtFixed(Number(x), Math.max(0, n)));
125
+ }
126
+
127
+ /** int() of a regex `\d+` match (Unicode Nd digits); BigInt when beyond 2**53. */
128
+ export function pyInt(digits) {
129
+ let s = '';
130
+ let sign = '';
131
+ for (const ch of String(digits)) {
132
+ if (ch === '-' && !s) { sign = '-'; continue; }
133
+ if (ch === '+' && !s) { continue; }
134
+ let cp = ch.codePointAt(0);
135
+ let k = 0;
136
+ while (/\p{Nd}/u.test(String.fromCodePoint(cp - 1))) { cp--; k++; }
137
+ s += String(k % 10);
138
+ }
139
+ const n = Number(sign + s);
140
+ return Number.isSafeInteger(n) ? (n === 0 ? 0 : n) : BigInt(sign + s);
141
+ }
142
+
143
+ /** int(x): bool->0/1, float truncates, str parsed strictly; ValueError text as Python. */
144
+ export function toInt(x) {
145
+ if (typeof x === 'boolean') { return x ? 1 : 0; }
146
+ if (typeof x === 'bigint') { return x; }
147
+ if (x instanceof PyFloat || typeof x === 'number') {
148
+ const v = Number(x);
149
+ if (Number.isNaN(v)) { throw new PyValueError('cannot convert float NaN to integer'); }
150
+ if (!Number.isFinite(v)) { throw new PyOverflowError('cannot convert float infinity to integer'); }
151
+ return Math.trunc(v) || 0;
152
+ }
153
+ if (typeof x === 'string') {
154
+ const t = pyStrip(x);
155
+ if (/^[+-]?\p{Nd}+(?:_\p{Nd}+)*$/u.test(t)) { return pyInt(t.replace(/_/g, '')); }
156
+ throw new PyValueError(`invalid literal for int() with base 10: ${strRepr(x)}`);
157
+ }
158
+ if (x === null || x === undefined) {
159
+ throw new PyTypeError("int() argument must be a string, a bytes-like object or a real number, not 'NoneType'");
160
+ }
161
+ throw new PyTypeError(`int() argument must be a string, a bytes-like object or a real number, not '${pyType(x)}'`);
162
+ }
163
+
164
+ /** float(x) as a JS number; ValueError text as Python for bad strings. */
165
+ export function toFloat(x) {
166
+ if (typeof x === 'boolean') { return x ? 1 : 0; }
167
+ if (x instanceof PyFloat || typeof x === 'number' || typeof x === 'bigint') { return Number(x); }
168
+ if (typeof x === 'string') {
169
+ const t = pyStrip(x).replace(/(\d)_(?=\d)/g, '$1');
170
+ const low = t.toLowerCase();
171
+ if (/^[+-]?(inf|infinity)$/.test(low)) { return low.startsWith('-') ? -Infinity : Infinity; }
172
+ if (/^[+-]?nan$/.test(low)) { return NaN; }
173
+ if (/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i.test(t)) { return Number(t); }
174
+ throw new PyValueError(`could not convert string to float: ${strRepr(x)}`);
175
+ }
176
+ if (x === null || x === undefined) {
177
+ throw new PyTypeError("float() argument must be a string or a real number, not 'NoneType'");
178
+ }
179
+ throw new PyTypeError(`float() argument must be a string or a real number, not '${pyType(x)}'`);
180
+ }
181
+
182
+ /** Python ValueError / TypeError / OverflowError / KeyError look-alikes (errStr gives str(exc)). */
183
+ export class PyValueError extends Error { constructor(m) { super(m); this.name = 'ValueError'; } }
184
+ export class PyTypeError extends Error { constructor(m) { super(m); this.name = 'TypeError'; } }
185
+ export class PyOverflowError extends Error { constructor(m) { super(m); this.name = 'OverflowError'; } }
186
+ export class PyKeyError extends Error {
187
+ constructor(key) { super(pyRepr(key)); this.name = 'KeyError'; this.key = key; }
188
+ }
189
+
190
+ // ------------------------------------------------------------------ json
191
+
192
+ /** Symbol under which jsonLoads/dset record key order when integer-like keys are present. */
193
+ export const KEY_ORDER = Symbol('pyKeyOrder');
194
+ const INDEX_KEY = /^(?:0|[1-9][0-9]*)$/;
195
+
196
+ /** json.JSONDecodeError: message "<msg>: line L column C (char P)". */
197
+ export class JSONDecodeError extends PyValueError {
198
+ constructor(msg, doc, pos) {
199
+ const lineno = doc.slice(0, pos).split('\n').length;
200
+ const colno = pos - (doc.lastIndexOf('\n', pos - 1) + 1) + 1;
201
+ super(`${msg}: line ${lineno} column ${colno} (char ${pos})`);
202
+ this.name = 'JSONDecodeError'; this.msg = msg; this.pos = pos; this.lineno = lineno; this.colno = colno;
203
+ }
204
+ }
205
+
206
+ /**
207
+ * json.loads(text): objects keep Python insertion order (incl. integer-like keys, see keysOf);
208
+ * integral floats (`1.0`) -> PyFloat, other floats -> number, ints beyond 2**53 -> BigInt.
209
+ */
210
+ export function jsonLoads(text) {
211
+ if (typeof text !== 'string') { text = new TextDecoder('utf-8').decode(text); }
212
+ let i = 0;
213
+ const n = text.length;
214
+ const fail = (msg, at = i) => { throw new JSONDecodeError(msg, text, at); };
215
+ const ws = () => {
216
+ while (i < n) {
217
+ const c = text.charCodeAt(i);
218
+ if (c === 0x20 || c === 0x09 || c === 0x0a || c === 0x0d) { i++; } else { break; }
219
+ }
220
+ };
221
+ const NUM = /(-?(?:0|[1-9][0-9]*))(\.[0-9]+)?([eE][-+]?[0-9]+)?/y;
222
+ const str = () => {
223
+ const begin = i;
224
+ i++;
225
+ let out = '';
226
+ let start = i;
227
+ for (;;) {
228
+ if (i >= n) { fail('Unterminated string starting at', begin); }
229
+ const c = text.charCodeAt(i);
230
+ if (c === 0x22) { out += text.slice(start, i); i++; return out; }
231
+ if (c < 0x20) { fail('Invalid control character at'); }
232
+ if (c === 0x5c) {
233
+ out += text.slice(start, i);
234
+ const esc = text[i + 1];
235
+ const simple = { '"': '"', '\\': '\\', '/': '/', b: '\b', f: '\f', n: '\n', r: '\r', t: '\t' }[esc];
236
+ if (simple !== undefined) {
237
+ out += simple; i += 2;
238
+ } else if (esc === 'u') {
239
+ const hex = text.slice(i + 2, i + 6);
240
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) { fail('Invalid \\uXXXX escape', i + 1); }
241
+ out += String.fromCharCode(parseInt(hex, 16));
242
+ i += 6;
243
+ } else {
244
+ if (esc === undefined) { fail('Unterminated string starting at', begin); }
245
+ fail('Invalid \\escape', i);
246
+ }
247
+ start = i;
248
+ continue;
249
+ }
250
+ i++;
251
+ }
252
+ };
253
+ const value = () => {
254
+ const c = text[i];
255
+ if (c === '{') {
256
+ i++;
257
+ const o = {};
258
+ const order = [];
259
+ let hasIndex = false;
260
+ ws();
261
+ if (text[i] === '}') { i++; return o; }
262
+ for (;;) {
263
+ if (text[i] !== '"') { fail('Expecting property name enclosed in double quotes'); }
264
+ const k = str();
265
+ ws();
266
+ if (text[i] !== ':') { fail("Expecting ':' delimiter"); }
267
+ i++;
268
+ ws();
269
+ if (i >= n) { fail('Expecting value'); }
270
+ const v = value();
271
+ if (!Object.hasOwn(o, k)) {
272
+ order.push(k);
273
+ if (INDEX_KEY.test(k)) { hasIndex = true; }
274
+ }
275
+ if (k === '__proto__') {
276
+ Object.defineProperty(o, k, { value: v, enumerable: true, writable: true, configurable: true });
277
+ } else { o[k] = v; }
278
+ ws();
279
+ if (text[i] === ',') { i++; ws(); continue; }
280
+ if (text[i] === '}') { i++; break; }
281
+ fail("Expecting ',' delimiter");
282
+ }
283
+ if (hasIndex) { Object.defineProperty(o, KEY_ORDER, { value: order, writable: true, configurable: true }); }
284
+ return o;
285
+ }
286
+ if (c === '[') {
287
+ i++;
288
+ const a = [];
289
+ ws();
290
+ if (text[i] === ']') { i++; return a; }
291
+ for (;;) {
292
+ if (i >= n) { fail('Expecting value'); }
293
+ a.push(value());
294
+ ws();
295
+ if (text[i] === ',') { i++; ws(); continue; }
296
+ if (text[i] === ']') { i++; break; }
297
+ fail("Expecting ',' delimiter");
298
+ }
299
+ return a;
300
+ }
301
+ if (c === '"') { return str(); }
302
+ if (text.startsWith('null', i)) { i += 4; return null; }
303
+ if (text.startsWith('true', i)) { i += 4; return true; }
304
+ if (text.startsWith('false', i)) { i += 5; return false; }
305
+ if (text.startsWith('NaN', i)) { i += 3; return NaN; }
306
+ if (text.startsWith('Infinity', i)) { i += 8; return Infinity; }
307
+ if (text.startsWith('-Infinity', i)) { i += 9; return -Infinity; }
308
+ NUM.lastIndex = i;
309
+ const m = NUM.exec(text);
310
+ if (!m) { fail('Expecting value'); }
311
+ i += m[0].length;
312
+ if (m[2] !== undefined || m[3] !== undefined) {
313
+ const f = Number(m[0]);
314
+ return Number.isInteger(f) ? new PyFloat(f) : f;
315
+ }
316
+ const num = Number(m[0]);
317
+ return Number.isSafeInteger(num) ? (num === 0 ? 0 : num) : BigInt(m[0]);
318
+ };
319
+ ws();
320
+ if (i >= n) { fail('Expecting value'); }
321
+ const v = value();
322
+ ws();
323
+ if (i !== n) { fail('Extra data'); }
324
+ return v;
325
+ }
326
+
327
+ /** Keys of a dict-like object in Python insertion order (honours KEY_ORDER). */
328
+ export function keysOf(o) {
329
+ if (o instanceof Map) { return [...o.keys()]; }
330
+ const ks = Object.keys(o);
331
+ const ord = o[KEY_ORDER];
332
+ if (!ord) { return ks; }
333
+ const present = new Set(ks);
334
+ const out = ord.filter((k) => present.has(k));
335
+ const seen = new Set(out);
336
+ for (const k of ks) { if (!seen.has(k)) { out.push(k); } }
337
+ return out;
338
+ }
339
+
340
+ /** d[k] = v keeping Python insertion order even for integer-like keys. Returns v. */
341
+ export function dset(o, k, v) {
342
+ k = String(k);
343
+ if (!Object.hasOwn(o, k)) {
344
+ let ord = o[KEY_ORDER];
345
+ if (!ord && INDEX_KEY.test(k)) {
346
+ ord = Object.keys(o);
347
+ Object.defineProperty(o, KEY_ORDER, { value: ord, writable: true, configurable: true });
348
+ }
349
+ if (ord) { ord.push(k); }
350
+ }
351
+ if (k === '__proto__') {
352
+ Object.defineProperty(o, k, { value: v, enumerable: true, writable: true, configurable: true });
353
+ } else { o[k] = v; }
354
+ return v;
355
+ }
356
+
357
+ function jsonStr(s, ensureAscii) {
358
+ let r = '"';
359
+ for (let j = 0; j < s.length; j++) {
360
+ const c = s.charCodeAt(j);
361
+ const ch = s[j];
362
+ if (ch === '"') { r += '\\"'; } else if (ch === '\\') { r += '\\\\'; }
363
+ else if (ch === '\n') { r += '\\n'; } else if (ch === '\r') { r += '\\r'; } else if (ch === '\t') { r += '\\t'; }
364
+ else if (ch === '\b') { r += '\\b'; } else if (ch === '\f') { r += '\\f'; }
365
+ else if (c < 0x20 || (ensureAscii && c > 0x7e)) { r += '\\u' + c.toString(16).padStart(4, '0'); }
366
+ else { r += ch; }
367
+ }
368
+ return r + '"';
369
+ }
370
+
371
+ function jsonKey(k) {
372
+ if (typeof k === 'string') { return k; }
373
+ if (k === null || k === undefined) { return 'null'; }
374
+ if (k === true) { return 'true'; }
375
+ if (k === false) { return 'false'; }
376
+ if (k instanceof PyFloat) { return floatRepr(k.value, true); }
377
+ if (typeof k === 'number') { return Number.isInteger(k) ? String(k) : floatRepr(k, true); }
378
+ if (typeof k === 'bigint') { return String(k); }
379
+ throw new PyTypeError(`keys must be str, int, float, bool or None, not ${pyType(k)}`);
380
+ }
381
+
382
+ /**
383
+ * json.dumps(v, {indent, ensure_ascii=true, separators, sort_keys=false}). Map = dict (any keys),
384
+ * Set is rejected like Python; undefined = None.
385
+ */
386
+ export function jsonDumps(v, opts = {}) {
387
+ const indent = opts.indent ?? null;
388
+ const ensureAscii = opts.ensure_ascii ?? true;
389
+ const [itemSep, keySep] = opts.separators ?? (indent === null ? [', ', ': '] : [',', ': ']);
390
+ const sortKeys = !!opts.sort_keys;
391
+ const ind = typeof indent === 'string' ? indent : indent === null ? null : ' '.repeat(indent);
392
+ const enc = (x, level) => {
393
+ if (x === null || x === undefined) { return 'null'; }
394
+ if (x === true) { return 'true'; }
395
+ if (x === false) { return 'false'; }
396
+ if (typeof x === 'bigint') { return x.toString(); }
397
+ if (x instanceof PyFloat) { return floatRepr(x.value, true); }
398
+ if (typeof x === 'number') {
399
+ return Number.isInteger(x) ? (Object.is(x, -0) ? '0' : String(x)) : floatRepr(x, true);
400
+ }
401
+ if (typeof x === 'string') { return jsonStr(x, ensureAscii); }
402
+ if (x instanceof Set) { throw new PyTypeError('Object of type set is not JSON serializable'); }
403
+ let entries; let open; let close;
404
+ if (Array.isArray(x)) {
405
+ if (x.length === 0) { return '[]'; }
406
+ entries = x.map((y) => enc(y, level + 1)); open = '['; close = ']';
407
+ } else if (typeof x === 'object') {
408
+ let pairs = x instanceof Map ? [...x].map(([k, y]) => [jsonKey(k), y]) : keysOf(x).map((k) => [k, x[k]]);
409
+ if (pairs.length === 0) { return '{}'; }
410
+ if (sortKeys) { pairs = sortedBy(pairs, (p) => p[0]); }
411
+ entries = pairs.map(([k, y]) => jsonStr(k, ensureAscii) + keySep + enc(y, level + 1)); open = '{'; close = '}';
412
+ } else {
413
+ throw new PyTypeError(`Object of type ${typeof x} is not JSON serializable`);
414
+ }
415
+ if (ind === null) { return open + entries.join(itemSep) + close; }
416
+ const pad = '\n' + ind.repeat(level + 1);
417
+ return open + pad + entries.join(itemSep + pad) + '\n' + ind.repeat(level) + close;
418
+ };
419
+ return enc(v, 0);
420
+ }
421
+
422
+ // ------------------------------------------------------------------ value semantics
423
+
424
+ /** type(v).__name__ for json-ish values. */
425
+ export function pyType(v) {
426
+ if (v === null || v === undefined) { return 'NoneType'; }
427
+ if (typeof v === 'boolean') { return 'bool'; }
428
+ if (typeof v === 'number') { return Number.isInteger(v) ? 'int' : 'float'; }
429
+ if (typeof v === 'bigint') { return 'int'; }
430
+ if (v instanceof PyFloat) { return 'float'; }
431
+ if (typeof v === 'string') { return 'str'; }
432
+ if (Array.isArray(v)) { return 'list'; }
433
+ if (v instanceof Set) { return 'set'; }
434
+ return 'dict';
435
+ }
436
+
437
+ /** bool(v). */
438
+ export function truthy(v) {
439
+ if (v === null || v === undefined || v === false) { return false; }
440
+ if (v === true) { return true; }
441
+ if (typeof v === 'number') { return v !== 0 && !Number.isNaN(v) ? true : Number.isNaN(v); }
442
+ if (typeof v === 'bigint') { return v !== 0n; }
443
+ if (v instanceof PyFloat) { return v.value !== 0; }
444
+ if (typeof v === 'string' || Array.isArray(v)) { return v.length > 0; }
445
+ if (v instanceof Map || v instanceof Set) { return v.size > 0; }
446
+ if (typeof v === 'function') { return true; }
447
+ return Object.keys(v).length > 0;
448
+ }
449
+
450
+ /** Python `a or b` (b may be a thunk: pass a function to defer evaluation). */
451
+ export function or(a, b) { return truthy(a) ? a : (typeof b === 'function' ? b() : b); }
452
+
453
+ /** d.get(k, dflt): dflt only when the key is absent (a stored null is returned). dflt defaults to null. */
454
+ export function get(d, k, dflt = null) {
455
+ if (d instanceof Map) { return d.has(k) ? d.get(k) : dflt; }
456
+ return d !== null && typeof d === 'object' && !Array.isArray(d) && Object.hasOwn(d, k) ? d[k] : dflt;
457
+ }
458
+
459
+ /** d[k] on a dict; throws PyKeyError when missing (str(exc) == repr(key)). */
460
+ export function mget(d, k) {
461
+ if (d instanceof Map) { if (d.has(k)) { return d.get(k); } throw new PyKeyError(k); }
462
+ if (d === null || d === undefined) { throw new PyTypeError("'NoneType' object is not subscriptable"); }
463
+ if (Object.hasOwn(d, k)) { return d[k]; }
464
+ throw new PyKeyError(k);
465
+ }
466
+
467
+ function numOf(v) {
468
+ if (typeof v === 'boolean') { return v ? 1 : 0; }
469
+ if (v instanceof PyFloat) { return v.value; }
470
+ if (typeof v === 'number' || typeof v === 'bigint') { return v; }
471
+ return undefined;
472
+ }
473
+
474
+ /** Python `==` for json-ish values (1 == 1.0 == True; list/dict deep; undefined == None). */
475
+ export function pyEq(a, b) {
476
+ if (a === undefined) { a = null; }
477
+ if (b === undefined) { b = null; }
478
+ const na = numOf(a); const nb = numOf(b);
479
+ if (na !== undefined && nb !== undefined) { return na == nb; } // eslint-disable-line eqeqeq
480
+ if (na !== undefined || nb !== undefined) { return false; }
481
+ if (a === null || b === null || typeof a === 'string' || typeof b === 'string') { return a === b; }
482
+ if (Array.isArray(a) || Array.isArray(b)) {
483
+ return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((x, i) => pyEq(x, b[i]));
484
+ }
485
+ if (a instanceof Set || b instanceof Set) {
486
+ return a instanceof Set && b instanceof Set && a.size === b.size && [...a].every((x) => b.has(x));
487
+ }
488
+ const ka = keysOf(a); const kb = keysOf(b);
489
+ if (ka.length !== kb.length) { return false; }
490
+ return ka.every((k) => (b instanceof Map ? b.has(k) : Object.hasOwn(b, k)) &&
491
+ pyEq(a instanceof Map ? a.get(k) : a[k], b instanceof Map ? b.get(k) : b[k]));
492
+ }
493
+
494
+ /** Python `x in c`: list -> ==, str -> substring, dict -> key, Set/Map -> has. */
495
+ export function pyIn(x, c) {
496
+ if (typeof c === 'string') {
497
+ if (typeof x !== 'string') { throw new PyTypeError(`'in <string>' requires string as left operand, not ${pyType(x)}`); }
498
+ return c.includes(x);
499
+ }
500
+ if (Array.isArray(c)) { return c.some((y) => pyEq(x, y)); }
501
+ if (c instanceof Set || c instanceof Map) { return c.has(x); }
502
+ if (c !== null && typeof c === 'object') { return typeof x === 'string' && Object.hasOwn(c, x); }
503
+ throw new PyTypeError(`argument of type '${pyType(c)}' is not iterable`);
504
+ }
505
+
506
+ /** len(v) (str counts code points). */
507
+ export function pyLen(v) {
508
+ if (typeof v === 'string') { return cpLen(v); }
509
+ if (Array.isArray(v)) { return v.length; }
510
+ if (v instanceof Map || v instanceof Set) { return v.size; }
511
+ if (v !== null && typeof v === 'object' && !(v instanceof PyFloat)) { return Object.keys(v).length; }
512
+ throw new PyTypeError(`object of type '${pyType(v)}' has no len()`);
513
+ }
514
+
515
+ /** str `<` by code point (JS compares UTF-16 units; differs only with astral chars). */
516
+ export function cmpStr(a, b) {
517
+ if (!/[\uD800-\uDFFF]/.test(a) && !/[\uD800-\uDFFF]/.test(b)) { return a < b ? -1 : a > b ? 1 : 0; }
518
+ const x = [...a]; const y = [...b];
519
+ for (let i = 0; i < Math.min(x.length, y.length); i++) {
520
+ const d = x[i].codePointAt(0) - y[i].codePointAt(0);
521
+ if (d !== 0) { return d < 0 ? -1 : 1; }
522
+ }
523
+ return x.length < y.length ? -1 : x.length > y.length ? 1 : 0;
524
+ }
525
+
526
+ /** Python ordering for sort keys: numbers/bools, str by code point, tuples/lists element-wise; TypeError otherwise. */
527
+ export function pyCmp(a, b) {
528
+ const na = numOf(a); const nb = numOf(b);
529
+ if (na !== undefined && nb !== undefined) { return na < nb ? -1 : na > nb ? 1 : 0; }
530
+ if (typeof a === 'string' && typeof b === 'string') { return cmpStr(a, b); }
531
+ if (Array.isArray(a) && Array.isArray(b)) {
532
+ for (let i = 0; i < Math.min(a.length, b.length); i++) {
533
+ if (!pyEq(a[i], b[i])) { return pyCmp(a[i], b[i]); }
534
+ }
535
+ return a.length < b.length ? -1 : a.length > b.length ? 1 : 0;
536
+ }
537
+ if (a instanceof Set && b instanceof Set) { // subset order is partial; only used for `>=`
538
+ const sub = [...a].every((x) => b.has(x)); const sup = [...b].every((x) => a.has(x));
539
+ return sub && sup ? 0 : sub ? -1 : sup ? 1 : NaN;
540
+ }
541
+ throw new PyTypeError(`'<' not supported between instances of '${pyType(a)}' and '${pyType(b)}'`);
542
+ }
543
+
544
+ /** sorted(items, key=key, reverse=reverse) — stable, Python comparison (reverse keeps stability like CPython). */
545
+ export function sortedBy(items, key = (x) => x, reverse = false) {
546
+ const dec = [...items].map((v, i) => [key(v), i, v]);
547
+ dec.sort((p, q) => (reverse ? pyCmp(q[0], p[0]) : pyCmp(p[0], q[0])) || p[1] - q[1]);
548
+ return dec.map((d) => d[2]);
549
+ }
550
+
551
+ /** sorted(iterable_of_str) by code point. */
552
+ export function sortedStr(items) { return [...items].sort(cmpStr); }
553
+
554
+ /** max(items, key=key): first maximal element (Python keeps the first on ties); default when empty. */
555
+ export function pyMax(items, key = (x) => x, dflt = undefined) {
556
+ let best; let bk; let first = true;
557
+ for (const it of items) {
558
+ const k = key(it);
559
+ if (first || pyCmp(k, bk) > 0) { best = it; bk = k; first = false; }
560
+ }
561
+ if (first) {
562
+ if (dflt !== undefined) { return dflt; }
563
+ throw new PyValueError('max() iterable argument is empty');
564
+ }
565
+ return best;
566
+ }
567
+
568
+ // ------------------------------------------------------------------ repr / str
569
+
570
+ const NON_PRINTABLE = /[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Zl}\p{Zp}\p{Zs}]/u;
571
+
572
+ /** repr(str). */
573
+ export function strRepr(s) {
574
+ const q = s.includes("'") && !s.includes('"') ? '"' : "'";
575
+ let r = q;
576
+ for (const ch of s) {
577
+ const cp = ch.codePointAt(0);
578
+ if (ch === q || ch === '\\') { r += '\\' + ch; }
579
+ else if (ch === '\t') { r += '\\t'; } else if (ch === '\n') { r += '\\n'; } else if (ch === '\r') { r += '\\r'; }
580
+ else if (ch !== ' ' && NON_PRINTABLE.test(ch)) {
581
+ r += cp < 0x100 ? '\\x' + cp.toString(16).padStart(2, '0')
582
+ : cp < 0x10000 ? '\\u' + cp.toString(16).padStart(4, '0') : '\\U' + cp.toString(16).padStart(8, '0');
583
+ } else { r += ch; }
584
+ }
585
+ return r + q;
586
+ }
587
+
588
+ /** repr(v): None/True/False, float repr, str quoting, list [..], dict {..}, Set {..} (insertion order). */
589
+ export function pyRepr(v) {
590
+ if (v === null || v === undefined) { return 'None'; }
591
+ if (v === true) { return 'True'; }
592
+ if (v === false) { return 'False'; }
593
+ if (typeof v === 'bigint') { return v.toString(); }
594
+ if (v instanceof PyFloat) { return floatRepr(v.value, false); }
595
+ if (typeof v === 'number') { return Number.isInteger(v) ? String(v === 0 ? 0 : v) : floatRepr(v, false); }
596
+ if (typeof v === 'string') { return strRepr(v); }
597
+ if (Array.isArray(v)) { return '[' + v.map(pyRepr).join(', ') + ']'; }
598
+ if (v instanceof Set) { return v.size ? '{' + [...v].map(pyRepr).join(', ') + '}' : 'set()'; }
599
+ if (v instanceof Map) { return '{' + [...v].map(([k, x]) => pyRepr(k) + ': ' + pyRepr(x)).join(', ') + '}'; }
600
+ return '{' + keysOf(v).map((k) => strRepr(k) + ': ' + pyRepr(v[k])).join(', ') + '}';
601
+ }
602
+
603
+ /** repr(tuple(items)): `(a,)` for one element. */
604
+ export function reprTuple(items) {
605
+ return items.length === 1 ? '(' + pyRepr(items[0]) + ',)' : '(' + items.map(pyRepr).join(', ') + ')';
606
+ }
607
+
608
+ /** str(v) / f"{v}". */
609
+ export function pyStr(v) { return typeof v === 'string' ? v : pyRepr(v); }
610
+
611
+ /** str(exc) for a caught JS/Python-like exception (KeyError -> repr(key), others -> message). */
612
+ export function errStr(e) {
613
+ if (e instanceof PyKeyError) { return pyRepr(e.key); }
614
+ if (e && typeof e === 'object' && 'message' in e) { return String(e.message); }
615
+ return String(e);
616
+ }
617
+
618
+ // ------------------------------------------------------------------ str helpers
619
+
620
+ /** Character class body of Python str.isspace() (= `\s` of str regexes and strip()). */
621
+ export const SP = '\\t\\n\\v\\f\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000';
622
+ const charsClass = (chars) => '[' + [...chars].map((c) => c.replace(/[\\\]^-]/g, '\\$&')).join('') + ']';
623
+
624
+ /** s.strip(chars=None). */
625
+ export function pyStrip(s, chars = null) {
626
+ const c = chars === null ? `[${SP}]` : charsClass(chars);
627
+ return chars === '' ? s : s.replace(new RegExp(`^${c}+|${c}+$`, 'gu'), '');
628
+ }
629
+ /** s.lstrip(chars=None). */
630
+ export function pyLstrip(s, chars = null) {
631
+ const c = chars === null ? `[${SP}]` : charsClass(chars);
632
+ return chars === '' ? s : s.replace(new RegExp(`^${c}+`, 'u'), '');
633
+ }
634
+ /** s.rstrip(chars=None). */
635
+ export function pyRstrip(s, chars = null) {
636
+ const c = chars === null ? `[${SP}]` : charsClass(chars);
637
+ return chars === '' ? s : s.replace(new RegExp(`${c}+$`, 'u'), '');
638
+ }
639
+
640
+ const LINE_BREAK = new RegExp('\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]');
641
+
642
+ /** s.splitlines(keepends=false). */
643
+ export function splitlines(s) {
644
+ if (s === '') { return []; }
645
+ const parts = s.split(LINE_BREAK);
646
+ if (parts[parts.length - 1] === '') { parts.pop(); }
647
+ return parts;
648
+ }
649
+
650
+ /** s.split(sep=None, maxsplit=-1). */
651
+ export function pySplit(s, sep = null, maxsplit = -1) {
652
+ if (sep === null) {
653
+ const out = [];
654
+ const re = new RegExp(`[^${SP}]+`, 'gu');
655
+ let m;
656
+ while ((m = re.exec(s)) !== null) {
657
+ if (maxsplit >= 0 && out.length === maxsplit) {
658
+ out.push(pyLstrip(s.slice(m.index)));
659
+ return out;
660
+ }
661
+ out.push(m[0]);
662
+ }
663
+ return out;
664
+ }
665
+ if (sep === '') { throw new PyValueError('empty separator'); }
666
+ if (maxsplit < 0) { return s.split(sep); }
667
+ const out = [];
668
+ let rest = s;
669
+ while (out.length < maxsplit) {
670
+ const i = rest.indexOf(sep);
671
+ if (i < 0) { break; }
672
+ out.push(rest.slice(0, i)); rest = rest.slice(i + sep.length);
673
+ }
674
+ out.push(rest);
675
+ return out;
676
+ }
677
+
678
+ /** s.rsplit(sep, maxsplit=-1) for an explicit sep. */
679
+ export function pyRsplit(s, sep, maxsplit = -1) {
680
+ if (maxsplit < 0) { return s.split(sep); }
681
+ const out = [];
682
+ let rest = s;
683
+ while (out.length < maxsplit) {
684
+ const i = rest.lastIndexOf(sep);
685
+ if (i < 0) { break; }
686
+ out.unshift(rest.slice(i + sep.length)); rest = rest.slice(0, i);
687
+ }
688
+ out.unshift(rest);
689
+ return out;
690
+ }
691
+
692
+ /** len(str) in code points. */
693
+ export function cpLen(s) { let n = 0; for (const _ of s) { n++; } return n; } // eslint-disable-line no-unused-vars
694
+
695
+ /** s[start:end] in code points (negative indices as Python; end may be undefined). */
696
+ export function cpSlice(s, start = 0, end = undefined) {
697
+ if (!/[\uD800-\uDFFF]/.test(s)) { return s.slice(start, end); }
698
+ return [...s].slice(start, end).join('');
699
+ }
700
+ /** s[:n] in code points. */
701
+ export function takeCodePoints(s, n) { return cpSlice(s, 0, n); }
702
+ /** s[:n] in code points. */
703
+ export function strHead(s, n) { return cpSlice(s, 0, n); }
704
+ /** s[-n:] in code points (n > 0). */
705
+ export function strTail(s, n) { return n <= 0 ? s : cpSlice(s, -n); }
706
+
707
+ // ------------------------------------------------------------------ regex
708
+ // Python `re` on str is Unicode-aware: \w = [\p{L}\p{N}_] (approximately: str.isalnum() + '_'),
709
+ // \d = \p{Nd}, \s = str.isspace(), \b is built on that \w. JS `\w`/`\d`/`\b` are ASCII-only even
710
+ // with the 'u' flag, so ported patterns that may see non-ASCII text use W/WC/B below via pyRe().
711
+ // `$` in Python (no MULTILINE) also matches before a final "\n"; fullmatch needs ^(?:...)$ in JS.
712
+ // `re.S` = JS 's'; `re.I` = 'i'; `re.M` ^/$ break only on "\n" in Python (JS also on \r, LS).
713
+
714
+ /** Python `\w` as a JS class: [\p{L}\p{N}_]. */
715
+ export const W = '[\\p{L}\\p{N}_]';
716
+ /** Body of the `\w` class for embedding: \p{L}\p{N}_ */
717
+ export const WC = '\\p{L}\\p{N}_';
718
+ /** Python `\b` (Unicode word boundary). */
719
+ export const B = `(?:(?<=${W})(?!${W})|(?<!${W})(?=${W}))`;
720
+ /** Python `\B`. */
721
+ export const NB = `(?:(?<=${W})(?=${W})|(?<!${W})(?!${W}))`;
722
+
723
+ /**
724
+ * Compile a Python-syntax str pattern to a JS RegExp with Python Unicode semantics for
725
+ * \w \W \d \D \s \S \b \B (outside and inside character classes). flags: JS flags ('u' added).
726
+ */
727
+ export function pyRe(pattern, flags = '') {
728
+ let out = '';
729
+ let inClass = false;
730
+ for (let i = 0; i < pattern.length; i++) {
731
+ const c = pattern[i];
732
+ if (c === '\\' && i + 1 < pattern.length) {
733
+ const e = pattern[i + 1];
734
+ i++;
735
+ const map = inClass
736
+ ? { w: WC, d: '\\p{Nd}', s: SP }
737
+ : { w: W, W: `[^${WC}]`, d: '\\p{Nd}', D: '\\P{Nd}', s: `[${SP}]`, S: `[^${SP}]`, b: B, B: NB, Z: '$(?![\\s\\S])', A: '^' };
738
+ if (map[e] !== undefined) { out += map[e]; continue; }
739
+ if (inClass && (e === 'W' || e === 'D' || e === 'S')) { throw new Error('negated class escape inside [] unsupported: \\' + e); }
740
+ if (/[A-Za-z0-9]/.test(e) || /[\\.^$|?*+()[\]{}/]/.test(e) || (inClass && e === '-')) { out += '\\' + e; continue; }
741
+ out += e === '-' ? '\\x2d' : e; // Python allows `\"`, `\'`, `\ ` ...; 'u' mode JS does not
742
+ continue;
743
+ }
744
+ if (inClass) { if (c === ']' && pattern[i - 1] !== '[' && pattern.slice(i - 2, i) !== '[^') { inClass = false; } out += c; continue; }
745
+ if (c === '[') { inClass = true; out += c; continue; }
746
+ if (c === '$' && !flags.includes('m')) { out += '(?=\\n?$)'; continue; } // Python `$`: end or before final \n
747
+ if (c === '.' && !flags.includes('s')) { out += '[^\\n]'; continue; } // Python `.` excludes only \n
748
+ if (c === '(' && pattern.startsWith('(?P<', i)) { out += '(?<'; i += 3; continue; }
749
+ if (c === '(' && pattern.startsWith('(?P=', i)) {
750
+ const j = pattern.indexOf(')', i); out += '\\k<' + pattern.slice(i + 4, j) + '>'; i = j; continue;
751
+ }
752
+ out += c;
753
+ }
754
+ return new RegExp(out, flags.includes('u') || flags.includes('v') ? flags : flags + 'u');
755
+ }
756
+
757
+ const asRe = (p, flags) => (p instanceof RegExp ? p : pyRe(p, flags));
758
+
759
+ /** re.search(p, s) -> match array or null (p: RegExp or Python pattern string). */
760
+ export function reSearch(p, s, flags = '') {
761
+ const re = asRe(p, flags.replace('g', '').replace('y', ''));
762
+ return new RegExp(re.source, re.flags.replace(/[gy]/g, '')).exec(s);
763
+ }
764
+ /** re.match(p, s): anchored at 0. */
765
+ export function reMatch(p, s, flags = '') {
766
+ const re = asRe(p, flags);
767
+ return new RegExp(re.source, re.flags.replace(/[gy]/g, '') + 'y').exec(s);
768
+ }
769
+ /** re.fullmatch(p, s). */
770
+ export function reFullmatch(p, s, flags = '') {
771
+ const re = asRe(p, flags);
772
+ return new RegExp('^(?:' + re.source + ')$(?![\\s\\S])', re.flags.replace(/[gym]/g, '')).exec(s);
773
+ }
774
+ /** re.findall(p, s): whole matches, the single group, or tuples of groups (None groups -> ''). */
775
+ export function reFindall(p, s, flags = '') {
776
+ const re = asRe(p, flags);
777
+ const g = new RegExp(re.source, re.flags.replace(/[gy]/g, '') + 'g');
778
+ const out = [];
779
+ for (const m of s.matchAll(g)) {
780
+ if (m.length === 1) { out.push(m[0]); } else if (m.length === 2) { out.push(m[1] ?? ''); }
781
+ else { out.push(m.slice(1).map((x) => x ?? '')); }
782
+ }
783
+ return out;
784
+ }
785
+ /** re.sub(p, repl, s) — repl string uses Python syntax (\1, \g<name>); or a function(match). */
786
+ export function reSub(p, repl, s, flags = '') {
787
+ const re = asRe(p, flags);
788
+ const g = new RegExp(re.source, re.flags.replace(/[gy]/g, '') + 'g');
789
+ if (typeof repl === 'function') { return s.replace(g, (...a) => repl(a.slice(0, -2 - (typeof a[a.length - 1] === 'object' ? 1 : 0)))); }
790
+ return s.replace(g, (...a) => {
791
+ const groups = typeof a[a.length - 1] === 'object' ? a[a.length - 1] : undefined;
792
+ return repl.replace(/\\(?:g<(\w+)>|(\d+)|(.))/g, (_, name, num, ch) => {
793
+ if (name !== undefined) { return (/^\d+$/.test(name) ? a[Number(name)] : groups?.[name]) ?? ''; }
794
+ if (num !== undefined) { return a[Number(num)] ?? ''; }
795
+ return { n: '\n', t: '\t', r: '\r', '\\': '\\' }[ch] ?? '\\' + ch;
796
+ });
797
+ });
798
+ }
799
+ /** Escape s for literal use inside a JS 'u' RegExp (the role re.escape plays in Python patterns). */
800
+ export function reEscape(s) { return String(s).replace(/[\\^$.*+?()[\]{}|/]/g, '\\$&').replace(/-/g, '\\x2d'); }
801
+
802
+ // ------------------------------------------------------------------ containers
803
+
804
+ /** Key for a Python tuple used as dict key / set member: JSON of its parts (strings/numbers/null). */
805
+ export function tupleKey(...parts) { return JSON.stringify(parts.map((x) => (x === undefined ? null : x))); }
806
+
807
+ /** dict.fromkeys(items) as an ordered de-duplicated array. */
808
+ export function dictFromkeys(items) { return [...new Set(items)]; }
809
+
810
+ /** collections.Counter(items) as a Map with Python insertion order; missing -> use (m.get(k) ?? 0). */
811
+ export function counter(items = []) {
812
+ const m = new Map();
813
+ for (const x of items) { m.set(x, (m.get(x) ?? 0) + 1); }
814
+ return m;
815
+ }
816
+
817
+ // ------------------------------------------------------------------ files
818
+
819
+ const STRICT_UTF8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
820
+ const LAX_UTF8 = new TextDecoder('utf-8', { fatal: false, ignoreBOM: true });
821
+
822
+ /** Path.read_bytes(). */
823
+ export function readBytes(p) { return fs.readFileSync(String(p)); }
824
+
825
+ /** bytes.decode('utf-8', 'replace'). */
826
+ export function decodeReplace(buf) { return LAX_UTF8.decode(buf); }
827
+
828
+ /**
829
+ * Path.read_text(encoding=...): 'utf-8' (strict, BOM kept as ), 'utf-8-sig' (BOM stripped);
830
+ * errors 'strict'|'replace'. Universal newlines: \r\n and \r -> \n.
831
+ */
832
+ export function readText(p, opts = {}) {
833
+ const encoding = opts.encoding ?? 'utf-8';
834
+ const errors = opts.errors ?? 'strict';
835
+ const buf = fs.readFileSync(String(p));
836
+ let s;
837
+ try { s = (errors === 'strict' ? STRICT_UTF8 : LAX_UTF8).decode(buf); } catch {
838
+ throw new PyValueError(`'utf-8' codec can't decode bytes in file ${pathStr(p)}`);
839
+ }
840
+ if (encoding === 'utf-8-sig' && s.charCodeAt(0) === 0xfeff) { s = s.slice(1); }
841
+ return s.replace(/\r\n?/g, '\n');
842
+ }
843
+
844
+ /** Text-mode translation of "\n" for writing (Windows "\r\n", even after an existing "\r"). */
845
+ const toNative = (s) => (IS_WIN ? s.replace(/\n/g, '\r\n') : s);
846
+
847
+ /** Path.write_text(s, encoding='utf-8') (text mode: "\n" -> os.linesep). */
848
+ export function writeText(p, s) { fs.writeFileSync(String(p), toNative(String(s)), 'utf8'); }
849
+
850
+ /** open(p, 'a', encoding='utf-8').write(s). */
851
+ export function appendText(p, s) { fs.appendFileSync(String(p), toNative(String(s)), 'utf8'); }
852
+
853
+ const TMP_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789_';
854
+
855
+ /** tempfile.NamedTemporaryFile(dir, prefix, suffix, delete=False) -> path of a new empty file (O_EXCL). */
856
+ export function namedTemporaryFile(opts = {}) {
857
+ const dir = opts.dir ?? gettempdir();
858
+ for (let i = 0; i < 10000; i++) {
859
+ let name = '';
860
+ for (let j = 0; j < 8; j++) { name += TMP_CHARS[crypto.randomInt(TMP_CHARS.length)]; }
861
+ const full = pJoin(dir, (opts.prefix ?? 'tmp') + name + (opts.suffix ?? ''));
862
+ try { fs.closeSync(fs.openSync(full, 'wx')); return full; } catch (e) {
863
+ if (e.code === 'EEXIST') { continue; }
864
+ if (e.code === 'EACCES' && IS_WIN && pIsDir(dir)) { continue; }
865
+ throw e;
866
+ }
867
+ }
868
+ throw new Error('No usable temporary file name found');
869
+ }
870
+
871
+ const isPermissionError = (e) => e && (e.code === 'EPERM' || e.code === 'EACCES' || e.code === 'EBUSY');
872
+
873
+ /**
874
+ * The atomic_write_json write: text to a NamedTemporaryFile in the target dir (text mode, fsync),
875
+ * then os.replace with `retries` attempts on PermissionError (sleep min(.05*2**n, .8)); temp removed.
876
+ */
877
+ export function atomicWriteText(p, text, retries = 6) {
878
+ const target = pathStr(p);
879
+ pMkdir(pParent(target), { parents: true, exist_ok: true });
880
+ const tmp = namedTemporaryFile({ dir: pParent(target), prefix: pName(target) + '.', suffix: '.tmp' });
881
+ try {
882
+ const fd = fs.openSync(tmp, 'w');
883
+ try { fs.writeSync(fd, toNative(text)); fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
884
+ const n = Math.max(1, toInt(retries));
885
+ for (let attempt = 0; attempt < n; attempt++) {
886
+ try { fs.renameSync(tmp, target); return; } catch (e) {
887
+ if (!isPermissionError(e) || attempt + 1 >= n) { throw e; }
888
+ sleep(Math.min(0.05 * (2 ** attempt), 0.8));
889
+ }
890
+ }
891
+ } finally {
892
+ try { fs.unlinkSync(tmp); } catch { /* missing_ok */ }
893
+ }
894
+ }
895
+
896
+ // ------------------------------------------------------------------ paths (pathlib semantics)
897
+ // A path is a plain string normalised like str(Path(x)); equality and hashing are case-folded on
898
+ // Windows (use pKey / pEq), ordering via pOrder (PurePath `<`).
899
+
900
+ const SEP = IS_WIN ? '\\' : '/';
901
+
902
+ function splitPath(p) {
903
+ if (IS_WIN) {
904
+ const s = String(p).replace(/\//g, '\\');
905
+ let drive = ''; let rest = s;
906
+ const unc = /^\\\\([^\\]+)\\([^\\]+)/.exec(s);
907
+ if (unc) { drive = unc[0]; rest = s.slice(drive.length); }
908
+ else if (/^[A-Za-z]:/.test(s)) { drive = s.slice(0, 2); rest = s.slice(2); }
909
+ const root = rest.startsWith('\\') ? '\\' : '';
910
+ return { drive, root, parts: rest.split('\\').filter((x) => x !== '' && x !== '.') };
911
+ }
912
+ const s = String(p);
913
+ const root = s.startsWith('//') && !s.startsWith('///') ? '//' : s.startsWith('/') ? '/' : '';
914
+ return { drive: '', root, parts: s.split('/').filter((x) => x !== '' && x !== '.') };
915
+ }
916
+ const fmt = ({ drive, root, parts }) => drive + root + parts.join(SEP) || '.';
917
+
918
+ /** str(Path(p)). */
919
+ export function pathStr(p) { return fmt(splitPath(p)); }
920
+
921
+ /** Path(a) / b / c ... */
922
+ export function pJoin(a, ...segs) {
923
+ let cur = splitPath(a);
924
+ for (const s of segs) {
925
+ const n = splitPath(s);
926
+ if (n.root || (n.drive && n.drive.toLowerCase() !== cur.drive.toLowerCase())) {
927
+ cur = { drive: n.drive || cur.drive, root: n.root, parts: n.parts };
928
+ } else if (n.drive) {
929
+ cur = { drive: n.drive, root: cur.root, parts: [...cur.parts, ...n.parts] };
930
+ } else { cur = { ...cur, parts: [...cur.parts, ...n.parts] }; }
931
+ }
932
+ return fmt(cur);
933
+ }
934
+ /** Path(p).parts. */
935
+ export function pParts(p) {
936
+ const s = splitPath(p);
937
+ return s.drive || s.root ? [s.drive + s.root, ...s.parts] : s.parts;
938
+ }
939
+ /** Path(p).name. */
940
+ export function pName(p) { const s = splitPath(p).parts; return s.length ? s[s.length - 1] : ''; }
941
+ /** Path(p).suffix. */
942
+ export function pSuffix(p) {
943
+ const n = pName(p); const i = n.lastIndexOf('.');
944
+ return i > 0 && i < n.length - 1 ? n.slice(i) : '';
945
+ }
946
+ /** Path(p).stem. */
947
+ export function pStem(p) { const n = pName(p); const x = pSuffix(p); return x ? n.slice(0, -x.length) : n; }
948
+ /** Path(p).parent. */
949
+ export function pParent(p) {
950
+ const s = splitPath(p);
951
+ return s.parts.length ? fmt({ ...s, parts: s.parts.slice(0, -1) }) : fmt(s);
952
+ }
953
+ /** list(Path(p).parents), nearest first. */
954
+ export function pParents(p) {
955
+ const s = splitPath(p); const out = [];
956
+ for (let k = s.parts.length - 1; k >= 0; k--) {
957
+ if (k === 0 && !(s.drive || s.root)) { out.push('.'); break; }
958
+ out.push(fmt({ ...s, parts: s.parts.slice(0, k) }));
959
+ }
960
+ return out;
961
+ }
962
+ /** Hash/equality key of a path (os.path.normcase on Windows). */
963
+ export function pKey(p) { return IS_WIN ? pathStr(p).toLowerCase() : pathStr(p); }
964
+ /** Path(a) == Path(b). */
965
+ export function pEq(a, b) { return pKey(a) === pKey(b); }
966
+ /** Sort key reproducing PurePath `<` (use with sortedBy). */
967
+ export function pOrder(p) { return IS_WIN ? pathStr(p).toLowerCase().split('\\') : pathStr(p).split('/'); }
968
+
969
+ /** Path(p).resolve() (strict=False): realpath of the longest existing prefix, rest appended. */
970
+ export function pResolve(p) {
971
+ let abs = path.resolve(String(p));
972
+ const tail = [];
973
+ for (;;) {
974
+ try {
975
+ const real = fs.realpathSync.native(abs);
976
+ return pathStr(tail.length ? path.join(real, ...tail.reverse()) : real);
977
+ } catch {
978
+ const parent = path.dirname(abs);
979
+ if (parent === abs) { return pathStr(path.resolve(String(p))); }
980
+ tail.push(path.basename(abs));
981
+ abs = parent;
982
+ }
983
+ }
984
+ }
985
+ /** Path(p).absolute(): cwd prefix only, no `..` collapsing. */
986
+ export function pAbsolute(p) {
987
+ const { drive, root, parts } = splitPath(p);
988
+ if (IS_WIN ? (drive && root) || /^\\\\/.test(drive) : root) { return pathStr(p); }
989
+ const cwd = process.cwd();
990
+ if (root) { return splitPath(cwd).drive + root + parts.join(SEP); }
991
+ const base = drive ? path.resolve(drive) : cwd;
992
+ return [base.replace(/[\\/]+$/, ''), ...parts].join(SEP) || base;
993
+ }
994
+ const statOf = (p) => { try { return fs.statSync(String(p), { throwIfNoEntry: false }); } catch { return undefined; } };
995
+ /** Path.is_file(). */
996
+ export function pIsFile(p) { return statOf(p)?.isFile() ?? false; }
997
+ /** Path.is_dir(). */
998
+ export function pIsDir(p) { return statOf(p)?.isDirectory() ?? false; }
999
+ /** Path.exists(). */
1000
+ export function pExists(p) { return statOf(p) !== undefined; }
1001
+ /** Path.mkdir(parents=False, exist_ok=False). */
1002
+ export function pMkdir(p, opts = {}) {
1003
+ const s = pathStr(p);
1004
+ if (opts.parents) {
1005
+ if (pIsDir(s)) { if (opts.exist_ok) { return; } const e = new Error(`[WinError 183] Cannot create a file when that file already exists: '${s}'`); e.code = 'EEXIST'; throw e; }
1006
+ fs.mkdirSync(s, { recursive: true });
1007
+ return;
1008
+ }
1009
+ try { fs.mkdirSync(s); } catch (e) { if (!(e.code === 'EEXIST' && opts.exist_ok && pIsDir(s))) { throw e; } }
1010
+ }
1011
+ /** Path(p).relative_to(base) parts (original case) or null when not relative. */
1012
+ function relParts(p, base) {
1013
+ const a = splitPath(pathStr(p)); const b = splitPath(pathStr(base));
1014
+ const norm = (x) => (IS_WIN ? x.toLowerCase() : x);
1015
+ if (norm(a.drive + a.root) !== norm(b.drive + b.root) || b.parts.length > a.parts.length) { return null; }
1016
+ for (let i = 0; i < b.parts.length; i++) { if (norm(a.parts[i]) !== norm(b.parts[i])) { return null; } }
1017
+ return a.parts.slice(b.parts.length);
1018
+ }
1019
+ /** Path(p).relative_to(base) as a path string; ValueError like Python when not relative. */
1020
+ export function pRelativeTo(p, base) {
1021
+ const r = relParts(p, base);
1022
+ if (r === null) { throw new PyValueError(`${strRepr(pathStr(p))} is not in the subpath of ${strRepr(pathStr(base))}`); }
1023
+ return r.length ? r.join(SEP) : '.';
1024
+ }
1025
+ /** Path(p).relative_to(base).parts, or null when not relative. */
1026
+ export function pRelativeParts(p, base) { return relParts(p, base); }
1027
+ /** Path(p).is_relative_to(base). */
1028
+ export function pIsRelativeTo(p, base) { return relParts(p, base) !== null; }
1029
+
1030
+ /** os.scandir(d) names in OS order. Throws on OSError. */
1031
+ export function listDirNames(d) {
1032
+ const names = [];
1033
+ const h = fs.opendirSync(String(d));
1034
+ try { for (let e = h.readSync(); e !== null; e = h.readSync()) { names.push(e); } } finally { h.closeSync(); }
1035
+ return names;
1036
+ }
1037
+ /** Path(d).iterdir(): child paths in scandir order. */
1038
+ export function pIterdir(d) { return listDirNames(d).map((e) => pJoin(d, e.name)); }
1039
+
1040
+ function globPartRe(part) {
1041
+ let re = '';
1042
+ for (let i = 0; i < part.length; i++) {
1043
+ const c = part[i];
1044
+ if (c === '*') { re += '[^\\\\/]*'; while (part[i + 1] === '*') { i++; } }
1045
+ else if (c === '?') { re += '[^\\\\/]'; }
1046
+ else if (c === '[') {
1047
+ const j = part.indexOf(']', i + 2);
1048
+ if (j < 0) { re += '\\['; continue; }
1049
+ let body = part.slice(i + 1, j);
1050
+ if (body.startsWith('!')) { body = '^' + body.slice(1); }
1051
+ re += '[' + body.replace(/\\/g, '\\\\') + ']';
1052
+ i = j;
1053
+ } else { re += c.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&'); }
1054
+ }
1055
+ return new RegExp('^(?:' + re + ')$', IS_WIN ? 'isu' : 'su');
1056
+ }
1057
+ const MAGIC = /[*?[]/;
1058
+ const direntIsDir = (e) => { try { return e.isDirectory(); } catch { return false; } };
1059
+ const lexists = (p) => { try { fs.lstatSync(p); return true; } catch { return false; } };
1060
+
1061
+ /**
1062
+ * Path(root).glob(pattern) exactly as CPython 3.13 walks it (recurse_symlinks=False): literal parts
1063
+ * joined and lstat-checked, `*` parts via scandir order, `**` as a LIFO-stack depth walk.
1064
+ * Case-insensitive name matching on Windows. Returns path strings (generator order).
1065
+ */
1066
+ export function pGlob(root, pattern) {
1067
+ const parts = String(pattern).split(/[\\/]+/).filter((x) => x !== '' && x !== '.');
1068
+ if (!parts.length) { throw new PyValueError(`Unacceptable pattern: ${strRepr(String(pattern))}`); }
1069
+ const addSlash = (s) => (s.endsWith(SEP) || s.endsWith('/') ? s : s + SEP);
1070
+ const build = (ps) => {
1071
+ if (!ps.length) { return function* exists(p, known) { if (known || lexists(p)) { yield p; } }; }
1072
+ let part = ps[0];
1073
+ if (part === '**') {
1074
+ let rest = ps.slice(1);
1075
+ while (rest[0] === '**') { rest = rest.slice(1); }
1076
+ const dirOnly = rest.length > 0;
1077
+ const next = build(rest);
1078
+ return function* recursive(p) {
1079
+ const base = addSlash(p);
1080
+ yield* next(base, false);
1081
+ const stack = [base];
1082
+ while (stack.length) {
1083
+ const cur = stack.pop();
1084
+ let entries;
1085
+ try { entries = listDirNames(cur); } catch { continue; }
1086
+ for (const e of entries) {
1087
+ const isDir = direntIsDir(e);
1088
+ if (isDir || !dirOnly) {
1089
+ const ep = cur.endsWith(SEP) || cur.endsWith('/') ? cur + e.name : cur + SEP + e.name;
1090
+ if (dirOnly) { yield* next(ep, true); } else { yield ep; }
1091
+ if (isDir) { stack.push(ep); }
1092
+ }
1093
+ }
1094
+ }
1095
+ };
1096
+ }
1097
+ if (!MAGIC.test(part)) {
1098
+ let k = 1;
1099
+ while (k < ps.length && !MAGIC.test(ps[k]) && ps[k] !== '**') { part += SEP + ps[k]; k++; }
1100
+ const next = build(ps.slice(k));
1101
+ return function* literal(p) { yield* next(addSlash(p) + part, false); };
1102
+ }
1103
+ const match = part === '*' ? null : globPartRe(part);
1104
+ const dirOnly = ps.length > 1;
1105
+ const next = dirOnly ? build(ps.slice(1)) : null;
1106
+ return function* wildcard(p) {
1107
+ let entries;
1108
+ try { entries = listDirNames(p); } catch { return; }
1109
+ for (const e of entries) {
1110
+ if (match === null || match.test(e.name)) {
1111
+ if (dirOnly && !direntIsDir(e)) { continue; }
1112
+ const ep = p.endsWith(SEP) || p.endsWith('/') ? p + e.name : p + SEP + e.name;
1113
+ if (dirOnly) { yield* next(ep, true); } else { yield ep; }
1114
+ }
1115
+ }
1116
+ };
1117
+ };
1118
+ const rootStr = pathStr(root);
1119
+ const out = [];
1120
+ for (const p of build(parts)(rootStr, false)) { out.push(pathStr(p)); }
1121
+ return out;
1122
+ }
1123
+
1124
+ // ------------------------------------------------------------------ xml.etree.ElementTree
1125
+ // A small non-validating XML parser with ElementTree's data model: namespaced names become
1126
+ // `{uri}local`, attribute order is document order, comments/PIs are dropped, entities and char
1127
+ // references decoded, attribute whitespace (\t \n \r) normalised to spaces as expat does.
1128
+
1129
+ /** xml.etree.ElementTree.ParseError (str(exc) like expat: "<msg>: line L, column C"). */
1130
+ export class XmlParseError extends Error {
1131
+ constructor(msg, line, col) { super(`${msg}: line ${line}, column ${col}`); this.name = 'ParseError'; this.position = [line, col]; }
1132
+ }
1133
+
1134
+ /** xml.etree.ElementTree.Element: tag, attrib, text, tail, children; iterable over children. */
1135
+ export class Element {
1136
+ constructor(tag, attrib = {}) { this.tag = tag; this.attrib = attrib; this.text = null; this.tail = null; this.children = []; }
1137
+ /** el.get(key, default=None). */
1138
+ get(k, d = null) { return Object.hasOwn(this.attrib, k) ? this.attrib[k] : d; }
1139
+ /** len(el). */
1140
+ get length() { return this.children.length; }
1141
+ [Symbol.iterator]() { return this.children[Symbol.iterator](); }
1142
+ /** el.iter(tag=None): depth-first pre-order including self. */
1143
+ *iter(tag = null) {
1144
+ if (tag === null || tag === '*' || this.tag === tag) { yield this; }
1145
+ for (const c of this.children) { yield* c.iter(tag); }
1146
+ }
1147
+ /** el.itertext(). */
1148
+ *itertext() {
1149
+ if (this.text) { yield this.text; }
1150
+ for (const c of this.children) { yield* c.itertext(); if (c.tail) { yield c.tail; } }
1151
+ }
1152
+ }
1153
+
1154
+ const XML_ENT = { lt: '<', gt: '>', amp: '&', quot: '"', apos: "'" };
1155
+ const NAME_RE = /[A-Za-z_:À-￿][-A-Za-z0-9_:.·À-￿]*/y;
1156
+
1157
+ /** ET.fromstring(text) -> root Element. */
1158
+ export function etFromString(text) {
1159
+ if (typeof text !== 'string') { text = text instanceof Uint8Array ? decodeXmlBytes(text) : String(text); }
1160
+ if (text.charCodeAt(0) === 0xfeff) { text = text.slice(1); }
1161
+ const src = text.replace(/\r\n?/g, '\n');
1162
+ let i = 0;
1163
+ const pos = (at = i) => {
1164
+ const before = src.slice(0, at);
1165
+ const line = before.split('\n').length;
1166
+ return [line, at - (before.lastIndexOf('\n') + 1)];
1167
+ };
1168
+ const fail = (msg, at = i) => { const [l, c] = pos(at); throw new XmlParseError(msg, l, c); };
1169
+ const decode = (s, at, attr) => {
1170
+ let out = '';
1171
+ for (let k = 0; k < s.length; k++) {
1172
+ const ch = s[k];
1173
+ if (ch === '&') {
1174
+ const end = s.indexOf(';', k);
1175
+ if (end < 0) { fail('not well-formed (invalid token)', at + k); }
1176
+ const name = s.slice(k + 1, end);
1177
+ if (name.startsWith('#x')) { out += String.fromCodePoint(parseInt(name.slice(2), 16)); }
1178
+ else if (name.startsWith('#')) { out += String.fromCodePoint(parseInt(name.slice(1), 10)); }
1179
+ else if (Object.hasOwn(XML_ENT, name)) { out += XML_ENT[name]; }
1180
+ else { fail('undefined entity', at + k); }
1181
+ k = end;
1182
+ } else if (ch === '<' && attr) { fail('not well-formed (invalid token)', at + k); }
1183
+ else if (attr && (ch === '\n' || ch === '\t')) { out += ' '; }
1184
+ else { out += ch; }
1185
+ }
1186
+ return out;
1187
+ };
1188
+ const name = () => {
1189
+ NAME_RE.lastIndex = i;
1190
+ const m = NAME_RE.exec(src);
1191
+ if (!m) { fail('not well-formed (invalid token)'); }
1192
+ i += m[0].length;
1193
+ return m[0];
1194
+ };
1195
+ const skipWs = () => { while (i < src.length && ' \t\n'.includes(src[i])) { i++; } };
1196
+ const stack = []; // [{el, rawTag, ns}]
1197
+ let root = null;
1198
+ let last = null; // element whose text/tail receives character data
1199
+ let lastIsTail = false;
1200
+ const addText = (t) => {
1201
+ if (!t) { return; }
1202
+ if (!stack.length) {
1203
+ if (/[^ \t\n]/.test(t)) { fail(root ? 'junk after document element' : 'syntax error'); }
1204
+ return;
1205
+ }
1206
+ if (lastIsTail) { last.tail = (last.tail ?? '') + t; } else { last.text = (last.text ?? '') + t; }
1207
+ };
1208
+ const resolve = (qname, ns, isAttr, at) => {
1209
+ const c = qname.indexOf(':');
1210
+ if (c < 0) { return isAttr ? qname : (ns[''] ? `{${ns['']}}${qname}` : qname); }
1211
+ const prefix = qname.slice(0, c);
1212
+ if (prefix === 'xml') { return `{http://www.w3.org/XML/1998/namespace}${qname.slice(c + 1)}`; }
1213
+ if (prefix === 'xmlns') { return null; }
1214
+ if (!Object.hasOwn(ns, prefix)) { fail('unbound prefix', at); }
1215
+ return `{${ns[prefix]}}${qname.slice(c + 1)}`;
1216
+ };
1217
+ while (i < src.length) {
1218
+ const lt = src.indexOf('<', i);
1219
+ if (lt < 0) { addText(decode(src.slice(i), i, false)); i = src.length; break; }
1220
+ if (lt > i) { addText(decode(src.slice(i, lt), i, false)); }
1221
+ i = lt;
1222
+ if (src.startsWith('<!--', i)) {
1223
+ const e = src.indexOf('-->', i + 4); if (e < 0) { fail('unclosed token'); } i = e + 3; continue;
1224
+ }
1225
+ if (src.startsWith('<![CDATA[', i)) {
1226
+ const e = src.indexOf(']]>', i); if (e < 0) { fail('unclosed CDATA section'); }
1227
+ if (!stack.length) { fail('syntax error'); }
1228
+ addText(src.slice(i + 9, e)); i = e + 3; continue;
1229
+ }
1230
+ if (src.startsWith('<?', i)) { const e = src.indexOf('?>', i); if (e < 0) { fail('unclosed token'); } i = e + 2; continue; }
1231
+ if (src.startsWith('<!DOCTYPE', i)) {
1232
+ let depth = 0; let k = i;
1233
+ for (; k < src.length; k++) { if (src[k] === '[') { depth++; } else if (src[k] === ']') { depth--; } else if (src[k] === '>' && depth <= 0) { break; } }
1234
+ i = k + 1; continue;
1235
+ }
1236
+ if (src[i + 1] === '/') {
1237
+ i += 2;
1238
+ const nm = name(); skipWs();
1239
+ if (src[i] !== '>') { fail('not well-formed (invalid token)'); }
1240
+ const top = stack.pop();
1241
+ if (!top || top.raw !== nm) { fail('mismatched tag', lt); }
1242
+ i++;
1243
+ last = top.el; lastIsTail = true;
1244
+ continue;
1245
+ }
1246
+ const tagAt = i;
1247
+ i++;
1248
+ const raw = name();
1249
+ const rawAttrs = [];
1250
+ for (;;) {
1251
+ const hadWs = i < src.length && ' \t\n'.includes(src[i]);
1252
+ skipWs();
1253
+ if (src[i] === '>' || src.startsWith('/>', i)) { break; }
1254
+ if (i >= src.length) { fail('unclosed token', tagAt); }
1255
+ if (!hadWs) { fail('not well-formed (invalid token)'); }
1256
+ const aAt = i;
1257
+ const an = name(); skipWs();
1258
+ if (src[i] !== '=') { fail('not well-formed (invalid token)'); }
1259
+ i++; skipWs();
1260
+ const q = src[i];
1261
+ if (q !== '"' && q !== "'") { fail('not well-formed (invalid token)'); }
1262
+ const e = src.indexOf(q, i + 1);
1263
+ if (e < 0) { fail('unclosed token', tagAt); }
1264
+ if (rawAttrs.some((a) => a[0] === an)) { fail('duplicate attribute', aAt); }
1265
+ rawAttrs.push([an, decode(src.slice(i + 1, e), i + 1, true), aAt]);
1266
+ i = e + 1;
1267
+ }
1268
+ const ns = { ...(stack.length ? stack[stack.length - 1].ns : {}) };
1269
+ for (const [an, av] of rawAttrs) {
1270
+ if (an === 'xmlns') { ns[''] = av; } else if (an.startsWith('xmlns:')) { ns[an.slice(6)] = av; }
1271
+ }
1272
+ const attrib = {};
1273
+ for (const [an, av, aAt] of rawAttrs) {
1274
+ const key = resolve(an, ns, true, aAt);
1275
+ if (key !== null && an !== 'xmlns') { dset(attrib, key, av); }
1276
+ }
1277
+ const el = new Element(resolve(raw, ns, false, tagAt), attrib);
1278
+ if (stack.length) { stack[stack.length - 1].el.children.push(el); }
1279
+ else if (root) { fail('junk after document element', tagAt); }
1280
+ else { root = el; }
1281
+ if (src.startsWith('/>', i)) { i += 2; last = el; lastIsTail = true; }
1282
+ else { i++; stack.push({ el, raw, ns }); last = el; lastIsTail = false; }
1283
+ }
1284
+ if (stack.length) { fail('no element found'); }
1285
+ if (!root) { fail('no element found'); }
1286
+ return root;
1287
+ }
1288
+
1289
+ function decodeXmlBytes(buf) {
1290
+ const head = Buffer.from(buf.subarray(0, 200)).toString('latin1');
1291
+ const m = /^(?:|\xEF\xBB\xBF)?<\?xml[^>]*encoding=["']([^"']+)["']/.exec(head);
1292
+ const enc = m ? m[1].toLowerCase() : 'utf-8';
1293
+ try {
1294
+ return new TextDecoder(enc === 'utf8' ? 'utf-8' : enc, { fatal: true }).decode(buf);
1295
+ } catch {
1296
+ // expat reports undecodable input as a token error
1297
+ let line = 1; let col = 0;
1298
+ for (let k = 0; k < buf.length; k++) {
1299
+ const b = buf[k];
1300
+ if (b === 0x0a) { line++; col = 0; continue; }
1301
+ const len = b < 0x80 ? 1 : (b & 0xe0) === 0xc0 ? 2 : (b & 0xf0) === 0xe0 ? 3 : (b & 0xf8) === 0xf0 ? 4 : 0;
1302
+ const ok = len > 0 && k + len <= buf.length && [...buf.subarray(k + 1, k + len)].every((c) => (c & 0xc0) === 0x80);
1303
+ if (!ok) { break; }
1304
+ k += len - 1; col++;
1305
+ }
1306
+ throw new XmlParseError('not well-formed (invalid token)', line, col);
1307
+ }
1308
+ }
1309
+
1310
+ /** ET.parse(path).getroot() (OSError for missing file propagates; XmlParseError on bad XML). */
1311
+ export function etParse(p) { return etFromString(decodeXmlBytes(fs.readFileSync(String(p)))); }
1312
+
1313
+ // ------------------------------------------------------------------ time / hashing / ids / os
1314
+
1315
+ const SLEEP_CELL = new Int32Array(new SharedArrayBuffer(4));
1316
+
1317
+ /** time.time(): epoch seconds as a float. */
1318
+ export function time() { return (performance.timeOrigin + performance.now()) / 1000; }
1319
+ /** time.sleep(seconds), synchronous (blocks the thread like Python). */
1320
+ export function sleep(seconds) {
1321
+ const ms = Number(seconds) * 1000;
1322
+ if (ms > 0) { Atomics.wait(SLEEP_CELL, 0, 0, ms); }
1323
+ }
1324
+ /** time.monotonic() in seconds. */
1325
+ export function monotonic() { return performance.now() / 1000; }
1326
+ /** hashlib.sha256(data).hexdigest() (str data is UTF-8 encoded). */
1327
+ export function sha256Hex(data) { return crypto.createHash('sha256').update(data).digest('hex'); }
1328
+ /** hashlib.md5(data).hexdigest(). */
1329
+ export function md5Hex(data) { return crypto.createHash('md5').update(data).digest('hex'); }
1330
+ /** sha256 of a file's bytes. */
1331
+ export function sha256File(p) { return sha256Hex(fs.readFileSync(String(p))); }
1332
+ /** md5 of a file's bytes. */
1333
+ export function md5File(p) { return md5Hex(fs.readFileSync(String(p))); }
1334
+ /** str(uuid.uuid4()). */
1335
+ export function uuid4() { return crypto.randomUUID(); }
1336
+ /** uuid.uuid4().hex. */
1337
+ export function uuid4Hex() { return crypto.randomUUID().replace(/-/g, ''); }
1338
+ /** tempfile.gettempdir() (TMPDIR/TEMP/TMP, else os.tmpdir()), normalised. */
1339
+ export function gettempdir() {
1340
+ for (const k of ['TMPDIR', 'TEMP', 'TMP']) { if (process.env[k] && pIsDir(process.env[k])) { return pathStr(path.resolve(process.env[k])); } }
1341
+ return pathStr(os.tmpdir());
1342
+ }
1343
+ /** shutil.which(cmd) or null (PATHEXT on Windows). */
1344
+ export function which(cmd) {
1345
+ const exts = IS_WIN ? (process.env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';') : [''];
1346
+ const dirs = /[\\/]/.test(cmd) ? [''] : [...(IS_WIN ? ['.'] : []), ...(process.env.PATH || '').split(path.delimiter)];
1347
+ for (const d of dirs) {
1348
+ const base = d ? path.join(d, cmd) : cmd;
1349
+ const cands = IS_WIN && exts.some((e) => base.toLowerCase().endsWith(e.toLowerCase())) ? [base] : exts.map((e) => base + e);
1350
+ for (const c of cands) { if (pIsFile(c)) { return c; } }
1351
+ }
1352
+ return null;
1353
+ }
1354
+
1355
+ /** shlex.quote(s). */
1356
+ export function shlexQuote(s) {
1357
+ s = String(s);
1358
+ if (!s) { return "''"; }
1359
+ if (!/[^\w@%+=:,./-]/.test(s)) { return s; }
1360
+ return "'" + s.replace(/'/g, "'\"'\"'") + "'";
1361
+ }
1362
+
1363
+ /** shlex.split(s) (POSIX mode, comments disabled). */
1364
+ export function shlexSplit(s) {
1365
+ const out = []; let cur = null; let i = 0;
1366
+ while (i < s.length) {
1367
+ const c = s[i];
1368
+ if (/\s/.test(c)) { if (cur !== null) { out.push(cur); cur = null; } i++; continue; }
1369
+ cur ??= '';
1370
+ if (c === "'") {
1371
+ const e = s.indexOf("'", i + 1); if (e < 0) { throw new PyValueError('No closing quotation'); }
1372
+ cur += s.slice(i + 1, e); i = e + 1;
1373
+ } else if (c === '"') {
1374
+ i++;
1375
+ for (;;) {
1376
+ if (i >= s.length) { throw new PyValueError('No closing quotation'); }
1377
+ if (s[i] === '"') { i++; break; }
1378
+ if (s[i] === '\\' && i + 1 < s.length && '\\"$`\n'.includes(s[i + 1])) { cur += s[i + 1]; i += 2; continue; }
1379
+ cur += s[i]; i++;
1380
+ }
1381
+ } else if (c === '\\') {
1382
+ if (i + 1 >= s.length) { throw new PyValueError('No escaped character'); }
1383
+ cur += s[i + 1]; i += 2;
1384
+ } else { cur += c; i++; }
1385
+ }
1386
+ if (cur !== null) { out.push(cur); }
1387
+ return out;
1388
+ }
1389
+
1390
+ /** unicodedata.normalize('NFKC', s). */
1391
+ export function nfkc(s) { return String(s).normalize('NFKC'); }
1392
+
1393
+ /** html.escape(s, quote=True). */
1394
+ export function htmlEscape(s, quote = true) {
1395
+ s = String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
1396
+ return quote ? s.replace(/"/g, '&quot;').replace(/'/g, '&#x27;') : s;
1397
+ }
1398
+
1399
+ /** subprocess.TimeoutExpired. */
1400
+ export class TimeoutExpired extends Error {
1401
+ constructor(cmd, timeout) {
1402
+ super(`Command '${pyRepr(cmd)}' timed out after ${pyStr(timeout)} seconds`);
1403
+ this.name = 'TimeoutExpired'; this.cmd = cmd; this.timeout = timeout;
1404
+ }
1405
+ }
1406
+
1407
+ /**
1408
+ * subprocess.run(argv, capture_output=True, timeout, input) with shell=False:
1409
+ * -> {returncode, stdout: Buffer, stderr: Buffer}; TimeoutExpired on timeout; FileNotFoundError-like
1410
+ * Error (code ENOENT, message "[WinError 2] The system cannot find the file specified") when missing.
1411
+ */
1412
+ export function subprocessRun(argv, opts = {}) {
1413
+ const r = spawnSync(String(argv[0]), argv.slice(1).map(String), {
1414
+ input: opts.input, timeout: opts.timeout != null ? Math.max(1, Math.round(Number(opts.timeout) * 1000)) : undefined,
1415
+ maxBuffer: 1 << 30, windowsHide: true, cwd: opts.cwd, env: opts.env, killSignal: 'SIGKILL',
1416
+ });
1417
+ if (r.error) {
1418
+ if (r.error.code === 'ETIMEDOUT') { throw new TimeoutExpired(argv, opts.timeout); }
1419
+ if (r.error.code === 'ENOENT') {
1420
+ const e = new Error(IS_WIN ? '[WinError 2] The system cannot find the file specified'
1421
+ : `[Errno 2] No such file or directory: ${strRepr(String(argv[0]))}`);
1422
+ e.code = 'ENOENT'; e.name = 'FileNotFoundError'; throw e;
1423
+ }
1424
+ throw r.error;
1425
+ }
1426
+ return { returncode: r.status ?? (r.signal ? -9 : 1), stdout: r.stdout ?? Buffer.alloc(0), stderr: r.stderr ?? Buffer.alloc(0) };
1427
+ }
1428
+
1429
+ /** True when a process with this pid exists (signal 0; EPERM counts as alive). */
1430
+ export function pidAlive(pid) {
1431
+ pid = Number(pid);
1432
+ if (!Number.isInteger(pid) || pid <= 0) { return false; }
1433
+ try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; }
1434
+ }
1435
+
1436
+ /** print(*args) to stdout (text mode, str() of each arg, sep ' '). */
1437
+ export function pyPrint(...args) { fs.writeSync(1, toNative(args.map(pyStr).join(' ') + '\n')); }
1438
+ /** print(*args, file=sys.stderr). */
1439
+ export function pyPrintErr(...args) { fs.writeSync(2, toNative(args.map(pyStr).join(' ') + '\n')); }
1440
+
1441
+ // ------------------------------------------------------------------ textwrap
1442
+
1443
+ /** textwrap.wrap(text, width) with default options (incl. break_on_hyphens / break_long_words). */
1444
+ export function textwrapWrap(text, width) {
1445
+ text = text.replace(/\t/g, ' ').replace(/[\t\n\v\f\r]/g, ' ');
1446
+ // chunks: whitespace runs, and words split after hyphens between letters (textwrap.wordsep_re)
1447
+ const chunks = [];
1448
+ for (const tok of text.split(/( +)/)) {
1449
+ if (tok === '') { continue; }
1450
+ if (/^ +$/.test(tok)) { chunks.push(tok); continue; }
1451
+ let start = 0;
1452
+ for (let k = 1; k < tok.length - 1; k++) {
1453
+ if (tok[k] !== '-') { continue; }
1454
+ const L = (c) => c !== undefined && /\p{L}/u.test(c);
1455
+ const before = (L(tok[k - 1]) && L(tok[k - 2])) || (L(tok[k - 1]) && tok[k - 2] === '-' && L(tok[k - 3]));
1456
+ const after = L(tok[k + 1]) || (tok[k + 1] === '-' && L(tok[k + 2]));
1457
+ if (before && after && k - start >= 1) { chunks.push(tok.slice(start, k + 1)); start = k + 1; }
1458
+ }
1459
+ chunks.push(tok.slice(start));
1460
+ }
1461
+ const lines = [];
1462
+ chunks.reverse();
1463
+ while (chunks.length) {
1464
+ const cur = []; let len = 0;
1465
+ if (chunks[chunks.length - 1].trim() === '' && lines.length) { chunks.pop(); }
1466
+ while (chunks.length) {
1467
+ const l = chunks[chunks.length - 1].length;
1468
+ if (len + l <= width) { cur.push(chunks.pop()); len += l; } else { break; }
1469
+ }
1470
+ if (chunks.length && chunks[chunks.length - 1].length > width) {
1471
+ const space = width < 1 ? 1 : width - len;
1472
+ let chunk = chunks[chunks.length - 1]; let end = space;
1473
+ if (chunk.length > space) {
1474
+ const h = chunk.lastIndexOf('-', space - 1);
1475
+ if (h > 0 && /[^-]/.test(chunk.slice(0, h))) { end = h + 1; }
1476
+ }
1477
+ cur.push(chunk.slice(0, end)); chunks[chunks.length - 1] = chunk.slice(end); len += end;
1478
+ chunk = null;
1479
+ }
1480
+ if (cur.length && cur[cur.length - 1].trim() === '') { len -= cur.pop().length; }
1481
+ if (cur.length) { lines.push(cur.join('')); }
1482
+ }
1483
+ return lines;
1484
+ }
1485
+
1486
+ // ------------------------------------------------------------------ argparse
1487
+ // Reproduces CPython 3.13 argparse's observable behaviour for the features the scripts use:
1488
+ // positionals and options (nargs None/'?'/'*'/'+'/N), actions store/store_true/store_false/
1489
+ // store_const/append/count, type (int, float or a function), choices, required, default, dest,
1490
+ // metavar, help, mutually exclusive groups, subparsers, description, RawDescriptionHelpFormatter,
1491
+ // prefix abbreviation, --opt=value, -xVALUE, '--', usage/help layout, "prog: error:" + exit 2.
1492
+
1493
+ /** argparse.SUPPRESS. */
1494
+ export const SUPPRESS = '==SUPPRESS==';
1495
+
1496
+ /** argparse.ArgumentError (str: "argument NAME: message"). */
1497
+ export class ArgumentError extends Error {
1498
+ constructor(action, message) {
1499
+ const name = action ? actionName(action) : null;
1500
+ super(name === null ? message : `argument ${name}: ${message}`);
1501
+ this.name = 'ArgumentError'; this.argument_name = name; this.bare = message;
1502
+ }
1503
+ }
1504
+
1505
+ function actionName(a) {
1506
+ if (a.option_strings.length) { return a.option_strings.join('/'); }
1507
+ if (a.metavar !== null && a.metavar !== SUPPRESS) { return a.metavar; }
1508
+ if (a.dest !== null && a.dest !== SUPPRESS) { return a.dest; }
1509
+ if (a.choices) { return '{' + a.choices.map(pyStr).join(',') + '}'; }
1510
+ return null;
1511
+ }
1512
+
1513
+ const typeName = (t) => (t === 'int' || t === toInt ? 'int' : t === 'float' || t === toFloat ? 'float' : t?.pyName ?? t?.name ?? String(t));
1514
+
1515
+ function termWidth() {
1516
+ const env = Number.parseInt(process.env.COLUMNS ?? '', 10);
1517
+ if (env > 0) { return env; }
1518
+ return process.stdout.isTTY && process.stdout.columns ? process.stdout.columns : 80;
1519
+ }
1520
+
1521
+ /** argparse.ArgumentParser({prog, description, formatter_class:'raw', exit_on_error, allow_abbrev}). */
1522
+ export class ArgumentParser {
1523
+ constructor(opts = {}) {
1524
+ this.prog = opts.prog ?? path.basename(process.argv[1] ?? 'prog');
1525
+ this.description = opts.description ?? null;
1526
+ this.raw = opts.formatter_class === 'raw' || opts.formatter_class === 'RawDescriptionHelpFormatter';
1527
+ this.exit_on_error = opts.exit_on_error ?? true;
1528
+ this.allow_abbrev = opts.allow_abbrev ?? true;
1529
+ this.usage = opts.usage ?? null;
1530
+ this._actions = [];
1531
+ this._groups = [];
1532
+ this._subparsers = null;
1533
+ if (opts.add_help ?? true) {
1534
+ this._add({ option_strings: ['-h', '--help'], dest: SUPPRESS, nargs: 0, action: 'help', help: 'show this help message and exit' });
1535
+ }
1536
+ }
1537
+
1538
+ _add(spec) {
1539
+ const a = {
1540
+ option_strings: [], dest: null, nargs: null, const: null, default: null, type: null, choices: null,
1541
+ required: false, help: null, metavar: null, action: 'store', ...spec,
1542
+ };
1543
+ this._actions.push(a);
1544
+ return a;
1545
+ }
1546
+
1547
+ /** add_argument(name_or_flags..., {action, nargs, const, default, type, choices, required, help, metavar, dest}). */
1548
+ add_argument(...args) {
1549
+ const opts = args.length && typeof args[args.length - 1] === 'object' ? args.pop() : {};
1550
+ const action = opts.action ?? 'store';
1551
+ const isOpt = args[0].startsWith('-');
1552
+ let dest = opts.dest;
1553
+ if (!dest) {
1554
+ if (!isOpt) { dest = args[0]; } else {
1555
+ const long = args.find((s) => s.startsWith('--')) ?? args[0];
1556
+ dest = long.replace(/^-+/, '').replace(/-/g, '_');
1557
+ }
1558
+ }
1559
+ const spec = { option_strings: isOpt ? args : [], dest, action, help: opts.help ?? null, metavar: opts.metavar ?? null,
1560
+ choices: opts.choices ?? null, type: opts.type ?? null, required: !!opts.required || (!isOpt && opts.nargs !== '?' && opts.nargs !== '*') };
1561
+ if (action === 'store_true' || action === 'store_false' || action === 'store_const' || action === 'count') {
1562
+ spec.nargs = 0;
1563
+ spec.const = action === 'store_true' ? true : action === 'store_false' ? false : opts.const ?? null;
1564
+ spec.default = opts.default !== undefined ? opts.default : action === 'store_true' ? false : action === 'store_false' ? true : null;
1565
+ } else {
1566
+ spec.nargs = opts.nargs ?? null; spec.const = opts.const ?? null; spec.default = opts.default !== undefined ? opts.default : null;
1567
+ }
1568
+ if (!isOpt && !opts.required) { spec.required = !(spec.nargs === '?' || spec.nargs === '*'); }
1569
+ if (isOpt) { spec.required = !!opts.required; }
1570
+ return this._add(spec);
1571
+ }
1572
+
1573
+ /** add_mutually_exclusive_group({required}) -> object with add_argument(). */
1574
+ add_mutually_exclusive_group(opts = {}) {
1575
+ const g = { required: !!opts.required, actions: [] };
1576
+ this._groups.push(g);
1577
+ return { add_argument: (...a) => { const act = this.add_argument(...a); g.actions.push(act); return act; } };
1578
+ }
1579
+
1580
+ /** add_subparsers({dest, required}) -> object with add_parser(name, opts). */
1581
+ add_subparsers(opts = {}) {
1582
+ const prefix = [this.prog, ...this._actions.filter((a) => !a.option_strings.length).map((a) => this._formatArgs(a, a.dest))].join(' ');
1583
+ const act = this._add({ dest: opts.dest ?? SUPPRESS, nargs: 'A...', action: 'parsers', required: !!opts.required, choices: [], parsers: new Map(), metavar: opts.metavar ?? null });
1584
+ this._subparsers = act;
1585
+ return {
1586
+ add_parser: (name, popts = {}) => {
1587
+ const p = new ArgumentParser({ ...popts, prog: popts.prog ?? `${prefix} ${name}` });
1588
+ act.parsers.set(name, p); act.choices.push(name);
1589
+ return p;
1590
+ },
1591
+ };
1592
+ }
1593
+
1594
+ _metavar(a, dflt) {
1595
+ if (a.metavar !== null) { return a.metavar; }
1596
+ if (a.choices !== null) { return '{' + a.choices.map(pyStr).join(',') + '}'; }
1597
+ return dflt;
1598
+ }
1599
+ _formatArgs(a, dflt) {
1600
+ const m = this._metavar(a, dflt);
1601
+ if (a.nargs === null) { return m; }
1602
+ if (a.nargs === '?') { return `[${m}]`; }
1603
+ if (a.nargs === '*') { return `[${m} ...]`; }
1604
+ if (a.nargs === '+') { return `${m} [${m} ...]`; }
1605
+ if (a.nargs === 'A...') { return `${m} ...`; }
1606
+ return Array(a.nargs).fill(m).join(' ');
1607
+ }
1608
+ _usageParts(actions) {
1609
+ const inGroup = new Map();
1610
+ for (const g of this._groups) {
1611
+ const idx = g.actions.map((x) => actions.indexOf(x));
1612
+ if (idx[0] >= 0 && idx.every((v, k) => v === idx[0] + k)) { for (const x of g.actions) { inGroup.set(x, g); } }
1613
+ }
1614
+ const parts = actions.map((a) => {
1615
+ if (a.help === SUPPRESS) { return null; }
1616
+ if (!a.option_strings.length) {
1617
+ let p = this._formatArgs(a, a.dest);
1618
+ if (inGroup.has(a) && p.startsWith('[') && p.endsWith(']')) { p = p.slice(1, -1); }
1619
+ return p;
1620
+ }
1621
+ let p = a.nargs === 0 ? a.option_strings[0] : `${a.option_strings[0]} ${this._formatArgs(a, a.dest.toUpperCase())}`;
1622
+ if (!a.required && !inGroup.has(a)) { p = `[${p}]`; }
1623
+ return p;
1624
+ });
1625
+ for (const g of this._groups) {
1626
+ const idx = g.actions.map((x) => actions.indexOf(x));
1627
+ if (!(idx[0] >= 0 && idx.every((v, k) => v === idx[0] + k))) { continue; }
1628
+ const [open, close] = g.required ? (g.actions.length > 1 ? ['(', ')'] : ['', '']) : ['[', ']'];
1629
+ const s = idx[0]; const e = s + g.actions.length - 1;
1630
+ parts[s] = open + parts[s];
1631
+ parts[e] = parts[e] + close;
1632
+ for (let k = s; k < e; k++) { parts[k] += ' |'; }
1633
+ }
1634
+ return parts.filter((p) => p !== null);
1635
+ }
1636
+
1637
+ /** format_usage() (with the "usage: " prefix and no trailing newlines). */
1638
+ format_usage() {
1639
+ const prefix = 'usage: ';
1640
+ if (this.usage !== null) { return prefix + this.usage.replace(/%\(prog\)s/g, this.prog); }
1641
+ const width = termWidth() - 2;
1642
+ const opts = this._actions.filter((a) => a.option_strings.length);
1643
+ const poss = this._actions.filter((a) => !a.option_strings.length);
1644
+ const all = this._usageParts([...opts, ...poss]);
1645
+ let usage = [this.prog, all.join(' ')].filter((s) => s).join(' ');
1646
+ if (prefix.length + usage.length > width) {
1647
+ const optParts = this._usageParts(opts); const posParts = this._usageParts(poss);
1648
+ const getLines = (parts, indent, pfx) => {
1649
+ const lines = []; let line = []; let len = pfx !== undefined ? pfx.length - 1 : indent.length - 1;
1650
+ for (const part of parts) {
1651
+ if (len + 1 + part.length > width && line.length) { lines.push(indent + line.join(' ')); line = []; len = indent.length - 1; }
1652
+ line.push(part); len += part.length + 1;
1653
+ }
1654
+ if (line.length) { lines.push(indent + line.join(' ')); }
1655
+ if (pfx !== undefined) { lines[0] = lines[0].slice(indent.length); }
1656
+ return lines;
1657
+ };
1658
+ let lines;
1659
+ if (prefix.length + this.prog.length <= 0.75 * width) {
1660
+ const indent = ' '.repeat(prefix.length + this.prog.length + 1);
1661
+ if (optParts.length) { lines = getLines([this.prog, ...optParts], indent, prefix); lines.push(...getLines(posParts, indent)); }
1662
+ else if (posParts.length) { lines = getLines([this.prog, ...posParts], indent, prefix); } else { lines = [this.prog]; }
1663
+ } else {
1664
+ const indent = ' '.repeat(prefix.length);
1665
+ lines = getLines([...optParts, ...posParts], indent);
1666
+ if (lines.length > 1) { lines = [...getLines(optParts, indent), ...getLines(posParts, indent)]; }
1667
+ lines = [this.prog, ...lines];
1668
+ }
1669
+ usage = lines.join('\n');
1670
+ }
1671
+ return prefix + usage;
1672
+ }
1673
+
1674
+ _expandHelp(a) {
1675
+ const params = { ...a, prog: this.prog, type: a.type ? typeName(a.type) : null,
1676
+ choices: a.choices ? a.choices.map(pyStr).join(', ') : null };
1677
+ return a.help.replace(/%(?:\((\w+)\)([sdr])|%)/g, (m, k, conv) => {
1678
+ if (m === '%%') { return '%'; }
1679
+ const v = params[k];
1680
+ return conv === 'r' ? pyRepr(v) : pyStr(v);
1681
+ });
1682
+ }
1683
+
1684
+ /** format_help() (ends with one "\n"). */
1685
+ format_help() {
1686
+ const width = termWidth() - 2;
1687
+ const maxHelpPos = Math.min(24, Math.max(width - 20, 4));
1688
+ const invocation = (a) => {
1689
+ if (!a.option_strings.length) { return this._metavar(a, a.dest); }
1690
+ if (a.nargs === 0) { return a.option_strings.join(', '); }
1691
+ return a.option_strings.join(', ') + ' ' + this._formatArgs(a, a.dest.toUpperCase());
1692
+ };
1693
+ const visible = this._actions.filter((a) => a.help !== SUPPRESS);
1694
+ const maxLen = Math.max(0, ...visible.map((a) => invocation(a).length + 2));
1695
+ const helpPos = Math.min(maxLen + 2, maxHelpPos);
1696
+ const helpWidth = Math.max(width - helpPos, 11);
1697
+ const actionWidth = helpPos - 2 - 2;
1698
+ const item = (a) => {
1699
+ const inv = invocation(a);
1700
+ if (!a.help) { return ' ' + inv + '\n'; }
1701
+ let out; let first;
1702
+ if (inv.length <= actionWidth) { out = ' ' + inv.padEnd(actionWidth) + ' '; first = 0; }
1703
+ else { out = ' ' + inv + '\n'; first = helpPos; }
1704
+ const text = this._expandHelp(a);
1705
+ if (a.help.trim() && text) {
1706
+ const lines = textwrapWrap(text.replace(/[ \t\n\r\f\v]+/g, ' ').trim(), helpWidth);
1707
+ out += ' '.repeat(first) + (lines[0] ?? '') + '\n';
1708
+ for (const l of lines.slice(1)) { out += ' '.repeat(helpPos) + l + '\n'; }
1709
+ } else if (!out.endsWith('\n')) { out += '\n'; }
1710
+ return out;
1711
+ };
1712
+ let help = this.format_usage() + '\n\n';
1713
+ if (this.description !== null) {
1714
+ if (this.raw) { help += this.description.replace(/%\(prog\)s/g, this.prog) + '\n\n'; }
1715
+ else {
1716
+ help += textwrapWrap(this.description.replace(/%\(prog\)s/g, this.prog).replace(/[ \t\n\r\f\v]+/g, ' ').trim(),
1717
+ Math.max(width, 11)).join('\n') + '\n\n';
1718
+ }
1719
+ }
1720
+ const section = (title, acts) => {
1721
+ const body = acts.filter((a) => a.help !== SUPPRESS).map(item).join('');
1722
+ return body ? '\n' + title + ':\n' + body + '\n' : '';
1723
+ };
1724
+ help += section('positional arguments', this._actions.filter((a) => !a.option_strings.length));
1725
+ help += section('options', this._actions.filter((a) => a.option_strings.length));
1726
+ help = help.replace(/\n\n\n+/g, '\n\n');
1727
+ return help.replace(/^\n+|\n+$/g, '') + '\n';
1728
+ }
1729
+
1730
+ /** print_help() to stdout. */
1731
+ print_help() { fs.writeSync(1, toNative(this.format_help())); }
1732
+
1733
+ /** error(message): usage + "prog: error: message" on stderr, exit 2. */
1734
+ error(message) {
1735
+ fs.writeSync(2, toNative(this.format_usage() + '\n' + `${this.prog}: error: ${message}\n`));
1736
+ process.exit(2);
1737
+ }
1738
+
1739
+ _optMap() {
1740
+ const m = new Map();
1741
+ for (const a of this._actions) { for (const s of a.option_strings) { m.set(s, a); } }
1742
+ return m;
1743
+ }
1744
+
1745
+ _parseOptional(arg, optMap) {
1746
+ if (!arg || arg[0] !== '-') { return null; }
1747
+ if (optMap.has(arg)) { return [[optMap.get(arg), arg, null, null]]; }
1748
+ if (arg.length === 1) { return null; }
1749
+ const eq = arg.indexOf('=');
1750
+ if (eq >= 0 && optMap.has(arg.slice(0, eq))) { return [[optMap.get(arg.slice(0, eq)), arg.slice(0, eq), '=', arg.slice(eq + 1)]]; }
1751
+ const result = [];
1752
+ const [prefix, sep, explicit] = eq >= 0 ? [arg.slice(0, eq), '=', arg.slice(eq + 1)] : [arg, null, null];
1753
+ if (arg[1] === '-') {
1754
+ if (this.allow_abbrev) { for (const [s, a] of optMap) { if (s.startsWith(prefix)) { result.push([a, s, sep, explicit]); } } }
1755
+ } else {
1756
+ const shortPrefix = arg.slice(0, 2); const shortExplicit = arg.slice(2);
1757
+ for (const [s, a] of optMap) {
1758
+ if (s === shortPrefix) { result.push([a, s, '', shortExplicit]); }
1759
+ else if (this.allow_abbrev && s.startsWith(prefix)) { result.push([a, s, sep, explicit]); }
1760
+ }
1761
+ }
1762
+ if (result.length) { return result; }
1763
+ if (/^-\d+$|^-\d*\.\d+$/.test(arg)) { return null; }
1764
+ if (arg.includes(' ')) { return null; }
1765
+ return [[null, arg, null, null]];
1766
+ }
1767
+
1768
+ _nargsPattern(a) {
1769
+ const opt = a.option_strings.length > 0;
1770
+ const n = a.nargs;
1771
+ if (n === null) { return opt ? '([A])' : '(-*A-*)'; }
1772
+ if (n === '?') { return opt ? '(A?)' : '(-*A?-*)'; }
1773
+ if (n === '*') { return opt ? '(A*)' : '(-*[A-]*)'; }
1774
+ if (n === '+') { return opt ? '(A+)' : '(-*A[A-]*)'; }
1775
+ if (n === 'A...') { return opt ? '(A[AO]*)' : '(-*A[-AO]*)'; }
1776
+ return opt ? `([AO]{${n}})` : `((?:-*A){${n}}-*)`;
1777
+ }
1778
+
1779
+ _matchArgument(a, pattern) {
1780
+ const m = new RegExp('^' + this._nargsPattern(a)).exec(pattern);
1781
+ if (!m) {
1782
+ const msgs = { null: 'expected one argument', '?': 'expected at most one argument', '+': 'expected at least one argument' };
1783
+ const msg = msgs[String(a.nargs)] ?? (a.nargs === 1 ? 'expected 1 argument' : `expected ${a.nargs} arguments`);
1784
+ throw new ArgumentError(a, msg);
1785
+ }
1786
+ return m[1].length;
1787
+ }
1788
+
1789
+ _getValue(a, s) {
1790
+ const t = a.type;
1791
+ if (t === null || t === undefined) { return s; }
1792
+ const fn = t === 'int' ? toInt : t === 'float' ? toFloat : t;
1793
+ try { return fn(s); } catch (e) {
1794
+ if (e && e.name === 'ArgumentTypeError') { throw new ArgumentError(a, e.message); }
1795
+ throw new ArgumentError(a, `invalid ${typeName(t)} value: ${pyRepr(s)}`);
1796
+ }
1797
+ }
1798
+
1799
+ _checkValue(a, v) {
1800
+ if (a.choices !== null && !a.choices.some((c) => pyEq(c, v))) {
1801
+ throw new ArgumentError(a, `invalid choice: ${pyRepr(pyStr(v))} (choose from ${a.choices.map(pyStr).join(', ')})`);
1802
+ }
1803
+ }
1804
+
1805
+ _getValues(a, args) {
1806
+ let v;
1807
+ if (!args.length && a.nargs === '?') {
1808
+ v = a.option_strings.length ? a.const : a.default;
1809
+ if (typeof v === 'string' && v !== SUPPRESS) { v = this._getValue(a, v); this._checkValue(a, v); }
1810
+ } else if (!args.length && a.nargs === '*' && !a.option_strings.length) {
1811
+ if (a.default !== null) { v = a.default; this._checkValue(a, v); } else { v = args; }
1812
+ } else if (args.length === 1 && (a.nargs === null || a.nargs === '?')) {
1813
+ v = this._getValue(a, args[0]); this._checkValue(a, v);
1814
+ } else if (a.nargs === 'A...') {
1815
+ v = args.map((x) => this._getValue(a, x)); this._checkValue(a, v[0]);
1816
+ } else if (a.nargs === 0) {
1817
+ v = []; // store_true & co. ignore values
1818
+ } else {
1819
+ v = args.map((x) => this._getValue(a, x)); for (const x of v) { this._checkValue(a, x); }
1820
+ }
1821
+ return v;
1822
+ }
1823
+
1824
+ /** parse_known_args(argv) -> [namespace, extras] (errors exit 2 unless exit_on_error=false). */
1825
+ parse_known_args(argv = process.argv.slice(2), namespace = null) {
1826
+ const ns = namespace ?? {};
1827
+ for (const a of this._actions) {
1828
+ if (a.dest !== SUPPRESS && !Object.hasOwn(ns, a.dest) && a.default !== SUPPRESS) { ns[a.dest] = a.default; }
1829
+ }
1830
+ try { return this._parseKnown([...argv], ns); } catch (e) {
1831
+ if (!(e instanceof ArgumentError) || !this.exit_on_error) { throw e; }
1832
+ this.error(e.message);
1833
+ }
1834
+ return null;
1835
+ }
1836
+
1837
+ /** parse_args(argv) -> namespace object keyed by dest. */
1838
+ parse_args(argv = process.argv.slice(2)) {
1839
+ const [ns, extras] = this.parse_known_args(argv);
1840
+ if (extras.length) {
1841
+ const msg = `unrecognized arguments: ${extras.join(' ')}`;
1842
+ if (this.exit_on_error) { this.error(msg); }
1843
+ throw new ArgumentError(null, msg);
1844
+ }
1845
+ return ns;
1846
+ }
1847
+
1848
+ _parseKnown(argStrings, ns) {
1849
+ const optMap = this._optMap();
1850
+ const conflicts = new Map();
1851
+ for (const g of this._groups) {
1852
+ g.actions.forEach((a, i) => {
1853
+ const c = conflicts.get(a) ?? [];
1854
+ c.push(...g.actions.slice(0, i), ...g.actions.slice(i + 1));
1855
+ conflicts.set(a, c);
1856
+ });
1857
+ }
1858
+ const optionIdx = new Map();
1859
+ let pattern = '';
1860
+ for (let i = 0; i < argStrings.length; i++) {
1861
+ if (argStrings[i] === '--') {
1862
+ pattern += '-';
1863
+ for (i++; i < argStrings.length; i++) { pattern += 'A'; }
1864
+ break;
1865
+ }
1866
+ const t = this._parseOptional(argStrings[i], optMap);
1867
+ if (t === null) { pattern += 'A'; } else { optionIdx.set(i, t); pattern += 'O'; }
1868
+ }
1869
+ const seen = new Set();
1870
+ const seenNonDefault = new Set();
1871
+ const extras = [];
1872
+ const takeAction = (a, args, optionString = null) => {
1873
+ seen.add(a);
1874
+ const values = this._getValues(a, args);
1875
+ if (a.option_strings.length || args.length) {
1876
+ seenNonDefault.add(a);
1877
+ for (const c of conflicts.get(a) ?? []) {
1878
+ if (seenNonDefault.has(c)) { throw new ArgumentError(a, `not allowed with argument ${actionName(c)}`); }
1879
+ }
1880
+ }
1881
+ if (values === SUPPRESS) { return; }
1882
+ switch (a.action) {
1883
+ case 'store': ns[a.dest] = values; break;
1884
+ case 'store_const': case 'store_true': case 'store_false': ns[a.dest] = a.const; break;
1885
+ case 'append': ns[a.dest] = [...(ns[a.dest] ?? []), values]; break;
1886
+ case 'append_const': ns[a.dest] = [...(ns[a.dest] ?? []), a.const]; break;
1887
+ case 'count': ns[a.dest] = (ns[a.dest] ?? 0) + 1; break;
1888
+ case 'help': this.print_help(); process.exit(0); break;
1889
+ case 'parsers': {
1890
+ const [name, ...rest] = values;
1891
+ if (a.dest !== SUPPRESS) { ns[a.dest] = name; }
1892
+ const sub = a.parsers.get(name);
1893
+ const [subNs, subExtras] = sub.parse_known_args(rest, null);
1894
+ Object.assign(ns, subNs);
1895
+ extras.push(...subExtras);
1896
+ break;
1897
+ }
1898
+ default: throw new Error('unsupported action ' + a.action);
1899
+ }
1900
+ void optionString;
1901
+ };
1902
+ const consumeOptional = (start) => {
1903
+ const tuples = optionIdx.get(start);
1904
+ if (tuples.length > 1) {
1905
+ throw new ArgumentError(null, `ambiguous option: ${argStrings[start]} could match ${tuples.map((t) => t[1]).join(', ')}`);
1906
+ }
1907
+ let [a, optionString, sep, explicit] = tuples[0];
1908
+ const actionTuples = [];
1909
+ let stop;
1910
+ for (;;) {
1911
+ if (a === null) { extras.push(argStrings[start]); return start + 1; }
1912
+ if (explicit !== null) {
1913
+ const count = this._matchArgument(a, 'A');
1914
+ if (count === 0 && optionString[1] !== '-' && explicit !== '') {
1915
+ if (sep || explicit[0] === '-') { throw new ArgumentError(a, `ignored explicit argument ${pyRepr(explicit)}`); }
1916
+ actionTuples.push([a, [], optionString]);
1917
+ optionString = '-' + explicit[0];
1918
+ if (optMap.has(optionString)) {
1919
+ a = optMap.get(optionString);
1920
+ explicit = explicit.slice(1);
1921
+ if (!explicit) { sep = explicit = null; } else if (explicit[0] === '=') { sep = '='; explicit = explicit.slice(1); } else { sep = ''; }
1922
+ } else { extras.push('-' + explicit); stop = start + 1; break; }
1923
+ } else if (count === 1) { stop = start + 1; actionTuples.push([a, [explicit], optionString]); break; }
1924
+ else { throw new ArgumentError(a, `ignored explicit argument ${pyRepr(explicit)}`); }
1925
+ } else {
1926
+ const s = start + 1;
1927
+ const count = this._matchArgument(a, pattern.slice(s));
1928
+ stop = s + count;
1929
+ actionTuples.push([a, argStrings.slice(s, stop), optionString]);
1930
+ break;
1931
+ }
1932
+ }
1933
+ for (const [act, args, os] of actionTuples) { takeAction(act, args, os); }
1934
+ return stop;
1935
+ };
1936
+ let positionals = this._actions.filter((a) => !a.option_strings.length);
1937
+ const consumePositionals = (start) => {
1938
+ const sel = pattern.slice(start);
1939
+ let counts = [];
1940
+ for (let k = positionals.length; k > 0; k--) {
1941
+ const m = new RegExp('^' + positionals.slice(0, k).map((a) => this._nargsPattern(a)).join('')).exec(sel);
1942
+ if (m) {
1943
+ counts = m.slice(1).map((x) => x.length);
1944
+ if (m[0].length < sel.length && sel[m[0].length] === 'O') { while (counts.length && !counts[counts.length - 1]) { counts.pop(); } }
1945
+ break;
1946
+ }
1947
+ }
1948
+ counts.forEach((n, k) => {
1949
+ const a = positionals[k];
1950
+ const args = argStrings.slice(start, start + n);
1951
+ if (a.nargs === 'A...') { if (pattern[start] === '-') { args.splice(args.indexOf('--'), 1); } }
1952
+ else if (pattern.slice(start, start + n).includes('-')) { args.splice(args.indexOf('--'), 1); }
1953
+ start += n;
1954
+ takeAction(a, args);
1955
+ });
1956
+ positionals = positionals.slice(counts.length);
1957
+ return start;
1958
+ };
1959
+ let start = 0;
1960
+ const maxOpt = optionIdx.size ? Math.max(...optionIdx.keys()) : -1;
1961
+ while (start <= maxOpt) {
1962
+ let next = start;
1963
+ while (next <= maxOpt && !optionIdx.has(next)) { next++; }
1964
+ if (start !== next) {
1965
+ const end = consumePositionals(start);
1966
+ if (end > start) { start = end; continue; }
1967
+ start = end;
1968
+ }
1969
+ if (!optionIdx.has(start)) { extras.push(...argStrings.slice(start, next)); start = next; }
1970
+ start = consumeOptional(start);
1971
+ }
1972
+ const stopIndex = consumePositionals(start);
1973
+ extras.push(...argStrings.slice(stopIndex));
1974
+ const required = [];
1975
+ for (const a of this._actions) {
1976
+ if (seen.has(a)) { continue; }
1977
+ if (a.required) { required.push(actionName(a)); }
1978
+ else if (typeof a.default === 'string' && a.default !== SUPPRESS && Object.hasOwn(ns, a.dest) && ns[a.dest] === a.default) {
1979
+ ns[a.dest] = this._getValue(a, a.default);
1980
+ }
1981
+ }
1982
+ if (required.length) { throw new ArgumentError(null, `the following arguments are required: ${required.join(', ')}`); }
1983
+ for (const g of this._groups) {
1984
+ if (g.required && !g.actions.some((a) => seenNonDefault.has(a))) {
1985
+ throw new ArgumentError(null, `one of the arguments ${g.actions.filter((a) => a.help !== SUPPRESS).map(actionName).join(' ')} is required`);
1986
+ }
1987
+ }
1988
+ return [ns, extras];
1989
+ }
1990
+ }
1991
+
1992
+ // ------------------------------------------------------------------ appended (phase 2B)
1993
+
1994
+ /**
1995
+ * SystemExit(code): code null -> exit 0; integer -> that status; anything else -> str(code)
1996
+ * printed on stderr and exit 1 (CPython's handling of an uncaught SystemExit).
1997
+ */
1998
+ export class SystemExit extends Error {
1999
+ constructor(code = null) {
2000
+ super(code === null || code === undefined ? '' : pyStr(code));
2001
+ this.name = 'SystemExit'; this.code = code ?? null;
2002
+ }
2003
+ }
2004
+
2005
+ /** Exit the process the way CPython does for an uncaught SystemExit `e`. */
2006
+ export function exitFor(e) {
2007
+ const c = e.code;
2008
+ if (c === null || c === undefined) { process.exit(0); }
2009
+ if (typeof c === 'number' && Number.isInteger(c)) { process.exit(c); }
2010
+ if (typeof c === 'boolean') { process.exit(c ? 1 : 0); }
2011
+ fs.writeSync(2, toNative(pyStr(c) + '\n'));
2012
+ process.exit(1);
2013
+ }
2014
+
2015
+ /** Run main(): an escaping SystemExit exits like Python; other errors print and exit 1. */
2016
+ export function runMain(main) {
2017
+ try { main(); } catch (e) {
2018
+ if (e instanceof SystemExit) { exitFor(e); }
2019
+ throw e;
2020
+ }
2021
+ }
2022
+
2023
+ /** copy.deepcopy for json-ish values (dict key order incl. KEY_ORDER kept; PyFloat shared). */
2024
+ export function deepCopy(v) {
2025
+ if (v === null || typeof v !== 'object' || v instanceof PyFloat) { return v; }
2026
+ if (Array.isArray(v)) { return v.map(deepCopy); }
2027
+ if (v instanceof Map) { return new Map([...v].map(([k, x]) => [k, deepCopy(x)])); }
2028
+ if (v instanceof Set) { return new Set(v); }
2029
+ const o = {};
2030
+ for (const k of keysOf(v)) { dset(o, k, deepCopy(v[k])); }
2031
+ return o;
2032
+ }
2033
+
2034
+ // ------------------------------------------------------------------ appended (phase 2A)
2035
+
2036
+ /** Path(p).is_absolute() (Windows: needs drive and root, or UNC). */
2037
+ export function pIsAbsolute(p) {
2038
+ const s = splitPath(p);
2039
+ return IS_WIN ? !!(s.drive && (s.root || s.drive.startsWith('\\\\'))) : !!s.root;
2040
+ }
2041
+
2042
+ /** os.path.relpath(p, start=cwd); ValueError "path is on mount 'X:', start on mount 'Y:'" across drives. */
2043
+ export function osRelpath(p, start = null) {
2044
+ const P = IS_WIN ? path.win32 : path.posix;
2045
+ const sep = IS_WIN ? '\\' : '/';
2046
+ const startAbs = P.resolve(String(start ?? '.')); const pathAbs = P.resolve(String(p));
2047
+ const split = (x) => {
2048
+ if (!IS_WIN) { return ['', x.replace(/^\/+/, '')]; }
2049
+ const unc = /^\\\\[^\\]+\\[^\\]+/.exec(x);
2050
+ const drive = unc ? unc[0] : /^[A-Za-z]:/.test(x) ? x.slice(0, 2) : '';
2051
+ return [drive, x.slice(drive.length).replace(/^\\+/, '')];
2052
+ };
2053
+ const [sd, sr] = split(startAbs); const [pd, pr] = split(pathAbs);
2054
+ const nc = (x) => (IS_WIN ? x.toLowerCase() : x);
2055
+ if (nc(sd) !== nc(pd)) { throw new PyValueError(`path is on mount ${strRepr(pd)}, start on mount ${strRepr(sd)}`); }
2056
+ const sl = sr ? sr.split(sep) : []; const pl = pr ? pr.split(sep) : [];
2057
+ let i = 0;
2058
+ while (i < sl.length && i < pl.length && nc(sl[i]) === nc(pl[i])) { i++; }
2059
+ const rel = [...Array(sl.length - i).fill('..'), ...pl.slice(i)];
2060
+ return rel.length ? rel.join(sep) : '.';
2061
+ }
2062
+
2063
+ /** urllib.parse.quote(s, safe='/') on the UTF-8 bytes (always safe: A-Za-z0-9_.-~). */
2064
+ export function urlQuote(s, safe = '/') {
2065
+ const ok = new Set([...'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~', ...safe].map((c) => c.charCodeAt(0)));
2066
+ let out = '';
2067
+ for (const b of Buffer.from(String(s), 'utf8')) { out += ok.has(b) ? String.fromCharCode(b) : '%' + b.toString(16).toUpperCase().padStart(2, '0'); }
2068
+ return out;
2069
+ }
2070
+
2071
+ /** Path(p).as_uri() (absolute paths only; ValueError otherwise). */
2072
+ export function pAsUri(p) {
2073
+ if (!pIsAbsolute(p)) { throw new PyValueError("relative path can't be expressed as a file URI"); }
2074
+ const s = splitPath(p); const posix = pathStr(p).replace(/\\/g, '/');
2075
+ if (s.drive.length === 2 && s.drive[1] === ':') { return 'file:///' + s.drive + urlQuote(posix.slice(2)); }
2076
+ if (s.drive) { return 'file:' + urlQuote(posix); }
2077
+ return 'file://' + urlQuote(pathStr(p));
2078
+ }
2079
+
2080
+ // ------------------------------------------------------------------ block-buffered stdout
2081
+ // CPython block-buffers stdout when it is not a TTY (8 KiB), so a stage's few stdout lines
2082
+ // reach a merged stdout+stderr pipe AFTER its stderr lines. pyPrintBuf mirrors that: the text
2083
+ // is held until 8192 bytes accumulate or the process exits (TTY: written immediately).
2084
+ let _stdoutBuf = '';
2085
+ let _stdoutHooked = false;
2086
+ /** Write any pending pyPrintBuf output now (sys.stdout.flush()). */
2087
+ export function pyFlushStdout() {
2088
+ if (_stdoutBuf) { const s = _stdoutBuf; _stdoutBuf = ''; fs.writeSync(1, s); }
2089
+ }
2090
+ /** print(*args) with CPython's piped-stdout block buffering (see above). */
2091
+ export function pyPrintBuf(...args) {
2092
+ const s = toNative(args.map(pyStr).join(' ') + '\n');
2093
+ if (process.stdout.isTTY) { fs.writeSync(1, s); return; }
2094
+ if (!_stdoutHooked) { _stdoutHooked = true; process.on('exit', pyFlushStdout); }
2095
+ _stdoutBuf += s;
2096
+ if (Buffer.byteLength(_stdoutBuf, 'utf8') >= 8192) { pyFlushStdout(); }
2097
+ }
2098
+
2099
+ // ------------------------------------------------------------------ str-set iteration order
2100
+ // CPython 3.13 set iteration order for str members under PYTHONHASHSEED=0 (the pipeline's
2101
+ // setting): str hash = siphash13 with an all-zero key over the PEP 393 buffer (1/2/4 bytes per
2102
+ // char), set table = open addressing (LINEAR_PROBES=9, perturb>>=5, i = i*5+1+perturb),
2103
+ // MINSIZE 8, resize to the smallest power of 2 > used*4 when fill*5 >= mask*3.
2104
+ const M64 = (1n << 64n) - 1n;
2105
+ const rotl = (x, b) => ((x << b) | (x >> (64n - b))) & M64;
2106
+ function sipRound(v) {
2107
+ v[0] = (v[0] + v[1]) & M64; v[2] = (v[2] + v[3]) & M64;
2108
+ v[1] = rotl(v[1], 13n) ^ v[0]; v[3] = rotl(v[3], 16n) ^ v[2]; v[0] = rotl(v[0], 32n);
2109
+ v[2] = (v[2] + v[1]) & M64; v[0] = (v[0] + v[3]) & M64;
2110
+ v[1] = rotl(v[1], 17n) ^ v[2]; v[3] = rotl(v[3], 21n) ^ v[0]; v[2] = rotl(v[2], 32n);
2111
+ }
2112
+ /** hash(s) for a Python str under PYTHONHASHSEED=0, as an unsigned 64-bit BigInt. */
2113
+ export function pyStrHash0(s) {
2114
+ const cps = [...String(s)].map((c) => c.codePointAt(0));
2115
+ if (!cps.length) { return 0n; }
2116
+ const mx = Math.max(...cps);
2117
+ const kind = mx < 0x100 ? 1 : mx < 0x10000 ? 2 : 4;
2118
+ const buf = Buffer.alloc(cps.length * kind);
2119
+ cps.forEach((c, i) => { if (kind === 1) { buf[i] = c; } else if (kind === 2) { buf.writeUInt16LE(c, i * 2); } else { buf.writeUInt32LE(c, i * 4); } });
2120
+ const v = [0x736f6d6570736575n, 0x646f72616e646f6dn, 0x6c7967656e657261n, 0x7465646279746573n];
2121
+ let n = buf.length; let off = 0;
2122
+ const b0 = (BigInt(n) << 56n) & M64;
2123
+ while (n >= 8) { const mi = buf.readBigUInt64LE(off); off += 8; n -= 8; v[3] ^= mi; sipRound(v); v[0] ^= mi; }
2124
+ let t = 0n;
2125
+ for (let i = n - 1; i >= 0; i--) { t = (t << 8n) | BigInt(buf[off + i]); }
2126
+ const b = b0 | t;
2127
+ v[3] ^= b; sipRound(v); v[0] ^= b;
2128
+ v[2] ^= 0xffn; sipRound(v); sipRound(v); sipRound(v);
2129
+ let h = (v[0] ^ v[1]) ^ (v[2] ^ v[3]);
2130
+ if (h === M64) { h = M64 - 1n; } // -1 is reserved -> -2
2131
+ return h;
2132
+ }
2133
+ /**
2134
+ * Iteration order of a Python set of str built by adding `items` in order (duplicates
2135
+ * ignored), i.e. `list(set(items))` / `for x in s` under PYTHONHASHSEED=0. Add-only (no
2136
+ * discard). For a set comprehension over another set, call it again on the filtered order.
2137
+ */
2138
+ export function pyStrSetOrder(items) {
2139
+ let mask = 7; let table = new Array(8).fill(null); let fill = 0;
2140
+ const hashes = new Map();
2141
+ const place = (tbl, m, key, h) => {
2142
+ let perturb = h; let i = Number(h & BigInt(m));
2143
+ for (;;) {
2144
+ if (tbl[i] === null) { return i; }
2145
+ if (tbl[i] === key) { return -1; }
2146
+ if (i + 9 <= m) {
2147
+ for (let j = 1; j <= 9; j++) {
2148
+ if (tbl[i + j] === null) { return i + j; }
2149
+ if (tbl[i + j] === key) { return -1; }
2150
+ }
2151
+ }
2152
+ perturb >>= 5n;
2153
+ i = Number((BigInt(i) * 5n + 1n + perturb) & BigInt(m));
2154
+ }
2155
+ };
2156
+ for (const raw of items) {
2157
+ const key = String(raw);
2158
+ if (!hashes.has(key)) { hashes.set(key, pyStrHash0(key)); }
2159
+ const at = place(table, mask, key, hashes.get(key));
2160
+ if (at < 0) { continue; }
2161
+ table[at] = key; fill++;
2162
+ if (fill * 5 >= mask * 3) {
2163
+ let size = 8; while (size <= fill * 4) { size <<= 1; }
2164
+ const old = table; table = new Array(size).fill(null); mask = size - 1;
2165
+ for (const k of old) { if (k !== null) { table[place(table, mask, k, hashes.get(k))] = k; } }
2166
+ }
2167
+ }
2168
+ return table.filter((k) => k !== null);
2169
+ }
2170
+ /** Python iteration order of the str set held in `s` (a JS Set/array in Python insertion order). */
2171
+ export function pySetIter(s) { return pyStrSetOrder([...s]); }
2172
+ /** Python iteration order of `a & b` for str sets (CPython iterates the smaller operand, b on a tie). */
2173
+ export function pyIntersectOrder(a, b) {
2174
+ const A = new Set(a); const B = new Set(b);
2175
+ const [it, other] = B.size > A.size ? [A, B] : [B, A];
2176
+ return pyStrSetOrder(pySetIter(it).filter((x) => other.has(x)));
2177
+ }