@buaa_smat/hometrans 26.0.0 → 26.0.1

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 (147) hide show
  1. package/package.json +11 -82
  2. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +2 -2
  3. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +2 -2
  4. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +2 -2
  5. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +1 -1
  6. package/skills/a2h-batch-ui-align/references/state-mgmt/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +1 -1
  7. package/skills/a2h-batch-ui-align/references/step3-capture.md +3 -3
  8. package/skills/a2h-batch-ui-align/references/step4-prepare.md +1 -1
  9. package/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +11 -6
  10. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +59 -21
  11. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -3
  12. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1 -1
  13. package/skills/a2h-batch-ui-align/scripts/static_check/core/scan.ts +1 -1
  14. package/skills/a2h-utg-explorer/SKILL.md +1 -1
  15. package/skills/a2h-utg-explorer/references/architecture.md +2 -2
  16. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +36 -11
  17. package/skills/a2h-utg-explorer/scripts/device_health.mjs +91 -6
  18. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +20 -2
  19. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +64 -8
  20. package/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
  21. package/skills/a2h-utg-explorer/scripts/recover.mjs +7 -1
  22. package/skills/a2h-utg-explorer/scripts/recover_b.mjs +8 -1
  23. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +89 -7
  24. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +173 -4
  25. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +82 -14
  26. package/skills/a2h-utg-static/SKILL.md +1 -1
  27. package/skills/a2h-utg-static/references/view-interactions.md +1 -1
  28. package/skills/a2h-utg-static/scripts/assemble.mjs +6 -3
  29. package/skills/a2h-utg-static/scripts/compose_body_text.mjs +23 -5
  30. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +29 -3
  31. package/skills/a2h-utg-static/scripts/compose_titles.mjs +10 -1
  32. package/skills/a2h-utg-static/scripts/label_resolve.mjs +51 -2
  33. package/skills/a2h-utg-static/scripts/static_prior.mjs +2 -1
  34. package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
  35. package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
  36. package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
  37. package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
  38. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  39. package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +135 -0
  40. package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
  41. package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
  42. package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
  43. package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  44. package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
  45. package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  46. package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  47. package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
  48. package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
  49. package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
  50. package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +108 -0
  51. package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
  52. package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
  53. package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
  54. package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
  55. package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
  56. package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
  57. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
  58. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
  59. package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  60. package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  61. package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
  62. package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
  63. package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
  64. package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
  65. package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
  66. package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
  67. package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
  68. package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
  69. package/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
  70. package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
  71. package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
  72. package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
  73. package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
  74. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  75. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  76. package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  77. package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  78. package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +155 -0
  79. package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
  80. package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
  81. package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
  82. package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  83. package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  84. package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  85. package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
  86. package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
  87. package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
  88. package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +328 -0
  89. package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
  90. package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
  91. package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
  92. package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  93. package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +83 -0
  94. package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  95. package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
  96. package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
  97. package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  98. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  99. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
  100. package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
  101. package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  102. package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
  103. package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
  104. package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
  105. package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
  106. package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
  107. package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
  108. package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
  109. package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
  110. package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
  111. package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
  112. package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
  113. package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  114. package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  115. package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
  116. package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
  117. package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
  118. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
  119. package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
  120. package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
  121. package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  122. package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
  123. package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
  124. package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
  125. package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
  126. package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
  127. package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
  128. package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  129. package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  130. package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
  131. package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
  132. package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
  133. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
  134. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  135. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
  136. package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
  137. package/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
  138. package/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
  139. package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  140. package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
  141. package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
  142. package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
  143. package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
  144. package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
  145. package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
  146. package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
  147. package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
@@ -17,13 +17,29 @@ import { lineOf, ownBody } from './compose_overlay.mjs';
17
17
  import { isCommentedOut } from './label_resolve.mjs';
18
18
 
19
19
  const S = String.raw;
20
+ /**
21
+ * Parameter names whose value is screen text: the plain ones plus camelCase compounds ending in
22
+ * Text / Title / Hint / Placeholder (`messageText`, `actionText`, `confirmTitle`). Measured
23
+ * (coolmall): the account-login page's only own texts were `placeholder = stringResource(…)`
24
+ * ("请输入密码") and `actionText = stringResource(…)` ("忘记密码"); without them it had no anchor.
25
+ */
26
+ const _TEXT_PARAM = S`(?:text|title|placeholder|hint|contentDescription|[a-z]\w*(?:Text|Title|Hint|Placeholder))`;
20
27
  export const _LITERAL_RES = [
21
28
  // `label = "…"` is Compose's animation label (animateFloatAsState), never screen text.
22
- pyRe(S`\b(?:text|title|placeholder|contentDescription)\s*=\s*"([^"\n$\\]{2,40})"`),
29
+ pyRe(S`\b${_TEXT_PARAM}\s*=\s*"([^"\n$\\]{2,40})"`),
23
30
  pyRe(S`\b[A-Z]\w*Text\s*\(\s*"([^"\n$\\]{2,40})"`),
24
31
  pyRe(S`\bText\s*\(\s*"([^"\n$\\]{2,40})"`),
25
32
  ];
