@buaa_smat/hometrans 26.0.4 → 26.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/agents/code-reviewer.md +2 -0
  2. package/agents/model-render-worker.md +1 -1
  3. package/i18n/agents/code-reviewer.md +2 -0
  4. package/i18n/agents/model-render-worker.md +1 -1
  5. package/i18n/skills/a2h-app-migrate/SKILL.md +51 -3
  6. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +140 -32
  7. package/i18n/skills/a2h-app-migrate/scripts/dag_graph.mjs +297 -0
  8. package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +134 -21
  9. package/i18n/skills/a2h-app-migrate/test/test_finalize.mjs +21 -4
  10. package/i18n/skills/a2h-app-migrate/test/test_image_probe.mjs +3 -3
  11. package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
  12. package/i18n/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +1 -1
  13. package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +12 -5
  14. package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +7 -8
  15. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -1
  16. package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +27 -15
  17. package/i18n/skills/a2h-batch-ui-align/SKILL.md +1 -1
  18. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +4 -0
  19. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +36 -0
  20. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +4 -0
  21. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +4 -0
  22. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +3 -3
  23. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +8 -0
  24. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_in_linear.ts +164 -0
  25. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/self_drawn_sheet.ts +105 -0
  26. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/staggered_lanes.ts +127 -0
  27. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/window_size_constant.ts +114 -0
  28. package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +4 -1
  29. package/i18n/skills/a2h-page-specgen/references/spec-example.md +35 -5
  30. package/i18n/skills/a2h-page-specgen/references/spec-template.md +4 -4
  31. package/i18n/skills/a2h-spec-generate/SKILL.md +3 -1
  32. package/i18n/skills/a2h-spec-generate/references/fusion-task-contract.md +15 -3
  33. package/i18n/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  34. package/i18n/skills/a2h-spec-generate/references/spec-sample-complex.md +16 -0
  35. package/i18n/skills/a2h-spec-generate/references/spec-sample-transfer.md +16 -0
  36. package/i18n/skills/a2h-spec-generate/references/spec-samples.md +5 -1
  37. package/i18n/skills/a2h-spec-generate/references/synthesis-rules.md +21 -1
  38. package/i18n/skills/a2h-spec-generate/references/worker-rules.md +25 -2
  39. package/i18n/skills/a2h-spec-generate/scripts/check_spec.ts +121 -6
  40. package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +2 -1
  41. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +3 -0
  42. package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +16 -2
  43. package/i18n/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +11 -2
  44. package/i18n/skills/a2h-spec-generate/test/check-spec.test.ts +35 -0
  45. package/package.json +1 -1
  46. package/skills/a2h-app-migrate/SKILL.md +53 -5
  47. package/skills/a2h-app-migrate/references/workflow.yaml +140 -32
  48. package/skills/a2h-app-migrate/scripts/assert_dag_complete.mjs +226 -0
  49. package/skills/a2h-app-migrate/scripts/dag_graph.mjs +297 -0
  50. package/skills/a2h-app-migrate/scripts/dag_process_executor.mjs +199 -0
  51. package/skills/a2h-app-migrate/scripts/dag_production_executor.mjs +897 -0
  52. package/skills/a2h-app-migrate/scripts/dag_runner.mjs +1767 -0
  53. package/skills/a2h-app-migrate/scripts/ledger.mjs +15 -2
  54. package/skills/a2h-app-migrate/scripts/lib-yaml-lite.mjs +8 -2
  55. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +3 -8
  56. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +134 -21
  57. package/skills/a2h-app-migrate/test/test_dag_complete.mjs +222 -0
  58. package/skills/a2h-app-migrate/test/test_dag_production.mjs +670 -0
  59. package/skills/a2h-app-migrate/test/test_dag_runner.mjs +423 -0
  60. package/skills/a2h-app-migrate/test/test_finalize.mjs +21 -4
  61. package/skills/a2h-app-migrate/test/test_image_probe.mjs +1 -1
  62. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +16 -1
  63. package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +1 -1
  64. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +12 -5
  65. package/skills/a2h-arkts-logic-coder/SKILL.md +7 -8
  66. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -1
  67. package/skills/a2h-arkts-logic-coder/references/code-generation.md +27 -15
  68. package/skills/a2h-batch-ui-align/SKILL.md +1 -1
  69. package/skills/a2h-batch-ui-align/references/cards/widgets.md +4 -0
  70. package/skills/a2h-batch-ui-align/references/checker-rules.md +36 -0
  71. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +4 -0
  72. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +4 -0
  73. package/skills/a2h-batch-ui-align/references/step5-convert.md +3 -3
  74. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +49 -3
  75. package/skills/a2h-batch-ui-align/scripts/static_check/core/android.ts +36 -0
  76. package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +8 -0
  77. package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +8 -0
  78. package/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_in_linear.ts +164 -0
  79. package/skills/a2h-batch-ui-align/scripts/static_check/rules/self_drawn_sheet.ts +105 -0
  80. package/skills/a2h-batch-ui-align/scripts/static_check/rules/staggered_lanes.ts +127 -0
  81. package/skills/a2h-batch-ui-align/scripts/static_check/rules/window_size_constant.ts +114 -0
  82. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_coolmall_ds1123.test.mjs +433 -0
  83. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_overlay_in_linear.test.mjs +288 -0
  84. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +46 -0
  85. package/skills/a2h-page-specgen/references/scenario-authoring.md +4 -1
  86. package/skills/a2h-page-specgen/references/spec-example.md +35 -5
  87. package/skills/a2h-page-specgen/references/spec-template.md +4 -4
  88. package/skills/a2h-spec-generate/SKILL.md +3 -1
  89. package/skills/a2h-spec-generate/references/fusion-task-contract.md +15 -3
  90. package/skills/a2h-spec-generate/references/review-checklist.md +1 -0
  91. package/skills/a2h-spec-generate/references/spec-sample-complex.md +16 -0
  92. package/skills/a2h-spec-generate/references/spec-sample-transfer.md +16 -0
  93. package/skills/a2h-spec-generate/references/spec-samples.md +5 -1
  94. package/skills/a2h-spec-generate/references/synthesis-rules.md +21 -1
  95. package/skills/a2h-spec-generate/references/worker-rules.md +25 -2
  96. package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +3 -1
  97. package/skills/a2h-spec-generate/scripts/check_spec.ts +262 -6
  98. package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +12 -2
  99. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +3 -0
  100. package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +16 -2
  101. package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +54 -3
  102. package/skills/a2h-spec-generate/test/check-spec.test.ts +247 -0
