@buaa_smat/hometrans 26.0.7 → 26.0.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 (154) hide show
  1. package/agents/a2h-executor.md +37 -0
  2. package/env-requirements.json +15 -1
  3. package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
  4. package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
  5. package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
  6. package/i18n/skills/a2h-app-migrate/SKILL.md +2 -2
  7. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +27 -4
  8. package/i18n/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
  9. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
  10. package/i18n/skills/a2h-batch-ui-align/SKILL.md +7 -7
  11. package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
  12. package/i18n/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
  13. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
  14. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
  15. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
  16. package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
  17. package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
  18. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
  19. package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
  20. package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
  21. package/i18n/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
  22. package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
  23. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
  24. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
  25. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
  26. package/i18n/skills/a2h-page-specgen/SKILL.md +1 -1
  27. package/i18n/skills/a2h-page-specgen/references/gates.md +3 -1
  28. package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +11 -11
  29. package/i18n/skills/a2h-page-specgen/references/spec-template.md +3 -3
  30. package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
  31. package/i18n/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
  32. package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +144 -0
  33. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +11 -11
  34. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +11 -11
  35. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +11 -11
  36. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +11 -11
  37. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
  38. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
  39. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +11 -11
  40. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +11 -11
  41. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +11 -11
  42. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +11 -11
  43. package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
  44. package/i18n/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
  45. package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +132 -3
  46. package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
  47. package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
  48. package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
  49. package/i18n/skills/a2h-utg-static/SKILL.md +2 -0
  50. package/package.json +1 -1
  51. package/platforms/atomcode/agents/a2h-executor.frontmatter.md +6 -0
  52. package/platforms/codebuddy/agents/a2h-executor.frontmatter.md +5 -0
  53. package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
  54. package/platforms/deveco/agents/a2h-executor.frontmatter.md +7 -0
  55. package/platforms/deveco/agents/build-fixer.frontmatter.md +0 -2
  56. package/platforms/deveco/agents/code-reviewer.frontmatter.md +0 -2
  57. package/platforms/deveco/agents/model-render-worker.frontmatter.md +0 -2
  58. package/platforms/deveco/agents/model-worker.frontmatter.md +0 -2
  59. package/platforms/deveco/agents/specgen-worker.frontmatter.md +0 -2
  60. package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
  61. package/platforms/opencode/agents/a2h-executor.frontmatter.md +7 -0
  62. package/platforms/opencode/agents/build-fixer.frontmatter.md +0 -2
  63. package/platforms/opencode/agents/code-reviewer.frontmatter.md +0 -2
  64. package/platforms/opencode/agents/model-render-worker.frontmatter.md +0 -2
  65. package/platforms/opencode/agents/model-worker.frontmatter.md +0 -2
  66. package/platforms/opencode/agents/specgen-worker.frontmatter.md +0 -2
  67. package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
  68. package/skills/a2h-app-migrate/SKILL.md +29 -3
  69. package/skills/a2h-app-migrate/references/host-rules.md +33 -0
  70. package/skills/a2h-app-migrate/references/workflow.yaml +24 -4
  71. package/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
  72. package/skills/a2h-app-migrate/test/test_executor_header_sync.mjs +78 -0
  73. package/skills/a2h-app-migrate/test/test_opencode_depth.mjs +312 -0
  74. package/skills/a2h-app-migrate/tools/dag.mjs +267 -0
  75. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
  76. package/skills/a2h-batch-ui-align/SKILL.md +7 -7
  77. package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
  78. package/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
  79. package/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
  80. package/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
  81. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
  82. package/skills/a2h-batch-ui-align/references/host-dispatch.md +5 -5
  83. package/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
  84. package/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
  85. package/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
  86. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
  87. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
  88. package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +3 -2
  89. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +139 -23
  90. package/skills/a2h-batch-ui-align/scripts/host_env.mjs +32 -8
  91. package/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
  92. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
  93. package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
  94. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
  95. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +82 -0
  96. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
  97. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +184 -2
  98. package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +33 -0
  99. package/skills/a2h-batch-ui-align/scripts/tests/interactions.test.mjs +258 -0
  100. package/skills/a2h-page-specgen/SKILL.md +1 -1
  101. package/skills/a2h-page-specgen/references/evidence.md +15 -0
  102. package/skills/a2h-page-specgen/references/gates.md +3 -1
  103. package/skills/a2h-page-specgen/references/scenario-authoring.md +10 -10
  104. package/skills/a2h-page-specgen/references/spec-template.md +2 -2
  105. package/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
  106. package/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
  107. package/skills/a2h-page-specgen/scripts/gate.mjs +141 -0
  108. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +10 -10
  109. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +10 -10
  110. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +10 -10
  111. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +10 -10
  112. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
  113. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
  114. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +10 -10
  115. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +10 -10
  116. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +10 -10
  117. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +10 -10
  118. package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
  119. package/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
  120. package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +104 -3
  121. package/skills/a2h-resource-convert/references/conversion-rules.md +2 -0
  122. package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
  123. package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +42 -0
  124. package/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
  125. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
  126. package/skills/a2h-spec-design-pipeline/references/execution-model.md +2 -2
  127. package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +5 -1
  128. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
  129. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
  130. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +2 -1
  131. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +3 -1
  132. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-cn.md +105 -0
  133. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-en.md +122 -0
  134. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +4 -4
  135. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIV2ObservationCheck.js +1862 -0
  136. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +2 -0
  137. package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
  138. package/skills/a2h-spec-design-pipeline/scripts/dispatch/wait.mjs +15 -2
  139. package/skills/a2h-spec-design-pipeline/scripts/dispatch.mjs +20 -4
  140. package/skills/a2h-spec-design-pipeline/scripts/test_arkui_v2_observation.ts +284 -0
  141. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_commands.mjs +32 -0
  142. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_wait.mjs +22 -1
  143. package/skills/a2h-utg-static/SKILL.md +2 -0
  144. package/skills/a2h-utg-static/references/extractors.md +16 -0
  145. package/skills/a2h-utg-static/scripts/run_pipeline.mjs +22 -1
  146. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +4 -0
  147. package/skills/a2h-utg-static/scripts/tests/test_pr169_review_fixes.mjs +15 -0
  148. package/skills/a2h-utg-static/scripts/tests/test_view_attachments.mjs +330 -0
  149. package/skills/a2h-utg-static/scripts/view_attachments.mjs +465 -0
  150. package/platforms/codebuddy/agents/build-fixer.frontmatter.md +0 -5
  151. package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +0 -5
  152. package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +0 -5
  153. package/platforms/codebuddy/agents/model-worker.frontmatter.md +0 -5
  154. package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +0 -5