26
- const _SR_RE = pyRe(S`\b(?:text|title|label|contentDescription)\s*=\s*stringResource\s*\(\s*(?:id\s*=\s*)?R\.string\.(\w+)`);
33
+ // A resource read through `label =` is a TextField label (an animation label is a literal).
34
+ const _SR_RE = pyRe(S`\b(?:${_TEXT_PARAM}|label)\s*=\s*stringResource\s*\(\s*(?:id\s*=\s*)?R\.string\.(\w+)`);
35
+ /**
36
+ * `title = R.string.cart` / `message = R.string.empty_cart`: an `@StringRes Int` parameter the callee
37
+ * renders through stringResource itself. Measured (coolmall): every top bar (`CenterTopAppBar(title =
38
+ * R.string.x)`) and empty state (`Empty(message = …)`) took its text this way, so cart, privacy policy
39
+ * and comments had no own text. A resource id is never an animation label, so `message` / `subtitle`
40
+ * join here only (a literal `message = "…"` is usually a toast or log).
41
+ */
42
+ const _RES_ID_RE = pyRe(S`\b(?:${_TEXT_PARAM}|label|message|subtitle|[a-z]\w*(?:Message|Subtitle))\s*=\s*R\.string\.(\w+)\b(?!\s*[.(])`);
27
43
  const _CALL_RE = pyRe(S`\b([A-Z][A-Za-z0-9_]*)\s*\(`);
28
44
  const _POSITIONAL_CALL_RE = pyRe(S`\b([A-Z][A-Za-z0-9_]*)\s*\(\s*"([^"\n$\\]{2,40})"`);
29
45
  const _BRANCH_RE = pyRe(S`\b(?:text|title|contentDescription)\s*=\s*if\s*\([^(){}\n]*\)\s*"([^"\n$\\]{2,40})"\s*else\s*"([^"\n$\\]{2,40})"`);
@@ -135,9 +151,11 @@ export function bodyTexts(name, fnIndex, fileText, strings, depth, stop, relOf,
135
151
  if (/Text$/.test(m[1]) || m[1] === 'Text') { continue; } // counted above
136
152
  if (fnIndex.has(m[1]) || /(?:Button|Tab|Chip)$/.test(m[1])) { add(m[2], m.index); }
137
153
  }
138
- for (const m of iter(_SR_RE, body)) {
139
- const v = strings && Object.hasOwn(strings, m[1]) ? strings[m[1]] : null;
140
- if (v && !String(v).includes('%')) { add(v, m.index); }
154
+ for (const re of [_SR_RE, _RES_ID_RE]) {
155
+ for (const m of iter(re, body)) {
156
+ const v = strings && Object.hasOwn(strings, m[1]) ? strings[m[1]] : null;
157
+ if (v && !String(v).includes('%')) { add(v, m.index); }
158
+ }
141
159
  }
142
160
  // `text = "天气信息来自${source}"`: the fixed lead before the first template is a prefix anchor.
143
161
  for (const m of iter(_TEMPLATE_RE, body)) {
@@ -160,13 +160,18 @@ const T = (v) => !(v === null || v === undefined || v === false || v === '' || v
160
160
 
161
161
  // ---- what counts as an overlay definition, and its kind ------------------- //
162
162
  export const HERE = path.dirname(fileURLToPath(import.meta.url));
163
+ // `*Modal` / `*Sheet` composables are Material3 bottom sheets (`CouponModal` → `BottomModal` →
164
+ // `ModalBottomSheet`). Measured (coolmall): matching only *Dialog / *Popup lost the goods page's
165
+ // coupon and spec sheets, so their captures had no static node to map onto.
163
166
  export const DEF_RE = P(S`@Composable\s+(?:private\s+|internal\s+|public\s+)?fun\s+` +
164
- S`([A-Z]\w*(?:Dialog|Popup))\s*\(`);
167
+ S`([A-Z]\w*(?:Dialog|Popup|Modal|BottomSheet|Sheet))\s*\(`);
168
+ /** Names DEF_RE takes on the suffix alone, kept only when they show an overlay (main, pass 1). */
169
+ export const SUFFIX_ONLY_RE = /(?:Modal|Sheet)$/;
165
170
  export const FUN_RE = P(S`(@Composable\s+)?(?:private\s+|internal\s+|public\s+|inline\s+)*` +
166
171
  S`fun\s+(?:[A-Za-z_][\w<>,\s]*\.)?([A-Za-z_]\w*)\s*\(`);
167
172
 
168
173
  export const SHEET_PRIMS = ['FullScreenColumnDialog', 'FullScreenWithCloseDialog',
169
- 'FullScreenDialog', 'BottomSheetDialog'];
174
+ 'FullScreenDialog', 'BottomSheetDialog', 'ModalBottomSheet('];
170
175
  export const DIALOG_PRIMS = ['BasicDialog', 'YesDialog', 'YesNoDialog', 'InputDialog',
171
176
  'TextDialog', 'DialogColumn', 'Dialog('];
172
177
  export const MENU_PRIMS = ['PopupMenu('];
@@ -747,6 +752,11 @@ export function classifyShared(params, identity, callSiteFiles) {
747
752
  return 'page';
748
753
  }
749
754
 
755
+ /** Does `body` call any sheet / dialog / menu primitive itself? */
756
+ export function _hasPrim(body) {
757
+ return [...SHEET_PRIMS, ...DIALOG_PRIMS, ...MENU_PRIMS].some((p) => _findPrim(body, p) >= 0);
758
+ }
759
+
750
760
  export function inferKind(body) {
751
761
  let first = null; let best = Infinity;
752
762
  for (const p of [...SHEET_PRIMS, ...DIALOG_PRIMS, ...MENU_PRIMS]) {
@@ -2158,6 +2168,16 @@ export function main(argv = process.argv.slice(2)) {
2158
2168
  });
2159
2169
  }
2160
2170
  }
