android2harmony 0.1.7 → 0.1.8

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 (226) hide show
  1. package/agents/api-analyzer.md +113 -0
  2. package/agents/app-action.md +122 -0
  3. package/agents/code-reviewer.md +191 -295
  4. package/agents/coder.md +377 -0
  5. package/agents/self-tester.md +8 -8
  6. package/agents/spec-designer.md +56 -0
  7. package/package.json +1 -1
  8. package/skills/a2h-app-req-gen/SKILL.md +174 -0
  9. package/skills/a2h-app-req-gen/references/spec-handoff.md +99 -0
  10. package/skills/a2h-app-req-gen/references/subagent-render.md +115 -0
  11. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/build.gradle.kts +41 -0
  12. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/gradle/wrapper/gradle-wrapper.jar +0 -0
  13. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/gradle/wrapper/gradle-wrapper.properties +8 -0
  14. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/gradle.properties +3 -0
  15. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/gradlew +251 -0
  16. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/gradlew.bat +94 -0
  17. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/settings.gradle.kts +17 -0
  18. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/src/main/java/dev/reqgen/analyzer/jvm/RawAnalysisDetector.java +1911 -0
  19. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/src/main/java/dev/reqgen/analyzer/jvm/RawIssueRegistry.java +37 -0
  20. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/src/main/java/dev/reqgen/analyzer/jvm/RawJson.java +146 -0
  21. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/src/main/java/dev/reqgen/analyzer/jvm/RawLocation.java +96 -0
  22. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/src/main/java/dev/reqgen/analyzer/jvm/RawRecordWriter.java +227 -0
  23. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/src/main/resources/META-INF/services/com.android.tools.lint.client.api.IssueRegistry +1 -0
  24. package/skills/a2h-app-req-gen/scripts/reqgen/analyzer-jvm/src/main/resources/dev/reqgen/analyzer/jvm/raw-record-v1.schema.json +93 -0
  25. package/skills/a2h-app-req-gen/scripts/reqgen/assets/dashboard.html +151 -0
  26. package/skills/a2h-app-req-gen/scripts/reqgen/gradle/reqgen-lint.init.gradle +60 -0
  27. package/skills/a2h-app-req-gen/scripts/reqgen/gradle/reqgen-model.init.gradle +204 -0
  28. package/skills/a2h-app-req-gen/scripts/reqgen/package.json +14 -0
  29. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/backend.js +323 -0
  30. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/cli.js +811 -0
  31. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/gap-audit-link.js +62 -0
  32. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/index.js +66 -0
  33. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/merge.js +605 -0
  34. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/name-trace.js +153 -0
  35. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/orchestrate.js +1324 -0
  36. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/output-parse.js +50 -0
  37. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/overview.js +10 -0
  38. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/pool.js +23 -0
  39. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/post-merge-fix.js +146 -0
  40. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/prompt-loader.js +51 -0
  41. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/prompt.js +967 -0
  42. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/prompts.md +301 -0
  43. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/serve.js +78 -0
  44. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/short-id.js +46 -0
  45. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/snapshot.js +267 -0
  46. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/types.js +1 -0
  47. package/skills/a2h-app-req-gen/scripts/reqgen/src/agent-render/validate.js +122 -0
  48. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/callback-call-sites.js +62 -0
  49. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/gap-audit/build.js +1291 -0
  50. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/gap-audit/index.js +1 -0
  51. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/graph/area-ownership.js +392 -0
  52. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/graph/build.js +1995 -0
  53. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/graph/callback-flow.js +277 -0
  54. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/graph/component-variants.js +725 -0
  55. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/graph/index.js +15 -0
  56. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/names/index.js +12 -0
  57. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/names/policy.js +469 -0
  58. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/names/traceability.js +468 -0
  59. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/req-model/build.js +1066 -0
  60. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/req-model/index.js +1 -0
  61. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/android-interaction-registry.js +174 -0
  62. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/android.js +1062 -0
  63. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/area-titles.js +678 -0
  64. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/builder.js +350 -0
  65. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/compose-api-registry.js +395 -0
  66. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/compose-call-sites.js +2008 -0
  67. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/compose.js +9059 -0
  68. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/dynamic-repeated-call-sites.js +529 -0
  69. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/index.js +1 -0
  70. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/interaction-effects.js +1149 -0
  71. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/jvm.js +6272 -0
  72. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/normalize.js +33 -0
  73. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/pending-intents.js +565 -0
  74. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/resource-id.js +42 -0
  75. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/route-state-variants.js +781 -0
  76. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/state.js +234 -0
  77. package/skills/a2h-app-req-gen/scripts/reqgen/src/analysis/source-facts/types.js +1 -0
  78. package/skills/a2h-app-req-gen/scripts/reqgen/src/android/extract.js +40 -0
  79. package/skills/a2h-app-req-gen/scripts/reqgen/src/android/index.js +6 -0
  80. package/skills/a2h-app-req-gen/scripts/reqgen/src/android/manifest.js +513 -0
  81. package/skills/a2h-app-req-gen/scripts/reqgen/src/android/resources.js +398 -0
  82. package/skills/a2h-app-req-gen/scripts/reqgen/src/android/types.js +1 -0
  83. package/skills/a2h-app-req-gen/scripts/reqgen/src/android/views.js +447 -0
  84. package/skills/a2h-app-req-gen/scripts/reqgen/src/android/xml-parser.js +175 -0
  85. package/skills/a2h-app-req-gen/scripts/reqgen/src/cli.js +398 -0
  86. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/area-graph.js +1 -0
  87. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/artifact.js +1 -0
  88. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/common.js +16 -0
  89. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/diagnostic.js +10 -0
  90. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/gap-audit.js +14 -0
  91. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/index.js +11 -0
  92. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/name-traceability.js +26 -0
  93. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/raw-fact.js +40 -0
  94. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/req-model.js +1 -0
  95. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/run.js +19 -0
  96. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/semantic-completeness.js +11 -0
  97. package/skills/a2h-app-req-gen/scripts/reqgen/src/contracts/source-facts.js +1 -0
  98. package/skills/a2h-app-req-gen/scripts/reqgen/src/core/output-guard.js +41 -0
  99. package/skills/a2h-app-req-gen/scripts/reqgen/src/core/stable-id.js +92 -0
  100. package/skills/a2h-app-req-gen/scripts/reqgen/src/dashboard-cli.js +169 -0
  101. package/skills/a2h-app-req-gen/scripts/reqgen/src/diagnostics.js +104 -0
  102. package/skills/a2h-app-req-gen/scripts/reqgen/src/dump/dump.js +1028 -0
  103. package/skills/a2h-app-req-gen/scripts/reqgen/src/dump/index.js +1 -0
  104. package/skills/a2h-app-req-gen/scripts/reqgen/src/dump-cli.js +251 -0
  105. package/skills/a2h-app-req-gen/scripts/reqgen/src/generation/artifacts.js +49 -0
  106. package/skills/a2h-app-req-gen/scripts/reqgen/src/generation/index.js +18 -0
  107. package/skills/a2h-app-req-gen/scripts/reqgen/src/generation/quality-report.js +125 -0
  108. package/skills/a2h-app-req-gen/scripts/reqgen/src/generation/render.js +353 -0
  109. package/skills/a2h-app-req-gen/scripts/reqgen/src/generation/types.js +2 -0
  110. package/skills/a2h-app-req-gen/scripts/reqgen/src/graph/paths.js +474 -0
  111. package/skills/a2h-app-req-gen/scripts/reqgen/src/jvm/index.js +15 -0
  112. package/skills/a2h-app-req-gen/scripts/reqgen/src/jvm/protocol.js +408 -0
  113. package/skills/a2h-app-req-gen/scripts/reqgen/src/jvm/runner.js +452 -0
  114. package/skills/a2h-app-req-gen/scripts/reqgen/src/pipeline/index.js +8 -0
  115. package/skills/a2h-app-req-gen/scripts/reqgen/src/pipeline/output.js +165 -0
  116. package/skills/a2h-app-req-gen/scripts/reqgen/src/pipeline/run-stage1.js +891 -0
  117. package/skills/a2h-app-req-gen/scripts/reqgen/src/project/discovery.js +299 -0
  118. package/skills/a2h-app-req-gen/scripts/reqgen/src/project/gradle-model.js +358 -0
  119. package/skills/a2h-app-req-gen/scripts/reqgen/src/project/gradle-runner.js +165 -0
  120. package/skills/a2h-app-req-gen/scripts/reqgen/src/project/resource-profile.js +60 -0
  121. package/skills/a2h-app-req-gen/scripts/reqgen/src/project/types.js +1 -0
  122. package/skills/a2h-app-req-gen/scripts/reqgen/src/spec-handoff-cli.js +151 -0
  123. package/skills/a2h-app-req-gen/scripts/reqgen/src/spec-handoff.js +1004 -0
  124. package/skills/a2h-app-req-gen/scripts/reqgen/src/stage2-cli.js +109 -0
  125. package/skills/a2h-app-req-gen/scripts/reqgen/src/stage2-input.js +419 -0
  126. package/skills/a2h-app-req-gen/scripts/reqgen/src/stage2-name-trace-input.js +95 -0
  127. package/skills/a2h-app-req-gen/scripts/reqgen/src/validation/area-graph.js +444 -0
  128. package/skills/a2h-app-req-gen/scripts/reqgen/src/validation/index.js +7 -0
  129. package/skills/a2h-app-req-gen/scripts/reqgen/src/validation/req-model.js +580 -0
  130. package/skills/a2h-app-req-gen/scripts/reqgen/src/validation/req-text.js +195 -0
  131. package/skills/a2h-app-req-gen/scripts/reqgen/src/validation/semantic-area-graph.js +1431 -0
  132. package/skills/a2h-app-req-gen/scripts/reqgen/src/validation/types.js +1 -0
  133. package/skills/a2h-app-req-gen/scripts/reqgen-audit.mjs +298 -0
  134. package/skills/a2h-app-req-gen/scripts/reqgen-selfcheck.mjs +555 -0
  135. package/skills/a2h-code-review/SKILL.md +379 -0
  136. package/skills/{hmos-integration-test → a2h-integration-test}/README.md +6 -6
  137. package/skills/{hmos-integration-test → a2h-integration-test}/SKILL.md +6 -6
  138. package/skills/{hmos-integration-test → a2h-integration-test}/scripts/report-tool.mjs +1 -1
  139. package/skills/a2h-spec-design/SKILL.md +330 -0
  140. package/skills/a2h-spec-design/scripts/inspect_spec_design_inputs.mjs +207 -0
  141. package/skills/a2h-spec-design/scripts/move_spec_technical_reference.mjs +198 -0
  142. package/skills/a2h-spec-design/scripts/validate_spec_design_output.mjs +256 -0
  143. package/skills/a2h-spec-generate/SKILL.md +696 -0
  144. package/skills/a2h-spec-generate/references/trace-template.md +115 -0
  145. package/skills/a2h-spec-generate/scripts/parse_requirements.mjs +537 -0
  146. package/skills/a2h-spec-generate/template/REQ.txt +22 -0
  147. package/skills/a2h-spec-generate/template/REQ.xlsx +0 -0
  148. package/skills/a2h-spec-implement/SKILL.md +548 -0
  149. package/skills/a2h-spec-implement/references/harmony-pitfalls.md +186 -0
  150. package/skills/a2h-spec-implement/references/l1-unit-test.md +185 -0
  151. package/skills/a2h-spec-implement/references/l3-e2e-uitest.md +167 -0
  152. package/skills/a2h-spec-implement/references/test-core.md +132 -0
  153. package/skills/a2h-spec-implement/rules/arkts/arkts-standards.md +184 -0
  154. package/skills/a2h-spec-implement/rules/arkts/conventions/coding-style.md +96 -0
  155. package/skills/a2h-spec-implement/rules/arkts/conventions/security.md +126 -0
  156. package/skills/a2h-spec-implement/rules/arkts/language/arkts-rules.md +650 -0
  157. package/skills/a2h-spec-implement/rules/arkts/language/arkui-structure-rules.md +173 -0
  158. package/skills/a2h-spec-implement/rules/arkts/language/ts-to-arkts-rewrites.md +58 -0
  159. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -0
  160. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/@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 +2089 -0
  161. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -0
  162. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -0
  163. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -0
  164. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -0
  165. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -0
  166. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/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 +903 -0
  167. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -0
  168. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -0
  169. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -0
  170. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1/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 +355 -0
  171. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v1//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -0
  172. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +216 -0
  173. package/skills/a2h-spec-implement/rules/arkts/official/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 +442 -0
  174. package/skills/a2h-spec-implement/rules/arkts/official/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 +169 -0
  175. package/skills/a2h-spec-implement/rules/arkts/official/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 +763 -0
  176. package/skills/a2h-spec-implement/rules/arkts/official/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 +2088 -0
  177. package/skills/a2h-spec-implement/rules/arkts/official/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 +1258 -0
  178. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v2/@Once/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 +175 -0
  179. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v2/@Param/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md +850 -0
  180. package/skills/a2h-spec-implement/rules/arkts/official/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 +862 -0
  181. package/skills/a2h-spec-implement/rules/arkts/official/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 +110 -0
  182. package/skills/a2h-spec-implement/rules/arkts/official/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 +301 -0
  183. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md +1411 -0
  184. package/skills/a2h-spec-implement/rules/arkts/official/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 +1392 -0
  185. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v2/getTarget/346/216/245/345/217/243/357/274/232/350/216/267/345/217/226/347/212/266/346/200/201/347/256/241/347/220/206/346/241/206/346/236/266/344/273/243/347/220/206/345/211/215/347/232/204/345/216/237/345/247/213/345/257/271/350/261/241.md +288 -0
  186. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v2/makeObserved/346/216/245/345/217/243/357/274/232/345/260/206/351/235/236/350/247/202/345/257/237/346/225/260/346/215/256/345/217/230/344/270/272/345/217/257/350/247/202/345/257/237/346/225/260/346/215/256.md +768 -0
  187. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v2//347/212/266/346/200/201/347/256/241/347/220/206V1/345/222/214V2/346/267/267/347/224/250/346/214/207/345/257/274/357/274/210API version 19/345/217/212/344/271/213/345/220/216/357/274/211.md" +829 -0
  188. package/skills/a2h-spec-implement/rules/arkts/official/mvvm-v2//347/212/266/346/200/201/347/256/241/347/220/206/346/246/202/350/277/260.md +184 -0
  189. package/skills/a2h-spec-implement/rules/arkts/ui/component-cookbook.md +431 -0
  190. package/skills/a2h-spec-implement/rules/arkts/ui/state-management.md +152 -0
  191. package/skills/a2h-spec-implement/rules/arkts/ui/ui-quality.md +67 -0
  192. package/skills/a2h-spec-implement/rules/arkts/ui/ui-runtime-diagnosis.md +32 -0
  193. package/skills/a2h-spec-implement/rules/pipeline/build/package-set-collection.md +43 -0
  194. package/skills/a2h-spec-implement/scripts/_lib/common.mjs +97 -0
  195. package/skills/a2h-spec-implement/scripts/_lib/config.mjs +70 -0
  196. package/skills/a2h-spec-implement/scripts/_lib/lessons_cli.mjs +48 -0
  197. package/skills/a2h-spec-implement/scripts/build_lessons.mjs +24 -0
  198. package/skills/a2h-spec-implement/scripts/code_pattern_lessons.mjs +26 -0
  199. package/skills/a2h-spec-implement/scripts/device_ui.mjs +433 -0
  200. package/skills/a2h-spec-implement/scripts/device_ui_core.mjs +895 -0
  201. package/skills/a2h-spec-implement/scripts/ledger/aggregate_run.mjs +207 -0
  202. package/skills/a2h-spec-implement/scripts/manifest/emit_summary_line.mjs +37 -0
  203. package/skills/a2h-spec-implement/scripts/manifest/finalize_run.mjs +115 -0
  204. package/skills/a2h-spec-implement/scripts/manifest/render_final_summary.mjs +78 -0
  205. package/skills/a2h-spec-implement/scripts/manifest/root_mirror.mjs +137 -0
  206. package/skills/a2h-spec-implement/scripts/package.json +12 -0
  207. package/skills/a2h-spec-implement/scripts/state_propagation_check.mjs +676 -0
  208. package/skills/a2h-spec-implement/scripts/test/l2_run.mjs +244 -0
  209. package/skills/a2h-spec-implement/scripts/test/tp_coverage.mjs +231 -0
  210. package/skills/a2h-spec-implement/scripts/ui_memory.mjs +161 -0
  211. package/skills/a2h-spec-implement/scripts/utils/ensure_app.mjs +134 -0
  212. package/skills/a2h-ui-transfer/SKILL.md +2 -2
  213. package/skills/hmos-convert-pipeline/SKILL.md +7 -5
  214. package/skills/hmos-incremental-ui-align/README.md +7 -7
  215. package/skills/hmos-incremental-ui-align/SKILL.md +1 -1
  216. package/skills/hmos-incremental-ui-align/page_align.md +1 -1
  217. package/skills/hmos-spec-generate/SKILL.md +2 -2
  218. package/skills/hmos-spec-generate/scripts/parse_requirements.mjs +537 -0
  219. package/skills/hmos-fix-build-errors/SKILL.md +0 -266
  220. package/skills/hmos-fix-build-errors/references/arkts-strict-patterns.md +0 -219
  221. package/skills/hmos-fix-build-errors/references/known-patterns.md +0 -157
  222. package/skills/hmos-fix-build-errors/references/rdb-entity-pattern.md +0 -131
  223. package/skills/hmos-spec-generate/scripts/parse_requirements.ts +0 -515
  224. /package/skills/{hmos-integration-test → a2h-integration-test}/scripts/resolve-metadata-tool.mjs +0 -0
  225. /package/skills/{hmos-integration-test → a2h-integration-test}/scripts/self-test-runner.mjs +0 -0
  226. /package/skills/{hmos-integration-test → a2h-integration-test}/scripts/testcases-tool.mjs +0 -0
