@buaa_smat/hometrans 26.0.0-devecocli.3 → 26.0.0-devecocli.4
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.
- package/package.json +1 -1
- package/plugin.jsonc +1 -1
- package/skills/a2h-batch-ui-align/scripts/arkts_static_check.ts +25 -5
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +24 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_weight_color.test.mjs +28 -0
- package/skills/a2h-utg-explorer/scripts/recover_d.mjs +17 -6
- package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +7 -4
- package/skills/a2h-utg-explorer/scripts/tests/recover_d.test.mjs +13 -0
- package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +5 -1
- package/skills/a2h-utg-static/scripts/compose_body_text.mjs +6 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buaa_smat/hometrans",
|
|
3
|
-
"version": "26.0.0-devecocli.
|
|
3
|
+
"version": "26.0.0-devecocli.4",
|
|
4
4
|
"description": "HomeTrans (Android-to-HarmonyOS) skill + agent installer. Run `ht init` to distribute conversion skills and subagents into AI editors.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/plugin.jsonc
CHANGED
|
@@ -1322,9 +1322,22 @@ function checkLayoutPlacement(code: string, rel: string, rawLines: string[] = []
|
|
|
1322
1322
|
if (w === undefined || !RE_PCT_FULL_ARG.test(w.args) || h === undefined || /%/.test(h.args)) { continue; }
|
|
1323
1323
|
// Stack 与条同高:居中即贴满,无害
|
|
1324
1324
|
if (stackH !== undefined && stackH.args.trim() === h.args.trim()) { continue; }
|
|
1325
|
+
// Stack 未定高时按最高子节点收缩:只有兄弟撑满(%)或比条更高时条才会被居中;看不出来就只报 CAND
|
|
1326
|
+
const vpOf = (s: string): number | null => {
|
|
1327
|
+
const m: RegExpExecArray | null = /^\s*(['"]?)(\d+(?:\.\d+)?)(?:vp)?\1\s*$/.exec(s);
|
|
1328
|
+
return m === null ? null : Number(m[2]);
|
|
1329
|
+
};
|
|
1330
|
+
const barVp: number | null = vpOf(h.args);
|
|
1331
|
+
const taller: boolean = stackH !== undefined || kids.some((o) => {
|
|
1332
|
+
if (o === c) { return false; }
|
|
1333
|
+
const oh: UiAttr | undefined = attrsOf(o).find((x) => x.name === 'height');
|
|
1334
|
+
if (oh === undefined) { return false; }
|
|
1335
|
+
const ov: number | null = vpOf(oh.args);
|
|
1336
|
+
return /%/.test(oh.args) || (ov !== null && barVp !== null && ov > barVp);
|
|
1337
|
+
});
|
|
1325
1338
|
const at: number = lineOfIndex(code, c.at);
|
|
1326
1339
|
const marked: boolean = markedAbove(rawLines, at, 'STACK-CENTER');
|
|
1327
|
-
report(marked ? 'CAND' : 'GATE', 'stack-bar-default-center', rel, at,
|
|
1340
|
+
report(marked || !taller ? 'CAND' : 'GATE', 'stack-bar-default-center', rel, at,
|
|
1328
1341
|
`Stack 未设 alignContent(默认 Center),子节点 ${kindOf(c) || c.name} 横向撑满、高 ${h.args.trim()} —— ` +
|
|
1329
1342
|
'它会被纵向居中,停在 Stack 中部。Compose Box / FrameLayout 默认左上:Box() 译成 ' +
|
|
1330
1343
|
'Stack({ alignContent: Alignment.TopStart }),Box(contentAlignment = X) 译成 X;顶栏用 Top/TopStart,底栏用 Bottom。' +
|
|
@@ -1704,8 +1717,13 @@ function checkFile(file: string, rel: string): FileScan {
|
|
|
1704
1717
|
const RES_CALL: string = String.raw`\$(?:r|rawfile)\(\s*(['"])[^'"\n]*\1\s*(?:,[^()\n]*)?\)`;
|
|
1705
1718
|
const resNames: string[] = [...new Set([...code.matchAll(/\b([A-Za-z_$][\w$]*)\s*\??\s*:\s*Resource\b(?![\w.<[])(?!\s*\|)/g)]
|
|
1706
1719
|
.map((x) => x[1]))]
|
|
1707
|
-
// 同名在本文件里还声明成别的类型(Resource 字段 title 与 string 参数 title)
|
|
1708
|
-
|
|
1720
|
+
// 同名在本文件里还声明成别的类型(Resource 字段 title 与 string 参数 title)或无注解的局部量
|
|
1721
|
+
// (const title = `…`,类型靠推断)时作用域分不清,只认 $r() 本身
|
|
1722
|
+
.filter((n) => {
|
|
1723
|
+
const id: string = n.replace(/\$/g, '\\$');
|
|
1724
|
+
return !new RegExp(String.raw`(?<![\w$.])` + id + String.raw`\s*\??\s*:\s*(?!Resource\b)[A-Za-z_{(\[]`).test(code) &&
|
|
1725
|
+
!new RegExp(String.raw`\b(?:let|const|var)\s+` + id + String.raw`\s*=`).test(code);
|
|
1726
|
+
});
|
|
1709
1727
|
const resRef: string = resNames.length
|
|
1710
1728
|
? `(?:${RES_CALL}|(?<![\\w$.])(?:this\\.)?(?:${resNames.map((n) => n.replace(/\$/g, '\\$')).join('|')})(?![\\w$]))`
|
|
1711
1729
|
: RES_CALL;
|
|
@@ -1924,8 +1942,10 @@ function checkFile(file: string, rel: string): FileScan {
|
|
|
1924
1942
|
// Canvas 的 Path2D 按 Canvas 单位(默认 vp),不报。插值或其前 20 行出现 vp2px / px 换算即视为已换算。
|
|
1925
1943
|
for (let i = 0; i < codeLines.length; i++) {
|
|
1926
1944
|
const ln: string = codeLines[i];
|
|
1927
|
-
const pm: RegExpExecArray | null = /`\s*
|
|
1928
|
-
|
|
1945
|
+
const pm: RegExpExecArray | null = /`\s*[Mm]\s*-?(?:\d|\$\{)[^`]*\$\{/.exec(ln);
|
|
1946
|
+
// 还要有第二个路径命令(H/V/L/C/S/Q/T/A/Z):`m-${year}-${month}` 这类 key 串不是路径
|
|
1947
|
+
if (pm !== null && !/[\s\d}][HVLCSQTAZhvlcsqtaz]\s*(?:-?\d|\$\{|`)/.test(ln.slice(pm.index + 2))) { continue; }
|
|
1948
|
+
if (pm === null ||/Path2D\s*\(\s*$/.test(ln.slice(0, pm.index))) { continue; }
|
|
1929
1949
|
const scope: string = codeLines.slice(Math.max(0, i - 20), i + 1).join('\n');
|
|
1930
1950
|
if (/\bvp2px\s*\(|\blpx2px\s*\(|\bfp2px\s*\(|LengthMetricsUnit\.PX/.test(scope)) { continue; }
|
|
1931
1951
|
const marked: boolean = markedAbove(rawLines, i + 1, 'PATH-PX');
|
package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs
CHANGED
|
@@ -332,6 +332,30 @@ test('stack_bar_default_center_gates_full_width_fixed_height_bar_in_bare_stack',
|
|
|
332
332
|
assert.deepEqual(hits(out, 'stack-bar-default-center', 'CANDIDATES'), ['pages/Marked.ets:8']);
|
|
333
333
|
});
|
|
334
334
|
|
|
335
|
+
test('stack_bar_default_center_is_only_a_candidate_when_nothing_makes_the_stack_taller', () => {
|
|
336
|
+
// a title bar: Stack wraps to the 48 Row, the centred Text overlays it; nothing is displaced
|
|
337
|
+
const out = run({
|
|
338
|
+
'pages/Title.ets': `@Entry
|
|
339
|
+
@ComponentV2
|
|
340
|
+
struct Title {
|
|
341
|
+
build() {
|
|
342
|
+
Stack() {
|
|
343
|
+
Row() {
|
|
344
|
+
Image($r('app.media.ic_back')).width(20).height(20)
|
|
345
|
+
}
|
|
346
|
+
.width('100%')
|
|
347
|
+
.height(48)
|
|
348
|
+
Text('标题')
|
|
349
|
+
}
|
|
350
|
+
.width('100%')
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
`,
|
|
354
|
+
});
|
|
355
|
+
assert.deepEqual(hits(out, 'stack-bar-default-center', 'GATE'), []);
|
|
356
|
+
assert.deepEqual(hits(out, 'stack-bar-default-center', 'CANDIDATES'), ['pages/Title.ets:6']);
|
|
357
|
+
});
|
|
358
|
+
|
|
335
359
|
test('stack_bar_default_center_ignores_same_height_stack_and_positioned_bar', () => {
|
|
336
360
|
const out = run({
|
|
337
361
|
'pages/Same.ets': barHost('Same', 'Stack()', '', '.height(48)'),
|
|
@@ -400,6 +400,20 @@ export const fixed: string = 'M0 0 H100 V100 Z'
|
|
|
400
400
|
assert.deepEqual(hits(out, 'path-commands-vp'), ['components/P.ets:2']);
|
|
401
401
|
});
|
|
402
402
|
|
|
403
|
+
test('path_commands_relative_moveto_gates_but_a_key_string_does_not', () => {
|
|
404
|
+
const out = run({
|
|
405
|
+
'components/R.ets': `export function clipRel(w: number, h: number): string {
|
|
406
|
+
return \`m0 0 h\${w} v\${h} z\`
|
|
407
|
+
}
|
|
408
|
+
export function pageKey(y: number, m: number): string {
|
|
409
|
+
return \`m-\${y}-\${m}\`
|
|
410
|
+
}
|
|
411
|
+
`,
|
|
412
|
+
});
|
|
413
|
+
// pageKey: a where2study2 page key, not a path (no second path command)
|
|
414
|
+
assert.deepEqual(hits(out, 'path-commands-vp'), ['components/R.ets:2']);
|
|
415
|
+
});
|
|
416
|
+
|
|
403
417
|
// ---------------------------------------------------------------- resource-as-string
|
|
404
418
|
// Measured (coolmall goods detail): stringResource(R.string.x) became $r('app.string.x').toString();
|
|
405
419
|
// Resource has no toString(), so the SKU sheet showed "[object Object]" instead of 「请选择规格」.
|
|
@@ -431,6 +445,20 @@ test('resource_used_as_a_string_is_a_gate', () => {
|
|
|
431
445
|
'pages/Detail.ets:8', 'pages/Detail.ets:10']);
|
|
432
446
|
});
|
|
433
447
|
|
|
448
|
+
test('a Resource field name reused by an untyped local is not judged by name', () => {
|
|
449
|
+
const out = run({
|
|
450
|
+
'viewmodel/Vm.ets': [
|
|
451
|
+
'interface Section { title: Resource }',
|
|
452
|
+
'export function log(n: number): string {',
|
|
453
|
+
' const title = `第${n}项`',
|
|
454
|
+
" return title + '!'",
|
|
455
|
+
'}',
|
|
456
|
+
'',
|
|
457
|
+
].join('\n'),
|
|
458
|
+
});
|
|
459
|
+
assert.deepEqual(hits(out, 'resource-as-string'), []);
|
|
460
|
+
});
|
|
461
|
+
|
|
434
462
|
test('a name typed Resource in one place and string in another is not judged by name', () => {
|
|
435
463
|
const out = run({
|
|
436
464
|
'viewmodel/Vm.ets': [
|
|
@@ -62,9 +62,14 @@ export function phasesNeedingState(doc, config) {
|
|
|
62
62
|
* Measured (ydweather): both add-city recipes reached Main, whose tree carried 「城市管理」 and
|
|
63
63
|
* 「每小时天气预报」, but their probes required 「空气质量」, a sticky title hidden at rest.
|
|
64
64
|
*/
|
|
65
|
+
/** Recipe phases blocked on their probe and not yet offered for a revision. */
|
|
66
|
+
export function probeFailedPhases(doc) {
|
|
67
|
+
return get(doc ?? {}, 'phases', []).filter((p) => pyStr(p.id).startsWith('recD-') && p.status === 'blocked' &&
|
|
68
|
+
get(p, 'reason') === 'state-probe-failed' && !T(get(p, 'probe_revised')));
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
export function probeFailures(doc, root) {
|
|
66
|
-
const failed = new Map(doc.
|
|
67
|
-
get(p, 'reason') === 'state-probe-failed' && !T(get(p, 'probe_revised'))).map((p) => [p.id, p]));
|
|
72
|
+
const failed = new Map(probeFailedPhases(doc).map((p) => [p.id, p]));
|
|
68
73
|
if (!failed.size || !pIsFile(pJoin(root, 'events.jsonl'))) { return []; }
|
|
69
74
|
const last = new Map();
|
|
70
75
|
for (const line of readText(pJoin(root, 'events.jsonl'), { encoding: 'utf-8' }).split('\n')) {
|
|
@@ -75,7 +80,9 @@ export function probeFailures(doc, root) {
|
|
|
75
80
|
}
|
|
76
81
|
return [...last.entries()].map(([ph, ev]) => {
|
|
77
82
|
const rid = ph.slice('recD-'.length);
|
|
78
|
-
|
|
83
|
+
// ids run to 32 chars: a truncated `rv-<id>` would let two long ids share one key
|
|
84
|
+
const key = `rv-${rid}`.length <= 32 ? `rv-${rid}` : `rv-${keyOf(rid)}`;
|
|
85
|
+
return { key, kind: 'probe-revision', phase: ph, recipe: rid,
|
|
79
86
|
tasks: doc.tasks.filter((t) => t.phase === ph).map((t) => t.task_id),
|
|
80
87
|
failed_probes: get(ev, 'probes', []), activity: get(ev, 'activity'),
|
|
81
88
|
observation_id: get(ev, 'observation_id'),
|
|
@@ -196,9 +203,13 @@ export function checkRevisedProbes(probes, visible) {
|
|
|
196
203
|
const pos = [...or_(get(p, 'all'), []), ...or_(get(p, 'any'), [])];
|
|
197
204
|
if (!pos.length) { return 'each probe needs all/any texts seen on the failed screen'; }
|
|
198
205
|
for (const c of pos) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (!
|
|
206
|
+
// a selector with no text (class / resource_id only) matches almost any screen: not evidence
|
|
207
|
+
const named = ['text', 'content_desc'].filter((k) => T(get(c, k)));
|
|
208
|
+
if (!named.length) { return 'each probe selector needs a text or content_desc seen on the failed screen'; }
|
|
209
|
+
for (const k of named) {
|
|
210
|
+
const t = get(c, k);
|
|
211
|
+
if (!shown.has(pyStr(t).trim())) { return `probe text not on the failed screen: ${pyStr(t)}`; }
|
|
212
|
+
}
|
|
202
213
|
}
|
|
203
214
|
}
|
|
204
215
|
return null;
|
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
} from './utg_explorer/_py.mjs';
|
|
70
70
|
import { BUSY_WHY } from './device_health.mjs';
|
|
71
71
|
import { scopeOf } from './utg_explorer/coverage.mjs';
|
|
72
|
+
import { probeFailedPhases } from './recover_d.mjs';
|
|
72
73
|
|
|
73
74
|
export const HERE = pathStr(path.dirname(fileURLToPath(import.meta.url)));
|
|
74
75
|
export const NODE = process.execPath;
|
|
@@ -638,14 +639,16 @@ export function step(root, a, state) {
|
|
|
638
639
|
if (gate('D')) { return false; }
|
|
639
640
|
if (ans('recovery_d')) {
|
|
640
641
|
once('D-apply', () => deps.sh(['recover_d.mjs', 'apply', root, '--config', a.config], root));
|
|
641
|
-
|
|
642
|
-
|
|
642
|
+
// after D-apply#2 the phases file holds the revision pass's list, which runs under scope D#2
|
|
643
|
+
if (!done.includes(tag + 'D-apply#2')) {
|
|
644
|
+
runPhases(root, a, phasesFile(root, 'recovery_d_phases.txt'), state, tag + 'D');
|
|
645
|
+
deps.sh(['recover_b.mjs', 'adopt', root], root);
|
|
646
|
+
}
|
|
643
647
|
// One probe-revision pass: a recipe whose steps ran but whose probe missed is offered back
|
|
644
648
|
// with the texts its screen showed (recover_d.mjs probeFailures). Measured (ydweather): both
|
|
645
649
|
// add-city recipes reached Main and blocked on a probe text Main never shows at rest.
|
|
646
650
|
once('D-revise-extract', () => dset(setdefault(state, 'd_revise', {}), tag,
|
|
647
|
-
|
|
648
|
-
p.status === 'blocked' && get(p, 'reason') === 'state-probe-failed' && !T(get(p, 'probe_revised'))) &&
|
|
651
|
+
probeFailedPhases(load(pJoin(root, 'campaign.json'), {})).length > 0 &&
|
|
649
652
|
refresh(root, state, 'recovery_d', extractArgs(root, a, 'recovery_d'))));
|
|
650
653
|
if (get(state, 'd_revise', null)?.[tag]) {
|
|
651
654
|
if (gateStage(root, a, state, tag, 'D', overlap)) { return false; }
|
|
@@ -240,6 +240,19 @@ describe('ProbeRevision', () => {
|
|
|
240
240
|
assert.equal(rd.checkRevisedProbes([{ all: [{ text: '城市管理' }, { text: '每小时天气预报' }] }], shown), null);
|
|
241
241
|
assert.match(rd.checkRevisedProbes([{ all: [{ text: '空气质量' }] }], shown), /not on the failed screen/);
|
|
242
242
|
assert.match(rd.checkRevisedProbes([{ none: [{ text: 'x' }] }], shown), /all\/any/);
|
|
243
|
+
// a text-free selector matches nearly any screen; content_desc is checked like text
|
|
244
|
+
assert.match(rd.checkRevisedProbes([{ all: [{ class: 'android.view.View' }] }], shown), /needs a text/);
|
|
245
|
+
assert.match(rd.checkRevisedProbes([{ any: [{ content_desc: '空气质量' }] }], shown), /not on the failed screen/);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test('a long recipe id gets a hashed key, so two ids sharing a prefix never collide', () => {
|
|
249
|
+
const a = 'recD-' + 'x'.repeat(29) + 'a'; const b = 'recD-' + 'x'.repeat(29) + 'b';
|
|
250
|
+
doc.phases = [a, b].map((id) => ({ id, status: 'blocked', reason: 'state-probe-failed' }));
|
|
251
|
+
fs.writeFileSync(path.join(root, 'events.jsonl'), [a, b].map((phase) =>
|
|
252
|
+
JSON.stringify({ kind: 'state_probe_failed', payload: { phase, visible_texts: shown } })).join('\n') + '\n');
|
|
253
|
+
const keys = rd.probeFailures(doc, root).map((i) => i.key);
|
|
254
|
+
assert.equal(new Set(keys).size, 2);
|
|
255
|
+
assert.ok(keys.every((k) => k.length <= 32));
|
|
243
256
|
});
|
|
244
257
|
|
|
245
258
|
test('apply re-arms the phase with the revised probe and schedules only it', () => {
|
|
@@ -683,8 +683,12 @@ export class Runner {
|
|
|
683
683
|
* sweep aborted `left-page` with no frame although the list sat at the same [42,310,1038,2400].
|
|
684
684
|
*/
|
|
685
685
|
_surfaceSelector(origin, selector, container) {
|
|
686
|
-
if (this._sameSurface(origin, selector)) { return selector; }
|
|
687
686
|
const cur = this.current;
|
|
687
|
+
if (this._sameSurface(origin, selector)) {
|
|
688
|
+
// a drifted {class, index} can land on another scrollable (a LazyRow above the list)
|
|
689
|
+
const [hit] = matching(get(cur, 'nodes', []), selector);
|
|
690
|
+
if (!_isHorizontal(hit) && get(hit, 'class') === get(container, 'class')) { return selector; }
|
|
691
|
+
}
|
|
688
692
|
if (get(cur, 'package') !== get(origin, 'package') || get(cur, 'activity') !== get(origin, 'activity')
|
|
689
693
|
|| get(cur, 'window') !== get(origin, 'window')) { return null; }
|
|
690
694
|
const ob = or(get(container, 'bounds'), []);
|
|
@@ -54,6 +54,12 @@ export function ifChainLiterals(src, i) {
|
|
|
54
54
|
if (src[k] !== '(') { break; }
|
|
55
55
|
let depth = 0; let j = k;
|
|
56
56
|
for (; j < src.length; j++) {
|
|
57
|
+
// a quoted ")" or "(" in the condition (`if (s == ")")`) must not move the depth
|
|
58
|
+
if (src[j] === '"' || src[j] === "'") {
|
|
59
|
+
const q = src[j];
|
|
60
|
+
for (j++; j < src.length && src[j] !== q && src[j] !== '\n'; j++) { if (src[j] === '\\') { j++; } }
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
57
63
|
if (src[j] === '(') { depth++; } else if (src[j] === ')' && --depth === 0) { break; }
|
|
58
64
|
}
|
|
59
65
|
if (j >= src.length) { break; }
|
|
@@ -9,7 +9,7 @@ import * as path from 'node:path';
|
|
|
9
9
|
import { spawnSync } from 'node:child_process';
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
11
|
import { vmNavHelpers, initReachable, vmNavEdges } from '../vm_nav.mjs';
|
|
12
|
-
import { bodyTexts } from '../compose_body_text.mjs';
|
|
12
|
+
import { bodyTexts, ifChainLiterals } from '../compose_body_text.mjs';
|
|
13
13
|
import { _markTransientEntries } from '../assemble.mjs';
|
|
14
14
|
import { _overlayCallbackHosts } from '../compose_overlay.mjs';
|
|
15
15
|
|
|
@@ -282,3 +282,8 @@ test('nested if/else literals reach body text, inline or through a rendered loca
|
|
|
282
282
|
const got = bodyTexts('CityManagerPage', idx, ft, {}, 2, new Set(), (p) => p).map((t) => t.text);
|
|
283
283
|
assert.deepEqual([...new Set(got)].sort(), ['城市管理', '批量删除', '删除城市', '编辑', '请选择项目'].sort());
|
|
284
284
|
});
|
|
285
|
+
|
|
286
|
+
test('a quoted paren in an if-chain condition does not cut the chain short', () => {
|
|
287
|
+
const src = 'if (s == ")") "右括号" else "其他符号"';
|
|
288
|
+
assert.deepEqual(ifChainLiterals(src, 0), ['右括号', '其他符号']);
|
|
289
|
+
});
|