2171
+ // A `*Modal` / `*Sheet` name is only a hint (BalanceSheet, TimeSheet are full pages): keep it
2172
+ // only when it shows an overlay, by a primitive of its own or by calling a kept overlay.
2173
+ for (let changed = true; changed;) {
2174
+ changed = false;
2175
+ for (const [n, d] of [...overlays]) {
2176
+ if (!SUFFIX_ONLY_RE.test(n) || _hasPrim(d.body || '')) { continue; }
2177
+ if ([...overlays.keys()].some((o) => o !== n && _findPrim(d.body || '', o + '(') >= 0)) { continue; }
2178
+ overlays.delete(n); changed = true;
2179
+ }
2180
+ }
2161
2181
  const allNames = [...overlays.keys()];
2162
2182
  const gateDelegate = new Map();
2163
2183
  for (const [n, d] of overlays) {
@@ -2171,12 +2191,18 @@ export function main(argv = process.argv.slice(2)) {
2171
2191
  }
2172
2192
  if (first) { gateDelegate.set(n, first); }
2173
2193
  }
2174
- for (const d of overlays.values()) { delete d.body; }
2175
2194
  const resolveGate = (name) => {
2176
2195
  const seen = new Set();
2177
2196
  while (gateDelegate.has(name) && !seen.has(name)) { seen.add(name); name = gateDelegate.get(name); }
2178
2197
  return name;
2179
2198
  };
2199
+ // A gate calling no primitive itself (`CouponModal` → `BottomModal` → `ModalBottomSheet`) shows
2200
+ // what its delegate shows: inferKind's 'dialog' default would mislabel every wrapped bottom sheet.
2201
+ for (const n of gateDelegate.keys()) {
2202
+ const d = overlays.get(n);
2203
+ if (!_hasPrim(d.body || '')) { d.kind = overlays.get(resolveGate(n)).kind; }
2204
+ }
2205
+ for (const d of overlays.values()) { delete d.body; }
2180
2206
  const overlayNames = new Set(overlays.keys());
2181
2207
  const callSiteFiles = new Map([...overlayNames].map((n) => [n, new Set()]));