@@ -0,0 +1,447 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { hardFailure } from "../diagnostics.js";
4
+ import { localName, parseXml } from "./xml-parser.js";
5
+ function attribute(element, name) {
6
+ return (
7
+ element.attributes[`android:${name}`] ??
8
+ element.attributes[`app:${name}`] ??
9
+ element.attributes[name]
10
+ );
11
+ }
12
+ function referenceName(value, expectedType) {
13
+ if (!value) return undefined;
14
+ const match = /^@(?:\+)?([^/]+)\/(.+)$/u.exec(value);
15
+ if (!match) return value;
16
+ if (expectedType && match[1] !== expectedType) return undefined;
17
+ return match[2];
18
+ }
19
+ function resourceReference(raw) {
20
+ if (!raw) return undefined;
21
+ const match =
22
+ /^@(?:\+)?(?:(?<package>[^:/]+):)?(?<type>[^/]+)\/(?<name>.+)$/u.exec(raw);
23
+ const resourceType = match?.groups?.type;
24
+ const name = match?.groups?.name;
25
+ if (!resourceType || !name) return undefined;
26
+ const packageName = match?.groups?.package;
27
+ return {
28
+ raw,
29
+ resourceType,
30
+ name,
31
+ ...(packageName ? { packageName } : {}),
32
+ };
33
+ }
34
+ const iconAttributeNames = [
35
+ "src",
36
+ "srcCompat",
37
+ "icon",
38
+ "drawableStart",
39
+ "drawableEnd",
40
+ "drawableLeft",
41
+ "drawableRight",
42
+ "drawableTop",
43
+ "drawableBottom",
44
+ ];
45
+ function iconResources(element) {
46
+ const seen = new Set();
47
+ return iconAttributeNames.flatMap((name) => {
48
+ const reference = resourceReference(attribute(element, name));
49
+ if (!reference) return [];
50
+ const key = `${reference.packageName ?? ""}:${reference.resourceType}/${reference.name}`;
51
+ if (seen.has(key)) return [];
52
+ seen.add(key);
53
+ return [reference];
54
+ });
55
+ }
56
+ function evidence(resource, element, anchor) {
57
+ return {
58
+ sourceKind: "xml",
59
+ path: resource.path,
60
+ anchor,
61
+ range: {
62
+ startLine: element.startLine,
63
+ endLine: element.endLine,
64
+ },
65
+ };
66
+ }
67
+ function interactiveTag(tag, resourceType) {
68
+ const name = localName(tag).toLowerCase();
69
+ if (resourceType === "menu" && name === "item") return true;
70
+ if (
71
+ resourceType === "xml" &&
72
+ name.includes("preference") &&
73
+ !name.endsWith("preferencecategory") &&
74
+ !name.endsWith("preferencescreen")
75
+ )
76
+ return true;
77
+ return (
78
+ name === "button" ||
79
+ name === "imagebutton" ||
80
+ name === "edittext" ||
81
+ name === "checkbox" ||
82
+ name === "radiobutton" ||
83
+ name === "switch" ||
84
+ name === "switchcompat" ||
85
+ name === "togglebutton" ||
86
+ name === "spinner" ||
87
+ name === "seekbar" ||
88
+ name === "ratingbar" ||
89
+ name.endsWith("button") ||
90
+ name.endsWith("chip") ||
91
+ name.endsWith("floatingactionbutton")
92
+ );
93
+ }
94
+ function recordView(resource, element, selection, isLayoutRoot) {
95
+ const preferenceElement =
96
+ resource.resourceType === "xml" &&
97
+ localName(element.name).toLowerCase().includes("preference");
98
+ const rawPreferenceKey = preferenceElement
99
+ ? attribute(element, "key")
100
+ : undefined;
101
+ const resolvedPreferenceKey = rawPreferenceKey
102
+ ? selection.resolveAttribute(rawPreferenceKey)
103
+ : undefined;
104
+ const preferenceKey =
105
+ resolvedPreferenceKey?.resolved?.trim() ||
106
+ (!rawPreferenceKey?.startsWith("@") ? rawPreferenceKey?.trim() : undefined);
107
+ const id = referenceName(attribute(element, "id"), "id") ?? preferenceKey;
108
+ const rawText = attribute(element, "text") ?? attribute(element, "title");
109
+ const rawTextAppearance = attribute(element, "textAppearance");
110
+ const rawHint = attribute(element, "hint");
111
+ const rawDescription = attribute(element, "contentDescription");
112
+ const rawEnabled = attribute(element, "enabled");
113
+ // `checked` is the existing transport slot for a control's initial
114
+ // selection. Preference XML calls the same concept `defaultValue`.
115
+ const rawChecked =
116
+ attribute(element, "checked") ??
117
+ (preferenceElement ? attribute(element, "defaultValue") : undefined);
118
+ const rawEntries = attribute(element, "entries");
119
+ const labelFor = referenceName(attribute(element, "labelFor"), "id");
120
+ const icons = iconResources(element);
121
+ const onClick = attribute(element, "onClick");
122
+ const actionable =
123
+ Boolean(onClick) ||
124
+ attribute(element, "clickable") === "true" ||
125
+ interactiveTag(element.name, resource.resourceType);
126
+ if (
127
+ !id &&
128
+ rawText === undefined &&
129
+ rawHint === undefined &&
130
+ rawDescription === undefined &&
131
+ rawEnabled === undefined &&
132
+ rawChecked === undefined &&
133
+ rawEntries === undefined &&
134
+ !labelFor &&
135
+ icons.length === 0 &&
136
+ !onClick &&
137
+ !actionable
138
+ ) {
139
+ return undefined;
140
+ }
141
+ const anchor = `${resource.resourceType}/${resource.name}#${id ?? `${localName(element.name)}:${element.startLine}`}`;
142
+ return {
143
+ resourceType: resource.resourceType,
144
+ resourceName: resource.name,
145
+ tag: element.name,
146
+ ...(isLayoutRoot ? { isLayoutRoot: true } : {}),
147
+ ...(id ? { id } : {}),
148
+ ...(rawText !== undefined
149
+ ? { text: selection.resolveAttribute(rawText) }
150
+ : {}),
151
+ ...(rawTextAppearance
152
+ ? {
153
+ textAppearance: selection.resolveAttribute(rawTextAppearance),
154
+ }
155
+ : {}),
156
+ ...(rawHint ? { hint: selection.resolveAttribute(rawHint) } : {}),
157
+ ...(rawDescription
158
+ ? { contentDescription: selection.resolveAttribute(rawDescription) }
159
+ : {}),
160
+ ...(rawEnabled !== undefined
161
+ ? { enabled: selection.resolveAttribute(rawEnabled) }
162
+ : {}),
163
+ ...(rawChecked !== undefined
164
+ ? { checked: selection.resolveAttribute(rawChecked) }
165
+ : {}),
166
+ ...(rawEntries !== undefined
167
+ ? { entries: selection.resolveAttribute(rawEntries) }
168
+ : {}),
169
+ ...(labelFor ? { labelFor } : {}),
170
+ ...(icons.length > 0 ? { iconResources: icons } : {}),
171
+ ...(onClick ? { onClick } : {}),
172
+ actionable,
173
+ evidence: evidence(resource, element, anchor),
174
+ };
175
+ }
176
+ function fragmentClass(element) {
177
+ const tag = localName(element.name);
178
+ if (tag === "fragment") {
179
+ return attribute(element, "name") ?? element.attributes.class;
180
+ }
181
+ if (tag.endsWith("FragmentContainerView")) {
182
+ return attribute(element, "name");
183
+ }
184
+ return undefined;
185
+ }
186
+ function sourceIdentity(element) {
187
+ if (!element) return undefined;
188
+ return (
189
+ referenceName(attribute(element, "id"), "id") ??
190
+ attribute(element, "shortcutId")
191
+ );
192
+ }
193
+ function visitResource(projectRoot, resource, selection) {
194
+ const path = resolve(projectRoot, resource.path);
195
+ const root = parseXml(readFileSync(path, "utf8"));
196
+ const views = [];
197
+ const fragments = [];
198
+ const includes = [];
199
+ const navigationTargets = [];
200
+ const appWidgetInfos = [];
201
+ const visit = (element, parent) => {
202
+ const preferenceResource =
203
+ resource.resourceType === "xml" &&
204
+ localName(root.name).toLowerCase().endsWith("preferencescreen");
205
+ if (
206
+ resource.resourceType === "layout" ||
207
+ resource.resourceType === "menu" ||
208
+ preferenceResource
209
+ ) {
210
+ const view = recordView(
211
+ resource,
212
+ element,
213
+ selection,
214
+ resource.resourceType === "layout" && element === root,
215
+ );
216
+ if (view) views.push(view);
217
+ }
218
+ const className = fragmentClass(element);
219
+ if (className) {
220
+ const id = referenceName(attribute(element, "id"), "id");
221
+ const rawLabel = attribute(element, "label");
222
+ const navigationGraph = referenceName(
223
+ attribute(element, "navGraph"),
224
+ "navigation",
225
+ );
226
+ fragments.push({
227
+ resourceName: resource.name,
228
+ ...(id ? { id } : {}),
229
+ className,
230
+ ...(rawLabel ? { label: selection.resolveAttribute(rawLabel) } : {}),
231
+ ...(navigationGraph ? { navigationGraph } : {}),
232
+ evidence: evidence(
233
+ resource,
234
+ element,
235
+ `${resource.resourceType}/${resource.name}#fragment:${id ?? className}`,
236
+ ),
237
+ });
238
+ }
239
+ if (localName(element.name) === "include") {
240
+ const includedLayout = referenceName(
241
+ element.attributes.layout ?? attribute(element, "layout"),
242
+ "layout",
243
+ );
244
+ if (includedLayout) {
245
+ includes.push({
246
+ resourceName: resource.name,
247
+ includedLayout,
248
+ evidence: evidence(
249
+ resource,
250
+ element,
251
+ `${resource.resourceType}/${resource.name}#include:${includedLayout}`,
252
+ ),
253
+ });
254
+ }
255
+ }
256
+ if (localName(element.name) === "navigation") {
257
+ const destination = referenceName(
258
+ attribute(element, "startDestination"),
259
+ "id",
260
+ );
261
+ if (destination) {
262
+ navigationTargets.push({
263
+ resourceType: resource.resourceType,
264
+ resourceName: resource.name,
265
+ kind: "graph-start",
266
+ destination,
267
+ evidence: evidence(
268
+ resource,
269
+ element,
270
+ `${resource.resourceType}/${resource.name}#start:${destination}`,
271
+ ),
272
+ });
273
+ }
274
+ }
275
+ if (localName(element.name) === "action") {
276
+ const actionId = referenceName(attribute(element, "id"), "id");
277
+ const destination = referenceName(
278
+ attribute(element, "destination"),
279
+ "id",
280
+ );
281
+ if (destination) {
282
+ const sourceId = sourceIdentity(parent);
283
+ navigationTargets.push({
284
+ resourceType: resource.resourceType,
285
+ resourceName: resource.name,
286
+ kind: "navigation-action",
287
+ ...(sourceId ? { sourceId } : {}),
288
+ ...(actionId ? { actionId } : {}),
289
+ destination,
290
+ evidence: evidence(
291
+ resource,
292
+ element,
293
+ `${resource.resourceType}/${resource.name}#action:${actionId ?? sourceId ?? element.startLine}->${destination}`,
294
+ ),
295
+ });
296
+ }
297
+ }
298
+ if (localName(element.name) === "intent") {
299
+ const targetClass = attribute(element, "targetClass");
300
+ const targetPackage = attribute(element, "targetPackage");
301
+ const intentAction = attribute(element, "action");
302
+ if (targetClass || targetPackage) {
303
+ const sourceId = sourceIdentity(parent);
304
+ navigationTargets.push({
305
+ resourceType: resource.resourceType,
306
+ resourceName: resource.name,
307
+ kind: "intent",
308
+ ...(sourceId ? { sourceId } : {}),
309
+ ...(targetClass ? { targetClass } : {}),
310
+ ...(targetPackage ? { targetPackage } : {}),
311
+ ...(intentAction ? { intentAction } : {}),
312
+ evidence: evidence(
313
+ resource,
314
+ element,
315
+ `${resource.resourceType}/${resource.name}#intent:${targetClass ?? targetPackage ?? element.startLine}`,
316
+ ),
317
+ });
318
+ }
319
+ }
320
+ if (element === root && localName(element.name) === "appwidget-provider") {
321
+ const layoutResourceName = referenceName(
322
+ attribute(element, "initialLayout"),
323
+ "layout",
324
+ );
325
+ if (layoutResourceName) {
326
+ appWidgetInfos.push({
327
+ infoResourceName: resource.name,
328
+ layoutResourceName,
329
+ evidence: evidence(
330
+ resource,
331
+ element,
332
+ `${resource.resourceType}/${resource.name}#initialLayout:` +
333
+ layoutResourceName,
334
+ ),
335
+ });
336
+ }
337
+ }
338
+ element.children.forEach((child) => visit(child, element));
339
+ };
340
+ visit(root);
341
+ return {
342
+ views,
343
+ fragments,
344
+ includes,
345
+ navigationTargets,
346
+ appWidgetInfos,
347
+ };
348
+ }
349
+ function byEvidence(left, right) {
350
+ return `${left.evidence.path}:${left.evidence.range.startLine}:${left.evidence.anchor}`.localeCompare(
351
+ `${right.evidence.path}:${right.evidence.range.startLine}:${right.evidence.anchor}`,
352
+ "en",
353
+ );
354
+ }
355
+ export function extractAndroidViews(selected, selection, manifest) {
356
+ try {
357
+ const extractions = selection.resources.map((resource) =>
358
+ visitResource(selected.model.projectRoot, resource, selection),
359
+ );
360
+ const navigationTargets = extractions
361
+ .flatMap((item) => item.navigationTargets)
362
+ .sort(byEvidence);
363
+ const shortcutResources = new Set(
364
+ manifest?.components.flatMap(
365
+ (component) => component.shortcutResources ?? [],
366
+ ) ?? [],
367
+ );
368
+ const shortcutEntries = navigationTargets
369
+ .filter(
370
+ (target) =>
371
+ target.kind === "intent" &&
372
+ shortcutResources.has(target.resourceName) &&
373
+ target.sourceId !== undefined &&
374
+ target.targetClass !== undefined,
375
+ )
376
+ .map((target) => {
377
+ const targetClass = target.targetClass;
378
+ const componentName = targetClass.startsWith(".")
379
+ ? `${manifest?.packageName ?? target.targetPackage ?? ""}${targetClass}`
380
+ : targetClass.includes(".")
381
+ ? targetClass
382
+ : `${manifest?.packageName ?? target.targetPackage ?? ""}.${targetClass}`;
383
+ return {
384
+ kind: "shortcut",
385
+ category: "alternate",
386
+ componentName,
387
+ action: target.intentAction ?? "android.intent.action.VIEW",
388
+ categories: [],
389
+ data: {
390
+ shortcutId: target.sourceId,
391
+ ...(target.targetPackage
392
+ ? { targetPackage: target.targetPackage }
393
+ : {}),
394
+ },
395
+ evidence: target.evidence,
396
+ };
397
+ })
398
+ .sort((left, right) =>
399
+ `${left.componentName}:${left.data.shortcutId}`.localeCompare(
400
+ `${right.componentName}:${right.data.shortcutId}`,
401
+ "en",
402
+ ),
403
+ );
404
+ const infoByName = new Map(
405
+ extractions
406
+ .flatMap((item) => item.appWidgetInfos)
407
+ .map((item) => [item.infoResourceName, item]),
408
+ );
409
+ const appWidgetLayouts =
410
+ manifest?.components
411
+ .flatMap((component) => {
412
+ if (
413
+ component.kind !== "app-widget" ||
414
+ !component.appWidgetInfoResource
415
+ )
416
+ return [];
417
+ const info = infoByName.get(component.appWidgetInfoResource);
418
+ return info
419
+ ? [
420
+ {
421
+ componentName: component.name,
422
+ infoResourceName: info.infoResourceName,
423
+ layoutResourceName: info.layoutResourceName,
424
+ evidence: info.evidence,
425
+ },
426
+ ]
427
+ : [];
428
+ })
429
+ .sort((left, right) =>
430
+ left.componentName.localeCompare(right.componentName, "en"),
431
+ ) ?? [];
432
+ return {
433
+ views: extractions.flatMap((item) => item.views).sort(byEvidence),
434
+ fragments: extractions.flatMap((item) => item.fragments).sort(byEvidence),
435
+ includes: extractions.flatMap((item) => item.includes).sort(byEvidence),
436
+ navigationTargets,
437
+ shortcutEntries,
438
+ appWidgetLayouts,
439
+ };
440
+ } catch (error) {
441
+ throw hardFailure(
442
+ "ANDROID_XML_PARSE_FAILED",
443
+ "resources",
444
+ `Could not parse selected Android XML: ${error instanceof Error ? error.message : String(error)}`,
445
+ );
446
+ }
447
+ }
@@ -0,0 +1,175 @@
1
+ function lineAt(source, offset) {
2
+ let line = 1;
3
+ for (let index = 0; index < offset; index += 1) {
4
+ if (source.charCodeAt(index) === 10) {
5
+ line += 1;
6
+ }
7
+ }
8
+ return line;
9
+ }
10
+ function decodeXml(value) {
11
+ return value.replace(
12
+ /&(?:#x[0-9a-fA-F]+|#[0-9]+|amp|lt|gt|quot|apos);/gu,
13
+ (entity) => {
14
+ if (entity === "&amp;") return "&";
15
+ if (entity === "&lt;") return "<";
16
+ if (entity === "&gt;") return ">";
17
+ if (entity === "&quot;") return '"';
18
+ if (entity === "&apos;") return "'";
19
+ const numeric = entity.startsWith("&#x")
20
+ ? Number.parseInt(entity.slice(3, -1), 16)
21
+ : Number.parseInt(entity.slice(2, -1), 10);
22
+ return Number.isFinite(numeric) ? String.fromCodePoint(numeric) : entity;
23
+ },
24
+ );
25
+ }
26
+ function tagEnd(source, start) {
27
+ let quote;
28
+ for (let index = start + 1; index < source.length; index += 1) {
29
+ const character = source[index];
30
+ if (quote) {
31
+ if (character === quote) quote = undefined;
32
+ continue;
33
+ }
34
+ if (character === '"' || character === "'") {
35
+ quote = character;
36
+ } else if (character === ">") {
37
+ return index;
38
+ }
39
+ }
40
+ throw new Error(`Unterminated XML tag at line ${lineAt(source, start)}`);
41
+ }
42
+ function parseTag(raw) {
43
+ let body = raw.slice(1, -1).trim();
44
+ const closing = body.startsWith("/");
45
+ if (closing) body = body.slice(1).trim();
46
+ const selfClosing = !closing && body.endsWith("/");
47
+ if (selfClosing) body = body.slice(0, -1).trim();
48
+ const nameMatch = /^[^\s=/>]+/u.exec(body);
49
+ if (!nameMatch) {
50
+ throw new Error(`Invalid XML tag: ${raw}`);
51
+ }
52
+ const name = nameMatch[0];
53
+ const attributes = {};
54
+ let cursor = name.length;
55
+ while (cursor < body.length) {
56
+ while (/\s/u.test(body[cursor] ?? "")) cursor += 1;
57
+ if (cursor >= body.length) break;
58
+ const attributeMatch = /^[^\s=/>]+/u.exec(body.slice(cursor));
59
+ if (!attributeMatch) {
60
+ throw new Error(`Invalid attribute in XML tag: ${raw}`);
61
+ }
62
+ const attributeName = attributeMatch[0];
63
+ cursor += attributeName.length;
64
+ while (/\s/u.test(body[cursor] ?? "")) cursor += 1;
65
+ if (body[cursor] !== "=") {
66
+ attributes[attributeName] = "";
67
+ continue;
68
+ }
69
+ cursor += 1;
70
+ while (/\s/u.test(body[cursor] ?? "")) cursor += 1;
71
+ const quote = body[cursor];
72
+ if (quote !== '"' && quote !== "'") {
73
+ throw new Error(`Attribute ${attributeName} must be quoted`);
74
+ }
75
+ const valueStart = cursor + 1;
76
+ const valueEnd = body.indexOf(quote, valueStart);
77
+ if (valueEnd < 0) {
78
+ throw new Error(`Unterminated attribute ${attributeName}`);
79
+ }
80
+ attributes[attributeName] = decodeXml(body.slice(valueStart, valueEnd));
81
+ cursor = valueEnd + 1;
82
+ }
83
+ return { name, attributes, closing, selfClosing };
84
+ }
85
+ function asReadonly(element) {
86
+ return {
87
+ ...element,
88
+ children: element.children.map(asReadonly),
89
+ };
90
+ }
91
+ export function parseXml(source) {
92
+ const roots = [];
93
+ const stack = [];
94
+ let cursor = 0;
95
+ while (cursor < source.length) {
96
+ const opening = source.indexOf("<", cursor);
97
+ if (opening < 0) {
98
+ if (stack.length > 0) {
99
+ stack.at(-1).text += decodeXml(source.slice(cursor));
100
+ }
101
+ break;
102
+ }
103
+ if (stack.length > 0 && opening > cursor) {
104
+ stack.at(-1).text += decodeXml(source.slice(cursor, opening));
105
+ }
106
+ if (source.startsWith("<!--", opening)) {
107
+ const end = source.indexOf("-->", opening + 4);
108
+ if (end < 0) throw new Error("Unterminated XML comment");
109
+ cursor = end + 3;
110
+ continue;
111
+ }
112
+ if (source.startsWith("<![CDATA[", opening)) {
113
+ const end = source.indexOf("]]>", opening + 9);
114
+ if (end < 0) throw new Error("Unterminated CDATA section");
115
+ if (stack.length > 0) {
116
+ stack.at(-1).text += source.slice(opening + 9, end);
117
+ }
118
+ cursor = end + 3;
119
+ continue;
120
+ }
121
+ if (source.startsWith("<?", opening)) {
122
+ const end = source.indexOf("?>", opening + 2);
123
+ if (end < 0) throw new Error("Unterminated XML declaration");
124
+ cursor = end + 2;
125
+ continue;
126
+ }
127
+ if (source.startsWith("<!", opening)) {
128
+ const end = tagEnd(source, opening);
129
+ cursor = end + 1;
130
+ continue;
131
+ }
132
+ const end = tagEnd(source, opening);
133
+ const parsed = parseTag(source.slice(opening, end + 1));
134
+ const line = lineAt(source, opening);
135
+ if (parsed.closing) {
136
+ const current = stack.pop();
137
+ if (!current || current.name !== parsed.name) {
138
+ throw new Error(
139
+ `Unexpected closing tag ${parsed.name} at line ${line}`,
140
+ );
141
+ }
142
+ current.endLine = lineAt(source, end);
143
+ } else {
144
+ const element = {
145
+ name: parsed.name,
146
+ attributes: parsed.attributes,
147
+ children: [],
148
+ text: "",
149
+ startLine: line,
150
+ endLine: lineAt(source, end),
151
+ };
152
+ const parent = stack.at(-1);
153
+ if (parent) parent.children.push(element);
154
+ else roots.push(element);
155
+ if (!parsed.selfClosing) stack.push(element);
156
+ }
157
+ cursor = end + 1;
158
+ }
159
+ if (stack.length > 0) {
160
+ throw new Error(`Unclosed XML tag ${stack.at(-1).name}`);
161
+ }
162
+ if (roots.length !== 1) {
163
+ throw new Error(`Expected one XML root, found ${roots.length}`);
164
+ }
165
+ return asReadonly(roots[0]);
166
+ }
167
+ export function localName(name) {
168
+ return name.includes(":") ? name.slice(name.lastIndexOf(":") + 1) : name;
169
+ }
170
+ export function descendantElements(root) {
171
+ return [root, ...root.children.flatMap(descendantElements)];
172
+ }
173
+ export function elementText(element) {
174
+ return [element.text, ...element.children.map(elementText)].join("").trim();
175
+ }