@@ -0,0 +1,465 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * view_attachments.mjs — auxiliary views handed to another view (S3 interaction surfaces).
4
+ *
5
+ * view_attachments.mjs <workspace> --project <project> [--append]
6
+ *
7
+ * A project View class that is CONSTRUCTED and then handed to something other than a layout
8
+ * container is an auxiliary surface of the receiving view: a chart marker, a tooltip, an empty
9
+ * view, a dialog body. It is usually shown by the receiver's own touch handling, so no click
10
+ * listener in the app names it, and `view_interactions` (click bindings) never sees it.
11
+ *
12
+ * Detection is structural; no library or API name is listed:
13
+ * 1. view classes — project classes whose base is a View-family name (`*View`, `*Layout`,
14
+ * `View`, `ViewGroup`, `*Button`, transitively through other project classes), or whose
15
+ * body inflates into / finds views on ITSELF. Fragments, Activities, Adapters, ViewHolders,
16
+ * decorations, dialogs and listeners are not views even when they call findViewById.
17
+ * 2. construction sites — `new X(..)` / Kotlin `X(..)`, not declarations or supertype calls.
18
+ * 3. sinks — where the new instance goes, through at most one local / field variable and at
19
+ * most one factory-function hop:
20
+ * call-arg `chart.setMarker(X(..))`, `setMarker(X(..))`
21
+ * prop-assign `chart.marker = X(..)`, `marker = X(..)` in `apply { }` / `run { }` / `with(c) { }`
22
+ * via-var `val m = X(..); chart.marker = m`
23
+ * via-fn `fun mk() = X(..)` ... `chart.marker = mk()` — a call receiver-less in the same
24
+ * file or qualified by the declaring class; an overriding factory has no call site
25
+ * A layout container call (`addView`, `setContentView`, ...), a collection call (`add`,
26
+ * `listOf`, ...) or a constructor argument is layout, not an attachment: counted, not emitted.
27
+ *
28
+ * Emits, per host node (the page owning the construction site, resolved with view_interactions'
29
+ * EvidenceIndex), `attachments[]`:
30
+ * {at, view_class, view_class_at, base, evidence[], layout?, sink: {kind, callee|target,
31
+ * receiver?, at}, via_var?, via_fn?}
32
+ * and `view_attachments.json` with every site, including host-less and dropped ones.
33
+ *
34
+ * Exports: VIEW_BASE NOT_VIEW LAYOUT_SINKS COLLECTION_SINKS viewClasses constructionSites
35
+ * statementPrefix classifySink collect main
36
+ */
37
+ import * as path from 'node:path';
38
+ import { pathToFileURL } from 'node:url';
39
+ import {
40
+ ArgumentParser, jsonDumps, jsonLoads, readText, writeText, pyPrintErr, pyPrintBuf, pyStrip, dset, tupleKey,
41
+ } from './_py.mjs';
42
+ import { sources, EvidenceIndex } from './view_interactions.mjs';
43
+ import { closeOf } from './interaction_sites.mjs';
44
+ import { enclosingClass, fnRanges } from './scope_utils.mjs';
45
+
46
+ /** Last segment of a base type that makes a class a View. */
47
+ export const VIEW_BASE = /^(?:View|ViewGroup|\w+View|\w+Layout|\w*Button)$/;
48
+ /** Own name or base name suffixes that are never a View, whatever their body does. */
49
+ export const NOT_VIEW = /(?:Fragment|Activity|Adapter|ViewHolder|ViewModel|Decoration|Callback|Listener|Binding|Dialog|Presenter|Controller|Service|Receiver|Application|Behavior|Factory)$/;
50
+ /** Sinks that place a view into the layout tree: the normal case, not an attachment. */
51
+ export const LAYOUT_SINKS = new Set(['addView', 'addViewInLayout', 'addContentView', 'setContentView',
52
+ 'addHeaderView', 'addFooterView', 'setCustomView', 'addPreference']);
53
+ /** Sinks that only collect instances (pager pages, lists). */
54
+ export const COLLECTION_SINKS = new Set(['add', 'addAll', 'put', 'set', 'push', 'offer', 'append',
55
+ 'listOf', 'mutableListOf', 'arrayListOf', 'arrayOf', 'setOf', 'mutableSetOf', 'mapOf', 'asList', 'of',
56
+ 'require', 'requireNotNull', 'checkNotNull', 'requireNonNull']);
57
+ const KEYWORDS = new Set(['if', 'for', 'while', 'when', 'switch', 'catch', 'synchronized', 'return',
58
+ 'super', 'this', 'throw', 'try', 'else', 'do', 'in', 'is', 'as', 'new']);
59
+ // Scope functions whose block has the receiver as `this` (`x.apply { marker = .. }`). In `also` / `let` /
60
+ // `takeIf` the receiver is `it`, so a bare `marker = ..` there is not the receiver's property.
61
+ const SCOPE_FNS = new Set(['apply', 'run']);
62
+
63
+ const lineOf = (text, pos) => { let n = 1; for (let i = text.indexOf('\n'); i !== -1 && i < pos; i = text.indexOf('\n', i + 1)) { n++; } return n; };
64
+ const ws = (c) => c === ' ' || c === '\t' || c === '\r' || c === '\n';
65
+ const lastSeg = (t) => t.split('.').at(-1);
66
+
67
+ // ── 1. view classes ──────────────────────────────────────────────────────────
68
+
69
+ const CLASS_HEAD = /\bclass\s+([A-Z]\w*)/g;
70
+ const SELF_VIEW = /(?<![\w.])(?:this\s*\.\s*)?findViewById\s*[<(]|\binflate\s*\([^;{}]*?,\s*this\s*[,)]|\bView\s*\.\s*inflate\s*\([^;{}]*?,\s*this\s*\)/;
71
+
72
+ /** Base type of the class header at `m` in masked code: Java `extends B`, Kotlin `: B(..)`, else null. */
73
+ function baseOf(code, m) {
74
+ let i = m.index + m[0].length;
75
+ const skipWs = () => { while (i < code.length && ws(code[i])) { i++; } };
76
+ skipWs();
77
+ if (code[i] === '<') { let d = 0; for (; i < code.length; i++) { if (code[i] === '<') { d++; } else if (code[i] === '>' && --d === 0) { i++; break; } } }
78
+ skipWs();
79
+ const ctor = /^(?:(?:@\w+\s*)*(?:private|protected|internal|public)\s+)?(?:@\w+\s*)*constructor\b/.exec(code.slice(i, i + 120));
80
+ if (ctor) { i += ctor[0].length; skipWs(); }
81
+ if (code[i] === '(') { i = closeOf(code, i); skipWs(); }
82
+ const rest = code.slice(i, i + 200);
83
+ const b = /^(?:extends\s+|:\s*)([A-Za-z_][\w.]*)/.exec(rest);
84
+ return b ? b[1] : null;
85
+ }
86
+
87
+ /** Body span `{...}` of the class header at `m`, or null. */
88
+ function bodyOf(code, m) {
89
+ const brace = code.indexOf('{', m.index);
90
+ if (brace === -1) { return null; }
91
+ // A body-less Kotlin class (`class B(c: Context) : A(c)`) must not borrow the next declaration's body.
92
+ const between = code.slice(m.index + m[0].length, brace).replace(/\([^()]*\)/g, '');
93
+ if (/[;=]|\b(?:class|fun|val|var|object|interface)\b/.test(between)) { return null; }
94
+ return [brace, closeOf(code, brace)];
95
+ }
96
+
97
+ /** The class's own body text: nested class bodies blanked, so their calls are not the outer class's. */
98
+ function ownBody(code, span) {
99
+ let body = code.slice(span[0], span[1]);
100
+ const nested = [...body.slice(1).matchAll(CLASS_HEAD)]
101
+ .map((m) => { const s = bodyOf(body, { index: m.index + 1, 0: m[0] }); return s; }).filter(Boolean);
102
+ for (const [s, e] of nested.reverse()) { body = body.slice(0, s) + ' '.repeat(e - s) + body.slice(e); }
103
+ return body;
104
+ }
105
+
106
+ /**
107
+ * Map{class name -> {path, at, base, evidence[]}} of project View classes. `code` is a
108
+ * Map{path -> masked text}. A name declared in two files is ambiguous and dropped.
109
+ */
110
+ export function viewClasses(code) {
111
+ const decl = new Map();
112
+ const dup = new Set();
113
+ for (const [p, text] of code) {
114
+ for (const m of text.matchAll(CLASS_HEAD)) {
115
+ const name = m[1];
116
+ if (decl.has(name)) { dup.add(name); continue; }
117
+ const body = bodyOf(text, m);
118
+ decl.set(name, { path: p, at: `${p}:${lineOf(text, m.index)}`, base: baseOf(text, m),
119
+ body: body ? ownBody(text, body) : '' });
120
+ }
121
+ }
122
+ for (const d of dup) { decl.delete(d); }
123
+ const out = new Map();
124
+ const isView = (name, seen = new Set()) => {
125
+ if (out.has(name)) { return true; }
126
+ const d = decl.get(name);
127
+ if (!d || seen.has(name) || NOT_VIEW.test(name)) { return false; }
128
+ seen.add(name);
129
+ const base = d.base ? lastSeg(d.base) : null;
130
+ if (base && NOT_VIEW.test(base)) { return false; }
131
+ const ev = [];
132
+ if (base && decl.has(base) && isView(base, seen)) { ev.push(`extends project view ${base}`); }
133
+ else if (base && VIEW_BASE.test(base)) { ev.push(`extends ${d.base}`); }
134
+ // Unqualified findViewById / inflate-into-this only compiles in a subclass of something:
135
+ // with no base at all the match is a nested or receiver-scoped call, not this class.
136
+ if (base && SELF_VIEW.test(d.body)) { ev.push('inflates / finds views on itself'); }
137
+ if (!ev.length) { return false; }
138
+ out.set(name, { path: d.path, at: d.at, base: d.base, evidence: ev });
139
+ return true;
140
+ };
141
+ for (const name of [...decl.keys()].sort()) { isView(name); }
142
+ return out;
143
+ }
144
+
145
+ // ── 2. construction sites ────────────────────────────────────────────────────
146
+
147
+ /**
148
+ * [{pos, end, cls}] construction sites of the view classes in masked `text`. `end` is just past
149
+ * the argument list. Declarations (`fun X(`, Java constructors, `class X(`) and supertype calls
150
+ * (`: X(ctx)`) are not constructions.
151
+ */
152
+ export function constructionSites(text, classes, java = false) {
153
+ if (!classes.size) { return []; }
154
+ const names = [...classes.keys()].sort((a, b) => b.length - a.length).join('|');
155
+ const rx = new RegExp(String.raw`(?<![\w.])(new\s+)?((?:[A-Z]\w*\.)*)(` + names + String.raw`)\s*\(`, 'g');
156
+ const out = [];
157
+ for (const m of text.matchAll(rx)) {
158
+ // Java constructs only with `new`; without it the match is a constructor declaration.
159
+ // Kotlin never writes `new`.
160
+ if (java !== Boolean(m[1])) { continue; }
161
+ const pre = text.slice(Math.max(0, m.index - 160), m.index);
162
+ if (/\b(?:class|fun|constructor|interface|object)\s+$/.test(pre)) { continue; }
163
+ // Kotlin supertype / delegation: `class Y(..) : X(..)`, `constructor(..) : X(..)`.
164
+ if (!java && (/\)\s*:\s*$/.test(pre) || /\bclass\s+\w+\s*:\s*$/.test(pre))) { continue; }
165
+ const open = m.index + m[0].length - 1;
166
+ out.push({ pos: m.index, end: closeOf(text, open), cls: m[3] });
167
+ }
168
+ return out;
169
+ }
170
+
171
+ // ── 3. sinks ─────────────────────────────────────────────────────────────────
172
+
173
+ let braceCache = { text: null, table: null };
174
+ /** table[k] = index of the innermost `{` still open before k (-1 at top level); one table per text, kept for the latest. */
175
+ function openBraces(text) {
176
+ if (braceCache.text !== text) {
177
+ const table = new Int32Array(text.length + 1);
178
+ const stack = [];
179
+ for (let k = 0; k < text.length; k++) {
180
+ table[k] = stack.length ? stack[stack.length - 1] : -1;
181
+ if (text[k] === '{') { stack.push(k); } else if (text[k] === '}') { stack.pop(); }
182
+ }
183
+ table[text.length] = stack.length ? stack[stack.length - 1] : -1;
184
+ braceCache = { text, table };
185
+ }
186
+ return braceCache.table;
187
+ }
188
+
189
+ /**
190
+ * Walk back from `pos` to the start of its statement. Returns {prefix, openCall, scopeRecv}:
191
+ * prefix text from the statement start to `pos`
192
+ * openCall {name, receiver, pos} of the innermost call whose `(` is still open at `pos`
193
+ * scopeRecv receiver of the enclosing `x.apply {` / `x.run {` / `with(x) {` block when the
194
+ * statement is that block's first-level content (any statement of it, not only the
195
+ * first), else null
196
+ */
197
+ export function statementPrefix(text, pos) {
198
+ let depth = 0; let i = pos - 1; let openCall = null;
199
+ for (; i >= 0; i--) {
200
+ const c = text[i];
201
+ if (c === ')' || c === ']' || c === '}') { depth++; continue; }
202
+ if (c === '(' || c === '[') {
203
+ if (depth) { depth--; continue; }
204
+ if (c === '(' && !openCall) {
205
+ const head = /((?:[\w.]|\(\s*\))*?)\b(\w+)\s*$/.exec(text.slice(Math.max(0, i - 160), i));
206
+ if (head) { openCall = { name: head[2], receiver: head[1].replace(/\.$/, '') || null, pos: i }; }
207
+ }
208
+ continue;
209
+ }
210
+ if (depth) { continue; }
211
+ if (c === '{' || c === ';') { break; }
212
+ if (c === '\n') {
213
+ // Kotlin: a newline ends the statement unless the previous line continues it.
214
+ const before = text.slice(Math.max(0, i - 200), i).replace(/\s+$/, '');
215
+ const nextLine = text.slice(i + 1, pos).trimStart();
216
+ const cont = /[=.,(+\-*/&|?:]$/.test(before) || /^[.?:]/.test(nextLine);
217
+ if (!cont) { break; }
218
+ }
219
+ }
220
+ const prefix = text.slice(i + 1, pos);
221
+ let scopeRecv = null;
222
+ // The statement stopped at `{`, `;` or a newline. The block it belongs to opens at the nearest
223
+ // unmatched `{` before that point: right there for the block's first statement, further back
224
+ // (past the earlier statements and their nested blocks) for any later one. Looked up in a
225
+ // per-text table, so a name used hundreds of times in a big file costs no rescan each time.
226
+ const b = i < 0 ? -1 : text[i] === '{' ? i : openBraces(text)[i];
227
+ if (b >= 0) {
228
+ const head = text.slice(Math.max(0, b - 200), b);
229
+ const dot = /((?:[\w.]|\(\s*\))+)\s*\.\s*(\w+)\s*$/.exec(head);
230
+ const withM = /\bwith\s*\(\s*([^()]+?)\s*\)\s*$/.exec(head);
231
+ if (dot && SCOPE_FNS.has(dot[2])) { scopeRecv = dot[1]; } else if (withM) { scopeRecv = withM[1]; }
232
+ }
233
+ return { prefix, openCall, scopeRecv };
234
+ }
235
+
236
+ /**
237
+ * Where the value produced at [pos, end) goes. Returns a sink
238
+ * {kind: 'call-arg', callee, receiver} | {kind: 'prop-assign', target, receiver}
239
+ * | {kind: 'var', name} | {kind: 'return', fn} | {kind: 'none'}
240
+ */
241
+ export function classifySink(text, pos, ranges) {
242
+ const { prefix, openCall, scopeRecv } = statementPrefix(text, pos);
243
+ if (openCall && !KEYWORDS.has(openCall.name)) {
244
+ return { kind: 'call-arg', callee: openCall.name, receiver: openCall.receiver ?? scopeRecv };
245
+ }
246
+ const p = prefix.replace(/\s+$/, '');
247
+ if (/(?:^|\s)return$/.test(p)) {
248
+ const fn = innermostFn(ranges, pos);
249
+ return fn ? { kind: 'return', fn } : { kind: 'none' };
250
+ }
251
+ // Kotlin expression body: `fun mk(..): T =`
252
+ const exprFn = /\bfun\s+(?:<[^>]*>\s*)?(?:[\w.]+\.)?(\w+)\s*\([^)]*\)\s*(?::\s*[\w.<>?, ]+)?=$/.exec(p);
253
+ if (exprFn) { return { kind: 'return', fn: exprFn[1] }; }
254
+ const local = /(?:\b(?:val|var)\s+|\bfinal\s+[\w.<>?]+\s+|^\s*[A-Z][\w.<>?]*\s+|(?:private|protected|public|static|internal|lateinit)\s+(?:[\w.<>?]+\s+)?)(\w+)\s*(?::\s*[\w.<>?]+\s*)?=$/.exec(p);
255
+ if (local) { return { kind: 'var', name: local[1] }; }
256
+ const assign = /^\s*((?:(?:[\w]|\(\s*\))+\s*\.\s*)*)(\w+)\s*=$/.exec(p);
257
+ if (assign) {
258
+ const recv = assign[1].replace(/\s*\.\s*$/, '').replace(/\s+/g, '') || null;
259
+ if (recv === 'this' || (!recv && !scopeRecv)) { return { kind: 'var', name: assign[2], field: true }; }
260
+ return { kind: 'prop-assign', target: assign[2], receiver: recv ?? scopeRecv };
261
+ }
262
+ return { kind: 'none' };
263
+ }
264
+
265
+ function innermostFn(ranges, pos) {
266
+ const r = innermostRange(ranges, pos);
267
+ return r ? r[2] : null;
268
+ }
269
+
270
+ function innermostRange(ranges, pos) {
271
+ let best = null;
272
+ for (const [s, e, name] of ranges) { if (s <= pos && pos < e && (!best || e - s < best[1] - best[0])) { best = [s, e, name]; } }
273
+ return best;
274
+ }
275
+
276
+ /**
277
+ * Sinks of a bare value expression `name` used in `text` (outside `skip`), one level, no further hops.
278
+ * `span` [start, end) limits the scan to the declaring function for a local: the same name in another
279
+ * function is another variable.
280
+ */
281
+ function usesOf(text, name, ranges, skipPos, span = null) {
282
+ const out = [];
283
+ const rx = new RegExp(String.raw`(?<![\w.])(?:this\s*\.\s*)?` + name + String.raw`(?![\w(])`, 'g');
284
+ for (const m of text.matchAll(rx)) {
285
+ if (m.index === skipPos) { continue; }
286
+ if (span && (m.index < span[0] || m.index >= span[1])) { continue; }
287
+ const after = text.slice(m.index + m[0].length, m.index + m[0].length + 40);
288
+ if (/^\s*(?:[.\[]|=(?!=))/.test(after)) { continue; } // member access / reassignment
289
+ const s = classifySink(text, m.index, ranges);
290
+ if (s.kind === 'call-arg' || s.kind === 'prop-assign') { out.push({ ...s, pos: m.index }); }
291
+ }
292
+ return out;
293
+ }
294
+
295
+ /**
296
+ * Call sites `fn(..)` of the factory function `fn` declared in `declPath` inside class `owner`
297
+ * (null for a top-level one), excluding its declaration. A name alone says nothing about which
298
+ * function a call reaches — `getView(` is also the Fragment's own method — so a call counts only
299
+ * when it is receiver-less in the declaring file, or qualified by the declaring class / object /
300
+ * companion (`Owner.fn(..)`, `Owner.Companion.fn(..)`). An overriding factory (`override fun`,
301
+ * `@Override`) is called by the framework, not by project code: no call site at all.
302
+ */
303
+ function callsOf(code, rangesOf, fn, declPath, owner, declPos) {
304
+ const out = [];
305
+ const declText = code.get(declPath) ?? '';
306
+ if (isOverrideDecl(declText, fn, declPos)) { return out; }
307
+ const rx = new RegExp(String.raw`(?<![\w])` + fn + String.raw`\s*\(`, 'g');
308
+ for (const [p, text] of code) {
309
+ for (const m of text.matchAll(rx)) {
310
+ const pre = text.slice(Math.max(0, m.index - 60), m.index);
311
+ if (/\b(?:fun|void|[A-Z][\w<>?]*)\s+$/.test(pre) && !/\breturn\s+$/.test(pre)) { continue; }
312
+ const recv = /((?:\w+\s*(?:\?\.|\.)\s*)*)$/.exec(pre)[1].replace(/\s+/g, '').replace(/\??\.$/, '');
313
+ const recvOk = recv && recv !== 'this' ? !!owner && (lastSeg(recv) === owner || recv.endsWith(`${owner}.Companion`)) : p === declPath;
314
+ if (!recvOk) { continue; }
315
+ const end = closeOf(text, m.index + m[0].length - 1);
316
+ if (/^\s*(?:throws\s+[\w.,\s]+)?\{/.test(text.slice(end, end + 60))) { continue; }
317
+ out.push({ path: p, pos: m.index, sink: classifySink(text, m.index, rangesOf(p)) });
318
+ }
319
+ }
320
+ return out;
321
+ }
322
+
323
+ /**
324
+ * True when the factory `fn` whose body holds `pos` is itself declared `override fun` / `@Override`.
325
+ * Only that declaration counts — the last `fn(` declaration before `pos`, its own line plus the
326
+ * annotation-only lines above it — not another class's same-named override in the file.
327
+ */
328
+ function isOverrideDecl(text, fn, pos) {
329
+ const rx = new RegExp(String.raw`(?:\bfun\s+(?:<[^>]*>\s*)?(?:[\w.]+\.)?|\b(\w+[>\]?]?|[>\]?])\s+)` + fn + String.raw`\s*\(`, 'g');
330
+ let at = -1;
331
+ for (const m of text.matchAll(rx)) {
332
+ if (m.index >= pos) { break; }
333
+ if (m[1] !== undefined && KEYWORDS.has(m[1])) { continue; } // `return mk(`, `else mk(`: a call
334
+ at = m.index;
335
+ }
336
+ if (at < 0) { return false; }
337
+ const lines = text.slice(0, at).split('\n');
338
+ const head = [lines.pop()];
339
+ while (lines.length && /^\s*(?:@\w+(?:\s*\([^)]*\))?\s*)+$/.test(lines.at(-1))) { head.push(lines.pop()); }
340
+ return /\boverride\b|@Override\b/.test(head.join('\n'));
341
+ }
342
+
343
+ /** `Log.d(..)`, `TextUtils.isEmpty(..)`: a call on a class (static utility), not on a view. */
344
+ const isStaticRecv = (r) => !!r && /^[A-Z]\w*[a-z]\w*$/.test(lastSeg(r));
345
+
346
+ const isAttachment = (s) => (s.kind === 'call-arg' && !LAYOUT_SINKS.has(s.callee) && !COLLECTION_SINKS.has(s.callee) && !/^[A-Z]/.test(s.callee)
347
+ && !isStaticRecv(s.receiver)) || s.kind === 'prop-assign';
348
+
349
+ function dropReason(s) {
350
+ if (s.kind === 'call-arg') {
351
+ if (LAYOUT_SINKS.has(s.callee)) { return `layout:${s.callee}`; }
352
+ if (COLLECTION_SINKS.has(s.callee)) { return `collection:${s.callee}`; }
353
+ if (/^[A-Z]/.test(s.callee)) { return `ctor-arg:${s.callee}`; }
354
+ if (isStaticRecv(s.receiver)) { return `static:${lastSeg(s.receiver)}.${s.callee}`; }
355
+ }
356
+ if (s.kind === 'var') { return 'var-without-attaching-use'; }
357
+ if (s.kind === 'return') { return 'factory-without-attaching-call'; }
358
+ return s.kind === 'none' ? 'no-sink' : s.kind;
359
+ }
360
+
361
+ // ── collect ──────────────────────────────────────────────────────────────────
362
+
363
+ const R_LAYOUT = /\bR\s*\.\s*layout\s*\.\s*(\w+)/;
364
+
365
+ /**
366
+ * {sites, by_node, stats}. `files` is Map{rel path -> raw text} (view_interactions.sources),
367
+ * `nodes` the workspace nodes.
368
+ */
369
+ export function collect(files, nodes) {
370
+ const index = new EvidenceIndex(files, nodes);
371
+ const code = index.code;
372
+ const rawOf = (p) => files.get(p) ?? '';
373
+ const rangeCache = new Map();
374
+ const rangesOf = (p) => { if (!rangeCache.has(p)) { rangeCache.set(p, fnRanges(code.get(p), p)); } return rangeCache.get(p); };
375
+ const classes = viewClasses(code);
376
+ const layoutFile = (name) => [...files.keys()].find((k) => new RegExp(String.raw`/res/layout[^/]*/` + name + String.raw`\.xml$`).test('/' + k)) ?? null;
377
+
378
+ const sites = [];
379
+ const stats = { view_classes: classes.size, constructions: 0, attachments: 0, hostless: 0, dropped: 0 };
380
+ for (const [p, text] of code) {
381
+ const ranges = rangesOf(p);
382
+ for (const c of constructionSites(text, classes, p.endsWith('.java'))) {
383
+ stats.constructions++;
384
+ const at = `${p}:${lineOf(text, c.pos)}`;
385
+ const direct = classifySink(text, c.pos, ranges);
386
+ // resolve one variable / factory hop
387
+ let resolved = []; let viaVar = null; let viaFn = null;
388
+ if (direct.kind === 'var') {
389
+ viaVar = direct.name;
390
+ // a local is scoped to its function; a field (or a class-level property) to the whole file
391
+ const span = direct.field ? null : innermostRange(ranges, c.pos);
392
+ resolved = usesOf(text, direct.name, ranges, -1, span).map((s) => ({ ...s, path: p }));
393
+ } else if (direct.kind === 'return') {
394
+ viaFn = direct.fn;
395
+ resolved = callsOf(code, rangesOf, direct.fn, p, enclosingClass(text, c.pos), c.pos).map((x) => ({ ...x.sink, path: x.path, pos: x.pos }));
396
+ } else {
397
+ resolved = [{ ...direct, path: p, pos: c.pos }];
398
+ }
399
+ const args = rawOf(p).slice(c.pos, c.end);
400
+ const lay = R_LAYOUT.exec(args);
401
+ const info = classes.get(c.cls);
402
+ const base = { at, view_class: c.cls, view_class_at: info.at, base: info.base, evidence: info.evidence,
403
+ ...(lay ? { layout: layoutFile(lay[1]) ?? `@layout/${lay[1]}` } : {}),
404
+ ...(viaVar ? { via_var: viaVar } : {}), ...(viaFn ? { via_fn: viaFn } : {}) };
405
+ const keep = resolved.filter(isAttachment);
406
+ if (!keep.length) {
407
+ stats.dropped++;
408
+ sites.push({ ...base, dropped: resolved.length ? [...new Set(resolved.map(dropReason))].join(',') : dropReason(direct) });
409
+ continue;
410
+ }
411
+ for (const s of keep) {
412
+ const sinkText = code.get(s.path);
413
+ const owner = enclosingClass(sinkText, s.pos);
414
+ const hosts = [...(index.hosts.get(tupleKey(s.path, owner)) ?? [])].sort();
415
+ const sink = { kind: s.kind, ...(s.callee ? { callee: s.callee } : { target: s.target }),
416
+ ...(s.receiver ? { receiver: s.receiver } : {}), at: `${s.path}:${lineOf(sinkText, s.pos)}` };
417
+ const site = { ...base, sink, hosts };
418
+ if (!hosts.length) { stats.hostless++; site.dropped = 'hostless'; } else { stats.attachments++; }
419
+ sites.push(site);
420
+ }
421
+ }
422
+ }
423
+ const byNode = new Map();
424
+ for (const s of sites) {
425
+ if (s.dropped) { continue; }
426
+ for (const h of s.hosts) {
427
+ const { hosts, ...rec } = s;
428
+ if (!byNode.has(h)) { byNode.set(h, []); }
429
+ const list = byNode.get(h);
430
+ if (!list.some((x) => x.at === rec.at && x.sink.at === rec.sink.at)) { list.push(rec); }
431
+ }
432
+ }
433
+ return { sites, by_node: byNode, stats };
434
+ }
435
+
436
+ const readJsonl = (p) => readText(p).split('\n').filter((l) => pyStrip(l)).map((l) => jsonLoads(l));
437
+
438
+ export function main(argv = process.argv.slice(2)) {
439
+ const ap = new ArgumentParser({ prog: 'view_attachments.mjs' });
440
+ ap.add_argument('workspace');
441
+ ap.add_argument('--project', { required: true });
442
+ ap.add_argument('--append', { action: 'store_true' });
443
+ const a = ap.parse_args(argv);
444
+ const npath = path.join(a.workspace, 'nodes.jsonl');
445
+ const nodes = readJsonl(npath);
446
+ const { sites, by_node: byNode, stats } = collect(sources(a.project), nodes);
447
+ writeText(path.join(a.workspace, 'view_attachments.json'),
448
+ jsonDumps({ stats, sites }, { ensure_ascii: false, indent: 2 }) + '\n');
449
+ if (a.append) {
450
+ let buf = '';
451
+ for (const n of nodes) {
452
+ // a rerun replaces the stamp: a node whose attachment went away loses the old one
453
+ if (byNode.has(n.id)) { dset(n, 'attachments', byNode.get(n.id)); } else { delete n.attachments; }
454
+ buf += jsonDumps(n, { ensure_ascii: false }) + '\n';
455
+ }
456
+ writeText(npath, buf);
457
+ pyPrintErr(`stamped attachments on ${byNode.size} node(s) -> ${npath}`);
458
+ } else {
459
+ pyPrintBuf(jsonDumps(Object.fromEntries(byNode), { ensure_ascii: false, indent: 1 }));
460
+ }
461
+ pyPrintErr(`[view_attachments] view_classes=${stats.view_classes} constructions=${stats.constructions} ` +
462
+ `attachments=${stats.attachments} hostless=${stats.hostless} dropped=${stats.dropped}`);
463
+ }
464
+
465
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { main(); }
@@ -1,5 +0,0 @@
1
- ---
2
- name: build-fixer
3
- description: Automatically builds a HarmonyOS project, parses compile errors, fixes them, and retries in a loop until build succeeds
4
- tools: Agent
5
- ---
@@ -1,5 +0,0 @@
1
- ---
2
- name: code-reviewer
3
- description: Reviews HarmonyOS code against the scenarios of a SPEC document and fixes the confirmed defects. mode=review (default, read-only) — extracts the change via git, expands it with homegraph, judges every scenario PASS / PARTIAL / FAIL / UNABLE TO VERIFY with launch-path tracing and cross-cutting checks, writes code-review-report.md. mode=fix — fixes the issues a review report lists, builds once (or leaves the build to the dispatcher), writes review-fix-report.md and commits.
4
- tools: Agent
5
- ---
@@ -1,5 +0,0 @@
1
- ---
2
- name: model-render-worker
3
- description: Fused Model worker for a2h-spec-generate — executes ONE self-contained per-Area fused task.md (reconcile + SPEC authoring in one session) and writes output.json plus specs/<stem>-SPEC.md (finalized true) after check-fused-spec passes
4
- tools: Agent
5
- ---
@@ -1,5 +0,0 @@
1
- ---
2
- name: model-worker
3
- description: Model worker for a2h-spec-generate — executes one self-contained interaction task.md (candidate review, or Area reconciliation/discovery) and writes only its own output.json (finalized true) after check-task passes
4
- tools: Agent
5
- ---
@@ -1,5 +0,0 @@
1
- ---
2
- name: specgen-worker
3
- description: SpecGen page worker for a2h-spec-generate — processes exactly one req-<idx>.txt page batch into <feature>-SPEC.md files from the rendered task.md it is handed
4
- tools: Agent
5
- ---