@@ -0,0 +1,105 @@
1
+ // static_check/rules/self_drawn_sheet.ts — GATE self-drawn-sheet-no-drag-dismiss.
2
+ //
3
+ // Material ModalBottomSheet / BottomSheetDialog close when the user drags the panel down. A converter that redraws
4
+ // the sheet as a Stack (full-screen scrim + bottom panel) to match the Android look keeps the tap-scrim-to-close but
5
+ // silently loses the drag: nothing in ArkUI adds it to a plain Stack. bindSheet keeps the drag, and with
6
+ // `dragBar: false` the builder can draw the Android drag handle itself, so the look is not a reason to self-draw.
7
+
8
+ import * as fs from 'fs';
9
+ import { report } from '../core/findings.ts';
10
+ import { attrsWithArgs, directUiChildren, fullOnAxis, hasAttr, lineOfIndex, markedAbove, matchBracket } from '../core/parse.ts';
11
+ import { androidStemsWhere, portedAndroidStem } from '../core/android.ts';
12
+ import { maskedOf } from '../core/scan.ts';
13
+ import type { FileScan } from '../core/scan.ts';
14
+ import type { RuleMeta } from '../core/meta.ts';
15
+
16
+ /** Rule metadata (rendered by scripts/gen_rule_docs.mjs). */
17
+ export const meta: RuleMeta[] = [
18
+ {
19
+ id: "self-drawn-sheet-no-drag-dismiss",
20
+ levels: ["GATE", "CAND"],
21
+ invariant: "interaction",
22
+ card: "widgets",
23
+ needs: ["--android"],
24
+ summary: "`Stack({ alignContent: Alignment.Bottom* })` 的直接子节点里有宽高都撑满且挂了 `.onClick` 的遮罩层,另有一个兄弟节点(面板),而这个 Stack 块内、以及它调用的 `this.X()` @Builder 体内都没有 `PanGesture` / `SwipeGesture`。按每个 Stack 单独判断:同一文件里别的弹层用了 `bindSheet` 或手势,不豁免这一个。GATE 需带 `--android`,且本文件对应的 Android 源文件(文件名相同,或引用了 `X.kt`)用了 `ModalBottomSheet` / `BottomSheetDialog` / `BottomSheetScaffold`;其余只报 CAND。已知误报:「点空白处收起键盘 + 底部栏」这类撑满可点层加兄弟节点的结构,在对应 Android 文件也有底部弹层时同样报 GATE,确认不是弹层后用标记关闭。",
25
+ fix: "Android 的 Material 底部弹层可以下拉关闭,自绘 Stack 只保留了点遮罩关闭。优先改回 `bindSheet(..., { dragBar: false, backgroundColor, ... })` 或 `UIContext.openBindSheet`,在 builder 里自己画 Android 的拖动指示条(`dragBar: false` 后系统不再画,不会重复绘制);必须自绘时,在面板上挂 `PanGesture({ direction: PanDirection.Down })`,跟手位移并在超过阈值或速度时调用关闭回调,同时处理返回键。确实不能拖动关闭(Android 设了 `sheetGesturesEnabled = false` 或 `confirmValueChange` 拒绝隐藏)时,在 Stack 上方写 `// SHEET-NO-DRAG: <源码依据>` 关闭本条。",
26
+ escape: "// SHEET-NO-DRAG:",
27
+ cases: [
28
+ "实测(CoolMall 商品详情,ds-1123):规格选择弹层与优惠券弹层都对照 BottomModal.kt 的 ModalBottomSheet,转换时认为 bindSheet 的 dragBar 会和 40×4dp 指示条重复绘制,按部件归属规则改判 (a) 自绘 Stack;遮罩点击能关闭,下拉面板没有任何反应。编译、GATE、冒烟、评审全过。",
29
+ ],
30
+ },
31
+ ];
32
+
33
+ /** Android files that show a Material bottom sheet (cached per dir by androidStemsWhere). */
34
+ function sheetStems(dir: string): Set<string> {
35
+ return androidStemsWhere(dir, 'modal-bottom-sheet', 'Sheet',
36
+ (src) => /\bModalBottomSheet\s*\(|\bBottomSheetDialog(?:Fragment)?\b|\bBottomSheetScaffold\s*\(/.test(src));
37
+ }
38
+
39
+ /** Gestures that give a self-drawn panel a drag-to-close. */
40
+ const DRAG: RegExp = /\bPanGesture\s*\(|\bSwipeGesture\s*\(/;
41
+
42
+ /**
43
+ * Whether this sheet's own code adds a drag: the Stack block itself, or the body of a @Builder it calls (`this.Panel()`,
44
+ * the usual home of the panel). A PanGesture or bindSheet elsewhere in the file belongs to another overlay and says
45
+ * nothing about this one.
46
+ */
47
+ function sheetHasDrag(code: string, masked: string, open: number, close: number): boolean {
48
+ const block: string = masked.slice(open, close);
49
+ if (DRAG.test(block)) { return true; }
50
+ for (const c of block.matchAll(/\bthis\.([A-Za-z_$][\w$]*)\s*\(/g)) {
51
+ const decl: RegExpExecArray | null =
52
+ new RegExp('@Builder\\s+(?:(?:private|public|protected)\\s+)*' + c[1].replace(/\$/g, '\\$') + '\\s*\\(').exec(masked);
53
+ if (decl === null) { continue; }
54
+ const paren: number = decl.index + decl[0].length - 1;
55
+ const pclose: number = matchBracket(masked, paren);
56
+ if (pclose < 0) { continue; }
57
+ const bo: number = masked.indexOf('{', pclose);
58
+ const bc: number = bo < 0 ? -1 : matchBracket(masked, bo);
59
+ if (bc > bo && DRAG.test(code.slice(bo, bc))) { return true; }
60
+ }
61
+ return false;
62
+ }
63
+
64
+ export function checkSelfDrawnSheet(scans: FileScan[], androidDir: string): void {
65
+ const stems: Set<string> = androidDir !== '' && fs.existsSync(androidDir) ? sheetStems(androidDir) : new Set();
66
+ for (const s of scans) {
67
+ const masked: string = maskedOf(s);
68
+ if (!/\bStack\s*\(\s*\{[^)]*alignContent\s*:\s*Alignment\.Bottom/.test(masked)) { continue; }
69
+ const rawLines: string[] = s.src.split(/\r?\n/);
70
+ for (const m of masked.matchAll(/(?<![\w$.])Stack\s*\(/g)) {
71
+ const paren: number = (m.index ?? 0) + m[0].length - 1;
72
+ const pclose: number = matchBracket(masked, paren);
73
+ if (pclose < 0) { continue; }
74
+ if (!/alignContent\s*:\s*Alignment\.Bottom(?:Start|End)?\b/.test(s.code.slice(paren + 1, pclose))) { continue; }
75
+ let k: number = pclose + 1;
76
+ while (k < masked.length && /\s/.test(masked[k])) { k++; }
77
+ if (masked[k] !== '{') { continue; }
78
+ const close: number = matchBracket(masked, k);
79
+ if (close < 0) { continue; }
80
+ const kids = directUiChildren(s.code, k, close, undefined, { intoBranches: true });
81
+ // the scrim: fills the Stack on both axes and closes the sheet on tap
82
+ const scrim = kids.find((c) => !c.isBuilderCall && fullOnAxis(c.attrs, 'width') && fullOnAxis(c.attrs, 'height') &&
83
+ hasAttr(c.attrs, 'onClick'));
84
+ // the panel: another child (a builder call or component) besides the scrim
85
+ if (scrim === undefined || kids.filter((c) => c !== scrim).length === 0) { continue; }
86
+ const line: number = lineOfIndex(s.code, m.index ?? 0);
87
+ if (markedAbove(rawLines, line, 'SHEET-NO-DRAG')) { continue; }
88
+ if (sheetHasDrag(s.code, masked, k, close)) { continue; }
89
+ // a Stack that itself hosts or opens a managed sheet (bindSheet on its chain, or in its block) is not a self-drawn one
90
+ if (/\.bindSheet\s*\(|\bopenBindSheet\s*\(/.test(masked.slice(k, close)) ||
91
+ attrsWithArgs(s.code, paren).some((a) => a.name === 'bindSheet' || a.name === 'bindContentCover')) { continue; }
92
+ const stem: string | null = stems.size > 0 ? portedAndroidStem(s.abs, s.src, stems) : null;
93
+ report(stem !== null ? 'GATE' : 'CAND', 'self-drawn-sheet-no-drag-dismiss', s.rel, line,
94
+ 'self-drawn bottom sheet: this Stack(alignContent: Bottom) holds a full-screen scrim that closes on tap ' +
95
+ `(line ${lineOfIndex(s.code, scrim.at)}) and a panel, and neither the Stack nor the @Builder it calls adds a ` +
96
+ 'drag (no PanGesture / SwipeGesture). ' +
97
+ (stem !== null
98
+ ? `${stem}.kt shows a Material bottom sheet, which closes when dragged down; this one cannot be dragged. `
99
+ : 'If the Android source is a Material bottom sheet, it closes when dragged down and this one cannot. ') +
100
+ "Use bindSheet / openBindSheet with dragBar: false and draw the Android drag handle in the builder, or add a " +
101
+ "PanGesture(Down) on the panel that calls the dismiss callback; write // SHEET-NO-DRAG: <source evidence> when " +
102
+ 'the source disables the drag');
103
+ }
104
+ }
105
+ }
@@ -0,0 +1,127 @@
1
+ // static_check/rules/staggered_lanes.ts — GATE staggered-grid-lanes-by-index.
2
+ //
3
+ // A Compose LazyVerticalStaggeredGrid / RecyclerView StaggeredGridLayoutManager places each item into the column
4
+ // that is currently shortest. Splitting the data by index parity into two Columns (item 0, 2, 4 … left; 1, 3, 5 …
5
+ // right) keeps the item count balanced but not the height: with cards of different heights one column grows longer
6
+ // with every row, and the order the user reads (left-right, top-down) no longer matches the source. Neither column is
7
+ // lazy either, so the whole list is laid out at once inside one ListItem.
8
+
9
+ import * as fs from 'fs';
10
+ import { report } from '../core/findings.ts';
11
+ import { lineOfIndex, markedAbove, matchBracket, splitTopLevel } from '../core/parse.ts';
12
+ import { androidStemsWhere, portedAndroidStem } from '../core/android.ts';
13
+ import { maskedOf } from '../core/scan.ts';
14
+ import type { FileScan } from '../core/scan.ts';
15
+ import type { RuleMeta } from '../core/meta.ts';
16
+
17
+ /** Rule metadata (rendered by scripts/gen_rule_docs.mjs). */
18
+ export const meta: RuleMeta[] = [
19
+ {
20
+ id: "staggered-grid-lanes-by-index",
21
+ levels: ["GATE", "CAND"],
22
+ invariant: "geometry",
23
+ card: "geometry",
24
+ needs: ["--android"],
25
+ summary: "按下标奇偶把数组分成两列:`for (let i = <非 0 起点>; …; i += 2)`,或 `.filter((_, i) => i % 2 …)`。GATE 需带 `--android`,且对应 Android 源文件(文件名相同,或引用了 `X.kt`)用了 `LazyVerticalStaggeredGrid` / `StaggeredGridItemSpan` / `StaggeredGridLayoutManager` 的那个 .ets 文件里能看到两列的形状:循环所在方法(成员方法或顶层函数均可)被以车道实参 `0` 和 `1` 各调用一次(如 `vm.laneItems(0)` / `laneItems(this.all, 1)`),或同一文件里写了两处 `.filter` 分列。其余步长为 2 的循环(成对遍历 key/value 等)只报 CAND。",
26
+ fix: "瀑布流按「当前最短列」放置每一项,奇偶分列只平衡了数量、没有平衡高度,卡片高度不一时两列越往下错位越大,也无法懒加载。改用 `WaterFlow` + `FlowItem`(`columnsTemplate('1fr 1fr')`);`span = FullLine` 的整行项放进 `crossCount: 1` 的分组(`WaterFlowSections`,间距规则见 waterflow-sections-no-gap)。源码确实是按奇偶分两列(不是瀑布流)时在分列代码上方写 `// LANES-BY-INDEX: <源码依据>` 关闭本条。",
27
+ escape: "// LANES-BY-INDEX:",
28
+ cases: [
29
+ "实测(CoolMall 首页,ds-1123):Android HomeScreen.kt 是 RefreshLayout(isGrid = true) 的 LazyVerticalStaggeredGrid(Fixed(2)),前段 FullLine;鸿蒙 HomeRoutePage.ets 用 List 套 Row 两个 Column,HomeRouteViewModel.laneItems() 按 i += 2 分列。转换报告把它登记成「权重 + 固定间距」,phase5_check 全过,真机上首页商品区越往下两列错位越大,排版与安卓不一致。",
30
+ ],
31
+ },
32
+ ];
33
+
34
+ /** `for (let i = <start>; i < …; i += 2)` with a start other than the literal 0 (lane = 0 / 1 passed in). */
35
+ const LANE_LOOP: RegExp =
36
+ /\bfor\s*\(\s*(?:let|var)\s+([A-Za-z_$][\w$]*)\s*(?::\s*number\s*)?=\s*([^;]+?)\s*;\s*\1\s*<=?[^;]+;\s*\1\s*\+=\s*2\s*\)/g;
37
+ /** `.filter((x, i) => i % 2 === k)` and its variants. */
38
+ const LANE_FILTER: RegExp = /\.filter\s*\(\s*\(\s*[^,)]*,\s*([A-Za-z_$][\w$]*)[^)]*\)\s*(?::\s*\w+\s*)?=>[^)]*?\b\1\s*%\s*2\b/g;
39
+
40
+ /** Android files that lay out a staggered grid (cached per dir by androidStemsWhere). */
41
+ function staggeredStems(dir: string): Set<string> {
42
+ return androidStemsWhere(dir, 'staggered-grid', 'Staggered',
43
+ (src) => /\bLazyVerticalStaggeredGrid\s*\(|\bStaggeredGridItemSpan\b|\bLazyStaggeredGridScope\b|\bStaggeredGridLayoutManager\s*\(/.test(src));
44
+ }
45
+
46
+ /** Name of the innermost method / getter / function whose body contains pos ('' when none). */
47
+ function enclosingMethod(masked: string, pos: number): string {
48
+ const re: RegExp = /(?:\bget\s+|\bfunction\s+)?([A-Za-z_$][\w$]*)\s*\([^()]*\)\s*(?::\s*[^{;=]+?)?\s*\{/g;
49
+ let best: string = '';
50
+ let bestOpen: number = -1;
51
+ let m: RegExpExecArray | null;
52
+ while ((m = re.exec(masked)) !== null) {
53
+ if (m.index > pos) { break; }
54
+ if (/^(?:if|for|while|switch|catch|function)$/.test(m[1])) { continue; }
55
+ const open: number = m.index + m[0].length - 1;
56
+ const close: number = matchBracket(masked, open);
57
+ if (close > pos && open > bestOpen) { best = m[1]; bestOpen = open; }
58
+ }
59
+ return best;
60
+ }
61
+
62
+ /**
63
+ * Whether masked code calls `name(…)` once with a lane argument `0` and once with `1` (any argument position, so both
64
+ * `vm.laneItems(0)` and a top-level `laneItems(this.all, 1)` count). That pair — one call per sibling column — is what
65
+ * separates a two-column split from any other step-2 loop; a generic name such as `get` called as `map.get('a')`
66
+ * passes no lane literal and does not count. The declaration itself (`name(lane: number)`) is skipped.
67
+ */
68
+ function callsBothLanes(masked: string, name: string): boolean {
69
+ const lanes: Set<string> = new Set();
70
+ const re: RegExp = new RegExp('(?<![\\w$])' + name.replace(/\$/g, '\\$') + '\\s*\\(', 'g');
71
+ for (const c of masked.matchAll(re)) {
72
+ const paren: number = (c.index ?? 0) + c[0].length - 1;
73
+ const close: number = matchBracket(masked, paren);
74
+ if (close < 0) { continue; }
75
+ if (/^\s*(?::[^{;]*)?\{/.test(masked.slice(close + 1, close + 80))) { continue; } // a declaration, not a call
76
+ for (const a of splitTopLevel(masked.slice(paren + 1, close))) {
77
+ const t: string = a.trim();
78
+ if (t === '0' || t === '1') { lanes.add(t); }
79
+ }
80
+ }
81
+ return lanes.size === 2;
82
+ }
83
+
84
+ /** `.filter((x, i) => i % 2 …)` written twice in one file: both columns of an inline split. */
85
+ function filtersBothLanes(masked: string): boolean {
86
+ return [...masked.matchAll(LANE_FILTER)].length >= 2;
87
+ }
88
+
89
+ export function checkStaggeredLanes(scans: FileScan[], androidDir: string): void {
90
+ const stems: Set<string> = androidDir !== '' && fs.existsSync(androidDir) ? staggeredStems(androidDir) : new Set();
91
+ // .ets files that port an Android staggered grid, with the Android stem they port
92
+ const porting: { scan: FileScan; stem: string }[] = [];
93
+ for (const s of scans) {
94
+ const stem: string | null = stems.size > 0 ? portedAndroidStem(s.abs, s.src, stems) : null;
95
+ if (stem !== null) { porting.push({ scan: s, stem }); }
96
+ }
97
+ for (const s of scans) {
98
+ const masked: string = maskedOf(s);
99
+ if (!/\+=\s*2\b|%\s*2\b/.test(masked)) { continue; }
100
+ const rawLines: string[] = s.src.split(/\r?\n/);
101
+ const sites: { at: number; filter: boolean }[] = [];
102
+ for (const m of masked.matchAll(LANE_LOOP)) {
103
+ if (/^0+$/.test(m[2].trim())) { continue; } // chunking rows of two from 0 is not a lane split
104
+ sites.push({ at: m.index ?? 0, filter: false });
105
+ }
106
+ for (const m of masked.matchAll(LANE_FILTER)) { sites.push({ at: m.index ?? 0, filter: true }); }
107
+ for (const site of sites) {
108
+ const line: number = lineOfIndex(s.code, site.at);
109
+ if (markedAbove(rawLines, line, 'LANES-BY-INDEX')) { continue; }
110
+ const method: string = site.filter ? '' : enclosingMethod(masked, site.at);
111
+ // GATE only for the two-column shape in a file that ports the grid: a loop split called once per lane
112
+ // (lane 0 and lane 1), or both inline filters in that file. Any other step-2 loop stays CAND.
113
+ const user: { scan: FileScan; stem: string } | undefined = porting.find((p) =>
114
+ site.filter ? p.scan === s && filtersBothLanes(masked) : method !== '' && callsBothLanes(maskedOf(p.scan), method));
115
+ const where: string = method === '' ? '' : ` in ${method}()`;
116
+ report(user !== undefined ? 'GATE' : 'CAND', 'staggered-grid-lanes-by-index', s.rel, line,
117
+ `the data is split into columns by index parity${where}: items 0, 2, 4 … go left and 1, 3, 5 … right. ` +
118
+ (user !== undefined
119
+ ? `${user.scan.rel} ports ${user.stem}.kt, a staggered grid, which places each item into the currently shortest ` +
120
+ 'column: with cards of different heights the two parity columns drift further apart row by row. '
121
+ : 'If the Android source is a staggered grid (LazyVerticalStaggeredGrid / StaggeredGridLayoutManager), it places ' +
122
+ 'each item into the shortest column, which parity columns do not reproduce. ') +
123
+ "Use WaterFlow + FlowItem (columnsTemplate('1fr 1fr')), full-line items in a crossCount: 1 section; " +
124
+ 'when the source really splits by parity, write // LANES-BY-INDEX: <source evidence> above the split');
125
+ }
126
+ }
127
+ }
@@ -0,0 +1,114 @@
1
+ // static_check/rules/window_size_constant.ts — GATE window-size-frozen-constant.
2
+ //
3
+ // Compose code often bounds a region by the window: `heightIn(max = screenHeight - 380.dp)` with screenHeight read
4
+ // from LocalWindowInfo / LocalConfiguration. A converter that evaluates that expression on the capture device and
5
+ // writes the result (914.29 − 380 = 534) as a constant reproduces the reference frame exactly, and breaks on any
6
+ // other window height: on a shorter screen the region keeps its 534 vp and pushes whatever follows it off screen.
7
+
8
+ import * as fs from 'fs';
9
+ import { report } from '../core/findings.ts';
10
+ import { lineOfIndex, markedAbove } from '../core/parse.ts';
11
+ import { androidStemsWhere, portedAndroidStem } from '../core/android.ts';
12
+ import { maskedOf } from '../core/scan.ts';
13
+ import type { FileScan } from '../core/scan.ts';
14
+ import type { RuleMeta } from '../core/meta.ts';
15
+
16
+ /** Rule metadata (rendered by scripts/gen_rule_docs.mjs). */
17
+ export const meta: RuleMeta[] = [
18
+ {
19
+ id: "window-size-frozen-constant",
20
+ levels: ["GATE", "CAND"],
21
+ invariant: "geometry",
22
+ card: "geometry",
23
+ needs: ["--android"],
24
+ summary: "`constraintSize` 的 `maxHeight` / `maxWidth` 是数字字面量(≥ 100),或是本文件里初值为这种字面量的常量,且本文件没有读运行时窗口尺寸(`getDefaultDisplaySync` / `getWindowProperties` / `windowSizeChange` / `windowRect` / `mainWindowSize`;`onAreaChange` / `onSizeChange` 量的是组件,不算)。按维度判:本文件对应的 Android 源文件(文件名相同,或引用了 `X.kt`)读了同一维度的窗口尺寸(高度:`.screenHeightDp` / `heightPixels` / `containerSize.height` / `bounds.height()`;宽度同理)时报 GATE;只读了不带维度的窗口 API(`LocalWindowInfo` / `LocalConfiguration` / `displayMetrics` / `currentWindowMetrics`)时报 CAND;只读了另一维度时不报。成员名单独匹配,先存到局部变量(`configuration.screenHeightDp`)和 Java 写法(`getDisplayMetrics().heightPixels`)都算。",
25
+ fix: "Android 侧按运行时窗口算的上限,不能写成采集机算出来的常量:屏幕一矮,这块区域保持原高度,后面的按钮被挤出屏幕。改用运行时窗口高度(`display.getDefaultDisplaySync()` / 窗口 `getWindowProperties().windowRect`,px 转 vp 后减去源码里的保留高度),或者改成弹性布局:可滚动区 `layoutWeight(1)`(或 `flexShrink(1)`)放在有 `constraintSize({ maxHeight })` 的父容器里,固定区块(按钮行)放在它后面,不随内容变化而被挤出。上限确实与窗口无关时在该行上方写 `// SIZE-NOT-WINDOW: <源码依据>` 关闭本条。",
26
+ escape: "// SIZE-NOT-WINDOW:",
27
+ cases: [
28
+ "实测(CoolMall 规格选择弹层,ds-1123):SpecSelectModal.kt:269-274 用 LocalWindowInfo 取屏高,规格区 heightIn(max = 屏高 − 380dp);鸿蒙写成 SPEC_AREA_MAX_VP = 534(采集机 914.29 − 380),面板本身没有高度上限。选中规格后多出已选名称和数量两行,面板超出可用高度,底部「加入购物车 / 立即购买」被挤出屏幕。静态裁切检查只算了采集到的未选中帧(759 < 783.6),判通过。",
29
+ ],
30
+ },
31
+ ];
32
+
33
+ /**
34
+ * Android reads of the window / screen height and width, matched on the member so that a value read into a local
35
+ * first (`val configuration = LocalConfiguration.current; configuration.screenHeightDp`) and the Java / View form
36
+ * (`getResources().getDisplayMetrics().heightPixels`) count too.
37
+ */
38
+ const ANDROID_HEIGHT_READ: RegExp =
39
+ /\.screenHeightDp\b|\bheightPixels\b|\bcontainerSize\.height\b|\bbounds\.height\s*\(|\bwindowHeightSizeClass\b|\bheightSizeClass\b/;
40
+ const ANDROID_WIDTH_READ: RegExp =
41
+ /\.screenWidthDp\b|\bwidthPixels\b|\bcontainerSize\.width\b|\bbounds\.width\s*\(|\bwindowWidthSizeClass\b|\bwidthSizeClass\b/;
42
+ /** Window-size APIs that do not name the axis on the same line (the dimension is then unknown). */
43
+ const ANDROID_WINDOW_ANY: RegExp =
44
+ /\bLocalWindowInfo\b|\bcurrentWindowMetrics\b|\bWindowMetricsCalculator\b|\bcalculateWindowSizeClass\s*\(|\bgetDisplayMetrics\s*\(|\bdisplayMetrics\b|\bLocalConfiguration\b/;
45
+
46
+ /**
47
+ * ArkTS APIs that read the runtime window size; any of them means the file already works from the real window.
48
+ * onAreaChange / onSizeChange are not among them: they measure a component, and converted code uses them for
49
+ * sticky headers and the like with no relation to the window.
50
+ */
51
+ const ETS_WINDOW_READ: RegExp =
52
+ /\bgetDefaultDisplaySync\s*\(|\bgetWindowProperties\s*\(|\bwindowSizeChange\b|\bwindowRect\b|\bmainWindowSize\b/;
53
+
54
+ type Axis = 'height' | 'width';
55
+
56
+ /** Android stems reading the window size, per axis; 'any' = reads it without naming the axis (no prefilter word). */
57
+ function windowStems(dir: string): { height: Set<string>; width: Set<string>; any: Set<string> } {
58
+ return {
59
+ height: androidStemsWhere(dir, 'window-size-height', '', (src) => ANDROID_HEIGHT_READ.test(src)),
60
+ width: androidStemsWhere(dir, 'window-size-width', '', (src) => ANDROID_WIDTH_READ.test(src)),
61
+ any: androidStemsWhere(dir, 'window-size-any', '',
62
+ (src) => ANDROID_WINDOW_ANY.test(src) && !ANDROID_HEIGHT_READ.test(src) && !ANDROID_WIDTH_READ.test(src)),
63
+ };
64
+ }
65
+
66
+ export function checkWindowSizeConstant(scans: FileScan[], androidDir: string): void {
67
+ if (androidDir === '' || !fs.existsSync(androidDir)) { return; }
68
+ const stems = windowStems(androidDir);
69
+ if (stems.height.size + stems.width.size + stems.any.size === 0) { return; }
70
+ for (const s of scans) {
71
+ const masked: string = maskedOf(s);
72
+ if (!/\bconstraintSize\s*\(/.test(masked)) { continue; }
73
+ if (ETS_WINDOW_READ.test(s.code)) { continue; }
74
+ const byAxis: Record<Axis, string | null> = {
75
+ height: portedAndroidStem(s.abs, s.src, stems.height),
76
+ width: portedAndroidStem(s.abs, s.src, stems.width),
77
+ };
78
+ const anyStem: string | null = portedAndroidStem(s.abs, s.src, stems.any);
79
+ if (byAxis.height === null && byAxis.width === null && anyStem === null) { continue; }
80
+ // file-level numeric constants: NAME = 534
81
+ const consts: Map<string, number> = new Map();
82
+ for (const c of masked.matchAll(/\b(?:const|readonly)\s+([A-Za-z_$][\w$]*)\s*(?::\s*number\s*)?=\s*(\d+(?:\.\d+)?)\s*[;\n]/g)) {
83
+ consts.set(c[1], Number(c[2]));
84
+ }
85
+ const rawLines: string[] = s.src.split(/\r?\n/);
86
+ for (const m of masked.matchAll(/\bconstraintSize\s*\(\s*\{([^}]*)\}/g)) {
87
+ for (const k of m[1].matchAll(/\b(maxHeight|maxWidth)\s*:\s*([A-Za-z_$][\w$.]*|\d+(?:\.\d+)?)\s*(?=[,}\s]|$)/g)) {
88
+ const ref: string = k[2].replace(/^this\./, '');
89
+ const value: number | undefined = /^\d/.test(ref) ? Number(ref) : consts.get(ref);
90
+ if (value === undefined || value < 100) { continue; }
91
+ const line: number = lineOfIndex(s.code, m.index ?? 0);
92
+ if (markedAbove(rawLines, line, 'SIZE-NOT-WINDOW')) { continue; }
93
+ // GATE when the Android file reads this very axis; CAND when it reads the window without naming an axis;
94
+ // nothing when it reads only the other axis (a screenWidthDp image width says nothing about a maxHeight).
95
+ const axis: Axis = k[1] === 'maxHeight' ? 'height' : 'width';
96
+ const stem: string | null = byAxis[axis] ?? anyStem;
97
+ if (stem === null) { continue; }
98
+ const gate: boolean = byAxis[axis] !== null;
99
+ report(gate ? 'GATE' : 'CAND', 'window-size-frozen-constant', s.rel, line,
100
+ `constraintSize ${k[1]}: ${k[2]}${ref !== String(value) ? ` (= ${value})` : ''} is a fixed number, while ` +
101
+ (gate
102
+ ? `${stem}.kt reads the window ${axis} at runtime (screen${axis === 'height' ? 'Height' : 'Width'}Dp / ` +
103
+ `${axis}Pixels / containerSize.${axis} …)`
104
+ : `${stem}.kt reads the window size without naming the axis on the same line (LocalWindowInfo / ` +
105
+ 'LocalConfiguration / displayMetrics): check whether this bound comes from it') +
106
+ ' and this file reads no window size. A value worked out on the capture device only fits that ' +
107
+ 'screen: on a shorter window the region keeps its size and pushes what follows it (bottom buttons) off screen. ' +
108
+ 'Read the runtime window size, or make the region flexible (layoutWeight(1) / flexShrink(1) under a bounded ' +
109
+ 'parent) so the fixed blocks after it stay on screen; write // SIZE-NOT-WINDOW: <source evidence> when the ' +
110
+ 'bound does not come from the window');
111
+ }
112
+ }
113
+ }
114
+ }