2182
2208
  for (const [p, text] of fileText) {
@@ -32,7 +32,8 @@ const osJoin = (a, b) => (a.endsWith('/') || a.endsWith(SEP) ? a + b : a + SEP +
32
32
  const _SKIP = new Set(['build', '.git', 'test', 'androidTest']);
33
33
  const basename = (p) => (IS_WIN ? path.win32.basename(p) : path.posix.basename(p));
34
34
 
35
- export const _TITLE_PARAM_DECL = pyRe(S`\b(title|pageTitle|headerTitle|titleText)\s*:\s*String`);
35
+ // `title: Int?` is a header taking an `@StringRes` id (`CenterTopAppBar(title: Int? = null, …)`).
36
+ export const _TITLE_PARAM_DECL = pyRe(S`\b(title|pageTitle|headerTitle|titleText)\s*:\s*(?:String|Int)\b`);
36
37
  export const _BACK_PARAM_DECL = pyRe(
37
38
  S`\b(onBack\w*|onClose\w*|onNavigateBack|navigateUp|backTo\w*|onReturn\w*)\s*:`);
38
39
  export const _MATERIAL_BARS = ['TopAppBar', 'LargeTopAppBar', 'CenterAlignedTopAppBar', 'MediumTopAppBar'];
@@ -40,6 +41,8 @@ export const _CALL_RE = pyRe(S`\b([A-Z][A-Za-z0-9_]*)\s*\(`);
40
41
  export const _TITLE_LITERAL = pyRe(S`\b(?:title|pageTitle|headerTitle|titleText)\s*=\s*"([^"\n]{1,40})"`);
41
42
  export const _TITLE_SR = pyRe(S`\b(?:title|pageTitle|headerTitle|titleText)\s*=\s*` +
42
43
  S`stringResource\s*\(\s*(?:id\s*=\s*)?R\.string\.(\w+)`);
44
+ // `CenterTopAppBar(title = R.string.cart)`: an `@StringRes Int` title the header resolves itself.
45
+ export const _TITLE_RES_ID = pyRe(S`\b(?:title|pageTitle|headerTitle)\s*=\s*R\.string\.(\w+)\b(?!\s*[.(])`);
43
46
  export const _TITLE_IDENT = pyRe(S`\b(?:title|pageTitle|headerTitle|titleText)\s*=\s*([A-Za-z_]\w*)`);
44
47
  export const _TITLE_SLOT_LIT = pyRe(S`\btitle\s*=\s*\{[^}]{0,160}?"([^"\n]{1,40})"`, 's');
45
48
  export const _TITLE_SLOT_SR = pyRe(S`\btitle\s*=\s*\{[^}]{0,160}?` +
@@ -140,6 +143,10 @@ export function _positionalTitle(args, pos, strings, consts) {
140
143
  if (m) { return [m[1], null]; }
141
144
  m = /^stringResource\s*\(\s*(?:id\s*=\s*)?R\.string\.(\w+)\s*\)$/.exec(a);
142
145
  if (m && truthy(get(strings, m[1]))) { return [strings[m[1]], `R.string.${m[1]}`]; }
146
+ // An `@StringRes Int` title the header resolves itself, as _TITLE_RES_ID for the named form
147
+ // (coolmall: `CenterTopAppBar(R.string.category, showBackIcon = false)` left the Category tab untitled).
148
+ m = /^R\.string\.(\w+)$/.exec(a);
149
+ if (m && truthy(get(strings, m[1]))) { return [strings[m[1]], `R.string.${m[1]}`]; }
143
150
  if (truthy(consts) && /^[A-Za-z_]\w*$/.test(a)) {
144
151
  const val = resolveConstLabel(a, consts);
145
152
  if (val) { return [val, a]; }
@@ -151,6 +158,8 @@ export function _positionalTitle(args, pos, strings, consts) {
151
158
  export function _resolveTitle(args, strings, consts) {
152
159
  let m = search(_TITLE_SR, args);
153
160
  if (m && truthy(get(strings, m[1]))) { return [strings[m[1]], `R.string.${m[1]}`]; }
161
+ m = search(_TITLE_RES_ID, args);
162
+ if (m && truthy(get(strings, m[1]))) { return [strings[m[1]], `R.string.${m[1]}`]; }
154
163
  m = search(_TITLE_SLOT_SR, args);
155
164
  if (m && truthy(get(strings, m[1]))) { return [strings[m[1]], `R.string.${m[1]}`]; }
156
165
  m = search(_TITLE_LITERAL, args);
@@ -115,12 +115,61 @@ function osJoin(a, b) {
115
115
 
116
116
  const _STRING_RE = pyRe('<string name="([^"]+)"[^>]*>(.*?)</string>', 's');
117
117
 
118
- /** Parse a strings.xml (prefer values-zh) into {name: value}. */
118
+ const _XML_ENTITY = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
119
+
120
+ /**
121
+ * What the device renders for a raw strings.xml value: CDATA unwrapped, inline markup
122
+ * (`<b>`, `<xliff:g>`) dropped, XML entities decoded, then aapt's rules — a fully quoted value
123
+ * keeps its whitespace, otherwise whitespace runs collapse — and backslash escapes
124
+ * (`\n`, `\t`, `\'`, `\"`, `\@`, `\uXXXX`). Left raw, `你好,\n欢迎…` (a literal backslash-n) and
125
+ * `Joker.X &amp; …` never matched the rendered text, so such pages had no usable anchor.
126
+ */
127
+ export function decodeAndroidString(raw) {
128
+ let s = String(raw ?? '');
129
+ // one pass: CDATA content is literal text (`<![CDATA[满100<减20>起]]>` keeps its brackets), so it
130
+ // must not meet the markup strip or the entity decoding
131
+ s = s.replace(/<!\[CDATA\[([\s\S]*?)\]\]>|<[^>]*>|&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (m, cdata, e) => {
132
+ if (cdata !== undefined) { return cdata; }
133
+ if (e === undefined) { return ''; }
134
+ if (e[0] !== '#') { return _XML_ENTITY[e]; }
135
+ const cp = e[1] === 'x' ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
136
+ return Number.isFinite(cp) && cp >= 0 && cp <= 0x10ffff ? String.fromCodePoint(cp) : m;
137
+ });
138
+ return aaptText(s);
139
+ }
140
+
141
+ /**
142
+ * aapt's one pass over an entity-decoded value: an unescaped `"` toggles a quoted run and is
143
+ * dropped (`Tap "OK" now` shows `Tap OK now`); outside quotes whitespace runs collapse to one
144
+ * space and the ends are trimmed; a backslash escape (`\n`, `\t`, `\uXXXX`, `\"`, `\\`, `\'`) is
145
+ * always literal, so `"C:\\"` shows `C:\`. semantics.mjs androidValue is the same rule.
146
+ */
147
+ export function aaptText(s) {
148
+ let out = ''; let quoted = false; let space = false;
149
+ for (let i = 0; i < s.length; i++) {
150
+ const c = s[i];
151
+ if (c === '\\' && i + 1 < s.length) {
152
+ const u = /^u([0-9a-fA-F]{4})/.exec(s.slice(i + 1, i + 6));
153
+ if (u) { out += String.fromCharCode(parseInt(u[1], 16)); i += 5; }
154
+ else { const d = s[i + 1]; out += d === 'n' ? '\n' : d === 't' ? '\t' : d; i += 1; }
155
+ space = false;
156
+ } else if (c === '"') {
157
+ quoted = !quoted;
158
+ } else if (!quoted && /\s/.test(c)) {
159
+ if (out && !space) { out += ' '; space = true; }
160
+ } else {
161
+ out += c; space = false;
162
+ }
163
+ }
164
+ return space ? out.slice(0, -1) : out;
165
+ }
166
+
167
+ /** Parse a strings.xml (prefer values-zh) into {name: rendered value}. */
119
168
  export function loadStrings(p) {
120
169
  if (!p || !pExists(p)) { return newDict(); }
121
170
  const t = readTextSmart(p);
122
171
  const out = newDict();
123
- for (const m of finditer(_STRING_RE, t)) { dset(out, m[1], m[2]); }
172
+ for (const m of finditer(_STRING_RE, t)) { dset(out, m[1], decodeAndroidString(m[2])); }
124
173
  return out;
125
174
  }
126
175
 
@@ -28,6 +28,7 @@ import {
28
28
  pyRe, pySplit, pyStr, pyStrip, readText, reFindall, sortedBy, sortedStr, toInt, truthy,
29
29
  } from './_py.mjs';
30
30
  import { nodeLinkGraph, dijkstraPath, singleSourceDijkstraPaths, NetworkXNoPath, NodeNotFound } from './_graph.mjs';
31
+ import { decodeAndroidString } from './label_resolve.mjs';
31
32
  import * as phasePlanner from './phase_planner.mjs';
32
33
  import { term, termLang } from './i18n-term.mjs';
33
34
 
@@ -223,7 +224,7 @@ export function _loadStringsXml(p) {
223
224
  if (!pExists(p)) { return {}; }
224
225
  const t = readText(p, { encoding: 'utf-8', errors: 'replace' });
225
226
  const out = {};
226
- for (const [k, v] of reFindall(/<string name="([^"]+)"[^>]*>(.*?)<\/string>/su, t)) { dset(out, k, v); }
227
+ for (const [k, v] of reFindall(/<string name="([^"]+)"[^>]*>(.*?)<\/string>/su, t)) { dset(out, k, decodeAndroidString(v)); }
227
228
  return out;
228
229
  }
229
230
  /** isinstance(v, dict) for json-ish values. */
@@ -0,0 +1,28 @@
1
+ // Test helper: write a ZIP of stored entries (what zipfile.ZipFile(...).writestr produces).
2
+ import * as fs from 'node:fs';
3
+ import { crc32 } from 'node:zlib';
4
+
5
+ /** A minimal ZIP writer (stored entries, UTF-8 names) — what zipfile.writestr produces. */
6
+ export function writeZip(p, entries) {
7
+ const locals = []; const centrals = []; let off = 0;
8
+ for (const [name, data] of entries) {
9
+ const nb = Buffer.from(name, 'utf8'); const db = Buffer.from(data, 'utf8');
10
+ const crc = crc32(db) >>> 0;
11
+ const lh = Buffer.alloc(30);
12
+ lh.writeUInt32LE(0x04034b50, 0); lh.writeUInt16LE(20, 4); lh.writeUInt16LE(0x800, 6);
13
+ lh.writeUInt16LE(0, 8); lh.writeUInt32LE(crc, 14); lh.writeUInt32LE(db.length, 18);
14
+ lh.writeUInt32LE(db.length, 22); lh.writeUInt16LE(nb.length, 26);
15
+ const ch = Buffer.alloc(46);
16
+ ch.writeUInt32LE(0x02014b50, 0); ch.writeUInt16LE(20, 4); ch.writeUInt16LE(20, 6);
17
+ ch.writeUInt16LE(0x800, 8); ch.writeUInt32LE(crc, 16); ch.writeUInt32LE(db.length, 20);
18
+ ch.writeUInt32LE(db.length, 24); ch.writeUInt16LE(nb.length, 28); ch.writeUInt32LE(off, 42);
19
+ locals.push(lh, nb, db); centrals.push(ch, nb);
20
+ off += 30 + nb.length + db.length;
21
+ }
22
+ const cd = Buffer.concat(centrals);
23
+ const eocd = Buffer.alloc(22);
24
+ eocd.writeUInt32LE(0x06054b50, 0); eocd.writeUInt16LE(entries.length, 8);
25
+ eocd.writeUInt16LE(entries.length, 10); eocd.writeUInt32LE(cd.length, 12); eocd.writeUInt32LE(off, 16);
26
+ fs.writeFileSync(p, Buffer.concat([...locals, cd, eocd]));
27
+ }
28
+
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * probe_autoload.mjs — port of tests/probe_autoload.py.
4
+ *
5
+ * Measure how many `via:auto-load` fragment edges are NOT lifecycle commits.
6
+ *
7
+ * `fragment_nav.py` decides auto-load by absence: a transaction not inside any
8
+ * click-listener span is stamped `action:"default", via:"auto-load"`. Absence of
9
+ * a listener is not evidence of a lifecycle commit -- the dispatching method may
10
+ * simply be called from elsewhere (an interface callback, a menu handler, a
11
+ * public setter invoked by another class). This probe reports, per corpus app,
12
+ * how many auto-load edges sit in a scope that is provably NOT lifecycle:
13
+ *
14
+ * addToBackStack : the transaction joins the back stack. A lifecycle commit
15
+ * that paints the first screen does not -- it would put the
16
+ * app's own home screen on the back stack.
17
+ * non_lifecycle : the enclosing function is not an Android lifecycle/creation
18
+ * callback, so nothing says this runs on the way in.
19
+ *
20
+ * Run: node scripts/tests/probe_autoload.mjs [--corpus DIR ...]
21
+ */
22
+ import * as fs from 'node:fs';
23
+ import * as path from 'node:path';
24
+ import { pathToFileURL } from 'node:url';
25
+ import { IS_WIN, pyRe, pyPrint, readText, sortedStr, ArgumentParser, runMain } from '../_py.mjs';
26
+ import { _osWalk } from '../layout_resolve.mjs';
27
+ import { fnRanges, innermostFnAt } from '../scope_utils.mjs';
28
+
29
+ export const DEFAULT_CORPORA = [
30
+ 'E:/opensourced_android_repos',
31
+ 'E:/hometrans-0801/harmonyos-arkts-benchmark/repos_android',
32
+ ];
33
+
34
+ // Lifecycle / view-creation callbacks: a commit here really is on the way in.
35
+ export const LIFECYCLE = new Set([
36
+ 'onCreate', 'onCreateView', 'onViewCreated', 'onStart', 'onResume',
37
+ 'onActivityCreated', 'onPostCreate', 'onAttach', 'onRestoreInstanceState',
38
+ 'onConfigurationChanged', 'onFinishInflate', 'init', 'initialize',
39
+ 'setupViews', 'setUpViews', 'initViews', 'initView', 'initFragments',
40
+ 'onCreateOptionsMenu',
41
+ ]);
42
+
43
+ const SEP = IS_WIN ? '\\' : '/';
44
+ const osJoin = (a, b) => (a === '' || a.endsWith('/') || a.endsWith(SEP) ? a + b : a + SEP + b);
45
+ const isDir = (p) => { try { return fs.statSync(p).isDirectory(); } catch { return false; } };
46
+ const countNl = (s, end) => { let n = 0; for (let i = s.indexOf('\n'); i >= 0 && i < end; i = s.indexOf('\n', i + 1)) { n++; } return n; };
47
+ const _WALK_SKIP = new Set(['build', '.git', 'test', 'androidTest', '.gradle']);
48
+
49
+ function* _iterSources(project) {
50
+ for (const [base, dirs, files] of _osWalk(project)) {
51
+ const keep = dirs.filter((d) => !_WALK_SKIP.has(d));
52
+ dirs.length = 0; dirs.push(...keep);
53
+ for (const fn of files) {
54
+ if (fn.endsWith('.kt') || fn.endsWith('.java')) { yield osJoin(base, fn); }
55
+ }
56
+ }
57
+ }
58
+
59
+ /** [total, backstack, non_lifecycle, samples] over auto-load-shaped sites. */
60
+ export function probe(project) {
61
+ let total = 0; let backstack = 0; let nonLife = 0;
62
+ const samples = [];
63
+ const txn = pyRe(String.raw`\.(?:replace|add)\s*\(`, 'g');
64
+ for (const p of _iterSources(project)) {
65
+ let text;
66
+ try { text = readText(p, { errors: 'replace' }); } catch { continue; }
67
+ if (!text.includes('beginTransaction') && !text.includes('commit')) { continue; }
68
+ const ranges = fnRanges(text, p);
69
+ for (const m of text.matchAll(txn)) {
70
+ const pos = m.index;
71
+ const fn = innermostFnAt(ranges, pos);
72
+ // the transaction statement's own chain, bounded
73
+ const chain = text.slice(Math.max(0, pos - 400), pos + 400);
74
+ if (!chain.includes('beginTransaction') && !chain.includes('FragmentTransaction')) { continue; }
75
+ total++;
76
+ const hasBs = chain.includes('addToBackStack');
77
+ const isLife = fn ? LIFECYCLE.has(fn) : false;
78
+ if (hasBs) { backstack++; }
79
+ if (!isLife) { nonLife++; }
80
+ if ((hasBs || !isLife) && samples.length < 4) {
81
+ const line = countNl(text, pos) + 1;
82
+ samples.push(`${path.basename(p)}:${line} fn=${fn === null ? 'None' : fn} backstack=${hasBs ? 'True' : 'False'}`);
83
+ }
84
+ }
85
+ }
86
+ return [total, backstack, nonLife, samples];
87
+ }
88
+
89
+ export function main(argv = process.argv.slice(2)) {
90
+ const ap = new ArgumentParser({ prog: 'probe_autoload.mjs' });
91
+ ap.add_argument('--corpus', { action: 'append', default: null });
92
+ const args = ap.parse_args(argv);
93
+ const corpora = args.corpus || DEFAULT_CORPORA;
94
+ for (const corpus of corpora) {
95
+ if (!isDir(corpus)) { pyPrint(`skip (missing): ${corpus}`); continue; }
96
+ pyPrint(`=== ${corpus} ===`);
97
+ for (const name of sortedStr(fs.readdirSync(corpus))) {
98
+ const p = osJoin(corpus, name);
99
+ if (!isDir(p)) { continue; }
100
+ const [total, bs, nl, samples] = probe(p);
101
+ if (!total) { continue; }
102
+ pyPrint(` ${name.padEnd(38)} txn=${String(total).padEnd(4)} addToBackStack=${String(bs).padEnd(4)} non_lifecycle=${nl}`);
103
+ for (const s of samples) { pyPrint(` ${s}`); }
104
+ }
105
+ }
106
+ }
107
+
108
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { runMain(() => main()); }
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * probe_layout_fragments.mjs — port of tests/probe_layout_fragments.py.
4
+ *
5
+ * Layout-declared fragments: `<fragment android:name>` / FragmentContainerView.
6
+ *
7
+ * A fragment named in a layout is instantiated by the framework when the host
8
+ * inflates that layout -- no transaction, no code call site. Every extractor keys
9
+ * on a CALL, so this whole family produces no edge: the page exists as a node (it
10
+ * is an app-owned Fragment subclass) but nothing links the host to it.
11
+ *
12
+ * Consequence, measured on BreezyWeather: `activity_main.xml:10` names
13
+ * HomeFragment in a FragmentContainerView. That is the app's real first screen,
14
+ * and with no edge for it `assemble.py`'s UI-less-shell fold picked a
15
+ * click-triggered commit as the entry child instead, folding MainActivity onto the
16
+ * WRONG fragment and rooting the whole graph there.
17
+ *
18
+ * This probe reports per app how many such declarations exist and whether an
19
+ * `android:name` is present (the attribute that names the class).
20
+ *
21
+ * node tests/probe_layout_fragments.mjs [corpus ...]
22
+ */
23
+ import * as fs from 'node:fs';
24
+ import * as path from 'node:path';
25
+ import { pathToFileURL } from 'node:url';
26
+ import { IS_WIN, pyRe, pyPrint, readText, osRelpath, sortedStr, pyRsplit } from '../_py.mjs';
27
+ import { _osWalk } from '../layout_resolve.mjs';
28
+
29
+ export const DEFAULT_CORPORA = [
30
+ 'E:/opensourced_android_repos',
31
+ 'E:/hometrans-0801/harmonyos-arkts-benchmark/repos_android',
32
+ ];
33
+
34
+ const _SKIP = new Set(['build', '.git', '.gradle', '.idea', 'node_modules']);
35
+
36
+ // <fragment .../> and <androidx.fragment.app.FragmentContainerView .../>
37
+ const _TAG_RE = pyRe(String.raw`<(?:(?:[\w.]*\.)?FragmentContainerView|fragment)\b[^>]*>`, 'sg');
38
+ const _NAME_RE = pyRe(String.raw`android:name\s*=\s*"([^"]+)"`);
39
+ const _ID_RE = pyRe(String.raw`android:id\s*=\s*"@\+?id/(\w+)"`);
40
+
41
+ const SEP = IS_WIN ? '\\' : '/';
42
+ const osJoin = (a, b) => (a === '' || a.endsWith('/') || a.endsWith(SEP) ? a + b : a + SEP + b);
43
+ const isDir = (p) => { try { return fs.statSync(p).isDirectory(); } catch { return false; } };
44
+ const countNl = (s, end) => { let n = 0; for (let i = s.indexOf('\n'); i >= 0 && i < end; i = s.indexOf('\n', i + 1)) { n++; } return n; };
45
+
46
+ /** [[rel, line, cls, vid|null]] for every layout fragment that names its class. */
47
+ export function probe(project) {
48
+ const hits = [];
49
+ for (const [base, dirs, files] of _osWalk(project)) {
50
+ const keep = dirs.filter((d) => !_SKIP.has(d));
51
+ dirs.length = 0; dirs.push(...keep);
52
+ if (!base.replace(/\\/g, '/').split('/').includes('res')) { continue; }
53
+ for (const fn of files) {
54
+ if (!fn.endsWith('.xml')) { continue; }
55
+ const p = osJoin(base, fn);
56
+ let text;
57
+ try { text = readText(p, { errors: 'replace' }); } catch { continue; }
58
+ for (const m of text.matchAll(_TAG_RE)) {
59
+ const tag = m[0];
60
+ const nm = _NAME_RE.exec(tag);
61
+ if (!nm) { continue; } // container only; target supplied by a transaction
62
+ const vid = _ID_RE.exec(tag);
63
+ const line = countNl(text, m.index) + 1;
64
+ const rel = osRelpath(p, project).replace(/\\/g, '/');
65
+ hits.push([rel, line, pyRsplit(nm[1], '.', 1).pop(), vid ? vid[1] : null]);
66
+ }
67
+ }
68
+ }
69
+ return hits;
70
+ }
71
+
72
+ export function main(argv = process.argv.slice(2)) {
73
+ const corpora = argv.length ? argv : DEFAULT_CORPORA;
74
+ for (const corpus of corpora) {
75
+ if (!isDir(corpus)) { continue; }
76
+ pyPrint(`=== ${corpus} ===`);
77
+ for (const name of sortedStr(fs.readdirSync(corpus))) {
78
+ const p = osJoin(corpus, name);
79
+ if (!isDir(p)) { continue; }
80
+ const hits = probe(p);
81
+ if (!hits.length) { continue; }
82
+ pyPrint(` ${name.padEnd(38)} named_fragments=${hits.length}`);
83
+ for (const [rel, line, cls, vid] of hits.slice(0, 4)) {
84
+ pyPrint(` ${rel}:${line} -> ${cls} (id=${vid === null ? 'None' : vid})`);
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { main(); }
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * probe_unknown_scope.mjs — port of tests/probe_unknown_scope.py.
4
+ *
5
+ * Why does a transaction site resolve to NO enclosing function?
6
+ *
7
+ * `classify_commit` returns 'unknown' when `innermost_fn_at` finds no range
8
+ * containing the site, and 'unknown' keeps the old conservative `auto-load`
9
+ * default. A high count means the conservative branch is carrying real dispatched
10
+ * commits, so it needs to be understood rather than accepted.
11
+ *
12
+ * Prints the source line plus a window for each unknown site.
13
+ *
14
+ * node tests/probe_unknown_scope.mjs <project> [limit]
15
+ */
16
+ import * as path from 'node:path';
17
+ import { pathToFileURL } from 'node:url';
18
+ import { IS_WIN, pyRe, pyPrint, readText, sortedStr, toInt, cpSlice } from '../_py.mjs';
19
+ import { _osWalk } from '../layout_resolve.mjs';
20
+ import { fnRanges, innermostFnAt } from '../scope_utils.mjs';
21
+
22
+ const _SKIP = new Set(['build', '.git', 'test', 'androidTest', '.gradle', '.idea']);
23
+ const _TXN = pyRe(String.raw`\.(?:replace|add)\s*\(`, 'g');
24
+
25
+ const SEP = IS_WIN ? '\\' : '/';
26
+ const osJoin = (a, b) => (a === '' || a.endsWith('/') || a.endsWith(SEP) ? a + b : a + SEP + b);
27
+ const countNl = (s, end) => { let n = 0; for (let i = s.indexOf('\n'); i >= 0 && i < end; i = s.indexOf('\n', i + 1)) { n++; } return n; };
28
+
29
+ export function main(argv = process.argv.slice(2)) {
30
+ const project = argv[0];
31
+ const limit = argv.length > 1 ? toInt(argv[1]) : 8;
32
+ let shown = 0;
33
+ for (const [base, dirs, files] of _osWalk(project)) {
34
+ const keep = dirs.filter((d) => !_SKIP.has(d));
35
+ dirs.length = 0; dirs.push(...keep);
36
+ for (const fn of sortedStr(files)) {
37
+ if (!(fn.endsWith('.kt') || fn.endsWith('.java'))) { continue; }
38
+ const p = osJoin(base, fn);
39
+ let text;
40
+ try { text = readText(p, { errors: 'replace' }); } catch { continue; }
41
+ if (!text.includes('beginTransaction')) { continue; }
42
+ const ranges = fnRanges(text, p);
43
+ for (const m of text.matchAll(_TXN)) {
44
+ const pos = m.index;
45
+ const chain = text.slice(Math.max(0, pos - 400), pos + 400);
46
+ if (!chain.includes('beginTransaction')) { continue; }
47
+ if (innermostFnAt(ranges, pos)) { continue; }
48
+ const line = countNl(text, pos) + 1;
49
+ const lines = text.split('\n');
50
+ pyPrint(`--- ${fn}:${line} (fn_ranges=${ranges.length}) ---`);
51
+ for (let i = Math.max(0, line - 6); i < Math.min(lines.length, line + 1); i++) {
52
+ pyPrint(` ${String(i + 1).padStart(5)}| ${cpSlice(lines[i], 0, 110)}`);
53
+ }
54
+ shown++;
55
+ if (shown >= limit) { return; }
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { main(); }